blob: 3f3477ffd46cc9e1626f9746d933642a71a06773 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 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
Bruce Allane921eb12012-11-28 09:28:37 +000029/* 82562G 10/100 Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070030 * 82562G-2 10/100 Network Connection
31 * 82562GT 10/100 Network Connection
32 * 82562GT-2 10/100 Network Connection
33 * 82562V 10/100 Network Connection
34 * 82562V-2 10/100 Network Connection
35 * 82566DC-2 Gigabit Network Connection
36 * 82566DC Gigabit Network Connection
37 * 82566DM-2 Gigabit Network Connection
38 * 82566DM Gigabit Network Connection
39 * 82566MC Gigabit Network Connection
40 * 82566MM Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070041 * 82567LM Gigabit Network Connection
42 * 82567LF Gigabit Network Connection
Bruce Allan16059272008-11-21 16:51:06 -080043 * 82567V Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070044 * 82567LM-2 Gigabit Network Connection
45 * 82567LF-2 Gigabit Network Connection
46 * 82567V-2 Gigabit Network Connection
Bruce Allanf4187b52008-08-26 18:36:50 -070047 * 82567LF-3 Gigabit Network Connection
48 * 82567LM-3 Gigabit Network Connection
Bruce Allan2f15f9d2008-08-26 18:36:36 -070049 * 82567LM-4 Gigabit Network Connection
Bruce Allana4f58f52009-06-02 11:29:18 +000050 * 82577LM Gigabit Network Connection
51 * 82577LC Gigabit Network Connection
52 * 82578DM Gigabit Network Connection
53 * 82578DC Gigabit Network Connection
Bruce Alland3738bb2010-06-16 13:27:28 +000054 * 82579LM Gigabit Network Connection
55 * 82579V Gigabit Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070056 */
57
Auke Kokbc7f75f2007-09-17 12:30:59 -070058#include "e1000.h"
59
60#define ICH_FLASH_GFPREG 0x0000
61#define ICH_FLASH_HSFSTS 0x0004
62#define ICH_FLASH_HSFCTL 0x0006
63#define ICH_FLASH_FADDR 0x0008
64#define ICH_FLASH_FDATA0 0x0010
Bruce Allan4a770352008-10-01 17:18:35 -070065#define ICH_FLASH_PR0 0x0074
Auke Kokbc7f75f2007-09-17 12:30:59 -070066
67#define ICH_FLASH_READ_COMMAND_TIMEOUT 500
68#define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
69#define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
70#define ICH_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
71#define ICH_FLASH_CYCLE_REPEAT_COUNT 10
72
73#define ICH_CYCLE_READ 0
74#define ICH_CYCLE_WRITE 2
75#define ICH_CYCLE_ERASE 3
76
77#define FLASH_GFPREG_BASE_MASK 0x1FFF
78#define FLASH_SECTOR_ADDR_SHIFT 12
79
80#define ICH_FLASH_SEG_SIZE_256 256
81#define ICH_FLASH_SEG_SIZE_4K 4096
82#define ICH_FLASH_SEG_SIZE_8K 8192
83#define ICH_FLASH_SEG_SIZE_64K 65536
84
85
86#define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
Bruce Allan6dfaa762010-05-05 22:00:06 +000087/* FW established a valid mode */
88#define E1000_ICH_FWSM_FW_VALID 0x00008000
Auke Kokbc7f75f2007-09-17 12:30:59 -070089
90#define E1000_ICH_MNG_IAMT_MODE 0x2
91
92#define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
93 (ID_LED_DEF1_OFF2 << 8) | \
94 (ID_LED_DEF1_ON2 << 4) | \
95 (ID_LED_DEF1_DEF2))
96
97#define E1000_ICH_NVM_SIG_WORD 0x13
98#define E1000_ICH_NVM_SIG_MASK 0xC000
Bruce Allane2434552008-11-21 17:02:41 -080099#define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
100#define E1000_ICH_NVM_SIG_VALUE 0x80
Auke Kokbc7f75f2007-09-17 12:30:59 -0700101
102#define E1000_ICH8_LAN_INIT_TIMEOUT 1500
103
104#define E1000_FEXTNVM_SW_CONFIG 1
105#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
106
Bruce Allan62bc8132012-03-20 03:47:57 +0000107#define E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK 0x0C000000
108#define E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC 0x08000000
109
Bruce Allan831bd2e2010-09-22 17:16:18 +0000110#define E1000_FEXTNVM4_BEACON_DURATION_MASK 0x7
111#define E1000_FEXTNVM4_BEACON_DURATION_8USEC 0x7
112#define E1000_FEXTNVM4_BEACON_DURATION_16USEC 0x3
113
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
115
116#define E1000_ICH_RAR_ENTRIES 7
Bruce Allan69e1e012012-04-14 03:28:50 +0000117#define E1000_PCH2_RAR_ENTRIES 5 /* RAR[0], SHRA[0-3] */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000118#define E1000_PCH_LPT_RAR_ENTRIES 12 /* RAR[0], SHRA[0-10] */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700119
120#define PHY_PAGE_SHIFT 5
121#define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
122 ((reg) & MAX_PHY_REG_ADDRESS))
123#define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
124#define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
125
126#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
127#define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
128#define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
129
Bruce Allana4f58f52009-06-02 11:29:18 +0000130#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
131
Bruce Allan53ac5a82009-10-26 11:23:06 +0000132#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
133
Bruce Allan2fbe4522012-04-19 03:21:47 +0000134/* SMBus Control Phy Register */
135#define CV_SMB_CTRL PHY_REG(769, 23)
136#define CV_SMB_CTRL_FORCE_SMBUS 0x0001
137
Bruce Allanf523d212009-10-29 13:45:45 +0000138/* SMBus Address Phy Register */
139#define HV_SMB_ADDR PHY_REG(768, 26)
Bruce Allan8395ae82010-09-22 17:15:08 +0000140#define HV_SMB_ADDR_MASK 0x007F
Bruce Allanf523d212009-10-29 13:45:45 +0000141#define HV_SMB_ADDR_PEC_EN 0x0200
142#define HV_SMB_ADDR_VALID 0x0080
Bruce Allan2fbe4522012-04-19 03:21:47 +0000143#define HV_SMB_ADDR_FREQ_MASK 0x1100
144#define HV_SMB_ADDR_FREQ_LOW_SHIFT 8
145#define HV_SMB_ADDR_FREQ_HIGH_SHIFT 12
Bruce Allanf523d212009-10-29 13:45:45 +0000146
Bruce Alland3738bb2010-06-16 13:27:28 +0000147/* PHY Power Management Control */
148#define HV_PM_CTRL PHY_REG(770, 17)
Bruce Allan36ceeb42012-03-20 03:47:47 +0000149#define HV_PM_CTRL_PLL_STOP_IN_K1_GIGA 0x100
Bruce Alland3738bb2010-06-16 13:27:28 +0000150
Bruce Allan2fbe4522012-04-19 03:21:47 +0000151/* Intel Rapid Start Technology Support */
Bruce Allan6d7407b2012-05-10 02:51:17 +0000152#define I217_PROXY_CTRL BM_PHY_REG(BM_WUC_PAGE, 70)
Bruce Allan2fbe4522012-04-19 03:21:47 +0000153#define I217_PROXY_CTRL_AUTO_DISABLE 0x0080
154#define I217_SxCTRL PHY_REG(BM_PORT_CTRL_PAGE, 28)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000155#define I217_SxCTRL_ENABLE_LPI_RESET 0x1000
Bruce Allan2fbe4522012-04-19 03:21:47 +0000156#define I217_CGFREG PHY_REG(772, 29)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000157#define I217_CGFREG_ENABLE_MTA_RESET 0x0002
Bruce Allan2fbe4522012-04-19 03:21:47 +0000158#define I217_MEMPWR PHY_REG(772, 26)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000159#define I217_MEMPWR_DISABLE_SMB_RELEASE 0x0010
Bruce Allan1effb452011-02-25 06:58:03 +0000160
Bruce Allanf523d212009-10-29 13:45:45 +0000161/* Strapping Option Register - RO */
162#define E1000_STRAP 0x0000C
163#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
164#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
Bruce Allan2fbe4522012-04-19 03:21:47 +0000165#define E1000_STRAP_SMT_FREQ_MASK 0x00003000
166#define E1000_STRAP_SMT_FREQ_SHIFT 12
Bruce Allanf523d212009-10-29 13:45:45 +0000167
Bruce Allanfa2ce132009-10-26 11:23:25 +0000168/* OEM Bits Phy Register */
169#define HV_OEM_BITS PHY_REG(768, 25)
170#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
Bruce Allanf523d212009-10-29 13:45:45 +0000171#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
Bruce Allanfa2ce132009-10-26 11:23:25 +0000172#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
173
Bruce Allan1d5846b2009-10-29 13:46:05 +0000174#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
175#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
176
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000177/* KMRN Mode Control */
178#define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
179#define HV_KMRN_MDIO_SLOW 0x0400
180
Bruce Allan1d2101a72011-07-22 06:21:56 +0000181/* KMRN FIFO Control and Status */
182#define HV_KMRN_FIFO_CTRLSTA PHY_REG(770, 16)
183#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK 0x7000
184#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT 12
185
Auke Kokbc7f75f2007-09-17 12:30:59 -0700186/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
187/* Offset 04h HSFSTS */
188union ich8_hws_flash_status {
189 struct ich8_hsfsts {
190 u16 flcdone :1; /* bit 0 Flash Cycle Done */
191 u16 flcerr :1; /* bit 1 Flash Cycle Error */
192 u16 dael :1; /* bit 2 Direct Access error Log */
193 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
194 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
195 u16 reserved1 :2; /* bit 13:6 Reserved */
196 u16 reserved2 :6; /* bit 13:6 Reserved */
197 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
198 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
199 } hsf_status;
200 u16 regval;
201};
202
203/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
204/* Offset 06h FLCTL */
205union ich8_hws_flash_ctrl {
206 struct ich8_hsflctl {
207 u16 flcgo :1; /* 0 Flash Cycle Go */
208 u16 flcycle :2; /* 2:1 Flash Cycle */
209 u16 reserved :5; /* 7:3 Reserved */
210 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
211 u16 flockdn :6; /* 15:10 Reserved */
212 } hsf_ctrl;
213 u16 regval;
214};
215
216/* ICH Flash Region Access Permissions */
217union ich8_hws_flash_regacc {
218 struct ich8_flracc {
219 u32 grra :8; /* 0:7 GbE region Read Access */
220 u32 grwa :8; /* 8:15 GbE region Write Access */
221 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
222 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
223 } hsf_flregacc;
224 u16 regval;
225};
226
Bruce Allan4a770352008-10-01 17:18:35 -0700227/* ICH Flash Protected Region */
228union ich8_flash_protected_range {
229 struct ich8_pr {
230 u32 base:13; /* 0:12 Protected Range Base */
231 u32 reserved1:2; /* 13:14 Reserved */
232 u32 rpe:1; /* 15 Read Protection Enable */
233 u32 limit:13; /* 16:28 Protected Range Limit */
234 u32 reserved2:2; /* 29:30 Reserved */
235 u32 wpe:1; /* 31 Write Protection Enable */
236 } range;
237 u32 regval;
238};
239
Auke Kokbc7f75f2007-09-17 12:30:59 -0700240static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
241static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
242static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700243static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
244static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
245 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700246static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
247 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700248static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
249 u16 *data);
250static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
251 u8 size, u16 *data);
252static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
253static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700254static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000255static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
256static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
257static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
258static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
259static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
260static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
261static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
262static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000263static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000264static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000265static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000266static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000267static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000268static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
269static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan69e1e012012-04-14 03:28:50 +0000270static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000271static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000272static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000273static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700274
275static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
276{
277 return readw(hw->flash_address + reg);
278}
279
280static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
281{
282 return readl(hw->flash_address + reg);
283}
284
285static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
286{
287 writew(val, hw->flash_address + reg);
288}
289
290static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
291{
292 writel(val, hw->flash_address + reg);
293}
294
295#define er16flash(reg) __er16flash(hw, (reg))
296#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000297#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
298#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700299
Bruce Allancb17aab2012-04-13 03:16:22 +0000300/**
301 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
302 * @hw: pointer to the HW structure
303 *
304 * Test access to the PHY registers by reading the PHY ID registers. If
305 * the PHY ID is already known (e.g. resume path) compare it with known ID,
306 * otherwise assume the read PHY ID is correct if it is valid.
307 *
308 * Assumes the sw/fw/hw semaphore is already acquired.
309 **/
310static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000311{
Bruce Allana52359b2012-07-14 04:23:58 +0000312 u16 phy_reg = 0;
313 u32 phy_id = 0;
314 s32 ret_val;
315 u16 retry_count;
Bruce Allan99730e42011-05-13 07:19:48 +0000316
Bruce Allana52359b2012-07-14 04:23:58 +0000317 for (retry_count = 0; retry_count < 2; retry_count++) {
318 ret_val = e1e_rphy_locked(hw, PHY_ID1, &phy_reg);
319 if (ret_val || (phy_reg == 0xFFFF))
320 continue;
321 phy_id = (u32)(phy_reg << 16);
322
323 ret_val = e1e_rphy_locked(hw, PHY_ID2, &phy_reg);
324 if (ret_val || (phy_reg == 0xFFFF)) {
325 phy_id = 0;
326 continue;
327 }
328 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
329 break;
330 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000331
Bruce Allancb17aab2012-04-13 03:16:22 +0000332 if (hw->phy.id) {
333 if (hw->phy.id == phy_id)
334 return true;
Bruce Allana52359b2012-07-14 04:23:58 +0000335 } else if (phy_id) {
336 hw->phy.id = phy_id;
337 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allancb17aab2012-04-13 03:16:22 +0000338 return true;
339 }
340
Bruce Allane921eb12012-11-28 09:28:37 +0000341 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000342 * set slow mode and try to get the PHY id again.
343 */
344 hw->phy.ops.release(hw);
345 ret_val = e1000_set_mdio_slow_mode_hv(hw);
346 if (!ret_val)
347 ret_val = e1000e_get_phy_id(hw);
348 hw->phy.ops.acquire(hw);
349
350 return !ret_val;
Bruce Allancb17aab2012-04-13 03:16:22 +0000351}
352
353/**
354 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
355 * @hw: pointer to the HW structure
356 *
357 * Workarounds/flow necessary for PHY initialization during driver load
358 * and resume paths.
359 **/
360static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
361{
362 u32 mac_reg, fwsm = er32(FWSM);
363 s32 ret_val;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000364 u16 phy_reg;
Bruce Allancb17aab2012-04-13 03:16:22 +0000365
Bruce Allan6e928b72012-12-12 04:45:51 +0000366 /* Gate automatic PHY configuration by hardware on managed and
367 * non-managed 82579 and newer adapters.
368 */
369 e1000_gate_hw_phy_config_ich8lan(hw, true);
370
Bruce Allancb17aab2012-04-13 03:16:22 +0000371 ret_val = hw->phy.ops.acquire(hw);
372 if (ret_val) {
373 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000374 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000375 }
376
Bruce Allane921eb12012-11-28 09:28:37 +0000377 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000378 * inaccessible and resetting the PHY is not blocked, toggle the
379 * LANPHYPC Value bit to force the interconnect to PCIe mode.
380 */
381 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000382 case e1000_pch_lpt:
383 if (e1000_phy_is_accessible_pchlan(hw))
384 break;
385
Bruce Allane921eb12012-11-28 09:28:37 +0000386 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000387 * forcing MAC to SMBus mode first.
388 */
389 mac_reg = er32(CTRL_EXT);
390 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
391 ew32(CTRL_EXT, mac_reg);
392
393 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000394 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000395 if (e1000_phy_is_accessible_pchlan(hw)) {
396 if (hw->mac.type == e1000_pch_lpt) {
397 /* Unforce SMBus mode in PHY */
398 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
399 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
400 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
401
402 /* Unforce SMBus mode in MAC */
403 mac_reg = er32(CTRL_EXT);
404 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
405 ew32(CTRL_EXT, mac_reg);
406 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000407 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000408 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000409
410 /* fall-through */
411 case e1000_pchlan:
412 if ((hw->mac.type == e1000_pchlan) &&
413 (fwsm & E1000_ICH_FWSM_FW_VALID))
414 break;
415
416 if (hw->phy.ops.check_reset_block(hw)) {
417 e_dbg("Required LANPHYPC toggle blocked by ME\n");
418 break;
419 }
420
421 e_dbg("Toggling LANPHYPC\n");
422
423 /* Set Phy Config Counter to 50msec */
424 mac_reg = er32(FEXTNVM3);
425 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
426 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
427 ew32(FEXTNVM3, mac_reg);
428
Bruce Allan4e035102013-01-04 09:53:19 +0000429 if (hw->mac.type == e1000_pch_lpt) {
430 /* Toggling LANPHYPC brings the PHY out of SMBus mode
431 * So ensure that the MAC is also out of SMBus mode
432 */
433 mac_reg = er32(CTRL_EXT);
434 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
435 ew32(CTRL_EXT, mac_reg);
436 }
437
Bruce Allancb17aab2012-04-13 03:16:22 +0000438 /* Toggle LANPHYPC Value bit */
439 mac_reg = er32(CTRL);
440 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
441 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
442 ew32(CTRL, mac_reg);
443 e1e_flush();
444 udelay(10);
445 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
446 ew32(CTRL, mac_reg);
447 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000448 if (hw->mac.type < e1000_pch_lpt) {
449 msleep(50);
450 } else {
451 u16 count = 20;
452 do {
453 usleep_range(5000, 10000);
454 } while (!(er32(CTRL_EXT) &
455 E1000_CTRL_EXT_LPCD) && count--);
456 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000457 break;
458 default:
459 break;
460 }
461
462 hw->phy.ops.release(hw);
463
Bruce Allane921eb12012-11-28 09:28:37 +0000464 /* Reset the PHY before any access to it. Doing so, ensures
Bruce Allancb17aab2012-04-13 03:16:22 +0000465 * that the PHY is in a known good state before we read/write
466 * PHY registers. The generic reset is sufficient here,
467 * because we haven't determined the PHY type yet.
468 */
469 ret_val = e1000e_phy_hw_reset_generic(hw);
470
Bruce Allan6e928b72012-12-12 04:45:51 +0000471out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000472 /* Ungate automatic PHY configuration on non-managed 82579 */
473 if ((hw->mac.type == e1000_pch2lan) &&
474 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
475 usleep_range(10000, 20000);
476 e1000_gate_hw_phy_config_ich8lan(hw, false);
477 }
478
479 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000480}
481
Auke Kokbc7f75f2007-09-17 12:30:59 -0700482/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000483 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
484 * @hw: pointer to the HW structure
485 *
486 * Initialize family-specific PHY parameters and function pointers.
487 **/
488static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
489{
490 struct e1000_phy_info *phy = &hw->phy;
491 s32 ret_val = 0;
492
493 phy->addr = 1;
494 phy->reset_delay_us = 100;
495
Bruce Allan2b6b1682011-05-13 07:20:09 +0000496 phy->ops.set_page = e1000_set_page_igp;
Bruce Allan94d81862009-11-20 23:25:26 +0000497 phy->ops.read_reg = e1000_read_phy_reg_hv;
498 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000499 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000500 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
501 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000502 phy->ops.write_reg = e1000_write_phy_reg_hv;
503 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000504 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
Bruce Allan17f208d2009-12-01 15:47:22 +0000505 phy->ops.power_up = e1000_power_up_phy_copper;
506 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000507 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
508
509 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000510
511 ret_val = e1000_init_phy_workarounds_pchlan(hw);
512 if (ret_val)
513 return ret_val;
514
515 if (phy->id == e1000_phy_unknown)
516 switch (hw->mac.type) {
517 default:
518 ret_val = e1000e_get_phy_id(hw);
519 if (ret_val)
520 return ret_val;
521 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
522 break;
523 /* fall-through */
524 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000525 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000526 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000527 * set slow mode and try to get the PHY id again.
528 */
529 ret_val = e1000_set_mdio_slow_mode_hv(hw);
530 if (ret_val)
531 return ret_val;
532 ret_val = e1000e_get_phy_id(hw);
533 if (ret_val)
534 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000535 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000536 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000537 phy->type = e1000e_get_phy_type_from_id(phy->id);
538
Bruce Allan0be84012009-12-02 17:03:18 +0000539 switch (phy->type) {
540 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000541 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000542 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000543 phy->ops.check_polarity = e1000_check_polarity_82577;
544 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000545 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000546 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000547 phy->ops.get_info = e1000_get_phy_info_82577;
548 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000549 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000550 case e1000_phy_82578:
551 phy->ops.check_polarity = e1000_check_polarity_m88;
552 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
553 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
554 phy->ops.get_info = e1000e_get_phy_info_m88;
555 break;
556 default:
557 ret_val = -E1000_ERR_PHY;
558 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000559 }
560
561 return ret_val;
562}
563
564/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700565 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
566 * @hw: pointer to the HW structure
567 *
568 * Initialize family-specific PHY parameters and function pointers.
569 **/
570static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
571{
572 struct e1000_phy_info *phy = &hw->phy;
573 s32 ret_val;
574 u16 i = 0;
575
576 phy->addr = 1;
577 phy->reset_delay_us = 100;
578
Bruce Allan17f208d2009-12-01 15:47:22 +0000579 phy->ops.power_up = e1000_power_up_phy_copper;
580 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
581
Bruce Allane921eb12012-11-28 09:28:37 +0000582 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700583 * we'll set BM func pointers and try again
584 */
585 ret_val = e1000e_determine_phy_address(hw);
586 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000587 phy->ops.write_reg = e1000e_write_phy_reg_bm;
588 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700589 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000590 if (ret_val) {
591 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700592 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000593 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700594 }
595
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596 phy->id = 0;
597 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
598 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000599 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700600 ret_val = e1000e_get_phy_id(hw);
601 if (ret_val)
602 return ret_val;
603 }
604
605 /* Verify phy id */
606 switch (phy->id) {
607 case IGP03E1000_E_PHY_ID:
608 phy->type = e1000_phy_igp_3;
609 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000610 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
611 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000612 phy->ops.get_info = e1000e_get_phy_info_igp;
613 phy->ops.check_polarity = e1000_check_polarity_igp;
614 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700615 break;
616 case IFE_E_PHY_ID:
617 case IFE_PLUS_E_PHY_ID:
618 case IFE_C_E_PHY_ID:
619 phy->type = e1000_phy_ife;
620 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000621 phy->ops.get_info = e1000_get_phy_info_ife;
622 phy->ops.check_polarity = e1000_check_polarity_ife;
623 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700624 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700625 case BME1000_E_PHY_ID:
626 phy->type = e1000_phy_bm;
627 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000628 phy->ops.read_reg = e1000e_read_phy_reg_bm;
629 phy->ops.write_reg = e1000e_write_phy_reg_bm;
630 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000631 phy->ops.get_info = e1000e_get_phy_info_m88;
632 phy->ops.check_polarity = e1000_check_polarity_m88;
633 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700634 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700635 default:
636 return -E1000_ERR_PHY;
637 break;
638 }
639
640 return 0;
641}
642
643/**
644 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
645 * @hw: pointer to the HW structure
646 *
647 * Initialize family-specific NVM parameters and function
648 * pointers.
649 **/
650static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
651{
652 struct e1000_nvm_info *nvm = &hw->nvm;
653 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000654 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700655 u16 i;
656
Bruce Allanad680762008-03-28 09:15:03 -0700657 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700658 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000659 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660 return -E1000_ERR_CONFIG;
661 }
662
663 nvm->type = e1000_nvm_flash_sw;
664
665 gfpreg = er32flash(ICH_FLASH_GFPREG);
666
Bruce Allane921eb12012-11-28 09:28:37 +0000667 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700668 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700669 * the overall size.
670 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700671 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
672 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
673
674 /* flash_base_addr is byte-aligned */
675 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
676
Bruce Allane921eb12012-11-28 09:28:37 +0000677 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700678 * size represents two separate NVM banks.
679 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700680 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
681 << FLASH_SECTOR_ADDR_SHIFT;
682 nvm->flash_bank_size /= 2;
683 /* Adjust to word count */
684 nvm->flash_bank_size /= sizeof(u16);
685
686 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
687
688 /* Clear shadow ram */
689 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000690 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700691 dev_spec->shadow_ram[i].value = 0xFFFF;
692 }
693
694 return 0;
695}
696
697/**
698 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
699 * @hw: pointer to the HW structure
700 *
701 * Initialize family-specific MAC parameters and function
702 * pointers.
703 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000704static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700706 struct e1000_mac_info *mac = &hw->mac;
707
708 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700709 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700710
711 /* Set mta register count */
712 mac->mta_reg_count = 32;
713 /* Set rar entry count */
714 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
715 if (mac->type == e1000_ich8lan)
716 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000717 /* FWSM register */
718 mac->has_fwsm = true;
719 /* ARC subsystem not supported */
720 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000721 /* Adaptive IFS supported */
722 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700723
Bruce Allan2fbe4522012-04-19 03:21:47 +0000724 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000725 switch (mac->type) {
726 case e1000_ich8lan:
727 case e1000_ich9lan:
728 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000729 /* check management mode */
730 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000731 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000732 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000733 /* blink LED */
734 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000735 /* setup LED */
736 mac->ops.setup_led = e1000e_setup_led_generic;
737 /* cleanup LED */
738 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
739 /* turn on/off LED */
740 mac->ops.led_on = e1000_led_on_ich8lan;
741 mac->ops.led_off = e1000_led_off_ich8lan;
742 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000743 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000744 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
745 mac->ops.rar_set = e1000_rar_set_pch2lan;
746 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000747 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000748 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000749 /* check management mode */
750 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000751 /* ID LED init */
752 mac->ops.id_led_init = e1000_id_led_init_pchlan;
753 /* setup LED */
754 mac->ops.setup_led = e1000_setup_led_pchlan;
755 /* cleanup LED */
756 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
757 /* turn on/off LED */
758 mac->ops.led_on = e1000_led_on_pchlan;
759 mac->ops.led_off = e1000_led_off_pchlan;
760 break;
761 default:
762 break;
763 }
764
Bruce Allan2fbe4522012-04-19 03:21:47 +0000765 if (mac->type == e1000_pch_lpt) {
766 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
767 mac->ops.rar_set = e1000_rar_set_pch_lpt;
768 }
769
Auke Kokbc7f75f2007-09-17 12:30:59 -0700770 /* Enable PCS Lock-loss workaround for ICH8 */
771 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000772 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700773
774 return 0;
775}
776
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000777/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000778 * __e1000_access_emi_reg_locked - Read/write EMI register
779 * @hw: pointer to the HW structure
780 * @addr: EMI address to program
781 * @data: pointer to value to read/write from/to the EMI address
782 * @read: boolean flag to indicate read or write
783 *
784 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
785 **/
786static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
787 u16 *data, bool read)
788{
789 s32 ret_val = 0;
790
791 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
792 if (ret_val)
793 return ret_val;
794
795 if (read)
796 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
797 else
798 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
799
800 return ret_val;
801}
802
803/**
804 * e1000_read_emi_reg_locked - Read Extended Management Interface register
805 * @hw: pointer to the HW structure
806 * @addr: EMI address to program
807 * @data: value to be read from the EMI address
808 *
809 * Assumes the SW/FW/HW Semaphore is already acquired.
810 **/
Bruce Allan203e4152012-12-05 08:40:59 +0000811s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000812{
813 return __e1000_access_emi_reg_locked(hw, addr, data, true);
814}
815
816/**
817 * e1000_write_emi_reg_locked - Write Extended Management Interface register
818 * @hw: pointer to the HW structure
819 * @addr: EMI address to program
820 * @data: value to be written to the EMI address
821 *
822 * Assumes the SW/FW/HW Semaphore is already acquired.
823 **/
824static s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
825{
826 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
827}
828
829/**
Bruce Allane52997f2010-06-16 13:27:49 +0000830 * e1000_set_eee_pchlan - Enable/disable EEE support
831 * @hw: pointer to the HW structure
832 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000833 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
834 * the link and the EEE capabilities of the link partner. The LPI Control
835 * register bits will remain set only if/when link is up.
Bruce Allane52997f2010-06-16 13:27:49 +0000836 **/
837static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
838{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000839 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000840 s32 ret_val;
841 u16 lpi_ctrl;
Bruce Allane52997f2010-06-16 13:27:49 +0000842
Bruce Allan2fbe4522012-04-19 03:21:47 +0000843 if ((hw->phy.type != e1000_phy_82579) &&
844 (hw->phy.type != e1000_phy_i217))
Bruce Allan5015e532012-02-08 02:55:56 +0000845 return 0;
Bruce Allane52997f2010-06-16 13:27:49 +0000846
Bruce Allan3d4d5752012-12-05 06:26:08 +0000847 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000848 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000849 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000850
Bruce Allan3d4d5752012-12-05 06:26:08 +0000851 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000852 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000853 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000854
Bruce Allan3d4d5752012-12-05 06:26:08 +0000855 /* Clear bits that enable EEE in various speeds */
856 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
857
858 /* Enable EEE if not disabled by user */
859 if (!dev_spec->eee_disable) {
860 u16 lpa, pcs_status, data;
861
Bruce Allan2fbe4522012-04-19 03:21:47 +0000862 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000863 switch (hw->phy.type) {
864 case e1000_phy_82579:
865 lpa = I82579_EEE_LP_ABILITY;
866 pcs_status = I82579_EEE_PCS_STATUS;
867 break;
868 case e1000_phy_i217:
869 lpa = I217_EEE_LP_ABILITY;
870 pcs_status = I217_EEE_PCS_STATUS;
871 break;
872 default:
873 ret_val = -E1000_ERR_PHY;
874 goto release;
875 }
876 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000877 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000878 if (ret_val)
879 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000880
Bruce Allan3d4d5752012-12-05 06:26:08 +0000881 /* Enable EEE only for speeds in which the link partner is
882 * EEE capable.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000883 */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000884 if (dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
885 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
886
887 if (dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
888 e1e_rphy_locked(hw, PHY_LP_ABILITY, &data);
889 if (data & NWAY_LPAR_100TX_FD_CAPS)
890 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
891 else
892 /* EEE is not supported in 100Half, so ignore
893 * partner's EEE in 100 ability if full-duplex
894 * is not advertised.
895 */
896 dev_spec->eee_lp_ability &=
897 ~I82579_EEE_100_SUPPORTED;
898 }
899
900 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
901 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
902 if (ret_val)
903 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000904 }
905
Bruce Allan3d4d5752012-12-05 06:26:08 +0000906 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
907release:
908 hw->phy.ops.release(hw);
909
910 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000911}
912
913/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000914 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
915 * @hw: pointer to the HW structure
916 *
917 * Checks to see of the link status of the hardware has changed. If a
918 * change in link status has been detected, then we read the PHY registers
919 * to get the current speed/duplex if link exists.
920 **/
921static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
922{
923 struct e1000_mac_info *mac = &hw->mac;
924 s32 ret_val;
925 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000926 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000927
Bruce Allane921eb12012-11-28 09:28:37 +0000928 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000929 * has completed and/or if our link status has changed. The
930 * get_link_status flag is set upon receiving a Link Status
931 * Change or Rx Sequence Error interrupt.
932 */
Bruce Allan5015e532012-02-08 02:55:56 +0000933 if (!mac->get_link_status)
934 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000935
Bruce Allane921eb12012-11-28 09:28:37 +0000936 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000937 * link. If so, then we want to get the current speed/duplex
938 * of the PHY.
939 */
940 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
941 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000942 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000943
Bruce Allan1d5846b2009-10-29 13:46:05 +0000944 if (hw->mac.type == e1000_pchlan) {
945 ret_val = e1000_k1_gig_workaround_hv(hw, link);
946 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000947 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +0000948 }
949
Bruce Allan2fbe4522012-04-19 03:21:47 +0000950 /* Clear link partner's EEE ability */
951 hw->dev_spec.ich8lan.eee_lp_ability = 0;
952
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000953 if (!link)
Bruce Allan5015e532012-02-08 02:55:56 +0000954 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000955
956 mac->get_link_status = false;
957
Bruce Allan1d2101a72011-07-22 06:21:56 +0000958 switch (hw->mac.type) {
959 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +0000960 ret_val = e1000_k1_workaround_lv(hw);
961 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000962 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000963 /* fall-thru */
964 case e1000_pchlan:
965 if (hw->phy.type == e1000_phy_82578) {
966 ret_val = e1000_link_stall_workaround_hv(hw);
967 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000968 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000969 }
970
Bruce Allane921eb12012-11-28 09:28:37 +0000971 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +0000972 * Set the number of preambles removed from the packet
973 * when it is passed from the PHY to the MAC to prevent
974 * the MAC from misinterpreting the packet type.
975 */
976 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
977 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
978
979 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
980 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
981
982 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
983 break;
984 default:
985 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +0000986 }
987
Bruce Allane921eb12012-11-28 09:28:37 +0000988 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000989 * immediately after link-up
990 */
991 e1000e_check_downshift(hw);
992
Bruce Allane52997f2010-06-16 13:27:49 +0000993 /* Enable/Disable EEE after link up */
994 ret_val = e1000_set_eee_pchlan(hw);
995 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000996 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000997
Bruce Allane921eb12012-11-28 09:28:37 +0000998 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000999 * we have already determined whether we have link or not.
1000 */
Bruce Allan5015e532012-02-08 02:55:56 +00001001 if (!mac->autoneg)
1002 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001003
Bruce Allane921eb12012-11-28 09:28:37 +00001004 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001005 * of MAC speed/duplex configuration. So we only need to
1006 * configure Collision Distance in the MAC.
1007 */
Bruce Allan57cde762012-02-22 09:02:58 +00001008 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001009
Bruce Allane921eb12012-11-28 09:28:37 +00001010 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001011 * First, we need to restore the desired flow control
1012 * settings because we may have had to re-autoneg with a
1013 * different link partner.
1014 */
1015 ret_val = e1000e_config_fc_after_link_up(hw);
1016 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001017 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001018
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001019 return ret_val;
1020}
1021
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001022static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023{
1024 struct e1000_hw *hw = &adapter->hw;
1025 s32 rc;
1026
Bruce Allanec34c172012-02-01 10:53:05 +00001027 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001028 if (rc)
1029 return rc;
1030
1031 rc = e1000_init_nvm_params_ich8lan(hw);
1032 if (rc)
1033 return rc;
1034
Bruce Alland3738bb2010-06-16 13:27:28 +00001035 switch (hw->mac.type) {
1036 case e1000_ich8lan:
1037 case e1000_ich9lan:
1038 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001039 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001040 break;
1041 case e1000_pchlan:
1042 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001043 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001044 rc = e1000_init_phy_params_pchlan(hw);
1045 break;
1046 default:
1047 break;
1048 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049 if (rc)
1050 return rc;
1051
Bruce Allane921eb12012-11-28 09:28:37 +00001052 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001053 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1054 */
1055 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1056 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1057 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001058 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1059 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001060
1061 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001062 }
1063
Auke Kokbc7f75f2007-09-17 12:30:59 -07001064 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001065 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001066 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1067
Bruce Allanc6e7f512011-07-29 05:53:02 +00001068 /* Enable workaround for 82579 w/ ME enabled */
1069 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1070 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1071 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1072
Bruce Allan5a86f282010-06-29 18:13:13 +00001073 /* Disable EEE by default until IEEE802.3az spec is finalized */
1074 if (adapter->flags2 & FLAG2_HAS_EEE)
1075 adapter->hw.dev_spec.ich8lan.eee_disable = true;
1076
Auke Kokbc7f75f2007-09-17 12:30:59 -07001077 return 0;
1078}
1079
Thomas Gleixner717d4382008-10-02 16:33:40 -07001080static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001081
Auke Kokbc7f75f2007-09-17 12:30:59 -07001082/**
Bruce Allanca15df52009-10-26 11:23:43 +00001083 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1084 * @hw: pointer to the HW structure
1085 *
1086 * Acquires the mutex for performing NVM operations.
1087 **/
1088static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
1089{
1090 mutex_lock(&nvm_mutex);
1091
1092 return 0;
1093}
1094
1095/**
1096 * e1000_release_nvm_ich8lan - Release NVM mutex
1097 * @hw: pointer to the HW structure
1098 *
1099 * Releases the mutex used while performing NVM operations.
1100 **/
1101static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
1102{
1103 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001104}
1105
Bruce Allanca15df52009-10-26 11:23:43 +00001106/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001107 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1108 * @hw: pointer to the HW structure
1109 *
Bruce Allanca15df52009-10-26 11:23:43 +00001110 * Acquires the software control flag for performing PHY and select
1111 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001112 **/
1113static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1114{
Bruce Allan373a88d2009-08-07 07:41:37 +00001115 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1116 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117
Bruce Allana90b4122011-10-07 03:50:38 +00001118 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1119 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001120 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001121 return -E1000_ERR_PHY;
1122 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001123
Auke Kokbc7f75f2007-09-17 12:30:59 -07001124 while (timeout) {
1125 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001126 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1127 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 mdelay(1);
1130 timeout--;
1131 }
1132
1133 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001134 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001135 ret_val = -E1000_ERR_CONFIG;
1136 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001137 }
1138
Bruce Allan53ac5a82009-10-26 11:23:06 +00001139 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001140
1141 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1142 ew32(EXTCNF_CTRL, extcnf_ctrl);
1143
1144 while (timeout) {
1145 extcnf_ctrl = er32(EXTCNF_CTRL);
1146 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1147 break;
1148
1149 mdelay(1);
1150 timeout--;
1151 }
1152
1153 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001154 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 +00001155 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001156 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1157 ew32(EXTCNF_CTRL, extcnf_ctrl);
1158 ret_val = -E1000_ERR_CONFIG;
1159 goto out;
1160 }
1161
1162out:
1163 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001164 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001165
1166 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167}
1168
1169/**
1170 * e1000_release_swflag_ich8lan - Release software control flag
1171 * @hw: pointer to the HW structure
1172 *
Bruce Allanca15df52009-10-26 11:23:43 +00001173 * Releases the software control flag for performing PHY and select
1174 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001175 **/
1176static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1177{
1178 u32 extcnf_ctrl;
1179
1180 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001181
1182 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1183 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1184 ew32(EXTCNF_CTRL, extcnf_ctrl);
1185 } else {
1186 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1187 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001188
Bruce Allana90b4122011-10-07 03:50:38 +00001189 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190}
1191
1192/**
Bruce Allan4662e822008-08-26 18:37:06 -07001193 * e1000_check_mng_mode_ich8lan - Checks management mode
1194 * @hw: pointer to the HW structure
1195 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001196 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001197 * This is a function pointer entry point only called by read/write
1198 * routines for the PHY and NVM parts.
1199 **/
1200static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1201{
Bruce Allana708dd82009-11-20 23:28:37 +00001202 u32 fwsm;
1203
1204 fwsm = er32(FWSM);
Bruce Allaneb7700d2010-06-16 13:27:05 +00001205 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1206 ((fwsm & E1000_FWSM_MODE_MASK) ==
1207 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1208}
Bruce Allan4662e822008-08-26 18:37:06 -07001209
Bruce Allaneb7700d2010-06-16 13:27:05 +00001210/**
1211 * e1000_check_mng_mode_pchlan - Checks management mode
1212 * @hw: pointer to the HW structure
1213 *
1214 * This checks if the adapter has iAMT enabled.
1215 * This is a function pointer entry point only called by read/write
1216 * routines for the PHY and NVM parts.
1217 **/
1218static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1219{
1220 u32 fwsm;
1221
1222 fwsm = er32(FWSM);
1223 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1224 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001225}
1226
1227/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001228 * e1000_rar_set_pch2lan - Set receive address register
1229 * @hw: pointer to the HW structure
1230 * @addr: pointer to the receive address
1231 * @index: receive address array register
1232 *
1233 * Sets the receive address array register at index to the address passed
1234 * in by addr. For 82579, RAR[0] is the base address register that is to
1235 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1236 * Use SHRA[0-3] in place of those reserved for ME.
1237 **/
1238static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1239{
1240 u32 rar_low, rar_high;
1241
Bruce Allane921eb12012-11-28 09:28:37 +00001242 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001243 * from network order (big endian) to little endian
1244 */
1245 rar_low = ((u32)addr[0] |
1246 ((u32)addr[1] << 8) |
1247 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1248
1249 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1250
1251 /* If MAC address zero, no need to set the AV bit */
1252 if (rar_low || rar_high)
1253 rar_high |= E1000_RAH_AV;
1254
1255 if (index == 0) {
1256 ew32(RAL(index), rar_low);
1257 e1e_flush();
1258 ew32(RAH(index), rar_high);
1259 e1e_flush();
1260 return;
1261 }
1262
1263 if (index < hw->mac.rar_entry_count) {
1264 s32 ret_val;
1265
1266 ret_val = e1000_acquire_swflag_ich8lan(hw);
1267 if (ret_val)
1268 goto out;
1269
1270 ew32(SHRAL(index - 1), rar_low);
1271 e1e_flush();
1272 ew32(SHRAH(index - 1), rar_high);
1273 e1e_flush();
1274
1275 e1000_release_swflag_ich8lan(hw);
1276
1277 /* verify the register updates */
1278 if ((er32(SHRAL(index - 1)) == rar_low) &&
1279 (er32(SHRAH(index - 1)) == rar_high))
1280 return;
1281
1282 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1283 (index - 1), er32(FWSM));
1284 }
1285
1286out:
1287 e_dbg("Failed to write receive address at index %d\n", index);
1288}
1289
1290/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001291 * e1000_rar_set_pch_lpt - Set receive address registers
1292 * @hw: pointer to the HW structure
1293 * @addr: pointer to the receive address
1294 * @index: receive address array register
1295 *
1296 * Sets the receive address register array at index to the address passed
1297 * in by addr. For LPT, RAR[0] is the base address register that is to
1298 * contain the MAC address. SHRA[0-10] are the shared receive address
1299 * registers that are shared between the Host and manageability engine (ME).
1300 **/
1301static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1302{
1303 u32 rar_low, rar_high;
1304 u32 wlock_mac;
1305
Bruce Allane921eb12012-11-28 09:28:37 +00001306 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001307 * from network order (big endian) to little endian
1308 */
1309 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1310 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1311
1312 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1313
1314 /* If MAC address zero, no need to set the AV bit */
1315 if (rar_low || rar_high)
1316 rar_high |= E1000_RAH_AV;
1317
1318 if (index == 0) {
1319 ew32(RAL(index), rar_low);
1320 e1e_flush();
1321 ew32(RAH(index), rar_high);
1322 e1e_flush();
1323 return;
1324 }
1325
Bruce Allane921eb12012-11-28 09:28:37 +00001326 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001327 * it is using - those registers are unavailable for use.
1328 */
1329 if (index < hw->mac.rar_entry_count) {
1330 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1331 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1332
1333 /* Check if all SHRAR registers are locked */
1334 if (wlock_mac == 1)
1335 goto out;
1336
1337 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1338 s32 ret_val;
1339
1340 ret_val = e1000_acquire_swflag_ich8lan(hw);
1341
1342 if (ret_val)
1343 goto out;
1344
1345 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1346 e1e_flush();
1347 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1348 e1e_flush();
1349
1350 e1000_release_swflag_ich8lan(hw);
1351
1352 /* verify the register updates */
1353 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1354 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1355 return;
1356 }
1357 }
1358
1359out:
1360 e_dbg("Failed to write receive address at index %d\n", index);
1361}
1362
1363/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001364 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1365 * @hw: pointer to the HW structure
1366 *
1367 * Checks if firmware is blocking the reset of the PHY.
1368 * This is a function pointer entry point only called by
1369 * reset routines.
1370 **/
1371static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1372{
1373 u32 fwsm;
1374
1375 fwsm = er32(FWSM);
1376
1377 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
1378}
1379
1380/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001381 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1382 * @hw: pointer to the HW structure
1383 *
1384 * Assumes semaphore already acquired.
1385 *
1386 **/
1387static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1388{
1389 u16 phy_data;
1390 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001391 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1392 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan8395ae82010-09-22 17:15:08 +00001393 s32 ret_val = 0;
1394
1395 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1396
1397 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1398 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001399 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001400
1401 phy_data &= ~HV_SMB_ADDR_MASK;
1402 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1403 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001404
Bruce Allan2fbe4522012-04-19 03:21:47 +00001405 if (hw->phy.type == e1000_phy_i217) {
1406 /* Restore SMBus frequency */
1407 if (freq--) {
1408 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1409 phy_data |= (freq & (1 << 0)) <<
1410 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1411 phy_data |= (freq & (1 << 1)) <<
1412 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1413 } else {
1414 e_dbg("Unsupported SMB frequency in PHY\n");
1415 }
1416 }
1417
Bruce Allan5015e532012-02-08 02:55:56 +00001418 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001419}
1420
1421/**
Bruce Allanf523d212009-10-29 13:45:45 +00001422 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1423 * @hw: pointer to the HW structure
1424 *
1425 * SW should configure the LCD from the NVM extended configuration region
1426 * as a workaround for certain parts.
1427 **/
1428static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1429{
1430 struct e1000_phy_info *phy = &hw->phy;
1431 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001432 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001433 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1434
Bruce Allane921eb12012-11-28 09:28:37 +00001435 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001436 * is needed due to an issue where the NVM configuration is
1437 * not properly autoloaded after power transitions.
1438 * Therefore, after each PHY reset, we will load the
1439 * configuration data out of the NVM manually.
1440 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001441 switch (hw->mac.type) {
1442 case e1000_ich8lan:
1443 if (phy->type != e1000_phy_igp_3)
1444 return ret_val;
1445
Bruce Allan5f3eed62010-09-22 17:15:54 +00001446 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1447 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001448 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1449 break;
1450 }
1451 /* Fall-thru */
1452 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001453 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001454 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001455 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001456 break;
1457 default:
1458 return ret_val;
1459 }
1460
1461 ret_val = hw->phy.ops.acquire(hw);
1462 if (ret_val)
1463 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001464
Bruce Allan8b802a72010-05-10 15:01:10 +00001465 data = er32(FEXTNVM);
1466 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001467 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001468
Bruce Allane921eb12012-11-28 09:28:37 +00001469 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001470 * extended configuration before SW configuration
1471 */
1472 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001473 if ((hw->mac.type < e1000_pch2lan) &&
1474 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1475 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001476
Bruce Allan8b802a72010-05-10 15:01:10 +00001477 cnf_size = er32(EXTCNF_SIZE);
1478 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1479 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1480 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001481 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001482
1483 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1484 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1485
Bruce Allan2fbe4522012-04-19 03:21:47 +00001486 if (((hw->mac.type == e1000_pchlan) &&
1487 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1488 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001489 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001490 * OEM and LCD Write Enable bits are set in the NVM.
1491 * When both NVM bits are cleared, SW will configure
1492 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001493 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001494 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001495 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001496 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001497
Bruce Allan8b802a72010-05-10 15:01:10 +00001498 data = er32(LEDCTL);
1499 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1500 (u16)data);
1501 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001502 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001503 }
1504
1505 /* Configure LCD from extended configuration region. */
1506
1507 /* cnf_base_addr is in DWORD */
1508 word_addr = (u16)(cnf_base_addr << 1);
1509
1510 for (i = 0; i < cnf_size; i++) {
1511 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
1512 &reg_data);
1513 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001514 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001515
Bruce Allan8b802a72010-05-10 15:01:10 +00001516 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1517 1, &reg_addr);
1518 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001519 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001520
Bruce Allan8b802a72010-05-10 15:01:10 +00001521 /* Save off the PHY page for future writes. */
1522 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1523 phy_page = reg_data;
1524 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001525 }
Bruce Allanf523d212009-10-29 13:45:45 +00001526
Bruce Allan8b802a72010-05-10 15:01:10 +00001527 reg_addr &= PHY_REG_MASK;
1528 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001529
Bruce Allanf1430d62012-04-14 04:21:52 +00001530 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001531 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001532 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001533 }
1534
Bruce Allan75ce1532012-02-08 02:54:48 +00001535release:
Bruce Allan94d81862009-11-20 23:25:26 +00001536 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001537 return ret_val;
1538}
1539
1540/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001541 * e1000_k1_gig_workaround_hv - K1 Si workaround
1542 * @hw: pointer to the HW structure
1543 * @link: link up bool flag
1544 *
1545 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1546 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1547 * If link is down, the function will restore the default K1 setting located
1548 * in the NVM.
1549 **/
1550static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1551{
1552 s32 ret_val = 0;
1553 u16 status_reg = 0;
1554 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1555
1556 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001557 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001558
1559 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001560 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001561 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001562 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001563
1564 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1565 if (link) {
1566 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001567 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1568 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001569 if (ret_val)
1570 goto release;
1571
1572 status_reg &= BM_CS_STATUS_LINK_UP |
1573 BM_CS_STATUS_RESOLVED |
1574 BM_CS_STATUS_SPEED_MASK;
1575
1576 if (status_reg == (BM_CS_STATUS_LINK_UP |
1577 BM_CS_STATUS_RESOLVED |
1578 BM_CS_STATUS_SPEED_1000))
1579 k1_enable = false;
1580 }
1581
1582 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001583 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001584 if (ret_val)
1585 goto release;
1586
1587 status_reg &= HV_M_STATUS_LINK_UP |
1588 HV_M_STATUS_AUTONEG_COMPLETE |
1589 HV_M_STATUS_SPEED_MASK;
1590
1591 if (status_reg == (HV_M_STATUS_LINK_UP |
1592 HV_M_STATUS_AUTONEG_COMPLETE |
1593 HV_M_STATUS_SPEED_1000))
1594 k1_enable = false;
1595 }
1596
1597 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001598 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001599 if (ret_val)
1600 goto release;
1601
1602 } else {
1603 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001604 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001605 if (ret_val)
1606 goto release;
1607 }
1608
1609 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1610
1611release:
Bruce Allan94d81862009-11-20 23:25:26 +00001612 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001613
Bruce Allan1d5846b2009-10-29 13:46:05 +00001614 return ret_val;
1615}
1616
1617/**
1618 * e1000_configure_k1_ich8lan - Configure K1 power state
1619 * @hw: pointer to the HW structure
1620 * @enable: K1 state to configure
1621 *
1622 * Configure the K1 power state based on the provided parameter.
1623 * Assumes semaphore already acquired.
1624 *
1625 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1626 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001627s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001628{
1629 s32 ret_val = 0;
1630 u32 ctrl_reg = 0;
1631 u32 ctrl_ext = 0;
1632 u32 reg = 0;
1633 u16 kmrn_reg = 0;
1634
Bruce Allan3d3a1672012-02-23 03:13:18 +00001635 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1636 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001637 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001638 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001639
1640 if (k1_enable)
1641 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1642 else
1643 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1644
Bruce Allan3d3a1672012-02-23 03:13:18 +00001645 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1646 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001647 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001648 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001649
1650 udelay(20);
1651 ctrl_ext = er32(CTRL_EXT);
1652 ctrl_reg = er32(CTRL);
1653
1654 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1655 reg |= E1000_CTRL_FRCSPD;
1656 ew32(CTRL, reg);
1657
1658 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001659 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001660 udelay(20);
1661 ew32(CTRL, ctrl_reg);
1662 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001663 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001664 udelay(20);
1665
Bruce Allan5015e532012-02-08 02:55:56 +00001666 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001667}
1668
1669/**
Bruce Allanf523d212009-10-29 13:45:45 +00001670 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1671 * @hw: pointer to the HW structure
1672 * @d0_state: boolean if entering d0 or d3 device state
1673 *
1674 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1675 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1676 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1677 **/
1678static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1679{
1680 s32 ret_val = 0;
1681 u32 mac_reg;
1682 u16 oem_reg;
1683
Bruce Allan2fbe4522012-04-19 03:21:47 +00001684 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001685 return ret_val;
1686
Bruce Allan94d81862009-11-20 23:25:26 +00001687 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001688 if (ret_val)
1689 return ret_val;
1690
Bruce Allan2fbe4522012-04-19 03:21:47 +00001691 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001692 mac_reg = er32(EXTCNF_CTRL);
1693 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001694 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001695 }
Bruce Allanf523d212009-10-29 13:45:45 +00001696
1697 mac_reg = er32(FEXTNVM);
1698 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001699 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001700
1701 mac_reg = er32(PHY_CTRL);
1702
Bruce Allanf1430d62012-04-14 04:21:52 +00001703 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001704 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001705 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001706
1707 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1708
1709 if (d0_state) {
1710 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1711 oem_reg |= HV_OEM_BITS_GBE_DIS;
1712
1713 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1714 oem_reg |= HV_OEM_BITS_LPLU;
1715 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001716 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1717 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001718 oem_reg |= HV_OEM_BITS_GBE_DIS;
1719
Bruce Allan03299e42011-09-30 08:07:05 +00001720 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1721 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001722 oem_reg |= HV_OEM_BITS_LPLU;
1723 }
Bruce Allan03299e42011-09-30 08:07:05 +00001724
Bruce Allan92fe1732012-04-12 06:27:03 +00001725 /* Set Restart auto-neg to activate the bits */
1726 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1727 !hw->phy.ops.check_reset_block(hw))
1728 oem_reg |= HV_OEM_BITS_RESTART_AN;
1729
Bruce Allanf1430d62012-04-14 04:21:52 +00001730 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001731
Bruce Allan75ce1532012-02-08 02:54:48 +00001732release:
Bruce Allan94d81862009-11-20 23:25:26 +00001733 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001734
1735 return ret_val;
1736}
1737
1738
1739/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001740 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1741 * @hw: pointer to the HW structure
1742 **/
1743static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1744{
1745 s32 ret_val;
1746 u16 data;
1747
1748 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1749 if (ret_val)
1750 return ret_val;
1751
1752 data |= HV_KMRN_MDIO_SLOW;
1753
1754 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1755
1756 return ret_val;
1757}
1758
1759/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001760 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1761 * done after every PHY reset.
1762 **/
1763static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1764{
1765 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001766 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001767
1768 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001769 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001770
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001771 /* Set MDIO slow mode before any other MDIO access */
1772 if (hw->phy.type == e1000_phy_82577) {
1773 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1774 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001775 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001776 }
1777
Bruce Allana4f58f52009-06-02 11:29:18 +00001778 if (((hw->phy.type == e1000_phy_82577) &&
1779 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1780 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1781 /* Disable generation of early preamble */
1782 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1783 if (ret_val)
1784 return ret_val;
1785
1786 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001787 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001788 if (ret_val)
1789 return ret_val;
1790 }
1791
1792 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001793 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001794 * writing 0x3140 to the control register.
1795 */
1796 if (hw->phy.revision < 2) {
1797 e1000e_phy_sw_reset(hw);
1798 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1799 }
1800 }
1801
1802 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001803 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001804 if (ret_val)
1805 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001806
Bruce Allana4f58f52009-06-02 11:29:18 +00001807 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001808 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001809 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001810 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001811 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001812
Bruce Allane921eb12012-11-28 09:28:37 +00001813 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001814 * link so that it disables K1 if link is in 1Gbps.
1815 */
1816 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001817 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001818 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001819
Bruce Allanbaf86c92010-01-13 01:53:08 +00001820 /* Workaround for link disconnects on a busy hub in half duplex */
1821 ret_val = hw->phy.ops.acquire(hw);
1822 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001823 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001824 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001825 if (ret_val)
1826 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001827 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001828 if (ret_val)
1829 goto release;
1830
1831 /* set MSE higher to enable link to stay up when noise is high */
1832 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001833release:
1834 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001835
Bruce Allana4f58f52009-06-02 11:29:18 +00001836 return ret_val;
1837}
1838
1839/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001840 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1841 * @hw: pointer to the HW structure
1842 **/
1843void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1844{
1845 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001846 u16 i, phy_reg = 0;
1847 s32 ret_val;
1848
1849 ret_val = hw->phy.ops.acquire(hw);
1850 if (ret_val)
1851 return;
1852 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1853 if (ret_val)
1854 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001855
1856 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1857 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1858 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001859 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1860 (u16)(mac_reg & 0xFFFF));
1861 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1862 (u16)((mac_reg >> 16) & 0xFFFF));
1863
Bruce Alland3738bb2010-06-16 13:27:28 +00001864 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001865 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1866 (u16)(mac_reg & 0xFFFF));
1867 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1868 (u16)((mac_reg & E1000_RAH_AV)
1869 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00001870 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00001871
1872 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1873
1874release:
1875 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001876}
1877
Bruce Alland3738bb2010-06-16 13:27:28 +00001878/**
1879 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1880 * with 82579 PHY
1881 * @hw: pointer to the HW structure
1882 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1883 **/
1884s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1885{
1886 s32 ret_val = 0;
1887 u16 phy_reg, data;
1888 u32 mac_reg;
1889 u16 i;
1890
Bruce Allan2fbe4522012-04-19 03:21:47 +00001891 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001892 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001893
1894 /* disable Rx path while enabling/disabling workaround */
1895 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1896 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1897 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001898 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001899
1900 if (enable) {
Bruce Allane921eb12012-11-28 09:28:37 +00001901 /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
Bruce Alland3738bb2010-06-16 13:27:28 +00001902 * SHRAL/H) and initial CRC values to the MAC
1903 */
1904 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1905 u8 mac_addr[ETH_ALEN] = {0};
1906 u32 addr_high, addr_low;
1907
1908 addr_high = er32(RAH(i));
1909 if (!(addr_high & E1000_RAH_AV))
1910 continue;
1911 addr_low = er32(RAL(i));
1912 mac_addr[0] = (addr_low & 0xFF);
1913 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1914 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1915 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1916 mac_addr[4] = (addr_high & 0xFF);
1917 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1918
Bruce Allanfe46f582011-01-06 14:29:51 +00001919 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00001920 }
1921
1922 /* Write Rx addresses to the PHY */
1923 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1924
1925 /* Enable jumbo frame workaround in the MAC */
1926 mac_reg = er32(FFLT_DBG);
1927 mac_reg &= ~(1 << 14);
1928 mac_reg |= (7 << 15);
1929 ew32(FFLT_DBG, mac_reg);
1930
1931 mac_reg = er32(RCTL);
1932 mac_reg |= E1000_RCTL_SECRC;
1933 ew32(RCTL, mac_reg);
1934
1935 ret_val = e1000e_read_kmrn_reg(hw,
1936 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1937 &data);
1938 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001939 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001940 ret_val = e1000e_write_kmrn_reg(hw,
1941 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1942 data | (1 << 0));
1943 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001944 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001945 ret_val = e1000e_read_kmrn_reg(hw,
1946 E1000_KMRNCTRLSTA_HD_CTRL,
1947 &data);
1948 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001949 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001950 data &= ~(0xF << 8);
1951 data |= (0xB << 8);
1952 ret_val = e1000e_write_kmrn_reg(hw,
1953 E1000_KMRNCTRLSTA_HD_CTRL,
1954 data);
1955 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001956 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001957
1958 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001959 e1e_rphy(hw, PHY_REG(769, 23), &data);
1960 data &= ~(0x7F << 5);
1961 data |= (0x37 << 5);
1962 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1963 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001964 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001965 e1e_rphy(hw, PHY_REG(769, 16), &data);
1966 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00001967 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1968 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001969 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001970 e1e_rphy(hw, PHY_REG(776, 20), &data);
1971 data &= ~(0x3FF << 2);
1972 data |= (0x1A << 2);
1973 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1974 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001975 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00001976 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00001977 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001978 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001979 e1e_rphy(hw, HV_PM_CTRL, &data);
1980 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1981 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001982 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001983 } else {
1984 /* Write MAC register values back to h/w defaults */
1985 mac_reg = er32(FFLT_DBG);
1986 mac_reg &= ~(0xF << 14);
1987 ew32(FFLT_DBG, mac_reg);
1988
1989 mac_reg = er32(RCTL);
1990 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00001991 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00001992
1993 ret_val = e1000e_read_kmrn_reg(hw,
1994 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1995 &data);
1996 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001997 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001998 ret_val = e1000e_write_kmrn_reg(hw,
1999 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2000 data & ~(1 << 0));
2001 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002002 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002003 ret_val = e1000e_read_kmrn_reg(hw,
2004 E1000_KMRNCTRLSTA_HD_CTRL,
2005 &data);
2006 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002007 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002008 data &= ~(0xF << 8);
2009 data |= (0xB << 8);
2010 ret_val = e1000e_write_kmrn_reg(hw,
2011 E1000_KMRNCTRLSTA_HD_CTRL,
2012 data);
2013 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002014 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002015
2016 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002017 e1e_rphy(hw, PHY_REG(769, 23), &data);
2018 data &= ~(0x7F << 5);
2019 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2020 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002021 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002022 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002023 data |= (1 << 13);
2024 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2025 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002026 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002027 e1e_rphy(hw, PHY_REG(776, 20), &data);
2028 data &= ~(0x3FF << 2);
2029 data |= (0x8 << 2);
2030 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2031 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002032 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002033 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2034 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002035 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002036 e1e_rphy(hw, HV_PM_CTRL, &data);
2037 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2038 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002039 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002040 }
2041
2042 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002043 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002044}
2045
2046/**
2047 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2048 * done after every PHY reset.
2049 **/
2050static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2051{
2052 s32 ret_val = 0;
2053
2054 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002055 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002056
2057 /* Set MDIO slow mode before any other MDIO access */
2058 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002059 if (ret_val)
2060 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002061
Bruce Allan4d241362011-12-16 00:46:06 +00002062 ret_val = hw->phy.ops.acquire(hw);
2063 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002064 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002065 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002066 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002067 if (ret_val)
2068 goto release;
2069 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002070 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002071release:
2072 hw->phy.ops.release(hw);
2073
Bruce Alland3738bb2010-06-16 13:27:28 +00002074 return ret_val;
2075}
2076
2077/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002078 * e1000_k1_gig_workaround_lv - K1 Si workaround
2079 * @hw: pointer to the HW structure
2080 *
2081 * Workaround to set the K1 beacon duration for 82579 parts
2082 **/
2083static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2084{
2085 s32 ret_val = 0;
2086 u16 status_reg = 0;
2087 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002088 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002089
2090 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002091 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002092
2093 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2094 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2095 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002096 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002097
2098 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2099 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2100 mac_reg = er32(FEXTNVM4);
2101 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2102
Bruce Allan0ed013e2011-07-29 05:52:56 +00002103 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2104 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002105 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002106
Bruce Allan0ed013e2011-07-29 05:52:56 +00002107 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002108 u16 pm_phy_reg;
2109
Bruce Allan0ed013e2011-07-29 05:52:56 +00002110 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2111 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002112 /* LV 1G Packet drop issue wa */
2113 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2114 if (ret_val)
2115 return ret_val;
2116 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2117 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2118 if (ret_val)
2119 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002120 } else {
2121 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2122 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2123 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002124 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002125 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002126 }
2127
Bruce Allan831bd2e2010-09-22 17:16:18 +00002128 return ret_val;
2129}
2130
2131/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002132 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2133 * @hw: pointer to the HW structure
2134 * @gate: boolean set to true to gate, false to ungate
2135 *
2136 * Gate/ungate the automatic PHY configuration via hardware; perform
2137 * the configuration via software instead.
2138 **/
2139static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2140{
2141 u32 extcnf_ctrl;
2142
Bruce Allan2fbe4522012-04-19 03:21:47 +00002143 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002144 return;
2145
2146 extcnf_ctrl = er32(EXTCNF_CTRL);
2147
2148 if (gate)
2149 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2150 else
2151 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2152
2153 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002154}
2155
2156/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002157 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2158 * @hw: pointer to the HW structure
2159 *
2160 * Check the appropriate indication the MAC has finished configuring the
2161 * PHY after a software reset.
2162 **/
2163static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2164{
2165 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2166
2167 /* Wait for basic configuration completes before proceeding */
2168 do {
2169 data = er32(STATUS);
2170 data &= E1000_STATUS_LAN_INIT_DONE;
2171 udelay(100);
2172 } while ((!data) && --loop);
2173
Bruce Allane921eb12012-11-28 09:28:37 +00002174 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002175 * count reaches 0, loading the configuration from NVM will
2176 * leave the PHY in a bad state possibly resulting in no link.
2177 */
2178 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002179 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002180
2181 /* Clear the Init Done bit for the next init event */
2182 data = er32(STATUS);
2183 data &= ~E1000_STATUS_LAN_INIT_DONE;
2184 ew32(STATUS, data);
2185}
2186
2187/**
Bruce Allane98cac42010-05-10 15:02:32 +00002188 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002189 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002191static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002192{
Bruce Allanf523d212009-10-29 13:45:45 +00002193 s32 ret_val = 0;
2194 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002195
Bruce Allan44abd5c2012-02-22 09:02:37 +00002196 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002197 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002198
Bruce Allan5f3eed62010-09-22 17:15:54 +00002199 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002200 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002201
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002202 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002203 switch (hw->mac.type) {
2204 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002205 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2206 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002207 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002208 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002209 case e1000_pch2lan:
2210 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2211 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002212 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002213 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002214 default:
2215 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002216 }
2217
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002218 /* Clear the host wakeup bit after lcd reset */
2219 if (hw->mac.type >= e1000_pchlan) {
2220 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2221 reg &= ~BM_WUC_HOST_WU_BIT;
2222 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2223 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002224
Bruce Allanf523d212009-10-29 13:45:45 +00002225 /* Configure the LCD with the extended configuration region in NVM */
2226 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2227 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002228 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229
Bruce Allanf523d212009-10-29 13:45:45 +00002230 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002231 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232
Bruce Allan1effb452011-02-25 06:58:03 +00002233 if (hw->mac.type == e1000_pch2lan) {
2234 /* Ungate automatic PHY configuration on non-managed 82579 */
2235 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002236 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002237 e1000_gate_hw_phy_config_ich8lan(hw, false);
2238 }
2239
2240 /* Set EEE LPI Update Timer to 200usec */
2241 ret_val = hw->phy.ops.acquire(hw);
2242 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002243 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002244 ret_val = e1000_write_emi_reg_locked(hw,
2245 I82579_LPI_UPDATE_TIMER,
2246 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002247 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002248 }
2249
Bruce Allane98cac42010-05-10 15:02:32 +00002250 return ret_val;
2251}
2252
2253/**
2254 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2255 * @hw: pointer to the HW structure
2256 *
2257 * Resets the PHY
2258 * This is a function pointer entry point called by drivers
2259 * or other shared routines.
2260 **/
2261static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2262{
2263 s32 ret_val = 0;
2264
Bruce Allan605c82b2010-09-22 17:17:01 +00002265 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2266 if ((hw->mac.type == e1000_pch2lan) &&
2267 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2268 e1000_gate_hw_phy_config_ich8lan(hw, true);
2269
Bruce Allane98cac42010-05-10 15:02:32 +00002270 ret_val = e1000e_phy_hw_reset_generic(hw);
2271 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002272 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002273
Bruce Allan5015e532012-02-08 02:55:56 +00002274 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002275}
2276
2277/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002278 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2279 * @hw: pointer to the HW structure
2280 * @active: true to enable LPLU, false to disable
2281 *
2282 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2283 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2284 * the phy speed. This function will manually set the LPLU bit and restart
2285 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2286 * since it configures the same bit.
2287 **/
2288static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2289{
2290 s32 ret_val = 0;
2291 u16 oem_reg;
2292
2293 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2294 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002295 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002296
2297 if (active)
2298 oem_reg |= HV_OEM_BITS_LPLU;
2299 else
2300 oem_reg &= ~HV_OEM_BITS_LPLU;
2301
Bruce Allan44abd5c2012-02-22 09:02:37 +00002302 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002303 oem_reg |= HV_OEM_BITS_RESTART_AN;
2304
Bruce Allan5015e532012-02-08 02:55:56 +00002305 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002306}
2307
2308/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002309 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2310 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002311 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002312 *
2313 * Sets the LPLU D0 state according to the active flag. When
2314 * activating LPLU this function also disables smart speed
2315 * and vice versa. LPLU will not be activated unless the
2316 * device autonegotiation advertisement meets standards of
2317 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2318 * This is a function pointer entry point only called by
2319 * PHY setup routines.
2320 **/
2321static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2322{
2323 struct e1000_phy_info *phy = &hw->phy;
2324 u32 phy_ctrl;
2325 s32 ret_val = 0;
2326 u16 data;
2327
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002328 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002329 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330
2331 phy_ctrl = er32(PHY_CTRL);
2332
2333 if (active) {
2334 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2335 ew32(PHY_CTRL, phy_ctrl);
2336
Bruce Allan60f12922009-07-01 13:28:14 +00002337 if (phy->type != e1000_phy_igp_3)
2338 return 0;
2339
Bruce Allane921eb12012-11-28 09:28:37 +00002340 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002341 * any PHY registers
2342 */
Bruce Allan60f12922009-07-01 13:28:14 +00002343 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344 e1000e_gig_downshift_workaround_ich8lan(hw);
2345
2346 /* When LPLU is enabled, we should disable SmartSpeed */
2347 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
2348 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2349 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2350 if (ret_val)
2351 return ret_val;
2352 } else {
2353 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2354 ew32(PHY_CTRL, phy_ctrl);
2355
Bruce Allan60f12922009-07-01 13:28:14 +00002356 if (phy->type != e1000_phy_igp_3)
2357 return 0;
2358
Bruce Allane921eb12012-11-28 09:28:37 +00002359 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002360 * during Dx states where the power conservation is most
2361 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002362 * SmartSpeed, so performance is maintained.
2363 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002364 if (phy->smart_speed == e1000_smart_speed_on) {
2365 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002366 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002367 if (ret_val)
2368 return ret_val;
2369
2370 data |= IGP01E1000_PSCFR_SMART_SPEED;
2371 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002372 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 if (ret_val)
2374 return ret_val;
2375 } else if (phy->smart_speed == e1000_smart_speed_off) {
2376 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002377 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002378 if (ret_val)
2379 return ret_val;
2380
2381 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2382 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002383 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002384 if (ret_val)
2385 return ret_val;
2386 }
2387 }
2388
2389 return 0;
2390}
2391
2392/**
2393 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2394 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002395 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002396 *
2397 * Sets the LPLU D3 state according to the active flag. When
2398 * activating LPLU this function also disables smart speed
2399 * and vice versa. LPLU will not be activated unless the
2400 * device autonegotiation advertisement meets standards of
2401 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2402 * This is a function pointer entry point only called by
2403 * PHY setup routines.
2404 **/
2405static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2406{
2407 struct e1000_phy_info *phy = &hw->phy;
2408 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002409 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410 u16 data;
2411
2412 phy_ctrl = er32(PHY_CTRL);
2413
2414 if (!active) {
2415 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2416 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002417
2418 if (phy->type != e1000_phy_igp_3)
2419 return 0;
2420
Bruce Allane921eb12012-11-28 09:28:37 +00002421 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002422 * during Dx states where the power conservation is most
2423 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002424 * SmartSpeed, so performance is maintained.
2425 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002426 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002427 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2428 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002429 if (ret_val)
2430 return ret_val;
2431
2432 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002433 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2434 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002435 if (ret_val)
2436 return ret_val;
2437 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002438 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2439 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440 if (ret_val)
2441 return ret_val;
2442
2443 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002444 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2445 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 if (ret_val)
2447 return ret_val;
2448 }
2449 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2450 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2451 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2452 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2453 ew32(PHY_CTRL, phy_ctrl);
2454
Bruce Allan60f12922009-07-01 13:28:14 +00002455 if (phy->type != e1000_phy_igp_3)
2456 return 0;
2457
Bruce Allane921eb12012-11-28 09:28:37 +00002458 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002459 * any PHY registers
2460 */
Bruce Allan60f12922009-07-01 13:28:14 +00002461 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002462 e1000e_gig_downshift_workaround_ich8lan(hw);
2463
2464 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002465 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002466 if (ret_val)
2467 return ret_val;
2468
2469 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002470 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002471 }
2472
Bruce Alland7eb3382012-02-08 02:55:14 +00002473 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002474}
2475
2476/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002477 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2478 * @hw: pointer to the HW structure
2479 * @bank: pointer to the variable that returns the active bank
2480 *
2481 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002482 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002483 **/
2484static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2485{
Bruce Allane2434552008-11-21 17:02:41 -08002486 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002487 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002488 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2489 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002490 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002491 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002492
Bruce Allane2434552008-11-21 17:02:41 -08002493 switch (hw->mac.type) {
2494 case e1000_ich8lan:
2495 case e1000_ich9lan:
2496 eecd = er32(EECD);
2497 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2498 E1000_EECD_SEC1VAL_VALID_MASK) {
2499 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002500 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002501 else
2502 *bank = 0;
2503
2504 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002505 }
Bruce Allan434f1392011-12-16 00:46:54 +00002506 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002507 /* fall-thru */
2508 default:
2509 /* set bank to 0 in case flash read fails */
2510 *bank = 0;
2511
2512 /* Check bank 0 */
2513 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
2514 &sig_byte);
2515 if (ret_val)
2516 return ret_val;
2517 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2518 E1000_ICH_NVM_SIG_VALUE) {
2519 *bank = 0;
2520 return 0;
2521 }
2522
2523 /* Check bank 1 */
2524 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
2525 bank1_offset,
2526 &sig_byte);
2527 if (ret_val)
2528 return ret_val;
2529 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2530 E1000_ICH_NVM_SIG_VALUE) {
2531 *bank = 1;
2532 return 0;
2533 }
2534
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002535 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002536 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002537 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002538}
2539
2540/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2542 * @hw: pointer to the HW structure
2543 * @offset: The offset (in bytes) of the word(s) to read.
2544 * @words: Size of data to read in words
2545 * @data: Pointer to the word(s) to read at offset.
2546 *
2547 * Reads a word(s) from the NVM using the flash access registers.
2548 **/
2549static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2550 u16 *data)
2551{
2552 struct e1000_nvm_info *nvm = &hw->nvm;
2553 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2554 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002555 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002556 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002557 u16 i, word;
2558
2559 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2560 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002561 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002562 ret_val = -E1000_ERR_NVM;
2563 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002564 }
2565
Bruce Allan94d81862009-11-20 23:25:26 +00002566 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002567
Bruce Allanf4187b52008-08-26 18:36:50 -07002568 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002569 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002570 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002571 bank = 0;
2572 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002573
2574 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002575 act_offset += offset;
2576
Bruce Allan148675a2009-08-07 07:41:56 +00002577 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002578 for (i = 0; i < words; i++) {
Bruce Allanb9e06f72011-07-22 06:21:41 +00002579 if (dev_spec->shadow_ram[offset+i].modified) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002580 data[i] = dev_spec->shadow_ram[offset+i].value;
2581 } else {
2582 ret_val = e1000_read_flash_word_ich8lan(hw,
2583 act_offset + i,
2584 &word);
2585 if (ret_val)
2586 break;
2587 data[i] = word;
2588 }
2589 }
2590
Bruce Allan94d81862009-11-20 23:25:26 +00002591 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002592
Bruce Allane2434552008-11-21 17:02:41 -08002593out:
2594 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002595 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002596
Auke Kokbc7f75f2007-09-17 12:30:59 -07002597 return ret_val;
2598}
2599
2600/**
2601 * e1000_flash_cycle_init_ich8lan - Initialize flash
2602 * @hw: pointer to the HW structure
2603 *
2604 * This function does initial flash setup so that a new read/write/erase cycle
2605 * can be started.
2606 **/
2607static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2608{
2609 union ich8_hws_flash_status hsfsts;
2610 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611
2612 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2613
2614 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002615 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002616 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002617 return -E1000_ERR_NVM;
2618 }
2619
2620 /* Clear FCERR and DAEL in hw status by writing 1 */
2621 hsfsts.hsf_status.flcerr = 1;
2622 hsfsts.hsf_status.dael = 1;
2623
2624 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2625
Bruce Allane921eb12012-11-28 09:28:37 +00002626 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002627 * bit to check against, in order to start a new cycle or
2628 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002629 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002630 * indication whether a cycle is in progress or has been
2631 * completed.
2632 */
2633
Bruce Allan04499ec2012-04-13 00:08:31 +00002634 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002635 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002636 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002637 * Begin by setting Flash Cycle Done.
2638 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002639 hsfsts.hsf_status.flcdone = 1;
2640 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2641 ret_val = 0;
2642 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002643 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002644
Bruce Allane921eb12012-11-28 09:28:37 +00002645 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002646 * cycle has a chance to end before giving up.
2647 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002648 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002649 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002650 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002651 ret_val = 0;
2652 break;
2653 }
2654 udelay(1);
2655 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002656 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002657 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002658 * now set the Flash Cycle Done.
2659 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002660 hsfsts.hsf_status.flcdone = 1;
2661 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2662 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002663 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002664 }
2665 }
2666
2667 return ret_val;
2668}
2669
2670/**
2671 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2672 * @hw: pointer to the HW structure
2673 * @timeout: maximum time to wait for completion
2674 *
2675 * This function starts a flash cycle and waits for its completion.
2676 **/
2677static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2678{
2679 union ich8_hws_flash_ctrl hsflctl;
2680 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002681 u32 i = 0;
2682
2683 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2684 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2685 hsflctl.hsf_ctrl.flcgo = 1;
2686 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2687
2688 /* wait till FDONE bit is set to 1 */
2689 do {
2690 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002691 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002692 break;
2693 udelay(1);
2694 } while (i++ < timeout);
2695
Bruce Allan04499ec2012-04-13 00:08:31 +00002696 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002697 return 0;
2698
Bruce Allan55920b52012-02-08 02:55:25 +00002699 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700}
2701
2702/**
2703 * e1000_read_flash_word_ich8lan - Read word from flash
2704 * @hw: pointer to the HW structure
2705 * @offset: offset to data location
2706 * @data: pointer to the location for storing the data
2707 *
2708 * Reads the flash word at offset into data. Offset is converted
2709 * to bytes before read.
2710 **/
2711static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2712 u16 *data)
2713{
2714 /* Must convert offset into bytes. */
2715 offset <<= 1;
2716
2717 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2718}
2719
2720/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002721 * e1000_read_flash_byte_ich8lan - Read byte from flash
2722 * @hw: pointer to the HW structure
2723 * @offset: The offset of the byte to read.
2724 * @data: Pointer to a byte to store the value read.
2725 *
2726 * Reads a single byte from the NVM using the flash access registers.
2727 **/
2728static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2729 u8 *data)
2730{
2731 s32 ret_val;
2732 u16 word = 0;
2733
2734 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2735 if (ret_val)
2736 return ret_val;
2737
2738 *data = (u8)word;
2739
2740 return 0;
2741}
2742
2743/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002744 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2745 * @hw: pointer to the HW structure
2746 * @offset: The offset (in bytes) of the byte or word to read.
2747 * @size: Size of data to read, 1=byte 2=word
2748 * @data: Pointer to the word to store the value read.
2749 *
2750 * Reads a byte or word from the NVM using the flash access registers.
2751 **/
2752static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2753 u8 size, u16 *data)
2754{
2755 union ich8_hws_flash_status hsfsts;
2756 union ich8_hws_flash_ctrl hsflctl;
2757 u32 flash_linear_addr;
2758 u32 flash_data = 0;
2759 s32 ret_val = -E1000_ERR_NVM;
2760 u8 count = 0;
2761
2762 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2763 return -E1000_ERR_NVM;
2764
2765 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2766 hw->nvm.flash_base_addr;
2767
2768 do {
2769 udelay(1);
2770 /* Steps */
2771 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002772 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002773 break;
2774
2775 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2776 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2777 hsflctl.hsf_ctrl.fldbcount = size - 1;
2778 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2779 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2780
2781 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2782
2783 ret_val = e1000_flash_cycle_ich8lan(hw,
2784 ICH_FLASH_READ_COMMAND_TIMEOUT);
2785
Bruce Allane921eb12012-11-28 09:28:37 +00002786 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787 * and try the whole sequence a few more times, else
2788 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002789 * least significant byte first msb to lsb
2790 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002791 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002792 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002793 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002794 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002795 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002796 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002797 break;
2798 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002799 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002800 * completely hosed, but if the error condition is
2801 * detected, it won't hurt to give it another try...
2802 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2803 */
2804 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002805 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002806 /* Repeat for some time before giving up. */
2807 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002808 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002809 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002810 break;
2811 }
2812 }
2813 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2814
2815 return ret_val;
2816}
2817
2818/**
2819 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2820 * @hw: pointer to the HW structure
2821 * @offset: The offset (in bytes) of the word(s) to write.
2822 * @words: Size of data to write in words
2823 * @data: Pointer to the word(s) to write at offset.
2824 *
2825 * Writes a byte or word to the NVM using the flash access registers.
2826 **/
2827static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2828 u16 *data)
2829{
2830 struct e1000_nvm_info *nvm = &hw->nvm;
2831 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832 u16 i;
2833
2834 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2835 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002836 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002837 return -E1000_ERR_NVM;
2838 }
2839
Bruce Allan94d81862009-11-20 23:25:26 +00002840 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002841
Auke Kokbc7f75f2007-09-17 12:30:59 -07002842 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002843 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844 dev_spec->shadow_ram[offset+i].value = data[i];
2845 }
2846
Bruce Allan94d81862009-11-20 23:25:26 +00002847 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002848
Auke Kokbc7f75f2007-09-17 12:30:59 -07002849 return 0;
2850}
2851
2852/**
2853 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2854 * @hw: pointer to the HW structure
2855 *
2856 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2857 * which writes the checksum to the shadow ram. The changes in the shadow
2858 * ram are then committed to the EEPROM by processing each bank at a time
2859 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002860 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002861 * future writes.
2862 **/
2863static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2864{
2865 struct e1000_nvm_info *nvm = &hw->nvm;
2866 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002867 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002868 s32 ret_val;
2869 u16 data;
2870
2871 ret_val = e1000e_update_nvm_checksum_generic(hw);
2872 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002873 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002874
2875 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002876 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002877
Bruce Allan94d81862009-11-20 23:25:26 +00002878 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002879
Bruce Allane921eb12012-11-28 09:28:37 +00002880 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002881 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002882 * is going to be written
2883 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002884 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002885 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002886 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002887 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002888 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002889
2890 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002891 new_bank_offset = nvm->flash_bank_size;
2892 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002893 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002894 if (ret_val)
2895 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002896 } else {
2897 old_bank_offset = nvm->flash_bank_size;
2898 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002899 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002900 if (ret_val)
2901 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002902 }
2903
2904 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00002905 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002907 * in the shadow RAM
2908 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002909 if (dev_spec->shadow_ram[i].modified) {
2910 data = dev_spec->shadow_ram[i].value;
2911 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002912 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2913 old_bank_offset,
2914 &data);
2915 if (ret_val)
2916 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002917 }
2918
Bruce Allane921eb12012-11-28 09:28:37 +00002919 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002920 * (15:14) are 11b until the commit has completed.
2921 * This will allow us to write 10b which indicates the
2922 * signature is valid. We want to do this after the write
2923 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002924 * while the write is still in progress
2925 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002926 if (i == E1000_ICH_NVM_SIG_WORD)
2927 data |= E1000_ICH_NVM_SIG_MASK;
2928
2929 /* Convert offset to bytes. */
2930 act_offset = (i + new_bank_offset) << 1;
2931
2932 udelay(100);
2933 /* Write the bytes to the new bank. */
2934 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2935 act_offset,
2936 (u8)data);
2937 if (ret_val)
2938 break;
2939
2940 udelay(100);
2941 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2942 act_offset + 1,
2943 (u8)(data >> 8));
2944 if (ret_val)
2945 break;
2946 }
2947
Bruce Allane921eb12012-11-28 09:28:37 +00002948 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07002949 * programming failed.
2950 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002951 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002952 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002953 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002954 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002955 }
2956
Bruce Allane921eb12012-11-28 09:28:37 +00002957 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 * to 10b in word 0x13 , this can be done without an
2959 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002960 * and we need to change bit 14 to 0b
2961 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002962 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002963 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002964 if (ret_val)
2965 goto release;
2966
Auke Kokbc7f75f2007-09-17 12:30:59 -07002967 data &= 0xBFFF;
2968 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2969 act_offset * 2 + 1,
2970 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002971 if (ret_val)
2972 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002973
Bruce Allane921eb12012-11-28 09:28:37 +00002974 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002975 * its signature word (0x13) high_byte to 0b. This can be
2976 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002977 * to 1's. We can write 1's to 0's without an erase
2978 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002979 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2980 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002981 if (ret_val)
2982 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002983
2984 /* Great! Everything worked, we can now clear the cached entries. */
2985 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002986 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987 dev_spec->shadow_ram[i].value = 0xFFFF;
2988 }
2989
Bruce Allan9c5e2092010-05-10 15:00:31 +00002990release:
Bruce Allan94d81862009-11-20 23:25:26 +00002991 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002992
Bruce Allane921eb12012-11-28 09:28:37 +00002993 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002994 * until after the next adapter reset.
2995 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002996 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00002997 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00002998 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002999 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003000
Bruce Allane2434552008-11-21 17:02:41 -08003001out:
3002 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003003 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003004
Auke Kokbc7f75f2007-09-17 12:30:59 -07003005 return ret_val;
3006}
3007
3008/**
3009 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3010 * @hw: pointer to the HW structure
3011 *
3012 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3013 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3014 * calculated, in which case we need to calculate the checksum and set bit 6.
3015 **/
3016static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3017{
3018 s32 ret_val;
3019 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003020 u16 word;
3021 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003022
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003023 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3024 * the checksum needs to be fixed. This bit is an indication that
3025 * the NVM was prepared by OEM software and did not calculate
3026 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003027 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003028 switch (hw->mac.type) {
3029 case e1000_pch_lpt:
3030 word = NVM_COMPAT;
3031 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3032 break;
3033 default:
3034 word = NVM_FUTURE_INIT_WORD1;
3035 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3036 break;
3037 }
3038
3039 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003040 if (ret_val)
3041 return ret_val;
3042
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003043 if (!(data & valid_csum_mask)) {
3044 data |= valid_csum_mask;
3045 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003046 if (ret_val)
3047 return ret_val;
3048 ret_val = e1000e_update_nvm_checksum(hw);
3049 if (ret_val)
3050 return ret_val;
3051 }
3052
3053 return e1000e_validate_nvm_checksum_generic(hw);
3054}
3055
3056/**
Bruce Allan4a770352008-10-01 17:18:35 -07003057 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3058 * @hw: pointer to the HW structure
3059 *
3060 * To prevent malicious write/erase of the NVM, set it to be read-only
3061 * so that the hardware ignores all write/erase cycles of the NVM via
3062 * the flash control registers. The shadow-ram copy of the NVM will
3063 * still be updated, however any updates to this copy will not stick
3064 * across driver reloads.
3065 **/
3066void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3067{
Bruce Allanca15df52009-10-26 11:23:43 +00003068 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003069 union ich8_flash_protected_range pr0;
3070 union ich8_hws_flash_status hsfsts;
3071 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003072
Bruce Allan94d81862009-11-20 23:25:26 +00003073 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003074
3075 gfpreg = er32flash(ICH_FLASH_GFPREG);
3076
3077 /* Write-protect GbE Sector of NVM */
3078 pr0.regval = er32flash(ICH_FLASH_PR0);
3079 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3080 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3081 pr0.range.wpe = true;
3082 ew32flash(ICH_FLASH_PR0, pr0.regval);
3083
Bruce Allane921eb12012-11-28 09:28:37 +00003084 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003085 * PR0 to prevent the write-protection from being lifted.
3086 * Once FLOCKDN is set, the registers protected by it cannot
3087 * be written until FLOCKDN is cleared by a hardware reset.
3088 */
3089 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3090 hsfsts.hsf_status.flockdn = true;
3091 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3092
Bruce Allan94d81862009-11-20 23:25:26 +00003093 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003094}
3095
3096/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003097 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3098 * @hw: pointer to the HW structure
3099 * @offset: The offset (in bytes) of the byte/word to read.
3100 * @size: Size of data to read, 1=byte 2=word
3101 * @data: The byte(s) to write to the NVM.
3102 *
3103 * Writes one/two bytes to the NVM using the flash access registers.
3104 **/
3105static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3106 u8 size, u16 data)
3107{
3108 union ich8_hws_flash_status hsfsts;
3109 union ich8_hws_flash_ctrl hsflctl;
3110 u32 flash_linear_addr;
3111 u32 flash_data = 0;
3112 s32 ret_val;
3113 u8 count = 0;
3114
3115 if (size < 1 || size > 2 || data > size * 0xff ||
3116 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3117 return -E1000_ERR_NVM;
3118
3119 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3120 hw->nvm.flash_base_addr;
3121
3122 do {
3123 udelay(1);
3124 /* Steps */
3125 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3126 if (ret_val)
3127 break;
3128
3129 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3130 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
3131 hsflctl.hsf_ctrl.fldbcount = size -1;
3132 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3133 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3134
3135 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3136
3137 if (size == 1)
3138 flash_data = (u32)data & 0x00FF;
3139 else
3140 flash_data = (u32)data;
3141
3142 ew32flash(ICH_FLASH_FDATA0, flash_data);
3143
Bruce Allane921eb12012-11-28 09:28:37 +00003144 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003145 * and try the whole sequence a few more times else done
3146 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003147 ret_val = e1000_flash_cycle_ich8lan(hw,
3148 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
3149 if (!ret_val)
3150 break;
3151
Bruce Allane921eb12012-11-28 09:28:37 +00003152 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003153 * completely hosed, but if the error condition
3154 * is detected, it won't hurt to give it another
3155 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3156 */
3157 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003158 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003159 /* Repeat for some time before giving up. */
3160 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003161 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003162 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003163 break;
3164 }
3165 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3166
3167 return ret_val;
3168}
3169
3170/**
3171 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3172 * @hw: pointer to the HW structure
3173 * @offset: The index of the byte to read.
3174 * @data: The byte to write to the NVM.
3175 *
3176 * Writes a single byte to the NVM using the flash access registers.
3177 **/
3178static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3179 u8 data)
3180{
3181 u16 word = (u16)data;
3182
3183 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3184}
3185
3186/**
3187 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3188 * @hw: pointer to the HW structure
3189 * @offset: The offset of the byte to write.
3190 * @byte: The byte to write to the NVM.
3191 *
3192 * Writes a single byte to the NVM using the flash access registers.
3193 * Goes through a retry algorithm before giving up.
3194 **/
3195static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3196 u32 offset, u8 byte)
3197{
3198 s32 ret_val;
3199 u16 program_retries;
3200
3201 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3202 if (!ret_val)
3203 return ret_val;
3204
3205 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003206 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003207 udelay(100);
3208 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3209 if (!ret_val)
3210 break;
3211 }
3212 if (program_retries == 100)
3213 return -E1000_ERR_NVM;
3214
3215 return 0;
3216}
3217
3218/**
3219 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3220 * @hw: pointer to the HW structure
3221 * @bank: 0 for first bank, 1 for second bank, etc.
3222 *
3223 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3224 * bank N is 4096 * N + flash_reg_addr.
3225 **/
3226static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3227{
3228 struct e1000_nvm_info *nvm = &hw->nvm;
3229 union ich8_hws_flash_status hsfsts;
3230 union ich8_hws_flash_ctrl hsflctl;
3231 u32 flash_linear_addr;
3232 /* bank size is in 16bit words - adjust to bytes */
3233 u32 flash_bank_size = nvm->flash_bank_size * 2;
3234 s32 ret_val;
3235 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003236 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003237
3238 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3239
Bruce Allane921eb12012-11-28 09:28:37 +00003240 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003241 * register
3242 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003243 * consecutive sectors. The start index for the nth Hw sector
3244 * can be calculated as = bank * 4096 + n * 256
3245 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3246 * The start index for the nth Hw sector can be calculated
3247 * as = bank * 4096
3248 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3249 * (ich9 only, otherwise error condition)
3250 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3251 */
3252 switch (hsfsts.hsf_status.berasesz) {
3253 case 0:
3254 /* Hw sector size 256 */
3255 sector_size = ICH_FLASH_SEG_SIZE_256;
3256 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3257 break;
3258 case 1:
3259 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003260 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003261 break;
3262 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003263 sector_size = ICH_FLASH_SEG_SIZE_8K;
3264 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003265 break;
3266 case 3:
3267 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003268 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003269 break;
3270 default:
3271 return -E1000_ERR_NVM;
3272 }
3273
3274 /* Start with the base address, then add the sector offset. */
3275 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003276 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003277
3278 for (j = 0; j < iteration ; j++) {
3279 do {
3280 /* Steps */
3281 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3282 if (ret_val)
3283 return ret_val;
3284
Bruce Allane921eb12012-11-28 09:28:37 +00003285 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003286 * Cycle field in hw flash control
3287 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003288 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3289 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3290 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3291
Bruce Allane921eb12012-11-28 09:28:37 +00003292 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003293 * block into Flash Linear address field in Flash
3294 * Address.
3295 */
3296 flash_linear_addr += (j * sector_size);
3297 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3298
3299 ret_val = e1000_flash_cycle_ich8lan(hw,
3300 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003301 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302 break;
3303
Bruce Allane921eb12012-11-28 09:28:37 +00003304 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003305 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003306 * a few more times else Done
3307 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003308 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003309 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003310 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003311 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003312 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003313 return ret_val;
3314 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3315 }
3316
3317 return 0;
3318}
3319
3320/**
3321 * e1000_valid_led_default_ich8lan - Set the default LED settings
3322 * @hw: pointer to the HW structure
3323 * @data: Pointer to the LED settings
3324 *
3325 * Reads the LED default settings from the NVM to data. If the NVM LED
3326 * settings is all 0's or F's, set the LED default to a valid LED default
3327 * setting.
3328 **/
3329static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3330{
3331 s32 ret_val;
3332
3333 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3334 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003335 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003336 return ret_val;
3337 }
3338
3339 if (*data == ID_LED_RESERVED_0000 ||
3340 *data == ID_LED_RESERVED_FFFF)
3341 *data = ID_LED_DEFAULT_ICH8LAN;
3342
3343 return 0;
3344}
3345
3346/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003347 * e1000_id_led_init_pchlan - store LED configurations
3348 * @hw: pointer to the HW structure
3349 *
3350 * PCH does not control LEDs via the LEDCTL register, rather it uses
3351 * the PHY LED configuration register.
3352 *
3353 * PCH also does not have an "always on" or "always off" mode which
3354 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003355 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003356 * use "link_up" mode. The LEDs will still ID on request if there is no
3357 * link based on logic in e1000_led_[on|off]_pchlan().
3358 **/
3359static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3360{
3361 struct e1000_mac_info *mac = &hw->mac;
3362 s32 ret_val;
3363 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3364 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3365 u16 data, i, temp, shift;
3366
3367 /* Get default ID LED modes */
3368 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3369 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003370 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003371
3372 mac->ledctl_default = er32(LEDCTL);
3373 mac->ledctl_mode1 = mac->ledctl_default;
3374 mac->ledctl_mode2 = mac->ledctl_default;
3375
3376 for (i = 0; i < 4; i++) {
3377 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3378 shift = (i * 5);
3379 switch (temp) {
3380 case ID_LED_ON1_DEF2:
3381 case ID_LED_ON1_ON2:
3382 case ID_LED_ON1_OFF2:
3383 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3384 mac->ledctl_mode1 |= (ledctl_on << shift);
3385 break;
3386 case ID_LED_OFF1_DEF2:
3387 case ID_LED_OFF1_ON2:
3388 case ID_LED_OFF1_OFF2:
3389 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3390 mac->ledctl_mode1 |= (ledctl_off << shift);
3391 break;
3392 default:
3393 /* Do nothing */
3394 break;
3395 }
3396 switch (temp) {
3397 case ID_LED_DEF1_ON2:
3398 case ID_LED_ON1_ON2:
3399 case ID_LED_OFF1_ON2:
3400 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3401 mac->ledctl_mode2 |= (ledctl_on << shift);
3402 break;
3403 case ID_LED_DEF1_OFF2:
3404 case ID_LED_ON1_OFF2:
3405 case ID_LED_OFF1_OFF2:
3406 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3407 mac->ledctl_mode2 |= (ledctl_off << shift);
3408 break;
3409 default:
3410 /* Do nothing */
3411 break;
3412 }
3413 }
3414
Bruce Allan5015e532012-02-08 02:55:56 +00003415 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003416}
3417
3418/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003419 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3420 * @hw: pointer to the HW structure
3421 *
3422 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3423 * register, so the the bus width is hard coded.
3424 **/
3425static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3426{
3427 struct e1000_bus_info *bus = &hw->bus;
3428 s32 ret_val;
3429
3430 ret_val = e1000e_get_bus_info_pcie(hw);
3431
Bruce Allane921eb12012-11-28 09:28:37 +00003432 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003433 * a configuration space, but do not contain
3434 * PCI Express Capability registers, so bus width
3435 * must be hardcoded.
3436 */
3437 if (bus->width == e1000_bus_width_unknown)
3438 bus->width = e1000_bus_width_pcie_x1;
3439
3440 return ret_val;
3441}
3442
3443/**
3444 * e1000_reset_hw_ich8lan - Reset the hardware
3445 * @hw: pointer to the HW structure
3446 *
3447 * Does a full reset of the hardware which includes a reset of the PHY and
3448 * MAC.
3449 **/
3450static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3451{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003452 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003453 u16 kum_cfg;
3454 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003455 s32 ret_val;
3456
Bruce Allane921eb12012-11-28 09:28:37 +00003457 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003458 * on the last TLP read/write transaction when MAC is reset.
3459 */
3460 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003461 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003462 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003463
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003464 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003465 ew32(IMC, 0xffffffff);
3466
Bruce Allane921eb12012-11-28 09:28:37 +00003467 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003468 * any pending transactions to complete before we hit the MAC
3469 * with the global reset.
3470 */
3471 ew32(RCTL, 0);
3472 ew32(TCTL, E1000_TCTL_PSP);
3473 e1e_flush();
3474
Bruce Allan1bba4382011-03-19 00:27:20 +00003475 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003476
3477 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3478 if (hw->mac.type == e1000_ich8lan) {
3479 /* Set Tx and Rx buffer allocation to 8k apiece. */
3480 ew32(PBA, E1000_PBA_8K);
3481 /* Set Packet Buffer Size to 16k. */
3482 ew32(PBS, E1000_PBS_16K);
3483 }
3484
Bruce Allan1d5846b2009-10-29 13:46:05 +00003485 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003486 /* Save the NVM K1 bit setting */
3487 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003488 if (ret_val)
3489 return ret_val;
3490
Bruce Allan62bc8132012-03-20 03:47:57 +00003491 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003492 dev_spec->nvm_k1_enabled = true;
3493 else
3494 dev_spec->nvm_k1_enabled = false;
3495 }
3496
Auke Kokbc7f75f2007-09-17 12:30:59 -07003497 ctrl = er32(CTRL);
3498
Bruce Allan44abd5c2012-02-22 09:02:37 +00003499 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003500 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003501 * time to make sure the interface between MAC and the
3502 * external PHY is reset.
3503 */
3504 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003505
Bruce Allane921eb12012-11-28 09:28:37 +00003506 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003507 * non-managed 82579
3508 */
3509 if ((hw->mac.type == e1000_pch2lan) &&
3510 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3511 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003512 }
3513 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003514 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003515 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003516 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003517 msleep(20);
3518
Bruce Allan62bc8132012-03-20 03:47:57 +00003519 /* Set Phy Config Counter to 50msec */
3520 if (hw->mac.type == e1000_pch2lan) {
3521 reg = er32(FEXTNVM3);
3522 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3523 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3524 ew32(FEXTNVM3, reg);
3525 }
3526
Bruce Allanfc0c7762009-07-01 13:27:55 +00003527 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003528 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003529
Bruce Allane98cac42010-05-10 15:02:32 +00003530 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003531 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003532 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003533 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003534
Bruce Allane98cac42010-05-10 15:02:32 +00003535 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003536 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003537 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003538 }
Bruce Allane98cac42010-05-10 15:02:32 +00003539
Bruce Allane921eb12012-11-28 09:28:37 +00003540 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003541 * will be detected as a CRC error and be dropped rather than show up
3542 * as a bad packet to the DMA engine.
3543 */
3544 if (hw->mac.type == e1000_pchlan)
3545 ew32(CRC_OFFSET, 0x65656565);
3546
Auke Kokbc7f75f2007-09-17 12:30:59 -07003547 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003548 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003549
Bruce Allan62bc8132012-03-20 03:47:57 +00003550 reg = er32(KABGTXD);
3551 reg |= E1000_KABGTXD_BGSQLBIAS;
3552 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003553
Bruce Allan5015e532012-02-08 02:55:56 +00003554 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003555}
3556
3557/**
3558 * e1000_init_hw_ich8lan - Initialize the hardware
3559 * @hw: pointer to the HW structure
3560 *
3561 * Prepares the hardware for transmit and receive by doing the following:
3562 * - initialize hardware bits
3563 * - initialize LED identification
3564 * - setup receive address registers
3565 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003566 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003567 * - clear statistics
3568 **/
3569static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3570{
3571 struct e1000_mac_info *mac = &hw->mac;
3572 u32 ctrl_ext, txdctl, snoop;
3573 s32 ret_val;
3574 u16 i;
3575
3576 e1000_initialize_hw_bits_ich8lan(hw);
3577
3578 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003579 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00003580 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003581 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00003582 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003583
3584 /* Setup the receive address. */
3585 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3586
3587 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003588 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003589 for (i = 0; i < mac->mta_reg_count; i++)
3590 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3591
Bruce Allane921eb12012-11-28 09:28:37 +00003592 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003593 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003594 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3595 */
3596 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003597 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3598 i &= ~BM_WUC_HOST_WU_BIT;
3599 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003600 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3601 if (ret_val)
3602 return ret_val;
3603 }
3604
Auke Kokbc7f75f2007-09-17 12:30:59 -07003605 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003606 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003607
3608 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003609 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003610 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3611 E1000_TXDCTL_FULL_TX_DESC_WB;
3612 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3613 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003614 ew32(TXDCTL(0), txdctl);
3615 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003616 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3617 E1000_TXDCTL_FULL_TX_DESC_WB;
3618 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3619 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003620 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003621
Bruce Allane921eb12012-11-28 09:28:37 +00003622 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003623 * By default, we should use snoop behavior.
3624 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003625 if (mac->type == e1000_ich8lan)
3626 snoop = PCIE_ICH8_SNOOP_ALL;
3627 else
3628 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
3629 e1000e_set_pcie_no_snoop(hw, snoop);
3630
3631 ctrl_ext = er32(CTRL_EXT);
3632 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3633 ew32(CTRL_EXT, ctrl_ext);
3634
Bruce Allane921eb12012-11-28 09:28:37 +00003635 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003636 * important that we do this after we have tried to establish link
3637 * because the symbol error count will increment wildly if there
3638 * is no link.
3639 */
3640 e1000_clear_hw_cntrs_ich8lan(hw);
3641
Bruce Allane561a702012-02-08 02:55:46 +00003642 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003643}
3644/**
3645 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3646 * @hw: pointer to the HW structure
3647 *
3648 * Sets/Clears required hardware bits necessary for correctly setting up the
3649 * hardware for transmit and receive.
3650 **/
3651static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3652{
3653 u32 reg;
3654
3655 /* Extended Device Control */
3656 reg = er32(CTRL_EXT);
3657 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003658 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3659 if (hw->mac.type >= e1000_pchlan)
3660 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003661 ew32(CTRL_EXT, reg);
3662
3663 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003664 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003665 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003666 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003667
3668 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003669 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003670 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003671 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003672
3673 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003674 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003675 if (hw->mac.type == e1000_ich8lan)
3676 reg |= (1 << 28) | (1 << 29);
3677 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003678 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003679
3680 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003681 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682 if (er32(TCTL) & E1000_TCTL_MULR)
3683 reg &= ~(1 << 28);
3684 else
3685 reg |= (1 << 28);
3686 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003687 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003688
3689 /* Device Status */
3690 if (hw->mac.type == e1000_ich8lan) {
3691 reg = er32(STATUS);
3692 reg &= ~(1 << 31);
3693 ew32(STATUS, reg);
3694 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003695
Bruce Allane921eb12012-11-28 09:28:37 +00003696 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003697 * traffic, just disable the nfs filtering capability
3698 */
3699 reg = er32(RFCTL);
3700 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003701
Bruce Allane921eb12012-11-28 09:28:37 +00003702 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003703 * IPv6 headers can hang the Rx.
3704 */
3705 if (hw->mac.type == e1000_ich8lan)
3706 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003707 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00003708
3709 /* Enable ECC on Lynxpoint */
3710 if (hw->mac.type == e1000_pch_lpt) {
3711 reg = er32(PBECCSTS);
3712 reg |= E1000_PBECCSTS_ECC_ENABLE;
3713 ew32(PBECCSTS, reg);
3714
3715 reg = er32(CTRL);
3716 reg |= E1000_CTRL_MEHE;
3717 ew32(CTRL, reg);
3718 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003719}
3720
3721/**
3722 * e1000_setup_link_ich8lan - Setup flow control and link settings
3723 * @hw: pointer to the HW structure
3724 *
3725 * Determines which flow control settings to use, then configures flow
3726 * control. Calls the appropriate media-specific link configuration
3727 * function. Assuming the adapter has a valid link partner, a valid link
3728 * should be established. Assumes the hardware has previously been reset
3729 * and the transmitter and receiver are not enabled.
3730 **/
3731static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3732{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003733 s32 ret_val;
3734
Bruce Allan44abd5c2012-02-22 09:02:37 +00003735 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003736 return 0;
3737
Bruce Allane921eb12012-11-28 09:28:37 +00003738 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003739 * the default flow control setting, so we explicitly
3740 * set it to full.
3741 */
Bruce Allan37289d92009-06-02 11:29:37 +00003742 if (hw->fc.requested_mode == e1000_fc_default) {
3743 /* Workaround h/w hang when Tx flow control enabled */
3744 if (hw->mac.type == e1000_pchlan)
3745 hw->fc.requested_mode = e1000_fc_rx_pause;
3746 else
3747 hw->fc.requested_mode = e1000_fc_full;
3748 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003749
Bruce Allane921eb12012-11-28 09:28:37 +00003750 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003751 * on the link partner's capabilities, we may or may not use this mode.
3752 */
3753 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003754
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003755 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003756 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003757
3758 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003759 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003760 if (ret_val)
3761 return ret_val;
3762
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003763 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003764 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003765 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003766 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003767 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003768 ew32(FCRTV_PCH, hw->fc.refresh_time);
3769
Bruce Allan482fed82011-01-06 14:29:49 +00003770 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3771 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003772 if (ret_val)
3773 return ret_val;
3774 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003775
3776 return e1000e_set_fc_watermarks(hw);
3777}
3778
3779/**
3780 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3781 * @hw: pointer to the HW structure
3782 *
3783 * Configures the kumeran interface to the PHY to wait the appropriate time
3784 * when polling the PHY, then call the generic setup_copper_link to finish
3785 * configuring the copper link.
3786 **/
3787static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3788{
3789 u32 ctrl;
3790 s32 ret_val;
3791 u16 reg_data;
3792
3793 ctrl = er32(CTRL);
3794 ctrl |= E1000_CTRL_SLU;
3795 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3796 ew32(CTRL, ctrl);
3797
Bruce Allane921eb12012-11-28 09:28:37 +00003798 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003799 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003800 * this fixes erroneous timeouts at 10Mbps.
3801 */
Bruce Allan07818952009-12-08 07:28:01 +00003802 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003803 if (ret_val)
3804 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003805 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3806 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003807 if (ret_val)
3808 return ret_val;
3809 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003810 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3811 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003812 if (ret_val)
3813 return ret_val;
3814
Bruce Allana4f58f52009-06-02 11:29:18 +00003815 switch (hw->phy.type) {
3816 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003817 ret_val = e1000e_copper_link_setup_igp(hw);
3818 if (ret_val)
3819 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003820 break;
3821 case e1000_phy_bm:
3822 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003823 ret_val = e1000e_copper_link_setup_m88(hw);
3824 if (ret_val)
3825 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003826 break;
3827 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003828 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003829 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +00003830 ret_val = e1000_copper_link_setup_82577(hw);
3831 if (ret_val)
3832 return ret_val;
3833 break;
3834 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003835 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003836 if (ret_val)
3837 return ret_val;
3838
3839 reg_data &= ~IFE_PMC_AUTO_MDIX;
3840
3841 switch (hw->phy.mdix) {
3842 case 1:
3843 reg_data &= ~IFE_PMC_FORCE_MDIX;
3844 break;
3845 case 2:
3846 reg_data |= IFE_PMC_FORCE_MDIX;
3847 break;
3848 case 0:
3849 default:
3850 reg_data |= IFE_PMC_AUTO_MDIX;
3851 break;
3852 }
Bruce Allan482fed82011-01-06 14:29:49 +00003853 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003854 if (ret_val)
3855 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003856 break;
3857 default:
3858 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003859 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003860
Auke Kokbc7f75f2007-09-17 12:30:59 -07003861 return e1000e_setup_copper_link(hw);
3862}
3863
3864/**
3865 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3866 * @hw: pointer to the HW structure
3867 * @speed: pointer to store current link speed
3868 * @duplex: pointer to store the current link duplex
3869 *
Bruce Allanad680762008-03-28 09:15:03 -07003870 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003871 * information and then calls the Kumeran lock loss workaround for links at
3872 * gigabit speeds.
3873 **/
3874static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3875 u16 *duplex)
3876{
3877 s32 ret_val;
3878
3879 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3880 if (ret_val)
3881 return ret_val;
3882
3883 if ((hw->mac.type == e1000_ich8lan) &&
3884 (hw->phy.type == e1000_phy_igp_3) &&
3885 (*speed == SPEED_1000)) {
3886 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3887 }
3888
3889 return ret_val;
3890}
3891
3892/**
3893 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3894 * @hw: pointer to the HW structure
3895 *
3896 * Work-around for 82566 Kumeran PCS lock loss:
3897 * On link status change (i.e. PCI reset, speed change) and link is up and
3898 * speed is gigabit-
3899 * 0) if workaround is optionally disabled do nothing
3900 * 1) wait 1ms for Kumeran link to come up
3901 * 2) check Kumeran Diagnostic register PCS lock loss bit
3902 * 3) if not set the link is locked (all is good), otherwise...
3903 * 4) reset the PHY
3904 * 5) repeat up to 10 times
3905 * Note: this is only called for IGP3 copper when speed is 1gb.
3906 **/
3907static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3908{
3909 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3910 u32 phy_ctrl;
3911 s32 ret_val;
3912 u16 i, data;
3913 bool link;
3914
3915 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3916 return 0;
3917
Bruce Allane921eb12012-11-28 09:28:37 +00003918 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003919 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003920 * stability
3921 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003922 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3923 if (!link)
3924 return 0;
3925
3926 for (i = 0; i < 10; i++) {
3927 /* read once to clear */
3928 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3929 if (ret_val)
3930 return ret_val;
3931 /* and again to get new status */
3932 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3933 if (ret_val)
3934 return ret_val;
3935
3936 /* check for PCS lock */
3937 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3938 return 0;
3939
3940 /* Issue PHY reset */
3941 e1000_phy_hw_reset(hw);
3942 mdelay(5);
3943 }
3944 /* Disable GigE link negotiation */
3945 phy_ctrl = er32(PHY_CTRL);
3946 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3947 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3948 ew32(PHY_CTRL, phy_ctrl);
3949
Bruce Allane921eb12012-11-28 09:28:37 +00003950 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07003951 * any PHY registers
3952 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003953 e1000e_gig_downshift_workaround_ich8lan(hw);
3954
3955 /* unable to acquire PCS lock */
3956 return -E1000_ERR_PHY;
3957}
3958
3959/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00003960 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003961 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003962 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003963 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003964 * If ICH8, set the current Kumeran workaround state (enabled - true
3965 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003966 **/
3967void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3968 bool state)
3969{
3970 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3971
3972 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003973 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003974 return;
3975 }
3976
3977 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3978}
3979
3980/**
3981 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3982 * @hw: pointer to the HW structure
3983 *
3984 * Workaround for 82566 power-down on D3 entry:
3985 * 1) disable gigabit link
3986 * 2) write VR power-down enable
3987 * 3) read it back
3988 * Continue if successful, else issue LCD reset and repeat
3989 **/
3990void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3991{
3992 u32 reg;
3993 u16 data;
3994 u8 retry = 0;
3995
3996 if (hw->phy.type != e1000_phy_igp_3)
3997 return;
3998
3999 /* Try the workaround twice (if needed) */
4000 do {
4001 /* Disable link */
4002 reg = er32(PHY_CTRL);
4003 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4004 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4005 ew32(PHY_CTRL, reg);
4006
Bruce Allane921eb12012-11-28 09:28:37 +00004007 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07004008 * accessing any PHY registers
4009 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004010 if (hw->mac.type == e1000_ich8lan)
4011 e1000e_gig_downshift_workaround_ich8lan(hw);
4012
4013 /* Write VR power-down enable */
4014 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4015 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4016 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4017
4018 /* Read it back and test */
4019 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4020 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4021 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4022 break;
4023
4024 /* Issue PHY reset and repeat at most one more time */
4025 reg = er32(CTRL);
4026 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4027 retry++;
4028 } while (retry);
4029}
4030
4031/**
4032 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4033 * @hw: pointer to the HW structure
4034 *
4035 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004036 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004037 * 1) Set Kumeran Near-end loopback
4038 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004039 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004040 **/
4041void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4042{
4043 s32 ret_val;
4044 u16 reg_data;
4045
Bruce Allan462d5992011-09-30 08:07:11 +00004046 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004047 return;
4048
4049 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4050 &reg_data);
4051 if (ret_val)
4052 return;
4053 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4054 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4055 reg_data);
4056 if (ret_val)
4057 return;
4058 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
4059 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4060 reg_data);
4061}
4062
4063/**
Bruce Allan99730e42011-05-13 07:19:48 +00004064 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004065 * @hw: pointer to the HW structure
4066 *
4067 * During S0 to Sx transition, it is possible the link remains at gig
4068 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004069 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4070 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4071 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4072 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004073 * Parts that support (and are linked to a partner which support) EEE in
4074 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4075 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004076 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004077void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004078{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004079 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004080 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004081 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004082
Bruce Allan17f085d2010-06-17 18:59:48 +00004083 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004084 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004085 if (hw->phy.type == e1000_phy_i217) {
4086 u16 phy_reg;
4087
4088 ret_val = hw->phy.ops.acquire(hw);
4089 if (ret_val)
4090 goto out;
4091
4092 if (!dev_spec->eee_disable) {
4093 u16 eee_advert;
4094
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004095 ret_val =
4096 e1000_read_emi_reg_locked(hw,
4097 I217_EEE_ADVERTISEMENT,
4098 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004099 if (ret_val)
4100 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004101
Bruce Allane921eb12012-11-28 09:28:37 +00004102 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004103 * EEE and 100Full is advertised on both ends of the
4104 * link.
4105 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004106 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004107 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004108 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004109 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4110 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4111 E1000_PHY_CTRL_NOND0A_LPLU);
4112 }
4113
Bruce Allane921eb12012-11-28 09:28:37 +00004114 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004115 * when the system is going into Sx and no manageability engine
4116 * is present, the driver must configure proxy to reset only on
4117 * power good. LPI (Low Power Idle) state must also reset only
4118 * on power good, as well as the MTA (Multicast table array).
4119 * The SMBus release must also be disabled on LCD reset.
4120 */
4121 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
4122
4123 /* Enable proxy to reset only on power good. */
4124 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4125 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4126 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4127
Bruce Allane921eb12012-11-28 09:28:37 +00004128 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004129 * power good.
4130 */
4131 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004132 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004133 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4134
4135 /* Disable the SMB release on LCD reset. */
4136 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004137 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004138 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4139 }
4140
Bruce Allane921eb12012-11-28 09:28:37 +00004141 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004142 * Support
4143 */
4144 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004145 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004146 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4147
4148release:
4149 hw->phy.ops.release(hw);
4150 }
4151out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004152 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004153
Bruce Allan462d5992011-09-30 08:07:11 +00004154 if (hw->mac.type == e1000_ich8lan)
4155 e1000e_gig_downshift_workaround_ich8lan(hw);
4156
Bruce Allan8395ae82010-09-22 17:15:08 +00004157 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004158 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004159
4160 /* Reset PHY to activate OEM bits on 82577/8 */
4161 if (hw->mac.type == e1000_pchlan)
4162 e1000e_phy_hw_reset_generic(hw);
4163
Bruce Allan8395ae82010-09-22 17:15:08 +00004164 ret_val = hw->phy.ops.acquire(hw);
4165 if (ret_val)
4166 return;
4167 e1000_write_smbus_addr(hw);
4168 hw->phy.ops.release(hw);
4169 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004170}
4171
4172/**
Bruce Allan99730e42011-05-13 07:19:48 +00004173 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4174 * @hw: pointer to the HW structure
4175 *
4176 * During Sx to S0 transitions on non-managed devices or managed devices
4177 * on which PHY resets are not blocked, if the PHY registers cannot be
4178 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4179 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004180 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004181 **/
4182void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4183{
Bruce Allan90b82982011-12-16 00:46:33 +00004184 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004185
Bruce Allancb17aab2012-04-13 03:16:22 +00004186 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004187 return;
4188
Bruce Allancb17aab2012-04-13 03:16:22 +00004189 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004190 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004191 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004192 return;
4193 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004194
Bruce Allane921eb12012-11-28 09:28:37 +00004195 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004196 * is transitioning from Sx and no manageability engine is present
4197 * configure SMBus to restore on reset, disable proxy, and enable
4198 * the reset on MTA (Multicast table array).
4199 */
4200 if (hw->phy.type == e1000_phy_i217) {
4201 u16 phy_reg;
4202
4203 ret_val = hw->phy.ops.acquire(hw);
4204 if (ret_val) {
4205 e_dbg("Failed to setup iRST\n");
4206 return;
4207 }
4208
4209 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004210 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004211 * is present
4212 */
4213 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4214 if (ret_val)
4215 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004216 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004217 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4218
4219 /* Disable Proxy */
4220 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4221 }
4222 /* Enable reset on MTA */
4223 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4224 if (ret_val)
4225 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004226 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004227 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4228release:
4229 if (ret_val)
4230 e_dbg("Error %d in resume workarounds\n", ret_val);
4231 hw->phy.ops.release(hw);
4232 }
Bruce Allan99730e42011-05-13 07:19:48 +00004233}
4234
4235/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004236 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4237 * @hw: pointer to the HW structure
4238 *
4239 * Return the LED back to the default configuration.
4240 **/
4241static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4242{
4243 if (hw->phy.type == e1000_phy_ife)
4244 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4245
4246 ew32(LEDCTL, hw->mac.ledctl_default);
4247 return 0;
4248}
4249
4250/**
Auke Kok489815c2008-02-21 15:11:07 -08004251 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004252 * @hw: pointer to the HW structure
4253 *
Auke Kok489815c2008-02-21 15:11:07 -08004254 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004255 **/
4256static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4257{
4258 if (hw->phy.type == e1000_phy_ife)
4259 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4260 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4261
4262 ew32(LEDCTL, hw->mac.ledctl_mode2);
4263 return 0;
4264}
4265
4266/**
Auke Kok489815c2008-02-21 15:11:07 -08004267 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004268 * @hw: pointer to the HW structure
4269 *
Auke Kok489815c2008-02-21 15:11:07 -08004270 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004271 **/
4272static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4273{
4274 if (hw->phy.type == e1000_phy_ife)
4275 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004276 (IFE_PSCL_PROBE_MODE |
4277 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278
4279 ew32(LEDCTL, hw->mac.ledctl_mode1);
4280 return 0;
4281}
4282
4283/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004284 * e1000_setup_led_pchlan - Configures SW controllable LED
4285 * @hw: pointer to the HW structure
4286 *
4287 * This prepares the SW controllable LED for use.
4288 **/
4289static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4290{
Bruce Allan482fed82011-01-06 14:29:49 +00004291 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004292}
4293
4294/**
4295 * e1000_cleanup_led_pchlan - Restore the default LED operation
4296 * @hw: pointer to the HW structure
4297 *
4298 * Return the LED back to the default configuration.
4299 **/
4300static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4301{
Bruce Allan482fed82011-01-06 14:29:49 +00004302 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004303}
4304
4305/**
4306 * e1000_led_on_pchlan - Turn LEDs on
4307 * @hw: pointer to the HW structure
4308 *
4309 * Turn on the LEDs.
4310 **/
4311static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4312{
4313 u16 data = (u16)hw->mac.ledctl_mode2;
4314 u32 i, led;
4315
Bruce Allane921eb12012-11-28 09:28:37 +00004316 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004317 * for each LED that's mode is "link_up" in ledctl_mode2.
4318 */
4319 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4320 for (i = 0; i < 3; i++) {
4321 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4322 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4323 E1000_LEDCTL_MODE_LINK_UP)
4324 continue;
4325 if (led & E1000_PHY_LED0_IVRT)
4326 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4327 else
4328 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4329 }
4330 }
4331
Bruce Allan482fed82011-01-06 14:29:49 +00004332 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004333}
4334
4335/**
4336 * e1000_led_off_pchlan - Turn LEDs off
4337 * @hw: pointer to the HW structure
4338 *
4339 * Turn off the LEDs.
4340 **/
4341static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4342{
4343 u16 data = (u16)hw->mac.ledctl_mode1;
4344 u32 i, led;
4345
Bruce Allane921eb12012-11-28 09:28:37 +00004346 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004347 * for each LED that's mode is "link_up" in ledctl_mode1.
4348 */
4349 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4350 for (i = 0; i < 3; i++) {
4351 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4352 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4353 E1000_LEDCTL_MODE_LINK_UP)
4354 continue;
4355 if (led & E1000_PHY_LED0_IVRT)
4356 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4357 else
4358 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4359 }
4360 }
4361
Bruce Allan482fed82011-01-06 14:29:49 +00004362 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004363}
4364
4365/**
Bruce Allane98cac42010-05-10 15:02:32 +00004366 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004367 * @hw: pointer to the HW structure
4368 *
Bruce Allane98cac42010-05-10 15:02:32 +00004369 * Read appropriate register for the config done bit for completion status
4370 * and configure the PHY through s/w for EEPROM-less parts.
4371 *
4372 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4373 * config done bit, so only an error is logged and continues. If we were
4374 * to return with error, EEPROM-less silicon would not be able to be reset
4375 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004376 **/
4377static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4378{
Bruce Allane98cac42010-05-10 15:02:32 +00004379 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004380 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004381 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004382
Bruce Allanf4187b52008-08-26 18:36:50 -07004383 e1000e_get_cfg_done(hw);
4384
Bruce Allane98cac42010-05-10 15:02:32 +00004385 /* Wait for indication from h/w that it has completed basic config */
4386 if (hw->mac.type >= e1000_ich10lan) {
4387 e1000_lan_init_done_ich8lan(hw);
4388 } else {
4389 ret_val = e1000e_get_auto_rd_done(hw);
4390 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004391 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004392 * return with an error. This can happen in situations
4393 * where there is no eeprom and prevents getting link.
4394 */
4395 e_dbg("Auto Read Done did not complete\n");
4396 ret_val = 0;
4397 }
4398 }
4399
4400 /* Clear PHY Reset Asserted bit */
4401 status = er32(STATUS);
4402 if (status & E1000_STATUS_PHYRA)
4403 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4404 else
4405 e_dbg("PHY Reset Asserted not set - needs delay\n");
4406
Bruce Allanf4187b52008-08-26 18:36:50 -07004407 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004408 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004409 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004410 (hw->phy.type == e1000_phy_igp_3)) {
4411 e1000e_phy_init_script_igp3(hw);
4412 }
4413 } else {
4414 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4415 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004416 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004417 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004418 }
4419 }
4420
Bruce Allane98cac42010-05-10 15:02:32 +00004421 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004422}
4423
4424/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004425 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4426 * @hw: pointer to the HW structure
4427 *
4428 * In the case of a PHY power down to save power, or to turn off link during a
4429 * driver unload, or wake on lan is not enabled, remove the link.
4430 **/
4431static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4432{
4433 /* If the management interface is not enabled, then power down */
4434 if (!(hw->mac.ops.check_mng_mode(hw) ||
4435 hw->phy.ops.check_reset_block(hw)))
4436 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004437}
4438
4439/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004440 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4441 * @hw: pointer to the HW structure
4442 *
4443 * Clears hardware counters specific to the silicon family and calls
4444 * clear_hw_cntrs_generic to clear all general purpose counters.
4445 **/
4446static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4447{
Bruce Allana4f58f52009-06-02 11:29:18 +00004448 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004449 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004450
4451 e1000e_clear_hw_cntrs_base(hw);
4452
Bruce Allan99673d92009-11-20 23:27:21 +00004453 er32(ALGNERRC);
4454 er32(RXERRC);
4455 er32(TNCRS);
4456 er32(CEXTERR);
4457 er32(TSCTC);
4458 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004459
Bruce Allan99673d92009-11-20 23:27:21 +00004460 er32(MGTPRC);
4461 er32(MGTPDC);
4462 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004463
Bruce Allan99673d92009-11-20 23:27:21 +00004464 er32(IAC);
4465 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004466
Bruce Allana4f58f52009-06-02 11:29:18 +00004467 /* Clear PHY statistics registers */
4468 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004469 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004470 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004471 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004472 ret_val = hw->phy.ops.acquire(hw);
4473 if (ret_val)
4474 return;
4475 ret_val = hw->phy.ops.set_page(hw,
4476 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4477 if (ret_val)
4478 goto release;
4479 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4480 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4481 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4482 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4483 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4484 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4485 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4486 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4487 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4488 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4489 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4490 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4491 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4492 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4493release:
4494 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004495 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004496}
4497
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004498static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004499 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004500 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004501 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004502 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4503 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004504 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004505 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004506 /* led_on dependent on mac type */
4507 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004508 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004509 .reset_hw = e1000_reset_hw_ich8lan,
4510 .init_hw = e1000_init_hw_ich8lan,
4511 .setup_link = e1000_setup_link_ich8lan,
4512 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004513 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004514 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004515 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004516};
4517
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004518static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004519 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004520 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004521 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004522 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004523 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004524 .read_reg = e1000e_read_phy_reg_igp,
4525 .release = e1000_release_swflag_ich8lan,
4526 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004527 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4528 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004529 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004530};
4531
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004532static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004533 .acquire = e1000_acquire_nvm_ich8lan,
4534 .read = e1000_read_nvm_ich8lan,
4535 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004536 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004537 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004538 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004539 .validate = e1000_validate_nvm_checksum_ich8lan,
4540 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004541};
4542
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004543const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004544 .mac = e1000_ich8lan,
4545 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004546 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004547 | FLAG_HAS_CTRLEXT_ON_LOAD
4548 | FLAG_HAS_AMT
4549 | FLAG_HAS_FLASH
4550 | FLAG_APME_IN_WUC,
4551 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004552 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004553 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004554 .mac_ops = &ich8_mac_ops,
4555 .phy_ops = &ich8_phy_ops,
4556 .nvm_ops = &ich8_nvm_ops,
4557};
4558
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004559const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004560 .mac = e1000_ich9lan,
4561 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004562 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004563 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004564 | FLAG_HAS_CTRLEXT_ON_LOAD
4565 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004566 | FLAG_HAS_FLASH
4567 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004568 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004569 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004570 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004571 .mac_ops = &ich8_mac_ops,
4572 .phy_ops = &ich8_phy_ops,
4573 .nvm_ops = &ich8_nvm_ops,
4574};
4575
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004576const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004577 .mac = e1000_ich10lan,
4578 .flags = FLAG_HAS_JUMBO_FRAMES
4579 | FLAG_IS_ICH
4580 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004581 | FLAG_HAS_CTRLEXT_ON_LOAD
4582 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004583 | FLAG_HAS_FLASH
4584 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004585 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004586 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004587 .get_variants = e1000_get_variants_ich8lan,
4588 .mac_ops = &ich8_mac_ops,
4589 .phy_ops = &ich8_phy_ops,
4590 .nvm_ops = &ich8_nvm_ops,
4591};
Bruce Allana4f58f52009-06-02 11:29:18 +00004592
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004593const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004594 .mac = e1000_pchlan,
4595 .flags = FLAG_IS_ICH
4596 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004597 | FLAG_HAS_CTRLEXT_ON_LOAD
4598 | FLAG_HAS_AMT
4599 | FLAG_HAS_FLASH
4600 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004601 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004602 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004603 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004604 .pba = 26,
4605 .max_hw_frame_size = 4096,
4606 .get_variants = e1000_get_variants_ich8lan,
4607 .mac_ops = &ich8_mac_ops,
4608 .phy_ops = &ich8_phy_ops,
4609 .nvm_ops = &ich8_nvm_ops,
4610};
Bruce Alland3738bb2010-06-16 13:27:28 +00004611
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004612const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004613 .mac = e1000_pch2lan,
4614 .flags = FLAG_IS_ICH
4615 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004616 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00004617 | FLAG_HAS_CTRLEXT_ON_LOAD
4618 | FLAG_HAS_AMT
4619 | FLAG_HAS_FLASH
4620 | FLAG_HAS_JUMBO_FRAMES
4621 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004622 .flags2 = FLAG2_HAS_PHY_STATS
4623 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004624 .pba = 26,
Bruce Alland3738bb2010-06-16 13:27:28 +00004625 .max_hw_frame_size = DEFAULT_JUMBO,
4626 .get_variants = e1000_get_variants_ich8lan,
4627 .mac_ops = &ich8_mac_ops,
4628 .phy_ops = &ich8_phy_ops,
4629 .nvm_ops = &ich8_nvm_ops,
4630};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004631
4632const struct e1000_info e1000_pch_lpt_info = {
4633 .mac = e1000_pch_lpt,
4634 .flags = FLAG_IS_ICH
4635 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004636 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00004637 | FLAG_HAS_CTRLEXT_ON_LOAD
4638 | FLAG_HAS_AMT
4639 | FLAG_HAS_FLASH
4640 | FLAG_HAS_JUMBO_FRAMES
4641 | FLAG_APME_IN_WUC,
4642 .flags2 = FLAG2_HAS_PHY_STATS
4643 | FLAG2_HAS_EEE,
4644 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00004645 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004646 .get_variants = e1000_get_variants_ich8lan,
4647 .mac_ops = &ich8_mac_ops,
4648 .phy_ops = &ich8_phy_ops,
4649 .nvm_ops = &ich8_nvm_ops,
4650};