e1000e: cosmetic newline in debug message
[linux-2.6/mini2440.git] / drivers / net / e1000e / ich8lan.c
blob33898ead9276c8562e46deee64b53b445441fb70
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * 82562G 10/100 Network Connection
31 * 82562G-2 10/100 Network Connection
32 * 82562GT 10/100 Network Connection
33 * 82562GT-2 10/100 Network Connection
34 * 82562V 10/100 Network Connection
35 * 82562V-2 10/100 Network Connection
36 * 82566DC-2 Gigabit Network Connection
37 * 82566DC Gigabit Network Connection
38 * 82566DM-2 Gigabit Network Connection
39 * 82566DM Gigabit Network Connection
40 * 82566MC Gigabit Network Connection
41 * 82566MM Gigabit Network Connection
42 * 82567LM Gigabit Network Connection
43 * 82567LF Gigabit Network Connection
44 * 82567V Gigabit Network Connection
45 * 82567LM-2 Gigabit Network Connection
46 * 82567LF-2 Gigabit Network Connection
47 * 82567V-2 Gigabit Network Connection
48 * 82567LF-3 Gigabit Network Connection
49 * 82567LM-3 Gigabit Network Connection
50 * 82567LM-4 Gigabit Network Connection
53 #include <linux/netdevice.h>
54 #include <linux/ethtool.h>
55 #include <linux/delay.h>
56 #include <linux/pci.h>
58 #include "e1000.h"
60 #define ICH_FLASH_GFPREG 0x0000
61 #define ICH_FLASH_HSFSTS 0x0004
62 #define ICH_FLASH_HSFCTL 0x0006
63 #define ICH_FLASH_FADDR 0x0008
64 #define ICH_FLASH_FDATA0 0x0010
65 #define ICH_FLASH_PR0 0x0074
67 #define ICH_FLASH_READ_COMMAND_TIMEOUT 500
68 #define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
69 #define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
70 #define ICH_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
71 #define ICH_FLASH_CYCLE_REPEAT_COUNT 10
73 #define ICH_CYCLE_READ 0
74 #define ICH_CYCLE_WRITE 2
75 #define ICH_CYCLE_ERASE 3
77 #define FLASH_GFPREG_BASE_MASK 0x1FFF
78 #define FLASH_SECTOR_ADDR_SHIFT 12
80 #define ICH_FLASH_SEG_SIZE_256 256
81 #define ICH_FLASH_SEG_SIZE_4K 4096
82 #define ICH_FLASH_SEG_SIZE_8K 8192
83 #define ICH_FLASH_SEG_SIZE_64K 65536
86 #define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
88 #define E1000_ICH_MNG_IAMT_MODE 0x2
90 #define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
91 (ID_LED_DEF1_OFF2 << 8) | \
92 (ID_LED_DEF1_ON2 << 4) | \
93 (ID_LED_DEF1_DEF2))
95 #define E1000_ICH_NVM_SIG_WORD 0x13
96 #define E1000_ICH_NVM_SIG_MASK 0xC000
98 #define E1000_ICH8_LAN_INIT_TIMEOUT 1500
100 #define E1000_FEXTNVM_SW_CONFIG 1
101 #define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
103 #define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
105 #define E1000_ICH_RAR_ENTRIES 7
107 #define PHY_PAGE_SHIFT 5
108 #define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
109 ((reg) & MAX_PHY_REG_ADDRESS))
110 #define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
111 #define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
113 #define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
114 #define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
115 #define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
117 /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
118 /* Offset 04h HSFSTS */
119 union ich8_hws_flash_status {
120 struct ich8_hsfsts {
121 u16 flcdone :1; /* bit 0 Flash Cycle Done */
122 u16 flcerr :1; /* bit 1 Flash Cycle Error */
123 u16 dael :1; /* bit 2 Direct Access error Log */
124 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
125 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
126 u16 reserved1 :2; /* bit 13:6 Reserved */
127 u16 reserved2 :6; /* bit 13:6 Reserved */
128 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
129 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
130 } hsf_status;
131 u16 regval;
134 /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
135 /* Offset 06h FLCTL */
136 union ich8_hws_flash_ctrl {
137 struct ich8_hsflctl {
138 u16 flcgo :1; /* 0 Flash Cycle Go */
139 u16 flcycle :2; /* 2:1 Flash Cycle */
140 u16 reserved :5; /* 7:3 Reserved */
141 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
142 u16 flockdn :6; /* 15:10 Reserved */
143 } hsf_ctrl;
144 u16 regval;
147 /* ICH Flash Region Access Permissions */
148 union ich8_hws_flash_regacc {
149 struct ich8_flracc {
150 u32 grra :8; /* 0:7 GbE region Read Access */
151 u32 grwa :8; /* 8:15 GbE region Write Access */
152 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
153 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
154 } hsf_flregacc;
155 u16 regval;
158 /* ICH Flash Protected Region */
159 union ich8_flash_protected_range {
160 struct ich8_pr {
161 u32 base:13; /* 0:12 Protected Range Base */
162 u32 reserved1:2; /* 13:14 Reserved */
163 u32 rpe:1; /* 15 Read Protection Enable */
164 u32 limit:13; /* 16:28 Protected Range Limit */
165 u32 reserved2:2; /* 29:30 Reserved */
166 u32 wpe:1; /* 31 Write Protection Enable */
167 } range;
168 u32 regval;
171 static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
172 static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
173 static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
174 static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw);
175 static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
176 static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
177 u32 offset, u8 byte);
178 static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
179 u8 *data);
180 static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
181 u16 *data);
182 static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
183 u8 size, u16 *data);
184 static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
185 static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
186 static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
188 static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
190 return readw(hw->flash_address + reg);
193 static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
195 return readl(hw->flash_address + reg);
198 static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
200 writew(val, hw->flash_address + reg);
203 static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
205 writel(val, hw->flash_address + reg);
208 #define er16flash(reg) __er16flash(hw, (reg))
209 #define er32flash(reg) __er32flash(hw, (reg))
210 #define ew16flash(reg,val) __ew16flash(hw, (reg), (val))
211 #define ew32flash(reg,val) __ew32flash(hw, (reg), (val))
214 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
215 * @hw: pointer to the HW structure
217 * Initialize family-specific PHY parameters and function pointers.
219 static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
221 struct e1000_phy_info *phy = &hw->phy;
222 s32 ret_val;
223 u16 i = 0;
225 phy->addr = 1;
226 phy->reset_delay_us = 100;
229 * We may need to do this twice - once for IGP and if that fails,
230 * we'll set BM func pointers and try again
232 ret_val = e1000e_determine_phy_address(hw);
233 if (ret_val) {
234 hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
235 hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
236 ret_val = e1000e_determine_phy_address(hw);
237 if (ret_val)
238 return ret_val;
241 phy->id = 0;
242 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
243 (i++ < 100)) {
244 msleep(1);
245 ret_val = e1000e_get_phy_id(hw);
246 if (ret_val)
247 return ret_val;
250 /* Verify phy id */
251 switch (phy->id) {
252 case IGP03E1000_E_PHY_ID:
253 phy->type = e1000_phy_igp_3;
254 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
255 break;
256 case IFE_E_PHY_ID:
257 case IFE_PLUS_E_PHY_ID:
258 case IFE_C_E_PHY_ID:
259 phy->type = e1000_phy_ife;
260 phy->autoneg_mask = E1000_ALL_NOT_GIG;
261 break;
262 case BME1000_E_PHY_ID:
263 phy->type = e1000_phy_bm;
264 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
265 hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
266 hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
267 hw->phy.ops.commit_phy = e1000e_phy_sw_reset;
268 break;
269 default:
270 return -E1000_ERR_PHY;
271 break;
274 return 0;
278 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
279 * @hw: pointer to the HW structure
281 * Initialize family-specific NVM parameters and function
282 * pointers.
284 static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
286 struct e1000_nvm_info *nvm = &hw->nvm;
287 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
288 u32 gfpreg;
289 u32 sector_base_addr;
290 u32 sector_end_addr;
291 u16 i;
293 /* Can't read flash registers if the register set isn't mapped. */
294 if (!hw->flash_address) {
295 hw_dbg(hw, "ERROR: Flash registers not mapped\n");
296 return -E1000_ERR_CONFIG;
299 nvm->type = e1000_nvm_flash_sw;
301 gfpreg = er32flash(ICH_FLASH_GFPREG);
304 * sector_X_addr is a "sector"-aligned address (4096 bytes)
305 * Add 1 to sector_end_addr since this sector is included in
306 * the overall size.
308 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
309 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
311 /* flash_base_addr is byte-aligned */
312 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
315 * find total size of the NVM, then cut in half since the total
316 * size represents two separate NVM banks.
318 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
319 << FLASH_SECTOR_ADDR_SHIFT;
320 nvm->flash_bank_size /= 2;
321 /* Adjust to word count */
322 nvm->flash_bank_size /= sizeof(u16);
324 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
326 /* Clear shadow ram */
327 for (i = 0; i < nvm->word_size; i++) {
328 dev_spec->shadow_ram[i].modified = 0;
329 dev_spec->shadow_ram[i].value = 0xFFFF;
332 return 0;
336 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
337 * @hw: pointer to the HW structure
339 * Initialize family-specific MAC parameters and function
340 * pointers.
342 static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
344 struct e1000_hw *hw = &adapter->hw;
345 struct e1000_mac_info *mac = &hw->mac;
347 /* Set media type function pointer */
348 hw->phy.media_type = e1000_media_type_copper;
350 /* Set mta register count */
351 mac->mta_reg_count = 32;
352 /* Set rar entry count */
353 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
354 if (mac->type == e1000_ich8lan)
355 mac->rar_entry_count--;
356 /* Set if manageability features are enabled. */
357 mac->arc_subsystem_valid = 1;
359 /* Enable PCS Lock-loss workaround for ICH8 */
360 if (mac->type == e1000_ich8lan)
361 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, 1);
363 return 0;
366 static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
368 struct e1000_hw *hw = &adapter->hw;
369 s32 rc;
371 rc = e1000_init_mac_params_ich8lan(adapter);
372 if (rc)
373 return rc;
375 rc = e1000_init_nvm_params_ich8lan(hw);
376 if (rc)
377 return rc;
379 rc = e1000_init_phy_params_ich8lan(hw);
380 if (rc)
381 return rc;
383 if ((adapter->hw.mac.type == e1000_ich8lan) &&
384 (adapter->hw.phy.type == e1000_phy_igp_3))
385 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
387 return 0;
390 static DEFINE_MUTEX(nvm_mutex);
391 static pid_t nvm_owner = -1;
394 * e1000_acquire_swflag_ich8lan - Acquire software control flag
395 * @hw: pointer to the HW structure
397 * Acquires the software control flag for performing NVM and PHY
398 * operations. This is a function pointer entry point only called by
399 * read/write routines for the PHY and NVM parts.
401 static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
403 u32 extcnf_ctrl;
404 u32 timeout = PHY_CFG_TIMEOUT;
406 might_sleep();
408 if (!mutex_trylock(&nvm_mutex)) {
409 WARN(1, KERN_ERR "e1000e mutex contention. Owned by pid %d\n",
410 nvm_owner);
411 mutex_lock(&nvm_mutex);
413 nvm_owner = current->pid;
415 while (timeout) {
416 extcnf_ctrl = er32(EXTCNF_CTRL);
417 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
418 ew32(EXTCNF_CTRL, extcnf_ctrl);
420 extcnf_ctrl = er32(EXTCNF_CTRL);
421 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
422 break;
423 mdelay(1);
424 timeout--;
427 if (!timeout) {
428 hw_dbg(hw, "FW or HW has locked the resource for too long.\n");
429 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
430 ew32(EXTCNF_CTRL, extcnf_ctrl);
431 nvm_owner = -1;
432 mutex_unlock(&nvm_mutex);
433 return -E1000_ERR_CONFIG;
436 return 0;
440 * e1000_release_swflag_ich8lan - Release software control flag
441 * @hw: pointer to the HW structure
443 * Releases the software control flag for performing NVM and PHY operations.
444 * This is a function pointer entry point only called by read/write
445 * routines for the PHY and NVM parts.
447 static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
449 u32 extcnf_ctrl;
451 extcnf_ctrl = er32(EXTCNF_CTRL);
452 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
453 ew32(EXTCNF_CTRL, extcnf_ctrl);
455 nvm_owner = -1;
456 mutex_unlock(&nvm_mutex);
460 * e1000_check_mng_mode_ich8lan - Checks management mode
461 * @hw: pointer to the HW structure
463 * This checks if the adapter has manageability enabled.
464 * This is a function pointer entry point only called by read/write
465 * routines for the PHY and NVM parts.
467 static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
469 u32 fwsm = er32(FWSM);
471 return (fwsm & E1000_FWSM_MODE_MASK) ==
472 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
476 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
477 * @hw: pointer to the HW structure
479 * Checks if firmware is blocking the reset of the PHY.
480 * This is a function pointer entry point only called by
481 * reset routines.
483 static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
485 u32 fwsm;
487 fwsm = er32(FWSM);
489 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
493 * e1000_phy_force_speed_duplex_ich8lan - Force PHY speed & duplex
494 * @hw: pointer to the HW structure
496 * Forces the speed and duplex settings of the PHY.
497 * This is a function pointer entry point only called by
498 * PHY setup routines.
500 static s32 e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw)
502 struct e1000_phy_info *phy = &hw->phy;
503 s32 ret_val;
504 u16 data;
505 bool link;
507 if (phy->type != e1000_phy_ife) {
508 ret_val = e1000e_phy_force_speed_duplex_igp(hw);
509 return ret_val;
512 ret_val = e1e_rphy(hw, PHY_CONTROL, &data);
513 if (ret_val)
514 return ret_val;
516 e1000e_phy_force_speed_duplex_setup(hw, &data);
518 ret_val = e1e_wphy(hw, PHY_CONTROL, data);
519 if (ret_val)
520 return ret_val;
522 /* Disable MDI-X support for 10/100 */
523 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
524 if (ret_val)
525 return ret_val;
527 data &= ~IFE_PMC_AUTO_MDIX;
528 data &= ~IFE_PMC_FORCE_MDIX;
530 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
531 if (ret_val)
532 return ret_val;
534 hw_dbg(hw, "IFE PMC: %X\n", data);
536 udelay(1);
538 if (phy->autoneg_wait_to_complete) {
539 hw_dbg(hw, "Waiting for forced speed/duplex link on IFE phy.\n");
541 ret_val = e1000e_phy_has_link_generic(hw,
542 PHY_FORCE_LIMIT,
543 100000,
544 &link);
545 if (ret_val)
546 return ret_val;
548 if (!link)
549 hw_dbg(hw, "Link taking longer than expected.\n");
551 /* Try once more */
552 ret_val = e1000e_phy_has_link_generic(hw,
553 PHY_FORCE_LIMIT,
554 100000,
555 &link);
556 if (ret_val)
557 return ret_val;
560 return 0;
564 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
565 * @hw: pointer to the HW structure
567 * Resets the PHY
568 * This is a function pointer entry point called by drivers
569 * or other shared routines.
571 static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
573 struct e1000_phy_info *phy = &hw->phy;
574 u32 i;
575 u32 data, cnf_size, cnf_base_addr, sw_cfg_mask;
576 s32 ret_val;
577 u16 loop = E1000_ICH8_LAN_INIT_TIMEOUT;
578 u16 word_addr, reg_data, reg_addr, phy_page = 0;
580 ret_val = e1000e_phy_hw_reset_generic(hw);
581 if (ret_val)
582 return ret_val;
585 * Initialize the PHY from the NVM on ICH platforms. This
586 * is needed due to an issue where the NVM configuration is
587 * not properly autoloaded after power transitions.
588 * Therefore, after each PHY reset, we will load the
589 * configuration data out of the NVM manually.
591 if (hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) {
592 struct e1000_adapter *adapter = hw->adapter;
594 /* Check if SW needs configure the PHY */
595 if ((adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
596 (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M))
597 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
598 else
599 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
601 data = er32(FEXTNVM);
602 if (!(data & sw_cfg_mask))
603 return 0;
605 /* Wait for basic configuration completes before proceeding*/
606 do {
607 data = er32(STATUS);
608 data &= E1000_STATUS_LAN_INIT_DONE;
609 udelay(100);
610 } while ((!data) && --loop);
613 * If basic configuration is incomplete before the above loop
614 * count reaches 0, loading the configuration from NVM will
615 * leave the PHY in a bad state possibly resulting in no link.
617 if (loop == 0) {
618 hw_dbg(hw, "LAN_INIT_DONE not set, increase timeout\n");
621 /* Clear the Init Done bit for the next init event */
622 data = er32(STATUS);
623 data &= ~E1000_STATUS_LAN_INIT_DONE;
624 ew32(STATUS, data);
627 * Make sure HW does not configure LCD from PHY
628 * extended configuration before SW configuration
630 data = er32(EXTCNF_CTRL);
631 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
632 return 0;
634 cnf_size = er32(EXTCNF_SIZE);
635 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
636 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
637 if (!cnf_size)
638 return 0;
640 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
641 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
643 /* Configure LCD from extended configuration region. */
645 /* cnf_base_addr is in DWORD */
646 word_addr = (u16)(cnf_base_addr << 1);
648 for (i = 0; i < cnf_size; i++) {
649 ret_val = e1000_read_nvm(hw,
650 (word_addr + i * 2),
652 &reg_data);
653 if (ret_val)
654 return ret_val;
656 ret_val = e1000_read_nvm(hw,
657 (word_addr + i * 2 + 1),
659 &reg_addr);
660 if (ret_val)
661 return ret_val;
663 /* Save off the PHY page for future writes. */
664 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
665 phy_page = reg_data;
666 continue;
669 reg_addr |= phy_page;
671 ret_val = e1e_wphy(hw, (u32)reg_addr, reg_data);
672 if (ret_val)
673 return ret_val;
677 return 0;
681 * e1000_get_phy_info_ife_ich8lan - Retrieves various IFE PHY states
682 * @hw: pointer to the HW structure
684 * Populates "phy" structure with various feature states.
685 * This function is only called by other family-specific
686 * routines.
688 static s32 e1000_get_phy_info_ife_ich8lan(struct e1000_hw *hw)
690 struct e1000_phy_info *phy = &hw->phy;
691 s32 ret_val;
692 u16 data;
693 bool link;
695 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
696 if (ret_val)
697 return ret_val;
699 if (!link) {
700 hw_dbg(hw, "Phy info is only valid if link is up\n");
701 return -E1000_ERR_CONFIG;
704 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
705 if (ret_val)
706 return ret_val;
707 phy->polarity_correction = (!(data & IFE_PSC_AUTO_POLARITY_DISABLE));
709 if (phy->polarity_correction) {
710 ret_val = e1000_check_polarity_ife_ich8lan(hw);
711 if (ret_val)
712 return ret_val;
713 } else {
714 /* Polarity is forced */
715 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
716 ? e1000_rev_polarity_reversed
717 : e1000_rev_polarity_normal;
720 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
721 if (ret_val)
722 return ret_val;
724 phy->is_mdix = (data & IFE_PMC_MDIX_STATUS);
726 /* The following parameters are undefined for 10/100 operation. */
727 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
728 phy->local_rx = e1000_1000t_rx_status_undefined;
729 phy->remote_rx = e1000_1000t_rx_status_undefined;
731 return 0;
735 * e1000_get_phy_info_ich8lan - Calls appropriate PHY type get_phy_info
736 * @hw: pointer to the HW structure
738 * Wrapper for calling the get_phy_info routines for the appropriate phy type.
739 * This is a function pointer entry point called by drivers
740 * or other shared routines.
742 static s32 e1000_get_phy_info_ich8lan(struct e1000_hw *hw)
744 switch (hw->phy.type) {
745 case e1000_phy_ife:
746 return e1000_get_phy_info_ife_ich8lan(hw);
747 break;
748 case e1000_phy_igp_3:
749 case e1000_phy_bm:
750 return e1000e_get_phy_info_igp(hw);
751 break;
752 default:
753 break;
756 return -E1000_ERR_PHY_TYPE;
760 * e1000_check_polarity_ife_ich8lan - Check cable polarity for IFE PHY
761 * @hw: pointer to the HW structure
763 * Polarity is determined on the polarity reversal feature being enabled.
764 * This function is only called by other family-specific
765 * routines.
767 static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw)
769 struct e1000_phy_info *phy = &hw->phy;
770 s32 ret_val;
771 u16 phy_data, offset, mask;
774 * Polarity is determined based on the reversal feature being enabled.
776 if (phy->polarity_correction) {
777 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
778 mask = IFE_PESC_POLARITY_REVERSED;
779 } else {
780 offset = IFE_PHY_SPECIAL_CONTROL;
781 mask = IFE_PSC_FORCE_POLARITY;
784 ret_val = e1e_rphy(hw, offset, &phy_data);
786 if (!ret_val)
787 phy->cable_polarity = (phy_data & mask)
788 ? e1000_rev_polarity_reversed
789 : e1000_rev_polarity_normal;
791 return ret_val;
795 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
796 * @hw: pointer to the HW structure
797 * @active: TRUE to enable LPLU, FALSE to disable
799 * Sets the LPLU D0 state according to the active flag. When
800 * activating LPLU this function also disables smart speed
801 * and vice versa. LPLU will not be activated unless the
802 * device autonegotiation advertisement meets standards of
803 * either 10 or 10/100 or 10/100/1000 at all duplexes.
804 * This is a function pointer entry point only called by
805 * PHY setup routines.
807 static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
809 struct e1000_phy_info *phy = &hw->phy;
810 u32 phy_ctrl;
811 s32 ret_val = 0;
812 u16 data;
814 if (phy->type == e1000_phy_ife)
815 return ret_val;
817 phy_ctrl = er32(PHY_CTRL);
819 if (active) {
820 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
821 ew32(PHY_CTRL, phy_ctrl);
824 * Call gig speed drop workaround on LPLU before accessing
825 * any PHY registers
827 if ((hw->mac.type == e1000_ich8lan) &&
828 (hw->phy.type == e1000_phy_igp_3))
829 e1000e_gig_downshift_workaround_ich8lan(hw);
831 /* When LPLU is enabled, we should disable SmartSpeed */
832 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
833 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
834 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
835 if (ret_val)
836 return ret_val;
837 } else {
838 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
839 ew32(PHY_CTRL, phy_ctrl);
842 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
843 * during Dx states where the power conservation is most
844 * important. During driver activity we should enable
845 * SmartSpeed, so performance is maintained.
847 if (phy->smart_speed == e1000_smart_speed_on) {
848 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
849 &data);
850 if (ret_val)
851 return ret_val;
853 data |= IGP01E1000_PSCFR_SMART_SPEED;
854 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
855 data);
856 if (ret_val)
857 return ret_val;
858 } else if (phy->smart_speed == e1000_smart_speed_off) {
859 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
860 &data);
861 if (ret_val)
862 return ret_val;
864 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
865 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
866 data);
867 if (ret_val)
868 return ret_val;
872 return 0;
876 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
877 * @hw: pointer to the HW structure
878 * @active: TRUE to enable LPLU, FALSE to disable
880 * Sets the LPLU D3 state according to the active flag. When
881 * activating LPLU this function also disables smart speed
882 * and vice versa. LPLU will not be activated unless the
883 * device autonegotiation advertisement meets standards of
884 * either 10 or 10/100 or 10/100/1000 at all duplexes.
885 * This is a function pointer entry point only called by
886 * PHY setup routines.
888 static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
890 struct e1000_phy_info *phy = &hw->phy;
891 u32 phy_ctrl;
892 s32 ret_val;
893 u16 data;
895 phy_ctrl = er32(PHY_CTRL);
897 if (!active) {
898 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
899 ew32(PHY_CTRL, phy_ctrl);
901 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
902 * during Dx states where the power conservation is most
903 * important. During driver activity we should enable
904 * SmartSpeed, so performance is maintained.
906 if (phy->smart_speed == e1000_smart_speed_on) {
907 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
908 &data);
909 if (ret_val)
910 return ret_val;
912 data |= IGP01E1000_PSCFR_SMART_SPEED;
913 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
914 data);
915 if (ret_val)
916 return ret_val;
917 } else if (phy->smart_speed == e1000_smart_speed_off) {
918 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
919 &data);
920 if (ret_val)
921 return ret_val;
923 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
924 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
925 data);
926 if (ret_val)
927 return ret_val;
929 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
930 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
931 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
932 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
933 ew32(PHY_CTRL, phy_ctrl);
936 * Call gig speed drop workaround on LPLU before accessing
937 * any PHY registers
939 if ((hw->mac.type == e1000_ich8lan) &&
940 (hw->phy.type == e1000_phy_igp_3))
941 e1000e_gig_downshift_workaround_ich8lan(hw);
943 /* When LPLU is enabled, we should disable SmartSpeed */
944 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
945 if (ret_val)
946 return ret_val;
948 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
949 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
952 return 0;
956 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
957 * @hw: pointer to the HW structure
958 * @bank: pointer to the variable that returns the active bank
960 * Reads signature byte from the NVM using the flash access registers.
962 static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
964 struct e1000_nvm_info *nvm = &hw->nvm;
965 /* flash bank size is in words */
966 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
967 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
968 u8 bank_high_byte = 0;
970 if (hw->mac.type != e1000_ich10lan) {
971 if (er32(EECD) & E1000_EECD_SEC1VAL)
972 *bank = 1;
973 else
974 *bank = 0;
975 } else {
977 * Make sure the signature for bank 0 is valid,
978 * if not check for bank1
980 e1000_read_flash_byte_ich8lan(hw, act_offset, &bank_high_byte);
981 if ((bank_high_byte & 0xC0) == 0x80) {
982 *bank = 0;
983 } else {
985 * find if segment 1 is valid by verifying
986 * bit 15:14 = 10b in word 0x13
988 e1000_read_flash_byte_ich8lan(hw,
989 act_offset + bank1_offset,
990 &bank_high_byte);
992 /* bank1 has a valid signature equivalent to SEC1V */
993 if ((bank_high_byte & 0xC0) == 0x80) {
994 *bank = 1;
995 } else {
996 hw_dbg(hw, "ERROR: EEPROM not present\n");
997 return -E1000_ERR_NVM;
1002 return 0;
1006 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
1007 * @hw: pointer to the HW structure
1008 * @offset: The offset (in bytes) of the word(s) to read.
1009 * @words: Size of data to read in words
1010 * @data: Pointer to the word(s) to read at offset.
1012 * Reads a word(s) from the NVM using the flash access registers.
1014 static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1015 u16 *data)
1017 struct e1000_nvm_info *nvm = &hw->nvm;
1018 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1019 u32 act_offset;
1020 s32 ret_val;
1021 u32 bank = 0;
1022 u16 i, word;
1024 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1025 (words == 0)) {
1026 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
1027 return -E1000_ERR_NVM;
1030 ret_val = e1000_acquire_swflag_ich8lan(hw);
1031 if (ret_val)
1032 return ret_val;
1034 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
1035 if (ret_val)
1036 return ret_val;
1038 act_offset = (bank) ? nvm->flash_bank_size : 0;
1039 act_offset += offset;
1041 for (i = 0; i < words; i++) {
1042 if ((dev_spec->shadow_ram) &&
1043 (dev_spec->shadow_ram[offset+i].modified)) {
1044 data[i] = dev_spec->shadow_ram[offset+i].value;
1045 } else {
1046 ret_val = e1000_read_flash_word_ich8lan(hw,
1047 act_offset + i,
1048 &word);
1049 if (ret_val)
1050 break;
1051 data[i] = word;
1055 e1000_release_swflag_ich8lan(hw);
1057 return ret_val;
1061 * e1000_flash_cycle_init_ich8lan - Initialize flash
1062 * @hw: pointer to the HW structure
1064 * This function does initial flash setup so that a new read/write/erase cycle
1065 * can be started.
1067 static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
1069 union ich8_hws_flash_status hsfsts;
1070 s32 ret_val = -E1000_ERR_NVM;
1071 s32 i = 0;
1073 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1075 /* Check if the flash descriptor is valid */
1076 if (hsfsts.hsf_status.fldesvalid == 0) {
1077 hw_dbg(hw, "Flash descriptor invalid. "
1078 "SW Sequencing must be used.");
1079 return -E1000_ERR_NVM;
1082 /* Clear FCERR and DAEL in hw status by writing 1 */
1083 hsfsts.hsf_status.flcerr = 1;
1084 hsfsts.hsf_status.dael = 1;
1086 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1089 * Either we should have a hardware SPI cycle in progress
1090 * bit to check against, in order to start a new cycle or
1091 * FDONE bit should be changed in the hardware so that it
1092 * is 1 after hardware reset, which can then be used as an
1093 * indication whether a cycle is in progress or has been
1094 * completed.
1097 if (hsfsts.hsf_status.flcinprog == 0) {
1099 * There is no cycle running at present,
1100 * so we can start a cycle
1101 * Begin by setting Flash Cycle Done.
1103 hsfsts.hsf_status.flcdone = 1;
1104 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1105 ret_val = 0;
1106 } else {
1108 * otherwise poll for sometime so the current
1109 * cycle has a chance to end before giving up.
1111 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
1112 hsfsts.regval = __er16flash(hw, ICH_FLASH_HSFSTS);
1113 if (hsfsts.hsf_status.flcinprog == 0) {
1114 ret_val = 0;
1115 break;
1117 udelay(1);
1119 if (ret_val == 0) {
1121 * Successful in waiting for previous cycle to timeout,
1122 * now set the Flash Cycle Done.
1124 hsfsts.hsf_status.flcdone = 1;
1125 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1126 } else {
1127 hw_dbg(hw, "Flash controller busy, cannot get access");
1131 return ret_val;
1135 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
1136 * @hw: pointer to the HW structure
1137 * @timeout: maximum time to wait for completion
1139 * This function starts a flash cycle and waits for its completion.
1141 static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
1143 union ich8_hws_flash_ctrl hsflctl;
1144 union ich8_hws_flash_status hsfsts;
1145 s32 ret_val = -E1000_ERR_NVM;
1146 u32 i = 0;
1148 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
1149 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1150 hsflctl.hsf_ctrl.flcgo = 1;
1151 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1153 /* wait till FDONE bit is set to 1 */
1154 do {
1155 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1156 if (hsfsts.hsf_status.flcdone == 1)
1157 break;
1158 udelay(1);
1159 } while (i++ < timeout);
1161 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
1162 return 0;
1164 return ret_val;
1168 * e1000_read_flash_word_ich8lan - Read word from flash
1169 * @hw: pointer to the HW structure
1170 * @offset: offset to data location
1171 * @data: pointer to the location for storing the data
1173 * Reads the flash word at offset into data. Offset is converted
1174 * to bytes before read.
1176 static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
1177 u16 *data)
1179 /* Must convert offset into bytes. */
1180 offset <<= 1;
1182 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
1186 * e1000_read_flash_byte_ich8lan - Read byte from flash
1187 * @hw: pointer to the HW structure
1188 * @offset: The offset of the byte to read.
1189 * @data: Pointer to a byte to store the value read.
1191 * Reads a single byte from the NVM using the flash access registers.
1193 static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1194 u8 *data)
1196 s32 ret_val;
1197 u16 word = 0;
1199 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
1200 if (ret_val)
1201 return ret_val;
1203 *data = (u8)word;
1205 return 0;
1209 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
1210 * @hw: pointer to the HW structure
1211 * @offset: The offset (in bytes) of the byte or word to read.
1212 * @size: Size of data to read, 1=byte 2=word
1213 * @data: Pointer to the word to store the value read.
1215 * Reads a byte or word from the NVM using the flash access registers.
1217 static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1218 u8 size, u16 *data)
1220 union ich8_hws_flash_status hsfsts;
1221 union ich8_hws_flash_ctrl hsflctl;
1222 u32 flash_linear_addr;
1223 u32 flash_data = 0;
1224 s32 ret_val = -E1000_ERR_NVM;
1225 u8 count = 0;
1227 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
1228 return -E1000_ERR_NVM;
1230 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1231 hw->nvm.flash_base_addr;
1233 do {
1234 udelay(1);
1235 /* Steps */
1236 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1237 if (ret_val != 0)
1238 break;
1240 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1241 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1242 hsflctl.hsf_ctrl.fldbcount = size - 1;
1243 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
1244 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1246 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1248 ret_val = e1000_flash_cycle_ich8lan(hw,
1249 ICH_FLASH_READ_COMMAND_TIMEOUT);
1252 * Check if FCERR is set to 1, if set to 1, clear it
1253 * and try the whole sequence a few more times, else
1254 * read in (shift in) the Flash Data0, the order is
1255 * least significant byte first msb to lsb
1257 if (ret_val == 0) {
1258 flash_data = er32flash(ICH_FLASH_FDATA0);
1259 if (size == 1) {
1260 *data = (u8)(flash_data & 0x000000FF);
1261 } else if (size == 2) {
1262 *data = (u16)(flash_data & 0x0000FFFF);
1264 break;
1265 } else {
1267 * If we've gotten here, then things are probably
1268 * completely hosed, but if the error condition is
1269 * detected, it won't hurt to give it another try...
1270 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
1272 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1273 if (hsfsts.hsf_status.flcerr == 1) {
1274 /* Repeat for some time before giving up. */
1275 continue;
1276 } else if (hsfsts.hsf_status.flcdone == 0) {
1277 hw_dbg(hw, "Timeout error - flash cycle "
1278 "did not complete.");
1279 break;
1282 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1284 return ret_val;
1288 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
1289 * @hw: pointer to the HW structure
1290 * @offset: The offset (in bytes) of the word(s) to write.
1291 * @words: Size of data to write in words
1292 * @data: Pointer to the word(s) to write at offset.
1294 * Writes a byte or word to the NVM using the flash access registers.
1296 static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1297 u16 *data)
1299 struct e1000_nvm_info *nvm = &hw->nvm;
1300 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1301 s32 ret_val;
1302 u16 i;
1304 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1305 (words == 0)) {
1306 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
1307 return -E1000_ERR_NVM;
1310 ret_val = e1000_acquire_swflag_ich8lan(hw);
1311 if (ret_val)
1312 return ret_val;
1314 for (i = 0; i < words; i++) {
1315 dev_spec->shadow_ram[offset+i].modified = 1;
1316 dev_spec->shadow_ram[offset+i].value = data[i];
1319 e1000_release_swflag_ich8lan(hw);
1321 return 0;
1325 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
1326 * @hw: pointer to the HW structure
1328 * The NVM checksum is updated by calling the generic update_nvm_checksum,
1329 * which writes the checksum to the shadow ram. The changes in the shadow
1330 * ram are then committed to the EEPROM by processing each bank at a time
1331 * checking for the modified bit and writing only the pending changes.
1332 * After a successful commit, the shadow ram is cleared and is ready for
1333 * future writes.
1335 static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1337 struct e1000_nvm_info *nvm = &hw->nvm;
1338 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1339 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
1340 s32 ret_val;
1341 u16 data;
1343 ret_val = e1000e_update_nvm_checksum_generic(hw);
1344 if (ret_val)
1345 return ret_val;
1347 if (nvm->type != e1000_nvm_flash_sw)
1348 return ret_val;
1350 ret_val = e1000_acquire_swflag_ich8lan(hw);
1351 if (ret_val)
1352 return ret_val;
1355 * We're writing to the opposite bank so if we're on bank 1,
1356 * write to bank 0 etc. We also need to erase the segment that
1357 * is going to be written
1359 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
1360 if (ret_val)
1361 return ret_val;
1363 if (bank == 0) {
1364 new_bank_offset = nvm->flash_bank_size;
1365 old_bank_offset = 0;
1366 e1000_erase_flash_bank_ich8lan(hw, 1);
1367 } else {
1368 old_bank_offset = nvm->flash_bank_size;
1369 new_bank_offset = 0;
1370 e1000_erase_flash_bank_ich8lan(hw, 0);
1373 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
1375 * Determine whether to write the value stored
1376 * in the other NVM bank or a modified value stored
1377 * in the shadow RAM
1379 if (dev_spec->shadow_ram[i].modified) {
1380 data = dev_spec->shadow_ram[i].value;
1381 } else {
1382 e1000_read_flash_word_ich8lan(hw,
1383 i + old_bank_offset,
1384 &data);
1388 * If the word is 0x13, then make sure the signature bits
1389 * (15:14) are 11b until the commit has completed.
1390 * This will allow us to write 10b which indicates the
1391 * signature is valid. We want to do this after the write
1392 * has completed so that we don't mark the segment valid
1393 * while the write is still in progress
1395 if (i == E1000_ICH_NVM_SIG_WORD)
1396 data |= E1000_ICH_NVM_SIG_MASK;
1398 /* Convert offset to bytes. */
1399 act_offset = (i + new_bank_offset) << 1;
1401 udelay(100);
1402 /* Write the bytes to the new bank. */
1403 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1404 act_offset,
1405 (u8)data);
1406 if (ret_val)
1407 break;
1409 udelay(100);
1410 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1411 act_offset + 1,
1412 (u8)(data >> 8));
1413 if (ret_val)
1414 break;
1418 * Don't bother writing the segment valid bits if sector
1419 * programming failed.
1421 if (ret_val) {
1422 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
1423 hw_dbg(hw, "Flash commit failed.\n");
1424 e1000_release_swflag_ich8lan(hw);
1425 return ret_val;
1429 * Finally validate the new segment by setting bit 15:14
1430 * to 10b in word 0x13 , this can be done without an
1431 * erase as well since these bits are 11 to start with
1432 * and we need to change bit 14 to 0b
1434 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
1435 e1000_read_flash_word_ich8lan(hw, act_offset, &data);
1436 data &= 0xBFFF;
1437 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1438 act_offset * 2 + 1,
1439 (u8)(data >> 8));
1440 if (ret_val) {
1441 e1000_release_swflag_ich8lan(hw);
1442 return ret_val;
1446 * And invalidate the previously valid segment by setting
1447 * its signature word (0x13) high_byte to 0b. This can be
1448 * done without an erase because flash erase sets all bits
1449 * to 1's. We can write 1's to 0's without an erase
1451 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
1452 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
1453 if (ret_val) {
1454 e1000_release_swflag_ich8lan(hw);
1455 return ret_val;
1458 /* Great! Everything worked, we can now clear the cached entries. */
1459 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
1460 dev_spec->shadow_ram[i].modified = 0;
1461 dev_spec->shadow_ram[i].value = 0xFFFF;
1464 e1000_release_swflag_ich8lan(hw);
1467 * Reload the EEPROM, or else modifications will not appear
1468 * until after the next adapter reset.
1470 e1000e_reload_nvm(hw);
1471 msleep(10);
1473 return ret_val;
1477 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
1478 * @hw: pointer to the HW structure
1480 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
1481 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
1482 * calculated, in which case we need to calculate the checksum and set bit 6.
1484 static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
1486 s32 ret_val;
1487 u16 data;
1490 * Read 0x19 and check bit 6. If this bit is 0, the checksum
1491 * needs to be fixed. This bit is an indication that the NVM
1492 * was prepared by OEM software and did not calculate the
1493 * checksum...a likely scenario.
1495 ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
1496 if (ret_val)
1497 return ret_val;
1499 if ((data & 0x40) == 0) {
1500 data |= 0x40;
1501 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
1502 if (ret_val)
1503 return ret_val;
1504 ret_val = e1000e_update_nvm_checksum(hw);
1505 if (ret_val)
1506 return ret_val;
1509 return e1000e_validate_nvm_checksum_generic(hw);
1513 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
1514 * @hw: pointer to the HW structure
1516 * To prevent malicious write/erase of the NVM, set it to be read-only
1517 * so that the hardware ignores all write/erase cycles of the NVM via
1518 * the flash control registers. The shadow-ram copy of the NVM will
1519 * still be updated, however any updates to this copy will not stick
1520 * across driver reloads.
1522 void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
1524 union ich8_flash_protected_range pr0;
1525 union ich8_hws_flash_status hsfsts;
1526 u32 gfpreg;
1527 s32 ret_val;
1529 ret_val = e1000_acquire_swflag_ich8lan(hw);
1530 if (ret_val)
1531 return;
1533 gfpreg = er32flash(ICH_FLASH_GFPREG);
1535 /* Write-protect GbE Sector of NVM */
1536 pr0.regval = er32flash(ICH_FLASH_PR0);
1537 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
1538 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
1539 pr0.range.wpe = true;
1540 ew32flash(ICH_FLASH_PR0, pr0.regval);
1543 * Lock down a subset of GbE Flash Control Registers, e.g.
1544 * PR0 to prevent the write-protection from being lifted.
1545 * Once FLOCKDN is set, the registers protected by it cannot
1546 * be written until FLOCKDN is cleared by a hardware reset.
1548 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1549 hsfsts.hsf_status.flockdn = true;
1550 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1552 e1000_release_swflag_ich8lan(hw);
1556 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
1557 * @hw: pointer to the HW structure
1558 * @offset: The offset (in bytes) of the byte/word to read.
1559 * @size: Size of data to read, 1=byte 2=word
1560 * @data: The byte(s) to write to the NVM.
1562 * Writes one/two bytes to the NVM using the flash access registers.
1564 static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1565 u8 size, u16 data)
1567 union ich8_hws_flash_status hsfsts;
1568 union ich8_hws_flash_ctrl hsflctl;
1569 u32 flash_linear_addr;
1570 u32 flash_data = 0;
1571 s32 ret_val;
1572 u8 count = 0;
1574 if (size < 1 || size > 2 || data > size * 0xff ||
1575 offset > ICH_FLASH_LINEAR_ADDR_MASK)
1576 return -E1000_ERR_NVM;
1578 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1579 hw->nvm.flash_base_addr;
1581 do {
1582 udelay(1);
1583 /* Steps */
1584 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1585 if (ret_val)
1586 break;
1588 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1589 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1590 hsflctl.hsf_ctrl.fldbcount = size -1;
1591 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
1592 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1594 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1596 if (size == 1)
1597 flash_data = (u32)data & 0x00FF;
1598 else
1599 flash_data = (u32)data;
1601 ew32flash(ICH_FLASH_FDATA0, flash_data);
1604 * check if FCERR is set to 1 , if set to 1, clear it
1605 * and try the whole sequence a few more times else done
1607 ret_val = e1000_flash_cycle_ich8lan(hw,
1608 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
1609 if (!ret_val)
1610 break;
1613 * If we're here, then things are most likely
1614 * completely hosed, but if the error condition
1615 * is detected, it won't hurt to give it another
1616 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
1618 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1619 if (hsfsts.hsf_status.flcerr == 1)
1620 /* Repeat for some time before giving up. */
1621 continue;
1622 if (hsfsts.hsf_status.flcdone == 0) {
1623 hw_dbg(hw, "Timeout error - flash cycle "
1624 "did not complete.");
1625 break;
1627 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1629 return ret_val;
1633 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
1634 * @hw: pointer to the HW structure
1635 * @offset: The index of the byte to read.
1636 * @data: The byte to write to the NVM.
1638 * Writes a single byte to the NVM using the flash access registers.
1640 static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1641 u8 data)
1643 u16 word = (u16)data;
1645 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
1649 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
1650 * @hw: pointer to the HW structure
1651 * @offset: The offset of the byte to write.
1652 * @byte: The byte to write to the NVM.
1654 * Writes a single byte to the NVM using the flash access registers.
1655 * Goes through a retry algorithm before giving up.
1657 static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
1658 u32 offset, u8 byte)
1660 s32 ret_val;
1661 u16 program_retries;
1663 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
1664 if (!ret_val)
1665 return ret_val;
1667 for (program_retries = 0; program_retries < 100; program_retries++) {
1668 hw_dbg(hw, "Retrying Byte %2.2X at offset %u\n", byte, offset);
1669 udelay(100);
1670 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
1671 if (!ret_val)
1672 break;
1674 if (program_retries == 100)
1675 return -E1000_ERR_NVM;
1677 return 0;
1681 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
1682 * @hw: pointer to the HW structure
1683 * @bank: 0 for first bank, 1 for second bank, etc.
1685 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
1686 * bank N is 4096 * N + flash_reg_addr.
1688 static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
1690 struct e1000_nvm_info *nvm = &hw->nvm;
1691 union ich8_hws_flash_status hsfsts;
1692 union ich8_hws_flash_ctrl hsflctl;
1693 u32 flash_linear_addr;
1694 /* bank size is in 16bit words - adjust to bytes */
1695 u32 flash_bank_size = nvm->flash_bank_size * 2;
1696 s32 ret_val;
1697 s32 count = 0;
1698 s32 iteration;
1699 s32 sector_size;
1700 s32 j;
1702 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1705 * Determine HW Sector size: Read BERASE bits of hw flash status
1706 * register
1707 * 00: The Hw sector is 256 bytes, hence we need to erase 16
1708 * consecutive sectors. The start index for the nth Hw sector
1709 * can be calculated as = bank * 4096 + n * 256
1710 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
1711 * The start index for the nth Hw sector can be calculated
1712 * as = bank * 4096
1713 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
1714 * (ich9 only, otherwise error condition)
1715 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
1717 switch (hsfsts.hsf_status.berasesz) {
1718 case 0:
1719 /* Hw sector size 256 */
1720 sector_size = ICH_FLASH_SEG_SIZE_256;
1721 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
1722 break;
1723 case 1:
1724 sector_size = ICH_FLASH_SEG_SIZE_4K;
1725 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_4K;
1726 break;
1727 case 2:
1728 if (hw->mac.type == e1000_ich9lan) {
1729 sector_size = ICH_FLASH_SEG_SIZE_8K;
1730 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_8K;
1731 } else {
1732 return -E1000_ERR_NVM;
1734 break;
1735 case 3:
1736 sector_size = ICH_FLASH_SEG_SIZE_64K;
1737 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_64K;
1738 break;
1739 default:
1740 return -E1000_ERR_NVM;
1743 /* Start with the base address, then add the sector offset. */
1744 flash_linear_addr = hw->nvm.flash_base_addr;
1745 flash_linear_addr += (bank) ? (sector_size * iteration) : 0;
1747 for (j = 0; j < iteration ; j++) {
1748 do {
1749 /* Steps */
1750 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1751 if (ret_val)
1752 return ret_val;
1755 * Write a value 11 (block Erase) in Flash
1756 * Cycle field in hw flash control
1758 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1759 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
1760 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1763 * Write the last 24 bits of an index within the
1764 * block into Flash Linear address field in Flash
1765 * Address.
1767 flash_linear_addr += (j * sector_size);
1768 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1770 ret_val = e1000_flash_cycle_ich8lan(hw,
1771 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
1772 if (ret_val == 0)
1773 break;
1776 * Check if FCERR is set to 1. If 1,
1777 * clear it and try the whole sequence
1778 * a few more times else Done
1780 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1781 if (hsfsts.hsf_status.flcerr == 1)
1782 /* repeat for some time before giving up */
1783 continue;
1784 else if (hsfsts.hsf_status.flcdone == 0)
1785 return ret_val;
1786 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
1789 return 0;
1793 * e1000_valid_led_default_ich8lan - Set the default LED settings
1794 * @hw: pointer to the HW structure
1795 * @data: Pointer to the LED settings
1797 * Reads the LED default settings from the NVM to data. If the NVM LED
1798 * settings is all 0's or F's, set the LED default to a valid LED default
1799 * setting.
1801 static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
1803 s32 ret_val;
1805 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
1806 if (ret_val) {
1807 hw_dbg(hw, "NVM Read Error\n");
1808 return ret_val;
1811 if (*data == ID_LED_RESERVED_0000 ||
1812 *data == ID_LED_RESERVED_FFFF)
1813 *data = ID_LED_DEFAULT_ICH8LAN;
1815 return 0;
1819 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
1820 * @hw: pointer to the HW structure
1822 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
1823 * register, so the the bus width is hard coded.
1825 static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
1827 struct e1000_bus_info *bus = &hw->bus;
1828 s32 ret_val;
1830 ret_val = e1000e_get_bus_info_pcie(hw);
1833 * ICH devices are "PCI Express"-ish. They have
1834 * a configuration space, but do not contain
1835 * PCI Express Capability registers, so bus width
1836 * must be hardcoded.
1838 if (bus->width == e1000_bus_width_unknown)
1839 bus->width = e1000_bus_width_pcie_x1;
1841 return ret_val;
1845 * e1000_reset_hw_ich8lan - Reset the hardware
1846 * @hw: pointer to the HW structure
1848 * Does a full reset of the hardware which includes a reset of the PHY and
1849 * MAC.
1851 static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
1853 u32 ctrl, icr, kab;
1854 s32 ret_val;
1857 * Prevent the PCI-E bus from sticking if there is no TLP connection
1858 * on the last TLP read/write transaction when MAC is reset.
1860 ret_val = e1000e_disable_pcie_master(hw);
1861 if (ret_val) {
1862 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
1865 hw_dbg(hw, "Masking off all interrupts\n");
1866 ew32(IMC, 0xffffffff);
1869 * Disable the Transmit and Receive units. Then delay to allow
1870 * any pending transactions to complete before we hit the MAC
1871 * with the global reset.
1873 ew32(RCTL, 0);
1874 ew32(TCTL, E1000_TCTL_PSP);
1875 e1e_flush();
1877 msleep(10);
1879 /* Workaround for ICH8 bit corruption issue in FIFO memory */
1880 if (hw->mac.type == e1000_ich8lan) {
1881 /* Set Tx and Rx buffer allocation to 8k apiece. */
1882 ew32(PBA, E1000_PBA_8K);
1883 /* Set Packet Buffer Size to 16k. */
1884 ew32(PBS, E1000_PBS_16K);
1887 ctrl = er32(CTRL);
1889 if (!e1000_check_reset_block(hw)) {
1891 * PHY HW reset requires MAC CORE reset at the same
1892 * time to make sure the interface between MAC and the
1893 * external PHY is reset.
1895 ctrl |= E1000_CTRL_PHY_RST;
1897 ret_val = e1000_acquire_swflag_ich8lan(hw);
1898 hw_dbg(hw, "Issuing a global reset to ich8lan\n");
1899 ew32(CTRL, (ctrl | E1000_CTRL_RST));
1900 msleep(20);
1902 /* release the swflag because it is not reset by hardware reset */
1903 e1000_release_swflag_ich8lan(hw);
1905 ret_val = e1000e_get_auto_rd_done(hw);
1906 if (ret_val) {
1908 * When auto config read does not complete, do not
1909 * return with an error. This can happen in situations
1910 * where there is no eeprom and prevents getting link.
1912 hw_dbg(hw, "Auto Read Done did not complete\n");
1915 ew32(IMC, 0xffffffff);
1916 icr = er32(ICR);
1918 kab = er32(KABGTXD);
1919 kab |= E1000_KABGTXD_BGSQLBIAS;
1920 ew32(KABGTXD, kab);
1922 return ret_val;
1926 * e1000_init_hw_ich8lan - Initialize the hardware
1927 * @hw: pointer to the HW structure
1929 * Prepares the hardware for transmit and receive by doing the following:
1930 * - initialize hardware bits
1931 * - initialize LED identification
1932 * - setup receive address registers
1933 * - setup flow control
1934 * - setup transmit descriptors
1935 * - clear statistics
1937 static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
1939 struct e1000_mac_info *mac = &hw->mac;
1940 u32 ctrl_ext, txdctl, snoop;
1941 s32 ret_val;
1942 u16 i;
1944 e1000_initialize_hw_bits_ich8lan(hw);
1946 /* Initialize identification LED */
1947 ret_val = e1000e_id_led_init(hw);
1948 if (ret_val) {
1949 hw_dbg(hw, "Error initializing identification LED\n");
1950 return ret_val;
1953 /* Setup the receive address. */
1954 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
1956 /* Zero out the Multicast HASH table */
1957 hw_dbg(hw, "Zeroing the MTA\n");
1958 for (i = 0; i < mac->mta_reg_count; i++)
1959 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
1961 /* Setup link and flow control */
1962 ret_val = e1000_setup_link_ich8lan(hw);
1964 /* Set the transmit descriptor write-back policy for both queues */
1965 txdctl = er32(TXDCTL(0));
1966 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
1967 E1000_TXDCTL_FULL_TX_DESC_WB;
1968 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
1969 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
1970 ew32(TXDCTL(0), txdctl);
1971 txdctl = er32(TXDCTL(1));
1972 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
1973 E1000_TXDCTL_FULL_TX_DESC_WB;
1974 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
1975 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
1976 ew32(TXDCTL(1), txdctl);
1979 * ICH8 has opposite polarity of no_snoop bits.
1980 * By default, we should use snoop behavior.
1982 if (mac->type == e1000_ich8lan)
1983 snoop = PCIE_ICH8_SNOOP_ALL;
1984 else
1985 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
1986 e1000e_set_pcie_no_snoop(hw, snoop);
1988 ctrl_ext = er32(CTRL_EXT);
1989 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1990 ew32(CTRL_EXT, ctrl_ext);
1993 * Clear all of the statistics registers (clear on read). It is
1994 * important that we do this after we have tried to establish link
1995 * because the symbol error count will increment wildly if there
1996 * is no link.
1998 e1000_clear_hw_cntrs_ich8lan(hw);
2000 return 0;
2003 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
2004 * @hw: pointer to the HW structure
2006 * Sets/Clears required hardware bits necessary for correctly setting up the
2007 * hardware for transmit and receive.
2009 static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
2011 u32 reg;
2013 /* Extended Device Control */
2014 reg = er32(CTRL_EXT);
2015 reg |= (1 << 22);
2016 ew32(CTRL_EXT, reg);
2018 /* Transmit Descriptor Control 0 */
2019 reg = er32(TXDCTL(0));
2020 reg |= (1 << 22);
2021 ew32(TXDCTL(0), reg);
2023 /* Transmit Descriptor Control 1 */
2024 reg = er32(TXDCTL(1));
2025 reg |= (1 << 22);
2026 ew32(TXDCTL(1), reg);
2028 /* Transmit Arbitration Control 0 */
2029 reg = er32(TARC(0));
2030 if (hw->mac.type == e1000_ich8lan)
2031 reg |= (1 << 28) | (1 << 29);
2032 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
2033 ew32(TARC(0), reg);
2035 /* Transmit Arbitration Control 1 */
2036 reg = er32(TARC(1));
2037 if (er32(TCTL) & E1000_TCTL_MULR)
2038 reg &= ~(1 << 28);
2039 else
2040 reg |= (1 << 28);
2041 reg |= (1 << 24) | (1 << 26) | (1 << 30);
2042 ew32(TARC(1), reg);
2044 /* Device Status */
2045 if (hw->mac.type == e1000_ich8lan) {
2046 reg = er32(STATUS);
2047 reg &= ~(1 << 31);
2048 ew32(STATUS, reg);
2053 * e1000_setup_link_ich8lan - Setup flow control and link settings
2054 * @hw: pointer to the HW structure
2056 * Determines which flow control settings to use, then configures flow
2057 * control. Calls the appropriate media-specific link configuration
2058 * function. Assuming the adapter has a valid link partner, a valid link
2059 * should be established. Assumes the hardware has previously been reset
2060 * and the transmitter and receiver are not enabled.
2062 static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
2064 s32 ret_val;
2066 if (e1000_check_reset_block(hw))
2067 return 0;
2070 * ICH parts do not have a word in the NVM to determine
2071 * the default flow control setting, so we explicitly
2072 * set it to full.
2074 if (hw->fc.requested_mode == e1000_fc_default)
2075 hw->fc.requested_mode = e1000_fc_full;
2078 * Save off the requested flow control mode for use later. Depending
2079 * on the link partner's capabilities, we may or may not use this mode.
2081 hw->fc.current_mode = hw->fc.requested_mode;
2083 hw_dbg(hw, "After fix-ups FlowControl is now = %x\n",
2084 hw->fc.current_mode);
2086 /* Continue to configure the copper link. */
2087 ret_val = e1000_setup_copper_link_ich8lan(hw);
2088 if (ret_val)
2089 return ret_val;
2091 ew32(FCTTV, hw->fc.pause_time);
2093 return e1000e_set_fc_watermarks(hw);
2097 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
2098 * @hw: pointer to the HW structure
2100 * Configures the kumeran interface to the PHY to wait the appropriate time
2101 * when polling the PHY, then call the generic setup_copper_link to finish
2102 * configuring the copper link.
2104 static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
2106 u32 ctrl;
2107 s32 ret_val;
2108 u16 reg_data;
2110 ctrl = er32(CTRL);
2111 ctrl |= E1000_CTRL_SLU;
2112 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2113 ew32(CTRL, ctrl);
2116 * Set the mac to wait the maximum time between each iteration
2117 * and increase the max iterations when polling the phy;
2118 * this fixes erroneous timeouts at 10Mbps.
2120 ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
2121 if (ret_val)
2122 return ret_val;
2123 ret_val = e1000e_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
2124 if (ret_val)
2125 return ret_val;
2126 reg_data |= 0x3F;
2127 ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
2128 if (ret_val)
2129 return ret_val;
2131 if (hw->phy.type == e1000_phy_igp_3) {
2132 ret_val = e1000e_copper_link_setup_igp(hw);
2133 if (ret_val)
2134 return ret_val;
2135 } else if (hw->phy.type == e1000_phy_bm) {
2136 ret_val = e1000e_copper_link_setup_m88(hw);
2137 if (ret_val)
2138 return ret_val;
2141 if (hw->phy.type == e1000_phy_ife) {
2142 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
2143 if (ret_val)
2144 return ret_val;
2146 reg_data &= ~IFE_PMC_AUTO_MDIX;
2148 switch (hw->phy.mdix) {
2149 case 1:
2150 reg_data &= ~IFE_PMC_FORCE_MDIX;
2151 break;
2152 case 2:
2153 reg_data |= IFE_PMC_FORCE_MDIX;
2154 break;
2155 case 0:
2156 default:
2157 reg_data |= IFE_PMC_AUTO_MDIX;
2158 break;
2160 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
2161 if (ret_val)
2162 return ret_val;
2164 return e1000e_setup_copper_link(hw);
2168 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
2169 * @hw: pointer to the HW structure
2170 * @speed: pointer to store current link speed
2171 * @duplex: pointer to store the current link duplex
2173 * Calls the generic get_speed_and_duplex to retrieve the current link
2174 * information and then calls the Kumeran lock loss workaround for links at
2175 * gigabit speeds.
2177 static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
2178 u16 *duplex)
2180 s32 ret_val;
2182 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
2183 if (ret_val)
2184 return ret_val;
2186 if ((hw->mac.type == e1000_ich8lan) &&
2187 (hw->phy.type == e1000_phy_igp_3) &&
2188 (*speed == SPEED_1000)) {
2189 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
2192 return ret_val;
2196 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
2197 * @hw: pointer to the HW structure
2199 * Work-around for 82566 Kumeran PCS lock loss:
2200 * On link status change (i.e. PCI reset, speed change) and link is up and
2201 * speed is gigabit-
2202 * 0) if workaround is optionally disabled do nothing
2203 * 1) wait 1ms for Kumeran link to come up
2204 * 2) check Kumeran Diagnostic register PCS lock loss bit
2205 * 3) if not set the link is locked (all is good), otherwise...
2206 * 4) reset the PHY
2207 * 5) repeat up to 10 times
2208 * Note: this is only called for IGP3 copper when speed is 1gb.
2210 static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
2212 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2213 u32 phy_ctrl;
2214 s32 ret_val;
2215 u16 i, data;
2216 bool link;
2218 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
2219 return 0;
2222 * Make sure link is up before proceeding. If not just return.
2223 * Attempting this while link is negotiating fouled up link
2224 * stability
2226 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2227 if (!link)
2228 return 0;
2230 for (i = 0; i < 10; i++) {
2231 /* read once to clear */
2232 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
2233 if (ret_val)
2234 return ret_val;
2235 /* and again to get new status */
2236 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
2237 if (ret_val)
2238 return ret_val;
2240 /* check for PCS lock */
2241 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
2242 return 0;
2244 /* Issue PHY reset */
2245 e1000_phy_hw_reset(hw);
2246 mdelay(5);
2248 /* Disable GigE link negotiation */
2249 phy_ctrl = er32(PHY_CTRL);
2250 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
2251 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
2252 ew32(PHY_CTRL, phy_ctrl);
2255 * Call gig speed drop workaround on Gig disable before accessing
2256 * any PHY registers
2258 e1000e_gig_downshift_workaround_ich8lan(hw);
2260 /* unable to acquire PCS lock */
2261 return -E1000_ERR_PHY;
2265 * e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
2266 * @hw: pointer to the HW structure
2267 * @state: boolean value used to set the current Kumeran workaround state
2269 * If ICH8, set the current Kumeran workaround state (enabled - TRUE
2270 * /disabled - FALSE).
2272 void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
2273 bool state)
2275 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2277 if (hw->mac.type != e1000_ich8lan) {
2278 hw_dbg(hw, "Workaround applies to ICH8 only.\n");
2279 return;
2282 dev_spec->kmrn_lock_loss_workaround_enabled = state;
2286 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
2287 * @hw: pointer to the HW structure
2289 * Workaround for 82566 power-down on D3 entry:
2290 * 1) disable gigabit link
2291 * 2) write VR power-down enable
2292 * 3) read it back
2293 * Continue if successful, else issue LCD reset and repeat
2295 void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
2297 u32 reg;
2298 u16 data;
2299 u8 retry = 0;
2301 if (hw->phy.type != e1000_phy_igp_3)
2302 return;
2304 /* Try the workaround twice (if needed) */
2305 do {
2306 /* Disable link */
2307 reg = er32(PHY_CTRL);
2308 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
2309 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
2310 ew32(PHY_CTRL, reg);
2313 * Call gig speed drop workaround on Gig disable before
2314 * accessing any PHY registers
2316 if (hw->mac.type == e1000_ich8lan)
2317 e1000e_gig_downshift_workaround_ich8lan(hw);
2319 /* Write VR power-down enable */
2320 e1e_rphy(hw, IGP3_VR_CTRL, &data);
2321 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
2322 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
2324 /* Read it back and test */
2325 e1e_rphy(hw, IGP3_VR_CTRL, &data);
2326 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
2327 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
2328 break;
2330 /* Issue PHY reset and repeat at most one more time */
2331 reg = er32(CTRL);
2332 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
2333 retry++;
2334 } while (retry);
2338 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
2339 * @hw: pointer to the HW structure
2341 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
2342 * LPLU, Gig disable, MDIC PHY reset):
2343 * 1) Set Kumeran Near-end loopback
2344 * 2) Clear Kumeran Near-end loopback
2345 * Should only be called for ICH8[m] devices with IGP_3 Phy.
2347 void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
2349 s32 ret_val;
2350 u16 reg_data;
2352 if ((hw->mac.type != e1000_ich8lan) ||
2353 (hw->phy.type != e1000_phy_igp_3))
2354 return;
2356 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2357 &reg_data);
2358 if (ret_val)
2359 return;
2360 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
2361 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2362 reg_data);
2363 if (ret_val)
2364 return;
2365 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
2366 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2367 reg_data);
2371 * e1000e_disable_gig_wol_ich8lan - disable gig during WoL
2372 * @hw: pointer to the HW structure
2374 * During S0 to Sx transition, it is possible the link remains at gig
2375 * instead of negotiating to a lower speed. Before going to Sx, set
2376 * 'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
2377 * to a lower speed.
2379 * Should only be called for ICH9 and ICH10 devices.
2381 void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
2383 u32 phy_ctrl;
2385 if ((hw->mac.type == e1000_ich10lan) ||
2386 (hw->mac.type == e1000_ich9lan)) {
2387 phy_ctrl = er32(PHY_CTRL);
2388 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
2389 E1000_PHY_CTRL_GBE_DISABLE;
2390 ew32(PHY_CTRL, phy_ctrl);
2393 return;
2397 * e1000_cleanup_led_ich8lan - Restore the default LED operation
2398 * @hw: pointer to the HW structure
2400 * Return the LED back to the default configuration.
2402 static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
2404 if (hw->phy.type == e1000_phy_ife)
2405 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
2407 ew32(LEDCTL, hw->mac.ledctl_default);
2408 return 0;
2412 * e1000_led_on_ich8lan - Turn LEDs on
2413 * @hw: pointer to the HW structure
2415 * Turn on the LEDs.
2417 static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
2419 if (hw->phy.type == e1000_phy_ife)
2420 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
2421 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
2423 ew32(LEDCTL, hw->mac.ledctl_mode2);
2424 return 0;
2428 * e1000_led_off_ich8lan - Turn LEDs off
2429 * @hw: pointer to the HW structure
2431 * Turn off the LEDs.
2433 static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
2435 if (hw->phy.type == e1000_phy_ife)
2436 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
2437 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
2439 ew32(LEDCTL, hw->mac.ledctl_mode1);
2440 return 0;
2444 * e1000_get_cfg_done_ich8lan - Read config done bit
2445 * @hw: pointer to the HW structure
2447 * Read the management control register for the config done bit for
2448 * completion status. NOTE: silicon which is EEPROM-less will fail trying
2449 * to read the config done bit, so an error is *ONLY* logged and returns
2450 * E1000_SUCCESS. If we were to return with error, EEPROM-less silicon
2451 * would not be able to be reset or change link.
2453 static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
2455 u32 bank = 0;
2457 e1000e_get_cfg_done(hw);
2459 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
2460 if (hw->mac.type != e1000_ich10lan) {
2461 if (((er32(EECD) & E1000_EECD_PRES) == 0) &&
2462 (hw->phy.type == e1000_phy_igp_3)) {
2463 e1000e_phy_init_script_igp3(hw);
2465 } else {
2466 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
2467 /* Maybe we should do a basic PHY config */
2468 hw_dbg(hw, "EEPROM not present\n");
2469 return -E1000_ERR_CONFIG;
2473 return 0;
2477 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
2478 * @hw: pointer to the HW structure
2480 * Clears hardware counters specific to the silicon family and calls
2481 * clear_hw_cntrs_generic to clear all general purpose counters.
2483 static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
2485 u32 temp;
2487 e1000e_clear_hw_cntrs_base(hw);
2489 temp = er32(ALGNERRC);
2490 temp = er32(RXERRC);
2491 temp = er32(TNCRS);
2492 temp = er32(CEXTERR);
2493 temp = er32(TSCTC);
2494 temp = er32(TSCTFC);
2496 temp = er32(MGTPRC);
2497 temp = er32(MGTPDC);
2498 temp = er32(MGTPTC);
2500 temp = er32(IAC);
2501 temp = er32(ICRXOC);
2505 static struct e1000_mac_operations ich8_mac_ops = {
2506 .check_mng_mode = e1000_check_mng_mode_ich8lan,
2507 .check_for_link = e1000e_check_for_copper_link,
2508 .cleanup_led = e1000_cleanup_led_ich8lan,
2509 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
2510 .get_bus_info = e1000_get_bus_info_ich8lan,
2511 .get_link_up_info = e1000_get_link_up_info_ich8lan,
2512 .led_on = e1000_led_on_ich8lan,
2513 .led_off = e1000_led_off_ich8lan,
2514 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
2515 .reset_hw = e1000_reset_hw_ich8lan,
2516 .init_hw = e1000_init_hw_ich8lan,
2517 .setup_link = e1000_setup_link_ich8lan,
2518 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
2521 static struct e1000_phy_operations ich8_phy_ops = {
2522 .acquire_phy = e1000_acquire_swflag_ich8lan,
2523 .check_reset_block = e1000_check_reset_block_ich8lan,
2524 .commit_phy = NULL,
2525 .force_speed_duplex = e1000_phy_force_speed_duplex_ich8lan,
2526 .get_cfg_done = e1000_get_cfg_done_ich8lan,
2527 .get_cable_length = e1000e_get_cable_length_igp_2,
2528 .get_phy_info = e1000_get_phy_info_ich8lan,
2529 .read_phy_reg = e1000e_read_phy_reg_igp,
2530 .release_phy = e1000_release_swflag_ich8lan,
2531 .reset_phy = e1000_phy_hw_reset_ich8lan,
2532 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
2533 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
2534 .write_phy_reg = e1000e_write_phy_reg_igp,
2537 static struct e1000_nvm_operations ich8_nvm_ops = {
2538 .acquire_nvm = e1000_acquire_swflag_ich8lan,
2539 .read_nvm = e1000_read_nvm_ich8lan,
2540 .release_nvm = e1000_release_swflag_ich8lan,
2541 .update_nvm = e1000_update_nvm_checksum_ich8lan,
2542 .valid_led_default = e1000_valid_led_default_ich8lan,
2543 .validate_nvm = e1000_validate_nvm_checksum_ich8lan,
2544 .write_nvm = e1000_write_nvm_ich8lan,
2547 struct e1000_info e1000_ich8_info = {
2548 .mac = e1000_ich8lan,
2549 .flags = FLAG_HAS_WOL
2550 | FLAG_IS_ICH
2551 | FLAG_RX_CSUM_ENABLED
2552 | FLAG_HAS_CTRLEXT_ON_LOAD
2553 | FLAG_HAS_AMT
2554 | FLAG_HAS_FLASH
2555 | FLAG_APME_IN_WUC,
2556 .pba = 8,
2557 .get_variants = e1000_get_variants_ich8lan,
2558 .mac_ops = &ich8_mac_ops,
2559 .phy_ops = &ich8_phy_ops,
2560 .nvm_ops = &ich8_nvm_ops,
2563 struct e1000_info e1000_ich9_info = {
2564 .mac = e1000_ich9lan,
2565 .flags = FLAG_HAS_JUMBO_FRAMES
2566 | FLAG_IS_ICH
2567 | FLAG_HAS_WOL
2568 | FLAG_RX_CSUM_ENABLED
2569 | FLAG_HAS_CTRLEXT_ON_LOAD
2570 | FLAG_HAS_AMT
2571 | FLAG_HAS_ERT
2572 | FLAG_HAS_FLASH
2573 | FLAG_APME_IN_WUC,
2574 .pba = 10,
2575 .get_variants = e1000_get_variants_ich8lan,
2576 .mac_ops = &ich8_mac_ops,
2577 .phy_ops = &ich8_phy_ops,
2578 .nvm_ops = &ich8_nvm_ops,
2581 struct e1000_info e1000_ich10_info = {
2582 .mac = e1000_ich10lan,
2583 .flags = FLAG_HAS_JUMBO_FRAMES
2584 | FLAG_IS_ICH
2585 | FLAG_HAS_WOL
2586 | FLAG_RX_CSUM_ENABLED
2587 | FLAG_HAS_CTRLEXT_ON_LOAD
2588 | FLAG_HAS_AMT
2589 | FLAG_HAS_ERT
2590 | FLAG_HAS_FLASH
2591 | FLAG_APME_IN_WUC,
2592 .pba = 10,
2593 .get_variants = e1000_get_variants_ich8lan,
2594 .mac_ops = &ich8_mac_ops,
2595 .phy_ops = &ich8_phy_ops,
2596 .nvm_ops = &ich8_nvm_ops,