e1000e: remove failed request for sw/fw/hw flag
[safe/jmp/linux-2.6] / drivers / net / e1000e / ich8lan.c
1 /*******************************************************************************
2
3   Intel PRO/1000 Linux driver
4   Copyright(c) 1999 - 2008 Intel Corporation.
5
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.
9
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.
14
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.
18
19   The full GNU General Public License is included in this distribution in
20   the file called "COPYING".
21
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
26
27 *******************************************************************************/
28
29 /*
30  * 82562G-2 10/100 Network Connection
31  * 82562GT 10/100 Network Connection
32  * 82562GT-2 10/100 Network Connection
33  * 82562V 10/100 Network Connection
34  * 82562V-2 10/100 Network Connection
35  * 82566DC-2 Gigabit Network Connection
36  * 82566DC Gigabit Network Connection
37  * 82566DM-2 Gigabit Network Connection
38  * 82566DM Gigabit Network Connection
39  * 82566MC Gigabit Network Connection
40  * 82566MM Gigabit Network Connection
41  * 82567LM Gigabit Network Connection
42  * 82567LF Gigabit Network Connection
43  * 82567LM-2 Gigabit Network Connection
44  * 82567LF-2 Gigabit Network Connection
45  * 82567V-2 Gigabit Network Connection
46  * 82567LF-3 Gigabit Network Connection
47  * 82567LM-3 Gigabit Network Connection
48  * 82567LM-4 Gigabit Network Connection
49  */
50
51 #include <linux/netdevice.h>
52 #include <linux/ethtool.h>
53 #include <linux/delay.h>
54 #include <linux/pci.h>
55
56 #include "e1000.h"
57
58 #define ICH_FLASH_GFPREG                0x0000
59 #define ICH_FLASH_HSFSTS                0x0004
60 #define ICH_FLASH_HSFCTL                0x0006
61 #define ICH_FLASH_FADDR                 0x0008
62 #define ICH_FLASH_FDATA0                0x0010
63
64 #define ICH_FLASH_READ_COMMAND_TIMEOUT  500
65 #define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
66 #define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
67 #define ICH_FLASH_LINEAR_ADDR_MASK      0x00FFFFFF
68 #define ICH_FLASH_CYCLE_REPEAT_COUNT    10
69
70 #define ICH_CYCLE_READ                  0
71 #define ICH_CYCLE_WRITE                 2
72 #define ICH_CYCLE_ERASE                 3
73
74 #define FLASH_GFPREG_BASE_MASK          0x1FFF
75 #define FLASH_SECTOR_ADDR_SHIFT         12
76
77 #define ICH_FLASH_SEG_SIZE_256          256
78 #define ICH_FLASH_SEG_SIZE_4K           4096
79 #define ICH_FLASH_SEG_SIZE_8K           8192
80 #define ICH_FLASH_SEG_SIZE_64K          65536
81
82
83 #define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
84
85 #define E1000_ICH_MNG_IAMT_MODE         0x2
86
87 #define ID_LED_DEFAULT_ICH8LAN  ((ID_LED_DEF1_DEF2 << 12) | \
88                                  (ID_LED_DEF1_OFF2 <<  8) | \
89                                  (ID_LED_DEF1_ON2  <<  4) | \
90                                  (ID_LED_DEF1_DEF2))
91
92 #define E1000_ICH_NVM_SIG_WORD          0x13
93 #define E1000_ICH_NVM_SIG_MASK          0xC000
94
95 #define E1000_ICH8_LAN_INIT_TIMEOUT     1500
96
97 #define E1000_FEXTNVM_SW_CONFIG         1
98 #define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
99
100 #define PCIE_ICH8_SNOOP_ALL             PCIE_NO_SNOOP_ALL
101
102 #define E1000_ICH_RAR_ENTRIES           7
103
104 #define PHY_PAGE_SHIFT 5
105 #define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
106                            ((reg) & MAX_PHY_REG_ADDRESS))
107 #define IGP3_KMRN_DIAG  PHY_REG(770, 19) /* KMRN Diagnostic */
108 #define IGP3_VR_CTRL    PHY_REG(776, 18) /* Voltage Regulator Control */
109
110 #define IGP3_KMRN_DIAG_PCS_LOCK_LOSS    0x0002
111 #define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
112 #define IGP3_VR_CTRL_MODE_SHUTDOWN      0x0200
113
114 /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
115 /* Offset 04h HSFSTS */
116 union ich8_hws_flash_status {
117         struct ich8_hsfsts {
118                 u16 flcdone    :1; /* bit 0 Flash Cycle Done */
119                 u16 flcerr     :1; /* bit 1 Flash Cycle Error */
120                 u16 dael       :1; /* bit 2 Direct Access error Log */
121                 u16 berasesz   :2; /* bit 4:3 Sector Erase Size */
122                 u16 flcinprog  :1; /* bit 5 flash cycle in Progress */
123                 u16 reserved1  :2; /* bit 13:6 Reserved */
124                 u16 reserved2  :6; /* bit 13:6 Reserved */
125                 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
126                 u16 flockdn    :1; /* bit 15 Flash Config Lock-Down */
127         } hsf_status;
128         u16 regval;
129 };
130
131 /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
132 /* Offset 06h FLCTL */
133 union ich8_hws_flash_ctrl {
134         struct ich8_hsflctl {
135                 u16 flcgo      :1;   /* 0 Flash Cycle Go */
136                 u16 flcycle    :2;   /* 2:1 Flash Cycle */
137                 u16 reserved   :5;   /* 7:3 Reserved  */
138                 u16 fldbcount  :2;   /* 9:8 Flash Data Byte Count */
139                 u16 flockdn    :6;   /* 15:10 Reserved */
140         } hsf_ctrl;
141         u16 regval;
142 };
143
144 /* ICH Flash Region Access Permissions */
145 union ich8_hws_flash_regacc {
146         struct ich8_flracc {
147                 u32 grra      :8; /* 0:7 GbE region Read Access */
148                 u32 grwa      :8; /* 8:15 GbE region Write Access */
149                 u32 gmrag     :8; /* 23:16 GbE Master Read Access Grant */
150                 u32 gmwag     :8; /* 31:24 GbE Master Write Access Grant */
151         } hsf_flregacc;
152         u16 regval;
153 };
154
155 static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
156 static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
157 static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
158 static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw);
159 static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
160 static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
161                                                 u32 offset, u8 byte);
162 static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
163                                          u8 *data);
164 static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
165                                          u16 *data);
166 static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
167                                          u8 size, u16 *data);
168 static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
169 static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
170 static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
171
172 static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
173 {
174         return readw(hw->flash_address + reg);
175 }
176
177 static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
178 {
179         return readl(hw->flash_address + reg);
180 }
181
182 static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
183 {
184         writew(val, hw->flash_address + reg);
185 }
186
187 static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
188 {
189         writel(val, hw->flash_address + reg);
190 }
191
192 #define er16flash(reg)          __er16flash(hw, (reg))
193 #define er32flash(reg)          __er32flash(hw, (reg))
194 #define ew16flash(reg,val)      __ew16flash(hw, (reg), (val))
195 #define ew32flash(reg,val)      __ew32flash(hw, (reg), (val))
196
197 /**
198  *  e1000_init_phy_params_ich8lan - Initialize PHY function pointers
199  *  @hw: pointer to the HW structure
200  *
201  *  Initialize family-specific PHY parameters and function pointers.
202  **/
203 static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
204 {
205         struct e1000_phy_info *phy = &hw->phy;
206         s32 ret_val;
207         u16 i = 0;
208
209         phy->addr                       = 1;
210         phy->reset_delay_us             = 100;
211
212         /*
213          * We may need to do this twice - once for IGP and if that fails,
214          * we'll set BM func pointers and try again
215          */
216         ret_val = e1000e_determine_phy_address(hw);
217         if (ret_val) {
218                 hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
219                 hw->phy.ops.read_phy_reg  = e1000e_read_phy_reg_bm;
220                 ret_val = e1000e_determine_phy_address(hw);
221                 if (ret_val)
222                         return ret_val;
223         }
224
225         phy->id = 0;
226         while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
227                (i++ < 100)) {
228                 msleep(1);
229                 ret_val = e1000e_get_phy_id(hw);
230                 if (ret_val)
231                         return ret_val;
232         }
233
234         /* Verify phy id */
235         switch (phy->id) {
236         case IGP03E1000_E_PHY_ID:
237                 phy->type = e1000_phy_igp_3;
238                 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
239                 break;
240         case IFE_E_PHY_ID:
241         case IFE_PLUS_E_PHY_ID:
242         case IFE_C_E_PHY_ID:
243                 phy->type = e1000_phy_ife;
244                 phy->autoneg_mask = E1000_ALL_NOT_GIG;
245                 break;
246         case BME1000_E_PHY_ID:
247                 phy->type = e1000_phy_bm;
248                 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
249                 hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
250                 hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
251                 hw->phy.ops.commit_phy = e1000e_phy_sw_reset;
252                 break;
253         default:
254                 return -E1000_ERR_PHY;
255                 break;
256         }
257
258         return 0;
259 }
260
261 /**
262  *  e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
263  *  @hw: pointer to the HW structure
264  *
265  *  Initialize family-specific NVM parameters and function
266  *  pointers.
267  **/
268 static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
269 {
270         struct e1000_nvm_info *nvm = &hw->nvm;
271         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
272         u32 gfpreg;
273         u32 sector_base_addr;
274         u32 sector_end_addr;
275         u16 i;
276
277         /* Can't read flash registers if the register set isn't mapped. */
278         if (!hw->flash_address) {
279                 hw_dbg(hw, "ERROR: Flash registers not mapped\n");
280                 return -E1000_ERR_CONFIG;
281         }
282
283         nvm->type = e1000_nvm_flash_sw;
284
285         gfpreg = er32flash(ICH_FLASH_GFPREG);
286
287         /*
288          * sector_X_addr is a "sector"-aligned address (4096 bytes)
289          * Add 1 to sector_end_addr since this sector is included in
290          * the overall size.
291          */
292         sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
293         sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
294
295         /* flash_base_addr is byte-aligned */
296         nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
297
298         /*
299          * find total size of the NVM, then cut in half since the total
300          * size represents two separate NVM banks.
301          */
302         nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
303                                 << FLASH_SECTOR_ADDR_SHIFT;
304         nvm->flash_bank_size /= 2;
305         /* Adjust to word count */
306         nvm->flash_bank_size /= sizeof(u16);
307
308         nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
309
310         /* Clear shadow ram */
311         for (i = 0; i < nvm->word_size; i++) {
312                 dev_spec->shadow_ram[i].modified = 0;
313                 dev_spec->shadow_ram[i].value    = 0xFFFF;
314         }
315
316         return 0;
317 }
318
319 /**
320  *  e1000_init_mac_params_ich8lan - Initialize MAC function pointers
321  *  @hw: pointer to the HW structure
322  *
323  *  Initialize family-specific MAC parameters and function
324  *  pointers.
325  **/
326 static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
327 {
328         struct e1000_hw *hw = &adapter->hw;
329         struct e1000_mac_info *mac = &hw->mac;
330
331         /* Set media type function pointer */
332         hw->phy.media_type = e1000_media_type_copper;
333
334         /* Set mta register count */
335         mac->mta_reg_count = 32;
336         /* Set rar entry count */
337         mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
338         if (mac->type == e1000_ich8lan)
339                 mac->rar_entry_count--;
340         /* Set if manageability features are enabled. */
341         mac->arc_subsystem_valid = 1;
342
343         /* Enable PCS Lock-loss workaround for ICH8 */
344         if (mac->type == e1000_ich8lan)
345                 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, 1);
346
347         return 0;
348 }
349
350 static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
351 {
352         struct e1000_hw *hw = &adapter->hw;
353         s32 rc;
354
355         rc = e1000_init_mac_params_ich8lan(adapter);
356         if (rc)
357                 return rc;
358
359         rc = e1000_init_nvm_params_ich8lan(hw);
360         if (rc)
361                 return rc;
362
363         rc = e1000_init_phy_params_ich8lan(hw);
364         if (rc)
365                 return rc;
366
367         if ((adapter->hw.mac.type == e1000_ich8lan) &&
368             (adapter->hw.phy.type == e1000_phy_igp_3))
369                 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
370
371         return 0;
372 }
373
374 /**
375  *  e1000_acquire_swflag_ich8lan - Acquire software control flag
376  *  @hw: pointer to the HW structure
377  *
378  *  Acquires the software control flag for performing NVM and PHY
379  *  operations.  This is a function pointer entry point only called by
380  *  read/write routines for the PHY and NVM parts.
381  **/
382 static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
383 {
384         u32 extcnf_ctrl;
385         u32 timeout = PHY_CFG_TIMEOUT;
386
387         while (timeout) {
388                 extcnf_ctrl = er32(EXTCNF_CTRL);
389                 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
390                 ew32(EXTCNF_CTRL, extcnf_ctrl);
391
392                 extcnf_ctrl = er32(EXTCNF_CTRL);
393                 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
394                         break;
395                 mdelay(1);
396                 timeout--;
397         }
398
399         if (!timeout) {
400                 hw_dbg(hw, "FW or HW has locked the resource for too long.\n");
401                 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
402                 ew32(EXTCNF_CTRL, extcnf_ctrl);
403                 return -E1000_ERR_CONFIG;
404         }
405
406         return 0;
407 }
408
409 /**
410  *  e1000_release_swflag_ich8lan - Release software control flag
411  *  @hw: pointer to the HW structure
412  *
413  *  Releases the software control flag for performing NVM and PHY operations.
414  *  This is a function pointer entry point only called by read/write
415  *  routines for the PHY and NVM parts.
416  **/
417 static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
418 {
419         u32 extcnf_ctrl;
420
421         extcnf_ctrl = er32(EXTCNF_CTRL);
422         extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
423         ew32(EXTCNF_CTRL, extcnf_ctrl);
424 }
425
426 /**
427  *  e1000_check_mng_mode_ich8lan - Checks management mode
428  *  @hw: pointer to the HW structure
429  *
430  *  This checks if the adapter has manageability enabled.
431  *  This is a function pointer entry point only called by read/write
432  *  routines for the PHY and NVM parts.
433  **/
434 static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
435 {
436         u32 fwsm = er32(FWSM);
437
438         return (fwsm & E1000_FWSM_MODE_MASK) ==
439                 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
440 }
441
442 /**
443  *  e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
444  *  @hw: pointer to the HW structure
445  *
446  *  Checks if firmware is blocking the reset of the PHY.
447  *  This is a function pointer entry point only called by
448  *  reset routines.
449  **/
450 static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
451 {
452         u32 fwsm;
453
454         fwsm = er32(FWSM);
455
456         return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
457 }
458
459 /**
460  *  e1000_phy_force_speed_duplex_ich8lan - Force PHY speed & duplex
461  *  @hw: pointer to the HW structure
462  *
463  *  Forces the speed and duplex settings of the PHY.
464  *  This is a function pointer entry point only called by
465  *  PHY setup routines.
466  **/
467 static s32 e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw)
468 {
469         struct e1000_phy_info *phy = &hw->phy;
470         s32 ret_val;
471         u16 data;
472         bool link;
473
474         if (phy->type != e1000_phy_ife) {
475                 ret_val = e1000e_phy_force_speed_duplex_igp(hw);
476                 return ret_val;
477         }
478
479         ret_val = e1e_rphy(hw, PHY_CONTROL, &data);
480         if (ret_val)
481                 return ret_val;
482
483         e1000e_phy_force_speed_duplex_setup(hw, &data);
484
485         ret_val = e1e_wphy(hw, PHY_CONTROL, data);
486         if (ret_val)
487                 return ret_val;
488
489         /* Disable MDI-X support for 10/100 */
490         ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
491         if (ret_val)
492                 return ret_val;
493
494         data &= ~IFE_PMC_AUTO_MDIX;
495         data &= ~IFE_PMC_FORCE_MDIX;
496
497         ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
498         if (ret_val)
499                 return ret_val;
500
501         hw_dbg(hw, "IFE PMC: %X\n", data);
502
503         udelay(1);
504
505         if (phy->autoneg_wait_to_complete) {
506                 hw_dbg(hw, "Waiting for forced speed/duplex link on IFE phy.\n");
507
508                 ret_val = e1000e_phy_has_link_generic(hw,
509                                                      PHY_FORCE_LIMIT,
510                                                      100000,
511                                                      &link);
512                 if (ret_val)
513                         return ret_val;
514
515                 if (!link)
516                         hw_dbg(hw, "Link taking longer than expected.\n");
517
518                 /* Try once more */
519                 ret_val = e1000e_phy_has_link_generic(hw,
520                                                      PHY_FORCE_LIMIT,
521                                                      100000,
522                                                      &link);
523                 if (ret_val)
524                         return ret_val;
525         }
526
527         return 0;
528 }
529
530 /**
531  *  e1000_phy_hw_reset_ich8lan - Performs a PHY reset
532  *  @hw: pointer to the HW structure
533  *
534  *  Resets the PHY
535  *  This is a function pointer entry point called by drivers
536  *  or other shared routines.
537  **/
538 static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
539 {
540         struct e1000_phy_info *phy = &hw->phy;
541         u32 i;
542         u32 data, cnf_size, cnf_base_addr, sw_cfg_mask;
543         s32 ret_val;
544         u16 loop = E1000_ICH8_LAN_INIT_TIMEOUT;
545         u16 word_addr, reg_data, reg_addr, phy_page = 0;
546
547         ret_val = e1000e_phy_hw_reset_generic(hw);
548         if (ret_val)
549                 return ret_val;
550
551         /*
552          * Initialize the PHY from the NVM on ICH platforms.  This
553          * is needed due to an issue where the NVM configuration is
554          * not properly autoloaded after power transitions.
555          * Therefore, after each PHY reset, we will load the
556          * configuration data out of the NVM manually.
557          */
558         if (hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) {
559                 struct e1000_adapter *adapter = hw->adapter;
560
561                 /* Check if SW needs configure the PHY */
562                 if ((adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
563                     (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M))
564                         sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
565                 else
566                         sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
567
568                 data = er32(FEXTNVM);
569                 if (!(data & sw_cfg_mask))
570                         return 0;
571
572                 /* Wait for basic configuration completes before proceeding*/
573                 do {
574                         data = er32(STATUS);
575                         data &= E1000_STATUS_LAN_INIT_DONE;
576                         udelay(100);
577                 } while ((!data) && --loop);
578
579                 /*
580                  * If basic configuration is incomplete before the above loop
581                  * count reaches 0, loading the configuration from NVM will
582                  * leave the PHY in a bad state possibly resulting in no link.
583                  */
584                 if (loop == 0) {
585                         hw_dbg(hw, "LAN_INIT_DONE not set, increase timeout\n");
586                 }
587
588                 /* Clear the Init Done bit for the next init event */
589                 data = er32(STATUS);
590                 data &= ~E1000_STATUS_LAN_INIT_DONE;
591                 ew32(STATUS, data);
592
593                 /*
594                  * Make sure HW does not configure LCD from PHY
595                  * extended configuration before SW configuration
596                  */
597                 data = er32(EXTCNF_CTRL);
598                 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
599                         return 0;
600
601                 cnf_size = er32(EXTCNF_SIZE);
602                 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
603                 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
604                 if (!cnf_size)
605                         return 0;
606
607                 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
608                 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
609
610                 /* Configure LCD from extended configuration region. */
611
612                 /* cnf_base_addr is in DWORD */
613                 word_addr = (u16)(cnf_base_addr << 1);
614
615                 for (i = 0; i < cnf_size; i++) {
616                         ret_val = e1000_read_nvm(hw,
617                                                 (word_addr + i * 2),
618                                                 1,
619                                                 &reg_data);
620                         if (ret_val)
621                                 return ret_val;
622
623                         ret_val = e1000_read_nvm(hw,
624                                                 (word_addr + i * 2 + 1),
625                                                 1,
626                                                 &reg_addr);
627                         if (ret_val)
628                                 return ret_val;
629
630                         /* Save off the PHY page for future writes. */
631                         if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
632                                 phy_page = reg_data;
633                                 continue;
634                         }
635
636                         reg_addr |= phy_page;
637
638                         ret_val = e1e_wphy(hw, (u32)reg_addr, reg_data);
639                         if (ret_val)
640                                 return ret_val;
641                 }
642         }
643
644         return 0;
645 }
646
647 /**
648  *  e1000_get_phy_info_ife_ich8lan - Retrieves various IFE PHY states
649  *  @hw: pointer to the HW structure
650  *
651  *  Populates "phy" structure with various feature states.
652  *  This function is only called by other family-specific
653  *  routines.
654  **/
655 static s32 e1000_get_phy_info_ife_ich8lan(struct e1000_hw *hw)
656 {
657         struct e1000_phy_info *phy = &hw->phy;
658         s32 ret_val;
659         u16 data;
660         bool link;
661
662         ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
663         if (ret_val)
664                 return ret_val;
665
666         if (!link) {
667                 hw_dbg(hw, "Phy info is only valid if link is up\n");
668                 return -E1000_ERR_CONFIG;
669         }
670
671         ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
672         if (ret_val)
673                 return ret_val;
674         phy->polarity_correction = (!(data & IFE_PSC_AUTO_POLARITY_DISABLE));
675
676         if (phy->polarity_correction) {
677                 ret_val = e1000_check_polarity_ife_ich8lan(hw);
678                 if (ret_val)
679                         return ret_val;
680         } else {
681                 /* Polarity is forced */
682                 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
683                                       ? e1000_rev_polarity_reversed
684                                       : e1000_rev_polarity_normal;
685         }
686
687         ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
688         if (ret_val)
689                 return ret_val;
690
691         phy->is_mdix = (data & IFE_PMC_MDIX_STATUS);
692
693         /* The following parameters are undefined for 10/100 operation. */
694         phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
695         phy->local_rx = e1000_1000t_rx_status_undefined;
696         phy->remote_rx = e1000_1000t_rx_status_undefined;
697
698         return 0;
699 }
700
701 /**
702  *  e1000_get_phy_info_ich8lan - Calls appropriate PHY type get_phy_info
703  *  @hw: pointer to the HW structure
704  *
705  *  Wrapper for calling the get_phy_info routines for the appropriate phy type.
706  *  This is a function pointer entry point called by drivers
707  *  or other shared routines.
708  **/
709 static s32 e1000_get_phy_info_ich8lan(struct e1000_hw *hw)
710 {
711         switch (hw->phy.type) {
712         case e1000_phy_ife:
713                 return e1000_get_phy_info_ife_ich8lan(hw);
714                 break;
715         case e1000_phy_igp_3:
716         case e1000_phy_bm:
717                 return e1000e_get_phy_info_igp(hw);
718                 break;
719         default:
720                 break;
721         }
722
723         return -E1000_ERR_PHY_TYPE;
724 }
725
726 /**
727  *  e1000_check_polarity_ife_ich8lan - Check cable polarity for IFE PHY
728  *  @hw: pointer to the HW structure
729  *
730  *  Polarity is determined on the polarity reversal feature being enabled.
731  *  This function is only called by other family-specific
732  *  routines.
733  **/
734 static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw)
735 {
736         struct e1000_phy_info *phy = &hw->phy;
737         s32 ret_val;
738         u16 phy_data, offset, mask;
739
740         /*
741          * Polarity is determined based on the reversal feature being enabled.
742          */
743         if (phy->polarity_correction) {
744                 offset  = IFE_PHY_EXTENDED_STATUS_CONTROL;
745                 mask    = IFE_PESC_POLARITY_REVERSED;
746         } else {
747                 offset  = IFE_PHY_SPECIAL_CONTROL;
748                 mask    = IFE_PSC_FORCE_POLARITY;
749         }
750
751         ret_val = e1e_rphy(hw, offset, &phy_data);
752
753         if (!ret_val)
754                 phy->cable_polarity = (phy_data & mask)
755                                       ? e1000_rev_polarity_reversed
756                                       : e1000_rev_polarity_normal;
757
758         return ret_val;
759 }
760
761 /**
762  *  e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
763  *  @hw: pointer to the HW structure
764  *  @active: TRUE to enable LPLU, FALSE to disable
765  *
766  *  Sets the LPLU D0 state according to the active flag.  When
767  *  activating LPLU this function also disables smart speed
768  *  and vice versa.  LPLU will not be activated unless the
769  *  device autonegotiation advertisement meets standards of
770  *  either 10 or 10/100 or 10/100/1000 at all duplexes.
771  *  This is a function pointer entry point only called by
772  *  PHY setup routines.
773  **/
774 static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
775 {
776         struct e1000_phy_info *phy = &hw->phy;
777         u32 phy_ctrl;
778         s32 ret_val = 0;
779         u16 data;
780
781         if (phy->type == e1000_phy_ife)
782                 return ret_val;
783
784         phy_ctrl = er32(PHY_CTRL);
785
786         if (active) {
787                 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
788                 ew32(PHY_CTRL, phy_ctrl);
789
790                 /*
791                  * Call gig speed drop workaround on LPLU before accessing
792                  * any PHY registers
793                  */
794                 if ((hw->mac.type == e1000_ich8lan) &&
795                     (hw->phy.type == e1000_phy_igp_3))
796                         e1000e_gig_downshift_workaround_ich8lan(hw);
797
798                 /* When LPLU is enabled, we should disable SmartSpeed */
799                 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
800                 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
801                 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
802                 if (ret_val)
803                         return ret_val;
804         } else {
805                 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
806                 ew32(PHY_CTRL, phy_ctrl);
807
808                 /*
809                  * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
810                  * during Dx states where the power conservation is most
811                  * important.  During driver activity we should enable
812                  * SmartSpeed, so performance is maintained.
813                  */
814                 if (phy->smart_speed == e1000_smart_speed_on) {
815                         ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
816                                            &data);
817                         if (ret_val)
818                                 return ret_val;
819
820                         data |= IGP01E1000_PSCFR_SMART_SPEED;
821                         ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
822                                            data);
823                         if (ret_val)
824                                 return ret_val;
825                 } else if (phy->smart_speed == e1000_smart_speed_off) {
826                         ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
827                                            &data);
828                         if (ret_val)
829                                 return ret_val;
830
831                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
832                         ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
833                                            data);
834                         if (ret_val)
835                                 return ret_val;
836                 }
837         }
838
839         return 0;
840 }
841
842 /**
843  *  e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
844  *  @hw: pointer to the HW structure
845  *  @active: TRUE to enable LPLU, FALSE to disable
846  *
847  *  Sets the LPLU D3 state according to the active flag.  When
848  *  activating LPLU this function also disables smart speed
849  *  and vice versa.  LPLU will not be activated unless the
850  *  device autonegotiation advertisement meets standards of
851  *  either 10 or 10/100 or 10/100/1000 at all duplexes.
852  *  This is a function pointer entry point only called by
853  *  PHY setup routines.
854  **/
855 static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
856 {
857         struct e1000_phy_info *phy = &hw->phy;
858         u32 phy_ctrl;
859         s32 ret_val;
860         u16 data;
861
862         phy_ctrl = er32(PHY_CTRL);
863
864         if (!active) {
865                 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
866                 ew32(PHY_CTRL, phy_ctrl);
867                 /*
868                  * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
869                  * during Dx states where the power conservation is most
870                  * important.  During driver activity we should enable
871                  * SmartSpeed, so performance is maintained.
872                  */
873                 if (phy->smart_speed == e1000_smart_speed_on) {
874                         ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
875                                            &data);
876                         if (ret_val)
877                                 return ret_val;
878
879                         data |= IGP01E1000_PSCFR_SMART_SPEED;
880                         ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
881                                            data);
882                         if (ret_val)
883                                 return ret_val;
884                 } else if (phy->smart_speed == e1000_smart_speed_off) {
885                         ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
886                                            &data);
887                         if (ret_val)
888                                 return ret_val;
889
890                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
891                         ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
892                                            data);
893                         if (ret_val)
894                                 return ret_val;
895                 }
896         } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
897                    (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
898                    (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
899                 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
900                 ew32(PHY_CTRL, phy_ctrl);
901
902                 /*
903                  * Call gig speed drop workaround on LPLU before accessing
904                  * any PHY registers
905                  */
906                 if ((hw->mac.type == e1000_ich8lan) &&
907                     (hw->phy.type == e1000_phy_igp_3))
908                         e1000e_gig_downshift_workaround_ich8lan(hw);
909
910                 /* When LPLU is enabled, we should disable SmartSpeed */
911                 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
912                 if (ret_val)
913                         return ret_val;
914
915                 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
916                 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
917         }
918
919         return 0;
920 }
921
922 /**
923  *  e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
924  *  @hw: pointer to the HW structure
925  *  @bank:  pointer to the variable that returns the active bank
926  *
927  *  Reads signature byte from the NVM using the flash access registers.
928  **/
929 static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
930 {
931         struct e1000_nvm_info *nvm = &hw->nvm;
932         /* flash bank size is in words */
933         u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
934         u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
935         u8 bank_high_byte = 0;
936
937         if (hw->mac.type != e1000_ich10lan) {
938                 if (er32(EECD) & E1000_EECD_SEC1VAL)
939                         *bank = 1;
940                 else
941                         *bank = 0;
942         } else {
943                 /*
944                  * Make sure the signature for bank 0 is valid,
945                  * if not check for bank1
946                  */
947                 e1000_read_flash_byte_ich8lan(hw, act_offset, &bank_high_byte);
948                 if ((bank_high_byte & 0xC0) == 0x80) {
949                         *bank = 0;
950                 } else {
951                         /*
952                          * find if segment 1 is valid by verifying
953                          * bit 15:14 = 10b in word 0x13
954                          */
955                         e1000_read_flash_byte_ich8lan(hw,
956                                                       act_offset + bank1_offset,
957                                                       &bank_high_byte);
958
959                         /* bank1 has a valid signature equivalent to SEC1V */
960                         if ((bank_high_byte & 0xC0) == 0x80) {
961                                 *bank = 1;
962                         } else {
963                                 hw_dbg(hw, "ERROR: EEPROM not present\n");
964                                 return -E1000_ERR_NVM;
965                         }
966                 }
967         }
968
969         return 0;
970 }
971
972 /**
973  *  e1000_read_nvm_ich8lan - Read word(s) from the NVM
974  *  @hw: pointer to the HW structure
975  *  @offset: The offset (in bytes) of the word(s) to read.
976  *  @words: Size of data to read in words
977  *  @data: Pointer to the word(s) to read at offset.
978  *
979  *  Reads a word(s) from the NVM using the flash access registers.
980  **/
981 static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
982                                   u16 *data)
983 {
984         struct e1000_nvm_info *nvm = &hw->nvm;
985         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
986         u32 act_offset;
987         s32 ret_val;
988         u32 bank = 0;
989         u16 i, word;
990
991         if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
992             (words == 0)) {
993                 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
994                 return -E1000_ERR_NVM;
995         }
996
997         ret_val = e1000_acquire_swflag_ich8lan(hw);
998         if (ret_val)
999                 return ret_val;
1000
1001         ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
1002         if (ret_val)
1003                 return ret_val;
1004
1005         act_offset = (bank) ? nvm->flash_bank_size : 0;
1006         act_offset += offset;
1007
1008         for (i = 0; i < words; i++) {
1009                 if ((dev_spec->shadow_ram) &&
1010                     (dev_spec->shadow_ram[offset+i].modified)) {
1011                         data[i] = dev_spec->shadow_ram[offset+i].value;
1012                 } else {
1013                         ret_val = e1000_read_flash_word_ich8lan(hw,
1014                                                                 act_offset + i,
1015                                                                 &word);
1016                         if (ret_val)
1017                                 break;
1018                         data[i] = word;
1019                 }
1020         }
1021
1022         e1000_release_swflag_ich8lan(hw);
1023
1024         return ret_val;
1025 }
1026
1027 /**
1028  *  e1000_flash_cycle_init_ich8lan - Initialize flash
1029  *  @hw: pointer to the HW structure
1030  *
1031  *  This function does initial flash setup so that a new read/write/erase cycle
1032  *  can be started.
1033  **/
1034 static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
1035 {
1036         union ich8_hws_flash_status hsfsts;
1037         s32 ret_val = -E1000_ERR_NVM;
1038         s32 i = 0;
1039
1040         hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1041
1042         /* Check if the flash descriptor is valid */
1043         if (hsfsts.hsf_status.fldesvalid == 0) {
1044                 hw_dbg(hw, "Flash descriptor invalid.  "
1045                          "SW Sequencing must be used.");
1046                 return -E1000_ERR_NVM;
1047         }
1048
1049         /* Clear FCERR and DAEL in hw status by writing 1 */
1050         hsfsts.hsf_status.flcerr = 1;
1051         hsfsts.hsf_status.dael = 1;
1052
1053         ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1054
1055         /*
1056          * Either we should have a hardware SPI cycle in progress
1057          * bit to check against, in order to start a new cycle or
1058          * FDONE bit should be changed in the hardware so that it
1059          * is 1 after hardware reset, which can then be used as an
1060          * indication whether a cycle is in progress or has been
1061          * completed.
1062          */
1063
1064         if (hsfsts.hsf_status.flcinprog == 0) {
1065                 /*
1066                  * There is no cycle running at present,
1067                  * so we can start a cycle
1068                  * Begin by setting Flash Cycle Done.
1069                  */
1070                 hsfsts.hsf_status.flcdone = 1;
1071                 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1072                 ret_val = 0;
1073         } else {
1074                 /*
1075                  * otherwise poll for sometime so the current
1076                  * cycle has a chance to end before giving up.
1077                  */
1078                 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
1079                         hsfsts.regval = __er16flash(hw, ICH_FLASH_HSFSTS);
1080                         if (hsfsts.hsf_status.flcinprog == 0) {
1081                                 ret_val = 0;
1082                                 break;
1083                         }
1084                         udelay(1);
1085                 }
1086                 if (ret_val == 0) {
1087                         /*
1088                          * Successful in waiting for previous cycle to timeout,
1089                          * now set the Flash Cycle Done.
1090                          */
1091                         hsfsts.hsf_status.flcdone = 1;
1092                         ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1093                 } else {
1094                         hw_dbg(hw, "Flash controller busy, cannot get access");
1095                 }
1096         }
1097
1098         return ret_val;
1099 }
1100
1101 /**
1102  *  e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
1103  *  @hw: pointer to the HW structure
1104  *  @timeout: maximum time to wait for completion
1105  *
1106  *  This function starts a flash cycle and waits for its completion.
1107  **/
1108 static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
1109 {
1110         union ich8_hws_flash_ctrl hsflctl;
1111         union ich8_hws_flash_status hsfsts;
1112         s32 ret_val = -E1000_ERR_NVM;
1113         u32 i = 0;
1114
1115         /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
1116         hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1117         hsflctl.hsf_ctrl.flcgo = 1;
1118         ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1119
1120         /* wait till FDONE bit is set to 1 */
1121         do {
1122                 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1123                 if (hsfsts.hsf_status.flcdone == 1)
1124                         break;
1125                 udelay(1);
1126         } while (i++ < timeout);
1127
1128         if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
1129                 return 0;
1130
1131         return ret_val;
1132 }
1133
1134 /**
1135  *  e1000_read_flash_word_ich8lan - Read word from flash
1136  *  @hw: pointer to the HW structure
1137  *  @offset: offset to data location
1138  *  @data: pointer to the location for storing the data
1139  *
1140  *  Reads the flash word at offset into data.  Offset is converted
1141  *  to bytes before read.
1142  **/
1143 static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
1144                                          u16 *data)
1145 {
1146         /* Must convert offset into bytes. */
1147         offset <<= 1;
1148
1149         return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
1150 }
1151
1152 /**
1153  *  e1000_read_flash_byte_ich8lan - Read byte from flash
1154  *  @hw: pointer to the HW structure
1155  *  @offset: The offset of the byte to read.
1156  *  @data: Pointer to a byte to store the value read.
1157  *
1158  *  Reads a single byte from the NVM using the flash access registers.
1159  **/
1160 static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1161                                          u8 *data)
1162 {
1163         s32 ret_val;
1164         u16 word = 0;
1165
1166         ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
1167         if (ret_val)
1168                 return ret_val;
1169
1170         *data = (u8)word;
1171
1172         return 0;
1173 }
1174
1175 /**
1176  *  e1000_read_flash_data_ich8lan - Read byte or word from NVM
1177  *  @hw: pointer to the HW structure
1178  *  @offset: The offset (in bytes) of the byte or word to read.
1179  *  @size: Size of data to read, 1=byte 2=word
1180  *  @data: Pointer to the word to store the value read.
1181  *
1182  *  Reads a byte or word from the NVM using the flash access registers.
1183  **/
1184 static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1185                                          u8 size, u16 *data)
1186 {
1187         union ich8_hws_flash_status hsfsts;
1188         union ich8_hws_flash_ctrl hsflctl;
1189         u32 flash_linear_addr;
1190         u32 flash_data = 0;
1191         s32 ret_val = -E1000_ERR_NVM;
1192         u8 count = 0;
1193
1194         if (size < 1  || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
1195                 return -E1000_ERR_NVM;
1196
1197         flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1198                             hw->nvm.flash_base_addr;
1199
1200         do {
1201                 udelay(1);
1202                 /* Steps */
1203                 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1204                 if (ret_val != 0)
1205                         break;
1206
1207                 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1208                 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1209                 hsflctl.hsf_ctrl.fldbcount = size - 1;
1210                 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
1211                 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1212
1213                 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1214
1215                 ret_val = e1000_flash_cycle_ich8lan(hw,
1216                                                 ICH_FLASH_READ_COMMAND_TIMEOUT);
1217
1218                 /*
1219                  * Check if FCERR is set to 1, if set to 1, clear it
1220                  * and try the whole sequence a few more times, else
1221                  * read in (shift in) the Flash Data0, the order is
1222                  * least significant byte first msb to lsb
1223                  */
1224                 if (ret_val == 0) {
1225                         flash_data = er32flash(ICH_FLASH_FDATA0);
1226                         if (size == 1) {
1227                                 *data = (u8)(flash_data & 0x000000FF);
1228                         } else if (size == 2) {
1229                                 *data = (u16)(flash_data & 0x0000FFFF);
1230                         }
1231                         break;
1232                 } else {
1233                         /*
1234                          * If we've gotten here, then things are probably
1235                          * completely hosed, but if the error condition is
1236                          * detected, it won't hurt to give it another try...
1237                          * ICH_FLASH_CYCLE_REPEAT_COUNT times.
1238                          */
1239                         hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1240                         if (hsfsts.hsf_status.flcerr == 1) {
1241                                 /* Repeat for some time before giving up. */
1242                                 continue;
1243                         } else if (hsfsts.hsf_status.flcdone == 0) {
1244                                 hw_dbg(hw, "Timeout error - flash cycle "
1245                                          "did not complete.");
1246                                 break;
1247                         }
1248                 }
1249         } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1250
1251         return ret_val;
1252 }
1253
1254 /**
1255  *  e1000_write_nvm_ich8lan - Write word(s) to the NVM
1256  *  @hw: pointer to the HW structure
1257  *  @offset: The offset (in bytes) of the word(s) to write.
1258  *  @words: Size of data to write in words
1259  *  @data: Pointer to the word(s) to write at offset.
1260  *
1261  *  Writes a byte or word to the NVM using the flash access registers.
1262  **/
1263 static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1264                                    u16 *data)
1265 {
1266         struct e1000_nvm_info *nvm = &hw->nvm;
1267         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1268         s32 ret_val;
1269         u16 i;
1270
1271         if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1272             (words == 0)) {
1273                 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
1274                 return -E1000_ERR_NVM;
1275         }
1276
1277         ret_val = e1000_acquire_swflag_ich8lan(hw);
1278         if (ret_val)
1279                 return ret_val;
1280
1281         for (i = 0; i < words; i++) {
1282                 dev_spec->shadow_ram[offset+i].modified = 1;
1283                 dev_spec->shadow_ram[offset+i].value = data[i];
1284         }
1285
1286         e1000_release_swflag_ich8lan(hw);
1287
1288         return 0;
1289 }
1290
1291 /**
1292  *  e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
1293  *  @hw: pointer to the HW structure
1294  *
1295  *  The NVM checksum is updated by calling the generic update_nvm_checksum,
1296  *  which writes the checksum to the shadow ram.  The changes in the shadow
1297  *  ram are then committed to the EEPROM by processing each bank at a time
1298  *  checking for the modified bit and writing only the pending changes.
1299  *  After a successful commit, the shadow ram is cleared and is ready for
1300  *  future writes.
1301  **/
1302 static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1303 {
1304         struct e1000_nvm_info *nvm = &hw->nvm;
1305         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1306         u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
1307         s32 ret_val;
1308         u16 data;
1309
1310         ret_val = e1000e_update_nvm_checksum_generic(hw);
1311         if (ret_val)
1312                 return ret_val;
1313
1314         if (nvm->type != e1000_nvm_flash_sw)
1315                 return ret_val;
1316
1317         ret_val = e1000_acquire_swflag_ich8lan(hw);
1318         if (ret_val)
1319                 return ret_val;
1320
1321         /*
1322          * We're writing to the opposite bank so if we're on bank 1,
1323          * write to bank 0 etc.  We also need to erase the segment that
1324          * is going to be written
1325          */
1326         ret_val =  e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
1327         if (ret_val)
1328                 return ret_val;
1329
1330         if (bank == 0) {
1331                 new_bank_offset = nvm->flash_bank_size;
1332                 old_bank_offset = 0;
1333                 e1000_erase_flash_bank_ich8lan(hw, 1);
1334         } else {
1335                 old_bank_offset = nvm->flash_bank_size;
1336                 new_bank_offset = 0;
1337                 e1000_erase_flash_bank_ich8lan(hw, 0);
1338         }
1339
1340         for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
1341                 /*
1342                  * Determine whether to write the value stored
1343                  * in the other NVM bank or a modified value stored
1344                  * in the shadow RAM
1345                  */
1346                 if (dev_spec->shadow_ram[i].modified) {
1347                         data = dev_spec->shadow_ram[i].value;
1348                 } else {
1349                         e1000_read_flash_word_ich8lan(hw,
1350                                                       i + old_bank_offset,
1351                                                       &data);
1352                 }
1353
1354                 /*
1355                  * If the word is 0x13, then make sure the signature bits
1356                  * (15:14) are 11b until the commit has completed.
1357                  * This will allow us to write 10b which indicates the
1358                  * signature is valid.  We want to do this after the write
1359                  * has completed so that we don't mark the segment valid
1360                  * while the write is still in progress
1361                  */
1362                 if (i == E1000_ICH_NVM_SIG_WORD)
1363                         data |= E1000_ICH_NVM_SIG_MASK;
1364
1365                 /* Convert offset to bytes. */
1366                 act_offset = (i + new_bank_offset) << 1;
1367
1368                 udelay(100);
1369                 /* Write the bytes to the new bank. */
1370                 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1371                                                                act_offset,
1372                                                                (u8)data);
1373                 if (ret_val)
1374                         break;
1375
1376                 udelay(100);
1377                 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1378                                                           act_offset + 1,
1379                                                           (u8)(data >> 8));
1380                 if (ret_val)
1381                         break;
1382         }
1383
1384         /*
1385          * Don't bother writing the segment valid bits if sector
1386          * programming failed.
1387          */
1388         if (ret_val) {
1389                 hw_dbg(hw, "Flash commit failed.\n");
1390                 e1000_release_swflag_ich8lan(hw);
1391                 return ret_val;
1392         }
1393
1394         /*
1395          * Finally validate the new segment by setting bit 15:14
1396          * to 10b in word 0x13 , this can be done without an
1397          * erase as well since these bits are 11 to start with
1398          * and we need to change bit 14 to 0b
1399          */
1400         act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
1401         e1000_read_flash_word_ich8lan(hw, act_offset, &data);
1402         data &= 0xBFFF;
1403         ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1404                                                        act_offset * 2 + 1,
1405                                                        (u8)(data >> 8));
1406         if (ret_val) {
1407                 e1000_release_swflag_ich8lan(hw);
1408                 return ret_val;
1409         }
1410
1411         /*
1412          * And invalidate the previously valid segment by setting
1413          * its signature word (0x13) high_byte to 0b. This can be
1414          * done without an erase because flash erase sets all bits
1415          * to 1's. We can write 1's to 0's without an erase
1416          */
1417         act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
1418         ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
1419         if (ret_val) {
1420                 e1000_release_swflag_ich8lan(hw);
1421                 return ret_val;
1422         }
1423
1424         /* Great!  Everything worked, we can now clear the cached entries. */
1425         for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
1426                 dev_spec->shadow_ram[i].modified = 0;
1427                 dev_spec->shadow_ram[i].value = 0xFFFF;
1428         }
1429
1430         e1000_release_swflag_ich8lan(hw);
1431
1432         /*
1433          * Reload the EEPROM, or else modifications will not appear
1434          * until after the next adapter reset.
1435          */
1436         e1000e_reload_nvm(hw);
1437         msleep(10);
1438
1439         return ret_val;
1440 }
1441
1442 /**
1443  *  e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
1444  *  @hw: pointer to the HW structure
1445  *
1446  *  Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
1447  *  If the bit is 0, that the EEPROM had been modified, but the checksum was not
1448  *  calculated, in which case we need to calculate the checksum and set bit 6.
1449  **/
1450 static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
1451 {
1452         s32 ret_val;
1453         u16 data;
1454
1455         /*
1456          * Read 0x19 and check bit 6.  If this bit is 0, the checksum
1457          * needs to be fixed.  This bit is an indication that the NVM
1458          * was prepared by OEM software and did not calculate the
1459          * checksum...a likely scenario.
1460          */
1461         ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
1462         if (ret_val)
1463                 return ret_val;
1464
1465         if ((data & 0x40) == 0) {
1466                 data |= 0x40;
1467                 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
1468                 if (ret_val)
1469                         return ret_val;
1470                 ret_val = e1000e_update_nvm_checksum(hw);
1471                 if (ret_val)
1472                         return ret_val;
1473         }
1474
1475         return e1000e_validate_nvm_checksum_generic(hw);
1476 }
1477
1478 /**
1479  *  e1000_write_flash_data_ich8lan - Writes bytes to the NVM
1480  *  @hw: pointer to the HW structure
1481  *  @offset: The offset (in bytes) of the byte/word to read.
1482  *  @size: Size of data to read, 1=byte 2=word
1483  *  @data: The byte(s) to write to the NVM.
1484  *
1485  *  Writes one/two bytes to the NVM using the flash access registers.
1486  **/
1487 static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1488                                           u8 size, u16 data)
1489 {
1490         union ich8_hws_flash_status hsfsts;
1491         union ich8_hws_flash_ctrl hsflctl;
1492         u32 flash_linear_addr;
1493         u32 flash_data = 0;
1494         s32 ret_val;
1495         u8 count = 0;
1496
1497         if (size < 1 || size > 2 || data > size * 0xff ||
1498             offset > ICH_FLASH_LINEAR_ADDR_MASK)
1499                 return -E1000_ERR_NVM;
1500
1501         flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1502                             hw->nvm.flash_base_addr;
1503
1504         do {
1505                 udelay(1);
1506                 /* Steps */
1507                 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1508                 if (ret_val)
1509                         break;
1510
1511                 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1512                 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1513                 hsflctl.hsf_ctrl.fldbcount = size -1;
1514                 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
1515                 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1516
1517                 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1518
1519                 if (size == 1)
1520                         flash_data = (u32)data & 0x00FF;
1521                 else
1522                         flash_data = (u32)data;
1523
1524                 ew32flash(ICH_FLASH_FDATA0, flash_data);
1525
1526                 /*
1527                  * check if FCERR is set to 1 , if set to 1, clear it
1528                  * and try the whole sequence a few more times else done
1529                  */
1530                 ret_val = e1000_flash_cycle_ich8lan(hw,
1531                                                ICH_FLASH_WRITE_COMMAND_TIMEOUT);
1532                 if (!ret_val)
1533                         break;
1534
1535                 /*
1536                  * If we're here, then things are most likely
1537                  * completely hosed, but if the error condition
1538                  * is detected, it won't hurt to give it another
1539                  * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
1540                  */
1541                 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1542                 if (hsfsts.hsf_status.flcerr == 1)
1543                         /* Repeat for some time before giving up. */
1544                         continue;
1545                 if (hsfsts.hsf_status.flcdone == 0) {
1546                         hw_dbg(hw, "Timeout error - flash cycle "
1547                                  "did not complete.");
1548                         break;
1549                 }
1550         } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1551
1552         return ret_val;
1553 }
1554
1555 /**
1556  *  e1000_write_flash_byte_ich8lan - Write a single byte to NVM
1557  *  @hw: pointer to the HW structure
1558  *  @offset: The index of the byte to read.
1559  *  @data: The byte to write to the NVM.
1560  *
1561  *  Writes a single byte to the NVM using the flash access registers.
1562  **/
1563 static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1564                                           u8 data)
1565 {
1566         u16 word = (u16)data;
1567
1568         return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
1569 }
1570
1571 /**
1572  *  e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
1573  *  @hw: pointer to the HW structure
1574  *  @offset: The offset of the byte to write.
1575  *  @byte: The byte to write to the NVM.
1576  *
1577  *  Writes a single byte to the NVM using the flash access registers.
1578  *  Goes through a retry algorithm before giving up.
1579  **/
1580 static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
1581                                                 u32 offset, u8 byte)
1582 {
1583         s32 ret_val;
1584         u16 program_retries;
1585
1586         ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
1587         if (!ret_val)
1588                 return ret_val;
1589
1590         for (program_retries = 0; program_retries < 100; program_retries++) {
1591                 hw_dbg(hw, "Retrying Byte %2.2X at offset %u\n", byte, offset);
1592                 udelay(100);
1593                 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
1594                 if (!ret_val)
1595                         break;
1596         }
1597         if (program_retries == 100)
1598                 return -E1000_ERR_NVM;
1599
1600         return 0;
1601 }
1602
1603 /**
1604  *  e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
1605  *  @hw: pointer to the HW structure
1606  *  @bank: 0 for first bank, 1 for second bank, etc.
1607  *
1608  *  Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
1609  *  bank N is 4096 * N + flash_reg_addr.
1610  **/
1611 static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
1612 {
1613         struct e1000_nvm_info *nvm = &hw->nvm;
1614         union ich8_hws_flash_status hsfsts;
1615         union ich8_hws_flash_ctrl hsflctl;
1616         u32 flash_linear_addr;
1617         /* bank size is in 16bit words - adjust to bytes */
1618         u32 flash_bank_size = nvm->flash_bank_size * 2;
1619         s32 ret_val;
1620         s32 count = 0;
1621         s32 iteration;
1622         s32 sector_size;
1623         s32 j;
1624
1625         hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1626
1627         /*
1628          * Determine HW Sector size: Read BERASE bits of hw flash status
1629          * register
1630          * 00: The Hw sector is 256 bytes, hence we need to erase 16
1631          *     consecutive sectors.  The start index for the nth Hw sector
1632          *     can be calculated as = bank * 4096 + n * 256
1633          * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
1634          *     The start index for the nth Hw sector can be calculated
1635          *     as = bank * 4096
1636          * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
1637          *     (ich9 only, otherwise error condition)
1638          * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
1639          */
1640         switch (hsfsts.hsf_status.berasesz) {
1641         case 0:
1642                 /* Hw sector size 256 */
1643                 sector_size = ICH_FLASH_SEG_SIZE_256;
1644                 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
1645                 break;
1646         case 1:
1647                 sector_size = ICH_FLASH_SEG_SIZE_4K;
1648                 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_4K;
1649                 break;
1650         case 2:
1651                 if (hw->mac.type == e1000_ich9lan) {
1652                         sector_size = ICH_FLASH_SEG_SIZE_8K;
1653                         iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_8K;
1654                 } else {
1655                         return -E1000_ERR_NVM;
1656                 }
1657                 break;
1658         case 3:
1659                 sector_size = ICH_FLASH_SEG_SIZE_64K;
1660                 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_64K;
1661                 break;
1662         default:
1663                 return -E1000_ERR_NVM;
1664         }
1665
1666         /* Start with the base address, then add the sector offset. */
1667         flash_linear_addr = hw->nvm.flash_base_addr;
1668         flash_linear_addr += (bank) ? (sector_size * iteration) : 0;
1669
1670         for (j = 0; j < iteration ; j++) {
1671                 do {
1672                         /* Steps */
1673                         ret_val = e1000_flash_cycle_init_ich8lan(hw);
1674                         if (ret_val)
1675                                 return ret_val;
1676
1677                         /*
1678                          * Write a value 11 (block Erase) in Flash
1679                          * Cycle field in hw flash control
1680                          */
1681                         hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1682                         hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
1683                         ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1684
1685                         /*
1686                          * Write the last 24 bits of an index within the
1687                          * block into Flash Linear address field in Flash
1688                          * Address.
1689                          */
1690                         flash_linear_addr += (j * sector_size);
1691                         ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1692
1693                         ret_val = e1000_flash_cycle_ich8lan(hw,
1694                                                ICH_FLASH_ERASE_COMMAND_TIMEOUT);
1695                         if (ret_val == 0)
1696                                 break;
1697
1698                         /*
1699                          * Check if FCERR is set to 1.  If 1,
1700                          * clear it and try the whole sequence
1701                          * a few more times else Done
1702                          */
1703                         hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1704                         if (hsfsts.hsf_status.flcerr == 1)
1705                                 /* repeat for some time before giving up */
1706                                 continue;
1707                         else if (hsfsts.hsf_status.flcdone == 0)
1708                                 return ret_val;
1709                 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
1710         }
1711
1712         return 0;
1713 }
1714
1715 /**
1716  *  e1000_valid_led_default_ich8lan - Set the default LED settings
1717  *  @hw: pointer to the HW structure
1718  *  @data: Pointer to the LED settings
1719  *
1720  *  Reads the LED default settings from the NVM to data.  If the NVM LED
1721  *  settings is all 0's or F's, set the LED default to a valid LED default
1722  *  setting.
1723  **/
1724 static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
1725 {
1726         s32 ret_val;
1727
1728         ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
1729         if (ret_val) {
1730                 hw_dbg(hw, "NVM Read Error\n");
1731                 return ret_val;
1732         }
1733
1734         if (*data == ID_LED_RESERVED_0000 ||
1735             *data == ID_LED_RESERVED_FFFF)
1736                 *data = ID_LED_DEFAULT_ICH8LAN;
1737
1738         return 0;
1739 }
1740
1741 /**
1742  *  e1000_get_bus_info_ich8lan - Get/Set the bus type and width
1743  *  @hw: pointer to the HW structure
1744  *
1745  *  ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
1746  *  register, so the the bus width is hard coded.
1747  **/
1748 static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
1749 {
1750         struct e1000_bus_info *bus = &hw->bus;
1751         s32 ret_val;
1752
1753         ret_val = e1000e_get_bus_info_pcie(hw);
1754
1755         /*
1756          * ICH devices are "PCI Express"-ish.  They have
1757          * a configuration space, but do not contain
1758          * PCI Express Capability registers, so bus width
1759          * must be hardcoded.
1760          */
1761         if (bus->width == e1000_bus_width_unknown)
1762                 bus->width = e1000_bus_width_pcie_x1;
1763
1764         return ret_val;
1765 }
1766
1767 /**
1768  *  e1000_reset_hw_ich8lan - Reset the hardware
1769  *  @hw: pointer to the HW structure
1770  *
1771  *  Does a full reset of the hardware which includes a reset of the PHY and
1772  *  MAC.
1773  **/
1774 static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
1775 {
1776         u32 ctrl, icr, kab;
1777         s32 ret_val;
1778
1779         /*
1780          * Prevent the PCI-E bus from sticking if there is no TLP connection
1781          * on the last TLP read/write transaction when MAC is reset.
1782          */
1783         ret_val = e1000e_disable_pcie_master(hw);
1784         if (ret_val) {
1785                 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
1786         }
1787
1788         hw_dbg(hw, "Masking off all interrupts\n");
1789         ew32(IMC, 0xffffffff);
1790
1791         /*
1792          * Disable the Transmit and Receive units.  Then delay to allow
1793          * any pending transactions to complete before we hit the MAC
1794          * with the global reset.
1795          */
1796         ew32(RCTL, 0);
1797         ew32(TCTL, E1000_TCTL_PSP);
1798         e1e_flush();
1799
1800         msleep(10);
1801
1802         /* Workaround for ICH8 bit corruption issue in FIFO memory */
1803         if (hw->mac.type == e1000_ich8lan) {
1804                 /* Set Tx and Rx buffer allocation to 8k apiece. */
1805                 ew32(PBA, E1000_PBA_8K);
1806                 /* Set Packet Buffer Size to 16k. */
1807                 ew32(PBS, E1000_PBS_16K);
1808         }
1809
1810         ctrl = er32(CTRL);
1811
1812         if (!e1000_check_reset_block(hw)) {
1813                 /*
1814                  * PHY HW reset requires MAC CORE reset at the same
1815                  * time to make sure the interface between MAC and the
1816                  * external PHY is reset.
1817                  */
1818                 ctrl |= E1000_CTRL_PHY_RST;
1819         }
1820         ret_val = e1000_acquire_swflag_ich8lan(hw);
1821         hw_dbg(hw, "Issuing a global reset to ich8lan");
1822         ew32(CTRL, (ctrl | E1000_CTRL_RST));
1823         msleep(20);
1824
1825         ret_val = e1000e_get_auto_rd_done(hw);
1826         if (ret_val) {
1827                 /*
1828                  * When auto config read does not complete, do not
1829                  * return with an error. This can happen in situations
1830                  * where there is no eeprom and prevents getting link.
1831                  */
1832                 hw_dbg(hw, "Auto Read Done did not complete\n");
1833         }
1834
1835         ew32(IMC, 0xffffffff);
1836         icr = er32(ICR);
1837
1838         kab = er32(KABGTXD);
1839         kab |= E1000_KABGTXD_BGSQLBIAS;
1840         ew32(KABGTXD, kab);
1841
1842         return ret_val;
1843 }
1844
1845 /**
1846  *  e1000_init_hw_ich8lan - Initialize the hardware
1847  *  @hw: pointer to the HW structure
1848  *
1849  *  Prepares the hardware for transmit and receive by doing the following:
1850  *   - initialize hardware bits
1851  *   - initialize LED identification
1852  *   - setup receive address registers
1853  *   - setup flow control
1854  *   - setup transmit descriptors
1855  *   - clear statistics
1856  **/
1857 static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
1858 {
1859         struct e1000_mac_info *mac = &hw->mac;
1860         u32 ctrl_ext, txdctl, snoop;
1861         s32 ret_val;
1862         u16 i;
1863
1864         e1000_initialize_hw_bits_ich8lan(hw);
1865
1866         /* Initialize identification LED */
1867         ret_val = e1000e_id_led_init(hw);
1868         if (ret_val) {
1869                 hw_dbg(hw, "Error initializing identification LED\n");
1870                 return ret_val;
1871         }
1872
1873         /* Setup the receive address. */
1874         e1000e_init_rx_addrs(hw, mac->rar_entry_count);
1875
1876         /* Zero out the Multicast HASH table */
1877         hw_dbg(hw, "Zeroing the MTA\n");
1878         for (i = 0; i < mac->mta_reg_count; i++)
1879                 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
1880
1881         /* Setup link and flow control */
1882         ret_val = e1000_setup_link_ich8lan(hw);
1883
1884         /* Set the transmit descriptor write-back policy for both queues */
1885         txdctl = er32(TXDCTL(0));
1886         txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
1887                  E1000_TXDCTL_FULL_TX_DESC_WB;
1888         txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
1889                  E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
1890         ew32(TXDCTL(0), txdctl);
1891         txdctl = er32(TXDCTL(1));
1892         txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
1893                  E1000_TXDCTL_FULL_TX_DESC_WB;
1894         txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
1895                  E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
1896         ew32(TXDCTL(1), txdctl);
1897
1898         /*
1899          * ICH8 has opposite polarity of no_snoop bits.
1900          * By default, we should use snoop behavior.
1901          */
1902         if (mac->type == e1000_ich8lan)
1903                 snoop = PCIE_ICH8_SNOOP_ALL;
1904         else
1905                 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
1906         e1000e_set_pcie_no_snoop(hw, snoop);
1907
1908         ctrl_ext = er32(CTRL_EXT);
1909         ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1910         ew32(CTRL_EXT, ctrl_ext);
1911
1912         /*
1913          * Clear all of the statistics registers (clear on read).  It is
1914          * important that we do this after we have tried to establish link
1915          * because the symbol error count will increment wildly if there
1916          * is no link.
1917          */
1918         e1000_clear_hw_cntrs_ich8lan(hw);
1919
1920         return 0;
1921 }
1922 /**
1923  *  e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
1924  *  @hw: pointer to the HW structure
1925  *
1926  *  Sets/Clears required hardware bits necessary for correctly setting up the
1927  *  hardware for transmit and receive.
1928  **/
1929 static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
1930 {
1931         u32 reg;
1932
1933         /* Extended Device Control */
1934         reg = er32(CTRL_EXT);
1935         reg |= (1 << 22);
1936         ew32(CTRL_EXT, reg);
1937
1938         /* Transmit Descriptor Control 0 */
1939         reg = er32(TXDCTL(0));
1940         reg |= (1 << 22);
1941         ew32(TXDCTL(0), reg);
1942
1943         /* Transmit Descriptor Control 1 */
1944         reg = er32(TXDCTL(1));
1945         reg |= (1 << 22);
1946         ew32(TXDCTL(1), reg);
1947
1948         /* Transmit Arbitration Control 0 */
1949         reg = er32(TARC(0));
1950         if (hw->mac.type == e1000_ich8lan)
1951                 reg |= (1 << 28) | (1 << 29);
1952         reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
1953         ew32(TARC(0), reg);
1954
1955         /* Transmit Arbitration Control 1 */
1956         reg = er32(TARC(1));
1957         if (er32(TCTL) & E1000_TCTL_MULR)
1958                 reg &= ~(1 << 28);
1959         else
1960                 reg |= (1 << 28);
1961         reg |= (1 << 24) | (1 << 26) | (1 << 30);
1962         ew32(TARC(1), reg);
1963
1964         /* Device Status */
1965         if (hw->mac.type == e1000_ich8lan) {
1966                 reg = er32(STATUS);
1967                 reg &= ~(1 << 31);
1968                 ew32(STATUS, reg);
1969         }
1970 }
1971
1972 /**
1973  *  e1000_setup_link_ich8lan - Setup flow control and link settings
1974  *  @hw: pointer to the HW structure
1975  *
1976  *  Determines which flow control settings to use, then configures flow
1977  *  control.  Calls the appropriate media-specific link configuration
1978  *  function.  Assuming the adapter has a valid link partner, a valid link
1979  *  should be established.  Assumes the hardware has previously been reset
1980  *  and the transmitter and receiver are not enabled.
1981  **/
1982 static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
1983 {
1984         s32 ret_val;
1985
1986         if (e1000_check_reset_block(hw))
1987                 return 0;
1988
1989         /*
1990          * ICH parts do not have a word in the NVM to determine
1991          * the default flow control setting, so we explicitly
1992          * set it to full.
1993          */
1994         if (hw->fc.type == e1000_fc_default)
1995                 hw->fc.type = e1000_fc_full;
1996
1997         hw->fc.original_type = hw->fc.type;
1998
1999         hw_dbg(hw, "After fix-ups FlowControl is now = %x\n", hw->fc.type);
2000
2001         /* Continue to configure the copper link. */
2002         ret_val = e1000_setup_copper_link_ich8lan(hw);
2003         if (ret_val)
2004                 return ret_val;
2005
2006         ew32(FCTTV, hw->fc.pause_time);
2007
2008         return e1000e_set_fc_watermarks(hw);
2009 }
2010
2011 /**
2012  *  e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
2013  *  @hw: pointer to the HW structure
2014  *
2015  *  Configures the kumeran interface to the PHY to wait the appropriate time
2016  *  when polling the PHY, then call the generic setup_copper_link to finish
2017  *  configuring the copper link.
2018  **/
2019 static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
2020 {
2021         u32 ctrl;
2022         s32 ret_val;
2023         u16 reg_data;
2024
2025         ctrl = er32(CTRL);
2026         ctrl |= E1000_CTRL_SLU;
2027         ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2028         ew32(CTRL, ctrl);
2029
2030         /*
2031          * Set the mac to wait the maximum time between each iteration
2032          * and increase the max iterations when polling the phy;
2033          * this fixes erroneous timeouts at 10Mbps.
2034          */
2035         ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
2036         if (ret_val)
2037                 return ret_val;
2038         ret_val = e1000e_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
2039         if (ret_val)
2040                 return ret_val;
2041         reg_data |= 0x3F;
2042         ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
2043         if (ret_val)
2044                 return ret_val;
2045
2046         if (hw->phy.type == e1000_phy_igp_3) {
2047                 ret_val = e1000e_copper_link_setup_igp(hw);
2048                 if (ret_val)
2049                         return ret_val;
2050         } else if (hw->phy.type == e1000_phy_bm) {
2051                 ret_val = e1000e_copper_link_setup_m88(hw);
2052                 if (ret_val)
2053                         return ret_val;
2054         }
2055
2056         if (hw->phy.type == e1000_phy_ife) {
2057                 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
2058                 if (ret_val)
2059                         return ret_val;
2060
2061                 reg_data &= ~IFE_PMC_AUTO_MDIX;
2062
2063                 switch (hw->phy.mdix) {
2064                 case 1:
2065                         reg_data &= ~IFE_PMC_FORCE_MDIX;
2066                         break;
2067                 case 2:
2068                         reg_data |= IFE_PMC_FORCE_MDIX;
2069                         break;
2070                 case 0:
2071                 default:
2072                         reg_data |= IFE_PMC_AUTO_MDIX;
2073                         break;
2074                 }
2075                 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
2076                 if (ret_val)
2077                         return ret_val;
2078         }
2079         return e1000e_setup_copper_link(hw);
2080 }
2081
2082 /**
2083  *  e1000_get_link_up_info_ich8lan - Get current link speed and duplex
2084  *  @hw: pointer to the HW structure
2085  *  @speed: pointer to store current link speed
2086  *  @duplex: pointer to store the current link duplex
2087  *
2088  *  Calls the generic get_speed_and_duplex to retrieve the current link
2089  *  information and then calls the Kumeran lock loss workaround for links at
2090  *  gigabit speeds.
2091  **/
2092 static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
2093                                           u16 *duplex)
2094 {
2095         s32 ret_val;
2096
2097         ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
2098         if (ret_val)
2099                 return ret_val;
2100
2101         if ((hw->mac.type == e1000_ich8lan) &&
2102             (hw->phy.type == e1000_phy_igp_3) &&
2103             (*speed == SPEED_1000)) {
2104                 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
2105         }
2106
2107         return ret_val;
2108 }
2109
2110 /**
2111  *  e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
2112  *  @hw: pointer to the HW structure
2113  *
2114  *  Work-around for 82566 Kumeran PCS lock loss:
2115  *  On link status change (i.e. PCI reset, speed change) and link is up and
2116  *  speed is gigabit-
2117  *    0) if workaround is optionally disabled do nothing
2118  *    1) wait 1ms for Kumeran link to come up
2119  *    2) check Kumeran Diagnostic register PCS lock loss bit
2120  *    3) if not set the link is locked (all is good), otherwise...
2121  *    4) reset the PHY
2122  *    5) repeat up to 10 times
2123  *  Note: this is only called for IGP3 copper when speed is 1gb.
2124  **/
2125 static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
2126 {
2127         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2128         u32 phy_ctrl;
2129         s32 ret_val;
2130         u16 i, data;
2131         bool link;
2132
2133         if (!dev_spec->kmrn_lock_loss_workaround_enabled)
2134                 return 0;
2135
2136         /*
2137          * Make sure link is up before proceeding.  If not just return.
2138          * Attempting this while link is negotiating fouled up link
2139          * stability
2140          */
2141         ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2142         if (!link)
2143                 return 0;
2144
2145         for (i = 0; i < 10; i++) {
2146                 /* read once to clear */
2147                 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
2148                 if (ret_val)
2149                         return ret_val;
2150                 /* and again to get new status */
2151                 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
2152                 if (ret_val)
2153                         return ret_val;
2154
2155                 /* check for PCS lock */
2156                 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
2157                         return 0;
2158
2159                 /* Issue PHY reset */
2160                 e1000_phy_hw_reset(hw);
2161                 mdelay(5);
2162         }
2163         /* Disable GigE link negotiation */
2164         phy_ctrl = er32(PHY_CTRL);
2165         phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
2166                      E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
2167         ew32(PHY_CTRL, phy_ctrl);
2168
2169         /*
2170          * Call gig speed drop workaround on Gig disable before accessing
2171          * any PHY registers
2172          */
2173         e1000e_gig_downshift_workaround_ich8lan(hw);
2174
2175         /* unable to acquire PCS lock */
2176         return -E1000_ERR_PHY;
2177 }
2178
2179 /**
2180  *  e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
2181  *  @hw: pointer to the HW structure
2182  *  @state: boolean value used to set the current Kumeran workaround state
2183  *
2184  *  If ICH8, set the current Kumeran workaround state (enabled - TRUE
2185  *  /disabled - FALSE).
2186  **/
2187 void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
2188                                                  bool state)
2189 {
2190         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2191
2192         if (hw->mac.type != e1000_ich8lan) {
2193                 hw_dbg(hw, "Workaround applies to ICH8 only.\n");
2194                 return;
2195         }
2196
2197         dev_spec->kmrn_lock_loss_workaround_enabled = state;
2198 }
2199
2200 /**
2201  *  e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
2202  *  @hw: pointer to the HW structure
2203  *
2204  *  Workaround for 82566 power-down on D3 entry:
2205  *    1) disable gigabit link
2206  *    2) write VR power-down enable
2207  *    3) read it back
2208  *  Continue if successful, else issue LCD reset and repeat
2209  **/
2210 void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
2211 {
2212         u32 reg;
2213         u16 data;
2214         u8  retry = 0;
2215
2216         if (hw->phy.type != e1000_phy_igp_3)
2217                 return;
2218
2219         /* Try the workaround twice (if needed) */
2220         do {
2221                 /* Disable link */
2222                 reg = er32(PHY_CTRL);
2223                 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
2224                         E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
2225                 ew32(PHY_CTRL, reg);
2226
2227                 /*
2228                  * Call gig speed drop workaround on Gig disable before
2229                  * accessing any PHY registers
2230                  */
2231                 if (hw->mac.type == e1000_ich8lan)
2232                         e1000e_gig_downshift_workaround_ich8lan(hw);
2233
2234                 /* Write VR power-down enable */
2235                 e1e_rphy(hw, IGP3_VR_CTRL, &data);
2236                 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
2237                 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
2238
2239                 /* Read it back and test */
2240                 e1e_rphy(hw, IGP3_VR_CTRL, &data);
2241                 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
2242                 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
2243                         break;
2244
2245                 /* Issue PHY reset and repeat at most one more time */
2246                 reg = er32(CTRL);
2247                 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
2248                 retry++;
2249         } while (retry);
2250 }
2251
2252 /**
2253  *  e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
2254  *  @hw: pointer to the HW structure
2255  *
2256  *  Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
2257  *  LPLU, Gig disable, MDIC PHY reset):
2258  *    1) Set Kumeran Near-end loopback
2259  *    2) Clear Kumeran Near-end loopback
2260  *  Should only be called for ICH8[m] devices with IGP_3 Phy.
2261  **/
2262 void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
2263 {
2264         s32 ret_val;
2265         u16 reg_data;
2266
2267         if ((hw->mac.type != e1000_ich8lan) ||
2268             (hw->phy.type != e1000_phy_igp_3))
2269                 return;
2270
2271         ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2272                                       &reg_data);
2273         if (ret_val)
2274                 return;
2275         reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
2276         ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2277                                        reg_data);
2278         if (ret_val)
2279                 return;
2280         reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
2281         ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2282                                        reg_data);
2283 }
2284
2285 /**
2286  *  e1000e_disable_gig_wol_ich8lan - disable gig during WoL
2287  *  @hw: pointer to the HW structure
2288  *
2289  *  During S0 to Sx transition, it is possible the link remains at gig
2290  *  instead of negotiating to a lower speed.  Before going to Sx, set
2291  *  'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
2292  *  to a lower speed.
2293  *
2294  *  Should only be called for ICH9 and ICH10 devices.
2295  **/
2296 void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
2297 {
2298         u32 phy_ctrl;
2299
2300         if ((hw->mac.type == e1000_ich10lan) ||
2301             (hw->mac.type == e1000_ich9lan)) {
2302                 phy_ctrl = er32(PHY_CTRL);
2303                 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
2304                             E1000_PHY_CTRL_GBE_DISABLE;
2305                 ew32(PHY_CTRL, phy_ctrl);
2306         }
2307
2308         return;
2309 }
2310
2311 /**
2312  *  e1000_cleanup_led_ich8lan - Restore the default LED operation
2313  *  @hw: pointer to the HW structure
2314  *
2315  *  Return the LED back to the default configuration.
2316  **/
2317 static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
2318 {
2319         if (hw->phy.type == e1000_phy_ife)
2320                 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
2321
2322         ew32(LEDCTL, hw->mac.ledctl_default);
2323         return 0;
2324 }
2325
2326 /**
2327  *  e1000_led_on_ich8lan - Turn LEDs on
2328  *  @hw: pointer to the HW structure
2329  *
2330  *  Turn on the LEDs.
2331  **/
2332 static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
2333 {
2334         if (hw->phy.type == e1000_phy_ife)
2335                 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
2336                                 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
2337
2338         ew32(LEDCTL, hw->mac.ledctl_mode2);
2339         return 0;
2340 }
2341
2342 /**
2343  *  e1000_led_off_ich8lan - Turn LEDs off
2344  *  @hw: pointer to the HW structure
2345  *
2346  *  Turn off the LEDs.
2347  **/
2348 static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
2349 {
2350         if (hw->phy.type == e1000_phy_ife)
2351                 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
2352                                (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
2353
2354         ew32(LEDCTL, hw->mac.ledctl_mode1);
2355         return 0;
2356 }
2357
2358 /**
2359  *  e1000_get_cfg_done_ich8lan - Read config done bit
2360  *  @hw: pointer to the HW structure
2361  *
2362  *  Read the management control register for the config done bit for
2363  *  completion status.  NOTE: silicon which is EEPROM-less will fail trying
2364  *  to read the config done bit, so an error is *ONLY* logged and returns
2365  *  E1000_SUCCESS.  If we were to return with error, EEPROM-less silicon
2366  *  would not be able to be reset or change link.
2367  **/
2368 static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
2369 {
2370         u32 bank = 0;
2371
2372         e1000e_get_cfg_done(hw);
2373
2374         /* If EEPROM is not marked present, init the IGP 3 PHY manually */
2375         if (hw->mac.type != e1000_ich10lan) {
2376                 if (((er32(EECD) & E1000_EECD_PRES) == 0) &&
2377                     (hw->phy.type == e1000_phy_igp_3)) {
2378                         e1000e_phy_init_script_igp3(hw);
2379                 }
2380         } else {
2381                 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
2382                         /* Maybe we should do a basic PHY config */
2383                         hw_dbg(hw, "EEPROM not present\n");
2384                         return -E1000_ERR_CONFIG;
2385                 }
2386         }
2387
2388         return 0;
2389 }
2390
2391 /**
2392  *  e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
2393  *  @hw: pointer to the HW structure
2394  *
2395  *  Clears hardware counters specific to the silicon family and calls
2396  *  clear_hw_cntrs_generic to clear all general purpose counters.
2397  **/
2398 static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
2399 {
2400         u32 temp;
2401
2402         e1000e_clear_hw_cntrs_base(hw);
2403
2404         temp = er32(ALGNERRC);
2405         temp = er32(RXERRC);
2406         temp = er32(TNCRS);
2407         temp = er32(CEXTERR);
2408         temp = er32(TSCTC);
2409         temp = er32(TSCTFC);
2410
2411         temp = er32(MGTPRC);
2412         temp = er32(MGTPDC);
2413         temp = er32(MGTPTC);
2414
2415         temp = er32(IAC);
2416         temp = er32(ICRXOC);
2417
2418 }
2419
2420 static struct e1000_mac_operations ich8_mac_ops = {
2421         .check_mng_mode         = e1000_check_mng_mode_ich8lan,
2422         .check_for_link         = e1000e_check_for_copper_link,
2423         .cleanup_led            = e1000_cleanup_led_ich8lan,
2424         .clear_hw_cntrs         = e1000_clear_hw_cntrs_ich8lan,
2425         .get_bus_info           = e1000_get_bus_info_ich8lan,
2426         .get_link_up_info       = e1000_get_link_up_info_ich8lan,
2427         .led_on                 = e1000_led_on_ich8lan,
2428         .led_off                = e1000_led_off_ich8lan,
2429         .update_mc_addr_list    = e1000e_update_mc_addr_list_generic,
2430         .reset_hw               = e1000_reset_hw_ich8lan,
2431         .init_hw                = e1000_init_hw_ich8lan,
2432         .setup_link             = e1000_setup_link_ich8lan,
2433         .setup_physical_interface= e1000_setup_copper_link_ich8lan,
2434 };
2435
2436 static struct e1000_phy_operations ich8_phy_ops = {
2437         .acquire_phy            = e1000_acquire_swflag_ich8lan,
2438         .check_reset_block      = e1000_check_reset_block_ich8lan,
2439         .commit_phy             = NULL,
2440         .force_speed_duplex     = e1000_phy_force_speed_duplex_ich8lan,
2441         .get_cfg_done           = e1000_get_cfg_done_ich8lan,
2442         .get_cable_length       = e1000e_get_cable_length_igp_2,
2443         .get_phy_info           = e1000_get_phy_info_ich8lan,
2444         .read_phy_reg           = e1000e_read_phy_reg_igp,
2445         .release_phy            = e1000_release_swflag_ich8lan,
2446         .reset_phy              = e1000_phy_hw_reset_ich8lan,
2447         .set_d0_lplu_state      = e1000_set_d0_lplu_state_ich8lan,
2448         .set_d3_lplu_state      = e1000_set_d3_lplu_state_ich8lan,
2449         .write_phy_reg          = e1000e_write_phy_reg_igp,
2450 };
2451
2452 static struct e1000_nvm_operations ich8_nvm_ops = {
2453         .acquire_nvm            = e1000_acquire_swflag_ich8lan,
2454         .read_nvm               = e1000_read_nvm_ich8lan,
2455         .release_nvm            = e1000_release_swflag_ich8lan,
2456         .update_nvm             = e1000_update_nvm_checksum_ich8lan,
2457         .valid_led_default      = e1000_valid_led_default_ich8lan,
2458         .validate_nvm           = e1000_validate_nvm_checksum_ich8lan,
2459         .write_nvm              = e1000_write_nvm_ich8lan,
2460 };
2461
2462 struct e1000_info e1000_ich8_info = {
2463         .mac                    = e1000_ich8lan,
2464         .flags                  = FLAG_HAS_WOL
2465                                   | FLAG_IS_ICH
2466                                   | FLAG_RX_CSUM_ENABLED
2467                                   | FLAG_HAS_CTRLEXT_ON_LOAD
2468                                   | FLAG_HAS_AMT
2469                                   | FLAG_HAS_FLASH
2470                                   | FLAG_APME_IN_WUC,
2471         .pba                    = 8,
2472         .get_variants           = e1000_get_variants_ich8lan,
2473         .mac_ops                = &ich8_mac_ops,
2474         .phy_ops                = &ich8_phy_ops,
2475         .nvm_ops                = &ich8_nvm_ops,
2476 };
2477
2478 struct e1000_info e1000_ich9_info = {
2479         .mac                    = e1000_ich9lan,
2480         .flags                  = FLAG_HAS_JUMBO_FRAMES
2481                                   | FLAG_IS_ICH
2482                                   | FLAG_HAS_WOL
2483                                   | FLAG_RX_CSUM_ENABLED
2484                                   | FLAG_HAS_CTRLEXT_ON_LOAD
2485                                   | FLAG_HAS_AMT
2486                                   | FLAG_HAS_ERT
2487                                   | FLAG_HAS_FLASH
2488                                   | FLAG_APME_IN_WUC,
2489         .pba                    = 10,
2490         .get_variants           = e1000_get_variants_ich8lan,
2491         .mac_ops                = &ich8_mac_ops,
2492         .phy_ops                = &ich8_phy_ops,
2493         .nvm_ops                = &ich8_nvm_ops,
2494 };
2495
2496 struct e1000_info e1000_ich10_info = {
2497         .mac                    = e1000_ich10lan,
2498         .flags                  = FLAG_HAS_JUMBO_FRAMES
2499                                   | FLAG_IS_ICH
2500                                   | FLAG_HAS_WOL
2501                                   | FLAG_RX_CSUM_ENABLED
2502                                   | FLAG_HAS_CTRLEXT_ON_LOAD
2503                                   | FLAG_HAS_AMT
2504                                   | FLAG_HAS_ERT
2505                                   | FLAG_HAS_FLASH
2506                                   | FLAG_APME_IN_WUC,
2507         .pba                    = 10,
2508         .get_variants           = e1000_get_variants_ich8lan,
2509         .mac_ops                = &ich8_mac_ops,
2510         .phy_ops                = &ich8_phy_ops,
2511         .nvm_ops                = &ich8_nvm_ops,
2512 };