1 // SPDX-License-Identifier: GPL-2.0+
2 /**************************************************************************
3 Intel Pro 1000 for ppcboot/das-u-boot
4 Drivers are port from Intel's Linux driver e1000-4.3.15
5 and from Etherboot pro 1000 driver by mrakes at vivato dot net
6 tested on both gig copper and gig fiber boards
7 ***************************************************************************/
8 /*******************************************************************************
11 Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
15 Linux NICS <linux.nics@intel.com>
16 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
18 *******************************************************************************/
20 * Copyright (C) Archway Digital Solutions.
22 * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
25 * Copyright (C) Linux Networx.
26 * Massive upgrade to work with the new intel gigabit NICs.
27 * <ebiederman at lnxi dot com>
29 * Copyright 2011 Freescale Semiconductor, Inc.
41 #define TOUT_LOOP 100000
44 #define virt_to_bus(devno, v) dm_pci_virt_to_mem(devno, (void *) (v))
45 #define bus_to_phys(devno, a) dm_pci_mem_to_phys(devno, a)
47 #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
48 #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
51 #define E1000_DEFAULT_PCI_PBA 0x00000030
52 #define E1000_DEFAULT_PCIE_PBA 0x000a0026
54 /* NIC specific static variables go here */
56 /* Intel i210 needs the DMA descriptor rings aligned to 128b */
57 #define E1000_BUFFER_ALIGN 128
60 * TODO(sjg@chromium.org): Even with driver model we share these buffers.
61 * Concurrent receiving on multiple active Ethernet devices will not work.
62 * Normally U-Boot does not support this anyway. To fix it in this driver,
63 * move these buffers and the tx/rx pointers to struct e1000_hw.
65 DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
66 DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
67 DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
70 static int rx_tail, rx_last;
72 static int num_cards; /* Number of E1000 devices seen so far */
75 static struct pci_device_id e1000_supported[] = {
76 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542) },
77 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER) },
78 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER) },
79 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER) },
80 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER) },
81 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER) },
82 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM) },
83 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM) },
84 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER) },
85 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER) },
86 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER) },
87 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER) },
88 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER) },
89 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER) },
90 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM) },
91 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER) },
92 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF) },
94 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER) },
95 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER) },
96 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES) },
97 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER) },
98 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER) },
99 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER) },
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE) },
101 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL) },
102 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD) },
103 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER) },
104 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER) },
105 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES) },
106 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI) },
107 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E) },
108 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT) },
109 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L) },
110 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L) },
111 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3) },
112 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT) },
113 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT) },
114 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT) },
115 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT) },
116 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED) },
117 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED) },
118 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER) },
119 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER) },
120 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS) },
121 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES) },
122 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS) },
123 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX) },
128 /* Function forward declarations */
129 static int e1000_setup_link(struct e1000_hw *hw);
130 static int e1000_setup_fiber_link(struct e1000_hw *hw);
131 static int e1000_setup_copper_link(struct e1000_hw *hw);
132 static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
133 static void e1000_config_collision_dist(struct e1000_hw *hw);
134 static int e1000_config_mac_to_phy(struct e1000_hw *hw);
135 static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
136 static int e1000_check_for_link(struct e1000_hw *hw);
137 static int e1000_wait_autoneg(struct e1000_hw *hw);
138 static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
140 static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
141 uint16_t * phy_data);
142 static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
144 static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
145 static int e1000_phy_reset(struct e1000_hw *hw);
146 static int e1000_detect_gig_phy(struct e1000_hw *hw);
147 static void e1000_set_media_type(struct e1000_hw *hw);
149 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
150 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
151 static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
153 #ifndef CONFIG_E1000_NO_NVM
154 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
155 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
156 static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
159 /******************************************************************************
160 * Raises the EEPROM's clock input.
162 * hw - Struct containing variables accessed by shared code
163 * eecd - EECD's current value
164 *****************************************************************************/
165 void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
167 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
168 * wait 50 microseconds.
170 *eecd = *eecd | E1000_EECD_SK;
171 E1000_WRITE_REG(hw, EECD, *eecd);
172 E1000_WRITE_FLUSH(hw);
176 /******************************************************************************
177 * Lowers the EEPROM's clock input.
179 * hw - Struct containing variables accessed by shared code
180 * eecd - EECD's current value
181 *****************************************************************************/
182 void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
184 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
185 * wait 50 microseconds.
187 *eecd = *eecd & ~E1000_EECD_SK;
188 E1000_WRITE_REG(hw, EECD, *eecd);
189 E1000_WRITE_FLUSH(hw);
193 /******************************************************************************
194 * Shift data bits out to the EEPROM.
196 * hw - Struct containing variables accessed by shared code
197 * data - data to send to the EEPROM
198 * count - number of bits to shift out
199 *****************************************************************************/
201 e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
206 /* We need to shift "count" bits out to the EEPROM. So, value in the
207 * "data" parameter will be shifted out to the EEPROM one bit at a time.
208 * In order to do this, "data" must be broken down into bits.
210 mask = 0x01 << (count - 1);
211 eecd = E1000_READ_REG(hw, EECD);
212 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
214 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
215 * and then raising and then lowering the clock (the SK bit controls
216 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
217 * by setting "DI" to "0" and then raising and then lowering the clock.
219 eecd &= ~E1000_EECD_DI;
222 eecd |= E1000_EECD_DI;
224 E1000_WRITE_REG(hw, EECD, eecd);
225 E1000_WRITE_FLUSH(hw);
229 e1000_raise_ee_clk(hw, &eecd);
230 e1000_lower_ee_clk(hw, &eecd);
236 /* We leave the "DI" bit set to "0" when we leave this routine. */
237 eecd &= ~E1000_EECD_DI;
238 E1000_WRITE_REG(hw, EECD, eecd);
241 /******************************************************************************
242 * Shift data bits in from the EEPROM
244 * hw - Struct containing variables accessed by shared code
245 *****************************************************************************/
247 e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
253 /* In order to read a register from the EEPROM, we need to shift 'count'
254 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
255 * input to the EEPROM (setting the SK bit), and then reading the
256 * value of the "DO" bit. During this "shifting in" process the
257 * "DI" bit should always be clear.
260 eecd = E1000_READ_REG(hw, EECD);
262 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
265 for (i = 0; i < count; i++) {
267 e1000_raise_ee_clk(hw, &eecd);
269 eecd = E1000_READ_REG(hw, EECD);
271 eecd &= ~(E1000_EECD_DI);
272 if (eecd & E1000_EECD_DO)
275 e1000_lower_ee_clk(hw, &eecd);
281 /******************************************************************************
282 * Returns EEPROM to a "standby" state
284 * hw - Struct containing variables accessed by shared code
285 *****************************************************************************/
286 void e1000_standby_eeprom(struct e1000_hw *hw)
288 struct e1000_eeprom_info *eeprom = &hw->eeprom;
291 eecd = E1000_READ_REG(hw, EECD);
293 if (eeprom->type == e1000_eeprom_microwire) {
294 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
295 E1000_WRITE_REG(hw, EECD, eecd);
296 E1000_WRITE_FLUSH(hw);
297 udelay(eeprom->delay_usec);
300 eecd |= E1000_EECD_SK;
301 E1000_WRITE_REG(hw, EECD, eecd);
302 E1000_WRITE_FLUSH(hw);
303 udelay(eeprom->delay_usec);
306 eecd |= E1000_EECD_CS;
307 E1000_WRITE_REG(hw, EECD, eecd);
308 E1000_WRITE_FLUSH(hw);
309 udelay(eeprom->delay_usec);
312 eecd &= ~E1000_EECD_SK;
313 E1000_WRITE_REG(hw, EECD, eecd);
314 E1000_WRITE_FLUSH(hw);
315 udelay(eeprom->delay_usec);
316 } else if (eeprom->type == e1000_eeprom_spi) {
317 /* Toggle CS to flush commands */
318 eecd |= E1000_EECD_CS;
319 E1000_WRITE_REG(hw, EECD, eecd);
320 E1000_WRITE_FLUSH(hw);
321 udelay(eeprom->delay_usec);
322 eecd &= ~E1000_EECD_CS;
323 E1000_WRITE_REG(hw, EECD, eecd);
324 E1000_WRITE_FLUSH(hw);
325 udelay(eeprom->delay_usec);
329 /***************************************************************************
330 * Description: Determines if the onboard NVM is FLASH or EEPROM.
332 * hw - Struct containing variables accessed by shared code
333 ****************************************************************************/
334 static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
340 if (hw->mac_type == e1000_ich8lan)
343 if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
344 eecd = E1000_READ_REG(hw, EECD);
346 /* Isolate bits 15 & 16 */
347 eecd = ((eecd >> 15) & 0x03);
349 /* If both bits are set, device is Flash type */
356 /******************************************************************************
357 * Prepares EEPROM for access
359 * hw - Struct containing variables accessed by shared code
361 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
362 * function should be called before issuing a command to the EEPROM.
363 *****************************************************************************/
364 int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
366 struct e1000_eeprom_info *eeprom = &hw->eeprom;
367 uint32_t eecd, i = 0;
371 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
372 return -E1000_ERR_SWFW_SYNC;
373 eecd = E1000_READ_REG(hw, EECD);
375 if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
376 /* Request EEPROM Access */
377 if (hw->mac_type > e1000_82544) {
378 eecd |= E1000_EECD_REQ;
379 E1000_WRITE_REG(hw, EECD, eecd);
380 eecd = E1000_READ_REG(hw, EECD);
381 while ((!(eecd & E1000_EECD_GNT)) &&
382 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
385 eecd = E1000_READ_REG(hw, EECD);
387 if (!(eecd & E1000_EECD_GNT)) {
388 eecd &= ~E1000_EECD_REQ;
389 E1000_WRITE_REG(hw, EECD, eecd);
390 DEBUGOUT("Could not acquire EEPROM grant\n");
391 return -E1000_ERR_EEPROM;
396 /* Setup EEPROM for Read/Write */
398 if (eeprom->type == e1000_eeprom_microwire) {
399 /* Clear SK and DI */
400 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
401 E1000_WRITE_REG(hw, EECD, eecd);
404 eecd |= E1000_EECD_CS;
405 E1000_WRITE_REG(hw, EECD, eecd);
406 } else if (eeprom->type == e1000_eeprom_spi) {
407 /* Clear SK and CS */
408 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
409 E1000_WRITE_REG(hw, EECD, eecd);
413 return E1000_SUCCESS;
416 /******************************************************************************
417 * Sets up eeprom variables in the hw struct. Must be called after mac_type
418 * is configured. Additionally, if this is ICH8, the flash controller GbE
419 * registers must be mapped, or this will crash.
421 * hw - Struct containing variables accessed by shared code
422 *****************************************************************************/
423 static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
425 struct e1000_eeprom_info *eeprom = &hw->eeprom;
427 int32_t ret_val = E1000_SUCCESS;
428 uint16_t eeprom_size;
430 if (hw->mac_type == e1000_igb)
431 eecd = E1000_READ_REG(hw, I210_EECD);
433 eecd = E1000_READ_REG(hw, EECD);
437 switch (hw->mac_type) {
438 case e1000_82542_rev2_0:
439 case e1000_82542_rev2_1:
442 eeprom->type = e1000_eeprom_microwire;
443 eeprom->word_size = 64;
444 eeprom->opcode_bits = 3;
445 eeprom->address_bits = 6;
446 eeprom->delay_usec = 50;
447 eeprom->use_eerd = false;
448 eeprom->use_eewr = false;
452 case e1000_82545_rev_3:
454 case e1000_82546_rev_3:
455 eeprom->type = e1000_eeprom_microwire;
456 eeprom->opcode_bits = 3;
457 eeprom->delay_usec = 50;
458 if (eecd & E1000_EECD_SIZE) {
459 eeprom->word_size = 256;
460 eeprom->address_bits = 8;
462 eeprom->word_size = 64;
463 eeprom->address_bits = 6;
465 eeprom->use_eerd = false;
466 eeprom->use_eewr = false;
469 case e1000_82541_rev_2:
471 case e1000_82547_rev_2:
472 if (eecd & E1000_EECD_TYPE) {
473 eeprom->type = e1000_eeprom_spi;
474 eeprom->opcode_bits = 8;
475 eeprom->delay_usec = 1;
476 if (eecd & E1000_EECD_ADDR_BITS) {
477 eeprom->page_size = 32;
478 eeprom->address_bits = 16;
480 eeprom->page_size = 8;
481 eeprom->address_bits = 8;
484 eeprom->type = e1000_eeprom_microwire;
485 eeprom->opcode_bits = 3;
486 eeprom->delay_usec = 50;
487 if (eecd & E1000_EECD_ADDR_BITS) {
488 eeprom->word_size = 256;
489 eeprom->address_bits = 8;
491 eeprom->word_size = 64;
492 eeprom->address_bits = 6;
495 eeprom->use_eerd = false;
496 eeprom->use_eewr = false;
500 eeprom->type = e1000_eeprom_spi;
501 eeprom->opcode_bits = 8;
502 eeprom->delay_usec = 1;
503 if (eecd & E1000_EECD_ADDR_BITS) {
504 eeprom->page_size = 32;
505 eeprom->address_bits = 16;
507 eeprom->page_size = 8;
508 eeprom->address_bits = 8;
510 eeprom->use_eerd = false;
511 eeprom->use_eewr = false;
515 eeprom->type = e1000_eeprom_spi;
516 eeprom->opcode_bits = 8;
517 eeprom->delay_usec = 1;
518 if (eecd & E1000_EECD_ADDR_BITS) {
519 eeprom->page_size = 32;
520 eeprom->address_bits = 16;
522 eeprom->page_size = 8;
523 eeprom->address_bits = 8;
525 if (e1000_is_onboard_nvm_eeprom(hw) == false) {
526 eeprom->use_eerd = true;
527 eeprom->use_eewr = true;
529 eeprom->type = e1000_eeprom_flash;
530 eeprom->word_size = 2048;
532 /* Ensure that the Autonomous FLASH update bit is cleared due to
533 * Flash update issue on parts which use a FLASH for NVM. */
534 eecd &= ~E1000_EECD_AUPDEN;
535 E1000_WRITE_REG(hw, EECD, eecd);
538 case e1000_80003es2lan:
539 eeprom->type = e1000_eeprom_spi;
540 eeprom->opcode_bits = 8;
541 eeprom->delay_usec = 1;
542 if (eecd & E1000_EECD_ADDR_BITS) {
543 eeprom->page_size = 32;
544 eeprom->address_bits = 16;
546 eeprom->page_size = 8;
547 eeprom->address_bits = 8;
549 eeprom->use_eerd = true;
550 eeprom->use_eewr = false;
553 /* i210 has 4k of iNVM mapped as EEPROM */
554 eeprom->type = e1000_eeprom_invm;
555 eeprom->opcode_bits = 8;
556 eeprom->delay_usec = 1;
557 eeprom->page_size = 32;
558 eeprom->address_bits = 16;
559 eeprom->use_eerd = true;
560 eeprom->use_eewr = false;
566 if (eeprom->type == e1000_eeprom_spi ||
567 eeprom->type == e1000_eeprom_invm) {
568 /* eeprom_size will be an enum [0..8] that maps
569 * to eeprom sizes 128B to
570 * 32KB (incremented by powers of 2).
572 if (hw->mac_type <= e1000_82547_rev_2) {
573 /* Set to default value for initial eeprom read. */
574 eeprom->word_size = 64;
575 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
579 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
580 >> EEPROM_SIZE_SHIFT;
581 /* 256B eeprom size was not supported in earlier
582 * hardware, so we bump eeprom_size up one to
583 * ensure that "1" (which maps to 256B) is never
584 * the result used in the shifting logic below. */
588 eeprom_size = (uint16_t)((eecd &
589 E1000_EECD_SIZE_EX_MASK) >>
590 E1000_EECD_SIZE_EX_SHIFT);
593 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
598 /******************************************************************************
599 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
601 * hw - Struct containing variables accessed by shared code
602 *****************************************************************************/
604 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
606 uint32_t attempts = 100000;
608 int32_t done = E1000_ERR_EEPROM;
610 for (i = 0; i < attempts; i++) {
611 if (eerd == E1000_EEPROM_POLL_READ) {
612 if (hw->mac_type == e1000_igb)
613 reg = E1000_READ_REG(hw, I210_EERD);
615 reg = E1000_READ_REG(hw, EERD);
617 if (hw->mac_type == e1000_igb)
618 reg = E1000_READ_REG(hw, I210_EEWR);
620 reg = E1000_READ_REG(hw, EEWR);
623 if (reg & E1000_EEPROM_RW_REG_DONE) {
624 done = E1000_SUCCESS;
633 /******************************************************************************
634 * Reads a 16 bit word from the EEPROM using the EERD register.
636 * hw - Struct containing variables accessed by shared code
637 * offset - offset of word in the EEPROM to read
638 * data - word read from the EEPROM
639 * words - number of words to read
640 *****************************************************************************/
642 e1000_read_eeprom_eerd(struct e1000_hw *hw,
647 uint32_t i, eerd = 0;
650 for (i = 0; i < words; i++) {
651 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
652 E1000_EEPROM_RW_REG_START;
654 if (hw->mac_type == e1000_igb)
655 E1000_WRITE_REG(hw, I210_EERD, eerd);
657 E1000_WRITE_REG(hw, EERD, eerd);
659 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
664 if (hw->mac_type == e1000_igb) {
665 data[i] = (E1000_READ_REG(hw, I210_EERD) >>
666 E1000_EEPROM_RW_REG_DATA);
668 data[i] = (E1000_READ_REG(hw, EERD) >>
669 E1000_EEPROM_RW_REG_DATA);
677 void e1000_release_eeprom(struct e1000_hw *hw)
683 eecd = E1000_READ_REG(hw, EECD);
685 if (hw->eeprom.type == e1000_eeprom_spi) {
686 eecd |= E1000_EECD_CS; /* Pull CS high */
687 eecd &= ~E1000_EECD_SK; /* Lower SCK */
689 E1000_WRITE_REG(hw, EECD, eecd);
691 udelay(hw->eeprom.delay_usec);
692 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
695 /* CS on Microwire is active-high */
696 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
698 E1000_WRITE_REG(hw, EECD, eecd);
700 /* Rising edge of clock */
701 eecd |= E1000_EECD_SK;
702 E1000_WRITE_REG(hw, EECD, eecd);
703 E1000_WRITE_FLUSH(hw);
704 udelay(hw->eeprom.delay_usec);
706 /* Falling edge of clock */
707 eecd &= ~E1000_EECD_SK;
708 E1000_WRITE_REG(hw, EECD, eecd);
709 E1000_WRITE_FLUSH(hw);
710 udelay(hw->eeprom.delay_usec);
713 /* Stop requesting EEPROM access */
714 if (hw->mac_type > e1000_82544) {
715 eecd &= ~E1000_EECD_REQ;
716 E1000_WRITE_REG(hw, EECD, eecd);
719 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
722 /******************************************************************************
723 * Reads a 16 bit word from the EEPROM.
725 * hw - Struct containing variables accessed by shared code
726 *****************************************************************************/
728 e1000_spi_eeprom_ready(struct e1000_hw *hw)
730 uint16_t retry_count = 0;
731 uint8_t spi_stat_reg;
735 /* Read "Status Register" repeatedly until the LSB is cleared. The
736 * EEPROM will signal that the command has been completed by clearing
737 * bit 0 of the internal status register. If it's not cleared within
738 * 5 milliseconds, then error out.
742 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
743 hw->eeprom.opcode_bits);
744 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
745 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
751 e1000_standby_eeprom(hw);
752 } while (retry_count < EEPROM_MAX_RETRY_SPI);
754 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
755 * only 0-5mSec on 5V devices)
757 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
758 DEBUGOUT("SPI EEPROM Status error\n");
759 return -E1000_ERR_EEPROM;
762 return E1000_SUCCESS;
765 /******************************************************************************
766 * Reads a 16 bit word from the EEPROM.
768 * hw - Struct containing variables accessed by shared code
769 * offset - offset of word in the EEPROM to read
770 * data - word read from the EEPROM
771 *****************************************************************************/
773 e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
774 uint16_t words, uint16_t *data)
776 struct e1000_eeprom_info *eeprom = &hw->eeprom;
781 /* If eeprom is not yet detected, do so now */
782 if (eeprom->word_size == 0)
783 e1000_init_eeprom_params(hw);
785 /* A check for invalid values: offset too large, too many words,
786 * and not enough words.
788 if ((offset >= eeprom->word_size) ||
789 (words > eeprom->word_size - offset) ||
791 DEBUGOUT("\"words\" parameter out of bounds."
792 "Words = %d, size = %d\n", offset, eeprom->word_size);
793 return -E1000_ERR_EEPROM;
796 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
797 * directly. In this case, we need to acquire the EEPROM so that
798 * FW or other port software does not interrupt.
800 if (e1000_is_onboard_nvm_eeprom(hw) == true &&
801 hw->eeprom.use_eerd == false) {
803 /* Prepare the EEPROM for bit-bang reading */
804 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
805 return -E1000_ERR_EEPROM;
808 /* Eerd register EEPROM access requires no eeprom aquire/release */
809 if (eeprom->use_eerd == true)
810 return e1000_read_eeprom_eerd(hw, offset, words, data);
812 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
813 * acquired the EEPROM at this point, so any returns should relase it */
814 if (eeprom->type == e1000_eeprom_spi) {
816 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
818 if (e1000_spi_eeprom_ready(hw)) {
819 e1000_release_eeprom(hw);
820 return -E1000_ERR_EEPROM;
823 e1000_standby_eeprom(hw);
825 /* Some SPI eeproms use the 8th address bit embedded in
827 if ((eeprom->address_bits == 8) && (offset >= 128))
828 read_opcode |= EEPROM_A8_OPCODE_SPI;
830 /* Send the READ command (opcode + addr) */
831 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
832 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
833 eeprom->address_bits);
835 /* Read the data. The address of the eeprom internally
836 * increments with each byte (spi) being read, saving on the
837 * overhead of eeprom setup and tear-down. The address
838 * counter will roll over if reading beyond the size of
839 * the eeprom, thus allowing the entire memory to be read
840 * starting from any offset. */
841 for (i = 0; i < words; i++) {
842 word_in = e1000_shift_in_ee_bits(hw, 16);
843 data[i] = (word_in >> 8) | (word_in << 8);
845 } else if (eeprom->type == e1000_eeprom_microwire) {
846 for (i = 0; i < words; i++) {
847 /* Send the READ command (opcode + addr) */
848 e1000_shift_out_ee_bits(hw,
849 EEPROM_READ_OPCODE_MICROWIRE,
850 eeprom->opcode_bits);
851 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
852 eeprom->address_bits);
854 /* Read the data. For microwire, each word requires
855 * the overhead of eeprom setup and tear-down. */
856 data[i] = e1000_shift_in_ee_bits(hw, 16);
857 e1000_standby_eeprom(hw);
861 /* End this read operation */
862 e1000_release_eeprom(hw);
864 return E1000_SUCCESS;
867 #ifndef CONFIG_DM_ETH
868 /******************************************************************************
869 * e1000_write_eeprom_srwr - Write to Shadow Ram using EEWR
870 * @hw: pointer to the HW structure
871 * @offset: offset within the Shadow Ram to be written to
872 * @words: number of words to write
873 * @data: 16 bit word(s) to be written to the Shadow Ram
875 * Writes data to Shadow Ram at offset using EEWR register.
877 * If e1000_update_eeprom_checksum_i210 is not called after this function, the
878 * Shadow Ram will most likely contain an invalid checksum.
879 *****************************************************************************/
880 static int32_t e1000_write_eeprom_srwr(struct e1000_hw *hw, uint16_t offset,
881 uint16_t words, uint16_t *data)
883 struct e1000_eeprom_info *eeprom = &hw->eeprom;
884 uint32_t i, k, eewr = 0;
885 uint32_t attempts = 100000;
888 /* A check for invalid values: offset too large, too many words,
889 * too many words for the offset, and not enough words.
891 if ((offset >= eeprom->word_size) ||
892 (words > (eeprom->word_size - offset)) || (words == 0)) {
893 DEBUGOUT("nvm parameter(s) out of bounds\n");
894 ret_val = -E1000_ERR_EEPROM;
898 for (i = 0; i < words; i++) {
899 eewr = ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT)
900 | (data[i] << E1000_EEPROM_RW_REG_DATA) |
901 E1000_EEPROM_RW_REG_START;
903 E1000_WRITE_REG(hw, I210_EEWR, eewr);
905 for (k = 0; k < attempts; k++) {
906 if (E1000_EEPROM_RW_REG_DONE &
907 E1000_READ_REG(hw, I210_EEWR)) {
915 DEBUGOUT("Shadow RAM write EEWR timed out\n");
924 /******************************************************************************
925 * e1000_pool_flash_update_done_i210 - Pool FLUDONE status.
926 * @hw: pointer to the HW structure
928 *****************************************************************************/
929 static int32_t e1000_pool_flash_update_done_i210(struct e1000_hw *hw)
931 int32_t ret_val = -E1000_ERR_EEPROM;
934 for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) {
935 reg = E1000_READ_REG(hw, EECD);
936 if (reg & E1000_EECD_FLUDONE_I210) {
946 /******************************************************************************
947 * e1000_update_flash_i210 - Commit EEPROM to the flash
948 * @hw: pointer to the HW structure
950 *****************************************************************************/
951 static int32_t e1000_update_flash_i210(struct e1000_hw *hw)
956 ret_val = e1000_pool_flash_update_done_i210(hw);
957 if (ret_val == -E1000_ERR_EEPROM) {
958 DEBUGOUT("Flash update time out\n");
962 flup = E1000_READ_REG(hw, EECD) | E1000_EECD_FLUPD_I210;
963 E1000_WRITE_REG(hw, EECD, flup);
965 ret_val = e1000_pool_flash_update_done_i210(hw);
967 DEBUGOUT("Flash update time out\n");
969 DEBUGOUT("Flash update complete\n");
975 /******************************************************************************
976 * e1000_update_eeprom_checksum_i210 - Update EEPROM checksum
977 * @hw: pointer to the HW structure
979 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
980 * up to the checksum. Then calculates the EEPROM checksum and writes the
981 * value to the EEPROM. Next commit EEPROM data onto the Flash.
982 *****************************************************************************/
983 static int32_t e1000_update_eeprom_checksum_i210(struct e1000_hw *hw)
986 uint16_t checksum = 0;
987 uint16_t i, nvm_data;
989 /* Read the first word from the EEPROM. If this times out or fails, do
990 * not continue or we could be in for a very long wait while every
993 ret_val = e1000_read_eeprom_eerd(hw, 0, 1, &nvm_data);
995 DEBUGOUT("EEPROM read failed\n");
999 if (!(e1000_get_hw_eeprom_semaphore(hw))) {
1000 /* Do not use hw->nvm.ops.write, hw->nvm.ops.read
1001 * because we do not want to take the synchronization
1002 * semaphores twice here.
1005 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
1006 ret_val = e1000_read_eeprom_eerd(hw, i, 1, &nvm_data);
1008 e1000_put_hw_eeprom_semaphore(hw);
1009 DEBUGOUT("EEPROM Read Error while updating checksum.\n");
1012 checksum += nvm_data;
1014 checksum = (uint16_t)EEPROM_SUM - checksum;
1015 ret_val = e1000_write_eeprom_srwr(hw, EEPROM_CHECKSUM_REG, 1,
1018 e1000_put_hw_eeprom_semaphore(hw);
1019 DEBUGOUT("EEPROM Write Error while updating checksum.\n");
1023 e1000_put_hw_eeprom_semaphore(hw);
1025 ret_val = e1000_update_flash_i210(hw);
1027 ret_val = -E1000_ERR_SWFW_SYNC;
1035 /******************************************************************************
1036 * Verifies that the EEPROM has a valid checksum
1038 * hw - Struct containing variables accessed by shared code
1040 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
1041 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
1043 *****************************************************************************/
1044 static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
1046 uint16_t i, checksum, checksum_reg, *buf;
1050 /* Allocate a temporary buffer */
1051 buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
1053 E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n");
1054 return -E1000_ERR_EEPROM;
1057 /* Read the EEPROM */
1058 if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
1059 E1000_ERR(hw, "Unable to read EEPROM!\n");
1060 return -E1000_ERR_EEPROM;
1063 /* Compute the checksum */
1065 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
1067 checksum = ((uint16_t)EEPROM_SUM) - checksum;
1068 checksum_reg = buf[i];
1071 if (checksum == checksum_reg)
1074 /* Hrm, verification failed, print an error */
1075 E1000_ERR(hw, "EEPROM checksum is incorrect!\n");
1076 E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n",
1077 checksum_reg, checksum);
1079 return -E1000_ERR_EEPROM;
1081 #endif /* CONFIG_E1000_NO_NVM */
1083 /*****************************************************************************
1084 * Set PHY to class A mode
1085 * Assumes the following operations will follow to enable the new class mode.
1086 * 1. Do a PHY soft reset
1087 * 2. Restart auto-negotiation or force link.
1089 * hw - Struct containing variables accessed by shared code
1090 ****************************************************************************/
1092 e1000_set_phy_mode(struct e1000_hw *hw)
1094 #ifndef CONFIG_E1000_NO_NVM
1096 uint16_t eeprom_data;
1100 if ((hw->mac_type == e1000_82545_rev_3) &&
1101 (hw->media_type == e1000_media_type_copper)) {
1102 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
1107 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
1108 (eeprom_data & EEPROM_PHY_CLASS_A)) {
1109 ret_val = e1000_write_phy_reg(hw,
1110 M88E1000_PHY_PAGE_SELECT, 0x000B);
1113 ret_val = e1000_write_phy_reg(hw,
1114 M88E1000_PHY_GEN_CONTROL, 0x8104);
1118 hw->phy_reset_disable = false;
1122 return E1000_SUCCESS;
1125 #ifndef CONFIG_E1000_NO_NVM
1126 /***************************************************************************
1128 * Obtaining software semaphore bit (SMBI) before resetting PHY.
1130 * hw: Struct containing variables accessed by shared code
1132 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
1133 * E1000_SUCCESS at any other case.
1135 ***************************************************************************/
1137 e1000_get_software_semaphore(struct e1000_hw *hw)
1139 int32_t timeout = hw->eeprom.word_size + 1;
1144 if (hw->mac_type != e1000_80003es2lan && hw->mac_type != e1000_igb)
1145 return E1000_SUCCESS;
1148 swsm = E1000_READ_REG(hw, SWSM);
1149 /* If SMBI bit cleared, it is now set and we hold
1151 if (!(swsm & E1000_SWSM_SMBI))
1158 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
1159 return -E1000_ERR_RESET;
1162 return E1000_SUCCESS;
1166 /***************************************************************************
1167 * This function clears HW semaphore bits.
1169 * hw: Struct containing variables accessed by shared code
1173 ***************************************************************************/
1175 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
1177 #ifndef CONFIG_E1000_NO_NVM
1182 if (!hw->eeprom_semaphore_present)
1185 swsm = E1000_READ_REG(hw, SWSM);
1186 if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) {
1187 /* Release both semaphores. */
1188 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1190 swsm &= ~(E1000_SWSM_SWESMBI);
1191 E1000_WRITE_REG(hw, SWSM, swsm);
1195 /***************************************************************************
1197 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
1198 * adapter or Eeprom access.
1200 * hw: Struct containing variables accessed by shared code
1202 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
1203 * E1000_SUCCESS at any other case.
1205 ***************************************************************************/
1207 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
1209 #ifndef CONFIG_E1000_NO_NVM
1215 if (!hw->eeprom_semaphore_present)
1216 return E1000_SUCCESS;
1218 if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) {
1219 /* Get the SW semaphore. */
1220 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
1221 return -E1000_ERR_EEPROM;
1224 /* Get the FW semaphore. */
1225 timeout = hw->eeprom.word_size + 1;
1227 swsm = E1000_READ_REG(hw, SWSM);
1228 swsm |= E1000_SWSM_SWESMBI;
1229 E1000_WRITE_REG(hw, SWSM, swsm);
1230 /* if we managed to set the bit we got the semaphore. */
1231 swsm = E1000_READ_REG(hw, SWSM);
1232 if (swsm & E1000_SWSM_SWESMBI)
1240 /* Release semaphores */
1241 e1000_put_hw_eeprom_semaphore(hw);
1242 DEBUGOUT("Driver can't access the Eeprom - "
1243 "SWESMBI bit is set.\n");
1244 return -E1000_ERR_EEPROM;
1247 return E1000_SUCCESS;
1250 /* Take ownership of the PHY */
1252 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
1254 uint32_t swfw_sync = 0;
1255 uint32_t swmask = mask;
1256 uint32_t fwmask = mask << 16;
1257 int32_t timeout = 200;
1261 if (e1000_get_hw_eeprom_semaphore(hw))
1262 return -E1000_ERR_SWFW_SYNC;
1264 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1265 if (!(swfw_sync & (fwmask | swmask)))
1268 /* firmware currently using resource (fwmask) */
1269 /* or other software thread currently using resource (swmask) */
1270 e1000_put_hw_eeprom_semaphore(hw);
1276 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1277 return -E1000_ERR_SWFW_SYNC;
1280 swfw_sync |= swmask;
1281 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1283 e1000_put_hw_eeprom_semaphore(hw);
1284 return E1000_SUCCESS;
1287 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
1289 uint32_t swfw_sync = 0;
1292 while (e1000_get_hw_eeprom_semaphore(hw))
1295 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1297 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1299 e1000_put_hw_eeprom_semaphore(hw);
1302 static bool e1000_is_second_port(struct e1000_hw *hw)
1304 switch (hw->mac_type) {
1305 case e1000_80003es2lan:
1308 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
1316 #ifndef CONFIG_E1000_NO_NVM
1317 /******************************************************************************
1318 * Reads the adapter's MAC address from the EEPROM
1320 * hw - Struct containing variables accessed by shared code
1321 * enetaddr - buffering where the MAC address will be stored
1322 *****************************************************************************/
1323 static int e1000_read_mac_addr_from_eeprom(struct e1000_hw *hw,
1324 unsigned char enetaddr[6])
1327 uint16_t eeprom_data;
1330 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1332 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
1333 DEBUGOUT("EEPROM Read Error\n");
1334 return -E1000_ERR_EEPROM;
1336 enetaddr[i] = eeprom_data & 0xff;
1337 enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
1343 /******************************************************************************
1344 * Reads the adapter's MAC address from the RAL/RAH registers
1346 * hw - Struct containing variables accessed by shared code
1347 * enetaddr - buffering where the MAC address will be stored
1348 *****************************************************************************/
1349 static int e1000_read_mac_addr_from_regs(struct e1000_hw *hw,
1350 unsigned char enetaddr[6])
1352 uint16_t offset, tmp;
1353 uint32_t reg_data = 0;
1356 if (hw->mac_type != e1000_igb)
1357 return -E1000_ERR_MAC_TYPE;
1359 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1363 reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
1364 else if (offset == 1)
1366 else if (offset == 2)
1367 reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
1368 tmp = reg_data & 0xffff;
1370 enetaddr[i] = tmp & 0xff;
1371 enetaddr[i + 1] = (tmp >> 8) & 0xff;
1377 /******************************************************************************
1378 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
1379 * second function of dual function devices
1381 * hw - Struct containing variables accessed by shared code
1382 * enetaddr - buffering where the MAC address will be stored
1383 *****************************************************************************/
1384 static int e1000_read_mac_addr(struct e1000_hw *hw, unsigned char enetaddr[6])
1388 if (hw->mac_type == e1000_igb) {
1389 /* i210 preloads MAC address into RAL/RAH registers */
1390 ret_val = e1000_read_mac_addr_from_regs(hw, enetaddr);
1392 ret_val = e1000_read_mac_addr_from_eeprom(hw, enetaddr);
1397 /* Invert the last bit if this is the second device */
1398 if (e1000_is_second_port(hw))
1405 /******************************************************************************
1406 * Initializes receive address filters.
1408 * hw - Struct containing variables accessed by shared code
1410 * Places the MAC address in receive address register 0 and clears the rest
1411 * of the receive addresss registers. Clears the multicast table. Assumes
1412 * the receiver is in reset when the routine is called.
1413 *****************************************************************************/
1415 e1000_init_rx_addrs(struct e1000_hw *hw, unsigned char enetaddr[6])
1423 /* Setup the receive address. */
1424 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1425 addr_low = (enetaddr[0] |
1426 (enetaddr[1] << 8) |
1427 (enetaddr[2] << 16) | (enetaddr[3] << 24));
1429 addr_high = (enetaddr[4] | (enetaddr[5] << 8) | E1000_RAH_AV);
1431 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
1432 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
1434 /* Zero out the other 15 receive addresses. */
1435 DEBUGOUT("Clearing RAR[1-15]\n");
1436 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
1437 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
1438 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
1442 /******************************************************************************
1443 * Clears the VLAN filer table
1445 * hw - Struct containing variables accessed by shared code
1446 *****************************************************************************/
1448 e1000_clear_vfta(struct e1000_hw *hw)
1452 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
1453 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
1456 /******************************************************************************
1457 * Set the mac type member in the hw struct.
1459 * hw - Struct containing variables accessed by shared code
1460 *****************************************************************************/
1462 e1000_set_mac_type(struct e1000_hw *hw)
1466 switch (hw->device_id) {
1467 case E1000_DEV_ID_82542:
1468 switch (hw->revision_id) {
1469 case E1000_82542_2_0_REV_ID:
1470 hw->mac_type = e1000_82542_rev2_0;
1472 case E1000_82542_2_1_REV_ID:
1473 hw->mac_type = e1000_82542_rev2_1;
1476 /* Invalid 82542 revision ID */
1477 return -E1000_ERR_MAC_TYPE;
1480 case E1000_DEV_ID_82543GC_FIBER:
1481 case E1000_DEV_ID_82543GC_COPPER:
1482 hw->mac_type = e1000_82543;
1484 case E1000_DEV_ID_82544EI_COPPER:
1485 case E1000_DEV_ID_82544EI_FIBER:
1486 case E1000_DEV_ID_82544GC_COPPER:
1487 case E1000_DEV_ID_82544GC_LOM:
1488 hw->mac_type = e1000_82544;
1490 case E1000_DEV_ID_82540EM:
1491 case E1000_DEV_ID_82540EM_LOM:
1492 case E1000_DEV_ID_82540EP:
1493 case E1000_DEV_ID_82540EP_LOM:
1494 case E1000_DEV_ID_82540EP_LP:
1495 hw->mac_type = e1000_82540;
1497 case E1000_DEV_ID_82545EM_COPPER:
1498 case E1000_DEV_ID_82545EM_FIBER:
1499 hw->mac_type = e1000_82545;
1501 case E1000_DEV_ID_82545GM_COPPER:
1502 case E1000_DEV_ID_82545GM_FIBER:
1503 case E1000_DEV_ID_82545GM_SERDES:
1504 hw->mac_type = e1000_82545_rev_3;
1506 case E1000_DEV_ID_82546EB_COPPER:
1507 case E1000_DEV_ID_82546EB_FIBER:
1508 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1509 hw->mac_type = e1000_82546;
1511 case E1000_DEV_ID_82546GB_COPPER:
1512 case E1000_DEV_ID_82546GB_FIBER:
1513 case E1000_DEV_ID_82546GB_SERDES:
1514 case E1000_DEV_ID_82546GB_PCIE:
1515 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1516 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1517 hw->mac_type = e1000_82546_rev_3;
1519 case E1000_DEV_ID_82541EI:
1520 case E1000_DEV_ID_82541EI_MOBILE:
1521 case E1000_DEV_ID_82541ER_LOM:
1522 hw->mac_type = e1000_82541;
1524 case E1000_DEV_ID_82541ER:
1525 case E1000_DEV_ID_82541GI:
1526 case E1000_DEV_ID_82541GI_LF:
1527 case E1000_DEV_ID_82541GI_MOBILE:
1528 hw->mac_type = e1000_82541_rev_2;
1530 case E1000_DEV_ID_82547EI:
1531 case E1000_DEV_ID_82547EI_MOBILE:
1532 hw->mac_type = e1000_82547;
1534 case E1000_DEV_ID_82547GI:
1535 hw->mac_type = e1000_82547_rev_2;
1537 case E1000_DEV_ID_82571EB_COPPER:
1538 case E1000_DEV_ID_82571EB_FIBER:
1539 case E1000_DEV_ID_82571EB_SERDES:
1540 case E1000_DEV_ID_82571EB_SERDES_DUAL:
1541 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1542 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1543 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1544 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1545 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1546 hw->mac_type = e1000_82571;
1548 case E1000_DEV_ID_82572EI_COPPER:
1549 case E1000_DEV_ID_82572EI_FIBER:
1550 case E1000_DEV_ID_82572EI_SERDES:
1551 case E1000_DEV_ID_82572EI:
1552 hw->mac_type = e1000_82572;
1554 case E1000_DEV_ID_82573E:
1555 case E1000_DEV_ID_82573E_IAMT:
1556 case E1000_DEV_ID_82573L:
1557 hw->mac_type = e1000_82573;
1559 case E1000_DEV_ID_82574L:
1560 hw->mac_type = e1000_82574;
1562 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
1563 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
1564 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
1565 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
1566 hw->mac_type = e1000_80003es2lan;
1568 case E1000_DEV_ID_ICH8_IGP_M_AMT:
1569 case E1000_DEV_ID_ICH8_IGP_AMT:
1570 case E1000_DEV_ID_ICH8_IGP_C:
1571 case E1000_DEV_ID_ICH8_IFE:
1572 case E1000_DEV_ID_ICH8_IFE_GT:
1573 case E1000_DEV_ID_ICH8_IFE_G:
1574 case E1000_DEV_ID_ICH8_IGP_M:
1575 hw->mac_type = e1000_ich8lan;
1577 case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED:
1578 case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED:
1579 case PCI_DEVICE_ID_INTEL_I210_COPPER:
1580 case PCI_DEVICE_ID_INTEL_I211_COPPER:
1581 case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
1582 case PCI_DEVICE_ID_INTEL_I210_SERDES:
1583 case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
1584 case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
1585 hw->mac_type = e1000_igb;
1588 /* Should never have loaded on this device */
1589 return -E1000_ERR_MAC_TYPE;
1591 return E1000_SUCCESS;
1594 /******************************************************************************
1595 * Reset the transmit and receive units; mask and clear all interrupts.
1597 * hw - Struct containing variables accessed by shared code
1598 *****************************************************************************/
1600 e1000_reset_hw(struct e1000_hw *hw)
1610 /* get the correct pba value for both PCI and PCIe*/
1611 if (hw->mac_type < e1000_82571)
1612 pba = E1000_DEFAULT_PCI_PBA;
1614 pba = E1000_DEFAULT_PCIE_PBA;
1616 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
1617 if (hw->mac_type == e1000_82542_rev2_0) {
1618 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1619 #ifdef CONFIG_DM_ETH
1620 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1621 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1623 pci_write_config_word(hw->pdev, PCI_COMMAND,
1624 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1628 /* Clear interrupt mask to stop board from generating interrupts */
1629 DEBUGOUT("Masking off all interrupts\n");
1630 if (hw->mac_type == e1000_igb)
1631 E1000_WRITE_REG(hw, I210_IAM, 0);
1632 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1634 /* Disable the Transmit and Receive units. Then delay to allow
1635 * any pending transactions to complete before we hit the MAC with
1638 E1000_WRITE_REG(hw, RCTL, 0);
1639 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
1640 E1000_WRITE_FLUSH(hw);
1642 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
1643 hw->tbi_compatibility_on = false;
1645 /* Delay to allow any outstanding PCI transactions to complete before
1646 * resetting the device
1650 /* Issue a global reset to the MAC. This will reset the chip's
1651 * transmit, receive, DMA, and link units. It will not effect
1652 * the current PCI configuration. The global reset bit is self-
1653 * clearing, and should clear within a microsecond.
1655 DEBUGOUT("Issuing a global reset to MAC\n");
1656 ctrl = E1000_READ_REG(hw, CTRL);
1658 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
1660 /* Force a reload from the EEPROM if necessary */
1661 if (hw->mac_type == e1000_igb) {
1663 reg = E1000_READ_REG(hw, STATUS);
1664 if (reg & E1000_STATUS_PF_RST_DONE)
1665 DEBUGOUT("PF OK\n");
1666 reg = E1000_READ_REG(hw, I210_EECD);
1667 if (reg & E1000_EECD_AUTO_RD)
1668 DEBUGOUT("EEC OK\n");
1669 } else if (hw->mac_type < e1000_82540) {
1670 /* Wait for reset to complete */
1672 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1673 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1674 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1675 E1000_WRITE_FLUSH(hw);
1676 /* Wait for EEPROM reload */
1679 /* Wait for EEPROM reload (it happens automatically) */
1681 /* Dissable HW ARPs on ASF enabled adapters */
1682 manc = E1000_READ_REG(hw, MANC);
1683 manc &= ~(E1000_MANC_ARP_EN);
1684 E1000_WRITE_REG(hw, MANC, manc);
1687 /* Clear interrupt mask to stop board from generating interrupts */
1688 DEBUGOUT("Masking off all interrupts\n");
1689 if (hw->mac_type == e1000_igb)
1690 E1000_WRITE_REG(hw, I210_IAM, 0);
1691 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1693 /* Clear any pending interrupt events. */
1694 E1000_READ_REG(hw, ICR);
1696 /* If MWI was previously enabled, reenable it. */
1697 if (hw->mac_type == e1000_82542_rev2_0) {
1698 #ifdef CONFIG_DM_ETH
1699 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1701 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1704 if (hw->mac_type != e1000_igb)
1705 E1000_WRITE_REG(hw, PBA, pba);
1708 /******************************************************************************
1710 * Initialize a number of hardware-dependent bits
1712 * hw: Struct containing variables accessed by shared code
1714 * This function contains hardware limitation workarounds for PCI-E adapters
1716 *****************************************************************************/
1718 e1000_initialize_hardware_bits(struct e1000_hw *hw)
1720 if ((hw->mac_type >= e1000_82571) &&
1721 (!hw->initialize_hw_bits_disable)) {
1722 /* Settings common to all PCI-express silicon */
1723 uint32_t reg_ctrl, reg_ctrl_ext;
1724 uint32_t reg_tarc0, reg_tarc1;
1726 uint32_t reg_txdctl, reg_txdctl1;
1728 /* link autonegotiation/sync workarounds */
1729 reg_tarc0 = E1000_READ_REG(hw, TARC0);
1730 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1732 /* Enable not-done TX descriptor counting */
1733 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
1734 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
1735 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
1737 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
1738 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
1739 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
1742 switch (hw->mac_type) {
1743 case e1000_igb: /* IGB is cool */
1747 /* Clear PHY TX compatible mode bits */
1748 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1749 reg_tarc1 &= ~((1 << 30)|(1 << 29));
1751 /* link autonegotiation/sync workarounds */
1752 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1754 /* TX ring control fixes */
1755 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
1757 /* Multiple read bit is reversed polarity */
1758 reg_tctl = E1000_READ_REG(hw, TCTL);
1759 if (reg_tctl & E1000_TCTL_MULR)
1760 reg_tarc1 &= ~(1 << 28);
1762 reg_tarc1 |= (1 << 28);
1764 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1768 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1769 reg_ctrl_ext &= ~(1 << 23);
1770 reg_ctrl_ext |= (1 << 22);
1772 /* TX byte count fix */
1773 reg_ctrl = E1000_READ_REG(hw, CTRL);
1774 reg_ctrl &= ~(1 << 29);
1776 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1777 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
1779 case e1000_80003es2lan:
1780 /* improve small packet performace for fiber/serdes */
1781 if ((hw->media_type == e1000_media_type_fiber)
1782 || (hw->media_type ==
1783 e1000_media_type_internal_serdes)) {
1784 reg_tarc0 &= ~(1 << 20);
1787 /* Multiple read bit is reversed polarity */
1788 reg_tctl = E1000_READ_REG(hw, TCTL);
1789 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1790 if (reg_tctl & E1000_TCTL_MULR)
1791 reg_tarc1 &= ~(1 << 28);
1793 reg_tarc1 |= (1 << 28);
1795 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1798 /* Reduce concurrent DMA requests to 3 from 4 */
1799 if ((hw->revision_id < 3) ||
1800 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1801 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
1802 reg_tarc0 |= ((1 << 29)|(1 << 28));
1804 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1805 reg_ctrl_ext |= (1 << 22);
1806 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1808 /* workaround TX hang with TSO=on */
1809 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1811 /* Multiple read bit is reversed polarity */
1812 reg_tctl = E1000_READ_REG(hw, TCTL);
1813 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1814 if (reg_tctl & E1000_TCTL_MULR)
1815 reg_tarc1 &= ~(1 << 28);
1817 reg_tarc1 |= (1 << 28);
1819 /* workaround TX hang with TSO=on */
1820 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
1822 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1828 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
1832 /******************************************************************************
1833 * Performs basic configuration of the adapter.
1835 * hw - Struct containing variables accessed by shared code
1837 * Assumes that the controller has previously been reset and is in a
1838 * post-reset uninitialized state. Initializes the receive address registers,
1839 * multicast table, and VLAN filter table. Calls routines to setup link
1840 * configuration and flow control settings. Clears all on-chip counters. Leaves
1841 * the transmit and receive units disabled and uninitialized.
1842 *****************************************************************************/
1844 e1000_init_hw(struct e1000_hw *hw, unsigned char enetaddr[6])
1849 uint16_t pcix_cmd_word;
1850 uint16_t pcix_stat_hi_word;
1852 uint16_t stat_mmrbc;
1857 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
1858 if ((hw->mac_type == e1000_ich8lan) &&
1859 ((hw->revision_id < 3) ||
1860 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1861 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
1862 reg_data = E1000_READ_REG(hw, STATUS);
1863 reg_data &= ~0x80000000;
1864 E1000_WRITE_REG(hw, STATUS, reg_data);
1866 /* Do not need initialize Identification LED */
1868 /* Set the media type and TBI compatibility */
1869 e1000_set_media_type(hw);
1871 /* Must be called after e1000_set_media_type
1872 * because media_type is used */
1873 e1000_initialize_hardware_bits(hw);
1875 /* Disabling VLAN filtering. */
1876 DEBUGOUT("Initializing the IEEE VLAN\n");
1877 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
1878 if (hw->mac_type != e1000_ich8lan) {
1879 if (hw->mac_type < e1000_82545_rev_3)
1880 E1000_WRITE_REG(hw, VET, 0);
1881 e1000_clear_vfta(hw);
1884 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
1885 if (hw->mac_type == e1000_82542_rev2_0) {
1886 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1887 #ifdef CONFIG_DM_ETH
1888 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1890 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1892 pci_write_config_word(hw->pdev, PCI_COMMAND,
1894 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1896 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
1897 E1000_WRITE_FLUSH(hw);
1901 /* Setup the receive address. This involves initializing all of the Receive
1902 * Address Registers (RARs 0 - 15).
1904 e1000_init_rx_addrs(hw, enetaddr);
1906 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
1907 if (hw->mac_type == e1000_82542_rev2_0) {
1908 E1000_WRITE_REG(hw, RCTL, 0);
1909 E1000_WRITE_FLUSH(hw);
1911 #ifdef CONFIG_DM_ETH
1912 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1914 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1918 /* Zero out the Multicast HASH table */
1919 DEBUGOUT("Zeroing the MTA\n");
1920 mta_size = E1000_MC_TBL_SIZE;
1921 if (hw->mac_type == e1000_ich8lan)
1922 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
1923 for (i = 0; i < mta_size; i++) {
1924 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1925 /* use write flush to prevent Memory Write Block (MWB) from
1926 * occuring when accessing our register space */
1927 E1000_WRITE_FLUSH(hw);
1930 switch (hw->mac_type) {
1931 case e1000_82545_rev_3:
1932 case e1000_82546_rev_3:
1936 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
1937 if (hw->bus_type == e1000_bus_type_pcix) {
1938 #ifdef CONFIG_DM_ETH
1939 dm_pci_read_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1941 dm_pci_read_config16(hw->pdev, PCIX_STATUS_REGISTER_HI,
1942 &pcix_stat_hi_word);
1944 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1946 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
1947 &pcix_stat_hi_word);
1950 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
1951 PCIX_COMMAND_MMRBC_SHIFT;
1953 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
1954 PCIX_STATUS_HI_MMRBC_SHIFT;
1955 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
1956 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1957 if (cmd_mmrbc > stat_mmrbc) {
1958 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1959 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1960 #ifdef CONFIG_DM_ETH
1961 dm_pci_write_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1964 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1972 /* More time needed for PHY to initialize */
1973 if (hw->mac_type == e1000_ich8lan)
1975 if (hw->mac_type == e1000_igb)
1978 /* Call a subroutine to configure the link and setup flow control. */
1979 ret_val = e1000_setup_link(hw);
1981 /* Set the transmit descriptor write-back policy */
1982 if (hw->mac_type > e1000_82544) {
1983 ctrl = E1000_READ_REG(hw, TXDCTL);
1985 (ctrl & ~E1000_TXDCTL_WTHRESH) |
1986 E1000_TXDCTL_FULL_TX_DESC_WB;
1987 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1990 /* Set the receive descriptor write back policy */
1991 if (hw->mac_type >= e1000_82571) {
1992 ctrl = E1000_READ_REG(hw, RXDCTL);
1994 (ctrl & ~E1000_RXDCTL_WTHRESH) |
1995 E1000_RXDCTL_FULL_RX_DESC_WB;
1996 E1000_WRITE_REG(hw, RXDCTL, ctrl);
1999 switch (hw->mac_type) {
2002 case e1000_80003es2lan:
2003 /* Enable retransmit on late collisions */
2004 reg_data = E1000_READ_REG(hw, TCTL);
2005 reg_data |= E1000_TCTL_RTLC;
2006 E1000_WRITE_REG(hw, TCTL, reg_data);
2008 /* Configure Gigabit Carry Extend Padding */
2009 reg_data = E1000_READ_REG(hw, TCTL_EXT);
2010 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
2011 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
2012 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
2014 /* Configure Transmit Inter-Packet Gap */
2015 reg_data = E1000_READ_REG(hw, TIPG);
2016 reg_data &= ~E1000_TIPG_IPGT_MASK;
2017 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2018 E1000_WRITE_REG(hw, TIPG, reg_data);
2020 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
2021 reg_data &= ~0x00100000;
2022 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
2027 ctrl = E1000_READ_REG(hw, TXDCTL1);
2028 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
2029 | E1000_TXDCTL_FULL_TX_DESC_WB;
2030 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
2034 reg_data = E1000_READ_REG(hw, GCR);
2035 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
2036 E1000_WRITE_REG(hw, GCR, reg_data);
2041 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
2042 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
2043 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2044 /* Relaxed ordering must be disabled to avoid a parity
2045 * error crash in a PCI slot. */
2046 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2047 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2053 /******************************************************************************
2054 * Configures flow control and link settings.
2056 * hw - Struct containing variables accessed by shared code
2058 * Determines which flow control settings to use. Calls the apropriate media-
2059 * specific link configuration function. Configures the flow control settings.
2060 * Assuming the adapter has a valid link partner, a valid link should be
2061 * established. Assumes the hardware has previously been reset and the
2062 * transmitter and receiver are not enabled.
2063 *****************************************************************************/
2065 e1000_setup_link(struct e1000_hw *hw)
2068 #ifndef CONFIG_E1000_NO_NVM
2070 uint16_t eeprom_data;
2075 /* In the case of the phy reset being blocked, we already have a link.
2076 * We do not have to set it up again. */
2077 if (e1000_check_phy_reset_block(hw))
2078 return E1000_SUCCESS;
2080 #ifndef CONFIG_E1000_NO_NVM
2081 /* Read and store word 0x0F of the EEPROM. This word contains bits
2082 * that determine the hardware's default PAUSE (flow control) mode,
2083 * a bit that determines whether the HW defaults to enabling or
2084 * disabling auto-negotiation, and the direction of the
2085 * SW defined pins. If there is no SW over-ride of the flow
2086 * control setting, then the variable hw->fc will
2087 * be initialized based on a value in the EEPROM.
2089 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
2090 &eeprom_data) < 0) {
2091 DEBUGOUT("EEPROM Read Error\n");
2092 return -E1000_ERR_EEPROM;
2095 if (hw->fc == e1000_fc_default) {
2096 switch (hw->mac_type) {
2101 hw->fc = e1000_fc_full;
2104 #ifndef CONFIG_E1000_NO_NVM
2105 ret_val = e1000_read_eeprom(hw,
2106 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
2108 DEBUGOUT("EEPROM Read Error\n");
2109 return -E1000_ERR_EEPROM;
2111 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
2112 hw->fc = e1000_fc_none;
2113 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
2114 EEPROM_WORD0F_ASM_DIR)
2115 hw->fc = e1000_fc_tx_pause;
2118 hw->fc = e1000_fc_full;
2123 /* We want to save off the original Flow Control configuration just
2124 * in case we get disconnected and then reconnected into a different
2125 * hub or switch with different Flow Control capabilities.
2127 if (hw->mac_type == e1000_82542_rev2_0)
2128 hw->fc &= (~e1000_fc_tx_pause);
2130 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
2131 hw->fc &= (~e1000_fc_rx_pause);
2133 hw->original_fc = hw->fc;
2135 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
2137 #ifndef CONFIG_E1000_NO_NVM
2138 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
2139 * polarity value for the SW controlled pins, and setup the
2140 * Extended Device Control reg with that info.
2141 * This is needed because one of the SW controlled pins is used for
2142 * signal detection. So this should be done before e1000_setup_pcs_link()
2143 * or e1000_phy_setup() is called.
2145 if (hw->mac_type == e1000_82543) {
2146 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
2148 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2152 /* Call the necessary subroutine to configure the link. */
2153 ret_val = (hw->media_type == e1000_media_type_fiber) ?
2154 e1000_setup_fiber_link(hw) : e1000_setup_copper_link(hw);
2159 /* Initialize the flow control address, type, and PAUSE timer
2160 * registers to their default values. This is done even if flow
2161 * control is disabled, because it does not hurt anything to
2162 * initialize these registers.
2164 DEBUGOUT("Initializing the Flow Control address, type"
2165 "and timer regs\n");
2167 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
2168 if (hw->mac_type != e1000_ich8lan) {
2169 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
2170 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
2171 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
2174 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
2176 /* Set the flow control receive threshold registers. Normally,
2177 * these registers will be set to a default threshold that may be
2178 * adjusted later by the driver's runtime code. However, if the
2179 * ability to transmit pause frames in not enabled, then these
2180 * registers will be set to 0.
2182 if (!(hw->fc & e1000_fc_tx_pause)) {
2183 E1000_WRITE_REG(hw, FCRTL, 0);
2184 E1000_WRITE_REG(hw, FCRTH, 0);
2186 /* We need to set up the Receive Threshold high and low water marks
2187 * as well as (optionally) enabling the transmission of XON frames.
2189 if (hw->fc_send_xon) {
2190 E1000_WRITE_REG(hw, FCRTL,
2191 (hw->fc_low_water | E1000_FCRTL_XONE));
2192 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2194 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
2195 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2201 /******************************************************************************
2202 * Sets up link for a fiber based adapter
2204 * hw - Struct containing variables accessed by shared code
2206 * Manipulates Physical Coding Sublayer functions in order to configure
2207 * link. Assumes the hardware has been previously reset and the transmitter
2208 * and receiver are not enabled.
2209 *****************************************************************************/
2211 e1000_setup_fiber_link(struct e1000_hw *hw)
2221 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
2222 * set when the optics detect a signal. On older adapters, it will be
2223 * cleared when there is a signal
2225 ctrl = E1000_READ_REG(hw, CTRL);
2226 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
2227 signal = E1000_CTRL_SWDPIN1;
2231 printf("signal for %s is %x (ctrl %08x)!!!!\n", hw->name, signal,
2233 /* Take the link out of reset */
2234 ctrl &= ~(E1000_CTRL_LRST);
2236 e1000_config_collision_dist(hw);
2238 /* Check for a software override of the flow control settings, and setup
2239 * the device accordingly. If auto-negotiation is enabled, then software
2240 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
2241 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
2242 * auto-negotiation is disabled, then software will have to manually
2243 * configure the two flow control enable bits in the CTRL register.
2245 * The possible values of the "fc" parameter are:
2246 * 0: Flow control is completely disabled
2247 * 1: Rx flow control is enabled (we can receive pause frames, but
2248 * not send pause frames).
2249 * 2: Tx flow control is enabled (we can send pause frames but we do
2250 * not support receiving pause frames).
2251 * 3: Both Rx and TX flow control (symmetric) are enabled.
2255 /* Flow control is completely disabled by a software over-ride. */
2256 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
2258 case e1000_fc_rx_pause:
2259 /* RX Flow control is enabled and TX Flow control is disabled by a
2260 * software over-ride. Since there really isn't a way to advertise
2261 * that we are capable of RX Pause ONLY, we will advertise that we
2262 * support both symmetric and asymmetric RX PAUSE. Later, we will
2263 * disable the adapter's ability to send PAUSE frames.
2265 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2267 case e1000_fc_tx_pause:
2268 /* TX Flow control is enabled, and RX Flow control is disabled, by a
2269 * software over-ride.
2271 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
2274 /* Flow control (both RX and TX) is enabled by a software over-ride. */
2275 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2278 DEBUGOUT("Flow control param set incorrectly\n");
2279 return -E1000_ERR_CONFIG;
2283 /* Since auto-negotiation is enabled, take the link out of reset (the link
2284 * will be in reset, because we previously reset the chip). This will
2285 * restart auto-negotiation. If auto-neogtiation is successful then the
2286 * link-up status bit will be set and the flow control enable bits (RFCE
2287 * and TFCE) will be set according to their negotiated value.
2289 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
2291 E1000_WRITE_REG(hw, TXCW, txcw);
2292 E1000_WRITE_REG(hw, CTRL, ctrl);
2293 E1000_WRITE_FLUSH(hw);
2298 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
2299 * indication in the Device Status Register. Time-out if a link isn't
2300 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
2301 * less than 500 milliseconds even if the other end is doing it in SW).
2303 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
2304 DEBUGOUT("Looking for Link\n");
2305 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
2307 status = E1000_READ_REG(hw, STATUS);
2308 if (status & E1000_STATUS_LU)
2311 if (i == (LINK_UP_TIMEOUT / 10)) {
2312 /* AutoNeg failed to achieve a link, so we'll call
2313 * e1000_check_for_link. This routine will force the link up if we
2314 * detect a signal. This will allow us to communicate with
2315 * non-autonegotiating link partners.
2317 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2318 hw->autoneg_failed = 1;
2319 ret_val = e1000_check_for_link(hw);
2321 DEBUGOUT("Error while checking for link\n");
2324 hw->autoneg_failed = 0;
2326 hw->autoneg_failed = 0;
2327 DEBUGOUT("Valid Link Found\n");
2330 DEBUGOUT("No Signal Detected\n");
2331 return -E1000_ERR_NOLINK;
2336 /******************************************************************************
2337 * Make sure we have a valid PHY and change PHY mode before link setup.
2339 * hw - Struct containing variables accessed by shared code
2340 ******************************************************************************/
2342 e1000_copper_link_preconfig(struct e1000_hw *hw)
2350 ctrl = E1000_READ_REG(hw, CTRL);
2351 /* With 82543, we need to force speed and duplex on the MAC equal to what
2352 * the PHY speed and duplex configuration is. In addition, we need to
2353 * perform a hardware reset on the PHY to take it out of reset.
2355 if (hw->mac_type > e1000_82543) {
2356 ctrl |= E1000_CTRL_SLU;
2357 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2358 E1000_WRITE_REG(hw, CTRL, ctrl);
2360 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
2362 E1000_WRITE_REG(hw, CTRL, ctrl);
2363 ret_val = e1000_phy_hw_reset(hw);
2368 /* Make sure we have a valid PHY */
2369 ret_val = e1000_detect_gig_phy(hw);
2371 DEBUGOUT("Error, did not detect valid phy.\n");
2374 DEBUGOUT("Phy ID = %x\n", hw->phy_id);
2376 /* Set PHY to class A mode (if necessary) */
2377 ret_val = e1000_set_phy_mode(hw);
2380 if ((hw->mac_type == e1000_82545_rev_3) ||
2381 (hw->mac_type == e1000_82546_rev_3)) {
2382 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2384 phy_data |= 0x00000008;
2385 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2389 if (hw->mac_type <= e1000_82543 ||
2390 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
2391 hw->mac_type == e1000_82541_rev_2
2392 || hw->mac_type == e1000_82547_rev_2)
2393 hw->phy_reset_disable = false;
2395 return E1000_SUCCESS;
2398 /*****************************************************************************
2400 * This function sets the lplu state according to the active flag. When
2401 * activating lplu this function also disables smart speed and vise versa.
2402 * lplu will not be activated unless the device autonegotiation advertisment
2403 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2404 * hw: Struct containing variables accessed by shared code
2405 * active - true to enable lplu false to disable lplu.
2407 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2408 * E1000_SUCCESS at any other case.
2410 ****************************************************************************/
2413 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
2415 uint32_t phy_ctrl = 0;
2420 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
2421 && hw->phy_type != e1000_phy_igp_3)
2422 return E1000_SUCCESS;
2424 /* During driver activity LPLU should not be used or it will attain link
2425 * from the lowest speeds starting from 10Mbps. The capability is used
2426 * for Dx transitions and states */
2427 if (hw->mac_type == e1000_82541_rev_2
2428 || hw->mac_type == e1000_82547_rev_2) {
2429 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
2433 } else if (hw->mac_type == e1000_ich8lan) {
2434 /* MAC writes into PHY register based on the state transition
2435 * and start auto-negotiation. SW driver can overwrite the
2436 * settings in CSR PHY power control E1000_PHY_CTRL register. */
2437 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2439 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2446 if (hw->mac_type == e1000_82541_rev_2 ||
2447 hw->mac_type == e1000_82547_rev_2) {
2448 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
2449 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
2454 if (hw->mac_type == e1000_ich8lan) {
2455 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2456 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2458 phy_data &= ~IGP02E1000_PM_D3_LPLU;
2459 ret_val = e1000_write_phy_reg(hw,
2460 IGP02E1000_PHY_POWER_MGMT, phy_data);
2466 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2467 * Dx states where the power conservation is most important. During
2468 * driver activity we should enable SmartSpeed, so performance is
2470 if (hw->smart_speed == e1000_smart_speed_on) {
2471 ret_val = e1000_read_phy_reg(hw,
2472 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2476 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2477 ret_val = e1000_write_phy_reg(hw,
2478 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2481 } else if (hw->smart_speed == e1000_smart_speed_off) {
2482 ret_val = e1000_read_phy_reg(hw,
2483 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2487 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2488 ret_val = e1000_write_phy_reg(hw,
2489 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2494 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
2495 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
2496 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
2498 if (hw->mac_type == e1000_82541_rev_2 ||
2499 hw->mac_type == e1000_82547_rev_2) {
2500 phy_data |= IGP01E1000_GMII_FLEX_SPD;
2501 ret_val = e1000_write_phy_reg(hw,
2502 IGP01E1000_GMII_FIFO, phy_data);
2506 if (hw->mac_type == e1000_ich8lan) {
2507 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2508 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2510 phy_data |= IGP02E1000_PM_D3_LPLU;
2511 ret_val = e1000_write_phy_reg(hw,
2512 IGP02E1000_PHY_POWER_MGMT, phy_data);
2518 /* When LPLU is enabled we should disable SmartSpeed */
2519 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2524 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2525 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2530 return E1000_SUCCESS;
2533 /*****************************************************************************
2535 * This function sets the lplu d0 state according to the active flag. When
2536 * activating lplu this function also disables smart speed and vise versa.
2537 * lplu will not be activated unless the device autonegotiation advertisment
2538 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2539 * hw: Struct containing variables accessed by shared code
2540 * active - true to enable lplu false to disable lplu.
2542 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2543 * E1000_SUCCESS at any other case.
2545 ****************************************************************************/
2548 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2550 uint32_t phy_ctrl = 0;
2555 if (hw->mac_type <= e1000_82547_rev_2)
2556 return E1000_SUCCESS;
2558 if (hw->mac_type == e1000_ich8lan) {
2559 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2560 } else if (hw->mac_type == e1000_igb) {
2561 phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
2563 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2570 if (hw->mac_type == e1000_ich8lan) {
2571 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2572 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2573 } else if (hw->mac_type == e1000_igb) {
2574 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2575 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2577 phy_data &= ~IGP02E1000_PM_D0_LPLU;
2578 ret_val = e1000_write_phy_reg(hw,
2579 IGP02E1000_PHY_POWER_MGMT, phy_data);
2584 if (hw->mac_type == e1000_igb)
2585 return E1000_SUCCESS;
2587 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2588 * Dx states where the power conservation is most important. During
2589 * driver activity we should enable SmartSpeed, so performance is
2591 if (hw->smart_speed == e1000_smart_speed_on) {
2592 ret_val = e1000_read_phy_reg(hw,
2593 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2597 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2598 ret_val = e1000_write_phy_reg(hw,
2599 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2602 } else if (hw->smart_speed == e1000_smart_speed_off) {
2603 ret_val = e1000_read_phy_reg(hw,
2604 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2608 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2609 ret_val = e1000_write_phy_reg(hw,
2610 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2618 if (hw->mac_type == e1000_ich8lan) {
2619 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2620 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2621 } else if (hw->mac_type == e1000_igb) {
2622 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2623 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2625 phy_data |= IGP02E1000_PM_D0_LPLU;
2626 ret_val = e1000_write_phy_reg(hw,
2627 IGP02E1000_PHY_POWER_MGMT, phy_data);
2632 if (hw->mac_type == e1000_igb)
2633 return E1000_SUCCESS;
2635 /* When LPLU is enabled we should disable SmartSpeed */
2636 ret_val = e1000_read_phy_reg(hw,
2637 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2641 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2642 ret_val = e1000_write_phy_reg(hw,
2643 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2648 return E1000_SUCCESS;
2651 /********************************************************************
2652 * Copper link setup for e1000_phy_igp series.
2654 * hw - Struct containing variables accessed by shared code
2655 *********************************************************************/
2657 e1000_copper_link_igp_setup(struct e1000_hw *hw)
2665 if (hw->phy_reset_disable)
2666 return E1000_SUCCESS;
2668 ret_val = e1000_phy_reset(hw);
2670 DEBUGOUT("Error Resetting the PHY\n");
2674 /* Wait 15ms for MAC to configure PHY from eeprom settings */
2676 if (hw->mac_type != e1000_ich8lan) {
2677 /* Configure activity LED after PHY reset */
2678 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2679 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2680 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2681 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2684 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
2685 if (hw->phy_type == e1000_phy_igp) {
2686 /* disable lplu d3 during driver init */
2687 ret_val = e1000_set_d3_lplu_state(hw, false);
2689 DEBUGOUT("Error Disabling LPLU D3\n");
2694 /* disable lplu d0 during driver init */
2695 ret_val = e1000_set_d0_lplu_state(hw, false);
2697 DEBUGOUT("Error Disabling LPLU D0\n");
2700 /* Configure mdi-mdix settings */
2701 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2705 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2706 hw->dsp_config_state = e1000_dsp_config_disabled;
2707 /* Force MDI for earlier revs of the IGP PHY */
2708 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
2709 | IGP01E1000_PSCR_FORCE_MDI_MDIX);
2713 hw->dsp_config_state = e1000_dsp_config_enabled;
2714 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2718 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2721 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
2725 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
2729 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2733 /* set auto-master slave resolution settings */
2735 e1000_ms_type phy_ms_setting = hw->master_slave;
2737 if (hw->ffe_config_state == e1000_ffe_config_active)
2738 hw->ffe_config_state = e1000_ffe_config_enabled;
2740 if (hw->dsp_config_state == e1000_dsp_config_activated)
2741 hw->dsp_config_state = e1000_dsp_config_enabled;
2743 /* when autonegotiation advertisment is only 1000Mbps then we
2744 * should disable SmartSpeed and enable Auto MasterSlave
2745 * resolution as hardware default. */
2746 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
2747 /* Disable SmartSpeed */
2748 ret_val = e1000_read_phy_reg(hw,
2749 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2752 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2753 ret_val = e1000_write_phy_reg(hw,
2754 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2757 /* Set auto Master/Slave resolution process */
2758 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
2762 phy_data &= ~CR_1000T_MS_ENABLE;
2763 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
2769 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
2773 /* load defaults for future use */
2774 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
2775 ((phy_data & CR_1000T_MS_VALUE) ?
2776 e1000_ms_force_master :
2777 e1000_ms_force_slave) :
2780 switch (phy_ms_setting) {
2781 case e1000_ms_force_master:
2782 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2784 case e1000_ms_force_slave:
2785 phy_data |= CR_1000T_MS_ENABLE;
2786 phy_data &= ~(CR_1000T_MS_VALUE);
2789 phy_data &= ~CR_1000T_MS_ENABLE;
2793 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
2798 return E1000_SUCCESS;
2801 /*****************************************************************************
2802 * This function checks the mode of the firmware.
2804 * returns - true when the mode is IAMT or false.
2805 ****************************************************************************/
2807 e1000_check_mng_mode(struct e1000_hw *hw)
2812 fwsm = E1000_READ_REG(hw, FWSM);
2814 if (hw->mac_type == e1000_ich8lan) {
2815 if ((fwsm & E1000_FWSM_MODE_MASK) ==
2816 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2818 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
2819 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2826 e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
2828 uint16_t swfw = E1000_SWFW_PHY0_SM;
2832 if (e1000_is_second_port(hw))
2833 swfw = E1000_SWFW_PHY1_SM;
2835 if (e1000_swfw_sync_acquire(hw, swfw))
2836 return -E1000_ERR_SWFW_SYNC;
2838 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
2839 & E1000_KUMCTRLSTA_OFFSET) | data;
2840 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2843 return E1000_SUCCESS;
2847 e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
2849 uint16_t swfw = E1000_SWFW_PHY0_SM;
2853 if (e1000_is_second_port(hw))
2854 swfw = E1000_SWFW_PHY1_SM;
2856 if (e1000_swfw_sync_acquire(hw, swfw)) {
2857 debug("%s[%i]\n", __func__, __LINE__);
2858 return -E1000_ERR_SWFW_SYNC;
2861 /* Write register address */
2862 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
2863 E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
2864 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2867 /* Read the data returned */
2868 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
2869 *data = (uint16_t)reg_val;
2871 return E1000_SUCCESS;
2874 /********************************************************************
2875 * Copper link setup for e1000_phy_gg82563 series.
2877 * hw - Struct containing variables accessed by shared code
2878 *********************************************************************/
2880 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
2888 if (!hw->phy_reset_disable) {
2889 /* Enable CRS on TX for half-duplex operation. */
2890 ret_val = e1000_read_phy_reg(hw,
2891 GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2895 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2896 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
2897 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
2899 ret_val = e1000_write_phy_reg(hw,
2900 GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2905 * MDI/MDI-X = 0 (default)
2906 * 0 - Auto for all speeds
2909 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2911 ret_val = e1000_read_phy_reg(hw,
2912 GG82563_PHY_SPEC_CTRL, &phy_data);
2916 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
2920 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
2923 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
2927 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
2932 * disable_polarity_correction = 0 (default)
2933 * Automatic Correction for Reversed Cable Polarity
2937 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
2938 ret_val = e1000_write_phy_reg(hw,
2939 GG82563_PHY_SPEC_CTRL, phy_data);
2944 /* SW Reset the PHY so all changes take effect */
2945 ret_val = e1000_phy_reset(hw);
2947 DEBUGOUT("Error Resetting the PHY\n");
2950 } /* phy_reset_disable */
2952 if (hw->mac_type == e1000_80003es2lan) {
2953 /* Bypass RX and TX FIFO's */
2954 ret_val = e1000_write_kmrn_reg(hw,
2955 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
2956 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2957 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
2961 ret_val = e1000_read_phy_reg(hw,
2962 GG82563_PHY_SPEC_CTRL_2, &phy_data);
2966 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
2967 ret_val = e1000_write_phy_reg(hw,
2968 GG82563_PHY_SPEC_CTRL_2, phy_data);
2973 reg_data = E1000_READ_REG(hw, CTRL_EXT);
2974 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
2975 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
2977 ret_val = e1000_read_phy_reg(hw,
2978 GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
2982 /* Do not init these registers when the HW is in IAMT mode, since the
2983 * firmware will have already initialized them. We only initialize
2984 * them if the HW is not in IAMT mode.
2986 if (e1000_check_mng_mode(hw) == false) {
2987 /* Enable Electrical Idle on the PHY */
2988 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
2989 ret_val = e1000_write_phy_reg(hw,
2990 GG82563_PHY_PWR_MGMT_CTRL, phy_data);
2994 ret_val = e1000_read_phy_reg(hw,
2995 GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
2999 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3000 ret_val = e1000_write_phy_reg(hw,
3001 GG82563_PHY_KMRN_MODE_CTRL, phy_data);
3007 /* Workaround: Disable padding in Kumeran interface in the MAC
3008 * and in the PHY to avoid CRC errors.
3010 ret_val = e1000_read_phy_reg(hw,
3011 GG82563_PHY_INBAND_CTRL, &phy_data);
3014 phy_data |= GG82563_ICR_DIS_PADDING;
3015 ret_val = e1000_write_phy_reg(hw,
3016 GG82563_PHY_INBAND_CTRL, phy_data);
3020 return E1000_SUCCESS;
3023 /********************************************************************
3024 * Copper link setup for e1000_phy_m88 series.
3026 * hw - Struct containing variables accessed by shared code
3027 *********************************************************************/
3029 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
3036 if (hw->phy_reset_disable)
3037 return E1000_SUCCESS;
3039 /* Enable CRS on TX. This must be set for half-duplex operation. */
3040 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3044 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
3047 * MDI/MDI-X = 0 (default)
3048 * 0 - Auto for all speeds
3051 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
3053 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
3057 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
3060 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
3063 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
3067 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
3072 * disable_polarity_correction = 0 (default)
3073 * Automatic Correction for Reversed Cable Polarity
3077 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
3078 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
3082 if (hw->phy_revision < M88E1011_I_REV_4) {
3083 /* Force TX_CLK in the Extended PHY Specific Control Register
3086 ret_val = e1000_read_phy_reg(hw,
3087 M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
3091 phy_data |= M88E1000_EPSCR_TX_CLK_25;
3093 if ((hw->phy_revision == E1000_REVISION_2) &&
3094 (hw->phy_id == M88E1111_I_PHY_ID)) {
3095 /* Vidalia Phy, set the downshift counter to 5x */
3096 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
3097 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
3098 ret_val = e1000_write_phy_reg(hw,
3099 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
3103 /* Configure Master and Slave downshift values */
3104 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
3105 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
3106 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
3107 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
3108 ret_val = e1000_write_phy_reg(hw,
3109 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
3115 /* SW Reset the PHY so all changes take effect */
3116 ret_val = e1000_phy_reset(hw);
3118 DEBUGOUT("Error Resetting the PHY\n");
3122 return E1000_SUCCESS;
3125 /********************************************************************
3126 * Setup auto-negotiation and flow control advertisements,
3127 * and then perform auto-negotiation.
3129 * hw - Struct containing variables accessed by shared code
3130 *********************************************************************/
3132 e1000_copper_link_autoneg(struct e1000_hw *hw)
3139 /* Perform some bounds checking on the hw->autoneg_advertised
3140 * parameter. If this variable is zero, then set it to the default.
3142 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
3144 /* If autoneg_advertised is zero, we assume it was not defaulted
3145 * by the calling code so we set to advertise full capability.
3147 if (hw->autoneg_advertised == 0)
3148 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
3150 /* IFE phy only supports 10/100 */
3151 if (hw->phy_type == e1000_phy_ife)
3152 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
3154 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
3155 ret_val = e1000_phy_setup_autoneg(hw);
3157 DEBUGOUT("Error Setting up Auto-Negotiation\n");
3160 DEBUGOUT("Restarting Auto-Neg\n");
3162 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
3163 * the Auto Neg Restart bit in the PHY control register.
3165 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3169 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
3170 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3174 /* Does the user want to wait for Auto-Neg to complete here, or
3175 * check at a later time (for example, callback routine).
3177 /* If we do not wait for autonegtation to complete I
3178 * do not see a valid link status.
3179 * wait_autoneg_complete = 1 .
3181 if (hw->wait_autoneg_complete) {
3182 ret_val = e1000_wait_autoneg(hw);
3184 DEBUGOUT("Error while waiting for autoneg"
3190 hw->get_link_status = true;
3192 return E1000_SUCCESS;
3195 /******************************************************************************
3196 * Config the MAC and the PHY after link is up.
3197 * 1) Set up the MAC to the current PHY speed/duplex
3198 * if we are on 82543. If we
3199 * are on newer silicon, we only need to configure
3200 * collision distance in the Transmit Control Register.
3201 * 2) Set up flow control on the MAC to that established with
3203 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
3205 * hw - Struct containing variables accessed by shared code
3206 ******************************************************************************/
3208 e1000_copper_link_postconfig(struct e1000_hw *hw)
3213 if (hw->mac_type >= e1000_82544) {
3214 e1000_config_collision_dist(hw);
3216 ret_val = e1000_config_mac_to_phy(hw);
3218 DEBUGOUT("Error configuring MAC to PHY settings\n");
3222 ret_val = e1000_config_fc_after_link_up(hw);
3224 DEBUGOUT("Error Configuring Flow Control\n");
3227 return E1000_SUCCESS;
3230 /******************************************************************************
3231 * Detects which PHY is present and setup the speed and duplex
3233 * hw - Struct containing variables accessed by shared code
3234 ******************************************************************************/
3236 e1000_setup_copper_link(struct e1000_hw *hw)
3245 switch (hw->mac_type) {
3246 case e1000_80003es2lan:
3248 /* Set the mac to wait the maximum time between each
3249 * iteration and increase the max iterations when
3250 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
3251 ret_val = e1000_write_kmrn_reg(hw,
3252 GG82563_REG(0x34, 4), 0xFFFF);
3255 ret_val = e1000_read_kmrn_reg(hw,
3256 GG82563_REG(0x34, 9), ®_data);
3260 ret_val = e1000_write_kmrn_reg(hw,
3261 GG82563_REG(0x34, 9), reg_data);
3268 /* Check if it is a valid PHY and set PHY mode if necessary. */
3269 ret_val = e1000_copper_link_preconfig(hw);
3272 switch (hw->mac_type) {
3273 case e1000_80003es2lan:
3274 /* Kumeran registers are written-only */
3276 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
3277 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
3278 ret_val = e1000_write_kmrn_reg(hw,
3279 E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
3287 if (hw->phy_type == e1000_phy_igp ||
3288 hw->phy_type == e1000_phy_igp_3 ||
3289 hw->phy_type == e1000_phy_igp_2) {
3290 ret_val = e1000_copper_link_igp_setup(hw);
3293 } else if (hw->phy_type == e1000_phy_m88 ||
3294 hw->phy_type == e1000_phy_igb) {
3295 ret_val = e1000_copper_link_mgp_setup(hw);
3298 } else if (hw->phy_type == e1000_phy_gg82563) {
3299 ret_val = e1000_copper_link_ggp_setup(hw);
3305 /* Setup autoneg and flow control advertisement
3306 * and perform autonegotiation */
3307 ret_val = e1000_copper_link_autoneg(hw);
3311 /* Check link status. Wait up to 100 microseconds for link to become
3314 for (i = 0; i < 10; i++) {
3315 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3318 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3322 if (phy_data & MII_SR_LINK_STATUS) {
3323 /* Config the MAC and PHY after link is up */
3324 ret_val = e1000_copper_link_postconfig(hw);
3328 DEBUGOUT("Valid link established!!!\n");
3329 return E1000_SUCCESS;
3334 DEBUGOUT("Unable to establish link!!!\n");
3335 return E1000_SUCCESS;
3338 /******************************************************************************
3339 * Configures PHY autoneg and flow control advertisement settings
3341 * hw - Struct containing variables accessed by shared code
3342 ******************************************************************************/
3344 e1000_phy_setup_autoneg(struct e1000_hw *hw)
3347 uint16_t mii_autoneg_adv_reg;
3348 uint16_t mii_1000t_ctrl_reg;
3352 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
3353 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
3357 if (hw->phy_type != e1000_phy_ife) {
3358 /* Read the MII 1000Base-T Control Register (Address 9). */
3359 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
3360 &mii_1000t_ctrl_reg);
3364 mii_1000t_ctrl_reg = 0;
3366 /* Need to parse both autoneg_advertised and fc and set up
3367 * the appropriate PHY registers. First we will parse for
3368 * autoneg_advertised software override. Since we can advertise
3369 * a plethora of combinations, we need to check each bit
3373 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
3374 * Advertisement Register (Address 4) and the 1000 mb speed bits in
3375 * the 1000Base-T Control Register (Address 9).
3377 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
3378 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
3380 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
3382 /* Do we want to advertise 10 Mb Half Duplex? */
3383 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
3384 DEBUGOUT("Advertise 10mb Half duplex\n");
3385 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
3388 /* Do we want to advertise 10 Mb Full Duplex? */
3389 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
3390 DEBUGOUT("Advertise 10mb Full duplex\n");
3391 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
3394 /* Do we want to advertise 100 Mb Half Duplex? */
3395 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
3396 DEBUGOUT("Advertise 100mb Half duplex\n");
3397 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
3400 /* Do we want to advertise 100 Mb Full Duplex? */
3401 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
3402 DEBUGOUT("Advertise 100mb Full duplex\n");
3403 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
3406 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
3407 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
3409 ("Advertise 1000mb Half duplex requested, request denied!\n");
3412 /* Do we want to advertise 1000 Mb Full Duplex? */
3413 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
3414 DEBUGOUT("Advertise 1000mb Full duplex\n");
3415 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
3418 /* Check for a software override of the flow control settings, and
3419 * setup the PHY advertisement registers accordingly. If
3420 * auto-negotiation is enabled, then software will have to set the
3421 * "PAUSE" bits to the correct value in the Auto-Negotiation
3422 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
3424 * The possible values of the "fc" parameter are:
3425 * 0: Flow control is completely disabled
3426 * 1: Rx flow control is enabled (we can receive pause frames
3427 * but not send pause frames).
3428 * 2: Tx flow control is enabled (we can send pause frames
3429 * but we do not support receiving pause frames).
3430 * 3: Both Rx and TX flow control (symmetric) are enabled.
3431 * other: No software override. The flow control configuration
3432 * in the EEPROM is used.
3435 case e1000_fc_none: /* 0 */
3436 /* Flow control (RX & TX) is completely disabled by a
3437 * software over-ride.
3439 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3441 case e1000_fc_rx_pause: /* 1 */
3442 /* RX Flow control is enabled, and TX Flow control is
3443 * disabled, by a software over-ride.
3445 /* Since there really isn't a way to advertise that we are
3446 * capable of RX Pause ONLY, we will advertise that we
3447 * support both symmetric and asymmetric RX PAUSE. Later
3448 * (in e1000_config_fc_after_link_up) we will disable the
3449 *hw's ability to send PAUSE frames.
3451 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3453 case e1000_fc_tx_pause: /* 2 */
3454 /* TX Flow control is enabled, and RX Flow control is
3455 * disabled, by a software over-ride.
3457 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
3458 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
3460 case e1000_fc_full: /* 3 */
3461 /* Flow control (both RX and TX) is enabled by a software
3464 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3467 DEBUGOUT("Flow control param set incorrectly\n");
3468 return -E1000_ERR_CONFIG;
3471 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
3475 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
3477 if (hw->phy_type != e1000_phy_ife) {
3478 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
3479 mii_1000t_ctrl_reg);
3484 return E1000_SUCCESS;
3487 /******************************************************************************
3488 * Sets the collision distance in the Transmit Control register
3490 * hw - Struct containing variables accessed by shared code
3492 * Link should have been established previously. Reads the speed and duplex
3493 * information from the Device Status register.
3494 ******************************************************************************/
3496 e1000_config_collision_dist(struct e1000_hw *hw)
3498 uint32_t tctl, coll_dist;
3502 if (hw->mac_type < e1000_82543)
3503 coll_dist = E1000_COLLISION_DISTANCE_82542;
3505 coll_dist = E1000_COLLISION_DISTANCE;
3507 tctl = E1000_READ_REG(hw, TCTL);
3509 tctl &= ~E1000_TCTL_COLD;
3510 tctl |= coll_dist << E1000_COLD_SHIFT;
3512 E1000_WRITE_REG(hw, TCTL, tctl);
3513 E1000_WRITE_FLUSH(hw);
3516 /******************************************************************************
3517 * Sets MAC speed and duplex settings to reflect the those in the PHY
3519 * hw - Struct containing variables accessed by shared code
3520 * mii_reg - data to write to the MII control register
3522 * The contents of the PHY register containing the needed information need to
3524 ******************************************************************************/
3526 e1000_config_mac_to_phy(struct e1000_hw *hw)
3533 /* Read the Device Control Register and set the bits to Force Speed
3536 ctrl = E1000_READ_REG(hw, CTRL);
3537 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3538 ctrl &= ~(E1000_CTRL_ILOS);
3539 ctrl |= (E1000_CTRL_SPD_SEL);
3541 /* Set up duplex in the Device Control and Transmit Control
3542 * registers depending on negotiated values.
3544 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
3545 DEBUGOUT("PHY Read Error\n");
3546 return -E1000_ERR_PHY;
3548 if (phy_data & M88E1000_PSSR_DPLX)
3549 ctrl |= E1000_CTRL_FD;
3551 ctrl &= ~E1000_CTRL_FD;
3553 e1000_config_collision_dist(hw);
3555 /* Set up speed in the Device Control register depending on
3556 * negotiated values.
3558 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
3559 ctrl |= E1000_CTRL_SPD_1000;
3560 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
3561 ctrl |= E1000_CTRL_SPD_100;
3562 /* Write the configured values back to the Device Control Reg. */
3563 E1000_WRITE_REG(hw, CTRL, ctrl);
3567 /******************************************************************************
3568 * Forces the MAC's flow control settings.
3570 * hw - Struct containing variables accessed by shared code
3572 * Sets the TFCE and RFCE bits in the device control register to reflect
3573 * the adapter settings. TFCE and RFCE need to be explicitly set by
3574 * software when a Copper PHY is used because autonegotiation is managed
3575 * by the PHY rather than the MAC. Software must also configure these
3576 * bits when link is forced on a fiber connection.
3577 *****************************************************************************/
3579 e1000_force_mac_fc(struct e1000_hw *hw)
3585 /* Get the current configuration of the Device Control Register */
3586 ctrl = E1000_READ_REG(hw, CTRL);
3588 /* Because we didn't get link via the internal auto-negotiation
3589 * mechanism (we either forced link or we got link via PHY
3590 * auto-neg), we have to manually enable/disable transmit an
3591 * receive flow control.
3593 * The "Case" statement below enables/disable flow control
3594 * according to the "hw->fc" parameter.
3596 * The possible values of the "fc" parameter are:
3597 * 0: Flow control is completely disabled
3598 * 1: Rx flow control is enabled (we can receive pause
3599 * frames but not send pause frames).
3600 * 2: Tx flow control is enabled (we can send pause frames
3601 * frames but we do not receive pause frames).
3602 * 3: Both Rx and TX flow control (symmetric) is enabled.
3603 * other: No other values should be possible at this point.
3608 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
3610 case e1000_fc_rx_pause:
3611 ctrl &= (~E1000_CTRL_TFCE);
3612 ctrl |= E1000_CTRL_RFCE;
3614 case e1000_fc_tx_pause:
3615 ctrl &= (~E1000_CTRL_RFCE);
3616 ctrl |= E1000_CTRL_TFCE;
3619 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
3622 DEBUGOUT("Flow control param set incorrectly\n");
3623 return -E1000_ERR_CONFIG;
3626 /* Disable TX Flow Control for 82542 (rev 2.0) */
3627 if (hw->mac_type == e1000_82542_rev2_0)
3628 ctrl &= (~E1000_CTRL_TFCE);
3630 E1000_WRITE_REG(hw, CTRL, ctrl);
3634 /******************************************************************************
3635 * Configures flow control settings after link is established
3637 * hw - Struct containing variables accessed by shared code
3639 * Should be called immediately after a valid link has been established.
3640 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
3641 * and autonegotiation is enabled, the MAC flow control settings will be set
3642 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
3643 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
3644 *****************************************************************************/
3646 e1000_config_fc_after_link_up(struct e1000_hw *hw)
3649 uint16_t mii_status_reg;
3650 uint16_t mii_nway_adv_reg;
3651 uint16_t mii_nway_lp_ability_reg;
3657 /* Check for the case where we have fiber media and auto-neg failed
3658 * so we had to force link. In this case, we need to force the
3659 * configuration of the MAC to match the "fc" parameter.
3661 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
3662 || ((hw->media_type == e1000_media_type_internal_serdes)
3663 && (hw->autoneg_failed))
3664 || ((hw->media_type == e1000_media_type_copper)
3665 && (!hw->autoneg))) {
3666 ret_val = e1000_force_mac_fc(hw);
3668 DEBUGOUT("Error forcing flow control settings\n");
3673 /* Check for the case where we have copper media and auto-neg is
3674 * enabled. In this case, we need to check and see if Auto-Neg
3675 * has completed, and if so, how the PHY and link partner has
3676 * flow control configured.
3678 if (hw->media_type == e1000_media_type_copper) {
3679 /* Read the MII Status Register and check to see if AutoNeg
3680 * has completed. We read this twice because this reg has
3681 * some "sticky" (latched) bits.
3683 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3684 DEBUGOUT("PHY Read Error\n");
3685 return -E1000_ERR_PHY;
3687 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3688 DEBUGOUT("PHY Read Error\n");
3689 return -E1000_ERR_PHY;
3692 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
3693 /* The AutoNeg process has completed, so we now need to
3694 * read both the Auto Negotiation Advertisement Register
3695 * (Address 4) and the Auto_Negotiation Base Page Ability
3696 * Register (Address 5) to determine how flow control was
3699 if (e1000_read_phy_reg
3700 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
3701 DEBUGOUT("PHY Read Error\n");
3702 return -E1000_ERR_PHY;
3704 if (e1000_read_phy_reg
3705 (hw, PHY_LP_ABILITY,
3706 &mii_nway_lp_ability_reg) < 0) {
3707 DEBUGOUT("PHY Read Error\n");
3708 return -E1000_ERR_PHY;
3711 /* Two bits in the Auto Negotiation Advertisement Register
3712 * (Address 4) and two bits in the Auto Negotiation Base
3713 * Page Ability Register (Address 5) determine flow control
3714 * for both the PHY and the link partner. The following
3715 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
3716 * 1999, describes these PAUSE resolution bits and how flow
3717 * control is determined based upon these settings.
3718 * NOTE: DC = Don't Care
3720 * LOCAL DEVICE | LINK PARTNER
3721 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
3722 *-------|---------|-------|---------|--------------------
3723 * 0 | 0 | DC | DC | e1000_fc_none
3724 * 0 | 1 | 0 | DC | e1000_fc_none
3725 * 0 | 1 | 1 | 0 | e1000_fc_none
3726 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3727 * 1 | 0 | 0 | DC | e1000_fc_none
3728 * 1 | DC | 1 | DC | e1000_fc_full
3729 * 1 | 1 | 0 | 0 | e1000_fc_none
3730 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3733 /* Are both PAUSE bits set to 1? If so, this implies
3734 * Symmetric Flow Control is enabled at both ends. The
3735 * ASM_DIR bits are irrelevant per the spec.
3737 * For Symmetric Flow Control:
3739 * LOCAL DEVICE | LINK PARTNER
3740 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3741 *-------|---------|-------|---------|--------------------
3742 * 1 | DC | 1 | DC | e1000_fc_full
3745 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3746 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
3747 /* Now we need to check if the user selected RX ONLY
3748 * of pause frames. In this case, we had to advertise
3749 * FULL flow control because we could not advertise RX
3750 * ONLY. Hence, we must now check to see if we need to
3751 * turn OFF the TRANSMISSION of PAUSE frames.
3753 if (hw->original_fc == e1000_fc_full) {
3754 hw->fc = e1000_fc_full;
3755 DEBUGOUT("Flow Control = FULL.\r\n");
3757 hw->fc = e1000_fc_rx_pause;
3759 ("Flow Control = RX PAUSE frames only.\r\n");
3762 /* For receiving PAUSE frames ONLY.
3764 * LOCAL DEVICE | LINK PARTNER
3765 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3766 *-------|---------|-------|---------|--------------------
3767 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3770 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3771 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3772 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3773 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3775 hw->fc = e1000_fc_tx_pause;
3777 ("Flow Control = TX PAUSE frames only.\r\n");
3779 /* For transmitting PAUSE frames ONLY.
3781 * LOCAL DEVICE | LINK PARTNER
3782 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3783 *-------|---------|-------|---------|--------------------
3784 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3787 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3788 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3789 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3790 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3792 hw->fc = e1000_fc_rx_pause;
3794 ("Flow Control = RX PAUSE frames only.\r\n");
3796 /* Per the IEEE spec, at this point flow control should be
3797 * disabled. However, we want to consider that we could
3798 * be connected to a legacy switch that doesn't advertise
3799 * desired flow control, but can be forced on the link
3800 * partner. So if we advertised no flow control, that is
3801 * what we will resolve to. If we advertised some kind of
3802 * receive capability (Rx Pause Only or Full Flow Control)
3803 * and the link partner advertised none, we will configure
3804 * ourselves to enable Rx Flow Control only. We can do
3805 * this safely for two reasons: If the link partner really
3806 * didn't want flow control enabled, and we enable Rx, no
3807 * harm done since we won't be receiving any PAUSE frames
3808 * anyway. If the intent on the link partner was to have
3809 * flow control enabled, then by us enabling RX only, we
3810 * can at least receive pause frames and process them.
3811 * This is a good idea because in most cases, since we are
3812 * predominantly a server NIC, more times than not we will
3813 * be asked to delay transmission of packets than asking
3814 * our link partner to pause transmission of frames.
3816 else if (hw->original_fc == e1000_fc_none ||
3817 hw->original_fc == e1000_fc_tx_pause) {
3818 hw->fc = e1000_fc_none;
3819 DEBUGOUT("Flow Control = NONE.\r\n");
3821 hw->fc = e1000_fc_rx_pause;
3823 ("Flow Control = RX PAUSE frames only.\r\n");
3826 /* Now we need to do one last check... If we auto-
3827 * negotiated to HALF DUPLEX, flow control should not be
3828 * enabled per IEEE 802.3 spec.
3830 e1000_get_speed_and_duplex(hw, &speed, &duplex);
3832 if (duplex == HALF_DUPLEX)
3833 hw->fc = e1000_fc_none;
3835 /* Now we call a subroutine to actually force the MAC
3836 * controller to use the correct flow control settings.
3838 ret_val = e1000_force_mac_fc(hw);
3841 ("Error forcing flow control settings\n");
3846 ("Copper PHY and Auto Neg has not completed.\r\n");
3849 return E1000_SUCCESS;
3852 /******************************************************************************
3853 * Checks to see if the link status of the hardware has changed.
3855 * hw - Struct containing variables accessed by shared code
3857 * Called by any function that needs to check the link status of the adapter.
3858 *****************************************************************************/
3860 e1000_check_for_link(struct e1000_hw *hw)
3869 uint16_t lp_capability;
3873 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
3874 * set when the optics detect a signal. On older adapters, it will be
3875 * cleared when there is a signal
3877 ctrl = E1000_READ_REG(hw, CTRL);
3878 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
3879 signal = E1000_CTRL_SWDPIN1;
3883 status = E1000_READ_REG(hw, STATUS);
3884 rxcw = E1000_READ_REG(hw, RXCW);
3885 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
3887 /* If we have a copper PHY then we only want to go out to the PHY
3888 * registers to see if Auto-Neg has completed and/or if our link
3889 * status has changed. The get_link_status flag will be set if we
3890 * receive a Link Status Change interrupt or we have Rx Sequence
3893 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
3894 /* First we want to see if the MII Status Register reports
3895 * link. If so, then we want to get the current speed/duplex
3897 * Read the register twice since the link bit is sticky.
3899 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3900 DEBUGOUT("PHY Read Error\n");
3901 return -E1000_ERR_PHY;
3903 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3904 DEBUGOUT("PHY Read Error\n");
3905 return -E1000_ERR_PHY;
3908 if (phy_data & MII_SR_LINK_STATUS) {
3909 hw->get_link_status = false;
3911 /* No link detected */
3912 return -E1000_ERR_NOLINK;
3915 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3916 * have Si on board that is 82544 or newer, Auto
3917 * Speed Detection takes care of MAC speed/duplex
3918 * configuration. So we only need to configure Collision
3919 * Distance in the MAC. Otherwise, we need to force
3920 * speed/duplex on the MAC to the current PHY speed/duplex
3923 if (hw->mac_type >= e1000_82544)
3924 e1000_config_collision_dist(hw);
3926 ret_val = e1000_config_mac_to_phy(hw);
3929 ("Error configuring MAC to PHY settings\n");
3934 /* Configure Flow Control now that Auto-Neg has completed. First, we
3935 * need to restore the desired flow control settings because we may
3936 * have had to re-autoneg with a different link partner.
3938 ret_val = e1000_config_fc_after_link_up(hw);
3940 DEBUGOUT("Error configuring flow control\n");
3944 /* At this point we know that we are on copper and we have
3945 * auto-negotiated link. These are conditions for checking the link
3946 * parter capability register. We use the link partner capability to
3947 * determine if TBI Compatibility needs to be turned on or off. If
3948 * the link partner advertises any speed in addition to Gigabit, then
3949 * we assume that they are GMII-based, and TBI compatibility is not
3950 * needed. If no other speeds are advertised, we assume the link
3951 * partner is TBI-based, and we turn on TBI Compatibility.
3953 if (hw->tbi_compatibility_en) {
3954 if (e1000_read_phy_reg
3955 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
3956 DEBUGOUT("PHY Read Error\n");
3957 return -E1000_ERR_PHY;
3959 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
3960 NWAY_LPAR_10T_FD_CAPS |
3961 NWAY_LPAR_100TX_HD_CAPS |
3962 NWAY_LPAR_100TX_FD_CAPS |
3963 NWAY_LPAR_100T4_CAPS)) {
3964 /* If our link partner advertises anything in addition to
3965 * gigabit, we do not need to enable TBI compatibility.
3967 if (hw->tbi_compatibility_on) {
3968 /* If we previously were in the mode, turn it off. */
3969 rctl = E1000_READ_REG(hw, RCTL);
3970 rctl &= ~E1000_RCTL_SBP;
3971 E1000_WRITE_REG(hw, RCTL, rctl);
3972 hw->tbi_compatibility_on = false;
3975 /* If TBI compatibility is was previously off, turn it on. For
3976 * compatibility with a TBI link partner, we will store bad
3977 * packets. Some frames have an additional byte on the end and
3978 * will look like CRC errors to to the hardware.
3980 if (!hw->tbi_compatibility_on) {
3981 hw->tbi_compatibility_on = true;
3982 rctl = E1000_READ_REG(hw, RCTL);
3983 rctl |= E1000_RCTL_SBP;
3984 E1000_WRITE_REG(hw, RCTL, rctl);
3989 /* If we don't have link (auto-negotiation failed or link partner cannot
3990 * auto-negotiate), the cable is plugged in (we have signal), and our
3991 * link partner is not trying to auto-negotiate with us (we are receiving
3992 * idles or data), we need to force link up. We also need to give
3993 * auto-negotiation time to complete, in case the cable was just plugged
3994 * in. The autoneg_failed flag does this.
3996 else if ((hw->media_type == e1000_media_type_fiber) &&
3997 (!(status & E1000_STATUS_LU)) &&
3998 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
3999 (!(rxcw & E1000_RXCW_C))) {
4000 if (hw->autoneg_failed == 0) {
4001 hw->autoneg_failed = 1;
4004 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
4006 /* Disable auto-negotiation in the TXCW register */
4007 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
4009 /* Force link-up and also force full-duplex. */
4010 ctrl = E1000_READ_REG(hw, CTRL);
4011 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
4012 E1000_WRITE_REG(hw, CTRL, ctrl);
4014 /* Configure Flow Control after forcing link up. */
4015 ret_val = e1000_config_fc_after_link_up(hw);
4017 DEBUGOUT("Error configuring flow control\n");
4021 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
4022 * auto-negotiation in the TXCW register and disable forced link in the
4023 * Device Control register in an attempt to auto-negotiate with our link
4026 else if ((hw->media_type == e1000_media_type_fiber) &&
4027 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
4029 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
4030 E1000_WRITE_REG(hw, TXCW, hw->txcw);
4031 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
4036 /******************************************************************************
4037 * Configure the MAC-to-PHY interface for 10/100Mbps
4039 * hw - Struct containing variables accessed by shared code
4040 ******************************************************************************/
4042 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
4044 int32_t ret_val = E1000_SUCCESS;
4050 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
4051 ret_val = e1000_write_kmrn_reg(hw,
4052 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
4056 /* Configure Transmit Inter-Packet Gap */
4057 tipg = E1000_READ_REG(hw, TIPG);
4058 tipg &= ~E1000_TIPG_IPGT_MASK;
4059 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
4060 E1000_WRITE_REG(hw, TIPG, tipg);
4062 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
4067 if (duplex == HALF_DUPLEX)
4068 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
4070 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
4072 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
4078 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
4080 int32_t ret_val = E1000_SUCCESS;
4086 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
4087 ret_val = e1000_write_kmrn_reg(hw,
4088 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
4092 /* Configure Transmit Inter-Packet Gap */
4093 tipg = E1000_READ_REG(hw, TIPG);
4094 tipg &= ~E1000_TIPG_IPGT_MASK;
4095 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
4096 E1000_WRITE_REG(hw, TIPG, tipg);
4098 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
4103 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
4104 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
4109 /******************************************************************************
4110 * Detects the current speed and duplex settings of the hardware.
4112 * hw - Struct containing variables accessed by shared code
4113 * speed - Speed of the connection
4114 * duplex - Duplex setting of the connection
4115 *****************************************************************************/
4117 e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
4126 if (hw->mac_type >= e1000_82543) {
4127 status = E1000_READ_REG(hw, STATUS);
4128 if (status & E1000_STATUS_SPEED_1000) {
4129 *speed = SPEED_1000;
4130 DEBUGOUT("1000 Mbs, ");
4131 } else if (status & E1000_STATUS_SPEED_100) {
4133 DEBUGOUT("100 Mbs, ");
4136 DEBUGOUT("10 Mbs, ");
4139 if (status & E1000_STATUS_FD) {
4140 *duplex = FULL_DUPLEX;
4141 DEBUGOUT("Full Duplex\r\n");
4143 *duplex = HALF_DUPLEX;
4144 DEBUGOUT(" Half Duplex\r\n");
4147 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
4148 *speed = SPEED_1000;
4149 *duplex = FULL_DUPLEX;
4152 /* IGP01 PHY may advertise full duplex operation after speed downgrade
4153 * even if it is operating at half duplex. Here we set the duplex
4154 * settings to match the duplex in the link partner's capabilities.
4156 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
4157 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
4161 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
4162 *duplex = HALF_DUPLEX;
4164 ret_val = e1000_read_phy_reg(hw,
4165 PHY_LP_ABILITY, &phy_data);
4168 if ((*speed == SPEED_100 &&
4169 !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
4170 || (*speed == SPEED_10
4171 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
4172 *duplex = HALF_DUPLEX;
4176 if ((hw->mac_type == e1000_80003es2lan) &&
4177 (hw->media_type == e1000_media_type_copper)) {
4178 if (*speed == SPEED_1000)
4179 ret_val = e1000_configure_kmrn_for_1000(hw);
4181 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
4185 return E1000_SUCCESS;
4188 /******************************************************************************
4189 * Blocks until autoneg completes or times out (~4.5 seconds)
4191 * hw - Struct containing variables accessed by shared code
4192 ******************************************************************************/
4194 e1000_wait_autoneg(struct e1000_hw *hw)
4200 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
4202 /* We will wait for autoneg to complete or timeout to expire. */
4203 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
4204 /* Read the MII Status Register and wait for Auto-Neg
4205 * Complete bit to be set.
4207 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4208 DEBUGOUT("PHY Read Error\n");
4209 return -E1000_ERR_PHY;
4211 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4212 DEBUGOUT("PHY Read Error\n");
4213 return -E1000_ERR_PHY;
4215 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
4216 DEBUGOUT("Auto-Neg complete.\n");
4221 DEBUGOUT("Auto-Neg timedout.\n");
4222 return -E1000_ERR_TIMEOUT;
4225 /******************************************************************************
4226 * Raises the Management Data Clock
4228 * hw - Struct containing variables accessed by shared code
4229 * ctrl - Device control register's current value
4230 ******************************************************************************/
4232 e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4234 /* Raise the clock input to the Management Data Clock (by setting the MDC
4235 * bit), and then delay 2 microseconds.
4237 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
4238 E1000_WRITE_FLUSH(hw);
4242 /******************************************************************************
4243 * Lowers the Management Data Clock
4245 * hw - Struct containing variables accessed by shared code
4246 * ctrl - Device control register's current value
4247 ******************************************************************************/
4249 e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4251 /* Lower the clock input to the Management Data Clock (by clearing the MDC
4252 * bit), and then delay 2 microseconds.
4254 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
4255 E1000_WRITE_FLUSH(hw);
4259 /******************************************************************************
4260 * Shifts data bits out to the PHY
4262 * hw - Struct containing variables accessed by shared code
4263 * data - Data to send out to the PHY
4264 * count - Number of bits to shift out
4266 * Bits are shifted out in MSB to LSB order.
4267 ******************************************************************************/
4269 e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
4274 /* We need to shift "count" number of bits out to the PHY. So, the value
4275 * in the "data" parameter will be shifted out to the PHY one bit at a
4276 * time. In order to do this, "data" must be broken down into bits.
4279 mask <<= (count - 1);
4281 ctrl = E1000_READ_REG(hw, CTRL);
4283 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
4284 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
4287 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
4288 * then raising and lowering the Management Data Clock. A "0" is
4289 * shifted out to the PHY by setting the MDIO bit to "0" and then
4290 * raising and lowering the clock.
4293 ctrl |= E1000_CTRL_MDIO;
4295 ctrl &= ~E1000_CTRL_MDIO;
4297 E1000_WRITE_REG(hw, CTRL, ctrl);
4298 E1000_WRITE_FLUSH(hw);
4302 e1000_raise_mdi_clk(hw, &ctrl);
4303 e1000_lower_mdi_clk(hw, &ctrl);
4309 /******************************************************************************
4310 * Shifts data bits in from the PHY
4312 * hw - Struct containing variables accessed by shared code
4314 * Bits are shifted in in MSB to LSB order.
4315 ******************************************************************************/
4317 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
4323 /* In order to read a register from the PHY, we need to shift in a total
4324 * of 18 bits from the PHY. The first two bit (turnaround) times are used
4325 * to avoid contention on the MDIO pin when a read operation is performed.
4326 * These two bits are ignored by us and thrown away. Bits are "shifted in"
4327 * by raising the input to the Management Data Clock (setting the MDC bit),
4328 * and then reading the value of the MDIO bit.
4330 ctrl = E1000_READ_REG(hw, CTRL);
4332 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
4333 ctrl &= ~E1000_CTRL_MDIO_DIR;
4334 ctrl &= ~E1000_CTRL_MDIO;
4336 E1000_WRITE_REG(hw, CTRL, ctrl);
4337 E1000_WRITE_FLUSH(hw);
4339 /* Raise and Lower the clock before reading in the data. This accounts for
4340 * the turnaround bits. The first clock occurred when we clocked out the
4341 * last bit of the Register Address.
4343 e1000_raise_mdi_clk(hw, &ctrl);
4344 e1000_lower_mdi_clk(hw, &ctrl);
4346 for (data = 0, i = 0; i < 16; i++) {
4348 e1000_raise_mdi_clk(hw, &ctrl);
4349 ctrl = E1000_READ_REG(hw, CTRL);
4350 /* Check to see if we shifted in a "1". */
4351 if (ctrl & E1000_CTRL_MDIO)
4353 e1000_lower_mdi_clk(hw, &ctrl);
4356 e1000_raise_mdi_clk(hw, &ctrl);
4357 e1000_lower_mdi_clk(hw, &ctrl);
4362 /*****************************************************************************
4363 * Reads the value from a PHY register
4365 * hw - Struct containing variables accessed by shared code
4366 * reg_addr - address of the PHY register to read
4367 ******************************************************************************/
4369 e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
4373 const uint32_t phy_addr = 1;
4375 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4376 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4377 return -E1000_ERR_PARAM;
4380 if (hw->mac_type > e1000_82543) {
4381 /* Set up Op-code, Phy Address, and register address in the MDI
4382 * Control register. The MAC will take care of interfacing with the
4383 * PHY to retrieve the desired data.
4385 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
4386 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4387 (E1000_MDIC_OP_READ));
4389 E1000_WRITE_REG(hw, MDIC, mdic);
4391 /* Poll the ready bit to see if the MDI read completed */
4392 for (i = 0; i < 64; i++) {
4394 mdic = E1000_READ_REG(hw, MDIC);
4395 if (mdic & E1000_MDIC_READY)
4398 if (!(mdic & E1000_MDIC_READY)) {
4399 DEBUGOUT("MDI Read did not complete\n");
4400 return -E1000_ERR_PHY;
4402 if (mdic & E1000_MDIC_ERROR) {
4403 DEBUGOUT("MDI Error\n");
4404 return -E1000_ERR_PHY;
4406 *phy_data = (uint16_t) mdic;
4408 /* We must first send a preamble through the MDIO pin to signal the
4409 * beginning of an MII instruction. This is done by sending 32
4410 * consecutive "1" bits.
4412 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4414 /* Now combine the next few fields that are required for a read
4415 * operation. We use this method instead of calling the
4416 * e1000_shift_out_mdi_bits routine five different times. The format of
4417 * a MII read instruction consists of a shift out of 14 bits and is
4418 * defined as follows:
4419 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
4420 * followed by a shift in of 18 bits. This first two bits shifted in
4421 * are TurnAround bits used to avoid contention on the MDIO pin when a
4422 * READ operation is performed. These two bits are thrown away
4423 * followed by a shift in of 16 bits which contains the desired data.
4425 mdic = ((reg_addr) | (phy_addr << 5) |
4426 (PHY_OP_READ << 10) | (PHY_SOF << 12));
4428 e1000_shift_out_mdi_bits(hw, mdic, 14);
4430 /* Now that we've shifted out the read command to the MII, we need to
4431 * "shift in" the 16-bit value (18 total bits) of the requested PHY
4434 *phy_data = e1000_shift_in_mdi_bits(hw);
4439 /******************************************************************************
4440 * Writes a value to a PHY register
4442 * hw - Struct containing variables accessed by shared code
4443 * reg_addr - address of the PHY register to write
4444 * data - data to write to the PHY
4445 ******************************************************************************/
4447 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
4451 const uint32_t phy_addr = 1;
4453 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4454 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4455 return -E1000_ERR_PARAM;
4458 if (hw->mac_type > e1000_82543) {
4459 /* Set up Op-code, Phy Address, register address, and data intended
4460 * for the PHY register in the MDI Control register. The MAC will take
4461 * care of interfacing with the PHY to send the desired data.
4463 mdic = (((uint32_t) phy_data) |
4464 (reg_addr << E1000_MDIC_REG_SHIFT) |
4465 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4466 (E1000_MDIC_OP_WRITE));
4468 E1000_WRITE_REG(hw, MDIC, mdic);
4470 /* Poll the ready bit to see if the MDI read completed */
4471 for (i = 0; i < 64; i++) {
4473 mdic = E1000_READ_REG(hw, MDIC);
4474 if (mdic & E1000_MDIC_READY)
4477 if (!(mdic & E1000_MDIC_READY)) {
4478 DEBUGOUT("MDI Write did not complete\n");
4479 return -E1000_ERR_PHY;
4482 /* We'll need to use the SW defined pins to shift the write command
4483 * out to the PHY. We first send a preamble to the PHY to signal the
4484 * beginning of the MII instruction. This is done by sending 32
4485 * consecutive "1" bits.
4487 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4489 /* Now combine the remaining required fields that will indicate a
4490 * write operation. We use this method instead of calling the
4491 * e1000_shift_out_mdi_bits routine for each field in the command. The
4492 * format of a MII write instruction is as follows:
4493 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
4495 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
4496 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
4498 mdic |= (uint32_t) phy_data;
4500 e1000_shift_out_mdi_bits(hw, mdic, 32);
4505 /******************************************************************************
4506 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
4507 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
4508 * the caller to figure out how to deal with it.
4510 * hw - Struct containing variables accessed by shared code
4512 * returns: - E1000_BLK_PHY_RESET
4515 *****************************************************************************/
4517 e1000_check_phy_reset_block(struct e1000_hw *hw)
4522 if (hw->mac_type == e1000_ich8lan) {
4523 fwsm = E1000_READ_REG(hw, FWSM);
4524 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
4525 : E1000_BLK_PHY_RESET;
4528 if (hw->mac_type > e1000_82547_rev_2)
4529 manc = E1000_READ_REG(hw, MANC);
4530 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
4531 E1000_BLK_PHY_RESET : E1000_SUCCESS;
4534 /***************************************************************************
4535 * Checks if the PHY configuration is done
4537 * hw: Struct containing variables accessed by shared code
4539 * returns: - E1000_ERR_RESET if fail to reset MAC
4540 * E1000_SUCCESS at any other case.
4542 ***************************************************************************/
4544 e1000_get_phy_cfg_done(struct e1000_hw *hw)
4546 int32_t timeout = PHY_CFG_TIMEOUT;
4547 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
4551 switch (hw->mac_type) {
4556 case e1000_80003es2lan:
4557 /* Separate *_CFG_DONE_* bit for each port */
4558 if (e1000_is_second_port(hw))
4559 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
4566 if (hw->mac_type == e1000_igb) {
4567 if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
4570 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
4577 DEBUGOUT("MNG configuration cycle has not "
4579 return -E1000_ERR_RESET;
4584 return E1000_SUCCESS;
4587 /******************************************************************************
4588 * Returns the PHY to the power-on reset state
4590 * hw - Struct containing variables accessed by shared code
4591 ******************************************************************************/
4593 e1000_phy_hw_reset(struct e1000_hw *hw)
4595 uint16_t swfw = E1000_SWFW_PHY0_SM;
4596 uint32_t ctrl, ctrl_ext;
4602 /* In the case of the phy reset being blocked, it's not an error, we
4603 * simply return success without performing the reset. */
4604 ret_val = e1000_check_phy_reset_block(hw);
4606 return E1000_SUCCESS;
4608 DEBUGOUT("Resetting Phy...\n");
4610 if (hw->mac_type > e1000_82543) {
4611 if (e1000_is_second_port(hw))
4612 swfw = E1000_SWFW_PHY1_SM;
4614 if (e1000_swfw_sync_acquire(hw, swfw)) {
4615 DEBUGOUT("Unable to acquire swfw sync\n");
4616 return -E1000_ERR_SWFW_SYNC;
4619 /* Read the device control register and assert the E1000_CTRL_PHY_RST
4620 * bit. Then, take it out of reset.
4622 ctrl = E1000_READ_REG(hw, CTRL);
4623 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
4624 E1000_WRITE_FLUSH(hw);
4626 if (hw->mac_type < e1000_82571)
4631 E1000_WRITE_REG(hw, CTRL, ctrl);
4632 E1000_WRITE_FLUSH(hw);
4634 if (hw->mac_type >= e1000_82571)
4638 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
4639 * bit to put the PHY into reset. Then, take it out of reset.
4641 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4642 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
4643 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
4644 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4645 E1000_WRITE_FLUSH(hw);
4647 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
4648 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4649 E1000_WRITE_FLUSH(hw);
4653 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
4654 /* Configure activity LED after PHY reset */
4655 led_ctrl = E1000_READ_REG(hw, LEDCTL);
4656 led_ctrl &= IGP_ACTIVITY_LED_MASK;
4657 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
4658 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
4661 e1000_swfw_sync_release(hw, swfw);
4663 /* Wait for FW to finish PHY configuration. */
4664 ret_val = e1000_get_phy_cfg_done(hw);
4665 if (ret_val != E1000_SUCCESS)
4671 /******************************************************************************
4672 * IGP phy init script - initializes the GbE PHY
4674 * hw - Struct containing variables accessed by shared code
4675 *****************************************************************************/
4677 e1000_phy_init_script(struct e1000_hw *hw)
4680 uint16_t phy_saved_data;
4683 if (hw->phy_init_script) {
4686 /* Save off the current value of register 0x2F5B to be
4687 * restored at the end of this routine. */
4688 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
4690 /* Disabled the PHY transmitter */
4691 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
4695 e1000_write_phy_reg(hw, 0x0000, 0x0140);
4699 switch (hw->mac_type) {
4702 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
4704 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
4706 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
4708 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
4710 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
4712 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
4714 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
4716 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
4718 e1000_write_phy_reg(hw, 0x2010, 0x0008);
4721 case e1000_82541_rev_2:
4722 case e1000_82547_rev_2:
4723 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
4729 e1000_write_phy_reg(hw, 0x0000, 0x3300);
4733 /* Now enable the transmitter */
4735 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
4737 if (hw->mac_type == e1000_82547) {
4738 uint16_t fused, fine, coarse;
4740 /* Move to analog registers page */
4741 e1000_read_phy_reg(hw,
4742 IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
4744 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
4745 e1000_read_phy_reg(hw,
4746 IGP01E1000_ANALOG_FUSE_STATUS, &fused);
4748 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
4750 & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
4753 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
4755 IGP01E1000_ANALOG_FUSE_COARSE_10;
4756 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
4758 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
4759 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
4762 & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
4764 & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
4766 & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
4768 e1000_write_phy_reg(hw,
4769 IGP01E1000_ANALOG_FUSE_CONTROL, fused);
4770 e1000_write_phy_reg(hw,
4771 IGP01E1000_ANALOG_FUSE_BYPASS,
4772 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
4778 /******************************************************************************
4781 * hw - Struct containing variables accessed by shared code
4783 * Sets bit 15 of the MII Control register
4784 ******************************************************************************/
4786 e1000_phy_reset(struct e1000_hw *hw)
4793 /* In the case of the phy reset being blocked, it's not an error, we
4794 * simply return success without performing the reset. */
4795 ret_val = e1000_check_phy_reset_block(hw);
4797 return E1000_SUCCESS;
4799 switch (hw->phy_type) {
4801 case e1000_phy_igp_2:
4802 case e1000_phy_igp_3:
4805 ret_val = e1000_phy_hw_reset(hw);
4810 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
4814 phy_data |= MII_CR_RESET;
4815 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
4823 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
4824 e1000_phy_init_script(hw);
4826 return E1000_SUCCESS;
4829 static int e1000_set_phy_type (struct e1000_hw *hw)
4833 if (hw->mac_type == e1000_undefined)
4834 return -E1000_ERR_PHY_TYPE;
4836 switch (hw->phy_id) {
4837 case M88E1000_E_PHY_ID:
4838 case M88E1000_I_PHY_ID:
4839 case M88E1011_I_PHY_ID:
4840 case M88E1111_I_PHY_ID:
4841 hw->phy_type = e1000_phy_m88;
4843 case IGP01E1000_I_PHY_ID:
4844 if (hw->mac_type == e1000_82541 ||
4845 hw->mac_type == e1000_82541_rev_2 ||
4846 hw->mac_type == e1000_82547 ||
4847 hw->mac_type == e1000_82547_rev_2) {
4848 hw->phy_type = e1000_phy_igp;
4851 case IGP03E1000_E_PHY_ID:
4852 hw->phy_type = e1000_phy_igp_3;
4855 case IFE_PLUS_E_PHY_ID:
4856 case IFE_C_E_PHY_ID:
4857 hw->phy_type = e1000_phy_ife;
4859 case GG82563_E_PHY_ID:
4860 if (hw->mac_type == e1000_80003es2lan) {
4861 hw->phy_type = e1000_phy_gg82563;
4864 case BME1000_E_PHY_ID:
4865 hw->phy_type = e1000_phy_bm;
4868 hw->phy_type = e1000_phy_igb;
4872 /* Should never have loaded on this device */
4873 hw->phy_type = e1000_phy_undefined;
4874 return -E1000_ERR_PHY_TYPE;
4877 return E1000_SUCCESS;
4880 /******************************************************************************
4881 * Probes the expected PHY address for known PHY IDs
4883 * hw - Struct containing variables accessed by shared code
4884 ******************************************************************************/
4886 e1000_detect_gig_phy(struct e1000_hw *hw)
4888 int32_t phy_init_status, ret_val;
4889 uint16_t phy_id_high, phy_id_low;
4894 /* The 82571 firmware may still be configuring the PHY. In this
4895 * case, we cannot access the PHY until the configuration is done. So
4896 * we explicitly set the PHY values. */
4897 if (hw->mac_type == e1000_82571 ||
4898 hw->mac_type == e1000_82572) {
4899 hw->phy_id = IGP01E1000_I_PHY_ID;
4900 hw->phy_type = e1000_phy_igp_2;
4901 return E1000_SUCCESS;
4904 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
4905 * work- around that forces PHY page 0 to be set or the reads fail.
4906 * The rest of the code in this routine uses e1000_read_phy_reg to
4907 * read the PHY ID. So for ESB-2 we need to have this set so our
4908 * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
4909 * the routines below will figure this out as well. */
4910 if (hw->mac_type == e1000_80003es2lan)
4911 hw->phy_type = e1000_phy_gg82563;
4913 /* Read the PHY ID Registers to identify which PHY is onboard. */
4914 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4918 hw->phy_id = (uint32_t) (phy_id_high << 16);
4920 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4924 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4925 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4927 switch (hw->mac_type) {
4929 if (hw->phy_id == M88E1000_E_PHY_ID)
4933 if (hw->phy_id == M88E1000_I_PHY_ID)
4938 case e1000_82545_rev_3:
4940 case e1000_82546_rev_3:
4941 if (hw->phy_id == M88E1011_I_PHY_ID)
4945 case e1000_82541_rev_2:
4947 case e1000_82547_rev_2:
4948 if(hw->phy_id == IGP01E1000_I_PHY_ID)
4953 if (hw->phy_id == M88E1111_I_PHY_ID)
4957 if (hw->phy_id == BME1000_E_PHY_ID)
4960 case e1000_80003es2lan:
4961 if (hw->phy_id == GG82563_E_PHY_ID)
4965 if (hw->phy_id == IGP03E1000_E_PHY_ID)
4967 if (hw->phy_id == IFE_E_PHY_ID)
4969 if (hw->phy_id == IFE_PLUS_E_PHY_ID)
4971 if (hw->phy_id == IFE_C_E_PHY_ID)
4975 if (hw->phy_id == I210_I_PHY_ID)
4979 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
4980 return -E1000_ERR_CONFIG;
4983 phy_init_status = e1000_set_phy_type(hw);
4985 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4986 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
4989 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
4990 return -E1000_ERR_PHY;
4993 /*****************************************************************************
4994 * Set media type and TBI compatibility.
4996 * hw - Struct containing variables accessed by shared code
4997 * **************************************************************************/
4999 e1000_set_media_type(struct e1000_hw *hw)
5005 if (hw->mac_type != e1000_82543) {
5006 /* tbi_compatibility is only valid on 82543 */
5007 hw->tbi_compatibility_en = false;
5010 switch (hw->device_id) {
5011 case E1000_DEV_ID_82545GM_SERDES:
5012 case E1000_DEV_ID_82546GB_SERDES:
5013 case E1000_DEV_ID_82571EB_SERDES:
5014 case E1000_DEV_ID_82571EB_SERDES_DUAL:
5015 case E1000_DEV_ID_82571EB_SERDES_QUAD:
5016 case E1000_DEV_ID_82572EI_SERDES:
5017 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
5018 hw->media_type = e1000_media_type_internal_serdes;
5021 switch (hw->mac_type) {
5022 case e1000_82542_rev2_0:
5023 case e1000_82542_rev2_1:
5024 hw->media_type = e1000_media_type_fiber;
5030 /* The STATUS_TBIMODE bit is reserved or reused
5031 * for the this device.
5033 hw->media_type = e1000_media_type_copper;
5036 status = E1000_READ_REG(hw, STATUS);
5037 if (status & E1000_STATUS_TBIMODE) {
5038 hw->media_type = e1000_media_type_fiber;
5039 /* tbi_compatibility not valid on fiber */
5040 hw->tbi_compatibility_en = false;
5042 hw->media_type = e1000_media_type_copper;
5050 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
5052 * e1000_sw_init initializes the Adapter private data structure.
5053 * Fields are initialized based on PCI device information and
5054 * OS network device settings (MTU size).
5058 e1000_sw_init(struct e1000_hw *hw)
5062 /* PCI config space info */
5063 #ifdef CONFIG_DM_ETH
5064 dm_pci_read_config16(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
5065 dm_pci_read_config16(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
5066 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
5067 &hw->subsystem_vendor_id);
5068 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
5070 dm_pci_read_config8(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
5071 dm_pci_read_config16(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
5073 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
5074 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
5075 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
5076 &hw->subsystem_vendor_id);
5077 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
5079 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
5080 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
5083 /* identify the MAC */
5084 result = e1000_set_mac_type(hw);
5086 E1000_ERR(hw, "Unknown MAC Type\n");
5090 switch (hw->mac_type) {
5095 case e1000_82541_rev_2:
5096 case e1000_82547_rev_2:
5097 hw->phy_init_script = 1;
5101 /* flow control settings */
5102 hw->fc_high_water = E1000_FC_HIGH_THRESH;
5103 hw->fc_low_water = E1000_FC_LOW_THRESH;
5104 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
5105 hw->fc_send_xon = 1;
5107 /* Media type - copper or fiber */
5108 hw->tbi_compatibility_en = true;
5109 e1000_set_media_type(hw);
5111 if (hw->mac_type >= e1000_82543) {
5112 uint32_t status = E1000_READ_REG(hw, STATUS);
5114 if (status & E1000_STATUS_TBIMODE) {
5115 DEBUGOUT("fiber interface\n");
5116 hw->media_type = e1000_media_type_fiber;
5118 DEBUGOUT("copper interface\n");
5119 hw->media_type = e1000_media_type_copper;
5122 hw->media_type = e1000_media_type_fiber;
5125 hw->wait_autoneg_complete = true;
5126 if (hw->mac_type < e1000_82543)
5127 hw->report_tx_early = 0;
5129 hw->report_tx_early = 1;
5131 return E1000_SUCCESS;
5135 fill_rx(struct e1000_hw *hw)
5137 struct e1000_rx_desc *rd;
5138 unsigned long flush_start, flush_end;
5141 rd = rx_base + rx_tail;
5142 rx_tail = (rx_tail + 1) % 8;
5144 rd->buffer_addr = cpu_to_le64((unsigned long)packet);
5147 * Make sure there are no stale data in WB over this area, which
5148 * might get written into the memory while the e1000 also writes
5149 * into the same memory area.
5151 invalidate_dcache_range((unsigned long)packet,
5152 (unsigned long)packet + 4096);
5153 /* Dump the DMA descriptor into RAM. */
5154 flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5155 flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5156 flush_dcache_range(flush_start, flush_end);
5158 E1000_WRITE_REG(hw, RDT, rx_tail);
5162 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
5163 * @adapter: board private structure
5165 * Configure the Tx unit of the MAC after a reset.
5169 e1000_configure_tx(struct e1000_hw *hw)
5172 unsigned long tipg, tarc;
5173 uint32_t ipgr1, ipgr2;
5175 E1000_WRITE_REG(hw, TDBAL, lower_32_bits((unsigned long)tx_base));
5176 E1000_WRITE_REG(hw, TDBAH, upper_32_bits((unsigned long)tx_base));
5178 E1000_WRITE_REG(hw, TDLEN, 128);
5180 /* Setup the HW Tx Head and Tail descriptor pointers */
5181 E1000_WRITE_REG(hw, TDH, 0);
5182 E1000_WRITE_REG(hw, TDT, 0);
5185 /* Set the default values for the Tx Inter Packet Gap timer */
5186 if (hw->mac_type <= e1000_82547_rev_2 &&
5187 (hw->media_type == e1000_media_type_fiber ||
5188 hw->media_type == e1000_media_type_internal_serdes))
5189 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
5191 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
5193 /* Set the default values for the Tx Inter Packet Gap timer */
5194 switch (hw->mac_type) {
5195 case e1000_82542_rev2_0:
5196 case e1000_82542_rev2_1:
5197 tipg = DEFAULT_82542_TIPG_IPGT;
5198 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
5199 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
5201 case e1000_80003es2lan:
5202 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5203 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
5206 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5207 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
5210 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
5211 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
5212 E1000_WRITE_REG(hw, TIPG, tipg);
5213 /* Program the Transmit Control Register */
5214 tctl = E1000_READ_REG(hw, TCTL);
5215 tctl &= ~E1000_TCTL_CT;
5216 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
5217 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
5219 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
5220 tarc = E1000_READ_REG(hw, TARC0);
5221 /* set the speed mode bit, we'll clear it if we're not at
5222 * gigabit link later */
5223 /* git bit can be set to 1*/
5224 } else if (hw->mac_type == e1000_80003es2lan) {
5225 tarc = E1000_READ_REG(hw, TARC0);
5227 E1000_WRITE_REG(hw, TARC0, tarc);
5228 tarc = E1000_READ_REG(hw, TARC1);
5230 E1000_WRITE_REG(hw, TARC1, tarc);
5234 e1000_config_collision_dist(hw);
5235 /* Setup Transmit Descriptor Settings for eop descriptor */
5236 hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
5238 /* Need to set up RS bit */
5239 if (hw->mac_type < e1000_82543)
5240 hw->txd_cmd |= E1000_TXD_CMD_RPS;
5242 hw->txd_cmd |= E1000_TXD_CMD_RS;
5245 if (hw->mac_type == e1000_igb) {
5246 E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
5248 uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
5249 reg_txdctl |= 1 << 25;
5250 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
5256 E1000_WRITE_REG(hw, TCTL, tctl);
5262 * e1000_setup_rctl - configure the receive control register
5263 * @adapter: Board private structure
5266 e1000_setup_rctl(struct e1000_hw *hw)
5270 rctl = E1000_READ_REG(hw, RCTL);
5272 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
5274 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
5275 | E1000_RCTL_RDMTS_HALF; /* |
5276 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
5278 if (hw->tbi_compatibility_on == 1)
5279 rctl |= E1000_RCTL_SBP;
5281 rctl &= ~E1000_RCTL_SBP;
5283 rctl &= ~(E1000_RCTL_SZ_4096);
5284 rctl |= E1000_RCTL_SZ_2048;
5285 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
5286 E1000_WRITE_REG(hw, RCTL, rctl);
5290 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
5291 * @adapter: board private structure
5293 * Configure the Rx unit of the MAC after a reset.
5296 e1000_configure_rx(struct e1000_hw *hw)
5298 unsigned long rctl, ctrl_ext;
5301 /* make sure receives are disabled while setting up the descriptors */
5302 rctl = E1000_READ_REG(hw, RCTL);
5303 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
5304 if (hw->mac_type >= e1000_82540) {
5305 /* Set the interrupt throttling rate. Value is calculated
5306 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
5307 #define MAX_INTS_PER_SEC 8000
5308 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
5309 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
5312 if (hw->mac_type >= e1000_82571) {
5313 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5314 /* Reset delay timers after every interrupt */
5315 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
5316 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5317 E1000_WRITE_FLUSH(hw);
5319 /* Setup the Base and Length of the Rx Descriptor Ring */
5320 E1000_WRITE_REG(hw, RDBAL, lower_32_bits((unsigned long)rx_base));
5321 E1000_WRITE_REG(hw, RDBAH, upper_32_bits((unsigned long)rx_base));
5323 E1000_WRITE_REG(hw, RDLEN, 128);
5325 /* Setup the HW Rx Head and Tail Descriptor Pointers */
5326 E1000_WRITE_REG(hw, RDH, 0);
5327 E1000_WRITE_REG(hw, RDT, 0);
5328 /* Enable Receives */
5330 if (hw->mac_type == e1000_igb) {
5332 uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
5333 reg_rxdctl |= 1 << 25;
5334 E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
5338 E1000_WRITE_REG(hw, RCTL, rctl);
5343 /**************************************************************************
5344 POLL - Wait for a frame
5345 ***************************************************************************/
5347 _e1000_poll(struct e1000_hw *hw)
5349 struct e1000_rx_desc *rd;
5350 unsigned long inval_start, inval_end;
5353 /* return true if there's an ethernet packet ready to read */
5354 rd = rx_base + rx_last;
5356 /* Re-load the descriptor from RAM. */
5357 inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5358 inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5359 invalidate_dcache_range(inval_start, inval_end);
5361 if (!(rd->status & E1000_RXD_STAT_DD))
5363 /* DEBUGOUT("recv: packet len=%d\n", rd->length); */
5364 /* Packet received, make sure the data are re-loaded from RAM. */
5365 len = le16_to_cpu(rd->length);
5366 invalidate_dcache_range((unsigned long)packet,
5367 (unsigned long)packet +
5368 roundup(len, ARCH_DMA_MINALIGN));
5372 static int _e1000_transmit(struct e1000_hw *hw, void *txpacket, int length)
5374 void *nv_packet = (void *)txpacket;
5375 struct e1000_tx_desc *txp;
5377 unsigned long flush_start, flush_end;
5379 txp = tx_base + tx_tail;
5380 tx_tail = (tx_tail + 1) % 8;
5382 txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
5383 txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
5384 txp->upper.data = 0;
5386 /* Dump the packet into RAM so e1000 can pick them. */
5387 flush_dcache_range((unsigned long)nv_packet,
5388 (unsigned long)nv_packet +
5389 roundup(length, ARCH_DMA_MINALIGN));
5390 /* Dump the descriptor into RAM as well. */
5391 flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1);
5392 flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
5393 flush_dcache_range(flush_start, flush_end);
5395 E1000_WRITE_REG(hw, TDT, tx_tail);
5397 E1000_WRITE_FLUSH(hw);
5399 invalidate_dcache_range(flush_start, flush_end);
5400 if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
5402 if (i++ > TOUT_LOOP) {
5403 DEBUGOUT("e1000: tx timeout\n");
5406 udelay(10); /* give the nic a chance to write to the register */
5412 _e1000_disable(struct e1000_hw *hw)
5414 /* Turn off the ethernet interface */
5415 E1000_WRITE_REG(hw, RCTL, 0);
5416 E1000_WRITE_REG(hw, TCTL, 0);
5418 /* Clear the transmit ring */
5419 E1000_WRITE_REG(hw, TDH, 0);
5420 E1000_WRITE_REG(hw, TDT, 0);
5422 /* Clear the receive ring */
5423 E1000_WRITE_REG(hw, RDH, 0);
5424 E1000_WRITE_REG(hw, RDT, 0);
5431 e1000_reset(struct e1000_hw *hw, unsigned char enetaddr[6])
5434 if (hw->mac_type >= e1000_82544)
5435 E1000_WRITE_REG(hw, WUC, 0);
5437 return e1000_init_hw(hw, enetaddr);
5441 _e1000_init(struct e1000_hw *hw, unsigned char enetaddr[6])
5445 ret_val = e1000_reset(hw, enetaddr);
5447 if ((ret_val == -E1000_ERR_NOLINK) ||
5448 (ret_val == -E1000_ERR_TIMEOUT)) {
5449 E1000_ERR(hw, "Valid Link not detected: %d\n", ret_val);
5451 E1000_ERR(hw, "Hardware Initialization Failed\n");
5455 e1000_configure_tx(hw);
5456 e1000_setup_rctl(hw);
5457 e1000_configure_rx(hw);
5461 /******************************************************************************
5462 * Gets the current PCI bus type of hardware
5464 * hw - Struct containing variables accessed by shared code
5465 *****************************************************************************/
5466 void e1000_get_bus_type(struct e1000_hw *hw)
5470 switch (hw->mac_type) {
5471 case e1000_82542_rev2_0:
5472 case e1000_82542_rev2_1:
5473 hw->bus_type = e1000_bus_type_pci;
5479 case e1000_80003es2lan:
5482 hw->bus_type = e1000_bus_type_pci_express;
5485 status = E1000_READ_REG(hw, STATUS);
5486 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5487 e1000_bus_type_pcix : e1000_bus_type_pci;
5492 #ifndef CONFIG_DM_ETH
5493 /* A list of all registered e1000 devices */
5494 static LIST_HEAD(e1000_hw_list);
5497 #ifdef CONFIG_DM_ETH
5498 static int e1000_init_one(struct e1000_hw *hw, int cardnum,
5499 struct udevice *devno, unsigned char enetaddr[6])
5501 static int e1000_init_one(struct e1000_hw *hw, int cardnum, pci_dev_t devno,
5502 unsigned char enetaddr[6])
5507 /* Assign the passed-in values */
5508 #ifdef CONFIG_DM_ETH
5513 hw->cardnum = cardnum;
5515 /* Print a debug message with the IO base address */
5516 #ifdef CONFIG_DM_ETH
5517 dm_pci_read_config32(devno, PCI_BASE_ADDRESS_0, &val);
5519 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
5521 E1000_DBG(hw, "iobase 0x%08x\n", val & 0xfffffff0);
5523 /* Try to enable I/O accesses and bus-mastering */
5524 val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
5525 #ifdef CONFIG_DM_ETH
5526 dm_pci_write_config32(devno, PCI_COMMAND, val);
5528 pci_write_config_dword(devno, PCI_COMMAND, val);
5531 /* Make sure it worked */
5532 #ifdef CONFIG_DM_ETH
5533 dm_pci_read_config32(devno, PCI_COMMAND, &val);
5535 pci_read_config_dword(devno, PCI_COMMAND, &val);
5537 if (!(val & PCI_COMMAND_MEMORY)) {
5538 E1000_ERR(hw, "Can't enable I/O memory\n");
5541 if (!(val & PCI_COMMAND_MASTER)) {
5542 E1000_ERR(hw, "Can't enable bus-mastering\n");
5546 /* Are these variables needed? */
5547 hw->fc = e1000_fc_default;
5548 hw->original_fc = e1000_fc_default;
5549 hw->autoneg_failed = 0;
5551 hw->get_link_status = true;
5552 #ifndef CONFIG_E1000_NO_NVM
5553 hw->eeprom_semaphore_present = true;
5555 #ifdef CONFIG_DM_ETH
5556 hw->hw_addr = dm_pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5559 hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5562 hw->mac_type = e1000_undefined;
5564 /* MAC and Phy settings */
5565 if (e1000_sw_init(hw) < 0) {
5566 E1000_ERR(hw, "Software init failed\n");
5569 if (e1000_check_phy_reset_block(hw))
5570 E1000_ERR(hw, "PHY Reset is blocked!\n");
5572 /* Basic init was OK, reset the hardware and allow SPI access */
5575 #ifndef CONFIG_E1000_NO_NVM
5576 /* Validate the EEPROM and get chipset information */
5577 if (e1000_init_eeprom_params(hw)) {
5578 E1000_ERR(hw, "EEPROM is invalid!\n");
5581 if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
5582 e1000_validate_eeprom_checksum(hw))
5584 e1000_read_mac_addr(hw, enetaddr);
5586 e1000_get_bus_type(hw);
5588 #ifndef CONFIG_E1000_NO_NVM
5589 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
5590 enetaddr[0], enetaddr[1], enetaddr[2],
5591 enetaddr[3], enetaddr[4], enetaddr[5]);
5593 memset(enetaddr, 0, 6);
5594 printf("e1000: no NVM\n");
5600 /* Put the name of a device in a string */
5601 static void e1000_name(char *str, int cardnum)
5603 sprintf(str, "e1000#%u", cardnum);
5606 #ifndef CONFIG_DM_ETH
5607 /**************************************************************************
5608 TRANSMIT - Transmit a frame
5609 ***************************************************************************/
5610 static int e1000_transmit(struct eth_device *nic, void *txpacket, int length)
5612 struct e1000_hw *hw = nic->priv;
5614 return _e1000_transmit(hw, txpacket, length);
5617 /**************************************************************************
5618 DISABLE - Turn off ethernet interface
5619 ***************************************************************************/
5621 e1000_disable(struct eth_device *nic)
5623 struct e1000_hw *hw = nic->priv;
5628 /**************************************************************************
5629 INIT - set up ethernet interface(s)
5630 ***************************************************************************/
5632 e1000_init(struct eth_device *nic, bd_t *bis)
5634 struct e1000_hw *hw = nic->priv;
5636 return _e1000_init(hw, nic->enetaddr);
5640 e1000_poll(struct eth_device *nic)
5642 struct e1000_hw *hw = nic->priv;
5645 len = _e1000_poll(hw);
5647 net_process_received_packet((uchar *)packet, len);
5654 static int e1000_write_hwaddr(struct eth_device *dev)
5656 #ifndef CONFIG_E1000_NO_NVM
5657 unsigned char *mac = dev->enetaddr;
5658 unsigned char current_mac[6];
5659 struct e1000_hw *hw = dev->priv;
5663 DEBUGOUT("%s: mac=%pM\n", __func__, mac);
5665 memset(current_mac, 0, 6);
5667 /* Read from EEPROM, not from registers, to make sure
5668 * the address is persistently configured
5670 ret_val = e1000_read_mac_addr_from_eeprom(hw, current_mac);
5671 DEBUGOUT("%s: current mac=%pM\n", __func__, current_mac);
5673 /* Only write to EEPROM if the given address is different or
5674 * reading the current address failed
5676 if (!ret_val && memcmp(current_mac, mac, 6) == 0)
5679 for (i = 0; i < 3; ++i)
5680 data[i] = mac[i * 2 + 1] << 8 | mac[i * 2];
5682 ret_val = e1000_write_eeprom_srwr(hw, 0x0, 3, data);
5685 ret_val = e1000_update_eeprom_checksum_i210(hw);
5693 /**************************************************************************
5694 PROBE - Look for an adapter, this routine's visible to the outside
5695 You should omit the last argument struct pci_device * for a non-PCI NIC
5696 ***************************************************************************/
5698 e1000_initialize(bd_t * bis)
5706 /* Find and probe all the matching PCI devices */
5707 for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
5709 * These will never get freed due to errors, this allows us to
5710 * perform SPI EEPROM programming from U-Boot, for example.
5712 struct eth_device *nic = malloc(sizeof(*nic));
5713 struct e1000_hw *hw = malloc(sizeof(*hw));
5715 printf("e1000#%u: Out of Memory!\n", i);
5721 /* Make sure all of the fields are initially zeroed */
5722 memset(nic, 0, sizeof(*nic));
5723 memset(hw, 0, sizeof(*hw));
5726 /* Generate a card name */
5727 e1000_name(nic->name, i);
5728 hw->name = nic->name;
5730 ret = e1000_init_one(hw, i, devno, nic->enetaddr);
5733 list_add_tail(&hw->list_node, &e1000_hw_list);
5737 /* Set up the function pointers and register the device */
5738 nic->init = e1000_init;
5739 nic->recv = e1000_poll;
5740 nic->send = e1000_transmit;
5741 nic->halt = e1000_disable;
5742 nic->write_hwaddr = e1000_write_hwaddr;
5749 struct e1000_hw *e1000_find_card(unsigned int cardnum)
5751 struct e1000_hw *hw;
5753 list_for_each_entry(hw, &e1000_hw_list, list_node)
5754 if (hw->cardnum == cardnum)
5759 #endif /* !CONFIG_DM_ETH */
5761 #ifdef CONFIG_CMD_E1000
5762 static int do_e1000(cmd_tbl_t *cmdtp, int flag,
5763 int argc, char * const argv[])
5765 unsigned char *mac = NULL;
5766 #ifdef CONFIG_DM_ETH
5767 struct eth_pdata *plat;
5768 struct udevice *dev;
5772 #if !defined(CONFIG_DM_ETH) || defined(CONFIG_E1000_SPI)
5773 struct e1000_hw *hw;
5782 /* Make sure we can find the requested e1000 card */
5783 cardnum = simple_strtoul(argv[1], NULL, 10);
5784 #ifdef CONFIG_DM_ETH
5785 e1000_name(name, cardnum);
5786 ret = uclass_get_device_by_name(UCLASS_ETH, name, &dev);
5788 plat = dev_get_platdata(dev);
5789 mac = plat->enetaddr;
5792 hw = e1000_find_card(cardnum);
5794 mac = hw->nic->enetaddr;
5797 printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
5801 if (!strcmp(argv[2], "print-mac-address")) {
5802 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5803 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
5807 #ifdef CONFIG_E1000_SPI
5808 #ifdef CONFIG_DM_ETH
5809 hw = dev_get_priv(dev);
5811 /* Handle the "SPI" subcommand */
5812 if (!strcmp(argv[2], "spi"))
5813 return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
5821 e1000, 7, 0, do_e1000,
5822 "Intel e1000 controller management",
5823 /* */"<card#> print-mac-address\n"
5824 #ifdef CONFIG_E1000_SPI
5825 "e1000 <card#> spi show [<offset> [<length>]]\n"
5826 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5827 "e1000 <card#> spi program <addr> <offset> <length>\n"
5828 "e1000 <card#> spi checksum [update]\n"
5830 " - Manage the Intel E1000 PCI device"
5832 #endif /* not CONFIG_CMD_E1000 */
5834 #ifdef CONFIG_DM_ETH
5835 static int e1000_eth_start(struct udevice *dev)
5837 struct eth_pdata *plat = dev_get_platdata(dev);
5838 struct e1000_hw *hw = dev_get_priv(dev);
5840 return _e1000_init(hw, plat->enetaddr);
5843 static void e1000_eth_stop(struct udevice *dev)
5845 struct e1000_hw *hw = dev_get_priv(dev);
5850 static int e1000_eth_send(struct udevice *dev, void *packet, int length)
5852 struct e1000_hw *hw = dev_get_priv(dev);
5855 ret = _e1000_transmit(hw, packet, length);
5857 return ret ? 0 : -ETIMEDOUT;
5860 static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp)
5862 struct e1000_hw *hw = dev_get_priv(dev);
5865 len = _e1000_poll(hw);
5869 return len ? len : -EAGAIN;
5872 static int e1000_free_pkt(struct udevice *dev, uchar *packet, int length)
5874 struct e1000_hw *hw = dev_get_priv(dev);
5881 static int e1000_eth_probe(struct udevice *dev)
5883 struct eth_pdata *plat = dev_get_platdata(dev);
5884 struct e1000_hw *hw = dev_get_priv(dev);
5887 hw->name = dev->name;
5888 ret = e1000_init_one(hw, trailing_strtol(dev->name),
5889 dev, plat->enetaddr);
5891 printf(pr_fmt("failed to initialize card: %d\n"), ret);
5898 static int e1000_eth_bind(struct udevice *dev)
5903 * A simple way to number the devices. When device tree is used this
5904 * is unnecessary, but when the device is just discovered on the PCI
5905 * bus we need a name. We could instead have the uclass figure out
5906 * which devices are different and number them.
5908 e1000_name(name, num_cards++);
5910 return device_set_name(dev, name);
5913 static const struct eth_ops e1000_eth_ops = {
5914 .start = e1000_eth_start,
5915 .send = e1000_eth_send,
5916 .recv = e1000_eth_recv,
5917 .stop = e1000_eth_stop,
5918 .free_pkt = e1000_free_pkt,
5921 static const struct udevice_id e1000_eth_ids[] = {
5922 { .compatible = "intel,e1000" },
5926 U_BOOT_DRIVER(eth_e1000) = {
5927 .name = "eth_e1000",
5929 .of_match = e1000_eth_ids,
5930 .bind = e1000_eth_bind,
5931 .probe = e1000_eth_probe,
5932 .ops = &e1000_eth_ops,
5933 .priv_auto_alloc_size = sizeof(struct e1000_hw),
5934 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
5937 U_BOOT_PCI_DEVICE(eth_e1000, e1000_supported);