1 /**************************************************************************
2 Intel Pro 1000 for ppcboot/das-u-boot
3 Drivers are port from Intel's Linux driver e1000-4.3.15
4 and from Etherboot pro 1000 driver by mrakes at vivato dot net
5 tested on both gig copper and gig fiber boards
6 ***************************************************************************/
7 /*******************************************************************************
10 Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
12 * SPDX-License-Identifier: GPL-2.0+
15 Linux NICS <linux.nics@intel.com>
16 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
18 *******************************************************************************/
20 * Copyright (C) Archway Digital Solutions.
22 * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
25 * Copyright (C) Linux Networx.
26 * Massive upgrade to work with the new intel gigabit NICs.
27 * <ebiederman at lnxi dot com>
29 * Copyright 2011 Freescale Semiconductor, Inc.
34 #define TOUT_LOOP 100000
36 #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
37 #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
39 #define E1000_DEFAULT_PCI_PBA 0x00000030
40 #define E1000_DEFAULT_PCIE_PBA 0x000a0026
42 /* NIC specific static variables go here */
44 static char tx_pool
[128 + 16];
45 static char rx_pool
[128 + 16];
46 static char packet
[2096];
48 static struct e1000_tx_desc
*tx_base
;
49 static struct e1000_rx_desc
*rx_base
;
52 static int rx_tail
, rx_last
;
54 static struct pci_device_id e1000_supported
[] = {
55 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82542
},
56 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82543GC_FIBER
},
57 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82543GC_COPPER
},
58 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82544EI_COPPER
},
59 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82544EI_FIBER
},
60 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82544GC_COPPER
},
61 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82544GC_LOM
},
62 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82540EM
},
63 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82545EM_COPPER
},
64 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82545GM_COPPER
},
65 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82546EB_COPPER
},
66 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82545EM_FIBER
},
67 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82546EB_FIBER
},
68 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82546GB_COPPER
},
69 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82540EM_LOM
},
70 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82541ER
},
71 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82541GI_LF
},
73 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571EB_COPPER
},
74 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571EB_FIBER
},
75 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571EB_SERDES
},
76 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER
},
77 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER
},
78 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER
},
79 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE
},
80 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL
},
81 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD
},
82 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82572EI_COPPER
},
83 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82572EI_FIBER
},
84 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82572EI_SERDES
},
85 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82572EI
},
86 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82573E
},
87 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82573E_IAMT
},
88 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82573L
},
89 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82574L
},
90 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3
},
91 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT
},
92 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT
},
93 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT
},
94 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT
},
98 /* Function forward declarations */
99 static int e1000_setup_link(struct eth_device
*nic
);
100 static int e1000_setup_fiber_link(struct eth_device
*nic
);
101 static int e1000_setup_copper_link(struct eth_device
*nic
);
102 static int e1000_phy_setup_autoneg(struct e1000_hw
*hw
);
103 static void e1000_config_collision_dist(struct e1000_hw
*hw
);
104 static int e1000_config_mac_to_phy(struct e1000_hw
*hw
);
105 static int e1000_config_fc_after_link_up(struct e1000_hw
*hw
);
106 static int e1000_check_for_link(struct eth_device
*nic
);
107 static int e1000_wait_autoneg(struct e1000_hw
*hw
);
108 static int e1000_get_speed_and_duplex(struct e1000_hw
*hw
, uint16_t * speed
,
110 static int e1000_read_phy_reg(struct e1000_hw
*hw
, uint32_t reg_addr
,
111 uint16_t * phy_data
);
112 static int e1000_write_phy_reg(struct e1000_hw
*hw
, uint32_t reg_addr
,
114 static int32_t e1000_phy_hw_reset(struct e1000_hw
*hw
);
115 static int e1000_phy_reset(struct e1000_hw
*hw
);
116 static int e1000_detect_gig_phy(struct e1000_hw
*hw
);
117 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw
*hw
);
118 static void e1000_set_media_type(struct e1000_hw
*hw
);
120 static int32_t e1000_swfw_sync_acquire(struct e1000_hw
*hw
, uint16_t mask
);
121 static int32_t e1000_check_phy_reset_block(struct e1000_hw
*hw
);
123 static int32_t e1000_read_eeprom(struct e1000_hw
*hw
, uint16_t offset
,
126 /******************************************************************************
127 * Raises the EEPROM's clock input.
129 * hw - Struct containing variables accessed by shared code
130 * eecd - EECD's current value
131 *****************************************************************************/
132 void e1000_raise_ee_clk(struct e1000_hw
*hw
, uint32_t * eecd
)
134 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
135 * wait 50 microseconds.
137 *eecd
= *eecd
| E1000_EECD_SK
;
138 E1000_WRITE_REG(hw
, EECD
, *eecd
);
139 E1000_WRITE_FLUSH(hw
);
143 /******************************************************************************
144 * Lowers the EEPROM's clock input.
146 * hw - Struct containing variables accessed by shared code
147 * eecd - EECD's current value
148 *****************************************************************************/
149 void e1000_lower_ee_clk(struct e1000_hw
*hw
, uint32_t * eecd
)
151 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
152 * wait 50 microseconds.
154 *eecd
= *eecd
& ~E1000_EECD_SK
;
155 E1000_WRITE_REG(hw
, EECD
, *eecd
);
156 E1000_WRITE_FLUSH(hw
);
160 /******************************************************************************
161 * Shift data bits out to the EEPROM.
163 * hw - Struct containing variables accessed by shared code
164 * data - data to send to the EEPROM
165 * count - number of bits to shift out
166 *****************************************************************************/
168 e1000_shift_out_ee_bits(struct e1000_hw
*hw
, uint16_t data
, uint16_t count
)
173 /* We need to shift "count" bits out to the EEPROM. So, value in the
174 * "data" parameter will be shifted out to the EEPROM one bit at a time.
175 * In order to do this, "data" must be broken down into bits.
177 mask
= 0x01 << (count
- 1);
178 eecd
= E1000_READ_REG(hw
, EECD
);
179 eecd
&= ~(E1000_EECD_DO
| E1000_EECD_DI
);
181 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
182 * and then raising and then lowering the clock (the SK bit controls
183 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
184 * by setting "DI" to "0" and then raising and then lowering the clock.
186 eecd
&= ~E1000_EECD_DI
;
189 eecd
|= E1000_EECD_DI
;
191 E1000_WRITE_REG(hw
, EECD
, eecd
);
192 E1000_WRITE_FLUSH(hw
);
196 e1000_raise_ee_clk(hw
, &eecd
);
197 e1000_lower_ee_clk(hw
, &eecd
);
203 /* We leave the "DI" bit set to "0" when we leave this routine. */
204 eecd
&= ~E1000_EECD_DI
;
205 E1000_WRITE_REG(hw
, EECD
, eecd
);
208 /******************************************************************************
209 * Shift data bits in from the EEPROM
211 * hw - Struct containing variables accessed by shared code
212 *****************************************************************************/
214 e1000_shift_in_ee_bits(struct e1000_hw
*hw
, uint16_t count
)
220 /* In order to read a register from the EEPROM, we need to shift 'count'
221 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
222 * input to the EEPROM (setting the SK bit), and then reading the
223 * value of the "DO" bit. During this "shifting in" process the
224 * "DI" bit should always be clear.
227 eecd
= E1000_READ_REG(hw
, EECD
);
229 eecd
&= ~(E1000_EECD_DO
| E1000_EECD_DI
);
232 for (i
= 0; i
< count
; i
++) {
234 e1000_raise_ee_clk(hw
, &eecd
);
236 eecd
= E1000_READ_REG(hw
, EECD
);
238 eecd
&= ~(E1000_EECD_DI
);
239 if (eecd
& E1000_EECD_DO
)
242 e1000_lower_ee_clk(hw
, &eecd
);
248 /******************************************************************************
249 * Returns EEPROM to a "standby" state
251 * hw - Struct containing variables accessed by shared code
252 *****************************************************************************/
253 void e1000_standby_eeprom(struct e1000_hw
*hw
)
255 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
258 eecd
= E1000_READ_REG(hw
, EECD
);
260 if (eeprom
->type
== e1000_eeprom_microwire
) {
261 eecd
&= ~(E1000_EECD_CS
| E1000_EECD_SK
);
262 E1000_WRITE_REG(hw
, EECD
, eecd
);
263 E1000_WRITE_FLUSH(hw
);
264 udelay(eeprom
->delay_usec
);
267 eecd
|= E1000_EECD_SK
;
268 E1000_WRITE_REG(hw
, EECD
, eecd
);
269 E1000_WRITE_FLUSH(hw
);
270 udelay(eeprom
->delay_usec
);
273 eecd
|= E1000_EECD_CS
;
274 E1000_WRITE_REG(hw
, EECD
, eecd
);
275 E1000_WRITE_FLUSH(hw
);
276 udelay(eeprom
->delay_usec
);
279 eecd
&= ~E1000_EECD_SK
;
280 E1000_WRITE_REG(hw
, EECD
, eecd
);
281 E1000_WRITE_FLUSH(hw
);
282 udelay(eeprom
->delay_usec
);
283 } else if (eeprom
->type
== e1000_eeprom_spi
) {
284 /* Toggle CS to flush commands */
285 eecd
|= E1000_EECD_CS
;
286 E1000_WRITE_REG(hw
, EECD
, eecd
);
287 E1000_WRITE_FLUSH(hw
);
288 udelay(eeprom
->delay_usec
);
289 eecd
&= ~E1000_EECD_CS
;
290 E1000_WRITE_REG(hw
, EECD
, eecd
);
291 E1000_WRITE_FLUSH(hw
);
292 udelay(eeprom
->delay_usec
);
296 /***************************************************************************
297 * Description: Determines if the onboard NVM is FLASH or EEPROM.
299 * hw - Struct containing variables accessed by shared code
300 ****************************************************************************/
301 static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw
*hw
)
307 if (hw
->mac_type
== e1000_ich8lan
)
310 if (hw
->mac_type
== e1000_82573
|| hw
->mac_type
== e1000_82574
) {
311 eecd
= E1000_READ_REG(hw
, EECD
);
313 /* Isolate bits 15 & 16 */
314 eecd
= ((eecd
>> 15) & 0x03);
316 /* If both bits are set, device is Flash type */
323 /******************************************************************************
324 * Prepares EEPROM for access
326 * hw - Struct containing variables accessed by shared code
328 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
329 * function should be called before issuing a command to the EEPROM.
330 *****************************************************************************/
331 int32_t e1000_acquire_eeprom(struct e1000_hw
*hw
)
333 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
334 uint32_t eecd
, i
= 0;
338 if (e1000_swfw_sync_acquire(hw
, E1000_SWFW_EEP_SM
))
339 return -E1000_ERR_SWFW_SYNC
;
340 eecd
= E1000_READ_REG(hw
, EECD
);
342 if (hw
->mac_type
!= e1000_82573
|| hw
->mac_type
!= e1000_82574
) {
343 /* Request EEPROM Access */
344 if (hw
->mac_type
> e1000_82544
) {
345 eecd
|= E1000_EECD_REQ
;
346 E1000_WRITE_REG(hw
, EECD
, eecd
);
347 eecd
= E1000_READ_REG(hw
, EECD
);
348 while ((!(eecd
& E1000_EECD_GNT
)) &&
349 (i
< E1000_EEPROM_GRANT_ATTEMPTS
)) {
352 eecd
= E1000_READ_REG(hw
, EECD
);
354 if (!(eecd
& E1000_EECD_GNT
)) {
355 eecd
&= ~E1000_EECD_REQ
;
356 E1000_WRITE_REG(hw
, EECD
, eecd
);
357 DEBUGOUT("Could not acquire EEPROM grant\n");
358 return -E1000_ERR_EEPROM
;
363 /* Setup EEPROM for Read/Write */
365 if (eeprom
->type
== e1000_eeprom_microwire
) {
366 /* Clear SK and DI */
367 eecd
&= ~(E1000_EECD_DI
| E1000_EECD_SK
);
368 E1000_WRITE_REG(hw
, EECD
, eecd
);
371 eecd
|= E1000_EECD_CS
;
372 E1000_WRITE_REG(hw
, EECD
, eecd
);
373 } else if (eeprom
->type
== e1000_eeprom_spi
) {
374 /* Clear SK and CS */
375 eecd
&= ~(E1000_EECD_CS
| E1000_EECD_SK
);
376 E1000_WRITE_REG(hw
, EECD
, eecd
);
380 return E1000_SUCCESS
;
383 /******************************************************************************
384 * Sets up eeprom variables in the hw struct. Must be called after mac_type
385 * is configured. Additionally, if this is ICH8, the flash controller GbE
386 * registers must be mapped, or this will crash.
388 * hw - Struct containing variables accessed by shared code
389 *****************************************************************************/
390 static int32_t e1000_init_eeprom_params(struct e1000_hw
*hw
)
392 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
393 uint32_t eecd
= E1000_READ_REG(hw
, EECD
);
394 int32_t ret_val
= E1000_SUCCESS
;
395 uint16_t eeprom_size
;
399 switch (hw
->mac_type
) {
400 case e1000_82542_rev2_0
:
401 case e1000_82542_rev2_1
:
404 eeprom
->type
= e1000_eeprom_microwire
;
405 eeprom
->word_size
= 64;
406 eeprom
->opcode_bits
= 3;
407 eeprom
->address_bits
= 6;
408 eeprom
->delay_usec
= 50;
409 eeprom
->use_eerd
= false;
410 eeprom
->use_eewr
= false;
414 case e1000_82545_rev_3
:
416 case e1000_82546_rev_3
:
417 eeprom
->type
= e1000_eeprom_microwire
;
418 eeprom
->opcode_bits
= 3;
419 eeprom
->delay_usec
= 50;
420 if (eecd
& E1000_EECD_SIZE
) {
421 eeprom
->word_size
= 256;
422 eeprom
->address_bits
= 8;
424 eeprom
->word_size
= 64;
425 eeprom
->address_bits
= 6;
427 eeprom
->use_eerd
= false;
428 eeprom
->use_eewr
= false;
431 case e1000_82541_rev_2
:
433 case e1000_82547_rev_2
:
434 if (eecd
& E1000_EECD_TYPE
) {
435 eeprom
->type
= e1000_eeprom_spi
;
436 eeprom
->opcode_bits
= 8;
437 eeprom
->delay_usec
= 1;
438 if (eecd
& E1000_EECD_ADDR_BITS
) {
439 eeprom
->page_size
= 32;
440 eeprom
->address_bits
= 16;
442 eeprom
->page_size
= 8;
443 eeprom
->address_bits
= 8;
446 eeprom
->type
= e1000_eeprom_microwire
;
447 eeprom
->opcode_bits
= 3;
448 eeprom
->delay_usec
= 50;
449 if (eecd
& E1000_EECD_ADDR_BITS
) {
450 eeprom
->word_size
= 256;
451 eeprom
->address_bits
= 8;
453 eeprom
->word_size
= 64;
454 eeprom
->address_bits
= 6;
457 eeprom
->use_eerd
= false;
458 eeprom
->use_eewr
= false;
462 eeprom
->type
= e1000_eeprom_spi
;
463 eeprom
->opcode_bits
= 8;
464 eeprom
->delay_usec
= 1;
465 if (eecd
& E1000_EECD_ADDR_BITS
) {
466 eeprom
->page_size
= 32;
467 eeprom
->address_bits
= 16;
469 eeprom
->page_size
= 8;
470 eeprom
->address_bits
= 8;
472 eeprom
->use_eerd
= false;
473 eeprom
->use_eewr
= false;
477 eeprom
->type
= e1000_eeprom_spi
;
478 eeprom
->opcode_bits
= 8;
479 eeprom
->delay_usec
= 1;
480 if (eecd
& E1000_EECD_ADDR_BITS
) {
481 eeprom
->page_size
= 32;
482 eeprom
->address_bits
= 16;
484 eeprom
->page_size
= 8;
485 eeprom
->address_bits
= 8;
487 eeprom
->use_eerd
= true;
488 eeprom
->use_eewr
= true;
489 if (e1000_is_onboard_nvm_eeprom(hw
) == false) {
490 eeprom
->type
= e1000_eeprom_flash
;
491 eeprom
->word_size
= 2048;
493 /* Ensure that the Autonomous FLASH update bit is cleared due to
494 * Flash update issue on parts which use a FLASH for NVM. */
495 eecd
&= ~E1000_EECD_AUPDEN
;
496 E1000_WRITE_REG(hw
, EECD
, eecd
);
499 case e1000_80003es2lan
:
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
= true;
511 eeprom
->use_eewr
= false;
514 /* ich8lan does not support currently. if needed, please
515 * add corresponding code and functions.
522 eeprom
->type
= e1000_eeprom_ich8
;
523 eeprom
->use_eerd
= false;
524 eeprom
->use_eewr
= false;
525 eeprom
->word_size
= E1000_SHADOW_RAM_WORDS
;
526 uint32_t flash_size
= E1000_READ_ICH_FLASH_REG(hw
,
528 /* Zero the shadow RAM structure. But don't load it from NVM
529 * so as to save time for driver init */
530 if (hw
->eeprom_shadow_ram
!= NULL
) {
531 for (i
= 0; i
< E1000_SHADOW_RAM_WORDS
; i
++) {
532 hw
->eeprom_shadow_ram
[i
].modified
= false;
533 hw
->eeprom_shadow_ram
[i
].eeprom_word
= 0xFFFF;
537 hw
->flash_base_addr
= (flash_size
& ICH_GFPREG_BASE_MASK
) *
538 ICH_FLASH_SECTOR_SIZE
;
540 hw
->flash_bank_size
= ((flash_size
>> 16)
541 & ICH_GFPREG_BASE_MASK
) + 1;
542 hw
->flash_bank_size
-= (flash_size
& ICH_GFPREG_BASE_MASK
);
544 hw
->flash_bank_size
*= ICH_FLASH_SECTOR_SIZE
;
546 hw
->flash_bank_size
/= 2 * sizeof(uint16_t);
554 if (eeprom
->type
== e1000_eeprom_spi
) {
555 /* eeprom_size will be an enum [0..8] that maps
556 * to eeprom sizes 128B to
557 * 32KB (incremented by powers of 2).
559 if (hw
->mac_type
<= e1000_82547_rev_2
) {
560 /* Set to default value for initial eeprom read. */
561 eeprom
->word_size
= 64;
562 ret_val
= e1000_read_eeprom(hw
, EEPROM_CFG
, 1,
566 eeprom_size
= (eeprom_size
& EEPROM_SIZE_MASK
)
567 >> EEPROM_SIZE_SHIFT
;
568 /* 256B eeprom size was not supported in earlier
569 * hardware, so we bump eeprom_size up one to
570 * ensure that "1" (which maps to 256B) is never
571 * the result used in the shifting logic below. */
575 eeprom_size
= (uint16_t)((eecd
&
576 E1000_EECD_SIZE_EX_MASK
) >>
577 E1000_EECD_SIZE_EX_SHIFT
);
580 eeprom
->word_size
= 1 << (eeprom_size
+ EEPROM_WORD_SIZE_SHIFT
);
585 /******************************************************************************
586 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
588 * hw - Struct containing variables accessed by shared code
589 *****************************************************************************/
591 e1000_poll_eerd_eewr_done(struct e1000_hw
*hw
, int eerd
)
593 uint32_t attempts
= 100000;
595 int32_t done
= E1000_ERR_EEPROM
;
597 for (i
= 0; i
< attempts
; i
++) {
598 if (eerd
== E1000_EEPROM_POLL_READ
)
599 reg
= E1000_READ_REG(hw
, EERD
);
601 reg
= E1000_READ_REG(hw
, EEWR
);
603 if (reg
& E1000_EEPROM_RW_REG_DONE
) {
604 done
= E1000_SUCCESS
;
613 /******************************************************************************
614 * Reads a 16 bit word from the EEPROM using the EERD register.
616 * hw - Struct containing variables accessed by shared code
617 * offset - offset of word in the EEPROM to read
618 * data - word read from the EEPROM
619 * words - number of words to read
620 *****************************************************************************/
622 e1000_read_eeprom_eerd(struct e1000_hw
*hw
,
627 uint32_t i
, eerd
= 0;
630 for (i
= 0; i
< words
; i
++) {
631 eerd
= ((offset
+i
) << E1000_EEPROM_RW_ADDR_SHIFT
) +
632 E1000_EEPROM_RW_REG_START
;
634 E1000_WRITE_REG(hw
, EERD
, eerd
);
635 error
= e1000_poll_eerd_eewr_done(hw
, E1000_EEPROM_POLL_READ
);
639 data
[i
] = (E1000_READ_REG(hw
, EERD
) >>
640 E1000_EEPROM_RW_REG_DATA
);
647 void e1000_release_eeprom(struct e1000_hw
*hw
)
653 eecd
= E1000_READ_REG(hw
, EECD
);
655 if (hw
->eeprom
.type
== e1000_eeprom_spi
) {
656 eecd
|= E1000_EECD_CS
; /* Pull CS high */
657 eecd
&= ~E1000_EECD_SK
; /* Lower SCK */
659 E1000_WRITE_REG(hw
, EECD
, eecd
);
661 udelay(hw
->eeprom
.delay_usec
);
662 } else if (hw
->eeprom
.type
== e1000_eeprom_microwire
) {
665 /* CS on Microwire is active-high */
666 eecd
&= ~(E1000_EECD_CS
| E1000_EECD_DI
);
668 E1000_WRITE_REG(hw
, EECD
, eecd
);
670 /* Rising edge of clock */
671 eecd
|= E1000_EECD_SK
;
672 E1000_WRITE_REG(hw
, EECD
, eecd
);
673 E1000_WRITE_FLUSH(hw
);
674 udelay(hw
->eeprom
.delay_usec
);
676 /* Falling edge of clock */
677 eecd
&= ~E1000_EECD_SK
;
678 E1000_WRITE_REG(hw
, EECD
, eecd
);
679 E1000_WRITE_FLUSH(hw
);
680 udelay(hw
->eeprom
.delay_usec
);
683 /* Stop requesting EEPROM access */
684 if (hw
->mac_type
> e1000_82544
) {
685 eecd
&= ~E1000_EECD_REQ
;
686 E1000_WRITE_REG(hw
, EECD
, eecd
);
689 /******************************************************************************
690 * Reads a 16 bit word from the EEPROM.
692 * hw - Struct containing variables accessed by shared code
693 *****************************************************************************/
695 e1000_spi_eeprom_ready(struct e1000_hw
*hw
)
697 uint16_t retry_count
= 0;
698 uint8_t spi_stat_reg
;
702 /* Read "Status Register" repeatedly until the LSB is cleared. The
703 * EEPROM will signal that the command has been completed by clearing
704 * bit 0 of the internal status register. If it's not cleared within
705 * 5 milliseconds, then error out.
709 e1000_shift_out_ee_bits(hw
, EEPROM_RDSR_OPCODE_SPI
,
710 hw
->eeprom
.opcode_bits
);
711 spi_stat_reg
= (uint8_t)e1000_shift_in_ee_bits(hw
, 8);
712 if (!(spi_stat_reg
& EEPROM_STATUS_RDY_SPI
))
718 e1000_standby_eeprom(hw
);
719 } while (retry_count
< EEPROM_MAX_RETRY_SPI
);
721 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
722 * only 0-5mSec on 5V devices)
724 if (retry_count
>= EEPROM_MAX_RETRY_SPI
) {
725 DEBUGOUT("SPI EEPROM Status error\n");
726 return -E1000_ERR_EEPROM
;
729 return E1000_SUCCESS
;
732 /******************************************************************************
733 * Reads a 16 bit word from the EEPROM.
735 * hw - Struct containing variables accessed by shared code
736 * offset - offset of word in the EEPROM to read
737 * data - word read from the EEPROM
738 *****************************************************************************/
740 e1000_read_eeprom(struct e1000_hw
*hw
, uint16_t offset
,
741 uint16_t words
, uint16_t *data
)
743 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
748 /* If eeprom is not yet detected, do so now */
749 if (eeprom
->word_size
== 0)
750 e1000_init_eeprom_params(hw
);
752 /* A check for invalid values: offset too large, too many words,
753 * and not enough words.
755 if ((offset
>= eeprom
->word_size
) ||
756 (words
> eeprom
->word_size
- offset
) ||
758 DEBUGOUT("\"words\" parameter out of bounds."
759 "Words = %d, size = %d\n", offset
, eeprom
->word_size
);
760 return -E1000_ERR_EEPROM
;
763 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
764 * directly. In this case, we need to acquire the EEPROM so that
765 * FW or other port software does not interrupt.
767 if (e1000_is_onboard_nvm_eeprom(hw
) == true &&
768 hw
->eeprom
.use_eerd
== false) {
770 /* Prepare the EEPROM for bit-bang reading */
771 if (e1000_acquire_eeprom(hw
) != E1000_SUCCESS
)
772 return -E1000_ERR_EEPROM
;
775 /* Eerd register EEPROM access requires no eeprom aquire/release */
776 if (eeprom
->use_eerd
== true)
777 return e1000_read_eeprom_eerd(hw
, offset
, words
, data
);
779 /* ich8lan does not support currently. if needed, please
780 * add corresponding code and functions.
783 /* ICH EEPROM access is done via the ICH flash controller */
784 if (eeprom
->type
== e1000_eeprom_ich8
)
785 return e1000_read_eeprom_ich8(hw
, offset
, words
, data
);
787 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
788 * acquired the EEPROM at this point, so any returns should relase it */
789 if (eeprom
->type
== e1000_eeprom_spi
) {
791 uint8_t read_opcode
= EEPROM_READ_OPCODE_SPI
;
793 if (e1000_spi_eeprom_ready(hw
)) {
794 e1000_release_eeprom(hw
);
795 return -E1000_ERR_EEPROM
;
798 e1000_standby_eeprom(hw
);
800 /* Some SPI eeproms use the 8th address bit embedded in
802 if ((eeprom
->address_bits
== 8) && (offset
>= 128))
803 read_opcode
|= EEPROM_A8_OPCODE_SPI
;
805 /* Send the READ command (opcode + addr) */
806 e1000_shift_out_ee_bits(hw
, read_opcode
, eeprom
->opcode_bits
);
807 e1000_shift_out_ee_bits(hw
, (uint16_t)(offset
*2),
808 eeprom
->address_bits
);
810 /* Read the data. The address of the eeprom internally
811 * increments with each byte (spi) being read, saving on the
812 * overhead of eeprom setup and tear-down. The address
813 * counter will roll over if reading beyond the size of
814 * the eeprom, thus allowing the entire memory to be read
815 * starting from any offset. */
816 for (i
= 0; i
< words
; i
++) {
817 word_in
= e1000_shift_in_ee_bits(hw
, 16);
818 data
[i
] = (word_in
>> 8) | (word_in
<< 8);
820 } else if (eeprom
->type
== e1000_eeprom_microwire
) {
821 for (i
= 0; i
< words
; i
++) {
822 /* Send the READ command (opcode + addr) */
823 e1000_shift_out_ee_bits(hw
,
824 EEPROM_READ_OPCODE_MICROWIRE
,
825 eeprom
->opcode_bits
);
826 e1000_shift_out_ee_bits(hw
, (uint16_t)(offset
+ i
),
827 eeprom
->address_bits
);
829 /* Read the data. For microwire, each word requires
830 * the overhead of eeprom setup and tear-down. */
831 data
[i
] = e1000_shift_in_ee_bits(hw
, 16);
832 e1000_standby_eeprom(hw
);
836 /* End this read operation */
837 e1000_release_eeprom(hw
);
839 return E1000_SUCCESS
;
842 /******************************************************************************
843 * Verifies that the EEPROM has a valid checksum
845 * hw - Struct containing variables accessed by shared code
847 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
848 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
850 *****************************************************************************/
851 static int e1000_validate_eeprom_checksum(struct e1000_hw
*hw
)
853 uint16_t i
, checksum
, checksum_reg
, *buf
;
857 /* Allocate a temporary buffer */
858 buf
= malloc(sizeof(buf
[0]) * (EEPROM_CHECKSUM_REG
+ 1));
860 E1000_ERR(hw
->nic
, "Unable to allocate EEPROM buffer!\n");
861 return -E1000_ERR_EEPROM
;
864 /* Read the EEPROM */
865 if (e1000_read_eeprom(hw
, 0, EEPROM_CHECKSUM_REG
+ 1, buf
) < 0) {
866 E1000_ERR(hw
->nic
, "Unable to read EEPROM!\n");
867 return -E1000_ERR_EEPROM
;
870 /* Compute the checksum */
872 for (i
= 0; i
< EEPROM_CHECKSUM_REG
; i
++)
874 checksum
= ((uint16_t)EEPROM_SUM
) - checksum
;
875 checksum_reg
= buf
[i
];
878 if (checksum
== checksum_reg
)
881 /* Hrm, verification failed, print an error */
882 E1000_ERR(hw
->nic
, "EEPROM checksum is incorrect!\n");
883 E1000_ERR(hw
->nic
, " ...register was 0x%04hx, calculated 0x%04hx\n",
884 checksum_reg
, checksum
);
886 return -E1000_ERR_EEPROM
;
889 /*****************************************************************************
890 * Set PHY to class A mode
891 * Assumes the following operations will follow to enable the new class mode.
892 * 1. Do a PHY soft reset
893 * 2. Restart auto-negotiation or force link.
895 * hw - Struct containing variables accessed by shared code
896 ****************************************************************************/
898 e1000_set_phy_mode(struct e1000_hw
*hw
)
901 uint16_t eeprom_data
;
905 if ((hw
->mac_type
== e1000_82545_rev_3
) &&
906 (hw
->media_type
== e1000_media_type_copper
)) {
907 ret_val
= e1000_read_eeprom(hw
, EEPROM_PHY_CLASS_WORD
,
912 if ((eeprom_data
!= EEPROM_RESERVED_WORD
) &&
913 (eeprom_data
& EEPROM_PHY_CLASS_A
)) {
914 ret_val
= e1000_write_phy_reg(hw
,
915 M88E1000_PHY_PAGE_SELECT
, 0x000B);
918 ret_val
= e1000_write_phy_reg(hw
,
919 M88E1000_PHY_GEN_CONTROL
, 0x8104);
923 hw
->phy_reset_disable
= false;
927 return E1000_SUCCESS
;
930 /***************************************************************************
932 * Obtaining software semaphore bit (SMBI) before resetting PHY.
934 * hw: Struct containing variables accessed by shared code
936 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
937 * E1000_SUCCESS at any other case.
939 ***************************************************************************/
941 e1000_get_software_semaphore(struct e1000_hw
*hw
)
943 int32_t timeout
= hw
->eeprom
.word_size
+ 1;
948 if (hw
->mac_type
!= e1000_80003es2lan
)
949 return E1000_SUCCESS
;
952 swsm
= E1000_READ_REG(hw
, SWSM
);
953 /* If SMBI bit cleared, it is now set and we hold
955 if (!(swsm
& E1000_SWSM_SMBI
))
962 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
963 return -E1000_ERR_RESET
;
966 return E1000_SUCCESS
;
969 /***************************************************************************
970 * This function clears HW semaphore bits.
972 * hw: Struct containing variables accessed by shared code
976 ***************************************************************************/
978 e1000_put_hw_eeprom_semaphore(struct e1000_hw
*hw
)
984 if (!hw
->eeprom_semaphore_present
)
987 swsm
= E1000_READ_REG(hw
, SWSM
);
988 if (hw
->mac_type
== e1000_80003es2lan
) {
989 /* Release both semaphores. */
990 swsm
&= ~(E1000_SWSM_SMBI
| E1000_SWSM_SWESMBI
);
992 swsm
&= ~(E1000_SWSM_SWESMBI
);
993 E1000_WRITE_REG(hw
, SWSM
, swsm
);
996 /***************************************************************************
998 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
999 * adapter or Eeprom access.
1001 * hw: Struct containing variables accessed by shared code
1003 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
1004 * E1000_SUCCESS at any other case.
1006 ***************************************************************************/
1008 e1000_get_hw_eeprom_semaphore(struct e1000_hw
*hw
)
1015 if (!hw
->eeprom_semaphore_present
)
1016 return E1000_SUCCESS
;
1018 if (hw
->mac_type
== e1000_80003es2lan
) {
1019 /* Get the SW semaphore. */
1020 if (e1000_get_software_semaphore(hw
) != E1000_SUCCESS
)
1021 return -E1000_ERR_EEPROM
;
1024 /* Get the FW semaphore. */
1025 timeout
= hw
->eeprom
.word_size
+ 1;
1027 swsm
= E1000_READ_REG(hw
, SWSM
);
1028 swsm
|= E1000_SWSM_SWESMBI
;
1029 E1000_WRITE_REG(hw
, SWSM
, swsm
);
1030 /* if we managed to set the bit we got the semaphore. */
1031 swsm
= E1000_READ_REG(hw
, SWSM
);
1032 if (swsm
& E1000_SWSM_SWESMBI
)
1040 /* Release semaphores */
1041 e1000_put_hw_eeprom_semaphore(hw
);
1042 DEBUGOUT("Driver can't access the Eeprom - "
1043 "SWESMBI bit is set.\n");
1044 return -E1000_ERR_EEPROM
;
1047 return E1000_SUCCESS
;
1051 e1000_swfw_sync_acquire(struct e1000_hw
*hw
, uint16_t mask
)
1053 uint32_t swfw_sync
= 0;
1054 uint32_t swmask
= mask
;
1055 uint32_t fwmask
= mask
<< 16;
1056 int32_t timeout
= 200;
1060 if (e1000_get_hw_eeprom_semaphore(hw
))
1061 return -E1000_ERR_SWFW_SYNC
;
1063 swfw_sync
= E1000_READ_REG(hw
, SW_FW_SYNC
);
1064 if (!(swfw_sync
& (fwmask
| swmask
)))
1067 /* firmware currently using resource (fwmask) */
1068 /* or other software thread currently using resource (swmask) */
1069 e1000_put_hw_eeprom_semaphore(hw
);
1075 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1076 return -E1000_ERR_SWFW_SYNC
;
1079 swfw_sync
|= swmask
;
1080 E1000_WRITE_REG(hw
, SW_FW_SYNC
, swfw_sync
);
1082 e1000_put_hw_eeprom_semaphore(hw
);
1083 return E1000_SUCCESS
;
1086 static bool e1000_is_second_port(struct e1000_hw
*hw
)
1088 switch (hw
->mac_type
) {
1089 case e1000_80003es2lan
:
1092 if (E1000_READ_REG(hw
, STATUS
) & E1000_STATUS_FUNC_1
)
1100 /******************************************************************************
1101 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
1102 * second function of dual function devices
1104 * nic - Struct containing variables accessed by shared code
1105 *****************************************************************************/
1107 e1000_read_mac_addr(struct eth_device
*nic
)
1109 struct e1000_hw
*hw
= nic
->priv
;
1111 uint16_t eeprom_data
;
1116 for (i
= 0; i
< NODE_ADDRESS_SIZE
; i
+= 2) {
1118 if (e1000_read_eeprom(hw
, offset
, 1, &eeprom_data
) < 0) {
1119 DEBUGOUT("EEPROM Read Error\n");
1120 return -E1000_ERR_EEPROM
;
1122 nic
->enetaddr
[i
] = eeprom_data
& 0xff;
1123 nic
->enetaddr
[i
+ 1] = (eeprom_data
>> 8) & 0xff;
1126 /* Invert the last bit if this is the second device */
1127 if (e1000_is_second_port(hw
))
1128 nic
->enetaddr
[5] ^= 1;
1130 #ifdef CONFIG_E1000_FALLBACK_MAC
1131 if (!is_valid_ether_addr(nic
->enetaddr
)) {
1132 unsigned char fb_mac
[NODE_ADDRESS_SIZE
] = CONFIG_E1000_FALLBACK_MAC
;
1134 memcpy (nic
->enetaddr
, fb_mac
, NODE_ADDRESS_SIZE
);
1140 /******************************************************************************
1141 * Initializes receive address filters.
1143 * hw - Struct containing variables accessed by shared code
1145 * Places the MAC address in receive address register 0 and clears the rest
1146 * of the receive addresss registers. Clears the multicast table. Assumes
1147 * the receiver is in reset when the routine is called.
1148 *****************************************************************************/
1150 e1000_init_rx_addrs(struct eth_device
*nic
)
1152 struct e1000_hw
*hw
= nic
->priv
;
1159 /* Setup the receive address. */
1160 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1161 addr_low
= (nic
->enetaddr
[0] |
1162 (nic
->enetaddr
[1] << 8) |
1163 (nic
->enetaddr
[2] << 16) | (nic
->enetaddr
[3] << 24));
1165 addr_high
= (nic
->enetaddr
[4] | (nic
->enetaddr
[5] << 8) | E1000_RAH_AV
);
1167 E1000_WRITE_REG_ARRAY(hw
, RA
, 0, addr_low
);
1168 E1000_WRITE_REG_ARRAY(hw
, RA
, 1, addr_high
);
1170 /* Zero out the other 15 receive addresses. */
1171 DEBUGOUT("Clearing RAR[1-15]\n");
1172 for (i
= 1; i
< E1000_RAR_ENTRIES
; i
++) {
1173 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1), 0);
1174 E1000_WRITE_REG_ARRAY(hw
, RA
, ((i
<< 1) + 1), 0);
1178 /******************************************************************************
1179 * Clears the VLAN filer table
1181 * hw - Struct containing variables accessed by shared code
1182 *****************************************************************************/
1184 e1000_clear_vfta(struct e1000_hw
*hw
)
1188 for (offset
= 0; offset
< E1000_VLAN_FILTER_TBL_SIZE
; offset
++)
1189 E1000_WRITE_REG_ARRAY(hw
, VFTA
, offset
, 0);
1192 /******************************************************************************
1193 * Set the mac type member in the hw struct.
1195 * hw - Struct containing variables accessed by shared code
1196 *****************************************************************************/
1198 e1000_set_mac_type(struct e1000_hw
*hw
)
1202 switch (hw
->device_id
) {
1203 case E1000_DEV_ID_82542
:
1204 switch (hw
->revision_id
) {
1205 case E1000_82542_2_0_REV_ID
:
1206 hw
->mac_type
= e1000_82542_rev2_0
;
1208 case E1000_82542_2_1_REV_ID
:
1209 hw
->mac_type
= e1000_82542_rev2_1
;
1212 /* Invalid 82542 revision ID */
1213 return -E1000_ERR_MAC_TYPE
;
1216 case E1000_DEV_ID_82543GC_FIBER
:
1217 case E1000_DEV_ID_82543GC_COPPER
:
1218 hw
->mac_type
= e1000_82543
;
1220 case E1000_DEV_ID_82544EI_COPPER
:
1221 case E1000_DEV_ID_82544EI_FIBER
:
1222 case E1000_DEV_ID_82544GC_COPPER
:
1223 case E1000_DEV_ID_82544GC_LOM
:
1224 hw
->mac_type
= e1000_82544
;
1226 case E1000_DEV_ID_82540EM
:
1227 case E1000_DEV_ID_82540EM_LOM
:
1228 case E1000_DEV_ID_82540EP
:
1229 case E1000_DEV_ID_82540EP_LOM
:
1230 case E1000_DEV_ID_82540EP_LP
:
1231 hw
->mac_type
= e1000_82540
;
1233 case E1000_DEV_ID_82545EM_COPPER
:
1234 case E1000_DEV_ID_82545EM_FIBER
:
1235 hw
->mac_type
= e1000_82545
;
1237 case E1000_DEV_ID_82545GM_COPPER
:
1238 case E1000_DEV_ID_82545GM_FIBER
:
1239 case E1000_DEV_ID_82545GM_SERDES
:
1240 hw
->mac_type
= e1000_82545_rev_3
;
1242 case E1000_DEV_ID_82546EB_COPPER
:
1243 case E1000_DEV_ID_82546EB_FIBER
:
1244 case E1000_DEV_ID_82546EB_QUAD_COPPER
:
1245 hw
->mac_type
= e1000_82546
;
1247 case E1000_DEV_ID_82546GB_COPPER
:
1248 case E1000_DEV_ID_82546GB_FIBER
:
1249 case E1000_DEV_ID_82546GB_SERDES
:
1250 case E1000_DEV_ID_82546GB_PCIE
:
1251 case E1000_DEV_ID_82546GB_QUAD_COPPER
:
1252 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
:
1253 hw
->mac_type
= e1000_82546_rev_3
;
1255 case E1000_DEV_ID_82541EI
:
1256 case E1000_DEV_ID_82541EI_MOBILE
:
1257 case E1000_DEV_ID_82541ER_LOM
:
1258 hw
->mac_type
= e1000_82541
;
1260 case E1000_DEV_ID_82541ER
:
1261 case E1000_DEV_ID_82541GI
:
1262 case E1000_DEV_ID_82541GI_LF
:
1263 case E1000_DEV_ID_82541GI_MOBILE
:
1264 hw
->mac_type
= e1000_82541_rev_2
;
1266 case E1000_DEV_ID_82547EI
:
1267 case E1000_DEV_ID_82547EI_MOBILE
:
1268 hw
->mac_type
= e1000_82547
;
1270 case E1000_DEV_ID_82547GI
:
1271 hw
->mac_type
= e1000_82547_rev_2
;
1273 case E1000_DEV_ID_82571EB_COPPER
:
1274 case E1000_DEV_ID_82571EB_FIBER
:
1275 case E1000_DEV_ID_82571EB_SERDES
:
1276 case E1000_DEV_ID_82571EB_SERDES_DUAL
:
1277 case E1000_DEV_ID_82571EB_SERDES_QUAD
:
1278 case E1000_DEV_ID_82571EB_QUAD_COPPER
:
1279 case E1000_DEV_ID_82571PT_QUAD_COPPER
:
1280 case E1000_DEV_ID_82571EB_QUAD_FIBER
:
1281 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE
:
1282 hw
->mac_type
= e1000_82571
;
1284 case E1000_DEV_ID_82572EI_COPPER
:
1285 case E1000_DEV_ID_82572EI_FIBER
:
1286 case E1000_DEV_ID_82572EI_SERDES
:
1287 case E1000_DEV_ID_82572EI
:
1288 hw
->mac_type
= e1000_82572
;
1290 case E1000_DEV_ID_82573E
:
1291 case E1000_DEV_ID_82573E_IAMT
:
1292 case E1000_DEV_ID_82573L
:
1293 hw
->mac_type
= e1000_82573
;
1295 case E1000_DEV_ID_82574L
:
1296 hw
->mac_type
= e1000_82574
;
1298 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT
:
1299 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT
:
1300 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT
:
1301 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT
:
1302 hw
->mac_type
= e1000_80003es2lan
;
1304 case E1000_DEV_ID_ICH8_IGP_M_AMT
:
1305 case E1000_DEV_ID_ICH8_IGP_AMT
:
1306 case E1000_DEV_ID_ICH8_IGP_C
:
1307 case E1000_DEV_ID_ICH8_IFE
:
1308 case E1000_DEV_ID_ICH8_IFE_GT
:
1309 case E1000_DEV_ID_ICH8_IFE_G
:
1310 case E1000_DEV_ID_ICH8_IGP_M
:
1311 hw
->mac_type
= e1000_ich8lan
;
1314 /* Should never have loaded on this device */
1315 return -E1000_ERR_MAC_TYPE
;
1317 return E1000_SUCCESS
;
1320 /******************************************************************************
1321 * Reset the transmit and receive units; mask and clear all interrupts.
1323 * hw - Struct containing variables accessed by shared code
1324 *****************************************************************************/
1326 e1000_reset_hw(struct e1000_hw
*hw
)
1335 /* get the correct pba value for both PCI and PCIe*/
1336 if (hw
->mac_type
< e1000_82571
)
1337 pba
= E1000_DEFAULT_PCI_PBA
;
1339 pba
= E1000_DEFAULT_PCIE_PBA
;
1341 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
1342 if (hw
->mac_type
== e1000_82542_rev2_0
) {
1343 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1344 pci_write_config_word(hw
->pdev
, PCI_COMMAND
,
1345 hw
->pci_cmd_word
& ~PCI_COMMAND_INVALIDATE
);
1348 /* Clear interrupt mask to stop board from generating interrupts */
1349 DEBUGOUT("Masking off all interrupts\n");
1350 E1000_WRITE_REG(hw
, IMC
, 0xffffffff);
1352 /* Disable the Transmit and Receive units. Then delay to allow
1353 * any pending transactions to complete before we hit the MAC with
1356 E1000_WRITE_REG(hw
, RCTL
, 0);
1357 E1000_WRITE_REG(hw
, TCTL
, E1000_TCTL_PSP
);
1358 E1000_WRITE_FLUSH(hw
);
1360 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
1361 hw
->tbi_compatibility_on
= false;
1363 /* Delay to allow any outstanding PCI transactions to complete before
1364 * resetting the device
1368 /* Issue a global reset to the MAC. This will reset the chip's
1369 * transmit, receive, DMA, and link units. It will not effect
1370 * the current PCI configuration. The global reset bit is self-
1371 * clearing, and should clear within a microsecond.
1373 DEBUGOUT("Issuing a global reset to MAC\n");
1374 ctrl
= E1000_READ_REG(hw
, CTRL
);
1376 E1000_WRITE_REG(hw
, CTRL
, (ctrl
| E1000_CTRL_RST
));
1378 /* Force a reload from the EEPROM if necessary */
1379 if (hw
->mac_type
< e1000_82540
) {
1380 /* Wait for reset to complete */
1382 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1383 ctrl_ext
|= E1000_CTRL_EXT_EE_RST
;
1384 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1385 E1000_WRITE_FLUSH(hw
);
1386 /* Wait for EEPROM reload */
1389 /* Wait for EEPROM reload (it happens automatically) */
1391 /* Dissable HW ARPs on ASF enabled adapters */
1392 manc
= E1000_READ_REG(hw
, MANC
);
1393 manc
&= ~(E1000_MANC_ARP_EN
);
1394 E1000_WRITE_REG(hw
, MANC
, manc
);
1397 /* Clear interrupt mask to stop board from generating interrupts */
1398 DEBUGOUT("Masking off all interrupts\n");
1399 E1000_WRITE_REG(hw
, IMC
, 0xffffffff);
1401 /* Clear any pending interrupt events. */
1402 E1000_READ_REG(hw
, ICR
);
1404 /* If MWI was previously enabled, reenable it. */
1405 if (hw
->mac_type
== e1000_82542_rev2_0
) {
1406 pci_write_config_word(hw
->pdev
, PCI_COMMAND
, hw
->pci_cmd_word
);
1408 E1000_WRITE_REG(hw
, PBA
, pba
);
1411 /******************************************************************************
1413 * Initialize a number of hardware-dependent bits
1415 * hw: Struct containing variables accessed by shared code
1417 * This function contains hardware limitation workarounds for PCI-E adapters
1419 *****************************************************************************/
1421 e1000_initialize_hardware_bits(struct e1000_hw
*hw
)
1423 if ((hw
->mac_type
>= e1000_82571
) &&
1424 (!hw
->initialize_hw_bits_disable
)) {
1425 /* Settings common to all PCI-express silicon */
1426 uint32_t reg_ctrl
, reg_ctrl_ext
;
1427 uint32_t reg_tarc0
, reg_tarc1
;
1429 uint32_t reg_txdctl
, reg_txdctl1
;
1431 /* link autonegotiation/sync workarounds */
1432 reg_tarc0
= E1000_READ_REG(hw
, TARC0
);
1433 reg_tarc0
&= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1435 /* Enable not-done TX descriptor counting */
1436 reg_txdctl
= E1000_READ_REG(hw
, TXDCTL
);
1437 reg_txdctl
|= E1000_TXDCTL_COUNT_DESC
;
1438 E1000_WRITE_REG(hw
, TXDCTL
, reg_txdctl
);
1440 reg_txdctl1
= E1000_READ_REG(hw
, TXDCTL1
);
1441 reg_txdctl1
|= E1000_TXDCTL_COUNT_DESC
;
1442 E1000_WRITE_REG(hw
, TXDCTL1
, reg_txdctl1
);
1444 switch (hw
->mac_type
) {
1447 /* Clear PHY TX compatible mode bits */
1448 reg_tarc1
= E1000_READ_REG(hw
, TARC1
);
1449 reg_tarc1
&= ~((1 << 30)|(1 << 29));
1451 /* link autonegotiation/sync workarounds */
1452 reg_tarc0
|= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1454 /* TX ring control fixes */
1455 reg_tarc1
|= ((1 << 26)|(1 << 25)|(1 << 24));
1457 /* Multiple read bit is reversed polarity */
1458 reg_tctl
= E1000_READ_REG(hw
, TCTL
);
1459 if (reg_tctl
& E1000_TCTL_MULR
)
1460 reg_tarc1
&= ~(1 << 28);
1462 reg_tarc1
|= (1 << 28);
1464 E1000_WRITE_REG(hw
, TARC1
, reg_tarc1
);
1468 reg_ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1469 reg_ctrl_ext
&= ~(1 << 23);
1470 reg_ctrl_ext
|= (1 << 22);
1472 /* TX byte count fix */
1473 reg_ctrl
= E1000_READ_REG(hw
, CTRL
);
1474 reg_ctrl
&= ~(1 << 29);
1476 E1000_WRITE_REG(hw
, CTRL_EXT
, reg_ctrl_ext
);
1477 E1000_WRITE_REG(hw
, CTRL
, reg_ctrl
);
1479 case e1000_80003es2lan
:
1480 /* improve small packet performace for fiber/serdes */
1481 if ((hw
->media_type
== e1000_media_type_fiber
)
1482 || (hw
->media_type
==
1483 e1000_media_type_internal_serdes
)) {
1484 reg_tarc0
&= ~(1 << 20);
1487 /* Multiple read bit is reversed polarity */
1488 reg_tctl
= E1000_READ_REG(hw
, TCTL
);
1489 reg_tarc1
= E1000_READ_REG(hw
, TARC1
);
1490 if (reg_tctl
& E1000_TCTL_MULR
)
1491 reg_tarc1
&= ~(1 << 28);
1493 reg_tarc1
|= (1 << 28);
1495 E1000_WRITE_REG(hw
, TARC1
, reg_tarc1
);
1498 /* Reduce concurrent DMA requests to 3 from 4 */
1499 if ((hw
->revision_id
< 3) ||
1500 ((hw
->device_id
!= E1000_DEV_ID_ICH8_IGP_M_AMT
) &&
1501 (hw
->device_id
!= E1000_DEV_ID_ICH8_IGP_M
)))
1502 reg_tarc0
|= ((1 << 29)|(1 << 28));
1504 reg_ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1505 reg_ctrl_ext
|= (1 << 22);
1506 E1000_WRITE_REG(hw
, CTRL_EXT
, reg_ctrl_ext
);
1508 /* workaround TX hang with TSO=on */
1509 reg_tarc0
|= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1511 /* Multiple read bit is reversed polarity */
1512 reg_tctl
= E1000_READ_REG(hw
, TCTL
);
1513 reg_tarc1
= E1000_READ_REG(hw
, TARC1
);
1514 if (reg_tctl
& E1000_TCTL_MULR
)
1515 reg_tarc1
&= ~(1 << 28);
1517 reg_tarc1
|= (1 << 28);
1519 /* workaround TX hang with TSO=on */
1520 reg_tarc1
|= ((1 << 30)|(1 << 26)|(1 << 24));
1522 E1000_WRITE_REG(hw
, TARC1
, reg_tarc1
);
1528 E1000_WRITE_REG(hw
, TARC0
, reg_tarc0
);
1532 /******************************************************************************
1533 * Performs basic configuration of the adapter.
1535 * hw - Struct containing variables accessed by shared code
1537 * Assumes that the controller has previously been reset and is in a
1538 * post-reset uninitialized state. Initializes the receive address registers,
1539 * multicast table, and VLAN filter table. Calls routines to setup link
1540 * configuration and flow control settings. Clears all on-chip counters. Leaves
1541 * the transmit and receive units disabled and uninitialized.
1542 *****************************************************************************/
1544 e1000_init_hw(struct eth_device
*nic
)
1546 struct e1000_hw
*hw
= nic
->priv
;
1550 uint16_t pcix_cmd_word
;
1551 uint16_t pcix_stat_hi_word
;
1553 uint16_t stat_mmrbc
;
1558 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
1559 if ((hw
->mac_type
== e1000_ich8lan
) &&
1560 ((hw
->revision_id
< 3) ||
1561 ((hw
->device_id
!= E1000_DEV_ID_ICH8_IGP_M_AMT
) &&
1562 (hw
->device_id
!= E1000_DEV_ID_ICH8_IGP_M
)))) {
1563 reg_data
= E1000_READ_REG(hw
, STATUS
);
1564 reg_data
&= ~0x80000000;
1565 E1000_WRITE_REG(hw
, STATUS
, reg_data
);
1567 /* Do not need initialize Identification LED */
1569 /* Set the media type and TBI compatibility */
1570 e1000_set_media_type(hw
);
1572 /* Must be called after e1000_set_media_type
1573 * because media_type is used */
1574 e1000_initialize_hardware_bits(hw
);
1576 /* Disabling VLAN filtering. */
1577 DEBUGOUT("Initializing the IEEE VLAN\n");
1578 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
1579 if (hw
->mac_type
!= e1000_ich8lan
) {
1580 if (hw
->mac_type
< e1000_82545_rev_3
)
1581 E1000_WRITE_REG(hw
, VET
, 0);
1582 e1000_clear_vfta(hw
);
1585 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
1586 if (hw
->mac_type
== e1000_82542_rev2_0
) {
1587 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1588 pci_write_config_word(hw
->pdev
, PCI_COMMAND
,
1590 pci_cmd_word
& ~PCI_COMMAND_INVALIDATE
);
1591 E1000_WRITE_REG(hw
, RCTL
, E1000_RCTL_RST
);
1592 E1000_WRITE_FLUSH(hw
);
1596 /* Setup the receive address. This involves initializing all of the Receive
1597 * Address Registers (RARs 0 - 15).
1599 e1000_init_rx_addrs(nic
);
1601 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
1602 if (hw
->mac_type
== e1000_82542_rev2_0
) {
1603 E1000_WRITE_REG(hw
, RCTL
, 0);
1604 E1000_WRITE_FLUSH(hw
);
1606 pci_write_config_word(hw
->pdev
, PCI_COMMAND
, hw
->pci_cmd_word
);
1609 /* Zero out the Multicast HASH table */
1610 DEBUGOUT("Zeroing the MTA\n");
1611 mta_size
= E1000_MC_TBL_SIZE
;
1612 if (hw
->mac_type
== e1000_ich8lan
)
1613 mta_size
= E1000_MC_TBL_SIZE_ICH8LAN
;
1614 for (i
= 0; i
< mta_size
; i
++) {
1615 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
1616 /* use write flush to prevent Memory Write Block (MWB) from
1617 * occuring when accessing our register space */
1618 E1000_WRITE_FLUSH(hw
);
1621 /* Set the PCI priority bit correctly in the CTRL register. This
1622 * determines if the adapter gives priority to receives, or if it
1623 * gives equal priority to transmits and receives. Valid only on
1624 * 82542 and 82543 silicon.
1626 if (hw
->dma_fairness
&& hw
->mac_type
<= e1000_82543
) {
1627 ctrl
= E1000_READ_REG(hw
, CTRL
);
1628 E1000_WRITE_REG(hw
, CTRL
, ctrl
| E1000_CTRL_PRIOR
);
1631 switch (hw
->mac_type
) {
1632 case e1000_82545_rev_3
:
1633 case e1000_82546_rev_3
:
1636 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
1637 if (hw
->bus_type
== e1000_bus_type_pcix
) {
1638 pci_read_config_word(hw
->pdev
, PCIX_COMMAND_REGISTER
,
1640 pci_read_config_word(hw
->pdev
, PCIX_STATUS_REGISTER_HI
,
1641 &pcix_stat_hi_word
);
1643 (pcix_cmd_word
& PCIX_COMMAND_MMRBC_MASK
) >>
1644 PCIX_COMMAND_MMRBC_SHIFT
;
1646 (pcix_stat_hi_word
& PCIX_STATUS_HI_MMRBC_MASK
) >>
1647 PCIX_STATUS_HI_MMRBC_SHIFT
;
1648 if (stat_mmrbc
== PCIX_STATUS_HI_MMRBC_4K
)
1649 stat_mmrbc
= PCIX_STATUS_HI_MMRBC_2K
;
1650 if (cmd_mmrbc
> stat_mmrbc
) {
1651 pcix_cmd_word
&= ~PCIX_COMMAND_MMRBC_MASK
;
1652 pcix_cmd_word
|= stat_mmrbc
<< PCIX_COMMAND_MMRBC_SHIFT
;
1653 pci_write_config_word(hw
->pdev
, PCIX_COMMAND_REGISTER
,
1660 /* More time needed for PHY to initialize */
1661 if (hw
->mac_type
== e1000_ich8lan
)
1664 /* Call a subroutine to configure the link and setup flow control. */
1665 ret_val
= e1000_setup_link(nic
);
1667 /* Set the transmit descriptor write-back policy */
1668 if (hw
->mac_type
> e1000_82544
) {
1669 ctrl
= E1000_READ_REG(hw
, TXDCTL
);
1671 (ctrl
& ~E1000_TXDCTL_WTHRESH
) |
1672 E1000_TXDCTL_FULL_TX_DESC_WB
;
1673 E1000_WRITE_REG(hw
, TXDCTL
, ctrl
);
1676 /* Set the receive descriptor write back policy */
1678 if (hw
->mac_type
>= e1000_82571
) {
1679 ctrl
= E1000_READ_REG(hw
, RXDCTL
);
1681 (ctrl
& ~E1000_RXDCTL_WTHRESH
) |
1682 E1000_RXDCTL_FULL_RX_DESC_WB
;
1683 E1000_WRITE_REG(hw
, RXDCTL
, ctrl
);
1686 switch (hw
->mac_type
) {
1689 case e1000_80003es2lan
:
1690 /* Enable retransmit on late collisions */
1691 reg_data
= E1000_READ_REG(hw
, TCTL
);
1692 reg_data
|= E1000_TCTL_RTLC
;
1693 E1000_WRITE_REG(hw
, TCTL
, reg_data
);
1695 /* Configure Gigabit Carry Extend Padding */
1696 reg_data
= E1000_READ_REG(hw
, TCTL_EXT
);
1697 reg_data
&= ~E1000_TCTL_EXT_GCEX_MASK
;
1698 reg_data
|= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX
;
1699 E1000_WRITE_REG(hw
, TCTL_EXT
, reg_data
);
1701 /* Configure Transmit Inter-Packet Gap */
1702 reg_data
= E1000_READ_REG(hw
, TIPG
);
1703 reg_data
&= ~E1000_TIPG_IPGT_MASK
;
1704 reg_data
|= DEFAULT_80003ES2LAN_TIPG_IPGT_1000
;
1705 E1000_WRITE_REG(hw
, TIPG
, reg_data
);
1707 reg_data
= E1000_READ_REG_ARRAY(hw
, FFLT
, 0x0001);
1708 reg_data
&= ~0x00100000;
1709 E1000_WRITE_REG_ARRAY(hw
, FFLT
, 0x0001, reg_data
);
1714 ctrl
= E1000_READ_REG(hw
, TXDCTL1
);
1715 ctrl
= (ctrl
& ~E1000_TXDCTL_WTHRESH
)
1716 | E1000_TXDCTL_FULL_TX_DESC_WB
;
1717 E1000_WRITE_REG(hw
, TXDCTL1
, ctrl
);
1721 reg_data
= E1000_READ_REG(hw
, GCR
);
1722 reg_data
|= E1000_GCR_L1_ACT_WITHOUT_L0S_RX
;
1723 E1000_WRITE_REG(hw
, GCR
, reg_data
);
1727 /* Clear all of the statistics registers (clear on read). It is
1728 * important that we do this after we have tried to establish link
1729 * because the symbol error count will increment wildly if there
1732 e1000_clear_hw_cntrs(hw
);
1734 /* ICH8 No-snoop bits are opposite polarity.
1735 * Set to snoop by default after reset. */
1736 if (hw
->mac_type
== e1000_ich8lan
)
1737 e1000_set_pci_ex_no_snoop(hw
, PCI_EX_82566_SNOOP_ALL
);
1740 if (hw
->device_id
== E1000_DEV_ID_82546GB_QUAD_COPPER
||
1741 hw
->device_id
== E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
) {
1742 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
1743 /* Relaxed ordering must be disabled to avoid a parity
1744 * error crash in a PCI slot. */
1745 ctrl_ext
|= E1000_CTRL_EXT_RO_DIS
;
1746 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1752 /******************************************************************************
1753 * Configures flow control and link settings.
1755 * hw - Struct containing variables accessed by shared code
1757 * Determines which flow control settings to use. Calls the apropriate media-
1758 * specific link configuration function. Configures the flow control settings.
1759 * Assuming the adapter has a valid link partner, a valid link should be
1760 * established. Assumes the hardware has previously been reset and the
1761 * transmitter and receiver are not enabled.
1762 *****************************************************************************/
1764 e1000_setup_link(struct eth_device
*nic
)
1766 struct e1000_hw
*hw
= nic
->priv
;
1769 uint16_t eeprom_data
;
1773 /* In the case of the phy reset being blocked, we already have a link.
1774 * We do not have to set it up again. */
1775 if (e1000_check_phy_reset_block(hw
))
1776 return E1000_SUCCESS
;
1778 /* Read and store word 0x0F of the EEPROM. This word contains bits
1779 * that determine the hardware's default PAUSE (flow control) mode,
1780 * a bit that determines whether the HW defaults to enabling or
1781 * disabling auto-negotiation, and the direction of the
1782 * SW defined pins. If there is no SW over-ride of the flow
1783 * control setting, then the variable hw->fc will
1784 * be initialized based on a value in the EEPROM.
1786 if (e1000_read_eeprom(hw
, EEPROM_INIT_CONTROL2_REG
, 1,
1787 &eeprom_data
) < 0) {
1788 DEBUGOUT("EEPROM Read Error\n");
1789 return -E1000_ERR_EEPROM
;
1792 if (hw
->fc
== e1000_fc_default
) {
1793 switch (hw
->mac_type
) {
1797 hw
->fc
= e1000_fc_full
;
1800 ret_val
= e1000_read_eeprom(hw
,
1801 EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
);
1803 DEBUGOUT("EEPROM Read Error\n");
1804 return -E1000_ERR_EEPROM
;
1806 if ((eeprom_data
& EEPROM_WORD0F_PAUSE_MASK
) == 0)
1807 hw
->fc
= e1000_fc_none
;
1808 else if ((eeprom_data
& EEPROM_WORD0F_PAUSE_MASK
) ==
1809 EEPROM_WORD0F_ASM_DIR
)
1810 hw
->fc
= e1000_fc_tx_pause
;
1812 hw
->fc
= e1000_fc_full
;
1817 /* We want to save off the original Flow Control configuration just
1818 * in case we get disconnected and then reconnected into a different
1819 * hub or switch with different Flow Control capabilities.
1821 if (hw
->mac_type
== e1000_82542_rev2_0
)
1822 hw
->fc
&= (~e1000_fc_tx_pause
);
1824 if ((hw
->mac_type
< e1000_82543
) && (hw
->report_tx_early
== 1))
1825 hw
->fc
&= (~e1000_fc_rx_pause
);
1827 hw
->original_fc
= hw
->fc
;
1829 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw
->fc
);
1831 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1832 * polarity value for the SW controlled pins, and setup the
1833 * Extended Device Control reg with that info.
1834 * This is needed because one of the SW controlled pins is used for
1835 * signal detection. So this should be done before e1000_setup_pcs_link()
1836 * or e1000_phy_setup() is called.
1838 if (hw
->mac_type
== e1000_82543
) {
1839 ctrl_ext
= ((eeprom_data
& EEPROM_WORD0F_SWPDIO_EXT
) <<
1841 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
1844 /* Call the necessary subroutine to configure the link. */
1845 ret_val
= (hw
->media_type
== e1000_media_type_fiber
) ?
1846 e1000_setup_fiber_link(nic
) : e1000_setup_copper_link(nic
);
1851 /* Initialize the flow control address, type, and PAUSE timer
1852 * registers to their default values. This is done even if flow
1853 * control is disabled, because it does not hurt anything to
1854 * initialize these registers.
1856 DEBUGOUT("Initializing the Flow Control address, type"
1857 "and timer regs\n");
1859 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1860 if (hw
->mac_type
!= e1000_ich8lan
) {
1861 E1000_WRITE_REG(hw
, FCT
, FLOW_CONTROL_TYPE
);
1862 E1000_WRITE_REG(hw
, FCAH
, FLOW_CONTROL_ADDRESS_HIGH
);
1863 E1000_WRITE_REG(hw
, FCAL
, FLOW_CONTROL_ADDRESS_LOW
);
1866 E1000_WRITE_REG(hw
, FCTTV
, hw
->fc_pause_time
);
1868 /* Set the flow control receive threshold registers. Normally,
1869 * these registers will be set to a default threshold that may be
1870 * adjusted later by the driver's runtime code. However, if the
1871 * ability to transmit pause frames in not enabled, then these
1872 * registers will be set to 0.
1874 if (!(hw
->fc
& e1000_fc_tx_pause
)) {
1875 E1000_WRITE_REG(hw
, FCRTL
, 0);
1876 E1000_WRITE_REG(hw
, FCRTH
, 0);
1878 /* We need to set up the Receive Threshold high and low water marks
1879 * as well as (optionally) enabling the transmission of XON frames.
1881 if (hw
->fc_send_xon
) {
1882 E1000_WRITE_REG(hw
, FCRTL
,
1883 (hw
->fc_low_water
| E1000_FCRTL_XONE
));
1884 E1000_WRITE_REG(hw
, FCRTH
, hw
->fc_high_water
);
1886 E1000_WRITE_REG(hw
, FCRTL
, hw
->fc_low_water
);
1887 E1000_WRITE_REG(hw
, FCRTH
, hw
->fc_high_water
);
1893 /******************************************************************************
1894 * Sets up link for a fiber based adapter
1896 * hw - Struct containing variables accessed by shared code
1898 * Manipulates Physical Coding Sublayer functions in order to configure
1899 * link. Assumes the hardware has been previously reset and the transmitter
1900 * and receiver are not enabled.
1901 *****************************************************************************/
1903 e1000_setup_fiber_link(struct eth_device
*nic
)
1905 struct e1000_hw
*hw
= nic
->priv
;
1914 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
1915 * set when the optics detect a signal. On older adapters, it will be
1916 * cleared when there is a signal
1918 ctrl
= E1000_READ_REG(hw
, CTRL
);
1919 if ((hw
->mac_type
> e1000_82544
) && !(ctrl
& E1000_CTRL_ILOS
))
1920 signal
= E1000_CTRL_SWDPIN1
;
1924 printf("signal for %s is %x (ctrl %08x)!!!!\n", nic
->name
, signal
,
1926 /* Take the link out of reset */
1927 ctrl
&= ~(E1000_CTRL_LRST
);
1929 e1000_config_collision_dist(hw
);
1931 /* Check for a software override of the flow control settings, and setup
1932 * the device accordingly. If auto-negotiation is enabled, then software
1933 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1934 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1935 * auto-negotiation is disabled, then software will have to manually
1936 * configure the two flow control enable bits in the CTRL register.
1938 * The possible values of the "fc" parameter are:
1939 * 0: Flow control is completely disabled
1940 * 1: Rx flow control is enabled (we can receive pause frames, but
1941 * not send pause frames).
1942 * 2: Tx flow control is enabled (we can send pause frames but we do
1943 * not support receiving pause frames).
1944 * 3: Both Rx and TX flow control (symmetric) are enabled.
1948 /* Flow control is completely disabled by a software over-ride. */
1949 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
);
1951 case e1000_fc_rx_pause
:
1952 /* RX Flow control is enabled and TX Flow control is disabled by a
1953 * software over-ride. Since there really isn't a way to advertise
1954 * that we are capable of RX Pause ONLY, we will advertise that we
1955 * support both symmetric and asymmetric RX PAUSE. Later, we will
1956 * disable the adapter's ability to send PAUSE frames.
1958 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_PAUSE_MASK
);
1960 case e1000_fc_tx_pause
:
1961 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1962 * software over-ride.
1964 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_ASM_DIR
);
1967 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1968 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_PAUSE_MASK
);
1971 DEBUGOUT("Flow control param set incorrectly\n");
1972 return -E1000_ERR_CONFIG
;
1976 /* Since auto-negotiation is enabled, take the link out of reset (the link
1977 * will be in reset, because we previously reset the chip). This will
1978 * restart auto-negotiation. If auto-neogtiation is successful then the
1979 * link-up status bit will be set and the flow control enable bits (RFCE
1980 * and TFCE) will be set according to their negotiated value.
1982 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw
);
1984 E1000_WRITE_REG(hw
, TXCW
, txcw
);
1985 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1986 E1000_WRITE_FLUSH(hw
);
1991 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1992 * indication in the Device Status Register. Time-out if a link isn't
1993 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1994 * less than 500 milliseconds even if the other end is doing it in SW).
1996 if ((E1000_READ_REG(hw
, CTRL
) & E1000_CTRL_SWDPIN1
) == signal
) {
1997 DEBUGOUT("Looking for Link\n");
1998 for (i
= 0; i
< (LINK_UP_TIMEOUT
/ 10); i
++) {
2000 status
= E1000_READ_REG(hw
, STATUS
);
2001 if (status
& E1000_STATUS_LU
)
2004 if (i
== (LINK_UP_TIMEOUT
/ 10)) {
2005 /* AutoNeg failed to achieve a link, so we'll call
2006 * e1000_check_for_link. This routine will force the link up if we
2007 * detect a signal. This will allow us to communicate with
2008 * non-autonegotiating link partners.
2010 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2011 hw
->autoneg_failed
= 1;
2012 ret_val
= e1000_check_for_link(nic
);
2014 DEBUGOUT("Error while checking for link\n");
2017 hw
->autoneg_failed
= 0;
2019 hw
->autoneg_failed
= 0;
2020 DEBUGOUT("Valid Link Found\n");
2023 DEBUGOUT("No Signal Detected\n");
2024 return -E1000_ERR_NOLINK
;
2029 /******************************************************************************
2030 * Make sure we have a valid PHY and change PHY mode before link setup.
2032 * hw - Struct containing variables accessed by shared code
2033 ******************************************************************************/
2035 e1000_copper_link_preconfig(struct e1000_hw
*hw
)
2043 ctrl
= E1000_READ_REG(hw
, CTRL
);
2044 /* With 82543, we need to force speed and duplex on the MAC equal to what
2045 * the PHY speed and duplex configuration is. In addition, we need to
2046 * perform a hardware reset on the PHY to take it out of reset.
2048 if (hw
->mac_type
> e1000_82543
) {
2049 ctrl
|= E1000_CTRL_SLU
;
2050 ctrl
&= ~(E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
2051 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2053 ctrl
|= (E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
2055 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2056 ret_val
= e1000_phy_hw_reset(hw
);
2061 /* Make sure we have a valid PHY */
2062 ret_val
= e1000_detect_gig_phy(hw
);
2064 DEBUGOUT("Error, did not detect valid phy.\n");
2067 DEBUGOUT("Phy ID = %x \n", hw
->phy_id
);
2069 /* Set PHY to class A mode (if necessary) */
2070 ret_val
= e1000_set_phy_mode(hw
);
2073 if ((hw
->mac_type
== e1000_82545_rev_3
) ||
2074 (hw
->mac_type
== e1000_82546_rev_3
)) {
2075 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
,
2077 phy_data
|= 0x00000008;
2078 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
,
2082 if (hw
->mac_type
<= e1000_82543
||
2083 hw
->mac_type
== e1000_82541
|| hw
->mac_type
== e1000_82547
||
2084 hw
->mac_type
== e1000_82541_rev_2
2085 || hw
->mac_type
== e1000_82547_rev_2
)
2086 hw
->phy_reset_disable
= false;
2088 return E1000_SUCCESS
;
2091 /*****************************************************************************
2093 * This function sets the lplu state according to the active flag. When
2094 * activating lplu this function also disables smart speed and vise versa.
2095 * lplu will not be activated unless the device autonegotiation advertisment
2096 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2097 * hw: Struct containing variables accessed by shared code
2098 * active - true to enable lplu false to disable lplu.
2100 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2101 * E1000_SUCCESS at any other case.
2103 ****************************************************************************/
2106 e1000_set_d3_lplu_state(struct e1000_hw
*hw
, bool active
)
2108 uint32_t phy_ctrl
= 0;
2113 if (hw
->phy_type
!= e1000_phy_igp
&& hw
->phy_type
!= e1000_phy_igp_2
2114 && hw
->phy_type
!= e1000_phy_igp_3
)
2115 return E1000_SUCCESS
;
2117 /* During driver activity LPLU should not be used or it will attain link
2118 * from the lowest speeds starting from 10Mbps. The capability is used
2119 * for Dx transitions and states */
2120 if (hw
->mac_type
== e1000_82541_rev_2
2121 || hw
->mac_type
== e1000_82547_rev_2
) {
2122 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_GMII_FIFO
,
2126 } else if (hw
->mac_type
== e1000_ich8lan
) {
2127 /* MAC writes into PHY register based on the state transition
2128 * and start auto-negotiation. SW driver can overwrite the
2129 * settings in CSR PHY power control E1000_PHY_CTRL register. */
2130 phy_ctrl
= E1000_READ_REG(hw
, PHY_CTRL
);
2132 ret_val
= e1000_read_phy_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
2139 if (hw
->mac_type
== e1000_82541_rev_2
||
2140 hw
->mac_type
== e1000_82547_rev_2
) {
2141 phy_data
&= ~IGP01E1000_GMII_FLEX_SPD
;
2142 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_GMII_FIFO
,
2147 if (hw
->mac_type
== e1000_ich8lan
) {
2148 phy_ctrl
&= ~E1000_PHY_CTRL_NOND0A_LPLU
;
2149 E1000_WRITE_REG(hw
, PHY_CTRL
, phy_ctrl
);
2151 phy_data
&= ~IGP02E1000_PM_D3_LPLU
;
2152 ret_val
= e1000_write_phy_reg(hw
,
2153 IGP02E1000_PHY_POWER_MGMT
, phy_data
);
2159 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2160 * Dx states where the power conservation is most important. During
2161 * driver activity we should enable SmartSpeed, so performance is
2163 if (hw
->smart_speed
== e1000_smart_speed_on
) {
2164 ret_val
= e1000_read_phy_reg(hw
,
2165 IGP01E1000_PHY_PORT_CONFIG
, &phy_data
);
2169 phy_data
|= IGP01E1000_PSCFR_SMART_SPEED
;
2170 ret_val
= e1000_write_phy_reg(hw
,
2171 IGP01E1000_PHY_PORT_CONFIG
, phy_data
);
2174 } else if (hw
->smart_speed
== e1000_smart_speed_off
) {
2175 ret_val
= e1000_read_phy_reg(hw
,
2176 IGP01E1000_PHY_PORT_CONFIG
, &phy_data
);
2180 phy_data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
2181 ret_val
= e1000_write_phy_reg(hw
,
2182 IGP01E1000_PHY_PORT_CONFIG
, phy_data
);
2187 } else if ((hw
->autoneg_advertised
== AUTONEG_ADVERTISE_SPEED_DEFAULT
)
2188 || (hw
->autoneg_advertised
== AUTONEG_ADVERTISE_10_ALL
) ||
2189 (hw
->autoneg_advertised
== AUTONEG_ADVERTISE_10_100_ALL
)) {
2191 if (hw
->mac_type
== e1000_82541_rev_2
||
2192 hw
->mac_type
== e1000_82547_rev_2
) {
2193 phy_data
|= IGP01E1000_GMII_FLEX_SPD
;
2194 ret_val
= e1000_write_phy_reg(hw
,
2195 IGP01E1000_GMII_FIFO
, phy_data
);
2199 if (hw
->mac_type
== e1000_ich8lan
) {
2200 phy_ctrl
|= E1000_PHY_CTRL_NOND0A_LPLU
;
2201 E1000_WRITE_REG(hw
, PHY_CTRL
, phy_ctrl
);
2203 phy_data
|= IGP02E1000_PM_D3_LPLU
;
2204 ret_val
= e1000_write_phy_reg(hw
,
2205 IGP02E1000_PHY_POWER_MGMT
, phy_data
);
2211 /* When LPLU is enabled we should disable SmartSpeed */
2212 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
2217 phy_data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
2218 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
2223 return E1000_SUCCESS
;
2226 /*****************************************************************************
2228 * This function sets the lplu d0 state according to the active flag. When
2229 * activating lplu this function also disables smart speed and vise versa.
2230 * lplu will not be activated unless the device autonegotiation advertisment
2231 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2232 * hw: Struct containing variables accessed by shared code
2233 * active - true to enable lplu false to disable lplu.
2235 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2236 * E1000_SUCCESS at any other case.
2238 ****************************************************************************/
2241 e1000_set_d0_lplu_state(struct e1000_hw
*hw
, bool active
)
2243 uint32_t phy_ctrl
= 0;
2248 if (hw
->mac_type
<= e1000_82547_rev_2
)
2249 return E1000_SUCCESS
;
2251 if (hw
->mac_type
== e1000_ich8lan
) {
2252 phy_ctrl
= E1000_READ_REG(hw
, PHY_CTRL
);
2254 ret_val
= e1000_read_phy_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
2261 if (hw
->mac_type
== e1000_ich8lan
) {
2262 phy_ctrl
&= ~E1000_PHY_CTRL_D0A_LPLU
;
2263 E1000_WRITE_REG(hw
, PHY_CTRL
, phy_ctrl
);
2265 phy_data
&= ~IGP02E1000_PM_D0_LPLU
;
2266 ret_val
= e1000_write_phy_reg(hw
,
2267 IGP02E1000_PHY_POWER_MGMT
, phy_data
);
2272 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2273 * Dx states where the power conservation is most important. During
2274 * driver activity we should enable SmartSpeed, so performance is
2276 if (hw
->smart_speed
== e1000_smart_speed_on
) {
2277 ret_val
= e1000_read_phy_reg(hw
,
2278 IGP01E1000_PHY_PORT_CONFIG
, &phy_data
);
2282 phy_data
|= IGP01E1000_PSCFR_SMART_SPEED
;
2283 ret_val
= e1000_write_phy_reg(hw
,
2284 IGP01E1000_PHY_PORT_CONFIG
, phy_data
);
2287 } else if (hw
->smart_speed
== e1000_smart_speed_off
) {
2288 ret_val
= e1000_read_phy_reg(hw
,
2289 IGP01E1000_PHY_PORT_CONFIG
, &phy_data
);
2293 phy_data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
2294 ret_val
= e1000_write_phy_reg(hw
,
2295 IGP01E1000_PHY_PORT_CONFIG
, phy_data
);
2303 if (hw
->mac_type
== e1000_ich8lan
) {
2304 phy_ctrl
|= E1000_PHY_CTRL_D0A_LPLU
;
2305 E1000_WRITE_REG(hw
, PHY_CTRL
, phy_ctrl
);
2307 phy_data
|= IGP02E1000_PM_D0_LPLU
;
2308 ret_val
= e1000_write_phy_reg(hw
,
2309 IGP02E1000_PHY_POWER_MGMT
, phy_data
);
2314 /* When LPLU is enabled we should disable SmartSpeed */
2315 ret_val
= e1000_read_phy_reg(hw
,
2316 IGP01E1000_PHY_PORT_CONFIG
, &phy_data
);
2320 phy_data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
2321 ret_val
= e1000_write_phy_reg(hw
,
2322 IGP01E1000_PHY_PORT_CONFIG
, phy_data
);
2327 return E1000_SUCCESS
;
2330 /********************************************************************
2331 * Copper link setup for e1000_phy_igp series.
2333 * hw - Struct containing variables accessed by shared code
2334 *********************************************************************/
2336 e1000_copper_link_igp_setup(struct e1000_hw
*hw
)
2344 if (hw
->phy_reset_disable
)
2345 return E1000_SUCCESS
;
2347 ret_val
= e1000_phy_reset(hw
);
2349 DEBUGOUT("Error Resetting the PHY\n");
2353 /* Wait 15ms for MAC to configure PHY from eeprom settings */
2355 if (hw
->mac_type
!= e1000_ich8lan
) {
2356 /* Configure activity LED after PHY reset */
2357 led_ctrl
= E1000_READ_REG(hw
, LEDCTL
);
2358 led_ctrl
&= IGP_ACTIVITY_LED_MASK
;
2359 led_ctrl
|= (IGP_ACTIVITY_LED_ENABLE
| IGP_LED3_MODE
);
2360 E1000_WRITE_REG(hw
, LEDCTL
, led_ctrl
);
2363 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
2364 if (hw
->phy_type
== e1000_phy_igp
) {
2365 /* disable lplu d3 during driver init */
2366 ret_val
= e1000_set_d3_lplu_state(hw
, false);
2368 DEBUGOUT("Error Disabling LPLU D3\n");
2373 /* disable lplu d0 during driver init */
2374 ret_val
= e1000_set_d0_lplu_state(hw
, false);
2376 DEBUGOUT("Error Disabling LPLU D0\n");
2379 /* Configure mdi-mdix settings */
2380 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_CTRL
, &phy_data
);
2384 if ((hw
->mac_type
== e1000_82541
) || (hw
->mac_type
== e1000_82547
)) {
2385 hw
->dsp_config_state
= e1000_dsp_config_disabled
;
2386 /* Force MDI for earlier revs of the IGP PHY */
2387 phy_data
&= ~(IGP01E1000_PSCR_AUTO_MDIX
2388 | IGP01E1000_PSCR_FORCE_MDI_MDIX
);
2392 hw
->dsp_config_state
= e1000_dsp_config_enabled
;
2393 phy_data
&= ~IGP01E1000_PSCR_AUTO_MDIX
;
2397 phy_data
&= ~IGP01E1000_PSCR_FORCE_MDI_MDIX
;
2400 phy_data
|= IGP01E1000_PSCR_FORCE_MDI_MDIX
;
2404 phy_data
|= IGP01E1000_PSCR_AUTO_MDIX
;
2408 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_PHY_PORT_CTRL
, phy_data
);
2412 /* set auto-master slave resolution settings */
2414 e1000_ms_type phy_ms_setting
= hw
->master_slave
;
2416 if (hw
->ffe_config_state
== e1000_ffe_config_active
)
2417 hw
->ffe_config_state
= e1000_ffe_config_enabled
;
2419 if (hw
->dsp_config_state
== e1000_dsp_config_activated
)
2420 hw
->dsp_config_state
= e1000_dsp_config_enabled
;
2422 /* when autonegotiation advertisment is only 1000Mbps then we
2423 * should disable SmartSpeed and enable Auto MasterSlave
2424 * resolution as hardware default. */
2425 if (hw
->autoneg_advertised
== ADVERTISE_1000_FULL
) {
2426 /* Disable SmartSpeed */
2427 ret_val
= e1000_read_phy_reg(hw
,
2428 IGP01E1000_PHY_PORT_CONFIG
, &phy_data
);
2431 phy_data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
2432 ret_val
= e1000_write_phy_reg(hw
,
2433 IGP01E1000_PHY_PORT_CONFIG
, phy_data
);
2436 /* Set auto Master/Slave resolution process */
2437 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_CTRL
,
2441 phy_data
&= ~CR_1000T_MS_ENABLE
;
2442 ret_val
= e1000_write_phy_reg(hw
, PHY_1000T_CTRL
,
2448 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_data
);
2452 /* load defaults for future use */
2453 hw
->original_master_slave
= (phy_data
& CR_1000T_MS_ENABLE
) ?
2454 ((phy_data
& CR_1000T_MS_VALUE
) ?
2455 e1000_ms_force_master
:
2456 e1000_ms_force_slave
) :
2459 switch (phy_ms_setting
) {
2460 case e1000_ms_force_master
:
2461 phy_data
|= (CR_1000T_MS_ENABLE
| CR_1000T_MS_VALUE
);
2463 case e1000_ms_force_slave
:
2464 phy_data
|= CR_1000T_MS_ENABLE
;
2465 phy_data
&= ~(CR_1000T_MS_VALUE
);
2468 phy_data
&= ~CR_1000T_MS_ENABLE
;
2472 ret_val
= e1000_write_phy_reg(hw
, PHY_1000T_CTRL
, phy_data
);
2477 return E1000_SUCCESS
;
2480 /*****************************************************************************
2481 * This function checks the mode of the firmware.
2483 * returns - true when the mode is IAMT or false.
2484 ****************************************************************************/
2486 e1000_check_mng_mode(struct e1000_hw
*hw
)
2491 fwsm
= E1000_READ_REG(hw
, FWSM
);
2493 if (hw
->mac_type
== e1000_ich8lan
) {
2494 if ((fwsm
& E1000_FWSM_MODE_MASK
) ==
2495 (E1000_MNG_ICH_IAMT_MODE
<< E1000_FWSM_MODE_SHIFT
))
2497 } else if ((fwsm
& E1000_FWSM_MODE_MASK
) ==
2498 (E1000_MNG_IAMT_MODE
<< E1000_FWSM_MODE_SHIFT
))
2505 e1000_write_kmrn_reg(struct e1000_hw
*hw
, uint32_t reg_addr
, uint16_t data
)
2507 uint16_t swfw
= E1000_SWFW_PHY0_SM
;
2511 if (e1000_is_second_port(hw
))
2512 swfw
= E1000_SWFW_PHY1_SM
;
2514 if (e1000_swfw_sync_acquire(hw
, swfw
))
2515 return -E1000_ERR_SWFW_SYNC
;
2517 reg_val
= ((reg_addr
<< E1000_KUMCTRLSTA_OFFSET_SHIFT
)
2518 & E1000_KUMCTRLSTA_OFFSET
) | data
;
2519 E1000_WRITE_REG(hw
, KUMCTRLSTA
, reg_val
);
2522 return E1000_SUCCESS
;
2526 e1000_read_kmrn_reg(struct e1000_hw
*hw
, uint32_t reg_addr
, uint16_t *data
)
2528 uint16_t swfw
= E1000_SWFW_PHY0_SM
;
2532 if (e1000_is_second_port(hw
))
2533 swfw
= E1000_SWFW_PHY1_SM
;
2535 if (e1000_swfw_sync_acquire(hw
, swfw
))
2536 return -E1000_ERR_SWFW_SYNC
;
2538 /* Write register address */
2539 reg_val
= ((reg_addr
<< E1000_KUMCTRLSTA_OFFSET_SHIFT
) &
2540 E1000_KUMCTRLSTA_OFFSET
) | E1000_KUMCTRLSTA_REN
;
2541 E1000_WRITE_REG(hw
, KUMCTRLSTA
, reg_val
);
2544 /* Read the data returned */
2545 reg_val
= E1000_READ_REG(hw
, KUMCTRLSTA
);
2546 *data
= (uint16_t)reg_val
;
2548 return E1000_SUCCESS
;
2551 /********************************************************************
2552 * Copper link setup for e1000_phy_gg82563 series.
2554 * hw - Struct containing variables accessed by shared code
2555 *********************************************************************/
2557 e1000_copper_link_ggp_setup(struct e1000_hw
*hw
)
2565 if (!hw
->phy_reset_disable
) {
2566 /* Enable CRS on TX for half-duplex operation. */
2567 ret_val
= e1000_read_phy_reg(hw
,
2568 GG82563_PHY_MAC_SPEC_CTRL
, &phy_data
);
2572 phy_data
|= GG82563_MSCR_ASSERT_CRS_ON_TX
;
2573 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
2574 phy_data
|= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ
;
2576 ret_val
= e1000_write_phy_reg(hw
,
2577 GG82563_PHY_MAC_SPEC_CTRL
, phy_data
);
2582 * MDI/MDI-X = 0 (default)
2583 * 0 - Auto for all speeds
2586 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2588 ret_val
= e1000_read_phy_reg(hw
,
2589 GG82563_PHY_SPEC_CTRL
, &phy_data
);
2593 phy_data
&= ~GG82563_PSCR_CROSSOVER_MODE_MASK
;
2597 phy_data
|= GG82563_PSCR_CROSSOVER_MODE_MDI
;
2600 phy_data
|= GG82563_PSCR_CROSSOVER_MODE_MDIX
;
2604 phy_data
|= GG82563_PSCR_CROSSOVER_MODE_AUTO
;
2609 * disable_polarity_correction = 0 (default)
2610 * Automatic Correction for Reversed Cable Polarity
2614 phy_data
&= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE
;
2615 ret_val
= e1000_write_phy_reg(hw
,
2616 GG82563_PHY_SPEC_CTRL
, phy_data
);
2621 /* SW Reset the PHY so all changes take effect */
2622 ret_val
= e1000_phy_reset(hw
);
2624 DEBUGOUT("Error Resetting the PHY\n");
2627 } /* phy_reset_disable */
2629 if (hw
->mac_type
== e1000_80003es2lan
) {
2630 /* Bypass RX and TX FIFO's */
2631 ret_val
= e1000_write_kmrn_reg(hw
,
2632 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL
,
2633 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2634 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS
);
2638 ret_val
= e1000_read_phy_reg(hw
,
2639 GG82563_PHY_SPEC_CTRL_2
, &phy_data
);
2643 phy_data
&= ~GG82563_PSCR2_REVERSE_AUTO_NEG
;
2644 ret_val
= e1000_write_phy_reg(hw
,
2645 GG82563_PHY_SPEC_CTRL_2
, phy_data
);
2650 reg_data
= E1000_READ_REG(hw
, CTRL_EXT
);
2651 reg_data
&= ~(E1000_CTRL_EXT_LINK_MODE_MASK
);
2652 E1000_WRITE_REG(hw
, CTRL_EXT
, reg_data
);
2654 ret_val
= e1000_read_phy_reg(hw
,
2655 GG82563_PHY_PWR_MGMT_CTRL
, &phy_data
);
2659 /* Do not init these registers when the HW is in IAMT mode, since the
2660 * firmware will have already initialized them. We only initialize
2661 * them if the HW is not in IAMT mode.
2663 if (e1000_check_mng_mode(hw
) == false) {
2664 /* Enable Electrical Idle on the PHY */
2665 phy_data
|= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE
;
2666 ret_val
= e1000_write_phy_reg(hw
,
2667 GG82563_PHY_PWR_MGMT_CTRL
, phy_data
);
2671 ret_val
= e1000_read_phy_reg(hw
,
2672 GG82563_PHY_KMRN_MODE_CTRL
, &phy_data
);
2676 phy_data
&= ~GG82563_KMCR_PASS_FALSE_CARRIER
;
2677 ret_val
= e1000_write_phy_reg(hw
,
2678 GG82563_PHY_KMRN_MODE_CTRL
, phy_data
);
2684 /* Workaround: Disable padding in Kumeran interface in the MAC
2685 * and in the PHY to avoid CRC errors.
2687 ret_val
= e1000_read_phy_reg(hw
,
2688 GG82563_PHY_INBAND_CTRL
, &phy_data
);
2691 phy_data
|= GG82563_ICR_DIS_PADDING
;
2692 ret_val
= e1000_write_phy_reg(hw
,
2693 GG82563_PHY_INBAND_CTRL
, phy_data
);
2697 return E1000_SUCCESS
;
2700 /********************************************************************
2701 * Copper link setup for e1000_phy_m88 series.
2703 * hw - Struct containing variables accessed by shared code
2704 *********************************************************************/
2706 e1000_copper_link_mgp_setup(struct e1000_hw
*hw
)
2713 if (hw
->phy_reset_disable
)
2714 return E1000_SUCCESS
;
2716 /* Enable CRS on TX. This must be set for half-duplex operation. */
2717 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
2721 phy_data
|= M88E1000_PSCR_ASSERT_CRS_ON_TX
;
2724 * MDI/MDI-X = 0 (default)
2725 * 0 - Auto for all speeds
2728 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2730 phy_data
&= ~M88E1000_PSCR_AUTO_X_MODE
;
2734 phy_data
|= M88E1000_PSCR_MDI_MANUAL_MODE
;
2737 phy_data
|= M88E1000_PSCR_MDIX_MANUAL_MODE
;
2740 phy_data
|= M88E1000_PSCR_AUTO_X_1000T
;
2744 phy_data
|= M88E1000_PSCR_AUTO_X_MODE
;
2749 * disable_polarity_correction = 0 (default)
2750 * Automatic Correction for Reversed Cable Polarity
2754 phy_data
&= ~M88E1000_PSCR_POLARITY_REVERSAL
;
2755 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
);
2759 if (hw
->phy_revision
< M88E1011_I_REV_4
) {
2760 /* Force TX_CLK in the Extended PHY Specific Control Register
2763 ret_val
= e1000_read_phy_reg(hw
,
2764 M88E1000_EXT_PHY_SPEC_CTRL
, &phy_data
);
2768 phy_data
|= M88E1000_EPSCR_TX_CLK_25
;
2770 if ((hw
->phy_revision
== E1000_REVISION_2
) &&
2771 (hw
->phy_id
== M88E1111_I_PHY_ID
)) {
2772 /* Vidalia Phy, set the downshift counter to 5x */
2773 phy_data
&= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK
);
2774 phy_data
|= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X
;
2775 ret_val
= e1000_write_phy_reg(hw
,
2776 M88E1000_EXT_PHY_SPEC_CTRL
, phy_data
);
2780 /* Configure Master and Slave downshift values */
2781 phy_data
&= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
2782 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK
);
2783 phy_data
|= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
2784 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X
);
2785 ret_val
= e1000_write_phy_reg(hw
,
2786 M88E1000_EXT_PHY_SPEC_CTRL
, phy_data
);
2792 /* SW Reset the PHY so all changes take effect */
2793 ret_val
= e1000_phy_reset(hw
);
2795 DEBUGOUT("Error Resetting the PHY\n");
2799 return E1000_SUCCESS
;
2802 /********************************************************************
2803 * Setup auto-negotiation and flow control advertisements,
2804 * and then perform auto-negotiation.
2806 * hw - Struct containing variables accessed by shared code
2807 *********************************************************************/
2809 e1000_copper_link_autoneg(struct e1000_hw
*hw
)
2816 /* Perform some bounds checking on the hw->autoneg_advertised
2817 * parameter. If this variable is zero, then set it to the default.
2819 hw
->autoneg_advertised
&= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
2821 /* If autoneg_advertised is zero, we assume it was not defaulted
2822 * by the calling code so we set to advertise full capability.
2824 if (hw
->autoneg_advertised
== 0)
2825 hw
->autoneg_advertised
= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
2827 /* IFE phy only supports 10/100 */
2828 if (hw
->phy_type
== e1000_phy_ife
)
2829 hw
->autoneg_advertised
&= AUTONEG_ADVERTISE_10_100_ALL
;
2831 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
2832 ret_val
= e1000_phy_setup_autoneg(hw
);
2834 DEBUGOUT("Error Setting up Auto-Negotiation\n");
2837 DEBUGOUT("Restarting Auto-Neg\n");
2839 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
2840 * the Auto Neg Restart bit in the PHY control register.
2842 ret_val
= e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_data
);
2846 phy_data
|= (MII_CR_AUTO_NEG_EN
| MII_CR_RESTART_AUTO_NEG
);
2847 ret_val
= e1000_write_phy_reg(hw
, PHY_CTRL
, phy_data
);
2851 /* Does the user want to wait for Auto-Neg to complete here, or
2852 * check at a later time (for example, callback routine).
2854 /* If we do not wait for autonegtation to complete I
2855 * do not see a valid link status.
2856 * wait_autoneg_complete = 1 .
2858 if (hw
->wait_autoneg_complete
) {
2859 ret_val
= e1000_wait_autoneg(hw
);
2861 DEBUGOUT("Error while waiting for autoneg"
2867 hw
->get_link_status
= true;
2869 return E1000_SUCCESS
;
2872 /******************************************************************************
2873 * Config the MAC and the PHY after link is up.
2874 * 1) Set up the MAC to the current PHY speed/duplex
2875 * if we are on 82543. If we
2876 * are on newer silicon, we only need to configure
2877 * collision distance in the Transmit Control Register.
2878 * 2) Set up flow control on the MAC to that established with
2880 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
2882 * hw - Struct containing variables accessed by shared code
2883 ******************************************************************************/
2885 e1000_copper_link_postconfig(struct e1000_hw
*hw
)
2890 if (hw
->mac_type
>= e1000_82544
) {
2891 e1000_config_collision_dist(hw
);
2893 ret_val
= e1000_config_mac_to_phy(hw
);
2895 DEBUGOUT("Error configuring MAC to PHY settings\n");
2899 ret_val
= e1000_config_fc_after_link_up(hw
);
2901 DEBUGOUT("Error Configuring Flow Control\n");
2904 return E1000_SUCCESS
;
2907 /******************************************************************************
2908 * Detects which PHY is present and setup the speed and duplex
2910 * hw - Struct containing variables accessed by shared code
2911 ******************************************************************************/
2913 e1000_setup_copper_link(struct eth_device
*nic
)
2915 struct e1000_hw
*hw
= nic
->priv
;
2923 switch (hw
->mac_type
) {
2924 case e1000_80003es2lan
:
2926 /* Set the mac to wait the maximum time between each
2927 * iteration and increase the max iterations when
2928 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
2929 ret_val
= e1000_write_kmrn_reg(hw
,
2930 GG82563_REG(0x34, 4), 0xFFFF);
2933 ret_val
= e1000_read_kmrn_reg(hw
,
2934 GG82563_REG(0x34, 9), ®_data
);
2938 ret_val
= e1000_write_kmrn_reg(hw
,
2939 GG82563_REG(0x34, 9), reg_data
);
2946 /* Check if it is a valid PHY and set PHY mode if necessary. */
2947 ret_val
= e1000_copper_link_preconfig(hw
);
2950 switch (hw
->mac_type
) {
2951 case e1000_80003es2lan
:
2952 /* Kumeran registers are written-only */
2954 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT
;
2955 reg_data
|= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING
;
2956 ret_val
= e1000_write_kmrn_reg(hw
,
2957 E1000_KUMCTRLSTA_OFFSET_INB_CTRL
, reg_data
);
2965 if (hw
->phy_type
== e1000_phy_igp
||
2966 hw
->phy_type
== e1000_phy_igp_3
||
2967 hw
->phy_type
== e1000_phy_igp_2
) {
2968 ret_val
= e1000_copper_link_igp_setup(hw
);
2971 } else if (hw
->phy_type
== e1000_phy_m88
) {
2972 ret_val
= e1000_copper_link_mgp_setup(hw
);
2975 } else if (hw
->phy_type
== e1000_phy_gg82563
) {
2976 ret_val
= e1000_copper_link_ggp_setup(hw
);
2982 /* Setup autoneg and flow control advertisement
2983 * and perform autonegotiation */
2984 ret_val
= e1000_copper_link_autoneg(hw
);
2988 /* Check link status. Wait up to 100 microseconds for link to become
2991 for (i
= 0; i
< 10; i
++) {
2992 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
2995 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
2999 if (phy_data
& MII_SR_LINK_STATUS
) {
3000 /* Config the MAC and PHY after link is up */
3001 ret_val
= e1000_copper_link_postconfig(hw
);
3005 DEBUGOUT("Valid link established!!!\n");
3006 return E1000_SUCCESS
;
3011 DEBUGOUT("Unable to establish link!!!\n");
3012 return E1000_SUCCESS
;
3015 /******************************************************************************
3016 * Configures PHY autoneg and flow control advertisement settings
3018 * hw - Struct containing variables accessed by shared code
3019 ******************************************************************************/
3021 e1000_phy_setup_autoneg(struct e1000_hw
*hw
)
3024 uint16_t mii_autoneg_adv_reg
;
3025 uint16_t mii_1000t_ctrl_reg
;
3029 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
3030 ret_val
= e1000_read_phy_reg(hw
, PHY_AUTONEG_ADV
, &mii_autoneg_adv_reg
);
3034 if (hw
->phy_type
!= e1000_phy_ife
) {
3035 /* Read the MII 1000Base-T Control Register (Address 9). */
3036 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_CTRL
,
3037 &mii_1000t_ctrl_reg
);
3041 mii_1000t_ctrl_reg
= 0;
3043 /* Need to parse both autoneg_advertised and fc and set up
3044 * the appropriate PHY registers. First we will parse for
3045 * autoneg_advertised software override. Since we can advertise
3046 * a plethora of combinations, we need to check each bit
3050 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
3051 * Advertisement Register (Address 4) and the 1000 mb speed bits in
3052 * the 1000Base-T Control Register (Address 9).
3054 mii_autoneg_adv_reg
&= ~REG4_SPEED_MASK
;
3055 mii_1000t_ctrl_reg
&= ~REG9_SPEED_MASK
;
3057 DEBUGOUT("autoneg_advertised %x\n", hw
->autoneg_advertised
);
3059 /* Do we want to advertise 10 Mb Half Duplex? */
3060 if (hw
->autoneg_advertised
& ADVERTISE_10_HALF
) {
3061 DEBUGOUT("Advertise 10mb Half duplex\n");
3062 mii_autoneg_adv_reg
|= NWAY_AR_10T_HD_CAPS
;
3065 /* Do we want to advertise 10 Mb Full Duplex? */
3066 if (hw
->autoneg_advertised
& ADVERTISE_10_FULL
) {
3067 DEBUGOUT("Advertise 10mb Full duplex\n");
3068 mii_autoneg_adv_reg
|= NWAY_AR_10T_FD_CAPS
;
3071 /* Do we want to advertise 100 Mb Half Duplex? */
3072 if (hw
->autoneg_advertised
& ADVERTISE_100_HALF
) {
3073 DEBUGOUT("Advertise 100mb Half duplex\n");
3074 mii_autoneg_adv_reg
|= NWAY_AR_100TX_HD_CAPS
;
3077 /* Do we want to advertise 100 Mb Full Duplex? */
3078 if (hw
->autoneg_advertised
& ADVERTISE_100_FULL
) {
3079 DEBUGOUT("Advertise 100mb Full duplex\n");
3080 mii_autoneg_adv_reg
|= NWAY_AR_100TX_FD_CAPS
;
3083 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
3084 if (hw
->autoneg_advertised
& ADVERTISE_1000_HALF
) {
3086 ("Advertise 1000mb Half duplex requested, request denied!\n");
3089 /* Do we want to advertise 1000 Mb Full Duplex? */
3090 if (hw
->autoneg_advertised
& ADVERTISE_1000_FULL
) {
3091 DEBUGOUT("Advertise 1000mb Full duplex\n");
3092 mii_1000t_ctrl_reg
|= CR_1000T_FD_CAPS
;
3095 /* Check for a software override of the flow control settings, and
3096 * setup the PHY advertisement registers accordingly. If
3097 * auto-negotiation is enabled, then software will have to set the
3098 * "PAUSE" bits to the correct value in the Auto-Negotiation
3099 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
3101 * The possible values of the "fc" parameter are:
3102 * 0: Flow control is completely disabled
3103 * 1: Rx flow control is enabled (we can receive pause frames
3104 * but not send pause frames).
3105 * 2: Tx flow control is enabled (we can send pause frames
3106 * but we do not support receiving pause frames).
3107 * 3: Both Rx and TX flow control (symmetric) are enabled.
3108 * other: No software override. The flow control configuration
3109 * in the EEPROM is used.
3112 case e1000_fc_none
: /* 0 */
3113 /* Flow control (RX & TX) is completely disabled by a
3114 * software over-ride.
3116 mii_autoneg_adv_reg
&= ~(NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
3118 case e1000_fc_rx_pause
: /* 1 */
3119 /* RX Flow control is enabled, and TX Flow control is
3120 * disabled, by a software over-ride.
3122 /* Since there really isn't a way to advertise that we are
3123 * capable of RX Pause ONLY, we will advertise that we
3124 * support both symmetric and asymmetric RX PAUSE. Later
3125 * (in e1000_config_fc_after_link_up) we will disable the
3126 *hw's ability to send PAUSE frames.
3128 mii_autoneg_adv_reg
|= (NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
3130 case e1000_fc_tx_pause
: /* 2 */
3131 /* TX Flow control is enabled, and RX Flow control is
3132 * disabled, by a software over-ride.
3134 mii_autoneg_adv_reg
|= NWAY_AR_ASM_DIR
;
3135 mii_autoneg_adv_reg
&= ~NWAY_AR_PAUSE
;
3137 case e1000_fc_full
: /* 3 */
3138 /* Flow control (both RX and TX) is enabled by a software
3141 mii_autoneg_adv_reg
|= (NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
3144 DEBUGOUT("Flow control param set incorrectly\n");
3145 return -E1000_ERR_CONFIG
;
3148 ret_val
= e1000_write_phy_reg(hw
, PHY_AUTONEG_ADV
, mii_autoneg_adv_reg
);
3152 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg
);
3154 if (hw
->phy_type
!= e1000_phy_ife
) {
3155 ret_val
= e1000_write_phy_reg(hw
, PHY_1000T_CTRL
,
3156 mii_1000t_ctrl_reg
);
3161 return E1000_SUCCESS
;
3164 /******************************************************************************
3165 * Sets the collision distance in the Transmit Control register
3167 * hw - Struct containing variables accessed by shared code
3169 * Link should have been established previously. Reads the speed and duplex
3170 * information from the Device Status register.
3171 ******************************************************************************/
3173 e1000_config_collision_dist(struct e1000_hw
*hw
)
3175 uint32_t tctl
, coll_dist
;
3179 if (hw
->mac_type
< e1000_82543
)
3180 coll_dist
= E1000_COLLISION_DISTANCE_82542
;
3182 coll_dist
= E1000_COLLISION_DISTANCE
;
3184 tctl
= E1000_READ_REG(hw
, TCTL
);
3186 tctl
&= ~E1000_TCTL_COLD
;
3187 tctl
|= coll_dist
<< E1000_COLD_SHIFT
;
3189 E1000_WRITE_REG(hw
, TCTL
, tctl
);
3190 E1000_WRITE_FLUSH(hw
);
3193 /******************************************************************************
3194 * Sets MAC speed and duplex settings to reflect the those in the PHY
3196 * hw - Struct containing variables accessed by shared code
3197 * mii_reg - data to write to the MII control register
3199 * The contents of the PHY register containing the needed information need to
3201 ******************************************************************************/
3203 e1000_config_mac_to_phy(struct e1000_hw
*hw
)
3210 /* Read the Device Control Register and set the bits to Force Speed
3213 ctrl
= E1000_READ_REG(hw
, CTRL
);
3214 ctrl
|= (E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
3215 ctrl
&= ~(E1000_CTRL_SPD_SEL
| E1000_CTRL_ILOS
);
3217 /* Set up duplex in the Device Control and Transmit Control
3218 * registers depending on negotiated values.
3220 if (e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
) < 0) {
3221 DEBUGOUT("PHY Read Error\n");
3222 return -E1000_ERR_PHY
;
3224 if (phy_data
& M88E1000_PSSR_DPLX
)
3225 ctrl
|= E1000_CTRL_FD
;
3227 ctrl
&= ~E1000_CTRL_FD
;
3229 e1000_config_collision_dist(hw
);
3231 /* Set up speed in the Device Control register depending on
3232 * negotiated values.
3234 if ((phy_data
& M88E1000_PSSR_SPEED
) == M88E1000_PSSR_1000MBS
)
3235 ctrl
|= E1000_CTRL_SPD_1000
;
3236 else if ((phy_data
& M88E1000_PSSR_SPEED
) == M88E1000_PSSR_100MBS
)
3237 ctrl
|= E1000_CTRL_SPD_100
;
3238 /* Write the configured values back to the Device Control Reg. */
3239 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
3243 /******************************************************************************
3244 * Forces the MAC's flow control settings.
3246 * hw - Struct containing variables accessed by shared code
3248 * Sets the TFCE and RFCE bits in the device control register to reflect
3249 * the adapter settings. TFCE and RFCE need to be explicitly set by
3250 * software when a Copper PHY is used because autonegotiation is managed
3251 * by the PHY rather than the MAC. Software must also configure these
3252 * bits when link is forced on a fiber connection.
3253 *****************************************************************************/
3255 e1000_force_mac_fc(struct e1000_hw
*hw
)
3261 /* Get the current configuration of the Device Control Register */
3262 ctrl
= E1000_READ_REG(hw
, CTRL
);
3264 /* Because we didn't get link via the internal auto-negotiation
3265 * mechanism (we either forced link or we got link via PHY
3266 * auto-neg), we have to manually enable/disable transmit an
3267 * receive flow control.
3269 * The "Case" statement below enables/disable flow control
3270 * according to the "hw->fc" parameter.
3272 * The possible values of the "fc" parameter are:
3273 * 0: Flow control is completely disabled
3274 * 1: Rx flow control is enabled (we can receive pause
3275 * frames but not send pause frames).
3276 * 2: Tx flow control is enabled (we can send pause frames
3277 * frames but we do not receive pause frames).
3278 * 3: Both Rx and TX flow control (symmetric) is enabled.
3279 * other: No other values should be possible at this point.
3284 ctrl
&= (~(E1000_CTRL_TFCE
| E1000_CTRL_RFCE
));
3286 case e1000_fc_rx_pause
:
3287 ctrl
&= (~E1000_CTRL_TFCE
);
3288 ctrl
|= E1000_CTRL_RFCE
;
3290 case e1000_fc_tx_pause
:
3291 ctrl
&= (~E1000_CTRL_RFCE
);
3292 ctrl
|= E1000_CTRL_TFCE
;
3295 ctrl
|= (E1000_CTRL_TFCE
| E1000_CTRL_RFCE
);
3298 DEBUGOUT("Flow control param set incorrectly\n");
3299 return -E1000_ERR_CONFIG
;
3302 /* Disable TX Flow Control for 82542 (rev 2.0) */
3303 if (hw
->mac_type
== e1000_82542_rev2_0
)
3304 ctrl
&= (~E1000_CTRL_TFCE
);
3306 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
3310 /******************************************************************************
3311 * Configures flow control settings after link is established
3313 * hw - Struct containing variables accessed by shared code
3315 * Should be called immediately after a valid link has been established.
3316 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
3317 * and autonegotiation is enabled, the MAC flow control settings will be set
3318 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
3319 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
3320 *****************************************************************************/
3322 e1000_config_fc_after_link_up(struct e1000_hw
*hw
)
3325 uint16_t mii_status_reg
;
3326 uint16_t mii_nway_adv_reg
;
3327 uint16_t mii_nway_lp_ability_reg
;
3333 /* Check for the case where we have fiber media and auto-neg failed
3334 * so we had to force link. In this case, we need to force the
3335 * configuration of the MAC to match the "fc" parameter.
3337 if (((hw
->media_type
== e1000_media_type_fiber
) && (hw
->autoneg_failed
))
3338 || ((hw
->media_type
== e1000_media_type_internal_serdes
)
3339 && (hw
->autoneg_failed
))
3340 || ((hw
->media_type
== e1000_media_type_copper
)
3341 && (!hw
->autoneg
))) {
3342 ret_val
= e1000_force_mac_fc(hw
);
3344 DEBUGOUT("Error forcing flow control settings\n");
3349 /* Check for the case where we have copper media and auto-neg is
3350 * enabled. In this case, we need to check and see if Auto-Neg
3351 * has completed, and if so, how the PHY and link partner has
3352 * flow control configured.
3354 if (hw
->media_type
== e1000_media_type_copper
) {
3355 /* Read the MII Status Register and check to see if AutoNeg
3356 * has completed. We read this twice because this reg has
3357 * some "sticky" (latched) bits.
3359 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
) < 0) {
3360 DEBUGOUT("PHY Read Error \n");
3361 return -E1000_ERR_PHY
;
3363 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
) < 0) {
3364 DEBUGOUT("PHY Read Error \n");
3365 return -E1000_ERR_PHY
;
3368 if (mii_status_reg
& MII_SR_AUTONEG_COMPLETE
) {
3369 /* The AutoNeg process has completed, so we now need to
3370 * read both the Auto Negotiation Advertisement Register
3371 * (Address 4) and the Auto_Negotiation Base Page Ability
3372 * Register (Address 5) to determine how flow control was
3375 if (e1000_read_phy_reg
3376 (hw
, PHY_AUTONEG_ADV
, &mii_nway_adv_reg
) < 0) {
3377 DEBUGOUT("PHY Read Error\n");
3378 return -E1000_ERR_PHY
;
3380 if (e1000_read_phy_reg
3381 (hw
, PHY_LP_ABILITY
,
3382 &mii_nway_lp_ability_reg
) < 0) {
3383 DEBUGOUT("PHY Read Error\n");
3384 return -E1000_ERR_PHY
;
3387 /* Two bits in the Auto Negotiation Advertisement Register
3388 * (Address 4) and two bits in the Auto Negotiation Base
3389 * Page Ability Register (Address 5) determine flow control
3390 * for both the PHY and the link partner. The following
3391 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
3392 * 1999, describes these PAUSE resolution bits and how flow
3393 * control is determined based upon these settings.
3394 * NOTE: DC = Don't Care
3396 * LOCAL DEVICE | LINK PARTNER
3397 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
3398 *-------|---------|-------|---------|--------------------
3399 * 0 | 0 | DC | DC | e1000_fc_none
3400 * 0 | 1 | 0 | DC | e1000_fc_none
3401 * 0 | 1 | 1 | 0 | e1000_fc_none
3402 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3403 * 1 | 0 | 0 | DC | e1000_fc_none
3404 * 1 | DC | 1 | DC | e1000_fc_full
3405 * 1 | 1 | 0 | 0 | e1000_fc_none
3406 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3409 /* Are both PAUSE bits set to 1? If so, this implies
3410 * Symmetric Flow Control is enabled at both ends. The
3411 * ASM_DIR bits are irrelevant per the spec.
3413 * For Symmetric Flow Control:
3415 * LOCAL DEVICE | LINK PARTNER
3416 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3417 *-------|---------|-------|---------|--------------------
3418 * 1 | DC | 1 | DC | e1000_fc_full
3421 if ((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
3422 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
)) {
3423 /* Now we need to check if the user selected RX ONLY
3424 * of pause frames. In this case, we had to advertise
3425 * FULL flow control because we could not advertise RX
3426 * ONLY. Hence, we must now check to see if we need to
3427 * turn OFF the TRANSMISSION of PAUSE frames.
3429 if (hw
->original_fc
== e1000_fc_full
) {
3430 hw
->fc
= e1000_fc_full
;
3431 DEBUGOUT("Flow Control = FULL.\r\n");
3433 hw
->fc
= e1000_fc_rx_pause
;
3435 ("Flow Control = RX PAUSE frames only.\r\n");
3438 /* For receiving PAUSE frames ONLY.
3440 * LOCAL DEVICE | LINK PARTNER
3441 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3442 *-------|---------|-------|---------|--------------------
3443 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3446 else if (!(mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
3447 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
3448 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
3449 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
))
3451 hw
->fc
= e1000_fc_tx_pause
;
3453 ("Flow Control = TX PAUSE frames only.\r\n");
3455 /* For transmitting PAUSE frames ONLY.
3457 * LOCAL DEVICE | LINK PARTNER
3458 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3459 *-------|---------|-------|---------|--------------------
3460 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3463 else if ((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
3464 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
3465 !(mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
3466 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
))
3468 hw
->fc
= e1000_fc_rx_pause
;
3470 ("Flow Control = RX PAUSE frames only.\r\n");
3472 /* Per the IEEE spec, at this point flow control should be
3473 * disabled. However, we want to consider that we could
3474 * be connected to a legacy switch that doesn't advertise
3475 * desired flow control, but can be forced on the link
3476 * partner. So if we advertised no flow control, that is
3477 * what we will resolve to. If we advertised some kind of
3478 * receive capability (Rx Pause Only or Full Flow Control)
3479 * and the link partner advertised none, we will configure
3480 * ourselves to enable Rx Flow Control only. We can do
3481 * this safely for two reasons: If the link partner really
3482 * didn't want flow control enabled, and we enable Rx, no
3483 * harm done since we won't be receiving any PAUSE frames
3484 * anyway. If the intent on the link partner was to have
3485 * flow control enabled, then by us enabling RX only, we
3486 * can at least receive pause frames and process them.
3487 * This is a good idea because in most cases, since we are
3488 * predominantly a server NIC, more times than not we will
3489 * be asked to delay transmission of packets than asking
3490 * our link partner to pause transmission of frames.
3492 else if (hw
->original_fc
== e1000_fc_none
||
3493 hw
->original_fc
== e1000_fc_tx_pause
) {
3494 hw
->fc
= e1000_fc_none
;
3495 DEBUGOUT("Flow Control = NONE.\r\n");
3497 hw
->fc
= e1000_fc_rx_pause
;
3499 ("Flow Control = RX PAUSE frames only.\r\n");
3502 /* Now we need to do one last check... If we auto-
3503 * negotiated to HALF DUPLEX, flow control should not be
3504 * enabled per IEEE 802.3 spec.
3506 e1000_get_speed_and_duplex(hw
, &speed
, &duplex
);
3508 if (duplex
== HALF_DUPLEX
)
3509 hw
->fc
= e1000_fc_none
;
3511 /* Now we call a subroutine to actually force the MAC
3512 * controller to use the correct flow control settings.
3514 ret_val
= e1000_force_mac_fc(hw
);
3517 ("Error forcing flow control settings\n");
3522 ("Copper PHY and Auto Neg has not completed.\r\n");
3525 return E1000_SUCCESS
;
3528 /******************************************************************************
3529 * Checks to see if the link status of the hardware has changed.
3531 * hw - Struct containing variables accessed by shared code
3533 * Called by any function that needs to check the link status of the adapter.
3534 *****************************************************************************/
3536 e1000_check_for_link(struct eth_device
*nic
)
3538 struct e1000_hw
*hw
= nic
->priv
;
3546 uint16_t lp_capability
;
3550 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
3551 * set when the optics detect a signal. On older adapters, it will be
3552 * cleared when there is a signal
3554 ctrl
= E1000_READ_REG(hw
, CTRL
);
3555 if ((hw
->mac_type
> e1000_82544
) && !(ctrl
& E1000_CTRL_ILOS
))
3556 signal
= E1000_CTRL_SWDPIN1
;
3560 status
= E1000_READ_REG(hw
, STATUS
);
3561 rxcw
= E1000_READ_REG(hw
, RXCW
);
3562 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl
, status
, rxcw
);
3564 /* If we have a copper PHY then we only want to go out to the PHY
3565 * registers to see if Auto-Neg has completed and/or if our link
3566 * status has changed. The get_link_status flag will be set if we
3567 * receive a Link Status Change interrupt or we have Rx Sequence
3570 if ((hw
->media_type
== e1000_media_type_copper
) && hw
->get_link_status
) {
3571 /* First we want to see if the MII Status Register reports
3572 * link. If so, then we want to get the current speed/duplex
3574 * Read the register twice since the link bit is sticky.
3576 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
3577 DEBUGOUT("PHY Read Error\n");
3578 return -E1000_ERR_PHY
;
3580 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
3581 DEBUGOUT("PHY Read Error\n");
3582 return -E1000_ERR_PHY
;
3585 if (phy_data
& MII_SR_LINK_STATUS
) {
3586 hw
->get_link_status
= false;
3588 /* No link detected */
3589 return -E1000_ERR_NOLINK
;
3592 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3593 * have Si on board that is 82544 or newer, Auto
3594 * Speed Detection takes care of MAC speed/duplex
3595 * configuration. So we only need to configure Collision
3596 * Distance in the MAC. Otherwise, we need to force
3597 * speed/duplex on the MAC to the current PHY speed/duplex
3600 if (hw
->mac_type
>= e1000_82544
)
3601 e1000_config_collision_dist(hw
);
3603 ret_val
= e1000_config_mac_to_phy(hw
);
3606 ("Error configuring MAC to PHY settings\n");
3611 /* Configure Flow Control now that Auto-Neg has completed. First, we
3612 * need to restore the desired flow control settings because we may
3613 * have had to re-autoneg with a different link partner.
3615 ret_val
= e1000_config_fc_after_link_up(hw
);
3617 DEBUGOUT("Error configuring flow control\n");
3621 /* At this point we know that we are on copper and we have
3622 * auto-negotiated link. These are conditions for checking the link
3623 * parter capability register. We use the link partner capability to
3624 * determine if TBI Compatibility needs to be turned on or off. If
3625 * the link partner advertises any speed in addition to Gigabit, then
3626 * we assume that they are GMII-based, and TBI compatibility is not
3627 * needed. If no other speeds are advertised, we assume the link
3628 * partner is TBI-based, and we turn on TBI Compatibility.
3630 if (hw
->tbi_compatibility_en
) {
3631 if (e1000_read_phy_reg
3632 (hw
, PHY_LP_ABILITY
, &lp_capability
) < 0) {
3633 DEBUGOUT("PHY Read Error\n");
3634 return -E1000_ERR_PHY
;
3636 if (lp_capability
& (NWAY_LPAR_10T_HD_CAPS
|
3637 NWAY_LPAR_10T_FD_CAPS
|
3638 NWAY_LPAR_100TX_HD_CAPS
|
3639 NWAY_LPAR_100TX_FD_CAPS
|
3640 NWAY_LPAR_100T4_CAPS
)) {
3641 /* If our link partner advertises anything in addition to
3642 * gigabit, we do not need to enable TBI compatibility.
3644 if (hw
->tbi_compatibility_on
) {
3645 /* If we previously were in the mode, turn it off. */
3646 rctl
= E1000_READ_REG(hw
, RCTL
);
3647 rctl
&= ~E1000_RCTL_SBP
;
3648 E1000_WRITE_REG(hw
, RCTL
, rctl
);
3649 hw
->tbi_compatibility_on
= false;
3652 /* If TBI compatibility is was previously off, turn it on. For
3653 * compatibility with a TBI link partner, we will store bad
3654 * packets. Some frames have an additional byte on the end and
3655 * will look like CRC errors to to the hardware.
3657 if (!hw
->tbi_compatibility_on
) {
3658 hw
->tbi_compatibility_on
= true;
3659 rctl
= E1000_READ_REG(hw
, RCTL
);
3660 rctl
|= E1000_RCTL_SBP
;
3661 E1000_WRITE_REG(hw
, RCTL
, rctl
);
3666 /* If we don't have link (auto-negotiation failed or link partner cannot
3667 * auto-negotiate), the cable is plugged in (we have signal), and our
3668 * link partner is not trying to auto-negotiate with us (we are receiving
3669 * idles or data), we need to force link up. We also need to give
3670 * auto-negotiation time to complete, in case the cable was just plugged
3671 * in. The autoneg_failed flag does this.
3673 else if ((hw
->media_type
== e1000_media_type_fiber
) &&
3674 (!(status
& E1000_STATUS_LU
)) &&
3675 ((ctrl
& E1000_CTRL_SWDPIN1
) == signal
) &&
3676 (!(rxcw
& E1000_RXCW_C
))) {
3677 if (hw
->autoneg_failed
== 0) {
3678 hw
->autoneg_failed
= 1;
3681 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
3683 /* Disable auto-negotiation in the TXCW register */
3684 E1000_WRITE_REG(hw
, TXCW
, (hw
->txcw
& ~E1000_TXCW_ANE
));
3686 /* Force link-up and also force full-duplex. */
3687 ctrl
= E1000_READ_REG(hw
, CTRL
);
3688 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FD
);
3689 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
3691 /* Configure Flow Control after forcing link up. */
3692 ret_val
= e1000_config_fc_after_link_up(hw
);
3694 DEBUGOUT("Error configuring flow control\n");
3698 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3699 * auto-negotiation in the TXCW register and disable forced link in the
3700 * Device Control register in an attempt to auto-negotiate with our link
3703 else if ((hw
->media_type
== e1000_media_type_fiber
) &&
3704 (ctrl
& E1000_CTRL_SLU
) && (rxcw
& E1000_RXCW_C
)) {
3706 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
3707 E1000_WRITE_REG(hw
, TXCW
, hw
->txcw
);
3708 E1000_WRITE_REG(hw
, CTRL
, (ctrl
& ~E1000_CTRL_SLU
));
3713 /******************************************************************************
3714 * Configure the MAC-to-PHY interface for 10/100Mbps
3716 * hw - Struct containing variables accessed by shared code
3717 ******************************************************************************/
3719 e1000_configure_kmrn_for_10_100(struct e1000_hw
*hw
, uint16_t duplex
)
3721 int32_t ret_val
= E1000_SUCCESS
;
3727 reg_data
= E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT
;
3728 ret_val
= e1000_write_kmrn_reg(hw
,
3729 E1000_KUMCTRLSTA_OFFSET_HD_CTRL
, reg_data
);
3733 /* Configure Transmit Inter-Packet Gap */
3734 tipg
= E1000_READ_REG(hw
, TIPG
);
3735 tipg
&= ~E1000_TIPG_IPGT_MASK
;
3736 tipg
|= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100
;
3737 E1000_WRITE_REG(hw
, TIPG
, tipg
);
3739 ret_val
= e1000_read_phy_reg(hw
, GG82563_PHY_KMRN_MODE_CTRL
, ®_data
);
3744 if (duplex
== HALF_DUPLEX
)
3745 reg_data
|= GG82563_KMCR_PASS_FALSE_CARRIER
;
3747 reg_data
&= ~GG82563_KMCR_PASS_FALSE_CARRIER
;
3749 ret_val
= e1000_write_phy_reg(hw
, GG82563_PHY_KMRN_MODE_CTRL
, reg_data
);
3755 e1000_configure_kmrn_for_1000(struct e1000_hw
*hw
)
3757 int32_t ret_val
= E1000_SUCCESS
;
3763 reg_data
= E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT
;
3764 ret_val
= e1000_write_kmrn_reg(hw
,
3765 E1000_KUMCTRLSTA_OFFSET_HD_CTRL
, reg_data
);
3769 /* Configure Transmit Inter-Packet Gap */
3770 tipg
= E1000_READ_REG(hw
, TIPG
);
3771 tipg
&= ~E1000_TIPG_IPGT_MASK
;
3772 tipg
|= DEFAULT_80003ES2LAN_TIPG_IPGT_1000
;
3773 E1000_WRITE_REG(hw
, TIPG
, tipg
);
3775 ret_val
= e1000_read_phy_reg(hw
, GG82563_PHY_KMRN_MODE_CTRL
, ®_data
);
3780 reg_data
&= ~GG82563_KMCR_PASS_FALSE_CARRIER
;
3781 ret_val
= e1000_write_phy_reg(hw
, GG82563_PHY_KMRN_MODE_CTRL
, reg_data
);
3786 /******************************************************************************
3787 * Detects the current speed and duplex settings of the hardware.
3789 * hw - Struct containing variables accessed by shared code
3790 * speed - Speed of the connection
3791 * duplex - Duplex setting of the connection
3792 *****************************************************************************/
3794 e1000_get_speed_and_duplex(struct e1000_hw
*hw
, uint16_t *speed
,
3803 if (hw
->mac_type
>= e1000_82543
) {
3804 status
= E1000_READ_REG(hw
, STATUS
);
3805 if (status
& E1000_STATUS_SPEED_1000
) {
3806 *speed
= SPEED_1000
;
3807 DEBUGOUT("1000 Mbs, ");
3808 } else if (status
& E1000_STATUS_SPEED_100
) {
3810 DEBUGOUT("100 Mbs, ");
3813 DEBUGOUT("10 Mbs, ");
3816 if (status
& E1000_STATUS_FD
) {
3817 *duplex
= FULL_DUPLEX
;
3818 DEBUGOUT("Full Duplex\r\n");
3820 *duplex
= HALF_DUPLEX
;
3821 DEBUGOUT(" Half Duplex\r\n");
3824 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
3825 *speed
= SPEED_1000
;
3826 *duplex
= FULL_DUPLEX
;
3829 /* IGP01 PHY may advertise full duplex operation after speed downgrade
3830 * even if it is operating at half duplex. Here we set the duplex
3831 * settings to match the duplex in the link partner's capabilities.
3833 if (hw
->phy_type
== e1000_phy_igp
&& hw
->speed_downgraded
) {
3834 ret_val
= e1000_read_phy_reg(hw
, PHY_AUTONEG_EXP
, &phy_data
);
3838 if (!(phy_data
& NWAY_ER_LP_NWAY_CAPS
))
3839 *duplex
= HALF_DUPLEX
;
3841 ret_val
= e1000_read_phy_reg(hw
,
3842 PHY_LP_ABILITY
, &phy_data
);
3845 if ((*speed
== SPEED_100
&&
3846 !(phy_data
& NWAY_LPAR_100TX_FD_CAPS
))
3847 || (*speed
== SPEED_10
3848 && !(phy_data
& NWAY_LPAR_10T_FD_CAPS
)))
3849 *duplex
= HALF_DUPLEX
;
3853 if ((hw
->mac_type
== e1000_80003es2lan
) &&
3854 (hw
->media_type
== e1000_media_type_copper
)) {
3855 if (*speed
== SPEED_1000
)
3856 ret_val
= e1000_configure_kmrn_for_1000(hw
);
3858 ret_val
= e1000_configure_kmrn_for_10_100(hw
, *duplex
);
3862 return E1000_SUCCESS
;
3865 /******************************************************************************
3866 * Blocks until autoneg completes or times out (~4.5 seconds)
3868 * hw - Struct containing variables accessed by shared code
3869 ******************************************************************************/
3871 e1000_wait_autoneg(struct e1000_hw
*hw
)
3877 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3879 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3880 for (i
= PHY_AUTO_NEG_TIME
; i
> 0; i
--) {
3881 /* Read the MII Status Register and wait for Auto-Neg
3882 * Complete bit to be set.
3884 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
3885 DEBUGOUT("PHY Read Error\n");
3886 return -E1000_ERR_PHY
;
3888 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
3889 DEBUGOUT("PHY Read Error\n");
3890 return -E1000_ERR_PHY
;
3892 if (phy_data
& MII_SR_AUTONEG_COMPLETE
) {
3893 DEBUGOUT("Auto-Neg complete.\n");
3898 DEBUGOUT("Auto-Neg timedout.\n");
3899 return -E1000_ERR_TIMEOUT
;
3902 /******************************************************************************
3903 * Raises the Management Data Clock
3905 * hw - Struct containing variables accessed by shared code
3906 * ctrl - Device control register's current value
3907 ******************************************************************************/
3909 e1000_raise_mdi_clk(struct e1000_hw
*hw
, uint32_t * ctrl
)
3911 /* Raise the clock input to the Management Data Clock (by setting the MDC
3912 * bit), and then delay 2 microseconds.
3914 E1000_WRITE_REG(hw
, CTRL
, (*ctrl
| E1000_CTRL_MDC
));
3915 E1000_WRITE_FLUSH(hw
);
3919 /******************************************************************************
3920 * Lowers the Management Data Clock
3922 * hw - Struct containing variables accessed by shared code
3923 * ctrl - Device control register's current value
3924 ******************************************************************************/
3926 e1000_lower_mdi_clk(struct e1000_hw
*hw
, uint32_t * ctrl
)
3928 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3929 * bit), and then delay 2 microseconds.
3931 E1000_WRITE_REG(hw
, CTRL
, (*ctrl
& ~E1000_CTRL_MDC
));
3932 E1000_WRITE_FLUSH(hw
);
3936 /******************************************************************************
3937 * Shifts data bits out to the PHY
3939 * hw - Struct containing variables accessed by shared code
3940 * data - Data to send out to the PHY
3941 * count - Number of bits to shift out
3943 * Bits are shifted out in MSB to LSB order.
3944 ******************************************************************************/
3946 e1000_shift_out_mdi_bits(struct e1000_hw
*hw
, uint32_t data
, uint16_t count
)
3951 /* We need to shift "count" number of bits out to the PHY. So, the value
3952 * in the "data" parameter will be shifted out to the PHY one bit at a
3953 * time. In order to do this, "data" must be broken down into bits.
3956 mask
<<= (count
- 1);
3958 ctrl
= E1000_READ_REG(hw
, CTRL
);
3960 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3961 ctrl
|= (E1000_CTRL_MDIO_DIR
| E1000_CTRL_MDC_DIR
);
3964 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3965 * then raising and lowering the Management Data Clock. A "0" is
3966 * shifted out to the PHY by setting the MDIO bit to "0" and then
3967 * raising and lowering the clock.
3970 ctrl
|= E1000_CTRL_MDIO
;
3972 ctrl
&= ~E1000_CTRL_MDIO
;
3974 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
3975 E1000_WRITE_FLUSH(hw
);
3979 e1000_raise_mdi_clk(hw
, &ctrl
);
3980 e1000_lower_mdi_clk(hw
, &ctrl
);
3986 /******************************************************************************
3987 * Shifts data bits in from the PHY
3989 * hw - Struct containing variables accessed by shared code
3991 * Bits are shifted in in MSB to LSB order.
3992 ******************************************************************************/
3994 e1000_shift_in_mdi_bits(struct e1000_hw
*hw
)
4000 /* In order to read a register from the PHY, we need to shift in a total
4001 * of 18 bits from the PHY. The first two bit (turnaround) times are used
4002 * to avoid contention on the MDIO pin when a read operation is performed.
4003 * These two bits are ignored by us and thrown away. Bits are "shifted in"
4004 * by raising the input to the Management Data Clock (setting the MDC bit),
4005 * and then reading the value of the MDIO bit.
4007 ctrl
= E1000_READ_REG(hw
, CTRL
);
4009 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
4010 ctrl
&= ~E1000_CTRL_MDIO_DIR
;
4011 ctrl
&= ~E1000_CTRL_MDIO
;
4013 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
4014 E1000_WRITE_FLUSH(hw
);
4016 /* Raise and Lower the clock before reading in the data. This accounts for
4017 * the turnaround bits. The first clock occurred when we clocked out the
4018 * last bit of the Register Address.
4020 e1000_raise_mdi_clk(hw
, &ctrl
);
4021 e1000_lower_mdi_clk(hw
, &ctrl
);
4023 for (data
= 0, i
= 0; i
< 16; i
++) {
4025 e1000_raise_mdi_clk(hw
, &ctrl
);
4026 ctrl
= E1000_READ_REG(hw
, CTRL
);
4027 /* Check to see if we shifted in a "1". */
4028 if (ctrl
& E1000_CTRL_MDIO
)
4030 e1000_lower_mdi_clk(hw
, &ctrl
);
4033 e1000_raise_mdi_clk(hw
, &ctrl
);
4034 e1000_lower_mdi_clk(hw
, &ctrl
);
4039 /*****************************************************************************
4040 * Reads the value from a PHY register
4042 * hw - Struct containing variables accessed by shared code
4043 * reg_addr - address of the PHY register to read
4044 ******************************************************************************/
4046 e1000_read_phy_reg(struct e1000_hw
*hw
, uint32_t reg_addr
, uint16_t * phy_data
)
4050 const uint32_t phy_addr
= 1;
4052 if (reg_addr
> MAX_PHY_REG_ADDRESS
) {
4053 DEBUGOUT("PHY Address %d is out of range\n", reg_addr
);
4054 return -E1000_ERR_PARAM
;
4057 if (hw
->mac_type
> e1000_82543
) {
4058 /* Set up Op-code, Phy Address, and register address in the MDI
4059 * Control register. The MAC will take care of interfacing with the
4060 * PHY to retrieve the desired data.
4062 mdic
= ((reg_addr
<< E1000_MDIC_REG_SHIFT
) |
4063 (phy_addr
<< E1000_MDIC_PHY_SHIFT
) |
4064 (E1000_MDIC_OP_READ
));
4066 E1000_WRITE_REG(hw
, MDIC
, mdic
);
4068 /* Poll the ready bit to see if the MDI read completed */
4069 for (i
= 0; i
< 64; i
++) {
4071 mdic
= E1000_READ_REG(hw
, MDIC
);
4072 if (mdic
& E1000_MDIC_READY
)
4075 if (!(mdic
& E1000_MDIC_READY
)) {
4076 DEBUGOUT("MDI Read did not complete\n");
4077 return -E1000_ERR_PHY
;
4079 if (mdic
& E1000_MDIC_ERROR
) {
4080 DEBUGOUT("MDI Error\n");
4081 return -E1000_ERR_PHY
;
4083 *phy_data
= (uint16_t) mdic
;
4085 /* We must first send a preamble through the MDIO pin to signal the
4086 * beginning of an MII instruction. This is done by sending 32
4087 * consecutive "1" bits.
4089 e1000_shift_out_mdi_bits(hw
, PHY_PREAMBLE
, PHY_PREAMBLE_SIZE
);
4091 /* Now combine the next few fields that are required for a read
4092 * operation. We use this method instead of calling the
4093 * e1000_shift_out_mdi_bits routine five different times. The format of
4094 * a MII read instruction consists of a shift out of 14 bits and is
4095 * defined as follows:
4096 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
4097 * followed by a shift in of 18 bits. This first two bits shifted in
4098 * are TurnAround bits used to avoid contention on the MDIO pin when a
4099 * READ operation is performed. These two bits are thrown away
4100 * followed by a shift in of 16 bits which contains the desired data.
4102 mdic
= ((reg_addr
) | (phy_addr
<< 5) |
4103 (PHY_OP_READ
<< 10) | (PHY_SOF
<< 12));
4105 e1000_shift_out_mdi_bits(hw
, mdic
, 14);
4107 /* Now that we've shifted out the read command to the MII, we need to
4108 * "shift in" the 16-bit value (18 total bits) of the requested PHY
4111 *phy_data
= e1000_shift_in_mdi_bits(hw
);
4116 /******************************************************************************
4117 * Writes a value to a PHY register
4119 * hw - Struct containing variables accessed by shared code
4120 * reg_addr - address of the PHY register to write
4121 * data - data to write to the PHY
4122 ******************************************************************************/
4124 e1000_write_phy_reg(struct e1000_hw
*hw
, uint32_t reg_addr
, uint16_t phy_data
)
4128 const uint32_t phy_addr
= 1;
4130 if (reg_addr
> MAX_PHY_REG_ADDRESS
) {
4131 DEBUGOUT("PHY Address %d is out of range\n", reg_addr
);
4132 return -E1000_ERR_PARAM
;
4135 if (hw
->mac_type
> e1000_82543
) {
4136 /* Set up Op-code, Phy Address, register address, and data intended
4137 * for the PHY register in the MDI Control register. The MAC will take
4138 * care of interfacing with the PHY to send the desired data.
4140 mdic
= (((uint32_t) phy_data
) |
4141 (reg_addr
<< E1000_MDIC_REG_SHIFT
) |
4142 (phy_addr
<< E1000_MDIC_PHY_SHIFT
) |
4143 (E1000_MDIC_OP_WRITE
));
4145 E1000_WRITE_REG(hw
, MDIC
, mdic
);
4147 /* Poll the ready bit to see if the MDI read completed */
4148 for (i
= 0; i
< 64; i
++) {
4150 mdic
= E1000_READ_REG(hw
, MDIC
);
4151 if (mdic
& E1000_MDIC_READY
)
4154 if (!(mdic
& E1000_MDIC_READY
)) {
4155 DEBUGOUT("MDI Write did not complete\n");
4156 return -E1000_ERR_PHY
;
4159 /* We'll need to use the SW defined pins to shift the write command
4160 * out to the PHY. We first send a preamble to the PHY to signal the
4161 * beginning of the MII instruction. This is done by sending 32
4162 * consecutive "1" bits.
4164 e1000_shift_out_mdi_bits(hw
, PHY_PREAMBLE
, PHY_PREAMBLE_SIZE
);
4166 /* Now combine the remaining required fields that will indicate a
4167 * write operation. We use this method instead of calling the
4168 * e1000_shift_out_mdi_bits routine for each field in the command. The
4169 * format of a MII write instruction is as follows:
4170 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
4172 mdic
= ((PHY_TURNAROUND
) | (reg_addr
<< 2) | (phy_addr
<< 7) |
4173 (PHY_OP_WRITE
<< 12) | (PHY_SOF
<< 14));
4175 mdic
|= (uint32_t) phy_data
;
4177 e1000_shift_out_mdi_bits(hw
, mdic
, 32);
4182 /******************************************************************************
4183 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
4184 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
4185 * the caller to figure out how to deal with it.
4187 * hw - Struct containing variables accessed by shared code
4189 * returns: - E1000_BLK_PHY_RESET
4192 *****************************************************************************/
4194 e1000_check_phy_reset_block(struct e1000_hw
*hw
)
4199 if (hw
->mac_type
== e1000_ich8lan
) {
4200 fwsm
= E1000_READ_REG(hw
, FWSM
);
4201 return (fwsm
& E1000_FWSM_RSPCIPHY
) ? E1000_SUCCESS
4202 : E1000_BLK_PHY_RESET
;
4205 if (hw
->mac_type
> e1000_82547_rev_2
)
4206 manc
= E1000_READ_REG(hw
, MANC
);
4207 return (manc
& E1000_MANC_BLK_PHY_RST_ON_IDE
) ?
4208 E1000_BLK_PHY_RESET
: E1000_SUCCESS
;
4211 /***************************************************************************
4212 * Checks if the PHY configuration is done
4214 * hw: Struct containing variables accessed by shared code
4216 * returns: - E1000_ERR_RESET if fail to reset MAC
4217 * E1000_SUCCESS at any other case.
4219 ***************************************************************************/
4221 e1000_get_phy_cfg_done(struct e1000_hw
*hw
)
4223 int32_t timeout
= PHY_CFG_TIMEOUT
;
4224 uint32_t cfg_mask
= E1000_EEPROM_CFG_DONE
;
4228 switch (hw
->mac_type
) {
4233 case e1000_80003es2lan
:
4234 /* Separate *_CFG_DONE_* bit for each port */
4235 if (e1000_is_second_port(hw
))
4236 cfg_mask
= E1000_EEPROM_CFG_DONE_PORT_1
;
4242 if (E1000_READ_REG(hw
, EEMNGCTL
) & cfg_mask
)
4249 DEBUGOUT("MNG configuration cycle has not "
4251 return -E1000_ERR_RESET
;
4256 return E1000_SUCCESS
;
4259 /******************************************************************************
4260 * Returns the PHY to the power-on reset state
4262 * hw - Struct containing variables accessed by shared code
4263 ******************************************************************************/
4265 e1000_phy_hw_reset(struct e1000_hw
*hw
)
4267 uint16_t swfw
= E1000_SWFW_PHY0_SM
;
4268 uint32_t ctrl
, ctrl_ext
;
4274 /* In the case of the phy reset being blocked, it's not an error, we
4275 * simply return success without performing the reset. */
4276 ret_val
= e1000_check_phy_reset_block(hw
);
4278 return E1000_SUCCESS
;
4280 DEBUGOUT("Resetting Phy...\n");
4282 if (hw
->mac_type
> e1000_82543
) {
4283 if (e1000_is_second_port(hw
))
4284 swfw
= E1000_SWFW_PHY1_SM
;
4286 if (e1000_swfw_sync_acquire(hw
, swfw
)) {
4287 DEBUGOUT("Unable to acquire swfw sync\n");
4288 return -E1000_ERR_SWFW_SYNC
;
4291 /* Read the device control register and assert the E1000_CTRL_PHY_RST
4292 * bit. Then, take it out of reset.
4294 ctrl
= E1000_READ_REG(hw
, CTRL
);
4295 E1000_WRITE_REG(hw
, CTRL
, ctrl
| E1000_CTRL_PHY_RST
);
4296 E1000_WRITE_FLUSH(hw
);
4298 if (hw
->mac_type
< e1000_82571
)
4303 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
4304 E1000_WRITE_FLUSH(hw
);
4306 if (hw
->mac_type
>= e1000_82571
)
4310 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
4311 * bit to put the PHY into reset. Then, take it out of reset.
4313 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
4314 ctrl_ext
|= E1000_CTRL_EXT_SDP4_DIR
;
4315 ctrl_ext
&= ~E1000_CTRL_EXT_SDP4_DATA
;
4316 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
4317 E1000_WRITE_FLUSH(hw
);
4319 ctrl_ext
|= E1000_CTRL_EXT_SDP4_DATA
;
4320 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
4321 E1000_WRITE_FLUSH(hw
);
4325 if ((hw
->mac_type
== e1000_82541
) || (hw
->mac_type
== e1000_82547
)) {
4326 /* Configure activity LED after PHY reset */
4327 led_ctrl
= E1000_READ_REG(hw
, LEDCTL
);
4328 led_ctrl
&= IGP_ACTIVITY_LED_MASK
;
4329 led_ctrl
|= (IGP_ACTIVITY_LED_ENABLE
| IGP_LED3_MODE
);
4330 E1000_WRITE_REG(hw
, LEDCTL
, led_ctrl
);
4333 /* Wait for FW to finish PHY configuration. */
4334 ret_val
= e1000_get_phy_cfg_done(hw
);
4335 if (ret_val
!= E1000_SUCCESS
)
4341 /******************************************************************************
4342 * IGP phy init script - initializes the GbE PHY
4344 * hw - Struct containing variables accessed by shared code
4345 *****************************************************************************/
4347 e1000_phy_init_script(struct e1000_hw
*hw
)
4350 uint16_t phy_saved_data
;
4353 if (hw
->phy_init_script
) {
4356 /* Save off the current value of register 0x2F5B to be
4357 * restored at the end of this routine. */
4358 ret_val
= e1000_read_phy_reg(hw
, 0x2F5B, &phy_saved_data
);
4360 /* Disabled the PHY transmitter */
4361 e1000_write_phy_reg(hw
, 0x2F5B, 0x0003);
4365 e1000_write_phy_reg(hw
, 0x0000, 0x0140);
4369 switch (hw
->mac_type
) {
4372 e1000_write_phy_reg(hw
, 0x1F95, 0x0001);
4374 e1000_write_phy_reg(hw
, 0x1F71, 0xBD21);
4376 e1000_write_phy_reg(hw
, 0x1F79, 0x0018);
4378 e1000_write_phy_reg(hw
, 0x1F30, 0x1600);
4380 e1000_write_phy_reg(hw
, 0x1F31, 0x0014);
4382 e1000_write_phy_reg(hw
, 0x1F32, 0x161C);
4384 e1000_write_phy_reg(hw
, 0x1F94, 0x0003);
4386 e1000_write_phy_reg(hw
, 0x1F96, 0x003F);
4388 e1000_write_phy_reg(hw
, 0x2010, 0x0008);
4391 case e1000_82541_rev_2
:
4392 case e1000_82547_rev_2
:
4393 e1000_write_phy_reg(hw
, 0x1F73, 0x0099);
4399 e1000_write_phy_reg(hw
, 0x0000, 0x3300);
4403 /* Now enable the transmitter */
4405 e1000_write_phy_reg(hw
, 0x2F5B, phy_saved_data
);
4407 if (hw
->mac_type
== e1000_82547
) {
4408 uint16_t fused
, fine
, coarse
;
4410 /* Move to analog registers page */
4411 e1000_read_phy_reg(hw
,
4412 IGP01E1000_ANALOG_SPARE_FUSE_STATUS
, &fused
);
4414 if (!(fused
& IGP01E1000_ANALOG_SPARE_FUSE_ENABLED
)) {
4415 e1000_read_phy_reg(hw
,
4416 IGP01E1000_ANALOG_FUSE_STATUS
, &fused
);
4418 fine
= fused
& IGP01E1000_ANALOG_FUSE_FINE_MASK
;
4420 & IGP01E1000_ANALOG_FUSE_COARSE_MASK
;
4423 IGP01E1000_ANALOG_FUSE_COARSE_THRESH
) {
4425 IGP01E1000_ANALOG_FUSE_COARSE_10
;
4426 fine
-= IGP01E1000_ANALOG_FUSE_FINE_1
;
4428 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH
)
4429 fine
-= IGP01E1000_ANALOG_FUSE_FINE_10
;
4432 & IGP01E1000_ANALOG_FUSE_POLY_MASK
) |
4434 & IGP01E1000_ANALOG_FUSE_FINE_MASK
) |
4436 & IGP01E1000_ANALOG_FUSE_COARSE_MASK
);
4438 e1000_write_phy_reg(hw
,
4439 IGP01E1000_ANALOG_FUSE_CONTROL
, fused
);
4440 e1000_write_phy_reg(hw
,
4441 IGP01E1000_ANALOG_FUSE_BYPASS
,
4442 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL
);
4448 /******************************************************************************
4451 * hw - Struct containing variables accessed by shared code
4453 * Sets bit 15 of the MII Control register
4454 ******************************************************************************/
4456 e1000_phy_reset(struct e1000_hw
*hw
)
4463 /* In the case of the phy reset being blocked, it's not an error, we
4464 * simply return success without performing the reset. */
4465 ret_val
= e1000_check_phy_reset_block(hw
);
4467 return E1000_SUCCESS
;
4469 switch (hw
->phy_type
) {
4471 case e1000_phy_igp_2
:
4472 case e1000_phy_igp_3
:
4474 ret_val
= e1000_phy_hw_reset(hw
);
4479 ret_val
= e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_data
);
4483 phy_data
|= MII_CR_RESET
;
4484 ret_val
= e1000_write_phy_reg(hw
, PHY_CTRL
, phy_data
);
4492 if (hw
->phy_type
== e1000_phy_igp
|| hw
->phy_type
== e1000_phy_igp_2
)
4493 e1000_phy_init_script(hw
);
4495 return E1000_SUCCESS
;
4498 static int e1000_set_phy_type (struct e1000_hw
*hw
)
4502 if (hw
->mac_type
== e1000_undefined
)
4503 return -E1000_ERR_PHY_TYPE
;
4505 switch (hw
->phy_id
) {
4506 case M88E1000_E_PHY_ID
:
4507 case M88E1000_I_PHY_ID
:
4508 case M88E1011_I_PHY_ID
:
4509 case M88E1111_I_PHY_ID
:
4510 hw
->phy_type
= e1000_phy_m88
;
4512 case IGP01E1000_I_PHY_ID
:
4513 if (hw
->mac_type
== e1000_82541
||
4514 hw
->mac_type
== e1000_82541_rev_2
||
4515 hw
->mac_type
== e1000_82547
||
4516 hw
->mac_type
== e1000_82547_rev_2
) {
4517 hw
->phy_type
= e1000_phy_igp
;
4518 hw
->phy_type
= e1000_phy_igp
;
4521 case IGP03E1000_E_PHY_ID
:
4522 hw
->phy_type
= e1000_phy_igp_3
;
4525 case IFE_PLUS_E_PHY_ID
:
4526 case IFE_C_E_PHY_ID
:
4527 hw
->phy_type
= e1000_phy_ife
;
4529 case GG82563_E_PHY_ID
:
4530 if (hw
->mac_type
== e1000_80003es2lan
) {
4531 hw
->phy_type
= e1000_phy_gg82563
;
4534 case BME1000_E_PHY_ID
:
4535 hw
->phy_type
= e1000_phy_bm
;
4539 /* Should never have loaded on this device */
4540 hw
->phy_type
= e1000_phy_undefined
;
4541 return -E1000_ERR_PHY_TYPE
;
4544 return E1000_SUCCESS
;
4547 /******************************************************************************
4548 * Probes the expected PHY address for known PHY IDs
4550 * hw - Struct containing variables accessed by shared code
4551 ******************************************************************************/
4553 e1000_detect_gig_phy(struct e1000_hw
*hw
)
4555 int32_t phy_init_status
, ret_val
;
4556 uint16_t phy_id_high
, phy_id_low
;
4561 /* The 82571 firmware may still be configuring the PHY. In this
4562 * case, we cannot access the PHY until the configuration is done. So
4563 * we explicitly set the PHY values. */
4564 if (hw
->mac_type
== e1000_82571
||
4565 hw
->mac_type
== e1000_82572
) {
4566 hw
->phy_id
= IGP01E1000_I_PHY_ID
;
4567 hw
->phy_type
= e1000_phy_igp_2
;
4568 return E1000_SUCCESS
;
4571 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
4572 * work- around that forces PHY page 0 to be set or the reads fail.
4573 * The rest of the code in this routine uses e1000_read_phy_reg to
4574 * read the PHY ID. So for ESB-2 we need to have this set so our
4575 * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
4576 * the routines below will figure this out as well. */
4577 if (hw
->mac_type
== e1000_80003es2lan
)
4578 hw
->phy_type
= e1000_phy_gg82563
;
4580 /* Read the PHY ID Registers to identify which PHY is onboard. */
4581 ret_val
= e1000_read_phy_reg(hw
, PHY_ID1
, &phy_id_high
);
4585 hw
->phy_id
= (uint32_t) (phy_id_high
<< 16);
4587 ret_val
= e1000_read_phy_reg(hw
, PHY_ID2
, &phy_id_low
);
4591 hw
->phy_id
|= (uint32_t) (phy_id_low
& PHY_REVISION_MASK
);
4592 hw
->phy_revision
= (uint32_t) phy_id_low
& ~PHY_REVISION_MASK
;
4594 switch (hw
->mac_type
) {
4596 if (hw
->phy_id
== M88E1000_E_PHY_ID
)
4600 if (hw
->phy_id
== M88E1000_I_PHY_ID
)
4605 case e1000_82545_rev_3
:
4607 case e1000_82546_rev_3
:
4608 if (hw
->phy_id
== M88E1011_I_PHY_ID
)
4612 case e1000_82541_rev_2
:
4614 case e1000_82547_rev_2
:
4615 if(hw
->phy_id
== IGP01E1000_I_PHY_ID
)
4620 if (hw
->phy_id
== M88E1111_I_PHY_ID
)
4624 if (hw
->phy_id
== BME1000_E_PHY_ID
)
4627 case e1000_80003es2lan
:
4628 if (hw
->phy_id
== GG82563_E_PHY_ID
)
4632 if (hw
->phy_id
== IGP03E1000_E_PHY_ID
)
4634 if (hw
->phy_id
== IFE_E_PHY_ID
)
4636 if (hw
->phy_id
== IFE_PLUS_E_PHY_ID
)
4638 if (hw
->phy_id
== IFE_C_E_PHY_ID
)
4642 DEBUGOUT("Invalid MAC type %d\n", hw
->mac_type
);
4643 return -E1000_ERR_CONFIG
;
4646 phy_init_status
= e1000_set_phy_type(hw
);
4648 if ((match
) && (phy_init_status
== E1000_SUCCESS
)) {
4649 DEBUGOUT("PHY ID 0x%X detected\n", hw
->phy_id
);
4652 DEBUGOUT("Invalid PHY ID 0x%X\n", hw
->phy_id
);
4653 return -E1000_ERR_PHY
;
4656 /*****************************************************************************
4657 * Set media type and TBI compatibility.
4659 * hw - Struct containing variables accessed by shared code
4660 * **************************************************************************/
4662 e1000_set_media_type(struct e1000_hw
*hw
)
4668 if (hw
->mac_type
!= e1000_82543
) {
4669 /* tbi_compatibility is only valid on 82543 */
4670 hw
->tbi_compatibility_en
= false;
4673 switch (hw
->device_id
) {
4674 case E1000_DEV_ID_82545GM_SERDES
:
4675 case E1000_DEV_ID_82546GB_SERDES
:
4676 case E1000_DEV_ID_82571EB_SERDES
:
4677 case E1000_DEV_ID_82571EB_SERDES_DUAL
:
4678 case E1000_DEV_ID_82571EB_SERDES_QUAD
:
4679 case E1000_DEV_ID_82572EI_SERDES
:
4680 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT
:
4681 hw
->media_type
= e1000_media_type_internal_serdes
;
4684 switch (hw
->mac_type
) {
4685 case e1000_82542_rev2_0
:
4686 case e1000_82542_rev2_1
:
4687 hw
->media_type
= e1000_media_type_fiber
;
4692 /* The STATUS_TBIMODE bit is reserved or reused
4693 * for the this device.
4695 hw
->media_type
= e1000_media_type_copper
;
4698 status
= E1000_READ_REG(hw
, STATUS
);
4699 if (status
& E1000_STATUS_TBIMODE
) {
4700 hw
->media_type
= e1000_media_type_fiber
;
4701 /* tbi_compatibility not valid on fiber */
4702 hw
->tbi_compatibility_en
= false;
4704 hw
->media_type
= e1000_media_type_copper
;
4712 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4714 * e1000_sw_init initializes the Adapter private data structure.
4715 * Fields are initialized based on PCI device information and
4716 * OS network device settings (MTU size).
4720 e1000_sw_init(struct eth_device
*nic
)
4722 struct e1000_hw
*hw
= (typeof(hw
)) nic
->priv
;
4725 /* PCI config space info */
4726 pci_read_config_word(hw
->pdev
, PCI_VENDOR_ID
, &hw
->vendor_id
);
4727 pci_read_config_word(hw
->pdev
, PCI_DEVICE_ID
, &hw
->device_id
);
4728 pci_read_config_word(hw
->pdev
, PCI_SUBSYSTEM_VENDOR_ID
,
4729 &hw
->subsystem_vendor_id
);
4730 pci_read_config_word(hw
->pdev
, PCI_SUBSYSTEM_ID
, &hw
->subsystem_id
);
4732 pci_read_config_byte(hw
->pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
4733 pci_read_config_word(hw
->pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
4735 /* identify the MAC */
4736 result
= e1000_set_mac_type(hw
);
4738 E1000_ERR(hw
->nic
, "Unknown MAC Type\n");
4742 switch (hw
->mac_type
) {
4747 case e1000_82541_rev_2
:
4748 case e1000_82547_rev_2
:
4749 hw
->phy_init_script
= 1;
4753 /* flow control settings */
4754 hw
->fc_high_water
= E1000_FC_HIGH_THRESH
;
4755 hw
->fc_low_water
= E1000_FC_LOW_THRESH
;
4756 hw
->fc_pause_time
= E1000_FC_PAUSE_TIME
;
4757 hw
->fc_send_xon
= 1;
4759 /* Media type - copper or fiber */
4760 e1000_set_media_type(hw
);
4762 if (hw
->mac_type
>= e1000_82543
) {
4763 uint32_t status
= E1000_READ_REG(hw
, STATUS
);
4765 if (status
& E1000_STATUS_TBIMODE
) {
4766 DEBUGOUT("fiber interface\n");
4767 hw
->media_type
= e1000_media_type_fiber
;
4769 DEBUGOUT("copper interface\n");
4770 hw
->media_type
= e1000_media_type_copper
;
4773 hw
->media_type
= e1000_media_type_fiber
;
4776 hw
->tbi_compatibility_en
= true;
4777 hw
->wait_autoneg_complete
= true;
4778 if (hw
->mac_type
< e1000_82543
)
4779 hw
->report_tx_early
= 0;
4781 hw
->report_tx_early
= 1;
4783 return E1000_SUCCESS
;
4787 fill_rx(struct e1000_hw
*hw
)
4789 struct e1000_rx_desc
*rd
;
4792 rd
= rx_base
+ rx_tail
;
4793 rx_tail
= (rx_tail
+ 1) % 8;
4795 rd
->buffer_addr
= cpu_to_le64((u32
) & packet
);
4796 E1000_WRITE_REG(hw
, RDT
, rx_tail
);
4800 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
4801 * @adapter: board private structure
4803 * Configure the Tx unit of the MAC after a reset.
4807 e1000_configure_tx(struct e1000_hw
*hw
)
4811 unsigned long tipg
, tarc
;
4812 uint32_t ipgr1
, ipgr2
;
4814 ptr
= (u32
) tx_pool
;
4816 ptr
= (ptr
+ 0x10) & (~0xf);
4818 tx_base
= (typeof(tx_base
)) ptr
;
4820 E1000_WRITE_REG(hw
, TDBAL
, (u32
) tx_base
);
4821 E1000_WRITE_REG(hw
, TDBAH
, 0);
4823 E1000_WRITE_REG(hw
, TDLEN
, 128);
4825 /* Setup the HW Tx Head and Tail descriptor pointers */
4826 E1000_WRITE_REG(hw
, TDH
, 0);
4827 E1000_WRITE_REG(hw
, TDT
, 0);
4830 /* Set the default values for the Tx Inter Packet Gap timer */
4831 if (hw
->mac_type
<= e1000_82547_rev_2
&&
4832 (hw
->media_type
== e1000_media_type_fiber
||
4833 hw
->media_type
== e1000_media_type_internal_serdes
))
4834 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
4836 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
4838 /* Set the default values for the Tx Inter Packet Gap timer */
4839 switch (hw
->mac_type
) {
4840 case e1000_82542_rev2_0
:
4841 case e1000_82542_rev2_1
:
4842 tipg
= DEFAULT_82542_TIPG_IPGT
;
4843 ipgr1
= DEFAULT_82542_TIPG_IPGR1
;
4844 ipgr2
= DEFAULT_82542_TIPG_IPGR2
;
4846 case e1000_80003es2lan
:
4847 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
4848 ipgr2
= DEFAULT_80003ES2LAN_TIPG_IPGR2
;
4851 ipgr1
= DEFAULT_82543_TIPG_IPGR1
;
4852 ipgr2
= DEFAULT_82543_TIPG_IPGR2
;
4855 tipg
|= ipgr1
<< E1000_TIPG_IPGR1_SHIFT
;
4856 tipg
|= ipgr2
<< E1000_TIPG_IPGR2_SHIFT
;
4857 E1000_WRITE_REG(hw
, TIPG
, tipg
);
4858 /* Program the Transmit Control Register */
4859 tctl
= E1000_READ_REG(hw
, TCTL
);
4860 tctl
&= ~E1000_TCTL_CT
;
4861 tctl
|= E1000_TCTL_EN
| E1000_TCTL_PSP
|
4862 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
4864 if (hw
->mac_type
== e1000_82571
|| hw
->mac_type
== e1000_82572
) {
4865 tarc
= E1000_READ_REG(hw
, TARC0
);
4866 /* set the speed mode bit, we'll clear it if we're not at
4867 * gigabit link later */
4868 /* git bit can be set to 1*/
4869 } else if (hw
->mac_type
== e1000_80003es2lan
) {
4870 tarc
= E1000_READ_REG(hw
, TARC0
);
4872 E1000_WRITE_REG(hw
, TARC0
, tarc
);
4873 tarc
= E1000_READ_REG(hw
, TARC1
);
4875 E1000_WRITE_REG(hw
, TARC1
, tarc
);
4879 e1000_config_collision_dist(hw
);
4880 /* Setup Transmit Descriptor Settings for eop descriptor */
4881 hw
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_IFCS
;
4883 /* Need to set up RS bit */
4884 if (hw
->mac_type
< e1000_82543
)
4885 hw
->txd_cmd
|= E1000_TXD_CMD_RPS
;
4887 hw
->txd_cmd
|= E1000_TXD_CMD_RS
;
4888 E1000_WRITE_REG(hw
, TCTL
, tctl
);
4892 * e1000_setup_rctl - configure the receive control register
4893 * @adapter: Board private structure
4896 e1000_setup_rctl(struct e1000_hw
*hw
)
4900 rctl
= E1000_READ_REG(hw
, RCTL
);
4902 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
4904 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_LBM_NO
4905 | E1000_RCTL_RDMTS_HALF
; /* |
4906 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
4908 if (hw
->tbi_compatibility_on
== 1)
4909 rctl
|= E1000_RCTL_SBP
;
4911 rctl
&= ~E1000_RCTL_SBP
;
4913 rctl
&= ~(E1000_RCTL_SZ_4096
);
4914 rctl
|= E1000_RCTL_SZ_2048
;
4915 rctl
&= ~(E1000_RCTL_BSEX
| E1000_RCTL_LPE
);
4916 E1000_WRITE_REG(hw
, RCTL
, rctl
);
4920 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
4921 * @adapter: board private structure
4923 * Configure the Rx unit of the MAC after a reset.
4926 e1000_configure_rx(struct e1000_hw
*hw
)
4929 unsigned long rctl
, ctrl_ext
;
4931 /* make sure receives are disabled while setting up the descriptors */
4932 rctl
= E1000_READ_REG(hw
, RCTL
);
4933 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
4934 if (hw
->mac_type
>= e1000_82540
) {
4935 /* Set the interrupt throttling rate. Value is calculated
4936 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
4937 #define MAX_INTS_PER_SEC 8000
4938 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
4939 E1000_WRITE_REG(hw
, ITR
, DEFAULT_ITR
);
4942 if (hw
->mac_type
>= e1000_82571
) {
4943 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
4944 /* Reset delay timers after every interrupt */
4945 ctrl_ext
|= E1000_CTRL_EXT_INT_TIMER_CLR
;
4946 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
4947 E1000_WRITE_FLUSH(hw
);
4949 /* Setup the Base and Length of the Rx Descriptor Ring */
4950 ptr
= (u32
) rx_pool
;
4952 ptr
= (ptr
+ 0x10) & (~0xf);
4953 rx_base
= (typeof(rx_base
)) ptr
;
4954 E1000_WRITE_REG(hw
, RDBAL
, (u32
) rx_base
);
4955 E1000_WRITE_REG(hw
, RDBAH
, 0);
4957 E1000_WRITE_REG(hw
, RDLEN
, 128);
4959 /* Setup the HW Rx Head and Tail Descriptor Pointers */
4960 E1000_WRITE_REG(hw
, RDH
, 0);
4961 E1000_WRITE_REG(hw
, RDT
, 0);
4962 /* Enable Receives */
4964 E1000_WRITE_REG(hw
, RCTL
, rctl
);
4968 /**************************************************************************
4969 POLL - Wait for a frame
4970 ***************************************************************************/
4972 e1000_poll(struct eth_device
*nic
)
4974 struct e1000_hw
*hw
= nic
->priv
;
4975 struct e1000_rx_desc
*rd
;
4976 /* return true if there's an ethernet packet ready to read */
4977 rd
= rx_base
+ rx_last
;
4978 if (!(le32_to_cpu(rd
->status
)) & E1000_RXD_STAT_DD
)
4980 /*DEBUGOUT("recv: packet len=%d \n", rd->length); */
4981 NetReceive((uchar
*)packet
, le32_to_cpu(rd
->length
));
4986 /**************************************************************************
4987 TRANSMIT - Transmit a frame
4988 ***************************************************************************/
4989 static int e1000_transmit(struct eth_device
*nic
, void *packet
, int length
)
4991 void *nv_packet
= (void *)packet
;
4992 struct e1000_hw
*hw
= nic
->priv
;
4993 struct e1000_tx_desc
*txp
;
4996 txp
= tx_base
+ tx_tail
;
4997 tx_tail
= (tx_tail
+ 1) % 8;
4999 txp
->buffer_addr
= cpu_to_le64(virt_to_bus(hw
->pdev
, nv_packet
));
5000 txp
->lower
.data
= cpu_to_le32(hw
->txd_cmd
| length
);
5001 txp
->upper
.data
= 0;
5002 E1000_WRITE_REG(hw
, TDT
, tx_tail
);
5004 E1000_WRITE_FLUSH(hw
);
5005 while (!(le32_to_cpu(txp
->upper
.data
) & E1000_TXD_STAT_DD
)) {
5006 if (i
++ > TOUT_LOOP
) {
5007 DEBUGOUT("e1000: tx timeout\n");
5010 udelay(10); /* give the nic a chance to write to the register */
5017 e1000_reset(struct eth_device
*nic
)
5019 struct e1000_hw
*hw
= nic
->priv
;
5022 if (hw
->mac_type
>= e1000_82544
) {
5023 E1000_WRITE_REG(hw
, WUC
, 0);
5025 return e1000_init_hw(nic
);
5028 /**************************************************************************
5029 DISABLE - Turn off ethernet interface
5030 ***************************************************************************/
5032 e1000_disable(struct eth_device
*nic
)
5034 struct e1000_hw
*hw
= nic
->priv
;
5036 /* Turn off the ethernet interface */
5037 E1000_WRITE_REG(hw
, RCTL
, 0);
5038 E1000_WRITE_REG(hw
, TCTL
, 0);
5040 /* Clear the transmit ring */
5041 E1000_WRITE_REG(hw
, TDH
, 0);
5042 E1000_WRITE_REG(hw
, TDT
, 0);
5044 /* Clear the receive ring */
5045 E1000_WRITE_REG(hw
, RDH
, 0);
5046 E1000_WRITE_REG(hw
, RDT
, 0);
5048 /* put the card in its initial state */
5050 E1000_WRITE_REG(hw
, CTRL
, E1000_CTRL_RST
);
5056 /**************************************************************************
5057 INIT - set up ethernet interface(s)
5058 ***************************************************************************/
5060 e1000_init(struct eth_device
*nic
, bd_t
* bis
)
5062 struct e1000_hw
*hw
= nic
->priv
;
5065 ret_val
= e1000_reset(nic
);
5067 if ((ret_val
== -E1000_ERR_NOLINK
) ||
5068 (ret_val
== -E1000_ERR_TIMEOUT
)) {
5069 E1000_ERR(hw
->nic
, "Valid Link not detected\n");
5071 E1000_ERR(hw
->nic
, "Hardware Initialization Failed\n");
5075 e1000_configure_tx(hw
);
5076 e1000_setup_rctl(hw
);
5077 e1000_configure_rx(hw
);
5081 /******************************************************************************
5082 * Gets the current PCI bus type of hardware
5084 * hw - Struct containing variables accessed by shared code
5085 *****************************************************************************/
5086 void e1000_get_bus_type(struct e1000_hw
*hw
)
5090 switch (hw
->mac_type
) {
5091 case e1000_82542_rev2_0
:
5092 case e1000_82542_rev2_1
:
5093 hw
->bus_type
= e1000_bus_type_pci
;
5099 case e1000_80003es2lan
:
5100 hw
->bus_type
= e1000_bus_type_pci_express
;
5103 hw
->bus_type
= e1000_bus_type_pci_express
;
5106 status
= E1000_READ_REG(hw
, STATUS
);
5107 hw
->bus_type
= (status
& E1000_STATUS_PCIX_MODE
) ?
5108 e1000_bus_type_pcix
: e1000_bus_type_pci
;
5113 /* A list of all registered e1000 devices */
5114 static LIST_HEAD(e1000_hw_list
);
5116 /**************************************************************************
5117 PROBE - Look for an adapter, this routine's visible to the outside
5118 You should omit the last argument struct pci_device * for a non-PCI NIC
5119 ***************************************************************************/
5121 e1000_initialize(bd_t
* bis
)
5128 /* Find and probe all the matching PCI devices */
5129 for (i
= 0; (devno
= pci_find_devices(e1000_supported
, i
)) >= 0; i
++) {
5133 * These will never get freed due to errors, this allows us to
5134 * perform SPI EEPROM programming from U-boot, for example.
5136 struct eth_device
*nic
= malloc(sizeof(*nic
));
5137 struct e1000_hw
*hw
= malloc(sizeof(*hw
));
5139 printf("e1000#%u: Out of Memory!\n", i
);
5145 /* Make sure all of the fields are initially zeroed */
5146 memset(nic
, 0, sizeof(*nic
));
5147 memset(hw
, 0, sizeof(*hw
));
5149 /* Assign the passed-in values */
5155 /* Generate a card name */
5156 sprintf(nic
->name
, "e1000#%u", hw
->cardnum
);
5158 /* Print a debug message with the IO base address */
5159 pci_read_config_dword(devno
, PCI_BASE_ADDRESS_0
, &val
);
5160 E1000_DBG(nic
, "iobase 0x%08x\n", val
& 0xfffffff0);
5162 /* Try to enable I/O accesses and bus-mastering */
5163 val
= PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
;
5164 pci_write_config_dword(devno
, PCI_COMMAND
, val
);
5166 /* Make sure it worked */
5167 pci_read_config_dword(devno
, PCI_COMMAND
, &val
);
5168 if (!(val
& PCI_COMMAND_MEMORY
)) {
5169 E1000_ERR(nic
, "Can't enable I/O memory\n");
5172 if (!(val
& PCI_COMMAND_MASTER
)) {
5173 E1000_ERR(nic
, "Can't enable bus-mastering\n");
5177 /* Are these variables needed? */
5178 hw
->fc
= e1000_fc_default
;
5179 hw
->original_fc
= e1000_fc_default
;
5180 hw
->autoneg_failed
= 0;
5182 hw
->get_link_status
= true;
5183 hw
->hw_addr
= pci_map_bar(devno
, PCI_BASE_ADDRESS_0
,
5185 hw
->mac_type
= e1000_undefined
;
5187 /* MAC and Phy settings */
5188 if (e1000_sw_init(nic
) < 0) {
5189 E1000_ERR(nic
, "Software init failed\n");
5192 if (e1000_check_phy_reset_block(hw
))
5193 E1000_ERR(nic
, "PHY Reset is blocked!\n");
5195 /* Basic init was OK, reset the hardware and allow SPI access */
5197 list_add_tail(&hw
->list_node
, &e1000_hw_list
);
5199 /* Validate the EEPROM and get chipset information */
5200 #if !defined(CONFIG_MVBC_1G)
5201 if (e1000_init_eeprom_params(hw
)) {
5202 E1000_ERR(nic
, "EEPROM is invalid!\n");
5205 if (e1000_validate_eeprom_checksum(hw
))
5208 e1000_read_mac_addr(nic
);
5209 e1000_get_bus_type(hw
);
5211 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
5212 nic
->enetaddr
[0], nic
->enetaddr
[1], nic
->enetaddr
[2],
5213 nic
->enetaddr
[3], nic
->enetaddr
[4], nic
->enetaddr
[5]);
5215 /* Set up the function pointers and register the device */
5216 nic
->init
= e1000_init
;
5217 nic
->recv
= e1000_poll
;
5218 nic
->send
= e1000_transmit
;
5219 nic
->halt
= e1000_disable
;
5226 struct e1000_hw
*e1000_find_card(unsigned int cardnum
)
5228 struct e1000_hw
*hw
;
5230 list_for_each_entry(hw
, &e1000_hw_list
, list_node
)
5231 if (hw
->cardnum
== cardnum
)
5237 #ifdef CONFIG_CMD_E1000
5238 static int do_e1000(cmd_tbl_t
*cmdtp
, int flag
,
5239 int argc
, char * const argv
[])
5241 struct e1000_hw
*hw
;
5248 /* Make sure we can find the requested e1000 card */
5249 hw
= e1000_find_card(simple_strtoul(argv
[1], NULL
, 10));
5251 printf("e1000: ERROR: No such device: e1000#%s\n", argv
[1]);
5255 if (!strcmp(argv
[2], "print-mac-address")) {
5256 unsigned char *mac
= hw
->nic
->enetaddr
;
5257 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5258 mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5]);
5262 #ifdef CONFIG_E1000_SPI
5263 /* Handle the "SPI" subcommand */
5264 if (!strcmp(argv
[2], "spi"))
5265 return do_e1000_spi(cmdtp
, hw
, argc
- 3, argv
+ 3);
5273 e1000
, 7, 0, do_e1000
,
5274 "Intel e1000 controller management",
5275 /* */"<card#> print-mac-address\n"
5276 #ifdef CONFIG_E1000_SPI
5277 "e1000 <card#> spi show [<offset> [<length>]]\n"
5278 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5279 "e1000 <card#> spi program <addr> <offset> <length>\n"
5280 "e1000 <card#> spi checksum [update]\n"
5282 " - Manage the Intel E1000 PCI device"
5284 #endif /* not CONFIG_CMD_E1000 */