blob: 56cbfa7981ebf6212d69de5c651bca07dccee45f [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanf5e261e2012-01-01 16:00:03 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
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
366 ret_val = hw->phy.ops.acquire(hw);
367 if (ret_val) {
368 e_dbg("Failed to initialize PHY flow\n");
369 return ret_val;
370 }
371
Bruce Allane921eb12012-11-28 09:28:37 +0000372 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000373 * inaccessible and resetting the PHY is not blocked, toggle the
374 * LANPHYPC Value bit to force the interconnect to PCIe mode.
375 */
376 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000377 case e1000_pch_lpt:
378 if (e1000_phy_is_accessible_pchlan(hw))
379 break;
380
Bruce Allane921eb12012-11-28 09:28:37 +0000381 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000382 * forcing MAC to SMBus mode first.
383 */
384 mac_reg = er32(CTRL_EXT);
385 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
386 ew32(CTRL_EXT, mac_reg);
387
388 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000389 case e1000_pch2lan:
Bruce Allane921eb12012-11-28 09:28:37 +0000390 /* Gate automatic PHY configuration by hardware on
Bruce Allancb17aab2012-04-13 03:16:22 +0000391 * non-managed 82579
392 */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000393 if ((hw->mac.type == e1000_pch2lan) &&
394 !(fwsm & E1000_ICH_FWSM_FW_VALID))
Bruce Allancb17aab2012-04-13 03:16:22 +0000395 e1000_gate_hw_phy_config_ich8lan(hw, true);
396
Bruce Allan2fbe4522012-04-19 03:21:47 +0000397 if (e1000_phy_is_accessible_pchlan(hw)) {
398 if (hw->mac.type == e1000_pch_lpt) {
399 /* Unforce SMBus mode in PHY */
400 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
401 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
402 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
403
404 /* Unforce SMBus mode in MAC */
405 mac_reg = er32(CTRL_EXT);
406 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
407 ew32(CTRL_EXT, mac_reg);
408 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000409 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000410 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000411
412 /* fall-through */
413 case e1000_pchlan:
414 if ((hw->mac.type == e1000_pchlan) &&
415 (fwsm & E1000_ICH_FWSM_FW_VALID))
416 break;
417
418 if (hw->phy.ops.check_reset_block(hw)) {
419 e_dbg("Required LANPHYPC toggle blocked by ME\n");
420 break;
421 }
422
423 e_dbg("Toggling LANPHYPC\n");
424
425 /* Set Phy Config Counter to 50msec */
426 mac_reg = er32(FEXTNVM3);
427 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
428 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
429 ew32(FEXTNVM3, mac_reg);
430
431 /* Toggle LANPHYPC Value bit */
432 mac_reg = er32(CTRL);
433 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
434 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
435 ew32(CTRL, mac_reg);
436 e1e_flush();
437 udelay(10);
438 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
439 ew32(CTRL, mac_reg);
440 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000441 if (hw->mac.type < e1000_pch_lpt) {
442 msleep(50);
443 } else {
444 u16 count = 20;
445 do {
446 usleep_range(5000, 10000);
447 } while (!(er32(CTRL_EXT) &
448 E1000_CTRL_EXT_LPCD) && count--);
449 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000450 break;
451 default:
452 break;
453 }
454
455 hw->phy.ops.release(hw);
456
Bruce Allane921eb12012-11-28 09:28:37 +0000457 /* Reset the PHY before any access to it. Doing so, ensures
Bruce Allancb17aab2012-04-13 03:16:22 +0000458 * that the PHY is in a known good state before we read/write
459 * PHY registers. The generic reset is sufficient here,
460 * because we haven't determined the PHY type yet.
461 */
462 ret_val = e1000e_phy_hw_reset_generic(hw);
463
464 /* Ungate automatic PHY configuration on non-managed 82579 */
465 if ((hw->mac.type == e1000_pch2lan) &&
466 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
467 usleep_range(10000, 20000);
468 e1000_gate_hw_phy_config_ich8lan(hw, false);
469 }
470
471 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000472}
473
Auke Kokbc7f75f2007-09-17 12:30:59 -0700474/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000475 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
476 * @hw: pointer to the HW structure
477 *
478 * Initialize family-specific PHY parameters and function pointers.
479 **/
480static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
481{
482 struct e1000_phy_info *phy = &hw->phy;
483 s32 ret_val = 0;
484
485 phy->addr = 1;
486 phy->reset_delay_us = 100;
487
Bruce Allan2b6b1682011-05-13 07:20:09 +0000488 phy->ops.set_page = e1000_set_page_igp;
Bruce Allan94d81862009-11-20 23:25:26 +0000489 phy->ops.read_reg = e1000_read_phy_reg_hv;
490 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000491 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000492 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
493 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000494 phy->ops.write_reg = e1000_write_phy_reg_hv;
495 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000496 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
Bruce Allan17f208d2009-12-01 15:47:22 +0000497 phy->ops.power_up = e1000_power_up_phy_copper;
498 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000499 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
500
501 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000502
503 ret_val = e1000_init_phy_workarounds_pchlan(hw);
504 if (ret_val)
505 return ret_val;
506
507 if (phy->id == e1000_phy_unknown)
508 switch (hw->mac.type) {
509 default:
510 ret_val = e1000e_get_phy_id(hw);
511 if (ret_val)
512 return ret_val;
513 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
514 break;
515 /* fall-through */
516 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000517 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000518 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000519 * set slow mode and try to get the PHY id again.
520 */
521 ret_val = e1000_set_mdio_slow_mode_hv(hw);
522 if (ret_val)
523 return ret_val;
524 ret_val = e1000e_get_phy_id(hw);
525 if (ret_val)
526 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000527 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000528 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000529 phy->type = e1000e_get_phy_type_from_id(phy->id);
530
Bruce Allan0be84012009-12-02 17:03:18 +0000531 switch (phy->type) {
532 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000533 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000534 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000535 phy->ops.check_polarity = e1000_check_polarity_82577;
536 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000537 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000538 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000539 phy->ops.get_info = e1000_get_phy_info_82577;
540 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000541 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000542 case e1000_phy_82578:
543 phy->ops.check_polarity = e1000_check_polarity_m88;
544 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
545 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
546 phy->ops.get_info = e1000e_get_phy_info_m88;
547 break;
548 default:
549 ret_val = -E1000_ERR_PHY;
550 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000551 }
552
553 return ret_val;
554}
555
556/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
558 * @hw: pointer to the HW structure
559 *
560 * Initialize family-specific PHY parameters and function pointers.
561 **/
562static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
563{
564 struct e1000_phy_info *phy = &hw->phy;
565 s32 ret_val;
566 u16 i = 0;
567
568 phy->addr = 1;
569 phy->reset_delay_us = 100;
570
Bruce Allan17f208d2009-12-01 15:47:22 +0000571 phy->ops.power_up = e1000_power_up_phy_copper;
572 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
573
Bruce Allane921eb12012-11-28 09:28:37 +0000574 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700575 * we'll set BM func pointers and try again
576 */
577 ret_val = e1000e_determine_phy_address(hw);
578 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000579 phy->ops.write_reg = e1000e_write_phy_reg_bm;
580 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700581 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000582 if (ret_val) {
583 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700584 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000585 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700586 }
587
Auke Kokbc7f75f2007-09-17 12:30:59 -0700588 phy->id = 0;
589 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
590 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000591 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700592 ret_val = e1000e_get_phy_id(hw);
593 if (ret_val)
594 return ret_val;
595 }
596
597 /* Verify phy id */
598 switch (phy->id) {
599 case IGP03E1000_E_PHY_ID:
600 phy->type = e1000_phy_igp_3;
601 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000602 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
603 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000604 phy->ops.get_info = e1000e_get_phy_info_igp;
605 phy->ops.check_polarity = e1000_check_polarity_igp;
606 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700607 break;
608 case IFE_E_PHY_ID:
609 case IFE_PLUS_E_PHY_ID:
610 case IFE_C_E_PHY_ID:
611 phy->type = e1000_phy_ife;
612 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000613 phy->ops.get_info = e1000_get_phy_info_ife;
614 phy->ops.check_polarity = e1000_check_polarity_ife;
615 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700616 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700617 case BME1000_E_PHY_ID:
618 phy->type = e1000_phy_bm;
619 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000620 phy->ops.read_reg = e1000e_read_phy_reg_bm;
621 phy->ops.write_reg = e1000e_write_phy_reg_bm;
622 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000623 phy->ops.get_info = e1000e_get_phy_info_m88;
624 phy->ops.check_polarity = e1000_check_polarity_m88;
625 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700626 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627 default:
628 return -E1000_ERR_PHY;
629 break;
630 }
631
632 return 0;
633}
634
635/**
636 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
637 * @hw: pointer to the HW structure
638 *
639 * Initialize family-specific NVM parameters and function
640 * pointers.
641 **/
642static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
643{
644 struct e1000_nvm_info *nvm = &hw->nvm;
645 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000646 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700647 u16 i;
648
Bruce Allanad680762008-03-28 09:15:03 -0700649 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000651 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700652 return -E1000_ERR_CONFIG;
653 }
654
655 nvm->type = e1000_nvm_flash_sw;
656
657 gfpreg = er32flash(ICH_FLASH_GFPREG);
658
Bruce Allane921eb12012-11-28 09:28:37 +0000659 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700661 * the overall size.
662 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700663 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
664 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
665
666 /* flash_base_addr is byte-aligned */
667 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
668
Bruce Allane921eb12012-11-28 09:28:37 +0000669 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700670 * size represents two separate NVM banks.
671 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700672 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
673 << FLASH_SECTOR_ADDR_SHIFT;
674 nvm->flash_bank_size /= 2;
675 /* Adjust to word count */
676 nvm->flash_bank_size /= sizeof(u16);
677
678 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
679
680 /* Clear shadow ram */
681 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000682 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700683 dev_spec->shadow_ram[i].value = 0xFFFF;
684 }
685
686 return 0;
687}
688
689/**
690 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
691 * @hw: pointer to the HW structure
692 *
693 * Initialize family-specific MAC parameters and function
694 * pointers.
695 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000696static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700697{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700698 struct e1000_mac_info *mac = &hw->mac;
699
700 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700701 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700702
703 /* Set mta register count */
704 mac->mta_reg_count = 32;
705 /* Set rar entry count */
706 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
707 if (mac->type == e1000_ich8lan)
708 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000709 /* FWSM register */
710 mac->has_fwsm = true;
711 /* ARC subsystem not supported */
712 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000713 /* Adaptive IFS supported */
714 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700715
Bruce Allan2fbe4522012-04-19 03:21:47 +0000716 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000717 switch (mac->type) {
718 case e1000_ich8lan:
719 case e1000_ich9lan:
720 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000721 /* check management mode */
722 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000723 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000724 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000725 /* blink LED */
726 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000727 /* setup LED */
728 mac->ops.setup_led = e1000e_setup_led_generic;
729 /* cleanup LED */
730 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
731 /* turn on/off LED */
732 mac->ops.led_on = e1000_led_on_ich8lan;
733 mac->ops.led_off = e1000_led_off_ich8lan;
734 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000735 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000736 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
737 mac->ops.rar_set = e1000_rar_set_pch2lan;
738 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000739 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000740 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000741 /* check management mode */
742 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000743 /* ID LED init */
744 mac->ops.id_led_init = e1000_id_led_init_pchlan;
745 /* setup LED */
746 mac->ops.setup_led = e1000_setup_led_pchlan;
747 /* cleanup LED */
748 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
749 /* turn on/off LED */
750 mac->ops.led_on = e1000_led_on_pchlan;
751 mac->ops.led_off = e1000_led_off_pchlan;
752 break;
753 default:
754 break;
755 }
756
Bruce Allan2fbe4522012-04-19 03:21:47 +0000757 if (mac->type == e1000_pch_lpt) {
758 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
759 mac->ops.rar_set = e1000_rar_set_pch_lpt;
760 }
761
Auke Kokbc7f75f2007-09-17 12:30:59 -0700762 /* Enable PCS Lock-loss workaround for ICH8 */
763 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000764 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700765
Bruce Allane921eb12012-11-28 09:28:37 +0000766 /* Gate automatic PHY configuration by hardware on managed
Bruce Allan2fbe4522012-04-19 03:21:47 +0000767 * 82579 and i217
768 */
769 if ((mac->type == e1000_pch2lan || mac->type == e1000_pch_lpt) &&
Bruce Allan605c82b2010-09-22 17:17:01 +0000770 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
771 e1000_gate_hw_phy_config_ich8lan(hw, true);
Bruce Alland3738bb2010-06-16 13:27:28 +0000772
Auke Kokbc7f75f2007-09-17 12:30:59 -0700773 return 0;
774}
775
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000776/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000777 * __e1000_access_emi_reg_locked - Read/write EMI register
778 * @hw: pointer to the HW structure
779 * @addr: EMI address to program
780 * @data: pointer to value to read/write from/to the EMI address
781 * @read: boolean flag to indicate read or write
782 *
783 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
784 **/
785static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
786 u16 *data, bool read)
787{
788 s32 ret_val = 0;
789
790 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
791 if (ret_val)
792 return ret_val;
793
794 if (read)
795 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
796 else
797 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
798
799 return ret_val;
800}
801
802/**
803 * e1000_read_emi_reg_locked - Read Extended Management Interface register
804 * @hw: pointer to the HW structure
805 * @addr: EMI address to program
806 * @data: value to be read from the EMI address
807 *
808 * Assumes the SW/FW/HW Semaphore is already acquired.
809 **/
Bruce Allan203e4152012-12-05 08:40:59 +0000810s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000811{
812 return __e1000_access_emi_reg_locked(hw, addr, data, true);
813}
814
815/**
816 * e1000_write_emi_reg_locked - Write Extended Management Interface register
817 * @hw: pointer to the HW structure
818 * @addr: EMI address to program
819 * @data: value to be written to the EMI address
820 *
821 * Assumes the SW/FW/HW Semaphore is already acquired.
822 **/
823static s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
824{
825 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
826}
827
828/**
Bruce Allane52997f2010-06-16 13:27:49 +0000829 * e1000_set_eee_pchlan - Enable/disable EEE support
830 * @hw: pointer to the HW structure
831 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000832 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
833 * the link and the EEE capabilities of the link partner. The LPI Control
834 * register bits will remain set only if/when link is up.
Bruce Allane52997f2010-06-16 13:27:49 +0000835 **/
836static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
837{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000838 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000839 s32 ret_val;
840 u16 lpi_ctrl;
Bruce Allane52997f2010-06-16 13:27:49 +0000841
Bruce Allan2fbe4522012-04-19 03:21:47 +0000842 if ((hw->phy.type != e1000_phy_82579) &&
843 (hw->phy.type != e1000_phy_i217))
Bruce Allan5015e532012-02-08 02:55:56 +0000844 return 0;
Bruce Allane52997f2010-06-16 13:27:49 +0000845
Bruce Allan3d4d5752012-12-05 06:26:08 +0000846 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000847 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000848 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000849
Bruce Allan3d4d5752012-12-05 06:26:08 +0000850 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000851 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000852 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000853
Bruce Allan3d4d5752012-12-05 06:26:08 +0000854 /* Clear bits that enable EEE in various speeds */
855 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
856
857 /* Enable EEE if not disabled by user */
858 if (!dev_spec->eee_disable) {
859 u16 lpa, pcs_status, data;
860
Bruce Allan2fbe4522012-04-19 03:21:47 +0000861 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000862 switch (hw->phy.type) {
863 case e1000_phy_82579:
864 lpa = I82579_EEE_LP_ABILITY;
865 pcs_status = I82579_EEE_PCS_STATUS;
866 break;
867 case e1000_phy_i217:
868 lpa = I217_EEE_LP_ABILITY;
869 pcs_status = I217_EEE_PCS_STATUS;
870 break;
871 default:
872 ret_val = -E1000_ERR_PHY;
873 goto release;
874 }
875 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000876 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000877 if (ret_val)
878 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000879
Bruce Allan3d4d5752012-12-05 06:26:08 +0000880 /* Enable EEE only for speeds in which the link partner is
881 * EEE capable.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000882 */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000883 if (dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
884 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
885
886 if (dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
887 e1e_rphy_locked(hw, PHY_LP_ABILITY, &data);
888 if (data & NWAY_LPAR_100TX_FD_CAPS)
889 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
890 else
891 /* EEE is not supported in 100Half, so ignore
892 * partner's EEE in 100 ability if full-duplex
893 * is not advertised.
894 */
895 dev_spec->eee_lp_ability &=
896 ~I82579_EEE_100_SUPPORTED;
897 }
898
899 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
900 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
901 if (ret_val)
902 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000903 }
904
Bruce Allan3d4d5752012-12-05 06:26:08 +0000905 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
906release:
907 hw->phy.ops.release(hw);
908
909 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000910}
911
912/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000913 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
914 * @hw: pointer to the HW structure
915 *
916 * Checks to see of the link status of the hardware has changed. If a
917 * change in link status has been detected, then we read the PHY registers
918 * to get the current speed/duplex if link exists.
919 **/
920static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
921{
922 struct e1000_mac_info *mac = &hw->mac;
923 s32 ret_val;
924 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000925 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000926
Bruce Allane921eb12012-11-28 09:28:37 +0000927 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000928 * has completed and/or if our link status has changed. The
929 * get_link_status flag is set upon receiving a Link Status
930 * Change or Rx Sequence Error interrupt.
931 */
Bruce Allan5015e532012-02-08 02:55:56 +0000932 if (!mac->get_link_status)
933 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000934
Bruce Allane921eb12012-11-28 09:28:37 +0000935 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000936 * link. If so, then we want to get the current speed/duplex
937 * of the PHY.
938 */
939 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
940 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000941 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000942
Bruce Allan1d5846b2009-10-29 13:46:05 +0000943 if (hw->mac.type == e1000_pchlan) {
944 ret_val = e1000_k1_gig_workaround_hv(hw, link);
945 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000946 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +0000947 }
948
Bruce Allan2fbe4522012-04-19 03:21:47 +0000949 /* Clear link partner's EEE ability */
950 hw->dev_spec.ich8lan.eee_lp_ability = 0;
951
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000952 if (!link)
Bruce Allan5015e532012-02-08 02:55:56 +0000953 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000954
955 mac->get_link_status = false;
956
Bruce Allan1d2101a72011-07-22 06:21:56 +0000957 switch (hw->mac.type) {
958 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +0000959 ret_val = e1000_k1_workaround_lv(hw);
960 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000961 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000962 /* fall-thru */
963 case e1000_pchlan:
964 if (hw->phy.type == e1000_phy_82578) {
965 ret_val = e1000_link_stall_workaround_hv(hw);
966 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000967 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000968 }
969
Bruce Allane921eb12012-11-28 09:28:37 +0000970 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +0000971 * Set the number of preambles removed from the packet
972 * when it is passed from the PHY to the MAC to prevent
973 * the MAC from misinterpreting the packet type.
974 */
975 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
976 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
977
978 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
979 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
980
981 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
982 break;
983 default:
984 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +0000985 }
986
Bruce Allane921eb12012-11-28 09:28:37 +0000987 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000988 * immediately after link-up
989 */
990 e1000e_check_downshift(hw);
991
Bruce Allane52997f2010-06-16 13:27:49 +0000992 /* Enable/Disable EEE after link up */
993 ret_val = e1000_set_eee_pchlan(hw);
994 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000995 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000996
Bruce Allane921eb12012-11-28 09:28:37 +0000997 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000998 * we have already determined whether we have link or not.
999 */
Bruce Allan5015e532012-02-08 02:55:56 +00001000 if (!mac->autoneg)
1001 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001002
Bruce Allane921eb12012-11-28 09:28:37 +00001003 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001004 * of MAC speed/duplex configuration. So we only need to
1005 * configure Collision Distance in the MAC.
1006 */
Bruce Allan57cde762012-02-22 09:02:58 +00001007 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001008
Bruce Allane921eb12012-11-28 09:28:37 +00001009 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001010 * First, we need to restore the desired flow control
1011 * settings because we may have had to re-autoneg with a
1012 * different link partner.
1013 */
1014 ret_val = e1000e_config_fc_after_link_up(hw);
1015 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001016 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001017
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001018 return ret_val;
1019}
1020
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001021static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001022{
1023 struct e1000_hw *hw = &adapter->hw;
1024 s32 rc;
1025
Bruce Allanec34c172012-02-01 10:53:05 +00001026 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 if (rc)
1028 return rc;
1029
1030 rc = e1000_init_nvm_params_ich8lan(hw);
1031 if (rc)
1032 return rc;
1033
Bruce Alland3738bb2010-06-16 13:27:28 +00001034 switch (hw->mac.type) {
1035 case e1000_ich8lan:
1036 case e1000_ich9lan:
1037 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001038 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001039 break;
1040 case e1000_pchlan:
1041 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001042 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001043 rc = e1000_init_phy_params_pchlan(hw);
1044 break;
1045 default:
1046 break;
1047 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001048 if (rc)
1049 return rc;
1050
Bruce Allane921eb12012-11-28 09:28:37 +00001051 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001052 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1053 */
1054 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1055 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1056 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001057 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1058 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001059
1060 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001061 }
1062
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001064 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001065 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1066
Bruce Allanc6e7f512011-07-29 05:53:02 +00001067 /* Enable workaround for 82579 w/ ME enabled */
1068 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1069 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1070 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1071
Bruce Allan5a86f282010-06-29 18:13:13 +00001072 /* Disable EEE by default until IEEE802.3az spec is finalized */
1073 if (adapter->flags2 & FLAG2_HAS_EEE)
1074 adapter->hw.dev_spec.ich8lan.eee_disable = true;
1075
Auke Kokbc7f75f2007-09-17 12:30:59 -07001076 return 0;
1077}
1078
Thomas Gleixner717d4382008-10-02 16:33:40 -07001079static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001080
Auke Kokbc7f75f2007-09-17 12:30:59 -07001081/**
Bruce Allanca15df52009-10-26 11:23:43 +00001082 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1083 * @hw: pointer to the HW structure
1084 *
1085 * Acquires the mutex for performing NVM operations.
1086 **/
1087static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
1088{
1089 mutex_lock(&nvm_mutex);
1090
1091 return 0;
1092}
1093
1094/**
1095 * e1000_release_nvm_ich8lan - Release NVM mutex
1096 * @hw: pointer to the HW structure
1097 *
1098 * Releases the mutex used while performing NVM operations.
1099 **/
1100static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
1101{
1102 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001103}
1104
Bruce Allanca15df52009-10-26 11:23:43 +00001105/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001106 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1107 * @hw: pointer to the HW structure
1108 *
Bruce Allanca15df52009-10-26 11:23:43 +00001109 * Acquires the software control flag for performing PHY and select
1110 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001111 **/
1112static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1113{
Bruce Allan373a88d2009-08-07 07:41:37 +00001114 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1115 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001116
Bruce Allana90b4122011-10-07 03:50:38 +00001117 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1118 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001119 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001120 return -E1000_ERR_PHY;
1121 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001122
Auke Kokbc7f75f2007-09-17 12:30:59 -07001123 while (timeout) {
1124 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001125 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1126 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 mdelay(1);
1129 timeout--;
1130 }
1131
1132 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001133 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001134 ret_val = -E1000_ERR_CONFIG;
1135 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001136 }
1137
Bruce Allan53ac5a82009-10-26 11:23:06 +00001138 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001139
1140 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1141 ew32(EXTCNF_CTRL, extcnf_ctrl);
1142
1143 while (timeout) {
1144 extcnf_ctrl = er32(EXTCNF_CTRL);
1145 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1146 break;
1147
1148 mdelay(1);
1149 timeout--;
1150 }
1151
1152 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001153 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 +00001154 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001155 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1156 ew32(EXTCNF_CTRL, extcnf_ctrl);
1157 ret_val = -E1000_ERR_CONFIG;
1158 goto out;
1159 }
1160
1161out:
1162 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001163 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001164
1165 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166}
1167
1168/**
1169 * e1000_release_swflag_ich8lan - Release software control flag
1170 * @hw: pointer to the HW structure
1171 *
Bruce Allanca15df52009-10-26 11:23:43 +00001172 * Releases the software control flag for performing PHY and select
1173 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001174 **/
1175static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1176{
1177 u32 extcnf_ctrl;
1178
1179 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001180
1181 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1182 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1183 ew32(EXTCNF_CTRL, extcnf_ctrl);
1184 } else {
1185 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1186 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001187
Bruce Allana90b4122011-10-07 03:50:38 +00001188 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189}
1190
1191/**
Bruce Allan4662e822008-08-26 18:37:06 -07001192 * e1000_check_mng_mode_ich8lan - Checks management mode
1193 * @hw: pointer to the HW structure
1194 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001195 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001196 * This is a function pointer entry point only called by read/write
1197 * routines for the PHY and NVM parts.
1198 **/
1199static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1200{
Bruce Allana708dd82009-11-20 23:28:37 +00001201 u32 fwsm;
1202
1203 fwsm = er32(FWSM);
Bruce Allaneb7700d2010-06-16 13:27:05 +00001204 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1205 ((fwsm & E1000_FWSM_MODE_MASK) ==
1206 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1207}
Bruce Allan4662e822008-08-26 18:37:06 -07001208
Bruce Allaneb7700d2010-06-16 13:27:05 +00001209/**
1210 * e1000_check_mng_mode_pchlan - Checks management mode
1211 * @hw: pointer to the HW structure
1212 *
1213 * This checks if the adapter has iAMT enabled.
1214 * This is a function pointer entry point only called by read/write
1215 * routines for the PHY and NVM parts.
1216 **/
1217static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1218{
1219 u32 fwsm;
1220
1221 fwsm = er32(FWSM);
1222 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1223 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001224}
1225
1226/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001227 * e1000_rar_set_pch2lan - Set receive address register
1228 * @hw: pointer to the HW structure
1229 * @addr: pointer to the receive address
1230 * @index: receive address array register
1231 *
1232 * Sets the receive address array register at index to the address passed
1233 * in by addr. For 82579, RAR[0] is the base address register that is to
1234 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1235 * Use SHRA[0-3] in place of those reserved for ME.
1236 **/
1237static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1238{
1239 u32 rar_low, rar_high;
1240
Bruce Allane921eb12012-11-28 09:28:37 +00001241 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001242 * from network order (big endian) to little endian
1243 */
1244 rar_low = ((u32)addr[0] |
1245 ((u32)addr[1] << 8) |
1246 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1247
1248 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1249
1250 /* If MAC address zero, no need to set the AV bit */
1251 if (rar_low || rar_high)
1252 rar_high |= E1000_RAH_AV;
1253
1254 if (index == 0) {
1255 ew32(RAL(index), rar_low);
1256 e1e_flush();
1257 ew32(RAH(index), rar_high);
1258 e1e_flush();
1259 return;
1260 }
1261
1262 if (index < hw->mac.rar_entry_count) {
1263 s32 ret_val;
1264
1265 ret_val = e1000_acquire_swflag_ich8lan(hw);
1266 if (ret_val)
1267 goto out;
1268
1269 ew32(SHRAL(index - 1), rar_low);
1270 e1e_flush();
1271 ew32(SHRAH(index - 1), rar_high);
1272 e1e_flush();
1273
1274 e1000_release_swflag_ich8lan(hw);
1275
1276 /* verify the register updates */
1277 if ((er32(SHRAL(index - 1)) == rar_low) &&
1278 (er32(SHRAH(index - 1)) == rar_high))
1279 return;
1280
1281 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1282 (index - 1), er32(FWSM));
1283 }
1284
1285out:
1286 e_dbg("Failed to write receive address at index %d\n", index);
1287}
1288
1289/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001290 * e1000_rar_set_pch_lpt - Set receive address registers
1291 * @hw: pointer to the HW structure
1292 * @addr: pointer to the receive address
1293 * @index: receive address array register
1294 *
1295 * Sets the receive address register array at index to the address passed
1296 * in by addr. For LPT, RAR[0] is the base address register that is to
1297 * contain the MAC address. SHRA[0-10] are the shared receive address
1298 * registers that are shared between the Host and manageability engine (ME).
1299 **/
1300static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1301{
1302 u32 rar_low, rar_high;
1303 u32 wlock_mac;
1304
Bruce Allane921eb12012-11-28 09:28:37 +00001305 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001306 * from network order (big endian) to little endian
1307 */
1308 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1309 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1310
1311 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1312
1313 /* If MAC address zero, no need to set the AV bit */
1314 if (rar_low || rar_high)
1315 rar_high |= E1000_RAH_AV;
1316
1317 if (index == 0) {
1318 ew32(RAL(index), rar_low);
1319 e1e_flush();
1320 ew32(RAH(index), rar_high);
1321 e1e_flush();
1322 return;
1323 }
1324
Bruce Allane921eb12012-11-28 09:28:37 +00001325 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001326 * it is using - those registers are unavailable for use.
1327 */
1328 if (index < hw->mac.rar_entry_count) {
1329 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1330 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1331
1332 /* Check if all SHRAR registers are locked */
1333 if (wlock_mac == 1)
1334 goto out;
1335
1336 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1337 s32 ret_val;
1338
1339 ret_val = e1000_acquire_swflag_ich8lan(hw);
1340
1341 if (ret_val)
1342 goto out;
1343
1344 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1345 e1e_flush();
1346 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1347 e1e_flush();
1348
1349 e1000_release_swflag_ich8lan(hw);
1350
1351 /* verify the register updates */
1352 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1353 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1354 return;
1355 }
1356 }
1357
1358out:
1359 e_dbg("Failed to write receive address at index %d\n", index);
1360}
1361
1362/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001363 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1364 * @hw: pointer to the HW structure
1365 *
1366 * Checks if firmware is blocking the reset of the PHY.
1367 * This is a function pointer entry point only called by
1368 * reset routines.
1369 **/
1370static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1371{
1372 u32 fwsm;
1373
1374 fwsm = er32(FWSM);
1375
1376 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
1377}
1378
1379/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001380 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1381 * @hw: pointer to the HW structure
1382 *
1383 * Assumes semaphore already acquired.
1384 *
1385 **/
1386static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1387{
1388 u16 phy_data;
1389 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001390 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1391 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan8395ae82010-09-22 17:15:08 +00001392 s32 ret_val = 0;
1393
1394 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1395
1396 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1397 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001398 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001399
1400 phy_data &= ~HV_SMB_ADDR_MASK;
1401 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1402 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001403
Bruce Allan2fbe4522012-04-19 03:21:47 +00001404 if (hw->phy.type == e1000_phy_i217) {
1405 /* Restore SMBus frequency */
1406 if (freq--) {
1407 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1408 phy_data |= (freq & (1 << 0)) <<
1409 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1410 phy_data |= (freq & (1 << 1)) <<
1411 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1412 } else {
1413 e_dbg("Unsupported SMB frequency in PHY\n");
1414 }
1415 }
1416
Bruce Allan5015e532012-02-08 02:55:56 +00001417 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001418}
1419
1420/**
Bruce Allanf523d212009-10-29 13:45:45 +00001421 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1422 * @hw: pointer to the HW structure
1423 *
1424 * SW should configure the LCD from the NVM extended configuration region
1425 * as a workaround for certain parts.
1426 **/
1427static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1428{
1429 struct e1000_phy_info *phy = &hw->phy;
1430 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001431 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001432 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1433
Bruce Allane921eb12012-11-28 09:28:37 +00001434 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001435 * is needed due to an issue where the NVM configuration is
1436 * not properly autoloaded after power transitions.
1437 * Therefore, after each PHY reset, we will load the
1438 * configuration data out of the NVM manually.
1439 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001440 switch (hw->mac.type) {
1441 case e1000_ich8lan:
1442 if (phy->type != e1000_phy_igp_3)
1443 return ret_val;
1444
Bruce Allan5f3eed62010-09-22 17:15:54 +00001445 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1446 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001447 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1448 break;
1449 }
1450 /* Fall-thru */
1451 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001452 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001453 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001454 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001455 break;
1456 default:
1457 return ret_val;
1458 }
1459
1460 ret_val = hw->phy.ops.acquire(hw);
1461 if (ret_val)
1462 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001463
Bruce Allan8b802a72010-05-10 15:01:10 +00001464 data = er32(FEXTNVM);
1465 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001466 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001467
Bruce Allane921eb12012-11-28 09:28:37 +00001468 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001469 * extended configuration before SW configuration
1470 */
1471 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001472 if ((hw->mac.type < e1000_pch2lan) &&
1473 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1474 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001475
Bruce Allan8b802a72010-05-10 15:01:10 +00001476 cnf_size = er32(EXTCNF_SIZE);
1477 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1478 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1479 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001480 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001481
1482 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1483 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1484
Bruce Allan2fbe4522012-04-19 03:21:47 +00001485 if (((hw->mac.type == e1000_pchlan) &&
1486 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1487 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001488 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001489 * OEM and LCD Write Enable bits are set in the NVM.
1490 * When both NVM bits are cleared, SW will configure
1491 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001492 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001493 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001494 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001495 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001496
Bruce Allan8b802a72010-05-10 15:01:10 +00001497 data = er32(LEDCTL);
1498 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1499 (u16)data);
1500 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001501 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001502 }
1503
1504 /* Configure LCD from extended configuration region. */
1505
1506 /* cnf_base_addr is in DWORD */
1507 word_addr = (u16)(cnf_base_addr << 1);
1508
1509 for (i = 0; i < cnf_size; i++) {
1510 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
1511 &reg_data);
1512 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001513 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001514
Bruce Allan8b802a72010-05-10 15:01:10 +00001515 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1516 1, &reg_addr);
1517 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001518 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001519
Bruce Allan8b802a72010-05-10 15:01:10 +00001520 /* Save off the PHY page for future writes. */
1521 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1522 phy_page = reg_data;
1523 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001524 }
Bruce Allanf523d212009-10-29 13:45:45 +00001525
Bruce Allan8b802a72010-05-10 15:01:10 +00001526 reg_addr &= PHY_REG_MASK;
1527 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001528
Bruce Allanf1430d62012-04-14 04:21:52 +00001529 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001530 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001531 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001532 }
1533
Bruce Allan75ce1532012-02-08 02:54:48 +00001534release:
Bruce Allan94d81862009-11-20 23:25:26 +00001535 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001536 return ret_val;
1537}
1538
1539/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001540 * e1000_k1_gig_workaround_hv - K1 Si workaround
1541 * @hw: pointer to the HW structure
1542 * @link: link up bool flag
1543 *
1544 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1545 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1546 * If link is down, the function will restore the default K1 setting located
1547 * in the NVM.
1548 **/
1549static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1550{
1551 s32 ret_val = 0;
1552 u16 status_reg = 0;
1553 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1554
1555 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001556 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001557
1558 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001559 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001560 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001561 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001562
1563 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1564 if (link) {
1565 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001566 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1567 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001568 if (ret_val)
1569 goto release;
1570
1571 status_reg &= BM_CS_STATUS_LINK_UP |
1572 BM_CS_STATUS_RESOLVED |
1573 BM_CS_STATUS_SPEED_MASK;
1574
1575 if (status_reg == (BM_CS_STATUS_LINK_UP |
1576 BM_CS_STATUS_RESOLVED |
1577 BM_CS_STATUS_SPEED_1000))
1578 k1_enable = false;
1579 }
1580
1581 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001582 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001583 if (ret_val)
1584 goto release;
1585
1586 status_reg &= HV_M_STATUS_LINK_UP |
1587 HV_M_STATUS_AUTONEG_COMPLETE |
1588 HV_M_STATUS_SPEED_MASK;
1589
1590 if (status_reg == (HV_M_STATUS_LINK_UP |
1591 HV_M_STATUS_AUTONEG_COMPLETE |
1592 HV_M_STATUS_SPEED_1000))
1593 k1_enable = false;
1594 }
1595
1596 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001597 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001598 if (ret_val)
1599 goto release;
1600
1601 } else {
1602 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001603 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001604 if (ret_val)
1605 goto release;
1606 }
1607
1608 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1609
1610release:
Bruce Allan94d81862009-11-20 23:25:26 +00001611 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001612
Bruce Allan1d5846b2009-10-29 13:46:05 +00001613 return ret_val;
1614}
1615
1616/**
1617 * e1000_configure_k1_ich8lan - Configure K1 power state
1618 * @hw: pointer to the HW structure
1619 * @enable: K1 state to configure
1620 *
1621 * Configure the K1 power state based on the provided parameter.
1622 * Assumes semaphore already acquired.
1623 *
1624 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1625 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001626s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001627{
1628 s32 ret_val = 0;
1629 u32 ctrl_reg = 0;
1630 u32 ctrl_ext = 0;
1631 u32 reg = 0;
1632 u16 kmrn_reg = 0;
1633
Bruce Allan3d3a1672012-02-23 03:13:18 +00001634 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1635 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001636 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001637 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001638
1639 if (k1_enable)
1640 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1641 else
1642 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1643
Bruce Allan3d3a1672012-02-23 03:13:18 +00001644 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1645 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001646 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001647 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001648
1649 udelay(20);
1650 ctrl_ext = er32(CTRL_EXT);
1651 ctrl_reg = er32(CTRL);
1652
1653 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1654 reg |= E1000_CTRL_FRCSPD;
1655 ew32(CTRL, reg);
1656
1657 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001658 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001659 udelay(20);
1660 ew32(CTRL, ctrl_reg);
1661 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001662 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001663 udelay(20);
1664
Bruce Allan5015e532012-02-08 02:55:56 +00001665 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001666}
1667
1668/**
Bruce Allanf523d212009-10-29 13:45:45 +00001669 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1670 * @hw: pointer to the HW structure
1671 * @d0_state: boolean if entering d0 or d3 device state
1672 *
1673 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1674 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1675 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1676 **/
1677static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1678{
1679 s32 ret_val = 0;
1680 u32 mac_reg;
1681 u16 oem_reg;
1682
Bruce Allan2fbe4522012-04-19 03:21:47 +00001683 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001684 return ret_val;
1685
Bruce Allan94d81862009-11-20 23:25:26 +00001686 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001687 if (ret_val)
1688 return ret_val;
1689
Bruce Allan2fbe4522012-04-19 03:21:47 +00001690 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001691 mac_reg = er32(EXTCNF_CTRL);
1692 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001693 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001694 }
Bruce Allanf523d212009-10-29 13:45:45 +00001695
1696 mac_reg = er32(FEXTNVM);
1697 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001698 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001699
1700 mac_reg = er32(PHY_CTRL);
1701
Bruce Allanf1430d62012-04-14 04:21:52 +00001702 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001703 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001704 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001705
1706 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1707
1708 if (d0_state) {
1709 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1710 oem_reg |= HV_OEM_BITS_GBE_DIS;
1711
1712 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1713 oem_reg |= HV_OEM_BITS_LPLU;
1714 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001715 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1716 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001717 oem_reg |= HV_OEM_BITS_GBE_DIS;
1718
Bruce Allan03299e42011-09-30 08:07:05 +00001719 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1720 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001721 oem_reg |= HV_OEM_BITS_LPLU;
1722 }
Bruce Allan03299e42011-09-30 08:07:05 +00001723
Bruce Allan92fe1732012-04-12 06:27:03 +00001724 /* Set Restart auto-neg to activate the bits */
1725 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1726 !hw->phy.ops.check_reset_block(hw))
1727 oem_reg |= HV_OEM_BITS_RESTART_AN;
1728
Bruce Allanf1430d62012-04-14 04:21:52 +00001729 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001730
Bruce Allan75ce1532012-02-08 02:54:48 +00001731release:
Bruce Allan94d81862009-11-20 23:25:26 +00001732 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001733
1734 return ret_val;
1735}
1736
1737
1738/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001739 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1740 * @hw: pointer to the HW structure
1741 **/
1742static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1743{
1744 s32 ret_val;
1745 u16 data;
1746
1747 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1748 if (ret_val)
1749 return ret_val;
1750
1751 data |= HV_KMRN_MDIO_SLOW;
1752
1753 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1754
1755 return ret_val;
1756}
1757
1758/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001759 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1760 * done after every PHY reset.
1761 **/
1762static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1763{
1764 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001765 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001766
1767 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001768 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001769
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001770 /* Set MDIO slow mode before any other MDIO access */
1771 if (hw->phy.type == e1000_phy_82577) {
1772 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1773 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001774 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001775 }
1776
Bruce Allana4f58f52009-06-02 11:29:18 +00001777 if (((hw->phy.type == e1000_phy_82577) &&
1778 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1779 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1780 /* Disable generation of early preamble */
1781 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1782 if (ret_val)
1783 return ret_val;
1784
1785 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001786 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001787 if (ret_val)
1788 return ret_val;
1789 }
1790
1791 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001792 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001793 * writing 0x3140 to the control register.
1794 */
1795 if (hw->phy.revision < 2) {
1796 e1000e_phy_sw_reset(hw);
1797 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1798 }
1799 }
1800
1801 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001802 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001803 if (ret_val)
1804 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001805
Bruce Allana4f58f52009-06-02 11:29:18 +00001806 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001807 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001808 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001809 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001810 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001811
Bruce Allane921eb12012-11-28 09:28:37 +00001812 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001813 * link so that it disables K1 if link is in 1Gbps.
1814 */
1815 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001816 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001817 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001818
Bruce Allanbaf86c92010-01-13 01:53:08 +00001819 /* Workaround for link disconnects on a busy hub in half duplex */
1820 ret_val = hw->phy.ops.acquire(hw);
1821 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001822 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001823 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001824 if (ret_val)
1825 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001826 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001827 if (ret_val)
1828 goto release;
1829
1830 /* set MSE higher to enable link to stay up when noise is high */
1831 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001832release:
1833 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001834
Bruce Allana4f58f52009-06-02 11:29:18 +00001835 return ret_val;
1836}
1837
1838/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001839 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1840 * @hw: pointer to the HW structure
1841 **/
1842void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1843{
1844 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001845 u16 i, phy_reg = 0;
1846 s32 ret_val;
1847
1848 ret_val = hw->phy.ops.acquire(hw);
1849 if (ret_val)
1850 return;
1851 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1852 if (ret_val)
1853 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001854
1855 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1856 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1857 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001858 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1859 (u16)(mac_reg & 0xFFFF));
1860 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1861 (u16)((mac_reg >> 16) & 0xFFFF));
1862
Bruce Alland3738bb2010-06-16 13:27:28 +00001863 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001864 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1865 (u16)(mac_reg & 0xFFFF));
1866 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1867 (u16)((mac_reg & E1000_RAH_AV)
1868 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00001869 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00001870
1871 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1872
1873release:
1874 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001875}
1876
Bruce Alland3738bb2010-06-16 13:27:28 +00001877/**
1878 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1879 * with 82579 PHY
1880 * @hw: pointer to the HW structure
1881 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1882 **/
1883s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1884{
1885 s32 ret_val = 0;
1886 u16 phy_reg, data;
1887 u32 mac_reg;
1888 u16 i;
1889
Bruce Allan2fbe4522012-04-19 03:21:47 +00001890 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001891 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001892
1893 /* disable Rx path while enabling/disabling workaround */
1894 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1895 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1896 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001897 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001898
1899 if (enable) {
Bruce Allane921eb12012-11-28 09:28:37 +00001900 /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
Bruce Alland3738bb2010-06-16 13:27:28 +00001901 * SHRAL/H) and initial CRC values to the MAC
1902 */
1903 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1904 u8 mac_addr[ETH_ALEN] = {0};
1905 u32 addr_high, addr_low;
1906
1907 addr_high = er32(RAH(i));
1908 if (!(addr_high & E1000_RAH_AV))
1909 continue;
1910 addr_low = er32(RAL(i));
1911 mac_addr[0] = (addr_low & 0xFF);
1912 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1913 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1914 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1915 mac_addr[4] = (addr_high & 0xFF);
1916 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1917
Bruce Allanfe46f582011-01-06 14:29:51 +00001918 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00001919 }
1920
1921 /* Write Rx addresses to the PHY */
1922 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1923
1924 /* Enable jumbo frame workaround in the MAC */
1925 mac_reg = er32(FFLT_DBG);
1926 mac_reg &= ~(1 << 14);
1927 mac_reg |= (7 << 15);
1928 ew32(FFLT_DBG, mac_reg);
1929
1930 mac_reg = er32(RCTL);
1931 mac_reg |= E1000_RCTL_SECRC;
1932 ew32(RCTL, mac_reg);
1933
1934 ret_val = e1000e_read_kmrn_reg(hw,
1935 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1936 &data);
1937 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001938 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001939 ret_val = e1000e_write_kmrn_reg(hw,
1940 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1941 data | (1 << 0));
1942 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001943 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001944 ret_val = e1000e_read_kmrn_reg(hw,
1945 E1000_KMRNCTRLSTA_HD_CTRL,
1946 &data);
1947 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001948 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001949 data &= ~(0xF << 8);
1950 data |= (0xB << 8);
1951 ret_val = e1000e_write_kmrn_reg(hw,
1952 E1000_KMRNCTRLSTA_HD_CTRL,
1953 data);
1954 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001955 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001956
1957 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001958 e1e_rphy(hw, PHY_REG(769, 23), &data);
1959 data &= ~(0x7F << 5);
1960 data |= (0x37 << 5);
1961 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1962 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001963 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001964 e1e_rphy(hw, PHY_REG(769, 16), &data);
1965 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00001966 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1967 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001968 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001969 e1e_rphy(hw, PHY_REG(776, 20), &data);
1970 data &= ~(0x3FF << 2);
1971 data |= (0x1A << 2);
1972 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1973 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001974 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00001975 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00001976 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001977 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001978 e1e_rphy(hw, HV_PM_CTRL, &data);
1979 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1980 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001981 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001982 } else {
1983 /* Write MAC register values back to h/w defaults */
1984 mac_reg = er32(FFLT_DBG);
1985 mac_reg &= ~(0xF << 14);
1986 ew32(FFLT_DBG, mac_reg);
1987
1988 mac_reg = er32(RCTL);
1989 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00001990 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00001991
1992 ret_val = e1000e_read_kmrn_reg(hw,
1993 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1994 &data);
1995 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001996 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001997 ret_val = e1000e_write_kmrn_reg(hw,
1998 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1999 data & ~(1 << 0));
2000 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002001 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002002 ret_val = e1000e_read_kmrn_reg(hw,
2003 E1000_KMRNCTRLSTA_HD_CTRL,
2004 &data);
2005 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002006 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002007 data &= ~(0xF << 8);
2008 data |= (0xB << 8);
2009 ret_val = e1000e_write_kmrn_reg(hw,
2010 E1000_KMRNCTRLSTA_HD_CTRL,
2011 data);
2012 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002013 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002014
2015 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002016 e1e_rphy(hw, PHY_REG(769, 23), &data);
2017 data &= ~(0x7F << 5);
2018 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2019 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002020 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002021 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002022 data |= (1 << 13);
2023 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2024 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002025 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002026 e1e_rphy(hw, PHY_REG(776, 20), &data);
2027 data &= ~(0x3FF << 2);
2028 data |= (0x8 << 2);
2029 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2030 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002031 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002032 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2033 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002034 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002035 e1e_rphy(hw, HV_PM_CTRL, &data);
2036 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2037 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002038 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002039 }
2040
2041 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002042 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002043}
2044
2045/**
2046 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2047 * done after every PHY reset.
2048 **/
2049static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2050{
2051 s32 ret_val = 0;
2052
2053 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002054 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002055
2056 /* Set MDIO slow mode before any other MDIO access */
2057 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002058 if (ret_val)
2059 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002060
Bruce Allan4d241362011-12-16 00:46:06 +00002061 ret_val = hw->phy.ops.acquire(hw);
2062 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002063 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002064 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002065 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002066 if (ret_val)
2067 goto release;
2068 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002069 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002070release:
2071 hw->phy.ops.release(hw);
2072
Bruce Alland3738bb2010-06-16 13:27:28 +00002073 return ret_val;
2074}
2075
2076/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002077 * e1000_k1_gig_workaround_lv - K1 Si workaround
2078 * @hw: pointer to the HW structure
2079 *
2080 * Workaround to set the K1 beacon duration for 82579 parts
2081 **/
2082static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2083{
2084 s32 ret_val = 0;
2085 u16 status_reg = 0;
2086 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002087 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002088
2089 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002090 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002091
2092 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2093 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2094 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002095 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002096
2097 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2098 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2099 mac_reg = er32(FEXTNVM4);
2100 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2101
Bruce Allan0ed013e2011-07-29 05:52:56 +00002102 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2103 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002104 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002105
Bruce Allan0ed013e2011-07-29 05:52:56 +00002106 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002107 u16 pm_phy_reg;
2108
Bruce Allan0ed013e2011-07-29 05:52:56 +00002109 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2110 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002111 /* LV 1G Packet drop issue wa */
2112 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2113 if (ret_val)
2114 return ret_val;
2115 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2116 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2117 if (ret_val)
2118 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002119 } else {
2120 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2121 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2122 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002123 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002124 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002125 }
2126
Bruce Allan831bd2e2010-09-22 17:16:18 +00002127 return ret_val;
2128}
2129
2130/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002131 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2132 * @hw: pointer to the HW structure
2133 * @gate: boolean set to true to gate, false to ungate
2134 *
2135 * Gate/ungate the automatic PHY configuration via hardware; perform
2136 * the configuration via software instead.
2137 **/
2138static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2139{
2140 u32 extcnf_ctrl;
2141
Bruce Allan2fbe4522012-04-19 03:21:47 +00002142 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002143 return;
2144
2145 extcnf_ctrl = er32(EXTCNF_CTRL);
2146
2147 if (gate)
2148 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2149 else
2150 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2151
2152 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002153}
2154
2155/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002156 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2157 * @hw: pointer to the HW structure
2158 *
2159 * Check the appropriate indication the MAC has finished configuring the
2160 * PHY after a software reset.
2161 **/
2162static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2163{
2164 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2165
2166 /* Wait for basic configuration completes before proceeding */
2167 do {
2168 data = er32(STATUS);
2169 data &= E1000_STATUS_LAN_INIT_DONE;
2170 udelay(100);
2171 } while ((!data) && --loop);
2172
Bruce Allane921eb12012-11-28 09:28:37 +00002173 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002174 * count reaches 0, loading the configuration from NVM will
2175 * leave the PHY in a bad state possibly resulting in no link.
2176 */
2177 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002178 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002179
2180 /* Clear the Init Done bit for the next init event */
2181 data = er32(STATUS);
2182 data &= ~E1000_STATUS_LAN_INIT_DONE;
2183 ew32(STATUS, data);
2184}
2185
2186/**
Bruce Allane98cac42010-05-10 15:02:32 +00002187 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002188 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002189 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002190static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002191{
Bruce Allanf523d212009-10-29 13:45:45 +00002192 s32 ret_val = 0;
2193 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002194
Bruce Allan44abd5c2012-02-22 09:02:37 +00002195 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002196 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002197
Bruce Allan5f3eed62010-09-22 17:15:54 +00002198 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002199 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002200
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002201 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002202 switch (hw->mac.type) {
2203 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002204 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2205 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002206 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002207 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002208 case e1000_pch2lan:
2209 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2210 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002211 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002212 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002213 default:
2214 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002215 }
2216
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002217 /* Clear the host wakeup bit after lcd reset */
2218 if (hw->mac.type >= e1000_pchlan) {
2219 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2220 reg &= ~BM_WUC_HOST_WU_BIT;
2221 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2222 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002223
Bruce Allanf523d212009-10-29 13:45:45 +00002224 /* Configure the LCD with the extended configuration region in NVM */
2225 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2226 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002227 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002228
Bruce Allanf523d212009-10-29 13:45:45 +00002229 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002230 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002231
Bruce Allan1effb452011-02-25 06:58:03 +00002232 if (hw->mac.type == e1000_pch2lan) {
2233 /* Ungate automatic PHY configuration on non-managed 82579 */
2234 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002235 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002236 e1000_gate_hw_phy_config_ich8lan(hw, false);
2237 }
2238
2239 /* Set EEE LPI Update Timer to 200usec */
2240 ret_val = hw->phy.ops.acquire(hw);
2241 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002242 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002243 ret_val = e1000_write_emi_reg_locked(hw,
2244 I82579_LPI_UPDATE_TIMER,
2245 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002246 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002247 }
2248
Bruce Allane98cac42010-05-10 15:02:32 +00002249 return ret_val;
2250}
2251
2252/**
2253 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2254 * @hw: pointer to the HW structure
2255 *
2256 * Resets the PHY
2257 * This is a function pointer entry point called by drivers
2258 * or other shared routines.
2259 **/
2260static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2261{
2262 s32 ret_val = 0;
2263
Bruce Allan605c82b2010-09-22 17:17:01 +00002264 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2265 if ((hw->mac.type == e1000_pch2lan) &&
2266 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2267 e1000_gate_hw_phy_config_ich8lan(hw, true);
2268
Bruce Allane98cac42010-05-10 15:02:32 +00002269 ret_val = e1000e_phy_hw_reset_generic(hw);
2270 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002271 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002272
Bruce Allan5015e532012-02-08 02:55:56 +00002273 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002274}
2275
2276/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002277 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2278 * @hw: pointer to the HW structure
2279 * @active: true to enable LPLU, false to disable
2280 *
2281 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2282 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2283 * the phy speed. This function will manually set the LPLU bit and restart
2284 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2285 * since it configures the same bit.
2286 **/
2287static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2288{
2289 s32 ret_val = 0;
2290 u16 oem_reg;
2291
2292 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2293 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002294 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002295
2296 if (active)
2297 oem_reg |= HV_OEM_BITS_LPLU;
2298 else
2299 oem_reg &= ~HV_OEM_BITS_LPLU;
2300
Bruce Allan44abd5c2012-02-22 09:02:37 +00002301 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002302 oem_reg |= HV_OEM_BITS_RESTART_AN;
2303
Bruce Allan5015e532012-02-08 02:55:56 +00002304 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002305}
2306
2307/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2309 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002310 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002311 *
2312 * Sets the LPLU D0 state according to the active flag. When
2313 * activating LPLU this function also disables smart speed
2314 * and vice versa. LPLU will not be activated unless the
2315 * device autonegotiation advertisement meets standards of
2316 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2317 * This is a function pointer entry point only called by
2318 * PHY setup routines.
2319 **/
2320static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2321{
2322 struct e1000_phy_info *phy = &hw->phy;
2323 u32 phy_ctrl;
2324 s32 ret_val = 0;
2325 u16 data;
2326
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002327 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002328 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329
2330 phy_ctrl = er32(PHY_CTRL);
2331
2332 if (active) {
2333 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2334 ew32(PHY_CTRL, phy_ctrl);
2335
Bruce Allan60f12922009-07-01 13:28:14 +00002336 if (phy->type != e1000_phy_igp_3)
2337 return 0;
2338
Bruce Allane921eb12012-11-28 09:28:37 +00002339 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002340 * any PHY registers
2341 */
Bruce Allan60f12922009-07-01 13:28:14 +00002342 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002343 e1000e_gig_downshift_workaround_ich8lan(hw);
2344
2345 /* When LPLU is enabled, we should disable SmartSpeed */
2346 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
2347 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2348 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2349 if (ret_val)
2350 return ret_val;
2351 } else {
2352 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2353 ew32(PHY_CTRL, phy_ctrl);
2354
Bruce Allan60f12922009-07-01 13:28:14 +00002355 if (phy->type != e1000_phy_igp_3)
2356 return 0;
2357
Bruce Allane921eb12012-11-28 09:28:37 +00002358 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359 * during Dx states where the power conservation is most
2360 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002361 * SmartSpeed, so performance is maintained.
2362 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363 if (phy->smart_speed == e1000_smart_speed_on) {
2364 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002365 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366 if (ret_val)
2367 return ret_val;
2368
2369 data |= IGP01E1000_PSCFR_SMART_SPEED;
2370 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002371 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002372 if (ret_val)
2373 return ret_val;
2374 } else if (phy->smart_speed == e1000_smart_speed_off) {
2375 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002376 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002377 if (ret_val)
2378 return ret_val;
2379
2380 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2381 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002382 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002383 if (ret_val)
2384 return ret_val;
2385 }
2386 }
2387
2388 return 0;
2389}
2390
2391/**
2392 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2393 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002394 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002395 *
2396 * Sets the LPLU D3 state according to the active flag. When
2397 * activating LPLU this function also disables smart speed
2398 * and vice versa. LPLU will not be activated unless the
2399 * device autonegotiation advertisement meets standards of
2400 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2401 * This is a function pointer entry point only called by
2402 * PHY setup routines.
2403 **/
2404static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2405{
2406 struct e1000_phy_info *phy = &hw->phy;
2407 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002408 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002409 u16 data;
2410
2411 phy_ctrl = er32(PHY_CTRL);
2412
2413 if (!active) {
2414 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2415 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002416
2417 if (phy->type != e1000_phy_igp_3)
2418 return 0;
2419
Bruce Allane921eb12012-11-28 09:28:37 +00002420 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002421 * during Dx states where the power conservation is most
2422 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002423 * SmartSpeed, so performance is maintained.
2424 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002425 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002426 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2427 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002428 if (ret_val)
2429 return ret_val;
2430
2431 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002432 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2433 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434 if (ret_val)
2435 return ret_val;
2436 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002437 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2438 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002439 if (ret_val)
2440 return ret_val;
2441
2442 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002443 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2444 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002445 if (ret_val)
2446 return ret_val;
2447 }
2448 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2449 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2450 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2451 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2452 ew32(PHY_CTRL, phy_ctrl);
2453
Bruce Allan60f12922009-07-01 13:28:14 +00002454 if (phy->type != e1000_phy_igp_3)
2455 return 0;
2456
Bruce Allane921eb12012-11-28 09:28:37 +00002457 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002458 * any PHY registers
2459 */
Bruce Allan60f12922009-07-01 13:28:14 +00002460 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002461 e1000e_gig_downshift_workaround_ich8lan(hw);
2462
2463 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002464 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465 if (ret_val)
2466 return ret_val;
2467
2468 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002469 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470 }
2471
Bruce Alland7eb3382012-02-08 02:55:14 +00002472 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002473}
2474
2475/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002476 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2477 * @hw: pointer to the HW structure
2478 * @bank: pointer to the variable that returns the active bank
2479 *
2480 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002481 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002482 **/
2483static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2484{
Bruce Allane2434552008-11-21 17:02:41 -08002485 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002486 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002487 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2488 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002489 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002490 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002491
Bruce Allane2434552008-11-21 17:02:41 -08002492 switch (hw->mac.type) {
2493 case e1000_ich8lan:
2494 case e1000_ich9lan:
2495 eecd = er32(EECD);
2496 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2497 E1000_EECD_SEC1VAL_VALID_MASK) {
2498 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002499 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002500 else
2501 *bank = 0;
2502
2503 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002504 }
Bruce Allan434f1392011-12-16 00:46:54 +00002505 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002506 /* fall-thru */
2507 default:
2508 /* set bank to 0 in case flash read fails */
2509 *bank = 0;
2510
2511 /* Check bank 0 */
2512 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
2513 &sig_byte);
2514 if (ret_val)
2515 return ret_val;
2516 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2517 E1000_ICH_NVM_SIG_VALUE) {
2518 *bank = 0;
2519 return 0;
2520 }
2521
2522 /* Check bank 1 */
2523 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
2524 bank1_offset,
2525 &sig_byte);
2526 if (ret_val)
2527 return ret_val;
2528 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2529 E1000_ICH_NVM_SIG_VALUE) {
2530 *bank = 1;
2531 return 0;
2532 }
2533
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002534 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002535 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002536 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002537}
2538
2539/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002540 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2541 * @hw: pointer to the HW structure
2542 * @offset: The offset (in bytes) of the word(s) to read.
2543 * @words: Size of data to read in words
2544 * @data: Pointer to the word(s) to read at offset.
2545 *
2546 * Reads a word(s) from the NVM using the flash access registers.
2547 **/
2548static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2549 u16 *data)
2550{
2551 struct e1000_nvm_info *nvm = &hw->nvm;
2552 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2553 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002554 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002555 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002556 u16 i, word;
2557
2558 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2559 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002560 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002561 ret_val = -E1000_ERR_NVM;
2562 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563 }
2564
Bruce Allan94d81862009-11-20 23:25:26 +00002565 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566
Bruce Allanf4187b52008-08-26 18:36:50 -07002567 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002568 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002569 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002570 bank = 0;
2571 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002572
2573 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574 act_offset += offset;
2575
Bruce Allan148675a2009-08-07 07:41:56 +00002576 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577 for (i = 0; i < words; i++) {
Bruce Allanb9e06f72011-07-22 06:21:41 +00002578 if (dev_spec->shadow_ram[offset+i].modified) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002579 data[i] = dev_spec->shadow_ram[offset+i].value;
2580 } else {
2581 ret_val = e1000_read_flash_word_ich8lan(hw,
2582 act_offset + i,
2583 &word);
2584 if (ret_val)
2585 break;
2586 data[i] = word;
2587 }
2588 }
2589
Bruce Allan94d81862009-11-20 23:25:26 +00002590 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002591
Bruce Allane2434552008-11-21 17:02:41 -08002592out:
2593 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002594 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002595
Auke Kokbc7f75f2007-09-17 12:30:59 -07002596 return ret_val;
2597}
2598
2599/**
2600 * e1000_flash_cycle_init_ich8lan - Initialize flash
2601 * @hw: pointer to the HW structure
2602 *
2603 * This function does initial flash setup so that a new read/write/erase cycle
2604 * can be started.
2605 **/
2606static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2607{
2608 union ich8_hws_flash_status hsfsts;
2609 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002610
2611 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2612
2613 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002614 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002615 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002616 return -E1000_ERR_NVM;
2617 }
2618
2619 /* Clear FCERR and DAEL in hw status by writing 1 */
2620 hsfsts.hsf_status.flcerr = 1;
2621 hsfsts.hsf_status.dael = 1;
2622
2623 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2624
Bruce Allane921eb12012-11-28 09:28:37 +00002625 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002626 * bit to check against, in order to start a new cycle or
2627 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002628 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002629 * indication whether a cycle is in progress or has been
2630 * completed.
2631 */
2632
Bruce Allan04499ec2012-04-13 00:08:31 +00002633 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002634 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002635 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002636 * Begin by setting Flash Cycle Done.
2637 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002638 hsfsts.hsf_status.flcdone = 1;
2639 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2640 ret_val = 0;
2641 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002642 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002643
Bruce Allane921eb12012-11-28 09:28:37 +00002644 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002645 * cycle has a chance to end before giving up.
2646 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002647 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002648 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002649 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002650 ret_val = 0;
2651 break;
2652 }
2653 udelay(1);
2654 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002655 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002656 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002657 * now set the Flash Cycle Done.
2658 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002659 hsfsts.hsf_status.flcdone = 1;
2660 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2661 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002662 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 }
2664 }
2665
2666 return ret_val;
2667}
2668
2669/**
2670 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2671 * @hw: pointer to the HW structure
2672 * @timeout: maximum time to wait for completion
2673 *
2674 * This function starts a flash cycle and waits for its completion.
2675 **/
2676static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2677{
2678 union ich8_hws_flash_ctrl hsflctl;
2679 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002680 u32 i = 0;
2681
2682 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2683 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2684 hsflctl.hsf_ctrl.flcgo = 1;
2685 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2686
2687 /* wait till FDONE bit is set to 1 */
2688 do {
2689 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002690 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691 break;
2692 udelay(1);
2693 } while (i++ < timeout);
2694
Bruce Allan04499ec2012-04-13 00:08:31 +00002695 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002696 return 0;
2697
Bruce Allan55920b52012-02-08 02:55:25 +00002698 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002699}
2700
2701/**
2702 * e1000_read_flash_word_ich8lan - Read word from flash
2703 * @hw: pointer to the HW structure
2704 * @offset: offset to data location
2705 * @data: pointer to the location for storing the data
2706 *
2707 * Reads the flash word at offset into data. Offset is converted
2708 * to bytes before read.
2709 **/
2710static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2711 u16 *data)
2712{
2713 /* Must convert offset into bytes. */
2714 offset <<= 1;
2715
2716 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2717}
2718
2719/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002720 * e1000_read_flash_byte_ich8lan - Read byte from flash
2721 * @hw: pointer to the HW structure
2722 * @offset: The offset of the byte to read.
2723 * @data: Pointer to a byte to store the value read.
2724 *
2725 * Reads a single byte from the NVM using the flash access registers.
2726 **/
2727static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2728 u8 *data)
2729{
2730 s32 ret_val;
2731 u16 word = 0;
2732
2733 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2734 if (ret_val)
2735 return ret_val;
2736
2737 *data = (u8)word;
2738
2739 return 0;
2740}
2741
2742/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002743 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2744 * @hw: pointer to the HW structure
2745 * @offset: The offset (in bytes) of the byte or word to read.
2746 * @size: Size of data to read, 1=byte 2=word
2747 * @data: Pointer to the word to store the value read.
2748 *
2749 * Reads a byte or word from the NVM using the flash access registers.
2750 **/
2751static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2752 u8 size, u16 *data)
2753{
2754 union ich8_hws_flash_status hsfsts;
2755 union ich8_hws_flash_ctrl hsflctl;
2756 u32 flash_linear_addr;
2757 u32 flash_data = 0;
2758 s32 ret_val = -E1000_ERR_NVM;
2759 u8 count = 0;
2760
2761 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2762 return -E1000_ERR_NVM;
2763
2764 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2765 hw->nvm.flash_base_addr;
2766
2767 do {
2768 udelay(1);
2769 /* Steps */
2770 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002771 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002772 break;
2773
2774 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2775 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2776 hsflctl.hsf_ctrl.fldbcount = size - 1;
2777 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2778 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2779
2780 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2781
2782 ret_val = e1000_flash_cycle_ich8lan(hw,
2783 ICH_FLASH_READ_COMMAND_TIMEOUT);
2784
Bruce Allane921eb12012-11-28 09:28:37 +00002785 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002786 * and try the whole sequence a few more times, else
2787 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002788 * least significant byte first msb to lsb
2789 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002790 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002791 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002792 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002793 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002794 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002795 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002796 break;
2797 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002798 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002799 * completely hosed, but if the error condition is
2800 * detected, it won't hurt to give it another try...
2801 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2802 */
2803 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002804 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002805 /* Repeat for some time before giving up. */
2806 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002807 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002808 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002809 break;
2810 }
2811 }
2812 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2813
2814 return ret_val;
2815}
2816
2817/**
2818 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2819 * @hw: pointer to the HW structure
2820 * @offset: The offset (in bytes) of the word(s) to write.
2821 * @words: Size of data to write in words
2822 * @data: Pointer to the word(s) to write at offset.
2823 *
2824 * Writes a byte or word to the NVM using the flash access registers.
2825 **/
2826static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2827 u16 *data)
2828{
2829 struct e1000_nvm_info *nvm = &hw->nvm;
2830 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 u16 i;
2832
2833 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2834 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002835 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836 return -E1000_ERR_NVM;
2837 }
2838
Bruce Allan94d81862009-11-20 23:25:26 +00002839 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002840
Auke Kokbc7f75f2007-09-17 12:30:59 -07002841 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002842 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843 dev_spec->shadow_ram[offset+i].value = data[i];
2844 }
2845
Bruce Allan94d81862009-11-20 23:25:26 +00002846 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002847
Auke Kokbc7f75f2007-09-17 12:30:59 -07002848 return 0;
2849}
2850
2851/**
2852 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2853 * @hw: pointer to the HW structure
2854 *
2855 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2856 * which writes the checksum to the shadow ram. The changes in the shadow
2857 * ram are then committed to the EEPROM by processing each bank at a time
2858 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002859 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002860 * future writes.
2861 **/
2862static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2863{
2864 struct e1000_nvm_info *nvm = &hw->nvm;
2865 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002866 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867 s32 ret_val;
2868 u16 data;
2869
2870 ret_val = e1000e_update_nvm_checksum_generic(hw);
2871 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002872 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002873
2874 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002875 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002876
Bruce Allan94d81862009-11-20 23:25:26 +00002877 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002878
Bruce Allane921eb12012-11-28 09:28:37 +00002879 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002880 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002881 * is going to be written
2882 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002883 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002884 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002885 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002886 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002887 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002888
2889 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002890 new_bank_offset = nvm->flash_bank_size;
2891 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002892 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002893 if (ret_val)
2894 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002895 } else {
2896 old_bank_offset = nvm->flash_bank_size;
2897 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002898 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002899 if (ret_val)
2900 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002901 }
2902
2903 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00002904 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002906 * in the shadow RAM
2907 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002908 if (dev_spec->shadow_ram[i].modified) {
2909 data = dev_spec->shadow_ram[i].value;
2910 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002911 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2912 old_bank_offset,
2913 &data);
2914 if (ret_val)
2915 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002916 }
2917
Bruce Allane921eb12012-11-28 09:28:37 +00002918 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002919 * (15:14) are 11b until the commit has completed.
2920 * This will allow us to write 10b which indicates the
2921 * signature is valid. We want to do this after the write
2922 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002923 * while the write is still in progress
2924 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002925 if (i == E1000_ICH_NVM_SIG_WORD)
2926 data |= E1000_ICH_NVM_SIG_MASK;
2927
2928 /* Convert offset to bytes. */
2929 act_offset = (i + new_bank_offset) << 1;
2930
2931 udelay(100);
2932 /* Write the bytes to the new bank. */
2933 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2934 act_offset,
2935 (u8)data);
2936 if (ret_val)
2937 break;
2938
2939 udelay(100);
2940 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2941 act_offset + 1,
2942 (u8)(data >> 8));
2943 if (ret_val)
2944 break;
2945 }
2946
Bruce Allane921eb12012-11-28 09:28:37 +00002947 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07002948 * programming failed.
2949 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002950 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002951 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002952 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002953 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002954 }
2955
Bruce Allane921eb12012-11-28 09:28:37 +00002956 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002957 * to 10b in word 0x13 , this can be done without an
2958 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002959 * and we need to change bit 14 to 0b
2960 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002962 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002963 if (ret_val)
2964 goto release;
2965
Auke Kokbc7f75f2007-09-17 12:30:59 -07002966 data &= 0xBFFF;
2967 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2968 act_offset * 2 + 1,
2969 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002970 if (ret_val)
2971 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002972
Bruce Allane921eb12012-11-28 09:28:37 +00002973 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974 * its signature word (0x13) high_byte to 0b. This can be
2975 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002976 * to 1's. We can write 1's to 0's without an erase
2977 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002978 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2979 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002980 if (ret_val)
2981 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002982
2983 /* Great! Everything worked, we can now clear the cached entries. */
2984 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002985 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986 dev_spec->shadow_ram[i].value = 0xFFFF;
2987 }
2988
Bruce Allan9c5e2092010-05-10 15:00:31 +00002989release:
Bruce Allan94d81862009-11-20 23:25:26 +00002990 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002991
Bruce Allane921eb12012-11-28 09:28:37 +00002992 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002993 * until after the next adapter reset.
2994 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002995 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00002996 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00002997 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002998 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002999
Bruce Allane2434552008-11-21 17:02:41 -08003000out:
3001 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003002 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003003
Auke Kokbc7f75f2007-09-17 12:30:59 -07003004 return ret_val;
3005}
3006
3007/**
3008 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3009 * @hw: pointer to the HW structure
3010 *
3011 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3012 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3013 * calculated, in which case we need to calculate the checksum and set bit 6.
3014 **/
3015static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3016{
3017 s32 ret_val;
3018 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003019 u16 word;
3020 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003021
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003022 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3023 * the checksum needs to be fixed. This bit is an indication that
3024 * the NVM was prepared by OEM software and did not calculate
3025 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003026 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003027 switch (hw->mac.type) {
3028 case e1000_pch_lpt:
3029 word = NVM_COMPAT;
3030 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3031 break;
3032 default:
3033 word = NVM_FUTURE_INIT_WORD1;
3034 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3035 break;
3036 }
3037
3038 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003039 if (ret_val)
3040 return ret_val;
3041
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003042 if (!(data & valid_csum_mask)) {
3043 data |= valid_csum_mask;
3044 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003045 if (ret_val)
3046 return ret_val;
3047 ret_val = e1000e_update_nvm_checksum(hw);
3048 if (ret_val)
3049 return ret_val;
3050 }
3051
3052 return e1000e_validate_nvm_checksum_generic(hw);
3053}
3054
3055/**
Bruce Allan4a770352008-10-01 17:18:35 -07003056 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3057 * @hw: pointer to the HW structure
3058 *
3059 * To prevent malicious write/erase of the NVM, set it to be read-only
3060 * so that the hardware ignores all write/erase cycles of the NVM via
3061 * the flash control registers. The shadow-ram copy of the NVM will
3062 * still be updated, however any updates to this copy will not stick
3063 * across driver reloads.
3064 **/
3065void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3066{
Bruce Allanca15df52009-10-26 11:23:43 +00003067 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003068 union ich8_flash_protected_range pr0;
3069 union ich8_hws_flash_status hsfsts;
3070 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003071
Bruce Allan94d81862009-11-20 23:25:26 +00003072 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003073
3074 gfpreg = er32flash(ICH_FLASH_GFPREG);
3075
3076 /* Write-protect GbE Sector of NVM */
3077 pr0.regval = er32flash(ICH_FLASH_PR0);
3078 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3079 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3080 pr0.range.wpe = true;
3081 ew32flash(ICH_FLASH_PR0, pr0.regval);
3082
Bruce Allane921eb12012-11-28 09:28:37 +00003083 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003084 * PR0 to prevent the write-protection from being lifted.
3085 * Once FLOCKDN is set, the registers protected by it cannot
3086 * be written until FLOCKDN is cleared by a hardware reset.
3087 */
3088 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3089 hsfsts.hsf_status.flockdn = true;
3090 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3091
Bruce Allan94d81862009-11-20 23:25:26 +00003092 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003093}
3094
3095/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3097 * @hw: pointer to the HW structure
3098 * @offset: The offset (in bytes) of the byte/word to read.
3099 * @size: Size of data to read, 1=byte 2=word
3100 * @data: The byte(s) to write to the NVM.
3101 *
3102 * Writes one/two bytes to the NVM using the flash access registers.
3103 **/
3104static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3105 u8 size, u16 data)
3106{
3107 union ich8_hws_flash_status hsfsts;
3108 union ich8_hws_flash_ctrl hsflctl;
3109 u32 flash_linear_addr;
3110 u32 flash_data = 0;
3111 s32 ret_val;
3112 u8 count = 0;
3113
3114 if (size < 1 || size > 2 || data > size * 0xff ||
3115 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3116 return -E1000_ERR_NVM;
3117
3118 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3119 hw->nvm.flash_base_addr;
3120
3121 do {
3122 udelay(1);
3123 /* Steps */
3124 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3125 if (ret_val)
3126 break;
3127
3128 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3129 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
3130 hsflctl.hsf_ctrl.fldbcount = size -1;
3131 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3132 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3133
3134 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3135
3136 if (size == 1)
3137 flash_data = (u32)data & 0x00FF;
3138 else
3139 flash_data = (u32)data;
3140
3141 ew32flash(ICH_FLASH_FDATA0, flash_data);
3142
Bruce Allane921eb12012-11-28 09:28:37 +00003143 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003144 * and try the whole sequence a few more times else done
3145 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003146 ret_val = e1000_flash_cycle_ich8lan(hw,
3147 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
3148 if (!ret_val)
3149 break;
3150
Bruce Allane921eb12012-11-28 09:28:37 +00003151 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003152 * completely hosed, but if the error condition
3153 * is detected, it won't hurt to give it another
3154 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3155 */
3156 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003157 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003158 /* Repeat for some time before giving up. */
3159 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003160 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003161 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003162 break;
3163 }
3164 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3165
3166 return ret_val;
3167}
3168
3169/**
3170 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3171 * @hw: pointer to the HW structure
3172 * @offset: The index of the byte to read.
3173 * @data: The byte to write to the NVM.
3174 *
3175 * Writes a single byte to the NVM using the flash access registers.
3176 **/
3177static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3178 u8 data)
3179{
3180 u16 word = (u16)data;
3181
3182 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3183}
3184
3185/**
3186 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3187 * @hw: pointer to the HW structure
3188 * @offset: The offset of the byte to write.
3189 * @byte: The byte to write to the NVM.
3190 *
3191 * Writes a single byte to the NVM using the flash access registers.
3192 * Goes through a retry algorithm before giving up.
3193 **/
3194static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3195 u32 offset, u8 byte)
3196{
3197 s32 ret_val;
3198 u16 program_retries;
3199
3200 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3201 if (!ret_val)
3202 return ret_val;
3203
3204 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003205 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003206 udelay(100);
3207 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3208 if (!ret_val)
3209 break;
3210 }
3211 if (program_retries == 100)
3212 return -E1000_ERR_NVM;
3213
3214 return 0;
3215}
3216
3217/**
3218 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3219 * @hw: pointer to the HW structure
3220 * @bank: 0 for first bank, 1 for second bank, etc.
3221 *
3222 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3223 * bank N is 4096 * N + flash_reg_addr.
3224 **/
3225static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3226{
3227 struct e1000_nvm_info *nvm = &hw->nvm;
3228 union ich8_hws_flash_status hsfsts;
3229 union ich8_hws_flash_ctrl hsflctl;
3230 u32 flash_linear_addr;
3231 /* bank size is in 16bit words - adjust to bytes */
3232 u32 flash_bank_size = nvm->flash_bank_size * 2;
3233 s32 ret_val;
3234 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003235 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003236
3237 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3238
Bruce Allane921eb12012-11-28 09:28:37 +00003239 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003240 * register
3241 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003242 * consecutive sectors. The start index for the nth Hw sector
3243 * can be calculated as = bank * 4096 + n * 256
3244 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3245 * The start index for the nth Hw sector can be calculated
3246 * as = bank * 4096
3247 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3248 * (ich9 only, otherwise error condition)
3249 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3250 */
3251 switch (hsfsts.hsf_status.berasesz) {
3252 case 0:
3253 /* Hw sector size 256 */
3254 sector_size = ICH_FLASH_SEG_SIZE_256;
3255 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3256 break;
3257 case 1:
3258 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003259 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003260 break;
3261 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003262 sector_size = ICH_FLASH_SEG_SIZE_8K;
3263 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003264 break;
3265 case 3:
3266 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003267 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003268 break;
3269 default:
3270 return -E1000_ERR_NVM;
3271 }
3272
3273 /* Start with the base address, then add the sector offset. */
3274 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003275 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003276
3277 for (j = 0; j < iteration ; j++) {
3278 do {
3279 /* Steps */
3280 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3281 if (ret_val)
3282 return ret_val;
3283
Bruce Allane921eb12012-11-28 09:28:37 +00003284 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003285 * Cycle field in hw flash control
3286 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003287 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3288 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3289 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3290
Bruce Allane921eb12012-11-28 09:28:37 +00003291 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003292 * block into Flash Linear address field in Flash
3293 * Address.
3294 */
3295 flash_linear_addr += (j * sector_size);
3296 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3297
3298 ret_val = e1000_flash_cycle_ich8lan(hw,
3299 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003300 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301 break;
3302
Bruce Allane921eb12012-11-28 09:28:37 +00003303 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003304 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003305 * a few more times else Done
3306 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003307 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003308 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003309 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003310 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003311 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003312 return ret_val;
3313 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3314 }
3315
3316 return 0;
3317}
3318
3319/**
3320 * e1000_valid_led_default_ich8lan - Set the default LED settings
3321 * @hw: pointer to the HW structure
3322 * @data: Pointer to the LED settings
3323 *
3324 * Reads the LED default settings from the NVM to data. If the NVM LED
3325 * settings is all 0's or F's, set the LED default to a valid LED default
3326 * setting.
3327 **/
3328static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3329{
3330 s32 ret_val;
3331
3332 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3333 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003334 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003335 return ret_val;
3336 }
3337
3338 if (*data == ID_LED_RESERVED_0000 ||
3339 *data == ID_LED_RESERVED_FFFF)
3340 *data = ID_LED_DEFAULT_ICH8LAN;
3341
3342 return 0;
3343}
3344
3345/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003346 * e1000_id_led_init_pchlan - store LED configurations
3347 * @hw: pointer to the HW structure
3348 *
3349 * PCH does not control LEDs via the LEDCTL register, rather it uses
3350 * the PHY LED configuration register.
3351 *
3352 * PCH also does not have an "always on" or "always off" mode which
3353 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003354 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003355 * use "link_up" mode. The LEDs will still ID on request if there is no
3356 * link based on logic in e1000_led_[on|off]_pchlan().
3357 **/
3358static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3359{
3360 struct e1000_mac_info *mac = &hw->mac;
3361 s32 ret_val;
3362 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3363 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3364 u16 data, i, temp, shift;
3365
3366 /* Get default ID LED modes */
3367 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3368 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003369 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003370
3371 mac->ledctl_default = er32(LEDCTL);
3372 mac->ledctl_mode1 = mac->ledctl_default;
3373 mac->ledctl_mode2 = mac->ledctl_default;
3374
3375 for (i = 0; i < 4; i++) {
3376 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3377 shift = (i * 5);
3378 switch (temp) {
3379 case ID_LED_ON1_DEF2:
3380 case ID_LED_ON1_ON2:
3381 case ID_LED_ON1_OFF2:
3382 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3383 mac->ledctl_mode1 |= (ledctl_on << shift);
3384 break;
3385 case ID_LED_OFF1_DEF2:
3386 case ID_LED_OFF1_ON2:
3387 case ID_LED_OFF1_OFF2:
3388 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3389 mac->ledctl_mode1 |= (ledctl_off << shift);
3390 break;
3391 default:
3392 /* Do nothing */
3393 break;
3394 }
3395 switch (temp) {
3396 case ID_LED_DEF1_ON2:
3397 case ID_LED_ON1_ON2:
3398 case ID_LED_OFF1_ON2:
3399 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3400 mac->ledctl_mode2 |= (ledctl_on << shift);
3401 break;
3402 case ID_LED_DEF1_OFF2:
3403 case ID_LED_ON1_OFF2:
3404 case ID_LED_OFF1_OFF2:
3405 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3406 mac->ledctl_mode2 |= (ledctl_off << shift);
3407 break;
3408 default:
3409 /* Do nothing */
3410 break;
3411 }
3412 }
3413
Bruce Allan5015e532012-02-08 02:55:56 +00003414 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003415}
3416
3417/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003418 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3419 * @hw: pointer to the HW structure
3420 *
3421 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3422 * register, so the the bus width is hard coded.
3423 **/
3424static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3425{
3426 struct e1000_bus_info *bus = &hw->bus;
3427 s32 ret_val;
3428
3429 ret_val = e1000e_get_bus_info_pcie(hw);
3430
Bruce Allane921eb12012-11-28 09:28:37 +00003431 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003432 * a configuration space, but do not contain
3433 * PCI Express Capability registers, so bus width
3434 * must be hardcoded.
3435 */
3436 if (bus->width == e1000_bus_width_unknown)
3437 bus->width = e1000_bus_width_pcie_x1;
3438
3439 return ret_val;
3440}
3441
3442/**
3443 * e1000_reset_hw_ich8lan - Reset the hardware
3444 * @hw: pointer to the HW structure
3445 *
3446 * Does a full reset of the hardware which includes a reset of the PHY and
3447 * MAC.
3448 **/
3449static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3450{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003451 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003452 u16 kum_cfg;
3453 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003454 s32 ret_val;
3455
Bruce Allane921eb12012-11-28 09:28:37 +00003456 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003457 * on the last TLP read/write transaction when MAC is reset.
3458 */
3459 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003460 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003461 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003462
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003463 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003464 ew32(IMC, 0xffffffff);
3465
Bruce Allane921eb12012-11-28 09:28:37 +00003466 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003467 * any pending transactions to complete before we hit the MAC
3468 * with the global reset.
3469 */
3470 ew32(RCTL, 0);
3471 ew32(TCTL, E1000_TCTL_PSP);
3472 e1e_flush();
3473
Bruce Allan1bba4382011-03-19 00:27:20 +00003474 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003475
3476 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3477 if (hw->mac.type == e1000_ich8lan) {
3478 /* Set Tx and Rx buffer allocation to 8k apiece. */
3479 ew32(PBA, E1000_PBA_8K);
3480 /* Set Packet Buffer Size to 16k. */
3481 ew32(PBS, E1000_PBS_16K);
3482 }
3483
Bruce Allan1d5846b2009-10-29 13:46:05 +00003484 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003485 /* Save the NVM K1 bit setting */
3486 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003487 if (ret_val)
3488 return ret_val;
3489
Bruce Allan62bc8132012-03-20 03:47:57 +00003490 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003491 dev_spec->nvm_k1_enabled = true;
3492 else
3493 dev_spec->nvm_k1_enabled = false;
3494 }
3495
Auke Kokbc7f75f2007-09-17 12:30:59 -07003496 ctrl = er32(CTRL);
3497
Bruce Allan44abd5c2012-02-22 09:02:37 +00003498 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003499 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003500 * time to make sure the interface between MAC and the
3501 * external PHY is reset.
3502 */
3503 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003504
Bruce Allane921eb12012-11-28 09:28:37 +00003505 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003506 * non-managed 82579
3507 */
3508 if ((hw->mac.type == e1000_pch2lan) &&
3509 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3510 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003511 }
3512 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003513 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003514 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003515 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003516 msleep(20);
3517
Bruce Allan62bc8132012-03-20 03:47:57 +00003518 /* Set Phy Config Counter to 50msec */
3519 if (hw->mac.type == e1000_pch2lan) {
3520 reg = er32(FEXTNVM3);
3521 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3522 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3523 ew32(FEXTNVM3, reg);
3524 }
3525
Bruce Allanfc0c7762009-07-01 13:27:55 +00003526 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003527 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003528
Bruce Allane98cac42010-05-10 15:02:32 +00003529 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003530 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003531 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003532 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003533
Bruce Allane98cac42010-05-10 15:02:32 +00003534 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003535 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003536 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003537 }
Bruce Allane98cac42010-05-10 15:02:32 +00003538
Bruce Allane921eb12012-11-28 09:28:37 +00003539 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003540 * will be detected as a CRC error and be dropped rather than show up
3541 * as a bad packet to the DMA engine.
3542 */
3543 if (hw->mac.type == e1000_pchlan)
3544 ew32(CRC_OFFSET, 0x65656565);
3545
Auke Kokbc7f75f2007-09-17 12:30:59 -07003546 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003547 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003548
Bruce Allan62bc8132012-03-20 03:47:57 +00003549 reg = er32(KABGTXD);
3550 reg |= E1000_KABGTXD_BGSQLBIAS;
3551 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003552
Bruce Allan5015e532012-02-08 02:55:56 +00003553 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003554}
3555
3556/**
3557 * e1000_init_hw_ich8lan - Initialize the hardware
3558 * @hw: pointer to the HW structure
3559 *
3560 * Prepares the hardware for transmit and receive by doing the following:
3561 * - initialize hardware bits
3562 * - initialize LED identification
3563 * - setup receive address registers
3564 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003565 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003566 * - clear statistics
3567 **/
3568static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3569{
3570 struct e1000_mac_info *mac = &hw->mac;
3571 u32 ctrl_ext, txdctl, snoop;
3572 s32 ret_val;
3573 u16 i;
3574
3575 e1000_initialize_hw_bits_ich8lan(hw);
3576
3577 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003578 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00003579 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003580 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00003581 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003582
3583 /* Setup the receive address. */
3584 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3585
3586 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003587 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003588 for (i = 0; i < mac->mta_reg_count; i++)
3589 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3590
Bruce Allane921eb12012-11-28 09:28:37 +00003591 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003592 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003593 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3594 */
3595 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003596 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3597 i &= ~BM_WUC_HOST_WU_BIT;
3598 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003599 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3600 if (ret_val)
3601 return ret_val;
3602 }
3603
Auke Kokbc7f75f2007-09-17 12:30:59 -07003604 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003605 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003606
3607 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003608 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003609 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3610 E1000_TXDCTL_FULL_TX_DESC_WB;
3611 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3612 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003613 ew32(TXDCTL(0), txdctl);
3614 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003615 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3616 E1000_TXDCTL_FULL_TX_DESC_WB;
3617 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3618 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003619 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003620
Bruce Allane921eb12012-11-28 09:28:37 +00003621 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003622 * By default, we should use snoop behavior.
3623 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003624 if (mac->type == e1000_ich8lan)
3625 snoop = PCIE_ICH8_SNOOP_ALL;
3626 else
3627 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
3628 e1000e_set_pcie_no_snoop(hw, snoop);
3629
3630 ctrl_ext = er32(CTRL_EXT);
3631 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3632 ew32(CTRL_EXT, ctrl_ext);
3633
Bruce Allane921eb12012-11-28 09:28:37 +00003634 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003635 * important that we do this after we have tried to establish link
3636 * because the symbol error count will increment wildly if there
3637 * is no link.
3638 */
3639 e1000_clear_hw_cntrs_ich8lan(hw);
3640
Bruce Allane561a702012-02-08 02:55:46 +00003641 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003642}
3643/**
3644 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3645 * @hw: pointer to the HW structure
3646 *
3647 * Sets/Clears required hardware bits necessary for correctly setting up the
3648 * hardware for transmit and receive.
3649 **/
3650static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3651{
3652 u32 reg;
3653
3654 /* Extended Device Control */
3655 reg = er32(CTRL_EXT);
3656 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003657 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3658 if (hw->mac.type >= e1000_pchlan)
3659 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003660 ew32(CTRL_EXT, reg);
3661
3662 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003663 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003664 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003665 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003666
3667 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003668 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003669 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003670 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003671
3672 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003673 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003674 if (hw->mac.type == e1000_ich8lan)
3675 reg |= (1 << 28) | (1 << 29);
3676 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003677 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003678
3679 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003680 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681 if (er32(TCTL) & E1000_TCTL_MULR)
3682 reg &= ~(1 << 28);
3683 else
3684 reg |= (1 << 28);
3685 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003686 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003687
3688 /* Device Status */
3689 if (hw->mac.type == e1000_ich8lan) {
3690 reg = er32(STATUS);
3691 reg &= ~(1 << 31);
3692 ew32(STATUS, reg);
3693 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003694
Bruce Allane921eb12012-11-28 09:28:37 +00003695 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003696 * traffic, just disable the nfs filtering capability
3697 */
3698 reg = er32(RFCTL);
3699 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003700
Bruce Allane921eb12012-11-28 09:28:37 +00003701 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003702 * IPv6 headers can hang the Rx.
3703 */
3704 if (hw->mac.type == e1000_ich8lan)
3705 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003706 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00003707
3708 /* Enable ECC on Lynxpoint */
3709 if (hw->mac.type == e1000_pch_lpt) {
3710 reg = er32(PBECCSTS);
3711 reg |= E1000_PBECCSTS_ECC_ENABLE;
3712 ew32(PBECCSTS, reg);
3713
3714 reg = er32(CTRL);
3715 reg |= E1000_CTRL_MEHE;
3716 ew32(CTRL, reg);
3717 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003718}
3719
3720/**
3721 * e1000_setup_link_ich8lan - Setup flow control and link settings
3722 * @hw: pointer to the HW structure
3723 *
3724 * Determines which flow control settings to use, then configures flow
3725 * control. Calls the appropriate media-specific link configuration
3726 * function. Assuming the adapter has a valid link partner, a valid link
3727 * should be established. Assumes the hardware has previously been reset
3728 * and the transmitter and receiver are not enabled.
3729 **/
3730static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3731{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003732 s32 ret_val;
3733
Bruce Allan44abd5c2012-02-22 09:02:37 +00003734 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003735 return 0;
3736
Bruce Allane921eb12012-11-28 09:28:37 +00003737 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003738 * the default flow control setting, so we explicitly
3739 * set it to full.
3740 */
Bruce Allan37289d92009-06-02 11:29:37 +00003741 if (hw->fc.requested_mode == e1000_fc_default) {
3742 /* Workaround h/w hang when Tx flow control enabled */
3743 if (hw->mac.type == e1000_pchlan)
3744 hw->fc.requested_mode = e1000_fc_rx_pause;
3745 else
3746 hw->fc.requested_mode = e1000_fc_full;
3747 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003748
Bruce Allane921eb12012-11-28 09:28:37 +00003749 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003750 * on the link partner's capabilities, we may or may not use this mode.
3751 */
3752 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003753
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003754 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003755 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003756
3757 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003758 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759 if (ret_val)
3760 return ret_val;
3761
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003762 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003763 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003764 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003765 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003766 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003767 ew32(FCRTV_PCH, hw->fc.refresh_time);
3768
Bruce Allan482fed82011-01-06 14:29:49 +00003769 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3770 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003771 if (ret_val)
3772 return ret_val;
3773 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003774
3775 return e1000e_set_fc_watermarks(hw);
3776}
3777
3778/**
3779 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3780 * @hw: pointer to the HW structure
3781 *
3782 * Configures the kumeran interface to the PHY to wait the appropriate time
3783 * when polling the PHY, then call the generic setup_copper_link to finish
3784 * configuring the copper link.
3785 **/
3786static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3787{
3788 u32 ctrl;
3789 s32 ret_val;
3790 u16 reg_data;
3791
3792 ctrl = er32(CTRL);
3793 ctrl |= E1000_CTRL_SLU;
3794 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3795 ew32(CTRL, ctrl);
3796
Bruce Allane921eb12012-11-28 09:28:37 +00003797 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003798 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003799 * this fixes erroneous timeouts at 10Mbps.
3800 */
Bruce Allan07818952009-12-08 07:28:01 +00003801 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003802 if (ret_val)
3803 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003804 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3805 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003806 if (ret_val)
3807 return ret_val;
3808 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003809 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3810 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003811 if (ret_val)
3812 return ret_val;
3813
Bruce Allana4f58f52009-06-02 11:29:18 +00003814 switch (hw->phy.type) {
3815 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003816 ret_val = e1000e_copper_link_setup_igp(hw);
3817 if (ret_val)
3818 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003819 break;
3820 case e1000_phy_bm:
3821 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003822 ret_val = e1000e_copper_link_setup_m88(hw);
3823 if (ret_val)
3824 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003825 break;
3826 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003827 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003828 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +00003829 ret_val = e1000_copper_link_setup_82577(hw);
3830 if (ret_val)
3831 return ret_val;
3832 break;
3833 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003834 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003835 if (ret_val)
3836 return ret_val;
3837
3838 reg_data &= ~IFE_PMC_AUTO_MDIX;
3839
3840 switch (hw->phy.mdix) {
3841 case 1:
3842 reg_data &= ~IFE_PMC_FORCE_MDIX;
3843 break;
3844 case 2:
3845 reg_data |= IFE_PMC_FORCE_MDIX;
3846 break;
3847 case 0:
3848 default:
3849 reg_data |= IFE_PMC_AUTO_MDIX;
3850 break;
3851 }
Bruce Allan482fed82011-01-06 14:29:49 +00003852 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003853 if (ret_val)
3854 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003855 break;
3856 default:
3857 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003858 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003859
Auke Kokbc7f75f2007-09-17 12:30:59 -07003860 return e1000e_setup_copper_link(hw);
3861}
3862
3863/**
3864 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3865 * @hw: pointer to the HW structure
3866 * @speed: pointer to store current link speed
3867 * @duplex: pointer to store the current link duplex
3868 *
Bruce Allanad680762008-03-28 09:15:03 -07003869 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003870 * information and then calls the Kumeran lock loss workaround for links at
3871 * gigabit speeds.
3872 **/
3873static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3874 u16 *duplex)
3875{
3876 s32 ret_val;
3877
3878 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3879 if (ret_val)
3880 return ret_val;
3881
3882 if ((hw->mac.type == e1000_ich8lan) &&
3883 (hw->phy.type == e1000_phy_igp_3) &&
3884 (*speed == SPEED_1000)) {
3885 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3886 }
3887
3888 return ret_val;
3889}
3890
3891/**
3892 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3893 * @hw: pointer to the HW structure
3894 *
3895 * Work-around for 82566 Kumeran PCS lock loss:
3896 * On link status change (i.e. PCI reset, speed change) and link is up and
3897 * speed is gigabit-
3898 * 0) if workaround is optionally disabled do nothing
3899 * 1) wait 1ms for Kumeran link to come up
3900 * 2) check Kumeran Diagnostic register PCS lock loss bit
3901 * 3) if not set the link is locked (all is good), otherwise...
3902 * 4) reset the PHY
3903 * 5) repeat up to 10 times
3904 * Note: this is only called for IGP3 copper when speed is 1gb.
3905 **/
3906static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3907{
3908 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3909 u32 phy_ctrl;
3910 s32 ret_val;
3911 u16 i, data;
3912 bool link;
3913
3914 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3915 return 0;
3916
Bruce Allane921eb12012-11-28 09:28:37 +00003917 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003918 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003919 * stability
3920 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003921 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3922 if (!link)
3923 return 0;
3924
3925 for (i = 0; i < 10; i++) {
3926 /* read once to clear */
3927 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3928 if (ret_val)
3929 return ret_val;
3930 /* and again to get new status */
3931 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3932 if (ret_val)
3933 return ret_val;
3934
3935 /* check for PCS lock */
3936 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3937 return 0;
3938
3939 /* Issue PHY reset */
3940 e1000_phy_hw_reset(hw);
3941 mdelay(5);
3942 }
3943 /* Disable GigE link negotiation */
3944 phy_ctrl = er32(PHY_CTRL);
3945 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3946 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3947 ew32(PHY_CTRL, phy_ctrl);
3948
Bruce Allane921eb12012-11-28 09:28:37 +00003949 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07003950 * any PHY registers
3951 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003952 e1000e_gig_downshift_workaround_ich8lan(hw);
3953
3954 /* unable to acquire PCS lock */
3955 return -E1000_ERR_PHY;
3956}
3957
3958/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00003959 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003960 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003961 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003962 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003963 * If ICH8, set the current Kumeran workaround state (enabled - true
3964 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003965 **/
3966void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3967 bool state)
3968{
3969 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3970
3971 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003972 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003973 return;
3974 }
3975
3976 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3977}
3978
3979/**
3980 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3981 * @hw: pointer to the HW structure
3982 *
3983 * Workaround for 82566 power-down on D3 entry:
3984 * 1) disable gigabit link
3985 * 2) write VR power-down enable
3986 * 3) read it back
3987 * Continue if successful, else issue LCD reset and repeat
3988 **/
3989void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3990{
3991 u32 reg;
3992 u16 data;
3993 u8 retry = 0;
3994
3995 if (hw->phy.type != e1000_phy_igp_3)
3996 return;
3997
3998 /* Try the workaround twice (if needed) */
3999 do {
4000 /* Disable link */
4001 reg = er32(PHY_CTRL);
4002 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4003 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4004 ew32(PHY_CTRL, reg);
4005
Bruce Allane921eb12012-11-28 09:28:37 +00004006 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07004007 * accessing any PHY registers
4008 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004009 if (hw->mac.type == e1000_ich8lan)
4010 e1000e_gig_downshift_workaround_ich8lan(hw);
4011
4012 /* Write VR power-down enable */
4013 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4014 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4015 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4016
4017 /* Read it back and test */
4018 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4019 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4020 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4021 break;
4022
4023 /* Issue PHY reset and repeat at most one more time */
4024 reg = er32(CTRL);
4025 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4026 retry++;
4027 } while (retry);
4028}
4029
4030/**
4031 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4032 * @hw: pointer to the HW structure
4033 *
4034 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004035 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004036 * 1) Set Kumeran Near-end loopback
4037 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004038 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039 **/
4040void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4041{
4042 s32 ret_val;
4043 u16 reg_data;
4044
Bruce Allan462d5992011-09-30 08:07:11 +00004045 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004046 return;
4047
4048 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4049 &reg_data);
4050 if (ret_val)
4051 return;
4052 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4053 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4054 reg_data);
4055 if (ret_val)
4056 return;
4057 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
4058 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4059 reg_data);
4060}
4061
4062/**
Bruce Allan99730e42011-05-13 07:19:48 +00004063 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004064 * @hw: pointer to the HW structure
4065 *
4066 * During S0 to Sx transition, it is possible the link remains at gig
4067 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004068 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4069 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4070 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4071 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004072 * Parts that support (and are linked to a partner which support) EEE in
4073 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4074 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004075 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004076void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004077{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004078 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004079 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004080 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004081
Bruce Allan17f085d2010-06-17 18:59:48 +00004082 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004083 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004084 if (hw->phy.type == e1000_phy_i217) {
4085 u16 phy_reg;
4086
4087 ret_val = hw->phy.ops.acquire(hw);
4088 if (ret_val)
4089 goto out;
4090
4091 if (!dev_spec->eee_disable) {
4092 u16 eee_advert;
4093
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004094 ret_val =
4095 e1000_read_emi_reg_locked(hw,
4096 I217_EEE_ADVERTISEMENT,
4097 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004098 if (ret_val)
4099 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004100
Bruce Allane921eb12012-11-28 09:28:37 +00004101 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004102 * EEE and 100Full is advertised on both ends of the
4103 * link.
4104 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004105 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004106 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004107 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004108 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4109 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4110 E1000_PHY_CTRL_NOND0A_LPLU);
4111 }
4112
Bruce Allane921eb12012-11-28 09:28:37 +00004113 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004114 * when the system is going into Sx and no manageability engine
4115 * is present, the driver must configure proxy to reset only on
4116 * power good. LPI (Low Power Idle) state must also reset only
4117 * on power good, as well as the MTA (Multicast table array).
4118 * The SMBus release must also be disabled on LCD reset.
4119 */
4120 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
4121
4122 /* Enable proxy to reset only on power good. */
4123 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4124 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4125 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4126
Bruce Allane921eb12012-11-28 09:28:37 +00004127 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004128 * power good.
4129 */
4130 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004131 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004132 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4133
4134 /* Disable the SMB release on LCD reset. */
4135 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004136 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004137 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4138 }
4139
Bruce Allane921eb12012-11-28 09:28:37 +00004140 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004141 * Support
4142 */
4143 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004144 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004145 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4146
4147release:
4148 hw->phy.ops.release(hw);
4149 }
4150out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004151 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004152
Bruce Allan462d5992011-09-30 08:07:11 +00004153 if (hw->mac.type == e1000_ich8lan)
4154 e1000e_gig_downshift_workaround_ich8lan(hw);
4155
Bruce Allan8395ae82010-09-22 17:15:08 +00004156 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004157 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004158
4159 /* Reset PHY to activate OEM bits on 82577/8 */
4160 if (hw->mac.type == e1000_pchlan)
4161 e1000e_phy_hw_reset_generic(hw);
4162
Bruce Allan8395ae82010-09-22 17:15:08 +00004163 ret_val = hw->phy.ops.acquire(hw);
4164 if (ret_val)
4165 return;
4166 e1000_write_smbus_addr(hw);
4167 hw->phy.ops.release(hw);
4168 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004169}
4170
4171/**
Bruce Allan99730e42011-05-13 07:19:48 +00004172 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4173 * @hw: pointer to the HW structure
4174 *
4175 * During Sx to S0 transitions on non-managed devices or managed devices
4176 * on which PHY resets are not blocked, if the PHY registers cannot be
4177 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4178 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004179 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004180 **/
4181void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4182{
Bruce Allan90b82982011-12-16 00:46:33 +00004183 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004184
Bruce Allancb17aab2012-04-13 03:16:22 +00004185 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004186 return;
4187
Bruce Allancb17aab2012-04-13 03:16:22 +00004188 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004189 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004190 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004191 return;
4192 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004193
Bruce Allane921eb12012-11-28 09:28:37 +00004194 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004195 * is transitioning from Sx and no manageability engine is present
4196 * configure SMBus to restore on reset, disable proxy, and enable
4197 * the reset on MTA (Multicast table array).
4198 */
4199 if (hw->phy.type == e1000_phy_i217) {
4200 u16 phy_reg;
4201
4202 ret_val = hw->phy.ops.acquire(hw);
4203 if (ret_val) {
4204 e_dbg("Failed to setup iRST\n");
4205 return;
4206 }
4207
4208 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004209 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004210 * is present
4211 */
4212 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4213 if (ret_val)
4214 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004215 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004216 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4217
4218 /* Disable Proxy */
4219 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4220 }
4221 /* Enable reset on MTA */
4222 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4223 if (ret_val)
4224 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004225 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004226 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4227release:
4228 if (ret_val)
4229 e_dbg("Error %d in resume workarounds\n", ret_val);
4230 hw->phy.ops.release(hw);
4231 }
Bruce Allan99730e42011-05-13 07:19:48 +00004232}
4233
4234/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004235 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4236 * @hw: pointer to the HW structure
4237 *
4238 * Return the LED back to the default configuration.
4239 **/
4240static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4241{
4242 if (hw->phy.type == e1000_phy_ife)
4243 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4244
4245 ew32(LEDCTL, hw->mac.ledctl_default);
4246 return 0;
4247}
4248
4249/**
Auke Kok489815c2008-02-21 15:11:07 -08004250 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004251 * @hw: pointer to the HW structure
4252 *
Auke Kok489815c2008-02-21 15:11:07 -08004253 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004254 **/
4255static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4256{
4257 if (hw->phy.type == e1000_phy_ife)
4258 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4259 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4260
4261 ew32(LEDCTL, hw->mac.ledctl_mode2);
4262 return 0;
4263}
4264
4265/**
Auke Kok489815c2008-02-21 15:11:07 -08004266 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004267 * @hw: pointer to the HW structure
4268 *
Auke Kok489815c2008-02-21 15:11:07 -08004269 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004270 **/
4271static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4272{
4273 if (hw->phy.type == e1000_phy_ife)
4274 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004275 (IFE_PSCL_PROBE_MODE |
4276 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004277
4278 ew32(LEDCTL, hw->mac.ledctl_mode1);
4279 return 0;
4280}
4281
4282/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004283 * e1000_setup_led_pchlan - Configures SW controllable LED
4284 * @hw: pointer to the HW structure
4285 *
4286 * This prepares the SW controllable LED for use.
4287 **/
4288static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4289{
Bruce Allan482fed82011-01-06 14:29:49 +00004290 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004291}
4292
4293/**
4294 * e1000_cleanup_led_pchlan - Restore the default LED operation
4295 * @hw: pointer to the HW structure
4296 *
4297 * Return the LED back to the default configuration.
4298 **/
4299static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4300{
Bruce Allan482fed82011-01-06 14:29:49 +00004301 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004302}
4303
4304/**
4305 * e1000_led_on_pchlan - Turn LEDs on
4306 * @hw: pointer to the HW structure
4307 *
4308 * Turn on the LEDs.
4309 **/
4310static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4311{
4312 u16 data = (u16)hw->mac.ledctl_mode2;
4313 u32 i, led;
4314
Bruce Allane921eb12012-11-28 09:28:37 +00004315 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004316 * for each LED that's mode is "link_up" in ledctl_mode2.
4317 */
4318 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4319 for (i = 0; i < 3; i++) {
4320 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4321 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4322 E1000_LEDCTL_MODE_LINK_UP)
4323 continue;
4324 if (led & E1000_PHY_LED0_IVRT)
4325 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4326 else
4327 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4328 }
4329 }
4330
Bruce Allan482fed82011-01-06 14:29:49 +00004331 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004332}
4333
4334/**
4335 * e1000_led_off_pchlan - Turn LEDs off
4336 * @hw: pointer to the HW structure
4337 *
4338 * Turn off the LEDs.
4339 **/
4340static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4341{
4342 u16 data = (u16)hw->mac.ledctl_mode1;
4343 u32 i, led;
4344
Bruce Allane921eb12012-11-28 09:28:37 +00004345 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004346 * for each LED that's mode is "link_up" in ledctl_mode1.
4347 */
4348 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4349 for (i = 0; i < 3; i++) {
4350 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4351 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4352 E1000_LEDCTL_MODE_LINK_UP)
4353 continue;
4354 if (led & E1000_PHY_LED0_IVRT)
4355 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4356 else
4357 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4358 }
4359 }
4360
Bruce Allan482fed82011-01-06 14:29:49 +00004361 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004362}
4363
4364/**
Bruce Allane98cac42010-05-10 15:02:32 +00004365 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004366 * @hw: pointer to the HW structure
4367 *
Bruce Allane98cac42010-05-10 15:02:32 +00004368 * Read appropriate register for the config done bit for completion status
4369 * and configure the PHY through s/w for EEPROM-less parts.
4370 *
4371 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4372 * config done bit, so only an error is logged and continues. If we were
4373 * to return with error, EEPROM-less silicon would not be able to be reset
4374 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004375 **/
4376static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4377{
Bruce Allane98cac42010-05-10 15:02:32 +00004378 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004379 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004380 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004381
Bruce Allanf4187b52008-08-26 18:36:50 -07004382 e1000e_get_cfg_done(hw);
4383
Bruce Allane98cac42010-05-10 15:02:32 +00004384 /* Wait for indication from h/w that it has completed basic config */
4385 if (hw->mac.type >= e1000_ich10lan) {
4386 e1000_lan_init_done_ich8lan(hw);
4387 } else {
4388 ret_val = e1000e_get_auto_rd_done(hw);
4389 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004390 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004391 * return with an error. This can happen in situations
4392 * where there is no eeprom and prevents getting link.
4393 */
4394 e_dbg("Auto Read Done did not complete\n");
4395 ret_val = 0;
4396 }
4397 }
4398
4399 /* Clear PHY Reset Asserted bit */
4400 status = er32(STATUS);
4401 if (status & E1000_STATUS_PHYRA)
4402 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4403 else
4404 e_dbg("PHY Reset Asserted not set - needs delay\n");
4405
Bruce Allanf4187b52008-08-26 18:36:50 -07004406 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004407 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004408 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004409 (hw->phy.type == e1000_phy_igp_3)) {
4410 e1000e_phy_init_script_igp3(hw);
4411 }
4412 } else {
4413 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4414 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004415 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004416 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004417 }
4418 }
4419
Bruce Allane98cac42010-05-10 15:02:32 +00004420 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004421}
4422
4423/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004424 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4425 * @hw: pointer to the HW structure
4426 *
4427 * In the case of a PHY power down to save power, or to turn off link during a
4428 * driver unload, or wake on lan is not enabled, remove the link.
4429 **/
4430static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4431{
4432 /* If the management interface is not enabled, then power down */
4433 if (!(hw->mac.ops.check_mng_mode(hw) ||
4434 hw->phy.ops.check_reset_block(hw)))
4435 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004436}
4437
4438/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004439 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4440 * @hw: pointer to the HW structure
4441 *
4442 * Clears hardware counters specific to the silicon family and calls
4443 * clear_hw_cntrs_generic to clear all general purpose counters.
4444 **/
4445static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4446{
Bruce Allana4f58f52009-06-02 11:29:18 +00004447 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004448 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004449
4450 e1000e_clear_hw_cntrs_base(hw);
4451
Bruce Allan99673d92009-11-20 23:27:21 +00004452 er32(ALGNERRC);
4453 er32(RXERRC);
4454 er32(TNCRS);
4455 er32(CEXTERR);
4456 er32(TSCTC);
4457 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004458
Bruce Allan99673d92009-11-20 23:27:21 +00004459 er32(MGTPRC);
4460 er32(MGTPDC);
4461 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004462
Bruce Allan99673d92009-11-20 23:27:21 +00004463 er32(IAC);
4464 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004465
Bruce Allana4f58f52009-06-02 11:29:18 +00004466 /* Clear PHY statistics registers */
4467 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004468 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004469 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004470 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004471 ret_val = hw->phy.ops.acquire(hw);
4472 if (ret_val)
4473 return;
4474 ret_val = hw->phy.ops.set_page(hw,
4475 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4476 if (ret_val)
4477 goto release;
4478 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4479 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4480 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4481 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4482 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4483 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4484 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4485 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4486 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4487 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4488 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4489 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4490 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4491 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4492release:
4493 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004494 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004495}
4496
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004497static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004498 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004499 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004500 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004501 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4502 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004503 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004504 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004505 /* led_on dependent on mac type */
4506 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004507 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004508 .reset_hw = e1000_reset_hw_ich8lan,
4509 .init_hw = e1000_init_hw_ich8lan,
4510 .setup_link = e1000_setup_link_ich8lan,
4511 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004512 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004513 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004514 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004515};
4516
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004517static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004518 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004519 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004520 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004521 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004522 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004523 .read_reg = e1000e_read_phy_reg_igp,
4524 .release = e1000_release_swflag_ich8lan,
4525 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004526 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4527 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004528 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004529};
4530
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004531static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004532 .acquire = e1000_acquire_nvm_ich8lan,
4533 .read = e1000_read_nvm_ich8lan,
4534 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004535 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004536 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004537 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004538 .validate = e1000_validate_nvm_checksum_ich8lan,
4539 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540};
4541
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004542const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004543 .mac = e1000_ich8lan,
4544 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004545 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004546 | FLAG_HAS_CTRLEXT_ON_LOAD
4547 | FLAG_HAS_AMT
4548 | FLAG_HAS_FLASH
4549 | FLAG_APME_IN_WUC,
4550 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004551 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004552 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004553 .mac_ops = &ich8_mac_ops,
4554 .phy_ops = &ich8_phy_ops,
4555 .nvm_ops = &ich8_nvm_ops,
4556};
4557
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004558const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004559 .mac = e1000_ich9lan,
4560 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004561 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004562 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004563 | FLAG_HAS_CTRLEXT_ON_LOAD
4564 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004565 | FLAG_HAS_FLASH
4566 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004567 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004568 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004569 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004570 .mac_ops = &ich8_mac_ops,
4571 .phy_ops = &ich8_phy_ops,
4572 .nvm_ops = &ich8_nvm_ops,
4573};
4574
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004575const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004576 .mac = e1000_ich10lan,
4577 .flags = FLAG_HAS_JUMBO_FRAMES
4578 | FLAG_IS_ICH
4579 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004580 | FLAG_HAS_CTRLEXT_ON_LOAD
4581 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004582 | FLAG_HAS_FLASH
4583 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004584 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004585 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004586 .get_variants = e1000_get_variants_ich8lan,
4587 .mac_ops = &ich8_mac_ops,
4588 .phy_ops = &ich8_phy_ops,
4589 .nvm_ops = &ich8_nvm_ops,
4590};
Bruce Allana4f58f52009-06-02 11:29:18 +00004591
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004592const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004593 .mac = e1000_pchlan,
4594 .flags = FLAG_IS_ICH
4595 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004596 | FLAG_HAS_CTRLEXT_ON_LOAD
4597 | FLAG_HAS_AMT
4598 | FLAG_HAS_FLASH
4599 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004600 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004601 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004602 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004603 .pba = 26,
4604 .max_hw_frame_size = 4096,
4605 .get_variants = e1000_get_variants_ich8lan,
4606 .mac_ops = &ich8_mac_ops,
4607 .phy_ops = &ich8_phy_ops,
4608 .nvm_ops = &ich8_nvm_ops,
4609};
Bruce Alland3738bb2010-06-16 13:27:28 +00004610
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004611const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004612 .mac = e1000_pch2lan,
4613 .flags = FLAG_IS_ICH
4614 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004615 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00004616 | FLAG_HAS_CTRLEXT_ON_LOAD
4617 | FLAG_HAS_AMT
4618 | FLAG_HAS_FLASH
4619 | FLAG_HAS_JUMBO_FRAMES
4620 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004621 .flags2 = FLAG2_HAS_PHY_STATS
4622 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004623 .pba = 26,
Bruce Alland3738bb2010-06-16 13:27:28 +00004624 .max_hw_frame_size = DEFAULT_JUMBO,
4625 .get_variants = e1000_get_variants_ich8lan,
4626 .mac_ops = &ich8_mac_ops,
4627 .phy_ops = &ich8_phy_ops,
4628 .nvm_ops = &ich8_nvm_ops,
4629};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004630
4631const struct e1000_info e1000_pch_lpt_info = {
4632 .mac = e1000_pch_lpt,
4633 .flags = FLAG_IS_ICH
4634 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004635 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00004636 | FLAG_HAS_CTRLEXT_ON_LOAD
4637 | FLAG_HAS_AMT
4638 | FLAG_HAS_FLASH
4639 | FLAG_HAS_JUMBO_FRAMES
4640 | FLAG_APME_IN_WUC,
4641 .flags2 = FLAG2_HAS_PHY_STATS
4642 | FLAG2_HAS_EEE,
4643 .pba = 26,
4644 .max_hw_frame_size = DEFAULT_JUMBO,
4645 .get_variants = e1000_get_variants_ich8lan,
4646 .mac_ops = &ich8_mac_ops,
4647 .phy_ops = &ich8_phy_ops,
4648 .nvm_ops = &ich8_nvm_ops,
4649};