blob: e1f244a478076ccf21d0a055404bb202ebe7f703 [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 */
Bruce Allan6dfaa762010-05-05 22:00:06 +000086/* FW established a valid mode */
87#define E1000_ICH_FWSM_FW_VALID 0x00008000
Auke Kokbc7f75f2007-09-17 12:30:59 -070088
89#define E1000_ICH_MNG_IAMT_MODE 0x2
90
91#define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
92 (ID_LED_DEF1_OFF2 << 8) | \
93 (ID_LED_DEF1_ON2 << 4) | \
94 (ID_LED_DEF1_DEF2))
95
96#define E1000_ICH_NVM_SIG_WORD 0x13
97#define E1000_ICH_NVM_SIG_MASK 0xC000
Bruce Allane2434552008-11-21 17:02:41 -080098#define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
99#define E1000_ICH_NVM_SIG_VALUE 0x80
Auke Kokbc7f75f2007-09-17 12:30:59 -0700100
101#define E1000_ICH8_LAN_INIT_TIMEOUT 1500
102
103#define E1000_FEXTNVM_SW_CONFIG 1
104#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
105
106#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
107
108#define E1000_ICH_RAR_ENTRIES 7
109
110#define PHY_PAGE_SHIFT 5
111#define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
112 ((reg) & MAX_PHY_REG_ADDRESS))
113#define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
114#define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
115
116#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
117#define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
118#define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
119
Bruce Allana4f58f52009-06-02 11:29:18 +0000120#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
121
Bruce Allan53ac5a82009-10-26 11:23:06 +0000122#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
123
Bruce Allanf523d212009-10-29 13:45:45 +0000124/* SMBus Address Phy Register */
125#define HV_SMB_ADDR PHY_REG(768, 26)
126#define HV_SMB_ADDR_PEC_EN 0x0200
127#define HV_SMB_ADDR_VALID 0x0080
128
129/* Strapping Option Register - RO */
130#define E1000_STRAP 0x0000C
131#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
132#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
133
Bruce Allanfa2ce132009-10-26 11:23:25 +0000134/* OEM Bits Phy Register */
135#define HV_OEM_BITS PHY_REG(768, 25)
136#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
Bruce Allanf523d212009-10-29 13:45:45 +0000137#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
Bruce Allanfa2ce132009-10-26 11:23:25 +0000138#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
139
Bruce Allan1d5846b2009-10-29 13:46:05 +0000140#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
141#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
142
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000143/* KMRN Mode Control */
144#define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
145#define HV_KMRN_MDIO_SLOW 0x0400
146
Auke Kokbc7f75f2007-09-17 12:30:59 -0700147/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
148/* Offset 04h HSFSTS */
149union ich8_hws_flash_status {
150 struct ich8_hsfsts {
151 u16 flcdone :1; /* bit 0 Flash Cycle Done */
152 u16 flcerr :1; /* bit 1 Flash Cycle Error */
153 u16 dael :1; /* bit 2 Direct Access error Log */
154 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
155 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
156 u16 reserved1 :2; /* bit 13:6 Reserved */
157 u16 reserved2 :6; /* bit 13:6 Reserved */
158 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
159 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
160 } hsf_status;
161 u16 regval;
162};
163
164/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
165/* Offset 06h FLCTL */
166union ich8_hws_flash_ctrl {
167 struct ich8_hsflctl {
168 u16 flcgo :1; /* 0 Flash Cycle Go */
169 u16 flcycle :2; /* 2:1 Flash Cycle */
170 u16 reserved :5; /* 7:3 Reserved */
171 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
172 u16 flockdn :6; /* 15:10 Reserved */
173 } hsf_ctrl;
174 u16 regval;
175};
176
177/* ICH Flash Region Access Permissions */
178union ich8_hws_flash_regacc {
179 struct ich8_flracc {
180 u32 grra :8; /* 0:7 GbE region Read Access */
181 u32 grwa :8; /* 8:15 GbE region Write Access */
182 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
183 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
184 } hsf_flregacc;
185 u16 regval;
186};
187
Bruce Allan4a770352008-10-01 17:18:35 -0700188/* ICH Flash Protected Region */
189union ich8_flash_protected_range {
190 struct ich8_pr {
191 u32 base:13; /* 0:12 Protected Range Base */
192 u32 reserved1:2; /* 13:14 Reserved */
193 u32 rpe:1; /* 15 Read Protection Enable */
194 u32 limit:13; /* 16:28 Protected Range Limit */
195 u32 reserved2:2; /* 29:30 Reserved */
196 u32 wpe:1; /* 31 Write Protection Enable */
197 } range;
198 u32 regval;
199};
200
Auke Kokbc7f75f2007-09-17 12:30:59 -0700201static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
202static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
203static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700204static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
205static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
206 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700207static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
208 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700209static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
210 u16 *data);
211static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
212 u8 size, u16 *data);
213static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
214static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700215static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000216static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
217static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
218static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
219static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
220static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
221static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
222static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
223static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000224static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000225static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000226static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000227static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000228static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700229
230static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
231{
232 return readw(hw->flash_address + reg);
233}
234
235static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
236{
237 return readl(hw->flash_address + reg);
238}
239
240static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
241{
242 writew(val, hw->flash_address + reg);
243}
244
245static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
246{
247 writel(val, hw->flash_address + reg);
248}
249
250#define er16flash(reg) __er16flash(hw, (reg))
251#define er32flash(reg) __er32flash(hw, (reg))
252#define ew16flash(reg,val) __ew16flash(hw, (reg), (val))
253#define ew32flash(reg,val) __ew32flash(hw, (reg), (val))
254
255/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000256 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
257 * @hw: pointer to the HW structure
258 *
259 * Initialize family-specific PHY parameters and function pointers.
260 **/
261static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
262{
263 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan6dfaa762010-05-05 22:00:06 +0000264 u32 ctrl;
Bruce Allana4f58f52009-06-02 11:29:18 +0000265 s32 ret_val = 0;
266
267 phy->addr = 1;
268 phy->reset_delay_us = 100;
269
Bruce Allan94d81862009-11-20 23:25:26 +0000270 phy->ops.read_reg = e1000_read_phy_reg_hv;
271 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000272 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
273 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000274 phy->ops.write_reg = e1000_write_phy_reg_hv;
275 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan17f208d2009-12-01 15:47:22 +0000276 phy->ops.power_up = e1000_power_up_phy_copper;
277 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000278 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
279
Bruce Allan6dfaa762010-05-05 22:00:06 +0000280 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
281 /*
282 * The MAC-PHY interconnect may still be in SMBus mode
283 * after Sx->S0. Toggle the LANPHYPC Value bit to force
284 * the interconnect to PCIe mode, but only if there is no
285 * firmware present otherwise firmware will have done it.
286 */
287 ctrl = er32(CTRL);
288 ctrl |= E1000_CTRL_LANPHYPC_OVERRIDE;
289 ctrl &= ~E1000_CTRL_LANPHYPC_VALUE;
290 ew32(CTRL, ctrl);
291 udelay(10);
292 ctrl &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
293 ew32(CTRL, ctrl);
294 msleep(50);
295 }
296
Bruce Allan627c8a02010-05-05 22:00:27 +0000297 /*
298 * Reset the PHY before any acccess to it. Doing so, ensures that
299 * the PHY is in a known good state before we read/write PHY registers.
300 * The generic reset is sufficient here, because we haven't determined
301 * the PHY type yet.
302 */
303 ret_val = e1000e_phy_hw_reset_generic(hw);
304 if (ret_val)
305 goto out;
306
Bruce Allana4f58f52009-06-02 11:29:18 +0000307 phy->id = e1000_phy_unknown;
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000308 ret_val = e1000e_get_phy_id(hw);
309 if (ret_val)
310 goto out;
311 if ((phy->id == 0) || (phy->id == PHY_REVISION_MASK)) {
312 /*
313 * In case the PHY needs to be in mdio slow mode (eg. 82577),
314 * set slow mode and try to get the PHY id again.
315 */
316 ret_val = e1000_set_mdio_slow_mode_hv(hw);
317 if (ret_val)
318 goto out;
319 ret_val = e1000e_get_phy_id(hw);
320 if (ret_val)
321 goto out;
322 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000323 phy->type = e1000e_get_phy_type_from_id(phy->id);
324
Bruce Allan0be84012009-12-02 17:03:18 +0000325 switch (phy->type) {
326 case e1000_phy_82577:
Bruce Allana4f58f52009-06-02 11:29:18 +0000327 phy->ops.check_polarity = e1000_check_polarity_82577;
328 phy->ops.force_speed_duplex =
329 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000330 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000331 phy->ops.get_info = e1000_get_phy_info_82577;
332 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000333 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000334 case e1000_phy_82578:
335 phy->ops.check_polarity = e1000_check_polarity_m88;
336 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
337 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
338 phy->ops.get_info = e1000e_get_phy_info_m88;
339 break;
340 default:
341 ret_val = -E1000_ERR_PHY;
342 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000343 }
344
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000345out:
Bruce Allana4f58f52009-06-02 11:29:18 +0000346 return ret_val;
347}
348
349/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700350 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
351 * @hw: pointer to the HW structure
352 *
353 * Initialize family-specific PHY parameters and function pointers.
354 **/
355static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
356{
357 struct e1000_phy_info *phy = &hw->phy;
358 s32 ret_val;
359 u16 i = 0;
360
361 phy->addr = 1;
362 phy->reset_delay_us = 100;
363
Bruce Allan17f208d2009-12-01 15:47:22 +0000364 phy->ops.power_up = e1000_power_up_phy_copper;
365 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
366
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700367 /*
368 * We may need to do this twice - once for IGP and if that fails,
369 * we'll set BM func pointers and try again
370 */
371 ret_val = e1000e_determine_phy_address(hw);
372 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000373 phy->ops.write_reg = e1000e_write_phy_reg_bm;
374 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700375 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000376 if (ret_val) {
377 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700378 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000379 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700380 }
381
Auke Kokbc7f75f2007-09-17 12:30:59 -0700382 phy->id = 0;
383 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
384 (i++ < 100)) {
385 msleep(1);
386 ret_val = e1000e_get_phy_id(hw);
387 if (ret_val)
388 return ret_val;
389 }
390
391 /* Verify phy id */
392 switch (phy->id) {
393 case IGP03E1000_E_PHY_ID:
394 phy->type = e1000_phy_igp_3;
395 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000396 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
397 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000398 phy->ops.get_info = e1000e_get_phy_info_igp;
399 phy->ops.check_polarity = e1000_check_polarity_igp;
400 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700401 break;
402 case IFE_E_PHY_ID:
403 case IFE_PLUS_E_PHY_ID:
404 case IFE_C_E_PHY_ID:
405 phy->type = e1000_phy_ife;
406 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000407 phy->ops.get_info = e1000_get_phy_info_ife;
408 phy->ops.check_polarity = e1000_check_polarity_ife;
409 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700410 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700411 case BME1000_E_PHY_ID:
412 phy->type = e1000_phy_bm;
413 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000414 phy->ops.read_reg = e1000e_read_phy_reg_bm;
415 phy->ops.write_reg = e1000e_write_phy_reg_bm;
416 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000417 phy->ops.get_info = e1000e_get_phy_info_m88;
418 phy->ops.check_polarity = e1000_check_polarity_m88;
419 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700420 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700421 default:
422 return -E1000_ERR_PHY;
423 break;
424 }
425
426 return 0;
427}
428
429/**
430 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
431 * @hw: pointer to the HW structure
432 *
433 * Initialize family-specific NVM parameters and function
434 * pointers.
435 **/
436static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
437{
438 struct e1000_nvm_info *nvm = &hw->nvm;
439 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000440 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700441 u16 i;
442
Bruce Allanad680762008-03-28 09:15:03 -0700443 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700444 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000445 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700446 return -E1000_ERR_CONFIG;
447 }
448
449 nvm->type = e1000_nvm_flash_sw;
450
451 gfpreg = er32flash(ICH_FLASH_GFPREG);
452
Bruce Allanad680762008-03-28 09:15:03 -0700453 /*
454 * sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700455 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700456 * the overall size.
457 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700458 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
459 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
460
461 /* flash_base_addr is byte-aligned */
462 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
463
Bruce Allanad680762008-03-28 09:15:03 -0700464 /*
465 * find total size of the NVM, then cut in half since the total
466 * size represents two separate NVM banks.
467 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700468 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
469 << FLASH_SECTOR_ADDR_SHIFT;
470 nvm->flash_bank_size /= 2;
471 /* Adjust to word count */
472 nvm->flash_bank_size /= sizeof(u16);
473
474 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
475
476 /* Clear shadow ram */
477 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000478 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700479 dev_spec->shadow_ram[i].value = 0xFFFF;
480 }
481
482 return 0;
483}
484
485/**
486 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
487 * @hw: pointer to the HW structure
488 *
489 * Initialize family-specific MAC parameters and function
490 * pointers.
491 **/
492static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
493{
494 struct e1000_hw *hw = &adapter->hw;
495 struct e1000_mac_info *mac = &hw->mac;
496
497 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700498 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700499
500 /* Set mta register count */
501 mac->mta_reg_count = 32;
502 /* Set rar entry count */
503 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
504 if (mac->type == e1000_ich8lan)
505 mac->rar_entry_count--;
506 /* Set if manageability features are enabled. */
Bruce Allan564ea9b2009-11-20 23:26:44 +0000507 mac->arc_subsystem_valid = true;
Bruce Allanf464ba82010-01-07 16:31:35 +0000508 /* Adaptive IFS supported */
509 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700510
Bruce Allana4f58f52009-06-02 11:29:18 +0000511 /* LED operations */
512 switch (mac->type) {
513 case e1000_ich8lan:
514 case e1000_ich9lan:
515 case e1000_ich10lan:
516 /* ID LED init */
517 mac->ops.id_led_init = e1000e_id_led_init;
518 /* setup LED */
519 mac->ops.setup_led = e1000e_setup_led_generic;
520 /* cleanup LED */
521 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
522 /* turn on/off LED */
523 mac->ops.led_on = e1000_led_on_ich8lan;
524 mac->ops.led_off = e1000_led_off_ich8lan;
525 break;
526 case e1000_pchlan:
527 /* ID LED init */
528 mac->ops.id_led_init = e1000_id_led_init_pchlan;
529 /* setup LED */
530 mac->ops.setup_led = e1000_setup_led_pchlan;
531 /* cleanup LED */
532 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
533 /* turn on/off LED */
534 mac->ops.led_on = e1000_led_on_pchlan;
535 mac->ops.led_off = e1000_led_off_pchlan;
536 break;
537 default:
538 break;
539 }
540
Auke Kokbc7f75f2007-09-17 12:30:59 -0700541 /* Enable PCS Lock-loss workaround for ICH8 */
542 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000543 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544
545 return 0;
546}
547
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000548/**
549 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
550 * @hw: pointer to the HW structure
551 *
552 * Checks to see of the link status of the hardware has changed. If a
553 * change in link status has been detected, then we read the PHY registers
554 * to get the current speed/duplex if link exists.
555 **/
556static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
557{
558 struct e1000_mac_info *mac = &hw->mac;
559 s32 ret_val;
560 bool link;
561
562 /*
563 * We only want to go out to the PHY registers to see if Auto-Neg
564 * has completed and/or if our link status has changed. The
565 * get_link_status flag is set upon receiving a Link Status
566 * Change or Rx Sequence Error interrupt.
567 */
568 if (!mac->get_link_status) {
569 ret_val = 0;
570 goto out;
571 }
572
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000573 /*
574 * First we want to see if the MII Status Register reports
575 * link. If so, then we want to get the current speed/duplex
576 * of the PHY.
577 */
578 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
579 if (ret_val)
580 goto out;
581
Bruce Allan1d5846b2009-10-29 13:46:05 +0000582 if (hw->mac.type == e1000_pchlan) {
583 ret_val = e1000_k1_gig_workaround_hv(hw, link);
584 if (ret_val)
585 goto out;
586 }
587
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000588 if (!link)
589 goto out; /* No link detected */
590
591 mac->get_link_status = false;
592
593 if (hw->phy.type == e1000_phy_82578) {
594 ret_val = e1000_link_stall_workaround_hv(hw);
595 if (ret_val)
596 goto out;
597 }
598
599 /*
600 * Check if there was DownShift, must be checked
601 * immediately after link-up
602 */
603 e1000e_check_downshift(hw);
604
605 /*
606 * If we are forcing speed/duplex, then we simply return since
607 * we have already determined whether we have link or not.
608 */
609 if (!mac->autoneg) {
610 ret_val = -E1000_ERR_CONFIG;
611 goto out;
612 }
613
614 /*
615 * Auto-Neg is enabled. Auto Speed Detection takes care
616 * of MAC speed/duplex configuration. So we only need to
617 * configure Collision Distance in the MAC.
618 */
619 e1000e_config_collision_dist(hw);
620
621 /*
622 * Configure Flow Control now that Auto-Neg has completed.
623 * First, we need to restore the desired flow control
624 * settings because we may have had to re-autoneg with a
625 * different link partner.
626 */
627 ret_val = e1000e_config_fc_after_link_up(hw);
628 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000629 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000630
631out:
632 return ret_val;
633}
634
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700635static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700636{
637 struct e1000_hw *hw = &adapter->hw;
638 s32 rc;
639
640 rc = e1000_init_mac_params_ich8lan(adapter);
641 if (rc)
642 return rc;
643
644 rc = e1000_init_nvm_params_ich8lan(hw);
645 if (rc)
646 return rc;
647
Bruce Allana4f58f52009-06-02 11:29:18 +0000648 if (hw->mac.type == e1000_pchlan)
649 rc = e1000_init_phy_params_pchlan(hw);
650 else
651 rc = e1000_init_phy_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700652 if (rc)
653 return rc;
654
Bruce Allan2adc55c2009-06-02 11:28:58 +0000655 if (adapter->hw.phy.type == e1000_phy_ife) {
656 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
657 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
658 }
659
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660 if ((adapter->hw.mac.type == e1000_ich8lan) &&
661 (adapter->hw.phy.type == e1000_phy_igp_3))
662 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
663
664 return 0;
665}
666
Thomas Gleixner717d4382008-10-02 16:33:40 -0700667static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700668
Auke Kokbc7f75f2007-09-17 12:30:59 -0700669/**
Bruce Allanca15df52009-10-26 11:23:43 +0000670 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
671 * @hw: pointer to the HW structure
672 *
673 * Acquires the mutex for performing NVM operations.
674 **/
675static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
676{
677 mutex_lock(&nvm_mutex);
678
679 return 0;
680}
681
682/**
683 * e1000_release_nvm_ich8lan - Release NVM mutex
684 * @hw: pointer to the HW structure
685 *
686 * Releases the mutex used while performing NVM operations.
687 **/
688static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
689{
690 mutex_unlock(&nvm_mutex);
691
692 return;
693}
694
695static DEFINE_MUTEX(swflag_mutex);
696
697/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700698 * e1000_acquire_swflag_ich8lan - Acquire software control flag
699 * @hw: pointer to the HW structure
700 *
Bruce Allanca15df52009-10-26 11:23:43 +0000701 * Acquires the software control flag for performing PHY and select
702 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700703 **/
704static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
705{
Bruce Allan373a88d2009-08-07 07:41:37 +0000706 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
707 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708
Bruce Allanca15df52009-10-26 11:23:43 +0000709 mutex_lock(&swflag_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700710
Auke Kokbc7f75f2007-09-17 12:30:59 -0700711 while (timeout) {
712 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +0000713 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
714 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700715
Auke Kokbc7f75f2007-09-17 12:30:59 -0700716 mdelay(1);
717 timeout--;
718 }
719
720 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000721 e_dbg("SW/FW/HW has locked the resource for too long.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000722 ret_val = -E1000_ERR_CONFIG;
723 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700724 }
725
Bruce Allan53ac5a82009-10-26 11:23:06 +0000726 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +0000727
728 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
729 ew32(EXTCNF_CTRL, extcnf_ctrl);
730
731 while (timeout) {
732 extcnf_ctrl = er32(EXTCNF_CTRL);
733 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
734 break;
735
736 mdelay(1);
737 timeout--;
738 }
739
740 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000741 e_dbg("Failed to acquire the semaphore.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000742 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
743 ew32(EXTCNF_CTRL, extcnf_ctrl);
744 ret_val = -E1000_ERR_CONFIG;
745 goto out;
746 }
747
748out:
749 if (ret_val)
Bruce Allanca15df52009-10-26 11:23:43 +0000750 mutex_unlock(&swflag_mutex);
Bruce Allan373a88d2009-08-07 07:41:37 +0000751
752 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700753}
754
755/**
756 * e1000_release_swflag_ich8lan - Release software control flag
757 * @hw: pointer to the HW structure
758 *
Bruce Allanca15df52009-10-26 11:23:43 +0000759 * Releases the software control flag for performing PHY and select
760 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700761 **/
762static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
763{
764 u32 extcnf_ctrl;
765
766 extcnf_ctrl = er32(EXTCNF_CTRL);
767 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
768 ew32(EXTCNF_CTRL, extcnf_ctrl);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700769
Bruce Allanca15df52009-10-26 11:23:43 +0000770 mutex_unlock(&swflag_mutex);
771
772 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700773}
774
775/**
Bruce Allan4662e822008-08-26 18:37:06 -0700776 * e1000_check_mng_mode_ich8lan - Checks management mode
777 * @hw: pointer to the HW structure
778 *
779 * This checks if the adapter has manageability enabled.
780 * This is a function pointer entry point only called by read/write
781 * routines for the PHY and NVM parts.
782 **/
783static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
784{
Bruce Allana708dd82009-11-20 23:28:37 +0000785 u32 fwsm;
786
787 fwsm = er32(FWSM);
Bruce Allan4662e822008-08-26 18:37:06 -0700788
789 return (fwsm & E1000_FWSM_MODE_MASK) ==
790 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
791}
792
793/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700794 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
795 * @hw: pointer to the HW structure
796 *
797 * Checks if firmware is blocking the reset of the PHY.
798 * This is a function pointer entry point only called by
799 * reset routines.
800 **/
801static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
802{
803 u32 fwsm;
804
805 fwsm = er32(FWSM);
806
807 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
808}
809
810/**
Bruce Allanf523d212009-10-29 13:45:45 +0000811 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
812 * @hw: pointer to the HW structure
813 *
814 * SW should configure the LCD from the NVM extended configuration region
815 * as a workaround for certain parts.
816 **/
817static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
818{
Bruce Allan8b802a72010-05-10 15:01:10 +0000819 struct e1000_adapter *adapter = hw->adapter;
Bruce Allanf523d212009-10-29 13:45:45 +0000820 struct e1000_phy_info *phy = &hw->phy;
821 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +0000822 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +0000823 u16 word_addr, reg_data, reg_addr, phy_page = 0;
824
Bruce Allan8b802a72010-05-10 15:01:10 +0000825 if (!(hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) &&
826 !(hw->mac.type == e1000_pchlan))
827 return ret_val;
828
Bruce Allan94d81862009-11-20 23:25:26 +0000829 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000830 if (ret_val)
831 return ret_val;
832
833 /*
834 * Initialize the PHY from the NVM on ICH platforms. This
835 * is needed due to an issue where the NVM configuration is
836 * not properly autoloaded after power transitions.
837 * Therefore, after each PHY reset, we will load the
838 * configuration data out of the NVM manually.
839 */
Bruce Allan8b802a72010-05-10 15:01:10 +0000840 if ((adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
841 (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_M) ||
842 (hw->mac.type == e1000_pchlan))
843 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
844 else
845 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
Bruce Allanf523d212009-10-29 13:45:45 +0000846
Bruce Allan8b802a72010-05-10 15:01:10 +0000847 data = er32(FEXTNVM);
848 if (!(data & sw_cfg_mask))
849 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +0000850
Bruce Allan8b802a72010-05-10 15:01:10 +0000851 /* Wait for basic configuration completes before proceeding */
852 e1000_lan_init_done_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000853
Bruce Allan8b802a72010-05-10 15:01:10 +0000854 /*
855 * Make sure HW does not configure LCD from PHY
856 * extended configuration before SW configuration
857 */
858 data = er32(EXTCNF_CTRL);
859 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
860 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +0000861
Bruce Allan8b802a72010-05-10 15:01:10 +0000862 cnf_size = er32(EXTCNF_SIZE);
863 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
864 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
865 if (!cnf_size)
866 goto out;
867
868 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
869 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
870
871 if (!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
872 (hw->mac.type == e1000_pchlan)) {
Bruce Allanf523d212009-10-29 13:45:45 +0000873 /*
Bruce Allan8b802a72010-05-10 15:01:10 +0000874 * HW configures the SMBus address and LEDs when the
875 * OEM and LCD Write Enable bits are set in the NVM.
876 * When both NVM bits are cleared, SW will configure
877 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +0000878 */
Bruce Allan8b802a72010-05-10 15:01:10 +0000879 data = er32(STRAP);
880 data &= E1000_STRAP_SMBUS_ADDRESS_MASK;
881 reg_data = data >> E1000_STRAP_SMBUS_ADDRESS_SHIFT;
882 reg_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
883 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR,
884 reg_data);
885 if (ret_val)
Bruce Allanf523d212009-10-29 13:45:45 +0000886 goto out;
887
Bruce Allan8b802a72010-05-10 15:01:10 +0000888 data = er32(LEDCTL);
889 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
890 (u16)data);
891 if (ret_val)
892 goto out;
893 }
894
895 /* Configure LCD from extended configuration region. */
896
897 /* cnf_base_addr is in DWORD */
898 word_addr = (u16)(cnf_base_addr << 1);
899
900 for (i = 0; i < cnf_size; i++) {
901 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
902 &reg_data);
903 if (ret_val)
Bruce Allanf523d212009-10-29 13:45:45 +0000904 goto out;
905
Bruce Allan8b802a72010-05-10 15:01:10 +0000906 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
907 1, &reg_addr);
908 if (ret_val)
909 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +0000910
Bruce Allan8b802a72010-05-10 15:01:10 +0000911 /* Save off the PHY page for future writes. */
912 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
913 phy_page = reg_data;
914 continue;
Bruce Allanf523d212009-10-29 13:45:45 +0000915 }
Bruce Allanf523d212009-10-29 13:45:45 +0000916
Bruce Allan8b802a72010-05-10 15:01:10 +0000917 reg_addr &= PHY_REG_MASK;
918 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +0000919
Bruce Allan8b802a72010-05-10 15:01:10 +0000920 ret_val = phy->ops.write_reg_locked(hw, (u32)reg_addr,
921 reg_data);
922 if (ret_val)
923 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +0000924 }
925
926out:
Bruce Allan94d81862009-11-20 23:25:26 +0000927 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000928 return ret_val;
929}
930
931/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000932 * e1000_k1_gig_workaround_hv - K1 Si workaround
933 * @hw: pointer to the HW structure
934 * @link: link up bool flag
935 *
936 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
937 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
938 * If link is down, the function will restore the default K1 setting located
939 * in the NVM.
940 **/
941static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
942{
943 s32 ret_val = 0;
944 u16 status_reg = 0;
945 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
946
947 if (hw->mac.type != e1000_pchlan)
948 goto out;
949
950 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +0000951 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000952 if (ret_val)
953 goto out;
954
955 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
956 if (link) {
957 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan94d81862009-11-20 23:25:26 +0000958 ret_val = hw->phy.ops.read_reg_locked(hw, BM_CS_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +0000959 &status_reg);
960 if (ret_val)
961 goto release;
962
963 status_reg &= BM_CS_STATUS_LINK_UP |
964 BM_CS_STATUS_RESOLVED |
965 BM_CS_STATUS_SPEED_MASK;
966
967 if (status_reg == (BM_CS_STATUS_LINK_UP |
968 BM_CS_STATUS_RESOLVED |
969 BM_CS_STATUS_SPEED_1000))
970 k1_enable = false;
971 }
972
973 if (hw->phy.type == e1000_phy_82577) {
Bruce Allan94d81862009-11-20 23:25:26 +0000974 ret_val = hw->phy.ops.read_reg_locked(hw, HV_M_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +0000975 &status_reg);
976 if (ret_val)
977 goto release;
978
979 status_reg &= HV_M_STATUS_LINK_UP |
980 HV_M_STATUS_AUTONEG_COMPLETE |
981 HV_M_STATUS_SPEED_MASK;
982
983 if (status_reg == (HV_M_STATUS_LINK_UP |
984 HV_M_STATUS_AUTONEG_COMPLETE |
985 HV_M_STATUS_SPEED_1000))
986 k1_enable = false;
987 }
988
989 /* Link stall fix for link up */
Bruce Allan94d81862009-11-20 23:25:26 +0000990 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +0000991 0x0100);
992 if (ret_val)
993 goto release;
994
995 } else {
996 /* Link stall fix for link down */
Bruce Allan94d81862009-11-20 23:25:26 +0000997 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +0000998 0x4100);
999 if (ret_val)
1000 goto release;
1001 }
1002
1003 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1004
1005release:
Bruce Allan94d81862009-11-20 23:25:26 +00001006 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001007out:
1008 return ret_val;
1009}
1010
1011/**
1012 * e1000_configure_k1_ich8lan - Configure K1 power state
1013 * @hw: pointer to the HW structure
1014 * @enable: K1 state to configure
1015 *
1016 * Configure the K1 power state based on the provided parameter.
1017 * Assumes semaphore already acquired.
1018 *
1019 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1020 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001021s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001022{
1023 s32 ret_val = 0;
1024 u32 ctrl_reg = 0;
1025 u32 ctrl_ext = 0;
1026 u32 reg = 0;
1027 u16 kmrn_reg = 0;
1028
1029 ret_val = e1000e_read_kmrn_reg_locked(hw,
1030 E1000_KMRNCTRLSTA_K1_CONFIG,
1031 &kmrn_reg);
1032 if (ret_val)
1033 goto out;
1034
1035 if (k1_enable)
1036 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1037 else
1038 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1039
1040 ret_val = e1000e_write_kmrn_reg_locked(hw,
1041 E1000_KMRNCTRLSTA_K1_CONFIG,
1042 kmrn_reg);
1043 if (ret_val)
1044 goto out;
1045
1046 udelay(20);
1047 ctrl_ext = er32(CTRL_EXT);
1048 ctrl_reg = er32(CTRL);
1049
1050 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1051 reg |= E1000_CTRL_FRCSPD;
1052 ew32(CTRL, reg);
1053
1054 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
1055 udelay(20);
1056 ew32(CTRL, ctrl_reg);
1057 ew32(CTRL_EXT, ctrl_ext);
1058 udelay(20);
1059
1060out:
1061 return ret_val;
1062}
1063
1064/**
Bruce Allanf523d212009-10-29 13:45:45 +00001065 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1066 * @hw: pointer to the HW structure
1067 * @d0_state: boolean if entering d0 or d3 device state
1068 *
1069 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1070 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1071 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1072 **/
1073static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1074{
1075 s32 ret_val = 0;
1076 u32 mac_reg;
1077 u16 oem_reg;
1078
1079 if (hw->mac.type != e1000_pchlan)
1080 return ret_val;
1081
Bruce Allan94d81862009-11-20 23:25:26 +00001082 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001083 if (ret_val)
1084 return ret_val;
1085
1086 mac_reg = er32(EXTCNF_CTRL);
1087 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
1088 goto out;
1089
1090 mac_reg = er32(FEXTNVM);
1091 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
1092 goto out;
1093
1094 mac_reg = er32(PHY_CTRL);
1095
Bruce Allan94d81862009-11-20 23:25:26 +00001096 ret_val = hw->phy.ops.read_reg_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001097 if (ret_val)
1098 goto out;
1099
1100 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1101
1102 if (d0_state) {
1103 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1104 oem_reg |= HV_OEM_BITS_GBE_DIS;
1105
1106 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1107 oem_reg |= HV_OEM_BITS_LPLU;
1108 } else {
1109 if (mac_reg & E1000_PHY_CTRL_NOND0A_GBE_DISABLE)
1110 oem_reg |= HV_OEM_BITS_GBE_DIS;
1111
1112 if (mac_reg & E1000_PHY_CTRL_NOND0A_LPLU)
1113 oem_reg |= HV_OEM_BITS_LPLU;
1114 }
1115 /* Restart auto-neg to activate the bits */
Bruce Allan818f3332009-11-19 14:17:30 +00001116 if (!e1000_check_reset_block(hw))
1117 oem_reg |= HV_OEM_BITS_RESTART_AN;
Bruce Allan94d81862009-11-20 23:25:26 +00001118 ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001119
1120out:
Bruce Allan94d81862009-11-20 23:25:26 +00001121 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001122
1123 return ret_val;
1124}
1125
1126
1127/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001128 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1129 * @hw: pointer to the HW structure
1130 **/
1131static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1132{
1133 s32 ret_val;
1134 u16 data;
1135
1136 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1137 if (ret_val)
1138 return ret_val;
1139
1140 data |= HV_KMRN_MDIO_SLOW;
1141
1142 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1143
1144 return ret_val;
1145}
1146
1147/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001148 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1149 * done after every PHY reset.
1150 **/
1151static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1152{
1153 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001154 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001155
1156 if (hw->mac.type != e1000_pchlan)
1157 return ret_val;
1158
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001159 /* Set MDIO slow mode before any other MDIO access */
1160 if (hw->phy.type == e1000_phy_82577) {
1161 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1162 if (ret_val)
1163 goto out;
1164 }
1165
Bruce Allana4f58f52009-06-02 11:29:18 +00001166 if (((hw->phy.type == e1000_phy_82577) &&
1167 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1168 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1169 /* Disable generation of early preamble */
1170 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1171 if (ret_val)
1172 return ret_val;
1173
1174 /* Preamble tuning for SSC */
1175 ret_val = e1e_wphy(hw, PHY_REG(770, 16), 0xA204);
1176 if (ret_val)
1177 return ret_val;
1178 }
1179
1180 if (hw->phy.type == e1000_phy_82578) {
1181 /*
1182 * Return registers to default by doing a soft reset then
1183 * writing 0x3140 to the control register.
1184 */
1185 if (hw->phy.revision < 2) {
1186 e1000e_phy_sw_reset(hw);
1187 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1188 }
1189 }
1190
1191 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001192 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001193 if (ret_val)
1194 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001195
Bruce Allana4f58f52009-06-02 11:29:18 +00001196 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001197 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001198 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001199 if (ret_val)
1200 goto out;
Bruce Allana4f58f52009-06-02 11:29:18 +00001201
Bruce Allan1d5846b2009-10-29 13:46:05 +00001202 /*
1203 * Configure the K1 Si workaround during phy reset assuming there is
1204 * link so that it disables K1 if link is in 1Gbps.
1205 */
1206 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001207 if (ret_val)
1208 goto out;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001209
Bruce Allanbaf86c92010-01-13 01:53:08 +00001210 /* Workaround for link disconnects on a busy hub in half duplex */
1211 ret_val = hw->phy.ops.acquire(hw);
1212 if (ret_val)
1213 goto out;
1214 ret_val = hw->phy.ops.read_reg_locked(hw,
1215 PHY_REG(BM_PORT_CTRL_PAGE, 17),
1216 &phy_data);
1217 if (ret_val)
1218 goto release;
1219 ret_val = hw->phy.ops.write_reg_locked(hw,
1220 PHY_REG(BM_PORT_CTRL_PAGE, 17),
1221 phy_data & 0x00FF);
1222release:
1223 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001224out:
Bruce Allana4f58f52009-06-02 11:29:18 +00001225 return ret_val;
1226}
1227
1228/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00001229 * e1000_lan_init_done_ich8lan - Check for PHY config completion
1230 * @hw: pointer to the HW structure
1231 *
1232 * Check the appropriate indication the MAC has finished configuring the
1233 * PHY after a software reset.
1234 **/
1235static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
1236{
1237 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
1238
1239 /* Wait for basic configuration completes before proceeding */
1240 do {
1241 data = er32(STATUS);
1242 data &= E1000_STATUS_LAN_INIT_DONE;
1243 udelay(100);
1244 } while ((!data) && --loop);
1245
1246 /*
1247 * If basic configuration is incomplete before the above loop
1248 * count reaches 0, loading the configuration from NVM will
1249 * leave the PHY in a bad state possibly resulting in no link.
1250 */
1251 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001252 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00001253
1254 /* Clear the Init Done bit for the next init event */
1255 data = er32(STATUS);
1256 data &= ~E1000_STATUS_LAN_INIT_DONE;
1257 ew32(STATUS, data);
1258}
1259
1260/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001261 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
1262 * @hw: pointer to the HW structure
1263 *
1264 * Resets the PHY
1265 * This is a function pointer entry point called by drivers
1266 * or other shared routines.
1267 **/
1268static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
1269{
Bruce Allanf523d212009-10-29 13:45:45 +00001270 s32 ret_val = 0;
1271 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001272
1273 ret_val = e1000e_phy_hw_reset_generic(hw);
1274 if (ret_val)
1275 return ret_val;
1276
Bruce Allanfc0c7762009-07-01 13:27:55 +00001277 /* Allow time for h/w to get to a quiescent state after reset */
1278 mdelay(10);
1279
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001280 /* Perform any necessary post-reset workarounds */
Bruce Allana4f58f52009-06-02 11:29:18 +00001281 if (hw->mac.type == e1000_pchlan) {
1282 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
1283 if (ret_val)
1284 return ret_val;
1285 }
1286
Bruce Allandb2932e2009-10-26 11:22:47 +00001287 /* Dummy read to clear the phy wakeup bit after lcd reset */
1288 if (hw->mac.type == e1000_pchlan)
1289 e1e_rphy(hw, BM_WUC, &reg);
1290
Bruce Allanf523d212009-10-29 13:45:45 +00001291 /* Configure the LCD with the extended configuration region in NVM */
1292 ret_val = e1000_sw_lcd_config_ich8lan(hw);
1293 if (ret_val)
1294 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001295
Bruce Allanf523d212009-10-29 13:45:45 +00001296 /* Configure the LCD with the OEM bits in NVM */
1297 if (hw->mac.type == e1000_pchlan)
1298 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001299
Bruce Allanf523d212009-10-29 13:45:45 +00001300out:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001301 return 0;
1302}
1303
1304/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00001305 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1306 * @hw: pointer to the HW structure
1307 * @active: true to enable LPLU, false to disable
1308 *
1309 * Sets the LPLU state according to the active flag. For PCH, if OEM write
1310 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1311 * the phy speed. This function will manually set the LPLU bit and restart
1312 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
1313 * since it configures the same bit.
1314 **/
1315static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1316{
1317 s32 ret_val = 0;
1318 u16 oem_reg;
1319
1320 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
1321 if (ret_val)
1322 goto out;
1323
1324 if (active)
1325 oem_reg |= HV_OEM_BITS_LPLU;
1326 else
1327 oem_reg &= ~HV_OEM_BITS_LPLU;
1328
1329 oem_reg |= HV_OEM_BITS_RESTART_AN;
1330 ret_val = e1e_wphy(hw, HV_OEM_BITS, oem_reg);
1331
1332out:
1333 return ret_val;
1334}
1335
1336/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001337 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1338 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001339 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001340 *
1341 * Sets the LPLU D0 state according to the active flag. When
1342 * activating LPLU this function also disables smart speed
1343 * and vice versa. LPLU will not be activated unless the
1344 * device autonegotiation advertisement meets standards of
1345 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1346 * This is a function pointer entry point only called by
1347 * PHY setup routines.
1348 **/
1349static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1350{
1351 struct e1000_phy_info *phy = &hw->phy;
1352 u32 phy_ctrl;
1353 s32 ret_val = 0;
1354 u16 data;
1355
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001356 if (phy->type == e1000_phy_ife)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001357 return ret_val;
1358
1359 phy_ctrl = er32(PHY_CTRL);
1360
1361 if (active) {
1362 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
1363 ew32(PHY_CTRL, phy_ctrl);
1364
Bruce Allan60f12922009-07-01 13:28:14 +00001365 if (phy->type != e1000_phy_igp_3)
1366 return 0;
1367
Bruce Allanad680762008-03-28 09:15:03 -07001368 /*
1369 * Call gig speed drop workaround on LPLU before accessing
1370 * any PHY registers
1371 */
Bruce Allan60f12922009-07-01 13:28:14 +00001372 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001373 e1000e_gig_downshift_workaround_ich8lan(hw);
1374
1375 /* When LPLU is enabled, we should disable SmartSpeed */
1376 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1377 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1378 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1379 if (ret_val)
1380 return ret_val;
1381 } else {
1382 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
1383 ew32(PHY_CTRL, phy_ctrl);
1384
Bruce Allan60f12922009-07-01 13:28:14 +00001385 if (phy->type != e1000_phy_igp_3)
1386 return 0;
1387
Bruce Allanad680762008-03-28 09:15:03 -07001388 /*
1389 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001390 * during Dx states where the power conservation is most
1391 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001392 * SmartSpeed, so performance is maintained.
1393 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001394 if (phy->smart_speed == e1000_smart_speed_on) {
1395 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001396 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001397 if (ret_val)
1398 return ret_val;
1399
1400 data |= IGP01E1000_PSCFR_SMART_SPEED;
1401 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001402 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001403 if (ret_val)
1404 return ret_val;
1405 } else if (phy->smart_speed == e1000_smart_speed_off) {
1406 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001407 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001408 if (ret_val)
1409 return ret_val;
1410
1411 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1412 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001413 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001414 if (ret_val)
1415 return ret_val;
1416 }
1417 }
1418
1419 return 0;
1420}
1421
1422/**
1423 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
1424 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001425 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001426 *
1427 * Sets the LPLU D3 state according to the active flag. When
1428 * activating LPLU this function also disables smart speed
1429 * and vice versa. LPLU will not be activated unless the
1430 * device autonegotiation advertisement meets standards of
1431 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1432 * This is a function pointer entry point only called by
1433 * PHY setup routines.
1434 **/
1435static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1436{
1437 struct e1000_phy_info *phy = &hw->phy;
1438 u32 phy_ctrl;
1439 s32 ret_val;
1440 u16 data;
1441
1442 phy_ctrl = er32(PHY_CTRL);
1443
1444 if (!active) {
1445 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
1446 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00001447
1448 if (phy->type != e1000_phy_igp_3)
1449 return 0;
1450
Bruce Allanad680762008-03-28 09:15:03 -07001451 /*
1452 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001453 * during Dx states where the power conservation is most
1454 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001455 * SmartSpeed, so performance is maintained.
1456 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001457 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07001458 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1459 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001460 if (ret_val)
1461 return ret_val;
1462
1463 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001464 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1465 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001466 if (ret_val)
1467 return ret_val;
1468 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07001469 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1470 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001471 if (ret_val)
1472 return ret_val;
1473
1474 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001475 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1476 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001477 if (ret_val)
1478 return ret_val;
1479 }
1480 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1481 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1482 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1483 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
1484 ew32(PHY_CTRL, phy_ctrl);
1485
Bruce Allan60f12922009-07-01 13:28:14 +00001486 if (phy->type != e1000_phy_igp_3)
1487 return 0;
1488
Bruce Allanad680762008-03-28 09:15:03 -07001489 /*
1490 * Call gig speed drop workaround on LPLU before accessing
1491 * any PHY registers
1492 */
Bruce Allan60f12922009-07-01 13:28:14 +00001493 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001494 e1000e_gig_downshift_workaround_ich8lan(hw);
1495
1496 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07001497 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001498 if (ret_val)
1499 return ret_val;
1500
1501 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001502 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001503 }
1504
1505 return 0;
1506}
1507
1508/**
Bruce Allanf4187b52008-08-26 18:36:50 -07001509 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
1510 * @hw: pointer to the HW structure
1511 * @bank: pointer to the variable that returns the active bank
1512 *
1513 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08001514 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07001515 **/
1516static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
1517{
Bruce Allane2434552008-11-21 17:02:41 -08001518 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07001519 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07001520 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
1521 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08001522 u8 sig_byte = 0;
1523 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001524
Bruce Allane2434552008-11-21 17:02:41 -08001525 switch (hw->mac.type) {
1526 case e1000_ich8lan:
1527 case e1000_ich9lan:
1528 eecd = er32(EECD);
1529 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
1530 E1000_EECD_SEC1VAL_VALID_MASK) {
1531 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07001532 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08001533 else
1534 *bank = 0;
1535
1536 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001537 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001538 e_dbg("Unable to determine valid NVM bank via EEC - "
Bruce Allane2434552008-11-21 17:02:41 -08001539 "reading flash signature\n");
1540 /* fall-thru */
1541 default:
1542 /* set bank to 0 in case flash read fails */
1543 *bank = 0;
1544
1545 /* Check bank 0 */
1546 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
1547 &sig_byte);
1548 if (ret_val)
1549 return ret_val;
1550 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1551 E1000_ICH_NVM_SIG_VALUE) {
1552 *bank = 0;
1553 return 0;
1554 }
1555
1556 /* Check bank 1 */
1557 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
1558 bank1_offset,
1559 &sig_byte);
1560 if (ret_val)
1561 return ret_val;
1562 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1563 E1000_ICH_NVM_SIG_VALUE) {
1564 *bank = 1;
1565 return 0;
1566 }
1567
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001568 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08001569 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07001570 }
1571
1572 return 0;
1573}
1574
1575/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
1577 * @hw: pointer to the HW structure
1578 * @offset: The offset (in bytes) of the word(s) to read.
1579 * @words: Size of data to read in words
1580 * @data: Pointer to the word(s) to read at offset.
1581 *
1582 * Reads a word(s) from the NVM using the flash access registers.
1583 **/
1584static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1585 u16 *data)
1586{
1587 struct e1000_nvm_info *nvm = &hw->nvm;
1588 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1589 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00001590 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001591 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 u16 i, word;
1593
1594 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1595 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001596 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00001597 ret_val = -E1000_ERR_NVM;
1598 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001599 }
1600
Bruce Allan94d81862009-11-20 23:25:26 +00001601 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602
Bruce Allanf4187b52008-08-26 18:36:50 -07001603 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00001604 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001605 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00001606 bank = 0;
1607 }
Bruce Allanf4187b52008-08-26 18:36:50 -07001608
1609 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001610 act_offset += offset;
1611
Bruce Allan148675a2009-08-07 07:41:56 +00001612 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001613 for (i = 0; i < words; i++) {
1614 if ((dev_spec->shadow_ram) &&
1615 (dev_spec->shadow_ram[offset+i].modified)) {
1616 data[i] = dev_spec->shadow_ram[offset+i].value;
1617 } else {
1618 ret_val = e1000_read_flash_word_ich8lan(hw,
1619 act_offset + i,
1620 &word);
1621 if (ret_val)
1622 break;
1623 data[i] = word;
1624 }
1625 }
1626
Bruce Allan94d81862009-11-20 23:25:26 +00001627 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001628
Bruce Allane2434552008-11-21 17:02:41 -08001629out:
1630 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001631 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08001632
Auke Kokbc7f75f2007-09-17 12:30:59 -07001633 return ret_val;
1634}
1635
1636/**
1637 * e1000_flash_cycle_init_ich8lan - Initialize flash
1638 * @hw: pointer to the HW structure
1639 *
1640 * This function does initial flash setup so that a new read/write/erase cycle
1641 * can be started.
1642 **/
1643static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
1644{
1645 union ich8_hws_flash_status hsfsts;
1646 s32 ret_val = -E1000_ERR_NVM;
1647 s32 i = 0;
1648
1649 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1650
1651 /* Check if the flash descriptor is valid */
1652 if (hsfsts.hsf_status.fldesvalid == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001653 e_dbg("Flash descriptor invalid. "
Joe Perches2c73e1f2010-03-26 20:16:59 +00001654 "SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001655 return -E1000_ERR_NVM;
1656 }
1657
1658 /* Clear FCERR and DAEL in hw status by writing 1 */
1659 hsfsts.hsf_status.flcerr = 1;
1660 hsfsts.hsf_status.dael = 1;
1661
1662 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1663
Bruce Allanad680762008-03-28 09:15:03 -07001664 /*
1665 * Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666 * bit to check against, in order to start a new cycle or
1667 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08001668 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07001669 * indication whether a cycle is in progress or has been
1670 * completed.
1671 */
1672
1673 if (hsfsts.hsf_status.flcinprog == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07001674 /*
1675 * There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00001676 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07001677 * Begin by setting Flash Cycle Done.
1678 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001679 hsfsts.hsf_status.flcdone = 1;
1680 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1681 ret_val = 0;
1682 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001683 /*
Bruce Allan5ff5b662009-12-01 15:51:11 +00001684 * Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07001685 * cycle has a chance to end before giving up.
1686 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
1688 hsfsts.regval = __er16flash(hw, ICH_FLASH_HSFSTS);
1689 if (hsfsts.hsf_status.flcinprog == 0) {
1690 ret_val = 0;
1691 break;
1692 }
1693 udelay(1);
1694 }
1695 if (ret_val == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07001696 /*
1697 * Successful in waiting for previous cycle to timeout,
1698 * now set the Flash Cycle Done.
1699 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700 hsfsts.hsf_status.flcdone = 1;
1701 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1702 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00001703 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001704 }
1705 }
1706
1707 return ret_val;
1708}
1709
1710/**
1711 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
1712 * @hw: pointer to the HW structure
1713 * @timeout: maximum time to wait for completion
1714 *
1715 * This function starts a flash cycle and waits for its completion.
1716 **/
1717static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
1718{
1719 union ich8_hws_flash_ctrl hsflctl;
1720 union ich8_hws_flash_status hsfsts;
1721 s32 ret_val = -E1000_ERR_NVM;
1722 u32 i = 0;
1723
1724 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
1725 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1726 hsflctl.hsf_ctrl.flcgo = 1;
1727 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1728
1729 /* wait till FDONE bit is set to 1 */
1730 do {
1731 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1732 if (hsfsts.hsf_status.flcdone == 1)
1733 break;
1734 udelay(1);
1735 } while (i++ < timeout);
1736
1737 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
1738 return 0;
1739
1740 return ret_val;
1741}
1742
1743/**
1744 * e1000_read_flash_word_ich8lan - Read word from flash
1745 * @hw: pointer to the HW structure
1746 * @offset: offset to data location
1747 * @data: pointer to the location for storing the data
1748 *
1749 * Reads the flash word at offset into data. Offset is converted
1750 * to bytes before read.
1751 **/
1752static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
1753 u16 *data)
1754{
1755 /* Must convert offset into bytes. */
1756 offset <<= 1;
1757
1758 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
1759}
1760
1761/**
Bruce Allanf4187b52008-08-26 18:36:50 -07001762 * e1000_read_flash_byte_ich8lan - Read byte from flash
1763 * @hw: pointer to the HW structure
1764 * @offset: The offset of the byte to read.
1765 * @data: Pointer to a byte to store the value read.
1766 *
1767 * Reads a single byte from the NVM using the flash access registers.
1768 **/
1769static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1770 u8 *data)
1771{
1772 s32 ret_val;
1773 u16 word = 0;
1774
1775 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
1776 if (ret_val)
1777 return ret_val;
1778
1779 *data = (u8)word;
1780
1781 return 0;
1782}
1783
1784/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001785 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
1786 * @hw: pointer to the HW structure
1787 * @offset: The offset (in bytes) of the byte or word to read.
1788 * @size: Size of data to read, 1=byte 2=word
1789 * @data: Pointer to the word to store the value read.
1790 *
1791 * Reads a byte or word from the NVM using the flash access registers.
1792 **/
1793static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1794 u8 size, u16 *data)
1795{
1796 union ich8_hws_flash_status hsfsts;
1797 union ich8_hws_flash_ctrl hsflctl;
1798 u32 flash_linear_addr;
1799 u32 flash_data = 0;
1800 s32 ret_val = -E1000_ERR_NVM;
1801 u8 count = 0;
1802
1803 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
1804 return -E1000_ERR_NVM;
1805
1806 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1807 hw->nvm.flash_base_addr;
1808
1809 do {
1810 udelay(1);
1811 /* Steps */
1812 ret_val = e1000_flash_cycle_init_ich8lan(hw);
1813 if (ret_val != 0)
1814 break;
1815
1816 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
1817 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1818 hsflctl.hsf_ctrl.fldbcount = size - 1;
1819 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
1820 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
1821
1822 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
1823
1824 ret_val = e1000_flash_cycle_ich8lan(hw,
1825 ICH_FLASH_READ_COMMAND_TIMEOUT);
1826
Bruce Allanad680762008-03-28 09:15:03 -07001827 /*
1828 * Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07001829 * and try the whole sequence a few more times, else
1830 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07001831 * least significant byte first msb to lsb
1832 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001833 if (ret_val == 0) {
1834 flash_data = er32flash(ICH_FLASH_FDATA0);
1835 if (size == 1) {
1836 *data = (u8)(flash_data & 0x000000FF);
1837 } else if (size == 2) {
1838 *data = (u16)(flash_data & 0x0000FFFF);
1839 }
1840 break;
1841 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001842 /*
1843 * If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07001844 * completely hosed, but if the error condition is
1845 * detected, it won't hurt to give it another try...
1846 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
1847 */
1848 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1849 if (hsfsts.hsf_status.flcerr == 1) {
1850 /* Repeat for some time before giving up. */
1851 continue;
1852 } else if (hsfsts.hsf_status.flcdone == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001853 e_dbg("Timeout error - flash cycle "
Joe Perches2c73e1f2010-03-26 20:16:59 +00001854 "did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001855 break;
1856 }
1857 }
1858 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1859
1860 return ret_val;
1861}
1862
1863/**
1864 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
1865 * @hw: pointer to the HW structure
1866 * @offset: The offset (in bytes) of the word(s) to write.
1867 * @words: Size of data to write in words
1868 * @data: Pointer to the word(s) to write at offset.
1869 *
1870 * Writes a byte or word to the NVM using the flash access registers.
1871 **/
1872static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1873 u16 *data)
1874{
1875 struct e1000_nvm_info *nvm = &hw->nvm;
1876 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001877 u16 i;
1878
1879 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1880 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001881 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001882 return -E1000_ERR_NVM;
1883 }
1884
Bruce Allan94d81862009-11-20 23:25:26 +00001885 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00001886
Auke Kokbc7f75f2007-09-17 12:30:59 -07001887 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00001888 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001889 dev_spec->shadow_ram[offset+i].value = data[i];
1890 }
1891
Bruce Allan94d81862009-11-20 23:25:26 +00001892 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00001893
Auke Kokbc7f75f2007-09-17 12:30:59 -07001894 return 0;
1895}
1896
1897/**
1898 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
1899 * @hw: pointer to the HW structure
1900 *
1901 * The NVM checksum is updated by calling the generic update_nvm_checksum,
1902 * which writes the checksum to the shadow ram. The changes in the shadow
1903 * ram are then committed to the EEPROM by processing each bank at a time
1904 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08001905 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07001906 * future writes.
1907 **/
1908static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
1909{
1910 struct e1000_nvm_info *nvm = &hw->nvm;
1911 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07001912 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001913 s32 ret_val;
1914 u16 data;
1915
1916 ret_val = e1000e_update_nvm_checksum_generic(hw);
1917 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08001918 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001919
1920 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08001921 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001922
Bruce Allan94d81862009-11-20 23:25:26 +00001923 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001924
Bruce Allanad680762008-03-28 09:15:03 -07001925 /*
1926 * We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001927 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07001928 * is going to be written
1929 */
Bruce Allanf4187b52008-08-26 18:36:50 -07001930 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08001931 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001932 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00001933 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08001934 }
Bruce Allanf4187b52008-08-26 18:36:50 -07001935
1936 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001937 new_bank_offset = nvm->flash_bank_size;
1938 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08001939 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00001940 if (ret_val)
1941 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001942 } else {
1943 old_bank_offset = nvm->flash_bank_size;
1944 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08001945 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00001946 if (ret_val)
1947 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001948 }
1949
1950 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allanad680762008-03-28 09:15:03 -07001951 /*
1952 * Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07001954 * in the shadow RAM
1955 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956 if (dev_spec->shadow_ram[i].modified) {
1957 data = dev_spec->shadow_ram[i].value;
1958 } else {
Bruce Allane2434552008-11-21 17:02:41 -08001959 ret_val = e1000_read_flash_word_ich8lan(hw, i +
1960 old_bank_offset,
1961 &data);
1962 if (ret_val)
1963 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001964 }
1965
Bruce Allanad680762008-03-28 09:15:03 -07001966 /*
1967 * If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07001968 * (15:14) are 11b until the commit has completed.
1969 * This will allow us to write 10b which indicates the
1970 * signature is valid. We want to do this after the write
1971 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07001972 * while the write is still in progress
1973 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001974 if (i == E1000_ICH_NVM_SIG_WORD)
1975 data |= E1000_ICH_NVM_SIG_MASK;
1976
1977 /* Convert offset to bytes. */
1978 act_offset = (i + new_bank_offset) << 1;
1979
1980 udelay(100);
1981 /* Write the bytes to the new bank. */
1982 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1983 act_offset,
1984 (u8)data);
1985 if (ret_val)
1986 break;
1987
1988 udelay(100);
1989 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
1990 act_offset + 1,
1991 (u8)(data >> 8));
1992 if (ret_val)
1993 break;
1994 }
1995
Bruce Allanad680762008-03-28 09:15:03 -07001996 /*
1997 * Don't bother writing the segment valid bits if sector
1998 * programming failed.
1999 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002000 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002001 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002002 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002003 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002004 }
2005
Bruce Allanad680762008-03-28 09:15:03 -07002006 /*
2007 * Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002008 * to 10b in word 0x13 , this can be done without an
2009 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002010 * and we need to change bit 14 to 0b
2011 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002012 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002013 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002014 if (ret_val)
2015 goto release;
2016
Auke Kokbc7f75f2007-09-17 12:30:59 -07002017 data &= 0xBFFF;
2018 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2019 act_offset * 2 + 1,
2020 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002021 if (ret_val)
2022 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002023
Bruce Allanad680762008-03-28 09:15:03 -07002024 /*
2025 * And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002026 * its signature word (0x13) high_byte to 0b. This can be
2027 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002028 * to 1's. We can write 1's to 0's without an erase
2029 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002030 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2031 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002032 if (ret_val)
2033 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002034
2035 /* Great! Everything worked, we can now clear the cached entries. */
2036 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002037 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002038 dev_spec->shadow_ram[i].value = 0xFFFF;
2039 }
2040
Bruce Allan9c5e2092010-05-10 15:00:31 +00002041release:
Bruce Allan94d81862009-11-20 23:25:26 +00002042 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002043
Bruce Allanad680762008-03-28 09:15:03 -07002044 /*
2045 * Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002046 * until after the next adapter reset.
2047 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002048 if (!ret_val) {
2049 e1000e_reload_nvm(hw);
2050 msleep(10);
2051 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002052
Bruce Allane2434552008-11-21 17:02:41 -08002053out:
2054 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002055 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002056
Auke Kokbc7f75f2007-09-17 12:30:59 -07002057 return ret_val;
2058}
2059
2060/**
2061 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2062 * @hw: pointer to the HW structure
2063 *
2064 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2065 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
2066 * calculated, in which case we need to calculate the checksum and set bit 6.
2067 **/
2068static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2069{
2070 s32 ret_val;
2071 u16 data;
2072
Bruce Allanad680762008-03-28 09:15:03 -07002073 /*
2074 * Read 0x19 and check bit 6. If this bit is 0, the checksum
Auke Kokbc7f75f2007-09-17 12:30:59 -07002075 * needs to be fixed. This bit is an indication that the NVM
2076 * was prepared by OEM software and did not calculate the
2077 * checksum...a likely scenario.
2078 */
2079 ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
2080 if (ret_val)
2081 return ret_val;
2082
2083 if ((data & 0x40) == 0) {
2084 data |= 0x40;
2085 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
2086 if (ret_val)
2087 return ret_val;
2088 ret_val = e1000e_update_nvm_checksum(hw);
2089 if (ret_val)
2090 return ret_val;
2091 }
2092
2093 return e1000e_validate_nvm_checksum_generic(hw);
2094}
2095
2096/**
Bruce Allan4a770352008-10-01 17:18:35 -07002097 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
2098 * @hw: pointer to the HW structure
2099 *
2100 * To prevent malicious write/erase of the NVM, set it to be read-only
2101 * so that the hardware ignores all write/erase cycles of the NVM via
2102 * the flash control registers. The shadow-ram copy of the NVM will
2103 * still be updated, however any updates to this copy will not stick
2104 * across driver reloads.
2105 **/
2106void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
2107{
Bruce Allanca15df52009-10-26 11:23:43 +00002108 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07002109 union ich8_flash_protected_range pr0;
2110 union ich8_hws_flash_status hsfsts;
2111 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07002112
Bruce Allan94d81862009-11-20 23:25:26 +00002113 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002114
2115 gfpreg = er32flash(ICH_FLASH_GFPREG);
2116
2117 /* Write-protect GbE Sector of NVM */
2118 pr0.regval = er32flash(ICH_FLASH_PR0);
2119 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
2120 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
2121 pr0.range.wpe = true;
2122 ew32flash(ICH_FLASH_PR0, pr0.regval);
2123
2124 /*
2125 * Lock down a subset of GbE Flash Control Registers, e.g.
2126 * PR0 to prevent the write-protection from being lifted.
2127 * Once FLOCKDN is set, the registers protected by it cannot
2128 * be written until FLOCKDN is cleared by a hardware reset.
2129 */
2130 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2131 hsfsts.hsf_status.flockdn = true;
2132 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2133
Bruce Allan94d81862009-11-20 23:25:26 +00002134 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002135}
2136
2137/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002138 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
2139 * @hw: pointer to the HW structure
2140 * @offset: The offset (in bytes) of the byte/word to read.
2141 * @size: Size of data to read, 1=byte 2=word
2142 * @data: The byte(s) to write to the NVM.
2143 *
2144 * Writes one/two bytes to the NVM using the flash access registers.
2145 **/
2146static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2147 u8 size, u16 data)
2148{
2149 union ich8_hws_flash_status hsfsts;
2150 union ich8_hws_flash_ctrl hsflctl;
2151 u32 flash_linear_addr;
2152 u32 flash_data = 0;
2153 s32 ret_val;
2154 u8 count = 0;
2155
2156 if (size < 1 || size > 2 || data > size * 0xff ||
2157 offset > ICH_FLASH_LINEAR_ADDR_MASK)
2158 return -E1000_ERR_NVM;
2159
2160 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2161 hw->nvm.flash_base_addr;
2162
2163 do {
2164 udelay(1);
2165 /* Steps */
2166 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2167 if (ret_val)
2168 break;
2169
2170 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2171 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2172 hsflctl.hsf_ctrl.fldbcount = size -1;
2173 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
2174 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2175
2176 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2177
2178 if (size == 1)
2179 flash_data = (u32)data & 0x00FF;
2180 else
2181 flash_data = (u32)data;
2182
2183 ew32flash(ICH_FLASH_FDATA0, flash_data);
2184
Bruce Allanad680762008-03-28 09:15:03 -07002185 /*
2186 * check if FCERR is set to 1 , if set to 1, clear it
2187 * and try the whole sequence a few more times else done
2188 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002189 ret_val = e1000_flash_cycle_ich8lan(hw,
2190 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
2191 if (!ret_val)
2192 break;
2193
Bruce Allanad680762008-03-28 09:15:03 -07002194 /*
2195 * If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07002196 * completely hosed, but if the error condition
2197 * is detected, it won't hurt to give it another
2198 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
2199 */
2200 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2201 if (hsfsts.hsf_status.flcerr == 1)
2202 /* Repeat for some time before giving up. */
2203 continue;
2204 if (hsfsts.hsf_status.flcdone == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002205 e_dbg("Timeout error - flash cycle "
Auke Kokbc7f75f2007-09-17 12:30:59 -07002206 "did not complete.");
2207 break;
2208 }
2209 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2210
2211 return ret_val;
2212}
2213
2214/**
2215 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
2216 * @hw: pointer to the HW structure
2217 * @offset: The index of the byte to read.
2218 * @data: The byte to write to the NVM.
2219 *
2220 * Writes a single byte to the NVM using the flash access registers.
2221 **/
2222static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2223 u8 data)
2224{
2225 u16 word = (u16)data;
2226
2227 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
2228}
2229
2230/**
2231 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
2232 * @hw: pointer to the HW structure
2233 * @offset: The offset of the byte to write.
2234 * @byte: The byte to write to the NVM.
2235 *
2236 * Writes a single byte to the NVM using the flash access registers.
2237 * Goes through a retry algorithm before giving up.
2238 **/
2239static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
2240 u32 offset, u8 byte)
2241{
2242 s32 ret_val;
2243 u16 program_retries;
2244
2245 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2246 if (!ret_val)
2247 return ret_val;
2248
2249 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002250 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 udelay(100);
2252 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2253 if (!ret_val)
2254 break;
2255 }
2256 if (program_retries == 100)
2257 return -E1000_ERR_NVM;
2258
2259 return 0;
2260}
2261
2262/**
2263 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
2264 * @hw: pointer to the HW structure
2265 * @bank: 0 for first bank, 1 for second bank, etc.
2266 *
2267 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
2268 * bank N is 4096 * N + flash_reg_addr.
2269 **/
2270static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
2271{
2272 struct e1000_nvm_info *nvm = &hw->nvm;
2273 union ich8_hws_flash_status hsfsts;
2274 union ich8_hws_flash_ctrl hsflctl;
2275 u32 flash_linear_addr;
2276 /* bank size is in 16bit words - adjust to bytes */
2277 u32 flash_bank_size = nvm->flash_bank_size * 2;
2278 s32 ret_val;
2279 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00002280 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002281
2282 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2283
Bruce Allanad680762008-03-28 09:15:03 -07002284 /*
2285 * Determine HW Sector size: Read BERASE bits of hw flash status
2286 * register
2287 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288 * consecutive sectors. The start index for the nth Hw sector
2289 * can be calculated as = bank * 4096 + n * 256
2290 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
2291 * The start index for the nth Hw sector can be calculated
2292 * as = bank * 4096
2293 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
2294 * (ich9 only, otherwise error condition)
2295 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
2296 */
2297 switch (hsfsts.hsf_status.berasesz) {
2298 case 0:
2299 /* Hw sector size 256 */
2300 sector_size = ICH_FLASH_SEG_SIZE_256;
2301 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
2302 break;
2303 case 1:
2304 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00002305 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002306 break;
2307 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00002308 sector_size = ICH_FLASH_SEG_SIZE_8K;
2309 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002310 break;
2311 case 3:
2312 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00002313 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002314 break;
2315 default:
2316 return -E1000_ERR_NVM;
2317 }
2318
2319 /* Start with the base address, then add the sector offset. */
2320 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00002321 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322
2323 for (j = 0; j < iteration ; j++) {
2324 do {
2325 /* Steps */
2326 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2327 if (ret_val)
2328 return ret_val;
2329
Bruce Allanad680762008-03-28 09:15:03 -07002330 /*
2331 * Write a value 11 (block Erase) in Flash
2332 * Cycle field in hw flash control
2333 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2335 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
2336 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2337
Bruce Allanad680762008-03-28 09:15:03 -07002338 /*
2339 * Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07002340 * block into Flash Linear address field in Flash
2341 * Address.
2342 */
2343 flash_linear_addr += (j * sector_size);
2344 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2345
2346 ret_val = e1000_flash_cycle_ich8lan(hw,
2347 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
2348 if (ret_val == 0)
2349 break;
2350
Bruce Allanad680762008-03-28 09:15:03 -07002351 /*
2352 * Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002353 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07002354 * a few more times else Done
2355 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2357 if (hsfsts.hsf_status.flcerr == 1)
Bruce Allanad680762008-03-28 09:15:03 -07002358 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359 continue;
2360 else if (hsfsts.hsf_status.flcdone == 0)
2361 return ret_val;
2362 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
2363 }
2364
2365 return 0;
2366}
2367
2368/**
2369 * e1000_valid_led_default_ich8lan - Set the default LED settings
2370 * @hw: pointer to the HW structure
2371 * @data: Pointer to the LED settings
2372 *
2373 * Reads the LED default settings from the NVM to data. If the NVM LED
2374 * settings is all 0's or F's, set the LED default to a valid LED default
2375 * setting.
2376 **/
2377static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
2378{
2379 s32 ret_val;
2380
2381 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
2382 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002383 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384 return ret_val;
2385 }
2386
2387 if (*data == ID_LED_RESERVED_0000 ||
2388 *data == ID_LED_RESERVED_FFFF)
2389 *data = ID_LED_DEFAULT_ICH8LAN;
2390
2391 return 0;
2392}
2393
2394/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002395 * e1000_id_led_init_pchlan - store LED configurations
2396 * @hw: pointer to the HW structure
2397 *
2398 * PCH does not control LEDs via the LEDCTL register, rather it uses
2399 * the PHY LED configuration register.
2400 *
2401 * PCH also does not have an "always on" or "always off" mode which
2402 * complicates the ID feature. Instead of using the "on" mode to indicate
2403 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init()),
2404 * use "link_up" mode. The LEDs will still ID on request if there is no
2405 * link based on logic in e1000_led_[on|off]_pchlan().
2406 **/
2407static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
2408{
2409 struct e1000_mac_info *mac = &hw->mac;
2410 s32 ret_val;
2411 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
2412 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
2413 u16 data, i, temp, shift;
2414
2415 /* Get default ID LED modes */
2416 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
2417 if (ret_val)
2418 goto out;
2419
2420 mac->ledctl_default = er32(LEDCTL);
2421 mac->ledctl_mode1 = mac->ledctl_default;
2422 mac->ledctl_mode2 = mac->ledctl_default;
2423
2424 for (i = 0; i < 4; i++) {
2425 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
2426 shift = (i * 5);
2427 switch (temp) {
2428 case ID_LED_ON1_DEF2:
2429 case ID_LED_ON1_ON2:
2430 case ID_LED_ON1_OFF2:
2431 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2432 mac->ledctl_mode1 |= (ledctl_on << shift);
2433 break;
2434 case ID_LED_OFF1_DEF2:
2435 case ID_LED_OFF1_ON2:
2436 case ID_LED_OFF1_OFF2:
2437 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2438 mac->ledctl_mode1 |= (ledctl_off << shift);
2439 break;
2440 default:
2441 /* Do nothing */
2442 break;
2443 }
2444 switch (temp) {
2445 case ID_LED_DEF1_ON2:
2446 case ID_LED_ON1_ON2:
2447 case ID_LED_OFF1_ON2:
2448 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2449 mac->ledctl_mode2 |= (ledctl_on << shift);
2450 break;
2451 case ID_LED_DEF1_OFF2:
2452 case ID_LED_ON1_OFF2:
2453 case ID_LED_OFF1_OFF2:
2454 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2455 mac->ledctl_mode2 |= (ledctl_off << shift);
2456 break;
2457 default:
2458 /* Do nothing */
2459 break;
2460 }
2461 }
2462
2463out:
2464 return ret_val;
2465}
2466
2467/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002468 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
2469 * @hw: pointer to the HW structure
2470 *
2471 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
2472 * register, so the the bus width is hard coded.
2473 **/
2474static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
2475{
2476 struct e1000_bus_info *bus = &hw->bus;
2477 s32 ret_val;
2478
2479 ret_val = e1000e_get_bus_info_pcie(hw);
2480
Bruce Allanad680762008-03-28 09:15:03 -07002481 /*
2482 * ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 * a configuration space, but do not contain
2484 * PCI Express Capability registers, so bus width
2485 * must be hardcoded.
2486 */
2487 if (bus->width == e1000_bus_width_unknown)
2488 bus->width = e1000_bus_width_pcie_x1;
2489
2490 return ret_val;
2491}
2492
2493/**
2494 * e1000_reset_hw_ich8lan - Reset the hardware
2495 * @hw: pointer to the HW structure
2496 *
2497 * Does a full reset of the hardware which includes a reset of the PHY and
2498 * MAC.
2499 **/
2500static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2501{
Bruce Allan1d5846b2009-10-29 13:46:05 +00002502 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allandb2932e2009-10-26 11:22:47 +00002503 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504 u32 ctrl, icr, kab;
2505 s32 ret_val;
2506
Bruce Allanad680762008-03-28 09:15:03 -07002507 /*
2508 * Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 * on the last TLP read/write transaction when MAC is reset.
2510 */
2511 ret_val = e1000e_disable_pcie_master(hw);
2512 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002513 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002514 }
2515
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002516 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517 ew32(IMC, 0xffffffff);
2518
Bruce Allanad680762008-03-28 09:15:03 -07002519 /*
2520 * Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 * any pending transactions to complete before we hit the MAC
2522 * with the global reset.
2523 */
2524 ew32(RCTL, 0);
2525 ew32(TCTL, E1000_TCTL_PSP);
2526 e1e_flush();
2527
2528 msleep(10);
2529
2530 /* Workaround for ICH8 bit corruption issue in FIFO memory */
2531 if (hw->mac.type == e1000_ich8lan) {
2532 /* Set Tx and Rx buffer allocation to 8k apiece. */
2533 ew32(PBA, E1000_PBA_8K);
2534 /* Set Packet Buffer Size to 16k. */
2535 ew32(PBS, E1000_PBS_16K);
2536 }
2537
Bruce Allan1d5846b2009-10-29 13:46:05 +00002538 if (hw->mac.type == e1000_pchlan) {
2539 /* Save the NVM K1 bit setting*/
2540 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &reg);
2541 if (ret_val)
2542 return ret_val;
2543
2544 if (reg & E1000_NVM_K1_ENABLE)
2545 dev_spec->nvm_k1_enabled = true;
2546 else
2547 dev_spec->nvm_k1_enabled = false;
2548 }
2549
Auke Kokbc7f75f2007-09-17 12:30:59 -07002550 ctrl = er32(CTRL);
2551
2552 if (!e1000_check_reset_block(hw)) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00002553 /* Clear PHY Reset Asserted bit */
2554 if (hw->mac.type >= e1000_pchlan) {
2555 u32 status = er32(STATUS);
2556 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
2557 }
2558
Bruce Allanad680762008-03-28 09:15:03 -07002559 /*
2560 * PHY HW reset requires MAC CORE reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07002561 * time to make sure the interface between MAC and the
2562 * external PHY is reset.
2563 */
2564 ctrl |= E1000_CTRL_PHY_RST;
2565 }
2566 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002567 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002568 ew32(CTRL, (ctrl | E1000_CTRL_RST));
2569 msleep(20);
2570
Bruce Allanfc0c7762009-07-01 13:27:55 +00002571 if (!ret_val)
Jeff Kirsher30bb0e02008-12-11 21:28:11 -08002572 e1000_release_swflag_ich8lan(hw);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07002573
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002574 /* Perform any necessary post-reset workarounds */
2575 if (hw->mac.type == e1000_pchlan)
2576 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2577
Bruce Allanfc0c7762009-07-01 13:27:55 +00002578 if (ctrl & E1000_CTRL_PHY_RST)
2579 ret_val = hw->phy.ops.get_cfg_done(hw);
2580
2581 if (hw->mac.type >= e1000_ich10lan) {
2582 e1000_lan_init_done_ich8lan(hw);
2583 } else {
2584 ret_val = e1000e_get_auto_rd_done(hw);
2585 if (ret_val) {
2586 /*
2587 * When auto config read does not complete, do not
2588 * return with an error. This can happen in situations
2589 * where there is no eeprom and prevents getting link.
2590 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002591 e_dbg("Auto Read Done did not complete\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002592 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002593 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002594 /* Dummy read to clear the phy wakeup bit after lcd reset */
2595 if (hw->mac.type == e1000_pchlan)
2596 e1e_rphy(hw, BM_WUC, &reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002597
Bruce Allanf523d212009-10-29 13:45:45 +00002598 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2599 if (ret_val)
2600 goto out;
2601
2602 if (hw->mac.type == e1000_pchlan) {
2603 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
2604 if (ret_val)
2605 goto out;
2606 }
Bruce Allan7d3cabb2009-07-01 13:29:08 +00002607 /*
2608 * For PCH, this write will make sure that any noise
2609 * will be detected as a CRC error and be dropped rather than show up
2610 * as a bad packet to the DMA engine.
2611 */
2612 if (hw->mac.type == e1000_pchlan)
2613 ew32(CRC_OFFSET, 0x65656565);
2614
Auke Kokbc7f75f2007-09-17 12:30:59 -07002615 ew32(IMC, 0xffffffff);
2616 icr = er32(ICR);
2617
2618 kab = er32(KABGTXD);
2619 kab |= E1000_KABGTXD_BGSQLBIAS;
2620 ew32(KABGTXD, kab);
2621
Bruce Allanf523d212009-10-29 13:45:45 +00002622out:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002623 return ret_val;
2624}
2625
2626/**
2627 * e1000_init_hw_ich8lan - Initialize the hardware
2628 * @hw: pointer to the HW structure
2629 *
2630 * Prepares the hardware for transmit and receive by doing the following:
2631 * - initialize hardware bits
2632 * - initialize LED identification
2633 * - setup receive address registers
2634 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08002635 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07002636 * - clear statistics
2637 **/
2638static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
2639{
2640 struct e1000_mac_info *mac = &hw->mac;
2641 u32 ctrl_ext, txdctl, snoop;
2642 s32 ret_val;
2643 u16 i;
2644
2645 e1000_initialize_hw_bits_ich8lan(hw);
2646
2647 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00002648 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00002649 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002650 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00002651 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002652
2653 /* Setup the receive address. */
2654 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
2655
2656 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002657 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002658 for (i = 0; i < mac->mta_reg_count; i++)
2659 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
2660
Bruce Allanfc0c7762009-07-01 13:27:55 +00002661 /*
2662 * The 82578 Rx buffer will stall if wakeup is enabled in host and
2663 * the ME. Reading the BM_WUC register will clear the host wakeup bit.
2664 * Reset the phy after disabling host wakeup to reset the Rx buffer.
2665 */
2666 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan94d81862009-11-20 23:25:26 +00002667 hw->phy.ops.read_reg(hw, BM_WUC, &i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002668 ret_val = e1000_phy_hw_reset_ich8lan(hw);
2669 if (ret_val)
2670 return ret_val;
2671 }
2672
Auke Kokbc7f75f2007-09-17 12:30:59 -07002673 /* Setup link and flow control */
2674 ret_val = e1000_setup_link_ich8lan(hw);
2675
2676 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002677 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002678 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2679 E1000_TXDCTL_FULL_TX_DESC_WB;
2680 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2681 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002682 ew32(TXDCTL(0), txdctl);
2683 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002684 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2685 E1000_TXDCTL_FULL_TX_DESC_WB;
2686 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2687 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002688 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002689
Bruce Allanad680762008-03-28 09:15:03 -07002690 /*
2691 * ICH8 has opposite polarity of no_snoop bits.
2692 * By default, we should use snoop behavior.
2693 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694 if (mac->type == e1000_ich8lan)
2695 snoop = PCIE_ICH8_SNOOP_ALL;
2696 else
2697 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
2698 e1000e_set_pcie_no_snoop(hw, snoop);
2699
2700 ctrl_ext = er32(CTRL_EXT);
2701 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2702 ew32(CTRL_EXT, ctrl_ext);
2703
Bruce Allanad680762008-03-28 09:15:03 -07002704 /*
2705 * Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07002706 * important that we do this after we have tried to establish link
2707 * because the symbol error count will increment wildly if there
2708 * is no link.
2709 */
2710 e1000_clear_hw_cntrs_ich8lan(hw);
2711
2712 return 0;
2713}
2714/**
2715 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
2716 * @hw: pointer to the HW structure
2717 *
2718 * Sets/Clears required hardware bits necessary for correctly setting up the
2719 * hardware for transmit and receive.
2720 **/
2721static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
2722{
2723 u32 reg;
2724
2725 /* Extended Device Control */
2726 reg = er32(CTRL_EXT);
2727 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00002728 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
2729 if (hw->mac.type >= e1000_pchlan)
2730 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002731 ew32(CTRL_EXT, reg);
2732
2733 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002734 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002735 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002736 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002737
2738 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002739 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002740 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002741 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002742
2743 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002744 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002745 if (hw->mac.type == e1000_ich8lan)
2746 reg |= (1 << 28) | (1 << 29);
2747 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002748 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002749
2750 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002751 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002752 if (er32(TCTL) & E1000_TCTL_MULR)
2753 reg &= ~(1 << 28);
2754 else
2755 reg |= (1 << 28);
2756 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002757 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002758
2759 /* Device Status */
2760 if (hw->mac.type == e1000_ich8lan) {
2761 reg = er32(STATUS);
2762 reg &= ~(1 << 31);
2763 ew32(STATUS, reg);
2764 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00002765
2766 /*
2767 * work-around descriptor data corruption issue during nfs v2 udp
2768 * traffic, just disable the nfs filtering capability
2769 */
2770 reg = er32(RFCTL);
2771 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
2772 ew32(RFCTL, reg);
2773
2774 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002775}
2776
2777/**
2778 * e1000_setup_link_ich8lan - Setup flow control and link settings
2779 * @hw: pointer to the HW structure
2780 *
2781 * Determines which flow control settings to use, then configures flow
2782 * control. Calls the appropriate media-specific link configuration
2783 * function. Assuming the adapter has a valid link partner, a valid link
2784 * should be established. Assumes the hardware has previously been reset
2785 * and the transmitter and receiver are not enabled.
2786 **/
2787static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
2788{
Auke Kokbc7f75f2007-09-17 12:30:59 -07002789 s32 ret_val;
2790
2791 if (e1000_check_reset_block(hw))
2792 return 0;
2793
Bruce Allanad680762008-03-28 09:15:03 -07002794 /*
2795 * ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07002796 * the default flow control setting, so we explicitly
2797 * set it to full.
2798 */
Bruce Allan37289d92009-06-02 11:29:37 +00002799 if (hw->fc.requested_mode == e1000_fc_default) {
2800 /* Workaround h/w hang when Tx flow control enabled */
2801 if (hw->mac.type == e1000_pchlan)
2802 hw->fc.requested_mode = e1000_fc_rx_pause;
2803 else
2804 hw->fc.requested_mode = e1000_fc_full;
2805 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002806
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002807 /*
2808 * Save off the requested flow control mode for use later. Depending
2809 * on the link partner's capabilities, we may or may not use this mode.
2810 */
2811 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002812
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002813 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08002814 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815
2816 /* Continue to configure the copper link. */
2817 ret_val = e1000_setup_copper_link_ich8lan(hw);
2818 if (ret_val)
2819 return ret_val;
2820
Jeff Kirsher318a94d2008-03-28 09:15:16 -07002821 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00002822 if ((hw->phy.type == e1000_phy_82578) ||
2823 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan94d81862009-11-20 23:25:26 +00002824 ret_val = hw->phy.ops.write_reg(hw,
Bruce Allana4f58f52009-06-02 11:29:18 +00002825 PHY_REG(BM_PORT_CTRL_PAGE, 27),
2826 hw->fc.pause_time);
2827 if (ret_val)
2828 return ret_val;
2829 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002830
2831 return e1000e_set_fc_watermarks(hw);
2832}
2833
2834/**
2835 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
2836 * @hw: pointer to the HW structure
2837 *
2838 * Configures the kumeran interface to the PHY to wait the appropriate time
2839 * when polling the PHY, then call the generic setup_copper_link to finish
2840 * configuring the copper link.
2841 **/
2842static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
2843{
2844 u32 ctrl;
2845 s32 ret_val;
2846 u16 reg_data;
2847
2848 ctrl = er32(CTRL);
2849 ctrl |= E1000_CTRL_SLU;
2850 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2851 ew32(CTRL, ctrl);
2852
Bruce Allanad680762008-03-28 09:15:03 -07002853 /*
2854 * Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07002855 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07002856 * this fixes erroneous timeouts at 10Mbps.
2857 */
Bruce Allan07818952009-12-08 07:28:01 +00002858 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002859 if (ret_val)
2860 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00002861 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
2862 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002863 if (ret_val)
2864 return ret_val;
2865 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00002866 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
2867 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002868 if (ret_val)
2869 return ret_val;
2870
Bruce Allana4f58f52009-06-02 11:29:18 +00002871 switch (hw->phy.type) {
2872 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002873 ret_val = e1000e_copper_link_setup_igp(hw);
2874 if (ret_val)
2875 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002876 break;
2877 case e1000_phy_bm:
2878 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002879 ret_val = e1000e_copper_link_setup_m88(hw);
2880 if (ret_val)
2881 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002882 break;
2883 case e1000_phy_82577:
2884 ret_val = e1000_copper_link_setup_82577(hw);
2885 if (ret_val)
2886 return ret_val;
2887 break;
2888 case e1000_phy_ife:
Bruce Allan94d81862009-11-20 23:25:26 +00002889 ret_val = hw->phy.ops.read_reg(hw, IFE_PHY_MDIX_CONTROL,
Bruce Allana4f58f52009-06-02 11:29:18 +00002890 &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002891 if (ret_val)
2892 return ret_val;
2893
2894 reg_data &= ~IFE_PMC_AUTO_MDIX;
2895
2896 switch (hw->phy.mdix) {
2897 case 1:
2898 reg_data &= ~IFE_PMC_FORCE_MDIX;
2899 break;
2900 case 2:
2901 reg_data |= IFE_PMC_FORCE_MDIX;
2902 break;
2903 case 0:
2904 default:
2905 reg_data |= IFE_PMC_AUTO_MDIX;
2906 break;
2907 }
Bruce Allan94d81862009-11-20 23:25:26 +00002908 ret_val = hw->phy.ops.write_reg(hw, IFE_PHY_MDIX_CONTROL,
Bruce Allana4f58f52009-06-02 11:29:18 +00002909 reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002910 if (ret_val)
2911 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002912 break;
2913 default:
2914 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002915 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002916 return e1000e_setup_copper_link(hw);
2917}
2918
2919/**
2920 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
2921 * @hw: pointer to the HW structure
2922 * @speed: pointer to store current link speed
2923 * @duplex: pointer to store the current link duplex
2924 *
Bruce Allanad680762008-03-28 09:15:03 -07002925 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07002926 * information and then calls the Kumeran lock loss workaround for links at
2927 * gigabit speeds.
2928 **/
2929static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
2930 u16 *duplex)
2931{
2932 s32 ret_val;
2933
2934 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
2935 if (ret_val)
2936 return ret_val;
2937
2938 if ((hw->mac.type == e1000_ich8lan) &&
2939 (hw->phy.type == e1000_phy_igp_3) &&
2940 (*speed == SPEED_1000)) {
2941 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
2942 }
2943
2944 return ret_val;
2945}
2946
2947/**
2948 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
2949 * @hw: pointer to the HW structure
2950 *
2951 * Work-around for 82566 Kumeran PCS lock loss:
2952 * On link status change (i.e. PCI reset, speed change) and link is up and
2953 * speed is gigabit-
2954 * 0) if workaround is optionally disabled do nothing
2955 * 1) wait 1ms for Kumeran link to come up
2956 * 2) check Kumeran Diagnostic register PCS lock loss bit
2957 * 3) if not set the link is locked (all is good), otherwise...
2958 * 4) reset the PHY
2959 * 5) repeat up to 10 times
2960 * Note: this is only called for IGP3 copper when speed is 1gb.
2961 **/
2962static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
2963{
2964 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2965 u32 phy_ctrl;
2966 s32 ret_val;
2967 u16 i, data;
2968 bool link;
2969
2970 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
2971 return 0;
2972
Bruce Allanad680762008-03-28 09:15:03 -07002973 /*
2974 * Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002975 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07002976 * stability
2977 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002978 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2979 if (!link)
2980 return 0;
2981
2982 for (i = 0; i < 10; i++) {
2983 /* read once to clear */
2984 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
2985 if (ret_val)
2986 return ret_val;
2987 /* and again to get new status */
2988 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
2989 if (ret_val)
2990 return ret_val;
2991
2992 /* check for PCS lock */
2993 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
2994 return 0;
2995
2996 /* Issue PHY reset */
2997 e1000_phy_hw_reset(hw);
2998 mdelay(5);
2999 }
3000 /* Disable GigE link negotiation */
3001 phy_ctrl = er32(PHY_CTRL);
3002 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3003 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3004 ew32(PHY_CTRL, phy_ctrl);
3005
Bruce Allanad680762008-03-28 09:15:03 -07003006 /*
3007 * Call gig speed drop workaround on Gig disable before accessing
3008 * any PHY registers
3009 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003010 e1000e_gig_downshift_workaround_ich8lan(hw);
3011
3012 /* unable to acquire PCS lock */
3013 return -E1000_ERR_PHY;
3014}
3015
3016/**
Bruce Allanad680762008-03-28 09:15:03 -07003017 * e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003018 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003019 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003020 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003021 * If ICH8, set the current Kumeran workaround state (enabled - true
3022 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023 **/
3024void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3025 bool state)
3026{
3027 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3028
3029 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003030 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003031 return;
3032 }
3033
3034 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3035}
3036
3037/**
3038 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3039 * @hw: pointer to the HW structure
3040 *
3041 * Workaround for 82566 power-down on D3 entry:
3042 * 1) disable gigabit link
3043 * 2) write VR power-down enable
3044 * 3) read it back
3045 * Continue if successful, else issue LCD reset and repeat
3046 **/
3047void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3048{
3049 u32 reg;
3050 u16 data;
3051 u8 retry = 0;
3052
3053 if (hw->phy.type != e1000_phy_igp_3)
3054 return;
3055
3056 /* Try the workaround twice (if needed) */
3057 do {
3058 /* Disable link */
3059 reg = er32(PHY_CTRL);
3060 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3061 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3062 ew32(PHY_CTRL, reg);
3063
Bruce Allanad680762008-03-28 09:15:03 -07003064 /*
3065 * Call gig speed drop workaround on Gig disable before
3066 * accessing any PHY registers
3067 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003068 if (hw->mac.type == e1000_ich8lan)
3069 e1000e_gig_downshift_workaround_ich8lan(hw);
3070
3071 /* Write VR power-down enable */
3072 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3073 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3074 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
3075
3076 /* Read it back and test */
3077 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3078 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3079 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
3080 break;
3081
3082 /* Issue PHY reset and repeat at most one more time */
3083 reg = er32(CTRL);
3084 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
3085 retry++;
3086 } while (retry);
3087}
3088
3089/**
3090 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
3091 * @hw: pointer to the HW structure
3092 *
3093 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08003094 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07003095 * 1) Set Kumeran Near-end loopback
3096 * 2) Clear Kumeran Near-end loopback
3097 * Should only be called for ICH8[m] devices with IGP_3 Phy.
3098 **/
3099void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
3100{
3101 s32 ret_val;
3102 u16 reg_data;
3103
3104 if ((hw->mac.type != e1000_ich8lan) ||
3105 (hw->phy.type != e1000_phy_igp_3))
3106 return;
3107
3108 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3109 &reg_data);
3110 if (ret_val)
3111 return;
3112 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
3113 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3114 reg_data);
3115 if (ret_val)
3116 return;
3117 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
3118 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3119 reg_data);
3120}
3121
3122/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003123 * e1000e_disable_gig_wol_ich8lan - disable gig during WoL
3124 * @hw: pointer to the HW structure
3125 *
3126 * During S0 to Sx transition, it is possible the link remains at gig
3127 * instead of negotiating to a lower speed. Before going to Sx, set
3128 * 'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
3129 * to a lower speed.
3130 *
Bruce Allana4f58f52009-06-02 11:29:18 +00003131 * Should only be called for applicable parts.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003132 **/
3133void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
3134{
3135 u32 phy_ctrl;
3136
Bruce Allana4f58f52009-06-02 11:29:18 +00003137 switch (hw->mac.type) {
Bruce Allan9e135a22009-12-01 15:50:31 +00003138 case e1000_ich8lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00003139 case e1000_ich9lan:
3140 case e1000_ich10lan:
3141 case e1000_pchlan:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003142 phy_ctrl = er32(PHY_CTRL);
3143 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
3144 E1000_PHY_CTRL_GBE_DISABLE;
3145 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00003146
Bruce Allana4f58f52009-06-02 11:29:18 +00003147 if (hw->mac.type == e1000_pchlan)
Bruce Allan74eee2e2009-10-22 21:22:18 -07003148 e1000_phy_hw_reset_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00003149 default:
3150 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003151 }
3152
3153 return;
3154}
3155
3156/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003157 * e1000_cleanup_led_ich8lan - Restore the default LED operation
3158 * @hw: pointer to the HW structure
3159 *
3160 * Return the LED back to the default configuration.
3161 **/
3162static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
3163{
3164 if (hw->phy.type == e1000_phy_ife)
3165 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
3166
3167 ew32(LEDCTL, hw->mac.ledctl_default);
3168 return 0;
3169}
3170
3171/**
Auke Kok489815c2008-02-21 15:11:07 -08003172 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07003173 * @hw: pointer to the HW structure
3174 *
Auke Kok489815c2008-02-21 15:11:07 -08003175 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003176 **/
3177static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
3178{
3179 if (hw->phy.type == e1000_phy_ife)
3180 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3181 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
3182
3183 ew32(LEDCTL, hw->mac.ledctl_mode2);
3184 return 0;
3185}
3186
3187/**
Auke Kok489815c2008-02-21 15:11:07 -08003188 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07003189 * @hw: pointer to the HW structure
3190 *
Auke Kok489815c2008-02-21 15:11:07 -08003191 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003192 **/
3193static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
3194{
3195 if (hw->phy.type == e1000_phy_ife)
3196 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3197 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
3198
3199 ew32(LEDCTL, hw->mac.ledctl_mode1);
3200 return 0;
3201}
3202
3203/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003204 * e1000_setup_led_pchlan - Configures SW controllable LED
3205 * @hw: pointer to the HW structure
3206 *
3207 * This prepares the SW controllable LED for use.
3208 **/
3209static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
3210{
Bruce Allan94d81862009-11-20 23:25:26 +00003211 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
Bruce Allana4f58f52009-06-02 11:29:18 +00003212 (u16)hw->mac.ledctl_mode1);
3213}
3214
3215/**
3216 * e1000_cleanup_led_pchlan - Restore the default LED operation
3217 * @hw: pointer to the HW structure
3218 *
3219 * Return the LED back to the default configuration.
3220 **/
3221static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
3222{
Bruce Allan94d81862009-11-20 23:25:26 +00003223 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
Bruce Allana4f58f52009-06-02 11:29:18 +00003224 (u16)hw->mac.ledctl_default);
3225}
3226
3227/**
3228 * e1000_led_on_pchlan - Turn LEDs on
3229 * @hw: pointer to the HW structure
3230 *
3231 * Turn on the LEDs.
3232 **/
3233static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
3234{
3235 u16 data = (u16)hw->mac.ledctl_mode2;
3236 u32 i, led;
3237
3238 /*
3239 * If no link, then turn LED on by setting the invert bit
3240 * for each LED that's mode is "link_up" in ledctl_mode2.
3241 */
3242 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3243 for (i = 0; i < 3; i++) {
3244 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3245 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3246 E1000_LEDCTL_MODE_LINK_UP)
3247 continue;
3248 if (led & E1000_PHY_LED0_IVRT)
3249 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3250 else
3251 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3252 }
3253 }
3254
Bruce Allan94d81862009-11-20 23:25:26 +00003255 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003256}
3257
3258/**
3259 * e1000_led_off_pchlan - Turn LEDs off
3260 * @hw: pointer to the HW structure
3261 *
3262 * Turn off the LEDs.
3263 **/
3264static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
3265{
3266 u16 data = (u16)hw->mac.ledctl_mode1;
3267 u32 i, led;
3268
3269 /*
3270 * If no link, then turn LED off by clearing the invert bit
3271 * for each LED that's mode is "link_up" in ledctl_mode1.
3272 */
3273 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3274 for (i = 0; i < 3; i++) {
3275 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3276 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3277 E1000_LEDCTL_MODE_LINK_UP)
3278 continue;
3279 if (led & E1000_PHY_LED0_IVRT)
3280 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3281 else
3282 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3283 }
3284 }
3285
Bruce Allan94d81862009-11-20 23:25:26 +00003286 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003287}
3288
3289/**
Bruce Allanf4187b52008-08-26 18:36:50 -07003290 * e1000_get_cfg_done_ich8lan - Read config done bit
3291 * @hw: pointer to the HW structure
3292 *
3293 * Read the management control register for the config done bit for
3294 * completion status. NOTE: silicon which is EEPROM-less will fail trying
3295 * to read the config done bit, so an error is *ONLY* logged and returns
Bruce Allana4f58f52009-06-02 11:29:18 +00003296 * 0. If we were to return with error, EEPROM-less silicon
Bruce Allanf4187b52008-08-26 18:36:50 -07003297 * would not be able to be reset or change link.
3298 **/
3299static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
3300{
3301 u32 bank = 0;
3302
Bruce Allanfc0c7762009-07-01 13:27:55 +00003303 if (hw->mac.type >= e1000_pchlan) {
3304 u32 status = er32(STATUS);
3305
3306 if (status & E1000_STATUS_PHYRA)
3307 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
3308 else
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003309 e_dbg("PHY Reset Asserted not set - needs delay\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00003310 }
3311
Bruce Allanf4187b52008-08-26 18:36:50 -07003312 e1000e_get_cfg_done(hw);
3313
3314 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allana4f58f52009-06-02 11:29:18 +00003315 if ((hw->mac.type != e1000_ich10lan) &&
3316 (hw->mac.type != e1000_pchlan)) {
Bruce Allanf4187b52008-08-26 18:36:50 -07003317 if (((er32(EECD) & E1000_EECD_PRES) == 0) &&
3318 (hw->phy.type == e1000_phy_igp_3)) {
3319 e1000e_phy_init_script_igp3(hw);
3320 }
3321 } else {
3322 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
3323 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003324 e_dbg("EEPROM not present\n");
Bruce Allanf4187b52008-08-26 18:36:50 -07003325 return -E1000_ERR_CONFIG;
3326 }
3327 }
3328
3329 return 0;
3330}
3331
3332/**
Bruce Allan17f208d2009-12-01 15:47:22 +00003333 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
3334 * @hw: pointer to the HW structure
3335 *
3336 * In the case of a PHY power down to save power, or to turn off link during a
3337 * driver unload, or wake on lan is not enabled, remove the link.
3338 **/
3339static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
3340{
3341 /* If the management interface is not enabled, then power down */
3342 if (!(hw->mac.ops.check_mng_mode(hw) ||
3343 hw->phy.ops.check_reset_block(hw)))
3344 e1000_power_down_phy_copper(hw);
3345
3346 return;
3347}
3348
3349/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003350 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
3351 * @hw: pointer to the HW structure
3352 *
3353 * Clears hardware counters specific to the silicon family and calls
3354 * clear_hw_cntrs_generic to clear all general purpose counters.
3355 **/
3356static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
3357{
Bruce Allana4f58f52009-06-02 11:29:18 +00003358 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359
3360 e1000e_clear_hw_cntrs_base(hw);
3361
Bruce Allan99673d92009-11-20 23:27:21 +00003362 er32(ALGNERRC);
3363 er32(RXERRC);
3364 er32(TNCRS);
3365 er32(CEXTERR);
3366 er32(TSCTC);
3367 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003368
Bruce Allan99673d92009-11-20 23:27:21 +00003369 er32(MGTPRC);
3370 er32(MGTPDC);
3371 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003372
Bruce Allan99673d92009-11-20 23:27:21 +00003373 er32(IAC);
3374 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003375
Bruce Allana4f58f52009-06-02 11:29:18 +00003376 /* Clear PHY statistics registers */
3377 if ((hw->phy.type == e1000_phy_82578) ||
3378 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan94d81862009-11-20 23:25:26 +00003379 hw->phy.ops.read_reg(hw, HV_SCC_UPPER, &phy_data);
3380 hw->phy.ops.read_reg(hw, HV_SCC_LOWER, &phy_data);
3381 hw->phy.ops.read_reg(hw, HV_ECOL_UPPER, &phy_data);
3382 hw->phy.ops.read_reg(hw, HV_ECOL_LOWER, &phy_data);
3383 hw->phy.ops.read_reg(hw, HV_MCC_UPPER, &phy_data);
3384 hw->phy.ops.read_reg(hw, HV_MCC_LOWER, &phy_data);
3385 hw->phy.ops.read_reg(hw, HV_LATECOL_UPPER, &phy_data);
3386 hw->phy.ops.read_reg(hw, HV_LATECOL_LOWER, &phy_data);
3387 hw->phy.ops.read_reg(hw, HV_COLC_UPPER, &phy_data);
3388 hw->phy.ops.read_reg(hw, HV_COLC_LOWER, &phy_data);
3389 hw->phy.ops.read_reg(hw, HV_DC_UPPER, &phy_data);
3390 hw->phy.ops.read_reg(hw, HV_DC_LOWER, &phy_data);
3391 hw->phy.ops.read_reg(hw, HV_TNCRS_UPPER, &phy_data);
3392 hw->phy.ops.read_reg(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003393 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003394}
3395
3396static struct e1000_mac_operations ich8_mac_ops = {
Bruce Allana4f58f52009-06-02 11:29:18 +00003397 .id_led_init = e1000e_id_led_init,
Bruce Allan4662e822008-08-26 18:37:06 -07003398 .check_mng_mode = e1000_check_mng_mode_ich8lan,
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003399 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003400 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003401 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
3402 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00003403 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003404 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003405 /* led_on dependent on mac type */
3406 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003407 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003408 .reset_hw = e1000_reset_hw_ich8lan,
3409 .init_hw = e1000_init_hw_ich8lan,
3410 .setup_link = e1000_setup_link_ich8lan,
3411 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003412 /* id_led_init dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003413};
3414
3415static struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00003416 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003417 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003418 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07003419 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003420 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00003421 .read_reg = e1000e_read_phy_reg_igp,
3422 .release = e1000_release_swflag_ich8lan,
3423 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003424 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
3425 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003426 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003427};
3428
3429static struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00003430 .acquire = e1000_acquire_nvm_ich8lan,
3431 .read = e1000_read_nvm_ich8lan,
3432 .release = e1000_release_nvm_ich8lan,
3433 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003434 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003435 .validate = e1000_validate_nvm_checksum_ich8lan,
3436 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003437};
3438
3439struct e1000_info e1000_ich8_info = {
3440 .mac = e1000_ich8lan,
3441 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003442 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003443 | FLAG_RX_CSUM_ENABLED
3444 | FLAG_HAS_CTRLEXT_ON_LOAD
3445 | FLAG_HAS_AMT
3446 | FLAG_HAS_FLASH
3447 | FLAG_APME_IN_WUC,
3448 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003449 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003450 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003451 .mac_ops = &ich8_mac_ops,
3452 .phy_ops = &ich8_phy_ops,
3453 .nvm_ops = &ich8_nvm_ops,
3454};
3455
3456struct e1000_info e1000_ich9_info = {
3457 .mac = e1000_ich9lan,
3458 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003459 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003460 | FLAG_HAS_WOL
3461 | FLAG_RX_CSUM_ENABLED
3462 | FLAG_HAS_CTRLEXT_ON_LOAD
3463 | FLAG_HAS_AMT
3464 | FLAG_HAS_ERT
3465 | FLAG_HAS_FLASH
3466 | FLAG_APME_IN_WUC,
3467 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003468 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003469 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003470 .mac_ops = &ich8_mac_ops,
3471 .phy_ops = &ich8_phy_ops,
3472 .nvm_ops = &ich8_nvm_ops,
3473};
3474
Bruce Allanf4187b52008-08-26 18:36:50 -07003475struct e1000_info e1000_ich10_info = {
3476 .mac = e1000_ich10lan,
3477 .flags = FLAG_HAS_JUMBO_FRAMES
3478 | FLAG_IS_ICH
3479 | FLAG_HAS_WOL
3480 | FLAG_RX_CSUM_ENABLED
3481 | FLAG_HAS_CTRLEXT_ON_LOAD
3482 | FLAG_HAS_AMT
3483 | FLAG_HAS_ERT
3484 | FLAG_HAS_FLASH
3485 | FLAG_APME_IN_WUC,
3486 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003487 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07003488 .get_variants = e1000_get_variants_ich8lan,
3489 .mac_ops = &ich8_mac_ops,
3490 .phy_ops = &ich8_phy_ops,
3491 .nvm_ops = &ich8_nvm_ops,
3492};
Bruce Allana4f58f52009-06-02 11:29:18 +00003493
3494struct e1000_info e1000_pch_info = {
3495 .mac = e1000_pchlan,
3496 .flags = FLAG_IS_ICH
3497 | FLAG_HAS_WOL
3498 | FLAG_RX_CSUM_ENABLED
3499 | FLAG_HAS_CTRLEXT_ON_LOAD
3500 | FLAG_HAS_AMT
3501 | FLAG_HAS_FLASH
3502 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00003503 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00003504 | FLAG_APME_IN_WUC,
3505 .pba = 26,
3506 .max_hw_frame_size = 4096,
3507 .get_variants = e1000_get_variants_ich8lan,
3508 .mac_ops = &ich8_mac_ops,
3509 .phy_ops = &ich8_phy_ops,
3510 .nvm_ops = &ich8_nvm_ops,
3511};