blob: 6efb77fbbd70c11e1cc0ed00bb5b16d0af29ebfd [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanc7e54b12009-11-20 23:25:45 +00004 Copyright(c) 1999 - 2009 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
Auke Kokbc7f75f2007-09-17 12:30:59 -070057#include "e1000.h"
58
59#define ICH_FLASH_GFPREG 0x0000
60#define ICH_FLASH_HSFSTS 0x0004
61#define ICH_FLASH_HSFCTL 0x0006
62#define ICH_FLASH_FADDR 0x0008
63#define ICH_FLASH_FDATA0 0x0010
Bruce Allan4a770352008-10-01 17:18:35 -070064#define ICH_FLASH_PR0 0x0074
Auke Kokbc7f75f2007-09-17 12:30:59 -070065
66#define ICH_FLASH_READ_COMMAND_TIMEOUT 500
67#define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
68#define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
69#define ICH_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
70#define ICH_FLASH_CYCLE_REPEAT_COUNT 10
71
72#define ICH_CYCLE_READ 0
73#define ICH_CYCLE_WRITE 2
74#define ICH_CYCLE_ERASE 3
75
76#define FLASH_GFPREG_BASE_MASK 0x1FFF
77#define FLASH_SECTOR_ADDR_SHIFT 12
78
79#define ICH_FLASH_SEG_SIZE_256 256
80#define ICH_FLASH_SEG_SIZE_4K 4096
81#define ICH_FLASH_SEG_SIZE_8K 8192
82#define ICH_FLASH_SEG_SIZE_64K 65536
83
84
85#define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
86
87#define E1000_ICH_MNG_IAMT_MODE 0x2
88
89#define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
90 (ID_LED_DEF1_OFF2 << 8) | \
91 (ID_LED_DEF1_ON2 << 4) | \
92 (ID_LED_DEF1_DEF2))
93
94#define E1000_ICH_NVM_SIG_WORD 0x13
95#define E1000_ICH_NVM_SIG_MASK 0xC000
Bruce Allane2434552008-11-21 17:02:41 -080096#define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
97#define E1000_ICH_NVM_SIG_VALUE 0x80
Auke Kokbc7f75f2007-09-17 12:30:59 -070098
99#define E1000_ICH8_LAN_INIT_TIMEOUT 1500
100
101#define E1000_FEXTNVM_SW_CONFIG 1
102#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
103
104#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
105
106#define E1000_ICH_RAR_ENTRIES 7
107
108#define PHY_PAGE_SHIFT 5
109#define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
110 ((reg) & MAX_PHY_REG_ADDRESS))
111#define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
112#define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
113
114#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
115#define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
116#define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
117
Bruce Allana4f58f52009-06-02 11:29:18 +0000118#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
119
Bruce Allan53ac5a82009-10-26 11:23:06 +0000120#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
121
Bruce Allanf523d212009-10-29 13:45:45 +0000122/* SMBus Address Phy Register */
123#define HV_SMB_ADDR PHY_REG(768, 26)
124#define HV_SMB_ADDR_PEC_EN 0x0200
125#define HV_SMB_ADDR_VALID 0x0080
126
127/* Strapping Option Register - RO */
128#define E1000_STRAP 0x0000C
129#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
130#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
131
Bruce Allanfa2ce132009-10-26 11:23:25 +0000132/* OEM Bits Phy Register */
133#define HV_OEM_BITS PHY_REG(768, 25)
134#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
Bruce Allanf523d212009-10-29 13:45:45 +0000135#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
Bruce Allanfa2ce132009-10-26 11:23:25 +0000136#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
137
Bruce Allan1d5846b2009-10-29 13:46:05 +0000138#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
139#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
140
Auke Kokbc7f75f2007-09-17 12:30:59 -0700141/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
142/* Offset 04h HSFSTS */
143union ich8_hws_flash_status {
144 struct ich8_hsfsts {
145 u16 flcdone :1; /* bit 0 Flash Cycle Done */
146 u16 flcerr :1; /* bit 1 Flash Cycle Error */
147 u16 dael :1; /* bit 2 Direct Access error Log */
148 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
149 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
150 u16 reserved1 :2; /* bit 13:6 Reserved */
151 u16 reserved2 :6; /* bit 13:6 Reserved */
152 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
153 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
154 } hsf_status;
155 u16 regval;
156};
157
158/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
159/* Offset 06h FLCTL */
160union ich8_hws_flash_ctrl {
161 struct ich8_hsflctl {
162 u16 flcgo :1; /* 0 Flash Cycle Go */
163 u16 flcycle :2; /* 2:1 Flash Cycle */
164 u16 reserved :5; /* 7:3 Reserved */
165 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
166 u16 flockdn :6; /* 15:10 Reserved */
167 } hsf_ctrl;
168 u16 regval;
169};
170
171/* ICH Flash Region Access Permissions */
172union ich8_hws_flash_regacc {
173 struct ich8_flracc {
174 u32 grra :8; /* 0:7 GbE region Read Access */
175 u32 grwa :8; /* 8:15 GbE region Write Access */
176 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
177 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
178 } hsf_flregacc;
179 u16 regval;
180};
181
Bruce Allan4a770352008-10-01 17:18:35 -0700182/* ICH Flash Protected Region */
183union ich8_flash_protected_range {
184 struct ich8_pr {
185 u32 base:13; /* 0:12 Protected Range Base */
186 u32 reserved1:2; /* 13:14 Reserved */
187 u32 rpe:1; /* 15 Read Protection Enable */
188 u32 limit:13; /* 16:28 Protected Range Limit */
189 u32 reserved2:2; /* 29:30 Reserved */
190 u32 wpe:1; /* 31 Write Protection Enable */
191 } range;
192 u32 regval;
193};
194
Auke Kokbc7f75f2007-09-17 12:30:59 -0700195static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
196static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
197static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
198static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw);
199static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
200static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
201 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700202static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
203 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700204static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
205 u16 *data);
206static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
207 u8 size, u16 *data);
208static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
209static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700210static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000211static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
212static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
213static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
214static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
215static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
216static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
217static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
218static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000219static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000220static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000221static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000222static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700223
224static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
225{
226 return readw(hw->flash_address + reg);
227}
228
229static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
230{
231 return readl(hw->flash_address + reg);
232}
233
234static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
235{
236 writew(val, hw->flash_address + reg);
237}
238
239static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
240{
241 writel(val, hw->flash_address + reg);
242}
243
244#define er16flash(reg) __er16flash(hw, (reg))
245#define er32flash(reg) __er32flash(hw, (reg))
246#define ew16flash(reg,val) __ew16flash(hw, (reg), (val))
247#define ew32flash(reg,val) __ew32flash(hw, (reg), (val))
248
249/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000250 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
251 * @hw: pointer to the HW structure
252 *
253 * Initialize family-specific PHY parameters and function pointers.
254 **/
255static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
256{
257 struct e1000_phy_info *phy = &hw->phy;
258 s32 ret_val = 0;
259
260 phy->addr = 1;
261 phy->reset_delay_us = 100;
262
263 phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
Bruce Allan94d81862009-11-20 23:25:26 +0000264 phy->ops.read_reg = e1000_read_phy_reg_hv;
265 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000266 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
267 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000268 phy->ops.write_reg = e1000_write_phy_reg_hv;
269 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan17f208d2009-12-01 15:47:22 +0000270 phy->ops.power_up = e1000_power_up_phy_copper;
271 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000272 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
273
274 phy->id = e1000_phy_unknown;
275 e1000e_get_phy_id(hw);
276 phy->type = e1000e_get_phy_type_from_id(phy->id);
277
278 if (phy->type == e1000_phy_82577) {
279 phy->ops.check_polarity = e1000_check_polarity_82577;
280 phy->ops.force_speed_duplex =
281 e1000_phy_force_speed_duplex_82577;
282 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000283 phy->ops.get_info = e1000_get_phy_info_82577;
284 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allana4f58f52009-06-02 11:29:18 +0000285 }
286
287 return ret_val;
288}
289
290/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700291 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
292 * @hw: pointer to the HW structure
293 *
294 * Initialize family-specific PHY parameters and function pointers.
295 **/
296static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
297{
298 struct e1000_phy_info *phy = &hw->phy;
299 s32 ret_val;
300 u16 i = 0;
301
302 phy->addr = 1;
303 phy->reset_delay_us = 100;
304
Bruce Allan17f208d2009-12-01 15:47:22 +0000305 phy->ops.power_up = e1000_power_up_phy_copper;
306 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
307
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700308 /*
309 * We may need to do this twice - once for IGP and if that fails,
310 * we'll set BM func pointers and try again
311 */
312 ret_val = e1000e_determine_phy_address(hw);
313 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000314 phy->ops.write_reg = e1000e_write_phy_reg_bm;
315 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700316 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000317 if (ret_val) {
318 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700319 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000320 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700321 }
322
Auke Kokbc7f75f2007-09-17 12:30:59 -0700323 phy->id = 0;
324 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
325 (i++ < 100)) {
326 msleep(1);
327 ret_val = e1000e_get_phy_id(hw);
328 if (ret_val)
329 return ret_val;
330 }
331
332 /* Verify phy id */
333 switch (phy->id) {
334 case IGP03E1000_E_PHY_ID:
335 phy->type = e1000_phy_igp_3;
336 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000337 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
338 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700339 break;
340 case IFE_E_PHY_ID:
341 case IFE_PLUS_E_PHY_ID:
342 case IFE_C_E_PHY_ID:
343 phy->type = e1000_phy_ife;
344 phy->autoneg_mask = E1000_ALL_NOT_GIG;
345 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700346 case BME1000_E_PHY_ID:
347 phy->type = e1000_phy_bm;
348 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000349 phy->ops.read_reg = e1000e_read_phy_reg_bm;
350 phy->ops.write_reg = e1000e_write_phy_reg_bm;
351 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700352 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700353 default:
354 return -E1000_ERR_PHY;
355 break;
356 }
357
Bruce Allana4f58f52009-06-02 11:29:18 +0000358 phy->ops.check_polarity = e1000_check_polarity_ife_ich8lan;
359
Auke Kokbc7f75f2007-09-17 12:30:59 -0700360 return 0;
361}
362
363/**
364 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
365 * @hw: pointer to the HW structure
366 *
367 * Initialize family-specific NVM parameters and function
368 * pointers.
369 **/
370static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
371{
372 struct e1000_nvm_info *nvm = &hw->nvm;
373 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000374 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700375 u16 i;
376
Bruce Allanad680762008-03-28 09:15:03 -0700377 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700378 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000379 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700380 return -E1000_ERR_CONFIG;
381 }
382
383 nvm->type = e1000_nvm_flash_sw;
384
385 gfpreg = er32flash(ICH_FLASH_GFPREG);
386
Bruce Allanad680762008-03-28 09:15:03 -0700387 /*
388 * sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700389 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700390 * the overall size.
391 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700392 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
393 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
394
395 /* flash_base_addr is byte-aligned */
396 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
397
Bruce Allanad680762008-03-28 09:15:03 -0700398 /*
399 * find total size of the NVM, then cut in half since the total
400 * size represents two separate NVM banks.
401 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700402 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
403 << FLASH_SECTOR_ADDR_SHIFT;
404 nvm->flash_bank_size /= 2;
405 /* Adjust to word count */
406 nvm->flash_bank_size /= sizeof(u16);
407
408 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
409
410 /* Clear shadow ram */
411 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000412 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700413 dev_spec->shadow_ram[i].value = 0xFFFF;
414 }
415
416 return 0;
417}
418
419/**
420 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
421 * @hw: pointer to the HW structure
422 *
423 * Initialize family-specific MAC parameters and function
424 * pointers.
425 **/
426static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
427{
428 struct e1000_hw *hw = &adapter->hw;
429 struct e1000_mac_info *mac = &hw->mac;
430
431 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700432 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700433
434 /* Set mta register count */
435 mac->mta_reg_count = 32;
436 /* Set rar entry count */
437 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
438 if (mac->type == e1000_ich8lan)
439 mac->rar_entry_count--;
440 /* Set if manageability features are enabled. */
Bruce Allan564ea9b2009-11-20 23:26:44 +0000441 mac->arc_subsystem_valid = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700442
Bruce Allana4f58f52009-06-02 11:29:18 +0000443 /* LED operations */
444 switch (mac->type) {
445 case e1000_ich8lan:
446 case e1000_ich9lan:
447 case e1000_ich10lan:
448 /* ID LED init */
449 mac->ops.id_led_init = e1000e_id_led_init;
450 /* setup LED */
451 mac->ops.setup_led = e1000e_setup_led_generic;
452 /* cleanup LED */
453 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
454 /* turn on/off LED */
455 mac->ops.led_on = e1000_led_on_ich8lan;
456 mac->ops.led_off = e1000_led_off_ich8lan;
457 break;
458 case e1000_pchlan:
459 /* ID LED init */
460 mac->ops.id_led_init = e1000_id_led_init_pchlan;
461 /* setup LED */
462 mac->ops.setup_led = e1000_setup_led_pchlan;
463 /* cleanup LED */
464 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
465 /* turn on/off LED */
466 mac->ops.led_on = e1000_led_on_pchlan;
467 mac->ops.led_off = e1000_led_off_pchlan;
468 break;
469 default:
470 break;
471 }
472
Auke Kokbc7f75f2007-09-17 12:30:59 -0700473 /* Enable PCS Lock-loss workaround for ICH8 */
474 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000475 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700476
477 return 0;
478}
479
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000480/**
481 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
482 * @hw: pointer to the HW structure
483 *
484 * Checks to see of the link status of the hardware has changed. If a
485 * change in link status has been detected, then we read the PHY registers
486 * to get the current speed/duplex if link exists.
487 **/
488static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
489{
490 struct e1000_mac_info *mac = &hw->mac;
491 s32 ret_val;
492 bool link;
493
494 /*
495 * We only want to go out to the PHY registers to see if Auto-Neg
496 * has completed and/or if our link status has changed. The
497 * get_link_status flag is set upon receiving a Link Status
498 * Change or Rx Sequence Error interrupt.
499 */
500 if (!mac->get_link_status) {
501 ret_val = 0;
502 goto out;
503 }
504
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000505 /*
506 * First we want to see if the MII Status Register reports
507 * link. If so, then we want to get the current speed/duplex
508 * of the PHY.
509 */
510 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
511 if (ret_val)
512 goto out;
513
Bruce Allan1d5846b2009-10-29 13:46:05 +0000514 if (hw->mac.type == e1000_pchlan) {
515 ret_val = e1000_k1_gig_workaround_hv(hw, link);
516 if (ret_val)
517 goto out;
518 }
519
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000520 if (!link)
521 goto out; /* No link detected */
522
523 mac->get_link_status = false;
524
525 if (hw->phy.type == e1000_phy_82578) {
526 ret_val = e1000_link_stall_workaround_hv(hw);
527 if (ret_val)
528 goto out;
529 }
530
531 /*
532 * Check if there was DownShift, must be checked
533 * immediately after link-up
534 */
535 e1000e_check_downshift(hw);
536
537 /*
538 * If we are forcing speed/duplex, then we simply return since
539 * we have already determined whether we have link or not.
540 */
541 if (!mac->autoneg) {
542 ret_val = -E1000_ERR_CONFIG;
543 goto out;
544 }
545
546 /*
547 * Auto-Neg is enabled. Auto Speed Detection takes care
548 * of MAC speed/duplex configuration. So we only need to
549 * configure Collision Distance in the MAC.
550 */
551 e1000e_config_collision_dist(hw);
552
553 /*
554 * Configure Flow Control now that Auto-Neg has completed.
555 * First, we need to restore the desired flow control
556 * settings because we may have had to re-autoneg with a
557 * different link partner.
558 */
559 ret_val = e1000e_config_fc_after_link_up(hw);
560 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000561 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000562
563out:
564 return ret_val;
565}
566
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700567static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700568{
569 struct e1000_hw *hw = &adapter->hw;
570 s32 rc;
571
572 rc = e1000_init_mac_params_ich8lan(adapter);
573 if (rc)
574 return rc;
575
576 rc = e1000_init_nvm_params_ich8lan(hw);
577 if (rc)
578 return rc;
579
Bruce Allana4f58f52009-06-02 11:29:18 +0000580 if (hw->mac.type == e1000_pchlan)
581 rc = e1000_init_phy_params_pchlan(hw);
582 else
583 rc = e1000_init_phy_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700584 if (rc)
585 return rc;
586
Bruce Allan2adc55c2009-06-02 11:28:58 +0000587 if (adapter->hw.phy.type == e1000_phy_ife) {
588 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
589 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
590 }
591
Auke Kokbc7f75f2007-09-17 12:30:59 -0700592 if ((adapter->hw.mac.type == e1000_ich8lan) &&
593 (adapter->hw.phy.type == e1000_phy_igp_3))
594 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
595
596 return 0;
597}
598
Thomas Gleixner717d4382008-10-02 16:33:40 -0700599static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700600
Auke Kokbc7f75f2007-09-17 12:30:59 -0700601/**
Bruce Allanca15df52009-10-26 11:23:43 +0000602 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
603 * @hw: pointer to the HW structure
604 *
605 * Acquires the mutex for performing NVM operations.
606 **/
607static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
608{
609 mutex_lock(&nvm_mutex);
610
611 return 0;
612}
613
614/**
615 * e1000_release_nvm_ich8lan - Release NVM mutex
616 * @hw: pointer to the HW structure
617 *
618 * Releases the mutex used while performing NVM operations.
619 **/
620static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
621{
622 mutex_unlock(&nvm_mutex);
623
624 return;
625}
626
627static DEFINE_MUTEX(swflag_mutex);
628
629/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630 * e1000_acquire_swflag_ich8lan - Acquire software control flag
631 * @hw: pointer to the HW structure
632 *
Bruce Allanca15df52009-10-26 11:23:43 +0000633 * Acquires the software control flag for performing PHY and select
634 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700635 **/
636static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
637{
Bruce Allan373a88d2009-08-07 07:41:37 +0000638 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
639 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640
Bruce Allanca15df52009-10-26 11:23:43 +0000641 mutex_lock(&swflag_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700642
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643 while (timeout) {
644 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +0000645 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
646 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700647
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648 mdelay(1);
649 timeout--;
650 }
651
652 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000653 e_dbg("SW/FW/HW has locked the resource for too long.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000654 ret_val = -E1000_ERR_CONFIG;
655 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700656 }
657
Bruce Allan53ac5a82009-10-26 11:23:06 +0000658 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +0000659
660 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
661 ew32(EXTCNF_CTRL, extcnf_ctrl);
662
663 while (timeout) {
664 extcnf_ctrl = er32(EXTCNF_CTRL);
665 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
666 break;
667
668 mdelay(1);
669 timeout--;
670 }
671
672 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000673 e_dbg("Failed to acquire the semaphore.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000674 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
675 ew32(EXTCNF_CTRL, extcnf_ctrl);
676 ret_val = -E1000_ERR_CONFIG;
677 goto out;
678 }
679
680out:
681 if (ret_val)
Bruce Allanca15df52009-10-26 11:23:43 +0000682 mutex_unlock(&swflag_mutex);
Bruce Allan373a88d2009-08-07 07:41:37 +0000683
684 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700685}
686
687/**
688 * e1000_release_swflag_ich8lan - Release software control flag
689 * @hw: pointer to the HW structure
690 *
Bruce Allanca15df52009-10-26 11:23:43 +0000691 * Releases the software control flag for performing PHY and select
692 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700693 **/
694static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
695{
696 u32 extcnf_ctrl;
697
698 extcnf_ctrl = er32(EXTCNF_CTRL);
699 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
700 ew32(EXTCNF_CTRL, extcnf_ctrl);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700701
Bruce Allanca15df52009-10-26 11:23:43 +0000702 mutex_unlock(&swflag_mutex);
703
704 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705}
706
707/**
Bruce Allan4662e822008-08-26 18:37:06 -0700708 * e1000_check_mng_mode_ich8lan - Checks management mode
709 * @hw: pointer to the HW structure
710 *
711 * This checks if the adapter has manageability enabled.
712 * This is a function pointer entry point only called by read/write
713 * routines for the PHY and NVM parts.
714 **/
715static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
716{
Bruce Allana708dd82009-11-20 23:28:37 +0000717 u32 fwsm;
718
719 fwsm = er32(FWSM);
Bruce Allan4662e822008-08-26 18:37:06 -0700720
721 return (fwsm & E1000_FWSM_MODE_MASK) ==
722 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
723}
724
725/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700726 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
727 * @hw: pointer to the HW structure
728 *
729 * Checks if firmware is blocking the reset of the PHY.
730 * This is a function pointer entry point only called by
731 * reset routines.
732 **/
733static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
734{
735 u32 fwsm;
736
737 fwsm = er32(FWSM);
738
739 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
740}
741
742/**
743 * e1000_phy_force_speed_duplex_ich8lan - Force PHY speed & duplex
744 * @hw: pointer to the HW structure
745 *
746 * Forces the speed and duplex settings of the PHY.
747 * This is a function pointer entry point only called by
748 * PHY setup routines.
749 **/
750static s32 e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw)
751{
752 struct e1000_phy_info *phy = &hw->phy;
753 s32 ret_val;
754 u16 data;
755 bool link;
756
757 if (phy->type != e1000_phy_ife) {
758 ret_val = e1000e_phy_force_speed_duplex_igp(hw);
759 return ret_val;
760 }
761
762 ret_val = e1e_rphy(hw, PHY_CONTROL, &data);
763 if (ret_val)
764 return ret_val;
765
766 e1000e_phy_force_speed_duplex_setup(hw, &data);
767
768 ret_val = e1e_wphy(hw, PHY_CONTROL, data);
769 if (ret_val)
770 return ret_val;
771
772 /* Disable MDI-X support for 10/100 */
773 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
774 if (ret_val)
775 return ret_val;
776
777 data &= ~IFE_PMC_AUTO_MDIX;
778 data &= ~IFE_PMC_FORCE_MDIX;
779
780 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
781 if (ret_val)
782 return ret_val;
783
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000784 e_dbg("IFE PMC: %X\n", data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700785
786 udelay(1);
787
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700788 if (phy->autoneg_wait_to_complete) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000789 e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700790
791 ret_val = e1000e_phy_has_link_generic(hw,
792 PHY_FORCE_LIMIT,
793 100000,
794 &link);
795 if (ret_val)
796 return ret_val;
797
798 if (!link)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000799 e_dbg("Link taking longer than expected.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700800
801 /* Try once more */
802 ret_val = e1000e_phy_has_link_generic(hw,
803 PHY_FORCE_LIMIT,
804 100000,
805 &link);
806 if (ret_val)
807 return ret_val;
808 }
809
810 return 0;
811}
812
813/**
Bruce Allanf523d212009-10-29 13:45:45 +0000814 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
815 * @hw: pointer to the HW structure
816 *
817 * SW should configure the LCD from the NVM extended configuration region
818 * as a workaround for certain parts.
819 **/
820static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
821{
822 struct e1000_phy_info *phy = &hw->phy;
823 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
824 s32 ret_val;
825 u16 word_addr, reg_data, reg_addr, phy_page = 0;
826
Bruce Allan94d81862009-11-20 23:25:26 +0000827 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000828 if (ret_val)
829 return ret_val;
830
831 /*
832 * Initialize the PHY from the NVM on ICH platforms. This
833 * is needed due to an issue where the NVM configuration is
834 * not properly autoloaded after power transitions.
835 * Therefore, after each PHY reset, we will load the
836 * configuration data out of the NVM manually.
837 */
838 if ((hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) ||
839 (hw->mac.type == e1000_pchlan)) {
840 struct e1000_adapter *adapter = hw->adapter;
841
842 /* Check if SW needs to configure the PHY */
843 if ((adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
844 (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M) ||
845 (hw->mac.type == e1000_pchlan))
846 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
847 else
848 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
849
850 data = er32(FEXTNVM);
851 if (!(data & sw_cfg_mask))
852 goto out;
853
854 /* Wait for basic configuration completes before proceeding */
855 e1000_lan_init_done_ich8lan(hw);
856
857 /*
858 * Make sure HW does not configure LCD from PHY
859 * extended configuration before SW configuration
860 */
861 data = er32(EXTCNF_CTRL);
862 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
863 goto out;
864
865 cnf_size = er32(EXTCNF_SIZE);
866 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
867 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
868 if (!cnf_size)
869 goto out;
870
871 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
872 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
873
874 if (!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
875 (hw->mac.type == e1000_pchlan)) {
876 /*
877 * HW configures the SMBus address and LEDs when the
878 * OEM and LCD Write Enable bits are set in the NVM.
879 * When both NVM bits are cleared, SW will configure
880 * them instead.
881 */
882 data = er32(STRAP);
883 data &= E1000_STRAP_SMBUS_ADDRESS_MASK;
884 reg_data = data >> E1000_STRAP_SMBUS_ADDRESS_SHIFT;
885 reg_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
886 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR,
887 reg_data);
888 if (ret_val)
889 goto out;
890
891 data = er32(LEDCTL);
892 ret_val = e1000_write_phy_reg_hv_locked(hw,
893 HV_LED_CONFIG,
894 (u16)data);
895 if (ret_val)
896 goto out;
897 }
898 /* Configure LCD from extended configuration region. */
899
900 /* cnf_base_addr is in DWORD */
901 word_addr = (u16)(cnf_base_addr << 1);
902
903 for (i = 0; i < cnf_size; i++) {
904 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
905 &reg_data);
906 if (ret_val)
907 goto out;
908
909 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
910 1, &reg_addr);
911 if (ret_val)
912 goto out;
913
914 /* Save off the PHY page for future writes. */
915 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
916 phy_page = reg_data;
917 continue;
918 }
919
920 reg_addr &= PHY_REG_MASK;
921 reg_addr |= phy_page;
922
Bruce Allan94d81862009-11-20 23:25:26 +0000923 ret_val = phy->ops.write_reg_locked(hw,
Bruce Allanf523d212009-10-29 13:45:45 +0000924 (u32)reg_addr,
925 reg_data);
926 if (ret_val)
927 goto out;
928 }
929 }
930
931out:
Bruce Allan94d81862009-11-20 23:25:26 +0000932 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000933 return ret_val;
934}
935
936/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000937 * e1000_k1_gig_workaround_hv - K1 Si workaround
938 * @hw: pointer to the HW structure
939 * @link: link up bool flag
940 *
941 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
942 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
943 * If link is down, the function will restore the default K1 setting located
944 * in the NVM.
945 **/
946static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
947{
948 s32 ret_val = 0;
949 u16 status_reg = 0;
950 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
951
952 if (hw->mac.type != e1000_pchlan)
953 goto out;
954
955 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +0000956 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000957 if (ret_val)
958 goto out;
959
960 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
961 if (link) {
962 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan94d81862009-11-20 23:25:26 +0000963 ret_val = hw->phy.ops.read_reg_locked(hw, BM_CS_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +0000964 &status_reg);
965 if (ret_val)
966 goto release;
967
968 status_reg &= BM_CS_STATUS_LINK_UP |
969 BM_CS_STATUS_RESOLVED |
970 BM_CS_STATUS_SPEED_MASK;
971
972 if (status_reg == (BM_CS_STATUS_LINK_UP |
973 BM_CS_STATUS_RESOLVED |
974 BM_CS_STATUS_SPEED_1000))
975 k1_enable = false;
976 }
977
978 if (hw->phy.type == e1000_phy_82577) {
Bruce Allan94d81862009-11-20 23:25:26 +0000979 ret_val = hw->phy.ops.read_reg_locked(hw, HV_M_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +0000980 &status_reg);
981 if (ret_val)
982 goto release;
983
984 status_reg &= HV_M_STATUS_LINK_UP |
985 HV_M_STATUS_AUTONEG_COMPLETE |
986 HV_M_STATUS_SPEED_MASK;
987
988 if (status_reg == (HV_M_STATUS_LINK_UP |
989 HV_M_STATUS_AUTONEG_COMPLETE |
990 HV_M_STATUS_SPEED_1000))
991 k1_enable = false;
992 }
993
994 /* Link stall fix for link up */
Bruce Allan94d81862009-11-20 23:25:26 +0000995 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +0000996 0x0100);
997 if (ret_val)
998 goto release;
999
1000 } else {
1001 /* Link stall fix for link down */
Bruce Allan94d81862009-11-20 23:25:26 +00001002 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +00001003 0x4100);
1004 if (ret_val)
1005 goto release;
1006 }
1007
1008 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1009
1010release:
Bruce Allan94d81862009-11-20 23:25:26 +00001011 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001012out:
1013 return ret_val;
1014}
1015
1016/**
1017 * e1000_configure_k1_ich8lan - Configure K1 power state
1018 * @hw: pointer to the HW structure
1019 * @enable: K1 state to configure
1020 *
1021 * Configure the K1 power state based on the provided parameter.
1022 * Assumes semaphore already acquired.
1023 *
1024 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1025 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001026s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001027{
1028 s32 ret_val = 0;
1029 u32 ctrl_reg = 0;
1030 u32 ctrl_ext = 0;
1031 u32 reg = 0;
1032 u16 kmrn_reg = 0;
1033
1034 ret_val = e1000e_read_kmrn_reg_locked(hw,
1035 E1000_KMRNCTRLSTA_K1_CONFIG,
1036 &kmrn_reg);
1037 if (ret_val)
1038 goto out;
1039
1040 if (k1_enable)
1041 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1042 else
1043 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1044
1045 ret_val = e1000e_write_kmrn_reg_locked(hw,
1046 E1000_KMRNCTRLSTA_K1_CONFIG,
1047 kmrn_reg);
1048 if (ret_val)
1049 goto out;
1050
1051 udelay(20);
1052 ctrl_ext = er32(CTRL_EXT);
1053 ctrl_reg = er32(CTRL);
1054
1055 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1056 reg |= E1000_CTRL_FRCSPD;
1057 ew32(CTRL, reg);
1058
1059 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
1060 udelay(20);
1061 ew32(CTRL, ctrl_reg);
1062 ew32(CTRL_EXT, ctrl_ext);
1063 udelay(20);
1064
1065out:
1066 return ret_val;
1067}
1068
1069/**
Bruce Allanf523d212009-10-29 13:45:45 +00001070 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1071 * @hw: pointer to the HW structure
1072 * @d0_state: boolean if entering d0 or d3 device state
1073 *
1074 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1075 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1076 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1077 **/
1078static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1079{
1080 s32 ret_val = 0;
1081 u32 mac_reg;
1082 u16 oem_reg;
1083
1084 if (hw->mac.type != e1000_pchlan)
1085 return ret_val;
1086
Bruce Allan94d81862009-11-20 23:25:26 +00001087 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001088 if (ret_val)
1089 return ret_val;
1090
1091 mac_reg = er32(EXTCNF_CTRL);
1092 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
1093 goto out;
1094
1095 mac_reg = er32(FEXTNVM);
1096 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
1097 goto out;
1098
1099 mac_reg = er32(PHY_CTRL);
1100
Bruce Allan94d81862009-11-20 23:25:26 +00001101 ret_val = hw->phy.ops.read_reg_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001102 if (ret_val)
1103 goto out;
1104
1105 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1106
1107 if (d0_state) {
1108 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1109 oem_reg |= HV_OEM_BITS_GBE_DIS;
1110
1111 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1112 oem_reg |= HV_OEM_BITS_LPLU;
1113 } else {
1114 if (mac_reg & E1000_PHY_CTRL_NOND0A_GBE_DISABLE)
1115 oem_reg |= HV_OEM_BITS_GBE_DIS;
1116
1117 if (mac_reg & E1000_PHY_CTRL_NOND0A_LPLU)
1118 oem_reg |= HV_OEM_BITS_LPLU;
1119 }
1120 /* Restart auto-neg to activate the bits */
Bruce Allan818f3332009-11-19 14:17:30 +00001121 if (!e1000_check_reset_block(hw))
1122 oem_reg |= HV_OEM_BITS_RESTART_AN;
Bruce Allan94d81862009-11-20 23:25:26 +00001123 ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001124
1125out:
Bruce Allan94d81862009-11-20 23:25:26 +00001126 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001127
1128 return ret_val;
1129}
1130
1131
1132/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001133 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1134 * done after every PHY reset.
1135 **/
1136static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1137{
1138 s32 ret_val = 0;
1139
1140 if (hw->mac.type != e1000_pchlan)
1141 return ret_val;
1142
1143 if (((hw->phy.type == e1000_phy_82577) &&
1144 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1145 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1146 /* Disable generation of early preamble */
1147 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1148 if (ret_val)
1149 return ret_val;
1150
1151 /* Preamble tuning for SSC */
1152 ret_val = e1e_wphy(hw, PHY_REG(770, 16), 0xA204);
1153 if (ret_val)
1154 return ret_val;
1155 }
1156
1157 if (hw->phy.type == e1000_phy_82578) {
1158 /*
1159 * Return registers to default by doing a soft reset then
1160 * writing 0x3140 to the control register.
1161 */
1162 if (hw->phy.revision < 2) {
1163 e1000e_phy_sw_reset(hw);
1164 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1165 }
1166 }
1167
1168 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001169 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001170 if (ret_val)
1171 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001172
Bruce Allana4f58f52009-06-02 11:29:18 +00001173 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001174 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
1175 if (ret_val)
1176 goto out;
Bruce Allan94d81862009-11-20 23:25:26 +00001177 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001178
Bruce Allan1d5846b2009-10-29 13:46:05 +00001179 /*
1180 * Configure the K1 Si workaround during phy reset assuming there is
1181 * link so that it disables K1 if link is in 1Gbps.
1182 */
1183 ret_val = e1000_k1_gig_workaround_hv(hw, true);
1184
1185out:
Bruce Allana4f58f52009-06-02 11:29:18 +00001186 return ret_val;
1187}
1188
1189/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00001190 * e1000_lan_init_done_ich8lan - Check for PHY config completion
1191 * @hw: pointer to the HW structure
1192 *
1193 * Check the appropriate indication the MAC has finished configuring the
1194 * PHY after a software reset.
1195 **/
1196static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
1197{
1198 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
1199
1200 /* Wait for basic configuration completes before proceeding */
1201 do {
1202 data = er32(STATUS);
1203 data &= E1000_STATUS_LAN_INIT_DONE;
1204 udelay(100);
1205 } while ((!data) && --loop);
1206
1207 /*
1208 * If basic configuration is incomplete before the above loop
1209 * count reaches 0, loading the configuration from NVM will
1210 * leave the PHY in a bad state possibly resulting in no link.
1211 */
1212 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001213 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00001214
1215 /* Clear the Init Done bit for the next init event */
1216 data = er32(STATUS);
1217 data &= ~E1000_STATUS_LAN_INIT_DONE;
1218 ew32(STATUS, data);
1219}
1220
1221/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001222 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
1223 * @hw: pointer to the HW structure
1224 *
1225 * Resets the PHY
1226 * This is a function pointer entry point called by drivers
1227 * or other shared routines.
1228 **/
1229static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
1230{
Bruce Allanf523d212009-10-29 13:45:45 +00001231 s32 ret_val = 0;
1232 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233
1234 ret_val = e1000e_phy_hw_reset_generic(hw);
1235 if (ret_val)
1236 return ret_val;
1237
Bruce Allanfc0c7762009-07-01 13:27:55 +00001238 /* Allow time for h/w to get to a quiescent state after reset */
1239 mdelay(10);
1240
Bruce Allana4f58f52009-06-02 11:29:18 +00001241 if (hw->mac.type == e1000_pchlan) {
1242 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
1243 if (ret_val)
1244 return ret_val;
1245 }
1246
Bruce Allandb2932e2009-10-26 11:22:47 +00001247 /* Dummy read to clear the phy wakeup bit after lcd reset */
1248 if (hw->mac.type == e1000_pchlan)
1249 e1e_rphy(hw, BM_WUC, &reg);
1250
Bruce Allanf523d212009-10-29 13:45:45 +00001251 /* Configure the LCD with the extended configuration region in NVM */
1252 ret_val = e1000_sw_lcd_config_ich8lan(hw);
1253 if (ret_val)
1254 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255
Bruce Allanf523d212009-10-29 13:45:45 +00001256 /* Configure the LCD with the OEM bits in NVM */
1257 if (hw->mac.type == e1000_pchlan)
1258 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001259
Bruce Allanf523d212009-10-29 13:45:45 +00001260out:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001261 return 0;
1262}
1263
1264/**
1265 * e1000_get_phy_info_ife_ich8lan - Retrieves various IFE PHY states
1266 * @hw: pointer to the HW structure
1267 *
1268 * Populates "phy" structure with various feature states.
1269 * This function is only called by other family-specific
1270 * routines.
1271 **/
1272static s32 e1000_get_phy_info_ife_ich8lan(struct e1000_hw *hw)
1273{
1274 struct e1000_phy_info *phy = &hw->phy;
1275 s32 ret_val;
1276 u16 data;
1277 bool link;
1278
1279 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1280 if (ret_val)
1281 return ret_val;
1282
1283 if (!link) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001284 e_dbg("Phy info is only valid if link is up\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001285 return -E1000_ERR_CONFIG;
1286 }
1287
1288 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
1289 if (ret_val)
1290 return ret_val;
1291 phy->polarity_correction = (!(data & IFE_PSC_AUTO_POLARITY_DISABLE));
1292
1293 if (phy->polarity_correction) {
Bruce Allana4f58f52009-06-02 11:29:18 +00001294 ret_val = phy->ops.check_polarity(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001295 if (ret_val)
1296 return ret_val;
1297 } else {
1298 /* Polarity is forced */
1299 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
1300 ? e1000_rev_polarity_reversed
1301 : e1000_rev_polarity_normal;
1302 }
1303
1304 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1305 if (ret_val)
1306 return ret_val;
1307
1308 phy->is_mdix = (data & IFE_PMC_MDIX_STATUS);
1309
1310 /* The following parameters are undefined for 10/100 operation. */
1311 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1312 phy->local_rx = e1000_1000t_rx_status_undefined;
1313 phy->remote_rx = e1000_1000t_rx_status_undefined;
1314
1315 return 0;
1316}
1317
1318/**
1319 * e1000_get_phy_info_ich8lan - Calls appropriate PHY type get_phy_info
1320 * @hw: pointer to the HW structure
1321 *
1322 * Wrapper for calling the get_phy_info routines for the appropriate phy type.
1323 * This is a function pointer entry point called by drivers
1324 * or other shared routines.
1325 **/
1326static s32 e1000_get_phy_info_ich8lan(struct e1000_hw *hw)
1327{
1328 switch (hw->phy.type) {
1329 case e1000_phy_ife:
1330 return e1000_get_phy_info_ife_ich8lan(hw);
1331 break;
1332 case e1000_phy_igp_3:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001333 case e1000_phy_bm:
Bruce Allana4f58f52009-06-02 11:29:18 +00001334 case e1000_phy_82578:
1335 case e1000_phy_82577:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336 return e1000e_get_phy_info_igp(hw);
1337 break;
1338 default:
1339 break;
1340 }
1341
1342 return -E1000_ERR_PHY_TYPE;
1343}
1344
1345/**
1346 * e1000_check_polarity_ife_ich8lan - Check cable polarity for IFE PHY
1347 * @hw: pointer to the HW structure
1348 *
Auke Kok489815c2008-02-21 15:11:07 -08001349 * Polarity is determined on the polarity reversal feature being enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001350 * This function is only called by other family-specific
1351 * routines.
1352 **/
1353static s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw)
1354{
1355 struct e1000_phy_info *phy = &hw->phy;
1356 s32 ret_val;
1357 u16 phy_data, offset, mask;
1358
Bruce Allanad680762008-03-28 09:15:03 -07001359 /*
1360 * Polarity is determined based on the reversal feature being enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001361 */
1362 if (phy->polarity_correction) {
1363 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1364 mask = IFE_PESC_POLARITY_REVERSED;
1365 } else {
1366 offset = IFE_PHY_SPECIAL_CONTROL;
1367 mask = IFE_PSC_FORCE_POLARITY;
1368 }
1369
1370 ret_val = e1e_rphy(hw, offset, &phy_data);
1371
1372 if (!ret_val)
1373 phy->cable_polarity = (phy_data & mask)
1374 ? e1000_rev_polarity_reversed
1375 : e1000_rev_polarity_normal;
1376
1377 return ret_val;
1378}
1379
1380/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00001381 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1382 * @hw: pointer to the HW structure
1383 * @active: true to enable LPLU, false to disable
1384 *
1385 * Sets the LPLU state according to the active flag. For PCH, if OEM write
1386 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1387 * the phy speed. This function will manually set the LPLU bit and restart
1388 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
1389 * since it configures the same bit.
1390 **/
1391static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1392{
1393 s32 ret_val = 0;
1394 u16 oem_reg;
1395
1396 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
1397 if (ret_val)
1398 goto out;
1399
1400 if (active)
1401 oem_reg |= HV_OEM_BITS_LPLU;
1402 else
1403 oem_reg &= ~HV_OEM_BITS_LPLU;
1404
1405 oem_reg |= HV_OEM_BITS_RESTART_AN;
1406 ret_val = e1e_wphy(hw, HV_OEM_BITS, oem_reg);
1407
1408out:
1409 return ret_val;
1410}
1411
1412/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001413 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1414 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001415 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001416 *
1417 * Sets the LPLU D0 state according to the active flag. When
1418 * activating LPLU this function also disables smart speed
1419 * and vice versa. LPLU will not be activated unless the
1420 * device autonegotiation advertisement meets standards of
1421 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1422 * This is a function pointer entry point only called by
1423 * PHY setup routines.
1424 **/
1425static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1426{
1427 struct e1000_phy_info *phy = &hw->phy;
1428 u32 phy_ctrl;
1429 s32 ret_val = 0;
1430 u16 data;
1431
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001432 if (phy->type == e1000_phy_ife)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001433 return ret_val;
1434
1435 phy_ctrl = er32(PHY_CTRL);
1436
1437 if (active) {
1438 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
1439 ew32(PHY_CTRL, phy_ctrl);
1440
Bruce Allan60f12922009-07-01 13:28:14 +00001441 if (phy->type != e1000_phy_igp_3)
1442 return 0;
1443
Bruce Allanad680762008-03-28 09:15:03 -07001444 /*
1445 * Call gig speed drop workaround on LPLU before accessing
1446 * any PHY registers
1447 */
Bruce Allan60f12922009-07-01 13:28:14 +00001448 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001449 e1000e_gig_downshift_workaround_ich8lan(hw);
1450
1451 /* When LPLU is enabled, we should disable SmartSpeed */
1452 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1453 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1454 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1455 if (ret_val)
1456 return ret_val;
1457 } else {
1458 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
1459 ew32(PHY_CTRL, phy_ctrl);
1460
Bruce Allan60f12922009-07-01 13:28:14 +00001461 if (phy->type != e1000_phy_igp_3)
1462 return 0;
1463
Bruce Allanad680762008-03-28 09:15:03 -07001464 /*
1465 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001466 * during Dx states where the power conservation is most
1467 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001468 * SmartSpeed, so performance is maintained.
1469 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001470 if (phy->smart_speed == e1000_smart_speed_on) {
1471 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001472 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473 if (ret_val)
1474 return ret_val;
1475
1476 data |= IGP01E1000_PSCFR_SMART_SPEED;
1477 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001478 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001479 if (ret_val)
1480 return ret_val;
1481 } else if (phy->smart_speed == e1000_smart_speed_off) {
1482 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001483 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001484 if (ret_val)
1485 return ret_val;
1486
1487 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1488 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001489 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001490 if (ret_val)
1491 return ret_val;
1492 }
1493 }
1494
1495 return 0;
1496}
1497
1498/**
1499 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
1500 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001501 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001502 *
1503 * Sets the LPLU D3 state according to the active flag. When
1504 * activating LPLU this function also disables smart speed
1505 * and vice versa. LPLU will not be activated unless the
1506 * device autonegotiation advertisement meets standards of
1507 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1508 * This is a function pointer entry point only called by
1509 * PHY setup routines.
1510 **/
1511static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1512{
1513 struct e1000_phy_info *phy = &hw->phy;
1514 u32 phy_ctrl;
1515 s32 ret_val;
1516 u16 data;
1517
1518 phy_ctrl = er32(PHY_CTRL);
1519
1520 if (!active) {
1521 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
1522 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00001523
1524 if (phy->type != e1000_phy_igp_3)
1525 return 0;
1526
Bruce Allanad680762008-03-28 09:15:03 -07001527 /*
1528 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001529 * during Dx states where the power conservation is most
1530 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001531 * SmartSpeed, so performance is maintained.
1532 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001533 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07001534 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1535 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001536 if (ret_val)
1537 return ret_val;
1538
1539 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001540 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1541 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001542 if (ret_val)
1543 return ret_val;
1544 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07001545 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1546 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547 if (ret_val)
1548 return ret_val;
1549
1550 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001551 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1552 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001553 if (ret_val)
1554 return ret_val;
1555 }
1556 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1557 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1558 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1559 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
1560 ew32(PHY_CTRL, phy_ctrl);
1561
Bruce Allan60f12922009-07-01 13:28:14 +00001562 if (phy->type != e1000_phy_igp_3)
1563 return 0;
1564
Bruce Allanad680762008-03-28 09:15:03 -07001565 /*
1566 * Call gig speed drop workaround on LPLU before accessing
1567 * any PHY registers
1568 */
Bruce Allan60f12922009-07-01 13:28:14 +00001569 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001570 e1000e_gig_downshift_workaround_ich8lan(hw);
1571
1572 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07001573 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574 if (ret_val)
1575 return ret_val;
1576
1577 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001578 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 }
1580
1581 return 0;
1582}
1583
1584/**
Bruce Allanf4187b52008-08-26 18:36:50 -07001585 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
1586 * @hw: pointer to the HW structure
1587 * @bank: pointer to the variable that returns the active bank
1588 *
1589 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08001590 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07001591 **/
1592static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
1593{
Bruce Allane2434552008-11-21 17:02:41 -08001594 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07001595 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07001596 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
1597 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08001598 u8 sig_byte = 0;
1599 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001600
Bruce Allane2434552008-11-21 17:02:41 -08001601 switch (hw->mac.type) {
1602 case e1000_ich8lan:
1603 case e1000_ich9lan:
1604 eecd = er32(EECD);
1605 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
1606 E1000_EECD_SEC1VAL_VALID_MASK) {
1607 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07001608 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08001609 else
1610 *bank = 0;
1611
1612 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001613 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001614 e_dbg("Unable to determine valid NVM bank via EEC - "
Bruce Allane2434552008-11-21 17:02:41 -08001615 "reading flash signature\n");
1616 /* fall-thru */
1617 default:
1618 /* set bank to 0 in case flash read fails */
1619 *bank = 0;
1620
1621 /* Check bank 0 */
1622 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
1623 &sig_byte);
1624 if (ret_val)
1625 return ret_val;
1626 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1627 E1000_ICH_NVM_SIG_VALUE) {
1628 *bank = 0;
1629 return 0;
1630 }
1631
1632 /* Check bank 1 */
1633 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
1634 bank1_offset,
1635 &sig_byte);
1636 if (ret_val)
1637 return ret_val;
1638 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1639 E1000_ICH_NVM_SIG_VALUE) {
1640 *bank = 1;
1641 return 0;
1642 }
1643
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001644 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08001645 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07001646 }
1647
1648 return 0;
1649}
1650
1651/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001652 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
1653 * @hw: pointer to the HW structure
1654 * @offset: The offset (in bytes) of the word(s) to read.
1655 * @words: Size of data to read in words
1656 * @data: Pointer to the word(s) to read at offset.
1657 *
1658 * Reads a word(s) from the NVM using the flash access registers.
1659 **/
1660static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1661 u16 *data)
1662{
1663 struct e1000_nvm_info *nvm = &hw->nvm;
1664 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1665 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00001666 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001667 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001668 u16 i, word;
1669
1670 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1671 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001672 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00001673 ret_val = -E1000_ERR_NVM;
1674 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675 }
1676
Bruce Allan94d81862009-11-20 23:25:26 +00001677 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678
Bruce Allanf4187b52008-08-26 18:36:50 -07001679 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00001680 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001681 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00001682 bank = 0;
1683 }
Bruce Allanf4187b52008-08-26 18:36:50 -07001684
1685 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001686 act_offset += offset;
1687
Bruce Allan148675a2009-08-07 07:41:56 +00001688 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689 for (i = 0; i < words; i++) {
1690 if ((dev_spec->shadow_ram) &&
1691 (dev_spec->shadow_ram[offset+i].modified)) {
1692 data[i] = dev_spec->shadow_ram[offset+i].value;
1693 } else {
1694 ret_val = e1000_read_flash_word_ich8lan(hw,
1695 act_offset + i,
1696 &word);
1697 if (ret_val)
1698 break;
1699 data[i] = word;
1700 }
1701 }
1702
Bruce Allan94d81862009-11-20 23:25:26 +00001703 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001704
Bruce Allane2434552008-11-21 17:02:41 -08001705out:
1706 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001707 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08001708
Auke Kokbc7f75f2007-09-17 12:30:59 -07001709 return ret_val;
1710}
1711
1712/**
1713 * e1000_flash_cycle_init_ich8lan - Initialize flash
1714 * @hw: pointer to the HW structure
1715 *
1716 * This function does initial flash setup so that a new read/write/erase cycle
1717 * can be started.
1718 **/
1719static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
1720{
1721 union ich8_hws_flash_status hsfsts;
1722 s32 ret_val = -E1000_ERR_NVM;
1723 s32 i = 0;
1724
1725 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1726
1727 /* Check if the flash descriptor is valid */
1728 if (hsfsts.hsf_status.fldesvalid == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001729 e_dbg("Flash descriptor invalid. "
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730 "SW Sequencing must be used.");
1731 return -E1000_ERR_NVM;
1732 }
1733
1734 /* Clear FCERR and DAEL in hw status by writing 1 */
1735 hsfsts.hsf_status.flcerr = 1;
1736 hsfsts.hsf_status.dael = 1;
1737
1738 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1739
Bruce Allanad680762008-03-28 09:15:03 -07001740 /*
1741 * Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07001742 * bit to check against, in order to start a new cycle or
1743 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08001744 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07001745 * indication whether a cycle is in progress or has been
1746 * completed.
1747 */
1748
1749 if (hsfsts.hsf_status.flcinprog == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07001750 /*
1751 * There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00001752 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07001753 * Begin by setting Flash Cycle Done.
1754 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001755 hsfsts.hsf_status.flcdone = 1;
1756 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1757 ret_val = 0;
1758 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001759 /*
Bruce Allan5ff5b662009-12-01 15:51:11 +00001760 * Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07001761 * cycle has a chance to end before giving up.
1762 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001763 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
1764 hsfsts.regval = __er16flash(hw, ICH_FLASH_HSFSTS);
1765 if (hsfsts.hsf_status.flcinprog == 0) {
1766 ret_val = 0;
1767 break;
1768 }
1769 udelay(1);
1770 }
1771 if (ret_val == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07001772 /*
1773 * Successful in waiting for previous cycle to timeout,
1774 * now set the Flash Cycle Done.
1775 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001776 hsfsts.hsf_status.flcdone = 1;
1777 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1778 } else {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001779 e_dbg("Flash controller busy, cannot get access");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001780 }
1781 }
1782
1783 return ret_val;
1784}
1785
1786/**
1787 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
1788 * @hw: pointer to the HW structure
1789 * @timeout: maximum time to wait for completion
1790 *
1791 * This function starts a flash cycle and waits for its completion.
1792 **/
1793static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
1794{
1795 union ich8_hws_flash_ctrl hsflctl;
1796 union ich8_hws_flash_status hsfsts;
1797 s32 ret_val = -E1000_ERR_NVM;
1798 u32 i = 0;
1799
1800 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
1801 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1802 hsflctl.hsf_ctrl.flcgo = 1;
1803 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1804
1805 /* wait till FDONE bit is set to 1 */
1806 do {
1807 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1808 if (hsfsts.hsf_status.flcdone == 1)
1809 break;
1810 udelay(1);
1811 } while (i++ < timeout);
1812
1813 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
1814 return 0;
1815
1816 return ret_val;
1817}
1818
1819/**
1820 * e1000_read_flash_word_ich8lan - Read word from flash
1821 * @hw: pointer to the HW structure
1822 * @offset: offset to data location
1823 * @data: pointer to the location for storing the data
1824 *
1825 * Reads the flash word at offset into data. Offset is converted
1826 * to bytes before read.
1827 **/
1828static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
1829 u16 *data)
1830{
1831 /* Must convert offset into bytes. */
1832 offset <<= 1;
1833
1834 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
1835}
1836
1837/**
Bruce Allanf4187b52008-08-26 18:36:50 -07001838 * e1000_read_flash_byte_ich8lan - Read byte from flash
1839 * @hw: pointer to the HW structure
1840 * @offset: The offset of the byte to read.
1841 * @data: Pointer to a byte to store the value read.
1842 *
1843 * Reads a single byte from the NVM using the flash access registers.
1844 **/
1845static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1846 u8 *data)
1847{
1848 s32 ret_val;
1849 u16 word = 0;
1850
1851 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
1852 if (ret_val)
1853 return ret_val;
1854
1855 *data = (u8)word;
1856
1857 return 0;
1858}
1859
1860/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001861 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
1862 * @hw: pointer to the HW structure
1863 * @offset: The offset (in bytes) of the byte or word to read.
1864 * @size: Size of data to read, 1=byte 2=word
1865 * @data: Pointer to the word to store the value read.
1866 *
1867 * Reads a byte or word from the NVM using the flash access registers.
1868 **/
1869static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1870 u8 size, u16 *data)
1871{
1872 union ich8_hws_flash_status hsfsts;
1873 union ich8_hws_flash_ctrl hsflctl;
1874 u32 flash_linear_addr;
1875 u32 flash_data = 0;
1876 s32 ret_val = -E1000_ERR_NVM;
1877 u8 count = 0;
1878
1879 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
1880 return -E1000_ERR_NVM;
1881
1882 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1883 hw->nvm.flash_base_addr;
1884
1885 do {
1886 udelay(1);
1887 /* Steps */
1888 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1889 if (ret_val != 0)
1890 break;
1891
1892 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1893 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1894 hsflctl.hsf_ctrl.fldbcount = size - 1;
1895 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
1896 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1897
1898 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1899
1900 ret_val = e1000_flash_cycle_ich8lan(hw,
1901 ICH_FLASH_READ_COMMAND_TIMEOUT);
1902
Bruce Allanad680762008-03-28 09:15:03 -07001903 /*
1904 * Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07001905 * and try the whole sequence a few more times, else
1906 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07001907 * least significant byte first msb to lsb
1908 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001909 if (ret_val == 0) {
1910 flash_data = er32flash(ICH_FLASH_FDATA0);
1911 if (size == 1) {
1912 *data = (u8)(flash_data & 0x000000FF);
1913 } else if (size == 2) {
1914 *data = (u16)(flash_data & 0x0000FFFF);
1915 }
1916 break;
1917 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001918 /*
1919 * If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07001920 * completely hosed, but if the error condition is
1921 * detected, it won't hurt to give it another try...
1922 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
1923 */
1924 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1925 if (hsfsts.hsf_status.flcerr == 1) {
1926 /* Repeat for some time before giving up. */
1927 continue;
1928 } else if (hsfsts.hsf_status.flcdone == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001929 e_dbg("Timeout error - flash cycle "
Auke Kokbc7f75f2007-09-17 12:30:59 -07001930 "did not complete.");
1931 break;
1932 }
1933 }
1934 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1935
1936 return ret_val;
1937}
1938
1939/**
1940 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
1941 * @hw: pointer to the HW structure
1942 * @offset: The offset (in bytes) of the word(s) to write.
1943 * @words: Size of data to write in words
1944 * @data: Pointer to the word(s) to write at offset.
1945 *
1946 * Writes a byte or word to the NVM using the flash access registers.
1947 **/
1948static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1949 u16 *data)
1950{
1951 struct e1000_nvm_info *nvm = &hw->nvm;
1952 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953 u16 i;
1954
1955 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1956 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001957 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001958 return -E1000_ERR_NVM;
1959 }
1960
Bruce Allan94d81862009-11-20 23:25:26 +00001961 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00001962
Auke Kokbc7f75f2007-09-17 12:30:59 -07001963 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00001964 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001965 dev_spec->shadow_ram[offset+i].value = data[i];
1966 }
1967
Bruce Allan94d81862009-11-20 23:25:26 +00001968 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00001969
Auke Kokbc7f75f2007-09-17 12:30:59 -07001970 return 0;
1971}
1972
1973/**
1974 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
1975 * @hw: pointer to the HW structure
1976 *
1977 * The NVM checksum is updated by calling the generic update_nvm_checksum,
1978 * which writes the checksum to the shadow ram. The changes in the shadow
1979 * ram are then committed to the EEPROM by processing each bank at a time
1980 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08001981 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07001982 * future writes.
1983 **/
1984static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1985{
1986 struct e1000_nvm_info *nvm = &hw->nvm;
1987 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07001988 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001989 s32 ret_val;
1990 u16 data;
1991
1992 ret_val = e1000e_update_nvm_checksum_generic(hw);
1993 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08001994 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995
1996 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08001997 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001998
Bruce Allan94d81862009-11-20 23:25:26 +00001999 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002000
Bruce Allanad680762008-03-28 09:15:03 -07002001 /*
2002 * We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002003 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002004 * is going to be written
2005 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002006 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002007 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002008 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002009 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002010 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002011
2012 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002013 new_bank_offset = nvm->flash_bank_size;
2014 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002015 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
2016 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +00002017 nvm->ops.release(hw);
Bruce Allane2434552008-11-21 17:02:41 -08002018 goto out;
2019 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002020 } else {
2021 old_bank_offset = nvm->flash_bank_size;
2022 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002023 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
2024 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +00002025 nvm->ops.release(hw);
Bruce Allane2434552008-11-21 17:02:41 -08002026 goto out;
2027 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002028 }
2029
2030 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allanad680762008-03-28 09:15:03 -07002031 /*
2032 * Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002033 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002034 * in the shadow RAM
2035 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002036 if (dev_spec->shadow_ram[i].modified) {
2037 data = dev_spec->shadow_ram[i].value;
2038 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002039 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2040 old_bank_offset,
2041 &data);
2042 if (ret_val)
2043 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002044 }
2045
Bruce Allanad680762008-03-28 09:15:03 -07002046 /*
2047 * If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002048 * (15:14) are 11b until the commit has completed.
2049 * This will allow us to write 10b which indicates the
2050 * signature is valid. We want to do this after the write
2051 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002052 * while the write is still in progress
2053 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002054 if (i == E1000_ICH_NVM_SIG_WORD)
2055 data |= E1000_ICH_NVM_SIG_MASK;
2056
2057 /* Convert offset to bytes. */
2058 act_offset = (i + new_bank_offset) << 1;
2059
2060 udelay(100);
2061 /* Write the bytes to the new bank. */
2062 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2063 act_offset,
2064 (u8)data);
2065 if (ret_val)
2066 break;
2067
2068 udelay(100);
2069 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2070 act_offset + 1,
2071 (u8)(data >> 8));
2072 if (ret_val)
2073 break;
2074 }
2075
Bruce Allanad680762008-03-28 09:15:03 -07002076 /*
2077 * Don't bother writing the segment valid bits if sector
2078 * programming failed.
2079 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002080 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002081 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002082 e_dbg("Flash commit failed.\n");
Bruce Allan94d81862009-11-20 23:25:26 +00002083 nvm->ops.release(hw);
Bruce Allane2434552008-11-21 17:02:41 -08002084 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002085 }
2086
Bruce Allanad680762008-03-28 09:15:03 -07002087 /*
2088 * Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002089 * to 10b in word 0x13 , this can be done without an
2090 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002091 * and we need to change bit 14 to 0b
2092 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002093 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002094 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
2095 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +00002096 nvm->ops.release(hw);
Bruce Allane2434552008-11-21 17:02:41 -08002097 goto out;
2098 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002099 data &= 0xBFFF;
2100 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2101 act_offset * 2 + 1,
2102 (u8)(data >> 8));
2103 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +00002104 nvm->ops.release(hw);
Bruce Allane2434552008-11-21 17:02:41 -08002105 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002106 }
2107
Bruce Allanad680762008-03-28 09:15:03 -07002108 /*
2109 * And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002110 * its signature word (0x13) high_byte to 0b. This can be
2111 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002112 * to 1's. We can write 1's to 0's without an erase
2113 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002114 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2115 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
2116 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +00002117 nvm->ops.release(hw);
Bruce Allane2434552008-11-21 17:02:41 -08002118 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002119 }
2120
2121 /* Great! Everything worked, we can now clear the cached entries. */
2122 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002123 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002124 dev_spec->shadow_ram[i].value = 0xFFFF;
2125 }
2126
Bruce Allan94d81862009-11-20 23:25:26 +00002127 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002128
Bruce Allanad680762008-03-28 09:15:03 -07002129 /*
2130 * Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002131 * until after the next adapter reset.
2132 */
2133 e1000e_reload_nvm(hw);
2134 msleep(10);
2135
Bruce Allane2434552008-11-21 17:02:41 -08002136out:
2137 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002138 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002139
Auke Kokbc7f75f2007-09-17 12:30:59 -07002140 return ret_val;
2141}
2142
2143/**
2144 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2145 * @hw: pointer to the HW structure
2146 *
2147 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2148 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
2149 * calculated, in which case we need to calculate the checksum and set bit 6.
2150 **/
2151static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2152{
2153 s32 ret_val;
2154 u16 data;
2155
Bruce Allanad680762008-03-28 09:15:03 -07002156 /*
2157 * Read 0x19 and check bit 6. If this bit is 0, the checksum
Auke Kokbc7f75f2007-09-17 12:30:59 -07002158 * needs to be fixed. This bit is an indication that the NVM
2159 * was prepared by OEM software and did not calculate the
2160 * checksum...a likely scenario.
2161 */
2162 ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
2163 if (ret_val)
2164 return ret_val;
2165
2166 if ((data & 0x40) == 0) {
2167 data |= 0x40;
2168 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
2169 if (ret_val)
2170 return ret_val;
2171 ret_val = e1000e_update_nvm_checksum(hw);
2172 if (ret_val)
2173 return ret_val;
2174 }
2175
2176 return e1000e_validate_nvm_checksum_generic(hw);
2177}
2178
2179/**
Bruce Allan4a770352008-10-01 17:18:35 -07002180 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
2181 * @hw: pointer to the HW structure
2182 *
2183 * To prevent malicious write/erase of the NVM, set it to be read-only
2184 * so that the hardware ignores all write/erase cycles of the NVM via
2185 * the flash control registers. The shadow-ram copy of the NVM will
2186 * still be updated, however any updates to this copy will not stick
2187 * across driver reloads.
2188 **/
2189void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
2190{
Bruce Allanca15df52009-10-26 11:23:43 +00002191 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07002192 union ich8_flash_protected_range pr0;
2193 union ich8_hws_flash_status hsfsts;
2194 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07002195
Bruce Allan94d81862009-11-20 23:25:26 +00002196 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002197
2198 gfpreg = er32flash(ICH_FLASH_GFPREG);
2199
2200 /* Write-protect GbE Sector of NVM */
2201 pr0.regval = er32flash(ICH_FLASH_PR0);
2202 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
2203 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
2204 pr0.range.wpe = true;
2205 ew32flash(ICH_FLASH_PR0, pr0.regval);
2206
2207 /*
2208 * Lock down a subset of GbE Flash Control Registers, e.g.
2209 * PR0 to prevent the write-protection from being lifted.
2210 * Once FLOCKDN is set, the registers protected by it cannot
2211 * be written until FLOCKDN is cleared by a hardware reset.
2212 */
2213 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2214 hsfsts.hsf_status.flockdn = true;
2215 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2216
Bruce Allan94d81862009-11-20 23:25:26 +00002217 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002218}
2219
2220/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002221 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
2222 * @hw: pointer to the HW structure
2223 * @offset: The offset (in bytes) of the byte/word to read.
2224 * @size: Size of data to read, 1=byte 2=word
2225 * @data: The byte(s) to write to the NVM.
2226 *
2227 * Writes one/two bytes to the NVM using the flash access registers.
2228 **/
2229static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2230 u8 size, u16 data)
2231{
2232 union ich8_hws_flash_status hsfsts;
2233 union ich8_hws_flash_ctrl hsflctl;
2234 u32 flash_linear_addr;
2235 u32 flash_data = 0;
2236 s32 ret_val;
2237 u8 count = 0;
2238
2239 if (size < 1 || size > 2 || data > size * 0xff ||
2240 offset > ICH_FLASH_LINEAR_ADDR_MASK)
2241 return -E1000_ERR_NVM;
2242
2243 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2244 hw->nvm.flash_base_addr;
2245
2246 do {
2247 udelay(1);
2248 /* Steps */
2249 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2250 if (ret_val)
2251 break;
2252
2253 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2254 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2255 hsflctl.hsf_ctrl.fldbcount = size -1;
2256 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
2257 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2258
2259 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2260
2261 if (size == 1)
2262 flash_data = (u32)data & 0x00FF;
2263 else
2264 flash_data = (u32)data;
2265
2266 ew32flash(ICH_FLASH_FDATA0, flash_data);
2267
Bruce Allanad680762008-03-28 09:15:03 -07002268 /*
2269 * check if FCERR is set to 1 , if set to 1, clear it
2270 * and try the whole sequence a few more times else done
2271 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002272 ret_val = e1000_flash_cycle_ich8lan(hw,
2273 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
2274 if (!ret_val)
2275 break;
2276
Bruce Allanad680762008-03-28 09:15:03 -07002277 /*
2278 * If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07002279 * completely hosed, but if the error condition
2280 * is detected, it won't hurt to give it another
2281 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
2282 */
2283 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2284 if (hsfsts.hsf_status.flcerr == 1)
2285 /* Repeat for some time before giving up. */
2286 continue;
2287 if (hsfsts.hsf_status.flcdone == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002288 e_dbg("Timeout error - flash cycle "
Auke Kokbc7f75f2007-09-17 12:30:59 -07002289 "did not complete.");
2290 break;
2291 }
2292 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2293
2294 return ret_val;
2295}
2296
2297/**
2298 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
2299 * @hw: pointer to the HW structure
2300 * @offset: The index of the byte to read.
2301 * @data: The byte to write to the NVM.
2302 *
2303 * Writes a single byte to the NVM using the flash access registers.
2304 **/
2305static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2306 u8 data)
2307{
2308 u16 word = (u16)data;
2309
2310 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
2311}
2312
2313/**
2314 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
2315 * @hw: pointer to the HW structure
2316 * @offset: The offset of the byte to write.
2317 * @byte: The byte to write to the NVM.
2318 *
2319 * Writes a single byte to the NVM using the flash access registers.
2320 * Goes through a retry algorithm before giving up.
2321 **/
2322static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
2323 u32 offset, u8 byte)
2324{
2325 s32 ret_val;
2326 u16 program_retries;
2327
2328 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2329 if (!ret_val)
2330 return ret_val;
2331
2332 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002333 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334 udelay(100);
2335 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2336 if (!ret_val)
2337 break;
2338 }
2339 if (program_retries == 100)
2340 return -E1000_ERR_NVM;
2341
2342 return 0;
2343}
2344
2345/**
2346 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
2347 * @hw: pointer to the HW structure
2348 * @bank: 0 for first bank, 1 for second bank, etc.
2349 *
2350 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
2351 * bank N is 4096 * N + flash_reg_addr.
2352 **/
2353static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
2354{
2355 struct e1000_nvm_info *nvm = &hw->nvm;
2356 union ich8_hws_flash_status hsfsts;
2357 union ich8_hws_flash_ctrl hsflctl;
2358 u32 flash_linear_addr;
2359 /* bank size is in 16bit words - adjust to bytes */
2360 u32 flash_bank_size = nvm->flash_bank_size * 2;
2361 s32 ret_val;
2362 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00002363 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002364
2365 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2366
Bruce Allanad680762008-03-28 09:15:03 -07002367 /*
2368 * Determine HW Sector size: Read BERASE bits of hw flash status
2369 * register
2370 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07002371 * consecutive sectors. The start index for the nth Hw sector
2372 * can be calculated as = bank * 4096 + n * 256
2373 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
2374 * The start index for the nth Hw sector can be calculated
2375 * as = bank * 4096
2376 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
2377 * (ich9 only, otherwise error condition)
2378 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
2379 */
2380 switch (hsfsts.hsf_status.berasesz) {
2381 case 0:
2382 /* Hw sector size 256 */
2383 sector_size = ICH_FLASH_SEG_SIZE_256;
2384 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
2385 break;
2386 case 1:
2387 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00002388 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 break;
2390 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00002391 sector_size = ICH_FLASH_SEG_SIZE_8K;
2392 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002393 break;
2394 case 3:
2395 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00002396 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002397 break;
2398 default:
2399 return -E1000_ERR_NVM;
2400 }
2401
2402 /* Start with the base address, then add the sector offset. */
2403 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00002404 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002405
2406 for (j = 0; j < iteration ; j++) {
2407 do {
2408 /* Steps */
2409 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2410 if (ret_val)
2411 return ret_val;
2412
Bruce Allanad680762008-03-28 09:15:03 -07002413 /*
2414 * Write a value 11 (block Erase) in Flash
2415 * Cycle field in hw flash control
2416 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002417 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2418 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
2419 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2420
Bruce Allanad680762008-03-28 09:15:03 -07002421 /*
2422 * Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07002423 * block into Flash Linear address field in Flash
2424 * Address.
2425 */
2426 flash_linear_addr += (j * sector_size);
2427 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2428
2429 ret_val = e1000_flash_cycle_ich8lan(hw,
2430 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
2431 if (ret_val == 0)
2432 break;
2433
Bruce Allanad680762008-03-28 09:15:03 -07002434 /*
2435 * Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002436 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07002437 * a few more times else Done
2438 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2440 if (hsfsts.hsf_status.flcerr == 1)
Bruce Allanad680762008-03-28 09:15:03 -07002441 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002442 continue;
2443 else if (hsfsts.hsf_status.flcdone == 0)
2444 return ret_val;
2445 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
2446 }
2447
2448 return 0;
2449}
2450
2451/**
2452 * e1000_valid_led_default_ich8lan - Set the default LED settings
2453 * @hw: pointer to the HW structure
2454 * @data: Pointer to the LED settings
2455 *
2456 * Reads the LED default settings from the NVM to data. If the NVM LED
2457 * settings is all 0's or F's, set the LED default to a valid LED default
2458 * setting.
2459 **/
2460static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
2461{
2462 s32 ret_val;
2463
2464 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
2465 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002466 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002467 return ret_val;
2468 }
2469
2470 if (*data == ID_LED_RESERVED_0000 ||
2471 *data == ID_LED_RESERVED_FFFF)
2472 *data = ID_LED_DEFAULT_ICH8LAN;
2473
2474 return 0;
2475}
2476
2477/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002478 * e1000_id_led_init_pchlan - store LED configurations
2479 * @hw: pointer to the HW structure
2480 *
2481 * PCH does not control LEDs via the LEDCTL register, rather it uses
2482 * the PHY LED configuration register.
2483 *
2484 * PCH also does not have an "always on" or "always off" mode which
2485 * complicates the ID feature. Instead of using the "on" mode to indicate
2486 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init()),
2487 * use "link_up" mode. The LEDs will still ID on request if there is no
2488 * link based on logic in e1000_led_[on|off]_pchlan().
2489 **/
2490static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
2491{
2492 struct e1000_mac_info *mac = &hw->mac;
2493 s32 ret_val;
2494 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
2495 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
2496 u16 data, i, temp, shift;
2497
2498 /* Get default ID LED modes */
2499 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
2500 if (ret_val)
2501 goto out;
2502
2503 mac->ledctl_default = er32(LEDCTL);
2504 mac->ledctl_mode1 = mac->ledctl_default;
2505 mac->ledctl_mode2 = mac->ledctl_default;
2506
2507 for (i = 0; i < 4; i++) {
2508 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
2509 shift = (i * 5);
2510 switch (temp) {
2511 case ID_LED_ON1_DEF2:
2512 case ID_LED_ON1_ON2:
2513 case ID_LED_ON1_OFF2:
2514 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2515 mac->ledctl_mode1 |= (ledctl_on << shift);
2516 break;
2517 case ID_LED_OFF1_DEF2:
2518 case ID_LED_OFF1_ON2:
2519 case ID_LED_OFF1_OFF2:
2520 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2521 mac->ledctl_mode1 |= (ledctl_off << shift);
2522 break;
2523 default:
2524 /* Do nothing */
2525 break;
2526 }
2527 switch (temp) {
2528 case ID_LED_DEF1_ON2:
2529 case ID_LED_ON1_ON2:
2530 case ID_LED_OFF1_ON2:
2531 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2532 mac->ledctl_mode2 |= (ledctl_on << shift);
2533 break;
2534 case ID_LED_DEF1_OFF2:
2535 case ID_LED_ON1_OFF2:
2536 case ID_LED_OFF1_OFF2:
2537 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2538 mac->ledctl_mode2 |= (ledctl_off << shift);
2539 break;
2540 default:
2541 /* Do nothing */
2542 break;
2543 }
2544 }
2545
2546out:
2547 return ret_val;
2548}
2549
2550/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002551 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
2552 * @hw: pointer to the HW structure
2553 *
2554 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
2555 * register, so the the bus width is hard coded.
2556 **/
2557static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
2558{
2559 struct e1000_bus_info *bus = &hw->bus;
2560 s32 ret_val;
2561
2562 ret_val = e1000e_get_bus_info_pcie(hw);
2563
Bruce Allanad680762008-03-28 09:15:03 -07002564 /*
2565 * ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566 * a configuration space, but do not contain
2567 * PCI Express Capability registers, so bus width
2568 * must be hardcoded.
2569 */
2570 if (bus->width == e1000_bus_width_unknown)
2571 bus->width = e1000_bus_width_pcie_x1;
2572
2573 return ret_val;
2574}
2575
2576/**
2577 * e1000_reset_hw_ich8lan - Reset the hardware
2578 * @hw: pointer to the HW structure
2579 *
2580 * Does a full reset of the hardware which includes a reset of the PHY and
2581 * MAC.
2582 **/
2583static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2584{
Bruce Allan1d5846b2009-10-29 13:46:05 +00002585 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allandb2932e2009-10-26 11:22:47 +00002586 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002587 u32 ctrl, icr, kab;
2588 s32 ret_val;
2589
Bruce Allanad680762008-03-28 09:15:03 -07002590 /*
2591 * Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07002592 * on the last TLP read/write transaction when MAC is reset.
2593 */
2594 ret_val = e1000e_disable_pcie_master(hw);
2595 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002596 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002597 }
2598
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002599 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002600 ew32(IMC, 0xffffffff);
2601
Bruce Allanad680762008-03-28 09:15:03 -07002602 /*
2603 * Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07002604 * any pending transactions to complete before we hit the MAC
2605 * with the global reset.
2606 */
2607 ew32(RCTL, 0);
2608 ew32(TCTL, E1000_TCTL_PSP);
2609 e1e_flush();
2610
2611 msleep(10);
2612
2613 /* Workaround for ICH8 bit corruption issue in FIFO memory */
2614 if (hw->mac.type == e1000_ich8lan) {
2615 /* Set Tx and Rx buffer allocation to 8k apiece. */
2616 ew32(PBA, E1000_PBA_8K);
2617 /* Set Packet Buffer Size to 16k. */
2618 ew32(PBS, E1000_PBS_16K);
2619 }
2620
Bruce Allan1d5846b2009-10-29 13:46:05 +00002621 if (hw->mac.type == e1000_pchlan) {
2622 /* Save the NVM K1 bit setting*/
2623 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &reg);
2624 if (ret_val)
2625 return ret_val;
2626
2627 if (reg & E1000_NVM_K1_ENABLE)
2628 dev_spec->nvm_k1_enabled = true;
2629 else
2630 dev_spec->nvm_k1_enabled = false;
2631 }
2632
Auke Kokbc7f75f2007-09-17 12:30:59 -07002633 ctrl = er32(CTRL);
2634
2635 if (!e1000_check_reset_block(hw)) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00002636 /* Clear PHY Reset Asserted bit */
2637 if (hw->mac.type >= e1000_pchlan) {
2638 u32 status = er32(STATUS);
2639 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
2640 }
2641
Bruce Allanad680762008-03-28 09:15:03 -07002642 /*
2643 * PHY HW reset requires MAC CORE reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07002644 * time to make sure the interface between MAC and the
2645 * external PHY is reset.
2646 */
2647 ctrl |= E1000_CTRL_PHY_RST;
2648 }
2649 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002650 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002651 ew32(CTRL, (ctrl | E1000_CTRL_RST));
2652 msleep(20);
2653
Bruce Allanfc0c7762009-07-01 13:27:55 +00002654 if (!ret_val)
Jeff Kirsher30bb0e02008-12-11 21:28:11 -08002655 e1000_release_swflag_ich8lan(hw);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07002656
Bruce Allanfc0c7762009-07-01 13:27:55 +00002657 if (ctrl & E1000_CTRL_PHY_RST)
2658 ret_val = hw->phy.ops.get_cfg_done(hw);
2659
2660 if (hw->mac.type >= e1000_ich10lan) {
2661 e1000_lan_init_done_ich8lan(hw);
2662 } else {
2663 ret_val = e1000e_get_auto_rd_done(hw);
2664 if (ret_val) {
2665 /*
2666 * When auto config read does not complete, do not
2667 * return with an error. This can happen in situations
2668 * where there is no eeprom and prevents getting link.
2669 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002670 e_dbg("Auto Read Done did not complete\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002671 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002672 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002673 /* Dummy read to clear the phy wakeup bit after lcd reset */
2674 if (hw->mac.type == e1000_pchlan)
2675 e1e_rphy(hw, BM_WUC, &reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002676
Bruce Allanf523d212009-10-29 13:45:45 +00002677 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2678 if (ret_val)
2679 goto out;
2680
2681 if (hw->mac.type == e1000_pchlan) {
2682 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
2683 if (ret_val)
2684 goto out;
2685 }
Bruce Allan7d3cabb2009-07-01 13:29:08 +00002686 /*
2687 * For PCH, this write will make sure that any noise
2688 * will be detected as a CRC error and be dropped rather than show up
2689 * as a bad packet to the DMA engine.
2690 */
2691 if (hw->mac.type == e1000_pchlan)
2692 ew32(CRC_OFFSET, 0x65656565);
2693
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694 ew32(IMC, 0xffffffff);
2695 icr = er32(ICR);
2696
2697 kab = er32(KABGTXD);
2698 kab |= E1000_KABGTXD_BGSQLBIAS;
2699 ew32(KABGTXD, kab);
2700
Bruce Allana4f58f52009-06-02 11:29:18 +00002701 if (hw->mac.type == e1000_pchlan)
2702 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2703
Bruce Allanf523d212009-10-29 13:45:45 +00002704out:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002705 return ret_val;
2706}
2707
2708/**
2709 * e1000_init_hw_ich8lan - Initialize the hardware
2710 * @hw: pointer to the HW structure
2711 *
2712 * Prepares the hardware for transmit and receive by doing the following:
2713 * - initialize hardware bits
2714 * - initialize LED identification
2715 * - setup receive address registers
2716 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08002717 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718 * - clear statistics
2719 **/
2720static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
2721{
2722 struct e1000_mac_info *mac = &hw->mac;
2723 u32 ctrl_ext, txdctl, snoop;
2724 s32 ret_val;
2725 u16 i;
2726
2727 e1000_initialize_hw_bits_ich8lan(hw);
2728
2729 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00002730 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00002731 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002732 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00002733 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002734
2735 /* Setup the receive address. */
2736 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
2737
2738 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002739 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002740 for (i = 0; i < mac->mta_reg_count; i++)
2741 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
2742
Bruce Allanfc0c7762009-07-01 13:27:55 +00002743 /*
2744 * The 82578 Rx buffer will stall if wakeup is enabled in host and
2745 * the ME. Reading the BM_WUC register will clear the host wakeup bit.
2746 * Reset the phy after disabling host wakeup to reset the Rx buffer.
2747 */
2748 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan94d81862009-11-20 23:25:26 +00002749 hw->phy.ops.read_reg(hw, BM_WUC, &i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002750 ret_val = e1000_phy_hw_reset_ich8lan(hw);
2751 if (ret_val)
2752 return ret_val;
2753 }
2754
Auke Kokbc7f75f2007-09-17 12:30:59 -07002755 /* Setup link and flow control */
2756 ret_val = e1000_setup_link_ich8lan(hw);
2757
2758 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002759 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002760 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2761 E1000_TXDCTL_FULL_TX_DESC_WB;
2762 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2763 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002764 ew32(TXDCTL(0), txdctl);
2765 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002766 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2767 E1000_TXDCTL_FULL_TX_DESC_WB;
2768 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2769 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002770 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002771
Bruce Allanad680762008-03-28 09:15:03 -07002772 /*
2773 * ICH8 has opposite polarity of no_snoop bits.
2774 * By default, we should use snoop behavior.
2775 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002776 if (mac->type == e1000_ich8lan)
2777 snoop = PCIE_ICH8_SNOOP_ALL;
2778 else
2779 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
2780 e1000e_set_pcie_no_snoop(hw, snoop);
2781
2782 ctrl_ext = er32(CTRL_EXT);
2783 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2784 ew32(CTRL_EXT, ctrl_ext);
2785
Bruce Allanad680762008-03-28 09:15:03 -07002786 /*
2787 * Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07002788 * important that we do this after we have tried to establish link
2789 * because the symbol error count will increment wildly if there
2790 * is no link.
2791 */
2792 e1000_clear_hw_cntrs_ich8lan(hw);
2793
2794 return 0;
2795}
2796/**
2797 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
2798 * @hw: pointer to the HW structure
2799 *
2800 * Sets/Clears required hardware bits necessary for correctly setting up the
2801 * hardware for transmit and receive.
2802 **/
2803static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
2804{
2805 u32 reg;
2806
2807 /* Extended Device Control */
2808 reg = er32(CTRL_EXT);
2809 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00002810 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
2811 if (hw->mac.type >= e1000_pchlan)
2812 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813 ew32(CTRL_EXT, reg);
2814
2815 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002816 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002817 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002818 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819
2820 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002821 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002822 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002823 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002824
2825 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002826 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002827 if (hw->mac.type == e1000_ich8lan)
2828 reg |= (1 << 28) | (1 << 29);
2829 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002830 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831
2832 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002833 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834 if (er32(TCTL) & E1000_TCTL_MULR)
2835 reg &= ~(1 << 28);
2836 else
2837 reg |= (1 << 28);
2838 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002839 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002840
2841 /* Device Status */
2842 if (hw->mac.type == e1000_ich8lan) {
2843 reg = er32(STATUS);
2844 reg &= ~(1 << 31);
2845 ew32(STATUS, reg);
2846 }
2847}
2848
2849/**
2850 * e1000_setup_link_ich8lan - Setup flow control and link settings
2851 * @hw: pointer to the HW structure
2852 *
2853 * Determines which flow control settings to use, then configures flow
2854 * control. Calls the appropriate media-specific link configuration
2855 * function. Assuming the adapter has a valid link partner, a valid link
2856 * should be established. Assumes the hardware has previously been reset
2857 * and the transmitter and receiver are not enabled.
2858 **/
2859static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
2860{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002861 s32 ret_val;
2862
2863 if (e1000_check_reset_block(hw))
2864 return 0;
2865
Bruce Allanad680762008-03-28 09:15:03 -07002866 /*
2867 * ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07002868 * the default flow control setting, so we explicitly
2869 * set it to full.
2870 */
Bruce Allan37289d92009-06-02 11:29:37 +00002871 if (hw->fc.requested_mode == e1000_fc_default) {
2872 /* Workaround h/w hang when Tx flow control enabled */
2873 if (hw->mac.type == e1000_pchlan)
2874 hw->fc.requested_mode = e1000_fc_rx_pause;
2875 else
2876 hw->fc.requested_mode = e1000_fc_full;
2877 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002878
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002879 /*
2880 * Save off the requested flow control mode for use later. Depending
2881 * on the link partner's capabilities, we may or may not use this mode.
2882 */
2883 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002884
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002885 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002886 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002887
2888 /* Continue to configure the copper link. */
2889 ret_val = e1000_setup_copper_link_ich8lan(hw);
2890 if (ret_val)
2891 return ret_val;
2892
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002893 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00002894 if ((hw->phy.type == e1000_phy_82578) ||
2895 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan94d81862009-11-20 23:25:26 +00002896 ret_val = hw->phy.ops.write_reg(hw,
Bruce Allana4f58f52009-06-02 11:29:18 +00002897 PHY_REG(BM_PORT_CTRL_PAGE, 27),
2898 hw->fc.pause_time);
2899 if (ret_val)
2900 return ret_val;
2901 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002902
2903 return e1000e_set_fc_watermarks(hw);
2904}
2905
2906/**
2907 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
2908 * @hw: pointer to the HW structure
2909 *
2910 * Configures the kumeran interface to the PHY to wait the appropriate time
2911 * when polling the PHY, then call the generic setup_copper_link to finish
2912 * configuring the copper link.
2913 **/
2914static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
2915{
2916 u32 ctrl;
2917 s32 ret_val;
2918 u16 reg_data;
2919
2920 ctrl = er32(CTRL);
2921 ctrl |= E1000_CTRL_SLU;
2922 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2923 ew32(CTRL, ctrl);
2924
Bruce Allanad680762008-03-28 09:15:03 -07002925 /*
2926 * Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07002927 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07002928 * this fixes erroneous timeouts at 10Mbps.
2929 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002930 ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
2931 if (ret_val)
2932 return ret_val;
2933 ret_val = e1000e_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
2934 if (ret_val)
2935 return ret_val;
2936 reg_data |= 0x3F;
2937 ret_val = e1000e_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
2938 if (ret_val)
2939 return ret_val;
2940
Bruce Allana4f58f52009-06-02 11:29:18 +00002941 switch (hw->phy.type) {
2942 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002943 ret_val = e1000e_copper_link_setup_igp(hw);
2944 if (ret_val)
2945 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002946 break;
2947 case e1000_phy_bm:
2948 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002949 ret_val = e1000e_copper_link_setup_m88(hw);
2950 if (ret_val)
2951 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002952 break;
2953 case e1000_phy_82577:
2954 ret_val = e1000_copper_link_setup_82577(hw);
2955 if (ret_val)
2956 return ret_val;
2957 break;
2958 case e1000_phy_ife:
Bruce Allan94d81862009-11-20 23:25:26 +00002959 ret_val = hw->phy.ops.read_reg(hw, IFE_PHY_MDIX_CONTROL,
Bruce Allana4f58f52009-06-02 11:29:18 +00002960 &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002961 if (ret_val)
2962 return ret_val;
2963
2964 reg_data &= ~IFE_PMC_AUTO_MDIX;
2965
2966 switch (hw->phy.mdix) {
2967 case 1:
2968 reg_data &= ~IFE_PMC_FORCE_MDIX;
2969 break;
2970 case 2:
2971 reg_data |= IFE_PMC_FORCE_MDIX;
2972 break;
2973 case 0:
2974 default:
2975 reg_data |= IFE_PMC_AUTO_MDIX;
2976 break;
2977 }
Bruce Allan94d81862009-11-20 23:25:26 +00002978 ret_val = hw->phy.ops.write_reg(hw, IFE_PHY_MDIX_CONTROL,
Bruce Allana4f58f52009-06-02 11:29:18 +00002979 reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002980 if (ret_val)
2981 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002982 break;
2983 default:
2984 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002985 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986 return e1000e_setup_copper_link(hw);
2987}
2988
2989/**
2990 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
2991 * @hw: pointer to the HW structure
2992 * @speed: pointer to store current link speed
2993 * @duplex: pointer to store the current link duplex
2994 *
Bruce Allanad680762008-03-28 09:15:03 -07002995 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07002996 * information and then calls the Kumeran lock loss workaround for links at
2997 * gigabit speeds.
2998 **/
2999static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3000 u16 *duplex)
3001{
3002 s32 ret_val;
3003
3004 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3005 if (ret_val)
3006 return ret_val;
3007
3008 if ((hw->mac.type == e1000_ich8lan) &&
3009 (hw->phy.type == e1000_phy_igp_3) &&
3010 (*speed == SPEED_1000)) {
3011 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3012 }
3013
3014 return ret_val;
3015}
3016
3017/**
3018 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3019 * @hw: pointer to the HW structure
3020 *
3021 * Work-around for 82566 Kumeran PCS lock loss:
3022 * On link status change (i.e. PCI reset, speed change) and link is up and
3023 * speed is gigabit-
3024 * 0) if workaround is optionally disabled do nothing
3025 * 1) wait 1ms for Kumeran link to come up
3026 * 2) check Kumeran Diagnostic register PCS lock loss bit
3027 * 3) if not set the link is locked (all is good), otherwise...
3028 * 4) reset the PHY
3029 * 5) repeat up to 10 times
3030 * Note: this is only called for IGP3 copper when speed is 1gb.
3031 **/
3032static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3033{
3034 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3035 u32 phy_ctrl;
3036 s32 ret_val;
3037 u16 i, data;
3038 bool link;
3039
3040 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3041 return 0;
3042
Bruce Allanad680762008-03-28 09:15:03 -07003043 /*
3044 * Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003045 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003046 * stability
3047 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003048 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3049 if (!link)
3050 return 0;
3051
3052 for (i = 0; i < 10; i++) {
3053 /* read once to clear */
3054 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3055 if (ret_val)
3056 return ret_val;
3057 /* and again to get new status */
3058 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3059 if (ret_val)
3060 return ret_val;
3061
3062 /* check for PCS lock */
3063 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3064 return 0;
3065
3066 /* Issue PHY reset */
3067 e1000_phy_hw_reset(hw);
3068 mdelay(5);
3069 }
3070 /* Disable GigE link negotiation */
3071 phy_ctrl = er32(PHY_CTRL);
3072 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3073 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3074 ew32(PHY_CTRL, phy_ctrl);
3075
Bruce Allanad680762008-03-28 09:15:03 -07003076 /*
3077 * Call gig speed drop workaround on Gig disable before accessing
3078 * any PHY registers
3079 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003080 e1000e_gig_downshift_workaround_ich8lan(hw);
3081
3082 /* unable to acquire PCS lock */
3083 return -E1000_ERR_PHY;
3084}
3085
3086/**
Bruce Allanad680762008-03-28 09:15:03 -07003087 * e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003088 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003089 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003090 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003091 * If ICH8, set the current Kumeran workaround state (enabled - true
3092 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093 **/
3094void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3095 bool state)
3096{
3097 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3098
3099 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003100 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003101 return;
3102 }
3103
3104 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3105}
3106
3107/**
3108 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3109 * @hw: pointer to the HW structure
3110 *
3111 * Workaround for 82566 power-down on D3 entry:
3112 * 1) disable gigabit link
3113 * 2) write VR power-down enable
3114 * 3) read it back
3115 * Continue if successful, else issue LCD reset and repeat
3116 **/
3117void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3118{
3119 u32 reg;
3120 u16 data;
3121 u8 retry = 0;
3122
3123 if (hw->phy.type != e1000_phy_igp_3)
3124 return;
3125
3126 /* Try the workaround twice (if needed) */
3127 do {
3128 /* Disable link */
3129 reg = er32(PHY_CTRL);
3130 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3131 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3132 ew32(PHY_CTRL, reg);
3133
Bruce Allanad680762008-03-28 09:15:03 -07003134 /*
3135 * Call gig speed drop workaround on Gig disable before
3136 * accessing any PHY registers
3137 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003138 if (hw->mac.type == e1000_ich8lan)
3139 e1000e_gig_downshift_workaround_ich8lan(hw);
3140
3141 /* Write VR power-down enable */
3142 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3143 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3144 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
3145
3146 /* Read it back and test */
3147 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3148 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3149 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
3150 break;
3151
3152 /* Issue PHY reset and repeat at most one more time */
3153 reg = er32(CTRL);
3154 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
3155 retry++;
3156 } while (retry);
3157}
3158
3159/**
3160 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
3161 * @hw: pointer to the HW structure
3162 *
3163 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08003164 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07003165 * 1) Set Kumeran Near-end loopback
3166 * 2) Clear Kumeran Near-end loopback
3167 * Should only be called for ICH8[m] devices with IGP_3 Phy.
3168 **/
3169void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
3170{
3171 s32 ret_val;
3172 u16 reg_data;
3173
3174 if ((hw->mac.type != e1000_ich8lan) ||
3175 (hw->phy.type != e1000_phy_igp_3))
3176 return;
3177
3178 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3179 &reg_data);
3180 if (ret_val)
3181 return;
3182 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
3183 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3184 reg_data);
3185 if (ret_val)
3186 return;
3187 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
3188 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3189 reg_data);
3190}
3191
3192/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003193 * e1000e_disable_gig_wol_ich8lan - disable gig during WoL
3194 * @hw: pointer to the HW structure
3195 *
3196 * During S0 to Sx transition, it is possible the link remains at gig
3197 * instead of negotiating to a lower speed. Before going to Sx, set
3198 * 'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
3199 * to a lower speed.
3200 *
Bruce Allana4f58f52009-06-02 11:29:18 +00003201 * Should only be called for applicable parts.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003202 **/
3203void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
3204{
3205 u32 phy_ctrl;
3206
Bruce Allana4f58f52009-06-02 11:29:18 +00003207 switch (hw->mac.type) {
Bruce Allan9e135a22009-12-01 15:50:31 +00003208 case e1000_ich8lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00003209 case e1000_ich9lan:
3210 case e1000_ich10lan:
3211 case e1000_pchlan:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003212 phy_ctrl = er32(PHY_CTRL);
3213 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
3214 E1000_PHY_CTRL_GBE_DISABLE;
3215 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00003216
Bruce Allana4f58f52009-06-02 11:29:18 +00003217 if (hw->mac.type == e1000_pchlan)
Bruce Allan74eee2e2009-10-22 21:22:18 -07003218 e1000_phy_hw_reset_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00003219 default:
3220 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003221 }
3222
3223 return;
3224}
3225
3226/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003227 * e1000_cleanup_led_ich8lan - Restore the default LED operation
3228 * @hw: pointer to the HW structure
3229 *
3230 * Return the LED back to the default configuration.
3231 **/
3232static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
3233{
3234 if (hw->phy.type == e1000_phy_ife)
3235 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
3236
3237 ew32(LEDCTL, hw->mac.ledctl_default);
3238 return 0;
3239}
3240
3241/**
Auke Kok489815c2008-02-21 15:11:07 -08003242 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07003243 * @hw: pointer to the HW structure
3244 *
Auke Kok489815c2008-02-21 15:11:07 -08003245 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003246 **/
3247static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
3248{
3249 if (hw->phy.type == e1000_phy_ife)
3250 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3251 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
3252
3253 ew32(LEDCTL, hw->mac.ledctl_mode2);
3254 return 0;
3255}
3256
3257/**
Auke Kok489815c2008-02-21 15:11:07 -08003258 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07003259 * @hw: pointer to the HW structure
3260 *
Auke Kok489815c2008-02-21 15:11:07 -08003261 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003262 **/
3263static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
3264{
3265 if (hw->phy.type == e1000_phy_ife)
3266 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3267 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
3268
3269 ew32(LEDCTL, hw->mac.ledctl_mode1);
3270 return 0;
3271}
3272
3273/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003274 * e1000_setup_led_pchlan - Configures SW controllable LED
3275 * @hw: pointer to the HW structure
3276 *
3277 * This prepares the SW controllable LED for use.
3278 **/
3279static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
3280{
Bruce Allan94d81862009-11-20 23:25:26 +00003281 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
Bruce Allana4f58f52009-06-02 11:29:18 +00003282 (u16)hw->mac.ledctl_mode1);
3283}
3284
3285/**
3286 * e1000_cleanup_led_pchlan - Restore the default LED operation
3287 * @hw: pointer to the HW structure
3288 *
3289 * Return the LED back to the default configuration.
3290 **/
3291static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
3292{
Bruce Allan94d81862009-11-20 23:25:26 +00003293 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
Bruce Allana4f58f52009-06-02 11:29:18 +00003294 (u16)hw->mac.ledctl_default);
3295}
3296
3297/**
3298 * e1000_led_on_pchlan - Turn LEDs on
3299 * @hw: pointer to the HW structure
3300 *
3301 * Turn on the LEDs.
3302 **/
3303static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
3304{
3305 u16 data = (u16)hw->mac.ledctl_mode2;
3306 u32 i, led;
3307
3308 /*
3309 * If no link, then turn LED on by setting the invert bit
3310 * for each LED that's mode is "link_up" in ledctl_mode2.
3311 */
3312 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3313 for (i = 0; i < 3; i++) {
3314 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3315 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3316 E1000_LEDCTL_MODE_LINK_UP)
3317 continue;
3318 if (led & E1000_PHY_LED0_IVRT)
3319 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3320 else
3321 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3322 }
3323 }
3324
Bruce Allan94d81862009-11-20 23:25:26 +00003325 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003326}
3327
3328/**
3329 * e1000_led_off_pchlan - Turn LEDs off
3330 * @hw: pointer to the HW structure
3331 *
3332 * Turn off the LEDs.
3333 **/
3334static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
3335{
3336 u16 data = (u16)hw->mac.ledctl_mode1;
3337 u32 i, led;
3338
3339 /*
3340 * If no link, then turn LED off by clearing the invert bit
3341 * for each LED that's mode is "link_up" in ledctl_mode1.
3342 */
3343 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3344 for (i = 0; i < 3; i++) {
3345 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3346 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3347 E1000_LEDCTL_MODE_LINK_UP)
3348 continue;
3349 if (led & E1000_PHY_LED0_IVRT)
3350 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3351 else
3352 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3353 }
3354 }
3355
Bruce Allan94d81862009-11-20 23:25:26 +00003356 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003357}
3358
3359/**
Bruce Allanf4187b52008-08-26 18:36:50 -07003360 * e1000_get_cfg_done_ich8lan - Read config done bit
3361 * @hw: pointer to the HW structure
3362 *
3363 * Read the management control register for the config done bit for
3364 * completion status. NOTE: silicon which is EEPROM-less will fail trying
3365 * to read the config done bit, so an error is *ONLY* logged and returns
Bruce Allana4f58f52009-06-02 11:29:18 +00003366 * 0. If we were to return with error, EEPROM-less silicon
Bruce Allanf4187b52008-08-26 18:36:50 -07003367 * would not be able to be reset or change link.
3368 **/
3369static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
3370{
3371 u32 bank = 0;
3372
Bruce Allanfc0c7762009-07-01 13:27:55 +00003373 if (hw->mac.type >= e1000_pchlan) {
3374 u32 status = er32(STATUS);
3375
3376 if (status & E1000_STATUS_PHYRA)
3377 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
3378 else
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003379 e_dbg("PHY Reset Asserted not set - needs delay\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00003380 }
3381
Bruce Allanf4187b52008-08-26 18:36:50 -07003382 e1000e_get_cfg_done(hw);
3383
3384 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allana4f58f52009-06-02 11:29:18 +00003385 if ((hw->mac.type != e1000_ich10lan) &&
3386 (hw->mac.type != e1000_pchlan)) {
Bruce Allanf4187b52008-08-26 18:36:50 -07003387 if (((er32(EECD) & E1000_EECD_PRES) == 0) &&
3388 (hw->phy.type == e1000_phy_igp_3)) {
3389 e1000e_phy_init_script_igp3(hw);
3390 }
3391 } else {
3392 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
3393 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003394 e_dbg("EEPROM not present\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07003395 return -E1000_ERR_CONFIG;
3396 }
3397 }
3398
3399 return 0;
3400}
3401
3402/**
Bruce Allan17f208d2009-12-01 15:47:22 +00003403 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
3404 * @hw: pointer to the HW structure
3405 *
3406 * In the case of a PHY power down to save power, or to turn off link during a
3407 * driver unload, or wake on lan is not enabled, remove the link.
3408 **/
3409static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
3410{
3411 /* If the management interface is not enabled, then power down */
3412 if (!(hw->mac.ops.check_mng_mode(hw) ||
3413 hw->phy.ops.check_reset_block(hw)))
3414 e1000_power_down_phy_copper(hw);
3415
3416 return;
3417}
3418
3419/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003420 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
3421 * @hw: pointer to the HW structure
3422 *
3423 * Clears hardware counters specific to the silicon family and calls
3424 * clear_hw_cntrs_generic to clear all general purpose counters.
3425 **/
3426static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
3427{
Bruce Allana4f58f52009-06-02 11:29:18 +00003428 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003429
3430 e1000e_clear_hw_cntrs_base(hw);
3431
Bruce Allan99673d92009-11-20 23:27:21 +00003432 er32(ALGNERRC);
3433 er32(RXERRC);
3434 er32(TNCRS);
3435 er32(CEXTERR);
3436 er32(TSCTC);
3437 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003438
Bruce Allan99673d92009-11-20 23:27:21 +00003439 er32(MGTPRC);
3440 er32(MGTPDC);
3441 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003442
Bruce Allan99673d92009-11-20 23:27:21 +00003443 er32(IAC);
3444 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003445
Bruce Allana4f58f52009-06-02 11:29:18 +00003446 /* Clear PHY statistics registers */
3447 if ((hw->phy.type == e1000_phy_82578) ||
3448 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan94d81862009-11-20 23:25:26 +00003449 hw->phy.ops.read_reg(hw, HV_SCC_UPPER, &phy_data);
3450 hw->phy.ops.read_reg(hw, HV_SCC_LOWER, &phy_data);
3451 hw->phy.ops.read_reg(hw, HV_ECOL_UPPER, &phy_data);
3452 hw->phy.ops.read_reg(hw, HV_ECOL_LOWER, &phy_data);
3453 hw->phy.ops.read_reg(hw, HV_MCC_UPPER, &phy_data);
3454 hw->phy.ops.read_reg(hw, HV_MCC_LOWER, &phy_data);
3455 hw->phy.ops.read_reg(hw, HV_LATECOL_UPPER, &phy_data);
3456 hw->phy.ops.read_reg(hw, HV_LATECOL_LOWER, &phy_data);
3457 hw->phy.ops.read_reg(hw, HV_COLC_UPPER, &phy_data);
3458 hw->phy.ops.read_reg(hw, HV_COLC_LOWER, &phy_data);
3459 hw->phy.ops.read_reg(hw, HV_DC_UPPER, &phy_data);
3460 hw->phy.ops.read_reg(hw, HV_DC_LOWER, &phy_data);
3461 hw->phy.ops.read_reg(hw, HV_TNCRS_UPPER, &phy_data);
3462 hw->phy.ops.read_reg(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003463 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003464}
3465
3466static struct e1000_mac_operations ich8_mac_ops = {
Bruce Allana4f58f52009-06-02 11:29:18 +00003467 .id_led_init = e1000e_id_led_init,
Bruce Allan4662e822008-08-26 18:37:06 -07003468 .check_mng_mode = e1000_check_mng_mode_ich8lan,
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003469 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003470 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003471 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
3472 .get_bus_info = e1000_get_bus_info_ich8lan,
3473 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003474 /* led_on dependent on mac type */
3475 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003476 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003477 .reset_hw = e1000_reset_hw_ich8lan,
3478 .init_hw = e1000_init_hw_ich8lan,
3479 .setup_link = e1000_setup_link_ich8lan,
3480 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003481 /* id_led_init dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003482};
3483
3484static struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00003485 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003486 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003487 .commit = NULL,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003488 .force_speed_duplex = e1000_phy_force_speed_duplex_ich8lan,
Bruce Allanf4187b52008-08-26 18:36:50 -07003489 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003490 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00003491 .get_info = e1000_get_phy_info_ich8lan,
3492 .read_reg = e1000e_read_phy_reg_igp,
3493 .release = e1000_release_swflag_ich8lan,
3494 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003495 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
3496 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003497 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003498};
3499
3500static struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00003501 .acquire = e1000_acquire_nvm_ich8lan,
3502 .read = e1000_read_nvm_ich8lan,
3503 .release = e1000_release_nvm_ich8lan,
3504 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003505 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003506 .validate = e1000_validate_nvm_checksum_ich8lan,
3507 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003508};
3509
3510struct e1000_info e1000_ich8_info = {
3511 .mac = e1000_ich8lan,
3512 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003513 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003514 | FLAG_RX_CSUM_ENABLED
3515 | FLAG_HAS_CTRLEXT_ON_LOAD
3516 | FLAG_HAS_AMT
3517 | FLAG_HAS_FLASH
3518 | FLAG_APME_IN_WUC,
3519 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003520 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003521 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003522 .mac_ops = &ich8_mac_ops,
3523 .phy_ops = &ich8_phy_ops,
3524 .nvm_ops = &ich8_nvm_ops,
3525};
3526
3527struct e1000_info e1000_ich9_info = {
3528 .mac = e1000_ich9lan,
3529 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003530 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003531 | FLAG_HAS_WOL
3532 | FLAG_RX_CSUM_ENABLED
3533 | FLAG_HAS_CTRLEXT_ON_LOAD
3534 | FLAG_HAS_AMT
3535 | FLAG_HAS_ERT
3536 | FLAG_HAS_FLASH
3537 | FLAG_APME_IN_WUC,
3538 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003539 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003540 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003541 .mac_ops = &ich8_mac_ops,
3542 .phy_ops = &ich8_phy_ops,
3543 .nvm_ops = &ich8_nvm_ops,
3544};
3545
Bruce Allanf4187b52008-08-26 18:36:50 -07003546struct e1000_info e1000_ich10_info = {
3547 .mac = e1000_ich10lan,
3548 .flags = FLAG_HAS_JUMBO_FRAMES
3549 | FLAG_IS_ICH
3550 | FLAG_HAS_WOL
3551 | FLAG_RX_CSUM_ENABLED
3552 | FLAG_HAS_CTRLEXT_ON_LOAD
3553 | FLAG_HAS_AMT
3554 | FLAG_HAS_ERT
3555 | FLAG_HAS_FLASH
3556 | FLAG_APME_IN_WUC,
3557 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003558 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07003559 .get_variants = e1000_get_variants_ich8lan,
3560 .mac_ops = &ich8_mac_ops,
3561 .phy_ops = &ich8_phy_ops,
3562 .nvm_ops = &ich8_nvm_ops,
3563};
Bruce Allana4f58f52009-06-02 11:29:18 +00003564
3565struct e1000_info e1000_pch_info = {
3566 .mac = e1000_pchlan,
3567 .flags = FLAG_IS_ICH
3568 | FLAG_HAS_WOL
3569 | FLAG_RX_CSUM_ENABLED
3570 | FLAG_HAS_CTRLEXT_ON_LOAD
3571 | FLAG_HAS_AMT
3572 | FLAG_HAS_FLASH
3573 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00003574 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00003575 | FLAG_APME_IN_WUC,
3576 .pba = 26,
3577 .max_hw_frame_size = 4096,
3578 .get_variants = e1000_get_variants_ich8lan,
3579 .mac_ops = &ich8_mac_ops,
3580 .phy_ops = &ich8_phy_ops,
3581 .nvm_ops = &ich8_nvm_ops,
3582};