blob: e0f41f0b5fe6fa0f82ea3d43795d04005640863c [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allane921eb12012-11-28 09:28:37 +000029/* 82562G 10/100 Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070030 * 82562G-2 10/100 Network Connection
31 * 82562GT 10/100 Network Connection
32 * 82562GT-2 10/100 Network Connection
33 * 82562V 10/100 Network Connection
34 * 82562V-2 10/100 Network Connection
35 * 82566DC-2 Gigabit Network Connection
36 * 82566DC Gigabit Network Connection
37 * 82566DM-2 Gigabit Network Connection
38 * 82566DM Gigabit Network Connection
39 * 82566MC Gigabit Network Connection
40 * 82566MM Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070041 * 82567LM Gigabit Network Connection
42 * 82567LF Gigabit Network Connection
Bruce Allan16059272008-11-21 16:51:06 -080043 * 82567V Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070044 * 82567LM-2 Gigabit Network Connection
45 * 82567LF-2 Gigabit Network Connection
46 * 82567V-2 Gigabit Network Connection
Bruce Allanf4187b52008-08-26 18:36:50 -070047 * 82567LF-3 Gigabit Network Connection
48 * 82567LM-3 Gigabit Network Connection
Bruce Allan2f15f9d2008-08-26 18:36:36 -070049 * 82567LM-4 Gigabit Network Connection
Bruce Allana4f58f52009-06-02 11:29:18 +000050 * 82577LM Gigabit Network Connection
51 * 82577LC Gigabit Network Connection
52 * 82578DM Gigabit Network Connection
53 * 82578DC Gigabit Network Connection
Bruce Alland3738bb2010-06-16 13:27:28 +000054 * 82579LM Gigabit Network Connection
55 * 82579V Gigabit Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070056 */
57
Auke Kokbc7f75f2007-09-17 12:30:59 -070058#include "e1000.h"
59
60#define ICH_FLASH_GFPREG 0x0000
61#define ICH_FLASH_HSFSTS 0x0004
62#define ICH_FLASH_HSFCTL 0x0006
63#define ICH_FLASH_FADDR 0x0008
64#define ICH_FLASH_FDATA0 0x0010
Bruce Allan4a770352008-10-01 17:18:35 -070065#define ICH_FLASH_PR0 0x0074
Auke Kokbc7f75f2007-09-17 12:30:59 -070066
67#define ICH_FLASH_READ_COMMAND_TIMEOUT 500
68#define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
69#define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
70#define ICH_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
71#define ICH_FLASH_CYCLE_REPEAT_COUNT 10
72
73#define ICH_CYCLE_READ 0
74#define ICH_CYCLE_WRITE 2
75#define ICH_CYCLE_ERASE 3
76
77#define FLASH_GFPREG_BASE_MASK 0x1FFF
78#define FLASH_SECTOR_ADDR_SHIFT 12
79
80#define ICH_FLASH_SEG_SIZE_256 256
81#define ICH_FLASH_SEG_SIZE_4K 4096
82#define ICH_FLASH_SEG_SIZE_8K 8192
83#define ICH_FLASH_SEG_SIZE_64K 65536
84
85
86#define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
Bruce Allan6dfaa762010-05-05 22:00:06 +000087/* FW established a valid mode */
88#define E1000_ICH_FWSM_FW_VALID 0x00008000
Auke Kokbc7f75f2007-09-17 12:30:59 -070089
90#define E1000_ICH_MNG_IAMT_MODE 0x2
91
92#define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
93 (ID_LED_DEF1_OFF2 << 8) | \
94 (ID_LED_DEF1_ON2 << 4) | \
95 (ID_LED_DEF1_DEF2))
96
97#define E1000_ICH_NVM_SIG_WORD 0x13
98#define E1000_ICH_NVM_SIG_MASK 0xC000
Bruce Allane2434552008-11-21 17:02:41 -080099#define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
100#define E1000_ICH_NVM_SIG_VALUE 0x80
Auke Kokbc7f75f2007-09-17 12:30:59 -0700101
102#define E1000_ICH8_LAN_INIT_TIMEOUT 1500
103
104#define E1000_FEXTNVM_SW_CONFIG 1
105#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
106
Bruce Allan62bc8132012-03-20 03:47:57 +0000107#define E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK 0x0C000000
108#define E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC 0x08000000
109
Bruce Allan831bd2e2010-09-22 17:16:18 +0000110#define E1000_FEXTNVM4_BEACON_DURATION_MASK 0x7
111#define E1000_FEXTNVM4_BEACON_DURATION_8USEC 0x7
112#define E1000_FEXTNVM4_BEACON_DURATION_16USEC 0x3
113
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
115
116#define E1000_ICH_RAR_ENTRIES 7
Bruce Allan69e1e012012-04-14 03:28:50 +0000117#define E1000_PCH2_RAR_ENTRIES 5 /* RAR[0], SHRA[0-3] */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000118#define E1000_PCH_LPT_RAR_ENTRIES 12 /* RAR[0], SHRA[0-10] */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700119
120#define PHY_PAGE_SHIFT 5
121#define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
122 ((reg) & MAX_PHY_REG_ADDRESS))
123#define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
124#define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
125
126#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
127#define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
128#define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
129
Bruce Allana4f58f52009-06-02 11:29:18 +0000130#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
131
Bruce Allan53ac5a82009-10-26 11:23:06 +0000132#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
133
Bruce Allan2fbe4522012-04-19 03:21:47 +0000134/* SMBus Control Phy Register */
135#define CV_SMB_CTRL PHY_REG(769, 23)
136#define CV_SMB_CTRL_FORCE_SMBUS 0x0001
137
Bruce Allanf523d212009-10-29 13:45:45 +0000138/* SMBus Address Phy Register */
139#define HV_SMB_ADDR PHY_REG(768, 26)
Bruce Allan8395ae82010-09-22 17:15:08 +0000140#define HV_SMB_ADDR_MASK 0x007F
Bruce Allanf523d212009-10-29 13:45:45 +0000141#define HV_SMB_ADDR_PEC_EN 0x0200
142#define HV_SMB_ADDR_VALID 0x0080
Bruce Allan2fbe4522012-04-19 03:21:47 +0000143#define HV_SMB_ADDR_FREQ_MASK 0x1100
144#define HV_SMB_ADDR_FREQ_LOW_SHIFT 8
145#define HV_SMB_ADDR_FREQ_HIGH_SHIFT 12
Bruce Allanf523d212009-10-29 13:45:45 +0000146
Bruce Alland3738bb2010-06-16 13:27:28 +0000147/* PHY Power Management Control */
148#define HV_PM_CTRL PHY_REG(770, 17)
Bruce Allan36ceeb42012-03-20 03:47:47 +0000149#define HV_PM_CTRL_PLL_STOP_IN_K1_GIGA 0x100
Bruce Alland3738bb2010-06-16 13:27:28 +0000150
Bruce Allan2fbe4522012-04-19 03:21:47 +0000151/* Intel Rapid Start Technology Support */
Bruce Allan6d7407b2012-05-10 02:51:17 +0000152#define I217_PROXY_CTRL BM_PHY_REG(BM_WUC_PAGE, 70)
Bruce Allan2fbe4522012-04-19 03:21:47 +0000153#define I217_PROXY_CTRL_AUTO_DISABLE 0x0080
154#define I217_SxCTRL PHY_REG(BM_PORT_CTRL_PAGE, 28)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000155#define I217_SxCTRL_ENABLE_LPI_RESET 0x1000
Bruce Allan2fbe4522012-04-19 03:21:47 +0000156#define I217_CGFREG PHY_REG(772, 29)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000157#define I217_CGFREG_ENABLE_MTA_RESET 0x0002
Bruce Allan2fbe4522012-04-19 03:21:47 +0000158#define I217_MEMPWR PHY_REG(772, 26)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000159#define I217_MEMPWR_DISABLE_SMB_RELEASE 0x0010
Bruce Allan1effb452011-02-25 06:58:03 +0000160
Bruce Allanf523d212009-10-29 13:45:45 +0000161/* Strapping Option Register - RO */
162#define E1000_STRAP 0x0000C
163#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
164#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
Bruce Allan2fbe4522012-04-19 03:21:47 +0000165#define E1000_STRAP_SMT_FREQ_MASK 0x00003000
166#define E1000_STRAP_SMT_FREQ_SHIFT 12
Bruce Allanf523d212009-10-29 13:45:45 +0000167
Bruce Allanfa2ce132009-10-26 11:23:25 +0000168/* OEM Bits Phy Register */
169#define HV_OEM_BITS PHY_REG(768, 25)
170#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
Bruce Allanf523d212009-10-29 13:45:45 +0000171#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
Bruce Allanfa2ce132009-10-26 11:23:25 +0000172#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
173
Bruce Allan1d5846b2009-10-29 13:46:05 +0000174#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
175#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
176
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000177/* KMRN Mode Control */
178#define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
179#define HV_KMRN_MDIO_SLOW 0x0400
180
Bruce Allan1d2101a72011-07-22 06:21:56 +0000181/* KMRN FIFO Control and Status */
182#define HV_KMRN_FIFO_CTRLSTA PHY_REG(770, 16)
183#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK 0x7000
184#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT 12
185
Auke Kokbc7f75f2007-09-17 12:30:59 -0700186/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
187/* Offset 04h HSFSTS */
188union ich8_hws_flash_status {
189 struct ich8_hsfsts {
190 u16 flcdone :1; /* bit 0 Flash Cycle Done */
191 u16 flcerr :1; /* bit 1 Flash Cycle Error */
192 u16 dael :1; /* bit 2 Direct Access error Log */
193 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
194 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
195 u16 reserved1 :2; /* bit 13:6 Reserved */
196 u16 reserved2 :6; /* bit 13:6 Reserved */
197 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
198 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
199 } hsf_status;
200 u16 regval;
201};
202
203/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
204/* Offset 06h FLCTL */
205union ich8_hws_flash_ctrl {
206 struct ich8_hsflctl {
207 u16 flcgo :1; /* 0 Flash Cycle Go */
208 u16 flcycle :2; /* 2:1 Flash Cycle */
209 u16 reserved :5; /* 7:3 Reserved */
210 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
211 u16 flockdn :6; /* 15:10 Reserved */
212 } hsf_ctrl;
213 u16 regval;
214};
215
216/* ICH Flash Region Access Permissions */
217union ich8_hws_flash_regacc {
218 struct ich8_flracc {
219 u32 grra :8; /* 0:7 GbE region Read Access */
220 u32 grwa :8; /* 8:15 GbE region Write Access */
221 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
222 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
223 } hsf_flregacc;
224 u16 regval;
225};
226
Bruce Allan4a770352008-10-01 17:18:35 -0700227/* ICH Flash Protected Region */
228union ich8_flash_protected_range {
229 struct ich8_pr {
230 u32 base:13; /* 0:12 Protected Range Base */
231 u32 reserved1:2; /* 13:14 Reserved */
232 u32 rpe:1; /* 15 Read Protection Enable */
233 u32 limit:13; /* 16:28 Protected Range Limit */
234 u32 reserved2:2; /* 29:30 Reserved */
235 u32 wpe:1; /* 31 Write Protection Enable */
236 } range;
237 u32 regval;
238};
239
Auke Kokbc7f75f2007-09-17 12:30:59 -0700240static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
241static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
242static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700243static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
244static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
245 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700246static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
247 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700248static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
249 u16 *data);
250static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
251 u8 size, u16 *data);
252static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
253static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700254static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000255static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
256static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
257static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
258static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
259static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
260static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
261static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
262static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000263static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000264static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000265static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000266static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000267static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000268static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
269static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan69e1e012012-04-14 03:28:50 +0000270static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000271static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000272static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000273static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700274
275static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
276{
277 return readw(hw->flash_address + reg);
278}
279
280static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
281{
282 return readl(hw->flash_address + reg);
283}
284
285static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
286{
287 writew(val, hw->flash_address + reg);
288}
289
290static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
291{
292 writel(val, hw->flash_address + reg);
293}
294
295#define er16flash(reg) __er16flash(hw, (reg))
296#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000297#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
298#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700299
Bruce Allancb17aab2012-04-13 03:16:22 +0000300/**
301 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
302 * @hw: pointer to the HW structure
303 *
304 * Test access to the PHY registers by reading the PHY ID registers. If
305 * the PHY ID is already known (e.g. resume path) compare it with known ID,
306 * otherwise assume the read PHY ID is correct if it is valid.
307 *
308 * Assumes the sw/fw/hw semaphore is already acquired.
309 **/
310static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000311{
Bruce Allana52359b2012-07-14 04:23:58 +0000312 u16 phy_reg = 0;
313 u32 phy_id = 0;
314 s32 ret_val;
315 u16 retry_count;
Bruce Allan99730e42011-05-13 07:19:48 +0000316
Bruce Allana52359b2012-07-14 04:23:58 +0000317 for (retry_count = 0; retry_count < 2; retry_count++) {
318 ret_val = e1e_rphy_locked(hw, PHY_ID1, &phy_reg);
319 if (ret_val || (phy_reg == 0xFFFF))
320 continue;
321 phy_id = (u32)(phy_reg << 16);
322
323 ret_val = e1e_rphy_locked(hw, PHY_ID2, &phy_reg);
324 if (ret_val || (phy_reg == 0xFFFF)) {
325 phy_id = 0;
326 continue;
327 }
328 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
329 break;
330 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000331
Bruce Allancb17aab2012-04-13 03:16:22 +0000332 if (hw->phy.id) {
333 if (hw->phy.id == phy_id)
334 return true;
Bruce Allana52359b2012-07-14 04:23:58 +0000335 } else if (phy_id) {
336 hw->phy.id = phy_id;
337 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allancb17aab2012-04-13 03:16:22 +0000338 return true;
339 }
340
Bruce Allane921eb12012-11-28 09:28:37 +0000341 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000342 * set slow mode and try to get the PHY id again.
343 */
344 hw->phy.ops.release(hw);
345 ret_val = e1000_set_mdio_slow_mode_hv(hw);
346 if (!ret_val)
347 ret_val = e1000e_get_phy_id(hw);
348 hw->phy.ops.acquire(hw);
349
350 return !ret_val;
Bruce Allancb17aab2012-04-13 03:16:22 +0000351}
352
353/**
354 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
355 * @hw: pointer to the HW structure
356 *
357 * Workarounds/flow necessary for PHY initialization during driver load
358 * and resume paths.
359 **/
360static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
361{
362 u32 mac_reg, fwsm = er32(FWSM);
363 s32 ret_val;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000364 u16 phy_reg;
Bruce Allancb17aab2012-04-13 03:16:22 +0000365
Bruce Allan6e928b72012-12-12 04:45:51 +0000366 /* Gate automatic PHY configuration by hardware on managed and
367 * non-managed 82579 and newer adapters.
368 */
369 e1000_gate_hw_phy_config_ich8lan(hw, true);
370
Bruce Allancb17aab2012-04-13 03:16:22 +0000371 ret_val = hw->phy.ops.acquire(hw);
372 if (ret_val) {
373 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000374 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000375 }
376
Bruce Allane921eb12012-11-28 09:28:37 +0000377 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000378 * inaccessible and resetting the PHY is not blocked, toggle the
379 * LANPHYPC Value bit to force the interconnect to PCIe mode.
380 */
381 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000382 case e1000_pch_lpt:
383 if (e1000_phy_is_accessible_pchlan(hw))
384 break;
385
Bruce Allane921eb12012-11-28 09:28:37 +0000386 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000387 * forcing MAC to SMBus mode first.
388 */
389 mac_reg = er32(CTRL_EXT);
390 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
391 ew32(CTRL_EXT, mac_reg);
392
393 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000394 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000395 if (e1000_phy_is_accessible_pchlan(hw)) {
396 if (hw->mac.type == e1000_pch_lpt) {
397 /* Unforce SMBus mode in PHY */
398 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
399 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
400 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
401
402 /* Unforce SMBus mode in MAC */
403 mac_reg = er32(CTRL_EXT);
404 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
405 ew32(CTRL_EXT, mac_reg);
406 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000407 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000408 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000409
410 /* fall-through */
411 case e1000_pchlan:
412 if ((hw->mac.type == e1000_pchlan) &&
413 (fwsm & E1000_ICH_FWSM_FW_VALID))
414 break;
415
416 if (hw->phy.ops.check_reset_block(hw)) {
417 e_dbg("Required LANPHYPC toggle blocked by ME\n");
418 break;
419 }
420
421 e_dbg("Toggling LANPHYPC\n");
422
423 /* Set Phy Config Counter to 50msec */
424 mac_reg = er32(FEXTNVM3);
425 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
426 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
427 ew32(FEXTNVM3, mac_reg);
428
429 /* Toggle LANPHYPC Value bit */
430 mac_reg = er32(CTRL);
431 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
432 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
433 ew32(CTRL, mac_reg);
434 e1e_flush();
435 udelay(10);
436 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
437 ew32(CTRL, mac_reg);
438 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000439 if (hw->mac.type < e1000_pch_lpt) {
440 msleep(50);
441 } else {
442 u16 count = 20;
443 do {
444 usleep_range(5000, 10000);
445 } while (!(er32(CTRL_EXT) &
446 E1000_CTRL_EXT_LPCD) && count--);
447 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000448 break;
449 default:
450 break;
451 }
452
453 hw->phy.ops.release(hw);
454
Bruce Allane921eb12012-11-28 09:28:37 +0000455 /* Reset the PHY before any access to it. Doing so, ensures
Bruce Allancb17aab2012-04-13 03:16:22 +0000456 * that the PHY is in a known good state before we read/write
457 * PHY registers. The generic reset is sufficient here,
458 * because we haven't determined the PHY type yet.
459 */
460 ret_val = e1000e_phy_hw_reset_generic(hw);
461
Bruce Allan6e928b72012-12-12 04:45:51 +0000462out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000463 /* Ungate automatic PHY configuration on non-managed 82579 */
464 if ((hw->mac.type == e1000_pch2lan) &&
465 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
466 usleep_range(10000, 20000);
467 e1000_gate_hw_phy_config_ich8lan(hw, false);
468 }
469
470 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000471}
472
Auke Kokbc7f75f2007-09-17 12:30:59 -0700473/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000474 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
475 * @hw: pointer to the HW structure
476 *
477 * Initialize family-specific PHY parameters and function pointers.
478 **/
479static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
480{
481 struct e1000_phy_info *phy = &hw->phy;
482 s32 ret_val = 0;
483
484 phy->addr = 1;
485 phy->reset_delay_us = 100;
486
Bruce Allan2b6b1682011-05-13 07:20:09 +0000487 phy->ops.set_page = e1000_set_page_igp;
Bruce Allan94d81862009-11-20 23:25:26 +0000488 phy->ops.read_reg = e1000_read_phy_reg_hv;
489 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000490 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000491 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
492 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000493 phy->ops.write_reg = e1000_write_phy_reg_hv;
494 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000495 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
Bruce Allan17f208d2009-12-01 15:47:22 +0000496 phy->ops.power_up = e1000_power_up_phy_copper;
497 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000498 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
499
500 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000501
502 ret_val = e1000_init_phy_workarounds_pchlan(hw);
503 if (ret_val)
504 return ret_val;
505
506 if (phy->id == e1000_phy_unknown)
507 switch (hw->mac.type) {
508 default:
509 ret_val = e1000e_get_phy_id(hw);
510 if (ret_val)
511 return ret_val;
512 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
513 break;
514 /* fall-through */
515 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000516 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000517 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000518 * set slow mode and try to get the PHY id again.
519 */
520 ret_val = e1000_set_mdio_slow_mode_hv(hw);
521 if (ret_val)
522 return ret_val;
523 ret_val = e1000e_get_phy_id(hw);
524 if (ret_val)
525 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000526 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000527 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000528 phy->type = e1000e_get_phy_type_from_id(phy->id);
529
Bruce Allan0be84012009-12-02 17:03:18 +0000530 switch (phy->type) {
531 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000532 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000533 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000534 phy->ops.check_polarity = e1000_check_polarity_82577;
535 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000536 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000537 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000538 phy->ops.get_info = e1000_get_phy_info_82577;
539 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000540 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000541 case e1000_phy_82578:
542 phy->ops.check_polarity = e1000_check_polarity_m88;
543 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
544 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
545 phy->ops.get_info = e1000e_get_phy_info_m88;
546 break;
547 default:
548 ret_val = -E1000_ERR_PHY;
549 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000550 }
551
552 return ret_val;
553}
554
555/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
557 * @hw: pointer to the HW structure
558 *
559 * Initialize family-specific PHY parameters and function pointers.
560 **/
561static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
562{
563 struct e1000_phy_info *phy = &hw->phy;
564 s32 ret_val;
565 u16 i = 0;
566
567 phy->addr = 1;
568 phy->reset_delay_us = 100;
569
Bruce Allan17f208d2009-12-01 15:47:22 +0000570 phy->ops.power_up = e1000_power_up_phy_copper;
571 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
572
Bruce Allane921eb12012-11-28 09:28:37 +0000573 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700574 * we'll set BM func pointers and try again
575 */
576 ret_val = e1000e_determine_phy_address(hw);
577 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000578 phy->ops.write_reg = e1000e_write_phy_reg_bm;
579 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700580 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000581 if (ret_val) {
582 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700583 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000584 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700585 }
586
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587 phy->id = 0;
588 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
589 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000590 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700591 ret_val = e1000e_get_phy_id(hw);
592 if (ret_val)
593 return ret_val;
594 }
595
596 /* Verify phy id */
597 switch (phy->id) {
598 case IGP03E1000_E_PHY_ID:
599 phy->type = e1000_phy_igp_3;
600 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000601 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
602 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000603 phy->ops.get_info = e1000e_get_phy_info_igp;
604 phy->ops.check_polarity = e1000_check_polarity_igp;
605 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700606 break;
607 case IFE_E_PHY_ID:
608 case IFE_PLUS_E_PHY_ID:
609 case IFE_C_E_PHY_ID:
610 phy->type = e1000_phy_ife;
611 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000612 phy->ops.get_info = e1000_get_phy_info_ife;
613 phy->ops.check_polarity = e1000_check_polarity_ife;
614 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700615 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700616 case BME1000_E_PHY_ID:
617 phy->type = e1000_phy_bm;
618 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000619 phy->ops.read_reg = e1000e_read_phy_reg_bm;
620 phy->ops.write_reg = e1000e_write_phy_reg_bm;
621 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000622 phy->ops.get_info = e1000e_get_phy_info_m88;
623 phy->ops.check_polarity = e1000_check_polarity_m88;
624 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700625 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700626 default:
627 return -E1000_ERR_PHY;
628 break;
629 }
630
631 return 0;
632}
633
634/**
635 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
636 * @hw: pointer to the HW structure
637 *
638 * Initialize family-specific NVM parameters and function
639 * pointers.
640 **/
641static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
642{
643 struct e1000_nvm_info *nvm = &hw->nvm;
644 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000645 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700646 u16 i;
647
Bruce Allanad680762008-03-28 09:15:03 -0700648 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700649 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000650 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651 return -E1000_ERR_CONFIG;
652 }
653
654 nvm->type = e1000_nvm_flash_sw;
655
656 gfpreg = er32flash(ICH_FLASH_GFPREG);
657
Bruce Allane921eb12012-11-28 09:28:37 +0000658 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700659 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700660 * the overall size.
661 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700662 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
663 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
664
665 /* flash_base_addr is byte-aligned */
666 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
667
Bruce Allane921eb12012-11-28 09:28:37 +0000668 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700669 * size represents two separate NVM banks.
670 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700671 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
672 << FLASH_SECTOR_ADDR_SHIFT;
673 nvm->flash_bank_size /= 2;
674 /* Adjust to word count */
675 nvm->flash_bank_size /= sizeof(u16);
676
677 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
678
679 /* Clear shadow ram */
680 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000681 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682 dev_spec->shadow_ram[i].value = 0xFFFF;
683 }
684
685 return 0;
686}
687
688/**
689 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
690 * @hw: pointer to the HW structure
691 *
692 * Initialize family-specific MAC parameters and function
693 * pointers.
694 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000695static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700696{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700697 struct e1000_mac_info *mac = &hw->mac;
698
699 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700700 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700701
702 /* Set mta register count */
703 mac->mta_reg_count = 32;
704 /* Set rar entry count */
705 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
706 if (mac->type == e1000_ich8lan)
707 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000708 /* FWSM register */
709 mac->has_fwsm = true;
710 /* ARC subsystem not supported */
711 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000712 /* Adaptive IFS supported */
713 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700714
Bruce Allan2fbe4522012-04-19 03:21:47 +0000715 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000716 switch (mac->type) {
717 case e1000_ich8lan:
718 case e1000_ich9lan:
719 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000720 /* check management mode */
721 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000722 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000723 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000724 /* blink LED */
725 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000726 /* setup LED */
727 mac->ops.setup_led = e1000e_setup_led_generic;
728 /* cleanup LED */
729 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
730 /* turn on/off LED */
731 mac->ops.led_on = e1000_led_on_ich8lan;
732 mac->ops.led_off = e1000_led_off_ich8lan;
733 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000734 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000735 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
736 mac->ops.rar_set = e1000_rar_set_pch2lan;
737 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000738 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000739 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000740 /* check management mode */
741 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000742 /* ID LED init */
743 mac->ops.id_led_init = e1000_id_led_init_pchlan;
744 /* setup LED */
745 mac->ops.setup_led = e1000_setup_led_pchlan;
746 /* cleanup LED */
747 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
748 /* turn on/off LED */
749 mac->ops.led_on = e1000_led_on_pchlan;
750 mac->ops.led_off = e1000_led_off_pchlan;
751 break;
752 default:
753 break;
754 }
755
Bruce Allan2fbe4522012-04-19 03:21:47 +0000756 if (mac->type == e1000_pch_lpt) {
757 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
758 mac->ops.rar_set = e1000_rar_set_pch_lpt;
759 }
760
Auke Kokbc7f75f2007-09-17 12:30:59 -0700761 /* Enable PCS Lock-loss workaround for ICH8 */
762 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000763 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700764
765 return 0;
766}
767
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000768/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000769 * __e1000_access_emi_reg_locked - Read/write EMI register
770 * @hw: pointer to the HW structure
771 * @addr: EMI address to program
772 * @data: pointer to value to read/write from/to the EMI address
773 * @read: boolean flag to indicate read or write
774 *
775 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
776 **/
777static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
778 u16 *data, bool read)
779{
780 s32 ret_val = 0;
781
782 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
783 if (ret_val)
784 return ret_val;
785
786 if (read)
787 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
788 else
789 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
790
791 return ret_val;
792}
793
794/**
795 * e1000_read_emi_reg_locked - Read Extended Management Interface register
796 * @hw: pointer to the HW structure
797 * @addr: EMI address to program
798 * @data: value to be read from the EMI address
799 *
800 * Assumes the SW/FW/HW Semaphore is already acquired.
801 **/
Bruce Allan203e4152012-12-05 08:40:59 +0000802s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000803{
804 return __e1000_access_emi_reg_locked(hw, addr, data, true);
805}
806
807/**
808 * e1000_write_emi_reg_locked - Write Extended Management Interface register
809 * @hw: pointer to the HW structure
810 * @addr: EMI address to program
811 * @data: value to be written to the EMI address
812 *
813 * Assumes the SW/FW/HW Semaphore is already acquired.
814 **/
815static s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
816{
817 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
818}
819
820/**
Bruce Allane52997f2010-06-16 13:27:49 +0000821 * e1000_set_eee_pchlan - Enable/disable EEE support
822 * @hw: pointer to the HW structure
823 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000824 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
825 * the link and the EEE capabilities of the link partner. The LPI Control
826 * register bits will remain set only if/when link is up.
Bruce Allane52997f2010-06-16 13:27:49 +0000827 **/
828static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
829{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000830 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000831 s32 ret_val;
832 u16 lpi_ctrl;
Bruce Allane52997f2010-06-16 13:27:49 +0000833
Bruce Allan2fbe4522012-04-19 03:21:47 +0000834 if ((hw->phy.type != e1000_phy_82579) &&
835 (hw->phy.type != e1000_phy_i217))
Bruce Allan5015e532012-02-08 02:55:56 +0000836 return 0;
Bruce Allane52997f2010-06-16 13:27:49 +0000837
Bruce Allan3d4d5752012-12-05 06:26:08 +0000838 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000839 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000840 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000841
Bruce Allan3d4d5752012-12-05 06:26:08 +0000842 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000843 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000844 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000845
Bruce Allan3d4d5752012-12-05 06:26:08 +0000846 /* Clear bits that enable EEE in various speeds */
847 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
848
849 /* Enable EEE if not disabled by user */
850 if (!dev_spec->eee_disable) {
851 u16 lpa, pcs_status, data;
852
Bruce Allan2fbe4522012-04-19 03:21:47 +0000853 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000854 switch (hw->phy.type) {
855 case e1000_phy_82579:
856 lpa = I82579_EEE_LP_ABILITY;
857 pcs_status = I82579_EEE_PCS_STATUS;
858 break;
859 case e1000_phy_i217:
860 lpa = I217_EEE_LP_ABILITY;
861 pcs_status = I217_EEE_PCS_STATUS;
862 break;
863 default:
864 ret_val = -E1000_ERR_PHY;
865 goto release;
866 }
867 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000868 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000869 if (ret_val)
870 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000871
Bruce Allan3d4d5752012-12-05 06:26:08 +0000872 /* Enable EEE only for speeds in which the link partner is
873 * EEE capable.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000874 */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000875 if (dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
876 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
877
878 if (dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
879 e1e_rphy_locked(hw, PHY_LP_ABILITY, &data);
880 if (data & NWAY_LPAR_100TX_FD_CAPS)
881 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
882 else
883 /* EEE is not supported in 100Half, so ignore
884 * partner's EEE in 100 ability if full-duplex
885 * is not advertised.
886 */
887 dev_spec->eee_lp_ability &=
888 ~I82579_EEE_100_SUPPORTED;
889 }
890
891 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
892 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
893 if (ret_val)
894 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000895 }
896
Bruce Allan3d4d5752012-12-05 06:26:08 +0000897 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
898release:
899 hw->phy.ops.release(hw);
900
901 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000902}
903
904/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000905 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
906 * @hw: pointer to the HW structure
907 *
908 * Checks to see of the link status of the hardware has changed. If a
909 * change in link status has been detected, then we read the PHY registers
910 * to get the current speed/duplex if link exists.
911 **/
912static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
913{
914 struct e1000_mac_info *mac = &hw->mac;
915 s32 ret_val;
916 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000917 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000918
Bruce Allane921eb12012-11-28 09:28:37 +0000919 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000920 * has completed and/or if our link status has changed. The
921 * get_link_status flag is set upon receiving a Link Status
922 * Change or Rx Sequence Error interrupt.
923 */
Bruce Allan5015e532012-02-08 02:55:56 +0000924 if (!mac->get_link_status)
925 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000926
Bruce Allane921eb12012-11-28 09:28:37 +0000927 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000928 * link. If so, then we want to get the current speed/duplex
929 * of the PHY.
930 */
931 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
932 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000933 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000934
Bruce Allan1d5846b2009-10-29 13:46:05 +0000935 if (hw->mac.type == e1000_pchlan) {
936 ret_val = e1000_k1_gig_workaround_hv(hw, link);
937 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000938 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +0000939 }
940
Bruce Allan2fbe4522012-04-19 03:21:47 +0000941 /* Clear link partner's EEE ability */
942 hw->dev_spec.ich8lan.eee_lp_ability = 0;
943
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000944 if (!link)
Bruce Allan5015e532012-02-08 02:55:56 +0000945 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000946
947 mac->get_link_status = false;
948
Bruce Allan1d2101a72011-07-22 06:21:56 +0000949 switch (hw->mac.type) {
950 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +0000951 ret_val = e1000_k1_workaround_lv(hw);
952 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000953 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000954 /* fall-thru */
955 case e1000_pchlan:
956 if (hw->phy.type == e1000_phy_82578) {
957 ret_val = e1000_link_stall_workaround_hv(hw);
958 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000959 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000960 }
961
Bruce Allane921eb12012-11-28 09:28:37 +0000962 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +0000963 * Set the number of preambles removed from the packet
964 * when it is passed from the PHY to the MAC to prevent
965 * the MAC from misinterpreting the packet type.
966 */
967 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
968 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
969
970 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
971 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
972
973 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
974 break;
975 default:
976 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +0000977 }
978
Bruce Allane921eb12012-11-28 09:28:37 +0000979 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000980 * immediately after link-up
981 */
982 e1000e_check_downshift(hw);
983
Bruce Allane52997f2010-06-16 13:27:49 +0000984 /* Enable/Disable EEE after link up */
985 ret_val = e1000_set_eee_pchlan(hw);
986 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000987 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000988
Bruce Allane921eb12012-11-28 09:28:37 +0000989 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000990 * we have already determined whether we have link or not.
991 */
Bruce Allan5015e532012-02-08 02:55:56 +0000992 if (!mac->autoneg)
993 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000994
Bruce Allane921eb12012-11-28 09:28:37 +0000995 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000996 * of MAC speed/duplex configuration. So we only need to
997 * configure Collision Distance in the MAC.
998 */
Bruce Allan57cde762012-02-22 09:02:58 +0000999 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001000
Bruce Allane921eb12012-11-28 09:28:37 +00001001 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001002 * First, we need to restore the desired flow control
1003 * settings because we may have had to re-autoneg with a
1004 * different link partner.
1005 */
1006 ret_val = e1000e_config_fc_after_link_up(hw);
1007 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001008 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001009
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001010 return ret_val;
1011}
1012
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001013static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001014{
1015 struct e1000_hw *hw = &adapter->hw;
1016 s32 rc;
1017
Bruce Allanec34c172012-02-01 10:53:05 +00001018 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001019 if (rc)
1020 return rc;
1021
1022 rc = e1000_init_nvm_params_ich8lan(hw);
1023 if (rc)
1024 return rc;
1025
Bruce Alland3738bb2010-06-16 13:27:28 +00001026 switch (hw->mac.type) {
1027 case e1000_ich8lan:
1028 case e1000_ich9lan:
1029 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001030 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001031 break;
1032 case e1000_pchlan:
1033 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001034 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001035 rc = e1000_init_phy_params_pchlan(hw);
1036 break;
1037 default:
1038 break;
1039 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 if (rc)
1041 return rc;
1042
Bruce Allane921eb12012-11-28 09:28:37 +00001043 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001044 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1045 */
1046 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1047 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1048 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001049 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1050 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001051
1052 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001053 }
1054
Auke Kokbc7f75f2007-09-17 12:30:59 -07001055 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001056 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001057 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1058
Bruce Allanc6e7f512011-07-29 05:53:02 +00001059 /* Enable workaround for 82579 w/ ME enabled */
1060 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1061 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1062 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1063
Bruce Allan5a86f282010-06-29 18:13:13 +00001064 /* Disable EEE by default until IEEE802.3az spec is finalized */
1065 if (adapter->flags2 & FLAG2_HAS_EEE)
1066 adapter->hw.dev_spec.ich8lan.eee_disable = true;
1067
Auke Kokbc7f75f2007-09-17 12:30:59 -07001068 return 0;
1069}
1070
Thomas Gleixner717d4382008-10-02 16:33:40 -07001071static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001072
Auke Kokbc7f75f2007-09-17 12:30:59 -07001073/**
Bruce Allanca15df52009-10-26 11:23:43 +00001074 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1075 * @hw: pointer to the HW structure
1076 *
1077 * Acquires the mutex for performing NVM operations.
1078 **/
1079static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
1080{
1081 mutex_lock(&nvm_mutex);
1082
1083 return 0;
1084}
1085
1086/**
1087 * e1000_release_nvm_ich8lan - Release NVM mutex
1088 * @hw: pointer to the HW structure
1089 *
1090 * Releases the mutex used while performing NVM operations.
1091 **/
1092static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
1093{
1094 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001095}
1096
Bruce Allanca15df52009-10-26 11:23:43 +00001097/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001098 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1099 * @hw: pointer to the HW structure
1100 *
Bruce Allanca15df52009-10-26 11:23:43 +00001101 * Acquires the software control flag for performing PHY and select
1102 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001103 **/
1104static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1105{
Bruce Allan373a88d2009-08-07 07:41:37 +00001106 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1107 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108
Bruce Allana90b4122011-10-07 03:50:38 +00001109 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1110 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001111 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001112 return -E1000_ERR_PHY;
1113 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001114
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 while (timeout) {
1116 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001117 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1118 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119
Auke Kokbc7f75f2007-09-17 12:30:59 -07001120 mdelay(1);
1121 timeout--;
1122 }
1123
1124 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001125 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001126 ret_val = -E1000_ERR_CONFIG;
1127 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 }
1129
Bruce Allan53ac5a82009-10-26 11:23:06 +00001130 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001131
1132 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1133 ew32(EXTCNF_CTRL, extcnf_ctrl);
1134
1135 while (timeout) {
1136 extcnf_ctrl = er32(EXTCNF_CTRL);
1137 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1138 break;
1139
1140 mdelay(1);
1141 timeout--;
1142 }
1143
1144 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001145 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 +00001146 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001147 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1148 ew32(EXTCNF_CTRL, extcnf_ctrl);
1149 ret_val = -E1000_ERR_CONFIG;
1150 goto out;
1151 }
1152
1153out:
1154 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001155 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001156
1157 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158}
1159
1160/**
1161 * e1000_release_swflag_ich8lan - Release software control flag
1162 * @hw: pointer to the HW structure
1163 *
Bruce Allanca15df52009-10-26 11:23:43 +00001164 * Releases the software control flag for performing PHY and select
1165 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166 **/
1167static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1168{
1169 u32 extcnf_ctrl;
1170
1171 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001172
1173 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1174 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1175 ew32(EXTCNF_CTRL, extcnf_ctrl);
1176 } else {
1177 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1178 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001179
Bruce Allana90b4122011-10-07 03:50:38 +00001180 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001181}
1182
1183/**
Bruce Allan4662e822008-08-26 18:37:06 -07001184 * e1000_check_mng_mode_ich8lan - Checks management mode
1185 * @hw: pointer to the HW structure
1186 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001187 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001188 * This is a function pointer entry point only called by read/write
1189 * routines for the PHY and NVM parts.
1190 **/
1191static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1192{
Bruce Allana708dd82009-11-20 23:28:37 +00001193 u32 fwsm;
1194
1195 fwsm = er32(FWSM);
Bruce Allaneb7700d2010-06-16 13:27:05 +00001196 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1197 ((fwsm & E1000_FWSM_MODE_MASK) ==
1198 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1199}
Bruce Allan4662e822008-08-26 18:37:06 -07001200
Bruce Allaneb7700d2010-06-16 13:27:05 +00001201/**
1202 * e1000_check_mng_mode_pchlan - Checks management mode
1203 * @hw: pointer to the HW structure
1204 *
1205 * This checks if the adapter has iAMT enabled.
1206 * This is a function pointer entry point only called by read/write
1207 * routines for the PHY and NVM parts.
1208 **/
1209static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1210{
1211 u32 fwsm;
1212
1213 fwsm = er32(FWSM);
1214 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1215 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001216}
1217
1218/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001219 * e1000_rar_set_pch2lan - Set receive address register
1220 * @hw: pointer to the HW structure
1221 * @addr: pointer to the receive address
1222 * @index: receive address array register
1223 *
1224 * Sets the receive address array register at index to the address passed
1225 * in by addr. For 82579, RAR[0] is the base address register that is to
1226 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1227 * Use SHRA[0-3] in place of those reserved for ME.
1228 **/
1229static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1230{
1231 u32 rar_low, rar_high;
1232
Bruce Allane921eb12012-11-28 09:28:37 +00001233 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001234 * from network order (big endian) to little endian
1235 */
1236 rar_low = ((u32)addr[0] |
1237 ((u32)addr[1] << 8) |
1238 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1239
1240 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1241
1242 /* If MAC address zero, no need to set the AV bit */
1243 if (rar_low || rar_high)
1244 rar_high |= E1000_RAH_AV;
1245
1246 if (index == 0) {
1247 ew32(RAL(index), rar_low);
1248 e1e_flush();
1249 ew32(RAH(index), rar_high);
1250 e1e_flush();
1251 return;
1252 }
1253
1254 if (index < hw->mac.rar_entry_count) {
1255 s32 ret_val;
1256
1257 ret_val = e1000_acquire_swflag_ich8lan(hw);
1258 if (ret_val)
1259 goto out;
1260
1261 ew32(SHRAL(index - 1), rar_low);
1262 e1e_flush();
1263 ew32(SHRAH(index - 1), rar_high);
1264 e1e_flush();
1265
1266 e1000_release_swflag_ich8lan(hw);
1267
1268 /* verify the register updates */
1269 if ((er32(SHRAL(index - 1)) == rar_low) &&
1270 (er32(SHRAH(index - 1)) == rar_high))
1271 return;
1272
1273 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1274 (index - 1), er32(FWSM));
1275 }
1276
1277out:
1278 e_dbg("Failed to write receive address at index %d\n", index);
1279}
1280
1281/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001282 * e1000_rar_set_pch_lpt - Set receive address registers
1283 * @hw: pointer to the HW structure
1284 * @addr: pointer to the receive address
1285 * @index: receive address array register
1286 *
1287 * Sets the receive address register array at index to the address passed
1288 * in by addr. For LPT, RAR[0] is the base address register that is to
1289 * contain the MAC address. SHRA[0-10] are the shared receive address
1290 * registers that are shared between the Host and manageability engine (ME).
1291 **/
1292static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1293{
1294 u32 rar_low, rar_high;
1295 u32 wlock_mac;
1296
Bruce Allane921eb12012-11-28 09:28:37 +00001297 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001298 * from network order (big endian) to little endian
1299 */
1300 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1301 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1302
1303 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1304
1305 /* If MAC address zero, no need to set the AV bit */
1306 if (rar_low || rar_high)
1307 rar_high |= E1000_RAH_AV;
1308
1309 if (index == 0) {
1310 ew32(RAL(index), rar_low);
1311 e1e_flush();
1312 ew32(RAH(index), rar_high);
1313 e1e_flush();
1314 return;
1315 }
1316
Bruce Allane921eb12012-11-28 09:28:37 +00001317 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001318 * it is using - those registers are unavailable for use.
1319 */
1320 if (index < hw->mac.rar_entry_count) {
1321 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1322 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1323
1324 /* Check if all SHRAR registers are locked */
1325 if (wlock_mac == 1)
1326 goto out;
1327
1328 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1329 s32 ret_val;
1330
1331 ret_val = e1000_acquire_swflag_ich8lan(hw);
1332
1333 if (ret_val)
1334 goto out;
1335
1336 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1337 e1e_flush();
1338 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1339 e1e_flush();
1340
1341 e1000_release_swflag_ich8lan(hw);
1342
1343 /* verify the register updates */
1344 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1345 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1346 return;
1347 }
1348 }
1349
1350out:
1351 e_dbg("Failed to write receive address at index %d\n", index);
1352}
1353
1354/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001355 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1356 * @hw: pointer to the HW structure
1357 *
1358 * Checks if firmware is blocking the reset of the PHY.
1359 * This is a function pointer entry point only called by
1360 * reset routines.
1361 **/
1362static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1363{
1364 u32 fwsm;
1365
1366 fwsm = er32(FWSM);
1367
1368 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
1369}
1370
1371/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001372 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1373 * @hw: pointer to the HW structure
1374 *
1375 * Assumes semaphore already acquired.
1376 *
1377 **/
1378static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1379{
1380 u16 phy_data;
1381 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001382 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1383 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan8395ae82010-09-22 17:15:08 +00001384 s32 ret_val = 0;
1385
1386 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1387
1388 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1389 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001390 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001391
1392 phy_data &= ~HV_SMB_ADDR_MASK;
1393 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1394 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001395
Bruce Allan2fbe4522012-04-19 03:21:47 +00001396 if (hw->phy.type == e1000_phy_i217) {
1397 /* Restore SMBus frequency */
1398 if (freq--) {
1399 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1400 phy_data |= (freq & (1 << 0)) <<
1401 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1402 phy_data |= (freq & (1 << 1)) <<
1403 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1404 } else {
1405 e_dbg("Unsupported SMB frequency in PHY\n");
1406 }
1407 }
1408
Bruce Allan5015e532012-02-08 02:55:56 +00001409 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001410}
1411
1412/**
Bruce Allanf523d212009-10-29 13:45:45 +00001413 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1414 * @hw: pointer to the HW structure
1415 *
1416 * SW should configure the LCD from the NVM extended configuration region
1417 * as a workaround for certain parts.
1418 **/
1419static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1420{
1421 struct e1000_phy_info *phy = &hw->phy;
1422 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001423 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001424 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1425
Bruce Allane921eb12012-11-28 09:28:37 +00001426 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001427 * is needed due to an issue where the NVM configuration is
1428 * not properly autoloaded after power transitions.
1429 * Therefore, after each PHY reset, we will load the
1430 * configuration data out of the NVM manually.
1431 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001432 switch (hw->mac.type) {
1433 case e1000_ich8lan:
1434 if (phy->type != e1000_phy_igp_3)
1435 return ret_val;
1436
Bruce Allan5f3eed62010-09-22 17:15:54 +00001437 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1438 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001439 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1440 break;
1441 }
1442 /* Fall-thru */
1443 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001444 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001445 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001446 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001447 break;
1448 default:
1449 return ret_val;
1450 }
1451
1452 ret_val = hw->phy.ops.acquire(hw);
1453 if (ret_val)
1454 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001455
Bruce Allan8b802a72010-05-10 15:01:10 +00001456 data = er32(FEXTNVM);
1457 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001458 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001459
Bruce Allane921eb12012-11-28 09:28:37 +00001460 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001461 * extended configuration before SW configuration
1462 */
1463 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001464 if ((hw->mac.type < e1000_pch2lan) &&
1465 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1466 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001467
Bruce Allan8b802a72010-05-10 15:01:10 +00001468 cnf_size = er32(EXTCNF_SIZE);
1469 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1470 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1471 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001472 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001473
1474 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1475 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1476
Bruce Allan2fbe4522012-04-19 03:21:47 +00001477 if (((hw->mac.type == e1000_pchlan) &&
1478 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1479 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001480 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001481 * OEM and LCD Write Enable bits are set in the NVM.
1482 * When both NVM bits are cleared, SW will configure
1483 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001484 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001485 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001486 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001487 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001488
Bruce Allan8b802a72010-05-10 15:01:10 +00001489 data = er32(LEDCTL);
1490 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1491 (u16)data);
1492 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001493 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001494 }
1495
1496 /* Configure LCD from extended configuration region. */
1497
1498 /* cnf_base_addr is in DWORD */
1499 word_addr = (u16)(cnf_base_addr << 1);
1500
1501 for (i = 0; i < cnf_size; i++) {
1502 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
1503 &reg_data);
1504 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001505 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001506
Bruce Allan8b802a72010-05-10 15:01:10 +00001507 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1508 1, &reg_addr);
1509 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001510 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001511
Bruce Allan8b802a72010-05-10 15:01:10 +00001512 /* Save off the PHY page for future writes. */
1513 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1514 phy_page = reg_data;
1515 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001516 }
Bruce Allanf523d212009-10-29 13:45:45 +00001517
Bruce Allan8b802a72010-05-10 15:01:10 +00001518 reg_addr &= PHY_REG_MASK;
1519 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001520
Bruce Allanf1430d62012-04-14 04:21:52 +00001521 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001522 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001523 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001524 }
1525
Bruce Allan75ce1532012-02-08 02:54:48 +00001526release:
Bruce Allan94d81862009-11-20 23:25:26 +00001527 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001528 return ret_val;
1529}
1530
1531/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001532 * e1000_k1_gig_workaround_hv - K1 Si workaround
1533 * @hw: pointer to the HW structure
1534 * @link: link up bool flag
1535 *
1536 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1537 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1538 * If link is down, the function will restore the default K1 setting located
1539 * in the NVM.
1540 **/
1541static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1542{
1543 s32 ret_val = 0;
1544 u16 status_reg = 0;
1545 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1546
1547 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001548 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001549
1550 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001551 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001552 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001553 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001554
1555 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1556 if (link) {
1557 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001558 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1559 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001560 if (ret_val)
1561 goto release;
1562
1563 status_reg &= BM_CS_STATUS_LINK_UP |
1564 BM_CS_STATUS_RESOLVED |
1565 BM_CS_STATUS_SPEED_MASK;
1566
1567 if (status_reg == (BM_CS_STATUS_LINK_UP |
1568 BM_CS_STATUS_RESOLVED |
1569 BM_CS_STATUS_SPEED_1000))
1570 k1_enable = false;
1571 }
1572
1573 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001574 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001575 if (ret_val)
1576 goto release;
1577
1578 status_reg &= HV_M_STATUS_LINK_UP |
1579 HV_M_STATUS_AUTONEG_COMPLETE |
1580 HV_M_STATUS_SPEED_MASK;
1581
1582 if (status_reg == (HV_M_STATUS_LINK_UP |
1583 HV_M_STATUS_AUTONEG_COMPLETE |
1584 HV_M_STATUS_SPEED_1000))
1585 k1_enable = false;
1586 }
1587
1588 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001589 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001590 if (ret_val)
1591 goto release;
1592
1593 } else {
1594 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001595 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001596 if (ret_val)
1597 goto release;
1598 }
1599
1600 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1601
1602release:
Bruce Allan94d81862009-11-20 23:25:26 +00001603 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001604
Bruce Allan1d5846b2009-10-29 13:46:05 +00001605 return ret_val;
1606}
1607
1608/**
1609 * e1000_configure_k1_ich8lan - Configure K1 power state
1610 * @hw: pointer to the HW structure
1611 * @enable: K1 state to configure
1612 *
1613 * Configure the K1 power state based on the provided parameter.
1614 * Assumes semaphore already acquired.
1615 *
1616 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1617 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001618s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001619{
1620 s32 ret_val = 0;
1621 u32 ctrl_reg = 0;
1622 u32 ctrl_ext = 0;
1623 u32 reg = 0;
1624 u16 kmrn_reg = 0;
1625
Bruce Allan3d3a1672012-02-23 03:13:18 +00001626 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1627 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001628 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001629 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001630
1631 if (k1_enable)
1632 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1633 else
1634 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1635
Bruce Allan3d3a1672012-02-23 03:13:18 +00001636 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1637 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001638 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001639 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001640
1641 udelay(20);
1642 ctrl_ext = er32(CTRL_EXT);
1643 ctrl_reg = er32(CTRL);
1644
1645 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1646 reg |= E1000_CTRL_FRCSPD;
1647 ew32(CTRL, reg);
1648
1649 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001650 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001651 udelay(20);
1652 ew32(CTRL, ctrl_reg);
1653 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001654 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001655 udelay(20);
1656
Bruce Allan5015e532012-02-08 02:55:56 +00001657 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001658}
1659
1660/**
Bruce Allanf523d212009-10-29 13:45:45 +00001661 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1662 * @hw: pointer to the HW structure
1663 * @d0_state: boolean if entering d0 or d3 device state
1664 *
1665 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1666 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1667 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1668 **/
1669static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1670{
1671 s32 ret_val = 0;
1672 u32 mac_reg;
1673 u16 oem_reg;
1674
Bruce Allan2fbe4522012-04-19 03:21:47 +00001675 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001676 return ret_val;
1677
Bruce Allan94d81862009-11-20 23:25:26 +00001678 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001679 if (ret_val)
1680 return ret_val;
1681
Bruce Allan2fbe4522012-04-19 03:21:47 +00001682 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001683 mac_reg = er32(EXTCNF_CTRL);
1684 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001685 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001686 }
Bruce Allanf523d212009-10-29 13:45:45 +00001687
1688 mac_reg = er32(FEXTNVM);
1689 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001690 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001691
1692 mac_reg = er32(PHY_CTRL);
1693
Bruce Allanf1430d62012-04-14 04:21:52 +00001694 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001695 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001696 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001697
1698 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1699
1700 if (d0_state) {
1701 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1702 oem_reg |= HV_OEM_BITS_GBE_DIS;
1703
1704 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1705 oem_reg |= HV_OEM_BITS_LPLU;
1706 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001707 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1708 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001709 oem_reg |= HV_OEM_BITS_GBE_DIS;
1710
Bruce Allan03299e42011-09-30 08:07:05 +00001711 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1712 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001713 oem_reg |= HV_OEM_BITS_LPLU;
1714 }
Bruce Allan03299e42011-09-30 08:07:05 +00001715
Bruce Allan92fe1732012-04-12 06:27:03 +00001716 /* Set Restart auto-neg to activate the bits */
1717 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1718 !hw->phy.ops.check_reset_block(hw))
1719 oem_reg |= HV_OEM_BITS_RESTART_AN;
1720
Bruce Allanf1430d62012-04-14 04:21:52 +00001721 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001722
Bruce Allan75ce1532012-02-08 02:54:48 +00001723release:
Bruce Allan94d81862009-11-20 23:25:26 +00001724 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001725
1726 return ret_val;
1727}
1728
1729
1730/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001731 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1732 * @hw: pointer to the HW structure
1733 **/
1734static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1735{
1736 s32 ret_val;
1737 u16 data;
1738
1739 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1740 if (ret_val)
1741 return ret_val;
1742
1743 data |= HV_KMRN_MDIO_SLOW;
1744
1745 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1746
1747 return ret_val;
1748}
1749
1750/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001751 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1752 * done after every PHY reset.
1753 **/
1754static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1755{
1756 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001757 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001758
1759 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001760 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001761
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001762 /* Set MDIO slow mode before any other MDIO access */
1763 if (hw->phy.type == e1000_phy_82577) {
1764 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1765 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001766 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001767 }
1768
Bruce Allana4f58f52009-06-02 11:29:18 +00001769 if (((hw->phy.type == e1000_phy_82577) &&
1770 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1771 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1772 /* Disable generation of early preamble */
1773 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1774 if (ret_val)
1775 return ret_val;
1776
1777 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001778 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001779 if (ret_val)
1780 return ret_val;
1781 }
1782
1783 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001784 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001785 * writing 0x3140 to the control register.
1786 */
1787 if (hw->phy.revision < 2) {
1788 e1000e_phy_sw_reset(hw);
1789 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1790 }
1791 }
1792
1793 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001794 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001795 if (ret_val)
1796 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001797
Bruce Allana4f58f52009-06-02 11:29:18 +00001798 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001799 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001800 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001801 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001802 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001803
Bruce Allane921eb12012-11-28 09:28:37 +00001804 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001805 * link so that it disables K1 if link is in 1Gbps.
1806 */
1807 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001808 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001809 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001810
Bruce Allanbaf86c92010-01-13 01:53:08 +00001811 /* Workaround for link disconnects on a busy hub in half duplex */
1812 ret_val = hw->phy.ops.acquire(hw);
1813 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001814 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001815 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001816 if (ret_val)
1817 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001818 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001819 if (ret_val)
1820 goto release;
1821
1822 /* set MSE higher to enable link to stay up when noise is high */
1823 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001824release:
1825 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001826
Bruce Allana4f58f52009-06-02 11:29:18 +00001827 return ret_val;
1828}
1829
1830/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001831 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1832 * @hw: pointer to the HW structure
1833 **/
1834void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1835{
1836 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001837 u16 i, phy_reg = 0;
1838 s32 ret_val;
1839
1840 ret_val = hw->phy.ops.acquire(hw);
1841 if (ret_val)
1842 return;
1843 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1844 if (ret_val)
1845 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001846
1847 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1848 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1849 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001850 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1851 (u16)(mac_reg & 0xFFFF));
1852 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1853 (u16)((mac_reg >> 16) & 0xFFFF));
1854
Bruce Alland3738bb2010-06-16 13:27:28 +00001855 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001856 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1857 (u16)(mac_reg & 0xFFFF));
1858 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1859 (u16)((mac_reg & E1000_RAH_AV)
1860 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00001861 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00001862
1863 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1864
1865release:
1866 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001867}
1868
Bruce Alland3738bb2010-06-16 13:27:28 +00001869/**
1870 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1871 * with 82579 PHY
1872 * @hw: pointer to the HW structure
1873 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1874 **/
1875s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1876{
1877 s32 ret_val = 0;
1878 u16 phy_reg, data;
1879 u32 mac_reg;
1880 u16 i;
1881
Bruce Allan2fbe4522012-04-19 03:21:47 +00001882 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001883 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001884
1885 /* disable Rx path while enabling/disabling workaround */
1886 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1887 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1888 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001889 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001890
1891 if (enable) {
Bruce Allane921eb12012-11-28 09:28:37 +00001892 /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
Bruce Alland3738bb2010-06-16 13:27:28 +00001893 * SHRAL/H) and initial CRC values to the MAC
1894 */
1895 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1896 u8 mac_addr[ETH_ALEN] = {0};
1897 u32 addr_high, addr_low;
1898
1899 addr_high = er32(RAH(i));
1900 if (!(addr_high & E1000_RAH_AV))
1901 continue;
1902 addr_low = er32(RAL(i));
1903 mac_addr[0] = (addr_low & 0xFF);
1904 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1905 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1906 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1907 mac_addr[4] = (addr_high & 0xFF);
1908 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1909
Bruce Allanfe46f582011-01-06 14:29:51 +00001910 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00001911 }
1912
1913 /* Write Rx addresses to the PHY */
1914 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1915
1916 /* Enable jumbo frame workaround in the MAC */
1917 mac_reg = er32(FFLT_DBG);
1918 mac_reg &= ~(1 << 14);
1919 mac_reg |= (7 << 15);
1920 ew32(FFLT_DBG, mac_reg);
1921
1922 mac_reg = er32(RCTL);
1923 mac_reg |= E1000_RCTL_SECRC;
1924 ew32(RCTL, mac_reg);
1925
1926 ret_val = e1000e_read_kmrn_reg(hw,
1927 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1928 &data);
1929 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001930 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001931 ret_val = e1000e_write_kmrn_reg(hw,
1932 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1933 data | (1 << 0));
1934 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001935 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001936 ret_val = e1000e_read_kmrn_reg(hw,
1937 E1000_KMRNCTRLSTA_HD_CTRL,
1938 &data);
1939 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001940 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001941 data &= ~(0xF << 8);
1942 data |= (0xB << 8);
1943 ret_val = e1000e_write_kmrn_reg(hw,
1944 E1000_KMRNCTRLSTA_HD_CTRL,
1945 data);
1946 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001947 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001948
1949 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001950 e1e_rphy(hw, PHY_REG(769, 23), &data);
1951 data &= ~(0x7F << 5);
1952 data |= (0x37 << 5);
1953 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1954 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001955 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001956 e1e_rphy(hw, PHY_REG(769, 16), &data);
1957 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00001958 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1959 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001960 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001961 e1e_rphy(hw, PHY_REG(776, 20), &data);
1962 data &= ~(0x3FF << 2);
1963 data |= (0x1A << 2);
1964 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1965 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001966 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00001967 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00001968 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001969 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001970 e1e_rphy(hw, HV_PM_CTRL, &data);
1971 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1972 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001973 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001974 } else {
1975 /* Write MAC register values back to h/w defaults */
1976 mac_reg = er32(FFLT_DBG);
1977 mac_reg &= ~(0xF << 14);
1978 ew32(FFLT_DBG, mac_reg);
1979
1980 mac_reg = er32(RCTL);
1981 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00001982 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00001983
1984 ret_val = e1000e_read_kmrn_reg(hw,
1985 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1986 &data);
1987 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001988 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001989 ret_val = e1000e_write_kmrn_reg(hw,
1990 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1991 data & ~(1 << 0));
1992 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001993 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001994 ret_val = e1000e_read_kmrn_reg(hw,
1995 E1000_KMRNCTRLSTA_HD_CTRL,
1996 &data);
1997 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001998 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001999 data &= ~(0xF << 8);
2000 data |= (0xB << 8);
2001 ret_val = e1000e_write_kmrn_reg(hw,
2002 E1000_KMRNCTRLSTA_HD_CTRL,
2003 data);
2004 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002005 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002006
2007 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002008 e1e_rphy(hw, PHY_REG(769, 23), &data);
2009 data &= ~(0x7F << 5);
2010 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2011 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002012 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002013 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002014 data |= (1 << 13);
2015 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2016 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002017 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002018 e1e_rphy(hw, PHY_REG(776, 20), &data);
2019 data &= ~(0x3FF << 2);
2020 data |= (0x8 << 2);
2021 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2022 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002023 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002024 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2025 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002026 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002027 e1e_rphy(hw, HV_PM_CTRL, &data);
2028 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2029 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002030 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002031 }
2032
2033 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002034 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002035}
2036
2037/**
2038 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2039 * done after every PHY reset.
2040 **/
2041static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2042{
2043 s32 ret_val = 0;
2044
2045 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002046 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002047
2048 /* Set MDIO slow mode before any other MDIO access */
2049 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002050 if (ret_val)
2051 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002052
Bruce Allan4d241362011-12-16 00:46:06 +00002053 ret_val = hw->phy.ops.acquire(hw);
2054 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002055 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002056 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002057 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002058 if (ret_val)
2059 goto release;
2060 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002061 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002062release:
2063 hw->phy.ops.release(hw);
2064
Bruce Alland3738bb2010-06-16 13:27:28 +00002065 return ret_val;
2066}
2067
2068/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002069 * e1000_k1_gig_workaround_lv - K1 Si workaround
2070 * @hw: pointer to the HW structure
2071 *
2072 * Workaround to set the K1 beacon duration for 82579 parts
2073 **/
2074static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2075{
2076 s32 ret_val = 0;
2077 u16 status_reg = 0;
2078 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002079 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002080
2081 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002082 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002083
2084 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2085 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2086 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002087 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002088
2089 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2090 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2091 mac_reg = er32(FEXTNVM4);
2092 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2093
Bruce Allan0ed013e2011-07-29 05:52:56 +00002094 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2095 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002096 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002097
Bruce Allan0ed013e2011-07-29 05:52:56 +00002098 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002099 u16 pm_phy_reg;
2100
Bruce Allan0ed013e2011-07-29 05:52:56 +00002101 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2102 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002103 /* LV 1G Packet drop issue wa */
2104 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2105 if (ret_val)
2106 return ret_val;
2107 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2108 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2109 if (ret_val)
2110 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002111 } else {
2112 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2113 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2114 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002115 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002116 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002117 }
2118
Bruce Allan831bd2e2010-09-22 17:16:18 +00002119 return ret_val;
2120}
2121
2122/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002123 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2124 * @hw: pointer to the HW structure
2125 * @gate: boolean set to true to gate, false to ungate
2126 *
2127 * Gate/ungate the automatic PHY configuration via hardware; perform
2128 * the configuration via software instead.
2129 **/
2130static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2131{
2132 u32 extcnf_ctrl;
2133
Bruce Allan2fbe4522012-04-19 03:21:47 +00002134 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002135 return;
2136
2137 extcnf_ctrl = er32(EXTCNF_CTRL);
2138
2139 if (gate)
2140 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2141 else
2142 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2143
2144 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002145}
2146
2147/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002148 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2149 * @hw: pointer to the HW structure
2150 *
2151 * Check the appropriate indication the MAC has finished configuring the
2152 * PHY after a software reset.
2153 **/
2154static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2155{
2156 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2157
2158 /* Wait for basic configuration completes before proceeding */
2159 do {
2160 data = er32(STATUS);
2161 data &= E1000_STATUS_LAN_INIT_DONE;
2162 udelay(100);
2163 } while ((!data) && --loop);
2164
Bruce Allane921eb12012-11-28 09:28:37 +00002165 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002166 * count reaches 0, loading the configuration from NVM will
2167 * leave the PHY in a bad state possibly resulting in no link.
2168 */
2169 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002170 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002171
2172 /* Clear the Init Done bit for the next init event */
2173 data = er32(STATUS);
2174 data &= ~E1000_STATUS_LAN_INIT_DONE;
2175 ew32(STATUS, data);
2176}
2177
2178/**
Bruce Allane98cac42010-05-10 15:02:32 +00002179 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002180 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002181 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002182static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002183{
Bruce Allanf523d212009-10-29 13:45:45 +00002184 s32 ret_val = 0;
2185 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002186
Bruce Allan44abd5c2012-02-22 09:02:37 +00002187 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002188 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002189
Bruce Allan5f3eed62010-09-22 17:15:54 +00002190 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002191 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002192
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002193 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002194 switch (hw->mac.type) {
2195 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002196 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2197 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002198 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002199 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002200 case e1000_pch2lan:
2201 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2202 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002203 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002204 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002205 default:
2206 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002207 }
2208
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002209 /* Clear the host wakeup bit after lcd reset */
2210 if (hw->mac.type >= e1000_pchlan) {
2211 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2212 reg &= ~BM_WUC_HOST_WU_BIT;
2213 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2214 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002215
Bruce Allanf523d212009-10-29 13:45:45 +00002216 /* Configure the LCD with the extended configuration region in NVM */
2217 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2218 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002219 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002220
Bruce Allanf523d212009-10-29 13:45:45 +00002221 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002222 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002223
Bruce Allan1effb452011-02-25 06:58:03 +00002224 if (hw->mac.type == e1000_pch2lan) {
2225 /* Ungate automatic PHY configuration on non-managed 82579 */
2226 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002227 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002228 e1000_gate_hw_phy_config_ich8lan(hw, false);
2229 }
2230
2231 /* Set EEE LPI Update Timer to 200usec */
2232 ret_val = hw->phy.ops.acquire(hw);
2233 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002234 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002235 ret_val = e1000_write_emi_reg_locked(hw,
2236 I82579_LPI_UPDATE_TIMER,
2237 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002238 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002239 }
2240
Bruce Allane98cac42010-05-10 15:02:32 +00002241 return ret_val;
2242}
2243
2244/**
2245 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2246 * @hw: pointer to the HW structure
2247 *
2248 * Resets the PHY
2249 * This is a function pointer entry point called by drivers
2250 * or other shared routines.
2251 **/
2252static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2253{
2254 s32 ret_val = 0;
2255
Bruce Allan605c82b2010-09-22 17:17:01 +00002256 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2257 if ((hw->mac.type == e1000_pch2lan) &&
2258 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2259 e1000_gate_hw_phy_config_ich8lan(hw, true);
2260
Bruce Allane98cac42010-05-10 15:02:32 +00002261 ret_val = e1000e_phy_hw_reset_generic(hw);
2262 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002263 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002264
Bruce Allan5015e532012-02-08 02:55:56 +00002265 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002266}
2267
2268/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002269 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2270 * @hw: pointer to the HW structure
2271 * @active: true to enable LPLU, false to disable
2272 *
2273 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2274 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2275 * the phy speed. This function will manually set the LPLU bit and restart
2276 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2277 * since it configures the same bit.
2278 **/
2279static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2280{
2281 s32 ret_val = 0;
2282 u16 oem_reg;
2283
2284 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2285 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002286 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002287
2288 if (active)
2289 oem_reg |= HV_OEM_BITS_LPLU;
2290 else
2291 oem_reg &= ~HV_OEM_BITS_LPLU;
2292
Bruce Allan44abd5c2012-02-22 09:02:37 +00002293 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002294 oem_reg |= HV_OEM_BITS_RESTART_AN;
2295
Bruce Allan5015e532012-02-08 02:55:56 +00002296 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002297}
2298
2299/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002300 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2301 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002302 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002303 *
2304 * Sets the LPLU D0 state according to the active flag. When
2305 * activating LPLU this function also disables smart speed
2306 * and vice versa. LPLU will not be activated unless the
2307 * device autonegotiation advertisement meets standards of
2308 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2309 * This is a function pointer entry point only called by
2310 * PHY setup routines.
2311 **/
2312static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2313{
2314 struct e1000_phy_info *phy = &hw->phy;
2315 u32 phy_ctrl;
2316 s32 ret_val = 0;
2317 u16 data;
2318
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002319 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002320 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002321
2322 phy_ctrl = er32(PHY_CTRL);
2323
2324 if (active) {
2325 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2326 ew32(PHY_CTRL, phy_ctrl);
2327
Bruce Allan60f12922009-07-01 13:28:14 +00002328 if (phy->type != e1000_phy_igp_3)
2329 return 0;
2330
Bruce Allane921eb12012-11-28 09:28:37 +00002331 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002332 * any PHY registers
2333 */
Bruce Allan60f12922009-07-01 13:28:14 +00002334 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002335 e1000e_gig_downshift_workaround_ich8lan(hw);
2336
2337 /* When LPLU is enabled, we should disable SmartSpeed */
2338 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
2339 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2340 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2341 if (ret_val)
2342 return ret_val;
2343 } else {
2344 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2345 ew32(PHY_CTRL, phy_ctrl);
2346
Bruce Allan60f12922009-07-01 13:28:14 +00002347 if (phy->type != e1000_phy_igp_3)
2348 return 0;
2349
Bruce Allane921eb12012-11-28 09:28:37 +00002350 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002351 * during Dx states where the power conservation is most
2352 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002353 * SmartSpeed, so performance is maintained.
2354 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002355 if (phy->smart_speed == e1000_smart_speed_on) {
2356 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002357 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002358 if (ret_val)
2359 return ret_val;
2360
2361 data |= IGP01E1000_PSCFR_SMART_SPEED;
2362 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002363 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002364 if (ret_val)
2365 return ret_val;
2366 } else if (phy->smart_speed == e1000_smart_speed_off) {
2367 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002368 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002369 if (ret_val)
2370 return ret_val;
2371
2372 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2373 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002374 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002375 if (ret_val)
2376 return ret_val;
2377 }
2378 }
2379
2380 return 0;
2381}
2382
2383/**
2384 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2385 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002386 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002387 *
2388 * Sets the LPLU D3 state according to the active flag. When
2389 * activating LPLU this function also disables smart speed
2390 * and vice versa. LPLU will not be activated unless the
2391 * device autonegotiation advertisement meets standards of
2392 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2393 * This is a function pointer entry point only called by
2394 * PHY setup routines.
2395 **/
2396static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2397{
2398 struct e1000_phy_info *phy = &hw->phy;
2399 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002400 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002401 u16 data;
2402
2403 phy_ctrl = er32(PHY_CTRL);
2404
2405 if (!active) {
2406 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2407 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002408
2409 if (phy->type != e1000_phy_igp_3)
2410 return 0;
2411
Bruce Allane921eb12012-11-28 09:28:37 +00002412 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002413 * during Dx states where the power conservation is most
2414 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002415 * SmartSpeed, so performance is maintained.
2416 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002417 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002418 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2419 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002420 if (ret_val)
2421 return ret_val;
2422
2423 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002424 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2425 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002426 if (ret_val)
2427 return ret_val;
2428 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002429 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2430 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 if (ret_val)
2432 return ret_val;
2433
2434 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002435 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2436 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437 if (ret_val)
2438 return ret_val;
2439 }
2440 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2441 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2442 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2443 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2444 ew32(PHY_CTRL, phy_ctrl);
2445
Bruce Allan60f12922009-07-01 13:28:14 +00002446 if (phy->type != e1000_phy_igp_3)
2447 return 0;
2448
Bruce Allane921eb12012-11-28 09:28:37 +00002449 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002450 * any PHY registers
2451 */
Bruce Allan60f12922009-07-01 13:28:14 +00002452 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002453 e1000e_gig_downshift_workaround_ich8lan(hw);
2454
2455 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002456 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002457 if (ret_val)
2458 return ret_val;
2459
2460 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002461 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002462 }
2463
Bruce Alland7eb3382012-02-08 02:55:14 +00002464 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465}
2466
2467/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002468 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2469 * @hw: pointer to the HW structure
2470 * @bank: pointer to the variable that returns the active bank
2471 *
2472 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002473 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002474 **/
2475static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2476{
Bruce Allane2434552008-11-21 17:02:41 -08002477 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002478 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002479 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2480 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002481 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002482 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002483
Bruce Allane2434552008-11-21 17:02:41 -08002484 switch (hw->mac.type) {
2485 case e1000_ich8lan:
2486 case e1000_ich9lan:
2487 eecd = er32(EECD);
2488 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2489 E1000_EECD_SEC1VAL_VALID_MASK) {
2490 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002491 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002492 else
2493 *bank = 0;
2494
2495 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002496 }
Bruce Allan434f1392011-12-16 00:46:54 +00002497 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002498 /* fall-thru */
2499 default:
2500 /* set bank to 0 in case flash read fails */
2501 *bank = 0;
2502
2503 /* Check bank 0 */
2504 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
2505 &sig_byte);
2506 if (ret_val)
2507 return ret_val;
2508 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2509 E1000_ICH_NVM_SIG_VALUE) {
2510 *bank = 0;
2511 return 0;
2512 }
2513
2514 /* Check bank 1 */
2515 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
2516 bank1_offset,
2517 &sig_byte);
2518 if (ret_val)
2519 return ret_val;
2520 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2521 E1000_ICH_NVM_SIG_VALUE) {
2522 *bank = 1;
2523 return 0;
2524 }
2525
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002526 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002527 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002528 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002529}
2530
2531/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002532 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2533 * @hw: pointer to the HW structure
2534 * @offset: The offset (in bytes) of the word(s) to read.
2535 * @words: Size of data to read in words
2536 * @data: Pointer to the word(s) to read at offset.
2537 *
2538 * Reads a word(s) from the NVM using the flash access registers.
2539 **/
2540static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2541 u16 *data)
2542{
2543 struct e1000_nvm_info *nvm = &hw->nvm;
2544 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2545 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002546 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002547 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002548 u16 i, word;
2549
2550 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2551 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002552 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002553 ret_val = -E1000_ERR_NVM;
2554 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555 }
2556
Bruce Allan94d81862009-11-20 23:25:26 +00002557 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002558
Bruce Allanf4187b52008-08-26 18:36:50 -07002559 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002560 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002561 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002562 bank = 0;
2563 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002564
2565 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566 act_offset += offset;
2567
Bruce Allan148675a2009-08-07 07:41:56 +00002568 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002569 for (i = 0; i < words; i++) {
Bruce Allanb9e06f72011-07-22 06:21:41 +00002570 if (dev_spec->shadow_ram[offset+i].modified) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002571 data[i] = dev_spec->shadow_ram[offset+i].value;
2572 } else {
2573 ret_val = e1000_read_flash_word_ich8lan(hw,
2574 act_offset + i,
2575 &word);
2576 if (ret_val)
2577 break;
2578 data[i] = word;
2579 }
2580 }
2581
Bruce Allan94d81862009-11-20 23:25:26 +00002582 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002583
Bruce Allane2434552008-11-21 17:02:41 -08002584out:
2585 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002586 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002587
Auke Kokbc7f75f2007-09-17 12:30:59 -07002588 return ret_val;
2589}
2590
2591/**
2592 * e1000_flash_cycle_init_ich8lan - Initialize flash
2593 * @hw: pointer to the HW structure
2594 *
2595 * This function does initial flash setup so that a new read/write/erase cycle
2596 * can be started.
2597 **/
2598static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2599{
2600 union ich8_hws_flash_status hsfsts;
2601 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002602
2603 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2604
2605 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002606 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002607 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002608 return -E1000_ERR_NVM;
2609 }
2610
2611 /* Clear FCERR and DAEL in hw status by writing 1 */
2612 hsfsts.hsf_status.flcerr = 1;
2613 hsfsts.hsf_status.dael = 1;
2614
2615 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2616
Bruce Allane921eb12012-11-28 09:28:37 +00002617 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002618 * bit to check against, in order to start a new cycle or
2619 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002620 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002621 * indication whether a cycle is in progress or has been
2622 * completed.
2623 */
2624
Bruce Allan04499ec2012-04-13 00:08:31 +00002625 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002626 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002627 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002628 * Begin by setting Flash Cycle Done.
2629 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002630 hsfsts.hsf_status.flcdone = 1;
2631 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2632 ret_val = 0;
2633 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002634 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002635
Bruce Allane921eb12012-11-28 09:28:37 +00002636 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002637 * cycle has a chance to end before giving up.
2638 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002639 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002640 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002641 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002642 ret_val = 0;
2643 break;
2644 }
2645 udelay(1);
2646 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002647 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002648 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002649 * now set the Flash Cycle Done.
2650 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002651 hsfsts.hsf_status.flcdone = 1;
2652 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2653 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002654 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002655 }
2656 }
2657
2658 return ret_val;
2659}
2660
2661/**
2662 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2663 * @hw: pointer to the HW structure
2664 * @timeout: maximum time to wait for completion
2665 *
2666 * This function starts a flash cycle and waits for its completion.
2667 **/
2668static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2669{
2670 union ich8_hws_flash_ctrl hsflctl;
2671 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002672 u32 i = 0;
2673
2674 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2675 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2676 hsflctl.hsf_ctrl.flcgo = 1;
2677 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2678
2679 /* wait till FDONE bit is set to 1 */
2680 do {
2681 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002682 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002683 break;
2684 udelay(1);
2685 } while (i++ < timeout);
2686
Bruce Allan04499ec2012-04-13 00:08:31 +00002687 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002688 return 0;
2689
Bruce Allan55920b52012-02-08 02:55:25 +00002690 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002691}
2692
2693/**
2694 * e1000_read_flash_word_ich8lan - Read word from flash
2695 * @hw: pointer to the HW structure
2696 * @offset: offset to data location
2697 * @data: pointer to the location for storing the data
2698 *
2699 * Reads the flash word at offset into data. Offset is converted
2700 * to bytes before read.
2701 **/
2702static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2703 u16 *data)
2704{
2705 /* Must convert offset into bytes. */
2706 offset <<= 1;
2707
2708 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2709}
2710
2711/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002712 * e1000_read_flash_byte_ich8lan - Read byte from flash
2713 * @hw: pointer to the HW structure
2714 * @offset: The offset of the byte to read.
2715 * @data: Pointer to a byte to store the value read.
2716 *
2717 * Reads a single byte from the NVM using the flash access registers.
2718 **/
2719static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2720 u8 *data)
2721{
2722 s32 ret_val;
2723 u16 word = 0;
2724
2725 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2726 if (ret_val)
2727 return ret_val;
2728
2729 *data = (u8)word;
2730
2731 return 0;
2732}
2733
2734/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002735 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2736 * @hw: pointer to the HW structure
2737 * @offset: The offset (in bytes) of the byte or word to read.
2738 * @size: Size of data to read, 1=byte 2=word
2739 * @data: Pointer to the word to store the value read.
2740 *
2741 * Reads a byte or word from the NVM using the flash access registers.
2742 **/
2743static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2744 u8 size, u16 *data)
2745{
2746 union ich8_hws_flash_status hsfsts;
2747 union ich8_hws_flash_ctrl hsflctl;
2748 u32 flash_linear_addr;
2749 u32 flash_data = 0;
2750 s32 ret_val = -E1000_ERR_NVM;
2751 u8 count = 0;
2752
2753 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2754 return -E1000_ERR_NVM;
2755
2756 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2757 hw->nvm.flash_base_addr;
2758
2759 do {
2760 udelay(1);
2761 /* Steps */
2762 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002763 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002764 break;
2765
2766 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2767 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2768 hsflctl.hsf_ctrl.fldbcount = size - 1;
2769 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2770 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2771
2772 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2773
2774 ret_val = e1000_flash_cycle_ich8lan(hw,
2775 ICH_FLASH_READ_COMMAND_TIMEOUT);
2776
Bruce Allane921eb12012-11-28 09:28:37 +00002777 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002778 * and try the whole sequence a few more times, else
2779 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002780 * least significant byte first msb to lsb
2781 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002782 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002783 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002784 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002785 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002786 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002788 break;
2789 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002790 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002791 * completely hosed, but if the error condition is
2792 * detected, it won't hurt to give it another try...
2793 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2794 */
2795 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002796 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002797 /* Repeat for some time before giving up. */
2798 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002799 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002800 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801 break;
2802 }
2803 }
2804 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2805
2806 return ret_val;
2807}
2808
2809/**
2810 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2811 * @hw: pointer to the HW structure
2812 * @offset: The offset (in bytes) of the word(s) to write.
2813 * @words: Size of data to write in words
2814 * @data: Pointer to the word(s) to write at offset.
2815 *
2816 * Writes a byte or word to the NVM using the flash access registers.
2817 **/
2818static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2819 u16 *data)
2820{
2821 struct e1000_nvm_info *nvm = &hw->nvm;
2822 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002823 u16 i;
2824
2825 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2826 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002827 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002828 return -E1000_ERR_NVM;
2829 }
2830
Bruce Allan94d81862009-11-20 23:25:26 +00002831 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002832
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002834 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835 dev_spec->shadow_ram[offset+i].value = data[i];
2836 }
2837
Bruce Allan94d81862009-11-20 23:25:26 +00002838 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002839
Auke Kokbc7f75f2007-09-17 12:30:59 -07002840 return 0;
2841}
2842
2843/**
2844 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2845 * @hw: pointer to the HW structure
2846 *
2847 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2848 * which writes the checksum to the shadow ram. The changes in the shadow
2849 * ram are then committed to the EEPROM by processing each bank at a time
2850 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002851 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002852 * future writes.
2853 **/
2854static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2855{
2856 struct e1000_nvm_info *nvm = &hw->nvm;
2857 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002858 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002859 s32 ret_val;
2860 u16 data;
2861
2862 ret_val = e1000e_update_nvm_checksum_generic(hw);
2863 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002864 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002865
2866 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002867 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002868
Bruce Allan94d81862009-11-20 23:25:26 +00002869 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002870
Bruce Allane921eb12012-11-28 09:28:37 +00002871 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002872 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002873 * is going to be written
2874 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002875 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002876 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002877 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002878 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002879 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002880
2881 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002882 new_bank_offset = nvm->flash_bank_size;
2883 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002884 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002885 if (ret_val)
2886 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002887 } else {
2888 old_bank_offset = nvm->flash_bank_size;
2889 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002890 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002891 if (ret_val)
2892 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002893 }
2894
2895 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00002896 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002897 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002898 * in the shadow RAM
2899 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002900 if (dev_spec->shadow_ram[i].modified) {
2901 data = dev_spec->shadow_ram[i].value;
2902 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002903 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2904 old_bank_offset,
2905 &data);
2906 if (ret_val)
2907 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002908 }
2909
Bruce Allane921eb12012-11-28 09:28:37 +00002910 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911 * (15:14) are 11b until the commit has completed.
2912 * This will allow us to write 10b which indicates the
2913 * signature is valid. We want to do this after the write
2914 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002915 * while the write is still in progress
2916 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002917 if (i == E1000_ICH_NVM_SIG_WORD)
2918 data |= E1000_ICH_NVM_SIG_MASK;
2919
2920 /* Convert offset to bytes. */
2921 act_offset = (i + new_bank_offset) << 1;
2922
2923 udelay(100);
2924 /* Write the bytes to the new bank. */
2925 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2926 act_offset,
2927 (u8)data);
2928 if (ret_val)
2929 break;
2930
2931 udelay(100);
2932 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2933 act_offset + 1,
2934 (u8)(data >> 8));
2935 if (ret_val)
2936 break;
2937 }
2938
Bruce Allane921eb12012-11-28 09:28:37 +00002939 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07002940 * programming failed.
2941 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002942 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002943 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002944 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002945 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002946 }
2947
Bruce Allane921eb12012-11-28 09:28:37 +00002948 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002949 * to 10b in word 0x13 , this can be done without an
2950 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002951 * and we need to change bit 14 to 0b
2952 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002953 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002954 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002955 if (ret_val)
2956 goto release;
2957
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 data &= 0xBFFF;
2959 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2960 act_offset * 2 + 1,
2961 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002962 if (ret_val)
2963 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964
Bruce Allane921eb12012-11-28 09:28:37 +00002965 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002966 * its signature word (0x13) high_byte to 0b. This can be
2967 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002968 * to 1's. We can write 1's to 0's without an erase
2969 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002970 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2971 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002972 if (ret_val)
2973 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974
2975 /* Great! Everything worked, we can now clear the cached entries. */
2976 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002977 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002978 dev_spec->shadow_ram[i].value = 0xFFFF;
2979 }
2980
Bruce Allan9c5e2092010-05-10 15:00:31 +00002981release:
Bruce Allan94d81862009-11-20 23:25:26 +00002982 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002983
Bruce Allane921eb12012-11-28 09:28:37 +00002984 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002985 * until after the next adapter reset.
2986 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002987 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00002988 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00002989 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002990 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002991
Bruce Allane2434552008-11-21 17:02:41 -08002992out:
2993 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002994 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002995
Auke Kokbc7f75f2007-09-17 12:30:59 -07002996 return ret_val;
2997}
2998
2999/**
3000 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3001 * @hw: pointer to the HW structure
3002 *
3003 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3004 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3005 * calculated, in which case we need to calculate the checksum and set bit 6.
3006 **/
3007static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3008{
3009 s32 ret_val;
3010 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003011 u16 word;
3012 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003013
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003014 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3015 * the checksum needs to be fixed. This bit is an indication that
3016 * the NVM was prepared by OEM software and did not calculate
3017 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003018 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003019 switch (hw->mac.type) {
3020 case e1000_pch_lpt:
3021 word = NVM_COMPAT;
3022 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3023 break;
3024 default:
3025 word = NVM_FUTURE_INIT_WORD1;
3026 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3027 break;
3028 }
3029
3030 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003031 if (ret_val)
3032 return ret_val;
3033
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003034 if (!(data & valid_csum_mask)) {
3035 data |= valid_csum_mask;
3036 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003037 if (ret_val)
3038 return ret_val;
3039 ret_val = e1000e_update_nvm_checksum(hw);
3040 if (ret_val)
3041 return ret_val;
3042 }
3043
3044 return e1000e_validate_nvm_checksum_generic(hw);
3045}
3046
3047/**
Bruce Allan4a770352008-10-01 17:18:35 -07003048 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3049 * @hw: pointer to the HW structure
3050 *
3051 * To prevent malicious write/erase of the NVM, set it to be read-only
3052 * so that the hardware ignores all write/erase cycles of the NVM via
3053 * the flash control registers. The shadow-ram copy of the NVM will
3054 * still be updated, however any updates to this copy will not stick
3055 * across driver reloads.
3056 **/
3057void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3058{
Bruce Allanca15df52009-10-26 11:23:43 +00003059 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003060 union ich8_flash_protected_range pr0;
3061 union ich8_hws_flash_status hsfsts;
3062 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003063
Bruce Allan94d81862009-11-20 23:25:26 +00003064 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003065
3066 gfpreg = er32flash(ICH_FLASH_GFPREG);
3067
3068 /* Write-protect GbE Sector of NVM */
3069 pr0.regval = er32flash(ICH_FLASH_PR0);
3070 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3071 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3072 pr0.range.wpe = true;
3073 ew32flash(ICH_FLASH_PR0, pr0.regval);
3074
Bruce Allane921eb12012-11-28 09:28:37 +00003075 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003076 * PR0 to prevent the write-protection from being lifted.
3077 * Once FLOCKDN is set, the registers protected by it cannot
3078 * be written until FLOCKDN is cleared by a hardware reset.
3079 */
3080 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3081 hsfsts.hsf_status.flockdn = true;
3082 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3083
Bruce Allan94d81862009-11-20 23:25:26 +00003084 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003085}
3086
3087/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003088 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3089 * @hw: pointer to the HW structure
3090 * @offset: The offset (in bytes) of the byte/word to read.
3091 * @size: Size of data to read, 1=byte 2=word
3092 * @data: The byte(s) to write to the NVM.
3093 *
3094 * Writes one/two bytes to the NVM using the flash access registers.
3095 **/
3096static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3097 u8 size, u16 data)
3098{
3099 union ich8_hws_flash_status hsfsts;
3100 union ich8_hws_flash_ctrl hsflctl;
3101 u32 flash_linear_addr;
3102 u32 flash_data = 0;
3103 s32 ret_val;
3104 u8 count = 0;
3105
3106 if (size < 1 || size > 2 || data > size * 0xff ||
3107 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3108 return -E1000_ERR_NVM;
3109
3110 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3111 hw->nvm.flash_base_addr;
3112
3113 do {
3114 udelay(1);
3115 /* Steps */
3116 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3117 if (ret_val)
3118 break;
3119
3120 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3121 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
3122 hsflctl.hsf_ctrl.fldbcount = size -1;
3123 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3124 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3125
3126 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3127
3128 if (size == 1)
3129 flash_data = (u32)data & 0x00FF;
3130 else
3131 flash_data = (u32)data;
3132
3133 ew32flash(ICH_FLASH_FDATA0, flash_data);
3134
Bruce Allane921eb12012-11-28 09:28:37 +00003135 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003136 * and try the whole sequence a few more times else done
3137 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003138 ret_val = e1000_flash_cycle_ich8lan(hw,
3139 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
3140 if (!ret_val)
3141 break;
3142
Bruce Allane921eb12012-11-28 09:28:37 +00003143 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003144 * completely hosed, but if the error condition
3145 * is detected, it won't hurt to give it another
3146 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3147 */
3148 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003149 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003150 /* Repeat for some time before giving up. */
3151 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003152 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003153 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003154 break;
3155 }
3156 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3157
3158 return ret_val;
3159}
3160
3161/**
3162 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3163 * @hw: pointer to the HW structure
3164 * @offset: The index of the byte to read.
3165 * @data: The byte to write to the NVM.
3166 *
3167 * Writes a single byte to the NVM using the flash access registers.
3168 **/
3169static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3170 u8 data)
3171{
3172 u16 word = (u16)data;
3173
3174 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3175}
3176
3177/**
3178 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3179 * @hw: pointer to the HW structure
3180 * @offset: The offset of the byte to write.
3181 * @byte: The byte to write to the NVM.
3182 *
3183 * Writes a single byte to the NVM using the flash access registers.
3184 * Goes through a retry algorithm before giving up.
3185 **/
3186static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3187 u32 offset, u8 byte)
3188{
3189 s32 ret_val;
3190 u16 program_retries;
3191
3192 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3193 if (!ret_val)
3194 return ret_val;
3195
3196 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003197 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003198 udelay(100);
3199 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3200 if (!ret_val)
3201 break;
3202 }
3203 if (program_retries == 100)
3204 return -E1000_ERR_NVM;
3205
3206 return 0;
3207}
3208
3209/**
3210 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3211 * @hw: pointer to the HW structure
3212 * @bank: 0 for first bank, 1 for second bank, etc.
3213 *
3214 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3215 * bank N is 4096 * N + flash_reg_addr.
3216 **/
3217static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3218{
3219 struct e1000_nvm_info *nvm = &hw->nvm;
3220 union ich8_hws_flash_status hsfsts;
3221 union ich8_hws_flash_ctrl hsflctl;
3222 u32 flash_linear_addr;
3223 /* bank size is in 16bit words - adjust to bytes */
3224 u32 flash_bank_size = nvm->flash_bank_size * 2;
3225 s32 ret_val;
3226 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003227 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003228
3229 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3230
Bruce Allane921eb12012-11-28 09:28:37 +00003231 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003232 * register
3233 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003234 * consecutive sectors. The start index for the nth Hw sector
3235 * can be calculated as = bank * 4096 + n * 256
3236 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3237 * The start index for the nth Hw sector can be calculated
3238 * as = bank * 4096
3239 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3240 * (ich9 only, otherwise error condition)
3241 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3242 */
3243 switch (hsfsts.hsf_status.berasesz) {
3244 case 0:
3245 /* Hw sector size 256 */
3246 sector_size = ICH_FLASH_SEG_SIZE_256;
3247 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3248 break;
3249 case 1:
3250 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003251 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003252 break;
3253 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003254 sector_size = ICH_FLASH_SEG_SIZE_8K;
3255 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003256 break;
3257 case 3:
3258 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003259 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003260 break;
3261 default:
3262 return -E1000_ERR_NVM;
3263 }
3264
3265 /* Start with the base address, then add the sector offset. */
3266 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003267 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003268
3269 for (j = 0; j < iteration ; j++) {
3270 do {
3271 /* Steps */
3272 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3273 if (ret_val)
3274 return ret_val;
3275
Bruce Allane921eb12012-11-28 09:28:37 +00003276 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003277 * Cycle field in hw flash control
3278 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003279 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3280 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3281 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3282
Bruce Allane921eb12012-11-28 09:28:37 +00003283 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003284 * block into Flash Linear address field in Flash
3285 * Address.
3286 */
3287 flash_linear_addr += (j * sector_size);
3288 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3289
3290 ret_val = e1000_flash_cycle_ich8lan(hw,
3291 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003292 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003293 break;
3294
Bruce Allane921eb12012-11-28 09:28:37 +00003295 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003296 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003297 * a few more times else Done
3298 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003299 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003300 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003301 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003303 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003304 return ret_val;
3305 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3306 }
3307
3308 return 0;
3309}
3310
3311/**
3312 * e1000_valid_led_default_ich8lan - Set the default LED settings
3313 * @hw: pointer to the HW structure
3314 * @data: Pointer to the LED settings
3315 *
3316 * Reads the LED default settings from the NVM to data. If the NVM LED
3317 * settings is all 0's or F's, set the LED default to a valid LED default
3318 * setting.
3319 **/
3320static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3321{
3322 s32 ret_val;
3323
3324 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3325 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003326 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003327 return ret_val;
3328 }
3329
3330 if (*data == ID_LED_RESERVED_0000 ||
3331 *data == ID_LED_RESERVED_FFFF)
3332 *data = ID_LED_DEFAULT_ICH8LAN;
3333
3334 return 0;
3335}
3336
3337/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003338 * e1000_id_led_init_pchlan - store LED configurations
3339 * @hw: pointer to the HW structure
3340 *
3341 * PCH does not control LEDs via the LEDCTL register, rather it uses
3342 * the PHY LED configuration register.
3343 *
3344 * PCH also does not have an "always on" or "always off" mode which
3345 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003346 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003347 * use "link_up" mode. The LEDs will still ID on request if there is no
3348 * link based on logic in e1000_led_[on|off]_pchlan().
3349 **/
3350static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3351{
3352 struct e1000_mac_info *mac = &hw->mac;
3353 s32 ret_val;
3354 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3355 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3356 u16 data, i, temp, shift;
3357
3358 /* Get default ID LED modes */
3359 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3360 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003361 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003362
3363 mac->ledctl_default = er32(LEDCTL);
3364 mac->ledctl_mode1 = mac->ledctl_default;
3365 mac->ledctl_mode2 = mac->ledctl_default;
3366
3367 for (i = 0; i < 4; i++) {
3368 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3369 shift = (i * 5);
3370 switch (temp) {
3371 case ID_LED_ON1_DEF2:
3372 case ID_LED_ON1_ON2:
3373 case ID_LED_ON1_OFF2:
3374 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3375 mac->ledctl_mode1 |= (ledctl_on << shift);
3376 break;
3377 case ID_LED_OFF1_DEF2:
3378 case ID_LED_OFF1_ON2:
3379 case ID_LED_OFF1_OFF2:
3380 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3381 mac->ledctl_mode1 |= (ledctl_off << shift);
3382 break;
3383 default:
3384 /* Do nothing */
3385 break;
3386 }
3387 switch (temp) {
3388 case ID_LED_DEF1_ON2:
3389 case ID_LED_ON1_ON2:
3390 case ID_LED_OFF1_ON2:
3391 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3392 mac->ledctl_mode2 |= (ledctl_on << shift);
3393 break;
3394 case ID_LED_DEF1_OFF2:
3395 case ID_LED_ON1_OFF2:
3396 case ID_LED_OFF1_OFF2:
3397 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3398 mac->ledctl_mode2 |= (ledctl_off << shift);
3399 break;
3400 default:
3401 /* Do nothing */
3402 break;
3403 }
3404 }
3405
Bruce Allan5015e532012-02-08 02:55:56 +00003406 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003407}
3408
3409/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003410 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3411 * @hw: pointer to the HW structure
3412 *
3413 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3414 * register, so the the bus width is hard coded.
3415 **/
3416static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3417{
3418 struct e1000_bus_info *bus = &hw->bus;
3419 s32 ret_val;
3420
3421 ret_val = e1000e_get_bus_info_pcie(hw);
3422
Bruce Allane921eb12012-11-28 09:28:37 +00003423 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003424 * a configuration space, but do not contain
3425 * PCI Express Capability registers, so bus width
3426 * must be hardcoded.
3427 */
3428 if (bus->width == e1000_bus_width_unknown)
3429 bus->width = e1000_bus_width_pcie_x1;
3430
3431 return ret_val;
3432}
3433
3434/**
3435 * e1000_reset_hw_ich8lan - Reset the hardware
3436 * @hw: pointer to the HW structure
3437 *
3438 * Does a full reset of the hardware which includes a reset of the PHY and
3439 * MAC.
3440 **/
3441static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3442{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003443 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003444 u16 kum_cfg;
3445 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003446 s32 ret_val;
3447
Bruce Allane921eb12012-11-28 09:28:37 +00003448 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003449 * on the last TLP read/write transaction when MAC is reset.
3450 */
3451 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003452 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003453 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003454
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003455 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003456 ew32(IMC, 0xffffffff);
3457
Bruce Allane921eb12012-11-28 09:28:37 +00003458 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003459 * any pending transactions to complete before we hit the MAC
3460 * with the global reset.
3461 */
3462 ew32(RCTL, 0);
3463 ew32(TCTL, E1000_TCTL_PSP);
3464 e1e_flush();
3465
Bruce Allan1bba4382011-03-19 00:27:20 +00003466 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003467
3468 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3469 if (hw->mac.type == e1000_ich8lan) {
3470 /* Set Tx and Rx buffer allocation to 8k apiece. */
3471 ew32(PBA, E1000_PBA_8K);
3472 /* Set Packet Buffer Size to 16k. */
3473 ew32(PBS, E1000_PBS_16K);
3474 }
3475
Bruce Allan1d5846b2009-10-29 13:46:05 +00003476 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003477 /* Save the NVM K1 bit setting */
3478 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003479 if (ret_val)
3480 return ret_val;
3481
Bruce Allan62bc8132012-03-20 03:47:57 +00003482 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003483 dev_spec->nvm_k1_enabled = true;
3484 else
3485 dev_spec->nvm_k1_enabled = false;
3486 }
3487
Auke Kokbc7f75f2007-09-17 12:30:59 -07003488 ctrl = er32(CTRL);
3489
Bruce Allan44abd5c2012-02-22 09:02:37 +00003490 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003491 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003492 * time to make sure the interface between MAC and the
3493 * external PHY is reset.
3494 */
3495 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003496
Bruce Allane921eb12012-11-28 09:28:37 +00003497 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003498 * non-managed 82579
3499 */
3500 if ((hw->mac.type == e1000_pch2lan) &&
3501 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3502 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003503 }
3504 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003505 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003506 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003507 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003508 msleep(20);
3509
Bruce Allan62bc8132012-03-20 03:47:57 +00003510 /* Set Phy Config Counter to 50msec */
3511 if (hw->mac.type == e1000_pch2lan) {
3512 reg = er32(FEXTNVM3);
3513 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3514 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3515 ew32(FEXTNVM3, reg);
3516 }
3517
Bruce Allanfc0c7762009-07-01 13:27:55 +00003518 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003519 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003520
Bruce Allane98cac42010-05-10 15:02:32 +00003521 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003522 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003523 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003524 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003525
Bruce Allane98cac42010-05-10 15:02:32 +00003526 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003527 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003528 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003529 }
Bruce Allane98cac42010-05-10 15:02:32 +00003530
Bruce Allane921eb12012-11-28 09:28:37 +00003531 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003532 * will be detected as a CRC error and be dropped rather than show up
3533 * as a bad packet to the DMA engine.
3534 */
3535 if (hw->mac.type == e1000_pchlan)
3536 ew32(CRC_OFFSET, 0x65656565);
3537
Auke Kokbc7f75f2007-09-17 12:30:59 -07003538 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003539 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003540
Bruce Allan62bc8132012-03-20 03:47:57 +00003541 reg = er32(KABGTXD);
3542 reg |= E1000_KABGTXD_BGSQLBIAS;
3543 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003544
Bruce Allan5015e532012-02-08 02:55:56 +00003545 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003546}
3547
3548/**
3549 * e1000_init_hw_ich8lan - Initialize the hardware
3550 * @hw: pointer to the HW structure
3551 *
3552 * Prepares the hardware for transmit and receive by doing the following:
3553 * - initialize hardware bits
3554 * - initialize LED identification
3555 * - setup receive address registers
3556 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003557 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003558 * - clear statistics
3559 **/
3560static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3561{
3562 struct e1000_mac_info *mac = &hw->mac;
3563 u32 ctrl_ext, txdctl, snoop;
3564 s32 ret_val;
3565 u16 i;
3566
3567 e1000_initialize_hw_bits_ich8lan(hw);
3568
3569 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003570 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00003571 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003572 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00003573 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003574
3575 /* Setup the receive address. */
3576 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3577
3578 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003579 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003580 for (i = 0; i < mac->mta_reg_count; i++)
3581 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3582
Bruce Allane921eb12012-11-28 09:28:37 +00003583 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003584 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003585 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3586 */
3587 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003588 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3589 i &= ~BM_WUC_HOST_WU_BIT;
3590 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003591 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3592 if (ret_val)
3593 return ret_val;
3594 }
3595
Auke Kokbc7f75f2007-09-17 12:30:59 -07003596 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003597 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003598
3599 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003600 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003601 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3602 E1000_TXDCTL_FULL_TX_DESC_WB;
3603 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3604 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003605 ew32(TXDCTL(0), txdctl);
3606 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003607 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3608 E1000_TXDCTL_FULL_TX_DESC_WB;
3609 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3610 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003611 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003612
Bruce Allane921eb12012-11-28 09:28:37 +00003613 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003614 * By default, we should use snoop behavior.
3615 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003616 if (mac->type == e1000_ich8lan)
3617 snoop = PCIE_ICH8_SNOOP_ALL;
3618 else
3619 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
3620 e1000e_set_pcie_no_snoop(hw, snoop);
3621
3622 ctrl_ext = er32(CTRL_EXT);
3623 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3624 ew32(CTRL_EXT, ctrl_ext);
3625
Bruce Allane921eb12012-11-28 09:28:37 +00003626 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003627 * important that we do this after we have tried to establish link
3628 * because the symbol error count will increment wildly if there
3629 * is no link.
3630 */
3631 e1000_clear_hw_cntrs_ich8lan(hw);
3632
Bruce Allane561a702012-02-08 02:55:46 +00003633 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003634}
3635/**
3636 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3637 * @hw: pointer to the HW structure
3638 *
3639 * Sets/Clears required hardware bits necessary for correctly setting up the
3640 * hardware for transmit and receive.
3641 **/
3642static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3643{
3644 u32 reg;
3645
3646 /* Extended Device Control */
3647 reg = er32(CTRL_EXT);
3648 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003649 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3650 if (hw->mac.type >= e1000_pchlan)
3651 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003652 ew32(CTRL_EXT, reg);
3653
3654 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003655 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003657 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003658
3659 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003660 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003661 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003662 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003663
3664 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003665 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003666 if (hw->mac.type == e1000_ich8lan)
3667 reg |= (1 << 28) | (1 << 29);
3668 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003669 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003670
3671 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003672 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003673 if (er32(TCTL) & E1000_TCTL_MULR)
3674 reg &= ~(1 << 28);
3675 else
3676 reg |= (1 << 28);
3677 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003678 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003679
3680 /* Device Status */
3681 if (hw->mac.type == e1000_ich8lan) {
3682 reg = er32(STATUS);
3683 reg &= ~(1 << 31);
3684 ew32(STATUS, reg);
3685 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003686
Bruce Allane921eb12012-11-28 09:28:37 +00003687 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003688 * traffic, just disable the nfs filtering capability
3689 */
3690 reg = er32(RFCTL);
3691 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003692
Bruce Allane921eb12012-11-28 09:28:37 +00003693 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003694 * IPv6 headers can hang the Rx.
3695 */
3696 if (hw->mac.type == e1000_ich8lan)
3697 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003698 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00003699
3700 /* Enable ECC on Lynxpoint */
3701 if (hw->mac.type == e1000_pch_lpt) {
3702 reg = er32(PBECCSTS);
3703 reg |= E1000_PBECCSTS_ECC_ENABLE;
3704 ew32(PBECCSTS, reg);
3705
3706 reg = er32(CTRL);
3707 reg |= E1000_CTRL_MEHE;
3708 ew32(CTRL, reg);
3709 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710}
3711
3712/**
3713 * e1000_setup_link_ich8lan - Setup flow control and link settings
3714 * @hw: pointer to the HW structure
3715 *
3716 * Determines which flow control settings to use, then configures flow
3717 * control. Calls the appropriate media-specific link configuration
3718 * function. Assuming the adapter has a valid link partner, a valid link
3719 * should be established. Assumes the hardware has previously been reset
3720 * and the transmitter and receiver are not enabled.
3721 **/
3722static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3723{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003724 s32 ret_val;
3725
Bruce Allan44abd5c2012-02-22 09:02:37 +00003726 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003727 return 0;
3728
Bruce Allane921eb12012-11-28 09:28:37 +00003729 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003730 * the default flow control setting, so we explicitly
3731 * set it to full.
3732 */
Bruce Allan37289d92009-06-02 11:29:37 +00003733 if (hw->fc.requested_mode == e1000_fc_default) {
3734 /* Workaround h/w hang when Tx flow control enabled */
3735 if (hw->mac.type == e1000_pchlan)
3736 hw->fc.requested_mode = e1000_fc_rx_pause;
3737 else
3738 hw->fc.requested_mode = e1000_fc_full;
3739 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003740
Bruce Allane921eb12012-11-28 09:28:37 +00003741 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003742 * on the link partner's capabilities, we may or may not use this mode.
3743 */
3744 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003745
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003746 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003747 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003748
3749 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003750 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003751 if (ret_val)
3752 return ret_val;
3753
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003754 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003755 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003756 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003757 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003758 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003759 ew32(FCRTV_PCH, hw->fc.refresh_time);
3760
Bruce Allan482fed82011-01-06 14:29:49 +00003761 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3762 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003763 if (ret_val)
3764 return ret_val;
3765 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003766
3767 return e1000e_set_fc_watermarks(hw);
3768}
3769
3770/**
3771 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3772 * @hw: pointer to the HW structure
3773 *
3774 * Configures the kumeran interface to the PHY to wait the appropriate time
3775 * when polling the PHY, then call the generic setup_copper_link to finish
3776 * configuring the copper link.
3777 **/
3778static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3779{
3780 u32 ctrl;
3781 s32 ret_val;
3782 u16 reg_data;
3783
3784 ctrl = er32(CTRL);
3785 ctrl |= E1000_CTRL_SLU;
3786 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3787 ew32(CTRL, ctrl);
3788
Bruce Allane921eb12012-11-28 09:28:37 +00003789 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003790 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003791 * this fixes erroneous timeouts at 10Mbps.
3792 */
Bruce Allan07818952009-12-08 07:28:01 +00003793 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003794 if (ret_val)
3795 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003796 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3797 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003798 if (ret_val)
3799 return ret_val;
3800 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003801 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3802 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003803 if (ret_val)
3804 return ret_val;
3805
Bruce Allana4f58f52009-06-02 11:29:18 +00003806 switch (hw->phy.type) {
3807 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003808 ret_val = e1000e_copper_link_setup_igp(hw);
3809 if (ret_val)
3810 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003811 break;
3812 case e1000_phy_bm:
3813 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003814 ret_val = e1000e_copper_link_setup_m88(hw);
3815 if (ret_val)
3816 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003817 break;
3818 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003819 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003820 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +00003821 ret_val = e1000_copper_link_setup_82577(hw);
3822 if (ret_val)
3823 return ret_val;
3824 break;
3825 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003826 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003827 if (ret_val)
3828 return ret_val;
3829
3830 reg_data &= ~IFE_PMC_AUTO_MDIX;
3831
3832 switch (hw->phy.mdix) {
3833 case 1:
3834 reg_data &= ~IFE_PMC_FORCE_MDIX;
3835 break;
3836 case 2:
3837 reg_data |= IFE_PMC_FORCE_MDIX;
3838 break;
3839 case 0:
3840 default:
3841 reg_data |= IFE_PMC_AUTO_MDIX;
3842 break;
3843 }
Bruce Allan482fed82011-01-06 14:29:49 +00003844 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003845 if (ret_val)
3846 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003847 break;
3848 default:
3849 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003850 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003851
Auke Kokbc7f75f2007-09-17 12:30:59 -07003852 return e1000e_setup_copper_link(hw);
3853}
3854
3855/**
3856 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3857 * @hw: pointer to the HW structure
3858 * @speed: pointer to store current link speed
3859 * @duplex: pointer to store the current link duplex
3860 *
Bruce Allanad680762008-03-28 09:15:03 -07003861 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003862 * information and then calls the Kumeran lock loss workaround for links at
3863 * gigabit speeds.
3864 **/
3865static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3866 u16 *duplex)
3867{
3868 s32 ret_val;
3869
3870 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3871 if (ret_val)
3872 return ret_val;
3873
3874 if ((hw->mac.type == e1000_ich8lan) &&
3875 (hw->phy.type == e1000_phy_igp_3) &&
3876 (*speed == SPEED_1000)) {
3877 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3878 }
3879
3880 return ret_val;
3881}
3882
3883/**
3884 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3885 * @hw: pointer to the HW structure
3886 *
3887 * Work-around for 82566 Kumeran PCS lock loss:
3888 * On link status change (i.e. PCI reset, speed change) and link is up and
3889 * speed is gigabit-
3890 * 0) if workaround is optionally disabled do nothing
3891 * 1) wait 1ms for Kumeran link to come up
3892 * 2) check Kumeran Diagnostic register PCS lock loss bit
3893 * 3) if not set the link is locked (all is good), otherwise...
3894 * 4) reset the PHY
3895 * 5) repeat up to 10 times
3896 * Note: this is only called for IGP3 copper when speed is 1gb.
3897 **/
3898static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3899{
3900 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3901 u32 phy_ctrl;
3902 s32 ret_val;
3903 u16 i, data;
3904 bool link;
3905
3906 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3907 return 0;
3908
Bruce Allane921eb12012-11-28 09:28:37 +00003909 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003910 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003911 * stability
3912 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003913 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3914 if (!link)
3915 return 0;
3916
3917 for (i = 0; i < 10; i++) {
3918 /* read once to clear */
3919 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3920 if (ret_val)
3921 return ret_val;
3922 /* and again to get new status */
3923 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3924 if (ret_val)
3925 return ret_val;
3926
3927 /* check for PCS lock */
3928 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3929 return 0;
3930
3931 /* Issue PHY reset */
3932 e1000_phy_hw_reset(hw);
3933 mdelay(5);
3934 }
3935 /* Disable GigE link negotiation */
3936 phy_ctrl = er32(PHY_CTRL);
3937 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3938 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3939 ew32(PHY_CTRL, phy_ctrl);
3940
Bruce Allane921eb12012-11-28 09:28:37 +00003941 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07003942 * any PHY registers
3943 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003944 e1000e_gig_downshift_workaround_ich8lan(hw);
3945
3946 /* unable to acquire PCS lock */
3947 return -E1000_ERR_PHY;
3948}
3949
3950/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00003951 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003952 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003953 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003954 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003955 * If ICH8, set the current Kumeran workaround state (enabled - true
3956 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003957 **/
3958void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3959 bool state)
3960{
3961 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3962
3963 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003964 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003965 return;
3966 }
3967
3968 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3969}
3970
3971/**
3972 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3973 * @hw: pointer to the HW structure
3974 *
3975 * Workaround for 82566 power-down on D3 entry:
3976 * 1) disable gigabit link
3977 * 2) write VR power-down enable
3978 * 3) read it back
3979 * Continue if successful, else issue LCD reset and repeat
3980 **/
3981void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3982{
3983 u32 reg;
3984 u16 data;
3985 u8 retry = 0;
3986
3987 if (hw->phy.type != e1000_phy_igp_3)
3988 return;
3989
3990 /* Try the workaround twice (if needed) */
3991 do {
3992 /* Disable link */
3993 reg = er32(PHY_CTRL);
3994 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3995 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3996 ew32(PHY_CTRL, reg);
3997
Bruce Allane921eb12012-11-28 09:28:37 +00003998 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07003999 * accessing any PHY registers
4000 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004001 if (hw->mac.type == e1000_ich8lan)
4002 e1000e_gig_downshift_workaround_ich8lan(hw);
4003
4004 /* Write VR power-down enable */
4005 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4006 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4007 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4008
4009 /* Read it back and test */
4010 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4011 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4012 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4013 break;
4014
4015 /* Issue PHY reset and repeat at most one more time */
4016 reg = er32(CTRL);
4017 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4018 retry++;
4019 } while (retry);
4020}
4021
4022/**
4023 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4024 * @hw: pointer to the HW structure
4025 *
4026 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004027 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004028 * 1) Set Kumeran Near-end loopback
4029 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004030 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004031 **/
4032void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4033{
4034 s32 ret_val;
4035 u16 reg_data;
4036
Bruce Allan462d5992011-09-30 08:07:11 +00004037 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004038 return;
4039
4040 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4041 &reg_data);
4042 if (ret_val)
4043 return;
4044 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4045 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4046 reg_data);
4047 if (ret_val)
4048 return;
4049 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
4050 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4051 reg_data);
4052}
4053
4054/**
Bruce Allan99730e42011-05-13 07:19:48 +00004055 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004056 * @hw: pointer to the HW structure
4057 *
4058 * During S0 to Sx transition, it is possible the link remains at gig
4059 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004060 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4061 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4062 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4063 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004064 * Parts that support (and are linked to a partner which support) EEE in
4065 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4066 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004067 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004068void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004069{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004070 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004071 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004072 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004073
Bruce Allan17f085d2010-06-17 18:59:48 +00004074 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004075 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004076 if (hw->phy.type == e1000_phy_i217) {
4077 u16 phy_reg;
4078
4079 ret_val = hw->phy.ops.acquire(hw);
4080 if (ret_val)
4081 goto out;
4082
4083 if (!dev_spec->eee_disable) {
4084 u16 eee_advert;
4085
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004086 ret_val =
4087 e1000_read_emi_reg_locked(hw,
4088 I217_EEE_ADVERTISEMENT,
4089 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004090 if (ret_val)
4091 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004092
Bruce Allane921eb12012-11-28 09:28:37 +00004093 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004094 * EEE and 100Full is advertised on both ends of the
4095 * link.
4096 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004097 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004098 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004099 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004100 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4101 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4102 E1000_PHY_CTRL_NOND0A_LPLU);
4103 }
4104
Bruce Allane921eb12012-11-28 09:28:37 +00004105 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004106 * when the system is going into Sx and no manageability engine
4107 * is present, the driver must configure proxy to reset only on
4108 * power good. LPI (Low Power Idle) state must also reset only
4109 * on power good, as well as the MTA (Multicast table array).
4110 * The SMBus release must also be disabled on LCD reset.
4111 */
4112 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
4113
4114 /* Enable proxy to reset only on power good. */
4115 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4116 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4117 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4118
Bruce Allane921eb12012-11-28 09:28:37 +00004119 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004120 * power good.
4121 */
4122 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004123 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004124 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4125
4126 /* Disable the SMB release on LCD reset. */
4127 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004128 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004129 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4130 }
4131
Bruce Allane921eb12012-11-28 09:28:37 +00004132 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004133 * Support
4134 */
4135 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004136 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004137 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4138
4139release:
4140 hw->phy.ops.release(hw);
4141 }
4142out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004143 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004144
Bruce Allan462d5992011-09-30 08:07:11 +00004145 if (hw->mac.type == e1000_ich8lan)
4146 e1000e_gig_downshift_workaround_ich8lan(hw);
4147
Bruce Allan8395ae82010-09-22 17:15:08 +00004148 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004149 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004150
4151 /* Reset PHY to activate OEM bits on 82577/8 */
4152 if (hw->mac.type == e1000_pchlan)
4153 e1000e_phy_hw_reset_generic(hw);
4154
Bruce Allan8395ae82010-09-22 17:15:08 +00004155 ret_val = hw->phy.ops.acquire(hw);
4156 if (ret_val)
4157 return;
4158 e1000_write_smbus_addr(hw);
4159 hw->phy.ops.release(hw);
4160 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004161}
4162
4163/**
Bruce Allan99730e42011-05-13 07:19:48 +00004164 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4165 * @hw: pointer to the HW structure
4166 *
4167 * During Sx to S0 transitions on non-managed devices or managed devices
4168 * on which PHY resets are not blocked, if the PHY registers cannot be
4169 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4170 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004171 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004172 **/
4173void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4174{
Bruce Allan90b82982011-12-16 00:46:33 +00004175 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004176
Bruce Allancb17aab2012-04-13 03:16:22 +00004177 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004178 return;
4179
Bruce Allancb17aab2012-04-13 03:16:22 +00004180 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004181 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004182 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004183 return;
4184 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004185
Bruce Allane921eb12012-11-28 09:28:37 +00004186 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004187 * is transitioning from Sx and no manageability engine is present
4188 * configure SMBus to restore on reset, disable proxy, and enable
4189 * the reset on MTA (Multicast table array).
4190 */
4191 if (hw->phy.type == e1000_phy_i217) {
4192 u16 phy_reg;
4193
4194 ret_val = hw->phy.ops.acquire(hw);
4195 if (ret_val) {
4196 e_dbg("Failed to setup iRST\n");
4197 return;
4198 }
4199
4200 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004201 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004202 * is present
4203 */
4204 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4205 if (ret_val)
4206 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004207 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004208 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4209
4210 /* Disable Proxy */
4211 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4212 }
4213 /* Enable reset on MTA */
4214 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4215 if (ret_val)
4216 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004217 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004218 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4219release:
4220 if (ret_val)
4221 e_dbg("Error %d in resume workarounds\n", ret_val);
4222 hw->phy.ops.release(hw);
4223 }
Bruce Allan99730e42011-05-13 07:19:48 +00004224}
4225
4226/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004227 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4228 * @hw: pointer to the HW structure
4229 *
4230 * Return the LED back to the default configuration.
4231 **/
4232static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4233{
4234 if (hw->phy.type == e1000_phy_ife)
4235 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4236
4237 ew32(LEDCTL, hw->mac.ledctl_default);
4238 return 0;
4239}
4240
4241/**
Auke Kok489815c2008-02-21 15:11:07 -08004242 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004243 * @hw: pointer to the HW structure
4244 *
Auke Kok489815c2008-02-21 15:11:07 -08004245 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 **/
4247static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4248{
4249 if (hw->phy.type == e1000_phy_ife)
4250 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4251 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4252
4253 ew32(LEDCTL, hw->mac.ledctl_mode2);
4254 return 0;
4255}
4256
4257/**
Auke Kok489815c2008-02-21 15:11:07 -08004258 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004259 * @hw: pointer to the HW structure
4260 *
Auke Kok489815c2008-02-21 15:11:07 -08004261 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262 **/
4263static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4264{
4265 if (hw->phy.type == e1000_phy_ife)
4266 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004267 (IFE_PSCL_PROBE_MODE |
4268 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004269
4270 ew32(LEDCTL, hw->mac.ledctl_mode1);
4271 return 0;
4272}
4273
4274/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004275 * e1000_setup_led_pchlan - Configures SW controllable LED
4276 * @hw: pointer to the HW structure
4277 *
4278 * This prepares the SW controllable LED for use.
4279 **/
4280static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4281{
Bruce Allan482fed82011-01-06 14:29:49 +00004282 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004283}
4284
4285/**
4286 * e1000_cleanup_led_pchlan - Restore the default LED operation
4287 * @hw: pointer to the HW structure
4288 *
4289 * Return the LED back to the default configuration.
4290 **/
4291static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4292{
Bruce Allan482fed82011-01-06 14:29:49 +00004293 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004294}
4295
4296/**
4297 * e1000_led_on_pchlan - Turn LEDs on
4298 * @hw: pointer to the HW structure
4299 *
4300 * Turn on the LEDs.
4301 **/
4302static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4303{
4304 u16 data = (u16)hw->mac.ledctl_mode2;
4305 u32 i, led;
4306
Bruce Allane921eb12012-11-28 09:28:37 +00004307 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004308 * for each LED that's mode is "link_up" in ledctl_mode2.
4309 */
4310 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4311 for (i = 0; i < 3; i++) {
4312 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4313 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4314 E1000_LEDCTL_MODE_LINK_UP)
4315 continue;
4316 if (led & E1000_PHY_LED0_IVRT)
4317 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4318 else
4319 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4320 }
4321 }
4322
Bruce Allan482fed82011-01-06 14:29:49 +00004323 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004324}
4325
4326/**
4327 * e1000_led_off_pchlan - Turn LEDs off
4328 * @hw: pointer to the HW structure
4329 *
4330 * Turn off the LEDs.
4331 **/
4332static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4333{
4334 u16 data = (u16)hw->mac.ledctl_mode1;
4335 u32 i, led;
4336
Bruce Allane921eb12012-11-28 09:28:37 +00004337 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004338 * for each LED that's mode is "link_up" in ledctl_mode1.
4339 */
4340 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4341 for (i = 0; i < 3; i++) {
4342 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4343 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4344 E1000_LEDCTL_MODE_LINK_UP)
4345 continue;
4346 if (led & E1000_PHY_LED0_IVRT)
4347 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4348 else
4349 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4350 }
4351 }
4352
Bruce Allan482fed82011-01-06 14:29:49 +00004353 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004354}
4355
4356/**
Bruce Allane98cac42010-05-10 15:02:32 +00004357 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004358 * @hw: pointer to the HW structure
4359 *
Bruce Allane98cac42010-05-10 15:02:32 +00004360 * Read appropriate register for the config done bit for completion status
4361 * and configure the PHY through s/w for EEPROM-less parts.
4362 *
4363 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4364 * config done bit, so only an error is logged and continues. If we were
4365 * to return with error, EEPROM-less silicon would not be able to be reset
4366 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004367 **/
4368static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4369{
Bruce Allane98cac42010-05-10 15:02:32 +00004370 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004371 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004372 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004373
Bruce Allanf4187b52008-08-26 18:36:50 -07004374 e1000e_get_cfg_done(hw);
4375
Bruce Allane98cac42010-05-10 15:02:32 +00004376 /* Wait for indication from h/w that it has completed basic config */
4377 if (hw->mac.type >= e1000_ich10lan) {
4378 e1000_lan_init_done_ich8lan(hw);
4379 } else {
4380 ret_val = e1000e_get_auto_rd_done(hw);
4381 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004382 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004383 * return with an error. This can happen in situations
4384 * where there is no eeprom and prevents getting link.
4385 */
4386 e_dbg("Auto Read Done did not complete\n");
4387 ret_val = 0;
4388 }
4389 }
4390
4391 /* Clear PHY Reset Asserted bit */
4392 status = er32(STATUS);
4393 if (status & E1000_STATUS_PHYRA)
4394 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4395 else
4396 e_dbg("PHY Reset Asserted not set - needs delay\n");
4397
Bruce Allanf4187b52008-08-26 18:36:50 -07004398 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004399 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004400 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004401 (hw->phy.type == e1000_phy_igp_3)) {
4402 e1000e_phy_init_script_igp3(hw);
4403 }
4404 } else {
4405 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4406 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004407 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004408 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004409 }
4410 }
4411
Bruce Allane98cac42010-05-10 15:02:32 +00004412 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004413}
4414
4415/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004416 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4417 * @hw: pointer to the HW structure
4418 *
4419 * In the case of a PHY power down to save power, or to turn off link during a
4420 * driver unload, or wake on lan is not enabled, remove the link.
4421 **/
4422static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4423{
4424 /* If the management interface is not enabled, then power down */
4425 if (!(hw->mac.ops.check_mng_mode(hw) ||
4426 hw->phy.ops.check_reset_block(hw)))
4427 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004428}
4429
4430/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004431 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4432 * @hw: pointer to the HW structure
4433 *
4434 * Clears hardware counters specific to the silicon family and calls
4435 * clear_hw_cntrs_generic to clear all general purpose counters.
4436 **/
4437static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4438{
Bruce Allana4f58f52009-06-02 11:29:18 +00004439 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004440 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004441
4442 e1000e_clear_hw_cntrs_base(hw);
4443
Bruce Allan99673d92009-11-20 23:27:21 +00004444 er32(ALGNERRC);
4445 er32(RXERRC);
4446 er32(TNCRS);
4447 er32(CEXTERR);
4448 er32(TSCTC);
4449 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004450
Bruce Allan99673d92009-11-20 23:27:21 +00004451 er32(MGTPRC);
4452 er32(MGTPDC);
4453 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004454
Bruce Allan99673d92009-11-20 23:27:21 +00004455 er32(IAC);
4456 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004457
Bruce Allana4f58f52009-06-02 11:29:18 +00004458 /* Clear PHY statistics registers */
4459 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004460 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004461 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004462 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004463 ret_val = hw->phy.ops.acquire(hw);
4464 if (ret_val)
4465 return;
4466 ret_val = hw->phy.ops.set_page(hw,
4467 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4468 if (ret_val)
4469 goto release;
4470 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4471 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4472 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4473 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4474 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4475 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4476 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4477 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4478 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4479 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4480 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4481 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4482 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4483 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4484release:
4485 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004486 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004487}
4488
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004489static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004490 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004491 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004492 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004493 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4494 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004495 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004496 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004497 /* led_on dependent on mac type */
4498 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004499 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004500 .reset_hw = e1000_reset_hw_ich8lan,
4501 .init_hw = e1000_init_hw_ich8lan,
4502 .setup_link = e1000_setup_link_ich8lan,
4503 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004504 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004505 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004506 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004507};
4508
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004509static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004510 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004511 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004512 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004513 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004514 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004515 .read_reg = e1000e_read_phy_reg_igp,
4516 .release = e1000_release_swflag_ich8lan,
4517 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004518 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4519 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004520 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004521};
4522
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004523static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004524 .acquire = e1000_acquire_nvm_ich8lan,
4525 .read = e1000_read_nvm_ich8lan,
4526 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004527 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004528 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004529 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004530 .validate = e1000_validate_nvm_checksum_ich8lan,
4531 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004532};
4533
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004534const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004535 .mac = e1000_ich8lan,
4536 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004537 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004538 | FLAG_HAS_CTRLEXT_ON_LOAD
4539 | FLAG_HAS_AMT
4540 | FLAG_HAS_FLASH
4541 | FLAG_APME_IN_WUC,
4542 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004543 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004544 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004545 .mac_ops = &ich8_mac_ops,
4546 .phy_ops = &ich8_phy_ops,
4547 .nvm_ops = &ich8_nvm_ops,
4548};
4549
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004550const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004551 .mac = e1000_ich9lan,
4552 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004553 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004554 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004555 | FLAG_HAS_CTRLEXT_ON_LOAD
4556 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557 | FLAG_HAS_FLASH
4558 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004559 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004560 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004561 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004562 .mac_ops = &ich8_mac_ops,
4563 .phy_ops = &ich8_phy_ops,
4564 .nvm_ops = &ich8_nvm_ops,
4565};
4566
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004567const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004568 .mac = e1000_ich10lan,
4569 .flags = FLAG_HAS_JUMBO_FRAMES
4570 | FLAG_IS_ICH
4571 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004572 | FLAG_HAS_CTRLEXT_ON_LOAD
4573 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004574 | FLAG_HAS_FLASH
4575 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004576 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004577 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004578 .get_variants = e1000_get_variants_ich8lan,
4579 .mac_ops = &ich8_mac_ops,
4580 .phy_ops = &ich8_phy_ops,
4581 .nvm_ops = &ich8_nvm_ops,
4582};
Bruce Allana4f58f52009-06-02 11:29:18 +00004583
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004584const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004585 .mac = e1000_pchlan,
4586 .flags = FLAG_IS_ICH
4587 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004588 | FLAG_HAS_CTRLEXT_ON_LOAD
4589 | FLAG_HAS_AMT
4590 | FLAG_HAS_FLASH
4591 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004592 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004593 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004594 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004595 .pba = 26,
4596 .max_hw_frame_size = 4096,
4597 .get_variants = e1000_get_variants_ich8lan,
4598 .mac_ops = &ich8_mac_ops,
4599 .phy_ops = &ich8_phy_ops,
4600 .nvm_ops = &ich8_nvm_ops,
4601};
Bruce Alland3738bb2010-06-16 13:27:28 +00004602
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004603const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004604 .mac = e1000_pch2lan,
4605 .flags = FLAG_IS_ICH
4606 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004607 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00004608 | FLAG_HAS_CTRLEXT_ON_LOAD
4609 | FLAG_HAS_AMT
4610 | FLAG_HAS_FLASH
4611 | FLAG_HAS_JUMBO_FRAMES
4612 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004613 .flags2 = FLAG2_HAS_PHY_STATS
4614 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004615 .pba = 26,
Bruce Alland3738bb2010-06-16 13:27:28 +00004616 .max_hw_frame_size = DEFAULT_JUMBO,
4617 .get_variants = e1000_get_variants_ich8lan,
4618 .mac_ops = &ich8_mac_ops,
4619 .phy_ops = &ich8_phy_ops,
4620 .nvm_ops = &ich8_nvm_ops,
4621};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004622
4623const struct e1000_info e1000_pch_lpt_info = {
4624 .mac = e1000_pch_lpt,
4625 .flags = FLAG_IS_ICH
4626 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004627 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00004628 | FLAG_HAS_CTRLEXT_ON_LOAD
4629 | FLAG_HAS_AMT
4630 | FLAG_HAS_FLASH
4631 | FLAG_HAS_JUMBO_FRAMES
4632 | FLAG_APME_IN_WUC,
4633 .flags2 = FLAG2_HAS_PHY_STATS
4634 | FLAG2_HAS_EEE,
4635 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00004636 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004637 .get_variants = e1000_get_variants_ich8lan,
4638 .mac_ops = &ich8_mac_ops,
4639 .phy_ops = &ich8_phy_ops,
4640 .nvm_ops = &ich8_nvm_ops,
4641};