blob: cf18d65417e61f8023a7e6cf4a8e203f117710b7 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 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
Bruce Allan831bd2e2010-09-22 17:16:18 +0000108#define E1000_FEXTNVM4_BEACON_DURATION_MASK 0x7
109#define E1000_FEXTNVM4_BEACON_DURATION_8USEC 0x7
110#define E1000_FEXTNVM4_BEACON_DURATION_16USEC 0x3
111
Auke Kokbc7f75f2007-09-17 12:30:59 -0700112#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
113
114#define E1000_ICH_RAR_ENTRIES 7
115
116#define PHY_PAGE_SHIFT 5
117#define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
118 ((reg) & MAX_PHY_REG_ADDRESS))
119#define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
120#define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
121
122#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
123#define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
124#define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
125
Bruce Allana4f58f52009-06-02 11:29:18 +0000126#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
127
Bruce Allan53ac5a82009-10-26 11:23:06 +0000128#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
129
Bruce Allanf523d212009-10-29 13:45:45 +0000130/* SMBus Address Phy Register */
131#define HV_SMB_ADDR PHY_REG(768, 26)
Bruce Allan8395ae82010-09-22 17:15:08 +0000132#define HV_SMB_ADDR_MASK 0x007F
Bruce Allanf523d212009-10-29 13:45:45 +0000133#define HV_SMB_ADDR_PEC_EN 0x0200
134#define HV_SMB_ADDR_VALID 0x0080
135
Bruce Alland3738bb2010-06-16 13:27:28 +0000136/* PHY Power Management Control */
137#define HV_PM_CTRL PHY_REG(770, 17)
138
Bruce Allane52997f2010-06-16 13:27:49 +0000139/* PHY Low Power Idle Control */
140#define I82579_LPI_CTRL PHY_REG(772, 20)
141#define I82579_LPI_CTRL_ENABLE_MASK 0x6000
142
Bruce Allan1effb452011-02-25 06:58:03 +0000143/* EMI Registers */
144#define I82579_EMI_ADDR 0x10
145#define I82579_EMI_DATA 0x11
146#define I82579_LPI_UPDATE_TIMER 0x4805 /* in 40ns units + 40 ns base value */
147
Bruce Allanf523d212009-10-29 13:45:45 +0000148/* Strapping Option Register - RO */
149#define E1000_STRAP 0x0000C
150#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
151#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
152
Bruce Allanfa2ce132009-10-26 11:23:25 +0000153/* OEM Bits Phy Register */
154#define HV_OEM_BITS PHY_REG(768, 25)
155#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
Bruce Allanf523d212009-10-29 13:45:45 +0000156#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
Bruce Allanfa2ce132009-10-26 11:23:25 +0000157#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
158
Bruce Allan1d5846b2009-10-29 13:46:05 +0000159#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
160#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
161
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000162/* KMRN Mode Control */
163#define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
164#define HV_KMRN_MDIO_SLOW 0x0400
165
Auke Kokbc7f75f2007-09-17 12:30:59 -0700166/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
167/* Offset 04h HSFSTS */
168union ich8_hws_flash_status {
169 struct ich8_hsfsts {
170 u16 flcdone :1; /* bit 0 Flash Cycle Done */
171 u16 flcerr :1; /* bit 1 Flash Cycle Error */
172 u16 dael :1; /* bit 2 Direct Access error Log */
173 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
174 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
175 u16 reserved1 :2; /* bit 13:6 Reserved */
176 u16 reserved2 :6; /* bit 13:6 Reserved */
177 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
178 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
179 } hsf_status;
180 u16 regval;
181};
182
183/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
184/* Offset 06h FLCTL */
185union ich8_hws_flash_ctrl {
186 struct ich8_hsflctl {
187 u16 flcgo :1; /* 0 Flash Cycle Go */
188 u16 flcycle :2; /* 2:1 Flash Cycle */
189 u16 reserved :5; /* 7:3 Reserved */
190 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
191 u16 flockdn :6; /* 15:10 Reserved */
192 } hsf_ctrl;
193 u16 regval;
194};
195
196/* ICH Flash Region Access Permissions */
197union ich8_hws_flash_regacc {
198 struct ich8_flracc {
199 u32 grra :8; /* 0:7 GbE region Read Access */
200 u32 grwa :8; /* 8:15 GbE region Write Access */
201 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
202 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
203 } hsf_flregacc;
204 u16 regval;
205};
206
Bruce Allan4a770352008-10-01 17:18:35 -0700207/* ICH Flash Protected Region */
208union ich8_flash_protected_range {
209 struct ich8_pr {
210 u32 base:13; /* 0:12 Protected Range Base */
211 u32 reserved1:2; /* 13:14 Reserved */
212 u32 rpe:1; /* 15 Read Protection Enable */
213 u32 limit:13; /* 16:28 Protected Range Limit */
214 u32 reserved2:2; /* 29:30 Reserved */
215 u32 wpe:1; /* 31 Write Protection Enable */
216 } range;
217 u32 regval;
218};
219
Auke Kokbc7f75f2007-09-17 12:30:59 -0700220static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
221static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
222static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700223static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
224static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
225 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700226static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
227 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700228static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
229 u16 *data);
230static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
231 u8 size, u16 *data);
232static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
233static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700234static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000235static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
236static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
237static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
238static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
239static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
240static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
241static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
242static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000243static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000244static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000245static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000246static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000247static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000248static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
249static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000250static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000251static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700252
253static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
254{
255 return readw(hw->flash_address + reg);
256}
257
258static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
259{
260 return readl(hw->flash_address + reg);
261}
262
263static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
264{
265 writew(val, hw->flash_address + reg);
266}
267
268static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
269{
270 writel(val, hw->flash_address + reg);
271}
272
273#define er16flash(reg) __er16flash(hw, (reg))
274#define er32flash(reg) __er32flash(hw, (reg))
275#define ew16flash(reg,val) __ew16flash(hw, (reg), (val))
276#define ew32flash(reg,val) __ew32flash(hw, (reg), (val))
277
278/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000279 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
280 * @hw: pointer to the HW structure
281 *
282 * Initialize family-specific PHY parameters and function pointers.
283 **/
284static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
285{
286 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan605c82b2010-09-22 17:17:01 +0000287 u32 ctrl, fwsm;
Bruce Allana4f58f52009-06-02 11:29:18 +0000288 s32 ret_val = 0;
289
290 phy->addr = 1;
291 phy->reset_delay_us = 100;
292
Bruce Allan94d81862009-11-20 23:25:26 +0000293 phy->ops.read_reg = e1000_read_phy_reg_hv;
294 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000295 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
296 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000297 phy->ops.write_reg = e1000_write_phy_reg_hv;
298 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan17f208d2009-12-01 15:47:22 +0000299 phy->ops.power_up = e1000_power_up_phy_copper;
300 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000301 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
302
Bruce Alland3738bb2010-06-16 13:27:28 +0000303 /*
304 * The MAC-PHY interconnect may still be in SMBus mode
305 * after Sx->S0. If the manageability engine (ME) is
306 * disabled, then toggle the LANPHYPC Value bit to force
307 * the interconnect to PCIe mode.
308 */
Bruce Allan605c82b2010-09-22 17:17:01 +0000309 fwsm = er32(FWSM);
310 if (!(fwsm & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan6dfaa762010-05-05 22:00:06 +0000311 ctrl = er32(CTRL);
312 ctrl |= E1000_CTRL_LANPHYPC_OVERRIDE;
313 ctrl &= ~E1000_CTRL_LANPHYPC_VALUE;
314 ew32(CTRL, ctrl);
315 udelay(10);
316 ctrl &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
317 ew32(CTRL, ctrl);
318 msleep(50);
Bruce Allan605c82b2010-09-22 17:17:01 +0000319
320 /*
321 * Gate automatic PHY configuration by hardware on
322 * non-managed 82579
323 */
324 if (hw->mac.type == e1000_pch2lan)
325 e1000_gate_hw_phy_config_ich8lan(hw, true);
Bruce Allan6dfaa762010-05-05 22:00:06 +0000326 }
327
Bruce Allan627c8a02010-05-05 22:00:27 +0000328 /*
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400329 * Reset the PHY before any access to it. Doing so, ensures that
Bruce Allan627c8a02010-05-05 22:00:27 +0000330 * the PHY is in a known good state before we read/write PHY registers.
331 * The generic reset is sufficient here, because we haven't determined
332 * the PHY type yet.
333 */
334 ret_val = e1000e_phy_hw_reset_generic(hw);
335 if (ret_val)
336 goto out;
337
Bruce Allan605c82b2010-09-22 17:17:01 +0000338 /* Ungate automatic PHY configuration on non-managed 82579 */
339 if ((hw->mac.type == e1000_pch2lan) &&
340 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
341 msleep(10);
342 e1000_gate_hw_phy_config_ich8lan(hw, false);
343 }
344
Bruce Allana4f58f52009-06-02 11:29:18 +0000345 phy->id = e1000_phy_unknown;
Bruce Allan664dc872010-11-24 06:01:46 +0000346 switch (hw->mac.type) {
347 default:
348 ret_val = e1000e_get_phy_id(hw);
349 if (ret_val)
350 goto out;
351 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
352 break;
353 /* fall-through */
354 case e1000_pch2lan:
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000355 /*
Bruce Allan664dc872010-11-24 06:01:46 +0000356 * In case the PHY needs to be in mdio slow mode,
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000357 * set slow mode and try to get the PHY id again.
358 */
359 ret_val = e1000_set_mdio_slow_mode_hv(hw);
360 if (ret_val)
361 goto out;
362 ret_val = e1000e_get_phy_id(hw);
363 if (ret_val)
364 goto out;
Bruce Allan664dc872010-11-24 06:01:46 +0000365 break;
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000366 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000367 phy->type = e1000e_get_phy_type_from_id(phy->id);
368
Bruce Allan0be84012009-12-02 17:03:18 +0000369 switch (phy->type) {
370 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000371 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +0000372 phy->ops.check_polarity = e1000_check_polarity_82577;
373 phy->ops.force_speed_duplex =
374 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000375 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000376 phy->ops.get_info = e1000_get_phy_info_82577;
377 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000378 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000379 case e1000_phy_82578:
380 phy->ops.check_polarity = e1000_check_polarity_m88;
381 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
382 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
383 phy->ops.get_info = e1000e_get_phy_info_m88;
384 break;
385 default:
386 ret_val = -E1000_ERR_PHY;
387 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000388 }
389
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000390out:
Bruce Allana4f58f52009-06-02 11:29:18 +0000391 return ret_val;
392}
393
394/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700395 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
396 * @hw: pointer to the HW structure
397 *
398 * Initialize family-specific PHY parameters and function pointers.
399 **/
400static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
401{
402 struct e1000_phy_info *phy = &hw->phy;
403 s32 ret_val;
404 u16 i = 0;
405
406 phy->addr = 1;
407 phy->reset_delay_us = 100;
408
Bruce Allan17f208d2009-12-01 15:47:22 +0000409 phy->ops.power_up = e1000_power_up_phy_copper;
410 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
411
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700412 /*
413 * We may need to do this twice - once for IGP and if that fails,
414 * we'll set BM func pointers and try again
415 */
416 ret_val = e1000e_determine_phy_address(hw);
417 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000418 phy->ops.write_reg = e1000e_write_phy_reg_bm;
419 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700420 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000421 if (ret_val) {
422 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700423 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000424 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700425 }
426
Auke Kokbc7f75f2007-09-17 12:30:59 -0700427 phy->id = 0;
428 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
429 (i++ < 100)) {
430 msleep(1);
431 ret_val = e1000e_get_phy_id(hw);
432 if (ret_val)
433 return ret_val;
434 }
435
436 /* Verify phy id */
437 switch (phy->id) {
438 case IGP03E1000_E_PHY_ID:
439 phy->type = e1000_phy_igp_3;
440 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000441 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
442 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000443 phy->ops.get_info = e1000e_get_phy_info_igp;
444 phy->ops.check_polarity = e1000_check_polarity_igp;
445 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700446 break;
447 case IFE_E_PHY_ID:
448 case IFE_PLUS_E_PHY_ID:
449 case IFE_C_E_PHY_ID:
450 phy->type = e1000_phy_ife;
451 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000452 phy->ops.get_info = e1000_get_phy_info_ife;
453 phy->ops.check_polarity = e1000_check_polarity_ife;
454 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700455 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700456 case BME1000_E_PHY_ID:
457 phy->type = e1000_phy_bm;
458 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000459 phy->ops.read_reg = e1000e_read_phy_reg_bm;
460 phy->ops.write_reg = e1000e_write_phy_reg_bm;
461 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000462 phy->ops.get_info = e1000e_get_phy_info_m88;
463 phy->ops.check_polarity = e1000_check_polarity_m88;
464 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700465 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700466 default:
467 return -E1000_ERR_PHY;
468 break;
469 }
470
471 return 0;
472}
473
474/**
475 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
476 * @hw: pointer to the HW structure
477 *
478 * Initialize family-specific NVM parameters and function
479 * pointers.
480 **/
481static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
482{
483 struct e1000_nvm_info *nvm = &hw->nvm;
484 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000485 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700486 u16 i;
487
Bruce Allanad680762008-03-28 09:15:03 -0700488 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700489 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000490 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700491 return -E1000_ERR_CONFIG;
492 }
493
494 nvm->type = e1000_nvm_flash_sw;
495
496 gfpreg = er32flash(ICH_FLASH_GFPREG);
497
Bruce Allanad680762008-03-28 09:15:03 -0700498 /*
499 * sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700500 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700501 * the overall size.
502 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700503 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
504 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
505
506 /* flash_base_addr is byte-aligned */
507 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
508
Bruce Allanad680762008-03-28 09:15:03 -0700509 /*
510 * find total size of the NVM, then cut in half since the total
511 * size represents two separate NVM banks.
512 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700513 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
514 << FLASH_SECTOR_ADDR_SHIFT;
515 nvm->flash_bank_size /= 2;
516 /* Adjust to word count */
517 nvm->flash_bank_size /= sizeof(u16);
518
519 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
520
521 /* Clear shadow ram */
522 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000523 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700524 dev_spec->shadow_ram[i].value = 0xFFFF;
525 }
526
527 return 0;
528}
529
530/**
531 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
532 * @hw: pointer to the HW structure
533 *
534 * Initialize family-specific MAC parameters and function
535 * pointers.
536 **/
537static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
538{
539 struct e1000_hw *hw = &adapter->hw;
540 struct e1000_mac_info *mac = &hw->mac;
541
542 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700543 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544
545 /* Set mta register count */
546 mac->mta_reg_count = 32;
547 /* Set rar entry count */
548 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
549 if (mac->type == e1000_ich8lan)
550 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000551 /* FWSM register */
552 mac->has_fwsm = true;
553 /* ARC subsystem not supported */
554 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000555 /* Adaptive IFS supported */
556 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557
Bruce Allana4f58f52009-06-02 11:29:18 +0000558 /* LED operations */
559 switch (mac->type) {
560 case e1000_ich8lan:
561 case e1000_ich9lan:
562 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000563 /* check management mode */
564 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000565 /* ID LED init */
566 mac->ops.id_led_init = e1000e_id_led_init;
567 /* setup LED */
568 mac->ops.setup_led = e1000e_setup_led_generic;
569 /* cleanup LED */
570 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
571 /* turn on/off LED */
572 mac->ops.led_on = e1000_led_on_ich8lan;
573 mac->ops.led_off = e1000_led_off_ich8lan;
574 break;
575 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000576 case e1000_pch2lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000577 /* check management mode */
578 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000579 /* ID LED init */
580 mac->ops.id_led_init = e1000_id_led_init_pchlan;
581 /* setup LED */
582 mac->ops.setup_led = e1000_setup_led_pchlan;
583 /* cleanup LED */
584 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
585 /* turn on/off LED */
586 mac->ops.led_on = e1000_led_on_pchlan;
587 mac->ops.led_off = e1000_led_off_pchlan;
588 break;
589 default:
590 break;
591 }
592
Auke Kokbc7f75f2007-09-17 12:30:59 -0700593 /* Enable PCS Lock-loss workaround for ICH8 */
594 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000595 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596
Bruce Allan605c82b2010-09-22 17:17:01 +0000597 /* Gate automatic PHY configuration by hardware on managed 82579 */
598 if ((mac->type == e1000_pch2lan) &&
599 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
600 e1000_gate_hw_phy_config_ich8lan(hw, true);
Bruce Alland3738bb2010-06-16 13:27:28 +0000601
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602 return 0;
603}
604
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000605/**
Bruce Allane52997f2010-06-16 13:27:49 +0000606 * e1000_set_eee_pchlan - Enable/disable EEE support
607 * @hw: pointer to the HW structure
608 *
609 * Enable/disable EEE based on setting in dev_spec structure. The bits in
610 * the LPI Control register will remain set only if/when link is up.
611 **/
612static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
613{
614 s32 ret_val = 0;
615 u16 phy_reg;
616
617 if (hw->phy.type != e1000_phy_82579)
618 goto out;
619
620 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
621 if (ret_val)
622 goto out;
623
624 if (hw->dev_spec.ich8lan.eee_disable)
625 phy_reg &= ~I82579_LPI_CTRL_ENABLE_MASK;
626 else
627 phy_reg |= I82579_LPI_CTRL_ENABLE_MASK;
628
629 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
630out:
631 return ret_val;
632}
633
634/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000635 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
636 * @hw: pointer to the HW structure
637 *
638 * Checks to see of the link status of the hardware has changed. If a
639 * change in link status has been detected, then we read the PHY registers
640 * to get the current speed/duplex if link exists.
641 **/
642static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
643{
644 struct e1000_mac_info *mac = &hw->mac;
645 s32 ret_val;
646 bool link;
647
648 /*
649 * We only want to go out to the PHY registers to see if Auto-Neg
650 * has completed and/or if our link status has changed. The
651 * get_link_status flag is set upon receiving a Link Status
652 * Change or Rx Sequence Error interrupt.
653 */
654 if (!mac->get_link_status) {
655 ret_val = 0;
656 goto out;
657 }
658
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000659 /*
660 * First we want to see if the MII Status Register reports
661 * link. If so, then we want to get the current speed/duplex
662 * of the PHY.
663 */
664 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
665 if (ret_val)
666 goto out;
667
Bruce Allan1d5846b2009-10-29 13:46:05 +0000668 if (hw->mac.type == e1000_pchlan) {
669 ret_val = e1000_k1_gig_workaround_hv(hw, link);
670 if (ret_val)
671 goto out;
672 }
673
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000674 if (!link)
675 goto out; /* No link detected */
676
677 mac->get_link_status = false;
678
679 if (hw->phy.type == e1000_phy_82578) {
680 ret_val = e1000_link_stall_workaround_hv(hw);
681 if (ret_val)
682 goto out;
683 }
684
Bruce Allan831bd2e2010-09-22 17:16:18 +0000685 if (hw->mac.type == e1000_pch2lan) {
686 ret_val = e1000_k1_workaround_lv(hw);
687 if (ret_val)
688 goto out;
689 }
690
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000691 /*
692 * Check if there was DownShift, must be checked
693 * immediately after link-up
694 */
695 e1000e_check_downshift(hw);
696
Bruce Allane52997f2010-06-16 13:27:49 +0000697 /* Enable/Disable EEE after link up */
698 ret_val = e1000_set_eee_pchlan(hw);
699 if (ret_val)
700 goto out;
701
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000702 /*
703 * If we are forcing speed/duplex, then we simply return since
704 * we have already determined whether we have link or not.
705 */
706 if (!mac->autoneg) {
707 ret_val = -E1000_ERR_CONFIG;
708 goto out;
709 }
710
711 /*
712 * Auto-Neg is enabled. Auto Speed Detection takes care
713 * of MAC speed/duplex configuration. So we only need to
714 * configure Collision Distance in the MAC.
715 */
716 e1000e_config_collision_dist(hw);
717
718 /*
719 * Configure Flow Control now that Auto-Neg has completed.
720 * First, we need to restore the desired flow control
721 * settings because we may have had to re-autoneg with a
722 * different link partner.
723 */
724 ret_val = e1000e_config_fc_after_link_up(hw);
725 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000726 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000727
728out:
729 return ret_val;
730}
731
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700732static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700733{
734 struct e1000_hw *hw = &adapter->hw;
735 s32 rc;
736
737 rc = e1000_init_mac_params_ich8lan(adapter);
738 if (rc)
739 return rc;
740
741 rc = e1000_init_nvm_params_ich8lan(hw);
742 if (rc)
743 return rc;
744
Bruce Alland3738bb2010-06-16 13:27:28 +0000745 switch (hw->mac.type) {
746 case e1000_ich8lan:
747 case e1000_ich9lan:
748 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000749 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +0000750 break;
751 case e1000_pchlan:
752 case e1000_pch2lan:
753 rc = e1000_init_phy_params_pchlan(hw);
754 break;
755 default:
756 break;
757 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700758 if (rc)
759 return rc;
760
Bruce Allan2adc55c2009-06-02 11:28:58 +0000761 if (adapter->hw.phy.type == e1000_phy_ife) {
762 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
763 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
764 }
765
Auke Kokbc7f75f2007-09-17 12:30:59 -0700766 if ((adapter->hw.mac.type == e1000_ich8lan) &&
767 (adapter->hw.phy.type == e1000_phy_igp_3))
768 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
769
Bruce Allan5a86f282010-06-29 18:13:13 +0000770 /* Disable EEE by default until IEEE802.3az spec is finalized */
771 if (adapter->flags2 & FLAG2_HAS_EEE)
772 adapter->hw.dev_spec.ich8lan.eee_disable = true;
773
Auke Kokbc7f75f2007-09-17 12:30:59 -0700774 return 0;
775}
776
Thomas Gleixner717d4382008-10-02 16:33:40 -0700777static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700778
Auke Kokbc7f75f2007-09-17 12:30:59 -0700779/**
Bruce Allanca15df52009-10-26 11:23:43 +0000780 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
781 * @hw: pointer to the HW structure
782 *
783 * Acquires the mutex for performing NVM operations.
784 **/
785static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
786{
787 mutex_lock(&nvm_mutex);
788
789 return 0;
790}
791
792/**
793 * e1000_release_nvm_ich8lan - Release NVM mutex
794 * @hw: pointer to the HW structure
795 *
796 * Releases the mutex used while performing NVM operations.
797 **/
798static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
799{
800 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +0000801}
802
803static DEFINE_MUTEX(swflag_mutex);
804
805/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700806 * e1000_acquire_swflag_ich8lan - Acquire software control flag
807 * @hw: pointer to the HW structure
808 *
Bruce Allanca15df52009-10-26 11:23:43 +0000809 * Acquires the software control flag for performing PHY and select
810 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700811 **/
812static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
813{
Bruce Allan373a88d2009-08-07 07:41:37 +0000814 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
815 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700816
Bruce Allanca15df52009-10-26 11:23:43 +0000817 mutex_lock(&swflag_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700818
Auke Kokbc7f75f2007-09-17 12:30:59 -0700819 while (timeout) {
820 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +0000821 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
822 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700823
Auke Kokbc7f75f2007-09-17 12:30:59 -0700824 mdelay(1);
825 timeout--;
826 }
827
828 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000829 e_dbg("SW/FW/HW has locked the resource for too long.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000830 ret_val = -E1000_ERR_CONFIG;
831 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700832 }
833
Bruce Allan53ac5a82009-10-26 11:23:06 +0000834 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +0000835
836 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
837 ew32(EXTCNF_CTRL, extcnf_ctrl);
838
839 while (timeout) {
840 extcnf_ctrl = er32(EXTCNF_CTRL);
841 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
842 break;
843
844 mdelay(1);
845 timeout--;
846 }
847
848 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000849 e_dbg("Failed to acquire the semaphore.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000850 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
851 ew32(EXTCNF_CTRL, extcnf_ctrl);
852 ret_val = -E1000_ERR_CONFIG;
853 goto out;
854 }
855
856out:
857 if (ret_val)
Bruce Allanca15df52009-10-26 11:23:43 +0000858 mutex_unlock(&swflag_mutex);
Bruce Allan373a88d2009-08-07 07:41:37 +0000859
860 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700861}
862
863/**
864 * e1000_release_swflag_ich8lan - Release software control flag
865 * @hw: pointer to the HW structure
866 *
Bruce Allanca15df52009-10-26 11:23:43 +0000867 * Releases the software control flag for performing PHY and select
868 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700869 **/
870static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
871{
872 u32 extcnf_ctrl;
873
874 extcnf_ctrl = er32(EXTCNF_CTRL);
875 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
876 ew32(EXTCNF_CTRL, extcnf_ctrl);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700877
Bruce Allanca15df52009-10-26 11:23:43 +0000878 mutex_unlock(&swflag_mutex);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700879}
880
881/**
Bruce Allan4662e822008-08-26 18:37:06 -0700882 * e1000_check_mng_mode_ich8lan - Checks management mode
883 * @hw: pointer to the HW structure
884 *
Bruce Allaneb7700d2010-06-16 13:27:05 +0000885 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -0700886 * This is a function pointer entry point only called by read/write
887 * routines for the PHY and NVM parts.
888 **/
889static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
890{
Bruce Allana708dd82009-11-20 23:28:37 +0000891 u32 fwsm;
892
893 fwsm = er32(FWSM);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000894 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
895 ((fwsm & E1000_FWSM_MODE_MASK) ==
896 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
897}
Bruce Allan4662e822008-08-26 18:37:06 -0700898
Bruce Allaneb7700d2010-06-16 13:27:05 +0000899/**
900 * e1000_check_mng_mode_pchlan - Checks management mode
901 * @hw: pointer to the HW structure
902 *
903 * This checks if the adapter has iAMT enabled.
904 * This is a function pointer entry point only called by read/write
905 * routines for the PHY and NVM parts.
906 **/
907static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
908{
909 u32 fwsm;
910
911 fwsm = er32(FWSM);
912 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
913 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -0700914}
915
916/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700917 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
918 * @hw: pointer to the HW structure
919 *
920 * Checks if firmware is blocking the reset of the PHY.
921 * This is a function pointer entry point only called by
922 * reset routines.
923 **/
924static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
925{
926 u32 fwsm;
927
928 fwsm = er32(FWSM);
929
930 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
931}
932
933/**
Bruce Allan8395ae82010-09-22 17:15:08 +0000934 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
935 * @hw: pointer to the HW structure
936 *
937 * Assumes semaphore already acquired.
938 *
939 **/
940static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
941{
942 u16 phy_data;
943 u32 strap = er32(STRAP);
944 s32 ret_val = 0;
945
946 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
947
948 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
949 if (ret_val)
950 goto out;
951
952 phy_data &= ~HV_SMB_ADDR_MASK;
953 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
954 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
955 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
956
957out:
958 return ret_val;
959}
960
961/**
Bruce Allanf523d212009-10-29 13:45:45 +0000962 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
963 * @hw: pointer to the HW structure
964 *
965 * SW should configure the LCD from the NVM extended configuration region
966 * as a workaround for certain parts.
967 **/
968static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
969{
970 struct e1000_phy_info *phy = &hw->phy;
971 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +0000972 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +0000973 u16 word_addr, reg_data, reg_addr, phy_page = 0;
974
Bruce Allanf523d212009-10-29 13:45:45 +0000975 /*
976 * Initialize the PHY from the NVM on ICH platforms. This
977 * is needed due to an issue where the NVM configuration is
978 * not properly autoloaded after power transitions.
979 * Therefore, after each PHY reset, we will load the
980 * configuration data out of the NVM manually.
981 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +0000982 switch (hw->mac.type) {
983 case e1000_ich8lan:
984 if (phy->type != e1000_phy_igp_3)
985 return ret_val;
986
Bruce Allan5f3eed62010-09-22 17:15:54 +0000987 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
988 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +0000989 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
990 break;
991 }
992 /* Fall-thru */
993 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000994 case e1000_pch2lan:
Bruce Allan8b802a72010-05-10 15:01:10 +0000995 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +0000996 break;
997 default:
998 return ret_val;
999 }
1000
1001 ret_val = hw->phy.ops.acquire(hw);
1002 if (ret_val)
1003 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001004
Bruce Allan8b802a72010-05-10 15:01:10 +00001005 data = er32(FEXTNVM);
1006 if (!(data & sw_cfg_mask))
1007 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +00001008
Bruce Allan8b802a72010-05-10 15:01:10 +00001009 /*
1010 * Make sure HW does not configure LCD from PHY
1011 * extended configuration before SW configuration
1012 */
1013 data = er32(EXTCNF_CTRL);
Bruce Alland3738bb2010-06-16 13:27:28 +00001014 if (!(hw->mac.type == e1000_pch2lan)) {
1015 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
1016 goto out;
1017 }
Bruce Allanf523d212009-10-29 13:45:45 +00001018
Bruce Allan8b802a72010-05-10 15:01:10 +00001019 cnf_size = er32(EXTCNF_SIZE);
1020 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1021 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1022 if (!cnf_size)
1023 goto out;
1024
1025 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1026 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1027
Bruce Allan87fb7412010-09-22 17:15:33 +00001028 if ((!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
1029 (hw->mac.type == e1000_pchlan)) ||
1030 (hw->mac.type == e1000_pch2lan)) {
Bruce Allanf523d212009-10-29 13:45:45 +00001031 /*
Bruce Allan8b802a72010-05-10 15:01:10 +00001032 * HW configures the SMBus address and LEDs when the
1033 * OEM and LCD Write Enable bits are set in the NVM.
1034 * When both NVM bits are cleared, SW will configure
1035 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001036 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001037 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001038 if (ret_val)
Bruce Allanf523d212009-10-29 13:45:45 +00001039 goto out;
1040
Bruce Allan8b802a72010-05-10 15:01:10 +00001041 data = er32(LEDCTL);
1042 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1043 (u16)data);
1044 if (ret_val)
1045 goto out;
1046 }
1047
1048 /* Configure LCD from extended configuration region. */
1049
1050 /* cnf_base_addr is in DWORD */
1051 word_addr = (u16)(cnf_base_addr << 1);
1052
1053 for (i = 0; i < cnf_size; i++) {
1054 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
1055 &reg_data);
1056 if (ret_val)
Bruce Allanf523d212009-10-29 13:45:45 +00001057 goto out;
1058
Bruce Allan8b802a72010-05-10 15:01:10 +00001059 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1060 1, &reg_addr);
1061 if (ret_val)
1062 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +00001063
Bruce Allan8b802a72010-05-10 15:01:10 +00001064 /* Save off the PHY page for future writes. */
1065 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1066 phy_page = reg_data;
1067 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001068 }
Bruce Allanf523d212009-10-29 13:45:45 +00001069
Bruce Allan8b802a72010-05-10 15:01:10 +00001070 reg_addr &= PHY_REG_MASK;
1071 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001072
Bruce Allan8b802a72010-05-10 15:01:10 +00001073 ret_val = phy->ops.write_reg_locked(hw, (u32)reg_addr,
1074 reg_data);
1075 if (ret_val)
1076 goto out;
Bruce Allanf523d212009-10-29 13:45:45 +00001077 }
1078
1079out:
Bruce Allan94d81862009-11-20 23:25:26 +00001080 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001081 return ret_val;
1082}
1083
1084/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001085 * e1000_k1_gig_workaround_hv - K1 Si workaround
1086 * @hw: pointer to the HW structure
1087 * @link: link up bool flag
1088 *
1089 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1090 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1091 * If link is down, the function will restore the default K1 setting located
1092 * in the NVM.
1093 **/
1094static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1095{
1096 s32 ret_val = 0;
1097 u16 status_reg = 0;
1098 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1099
1100 if (hw->mac.type != e1000_pchlan)
1101 goto out;
1102
1103 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001104 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001105 if (ret_val)
1106 goto out;
1107
1108 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1109 if (link) {
1110 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan94d81862009-11-20 23:25:26 +00001111 ret_val = hw->phy.ops.read_reg_locked(hw, BM_CS_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +00001112 &status_reg);
1113 if (ret_val)
1114 goto release;
1115
1116 status_reg &= BM_CS_STATUS_LINK_UP |
1117 BM_CS_STATUS_RESOLVED |
1118 BM_CS_STATUS_SPEED_MASK;
1119
1120 if (status_reg == (BM_CS_STATUS_LINK_UP |
1121 BM_CS_STATUS_RESOLVED |
1122 BM_CS_STATUS_SPEED_1000))
1123 k1_enable = false;
1124 }
1125
1126 if (hw->phy.type == e1000_phy_82577) {
Bruce Allan94d81862009-11-20 23:25:26 +00001127 ret_val = hw->phy.ops.read_reg_locked(hw, HV_M_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +00001128 &status_reg);
1129 if (ret_val)
1130 goto release;
1131
1132 status_reg &= HV_M_STATUS_LINK_UP |
1133 HV_M_STATUS_AUTONEG_COMPLETE |
1134 HV_M_STATUS_SPEED_MASK;
1135
1136 if (status_reg == (HV_M_STATUS_LINK_UP |
1137 HV_M_STATUS_AUTONEG_COMPLETE |
1138 HV_M_STATUS_SPEED_1000))
1139 k1_enable = false;
1140 }
1141
1142 /* Link stall fix for link up */
Bruce Allan94d81862009-11-20 23:25:26 +00001143 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +00001144 0x0100);
1145 if (ret_val)
1146 goto release;
1147
1148 } else {
1149 /* Link stall fix for link down */
Bruce Allan94d81862009-11-20 23:25:26 +00001150 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +00001151 0x4100);
1152 if (ret_val)
1153 goto release;
1154 }
1155
1156 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1157
1158release:
Bruce Allan94d81862009-11-20 23:25:26 +00001159 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001160out:
1161 return ret_val;
1162}
1163
1164/**
1165 * e1000_configure_k1_ich8lan - Configure K1 power state
1166 * @hw: pointer to the HW structure
1167 * @enable: K1 state to configure
1168 *
1169 * Configure the K1 power state based on the provided parameter.
1170 * Assumes semaphore already acquired.
1171 *
1172 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1173 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001174s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001175{
1176 s32 ret_val = 0;
1177 u32 ctrl_reg = 0;
1178 u32 ctrl_ext = 0;
1179 u32 reg = 0;
1180 u16 kmrn_reg = 0;
1181
1182 ret_val = e1000e_read_kmrn_reg_locked(hw,
1183 E1000_KMRNCTRLSTA_K1_CONFIG,
1184 &kmrn_reg);
1185 if (ret_val)
1186 goto out;
1187
1188 if (k1_enable)
1189 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1190 else
1191 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1192
1193 ret_val = e1000e_write_kmrn_reg_locked(hw,
1194 E1000_KMRNCTRLSTA_K1_CONFIG,
1195 kmrn_reg);
1196 if (ret_val)
1197 goto out;
1198
1199 udelay(20);
1200 ctrl_ext = er32(CTRL_EXT);
1201 ctrl_reg = er32(CTRL);
1202
1203 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1204 reg |= E1000_CTRL_FRCSPD;
1205 ew32(CTRL, reg);
1206
1207 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
1208 udelay(20);
1209 ew32(CTRL, ctrl_reg);
1210 ew32(CTRL_EXT, ctrl_ext);
1211 udelay(20);
1212
1213out:
1214 return ret_val;
1215}
1216
1217/**
Bruce Allanf523d212009-10-29 13:45:45 +00001218 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1219 * @hw: pointer to the HW structure
1220 * @d0_state: boolean if entering d0 or d3 device state
1221 *
1222 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1223 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1224 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1225 **/
1226static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1227{
1228 s32 ret_val = 0;
1229 u32 mac_reg;
1230 u16 oem_reg;
1231
Bruce Alland3738bb2010-06-16 13:27:28 +00001232 if ((hw->mac.type != e1000_pch2lan) && (hw->mac.type != e1000_pchlan))
Bruce Allanf523d212009-10-29 13:45:45 +00001233 return ret_val;
1234
Bruce Allan94d81862009-11-20 23:25:26 +00001235 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001236 if (ret_val)
1237 return ret_val;
1238
Bruce Alland3738bb2010-06-16 13:27:28 +00001239 if (!(hw->mac.type == e1000_pch2lan)) {
1240 mac_reg = er32(EXTCNF_CTRL);
1241 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
1242 goto out;
1243 }
Bruce Allanf523d212009-10-29 13:45:45 +00001244
1245 mac_reg = er32(FEXTNVM);
1246 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
1247 goto out;
1248
1249 mac_reg = er32(PHY_CTRL);
1250
Bruce Allan94d81862009-11-20 23:25:26 +00001251 ret_val = hw->phy.ops.read_reg_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001252 if (ret_val)
1253 goto out;
1254
1255 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1256
1257 if (d0_state) {
1258 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1259 oem_reg |= HV_OEM_BITS_GBE_DIS;
1260
1261 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1262 oem_reg |= HV_OEM_BITS_LPLU;
1263 } else {
1264 if (mac_reg & E1000_PHY_CTRL_NOND0A_GBE_DISABLE)
1265 oem_reg |= HV_OEM_BITS_GBE_DIS;
1266
1267 if (mac_reg & E1000_PHY_CTRL_NOND0A_LPLU)
1268 oem_reg |= HV_OEM_BITS_LPLU;
1269 }
1270 /* Restart auto-neg to activate the bits */
Bruce Allan818f3332009-11-19 14:17:30 +00001271 if (!e1000_check_reset_block(hw))
1272 oem_reg |= HV_OEM_BITS_RESTART_AN;
Bruce Allan94d81862009-11-20 23:25:26 +00001273 ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001274
1275out:
Bruce Allan94d81862009-11-20 23:25:26 +00001276 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001277
1278 return ret_val;
1279}
1280
1281
1282/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001283 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1284 * @hw: pointer to the HW structure
1285 **/
1286static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1287{
1288 s32 ret_val;
1289 u16 data;
1290
1291 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1292 if (ret_val)
1293 return ret_val;
1294
1295 data |= HV_KMRN_MDIO_SLOW;
1296
1297 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1298
1299 return ret_val;
1300}
1301
1302/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001303 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1304 * done after every PHY reset.
1305 **/
1306static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1307{
1308 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001309 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001310
1311 if (hw->mac.type != e1000_pchlan)
1312 return ret_val;
1313
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001314 /* Set MDIO slow mode before any other MDIO access */
1315 if (hw->phy.type == e1000_phy_82577) {
1316 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1317 if (ret_val)
1318 goto out;
1319 }
1320
Bruce Allana4f58f52009-06-02 11:29:18 +00001321 if (((hw->phy.type == e1000_phy_82577) &&
1322 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1323 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1324 /* Disable generation of early preamble */
1325 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1326 if (ret_val)
1327 return ret_val;
1328
1329 /* Preamble tuning for SSC */
1330 ret_val = e1e_wphy(hw, PHY_REG(770, 16), 0xA204);
1331 if (ret_val)
1332 return ret_val;
1333 }
1334
1335 if (hw->phy.type == e1000_phy_82578) {
1336 /*
1337 * Return registers to default by doing a soft reset then
1338 * writing 0x3140 to the control register.
1339 */
1340 if (hw->phy.revision < 2) {
1341 e1000e_phy_sw_reset(hw);
1342 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1343 }
1344 }
1345
1346 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001347 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001348 if (ret_val)
1349 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001350
Bruce Allana4f58f52009-06-02 11:29:18 +00001351 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001352 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001353 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001354 if (ret_val)
1355 goto out;
Bruce Allana4f58f52009-06-02 11:29:18 +00001356
Bruce Allan1d5846b2009-10-29 13:46:05 +00001357 /*
1358 * Configure the K1 Si workaround during phy reset assuming there is
1359 * link so that it disables K1 if link is in 1Gbps.
1360 */
1361 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001362 if (ret_val)
1363 goto out;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001364
Bruce Allanbaf86c92010-01-13 01:53:08 +00001365 /* Workaround for link disconnects on a busy hub in half duplex */
1366 ret_val = hw->phy.ops.acquire(hw);
1367 if (ret_val)
1368 goto out;
1369 ret_val = hw->phy.ops.read_reg_locked(hw,
1370 PHY_REG(BM_PORT_CTRL_PAGE, 17),
1371 &phy_data);
1372 if (ret_val)
1373 goto release;
1374 ret_val = hw->phy.ops.write_reg_locked(hw,
1375 PHY_REG(BM_PORT_CTRL_PAGE, 17),
1376 phy_data & 0x00FF);
1377release:
1378 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001379out:
Bruce Allana4f58f52009-06-02 11:29:18 +00001380 return ret_val;
1381}
1382
1383/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001384 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1385 * @hw: pointer to the HW structure
1386 **/
1387void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1388{
1389 u32 mac_reg;
1390 u16 i;
1391
1392 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1393 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1394 mac_reg = er32(RAL(i));
1395 e1e_wphy(hw, BM_RAR_L(i), (u16)(mac_reg & 0xFFFF));
1396 e1e_wphy(hw, BM_RAR_M(i), (u16)((mac_reg >> 16) & 0xFFFF));
1397 mac_reg = er32(RAH(i));
1398 e1e_wphy(hw, BM_RAR_H(i), (u16)(mac_reg & 0xFFFF));
1399 e1e_wphy(hw, BM_RAR_CTRL(i), (u16)((mac_reg >> 16) & 0x8000));
1400 }
1401}
1402
Bruce Alland3738bb2010-06-16 13:27:28 +00001403/**
1404 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1405 * with 82579 PHY
1406 * @hw: pointer to the HW structure
1407 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1408 **/
1409s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1410{
1411 s32 ret_val = 0;
1412 u16 phy_reg, data;
1413 u32 mac_reg;
1414 u16 i;
1415
1416 if (hw->mac.type != e1000_pch2lan)
1417 goto out;
1418
1419 /* disable Rx path while enabling/disabling workaround */
1420 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1421 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1422 if (ret_val)
1423 goto out;
1424
1425 if (enable) {
1426 /*
1427 * Write Rx addresses (rar_entry_count for RAL/H, +4 for
1428 * SHRAL/H) and initial CRC values to the MAC
1429 */
1430 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1431 u8 mac_addr[ETH_ALEN] = {0};
1432 u32 addr_high, addr_low;
1433
1434 addr_high = er32(RAH(i));
1435 if (!(addr_high & E1000_RAH_AV))
1436 continue;
1437 addr_low = er32(RAL(i));
1438 mac_addr[0] = (addr_low & 0xFF);
1439 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1440 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1441 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1442 mac_addr[4] = (addr_high & 0xFF);
1443 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1444
Bruce Allanfe46f582011-01-06 14:29:51 +00001445 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00001446 }
1447
1448 /* Write Rx addresses to the PHY */
1449 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1450
1451 /* Enable jumbo frame workaround in the MAC */
1452 mac_reg = er32(FFLT_DBG);
1453 mac_reg &= ~(1 << 14);
1454 mac_reg |= (7 << 15);
1455 ew32(FFLT_DBG, mac_reg);
1456
1457 mac_reg = er32(RCTL);
1458 mac_reg |= E1000_RCTL_SECRC;
1459 ew32(RCTL, mac_reg);
1460
1461 ret_val = e1000e_read_kmrn_reg(hw,
1462 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1463 &data);
1464 if (ret_val)
1465 goto out;
1466 ret_val = e1000e_write_kmrn_reg(hw,
1467 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1468 data | (1 << 0));
1469 if (ret_val)
1470 goto out;
1471 ret_val = e1000e_read_kmrn_reg(hw,
1472 E1000_KMRNCTRLSTA_HD_CTRL,
1473 &data);
1474 if (ret_val)
1475 goto out;
1476 data &= ~(0xF << 8);
1477 data |= (0xB << 8);
1478 ret_val = e1000e_write_kmrn_reg(hw,
1479 E1000_KMRNCTRLSTA_HD_CTRL,
1480 data);
1481 if (ret_val)
1482 goto out;
1483
1484 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001485 e1e_rphy(hw, PHY_REG(769, 23), &data);
1486 data &= ~(0x7F << 5);
1487 data |= (0x37 << 5);
1488 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1489 if (ret_val)
1490 goto out;
1491 e1e_rphy(hw, PHY_REG(769, 16), &data);
1492 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00001493 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1494 if (ret_val)
1495 goto out;
1496 e1e_rphy(hw, PHY_REG(776, 20), &data);
1497 data &= ~(0x3FF << 2);
1498 data |= (0x1A << 2);
1499 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1500 if (ret_val)
1501 goto out;
1502 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xFE00);
1503 if (ret_val)
1504 goto out;
1505 e1e_rphy(hw, HV_PM_CTRL, &data);
1506 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1507 if (ret_val)
1508 goto out;
1509 } else {
1510 /* Write MAC register values back to h/w defaults */
1511 mac_reg = er32(FFLT_DBG);
1512 mac_reg &= ~(0xF << 14);
1513 ew32(FFLT_DBG, mac_reg);
1514
1515 mac_reg = er32(RCTL);
1516 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00001517 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00001518
1519 ret_val = e1000e_read_kmrn_reg(hw,
1520 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1521 &data);
1522 if (ret_val)
1523 goto out;
1524 ret_val = e1000e_write_kmrn_reg(hw,
1525 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1526 data & ~(1 << 0));
1527 if (ret_val)
1528 goto out;
1529 ret_val = e1000e_read_kmrn_reg(hw,
1530 E1000_KMRNCTRLSTA_HD_CTRL,
1531 &data);
1532 if (ret_val)
1533 goto out;
1534 data &= ~(0xF << 8);
1535 data |= (0xB << 8);
1536 ret_val = e1000e_write_kmrn_reg(hw,
1537 E1000_KMRNCTRLSTA_HD_CTRL,
1538 data);
1539 if (ret_val)
1540 goto out;
1541
1542 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00001543 e1e_rphy(hw, PHY_REG(769, 23), &data);
1544 data &= ~(0x7F << 5);
1545 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1546 if (ret_val)
1547 goto out;
1548 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001549 data |= (1 << 13);
1550 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1551 if (ret_val)
1552 goto out;
1553 e1e_rphy(hw, PHY_REG(776, 20), &data);
1554 data &= ~(0x3FF << 2);
1555 data |= (0x8 << 2);
1556 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1557 if (ret_val)
1558 goto out;
1559 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
1560 if (ret_val)
1561 goto out;
1562 e1e_rphy(hw, HV_PM_CTRL, &data);
1563 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
1564 if (ret_val)
1565 goto out;
1566 }
1567
1568 /* re-enable Rx path after enabling/disabling workaround */
1569 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
1570
1571out:
1572 return ret_val;
1573}
1574
1575/**
1576 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1577 * done after every PHY reset.
1578 **/
1579static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1580{
1581 s32 ret_val = 0;
1582
1583 if (hw->mac.type != e1000_pch2lan)
1584 goto out;
1585
1586 /* Set MDIO slow mode before any other MDIO access */
1587 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1588
1589out:
1590 return ret_val;
1591}
1592
1593/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00001594 * e1000_k1_gig_workaround_lv - K1 Si workaround
1595 * @hw: pointer to the HW structure
1596 *
1597 * Workaround to set the K1 beacon duration for 82579 parts
1598 **/
1599static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
1600{
1601 s32 ret_val = 0;
1602 u16 status_reg = 0;
1603 u32 mac_reg;
1604
1605 if (hw->mac.type != e1000_pch2lan)
1606 goto out;
1607
1608 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
1609 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
1610 if (ret_val)
1611 goto out;
1612
1613 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
1614 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
1615 mac_reg = er32(FEXTNVM4);
1616 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
1617
1618 if (status_reg & HV_M_STATUS_SPEED_1000)
1619 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
1620 else
1621 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
1622
1623 ew32(FEXTNVM4, mac_reg);
1624 }
1625
1626out:
1627 return ret_val;
1628}
1629
1630/**
Bruce Allan605c82b2010-09-22 17:17:01 +00001631 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
1632 * @hw: pointer to the HW structure
1633 * @gate: boolean set to true to gate, false to ungate
1634 *
1635 * Gate/ungate the automatic PHY configuration via hardware; perform
1636 * the configuration via software instead.
1637 **/
1638static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
1639{
1640 u32 extcnf_ctrl;
1641
1642 if (hw->mac.type != e1000_pch2lan)
1643 return;
1644
1645 extcnf_ctrl = er32(EXTCNF_CTRL);
1646
1647 if (gate)
1648 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
1649 else
1650 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
1651
1652 ew32(EXTCNF_CTRL, extcnf_ctrl);
1653 return;
1654}
1655
1656/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00001657 * e1000_lan_init_done_ich8lan - Check for PHY config completion
1658 * @hw: pointer to the HW structure
1659 *
1660 * Check the appropriate indication the MAC has finished configuring the
1661 * PHY after a software reset.
1662 **/
1663static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
1664{
1665 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
1666
1667 /* Wait for basic configuration completes before proceeding */
1668 do {
1669 data = er32(STATUS);
1670 data &= E1000_STATUS_LAN_INIT_DONE;
1671 udelay(100);
1672 } while ((!data) && --loop);
1673
1674 /*
1675 * If basic configuration is incomplete before the above loop
1676 * count reaches 0, loading the configuration from NVM will
1677 * leave the PHY in a bad state possibly resulting in no link.
1678 */
1679 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001680 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00001681
1682 /* Clear the Init Done bit for the next init event */
1683 data = er32(STATUS);
1684 data &= ~E1000_STATUS_LAN_INIT_DONE;
1685 ew32(STATUS, data);
1686}
1687
1688/**
Bruce Allane98cac42010-05-10 15:02:32 +00001689 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07001691 **/
Bruce Allane98cac42010-05-10 15:02:32 +00001692static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001693{
Bruce Allanf523d212009-10-29 13:45:45 +00001694 s32 ret_val = 0;
1695 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696
Bruce Allane98cac42010-05-10 15:02:32 +00001697 if (e1000_check_reset_block(hw))
1698 goto out;
Bruce Allanfc0c7762009-07-01 13:27:55 +00001699
Bruce Allan5f3eed62010-09-22 17:15:54 +00001700 /* Allow time for h/w to get to quiescent state after reset */
1701 msleep(10);
1702
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001703 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00001704 switch (hw->mac.type) {
1705 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001706 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
1707 if (ret_val)
Bruce Allane98cac42010-05-10 15:02:32 +00001708 goto out;
1709 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001710 case e1000_pch2lan:
1711 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
1712 if (ret_val)
1713 goto out;
1714 break;
Bruce Allane98cac42010-05-10 15:02:32 +00001715 default:
1716 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00001717 }
1718
Bruce Allandb2932e2009-10-26 11:22:47 +00001719 /* Dummy read to clear the phy wakeup bit after lcd reset */
Bruce Alland3738bb2010-06-16 13:27:28 +00001720 if (hw->mac.type >= e1000_pchlan)
Bruce Allandb2932e2009-10-26 11:22:47 +00001721 e1e_rphy(hw, BM_WUC, &reg);
1722
Bruce Allanf523d212009-10-29 13:45:45 +00001723 /* Configure the LCD with the extended configuration region in NVM */
1724 ret_val = e1000_sw_lcd_config_ich8lan(hw);
1725 if (ret_val)
1726 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001727
Bruce Allanf523d212009-10-29 13:45:45 +00001728 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00001729 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730
Bruce Allan1effb452011-02-25 06:58:03 +00001731 if (hw->mac.type == e1000_pch2lan) {
1732 /* Ungate automatic PHY configuration on non-managed 82579 */
1733 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
1734 msleep(10);
1735 e1000_gate_hw_phy_config_ich8lan(hw, false);
1736 }
1737
1738 /* Set EEE LPI Update Timer to 200usec */
1739 ret_val = hw->phy.ops.acquire(hw);
1740 if (ret_val)
1741 goto out;
1742 ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_ADDR,
1743 I82579_LPI_UPDATE_TIMER);
1744 if (ret_val)
1745 goto release;
1746 ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_DATA,
1747 0x1387);
1748release:
1749 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00001750 }
1751
Bruce Allanf523d212009-10-29 13:45:45 +00001752out:
Bruce Allane98cac42010-05-10 15:02:32 +00001753 return ret_val;
1754}
1755
1756/**
1757 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
1758 * @hw: pointer to the HW structure
1759 *
1760 * Resets the PHY
1761 * This is a function pointer entry point called by drivers
1762 * or other shared routines.
1763 **/
1764static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
1765{
1766 s32 ret_val = 0;
1767
Bruce Allan605c82b2010-09-22 17:17:01 +00001768 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
1769 if ((hw->mac.type == e1000_pch2lan) &&
1770 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1771 e1000_gate_hw_phy_config_ich8lan(hw, true);
1772
Bruce Allane98cac42010-05-10 15:02:32 +00001773 ret_val = e1000e_phy_hw_reset_generic(hw);
1774 if (ret_val)
1775 goto out;
1776
1777 ret_val = e1000_post_phy_reset_ich8lan(hw);
1778
1779out:
1780 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001781}
1782
1783/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00001784 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1785 * @hw: pointer to the HW structure
1786 * @active: true to enable LPLU, false to disable
1787 *
1788 * Sets the LPLU state according to the active flag. For PCH, if OEM write
1789 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1790 * the phy speed. This function will manually set the LPLU bit and restart
1791 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
1792 * since it configures the same bit.
1793 **/
1794static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1795{
1796 s32 ret_val = 0;
1797 u16 oem_reg;
1798
1799 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
1800 if (ret_val)
1801 goto out;
1802
1803 if (active)
1804 oem_reg |= HV_OEM_BITS_LPLU;
1805 else
1806 oem_reg &= ~HV_OEM_BITS_LPLU;
1807
1808 oem_reg |= HV_OEM_BITS_RESTART_AN;
1809 ret_val = e1e_wphy(hw, HV_OEM_BITS, oem_reg);
1810
1811out:
1812 return ret_val;
1813}
1814
1815/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001816 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1817 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001818 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001819 *
1820 * Sets the LPLU D0 state according to the active flag. When
1821 * activating LPLU this function also disables smart speed
1822 * and vice versa. LPLU will not be activated unless the
1823 * device autonegotiation advertisement meets standards of
1824 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1825 * This is a function pointer entry point only called by
1826 * PHY setup routines.
1827 **/
1828static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1829{
1830 struct e1000_phy_info *phy = &hw->phy;
1831 u32 phy_ctrl;
1832 s32 ret_val = 0;
1833 u16 data;
1834
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001835 if (phy->type == e1000_phy_ife)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001836 return ret_val;
1837
1838 phy_ctrl = er32(PHY_CTRL);
1839
1840 if (active) {
1841 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
1842 ew32(PHY_CTRL, phy_ctrl);
1843
Bruce Allan60f12922009-07-01 13:28:14 +00001844 if (phy->type != e1000_phy_igp_3)
1845 return 0;
1846
Bruce Allanad680762008-03-28 09:15:03 -07001847 /*
1848 * Call gig speed drop workaround on LPLU before accessing
1849 * any PHY registers
1850 */
Bruce Allan60f12922009-07-01 13:28:14 +00001851 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001852 e1000e_gig_downshift_workaround_ich8lan(hw);
1853
1854 /* When LPLU is enabled, we should disable SmartSpeed */
1855 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1856 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1857 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1858 if (ret_val)
1859 return ret_val;
1860 } else {
1861 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
1862 ew32(PHY_CTRL, phy_ctrl);
1863
Bruce Allan60f12922009-07-01 13:28:14 +00001864 if (phy->type != e1000_phy_igp_3)
1865 return 0;
1866
Bruce Allanad680762008-03-28 09:15:03 -07001867 /*
1868 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001869 * during Dx states where the power conservation is most
1870 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001871 * SmartSpeed, so performance is maintained.
1872 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001873 if (phy->smart_speed == e1000_smart_speed_on) {
1874 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001875 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001876 if (ret_val)
1877 return ret_val;
1878
1879 data |= IGP01E1000_PSCFR_SMART_SPEED;
1880 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001881 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001882 if (ret_val)
1883 return ret_val;
1884 } else if (phy->smart_speed == e1000_smart_speed_off) {
1885 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001886 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001887 if (ret_val)
1888 return ret_val;
1889
1890 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1891 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001892 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001893 if (ret_val)
1894 return ret_val;
1895 }
1896 }
1897
1898 return 0;
1899}
1900
1901/**
1902 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
1903 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001904 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001905 *
1906 * Sets the LPLU D3 state according to the active flag. When
1907 * activating LPLU this function also disables smart speed
1908 * and vice versa. LPLU will not be activated unless the
1909 * device autonegotiation advertisement meets standards of
1910 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1911 * This is a function pointer entry point only called by
1912 * PHY setup routines.
1913 **/
1914static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1915{
1916 struct e1000_phy_info *phy = &hw->phy;
1917 u32 phy_ctrl;
1918 s32 ret_val;
1919 u16 data;
1920
1921 phy_ctrl = er32(PHY_CTRL);
1922
1923 if (!active) {
1924 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
1925 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00001926
1927 if (phy->type != e1000_phy_igp_3)
1928 return 0;
1929
Bruce Allanad680762008-03-28 09:15:03 -07001930 /*
1931 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001932 * during Dx states where the power conservation is most
1933 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001934 * SmartSpeed, so performance is maintained.
1935 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001936 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07001937 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1938 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001939 if (ret_val)
1940 return ret_val;
1941
1942 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001943 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1944 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001945 if (ret_val)
1946 return ret_val;
1947 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07001948 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1949 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001950 if (ret_val)
1951 return ret_val;
1952
1953 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001954 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1955 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956 if (ret_val)
1957 return ret_val;
1958 }
1959 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1960 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1961 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1962 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
1963 ew32(PHY_CTRL, phy_ctrl);
1964
Bruce Allan60f12922009-07-01 13:28:14 +00001965 if (phy->type != e1000_phy_igp_3)
1966 return 0;
1967
Bruce Allanad680762008-03-28 09:15:03 -07001968 /*
1969 * Call gig speed drop workaround on LPLU before accessing
1970 * any PHY registers
1971 */
Bruce Allan60f12922009-07-01 13:28:14 +00001972 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001973 e1000e_gig_downshift_workaround_ich8lan(hw);
1974
1975 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07001976 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977 if (ret_val)
1978 return ret_val;
1979
1980 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07001981 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001982 }
1983
1984 return 0;
1985}
1986
1987/**
Bruce Allanf4187b52008-08-26 18:36:50 -07001988 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
1989 * @hw: pointer to the HW structure
1990 * @bank: pointer to the variable that returns the active bank
1991 *
1992 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08001993 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07001994 **/
1995static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
1996{
Bruce Allane2434552008-11-21 17:02:41 -08001997 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07001998 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07001999 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2000 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002001 u8 sig_byte = 0;
2002 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002003
Bruce Allane2434552008-11-21 17:02:41 -08002004 switch (hw->mac.type) {
2005 case e1000_ich8lan:
2006 case e1000_ich9lan:
2007 eecd = er32(EECD);
2008 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2009 E1000_EECD_SEC1VAL_VALID_MASK) {
2010 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002011 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002012 else
2013 *bank = 0;
2014
2015 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002016 }
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002017 e_dbg("Unable to determine valid NVM bank via EEC - "
Bruce Allane2434552008-11-21 17:02:41 -08002018 "reading flash signature\n");
2019 /* fall-thru */
2020 default:
2021 /* set bank to 0 in case flash read fails */
2022 *bank = 0;
2023
2024 /* Check bank 0 */
2025 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
2026 &sig_byte);
2027 if (ret_val)
2028 return ret_val;
2029 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2030 E1000_ICH_NVM_SIG_VALUE) {
2031 *bank = 0;
2032 return 0;
2033 }
2034
2035 /* Check bank 1 */
2036 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
2037 bank1_offset,
2038 &sig_byte);
2039 if (ret_val)
2040 return ret_val;
2041 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2042 E1000_ICH_NVM_SIG_VALUE) {
2043 *bank = 1;
2044 return 0;
2045 }
2046
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002047 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002048 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002049 }
2050
2051 return 0;
2052}
2053
2054/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002055 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2056 * @hw: pointer to the HW structure
2057 * @offset: The offset (in bytes) of the word(s) to read.
2058 * @words: Size of data to read in words
2059 * @data: Pointer to the word(s) to read at offset.
2060 *
2061 * Reads a word(s) from the NVM using the flash access registers.
2062 **/
2063static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2064 u16 *data)
2065{
2066 struct e1000_nvm_info *nvm = &hw->nvm;
2067 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2068 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002069 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002070 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002071 u16 i, word;
2072
2073 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2074 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002075 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002076 ret_val = -E1000_ERR_NVM;
2077 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002078 }
2079
Bruce Allan94d81862009-11-20 23:25:26 +00002080 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002081
Bruce Allanf4187b52008-08-26 18:36:50 -07002082 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002083 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002084 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002085 bank = 0;
2086 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002087
2088 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002089 act_offset += offset;
2090
Bruce Allan148675a2009-08-07 07:41:56 +00002091 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002092 for (i = 0; i < words; i++) {
2093 if ((dev_spec->shadow_ram) &&
2094 (dev_spec->shadow_ram[offset+i].modified)) {
2095 data[i] = dev_spec->shadow_ram[offset+i].value;
2096 } else {
2097 ret_val = e1000_read_flash_word_ich8lan(hw,
2098 act_offset + i,
2099 &word);
2100 if (ret_val)
2101 break;
2102 data[i] = word;
2103 }
2104 }
2105
Bruce Allan94d81862009-11-20 23:25:26 +00002106 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002107
Bruce Allane2434552008-11-21 17:02:41 -08002108out:
2109 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002110 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002111
Auke Kokbc7f75f2007-09-17 12:30:59 -07002112 return ret_val;
2113}
2114
2115/**
2116 * e1000_flash_cycle_init_ich8lan - Initialize flash
2117 * @hw: pointer to the HW structure
2118 *
2119 * This function does initial flash setup so that a new read/write/erase cycle
2120 * can be started.
2121 **/
2122static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2123{
2124 union ich8_hws_flash_status hsfsts;
2125 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002126
2127 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2128
2129 /* Check if the flash descriptor is valid */
2130 if (hsfsts.hsf_status.fldesvalid == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002131 e_dbg("Flash descriptor invalid. "
Joe Perches2c73e1f2010-03-26 20:16:59 +00002132 "SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002133 return -E1000_ERR_NVM;
2134 }
2135
2136 /* Clear FCERR and DAEL in hw status by writing 1 */
2137 hsfsts.hsf_status.flcerr = 1;
2138 hsfsts.hsf_status.dael = 1;
2139
2140 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2141
Bruce Allanad680762008-03-28 09:15:03 -07002142 /*
2143 * Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002144 * bit to check against, in order to start a new cycle or
2145 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002146 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147 * indication whether a cycle is in progress or has been
2148 * completed.
2149 */
2150
2151 if (hsfsts.hsf_status.flcinprog == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07002152 /*
2153 * There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002154 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002155 * Begin by setting Flash Cycle Done.
2156 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002157 hsfsts.hsf_status.flcdone = 1;
2158 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2159 ret_val = 0;
2160 } else {
Bruce Allan90da0662011-01-06 07:02:53 +00002161 s32 i = 0;
2162
Bruce Allanad680762008-03-28 09:15:03 -07002163 /*
Bruce Allan5ff5b662009-12-01 15:51:11 +00002164 * Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002165 * cycle has a chance to end before giving up.
2166 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002167 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
2168 hsfsts.regval = __er16flash(hw, ICH_FLASH_HSFSTS);
2169 if (hsfsts.hsf_status.flcinprog == 0) {
2170 ret_val = 0;
2171 break;
2172 }
2173 udelay(1);
2174 }
2175 if (ret_val == 0) {
Bruce Allanad680762008-03-28 09:15:03 -07002176 /*
2177 * Successful in waiting for previous cycle to timeout,
2178 * now set the Flash Cycle Done.
2179 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002180 hsfsts.hsf_status.flcdone = 1;
2181 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2182 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002183 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002184 }
2185 }
2186
2187 return ret_val;
2188}
2189
2190/**
2191 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2192 * @hw: pointer to the HW structure
2193 * @timeout: maximum time to wait for completion
2194 *
2195 * This function starts a flash cycle and waits for its completion.
2196 **/
2197static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2198{
2199 union ich8_hws_flash_ctrl hsflctl;
2200 union ich8_hws_flash_status hsfsts;
2201 s32 ret_val = -E1000_ERR_NVM;
2202 u32 i = 0;
2203
2204 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2205 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2206 hsflctl.hsf_ctrl.flcgo = 1;
2207 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2208
2209 /* wait till FDONE bit is set to 1 */
2210 do {
2211 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2212 if (hsfsts.hsf_status.flcdone == 1)
2213 break;
2214 udelay(1);
2215 } while (i++ < timeout);
2216
2217 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
2218 return 0;
2219
2220 return ret_val;
2221}
2222
2223/**
2224 * e1000_read_flash_word_ich8lan - Read word from flash
2225 * @hw: pointer to the HW structure
2226 * @offset: offset to data location
2227 * @data: pointer to the location for storing the data
2228 *
2229 * Reads the flash word at offset into data. Offset is converted
2230 * to bytes before read.
2231 **/
2232static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2233 u16 *data)
2234{
2235 /* Must convert offset into bytes. */
2236 offset <<= 1;
2237
2238 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2239}
2240
2241/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002242 * e1000_read_flash_byte_ich8lan - Read byte from flash
2243 * @hw: pointer to the HW structure
2244 * @offset: The offset of the byte to read.
2245 * @data: Pointer to a byte to store the value read.
2246 *
2247 * Reads a single byte from the NVM using the flash access registers.
2248 **/
2249static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2250 u8 *data)
2251{
2252 s32 ret_val;
2253 u16 word = 0;
2254
2255 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2256 if (ret_val)
2257 return ret_val;
2258
2259 *data = (u8)word;
2260
2261 return 0;
2262}
2263
2264/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002265 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2266 * @hw: pointer to the HW structure
2267 * @offset: The offset (in bytes) of the byte or word to read.
2268 * @size: Size of data to read, 1=byte 2=word
2269 * @data: Pointer to the word to store the value read.
2270 *
2271 * Reads a byte or word from the NVM using the flash access registers.
2272 **/
2273static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2274 u8 size, u16 *data)
2275{
2276 union ich8_hws_flash_status hsfsts;
2277 union ich8_hws_flash_ctrl hsflctl;
2278 u32 flash_linear_addr;
2279 u32 flash_data = 0;
2280 s32 ret_val = -E1000_ERR_NVM;
2281 u8 count = 0;
2282
2283 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2284 return -E1000_ERR_NVM;
2285
2286 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2287 hw->nvm.flash_base_addr;
2288
2289 do {
2290 udelay(1);
2291 /* Steps */
2292 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2293 if (ret_val != 0)
2294 break;
2295
2296 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2297 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2298 hsflctl.hsf_ctrl.fldbcount = size - 1;
2299 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2300 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2301
2302 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2303
2304 ret_val = e1000_flash_cycle_ich8lan(hw,
2305 ICH_FLASH_READ_COMMAND_TIMEOUT);
2306
Bruce Allanad680762008-03-28 09:15:03 -07002307 /*
2308 * Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309 * and try the whole sequence a few more times, else
2310 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002311 * least significant byte first msb to lsb
2312 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313 if (ret_val == 0) {
2314 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002315 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002316 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002317 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002318 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319 break;
2320 } else {
Bruce Allanad680762008-03-28 09:15:03 -07002321 /*
2322 * If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002323 * completely hosed, but if the error condition is
2324 * detected, it won't hurt to give it another try...
2325 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2326 */
2327 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2328 if (hsfsts.hsf_status.flcerr == 1) {
2329 /* Repeat for some time before giving up. */
2330 continue;
2331 } else if (hsfsts.hsf_status.flcdone == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002332 e_dbg("Timeout error - flash cycle "
Joe Perches2c73e1f2010-03-26 20:16:59 +00002333 "did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334 break;
2335 }
2336 }
2337 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2338
2339 return ret_val;
2340}
2341
2342/**
2343 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2344 * @hw: pointer to the HW structure
2345 * @offset: The offset (in bytes) of the word(s) to write.
2346 * @words: Size of data to write in words
2347 * @data: Pointer to the word(s) to write at offset.
2348 *
2349 * Writes a byte or word to the NVM using the flash access registers.
2350 **/
2351static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2352 u16 *data)
2353{
2354 struct e1000_nvm_info *nvm = &hw->nvm;
2355 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356 u16 i;
2357
2358 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2359 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002360 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002361 return -E1000_ERR_NVM;
2362 }
2363
Bruce Allan94d81862009-11-20 23:25:26 +00002364 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002365
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002367 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002368 dev_spec->shadow_ram[offset+i].value = data[i];
2369 }
2370
Bruce Allan94d81862009-11-20 23:25:26 +00002371 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002372
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 return 0;
2374}
2375
2376/**
2377 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2378 * @hw: pointer to the HW structure
2379 *
2380 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2381 * which writes the checksum to the shadow ram. The changes in the shadow
2382 * ram are then committed to the EEPROM by processing each bank at a time
2383 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002384 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002385 * future writes.
2386 **/
2387static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2388{
2389 struct e1000_nvm_info *nvm = &hw->nvm;
2390 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002391 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392 s32 ret_val;
2393 u16 data;
2394
2395 ret_val = e1000e_update_nvm_checksum_generic(hw);
2396 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002397 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398
2399 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002400 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002401
Bruce Allan94d81862009-11-20 23:25:26 +00002402 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002403
Bruce Allanad680762008-03-28 09:15:03 -07002404 /*
2405 * We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002406 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002407 * is going to be written
2408 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002409 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002410 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002411 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002412 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002413 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002414
2415 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002416 new_bank_offset = nvm->flash_bank_size;
2417 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002418 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002419 if (ret_val)
2420 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002421 } else {
2422 old_bank_offset = nvm->flash_bank_size;
2423 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002424 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002425 if (ret_val)
2426 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002427 }
2428
2429 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allanad680762008-03-28 09:15:03 -07002430 /*
2431 * Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002432 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002433 * in the shadow RAM
2434 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002435 if (dev_spec->shadow_ram[i].modified) {
2436 data = dev_spec->shadow_ram[i].value;
2437 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002438 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2439 old_bank_offset,
2440 &data);
2441 if (ret_val)
2442 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002443 }
2444
Bruce Allanad680762008-03-28 09:15:03 -07002445 /*
2446 * If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002447 * (15:14) are 11b until the commit has completed.
2448 * This will allow us to write 10b which indicates the
2449 * signature is valid. We want to do this after the write
2450 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002451 * while the write is still in progress
2452 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002453 if (i == E1000_ICH_NVM_SIG_WORD)
2454 data |= E1000_ICH_NVM_SIG_MASK;
2455
2456 /* Convert offset to bytes. */
2457 act_offset = (i + new_bank_offset) << 1;
2458
2459 udelay(100);
2460 /* Write the bytes to the new bank. */
2461 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2462 act_offset,
2463 (u8)data);
2464 if (ret_val)
2465 break;
2466
2467 udelay(100);
2468 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2469 act_offset + 1,
2470 (u8)(data >> 8));
2471 if (ret_val)
2472 break;
2473 }
2474
Bruce Allanad680762008-03-28 09:15:03 -07002475 /*
2476 * Don't bother writing the segment valid bits if sector
2477 * programming failed.
2478 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002479 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002480 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002481 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002482 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 }
2484
Bruce Allanad680762008-03-28 09:15:03 -07002485 /*
2486 * Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002487 * to 10b in word 0x13 , this can be done without an
2488 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002489 * and we need to change bit 14 to 0b
2490 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002491 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002492 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002493 if (ret_val)
2494 goto release;
2495
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496 data &= 0xBFFF;
2497 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2498 act_offset * 2 + 1,
2499 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002500 if (ret_val)
2501 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502
Bruce Allanad680762008-03-28 09:15:03 -07002503 /*
2504 * And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002505 * its signature word (0x13) high_byte to 0b. This can be
2506 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002507 * to 1's. We can write 1's to 0's without an erase
2508 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2510 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002511 if (ret_val)
2512 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002513
2514 /* Great! Everything worked, we can now clear the cached entries. */
2515 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002516 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517 dev_spec->shadow_ram[i].value = 0xFFFF;
2518 }
2519
Bruce Allan9c5e2092010-05-10 15:00:31 +00002520release:
Bruce Allan94d81862009-11-20 23:25:26 +00002521 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002522
Bruce Allanad680762008-03-28 09:15:03 -07002523 /*
2524 * Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002525 * until after the next adapter reset.
2526 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002527 if (!ret_val) {
2528 e1000e_reload_nvm(hw);
2529 msleep(10);
2530 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002531
Bruce Allane2434552008-11-21 17:02:41 -08002532out:
2533 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002534 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002535
Auke Kokbc7f75f2007-09-17 12:30:59 -07002536 return ret_val;
2537}
2538
2539/**
2540 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2541 * @hw: pointer to the HW structure
2542 *
2543 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2544 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
2545 * calculated, in which case we need to calculate the checksum and set bit 6.
2546 **/
2547static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2548{
2549 s32 ret_val;
2550 u16 data;
2551
Bruce Allanad680762008-03-28 09:15:03 -07002552 /*
2553 * Read 0x19 and check bit 6. If this bit is 0, the checksum
Auke Kokbc7f75f2007-09-17 12:30:59 -07002554 * needs to be fixed. This bit is an indication that the NVM
2555 * was prepared by OEM software and did not calculate the
2556 * checksum...a likely scenario.
2557 */
2558 ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
2559 if (ret_val)
2560 return ret_val;
2561
2562 if ((data & 0x40) == 0) {
2563 data |= 0x40;
2564 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
2565 if (ret_val)
2566 return ret_val;
2567 ret_val = e1000e_update_nvm_checksum(hw);
2568 if (ret_val)
2569 return ret_val;
2570 }
2571
2572 return e1000e_validate_nvm_checksum_generic(hw);
2573}
2574
2575/**
Bruce Allan4a770352008-10-01 17:18:35 -07002576 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
2577 * @hw: pointer to the HW structure
2578 *
2579 * To prevent malicious write/erase of the NVM, set it to be read-only
2580 * so that the hardware ignores all write/erase cycles of the NVM via
2581 * the flash control registers. The shadow-ram copy of the NVM will
2582 * still be updated, however any updates to this copy will not stick
2583 * across driver reloads.
2584 **/
2585void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
2586{
Bruce Allanca15df52009-10-26 11:23:43 +00002587 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07002588 union ich8_flash_protected_range pr0;
2589 union ich8_hws_flash_status hsfsts;
2590 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07002591
Bruce Allan94d81862009-11-20 23:25:26 +00002592 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002593
2594 gfpreg = er32flash(ICH_FLASH_GFPREG);
2595
2596 /* Write-protect GbE Sector of NVM */
2597 pr0.regval = er32flash(ICH_FLASH_PR0);
2598 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
2599 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
2600 pr0.range.wpe = true;
2601 ew32flash(ICH_FLASH_PR0, pr0.regval);
2602
2603 /*
2604 * Lock down a subset of GbE Flash Control Registers, e.g.
2605 * PR0 to prevent the write-protection from being lifted.
2606 * Once FLOCKDN is set, the registers protected by it cannot
2607 * be written until FLOCKDN is cleared by a hardware reset.
2608 */
2609 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2610 hsfsts.hsf_status.flockdn = true;
2611 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2612
Bruce Allan94d81862009-11-20 23:25:26 +00002613 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002614}
2615
2616/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002617 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
2618 * @hw: pointer to the HW structure
2619 * @offset: The offset (in bytes) of the byte/word to read.
2620 * @size: Size of data to read, 1=byte 2=word
2621 * @data: The byte(s) to write to the NVM.
2622 *
2623 * Writes one/two bytes to the NVM using the flash access registers.
2624 **/
2625static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2626 u8 size, u16 data)
2627{
2628 union ich8_hws_flash_status hsfsts;
2629 union ich8_hws_flash_ctrl hsflctl;
2630 u32 flash_linear_addr;
2631 u32 flash_data = 0;
2632 s32 ret_val;
2633 u8 count = 0;
2634
2635 if (size < 1 || size > 2 || data > size * 0xff ||
2636 offset > ICH_FLASH_LINEAR_ADDR_MASK)
2637 return -E1000_ERR_NVM;
2638
2639 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2640 hw->nvm.flash_base_addr;
2641
2642 do {
2643 udelay(1);
2644 /* Steps */
2645 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2646 if (ret_val)
2647 break;
2648
2649 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2650 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2651 hsflctl.hsf_ctrl.fldbcount = size -1;
2652 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
2653 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2654
2655 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2656
2657 if (size == 1)
2658 flash_data = (u32)data & 0x00FF;
2659 else
2660 flash_data = (u32)data;
2661
2662 ew32flash(ICH_FLASH_FDATA0, flash_data);
2663
Bruce Allanad680762008-03-28 09:15:03 -07002664 /*
2665 * check if FCERR is set to 1 , if set to 1, clear it
2666 * and try the whole sequence a few more times else done
2667 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002668 ret_val = e1000_flash_cycle_ich8lan(hw,
2669 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
2670 if (!ret_val)
2671 break;
2672
Bruce Allanad680762008-03-28 09:15:03 -07002673 /*
2674 * If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07002675 * completely hosed, but if the error condition
2676 * is detected, it won't hurt to give it another
2677 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
2678 */
2679 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2680 if (hsfsts.hsf_status.flcerr == 1)
2681 /* Repeat for some time before giving up. */
2682 continue;
2683 if (hsfsts.hsf_status.flcdone == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002684 e_dbg("Timeout error - flash cycle "
Auke Kokbc7f75f2007-09-17 12:30:59 -07002685 "did not complete.");
2686 break;
2687 }
2688 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2689
2690 return ret_val;
2691}
2692
2693/**
2694 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
2695 * @hw: pointer to the HW structure
2696 * @offset: The index of the byte to read.
2697 * @data: The byte to write to the NVM.
2698 *
2699 * Writes a single byte to the NVM using the flash access registers.
2700 **/
2701static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2702 u8 data)
2703{
2704 u16 word = (u16)data;
2705
2706 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
2707}
2708
2709/**
2710 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
2711 * @hw: pointer to the HW structure
2712 * @offset: The offset of the byte to write.
2713 * @byte: The byte to write to the NVM.
2714 *
2715 * Writes a single byte to the NVM using the flash access registers.
2716 * Goes through a retry algorithm before giving up.
2717 **/
2718static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
2719 u32 offset, u8 byte)
2720{
2721 s32 ret_val;
2722 u16 program_retries;
2723
2724 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2725 if (!ret_val)
2726 return ret_val;
2727
2728 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002729 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002730 udelay(100);
2731 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2732 if (!ret_val)
2733 break;
2734 }
2735 if (program_retries == 100)
2736 return -E1000_ERR_NVM;
2737
2738 return 0;
2739}
2740
2741/**
2742 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
2743 * @hw: pointer to the HW structure
2744 * @bank: 0 for first bank, 1 for second bank, etc.
2745 *
2746 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
2747 * bank N is 4096 * N + flash_reg_addr.
2748 **/
2749static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
2750{
2751 struct e1000_nvm_info *nvm = &hw->nvm;
2752 union ich8_hws_flash_status hsfsts;
2753 union ich8_hws_flash_ctrl hsflctl;
2754 u32 flash_linear_addr;
2755 /* bank size is in 16bit words - adjust to bytes */
2756 u32 flash_bank_size = nvm->flash_bank_size * 2;
2757 s32 ret_val;
2758 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00002759 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002760
2761 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2762
Bruce Allanad680762008-03-28 09:15:03 -07002763 /*
2764 * Determine HW Sector size: Read BERASE bits of hw flash status
2765 * register
2766 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07002767 * consecutive sectors. The start index for the nth Hw sector
2768 * can be calculated as = bank * 4096 + n * 256
2769 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
2770 * The start index for the nth Hw sector can be calculated
2771 * as = bank * 4096
2772 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
2773 * (ich9 only, otherwise error condition)
2774 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
2775 */
2776 switch (hsfsts.hsf_status.berasesz) {
2777 case 0:
2778 /* Hw sector size 256 */
2779 sector_size = ICH_FLASH_SEG_SIZE_256;
2780 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
2781 break;
2782 case 1:
2783 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00002784 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002785 break;
2786 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00002787 sector_size = ICH_FLASH_SEG_SIZE_8K;
2788 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002789 break;
2790 case 3:
2791 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00002792 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002793 break;
2794 default:
2795 return -E1000_ERR_NVM;
2796 }
2797
2798 /* Start with the base address, then add the sector offset. */
2799 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00002800 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801
2802 for (j = 0; j < iteration ; j++) {
2803 do {
2804 /* Steps */
2805 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2806 if (ret_val)
2807 return ret_val;
2808
Bruce Allanad680762008-03-28 09:15:03 -07002809 /*
2810 * Write a value 11 (block Erase) in Flash
2811 * Cycle field in hw flash control
2812 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2814 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
2815 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2816
Bruce Allanad680762008-03-28 09:15:03 -07002817 /*
2818 * Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819 * block into Flash Linear address field in Flash
2820 * Address.
2821 */
2822 flash_linear_addr += (j * sector_size);
2823 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2824
2825 ret_val = e1000_flash_cycle_ich8lan(hw,
2826 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
2827 if (ret_val == 0)
2828 break;
2829
Bruce Allanad680762008-03-28 09:15:03 -07002830 /*
2831 * Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07002833 * a few more times else Done
2834 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2836 if (hsfsts.hsf_status.flcerr == 1)
Bruce Allanad680762008-03-28 09:15:03 -07002837 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838 continue;
2839 else if (hsfsts.hsf_status.flcdone == 0)
2840 return ret_val;
2841 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
2842 }
2843
2844 return 0;
2845}
2846
2847/**
2848 * e1000_valid_led_default_ich8lan - Set the default LED settings
2849 * @hw: pointer to the HW structure
2850 * @data: Pointer to the LED settings
2851 *
2852 * Reads the LED default settings from the NVM to data. If the NVM LED
2853 * settings is all 0's or F's, set the LED default to a valid LED default
2854 * setting.
2855 **/
2856static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
2857{
2858 s32 ret_val;
2859
2860 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
2861 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002862 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002863 return ret_val;
2864 }
2865
2866 if (*data == ID_LED_RESERVED_0000 ||
2867 *data == ID_LED_RESERVED_FFFF)
2868 *data = ID_LED_DEFAULT_ICH8LAN;
2869
2870 return 0;
2871}
2872
2873/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002874 * e1000_id_led_init_pchlan - store LED configurations
2875 * @hw: pointer to the HW structure
2876 *
2877 * PCH does not control LEDs via the LEDCTL register, rather it uses
2878 * the PHY LED configuration register.
2879 *
2880 * PCH also does not have an "always on" or "always off" mode which
2881 * complicates the ID feature. Instead of using the "on" mode to indicate
2882 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init()),
2883 * use "link_up" mode. The LEDs will still ID on request if there is no
2884 * link based on logic in e1000_led_[on|off]_pchlan().
2885 **/
2886static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
2887{
2888 struct e1000_mac_info *mac = &hw->mac;
2889 s32 ret_val;
2890 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
2891 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
2892 u16 data, i, temp, shift;
2893
2894 /* Get default ID LED modes */
2895 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
2896 if (ret_val)
2897 goto out;
2898
2899 mac->ledctl_default = er32(LEDCTL);
2900 mac->ledctl_mode1 = mac->ledctl_default;
2901 mac->ledctl_mode2 = mac->ledctl_default;
2902
2903 for (i = 0; i < 4; i++) {
2904 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
2905 shift = (i * 5);
2906 switch (temp) {
2907 case ID_LED_ON1_DEF2:
2908 case ID_LED_ON1_ON2:
2909 case ID_LED_ON1_OFF2:
2910 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2911 mac->ledctl_mode1 |= (ledctl_on << shift);
2912 break;
2913 case ID_LED_OFF1_DEF2:
2914 case ID_LED_OFF1_ON2:
2915 case ID_LED_OFF1_OFF2:
2916 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2917 mac->ledctl_mode1 |= (ledctl_off << shift);
2918 break;
2919 default:
2920 /* Do nothing */
2921 break;
2922 }
2923 switch (temp) {
2924 case ID_LED_DEF1_ON2:
2925 case ID_LED_ON1_ON2:
2926 case ID_LED_OFF1_ON2:
2927 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2928 mac->ledctl_mode2 |= (ledctl_on << shift);
2929 break;
2930 case ID_LED_DEF1_OFF2:
2931 case ID_LED_ON1_OFF2:
2932 case ID_LED_OFF1_OFF2:
2933 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2934 mac->ledctl_mode2 |= (ledctl_off << shift);
2935 break;
2936 default:
2937 /* Do nothing */
2938 break;
2939 }
2940 }
2941
2942out:
2943 return ret_val;
2944}
2945
2946/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
2948 * @hw: pointer to the HW structure
2949 *
2950 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
2951 * register, so the the bus width is hard coded.
2952 **/
2953static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
2954{
2955 struct e1000_bus_info *bus = &hw->bus;
2956 s32 ret_val;
2957
2958 ret_val = e1000e_get_bus_info_pcie(hw);
2959
Bruce Allanad680762008-03-28 09:15:03 -07002960 /*
2961 * ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07002962 * a configuration space, but do not contain
2963 * PCI Express Capability registers, so bus width
2964 * must be hardcoded.
2965 */
2966 if (bus->width == e1000_bus_width_unknown)
2967 bus->width = e1000_bus_width_pcie_x1;
2968
2969 return ret_val;
2970}
2971
2972/**
2973 * e1000_reset_hw_ich8lan - Reset the hardware
2974 * @hw: pointer to the HW structure
2975 *
2976 * Does a full reset of the hardware which includes a reset of the PHY and
2977 * MAC.
2978 **/
2979static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2980{
Bruce Allan1d5846b2009-10-29 13:46:05 +00002981 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allandb2932e2009-10-26 11:22:47 +00002982 u16 reg;
Bruce Allandd93f952011-01-06 14:29:48 +00002983 u32 ctrl, kab;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002984 s32 ret_val;
2985
Bruce Allanad680762008-03-28 09:15:03 -07002986 /*
2987 * Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07002988 * on the last TLP read/write transaction when MAC is reset.
2989 */
2990 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00002991 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002992 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002993
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002994 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002995 ew32(IMC, 0xffffffff);
2996
Bruce Allanad680762008-03-28 09:15:03 -07002997 /*
2998 * Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07002999 * any pending transactions to complete before we hit the MAC
3000 * with the global reset.
3001 */
3002 ew32(RCTL, 0);
3003 ew32(TCTL, E1000_TCTL_PSP);
3004 e1e_flush();
3005
3006 msleep(10);
3007
3008 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3009 if (hw->mac.type == e1000_ich8lan) {
3010 /* Set Tx and Rx buffer allocation to 8k apiece. */
3011 ew32(PBA, E1000_PBA_8K);
3012 /* Set Packet Buffer Size to 16k. */
3013 ew32(PBS, E1000_PBS_16K);
3014 }
3015
Bruce Allan1d5846b2009-10-29 13:46:05 +00003016 if (hw->mac.type == e1000_pchlan) {
3017 /* Save the NVM K1 bit setting*/
3018 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &reg);
3019 if (ret_val)
3020 return ret_val;
3021
3022 if (reg & E1000_NVM_K1_ENABLE)
3023 dev_spec->nvm_k1_enabled = true;
3024 else
3025 dev_spec->nvm_k1_enabled = false;
3026 }
3027
Auke Kokbc7f75f2007-09-17 12:30:59 -07003028 ctrl = er32(CTRL);
3029
3030 if (!e1000_check_reset_block(hw)) {
Bruce Allanad680762008-03-28 09:15:03 -07003031 /*
Bruce Allane98cac42010-05-10 15:02:32 +00003032 * Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003033 * time to make sure the interface between MAC and the
3034 * external PHY is reset.
3035 */
3036 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003037
3038 /*
3039 * Gate automatic PHY configuration by hardware on
3040 * non-managed 82579
3041 */
3042 if ((hw->mac.type == e1000_pch2lan) &&
3043 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3044 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003045 }
3046 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003047 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003048 ew32(CTRL, (ctrl | E1000_CTRL_RST));
3049 msleep(20);
3050
Bruce Allanfc0c7762009-07-01 13:27:55 +00003051 if (!ret_val)
Jeff Kirsher30bb0e02008-12-11 21:28:11 -08003052 e1000_release_swflag_ich8lan(hw);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003053
Bruce Allane98cac42010-05-10 15:02:32 +00003054 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003055 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003056 if (ret_val)
3057 goto out;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003058
Bruce Allane98cac42010-05-10 15:02:32 +00003059 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003060 if (ret_val)
3061 goto out;
3062 }
Bruce Allane98cac42010-05-10 15:02:32 +00003063
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003064 /*
3065 * For PCH, this write will make sure that any noise
3066 * will be detected as a CRC error and be dropped rather than show up
3067 * as a bad packet to the DMA engine.
3068 */
3069 if (hw->mac.type == e1000_pchlan)
3070 ew32(CRC_OFFSET, 0x65656565);
3071
Auke Kokbc7f75f2007-09-17 12:30:59 -07003072 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003073 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003074
3075 kab = er32(KABGTXD);
3076 kab |= E1000_KABGTXD_BGSQLBIAS;
3077 ew32(KABGTXD, kab);
3078
Bruce Allanf523d212009-10-29 13:45:45 +00003079out:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003080 return ret_val;
3081}
3082
3083/**
3084 * e1000_init_hw_ich8lan - Initialize the hardware
3085 * @hw: pointer to the HW structure
3086 *
3087 * Prepares the hardware for transmit and receive by doing the following:
3088 * - initialize hardware bits
3089 * - initialize LED identification
3090 * - setup receive address registers
3091 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003092 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093 * - clear statistics
3094 **/
3095static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3096{
3097 struct e1000_mac_info *mac = &hw->mac;
3098 u32 ctrl_ext, txdctl, snoop;
3099 s32 ret_val;
3100 u16 i;
3101
3102 e1000_initialize_hw_bits_ich8lan(hw);
3103
3104 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003105 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00003106 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003107 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00003108 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003109
3110 /* Setup the receive address. */
3111 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3112
3113 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003114 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003115 for (i = 0; i < mac->mta_reg_count; i++)
3116 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3117
Bruce Allanfc0c7762009-07-01 13:27:55 +00003118 /*
3119 * The 82578 Rx buffer will stall if wakeup is enabled in host and
3120 * the ME. Reading the BM_WUC register will clear the host wakeup bit.
3121 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3122 */
3123 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan482fed82011-01-06 14:29:49 +00003124 e1e_rphy(hw, BM_WUC, &i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003125 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3126 if (ret_val)
3127 return ret_val;
3128 }
3129
Auke Kokbc7f75f2007-09-17 12:30:59 -07003130 /* Setup link and flow control */
3131 ret_val = e1000_setup_link_ich8lan(hw);
3132
3133 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003134 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003135 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3136 E1000_TXDCTL_FULL_TX_DESC_WB;
3137 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3138 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003139 ew32(TXDCTL(0), txdctl);
3140 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003141 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3142 E1000_TXDCTL_FULL_TX_DESC_WB;
3143 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3144 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003145 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146
Bruce Allanad680762008-03-28 09:15:03 -07003147 /*
3148 * ICH8 has opposite polarity of no_snoop bits.
3149 * By default, we should use snoop behavior.
3150 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003151 if (mac->type == e1000_ich8lan)
3152 snoop = PCIE_ICH8_SNOOP_ALL;
3153 else
3154 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
3155 e1000e_set_pcie_no_snoop(hw, snoop);
3156
3157 ctrl_ext = er32(CTRL_EXT);
3158 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3159 ew32(CTRL_EXT, ctrl_ext);
3160
Bruce Allanad680762008-03-28 09:15:03 -07003161 /*
3162 * Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003163 * important that we do this after we have tried to establish link
3164 * because the symbol error count will increment wildly if there
3165 * is no link.
3166 */
3167 e1000_clear_hw_cntrs_ich8lan(hw);
3168
3169 return 0;
3170}
3171/**
3172 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3173 * @hw: pointer to the HW structure
3174 *
3175 * Sets/Clears required hardware bits necessary for correctly setting up the
3176 * hardware for transmit and receive.
3177 **/
3178static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3179{
3180 u32 reg;
3181
3182 /* Extended Device Control */
3183 reg = er32(CTRL_EXT);
3184 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003185 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3186 if (hw->mac.type >= e1000_pchlan)
3187 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003188 ew32(CTRL_EXT, reg);
3189
3190 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003191 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003192 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003193 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003194
3195 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003196 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003197 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003198 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003199
3200 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003201 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003202 if (hw->mac.type == e1000_ich8lan)
3203 reg |= (1 << 28) | (1 << 29);
3204 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003205 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003206
3207 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003208 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003209 if (er32(TCTL) & E1000_TCTL_MULR)
3210 reg &= ~(1 << 28);
3211 else
3212 reg |= (1 << 28);
3213 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003214 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003215
3216 /* Device Status */
3217 if (hw->mac.type == e1000_ich8lan) {
3218 reg = er32(STATUS);
3219 reg &= ~(1 << 31);
3220 ew32(STATUS, reg);
3221 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003222
3223 /*
3224 * work-around descriptor data corruption issue during nfs v2 udp
3225 * traffic, just disable the nfs filtering capability
3226 */
3227 reg = er32(RFCTL);
3228 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
3229 ew32(RFCTL, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003230}
3231
3232/**
3233 * e1000_setup_link_ich8lan - Setup flow control and link settings
3234 * @hw: pointer to the HW structure
3235 *
3236 * Determines which flow control settings to use, then configures flow
3237 * control. Calls the appropriate media-specific link configuration
3238 * function. Assuming the adapter has a valid link partner, a valid link
3239 * should be established. Assumes the hardware has previously been reset
3240 * and the transmitter and receiver are not enabled.
3241 **/
3242static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3243{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003244 s32 ret_val;
3245
3246 if (e1000_check_reset_block(hw))
3247 return 0;
3248
Bruce Allanad680762008-03-28 09:15:03 -07003249 /*
3250 * ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003251 * the default flow control setting, so we explicitly
3252 * set it to full.
3253 */
Bruce Allan37289d92009-06-02 11:29:37 +00003254 if (hw->fc.requested_mode == e1000_fc_default) {
3255 /* Workaround h/w hang when Tx flow control enabled */
3256 if (hw->mac.type == e1000_pchlan)
3257 hw->fc.requested_mode = e1000_fc_rx_pause;
3258 else
3259 hw->fc.requested_mode = e1000_fc_full;
3260 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003261
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003262 /*
3263 * Save off the requested flow control mode for use later. Depending
3264 * on the link partner's capabilities, we may or may not use this mode.
3265 */
3266 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003267
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003268 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003269 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003270
3271 /* Continue to configure the copper link. */
3272 ret_val = e1000_setup_copper_link_ich8lan(hw);
3273 if (ret_val)
3274 return ret_val;
3275
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003276 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003277 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003278 (hw->phy.type == e1000_phy_82579) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003279 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003280 ew32(FCRTV_PCH, hw->fc.refresh_time);
3281
Bruce Allan482fed82011-01-06 14:29:49 +00003282 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3283 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003284 if (ret_val)
3285 return ret_val;
3286 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003287
3288 return e1000e_set_fc_watermarks(hw);
3289}
3290
3291/**
3292 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3293 * @hw: pointer to the HW structure
3294 *
3295 * Configures the kumeran interface to the PHY to wait the appropriate time
3296 * when polling the PHY, then call the generic setup_copper_link to finish
3297 * configuring the copper link.
3298 **/
3299static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3300{
3301 u32 ctrl;
3302 s32 ret_val;
3303 u16 reg_data;
3304
3305 ctrl = er32(CTRL);
3306 ctrl |= E1000_CTRL_SLU;
3307 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3308 ew32(CTRL, ctrl);
3309
Bruce Allanad680762008-03-28 09:15:03 -07003310 /*
3311 * Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003312 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003313 * this fixes erroneous timeouts at 10Mbps.
3314 */
Bruce Allan07818952009-12-08 07:28:01 +00003315 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003316 if (ret_val)
3317 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003318 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3319 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003320 if (ret_val)
3321 return ret_val;
3322 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003323 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3324 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003325 if (ret_val)
3326 return ret_val;
3327
Bruce Allana4f58f52009-06-02 11:29:18 +00003328 switch (hw->phy.type) {
3329 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003330 ret_val = e1000e_copper_link_setup_igp(hw);
3331 if (ret_val)
3332 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003333 break;
3334 case e1000_phy_bm:
3335 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003336 ret_val = e1000e_copper_link_setup_m88(hw);
3337 if (ret_val)
3338 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003339 break;
3340 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003341 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00003342 ret_val = e1000_copper_link_setup_82577(hw);
3343 if (ret_val)
3344 return ret_val;
3345 break;
3346 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003347 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003348 if (ret_val)
3349 return ret_val;
3350
3351 reg_data &= ~IFE_PMC_AUTO_MDIX;
3352
3353 switch (hw->phy.mdix) {
3354 case 1:
3355 reg_data &= ~IFE_PMC_FORCE_MDIX;
3356 break;
3357 case 2:
3358 reg_data |= IFE_PMC_FORCE_MDIX;
3359 break;
3360 case 0:
3361 default:
3362 reg_data |= IFE_PMC_AUTO_MDIX;
3363 break;
3364 }
Bruce Allan482fed82011-01-06 14:29:49 +00003365 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003366 if (ret_val)
3367 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003368 break;
3369 default:
3370 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003371 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003372 return e1000e_setup_copper_link(hw);
3373}
3374
3375/**
3376 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3377 * @hw: pointer to the HW structure
3378 * @speed: pointer to store current link speed
3379 * @duplex: pointer to store the current link duplex
3380 *
Bruce Allanad680762008-03-28 09:15:03 -07003381 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003382 * information and then calls the Kumeran lock loss workaround for links at
3383 * gigabit speeds.
3384 **/
3385static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3386 u16 *duplex)
3387{
3388 s32 ret_val;
3389
3390 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3391 if (ret_val)
3392 return ret_val;
3393
3394 if ((hw->mac.type == e1000_ich8lan) &&
3395 (hw->phy.type == e1000_phy_igp_3) &&
3396 (*speed == SPEED_1000)) {
3397 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3398 }
3399
3400 return ret_val;
3401}
3402
3403/**
3404 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3405 * @hw: pointer to the HW structure
3406 *
3407 * Work-around for 82566 Kumeran PCS lock loss:
3408 * On link status change (i.e. PCI reset, speed change) and link is up and
3409 * speed is gigabit-
3410 * 0) if workaround is optionally disabled do nothing
3411 * 1) wait 1ms for Kumeran link to come up
3412 * 2) check Kumeran Diagnostic register PCS lock loss bit
3413 * 3) if not set the link is locked (all is good), otherwise...
3414 * 4) reset the PHY
3415 * 5) repeat up to 10 times
3416 * Note: this is only called for IGP3 copper when speed is 1gb.
3417 **/
3418static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3419{
3420 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3421 u32 phy_ctrl;
3422 s32 ret_val;
3423 u16 i, data;
3424 bool link;
3425
3426 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3427 return 0;
3428
Bruce Allanad680762008-03-28 09:15:03 -07003429 /*
3430 * Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003431 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003432 * stability
3433 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003434 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3435 if (!link)
3436 return 0;
3437
3438 for (i = 0; i < 10; i++) {
3439 /* read once to clear */
3440 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3441 if (ret_val)
3442 return ret_val;
3443 /* and again to get new status */
3444 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3445 if (ret_val)
3446 return ret_val;
3447
3448 /* check for PCS lock */
3449 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3450 return 0;
3451
3452 /* Issue PHY reset */
3453 e1000_phy_hw_reset(hw);
3454 mdelay(5);
3455 }
3456 /* Disable GigE link negotiation */
3457 phy_ctrl = er32(PHY_CTRL);
3458 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3459 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3460 ew32(PHY_CTRL, phy_ctrl);
3461
Bruce Allanad680762008-03-28 09:15:03 -07003462 /*
3463 * Call gig speed drop workaround on Gig disable before accessing
3464 * any PHY registers
3465 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003466 e1000e_gig_downshift_workaround_ich8lan(hw);
3467
3468 /* unable to acquire PCS lock */
3469 return -E1000_ERR_PHY;
3470}
3471
3472/**
Bruce Allanad680762008-03-28 09:15:03 -07003473 * e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003474 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003475 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003476 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003477 * If ICH8, set the current Kumeran workaround state (enabled - true
3478 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003479 **/
3480void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3481 bool state)
3482{
3483 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3484
3485 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003486 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003487 return;
3488 }
3489
3490 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3491}
3492
3493/**
3494 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3495 * @hw: pointer to the HW structure
3496 *
3497 * Workaround for 82566 power-down on D3 entry:
3498 * 1) disable gigabit link
3499 * 2) write VR power-down enable
3500 * 3) read it back
3501 * Continue if successful, else issue LCD reset and repeat
3502 **/
3503void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3504{
3505 u32 reg;
3506 u16 data;
3507 u8 retry = 0;
3508
3509 if (hw->phy.type != e1000_phy_igp_3)
3510 return;
3511
3512 /* Try the workaround twice (if needed) */
3513 do {
3514 /* Disable link */
3515 reg = er32(PHY_CTRL);
3516 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3517 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3518 ew32(PHY_CTRL, reg);
3519
Bruce Allanad680762008-03-28 09:15:03 -07003520 /*
3521 * Call gig speed drop workaround on Gig disable before
3522 * accessing any PHY registers
3523 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003524 if (hw->mac.type == e1000_ich8lan)
3525 e1000e_gig_downshift_workaround_ich8lan(hw);
3526
3527 /* Write VR power-down enable */
3528 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3529 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3530 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
3531
3532 /* Read it back and test */
3533 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3534 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3535 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
3536 break;
3537
3538 /* Issue PHY reset and repeat at most one more time */
3539 reg = er32(CTRL);
3540 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
3541 retry++;
3542 } while (retry);
3543}
3544
3545/**
3546 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
3547 * @hw: pointer to the HW structure
3548 *
3549 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08003550 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07003551 * 1) Set Kumeran Near-end loopback
3552 * 2) Clear Kumeran Near-end loopback
3553 * Should only be called for ICH8[m] devices with IGP_3 Phy.
3554 **/
3555void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
3556{
3557 s32 ret_val;
3558 u16 reg_data;
3559
3560 if ((hw->mac.type != e1000_ich8lan) ||
3561 (hw->phy.type != e1000_phy_igp_3))
3562 return;
3563
3564 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3565 &reg_data);
3566 if (ret_val)
3567 return;
3568 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
3569 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3570 reg_data);
3571 if (ret_val)
3572 return;
3573 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
3574 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3575 reg_data);
3576}
3577
3578/**
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003579 * e1000e_disable_gig_wol_ich8lan - disable gig during WoL
3580 * @hw: pointer to the HW structure
3581 *
3582 * During S0 to Sx transition, it is possible the link remains at gig
3583 * instead of negotiating to a lower speed. Before going to Sx, set
3584 * 'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
3585 * to a lower speed.
3586 *
Bruce Allana4f58f52009-06-02 11:29:18 +00003587 * Should only be called for applicable parts.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003588 **/
3589void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
3590{
3591 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00003592 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003593
Bruce Allan17f085d2010-06-17 18:59:48 +00003594 phy_ctrl = er32(PHY_CTRL);
3595 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU | E1000_PHY_CTRL_GBE_DISABLE;
3596 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00003597
Bruce Allan8395ae82010-09-22 17:15:08 +00003598 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00003599 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan8395ae82010-09-22 17:15:08 +00003600 ret_val = hw->phy.ops.acquire(hw);
3601 if (ret_val)
3602 return;
3603 e1000_write_smbus_addr(hw);
3604 hw->phy.ops.release(hw);
3605 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003606}
3607
3608/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003609 * e1000_cleanup_led_ich8lan - Restore the default LED operation
3610 * @hw: pointer to the HW structure
3611 *
3612 * Return the LED back to the default configuration.
3613 **/
3614static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
3615{
3616 if (hw->phy.type == e1000_phy_ife)
3617 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
3618
3619 ew32(LEDCTL, hw->mac.ledctl_default);
3620 return 0;
3621}
3622
3623/**
Auke Kok489815c2008-02-21 15:11:07 -08003624 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07003625 * @hw: pointer to the HW structure
3626 *
Auke Kok489815c2008-02-21 15:11:07 -08003627 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003628 **/
3629static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
3630{
3631 if (hw->phy.type == e1000_phy_ife)
3632 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3633 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
3634
3635 ew32(LEDCTL, hw->mac.ledctl_mode2);
3636 return 0;
3637}
3638
3639/**
Auke Kok489815c2008-02-21 15:11:07 -08003640 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07003641 * @hw: pointer to the HW structure
3642 *
Auke Kok489815c2008-02-21 15:11:07 -08003643 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003644 **/
3645static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
3646{
3647 if (hw->phy.type == e1000_phy_ife)
3648 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00003649 (IFE_PSCL_PROBE_MODE |
3650 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003651
3652 ew32(LEDCTL, hw->mac.ledctl_mode1);
3653 return 0;
3654}
3655
3656/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003657 * e1000_setup_led_pchlan - Configures SW controllable LED
3658 * @hw: pointer to the HW structure
3659 *
3660 * This prepares the SW controllable LED for use.
3661 **/
3662static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
3663{
Bruce Allan482fed82011-01-06 14:29:49 +00003664 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00003665}
3666
3667/**
3668 * e1000_cleanup_led_pchlan - Restore the default LED operation
3669 * @hw: pointer to the HW structure
3670 *
3671 * Return the LED back to the default configuration.
3672 **/
3673static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
3674{
Bruce Allan482fed82011-01-06 14:29:49 +00003675 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00003676}
3677
3678/**
3679 * e1000_led_on_pchlan - Turn LEDs on
3680 * @hw: pointer to the HW structure
3681 *
3682 * Turn on the LEDs.
3683 **/
3684static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
3685{
3686 u16 data = (u16)hw->mac.ledctl_mode2;
3687 u32 i, led;
3688
3689 /*
3690 * If no link, then turn LED on by setting the invert bit
3691 * for each LED that's mode is "link_up" in ledctl_mode2.
3692 */
3693 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3694 for (i = 0; i < 3; i++) {
3695 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3696 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3697 E1000_LEDCTL_MODE_LINK_UP)
3698 continue;
3699 if (led & E1000_PHY_LED0_IVRT)
3700 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3701 else
3702 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3703 }
3704 }
3705
Bruce Allan482fed82011-01-06 14:29:49 +00003706 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003707}
3708
3709/**
3710 * e1000_led_off_pchlan - Turn LEDs off
3711 * @hw: pointer to the HW structure
3712 *
3713 * Turn off the LEDs.
3714 **/
3715static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
3716{
3717 u16 data = (u16)hw->mac.ledctl_mode1;
3718 u32 i, led;
3719
3720 /*
3721 * If no link, then turn LED off by clearing the invert bit
3722 * for each LED that's mode is "link_up" in ledctl_mode1.
3723 */
3724 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3725 for (i = 0; i < 3; i++) {
3726 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3727 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3728 E1000_LEDCTL_MODE_LINK_UP)
3729 continue;
3730 if (led & E1000_PHY_LED0_IVRT)
3731 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3732 else
3733 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3734 }
3735 }
3736
Bruce Allan482fed82011-01-06 14:29:49 +00003737 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003738}
3739
3740/**
Bruce Allane98cac42010-05-10 15:02:32 +00003741 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07003742 * @hw: pointer to the HW structure
3743 *
Bruce Allane98cac42010-05-10 15:02:32 +00003744 * Read appropriate register for the config done bit for completion status
3745 * and configure the PHY through s/w for EEPROM-less parts.
3746 *
3747 * NOTE: some silicon which is EEPROM-less will fail trying to read the
3748 * config done bit, so only an error is logged and continues. If we were
3749 * to return with error, EEPROM-less silicon would not be able to be reset
3750 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07003751 **/
3752static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
3753{
Bruce Allane98cac42010-05-10 15:02:32 +00003754 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07003755 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00003756 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003757
Bruce Allanf4187b52008-08-26 18:36:50 -07003758 e1000e_get_cfg_done(hw);
3759
Bruce Allane98cac42010-05-10 15:02:32 +00003760 /* Wait for indication from h/w that it has completed basic config */
3761 if (hw->mac.type >= e1000_ich10lan) {
3762 e1000_lan_init_done_ich8lan(hw);
3763 } else {
3764 ret_val = e1000e_get_auto_rd_done(hw);
3765 if (ret_val) {
3766 /*
3767 * When auto config read does not complete, do not
3768 * return with an error. This can happen in situations
3769 * where there is no eeprom and prevents getting link.
3770 */
3771 e_dbg("Auto Read Done did not complete\n");
3772 ret_val = 0;
3773 }
3774 }
3775
3776 /* Clear PHY Reset Asserted bit */
3777 status = er32(STATUS);
3778 if (status & E1000_STATUS_PHYRA)
3779 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
3780 else
3781 e_dbg("PHY Reset Asserted not set - needs delay\n");
3782
Bruce Allanf4187b52008-08-26 18:36:50 -07003783 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00003784 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allanf4187b52008-08-26 18:36:50 -07003785 if (((er32(EECD) & E1000_EECD_PRES) == 0) &&
3786 (hw->phy.type == e1000_phy_igp_3)) {
3787 e1000e_phy_init_script_igp3(hw);
3788 }
3789 } else {
3790 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
3791 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003792 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00003793 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07003794 }
3795 }
3796
Bruce Allane98cac42010-05-10 15:02:32 +00003797 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07003798}
3799
3800/**
Bruce Allan17f208d2009-12-01 15:47:22 +00003801 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
3802 * @hw: pointer to the HW structure
3803 *
3804 * In the case of a PHY power down to save power, or to turn off link during a
3805 * driver unload, or wake on lan is not enabled, remove the link.
3806 **/
3807static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
3808{
3809 /* If the management interface is not enabled, then power down */
3810 if (!(hw->mac.ops.check_mng_mode(hw) ||
3811 hw->phy.ops.check_reset_block(hw)))
3812 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00003813}
3814
3815/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003816 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
3817 * @hw: pointer to the HW structure
3818 *
3819 * Clears hardware counters specific to the silicon family and calls
3820 * clear_hw_cntrs_generic to clear all general purpose counters.
3821 **/
3822static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
3823{
Bruce Allana4f58f52009-06-02 11:29:18 +00003824 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003825
3826 e1000e_clear_hw_cntrs_base(hw);
3827
Bruce Allan99673d92009-11-20 23:27:21 +00003828 er32(ALGNERRC);
3829 er32(RXERRC);
3830 er32(TNCRS);
3831 er32(CEXTERR);
3832 er32(TSCTC);
3833 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003834
Bruce Allan99673d92009-11-20 23:27:21 +00003835 er32(MGTPRC);
3836 er32(MGTPDC);
3837 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003838
Bruce Allan99673d92009-11-20 23:27:21 +00003839 er32(IAC);
3840 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003841
Bruce Allana4f58f52009-06-02 11:29:18 +00003842 /* Clear PHY statistics registers */
3843 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003844 (hw->phy.type == e1000_phy_82579) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003845 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan482fed82011-01-06 14:29:49 +00003846 e1e_rphy(hw, HV_SCC_UPPER, &phy_data);
3847 e1e_rphy(hw, HV_SCC_LOWER, &phy_data);
3848 e1e_rphy(hw, HV_ECOL_UPPER, &phy_data);
3849 e1e_rphy(hw, HV_ECOL_LOWER, &phy_data);
3850 e1e_rphy(hw, HV_MCC_UPPER, &phy_data);
3851 e1e_rphy(hw, HV_MCC_LOWER, &phy_data);
3852 e1e_rphy(hw, HV_LATECOL_UPPER, &phy_data);
3853 e1e_rphy(hw, HV_LATECOL_LOWER, &phy_data);
3854 e1e_rphy(hw, HV_COLC_UPPER, &phy_data);
3855 e1e_rphy(hw, HV_COLC_LOWER, &phy_data);
3856 e1e_rphy(hw, HV_DC_UPPER, &phy_data);
3857 e1e_rphy(hw, HV_DC_LOWER, &phy_data);
3858 e1e_rphy(hw, HV_TNCRS_UPPER, &phy_data);
3859 e1e_rphy(hw, HV_TNCRS_LOWER, &phy_data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003860 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003861}
3862
3863static struct e1000_mac_operations ich8_mac_ops = {
Bruce Allana4f58f52009-06-02 11:29:18 +00003864 .id_led_init = e1000e_id_led_init,
Bruce Allaneb7700d2010-06-16 13:27:05 +00003865 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003866 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003867 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003868 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
3869 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00003870 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003871 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003872 /* led_on dependent on mac type */
3873 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07003874 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003875 .reset_hw = e1000_reset_hw_ich8lan,
3876 .init_hw = e1000_init_hw_ich8lan,
3877 .setup_link = e1000_setup_link_ich8lan,
3878 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00003879 /* id_led_init dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003880};
3881
3882static struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00003883 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003884 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003885 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07003886 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003887 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00003888 .read_reg = e1000e_read_phy_reg_igp,
3889 .release = e1000_release_swflag_ich8lan,
3890 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003891 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
3892 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003893 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894};
3895
3896static struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00003897 .acquire = e1000_acquire_nvm_ich8lan,
3898 .read = e1000_read_nvm_ich8lan,
3899 .release = e1000_release_nvm_ich8lan,
3900 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003901 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00003902 .validate = e1000_validate_nvm_checksum_ich8lan,
3903 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003904};
3905
3906struct e1000_info e1000_ich8_info = {
3907 .mac = e1000_ich8lan,
3908 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003909 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003910 | FLAG_RX_CSUM_ENABLED
3911 | FLAG_HAS_CTRLEXT_ON_LOAD
3912 | FLAG_HAS_AMT
3913 | FLAG_HAS_FLASH
3914 | FLAG_APME_IN_WUC,
3915 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003916 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003917 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918 .mac_ops = &ich8_mac_ops,
3919 .phy_ops = &ich8_phy_ops,
3920 .nvm_ops = &ich8_nvm_ops,
3921};
3922
3923struct e1000_info e1000_ich9_info = {
3924 .mac = e1000_ich9lan,
3925 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003926 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07003927 | FLAG_HAS_WOL
3928 | FLAG_RX_CSUM_ENABLED
3929 | FLAG_HAS_CTRLEXT_ON_LOAD
3930 | FLAG_HAS_AMT
3931 | FLAG_HAS_ERT
3932 | FLAG_HAS_FLASH
3933 | FLAG_APME_IN_WUC,
3934 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003935 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07003936 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003937 .mac_ops = &ich8_mac_ops,
3938 .phy_ops = &ich8_phy_ops,
3939 .nvm_ops = &ich8_nvm_ops,
3940};
3941
Bruce Allanf4187b52008-08-26 18:36:50 -07003942struct e1000_info e1000_ich10_info = {
3943 .mac = e1000_ich10lan,
3944 .flags = FLAG_HAS_JUMBO_FRAMES
3945 | FLAG_IS_ICH
3946 | FLAG_HAS_WOL
3947 | FLAG_RX_CSUM_ENABLED
3948 | FLAG_HAS_CTRLEXT_ON_LOAD
3949 | FLAG_HAS_AMT
3950 | FLAG_HAS_ERT
3951 | FLAG_HAS_FLASH
3952 | FLAG_APME_IN_WUC,
3953 .pba = 10,
Bruce Allan2adc55c2009-06-02 11:28:58 +00003954 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07003955 .get_variants = e1000_get_variants_ich8lan,
3956 .mac_ops = &ich8_mac_ops,
3957 .phy_ops = &ich8_phy_ops,
3958 .nvm_ops = &ich8_nvm_ops,
3959};
Bruce Allana4f58f52009-06-02 11:29:18 +00003960
3961struct e1000_info e1000_pch_info = {
3962 .mac = e1000_pchlan,
3963 .flags = FLAG_IS_ICH
3964 | FLAG_HAS_WOL
3965 | FLAG_RX_CSUM_ENABLED
3966 | FLAG_HAS_CTRLEXT_ON_LOAD
3967 | FLAG_HAS_AMT
3968 | FLAG_HAS_FLASH
3969 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00003970 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00003971 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00003972 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00003973 .pba = 26,
3974 .max_hw_frame_size = 4096,
3975 .get_variants = e1000_get_variants_ich8lan,
3976 .mac_ops = &ich8_mac_ops,
3977 .phy_ops = &ich8_phy_ops,
3978 .nvm_ops = &ich8_nvm_ops,
3979};
Bruce Alland3738bb2010-06-16 13:27:28 +00003980
3981struct e1000_info e1000_pch2_info = {
3982 .mac = e1000_pch2lan,
3983 .flags = FLAG_IS_ICH
3984 | FLAG_HAS_WOL
3985 | FLAG_RX_CSUM_ENABLED
3986 | FLAG_HAS_CTRLEXT_ON_LOAD
3987 | FLAG_HAS_AMT
3988 | FLAG_HAS_FLASH
3989 | FLAG_HAS_JUMBO_FRAMES
3990 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00003991 .flags2 = FLAG2_HAS_PHY_STATS
3992 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00003993 .pba = 26,
Bruce Alland3738bb2010-06-16 13:27:28 +00003994 .max_hw_frame_size = DEFAULT_JUMBO,
3995 .get_variants = e1000_get_variants_ich8lan,
3996 .mac_ops = &ich8_mac_ops,
3997 .phy_ops = &ich8_phy_ops,
3998 .nvm_ops = &ich8_nvm_ops,
3999};