1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
6 * 82541EI Gigabit Ethernet Controller
7 * 82541ER Gigabit Ethernet Controller
8 * 82541GI Gigabit Ethernet Controller
9 * 82541PI Gigabit Ethernet Controller
10 * 82547EI Gigabit Ethernet Controller
11 * 82547GI Gigabit Ethernet Controller
14 #include "e1000_api.h"
16 STATIC s32 e1000_init_phy_params_82541(struct e1000_hw *hw);
17 STATIC s32 e1000_init_nvm_params_82541(struct e1000_hw *hw);
18 STATIC s32 e1000_init_mac_params_82541(struct e1000_hw *hw);
19 STATIC s32 e1000_reset_hw_82541(struct e1000_hw *hw);
20 STATIC s32 e1000_init_hw_82541(struct e1000_hw *hw);
21 STATIC s32 e1000_get_link_up_info_82541(struct e1000_hw *hw, u16 *speed,
23 STATIC s32 e1000_phy_hw_reset_82541(struct e1000_hw *hw);
24 STATIC s32 e1000_setup_copper_link_82541(struct e1000_hw *hw);
25 STATIC s32 e1000_check_for_link_82541(struct e1000_hw *hw);
26 STATIC s32 e1000_get_cable_length_igp_82541(struct e1000_hw *hw);
27 STATIC s32 e1000_set_d3_lplu_state_82541(struct e1000_hw *hw,
29 STATIC s32 e1000_setup_led_82541(struct e1000_hw *hw);
30 STATIC s32 e1000_cleanup_led_82541(struct e1000_hw *hw);
31 STATIC void e1000_clear_hw_cntrs_82541(struct e1000_hw *hw);
32 STATIC s32 e1000_config_dsp_after_link_change_82541(struct e1000_hw *hw,
34 STATIC s32 e1000_phy_init_script_82541(struct e1000_hw *hw);
35 STATIC void e1000_power_down_phy_copper_82541(struct e1000_hw *hw);
37 STATIC const u16 e1000_igp_cable_length_table[] = {
38 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10,
39 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, 25, 25, 25, 25, 30, 30, 30, 30,
40 40, 40, 40, 40, 40, 40, 40, 40, 40, 50, 50, 50, 50, 50, 50, 50, 60, 60,
41 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80,
42 80, 90, 90, 90, 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100,
43 100, 100, 100, 100, 100, 100, 100, 100, 110, 110, 110, 110, 110, 110,
44 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 120, 120,
45 120, 120, 120, 120, 120, 120, 120, 120};
46 #define IGP01E1000_AGC_LENGTH_TABLE_SIZE \
47 (sizeof(e1000_igp_cable_length_table) / \
48 sizeof(e1000_igp_cable_length_table[0]))
51 * e1000_init_phy_params_82541 - Init PHY func ptrs.
52 * @hw: pointer to the HW structure
54 STATIC s32 e1000_init_phy_params_82541(struct e1000_hw *hw)
56 struct e1000_phy_info *phy = &hw->phy;
59 DEBUGFUNC("e1000_init_phy_params_82541");
62 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
63 phy->reset_delay_us = 10000;
64 phy->type = e1000_phy_igp;
66 /* Function Pointers */
67 phy->ops.check_polarity = e1000_check_polarity_igp;
68 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_igp;
69 phy->ops.get_cable_length = e1000_get_cable_length_igp_82541;
70 phy->ops.get_cfg_done = e1000_get_cfg_done_generic;
71 phy->ops.get_info = e1000_get_phy_info_igp;
72 phy->ops.read_reg = e1000_read_phy_reg_igp;
73 phy->ops.reset = e1000_phy_hw_reset_82541;
74 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_82541;
75 phy->ops.write_reg = e1000_write_phy_reg_igp;
76 phy->ops.power_up = e1000_power_up_phy_copper;
77 phy->ops.power_down = e1000_power_down_phy_copper_82541;
79 ret_val = e1000_get_phy_id(hw);
84 if (phy->id != IGP01E1000_I_PHY_ID) {
85 ret_val = -E1000_ERR_PHY;
94 * e1000_init_nvm_params_82541 - Init NVM func ptrs.
95 * @hw: pointer to the HW structure
97 STATIC s32 e1000_init_nvm_params_82541(struct e1000_hw *hw)
99 struct e1000_nvm_info *nvm = &hw->nvm;
100 s32 ret_val = E1000_SUCCESS;
101 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
104 DEBUGFUNC("e1000_init_nvm_params_82541");
106 switch (nvm->override) {
107 case e1000_nvm_override_spi_large:
108 nvm->type = e1000_nvm_eeprom_spi;
109 eecd |= E1000_EECD_ADDR_BITS;
111 case e1000_nvm_override_spi_small:
112 nvm->type = e1000_nvm_eeprom_spi;
113 eecd &= ~E1000_EECD_ADDR_BITS;
115 case e1000_nvm_override_microwire_large:
116 nvm->type = e1000_nvm_eeprom_microwire;
117 eecd |= E1000_EECD_SIZE;
119 case e1000_nvm_override_microwire_small:
120 nvm->type = e1000_nvm_eeprom_microwire;
121 eecd &= ~E1000_EECD_SIZE;
124 nvm->type = eecd & E1000_EECD_TYPE ? e1000_nvm_eeprom_spi
125 : e1000_nvm_eeprom_microwire;
129 if (nvm->type == e1000_nvm_eeprom_spi) {
130 nvm->address_bits = (eecd & E1000_EECD_ADDR_BITS) ? 16 : 8;
132 nvm->opcode_bits = 8;
133 nvm->page_size = (eecd & E1000_EECD_ADDR_BITS) ? 32 : 8;
135 /* Function Pointers */
136 nvm->ops.acquire = e1000_acquire_nvm_generic;
137 nvm->ops.read = e1000_read_nvm_spi;
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_spi;
145 * nvm->word_size must be discovered after the pointers
146 * are set so we can verify the size from the nvm image
147 * itself. Temporarily set it to a dummy value so the
151 ret_val = nvm->ops.read(hw, NVM_CFG, 1, &size);
154 size = (size & NVM_SIZE_MASK) >> NVM_SIZE_SHIFT;
156 * if size != 0, it can be added to a constant and become
157 * the left-shift value to set the word_size. Otherwise,
158 * word_size stays at 64.
161 size += NVM_WORD_SIZE_BASE_SHIFT_82541;
162 nvm->word_size = 1 << size;
165 nvm->address_bits = (eecd & E1000_EECD_ADDR_BITS) ? 8 : 6;
166 nvm->delay_usec = 50;
167 nvm->opcode_bits = 3;
168 nvm->word_size = (eecd & E1000_EECD_ADDR_BITS) ? 256 : 64;
170 /* Function Pointers */
171 nvm->ops.acquire = e1000_acquire_nvm_generic;
172 nvm->ops.read = e1000_read_nvm_microwire;
173 nvm->ops.release = e1000_release_nvm_generic;
174 nvm->ops.update = e1000_update_nvm_checksum_generic;
175 nvm->ops.valid_led_default = e1000_valid_led_default_generic;
176 nvm->ops.validate = e1000_validate_nvm_checksum_generic;
177 nvm->ops.write = e1000_write_nvm_microwire;
185 * e1000_init_mac_params_82541 - Init MAC func ptrs.
186 * @hw: pointer to the HW structure
188 STATIC s32 e1000_init_mac_params_82541(struct e1000_hw *hw)
190 struct e1000_mac_info *mac = &hw->mac;
192 DEBUGFUNC("e1000_init_mac_params_82541");
195 hw->phy.media_type = e1000_media_type_copper;
196 /* Set mta register count */
197 mac->mta_reg_count = 128;
198 /* Set rar entry count */
199 mac->rar_entry_count = E1000_RAR_ENTRIES;
200 /* Set if part includes ASF firmware */
201 mac->asf_firmware_present = true;
203 /* Function Pointers */
205 /* bus type/speed/width */
206 mac->ops.get_bus_info = e1000_get_bus_info_pci_generic;
208 mac->ops.set_lan_id = e1000_set_lan_id_single_port;
210 mac->ops.reset_hw = e1000_reset_hw_82541;
211 /* hw initialization */
212 mac->ops.init_hw = e1000_init_hw_82541;
214 mac->ops.setup_link = e1000_setup_link_generic;
215 /* physical interface link setup */
216 mac->ops.setup_physical_interface = e1000_setup_copper_link_82541;
218 mac->ops.check_for_link = e1000_check_for_link_82541;
220 mac->ops.get_link_up_info = e1000_get_link_up_info_82541;
221 /* multicast address update */
222 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
224 mac->ops.write_vfta = e1000_write_vfta_generic;
226 mac->ops.clear_vfta = e1000_clear_vfta_generic;
228 mac->ops.id_led_init = e1000_id_led_init_generic;
230 mac->ops.setup_led = e1000_setup_led_82541;
232 mac->ops.cleanup_led = e1000_cleanup_led_82541;
233 /* turn on/off LED */
234 mac->ops.led_on = e1000_led_on_generic;
235 mac->ops.led_off = e1000_led_off_generic;
236 /* clear hardware counters */
237 mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82541;
239 return E1000_SUCCESS;
243 * e1000_init_function_pointers_82541 - 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_82541(struct e1000_hw *hw)
250 DEBUGFUNC("e1000_init_function_pointers_82541");
252 hw->mac.ops.init_params = e1000_init_mac_params_82541;
253 hw->nvm.ops.init_params = e1000_init_nvm_params_82541;
254 hw->phy.ops.init_params = e1000_init_phy_params_82541;
258 * e1000_reset_hw_82541 - Reset hardware
259 * @hw: pointer to the HW structure
261 * This resets the hardware into a known state.
263 STATIC s32 e1000_reset_hw_82541(struct e1000_hw *hw)
265 u32 ledctl, ctrl, manc;
267 DEBUGFUNC("e1000_reset_hw_82541");
269 DEBUGOUT("Masking off all interrupts\n");
270 E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF);
272 E1000_WRITE_REG(hw, E1000_RCTL, 0);
273 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
274 E1000_WRITE_FLUSH(hw);
277 * Delay to allow any outstanding PCI transactions to complete
278 * before resetting the device.
282 ctrl = E1000_READ_REG(hw, E1000_CTRL);
284 /* Must reset the Phy before resetting the MAC */
285 if ((hw->mac.type == e1000_82541) || (hw->mac.type == e1000_82547)) {
286 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl | E1000_CTRL_PHY_RST));
287 E1000_WRITE_FLUSH(hw);
291 DEBUGOUT("Issuing a global reset to 82541/82547 MAC\n");
292 switch (hw->mac.type) {
294 case e1000_82541_rev_2:
296 * These controllers can't ack the 64-bit write when
297 * issuing the reset, so we use IO-mapping as a
298 * workaround to issue the reset.
300 E1000_WRITE_REG_IO(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
303 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
307 /* Wait for NVM reload */
310 /* Disable HW ARPs on ASF enabled adapters */
311 manc = E1000_READ_REG(hw, E1000_MANC);
312 manc &= ~E1000_MANC_ARP_EN;
313 E1000_WRITE_REG(hw, E1000_MANC, manc);
315 if ((hw->mac.type == e1000_82541) || (hw->mac.type == e1000_82547)) {
316 e1000_phy_init_script_82541(hw);
318 /* Configure activity LED after Phy reset */
319 ledctl = E1000_READ_REG(hw, E1000_LEDCTL);
320 ledctl &= IGP_ACTIVITY_LED_MASK;
321 ledctl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
322 E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl);
325 /* Once again, mask the interrupts */
326 DEBUGOUT("Masking off all interrupts\n");
327 E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF);
329 /* Clear any pending interrupt events. */
330 E1000_READ_REG(hw, E1000_ICR);
332 return E1000_SUCCESS;
336 * e1000_init_hw_82541 - Initialize hardware
337 * @hw: pointer to the HW structure
339 * This inits the hardware readying it for operation.
341 STATIC s32 e1000_init_hw_82541(struct e1000_hw *hw)
343 struct e1000_mac_info *mac = &hw->mac;
344 struct e1000_dev_spec_82541 *dev_spec = &hw->dev_spec._82541;
348 DEBUGFUNC("e1000_init_hw_82541");
350 /* Initialize identification LED */
351 ret_val = mac->ops.id_led_init(hw);
353 DEBUGOUT("Error initializing identification LED\n");
354 /* This is not fatal and we should not stop init due to this */
357 /* Storing the Speed Power Down value for later use */
358 ret_val = hw->phy.ops.read_reg(hw, IGP01E1000_GMII_FIFO,
359 &dev_spec->spd_default);
363 /* Disabling VLAN filtering */
364 DEBUGOUT("Initializing the IEEE VLAN\n");
365 mac->ops.clear_vfta(hw);
367 /* Setup the receive address. */
368 e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
370 /* Zero out the Multicast HASH table */
371 DEBUGOUT("Zeroing the MTA\n");
372 for (i = 0; i < mac->mta_reg_count; i++) {
373 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
375 * Avoid back to back register writes by adding the register
376 * read (flush). This is to protect against some strange
377 * bridge configurations that may issue Memory Write Block
378 * (MWB) to our register space.
380 E1000_WRITE_FLUSH(hw);
383 /* Setup link and flow control */
384 ret_val = mac->ops.setup_link(hw);
386 txdctl = E1000_READ_REG(hw, E1000_TXDCTL(0));
387 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
388 E1000_TXDCTL_FULL_TX_DESC_WB;
389 E1000_WRITE_REG(hw, E1000_TXDCTL(0), txdctl);
392 * Clear all of the statistics registers (clear on read). It is
393 * important that we do this after we have tried to establish link
394 * because the symbol error count will increment wildly if there
397 e1000_clear_hw_cntrs_82541(hw);
404 * e1000_get_link_up_info_82541 - Report speed and duplex
405 * @hw: pointer to the HW structure
406 * @speed: pointer to speed buffer
407 * @duplex: pointer to duplex buffer
409 * Retrieve the current speed and duplex configuration.
411 STATIC s32 e1000_get_link_up_info_82541(struct e1000_hw *hw, u16 *speed,
414 struct e1000_phy_info *phy = &hw->phy;
418 DEBUGFUNC("e1000_get_link_up_info_82541");
420 ret_val = e1000_get_speed_and_duplex_copper_generic(hw, speed, duplex);
424 if (!phy->speed_downgraded)
428 * IGP01 PHY may advertise full duplex operation after speed
429 * downgrade even if it is operating at half duplex.
430 * Here we set the duplex settings to match the duplex in the
431 * link partner's capabilities.
433 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_EXP, &data);
437 if (!(data & NWAY_ER_LP_NWAY_CAPS)) {
438 *duplex = HALF_DUPLEX;
440 ret_val = phy->ops.read_reg(hw, PHY_LP_ABILITY, &data);
444 if (*speed == SPEED_100) {
445 if (!(data & NWAY_LPAR_100TX_FD_CAPS))
446 *duplex = HALF_DUPLEX;
447 } else if (*speed == SPEED_10) {
448 if (!(data & NWAY_LPAR_10T_FD_CAPS))
449 *duplex = HALF_DUPLEX;
458 * e1000_phy_hw_reset_82541 - PHY hardware reset
459 * @hw: pointer to the HW structure
461 * Verify the reset block is not blocking us from resetting. Acquire
462 * semaphore (if necessary) and read/set/write the device control reset
463 * bit in the PHY. Wait the appropriate delay time for the device to
464 * reset and release the semaphore (if necessary).
466 STATIC s32 e1000_phy_hw_reset_82541(struct e1000_hw *hw)
471 DEBUGFUNC("e1000_phy_hw_reset_82541");
473 ret_val = e1000_phy_hw_reset_generic(hw);
477 e1000_phy_init_script_82541(hw);
479 if ((hw->mac.type == e1000_82541) || (hw->mac.type == e1000_82547)) {
480 /* Configure activity LED after PHY reset */
481 ledctl = E1000_READ_REG(hw, E1000_LEDCTL);
482 ledctl &= IGP_ACTIVITY_LED_MASK;
483 ledctl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
484 E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl);
492 * e1000_setup_copper_link_82541 - Configure copper link settings
493 * @hw: pointer to the HW structure
495 * Calls the appropriate function to configure the link for auto-neg or forced
496 * speed and duplex. Then we check for link, once link is established calls
497 * to configure collision distance and flow control are called. If link is
498 * not established, we return -E1000_ERR_PHY (-2).
500 STATIC s32 e1000_setup_copper_link_82541(struct e1000_hw *hw)
502 struct e1000_phy_info *phy = &hw->phy;
503 struct e1000_dev_spec_82541 *dev_spec = &hw->dev_spec._82541;
507 DEBUGFUNC("e1000_setup_copper_link_82541");
509 ctrl = E1000_READ_REG(hw, E1000_CTRL);
510 ctrl |= E1000_CTRL_SLU;
511 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
512 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
515 /* Earlier revs of the IGP phy require us to force MDI. */
516 if (hw->mac.type == e1000_82541 || hw->mac.type == e1000_82547) {
517 dev_spec->dsp_config = e1000_dsp_config_disabled;
520 dev_spec->dsp_config = e1000_dsp_config_enabled;
523 ret_val = e1000_copper_link_setup_igp(hw);
527 if (hw->mac.autoneg) {
528 if (dev_spec->ffe_config == e1000_ffe_config_active)
529 dev_spec->ffe_config = e1000_ffe_config_enabled;
532 /* Configure activity LED after Phy reset */
533 ledctl = E1000_READ_REG(hw, E1000_LEDCTL);
534 ledctl &= IGP_ACTIVITY_LED_MASK;
535 ledctl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
536 E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl);
538 ret_val = e1000_setup_copper_link_generic(hw);
545 * e1000_check_for_link_82541 - Check/Store link connection
546 * @hw: pointer to the HW structure
548 * This checks the link condition of the adapter and stores the
549 * results in the hw->mac structure.
551 STATIC s32 e1000_check_for_link_82541(struct e1000_hw *hw)
553 struct e1000_mac_info *mac = &hw->mac;
557 DEBUGFUNC("e1000_check_for_link_82541");
560 * We only want to go out to the PHY registers to see if Auto-Neg
561 * has completed and/or if our link status has changed. The
562 * get_link_status flag is set upon receiving a Link Status
563 * Change or Rx Sequence Error interrupt.
565 if (!mac->get_link_status) {
566 ret_val = E1000_SUCCESS;
571 * First we want to see if the MII Status Register reports
572 * link. If so, then we want to get the current speed/duplex
575 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
580 ret_val = e1000_config_dsp_after_link_change_82541(hw, false);
581 goto out; /* No link detected */
584 mac->get_link_status = false;
587 * Check if there was DownShift, must be checked
588 * immediately after link-up
590 e1000_check_downshift_generic(hw);
593 * If we are forcing speed/duplex, then we simply return since
594 * we have already determined whether we have link or not.
597 ret_val = -E1000_ERR_CONFIG;
601 ret_val = e1000_config_dsp_after_link_change_82541(hw, true);
604 * Auto-Neg is enabled. Auto Speed Detection takes care
605 * of MAC speed/duplex configuration. So we only need to
606 * configure Collision Distance in the MAC.
608 mac->ops.config_collision_dist(hw);
611 * Configure Flow Control now that Auto-Neg has completed.
612 * First, we need to restore the desired flow control
613 * settings because we may have had to re-autoneg with a
614 * different link partner.
616 ret_val = e1000_config_fc_after_link_up_generic(hw);
618 DEBUGOUT("Error configuring flow control\n");
625 * e1000_config_dsp_after_link_change_82541 - Config DSP after link
626 * @hw: pointer to the HW structure
627 * @link_up: boolean flag for link up status
629 * Return E1000_ERR_PHY when failing to read/write the PHY, else E1000_SUCCESS
632 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
633 * gigabit link is achieved to improve link quality.
635 STATIC s32 e1000_config_dsp_after_link_change_82541(struct e1000_hw *hw,
638 struct e1000_phy_info *phy = &hw->phy;
639 struct e1000_dev_spec_82541 *dev_spec = &hw->dev_spec._82541;
642 u16 phy_data, phy_saved_data, speed, duplex, i;
643 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
644 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
645 IGP01E1000_PHY_AGC_PARAM_A,
646 IGP01E1000_PHY_AGC_PARAM_B,
647 IGP01E1000_PHY_AGC_PARAM_C,
648 IGP01E1000_PHY_AGC_PARAM_D};
650 DEBUGFUNC("e1000_config_dsp_after_link_change_82541");
653 ret_val = hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
655 DEBUGOUT("Error getting link speed and duplex\n");
659 if (speed != SPEED_1000) {
660 ret_val = E1000_SUCCESS;
664 ret_val = phy->ops.get_cable_length(hw);
668 if ((dev_spec->dsp_config == e1000_dsp_config_enabled) &&
669 phy->min_cable_length >= 50) {
671 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
672 ret_val = phy->ops.read_reg(hw,
678 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
680 ret_val = phy->ops.write_reg(hw,
686 dev_spec->dsp_config = e1000_dsp_config_activated;
689 if ((dev_spec->ffe_config != e1000_ffe_config_enabled) ||
690 (phy->min_cable_length >= 50)) {
691 ret_val = E1000_SUCCESS;
695 /* clear previous idle error counts */
696 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
700 for (i = 0; i < ffe_idle_err_timeout; i++) {
702 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS,
707 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
708 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
709 dev_spec->ffe_config = e1000_ffe_config_active;
711 ret_val = phy->ops.write_reg(hw,
712 IGP01E1000_PHY_DSP_FFE,
713 IGP01E1000_PHY_DSP_FFE_CM_CP);
720 ffe_idle_err_timeout =
721 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
724 if (dev_spec->dsp_config == e1000_dsp_config_activated) {
726 * Save off the current value of register 0x2F5B
727 * to be restored at the end of the routines.
729 ret_val = phy->ops.read_reg(hw, 0x2F5B,
734 /* Disable the PHY transmitter */
735 ret_val = phy->ops.write_reg(hw, 0x2F5B, 0x0003);
741 ret_val = phy->ops.write_reg(hw, 0x0000,
742 IGP01E1000_IEEE_FORCE_GIG);
745 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
746 ret_val = phy->ops.read_reg(hw,
752 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
753 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
755 ret_val = phy->ops.write_reg(hw,
762 ret_val = phy->ops.write_reg(hw, 0x0000,
763 IGP01E1000_IEEE_RESTART_AUTONEG);
769 /* Now enable the transmitter */
770 ret_val = phy->ops.write_reg(hw, 0x2F5B,
775 dev_spec->dsp_config = e1000_dsp_config_enabled;
778 if (dev_spec->ffe_config != e1000_ffe_config_active) {
779 ret_val = E1000_SUCCESS;
784 * Save off the current value of register 0x2F5B
785 * to be restored at the end of the routines.
787 ret_val = phy->ops.read_reg(hw, 0x2F5B, &phy_saved_data);
791 /* Disable the PHY transmitter */
792 ret_val = phy->ops.write_reg(hw, 0x2F5B, 0x0003);
798 ret_val = phy->ops.write_reg(hw, 0x0000,
799 IGP01E1000_IEEE_FORCE_GIG);
803 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_DSP_FFE,
804 IGP01E1000_PHY_DSP_FFE_DEFAULT);
808 ret_val = phy->ops.write_reg(hw, 0x0000,
809 IGP01E1000_IEEE_RESTART_AUTONEG);
815 /* Now enable the transmitter */
816 ret_val = phy->ops.write_reg(hw, 0x2F5B, phy_saved_data);
821 dev_spec->ffe_config = e1000_ffe_config_enabled;
829 * e1000_get_cable_length_igp_82541 - Determine cable length for igp PHY
830 * @hw: pointer to the HW structure
832 * The automatic gain control (agc) normalizes the amplitude of the
833 * received signal, adjusting for the attenuation produced by the
834 * cable. By reading the AGC registers, which represent the
835 * combination of coarse and fine gain value, the value can be put
836 * into a lookup table to obtain the approximate cable length
839 STATIC s32 e1000_get_cable_length_igp_82541(struct e1000_hw *hw)
841 struct e1000_phy_info *phy = &hw->phy;
842 s32 ret_val = E1000_SUCCESS;
844 u16 cur_agc_value, agc_value = 0;
845 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
846 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {IGP01E1000_PHY_AGC_A,
847 IGP01E1000_PHY_AGC_B,
848 IGP01E1000_PHY_AGC_C,
849 IGP01E1000_PHY_AGC_D};
851 DEBUGFUNC("e1000_get_cable_length_igp_82541");
853 /* Read the AGC registers for all channels */
854 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
855 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &data);
859 cur_agc_value = data >> IGP01E1000_AGC_LENGTH_SHIFT;
861 /* Bounds checking */
862 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
863 (cur_agc_value == 0)) {
864 ret_val = -E1000_ERR_PHY;
868 agc_value += cur_agc_value;
870 if (min_agc_value > cur_agc_value)
871 min_agc_value = cur_agc_value;
874 /* Remove the minimal AGC result for length < 50m */
875 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * 50) {
876 agc_value -= min_agc_value;
877 /* Average the three remaining channels for the length. */
878 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
880 /* Average the channels for the length. */
881 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
884 phy->min_cable_length = (e1000_igp_cable_length_table[agc_value] >
885 IGP01E1000_AGC_RANGE)
886 ? (e1000_igp_cable_length_table[agc_value] -
887 IGP01E1000_AGC_RANGE)
889 phy->max_cable_length = e1000_igp_cable_length_table[agc_value] +
890 IGP01E1000_AGC_RANGE;
892 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
899 * e1000_set_d3_lplu_state_82541 - Sets low power link up state for D3
900 * @hw: pointer to the HW structure
901 * @active: boolean used to enable/disable lplu
903 * Success returns 0, Failure returns 1
905 * The low power link up (lplu) state is set to the power management level D3
906 * and SmartSpeed is disabled when active is true, else clear lplu for D3
907 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
908 * is used during Dx states where the power conservation is most important.
909 * During driver activity, SmartSpeed should be enabled so performance is
912 STATIC s32 e1000_set_d3_lplu_state_82541(struct e1000_hw *hw, bool active)
914 struct e1000_phy_info *phy = &hw->phy;
918 DEBUGFUNC("e1000_set_d3_lplu_state_82541");
920 switch (hw->mac.type) {
921 case e1000_82541_rev_2:
922 case e1000_82547_rev_2:
925 ret_val = e1000_set_d3_lplu_state_generic(hw, active);
930 ret_val = phy->ops.read_reg(hw, IGP01E1000_GMII_FIFO, &data);
935 data &= ~IGP01E1000_GMII_FLEX_SPD;
936 ret_val = phy->ops.write_reg(hw, IGP01E1000_GMII_FIFO, data);
941 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
942 * during Dx states where the power conservation is most
943 * important. During driver activity we should enable
944 * SmartSpeed, so performance is maintained.
946 if (phy->smart_speed == e1000_smart_speed_on) {
947 ret_val = phy->ops.read_reg(hw,
948 IGP01E1000_PHY_PORT_CONFIG,
953 data |= IGP01E1000_PSCFR_SMART_SPEED;
954 ret_val = phy->ops.write_reg(hw,
955 IGP01E1000_PHY_PORT_CONFIG,
959 } else if (phy->smart_speed == e1000_smart_speed_off) {
960 ret_val = phy->ops.read_reg(hw,
961 IGP01E1000_PHY_PORT_CONFIG,
966 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
967 ret_val = phy->ops.write_reg(hw,
968 IGP01E1000_PHY_PORT_CONFIG,
973 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
974 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
975 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
976 data |= IGP01E1000_GMII_FLEX_SPD;
977 ret_val = phy->ops.write_reg(hw, IGP01E1000_GMII_FIFO, data);
981 /* When LPLU is enabled, we should disable SmartSpeed */
982 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
987 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
988 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
997 * e1000_setup_led_82541 - Configures SW controllable LED
998 * @hw: pointer to the HW structure
1000 * This prepares the SW controllable LED for use and saves the current state
1001 * of the LED so it can be later restored.
1003 STATIC s32 e1000_setup_led_82541(struct e1000_hw *hw)
1005 struct e1000_dev_spec_82541 *dev_spec = &hw->dev_spec._82541;
1008 DEBUGFUNC("e1000_setup_led_82541");
1010 ret_val = hw->phy.ops.read_reg(hw, IGP01E1000_GMII_FIFO,
1011 &dev_spec->spd_default);
1015 ret_val = hw->phy.ops.write_reg(hw, IGP01E1000_GMII_FIFO,
1016 (u16)(dev_spec->spd_default &
1017 ~IGP01E1000_GMII_SPD));
1021 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
1028 * e1000_cleanup_led_82541 - Set LED config to default operation
1029 * @hw: pointer to the HW structure
1031 * Remove the current LED configuration and set the LED configuration
1032 * to the default value, saved from the EEPROM.
1034 STATIC s32 e1000_cleanup_led_82541(struct e1000_hw *hw)
1036 struct e1000_dev_spec_82541 *dev_spec = &hw->dev_spec._82541;
1039 DEBUGFUNC("e1000_cleanup_led_82541");
1041 ret_val = hw->phy.ops.write_reg(hw, IGP01E1000_GMII_FIFO,
1042 dev_spec->spd_default);
1046 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default);
1053 * e1000_phy_init_script_82541 - Initialize GbE PHY
1054 * @hw: pointer to the HW structure
1056 * Initializes the IGP PHY.
1058 STATIC s32 e1000_phy_init_script_82541(struct e1000_hw *hw)
1060 struct e1000_dev_spec_82541 *dev_spec = &hw->dev_spec._82541;
1064 DEBUGFUNC("e1000_phy_init_script_82541");
1066 if (!dev_spec->phy_init_script) {
1067 ret_val = E1000_SUCCESS;
1071 /* Delay after phy reset to enable NVM configuration to load */
1075 * Save off the current value of register 0x2F5B to be restored at
1076 * the end of this routine.
1078 ret_val = hw->phy.ops.read_reg(hw, 0x2F5B, &phy_saved_data);
1080 /* Disabled the PHY transmitter */
1081 hw->phy.ops.write_reg(hw, 0x2F5B, 0x0003);
1085 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
1089 switch (hw->mac.type) {
1092 hw->phy.ops.write_reg(hw, 0x1F95, 0x0001);
1094 hw->phy.ops.write_reg(hw, 0x1F71, 0xBD21);
1096 hw->phy.ops.write_reg(hw, 0x1F79, 0x0018);
1098 hw->phy.ops.write_reg(hw, 0x1F30, 0x1600);
1100 hw->phy.ops.write_reg(hw, 0x1F31, 0x0014);
1102 hw->phy.ops.write_reg(hw, 0x1F32, 0x161C);
1104 hw->phy.ops.write_reg(hw, 0x1F94, 0x0003);
1106 hw->phy.ops.write_reg(hw, 0x1F96, 0x003F);
1108 hw->phy.ops.write_reg(hw, 0x2010, 0x0008);
1110 case e1000_82541_rev_2:
1111 case e1000_82547_rev_2:
1112 hw->phy.ops.write_reg(hw, 0x1F73, 0x0099);
1118 hw->phy.ops.write_reg(hw, 0x0000, 0x3300);
1122 /* Now enable the transmitter */
1123 hw->phy.ops.write_reg(hw, 0x2F5B, phy_saved_data);
1125 if (hw->mac.type == e1000_82547) {
1126 u16 fused, fine, coarse;
1128 /* Move to analog registers page */
1129 hw->phy.ops.read_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
1132 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
1133 hw->phy.ops.read_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS,
1136 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
1137 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
1139 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
1140 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
1141 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
1142 } else if (coarse ==
1143 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
1144 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
1146 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
1147 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
1148 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
1150 hw->phy.ops.write_reg(hw,
1151 IGP01E1000_ANALOG_FUSE_CONTROL,
1153 hw->phy.ops.write_reg(hw,
1154 IGP01E1000_ANALOG_FUSE_BYPASS,
1155 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
1164 * e1000_init_script_state_82541 - Enable/Disable PHY init script
1165 * @hw: pointer to the HW structure
1166 * @state: boolean value used to enable/disable PHY init script
1168 * Allows the driver to enable/disable the PHY init script, if the PHY is an
1171 void e1000_init_script_state_82541(struct e1000_hw *hw, bool state)
1173 struct e1000_dev_spec_82541 *dev_spec = &hw->dev_spec._82541;
1175 DEBUGFUNC("e1000_init_script_state_82541");
1177 if (hw->phy.type != e1000_phy_igp) {
1178 DEBUGOUT("Initialization script not necessary.\n");
1182 dev_spec->phy_init_script = state;
1189 * e1000_power_down_phy_copper_82541 - Remove link in case of PHY power down
1190 * @hw: pointer to the HW structure
1192 * In the case of a PHY power down to save power, or to turn off link during a
1193 * driver unload, or wake on lan is not enabled, remove the link.
1195 STATIC void e1000_power_down_phy_copper_82541(struct e1000_hw *hw)
1197 /* If the management interface is not enabled, then power down */
1198 if (!(E1000_READ_REG(hw, E1000_MANC) & E1000_MANC_SMBUS_EN))
1199 e1000_power_down_phy_copper(hw);
1205 * e1000_clear_hw_cntrs_82541 - Clear device specific hardware counters
1206 * @hw: pointer to the HW structure
1208 * Clears the hardware counters by reading the counter registers.
1210 STATIC void e1000_clear_hw_cntrs_82541(struct e1000_hw *hw)
1212 DEBUGFUNC("e1000_clear_hw_cntrs_82541");
1214 e1000_clear_hw_cntrs_base_generic(hw);
1216 E1000_READ_REG(hw, E1000_PRC64);
1217 E1000_READ_REG(hw, E1000_PRC127);
1218 E1000_READ_REG(hw, E1000_PRC255);
1219 E1000_READ_REG(hw, E1000_PRC511);
1220 E1000_READ_REG(hw, E1000_PRC1023);
1221 E1000_READ_REG(hw, E1000_PRC1522);
1222 E1000_READ_REG(hw, E1000_PTC64);
1223 E1000_READ_REG(hw, E1000_PTC127);
1224 E1000_READ_REG(hw, E1000_PTC255);
1225 E1000_READ_REG(hw, E1000_PTC511);
1226 E1000_READ_REG(hw, E1000_PTC1023);
1227 E1000_READ_REG(hw, E1000_PTC1522);
1229 E1000_READ_REG(hw, E1000_ALGNERRC);
1230 E1000_READ_REG(hw, E1000_RXERRC);
1231 E1000_READ_REG(hw, E1000_TNCRS);
1232 E1000_READ_REG(hw, E1000_CEXTERR);
1233 E1000_READ_REG(hw, E1000_TSCTC);
1234 E1000_READ_REG(hw, E1000_TSCTFC);
1236 E1000_READ_REG(hw, E1000_MGTPRC);
1237 E1000_READ_REG(hw, E1000_MGTPDC);
1238 E1000_READ_REG(hw, E1000_MGTPTC);