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