blob: 8274499b7df62b21fe96602a4d36d95fea9d39df [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
Bruce Alland3738bb2010-06-16 13:27:28 +000055 * 82579LM Gigabit Network Connection
56 * 82579V Gigabit Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070057 */
58
Auke Kokbc7f75f2007-09-17 12:30:59 -070059#include "e1000.h"
60
61#define ICH_FLASH_GFPREG 0x0000
62#define ICH_FLASH_HSFSTS 0x0004
63#define ICH_FLASH_HSFCTL 0x0006
64#define ICH_FLASH_FADDR 0x0008
65#define ICH_FLASH_FDATA0 0x0010
Bruce Allan4a770352008-10-01 17:18:35 -070066#define ICH_FLASH_PR0 0x0074
Auke Kokbc7f75f2007-09-17 12:30:59 -070067
68#define ICH_FLASH_READ_COMMAND_TIMEOUT 500
69#define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
70#define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
71#define ICH_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
72#define ICH_FLASH_CYCLE_REPEAT_COUNT 10
73
74#define ICH_CYCLE_READ 0
75#define ICH_CYCLE_WRITE 2
76#define ICH_CYCLE_ERASE 3
77
78#define FLASH_GFPREG_BASE_MASK 0x1FFF
79#define FLASH_SECTOR_ADDR_SHIFT 12
80
81#define ICH_FLASH_SEG_SIZE_256 256
82#define ICH_FLASH_SEG_SIZE_4K 4096
83#define ICH_FLASH_SEG_SIZE_8K 8192
84#define ICH_FLASH_SEG_SIZE_64K 65536
85
86
87#define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
Bruce Allan6dfaa762010-05-05 22:00:06 +000088/* FW established a valid mode */
89#define E1000_ICH_FWSM_FW_VALID 0x00008000
Auke Kokbc7f75f2007-09-17 12:30:59 -070090
91#define E1000_ICH_MNG_IAMT_MODE 0x2
92
93#define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
94 (ID_LED_DEF1_OFF2 << 8) | \
95 (ID_LED_DEF1_ON2 << 4) | \
96 (ID_LED_DEF1_DEF2))
97
98#define E1000_ICH_NVM_SIG_WORD 0x13
99#define E1000_ICH_NVM_SIG_MASK 0xC000
Bruce Allane2434552008-11-21 17:02:41 -0800100#define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
101#define E1000_ICH_NVM_SIG_VALUE 0x80
Auke Kokbc7f75f2007-09-17 12:30:59 -0700102
103#define E1000_ICH8_LAN_INIT_TIMEOUT 1500
104
105#define E1000_FEXTNVM_SW_CONFIG 1
106#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
107
108#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
109
110#define E1000_ICH_RAR_ENTRIES 7
111
112#define PHY_PAGE_SHIFT 5
113#define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
114 ((reg) & MAX_PHY_REG_ADDRESS))
115#define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
116#define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
117
118#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
119#define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
120#define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
121
Bruce Allana4f58f52009-06-02 11:29:18 +0000122#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
123
Bruce Allan53ac5a82009-10-26 11:23:06 +0000124#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
125
Bruce Allanf523d212009-10-29 13:45:45 +0000126/* SMBus Address Phy Register */
127#define HV_SMB_ADDR PHY_REG(768, 26)
128#define HV_SMB_ADDR_PEC_EN 0x0200
129#define HV_SMB_ADDR_VALID 0x0080
130
Bruce Alland3738bb2010-06-16 13:27:28 +0000131/* PHY Power Management Control */
132#define HV_PM_CTRL PHY_REG(770, 17)
133
Bruce Allanf523d212009-10-29 13:45:45 +0000134/* Strapping Option Register - RO */
135#define E1000_STRAP 0x0000C
136#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
137#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
138
Bruce Allanfa2ce132009-10-26 11:23:25 +0000139/* OEM Bits Phy Register */
140#define HV_OEM_BITS PHY_REG(768, 25)
141#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
Bruce Allanf523d212009-10-29 13:45:45 +0000142#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
Bruce Allanfa2ce132009-10-26 11:23:25 +0000143#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
144
Bruce Allan1d5846b2009-10-29 13:46:05 +0000145#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
146#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
147
Bruce Allanfddaa1af2010-01-13 01:52:49 +0000148/* KMRN Mode Control */
149#define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
150#define HV_KMRN_MDIO_SLOW 0x0400
151
Auke Kokbc7f75f2007-09-17 12:30:59 -0700152/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
153/* Offset 04h HSFSTS */
154union ich8_hws_flash_status {
155 struct ich8_hsfsts {
156 u16 flcdone :1; /* bit 0 Flash Cycle Done */
157 u16 flcerr :1; /* bit 1 Flash Cycle Error */
158 u16 dael :1; /* bit 2 Direct Access error Log */
159 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
160 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
161 u16 reserved1 :2; /* bit 13:6 Reserved */
162 u16 reserved2 :6; /* bit 13:6 Reserved */
163 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
164 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
165 } hsf_status;
166 u16 regval;
167};
168
169/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
170/* Offset 06h FLCTL */
171union ich8_hws_flash_ctrl {
172 struct ich8_hsflctl {
173 u16 flcgo :1; /* 0 Flash Cycle Go */
174 u16 flcycle :2; /* 2:1 Flash Cycle */
175 u16 reserved :5; /* 7:3 Reserved */
176 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
177 u16 flockdn :6; /* 15:10 Reserved */
178 } hsf_ctrl;
179 u16 regval;
180};
181
182/* ICH Flash Region Access Permissions */
183union ich8_hws_flash_regacc {
184 struct ich8_flracc {
185 u32 grra :8; /* 0:7 GbE region Read Access */
186 u32 grwa :8; /* 8:15 GbE region Write Access */
187 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
188 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
189 } hsf_flregacc;
190 u16 regval;
191};
192
Bruce Allan4a770352008-10-01 17:18:35 -0700193/* ICH Flash Protected Region */
194union ich8_flash_protected_range {
195 struct ich8_pr {
196 u32 base:13; /* 0:12 Protected Range Base */
197 u32 reserved1:2; /* 13:14 Reserved */
198 u32 rpe:1; /* 15 Read Protection Enable */
199 u32 limit:13; /* 16:28 Protected Range Limit */
200 u32 reserved2:2; /* 29:30 Reserved */
201 u32 wpe:1; /* 31 Write Protection Enable */
202 } range;
203 u32 regval;
204};
205
Auke Kokbc7f75f2007-09-17 12:30:59 -0700206static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
207static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
208static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700209static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
210static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
211 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700212static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
213 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700214static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
215 u16 *data);
216static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
217 u8 size, u16 *data);
218static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
219static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700220static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000221static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
222static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
223static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
224static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
225static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
226static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
227static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
228static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000229static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000230static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000231static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000232static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1af2010-01-13 01:52:49 +0000233static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000234static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
235static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700236
237static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
238{
239 return readw(hw->flash_address + reg);
240}
241
242static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
243{
244 return readl(hw->flash_address + reg);
245}
246
247static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
248{
249 writew(val, hw->flash_address + reg);
250}
251
252static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
253{
254 writel(val, hw->flash_address + reg);
255}
256
257#define er16flash(reg) __er16flash(hw, (reg))
258#define er32flash(reg) __er32flash(hw, (reg))
259#define ew16flash(reg,val) __ew16flash(hw, (reg), (val))
260#define ew32flash(reg,val) __ew32flash(hw, (reg), (val))
261
262/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000263 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
264 * @hw: pointer to the HW structure
265 *
266 * Initialize family-specific PHY parameters and function pointers.
267 **/
268static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
269{
270 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan6dfaa762010-05-05 22:00:06 +0000271 u32 ctrl;
Bruce Allana4f58f52009-06-02 11:29:18 +0000272 s32 ret_val = 0;
273
274 phy->addr = 1;
275 phy->reset_delay_us = 100;
276
Bruce Allan94d81862009-11-20 23:25:26 +0000277 phy->ops.read_reg = e1000_read_phy_reg_hv;
278 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000279 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
280 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000281 phy->ops.write_reg = e1000_write_phy_reg_hv;
282 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan17f208d2009-12-01 15:47:22 +0000283 phy->ops.power_up = e1000_power_up_phy_copper;
284 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000285 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
286
Bruce Alland3738bb2010-06-16 13:27:28 +0000287 /*
288 * The MAC-PHY interconnect may still be in SMBus mode
289 * after Sx->S0. If the manageability engine (ME) is
290 * disabled, then toggle the LANPHYPC Value bit to force
291 * the interconnect to PCIe mode.
292 */
Bruce Allan6dfaa762010-05-05 22:00:06 +0000293 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan6dfaa762010-05-05 22:00:06 +0000294 ctrl = er32(CTRL);
295 ctrl |= E1000_CTRL_LANPHYPC_OVERRIDE;
296 ctrl &= ~E1000_CTRL_LANPHYPC_VALUE;
297 ew32(CTRL, ctrl);
298 udelay(10);
299 ctrl &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
300 ew32(CTRL, ctrl);
301 msleep(50);
302 }
303
Bruce Allan627c8a02010-05-05 22:00:27 +0000304 /*
305 * Reset the PHY before any acccess to it. Doing so, ensures that
306 * the PHY is in a known good state before we read/write PHY registers.
307 * The generic reset is sufficient here, because we haven't determined
308 * the PHY type yet.
309 */
310 ret_val = e1000e_phy_hw_reset_generic(hw);
311 if (ret_val)
312 goto out;
313
Bruce Allana4f58f52009-06-02 11:29:18 +0000314 phy->id = e1000_phy_unknown;
Bruce Allanfddaa1af2010-01-13 01:52:49 +0000315 ret_val = e1000e_get_phy_id(hw);
316 if (ret_val)
317 goto out;
318 if ((phy->id == 0) || (phy->id == PHY_REVISION_MASK)) {
319 /*
320 * In case the PHY needs to be in mdio slow mode (eg. 82577),
321 * set slow mode and try to get the PHY id again.
322 */
323 ret_val = e1000_set_mdio_slow_mode_hv(hw);
324 if (ret_val)
325 goto out;
326 ret_val = e1000e_get_phy_id(hw);
327 if (ret_val)
328 goto out;
329 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000330 phy->type = e1000e_get_phy_type_from_id(phy->id);
331
Bruce Allan0be84012009-12-02 17:03:18 +0000332 switch (phy->type) {
333 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000334 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +0000335 phy->ops.check_polarity = e1000_check_polarity_82577;
336 phy->ops.force_speed_duplex =
337 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000338 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000339 phy->ops.get_info = e1000_get_phy_info_82577;
340 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000341 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000342 case e1000_phy_82578:
343 phy->ops.check_polarity = e1000_check_polarity_m88;
344 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
345 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
346 phy->ops.get_info = e1000e_get_phy_info_m88;
347 break;
348 default:
349 ret_val = -E1000_ERR_PHY;
350 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000351 }
352
Bruce Allanfddaa1af2010-01-13 01:52:49 +0000353out:
Bruce Allana4f58f52009-06-02 11:29:18 +0000354 return ret_val;
355}
356
357/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700358 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
359 * @hw: pointer to the HW structure
360 *
361 * Initialize family-specific PHY parameters and function pointers.
362 **/
363static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
364{
365 struct e1000_phy_info *phy = &hw->phy;
366 s32 ret_val;
367 u16 i = 0;
368
369 phy->addr = 1;
370 phy->reset_delay_us = 100;
371
Bruce Allan17f208d2009-12-01 15:47:22 +0000372 phy->ops.power_up = e1000_power_up_phy_copper;
373 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
374
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700375 /*
376 * We may need to do this twice - once for IGP and if that fails,
377 * we'll set BM func pointers and try again
378 */
379 ret_val = e1000e_determine_phy_address(hw);
380 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000381 phy->ops.write_reg = e1000e_write_phy_reg_bm;
382 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700383 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000384 if (ret_val) {
385 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700386 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000387 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700388 }
389
Auke Kokbc7f75f2007-09-17 12:30:59 -0700390 phy->id = 0;
391 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
392 (i++ < 100)) {
393 msleep(1);
394 ret_val = e1000e_get_phy_id(hw);
395 if (ret_val)
396 return ret_val;
397 }
398
399 /* Verify phy id */
400 switch (phy->id) {
401 case IGP03E1000_E_PHY_ID:
402 phy->type = e1000_phy_igp_3;
403 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000404 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
405 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000406 phy->ops.get_info = e1000e_get_phy_info_igp;
407 phy->ops.check_polarity = e1000_check_polarity_igp;
408 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700409 break;
410 case IFE_E_PHY_ID:
411 case IFE_PLUS_E_PHY_ID:
412 case IFE_C_E_PHY_ID:
413 phy->type = e1000_phy_ife;
414 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000415 phy->ops.get_info = e1000_get_phy_info_ife;
416 phy->ops.check_polarity = e1000_check_polarity_ife;
417 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700418 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700419 case BME1000_E_PHY_ID:
420 phy->type = e1000_phy_bm;
421 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000422 phy->ops.read_reg = e1000e_read_phy_reg_bm;
423 phy->ops.write_reg = e1000e_write_phy_reg_bm;
424 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000425 phy->ops.get_info = e1000e_get_phy_info_m88;
426 phy->ops.check_polarity = e1000_check_polarity_m88;
427 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700428 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700429 default:
430 return -E1000_ERR_PHY;
431 break;
432 }
433
434 return 0;
435}
436
437/**
438 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
439 * @hw: pointer to the HW structure
440 *
441 * Initialize family-specific NVM parameters and function
442 * pointers.
443 **/
444static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
445{
446 struct e1000_nvm_info *nvm = &hw->nvm;
447 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000448 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700449 u16 i;
450
Bruce Allanad680762008-03-28 09:15:03 -0700451 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700452 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000453 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700454 return -E1000_ERR_CONFIG;
455 }
456
457 nvm->type = e1000_nvm_flash_sw;
458
459 gfpreg = er32flash(ICH_FLASH_GFPREG);
460
Bruce Allanad680762008-03-28 09:15:03 -0700461 /*
462 * sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700463 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700464 * the overall size.
465 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700466 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
467 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
468
469 /* flash_base_addr is byte-aligned */
470 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
471
Bruce Allanad680762008-03-28 09:15:03 -0700472 /*
473 * find total size of the NVM, then cut in half since the total
474 * size represents two separate NVM banks.
475 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700476 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
477 << FLASH_SECTOR_ADDR_SHIFT;
478 nvm->flash_bank_size /= 2;
479 /* Adjust to word count */
480 nvm->flash_bank_size /= sizeof(u16);
481
482 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
483
484 /* Clear shadow ram */
485 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000486 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700487 dev_spec->shadow_ram[i].value = 0xFFFF;
488 }
489
490 return 0;
491}
492
493/**
494 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
495 * @hw: pointer to the HW structure
496 *
497 * Initialize family-specific MAC parameters and function
498 * pointers.
499 **/
500static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
501{
502 struct e1000_hw *hw = &adapter->hw;
503 struct e1000_mac_info *mac = &hw->mac;
504
505 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700506 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700507
508 /* Set mta register count */
509 mac->mta_reg_count = 32;
510 /* Set rar entry count */
511 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
512 if (mac->type == e1000_ich8lan)
513 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000514 /* FWSM register */
515 mac->has_fwsm = true;
516 /* ARC subsystem not supported */
517 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000518 /* Adaptive IFS supported */
519 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700520
Bruce Allana4f58f52009-06-02 11:29:18 +0000521 /* LED operations */
522 switch (mac->type) {
523 case e1000_ich8lan:
524 case e1000_ich9lan:
525 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000526 /* check management mode */
527 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000528 /* ID LED init */
529 mac->ops.id_led_init = e1000e_id_led_init;
530 /* setup LED */
531 mac->ops.setup_led = e1000e_setup_led_generic;
532 /* cleanup LED */
533 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
534 /* turn on/off LED */
535 mac->ops.led_on = e1000_led_on_ich8lan;
536 mac->ops.led_off = e1000_led_off_ich8lan;
537 break;
538 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000539 case e1000_pch2lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000540 /* check management mode */
541 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000542 /* ID LED init */
543 mac->ops.id_led_init = e1000_id_led_init_pchlan;
544 /* setup LED */
545 mac->ops.setup_led = e1000_setup_led_pchlan;
546 /* cleanup LED */
547 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
548 /* turn on/off LED */
549 mac->ops.led_on = e1000_led_on_pchlan;
550 mac->ops.led_off = e1000_led_off_pchlan;
551 break;
552 default:
553 break;
554 }
555
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556 /* Enable PCS Lock-loss workaround for ICH8 */
557 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000558 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700559
Bruce Alland3738bb2010-06-16 13:27:28 +0000560 /* Disable PHY configuration by hardware, config by software */
561 if (mac->type == e1000_pch2lan) {
562 u32 extcnf_ctrl = er32(EXTCNF_CTRL);
563
564 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
565 ew32(EXTCNF_CTRL, extcnf_ctrl);
566 }
567
Auke Kokbc7f75f2007-09-17 12:30:59 -0700568 return 0;
569}
570
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000571/**
572 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
573 * @hw: pointer to the HW structure
574 *
575 * Checks to see of the link status of the hardware has changed. If a
576 * change in link status has been detected, then we read the PHY registers
577 * to get the current speed/duplex if link exists.
578 **/
579static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
580{
581 struct e1000_mac_info *mac = &hw->mac;
582 s32 ret_val;
583 bool link;
584
585 /*
586 * We only want to go out to the PHY registers to see if Auto-Neg
587 * has completed and/or if our link status has changed. The
588 * get_link_status flag is set upon receiving a Link Status
589 * Change or Rx Sequence Error interrupt.
590 */
591 if (!mac->get_link_status) {
592 ret_val = 0;
593 goto out;
594 }
595
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000596 /*
597 * First we want to see if the MII Status Register reports
598 * link. If so, then we want to get the current speed/duplex
599 * of the PHY.
600 */
601 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
602 if (ret_val)
603 goto out;
604
Bruce Allan1d5846b2009-10-29 13:46:05 +0000605 if (hw->mac.type == e1000_pchlan) {
606 ret_val = e1000_k1_gig_workaround_hv(hw, link);
607 if (ret_val)
608 goto out;
609 }
610
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000611 if (!link)
612 goto out; /* No link detected */
613
614 mac->get_link_status = false;
615
616 if (hw->phy.type == e1000_phy_82578) {
617 ret_val = e1000_link_stall_workaround_hv(hw);
618 if (ret_val)
619 goto out;
620 }
621
622 /*
623 * Check if there was DownShift, must be checked
624 * immediately after link-up
625 */
626 e1000e_check_downshift(hw);
627
628 /*
629 * If we are forcing speed/duplex, then we simply return since
630 * we have already determined whether we have link or not.
631 */
632 if (!mac->autoneg) {
633 ret_val = -E1000_ERR_CONFIG;
634 goto out;
635 }
636
637 /*
638 * Auto-Neg is enabled. Auto Speed Detection takes care
639 * of MAC speed/duplex configuration. So we only need to
640 * configure Collision Distance in the MAC.
641 */
642 e1000e_config_collision_dist(hw);
643
644 /*
645 * Configure Flow Control now that Auto-Neg has completed.
646 * First, we need to restore the desired flow control
647 * settings because we may have had to re-autoneg with a
648 * different link partner.
649 */
650 ret_val = e1000e_config_fc_after_link_up(hw);
651 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000652 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000653
654out:
655 return ret_val;
656}
657
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700658static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700659{
660 struct e1000_hw *hw = &adapter->hw;
661 s32 rc;
662
663 rc = e1000_init_mac_params_ich8lan(adapter);
664 if (rc)
665 return rc;
666
667 rc = e1000_init_nvm_params_ich8lan(hw);
668 if (rc)
669 return rc;
670
Bruce Alland3738bb2010-06-16 13:27:28 +0000671 switch (hw->mac.type) {
672 case e1000_ich8lan:
673 case e1000_ich9lan:
674 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000675 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +0000676 break;
677 case e1000_pchlan:
678 case e1000_pch2lan:
679 rc = e1000_init_phy_params_pchlan(hw);
680 break;
681 default:
682 break;
683 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700684 if (rc)
685 return rc;
686
Bruce Allan2adc55c2009-06-02 11:28:58 +0000687 if (adapter->hw.phy.type == e1000_phy_ife) {
688 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
689 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
690 }
691
Auke Kokbc7f75f2007-09-17 12:30:59 -0700692 if ((adapter->hw.mac.type == e1000_ich8lan) &&
693 (adapter->hw.phy.type == e1000_phy_igp_3))
694 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
695
696 return 0;
697}
698
Thomas Gleixner717d4382008-10-02 16:33:40 -0700699static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700700
Auke Kokbc7f75f2007-09-17 12:30:59 -0700701/**
Bruce Allanca15df52009-10-26 11:23:43 +0000702 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
703 * @hw: pointer to the HW structure
704 *
705 * Acquires the mutex for performing NVM operations.
706 **/
707static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
708{
709 mutex_lock(&nvm_mutex);
710
711 return 0;
712}
713
714/**
715 * e1000_release_nvm_ich8lan - Release NVM mutex
716 * @hw: pointer to the HW structure
717 *
718 * Releases the mutex used while performing NVM operations.
719 **/
720static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
721{
722 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +0000723}
724
725static DEFINE_MUTEX(swflag_mutex);
726
727/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700728 * e1000_acquire_swflag_ich8lan - Acquire software control flag
729 * @hw: pointer to the HW structure
730 *
Bruce Allanca15df52009-10-26 11:23:43 +0000731 * Acquires the software control flag for performing PHY and select
732 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700733 **/
734static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
735{
Bruce Allan373a88d2009-08-07 07:41:37 +0000736 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
737 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700738
Bruce Allanca15df52009-10-26 11:23:43 +0000739 mutex_lock(&swflag_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700740
Auke Kokbc7f75f2007-09-17 12:30:59 -0700741 while (timeout) {
742 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +0000743 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
744 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700745
Auke Kokbc7f75f2007-09-17 12:30:59 -0700746 mdelay(1);
747 timeout--;
748 }
749
750 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000751 e_dbg("SW/FW/HW has locked the resource for too long.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000752 ret_val = -E1000_ERR_CONFIG;
753 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700754 }
755
Bruce Allan53ac5a82009-10-26 11:23:06 +0000756 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +0000757
758 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
759 ew32(EXTCNF_CTRL, extcnf_ctrl);
760
761 while (timeout) {
762 extcnf_ctrl = er32(EXTCNF_CTRL);
763 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
764 break;
765
766 mdelay(1);
767 timeout--;
768 }
769
770 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000771 e_dbg("Failed to acquire the semaphore.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000772 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
773 ew32(EXTCNF_CTRL, extcnf_ctrl);
774 ret_val = -E1000_ERR_CONFIG;
775 goto out;
776 }
777
778out:
779 if (ret_val)
Bruce Allanca15df52009-10-26 11:23:43 +0000780 mutex_unlock(&swflag_mutex);
Bruce Allan373a88d2009-08-07 07:41:37 +0000781
782 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700783}
784
785/**
786 * e1000_release_swflag_ich8lan - Release software control flag
787 * @hw: pointer to the HW structure
788 *
Bruce Allanca15df52009-10-26 11:23:43 +0000789 * Releases the software control flag for performing PHY and select
790 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700791 **/
792static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
793{
794 u32 extcnf_ctrl;
795
796 extcnf_ctrl = er32(EXTCNF_CTRL);
797 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
798 ew32(EXTCNF_CTRL, extcnf_ctrl);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700799
Bruce Allanca15df52009-10-26 11:23:43 +0000800 mutex_unlock(&swflag_mutex);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700801}
802
803/**
Bruce Allan4662e822008-08-26 18:37:06 -0700804 * e1000_check_mng_mode_ich8lan - Checks management mode
805 * @hw: pointer to the HW structure
806 *
Bruce Allaneb7700d2010-06-16 13:27:05 +0000807 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -0700808 * This is a function pointer entry point only called by read/write
809 * routines for the PHY and NVM parts.
810 **/
811static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
812{
Bruce Allana708dd82009-11-20 23:28:37 +0000813 u32 fwsm;
814
815 fwsm = er32(FWSM);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000816 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
817 ((fwsm & E1000_FWSM_MODE_MASK) ==
818 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
819}
Bruce Allan4662e822008-08-26 18:37:06 -0700820
Bruce Allaneb7700d2010-06-16 13:27:05 +0000821/**
822 * e1000_check_mng_mode_pchlan - Checks management mode
823 * @hw: pointer to the HW structure
824 *
825 * This checks if the adapter has iAMT enabled.
826 * This is a function pointer entry point only called by read/write
827 * routines for the PHY and NVM parts.
828 **/
829static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
830{
831 u32 fwsm;
832
833 fwsm = er32(FWSM);
834 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
835 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -0700836}
837
838/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700839 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
840 * @hw: pointer to the HW structure
841 *
842 * Checks if firmware is blocking the reset of the PHY.
843 * This is a function pointer entry point only called by
844 * reset routines.
845 **/
846static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
847{
848 u32 fwsm;
849
850 fwsm = er32(FWSM);
851
852 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
853}
854
855/**
Bruce Allanf523d212009-10-29 13:45:45 +0000856 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
857 * @hw: pointer to the HW structure
858 *
859 * SW should configure the LCD from the NVM extended configuration region
860 * as a workaround for certain parts.
861 **/
862static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
863{
Bruce Allan8b802a72010-05-10 15:01:10 +0000864 struct e1000_adapter *adapter = hw->adapter;
Bruce Allanf523d212009-10-29 13:45:45 +0000865 struct e1000_phy_info *phy = &hw->phy;
866 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +0000867 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +0000868 u16 word_addr, reg_data, reg_addr, phy_page = 0;
869
Bruce Allanf523d212009-10-29 13:45:45 +0000870 /*
871 * Initialize the PHY from the NVM on ICH platforms. This
872 * is needed due to an issue where the NVM configuration is
873 * not properly autoloaded after power transitions.
874 * Therefore, after each PHY reset, we will load the
875 * configuration data out of the NVM manually.
876 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +0000877 switch (hw->mac.type) {
878 case e1000_ich8lan:
879 if (phy->type != e1000_phy_igp_3)
880 return ret_val;
881
882 if (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) {
883 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
884 break;
885 }
886 /* Fall-thru */
887 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000888 case e1000_pch2lan:
Bruce Allan8b802a72010-05-10 15:01:10 +0000889 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +0000890 break;
891 default:
892 return ret_val;
893 }
894
895 ret_val = hw->phy.ops.acquire(hw);
896 if (ret_val)
897 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +0000898
Bruce Allan8b802a72010-05-10 15:01:10 +0000899 data = er32(FEXTNVM);
900 if (!(data & sw_cfg_mask))
901 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +0000902
Bruce Allan8b802a72010-05-10 15:01:10 +0000903 /*
904 * Make sure HW does not configure LCD from PHY
905 * extended configuration before SW configuration
906 */
907 data = er32(EXTCNF_CTRL);
Bruce Alland3738bb2010-06-16 13:27:28 +0000908 if (!(hw->mac.type == e1000_pch2lan)) {
909 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
910 goto out;
911 }
Bruce Allanf523d212009-10-29 13:45:45 +0000912
Bruce Allan8b802a72010-05-10 15:01:10 +0000913 cnf_size = er32(EXTCNF_SIZE);
914 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
915 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
916 if (!cnf_size)
917 goto out;
918
919 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
920 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
921
922 if (!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
Bruce Alland3738bb2010-06-16 13:27:28 +0000923 ((hw->mac.type == e1000_pchlan) ||
924 (hw->mac.type == e1000_pch2lan))) {
Bruce Allanf523d212009-10-29 13:45:45 +0000925 /*
Bruce Allan8b802a72010-05-10 15:01:10 +0000926 * HW configures the SMBus address and LEDs when the
927 * OEM and LCD Write Enable bits are set in the NVM.
928 * When both NVM bits are cleared, SW will configure
929 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +0000930 */
Bruce Allan8b802a72010-05-10 15:01:10 +0000931 data = er32(STRAP);
932 data &= E1000_STRAP_SMBUS_ADDRESS_MASK;
933 reg_data = data >> E1000_STRAP_SMBUS_ADDRESS_SHIFT;
934 reg_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
935 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR,
936 reg_data);
937 if (ret_val)
Bruce Allanf523d212009-10-29 13:45:45 +0000938 goto out;
939
Bruce Allan8b802a72010-05-10 15:01:10 +0000940 data = er32(LEDCTL);
941 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
942 (u16)data);
943 if (ret_val)
944 goto out;
945 }
946
947 /* Configure LCD from extended configuration region. */
948
949 /* cnf_base_addr is in DWORD */
950 word_addr = (u16)(cnf_base_addr << 1);
951
952 for (i = 0; i < cnf_size; i++) {
953 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
954 &reg_data);
955 if (ret_val)
Bruce Allanf523d212009-10-29 13:45:45 +0000956 goto out;
957
Bruce Allan8b802a72010-05-10 15:01:10 +0000958 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
959 1, &reg_addr);
960 if (ret_val)
961 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +0000962
Bruce Allan8b802a72010-05-10 15:01:10 +0000963 /* Save off the PHY page for future writes. */
964 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
965 phy_page = reg_data;
966 continue;
Bruce Allanf523d212009-10-29 13:45:45 +0000967 }
Bruce Allanf523d212009-10-29 13:45:45 +0000968
Bruce Allan8b802a72010-05-10 15:01:10 +0000969 reg_addr &= PHY_REG_MASK;
970 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +0000971
Bruce Allan8b802a72010-05-10 15:01:10 +0000972 ret_val = phy->ops.write_reg_locked(hw, (u32)reg_addr,
973 reg_data);
974 if (ret_val)
975 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +0000976 }
977
978out:
Bruce Allan94d81862009-11-20 23:25:26 +0000979 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000980 return ret_val;
981}
982
983/**
Bruce Allan1d5846b2009-10-29 13:46:05 +0000984 * e1000_k1_gig_workaround_hv - K1 Si workaround
985 * @hw: pointer to the HW structure
986 * @link: link up bool flag
987 *
988 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
989 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
990 * If link is down, the function will restore the default K1 setting located
991 * in the NVM.
992 **/
993static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
994{
995 s32 ret_val = 0;
996 u16 status_reg = 0;
997 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
998
999 if (hw->mac.type != e1000_pchlan)
1000 goto out;
1001
1002 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001003 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001004 if (ret_val)
1005 goto out;
1006
1007 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1008 if (link) {
1009 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan94d81862009-11-20 23:25:26 +00001010 ret_val = hw->phy.ops.read_reg_locked(hw, BM_CS_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +00001011 &status_reg);
1012 if (ret_val)
1013 goto release;
1014
1015 status_reg &= BM_CS_STATUS_LINK_UP |
1016 BM_CS_STATUS_RESOLVED |
1017 BM_CS_STATUS_SPEED_MASK;
1018
1019 if (status_reg == (BM_CS_STATUS_LINK_UP |
1020 BM_CS_STATUS_RESOLVED |
1021 BM_CS_STATUS_SPEED_1000))
1022 k1_enable = false;
1023 }
1024
1025 if (hw->phy.type == e1000_phy_82577) {
Bruce Allan94d81862009-11-20 23:25:26 +00001026 ret_val = hw->phy.ops.read_reg_locked(hw, HV_M_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +00001027 &status_reg);
1028 if (ret_val)
1029 goto release;
1030
1031 status_reg &= HV_M_STATUS_LINK_UP |
1032 HV_M_STATUS_AUTONEG_COMPLETE |
1033 HV_M_STATUS_SPEED_MASK;
1034
1035 if (status_reg == (HV_M_STATUS_LINK_UP |
1036 HV_M_STATUS_AUTONEG_COMPLETE |
1037 HV_M_STATUS_SPEED_1000))
1038 k1_enable = false;
1039 }
1040
1041 /* Link stall fix for link up */
Bruce Allan94d81862009-11-20 23:25:26 +00001042 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +00001043 0x0100);
1044 if (ret_val)
1045 goto release;
1046
1047 } else {
1048 /* Link stall fix for link down */
Bruce Allan94d81862009-11-20 23:25:26 +00001049 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +00001050 0x4100);
1051 if (ret_val)
1052 goto release;
1053 }
1054
1055 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1056
1057release:
Bruce Allan94d81862009-11-20 23:25:26 +00001058 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001059out:
1060 return ret_val;
1061}
1062
1063/**
1064 * e1000_configure_k1_ich8lan - Configure K1 power state
1065 * @hw: pointer to the HW structure
1066 * @enable: K1 state to configure
1067 *
1068 * Configure the K1 power state based on the provided parameter.
1069 * Assumes semaphore already acquired.
1070 *
1071 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1072 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001073s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001074{
1075 s32 ret_val = 0;
1076 u32 ctrl_reg = 0;
1077 u32 ctrl_ext = 0;
1078 u32 reg = 0;
1079 u16 kmrn_reg = 0;
1080
1081 ret_val = e1000e_read_kmrn_reg_locked(hw,
1082 E1000_KMRNCTRLSTA_K1_CONFIG,
1083 &kmrn_reg);
1084 if (ret_val)
1085 goto out;
1086
1087 if (k1_enable)
1088 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1089 else
1090 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1091
1092 ret_val = e1000e_write_kmrn_reg_locked(hw,
1093 E1000_KMRNCTRLSTA_K1_CONFIG,
1094 kmrn_reg);
1095 if (ret_val)
1096 goto out;
1097
1098 udelay(20);
1099 ctrl_ext = er32(CTRL_EXT);
1100 ctrl_reg = er32(CTRL);
1101
1102 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1103 reg |= E1000_CTRL_FRCSPD;
1104 ew32(CTRL, reg);
1105
1106 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
1107 udelay(20);
1108 ew32(CTRL, ctrl_reg);
1109 ew32(CTRL_EXT, ctrl_ext);
1110 udelay(20);
1111
1112out:
1113 return ret_val;
1114}
1115
1116/**
Bruce Allanf523d212009-10-29 13:45:45 +00001117 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1118 * @hw: pointer to the HW structure
1119 * @d0_state: boolean if entering d0 or d3 device state
1120 *
1121 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1122 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1123 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1124 **/
1125static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1126{
1127 s32 ret_val = 0;
1128 u32 mac_reg;
1129 u16 oem_reg;
1130
Bruce Alland3738bb2010-06-16 13:27:28 +00001131 if ((hw->mac.type != e1000_pch2lan) && (hw->mac.type != e1000_pchlan))
Bruce Allanf523d212009-10-29 13:45:45 +00001132 return ret_val;
1133
Bruce Allan94d81862009-11-20 23:25:26 +00001134 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001135 if (ret_val)
1136 return ret_val;
1137
Bruce Alland3738bb2010-06-16 13:27:28 +00001138 if (!(hw->mac.type == e1000_pch2lan)) {
1139 mac_reg = er32(EXTCNF_CTRL);
1140 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
1141 goto out;
1142 }
Bruce Allanf523d212009-10-29 13:45:45 +00001143
1144 mac_reg = er32(FEXTNVM);
1145 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
1146 goto out;
1147
1148 mac_reg = er32(PHY_CTRL);
1149
Bruce Allan94d81862009-11-20 23:25:26 +00001150 ret_val = hw->phy.ops.read_reg_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001151 if (ret_val)
1152 goto out;
1153
1154 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1155
1156 if (d0_state) {
1157 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1158 oem_reg |= HV_OEM_BITS_GBE_DIS;
1159
1160 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1161 oem_reg |= HV_OEM_BITS_LPLU;
1162 } else {
1163 if (mac_reg & E1000_PHY_CTRL_NOND0A_GBE_DISABLE)
1164 oem_reg |= HV_OEM_BITS_GBE_DIS;
1165
1166 if (mac_reg & E1000_PHY_CTRL_NOND0A_LPLU)
1167 oem_reg |= HV_OEM_BITS_LPLU;
1168 }
1169 /* Restart auto-neg to activate the bits */
Bruce Allan818f3332009-11-19 14:17:30 +00001170 if (!e1000_check_reset_block(hw))
1171 oem_reg |= HV_OEM_BITS_RESTART_AN;
Bruce Allan94d81862009-11-20 23:25:26 +00001172 ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001173
1174out:
Bruce Allan94d81862009-11-20 23:25:26 +00001175 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001176
1177 return ret_val;
1178}
1179
1180
1181/**
Bruce Allanfddaa1af2010-01-13 01:52:49 +00001182 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1183 * @hw: pointer to the HW structure
1184 **/
1185static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1186{
1187 s32 ret_val;
1188 u16 data;
1189
1190 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1191 if (ret_val)
1192 return ret_val;
1193
1194 data |= HV_KMRN_MDIO_SLOW;
1195
1196 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1197
1198 return ret_val;
1199}
1200
1201/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001202 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1203 * done after every PHY reset.
1204 **/
1205static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1206{
1207 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001208 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001209
1210 if (hw->mac.type != e1000_pchlan)
1211 return ret_val;
1212
Bruce Allanfddaa1af2010-01-13 01:52:49 +00001213 /* Set MDIO slow mode before any other MDIO access */
1214 if (hw->phy.type == e1000_phy_82577) {
1215 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1216 if (ret_val)
1217 goto out;
1218 }
1219
Bruce Allana4f58f52009-06-02 11:29:18 +00001220 if (((hw->phy.type == e1000_phy_82577) &&
1221 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1222 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1223 /* Disable generation of early preamble */
1224 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1225 if (ret_val)
1226 return ret_val;
1227
1228 /* Preamble tuning for SSC */
1229 ret_val = e1e_wphy(hw, PHY_REG(770, 16), 0xA204);
1230 if (ret_val)
1231 return ret_val;
1232 }
1233
1234 if (hw->phy.type == e1000_phy_82578) {
1235 /*
1236 * Return registers to default by doing a soft reset then
1237 * writing 0x3140 to the control register.
1238 */
1239 if (hw->phy.revision < 2) {
1240 e1000e_phy_sw_reset(hw);
1241 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1242 }
1243 }
1244
1245 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001246 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001247 if (ret_val)
1248 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001249
Bruce Allana4f58f52009-06-02 11:29:18 +00001250 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001251 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001252 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001253 if (ret_val)
1254 goto out;
Bruce Allana4f58f52009-06-02 11:29:18 +00001255
Bruce Allan1d5846b2009-10-29 13:46:05 +00001256 /*
1257 * Configure the K1 Si workaround during phy reset assuming there is
1258 * link so that it disables K1 if link is in 1Gbps.
1259 */
1260 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001261 if (ret_val)
1262 goto out;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001263
Bruce Allanbaf86c92010-01-13 01:53:08 +00001264 /* Workaround for link disconnects on a busy hub in half duplex */
1265 ret_val = hw->phy.ops.acquire(hw);
1266 if (ret_val)
1267 goto out;
1268 ret_val = hw->phy.ops.read_reg_locked(hw,
1269 PHY_REG(BM_PORT_CTRL_PAGE, 17),
1270 &phy_data);
1271 if (ret_val)
1272 goto release;
1273 ret_val = hw->phy.ops.write_reg_locked(hw,
1274 PHY_REG(BM_PORT_CTRL_PAGE, 17),
1275 phy_data & 0x00FF);
1276release:
1277 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001278out:
Bruce Allana4f58f52009-06-02 11:29:18 +00001279 return ret_val;
1280}
1281
1282/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001283 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1284 * @hw: pointer to the HW structure
1285 **/
1286void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1287{
1288 u32 mac_reg;
1289 u16 i;
1290
1291 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1292 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1293 mac_reg = er32(RAL(i));
1294 e1e_wphy(hw, BM_RAR_L(i), (u16)(mac_reg & 0xFFFF));
1295 e1e_wphy(hw, BM_RAR_M(i), (u16)((mac_reg >> 16) & 0xFFFF));
1296 mac_reg = er32(RAH(i));
1297 e1e_wphy(hw, BM_RAR_H(i), (u16)(mac_reg & 0xFFFF));
1298 e1e_wphy(hw, BM_RAR_CTRL(i), (u16)((mac_reg >> 16) & 0x8000));
1299 }
1300}
1301
1302static u32 e1000_calc_rx_da_crc(u8 mac[])
1303{
1304 u32 poly = 0xEDB88320; /* Polynomial for 802.3 CRC calculation */
1305 u32 i, j, mask, crc;
1306
1307 crc = 0xffffffff;
1308 for (i = 0; i < 6; i++) {
1309 crc = crc ^ mac[i];
1310 for (j = 8; j > 0; j--) {
1311 mask = (crc & 1) * (-1);
1312 crc = (crc >> 1) ^ (poly & mask);
1313 }
1314 }
1315 return ~crc;
1316}
1317
1318/**
1319 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1320 * with 82579 PHY
1321 * @hw: pointer to the HW structure
1322 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1323 **/
1324s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1325{
1326 s32 ret_val = 0;
1327 u16 phy_reg, data;
1328 u32 mac_reg;
1329 u16 i;
1330
1331 if (hw->mac.type != e1000_pch2lan)
1332 goto out;
1333
1334 /* disable Rx path while enabling/disabling workaround */
1335 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1336 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1337 if (ret_val)
1338 goto out;
1339
1340 if (enable) {
1341 /*
1342 * Write Rx addresses (rar_entry_count for RAL/H, +4 for
1343 * SHRAL/H) and initial CRC values to the MAC
1344 */
1345 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1346 u8 mac_addr[ETH_ALEN] = {0};
1347 u32 addr_high, addr_low;
1348
1349 addr_high = er32(RAH(i));
1350 if (!(addr_high & E1000_RAH_AV))
1351 continue;
1352 addr_low = er32(RAL(i));
1353 mac_addr[0] = (addr_low & 0xFF);
1354 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1355 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1356 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1357 mac_addr[4] = (addr_high & 0xFF);
1358 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1359
1360 ew32(PCH_RAICC(i),
1361 e1000_calc_rx_da_crc(mac_addr));
1362 }
1363
1364 /* Write Rx addresses to the PHY */
1365 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1366
1367 /* Enable jumbo frame workaround in the MAC */
1368 mac_reg = er32(FFLT_DBG);
1369 mac_reg &= ~(1 << 14);
1370 mac_reg |= (7 << 15);
1371 ew32(FFLT_DBG, mac_reg);
1372
1373 mac_reg = er32(RCTL);
1374 mac_reg |= E1000_RCTL_SECRC;
1375 ew32(RCTL, mac_reg);
1376
1377 ret_val = e1000e_read_kmrn_reg(hw,
1378 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1379 &data);
1380 if (ret_val)
1381 goto out;
1382 ret_val = e1000e_write_kmrn_reg(hw,
1383 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1384 data | (1 << 0));
1385 if (ret_val)
1386 goto out;
1387 ret_val = e1000e_read_kmrn_reg(hw,
1388 E1000_KMRNCTRLSTA_HD_CTRL,
1389 &data);
1390 if (ret_val)
1391 goto out;
1392 data &= ~(0xF << 8);
1393 data |= (0xB << 8);
1394 ret_val = e1000e_write_kmrn_reg(hw,
1395 E1000_KMRNCTRLSTA_HD_CTRL,
1396 data);
1397 if (ret_val)
1398 goto out;
1399
1400 /* Enable jumbo frame workaround in the PHY */
1401 e1e_rphy(hw, PHY_REG(769, 20), &data);
1402 ret_val = e1e_wphy(hw, PHY_REG(769, 20), data & ~(1 << 14));
1403 if (ret_val)
1404 goto out;
1405 e1e_rphy(hw, PHY_REG(769, 23), &data);
1406 data &= ~(0x7F << 5);
1407 data |= (0x37 << 5);
1408 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1409 if (ret_val)
1410 goto out;
1411 e1e_rphy(hw, PHY_REG(769, 16), &data);
1412 data &= ~(1 << 13);
1413 data |= (1 << 12);
1414 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1415 if (ret_val)
1416 goto out;
1417 e1e_rphy(hw, PHY_REG(776, 20), &data);
1418 data &= ~(0x3FF << 2);
1419 data |= (0x1A << 2);
1420 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1421 if (ret_val)
1422 goto out;
1423 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xFE00);
1424 if (ret_val)
1425 goto out;
1426 e1e_rphy(hw, HV_PM_CTRL, &data);
1427 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1428 if (ret_val)
1429 goto out;
1430 } else {
1431 /* Write MAC register values back to h/w defaults */
1432 mac_reg = er32(FFLT_DBG);
1433 mac_reg &= ~(0xF << 14);
1434 ew32(FFLT_DBG, mac_reg);
1435
1436 mac_reg = er32(RCTL);
1437 mac_reg &= ~E1000_RCTL_SECRC;
1438 ew32(FFLT_DBG, mac_reg);
1439
1440 ret_val = e1000e_read_kmrn_reg(hw,
1441 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1442 &data);
1443 if (ret_val)
1444 goto out;
1445 ret_val = e1000e_write_kmrn_reg(hw,
1446 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1447 data & ~(1 << 0));
1448 if (ret_val)
1449 goto out;
1450 ret_val = e1000e_read_kmrn_reg(hw,
1451 E1000_KMRNCTRLSTA_HD_CTRL,
1452 &data);
1453 if (ret_val)
1454 goto out;
1455 data &= ~(0xF << 8);
1456 data |= (0xB << 8);
1457 ret_val = e1000e_write_kmrn_reg(hw,
1458 E1000_KMRNCTRLSTA_HD_CTRL,
1459 data);
1460 if (ret_val)
1461 goto out;
1462
1463 /* Write PHY register values back to h/w defaults */
1464 e1e_rphy(hw, PHY_REG(769, 20), &data);
1465 ret_val = e1e_wphy(hw, PHY_REG(769, 20), data & ~(1 << 14));
1466 if (ret_val)
1467 goto out;
1468 e1e_rphy(hw, PHY_REG(769, 23), &data);
1469 data &= ~(0x7F << 5);
1470 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1471 if (ret_val)
1472 goto out;
1473 e1e_rphy(hw, PHY_REG(769, 16), &data);
1474 data &= ~(1 << 12);
1475 data |= (1 << 13);
1476 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1477 if (ret_val)
1478 goto out;
1479 e1e_rphy(hw, PHY_REG(776, 20), &data);
1480 data &= ~(0x3FF << 2);
1481 data |= (0x8 << 2);
1482 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1483 if (ret_val)
1484 goto out;
1485 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
1486 if (ret_val)
1487 goto out;
1488 e1e_rphy(hw, HV_PM_CTRL, &data);
1489 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
1490 if (ret_val)
1491 goto out;
1492 }
1493
1494 /* re-enable Rx path after enabling/disabling workaround */
1495 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
1496
1497out:
1498 return ret_val;
1499}
1500
1501/**
1502 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1503 * done after every PHY reset.
1504 **/
1505static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1506{
1507 s32 ret_val = 0;
1508
1509 if (hw->mac.type != e1000_pch2lan)
1510 goto out;
1511
1512 /* Set MDIO slow mode before any other MDIO access */
1513 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1514
1515out:
1516 return ret_val;
1517}
1518
1519/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00001520 * e1000_lan_init_done_ich8lan - Check for PHY config completion
1521 * @hw: pointer to the HW structure
1522 *
1523 * Check the appropriate indication the MAC has finished configuring the
1524 * PHY after a software reset.
1525 **/
1526static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
1527{
1528 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
1529
1530 /* Wait for basic configuration completes before proceeding */
1531 do {
1532 data = er32(STATUS);
1533 data &= E1000_STATUS_LAN_INIT_DONE;
1534 udelay(100);
1535 } while ((!data) && --loop);
1536
1537 /*
1538 * If basic configuration is incomplete before the above loop
1539 * count reaches 0, loading the configuration from NVM will
1540 * leave the PHY in a bad state possibly resulting in no link.
1541 */
1542 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001543 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00001544
1545 /* Clear the Init Done bit for the next init event */
1546 data = er32(STATUS);
1547 data &= ~E1000_STATUS_LAN_INIT_DONE;
1548 ew32(STATUS, data);
1549}
1550
1551/**
Bruce Allane98cac42010-05-10 15:02:32 +00001552 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07001553 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07001554 **/
Bruce Allane98cac42010-05-10 15:02:32 +00001555static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001556{
Bruce Allanf523d212009-10-29 13:45:45 +00001557 s32 ret_val = 0;
1558 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001559
Bruce Allane98cac42010-05-10 15:02:32 +00001560 if (e1000_check_reset_block(hw))
1561 goto out;
Bruce Allanfc0c7762009-07-01 13:27:55 +00001562
Bruce Allanfddaa1af2010-01-13 01:52:49 +00001563 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00001564 switch (hw->mac.type) {
1565 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001566 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
1567 if (ret_val)
Bruce Allane98cac42010-05-10 15:02:32 +00001568 goto out;
1569 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001570 case e1000_pch2lan:
1571 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
1572 if (ret_val)
1573 goto out;
1574 break;
Bruce Allane98cac42010-05-10 15:02:32 +00001575 default:
1576 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00001577 }
1578
Bruce Allandb2932e2009-10-26 11:22:47 +00001579 /* Dummy read to clear the phy wakeup bit after lcd reset */
Bruce Alland3738bb2010-06-16 13:27:28 +00001580 if (hw->mac.type >= e1000_pchlan)
Bruce Allandb2932e2009-10-26 11:22:47 +00001581 e1e_rphy(hw, BM_WUC, &reg);
1582
Bruce Allanf523d212009-10-29 13:45:45 +00001583 /* Configure the LCD with the extended configuration region in NVM */
1584 ret_val = e1000_sw_lcd_config_ich8lan(hw);
1585 if (ret_val)
1586 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001587
Bruce Allanf523d212009-10-29 13:45:45 +00001588 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00001589 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001590
Bruce Allanf523d212009-10-29 13:45:45 +00001591out:
Bruce Allane98cac42010-05-10 15:02:32 +00001592 return ret_val;
1593}
1594
1595/**
1596 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
1597 * @hw: pointer to the HW structure
1598 *
1599 * Resets the PHY
1600 * This is a function pointer entry point called by drivers
1601 * or other shared routines.
1602 **/
1603static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
1604{
1605 s32 ret_val = 0;
1606
1607 ret_val = e1000e_phy_hw_reset_generic(hw);
1608 if (ret_val)
1609 goto out;
1610
1611 ret_val = e1000_post_phy_reset_ich8lan(hw);
1612
1613out:
1614 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001615}
1616
1617/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00001618 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1619 * @hw: pointer to the HW structure
1620 * @active: true to enable LPLU, false to disable
1621 *
1622 * Sets the LPLU state according to the active flag. For PCH, if OEM write
1623 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1624 * the phy speed. This function will manually set the LPLU bit and restart
1625 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
1626 * since it configures the same bit.
1627 **/
1628static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1629{
1630 s32 ret_val = 0;
1631 u16 oem_reg;
1632
1633 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
1634 if (ret_val)
1635 goto out;
1636
1637 if (active)
1638 oem_reg |= HV_OEM_BITS_LPLU;
1639 else
1640 oem_reg &= ~HV_OEM_BITS_LPLU;
1641
1642 oem_reg |= HV_OEM_BITS_RESTART_AN;
1643 ret_val = e1e_wphy(hw, HV_OEM_BITS, oem_reg);
1644
1645out:
1646 return ret_val;
1647}
1648
1649/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001650 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1651 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001652 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001653 *
1654 * Sets the LPLU D0 state according to the active flag. When
1655 * activating LPLU this function also disables smart speed
1656 * and vice versa. LPLU will not be activated unless the
1657 * device autonegotiation advertisement meets standards of
1658 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1659 * This is a function pointer entry point only called by
1660 * PHY setup routines.
1661 **/
1662static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1663{
1664 struct e1000_phy_info *phy = &hw->phy;
1665 u32 phy_ctrl;
1666 s32 ret_val = 0;
1667 u16 data;
1668
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001669 if (phy->type == e1000_phy_ife)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001670 return ret_val;
1671
1672 phy_ctrl = er32(PHY_CTRL);
1673
1674 if (active) {
1675 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
1676 ew32(PHY_CTRL, phy_ctrl);
1677
Bruce Allan60f12922009-07-01 13:28:14 +00001678 if (phy->type != e1000_phy_igp_3)
1679 return 0;
1680
Bruce Allanad680762008-03-28 09:15:03 -07001681 /*
1682 * Call gig speed drop workaround on LPLU before accessing
1683 * any PHY registers
1684 */
Bruce Allan60f12922009-07-01 13:28:14 +00001685 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001686 e1000e_gig_downshift_workaround_ich8lan(hw);
1687
1688 /* When LPLU is enabled, we should disable SmartSpeed */
1689 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1690 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1691 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1692 if (ret_val)
1693 return ret_val;
1694 } else {
1695 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
1696 ew32(PHY_CTRL, phy_ctrl);
1697
Bruce Allan60f12922009-07-01 13:28:14 +00001698 if (phy->type != e1000_phy_igp_3)
1699 return 0;
1700
Bruce Allanad680762008-03-28 09:15:03 -07001701 /*
1702 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001703 * during Dx states where the power conservation is most
1704 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001705 * SmartSpeed, so performance is maintained.
1706 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 if (phy->smart_speed == e1000_smart_speed_on) {
1708 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001709 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001710 if (ret_val)
1711 return ret_val;
1712
1713 data |= IGP01E1000_PSCFR_SMART_SPEED;
1714 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001715 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001716 if (ret_val)
1717 return ret_val;
1718 } else if (phy->smart_speed == e1000_smart_speed_off) {
1719 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001720 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721 if (ret_val)
1722 return ret_val;
1723
1724 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1725 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001726 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001727 if (ret_val)
1728 return ret_val;
1729 }
1730 }
1731
1732 return 0;
1733}
1734
1735/**
1736 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
1737 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001738 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001739 *
1740 * Sets the LPLU D3 state according to the active flag. When
1741 * activating LPLU this function also disables smart speed
1742 * and vice versa. LPLU will not be activated unless the
1743 * device autonegotiation advertisement meets standards of
1744 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1745 * This is a function pointer entry point only called by
1746 * PHY setup routines.
1747 **/
1748static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1749{
1750 struct e1000_phy_info *phy = &hw->phy;
1751 u32 phy_ctrl;
1752 s32 ret_val;
1753 u16 data;
1754
1755 phy_ctrl = er32(PHY_CTRL);
1756
1757 if (!active) {
1758 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
1759 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00001760
1761 if (phy->type != e1000_phy_igp_3)
1762 return 0;
1763
Bruce Allanad680762008-03-28 09:15:03 -07001764 /*
1765 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001766 * during Dx states where the power conservation is most
1767 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001768 * SmartSpeed, so performance is maintained.
1769 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001770 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07001771 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1772 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001773 if (ret_val)
1774 return ret_val;
1775
1776 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001777 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1778 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001779 if (ret_val)
1780 return ret_val;
1781 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07001782 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1783 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001784 if (ret_val)
1785 return ret_val;
1786
1787 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001788 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1789 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001790 if (ret_val)
1791 return ret_val;
1792 }
1793 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1794 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1795 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1796 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
1797 ew32(PHY_CTRL, phy_ctrl);
1798
Bruce Allan60f12922009-07-01 13:28:14 +00001799 if (phy->type != e1000_phy_igp_3)
1800 return 0;
1801
Bruce Allanad680762008-03-28 09:15:03 -07001802 /*
1803 * Call gig speed drop workaround on LPLU before accessing
1804 * any PHY registers
1805 */
Bruce Allan60f12922009-07-01 13:28:14 +00001806 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001807 e1000e_gig_downshift_workaround_ich8lan(hw);
1808
1809 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07001810 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001811 if (ret_val)
1812 return ret_val;
1813
1814 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001815 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001816 }
1817
1818 return 0;
1819}
1820
1821/**
Bruce Allanf4187b52008-08-26 18:36:50 -07001822 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
1823 * @hw: pointer to the HW structure
1824 * @bank: pointer to the variable that returns the active bank
1825 *
1826 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08001827 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07001828 **/
1829static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
1830{
Bruce Allane2434552008-11-21 17:02:41 -08001831 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07001832 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07001833 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
1834 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08001835 u8 sig_byte = 0;
1836 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001837
Bruce Allane2434552008-11-21 17:02:41 -08001838 switch (hw->mac.type) {
1839 case e1000_ich8lan:
1840 case e1000_ich9lan:
1841 eecd = er32(EECD);
1842 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
1843 E1000_EECD_SEC1VAL_VALID_MASK) {
1844 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07001845 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08001846 else
1847 *bank = 0;
1848
1849 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001850 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001851 e_dbg("Unable to determine valid NVM bank via EEC - "
Bruce Allane2434552008-11-21 17:02:41 -08001852 "reading flash signature\n");
1853 /* fall-thru */
1854 default:
1855 /* set bank to 0 in case flash read fails */
1856 *bank = 0;
1857
1858 /* Check bank 0 */
1859 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
1860 &sig_byte);
1861 if (ret_val)
1862 return ret_val;
1863 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1864 E1000_ICH_NVM_SIG_VALUE) {
1865 *bank = 0;
1866 return 0;
1867 }
1868
1869 /* Check bank 1 */
1870 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
1871 bank1_offset,
1872 &sig_byte);
1873 if (ret_val)
1874 return ret_val;
1875 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1876 E1000_ICH_NVM_SIG_VALUE) {
1877 *bank = 1;
1878 return 0;
1879 }
1880
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001881 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08001882 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07001883 }
1884
1885 return 0;
1886}
1887
1888/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001889 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
1890 * @hw: pointer to the HW structure
1891 * @offset: The offset (in bytes) of the word(s) to read.
1892 * @words: Size of data to read in words
1893 * @data: Pointer to the word(s) to read at offset.
1894 *
1895 * Reads a word(s) from the NVM using the flash access registers.
1896 **/
1897static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1898 u16 *data)
1899{
1900 struct e1000_nvm_info *nvm = &hw->nvm;
1901 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1902 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00001903 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07001904 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001905 u16 i, word;
1906
1907 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1908 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001909 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00001910 ret_val = -E1000_ERR_NVM;
1911 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001912 }
1913
Bruce Allan94d81862009-11-20 23:25:26 +00001914 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001915
Bruce Allanf4187b52008-08-26 18:36:50 -07001916 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00001917 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001918 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00001919 bank = 0;
1920 }
Bruce Allanf4187b52008-08-26 18:36:50 -07001921
1922 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001923 act_offset += offset;
1924
Bruce Allan148675a2009-08-07 07:41:56 +00001925 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001926 for (i = 0; i < words; i++) {
1927 if ((dev_spec->shadow_ram) &&
1928 (dev_spec->shadow_ram[offset+i].modified)) {
1929 data[i] = dev_spec->shadow_ram[offset+i].value;
1930 } else {
1931 ret_val = e1000_read_flash_word_ich8lan(hw,
1932 act_offset + i,
1933 &word);
1934 if (ret_val)
1935 break;
1936 data[i] = word;
1937 }
1938 }
1939
Bruce Allan94d81862009-11-20 23:25:26 +00001940 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001941
Bruce Allane2434552008-11-21 17:02:41 -08001942out:
1943 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001944 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08001945
Auke Kokbc7f75f2007-09-17 12:30:59 -07001946 return ret_val;
1947}
1948
1949/**
1950 * e1000_flash_cycle_init_ich8lan - Initialize flash
1951 * @hw: pointer to the HW structure
1952 *
1953 * This function does initial flash setup so that a new read/write/erase cycle
1954 * can be started.
1955 **/
1956static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
1957{
1958 union ich8_hws_flash_status hsfsts;
1959 s32 ret_val = -E1000_ERR_NVM;
1960 s32 i = 0;
1961
1962 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
1963
1964 /* Check if the flash descriptor is valid */
1965 if (hsfsts.hsf_status.fldesvalid == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001966 e_dbg("Flash descriptor invalid. "
Joe Perches2c73e1f2010-03-26 20:16:59 +00001967 "SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001968 return -E1000_ERR_NVM;
1969 }
1970
1971 /* Clear FCERR and DAEL in hw status by writing 1 */
1972 hsfsts.hsf_status.flcerr = 1;
1973 hsfsts.hsf_status.dael = 1;
1974
1975 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1976
Bruce Allanad680762008-03-28 09:15:03 -07001977 /*
1978 * Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07001979 * bit to check against, in order to start a new cycle or
1980 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08001981 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07001982 * indication whether a cycle is in progress or has been
1983 * completed.
1984 */
1985
1986 if (hsfsts.hsf_status.flcinprog == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07001987 /*
1988 * There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00001989 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07001990 * Begin by setting Flash Cycle Done.
1991 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001992 hsfsts.hsf_status.flcdone = 1;
1993 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
1994 ret_val = 0;
1995 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001996 /*
Bruce Allan5ff5b662009-12-01 15:51:11 +00001997 * Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07001998 * cycle has a chance to end before giving up.
1999 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002000 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
2001 hsfsts.regval = __er16flash(hw, ICH_FLASH_HSFSTS);
2002 if (hsfsts.hsf_status.flcinprog == 0) {
2003 ret_val = 0;
2004 break;
2005 }
2006 udelay(1);
2007 }
2008 if (ret_val == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07002009 /*
2010 * Successful in waiting for previous cycle to timeout,
2011 * now set the Flash Cycle Done.
2012 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002013 hsfsts.hsf_status.flcdone = 1;
2014 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2015 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002016 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002017 }
2018 }
2019
2020 return ret_val;
2021}
2022
2023/**
2024 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2025 * @hw: pointer to the HW structure
2026 * @timeout: maximum time to wait for completion
2027 *
2028 * This function starts a flash cycle and waits for its completion.
2029 **/
2030static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2031{
2032 union ich8_hws_flash_ctrl hsflctl;
2033 union ich8_hws_flash_status hsfsts;
2034 s32 ret_val = -E1000_ERR_NVM;
2035 u32 i = 0;
2036
2037 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2038 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2039 hsflctl.hsf_ctrl.flcgo = 1;
2040 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2041
2042 /* wait till FDONE bit is set to 1 */
2043 do {
2044 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2045 if (hsfsts.hsf_status.flcdone == 1)
2046 break;
2047 udelay(1);
2048 } while (i++ < timeout);
2049
2050 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
2051 return 0;
2052
2053 return ret_val;
2054}
2055
2056/**
2057 * e1000_read_flash_word_ich8lan - Read word from flash
2058 * @hw: pointer to the HW structure
2059 * @offset: offset to data location
2060 * @data: pointer to the location for storing the data
2061 *
2062 * Reads the flash word at offset into data. Offset is converted
2063 * to bytes before read.
2064 **/
2065static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2066 u16 *data)
2067{
2068 /* Must convert offset into bytes. */
2069 offset <<= 1;
2070
2071 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2072}
2073
2074/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002075 * e1000_read_flash_byte_ich8lan - Read byte from flash
2076 * @hw: pointer to the HW structure
2077 * @offset: The offset of the byte to read.
2078 * @data: Pointer to a byte to store the value read.
2079 *
2080 * Reads a single byte from the NVM using the flash access registers.
2081 **/
2082static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2083 u8 *data)
2084{
2085 s32 ret_val;
2086 u16 word = 0;
2087
2088 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2089 if (ret_val)
2090 return ret_val;
2091
2092 *data = (u8)word;
2093
2094 return 0;
2095}
2096
2097/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002098 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2099 * @hw: pointer to the HW structure
2100 * @offset: The offset (in bytes) of the byte or word to read.
2101 * @size: Size of data to read, 1=byte 2=word
2102 * @data: Pointer to the word to store the value read.
2103 *
2104 * Reads a byte or word from the NVM using the flash access registers.
2105 **/
2106static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2107 u8 size, u16 *data)
2108{
2109 union ich8_hws_flash_status hsfsts;
2110 union ich8_hws_flash_ctrl hsflctl;
2111 u32 flash_linear_addr;
2112 u32 flash_data = 0;
2113 s32 ret_val = -E1000_ERR_NVM;
2114 u8 count = 0;
2115
2116 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2117 return -E1000_ERR_NVM;
2118
2119 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2120 hw->nvm.flash_base_addr;
2121
2122 do {
2123 udelay(1);
2124 /* Steps */
2125 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2126 if (ret_val != 0)
2127 break;
2128
2129 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2130 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2131 hsflctl.hsf_ctrl.fldbcount = size - 1;
2132 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2133 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2134
2135 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2136
2137 ret_val = e1000_flash_cycle_ich8lan(hw,
2138 ICH_FLASH_READ_COMMAND_TIMEOUT);
2139
Bruce Allanad680762008-03-28 09:15:03 -07002140 /*
2141 * Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002142 * and try the whole sequence a few more times, else
2143 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002144 * least significant byte first msb to lsb
2145 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002146 if (ret_val == 0) {
2147 flash_data = er32flash(ICH_FLASH_FDATA0);
2148 if (size == 1) {
2149 *data = (u8)(flash_data & 0x000000FF);
2150 } else if (size == 2) {
2151 *data = (u16)(flash_data & 0x0000FFFF);
2152 }
2153 break;
2154 } else {
Bruce Allanad680762008-03-28 09:15:03 -07002155 /*
2156 * If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002157 * completely hosed, but if the error condition is
2158 * detected, it won't hurt to give it another try...
2159 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2160 */
2161 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2162 if (hsfsts.hsf_status.flcerr == 1) {
2163 /* Repeat for some time before giving up. */
2164 continue;
2165 } else if (hsfsts.hsf_status.flcdone == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002166 e_dbg("Timeout error - flash cycle "
Joe Perches2c73e1f2010-03-26 20:16:59 +00002167 "did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002168 break;
2169 }
2170 }
2171 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2172
2173 return ret_val;
2174}
2175
2176/**
2177 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2178 * @hw: pointer to the HW structure
2179 * @offset: The offset (in bytes) of the word(s) to write.
2180 * @words: Size of data to write in words
2181 * @data: Pointer to the word(s) to write at offset.
2182 *
2183 * Writes a byte or word to the NVM using the flash access registers.
2184 **/
2185static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2186 u16 *data)
2187{
2188 struct e1000_nvm_info *nvm = &hw->nvm;
2189 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190 u16 i;
2191
2192 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2193 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002194 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002195 return -E1000_ERR_NVM;
2196 }
2197
Bruce Allan94d81862009-11-20 23:25:26 +00002198 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002199
Auke Kokbc7f75f2007-09-17 12:30:59 -07002200 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002201 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002202 dev_spec->shadow_ram[offset+i].value = data[i];
2203 }
2204
Bruce Allan94d81862009-11-20 23:25:26 +00002205 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002206
Auke Kokbc7f75f2007-09-17 12:30:59 -07002207 return 0;
2208}
2209
2210/**
2211 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2212 * @hw: pointer to the HW structure
2213 *
2214 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2215 * which writes the checksum to the shadow ram. The changes in the shadow
2216 * ram are then committed to the EEPROM by processing each bank at a time
2217 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002218 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002219 * future writes.
2220 **/
2221static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2222{
2223 struct e1000_nvm_info *nvm = &hw->nvm;
2224 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002225 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002226 s32 ret_val;
2227 u16 data;
2228
2229 ret_val = e1000e_update_nvm_checksum_generic(hw);
2230 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002231 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232
2233 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002234 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002235
Bruce Allan94d81862009-11-20 23:25:26 +00002236 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002237
Bruce Allanad680762008-03-28 09:15:03 -07002238 /*
2239 * We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002240 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002241 * is going to be written
2242 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002243 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002244 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002245 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002246 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002247 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002248
2249 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002250 new_bank_offset = nvm->flash_bank_size;
2251 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002252 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002253 if (ret_val)
2254 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002255 } else {
2256 old_bank_offset = nvm->flash_bank_size;
2257 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002258 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002259 if (ret_val)
2260 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002261 }
2262
2263 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allanad680762008-03-28 09:15:03 -07002264 /*
2265 * Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002266 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002267 * in the shadow RAM
2268 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002269 if (dev_spec->shadow_ram[i].modified) {
2270 data = dev_spec->shadow_ram[i].value;
2271 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002272 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2273 old_bank_offset,
2274 &data);
2275 if (ret_val)
2276 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002277 }
2278
Bruce Allanad680762008-03-28 09:15:03 -07002279 /*
2280 * If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002281 * (15:14) are 11b until the commit has completed.
2282 * This will allow us to write 10b which indicates the
2283 * signature is valid. We want to do this after the write
2284 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002285 * while the write is still in progress
2286 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002287 if (i == E1000_ICH_NVM_SIG_WORD)
2288 data |= E1000_ICH_NVM_SIG_MASK;
2289
2290 /* Convert offset to bytes. */
2291 act_offset = (i + new_bank_offset) << 1;
2292
2293 udelay(100);
2294 /* Write the bytes to the new bank. */
2295 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2296 act_offset,
2297 (u8)data);
2298 if (ret_val)
2299 break;
2300
2301 udelay(100);
2302 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2303 act_offset + 1,
2304 (u8)(data >> 8));
2305 if (ret_val)
2306 break;
2307 }
2308
Bruce Allanad680762008-03-28 09:15:03 -07002309 /*
2310 * Don't bother writing the segment valid bits if sector
2311 * programming failed.
2312 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002314 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002315 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002316 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002317 }
2318
Bruce Allanad680762008-03-28 09:15:03 -07002319 /*
2320 * Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002321 * to 10b in word 0x13 , this can be done without an
2322 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002323 * and we need to change bit 14 to 0b
2324 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002326 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002327 if (ret_val)
2328 goto release;
2329
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 data &= 0xBFFF;
2331 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2332 act_offset * 2 + 1,
2333 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002334 if (ret_val)
2335 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002336
Bruce Allanad680762008-03-28 09:15:03 -07002337 /*
2338 * And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339 * its signature word (0x13) high_byte to 0b. This can be
2340 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002341 * to 1's. We can write 1's to 0's without an erase
2342 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002343 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2344 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002345 if (ret_val)
2346 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347
2348 /* Great! Everything worked, we can now clear the cached entries. */
2349 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002350 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002351 dev_spec->shadow_ram[i].value = 0xFFFF;
2352 }
2353
Bruce Allan9c5e2092010-05-10 15:00:31 +00002354release:
Bruce Allan94d81862009-11-20 23:25:26 +00002355 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356
Bruce Allanad680762008-03-28 09:15:03 -07002357 /*
2358 * Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359 * until after the next adapter reset.
2360 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002361 if (!ret_val) {
2362 e1000e_reload_nvm(hw);
2363 msleep(10);
2364 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365
Bruce Allane2434552008-11-21 17:02:41 -08002366out:
2367 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002368 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002369
Auke Kokbc7f75f2007-09-17 12:30:59 -07002370 return ret_val;
2371}
2372
2373/**
2374 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2375 * @hw: pointer to the HW structure
2376 *
2377 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2378 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
2379 * calculated, in which case we need to calculate the checksum and set bit 6.
2380 **/
2381static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2382{
2383 s32 ret_val;
2384 u16 data;
2385
Bruce Allanad680762008-03-28 09:15:03 -07002386 /*
2387 * Read 0x19 and check bit 6. If this bit is 0, the checksum
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388 * needs to be fixed. This bit is an indication that the NVM
2389 * was prepared by OEM software and did not calculate the
2390 * checksum...a likely scenario.
2391 */
2392 ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
2393 if (ret_val)
2394 return ret_val;
2395
2396 if ((data & 0x40) == 0) {
2397 data |= 0x40;
2398 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
2399 if (ret_val)
2400 return ret_val;
2401 ret_val = e1000e_update_nvm_checksum(hw);
2402 if (ret_val)
2403 return ret_val;
2404 }
2405
2406 return e1000e_validate_nvm_checksum_generic(hw);
2407}
2408
2409/**
Bruce Allan4a770352008-10-01 17:18:35 -07002410 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
2411 * @hw: pointer to the HW structure
2412 *
2413 * To prevent malicious write/erase of the NVM, set it to be read-only
2414 * so that the hardware ignores all write/erase cycles of the NVM via
2415 * the flash control registers. The shadow-ram copy of the NVM will
2416 * still be updated, however any updates to this copy will not stick
2417 * across driver reloads.
2418 **/
2419void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
2420{
Bruce Allanca15df52009-10-26 11:23:43 +00002421 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07002422 union ich8_flash_protected_range pr0;
2423 union ich8_hws_flash_status hsfsts;
2424 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07002425
Bruce Allan94d81862009-11-20 23:25:26 +00002426 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002427
2428 gfpreg = er32flash(ICH_FLASH_GFPREG);
2429
2430 /* Write-protect GbE Sector of NVM */
2431 pr0.regval = er32flash(ICH_FLASH_PR0);
2432 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
2433 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
2434 pr0.range.wpe = true;
2435 ew32flash(ICH_FLASH_PR0, pr0.regval);
2436
2437 /*
2438 * Lock down a subset of GbE Flash Control Registers, e.g.
2439 * PR0 to prevent the write-protection from being lifted.
2440 * Once FLOCKDN is set, the registers protected by it cannot
2441 * be written until FLOCKDN is cleared by a hardware reset.
2442 */
2443 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2444 hsfsts.hsf_status.flockdn = true;
2445 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2446
Bruce Allan94d81862009-11-20 23:25:26 +00002447 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002448}
2449
2450/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002451 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
2452 * @hw: pointer to the HW structure
2453 * @offset: The offset (in bytes) of the byte/word to read.
2454 * @size: Size of data to read, 1=byte 2=word
2455 * @data: The byte(s) to write to the NVM.
2456 *
2457 * Writes one/two bytes to the NVM using the flash access registers.
2458 **/
2459static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2460 u8 size, u16 data)
2461{
2462 union ich8_hws_flash_status hsfsts;
2463 union ich8_hws_flash_ctrl hsflctl;
2464 u32 flash_linear_addr;
2465 u32 flash_data = 0;
2466 s32 ret_val;
2467 u8 count = 0;
2468
2469 if (size < 1 || size > 2 || data > size * 0xff ||
2470 offset > ICH_FLASH_LINEAR_ADDR_MASK)
2471 return -E1000_ERR_NVM;
2472
2473 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2474 hw->nvm.flash_base_addr;
2475
2476 do {
2477 udelay(1);
2478 /* Steps */
2479 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2480 if (ret_val)
2481 break;
2482
2483 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2484 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2485 hsflctl.hsf_ctrl.fldbcount = size -1;
2486 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
2487 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2488
2489 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2490
2491 if (size == 1)
2492 flash_data = (u32)data & 0x00FF;
2493 else
2494 flash_data = (u32)data;
2495
2496 ew32flash(ICH_FLASH_FDATA0, flash_data);
2497
Bruce Allanad680762008-03-28 09:15:03 -07002498 /*
2499 * check if FCERR is set to 1 , if set to 1, clear it
2500 * and try the whole sequence a few more times else done
2501 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502 ret_val = e1000_flash_cycle_ich8lan(hw,
2503 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
2504 if (!ret_val)
2505 break;
2506
Bruce Allanad680762008-03-28 09:15:03 -07002507 /*
2508 * If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 * completely hosed, but if the error condition
2510 * is detected, it won't hurt to give it another
2511 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
2512 */
2513 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2514 if (hsfsts.hsf_status.flcerr == 1)
2515 /* Repeat for some time before giving up. */
2516 continue;
2517 if (hsfsts.hsf_status.flcdone == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002518 e_dbg("Timeout error - flash cycle "
Auke Kokbc7f75f2007-09-17 12:30:59 -07002519 "did not complete.");
2520 break;
2521 }
2522 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2523
2524 return ret_val;
2525}
2526
2527/**
2528 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
2529 * @hw: pointer to the HW structure
2530 * @offset: The index of the byte to read.
2531 * @data: The byte to write to the NVM.
2532 *
2533 * Writes a single byte to the NVM using the flash access registers.
2534 **/
2535static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2536 u8 data)
2537{
2538 u16 word = (u16)data;
2539
2540 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
2541}
2542
2543/**
2544 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
2545 * @hw: pointer to the HW structure
2546 * @offset: The offset of the byte to write.
2547 * @byte: The byte to write to the NVM.
2548 *
2549 * Writes a single byte to the NVM using the flash access registers.
2550 * Goes through a retry algorithm before giving up.
2551 **/
2552static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
2553 u32 offset, u8 byte)
2554{
2555 s32 ret_val;
2556 u16 program_retries;
2557
2558 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2559 if (!ret_val)
2560 return ret_val;
2561
2562 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002563 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002564 udelay(100);
2565 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2566 if (!ret_val)
2567 break;
2568 }
2569 if (program_retries == 100)
2570 return -E1000_ERR_NVM;
2571
2572 return 0;
2573}
2574
2575/**
2576 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
2577 * @hw: pointer to the HW structure
2578 * @bank: 0 for first bank, 1 for second bank, etc.
2579 *
2580 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
2581 * bank N is 4096 * N + flash_reg_addr.
2582 **/
2583static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
2584{
2585 struct e1000_nvm_info *nvm = &hw->nvm;
2586 union ich8_hws_flash_status hsfsts;
2587 union ich8_hws_flash_ctrl hsflctl;
2588 u32 flash_linear_addr;
2589 /* bank size is in 16bit words - adjust to bytes */
2590 u32 flash_bank_size = nvm->flash_bank_size * 2;
2591 s32 ret_val;
2592 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00002593 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002594
2595 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2596
Bruce Allanad680762008-03-28 09:15:03 -07002597 /*
2598 * Determine HW Sector size: Read BERASE bits of hw flash status
2599 * register
2600 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07002601 * consecutive sectors. The start index for the nth Hw sector
2602 * can be calculated as = bank * 4096 + n * 256
2603 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
2604 * The start index for the nth Hw sector can be calculated
2605 * as = bank * 4096
2606 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
2607 * (ich9 only, otherwise error condition)
2608 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
2609 */
2610 switch (hsfsts.hsf_status.berasesz) {
2611 case 0:
2612 /* Hw sector size 256 */
2613 sector_size = ICH_FLASH_SEG_SIZE_256;
2614 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
2615 break;
2616 case 1:
2617 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00002618 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002619 break;
2620 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00002621 sector_size = ICH_FLASH_SEG_SIZE_8K;
2622 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002623 break;
2624 case 3:
2625 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00002626 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002627 break;
2628 default:
2629 return -E1000_ERR_NVM;
2630 }
2631
2632 /* Start with the base address, then add the sector offset. */
2633 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00002634 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002635
2636 for (j = 0; j < iteration ; j++) {
2637 do {
2638 /* Steps */
2639 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2640 if (ret_val)
2641 return ret_val;
2642
Bruce Allanad680762008-03-28 09:15:03 -07002643 /*
2644 * Write a value 11 (block Erase) in Flash
2645 * Cycle field in hw flash control
2646 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002647 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2648 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
2649 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2650
Bruce Allanad680762008-03-28 09:15:03 -07002651 /*
2652 * Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07002653 * block into Flash Linear address field in Flash
2654 * Address.
2655 */
2656 flash_linear_addr += (j * sector_size);
2657 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2658
2659 ret_val = e1000_flash_cycle_ich8lan(hw,
2660 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
2661 if (ret_val == 0)
2662 break;
2663
Bruce Allanad680762008-03-28 09:15:03 -07002664 /*
2665 * Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002666 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07002667 * a few more times else Done
2668 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2670 if (hsfsts.hsf_status.flcerr == 1)
Bruce Allanad680762008-03-28 09:15:03 -07002671 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002672 continue;
2673 else if (hsfsts.hsf_status.flcdone == 0)
2674 return ret_val;
2675 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
2676 }
2677
2678 return 0;
2679}
2680
2681/**
2682 * e1000_valid_led_default_ich8lan - Set the default LED settings
2683 * @hw: pointer to the HW structure
2684 * @data: Pointer to the LED settings
2685 *
2686 * Reads the LED default settings from the NVM to data. If the NVM LED
2687 * settings is all 0's or F's, set the LED default to a valid LED default
2688 * setting.
2689 **/
2690static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
2691{
2692 s32 ret_val;
2693
2694 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
2695 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002696 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697 return ret_val;
2698 }
2699
2700 if (*data == ID_LED_RESERVED_0000 ||
2701 *data == ID_LED_RESERVED_FFFF)
2702 *data = ID_LED_DEFAULT_ICH8LAN;
2703
2704 return 0;
2705}
2706
2707/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002708 * e1000_id_led_init_pchlan - store LED configurations
2709 * @hw: pointer to the HW structure
2710 *
2711 * PCH does not control LEDs via the LEDCTL register, rather it uses
2712 * the PHY LED configuration register.
2713 *
2714 * PCH also does not have an "always on" or "always off" mode which
2715 * complicates the ID feature. Instead of using the "on" mode to indicate
2716 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init()),
2717 * use "link_up" mode. The LEDs will still ID on request if there is no
2718 * link based on logic in e1000_led_[on|off]_pchlan().
2719 **/
2720static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
2721{
2722 struct e1000_mac_info *mac = &hw->mac;
2723 s32 ret_val;
2724 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
2725 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
2726 u16 data, i, temp, shift;
2727
2728 /* Get default ID LED modes */
2729 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
2730 if (ret_val)
2731 goto out;
2732
2733 mac->ledctl_default = er32(LEDCTL);
2734 mac->ledctl_mode1 = mac->ledctl_default;
2735 mac->ledctl_mode2 = mac->ledctl_default;
2736
2737 for (i = 0; i < 4; i++) {
2738 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
2739 shift = (i * 5);
2740 switch (temp) {
2741 case ID_LED_ON1_DEF2:
2742 case ID_LED_ON1_ON2:
2743 case ID_LED_ON1_OFF2:
2744 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2745 mac->ledctl_mode1 |= (ledctl_on << shift);
2746 break;
2747 case ID_LED_OFF1_DEF2:
2748 case ID_LED_OFF1_ON2:
2749 case ID_LED_OFF1_OFF2:
2750 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2751 mac->ledctl_mode1 |= (ledctl_off << shift);
2752 break;
2753 default:
2754 /* Do nothing */
2755 break;
2756 }
2757 switch (temp) {
2758 case ID_LED_DEF1_ON2:
2759 case ID_LED_ON1_ON2:
2760 case ID_LED_OFF1_ON2:
2761 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2762 mac->ledctl_mode2 |= (ledctl_on << shift);
2763 break;
2764 case ID_LED_DEF1_OFF2:
2765 case ID_LED_ON1_OFF2:
2766 case ID_LED_OFF1_OFF2:
2767 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2768 mac->ledctl_mode2 |= (ledctl_off << shift);
2769 break;
2770 default:
2771 /* Do nothing */
2772 break;
2773 }
2774 }
2775
2776out:
2777 return ret_val;
2778}
2779
2780/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002781 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
2782 * @hw: pointer to the HW structure
2783 *
2784 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
2785 * register, so the the bus width is hard coded.
2786 **/
2787static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
2788{
2789 struct e1000_bus_info *bus = &hw->bus;
2790 s32 ret_val;
2791
2792 ret_val = e1000e_get_bus_info_pcie(hw);
2793
Bruce Allanad680762008-03-28 09:15:03 -07002794 /*
2795 * ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07002796 * a configuration space, but do not contain
2797 * PCI Express Capability registers, so bus width
2798 * must be hardcoded.
2799 */
2800 if (bus->width == e1000_bus_width_unknown)
2801 bus->width = e1000_bus_width_pcie_x1;
2802
2803 return ret_val;
2804}
2805
2806/**
2807 * e1000_reset_hw_ich8lan - Reset the hardware
2808 * @hw: pointer to the HW structure
2809 *
2810 * Does a full reset of the hardware which includes a reset of the PHY and
2811 * MAC.
2812 **/
2813static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2814{
Bruce Allan1d5846b2009-10-29 13:46:05 +00002815 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allandb2932e2009-10-26 11:22:47 +00002816 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002817 u32 ctrl, icr, kab;
2818 s32 ret_val;
2819
Bruce Allanad680762008-03-28 09:15:03 -07002820 /*
2821 * Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07002822 * on the last TLP read/write transaction when MAC is reset.
2823 */
2824 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00002825 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002826 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002827
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002828 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 ew32(IMC, 0xffffffff);
2830
Bruce Allanad680762008-03-28 09:15:03 -07002831 /*
2832 * Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833 * any pending transactions to complete before we hit the MAC
2834 * with the global reset.
2835 */
2836 ew32(RCTL, 0);
2837 ew32(TCTL, E1000_TCTL_PSP);
2838 e1e_flush();
2839
2840 msleep(10);
2841
2842 /* Workaround for ICH8 bit corruption issue in FIFO memory */
2843 if (hw->mac.type == e1000_ich8lan) {
2844 /* Set Tx and Rx buffer allocation to 8k apiece. */
2845 ew32(PBA, E1000_PBA_8K);
2846 /* Set Packet Buffer Size to 16k. */
2847 ew32(PBS, E1000_PBS_16K);
2848 }
2849
Bruce Allan1d5846b2009-10-29 13:46:05 +00002850 if (hw->mac.type == e1000_pchlan) {
2851 /* Save the NVM K1 bit setting*/
2852 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &reg);
2853 if (ret_val)
2854 return ret_val;
2855
2856 if (reg & E1000_NVM_K1_ENABLE)
2857 dev_spec->nvm_k1_enabled = true;
2858 else
2859 dev_spec->nvm_k1_enabled = false;
2860 }
2861
Auke Kokbc7f75f2007-09-17 12:30:59 -07002862 ctrl = er32(CTRL);
2863
2864 if (!e1000_check_reset_block(hw)) {
Bruce Allanad680762008-03-28 09:15:03 -07002865 /*
Bruce Allane98cac42010-05-10 15:02:32 +00002866 * Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867 * time to make sure the interface between MAC and the
2868 * external PHY is reset.
2869 */
2870 ctrl |= E1000_CTRL_PHY_RST;
2871 }
2872 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002873 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002874 ew32(CTRL, (ctrl | E1000_CTRL_RST));
2875 msleep(20);
2876
Bruce Allanfc0c7762009-07-01 13:27:55 +00002877 if (!ret_val)
Jeff Kirsher30bb0e02008-12-11 21:28:11 -08002878 e1000_release_swflag_ich8lan(hw);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07002879
Bruce Allane98cac42010-05-10 15:02:32 +00002880 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00002881 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00002882 if (ret_val)
2883 goto out;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002884
Bruce Allane98cac42010-05-10 15:02:32 +00002885 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00002886 if (ret_val)
2887 goto out;
2888 }
Bruce Allane98cac42010-05-10 15:02:32 +00002889
Bruce Allan7d3cabb2009-07-01 13:29:08 +00002890 /*
2891 * For PCH, this write will make sure that any noise
2892 * will be detected as a CRC error and be dropped rather than show up
2893 * as a bad packet to the DMA engine.
2894 */
2895 if (hw->mac.type == e1000_pchlan)
2896 ew32(CRC_OFFSET, 0x65656565);
2897
Auke Kokbc7f75f2007-09-17 12:30:59 -07002898 ew32(IMC, 0xffffffff);
2899 icr = er32(ICR);
2900
2901 kab = er32(KABGTXD);
2902 kab |= E1000_KABGTXD_BGSQLBIAS;
2903 ew32(KABGTXD, kab);
2904
Bruce Allanf523d212009-10-29 13:45:45 +00002905out:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 return ret_val;
2907}
2908
2909/**
2910 * e1000_init_hw_ich8lan - Initialize the hardware
2911 * @hw: pointer to the HW structure
2912 *
2913 * Prepares the hardware for transmit and receive by doing the following:
2914 * - initialize hardware bits
2915 * - initialize LED identification
2916 * - setup receive address registers
2917 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08002918 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07002919 * - clear statistics
2920 **/
2921static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
2922{
2923 struct e1000_mac_info *mac = &hw->mac;
2924 u32 ctrl_ext, txdctl, snoop;
2925 s32 ret_val;
2926 u16 i;
2927
2928 e1000_initialize_hw_bits_ich8lan(hw);
2929
2930 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00002931 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00002932 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002933 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00002934 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002935
2936 /* Setup the receive address. */
2937 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
2938
2939 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002940 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002941 for (i = 0; i < mac->mta_reg_count; i++)
2942 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
2943
Bruce Allanfc0c7762009-07-01 13:27:55 +00002944 /*
2945 * The 82578 Rx buffer will stall if wakeup is enabled in host and
2946 * the ME. Reading the BM_WUC register will clear the host wakeup bit.
2947 * Reset the phy after disabling host wakeup to reset the Rx buffer.
2948 */
2949 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan94d81862009-11-20 23:25:26 +00002950 hw->phy.ops.read_reg(hw, BM_WUC, &i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002951 ret_val = e1000_phy_hw_reset_ich8lan(hw);
2952 if (ret_val)
2953 return ret_val;
2954 }
2955
Auke Kokbc7f75f2007-09-17 12:30:59 -07002956 /* Setup link and flow control */
2957 ret_val = e1000_setup_link_ich8lan(hw);
2958
2959 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002960 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2962 E1000_TXDCTL_FULL_TX_DESC_WB;
2963 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2964 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002965 ew32(TXDCTL(0), txdctl);
2966 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002967 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2968 E1000_TXDCTL_FULL_TX_DESC_WB;
2969 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2970 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07002971 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002972
Bruce Allanad680762008-03-28 09:15:03 -07002973 /*
2974 * ICH8 has opposite polarity of no_snoop bits.
2975 * By default, we should use snoop behavior.
2976 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002977 if (mac->type == e1000_ich8lan)
2978 snoop = PCIE_ICH8_SNOOP_ALL;
2979 else
2980 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
2981 e1000e_set_pcie_no_snoop(hw, snoop);
2982
2983 ctrl_ext = er32(CTRL_EXT);
2984 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2985 ew32(CTRL_EXT, ctrl_ext);
2986
Bruce Allanad680762008-03-28 09:15:03 -07002987 /*
2988 * Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07002989 * important that we do this after we have tried to establish link
2990 * because the symbol error count will increment wildly if there
2991 * is no link.
2992 */
2993 e1000_clear_hw_cntrs_ich8lan(hw);
2994
2995 return 0;
2996}
2997/**
2998 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
2999 * @hw: pointer to the HW structure
3000 *
3001 * Sets/Clears required hardware bits necessary for correctly setting up the
3002 * hardware for transmit and receive.
3003 **/
3004static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3005{
3006 u32 reg;
3007
3008 /* Extended Device Control */
3009 reg = er32(CTRL_EXT);
3010 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003011 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3012 if (hw->mac.type >= e1000_pchlan)
3013 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014 ew32(CTRL_EXT, reg);
3015
3016 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003017 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003018 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003019 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003020
3021 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003022 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003023 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003024 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003025
3026 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003027 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003028 if (hw->mac.type == e1000_ich8lan)
3029 reg |= (1 << 28) | (1 << 29);
3030 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003031 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003032
3033 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003034 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003035 if (er32(TCTL) & E1000_TCTL_MULR)
3036 reg &= ~(1 << 28);
3037 else
3038 reg |= (1 << 28);
3039 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003040 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003041
3042 /* Device Status */
3043 if (hw->mac.type == e1000_ich8lan) {
3044 reg = er32(STATUS);
3045 reg &= ~(1 << 31);
3046 ew32(STATUS, reg);
3047 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003048
3049 /*
3050 * work-around descriptor data corruption issue during nfs v2 udp
3051 * traffic, just disable the nfs filtering capability
3052 */
3053 reg = er32(RFCTL);
3054 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
3055 ew32(RFCTL, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003056}
3057
3058/**
3059 * e1000_setup_link_ich8lan - Setup flow control and link settings
3060 * @hw: pointer to the HW structure
3061 *
3062 * Determines which flow control settings to use, then configures flow
3063 * control. Calls the appropriate media-specific link configuration
3064 * function. Assuming the adapter has a valid link partner, a valid link
3065 * should be established. Assumes the hardware has previously been reset
3066 * and the transmitter and receiver are not enabled.
3067 **/
3068static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3069{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003070 s32 ret_val;
3071
3072 if (e1000_check_reset_block(hw))
3073 return 0;
3074
Bruce Allanad680762008-03-28 09:15:03 -07003075 /*
3076 * ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003077 * the default flow control setting, so we explicitly
3078 * set it to full.
3079 */
Bruce Allan37289d92009-06-02 11:29:37 +00003080 if (hw->fc.requested_mode == e1000_fc_default) {
3081 /* Workaround h/w hang when Tx flow control enabled */
3082 if (hw->mac.type == e1000_pchlan)
3083 hw->fc.requested_mode = e1000_fc_rx_pause;
3084 else
3085 hw->fc.requested_mode = e1000_fc_full;
3086 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003087
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003088 /*
3089 * Save off the requested flow control mode for use later. Depending
3090 * on the link partner's capabilities, we may or may not use this mode.
3091 */
3092 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003094 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003095 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096
3097 /* Continue to configure the copper link. */
3098 ret_val = e1000_setup_copper_link_ich8lan(hw);
3099 if (ret_val)
3100 return ret_val;
3101
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003102 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003103 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003104 (hw->phy.type == e1000_phy_82579) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003105 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003106 ew32(FCRTV_PCH, hw->fc.refresh_time);
3107
Bruce Allan94d81862009-11-20 23:25:26 +00003108 ret_val = hw->phy.ops.write_reg(hw,
Bruce Allana4f58f52009-06-02 11:29:18 +00003109 PHY_REG(BM_PORT_CTRL_PAGE, 27),
3110 hw->fc.pause_time);
3111 if (ret_val)
3112 return ret_val;
3113 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003114
3115 return e1000e_set_fc_watermarks(hw);
3116}
3117
3118/**
3119 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3120 * @hw: pointer to the HW structure
3121 *
3122 * Configures the kumeran interface to the PHY to wait the appropriate time
3123 * when polling the PHY, then call the generic setup_copper_link to finish
3124 * configuring the copper link.
3125 **/
3126static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3127{
3128 u32 ctrl;
3129 s32 ret_val;
3130 u16 reg_data;
3131
3132 ctrl = er32(CTRL);
3133 ctrl |= E1000_CTRL_SLU;
3134 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3135 ew32(CTRL, ctrl);
3136
Bruce Allanad680762008-03-28 09:15:03 -07003137 /*
3138 * Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003140 * this fixes erroneous timeouts at 10Mbps.
3141 */
Bruce Allan07818952009-12-08 07:28:01 +00003142 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003143 if (ret_val)
3144 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003145 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3146 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003147 if (ret_val)
3148 return ret_val;
3149 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003150 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3151 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003152 if (ret_val)
3153 return ret_val;
3154
Bruce Allana4f58f52009-06-02 11:29:18 +00003155 switch (hw->phy.type) {
3156 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003157 ret_val = e1000e_copper_link_setup_igp(hw);
3158 if (ret_val)
3159 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003160 break;
3161 case e1000_phy_bm:
3162 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003163 ret_val = e1000e_copper_link_setup_m88(hw);
3164 if (ret_val)
3165 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003166 break;
3167 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003168 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00003169 ret_val = e1000_copper_link_setup_82577(hw);
3170 if (ret_val)
3171 return ret_val;
3172 break;
3173 case e1000_phy_ife:
Bruce Allan94d81862009-11-20 23:25:26 +00003174 ret_val = hw->phy.ops.read_reg(hw, IFE_PHY_MDIX_CONTROL,
Bruce Allana4f58f52009-06-02 11:29:18 +00003175 &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003176 if (ret_val)
3177 return ret_val;
3178
3179 reg_data &= ~IFE_PMC_AUTO_MDIX;
3180
3181 switch (hw->phy.mdix) {
3182 case 1:
3183 reg_data &= ~IFE_PMC_FORCE_MDIX;
3184 break;
3185 case 2:
3186 reg_data |= IFE_PMC_FORCE_MDIX;
3187 break;
3188 case 0:
3189 default:
3190 reg_data |= IFE_PMC_AUTO_MDIX;
3191 break;
3192 }
Bruce Allan94d81862009-11-20 23:25:26 +00003193 ret_val = hw->phy.ops.write_reg(hw, IFE_PHY_MDIX_CONTROL,
Bruce Allana4f58f52009-06-02 11:29:18 +00003194 reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003195 if (ret_val)
3196 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003197 break;
3198 default:
3199 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003200 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003201 return e1000e_setup_copper_link(hw);
3202}
3203
3204/**
3205 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3206 * @hw: pointer to the HW structure
3207 * @speed: pointer to store current link speed
3208 * @duplex: pointer to store the current link duplex
3209 *
Bruce Allanad680762008-03-28 09:15:03 -07003210 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003211 * information and then calls the Kumeran lock loss workaround for links at
3212 * gigabit speeds.
3213 **/
3214static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3215 u16 *duplex)
3216{
3217 s32 ret_val;
3218
3219 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3220 if (ret_val)
3221 return ret_val;
3222
3223 if ((hw->mac.type == e1000_ich8lan) &&
3224 (hw->phy.type == e1000_phy_igp_3) &&
3225 (*speed == SPEED_1000)) {
3226 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3227 }
3228
3229 return ret_val;
3230}
3231
3232/**
3233 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3234 * @hw: pointer to the HW structure
3235 *
3236 * Work-around for 82566 Kumeran PCS lock loss:
3237 * On link status change (i.e. PCI reset, speed change) and link is up and
3238 * speed is gigabit-
3239 * 0) if workaround is optionally disabled do nothing
3240 * 1) wait 1ms for Kumeran link to come up
3241 * 2) check Kumeran Diagnostic register PCS lock loss bit
3242 * 3) if not set the link is locked (all is good), otherwise...
3243 * 4) reset the PHY
3244 * 5) repeat up to 10 times
3245 * Note: this is only called for IGP3 copper when speed is 1gb.
3246 **/
3247static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3248{
3249 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3250 u32 phy_ctrl;
3251 s32 ret_val;
3252 u16 i, data;
3253 bool link;
3254
3255 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3256 return 0;
3257
Bruce Allanad680762008-03-28 09:15:03 -07003258 /*
3259 * Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003260 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003261 * stability
3262 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003263 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3264 if (!link)
3265 return 0;
3266
3267 for (i = 0; i < 10; i++) {
3268 /* read once to clear */
3269 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3270 if (ret_val)
3271 return ret_val;
3272 /* and again to get new status */
3273 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3274 if (ret_val)
3275 return ret_val;
3276
3277 /* check for PCS lock */
3278 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3279 return 0;
3280
3281 /* Issue PHY reset */
3282 e1000_phy_hw_reset(hw);
3283 mdelay(5);
3284 }
3285 /* Disable GigE link negotiation */
3286 phy_ctrl = er32(PHY_CTRL);
3287 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3288 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3289 ew32(PHY_CTRL, phy_ctrl);
3290
Bruce Allanad680762008-03-28 09:15:03 -07003291 /*
3292 * Call gig speed drop workaround on Gig disable before accessing
3293 * any PHY registers
3294 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003295 e1000e_gig_downshift_workaround_ich8lan(hw);
3296
3297 /* unable to acquire PCS lock */
3298 return -E1000_ERR_PHY;
3299}
3300
3301/**
Bruce Allanad680762008-03-28 09:15:03 -07003302 * e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003303 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003304 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003305 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003306 * If ICH8, set the current Kumeran workaround state (enabled - true
3307 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003308 **/
3309void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3310 bool state)
3311{
3312 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3313
3314 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003315 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003316 return;
3317 }
3318
3319 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3320}
3321
3322/**
3323 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3324 * @hw: pointer to the HW structure
3325 *
3326 * Workaround for 82566 power-down on D3 entry:
3327 * 1) disable gigabit link
3328 * 2) write VR power-down enable
3329 * 3) read it back
3330 * Continue if successful, else issue LCD reset and repeat
3331 **/
3332void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3333{
3334 u32 reg;
3335 u16 data;
3336 u8 retry = 0;
3337
3338 if (hw->phy.type != e1000_phy_igp_3)
3339 return;
3340
3341 /* Try the workaround twice (if needed) */
3342 do {
3343 /* Disable link */
3344 reg = er32(PHY_CTRL);
3345 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3346 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3347 ew32(PHY_CTRL, reg);
3348
Bruce Allanad680762008-03-28 09:15:03 -07003349 /*
3350 * Call gig speed drop workaround on Gig disable before
3351 * accessing any PHY registers
3352 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003353 if (hw->mac.type == e1000_ich8lan)
3354 e1000e_gig_downshift_workaround_ich8lan(hw);
3355
3356 /* Write VR power-down enable */
3357 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3358 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3359 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
3360
3361 /* Read it back and test */
3362 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3363 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3364 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
3365 break;
3366
3367 /* Issue PHY reset and repeat at most one more time */
3368 reg = er32(CTRL);
3369 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
3370 retry++;
3371 } while (retry);
3372}
3373
3374/**
3375 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
3376 * @hw: pointer to the HW structure
3377 *
3378 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08003379 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07003380 * 1) Set Kumeran Near-end loopback
3381 * 2) Clear Kumeran Near-end loopback
3382 * Should only be called for ICH8[m] devices with IGP_3 Phy.
3383 **/
3384void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
3385{
3386 s32 ret_val;
3387 u16 reg_data;
3388
3389 if ((hw->mac.type != e1000_ich8lan) ||
3390 (hw->phy.type != e1000_phy_igp_3))
3391 return;
3392
3393 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3394 &reg_data);
3395 if (ret_val)
3396 return;
3397 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
3398 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3399 reg_data);
3400 if (ret_val)
3401 return;
3402 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
3403 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3404 reg_data);
3405}
3406
3407/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003408 * e1000e_disable_gig_wol_ich8lan - disable gig during WoL
3409 * @hw: pointer to the HW structure
3410 *
3411 * During S0 to Sx transition, it is possible the link remains at gig
3412 * instead of negotiating to a lower speed. Before going to Sx, set
3413 * 'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
3414 * to a lower speed.
3415 *
Bruce Allana4f58f52009-06-02 11:29:18 +00003416 * Should only be called for applicable parts.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003417 **/
3418void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
3419{
3420 u32 phy_ctrl;
3421
Bruce Allana4f58f52009-06-02 11:29:18 +00003422 switch (hw->mac.type) {
Bruce Allan9e135a22009-12-01 15:50:31 +00003423 case e1000_ich8lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00003424 case e1000_ich9lan:
3425 case e1000_ich10lan:
3426 case e1000_pchlan:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003427 phy_ctrl = er32(PHY_CTRL);
3428 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
3429 E1000_PHY_CTRL_GBE_DISABLE;
3430 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00003431
Bruce Allana4f58f52009-06-02 11:29:18 +00003432 if (hw->mac.type == e1000_pchlan)
Bruce Allan74eee2e2009-10-22 21:22:18 -07003433 e1000_phy_hw_reset_ich8lan(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00003434 default:
3435 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003436 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003437}
3438
3439/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003440 * e1000_cleanup_led_ich8lan - Restore the default LED operation
3441 * @hw: pointer to the HW structure
3442 *
3443 * Return the LED back to the default configuration.
3444 **/
3445static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
3446{
3447 if (hw->phy.type == e1000_phy_ife)
3448 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
3449
3450 ew32(LEDCTL, hw->mac.ledctl_default);
3451 return 0;
3452}
3453
3454/**
Auke Kok489815c2008-02-21 15:11:07 -08003455 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07003456 * @hw: pointer to the HW structure
3457 *
Auke Kok489815c2008-02-21 15:11:07 -08003458 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003459 **/
3460static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
3461{
3462 if (hw->phy.type == e1000_phy_ife)
3463 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3464 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
3465
3466 ew32(LEDCTL, hw->mac.ledctl_mode2);
3467 return 0;
3468}
3469
3470/**
Auke Kok489815c2008-02-21 15:11:07 -08003471 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07003472 * @hw: pointer to the HW structure
3473 *
Auke Kok489815c2008-02-21 15:11:07 -08003474 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003475 **/
3476static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
3477{
3478 if (hw->phy.type == e1000_phy_ife)
3479 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3480 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
3481
3482 ew32(LEDCTL, hw->mac.ledctl_mode1);
3483 return 0;
3484}
3485
3486/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003487 * e1000_setup_led_pchlan - Configures SW controllable LED
3488 * @hw: pointer to the HW structure
3489 *
3490 * This prepares the SW controllable LED for use.
3491 **/
3492static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
3493{
Bruce Allan94d81862009-11-20 23:25:26 +00003494 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
Bruce Allana4f58f52009-06-02 11:29:18 +00003495 (u16)hw->mac.ledctl_mode1);
3496}
3497
3498/**
3499 * e1000_cleanup_led_pchlan - Restore the default LED operation
3500 * @hw: pointer to the HW structure
3501 *
3502 * Return the LED back to the default configuration.
3503 **/
3504static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
3505{
Bruce Allan94d81862009-11-20 23:25:26 +00003506 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
Bruce Allana4f58f52009-06-02 11:29:18 +00003507 (u16)hw->mac.ledctl_default);
3508}
3509
3510/**
3511 * e1000_led_on_pchlan - Turn LEDs on
3512 * @hw: pointer to the HW structure
3513 *
3514 * Turn on the LEDs.
3515 **/
3516static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
3517{
3518 u16 data = (u16)hw->mac.ledctl_mode2;
3519 u32 i, led;
3520
3521 /*
3522 * If no link, then turn LED on by setting the invert bit
3523 * for each LED that's mode is "link_up" in ledctl_mode2.
3524 */
3525 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3526 for (i = 0; i < 3; i++) {
3527 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3528 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3529 E1000_LEDCTL_MODE_LINK_UP)
3530 continue;
3531 if (led & E1000_PHY_LED0_IVRT)
3532 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3533 else
3534 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3535 }
3536 }
3537
Bruce Allan94d81862009-11-20 23:25:26 +00003538 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003539}
3540
3541/**
3542 * e1000_led_off_pchlan - Turn LEDs off
3543 * @hw: pointer to the HW structure
3544 *
3545 * Turn off the LEDs.
3546 **/
3547static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
3548{
3549 u16 data = (u16)hw->mac.ledctl_mode1;
3550 u32 i, led;
3551
3552 /*
3553 * If no link, then turn LED off by clearing the invert bit
3554 * for each LED that's mode is "link_up" in ledctl_mode1.
3555 */
3556 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3557 for (i = 0; i < 3; i++) {
3558 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3559 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3560 E1000_LEDCTL_MODE_LINK_UP)
3561 continue;
3562 if (led & E1000_PHY_LED0_IVRT)
3563 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3564 else
3565 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3566 }
3567 }
3568
Bruce Allan94d81862009-11-20 23:25:26 +00003569 return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003570}
3571
3572/**
Bruce Allane98cac42010-05-10 15:02:32 +00003573 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07003574 * @hw: pointer to the HW structure
3575 *
Bruce Allane98cac42010-05-10 15:02:32 +00003576 * Read appropriate register for the config done bit for completion status
3577 * and configure the PHY through s/w for EEPROM-less parts.
3578 *
3579 * NOTE: some silicon which is EEPROM-less will fail trying to read the
3580 * config done bit, so only an error is logged and continues. If we were
3581 * to return with error, EEPROM-less silicon would not be able to be reset
3582 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07003583 **/
3584static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
3585{
Bruce Allane98cac42010-05-10 15:02:32 +00003586 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07003587 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00003588 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003589
Bruce Allanf4187b52008-08-26 18:36:50 -07003590 e1000e_get_cfg_done(hw);
3591
Bruce Allane98cac42010-05-10 15:02:32 +00003592 /* Wait for indication from h/w that it has completed basic config */
3593 if (hw->mac.type >= e1000_ich10lan) {
3594 e1000_lan_init_done_ich8lan(hw);
3595 } else {
3596 ret_val = e1000e_get_auto_rd_done(hw);
3597 if (ret_val) {
3598 /*
3599 * When auto config read does not complete, do not
3600 * return with an error. This can happen in situations
3601 * where there is no eeprom and prevents getting link.
3602 */
3603 e_dbg("Auto Read Done did not complete\n");
3604 ret_val = 0;
3605 }
3606 }
3607
3608 /* Clear PHY Reset Asserted bit */
3609 status = er32(STATUS);
3610 if (status & E1000_STATUS_PHYRA)
3611 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
3612 else
3613 e_dbg("PHY Reset Asserted not set - needs delay\n");
3614
Bruce Allanf4187b52008-08-26 18:36:50 -07003615 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00003616 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allanf4187b52008-08-26 18:36:50 -07003617 if (((er32(EECD) & E1000_EECD_PRES) == 0) &&
3618 (hw->phy.type == e1000_phy_igp_3)) {
3619 e1000e_phy_init_script_igp3(hw);
3620 }
3621 } else {
3622 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
3623 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003624 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00003625 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07003626 }
3627 }
3628
Bruce Allane98cac42010-05-10 15:02:32 +00003629 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07003630}
3631
3632/**
Bruce Allan17f208d2009-12-01 15:47:22 +00003633 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
3634 * @hw: pointer to the HW structure
3635 *
3636 * In the case of a PHY power down to save power, or to turn off link during a
3637 * driver unload, or wake on lan is not enabled, remove the link.
3638 **/
3639static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
3640{
3641 /* If the management interface is not enabled, then power down */
3642 if (!(hw->mac.ops.check_mng_mode(hw) ||
3643 hw->phy.ops.check_reset_block(hw)))
3644 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00003645}
3646
3647/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003648 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
3649 * @hw: pointer to the HW structure
3650 *
3651 * Clears hardware counters specific to the silicon family and calls
3652 * clear_hw_cntrs_generic to clear all general purpose counters.
3653 **/
3654static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
3655{
Bruce Allana4f58f52009-06-02 11:29:18 +00003656 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003657
3658 e1000e_clear_hw_cntrs_base(hw);
3659
Bruce Allan99673d92009-11-20 23:27:21 +00003660 er32(ALGNERRC);
3661 er32(RXERRC);
3662 er32(TNCRS);
3663 er32(CEXTERR);
3664 er32(TSCTC);
3665 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003666
Bruce Allan99673d92009-11-20 23:27:21 +00003667 er32(MGTPRC);
3668 er32(MGTPDC);
3669 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003670
Bruce Allan99673d92009-11-20 23:27:21 +00003671 er32(IAC);
3672 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003673
Bruce Allana4f58f52009-06-02 11:29:18 +00003674 /* Clear PHY statistics registers */
3675 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003676 (hw->phy.type == e1000_phy_82579) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003677 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan94d81862009-11-20 23:25:26 +00003678 hw->phy.ops.read_reg(hw, HV_SCC_UPPER, &phy_data);
3679 hw->phy.ops.read_reg(hw, HV_SCC_LOWER, &phy_data);
3680 hw->phy.ops.read_reg(hw, HV_ECOL_UPPER, &phy_data);
3681 hw->phy.ops.read_reg(hw, HV_ECOL_LOWER, &phy_data);
3682 hw->phy.ops.read_reg(hw, HV_MCC_UPPER, &phy_data);
3683 hw->phy.ops.read_reg(hw, HV_MCC_LOWER, &phy_data);
3684 hw->phy.ops.read_reg(hw, HV_LATECOL_UPPER, &phy_data);
3685 hw->phy.ops.read_reg(hw, HV_LATECOL_LOWER, &phy_data);
3686 hw->phy.ops.read_reg(hw, HV_COLC_UPPER, &phy_data);
3687 hw->phy.ops.read_reg(hw, HV_COLC_LOWER, &phy_data);
3688 hw->phy.ops.read_reg(hw, HV_DC_UPPER, &phy_data);
3689 hw->phy.ops.read_reg(hw, HV_DC_LOWER, &phy_data);
3690 hw->phy.ops.read_reg(hw, HV_TNCRS_UPPER, &phy_data);
3691 hw->phy.ops.read_reg(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003692 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003693}
3694
3695static struct e1000_mac_operations ich8_mac_ops = {
Bruce Allana4f58f52009-06-02 11:29:18 +00003696 .id_led_init = e1000e_id_led_init,
Bruce Allaneb7700d2010-06-16 13:27:05 +00003697 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003698 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003699 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003700 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
3701 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00003702 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003703 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003704 /* led_on dependent on mac type */
3705 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003706 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003707 .reset_hw = e1000_reset_hw_ich8lan,
3708 .init_hw = e1000_init_hw_ich8lan,
3709 .setup_link = e1000_setup_link_ich8lan,
3710 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003711 /* id_led_init dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003712};
3713
3714static struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00003715 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003716 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003717 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07003718 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003719 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00003720 .read_reg = e1000e_read_phy_reg_igp,
3721 .release = e1000_release_swflag_ich8lan,
3722 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003723 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
3724 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003725 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003726};
3727
3728static struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00003729 .acquire = e1000_acquire_nvm_ich8lan,
3730 .read = e1000_read_nvm_ich8lan,
3731 .release = e1000_release_nvm_ich8lan,
3732 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003733 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003734 .validate = e1000_validate_nvm_checksum_ich8lan,
3735 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003736};
3737
3738struct e1000_info e1000_ich8_info = {
3739 .mac = e1000_ich8lan,
3740 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003741 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003742 | FLAG_RX_CSUM_ENABLED
3743 | FLAG_HAS_CTRLEXT_ON_LOAD
3744 | FLAG_HAS_AMT
3745 | FLAG_HAS_FLASH
3746 | FLAG_APME_IN_WUC,
3747 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003748 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003749 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750 .mac_ops = &ich8_mac_ops,
3751 .phy_ops = &ich8_phy_ops,
3752 .nvm_ops = &ich8_nvm_ops,
3753};
3754
3755struct e1000_info e1000_ich9_info = {
3756 .mac = e1000_ich9lan,
3757 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003758 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 | FLAG_HAS_WOL
3760 | FLAG_RX_CSUM_ENABLED
3761 | FLAG_HAS_CTRLEXT_ON_LOAD
3762 | FLAG_HAS_AMT
3763 | FLAG_HAS_ERT
3764 | FLAG_HAS_FLASH
3765 | FLAG_APME_IN_WUC,
3766 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003767 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003768 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003769 .mac_ops = &ich8_mac_ops,
3770 .phy_ops = &ich8_phy_ops,
3771 .nvm_ops = &ich8_nvm_ops,
3772};
3773
Bruce Allanf4187b52008-08-26 18:36:50 -07003774struct e1000_info e1000_ich10_info = {
3775 .mac = e1000_ich10lan,
3776 .flags = FLAG_HAS_JUMBO_FRAMES
3777 | FLAG_IS_ICH
3778 | FLAG_HAS_WOL
3779 | FLAG_RX_CSUM_ENABLED
3780 | FLAG_HAS_CTRLEXT_ON_LOAD
3781 | FLAG_HAS_AMT
3782 | FLAG_HAS_ERT
3783 | FLAG_HAS_FLASH
3784 | FLAG_APME_IN_WUC,
3785 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003786 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07003787 .get_variants = e1000_get_variants_ich8lan,
3788 .mac_ops = &ich8_mac_ops,
3789 .phy_ops = &ich8_phy_ops,
3790 .nvm_ops = &ich8_nvm_ops,
3791};
Bruce Allana4f58f52009-06-02 11:29:18 +00003792
3793struct e1000_info e1000_pch_info = {
3794 .mac = e1000_pchlan,
3795 .flags = FLAG_IS_ICH
3796 | FLAG_HAS_WOL
3797 | FLAG_RX_CSUM_ENABLED
3798 | FLAG_HAS_CTRLEXT_ON_LOAD
3799 | FLAG_HAS_AMT
3800 | FLAG_HAS_FLASH
3801 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00003802 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00003803 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003804 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00003805 .pba = 26,
3806 .max_hw_frame_size = 4096,
3807 .get_variants = e1000_get_variants_ich8lan,
3808 .mac_ops = &ich8_mac_ops,
3809 .phy_ops = &ich8_phy_ops,
3810 .nvm_ops = &ich8_nvm_ops,
3811};
Bruce Alland3738bb2010-06-16 13:27:28 +00003812
3813struct e1000_info e1000_pch2_info = {
3814 .mac = e1000_pch2lan,
3815 .flags = FLAG_IS_ICH
3816 | FLAG_HAS_WOL
3817 | FLAG_RX_CSUM_ENABLED
3818 | FLAG_HAS_CTRLEXT_ON_LOAD
3819 | FLAG_HAS_AMT
3820 | FLAG_HAS_FLASH
3821 | FLAG_HAS_JUMBO_FRAMES
3822 | FLAG_APME_IN_WUC,
3823 .flags2 = FLAG2_HAS_PHY_STATS,
3824 .pba = 18,
3825 .max_hw_frame_size = DEFAULT_JUMBO,
3826 .get_variants = e1000_get_variants_ich8lan,
3827 .mac_ops = &ich8_mac_ops,
3828 .phy_ops = &ich8_phy_ops,
3829 .nvm_ops = &ich8_nvm_ops,
3830};