blob: aaaaf2ca4084fdf1f88de5580209056ea7f5c408 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanad680762008-03-28 09:15:03 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
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/*
Bruce Allan16059272008-11-21 16:51:06 -080030 * 82562G 10/100 Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070031 * 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
Bruce Allan97ac8ca2008-04-29 09:16:05 -070042 * 82567LM Gigabit Network Connection
43 * 82567LF Gigabit Network Connection
Bruce Allan16059272008-11-21 16:51:06 -080044 * 82567V Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070045 * 82567LM-2 Gigabit Network Connection
46 * 82567LF-2 Gigabit Network Connection
47 * 82567V-2 Gigabit Network Connection
Bruce Allanf4187b52008-08-26 18:36:50 -070048 * 82567LF-3 Gigabit Network Connection
49 * 82567LM-3 Gigabit Network Connection
Bruce Allan2f15f9d2008-08-26 18:36:36 -070050 * 82567LM-4 Gigabit Network Connection
Bruce Allana4f58f52009-06-02 11:29:18 +000051 * 82577LM Gigabit Network Connection
52 * 82577LC Gigabit Network Connection
53 * 82578DM Gigabit Network Connection
54 * 82578DC Gigabit Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070055 */
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
Bruce Allan4a770352008-10-01 17:18:35 -070069#define ICH_FLASH_PR0 0x0074
Auke Kokbc7f75f2007-09-17 12:30:59 -070070
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
Bruce Allane2434552008-11-21 17:02:41 -0800101#define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
102#define E1000_ICH_NVM_SIG_VALUE 0x80
Auke Kokbc7f75f2007-09-17 12:30:59 -0700103
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
Bruce Allana4f58f52009-06-02 11:29:18 +0000123#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
124
Bruce Allan53ac5a82009-10-26 11:23:06 +0000125#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
126
Bruce Allanfa2ce132009-10-26 11:23:25 +0000127/* OEM Bits Phy Register */
128#define HV_OEM_BITS PHY_REG(768, 25)
129#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
130#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
131
Auke Kokbc7f75f2007-09-17 12:30:59 -0700132/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
133/* Offset 04h HSFSTS */
134union ich8_hws_flash_status {
135 struct ich8_hsfsts {
136 u16 flcdone :1; /* bit 0 Flash Cycle Done */
137 u16 flcerr :1; /* bit 1 Flash Cycle Error */
138 u16 dael :1; /* bit 2 Direct Access error Log */
139 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
140 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
141 u16 reserved1 :2; /* bit 13:6 Reserved */
142 u16 reserved2 :6; /* bit 13:6 Reserved */
143 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
144 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
145 } hsf_status;
146 u16 regval;
147};
148
149/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
150/* Offset 06h FLCTL */
151union ich8_hws_flash_ctrl {
152 struct ich8_hsflctl {
153 u16 flcgo :1; /* 0 Flash Cycle Go */
154 u16 flcycle :2; /* 2:1 Flash Cycle */
155 u16 reserved :5; /* 7:3 Reserved */
156 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
157 u16 flockdn :6; /* 15:10 Reserved */
158 } hsf_ctrl;
159 u16 regval;
160};
161
162/* ICH Flash Region Access Permissions */
163union ich8_hws_flash_regacc {
164 struct ich8_flracc {
165 u32 grra :8; /* 0:7 GbE region Read Access */
166 u32 grwa :8; /* 8:15 GbE region Write Access */
167 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
168 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
169 } hsf_flregacc;
170 u16 regval;
171};
172
Bruce Allan4a770352008-10-01 17:18:35 -0700173/* ICH Flash Protected Region */
174union ich8_flash_protected_range {
175 struct ich8_pr {
176 u32 base:13; /* 0:12 Protected Range Base */
177 u32 reserved1:2; /* 13:14 Reserved */
178 u32 rpe:1; /* 15 Read Protection Enable */
179 u32 limit:13; /* 16:28 Protected Range Limit */
180 u32 reserved2:2; /* 29:30 Reserved */
181 u32 wpe:1; /* 31 Write Protection Enable */
182 } range;
183 u32 regval;
184};
185
Auke Kokbc7f75f2007-09-17 12:30:59 -0700186static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
187static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
188static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
189static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw);
190static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
191static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
192 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700193static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
194 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700195static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
196 u16 *data);
197static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
198 u8 size, u16 *data);
199static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
200static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700201static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000202static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
203static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
204static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
205static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
206static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
207static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
208static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
209static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000210static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700211
212static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
213{
214 return readw(hw->flash_address + reg);
215}
216
217static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
218{
219 return readl(hw->flash_address + reg);
220}
221
222static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
223{
224 writew(val, hw->flash_address + reg);
225}
226
227static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
228{
229 writel(val, hw->flash_address + reg);
230}
231
232#define er16flash(reg) __er16flash(hw, (reg))
233#define er32flash(reg) __er32flash(hw, (reg))
234#define ew16flash(reg,val) __ew16flash(hw, (reg), (val))
235#define ew32flash(reg,val) __ew32flash(hw, (reg), (val))
236
237/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000238 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
239 * @hw: pointer to the HW structure
240 *
241 * Initialize family-specific PHY parameters and function pointers.
242 **/
243static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
244{
245 struct e1000_phy_info *phy = &hw->phy;
246 s32 ret_val = 0;
247
248 phy->addr = 1;
249 phy->reset_delay_us = 100;
250
251 phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
252 phy->ops.read_phy_reg = e1000_read_phy_reg_hv;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000253 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
254 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000255 phy->ops.write_phy_reg = e1000_write_phy_reg_hv;
256 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
257
258 phy->id = e1000_phy_unknown;
259 e1000e_get_phy_id(hw);
260 phy->type = e1000e_get_phy_type_from_id(phy->id);
261
262 if (phy->type == e1000_phy_82577) {
263 phy->ops.check_polarity = e1000_check_polarity_82577;
264 phy->ops.force_speed_duplex =
265 e1000_phy_force_speed_duplex_82577;
266 phy->ops.get_cable_length = e1000_get_cable_length_82577;
267 phy->ops.get_phy_info = e1000_get_phy_info_82577;
268 phy->ops.commit_phy = e1000e_phy_sw_reset;
269 }
270
271 return ret_val;
272}
273
274/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700275 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
276 * @hw: pointer to the HW structure
277 *
278 * Initialize family-specific PHY parameters and function pointers.
279 **/
280static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
281{
282 struct e1000_phy_info *phy = &hw->phy;
283 s32 ret_val;
284 u16 i = 0;
285
286 phy->addr = 1;
287 phy->reset_delay_us = 100;
288
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700289 /*
290 * We may need to do this twice - once for IGP and if that fails,
291 * we'll set BM func pointers and try again
292 */
293 ret_val = e1000e_determine_phy_address(hw);
294 if (ret_val) {
295 hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
296 hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
297 ret_val = e1000e_determine_phy_address(hw);
298 if (ret_val)
299 return ret_val;
300 }
301
Auke Kokbc7f75f2007-09-17 12:30:59 -0700302 phy->id = 0;
303 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
304 (i++ < 100)) {
305 msleep(1);
306 ret_val = e1000e_get_phy_id(hw);
307 if (ret_val)
308 return ret_val;
309 }
310
311 /* Verify phy id */
312 switch (phy->id) {
313 case IGP03E1000_E_PHY_ID:
314 phy->type = e1000_phy_igp_3;
315 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
316 break;
317 case IFE_E_PHY_ID:
318 case IFE_PLUS_E_PHY_ID:
319 case IFE_C_E_PHY_ID:
320 phy->type = e1000_phy_ife;
321 phy->autoneg_mask = E1000_ALL_NOT_GIG;
322 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700323 case BME1000_E_PHY_ID:
324 phy->type = e1000_phy_bm;
325 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
326 hw->phy.ops.read_phy_reg = e1000e_read_phy_reg_bm;
327 hw->phy.ops.write_phy_reg = e1000e_write_phy_reg_bm;
328 hw->phy.ops.commit_phy = e1000e_phy_sw_reset;
329 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700330 default:
331 return -E1000_ERR_PHY;
332 break;
333 }
334
Bruce Allana4f58f52009-06-02 11:29:18 +0000335 phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
336
Auke Kokbc7f75f2007-09-17 12:30:59 -0700337 return 0;
338}
339
340/**
341 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
342 * @hw: pointer to the HW structure
343 *
344 * Initialize family-specific NVM parameters and function
345 * pointers.
346 **/
347static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
348{
349 struct e1000_nvm_info *nvm = &hw->nvm;
350 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000351 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700352 u16 i;
353
Bruce Allanad680762008-03-28 09:15:03 -0700354 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700355 if (!hw->flash_address) {
356 hw_dbg(hw, "ERROR: Flash registers not mapped\n");
357 return -E1000_ERR_CONFIG;
358 }
359
360 nvm->type = e1000_nvm_flash_sw;
361
362 gfpreg = er32flash(ICH_FLASH_GFPREG);
363
Bruce Allanad680762008-03-28 09:15:03 -0700364 /*
365 * sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700366 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700367 * the overall size.
368 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700369 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
370 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
371
372 /* flash_base_addr is byte-aligned */
373 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
374
Bruce Allanad680762008-03-28 09:15:03 -0700375 /*
376 * find total size of the NVM, then cut in half since the total
377 * size represents two separate NVM banks.
378 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700379 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
380 << FLASH_SECTOR_ADDR_SHIFT;
381 nvm->flash_bank_size /= 2;
382 /* Adjust to word count */
383 nvm->flash_bank_size /= sizeof(u16);
384
385 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
386
387 /* Clear shadow ram */
388 for (i = 0; i < nvm->word_size; i++) {
389 dev_spec->shadow_ram[i].modified = 0;
390 dev_spec->shadow_ram[i].value = 0xFFFF;
391 }
392
393 return 0;
394}
395
396/**
397 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
398 * @hw: pointer to the HW structure
399 *
400 * Initialize family-specific MAC parameters and function
401 * pointers.
402 **/
403static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
404{
405 struct e1000_hw *hw = &adapter->hw;
406 struct e1000_mac_info *mac = &hw->mac;
407
408 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700409 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700410
411 /* Set mta register count */
412 mac->mta_reg_count = 32;
413 /* Set rar entry count */
414 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
415 if (mac->type == e1000_ich8lan)
416 mac->rar_entry_count--;
417 /* Set if manageability features are enabled. */
418 mac->arc_subsystem_valid = 1;
419
Bruce Allana4f58f52009-06-02 11:29:18 +0000420 /* LED operations */
421 switch (mac->type) {
422 case e1000_ich8lan:
423 case e1000_ich9lan:
424 case e1000_ich10lan:
425 /* ID LED init */
426 mac->ops.id_led_init = e1000e_id_led_init;
427 /* setup LED */
428 mac->ops.setup_led = e1000e_setup_led_generic;
429 /* cleanup LED */
430 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
431 /* turn on/off LED */
432 mac->ops.led_on = e1000_led_on_ich8lan;
433 mac->ops.led_off = e1000_led_off_ich8lan;
434 break;
435 case e1000_pchlan:
436 /* ID LED init */
437 mac->ops.id_led_init = e1000_id_led_init_pchlan;
438 /* setup LED */
439 mac->ops.setup_led = e1000_setup_led_pchlan;
440 /* cleanup LED */
441 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
442 /* turn on/off LED */
443 mac->ops.led_on = e1000_led_on_pchlan;
444 mac->ops.led_off = e1000_led_off_pchlan;
445 break;
446 default:
447 break;
448 }
449
Auke Kokbc7f75f2007-09-17 12:30:59 -0700450 /* Enable PCS Lock-loss workaround for ICH8 */
451 if (mac->type == e1000_ich8lan)
452 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, 1);
453
454 return 0;
455}
456
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000457/**
458 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
459 * @hw: pointer to the HW structure
460 *
461 * Checks to see of the link status of the hardware has changed. If a
462 * change in link status has been detected, then we read the PHY registers
463 * to get the current speed/duplex if link exists.
464 **/
465static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
466{
467 struct e1000_mac_info *mac = &hw->mac;
468 s32 ret_val;
469 bool link;
470
471 /*
472 * We only want to go out to the PHY registers to see if Auto-Neg
473 * has completed and/or if our link status has changed. The
474 * get_link_status flag is set upon receiving a Link Status
475 * Change or Rx Sequence Error interrupt.
476 */
477 if (!mac->get_link_status) {
478 ret_val = 0;
479 goto out;
480 }
481
482 if (hw->mac.type == e1000_pchlan) {
483 ret_val = e1000e_write_kmrn_reg(hw,
484 E1000_KMRNCTRLSTA_K1_CONFIG,
485 E1000_KMRNCTRLSTA_K1_ENABLE);
486 if (ret_val)
487 goto out;
488 }
489
490 /*
491 * First we want to see if the MII Status Register reports
492 * link. If so, then we want to get the current speed/duplex
493 * of the PHY.
494 */
495 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
496 if (ret_val)
497 goto out;
498
499 if (!link)
500 goto out; /* No link detected */
501
502 mac->get_link_status = false;
503
504 if (hw->phy.type == e1000_phy_82578) {
505 ret_val = e1000_link_stall_workaround_hv(hw);
506 if (ret_val)
507 goto out;
508 }
509
510 /*
511 * Check if there was DownShift, must be checked
512 * immediately after link-up
513 */
514 e1000e_check_downshift(hw);
515
516 /*
517 * If we are forcing speed/duplex, then we simply return since
518 * we have already determined whether we have link or not.
519 */
520 if (!mac->autoneg) {
521 ret_val = -E1000_ERR_CONFIG;
522 goto out;
523 }
524
525 /*
526 * Auto-Neg is enabled. Auto Speed Detection takes care
527 * of MAC speed/duplex configuration. So we only need to
528 * configure Collision Distance in the MAC.
529 */
530 e1000e_config_collision_dist(hw);
531
532 /*
533 * Configure Flow Control now that Auto-Neg has completed.
534 * First, we need to restore the desired flow control
535 * settings because we may have had to re-autoneg with a
536 * different link partner.
537 */
538 ret_val = e1000e_config_fc_after_link_up(hw);
539 if (ret_val)
540 hw_dbg(hw, "Error configuring flow control\n");
541
542out:
543 return ret_val;
544}
545
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700546static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700547{
548 struct e1000_hw *hw = &adapter->hw;
549 s32 rc;
550
551 rc = e1000_init_mac_params_ich8lan(adapter);
552 if (rc)
553 return rc;
554
555 rc = e1000_init_nvm_params_ich8lan(hw);
556 if (rc)
557 return rc;
558
Bruce Allana4f58f52009-06-02 11:29:18 +0000559 if (hw->mac.type == e1000_pchlan)
560 rc = e1000_init_phy_params_pchlan(hw);
561 else
562 rc = e1000_init_phy_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700563 if (rc)
564 return rc;
565
Bruce Allan2adc55c2009-06-02 11:28:58 +0000566 if (adapter->hw.phy.type == e1000_phy_ife) {
567 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
568 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
569 }
570
Auke Kokbc7f75f2007-09-17 12:30:59 -0700571 if ((adapter->hw.mac.type == e1000_ich8lan) &&
572 (adapter->hw.phy.type == e1000_phy_igp_3))
573 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
574
575 return 0;
576}
577
Thomas Gleixner717d4382008-10-02 16:33:40 -0700578static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700579
Auke Kokbc7f75f2007-09-17 12:30:59 -0700580/**
Bruce Allanca15df52009-10-26 11:23:43 +0000581 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
582 * @hw: pointer to the HW structure
583 *
584 * Acquires the mutex for performing NVM operations.
585 **/
586static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
587{
588 mutex_lock(&nvm_mutex);
589
590 return 0;
591}
592
593/**
594 * e1000_release_nvm_ich8lan - Release NVM mutex
595 * @hw: pointer to the HW structure
596 *
597 * Releases the mutex used while performing NVM operations.
598 **/
599static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
600{
601 mutex_unlock(&nvm_mutex);
602
603 return;
604}
605
606static DEFINE_MUTEX(swflag_mutex);
607
608/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700609 * e1000_acquire_swflag_ich8lan - Acquire software control flag
610 * @hw: pointer to the HW structure
611 *
Bruce Allanca15df52009-10-26 11:23:43 +0000612 * Acquires the software control flag for performing PHY and select
613 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614 **/
615static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
616{
Bruce Allan373a88d2009-08-07 07:41:37 +0000617 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
618 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700619
Linus Torvalds95b866d2008-10-03 09:18:17 -0700620 might_sleep();
Thomas Gleixner717d4382008-10-02 16:33:40 -0700621
Bruce Allanca15df52009-10-26 11:23:43 +0000622 mutex_lock(&swflag_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700623
Auke Kokbc7f75f2007-09-17 12:30:59 -0700624 while (timeout) {
625 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +0000626 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
627 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700628
Auke Kokbc7f75f2007-09-17 12:30:59 -0700629 mdelay(1);
630 timeout--;
631 }
632
633 if (!timeout) {
Bruce Allan373a88d2009-08-07 07:41:37 +0000634 hw_dbg(hw, "SW/FW/HW has locked the resource for too long.\n");
635 ret_val = -E1000_ERR_CONFIG;
636 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700637 }
638
Bruce Allan53ac5a82009-10-26 11:23:06 +0000639 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +0000640
641 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
642 ew32(EXTCNF_CTRL, extcnf_ctrl);
643
644 while (timeout) {
645 extcnf_ctrl = er32(EXTCNF_CTRL);
646 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
647 break;
648
649 mdelay(1);
650 timeout--;
651 }
652
653 if (!timeout) {
654 hw_dbg(hw, "Failed to acquire the semaphore.\n");
655 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
656 ew32(EXTCNF_CTRL, extcnf_ctrl);
657 ret_val = -E1000_ERR_CONFIG;
658 goto out;
659 }
660
661out:
662 if (ret_val)
Bruce Allanca15df52009-10-26 11:23:43 +0000663 mutex_unlock(&swflag_mutex);
Bruce Allan373a88d2009-08-07 07:41:37 +0000664
665 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700666}
667
668/**
669 * e1000_release_swflag_ich8lan - Release software control flag
670 * @hw: pointer to the HW structure
671 *
Bruce Allanca15df52009-10-26 11:23:43 +0000672 * Releases the software control flag for performing PHY and select
673 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 **/
675static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
676{
677 u32 extcnf_ctrl;
678
679 extcnf_ctrl = er32(EXTCNF_CTRL);
680 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
681 ew32(EXTCNF_CTRL, extcnf_ctrl);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700682
Bruce Allanca15df52009-10-26 11:23:43 +0000683 mutex_unlock(&swflag_mutex);
684
685 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700686}
687
688/**
Bruce Allan4662e822008-08-26 18:37:06 -0700689 * e1000_check_mng_mode_ich8lan - Checks management mode
690 * @hw: pointer to the HW structure
691 *
692 * This checks if the adapter has manageability enabled.
693 * This is a function pointer entry point only called by read/write
694 * routines for the PHY and NVM parts.
695 **/
696static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
697{
698 u32 fwsm = er32(FWSM);
699
700 return (fwsm & E1000_FWSM_MODE_MASK) ==
701 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
702}
703
704/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
706 * @hw: pointer to the HW structure
707 *
708 * Checks if firmware is blocking the reset of the PHY.
709 * This is a function pointer entry point only called by
710 * reset routines.
711 **/
712static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
713{
714 u32 fwsm;
715
716 fwsm = er32(FWSM);
717
718 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
719}
720
721/**
722 * e1000_phy_force_speed_duplex_ich8lan - Force PHY speed & duplex
723 * @hw: pointer to the HW structure
724 *
725 * Forces the speed and duplex settings of the PHY.
726 * This is a function pointer entry point only called by
727 * PHY setup routines.
728 **/
729static s32 e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw)
730{
731 struct e1000_phy_info *phy = &hw->phy;
732 s32 ret_val;
733 u16 data;
734 bool link;
735
736 if (phy->type != e1000_phy_ife) {
737 ret_val = e1000e_phy_force_speed_duplex_igp(hw);
738 return ret_val;
739 }
740
741 ret_val = e1e_rphy(hw, PHY_CONTROL, &data);
742 if (ret_val)
743 return ret_val;
744
745 e1000e_phy_force_speed_duplex_setup(hw, &data);
746
747 ret_val = e1e_wphy(hw, PHY_CONTROL, data);
748 if (ret_val)
749 return ret_val;
750
751 /* Disable MDI-X support for 10/100 */
752 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
753 if (ret_val)
754 return ret_val;
755
756 data &= ~IFE_PMC_AUTO_MDIX;
757 data &= ~IFE_PMC_FORCE_MDIX;
758
759 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
760 if (ret_val)
761 return ret_val;
762
763 hw_dbg(hw, "IFE PMC: %X\n", data);
764
765 udelay(1);
766
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700767 if (phy->autoneg_wait_to_complete) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700768 hw_dbg(hw, "Waiting for forced speed/duplex link on IFE phy.\n");
769
770 ret_val = e1000e_phy_has_link_generic(hw,
771 PHY_FORCE_LIMIT,
772 100000,
773 &link);
774 if (ret_val)
775 return ret_val;
776
777 if (!link)
778 hw_dbg(hw, "Link taking longer than expected.\n");
779
780 /* Try once more */
781 ret_val = e1000e_phy_has_link_generic(hw,
782 PHY_FORCE_LIMIT,
783 100000,
784 &link);
785 if (ret_val)
786 return ret_val;
787 }
788
789 return 0;
790}
791
792/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000793 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
794 * done after every PHY reset.
795 **/
796static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
797{
798 s32 ret_val = 0;
799
800 if (hw->mac.type != e1000_pchlan)
801 return ret_val;
802
803 if (((hw->phy.type == e1000_phy_82577) &&
804 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
805 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
806 /* Disable generation of early preamble */
807 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
808 if (ret_val)
809 return ret_val;
810
811 /* Preamble tuning for SSC */
812 ret_val = e1e_wphy(hw, PHY_REG(770, 16), 0xA204);
813 if (ret_val)
814 return ret_val;
815 }
816
817 if (hw->phy.type == e1000_phy_82578) {
818 /*
819 * Return registers to default by doing a soft reset then
820 * writing 0x3140 to the control register.
821 */
822 if (hw->phy.revision < 2) {
823 e1000e_phy_sw_reset(hw);
824 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
825 }
826 }
827
828 /* Select page 0 */
829 ret_val = hw->phy.ops.acquire_phy(hw);
830 if (ret_val)
831 return ret_val;
832 hw->phy.addr = 1;
833 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
834 hw->phy.ops.release_phy(hw);
835
836 return ret_val;
837}
838
839/**
Bruce Allanfc0c7762009-07-01 13:27:55 +0000840 * e1000_lan_init_done_ich8lan - Check for PHY config completion
841 * @hw: pointer to the HW structure
842 *
843 * Check the appropriate indication the MAC has finished configuring the
844 * PHY after a software reset.
845 **/
846static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
847{
848 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
849
850 /* Wait for basic configuration completes before proceeding */
851 do {
852 data = er32(STATUS);
853 data &= E1000_STATUS_LAN_INIT_DONE;
854 udelay(100);
855 } while ((!data) && --loop);
856
857 /*
858 * If basic configuration is incomplete before the above loop
859 * count reaches 0, loading the configuration from NVM will
860 * leave the PHY in a bad state possibly resulting in no link.
861 */
862 if (loop == 0)
863 hw_dbg(hw, "LAN_INIT_DONE not set, increase timeout\n");
864
865 /* Clear the Init Done bit for the next init event */
866 data = er32(STATUS);
867 data &= ~E1000_STATUS_LAN_INIT_DONE;
868 ew32(STATUS, data);
869}
870
871/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700872 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
873 * @hw: pointer to the HW structure
874 *
875 * Resets the PHY
876 * This is a function pointer entry point called by drivers
877 * or other shared routines.
878 **/
879static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
880{
881 struct e1000_phy_info *phy = &hw->phy;
882 u32 i;
883 u32 data, cnf_size, cnf_base_addr, sw_cfg_mask;
884 s32 ret_val;
Bruce Allandb2932e2009-10-26 11:22:47 +0000885 u16 reg, word_addr, reg_data, reg_addr, phy_page = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700886
887 ret_val = e1000e_phy_hw_reset_generic(hw);
888 if (ret_val)
889 return ret_val;
890
Bruce Allanfc0c7762009-07-01 13:27:55 +0000891 /* Allow time for h/w to get to a quiescent state after reset */
892 mdelay(10);
893
Bruce Allana4f58f52009-06-02 11:29:18 +0000894 if (hw->mac.type == e1000_pchlan) {
895 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
896 if (ret_val)
897 return ret_val;
898 }
899
Bruce Allandb2932e2009-10-26 11:22:47 +0000900 /* Dummy read to clear the phy wakeup bit after lcd reset */
901 if (hw->mac.type == e1000_pchlan)
902 e1e_rphy(hw, BM_WUC, &reg);
903
Bruce Allanad680762008-03-28 09:15:03 -0700904 /*
905 * Initialize the PHY from the NVM on ICH platforms. This
Auke Kokbc7f75f2007-09-17 12:30:59 -0700906 * is needed due to an issue where the NVM configuration is
907 * not properly autoloaded after power transitions.
908 * Therefore, after each PHY reset, we will load the
909 * configuration data out of the NVM manually.
910 */
911 if (hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) {
912 struct e1000_adapter *adapter = hw->adapter;
913
914 /* Check if SW needs configure the PHY */
915 if ((adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
916 (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M))
917 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
918 else
919 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
920
921 data = er32(FEXTNVM);
922 if (!(data & sw_cfg_mask))
923 return 0;
924
Bruce Allanfc0c7762009-07-01 13:27:55 +0000925 /* Wait for basic configuration completes before proceeding */
926 e1000_lan_init_done_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700927
Bruce Allanad680762008-03-28 09:15:03 -0700928 /*
929 * Make sure HW does not configure LCD from PHY
930 * extended configuration before SW configuration
931 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932 data = er32(EXTCNF_CTRL);
933 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
934 return 0;
935
936 cnf_size = er32(EXTCNF_SIZE);
937 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
938 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
939 if (!cnf_size)
940 return 0;
941
942 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
943 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
944
Bruce Allanad680762008-03-28 09:15:03 -0700945 /* Configure LCD from extended configuration region. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700946
947 /* cnf_base_addr is in DWORD */
948 word_addr = (u16)(cnf_base_addr << 1);
949
950 for (i = 0; i < cnf_size; i++) {
951 ret_val = e1000_read_nvm(hw,
952 (word_addr + i * 2),
953 1,
954 &reg_data);
955 if (ret_val)
956 return ret_val;
957
958 ret_val = e1000_read_nvm(hw,
959 (word_addr + i * 2 + 1),
960 1,
961 &reg_addr);
962 if (ret_val)
963 return ret_val;
964
965 /* Save off the PHY page for future writes. */
966 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
967 phy_page = reg_data;
968 continue;
969 }
970
971 reg_addr |= phy_page;
972
973 ret_val = e1e_wphy(hw, (u32)reg_addr, reg_data);
974 if (ret_val)
975 return ret_val;
976 }
977 }
978
979 return 0;
980}
981
982/**
983 * e1000_get_phy_info_ife_ich8lan - Retrieves various IFE PHY states
984 * @hw: pointer to the HW structure
985 *
986 * Populates "phy" structure with various feature states.
987 * This function is only called by other family-specific
988 * routines.
989 **/
990static s32 e1000_get_phy_info_ife_ich8lan(struct e1000_hw *hw)
991{
992 struct e1000_phy_info *phy = &hw->phy;
993 s32 ret_val;
994 u16 data;
995 bool link;
996
997 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
998 if (ret_val)
999 return ret_val;
1000
1001 if (!link) {
1002 hw_dbg(hw, "Phy info is only valid if link is up\n");
1003 return -E1000_ERR_CONFIG;
1004 }
1005
1006 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
1007 if (ret_val)
1008 return ret_val;
1009 phy->polarity_correction = (!(data & IFE_PSC_AUTO_POLARITY_DISABLE));
1010
1011 if (phy->polarity_correction) {
Bruce Allana4f58f52009-06-02 11:29:18 +00001012 ret_val = phy->ops.check_polarity(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001013 if (ret_val)
1014 return ret_val;
1015 } else {
1016 /* Polarity is forced */
1017 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
1018 ? e1000_rev_polarity_reversed
1019 : e1000_rev_polarity_normal;
1020 }
1021
1022 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1023 if (ret_val)
1024 return ret_val;
1025
1026 phy->is_mdix = (data & IFE_PMC_MDIX_STATUS);
1027
1028 /* The following parameters are undefined for 10/100 operation. */
1029 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1030 phy->local_rx = e1000_1000t_rx_status_undefined;
1031 phy->remote_rx = e1000_1000t_rx_status_undefined;
1032
1033 return 0;
1034}
1035
1036/**
1037 * e1000_get_phy_info_ich8lan - Calls appropriate PHY type get_phy_info
1038 * @hw: pointer to the HW structure
1039 *
1040 * Wrapper for calling the get_phy_info routines for the appropriate phy type.
1041 * This is a function pointer entry point called by drivers
1042 * or other shared routines.
1043 **/
1044static s32 e1000_get_phy_info_ich8lan(struct e1000_hw *hw)
1045{
1046 switch (hw->phy.type) {
1047 case e1000_phy_ife:
1048 return e1000_get_phy_info_ife_ich8lan(hw);
1049 break;
1050 case e1000_phy_igp_3:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001051 case e1000_phy_bm:
Bruce Allana4f58f52009-06-02 11:29:18 +00001052 case e1000_phy_82578:
1053 case e1000_phy_82577:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001054 return e1000e_get_phy_info_igp(hw);
1055 break;
1056 default:
1057 break;
1058 }
1059
1060 return -E1000_ERR_PHY_TYPE;
1061}
1062
1063/**
1064 * e1000_check_polarity_ife_ich8lan - Check cable polarity for IFE PHY
1065 * @hw: pointer to the HW structure
1066 *
Auke Kok489815c2008-02-21 15:11:07 -08001067 * Polarity is determined on the polarity reversal feature being enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001068 * This function is only called by other family-specific
1069 * routines.
1070 **/
1071static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw)
1072{
1073 struct e1000_phy_info *phy = &hw->phy;
1074 s32 ret_val;
1075 u16 phy_data, offset, mask;
1076
Bruce Allanad680762008-03-28 09:15:03 -07001077 /*
1078 * Polarity is determined based on the reversal feature being enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079 */
1080 if (phy->polarity_correction) {
1081 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1082 mask = IFE_PESC_POLARITY_REVERSED;
1083 } else {
1084 offset = IFE_PHY_SPECIAL_CONTROL;
1085 mask = IFE_PSC_FORCE_POLARITY;
1086 }
1087
1088 ret_val = e1e_rphy(hw, offset, &phy_data);
1089
1090 if (!ret_val)
1091 phy->cable_polarity = (phy_data & mask)
1092 ? e1000_rev_polarity_reversed
1093 : e1000_rev_polarity_normal;
1094
1095 return ret_val;
1096}
1097
1098/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00001099 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1100 * @hw: pointer to the HW structure
1101 * @active: true to enable LPLU, false to disable
1102 *
1103 * Sets the LPLU state according to the active flag. For PCH, if OEM write
1104 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1105 * the phy speed. This function will manually set the LPLU bit and restart
1106 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
1107 * since it configures the same bit.
1108 **/
1109static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1110{
1111 s32 ret_val = 0;
1112 u16 oem_reg;
1113
1114 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
1115 if (ret_val)
1116 goto out;
1117
1118 if (active)
1119 oem_reg |= HV_OEM_BITS_LPLU;
1120 else
1121 oem_reg &= ~HV_OEM_BITS_LPLU;
1122
1123 oem_reg |= HV_OEM_BITS_RESTART_AN;
1124 ret_val = e1e_wphy(hw, HV_OEM_BITS, oem_reg);
1125
1126out:
1127 return ret_val;
1128}
1129
1130/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001131 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1132 * @hw: pointer to the HW structure
1133 * @active: TRUE to enable LPLU, FALSE to disable
1134 *
1135 * Sets the LPLU D0 state according to the active flag. When
1136 * activating LPLU this function also disables smart speed
1137 * and vice versa. LPLU will not be activated unless the
1138 * device autonegotiation advertisement meets standards of
1139 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1140 * This is a function pointer entry point only called by
1141 * PHY setup routines.
1142 **/
1143static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1144{
1145 struct e1000_phy_info *phy = &hw->phy;
1146 u32 phy_ctrl;
1147 s32 ret_val = 0;
1148 u16 data;
1149
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001150 if (phy->type == e1000_phy_ife)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001151 return ret_val;
1152
1153 phy_ctrl = er32(PHY_CTRL);
1154
1155 if (active) {
1156 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
1157 ew32(PHY_CTRL, phy_ctrl);
1158
Bruce Allan60f12922009-07-01 13:28:14 +00001159 if (phy->type != e1000_phy_igp_3)
1160 return 0;
1161
Bruce Allanad680762008-03-28 09:15:03 -07001162 /*
1163 * Call gig speed drop workaround on LPLU before accessing
1164 * any PHY registers
1165 */
Bruce Allan60f12922009-07-01 13:28:14 +00001166 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167 e1000e_gig_downshift_workaround_ich8lan(hw);
1168
1169 /* When LPLU is enabled, we should disable SmartSpeed */
1170 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1171 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1172 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1173 if (ret_val)
1174 return ret_val;
1175 } else {
1176 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
1177 ew32(PHY_CTRL, phy_ctrl);
1178
Bruce Allan60f12922009-07-01 13:28:14 +00001179 if (phy->type != e1000_phy_igp_3)
1180 return 0;
1181
Bruce Allanad680762008-03-28 09:15:03 -07001182 /*
1183 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001184 * during Dx states where the power conservation is most
1185 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001186 * SmartSpeed, so performance is maintained.
1187 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188 if (phy->smart_speed == e1000_smart_speed_on) {
1189 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001190 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001191 if (ret_val)
1192 return ret_val;
1193
1194 data |= IGP01E1000_PSCFR_SMART_SPEED;
1195 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001196 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 if (ret_val)
1198 return ret_val;
1199 } else if (phy->smart_speed == e1000_smart_speed_off) {
1200 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001201 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 if (ret_val)
1203 return ret_val;
1204
1205 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1206 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001207 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001208 if (ret_val)
1209 return ret_val;
1210 }
1211 }
1212
1213 return 0;
1214}
1215
1216/**
1217 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
1218 * @hw: pointer to the HW structure
1219 * @active: TRUE to enable LPLU, FALSE to disable
1220 *
1221 * Sets the LPLU D3 state according to the active flag. When
1222 * activating LPLU this function also disables smart speed
1223 * and vice versa. LPLU will not be activated unless the
1224 * device autonegotiation advertisement meets standards of
1225 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1226 * This is a function pointer entry point only called by
1227 * PHY setup routines.
1228 **/
1229static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1230{
1231 struct e1000_phy_info *phy = &hw->phy;
1232 u32 phy_ctrl;
1233 s32 ret_val;
1234 u16 data;
1235
1236 phy_ctrl = er32(PHY_CTRL);
1237
1238 if (!active) {
1239 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
1240 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00001241
1242 if (phy->type != e1000_phy_igp_3)
1243 return 0;
1244
Bruce Allanad680762008-03-28 09:15:03 -07001245 /*
1246 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247 * during Dx states where the power conservation is most
1248 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001249 * SmartSpeed, so performance is maintained.
1250 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001251 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07001252 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1253 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254 if (ret_val)
1255 return ret_val;
1256
1257 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001258 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1259 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260 if (ret_val)
1261 return ret_val;
1262 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07001263 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1264 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001265 if (ret_val)
1266 return ret_val;
1267
1268 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001269 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1270 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001271 if (ret_val)
1272 return ret_val;
1273 }
1274 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1275 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1276 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1277 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
1278 ew32(PHY_CTRL, phy_ctrl);
1279
Bruce Allan60f12922009-07-01 13:28:14 +00001280 if (phy->type != e1000_phy_igp_3)
1281 return 0;
1282
Bruce Allanad680762008-03-28 09:15:03 -07001283 /*
1284 * Call gig speed drop workaround on LPLU before accessing
1285 * any PHY registers
1286 */
Bruce Allan60f12922009-07-01 13:28:14 +00001287 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001288 e1000e_gig_downshift_workaround_ich8lan(hw);
1289
1290 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07001291 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001292 if (ret_val)
1293 return ret_val;
1294
1295 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001296 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001297 }
1298
1299 return 0;
1300}
1301
1302/**
Bruce Allanf4187b52008-08-26 18:36:50 -07001303 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
1304 * @hw: pointer to the HW structure
1305 * @bank: pointer to the variable that returns the active bank
1306 *
1307 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08001308 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07001309 **/
1310static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
1311{
Bruce Allane2434552008-11-21 17:02:41 -08001312 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07001313 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07001314 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
1315 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08001316 u8 sig_byte = 0;
1317 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001318
Bruce Allane2434552008-11-21 17:02:41 -08001319 switch (hw->mac.type) {
1320 case e1000_ich8lan:
1321 case e1000_ich9lan:
1322 eecd = er32(EECD);
1323 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
1324 E1000_EECD_SEC1VAL_VALID_MASK) {
1325 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07001326 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08001327 else
1328 *bank = 0;
1329
1330 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001331 }
Bruce Allane2434552008-11-21 17:02:41 -08001332 hw_dbg(hw, "Unable to determine valid NVM bank via EEC - "
1333 "reading flash signature\n");
1334 /* fall-thru */
1335 default:
1336 /* set bank to 0 in case flash read fails */
1337 *bank = 0;
1338
1339 /* Check bank 0 */
1340 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
1341 &sig_byte);
1342 if (ret_val)
1343 return ret_val;
1344 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1345 E1000_ICH_NVM_SIG_VALUE) {
1346 *bank = 0;
1347 return 0;
1348 }
1349
1350 /* Check bank 1 */
1351 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
1352 bank1_offset,
1353 &sig_byte);
1354 if (ret_val)
1355 return ret_val;
1356 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1357 E1000_ICH_NVM_SIG_VALUE) {
1358 *bank = 1;
1359 return 0;
1360 }
1361
1362 hw_dbg(hw, "ERROR: No valid NVM bank present\n");
1363 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07001364 }
1365
1366 return 0;
1367}
1368
1369/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001370 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
1371 * @hw: pointer to the HW structure
1372 * @offset: The offset (in bytes) of the word(s) to read.
1373 * @words: Size of data to read in words
1374 * @data: Pointer to the word(s) to read at offset.
1375 *
1376 * Reads a word(s) from the NVM using the flash access registers.
1377 **/
1378static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1379 u16 *data)
1380{
1381 struct e1000_nvm_info *nvm = &hw->nvm;
1382 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1383 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00001384 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001385 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001386 u16 i, word;
1387
1388 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1389 (words == 0)) {
1390 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00001391 ret_val = -E1000_ERR_NVM;
1392 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001393 }
1394
Bruce Allanca15df52009-10-26 11:23:43 +00001395 nvm->ops.acquire_nvm(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001396
Bruce Allanf4187b52008-08-26 18:36:50 -07001397 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00001398 if (ret_val) {
1399 hw_dbg(hw, "Could not detect valid bank, assuming bank 0\n");
1400 bank = 0;
1401 }
Bruce Allanf4187b52008-08-26 18:36:50 -07001402
1403 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001404 act_offset += offset;
1405
Bruce Allan148675a2009-08-07 07:41:56 +00001406 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001407 for (i = 0; i < words; i++) {
1408 if ((dev_spec->shadow_ram) &&
1409 (dev_spec->shadow_ram[offset+i].modified)) {
1410 data[i] = dev_spec->shadow_ram[offset+i].value;
1411 } else {
1412 ret_val = e1000_read_flash_word_ich8lan(hw,
1413 act_offset + i,
1414 &word);
1415 if (ret_val)
1416 break;
1417 data[i] = word;
1418 }
1419 }
1420
Bruce Allanca15df52009-10-26 11:23:43 +00001421 nvm->ops.release_nvm(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001422
Bruce Allane2434552008-11-21 17:02:41 -08001423out:
1424 if (ret_val)
1425 hw_dbg(hw, "NVM read error: %d\n", ret_val);
1426
Auke Kokbc7f75f2007-09-17 12:30:59 -07001427 return ret_val;
1428}
1429
1430/**
1431 * e1000_flash_cycle_init_ich8lan - Initialize flash
1432 * @hw: pointer to the HW structure
1433 *
1434 * This function does initial flash setup so that a new read/write/erase cycle
1435 * can be started.
1436 **/
1437static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
1438{
1439 union ich8_hws_flash_status hsfsts;
1440 s32 ret_val = -E1000_ERR_NVM;
1441 s32 i = 0;
1442
1443 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1444
1445 /* Check if the flash descriptor is valid */
1446 if (hsfsts.hsf_status.fldesvalid == 0) {
1447 hw_dbg(hw, "Flash descriptor invalid. "
1448 "SW Sequencing must be used.");
1449 return -E1000_ERR_NVM;
1450 }
1451
1452 /* Clear FCERR and DAEL in hw status by writing 1 */
1453 hsfsts.hsf_status.flcerr = 1;
1454 hsfsts.hsf_status.dael = 1;
1455
1456 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1457
Bruce Allanad680762008-03-28 09:15:03 -07001458 /*
1459 * Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07001460 * bit to check against, in order to start a new cycle or
1461 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08001462 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07001463 * indication whether a cycle is in progress or has been
1464 * completed.
1465 */
1466
1467 if (hsfsts.hsf_status.flcinprog == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07001468 /*
1469 * There is no cycle running at present,
1470 * so we can start a cycle
1471 * Begin by setting Flash Cycle Done.
1472 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473 hsfsts.hsf_status.flcdone = 1;
1474 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1475 ret_val = 0;
1476 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001477 /*
1478 * otherwise poll for sometime so the current
1479 * cycle has a chance to end before giving up.
1480 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001481 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
1482 hsfsts.regval = __er16flash(hw, ICH_FLASH_HSFSTS);
1483 if (hsfsts.hsf_status.flcinprog == 0) {
1484 ret_val = 0;
1485 break;
1486 }
1487 udelay(1);
1488 }
1489 if (ret_val == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07001490 /*
1491 * Successful in waiting for previous cycle to timeout,
1492 * now set the Flash Cycle Done.
1493 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001494 hsfsts.hsf_status.flcdone = 1;
1495 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1496 } else {
1497 hw_dbg(hw, "Flash controller busy, cannot get access");
1498 }
1499 }
1500
1501 return ret_val;
1502}
1503
1504/**
1505 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
1506 * @hw: pointer to the HW structure
1507 * @timeout: maximum time to wait for completion
1508 *
1509 * This function starts a flash cycle and waits for its completion.
1510 **/
1511static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
1512{
1513 union ich8_hws_flash_ctrl hsflctl;
1514 union ich8_hws_flash_status hsfsts;
1515 s32 ret_val = -E1000_ERR_NVM;
1516 u32 i = 0;
1517
1518 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
1519 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1520 hsflctl.hsf_ctrl.flcgo = 1;
1521 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1522
1523 /* wait till FDONE bit is set to 1 */
1524 do {
1525 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1526 if (hsfsts.hsf_status.flcdone == 1)
1527 break;
1528 udelay(1);
1529 } while (i++ < timeout);
1530
1531 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
1532 return 0;
1533
1534 return ret_val;
1535}
1536
1537/**
1538 * e1000_read_flash_word_ich8lan - Read word from flash
1539 * @hw: pointer to the HW structure
1540 * @offset: offset to data location
1541 * @data: pointer to the location for storing the data
1542 *
1543 * Reads the flash word at offset into data. Offset is converted
1544 * to bytes before read.
1545 **/
1546static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
1547 u16 *data)
1548{
1549 /* Must convert offset into bytes. */
1550 offset <<= 1;
1551
1552 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
1553}
1554
1555/**
Bruce Allanf4187b52008-08-26 18:36:50 -07001556 * e1000_read_flash_byte_ich8lan - Read byte from flash
1557 * @hw: pointer to the HW structure
1558 * @offset: The offset of the byte to read.
1559 * @data: Pointer to a byte to store the value read.
1560 *
1561 * Reads a single byte from the NVM using the flash access registers.
1562 **/
1563static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1564 u8 *data)
1565{
1566 s32 ret_val;
1567 u16 word = 0;
1568
1569 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
1570 if (ret_val)
1571 return ret_val;
1572
1573 *data = (u8)word;
1574
1575 return 0;
1576}
1577
1578/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
1580 * @hw: pointer to the HW structure
1581 * @offset: The offset (in bytes) of the byte or word to read.
1582 * @size: Size of data to read, 1=byte 2=word
1583 * @data: Pointer to the word to store the value read.
1584 *
1585 * Reads a byte or word from the NVM using the flash access registers.
1586 **/
1587static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1588 u8 size, u16 *data)
1589{
1590 union ich8_hws_flash_status hsfsts;
1591 union ich8_hws_flash_ctrl hsflctl;
1592 u32 flash_linear_addr;
1593 u32 flash_data = 0;
1594 s32 ret_val = -E1000_ERR_NVM;
1595 u8 count = 0;
1596
1597 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
1598 return -E1000_ERR_NVM;
1599
1600 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1601 hw->nvm.flash_base_addr;
1602
1603 do {
1604 udelay(1);
1605 /* Steps */
1606 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1607 if (ret_val != 0)
1608 break;
1609
1610 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1611 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1612 hsflctl.hsf_ctrl.fldbcount = size - 1;
1613 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
1614 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1615
1616 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1617
1618 ret_val = e1000_flash_cycle_ich8lan(hw,
1619 ICH_FLASH_READ_COMMAND_TIMEOUT);
1620
Bruce Allanad680762008-03-28 09:15:03 -07001621 /*
1622 * Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07001623 * and try the whole sequence a few more times, else
1624 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07001625 * least significant byte first msb to lsb
1626 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001627 if (ret_val == 0) {
1628 flash_data = er32flash(ICH_FLASH_FDATA0);
1629 if (size == 1) {
1630 *data = (u8)(flash_data & 0x000000FF);
1631 } else if (size == 2) {
1632 *data = (u16)(flash_data & 0x0000FFFF);
1633 }
1634 break;
1635 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001636 /*
1637 * If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638 * completely hosed, but if the error condition is
1639 * detected, it won't hurt to give it another try...
1640 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
1641 */
1642 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1643 if (hsfsts.hsf_status.flcerr == 1) {
1644 /* Repeat for some time before giving up. */
1645 continue;
1646 } else if (hsfsts.hsf_status.flcdone == 0) {
1647 hw_dbg(hw, "Timeout error - flash cycle "
1648 "did not complete.");
1649 break;
1650 }
1651 }
1652 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1653
1654 return ret_val;
1655}
1656
1657/**
1658 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
1659 * @hw: pointer to the HW structure
1660 * @offset: The offset (in bytes) of the word(s) to write.
1661 * @words: Size of data to write in words
1662 * @data: Pointer to the word(s) to write at offset.
1663 *
1664 * Writes a byte or word to the NVM using the flash access registers.
1665 **/
1666static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1667 u16 *data)
1668{
1669 struct e1000_nvm_info *nvm = &hw->nvm;
1670 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001671 u16 i;
1672
1673 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1674 (words == 0)) {
1675 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
1676 return -E1000_ERR_NVM;
1677 }
1678
Bruce Allanca15df52009-10-26 11:23:43 +00001679 nvm->ops.acquire_nvm(hw);
1680
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 for (i = 0; i < words; i++) {
1682 dev_spec->shadow_ram[offset+i].modified = 1;
1683 dev_spec->shadow_ram[offset+i].value = data[i];
1684 }
1685
Bruce Allanca15df52009-10-26 11:23:43 +00001686 nvm->ops.release_nvm(hw);
1687
Auke Kokbc7f75f2007-09-17 12:30:59 -07001688 return 0;
1689}
1690
1691/**
1692 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
1693 * @hw: pointer to the HW structure
1694 *
1695 * The NVM checksum is updated by calling the generic update_nvm_checksum,
1696 * which writes the checksum to the shadow ram. The changes in the shadow
1697 * ram are then committed to the EEPROM by processing each bank at a time
1698 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08001699 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700 * future writes.
1701 **/
1702static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1703{
1704 struct e1000_nvm_info *nvm = &hw->nvm;
1705 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07001706 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 s32 ret_val;
1708 u16 data;
1709
1710 ret_val = e1000e_update_nvm_checksum_generic(hw);
1711 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08001712 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713
1714 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08001715 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001716
Bruce Allanca15df52009-10-26 11:23:43 +00001717 nvm->ops.acquire_nvm(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001718
Bruce Allanad680762008-03-28 09:15:03 -07001719 /*
1720 * We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07001722 * is going to be written
1723 */
Bruce Allanf4187b52008-08-26 18:36:50 -07001724 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08001725 if (ret_val) {
Bruce Allan148675a2009-08-07 07:41:56 +00001726 hw_dbg(hw, "Could not detect valid bank, assuming bank 0\n");
1727 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08001728 }
Bruce Allanf4187b52008-08-26 18:36:50 -07001729
1730 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001731 new_bank_offset = nvm->flash_bank_size;
1732 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08001733 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
1734 if (ret_val) {
Bruce Allanca15df52009-10-26 11:23:43 +00001735 nvm->ops.release_nvm(hw);
Bruce Allane2434552008-11-21 17:02:41 -08001736 goto out;
1737 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 } else {
1739 old_bank_offset = nvm->flash_bank_size;
1740 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08001741 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
1742 if (ret_val) {
Bruce Allanca15df52009-10-26 11:23:43 +00001743 nvm->ops.release_nvm(hw);
Bruce Allane2434552008-11-21 17:02:41 -08001744 goto out;
1745 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001746 }
1747
1748 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allanad680762008-03-28 09:15:03 -07001749 /*
1750 * Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07001751 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07001752 * in the shadow RAM
1753 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001754 if (dev_spec->shadow_ram[i].modified) {
1755 data = dev_spec->shadow_ram[i].value;
1756 } else {
Bruce Allane2434552008-11-21 17:02:41 -08001757 ret_val = e1000_read_flash_word_ich8lan(hw, i +
1758 old_bank_offset,
1759 &data);
1760 if (ret_val)
1761 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001762 }
1763
Bruce Allanad680762008-03-28 09:15:03 -07001764 /*
1765 * If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07001766 * (15:14) are 11b until the commit has completed.
1767 * This will allow us to write 10b which indicates the
1768 * signature is valid. We want to do this after the write
1769 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07001770 * while the write is still in progress
1771 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001772 if (i == E1000_ICH_NVM_SIG_WORD)
1773 data |= E1000_ICH_NVM_SIG_MASK;
1774
1775 /* Convert offset to bytes. */
1776 act_offset = (i + new_bank_offset) << 1;
1777
1778 udelay(100);
1779 /* Write the bytes to the new bank. */
1780 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1781 act_offset,
1782 (u8)data);
1783 if (ret_val)
1784 break;
1785
1786 udelay(100);
1787 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1788 act_offset + 1,
1789 (u8)(data >> 8));
1790 if (ret_val)
1791 break;
1792 }
1793
Bruce Allanad680762008-03-28 09:15:03 -07001794 /*
1795 * Don't bother writing the segment valid bits if sector
1796 * programming failed.
1797 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001798 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07001799 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001800 hw_dbg(hw, "Flash commit failed.\n");
Bruce Allanca15df52009-10-26 11:23:43 +00001801 nvm->ops.release_nvm(hw);
Bruce Allane2434552008-11-21 17:02:41 -08001802 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001803 }
1804
Bruce Allanad680762008-03-28 09:15:03 -07001805 /*
1806 * Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07001807 * to 10b in word 0x13 , this can be done without an
1808 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07001809 * and we need to change bit 14 to 0b
1810 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001811 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08001812 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
1813 if (ret_val) {
Bruce Allanca15df52009-10-26 11:23:43 +00001814 nvm->ops.release_nvm(hw);
Bruce Allane2434552008-11-21 17:02:41 -08001815 goto out;
1816 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001817 data &= 0xBFFF;
1818 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1819 act_offset * 2 + 1,
1820 (u8)(data >> 8));
1821 if (ret_val) {
Bruce Allanca15df52009-10-26 11:23:43 +00001822 nvm->ops.release_nvm(hw);
Bruce Allane2434552008-11-21 17:02:41 -08001823 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001824 }
1825
Bruce Allanad680762008-03-28 09:15:03 -07001826 /*
1827 * And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07001828 * its signature word (0x13) high_byte to 0b. This can be
1829 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07001830 * to 1's. We can write 1's to 0's without an erase
1831 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001832 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
1833 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
1834 if (ret_val) {
Bruce Allanca15df52009-10-26 11:23:43 +00001835 nvm->ops.release_nvm(hw);
Bruce Allane2434552008-11-21 17:02:41 -08001836 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837 }
1838
1839 /* Great! Everything worked, we can now clear the cached entries. */
1840 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
1841 dev_spec->shadow_ram[i].modified = 0;
1842 dev_spec->shadow_ram[i].value = 0xFFFF;
1843 }
1844
Bruce Allanca15df52009-10-26 11:23:43 +00001845 nvm->ops.release_nvm(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846
Bruce Allanad680762008-03-28 09:15:03 -07001847 /*
1848 * Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07001849 * until after the next adapter reset.
1850 */
1851 e1000e_reload_nvm(hw);
1852 msleep(10);
1853
Bruce Allane2434552008-11-21 17:02:41 -08001854out:
1855 if (ret_val)
1856 hw_dbg(hw, "NVM update error: %d\n", ret_val);
1857
Auke Kokbc7f75f2007-09-17 12:30:59 -07001858 return ret_val;
1859}
1860
1861/**
1862 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
1863 * @hw: pointer to the HW structure
1864 *
1865 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
1866 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
1867 * calculated, in which case we need to calculate the checksum and set bit 6.
1868 **/
1869static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
1870{
1871 s32 ret_val;
1872 u16 data;
1873
Bruce Allanad680762008-03-28 09:15:03 -07001874 /*
1875 * Read 0x19 and check bit 6. If this bit is 0, the checksum
Auke Kokbc7f75f2007-09-17 12:30:59 -07001876 * needs to be fixed. This bit is an indication that the NVM
1877 * was prepared by OEM software and did not calculate the
1878 * checksum...a likely scenario.
1879 */
1880 ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
1881 if (ret_val)
1882 return ret_val;
1883
1884 if ((data & 0x40) == 0) {
1885 data |= 0x40;
1886 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
1887 if (ret_val)
1888 return ret_val;
1889 ret_val = e1000e_update_nvm_checksum(hw);
1890 if (ret_val)
1891 return ret_val;
1892 }
1893
1894 return e1000e_validate_nvm_checksum_generic(hw);
1895}
1896
1897/**
Bruce Allan4a770352008-10-01 17:18:35 -07001898 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
1899 * @hw: pointer to the HW structure
1900 *
1901 * To prevent malicious write/erase of the NVM, set it to be read-only
1902 * so that the hardware ignores all write/erase cycles of the NVM via
1903 * the flash control registers. The shadow-ram copy of the NVM will
1904 * still be updated, however any updates to this copy will not stick
1905 * across driver reloads.
1906 **/
1907void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
1908{
Bruce Allanca15df52009-10-26 11:23:43 +00001909 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07001910 union ich8_flash_protected_range pr0;
1911 union ich8_hws_flash_status hsfsts;
1912 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07001913
Bruce Allanca15df52009-10-26 11:23:43 +00001914 nvm->ops.acquire_nvm(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07001915
1916 gfpreg = er32flash(ICH_FLASH_GFPREG);
1917
1918 /* Write-protect GbE Sector of NVM */
1919 pr0.regval = er32flash(ICH_FLASH_PR0);
1920 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
1921 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
1922 pr0.range.wpe = true;
1923 ew32flash(ICH_FLASH_PR0, pr0.regval);
1924
1925 /*
1926 * Lock down a subset of GbE Flash Control Registers, e.g.
1927 * PR0 to prevent the write-protection from being lifted.
1928 * Once FLOCKDN is set, the registers protected by it cannot
1929 * be written until FLOCKDN is cleared by a hardware reset.
1930 */
1931 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1932 hsfsts.hsf_status.flockdn = true;
1933 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1934
Bruce Allanca15df52009-10-26 11:23:43 +00001935 nvm->ops.release_nvm(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07001936}
1937
1938/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001939 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
1940 * @hw: pointer to the HW structure
1941 * @offset: The offset (in bytes) of the byte/word to read.
1942 * @size: Size of data to read, 1=byte 2=word
1943 * @data: The byte(s) to write to the NVM.
1944 *
1945 * Writes one/two bytes to the NVM using the flash access registers.
1946 **/
1947static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1948 u8 size, u16 data)
1949{
1950 union ich8_hws_flash_status hsfsts;
1951 union ich8_hws_flash_ctrl hsflctl;
1952 u32 flash_linear_addr;
1953 u32 flash_data = 0;
1954 s32 ret_val;
1955 u8 count = 0;
1956
1957 if (size < 1 || size > 2 || data > size * 0xff ||
1958 offset > ICH_FLASH_LINEAR_ADDR_MASK)
1959 return -E1000_ERR_NVM;
1960
1961 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1962 hw->nvm.flash_base_addr;
1963
1964 do {
1965 udelay(1);
1966 /* Steps */
1967 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1968 if (ret_val)
1969 break;
1970
1971 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1972 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1973 hsflctl.hsf_ctrl.fldbcount = size -1;
1974 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
1975 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1976
1977 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1978
1979 if (size == 1)
1980 flash_data = (u32)data & 0x00FF;
1981 else
1982 flash_data = (u32)data;
1983
1984 ew32flash(ICH_FLASH_FDATA0, flash_data);
1985
Bruce Allanad680762008-03-28 09:15:03 -07001986 /*
1987 * check if FCERR is set to 1 , if set to 1, clear it
1988 * and try the whole sequence a few more times else done
1989 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001990 ret_val = e1000_flash_cycle_ich8lan(hw,
1991 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
1992 if (!ret_val)
1993 break;
1994
Bruce Allanad680762008-03-28 09:15:03 -07001995 /*
1996 * If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07001997 * completely hosed, but if the error condition
1998 * is detected, it won't hurt to give it another
1999 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
2000 */
2001 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2002 if (hsfsts.hsf_status.flcerr == 1)
2003 /* Repeat for some time before giving up. */
2004 continue;
2005 if (hsfsts.hsf_status.flcdone == 0) {
2006 hw_dbg(hw, "Timeout error - flash cycle "
2007 "did not complete.");
2008 break;
2009 }
2010 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2011
2012 return ret_val;
2013}
2014
2015/**
2016 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
2017 * @hw: pointer to the HW structure
2018 * @offset: The index of the byte to read.
2019 * @data: The byte to write to the NVM.
2020 *
2021 * Writes a single byte to the NVM using the flash access registers.
2022 **/
2023static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2024 u8 data)
2025{
2026 u16 word = (u16)data;
2027
2028 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
2029}
2030
2031/**
2032 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
2033 * @hw: pointer to the HW structure
2034 * @offset: The offset of the byte to write.
2035 * @byte: The byte to write to the NVM.
2036 *
2037 * Writes a single byte to the NVM using the flash access registers.
2038 * Goes through a retry algorithm before giving up.
2039 **/
2040static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
2041 u32 offset, u8 byte)
2042{
2043 s32 ret_val;
2044 u16 program_retries;
2045
2046 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2047 if (!ret_val)
2048 return ret_val;
2049
2050 for (program_retries = 0; program_retries < 100; program_retries++) {
2051 hw_dbg(hw, "Retrying Byte %2.2X at offset %u\n", byte, offset);
2052 udelay(100);
2053 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2054 if (!ret_val)
2055 break;
2056 }
2057 if (program_retries == 100)
2058 return -E1000_ERR_NVM;
2059
2060 return 0;
2061}
2062
2063/**
2064 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
2065 * @hw: pointer to the HW structure
2066 * @bank: 0 for first bank, 1 for second bank, etc.
2067 *
2068 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
2069 * bank N is 4096 * N + flash_reg_addr.
2070 **/
2071static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
2072{
2073 struct e1000_nvm_info *nvm = &hw->nvm;
2074 union ich8_hws_flash_status hsfsts;
2075 union ich8_hws_flash_ctrl hsflctl;
2076 u32 flash_linear_addr;
2077 /* bank size is in 16bit words - adjust to bytes */
2078 u32 flash_bank_size = nvm->flash_bank_size * 2;
2079 s32 ret_val;
2080 s32 count = 0;
2081 s32 iteration;
2082 s32 sector_size;
2083 s32 j;
2084
2085 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2086
Bruce Allanad680762008-03-28 09:15:03 -07002087 /*
2088 * Determine HW Sector size: Read BERASE bits of hw flash status
2089 * register
2090 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07002091 * consecutive sectors. The start index for the nth Hw sector
2092 * can be calculated as = bank * 4096 + n * 256
2093 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
2094 * The start index for the nth Hw sector can be calculated
2095 * as = bank * 4096
2096 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
2097 * (ich9 only, otherwise error condition)
2098 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
2099 */
2100 switch (hsfsts.hsf_status.berasesz) {
2101 case 0:
2102 /* Hw sector size 256 */
2103 sector_size = ICH_FLASH_SEG_SIZE_256;
2104 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
2105 break;
2106 case 1:
2107 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00002108 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002109 break;
2110 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00002111 sector_size = ICH_FLASH_SEG_SIZE_8K;
2112 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002113 break;
2114 case 3:
2115 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00002116 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002117 break;
2118 default:
2119 return -E1000_ERR_NVM;
2120 }
2121
2122 /* Start with the base address, then add the sector offset. */
2123 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00002124 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002125
2126 for (j = 0; j < iteration ; j++) {
2127 do {
2128 /* Steps */
2129 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2130 if (ret_val)
2131 return ret_val;
2132
Bruce Allanad680762008-03-28 09:15:03 -07002133 /*
2134 * Write a value 11 (block Erase) in Flash
2135 * Cycle field in hw flash control
2136 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002137 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2138 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
2139 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2140
Bruce Allanad680762008-03-28 09:15:03 -07002141 /*
2142 * Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07002143 * block into Flash Linear address field in Flash
2144 * Address.
2145 */
2146 flash_linear_addr += (j * sector_size);
2147 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2148
2149 ret_val = e1000_flash_cycle_ich8lan(hw,
2150 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
2151 if (ret_val == 0)
2152 break;
2153
Bruce Allanad680762008-03-28 09:15:03 -07002154 /*
2155 * Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002156 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07002157 * a few more times else Done
2158 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002159 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2160 if (hsfsts.hsf_status.flcerr == 1)
Bruce Allanad680762008-03-28 09:15:03 -07002161 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002162 continue;
2163 else if (hsfsts.hsf_status.flcdone == 0)
2164 return ret_val;
2165 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
2166 }
2167
2168 return 0;
2169}
2170
2171/**
2172 * e1000_valid_led_default_ich8lan - Set the default LED settings
2173 * @hw: pointer to the HW structure
2174 * @data: Pointer to the LED settings
2175 *
2176 * Reads the LED default settings from the NVM to data. If the NVM LED
2177 * settings is all 0's or F's, set the LED default to a valid LED default
2178 * setting.
2179 **/
2180static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
2181{
2182 s32 ret_val;
2183
2184 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
2185 if (ret_val) {
2186 hw_dbg(hw, "NVM Read Error\n");
2187 return ret_val;
2188 }
2189
2190 if (*data == ID_LED_RESERVED_0000 ||
2191 *data == ID_LED_RESERVED_FFFF)
2192 *data = ID_LED_DEFAULT_ICH8LAN;
2193
2194 return 0;
2195}
2196
2197/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002198 * e1000_id_led_init_pchlan - store LED configurations
2199 * @hw: pointer to the HW structure
2200 *
2201 * PCH does not control LEDs via the LEDCTL register, rather it uses
2202 * the PHY LED configuration register.
2203 *
2204 * PCH also does not have an "always on" or "always off" mode which
2205 * complicates the ID feature. Instead of using the "on" mode to indicate
2206 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init()),
2207 * use "link_up" mode. The LEDs will still ID on request if there is no
2208 * link based on logic in e1000_led_[on|off]_pchlan().
2209 **/
2210static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
2211{
2212 struct e1000_mac_info *mac = &hw->mac;
2213 s32 ret_val;
2214 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
2215 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
2216 u16 data, i, temp, shift;
2217
2218 /* Get default ID LED modes */
2219 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
2220 if (ret_val)
2221 goto out;
2222
2223 mac->ledctl_default = er32(LEDCTL);
2224 mac->ledctl_mode1 = mac->ledctl_default;
2225 mac->ledctl_mode2 = mac->ledctl_default;
2226
2227 for (i = 0; i < 4; i++) {
2228 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
2229 shift = (i * 5);
2230 switch (temp) {
2231 case ID_LED_ON1_DEF2:
2232 case ID_LED_ON1_ON2:
2233 case ID_LED_ON1_OFF2:
2234 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2235 mac->ledctl_mode1 |= (ledctl_on << shift);
2236 break;
2237 case ID_LED_OFF1_DEF2:
2238 case ID_LED_OFF1_ON2:
2239 case ID_LED_OFF1_OFF2:
2240 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2241 mac->ledctl_mode1 |= (ledctl_off << shift);
2242 break;
2243 default:
2244 /* Do nothing */
2245 break;
2246 }
2247 switch (temp) {
2248 case ID_LED_DEF1_ON2:
2249 case ID_LED_ON1_ON2:
2250 case ID_LED_OFF1_ON2:
2251 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2252 mac->ledctl_mode2 |= (ledctl_on << shift);
2253 break;
2254 case ID_LED_DEF1_OFF2:
2255 case ID_LED_ON1_OFF2:
2256 case ID_LED_OFF1_OFF2:
2257 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2258 mac->ledctl_mode2 |= (ledctl_off << shift);
2259 break;
2260 default:
2261 /* Do nothing */
2262 break;
2263 }
2264 }
2265
2266out:
2267 return ret_val;
2268}
2269
2270/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002271 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
2272 * @hw: pointer to the HW structure
2273 *
2274 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
2275 * register, so the the bus width is hard coded.
2276 **/
2277static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
2278{
2279 struct e1000_bus_info *bus = &hw->bus;
2280 s32 ret_val;
2281
2282 ret_val = e1000e_get_bus_info_pcie(hw);
2283
Bruce Allanad680762008-03-28 09:15:03 -07002284 /*
2285 * ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07002286 * a configuration space, but do not contain
2287 * PCI Express Capability registers, so bus width
2288 * must be hardcoded.
2289 */
2290 if (bus->width == e1000_bus_width_unknown)
2291 bus->width = e1000_bus_width_pcie_x1;
2292
2293 return ret_val;
2294}
2295
2296/**
2297 * e1000_reset_hw_ich8lan - Reset the hardware
2298 * @hw: pointer to the HW structure
2299 *
2300 * Does a full reset of the hardware which includes a reset of the PHY and
2301 * MAC.
2302 **/
2303static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2304{
Bruce Allandb2932e2009-10-26 11:22:47 +00002305 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002306 u32 ctrl, icr, kab;
2307 s32 ret_val;
2308
Bruce Allanad680762008-03-28 09:15:03 -07002309 /*
2310 * Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07002311 * on the last TLP read/write transaction when MAC is reset.
2312 */
2313 ret_val = e1000e_disable_pcie_master(hw);
2314 if (ret_val) {
2315 hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
2316 }
2317
2318 hw_dbg(hw, "Masking off all interrupts\n");
2319 ew32(IMC, 0xffffffff);
2320
Bruce Allanad680762008-03-28 09:15:03 -07002321 /*
2322 * Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07002323 * any pending transactions to complete before we hit the MAC
2324 * with the global reset.
2325 */
2326 ew32(RCTL, 0);
2327 ew32(TCTL, E1000_TCTL_PSP);
2328 e1e_flush();
2329
2330 msleep(10);
2331
2332 /* Workaround for ICH8 bit corruption issue in FIFO memory */
2333 if (hw->mac.type == e1000_ich8lan) {
2334 /* Set Tx and Rx buffer allocation to 8k apiece. */
2335 ew32(PBA, E1000_PBA_8K);
2336 /* Set Packet Buffer Size to 16k. */
2337 ew32(PBS, E1000_PBS_16K);
2338 }
2339
2340 ctrl = er32(CTRL);
2341
2342 if (!e1000_check_reset_block(hw)) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00002343 /* Clear PHY Reset Asserted bit */
2344 if (hw->mac.type >= e1000_pchlan) {
2345 u32 status = er32(STATUS);
2346 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
2347 }
2348
Bruce Allanad680762008-03-28 09:15:03 -07002349 /*
2350 * PHY HW reset requires MAC CORE reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07002351 * time to make sure the interface between MAC and the
2352 * external PHY is reset.
2353 */
2354 ctrl |= E1000_CTRL_PHY_RST;
2355 }
2356 ret_val = e1000_acquire_swflag_ich8lan(hw);
Jeff Kirsher30bb0e02008-12-11 21:28:11 -08002357 /* Whether or not the swflag was acquired, we need to reset the part */
Bruce Allan0285c8d2008-11-21 16:59:54 -08002358 hw_dbg(hw, "Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359 ew32(CTRL, (ctrl | E1000_CTRL_RST));
2360 msleep(20);
2361
Bruce Allanfc0c7762009-07-01 13:27:55 +00002362 if (!ret_val)
Jeff Kirsher30bb0e02008-12-11 21:28:11 -08002363 e1000_release_swflag_ich8lan(hw);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07002364
Bruce Allanfc0c7762009-07-01 13:27:55 +00002365 if (ctrl & E1000_CTRL_PHY_RST)
2366 ret_val = hw->phy.ops.get_cfg_done(hw);
2367
2368 if (hw->mac.type >= e1000_ich10lan) {
2369 e1000_lan_init_done_ich8lan(hw);
2370 } else {
2371 ret_val = e1000e_get_auto_rd_done(hw);
2372 if (ret_val) {
2373 /*
2374 * When auto config read does not complete, do not
2375 * return with an error. This can happen in situations
2376 * where there is no eeprom and prevents getting link.
2377 */
2378 hw_dbg(hw, "Auto Read Done did not complete\n");
2379 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002380 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002381 /* Dummy read to clear the phy wakeup bit after lcd reset */
2382 if (hw->mac.type == e1000_pchlan)
2383 e1e_rphy(hw, BM_WUC, &reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384
Bruce Allan7d3cabb2009-07-01 13:29:08 +00002385 /*
2386 * For PCH, this write will make sure that any noise
2387 * will be detected as a CRC error and be dropped rather than show up
2388 * as a bad packet to the DMA engine.
2389 */
2390 if (hw->mac.type == e1000_pchlan)
2391 ew32(CRC_OFFSET, 0x65656565);
2392
Auke Kokbc7f75f2007-09-17 12:30:59 -07002393 ew32(IMC, 0xffffffff);
2394 icr = er32(ICR);
2395
2396 kab = er32(KABGTXD);
2397 kab |= E1000_KABGTXD_BGSQLBIAS;
2398 ew32(KABGTXD, kab);
2399
Bruce Allana4f58f52009-06-02 11:29:18 +00002400 if (hw->mac.type == e1000_pchlan)
2401 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2402
Auke Kokbc7f75f2007-09-17 12:30:59 -07002403 return ret_val;
2404}
2405
2406/**
2407 * e1000_init_hw_ich8lan - Initialize the hardware
2408 * @hw: pointer to the HW structure
2409 *
2410 * Prepares the hardware for transmit and receive by doing the following:
2411 * - initialize hardware bits
2412 * - initialize LED identification
2413 * - setup receive address registers
2414 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08002415 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07002416 * - clear statistics
2417 **/
2418static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
2419{
2420 struct e1000_mac_info *mac = &hw->mac;
2421 u32 ctrl_ext, txdctl, snoop;
2422 s32 ret_val;
2423 u16 i;
2424
2425 e1000_initialize_hw_bits_ich8lan(hw);
2426
2427 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00002428 ret_val = mac->ops.id_led_init(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002429 if (ret_val) {
2430 hw_dbg(hw, "Error initializing identification LED\n");
2431 return ret_val;
2432 }
2433
2434 /* Setup the receive address. */
2435 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
2436
2437 /* Zero out the Multicast HASH table */
2438 hw_dbg(hw, "Zeroing the MTA\n");
2439 for (i = 0; i < mac->mta_reg_count; i++)
2440 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
2441
Bruce Allanfc0c7762009-07-01 13:27:55 +00002442 /*
2443 * The 82578 Rx buffer will stall if wakeup is enabled in host and
2444 * the ME. Reading the BM_WUC register will clear the host wakeup bit.
2445 * Reset the phy after disabling host wakeup to reset the Rx buffer.
2446 */
2447 if (hw->phy.type == e1000_phy_82578) {
2448 hw->phy.ops.read_phy_reg(hw, BM_WUC, &i);
2449 ret_val = e1000_phy_hw_reset_ich8lan(hw);
2450 if (ret_val)
2451 return ret_val;
2452 }
2453
Auke Kokbc7f75f2007-09-17 12:30:59 -07002454 /* Setup link and flow control */
2455 ret_val = e1000_setup_link_ich8lan(hw);
2456
2457 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002458 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002459 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2460 E1000_TXDCTL_FULL_TX_DESC_WB;
2461 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2462 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002463 ew32(TXDCTL(0), txdctl);
2464 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2466 E1000_TXDCTL_FULL_TX_DESC_WB;
2467 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2468 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002469 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470
Bruce Allanad680762008-03-28 09:15:03 -07002471 /*
2472 * ICH8 has opposite polarity of no_snoop bits.
2473 * By default, we should use snoop behavior.
2474 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002475 if (mac->type == e1000_ich8lan)
2476 snoop = PCIE_ICH8_SNOOP_ALL;
2477 else
2478 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
2479 e1000e_set_pcie_no_snoop(hw, snoop);
2480
2481 ctrl_ext = er32(CTRL_EXT);
2482 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2483 ew32(CTRL_EXT, ctrl_ext);
2484
Bruce Allanad680762008-03-28 09:15:03 -07002485 /*
2486 * Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07002487 * important that we do this after we have tried to establish link
2488 * because the symbol error count will increment wildly if there
2489 * is no link.
2490 */
2491 e1000_clear_hw_cntrs_ich8lan(hw);
2492
2493 return 0;
2494}
2495/**
2496 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
2497 * @hw: pointer to the HW structure
2498 *
2499 * Sets/Clears required hardware bits necessary for correctly setting up the
2500 * hardware for transmit and receive.
2501 **/
2502static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
2503{
2504 u32 reg;
2505
2506 /* Extended Device Control */
2507 reg = er32(CTRL_EXT);
2508 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00002509 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
2510 if (hw->mac.type >= e1000_pchlan)
2511 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002512 ew32(CTRL_EXT, reg);
2513
2514 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002515 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002516 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002517 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002518
2519 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002520 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002522 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002523
2524 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002525 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526 if (hw->mac.type == e1000_ich8lan)
2527 reg |= (1 << 28) | (1 << 29);
2528 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002529 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530
2531 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002532 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002533 if (er32(TCTL) & E1000_TCTL_MULR)
2534 reg &= ~(1 << 28);
2535 else
2536 reg |= (1 << 28);
2537 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002538 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002539
2540 /* Device Status */
2541 if (hw->mac.type == e1000_ich8lan) {
2542 reg = er32(STATUS);
2543 reg &= ~(1 << 31);
2544 ew32(STATUS, reg);
2545 }
2546}
2547
2548/**
2549 * e1000_setup_link_ich8lan - Setup flow control and link settings
2550 * @hw: pointer to the HW structure
2551 *
2552 * Determines which flow control settings to use, then configures flow
2553 * control. Calls the appropriate media-specific link configuration
2554 * function. Assuming the adapter has a valid link partner, a valid link
2555 * should be established. Assumes the hardware has previously been reset
2556 * and the transmitter and receiver are not enabled.
2557 **/
2558static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
2559{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560 s32 ret_val;
2561
2562 if (e1000_check_reset_block(hw))
2563 return 0;
2564
Bruce Allanad680762008-03-28 09:15:03 -07002565 /*
2566 * ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07002567 * the default flow control setting, so we explicitly
2568 * set it to full.
2569 */
Bruce Allan37289d92009-06-02 11:29:37 +00002570 if (hw->fc.requested_mode == e1000_fc_default) {
2571 /* Workaround h/w hang when Tx flow control enabled */
2572 if (hw->mac.type == e1000_pchlan)
2573 hw->fc.requested_mode = e1000_fc_rx_pause;
2574 else
2575 hw->fc.requested_mode = e1000_fc_full;
2576 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002578 /*
2579 * Save off the requested flow control mode for use later. Depending
2580 * on the link partner's capabilities, we may or may not use this mode.
2581 */
2582 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002583
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002584 hw_dbg(hw, "After fix-ups FlowControl is now = %x\n",
2585 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002586
2587 /* Continue to configure the copper link. */
2588 ret_val = e1000_setup_copper_link_ich8lan(hw);
2589 if (ret_val)
2590 return ret_val;
2591
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002592 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00002593 if ((hw->phy.type == e1000_phy_82578) ||
2594 (hw->phy.type == e1000_phy_82577)) {
2595 ret_val = hw->phy.ops.write_phy_reg(hw,
2596 PHY_REG(BM_PORT_CTRL_PAGE, 27),
2597 hw->fc.pause_time);
2598 if (ret_val)
2599 return ret_val;
2600 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002601
2602 return e1000e_set_fc_watermarks(hw);
2603}
2604
2605/**
2606 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
2607 * @hw: pointer to the HW structure
2608 *
2609 * Configures the kumeran interface to the PHY to wait the appropriate time
2610 * when polling the PHY, then call the generic setup_copper_link to finish
2611 * configuring the copper link.
2612 **/
2613static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
2614{
2615 u32 ctrl;
2616 s32 ret_val;
2617 u16 reg_data;
2618
2619 ctrl = er32(CTRL);
2620 ctrl |= E1000_CTRL_SLU;
2621 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2622 ew32(CTRL, ctrl);
2623
Bruce Allanad680762008-03-28 09:15:03 -07002624 /*
2625 * Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07002626 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07002627 * this fixes erroneous timeouts at 10Mbps.
2628 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002629 ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
2630 if (ret_val)
2631 return ret_val;
2632 ret_val = e1000e_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
2633 if (ret_val)
2634 return ret_val;
2635 reg_data |= 0x3F;
2636 ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
2637 if (ret_val)
2638 return ret_val;
2639
Bruce Allana4f58f52009-06-02 11:29:18 +00002640 switch (hw->phy.type) {
2641 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002642 ret_val = e1000e_copper_link_setup_igp(hw);
2643 if (ret_val)
2644 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002645 break;
2646 case e1000_phy_bm:
2647 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002648 ret_val = e1000e_copper_link_setup_m88(hw);
2649 if (ret_val)
2650 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002651 break;
2652 case e1000_phy_82577:
2653 ret_val = e1000_copper_link_setup_82577(hw);
2654 if (ret_val)
2655 return ret_val;
2656 break;
2657 case e1000_phy_ife:
2658 ret_val = hw->phy.ops.read_phy_reg(hw, IFE_PHY_MDIX_CONTROL,
2659 &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002660 if (ret_val)
2661 return ret_val;
2662
2663 reg_data &= ~IFE_PMC_AUTO_MDIX;
2664
2665 switch (hw->phy.mdix) {
2666 case 1:
2667 reg_data &= ~IFE_PMC_FORCE_MDIX;
2668 break;
2669 case 2:
2670 reg_data |= IFE_PMC_FORCE_MDIX;
2671 break;
2672 case 0:
2673 default:
2674 reg_data |= IFE_PMC_AUTO_MDIX;
2675 break;
2676 }
Bruce Allana4f58f52009-06-02 11:29:18 +00002677 ret_val = hw->phy.ops.write_phy_reg(hw, IFE_PHY_MDIX_CONTROL,
2678 reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002679 if (ret_val)
2680 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002681 break;
2682 default:
2683 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002684 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002685 return e1000e_setup_copper_link(hw);
2686}
2687
2688/**
2689 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
2690 * @hw: pointer to the HW structure
2691 * @speed: pointer to store current link speed
2692 * @duplex: pointer to store the current link duplex
2693 *
Bruce Allanad680762008-03-28 09:15:03 -07002694 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07002695 * information and then calls the Kumeran lock loss workaround for links at
2696 * gigabit speeds.
2697 **/
2698static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
2699 u16 *duplex)
2700{
2701 s32 ret_val;
2702
2703 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
2704 if (ret_val)
2705 return ret_val;
2706
Bruce Allan7d3cabb2009-07-01 13:29:08 +00002707 if ((hw->mac.type == e1000_pchlan) && (*speed == SPEED_1000)) {
2708 ret_val = e1000e_write_kmrn_reg(hw,
2709 E1000_KMRNCTRLSTA_K1_CONFIG,
2710 E1000_KMRNCTRLSTA_K1_DISABLE);
2711 if (ret_val)
2712 return ret_val;
2713 }
2714
Auke Kokbc7f75f2007-09-17 12:30:59 -07002715 if ((hw->mac.type == e1000_ich8lan) &&
2716 (hw->phy.type == e1000_phy_igp_3) &&
2717 (*speed == SPEED_1000)) {
2718 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
2719 }
2720
2721 return ret_val;
2722}
2723
2724/**
2725 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
2726 * @hw: pointer to the HW structure
2727 *
2728 * Work-around for 82566 Kumeran PCS lock loss:
2729 * On link status change (i.e. PCI reset, speed change) and link is up and
2730 * speed is gigabit-
2731 * 0) if workaround is optionally disabled do nothing
2732 * 1) wait 1ms for Kumeran link to come up
2733 * 2) check Kumeran Diagnostic register PCS lock loss bit
2734 * 3) if not set the link is locked (all is good), otherwise...
2735 * 4) reset the PHY
2736 * 5) repeat up to 10 times
2737 * Note: this is only called for IGP3 copper when speed is 1gb.
2738 **/
2739static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
2740{
2741 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2742 u32 phy_ctrl;
2743 s32 ret_val;
2744 u16 i, data;
2745 bool link;
2746
2747 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
2748 return 0;
2749
Bruce Allanad680762008-03-28 09:15:03 -07002750 /*
2751 * Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002752 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07002753 * stability
2754 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002755 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2756 if (!link)
2757 return 0;
2758
2759 for (i = 0; i < 10; i++) {
2760 /* read once to clear */
2761 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
2762 if (ret_val)
2763 return ret_val;
2764 /* and again to get new status */
2765 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
2766 if (ret_val)
2767 return ret_val;
2768
2769 /* check for PCS lock */
2770 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
2771 return 0;
2772
2773 /* Issue PHY reset */
2774 e1000_phy_hw_reset(hw);
2775 mdelay(5);
2776 }
2777 /* Disable GigE link negotiation */
2778 phy_ctrl = er32(PHY_CTRL);
2779 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
2780 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
2781 ew32(PHY_CTRL, phy_ctrl);
2782
Bruce Allanad680762008-03-28 09:15:03 -07002783 /*
2784 * Call gig speed drop workaround on Gig disable before accessing
2785 * any PHY registers
2786 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787 e1000e_gig_downshift_workaround_ich8lan(hw);
2788
2789 /* unable to acquire PCS lock */
2790 return -E1000_ERR_PHY;
2791}
2792
2793/**
Bruce Allanad680762008-03-28 09:15:03 -07002794 * e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07002795 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08002796 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07002797 *
2798 * If ICH8, set the current Kumeran workaround state (enabled - TRUE
2799 * /disabled - FALSE).
2800 **/
2801void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
2802 bool state)
2803{
2804 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2805
2806 if (hw->mac.type != e1000_ich8lan) {
2807 hw_dbg(hw, "Workaround applies to ICH8 only.\n");
2808 return;
2809 }
2810
2811 dev_spec->kmrn_lock_loss_workaround_enabled = state;
2812}
2813
2814/**
2815 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
2816 * @hw: pointer to the HW structure
2817 *
2818 * Workaround for 82566 power-down on D3 entry:
2819 * 1) disable gigabit link
2820 * 2) write VR power-down enable
2821 * 3) read it back
2822 * Continue if successful, else issue LCD reset and repeat
2823 **/
2824void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
2825{
2826 u32 reg;
2827 u16 data;
2828 u8 retry = 0;
2829
2830 if (hw->phy.type != e1000_phy_igp_3)
2831 return;
2832
2833 /* Try the workaround twice (if needed) */
2834 do {
2835 /* Disable link */
2836 reg = er32(PHY_CTRL);
2837 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
2838 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
2839 ew32(PHY_CTRL, reg);
2840
Bruce Allanad680762008-03-28 09:15:03 -07002841 /*
2842 * Call gig speed drop workaround on Gig disable before
2843 * accessing any PHY registers
2844 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845 if (hw->mac.type == e1000_ich8lan)
2846 e1000e_gig_downshift_workaround_ich8lan(hw);
2847
2848 /* Write VR power-down enable */
2849 e1e_rphy(hw, IGP3_VR_CTRL, &data);
2850 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
2851 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
2852
2853 /* Read it back and test */
2854 e1e_rphy(hw, IGP3_VR_CTRL, &data);
2855 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
2856 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
2857 break;
2858
2859 /* Issue PHY reset and repeat at most one more time */
2860 reg = er32(CTRL);
2861 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
2862 retry++;
2863 } while (retry);
2864}
2865
2866/**
2867 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
2868 * @hw: pointer to the HW structure
2869 *
2870 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08002871 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07002872 * 1) Set Kumeran Near-end loopback
2873 * 2) Clear Kumeran Near-end loopback
2874 * Should only be called for ICH8[m] devices with IGP_3 Phy.
2875 **/
2876void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
2877{
2878 s32 ret_val;
2879 u16 reg_data;
2880
2881 if ((hw->mac.type != e1000_ich8lan) ||
2882 (hw->phy.type != e1000_phy_igp_3))
2883 return;
2884
2885 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2886 &reg_data);
2887 if (ret_val)
2888 return;
2889 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
2890 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2891 reg_data);
2892 if (ret_val)
2893 return;
2894 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
2895 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
2896 reg_data);
2897}
2898
2899/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002900 * e1000e_disable_gig_wol_ich8lan - disable gig during WoL
2901 * @hw: pointer to the HW structure
2902 *
2903 * During S0 to Sx transition, it is possible the link remains at gig
2904 * instead of negotiating to a lower speed. Before going to Sx, set
2905 * 'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
2906 * to a lower speed.
2907 *
Bruce Allana4f58f52009-06-02 11:29:18 +00002908 * Should only be called for applicable parts.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002909 **/
2910void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
2911{
2912 u32 phy_ctrl;
2913
Bruce Allana4f58f52009-06-02 11:29:18 +00002914 switch (hw->mac.type) {
2915 case e1000_ich9lan:
2916 case e1000_ich10lan:
2917 case e1000_pchlan:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002918 phy_ctrl = er32(PHY_CTRL);
2919 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
2920 E1000_PHY_CTRL_GBE_DISABLE;
2921 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00002922
Bruce Allana4f58f52009-06-02 11:29:18 +00002923 if (hw->mac.type == e1000_pchlan)
Bruce Allan74eee2e2009-10-22 21:22:18 -07002924 e1000_phy_hw_reset_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00002925 default:
2926 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002927 }
2928
2929 return;
2930}
2931
2932/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933 * e1000_cleanup_led_ich8lan - Restore the default LED operation
2934 * @hw: pointer to the HW structure
2935 *
2936 * Return the LED back to the default configuration.
2937 **/
2938static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
2939{
2940 if (hw->phy.type == e1000_phy_ife)
2941 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
2942
2943 ew32(LEDCTL, hw->mac.ledctl_default);
2944 return 0;
2945}
2946
2947/**
Auke Kok489815c2008-02-21 15:11:07 -08002948 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07002949 * @hw: pointer to the HW structure
2950 *
Auke Kok489815c2008-02-21 15:11:07 -08002951 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002952 **/
2953static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
2954{
2955 if (hw->phy.type == e1000_phy_ife)
2956 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
2957 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
2958
2959 ew32(LEDCTL, hw->mac.ledctl_mode2);
2960 return 0;
2961}
2962
2963/**
Auke Kok489815c2008-02-21 15:11:07 -08002964 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07002965 * @hw: pointer to the HW structure
2966 *
Auke Kok489815c2008-02-21 15:11:07 -08002967 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002968 **/
2969static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
2970{
2971 if (hw->phy.type == e1000_phy_ife)
2972 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
2973 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
2974
2975 ew32(LEDCTL, hw->mac.ledctl_mode1);
2976 return 0;
2977}
2978
2979/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002980 * e1000_setup_led_pchlan - Configures SW controllable LED
2981 * @hw: pointer to the HW structure
2982 *
2983 * This prepares the SW controllable LED for use.
2984 **/
2985static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
2986{
2987 return hw->phy.ops.write_phy_reg(hw, HV_LED_CONFIG,
2988 (u16)hw->mac.ledctl_mode1);
2989}
2990
2991/**
2992 * e1000_cleanup_led_pchlan - Restore the default LED operation
2993 * @hw: pointer to the HW structure
2994 *
2995 * Return the LED back to the default configuration.
2996 **/
2997static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
2998{
2999 return hw->phy.ops.write_phy_reg(hw, HV_LED_CONFIG,
3000 (u16)hw->mac.ledctl_default);
3001}
3002
3003/**
3004 * e1000_led_on_pchlan - Turn LEDs on
3005 * @hw: pointer to the HW structure
3006 *
3007 * Turn on the LEDs.
3008 **/
3009static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
3010{
3011 u16 data = (u16)hw->mac.ledctl_mode2;
3012 u32 i, led;
3013
3014 /*
3015 * If no link, then turn LED on by setting the invert bit
3016 * for each LED that's mode is "link_up" in ledctl_mode2.
3017 */
3018 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3019 for (i = 0; i < 3; i++) {
3020 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3021 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3022 E1000_LEDCTL_MODE_LINK_UP)
3023 continue;
3024 if (led & E1000_PHY_LED0_IVRT)
3025 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3026 else
3027 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3028 }
3029 }
3030
3031 return hw->phy.ops.write_phy_reg(hw, HV_LED_CONFIG, data);
3032}
3033
3034/**
3035 * e1000_led_off_pchlan - Turn LEDs off
3036 * @hw: pointer to the HW structure
3037 *
3038 * Turn off the LEDs.
3039 **/
3040static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
3041{
3042 u16 data = (u16)hw->mac.ledctl_mode1;
3043 u32 i, led;
3044
3045 /*
3046 * If no link, then turn LED off by clearing the invert bit
3047 * for each LED that's mode is "link_up" in ledctl_mode1.
3048 */
3049 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3050 for (i = 0; i < 3; i++) {
3051 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3052 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3053 E1000_LEDCTL_MODE_LINK_UP)
3054 continue;
3055 if (led & E1000_PHY_LED0_IVRT)
3056 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3057 else
3058 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3059 }
3060 }
3061
3062 return hw->phy.ops.write_phy_reg(hw, HV_LED_CONFIG, data);
3063}
3064
3065/**
Bruce Allanf4187b52008-08-26 18:36:50 -07003066 * e1000_get_cfg_done_ich8lan - Read config done bit
3067 * @hw: pointer to the HW structure
3068 *
3069 * Read the management control register for the config done bit for
3070 * completion status. NOTE: silicon which is EEPROM-less will fail trying
3071 * to read the config done bit, so an error is *ONLY* logged and returns
Bruce Allana4f58f52009-06-02 11:29:18 +00003072 * 0. If we were to return with error, EEPROM-less silicon
Bruce Allanf4187b52008-08-26 18:36:50 -07003073 * would not be able to be reset or change link.
3074 **/
3075static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
3076{
3077 u32 bank = 0;
3078
Bruce Allanfc0c7762009-07-01 13:27:55 +00003079 if (hw->mac.type >= e1000_pchlan) {
3080 u32 status = er32(STATUS);
3081
3082 if (status & E1000_STATUS_PHYRA)
3083 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
3084 else
3085 hw_dbg(hw,
3086 "PHY Reset Asserted not set - needs delay\n");
3087 }
3088
Bruce Allanf4187b52008-08-26 18:36:50 -07003089 e1000e_get_cfg_done(hw);
3090
3091 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allana4f58f52009-06-02 11:29:18 +00003092 if ((hw->mac.type != e1000_ich10lan) &&
3093 (hw->mac.type != e1000_pchlan)) {
Bruce Allanf4187b52008-08-26 18:36:50 -07003094 if (((er32(EECD) & E1000_EECD_PRES) == 0) &&
3095 (hw->phy.type == e1000_phy_igp_3)) {
3096 e1000e_phy_init_script_igp3(hw);
3097 }
3098 } else {
3099 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
3100 /* Maybe we should do a basic PHY config */
3101 hw_dbg(hw, "EEPROM not present\n");
3102 return -E1000_ERR_CONFIG;
3103 }
3104 }
3105
3106 return 0;
3107}
3108
3109/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003110 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
3111 * @hw: pointer to the HW structure
3112 *
3113 * Clears hardware counters specific to the silicon family and calls
3114 * clear_hw_cntrs_generic to clear all general purpose counters.
3115 **/
3116static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
3117{
3118 u32 temp;
Bruce Allana4f58f52009-06-02 11:29:18 +00003119 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003120
3121 e1000e_clear_hw_cntrs_base(hw);
3122
3123 temp = er32(ALGNERRC);
3124 temp = er32(RXERRC);
3125 temp = er32(TNCRS);
3126 temp = er32(CEXTERR);
3127 temp = er32(TSCTC);
3128 temp = er32(TSCTFC);
3129
3130 temp = er32(MGTPRC);
3131 temp = er32(MGTPDC);
3132 temp = er32(MGTPTC);
3133
3134 temp = er32(IAC);
3135 temp = er32(ICRXOC);
3136
Bruce Allana4f58f52009-06-02 11:29:18 +00003137 /* Clear PHY statistics registers */
3138 if ((hw->phy.type == e1000_phy_82578) ||
3139 (hw->phy.type == e1000_phy_82577)) {
3140 hw->phy.ops.read_phy_reg(hw, HV_SCC_UPPER, &phy_data);
3141 hw->phy.ops.read_phy_reg(hw, HV_SCC_LOWER, &phy_data);
3142 hw->phy.ops.read_phy_reg(hw, HV_ECOL_UPPER, &phy_data);
3143 hw->phy.ops.read_phy_reg(hw, HV_ECOL_LOWER, &phy_data);
3144 hw->phy.ops.read_phy_reg(hw, HV_MCC_UPPER, &phy_data);
3145 hw->phy.ops.read_phy_reg(hw, HV_MCC_LOWER, &phy_data);
3146 hw->phy.ops.read_phy_reg(hw, HV_LATECOL_UPPER, &phy_data);
3147 hw->phy.ops.read_phy_reg(hw, HV_LATECOL_LOWER, &phy_data);
3148 hw->phy.ops.read_phy_reg(hw, HV_COLC_UPPER, &phy_data);
3149 hw->phy.ops.read_phy_reg(hw, HV_COLC_LOWER, &phy_data);
3150 hw->phy.ops.read_phy_reg(hw, HV_DC_UPPER, &phy_data);
3151 hw->phy.ops.read_phy_reg(hw, HV_DC_LOWER, &phy_data);
3152 hw->phy.ops.read_phy_reg(hw, HV_TNCRS_UPPER, &phy_data);
3153 hw->phy.ops.read_phy_reg(hw, HV_TNCRS_LOWER, &phy_data);
3154 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003155}
3156
3157static struct e1000_mac_operations ich8_mac_ops = {
Bruce Allana4f58f52009-06-02 11:29:18 +00003158 .id_led_init = e1000e_id_led_init,
Bruce Allan4662e822008-08-26 18:37:06 -07003159 .check_mng_mode = e1000_check_mng_mode_ich8lan,
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003160 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003161 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003162 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
3163 .get_bus_info = e1000_get_bus_info_ich8lan,
3164 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003165 /* led_on dependent on mac type */
3166 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003167 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168 .reset_hw = e1000_reset_hw_ich8lan,
3169 .init_hw = e1000_init_hw_ich8lan,
3170 .setup_link = e1000_setup_link_ich8lan,
3171 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003172 /* id_led_init dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003173};
3174
3175static struct e1000_phy_operations ich8_phy_ops = {
3176 .acquire_phy = e1000_acquire_swflag_ich8lan,
3177 .check_reset_block = e1000_check_reset_block_ich8lan,
3178 .commit_phy = NULL,
3179 .force_speed_duplex = e1000_phy_force_speed_duplex_ich8lan,
Bruce Allanf4187b52008-08-26 18:36:50 -07003180 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003181 .get_cable_length = e1000e_get_cable_length_igp_2,
3182 .get_phy_info = e1000_get_phy_info_ich8lan,
3183 .read_phy_reg = e1000e_read_phy_reg_igp,
3184 .release_phy = e1000_release_swflag_ich8lan,
3185 .reset_phy = e1000_phy_hw_reset_ich8lan,
3186 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
3187 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
3188 .write_phy_reg = e1000e_write_phy_reg_igp,
3189};
3190
3191static struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allanca15df52009-10-26 11:23:43 +00003192 .acquire_nvm = e1000_acquire_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003193 .read_nvm = e1000_read_nvm_ich8lan,
Bruce Allanca15df52009-10-26 11:23:43 +00003194 .release_nvm = e1000_release_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003195 .update_nvm = e1000_update_nvm_checksum_ich8lan,
3196 .valid_led_default = e1000_valid_led_default_ich8lan,
3197 .validate_nvm = e1000_validate_nvm_checksum_ich8lan,
3198 .write_nvm = e1000_write_nvm_ich8lan,
3199};
3200
3201struct e1000_info e1000_ich8_info = {
3202 .mac = e1000_ich8lan,
3203 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003204 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003205 | FLAG_RX_CSUM_ENABLED
3206 | FLAG_HAS_CTRLEXT_ON_LOAD
3207 | FLAG_HAS_AMT
3208 | FLAG_HAS_FLASH
3209 | FLAG_APME_IN_WUC,
3210 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003211 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003212 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003213 .mac_ops = &ich8_mac_ops,
3214 .phy_ops = &ich8_phy_ops,
3215 .nvm_ops = &ich8_nvm_ops,
3216};
3217
3218struct e1000_info e1000_ich9_info = {
3219 .mac = e1000_ich9lan,
3220 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003221 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003222 | FLAG_HAS_WOL
3223 | FLAG_RX_CSUM_ENABLED
3224 | FLAG_HAS_CTRLEXT_ON_LOAD
3225 | FLAG_HAS_AMT
3226 | FLAG_HAS_ERT
3227 | FLAG_HAS_FLASH
3228 | FLAG_APME_IN_WUC,
3229 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003230 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003231 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003232 .mac_ops = &ich8_mac_ops,
3233 .phy_ops = &ich8_phy_ops,
3234 .nvm_ops = &ich8_nvm_ops,
3235};
3236
Bruce Allanf4187b52008-08-26 18:36:50 -07003237struct e1000_info e1000_ich10_info = {
3238 .mac = e1000_ich10lan,
3239 .flags = FLAG_HAS_JUMBO_FRAMES
3240 | FLAG_IS_ICH
3241 | FLAG_HAS_WOL
3242 | FLAG_RX_CSUM_ENABLED
3243 | FLAG_HAS_CTRLEXT_ON_LOAD
3244 | FLAG_HAS_AMT
3245 | FLAG_HAS_ERT
3246 | FLAG_HAS_FLASH
3247 | FLAG_APME_IN_WUC,
3248 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003249 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07003250 .get_variants = e1000_get_variants_ich8lan,
3251 .mac_ops = &ich8_mac_ops,
3252 .phy_ops = &ich8_phy_ops,
3253 .nvm_ops = &ich8_nvm_ops,
3254};
Bruce Allana4f58f52009-06-02 11:29:18 +00003255
3256struct e1000_info e1000_pch_info = {
3257 .mac = e1000_pchlan,
3258 .flags = FLAG_IS_ICH
3259 | FLAG_HAS_WOL
3260 | FLAG_RX_CSUM_ENABLED
3261 | FLAG_HAS_CTRLEXT_ON_LOAD
3262 | FLAG_HAS_AMT
3263 | FLAG_HAS_FLASH
3264 | FLAG_HAS_JUMBO_FRAMES
3265 | FLAG_APME_IN_WUC,
3266 .pba = 26,
3267 .max_hw_frame_size = 4096,
3268 .get_variants = e1000_get_variants_ich8lan,
3269 .mac_ops = &ich8_mac_ops,
3270 .phy_ops = &ich8_phy_ops,
3271 .nvm_ops = &ich8_nvm_ops,
3272};