1 /******************************************************************************
3 Copyright (c) 2001-2014, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
35 /* 82571EB Gigabit Ethernet Controller
36 * 82571EB Gigabit Ethernet Controller (Copper)
37 * 82571EB Gigabit Ethernet Controller (Fiber)
38 * 82571EB Dual Port Gigabit Mezzanine Adapter
39 * 82571EB Quad Port Gigabit Mezzanine Adapter
40 * 82571PT Gigabit PT Quad Port Server ExpressModule
41 * 82572EI Gigabit Ethernet Controller (Copper)
42 * 82572EI Gigabit Ethernet Controller (Fiber)
43 * 82572EI Gigabit Ethernet Controller
44 * 82573V Gigabit Ethernet Controller (Copper)
45 * 82573E Gigabit Ethernet Controller (Copper)
46 * 82573L Gigabit Ethernet Controller
47 * 82574L Gigabit Network Connection
48 * 82583V Gigabit Network Connection
51 #include "e1000_api.h"
53 static s32 e1000_acquire_nvm_82571(struct e1000_hw *hw);
54 static void e1000_release_nvm_82571(struct e1000_hw *hw);
55 static s32 e1000_write_nvm_82571(struct e1000_hw *hw, u16 offset,
56 u16 words, u16 *data);
57 static s32 e1000_update_nvm_checksum_82571(struct e1000_hw *hw);
58 static s32 e1000_validate_nvm_checksum_82571(struct e1000_hw *hw);
59 static s32 e1000_get_cfg_done_82571(struct e1000_hw *hw);
60 static s32 e1000_set_d0_lplu_state_82571(struct e1000_hw *hw,
62 static s32 e1000_reset_hw_82571(struct e1000_hw *hw);
63 static s32 e1000_init_hw_82571(struct e1000_hw *hw);
64 static void e1000_clear_vfta_82571(struct e1000_hw *hw);
65 static bool e1000_check_mng_mode_82574(struct e1000_hw *hw);
66 static s32 e1000_led_on_82574(struct e1000_hw *hw);
67 static s32 e1000_setup_link_82571(struct e1000_hw *hw);
68 static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw);
69 static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw);
70 static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw);
71 static s32 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 *data);
72 static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw);
73 static s32 e1000_get_hw_semaphore_82571(struct e1000_hw *hw);
74 static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw);
75 static s32 e1000_get_phy_id_82571(struct e1000_hw *hw);
76 static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw);
77 static void e1000_put_hw_semaphore_82573(struct e1000_hw *hw);
78 static s32 e1000_get_hw_semaphore_82574(struct e1000_hw *hw);
79 static void e1000_put_hw_semaphore_82574(struct e1000_hw *hw);
80 static s32 e1000_set_d0_lplu_state_82574(struct e1000_hw *hw,
82 static s32 e1000_set_d3_lplu_state_82574(struct e1000_hw *hw,
84 static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw);
85 static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
86 u16 words, u16 *data);
87 static s32 e1000_read_mac_addr_82571(struct e1000_hw *hw);
88 static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw);
91 * e1000_init_phy_params_82571 - Init PHY func ptrs.
92 * @hw: pointer to the HW structure
94 static s32 e1000_init_phy_params_82571(struct e1000_hw *hw)
96 struct e1000_phy_info *phy = &hw->phy;
99 DEBUGFUNC("e1000_init_phy_params_82571");
101 if (hw->phy.media_type != e1000_media_type_copper) {
102 phy->type = e1000_phy_none;
103 return E1000_SUCCESS;
107 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
108 phy->reset_delay_us = 100;
110 phy->ops.check_reset_block = e1000_check_reset_block_generic;
111 phy->ops.reset = e1000_phy_hw_reset_generic;
112 phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82571;
113 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_generic;
114 phy->ops.power_up = e1000_power_up_phy_copper;
115 phy->ops.power_down = e1000_power_down_phy_copper_82571;
117 switch (hw->mac.type) {
120 phy->type = e1000_phy_igp_2;
121 phy->ops.get_cfg_done = e1000_get_cfg_done_82571;
122 phy->ops.get_info = e1000_get_phy_info_igp;
123 phy->ops.check_polarity = e1000_check_polarity_igp;
124 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_igp;
125 phy->ops.get_cable_length = e1000_get_cable_length_igp_2;
126 phy->ops.read_reg = e1000_read_phy_reg_igp;
127 phy->ops.write_reg = e1000_write_phy_reg_igp;
128 phy->ops.acquire = e1000_get_hw_semaphore_82571;
129 phy->ops.release = e1000_put_hw_semaphore_82571;
132 phy->type = e1000_phy_m88;
133 phy->ops.get_cfg_done = e1000_get_cfg_done_generic;
134 phy->ops.get_info = e1000_get_phy_info_m88;
135 phy->ops.check_polarity = e1000_check_polarity_m88;
136 phy->ops.commit = e1000_phy_sw_reset_generic;
137 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
138 phy->ops.get_cable_length = e1000_get_cable_length_m88;
139 phy->ops.read_reg = e1000_read_phy_reg_m88;
140 phy->ops.write_reg = e1000_write_phy_reg_m88;
141 phy->ops.acquire = e1000_get_hw_semaphore_82571;
142 phy->ops.release = e1000_put_hw_semaphore_82571;
146 phy->type = e1000_phy_bm;
147 phy->ops.get_cfg_done = e1000_get_cfg_done_generic;
148 phy->ops.get_info = e1000_get_phy_info_m88;
149 phy->ops.check_polarity = e1000_check_polarity_m88;
150 phy->ops.commit = e1000_phy_sw_reset_generic;
151 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
152 phy->ops.get_cable_length = e1000_get_cable_length_m88;
153 phy->ops.read_reg = e1000_read_phy_reg_bm2;
154 phy->ops.write_reg = e1000_write_phy_reg_bm2;
155 phy->ops.acquire = e1000_get_hw_semaphore_82574;
156 phy->ops.release = e1000_put_hw_semaphore_82574;
157 phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_82574;
158 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_82574;
161 return -E1000_ERR_PHY;
165 /* This can only be done after all function pointers are setup. */
166 ret_val = e1000_get_phy_id_82571(hw);
168 DEBUGOUT("Error getting PHY ID\n");
173 switch (hw->mac.type) {
176 if (phy->id != IGP01E1000_I_PHY_ID)
177 ret_val = -E1000_ERR_PHY;
180 if (phy->id != M88E1111_I_PHY_ID)
181 ret_val = -E1000_ERR_PHY;
185 if (phy->id != BME1000_E_PHY_ID_R2)
186 ret_val = -E1000_ERR_PHY;
189 ret_val = -E1000_ERR_PHY;
194 DEBUGOUT1("PHY ID unknown: type = 0x%08x\n", phy->id);
200 * e1000_init_nvm_params_82571 - Init NVM func ptrs.
201 * @hw: pointer to the HW structure
203 static s32 e1000_init_nvm_params_82571(struct e1000_hw *hw)
205 struct e1000_nvm_info *nvm = &hw->nvm;
206 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
209 DEBUGFUNC("e1000_init_nvm_params_82571");
211 nvm->opcode_bits = 8;
213 switch (nvm->override) {
214 case e1000_nvm_override_spi_large:
216 nvm->address_bits = 16;
218 case e1000_nvm_override_spi_small:
220 nvm->address_bits = 8;
223 nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
224 nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
228 switch (hw->mac.type) {
232 if (((eecd >> 15) & 0x3) == 0x3) {
233 nvm->type = e1000_nvm_flash_hw;
234 nvm->word_size = 2048;
235 /* Autonomous Flash update bit must be cleared due
236 * to Flash update issue.
238 eecd &= ~E1000_EECD_AUPDEN;
239 E1000_WRITE_REG(hw, E1000_EECD, eecd);
244 nvm->type = e1000_nvm_eeprom_spi;
245 size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
246 E1000_EECD_SIZE_EX_SHIFT);
247 /* Added to a constant, "size" becomes the left-shift value
248 * for setting word_size.
250 size += NVM_WORD_SIZE_BASE_SHIFT;
252 /* EEPROM access above 16k is unsupported */
255 nvm->word_size = 1 << size;
259 /* Function Pointers */
260 switch (hw->mac.type) {
263 nvm->ops.acquire = e1000_get_hw_semaphore_82574;
264 nvm->ops.release = e1000_put_hw_semaphore_82574;
267 nvm->ops.acquire = e1000_acquire_nvm_82571;
268 nvm->ops.release = e1000_release_nvm_82571;
271 nvm->ops.read = e1000_read_nvm_eerd;
272 nvm->ops.update = e1000_update_nvm_checksum_82571;
273 nvm->ops.validate = e1000_validate_nvm_checksum_82571;
274 nvm->ops.valid_led_default = e1000_valid_led_default_82571;
275 nvm->ops.write = e1000_write_nvm_82571;
277 return E1000_SUCCESS;
281 * e1000_init_mac_params_82571 - Init MAC func ptrs.
282 * @hw: pointer to the HW structure
284 static s32 e1000_init_mac_params_82571(struct e1000_hw *hw)
286 struct e1000_mac_info *mac = &hw->mac;
289 bool force_clear_smbi = FALSE;
291 DEBUGFUNC("e1000_init_mac_params_82571");
293 /* Set media type and media-dependent function pointers */
294 switch (hw->device_id) {
295 case E1000_DEV_ID_82571EB_FIBER:
296 case E1000_DEV_ID_82572EI_FIBER:
297 case E1000_DEV_ID_82571EB_QUAD_FIBER:
298 hw->phy.media_type = e1000_media_type_fiber;
299 mac->ops.setup_physical_interface =
300 e1000_setup_fiber_serdes_link_82571;
301 mac->ops.check_for_link = e1000_check_for_fiber_link_generic;
302 mac->ops.get_link_up_info =
303 e1000_get_speed_and_duplex_fiber_serdes_generic;
305 case E1000_DEV_ID_82571EB_SERDES:
306 case E1000_DEV_ID_82571EB_SERDES_DUAL:
307 case E1000_DEV_ID_82571EB_SERDES_QUAD:
308 case E1000_DEV_ID_82572EI_SERDES:
309 hw->phy.media_type = e1000_media_type_internal_serdes;
310 mac->ops.setup_physical_interface =
311 e1000_setup_fiber_serdes_link_82571;
312 mac->ops.check_for_link = e1000_check_for_serdes_link_82571;
313 mac->ops.get_link_up_info =
314 e1000_get_speed_and_duplex_fiber_serdes_generic;
317 hw->phy.media_type = e1000_media_type_copper;
318 mac->ops.setup_physical_interface =
319 e1000_setup_copper_link_82571;
320 mac->ops.check_for_link = e1000_check_for_copper_link_generic;
321 mac->ops.get_link_up_info =
322 e1000_get_speed_and_duplex_copper_generic;
326 /* Set mta register count */
327 mac->mta_reg_count = 128;
328 /* Set rar entry count */
329 mac->rar_entry_count = E1000_RAR_ENTRIES;
330 /* Set if part includes ASF firmware */
331 mac->asf_firmware_present = TRUE;
332 /* Adaptive IFS supported */
333 mac->adaptive_ifs = TRUE;
335 /* Function pointers */
337 /* bus type/speed/width */
338 mac->ops.get_bus_info = e1000_get_bus_info_pcie_generic;
340 mac->ops.reset_hw = e1000_reset_hw_82571;
341 /* hw initialization */
342 mac->ops.init_hw = e1000_init_hw_82571;
344 mac->ops.setup_link = e1000_setup_link_82571;
345 /* multicast address update */
346 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
348 mac->ops.write_vfta = e1000_write_vfta_generic;
350 mac->ops.clear_vfta = e1000_clear_vfta_82571;
351 /* read mac address */
352 mac->ops.read_mac_addr = e1000_read_mac_addr_82571;
354 mac->ops.id_led_init = e1000_id_led_init_generic;
356 mac->ops.setup_led = e1000_setup_led_generic;
358 mac->ops.cleanup_led = e1000_cleanup_led_generic;
360 mac->ops.led_off = e1000_led_off_generic;
361 /* clear hardware counters */
362 mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82571;
364 /* MAC-specific function pointers */
365 switch (hw->mac.type) {
367 mac->ops.set_lan_id = e1000_set_lan_id_single_port;
368 mac->ops.check_mng_mode = e1000_check_mng_mode_generic;
369 mac->ops.led_on = e1000_led_on_generic;
370 mac->ops.blink_led = e1000_blink_led_generic;
373 mac->has_fwsm = TRUE;
374 /* ARC supported; valid only if manageability features are
377 mac->arc_subsystem_valid = !!(E1000_READ_REG(hw, E1000_FWSM) &
378 E1000_FWSM_MODE_MASK);
382 mac->ops.set_lan_id = e1000_set_lan_id_single_port;
383 mac->ops.check_mng_mode = e1000_check_mng_mode_82574;
384 mac->ops.led_on = e1000_led_on_82574;
387 mac->ops.check_mng_mode = e1000_check_mng_mode_generic;
388 mac->ops.led_on = e1000_led_on_generic;
389 mac->ops.blink_led = e1000_blink_led_generic;
392 mac->has_fwsm = TRUE;
396 /* Ensure that the inter-port SWSM.SMBI lock bit is clear before
397 * first NVM or PHY acess. This should be done for single-port
398 * devices, and for one port only on dual-port devices so that
399 * for those devices we can still use the SMBI lock to synchronize
400 * inter-port accesses to the PHY & NVM.
402 switch (hw->mac.type) {
405 swsm2 = E1000_READ_REG(hw, E1000_SWSM2);
407 if (!(swsm2 & E1000_SWSM2_LOCK)) {
408 /* Only do this for the first interface on this card */
409 E1000_WRITE_REG(hw, E1000_SWSM2, swsm2 |
411 force_clear_smbi = TRUE;
413 force_clear_smbi = FALSE;
417 force_clear_smbi = TRUE;
421 if (force_clear_smbi) {
422 /* Make sure SWSM.SMBI is clear */
423 swsm = E1000_READ_REG(hw, E1000_SWSM);
424 if (swsm & E1000_SWSM_SMBI) {
425 /* This bit should not be set on a first interface, and
426 * indicates that the bootagent or EFI code has
427 * improperly left this bit enabled
429 DEBUGOUT("Please update your 82571 Bootagent\n");
431 E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_SMBI);
434 /* Initialze device specific counter of SMBI acquisition timeouts. */
435 hw->dev_spec._82571.smb_counter = 0;
437 return E1000_SUCCESS;
441 * e1000_init_function_pointers_82571 - Init func ptrs.
442 * @hw: pointer to the HW structure
444 * Called to initialize all function pointers and parameters.
446 void e1000_init_function_pointers_82571(struct e1000_hw *hw)
448 DEBUGFUNC("e1000_init_function_pointers_82571");
450 hw->mac.ops.init_params = e1000_init_mac_params_82571;
451 hw->nvm.ops.init_params = e1000_init_nvm_params_82571;
452 hw->phy.ops.init_params = e1000_init_phy_params_82571;
456 * e1000_get_phy_id_82571 - Retrieve the PHY ID and revision
457 * @hw: pointer to the HW structure
459 * Reads the PHY registers and stores the PHY ID and possibly the PHY
460 * revision in the hardware structure.
462 static s32 e1000_get_phy_id_82571(struct e1000_hw *hw)
464 struct e1000_phy_info *phy = &hw->phy;
468 DEBUGFUNC("e1000_get_phy_id_82571");
470 switch (hw->mac.type) {
473 /* The 82571 firmware may still be configuring the PHY.
474 * In this case, we cannot access the PHY until the
475 * configuration is done. So we explicitly set the
478 phy->id = IGP01E1000_I_PHY_ID;
481 return e1000_get_phy_id(hw);
485 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
489 phy->id = (u32)(phy_id << 16);
491 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
495 phy->id |= (u32)(phy_id);
496 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
499 return -E1000_ERR_PHY;
503 return E1000_SUCCESS;
507 * e1000_get_hw_semaphore_82571 - Acquire hardware semaphore
508 * @hw: pointer to the HW structure
510 * Acquire the HW semaphore to access the PHY or NVM
512 static s32 e1000_get_hw_semaphore_82571(struct e1000_hw *hw)
515 s32 sw_timeout = hw->nvm.word_size + 1;
516 s32 fw_timeout = hw->nvm.word_size + 1;
519 DEBUGFUNC("e1000_get_hw_semaphore_82571");
521 /* If we have timedout 3 times on trying to acquire
522 * the inter-port SMBI semaphore, there is old code
523 * operating on the other port, and it is not
524 * releasing SMBI. Modify the number of times that
525 * we try for the semaphore to interwork with this
528 if (hw->dev_spec._82571.smb_counter > 2)
531 /* Get the SW semaphore */
532 while (i < sw_timeout) {
533 swsm = E1000_READ_REG(hw, E1000_SWSM);
534 if (!(swsm & E1000_SWSM_SMBI))
541 if (i == sw_timeout) {
542 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
543 hw->dev_spec._82571.smb_counter++;
545 /* Get the FW semaphore. */
546 for (i = 0; i < fw_timeout; i++) {
547 swsm = E1000_READ_REG(hw, E1000_SWSM);
548 E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
550 /* Semaphore acquired if bit latched */
551 if (E1000_READ_REG(hw, E1000_SWSM) & E1000_SWSM_SWESMBI)
557 if (i == fw_timeout) {
558 /* Release semaphores */
559 e1000_put_hw_semaphore_82571(hw);
560 DEBUGOUT("Driver can't access the NVM\n");
561 return -E1000_ERR_NVM;
564 return E1000_SUCCESS;
568 * e1000_put_hw_semaphore_82571 - Release hardware semaphore
569 * @hw: pointer to the HW structure
571 * Release hardware semaphore used to access the PHY or NVM
573 static void e1000_put_hw_semaphore_82571(struct e1000_hw *hw)
577 DEBUGFUNC("e1000_put_hw_semaphore_generic");
579 swsm = E1000_READ_REG(hw, E1000_SWSM);
581 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
583 E1000_WRITE_REG(hw, E1000_SWSM, swsm);
587 * e1000_get_hw_semaphore_82573 - Acquire hardware semaphore
588 * @hw: pointer to the HW structure
590 * Acquire the HW semaphore during reset.
593 static s32 e1000_get_hw_semaphore_82573(struct e1000_hw *hw)
598 DEBUGFUNC("e1000_get_hw_semaphore_82573");
600 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
602 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
603 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
604 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
606 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
611 } while (i < MDIO_OWNERSHIP_TIMEOUT);
613 if (i == MDIO_OWNERSHIP_TIMEOUT) {
614 /* Release semaphores */
615 e1000_put_hw_semaphore_82573(hw);
616 DEBUGOUT("Driver can't access the PHY\n");
617 return -E1000_ERR_PHY;
620 return E1000_SUCCESS;
624 * e1000_put_hw_semaphore_82573 - Release hardware semaphore
625 * @hw: pointer to the HW structure
627 * Release hardware semaphore used during reset.
630 static void e1000_put_hw_semaphore_82573(struct e1000_hw *hw)
634 DEBUGFUNC("e1000_put_hw_semaphore_82573");
636 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
637 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
638 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
642 * e1000_get_hw_semaphore_82574 - Acquire hardware semaphore
643 * @hw: pointer to the HW structure
645 * Acquire the HW semaphore to access the PHY or NVM.
648 static s32 e1000_get_hw_semaphore_82574(struct e1000_hw *hw)
652 DEBUGFUNC("e1000_get_hw_semaphore_82574");
654 ret_val = e1000_get_hw_semaphore_82573(hw);
659 * e1000_put_hw_semaphore_82574 - Release hardware semaphore
660 * @hw: pointer to the HW structure
662 * Release hardware semaphore used to access the PHY or NVM
665 static void e1000_put_hw_semaphore_82574(struct e1000_hw *hw)
667 DEBUGFUNC("e1000_put_hw_semaphore_82574");
669 e1000_put_hw_semaphore_82573(hw);
673 * e1000_set_d0_lplu_state_82574 - Set Low Power Linkup D0 state
674 * @hw: pointer to the HW structure
675 * @active: TRUE to enable LPLU, FALSE to disable
677 * Sets the LPLU D0 state according to the active flag.
678 * LPLU will not be activated unless the
679 * device autonegotiation advertisement meets standards of
680 * either 10 or 10/100 or 10/100/1000 at all duplexes.
681 * This is a function pointer entry point only called by
682 * PHY setup routines.
684 static s32 e1000_set_d0_lplu_state_82574(struct e1000_hw *hw, bool active)
686 u32 data = E1000_READ_REG(hw, E1000_POEMB);
688 DEBUGFUNC("e1000_set_d0_lplu_state_82574");
691 data |= E1000_PHY_CTRL_D0A_LPLU;
693 data &= ~E1000_PHY_CTRL_D0A_LPLU;
695 E1000_WRITE_REG(hw, E1000_POEMB, data);
696 return E1000_SUCCESS;
700 * e1000_set_d3_lplu_state_82574 - Sets low power link up state for D3
701 * @hw: pointer to the HW structure
702 * @active: boolean used to enable/disable lplu
704 * The low power link up (lplu) state is set to the power management level D3
705 * when active is TRUE, else clear lplu for D3. LPLU
706 * is used during Dx states where the power conservation is most important.
707 * During driver activity, SmartSpeed should be enabled so performance is
710 static s32 e1000_set_d3_lplu_state_82574(struct e1000_hw *hw, bool active)
712 u32 data = E1000_READ_REG(hw, E1000_POEMB);
714 DEBUGFUNC("e1000_set_d3_lplu_state_82574");
717 data &= ~E1000_PHY_CTRL_NOND0A_LPLU;
718 } else if ((hw->phy.autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
719 (hw->phy.autoneg_advertised == E1000_ALL_NOT_GIG) ||
720 (hw->phy.autoneg_advertised == E1000_ALL_10_SPEED)) {
721 data |= E1000_PHY_CTRL_NOND0A_LPLU;
724 E1000_WRITE_REG(hw, E1000_POEMB, data);
725 return E1000_SUCCESS;
729 * e1000_acquire_nvm_82571 - Request for access to the EEPROM
730 * @hw: pointer to the HW structure
732 * To gain access to the EEPROM, first we must obtain a hardware semaphore.
733 * Then for non-82573 hardware, set the EEPROM access request bit and wait
734 * for EEPROM access grant bit. If the access grant bit is not set, release
735 * hardware semaphore.
737 static s32 e1000_acquire_nvm_82571(struct e1000_hw *hw)
741 DEBUGFUNC("e1000_acquire_nvm_82571");
743 ret_val = e1000_get_hw_semaphore_82571(hw);
747 switch (hw->mac.type) {
751 ret_val = e1000_acquire_nvm_generic(hw);
756 e1000_put_hw_semaphore_82571(hw);
762 * e1000_release_nvm_82571 - Release exclusive access to EEPROM
763 * @hw: pointer to the HW structure
765 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
767 static void e1000_release_nvm_82571(struct e1000_hw *hw)
769 DEBUGFUNC("e1000_release_nvm_82571");
771 e1000_release_nvm_generic(hw);
772 e1000_put_hw_semaphore_82571(hw);
776 * e1000_write_nvm_82571 - Write to EEPROM using appropriate interface
777 * @hw: pointer to the HW structure
778 * @offset: offset within the EEPROM to be written to
779 * @words: number of words to write
780 * @data: 16 bit word(s) to be written to the EEPROM
782 * For non-82573 silicon, write data to EEPROM at offset using SPI interface.
784 * If e1000_update_nvm_checksum is not called after this function, the
785 * EEPROM will most likely contain an invalid checksum.
787 static s32 e1000_write_nvm_82571(struct e1000_hw *hw, u16 offset, u16 words,
792 DEBUGFUNC("e1000_write_nvm_82571");
794 switch (hw->mac.type) {
798 ret_val = e1000_write_nvm_eewr_82571(hw, offset, words, data);
802 ret_val = e1000_write_nvm_spi(hw, offset, words, data);
805 ret_val = -E1000_ERR_NVM;
813 * e1000_update_nvm_checksum_82571 - Update EEPROM checksum
814 * @hw: pointer to the HW structure
816 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
817 * up to the checksum. Then calculates the EEPROM checksum and writes the
818 * value to the EEPROM.
820 static s32 e1000_update_nvm_checksum_82571(struct e1000_hw *hw)
826 DEBUGFUNC("e1000_update_nvm_checksum_82571");
828 ret_val = e1000_update_nvm_checksum_generic(hw);
832 /* If our nvm is an EEPROM, then we're done
833 * otherwise, commit the checksum to the flash NVM.
835 if (hw->nvm.type != e1000_nvm_flash_hw)
836 return E1000_SUCCESS;
838 /* Check for pending operations. */
839 for (i = 0; i < E1000_FLASH_UPDATES; i++) {
841 if (!(E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_FLUPD))
845 if (i == E1000_FLASH_UPDATES)
846 return -E1000_ERR_NVM;
848 /* Reset the firmware if using STM opcode. */
849 if ((E1000_READ_REG(hw, E1000_FLOP) & 0xFF00) == E1000_STM_OPCODE) {
850 /* The enabling of and the actual reset must be done
851 * in two write cycles.
853 E1000_WRITE_REG(hw, E1000_HICR, E1000_HICR_FW_RESET_ENABLE);
854 E1000_WRITE_FLUSH(hw);
855 E1000_WRITE_REG(hw, E1000_HICR, E1000_HICR_FW_RESET);
858 /* Commit the write to flash */
859 eecd = E1000_READ_REG(hw, E1000_EECD) | E1000_EECD_FLUPD;
860 E1000_WRITE_REG(hw, E1000_EECD, eecd);
862 for (i = 0; i < E1000_FLASH_UPDATES; i++) {
864 if (!(E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_FLUPD))
868 if (i == E1000_FLASH_UPDATES)
869 return -E1000_ERR_NVM;
871 return E1000_SUCCESS;
875 * e1000_validate_nvm_checksum_82571 - Validate EEPROM checksum
876 * @hw: pointer to the HW structure
878 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
879 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
881 static s32 e1000_validate_nvm_checksum_82571(struct e1000_hw *hw)
883 DEBUGFUNC("e1000_validate_nvm_checksum_82571");
885 if (hw->nvm.type == e1000_nvm_flash_hw)
886 e1000_fix_nvm_checksum_82571(hw);
888 return e1000_validate_nvm_checksum_generic(hw);
892 * e1000_write_nvm_eewr_82571 - Write to EEPROM for 82573 silicon
893 * @hw: pointer to the HW structure
894 * @offset: offset within the EEPROM to be written to
895 * @words: number of words to write
896 * @data: 16 bit word(s) to be written to the EEPROM
898 * After checking for invalid values, poll the EEPROM to ensure the previous
899 * command has completed before trying to write the next word. After write
900 * poll for completion.
902 * If e1000_update_nvm_checksum is not called after this function, the
903 * EEPROM will most likely contain an invalid checksum.
905 static s32 e1000_write_nvm_eewr_82571(struct e1000_hw *hw, u16 offset,
906 u16 words, u16 *data)
908 struct e1000_nvm_info *nvm = &hw->nvm;
910 s32 ret_val = E1000_SUCCESS;
912 DEBUGFUNC("e1000_write_nvm_eewr_82571");
914 /* A check for invalid values: offset too large, too many words,
915 * and not enough words.
917 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
919 DEBUGOUT("nvm parameter(s) out of bounds\n");
920 return -E1000_ERR_NVM;
923 for (i = 0; i < words; i++) {
924 eewr = ((data[i] << E1000_NVM_RW_REG_DATA) |
925 ((offset + i) << E1000_NVM_RW_ADDR_SHIFT) |
926 E1000_NVM_RW_REG_START);
928 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
932 E1000_WRITE_REG(hw, E1000_EEWR, eewr);
934 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_WRITE);
943 * e1000_get_cfg_done_82571 - Poll for configuration done
944 * @hw: pointer to the HW structure
946 * Reads the management control register for the config done bit to be set.
948 static s32 e1000_get_cfg_done_82571(struct e1000_hw *hw)
950 s32 timeout = PHY_CFG_TIMEOUT;
952 DEBUGFUNC("e1000_get_cfg_done_82571");
955 if (E1000_READ_REG(hw, E1000_EEMNGCTL) &
956 E1000_NVM_CFG_DONE_PORT_0)
962 DEBUGOUT("MNG configuration cycle has not completed.\n");
963 return -E1000_ERR_RESET;
966 return E1000_SUCCESS;
970 * e1000_set_d0_lplu_state_82571 - Set Low Power Linkup D0 state
971 * @hw: pointer to the HW structure
972 * @active: TRUE to enable LPLU, FALSE to disable
974 * Sets the LPLU D0 state according to the active flag. When activating LPLU
975 * this function also disables smart speed and vice versa. LPLU will not be
976 * activated unless the device autonegotiation advertisement meets standards
977 * of either 10 or 10/100 or 10/100/1000 at all duplexes. This is a function
978 * pointer entry point only called by PHY setup routines.
980 static s32 e1000_set_d0_lplu_state_82571(struct e1000_hw *hw, bool active)
982 struct e1000_phy_info *phy = &hw->phy;
986 DEBUGFUNC("e1000_set_d0_lplu_state_82571");
988 if (!(phy->ops.read_reg))
989 return E1000_SUCCESS;
991 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
996 data |= IGP02E1000_PM_D0_LPLU;
997 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1002 /* When LPLU is enabled, we should disable SmartSpeed */
1003 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1007 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1008 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1013 data &= ~IGP02E1000_PM_D0_LPLU;
1014 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1016 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
1017 * during Dx states where the power conservation is most
1018 * important. During driver activity we should enable
1019 * SmartSpeed, so performance is maintained.
1021 if (phy->smart_speed == e1000_smart_speed_on) {
1022 ret_val = phy->ops.read_reg(hw,
1023 IGP01E1000_PHY_PORT_CONFIG,
1028 data |= IGP01E1000_PSCFR_SMART_SPEED;
1029 ret_val = phy->ops.write_reg(hw,
1030 IGP01E1000_PHY_PORT_CONFIG,
1034 } else if (phy->smart_speed == e1000_smart_speed_off) {
1035 ret_val = phy->ops.read_reg(hw,
1036 IGP01E1000_PHY_PORT_CONFIG,
1041 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1042 ret_val = phy->ops.write_reg(hw,
1043 IGP01E1000_PHY_PORT_CONFIG,
1050 return E1000_SUCCESS;
1054 * e1000_reset_hw_82571 - Reset hardware
1055 * @hw: pointer to the HW structure
1057 * This resets the hardware into a known state.
1059 static s32 e1000_reset_hw_82571(struct e1000_hw *hw)
1061 u32 ctrl, ctrl_ext, eecd, tctl;
1064 DEBUGFUNC("e1000_reset_hw_82571");
1066 /* Prevent the PCI-E bus from sticking if there is no TLP connection
1067 * on the last TLP read/write transaction when MAC is reset.
1069 ret_val = e1000_disable_pcie_master_generic(hw);
1071 DEBUGOUT("PCI-E Master disable polling has failed.\n");
1073 DEBUGOUT("Masking off all interrupts\n");
1074 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
1076 E1000_WRITE_REG(hw, E1000_RCTL, 0);
1077 tctl = E1000_READ_REG(hw, E1000_TCTL);
1078 tctl &= ~E1000_TCTL_EN;
1079 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1080 E1000_WRITE_FLUSH(hw);
1084 /* Must acquire the MDIO ownership before MAC reset.
1085 * Ownership defaults to firmware after a reset.
1087 switch (hw->mac.type) {
1089 ret_val = e1000_get_hw_semaphore_82573(hw);
1093 ret_val = e1000_get_hw_semaphore_82574(hw);
1099 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1101 DEBUGOUT("Issuing a global reset to MAC\n");
1102 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
1104 /* Must release MDIO ownership and mutex after MAC reset. */
1105 switch (hw->mac.type) {
1107 /* Release mutex only if the hw semaphore is acquired */
1109 e1000_put_hw_semaphore_82573(hw);
1113 /* Release mutex only if the hw semaphore is acquired */
1115 e1000_put_hw_semaphore_82574(hw);
1121 if (hw->nvm.type == e1000_nvm_flash_hw) {
1123 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1124 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1125 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1126 E1000_WRITE_FLUSH(hw);
1129 ret_val = e1000_get_auto_rd_done_generic(hw);
1131 /* We don't want to continue accessing MAC registers. */
1134 /* Phy configuration from NVM just starts after EECD_AUTO_RD is set.
1135 * Need to wait for Phy configuration completion before accessing
1139 switch (hw->mac.type) {
1142 /* REQ and GNT bits need to be cleared when using AUTO_RD
1143 * to access the EEPROM.
1145 eecd = E1000_READ_REG(hw, E1000_EECD);
1146 eecd &= ~(E1000_EECD_REQ | E1000_EECD_GNT);
1147 E1000_WRITE_REG(hw, E1000_EECD, eecd);
1158 /* Clear any pending interrupt events. */
1159 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
1160 E1000_READ_REG(hw, E1000_ICR);
1162 if (hw->mac.type == e1000_82571) {
1163 /* Install any alternate MAC address into RAR0 */
1164 ret_val = e1000_check_alt_mac_addr_generic(hw);
1168 e1000_set_laa_state_82571(hw, TRUE);
1171 /* Reinitialize the 82571 serdes link state machine */
1172 if (hw->phy.media_type == e1000_media_type_internal_serdes)
1173 hw->mac.serdes_link_state = e1000_serdes_link_down;
1175 return E1000_SUCCESS;
1179 * e1000_init_hw_82571 - Initialize hardware
1180 * @hw: pointer to the HW structure
1182 * This inits the hardware readying it for operation.
1184 static s32 e1000_init_hw_82571(struct e1000_hw *hw)
1186 struct e1000_mac_info *mac = &hw->mac;
1189 u16 i, rar_count = mac->rar_entry_count;
1191 DEBUGFUNC("e1000_init_hw_82571");
1193 e1000_initialize_hw_bits_82571(hw);
1195 /* Initialize identification LED */
1196 ret_val = mac->ops.id_led_init(hw);
1197 /* An error is not fatal and we should not stop init due to this */
1199 DEBUGOUT("Error initializing identification LED\n");
1201 /* Disabling VLAN filtering */
1202 DEBUGOUT("Initializing the IEEE VLAN\n");
1203 mac->ops.clear_vfta(hw);
1205 /* Setup the receive address.
1206 * If, however, a locally administered address was assigned to the
1207 * 82571, we must reserve a RAR for it to work around an issue where
1208 * resetting one port will reload the MAC on the other port.
1210 if (e1000_get_laa_state_82571(hw))
1212 e1000_init_rx_addrs_generic(hw, rar_count);
1214 /* Zero out the Multicast HASH table */
1215 DEBUGOUT("Zeroing the MTA\n");
1216 for (i = 0; i < mac->mta_reg_count; i++)
1217 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
1219 /* Setup link and flow control */
1220 ret_val = mac->ops.setup_link(hw);
1222 /* Set the transmit descriptor write-back policy */
1223 reg_data = E1000_READ_REG(hw, E1000_TXDCTL(0));
1224 reg_data = ((reg_data & ~E1000_TXDCTL_WTHRESH) |
1225 E1000_TXDCTL_FULL_TX_DESC_WB | E1000_TXDCTL_COUNT_DESC);
1226 E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg_data);
1228 /* ...for both queues. */
1229 switch (mac->type) {
1231 e1000_enable_tx_pkt_filtering_generic(hw);
1235 reg_data = E1000_READ_REG(hw, E1000_GCR);
1236 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1237 E1000_WRITE_REG(hw, E1000_GCR, reg_data);
1240 reg_data = E1000_READ_REG(hw, E1000_TXDCTL(1));
1241 reg_data = ((reg_data & ~E1000_TXDCTL_WTHRESH) |
1242 E1000_TXDCTL_FULL_TX_DESC_WB |
1243 E1000_TXDCTL_COUNT_DESC);
1244 E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg_data);
1248 /* Clear all of the statistics registers (clear on read). It is
1249 * important that we do this after we have tried to establish link
1250 * because the symbol error count will increment wildly if there
1253 e1000_clear_hw_cntrs_82571(hw);
1259 * e1000_initialize_hw_bits_82571 - Initialize hardware-dependent bits
1260 * @hw: pointer to the HW structure
1262 * Initializes required hardware-dependent bits needed for normal operation.
1264 static void e1000_initialize_hw_bits_82571(struct e1000_hw *hw)
1268 DEBUGFUNC("e1000_initialize_hw_bits_82571");
1270 /* Transmit Descriptor Control 0 */
1271 reg = E1000_READ_REG(hw, E1000_TXDCTL(0));
1273 E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg);
1275 /* Transmit Descriptor Control 1 */
1276 reg = E1000_READ_REG(hw, E1000_TXDCTL(1));
1278 E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg);
1280 /* Transmit Arbitration Control 0 */
1281 reg = E1000_READ_REG(hw, E1000_TARC(0));
1282 reg &= ~(0xF << 27); /* 30:27 */
1283 switch (hw->mac.type) {
1286 reg |= (1 << 23) | (1 << 24) | (1 << 25) | (1 << 26);
1295 E1000_WRITE_REG(hw, E1000_TARC(0), reg);
1297 /* Transmit Arbitration Control 1 */
1298 reg = E1000_READ_REG(hw, E1000_TARC(1));
1299 switch (hw->mac.type) {
1302 reg &= ~((1 << 29) | (1 << 30));
1303 reg |= (1 << 22) | (1 << 24) | (1 << 25) | (1 << 26);
1304 if (E1000_READ_REG(hw, E1000_TCTL) & E1000_TCTL_MULR)
1308 E1000_WRITE_REG(hw, E1000_TARC(1), reg);
1314 /* Device Control */
1315 switch (hw->mac.type) {
1319 reg = E1000_READ_REG(hw, E1000_CTRL);
1321 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1327 /* Extended Device Control */
1328 switch (hw->mac.type) {
1332 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1335 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1341 if (hw->mac.type == e1000_82571) {
1342 reg = E1000_READ_REG(hw, E1000_PBA_ECC);
1343 reg |= E1000_PBA_ECC_CORR_EN;
1344 E1000_WRITE_REG(hw, E1000_PBA_ECC, reg);
1347 /* Workaround for hardware errata.
1348 * Ensure that DMA Dynamic Clock gating is disabled on 82571 and 82572
1350 if ((hw->mac.type == e1000_82571) ||
1351 (hw->mac.type == e1000_82572)) {
1352 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1353 reg &= ~E1000_CTRL_EXT_DMA_DYN_CLK_EN;
1354 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1357 /* Disable IPv6 extension header parsing because some malformed
1358 * IPv6 headers can hang the Rx.
1360 if (hw->mac.type <= e1000_82573) {
1361 reg = E1000_READ_REG(hw, E1000_RFCTL);
1362 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
1363 E1000_WRITE_REG(hw, E1000_RFCTL, reg);
1366 /* PCI-Ex Control Registers */
1367 switch (hw->mac.type) {
1370 reg = E1000_READ_REG(hw, E1000_GCR);
1372 E1000_WRITE_REG(hw, E1000_GCR, reg);
1374 /* Workaround for hardware errata.
1375 * apply workaround for hardware errata documented in errata
1376 * docs Fixes issue where some error prone or unreliable PCIe
1377 * completions are occurring, particularly with ASPM enabled.
1378 * Without fix, issue can cause Tx timeouts.
1380 reg = E1000_READ_REG(hw, E1000_GCR2);
1382 E1000_WRITE_REG(hw, E1000_GCR2, reg);
1392 * e1000_clear_vfta_82571 - Clear VLAN filter table
1393 * @hw: pointer to the HW structure
1395 * Clears the register array which contains the VLAN filter table by
1396 * setting all the values to 0.
1398 static void e1000_clear_vfta_82571(struct e1000_hw *hw)
1402 u32 vfta_offset = 0;
1403 u32 vfta_bit_in_reg = 0;
1405 DEBUGFUNC("e1000_clear_vfta_82571");
1407 switch (hw->mac.type) {
1411 if (hw->mng_cookie.vlan_id != 0) {
1412 /* The VFTA is a 4096b bit-field, each identifying
1413 * a single VLAN ID. The following operations
1414 * determine which 32b entry (i.e. offset) into the
1415 * array we want to set the VLAN ID (i.e. bit) of
1416 * the manageability unit.
1418 vfta_offset = (hw->mng_cookie.vlan_id >>
1419 E1000_VFTA_ENTRY_SHIFT) &
1420 E1000_VFTA_ENTRY_MASK;
1422 1 << (hw->mng_cookie.vlan_id &
1423 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
1429 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
1430 /* If the offset we want to clear is the same offset of the
1431 * manageability VLAN ID, then clear all bits except that of
1432 * the manageability unit.
1434 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
1435 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, vfta_value);
1436 E1000_WRITE_FLUSH(hw);
1441 * e1000_check_mng_mode_82574 - Check manageability is enabled
1442 * @hw: pointer to the HW structure
1444 * Reads the NVM Initialization Control Word 2 and returns TRUE
1445 * (>0) if any manageability is enabled, else FALSE (0).
1447 static bool e1000_check_mng_mode_82574(struct e1000_hw *hw)
1452 DEBUGFUNC("e1000_check_mng_mode_82574");
1454 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &data);
1458 return (data & E1000_NVM_INIT_CTRL2_MNGM) != 0;
1462 * e1000_led_on_82574 - Turn LED on
1463 * @hw: pointer to the HW structure
1467 static s32 e1000_led_on_82574(struct e1000_hw *hw)
1472 DEBUGFUNC("e1000_led_on_82574");
1474 ctrl = hw->mac.ledctl_mode2;
1475 if (!(E1000_STATUS_LU & E1000_READ_REG(hw, E1000_STATUS))) {
1476 /* If no link, then turn LED on by setting the invert bit
1477 * for each LED that's "on" (0x0E) in ledctl_mode2.
1479 for (i = 0; i < 4; i++)
1480 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1481 E1000_LEDCTL_MODE_LED_ON)
1482 ctrl |= (E1000_LEDCTL_LED0_IVRT << (i * 8));
1484 E1000_WRITE_REG(hw, E1000_LEDCTL, ctrl);
1486 return E1000_SUCCESS;
1490 * e1000_check_phy_82574 - check 82574 phy hung state
1491 * @hw: pointer to the HW structure
1493 * Returns whether phy is hung or not
1495 bool e1000_check_phy_82574(struct e1000_hw *hw)
1497 u16 status_1kbt = 0;
1498 u16 receive_errors = 0;
1501 DEBUGFUNC("e1000_check_phy_82574");
1503 /* Read PHY Receive Error counter first, if its is max - all F's then
1504 * read the Base1000T status register If both are max then PHY is hung.
1506 ret_val = hw->phy.ops.read_reg(hw, E1000_RECEIVE_ERROR_COUNTER,
1510 if (receive_errors == E1000_RECEIVE_ERROR_MAX) {
1511 ret_val = hw->phy.ops.read_reg(hw, E1000_BASE1000T_STATUS,
1515 if ((status_1kbt & E1000_IDLE_ERROR_COUNT_MASK) ==
1516 E1000_IDLE_ERROR_COUNT_MASK)
1525 * e1000_setup_link_82571 - Setup flow control and link settings
1526 * @hw: pointer to the HW structure
1528 * Determines which flow control settings to use, then configures flow
1529 * control. Calls the appropriate media-specific link configuration
1530 * function. Assuming the adapter has a valid link partner, a valid link
1531 * should be established. Assumes the hardware has previously been reset
1532 * and the transmitter and receiver are not enabled.
1534 static s32 e1000_setup_link_82571(struct e1000_hw *hw)
1536 DEBUGFUNC("e1000_setup_link_82571");
1538 /* 82573 does not have a word in the NVM to determine
1539 * the default flow control setting, so we explicitly
1542 switch (hw->mac.type) {
1546 if (hw->fc.requested_mode == e1000_fc_default)
1547 hw->fc.requested_mode = e1000_fc_full;
1553 return e1000_setup_link_generic(hw);
1557 * e1000_setup_copper_link_82571 - Configure copper link settings
1558 * @hw: pointer to the HW structure
1560 * Configures the link for auto-neg or forced speed and duplex. Then we check
1561 * for link, once link is established calls to configure collision distance
1562 * and flow control are called.
1564 static s32 e1000_setup_copper_link_82571(struct e1000_hw *hw)
1569 DEBUGFUNC("e1000_setup_copper_link_82571");
1571 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1572 ctrl |= E1000_CTRL_SLU;
1573 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1574 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1576 switch (hw->phy.type) {
1579 ret_val = e1000_copper_link_setup_m88(hw);
1581 case e1000_phy_igp_2:
1582 ret_val = e1000_copper_link_setup_igp(hw);
1585 return -E1000_ERR_PHY;
1592 return e1000_setup_copper_link_generic(hw);
1596 * e1000_setup_fiber_serdes_link_82571 - Setup link for fiber/serdes
1597 * @hw: pointer to the HW structure
1599 * Configures collision distance and flow control for fiber and serdes links.
1600 * Upon successful setup, poll for link.
1602 static s32 e1000_setup_fiber_serdes_link_82571(struct e1000_hw *hw)
1604 DEBUGFUNC("e1000_setup_fiber_serdes_link_82571");
1606 switch (hw->mac.type) {
1609 /* If SerDes loopback mode is entered, there is no form
1610 * of reset to take the adapter out of that mode. So we
1611 * have to explicitly take the adapter out of loopback
1612 * mode. This prevents drivers from twiddling their thumbs
1613 * if another tool failed to take it out of loopback mode.
1615 E1000_WRITE_REG(hw, E1000_SCTL,
1616 E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1622 return e1000_setup_fiber_serdes_link_generic(hw);
1626 * e1000_check_for_serdes_link_82571 - Check for link (Serdes)
1627 * @hw: pointer to the HW structure
1629 * Reports the link state as up or down.
1631 * If autonegotiation is supported by the link partner, the link state is
1632 * determined by the result of autonegotiation. This is the most likely case.
1633 * If autonegotiation is not supported by the link partner, and the link
1634 * has a valid signal, force the link up.
1636 * The link state is represented internally here by 4 states:
1639 * 2) autoneg_progress
1640 * 3) autoneg_complete (the link successfully autonegotiated)
1641 * 4) forced_up (the link has been forced up, it did not autonegotiate)
1644 static s32 e1000_check_for_serdes_link_82571(struct e1000_hw *hw)
1646 struct e1000_mac_info *mac = &hw->mac;
1652 s32 ret_val = E1000_SUCCESS;
1654 DEBUGFUNC("e1000_check_for_serdes_link_82571");
1656 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1657 status = E1000_READ_REG(hw, E1000_STATUS);
1658 E1000_READ_REG(hw, E1000_RXCW);
1659 /* SYNCH bit and IV bit are sticky */
1661 rxcw = E1000_READ_REG(hw, E1000_RXCW);
1663 if ((rxcw & E1000_RXCW_SYNCH) && !(rxcw & E1000_RXCW_IV)) {
1664 /* Receiver is synchronized with no invalid bits. */
1665 switch (mac->serdes_link_state) {
1666 case e1000_serdes_link_autoneg_complete:
1667 if (!(status & E1000_STATUS_LU)) {
1668 /* We have lost link, retry autoneg before
1669 * reporting link failure
1671 mac->serdes_link_state =
1672 e1000_serdes_link_autoneg_progress;
1673 mac->serdes_has_link = FALSE;
1674 DEBUGOUT("AN_UP -> AN_PROG\n");
1676 mac->serdes_has_link = TRUE;
1680 case e1000_serdes_link_forced_up:
1681 /* If we are receiving /C/ ordered sets, re-enable
1682 * auto-negotiation in the TXCW register and disable
1683 * forced link in the Device Control register in an
1684 * attempt to auto-negotiate with our link partner.
1686 if (rxcw & E1000_RXCW_C) {
1687 /* Enable autoneg, and unforce link up */
1688 E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
1689 E1000_WRITE_REG(hw, E1000_CTRL,
1690 (ctrl & ~E1000_CTRL_SLU));
1691 mac->serdes_link_state =
1692 e1000_serdes_link_autoneg_progress;
1693 mac->serdes_has_link = FALSE;
1694 DEBUGOUT("FORCED_UP -> AN_PROG\n");
1696 mac->serdes_has_link = TRUE;
1700 case e1000_serdes_link_autoneg_progress:
1701 if (rxcw & E1000_RXCW_C) {
1702 /* We received /C/ ordered sets, meaning the
1703 * link partner has autonegotiated, and we can
1704 * trust the Link Up (LU) status bit.
1706 if (status & E1000_STATUS_LU) {
1707 mac->serdes_link_state =
1708 e1000_serdes_link_autoneg_complete;
1709 DEBUGOUT("AN_PROG -> AN_UP\n");
1710 mac->serdes_has_link = TRUE;
1712 /* Autoneg completed, but failed. */
1713 mac->serdes_link_state =
1714 e1000_serdes_link_down;
1715 DEBUGOUT("AN_PROG -> DOWN\n");
1718 /* The link partner did not autoneg.
1719 * Force link up and full duplex, and change
1722 E1000_WRITE_REG(hw, E1000_TXCW,
1723 (mac->txcw & ~E1000_TXCW_ANE));
1724 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
1725 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1727 /* Configure Flow Control after link up. */
1729 e1000_config_fc_after_link_up_generic(hw);
1731 DEBUGOUT("Error config flow control\n");
1734 mac->serdes_link_state =
1735 e1000_serdes_link_forced_up;
1736 mac->serdes_has_link = TRUE;
1737 DEBUGOUT("AN_PROG -> FORCED_UP\n");
1741 case e1000_serdes_link_down:
1743 /* The link was down but the receiver has now gained
1744 * valid sync, so lets see if we can bring the link
1747 E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
1748 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl &
1750 mac->serdes_link_state =
1751 e1000_serdes_link_autoneg_progress;
1752 mac->serdes_has_link = FALSE;
1753 DEBUGOUT("DOWN -> AN_PROG\n");
1757 if (!(rxcw & E1000_RXCW_SYNCH)) {
1758 mac->serdes_has_link = FALSE;
1759 mac->serdes_link_state = e1000_serdes_link_down;
1760 DEBUGOUT("ANYSTATE -> DOWN\n");
1762 /* Check several times, if SYNCH bit and CONFIG
1763 * bit both are consistently 1 then simply ignore
1764 * the IV bit and restart Autoneg
1766 for (i = 0; i < AN_RETRY_COUNT; i++) {
1768 rxcw = E1000_READ_REG(hw, E1000_RXCW);
1769 if ((rxcw & E1000_RXCW_SYNCH) &&
1770 (rxcw & E1000_RXCW_C))
1773 if (rxcw & E1000_RXCW_IV) {
1774 mac->serdes_has_link = FALSE;
1775 mac->serdes_link_state =
1776 e1000_serdes_link_down;
1777 DEBUGOUT("ANYSTATE -> DOWN\n");
1782 if (i == AN_RETRY_COUNT) {
1783 txcw = E1000_READ_REG(hw, E1000_TXCW);
1784 txcw |= E1000_TXCW_ANE;
1785 E1000_WRITE_REG(hw, E1000_TXCW, txcw);
1786 mac->serdes_link_state =
1787 e1000_serdes_link_autoneg_progress;
1788 mac->serdes_has_link = FALSE;
1789 DEBUGOUT("ANYSTATE -> AN_PROG\n");
1798 * e1000_valid_led_default_82571 - Verify a valid default LED config
1799 * @hw: pointer to the HW structure
1800 * @data: pointer to the NVM (EEPROM)
1802 * Read the EEPROM for the current default LED configuration. If the
1803 * LED configuration is not valid, set to a valid LED configuration.
1805 static s32 e1000_valid_led_default_82571(struct e1000_hw *hw, u16 *data)
1809 DEBUGFUNC("e1000_valid_led_default_82571");
1811 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
1813 DEBUGOUT("NVM Read Error\n");
1817 switch (hw->mac.type) {
1821 if (*data == ID_LED_RESERVED_F746)
1822 *data = ID_LED_DEFAULT_82573;
1825 if (*data == ID_LED_RESERVED_0000 ||
1826 *data == ID_LED_RESERVED_FFFF)
1827 *data = ID_LED_DEFAULT;
1831 return E1000_SUCCESS;
1835 * e1000_get_laa_state_82571 - Get locally administered address state
1836 * @hw: pointer to the HW structure
1838 * Retrieve and return the current locally administered address state.
1840 bool e1000_get_laa_state_82571(struct e1000_hw *hw)
1842 DEBUGFUNC("e1000_get_laa_state_82571");
1844 if (hw->mac.type != e1000_82571)
1847 return hw->dev_spec._82571.laa_is_present;
1851 * e1000_set_laa_state_82571 - Set locally administered address state
1852 * @hw: pointer to the HW structure
1853 * @state: enable/disable locally administered address
1855 * Enable/Disable the current locally administered address state.
1857 void e1000_set_laa_state_82571(struct e1000_hw *hw, bool state)
1859 DEBUGFUNC("e1000_set_laa_state_82571");
1861 if (hw->mac.type != e1000_82571)
1864 hw->dev_spec._82571.laa_is_present = state;
1866 /* If workaround is activated... */
1868 /* Hold a copy of the LAA in RAR[14] This is done so that
1869 * between the time RAR[0] gets clobbered and the time it
1870 * gets fixed, the actual LAA is in one of the RARs and no
1871 * incoming packets directed to this port are dropped.
1872 * Eventually the LAA will be in RAR[0] and RAR[14].
1874 hw->mac.ops.rar_set(hw, hw->mac.addr,
1875 hw->mac.rar_entry_count - 1);
1880 * e1000_fix_nvm_checksum_82571 - Fix EEPROM checksum
1881 * @hw: pointer to the HW structure
1883 * Verifies that the EEPROM has completed the update. After updating the
1884 * EEPROM, we need to check bit 15 in work 0x23 for the checksum fix. If
1885 * the checksum fix is not implemented, we need to set the bit and update
1886 * the checksum. Otherwise, if bit 15 is set and the checksum is incorrect,
1887 * we need to return bad checksum.
1889 static s32 e1000_fix_nvm_checksum_82571(struct e1000_hw *hw)
1891 struct e1000_nvm_info *nvm = &hw->nvm;
1895 DEBUGFUNC("e1000_fix_nvm_checksum_82571");
1897 if (nvm->type != e1000_nvm_flash_hw)
1898 return E1000_SUCCESS;
1900 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
1901 * 10h-12h. Checksum may need to be fixed.
1903 ret_val = nvm->ops.read(hw, 0x10, 1, &data);
1907 if (!(data & 0x10)) {
1908 /* Read 0x23 and check bit 15. This bit is a 1
1909 * when the checksum has already been fixed. If
1910 * the checksum is still wrong and this bit is a
1911 * 1, we need to return bad checksum. Otherwise,
1912 * we need to set this bit to a 1 and update the
1915 ret_val = nvm->ops.read(hw, 0x23, 1, &data);
1919 if (!(data & 0x8000)) {
1921 ret_val = nvm->ops.write(hw, 0x23, 1, &data);
1924 ret_val = nvm->ops.update(hw);
1930 return E1000_SUCCESS;
1935 * e1000_read_mac_addr_82571 - Read device MAC address
1936 * @hw: pointer to the HW structure
1938 static s32 e1000_read_mac_addr_82571(struct e1000_hw *hw)
1940 DEBUGFUNC("e1000_read_mac_addr_82571");
1942 if (hw->mac.type == e1000_82571) {
1945 /* If there's an alternate MAC address place it in RAR0
1946 * so that it will override the Si installed default perm
1949 ret_val = e1000_check_alt_mac_addr_generic(hw);
1954 return e1000_read_mac_addr_generic(hw);
1958 * e1000_power_down_phy_copper_82571 - Remove link during PHY power down
1959 * @hw: pointer to the HW structure
1961 * In the case of a PHY power down to save power, or to turn off link during a
1962 * driver unload, or wake on lan is not enabled, remove the link.
1964 static void e1000_power_down_phy_copper_82571(struct e1000_hw *hw)
1966 struct e1000_phy_info *phy = &hw->phy;
1967 struct e1000_mac_info *mac = &hw->mac;
1969 if (!phy->ops.check_reset_block)
1972 /* If the management interface is not enabled, then power down */
1973 if (!(mac->ops.check_mng_mode(hw) || phy->ops.check_reset_block(hw)))
1974 e1000_power_down_phy_copper(hw);
1980 * e1000_clear_hw_cntrs_82571 - Clear device specific hardware counters
1981 * @hw: pointer to the HW structure
1983 * Clears the hardware counters by reading the counter registers.
1985 static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
1987 DEBUGFUNC("e1000_clear_hw_cntrs_82571");
1989 e1000_clear_hw_cntrs_base_generic(hw);
1991 E1000_READ_REG(hw, E1000_PRC64);
1992 E1000_READ_REG(hw, E1000_PRC127);
1993 E1000_READ_REG(hw, E1000_PRC255);
1994 E1000_READ_REG(hw, E1000_PRC511);
1995 E1000_READ_REG(hw, E1000_PRC1023);
1996 E1000_READ_REG(hw, E1000_PRC1522);
1997 E1000_READ_REG(hw, E1000_PTC64);
1998 E1000_READ_REG(hw, E1000_PTC127);
1999 E1000_READ_REG(hw, E1000_PTC255);
2000 E1000_READ_REG(hw, E1000_PTC511);
2001 E1000_READ_REG(hw, E1000_PTC1023);
2002 E1000_READ_REG(hw, E1000_PTC1522);
2004 E1000_READ_REG(hw, E1000_ALGNERRC);
2005 E1000_READ_REG(hw, E1000_RXERRC);
2006 E1000_READ_REG(hw, E1000_TNCRS);
2007 E1000_READ_REG(hw, E1000_CEXTERR);
2008 E1000_READ_REG(hw, E1000_TSCTC);
2009 E1000_READ_REG(hw, E1000_TSCTFC);
2011 E1000_READ_REG(hw, E1000_MGTPRC);
2012 E1000_READ_REG(hw, E1000_MGTPDC);
2013 E1000_READ_REG(hw, E1000_MGTPTC);
2015 E1000_READ_REG(hw, E1000_IAC);
2016 E1000_READ_REG(hw, E1000_ICRXOC);
2018 E1000_READ_REG(hw, E1000_ICRXPTC);
2019 E1000_READ_REG(hw, E1000_ICRXATC);
2020 E1000_READ_REG(hw, E1000_ICTXPTC);
2021 E1000_READ_REG(hw, E1000_ICTXATC);
2022 E1000_READ_REG(hw, E1000_ICTXQEC);
2023 E1000_READ_REG(hw, E1000_ICTXQMTC);
2024 E1000_READ_REG(hw, E1000_ICRXDMTC);