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 * 82541EI Gigabit Ethernet Controller
31 * 82541ER Gigabit Ethernet Controller
32 * 82541GI Gigabit Ethernet Controller
33 * 82541PI Gigabit Ethernet Controller
34 * 82547EI Gigabit Ethernet Controller
35 * 82547GI Gigabit Ethernet Controller
38 #include "e1000_api.h"
40 static s32
e1000_init_phy_params_82541(struct e1000_hw
*hw
);
41 static s32
e1000_init_nvm_params_82541(struct e1000_hw
*hw
);
42 static s32
e1000_init_mac_params_82541(struct e1000_hw
*hw
);
43 static s32
e1000_reset_hw_82541(struct e1000_hw
*hw
);
44 static s32
e1000_init_hw_82541(struct e1000_hw
*hw
);
45 static s32
e1000_get_link_up_info_82541(struct e1000_hw
*hw
, u16
*speed
,
47 static s32
e1000_phy_hw_reset_82541(struct e1000_hw
*hw
);
48 static s32
e1000_setup_copper_link_82541(struct e1000_hw
*hw
);
49 static s32
e1000_check_for_link_82541(struct e1000_hw
*hw
);
50 static s32
e1000_get_cable_length_igp_82541(struct e1000_hw
*hw
);
51 static s32
e1000_set_d3_lplu_state_82541(struct e1000_hw
*hw
,
53 static s32
e1000_setup_led_82541(struct e1000_hw
*hw
);
54 static s32
e1000_cleanup_led_82541(struct e1000_hw
*hw
);
55 static void e1000_clear_hw_cntrs_82541(struct e1000_hw
*hw
);
56 static s32
e1000_config_dsp_after_link_change_82541(struct e1000_hw
*hw
,
58 static s32
e1000_phy_init_script_82541(struct e1000_hw
*hw
);
59 static void e1000_power_down_phy_copper_82541(struct e1000_hw
*hw
);
61 static const u16 e1000_igp_cable_length_table
[] =
62 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
63 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
64 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
65 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
66 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
67 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
68 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
69 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
70 #define IGP01E1000_AGC_LENGTH_TABLE_SIZE \
71 (sizeof(e1000_igp_cable_length_table) / \
72 sizeof(e1000_igp_cable_length_table[0]))
75 * e1000_init_phy_params_82541 - Init PHY func ptrs.
76 * @hw: pointer to the HW structure
78 static s32
e1000_init_phy_params_82541(struct e1000_hw
*hw
)
80 struct e1000_phy_info
*phy
= &hw
->phy
;
81 s32 ret_val
= E1000_SUCCESS
;
83 DEBUGFUNC("e1000_init_phy_params_82541");
86 phy
->autoneg_mask
= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
87 phy
->reset_delay_us
= 10000;
88 phy
->type
= e1000_phy_igp
;
90 /* Function Pointers */
91 phy
->ops
.check_polarity
= e1000_check_polarity_igp
;
92 phy
->ops
.force_speed_duplex
= e1000_phy_force_speed_duplex_igp
;
93 phy
->ops
.get_cable_length
= e1000_get_cable_length_igp_82541
;
94 phy
->ops
.get_cfg_done
= e1000_get_cfg_done_generic
;
95 phy
->ops
.get_info
= e1000_get_phy_info_igp
;
96 phy
->ops
.read_reg
= e1000_read_phy_reg_igp
;
97 phy
->ops
.reset
= e1000_phy_hw_reset_82541
;
98 phy
->ops
.set_d3_lplu_state
= e1000_set_d3_lplu_state_82541
;
99 phy
->ops
.write_reg
= e1000_write_phy_reg_igp
;
100 phy
->ops
.power_up
= e1000_power_up_phy_copper
;
101 phy
->ops
.power_down
= e1000_power_down_phy_copper_82541
;
103 ret_val
= e1000_get_phy_id(hw
);
108 if (phy
->id
!= IGP01E1000_I_PHY_ID
) {
109 ret_val
= -E1000_ERR_PHY
;
118 * e1000_init_nvm_params_82541 - Init NVM func ptrs.
119 * @hw: pointer to the HW structure
121 static s32
e1000_init_nvm_params_82541(struct e1000_hw
*hw
)
123 struct e1000_nvm_info
*nvm
= &hw
->nvm
;
124 s32 ret_val
= E1000_SUCCESS
;
125 u32 eecd
= E1000_READ_REG(hw
, E1000_EECD
);
128 DEBUGFUNC("e1000_init_nvm_params_82541");
130 switch (nvm
->override
) {
131 case e1000_nvm_override_spi_large
:
132 nvm
->type
= e1000_nvm_eeprom_spi
;
133 eecd
|= E1000_EECD_ADDR_BITS
;
135 case e1000_nvm_override_spi_small
:
136 nvm
->type
= e1000_nvm_eeprom_spi
;
137 eecd
&= ~E1000_EECD_ADDR_BITS
;
139 case e1000_nvm_override_microwire_large
:
140 nvm
->type
= e1000_nvm_eeprom_microwire
;
141 eecd
|= E1000_EECD_SIZE
;
143 case e1000_nvm_override_microwire_small
:
144 nvm
->type
= e1000_nvm_eeprom_microwire
;
145 eecd
&= ~E1000_EECD_SIZE
;
148 nvm
->type
= eecd
& E1000_EECD_TYPE
149 ? e1000_nvm_eeprom_spi
150 : e1000_nvm_eeprom_microwire
;
154 if (nvm
->type
== e1000_nvm_eeprom_spi
) {
155 nvm
->address_bits
= (eecd
& E1000_EECD_ADDR_BITS
)
158 nvm
->opcode_bits
= 8;
159 nvm
->page_size
= (eecd
& E1000_EECD_ADDR_BITS
)
162 /* Function Pointers */
163 nvm
->ops
.acquire
= e1000_acquire_nvm_generic
;
164 nvm
->ops
.read
= e1000_read_nvm_spi
;
165 nvm
->ops
.release
= e1000_release_nvm_generic
;
166 nvm
->ops
.update
= e1000_update_nvm_checksum_generic
;
167 nvm
->ops
.valid_led_default
= e1000_valid_led_default_generic
;
168 nvm
->ops
.validate
= e1000_validate_nvm_checksum_generic
;
169 nvm
->ops
.write
= e1000_write_nvm_spi
;
172 * nvm->word_size must be discovered after the pointers
173 * are set so we can verify the size from the nvm image
174 * itself. Temporarily set it to a dummy value so the
178 ret_val
= nvm
->ops
.read(hw
, NVM_CFG
, 1, &size
);
181 size
= (size
& NVM_SIZE_MASK
) >> NVM_SIZE_SHIFT
;
183 * if size != 0, it can be added to a constant and become
184 * the left-shift value to set the word_size. Otherwise,
185 * word_size stays at 64.
188 size
+= NVM_WORD_SIZE_BASE_SHIFT_82541
;
189 nvm
->word_size
= 1 << size
;
192 nvm
->address_bits
= (eecd
& E1000_EECD_ADDR_BITS
)
194 nvm
->delay_usec
= 50;
195 nvm
->opcode_bits
= 3;
196 nvm
->word_size
= (eecd
& E1000_EECD_ADDR_BITS
)
199 /* Function Pointers */
200 nvm
->ops
.acquire
= e1000_acquire_nvm_generic
;
201 nvm
->ops
.read
= e1000_read_nvm_microwire
;
202 nvm
->ops
.release
= e1000_release_nvm_generic
;
203 nvm
->ops
.update
= e1000_update_nvm_checksum_generic
;
204 nvm
->ops
.valid_led_default
= e1000_valid_led_default_generic
;
205 nvm
->ops
.validate
= e1000_validate_nvm_checksum_generic
;
206 nvm
->ops
.write
= e1000_write_nvm_microwire
;
214 * e1000_init_mac_params_82541 - Init MAC func ptrs.
215 * @hw: pointer to the HW structure
217 static s32
e1000_init_mac_params_82541(struct e1000_hw
*hw
)
219 struct e1000_mac_info
*mac
= &hw
->mac
;
221 DEBUGFUNC("e1000_init_mac_params_82541");
224 hw
->phy
.media_type
= e1000_media_type_copper
;
225 /* Set mta register count */
226 mac
->mta_reg_count
= 128;
227 /* Set rar entry count */
228 mac
->rar_entry_count
= E1000_RAR_ENTRIES
;
229 /* Set if part includes ASF firmware */
230 mac
->asf_firmware_present
= true;
232 /* Function Pointers */
234 /* bus type/speed/width */
235 mac
->ops
.get_bus_info
= e1000_get_bus_info_pci_generic
;
237 mac
->ops
.set_lan_id
= e1000_set_lan_id_single_port
;
239 mac
->ops
.reset_hw
= e1000_reset_hw_82541
;
240 /* hw initialization */
241 mac
->ops
.init_hw
= e1000_init_hw_82541
;
243 mac
->ops
.setup_link
= e1000_setup_link_generic
;
244 /* physical interface link setup */
245 mac
->ops
.setup_physical_interface
= e1000_setup_copper_link_82541
;
247 mac
->ops
.check_for_link
= e1000_check_for_link_82541
;
249 mac
->ops
.get_link_up_info
= e1000_get_link_up_info_82541
;
250 /* multicast address update */
251 mac
->ops
.update_mc_addr_list
= e1000_update_mc_addr_list_generic
;
253 mac
->ops
.write_vfta
= e1000_write_vfta_generic
;
255 mac
->ops
.clear_vfta
= e1000_clear_vfta_generic
;
257 mac
->ops
.mta_set
= e1000_mta_set_generic
;
259 mac
->ops
.id_led_init
= e1000_id_led_init_generic
;
261 mac
->ops
.setup_led
= e1000_setup_led_82541
;
263 mac
->ops
.cleanup_led
= e1000_cleanup_led_82541
;
264 /* turn on/off LED */
265 mac
->ops
.led_on
= e1000_led_on_generic
;
266 mac
->ops
.led_off
= e1000_led_off_generic
;
267 /* clear hardware counters */
268 mac
->ops
.clear_hw_cntrs
= e1000_clear_hw_cntrs_82541
;
270 return E1000_SUCCESS
;
274 * e1000_init_function_pointers_82541 - Init func ptrs.
275 * @hw: pointer to the HW structure
277 * Called to initialize all function pointers and parameters.
279 void e1000_init_function_pointers_82541(struct e1000_hw
*hw
)
281 DEBUGFUNC("e1000_init_function_pointers_82541");
283 hw
->mac
.ops
.init_params
= e1000_init_mac_params_82541
;
284 hw
->nvm
.ops
.init_params
= e1000_init_nvm_params_82541
;
285 hw
->phy
.ops
.init_params
= e1000_init_phy_params_82541
;
289 * e1000_reset_hw_82541 - Reset hardware
290 * @hw: pointer to the HW structure
292 * This resets the hardware into a known state.
294 static s32
e1000_reset_hw_82541(struct e1000_hw
*hw
)
296 u32 ledctl
, ctrl
, manc
;
298 DEBUGFUNC("e1000_reset_hw_82541");
300 DEBUGOUT("Masking off all interrupts\n");
301 E1000_WRITE_REG(hw
, E1000_IMC
, 0xFFFFFFFF);
303 E1000_WRITE_REG(hw
, E1000_RCTL
, 0);
304 E1000_WRITE_REG(hw
, E1000_TCTL
, E1000_TCTL_PSP
);
305 E1000_WRITE_FLUSH(hw
);
308 * Delay to allow any outstanding PCI transactions to complete
309 * before resetting the device.
313 ctrl
= E1000_READ_REG(hw
, E1000_CTRL
);
315 /* Must reset the Phy before resetting the MAC */
316 if ((hw
->mac
.type
== e1000_82541
) || (hw
->mac
.type
== e1000_82547
)) {
317 E1000_WRITE_REG(hw
, E1000_CTRL
, (ctrl
| E1000_CTRL_PHY_RST
));
321 DEBUGOUT("Issuing a global reset to 82541/82547 MAC\n");
322 switch (hw
->mac
.type
) {
324 case e1000_82541_rev_2
:
326 * These controllers can't ack the 64-bit write when
327 * issuing the reset, so we use IO-mapping as a
328 * workaround to issue the reset.
330 E1000_WRITE_REG_IO(hw
, E1000_CTRL
, ctrl
| E1000_CTRL_RST
);
333 E1000_WRITE_REG(hw
, E1000_CTRL
, ctrl
| E1000_CTRL_RST
);
337 /* Wait for NVM reload */
340 /* Disable HW ARPs on ASF enabled adapters */
341 manc
= E1000_READ_REG(hw
, E1000_MANC
);
342 manc
&= ~E1000_MANC_ARP_EN
;
343 E1000_WRITE_REG(hw
, E1000_MANC
, manc
);
345 if ((hw
->mac
.type
== e1000_82541
) || (hw
->mac
.type
== e1000_82547
)) {
346 e1000_phy_init_script_82541(hw
);
348 /* Configure activity LED after Phy reset */
349 ledctl
= E1000_READ_REG(hw
, E1000_LEDCTL
);
350 ledctl
&= IGP_ACTIVITY_LED_MASK
;
351 ledctl
|= (IGP_ACTIVITY_LED_ENABLE
| IGP_LED3_MODE
);
352 E1000_WRITE_REG(hw
, E1000_LEDCTL
, ledctl
);
355 /* Once again, mask the interrupts */
356 DEBUGOUT("Masking off all interrupts\n");
357 E1000_WRITE_REG(hw
, E1000_IMC
, 0xFFFFFFFF);
359 /* Clear any pending interrupt events. */
360 E1000_READ_REG(hw
, E1000_ICR
);
362 return E1000_SUCCESS
;
366 * e1000_init_hw_82541 - Initialize hardware
367 * @hw: pointer to the HW structure
369 * This inits the hardware readying it for operation.
371 static s32
e1000_init_hw_82541(struct e1000_hw
*hw
)
373 struct e1000_mac_info
*mac
= &hw
->mac
;
377 DEBUGFUNC("e1000_init_hw_82541");
379 /* Initialize identification LED */
380 ret_val
= mac
->ops
.id_led_init(hw
);
382 DEBUGOUT("Error initializing identification LED\n");
383 /* This is not fatal and we should not stop init due to this */
386 /* Disabling VLAN filtering */
387 DEBUGOUT("Initializing the IEEE VLAN\n");
388 mac
->ops
.clear_vfta(hw
);
390 /* Setup the receive address. */
391 e1000_init_rx_addrs_generic(hw
, mac
->rar_entry_count
);
393 /* Zero out the Multicast HASH table */
394 DEBUGOUT("Zeroing the MTA\n");
395 for (i
= 0; i
< mac
->mta_reg_count
; i
++) {
396 E1000_WRITE_REG_ARRAY(hw
, E1000_MTA
, i
, 0);
398 * Avoid back to back register writes by adding the register
399 * read (flush). This is to protect against some strange
400 * bridge configurations that may issue Memory Write Block
401 * (MWB) to our register space.
403 E1000_WRITE_FLUSH(hw
);
406 /* Setup link and flow control */
407 ret_val
= mac
->ops
.setup_link(hw
);
409 txdctl
= E1000_READ_REG(hw
, E1000_TXDCTL(0));
410 txdctl
= (txdctl
& ~E1000_TXDCTL_WTHRESH
) |
411 E1000_TXDCTL_FULL_TX_DESC_WB
;
412 E1000_WRITE_REG(hw
, E1000_TXDCTL(0), txdctl
);
415 * Clear all of the statistics registers (clear on read). It is
416 * important that we do this after we have tried to establish link
417 * because the symbol error count will increment wildly if there
420 e1000_clear_hw_cntrs_82541(hw
);
426 * e1000_get_link_up_info_82541 - Report speed and duplex
427 * @hw: pointer to the HW structure
428 * @speed: pointer to speed buffer
429 * @duplex: pointer to duplex buffer
431 * Retrieve the current speed and duplex configuration.
433 static s32
e1000_get_link_up_info_82541(struct e1000_hw
*hw
, u16
*speed
,
436 struct e1000_phy_info
*phy
= &hw
->phy
;
440 DEBUGFUNC("e1000_get_link_up_info_82541");
442 ret_val
= e1000_get_speed_and_duplex_copper_generic(hw
, speed
, duplex
);
446 if (!phy
->speed_downgraded
)
450 * IGP01 PHY may advertise full duplex operation after speed
451 * downgrade even if it is operating at half duplex.
452 * Here we set the duplex settings to match the duplex in the
453 * link partner's capabilities.
455 ret_val
= phy
->ops
.read_reg(hw
, PHY_AUTONEG_EXP
, &data
);
459 if (!(data
& NWAY_ER_LP_NWAY_CAPS
)) {
460 *duplex
= HALF_DUPLEX
;
462 ret_val
= phy
->ops
.read_reg(hw
, PHY_LP_ABILITY
, &data
);
466 if (*speed
== SPEED_100
) {
467 if (!(data
& NWAY_LPAR_100TX_FD_CAPS
))
468 *duplex
= HALF_DUPLEX
;
469 } else if (*speed
== SPEED_10
) {
470 if (!(data
& NWAY_LPAR_10T_FD_CAPS
))
471 *duplex
= HALF_DUPLEX
;
480 * e1000_phy_hw_reset_82541 - PHY hardware reset
481 * @hw: pointer to the HW structure
483 * Verify the reset block is not blocking us from resetting. Acquire
484 * semaphore (if necessary) and read/set/write the device control reset
485 * bit in the PHY. Wait the appropriate delay time for the device to
486 * reset and release the semaphore (if necessary).
488 static s32
e1000_phy_hw_reset_82541(struct e1000_hw
*hw
)
493 DEBUGFUNC("e1000_phy_hw_reset_82541");
495 ret_val
= e1000_phy_hw_reset_generic(hw
);
499 e1000_phy_init_script_82541(hw
);
501 if ((hw
->mac
.type
== e1000_82541
) || (hw
->mac
.type
== e1000_82547
)) {
502 /* Configure activity LED after PHY reset */
503 ledctl
= E1000_READ_REG(hw
, E1000_LEDCTL
);
504 ledctl
&= IGP_ACTIVITY_LED_MASK
;
505 ledctl
|= (IGP_ACTIVITY_LED_ENABLE
| IGP_LED3_MODE
);
506 E1000_WRITE_REG(hw
, E1000_LEDCTL
, ledctl
);
514 * e1000_setup_copper_link_82541 - Configure copper link settings
515 * @hw: pointer to the HW structure
517 * Calls the appropriate function to configure the link for auto-neg or forced
518 * speed and duplex. Then we check for link, once link is established calls
519 * to configure collision distance and flow control are called. If link is
520 * not established, we return -E1000_ERR_PHY (-2).
522 static s32
e1000_setup_copper_link_82541(struct e1000_hw
*hw
)
524 struct e1000_phy_info
*phy
= &hw
->phy
;
525 struct e1000_dev_spec_82541
*dev_spec
= &hw
->dev_spec
._82541
;
529 DEBUGFUNC("e1000_setup_copper_link_82541");
531 ctrl
= E1000_READ_REG(hw
, E1000_CTRL
);
532 ctrl
|= E1000_CTRL_SLU
;
533 ctrl
&= ~(E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
534 E1000_WRITE_REG(hw
, E1000_CTRL
, ctrl
);
536 hw
->phy
.reset_disable
= false;
538 /* Earlier revs of the IGP phy require us to force MDI. */
539 if (hw
->mac
.type
== e1000_82541
|| hw
->mac
.type
== e1000_82547
) {
540 dev_spec
->dsp_config
= e1000_dsp_config_disabled
;
543 dev_spec
->dsp_config
= e1000_dsp_config_enabled
;
546 ret_val
= e1000_copper_link_setup_igp(hw
);
550 if (hw
->mac
.autoneg
) {
551 if (dev_spec
->ffe_config
== e1000_ffe_config_active
)
552 dev_spec
->ffe_config
= e1000_ffe_config_enabled
;
555 /* Configure activity LED after Phy reset */
556 ledctl
= E1000_READ_REG(hw
, E1000_LEDCTL
);
557 ledctl
&= IGP_ACTIVITY_LED_MASK
;
558 ledctl
|= (IGP_ACTIVITY_LED_ENABLE
| IGP_LED3_MODE
);
559 E1000_WRITE_REG(hw
, E1000_LEDCTL
, ledctl
);
561 ret_val
= e1000_setup_copper_link_generic(hw
);
568 * e1000_check_for_link_82541 - Check/Store link connection
569 * @hw: pointer to the HW structure
571 * This checks the link condition of the adapter and stores the
572 * results in the hw->mac structure.
574 static s32
e1000_check_for_link_82541(struct e1000_hw
*hw
)
576 struct e1000_mac_info
*mac
= &hw
->mac
;
580 DEBUGFUNC("e1000_check_for_link_82541");
583 * We only want to go out to the PHY registers to see if Auto-Neg
584 * has completed and/or if our link status has changed. The
585 * get_link_status flag is set upon receiving a Link Status
586 * Change or Rx Sequence Error interrupt.
588 if (!mac
->get_link_status
) {
589 ret_val
= E1000_SUCCESS
;
594 * First we want to see if the MII Status Register reports
595 * link. If so, then we want to get the current speed/duplex
598 ret_val
= e1000_phy_has_link_generic(hw
, 1, 0, &link
);
603 ret_val
= e1000_config_dsp_after_link_change_82541(hw
, false);
604 goto out
; /* No link detected */
607 mac
->get_link_status
= false;
610 * Check if there was DownShift, must be checked
611 * immediately after link-up
613 e1000_check_downshift_generic(hw
);
616 * If we are forcing speed/duplex, then we simply return since
617 * we have already determined whether we have link or not.
620 ret_val
= -E1000_ERR_CONFIG
;
624 ret_val
= e1000_config_dsp_after_link_change_82541(hw
, true);
627 * Auto-Neg is enabled. Auto Speed Detection takes care
628 * of MAC speed/duplex configuration. So we only need to
629 * configure Collision Distance in the MAC.
631 e1000_config_collision_dist_generic(hw
);
634 * Configure Flow Control now that Auto-Neg has completed.
635 * First, we need to restore the desired flow control
636 * settings because we may have had to re-autoneg with a
637 * different link partner.
639 ret_val
= e1000_config_fc_after_link_up_generic(hw
);
641 DEBUGOUT("Error configuring flow control\n");
649 * e1000_config_dsp_after_link_change_82541 - Config DSP after link
650 * @hw: pointer to the HW structure
651 * @link_up: boolean flag for link up status
653 * Return E1000_ERR_PHY when failing to read/write the PHY, else E1000_SUCCESS
656 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
657 * gigabit link is achieved to improve link quality.
659 static s32
e1000_config_dsp_after_link_change_82541(struct e1000_hw
*hw
,
662 struct e1000_phy_info
*phy
= &hw
->phy
;
663 struct e1000_dev_spec_82541
*dev_spec
= &hw
->dev_spec
._82541
;
666 u16 phy_data
, phy_saved_data
, speed
, duplex
, i
;
667 u16 ffe_idle_err_timeout
= FFE_IDLE_ERR_COUNT_TIMEOUT_20
;
668 u16 dsp_reg_array
[IGP01E1000_PHY_CHANNEL_NUM
] =
669 {IGP01E1000_PHY_AGC_PARAM_A
,
670 IGP01E1000_PHY_AGC_PARAM_B
,
671 IGP01E1000_PHY_AGC_PARAM_C
,
672 IGP01E1000_PHY_AGC_PARAM_D
};
674 DEBUGFUNC("e1000_config_dsp_after_link_change_82541");
677 ret_val
= hw
->mac
.ops
.get_link_up_info(hw
, &speed
, &duplex
);
679 DEBUGOUT("Error getting link speed and duplex\n");
683 if (speed
!= SPEED_1000
) {
684 ret_val
= E1000_SUCCESS
;
688 ret_val
= phy
->ops
.get_cable_length(hw
);
692 if ((dev_spec
->dsp_config
== e1000_dsp_config_enabled
) &&
693 phy
->min_cable_length
>= 50) {
695 for (i
= 0; i
< IGP01E1000_PHY_CHANNEL_NUM
; i
++) {
696 ret_val
= phy
->ops
.read_reg(hw
,
702 phy_data
&= ~IGP01E1000_PHY_EDAC_MU_INDEX
;
704 ret_val
= phy
->ops
.write_reg(hw
,
710 dev_spec
->dsp_config
= e1000_dsp_config_activated
;
713 if ((dev_spec
->ffe_config
!= e1000_ffe_config_enabled
) ||
714 (phy
->min_cable_length
>= 50)) {
715 ret_val
= E1000_SUCCESS
;
719 /* clear previous idle error counts */
720 ret_val
= phy
->ops
.read_reg(hw
, PHY_1000T_STATUS
, &phy_data
);
724 for (i
= 0; i
< ffe_idle_err_timeout
; i
++) {
726 ret_val
= phy
->ops
.read_reg(hw
,
732 idle_errs
+= (phy_data
& SR_1000T_IDLE_ERROR_CNT
);
733 if (idle_errs
> SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT
) {
734 dev_spec
->ffe_config
= e1000_ffe_config_active
;
736 ret_val
= phy
->ops
.write_reg(hw
,
737 IGP01E1000_PHY_DSP_FFE
,
738 IGP01E1000_PHY_DSP_FFE_CM_CP
);
745 ffe_idle_err_timeout
=
746 FFE_IDLE_ERR_COUNT_TIMEOUT_100
;
749 if (dev_spec
->dsp_config
== e1000_dsp_config_activated
) {
751 * Save off the current value of register 0x2F5B
752 * to be restored at the end of the routines.
754 ret_val
= phy
->ops
.read_reg(hw
,
760 /* Disable the PHY transmitter */
761 ret_val
= phy
->ops
.write_reg(hw
, 0x2F5B, 0x0003);
767 ret_val
= phy
->ops
.write_reg(hw
,
769 IGP01E1000_IEEE_FORCE_GIG
);
772 for (i
= 0; i
< IGP01E1000_PHY_CHANNEL_NUM
; i
++) {
773 ret_val
= phy
->ops
.read_reg(hw
,
779 phy_data
&= ~IGP01E1000_PHY_EDAC_MU_INDEX
;
780 phy_data
|= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS
;
782 ret_val
= phy
->ops
.write_reg(hw
,
789 ret_val
= phy
->ops
.write_reg(hw
,
791 IGP01E1000_IEEE_RESTART_AUTONEG
);
797 /* Now enable the transmitter */
798 ret_val
= phy
->ops
.write_reg(hw
,
804 dev_spec
->dsp_config
= e1000_dsp_config_enabled
;
807 if (dev_spec
->ffe_config
!= e1000_ffe_config_active
) {
808 ret_val
= E1000_SUCCESS
;
813 * Save off the current value of register 0x2F5B
814 * to be restored at the end of the routines.
816 ret_val
= phy
->ops
.read_reg(hw
, 0x2F5B, &phy_saved_data
);
820 /* Disable the PHY transmitter */
821 ret_val
= phy
->ops
.write_reg(hw
, 0x2F5B, 0x0003);
827 ret_val
= phy
->ops
.write_reg(hw
,
829 IGP01E1000_IEEE_FORCE_GIG
);
833 ret_val
= phy
->ops
.write_reg(hw
,
834 IGP01E1000_PHY_DSP_FFE
,
835 IGP01E1000_PHY_DSP_FFE_DEFAULT
);
839 ret_val
= phy
->ops
.write_reg(hw
,
841 IGP01E1000_IEEE_RESTART_AUTONEG
);
847 /* Now enable the transmitter */
848 ret_val
= phy
->ops
.write_reg(hw
, 0x2F5B, phy_saved_data
);
853 dev_spec
->ffe_config
= e1000_ffe_config_enabled
;
861 * e1000_get_cable_length_igp_82541 - Determine cable length for igp PHY
862 * @hw: pointer to the HW structure
864 * The automatic gain control (agc) normalizes the amplitude of the
865 * received signal, adjusting for the attenuation produced by the
866 * cable. By reading the AGC registers, which represent the
867 * combination of coarse and fine gain value, the value can be put
868 * into a lookup table to obtain the approximate cable length
871 static s32
e1000_get_cable_length_igp_82541(struct e1000_hw
*hw
)
873 struct e1000_phy_info
*phy
= &hw
->phy
;
874 s32 ret_val
= E1000_SUCCESS
;
876 u16 cur_agc_value
, agc_value
= 0;
877 u16 min_agc_value
= IGP01E1000_AGC_LENGTH_TABLE_SIZE
;
878 u16 agc_reg_array
[IGP01E1000_PHY_CHANNEL_NUM
] =
879 {IGP01E1000_PHY_AGC_A
,
880 IGP01E1000_PHY_AGC_B
,
881 IGP01E1000_PHY_AGC_C
,
882 IGP01E1000_PHY_AGC_D
};
884 DEBUGFUNC("e1000_get_cable_length_igp_82541");
886 /* Read the AGC registers for all channels */
887 for (i
= 0; i
< IGP01E1000_PHY_CHANNEL_NUM
; i
++) {
888 ret_val
= phy
->ops
.read_reg(hw
, agc_reg_array
[i
], &data
);
892 cur_agc_value
= data
>> IGP01E1000_AGC_LENGTH_SHIFT
;
894 /* Bounds checking */
895 if ((cur_agc_value
>= IGP01E1000_AGC_LENGTH_TABLE_SIZE
- 1) ||
896 (cur_agc_value
== 0)) {
897 ret_val
= -E1000_ERR_PHY
;
901 agc_value
+= cur_agc_value
;
903 if (min_agc_value
> cur_agc_value
)
904 min_agc_value
= cur_agc_value
;
907 /* Remove the minimal AGC result for length < 50m */
908 if (agc_value
< IGP01E1000_PHY_CHANNEL_NUM
* 50) {
909 agc_value
-= min_agc_value
;
910 /* Average the three remaining channels for the length. */
911 agc_value
/= (IGP01E1000_PHY_CHANNEL_NUM
- 1);
913 /* Average the channels for the length. */
914 agc_value
/= IGP01E1000_PHY_CHANNEL_NUM
;
917 phy
->min_cable_length
= (e1000_igp_cable_length_table
[agc_value
] >
918 IGP01E1000_AGC_RANGE
)
919 ? (e1000_igp_cable_length_table
[agc_value
] -
920 IGP01E1000_AGC_RANGE
)
922 phy
->max_cable_length
= e1000_igp_cable_length_table
[agc_value
] +
923 IGP01E1000_AGC_RANGE
;
925 phy
->cable_length
= (phy
->min_cable_length
+ phy
->max_cable_length
) / 2;
932 * e1000_set_d3_lplu_state_82541 - Sets low power link up state for D3
933 * @hw: pointer to the HW structure
934 * @active: boolean used to enable/disable lplu
936 * Success returns 0, Failure returns 1
938 * The low power link up (lplu) state is set to the power management level D3
939 * and SmartSpeed is disabled when active is true, else clear lplu for D3
940 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
941 * is used during Dx states where the power conservation is most important.
942 * During driver activity, SmartSpeed should be enabled so performance is
945 static s32
e1000_set_d3_lplu_state_82541(struct e1000_hw
*hw
, bool active
)
947 struct e1000_phy_info
*phy
= &hw
->phy
;
951 DEBUGFUNC("e1000_set_d3_lplu_state_82541");
953 switch (hw
->mac
.type
) {
954 case e1000_82541_rev_2
:
955 case e1000_82547_rev_2
:
958 ret_val
= e1000_set_d3_lplu_state_generic(hw
, active
);
963 ret_val
= phy
->ops
.read_reg(hw
, IGP01E1000_GMII_FIFO
, &data
);
968 data
&= ~IGP01E1000_GMII_FLEX_SPD
;
969 ret_val
= phy
->ops
.write_reg(hw
, IGP01E1000_GMII_FIFO
, data
);
974 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
975 * during Dx states where the power conservation is most
976 * important. During driver activity we should enable
977 * SmartSpeed, so performance is maintained.
979 if (phy
->smart_speed
== e1000_smart_speed_on
) {
980 ret_val
= phy
->ops
.read_reg(hw
,
981 IGP01E1000_PHY_PORT_CONFIG
,
986 data
|= IGP01E1000_PSCFR_SMART_SPEED
;
987 ret_val
= phy
->ops
.write_reg(hw
,
988 IGP01E1000_PHY_PORT_CONFIG
,
992 } else if (phy
->smart_speed
== e1000_smart_speed_off
) {
993 ret_val
= phy
->ops
.read_reg(hw
,
994 IGP01E1000_PHY_PORT_CONFIG
,
999 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
1000 ret_val
= phy
->ops
.write_reg(hw
,
1001 IGP01E1000_PHY_PORT_CONFIG
,
1006 } else if ((phy
->autoneg_advertised
== E1000_ALL_SPEED_DUPLEX
) ||
1007 (phy
->autoneg_advertised
== E1000_ALL_NOT_GIG
) ||
1008 (phy
->autoneg_advertised
== E1000_ALL_10_SPEED
)) {
1009 data
|= IGP01E1000_GMII_FLEX_SPD
;
1010 ret_val
= phy
->ops
.write_reg(hw
, IGP01E1000_GMII_FIFO
, data
);
1014 /* When LPLU is enabled, we should disable SmartSpeed */
1015 ret_val
= phy
->ops
.read_reg(hw
,
1016 IGP01E1000_PHY_PORT_CONFIG
,
1021 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
1022 ret_val
= phy
->ops
.write_reg(hw
,
1023 IGP01E1000_PHY_PORT_CONFIG
,
1032 * e1000_setup_led_82541 - Configures SW controllable LED
1033 * @hw: pointer to the HW structure
1035 * This prepares the SW controllable LED for use and saves the current state
1036 * of the LED so it can be later restored.
1038 static s32
e1000_setup_led_82541(struct e1000_hw
*hw
)
1040 struct e1000_dev_spec_82541
*dev_spec
= &hw
->dev_spec
._82541
;
1043 DEBUGFUNC("e1000_setup_led_82541");
1045 ret_val
= hw
->phy
.ops
.read_reg(hw
,
1046 IGP01E1000_GMII_FIFO
,
1047 &dev_spec
->spd_default
);
1051 ret_val
= hw
->phy
.ops
.write_reg(hw
,
1052 IGP01E1000_GMII_FIFO
,
1053 (u16
)(dev_spec
->spd_default
&
1054 ~IGP01E1000_GMII_SPD
));
1058 E1000_WRITE_REG(hw
, E1000_LEDCTL
, hw
->mac
.ledctl_mode1
);
1065 * e1000_cleanup_led_82541 - Set LED config to default operation
1066 * @hw: pointer to the HW structure
1068 * Remove the current LED configuration and set the LED configuration
1069 * to the default value, saved from the EEPROM.
1071 static s32
e1000_cleanup_led_82541(struct e1000_hw
*hw
)
1073 struct e1000_dev_spec_82541
*dev_spec
= &hw
->dev_spec
._82541
;
1076 DEBUGFUNC("e1000_cleanup_led_82541");
1078 ret_val
= hw
->phy
.ops
.write_reg(hw
,
1079 IGP01E1000_GMII_FIFO
,
1080 dev_spec
->spd_default
);
1084 E1000_WRITE_REG(hw
, E1000_LEDCTL
, hw
->mac
.ledctl_default
);
1091 * e1000_phy_init_script_82541 - Initialize GbE PHY
1092 * @hw: pointer to the HW structure
1094 * Initializes the IGP PHY.
1096 static s32
e1000_phy_init_script_82541(struct e1000_hw
*hw
)
1098 struct e1000_dev_spec_82541
*dev_spec
= &hw
->dev_spec
._82541
;
1102 DEBUGFUNC("e1000_phy_init_script_82541");
1104 if (!dev_spec
->phy_init_script
) {
1105 ret_val
= E1000_SUCCESS
;
1109 /* Delay after phy reset to enable NVM configuration to load */
1113 * Save off the current value of register 0x2F5B to be restored at
1114 * the end of this routine.
1116 ret_val
= hw
->phy
.ops
.read_reg(hw
, 0x2F5B, &phy_saved_data
);
1118 /* Disabled the PHY transmitter */
1119 hw
->phy
.ops
.write_reg(hw
, 0x2F5B, 0x0003);
1123 hw
->phy
.ops
.write_reg(hw
, 0x0000, 0x0140);
1127 switch (hw
->mac
.type
) {
1130 hw
->phy
.ops
.write_reg(hw
, 0x1F95, 0x0001);
1132 hw
->phy
.ops
.write_reg(hw
, 0x1F71, 0xBD21);
1134 hw
->phy
.ops
.write_reg(hw
, 0x1F79, 0x0018);
1136 hw
->phy
.ops
.write_reg(hw
, 0x1F30, 0x1600);
1138 hw
->phy
.ops
.write_reg(hw
, 0x1F31, 0x0014);
1140 hw
->phy
.ops
.write_reg(hw
, 0x1F32, 0x161C);
1142 hw
->phy
.ops
.write_reg(hw
, 0x1F94, 0x0003);
1144 hw
->phy
.ops
.write_reg(hw
, 0x1F96, 0x003F);
1146 hw
->phy
.ops
.write_reg(hw
, 0x2010, 0x0008);
1148 case e1000_82541_rev_2
:
1149 case e1000_82547_rev_2
:
1150 hw
->phy
.ops
.write_reg(hw
, 0x1F73, 0x0099);
1156 hw
->phy
.ops
.write_reg(hw
, 0x0000, 0x3300);
1160 /* Now enable the transmitter */
1161 hw
->phy
.ops
.write_reg(hw
, 0x2F5B, phy_saved_data
);
1163 if (hw
->mac
.type
== e1000_82547
) {
1164 u16 fused
, fine
, coarse
;
1166 /* Move to analog registers page */
1167 hw
->phy
.ops
.read_reg(hw
,
1168 IGP01E1000_ANALOG_SPARE_FUSE_STATUS
,
1171 if (!(fused
& IGP01E1000_ANALOG_SPARE_FUSE_ENABLED
)) {
1172 hw
->phy
.ops
.read_reg(hw
,
1173 IGP01E1000_ANALOG_FUSE_STATUS
,
1176 fine
= fused
& IGP01E1000_ANALOG_FUSE_FINE_MASK
;
1177 coarse
= fused
& IGP01E1000_ANALOG_FUSE_COARSE_MASK
;
1179 if (coarse
> IGP01E1000_ANALOG_FUSE_COARSE_THRESH
) {
1180 coarse
-= IGP01E1000_ANALOG_FUSE_COARSE_10
;
1181 fine
-= IGP01E1000_ANALOG_FUSE_FINE_1
;
1182 } else if (coarse
==
1183 IGP01E1000_ANALOG_FUSE_COARSE_THRESH
)
1184 fine
-= IGP01E1000_ANALOG_FUSE_FINE_10
;
1186 fused
= (fused
& IGP01E1000_ANALOG_FUSE_POLY_MASK
) |
1187 (fine
& IGP01E1000_ANALOG_FUSE_FINE_MASK
) |
1188 (coarse
& IGP01E1000_ANALOG_FUSE_COARSE_MASK
);
1190 hw
->phy
.ops
.write_reg(hw
,
1191 IGP01E1000_ANALOG_FUSE_CONTROL
,
1193 hw
->phy
.ops
.write_reg(hw
,
1194 IGP01E1000_ANALOG_FUSE_BYPASS
,
1195 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL
);
1204 * e1000_init_script_state_82541 - Enable/Disable PHY init script
1205 * @hw: pointer to the HW structure
1206 * @state: boolean value used to enable/disable PHY init script
1208 * Allows the driver to enable/disable the PHY init script, if the PHY is an
1211 void e1000_init_script_state_82541(struct e1000_hw
*hw
, bool state
)
1213 struct e1000_dev_spec_82541
*dev_spec
= &hw
->dev_spec
._82541
;
1215 DEBUGFUNC("e1000_init_script_state_82541");
1217 if (hw
->phy
.type
!= e1000_phy_igp
) {
1218 DEBUGOUT("Initialization script not necessary.\n");
1222 dev_spec
->phy_init_script
= state
;
1229 * e1000_power_down_phy_copper_82541 - Remove link in case of PHY power down
1230 * @hw: pointer to the HW structure
1232 * In the case of a PHY power down to save power, or to turn off link during a
1233 * driver unload, or wake on lan is not enabled, remove the link.
1235 static void e1000_power_down_phy_copper_82541(struct e1000_hw
*hw
)
1237 /* If the management interface is not enabled, then power down */
1238 if (!(E1000_READ_REG(hw
, E1000_MANC
) & E1000_MANC_SMBUS_EN
))
1239 e1000_power_down_phy_copper(hw
);
1245 * e1000_clear_hw_cntrs_82541 - Clear device specific hardware counters
1246 * @hw: pointer to the HW structure
1248 * Clears the hardware counters by reading the counter registers.
1250 static void e1000_clear_hw_cntrs_82541(struct e1000_hw
*hw
)
1252 DEBUGFUNC("e1000_clear_hw_cntrs_82541");
1254 e1000_clear_hw_cntrs_base_generic(hw
);
1256 E1000_READ_REG(hw
, E1000_PRC64
);
1257 E1000_READ_REG(hw
, E1000_PRC127
);
1258 E1000_READ_REG(hw
, E1000_PRC255
);
1259 E1000_READ_REG(hw
, E1000_PRC511
);
1260 E1000_READ_REG(hw
, E1000_PRC1023
);
1261 E1000_READ_REG(hw
, E1000_PRC1522
);
1262 E1000_READ_REG(hw
, E1000_PTC64
);
1263 E1000_READ_REG(hw
, E1000_PTC127
);
1264 E1000_READ_REG(hw
, E1000_PTC255
);
1265 E1000_READ_REG(hw
, E1000_PTC511
);
1266 E1000_READ_REG(hw
, E1000_PTC1023
);
1267 E1000_READ_REG(hw
, E1000_PTC1522
);
1269 E1000_READ_REG(hw
, E1000_ALGNERRC
);
1270 E1000_READ_REG(hw
, E1000_RXERRC
);
1271 E1000_READ_REG(hw
, E1000_TNCRS
);
1272 E1000_READ_REG(hw
, E1000_CEXTERR
);
1273 E1000_READ_REG(hw
, E1000_TSCTC
);
1274 E1000_READ_REG(hw
, E1000_TSCTFC
);
1276 E1000_READ_REG(hw
, E1000_MGTPRC
);
1277 E1000_READ_REG(hw
, E1000_MGTPDC
);
1278 E1000_READ_REG(hw
, E1000_MGTPTC
);