1 /******************************************************************************
3 Copyright (c) 2001-2010, 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 ******************************************************************************/
36 * 82562G 10/100 Network Connection
37 * 82562G-2 10/100 Network Connection
38 * 82562GT 10/100 Network Connection
39 * 82562GT-2 10/100 Network Connection
40 * 82562V 10/100 Network Connection
41 * 82562V-2 10/100 Network Connection
42 * 82566DC-2 Gigabit Network Connection
43 * 82566DC Gigabit Network Connection
44 * 82566DM-2 Gigabit Network Connection
45 * 82566DM Gigabit Network Connection
46 * 82566MC Gigabit Network Connection
47 * 82566MM Gigabit Network Connection
48 * 82567LM Gigabit Network Connection
49 * 82567LF Gigabit Network Connection
50 * 82567V Gigabit Network Connection
51 * 82567LM-2 Gigabit Network Connection
52 * 82567LF-2 Gigabit Network Connection
53 * 82567V-2 Gigabit Network Connection
54 * 82567LF-3 Gigabit Network Connection
55 * 82567LM-3 Gigabit Network Connection
56 * 82567LM-4 Gigabit Network Connection
57 * 82577LM Gigabit Network Connection
58 * 82577LC Gigabit Network Connection
59 * 82578DM Gigabit Network Connection
60 * 82578DC Gigabit Network Connection
63 #include "e1000_api.h"
65 static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw);
66 static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw);
67 static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw);
68 static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw);
69 static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw);
70 static void e1000_release_swflag_ich8lan(struct e1000_hw *hw);
71 static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw);
72 static void e1000_release_nvm_ich8lan(struct e1000_hw *hw);
73 static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
74 static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw);
75 static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw);
76 static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
77 static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw,
79 static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw,
81 static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset,
82 u16 words, u16 *data);
83 static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset,
84 u16 words, u16 *data);
85 static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw);
86 static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw);
87 static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw,
89 static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
90 static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw);
91 static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw);
92 static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw);
93 static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
94 static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
95 static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw,
96 u16 *speed, u16 *duplex);
97 static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
98 static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
99 static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
100 static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
101 static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
102 static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
103 static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
104 static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
105 static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
106 static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
107 static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout);
108 static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw);
109 static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
110 static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
111 static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw,
112 u32 offset, u8 *data);
113 static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
115 static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw,
116 u32 offset, u16 *data);
117 static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
118 u32 offset, u8 byte);
119 static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw,
120 u32 offset, u8 data);
121 static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
123 static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
124 static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
125 static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw);
126 static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
127 static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw);
128 static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
130 /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
131 /* Offset 04h HSFSTS */
132 union ich8_hws_flash_status {
134 u16 flcdone :1; /* bit 0 Flash Cycle Done */
135 u16 flcerr :1; /* bit 1 Flash Cycle Error */
136 u16 dael :1; /* bit 2 Direct Access error Log */
137 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
138 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
139 u16 reserved1 :2; /* bit 13:6 Reserved */
140 u16 reserved2 :6; /* bit 13:6 Reserved */
141 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
142 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
147 /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
148 /* Offset 06h FLCTL */
149 union ich8_hws_flash_ctrl {
150 struct ich8_hsflctl {
151 u16 flcgo :1; /* 0 Flash Cycle Go */
152 u16 flcycle :2; /* 2:1 Flash Cycle */
153 u16 reserved :5; /* 7:3 Reserved */
154 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
155 u16 flockdn :6; /* 15:10 Reserved */
160 /* ICH Flash Region Access Permissions */
161 union ich8_hws_flash_regacc {
163 u32 grra :8; /* 0:7 GbE region Read Access */
164 u32 grwa :8; /* 8:15 GbE region Write Access */
165 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
166 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
172 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
173 * @hw: pointer to the HW structure
175 * Initialize family-specific PHY parameters and function pointers.
177 static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
179 struct e1000_phy_info *phy = &hw->phy;
181 s32 ret_val = E1000_SUCCESS;
183 DEBUGFUNC("e1000_init_phy_params_pchlan");
186 phy->reset_delay_us = 100;
188 phy->ops.acquire = e1000_acquire_swflag_ich8lan;
189 phy->ops.check_reset_block = e1000_check_reset_block_ich8lan;
190 phy->ops.get_cfg_done = e1000_get_cfg_done_ich8lan;
191 phy->ops.read_reg = e1000_read_phy_reg_hv;
192 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
193 phy->ops.release = e1000_release_swflag_ich8lan;
194 phy->ops.reset = e1000_phy_hw_reset_ich8lan;
195 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
196 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
197 phy->ops.write_reg = e1000_write_phy_reg_hv;
198 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
199 phy->ops.power_up = e1000_power_up_phy_copper;
200 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
201 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
203 if ((hw->mac.type == e1000_pchlan) &&
204 (!(E1000_READ_REG(hw, E1000_FWSM) & E1000_ICH_FWSM_FW_VALID))) {
207 * The MAC-PHY interconnect may still be in SMBus mode
208 * after Sx->S0. Toggle the LANPHYPC Value bit to force
209 * the interconnect to PCIe mode, but only if there is no
210 * firmware present otherwise firmware will have done it.
212 ctrl = E1000_READ_REG(hw, E1000_CTRL);
213 ctrl |= E1000_CTRL_LANPHYPC_OVERRIDE;
214 ctrl &= ~E1000_CTRL_LANPHYPC_VALUE;
215 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
217 ctrl &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
218 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
223 * Reset the PHY before any acccess to it. Doing so, ensures that
224 * the PHY is in a known good state before we read/write PHY registers.
225 * The generic reset is sufficient here, because we haven't determined
228 ret_val = e1000_phy_hw_reset_generic(hw);
232 phy->id = e1000_phy_unknown;
233 ret_val = e1000_get_phy_id(hw);
236 if ((phy->id == 0) || (phy->id == PHY_REVISION_MASK)) {
238 * In case the PHY needs to be in mdio slow mode (eg. 82577),
239 * set slow mode and try to get the PHY id again.
241 ret_val = e1000_set_mdio_slow_mode_hv(hw);
244 ret_val = e1000_get_phy_id(hw);
248 phy->type = e1000_get_phy_type_from_id(phy->id);
251 case e1000_phy_82577:
252 phy->ops.check_polarity = e1000_check_polarity_82577;
253 phy->ops.force_speed_duplex =
254 e1000_phy_force_speed_duplex_82577;
255 phy->ops.get_cable_length = e1000_get_cable_length_82577;
256 phy->ops.get_info = e1000_get_phy_info_82577;
257 phy->ops.commit = e1000_phy_sw_reset_generic;
259 case e1000_phy_82578:
260 phy->ops.check_polarity = e1000_check_polarity_m88;
261 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
262 phy->ops.get_cable_length = e1000_get_cable_length_m88;
263 phy->ops.get_info = e1000_get_phy_info_m88;
266 ret_val = -E1000_ERR_PHY;
275 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
276 * @hw: pointer to the HW structure
278 * Initialize family-specific PHY parameters and function pointers.
280 static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
282 struct e1000_phy_info *phy = &hw->phy;
283 s32 ret_val = E1000_SUCCESS;
286 DEBUGFUNC("e1000_init_phy_params_ich8lan");
289 phy->reset_delay_us = 100;
291 phy->ops.acquire = e1000_acquire_swflag_ich8lan;
292 phy->ops.check_reset_block = e1000_check_reset_block_ich8lan;
293 phy->ops.get_cable_length = e1000_get_cable_length_igp_2;
294 phy->ops.get_cfg_done = e1000_get_cfg_done_ich8lan;
295 phy->ops.read_reg = e1000_read_phy_reg_igp;
296 phy->ops.release = e1000_release_swflag_ich8lan;
297 phy->ops.reset = e1000_phy_hw_reset_ich8lan;
298 phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan;
299 phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan;
300 phy->ops.write_reg = e1000_write_phy_reg_igp;
301 phy->ops.power_up = e1000_power_up_phy_copper;
302 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
305 * We may need to do this twice - once for IGP and if that fails,
306 * we'll set BM func pointers and try again
308 ret_val = e1000_determine_phy_address(hw);
310 phy->ops.write_reg = e1000_write_phy_reg_bm;
311 phy->ops.read_reg = e1000_read_phy_reg_bm;
312 ret_val = e1000_determine_phy_address(hw);
314 DEBUGOUT("Cannot determine PHY addr. Erroring out\n");
320 while ((e1000_phy_unknown == e1000_get_phy_type_from_id(phy->id)) &&
323 ret_val = e1000_get_phy_id(hw);
330 case IGP03E1000_E_PHY_ID:
331 phy->type = e1000_phy_igp_3;
332 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
333 phy->ops.read_reg_locked = e1000_read_phy_reg_igp_locked;
334 phy->ops.write_reg_locked = e1000_write_phy_reg_igp_locked;
335 phy->ops.get_info = e1000_get_phy_info_igp;
336 phy->ops.check_polarity = e1000_check_polarity_igp;
337 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_igp;
340 case IFE_PLUS_E_PHY_ID:
342 phy->type = e1000_phy_ife;
343 phy->autoneg_mask = E1000_ALL_NOT_GIG;
344 phy->ops.get_info = e1000_get_phy_info_ife;
345 phy->ops.check_polarity = e1000_check_polarity_ife;
346 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
348 case BME1000_E_PHY_ID:
349 phy->type = e1000_phy_bm;
350 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
351 phy->ops.read_reg = e1000_read_phy_reg_bm;
352 phy->ops.write_reg = e1000_write_phy_reg_bm;
353 phy->ops.commit = e1000_phy_sw_reset_generic;
354 phy->ops.get_info = e1000_get_phy_info_m88;
355 phy->ops.check_polarity = e1000_check_polarity_m88;
356 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
359 ret_val = -E1000_ERR_PHY;
368 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
369 * @hw: pointer to the HW structure
371 * Initialize family-specific NVM parameters and function
374 static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
376 struct e1000_nvm_info *nvm = &hw->nvm;
377 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
378 u32 gfpreg, sector_base_addr, sector_end_addr;
379 s32 ret_val = E1000_SUCCESS;
382 DEBUGFUNC("e1000_init_nvm_params_ich8lan");
384 /* Can't read flash registers if the register set isn't mapped. */
385 if (!hw->flash_address) {
386 DEBUGOUT("ERROR: Flash registers not mapped\n");
387 ret_val = -E1000_ERR_CONFIG;
391 nvm->type = e1000_nvm_flash_sw;
393 gfpreg = E1000_READ_FLASH_REG(hw, ICH_FLASH_GFPREG);
396 * sector_X_addr is a "sector"-aligned address (4096 bytes)
397 * Add 1 to sector_end_addr since this sector is included in
400 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
401 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
403 /* flash_base_addr is byte-aligned */
404 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
407 * find total size of the NVM, then cut in half since the total
408 * size represents two separate NVM banks.
410 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
411 << FLASH_SECTOR_ADDR_SHIFT;
412 nvm->flash_bank_size /= 2;
413 /* Adjust to word count */
414 nvm->flash_bank_size /= sizeof(u16);
416 nvm->word_size = E1000_SHADOW_RAM_WORDS;
418 /* Clear shadow ram */
419 for (i = 0; i < nvm->word_size; i++) {
420 dev_spec->shadow_ram[i].modified = FALSE;
421 dev_spec->shadow_ram[i].value = 0xFFFF;
424 E1000_MUTEX_INIT(&dev_spec->nvm_mutex);
425 E1000_MUTEX_INIT(&dev_spec->swflag_mutex);
427 /* Function Pointers */
428 nvm->ops.acquire = e1000_acquire_nvm_ich8lan;
429 nvm->ops.release = e1000_release_nvm_ich8lan;
430 nvm->ops.read = e1000_read_nvm_ich8lan;
431 nvm->ops.update = e1000_update_nvm_checksum_ich8lan;
432 nvm->ops.valid_led_default = e1000_valid_led_default_ich8lan;
433 nvm->ops.validate = e1000_validate_nvm_checksum_ich8lan;
434 nvm->ops.write = e1000_write_nvm_ich8lan;
441 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
442 * @hw: pointer to the HW structure
444 * Initialize family-specific MAC parameters and function
447 static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
449 struct e1000_mac_info *mac = &hw->mac;
452 DEBUGFUNC("e1000_init_mac_params_ich8lan");
454 /* Set media type function pointer */
455 hw->phy.media_type = e1000_media_type_copper;
457 /* Set mta register count */
458 mac->mta_reg_count = 32;
459 /* Set rar entry count */
460 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
461 if (mac->type == e1000_ich8lan)
462 mac->rar_entry_count--;
463 /* Set if part includes ASF firmware */
464 mac->asf_firmware_present = TRUE;
466 mac->has_fwsm = TRUE;
467 /* ARC subsystem not supported */
468 mac->arc_subsystem_valid = FALSE;
469 /* Adaptive IFS supported */
470 mac->adaptive_ifs = TRUE;
472 /* Function pointers */
474 /* bus type/speed/width */
475 mac->ops.get_bus_info = e1000_get_bus_info_ich8lan;
477 mac->ops.set_lan_id = e1000_set_lan_id_single_port;
479 mac->ops.reset_hw = e1000_reset_hw_ich8lan;
480 /* hw initialization */
481 mac->ops.init_hw = e1000_init_hw_ich8lan;
483 mac->ops.setup_link = e1000_setup_link_ich8lan;
484 /* physical interface setup */
485 mac->ops.setup_physical_interface = e1000_setup_copper_link_ich8lan;
487 mac->ops.check_for_link = e1000_check_for_copper_link_ich8lan;
488 /* check management mode */
489 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
491 mac->ops.get_link_up_info = e1000_get_link_up_info_ich8lan;
492 /* multicast address update */
493 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
494 /* clear hardware counters */
495 mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan;
503 mac->ops.id_led_init = e1000_id_led_init_generic;
505 mac->ops.blink_led = e1000_blink_led_generic;
507 mac->ops.setup_led = e1000_setup_led_generic;
509 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
510 /* turn on/off LED */
511 mac->ops.led_on = e1000_led_on_ich8lan;
512 mac->ops.led_off = e1000_led_off_ich8lan;
515 /* save PCH revision_id */
516 e1000_read_pci_cfg(hw, 0x2, &pci_cfg);
517 hw->revision_id = (u8)(pci_cfg &= 0x000F);
519 mac->ops.id_led_init = e1000_id_led_init_pchlan;
521 mac->ops.setup_led = e1000_setup_led_pchlan;
523 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
524 /* turn on/off LED */
525 mac->ops.led_on = e1000_led_on_pchlan;
526 mac->ops.led_off = e1000_led_off_pchlan;
532 /* Enable PCS Lock-loss workaround for ICH8 */
533 if (mac->type == e1000_ich8lan)
534 e1000_set_kmrn_lock_loss_workaround_ich8lan(hw, TRUE);
536 return E1000_SUCCESS;
540 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
541 * @hw: pointer to the HW structure
543 * Checks to see of the link status of the hardware has changed. If a
544 * change in link status has been detected, then we read the PHY registers
545 * to get the current speed/duplex if link exists.
547 static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
549 struct e1000_mac_info *mac = &hw->mac;
553 DEBUGFUNC("e1000_check_for_copper_link_ich8lan");
556 * We only want to go out to the PHY registers to see if Auto-Neg
557 * has completed and/or if our link status has changed. The
558 * get_link_status flag is set upon receiving a Link Status
559 * Change or Rx Sequence Error interrupt.
561 if (!mac->get_link_status) {
562 ret_val = E1000_SUCCESS;
567 * First we want to see if the MII Status Register reports
568 * link. If so, then we want to get the current speed/duplex
571 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
575 if (hw->mac.type == e1000_pchlan) {
576 ret_val = e1000_k1_gig_workaround_hv(hw, link);
582 goto out; /* No link detected */
584 mac->get_link_status = FALSE;
586 if (hw->phy.type == e1000_phy_82578) {
587 ret_val = e1000_link_stall_workaround_hv(hw);
593 * Check if there was DownShift, must be checked
594 * immediately after link-up
596 e1000_check_downshift_generic(hw);
599 * If we are forcing speed/duplex, then we simply return since
600 * we have already determined whether we have link or not.
603 ret_val = -E1000_ERR_CONFIG;
608 * Auto-Neg is enabled. Auto Speed Detection takes care
609 * of MAC speed/duplex configuration. So we only need to
610 * configure Collision Distance in the MAC.
612 e1000_config_collision_dist_generic(hw);
615 * Configure Flow Control now that Auto-Neg has completed.
616 * First, we need to restore the desired flow control
617 * settings because we may have had to re-autoneg with a
618 * different link partner.
620 ret_val = e1000_config_fc_after_link_up_generic(hw);
622 DEBUGOUT("Error configuring flow control\n");
629 * e1000_init_function_pointers_ich8lan - Initialize ICH8 function pointers
630 * @hw: pointer to the HW structure
632 * Initialize family-specific function pointers for PHY, MAC, and NVM.
634 void e1000_init_function_pointers_ich8lan(struct e1000_hw *hw)
636 DEBUGFUNC("e1000_init_function_pointers_ich8lan");
638 hw->mac.ops.init_params = e1000_init_mac_params_ich8lan;
639 hw->nvm.ops.init_params = e1000_init_nvm_params_ich8lan;
640 switch (hw->mac.type) {
644 hw->phy.ops.init_params = e1000_init_phy_params_ich8lan;
647 hw->phy.ops.init_params = e1000_init_phy_params_pchlan;
655 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
656 * @hw: pointer to the HW structure
658 * Acquires the mutex for performing NVM operations.
660 static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
662 DEBUGFUNC("e1000_acquire_nvm_ich8lan");
664 E1000_MUTEX_LOCK(&hw->dev_spec.ich8lan.nvm_mutex);
666 return E1000_SUCCESS;
670 * e1000_release_nvm_ich8lan - Release NVM mutex
671 * @hw: pointer to the HW structure
673 * Releases the mutex used while performing NVM operations.
675 static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
677 DEBUGFUNC("e1000_release_nvm_ich8lan");
679 E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.nvm_mutex);
685 * e1000_acquire_swflag_ich8lan - Acquire software control flag
686 * @hw: pointer to the HW structure
688 * Acquires the software control flag for performing PHY and select
691 static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
693 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
694 s32 ret_val = E1000_SUCCESS;
696 DEBUGFUNC("e1000_acquire_swflag_ich8lan");
698 E1000_MUTEX_LOCK(&hw->dev_spec.ich8lan.swflag_mutex);
701 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
702 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
710 DEBUGOUT("SW/FW/HW has locked the resource for too long.\n");
711 ret_val = -E1000_ERR_CONFIG;
715 timeout = SW_FLAG_TIMEOUT;
717 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
718 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
721 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
722 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
730 DEBUGOUT("Failed to acquire the semaphore.\n");
731 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
732 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
733 ret_val = -E1000_ERR_CONFIG;
739 E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.swflag_mutex);
745 * e1000_release_swflag_ich8lan - Release software control flag
746 * @hw: pointer to the HW structure
748 * Releases the software control flag for performing PHY and select
751 static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
755 DEBUGFUNC("e1000_release_swflag_ich8lan");
757 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
758 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
759 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
761 E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.swflag_mutex);
767 * e1000_check_mng_mode_ich8lan - Checks management mode
768 * @hw: pointer to the HW structure
770 * This checks if the adapter has manageability enabled.
771 * This is a function pointer entry point only called by read/write
772 * routines for the PHY and NVM parts.
774 static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
778 DEBUGFUNC("e1000_check_mng_mode_ich8lan");
780 fwsm = E1000_READ_REG(hw, E1000_FWSM);
782 return (fwsm & E1000_FWSM_MODE_MASK) ==
783 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
787 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
788 * @hw: pointer to the HW structure
790 * Checks if firmware is blocking the reset of the PHY.
791 * This is a function pointer entry point only called by
794 static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
798 DEBUGFUNC("e1000_check_reset_block_ich8lan");
800 if (hw->phy.reset_disable)
801 return E1000_BLK_PHY_RESET;
803 fwsm = E1000_READ_REG(hw, E1000_FWSM);
805 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? E1000_SUCCESS
806 : E1000_BLK_PHY_RESET;
810 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
811 * @hw: pointer to the HW structure
813 * SW should configure the LCD from the NVM extended configuration region
814 * as a workaround for certain parts.
816 static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
818 struct e1000_phy_info *phy = &hw->phy;
819 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
820 s32 ret_val = E1000_SUCCESS;
821 u16 word_addr, reg_data, reg_addr, phy_page = 0;
823 if (!(hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) &&
824 !(hw->mac.type == e1000_pchlan))
827 ret_val = hw->phy.ops.acquire(hw);
832 * Initialize the PHY from the NVM on ICH platforms. This
833 * is needed due to an issue where the NVM configuration is
834 * not properly autoloaded after power transitions.
835 * Therefore, after each PHY reset, we will load the
836 * configuration data out of the NVM manually.
838 if ((hw->device_id == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
839 (hw->device_id == E1000_DEV_ID_ICH8_IGP_M) ||
840 (hw->mac.type == e1000_pchlan))
841 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
843 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
845 data = E1000_READ_REG(hw, E1000_FEXTNVM);
846 if (!(data & sw_cfg_mask))
849 /* Wait for basic configuration completes before proceeding */
850 e1000_lan_init_done_ich8lan(hw);
853 * Make sure HW does not configure LCD from PHY
854 * extended configuration before SW configuration
856 data = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
857 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
860 cnf_size = E1000_READ_REG(hw, E1000_EXTCNF_SIZE);
861 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
862 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
866 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
867 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
869 if (!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
870 (hw->mac.type == e1000_pchlan)) {
872 * HW configures the SMBus address and LEDs when the
873 * OEM and LCD Write Enable bits are set in the NVM.
874 * When both NVM bits are cleared, SW will configure
877 data = E1000_READ_REG(hw, E1000_STRAP);
878 data &= E1000_STRAP_SMBUS_ADDRESS_MASK;
879 reg_data = data >> E1000_STRAP_SMBUS_ADDRESS_SHIFT;
880 reg_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
881 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR,
886 data = E1000_READ_REG(hw, E1000_LEDCTL);
887 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
893 /* Configure LCD from extended configuration region. */
895 /* cnf_base_addr is in DWORD */
896 word_addr = (u16)(cnf_base_addr << 1);
898 for (i = 0; i < cnf_size; i++) {
899 ret_val = hw->nvm.ops.read(hw, (word_addr + i * 2), 1,
904 ret_val = hw->nvm.ops.read(hw, (word_addr + i * 2 + 1),
909 /* Save off the PHY page for future writes. */
910 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
915 reg_addr &= PHY_REG_MASK;
916 reg_addr |= phy_page;
918 ret_val = phy->ops.write_reg_locked(hw, (u32)reg_addr,
925 hw->phy.ops.release(hw);
930 * e1000_k1_gig_workaround_hv - K1 Si workaround
931 * @hw: pointer to the HW structure
932 * @link: link up bool flag
934 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
935 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
936 * If link is down, the function will restore the default K1 setting located
939 static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
941 s32 ret_val = E1000_SUCCESS;
943 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
945 DEBUGFUNC("e1000_k1_gig_workaround_hv");
947 if (hw->mac.type != e1000_pchlan)
950 /* Wrap the whole flow with the sw flag */
951 ret_val = hw->phy.ops.acquire(hw);
955 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
957 if (hw->phy.type == e1000_phy_82578) {
958 ret_val = hw->phy.ops.read_reg_locked(hw, BM_CS_STATUS,
963 status_reg &= BM_CS_STATUS_LINK_UP |
964 BM_CS_STATUS_RESOLVED |
965 BM_CS_STATUS_SPEED_MASK;
967 if (status_reg == (BM_CS_STATUS_LINK_UP |
968 BM_CS_STATUS_RESOLVED |
969 BM_CS_STATUS_SPEED_1000))
973 if (hw->phy.type == e1000_phy_82577) {
974 ret_val = hw->phy.ops.read_reg_locked(hw, HV_M_STATUS,
979 status_reg &= HV_M_STATUS_LINK_UP |
980 HV_M_STATUS_AUTONEG_COMPLETE |
981 HV_M_STATUS_SPEED_MASK;
983 if (status_reg == (HV_M_STATUS_LINK_UP |
984 HV_M_STATUS_AUTONEG_COMPLETE |
985 HV_M_STATUS_SPEED_1000))
989 /* Link stall fix for link up */
990 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
996 /* Link stall fix for link down */
997 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
1003 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1006 hw->phy.ops.release(hw);
1012 * e1000_configure_k1_ich8lan - Configure K1 power state
1013 * @hw: pointer to the HW structure
1014 * @enable: K1 state to configure
1016 * Configure the K1 power state based on the provided parameter.
1017 * Assumes semaphore already acquired.
1019 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1021 s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
1023 s32 ret_val = E1000_SUCCESS;
1029 ret_val = e1000_read_kmrn_reg_locked(hw,
1030 E1000_KMRNCTRLSTA_K1_CONFIG,
1036 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1038 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1040 ret_val = e1000_write_kmrn_reg_locked(hw,
1041 E1000_KMRNCTRLSTA_K1_CONFIG,
1047 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1048 ctrl_reg = E1000_READ_REG(hw, E1000_CTRL);
1050 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1051 reg |= E1000_CTRL_FRCSPD;
1052 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1054 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
1056 E1000_WRITE_REG(hw, E1000_CTRL, ctrl_reg);
1057 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1065 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1066 * @hw: pointer to the HW structure
1067 * @d0_state: boolean if entering d0 or d3 device state
1069 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1070 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1071 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1073 s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1079 if (hw->mac.type != e1000_pchlan)
1082 ret_val = hw->phy.ops.acquire(hw);
1086 mac_reg = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
1087 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
1090 mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM);
1091 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
1094 mac_reg = E1000_READ_REG(hw, E1000_PHY_CTRL);
1096 ret_val = hw->phy.ops.read_reg_locked(hw, HV_OEM_BITS, &oem_reg);
1100 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1103 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1104 oem_reg |= HV_OEM_BITS_GBE_DIS;
1106 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1107 oem_reg |= HV_OEM_BITS_LPLU;
1109 if (mac_reg & E1000_PHY_CTRL_NOND0A_GBE_DISABLE)
1110 oem_reg |= HV_OEM_BITS_GBE_DIS;
1112 if (mac_reg & E1000_PHY_CTRL_NOND0A_LPLU)
1113 oem_reg |= HV_OEM_BITS_LPLU;
1115 /* Restart auto-neg to activate the bits */
1116 if (!hw->phy.ops.check_reset_block(hw))
1117 oem_reg |= HV_OEM_BITS_RESTART_AN;
1118 ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
1121 hw->phy.ops.release(hw);
1128 * e1000_hv_phy_powerdown_workaround_ich8lan - Power down workaround on Sx
1129 * @hw: pointer to the HW structure
1131 s32 e1000_hv_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
1133 if ((hw->phy.type != e1000_phy_82577) || (hw->revision_id > 2))
1134 return E1000_SUCCESS;
1136 return hw->phy.ops.write_reg(hw, PHY_REG(768, 25), 0x0444);
1140 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1141 * @hw: pointer to the HW structure
1143 static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1148 ret_val = hw->phy.ops.read_reg(hw, HV_KMRN_MODE_CTRL, &data);
1152 data |= HV_KMRN_MDIO_SLOW;
1154 ret_val = hw->phy.ops.write_reg(hw, HV_KMRN_MODE_CTRL, data);
1160 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1161 * done after every PHY reset.
1163 static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1165 s32 ret_val = E1000_SUCCESS;
1168 if (hw->mac.type != e1000_pchlan)
1171 /* Set MDIO slow mode before any other MDIO access */
1172 if (hw->phy.type == e1000_phy_82577) {
1173 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1178 /* Hanksville M Phy init for IEEE. */
1179 if ((hw->revision_id == 2) &&
1180 (hw->phy.type == e1000_phy_82577) &&
1181 ((hw->phy.revision == 2) || (hw->phy.revision == 3))) {
1182 hw->phy.ops.write_reg(hw, 0x10, 0x8823);
1183 hw->phy.ops.write_reg(hw, 0x11, 0x0018);
1184 hw->phy.ops.write_reg(hw, 0x10, 0x8824);
1185 hw->phy.ops.write_reg(hw, 0x11, 0x0016);
1186 hw->phy.ops.write_reg(hw, 0x10, 0x8825);
1187 hw->phy.ops.write_reg(hw, 0x11, 0x001A);
1188 hw->phy.ops.write_reg(hw, 0x10, 0x888C);
1189 hw->phy.ops.write_reg(hw, 0x11, 0x0007);
1190 hw->phy.ops.write_reg(hw, 0x10, 0x888D);
1191 hw->phy.ops.write_reg(hw, 0x11, 0x0007);
1192 hw->phy.ops.write_reg(hw, 0x10, 0x888E);
1193 hw->phy.ops.write_reg(hw, 0x11, 0x0007);
1194 hw->phy.ops.write_reg(hw, 0x10, 0x8827);
1195 hw->phy.ops.write_reg(hw, 0x11, 0x0001);
1196 hw->phy.ops.write_reg(hw, 0x10, 0x8835);
1197 hw->phy.ops.write_reg(hw, 0x11, 0x0001);
1198 hw->phy.ops.write_reg(hw, 0x10, 0x8834);
1199 hw->phy.ops.write_reg(hw, 0x11, 0x0001);
1200 hw->phy.ops.write_reg(hw, 0x10, 0x8833);
1201 hw->phy.ops.write_reg(hw, 0x11, 0x0002);
1204 if (((hw->phy.type == e1000_phy_82577) &&
1205 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1206 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1207 /* Disable generation of early preamble */
1208 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(769, 25), 0x4431);
1212 /* Preamble tuning for SSC */
1213 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(770, 16), 0xA204);
1218 if (hw->phy.type == e1000_phy_82578) {
1219 if (hw->revision_id < 3) {
1221 ret_val = hw->phy.ops.write_reg(hw, (1 << 6) | 0x29,
1227 ret_val = hw->phy.ops.write_reg(hw, (1 << 6) | 0x1E,
1234 * Return registers to default by doing a soft reset then
1235 * writing 0x3140 to the control register.
1237 if (hw->phy.revision < 2) {
1238 e1000_phy_sw_reset_generic(hw);
1239 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL,
1244 if ((hw->revision_id == 2) &&
1245 (hw->phy.type == e1000_phy_82577) &&
1246 ((hw->phy.revision == 2) || (hw->phy.revision == 3))) {
1248 * Workaround for OEM (GbE) not operating after reset -
1249 * restart AN (twice)
1251 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(768, 25), 0x0400);
1254 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(768, 25), 0x0400);
1260 ret_val = hw->phy.ops.acquire(hw);
1265 ret_val = e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
1266 hw->phy.ops.release(hw);
1271 * Configure the K1 Si workaround during phy reset assuming there is
1272 * link so that it disables K1 if link is in 1Gbps.
1274 ret_val = e1000_k1_gig_workaround_hv(hw, TRUE);
1278 /* Workaround for link disconnects on a busy hub in half duplex */
1279 ret_val = hw->phy.ops.acquire(hw);
1282 ret_val = hw->phy.ops.read_reg_locked(hw,
1283 PHY_REG(BM_PORT_CTRL_PAGE, 17),
1287 ret_val = hw->phy.ops.write_reg_locked(hw,
1288 PHY_REG(BM_PORT_CTRL_PAGE, 17),
1291 hw->phy.ops.release(hw);
1297 * e1000_lan_init_done_ich8lan - Check for PHY config completion
1298 * @hw: pointer to the HW structure
1300 * Check the appropriate indication the MAC has finished configuring the
1301 * PHY after a software reset.
1303 static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
1305 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
1307 DEBUGFUNC("e1000_lan_init_done_ich8lan");
1309 /* Wait for basic configuration completes before proceeding */
1311 data = E1000_READ_REG(hw, E1000_STATUS);
1312 data &= E1000_STATUS_LAN_INIT_DONE;
1314 } while ((!data) && --loop);
1317 * If basic configuration is incomplete before the above loop
1318 * count reaches 0, loading the configuration from NVM will
1319 * leave the PHY in a bad state possibly resulting in no link.
1322 DEBUGOUT("LAN_INIT_DONE not set, increase timeout\n");
1324 /* Clear the Init Done bit for the next init event */
1325 data = E1000_READ_REG(hw, E1000_STATUS);
1326 data &= ~E1000_STATUS_LAN_INIT_DONE;
1327 E1000_WRITE_REG(hw, E1000_STATUS, data);
1331 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
1332 * @hw: pointer to the HW structure
1335 * This is a function pointer entry point called by drivers
1336 * or other shared routines.
1338 static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
1340 s32 ret_val = E1000_SUCCESS;
1343 DEBUGFUNC("e1000_phy_hw_reset_ich8lan");
1345 ret_val = e1000_phy_hw_reset_generic(hw);
1349 /* Allow time for h/w to get to a quiescent state after reset */
1352 /* Perform any necessary post-reset workarounds */
1353 switch (hw->mac.type) {
1355 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
1363 /* Dummy read to clear the phy wakeup bit after lcd reset */
1364 if (hw->mac.type == e1000_pchlan)
1365 hw->phy.ops.read_reg(hw, BM_WUC, ®);
1367 /* Configure the LCD with the extended configuration region in NVM */
1368 ret_val = e1000_sw_lcd_config_ich8lan(hw);
1372 /* Configure the LCD with the OEM bits in NVM */
1373 ret_val = e1000_oem_bits_config_ich8lan(hw, TRUE);
1380 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1381 * @hw: pointer to the HW structure
1382 * @active: TRUE to enable LPLU, FALSE to disable
1384 * Sets the LPLU state according to the active flag. For PCH, if OEM write
1385 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1386 * the phy speed. This function will manually set the LPLU bit and restart
1387 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
1388 * since it configures the same bit.
1390 static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1392 s32 ret_val = E1000_SUCCESS;
1395 DEBUGFUNC("e1000_set_lplu_state_pchlan");
1397 ret_val = hw->phy.ops.read_reg(hw, HV_OEM_BITS, &oem_reg);
1402 oem_reg |= HV_OEM_BITS_LPLU;
1404 oem_reg &= ~HV_OEM_BITS_LPLU;
1406 oem_reg |= HV_OEM_BITS_RESTART_AN;
1407 ret_val = hw->phy.ops.write_reg(hw, HV_OEM_BITS, oem_reg);
1414 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1415 * @hw: pointer to the HW structure
1416 * @active: TRUE to enable LPLU, FALSE to disable
1418 * Sets the LPLU D0 state according to the active flag. When
1419 * activating LPLU this function also disables smart speed
1420 * and vice versa. LPLU will not be activated unless the
1421 * device autonegotiation advertisement meets standards of
1422 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1423 * This is a function pointer entry point only called by
1424 * PHY setup routines.
1426 static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1428 struct e1000_phy_info *phy = &hw->phy;
1430 s32 ret_val = E1000_SUCCESS;
1433 DEBUGFUNC("e1000_set_d0_lplu_state_ich8lan");
1435 if (phy->type == e1000_phy_ife)
1438 phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
1441 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
1442 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
1444 if (phy->type != e1000_phy_igp_3)
1448 * Call gig speed drop workaround on LPLU before accessing
1451 if (hw->mac.type == e1000_ich8lan)
1452 e1000_gig_downshift_workaround_ich8lan(hw);
1454 /* When LPLU is enabled, we should disable SmartSpeed */
1455 ret_val = phy->ops.read_reg(hw,
1456 IGP01E1000_PHY_PORT_CONFIG,
1458 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1459 ret_val = phy->ops.write_reg(hw,
1460 IGP01E1000_PHY_PORT_CONFIG,
1465 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
1466 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
1468 if (phy->type != e1000_phy_igp_3)
1472 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1473 * during Dx states where the power conservation is most
1474 * important. During driver activity we should enable
1475 * SmartSpeed, so performance is maintained.
1477 if (phy->smart_speed == e1000_smart_speed_on) {
1478 ret_val = phy->ops.read_reg(hw,
1479 IGP01E1000_PHY_PORT_CONFIG,
1484 data |= IGP01E1000_PSCFR_SMART_SPEED;
1485 ret_val = phy->ops.write_reg(hw,
1486 IGP01E1000_PHY_PORT_CONFIG,
1490 } else if (phy->smart_speed == e1000_smart_speed_off) {
1491 ret_val = phy->ops.read_reg(hw,
1492 IGP01E1000_PHY_PORT_CONFIG,
1497 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1498 ret_val = phy->ops.write_reg(hw,
1499 IGP01E1000_PHY_PORT_CONFIG,
1511 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
1512 * @hw: pointer to the HW structure
1513 * @active: TRUE to enable LPLU, FALSE to disable
1515 * Sets the LPLU D3 state according to the active flag. When
1516 * activating LPLU this function also disables smart speed
1517 * and vice versa. LPLU will not be activated unless the
1518 * device autonegotiation advertisement meets standards of
1519 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1520 * This is a function pointer entry point only called by
1521 * PHY setup routines.
1523 static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1525 struct e1000_phy_info *phy = &hw->phy;
1527 s32 ret_val = E1000_SUCCESS;
1530 DEBUGFUNC("e1000_set_d3_lplu_state_ich8lan");
1532 phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
1535 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
1536 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
1538 if (phy->type != e1000_phy_igp_3)
1542 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1543 * during Dx states where the power conservation is most
1544 * important. During driver activity we should enable
1545 * SmartSpeed, so performance is maintained.
1547 if (phy->smart_speed == e1000_smart_speed_on) {
1548 ret_val = phy->ops.read_reg(hw,
1549 IGP01E1000_PHY_PORT_CONFIG,
1554 data |= IGP01E1000_PSCFR_SMART_SPEED;
1555 ret_val = phy->ops.write_reg(hw,
1556 IGP01E1000_PHY_PORT_CONFIG,
1560 } else if (phy->smart_speed == e1000_smart_speed_off) {
1561 ret_val = phy->ops.read_reg(hw,
1562 IGP01E1000_PHY_PORT_CONFIG,
1567 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1568 ret_val = phy->ops.write_reg(hw,
1569 IGP01E1000_PHY_PORT_CONFIG,
1574 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1575 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1576 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1577 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
1578 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
1580 if (phy->type != e1000_phy_igp_3)
1584 * Call gig speed drop workaround on LPLU before accessing
1587 if (hw->mac.type == e1000_ich8lan)
1588 e1000_gig_downshift_workaround_ich8lan(hw);
1590 /* When LPLU is enabled, we should disable SmartSpeed */
1591 ret_val = phy->ops.read_reg(hw,
1592 IGP01E1000_PHY_PORT_CONFIG,
1597 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1598 ret_val = phy->ops.write_reg(hw,
1599 IGP01E1000_PHY_PORT_CONFIG,
1608 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
1609 * @hw: pointer to the HW structure
1610 * @bank: pointer to the variable that returns the active bank
1612 * Reads signature byte from the NVM using the flash access registers.
1613 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
1615 static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
1618 struct e1000_nvm_info *nvm = &hw->nvm;
1619 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
1620 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
1622 s32 ret_val = E1000_SUCCESS;
1624 switch (hw->mac.type) {
1627 eecd = E1000_READ_REG(hw, E1000_EECD);
1628 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
1629 E1000_EECD_SEC1VAL_VALID_MASK) {
1630 if (eecd & E1000_EECD_SEC1VAL)
1637 DEBUGOUT("Unable to determine valid NVM bank via EEC - "
1638 "reading flash signature\n");
1641 /* set bank to 0 in case flash read fails */
1645 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
1649 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1650 E1000_ICH_NVM_SIG_VALUE) {
1656 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
1661 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1662 E1000_ICH_NVM_SIG_VALUE) {
1667 DEBUGOUT("ERROR: No valid NVM bank present\n");
1668 ret_val = -E1000_ERR_NVM;
1676 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
1677 * @hw: pointer to the HW structure
1678 * @offset: The offset (in bytes) of the word(s) to read.
1679 * @words: Size of data to read in words
1680 * @data: Pointer to the word(s) to read at offset.
1682 * Reads a word(s) from the NVM using the flash access registers.
1684 static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1687 struct e1000_nvm_info *nvm = &hw->nvm;
1688 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1690 s32 ret_val = E1000_SUCCESS;
1694 DEBUGFUNC("e1000_read_nvm_ich8lan");
1696 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1698 DEBUGOUT("nvm parameter(s) out of bounds\n");
1699 ret_val = -E1000_ERR_NVM;
1703 nvm->ops.acquire(hw);
1705 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
1706 if (ret_val != E1000_SUCCESS) {
1707 DEBUGOUT("Could not detect valid bank, assuming bank 0\n");
1711 act_offset = (bank) ? nvm->flash_bank_size : 0;
1712 act_offset += offset;
1714 ret_val = E1000_SUCCESS;
1715 for (i = 0; i < words; i++) {
1716 if ((dev_spec->shadow_ram) &&
1717 (dev_spec->shadow_ram[offset+i].modified)) {
1718 data[i] = dev_spec->shadow_ram[offset+i].value;
1720 ret_val = e1000_read_flash_word_ich8lan(hw,
1729 nvm->ops.release(hw);
1733 DEBUGOUT1("NVM read error: %d\n", ret_val);
1739 * e1000_flash_cycle_init_ich8lan - Initialize flash
1740 * @hw: pointer to the HW structure
1742 * This function does initial flash setup so that a new read/write/erase cycle
1745 static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
1747 union ich8_hws_flash_status hsfsts;
1748 s32 ret_val = -E1000_ERR_NVM;
1751 DEBUGFUNC("e1000_flash_cycle_init_ich8lan");
1753 hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
1755 /* Check if the flash descriptor is valid */
1756 if (hsfsts.hsf_status.fldesvalid == 0) {
1757 DEBUGOUT("Flash descriptor invalid. "
1758 "SW Sequencing must be used.");
1762 /* Clear FCERR and DAEL in hw status by writing 1 */
1763 hsfsts.hsf_status.flcerr = 1;
1764 hsfsts.hsf_status.dael = 1;
1766 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
1769 * Either we should have a hardware SPI cycle in progress
1770 * bit to check against, in order to start a new cycle or
1771 * FDONE bit should be changed in the hardware so that it
1772 * is 1 after hardware reset, which can then be used as an
1773 * indication whether a cycle is in progress or has been
1777 if (hsfsts.hsf_status.flcinprog == 0) {
1779 * There is no cycle running at present,
1780 * so we can start a cycle.
1781 * Begin by setting Flash Cycle Done.
1783 hsfsts.hsf_status.flcdone = 1;
1784 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
1785 ret_val = E1000_SUCCESS;
1788 * Otherwise poll for sometime so the current
1789 * cycle has a chance to end before giving up.
1791 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
1792 hsfsts.regval = E1000_READ_FLASH_REG16(hw,
1794 if (hsfsts.hsf_status.flcinprog == 0) {
1795 ret_val = E1000_SUCCESS;
1800 if (ret_val == E1000_SUCCESS) {
1802 * Successful in waiting for previous cycle to timeout,
1803 * now set the Flash Cycle Done.
1805 hsfsts.hsf_status.flcdone = 1;
1806 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS,
1809 DEBUGOUT("Flash controller busy, cannot get access");
1818 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
1819 * @hw: pointer to the HW structure
1820 * @timeout: maximum time to wait for completion
1822 * This function starts a flash cycle and waits for its completion.
1824 static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
1826 union ich8_hws_flash_ctrl hsflctl;
1827 union ich8_hws_flash_status hsfsts;
1828 s32 ret_val = -E1000_ERR_NVM;
1831 DEBUGFUNC("e1000_flash_cycle_ich8lan");
1833 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
1834 hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
1835 hsflctl.hsf_ctrl.flcgo = 1;
1836 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
1838 /* wait till FDONE bit is set to 1 */
1840 hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
1841 if (hsfsts.hsf_status.flcdone == 1)
1844 } while (i++ < timeout);
1846 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
1847 ret_val = E1000_SUCCESS;
1853 * e1000_read_flash_word_ich8lan - Read word from flash
1854 * @hw: pointer to the HW structure
1855 * @offset: offset to data location
1856 * @data: pointer to the location for storing the data
1858 * Reads the flash word at offset into data. Offset is converted
1859 * to bytes before read.
1861 static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
1866 DEBUGFUNC("e1000_read_flash_word_ich8lan");
1869 ret_val = -E1000_ERR_NVM;
1873 /* Must convert offset into bytes. */
1876 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 2, data);
1883 * e1000_read_flash_byte_ich8lan - Read byte from flash
1884 * @hw: pointer to the HW structure
1885 * @offset: The offset of the byte to read.
1886 * @data: Pointer to a byte to store the value read.
1888 * Reads a single byte from the NVM using the flash access registers.
1890 static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1893 s32 ret_val = E1000_SUCCESS;
1896 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
1907 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
1908 * @hw: pointer to the HW structure
1909 * @offset: The offset (in bytes) of the byte or word to read.
1910 * @size: Size of data to read, 1=byte 2=word
1911 * @data: Pointer to the word to store the value read.
1913 * Reads a byte or word from the NVM using the flash access registers.
1915 static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1918 union ich8_hws_flash_status hsfsts;
1919 union ich8_hws_flash_ctrl hsflctl;
1920 u32 flash_linear_addr;
1922 s32 ret_val = -E1000_ERR_NVM;
1925 DEBUGFUNC("e1000_read_flash_data_ich8lan");
1927 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
1930 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1931 hw->nvm.flash_base_addr;
1936 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1937 if (ret_val != E1000_SUCCESS)
1940 hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
1941 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1942 hsflctl.hsf_ctrl.fldbcount = size - 1;
1943 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
1944 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
1946 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
1948 ret_val = e1000_flash_cycle_ich8lan(hw,
1949 ICH_FLASH_READ_COMMAND_TIMEOUT);
1952 * Check if FCERR is set to 1, if set to 1, clear it
1953 * and try the whole sequence a few more times, else
1954 * read in (shift in) the Flash Data0, the order is
1955 * least significant byte first msb to lsb
1957 if (ret_val == E1000_SUCCESS) {
1958 flash_data = E1000_READ_FLASH_REG(hw, ICH_FLASH_FDATA0);
1960 *data = (u8)(flash_data & 0x000000FF);
1962 *data = (u16)(flash_data & 0x0000FFFF);
1966 * If we've gotten here, then things are probably
1967 * completely hosed, but if the error condition is
1968 * detected, it won't hurt to give it another try...
1969 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
1971 hsfsts.regval = E1000_READ_FLASH_REG16(hw,
1973 if (hsfsts.hsf_status.flcerr == 1) {
1974 /* Repeat for some time before giving up. */
1976 } else if (hsfsts.hsf_status.flcdone == 0) {
1977 DEBUGOUT("Timeout error - flash cycle "
1978 "did not complete.");
1982 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1989 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
1990 * @hw: pointer to the HW structure
1991 * @offset: The offset (in bytes) of the word(s) to write.
1992 * @words: Size of data to write in words
1993 * @data: Pointer to the word(s) to write at offset.
1995 * Writes a byte or word to the NVM using the flash access registers.
1997 static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2000 struct e1000_nvm_info *nvm = &hw->nvm;
2001 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2002 s32 ret_val = E1000_SUCCESS;
2005 DEBUGFUNC("e1000_write_nvm_ich8lan");
2007 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2009 DEBUGOUT("nvm parameter(s) out of bounds\n");
2010 ret_val = -E1000_ERR_NVM;
2014 nvm->ops.acquire(hw);
2016 for (i = 0; i < words; i++) {
2017 dev_spec->shadow_ram[offset+i].modified = TRUE;
2018 dev_spec->shadow_ram[offset+i].value = data[i];
2021 nvm->ops.release(hw);
2028 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2029 * @hw: pointer to the HW structure
2031 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2032 * which writes the checksum to the shadow ram. The changes in the shadow
2033 * ram are then committed to the EEPROM by processing each bank at a time
2034 * checking for the modified bit and writing only the pending changes.
2035 * After a successful commit, the shadow ram is cleared and is ready for
2038 static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2040 struct e1000_nvm_info *nvm = &hw->nvm;
2041 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2042 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
2046 DEBUGFUNC("e1000_update_nvm_checksum_ich8lan");
2048 ret_val = e1000_update_nvm_checksum_generic(hw);
2052 if (nvm->type != e1000_nvm_flash_sw)
2055 nvm->ops.acquire(hw);
2058 * We're writing to the opposite bank so if we're on bank 1,
2059 * write to bank 0 etc. We also need to erase the segment that
2060 * is going to be written
2062 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
2063 if (ret_val != E1000_SUCCESS) {
2064 DEBUGOUT("Could not detect valid bank, assuming bank 0\n");
2069 new_bank_offset = nvm->flash_bank_size;
2070 old_bank_offset = 0;
2071 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
2075 old_bank_offset = nvm->flash_bank_size;
2076 new_bank_offset = 0;
2077 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
2082 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
2084 * Determine whether to write the value stored
2085 * in the other NVM bank or a modified value stored
2088 if (dev_spec->shadow_ram[i].modified) {
2089 data = dev_spec->shadow_ram[i].value;
2091 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2099 * If the word is 0x13, then make sure the signature bits
2100 * (15:14) are 11b until the commit has completed.
2101 * This will allow us to write 10b which indicates the
2102 * signature is valid. We want to do this after the write
2103 * has completed so that we don't mark the segment valid
2104 * while the write is still in progress
2106 if (i == E1000_ICH_NVM_SIG_WORD)
2107 data |= E1000_ICH_NVM_SIG_MASK;
2109 /* Convert offset to bytes. */
2110 act_offset = (i + new_bank_offset) << 1;
2113 /* Write the bytes to the new bank. */
2114 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2121 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2129 * Don't bother writing the segment valid bits if sector
2130 * programming failed.
2133 DEBUGOUT("Flash commit failed.\n");
2138 * Finally validate the new segment by setting bit 15:14
2139 * to 10b in word 0x13 , this can be done without an
2140 * erase as well since these bits are 11 to start with
2141 * and we need to change bit 14 to 0b
2143 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
2144 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
2149 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2156 * And invalidate the previously valid segment by setting
2157 * its signature word (0x13) high_byte to 0b. This can be
2158 * done without an erase because flash erase sets all bits
2159 * to 1's. We can write 1's to 0's without an erase
2161 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2162 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
2166 /* Great! Everything worked, we can now clear the cached entries. */
2167 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
2168 dev_spec->shadow_ram[i].modified = FALSE;
2169 dev_spec->shadow_ram[i].value = 0xFFFF;
2173 nvm->ops.release(hw);
2176 * Reload the EEPROM, or else modifications will not appear
2177 * until after the next adapter reset.
2180 nvm->ops.reload(hw);
2186 DEBUGOUT1("NVM update error: %d\n", ret_val);
2192 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2193 * @hw: pointer to the HW structure
2195 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2196 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
2197 * calculated, in which case we need to calculate the checksum and set bit 6.
2199 static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2201 s32 ret_val = E1000_SUCCESS;
2204 DEBUGFUNC("e1000_validate_nvm_checksum_ich8lan");
2207 * Read 0x19 and check bit 6. If this bit is 0, the checksum
2208 * needs to be fixed. This bit is an indication that the NVM
2209 * was prepared by OEM software and did not calculate the
2210 * checksum...a likely scenario.
2212 ret_val = hw->nvm.ops.read(hw, 0x19, 1, &data);
2216 if ((data & 0x40) == 0) {
2218 ret_val = hw->nvm.ops.write(hw, 0x19, 1, &data);
2221 ret_val = hw->nvm.ops.update(hw);
2226 ret_val = e1000_validate_nvm_checksum_generic(hw);
2233 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
2234 * @hw: pointer to the HW structure
2235 * @offset: The offset (in bytes) of the byte/word to read.
2236 * @size: Size of data to read, 1=byte 2=word
2237 * @data: The byte(s) to write to the NVM.
2239 * Writes one/two bytes to the NVM using the flash access registers.
2241 static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2244 union ich8_hws_flash_status hsfsts;
2245 union ich8_hws_flash_ctrl hsflctl;
2246 u32 flash_linear_addr;
2248 s32 ret_val = -E1000_ERR_NVM;
2251 DEBUGFUNC("e1000_write_ich8_data");
2253 if (size < 1 || size > 2 || data > size * 0xff ||
2254 offset > ICH_FLASH_LINEAR_ADDR_MASK)
2257 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2258 hw->nvm.flash_base_addr;
2263 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2264 if (ret_val != E1000_SUCCESS)
2267 hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
2268 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2269 hsflctl.hsf_ctrl.fldbcount = size - 1;
2270 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
2271 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
2273 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
2276 flash_data = (u32)data & 0x00FF;
2278 flash_data = (u32)data;
2280 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
2283 * check if FCERR is set to 1 , if set to 1, clear it
2284 * and try the whole sequence a few more times else done
2286 ret_val = e1000_flash_cycle_ich8lan(hw,
2287 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
2288 if (ret_val == E1000_SUCCESS)
2292 * If we're here, then things are most likely
2293 * completely hosed, but if the error condition
2294 * is detected, it won't hurt to give it another
2295 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
2297 hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
2298 if (hsfsts.hsf_status.flcerr == 1)
2299 /* Repeat for some time before giving up. */
2301 if (hsfsts.hsf_status.flcdone == 0) {
2302 DEBUGOUT("Timeout error - flash cycle "
2303 "did not complete.");
2306 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2313 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
2314 * @hw: pointer to the HW structure
2315 * @offset: The index of the byte to read.
2316 * @data: The byte to write to the NVM.
2318 * Writes a single byte to the NVM using the flash access registers.
2320 static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2323 u16 word = (u16)data;
2325 DEBUGFUNC("e1000_write_flash_byte_ich8lan");
2327 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
2331 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
2332 * @hw: pointer to the HW structure
2333 * @offset: The offset of the byte to write.
2334 * @byte: The byte to write to the NVM.
2336 * Writes a single byte to the NVM using the flash access registers.
2337 * Goes through a retry algorithm before giving up.
2339 static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
2340 u32 offset, u8 byte)
2343 u16 program_retries;
2345 DEBUGFUNC("e1000_retry_write_flash_byte_ich8lan");
2347 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2348 if (ret_val == E1000_SUCCESS)
2351 for (program_retries = 0; program_retries < 100; program_retries++) {
2352 DEBUGOUT2("Retrying Byte %2.2X at offset %u\n", byte, offset);
2354 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2355 if (ret_val == E1000_SUCCESS)
2358 if (program_retries == 100) {
2359 ret_val = -E1000_ERR_NVM;
2368 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
2369 * @hw: pointer to the HW structure
2370 * @bank: 0 for first bank, 1 for second bank, etc.
2372 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
2373 * bank N is 4096 * N + flash_reg_addr.
2375 static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
2377 struct e1000_nvm_info *nvm = &hw->nvm;
2378 union ich8_hws_flash_status hsfsts;
2379 union ich8_hws_flash_ctrl hsflctl;
2380 u32 flash_linear_addr;
2381 /* bank size is in 16bit words - adjust to bytes */
2382 u32 flash_bank_size = nvm->flash_bank_size * 2;
2383 s32 ret_val = E1000_SUCCESS;
2385 s32 j, iteration, sector_size;
2387 DEBUGFUNC("e1000_erase_flash_bank_ich8lan");
2389 hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
2392 * Determine HW Sector size: Read BERASE bits of hw flash status
2394 * 00: The Hw sector is 256 bytes, hence we need to erase 16
2395 * consecutive sectors. The start index for the nth Hw sector
2396 * can be calculated as = bank * 4096 + n * 256
2397 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
2398 * The start index for the nth Hw sector can be calculated
2400 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
2401 * (ich9 only, otherwise error condition)
2402 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
2404 switch (hsfsts.hsf_status.berasesz) {
2406 /* Hw sector size 256 */
2407 sector_size = ICH_FLASH_SEG_SIZE_256;
2408 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
2411 sector_size = ICH_FLASH_SEG_SIZE_4K;
2415 sector_size = ICH_FLASH_SEG_SIZE_8K;
2419 sector_size = ICH_FLASH_SEG_SIZE_64K;
2423 ret_val = -E1000_ERR_NVM;
2427 /* Start with the base address, then add the sector offset. */
2428 flash_linear_addr = hw->nvm.flash_base_addr;
2429 flash_linear_addr += (bank) ? flash_bank_size : 0;
2431 for (j = 0; j < iteration ; j++) {
2434 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2439 * Write a value 11 (block Erase) in Flash
2440 * Cycle field in hw flash control
2442 hsflctl.regval = E1000_READ_FLASH_REG16(hw,
2444 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
2445 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL,
2449 * Write the last 24 bits of an index within the
2450 * block into Flash Linear address field in Flash
2453 flash_linear_addr += (j * sector_size);
2454 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR,
2457 ret_val = e1000_flash_cycle_ich8lan(hw,
2458 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
2459 if (ret_val == E1000_SUCCESS)
2463 * Check if FCERR is set to 1. If 1,
2464 * clear it and try the whole sequence
2465 * a few more times else Done
2467 hsfsts.regval = E1000_READ_FLASH_REG16(hw,
2469 if (hsfsts.hsf_status.flcerr == 1)
2470 /* repeat for some time before giving up */
2472 else if (hsfsts.hsf_status.flcdone == 0)
2474 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
2482 * e1000_valid_led_default_ich8lan - Set the default LED settings
2483 * @hw: pointer to the HW structure
2484 * @data: Pointer to the LED settings
2486 * Reads the LED default settings from the NVM to data. If the NVM LED
2487 * settings is all 0's or F's, set the LED default to a valid LED default
2490 static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
2494 DEBUGFUNC("e1000_valid_led_default_ich8lan");
2496 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
2498 DEBUGOUT("NVM Read Error\n");
2502 if (*data == ID_LED_RESERVED_0000 ||
2503 *data == ID_LED_RESERVED_FFFF)
2504 *data = ID_LED_DEFAULT_ICH8LAN;
2511 * e1000_id_led_init_pchlan - store LED configurations
2512 * @hw: pointer to the HW structure
2514 * PCH does not control LEDs via the LEDCTL register, rather it uses
2515 * the PHY LED configuration register.
2517 * PCH also does not have an "always on" or "always off" mode which
2518 * complicates the ID feature. Instead of using the "on" mode to indicate
2519 * in ledctl_mode2 the LEDs to use for ID (see e1000_id_led_init_generic()),
2520 * use "link_up" mode. The LEDs will still ID on request if there is no
2521 * link based on logic in e1000_led_[on|off]_pchlan().
2523 static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
2525 struct e1000_mac_info *mac = &hw->mac;
2527 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
2528 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
2529 u16 data, i, temp, shift;
2531 DEBUGFUNC("e1000_id_led_init_pchlan");
2533 /* Get default ID LED modes */
2534 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
2538 mac->ledctl_default = E1000_READ_REG(hw, E1000_LEDCTL);
2539 mac->ledctl_mode1 = mac->ledctl_default;
2540 mac->ledctl_mode2 = mac->ledctl_default;
2542 for (i = 0; i < 4; i++) {
2543 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
2546 case ID_LED_ON1_DEF2:
2547 case ID_LED_ON1_ON2:
2548 case ID_LED_ON1_OFF2:
2549 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2550 mac->ledctl_mode1 |= (ledctl_on << shift);
2552 case ID_LED_OFF1_DEF2:
2553 case ID_LED_OFF1_ON2:
2554 case ID_LED_OFF1_OFF2:
2555 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2556 mac->ledctl_mode1 |= (ledctl_off << shift);
2563 case ID_LED_DEF1_ON2:
2564 case ID_LED_ON1_ON2:
2565 case ID_LED_OFF1_ON2:
2566 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2567 mac->ledctl_mode2 |= (ledctl_on << shift);
2569 case ID_LED_DEF1_OFF2:
2570 case ID_LED_ON1_OFF2:
2571 case ID_LED_OFF1_OFF2:
2572 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2573 mac->ledctl_mode2 |= (ledctl_off << shift);
2586 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
2587 * @hw: pointer to the HW structure
2589 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
2590 * register, so the the bus width is hard coded.
2592 static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
2594 struct e1000_bus_info *bus = &hw->bus;
2597 DEBUGFUNC("e1000_get_bus_info_ich8lan");
2599 ret_val = e1000_get_bus_info_pcie_generic(hw);
2602 * ICH devices are "PCI Express"-ish. They have
2603 * a configuration space, but do not contain
2604 * PCI Express Capability registers, so bus width
2605 * must be hardcoded.
2607 if (bus->width == e1000_bus_width_unknown)
2608 bus->width = e1000_bus_width_pcie_x1;
2614 * e1000_reset_hw_ich8lan - Reset the hardware
2615 * @hw: pointer to the HW structure
2617 * Does a full reset of the hardware which includes a reset of the PHY and
2620 static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2622 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2627 DEBUGFUNC("e1000_reset_hw_ich8lan");
2630 * Prevent the PCI-E bus from sticking if there is no TLP connection
2631 * on the last TLP read/write transaction when MAC is reset.
2633 ret_val = e1000_disable_pcie_master_generic(hw);
2635 DEBUGOUT("PCI-E Master disable polling has failed.\n");
2637 DEBUGOUT("Masking off all interrupts\n");
2638 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2641 * Disable the Transmit and Receive units. Then delay to allow
2642 * any pending transactions to complete before we hit the MAC
2643 * with the global reset.
2645 E1000_WRITE_REG(hw, E1000_RCTL, 0);
2646 E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
2647 E1000_WRITE_FLUSH(hw);
2651 /* Workaround for ICH8 bit corruption issue in FIFO memory */
2652 if (hw->mac.type == e1000_ich8lan) {
2653 /* Set Tx and Rx buffer allocation to 8k apiece. */
2654 E1000_WRITE_REG(hw, E1000_PBA, E1000_PBA_8K);
2655 /* Set Packet Buffer Size to 16k. */
2656 E1000_WRITE_REG(hw, E1000_PBS, E1000_PBS_16K);
2659 if (hw->mac.type == e1000_pchlan) {
2660 /* Save the NVM K1 bit setting*/
2661 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, ®);
2665 if (reg & E1000_NVM_K1_ENABLE)
2666 dev_spec->nvm_k1_enabled = TRUE;
2668 dev_spec->nvm_k1_enabled = FALSE;
2671 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2673 if (!hw->phy.ops.check_reset_block(hw) && !hw->phy.reset_disable) {
2674 /* Clear PHY Reset Asserted bit */
2675 if (hw->mac.type >= e1000_pchlan) {
2676 u32 status = E1000_READ_REG(hw, E1000_STATUS);
2677 E1000_WRITE_REG(hw, E1000_STATUS, status &
2678 ~E1000_STATUS_PHYRA);
2682 * PHY HW reset requires MAC CORE reset at the same
2683 * time to make sure the interface between MAC and the
2684 * external PHY is reset.
2686 ctrl |= E1000_CTRL_PHY_RST;
2688 ret_val = e1000_acquire_swflag_ich8lan(hw);
2689 DEBUGOUT("Issuing a global reset to ich8lan\n");
2690 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl | E1000_CTRL_RST));
2694 e1000_release_swflag_ich8lan(hw);
2696 /* Perform any necessary post-reset workarounds */
2697 switch (hw->mac.type) {
2699 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2707 if (ctrl & E1000_CTRL_PHY_RST)
2708 ret_val = hw->phy.ops.get_cfg_done(hw);
2710 if (hw->mac.type >= e1000_ich10lan) {
2711 e1000_lan_init_done_ich8lan(hw);
2713 ret_val = e1000_get_auto_rd_done_generic(hw);
2716 * When auto config read does not complete, do not
2717 * return with an error. This can happen in situations
2718 * where there is no eeprom and prevents getting link.
2720 DEBUGOUT("Auto Read Done did not complete\n");
2723 /* Dummy read to clear the phy wakeup bit after lcd reset */
2724 if (hw->mac.type == e1000_pchlan)
2725 hw->phy.ops.read_reg(hw, BM_WUC, ®);
2727 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2731 ret_val = e1000_oem_bits_config_ich8lan(hw, TRUE);
2735 * For PCH, this write will make sure that any noise
2736 * will be detected as a CRC error and be dropped rather than show up
2737 * as a bad packet to the DMA engine.
2739 if (hw->mac.type == e1000_pchlan)
2740 E1000_WRITE_REG(hw, E1000_CRC_OFFSET, 0x65656565);
2742 E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2743 icr = E1000_READ_REG(hw, E1000_ICR);
2745 kab = E1000_READ_REG(hw, E1000_KABGTXD);
2746 kab |= E1000_KABGTXD_BGSQLBIAS;
2747 E1000_WRITE_REG(hw, E1000_KABGTXD, kab);
2754 * e1000_init_hw_ich8lan - Initialize the hardware
2755 * @hw: pointer to the HW structure
2757 * Prepares the hardware for transmit and receive by doing the following:
2758 * - initialize hardware bits
2759 * - initialize LED identification
2760 * - setup receive address registers
2761 * - setup flow control
2762 * - setup transmit descriptors
2763 * - clear statistics
2765 static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
2767 struct e1000_mac_info *mac = &hw->mac;
2768 u32 ctrl_ext, txdctl, snoop;
2772 DEBUGFUNC("e1000_init_hw_ich8lan");
2774 e1000_initialize_hw_bits_ich8lan(hw);
2776 /* Initialize identification LED */
2777 ret_val = mac->ops.id_led_init(hw);
2779 DEBUGOUT("Error initializing identification LED\n");
2780 /* This is not fatal and we should not stop init due to this */
2782 /* Setup the receive address. */
2783 e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
2785 /* Zero out the Multicast HASH table */
2786 DEBUGOUT("Zeroing the MTA\n");
2787 for (i = 0; i < mac->mta_reg_count; i++)
2788 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
2791 * The 82578 Rx buffer will stall if wakeup is enabled in host and
2792 * the ME. Reading the BM_WUC register will clear the host wakeup bit.
2793 * Reset the phy after disabling host wakeup to reset the Rx buffer.
2795 if (hw->phy.type == e1000_phy_82578) {
2796 hw->phy.ops.read_reg(hw, BM_WUC, &i);
2797 ret_val = e1000_phy_hw_reset_ich8lan(hw);
2802 /* Setup link and flow control */
2803 ret_val = mac->ops.setup_link(hw);
2805 /* Set the transmit descriptor write-back policy for both queues */
2806 txdctl = E1000_READ_REG(hw, E1000_TXDCTL(0));
2807 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2808 E1000_TXDCTL_FULL_TX_DESC_WB;
2809 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2810 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
2811 E1000_WRITE_REG(hw, E1000_TXDCTL(0), txdctl);
2812 txdctl = E1000_READ_REG(hw, E1000_TXDCTL(1));
2813 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2814 E1000_TXDCTL_FULL_TX_DESC_WB;
2815 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2816 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
2817 E1000_WRITE_REG(hw, E1000_TXDCTL(1), txdctl);
2820 * ICH8 has opposite polarity of no_snoop bits.
2821 * By default, we should use snoop behavior.
2823 if (mac->type == e1000_ich8lan)
2824 snoop = PCIE_ICH8_SNOOP_ALL;
2826 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
2827 e1000_set_pcie_no_snoop_generic(hw, snoop);
2829 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2830 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2831 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
2834 * Clear all of the statistics registers (clear on read). It is
2835 * important that we do this after we have tried to establish link
2836 * because the symbol error count will increment wildly if there
2839 e1000_clear_hw_cntrs_ich8lan(hw);
2844 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
2845 * @hw: pointer to the HW structure
2847 * Sets/Clears required hardware bits necessary for correctly setting up the
2848 * hardware for transmit and receive.
2850 static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
2854 DEBUGFUNC("e1000_initialize_hw_bits_ich8lan");
2856 /* Extended Device Control */
2857 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2859 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
2860 if (hw->mac.type >= e1000_pchlan)
2861 reg |= E1000_CTRL_EXT_PHYPDEN;
2862 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2864 /* Transmit Descriptor Control 0 */
2865 reg = E1000_READ_REG(hw, E1000_TXDCTL(0));
2867 E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg);
2869 /* Transmit Descriptor Control 1 */
2870 reg = E1000_READ_REG(hw, E1000_TXDCTL(1));
2872 E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg);
2874 /* Transmit Arbitration Control 0 */
2875 reg = E1000_READ_REG(hw, E1000_TARC(0));
2876 if (hw->mac.type == e1000_ich8lan)
2877 reg |= (1 << 28) | (1 << 29);
2878 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
2879 E1000_WRITE_REG(hw, E1000_TARC(0), reg);
2881 /* Transmit Arbitration Control 1 */
2882 reg = E1000_READ_REG(hw, E1000_TARC(1));
2883 if (E1000_READ_REG(hw, E1000_TCTL) & E1000_TCTL_MULR)
2887 reg |= (1 << 24) | (1 << 26) | (1 << 30);
2888 E1000_WRITE_REG(hw, E1000_TARC(1), reg);
2891 if (hw->mac.type == e1000_ich8lan) {
2892 reg = E1000_READ_REG(hw, E1000_STATUS);
2894 E1000_WRITE_REG(hw, E1000_STATUS, reg);
2898 * work-around descriptor data corruption issue during nfs v2 udp
2899 * traffic, just disable the nfs filtering capability
2901 reg = E1000_READ_REG(hw, E1000_RFCTL);
2902 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
2903 E1000_WRITE_REG(hw, E1000_RFCTL, reg);
2909 * e1000_setup_link_ich8lan - Setup flow control and link settings
2910 * @hw: pointer to the HW structure
2912 * Determines which flow control settings to use, then configures flow
2913 * control. Calls the appropriate media-specific link configuration
2914 * function. Assuming the adapter has a valid link partner, a valid link
2915 * should be established. Assumes the hardware has previously been reset
2916 * and the transmitter and receiver are not enabled.
2918 static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
2920 s32 ret_val = E1000_SUCCESS;
2922 DEBUGFUNC("e1000_setup_link_ich8lan");
2924 if (hw->phy.ops.check_reset_block(hw))
2928 * ICH parts do not have a word in the NVM to determine
2929 * the default flow control setting, so we explicitly
2932 if (hw->fc.requested_mode == e1000_fc_default)
2933 hw->fc.requested_mode = e1000_fc_full;
2936 * Save off the requested flow control mode for use later. Depending
2937 * on the link partner's capabilities, we may or may not use this mode.
2939 hw->fc.current_mode = hw->fc.requested_mode;
2941 DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
2942 hw->fc.current_mode);
2944 /* Continue to configure the copper link. */
2945 ret_val = hw->mac.ops.setup_physical_interface(hw);
2949 E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
2950 if ((hw->phy.type == e1000_phy_82578) ||
2951 (hw->phy.type == e1000_phy_82577)) {
2952 ret_val = hw->phy.ops.write_reg(hw,
2953 PHY_REG(BM_PORT_CTRL_PAGE, 27),
2959 ret_val = e1000_set_fc_watermarks_generic(hw);
2966 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
2967 * @hw: pointer to the HW structure
2969 * Configures the kumeran interface to the PHY to wait the appropriate time
2970 * when polling the PHY, then call the generic setup_copper_link to finish
2971 * configuring the copper link.
2973 static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
2979 DEBUGFUNC("e1000_setup_copper_link_ich8lan");
2981 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2982 ctrl |= E1000_CTRL_SLU;
2983 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2984 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2987 * Set the mac to wait the maximum time between each iteration
2988 * and increase the max iterations when polling the phy;
2989 * this fixes erroneous timeouts at 10Mbps.
2991 ret_val = e1000_write_kmrn_reg_generic(hw, E1000_KMRNCTRLSTA_TIMEOUTS,
2995 ret_val = e1000_read_kmrn_reg_generic(hw,
2996 E1000_KMRNCTRLSTA_INBAND_PARAM,
3001 ret_val = e1000_write_kmrn_reg_generic(hw,
3002 E1000_KMRNCTRLSTA_INBAND_PARAM,
3007 switch (hw->phy.type) {
3008 case e1000_phy_igp_3:
3009 ret_val = e1000_copper_link_setup_igp(hw);
3014 case e1000_phy_82578:
3015 ret_val = e1000_copper_link_setup_m88(hw);
3019 case e1000_phy_82577:
3020 ret_val = e1000_copper_link_setup_82577(hw);
3025 ret_val = hw->phy.ops.read_reg(hw, IFE_PHY_MDIX_CONTROL,
3030 reg_data &= ~IFE_PMC_AUTO_MDIX;
3032 switch (hw->phy.mdix) {
3034 reg_data &= ~IFE_PMC_FORCE_MDIX;
3037 reg_data |= IFE_PMC_FORCE_MDIX;
3041 reg_data |= IFE_PMC_AUTO_MDIX;
3044 ret_val = hw->phy.ops.write_reg(hw, IFE_PHY_MDIX_CONTROL,
3052 ret_val = e1000_setup_copper_link_generic(hw);
3059 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3060 * @hw: pointer to the HW structure
3061 * @speed: pointer to store current link speed
3062 * @duplex: pointer to store the current link duplex
3064 * Calls the generic get_speed_and_duplex to retrieve the current link
3065 * information and then calls the Kumeran lock loss workaround for links at
3068 static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3073 DEBUGFUNC("e1000_get_link_up_info_ich8lan");
3075 ret_val = e1000_get_speed_and_duplex_copper_generic(hw, speed, duplex);
3079 if ((hw->mac.type == e1000_ich8lan) &&
3080 (hw->phy.type == e1000_phy_igp_3) &&
3081 (*speed == SPEED_1000)) {
3082 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3090 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3091 * @hw: pointer to the HW structure
3093 * Work-around for 82566 Kumeran PCS lock loss:
3094 * On link status change (i.e. PCI reset, speed change) and link is up and
3096 * 0) if workaround is optionally disabled do nothing
3097 * 1) wait 1ms for Kumeran link to come up
3098 * 2) check Kumeran Diagnostic register PCS lock loss bit
3099 * 3) if not set the link is locked (all is good), otherwise...
3101 * 5) repeat up to 10 times
3102 * Note: this is only called for IGP3 copper when speed is 1gb.
3104 static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3106 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3108 s32 ret_val = E1000_SUCCESS;
3112 DEBUGFUNC("e1000_kmrn_lock_loss_workaround_ich8lan");
3114 if (!(dev_spec->kmrn_lock_loss_workaround_enabled))
3118 * Make sure link is up before proceeding. If not just return.
3119 * Attempting this while link is negotiating fouled up link
3122 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
3124 ret_val = E1000_SUCCESS;
3128 for (i = 0; i < 10; i++) {
3129 /* read once to clear */
3130 ret_val = hw->phy.ops.read_reg(hw, IGP3_KMRN_DIAG, &data);
3133 /* and again to get new status */
3134 ret_val = hw->phy.ops.read_reg(hw, IGP3_KMRN_DIAG, &data);
3138 /* check for PCS lock */
3139 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS)) {
3140 ret_val = E1000_SUCCESS;
3144 /* Issue PHY reset */
3145 hw->phy.ops.reset(hw);
3148 /* Disable GigE link negotiation */
3149 phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
3150 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3151 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3152 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
3155 * Call gig speed drop workaround on Gig disable before accessing
3158 e1000_gig_downshift_workaround_ich8lan(hw);
3160 /* unable to acquire PCS lock */
3161 ret_val = -E1000_ERR_PHY;
3168 * e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
3169 * @hw: pointer to the HW structure
3170 * @state: boolean value used to set the current Kumeran workaround state
3172 * If ICH8, set the current Kumeran workaround state (enabled - TRUE
3173 * /disabled - FALSE).
3175 void e1000_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3178 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3180 DEBUGFUNC("e1000_set_kmrn_lock_loss_workaround_ich8lan");
3182 if (hw->mac.type != e1000_ich8lan) {
3183 DEBUGOUT("Workaround applies to ICH8 only.\n");
3187 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3193 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3194 * @hw: pointer to the HW structure
3196 * Workaround for 82566 power-down on D3 entry:
3197 * 1) disable gigabit link
3198 * 2) write VR power-down enable
3200 * Continue if successful, else issue LCD reset and repeat
3202 void e1000_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3208 DEBUGFUNC("e1000_igp3_phy_powerdown_workaround_ich8lan");
3210 if (hw->phy.type != e1000_phy_igp_3)
3213 /* Try the workaround twice (if needed) */
3216 reg = E1000_READ_REG(hw, E1000_PHY_CTRL);
3217 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3218 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3219 E1000_WRITE_REG(hw, E1000_PHY_CTRL, reg);
3222 * Call gig speed drop workaround on Gig disable before
3223 * accessing any PHY registers
3225 if (hw->mac.type == e1000_ich8lan)
3226 e1000_gig_downshift_workaround_ich8lan(hw);
3228 /* Write VR power-down enable */
3229 hw->phy.ops.read_reg(hw, IGP3_VR_CTRL, &data);
3230 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3231 hw->phy.ops.write_reg(hw, IGP3_VR_CTRL,
3232 data | IGP3_VR_CTRL_MODE_SHUTDOWN);
3234 /* Read it back and test */
3235 hw->phy.ops.read_reg(hw, IGP3_VR_CTRL, &data);
3236 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3237 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
3240 /* Issue PHY reset and repeat at most one more time */
3241 reg = E1000_READ_REG(hw, E1000_CTRL);
3242 E1000_WRITE_REG(hw, E1000_CTRL, reg | E1000_CTRL_PHY_RST);
3251 * e1000_gig_downshift_workaround_ich8lan - WoL from S5 stops working
3252 * @hw: pointer to the HW structure
3254 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
3255 * LPLU, Gig disable, MDIC PHY reset):
3256 * 1) Set Kumeran Near-end loopback
3257 * 2) Clear Kumeran Near-end loopback
3258 * Should only be called for ICH8[m] devices with IGP_3 Phy.
3260 void e1000_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
3262 s32 ret_val = E1000_SUCCESS;
3265 DEBUGFUNC("e1000_gig_downshift_workaround_ich8lan");
3267 if ((hw->mac.type != e1000_ich8lan) ||
3268 (hw->phy.type != e1000_phy_igp_3))
3271 ret_val = e1000_read_kmrn_reg_generic(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3275 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
3276 ret_val = e1000_write_kmrn_reg_generic(hw,
3277 E1000_KMRNCTRLSTA_DIAG_OFFSET,
3281 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
3282 ret_val = e1000_write_kmrn_reg_generic(hw,
3283 E1000_KMRNCTRLSTA_DIAG_OFFSET,
3290 * e1000_disable_gig_wol_ich8lan - disable gig during WoL
3291 * @hw: pointer to the HW structure
3293 * During S0 to Sx transition, it is possible the link remains at gig
3294 * instead of negotiating to a lower speed. Before going to Sx, set
3295 * 'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
3298 * Should only be called for applicable parts.
3300 void e1000_disable_gig_wol_ich8lan(struct e1000_hw *hw)
3304 switch (hw->mac.type) {
3307 case e1000_ich10lan:
3309 phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
3310 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
3311 E1000_PHY_CTRL_GBE_DISABLE;
3312 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
3314 if (hw->mac.type == e1000_pchlan)
3315 e1000_phy_hw_reset_ich8lan(hw);
3324 * e1000_cleanup_led_ich8lan - Restore the default LED operation
3325 * @hw: pointer to the HW structure
3327 * Return the LED back to the default configuration.
3329 static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
3331 DEBUGFUNC("e1000_cleanup_led_ich8lan");
3333 if (hw->phy.type == e1000_phy_ife)
3334 return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3337 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default);
3338 return E1000_SUCCESS;
3342 * e1000_led_on_ich8lan - Turn LEDs on
3343 * @hw: pointer to the HW structure
3347 static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
3349 DEBUGFUNC("e1000_led_on_ich8lan");
3351 if (hw->phy.type == e1000_phy_ife)
3352 return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3353 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
3355 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode2);
3356 return E1000_SUCCESS;
3360 * e1000_led_off_ich8lan - Turn LEDs off
3361 * @hw: pointer to the HW structure
3363 * Turn off the LEDs.
3365 static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
3367 DEBUGFUNC("e1000_led_off_ich8lan");
3369 if (hw->phy.type == e1000_phy_ife)
3370 return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3371 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
3373 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
3374 return E1000_SUCCESS;
3378 * e1000_setup_led_pchlan - Configures SW controllable LED
3379 * @hw: pointer to the HW structure
3381 * This prepares the SW controllable LED for use.
3383 static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
3385 DEBUGFUNC("e1000_setup_led_pchlan");
3387 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
3388 (u16)hw->mac.ledctl_mode1);
3392 * e1000_cleanup_led_pchlan - Restore the default LED operation
3393 * @hw: pointer to the HW structure
3395 * Return the LED back to the default configuration.
3397 static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
3399 DEBUGFUNC("e1000_cleanup_led_pchlan");
3401 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
3402 (u16)hw->mac.ledctl_default);
3406 * e1000_led_on_pchlan - Turn LEDs on
3407 * @hw: pointer to the HW structure
3411 static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
3413 u16 data = (u16)hw->mac.ledctl_mode2;
3416 DEBUGFUNC("e1000_led_on_pchlan");
3419 * If no link, then turn LED on by setting the invert bit
3420 * for each LED that's mode is "link_up" in ledctl_mode2.
3422 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
3423 for (i = 0; i < 3; i++) {
3424 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3425 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3426 E1000_LEDCTL_MODE_LINK_UP)
3428 if (led & E1000_PHY_LED0_IVRT)
3429 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3431 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3435 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
3439 * e1000_led_off_pchlan - Turn LEDs off
3440 * @hw: pointer to the HW structure
3442 * Turn off the LEDs.
3444 static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
3446 u16 data = (u16)hw->mac.ledctl_mode1;
3449 DEBUGFUNC("e1000_led_off_pchlan");
3452 * If no link, then turn LED off by clearing the invert bit
3453 * for each LED that's mode is "link_up" in ledctl_mode1.
3455 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
3456 for (i = 0; i < 3; i++) {
3457 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3458 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3459 E1000_LEDCTL_MODE_LINK_UP)
3461 if (led & E1000_PHY_LED0_IVRT)
3462 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3464 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3468 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
3472 * e1000_get_cfg_done_ich8lan - Read config done bit
3473 * @hw: pointer to the HW structure
3475 * Read the management control register for the config done bit for
3476 * completion status. NOTE: silicon which is EEPROM-less will fail trying
3477 * to read the config done bit, so an error is *ONLY* logged and returns
3478 * E1000_SUCCESS. If we were to return with error, EEPROM-less silicon
3479 * would not be able to be reset or change link.
3481 static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
3483 s32 ret_val = E1000_SUCCESS;
3486 if (hw->mac.type >= e1000_pchlan) {
3487 u32 status = E1000_READ_REG(hw, E1000_STATUS);
3489 if (status & E1000_STATUS_PHYRA)
3490 E1000_WRITE_REG(hw, E1000_STATUS, status &
3491 ~E1000_STATUS_PHYRA);
3493 DEBUGOUT("PHY Reset Asserted not set - needs delay\n");
3496 e1000_get_cfg_done_generic(hw);
3498 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
3499 if (hw->mac.type <= e1000_ich9lan) {
3500 if (((E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_PRES) == 0) &&
3501 (hw->phy.type == e1000_phy_igp_3)) {
3502 e1000_phy_init_script_igp3(hw);
3505 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
3506 /* Maybe we should do a basic PHY config */
3507 DEBUGOUT("EEPROM not present\n");
3508 ret_val = -E1000_ERR_CONFIG;
3516 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
3517 * @hw: pointer to the HW structure
3519 * In the case of a PHY power down to save power, or to turn off link during a
3520 * driver unload, or wake on lan is not enabled, remove the link.
3522 static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
3524 /* If the management interface is not enabled, then power down */
3525 if (!(hw->mac.ops.check_mng_mode(hw) ||
3526 hw->phy.ops.check_reset_block(hw)))
3527 e1000_power_down_phy_copper(hw);
3533 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
3534 * @hw: pointer to the HW structure
3536 * Clears hardware counters specific to the silicon family and calls
3537 * clear_hw_cntrs_generic to clear all general purpose counters.
3539 static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
3543 DEBUGFUNC("e1000_clear_hw_cntrs_ich8lan");
3545 e1000_clear_hw_cntrs_base_generic(hw);
3547 E1000_READ_REG(hw, E1000_ALGNERRC);
3548 E1000_READ_REG(hw, E1000_RXERRC);
3549 E1000_READ_REG(hw, E1000_TNCRS);
3550 E1000_READ_REG(hw, E1000_CEXTERR);
3551 E1000_READ_REG(hw, E1000_TSCTC);
3552 E1000_READ_REG(hw, E1000_TSCTFC);
3554 E1000_READ_REG(hw, E1000_MGTPRC);
3555 E1000_READ_REG(hw, E1000_MGTPDC);
3556 E1000_READ_REG(hw, E1000_MGTPTC);
3558 E1000_READ_REG(hw, E1000_IAC);
3559 E1000_READ_REG(hw, E1000_ICRXOC);
3561 /* Clear PHY statistics registers */
3562 if ((hw->phy.type == e1000_phy_82578) ||
3563 (hw->phy.type == e1000_phy_82577)) {
3564 hw->phy.ops.read_reg(hw, HV_SCC_UPPER, &phy_data);
3565 hw->phy.ops.read_reg(hw, HV_SCC_LOWER, &phy_data);
3566 hw->phy.ops.read_reg(hw, HV_ECOL_UPPER, &phy_data);
3567 hw->phy.ops.read_reg(hw, HV_ECOL_LOWER, &phy_data);
3568 hw->phy.ops.read_reg(hw, HV_MCC_UPPER, &phy_data);
3569 hw->phy.ops.read_reg(hw, HV_MCC_LOWER, &phy_data);
3570 hw->phy.ops.read_reg(hw, HV_LATECOL_UPPER, &phy_data);
3571 hw->phy.ops.read_reg(hw, HV_LATECOL_LOWER, &phy_data);
3572 hw->phy.ops.read_reg(hw, HV_COLC_UPPER, &phy_data);
3573 hw->phy.ops.read_reg(hw, HV_COLC_LOWER, &phy_data);
3574 hw->phy.ops.read_reg(hw, HV_DC_UPPER, &phy_data);
3575 hw->phy.ops.read_reg(hw, HV_DC_LOWER, &phy_data);
3576 hw->phy.ops.read_reg(hw, HV_TNCRS_UPPER, &phy_data);
3577 hw->phy.ops.read_reg(hw, HV_TNCRS_LOWER, &phy_data);