1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * 82540EM Gigabit Ethernet Controller
31 * 82540EP Gigabit Ethernet Controller
32 * 82545EM Gigabit Ethernet Controller (Copper)
33 * 82545EM Gigabit Ethernet Controller (Fiber)
34 * 82545GM Gigabit Ethernet Controller
35 * 82546EB Gigabit Ethernet Controller (Copper)
36 * 82546EB Gigabit Ethernet Controller (Fiber)
37 * 82546GB Gigabit Ethernet Controller
40 #include "e1000_api.h"
42 static s32
e1000_init_phy_params_82540(struct e1000_hw
*hw
);
43 static s32
e1000_init_nvm_params_82540(struct e1000_hw
*hw
);
44 static s32
e1000_init_mac_params_82540(struct e1000_hw
*hw
);
45 static s32
e1000_adjust_serdes_amplitude_82540(struct e1000_hw
*hw
);
46 static void e1000_clear_hw_cntrs_82540(struct e1000_hw
*hw
);
47 static s32
e1000_init_hw_82540(struct e1000_hw
*hw
);
48 static s32
e1000_reset_hw_82540(struct e1000_hw
*hw
);
49 static s32
e1000_set_phy_mode_82540(struct e1000_hw
*hw
);
50 static s32
e1000_set_vco_speed_82540(struct e1000_hw
*hw
);
51 static s32
e1000_setup_copper_link_82540(struct e1000_hw
*hw
);
52 static s32
e1000_setup_fiber_serdes_link_82540(struct e1000_hw
*hw
);
53 static void e1000_power_down_phy_copper_82540(struct e1000_hw
*hw
);
56 * e1000_init_phy_params_82540 - Init PHY func ptrs.
57 * @hw: pointer to the HW structure
59 static s32
e1000_init_phy_params_82540(struct e1000_hw
*hw
)
61 struct e1000_phy_info
*phy
= &hw
->phy
;
62 s32 ret_val
= E1000_SUCCESS
;
65 phy
->autoneg_mask
= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
66 phy
->reset_delay_us
= 10000;
67 phy
->type
= e1000_phy_m88
;
69 /* Function Pointers */
70 phy
->ops
.check_polarity
= e1000_check_polarity_m88
;
71 phy
->ops
.commit
= e1000_phy_sw_reset_generic
;
72 phy
->ops
.force_speed_duplex
= e1000_phy_force_speed_duplex_m88
;
73 phy
->ops
.get_cable_length
= e1000_get_cable_length_m88
;
74 phy
->ops
.get_cfg_done
= e1000_get_cfg_done_generic
;
75 phy
->ops
.read_reg
= e1000_read_phy_reg_m88
;
76 phy
->ops
.reset
= e1000_phy_hw_reset_generic
;
77 phy
->ops
.write_reg
= e1000_write_phy_reg_m88
;
78 phy
->ops
.get_info
= e1000_get_phy_info_m88
;
79 phy
->ops
.power_up
= e1000_power_up_phy_copper
;
80 phy
->ops
.power_down
= e1000_power_down_phy_copper_82540
;
82 ret_val
= e1000_get_phy_id(hw
);
87 switch (hw
->mac
.type
) {
90 case e1000_82545_rev_3
:
92 case e1000_82546_rev_3
:
93 if (phy
->id
== M88E1011_I_PHY_ID
)
97 ret_val
= -E1000_ERR_PHY
;
107 * e1000_init_nvm_params_82540 - Init NVM func ptrs.
108 * @hw: pointer to the HW structure
110 static s32
e1000_init_nvm_params_82540(struct e1000_hw
*hw
)
112 struct e1000_nvm_info
*nvm
= &hw
->nvm
;
113 u32 eecd
= E1000_READ_REG(hw
, E1000_EECD
);
115 DEBUGFUNC("e1000_init_nvm_params_82540");
117 nvm
->type
= e1000_nvm_eeprom_microwire
;
118 nvm
->delay_usec
= 50;
119 nvm
->opcode_bits
= 3;
120 switch (nvm
->override
) {
121 case e1000_nvm_override_microwire_large
:
122 nvm
->address_bits
= 8;
123 nvm
->word_size
= 256;
125 case e1000_nvm_override_microwire_small
:
126 nvm
->address_bits
= 6;
130 nvm
->address_bits
= eecd
& E1000_EECD_SIZE
? 8 : 6;
131 nvm
->word_size
= eecd
& E1000_EECD_SIZE
? 256 : 64;
135 /* Function Pointers */
136 nvm
->ops
.acquire
= e1000_acquire_nvm_generic
;
137 nvm
->ops
.read
= e1000_read_nvm_microwire
;
138 nvm
->ops
.release
= e1000_release_nvm_generic
;
139 nvm
->ops
.update
= e1000_update_nvm_checksum_generic
;
140 nvm
->ops
.valid_led_default
= e1000_valid_led_default_generic
;
141 nvm
->ops
.validate
= e1000_validate_nvm_checksum_generic
;
142 nvm
->ops
.write
= e1000_write_nvm_microwire
;
144 return E1000_SUCCESS
;
148 * e1000_init_mac_params_82540 - Init MAC func ptrs.
149 * @hw: pointer to the HW structure
151 static s32
e1000_init_mac_params_82540(struct e1000_hw
*hw
)
153 struct e1000_mac_info
*mac
= &hw
->mac
;
154 s32 ret_val
= E1000_SUCCESS
;
156 DEBUGFUNC("e1000_init_mac_params_82540");
159 switch (hw
->device_id
) {
160 case E1000_DEV_ID_82545EM_FIBER
:
161 case E1000_DEV_ID_82545GM_FIBER
:
162 case E1000_DEV_ID_82546EB_FIBER
:
163 case E1000_DEV_ID_82546GB_FIBER
:
164 hw
->phy
.media_type
= e1000_media_type_fiber
;
166 case E1000_DEV_ID_82545GM_SERDES
:
167 case E1000_DEV_ID_82546GB_SERDES
:
168 hw
->phy
.media_type
= e1000_media_type_internal_serdes
;
171 hw
->phy
.media_type
= e1000_media_type_copper
;
175 /* Set mta register count */
176 mac
->mta_reg_count
= 128;
177 /* Set rar entry count */
178 mac
->rar_entry_count
= E1000_RAR_ENTRIES
;
180 /* Function pointers */
182 /* bus type/speed/width */
183 mac
->ops
.get_bus_info
= e1000_get_bus_info_pci_generic
;
185 mac
->ops
.set_lan_id
= e1000_set_lan_id_multi_port_pci
;
187 mac
->ops
.reset_hw
= e1000_reset_hw_82540
;
188 /* hw initialization */
189 mac
->ops
.init_hw
= e1000_init_hw_82540
;
191 mac
->ops
.setup_link
= e1000_setup_link_generic
;
192 /* physical interface setup */
193 mac
->ops
.setup_physical_interface
=
194 (hw
->phy
.media_type
== e1000_media_type_copper
)
195 ? e1000_setup_copper_link_82540
196 : e1000_setup_fiber_serdes_link_82540
;
198 switch (hw
->phy
.media_type
) {
199 case e1000_media_type_copper
:
200 mac
->ops
.check_for_link
= e1000_check_for_copper_link_generic
;
202 case e1000_media_type_fiber
:
203 mac
->ops
.check_for_link
= e1000_check_for_fiber_link_generic
;
205 case e1000_media_type_internal_serdes
:
206 mac
->ops
.check_for_link
= e1000_check_for_serdes_link_generic
;
209 ret_val
= -E1000_ERR_CONFIG
;
214 mac
->ops
.get_link_up_info
=
215 (hw
->phy
.media_type
== e1000_media_type_copper
)
216 ? e1000_get_speed_and_duplex_copper_generic
217 : e1000_get_speed_and_duplex_fiber_serdes_generic
;
218 /* multicast address update */
219 mac
->ops
.update_mc_addr_list
= e1000_update_mc_addr_list_generic
;
221 mac
->ops
.write_vfta
= e1000_write_vfta_generic
;
223 mac
->ops
.clear_vfta
= e1000_clear_vfta_generic
;
225 mac
->ops
.mta_set
= e1000_mta_set_generic
;
227 mac
->ops
.id_led_init
= e1000_id_led_init_generic
;
229 mac
->ops
.setup_led
= e1000_setup_led_generic
;
231 mac
->ops
.cleanup_led
= e1000_cleanup_led_generic
;
232 /* turn on/off LED */
233 mac
->ops
.led_on
= e1000_led_on_generic
;
234 mac
->ops
.led_off
= e1000_led_off_generic
;
235 /* clear hardware counters */
236 mac
->ops
.clear_hw_cntrs
= e1000_clear_hw_cntrs_82540
;
243 * e1000_init_function_pointers_82540 - Init func ptrs.
244 * @hw: pointer to the HW structure
246 * Called to initialize all function pointers and parameters.
248 void e1000_init_function_pointers_82540(struct e1000_hw
*hw
)
250 DEBUGFUNC("e1000_init_function_pointers_82540");
252 hw
->mac
.ops
.init_params
= e1000_init_mac_params_82540
;
253 hw
->nvm
.ops
.init_params
= e1000_init_nvm_params_82540
;
254 hw
->phy
.ops
.init_params
= e1000_init_phy_params_82540
;
258 * e1000_reset_hw_82540 - Reset hardware
259 * @hw: pointer to the HW structure
261 * This resets the hardware into a known state.
263 static s32
e1000_reset_hw_82540(struct e1000_hw
*hw
)
266 s32 ret_val
= E1000_SUCCESS
;
268 DEBUGFUNC("e1000_reset_hw_82540");
270 DEBUGOUT("Masking off all interrupts\n");
271 E1000_WRITE_REG(hw
, E1000_IMC
, 0xFFFFFFFF);
273 E1000_WRITE_REG(hw
, E1000_RCTL
, 0);
274 E1000_WRITE_REG(hw
, E1000_TCTL
, E1000_TCTL_PSP
);
275 E1000_WRITE_FLUSH(hw
);
278 * Delay to allow any outstanding PCI transactions to complete
279 * before resetting the device.
283 ctrl
= E1000_READ_REG(hw
, E1000_CTRL
);
285 DEBUGOUT("Issuing a global reset to 82540/82545/82546 MAC\n");
286 switch (hw
->mac
.type
) {
287 case e1000_82545_rev_3
:
288 case e1000_82546_rev_3
:
289 E1000_WRITE_REG(hw
, E1000_CTRL_DUP
, ctrl
| E1000_CTRL_RST
);
293 * These controllers can't ack the 64-bit write when
294 * issuing the reset, so we use IO-mapping as a
295 * workaround to issue the reset.
297 E1000_WRITE_REG_IO(hw
, E1000_CTRL
, ctrl
| E1000_CTRL_RST
);
301 /* Wait for EEPROM reload */
304 /* Disable HW ARPs on ASF enabled adapters */
305 manc
= E1000_READ_REG(hw
, E1000_MANC
);
306 manc
&= ~E1000_MANC_ARP_EN
;
307 E1000_WRITE_REG(hw
, E1000_MANC
, manc
);
309 E1000_WRITE_REG(hw
, E1000_IMC
, 0xffffffff);
310 E1000_READ_REG(hw
, E1000_ICR
);
316 * e1000_init_hw_82540 - Initialize hardware
317 * @hw: pointer to the HW structure
319 * This inits the hardware readying it for operation.
321 static s32
e1000_init_hw_82540(struct e1000_hw
*hw
)
323 struct e1000_mac_info
*mac
= &hw
->mac
;
324 u32 txdctl
, ctrl_ext
;
325 s32 ret_val
= E1000_SUCCESS
;
328 DEBUGFUNC("e1000_init_hw_82540");
330 /* Initialize identification LED */
331 ret_val
= mac
->ops
.id_led_init(hw
);
333 DEBUGOUT("Error initializing identification LED\n");
334 /* This is not fatal and we should not stop init due to this */
337 /* Disabling VLAN filtering */
338 DEBUGOUT("Initializing the IEEE VLAN\n");
339 if (mac
->type
< e1000_82545_rev_3
)
340 E1000_WRITE_REG(hw
, E1000_VET
, 0);
342 mac
->ops
.clear_vfta(hw
);
344 /* Setup the receive address. */
345 e1000_init_rx_addrs_generic(hw
, mac
->rar_entry_count
);
347 /* Zero out the Multicast HASH table */
348 DEBUGOUT("Zeroing the MTA\n");
349 for (i
= 0; i
< mac
->mta_reg_count
; i
++) {
350 E1000_WRITE_REG_ARRAY(hw
, E1000_MTA
, i
, 0);
352 * Avoid back to back register writes by adding the register
353 * read (flush). This is to protect against some strange
354 * bridge configurations that may issue Memory Write Block
355 * (MWB) to our register space. The *_rev_3 hardware at
356 * least doesn't respond correctly to every other dword in an
357 * MWB to our register space.
359 E1000_WRITE_FLUSH(hw
);
362 if (mac
->type
< e1000_82545_rev_3
)
363 e1000_pcix_mmrbc_workaround_generic(hw
);
365 /* Setup link and flow control */
366 ret_val
= mac
->ops
.setup_link(hw
);
368 txdctl
= E1000_READ_REG(hw
, E1000_TXDCTL(0));
369 txdctl
= (txdctl
& ~E1000_TXDCTL_WTHRESH
) |
370 E1000_TXDCTL_FULL_TX_DESC_WB
;
371 E1000_WRITE_REG(hw
, E1000_TXDCTL(0), txdctl
);
374 * Clear all of the statistics registers (clear on read). It is
375 * important that we do this after we have tried to establish link
376 * because the symbol error count will increment wildly if there
379 e1000_clear_hw_cntrs_82540(hw
);
381 if ((hw
->device_id
== E1000_DEV_ID_82546GB_QUAD_COPPER
) ||
382 (hw
->device_id
== E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3
)) {
383 ctrl_ext
= E1000_READ_REG(hw
, E1000_CTRL_EXT
);
385 * Relaxed ordering must be disabled to avoid a parity
386 * error crash in a PCI slot.
388 ctrl_ext
|= E1000_CTRL_EXT_RO_DIS
;
389 E1000_WRITE_REG(hw
, E1000_CTRL_EXT
, ctrl_ext
);
396 * e1000_setup_copper_link_82540 - Configure copper link settings
397 * @hw: pointer to the HW structure
399 * Calls the appropriate function to configure the link for auto-neg or forced
400 * speed and duplex. Then we check for link, once link is established calls
401 * to configure collision distance and flow control are called. If link is
402 * not established, we return -E1000_ERR_PHY (-2).
404 static s32
e1000_setup_copper_link_82540(struct e1000_hw
*hw
)
407 s32 ret_val
= E1000_SUCCESS
;
410 DEBUGFUNC("e1000_setup_copper_link_82540");
412 ctrl
= E1000_READ_REG(hw
, E1000_CTRL
);
413 ctrl
|= E1000_CTRL_SLU
;
414 ctrl
&= ~(E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
415 E1000_WRITE_REG(hw
, E1000_CTRL
, ctrl
);
417 ret_val
= e1000_set_phy_mode_82540(hw
);
421 if (hw
->mac
.type
== e1000_82545_rev_3
||
422 hw
->mac
.type
== e1000_82546_rev_3
) {
423 ret_val
= hw
->phy
.ops
.read_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &data
);
427 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_SPEC_CTRL
, data
);
432 ret_val
= e1000_copper_link_setup_m88(hw
);
436 ret_val
= e1000_setup_copper_link_generic(hw
);
443 * e1000_setup_fiber_serdes_link_82540 - Setup link for fiber/serdes
444 * @hw: pointer to the HW structure
446 * Set the output amplitude to the value in the EEPROM and adjust the VCO
447 * speed to improve Bit Error Rate (BER) performance. Configures collision
448 * distance and flow control for fiber and serdes links. Upon successful
449 * setup, poll for link.
451 static s32
e1000_setup_fiber_serdes_link_82540(struct e1000_hw
*hw
)
453 struct e1000_mac_info
*mac
= &hw
->mac
;
454 s32 ret_val
= E1000_SUCCESS
;
456 DEBUGFUNC("e1000_setup_fiber_serdes_link_82540");
459 case e1000_82545_rev_3
:
460 case e1000_82546_rev_3
:
461 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
463 * If we're on serdes media, adjust the output
464 * amplitude to value set in the EEPROM.
466 ret_val
= e1000_adjust_serdes_amplitude_82540(hw
);
470 /* Adjust VCO speed to improve BER performance */
471 ret_val
= e1000_set_vco_speed_82540(hw
);
478 ret_val
= e1000_setup_fiber_serdes_link_generic(hw
);
485 * e1000_adjust_serdes_amplitude_82540 - Adjust amplitude based on EEPROM
486 * @hw: pointer to the HW structure
488 * Adjust the SERDES output amplitude based on the EEPROM settings.
490 static s32
e1000_adjust_serdes_amplitude_82540(struct e1000_hw
*hw
)
492 s32 ret_val
= E1000_SUCCESS
;
495 DEBUGFUNC("e1000_adjust_serdes_amplitude_82540");
497 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_SERDES_AMPLITUDE
, 1, &nvm_data
);
501 if (nvm_data
!= NVM_RESERVED_WORD
) {
502 /* Adjust serdes output amplitude only. */
503 nvm_data
&= NVM_SERDES_AMPLITUDE_MASK
;
504 ret_val
= hw
->phy
.ops
.write_reg(hw
,
505 M88E1000_PHY_EXT_CTRL
,
516 * e1000_set_vco_speed_82540 - Set VCO speed for better performance
517 * @hw: pointer to the HW structure
519 * Set the VCO speed to improve Bit Error Rate (BER) performance.
521 static s32
e1000_set_vco_speed_82540(struct e1000_hw
*hw
)
523 s32 ret_val
= E1000_SUCCESS
;
524 u16 default_page
= 0;
527 DEBUGFUNC("e1000_set_vco_speed_82540");
529 /* Set PHY register 30, page 5, bit 8 to 0 */
531 ret_val
= hw
->phy
.ops
.read_reg(hw
,
532 M88E1000_PHY_PAGE_SELECT
,
537 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x0005);
541 ret_val
= hw
->phy
.ops
.read_reg(hw
, M88E1000_PHY_GEN_CONTROL
, &phy_data
);
545 phy_data
&= ~M88E1000_PHY_VCO_REG_BIT8
;
546 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_GEN_CONTROL
, phy_data
);
550 /* Set PHY register 30, page 4, bit 11 to 1 */
552 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x0004);
556 ret_val
= hw
->phy
.ops
.read_reg(hw
, M88E1000_PHY_GEN_CONTROL
, &phy_data
);
560 phy_data
|= M88E1000_PHY_VCO_REG_BIT11
;
561 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_GEN_CONTROL
, phy_data
);
565 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_PAGE_SELECT
,
573 * e1000_set_phy_mode_82540 - Set PHY to class A mode
574 * @hw: pointer to the HW structure
576 * Sets the PHY to class A mode and assumes the following operations will
577 * follow to enable the new class mode:
578 * 1. Do a PHY soft reset.
579 * 2. Restart auto-negotiation or force link.
581 static s32
e1000_set_phy_mode_82540(struct e1000_hw
*hw
)
583 struct e1000_phy_info
*phy
= &hw
->phy
;
584 s32 ret_val
= E1000_SUCCESS
;
587 DEBUGFUNC("e1000_set_phy_mode_82540");
589 if (hw
->mac
.type
!= e1000_82545_rev_3
)
592 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_PHY_CLASS_WORD
, 1, &nvm_data
);
594 ret_val
= -E1000_ERR_PHY
;
598 if ((nvm_data
!= NVM_RESERVED_WORD
) && (nvm_data
& NVM_PHY_CLASS_A
)) {
599 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_PAGE_SELECT
,
602 ret_val
= -E1000_ERR_PHY
;
605 ret_val
= hw
->phy
.ops
.write_reg(hw
,
606 M88E1000_PHY_GEN_CONTROL
,
609 ret_val
= -E1000_ERR_PHY
;
613 phy
->reset_disable
= false;
621 * e1000_power_down_phy_copper_82540 - Remove link in case of PHY power down
622 * @hw: pointer to the HW structure
624 * In the case of a PHY power down to save power, or to turn off link during a
625 * driver unload, or wake on lan is not enabled, remove the link.
627 static void e1000_power_down_phy_copper_82540(struct e1000_hw
*hw
)
629 /* If the management interface is not enabled, then power down */
630 if (!(E1000_READ_REG(hw
, E1000_MANC
) & E1000_MANC_SMBUS_EN
))
631 e1000_power_down_phy_copper(hw
);
637 * e1000_clear_hw_cntrs_82540 - Clear device specific hardware counters
638 * @hw: pointer to the HW structure
640 * Clears the hardware counters by reading the counter registers.
642 static void e1000_clear_hw_cntrs_82540(struct e1000_hw
*hw
)
644 DEBUGFUNC("e1000_clear_hw_cntrs_82540");
646 e1000_clear_hw_cntrs_base_generic(hw
);
648 E1000_READ_REG(hw
, E1000_PRC64
);
649 E1000_READ_REG(hw
, E1000_PRC127
);
650 E1000_READ_REG(hw
, E1000_PRC255
);
651 E1000_READ_REG(hw
, E1000_PRC511
);
652 E1000_READ_REG(hw
, E1000_PRC1023
);
653 E1000_READ_REG(hw
, E1000_PRC1522
);
654 E1000_READ_REG(hw
, E1000_PTC64
);
655 E1000_READ_REG(hw
, E1000_PTC127
);
656 E1000_READ_REG(hw
, E1000_PTC255
);
657 E1000_READ_REG(hw
, E1000_PTC511
);
658 E1000_READ_REG(hw
, E1000_PTC1023
);
659 E1000_READ_REG(hw
, E1000_PTC1522
);
661 E1000_READ_REG(hw
, E1000_ALGNERRC
);
662 E1000_READ_REG(hw
, E1000_RXERRC
);
663 E1000_READ_REG(hw
, E1000_TNCRS
);
664 E1000_READ_REG(hw
, E1000_CEXTERR
);
665 E1000_READ_REG(hw
, E1000_TSCTC
);
666 E1000_READ_REG(hw
, E1000_TSCTFC
);
668 E1000_READ_REG(hw
, E1000_MGTPRC
);
669 E1000_READ_REG(hw
, E1000_MGTPDC
);
670 E1000_READ_REG(hw
, E1000_MGTPTC
);