blob: 059f1b0112f4b0af995952ce94ffaeba5d37c538 [file] [log] [blame]
David Ertmane78b80b2014-02-04 01:56:06 +00001/* Intel PRO/1000 Linux driver
2 * Copyright(c) 1999 - 2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * Linux NICS <linux.nics@intel.com>
18 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
19 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
20 */
Auke Kokbc7f75f2007-09-17 12:30:59 -070021
Bruce Allane921eb12012-11-28 09:28:37 +000022/* 82562G 10/100 Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070023 * 82562G-2 10/100 Network Connection
24 * 82562GT 10/100 Network Connection
25 * 82562GT-2 10/100 Network Connection
26 * 82562V 10/100 Network Connection
27 * 82562V-2 10/100 Network Connection
28 * 82566DC-2 Gigabit Network Connection
29 * 82566DC Gigabit Network Connection
30 * 82566DM-2 Gigabit Network Connection
31 * 82566DM Gigabit Network Connection
32 * 82566MC Gigabit Network Connection
33 * 82566MM Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070034 * 82567LM Gigabit Network Connection
35 * 82567LF Gigabit Network Connection
Bruce Allan16059272008-11-21 16:51:06 -080036 * 82567V Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070037 * 82567LM-2 Gigabit Network Connection
38 * 82567LF-2 Gigabit Network Connection
39 * 82567V-2 Gigabit Network Connection
Bruce Allanf4187b52008-08-26 18:36:50 -070040 * 82567LF-3 Gigabit Network Connection
41 * 82567LM-3 Gigabit Network Connection
Bruce Allan2f15f9d2008-08-26 18:36:36 -070042 * 82567LM-4 Gigabit Network Connection
Bruce Allana4f58f52009-06-02 11:29:18 +000043 * 82577LM Gigabit Network Connection
44 * 82577LC Gigabit Network Connection
45 * 82578DM Gigabit Network Connection
46 * 82578DC Gigabit Network Connection
Bruce Alland3738bb2010-06-16 13:27:28 +000047 * 82579LM Gigabit Network Connection
48 * 82579V Gigabit Network Connection
David Ertman3b70d4f2014-02-05 01:09:54 +000049 * Ethernet Connection I217-LM
50 * Ethernet Connection I217-V
51 * Ethernet Connection I218-V
52 * Ethernet Connection I218-LM
53 * Ethernet Connection (2) I218-LM
54 * Ethernet Connection (2) I218-V
55 * Ethernet Connection (3) I218-LM
56 * Ethernet Connection (3) I218-V
Auke Kokbc7f75f2007-09-17 12:30:59 -070057 */
58
Auke Kokbc7f75f2007-09-17 12:30:59 -070059#include "e1000.h"
60
Auke Kokbc7f75f2007-09-17 12:30:59 -070061/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
62/* Offset 04h HSFSTS */
63union ich8_hws_flash_status {
64 struct ich8_hsfsts {
Bruce Allan362e20c2013-02-20 04:05:45 +000065 u16 flcdone:1; /* bit 0 Flash Cycle Done */
66 u16 flcerr:1; /* bit 1 Flash Cycle Error */
67 u16 dael:1; /* bit 2 Direct Access error Log */
68 u16 berasesz:2; /* bit 4:3 Sector Erase Size */
69 u16 flcinprog:1; /* bit 5 flash cycle in Progress */
70 u16 reserved1:2; /* bit 13:6 Reserved */
71 u16 reserved2:6; /* bit 13:6 Reserved */
72 u16 fldesvalid:1; /* bit 14 Flash Descriptor Valid */
73 u16 flockdn:1; /* bit 15 Flash Config Lock-Down */
Auke Kokbc7f75f2007-09-17 12:30:59 -070074 } hsf_status;
75 u16 regval;
76};
77
78/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
79/* Offset 06h FLCTL */
80union ich8_hws_flash_ctrl {
81 struct ich8_hsflctl {
Bruce Allan362e20c2013-02-20 04:05:45 +000082 u16 flcgo:1; /* 0 Flash Cycle Go */
83 u16 flcycle:2; /* 2:1 Flash Cycle */
84 u16 reserved:5; /* 7:3 Reserved */
85 u16 fldbcount:2; /* 9:8 Flash Data Byte Count */
86 u16 flockdn:6; /* 15:10 Reserved */
Auke Kokbc7f75f2007-09-17 12:30:59 -070087 } hsf_ctrl;
88 u16 regval;
89};
90
91/* ICH Flash Region Access Permissions */
92union ich8_hws_flash_regacc {
93 struct ich8_flracc {
Bruce Allan362e20c2013-02-20 04:05:45 +000094 u32 grra:8; /* 0:7 GbE region Read Access */
95 u32 grwa:8; /* 8:15 GbE region Write Access */
96 u32 gmrag:8; /* 23:16 GbE Master Read Access Grant */
97 u32 gmwag:8; /* 31:24 GbE Master Write Access Grant */
Auke Kokbc7f75f2007-09-17 12:30:59 -070098 } hsf_flregacc;
99 u16 regval;
100};
101
Bruce Allan4a770352008-10-01 17:18:35 -0700102/* ICH Flash Protected Region */
103union ich8_flash_protected_range {
104 struct ich8_pr {
Bruce Allane80bd1d2013-05-01 01:19:46 +0000105 u32 base:13; /* 0:12 Protected Range Base */
106 u32 reserved1:2; /* 13:14 Reserved */
107 u32 rpe:1; /* 15 Read Protection Enable */
108 u32 limit:13; /* 16:28 Protected Range Limit */
109 u32 reserved2:2; /* 29:30 Reserved */
110 u32 wpe:1; /* 31 Write Protection Enable */
Bruce Allan4a770352008-10-01 17:18:35 -0700111 } range;
112 u32 regval;
113};
114
Auke Kokbc7f75f2007-09-17 12:30:59 -0700115static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
116static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700117static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
118static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
119 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700120static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
121 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700122static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
123 u16 *data);
124static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
125 u8 size, u16 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700126static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000127static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
128static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
129static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
130static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
131static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
132static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
133static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
134static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000135static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000136static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000137static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1f96012d2013-01-05 03:06:54 +0000138static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000139static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000140static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
141static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan69e1e012012-04-14 03:28:50 +0000142static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000143static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000144static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000145static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
David Ertman74f350e2014-02-22 03:15:17 +0000146static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force);
Bruce Allanea8179a2013-03-06 09:02:47 +0000147static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
David Ertman74f350e2014-02-22 03:15:17 +0000148static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700149
150static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
151{
152 return readw(hw->flash_address + reg);
153}
154
155static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
156{
157 return readl(hw->flash_address + reg);
158}
159
160static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
161{
162 writew(val, hw->flash_address + reg);
163}
164
165static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
166{
167 writel(val, hw->flash_address + reg);
168}
169
170#define er16flash(reg) __er16flash(hw, (reg))
171#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000172#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
173#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700174
Bruce Allancb17aab2012-04-13 03:16:22 +0000175/**
176 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
177 * @hw: pointer to the HW structure
178 *
179 * Test access to the PHY registers by reading the PHY ID registers. If
180 * the PHY ID is already known (e.g. resume path) compare it with known ID,
181 * otherwise assume the read PHY ID is correct if it is valid.
182 *
183 * Assumes the sw/fw/hw semaphore is already acquired.
184 **/
185static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000186{
Bruce Allana52359b2012-07-14 04:23:58 +0000187 u16 phy_reg = 0;
188 u32 phy_id = 0;
189 s32 ret_val;
190 u16 retry_count;
Bruce Allan16b095a2013-06-29 07:42:39 +0000191 u32 mac_reg = 0;
Bruce Allan99730e42011-05-13 07:19:48 +0000192
Bruce Allana52359b2012-07-14 04:23:58 +0000193 for (retry_count = 0; retry_count < 2; retry_count++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000194 ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000195 if (ret_val || (phy_reg == 0xFFFF))
196 continue;
197 phy_id = (u32)(phy_reg << 16);
198
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000199 ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000200 if (ret_val || (phy_reg == 0xFFFF)) {
201 phy_id = 0;
202 continue;
203 }
204 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
205 break;
206 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000207
Bruce Allancb17aab2012-04-13 03:16:22 +0000208 if (hw->phy.id) {
209 if (hw->phy.id == phy_id)
Bruce Allan16b095a2013-06-29 07:42:39 +0000210 goto out;
Bruce Allana52359b2012-07-14 04:23:58 +0000211 } else if (phy_id) {
212 hw->phy.id = phy_id;
213 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allan16b095a2013-06-29 07:42:39 +0000214 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000215 }
216
Bruce Allane921eb12012-11-28 09:28:37 +0000217 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000218 * set slow mode and try to get the PHY id again.
219 */
220 hw->phy.ops.release(hw);
221 ret_val = e1000_set_mdio_slow_mode_hv(hw);
222 if (!ret_val)
223 ret_val = e1000e_get_phy_id(hw);
224 hw->phy.ops.acquire(hw);
225
Bruce Allan16b095a2013-06-29 07:42:39 +0000226 if (ret_val)
227 return false;
228out:
229 if (hw->mac.type == e1000_pch_lpt) {
230 /* Unforce SMBus mode in PHY */
231 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
232 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
233 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
234
235 /* Unforce SMBus mode in MAC */
236 mac_reg = er32(CTRL_EXT);
237 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
238 ew32(CTRL_EXT, mac_reg);
239 }
240
241 return true;
Bruce Allancb17aab2012-04-13 03:16:22 +0000242}
243
244/**
David Ertman74f350e2014-02-22 03:15:17 +0000245 * e1000_toggle_lanphypc_pch_lpt - toggle the LANPHYPC pin value
246 * @hw: pointer to the HW structure
247 *
248 * Toggling the LANPHYPC pin value fully power-cycles the PHY and is
249 * used to reset the PHY to a quiescent state when necessary.
250 **/
251static void e1000_toggle_lanphypc_pch_lpt(struct e1000_hw *hw)
252{
253 u32 mac_reg;
254
255 /* Set Phy Config Counter to 50msec */
256 mac_reg = er32(FEXTNVM3);
257 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
258 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
259 ew32(FEXTNVM3, mac_reg);
260
261 /* Toggle LANPHYPC Value bit */
262 mac_reg = er32(CTRL);
263 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
264 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
265 ew32(CTRL, mac_reg);
266 e1e_flush();
267 usleep_range(10, 20);
268 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
269 ew32(CTRL, mac_reg);
270 e1e_flush();
271
272 if (hw->mac.type < e1000_pch_lpt) {
273 msleep(50);
274 } else {
275 u16 count = 20;
276
277 do {
278 usleep_range(5000, 10000);
279 } while (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LPCD) && count--);
280
281 msleep(30);
282 }
283}
284
285/**
Bruce Allancb17aab2012-04-13 03:16:22 +0000286 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
287 * @hw: pointer to the HW structure
288 *
289 * Workarounds/flow necessary for PHY initialization during driver load
290 * and resume paths.
291 **/
292static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
293{
David Ertmanf7235ef2014-01-23 06:29:13 +0000294 struct e1000_adapter *adapter = hw->adapter;
Bruce Allancb17aab2012-04-13 03:16:22 +0000295 u32 mac_reg, fwsm = er32(FWSM);
296 s32 ret_val;
297
Bruce Allan6e928b72012-12-12 04:45:51 +0000298 /* Gate automatic PHY configuration by hardware on managed and
299 * non-managed 82579 and newer adapters.
300 */
301 e1000_gate_hw_phy_config_ich8lan(hw, true);
302
David Ertman74f350e2014-02-22 03:15:17 +0000303 /* It is not possible to be certain of the current state of ULP
304 * so forcibly disable it.
305 */
306 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_unknown;
307 e1000_disable_ulp_lpt_lp(hw, true);
308
Bruce Allancb17aab2012-04-13 03:16:22 +0000309 ret_val = hw->phy.ops.acquire(hw);
310 if (ret_val) {
311 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000312 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000313 }
314
Bruce Allane921eb12012-11-28 09:28:37 +0000315 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000316 * inaccessible and resetting the PHY is not blocked, toggle the
317 * LANPHYPC Value bit to force the interconnect to PCIe mode.
318 */
319 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000320 case e1000_pch_lpt:
321 if (e1000_phy_is_accessible_pchlan(hw))
322 break;
323
Bruce Allane921eb12012-11-28 09:28:37 +0000324 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000325 * forcing MAC to SMBus mode first.
326 */
327 mac_reg = er32(CTRL_EXT);
328 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
329 ew32(CTRL_EXT, mac_reg);
330
Bruce Allan16b095a2013-06-29 07:42:39 +0000331 /* Wait 50 milliseconds for MAC to finish any retries
332 * that it might be trying to perform from previous
333 * attempts to acknowledge any phy read requests.
334 */
335 msleep(50);
336
Bruce Allan2fbe4522012-04-19 03:21:47 +0000337 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000338 case e1000_pch2lan:
Bruce Allan16b095a2013-06-29 07:42:39 +0000339 if (e1000_phy_is_accessible_pchlan(hw))
Bruce Allancb17aab2012-04-13 03:16:22 +0000340 break;
341
342 /* fall-through */
343 case e1000_pchlan:
344 if ((hw->mac.type == e1000_pchlan) &&
345 (fwsm & E1000_ICH_FWSM_FW_VALID))
346 break;
347
348 if (hw->phy.ops.check_reset_block(hw)) {
349 e_dbg("Required LANPHYPC toggle blocked by ME\n");
Bruce Allan16b095a2013-06-29 07:42:39 +0000350 ret_val = -E1000_ERR_PHY;
Bruce Allancb17aab2012-04-13 03:16:22 +0000351 break;
352 }
353
Bruce Allancb17aab2012-04-13 03:16:22 +0000354 /* Toggle LANPHYPC Value bit */
David Ertman74f350e2014-02-22 03:15:17 +0000355 e1000_toggle_lanphypc_pch_lpt(hw);
356 if (hw->mac.type >= e1000_pch_lpt) {
Bruce Allan16b095a2013-06-29 07:42:39 +0000357 if (e1000_phy_is_accessible_pchlan(hw))
358 break;
359
360 /* Toggling LANPHYPC brings the PHY out of SMBus mode
361 * so ensure that the MAC is also out of SMBus mode
362 */
363 mac_reg = er32(CTRL_EXT);
364 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
365 ew32(CTRL_EXT, mac_reg);
366
367 if (e1000_phy_is_accessible_pchlan(hw))
368 break;
369
370 ret_val = -E1000_ERR_PHY;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000371 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000372 break;
373 default:
374 break;
375 }
376
377 hw->phy.ops.release(hw);
Bruce Allan16b095a2013-06-29 07:42:39 +0000378 if (!ret_val) {
David Ertmanf7235ef2014-01-23 06:29:13 +0000379
380 /* Check to see if able to reset PHY. Print error if not */
381 if (hw->phy.ops.check_reset_block(hw)) {
382 e_err("Reset blocked by ME\n");
383 goto out;
384 }
385
Bruce Allan16b095a2013-06-29 07:42:39 +0000386 /* Reset the PHY before any access to it. Doing so, ensures
387 * that the PHY is in a known good state before we read/write
388 * PHY registers. The generic reset is sufficient here,
389 * because we haven't determined the PHY type yet.
390 */
391 ret_val = e1000e_phy_hw_reset_generic(hw);
David Ertmanf7235ef2014-01-23 06:29:13 +0000392 if (ret_val)
393 goto out;
394
395 /* On a successful reset, possibly need to wait for the PHY
396 * to quiesce to an accessible state before returning control
397 * to the calling function. If the PHY does not quiesce, then
398 * return E1000E_BLK_PHY_RESET, as this is the condition that
399 * the PHY is in.
400 */
401 ret_val = hw->phy.ops.check_reset_block(hw);
402 if (ret_val)
403 e_err("ME blocked access to PHY after reset\n");
Bruce Allan16b095a2013-06-29 07:42:39 +0000404 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000405
Bruce Allan6e928b72012-12-12 04:45:51 +0000406out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000407 /* Ungate automatic PHY configuration on non-managed 82579 */
408 if ((hw->mac.type == e1000_pch2lan) &&
409 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
410 usleep_range(10000, 20000);
411 e1000_gate_hw_phy_config_ich8lan(hw, false);
412 }
413
414 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000415}
416
Auke Kokbc7f75f2007-09-17 12:30:59 -0700417/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000418 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
419 * @hw: pointer to the HW structure
420 *
421 * Initialize family-specific PHY parameters and function pointers.
422 **/
423static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
424{
425 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan70806a72013-01-05 05:08:37 +0000426 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000427
Bruce Allane80bd1d2013-05-01 01:19:46 +0000428 phy->addr = 1;
429 phy->reset_delay_us = 100;
Bruce Allana4f58f52009-06-02 11:29:18 +0000430
Bruce Allane80bd1d2013-05-01 01:19:46 +0000431 phy->ops.set_page = e1000_set_page_igp;
432 phy->ops.read_reg = e1000_read_phy_reg_hv;
433 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
434 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
435 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
436 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
437 phy->ops.write_reg = e1000_write_phy_reg_hv;
438 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
439 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
440 phy->ops.power_up = e1000_power_up_phy_copper;
441 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
442 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allana4f58f52009-06-02 11:29:18 +0000443
444 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000445
446 ret_val = e1000_init_phy_workarounds_pchlan(hw);
447 if (ret_val)
448 return ret_val;
449
450 if (phy->id == e1000_phy_unknown)
451 switch (hw->mac.type) {
452 default:
453 ret_val = e1000e_get_phy_id(hw);
454 if (ret_val)
455 return ret_val;
456 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
457 break;
458 /* fall-through */
459 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000460 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000461 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000462 * set slow mode and try to get the PHY id again.
463 */
464 ret_val = e1000_set_mdio_slow_mode_hv(hw);
465 if (ret_val)
466 return ret_val;
467 ret_val = e1000e_get_phy_id(hw);
468 if (ret_val)
469 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000470 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000471 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000472 phy->type = e1000e_get_phy_type_from_id(phy->id);
473
Bruce Allan0be84012009-12-02 17:03:18 +0000474 switch (phy->type) {
475 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000476 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000477 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000478 phy->ops.check_polarity = e1000_check_polarity_82577;
479 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000480 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000481 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000482 phy->ops.get_info = e1000_get_phy_info_82577;
483 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000484 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000485 case e1000_phy_82578:
486 phy->ops.check_polarity = e1000_check_polarity_m88;
487 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
488 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
489 phy->ops.get_info = e1000e_get_phy_info_m88;
490 break;
491 default:
492 ret_val = -E1000_ERR_PHY;
493 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000494 }
495
496 return ret_val;
497}
498
499/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700500 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
501 * @hw: pointer to the HW structure
502 *
503 * Initialize family-specific PHY parameters and function pointers.
504 **/
505static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
506{
507 struct e1000_phy_info *phy = &hw->phy;
508 s32 ret_val;
509 u16 i = 0;
510
Bruce Allane80bd1d2013-05-01 01:19:46 +0000511 phy->addr = 1;
512 phy->reset_delay_us = 100;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700513
Bruce Allane80bd1d2013-05-01 01:19:46 +0000514 phy->ops.power_up = e1000_power_up_phy_copper;
515 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allan17f208d2009-12-01 15:47:22 +0000516
Bruce Allane921eb12012-11-28 09:28:37 +0000517 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700518 * we'll set BM func pointers and try again
519 */
520 ret_val = e1000e_determine_phy_address(hw);
521 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000522 phy->ops.write_reg = e1000e_write_phy_reg_bm;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000523 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700524 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000525 if (ret_val) {
526 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700527 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000528 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700529 }
530
Auke Kokbc7f75f2007-09-17 12:30:59 -0700531 phy->id = 0;
532 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
533 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000534 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700535 ret_val = e1000e_get_phy_id(hw);
536 if (ret_val)
537 return ret_val;
538 }
539
540 /* Verify phy id */
541 switch (phy->id) {
542 case IGP03E1000_E_PHY_ID:
543 phy->type = e1000_phy_igp_3;
544 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000545 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
546 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000547 phy->ops.get_info = e1000e_get_phy_info_igp;
548 phy->ops.check_polarity = e1000_check_polarity_igp;
549 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700550 break;
551 case IFE_E_PHY_ID:
552 case IFE_PLUS_E_PHY_ID:
553 case IFE_C_E_PHY_ID:
554 phy->type = e1000_phy_ife;
555 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000556 phy->ops.get_info = e1000_get_phy_info_ife;
557 phy->ops.check_polarity = e1000_check_polarity_ife;
558 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700559 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700560 case BME1000_E_PHY_ID:
561 phy->type = e1000_phy_bm;
562 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000563 phy->ops.read_reg = e1000e_read_phy_reg_bm;
564 phy->ops.write_reg = e1000e_write_phy_reg_bm;
565 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000566 phy->ops.get_info = e1000e_get_phy_info_m88;
567 phy->ops.check_polarity = e1000_check_polarity_m88;
568 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700569 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700570 default:
571 return -E1000_ERR_PHY;
572 break;
573 }
574
575 return 0;
576}
577
578/**
579 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
580 * @hw: pointer to the HW structure
581 *
582 * Initialize family-specific NVM parameters and function
583 * pointers.
584 **/
585static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
586{
587 struct e1000_nvm_info *nvm = &hw->nvm;
588 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000589 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700590 u16 i;
591
Bruce Allanad680762008-03-28 09:15:03 -0700592 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700593 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000594 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700595 return -E1000_ERR_CONFIG;
596 }
597
598 nvm->type = e1000_nvm_flash_sw;
599
600 gfpreg = er32flash(ICH_FLASH_GFPREG);
601
Bruce Allane921eb12012-11-28 09:28:37 +0000602 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700603 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700604 * the overall size.
605 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700606 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
607 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
608
609 /* flash_base_addr is byte-aligned */
610 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
611
Bruce Allane921eb12012-11-28 09:28:37 +0000612 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700613 * size represents two separate NVM banks.
614 */
Bruce Allanf0ff4392013-02-20 04:05:39 +0000615 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
616 << FLASH_SECTOR_ADDR_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700617 nvm->flash_bank_size /= 2;
618 /* Adjust to word count */
619 nvm->flash_bank_size /= sizeof(u16);
620
621 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
622
623 /* Clear shadow ram */
624 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000625 dev_spec->shadow_ram[i].modified = false;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000626 dev_spec->shadow_ram[i].value = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627 }
628
629 return 0;
630}
631
632/**
633 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
634 * @hw: pointer to the HW structure
635 *
636 * Initialize family-specific MAC parameters and function
637 * pointers.
638 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000639static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641 struct e1000_mac_info *mac = &hw->mac;
642
643 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700644 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645
646 /* Set mta register count */
647 mac->mta_reg_count = 32;
648 /* Set rar entry count */
649 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
650 if (mac->type == e1000_ich8lan)
651 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000652 /* FWSM register */
653 mac->has_fwsm = true;
654 /* ARC subsystem not supported */
655 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000656 /* Adaptive IFS supported */
657 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700658
Bruce Allan2fbe4522012-04-19 03:21:47 +0000659 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000660 switch (mac->type) {
661 case e1000_ich8lan:
662 case e1000_ich9lan:
663 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000664 /* check management mode */
665 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000666 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000667 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000668 /* blink LED */
669 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000670 /* setup LED */
671 mac->ops.setup_led = e1000e_setup_led_generic;
672 /* cleanup LED */
673 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
674 /* turn on/off LED */
675 mac->ops.led_on = e1000_led_on_ich8lan;
676 mac->ops.led_off = e1000_led_off_ich8lan;
677 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000678 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000679 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
680 mac->ops.rar_set = e1000_rar_set_pch2lan;
681 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000682 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000683 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000684 /* check management mode */
685 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000686 /* ID LED init */
687 mac->ops.id_led_init = e1000_id_led_init_pchlan;
688 /* setup LED */
689 mac->ops.setup_led = e1000_setup_led_pchlan;
690 /* cleanup LED */
691 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
692 /* turn on/off LED */
693 mac->ops.led_on = e1000_led_on_pchlan;
694 mac->ops.led_off = e1000_led_off_pchlan;
695 break;
696 default:
697 break;
698 }
699
Bruce Allan2fbe4522012-04-19 03:21:47 +0000700 if (mac->type == e1000_pch_lpt) {
701 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
702 mac->ops.rar_set = e1000_rar_set_pch_lpt;
Bruce Allanea8179a2013-03-06 09:02:47 +0000703 mac->ops.setup_physical_interface =
704 e1000_setup_copper_link_pch_lpt;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000705 }
706
Auke Kokbc7f75f2007-09-17 12:30:59 -0700707 /* Enable PCS Lock-loss workaround for ICH8 */
708 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000709 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700710
711 return 0;
712}
713
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000714/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000715 * __e1000_access_emi_reg_locked - Read/write EMI register
716 * @hw: pointer to the HW structure
717 * @addr: EMI address to program
718 * @data: pointer to value to read/write from/to the EMI address
719 * @read: boolean flag to indicate read or write
720 *
721 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
722 **/
723static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
724 u16 *data, bool read)
725{
Bruce Allan70806a72013-01-05 05:08:37 +0000726 s32 ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000727
728 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
729 if (ret_val)
730 return ret_val;
731
732 if (read)
733 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
734 else
735 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
736
737 return ret_val;
738}
739
740/**
741 * e1000_read_emi_reg_locked - Read Extended Management Interface register
742 * @hw: pointer to the HW structure
743 * @addr: EMI address to program
744 * @data: value to be read from the EMI address
745 *
746 * Assumes the SW/FW/HW Semaphore is already acquired.
747 **/
Bruce Allan203e41512012-12-05 08:40:59 +0000748s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000749{
750 return __e1000_access_emi_reg_locked(hw, addr, data, true);
751}
752
753/**
754 * e1000_write_emi_reg_locked - Write Extended Management Interface register
755 * @hw: pointer to the HW structure
756 * @addr: EMI address to program
757 * @data: value to be written to the EMI address
758 *
759 * Assumes the SW/FW/HW Semaphore is already acquired.
760 **/
Bruce Alland495bcb2013-03-20 07:23:11 +0000761s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000762{
763 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
764}
765
766/**
Bruce Allane52997f2010-06-16 13:27:49 +0000767 * e1000_set_eee_pchlan - Enable/disable EEE support
768 * @hw: pointer to the HW structure
769 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000770 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
771 * the link and the EEE capabilities of the link partner. The LPI Control
772 * register bits will remain set only if/when link is up.
David Ertmana03206e2014-01-24 23:07:48 +0000773 *
774 * EEE LPI must not be asserted earlier than one second after link is up.
775 * On 82579, EEE LPI should not be enabled until such time otherwise there
776 * can be link issues with some switches. Other devices can have EEE LPI
777 * enabled immediately upon link up since they have a timer in hardware which
778 * prevents LPI from being asserted too early.
Bruce Allane52997f2010-06-16 13:27:49 +0000779 **/
David Ertmana03206e2014-01-24 23:07:48 +0000780s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
Bruce Allane52997f2010-06-16 13:27:49 +0000781{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000782 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000783 s32 ret_val;
Bruce Alland495bcb2013-03-20 07:23:11 +0000784 u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
Bruce Allane52997f2010-06-16 13:27:49 +0000785
Bruce Alland495bcb2013-03-20 07:23:11 +0000786 switch (hw->phy.type) {
787 case e1000_phy_82579:
788 lpa = I82579_EEE_LP_ABILITY;
789 pcs_status = I82579_EEE_PCS_STATUS;
790 adv_addr = I82579_EEE_ADVERTISEMENT;
791 break;
792 case e1000_phy_i217:
793 lpa = I217_EEE_LP_ABILITY;
794 pcs_status = I217_EEE_PCS_STATUS;
795 adv_addr = I217_EEE_ADVERTISEMENT;
796 break;
797 default:
Bruce Allan5015e532012-02-08 02:55:56 +0000798 return 0;
Bruce Alland495bcb2013-03-20 07:23:11 +0000799 }
Bruce Allane52997f2010-06-16 13:27:49 +0000800
Bruce Allan3d4d5752012-12-05 06:26:08 +0000801 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000802 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000803 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000804
Bruce Allan3d4d5752012-12-05 06:26:08 +0000805 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000806 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000807 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000808
Bruce Allan3d4d5752012-12-05 06:26:08 +0000809 /* Clear bits that enable EEE in various speeds */
810 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
811
812 /* Enable EEE if not disabled by user */
813 if (!dev_spec->eee_disable) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000814 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000815 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000816 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000817 if (ret_val)
818 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000819
Bruce Alland495bcb2013-03-20 07:23:11 +0000820 /* Read EEE advertisement */
821 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
822 if (ret_val)
823 goto release;
824
Bruce Allan3d4d5752012-12-05 06:26:08 +0000825 /* Enable EEE only for speeds in which the link partner is
Bruce Alland495bcb2013-03-20 07:23:11 +0000826 * EEE capable and for which we advertise EEE.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000827 */
Bruce Alland495bcb2013-03-20 07:23:11 +0000828 if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000829 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
830
Bruce Alland495bcb2013-03-20 07:23:11 +0000831 if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000832 e1e_rphy_locked(hw, MII_LPA, &data);
833 if (data & LPA_100FULL)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000834 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
835 else
836 /* EEE is not supported in 100Half, so ignore
837 * partner's EEE in 100 ability if full-duplex
838 * is not advertised.
839 */
840 dev_spec->eee_lp_ability &=
841 ~I82579_EEE_100_SUPPORTED;
842 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000843 }
844
Bruce Alland495bcb2013-03-20 07:23:11 +0000845 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
846 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
847 if (ret_val)
848 goto release;
849
Bruce Allan3d4d5752012-12-05 06:26:08 +0000850 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
851release:
852 hw->phy.ops.release(hw);
853
854 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000855}
856
857/**
Bruce Allane08f6262013-02-20 03:06:34 +0000858 * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
859 * @hw: pointer to the HW structure
860 * @link: link up bool flag
861 *
862 * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
863 * preventing further DMA write requests. Workaround the issue by disabling
864 * the de-assertion of the clock request when in 1Gpbs mode.
Bruce Allane0236ad2013-06-21 09:07:13 +0000865 * Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
866 * speeds in order to avoid Tx hangs.
Bruce Allane08f6262013-02-20 03:06:34 +0000867 **/
868static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
869{
870 u32 fextnvm6 = er32(FEXTNVM6);
Bruce Allane0236ad2013-06-21 09:07:13 +0000871 u32 status = er32(STATUS);
Bruce Allane08f6262013-02-20 03:06:34 +0000872 s32 ret_val = 0;
Bruce Allane0236ad2013-06-21 09:07:13 +0000873 u16 reg;
Bruce Allane08f6262013-02-20 03:06:34 +0000874
Bruce Allane0236ad2013-06-21 09:07:13 +0000875 if (link && (status & E1000_STATUS_SPEED_1000)) {
Bruce Allane08f6262013-02-20 03:06:34 +0000876 ret_val = hw->phy.ops.acquire(hw);
877 if (ret_val)
878 return ret_val;
879
880 ret_val =
881 e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000882 &reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000883 if (ret_val)
884 goto release;
885
886 ret_val =
887 e1000e_write_kmrn_reg_locked(hw,
888 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000889 reg &
Bruce Allane08f6262013-02-20 03:06:34 +0000890 ~E1000_KMRNCTRLSTA_K1_ENABLE);
891 if (ret_val)
892 goto release;
893
894 usleep_range(10, 20);
895
896 ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
897
898 ret_val =
899 e1000e_write_kmrn_reg_locked(hw,
900 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000901 reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000902release:
903 hw->phy.ops.release(hw);
904 } else {
905 /* clear FEXTNVM6 bit 8 on link down or 10/100 */
Bruce Allane0236ad2013-06-21 09:07:13 +0000906 fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
907
908 if (!link || ((status & E1000_STATUS_SPEED_100) &&
909 (status & E1000_STATUS_FD)))
910 goto update_fextnvm6;
911
912 ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
913 if (ret_val)
914 return ret_val;
915
916 /* Clear link status transmit timeout */
917 reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
918
919 if (status & E1000_STATUS_SPEED_100) {
920 /* Set inband Tx timeout to 5x10us for 100Half */
921 reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
922
923 /* Do not extend the K1 entry latency for 100Half */
924 fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
925 } else {
926 /* Set inband Tx timeout to 50x10us for 10Full/Half */
927 reg |= 50 <<
928 I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
929
930 /* Extend the K1 entry latency for 10 Mbps */
931 fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
932 }
933
934 ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
935 if (ret_val)
936 return ret_val;
937
938update_fextnvm6:
939 ew32(FEXTNVM6, fextnvm6);
Bruce Allane08f6262013-02-20 03:06:34 +0000940 }
941
942 return ret_val;
943}
944
945/**
Bruce Allancf8fb732013-03-06 09:03:02 +0000946 * e1000_platform_pm_pch_lpt - Set platform power management values
947 * @hw: pointer to the HW structure
948 * @link: bool indicating link status
949 *
950 * Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
951 * GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
952 * when link is up (which must not exceed the maximum latency supported
953 * by the platform), otherwise specify there is no LTR requirement.
954 * Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
955 * latencies in the LTR Extended Capability Structure in the PCIe Extended
956 * Capability register set, on this device LTR is set by writing the
957 * equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
958 * set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
959 * message to the PMC.
960 **/
961static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
962{
963 u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
964 link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
965 u16 lat_enc = 0; /* latency encoded */
966
967 if (link) {
968 u16 speed, duplex, scale = 0;
969 u16 max_snoop, max_nosnoop;
970 u16 max_ltr_enc; /* max LTR latency encoded */
971 s64 lat_ns; /* latency (ns) */
972 s64 value;
973 u32 rxa;
974
975 if (!hw->adapter->max_frame_size) {
976 e_dbg("max_frame_size not set.\n");
977 return -E1000_ERR_CONFIG;
978 }
979
980 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
981 if (!speed) {
982 e_dbg("Speed not set.\n");
983 return -E1000_ERR_CONFIG;
984 }
985
986 /* Rx Packet Buffer Allocation size (KB) */
987 rxa = er32(PBA) & E1000_PBA_RXA_MASK;
988
989 /* Determine the maximum latency tolerated by the device.
990 *
991 * Per the PCIe spec, the tolerated latencies are encoded as
992 * a 3-bit encoded scale (only 0-5 are valid) multiplied by
993 * a 10-bit value (0-1023) to provide a range from 1 ns to
994 * 2^25*(2^10-1) ns. The scale is encoded as 0=2^0ns,
995 * 1=2^5ns, 2=2^10ns,...5=2^25ns.
996 */
997 lat_ns = ((s64)rxa * 1024 -
998 (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
999 if (lat_ns < 0)
1000 lat_ns = 0;
1001 else
1002 do_div(lat_ns, speed);
1003
1004 value = lat_ns;
1005 while (value > PCI_LTR_VALUE_MASK) {
1006 scale++;
1007 value = DIV_ROUND_UP(value, (1 << 5));
1008 }
1009 if (scale > E1000_LTRV_SCALE_MAX) {
1010 e_dbg("Invalid LTR latency scale %d\n", scale);
1011 return -E1000_ERR_CONFIG;
1012 }
1013 lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
1014
1015 /* Determine the maximum latency tolerated by the platform */
1016 pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
1017 &max_snoop);
1018 pci_read_config_word(hw->adapter->pdev,
1019 E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
1020 max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
1021
1022 if (lat_enc > max_ltr_enc)
1023 lat_enc = max_ltr_enc;
1024 }
1025
1026 /* Set Snoop and No-Snoop latencies the same */
1027 reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
1028 ew32(LTRV, reg);
1029
1030 return 0;
1031}
1032
1033/**
David Ertman74f350e2014-02-22 03:15:17 +00001034 * e1000_enable_ulp_lpt_lp - configure Ultra Low Power mode for LynxPoint-LP
1035 * @hw: pointer to the HW structure
1036 * @to_sx: boolean indicating a system power state transition to Sx
1037 *
1038 * When link is down, configure ULP mode to significantly reduce the power
1039 * to the PHY. If on a Manageability Engine (ME) enabled system, tell the
1040 * ME firmware to start the ULP configuration. If not on an ME enabled
1041 * system, configure the ULP mode by software.
1042 */
1043s32 e1000_enable_ulp_lpt_lp(struct e1000_hw *hw, bool to_sx)
1044{
1045 u32 mac_reg;
1046 s32 ret_val = 0;
1047 u16 phy_reg;
1048
1049 if ((hw->mac.type < e1000_pch_lpt) ||
1050 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
1051 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
1052 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
1053 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
1054 (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_on))
1055 return 0;
1056
1057 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
1058 /* Request ME configure ULP mode in the PHY */
1059 mac_reg = er32(H2ME);
1060 mac_reg |= E1000_H2ME_ULP | E1000_H2ME_ENFORCE_SETTINGS;
1061 ew32(H2ME, mac_reg);
1062
1063 goto out;
1064 }
1065
1066 if (!to_sx) {
1067 int i = 0;
1068
1069 /* Poll up to 5 seconds for Cable Disconnected indication */
1070 while (!(er32(FEXT) & E1000_FEXT_PHY_CABLE_DISCONNECTED)) {
1071 /* Bail if link is re-acquired */
1072 if (er32(STATUS) & E1000_STATUS_LU)
1073 return -E1000_ERR_PHY;
1074
1075 if (i++ == 100)
1076 break;
1077
1078 msleep(50);
1079 }
1080 e_dbg("CABLE_DISCONNECTED %s set after %dmsec\n",
1081 (er32(FEXT) &
1082 E1000_FEXT_PHY_CABLE_DISCONNECTED) ? "" : "not", i * 50);
1083 }
1084
1085 ret_val = hw->phy.ops.acquire(hw);
1086 if (ret_val)
1087 goto out;
1088
1089 /* Force SMBus mode in PHY */
1090 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
1091 if (ret_val)
1092 goto release;
1093 phy_reg |= CV_SMB_CTRL_FORCE_SMBUS;
1094 e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
1095
1096 /* Force SMBus mode in MAC */
1097 mac_reg = er32(CTRL_EXT);
1098 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
1099 ew32(CTRL_EXT, mac_reg);
1100
1101 /* Set Inband ULP Exit, Reset to SMBus mode and
1102 * Disable SMBus Release on PERST# in PHY
1103 */
1104 ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
1105 if (ret_val)
1106 goto release;
1107 phy_reg |= (I218_ULP_CONFIG1_RESET_TO_SMBUS |
1108 I218_ULP_CONFIG1_DISABLE_SMB_PERST);
1109 if (to_sx) {
1110 if (er32(WUFC) & E1000_WUFC_LNKC)
1111 phy_reg |= I218_ULP_CONFIG1_WOL_HOST;
1112
1113 phy_reg |= I218_ULP_CONFIG1_STICKY_ULP;
1114 } else {
1115 phy_reg |= I218_ULP_CONFIG1_INBAND_EXIT;
1116 }
1117 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1118
1119 /* Set Disable SMBus Release on PERST# in MAC */
1120 mac_reg = er32(FEXTNVM7);
1121 mac_reg |= E1000_FEXTNVM7_DISABLE_SMB_PERST;
1122 ew32(FEXTNVM7, mac_reg);
1123
1124 /* Commit ULP changes in PHY by starting auto ULP configuration */
1125 phy_reg |= I218_ULP_CONFIG1_START;
1126 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1127release:
1128 hw->phy.ops.release(hw);
1129out:
1130 if (ret_val)
1131 e_dbg("Error in ULP enable flow: %d\n", ret_val);
1132 else
1133 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_on;
1134
1135 return ret_val;
1136}
1137
1138/**
1139 * e1000_disable_ulp_lpt_lp - unconfigure Ultra Low Power mode for LynxPoint-LP
1140 * @hw: pointer to the HW structure
1141 * @force: boolean indicating whether or not to force disabling ULP
1142 *
1143 * Un-configure ULP mode when link is up, the system is transitioned from
1144 * Sx or the driver is unloaded. If on a Manageability Engine (ME) enabled
1145 * system, poll for an indication from ME that ULP has been un-configured.
1146 * If not on an ME enabled system, un-configure the ULP mode by software.
1147 *
1148 * During nominal operation, this function is called when link is acquired
1149 * to disable ULP mode (force=false); otherwise, for example when unloading
1150 * the driver or during Sx->S0 transitions, this is called with force=true
1151 * to forcibly disable ULP.
1152 */
1153static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force)
1154{
1155 s32 ret_val = 0;
1156 u32 mac_reg;
1157 u16 phy_reg;
1158 int i = 0;
1159
1160 if ((hw->mac.type < e1000_pch_lpt) ||
1161 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
1162 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
1163 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
1164 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
1165 (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_off))
1166 return 0;
1167
1168 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
1169 if (force) {
1170 /* Request ME un-configure ULP mode in the PHY */
1171 mac_reg = er32(H2ME);
1172 mac_reg &= ~E1000_H2ME_ULP;
1173 mac_reg |= E1000_H2ME_ENFORCE_SETTINGS;
1174 ew32(H2ME, mac_reg);
1175 }
1176
1177 /* Poll up to 100msec for ME to clear ULP_CFG_DONE */
1178 while (er32(FWSM) & E1000_FWSM_ULP_CFG_DONE) {
1179 if (i++ == 10) {
1180 ret_val = -E1000_ERR_PHY;
1181 goto out;
1182 }
1183
1184 usleep_range(10000, 20000);
1185 }
1186 e_dbg("ULP_CONFIG_DONE cleared after %dmsec\n", i * 10);
1187
1188 if (force) {
1189 mac_reg = er32(H2ME);
1190 mac_reg &= ~E1000_H2ME_ENFORCE_SETTINGS;
1191 ew32(H2ME, mac_reg);
1192 } else {
1193 /* Clear H2ME.ULP after ME ULP configuration */
1194 mac_reg = er32(H2ME);
1195 mac_reg &= ~E1000_H2ME_ULP;
1196 ew32(H2ME, mac_reg);
1197 }
1198
1199 goto out;
1200 }
1201
1202 ret_val = hw->phy.ops.acquire(hw);
1203 if (ret_val)
1204 goto out;
1205
1206 if (force)
1207 /* Toggle LANPHYPC Value bit */
1208 e1000_toggle_lanphypc_pch_lpt(hw);
1209
1210 /* Unforce SMBus mode in PHY */
1211 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
1212 if (ret_val) {
1213 /* The MAC might be in PCIe mode, so temporarily force to
1214 * SMBus mode in order to access the PHY.
1215 */
1216 mac_reg = er32(CTRL_EXT);
1217 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
1218 ew32(CTRL_EXT, mac_reg);
1219
1220 msleep(50);
1221
1222 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL,
1223 &phy_reg);
1224 if (ret_val)
1225 goto release;
1226 }
1227 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
1228 e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
1229
1230 /* Unforce SMBus mode in MAC */
1231 mac_reg = er32(CTRL_EXT);
1232 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
1233 ew32(CTRL_EXT, mac_reg);
1234
1235 /* When ULP mode was previously entered, K1 was disabled by the
1236 * hardware. Re-Enable K1 in the PHY when exiting ULP.
1237 */
1238 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_PM_CTRL, &phy_reg);
1239 if (ret_val)
1240 goto release;
1241 phy_reg |= HV_PM_CTRL_K1_ENABLE;
1242 e1000_write_phy_reg_hv_locked(hw, HV_PM_CTRL, phy_reg);
1243
1244 /* Clear ULP enabled configuration */
1245 ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
1246 if (ret_val)
1247 goto release;
1248 phy_reg &= ~(I218_ULP_CONFIG1_IND |
1249 I218_ULP_CONFIG1_STICKY_ULP |
1250 I218_ULP_CONFIG1_RESET_TO_SMBUS |
1251 I218_ULP_CONFIG1_WOL_HOST |
1252 I218_ULP_CONFIG1_INBAND_EXIT |
1253 I218_ULP_CONFIG1_DISABLE_SMB_PERST);
1254 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1255
1256 /* Commit ULP changes by starting auto ULP configuration */
1257 phy_reg |= I218_ULP_CONFIG1_START;
1258 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1259
1260 /* Clear Disable SMBus Release on PERST# in MAC */
1261 mac_reg = er32(FEXTNVM7);
1262 mac_reg &= ~E1000_FEXTNVM7_DISABLE_SMB_PERST;
1263 ew32(FEXTNVM7, mac_reg);
1264
1265release:
1266 hw->phy.ops.release(hw);
1267 if (force) {
1268 e1000_phy_hw_reset(hw);
1269 msleep(50);
1270 }
1271out:
1272 if (ret_val)
1273 e_dbg("Error in ULP disable flow: %d\n", ret_val);
1274 else
1275 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_off;
1276
1277 return ret_val;
1278}
1279
1280/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001281 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
1282 * @hw: pointer to the HW structure
1283 *
1284 * Checks to see of the link status of the hardware has changed. If a
1285 * change in link status has been detected, then we read the PHY registers
1286 * to get the current speed/duplex if link exists.
1287 **/
1288static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1289{
1290 struct e1000_mac_info *mac = &hw->mac;
1291 s32 ret_val;
1292 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001293 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001294
Bruce Allane921eb12012-11-28 09:28:37 +00001295 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001296 * has completed and/or if our link status has changed. The
1297 * get_link_status flag is set upon receiving a Link Status
1298 * Change or Rx Sequence Error interrupt.
1299 */
Bruce Allan5015e532012-02-08 02:55:56 +00001300 if (!mac->get_link_status)
1301 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001302
Bruce Allane921eb12012-11-28 09:28:37 +00001303 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001304 * link. If so, then we want to get the current speed/duplex
1305 * of the PHY.
1306 */
1307 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1308 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001309 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001310
Bruce Allan1d5846b2009-10-29 13:46:05 +00001311 if (hw->mac.type == e1000_pchlan) {
1312 ret_val = e1000_k1_gig_workaround_hv(hw, link);
1313 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001314 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001315 }
1316
David Ertmanfbb9ab12014-04-22 05:48:54 +00001317 /* When connected at 10Mbps half-duplex, some parts are excessively
Bruce Allan772d05c2013-03-06 09:02:36 +00001318 * aggressive resulting in many collisions. To avoid this, increase
1319 * the IPG and reduce Rx latency in the PHY.
1320 */
David Ertmanfbb9ab12014-04-22 05:48:54 +00001321 if (((hw->mac.type == e1000_pch2lan) ||
1322 (hw->mac.type == e1000_pch_lpt)) && link) {
Bruce Allan772d05c2013-03-06 09:02:36 +00001323 u32 reg;
1324 reg = er32(STATUS);
1325 if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
David Ertmanfbb9ab12014-04-22 05:48:54 +00001326 u16 emi_addr;
1327
Bruce Allan772d05c2013-03-06 09:02:36 +00001328 reg = er32(TIPG);
1329 reg &= ~E1000_TIPG_IPGT_MASK;
1330 reg |= 0xFF;
1331 ew32(TIPG, reg);
1332
1333 /* Reduce Rx latency in analog PHY */
1334 ret_val = hw->phy.ops.acquire(hw);
1335 if (ret_val)
1336 return ret_val;
1337
David Ertmanfbb9ab12014-04-22 05:48:54 +00001338 if (hw->mac.type == e1000_pch2lan)
1339 emi_addr = I82579_RX_CONFIG;
1340 else
1341 emi_addr = I217_RX_CONFIG;
1342
1343 ret_val = e1000_write_emi_reg_locked(hw, emi_addr, 0);
Bruce Allan772d05c2013-03-06 09:02:36 +00001344
1345 hw->phy.ops.release(hw);
1346
1347 if (ret_val)
1348 return ret_val;
1349 }
1350 }
1351
Bruce Allane08f6262013-02-20 03:06:34 +00001352 /* Work-around I218 hang issue */
1353 if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
Bruce Allan91a3d822013-06-29 01:15:16 +00001354 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
1355 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
1356 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
Bruce Allane08f6262013-02-20 03:06:34 +00001357 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
1358 if (ret_val)
1359 return ret_val;
1360 }
1361
Bruce Allancf8fb732013-03-06 09:03:02 +00001362 if (hw->mac.type == e1000_pch_lpt) {
1363 /* Set platform power management values for
1364 * Latency Tolerance Reporting (LTR)
1365 */
1366 ret_val = e1000_platform_pm_pch_lpt(hw, link);
1367 if (ret_val)
1368 return ret_val;
1369 }
1370
Bruce Allan2fbe4522012-04-19 03:21:47 +00001371 /* Clear link partner's EEE ability */
1372 hw->dev_spec.ich8lan.eee_lp_ability = 0;
1373
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001374 if (!link)
Bruce Allane80bd1d2013-05-01 01:19:46 +00001375 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001376
1377 mac->get_link_status = false;
1378
Bruce Allan1d2101a72011-07-22 06:21:56 +00001379 switch (hw->mac.type) {
1380 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +00001381 ret_val = e1000_k1_workaround_lv(hw);
1382 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001383 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001384 /* fall-thru */
1385 case e1000_pchlan:
1386 if (hw->phy.type == e1000_phy_82578) {
1387 ret_val = e1000_link_stall_workaround_hv(hw);
1388 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001389 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001390 }
1391
Bruce Allane921eb12012-11-28 09:28:37 +00001392 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +00001393 * Set the number of preambles removed from the packet
1394 * when it is passed from the PHY to the MAC to prevent
1395 * the MAC from misinterpreting the packet type.
1396 */
1397 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
1398 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
1399
1400 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
1401 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
1402
1403 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
1404 break;
1405 default:
1406 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001407 }
1408
Bruce Allane921eb12012-11-28 09:28:37 +00001409 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001410 * immediately after link-up
1411 */
1412 e1000e_check_downshift(hw);
1413
Bruce Allane52997f2010-06-16 13:27:49 +00001414 /* Enable/Disable EEE after link up */
David Ertmana03206e2014-01-24 23:07:48 +00001415 if (hw->phy.type > e1000_phy_82579) {
1416 ret_val = e1000_set_eee_pchlan(hw);
1417 if (ret_val)
1418 return ret_val;
1419 }
Bruce Allane52997f2010-06-16 13:27:49 +00001420
Bruce Allane921eb12012-11-28 09:28:37 +00001421 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001422 * we have already determined whether we have link or not.
1423 */
Bruce Allan5015e532012-02-08 02:55:56 +00001424 if (!mac->autoneg)
1425 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001426
Bruce Allane921eb12012-11-28 09:28:37 +00001427 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001428 * of MAC speed/duplex configuration. So we only need to
1429 * configure Collision Distance in the MAC.
1430 */
Bruce Allan57cde762012-02-22 09:02:58 +00001431 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001432
Bruce Allane921eb12012-11-28 09:28:37 +00001433 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001434 * First, we need to restore the desired flow control
1435 * settings because we may have had to re-autoneg with a
1436 * different link partner.
1437 */
1438 ret_val = e1000e_config_fc_after_link_up(hw);
1439 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001440 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001441
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001442 return ret_val;
1443}
1444
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001445static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001446{
1447 struct e1000_hw *hw = &adapter->hw;
1448 s32 rc;
1449
Bruce Allanec34c172012-02-01 10:53:05 +00001450 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001451 if (rc)
1452 return rc;
1453
1454 rc = e1000_init_nvm_params_ich8lan(hw);
1455 if (rc)
1456 return rc;
1457
Bruce Alland3738bb2010-06-16 13:27:28 +00001458 switch (hw->mac.type) {
1459 case e1000_ich8lan:
1460 case e1000_ich9lan:
1461 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001462 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001463 break;
1464 case e1000_pchlan:
1465 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001466 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001467 rc = e1000_init_phy_params_pchlan(hw);
1468 break;
1469 default:
1470 break;
1471 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001472 if (rc)
1473 return rc;
1474
Bruce Allane921eb12012-11-28 09:28:37 +00001475 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001476 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1477 */
1478 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1479 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1480 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001481 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1482 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001483
1484 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001485 }
1486
Auke Kokbc7f75f2007-09-17 12:30:59 -07001487 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001488 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001489 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1490
Bruce Allanc6e7f512011-07-29 05:53:02 +00001491 /* Enable workaround for 82579 w/ ME enabled */
1492 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1493 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1494 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1495
Auke Kokbc7f75f2007-09-17 12:30:59 -07001496 return 0;
1497}
1498
Thomas Gleixner717d4382008-10-02 16:33:40 -07001499static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001500
Auke Kokbc7f75f2007-09-17 12:30:59 -07001501/**
Bruce Allanca15df52009-10-26 11:23:43 +00001502 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1503 * @hw: pointer to the HW structure
1504 *
1505 * Acquires the mutex for performing NVM operations.
1506 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001507static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001508{
1509 mutex_lock(&nvm_mutex);
1510
1511 return 0;
1512}
1513
1514/**
1515 * e1000_release_nvm_ich8lan - Release NVM mutex
1516 * @hw: pointer to the HW structure
1517 *
1518 * Releases the mutex used while performing NVM operations.
1519 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001520static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001521{
1522 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001523}
1524
Bruce Allanca15df52009-10-26 11:23:43 +00001525/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001526 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1527 * @hw: pointer to the HW structure
1528 *
Bruce Allanca15df52009-10-26 11:23:43 +00001529 * Acquires the software control flag for performing PHY and select
1530 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001531 **/
1532static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1533{
Bruce Allan373a88d2009-08-07 07:41:37 +00001534 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1535 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001536
Bruce Allana90b4122011-10-07 03:50:38 +00001537 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1538 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001539 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001540 return -E1000_ERR_PHY;
1541 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001542
Auke Kokbc7f75f2007-09-17 12:30:59 -07001543 while (timeout) {
1544 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001545 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1546 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547
Auke Kokbc7f75f2007-09-17 12:30:59 -07001548 mdelay(1);
1549 timeout--;
1550 }
1551
1552 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001553 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001554 ret_val = -E1000_ERR_CONFIG;
1555 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001556 }
1557
Bruce Allan53ac5a82009-10-26 11:23:06 +00001558 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001559
1560 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1561 ew32(EXTCNF_CTRL, extcnf_ctrl);
1562
1563 while (timeout) {
1564 extcnf_ctrl = er32(EXTCNF_CTRL);
1565 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1566 break;
1567
1568 mdelay(1);
1569 timeout--;
1570 }
1571
1572 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001573 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 +00001574 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001575 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1576 ew32(EXTCNF_CTRL, extcnf_ctrl);
1577 ret_val = -E1000_ERR_CONFIG;
1578 goto out;
1579 }
1580
1581out:
1582 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001583 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001584
1585 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586}
1587
1588/**
1589 * e1000_release_swflag_ich8lan - Release software control flag
1590 * @hw: pointer to the HW structure
1591 *
Bruce Allanca15df52009-10-26 11:23:43 +00001592 * Releases the software control flag for performing PHY and select
1593 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001594 **/
1595static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1596{
1597 u32 extcnf_ctrl;
1598
1599 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001600
1601 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1602 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1603 ew32(EXTCNF_CTRL, extcnf_ctrl);
1604 } else {
1605 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1606 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001607
Bruce Allana90b4122011-10-07 03:50:38 +00001608 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001609}
1610
1611/**
Bruce Allan4662e822008-08-26 18:37:06 -07001612 * e1000_check_mng_mode_ich8lan - Checks management mode
1613 * @hw: pointer to the HW structure
1614 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001615 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001616 * This is a function pointer entry point only called by read/write
1617 * routines for the PHY and NVM parts.
1618 **/
1619static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1620{
Bruce Allana708dd82009-11-20 23:28:37 +00001621 u32 fwsm;
1622
1623 fwsm = er32(FWSM);
Bruce Allanf0ff4392013-02-20 04:05:39 +00001624 return ((fwsm & E1000_ICH_FWSM_FW_VALID) &&
1625 ((fwsm & E1000_FWSM_MODE_MASK) ==
1626 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)));
Bruce Allaneb7700d2010-06-16 13:27:05 +00001627}
Bruce Allan4662e822008-08-26 18:37:06 -07001628
Bruce Allaneb7700d2010-06-16 13:27:05 +00001629/**
1630 * e1000_check_mng_mode_pchlan - Checks management mode
1631 * @hw: pointer to the HW structure
1632 *
1633 * This checks if the adapter has iAMT enabled.
1634 * This is a function pointer entry point only called by read/write
1635 * routines for the PHY and NVM parts.
1636 **/
1637static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1638{
1639 u32 fwsm;
1640
1641 fwsm = er32(FWSM);
1642 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
Bruce Allanf0ff4392013-02-20 04:05:39 +00001643 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001644}
1645
1646/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001647 * e1000_rar_set_pch2lan - Set receive address register
1648 * @hw: pointer to the HW structure
1649 * @addr: pointer to the receive address
1650 * @index: receive address array register
1651 *
1652 * Sets the receive address array register at index to the address passed
1653 * in by addr. For 82579, RAR[0] is the base address register that is to
1654 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1655 * Use SHRA[0-3] in place of those reserved for ME.
1656 **/
1657static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1658{
1659 u32 rar_low, rar_high;
1660
Bruce Allane921eb12012-11-28 09:28:37 +00001661 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001662 * from network order (big endian) to little endian
1663 */
1664 rar_low = ((u32)addr[0] |
1665 ((u32)addr[1] << 8) |
1666 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1667
1668 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1669
1670 /* If MAC address zero, no need to set the AV bit */
1671 if (rar_low || rar_high)
1672 rar_high |= E1000_RAH_AV;
1673
1674 if (index == 0) {
1675 ew32(RAL(index), rar_low);
1676 e1e_flush();
1677 ew32(RAH(index), rar_high);
1678 e1e_flush();
1679 return;
1680 }
1681
David Ertmanc3a0dce2013-09-05 04:24:25 +00001682 /* RAR[1-6] are owned by manageability. Skip those and program the
1683 * next address into the SHRA register array.
1684 */
David Ertman96dee022014-03-05 07:50:46 +00001685 if (index < (u32)(hw->mac.rar_entry_count)) {
Bruce Allan69e1e012012-04-14 03:28:50 +00001686 s32 ret_val;
1687
1688 ret_val = e1000_acquire_swflag_ich8lan(hw);
1689 if (ret_val)
1690 goto out;
1691
1692 ew32(SHRAL(index - 1), rar_low);
1693 e1e_flush();
1694 ew32(SHRAH(index - 1), rar_high);
1695 e1e_flush();
1696
1697 e1000_release_swflag_ich8lan(hw);
1698
1699 /* verify the register updates */
1700 if ((er32(SHRAL(index - 1)) == rar_low) &&
1701 (er32(SHRAH(index - 1)) == rar_high))
1702 return;
1703
1704 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1705 (index - 1), er32(FWSM));
1706 }
1707
1708out:
1709 e_dbg("Failed to write receive address at index %d\n", index);
1710}
1711
1712/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001713 * e1000_rar_set_pch_lpt - Set receive address registers
1714 * @hw: pointer to the HW structure
1715 * @addr: pointer to the receive address
1716 * @index: receive address array register
1717 *
1718 * Sets the receive address register array at index to the address passed
1719 * in by addr. For LPT, RAR[0] is the base address register that is to
1720 * contain the MAC address. SHRA[0-10] are the shared receive address
1721 * registers that are shared between the Host and manageability engine (ME).
1722 **/
1723static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1724{
1725 u32 rar_low, rar_high;
1726 u32 wlock_mac;
1727
Bruce Allane921eb12012-11-28 09:28:37 +00001728 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001729 * from network order (big endian) to little endian
1730 */
1731 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1732 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1733
1734 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1735
1736 /* If MAC address zero, no need to set the AV bit */
1737 if (rar_low || rar_high)
1738 rar_high |= E1000_RAH_AV;
1739
1740 if (index == 0) {
1741 ew32(RAL(index), rar_low);
1742 e1e_flush();
1743 ew32(RAH(index), rar_high);
1744 e1e_flush();
1745 return;
1746 }
1747
Bruce Allane921eb12012-11-28 09:28:37 +00001748 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001749 * it is using - those registers are unavailable for use.
1750 */
1751 if (index < hw->mac.rar_entry_count) {
1752 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1753 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1754
1755 /* Check if all SHRAR registers are locked */
1756 if (wlock_mac == 1)
1757 goto out;
1758
1759 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1760 s32 ret_val;
1761
1762 ret_val = e1000_acquire_swflag_ich8lan(hw);
1763
1764 if (ret_val)
1765 goto out;
1766
1767 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1768 e1e_flush();
1769 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1770 e1e_flush();
1771
1772 e1000_release_swflag_ich8lan(hw);
1773
1774 /* verify the register updates */
1775 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1776 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1777 return;
1778 }
1779 }
1780
1781out:
1782 e_dbg("Failed to write receive address at index %d\n", index);
1783}
1784
1785/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001786 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1787 * @hw: pointer to the HW structure
1788 *
1789 * Checks if firmware is blocking the reset of the PHY.
1790 * This is a function pointer entry point only called by
1791 * reset routines.
1792 **/
1793static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1794{
David Ertmanf7235ef2014-01-23 06:29:13 +00001795 bool blocked = false;
1796 int i = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001797
David Ertmanf7235ef2014-01-23 06:29:13 +00001798 while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&
1799 (i++ < 10))
1800 usleep_range(10000, 20000);
1801 return blocked ? E1000_BLK_PHY_RESET : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001802}
1803
1804/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001805 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1806 * @hw: pointer to the HW structure
1807 *
1808 * Assumes semaphore already acquired.
1809 *
1810 **/
1811static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1812{
1813 u16 phy_data;
1814 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001815 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1816 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan70806a72013-01-05 05:08:37 +00001817 s32 ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001818
1819 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1820
1821 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1822 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001823 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001824
1825 phy_data &= ~HV_SMB_ADDR_MASK;
1826 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1827 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001828
Bruce Allan2fbe4522012-04-19 03:21:47 +00001829 if (hw->phy.type == e1000_phy_i217) {
1830 /* Restore SMBus frequency */
1831 if (freq--) {
1832 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1833 phy_data |= (freq & (1 << 0)) <<
1834 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1835 phy_data |= (freq & (1 << 1)) <<
1836 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1837 } else {
1838 e_dbg("Unsupported SMB frequency in PHY\n");
1839 }
1840 }
1841
Bruce Allan5015e532012-02-08 02:55:56 +00001842 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001843}
1844
1845/**
Bruce Allanf523d212009-10-29 13:45:45 +00001846 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1847 * @hw: pointer to the HW structure
1848 *
1849 * SW should configure the LCD from the NVM extended configuration region
1850 * as a workaround for certain parts.
1851 **/
1852static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1853{
1854 struct e1000_phy_info *phy = &hw->phy;
1855 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001856 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001857 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1858
Bruce Allane921eb12012-11-28 09:28:37 +00001859 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001860 * is needed due to an issue where the NVM configuration is
1861 * not properly autoloaded after power transitions.
1862 * Therefore, after each PHY reset, we will load the
1863 * configuration data out of the NVM manually.
1864 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001865 switch (hw->mac.type) {
1866 case e1000_ich8lan:
1867 if (phy->type != e1000_phy_igp_3)
1868 return ret_val;
1869
Bruce Allan5f3eed62010-09-22 17:15:54 +00001870 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1871 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001872 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1873 break;
1874 }
1875 /* Fall-thru */
1876 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001877 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001878 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001879 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001880 break;
1881 default:
1882 return ret_val;
1883 }
1884
1885 ret_val = hw->phy.ops.acquire(hw);
1886 if (ret_val)
1887 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001888
Bruce Allan8b802a72010-05-10 15:01:10 +00001889 data = er32(FEXTNVM);
1890 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001891 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001892
Bruce Allane921eb12012-11-28 09:28:37 +00001893 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001894 * extended configuration before SW configuration
1895 */
1896 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001897 if ((hw->mac.type < e1000_pch2lan) &&
1898 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1899 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001900
Bruce Allan8b802a72010-05-10 15:01:10 +00001901 cnf_size = er32(EXTCNF_SIZE);
1902 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1903 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1904 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001905 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001906
1907 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1908 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1909
Bruce Allan2fbe4522012-04-19 03:21:47 +00001910 if (((hw->mac.type == e1000_pchlan) &&
1911 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1912 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001913 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001914 * OEM and LCD Write Enable bits are set in the NVM.
1915 * When both NVM bits are cleared, SW will configure
1916 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001917 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001918 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001919 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001920 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001921
Bruce Allan8b802a72010-05-10 15:01:10 +00001922 data = er32(LEDCTL);
1923 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1924 (u16)data);
1925 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001926 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001927 }
1928
1929 /* Configure LCD from extended configuration region. */
1930
1931 /* cnf_base_addr is in DWORD */
1932 word_addr = (u16)(cnf_base_addr << 1);
1933
1934 for (i = 0; i < cnf_size; i++) {
Bruce Allane5fe2542013-02-20 04:06:27 +00001935 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001936 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001937 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001938
Bruce Allan8b802a72010-05-10 15:01:10 +00001939 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1940 1, &reg_addr);
1941 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001942 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001943
Bruce Allan8b802a72010-05-10 15:01:10 +00001944 /* Save off the PHY page for future writes. */
1945 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1946 phy_page = reg_data;
1947 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001948 }
Bruce Allanf523d212009-10-29 13:45:45 +00001949
Bruce Allan8b802a72010-05-10 15:01:10 +00001950 reg_addr &= PHY_REG_MASK;
1951 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001952
Bruce Allanf1430d62012-04-14 04:21:52 +00001953 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001954 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001955 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001956 }
1957
Bruce Allan75ce1532012-02-08 02:54:48 +00001958release:
Bruce Allan94d81862009-11-20 23:25:26 +00001959 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001960 return ret_val;
1961}
1962
1963/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001964 * e1000_k1_gig_workaround_hv - K1 Si workaround
1965 * @hw: pointer to the HW structure
1966 * @link: link up bool flag
1967 *
1968 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1969 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1970 * If link is down, the function will restore the default K1 setting located
1971 * in the NVM.
1972 **/
1973static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1974{
1975 s32 ret_val = 0;
1976 u16 status_reg = 0;
1977 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1978
1979 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001980 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001981
1982 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001983 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001984 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001985 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001986
1987 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1988 if (link) {
1989 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001990 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1991 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001992 if (ret_val)
1993 goto release;
1994
Bruce Allanf0ff4392013-02-20 04:05:39 +00001995 status_reg &= (BM_CS_STATUS_LINK_UP |
1996 BM_CS_STATUS_RESOLVED |
1997 BM_CS_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001998
1999 if (status_reg == (BM_CS_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00002000 BM_CS_STATUS_RESOLVED |
2001 BM_CS_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00002002 k1_enable = false;
2003 }
2004
2005 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00002006 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002007 if (ret_val)
2008 goto release;
2009
Bruce Allanf0ff4392013-02-20 04:05:39 +00002010 status_reg &= (HV_M_STATUS_LINK_UP |
2011 HV_M_STATUS_AUTONEG_COMPLETE |
2012 HV_M_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002013
2014 if (status_reg == (HV_M_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00002015 HV_M_STATUS_AUTONEG_COMPLETE |
2016 HV_M_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00002017 k1_enable = false;
2018 }
2019
2020 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00002021 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002022 if (ret_val)
2023 goto release;
2024
2025 } else {
2026 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00002027 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002028 if (ret_val)
2029 goto release;
2030 }
2031
2032 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
2033
2034release:
Bruce Allan94d81862009-11-20 23:25:26 +00002035 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00002036
Bruce Allan1d5846b2009-10-29 13:46:05 +00002037 return ret_val;
2038}
2039
2040/**
2041 * e1000_configure_k1_ich8lan - Configure K1 power state
2042 * @hw: pointer to the HW structure
2043 * @enable: K1 state to configure
2044 *
2045 * Configure the K1 power state based on the provided parameter.
2046 * Assumes semaphore already acquired.
2047 *
2048 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2049 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00002050s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00002051{
Bruce Allan70806a72013-01-05 05:08:37 +00002052 s32 ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002053 u32 ctrl_reg = 0;
2054 u32 ctrl_ext = 0;
2055 u32 reg = 0;
2056 u16 kmrn_reg = 0;
2057
Bruce Allan3d3a1672012-02-23 03:13:18 +00002058 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
2059 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002060 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002061 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002062
2063 if (k1_enable)
2064 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
2065 else
2066 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
2067
Bruce Allan3d3a1672012-02-23 03:13:18 +00002068 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
2069 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002070 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002071 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002072
Bruce Allance43a212013-02-20 04:06:32 +00002073 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002074 ctrl_ext = er32(CTRL_EXT);
2075 ctrl_reg = er32(CTRL);
2076
2077 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2078 reg |= E1000_CTRL_FRCSPD;
2079 ew32(CTRL, reg);
2080
2081 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002082 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00002083 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002084 ew32(CTRL, ctrl_reg);
2085 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002086 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00002087 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002088
Bruce Allan5015e532012-02-08 02:55:56 +00002089 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002090}
2091
2092/**
Bruce Allanf523d212009-10-29 13:45:45 +00002093 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
2094 * @hw: pointer to the HW structure
2095 * @d0_state: boolean if entering d0 or d3 device state
2096 *
2097 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
2098 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
2099 * in NVM determines whether HW should configure LPLU and Gbe Disable.
2100 **/
2101static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
2102{
2103 s32 ret_val = 0;
2104 u32 mac_reg;
2105 u16 oem_reg;
2106
Bruce Allan2fbe4522012-04-19 03:21:47 +00002107 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00002108 return ret_val;
2109
Bruce Allan94d81862009-11-20 23:25:26 +00002110 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00002111 if (ret_val)
2112 return ret_val;
2113
Bruce Allan2fbe4522012-04-19 03:21:47 +00002114 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00002115 mac_reg = er32(EXTCNF_CTRL);
2116 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00002117 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00002118 }
Bruce Allanf523d212009-10-29 13:45:45 +00002119
2120 mac_reg = er32(FEXTNVM);
2121 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00002122 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00002123
2124 mac_reg = er32(PHY_CTRL);
2125
Bruce Allanf1430d62012-04-14 04:21:52 +00002126 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00002127 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002128 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00002129
2130 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
2131
2132 if (d0_state) {
2133 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
2134 oem_reg |= HV_OEM_BITS_GBE_DIS;
2135
2136 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
2137 oem_reg |= HV_OEM_BITS_LPLU;
2138 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00002139 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
2140 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00002141 oem_reg |= HV_OEM_BITS_GBE_DIS;
2142
Bruce Allan03299e42011-09-30 08:07:05 +00002143 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
2144 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00002145 oem_reg |= HV_OEM_BITS_LPLU;
2146 }
Bruce Allan03299e42011-09-30 08:07:05 +00002147
Bruce Allan92fe1732012-04-12 06:27:03 +00002148 /* Set Restart auto-neg to activate the bits */
2149 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
2150 !hw->phy.ops.check_reset_block(hw))
2151 oem_reg |= HV_OEM_BITS_RESTART_AN;
2152
Bruce Allanf1430d62012-04-14 04:21:52 +00002153 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00002154
Bruce Allan75ce1532012-02-08 02:54:48 +00002155release:
Bruce Allan94d81862009-11-20 23:25:26 +00002156 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00002157
2158 return ret_val;
2159}
2160
Bruce Allanf523d212009-10-29 13:45:45 +00002161/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002162 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
2163 * @hw: pointer to the HW structure
2164 **/
2165static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
2166{
2167 s32 ret_val;
2168 u16 data;
2169
2170 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
2171 if (ret_val)
2172 return ret_val;
2173
2174 data |= HV_KMRN_MDIO_SLOW;
2175
2176 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
2177
2178 return ret_val;
2179}
2180
2181/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002182 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2183 * done after every PHY reset.
2184 **/
2185static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2186{
2187 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00002188 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00002189
2190 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00002191 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002192
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002193 /* Set MDIO slow mode before any other MDIO access */
2194 if (hw->phy.type == e1000_phy_82577) {
2195 ret_val = e1000_set_mdio_slow_mode_hv(hw);
2196 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002197 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002198 }
2199
Bruce Allana4f58f52009-06-02 11:29:18 +00002200 if (((hw->phy.type == e1000_phy_82577) &&
2201 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
2202 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
2203 /* Disable generation of early preamble */
2204 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
2205 if (ret_val)
2206 return ret_val;
2207
2208 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00002209 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00002210 if (ret_val)
2211 return ret_val;
2212 }
2213
2214 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00002215 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00002216 * writing 0x3140 to the control register.
2217 */
2218 if (hw->phy.revision < 2) {
2219 e1000e_phy_sw_reset(hw);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002220 ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
Bruce Allana4f58f52009-06-02 11:29:18 +00002221 }
2222 }
2223
2224 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00002225 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00002226 if (ret_val)
2227 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002228
Bruce Allana4f58f52009-06-02 11:29:18 +00002229 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002230 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00002231 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002232 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002233 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002234
Bruce Allane921eb12012-11-28 09:28:37 +00002235 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00002236 * link so that it disables K1 if link is in 1Gbps.
2237 */
2238 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00002239 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002240 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002241
Bruce Allanbaf86c92010-01-13 01:53:08 +00002242 /* Workaround for link disconnects on a busy hub in half duplex */
2243 ret_val = hw->phy.ops.acquire(hw);
2244 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002245 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00002246 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00002247 if (ret_val)
2248 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00002249 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00002250 if (ret_val)
2251 goto release;
2252
2253 /* set MSE higher to enable link to stay up when noise is high */
2254 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00002255release:
2256 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00002257
Bruce Allana4f58f52009-06-02 11:29:18 +00002258 return ret_val;
2259}
2260
2261/**
Bruce Alland3738bb2010-06-16 13:27:28 +00002262 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
2263 * @hw: pointer to the HW structure
2264 **/
2265void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
2266{
2267 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002268 u16 i, phy_reg = 0;
2269 s32 ret_val;
2270
2271 ret_val = hw->phy.ops.acquire(hw);
2272 if (ret_val)
2273 return;
2274 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2275 if (ret_val)
2276 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00002277
David Ertmanc3a0dce2013-09-05 04:24:25 +00002278 /* Copy both RAL/H (rar_entry_count) and SHRAL/H to PHY */
2279 for (i = 0; i < (hw->mac.rar_entry_count); i++) {
Bruce Alland3738bb2010-06-16 13:27:28 +00002280 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002281 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
2282 (u16)(mac_reg & 0xFFFF));
2283 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
2284 (u16)((mac_reg >> 16) & 0xFFFF));
2285
Bruce Alland3738bb2010-06-16 13:27:28 +00002286 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002287 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
2288 (u16)(mac_reg & 0xFFFF));
2289 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
2290 (u16)((mac_reg & E1000_RAH_AV)
2291 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00002292 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00002293
2294 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2295
2296release:
2297 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00002298}
2299
Bruce Alland3738bb2010-06-16 13:27:28 +00002300/**
2301 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
2302 * with 82579 PHY
2303 * @hw: pointer to the HW structure
2304 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
2305 **/
2306s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
2307{
2308 s32 ret_val = 0;
2309 u16 phy_reg, data;
2310 u32 mac_reg;
2311 u16 i;
2312
Bruce Allan2fbe4522012-04-19 03:21:47 +00002313 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002314 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002315
2316 /* disable Rx path while enabling/disabling workaround */
2317 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
2318 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
2319 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002320 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002321
2322 if (enable) {
David Ertmanc3a0dce2013-09-05 04:24:25 +00002323 /* Write Rx addresses (rar_entry_count for RAL/H, and
Bruce Alland3738bb2010-06-16 13:27:28 +00002324 * SHRAL/H) and initial CRC values to the MAC
2325 */
David Ertmanc3a0dce2013-09-05 04:24:25 +00002326 for (i = 0; i < hw->mac.rar_entry_count; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002327 u8 mac_addr[ETH_ALEN] = { 0 };
Bruce Alland3738bb2010-06-16 13:27:28 +00002328 u32 addr_high, addr_low;
2329
2330 addr_high = er32(RAH(i));
2331 if (!(addr_high & E1000_RAH_AV))
2332 continue;
2333 addr_low = er32(RAL(i));
2334 mac_addr[0] = (addr_low & 0xFF);
2335 mac_addr[1] = ((addr_low >> 8) & 0xFF);
2336 mac_addr[2] = ((addr_low >> 16) & 0xFF);
2337 mac_addr[3] = ((addr_low >> 24) & 0xFF);
2338 mac_addr[4] = (addr_high & 0xFF);
2339 mac_addr[5] = ((addr_high >> 8) & 0xFF);
2340
Bruce Allanfe46f582011-01-06 14:29:51 +00002341 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00002342 }
2343
2344 /* Write Rx addresses to the PHY */
2345 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
2346
2347 /* Enable jumbo frame workaround in the MAC */
2348 mac_reg = er32(FFLT_DBG);
2349 mac_reg &= ~(1 << 14);
2350 mac_reg |= (7 << 15);
2351 ew32(FFLT_DBG, mac_reg);
2352
2353 mac_reg = er32(RCTL);
2354 mac_reg |= E1000_RCTL_SECRC;
2355 ew32(RCTL, mac_reg);
2356
2357 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002358 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2359 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002360 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002361 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002362 ret_val = e1000e_write_kmrn_reg(hw,
2363 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2364 data | (1 << 0));
2365 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002366 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002367 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002368 E1000_KMRNCTRLSTA_HD_CTRL,
2369 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002370 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002371 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002372 data &= ~(0xF << 8);
2373 data |= (0xB << 8);
2374 ret_val = e1000e_write_kmrn_reg(hw,
2375 E1000_KMRNCTRLSTA_HD_CTRL,
2376 data);
2377 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002378 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002379
2380 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00002381 e1e_rphy(hw, PHY_REG(769, 23), &data);
2382 data &= ~(0x7F << 5);
2383 data |= (0x37 << 5);
2384 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2385 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002386 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002387 e1e_rphy(hw, PHY_REG(769, 16), &data);
2388 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00002389 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2390 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002391 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002392 e1e_rphy(hw, PHY_REG(776, 20), &data);
2393 data &= ~(0x3FF << 2);
2394 data |= (0x1A << 2);
2395 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2396 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002397 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00002398 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00002399 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002400 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002401 e1e_rphy(hw, HV_PM_CTRL, &data);
2402 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
2403 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002404 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002405 } else {
2406 /* Write MAC register values back to h/w defaults */
2407 mac_reg = er32(FFLT_DBG);
2408 mac_reg &= ~(0xF << 14);
2409 ew32(FFLT_DBG, mac_reg);
2410
2411 mac_reg = er32(RCTL);
2412 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00002413 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00002414
2415 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002416 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2417 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002418 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002419 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002420 ret_val = e1000e_write_kmrn_reg(hw,
2421 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2422 data & ~(1 << 0));
2423 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002424 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002425 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002426 E1000_KMRNCTRLSTA_HD_CTRL,
2427 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002428 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002429 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002430 data &= ~(0xF << 8);
2431 data |= (0xB << 8);
2432 ret_val = e1000e_write_kmrn_reg(hw,
2433 E1000_KMRNCTRLSTA_HD_CTRL,
2434 data);
2435 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002436 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002437
2438 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002439 e1e_rphy(hw, PHY_REG(769, 23), &data);
2440 data &= ~(0x7F << 5);
2441 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2442 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002443 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002444 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002445 data |= (1 << 13);
2446 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2447 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002448 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002449 e1e_rphy(hw, PHY_REG(776, 20), &data);
2450 data &= ~(0x3FF << 2);
2451 data |= (0x8 << 2);
2452 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2453 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002454 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002455 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2456 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002457 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002458 e1e_rphy(hw, HV_PM_CTRL, &data);
2459 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2460 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002461 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002462 }
2463
2464 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002465 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002466}
2467
2468/**
2469 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2470 * done after every PHY reset.
2471 **/
2472static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2473{
2474 s32 ret_val = 0;
2475
2476 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002477 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002478
2479 /* Set MDIO slow mode before any other MDIO access */
2480 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002481 if (ret_val)
2482 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002483
Bruce Allan4d241362011-12-16 00:46:06 +00002484 ret_val = hw->phy.ops.acquire(hw);
2485 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002486 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002487 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002488 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002489 if (ret_val)
2490 goto release;
2491 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002492 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002493release:
2494 hw->phy.ops.release(hw);
2495
Bruce Alland3738bb2010-06-16 13:27:28 +00002496 return ret_val;
2497}
2498
2499/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002500 * e1000_k1_gig_workaround_lv - K1 Si workaround
2501 * @hw: pointer to the HW structure
2502 *
David Ertman77e61142014-04-22 05:25:53 +00002503 * Workaround to set the K1 beacon duration for 82579 parts in 10Mbps
2504 * Disable K1 in 1000Mbps and 100Mbps
Bruce Allan831bd2e2010-09-22 17:16:18 +00002505 **/
2506static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2507{
2508 s32 ret_val = 0;
2509 u16 status_reg = 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002510
2511 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002512 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002513
David Ertman77e61142014-04-22 05:25:53 +00002514 /* Set K1 beacon duration based on 10Mbs speed */
Bruce Allan831bd2e2010-09-22 17:16:18 +00002515 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2516 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002517 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002518
2519 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2520 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
David Ertman77e61142014-04-22 05:25:53 +00002521 if (status_reg &
2522 (HV_M_STATUS_SPEED_1000 | HV_M_STATUS_SPEED_100)) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002523 u16 pm_phy_reg;
2524
David Ertman77e61142014-04-22 05:25:53 +00002525 /* LV 1G/100 Packet drop issue wa */
Bruce Allan36ceeb42012-03-20 03:47:47 +00002526 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2527 if (ret_val)
2528 return ret_val;
David Ertman77e61142014-04-22 05:25:53 +00002529 pm_phy_reg &= ~HV_PM_CTRL_K1_ENABLE;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002530 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2531 if (ret_val)
2532 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002533 } else {
David Ertman77e61142014-04-22 05:25:53 +00002534 u32 mac_reg;
2535
2536 mac_reg = er32(FEXTNVM4);
2537 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002538 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
David Ertman77e61142014-04-22 05:25:53 +00002539 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002540 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002541 }
2542
Bruce Allan831bd2e2010-09-22 17:16:18 +00002543 return ret_val;
2544}
2545
2546/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002547 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2548 * @hw: pointer to the HW structure
2549 * @gate: boolean set to true to gate, false to ungate
2550 *
2551 * Gate/ungate the automatic PHY configuration via hardware; perform
2552 * the configuration via software instead.
2553 **/
2554static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2555{
2556 u32 extcnf_ctrl;
2557
Bruce Allan2fbe4522012-04-19 03:21:47 +00002558 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002559 return;
2560
2561 extcnf_ctrl = er32(EXTCNF_CTRL);
2562
2563 if (gate)
2564 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2565 else
2566 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2567
2568 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002569}
2570
2571/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002572 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2573 * @hw: pointer to the HW structure
2574 *
2575 * Check the appropriate indication the MAC has finished configuring the
2576 * PHY after a software reset.
2577 **/
2578static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2579{
2580 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2581
2582 /* Wait for basic configuration completes before proceeding */
2583 do {
2584 data = er32(STATUS);
2585 data &= E1000_STATUS_LAN_INIT_DONE;
Bruce Allance43a212013-02-20 04:06:32 +00002586 usleep_range(100, 200);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002587 } while ((!data) && --loop);
2588
Bruce Allane921eb12012-11-28 09:28:37 +00002589 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002590 * count reaches 0, loading the configuration from NVM will
2591 * leave the PHY in a bad state possibly resulting in no link.
2592 */
2593 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002594 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002595
2596 /* Clear the Init Done bit for the next init event */
2597 data = er32(STATUS);
2598 data &= ~E1000_STATUS_LAN_INIT_DONE;
2599 ew32(STATUS, data);
2600}
2601
2602/**
Bruce Allane98cac42010-05-10 15:02:32 +00002603 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002604 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002605 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002606static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002607{
Bruce Allanf523d212009-10-29 13:45:45 +00002608 s32 ret_val = 0;
2609 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002610
Bruce Allan44abd5c2012-02-22 09:02:37 +00002611 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002612 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002613
Bruce Allan5f3eed62010-09-22 17:15:54 +00002614 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002615 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002616
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002617 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002618 switch (hw->mac.type) {
2619 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002620 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2621 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002622 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002623 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002624 case e1000_pch2lan:
2625 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2626 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002627 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002628 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002629 default:
2630 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002631 }
2632
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002633 /* Clear the host wakeup bit after lcd reset */
2634 if (hw->mac.type >= e1000_pchlan) {
2635 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2636 reg &= ~BM_WUC_HOST_WU_BIT;
2637 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2638 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002639
Bruce Allanf523d212009-10-29 13:45:45 +00002640 /* Configure the LCD with the extended configuration region in NVM */
2641 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2642 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002643 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002644
Bruce Allanf523d212009-10-29 13:45:45 +00002645 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002646 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002647
Bruce Allan1effb452011-02-25 06:58:03 +00002648 if (hw->mac.type == e1000_pch2lan) {
2649 /* Ungate automatic PHY configuration on non-managed 82579 */
2650 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002651 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002652 e1000_gate_hw_phy_config_ich8lan(hw, false);
2653 }
2654
2655 /* Set EEE LPI Update Timer to 200usec */
2656 ret_val = hw->phy.ops.acquire(hw);
2657 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002658 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002659 ret_val = e1000_write_emi_reg_locked(hw,
2660 I82579_LPI_UPDATE_TIMER,
2661 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002662 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002663 }
2664
Bruce Allane98cac42010-05-10 15:02:32 +00002665 return ret_val;
2666}
2667
2668/**
2669 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2670 * @hw: pointer to the HW structure
2671 *
2672 * Resets the PHY
2673 * This is a function pointer entry point called by drivers
2674 * or other shared routines.
2675 **/
2676static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2677{
2678 s32 ret_val = 0;
2679
Bruce Allan605c82b2010-09-22 17:17:01 +00002680 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2681 if ((hw->mac.type == e1000_pch2lan) &&
2682 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2683 e1000_gate_hw_phy_config_ich8lan(hw, true);
2684
Bruce Allane98cac42010-05-10 15:02:32 +00002685 ret_val = e1000e_phy_hw_reset_generic(hw);
2686 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002687 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002688
Bruce Allan5015e532012-02-08 02:55:56 +00002689 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002690}
2691
2692/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002693 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2694 * @hw: pointer to the HW structure
2695 * @active: true to enable LPLU, false to disable
2696 *
2697 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2698 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2699 * the phy speed. This function will manually set the LPLU bit and restart
2700 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2701 * since it configures the same bit.
2702 **/
2703static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2704{
Bruce Allan70806a72013-01-05 05:08:37 +00002705 s32 ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002706 u16 oem_reg;
2707
2708 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2709 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002710 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002711
2712 if (active)
2713 oem_reg |= HV_OEM_BITS_LPLU;
2714 else
2715 oem_reg &= ~HV_OEM_BITS_LPLU;
2716
Bruce Allan44abd5c2012-02-22 09:02:37 +00002717 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002718 oem_reg |= HV_OEM_BITS_RESTART_AN;
2719
Bruce Allan5015e532012-02-08 02:55:56 +00002720 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002721}
2722
2723/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002724 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2725 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002726 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002727 *
2728 * Sets the LPLU D0 state according to the active flag. When
2729 * activating LPLU this function also disables smart speed
2730 * and vice versa. LPLU will not be activated unless the
2731 * device autonegotiation advertisement meets standards of
2732 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2733 * This is a function pointer entry point only called by
2734 * PHY setup routines.
2735 **/
2736static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2737{
2738 struct e1000_phy_info *phy = &hw->phy;
2739 u32 phy_ctrl;
2740 s32 ret_val = 0;
2741 u16 data;
2742
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002743 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002744 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002745
2746 phy_ctrl = er32(PHY_CTRL);
2747
2748 if (active) {
2749 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2750 ew32(PHY_CTRL, phy_ctrl);
2751
Bruce Allan60f12922009-07-01 13:28:14 +00002752 if (phy->type != e1000_phy_igp_3)
2753 return 0;
2754
Bruce Allane921eb12012-11-28 09:28:37 +00002755 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002756 * any PHY registers
2757 */
Bruce Allan60f12922009-07-01 13:28:14 +00002758 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002759 e1000e_gig_downshift_workaround_ich8lan(hw);
2760
2761 /* When LPLU is enabled, we should disable SmartSpeed */
2762 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00002763 if (ret_val)
2764 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002765 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2766 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2767 if (ret_val)
2768 return ret_val;
2769 } else {
2770 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2771 ew32(PHY_CTRL, phy_ctrl);
2772
Bruce Allan60f12922009-07-01 13:28:14 +00002773 if (phy->type != e1000_phy_igp_3)
2774 return 0;
2775
Bruce Allane921eb12012-11-28 09:28:37 +00002776 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002777 * during Dx states where the power conservation is most
2778 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002779 * SmartSpeed, so performance is maintained.
2780 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002781 if (phy->smart_speed == e1000_smart_speed_on) {
2782 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002783 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002784 if (ret_val)
2785 return ret_val;
2786
2787 data |= IGP01E1000_PSCFR_SMART_SPEED;
2788 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002789 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002790 if (ret_val)
2791 return ret_val;
2792 } else if (phy->smart_speed == e1000_smart_speed_off) {
2793 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002794 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002795 if (ret_val)
2796 return ret_val;
2797
2798 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2799 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002800 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801 if (ret_val)
2802 return ret_val;
2803 }
2804 }
2805
2806 return 0;
2807}
2808
2809/**
2810 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2811 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002812 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813 *
2814 * Sets the LPLU D3 state according to the active flag. When
2815 * activating LPLU this function also disables smart speed
2816 * and vice versa. LPLU will not be activated unless the
2817 * device autonegotiation advertisement meets standards of
2818 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2819 * This is a function pointer entry point only called by
2820 * PHY setup routines.
2821 **/
2822static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2823{
2824 struct e1000_phy_info *phy = &hw->phy;
2825 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002826 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002827 u16 data;
2828
2829 phy_ctrl = er32(PHY_CTRL);
2830
2831 if (!active) {
2832 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2833 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002834
2835 if (phy->type != e1000_phy_igp_3)
2836 return 0;
2837
Bruce Allane921eb12012-11-28 09:28:37 +00002838 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002839 * during Dx states where the power conservation is most
2840 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002841 * SmartSpeed, so performance is maintained.
2842 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002844 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2845 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002846 if (ret_val)
2847 return ret_val;
2848
2849 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002850 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2851 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002852 if (ret_val)
2853 return ret_val;
2854 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002855 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2856 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002857 if (ret_val)
2858 return ret_val;
2859
2860 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002861 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2862 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002863 if (ret_val)
2864 return ret_val;
2865 }
2866 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2867 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2868 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2869 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2870 ew32(PHY_CTRL, phy_ctrl);
2871
Bruce Allan60f12922009-07-01 13:28:14 +00002872 if (phy->type != e1000_phy_igp_3)
2873 return 0;
2874
Bruce Allane921eb12012-11-28 09:28:37 +00002875 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002876 * any PHY registers
2877 */
Bruce Allan60f12922009-07-01 13:28:14 +00002878 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002879 e1000e_gig_downshift_workaround_ich8lan(hw);
2880
2881 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002882 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002883 if (ret_val)
2884 return ret_val;
2885
2886 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002887 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002888 }
2889
Bruce Alland7eb3382012-02-08 02:55:14 +00002890 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002891}
2892
2893/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002894 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2895 * @hw: pointer to the HW structure
2896 * @bank: pointer to the variable that returns the active bank
2897 *
2898 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002899 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002900 **/
2901static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2902{
Bruce Allane2434552008-11-21 17:02:41 -08002903 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002904 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002905 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2906 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002907 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002908 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002909
Bruce Allane2434552008-11-21 17:02:41 -08002910 switch (hw->mac.type) {
2911 case e1000_ich8lan:
2912 case e1000_ich9lan:
2913 eecd = er32(EECD);
2914 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2915 E1000_EECD_SEC1VAL_VALID_MASK) {
2916 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002917 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002918 else
2919 *bank = 0;
2920
2921 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002922 }
Bruce Allan434f1392011-12-16 00:46:54 +00002923 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002924 /* fall-thru */
2925 default:
2926 /* set bank to 0 in case flash read fails */
2927 *bank = 0;
2928
2929 /* Check bank 0 */
2930 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002931 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002932 if (ret_val)
2933 return ret_val;
2934 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2935 E1000_ICH_NVM_SIG_VALUE) {
2936 *bank = 0;
2937 return 0;
2938 }
2939
2940 /* Check bank 1 */
2941 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002942 bank1_offset,
2943 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002944 if (ret_val)
2945 return ret_val;
2946 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2947 E1000_ICH_NVM_SIG_VALUE) {
2948 *bank = 1;
2949 return 0;
2950 }
2951
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002952 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002953 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002954 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002955}
2956
2957/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2959 * @hw: pointer to the HW structure
2960 * @offset: The offset (in bytes) of the word(s) to read.
2961 * @words: Size of data to read in words
2962 * @data: Pointer to the word(s) to read at offset.
2963 *
2964 * Reads a word(s) from the NVM using the flash access registers.
2965 **/
2966static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2967 u16 *data)
2968{
2969 struct e1000_nvm_info *nvm = &hw->nvm;
2970 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2971 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002972 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002973 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974 u16 i, word;
2975
2976 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2977 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002978 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002979 ret_val = -E1000_ERR_NVM;
2980 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002981 }
2982
Bruce Allan94d81862009-11-20 23:25:26 +00002983 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002984
Bruce Allanf4187b52008-08-26 18:36:50 -07002985 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002986 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002987 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002988 bank = 0;
2989 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002990
2991 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002992 act_offset += offset;
2993
Bruce Allan148675a2009-08-07 07:41:56 +00002994 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002995 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002996 if (dev_spec->shadow_ram[offset + i].modified) {
2997 data[i] = dev_spec->shadow_ram[offset + i].value;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002998 } else {
2999 ret_val = e1000_read_flash_word_ich8lan(hw,
3000 act_offset + i,
3001 &word);
3002 if (ret_val)
3003 break;
3004 data[i] = word;
3005 }
3006 }
3007
Bruce Allan94d81862009-11-20 23:25:26 +00003008 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003009
Bruce Allane2434552008-11-21 17:02:41 -08003010out:
3011 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003012 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003013
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014 return ret_val;
3015}
3016
3017/**
3018 * e1000_flash_cycle_init_ich8lan - Initialize flash
3019 * @hw: pointer to the HW structure
3020 *
3021 * This function does initial flash setup so that a new read/write/erase cycle
3022 * can be started.
3023 **/
3024static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
3025{
3026 union ich8_hws_flash_status hsfsts;
3027 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003028
3029 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3030
3031 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00003032 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00003033 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003034 return -E1000_ERR_NVM;
3035 }
3036
3037 /* Clear FCERR and DAEL in hw status by writing 1 */
3038 hsfsts.hsf_status.flcerr = 1;
3039 hsfsts.hsf_status.dael = 1;
3040
3041 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3042
Bruce Allane921eb12012-11-28 09:28:37 +00003043 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07003044 * bit to check against, in order to start a new cycle or
3045 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08003046 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07003047 * indication whether a cycle is in progress or has been
3048 * completed.
3049 */
3050
Bruce Allan04499ec2012-04-13 00:08:31 +00003051 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00003052 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00003053 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07003054 * Begin by setting Flash Cycle Done.
3055 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003056 hsfsts.hsf_status.flcdone = 1;
3057 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3058 ret_val = 0;
3059 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00003060 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00003061
Bruce Allane921eb12012-11-28 09:28:37 +00003062 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07003063 * cycle has a chance to end before giving up.
3064 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003065 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00003066 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003067 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003068 ret_val = 0;
3069 break;
3070 }
3071 udelay(1);
3072 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00003073 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00003074 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07003075 * now set the Flash Cycle Done.
3076 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003077 hsfsts.hsf_status.flcdone = 1;
3078 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3079 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00003080 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081 }
3082 }
3083
3084 return ret_val;
3085}
3086
3087/**
3088 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
3089 * @hw: pointer to the HW structure
3090 * @timeout: maximum time to wait for completion
3091 *
3092 * This function starts a flash cycle and waits for its completion.
3093 **/
3094static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
3095{
3096 union ich8_hws_flash_ctrl hsflctl;
3097 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003098 u32 i = 0;
3099
3100 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
3101 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3102 hsflctl.hsf_ctrl.flcgo = 1;
3103 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3104
3105 /* wait till FDONE bit is set to 1 */
3106 do {
3107 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003108 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003109 break;
3110 udelay(1);
3111 } while (i++ < timeout);
3112
Bruce Allan04499ec2012-04-13 00:08:31 +00003113 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003114 return 0;
3115
Bruce Allan55920b52012-02-08 02:55:25 +00003116 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003117}
3118
3119/**
3120 * e1000_read_flash_word_ich8lan - Read word from flash
3121 * @hw: pointer to the HW structure
3122 * @offset: offset to data location
3123 * @data: pointer to the location for storing the data
3124 *
3125 * Reads the flash word at offset into data. Offset is converted
3126 * to bytes before read.
3127 **/
3128static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
3129 u16 *data)
3130{
3131 /* Must convert offset into bytes. */
3132 offset <<= 1;
3133
3134 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
3135}
3136
3137/**
Bruce Allanf4187b52008-08-26 18:36:50 -07003138 * e1000_read_flash_byte_ich8lan - Read byte from flash
3139 * @hw: pointer to the HW structure
3140 * @offset: The offset of the byte to read.
3141 * @data: Pointer to a byte to store the value read.
3142 *
3143 * Reads a single byte from the NVM using the flash access registers.
3144 **/
3145static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3146 u8 *data)
3147{
3148 s32 ret_val;
3149 u16 word = 0;
3150
3151 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
3152 if (ret_val)
3153 return ret_val;
3154
3155 *data = (u8)word;
3156
3157 return 0;
3158}
3159
3160/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003161 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
3162 * @hw: pointer to the HW structure
3163 * @offset: The offset (in bytes) of the byte or word to read.
3164 * @size: Size of data to read, 1=byte 2=word
3165 * @data: Pointer to the word to store the value read.
3166 *
3167 * Reads a byte or word from the NVM using the flash access registers.
3168 **/
3169static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3170 u8 size, u16 *data)
3171{
3172 union ich8_hws_flash_status hsfsts;
3173 union ich8_hws_flash_ctrl hsflctl;
3174 u32 flash_linear_addr;
3175 u32 flash_data = 0;
3176 s32 ret_val = -E1000_ERR_NVM;
3177 u8 count = 0;
3178
Bruce Allane80bd1d2013-05-01 01:19:46 +00003179 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003180 return -E1000_ERR_NVM;
3181
Bruce Allanf0ff4392013-02-20 04:05:39 +00003182 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3183 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003184
3185 do {
3186 udelay(1);
3187 /* Steps */
3188 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003189 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003190 break;
3191
3192 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3193 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
3194 hsflctl.hsf_ctrl.fldbcount = size - 1;
3195 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
3196 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3197
3198 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3199
Bruce Allan17e813e2013-02-20 04:06:01 +00003200 ret_val =
3201 e1000_flash_cycle_ich8lan(hw,
3202 ICH_FLASH_READ_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003203
Bruce Allane921eb12012-11-28 09:28:37 +00003204 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07003205 * and try the whole sequence a few more times, else
3206 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07003207 * least significant byte first msb to lsb
3208 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00003209 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003210 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00003211 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003212 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00003213 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003214 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003215 break;
3216 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003217 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07003218 * completely hosed, but if the error condition is
3219 * detected, it won't hurt to give it another try...
3220 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
3221 */
3222 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003223 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003224 /* Repeat for some time before giving up. */
3225 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003226 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003227 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003228 break;
3229 }
3230 }
3231 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3232
3233 return ret_val;
3234}
3235
3236/**
3237 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
3238 * @hw: pointer to the HW structure
3239 * @offset: The offset (in bytes) of the word(s) to write.
3240 * @words: Size of data to write in words
3241 * @data: Pointer to the word(s) to write at offset.
3242 *
3243 * Writes a byte or word to the NVM using the flash access registers.
3244 **/
3245static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
3246 u16 *data)
3247{
3248 struct e1000_nvm_info *nvm = &hw->nvm;
3249 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003250 u16 i;
3251
3252 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
3253 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003254 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003255 return -E1000_ERR_NVM;
3256 }
3257
Bruce Allan94d81862009-11-20 23:25:26 +00003258 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00003259
Auke Kokbc7f75f2007-09-17 12:30:59 -07003260 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00003261 dev_spec->shadow_ram[offset + i].modified = true;
3262 dev_spec->shadow_ram[offset + i].value = data[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07003263 }
3264
Bruce Allan94d81862009-11-20 23:25:26 +00003265 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00003266
Auke Kokbc7f75f2007-09-17 12:30:59 -07003267 return 0;
3268}
3269
3270/**
3271 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
3272 * @hw: pointer to the HW structure
3273 *
3274 * The NVM checksum is updated by calling the generic update_nvm_checksum,
3275 * which writes the checksum to the shadow ram. The changes in the shadow
3276 * ram are then committed to the EEPROM by processing each bank at a time
3277 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08003278 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07003279 * future writes.
3280 **/
3281static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
3282{
3283 struct e1000_nvm_info *nvm = &hw->nvm;
3284 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07003285 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003286 s32 ret_val;
3287 u16 data;
3288
3289 ret_val = e1000e_update_nvm_checksum_generic(hw);
3290 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08003291 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003292
3293 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08003294 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003295
Bruce Allan94d81862009-11-20 23:25:26 +00003296 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003297
Bruce Allane921eb12012-11-28 09:28:37 +00003298 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003299 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07003300 * is going to be written
3301 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003302 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08003303 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003304 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00003305 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003306 }
Bruce Allanf4187b52008-08-26 18:36:50 -07003307
3308 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003309 new_bank_offset = nvm->flash_bank_size;
3310 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003311 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003312 if (ret_val)
3313 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003314 } else {
3315 old_bank_offset = nvm->flash_bank_size;
3316 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003317 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003318 if (ret_val)
3319 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003320 }
3321
3322 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00003323 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07003324 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07003325 * in the shadow RAM
3326 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003327 if (dev_spec->shadow_ram[i].modified) {
3328 data = dev_spec->shadow_ram[i].value;
3329 } else {
Bruce Allane2434552008-11-21 17:02:41 -08003330 ret_val = e1000_read_flash_word_ich8lan(hw, i +
Bruce Allanf0ff4392013-02-20 04:05:39 +00003331 old_bank_offset,
3332 &data);
Bruce Allane2434552008-11-21 17:02:41 -08003333 if (ret_val)
3334 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003335 }
3336
Bruce Allane921eb12012-11-28 09:28:37 +00003337 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07003338 * (15:14) are 11b until the commit has completed.
3339 * This will allow us to write 10b which indicates the
3340 * signature is valid. We want to do this after the write
3341 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07003342 * while the write is still in progress
3343 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003344 if (i == E1000_ICH_NVM_SIG_WORD)
3345 data |= E1000_ICH_NVM_SIG_MASK;
3346
3347 /* Convert offset to bytes. */
3348 act_offset = (i + new_bank_offset) << 1;
3349
Bruce Allance43a212013-02-20 04:06:32 +00003350 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003351 /* Write the bytes to the new bank. */
3352 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3353 act_offset,
3354 (u8)data);
3355 if (ret_val)
3356 break;
3357
Bruce Allance43a212013-02-20 04:06:32 +00003358 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003360 act_offset + 1,
3361 (u8)(data >> 8));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003362 if (ret_val)
3363 break;
3364 }
3365
Bruce Allane921eb12012-11-28 09:28:37 +00003366 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07003367 * programming failed.
3368 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003369 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07003370 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003371 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00003372 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003373 }
3374
Bruce Allane921eb12012-11-28 09:28:37 +00003375 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07003376 * to 10b in word 0x13 , this can be done without an
3377 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07003378 * and we need to change bit 14 to 0b
3379 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003380 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08003381 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003382 if (ret_val)
3383 goto release;
3384
Auke Kokbc7f75f2007-09-17 12:30:59 -07003385 data &= 0xBFFF;
3386 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3387 act_offset * 2 + 1,
3388 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00003389 if (ret_val)
3390 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003391
Bruce Allane921eb12012-11-28 09:28:37 +00003392 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07003393 * its signature word (0x13) high_byte to 0b. This can be
3394 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07003395 * to 1's. We can write 1's to 0's without an erase
3396 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003397 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
3398 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003399 if (ret_val)
3400 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003401
3402 /* Great! Everything worked, we can now clear the cached entries. */
3403 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00003404 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003405 dev_spec->shadow_ram[i].value = 0xFFFF;
3406 }
3407
Bruce Allan9c5e2092010-05-10 15:00:31 +00003408release:
Bruce Allan94d81862009-11-20 23:25:26 +00003409 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003410
Bruce Allane921eb12012-11-28 09:28:37 +00003411 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07003412 * until after the next adapter reset.
3413 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00003414 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00003415 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00003416 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003417 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003418
Bruce Allane2434552008-11-21 17:02:41 -08003419out:
3420 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003421 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003422
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423 return ret_val;
3424}
3425
3426/**
3427 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3428 * @hw: pointer to the HW structure
3429 *
3430 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3431 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3432 * calculated, in which case we need to calculate the checksum and set bit 6.
3433 **/
3434static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3435{
3436 s32 ret_val;
3437 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003438 u16 word;
3439 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003440
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003441 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3442 * the checksum needs to be fixed. This bit is an indication that
3443 * the NVM was prepared by OEM software and did not calculate
3444 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003445 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003446 switch (hw->mac.type) {
3447 case e1000_pch_lpt:
3448 word = NVM_COMPAT;
3449 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3450 break;
3451 default:
3452 word = NVM_FUTURE_INIT_WORD1;
3453 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3454 break;
3455 }
3456
3457 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003458 if (ret_val)
3459 return ret_val;
3460
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003461 if (!(data & valid_csum_mask)) {
3462 data |= valid_csum_mask;
3463 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003464 if (ret_val)
3465 return ret_val;
3466 ret_val = e1000e_update_nvm_checksum(hw);
3467 if (ret_val)
3468 return ret_val;
3469 }
3470
3471 return e1000e_validate_nvm_checksum_generic(hw);
3472}
3473
3474/**
Bruce Allan4a770352008-10-01 17:18:35 -07003475 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3476 * @hw: pointer to the HW structure
3477 *
3478 * To prevent malicious write/erase of the NVM, set it to be read-only
3479 * so that the hardware ignores all write/erase cycles of the NVM via
3480 * the flash control registers. The shadow-ram copy of the NVM will
3481 * still be updated, however any updates to this copy will not stick
3482 * across driver reloads.
3483 **/
3484void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3485{
Bruce Allanca15df52009-10-26 11:23:43 +00003486 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003487 union ich8_flash_protected_range pr0;
3488 union ich8_hws_flash_status hsfsts;
3489 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003490
Bruce Allan94d81862009-11-20 23:25:26 +00003491 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003492
3493 gfpreg = er32flash(ICH_FLASH_GFPREG);
3494
3495 /* Write-protect GbE Sector of NVM */
3496 pr0.regval = er32flash(ICH_FLASH_PR0);
3497 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3498 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3499 pr0.range.wpe = true;
3500 ew32flash(ICH_FLASH_PR0, pr0.regval);
3501
Bruce Allane921eb12012-11-28 09:28:37 +00003502 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003503 * PR0 to prevent the write-protection from being lifted.
3504 * Once FLOCKDN is set, the registers protected by it cannot
3505 * be written until FLOCKDN is cleared by a hardware reset.
3506 */
3507 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3508 hsfsts.hsf_status.flockdn = true;
3509 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3510
Bruce Allan94d81862009-11-20 23:25:26 +00003511 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003512}
3513
3514/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003515 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3516 * @hw: pointer to the HW structure
3517 * @offset: The offset (in bytes) of the byte/word to read.
3518 * @size: Size of data to read, 1=byte 2=word
3519 * @data: The byte(s) to write to the NVM.
3520 *
3521 * Writes one/two bytes to the NVM using the flash access registers.
3522 **/
3523static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3524 u8 size, u16 data)
3525{
3526 union ich8_hws_flash_status hsfsts;
3527 union ich8_hws_flash_ctrl hsflctl;
3528 u32 flash_linear_addr;
3529 u32 flash_data = 0;
3530 s32 ret_val;
3531 u8 count = 0;
3532
3533 if (size < 1 || size > 2 || data > size * 0xff ||
3534 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3535 return -E1000_ERR_NVM;
3536
Bruce Allanf0ff4392013-02-20 04:05:39 +00003537 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3538 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003539
3540 do {
3541 udelay(1);
3542 /* Steps */
3543 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3544 if (ret_val)
3545 break;
3546
3547 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3548 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
Bruce Allan362e20c2013-02-20 04:05:45 +00003549 hsflctl.hsf_ctrl.fldbcount = size - 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003550 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3551 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3552
3553 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3554
3555 if (size == 1)
3556 flash_data = (u32)data & 0x00FF;
3557 else
3558 flash_data = (u32)data;
3559
3560 ew32flash(ICH_FLASH_FDATA0, flash_data);
3561
Bruce Allane921eb12012-11-28 09:28:37 +00003562 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003563 * and try the whole sequence a few more times else done
3564 */
Bruce Allan17e813e2013-02-20 04:06:01 +00003565 ret_val =
3566 e1000_flash_cycle_ich8lan(hw,
3567 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003568 if (!ret_val)
3569 break;
3570
Bruce Allane921eb12012-11-28 09:28:37 +00003571 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003572 * completely hosed, but if the error condition
3573 * is detected, it won't hurt to give it another
3574 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3575 */
3576 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003577 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003578 /* Repeat for some time before giving up. */
3579 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003580 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003581 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003582 break;
3583 }
3584 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3585
3586 return ret_val;
3587}
3588
3589/**
3590 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3591 * @hw: pointer to the HW structure
3592 * @offset: The index of the byte to read.
3593 * @data: The byte to write to the NVM.
3594 *
3595 * Writes a single byte to the NVM using the flash access registers.
3596 **/
3597static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3598 u8 data)
3599{
3600 u16 word = (u16)data;
3601
3602 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3603}
3604
3605/**
3606 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3607 * @hw: pointer to the HW structure
3608 * @offset: The offset of the byte to write.
3609 * @byte: The byte to write to the NVM.
3610 *
3611 * Writes a single byte to the NVM using the flash access registers.
3612 * Goes through a retry algorithm before giving up.
3613 **/
3614static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3615 u32 offset, u8 byte)
3616{
3617 s32 ret_val;
3618 u16 program_retries;
3619
3620 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3621 if (!ret_val)
3622 return ret_val;
3623
3624 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003625 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Bruce Allance43a212013-02-20 04:06:32 +00003626 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003627 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3628 if (!ret_val)
3629 break;
3630 }
3631 if (program_retries == 100)
3632 return -E1000_ERR_NVM;
3633
3634 return 0;
3635}
3636
3637/**
3638 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3639 * @hw: pointer to the HW structure
3640 * @bank: 0 for first bank, 1 for second bank, etc.
3641 *
3642 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3643 * bank N is 4096 * N + flash_reg_addr.
3644 **/
3645static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3646{
3647 struct e1000_nvm_info *nvm = &hw->nvm;
3648 union ich8_hws_flash_status hsfsts;
3649 union ich8_hws_flash_ctrl hsflctl;
3650 u32 flash_linear_addr;
3651 /* bank size is in 16bit words - adjust to bytes */
3652 u32 flash_bank_size = nvm->flash_bank_size * 2;
3653 s32 ret_val;
3654 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003655 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656
3657 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3658
Bruce Allane921eb12012-11-28 09:28:37 +00003659 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003660 * register
3661 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003662 * consecutive sectors. The start index for the nth Hw sector
3663 * can be calculated as = bank * 4096 + n * 256
3664 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3665 * The start index for the nth Hw sector can be calculated
3666 * as = bank * 4096
3667 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3668 * (ich9 only, otherwise error condition)
3669 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3670 */
3671 switch (hsfsts.hsf_status.berasesz) {
3672 case 0:
3673 /* Hw sector size 256 */
3674 sector_size = ICH_FLASH_SEG_SIZE_256;
3675 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3676 break;
3677 case 1:
3678 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003679 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003680 break;
3681 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003682 sector_size = ICH_FLASH_SEG_SIZE_8K;
3683 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003684 break;
3685 case 3:
3686 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003687 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003688 break;
3689 default:
3690 return -E1000_ERR_NVM;
3691 }
3692
3693 /* Start with the base address, then add the sector offset. */
3694 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003695 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696
Bruce Allan53aa82d2013-02-20 04:06:06 +00003697 for (j = 0; j < iteration; j++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003698 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00003699 u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
3700
Auke Kokbc7f75f2007-09-17 12:30:59 -07003701 /* Steps */
3702 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3703 if (ret_val)
3704 return ret_val;
3705
Bruce Allane921eb12012-11-28 09:28:37 +00003706 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003707 * Cycle field in hw flash control
3708 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003709 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3710 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3711 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3712
Bruce Allane921eb12012-11-28 09:28:37 +00003713 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003714 * block into Flash Linear address field in Flash
3715 * Address.
3716 */
3717 flash_linear_addr += (j * sector_size);
3718 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3719
Bruce Allan17e813e2013-02-20 04:06:01 +00003720 ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003721 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003722 break;
3723
Bruce Allane921eb12012-11-28 09:28:37 +00003724 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003725 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003726 * a few more times else Done
3727 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003728 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003729 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003730 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003731 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003732 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003733 return ret_val;
3734 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3735 }
3736
3737 return 0;
3738}
3739
3740/**
3741 * e1000_valid_led_default_ich8lan - Set the default LED settings
3742 * @hw: pointer to the HW structure
3743 * @data: Pointer to the LED settings
3744 *
3745 * Reads the LED default settings from the NVM to data. If the NVM LED
3746 * settings is all 0's or F's, set the LED default to a valid LED default
3747 * setting.
3748 **/
3749static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3750{
3751 s32 ret_val;
3752
3753 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3754 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003755 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003756 return ret_val;
3757 }
3758
Bruce Allane5fe2542013-02-20 04:06:27 +00003759 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003760 *data = ID_LED_DEFAULT_ICH8LAN;
3761
3762 return 0;
3763}
3764
3765/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003766 * e1000_id_led_init_pchlan - store LED configurations
3767 * @hw: pointer to the HW structure
3768 *
3769 * PCH does not control LEDs via the LEDCTL register, rather it uses
3770 * the PHY LED configuration register.
3771 *
3772 * PCH also does not have an "always on" or "always off" mode which
3773 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003774 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003775 * use "link_up" mode. The LEDs will still ID on request if there is no
3776 * link based on logic in e1000_led_[on|off]_pchlan().
3777 **/
3778static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3779{
3780 struct e1000_mac_info *mac = &hw->mac;
3781 s32 ret_val;
3782 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3783 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3784 u16 data, i, temp, shift;
3785
3786 /* Get default ID LED modes */
3787 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3788 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003789 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003790
3791 mac->ledctl_default = er32(LEDCTL);
3792 mac->ledctl_mode1 = mac->ledctl_default;
3793 mac->ledctl_mode2 = mac->ledctl_default;
3794
3795 for (i = 0; i < 4; i++) {
3796 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3797 shift = (i * 5);
3798 switch (temp) {
3799 case ID_LED_ON1_DEF2:
3800 case ID_LED_ON1_ON2:
3801 case ID_LED_ON1_OFF2:
3802 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3803 mac->ledctl_mode1 |= (ledctl_on << shift);
3804 break;
3805 case ID_LED_OFF1_DEF2:
3806 case ID_LED_OFF1_ON2:
3807 case ID_LED_OFF1_OFF2:
3808 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3809 mac->ledctl_mode1 |= (ledctl_off << shift);
3810 break;
3811 default:
3812 /* Do nothing */
3813 break;
3814 }
3815 switch (temp) {
3816 case ID_LED_DEF1_ON2:
3817 case ID_LED_ON1_ON2:
3818 case ID_LED_OFF1_ON2:
3819 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3820 mac->ledctl_mode2 |= (ledctl_on << shift);
3821 break;
3822 case ID_LED_DEF1_OFF2:
3823 case ID_LED_ON1_OFF2:
3824 case ID_LED_OFF1_OFF2:
3825 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3826 mac->ledctl_mode2 |= (ledctl_off << shift);
3827 break;
3828 default:
3829 /* Do nothing */
3830 break;
3831 }
3832 }
3833
Bruce Allan5015e532012-02-08 02:55:56 +00003834 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003835}
3836
3837/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003838 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3839 * @hw: pointer to the HW structure
3840 *
3841 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3842 * register, so the the bus width is hard coded.
3843 **/
3844static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3845{
3846 struct e1000_bus_info *bus = &hw->bus;
3847 s32 ret_val;
3848
3849 ret_val = e1000e_get_bus_info_pcie(hw);
3850
Bruce Allane921eb12012-11-28 09:28:37 +00003851 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003852 * a configuration space, but do not contain
3853 * PCI Express Capability registers, so bus width
3854 * must be hardcoded.
3855 */
3856 if (bus->width == e1000_bus_width_unknown)
3857 bus->width = e1000_bus_width_pcie_x1;
3858
3859 return ret_val;
3860}
3861
3862/**
3863 * e1000_reset_hw_ich8lan - Reset the hardware
3864 * @hw: pointer to the HW structure
3865 *
3866 * Does a full reset of the hardware which includes a reset of the PHY and
3867 * MAC.
3868 **/
3869static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3870{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003871 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003872 u16 kum_cfg;
3873 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003874 s32 ret_val;
3875
Bruce Allane921eb12012-11-28 09:28:37 +00003876 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003877 * on the last TLP read/write transaction when MAC is reset.
3878 */
3879 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003880 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003881 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003882
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003883 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003884 ew32(IMC, 0xffffffff);
3885
Bruce Allane921eb12012-11-28 09:28:37 +00003886 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003887 * any pending transactions to complete before we hit the MAC
3888 * with the global reset.
3889 */
3890 ew32(RCTL, 0);
3891 ew32(TCTL, E1000_TCTL_PSP);
3892 e1e_flush();
3893
Bruce Allan1bba4382011-03-19 00:27:20 +00003894 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003895
3896 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3897 if (hw->mac.type == e1000_ich8lan) {
3898 /* Set Tx and Rx buffer allocation to 8k apiece. */
3899 ew32(PBA, E1000_PBA_8K);
3900 /* Set Packet Buffer Size to 16k. */
3901 ew32(PBS, E1000_PBS_16K);
3902 }
3903
Bruce Allan1d5846b2009-10-29 13:46:05 +00003904 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003905 /* Save the NVM K1 bit setting */
3906 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003907 if (ret_val)
3908 return ret_val;
3909
Bruce Allan62bc8132012-03-20 03:47:57 +00003910 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003911 dev_spec->nvm_k1_enabled = true;
3912 else
3913 dev_spec->nvm_k1_enabled = false;
3914 }
3915
Auke Kokbc7f75f2007-09-17 12:30:59 -07003916 ctrl = er32(CTRL);
3917
Bruce Allan44abd5c2012-02-22 09:02:37 +00003918 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003919 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003920 * time to make sure the interface between MAC and the
3921 * external PHY is reset.
3922 */
3923 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003924
Bruce Allane921eb12012-11-28 09:28:37 +00003925 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003926 * non-managed 82579
3927 */
3928 if ((hw->mac.type == e1000_pch2lan) &&
3929 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3930 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003931 }
3932 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003933 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003934 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003935 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003936 msleep(20);
3937
Bruce Allan62bc8132012-03-20 03:47:57 +00003938 /* Set Phy Config Counter to 50msec */
3939 if (hw->mac.type == e1000_pch2lan) {
3940 reg = er32(FEXTNVM3);
3941 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3942 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3943 ew32(FEXTNVM3, reg);
3944 }
3945
Bruce Allanfc0c7762009-07-01 13:27:55 +00003946 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003947 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003948
Bruce Allane98cac42010-05-10 15:02:32 +00003949 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003950 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003951 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003952 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003953
Bruce Allane98cac42010-05-10 15:02:32 +00003954 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003955 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003956 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003957 }
Bruce Allane98cac42010-05-10 15:02:32 +00003958
Bruce Allane921eb12012-11-28 09:28:37 +00003959 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003960 * will be detected as a CRC error and be dropped rather than show up
3961 * as a bad packet to the DMA engine.
3962 */
3963 if (hw->mac.type == e1000_pchlan)
3964 ew32(CRC_OFFSET, 0x65656565);
3965
Auke Kokbc7f75f2007-09-17 12:30:59 -07003966 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003967 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003968
Bruce Allan62bc8132012-03-20 03:47:57 +00003969 reg = er32(KABGTXD);
3970 reg |= E1000_KABGTXD_BGSQLBIAS;
3971 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003972
Bruce Allan5015e532012-02-08 02:55:56 +00003973 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003974}
3975
3976/**
3977 * e1000_init_hw_ich8lan - Initialize the hardware
3978 * @hw: pointer to the HW structure
3979 *
3980 * Prepares the hardware for transmit and receive by doing the following:
3981 * - initialize hardware bits
3982 * - initialize LED identification
3983 * - setup receive address registers
3984 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003985 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003986 * - clear statistics
3987 **/
3988static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3989{
3990 struct e1000_mac_info *mac = &hw->mac;
3991 u32 ctrl_ext, txdctl, snoop;
3992 s32 ret_val;
3993 u16 i;
3994
3995 e1000_initialize_hw_bits_ich8lan(hw);
3996
3997 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003998 ret_val = mac->ops.id_led_init(hw);
Bruce Allan33550ce2013-02-20 04:06:16 +00003999 /* An error is not fatal and we should not stop init due to this */
Bruce Allande39b752009-11-20 23:27:59 +00004000 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004001 e_dbg("Error initializing identification LED\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004002
4003 /* Setup the receive address. */
4004 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
4005
4006 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004007 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008 for (i = 0; i < mac->mta_reg_count; i++)
4009 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
4010
Bruce Allane921eb12012-11-28 09:28:37 +00004011 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00004012 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00004013 * Reset the phy after disabling host wakeup to reset the Rx buffer.
4014 */
4015 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00004016 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
4017 i &= ~BM_WUC_HOST_WU_BIT;
4018 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00004019 ret_val = e1000_phy_hw_reset_ich8lan(hw);
4020 if (ret_val)
4021 return ret_val;
4022 }
4023
Auke Kokbc7f75f2007-09-17 12:30:59 -07004024 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00004025 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004026
4027 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004028 txdctl = er32(TXDCTL(0));
Bruce Allanf0ff4392013-02-20 04:05:39 +00004029 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
4030 E1000_TXDCTL_FULL_TX_DESC_WB);
4031 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
4032 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004033 ew32(TXDCTL(0), txdctl);
4034 txdctl = er32(TXDCTL(1));
Bruce Allanf0ff4392013-02-20 04:05:39 +00004035 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
4036 E1000_TXDCTL_FULL_TX_DESC_WB);
4037 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
4038 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004039 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004040
Bruce Allane921eb12012-11-28 09:28:37 +00004041 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07004042 * By default, we should use snoop behavior.
4043 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004044 if (mac->type == e1000_ich8lan)
4045 snoop = PCIE_ICH8_SNOOP_ALL;
4046 else
Bruce Allan53aa82d2013-02-20 04:06:06 +00004047 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004048 e1000e_set_pcie_no_snoop(hw, snoop);
4049
4050 ctrl_ext = er32(CTRL_EXT);
4051 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
4052 ew32(CTRL_EXT, ctrl_ext);
4053
Bruce Allane921eb12012-11-28 09:28:37 +00004054 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07004055 * important that we do this after we have tried to establish link
4056 * because the symbol error count will increment wildly if there
4057 * is no link.
4058 */
4059 e1000_clear_hw_cntrs_ich8lan(hw);
4060
Bruce Allane561a702012-02-08 02:55:46 +00004061 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004062}
Bruce Allanfc830b72013-02-20 04:06:11 +00004063
Auke Kokbc7f75f2007-09-17 12:30:59 -07004064/**
4065 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
4066 * @hw: pointer to the HW structure
4067 *
4068 * Sets/Clears required hardware bits necessary for correctly setting up the
4069 * hardware for transmit and receive.
4070 **/
4071static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
4072{
4073 u32 reg;
4074
4075 /* Extended Device Control */
4076 reg = er32(CTRL_EXT);
4077 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00004078 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
4079 if (hw->mac.type >= e1000_pchlan)
4080 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004081 ew32(CTRL_EXT, reg);
4082
4083 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004084 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004085 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004086 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004087
4088 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004089 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004090 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004091 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004092
4093 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004094 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004095 if (hw->mac.type == e1000_ich8lan)
4096 reg |= (1 << 28) | (1 << 29);
4097 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004098 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004099
4100 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004101 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004102 if (er32(TCTL) & E1000_TCTL_MULR)
4103 reg &= ~(1 << 28);
4104 else
4105 reg |= (1 << 28);
4106 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004107 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004108
4109 /* Device Status */
4110 if (hw->mac.type == e1000_ich8lan) {
4111 reg = er32(STATUS);
4112 reg &= ~(1 << 31);
4113 ew32(STATUS, reg);
4114 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00004115
Bruce Allane921eb12012-11-28 09:28:37 +00004116 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00004117 * traffic, just disable the nfs filtering capability
4118 */
4119 reg = er32(RFCTL);
4120 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00004121
Bruce Allane921eb12012-11-28 09:28:37 +00004122 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00004123 * IPv6 headers can hang the Rx.
4124 */
4125 if (hw->mac.type == e1000_ich8lan)
4126 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00004127 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00004128
4129 /* Enable ECC on Lynxpoint */
4130 if (hw->mac.type == e1000_pch_lpt) {
4131 reg = er32(PBECCSTS);
4132 reg |= E1000_PBECCSTS_ECC_ENABLE;
4133 ew32(PBECCSTS, reg);
4134
4135 reg = er32(CTRL);
4136 reg |= E1000_CTRL_MEHE;
4137 ew32(CTRL, reg);
4138 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004139}
4140
4141/**
4142 * e1000_setup_link_ich8lan - Setup flow control and link settings
4143 * @hw: pointer to the HW structure
4144 *
4145 * Determines which flow control settings to use, then configures flow
4146 * control. Calls the appropriate media-specific link configuration
4147 * function. Assuming the adapter has a valid link partner, a valid link
4148 * should be established. Assumes the hardware has previously been reset
4149 * and the transmitter and receiver are not enabled.
4150 **/
4151static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
4152{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004153 s32 ret_val;
4154
Bruce Allan44abd5c2012-02-22 09:02:37 +00004155 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004156 return 0;
4157
Bruce Allane921eb12012-11-28 09:28:37 +00004158 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07004159 * the default flow control setting, so we explicitly
4160 * set it to full.
4161 */
Bruce Allan37289d92009-06-02 11:29:37 +00004162 if (hw->fc.requested_mode == e1000_fc_default) {
4163 /* Workaround h/w hang when Tx flow control enabled */
4164 if (hw->mac.type == e1000_pchlan)
4165 hw->fc.requested_mode = e1000_fc_rx_pause;
4166 else
4167 hw->fc.requested_mode = e1000_fc_full;
4168 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004169
Bruce Allane921eb12012-11-28 09:28:37 +00004170 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08004171 * on the link partner's capabilities, we may or may not use this mode.
4172 */
4173 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004174
Bruce Allan17e813e2013-02-20 04:06:01 +00004175 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004176
4177 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00004178 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004179 if (ret_val)
4180 return ret_val;
4181
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004182 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00004183 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004184 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004185 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004186 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00004187 ew32(FCRTV_PCH, hw->fc.refresh_time);
4188
Bruce Allan482fed82011-01-06 14:29:49 +00004189 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
4190 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00004191 if (ret_val)
4192 return ret_val;
4193 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004194
4195 return e1000e_set_fc_watermarks(hw);
4196}
4197
4198/**
4199 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
4200 * @hw: pointer to the HW structure
4201 *
4202 * Configures the kumeran interface to the PHY to wait the appropriate time
4203 * when polling the PHY, then call the generic setup_copper_link to finish
4204 * configuring the copper link.
4205 **/
4206static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
4207{
4208 u32 ctrl;
4209 s32 ret_val;
4210 u16 reg_data;
4211
4212 ctrl = er32(CTRL);
4213 ctrl |= E1000_CTRL_SLU;
4214 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
4215 ew32(CTRL, ctrl);
4216
Bruce Allane921eb12012-11-28 09:28:37 +00004217 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07004218 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07004219 * this fixes erroneous timeouts at 10Mbps.
4220 */
Bruce Allan07818952009-12-08 07:28:01 +00004221 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 if (ret_val)
4223 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00004224 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00004225 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004226 if (ret_val)
4227 return ret_val;
4228 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00004229 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00004230 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004231 if (ret_val)
4232 return ret_val;
4233
Bruce Allana4f58f52009-06-02 11:29:18 +00004234 switch (hw->phy.type) {
4235 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004236 ret_val = e1000e_copper_link_setup_igp(hw);
4237 if (ret_val)
4238 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00004239 break;
4240 case e1000_phy_bm:
4241 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004242 ret_val = e1000e_copper_link_setup_m88(hw);
4243 if (ret_val)
4244 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00004245 break;
4246 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00004247 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00004248 ret_val = e1000_copper_link_setup_82577(hw);
4249 if (ret_val)
4250 return ret_val;
4251 break;
4252 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00004253 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004254 if (ret_val)
4255 return ret_val;
4256
4257 reg_data &= ~IFE_PMC_AUTO_MDIX;
4258
4259 switch (hw->phy.mdix) {
4260 case 1:
4261 reg_data &= ~IFE_PMC_FORCE_MDIX;
4262 break;
4263 case 2:
4264 reg_data |= IFE_PMC_FORCE_MDIX;
4265 break;
4266 case 0:
4267 default:
4268 reg_data |= IFE_PMC_AUTO_MDIX;
4269 break;
4270 }
Bruce Allan482fed82011-01-06 14:29:49 +00004271 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004272 if (ret_val)
4273 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00004274 break;
4275 default:
4276 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004277 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00004278
Auke Kokbc7f75f2007-09-17 12:30:59 -07004279 return e1000e_setup_copper_link(hw);
4280}
4281
4282/**
Bruce Allanea8179a2013-03-06 09:02:47 +00004283 * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
4284 * @hw: pointer to the HW structure
4285 *
4286 * Calls the PHY specific link setup function and then calls the
4287 * generic setup_copper_link to finish configuring the link for
4288 * Lynxpoint PCH devices
4289 **/
4290static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
4291{
4292 u32 ctrl;
4293 s32 ret_val;
4294
4295 ctrl = er32(CTRL);
4296 ctrl |= E1000_CTRL_SLU;
4297 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
4298 ew32(CTRL, ctrl);
4299
4300 ret_val = e1000_copper_link_setup_82577(hw);
4301 if (ret_val)
4302 return ret_val;
4303
4304 return e1000e_setup_copper_link(hw);
4305}
4306
4307/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004308 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
4309 * @hw: pointer to the HW structure
4310 * @speed: pointer to store current link speed
4311 * @duplex: pointer to store the current link duplex
4312 *
Bruce Allanad680762008-03-28 09:15:03 -07004313 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07004314 * information and then calls the Kumeran lock loss workaround for links at
4315 * gigabit speeds.
4316 **/
4317static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
4318 u16 *duplex)
4319{
4320 s32 ret_val;
4321
4322 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
4323 if (ret_val)
4324 return ret_val;
4325
4326 if ((hw->mac.type == e1000_ich8lan) &&
Bruce Allane5fe2542013-02-20 04:06:27 +00004327 (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004328 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
4329 }
4330
4331 return ret_val;
4332}
4333
4334/**
4335 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
4336 * @hw: pointer to the HW structure
4337 *
4338 * Work-around for 82566 Kumeran PCS lock loss:
4339 * On link status change (i.e. PCI reset, speed change) and link is up and
4340 * speed is gigabit-
4341 * 0) if workaround is optionally disabled do nothing
4342 * 1) wait 1ms for Kumeran link to come up
4343 * 2) check Kumeran Diagnostic register PCS lock loss bit
4344 * 3) if not set the link is locked (all is good), otherwise...
4345 * 4) reset the PHY
4346 * 5) repeat up to 10 times
4347 * Note: this is only called for IGP3 copper when speed is 1gb.
4348 **/
4349static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
4350{
4351 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4352 u32 phy_ctrl;
4353 s32 ret_val;
4354 u16 i, data;
4355 bool link;
4356
4357 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
4358 return 0;
4359
Bruce Allane921eb12012-11-28 09:28:37 +00004360 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004361 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07004362 * stability
4363 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004364 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
4365 if (!link)
4366 return 0;
4367
4368 for (i = 0; i < 10; i++) {
4369 /* read once to clear */
4370 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4371 if (ret_val)
4372 return ret_val;
4373 /* and again to get new status */
4374 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4375 if (ret_val)
4376 return ret_val;
4377
4378 /* check for PCS lock */
4379 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4380 return 0;
4381
4382 /* Issue PHY reset */
4383 e1000_phy_hw_reset(hw);
4384 mdelay(5);
4385 }
4386 /* Disable GigE link negotiation */
4387 phy_ctrl = er32(PHY_CTRL);
4388 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
4389 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4390 ew32(PHY_CTRL, phy_ctrl);
4391
Bruce Allane921eb12012-11-28 09:28:37 +00004392 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07004393 * any PHY registers
4394 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004395 e1000e_gig_downshift_workaround_ich8lan(hw);
4396
4397 /* unable to acquire PCS lock */
4398 return -E1000_ERR_PHY;
4399}
4400
4401/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00004402 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004403 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08004404 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004405 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00004406 * If ICH8, set the current Kumeran workaround state (enabled - true
4407 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07004408 **/
4409void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004410 bool state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004411{
4412 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4413
4414 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004415 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004416 return;
4417 }
4418
4419 dev_spec->kmrn_lock_loss_workaround_enabled = state;
4420}
4421
4422/**
4423 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
4424 * @hw: pointer to the HW structure
4425 *
4426 * Workaround for 82566 power-down on D3 entry:
4427 * 1) disable gigabit link
4428 * 2) write VR power-down enable
4429 * 3) read it back
4430 * Continue if successful, else issue LCD reset and repeat
4431 **/
4432void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
4433{
4434 u32 reg;
4435 u16 data;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004436 u8 retry = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004437
4438 if (hw->phy.type != e1000_phy_igp_3)
4439 return;
4440
4441 /* Try the workaround twice (if needed) */
4442 do {
4443 /* Disable link */
4444 reg = er32(PHY_CTRL);
4445 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4446 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4447 ew32(PHY_CTRL, reg);
4448
Bruce Allane921eb12012-11-28 09:28:37 +00004449 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07004450 * accessing any PHY registers
4451 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004452 if (hw->mac.type == e1000_ich8lan)
4453 e1000e_gig_downshift_workaround_ich8lan(hw);
4454
4455 /* Write VR power-down enable */
4456 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4457 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4458 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4459
4460 /* Read it back and test */
4461 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4462 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4463 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4464 break;
4465
4466 /* Issue PHY reset and repeat at most one more time */
4467 reg = er32(CTRL);
4468 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4469 retry++;
4470 } while (retry);
4471}
4472
4473/**
4474 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4475 * @hw: pointer to the HW structure
4476 *
4477 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004478 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004479 * 1) Set Kumeran Near-end loopback
4480 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004481 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004482 **/
4483void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4484{
4485 s32 ret_val;
4486 u16 reg_data;
4487
Bruce Allan462d5992011-09-30 08:07:11 +00004488 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004489 return;
4490
4491 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004492 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004493 if (ret_val)
4494 return;
4495 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4496 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004497 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004498 if (ret_val)
4499 return;
4500 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00004501 e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004502}
4503
4504/**
Bruce Allan99730e42011-05-13 07:19:48 +00004505 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004506 * @hw: pointer to the HW structure
4507 *
4508 * During S0 to Sx transition, it is possible the link remains at gig
4509 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004510 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4511 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4512 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4513 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004514 * Parts that support (and are linked to a partner which support) EEE in
4515 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4516 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004517 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004518void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004519{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004520 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004521 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004522 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004523
Bruce Allan17f085d2010-06-17 18:59:48 +00004524 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004525 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allane08f6262013-02-20 03:06:34 +00004526
Bruce Allan2fbe4522012-04-19 03:21:47 +00004527 if (hw->phy.type == e1000_phy_i217) {
Bruce Allane08f6262013-02-20 03:06:34 +00004528 u16 phy_reg, device_id = hw->adapter->pdev->device;
4529
4530 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
Bruce Allan91a3d822013-06-29 01:15:16 +00004531 (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
4532 (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
4533 (device_id == E1000_DEV_ID_PCH_I218_V3)) {
Bruce Allane08f6262013-02-20 03:06:34 +00004534 u32 fextnvm6 = er32(FEXTNVM6);
4535
4536 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
4537 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004538
4539 ret_val = hw->phy.ops.acquire(hw);
4540 if (ret_val)
4541 goto out;
4542
4543 if (!dev_spec->eee_disable) {
4544 u16 eee_advert;
4545
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004546 ret_val =
4547 e1000_read_emi_reg_locked(hw,
4548 I217_EEE_ADVERTISEMENT,
4549 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004550 if (ret_val)
4551 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004552
Bruce Allane921eb12012-11-28 09:28:37 +00004553 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004554 * EEE and 100Full is advertised on both ends of the
4555 * link.
4556 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004557 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004558 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004559 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004560 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4561 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4562 E1000_PHY_CTRL_NOND0A_LPLU);
4563 }
4564
Bruce Allane921eb12012-11-28 09:28:37 +00004565 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004566 * when the system is going into Sx and no manageability engine
4567 * is present, the driver must configure proxy to reset only on
4568 * power good. LPI (Low Power Idle) state must also reset only
4569 * on power good, as well as the MTA (Multicast table array).
4570 * The SMBus release must also be disabled on LCD reset.
4571 */
4572 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00004573 /* Enable proxy to reset only on power good. */
4574 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4575 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4576 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4577
Bruce Allane921eb12012-11-28 09:28:37 +00004578 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004579 * power good.
4580 */
4581 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004582 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004583 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4584
4585 /* Disable the SMB release on LCD reset. */
4586 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004587 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004588 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4589 }
4590
Bruce Allane921eb12012-11-28 09:28:37 +00004591 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004592 * Support
4593 */
4594 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004595 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004596 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4597
4598release:
4599 hw->phy.ops.release(hw);
4600 }
4601out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004602 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004603
Bruce Allan462d5992011-09-30 08:07:11 +00004604 if (hw->mac.type == e1000_ich8lan)
4605 e1000e_gig_downshift_workaround_ich8lan(hw);
4606
Bruce Allan8395ae82010-09-22 17:15:08 +00004607 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004608 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004609
4610 /* Reset PHY to activate OEM bits on 82577/8 */
4611 if (hw->mac.type == e1000_pchlan)
4612 e1000e_phy_hw_reset_generic(hw);
4613
Bruce Allan8395ae82010-09-22 17:15:08 +00004614 ret_val = hw->phy.ops.acquire(hw);
4615 if (ret_val)
4616 return;
4617 e1000_write_smbus_addr(hw);
4618 hw->phy.ops.release(hw);
4619 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004620}
4621
4622/**
Bruce Allan99730e42011-05-13 07:19:48 +00004623 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4624 * @hw: pointer to the HW structure
4625 *
4626 * During Sx to S0 transitions on non-managed devices or managed devices
4627 * on which PHY resets are not blocked, if the PHY registers cannot be
4628 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4629 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004630 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004631 **/
4632void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4633{
Bruce Allan90b82982011-12-16 00:46:33 +00004634 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004635
Bruce Allancb17aab2012-04-13 03:16:22 +00004636 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004637 return;
4638
Bruce Allancb17aab2012-04-13 03:16:22 +00004639 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004640 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004641 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004642 return;
4643 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004644
Bruce Allane921eb12012-11-28 09:28:37 +00004645 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004646 * is transitioning from Sx and no manageability engine is present
4647 * configure SMBus to restore on reset, disable proxy, and enable
4648 * the reset on MTA (Multicast table array).
4649 */
4650 if (hw->phy.type == e1000_phy_i217) {
4651 u16 phy_reg;
4652
4653 ret_val = hw->phy.ops.acquire(hw);
4654 if (ret_val) {
4655 e_dbg("Failed to setup iRST\n");
4656 return;
4657 }
4658
4659 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004660 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004661 * is present
4662 */
4663 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4664 if (ret_val)
4665 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004666 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004667 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4668
4669 /* Disable Proxy */
4670 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4671 }
4672 /* Enable reset on MTA */
4673 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4674 if (ret_val)
4675 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004676 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004677 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4678release:
4679 if (ret_val)
4680 e_dbg("Error %d in resume workarounds\n", ret_val);
4681 hw->phy.ops.release(hw);
4682 }
Bruce Allan99730e42011-05-13 07:19:48 +00004683}
4684
4685/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004686 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4687 * @hw: pointer to the HW structure
4688 *
4689 * Return the LED back to the default configuration.
4690 **/
4691static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4692{
4693 if (hw->phy.type == e1000_phy_ife)
4694 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4695
4696 ew32(LEDCTL, hw->mac.ledctl_default);
4697 return 0;
4698}
4699
4700/**
Auke Kok489815c2008-02-21 15:11:07 -08004701 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004702 * @hw: pointer to the HW structure
4703 *
Auke Kok489815c2008-02-21 15:11:07 -08004704 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004705 **/
4706static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4707{
4708 if (hw->phy.type == e1000_phy_ife)
4709 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4710 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4711
4712 ew32(LEDCTL, hw->mac.ledctl_mode2);
4713 return 0;
4714}
4715
4716/**
Auke Kok489815c2008-02-21 15:11:07 -08004717 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004718 * @hw: pointer to the HW structure
4719 *
Auke Kok489815c2008-02-21 15:11:07 -08004720 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004721 **/
4722static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4723{
4724 if (hw->phy.type == e1000_phy_ife)
4725 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004726 (IFE_PSCL_PROBE_MODE |
4727 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004728
4729 ew32(LEDCTL, hw->mac.ledctl_mode1);
4730 return 0;
4731}
4732
4733/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004734 * e1000_setup_led_pchlan - Configures SW controllable LED
4735 * @hw: pointer to the HW structure
4736 *
4737 * This prepares the SW controllable LED for use.
4738 **/
4739static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4740{
Bruce Allan482fed82011-01-06 14:29:49 +00004741 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004742}
4743
4744/**
4745 * e1000_cleanup_led_pchlan - Restore the default LED operation
4746 * @hw: pointer to the HW structure
4747 *
4748 * Return the LED back to the default configuration.
4749 **/
4750static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4751{
Bruce Allan482fed82011-01-06 14:29:49 +00004752 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004753}
4754
4755/**
4756 * e1000_led_on_pchlan - Turn LEDs on
4757 * @hw: pointer to the HW structure
4758 *
4759 * Turn on the LEDs.
4760 **/
4761static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4762{
4763 u16 data = (u16)hw->mac.ledctl_mode2;
4764 u32 i, led;
4765
Bruce Allane921eb12012-11-28 09:28:37 +00004766 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004767 * for each LED that's mode is "link_up" in ledctl_mode2.
4768 */
4769 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4770 for (i = 0; i < 3; i++) {
4771 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4772 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4773 E1000_LEDCTL_MODE_LINK_UP)
4774 continue;
4775 if (led & E1000_PHY_LED0_IVRT)
4776 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4777 else
4778 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4779 }
4780 }
4781
Bruce Allan482fed82011-01-06 14:29:49 +00004782 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004783}
4784
4785/**
4786 * e1000_led_off_pchlan - Turn LEDs off
4787 * @hw: pointer to the HW structure
4788 *
4789 * Turn off the LEDs.
4790 **/
4791static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4792{
4793 u16 data = (u16)hw->mac.ledctl_mode1;
4794 u32 i, led;
4795
Bruce Allane921eb12012-11-28 09:28:37 +00004796 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004797 * for each LED that's mode is "link_up" in ledctl_mode1.
4798 */
4799 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4800 for (i = 0; i < 3; i++) {
4801 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4802 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4803 E1000_LEDCTL_MODE_LINK_UP)
4804 continue;
4805 if (led & E1000_PHY_LED0_IVRT)
4806 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4807 else
4808 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4809 }
4810 }
4811
Bruce Allan482fed82011-01-06 14:29:49 +00004812 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004813}
4814
4815/**
Bruce Allane98cac42010-05-10 15:02:32 +00004816 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004817 * @hw: pointer to the HW structure
4818 *
Bruce Allane98cac42010-05-10 15:02:32 +00004819 * Read appropriate register for the config done bit for completion status
4820 * and configure the PHY through s/w for EEPROM-less parts.
4821 *
4822 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4823 * config done bit, so only an error is logged and continues. If we were
4824 * to return with error, EEPROM-less silicon would not be able to be reset
4825 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004826 **/
4827static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4828{
Bruce Allane98cac42010-05-10 15:02:32 +00004829 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004830 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004831 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004832
Bruce Allanfe908492013-01-05 08:06:14 +00004833 e1000e_get_cfg_done_generic(hw);
Bruce Allanf4187b52008-08-26 18:36:50 -07004834
Bruce Allane98cac42010-05-10 15:02:32 +00004835 /* Wait for indication from h/w that it has completed basic config */
4836 if (hw->mac.type >= e1000_ich10lan) {
4837 e1000_lan_init_done_ich8lan(hw);
4838 } else {
4839 ret_val = e1000e_get_auto_rd_done(hw);
4840 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004841 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004842 * return with an error. This can happen in situations
4843 * where there is no eeprom and prevents getting link.
4844 */
4845 e_dbg("Auto Read Done did not complete\n");
4846 ret_val = 0;
4847 }
4848 }
4849
4850 /* Clear PHY Reset Asserted bit */
4851 status = er32(STATUS);
4852 if (status & E1000_STATUS_PHYRA)
4853 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4854 else
4855 e_dbg("PHY Reset Asserted not set - needs delay\n");
4856
Bruce Allanf4187b52008-08-26 18:36:50 -07004857 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004858 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004859 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004860 (hw->phy.type == e1000_phy_igp_3)) {
4861 e1000e_phy_init_script_igp3(hw);
4862 }
4863 } else {
4864 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4865 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004866 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004867 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004868 }
4869 }
4870
Bruce Allane98cac42010-05-10 15:02:32 +00004871 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004872}
4873
4874/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004875 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4876 * @hw: pointer to the HW structure
4877 *
4878 * In the case of a PHY power down to save power, or to turn off link during a
4879 * driver unload, or wake on lan is not enabled, remove the link.
4880 **/
4881static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4882{
4883 /* If the management interface is not enabled, then power down */
4884 if (!(hw->mac.ops.check_mng_mode(hw) ||
4885 hw->phy.ops.check_reset_block(hw)))
4886 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004887}
4888
4889/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004890 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4891 * @hw: pointer to the HW structure
4892 *
4893 * Clears hardware counters specific to the silicon family and calls
4894 * clear_hw_cntrs_generic to clear all general purpose counters.
4895 **/
4896static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4897{
Bruce Allana4f58f52009-06-02 11:29:18 +00004898 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004899 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004900
4901 e1000e_clear_hw_cntrs_base(hw);
4902
Bruce Allan99673d92009-11-20 23:27:21 +00004903 er32(ALGNERRC);
4904 er32(RXERRC);
4905 er32(TNCRS);
4906 er32(CEXTERR);
4907 er32(TSCTC);
4908 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004909
Bruce Allan99673d92009-11-20 23:27:21 +00004910 er32(MGTPRC);
4911 er32(MGTPDC);
4912 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004913
Bruce Allan99673d92009-11-20 23:27:21 +00004914 er32(IAC);
4915 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004916
Bruce Allana4f58f52009-06-02 11:29:18 +00004917 /* Clear PHY statistics registers */
4918 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004919 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004920 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004921 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004922 ret_val = hw->phy.ops.acquire(hw);
4923 if (ret_val)
4924 return;
4925 ret_val = hw->phy.ops.set_page(hw,
4926 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4927 if (ret_val)
4928 goto release;
4929 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4930 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4931 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4932 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4933 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4934 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4935 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4936 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4937 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4938 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4939 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4940 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4941 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4942 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4943release:
4944 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004945 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004946}
4947
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004948static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004949 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004950 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004951 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004952 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4953 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004954 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004955 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004956 /* led_on dependent on mac type */
4957 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004958 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004959 .reset_hw = e1000_reset_hw_ich8lan,
4960 .init_hw = e1000_init_hw_ich8lan,
4961 .setup_link = e1000_setup_link_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004962 .setup_physical_interface = e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004963 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004964 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004965 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004966};
4967
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004968static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004969 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004970 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004971 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004972 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004973 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004974 .read_reg = e1000e_read_phy_reg_igp,
4975 .release = e1000_release_swflag_ich8lan,
4976 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004977 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4978 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004979 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004980};
4981
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004982static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004983 .acquire = e1000_acquire_nvm_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004984 .read = e1000_read_nvm_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004985 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004986 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004987 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004988 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004989 .validate = e1000_validate_nvm_checksum_ich8lan,
4990 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004991};
4992
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004993const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004994 .mac = e1000_ich8lan,
4995 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004996 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004997 | FLAG_HAS_CTRLEXT_ON_LOAD
4998 | FLAG_HAS_AMT
4999 | FLAG_HAS_FLASH
5000 | FLAG_APME_IN_WUC,
5001 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00005002 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005003 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005004 .mac_ops = &ich8_mac_ops,
5005 .phy_ops = &ich8_phy_ops,
5006 .nvm_ops = &ich8_nvm_ops,
5007};
5008
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005009const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005010 .mac = e1000_ich9lan,
5011 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005012 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07005013 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07005014 | FLAG_HAS_CTRLEXT_ON_LOAD
5015 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07005016 | FLAG_HAS_FLASH
5017 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00005018 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00005019 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005020 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021 .mac_ops = &ich8_mac_ops,
5022 .phy_ops = &ich8_phy_ops,
5023 .nvm_ops = &ich8_nvm_ops,
5024};
5025
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005026const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07005027 .mac = e1000_ich10lan,
5028 .flags = FLAG_HAS_JUMBO_FRAMES
5029 | FLAG_IS_ICH
5030 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07005031 | FLAG_HAS_CTRLEXT_ON_LOAD
5032 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07005033 | FLAG_HAS_FLASH
5034 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00005035 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00005036 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07005037 .get_variants = e1000_get_variants_ich8lan,
5038 .mac_ops = &ich8_mac_ops,
5039 .phy_ops = &ich8_phy_ops,
5040 .nvm_ops = &ich8_nvm_ops,
5041};
Bruce Allana4f58f52009-06-02 11:29:18 +00005042
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005043const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00005044 .mac = e1000_pchlan,
5045 .flags = FLAG_IS_ICH
5046 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00005047 | FLAG_HAS_CTRLEXT_ON_LOAD
5048 | FLAG_HAS_AMT
5049 | FLAG_HAS_FLASH
5050 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00005051 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00005052 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00005053 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00005054 .pba = 26,
5055 .max_hw_frame_size = 4096,
5056 .get_variants = e1000_get_variants_ich8lan,
5057 .mac_ops = &ich8_mac_ops,
5058 .phy_ops = &ich8_phy_ops,
5059 .nvm_ops = &ich8_nvm_ops,
5060};
Bruce Alland3738bb2010-06-16 13:27:28 +00005061
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005062const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00005063 .mac = e1000_pch2lan,
5064 .flags = FLAG_IS_ICH
5065 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00005066 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00005067 | FLAG_HAS_CTRLEXT_ON_LOAD
5068 | FLAG_HAS_AMT
5069 | FLAG_HAS_FLASH
5070 | FLAG_HAS_JUMBO_FRAMES
5071 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00005072 .flags2 = FLAG2_HAS_PHY_STATS
5073 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00005074 .pba = 26,
Bruce Allanc3d2dbf2013-01-09 01:20:46 +00005075 .max_hw_frame_size = 9018,
Bruce Alland3738bb2010-06-16 13:27:28 +00005076 .get_variants = e1000_get_variants_ich8lan,
5077 .mac_ops = &ich8_mac_ops,
5078 .phy_ops = &ich8_phy_ops,
5079 .nvm_ops = &ich8_nvm_ops,
5080};
Bruce Allan2fbe4522012-04-19 03:21:47 +00005081
5082const struct e1000_info e1000_pch_lpt_info = {
5083 .mac = e1000_pch_lpt,
5084 .flags = FLAG_IS_ICH
5085 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00005086 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00005087 | FLAG_HAS_CTRLEXT_ON_LOAD
5088 | FLAG_HAS_AMT
5089 | FLAG_HAS_FLASH
5090 | FLAG_HAS_JUMBO_FRAMES
5091 | FLAG_APME_IN_WUC,
5092 .flags2 = FLAG2_HAS_PHY_STATS
5093 | FLAG2_HAS_EEE,
5094 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00005095 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00005096 .get_variants = e1000_get_variants_ich8lan,
5097 .mac_ops = &ich8_mac_ops,
5098 .phy_ops = &ich8_phy_ops,
5099 .nvm_ops = &ich8_nvm_ops,
5100};