blob: d7fd1e848ddc949f3ee5e0d45e0ff69df33fd2a3 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanf5e261e2012-01-01 16:00:03 +00004 Copyright(c) 1999 - 2012 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)
Bruce Allan36ceeb42012-03-20 03:47:47 +0000138#define HV_PM_CTRL_PLL_STOP_IN_K1_GIGA 0x100
Bruce Alland3738bb2010-06-16 13:27:28 +0000139
Bruce Allane52997f2010-06-16 13:27:49 +0000140/* PHY Low Power Idle Control */
Bruce Allan0ed013e2011-07-29 05:52:56 +0000141#define I82579_LPI_CTRL PHY_REG(772, 20)
142#define I82579_LPI_CTRL_ENABLE_MASK 0x6000
143#define I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT 0x80
Bruce Allane52997f2010-06-16 13:27:49 +0000144
Bruce Allan1effb452011-02-25 06:58:03 +0000145/* EMI Registers */
146#define I82579_EMI_ADDR 0x10
147#define I82579_EMI_DATA 0x11
148#define I82579_LPI_UPDATE_TIMER 0x4805 /* in 40ns units + 40 ns base value */
Bruce Allan4d241362011-12-16 00:46:06 +0000149#define I82579_MSE_THRESHOLD 0x084F /* Mean Square Error Threshold */
150#define I82579_MSE_LINK_DOWN 0x2411 /* MSE count before dropping link */
Bruce Allan1effb452011-02-25 06:58:03 +0000151
Bruce Allanf523d212009-10-29 13:45:45 +0000152/* Strapping Option Register - RO */
153#define E1000_STRAP 0x0000C
154#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
155#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
156
Bruce Allanfa2ce132009-10-26 11:23:25 +0000157/* OEM Bits Phy Register */
158#define HV_OEM_BITS PHY_REG(768, 25)
159#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
Bruce Allanf523d212009-10-29 13:45:45 +0000160#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
Bruce Allanfa2ce132009-10-26 11:23:25 +0000161#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
162
Bruce Allan1d5846b2009-10-29 13:46:05 +0000163#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
164#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
165
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000166/* KMRN Mode Control */
167#define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
168#define HV_KMRN_MDIO_SLOW 0x0400
169
Bruce Allan1d2101a72011-07-22 06:21:56 +0000170/* KMRN FIFO Control and Status */
171#define HV_KMRN_FIFO_CTRLSTA PHY_REG(770, 16)
172#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK 0x7000
173#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT 12
174
Auke Kokbc7f75f2007-09-17 12:30:59 -0700175/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
176/* Offset 04h HSFSTS */
177union ich8_hws_flash_status {
178 struct ich8_hsfsts {
179 u16 flcdone :1; /* bit 0 Flash Cycle Done */
180 u16 flcerr :1; /* bit 1 Flash Cycle Error */
181 u16 dael :1; /* bit 2 Direct Access error Log */
182 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
183 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
184 u16 reserved1 :2; /* bit 13:6 Reserved */
185 u16 reserved2 :6; /* bit 13:6 Reserved */
186 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
187 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
188 } hsf_status;
189 u16 regval;
190};
191
192/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
193/* Offset 06h FLCTL */
194union ich8_hws_flash_ctrl {
195 struct ich8_hsflctl {
196 u16 flcgo :1; /* 0 Flash Cycle Go */
197 u16 flcycle :2; /* 2:1 Flash Cycle */
198 u16 reserved :5; /* 7:3 Reserved */
199 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
200 u16 flockdn :6; /* 15:10 Reserved */
201 } hsf_ctrl;
202 u16 regval;
203};
204
205/* ICH Flash Region Access Permissions */
206union ich8_hws_flash_regacc {
207 struct ich8_flracc {
208 u32 grra :8; /* 0:7 GbE region Read Access */
209 u32 grwa :8; /* 8:15 GbE region Write Access */
210 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
211 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
212 } hsf_flregacc;
213 u16 regval;
214};
215
Bruce Allan4a770352008-10-01 17:18:35 -0700216/* ICH Flash Protected Region */
217union ich8_flash_protected_range {
218 struct ich8_pr {
219 u32 base:13; /* 0:12 Protected Range Base */
220 u32 reserved1:2; /* 13:14 Reserved */
221 u32 rpe:1; /* 15 Read Protection Enable */
222 u32 limit:13; /* 16:28 Protected Range Limit */
223 u32 reserved2:2; /* 29:30 Reserved */
224 u32 wpe:1; /* 31 Write Protection Enable */
225 } range;
226 u32 regval;
227};
228
Auke Kokbc7f75f2007-09-17 12:30:59 -0700229static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
230static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
231static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700232static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
233static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
234 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700235static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
236 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700237static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
238 u16 *data);
239static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
240 u8 size, u16 *data);
241static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
242static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700243static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000244static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
245static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
246static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
247static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
248static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
249static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
250static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
251static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000252static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000253static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000254static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000255static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000256static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000257static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
258static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000259static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000260static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700261
262static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
263{
264 return readw(hw->flash_address + reg);
265}
266
267static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
268{
269 return readl(hw->flash_address + reg);
270}
271
272static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
273{
274 writew(val, hw->flash_address + reg);
275}
276
277static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
278{
279 writel(val, hw->flash_address + reg);
280}
281
282#define er16flash(reg) __er16flash(hw, (reg))
283#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000284#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
285#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700286
Bruce Allan99730e42011-05-13 07:19:48 +0000287static void e1000_toggle_lanphypc_value_ich8lan(struct e1000_hw *hw)
288{
289 u32 ctrl;
290
291 ctrl = er32(CTRL);
292 ctrl |= E1000_CTRL_LANPHYPC_OVERRIDE;
293 ctrl &= ~E1000_CTRL_LANPHYPC_VALUE;
294 ew32(CTRL, ctrl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000295 e1e_flush();
Bruce Allan99730e42011-05-13 07:19:48 +0000296 udelay(10);
297 ctrl &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
298 ew32(CTRL, ctrl);
299}
300
Auke Kokbc7f75f2007-09-17 12:30:59 -0700301/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000302 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
303 * @hw: pointer to the HW structure
304 *
305 * Initialize family-specific PHY parameters and function pointers.
306 **/
307static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
308{
309 struct e1000_phy_info *phy = &hw->phy;
310 s32 ret_val = 0;
311
312 phy->addr = 1;
313 phy->reset_delay_us = 100;
314
Bruce Allan2b6b1682011-05-13 07:20:09 +0000315 phy->ops.set_page = e1000_set_page_igp;
Bruce Allan94d81862009-11-20 23:25:26 +0000316 phy->ops.read_reg = e1000_read_phy_reg_hv;
317 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000318 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000319 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
320 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000321 phy->ops.write_reg = e1000_write_phy_reg_hv;
322 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000323 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
Bruce Allan17f208d2009-12-01 15:47:22 +0000324 phy->ops.power_up = e1000_power_up_phy_copper;
325 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000326 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
327
Bruce Allan44abd5c2012-02-22 09:02:37 +0000328 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allan90b82982011-12-16 00:46:33 +0000329 u32 fwsm = er32(FWSM);
330
331 /*
332 * The MAC-PHY interconnect may still be in SMBus mode after
333 * Sx->S0. If resetting the PHY is not blocked, toggle the
334 * LANPHYPC Value bit to force the interconnect to PCIe mode.
335 */
Bruce Allan99730e42011-05-13 07:19:48 +0000336 e1000_toggle_lanphypc_value_ich8lan(hw);
Bruce Allan6dfaa762010-05-05 22:00:06 +0000337 msleep(50);
Bruce Allan605c82b2010-09-22 17:17:01 +0000338
339 /*
340 * Gate automatic PHY configuration by hardware on
341 * non-managed 82579
342 */
Bruce Allan90b82982011-12-16 00:46:33 +0000343 if ((hw->mac.type == e1000_pch2lan) &&
344 !(fwsm & E1000_ICH_FWSM_FW_VALID))
Bruce Allan605c82b2010-09-22 17:17:01 +0000345 e1000_gate_hw_phy_config_ich8lan(hw, true);
Bruce Allan6dfaa762010-05-05 22:00:06 +0000346
Bruce Allan90b82982011-12-16 00:46:33 +0000347 /*
348 * Reset the PHY before any access to it. Doing so, ensures
349 * that the PHY is in a known good state before we read/write
350 * PHY registers. The generic reset is sufficient here,
351 * because we haven't determined the PHY type yet.
352 */
353 ret_val = e1000e_phy_hw_reset_generic(hw);
354 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000355 return ret_val;
Bruce Allan627c8a02010-05-05 22:00:27 +0000356
Bruce Allan90b82982011-12-16 00:46:33 +0000357 /* Ungate automatic PHY configuration on non-managed 82579 */
358 if ((hw->mac.type == e1000_pch2lan) &&
359 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
360 usleep_range(10000, 20000);
361 e1000_gate_hw_phy_config_ich8lan(hw, false);
362 }
Bruce Allan605c82b2010-09-22 17:17:01 +0000363 }
364
Bruce Allana4f58f52009-06-02 11:29:18 +0000365 phy->id = e1000_phy_unknown;
Bruce Allan664dc872010-11-24 06:01:46 +0000366 switch (hw->mac.type) {
367 default:
368 ret_val = e1000e_get_phy_id(hw);
369 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000370 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000371 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
372 break;
373 /* fall-through */
374 case e1000_pch2lan:
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000375 /*
Bruce Allan664dc872010-11-24 06:01:46 +0000376 * In case the PHY needs to be in mdio slow mode,
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000377 * set slow mode and try to get the PHY id again.
378 */
379 ret_val = e1000_set_mdio_slow_mode_hv(hw);
380 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000381 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000382 ret_val = e1000e_get_phy_id(hw);
383 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000384 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000385 break;
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000386 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000387 phy->type = e1000e_get_phy_type_from_id(phy->id);
388
Bruce Allan0be84012009-12-02 17:03:18 +0000389 switch (phy->type) {
390 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000391 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +0000392 phy->ops.check_polarity = e1000_check_polarity_82577;
393 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000394 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000395 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000396 phy->ops.get_info = e1000_get_phy_info_82577;
397 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000398 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000399 case e1000_phy_82578:
400 phy->ops.check_polarity = e1000_check_polarity_m88;
401 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
402 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
403 phy->ops.get_info = e1000e_get_phy_info_m88;
404 break;
405 default:
406 ret_val = -E1000_ERR_PHY;
407 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000408 }
409
410 return ret_val;
411}
412
413/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700414 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
415 * @hw: pointer to the HW structure
416 *
417 * Initialize family-specific PHY parameters and function pointers.
418 **/
419static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
420{
421 struct e1000_phy_info *phy = &hw->phy;
422 s32 ret_val;
423 u16 i = 0;
424
425 phy->addr = 1;
426 phy->reset_delay_us = 100;
427
Bruce Allan17f208d2009-12-01 15:47:22 +0000428 phy->ops.power_up = e1000_power_up_phy_copper;
429 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
430
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700431 /*
432 * We may need to do this twice - once for IGP and if that fails,
433 * we'll set BM func pointers and try again
434 */
435 ret_val = e1000e_determine_phy_address(hw);
436 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000437 phy->ops.write_reg = e1000e_write_phy_reg_bm;
438 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700439 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000440 if (ret_val) {
441 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700442 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000443 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700444 }
445
Auke Kokbc7f75f2007-09-17 12:30:59 -0700446 phy->id = 0;
447 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
448 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000449 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700450 ret_val = e1000e_get_phy_id(hw);
451 if (ret_val)
452 return ret_val;
453 }
454
455 /* Verify phy id */
456 switch (phy->id) {
457 case IGP03E1000_E_PHY_ID:
458 phy->type = e1000_phy_igp_3;
459 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000460 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
461 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000462 phy->ops.get_info = e1000e_get_phy_info_igp;
463 phy->ops.check_polarity = e1000_check_polarity_igp;
464 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700465 break;
466 case IFE_E_PHY_ID:
467 case IFE_PLUS_E_PHY_ID:
468 case IFE_C_E_PHY_ID:
469 phy->type = e1000_phy_ife;
470 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000471 phy->ops.get_info = e1000_get_phy_info_ife;
472 phy->ops.check_polarity = e1000_check_polarity_ife;
473 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700474 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700475 case BME1000_E_PHY_ID:
476 phy->type = e1000_phy_bm;
477 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000478 phy->ops.read_reg = e1000e_read_phy_reg_bm;
479 phy->ops.write_reg = e1000e_write_phy_reg_bm;
480 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000481 phy->ops.get_info = e1000e_get_phy_info_m88;
482 phy->ops.check_polarity = e1000_check_polarity_m88;
483 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700484 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700485 default:
486 return -E1000_ERR_PHY;
487 break;
488 }
489
490 return 0;
491}
492
493/**
494 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
495 * @hw: pointer to the HW structure
496 *
497 * Initialize family-specific NVM parameters and function
498 * pointers.
499 **/
500static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
501{
502 struct e1000_nvm_info *nvm = &hw->nvm;
503 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000504 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700505 u16 i;
506
Bruce Allanad680762008-03-28 09:15:03 -0700507 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700508 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000509 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700510 return -E1000_ERR_CONFIG;
511 }
512
513 nvm->type = e1000_nvm_flash_sw;
514
515 gfpreg = er32flash(ICH_FLASH_GFPREG);
516
Bruce Allanad680762008-03-28 09:15:03 -0700517 /*
518 * sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700519 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700520 * the overall size.
521 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700522 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
523 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
524
525 /* flash_base_addr is byte-aligned */
526 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
527
Bruce Allanad680762008-03-28 09:15:03 -0700528 /*
529 * find total size of the NVM, then cut in half since the total
530 * size represents two separate NVM banks.
531 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
533 << FLASH_SECTOR_ADDR_SHIFT;
534 nvm->flash_bank_size /= 2;
535 /* Adjust to word count */
536 nvm->flash_bank_size /= sizeof(u16);
537
538 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
539
540 /* Clear shadow ram */
541 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000542 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700543 dev_spec->shadow_ram[i].value = 0xFFFF;
544 }
545
546 return 0;
547}
548
549/**
550 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
551 * @hw: pointer to the HW structure
552 *
553 * Initialize family-specific MAC parameters and function
554 * pointers.
555 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000556static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700558 struct e1000_mac_info *mac = &hw->mac;
559
560 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700561 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562
563 /* Set mta register count */
564 mac->mta_reg_count = 32;
565 /* Set rar entry count */
566 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
567 if (mac->type == e1000_ich8lan)
568 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000569 /* FWSM register */
570 mac->has_fwsm = true;
571 /* ARC subsystem not supported */
572 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000573 /* Adaptive IFS supported */
574 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700575
Bruce Allana4f58f52009-06-02 11:29:18 +0000576 /* LED operations */
577 switch (mac->type) {
578 case e1000_ich8lan:
579 case e1000_ich9lan:
580 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000581 /* check management mode */
582 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000583 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000584 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000585 /* blink LED */
586 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000587 /* setup LED */
588 mac->ops.setup_led = e1000e_setup_led_generic;
589 /* cleanup LED */
590 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
591 /* turn on/off LED */
592 mac->ops.led_on = e1000_led_on_ich8lan;
593 mac->ops.led_off = e1000_led_off_ich8lan;
594 break;
595 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000596 case e1000_pch2lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000597 /* check management mode */
598 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000599 /* ID LED init */
600 mac->ops.id_led_init = e1000_id_led_init_pchlan;
601 /* setup LED */
602 mac->ops.setup_led = e1000_setup_led_pchlan;
603 /* cleanup LED */
604 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
605 /* turn on/off LED */
606 mac->ops.led_on = e1000_led_on_pchlan;
607 mac->ops.led_off = e1000_led_off_pchlan;
608 break;
609 default:
610 break;
611 }
612
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613 /* Enable PCS Lock-loss workaround for ICH8 */
614 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000615 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700616
Bruce Allan605c82b2010-09-22 17:17:01 +0000617 /* Gate automatic PHY configuration by hardware on managed 82579 */
618 if ((mac->type == e1000_pch2lan) &&
619 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
620 e1000_gate_hw_phy_config_ich8lan(hw, true);
Bruce Alland3738bb2010-06-16 13:27:28 +0000621
Auke Kokbc7f75f2007-09-17 12:30:59 -0700622 return 0;
623}
624
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000625/**
Bruce Allane52997f2010-06-16 13:27:49 +0000626 * e1000_set_eee_pchlan - Enable/disable EEE support
627 * @hw: pointer to the HW structure
628 *
629 * Enable/disable EEE based on setting in dev_spec structure. The bits in
630 * the LPI Control register will remain set only if/when link is up.
631 **/
632static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
633{
634 s32 ret_val = 0;
635 u16 phy_reg;
636
637 if (hw->phy.type != e1000_phy_82579)
Bruce Allan5015e532012-02-08 02:55:56 +0000638 return 0;
Bruce Allane52997f2010-06-16 13:27:49 +0000639
640 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
641 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000642 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000643
644 if (hw->dev_spec.ich8lan.eee_disable)
645 phy_reg &= ~I82579_LPI_CTRL_ENABLE_MASK;
646 else
647 phy_reg |= I82579_LPI_CTRL_ENABLE_MASK;
648
Bruce Allan5015e532012-02-08 02:55:56 +0000649 return e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allane52997f2010-06-16 13:27:49 +0000650}
651
652/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000653 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
654 * @hw: pointer to the HW structure
655 *
656 * Checks to see of the link status of the hardware has changed. If a
657 * change in link status has been detected, then we read the PHY registers
658 * to get the current speed/duplex if link exists.
659 **/
660static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
661{
662 struct e1000_mac_info *mac = &hw->mac;
663 s32 ret_val;
664 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000665 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000666
667 /*
668 * We only want to go out to the PHY registers to see if Auto-Neg
669 * has completed and/or if our link status has changed. The
670 * get_link_status flag is set upon receiving a Link Status
671 * Change or Rx Sequence Error interrupt.
672 */
Bruce Allan5015e532012-02-08 02:55:56 +0000673 if (!mac->get_link_status)
674 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000675
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000676 /*
677 * First we want to see if the MII Status Register reports
678 * link. If so, then we want to get the current speed/duplex
679 * of the PHY.
680 */
681 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
682 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000683 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000684
Bruce Allan1d5846b2009-10-29 13:46:05 +0000685 if (hw->mac.type == e1000_pchlan) {
686 ret_val = e1000_k1_gig_workaround_hv(hw, link);
687 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000688 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +0000689 }
690
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000691 if (!link)
Bruce Allan5015e532012-02-08 02:55:56 +0000692 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000693
694 mac->get_link_status = false;
695
Bruce Allan1d2101a72011-07-22 06:21:56 +0000696 switch (hw->mac.type) {
697 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +0000698 ret_val = e1000_k1_workaround_lv(hw);
699 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000700 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000701 /* fall-thru */
702 case e1000_pchlan:
703 if (hw->phy.type == e1000_phy_82578) {
704 ret_val = e1000_link_stall_workaround_hv(hw);
705 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000706 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000707 }
708
709 /*
710 * Workaround for PCHx parts in half-duplex:
711 * Set the number of preambles removed from the packet
712 * when it is passed from the PHY to the MAC to prevent
713 * the MAC from misinterpreting the packet type.
714 */
715 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
716 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
717
718 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
719 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
720
721 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
722 break;
723 default:
724 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +0000725 }
726
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000727 /*
728 * Check if there was DownShift, must be checked
729 * immediately after link-up
730 */
731 e1000e_check_downshift(hw);
732
Bruce Allane52997f2010-06-16 13:27:49 +0000733 /* Enable/Disable EEE after link up */
734 ret_val = e1000_set_eee_pchlan(hw);
735 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000736 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000737
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000738 /*
739 * If we are forcing speed/duplex, then we simply return since
740 * we have already determined whether we have link or not.
741 */
Bruce Allan5015e532012-02-08 02:55:56 +0000742 if (!mac->autoneg)
743 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000744
745 /*
746 * Auto-Neg is enabled. Auto Speed Detection takes care
747 * of MAC speed/duplex configuration. So we only need to
748 * configure Collision Distance in the MAC.
749 */
Bruce Allan57cde762012-02-22 09:02:58 +0000750 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000751
752 /*
753 * Configure Flow Control now that Auto-Neg has completed.
754 * First, we need to restore the desired flow control
755 * settings because we may have had to re-autoneg with a
756 * different link partner.
757 */
758 ret_val = e1000e_config_fc_after_link_up(hw);
759 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000760 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000761
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000762 return ret_val;
763}
764
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700765static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700766{
767 struct e1000_hw *hw = &adapter->hw;
768 s32 rc;
769
Bruce Allanec34c172012-02-01 10:53:05 +0000770 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771 if (rc)
772 return rc;
773
774 rc = e1000_init_nvm_params_ich8lan(hw);
775 if (rc)
776 return rc;
777
Bruce Alland3738bb2010-06-16 13:27:28 +0000778 switch (hw->mac.type) {
779 case e1000_ich8lan:
780 case e1000_ich9lan:
781 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000782 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +0000783 break;
784 case e1000_pchlan:
785 case e1000_pch2lan:
786 rc = e1000_init_phy_params_pchlan(hw);
787 break;
788 default:
789 break;
790 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700791 if (rc)
792 return rc;
793
Bruce Allan23e4f062011-02-25 07:44:51 +0000794 /*
795 * Disable Jumbo Frame support on parts with Intel 10/100 PHY or
796 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
797 */
798 if ((adapter->hw.phy.type == e1000_phy_ife) ||
799 ((adapter->hw.mac.type >= e1000_pch2lan) &&
800 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +0000801 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
802 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000803
804 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +0000805 }
806
Auke Kokbc7f75f2007-09-17 12:30:59 -0700807 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +0000808 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700809 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
810
Bruce Allanc6e7f512011-07-29 05:53:02 +0000811 /* Enable workaround for 82579 w/ ME enabled */
812 if ((adapter->hw.mac.type == e1000_pch2lan) &&
813 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
814 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
815
Bruce Allan5a86f282010-06-29 18:13:13 +0000816 /* Disable EEE by default until IEEE802.3az spec is finalized */
817 if (adapter->flags2 & FLAG2_HAS_EEE)
818 adapter->hw.dev_spec.ich8lan.eee_disable = true;
819
Auke Kokbc7f75f2007-09-17 12:30:59 -0700820 return 0;
821}
822
Thomas Gleixner717d4382008-10-02 16:33:40 -0700823static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -0700824
Auke Kokbc7f75f2007-09-17 12:30:59 -0700825/**
Bruce Allanca15df52009-10-26 11:23:43 +0000826 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
827 * @hw: pointer to the HW structure
828 *
829 * Acquires the mutex for performing NVM operations.
830 **/
831static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
832{
833 mutex_lock(&nvm_mutex);
834
835 return 0;
836}
837
838/**
839 * e1000_release_nvm_ich8lan - Release NVM mutex
840 * @hw: pointer to the HW structure
841 *
842 * Releases the mutex used while performing NVM operations.
843 **/
844static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
845{
846 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +0000847}
848
Bruce Allanca15df52009-10-26 11:23:43 +0000849/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700850 * e1000_acquire_swflag_ich8lan - Acquire software control flag
851 * @hw: pointer to the HW structure
852 *
Bruce Allanca15df52009-10-26 11:23:43 +0000853 * Acquires the software control flag for performing PHY and select
854 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700855 **/
856static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
857{
Bruce Allan373a88d2009-08-07 07:41:37 +0000858 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
859 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860
Bruce Allana90b4122011-10-07 03:50:38 +0000861 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
862 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +0000863 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +0000864 return -E1000_ERR_PHY;
865 }
Thomas Gleixner717d4382008-10-02 16:33:40 -0700866
Auke Kokbc7f75f2007-09-17 12:30:59 -0700867 while (timeout) {
868 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +0000869 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
870 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700871
Auke Kokbc7f75f2007-09-17 12:30:59 -0700872 mdelay(1);
873 timeout--;
874 }
875
876 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +0000877 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +0000878 ret_val = -E1000_ERR_CONFIG;
879 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700880 }
881
Bruce Allan53ac5a82009-10-26 11:23:06 +0000882 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +0000883
884 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
885 ew32(EXTCNF_CTRL, extcnf_ctrl);
886
887 while (timeout) {
888 extcnf_ctrl = er32(EXTCNF_CTRL);
889 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
890 break;
891
892 mdelay(1);
893 timeout--;
894 }
895
896 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +0000897 e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
Bruce Allana90b4122011-10-07 03:50:38 +0000898 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +0000899 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
900 ew32(EXTCNF_CTRL, extcnf_ctrl);
901 ret_val = -E1000_ERR_CONFIG;
902 goto out;
903 }
904
905out:
906 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +0000907 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +0000908
909 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700910}
911
912/**
913 * e1000_release_swflag_ich8lan - Release software control flag
914 * @hw: pointer to the HW structure
915 *
Bruce Allanca15df52009-10-26 11:23:43 +0000916 * Releases the software control flag for performing PHY and select
917 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918 **/
919static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
920{
921 u32 extcnf_ctrl;
922
923 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +0000924
925 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
926 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
927 ew32(EXTCNF_CTRL, extcnf_ctrl);
928 } else {
929 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
930 }
Thomas Gleixner717d4382008-10-02 16:33:40 -0700931
Bruce Allana90b4122011-10-07 03:50:38 +0000932 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933}
934
935/**
Bruce Allan4662e822008-08-26 18:37:06 -0700936 * e1000_check_mng_mode_ich8lan - Checks management mode
937 * @hw: pointer to the HW structure
938 *
Bruce Allaneb7700d2010-06-16 13:27:05 +0000939 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -0700940 * This is a function pointer entry point only called by read/write
941 * routines for the PHY and NVM parts.
942 **/
943static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
944{
Bruce Allana708dd82009-11-20 23:28:37 +0000945 u32 fwsm;
946
947 fwsm = er32(FWSM);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000948 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
949 ((fwsm & E1000_FWSM_MODE_MASK) ==
950 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
951}
Bruce Allan4662e822008-08-26 18:37:06 -0700952
Bruce Allaneb7700d2010-06-16 13:27:05 +0000953/**
954 * e1000_check_mng_mode_pchlan - Checks management mode
955 * @hw: pointer to the HW structure
956 *
957 * This checks if the adapter has iAMT enabled.
958 * This is a function pointer entry point only called by read/write
959 * routines for the PHY and NVM parts.
960 **/
961static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
962{
963 u32 fwsm;
964
965 fwsm = er32(FWSM);
966 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
967 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -0700968}
969
970/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700971 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
972 * @hw: pointer to the HW structure
973 *
974 * Checks if firmware is blocking the reset of the PHY.
975 * This is a function pointer entry point only called by
976 * reset routines.
977 **/
978static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
979{
980 u32 fwsm;
981
982 fwsm = er32(FWSM);
983
984 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
985}
986
987/**
Bruce Allan8395ae82010-09-22 17:15:08 +0000988 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
989 * @hw: pointer to the HW structure
990 *
991 * Assumes semaphore already acquired.
992 *
993 **/
994static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
995{
996 u16 phy_data;
997 u32 strap = er32(STRAP);
998 s32 ret_val = 0;
999
1000 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1001
1002 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1003 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001004 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001005
1006 phy_data &= ~HV_SMB_ADDR_MASK;
1007 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1008 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001009
Bruce Allan5015e532012-02-08 02:55:56 +00001010 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001011}
1012
1013/**
Bruce Allanf523d212009-10-29 13:45:45 +00001014 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1015 * @hw: pointer to the HW structure
1016 *
1017 * SW should configure the LCD from the NVM extended configuration region
1018 * as a workaround for certain parts.
1019 **/
1020static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1021{
1022 struct e1000_phy_info *phy = &hw->phy;
1023 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001024 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001025 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1026
Bruce Allanf523d212009-10-29 13:45:45 +00001027 /*
1028 * Initialize the PHY from the NVM on ICH platforms. This
1029 * is needed due to an issue where the NVM configuration is
1030 * not properly autoloaded after power transitions.
1031 * Therefore, after each PHY reset, we will load the
1032 * configuration data out of the NVM manually.
1033 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001034 switch (hw->mac.type) {
1035 case e1000_ich8lan:
1036 if (phy->type != e1000_phy_igp_3)
1037 return ret_val;
1038
Bruce Allan5f3eed62010-09-22 17:15:54 +00001039 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1040 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001041 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1042 break;
1043 }
1044 /* Fall-thru */
1045 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001046 case e1000_pch2lan:
Bruce Allan8b802a72010-05-10 15:01:10 +00001047 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001048 break;
1049 default:
1050 return ret_val;
1051 }
1052
1053 ret_val = hw->phy.ops.acquire(hw);
1054 if (ret_val)
1055 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001056
Bruce Allan8b802a72010-05-10 15:01:10 +00001057 data = er32(FEXTNVM);
1058 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001059 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001060
Bruce Allan8b802a72010-05-10 15:01:10 +00001061 /*
1062 * Make sure HW does not configure LCD from PHY
1063 * extended configuration before SW configuration
1064 */
1065 data = er32(EXTCNF_CTRL);
Bruce Alland3738bb2010-06-16 13:27:28 +00001066 if (!(hw->mac.type == e1000_pch2lan)) {
1067 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001068 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001069 }
Bruce Allanf523d212009-10-29 13:45:45 +00001070
Bruce Allan8b802a72010-05-10 15:01:10 +00001071 cnf_size = er32(EXTCNF_SIZE);
1072 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1073 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1074 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001075 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001076
1077 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1078 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1079
Bruce Allan87fb7412010-09-22 17:15:33 +00001080 if ((!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
1081 (hw->mac.type == e1000_pchlan)) ||
1082 (hw->mac.type == e1000_pch2lan)) {
Bruce Allanf523d212009-10-29 13:45:45 +00001083 /*
Bruce Allan8b802a72010-05-10 15:01:10 +00001084 * HW configures the SMBus address and LEDs when the
1085 * OEM and LCD Write Enable bits are set in the NVM.
1086 * When both NVM bits are cleared, SW will configure
1087 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001088 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001089 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001090 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001091 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001092
Bruce Allan8b802a72010-05-10 15:01:10 +00001093 data = er32(LEDCTL);
1094 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1095 (u16)data);
1096 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001097 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001098 }
1099
1100 /* Configure LCD from extended configuration region. */
1101
1102 /* cnf_base_addr is in DWORD */
1103 word_addr = (u16)(cnf_base_addr << 1);
1104
1105 for (i = 0; i < cnf_size; i++) {
1106 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
1107 &reg_data);
1108 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001109 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001110
Bruce Allan8b802a72010-05-10 15:01:10 +00001111 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1112 1, &reg_addr);
1113 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001114 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001115
Bruce Allan8b802a72010-05-10 15:01:10 +00001116 /* Save off the PHY page for future writes. */
1117 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1118 phy_page = reg_data;
1119 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001120 }
Bruce Allanf523d212009-10-29 13:45:45 +00001121
Bruce Allan8b802a72010-05-10 15:01:10 +00001122 reg_addr &= PHY_REG_MASK;
1123 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001124
Bruce Allan8b802a72010-05-10 15:01:10 +00001125 ret_val = phy->ops.write_reg_locked(hw, (u32)reg_addr,
1126 reg_data);
1127 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001128 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001129 }
1130
Bruce Allan75ce1532012-02-08 02:54:48 +00001131release:
Bruce Allan94d81862009-11-20 23:25:26 +00001132 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001133 return ret_val;
1134}
1135
1136/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001137 * e1000_k1_gig_workaround_hv - K1 Si workaround
1138 * @hw: pointer to the HW structure
1139 * @link: link up bool flag
1140 *
1141 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1142 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1143 * If link is down, the function will restore the default K1 setting located
1144 * in the NVM.
1145 **/
1146static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1147{
1148 s32 ret_val = 0;
1149 u16 status_reg = 0;
1150 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1151
1152 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001153 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001154
1155 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001156 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001157 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001158 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001159
1160 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1161 if (link) {
1162 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan94d81862009-11-20 23:25:26 +00001163 ret_val = hw->phy.ops.read_reg_locked(hw, BM_CS_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +00001164 &status_reg);
1165 if (ret_val)
1166 goto release;
1167
1168 status_reg &= BM_CS_STATUS_LINK_UP |
1169 BM_CS_STATUS_RESOLVED |
1170 BM_CS_STATUS_SPEED_MASK;
1171
1172 if (status_reg == (BM_CS_STATUS_LINK_UP |
1173 BM_CS_STATUS_RESOLVED |
1174 BM_CS_STATUS_SPEED_1000))
1175 k1_enable = false;
1176 }
1177
1178 if (hw->phy.type == e1000_phy_82577) {
Bruce Allan94d81862009-11-20 23:25:26 +00001179 ret_val = hw->phy.ops.read_reg_locked(hw, HV_M_STATUS,
Bruce Allan1d5846b2009-10-29 13:46:05 +00001180 &status_reg);
1181 if (ret_val)
1182 goto release;
1183
1184 status_reg &= HV_M_STATUS_LINK_UP |
1185 HV_M_STATUS_AUTONEG_COMPLETE |
1186 HV_M_STATUS_SPEED_MASK;
1187
1188 if (status_reg == (HV_M_STATUS_LINK_UP |
1189 HV_M_STATUS_AUTONEG_COMPLETE |
1190 HV_M_STATUS_SPEED_1000))
1191 k1_enable = false;
1192 }
1193
1194 /* Link stall fix for link up */
Bruce Allan94d81862009-11-20 23:25:26 +00001195 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +00001196 0x0100);
1197 if (ret_val)
1198 goto release;
1199
1200 } else {
1201 /* Link stall fix for link down */
Bruce Allan94d81862009-11-20 23:25:26 +00001202 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
Bruce Allan1d5846b2009-10-29 13:46:05 +00001203 0x4100);
1204 if (ret_val)
1205 goto release;
1206 }
1207
1208 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1209
1210release:
Bruce Allan94d81862009-11-20 23:25:26 +00001211 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001212
Bruce Allan1d5846b2009-10-29 13:46:05 +00001213 return ret_val;
1214}
1215
1216/**
1217 * e1000_configure_k1_ich8lan - Configure K1 power state
1218 * @hw: pointer to the HW structure
1219 * @enable: K1 state to configure
1220 *
1221 * Configure the K1 power state based on the provided parameter.
1222 * Assumes semaphore already acquired.
1223 *
1224 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1225 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001226s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001227{
1228 s32 ret_val = 0;
1229 u32 ctrl_reg = 0;
1230 u32 ctrl_ext = 0;
1231 u32 reg = 0;
1232 u16 kmrn_reg = 0;
1233
Bruce Allan3d3a1672012-02-23 03:13:18 +00001234 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1235 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001236 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001237 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001238
1239 if (k1_enable)
1240 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1241 else
1242 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1243
Bruce Allan3d3a1672012-02-23 03:13:18 +00001244 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1245 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001246 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001247 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001248
1249 udelay(20);
1250 ctrl_ext = er32(CTRL_EXT);
1251 ctrl_reg = er32(CTRL);
1252
1253 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1254 reg |= E1000_CTRL_FRCSPD;
1255 ew32(CTRL, reg);
1256
1257 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001258 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001259 udelay(20);
1260 ew32(CTRL, ctrl_reg);
1261 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001262 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001263 udelay(20);
1264
Bruce Allan5015e532012-02-08 02:55:56 +00001265 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001266}
1267
1268/**
Bruce Allanf523d212009-10-29 13:45:45 +00001269 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1270 * @hw: pointer to the HW structure
1271 * @d0_state: boolean if entering d0 or d3 device state
1272 *
1273 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1274 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1275 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1276 **/
1277static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1278{
1279 s32 ret_val = 0;
1280 u32 mac_reg;
1281 u16 oem_reg;
1282
Bruce Alland3738bb2010-06-16 13:27:28 +00001283 if ((hw->mac.type != e1000_pch2lan) && (hw->mac.type != e1000_pchlan))
Bruce Allanf523d212009-10-29 13:45:45 +00001284 return ret_val;
1285
Bruce Allan94d81862009-11-20 23:25:26 +00001286 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001287 if (ret_val)
1288 return ret_val;
1289
Bruce Alland3738bb2010-06-16 13:27:28 +00001290 if (!(hw->mac.type == e1000_pch2lan)) {
1291 mac_reg = er32(EXTCNF_CTRL);
1292 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001293 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001294 }
Bruce Allanf523d212009-10-29 13:45:45 +00001295
1296 mac_reg = er32(FEXTNVM);
1297 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001298 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001299
1300 mac_reg = er32(PHY_CTRL);
1301
Bruce Allan94d81862009-11-20 23:25:26 +00001302 ret_val = hw->phy.ops.read_reg_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001303 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001304 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001305
1306 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1307
1308 if (d0_state) {
1309 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1310 oem_reg |= HV_OEM_BITS_GBE_DIS;
1311
1312 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1313 oem_reg |= HV_OEM_BITS_LPLU;
1314 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001315 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1316 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001317 oem_reg |= HV_OEM_BITS_GBE_DIS;
1318
Bruce Allan03299e42011-09-30 08:07:05 +00001319 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1320 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001321 oem_reg |= HV_OEM_BITS_LPLU;
1322 }
Bruce Allan03299e42011-09-30 08:07:05 +00001323
Bruce Allan92fe1732012-04-12 06:27:03 +00001324 /* Set Restart auto-neg to activate the bits */
1325 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1326 !hw->phy.ops.check_reset_block(hw))
1327 oem_reg |= HV_OEM_BITS_RESTART_AN;
1328
Bruce Allan94d81862009-11-20 23:25:26 +00001329 ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001330
Bruce Allan75ce1532012-02-08 02:54:48 +00001331release:
Bruce Allan94d81862009-11-20 23:25:26 +00001332 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001333
1334 return ret_val;
1335}
1336
1337
1338/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001339 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1340 * @hw: pointer to the HW structure
1341 **/
1342static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1343{
1344 s32 ret_val;
1345 u16 data;
1346
1347 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1348 if (ret_val)
1349 return ret_val;
1350
1351 data |= HV_KMRN_MDIO_SLOW;
1352
1353 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1354
1355 return ret_val;
1356}
1357
1358/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001359 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1360 * done after every PHY reset.
1361 **/
1362static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1363{
1364 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001365 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001366
1367 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001368 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001369
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001370 /* Set MDIO slow mode before any other MDIO access */
1371 if (hw->phy.type == e1000_phy_82577) {
1372 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1373 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001374 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001375 }
1376
Bruce Allana4f58f52009-06-02 11:29:18 +00001377 if (((hw->phy.type == e1000_phy_82577) &&
1378 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1379 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1380 /* Disable generation of early preamble */
1381 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1382 if (ret_val)
1383 return ret_val;
1384
1385 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001386 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001387 if (ret_val)
1388 return ret_val;
1389 }
1390
1391 if (hw->phy.type == e1000_phy_82578) {
1392 /*
1393 * Return registers to default by doing a soft reset then
1394 * writing 0x3140 to the control register.
1395 */
1396 if (hw->phy.revision < 2) {
1397 e1000e_phy_sw_reset(hw);
1398 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1399 }
1400 }
1401
1402 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001403 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001404 if (ret_val)
1405 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001406
Bruce Allana4f58f52009-06-02 11:29:18 +00001407 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001408 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001409 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001410 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001411 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001412
Bruce Allan1d5846b2009-10-29 13:46:05 +00001413 /*
1414 * Configure the K1 Si workaround during phy reset assuming there is
1415 * link so that it disables K1 if link is in 1Gbps.
1416 */
1417 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001418 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001419 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001420
Bruce Allanbaf86c92010-01-13 01:53:08 +00001421 /* Workaround for link disconnects on a busy hub in half duplex */
1422 ret_val = hw->phy.ops.acquire(hw);
1423 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001424 return ret_val;
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00001425 ret_val = hw->phy.ops.read_reg_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001426 if (ret_val)
1427 goto release;
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00001428 ret_val = hw->phy.ops.write_reg_locked(hw, BM_PORT_GEN_CFG,
1429 phy_data & 0x00FF);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001430release:
1431 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001432
Bruce Allana4f58f52009-06-02 11:29:18 +00001433 return ret_val;
1434}
1435
1436/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001437 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1438 * @hw: pointer to the HW structure
1439 **/
1440void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1441{
1442 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001443 u16 i, phy_reg = 0;
1444 s32 ret_val;
1445
1446 ret_val = hw->phy.ops.acquire(hw);
1447 if (ret_val)
1448 return;
1449 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1450 if (ret_val)
1451 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001452
1453 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1454 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1455 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001456 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1457 (u16)(mac_reg & 0xFFFF));
1458 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1459 (u16)((mac_reg >> 16) & 0xFFFF));
1460
Bruce Alland3738bb2010-06-16 13:27:28 +00001461 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001462 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1463 (u16)(mac_reg & 0xFFFF));
1464 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1465 (u16)((mac_reg & E1000_RAH_AV)
1466 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00001467 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00001468
1469 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1470
1471release:
1472 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001473}
1474
Bruce Alland3738bb2010-06-16 13:27:28 +00001475/**
1476 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1477 * with 82579 PHY
1478 * @hw: pointer to the HW structure
1479 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1480 **/
1481s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1482{
1483 s32 ret_val = 0;
1484 u16 phy_reg, data;
1485 u32 mac_reg;
1486 u16 i;
1487
1488 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001489 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001490
1491 /* disable Rx path while enabling/disabling workaround */
1492 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1493 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1494 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001495 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001496
1497 if (enable) {
1498 /*
1499 * Write Rx addresses (rar_entry_count for RAL/H, +4 for
1500 * SHRAL/H) and initial CRC values to the MAC
1501 */
1502 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1503 u8 mac_addr[ETH_ALEN] = {0};
1504 u32 addr_high, addr_low;
1505
1506 addr_high = er32(RAH(i));
1507 if (!(addr_high & E1000_RAH_AV))
1508 continue;
1509 addr_low = er32(RAL(i));
1510 mac_addr[0] = (addr_low & 0xFF);
1511 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1512 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1513 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1514 mac_addr[4] = (addr_high & 0xFF);
1515 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1516
Bruce Allanfe46f582011-01-06 14:29:51 +00001517 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00001518 }
1519
1520 /* Write Rx addresses to the PHY */
1521 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1522
1523 /* Enable jumbo frame workaround in the MAC */
1524 mac_reg = er32(FFLT_DBG);
1525 mac_reg &= ~(1 << 14);
1526 mac_reg |= (7 << 15);
1527 ew32(FFLT_DBG, mac_reg);
1528
1529 mac_reg = er32(RCTL);
1530 mac_reg |= E1000_RCTL_SECRC;
1531 ew32(RCTL, mac_reg);
1532
1533 ret_val = e1000e_read_kmrn_reg(hw,
1534 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1535 &data);
1536 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001537 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001538 ret_val = e1000e_write_kmrn_reg(hw,
1539 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1540 data | (1 << 0));
1541 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001542 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001543 ret_val = e1000e_read_kmrn_reg(hw,
1544 E1000_KMRNCTRLSTA_HD_CTRL,
1545 &data);
1546 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001547 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001548 data &= ~(0xF << 8);
1549 data |= (0xB << 8);
1550 ret_val = e1000e_write_kmrn_reg(hw,
1551 E1000_KMRNCTRLSTA_HD_CTRL,
1552 data);
1553 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001554 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001555
1556 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001557 e1e_rphy(hw, PHY_REG(769, 23), &data);
1558 data &= ~(0x7F << 5);
1559 data |= (0x37 << 5);
1560 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1561 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001562 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001563 e1e_rphy(hw, PHY_REG(769, 16), &data);
1564 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00001565 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1566 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001567 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001568 e1e_rphy(hw, PHY_REG(776, 20), &data);
1569 data &= ~(0x3FF << 2);
1570 data |= (0x1A << 2);
1571 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1572 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001573 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00001574 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00001575 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001576 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001577 e1e_rphy(hw, HV_PM_CTRL, &data);
1578 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1579 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001580 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001581 } else {
1582 /* Write MAC register values back to h/w defaults */
1583 mac_reg = er32(FFLT_DBG);
1584 mac_reg &= ~(0xF << 14);
1585 ew32(FFLT_DBG, mac_reg);
1586
1587 mac_reg = er32(RCTL);
1588 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00001589 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00001590
1591 ret_val = e1000e_read_kmrn_reg(hw,
1592 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1593 &data);
1594 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001595 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001596 ret_val = e1000e_write_kmrn_reg(hw,
1597 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1598 data & ~(1 << 0));
1599 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001600 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001601 ret_val = e1000e_read_kmrn_reg(hw,
1602 E1000_KMRNCTRLSTA_HD_CTRL,
1603 &data);
1604 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001605 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001606 data &= ~(0xF << 8);
1607 data |= (0xB << 8);
1608 ret_val = e1000e_write_kmrn_reg(hw,
1609 E1000_KMRNCTRLSTA_HD_CTRL,
1610 data);
1611 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001612 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001613
1614 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00001615 e1e_rphy(hw, PHY_REG(769, 23), &data);
1616 data &= ~(0x7F << 5);
1617 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1618 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001619 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001620 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001621 data |= (1 << 13);
1622 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1623 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001624 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001625 e1e_rphy(hw, PHY_REG(776, 20), &data);
1626 data &= ~(0x3FF << 2);
1627 data |= (0x8 << 2);
1628 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1629 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001630 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001631 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
1632 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001633 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001634 e1e_rphy(hw, HV_PM_CTRL, &data);
1635 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
1636 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001637 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001638 }
1639
1640 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00001641 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00001642}
1643
1644/**
1645 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1646 * done after every PHY reset.
1647 **/
1648static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1649{
1650 s32 ret_val = 0;
1651
1652 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001653 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001654
1655 /* Set MDIO slow mode before any other MDIO access */
1656 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1657
Bruce Allan4d241362011-12-16 00:46:06 +00001658 ret_val = hw->phy.ops.acquire(hw);
1659 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001660 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00001661 ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_ADDR,
1662 I82579_MSE_THRESHOLD);
1663 if (ret_val)
1664 goto release;
1665 /* set MSE higher to enable link to stay up when noise is high */
1666 ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_DATA, 0x0034);
1667 if (ret_val)
1668 goto release;
1669 ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_ADDR,
1670 I82579_MSE_LINK_DOWN);
1671 if (ret_val)
1672 goto release;
1673 /* drop link after 5 times MSE threshold was reached */
1674 ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_DATA, 0x0005);
1675release:
1676 hw->phy.ops.release(hw);
1677
Bruce Alland3738bb2010-06-16 13:27:28 +00001678 return ret_val;
1679}
1680
1681/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00001682 * e1000_k1_gig_workaround_lv - K1 Si workaround
1683 * @hw: pointer to the HW structure
1684 *
1685 * Workaround to set the K1 beacon duration for 82579 parts
1686 **/
1687static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
1688{
1689 s32 ret_val = 0;
1690 u16 status_reg = 0;
1691 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00001692 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001693
1694 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001695 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001696
1697 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
1698 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
1699 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001700 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001701
1702 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
1703 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
1704 mac_reg = er32(FEXTNVM4);
1705 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
1706
Bruce Allan0ed013e2011-07-29 05:52:56 +00001707 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
1708 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001709 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001710
Bruce Allan0ed013e2011-07-29 05:52:56 +00001711 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00001712 u16 pm_phy_reg;
1713
Bruce Allan0ed013e2011-07-29 05:52:56 +00001714 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
1715 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00001716 /* LV 1G Packet drop issue wa */
1717 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
1718 if (ret_val)
1719 return ret_val;
1720 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
1721 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
1722 if (ret_val)
1723 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00001724 } else {
1725 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
1726 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
1727 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00001728 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00001729 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00001730 }
1731
Bruce Allan831bd2e2010-09-22 17:16:18 +00001732 return ret_val;
1733}
1734
1735/**
Bruce Allan605c82b2010-09-22 17:17:01 +00001736 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
1737 * @hw: pointer to the HW structure
1738 * @gate: boolean set to true to gate, false to ungate
1739 *
1740 * Gate/ungate the automatic PHY configuration via hardware; perform
1741 * the configuration via software instead.
1742 **/
1743static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
1744{
1745 u32 extcnf_ctrl;
1746
1747 if (hw->mac.type != e1000_pch2lan)
1748 return;
1749
1750 extcnf_ctrl = er32(EXTCNF_CTRL);
1751
1752 if (gate)
1753 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
1754 else
1755 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
1756
1757 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00001758}
1759
1760/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00001761 * e1000_lan_init_done_ich8lan - Check for PHY config completion
1762 * @hw: pointer to the HW structure
1763 *
1764 * Check the appropriate indication the MAC has finished configuring the
1765 * PHY after a software reset.
1766 **/
1767static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
1768{
1769 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
1770
1771 /* Wait for basic configuration completes before proceeding */
1772 do {
1773 data = er32(STATUS);
1774 data &= E1000_STATUS_LAN_INIT_DONE;
1775 udelay(100);
1776 } while ((!data) && --loop);
1777
1778 /*
1779 * If basic configuration is incomplete before the above loop
1780 * count reaches 0, loading the configuration from NVM will
1781 * leave the PHY in a bad state possibly resulting in no link.
1782 */
1783 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001784 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00001785
1786 /* Clear the Init Done bit for the next init event */
1787 data = er32(STATUS);
1788 data &= ~E1000_STATUS_LAN_INIT_DONE;
1789 ew32(STATUS, data);
1790}
1791
1792/**
Bruce Allane98cac42010-05-10 15:02:32 +00001793 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07001794 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795 **/
Bruce Allane98cac42010-05-10 15:02:32 +00001796static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001797{
Bruce Allanf523d212009-10-29 13:45:45 +00001798 s32 ret_val = 0;
1799 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001800
Bruce Allan44abd5c2012-02-22 09:02:37 +00001801 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00001802 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00001803
Bruce Allan5f3eed62010-09-22 17:15:54 +00001804 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00001805 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00001806
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001807 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00001808 switch (hw->mac.type) {
1809 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001810 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
1811 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001812 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00001813 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001814 case e1000_pch2lan:
1815 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
1816 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001817 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001818 break;
Bruce Allane98cac42010-05-10 15:02:32 +00001819 default:
1820 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00001821 }
1822
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00001823 /* Clear the host wakeup bit after lcd reset */
1824 if (hw->mac.type >= e1000_pchlan) {
1825 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
1826 reg &= ~BM_WUC_HOST_WU_BIT;
1827 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
1828 }
Bruce Allandb2932e2009-10-26 11:22:47 +00001829
Bruce Allanf523d212009-10-29 13:45:45 +00001830 /* Configure the LCD with the extended configuration region in NVM */
1831 ret_val = e1000_sw_lcd_config_ich8lan(hw);
1832 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001833 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834
Bruce Allanf523d212009-10-29 13:45:45 +00001835 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00001836 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837
Bruce Allan1effb452011-02-25 06:58:03 +00001838 if (hw->mac.type == e1000_pch2lan) {
1839 /* Ungate automatic PHY configuration on non-managed 82579 */
1840 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00001841 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00001842 e1000_gate_hw_phy_config_ich8lan(hw, false);
1843 }
1844
1845 /* Set EEE LPI Update Timer to 200usec */
1846 ret_val = hw->phy.ops.acquire(hw);
1847 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001848 return ret_val;
Bruce Allan1effb452011-02-25 06:58:03 +00001849 ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_ADDR,
1850 I82579_LPI_UPDATE_TIMER);
Bruce Allan5015e532012-02-08 02:55:56 +00001851 if (!ret_val)
1852 ret_val = hw->phy.ops.write_reg_locked(hw,
1853 I82579_EMI_DATA,
1854 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00001855 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00001856 }
1857
Bruce Allane98cac42010-05-10 15:02:32 +00001858 return ret_val;
1859}
1860
1861/**
1862 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
1863 * @hw: pointer to the HW structure
1864 *
1865 * Resets the PHY
1866 * This is a function pointer entry point called by drivers
1867 * or other shared routines.
1868 **/
1869static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
1870{
1871 s32 ret_val = 0;
1872
Bruce Allan605c82b2010-09-22 17:17:01 +00001873 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
1874 if ((hw->mac.type == e1000_pch2lan) &&
1875 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1876 e1000_gate_hw_phy_config_ich8lan(hw, true);
1877
Bruce Allane98cac42010-05-10 15:02:32 +00001878 ret_val = e1000e_phy_hw_reset_generic(hw);
1879 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001880 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00001881
Bruce Allan5015e532012-02-08 02:55:56 +00001882 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001883}
1884
1885/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00001886 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1887 * @hw: pointer to the HW structure
1888 * @active: true to enable LPLU, false to disable
1889 *
1890 * Sets the LPLU state according to the active flag. For PCH, if OEM write
1891 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1892 * the phy speed. This function will manually set the LPLU bit and restart
1893 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
1894 * since it configures the same bit.
1895 **/
1896static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1897{
1898 s32 ret_val = 0;
1899 u16 oem_reg;
1900
1901 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
1902 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001903 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00001904
1905 if (active)
1906 oem_reg |= HV_OEM_BITS_LPLU;
1907 else
1908 oem_reg &= ~HV_OEM_BITS_LPLU;
1909
Bruce Allan44abd5c2012-02-22 09:02:37 +00001910 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00001911 oem_reg |= HV_OEM_BITS_RESTART_AN;
1912
Bruce Allan5015e532012-02-08 02:55:56 +00001913 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00001914}
1915
1916/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001917 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1918 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00001919 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07001920 *
1921 * Sets the LPLU D0 state according to the active flag. When
1922 * activating LPLU this function also disables smart speed
1923 * and vice versa. LPLU will not be activated unless the
1924 * device autonegotiation advertisement meets standards of
1925 * either 10 or 10/100 or 10/100/1000 at all duplexes.
1926 * This is a function pointer entry point only called by
1927 * PHY setup routines.
1928 **/
1929static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1930{
1931 struct e1000_phy_info *phy = &hw->phy;
1932 u32 phy_ctrl;
1933 s32 ret_val = 0;
1934 u16 data;
1935
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001936 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00001937 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001938
1939 phy_ctrl = er32(PHY_CTRL);
1940
1941 if (active) {
1942 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
1943 ew32(PHY_CTRL, phy_ctrl);
1944
Bruce Allan60f12922009-07-01 13:28:14 +00001945 if (phy->type != e1000_phy_igp_3)
1946 return 0;
1947
Bruce Allanad680762008-03-28 09:15:03 -07001948 /*
1949 * Call gig speed drop workaround on LPLU before accessing
1950 * any PHY registers
1951 */
Bruce Allan60f12922009-07-01 13:28:14 +00001952 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953 e1000e_gig_downshift_workaround_ich8lan(hw);
1954
1955 /* When LPLU is enabled, we should disable SmartSpeed */
1956 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1957 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1958 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1959 if (ret_val)
1960 return ret_val;
1961 } else {
1962 phy_ctrl &= ~E1000_PHY_CTRL_D0A_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 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07001970 * during Dx states where the power conservation is most
1971 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07001972 * SmartSpeed, so performance is maintained.
1973 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001974 if (phy->smart_speed == e1000_smart_speed_on) {
1975 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001976 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977 if (ret_val)
1978 return ret_val;
1979
1980 data |= IGP01E1000_PSCFR_SMART_SPEED;
1981 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001982 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001983 if (ret_val)
1984 return ret_val;
1985 } else if (phy->smart_speed == e1000_smart_speed_off) {
1986 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001987 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001988 if (ret_val)
1989 return ret_val;
1990
1991 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1992 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07001993 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001994 if (ret_val)
1995 return ret_val;
1996 }
1997 }
1998
1999 return 0;
2000}
2001
2002/**
2003 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2004 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002005 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002006 *
2007 * Sets the LPLU D3 state according to the active flag. When
2008 * activating LPLU this function also disables smart speed
2009 * and vice versa. LPLU will not be activated unless the
2010 * device autonegotiation advertisement meets standards of
2011 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2012 * This is a function pointer entry point only called by
2013 * PHY setup routines.
2014 **/
2015static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2016{
2017 struct e1000_phy_info *phy = &hw->phy;
2018 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002019 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002020 u16 data;
2021
2022 phy_ctrl = er32(PHY_CTRL);
2023
2024 if (!active) {
2025 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2026 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002027
2028 if (phy->type != e1000_phy_igp_3)
2029 return 0;
2030
Bruce Allanad680762008-03-28 09:15:03 -07002031 /*
2032 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002033 * during Dx states where the power conservation is most
2034 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002035 * SmartSpeed, so performance is maintained.
2036 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002037 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002038 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2039 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002040 if (ret_val)
2041 return ret_val;
2042
2043 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002044 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2045 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002046 if (ret_val)
2047 return ret_val;
2048 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002049 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2050 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002051 if (ret_val)
2052 return ret_val;
2053
2054 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002055 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2056 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002057 if (ret_val)
2058 return ret_val;
2059 }
2060 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2061 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2062 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2063 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2064 ew32(PHY_CTRL, phy_ctrl);
2065
Bruce Allan60f12922009-07-01 13:28:14 +00002066 if (phy->type != e1000_phy_igp_3)
2067 return 0;
2068
Bruce Allanad680762008-03-28 09:15:03 -07002069 /*
2070 * Call gig speed drop workaround on LPLU before accessing
2071 * any PHY registers
2072 */
Bruce Allan60f12922009-07-01 13:28:14 +00002073 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002074 e1000e_gig_downshift_workaround_ich8lan(hw);
2075
2076 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002077 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002078 if (ret_val)
2079 return ret_val;
2080
2081 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002082 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002083 }
2084
Bruce Alland7eb3382012-02-08 02:55:14 +00002085 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002086}
2087
2088/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002089 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2090 * @hw: pointer to the HW structure
2091 * @bank: pointer to the variable that returns the active bank
2092 *
2093 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002094 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002095 **/
2096static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2097{
Bruce Allane2434552008-11-21 17:02:41 -08002098 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002099 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002100 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2101 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002102 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002103 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002104
Bruce Allane2434552008-11-21 17:02:41 -08002105 switch (hw->mac.type) {
2106 case e1000_ich8lan:
2107 case e1000_ich9lan:
2108 eecd = er32(EECD);
2109 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2110 E1000_EECD_SEC1VAL_VALID_MASK) {
2111 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002112 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002113 else
2114 *bank = 0;
2115
2116 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002117 }
Bruce Allan434f1392011-12-16 00:46:54 +00002118 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002119 /* fall-thru */
2120 default:
2121 /* set bank to 0 in case flash read fails */
2122 *bank = 0;
2123
2124 /* Check bank 0 */
2125 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
2126 &sig_byte);
2127 if (ret_val)
2128 return ret_val;
2129 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2130 E1000_ICH_NVM_SIG_VALUE) {
2131 *bank = 0;
2132 return 0;
2133 }
2134
2135 /* Check bank 1 */
2136 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
2137 bank1_offset,
2138 &sig_byte);
2139 if (ret_val)
2140 return ret_val;
2141 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2142 E1000_ICH_NVM_SIG_VALUE) {
2143 *bank = 1;
2144 return 0;
2145 }
2146
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002147 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002148 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002149 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002150}
2151
2152/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002153 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2154 * @hw: pointer to the HW structure
2155 * @offset: The offset (in bytes) of the word(s) to read.
2156 * @words: Size of data to read in words
2157 * @data: Pointer to the word(s) to read at offset.
2158 *
2159 * Reads a word(s) from the NVM using the flash access registers.
2160 **/
2161static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2162 u16 *data)
2163{
2164 struct e1000_nvm_info *nvm = &hw->nvm;
2165 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2166 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002167 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002168 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002169 u16 i, word;
2170
2171 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2172 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002173 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002174 ret_val = -E1000_ERR_NVM;
2175 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002176 }
2177
Bruce Allan94d81862009-11-20 23:25:26 +00002178 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002179
Bruce Allanf4187b52008-08-26 18:36:50 -07002180 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002181 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002182 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002183 bank = 0;
2184 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002185
2186 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002187 act_offset += offset;
2188
Bruce Allan148675a2009-08-07 07:41:56 +00002189 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190 for (i = 0; i < words; i++) {
Bruce Allanb9e06f72011-07-22 06:21:41 +00002191 if (dev_spec->shadow_ram[offset+i].modified) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002192 data[i] = dev_spec->shadow_ram[offset+i].value;
2193 } else {
2194 ret_val = e1000_read_flash_word_ich8lan(hw,
2195 act_offset + i,
2196 &word);
2197 if (ret_val)
2198 break;
2199 data[i] = word;
2200 }
2201 }
2202
Bruce Allan94d81862009-11-20 23:25:26 +00002203 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002204
Bruce Allane2434552008-11-21 17:02:41 -08002205out:
2206 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002207 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002208
Auke Kokbc7f75f2007-09-17 12:30:59 -07002209 return ret_val;
2210}
2211
2212/**
2213 * e1000_flash_cycle_init_ich8lan - Initialize flash
2214 * @hw: pointer to the HW structure
2215 *
2216 * This function does initial flash setup so that a new read/write/erase cycle
2217 * can be started.
2218 **/
2219static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2220{
2221 union ich8_hws_flash_status hsfsts;
2222 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002223
2224 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2225
2226 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002227 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002228 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229 return -E1000_ERR_NVM;
2230 }
2231
2232 /* Clear FCERR and DAEL in hw status by writing 1 */
2233 hsfsts.hsf_status.flcerr = 1;
2234 hsfsts.hsf_status.dael = 1;
2235
2236 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2237
Bruce Allanad680762008-03-28 09:15:03 -07002238 /*
2239 * Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002240 * bit to check against, in order to start a new cycle or
2241 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002242 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002243 * indication whether a cycle is in progress or has been
2244 * completed.
2245 */
2246
Bruce Allan04499ec2012-04-13 00:08:31 +00002247 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allanad680762008-03-28 09:15:03 -07002248 /*
2249 * There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002250 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002251 * Begin by setting Flash Cycle Done.
2252 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253 hsfsts.hsf_status.flcdone = 1;
2254 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2255 ret_val = 0;
2256 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002257 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002258
Bruce Allanad680762008-03-28 09:15:03 -07002259 /*
Bruce Allan5ff5b662009-12-01 15:51:11 +00002260 * Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002261 * cycle has a chance to end before giving up.
2262 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002263 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002264 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002265 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002266 ret_val = 0;
2267 break;
2268 }
2269 udelay(1);
2270 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002271 if (!ret_val) {
Bruce Allanad680762008-03-28 09:15:03 -07002272 /*
2273 * Successful in waiting for previous cycle to timeout,
2274 * now set the Flash Cycle Done.
2275 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002276 hsfsts.hsf_status.flcdone = 1;
2277 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2278 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002279 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002280 }
2281 }
2282
2283 return ret_val;
2284}
2285
2286/**
2287 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2288 * @hw: pointer to the HW structure
2289 * @timeout: maximum time to wait for completion
2290 *
2291 * This function starts a flash cycle and waits for its completion.
2292 **/
2293static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2294{
2295 union ich8_hws_flash_ctrl hsflctl;
2296 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002297 u32 i = 0;
2298
2299 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2300 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2301 hsflctl.hsf_ctrl.flcgo = 1;
2302 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2303
2304 /* wait till FDONE bit is set to 1 */
2305 do {
2306 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002307 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308 break;
2309 udelay(1);
2310 } while (i++ < timeout);
2311
Bruce Allan04499ec2012-04-13 00:08:31 +00002312 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002313 return 0;
2314
Bruce Allan55920b52012-02-08 02:55:25 +00002315 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002316}
2317
2318/**
2319 * e1000_read_flash_word_ich8lan - Read word from flash
2320 * @hw: pointer to the HW structure
2321 * @offset: offset to data location
2322 * @data: pointer to the location for storing the data
2323 *
2324 * Reads the flash word at offset into data. Offset is converted
2325 * to bytes before read.
2326 **/
2327static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2328 u16 *data)
2329{
2330 /* Must convert offset into bytes. */
2331 offset <<= 1;
2332
2333 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2334}
2335
2336/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002337 * e1000_read_flash_byte_ich8lan - Read byte from flash
2338 * @hw: pointer to the HW structure
2339 * @offset: The offset of the byte to read.
2340 * @data: Pointer to a byte to store the value read.
2341 *
2342 * Reads a single byte from the NVM using the flash access registers.
2343 **/
2344static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2345 u8 *data)
2346{
2347 s32 ret_val;
2348 u16 word = 0;
2349
2350 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2351 if (ret_val)
2352 return ret_val;
2353
2354 *data = (u8)word;
2355
2356 return 0;
2357}
2358
2359/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002360 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2361 * @hw: pointer to the HW structure
2362 * @offset: The offset (in bytes) of the byte or word to read.
2363 * @size: Size of data to read, 1=byte 2=word
2364 * @data: Pointer to the word to store the value read.
2365 *
2366 * Reads a byte or word from the NVM using the flash access registers.
2367 **/
2368static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2369 u8 size, u16 *data)
2370{
2371 union ich8_hws_flash_status hsfsts;
2372 union ich8_hws_flash_ctrl hsflctl;
2373 u32 flash_linear_addr;
2374 u32 flash_data = 0;
2375 s32 ret_val = -E1000_ERR_NVM;
2376 u8 count = 0;
2377
2378 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2379 return -E1000_ERR_NVM;
2380
2381 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2382 hw->nvm.flash_base_addr;
2383
2384 do {
2385 udelay(1);
2386 /* Steps */
2387 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002388 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 break;
2390
2391 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2392 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2393 hsflctl.hsf_ctrl.fldbcount = size - 1;
2394 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2395 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2396
2397 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2398
2399 ret_val = e1000_flash_cycle_ich8lan(hw,
2400 ICH_FLASH_READ_COMMAND_TIMEOUT);
2401
Bruce Allanad680762008-03-28 09:15:03 -07002402 /*
2403 * Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002404 * and try the whole sequence a few more times, else
2405 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002406 * least significant byte first msb to lsb
2407 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002408 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002409 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002410 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002411 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002412 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002413 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002414 break;
2415 } else {
Bruce Allanad680762008-03-28 09:15:03 -07002416 /*
2417 * If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002418 * completely hosed, but if the error condition is
2419 * detected, it won't hurt to give it another try...
2420 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2421 */
2422 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002423 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002424 /* Repeat for some time before giving up. */
2425 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002426 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002427 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002428 break;
2429 }
2430 }
2431 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2432
2433 return ret_val;
2434}
2435
2436/**
2437 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2438 * @hw: pointer to the HW structure
2439 * @offset: The offset (in bytes) of the word(s) to write.
2440 * @words: Size of data to write in words
2441 * @data: Pointer to the word(s) to write at offset.
2442 *
2443 * Writes a byte or word to the NVM using the flash access registers.
2444 **/
2445static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2446 u16 *data)
2447{
2448 struct e1000_nvm_info *nvm = &hw->nvm;
2449 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002450 u16 i;
2451
2452 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2453 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002454 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002455 return -E1000_ERR_NVM;
2456 }
2457
Bruce Allan94d81862009-11-20 23:25:26 +00002458 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002459
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002461 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002462 dev_spec->shadow_ram[offset+i].value = data[i];
2463 }
2464
Bruce Allan94d81862009-11-20 23:25:26 +00002465 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002466
Auke Kokbc7f75f2007-09-17 12:30:59 -07002467 return 0;
2468}
2469
2470/**
2471 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2472 * @hw: pointer to the HW structure
2473 *
2474 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2475 * which writes the checksum to the shadow ram. The changes in the shadow
2476 * ram are then committed to the EEPROM by processing each bank at a time
2477 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002478 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002479 * future writes.
2480 **/
2481static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2482{
2483 struct e1000_nvm_info *nvm = &hw->nvm;
2484 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002485 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002486 s32 ret_val;
2487 u16 data;
2488
2489 ret_val = e1000e_update_nvm_checksum_generic(hw);
2490 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002491 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002492
2493 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002494 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002495
Bruce Allan94d81862009-11-20 23:25:26 +00002496 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002497
Bruce Allanad680762008-03-28 09:15:03 -07002498 /*
2499 * We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002501 * is going to be written
2502 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002503 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002504 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002505 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002506 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002507 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002508
2509 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 new_bank_offset = nvm->flash_bank_size;
2511 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002512 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002513 if (ret_val)
2514 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002515 } else {
2516 old_bank_offset = nvm->flash_bank_size;
2517 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002518 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002519 if (ret_val)
2520 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 }
2522
2523 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allanad680762008-03-28 09:15:03 -07002524 /*
2525 * Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002526 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002527 * in the shadow RAM
2528 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002529 if (dev_spec->shadow_ram[i].modified) {
2530 data = dev_spec->shadow_ram[i].value;
2531 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002532 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2533 old_bank_offset,
2534 &data);
2535 if (ret_val)
2536 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002537 }
2538
Bruce Allanad680762008-03-28 09:15:03 -07002539 /*
2540 * If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541 * (15:14) are 11b until the commit has completed.
2542 * This will allow us to write 10b which indicates the
2543 * signature is valid. We want to do this after the write
2544 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002545 * while the write is still in progress
2546 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547 if (i == E1000_ICH_NVM_SIG_WORD)
2548 data |= E1000_ICH_NVM_SIG_MASK;
2549
2550 /* Convert offset to bytes. */
2551 act_offset = (i + new_bank_offset) << 1;
2552
2553 udelay(100);
2554 /* Write the bytes to the new bank. */
2555 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2556 act_offset,
2557 (u8)data);
2558 if (ret_val)
2559 break;
2560
2561 udelay(100);
2562 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2563 act_offset + 1,
2564 (u8)(data >> 8));
2565 if (ret_val)
2566 break;
2567 }
2568
Bruce Allanad680762008-03-28 09:15:03 -07002569 /*
2570 * Don't bother writing the segment valid bits if sector
2571 * programming failed.
2572 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002573 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002574 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002575 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002576 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577 }
2578
Bruce Allanad680762008-03-28 09:15:03 -07002579 /*
2580 * Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002581 * to 10b in word 0x13 , this can be done without an
2582 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002583 * and we need to change bit 14 to 0b
2584 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002585 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002586 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002587 if (ret_val)
2588 goto release;
2589
Auke Kokbc7f75f2007-09-17 12:30:59 -07002590 data &= 0xBFFF;
2591 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2592 act_offset * 2 + 1,
2593 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002594 if (ret_val)
2595 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002596
Bruce Allanad680762008-03-28 09:15:03 -07002597 /*
2598 * And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002599 * its signature word (0x13) high_byte to 0b. This can be
2600 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002601 * to 1's. We can write 1's to 0's without an erase
2602 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002603 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2604 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002605 if (ret_val)
2606 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002607
2608 /* Great! Everything worked, we can now clear the cached entries. */
2609 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002610 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611 dev_spec->shadow_ram[i].value = 0xFFFF;
2612 }
2613
Bruce Allan9c5e2092010-05-10 15:00:31 +00002614release:
Bruce Allan94d81862009-11-20 23:25:26 +00002615 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002616
Bruce Allanad680762008-03-28 09:15:03 -07002617 /*
2618 * Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002619 * until after the next adapter reset.
2620 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002621 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00002622 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00002623 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002624 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002625
Bruce Allane2434552008-11-21 17:02:41 -08002626out:
2627 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002628 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002629
Auke Kokbc7f75f2007-09-17 12:30:59 -07002630 return ret_val;
2631}
2632
2633/**
2634 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2635 * @hw: pointer to the HW structure
2636 *
2637 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2638 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
2639 * calculated, in which case we need to calculate the checksum and set bit 6.
2640 **/
2641static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2642{
2643 s32 ret_val;
2644 u16 data;
2645
Bruce Allanad680762008-03-28 09:15:03 -07002646 /*
2647 * Read 0x19 and check bit 6. If this bit is 0, the checksum
Auke Kokbc7f75f2007-09-17 12:30:59 -07002648 * needs to be fixed. This bit is an indication that the NVM
2649 * was prepared by OEM software and did not calculate the
2650 * checksum...a likely scenario.
2651 */
2652 ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
2653 if (ret_val)
2654 return ret_val;
2655
Bruce Allan04499ec2012-04-13 00:08:31 +00002656 if (!(data & 0x40)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002657 data |= 0x40;
2658 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
2659 if (ret_val)
2660 return ret_val;
2661 ret_val = e1000e_update_nvm_checksum(hw);
2662 if (ret_val)
2663 return ret_val;
2664 }
2665
2666 return e1000e_validate_nvm_checksum_generic(hw);
2667}
2668
2669/**
Bruce Allan4a770352008-10-01 17:18:35 -07002670 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
2671 * @hw: pointer to the HW structure
2672 *
2673 * To prevent malicious write/erase of the NVM, set it to be read-only
2674 * so that the hardware ignores all write/erase cycles of the NVM via
2675 * the flash control registers. The shadow-ram copy of the NVM will
2676 * still be updated, however any updates to this copy will not stick
2677 * across driver reloads.
2678 **/
2679void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
2680{
Bruce Allanca15df52009-10-26 11:23:43 +00002681 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07002682 union ich8_flash_protected_range pr0;
2683 union ich8_hws_flash_status hsfsts;
2684 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07002685
Bruce Allan94d81862009-11-20 23:25:26 +00002686 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002687
2688 gfpreg = er32flash(ICH_FLASH_GFPREG);
2689
2690 /* Write-protect GbE Sector of NVM */
2691 pr0.regval = er32flash(ICH_FLASH_PR0);
2692 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
2693 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
2694 pr0.range.wpe = true;
2695 ew32flash(ICH_FLASH_PR0, pr0.regval);
2696
2697 /*
2698 * Lock down a subset of GbE Flash Control Registers, e.g.
2699 * PR0 to prevent the write-protection from being lifted.
2700 * Once FLOCKDN is set, the registers protected by it cannot
2701 * be written until FLOCKDN is cleared by a hardware reset.
2702 */
2703 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2704 hsfsts.hsf_status.flockdn = true;
2705 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2706
Bruce Allan94d81862009-11-20 23:25:26 +00002707 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07002708}
2709
2710/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
2712 * @hw: pointer to the HW structure
2713 * @offset: The offset (in bytes) of the byte/word to read.
2714 * @size: Size of data to read, 1=byte 2=word
2715 * @data: The byte(s) to write to the NVM.
2716 *
2717 * Writes one/two bytes to the NVM using the flash access registers.
2718 **/
2719static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2720 u8 size, u16 data)
2721{
2722 union ich8_hws_flash_status hsfsts;
2723 union ich8_hws_flash_ctrl hsflctl;
2724 u32 flash_linear_addr;
2725 u32 flash_data = 0;
2726 s32 ret_val;
2727 u8 count = 0;
2728
2729 if (size < 1 || size > 2 || data > size * 0xff ||
2730 offset > ICH_FLASH_LINEAR_ADDR_MASK)
2731 return -E1000_ERR_NVM;
2732
2733 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2734 hw->nvm.flash_base_addr;
2735
2736 do {
2737 udelay(1);
2738 /* Steps */
2739 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2740 if (ret_val)
2741 break;
2742
2743 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2744 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2745 hsflctl.hsf_ctrl.fldbcount = size -1;
2746 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
2747 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2748
2749 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2750
2751 if (size == 1)
2752 flash_data = (u32)data & 0x00FF;
2753 else
2754 flash_data = (u32)data;
2755
2756 ew32flash(ICH_FLASH_FDATA0, flash_data);
2757
Bruce Allanad680762008-03-28 09:15:03 -07002758 /*
2759 * check if FCERR is set to 1 , if set to 1, clear it
2760 * and try the whole sequence a few more times else done
2761 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002762 ret_val = e1000_flash_cycle_ich8lan(hw,
2763 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
2764 if (!ret_val)
2765 break;
2766
Bruce Allanad680762008-03-28 09:15:03 -07002767 /*
2768 * If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07002769 * completely hosed, but if the error condition
2770 * is detected, it won't hurt to give it another
2771 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
2772 */
2773 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002774 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002775 /* Repeat for some time before giving up. */
2776 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002777 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002778 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002779 break;
2780 }
2781 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2782
2783 return ret_val;
2784}
2785
2786/**
2787 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
2788 * @hw: pointer to the HW structure
2789 * @offset: The index of the byte to read.
2790 * @data: The byte to write to the NVM.
2791 *
2792 * Writes a single byte to the NVM using the flash access registers.
2793 **/
2794static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2795 u8 data)
2796{
2797 u16 word = (u16)data;
2798
2799 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
2800}
2801
2802/**
2803 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
2804 * @hw: pointer to the HW structure
2805 * @offset: The offset of the byte to write.
2806 * @byte: The byte to write to the NVM.
2807 *
2808 * Writes a single byte to the NVM using the flash access registers.
2809 * Goes through a retry algorithm before giving up.
2810 **/
2811static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
2812 u32 offset, u8 byte)
2813{
2814 s32 ret_val;
2815 u16 program_retries;
2816
2817 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2818 if (!ret_val)
2819 return ret_val;
2820
2821 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002822 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002823 udelay(100);
2824 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2825 if (!ret_val)
2826 break;
2827 }
2828 if (program_retries == 100)
2829 return -E1000_ERR_NVM;
2830
2831 return 0;
2832}
2833
2834/**
2835 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
2836 * @hw: pointer to the HW structure
2837 * @bank: 0 for first bank, 1 for second bank, etc.
2838 *
2839 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
2840 * bank N is 4096 * N + flash_reg_addr.
2841 **/
2842static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
2843{
2844 struct e1000_nvm_info *nvm = &hw->nvm;
2845 union ich8_hws_flash_status hsfsts;
2846 union ich8_hws_flash_ctrl hsflctl;
2847 u32 flash_linear_addr;
2848 /* bank size is in 16bit words - adjust to bytes */
2849 u32 flash_bank_size = nvm->flash_bank_size * 2;
2850 s32 ret_val;
2851 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00002852 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002853
2854 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2855
Bruce Allanad680762008-03-28 09:15:03 -07002856 /*
2857 * Determine HW Sector size: Read BERASE bits of hw flash status
2858 * register
2859 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07002860 * consecutive sectors. The start index for the nth Hw sector
2861 * can be calculated as = bank * 4096 + n * 256
2862 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
2863 * The start index for the nth Hw sector can be calculated
2864 * as = bank * 4096
2865 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
2866 * (ich9 only, otherwise error condition)
2867 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
2868 */
2869 switch (hsfsts.hsf_status.berasesz) {
2870 case 0:
2871 /* Hw sector size 256 */
2872 sector_size = ICH_FLASH_SEG_SIZE_256;
2873 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
2874 break;
2875 case 1:
2876 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00002877 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002878 break;
2879 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00002880 sector_size = ICH_FLASH_SEG_SIZE_8K;
2881 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002882 break;
2883 case 3:
2884 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00002885 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002886 break;
2887 default:
2888 return -E1000_ERR_NVM;
2889 }
2890
2891 /* Start with the base address, then add the sector offset. */
2892 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00002893 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002894
2895 for (j = 0; j < iteration ; j++) {
2896 do {
2897 /* Steps */
2898 ret_val = e1000_flash_cycle_init_ich8lan(hw);
2899 if (ret_val)
2900 return ret_val;
2901
Bruce Allanad680762008-03-28 09:15:03 -07002902 /*
2903 * Write a value 11 (block Erase) in Flash
2904 * Cycle field in hw flash control
2905 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2907 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
2908 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2909
Bruce Allanad680762008-03-28 09:15:03 -07002910 /*
2911 * Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07002912 * block into Flash Linear address field in Flash
2913 * Address.
2914 */
2915 flash_linear_addr += (j * sector_size);
2916 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2917
2918 ret_val = e1000_flash_cycle_ich8lan(hw,
2919 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002920 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002921 break;
2922
Bruce Allanad680762008-03-28 09:15:03 -07002923 /*
2924 * Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002925 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07002926 * a few more times else Done
2927 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002928 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002929 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07002930 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002931 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002932 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933 return ret_val;
2934 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
2935 }
2936
2937 return 0;
2938}
2939
2940/**
2941 * e1000_valid_led_default_ich8lan - Set the default LED settings
2942 * @hw: pointer to the HW structure
2943 * @data: Pointer to the LED settings
2944 *
2945 * Reads the LED default settings from the NVM to data. If the NVM LED
2946 * settings is all 0's or F's, set the LED default to a valid LED default
2947 * setting.
2948 **/
2949static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
2950{
2951 s32 ret_val;
2952
2953 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
2954 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002955 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002956 return ret_val;
2957 }
2958
2959 if (*data == ID_LED_RESERVED_0000 ||
2960 *data == ID_LED_RESERVED_FFFF)
2961 *data = ID_LED_DEFAULT_ICH8LAN;
2962
2963 return 0;
2964}
2965
2966/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002967 * e1000_id_led_init_pchlan - store LED configurations
2968 * @hw: pointer to the HW structure
2969 *
2970 * PCH does not control LEDs via the LEDCTL register, rather it uses
2971 * the PHY LED configuration register.
2972 *
2973 * PCH also does not have an "always on" or "always off" mode which
2974 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00002975 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00002976 * use "link_up" mode. The LEDs will still ID on request if there is no
2977 * link based on logic in e1000_led_[on|off]_pchlan().
2978 **/
2979static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
2980{
2981 struct e1000_mac_info *mac = &hw->mac;
2982 s32 ret_val;
2983 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
2984 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
2985 u16 data, i, temp, shift;
2986
2987 /* Get default ID LED modes */
2988 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
2989 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002990 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002991
2992 mac->ledctl_default = er32(LEDCTL);
2993 mac->ledctl_mode1 = mac->ledctl_default;
2994 mac->ledctl_mode2 = mac->ledctl_default;
2995
2996 for (i = 0; i < 4; i++) {
2997 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
2998 shift = (i * 5);
2999 switch (temp) {
3000 case ID_LED_ON1_DEF2:
3001 case ID_LED_ON1_ON2:
3002 case ID_LED_ON1_OFF2:
3003 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3004 mac->ledctl_mode1 |= (ledctl_on << shift);
3005 break;
3006 case ID_LED_OFF1_DEF2:
3007 case ID_LED_OFF1_ON2:
3008 case ID_LED_OFF1_OFF2:
3009 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3010 mac->ledctl_mode1 |= (ledctl_off << shift);
3011 break;
3012 default:
3013 /* Do nothing */
3014 break;
3015 }
3016 switch (temp) {
3017 case ID_LED_DEF1_ON2:
3018 case ID_LED_ON1_ON2:
3019 case ID_LED_OFF1_ON2:
3020 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3021 mac->ledctl_mode2 |= (ledctl_on << shift);
3022 break;
3023 case ID_LED_DEF1_OFF2:
3024 case ID_LED_ON1_OFF2:
3025 case ID_LED_OFF1_OFF2:
3026 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3027 mac->ledctl_mode2 |= (ledctl_off << shift);
3028 break;
3029 default:
3030 /* Do nothing */
3031 break;
3032 }
3033 }
3034
Bruce Allan5015e532012-02-08 02:55:56 +00003035 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003036}
3037
3038/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003039 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3040 * @hw: pointer to the HW structure
3041 *
3042 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3043 * register, so the the bus width is hard coded.
3044 **/
3045static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3046{
3047 struct e1000_bus_info *bus = &hw->bus;
3048 s32 ret_val;
3049
3050 ret_val = e1000e_get_bus_info_pcie(hw);
3051
Bruce Allanad680762008-03-28 09:15:03 -07003052 /*
3053 * ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003054 * a configuration space, but do not contain
3055 * PCI Express Capability registers, so bus width
3056 * must be hardcoded.
3057 */
3058 if (bus->width == e1000_bus_width_unknown)
3059 bus->width = e1000_bus_width_pcie_x1;
3060
3061 return ret_val;
3062}
3063
3064/**
3065 * e1000_reset_hw_ich8lan - Reset the hardware
3066 * @hw: pointer to the HW structure
3067 *
3068 * Does a full reset of the hardware which includes a reset of the PHY and
3069 * MAC.
3070 **/
3071static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3072{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003073 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allandb2932e2009-10-26 11:22:47 +00003074 u16 reg;
Bruce Allandd93f952011-01-06 14:29:48 +00003075 u32 ctrl, kab;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003076 s32 ret_val;
3077
Bruce Allanad680762008-03-28 09:15:03 -07003078 /*
3079 * Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003080 * on the last TLP read/write transaction when MAC is reset.
3081 */
3082 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003083 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003084 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003085
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003086 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003087 ew32(IMC, 0xffffffff);
3088
Bruce Allanad680762008-03-28 09:15:03 -07003089 /*
3090 * Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003091 * any pending transactions to complete before we hit the MAC
3092 * with the global reset.
3093 */
3094 ew32(RCTL, 0);
3095 ew32(TCTL, E1000_TCTL_PSP);
3096 e1e_flush();
3097
Bruce Allan1bba4382011-03-19 00:27:20 +00003098 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003099
3100 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3101 if (hw->mac.type == e1000_ich8lan) {
3102 /* Set Tx and Rx buffer allocation to 8k apiece. */
3103 ew32(PBA, E1000_PBA_8K);
3104 /* Set Packet Buffer Size to 16k. */
3105 ew32(PBS, E1000_PBS_16K);
3106 }
3107
Bruce Allan1d5846b2009-10-29 13:46:05 +00003108 if (hw->mac.type == e1000_pchlan) {
3109 /* Save the NVM K1 bit setting*/
3110 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &reg);
3111 if (ret_val)
3112 return ret_val;
3113
3114 if (reg & E1000_NVM_K1_ENABLE)
3115 dev_spec->nvm_k1_enabled = true;
3116 else
3117 dev_spec->nvm_k1_enabled = false;
3118 }
3119
Auke Kokbc7f75f2007-09-17 12:30:59 -07003120 ctrl = er32(CTRL);
3121
Bruce Allan44abd5c2012-02-22 09:02:37 +00003122 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allanad680762008-03-28 09:15:03 -07003123 /*
Bruce Allane98cac42010-05-10 15:02:32 +00003124 * Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003125 * time to make sure the interface between MAC and the
3126 * external PHY is reset.
3127 */
3128 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003129
3130 /*
3131 * Gate automatic PHY configuration by hardware on
3132 * non-managed 82579
3133 */
3134 if ((hw->mac.type == e1000_pch2lan) &&
3135 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3136 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003137 }
3138 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003139 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003140 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003141 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003142 msleep(20);
3143
Bruce Allanfc0c7762009-07-01 13:27:55 +00003144 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003145 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003146
Bruce Allane98cac42010-05-10 15:02:32 +00003147 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003148 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003149 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003150 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003151
Bruce Allane98cac42010-05-10 15:02:32 +00003152 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003153 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003154 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003155 }
Bruce Allane98cac42010-05-10 15:02:32 +00003156
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003157 /*
3158 * For PCH, this write will make sure that any noise
3159 * will be detected as a CRC error and be dropped rather than show up
3160 * as a bad packet to the DMA engine.
3161 */
3162 if (hw->mac.type == e1000_pchlan)
3163 ew32(CRC_OFFSET, 0x65656565);
3164
Auke Kokbc7f75f2007-09-17 12:30:59 -07003165 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003166 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003167
3168 kab = er32(KABGTXD);
3169 kab |= E1000_KABGTXD_BGSQLBIAS;
3170 ew32(KABGTXD, kab);
3171
Bruce Allan5015e532012-02-08 02:55:56 +00003172 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003173}
3174
3175/**
3176 * e1000_init_hw_ich8lan - Initialize the hardware
3177 * @hw: pointer to the HW structure
3178 *
3179 * Prepares the hardware for transmit and receive by doing the following:
3180 * - initialize hardware bits
3181 * - initialize LED identification
3182 * - setup receive address registers
3183 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003184 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003185 * - clear statistics
3186 **/
3187static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3188{
3189 struct e1000_mac_info *mac = &hw->mac;
3190 u32 ctrl_ext, txdctl, snoop;
3191 s32 ret_val;
3192 u16 i;
3193
3194 e1000_initialize_hw_bits_ich8lan(hw);
3195
3196 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003197 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00003198 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003199 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00003200 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003201
3202 /* Setup the receive address. */
3203 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3204
3205 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003206 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003207 for (i = 0; i < mac->mta_reg_count; i++)
3208 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3209
Bruce Allanfc0c7762009-07-01 13:27:55 +00003210 /*
3211 * The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003212 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003213 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3214 */
3215 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003216 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3217 i &= ~BM_WUC_HOST_WU_BIT;
3218 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003219 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3220 if (ret_val)
3221 return ret_val;
3222 }
3223
Auke Kokbc7f75f2007-09-17 12:30:59 -07003224 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003225 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003226
3227 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003228 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003229 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3230 E1000_TXDCTL_FULL_TX_DESC_WB;
3231 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3232 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003233 ew32(TXDCTL(0), txdctl);
3234 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003235 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3236 E1000_TXDCTL_FULL_TX_DESC_WB;
3237 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3238 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003239 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003240
Bruce Allanad680762008-03-28 09:15:03 -07003241 /*
3242 * ICH8 has opposite polarity of no_snoop bits.
3243 * By default, we should use snoop behavior.
3244 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003245 if (mac->type == e1000_ich8lan)
3246 snoop = PCIE_ICH8_SNOOP_ALL;
3247 else
3248 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
3249 e1000e_set_pcie_no_snoop(hw, snoop);
3250
3251 ctrl_ext = er32(CTRL_EXT);
3252 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3253 ew32(CTRL_EXT, ctrl_ext);
3254
Bruce Allanad680762008-03-28 09:15:03 -07003255 /*
3256 * Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003257 * important that we do this after we have tried to establish link
3258 * because the symbol error count will increment wildly if there
3259 * is no link.
3260 */
3261 e1000_clear_hw_cntrs_ich8lan(hw);
3262
Bruce Allane561a702012-02-08 02:55:46 +00003263 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003264}
3265/**
3266 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3267 * @hw: pointer to the HW structure
3268 *
3269 * Sets/Clears required hardware bits necessary for correctly setting up the
3270 * hardware for transmit and receive.
3271 **/
3272static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3273{
3274 u32 reg;
3275
3276 /* Extended Device Control */
3277 reg = er32(CTRL_EXT);
3278 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003279 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3280 if (hw->mac.type >= e1000_pchlan)
3281 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003282 ew32(CTRL_EXT, reg);
3283
3284 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003285 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003286 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003287 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003288
3289 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003290 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003291 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003292 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003293
3294 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003295 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003296 if (hw->mac.type == e1000_ich8lan)
3297 reg |= (1 << 28) | (1 << 29);
3298 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003299 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003300
3301 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003302 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003303 if (er32(TCTL) & E1000_TCTL_MULR)
3304 reg &= ~(1 << 28);
3305 else
3306 reg |= (1 << 28);
3307 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003308 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003309
3310 /* Device Status */
3311 if (hw->mac.type == e1000_ich8lan) {
3312 reg = er32(STATUS);
3313 reg &= ~(1 << 31);
3314 ew32(STATUS, reg);
3315 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003316
3317 /*
3318 * work-around descriptor data corruption issue during nfs v2 udp
3319 * traffic, just disable the nfs filtering capability
3320 */
3321 reg = er32(RFCTL);
3322 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
3323 ew32(RFCTL, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003324}
3325
3326/**
3327 * e1000_setup_link_ich8lan - Setup flow control and link settings
3328 * @hw: pointer to the HW structure
3329 *
3330 * Determines which flow control settings to use, then configures flow
3331 * control. Calls the appropriate media-specific link configuration
3332 * function. Assuming the adapter has a valid link partner, a valid link
3333 * should be established. Assumes the hardware has previously been reset
3334 * and the transmitter and receiver are not enabled.
3335 **/
3336static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3337{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003338 s32 ret_val;
3339
Bruce Allan44abd5c2012-02-22 09:02:37 +00003340 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003341 return 0;
3342
Bruce Allanad680762008-03-28 09:15:03 -07003343 /*
3344 * ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003345 * the default flow control setting, so we explicitly
3346 * set it to full.
3347 */
Bruce Allan37289d92009-06-02 11:29:37 +00003348 if (hw->fc.requested_mode == e1000_fc_default) {
3349 /* Workaround h/w hang when Tx flow control enabled */
3350 if (hw->mac.type == e1000_pchlan)
3351 hw->fc.requested_mode = e1000_fc_rx_pause;
3352 else
3353 hw->fc.requested_mode = e1000_fc_full;
3354 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003355
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003356 /*
3357 * Save off the requested flow control mode for use later. Depending
3358 * on the link partner's capabilities, we may or may not use this mode.
3359 */
3360 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003361
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003362 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003363 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003364
3365 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003366 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003367 if (ret_val)
3368 return ret_val;
3369
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003370 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003371 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003372 (hw->phy.type == e1000_phy_82579) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003373 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003374 ew32(FCRTV_PCH, hw->fc.refresh_time);
3375
Bruce Allan482fed82011-01-06 14:29:49 +00003376 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3377 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003378 if (ret_val)
3379 return ret_val;
3380 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381
3382 return e1000e_set_fc_watermarks(hw);
3383}
3384
3385/**
3386 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3387 * @hw: pointer to the HW structure
3388 *
3389 * Configures the kumeran interface to the PHY to wait the appropriate time
3390 * when polling the PHY, then call the generic setup_copper_link to finish
3391 * configuring the copper link.
3392 **/
3393static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3394{
3395 u32 ctrl;
3396 s32 ret_val;
3397 u16 reg_data;
3398
3399 ctrl = er32(CTRL);
3400 ctrl |= E1000_CTRL_SLU;
3401 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3402 ew32(CTRL, ctrl);
3403
Bruce Allanad680762008-03-28 09:15:03 -07003404 /*
3405 * Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003406 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003407 * this fixes erroneous timeouts at 10Mbps.
3408 */
Bruce Allan07818952009-12-08 07:28:01 +00003409 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003410 if (ret_val)
3411 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003412 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3413 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003414 if (ret_val)
3415 return ret_val;
3416 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003417 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3418 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003419 if (ret_val)
3420 return ret_val;
3421
Bruce Allana4f58f52009-06-02 11:29:18 +00003422 switch (hw->phy.type) {
3423 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003424 ret_val = e1000e_copper_link_setup_igp(hw);
3425 if (ret_val)
3426 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003427 break;
3428 case e1000_phy_bm:
3429 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003430 ret_val = e1000e_copper_link_setup_m88(hw);
3431 if (ret_val)
3432 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003433 break;
3434 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003435 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00003436 ret_val = e1000_copper_link_setup_82577(hw);
3437 if (ret_val)
3438 return ret_val;
3439 break;
3440 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003441 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003442 if (ret_val)
3443 return ret_val;
3444
3445 reg_data &= ~IFE_PMC_AUTO_MDIX;
3446
3447 switch (hw->phy.mdix) {
3448 case 1:
3449 reg_data &= ~IFE_PMC_FORCE_MDIX;
3450 break;
3451 case 2:
3452 reg_data |= IFE_PMC_FORCE_MDIX;
3453 break;
3454 case 0:
3455 default:
3456 reg_data |= IFE_PMC_AUTO_MDIX;
3457 break;
3458 }
Bruce Allan482fed82011-01-06 14:29:49 +00003459 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003460 if (ret_val)
3461 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003462 break;
3463 default:
3464 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003465 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003466
Auke Kokbc7f75f2007-09-17 12:30:59 -07003467 return e1000e_setup_copper_link(hw);
3468}
3469
3470/**
3471 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3472 * @hw: pointer to the HW structure
3473 * @speed: pointer to store current link speed
3474 * @duplex: pointer to store the current link duplex
3475 *
Bruce Allanad680762008-03-28 09:15:03 -07003476 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003477 * information and then calls the Kumeran lock loss workaround for links at
3478 * gigabit speeds.
3479 **/
3480static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3481 u16 *duplex)
3482{
3483 s32 ret_val;
3484
3485 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3486 if (ret_val)
3487 return ret_val;
3488
3489 if ((hw->mac.type == e1000_ich8lan) &&
3490 (hw->phy.type == e1000_phy_igp_3) &&
3491 (*speed == SPEED_1000)) {
3492 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3493 }
3494
3495 return ret_val;
3496}
3497
3498/**
3499 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3500 * @hw: pointer to the HW structure
3501 *
3502 * Work-around for 82566 Kumeran PCS lock loss:
3503 * On link status change (i.e. PCI reset, speed change) and link is up and
3504 * speed is gigabit-
3505 * 0) if workaround is optionally disabled do nothing
3506 * 1) wait 1ms for Kumeran link to come up
3507 * 2) check Kumeran Diagnostic register PCS lock loss bit
3508 * 3) if not set the link is locked (all is good), otherwise...
3509 * 4) reset the PHY
3510 * 5) repeat up to 10 times
3511 * Note: this is only called for IGP3 copper when speed is 1gb.
3512 **/
3513static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3514{
3515 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3516 u32 phy_ctrl;
3517 s32 ret_val;
3518 u16 i, data;
3519 bool link;
3520
3521 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3522 return 0;
3523
Bruce Allanad680762008-03-28 09:15:03 -07003524 /*
3525 * Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003526 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003527 * stability
3528 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003529 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3530 if (!link)
3531 return 0;
3532
3533 for (i = 0; i < 10; i++) {
3534 /* read once to clear */
3535 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3536 if (ret_val)
3537 return ret_val;
3538 /* and again to get new status */
3539 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3540 if (ret_val)
3541 return ret_val;
3542
3543 /* check for PCS lock */
3544 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3545 return 0;
3546
3547 /* Issue PHY reset */
3548 e1000_phy_hw_reset(hw);
3549 mdelay(5);
3550 }
3551 /* Disable GigE link negotiation */
3552 phy_ctrl = er32(PHY_CTRL);
3553 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3554 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3555 ew32(PHY_CTRL, phy_ctrl);
3556
Bruce Allanad680762008-03-28 09:15:03 -07003557 /*
3558 * Call gig speed drop workaround on Gig disable before accessing
3559 * any PHY registers
3560 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003561 e1000e_gig_downshift_workaround_ich8lan(hw);
3562
3563 /* unable to acquire PCS lock */
3564 return -E1000_ERR_PHY;
3565}
3566
3567/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00003568 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003569 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003570 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003571 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003572 * If ICH8, set the current Kumeran workaround state (enabled - true
3573 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003574 **/
3575void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3576 bool state)
3577{
3578 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3579
3580 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003581 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003582 return;
3583 }
3584
3585 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3586}
3587
3588/**
3589 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3590 * @hw: pointer to the HW structure
3591 *
3592 * Workaround for 82566 power-down on D3 entry:
3593 * 1) disable gigabit link
3594 * 2) write VR power-down enable
3595 * 3) read it back
3596 * Continue if successful, else issue LCD reset and repeat
3597 **/
3598void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3599{
3600 u32 reg;
3601 u16 data;
3602 u8 retry = 0;
3603
3604 if (hw->phy.type != e1000_phy_igp_3)
3605 return;
3606
3607 /* Try the workaround twice (if needed) */
3608 do {
3609 /* Disable link */
3610 reg = er32(PHY_CTRL);
3611 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3612 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3613 ew32(PHY_CTRL, reg);
3614
Bruce Allanad680762008-03-28 09:15:03 -07003615 /*
3616 * Call gig speed drop workaround on Gig disable before
3617 * accessing any PHY registers
3618 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003619 if (hw->mac.type == e1000_ich8lan)
3620 e1000e_gig_downshift_workaround_ich8lan(hw);
3621
3622 /* Write VR power-down enable */
3623 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3624 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3625 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
3626
3627 /* Read it back and test */
3628 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3629 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3630 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
3631 break;
3632
3633 /* Issue PHY reset and repeat at most one more time */
3634 reg = er32(CTRL);
3635 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
3636 retry++;
3637 } while (retry);
3638}
3639
3640/**
3641 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
3642 * @hw: pointer to the HW structure
3643 *
3644 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08003645 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 * 1) Set Kumeran Near-end loopback
3647 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00003648 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003649 **/
3650void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
3651{
3652 s32 ret_val;
3653 u16 reg_data;
3654
Bruce Allan462d5992011-09-30 08:07:11 +00003655 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656 return;
3657
3658 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3659 &reg_data);
3660 if (ret_val)
3661 return;
3662 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
3663 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3664 reg_data);
3665 if (ret_val)
3666 return;
3667 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
3668 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3669 reg_data);
3670}
3671
3672/**
Bruce Allan99730e42011-05-13 07:19:48 +00003673 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003674 * @hw: pointer to the HW structure
3675 *
3676 * During S0 to Sx transition, it is possible the link remains at gig
3677 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00003678 * 'Gig Disable' to force link speed negotiation to a lower speed based on
3679 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
3680 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
3681 * needs to be written.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003682 **/
Bruce Allan99730e42011-05-13 07:19:48 +00003683void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003684{
3685 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00003686 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003687
Bruce Allan17f085d2010-06-17 18:59:48 +00003688 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00003689 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allan17f085d2010-06-17 18:59:48 +00003690 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00003691
Bruce Allan462d5992011-09-30 08:07:11 +00003692 if (hw->mac.type == e1000_ich8lan)
3693 e1000e_gig_downshift_workaround_ich8lan(hw);
3694
Bruce Allan8395ae82010-09-22 17:15:08 +00003695 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00003696 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00003697
3698 /* Reset PHY to activate OEM bits on 82577/8 */
3699 if (hw->mac.type == e1000_pchlan)
3700 e1000e_phy_hw_reset_generic(hw);
3701
Bruce Allan8395ae82010-09-22 17:15:08 +00003702 ret_val = hw->phy.ops.acquire(hw);
3703 if (ret_val)
3704 return;
3705 e1000_write_smbus_addr(hw);
3706 hw->phy.ops.release(hw);
3707 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003708}
3709
3710/**
Bruce Allan99730e42011-05-13 07:19:48 +00003711 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
3712 * @hw: pointer to the HW structure
3713 *
3714 * During Sx to S0 transitions on non-managed devices or managed devices
3715 * on which PHY resets are not blocked, if the PHY registers cannot be
3716 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
3717 * the PHY.
3718 **/
3719void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
3720{
Bruce Allan90b82982011-12-16 00:46:33 +00003721 u16 phy_id1, phy_id2;
3722 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00003723
Bruce Allan44abd5c2012-02-22 09:02:37 +00003724 if ((hw->mac.type != e1000_pch2lan) ||
3725 hw->phy.ops.check_reset_block(hw))
Bruce Allan99730e42011-05-13 07:19:48 +00003726 return;
3727
Bruce Allan90b82982011-12-16 00:46:33 +00003728 ret_val = hw->phy.ops.acquire(hw);
3729 if (ret_val) {
3730 e_dbg("Failed to acquire PHY semaphore in resume\n");
Bruce Allan99730e42011-05-13 07:19:48 +00003731 return;
3732 }
3733
Bruce Allan90b82982011-12-16 00:46:33 +00003734 /* Test access to the PHY registers by reading the ID regs */
3735 ret_val = hw->phy.ops.read_reg_locked(hw, PHY_ID1, &phy_id1);
3736 if (ret_val)
3737 goto release;
3738 ret_val = hw->phy.ops.read_reg_locked(hw, PHY_ID2, &phy_id2);
3739 if (ret_val)
3740 goto release;
3741
3742 if (hw->phy.id == ((u32)(phy_id1 << 16) |
3743 (u32)(phy_id2 & PHY_REVISION_MASK)))
3744 goto release;
3745
3746 e1000_toggle_lanphypc_value_ich8lan(hw);
3747
3748 hw->phy.ops.release(hw);
3749 msleep(50);
3750 e1000_phy_hw_reset(hw);
3751 msleep(50);
3752 return;
3753
Bruce Allan99730e42011-05-13 07:19:48 +00003754release:
3755 hw->phy.ops.release(hw);
Bruce Allan99730e42011-05-13 07:19:48 +00003756}
3757
3758/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 * e1000_cleanup_led_ich8lan - Restore the default LED operation
3760 * @hw: pointer to the HW structure
3761 *
3762 * Return the LED back to the default configuration.
3763 **/
3764static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
3765{
3766 if (hw->phy.type == e1000_phy_ife)
3767 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
3768
3769 ew32(LEDCTL, hw->mac.ledctl_default);
3770 return 0;
3771}
3772
3773/**
Auke Kok489815c2008-02-21 15:11:07 -08003774 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07003775 * @hw: pointer to the HW structure
3776 *
Auke Kok489815c2008-02-21 15:11:07 -08003777 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003778 **/
3779static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
3780{
3781 if (hw->phy.type == e1000_phy_ife)
3782 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3783 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
3784
3785 ew32(LEDCTL, hw->mac.ledctl_mode2);
3786 return 0;
3787}
3788
3789/**
Auke Kok489815c2008-02-21 15:11:07 -08003790 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07003791 * @hw: pointer to the HW structure
3792 *
Auke Kok489815c2008-02-21 15:11:07 -08003793 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003794 **/
3795static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
3796{
3797 if (hw->phy.type == e1000_phy_ife)
3798 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00003799 (IFE_PSCL_PROBE_MODE |
3800 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003801
3802 ew32(LEDCTL, hw->mac.ledctl_mode1);
3803 return 0;
3804}
3805
3806/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003807 * e1000_setup_led_pchlan - Configures SW controllable LED
3808 * @hw: pointer to the HW structure
3809 *
3810 * This prepares the SW controllable LED for use.
3811 **/
3812static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
3813{
Bruce Allan482fed82011-01-06 14:29:49 +00003814 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00003815}
3816
3817/**
3818 * e1000_cleanup_led_pchlan - Restore the default LED operation
3819 * @hw: pointer to the HW structure
3820 *
3821 * Return the LED back to the default configuration.
3822 **/
3823static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
3824{
Bruce Allan482fed82011-01-06 14:29:49 +00003825 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00003826}
3827
3828/**
3829 * e1000_led_on_pchlan - Turn LEDs on
3830 * @hw: pointer to the HW structure
3831 *
3832 * Turn on the LEDs.
3833 **/
3834static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
3835{
3836 u16 data = (u16)hw->mac.ledctl_mode2;
3837 u32 i, led;
3838
3839 /*
3840 * If no link, then turn LED on by setting the invert bit
3841 * for each LED that's mode is "link_up" in ledctl_mode2.
3842 */
3843 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3844 for (i = 0; i < 3; i++) {
3845 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3846 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3847 E1000_LEDCTL_MODE_LINK_UP)
3848 continue;
3849 if (led & E1000_PHY_LED0_IVRT)
3850 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3851 else
3852 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3853 }
3854 }
3855
Bruce Allan482fed82011-01-06 14:29:49 +00003856 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003857}
3858
3859/**
3860 * e1000_led_off_pchlan - Turn LEDs off
3861 * @hw: pointer to the HW structure
3862 *
3863 * Turn off the LEDs.
3864 **/
3865static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
3866{
3867 u16 data = (u16)hw->mac.ledctl_mode1;
3868 u32 i, led;
3869
3870 /*
3871 * If no link, then turn LED off by clearing the invert bit
3872 * for each LED that's mode is "link_up" in ledctl_mode1.
3873 */
3874 if (!(er32(STATUS) & E1000_STATUS_LU)) {
3875 for (i = 0; i < 3; i++) {
3876 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3877 if ((led & E1000_PHY_LED0_MODE_MASK) !=
3878 E1000_LEDCTL_MODE_LINK_UP)
3879 continue;
3880 if (led & E1000_PHY_LED0_IVRT)
3881 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3882 else
3883 data |= (E1000_PHY_LED0_IVRT << (i * 5));
3884 }
3885 }
3886
Bruce Allan482fed82011-01-06 14:29:49 +00003887 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00003888}
3889
3890/**
Bruce Allane98cac42010-05-10 15:02:32 +00003891 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07003892 * @hw: pointer to the HW structure
3893 *
Bruce Allane98cac42010-05-10 15:02:32 +00003894 * Read appropriate register for the config done bit for completion status
3895 * and configure the PHY through s/w for EEPROM-less parts.
3896 *
3897 * NOTE: some silicon which is EEPROM-less will fail trying to read the
3898 * config done bit, so only an error is logged and continues. If we were
3899 * to return with error, EEPROM-less silicon would not be able to be reset
3900 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07003901 **/
3902static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
3903{
Bruce Allane98cac42010-05-10 15:02:32 +00003904 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07003905 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00003906 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003907
Bruce Allanf4187b52008-08-26 18:36:50 -07003908 e1000e_get_cfg_done(hw);
3909
Bruce Allane98cac42010-05-10 15:02:32 +00003910 /* Wait for indication from h/w that it has completed basic config */
3911 if (hw->mac.type >= e1000_ich10lan) {
3912 e1000_lan_init_done_ich8lan(hw);
3913 } else {
3914 ret_val = e1000e_get_auto_rd_done(hw);
3915 if (ret_val) {
3916 /*
3917 * When auto config read does not complete, do not
3918 * return with an error. This can happen in situations
3919 * where there is no eeprom and prevents getting link.
3920 */
3921 e_dbg("Auto Read Done did not complete\n");
3922 ret_val = 0;
3923 }
3924 }
3925
3926 /* Clear PHY Reset Asserted bit */
3927 status = er32(STATUS);
3928 if (status & E1000_STATUS_PHYRA)
3929 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
3930 else
3931 e_dbg("PHY Reset Asserted not set - needs delay\n");
3932
Bruce Allanf4187b52008-08-26 18:36:50 -07003933 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00003934 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00003935 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07003936 (hw->phy.type == e1000_phy_igp_3)) {
3937 e1000e_phy_init_script_igp3(hw);
3938 }
3939 } else {
3940 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
3941 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003942 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00003943 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07003944 }
3945 }
3946
Bruce Allane98cac42010-05-10 15:02:32 +00003947 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07003948}
3949
3950/**
Bruce Allan17f208d2009-12-01 15:47:22 +00003951 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
3952 * @hw: pointer to the HW structure
3953 *
3954 * In the case of a PHY power down to save power, or to turn off link during a
3955 * driver unload, or wake on lan is not enabled, remove the link.
3956 **/
3957static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
3958{
3959 /* If the management interface is not enabled, then power down */
3960 if (!(hw->mac.ops.check_mng_mode(hw) ||
3961 hw->phy.ops.check_reset_block(hw)))
3962 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00003963}
3964
3965/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003966 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
3967 * @hw: pointer to the HW structure
3968 *
3969 * Clears hardware counters specific to the silicon family and calls
3970 * clear_hw_cntrs_generic to clear all general purpose counters.
3971 **/
3972static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
3973{
Bruce Allana4f58f52009-06-02 11:29:18 +00003974 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00003975 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003976
3977 e1000e_clear_hw_cntrs_base(hw);
3978
Bruce Allan99673d92009-11-20 23:27:21 +00003979 er32(ALGNERRC);
3980 er32(RXERRC);
3981 er32(TNCRS);
3982 er32(CEXTERR);
3983 er32(TSCTC);
3984 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003985
Bruce Allan99673d92009-11-20 23:27:21 +00003986 er32(MGTPRC);
3987 er32(MGTPDC);
3988 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989
Bruce Allan99673d92009-11-20 23:27:21 +00003990 er32(IAC);
3991 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003992
Bruce Allana4f58f52009-06-02 11:29:18 +00003993 /* Clear PHY statistics registers */
3994 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003995 (hw->phy.type == e1000_phy_82579) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003996 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00003997 ret_val = hw->phy.ops.acquire(hw);
3998 if (ret_val)
3999 return;
4000 ret_val = hw->phy.ops.set_page(hw,
4001 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4002 if (ret_val)
4003 goto release;
4004 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4005 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4006 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4007 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4008 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4009 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4010 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4011 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4012 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4013 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4014 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4015 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4016 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4017 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4018release:
4019 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004020 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004021}
4022
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004023static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004024 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004025 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004026 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004027 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4028 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004029 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004030 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004031 /* led_on dependent on mac type */
4032 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004033 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004034 .reset_hw = e1000_reset_hw_ich8lan,
4035 .init_hw = e1000_init_hw_ich8lan,
4036 .setup_link = e1000_setup_link_ich8lan,
4037 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004038 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004039 .config_collision_dist = e1000e_config_collision_dist_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004040};
4041
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004042static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004043 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004044 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004045 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004046 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004047 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004048 .read_reg = e1000e_read_phy_reg_igp,
4049 .release = e1000_release_swflag_ich8lan,
4050 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004051 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4052 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004053 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004054};
4055
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004056static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004057 .acquire = e1000_acquire_nvm_ich8lan,
4058 .read = e1000_read_nvm_ich8lan,
4059 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004060 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004061 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004062 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004063 .validate = e1000_validate_nvm_checksum_ich8lan,
4064 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004065};
4066
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004067const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004068 .mac = e1000_ich8lan,
4069 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004070 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004071 | FLAG_HAS_CTRLEXT_ON_LOAD
4072 | FLAG_HAS_AMT
4073 | FLAG_HAS_FLASH
4074 | FLAG_APME_IN_WUC,
4075 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004076 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004077 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004078 .mac_ops = &ich8_mac_ops,
4079 .phy_ops = &ich8_phy_ops,
4080 .nvm_ops = &ich8_nvm_ops,
4081};
4082
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004083const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004084 .mac = e1000_ich9lan,
4085 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004086 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004087 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004088 | FLAG_HAS_CTRLEXT_ON_LOAD
4089 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004090 | FLAG_HAS_FLASH
4091 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004092 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004093 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004094 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004095 .mac_ops = &ich8_mac_ops,
4096 .phy_ops = &ich8_phy_ops,
4097 .nvm_ops = &ich8_nvm_ops,
4098};
4099
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004100const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004101 .mac = e1000_ich10lan,
4102 .flags = FLAG_HAS_JUMBO_FRAMES
4103 | FLAG_IS_ICH
4104 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004105 | FLAG_HAS_CTRLEXT_ON_LOAD
4106 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004107 | FLAG_HAS_FLASH
4108 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004109 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004110 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004111 .get_variants = e1000_get_variants_ich8lan,
4112 .mac_ops = &ich8_mac_ops,
4113 .phy_ops = &ich8_phy_ops,
4114 .nvm_ops = &ich8_nvm_ops,
4115};
Bruce Allana4f58f52009-06-02 11:29:18 +00004116
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004117const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004118 .mac = e1000_pchlan,
4119 .flags = FLAG_IS_ICH
4120 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004121 | FLAG_HAS_CTRLEXT_ON_LOAD
4122 | FLAG_HAS_AMT
4123 | FLAG_HAS_FLASH
4124 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004125 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004126 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004127 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004128 .pba = 26,
4129 .max_hw_frame_size = 4096,
4130 .get_variants = e1000_get_variants_ich8lan,
4131 .mac_ops = &ich8_mac_ops,
4132 .phy_ops = &ich8_phy_ops,
4133 .nvm_ops = &ich8_nvm_ops,
4134};
Bruce Alland3738bb2010-06-16 13:27:28 +00004135
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004136const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004137 .mac = e1000_pch2lan,
4138 .flags = FLAG_IS_ICH
4139 | FLAG_HAS_WOL
Bruce Alland3738bb2010-06-16 13:27:28 +00004140 | FLAG_HAS_CTRLEXT_ON_LOAD
4141 | FLAG_HAS_AMT
4142 | FLAG_HAS_FLASH
4143 | FLAG_HAS_JUMBO_FRAMES
4144 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004145 .flags2 = FLAG2_HAS_PHY_STATS
4146 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004147 .pba = 26,
Bruce Alland3738bb2010-06-16 13:27:28 +00004148 .max_hw_frame_size = DEFAULT_JUMBO,
4149 .get_variants = e1000_get_variants_ich8lan,
4150 .mac_ops = &ich8_mac_ops,
4151 .phy_ops = &ich8_phy_ops,
4152 .nvm_ops = &ich8_nvm_ops,
4153};