blob: 8894ab8ed6bd82de2c0f720939d31a906096a12c [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);
David Ertmanb3e5bf12014-05-06 03:50:17 +0000142static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
143static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
144static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000145static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000146static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
David Ertman74f350e2014-02-22 03:15:17 +0000147static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force);
Bruce Allanea8179a2013-03-06 09:02:47 +0000148static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
David Ertman74f350e2014-02-22 03:15:17 +0000149static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700150
151static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
152{
153 return readw(hw->flash_address + reg);
154}
155
156static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
157{
158 return readl(hw->flash_address + reg);
159}
160
161static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
162{
163 writew(val, hw->flash_address + reg);
164}
165
166static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
167{
168 writel(val, hw->flash_address + reg);
169}
170
171#define er16flash(reg) __er16flash(hw, (reg))
172#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000173#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
174#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700175
Bruce Allancb17aab2012-04-13 03:16:22 +0000176/**
177 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
178 * @hw: pointer to the HW structure
179 *
180 * Test access to the PHY registers by reading the PHY ID registers. If
181 * the PHY ID is already known (e.g. resume path) compare it with known ID,
182 * otherwise assume the read PHY ID is correct if it is valid.
183 *
184 * Assumes the sw/fw/hw semaphore is already acquired.
185 **/
186static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000187{
Bruce Allana52359b2012-07-14 04:23:58 +0000188 u16 phy_reg = 0;
189 u32 phy_id = 0;
David Ertman2c982622014-05-01 02:19:03 +0000190 s32 ret_val = 0;
Bruce Allana52359b2012-07-14 04:23:58 +0000191 u16 retry_count;
Bruce Allan16b095a2013-06-29 07:42:39 +0000192 u32 mac_reg = 0;
Bruce Allan99730e42011-05-13 07:19:48 +0000193
Bruce Allana52359b2012-07-14 04:23:58 +0000194 for (retry_count = 0; retry_count < 2; retry_count++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000195 ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000196 if (ret_val || (phy_reg == 0xFFFF))
197 continue;
198 phy_id = (u32)(phy_reg << 16);
199
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000200 ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000201 if (ret_val || (phy_reg == 0xFFFF)) {
202 phy_id = 0;
203 continue;
204 }
205 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
206 break;
207 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000208
Bruce Allancb17aab2012-04-13 03:16:22 +0000209 if (hw->phy.id) {
210 if (hw->phy.id == phy_id)
Bruce Allan16b095a2013-06-29 07:42:39 +0000211 goto out;
Bruce Allana52359b2012-07-14 04:23:58 +0000212 } else if (phy_id) {
213 hw->phy.id = phy_id;
214 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allan16b095a2013-06-29 07:42:39 +0000215 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000216 }
217
Bruce Allane921eb12012-11-28 09:28:37 +0000218 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000219 * set slow mode and try to get the PHY id again.
220 */
David Ertman2c982622014-05-01 02:19:03 +0000221 if (hw->mac.type < e1000_pch_lpt) {
222 hw->phy.ops.release(hw);
223 ret_val = e1000_set_mdio_slow_mode_hv(hw);
224 if (!ret_val)
225 ret_val = e1000e_get_phy_id(hw);
226 hw->phy.ops.acquire(hw);
227 }
Bruce Allana52359b2012-07-14 04:23:58 +0000228
Bruce Allan16b095a2013-06-29 07:42:39 +0000229 if (ret_val)
230 return false;
231out:
232 if (hw->mac.type == e1000_pch_lpt) {
233 /* Unforce SMBus mode in PHY */
234 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
235 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
236 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
237
238 /* Unforce SMBus mode in MAC */
239 mac_reg = er32(CTRL_EXT);
240 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
241 ew32(CTRL_EXT, mac_reg);
242 }
243
244 return true;
Bruce Allancb17aab2012-04-13 03:16:22 +0000245}
246
247/**
David Ertman74f350e2014-02-22 03:15:17 +0000248 * e1000_toggle_lanphypc_pch_lpt - toggle the LANPHYPC pin value
249 * @hw: pointer to the HW structure
250 *
251 * Toggling the LANPHYPC pin value fully power-cycles the PHY and is
252 * used to reset the PHY to a quiescent state when necessary.
253 **/
254static void e1000_toggle_lanphypc_pch_lpt(struct e1000_hw *hw)
255{
256 u32 mac_reg;
257
258 /* Set Phy Config Counter to 50msec */
259 mac_reg = er32(FEXTNVM3);
260 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
261 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
262 ew32(FEXTNVM3, mac_reg);
263
264 /* Toggle LANPHYPC Value bit */
265 mac_reg = er32(CTRL);
266 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
267 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
268 ew32(CTRL, mac_reg);
269 e1e_flush();
270 usleep_range(10, 20);
271 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
272 ew32(CTRL, mac_reg);
273 e1e_flush();
274
275 if (hw->mac.type < e1000_pch_lpt) {
276 msleep(50);
277 } else {
278 u16 count = 20;
279
280 do {
281 usleep_range(5000, 10000);
282 } while (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LPCD) && count--);
283
284 msleep(30);
285 }
286}
287
288/**
Bruce Allancb17aab2012-04-13 03:16:22 +0000289 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
290 * @hw: pointer to the HW structure
291 *
292 * Workarounds/flow necessary for PHY initialization during driver load
293 * and resume paths.
294 **/
295static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
296{
David Ertmanf7235ef2014-01-23 06:29:13 +0000297 struct e1000_adapter *adapter = hw->adapter;
Bruce Allancb17aab2012-04-13 03:16:22 +0000298 u32 mac_reg, fwsm = er32(FWSM);
299 s32 ret_val;
300
Bruce Allan6e928b72012-12-12 04:45:51 +0000301 /* Gate automatic PHY configuration by hardware on managed and
302 * non-managed 82579 and newer adapters.
303 */
304 e1000_gate_hw_phy_config_ich8lan(hw, true);
305
David Ertman74f350e2014-02-22 03:15:17 +0000306 /* It is not possible to be certain of the current state of ULP
307 * so forcibly disable it.
308 */
309 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_unknown;
310 e1000_disable_ulp_lpt_lp(hw, true);
311
Bruce Allancb17aab2012-04-13 03:16:22 +0000312 ret_val = hw->phy.ops.acquire(hw);
313 if (ret_val) {
314 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000315 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000316 }
317
Bruce Allane921eb12012-11-28 09:28:37 +0000318 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000319 * inaccessible and resetting the PHY is not blocked, toggle the
320 * LANPHYPC Value bit to force the interconnect to PCIe mode.
321 */
322 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000323 case e1000_pch_lpt:
324 if (e1000_phy_is_accessible_pchlan(hw))
325 break;
326
Bruce Allane921eb12012-11-28 09:28:37 +0000327 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000328 * forcing MAC to SMBus mode first.
329 */
330 mac_reg = er32(CTRL_EXT);
331 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
332 ew32(CTRL_EXT, mac_reg);
333
Bruce Allan16b095a2013-06-29 07:42:39 +0000334 /* Wait 50 milliseconds for MAC to finish any retries
335 * that it might be trying to perform from previous
336 * attempts to acknowledge any phy read requests.
337 */
338 msleep(50);
339
Bruce Allan2fbe4522012-04-19 03:21:47 +0000340 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000341 case e1000_pch2lan:
Bruce Allan16b095a2013-06-29 07:42:39 +0000342 if (e1000_phy_is_accessible_pchlan(hw))
Bruce Allancb17aab2012-04-13 03:16:22 +0000343 break;
344
345 /* fall-through */
346 case e1000_pchlan:
347 if ((hw->mac.type == e1000_pchlan) &&
348 (fwsm & E1000_ICH_FWSM_FW_VALID))
349 break;
350
351 if (hw->phy.ops.check_reset_block(hw)) {
352 e_dbg("Required LANPHYPC toggle blocked by ME\n");
Bruce Allan16b095a2013-06-29 07:42:39 +0000353 ret_val = -E1000_ERR_PHY;
Bruce Allancb17aab2012-04-13 03:16:22 +0000354 break;
355 }
356
Bruce Allancb17aab2012-04-13 03:16:22 +0000357 /* Toggle LANPHYPC Value bit */
David Ertman74f350e2014-02-22 03:15:17 +0000358 e1000_toggle_lanphypc_pch_lpt(hw);
359 if (hw->mac.type >= e1000_pch_lpt) {
Bruce Allan16b095a2013-06-29 07:42:39 +0000360 if (e1000_phy_is_accessible_pchlan(hw))
361 break;
362
363 /* Toggling LANPHYPC brings the PHY out of SMBus mode
364 * so ensure that the MAC is also out of SMBus mode
365 */
366 mac_reg = er32(CTRL_EXT);
367 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
368 ew32(CTRL_EXT, mac_reg);
369
370 if (e1000_phy_is_accessible_pchlan(hw))
371 break;
372
373 ret_val = -E1000_ERR_PHY;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000374 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000375 break;
376 default:
377 break;
378 }
379
380 hw->phy.ops.release(hw);
Bruce Allan16b095a2013-06-29 07:42:39 +0000381 if (!ret_val) {
David Ertmanf7235ef2014-01-23 06:29:13 +0000382
383 /* Check to see if able to reset PHY. Print error if not */
384 if (hw->phy.ops.check_reset_block(hw)) {
385 e_err("Reset blocked by ME\n");
386 goto out;
387 }
388
Bruce Allan16b095a2013-06-29 07:42:39 +0000389 /* Reset the PHY before any access to it. Doing so, ensures
390 * that the PHY is in a known good state before we read/write
391 * PHY registers. The generic reset is sufficient here,
392 * because we haven't determined the PHY type yet.
393 */
394 ret_val = e1000e_phy_hw_reset_generic(hw);
David Ertmanf7235ef2014-01-23 06:29:13 +0000395 if (ret_val)
396 goto out;
397
398 /* On a successful reset, possibly need to wait for the PHY
399 * to quiesce to an accessible state before returning control
400 * to the calling function. If the PHY does not quiesce, then
401 * return E1000E_BLK_PHY_RESET, as this is the condition that
402 * the PHY is in.
403 */
404 ret_val = hw->phy.ops.check_reset_block(hw);
405 if (ret_val)
406 e_err("ME blocked access to PHY after reset\n");
Bruce Allan16b095a2013-06-29 07:42:39 +0000407 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000408
Bruce Allan6e928b72012-12-12 04:45:51 +0000409out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000410 /* Ungate automatic PHY configuration on non-managed 82579 */
411 if ((hw->mac.type == e1000_pch2lan) &&
412 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
413 usleep_range(10000, 20000);
414 e1000_gate_hw_phy_config_ich8lan(hw, false);
415 }
416
417 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000418}
419
Auke Kokbc7f75f2007-09-17 12:30:59 -0700420/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000421 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
422 * @hw: pointer to the HW structure
423 *
424 * Initialize family-specific PHY parameters and function pointers.
425 **/
426static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
427{
428 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan70806a72013-01-05 05:08:37 +0000429 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000430
Bruce Allane80bd1d2013-05-01 01:19:46 +0000431 phy->addr = 1;
432 phy->reset_delay_us = 100;
Bruce Allana4f58f52009-06-02 11:29:18 +0000433
Bruce Allane80bd1d2013-05-01 01:19:46 +0000434 phy->ops.set_page = e1000_set_page_igp;
435 phy->ops.read_reg = e1000_read_phy_reg_hv;
436 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
437 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
438 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
439 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
440 phy->ops.write_reg = e1000_write_phy_reg_hv;
441 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
442 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
443 phy->ops.power_up = e1000_power_up_phy_copper;
444 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
445 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allana4f58f52009-06-02 11:29:18 +0000446
447 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000448
449 ret_val = e1000_init_phy_workarounds_pchlan(hw);
450 if (ret_val)
451 return ret_val;
452
453 if (phy->id == e1000_phy_unknown)
454 switch (hw->mac.type) {
455 default:
456 ret_val = e1000e_get_phy_id(hw);
457 if (ret_val)
458 return ret_val;
459 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
460 break;
461 /* fall-through */
462 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000463 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000464 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000465 * set slow mode and try to get the PHY id again.
466 */
467 ret_val = e1000_set_mdio_slow_mode_hv(hw);
468 if (ret_val)
469 return ret_val;
470 ret_val = e1000e_get_phy_id(hw);
471 if (ret_val)
472 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000473 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000474 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000475 phy->type = e1000e_get_phy_type_from_id(phy->id);
476
Bruce Allan0be84012009-12-02 17:03:18 +0000477 switch (phy->type) {
478 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000479 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000480 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000481 phy->ops.check_polarity = e1000_check_polarity_82577;
482 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000483 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000484 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000485 phy->ops.get_info = e1000_get_phy_info_82577;
486 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000487 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000488 case e1000_phy_82578:
489 phy->ops.check_polarity = e1000_check_polarity_m88;
490 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
491 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
492 phy->ops.get_info = e1000e_get_phy_info_m88;
493 break;
494 default:
495 ret_val = -E1000_ERR_PHY;
496 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000497 }
498
499 return ret_val;
500}
501
502/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700503 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
504 * @hw: pointer to the HW structure
505 *
506 * Initialize family-specific PHY parameters and function pointers.
507 **/
508static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
509{
510 struct e1000_phy_info *phy = &hw->phy;
511 s32 ret_val;
512 u16 i = 0;
513
Bruce Allane80bd1d2013-05-01 01:19:46 +0000514 phy->addr = 1;
515 phy->reset_delay_us = 100;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700516
Bruce Allane80bd1d2013-05-01 01:19:46 +0000517 phy->ops.power_up = e1000_power_up_phy_copper;
518 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allan17f208d2009-12-01 15:47:22 +0000519
Bruce Allane921eb12012-11-28 09:28:37 +0000520 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700521 * we'll set BM func pointers and try again
522 */
523 ret_val = e1000e_determine_phy_address(hw);
524 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000525 phy->ops.write_reg = e1000e_write_phy_reg_bm;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000526 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700527 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000528 if (ret_val) {
529 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700530 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000531 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700532 }
533
Auke Kokbc7f75f2007-09-17 12:30:59 -0700534 phy->id = 0;
535 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
536 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000537 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700538 ret_val = e1000e_get_phy_id(hw);
539 if (ret_val)
540 return ret_val;
541 }
542
543 /* Verify phy id */
544 switch (phy->id) {
545 case IGP03E1000_E_PHY_ID:
546 phy->type = e1000_phy_igp_3;
547 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000548 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
549 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000550 phy->ops.get_info = e1000e_get_phy_info_igp;
551 phy->ops.check_polarity = e1000_check_polarity_igp;
552 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700553 break;
554 case IFE_E_PHY_ID:
555 case IFE_PLUS_E_PHY_ID:
556 case IFE_C_E_PHY_ID:
557 phy->type = e1000_phy_ife;
558 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000559 phy->ops.get_info = e1000_get_phy_info_ife;
560 phy->ops.check_polarity = e1000_check_polarity_ife;
561 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700563 case BME1000_E_PHY_ID:
564 phy->type = e1000_phy_bm;
565 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000566 phy->ops.read_reg = e1000e_read_phy_reg_bm;
567 phy->ops.write_reg = e1000e_write_phy_reg_bm;
568 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000569 phy->ops.get_info = e1000e_get_phy_info_m88;
570 phy->ops.check_polarity = e1000_check_polarity_m88;
571 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700572 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700573 default:
574 return -E1000_ERR_PHY;
575 break;
576 }
577
578 return 0;
579}
580
581/**
582 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
583 * @hw: pointer to the HW structure
584 *
585 * Initialize family-specific NVM parameters and function
586 * pointers.
587 **/
588static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
589{
590 struct e1000_nvm_info *nvm = &hw->nvm;
591 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000592 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700593 u16 i;
594
Bruce Allanad680762008-03-28 09:15:03 -0700595 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700596 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000597 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700598 return -E1000_ERR_CONFIG;
599 }
600
601 nvm->type = e1000_nvm_flash_sw;
602
603 gfpreg = er32flash(ICH_FLASH_GFPREG);
604
Bruce Allane921eb12012-11-28 09:28:37 +0000605 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700606 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700607 * the overall size.
608 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700609 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
610 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
611
612 /* flash_base_addr is byte-aligned */
613 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
614
Bruce Allane921eb12012-11-28 09:28:37 +0000615 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700616 * size represents two separate NVM banks.
617 */
Bruce Allanf0ff4392013-02-20 04:05:39 +0000618 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
619 << FLASH_SECTOR_ADDR_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700620 nvm->flash_bank_size /= 2;
621 /* Adjust to word count */
622 nvm->flash_bank_size /= sizeof(u16);
623
624 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
625
626 /* Clear shadow ram */
627 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000628 dev_spec->shadow_ram[i].modified = false;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000629 dev_spec->shadow_ram[i].value = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630 }
631
632 return 0;
633}
634
635/**
636 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
637 * @hw: pointer to the HW structure
638 *
639 * Initialize family-specific MAC parameters and function
640 * pointers.
641 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000642static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644 struct e1000_mac_info *mac = &hw->mac;
645
646 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700647 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648
649 /* Set mta register count */
650 mac->mta_reg_count = 32;
651 /* Set rar entry count */
652 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
653 if (mac->type == e1000_ich8lan)
654 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000655 /* FWSM register */
656 mac->has_fwsm = true;
657 /* ARC subsystem not supported */
658 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000659 /* Adaptive IFS supported */
660 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700661
Bruce Allan2fbe4522012-04-19 03:21:47 +0000662 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000663 switch (mac->type) {
664 case e1000_ich8lan:
665 case e1000_ich9lan:
666 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000667 /* check management mode */
668 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000669 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000670 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000671 /* blink LED */
672 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000673 /* setup LED */
674 mac->ops.setup_led = e1000e_setup_led_generic;
675 /* cleanup LED */
676 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
677 /* turn on/off LED */
678 mac->ops.led_on = e1000_led_on_ich8lan;
679 mac->ops.led_off = e1000_led_off_ich8lan;
680 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000681 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000682 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
683 mac->ops.rar_set = e1000_rar_set_pch2lan;
684 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000685 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000686 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000687 /* check management mode */
688 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000689 /* ID LED init */
690 mac->ops.id_led_init = e1000_id_led_init_pchlan;
691 /* setup LED */
692 mac->ops.setup_led = e1000_setup_led_pchlan;
693 /* cleanup LED */
694 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
695 /* turn on/off LED */
696 mac->ops.led_on = e1000_led_on_pchlan;
697 mac->ops.led_off = e1000_led_off_pchlan;
698 break;
699 default:
700 break;
701 }
702
Bruce Allan2fbe4522012-04-19 03:21:47 +0000703 if (mac->type == e1000_pch_lpt) {
704 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
705 mac->ops.rar_set = e1000_rar_set_pch_lpt;
Bruce Allanea8179a2013-03-06 09:02:47 +0000706 mac->ops.setup_physical_interface =
707 e1000_setup_copper_link_pch_lpt;
David Ertmanb3e5bf12014-05-06 03:50:17 +0000708 mac->ops.rar_get_count = e1000_rar_get_count_pch_lpt;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000709 }
710
Auke Kokbc7f75f2007-09-17 12:30:59 -0700711 /* Enable PCS Lock-loss workaround for ICH8 */
712 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000713 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700714
715 return 0;
716}
717
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000718/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000719 * __e1000_access_emi_reg_locked - Read/write EMI register
720 * @hw: pointer to the HW structure
721 * @addr: EMI address to program
722 * @data: pointer to value to read/write from/to the EMI address
723 * @read: boolean flag to indicate read or write
724 *
725 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
726 **/
727static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
728 u16 *data, bool read)
729{
Bruce Allan70806a72013-01-05 05:08:37 +0000730 s32 ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000731
732 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
733 if (ret_val)
734 return ret_val;
735
736 if (read)
737 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
738 else
739 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
740
741 return ret_val;
742}
743
744/**
745 * e1000_read_emi_reg_locked - Read Extended Management Interface register
746 * @hw: pointer to the HW structure
747 * @addr: EMI address to program
748 * @data: value to be read from the EMI address
749 *
750 * Assumes the SW/FW/HW Semaphore is already acquired.
751 **/
Bruce Allan203e4152012-12-05 08:40:59 +0000752s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000753{
754 return __e1000_access_emi_reg_locked(hw, addr, data, true);
755}
756
757/**
758 * e1000_write_emi_reg_locked - Write Extended Management Interface register
759 * @hw: pointer to the HW structure
760 * @addr: EMI address to program
761 * @data: value to be written to the EMI address
762 *
763 * Assumes the SW/FW/HW Semaphore is already acquired.
764 **/
Bruce Alland495bcb2013-03-20 07:23:11 +0000765s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000766{
767 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
768}
769
770/**
Bruce Allane52997f2010-06-16 13:27:49 +0000771 * e1000_set_eee_pchlan - Enable/disable EEE support
772 * @hw: pointer to the HW structure
773 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000774 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
775 * the link and the EEE capabilities of the link partner. The LPI Control
776 * register bits will remain set only if/when link is up.
David Ertmana03206e2014-01-24 23:07:48 +0000777 *
778 * EEE LPI must not be asserted earlier than one second after link is up.
779 * On 82579, EEE LPI should not be enabled until such time otherwise there
780 * can be link issues with some switches. Other devices can have EEE LPI
781 * enabled immediately upon link up since they have a timer in hardware which
782 * prevents LPI from being asserted too early.
Bruce Allane52997f2010-06-16 13:27:49 +0000783 **/
David Ertmana03206e2014-01-24 23:07:48 +0000784s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
Bruce Allane52997f2010-06-16 13:27:49 +0000785{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000786 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000787 s32 ret_val;
Bruce Alland495bcb2013-03-20 07:23:11 +0000788 u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
Bruce Allane52997f2010-06-16 13:27:49 +0000789
Bruce Alland495bcb2013-03-20 07:23:11 +0000790 switch (hw->phy.type) {
791 case e1000_phy_82579:
792 lpa = I82579_EEE_LP_ABILITY;
793 pcs_status = I82579_EEE_PCS_STATUS;
794 adv_addr = I82579_EEE_ADVERTISEMENT;
795 break;
796 case e1000_phy_i217:
797 lpa = I217_EEE_LP_ABILITY;
798 pcs_status = I217_EEE_PCS_STATUS;
799 adv_addr = I217_EEE_ADVERTISEMENT;
800 break;
801 default:
Bruce Allan5015e532012-02-08 02:55:56 +0000802 return 0;
Bruce Alland495bcb2013-03-20 07:23:11 +0000803 }
Bruce Allane52997f2010-06-16 13:27:49 +0000804
Bruce Allan3d4d5752012-12-05 06:26:08 +0000805 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000806 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000807 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000808
Bruce Allan3d4d5752012-12-05 06:26:08 +0000809 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000810 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000811 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000812
Bruce Allan3d4d5752012-12-05 06:26:08 +0000813 /* Clear bits that enable EEE in various speeds */
814 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
815
816 /* Enable EEE if not disabled by user */
817 if (!dev_spec->eee_disable) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000818 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000819 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000820 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000821 if (ret_val)
822 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000823
Bruce Alland495bcb2013-03-20 07:23:11 +0000824 /* Read EEE advertisement */
825 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
826 if (ret_val)
827 goto release;
828
Bruce Allan3d4d5752012-12-05 06:26:08 +0000829 /* Enable EEE only for speeds in which the link partner is
Bruce Alland495bcb2013-03-20 07:23:11 +0000830 * EEE capable and for which we advertise EEE.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000831 */
Bruce Alland495bcb2013-03-20 07:23:11 +0000832 if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000833 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
834
Bruce Alland495bcb2013-03-20 07:23:11 +0000835 if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000836 e1e_rphy_locked(hw, MII_LPA, &data);
837 if (data & LPA_100FULL)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000838 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
839 else
840 /* EEE is not supported in 100Half, so ignore
841 * partner's EEE in 100 ability if full-duplex
842 * is not advertised.
843 */
844 dev_spec->eee_lp_ability &=
845 ~I82579_EEE_100_SUPPORTED;
846 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000847 }
848
David Ertman7142a552014-05-01 01:22:26 +0000849 if (hw->phy.type == e1000_phy_82579) {
850 ret_val = e1000_read_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
851 &data);
852 if (ret_val)
853 goto release;
854
855 data &= ~I82579_LPI_100_PLL_SHUT;
856 ret_val = e1000_write_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
857 data);
858 }
859
Bruce Alland495bcb2013-03-20 07:23:11 +0000860 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
861 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
862 if (ret_val)
863 goto release;
864
Bruce Allan3d4d5752012-12-05 06:26:08 +0000865 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
866release:
867 hw->phy.ops.release(hw);
868
869 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000870}
871
872/**
Bruce Allane08f6262013-02-20 03:06:34 +0000873 * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
874 * @hw: pointer to the HW structure
875 * @link: link up bool flag
876 *
877 * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
878 * preventing further DMA write requests. Workaround the issue by disabling
879 * the de-assertion of the clock request when in 1Gpbs mode.
Bruce Allane0236ad2013-06-21 09:07:13 +0000880 * Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
881 * speeds in order to avoid Tx hangs.
Bruce Allane08f6262013-02-20 03:06:34 +0000882 **/
883static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
884{
885 u32 fextnvm6 = er32(FEXTNVM6);
Bruce Allane0236ad2013-06-21 09:07:13 +0000886 u32 status = er32(STATUS);
Bruce Allane08f6262013-02-20 03:06:34 +0000887 s32 ret_val = 0;
Bruce Allane0236ad2013-06-21 09:07:13 +0000888 u16 reg;
Bruce Allane08f6262013-02-20 03:06:34 +0000889
Bruce Allane0236ad2013-06-21 09:07:13 +0000890 if (link && (status & E1000_STATUS_SPEED_1000)) {
Bruce Allane08f6262013-02-20 03:06:34 +0000891 ret_val = hw->phy.ops.acquire(hw);
892 if (ret_val)
893 return ret_val;
894
895 ret_val =
896 e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000897 &reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000898 if (ret_val)
899 goto release;
900
901 ret_val =
902 e1000e_write_kmrn_reg_locked(hw,
903 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000904 reg &
Bruce Allane08f6262013-02-20 03:06:34 +0000905 ~E1000_KMRNCTRLSTA_K1_ENABLE);
906 if (ret_val)
907 goto release;
908
909 usleep_range(10, 20);
910
911 ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
912
913 ret_val =
914 e1000e_write_kmrn_reg_locked(hw,
915 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000916 reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000917release:
918 hw->phy.ops.release(hw);
919 } else {
920 /* clear FEXTNVM6 bit 8 on link down or 10/100 */
Bruce Allane0236ad2013-06-21 09:07:13 +0000921 fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
922
923 if (!link || ((status & E1000_STATUS_SPEED_100) &&
924 (status & E1000_STATUS_FD)))
925 goto update_fextnvm6;
926
927 ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
928 if (ret_val)
929 return ret_val;
930
931 /* Clear link status transmit timeout */
932 reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
933
934 if (status & E1000_STATUS_SPEED_100) {
935 /* Set inband Tx timeout to 5x10us for 100Half */
936 reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
937
938 /* Do not extend the K1 entry latency for 100Half */
939 fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
940 } else {
941 /* Set inband Tx timeout to 50x10us for 10Full/Half */
942 reg |= 50 <<
943 I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
944
945 /* Extend the K1 entry latency for 10 Mbps */
946 fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
947 }
948
949 ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
950 if (ret_val)
951 return ret_val;
952
953update_fextnvm6:
954 ew32(FEXTNVM6, fextnvm6);
Bruce Allane08f6262013-02-20 03:06:34 +0000955 }
956
957 return ret_val;
958}
959
960/**
Bruce Allancf8fb732013-03-06 09:03:02 +0000961 * e1000_platform_pm_pch_lpt - Set platform power management values
962 * @hw: pointer to the HW structure
963 * @link: bool indicating link status
964 *
965 * Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
966 * GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
967 * when link is up (which must not exceed the maximum latency supported
968 * by the platform), otherwise specify there is no LTR requirement.
969 * Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
970 * latencies in the LTR Extended Capability Structure in the PCIe Extended
971 * Capability register set, on this device LTR is set by writing the
972 * equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
973 * set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
974 * message to the PMC.
975 **/
976static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
977{
978 u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
979 link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
980 u16 lat_enc = 0; /* latency encoded */
981
982 if (link) {
983 u16 speed, duplex, scale = 0;
984 u16 max_snoop, max_nosnoop;
985 u16 max_ltr_enc; /* max LTR latency encoded */
986 s64 lat_ns; /* latency (ns) */
987 s64 value;
988 u32 rxa;
989
990 if (!hw->adapter->max_frame_size) {
991 e_dbg("max_frame_size not set.\n");
992 return -E1000_ERR_CONFIG;
993 }
994
995 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
996 if (!speed) {
997 e_dbg("Speed not set.\n");
998 return -E1000_ERR_CONFIG;
999 }
1000
1001 /* Rx Packet Buffer Allocation size (KB) */
1002 rxa = er32(PBA) & E1000_PBA_RXA_MASK;
1003
1004 /* Determine the maximum latency tolerated by the device.
1005 *
1006 * Per the PCIe spec, the tolerated latencies are encoded as
1007 * a 3-bit encoded scale (only 0-5 are valid) multiplied by
1008 * a 10-bit value (0-1023) to provide a range from 1 ns to
1009 * 2^25*(2^10-1) ns. The scale is encoded as 0=2^0ns,
1010 * 1=2^5ns, 2=2^10ns,...5=2^25ns.
1011 */
1012 lat_ns = ((s64)rxa * 1024 -
1013 (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
1014 if (lat_ns < 0)
1015 lat_ns = 0;
1016 else
1017 do_div(lat_ns, speed);
1018
1019 value = lat_ns;
1020 while (value > PCI_LTR_VALUE_MASK) {
1021 scale++;
1022 value = DIV_ROUND_UP(value, (1 << 5));
1023 }
1024 if (scale > E1000_LTRV_SCALE_MAX) {
1025 e_dbg("Invalid LTR latency scale %d\n", scale);
1026 return -E1000_ERR_CONFIG;
1027 }
1028 lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
1029
1030 /* Determine the maximum latency tolerated by the platform */
1031 pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
1032 &max_snoop);
1033 pci_read_config_word(hw->adapter->pdev,
1034 E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
1035 max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
1036
1037 if (lat_enc > max_ltr_enc)
1038 lat_enc = max_ltr_enc;
1039 }
1040
1041 /* Set Snoop and No-Snoop latencies the same */
1042 reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
1043 ew32(LTRV, reg);
1044
1045 return 0;
1046}
1047
1048/**
David Ertman74f350e2014-02-22 03:15:17 +00001049 * e1000_enable_ulp_lpt_lp - configure Ultra Low Power mode for LynxPoint-LP
1050 * @hw: pointer to the HW structure
1051 * @to_sx: boolean indicating a system power state transition to Sx
1052 *
1053 * When link is down, configure ULP mode to significantly reduce the power
1054 * to the PHY. If on a Manageability Engine (ME) enabled system, tell the
1055 * ME firmware to start the ULP configuration. If not on an ME enabled
1056 * system, configure the ULP mode by software.
1057 */
1058s32 e1000_enable_ulp_lpt_lp(struct e1000_hw *hw, bool to_sx)
1059{
1060 u32 mac_reg;
1061 s32 ret_val = 0;
1062 u16 phy_reg;
1063
1064 if ((hw->mac.type < e1000_pch_lpt) ||
1065 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
1066 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
1067 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
1068 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
1069 (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_on))
1070 return 0;
1071
1072 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
1073 /* Request ME configure ULP mode in the PHY */
1074 mac_reg = er32(H2ME);
1075 mac_reg |= E1000_H2ME_ULP | E1000_H2ME_ENFORCE_SETTINGS;
1076 ew32(H2ME, mac_reg);
1077
1078 goto out;
1079 }
1080
1081 if (!to_sx) {
1082 int i = 0;
1083
1084 /* Poll up to 5 seconds for Cable Disconnected indication */
1085 while (!(er32(FEXT) & E1000_FEXT_PHY_CABLE_DISCONNECTED)) {
1086 /* Bail if link is re-acquired */
1087 if (er32(STATUS) & E1000_STATUS_LU)
1088 return -E1000_ERR_PHY;
1089
1090 if (i++ == 100)
1091 break;
1092
1093 msleep(50);
1094 }
1095 e_dbg("CABLE_DISCONNECTED %s set after %dmsec\n",
1096 (er32(FEXT) &
1097 E1000_FEXT_PHY_CABLE_DISCONNECTED) ? "" : "not", i * 50);
1098 }
1099
1100 ret_val = hw->phy.ops.acquire(hw);
1101 if (ret_val)
1102 goto out;
1103
1104 /* Force SMBus mode in PHY */
1105 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
1106 if (ret_val)
1107 goto release;
1108 phy_reg |= CV_SMB_CTRL_FORCE_SMBUS;
1109 e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
1110
1111 /* Force SMBus mode in MAC */
1112 mac_reg = er32(CTRL_EXT);
1113 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
1114 ew32(CTRL_EXT, mac_reg);
1115
1116 /* Set Inband ULP Exit, Reset to SMBus mode and
1117 * Disable SMBus Release on PERST# in PHY
1118 */
1119 ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
1120 if (ret_val)
1121 goto release;
1122 phy_reg |= (I218_ULP_CONFIG1_RESET_TO_SMBUS |
1123 I218_ULP_CONFIG1_DISABLE_SMB_PERST);
1124 if (to_sx) {
1125 if (er32(WUFC) & E1000_WUFC_LNKC)
1126 phy_reg |= I218_ULP_CONFIG1_WOL_HOST;
1127
1128 phy_reg |= I218_ULP_CONFIG1_STICKY_ULP;
1129 } else {
1130 phy_reg |= I218_ULP_CONFIG1_INBAND_EXIT;
1131 }
1132 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1133
1134 /* Set Disable SMBus Release on PERST# in MAC */
1135 mac_reg = er32(FEXTNVM7);
1136 mac_reg |= E1000_FEXTNVM7_DISABLE_SMB_PERST;
1137 ew32(FEXTNVM7, mac_reg);
1138
1139 /* Commit ULP changes in PHY by starting auto ULP configuration */
1140 phy_reg |= I218_ULP_CONFIG1_START;
1141 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1142release:
1143 hw->phy.ops.release(hw);
1144out:
1145 if (ret_val)
1146 e_dbg("Error in ULP enable flow: %d\n", ret_val);
1147 else
1148 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_on;
1149
1150 return ret_val;
1151}
1152
1153/**
1154 * e1000_disable_ulp_lpt_lp - unconfigure Ultra Low Power mode for LynxPoint-LP
1155 * @hw: pointer to the HW structure
1156 * @force: boolean indicating whether or not to force disabling ULP
1157 *
1158 * Un-configure ULP mode when link is up, the system is transitioned from
1159 * Sx or the driver is unloaded. If on a Manageability Engine (ME) enabled
1160 * system, poll for an indication from ME that ULP has been un-configured.
1161 * If not on an ME enabled system, un-configure the ULP mode by software.
1162 *
1163 * During nominal operation, this function is called when link is acquired
1164 * to disable ULP mode (force=false); otherwise, for example when unloading
1165 * the driver or during Sx->S0 transitions, this is called with force=true
1166 * to forcibly disable ULP.
1167 */
1168static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force)
1169{
1170 s32 ret_val = 0;
1171 u32 mac_reg;
1172 u16 phy_reg;
1173 int i = 0;
1174
1175 if ((hw->mac.type < e1000_pch_lpt) ||
1176 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
1177 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
1178 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
1179 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
1180 (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_off))
1181 return 0;
1182
1183 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
1184 if (force) {
1185 /* Request ME un-configure ULP mode in the PHY */
1186 mac_reg = er32(H2ME);
1187 mac_reg &= ~E1000_H2ME_ULP;
1188 mac_reg |= E1000_H2ME_ENFORCE_SETTINGS;
1189 ew32(H2ME, mac_reg);
1190 }
1191
1192 /* Poll up to 100msec for ME to clear ULP_CFG_DONE */
1193 while (er32(FWSM) & E1000_FWSM_ULP_CFG_DONE) {
1194 if (i++ == 10) {
1195 ret_val = -E1000_ERR_PHY;
1196 goto out;
1197 }
1198
1199 usleep_range(10000, 20000);
1200 }
1201 e_dbg("ULP_CONFIG_DONE cleared after %dmsec\n", i * 10);
1202
1203 if (force) {
1204 mac_reg = er32(H2ME);
1205 mac_reg &= ~E1000_H2ME_ENFORCE_SETTINGS;
1206 ew32(H2ME, mac_reg);
1207 } else {
1208 /* Clear H2ME.ULP after ME ULP configuration */
1209 mac_reg = er32(H2ME);
1210 mac_reg &= ~E1000_H2ME_ULP;
1211 ew32(H2ME, mac_reg);
1212 }
1213
1214 goto out;
1215 }
1216
1217 ret_val = hw->phy.ops.acquire(hw);
1218 if (ret_val)
1219 goto out;
1220
1221 if (force)
1222 /* Toggle LANPHYPC Value bit */
1223 e1000_toggle_lanphypc_pch_lpt(hw);
1224
1225 /* Unforce SMBus mode in PHY */
1226 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
1227 if (ret_val) {
1228 /* The MAC might be in PCIe mode, so temporarily force to
1229 * SMBus mode in order to access the PHY.
1230 */
1231 mac_reg = er32(CTRL_EXT);
1232 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
1233 ew32(CTRL_EXT, mac_reg);
1234
1235 msleep(50);
1236
1237 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL,
1238 &phy_reg);
1239 if (ret_val)
1240 goto release;
1241 }
1242 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
1243 e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
1244
1245 /* Unforce SMBus mode in MAC */
1246 mac_reg = er32(CTRL_EXT);
1247 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
1248 ew32(CTRL_EXT, mac_reg);
1249
1250 /* When ULP mode was previously entered, K1 was disabled by the
1251 * hardware. Re-Enable K1 in the PHY when exiting ULP.
1252 */
1253 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_PM_CTRL, &phy_reg);
1254 if (ret_val)
1255 goto release;
1256 phy_reg |= HV_PM_CTRL_K1_ENABLE;
1257 e1000_write_phy_reg_hv_locked(hw, HV_PM_CTRL, phy_reg);
1258
1259 /* Clear ULP enabled configuration */
1260 ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
1261 if (ret_val)
1262 goto release;
1263 phy_reg &= ~(I218_ULP_CONFIG1_IND |
1264 I218_ULP_CONFIG1_STICKY_ULP |
1265 I218_ULP_CONFIG1_RESET_TO_SMBUS |
1266 I218_ULP_CONFIG1_WOL_HOST |
1267 I218_ULP_CONFIG1_INBAND_EXIT |
1268 I218_ULP_CONFIG1_DISABLE_SMB_PERST);
1269 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1270
1271 /* Commit ULP changes by starting auto ULP configuration */
1272 phy_reg |= I218_ULP_CONFIG1_START;
1273 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
1274
1275 /* Clear Disable SMBus Release on PERST# in MAC */
1276 mac_reg = er32(FEXTNVM7);
1277 mac_reg &= ~E1000_FEXTNVM7_DISABLE_SMB_PERST;
1278 ew32(FEXTNVM7, mac_reg);
1279
1280release:
1281 hw->phy.ops.release(hw);
1282 if (force) {
1283 e1000_phy_hw_reset(hw);
1284 msleep(50);
1285 }
1286out:
1287 if (ret_val)
1288 e_dbg("Error in ULP disable flow: %d\n", ret_val);
1289 else
1290 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_off;
1291
1292 return ret_val;
1293}
1294
1295/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001296 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
1297 * @hw: pointer to the HW structure
1298 *
1299 * Checks to see of the link status of the hardware has changed. If a
1300 * change in link status has been detected, then we read the PHY registers
1301 * to get the current speed/duplex if link exists.
1302 **/
1303static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1304{
1305 struct e1000_mac_info *mac = &hw->mac;
1306 s32 ret_val;
1307 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001308 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001309
Bruce Allane921eb12012-11-28 09:28:37 +00001310 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001311 * has completed and/or if our link status has changed. The
1312 * get_link_status flag is set upon receiving a Link Status
1313 * Change or Rx Sequence Error interrupt.
1314 */
Bruce Allan5015e532012-02-08 02:55:56 +00001315 if (!mac->get_link_status)
1316 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001317
Bruce Allane921eb12012-11-28 09:28:37 +00001318 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001319 * link. If so, then we want to get the current speed/duplex
1320 * of the PHY.
1321 */
1322 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1323 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001324 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001325
Bruce Allan1d5846b2009-10-29 13:46:05 +00001326 if (hw->mac.type == e1000_pchlan) {
1327 ret_val = e1000_k1_gig_workaround_hv(hw, link);
1328 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001329 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001330 }
1331
David Ertmanfbb9ab12014-04-22 05:48:54 +00001332 /* When connected at 10Mbps half-duplex, some parts are excessively
Bruce Allan772d05c2013-03-06 09:02:36 +00001333 * aggressive resulting in many collisions. To avoid this, increase
1334 * the IPG and reduce Rx latency in the PHY.
1335 */
David Ertmanfbb9ab12014-04-22 05:48:54 +00001336 if (((hw->mac.type == e1000_pch2lan) ||
1337 (hw->mac.type == e1000_pch_lpt)) && link) {
Bruce Allan772d05c2013-03-06 09:02:36 +00001338 u32 reg;
David Ertman6cf08d12014-04-05 06:07:00 +00001339
Bruce Allan772d05c2013-03-06 09:02:36 +00001340 reg = er32(STATUS);
1341 if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
David Ertmanfbb9ab12014-04-22 05:48:54 +00001342 u16 emi_addr;
1343
Bruce Allan772d05c2013-03-06 09:02:36 +00001344 reg = er32(TIPG);
1345 reg &= ~E1000_TIPG_IPGT_MASK;
1346 reg |= 0xFF;
1347 ew32(TIPG, reg);
1348
1349 /* Reduce Rx latency in analog PHY */
1350 ret_val = hw->phy.ops.acquire(hw);
1351 if (ret_val)
1352 return ret_val;
1353
David Ertmanfbb9ab12014-04-22 05:48:54 +00001354 if (hw->mac.type == e1000_pch2lan)
1355 emi_addr = I82579_RX_CONFIG;
1356 else
1357 emi_addr = I217_RX_CONFIG;
1358
1359 ret_val = e1000_write_emi_reg_locked(hw, emi_addr, 0);
Bruce Allan772d05c2013-03-06 09:02:36 +00001360
1361 hw->phy.ops.release(hw);
1362
1363 if (ret_val)
1364 return ret_val;
1365 }
1366 }
1367
Bruce Allane08f6262013-02-20 03:06:34 +00001368 /* Work-around I218 hang issue */
1369 if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
Bruce Allan91a3d822013-06-29 01:15:16 +00001370 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
1371 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
1372 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
Bruce Allane08f6262013-02-20 03:06:34 +00001373 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
1374 if (ret_val)
1375 return ret_val;
1376 }
1377
Bruce Allancf8fb732013-03-06 09:03:02 +00001378 if (hw->mac.type == e1000_pch_lpt) {
1379 /* Set platform power management values for
1380 * Latency Tolerance Reporting (LTR)
1381 */
1382 ret_val = e1000_platform_pm_pch_lpt(hw, link);
1383 if (ret_val)
1384 return ret_val;
1385 }
1386
Bruce Allan2fbe4522012-04-19 03:21:47 +00001387 /* Clear link partner's EEE ability */
1388 hw->dev_spec.ich8lan.eee_lp_ability = 0;
1389
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001390 if (!link)
Bruce Allane80bd1d2013-05-01 01:19:46 +00001391 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001392
1393 mac->get_link_status = false;
1394
Bruce Allan1d2101a72011-07-22 06:21:56 +00001395 switch (hw->mac.type) {
1396 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +00001397 ret_val = e1000_k1_workaround_lv(hw);
1398 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001399 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001400 /* fall-thru */
1401 case e1000_pchlan:
1402 if (hw->phy.type == e1000_phy_82578) {
1403 ret_val = e1000_link_stall_workaround_hv(hw);
1404 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001405 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001406 }
1407
Bruce Allane921eb12012-11-28 09:28:37 +00001408 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +00001409 * Set the number of preambles removed from the packet
1410 * when it is passed from the PHY to the MAC to prevent
1411 * the MAC from misinterpreting the packet type.
1412 */
1413 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
1414 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
1415
1416 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
1417 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
1418
1419 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
1420 break;
1421 default:
1422 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001423 }
1424
Bruce Allane921eb12012-11-28 09:28:37 +00001425 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001426 * immediately after link-up
1427 */
1428 e1000e_check_downshift(hw);
1429
Bruce Allane52997f2010-06-16 13:27:49 +00001430 /* Enable/Disable EEE after link up */
David Ertmana03206e2014-01-24 23:07:48 +00001431 if (hw->phy.type > e1000_phy_82579) {
1432 ret_val = e1000_set_eee_pchlan(hw);
1433 if (ret_val)
1434 return ret_val;
1435 }
Bruce Allane52997f2010-06-16 13:27:49 +00001436
Bruce Allane921eb12012-11-28 09:28:37 +00001437 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001438 * we have already determined whether we have link or not.
1439 */
Bruce Allan5015e532012-02-08 02:55:56 +00001440 if (!mac->autoneg)
1441 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001442
Bruce Allane921eb12012-11-28 09:28:37 +00001443 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001444 * of MAC speed/duplex configuration. So we only need to
1445 * configure Collision Distance in the MAC.
1446 */
Bruce Allan57cde762012-02-22 09:02:58 +00001447 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001448
Bruce Allane921eb12012-11-28 09:28:37 +00001449 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001450 * First, we need to restore the desired flow control
1451 * settings because we may have had to re-autoneg with a
1452 * different link partner.
1453 */
1454 ret_val = e1000e_config_fc_after_link_up(hw);
1455 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001456 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001457
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001458 return ret_val;
1459}
1460
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001461static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001462{
1463 struct e1000_hw *hw = &adapter->hw;
1464 s32 rc;
1465
Bruce Allanec34c172012-02-01 10:53:05 +00001466 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001467 if (rc)
1468 return rc;
1469
1470 rc = e1000_init_nvm_params_ich8lan(hw);
1471 if (rc)
1472 return rc;
1473
Bruce Alland3738bb2010-06-16 13:27:28 +00001474 switch (hw->mac.type) {
1475 case e1000_ich8lan:
1476 case e1000_ich9lan:
1477 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001478 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001479 break;
1480 case e1000_pchlan:
1481 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001482 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001483 rc = e1000_init_phy_params_pchlan(hw);
1484 break;
1485 default:
1486 break;
1487 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001488 if (rc)
1489 return rc;
1490
Bruce Allane921eb12012-11-28 09:28:37 +00001491 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001492 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1493 */
1494 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1495 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1496 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001497 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1498 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001499
1500 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001501 }
1502
Auke Kokbc7f75f2007-09-17 12:30:59 -07001503 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001504 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001505 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1506
Bruce Allanc6e7f512011-07-29 05:53:02 +00001507 /* Enable workaround for 82579 w/ ME enabled */
1508 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1509 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1510 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1511
Auke Kokbc7f75f2007-09-17 12:30:59 -07001512 return 0;
1513}
1514
Thomas Gleixner717d4382008-10-02 16:33:40 -07001515static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001516
Auke Kokbc7f75f2007-09-17 12:30:59 -07001517/**
Bruce Allanca15df52009-10-26 11:23:43 +00001518 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1519 * @hw: pointer to the HW structure
1520 *
1521 * Acquires the mutex for performing NVM operations.
1522 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001523static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001524{
1525 mutex_lock(&nvm_mutex);
1526
1527 return 0;
1528}
1529
1530/**
1531 * e1000_release_nvm_ich8lan - Release NVM mutex
1532 * @hw: pointer to the HW structure
1533 *
1534 * Releases the mutex used while performing NVM operations.
1535 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001536static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001537{
1538 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001539}
1540
Bruce Allanca15df52009-10-26 11:23:43 +00001541/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001542 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1543 * @hw: pointer to the HW structure
1544 *
Bruce Allanca15df52009-10-26 11:23:43 +00001545 * Acquires the software control flag for performing PHY and select
1546 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547 **/
1548static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1549{
Bruce Allan373a88d2009-08-07 07:41:37 +00001550 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1551 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001552
Bruce Allana90b4122011-10-07 03:50:38 +00001553 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1554 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001555 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001556 return -E1000_ERR_PHY;
1557 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001558
Auke Kokbc7f75f2007-09-17 12:30:59 -07001559 while (timeout) {
1560 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001561 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1562 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001563
Auke Kokbc7f75f2007-09-17 12:30:59 -07001564 mdelay(1);
1565 timeout--;
1566 }
1567
1568 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001569 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001570 ret_val = -E1000_ERR_CONFIG;
1571 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001572 }
1573
Bruce Allan53ac5a82009-10-26 11:23:06 +00001574 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001575
1576 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1577 ew32(EXTCNF_CTRL, extcnf_ctrl);
1578
1579 while (timeout) {
1580 extcnf_ctrl = er32(EXTCNF_CTRL);
1581 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1582 break;
1583
1584 mdelay(1);
1585 timeout--;
1586 }
1587
1588 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001589 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 +00001590 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001591 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1592 ew32(EXTCNF_CTRL, extcnf_ctrl);
1593 ret_val = -E1000_ERR_CONFIG;
1594 goto out;
1595 }
1596
1597out:
1598 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001599 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001600
1601 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602}
1603
1604/**
1605 * e1000_release_swflag_ich8lan - Release software control flag
1606 * @hw: pointer to the HW structure
1607 *
Bruce Allanca15df52009-10-26 11:23:43 +00001608 * Releases the software control flag for performing PHY and select
1609 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001610 **/
1611static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1612{
1613 u32 extcnf_ctrl;
1614
1615 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001616
1617 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1618 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1619 ew32(EXTCNF_CTRL, extcnf_ctrl);
1620 } else {
1621 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1622 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001623
Bruce Allana90b4122011-10-07 03:50:38 +00001624 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001625}
1626
1627/**
Bruce Allan4662e822008-08-26 18:37:06 -07001628 * e1000_check_mng_mode_ich8lan - Checks management mode
1629 * @hw: pointer to the HW structure
1630 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001631 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001632 * This is a function pointer entry point only called by read/write
1633 * routines for the PHY and NVM parts.
1634 **/
1635static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1636{
Bruce Allana708dd82009-11-20 23:28:37 +00001637 u32 fwsm;
1638
1639 fwsm = er32(FWSM);
David Ertman261a7d12014-05-13 00:02:12 +00001640 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
Bruce Allanf0ff4392013-02-20 04:05:39 +00001641 ((fwsm & E1000_FWSM_MODE_MASK) ==
David Ertman261a7d12014-05-13 00:02:12 +00001642 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allaneb7700d2010-06-16 13:27:05 +00001643}
Bruce Allan4662e822008-08-26 18:37:06 -07001644
Bruce Allaneb7700d2010-06-16 13:27:05 +00001645/**
1646 * e1000_check_mng_mode_pchlan - Checks management mode
1647 * @hw: pointer to the HW structure
1648 *
1649 * This checks if the adapter has iAMT enabled.
1650 * This is a function pointer entry point only called by read/write
1651 * routines for the PHY and NVM parts.
1652 **/
1653static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1654{
1655 u32 fwsm;
1656
1657 fwsm = er32(FWSM);
1658 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
Bruce Allanf0ff4392013-02-20 04:05:39 +00001659 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001660}
1661
1662/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001663 * e1000_rar_set_pch2lan - Set receive address register
1664 * @hw: pointer to the HW structure
1665 * @addr: pointer to the receive address
1666 * @index: receive address array register
1667 *
1668 * Sets the receive address array register at index to the address passed
1669 * in by addr. For 82579, RAR[0] is the base address register that is to
1670 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1671 * Use SHRA[0-3] in place of those reserved for ME.
1672 **/
David Ertmanb3e5bf12014-05-06 03:50:17 +00001673static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
Bruce Allan69e1e012012-04-14 03:28:50 +00001674{
1675 u32 rar_low, rar_high;
1676
Bruce Allane921eb12012-11-28 09:28:37 +00001677 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001678 * from network order (big endian) to little endian
1679 */
1680 rar_low = ((u32)addr[0] |
1681 ((u32)addr[1] << 8) |
1682 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1683
1684 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1685
1686 /* If MAC address zero, no need to set the AV bit */
1687 if (rar_low || rar_high)
1688 rar_high |= E1000_RAH_AV;
1689
1690 if (index == 0) {
1691 ew32(RAL(index), rar_low);
1692 e1e_flush();
1693 ew32(RAH(index), rar_high);
1694 e1e_flush();
David Ertmanb3e5bf12014-05-06 03:50:17 +00001695 return 0;
Bruce Allan69e1e012012-04-14 03:28:50 +00001696 }
1697
David Ertmanc3a0dce2013-09-05 04:24:25 +00001698 /* RAR[1-6] are owned by manageability. Skip those and program the
1699 * next address into the SHRA register array.
1700 */
David Ertman96dee022014-03-05 07:50:46 +00001701 if (index < (u32)(hw->mac.rar_entry_count)) {
Bruce Allan69e1e012012-04-14 03:28:50 +00001702 s32 ret_val;
1703
1704 ret_val = e1000_acquire_swflag_ich8lan(hw);
1705 if (ret_val)
1706 goto out;
1707
1708 ew32(SHRAL(index - 1), rar_low);
1709 e1e_flush();
1710 ew32(SHRAH(index - 1), rar_high);
1711 e1e_flush();
1712
1713 e1000_release_swflag_ich8lan(hw);
1714
1715 /* verify the register updates */
1716 if ((er32(SHRAL(index - 1)) == rar_low) &&
1717 (er32(SHRAH(index - 1)) == rar_high))
David Ertmanb3e5bf12014-05-06 03:50:17 +00001718 return 0;
Bruce Allan69e1e012012-04-14 03:28:50 +00001719
1720 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1721 (index - 1), er32(FWSM));
1722 }
1723
1724out:
1725 e_dbg("Failed to write receive address at index %d\n", index);
David Ertmanb3e5bf12014-05-06 03:50:17 +00001726 return -E1000_ERR_CONFIG;
1727}
1728
1729/**
1730 * e1000_rar_get_count_pch_lpt - Get the number of available SHRA
1731 * @hw: pointer to the HW structure
1732 *
1733 * Get the number of available receive registers that the Host can
1734 * program. SHRA[0-10] are the shared receive address registers
1735 * that are shared between the Host and manageability engine (ME).
1736 * ME can reserve any number of addresses and the host needs to be
1737 * able to tell how many available registers it has access to.
1738 **/
1739static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw)
1740{
1741 u32 wlock_mac;
1742 u32 num_entries;
1743
1744 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1745 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1746
1747 switch (wlock_mac) {
1748 case 0:
1749 /* All SHRA[0..10] and RAR[0] available */
1750 num_entries = hw->mac.rar_entry_count;
1751 break;
1752 case 1:
1753 /* Only RAR[0] available */
1754 num_entries = 1;
1755 break;
1756 default:
1757 /* SHRA[0..(wlock_mac - 1)] available + RAR[0] */
1758 num_entries = wlock_mac + 1;
1759 break;
1760 }
1761
1762 return num_entries;
Bruce Allan69e1e012012-04-14 03:28:50 +00001763}
1764
1765/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001766 * e1000_rar_set_pch_lpt - Set receive address registers
1767 * @hw: pointer to the HW structure
1768 * @addr: pointer to the receive address
1769 * @index: receive address array register
1770 *
1771 * Sets the receive address register array at index to the address passed
1772 * in by addr. For LPT, RAR[0] is the base address register that is to
1773 * contain the MAC address. SHRA[0-10] are the shared receive address
1774 * registers that are shared between the Host and manageability engine (ME).
1775 **/
David Ertmanb3e5bf12014-05-06 03:50:17 +00001776static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
Bruce Allan2fbe4522012-04-19 03:21:47 +00001777{
1778 u32 rar_low, rar_high;
1779 u32 wlock_mac;
1780
Bruce Allane921eb12012-11-28 09:28:37 +00001781 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001782 * from network order (big endian) to little endian
1783 */
1784 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1785 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1786
1787 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1788
1789 /* If MAC address zero, no need to set the AV bit */
1790 if (rar_low || rar_high)
1791 rar_high |= E1000_RAH_AV;
1792
1793 if (index == 0) {
1794 ew32(RAL(index), rar_low);
1795 e1e_flush();
1796 ew32(RAH(index), rar_high);
1797 e1e_flush();
David Ertmanb3e5bf12014-05-06 03:50:17 +00001798 return 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +00001799 }
1800
Bruce Allane921eb12012-11-28 09:28:37 +00001801 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001802 * it is using - those registers are unavailable for use.
1803 */
1804 if (index < hw->mac.rar_entry_count) {
1805 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1806 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1807
1808 /* Check if all SHRAR registers are locked */
1809 if (wlock_mac == 1)
1810 goto out;
1811
1812 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1813 s32 ret_val;
1814
1815 ret_val = e1000_acquire_swflag_ich8lan(hw);
1816
1817 if (ret_val)
1818 goto out;
1819
1820 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1821 e1e_flush();
1822 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1823 e1e_flush();
1824
1825 e1000_release_swflag_ich8lan(hw);
1826
1827 /* verify the register updates */
1828 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1829 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
David Ertmanb3e5bf12014-05-06 03:50:17 +00001830 return 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +00001831 }
1832 }
1833
1834out:
1835 e_dbg("Failed to write receive address at index %d\n", index);
David Ertmanb3e5bf12014-05-06 03:50:17 +00001836 return -E1000_ERR_CONFIG;
Bruce Allan2fbe4522012-04-19 03:21:47 +00001837}
1838
1839/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001840 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1841 * @hw: pointer to the HW structure
1842 *
1843 * Checks if firmware is blocking the reset of the PHY.
1844 * This is a function pointer entry point only called by
1845 * reset routines.
1846 **/
1847static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1848{
David Ertmanf7235ef2014-01-23 06:29:13 +00001849 bool blocked = false;
1850 int i = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001851
David Ertmanf7235ef2014-01-23 06:29:13 +00001852 while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&
1853 (i++ < 10))
1854 usleep_range(10000, 20000);
1855 return blocked ? E1000_BLK_PHY_RESET : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856}
1857
1858/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001859 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1860 * @hw: pointer to the HW structure
1861 *
1862 * Assumes semaphore already acquired.
1863 *
1864 **/
1865static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1866{
1867 u16 phy_data;
1868 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001869 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1870 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan70806a72013-01-05 05:08:37 +00001871 s32 ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001872
1873 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1874
1875 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1876 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001877 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001878
1879 phy_data &= ~HV_SMB_ADDR_MASK;
1880 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1881 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001882
Bruce Allan2fbe4522012-04-19 03:21:47 +00001883 if (hw->phy.type == e1000_phy_i217) {
1884 /* Restore SMBus frequency */
1885 if (freq--) {
1886 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1887 phy_data |= (freq & (1 << 0)) <<
1888 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1889 phy_data |= (freq & (1 << 1)) <<
1890 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1891 } else {
1892 e_dbg("Unsupported SMB frequency in PHY\n");
1893 }
1894 }
1895
Bruce Allan5015e532012-02-08 02:55:56 +00001896 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001897}
1898
1899/**
Bruce Allanf523d212009-10-29 13:45:45 +00001900 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1901 * @hw: pointer to the HW structure
1902 *
1903 * SW should configure the LCD from the NVM extended configuration region
1904 * as a workaround for certain parts.
1905 **/
1906static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1907{
1908 struct e1000_phy_info *phy = &hw->phy;
1909 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001910 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001911 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1912
Bruce Allane921eb12012-11-28 09:28:37 +00001913 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001914 * is needed due to an issue where the NVM configuration is
1915 * not properly autoloaded after power transitions.
1916 * Therefore, after each PHY reset, we will load the
1917 * configuration data out of the NVM manually.
1918 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001919 switch (hw->mac.type) {
1920 case e1000_ich8lan:
1921 if (phy->type != e1000_phy_igp_3)
1922 return ret_val;
1923
Bruce Allan5f3eed62010-09-22 17:15:54 +00001924 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1925 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001926 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1927 break;
1928 }
1929 /* Fall-thru */
1930 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001931 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001932 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001933 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001934 break;
1935 default:
1936 return ret_val;
1937 }
1938
1939 ret_val = hw->phy.ops.acquire(hw);
1940 if (ret_val)
1941 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001942
Bruce Allan8b802a72010-05-10 15:01:10 +00001943 data = er32(FEXTNVM);
1944 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001945 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001946
Bruce Allane921eb12012-11-28 09:28:37 +00001947 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001948 * extended configuration before SW configuration
1949 */
1950 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001951 if ((hw->mac.type < e1000_pch2lan) &&
1952 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1953 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001954
Bruce Allan8b802a72010-05-10 15:01:10 +00001955 cnf_size = er32(EXTCNF_SIZE);
1956 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1957 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1958 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001959 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001960
1961 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1962 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1963
Bruce Allan2fbe4522012-04-19 03:21:47 +00001964 if (((hw->mac.type == e1000_pchlan) &&
1965 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1966 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001967 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001968 * OEM and LCD Write Enable bits are set in the NVM.
1969 * When both NVM bits are cleared, SW will configure
1970 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001971 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001972 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001973 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001974 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001975
Bruce Allan8b802a72010-05-10 15:01:10 +00001976 data = er32(LEDCTL);
1977 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1978 (u16)data);
1979 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001980 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001981 }
1982
1983 /* Configure LCD from extended configuration region. */
1984
1985 /* cnf_base_addr is in DWORD */
1986 word_addr = (u16)(cnf_base_addr << 1);
1987
1988 for (i = 0; i < cnf_size; i++) {
Bruce Allane5fe2542013-02-20 04:06:27 +00001989 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001990 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001991 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001992
Bruce Allan8b802a72010-05-10 15:01:10 +00001993 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1994 1, &reg_addr);
1995 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001996 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001997
Bruce Allan8b802a72010-05-10 15:01:10 +00001998 /* Save off the PHY page for future writes. */
1999 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
2000 phy_page = reg_data;
2001 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00002002 }
Bruce Allanf523d212009-10-29 13:45:45 +00002003
Bruce Allan8b802a72010-05-10 15:01:10 +00002004 reg_addr &= PHY_REG_MASK;
2005 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00002006
Bruce Allanf1430d62012-04-14 04:21:52 +00002007 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00002008 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002009 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00002010 }
2011
Bruce Allan75ce1532012-02-08 02:54:48 +00002012release:
Bruce Allan94d81862009-11-20 23:25:26 +00002013 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00002014 return ret_val;
2015}
2016
2017/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00002018 * e1000_k1_gig_workaround_hv - K1 Si workaround
2019 * @hw: pointer to the HW structure
2020 * @link: link up bool flag
2021 *
2022 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
2023 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
2024 * If link is down, the function will restore the default K1 setting located
2025 * in the NVM.
2026 **/
2027static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
2028{
2029 s32 ret_val = 0;
2030 u16 status_reg = 0;
2031 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
2032
2033 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00002034 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002035
2036 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00002037 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002038 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002039 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002040
2041 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
2042 if (link) {
2043 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00002044 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
2045 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002046 if (ret_val)
2047 goto release;
2048
Bruce Allanf0ff4392013-02-20 04:05:39 +00002049 status_reg &= (BM_CS_STATUS_LINK_UP |
2050 BM_CS_STATUS_RESOLVED |
2051 BM_CS_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002052
2053 if (status_reg == (BM_CS_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00002054 BM_CS_STATUS_RESOLVED |
2055 BM_CS_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00002056 k1_enable = false;
2057 }
2058
2059 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00002060 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002061 if (ret_val)
2062 goto release;
2063
Bruce Allanf0ff4392013-02-20 04:05:39 +00002064 status_reg &= (HV_M_STATUS_LINK_UP |
2065 HV_M_STATUS_AUTONEG_COMPLETE |
2066 HV_M_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002067
2068 if (status_reg == (HV_M_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00002069 HV_M_STATUS_AUTONEG_COMPLETE |
2070 HV_M_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00002071 k1_enable = false;
2072 }
2073
2074 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00002075 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002076 if (ret_val)
2077 goto release;
2078
2079 } else {
2080 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00002081 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002082 if (ret_val)
2083 goto release;
2084 }
2085
2086 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
2087
2088release:
Bruce Allan94d81862009-11-20 23:25:26 +00002089 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00002090
Bruce Allan1d5846b2009-10-29 13:46:05 +00002091 return ret_val;
2092}
2093
2094/**
2095 * e1000_configure_k1_ich8lan - Configure K1 power state
2096 * @hw: pointer to the HW structure
2097 * @enable: K1 state to configure
2098 *
2099 * Configure the K1 power state based on the provided parameter.
2100 * Assumes semaphore already acquired.
2101 *
2102 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2103 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00002104s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00002105{
Bruce Allan70806a72013-01-05 05:08:37 +00002106 s32 ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002107 u32 ctrl_reg = 0;
2108 u32 ctrl_ext = 0;
2109 u32 reg = 0;
2110 u16 kmrn_reg = 0;
2111
Bruce Allan3d3a1672012-02-23 03:13:18 +00002112 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
2113 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002114 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002115 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002116
2117 if (k1_enable)
2118 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
2119 else
2120 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
2121
Bruce Allan3d3a1672012-02-23 03:13:18 +00002122 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
2123 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002124 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002125 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002126
Bruce Allance43a212013-02-20 04:06:32 +00002127 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002128 ctrl_ext = er32(CTRL_EXT);
2129 ctrl_reg = er32(CTRL);
2130
2131 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2132 reg |= E1000_CTRL_FRCSPD;
2133 ew32(CTRL, reg);
2134
2135 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002136 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00002137 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002138 ew32(CTRL, ctrl_reg);
2139 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002140 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00002141 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002142
Bruce Allan5015e532012-02-08 02:55:56 +00002143 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002144}
2145
2146/**
Bruce Allanf523d212009-10-29 13:45:45 +00002147 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
2148 * @hw: pointer to the HW structure
2149 * @d0_state: boolean if entering d0 or d3 device state
2150 *
2151 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
2152 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
2153 * in NVM determines whether HW should configure LPLU and Gbe Disable.
2154 **/
2155static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
2156{
2157 s32 ret_val = 0;
2158 u32 mac_reg;
2159 u16 oem_reg;
2160
Bruce Allan2fbe4522012-04-19 03:21:47 +00002161 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00002162 return ret_val;
2163
Bruce Allan94d81862009-11-20 23:25:26 +00002164 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00002165 if (ret_val)
2166 return ret_val;
2167
Bruce Allan2fbe4522012-04-19 03:21:47 +00002168 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00002169 mac_reg = er32(EXTCNF_CTRL);
2170 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00002171 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00002172 }
Bruce Allanf523d212009-10-29 13:45:45 +00002173
2174 mac_reg = er32(FEXTNVM);
2175 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00002176 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00002177
2178 mac_reg = er32(PHY_CTRL);
2179
Bruce Allanf1430d62012-04-14 04:21:52 +00002180 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00002181 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00002182 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00002183
2184 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
2185
2186 if (d0_state) {
2187 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
2188 oem_reg |= HV_OEM_BITS_GBE_DIS;
2189
2190 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
2191 oem_reg |= HV_OEM_BITS_LPLU;
2192 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00002193 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
2194 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00002195 oem_reg |= HV_OEM_BITS_GBE_DIS;
2196
Bruce Allan03299e42011-09-30 08:07:05 +00002197 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
2198 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00002199 oem_reg |= HV_OEM_BITS_LPLU;
2200 }
Bruce Allan03299e42011-09-30 08:07:05 +00002201
Bruce Allan92fe1732012-04-12 06:27:03 +00002202 /* Set Restart auto-neg to activate the bits */
2203 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
2204 !hw->phy.ops.check_reset_block(hw))
2205 oem_reg |= HV_OEM_BITS_RESTART_AN;
2206
Bruce Allanf1430d62012-04-14 04:21:52 +00002207 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00002208
Bruce Allan75ce1532012-02-08 02:54:48 +00002209release:
Bruce Allan94d81862009-11-20 23:25:26 +00002210 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00002211
2212 return ret_val;
2213}
2214
Bruce Allanf523d212009-10-29 13:45:45 +00002215/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002216 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
2217 * @hw: pointer to the HW structure
2218 **/
2219static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
2220{
2221 s32 ret_val;
2222 u16 data;
2223
2224 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
2225 if (ret_val)
2226 return ret_val;
2227
2228 data |= HV_KMRN_MDIO_SLOW;
2229
2230 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
2231
2232 return ret_val;
2233}
2234
2235/**
Bruce Allana4f58f52009-06-02 11:29:18 +00002236 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2237 * done after every PHY reset.
2238 **/
2239static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2240{
2241 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00002242 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00002243
2244 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00002245 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00002246
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002247 /* Set MDIO slow mode before any other MDIO access */
2248 if (hw->phy.type == e1000_phy_82577) {
2249 ret_val = e1000_set_mdio_slow_mode_hv(hw);
2250 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002251 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002252 }
2253
Bruce Allana4f58f52009-06-02 11:29:18 +00002254 if (((hw->phy.type == e1000_phy_82577) &&
2255 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
2256 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
2257 /* Disable generation of early preamble */
2258 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
2259 if (ret_val)
2260 return ret_val;
2261
2262 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00002263 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00002264 if (ret_val)
2265 return ret_val;
2266 }
2267
2268 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00002269 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00002270 * writing 0x3140 to the control register.
2271 */
2272 if (hw->phy.revision < 2) {
2273 e1000e_phy_sw_reset(hw);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00002274 ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
Bruce Allana4f58f52009-06-02 11:29:18 +00002275 }
2276 }
2277
2278 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00002279 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00002280 if (ret_val)
2281 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002282
Bruce Allana4f58f52009-06-02 11:29:18 +00002283 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002284 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00002285 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00002286 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002287 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00002288
Bruce Allane921eb12012-11-28 09:28:37 +00002289 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00002290 * link so that it disables K1 if link is in 1Gbps.
2291 */
2292 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00002293 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002294 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00002295
Bruce Allanbaf86c92010-01-13 01:53:08 +00002296 /* Workaround for link disconnects on a busy hub in half duplex */
2297 ret_val = hw->phy.ops.acquire(hw);
2298 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002299 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00002300 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00002301 if (ret_val)
2302 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00002303 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00002304 if (ret_val)
2305 goto release;
2306
2307 /* set MSE higher to enable link to stay up when noise is high */
2308 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00002309release:
2310 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00002311
Bruce Allana4f58f52009-06-02 11:29:18 +00002312 return ret_val;
2313}
2314
2315/**
Bruce Alland3738bb2010-06-16 13:27:28 +00002316 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
2317 * @hw: pointer to the HW structure
2318 **/
2319void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
2320{
2321 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00002322 u16 i, phy_reg = 0;
2323 s32 ret_val;
2324
2325 ret_val = hw->phy.ops.acquire(hw);
2326 if (ret_val)
2327 return;
2328 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2329 if (ret_val)
2330 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00002331
David Ertmanc3a0dce2013-09-05 04:24:25 +00002332 /* Copy both RAL/H (rar_entry_count) and SHRAL/H to PHY */
2333 for (i = 0; i < (hw->mac.rar_entry_count); i++) {
Bruce Alland3738bb2010-06-16 13:27:28 +00002334 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002335 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
2336 (u16)(mac_reg & 0xFFFF));
2337 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
2338 (u16)((mac_reg >> 16) & 0xFFFF));
2339
Bruce Alland3738bb2010-06-16 13:27:28 +00002340 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002341 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
2342 (u16)(mac_reg & 0xFFFF));
2343 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
2344 (u16)((mac_reg & E1000_RAH_AV)
2345 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00002346 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00002347
2348 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2349
2350release:
2351 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00002352}
2353
Bruce Alland3738bb2010-06-16 13:27:28 +00002354/**
2355 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
2356 * with 82579 PHY
2357 * @hw: pointer to the HW structure
2358 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
2359 **/
2360s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
2361{
2362 s32 ret_val = 0;
2363 u16 phy_reg, data;
2364 u32 mac_reg;
2365 u16 i;
2366
Bruce Allan2fbe4522012-04-19 03:21:47 +00002367 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002368 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002369
2370 /* disable Rx path while enabling/disabling workaround */
2371 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
2372 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
2373 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002374 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002375
2376 if (enable) {
David Ertmanc3a0dce2013-09-05 04:24:25 +00002377 /* Write Rx addresses (rar_entry_count for RAL/H, and
Bruce Alland3738bb2010-06-16 13:27:28 +00002378 * SHRAL/H) and initial CRC values to the MAC
2379 */
David Ertmanc3a0dce2013-09-05 04:24:25 +00002380 for (i = 0; i < hw->mac.rar_entry_count; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002381 u8 mac_addr[ETH_ALEN] = { 0 };
Bruce Alland3738bb2010-06-16 13:27:28 +00002382 u32 addr_high, addr_low;
2383
2384 addr_high = er32(RAH(i));
2385 if (!(addr_high & E1000_RAH_AV))
2386 continue;
2387 addr_low = er32(RAL(i));
2388 mac_addr[0] = (addr_low & 0xFF);
2389 mac_addr[1] = ((addr_low >> 8) & 0xFF);
2390 mac_addr[2] = ((addr_low >> 16) & 0xFF);
2391 mac_addr[3] = ((addr_low >> 24) & 0xFF);
2392 mac_addr[4] = (addr_high & 0xFF);
2393 mac_addr[5] = ((addr_high >> 8) & 0xFF);
2394
Bruce Allanfe46f582011-01-06 14:29:51 +00002395 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00002396 }
2397
2398 /* Write Rx addresses to the PHY */
2399 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
2400
2401 /* Enable jumbo frame workaround in the MAC */
2402 mac_reg = er32(FFLT_DBG);
2403 mac_reg &= ~(1 << 14);
2404 mac_reg |= (7 << 15);
2405 ew32(FFLT_DBG, mac_reg);
2406
2407 mac_reg = er32(RCTL);
2408 mac_reg |= E1000_RCTL_SECRC;
2409 ew32(RCTL, mac_reg);
2410
2411 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002412 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2413 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002414 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002415 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002416 ret_val = e1000e_write_kmrn_reg(hw,
2417 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2418 data | (1 << 0));
2419 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002420 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002421 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002422 E1000_KMRNCTRLSTA_HD_CTRL,
2423 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002424 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002425 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002426 data &= ~(0xF << 8);
2427 data |= (0xB << 8);
2428 ret_val = e1000e_write_kmrn_reg(hw,
2429 E1000_KMRNCTRLSTA_HD_CTRL,
2430 data);
2431 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002432 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002433
2434 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00002435 e1e_rphy(hw, PHY_REG(769, 23), &data);
2436 data &= ~(0x7F << 5);
2437 data |= (0x37 << 5);
2438 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2439 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002440 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002441 e1e_rphy(hw, PHY_REG(769, 16), &data);
2442 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00002443 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2444 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002445 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002446 e1e_rphy(hw, PHY_REG(776, 20), &data);
2447 data &= ~(0x3FF << 2);
2448 data |= (0x1A << 2);
2449 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2450 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002451 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00002452 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00002453 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002454 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002455 e1e_rphy(hw, HV_PM_CTRL, &data);
2456 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
2457 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002458 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002459 } else {
2460 /* Write MAC register values back to h/w defaults */
2461 mac_reg = er32(FFLT_DBG);
2462 mac_reg &= ~(0xF << 14);
2463 ew32(FFLT_DBG, mac_reg);
2464
2465 mac_reg = er32(RCTL);
2466 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00002467 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00002468
2469 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002470 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2471 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002472 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002473 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002474 ret_val = e1000e_write_kmrn_reg(hw,
2475 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2476 data & ~(1 << 0));
2477 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002478 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002479 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002480 E1000_KMRNCTRLSTA_HD_CTRL,
2481 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002482 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002483 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002484 data &= ~(0xF << 8);
2485 data |= (0xB << 8);
2486 ret_val = e1000e_write_kmrn_reg(hw,
2487 E1000_KMRNCTRLSTA_HD_CTRL,
2488 data);
2489 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002490 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002491
2492 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002493 e1e_rphy(hw, PHY_REG(769, 23), &data);
2494 data &= ~(0x7F << 5);
2495 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2496 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002497 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002498 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002499 data |= (1 << 13);
2500 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2501 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002502 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002503 e1e_rphy(hw, PHY_REG(776, 20), &data);
2504 data &= ~(0x3FF << 2);
2505 data |= (0x8 << 2);
2506 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2507 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002508 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002509 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2510 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002511 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002512 e1e_rphy(hw, HV_PM_CTRL, &data);
2513 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2514 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002515 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002516 }
2517
2518 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002519 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002520}
2521
2522/**
2523 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2524 * done after every PHY reset.
2525 **/
2526static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2527{
2528 s32 ret_val = 0;
2529
2530 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002531 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002532
2533 /* Set MDIO slow mode before any other MDIO access */
2534 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002535 if (ret_val)
2536 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002537
Bruce Allan4d241362011-12-16 00:46:06 +00002538 ret_val = hw->phy.ops.acquire(hw);
2539 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002540 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002541 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002542 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002543 if (ret_val)
2544 goto release;
2545 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002546 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002547release:
2548 hw->phy.ops.release(hw);
2549
Bruce Alland3738bb2010-06-16 13:27:28 +00002550 return ret_val;
2551}
2552
2553/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002554 * e1000_k1_gig_workaround_lv - K1 Si workaround
2555 * @hw: pointer to the HW structure
2556 *
David Ertman77e61142014-04-22 05:25:53 +00002557 * Workaround to set the K1 beacon duration for 82579 parts in 10Mbps
2558 * Disable K1 in 1000Mbps and 100Mbps
Bruce Allan831bd2e2010-09-22 17:16:18 +00002559 **/
2560static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2561{
2562 s32 ret_val = 0;
2563 u16 status_reg = 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002564
2565 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002566 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002567
David Ertman77e61142014-04-22 05:25:53 +00002568 /* Set K1 beacon duration based on 10Mbs speed */
Bruce Allan831bd2e2010-09-22 17:16:18 +00002569 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2570 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002571 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002572
2573 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2574 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
David Ertman77e61142014-04-22 05:25:53 +00002575 if (status_reg &
2576 (HV_M_STATUS_SPEED_1000 | HV_M_STATUS_SPEED_100)) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002577 u16 pm_phy_reg;
2578
David Ertman77e61142014-04-22 05:25:53 +00002579 /* LV 1G/100 Packet drop issue wa */
Bruce Allan36ceeb42012-03-20 03:47:47 +00002580 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2581 if (ret_val)
2582 return ret_val;
David Ertman77e61142014-04-22 05:25:53 +00002583 pm_phy_reg &= ~HV_PM_CTRL_K1_ENABLE;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002584 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2585 if (ret_val)
2586 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002587 } else {
David Ertman77e61142014-04-22 05:25:53 +00002588 u32 mac_reg;
2589
2590 mac_reg = er32(FEXTNVM4);
2591 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002592 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
David Ertman77e61142014-04-22 05:25:53 +00002593 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002594 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002595 }
2596
Bruce Allan831bd2e2010-09-22 17:16:18 +00002597 return ret_val;
2598}
2599
2600/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002601 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2602 * @hw: pointer to the HW structure
2603 * @gate: boolean set to true to gate, false to ungate
2604 *
2605 * Gate/ungate the automatic PHY configuration via hardware; perform
2606 * the configuration via software instead.
2607 **/
2608static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2609{
2610 u32 extcnf_ctrl;
2611
Bruce Allan2fbe4522012-04-19 03:21:47 +00002612 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002613 return;
2614
2615 extcnf_ctrl = er32(EXTCNF_CTRL);
2616
2617 if (gate)
2618 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2619 else
2620 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2621
2622 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002623}
2624
2625/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002626 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2627 * @hw: pointer to the HW structure
2628 *
2629 * Check the appropriate indication the MAC has finished configuring the
2630 * PHY after a software reset.
2631 **/
2632static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2633{
2634 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2635
2636 /* Wait for basic configuration completes before proceeding */
2637 do {
2638 data = er32(STATUS);
2639 data &= E1000_STATUS_LAN_INIT_DONE;
Bruce Allance43a212013-02-20 04:06:32 +00002640 usleep_range(100, 200);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002641 } while ((!data) && --loop);
2642
Bruce Allane921eb12012-11-28 09:28:37 +00002643 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002644 * count reaches 0, loading the configuration from NVM will
2645 * leave the PHY in a bad state possibly resulting in no link.
2646 */
2647 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002648 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002649
2650 /* Clear the Init Done bit for the next init event */
2651 data = er32(STATUS);
2652 data &= ~E1000_STATUS_LAN_INIT_DONE;
2653 ew32(STATUS, data);
2654}
2655
2656/**
Bruce Allane98cac42010-05-10 15:02:32 +00002657 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002658 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002659 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002660static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002661{
Bruce Allanf523d212009-10-29 13:45:45 +00002662 s32 ret_val = 0;
2663 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002664
Bruce Allan44abd5c2012-02-22 09:02:37 +00002665 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002666 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002667
Bruce Allan5f3eed62010-09-22 17:15:54 +00002668 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002669 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002670
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002671 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002672 switch (hw->mac.type) {
2673 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002674 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2675 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002676 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002677 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002678 case e1000_pch2lan:
2679 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2680 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002681 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002682 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002683 default:
2684 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002685 }
2686
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002687 /* Clear the host wakeup bit after lcd reset */
2688 if (hw->mac.type >= e1000_pchlan) {
2689 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2690 reg &= ~BM_WUC_HOST_WU_BIT;
2691 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2692 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002693
Bruce Allanf523d212009-10-29 13:45:45 +00002694 /* Configure the LCD with the extended configuration region in NVM */
2695 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2696 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002697 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002698
Bruce Allanf523d212009-10-29 13:45:45 +00002699 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002700 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002701
Bruce Allan1effb452011-02-25 06:58:03 +00002702 if (hw->mac.type == e1000_pch2lan) {
2703 /* Ungate automatic PHY configuration on non-managed 82579 */
2704 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002705 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002706 e1000_gate_hw_phy_config_ich8lan(hw, false);
2707 }
2708
2709 /* Set EEE LPI Update Timer to 200usec */
2710 ret_val = hw->phy.ops.acquire(hw);
2711 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002712 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002713 ret_val = e1000_write_emi_reg_locked(hw,
2714 I82579_LPI_UPDATE_TIMER,
2715 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002716 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002717 }
2718
Bruce Allane98cac42010-05-10 15:02:32 +00002719 return ret_val;
2720}
2721
2722/**
2723 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2724 * @hw: pointer to the HW structure
2725 *
2726 * Resets the PHY
2727 * This is a function pointer entry point called by drivers
2728 * or other shared routines.
2729 **/
2730static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2731{
2732 s32 ret_val = 0;
2733
Bruce Allan605c82b2010-09-22 17:17:01 +00002734 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2735 if ((hw->mac.type == e1000_pch2lan) &&
2736 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2737 e1000_gate_hw_phy_config_ich8lan(hw, true);
2738
Bruce Allane98cac42010-05-10 15:02:32 +00002739 ret_val = e1000e_phy_hw_reset_generic(hw);
2740 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002741 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002742
Bruce Allan5015e532012-02-08 02:55:56 +00002743 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002744}
2745
2746/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002747 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2748 * @hw: pointer to the HW structure
2749 * @active: true to enable LPLU, false to disable
2750 *
2751 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2752 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2753 * the phy speed. This function will manually set the LPLU bit and restart
2754 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2755 * since it configures the same bit.
2756 **/
2757static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2758{
Bruce Allan70806a72013-01-05 05:08:37 +00002759 s32 ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002760 u16 oem_reg;
2761
2762 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2763 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002764 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002765
2766 if (active)
2767 oem_reg |= HV_OEM_BITS_LPLU;
2768 else
2769 oem_reg &= ~HV_OEM_BITS_LPLU;
2770
Bruce Allan44abd5c2012-02-22 09:02:37 +00002771 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002772 oem_reg |= HV_OEM_BITS_RESTART_AN;
2773
Bruce Allan5015e532012-02-08 02:55:56 +00002774 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002775}
2776
2777/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002778 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2779 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002780 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002781 *
2782 * Sets the LPLU D0 state according to the active flag. When
2783 * activating LPLU this function also disables smart speed
2784 * and vice versa. LPLU will not be activated unless the
2785 * device autonegotiation advertisement meets standards of
2786 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2787 * This is a function pointer entry point only called by
2788 * PHY setup routines.
2789 **/
2790static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2791{
2792 struct e1000_phy_info *phy = &hw->phy;
2793 u32 phy_ctrl;
2794 s32 ret_val = 0;
2795 u16 data;
2796
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002797 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002798 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002799
2800 phy_ctrl = er32(PHY_CTRL);
2801
2802 if (active) {
2803 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2804 ew32(PHY_CTRL, phy_ctrl);
2805
Bruce Allan60f12922009-07-01 13:28:14 +00002806 if (phy->type != e1000_phy_igp_3)
2807 return 0;
2808
Bruce Allane921eb12012-11-28 09:28:37 +00002809 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002810 * any PHY registers
2811 */
Bruce Allan60f12922009-07-01 13:28:14 +00002812 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813 e1000e_gig_downshift_workaround_ich8lan(hw);
2814
2815 /* When LPLU is enabled, we should disable SmartSpeed */
2816 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00002817 if (ret_val)
2818 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002819 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2820 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2821 if (ret_val)
2822 return ret_val;
2823 } else {
2824 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2825 ew32(PHY_CTRL, phy_ctrl);
2826
Bruce Allan60f12922009-07-01 13:28:14 +00002827 if (phy->type != e1000_phy_igp_3)
2828 return 0;
2829
Bruce Allane921eb12012-11-28 09:28:37 +00002830 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 * during Dx states where the power conservation is most
2832 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002833 * SmartSpeed, so performance is maintained.
2834 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835 if (phy->smart_speed == e1000_smart_speed_on) {
2836 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002837 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838 if (ret_val)
2839 return ret_val;
2840
2841 data |= IGP01E1000_PSCFR_SMART_SPEED;
2842 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002843 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002844 if (ret_val)
2845 return ret_val;
2846 } else if (phy->smart_speed == e1000_smart_speed_off) {
2847 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002848 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002849 if (ret_val)
2850 return ret_val;
2851
2852 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2853 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002854 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002855 if (ret_val)
2856 return ret_val;
2857 }
2858 }
2859
2860 return 0;
2861}
2862
2863/**
2864 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2865 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002866 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867 *
2868 * Sets the LPLU D3 state according to the active flag. When
2869 * activating LPLU this function also disables smart speed
2870 * and vice versa. LPLU will not be activated unless the
2871 * device autonegotiation advertisement meets standards of
2872 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2873 * This is a function pointer entry point only called by
2874 * PHY setup routines.
2875 **/
2876static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2877{
2878 struct e1000_phy_info *phy = &hw->phy;
2879 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002880 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002881 u16 data;
2882
2883 phy_ctrl = er32(PHY_CTRL);
2884
2885 if (!active) {
2886 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2887 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002888
2889 if (phy->type != e1000_phy_igp_3)
2890 return 0;
2891
Bruce Allane921eb12012-11-28 09:28:37 +00002892 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002893 * during Dx states where the power conservation is most
2894 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002895 * SmartSpeed, so performance is maintained.
2896 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002897 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002898 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2899 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002900 if (ret_val)
2901 return ret_val;
2902
2903 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002904 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2905 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002906 if (ret_val)
2907 return ret_val;
2908 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002909 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2910 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002911 if (ret_val)
2912 return ret_val;
2913
2914 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002915 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2916 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002917 if (ret_val)
2918 return ret_val;
2919 }
2920 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2921 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2922 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2923 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2924 ew32(PHY_CTRL, phy_ctrl);
2925
Bruce Allan60f12922009-07-01 13:28:14 +00002926 if (phy->type != e1000_phy_igp_3)
2927 return 0;
2928
Bruce Allane921eb12012-11-28 09:28:37 +00002929 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002930 * any PHY registers
2931 */
Bruce Allan60f12922009-07-01 13:28:14 +00002932 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933 e1000e_gig_downshift_workaround_ich8lan(hw);
2934
2935 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002936 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002937 if (ret_val)
2938 return ret_val;
2939
2940 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002941 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002942 }
2943
Bruce Alland7eb3382012-02-08 02:55:14 +00002944 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002945}
2946
2947/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002948 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2949 * @hw: pointer to the HW structure
2950 * @bank: pointer to the variable that returns the active bank
2951 *
2952 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002953 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002954 **/
2955static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2956{
Bruce Allane2434552008-11-21 17:02:41 -08002957 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002958 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002959 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2960 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002961 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002962 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002963
Bruce Allane2434552008-11-21 17:02:41 -08002964 switch (hw->mac.type) {
2965 case e1000_ich8lan:
2966 case e1000_ich9lan:
2967 eecd = er32(EECD);
2968 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2969 E1000_EECD_SEC1VAL_VALID_MASK) {
2970 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002971 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002972 else
2973 *bank = 0;
2974
2975 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002976 }
Bruce Allan434f1392011-12-16 00:46:54 +00002977 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002978 /* fall-thru */
2979 default:
2980 /* set bank to 0 in case flash read fails */
2981 *bank = 0;
2982
2983 /* Check bank 0 */
2984 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002985 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002986 if (ret_val)
2987 return ret_val;
2988 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2989 E1000_ICH_NVM_SIG_VALUE) {
2990 *bank = 0;
2991 return 0;
2992 }
2993
2994 /* Check bank 1 */
2995 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002996 bank1_offset,
2997 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002998 if (ret_val)
2999 return ret_val;
3000 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
3001 E1000_ICH_NVM_SIG_VALUE) {
3002 *bank = 1;
3003 return 0;
3004 }
3005
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003006 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08003007 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07003008 }
Bruce Allanf4187b52008-08-26 18:36:50 -07003009}
3010
3011/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003012 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
3013 * @hw: pointer to the HW structure
3014 * @offset: The offset (in bytes) of the word(s) to read.
3015 * @words: Size of data to read in words
3016 * @data: Pointer to the word(s) to read at offset.
3017 *
3018 * Reads a word(s) from the NVM using the flash access registers.
3019 **/
3020static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
3021 u16 *data)
3022{
3023 struct e1000_nvm_info *nvm = &hw->nvm;
3024 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3025 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00003026 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07003027 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003028 u16 i, word;
3029
3030 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
3031 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003032 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00003033 ret_val = -E1000_ERR_NVM;
3034 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003035 }
3036
Bruce Allan94d81862009-11-20 23:25:26 +00003037 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003038
Bruce Allanf4187b52008-08-26 18:36:50 -07003039 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00003040 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003041 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00003042 bank = 0;
3043 }
Bruce Allanf4187b52008-08-26 18:36:50 -07003044
3045 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003046 act_offset += offset;
3047
Bruce Allan148675a2009-08-07 07:41:56 +00003048 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003049 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00003050 if (dev_spec->shadow_ram[offset + i].modified) {
3051 data[i] = dev_spec->shadow_ram[offset + i].value;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003052 } else {
3053 ret_val = e1000_read_flash_word_ich8lan(hw,
3054 act_offset + i,
3055 &word);
3056 if (ret_val)
3057 break;
3058 data[i] = word;
3059 }
3060 }
3061
Bruce Allan94d81862009-11-20 23:25:26 +00003062 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003063
Bruce Allane2434552008-11-21 17:02:41 -08003064out:
3065 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003066 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003067
Auke Kokbc7f75f2007-09-17 12:30:59 -07003068 return ret_val;
3069}
3070
3071/**
3072 * e1000_flash_cycle_init_ich8lan - Initialize flash
3073 * @hw: pointer to the HW structure
3074 *
3075 * This function does initial flash setup so that a new read/write/erase cycle
3076 * can be started.
3077 **/
3078static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
3079{
3080 union ich8_hws_flash_status hsfsts;
3081 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003082
3083 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3084
3085 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00003086 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00003087 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003088 return -E1000_ERR_NVM;
3089 }
3090
3091 /* Clear FCERR and DAEL in hw status by writing 1 */
3092 hsfsts.hsf_status.flcerr = 1;
3093 hsfsts.hsf_status.dael = 1;
3094
3095 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3096
Bruce Allane921eb12012-11-28 09:28:37 +00003097 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07003098 * bit to check against, in order to start a new cycle or
3099 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08003100 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07003101 * indication whether a cycle is in progress or has been
3102 * completed.
3103 */
3104
Bruce Allan04499ec2012-04-13 00:08:31 +00003105 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00003106 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00003107 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07003108 * Begin by setting Flash Cycle Done.
3109 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003110 hsfsts.hsf_status.flcdone = 1;
3111 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3112 ret_val = 0;
3113 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00003114 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00003115
Bruce Allane921eb12012-11-28 09:28:37 +00003116 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07003117 * cycle has a chance to end before giving up.
3118 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003119 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00003120 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003121 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003122 ret_val = 0;
3123 break;
3124 }
3125 udelay(1);
3126 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00003127 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00003128 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07003129 * now set the Flash Cycle Done.
3130 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131 hsfsts.hsf_status.flcdone = 1;
3132 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3133 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00003134 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003135 }
3136 }
3137
3138 return ret_val;
3139}
3140
3141/**
3142 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
3143 * @hw: pointer to the HW structure
3144 * @timeout: maximum time to wait for completion
3145 *
3146 * This function starts a flash cycle and waits for its completion.
3147 **/
3148static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
3149{
3150 union ich8_hws_flash_ctrl hsflctl;
3151 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003152 u32 i = 0;
3153
3154 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
3155 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3156 hsflctl.hsf_ctrl.flcgo = 1;
3157 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3158
3159 /* wait till FDONE bit is set to 1 */
3160 do {
3161 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003162 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003163 break;
3164 udelay(1);
3165 } while (i++ < timeout);
3166
Bruce Allan04499ec2012-04-13 00:08:31 +00003167 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168 return 0;
3169
Bruce Allan55920b52012-02-08 02:55:25 +00003170 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003171}
3172
3173/**
3174 * e1000_read_flash_word_ich8lan - Read word from flash
3175 * @hw: pointer to the HW structure
3176 * @offset: offset to data location
3177 * @data: pointer to the location for storing the data
3178 *
3179 * Reads the flash word at offset into data. Offset is converted
3180 * to bytes before read.
3181 **/
3182static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
3183 u16 *data)
3184{
3185 /* Must convert offset into bytes. */
3186 offset <<= 1;
3187
3188 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
3189}
3190
3191/**
Bruce Allanf4187b52008-08-26 18:36:50 -07003192 * e1000_read_flash_byte_ich8lan - Read byte from flash
3193 * @hw: pointer to the HW structure
3194 * @offset: The offset of the byte to read.
3195 * @data: Pointer to a byte to store the value read.
3196 *
3197 * Reads a single byte from the NVM using the flash access registers.
3198 **/
3199static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3200 u8 *data)
3201{
3202 s32 ret_val;
3203 u16 word = 0;
3204
3205 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
3206 if (ret_val)
3207 return ret_val;
3208
3209 *data = (u8)word;
3210
3211 return 0;
3212}
3213
3214/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003215 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
3216 * @hw: pointer to the HW structure
3217 * @offset: The offset (in bytes) of the byte or word to read.
3218 * @size: Size of data to read, 1=byte 2=word
3219 * @data: Pointer to the word to store the value read.
3220 *
3221 * Reads a byte or word from the NVM using the flash access registers.
3222 **/
3223static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3224 u8 size, u16 *data)
3225{
3226 union ich8_hws_flash_status hsfsts;
3227 union ich8_hws_flash_ctrl hsflctl;
3228 u32 flash_linear_addr;
3229 u32 flash_data = 0;
3230 s32 ret_val = -E1000_ERR_NVM;
3231 u8 count = 0;
3232
Bruce Allane80bd1d2013-05-01 01:19:46 +00003233 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003234 return -E1000_ERR_NVM;
3235
Bruce Allanf0ff4392013-02-20 04:05:39 +00003236 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3237 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003238
3239 do {
3240 udelay(1);
3241 /* Steps */
3242 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003243 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003244 break;
3245
3246 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3247 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
3248 hsflctl.hsf_ctrl.fldbcount = size - 1;
3249 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
3250 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3251
3252 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3253
Bruce Allan17e813e2013-02-20 04:06:01 +00003254 ret_val =
3255 e1000_flash_cycle_ich8lan(hw,
3256 ICH_FLASH_READ_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003257
Bruce Allane921eb12012-11-28 09:28:37 +00003258 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07003259 * and try the whole sequence a few more times, else
3260 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07003261 * least significant byte first msb to lsb
3262 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00003263 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003264 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00003265 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003266 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00003267 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003268 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003269 break;
3270 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00003271 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07003272 * completely hosed, but if the error condition is
3273 * detected, it won't hurt to give it another try...
3274 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
3275 */
3276 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003277 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003278 /* Repeat for some time before giving up. */
3279 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003280 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003281 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003282 break;
3283 }
3284 }
3285 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3286
3287 return ret_val;
3288}
3289
3290/**
3291 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
3292 * @hw: pointer to the HW structure
3293 * @offset: The offset (in bytes) of the word(s) to write.
3294 * @words: Size of data to write in words
3295 * @data: Pointer to the word(s) to write at offset.
3296 *
3297 * Writes a byte or word to the NVM using the flash access registers.
3298 **/
3299static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
3300 u16 *data)
3301{
3302 struct e1000_nvm_info *nvm = &hw->nvm;
3303 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003304 u16 i;
3305
3306 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
3307 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003308 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003309 return -E1000_ERR_NVM;
3310 }
3311
Bruce Allan94d81862009-11-20 23:25:26 +00003312 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00003313
Auke Kokbc7f75f2007-09-17 12:30:59 -07003314 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00003315 dev_spec->shadow_ram[offset + i].modified = true;
3316 dev_spec->shadow_ram[offset + i].value = data[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07003317 }
3318
Bruce Allan94d81862009-11-20 23:25:26 +00003319 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00003320
Auke Kokbc7f75f2007-09-17 12:30:59 -07003321 return 0;
3322}
3323
3324/**
3325 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
3326 * @hw: pointer to the HW structure
3327 *
3328 * The NVM checksum is updated by calling the generic update_nvm_checksum,
3329 * which writes the checksum to the shadow ram. The changes in the shadow
3330 * ram are then committed to the EEPROM by processing each bank at a time
3331 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08003332 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07003333 * future writes.
3334 **/
3335static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
3336{
3337 struct e1000_nvm_info *nvm = &hw->nvm;
3338 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07003339 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003340 s32 ret_val;
3341 u16 data;
3342
3343 ret_val = e1000e_update_nvm_checksum_generic(hw);
3344 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08003345 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003346
3347 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08003348 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003349
Bruce Allan94d81862009-11-20 23:25:26 +00003350 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003351
Bruce Allane921eb12012-11-28 09:28:37 +00003352 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003353 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07003354 * is going to be written
3355 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003356 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08003357 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003358 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00003359 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003360 }
Bruce Allanf4187b52008-08-26 18:36:50 -07003361
3362 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003363 new_bank_offset = nvm->flash_bank_size;
3364 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003365 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003366 if (ret_val)
3367 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003368 } else {
3369 old_bank_offset = nvm->flash_bank_size;
3370 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003371 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003372 if (ret_val)
3373 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003374 }
3375
3376 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00003377 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07003378 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07003379 * in the shadow RAM
3380 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381 if (dev_spec->shadow_ram[i].modified) {
3382 data = dev_spec->shadow_ram[i].value;
3383 } else {
Bruce Allane2434552008-11-21 17:02:41 -08003384 ret_val = e1000_read_flash_word_ich8lan(hw, i +
Bruce Allanf0ff4392013-02-20 04:05:39 +00003385 old_bank_offset,
3386 &data);
Bruce Allane2434552008-11-21 17:02:41 -08003387 if (ret_val)
3388 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003389 }
3390
Bruce Allane921eb12012-11-28 09:28:37 +00003391 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07003392 * (15:14) are 11b until the commit has completed.
3393 * This will allow us to write 10b which indicates the
3394 * signature is valid. We want to do this after the write
3395 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07003396 * while the write is still in progress
3397 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003398 if (i == E1000_ICH_NVM_SIG_WORD)
3399 data |= E1000_ICH_NVM_SIG_MASK;
3400
3401 /* Convert offset to bytes. */
3402 act_offset = (i + new_bank_offset) << 1;
3403
Bruce Allance43a212013-02-20 04:06:32 +00003404 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003405 /* Write the bytes to the new bank. */
3406 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3407 act_offset,
3408 (u8)data);
3409 if (ret_val)
3410 break;
3411
Bruce Allance43a212013-02-20 04:06:32 +00003412 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003413 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003414 act_offset + 1,
3415 (u8)(data >> 8));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003416 if (ret_val)
3417 break;
3418 }
3419
Bruce Allane921eb12012-11-28 09:28:37 +00003420 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07003421 * programming failed.
3422 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07003424 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003425 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00003426 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003427 }
3428
Bruce Allane921eb12012-11-28 09:28:37 +00003429 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07003430 * to 10b in word 0x13 , this can be done without an
3431 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07003432 * and we need to change bit 14 to 0b
3433 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003434 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08003435 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003436 if (ret_val)
3437 goto release;
3438
Auke Kokbc7f75f2007-09-17 12:30:59 -07003439 data &= 0xBFFF;
3440 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3441 act_offset * 2 + 1,
3442 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00003443 if (ret_val)
3444 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003445
Bruce Allane921eb12012-11-28 09:28:37 +00003446 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07003447 * its signature word (0x13) high_byte to 0b. This can be
3448 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07003449 * to 1's. We can write 1's to 0's without an erase
3450 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003451 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
3452 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003453 if (ret_val)
3454 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003455
3456 /* Great! Everything worked, we can now clear the cached entries. */
3457 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00003458 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003459 dev_spec->shadow_ram[i].value = 0xFFFF;
3460 }
3461
Bruce Allan9c5e2092010-05-10 15:00:31 +00003462release:
Bruce Allan94d81862009-11-20 23:25:26 +00003463 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003464
Bruce Allane921eb12012-11-28 09:28:37 +00003465 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07003466 * until after the next adapter reset.
3467 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00003468 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00003469 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00003470 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003471 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003472
Bruce Allane2434552008-11-21 17:02:41 -08003473out:
3474 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003475 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003476
Auke Kokbc7f75f2007-09-17 12:30:59 -07003477 return ret_val;
3478}
3479
3480/**
3481 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3482 * @hw: pointer to the HW structure
3483 *
3484 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3485 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3486 * calculated, in which case we need to calculate the checksum and set bit 6.
3487 **/
3488static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3489{
3490 s32 ret_val;
3491 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003492 u16 word;
3493 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003494
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003495 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3496 * the checksum needs to be fixed. This bit is an indication that
3497 * the NVM was prepared by OEM software and did not calculate
3498 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003499 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003500 switch (hw->mac.type) {
3501 case e1000_pch_lpt:
3502 word = NVM_COMPAT;
3503 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3504 break;
3505 default:
3506 word = NVM_FUTURE_INIT_WORD1;
3507 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3508 break;
3509 }
3510
3511 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003512 if (ret_val)
3513 return ret_val;
3514
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003515 if (!(data & valid_csum_mask)) {
3516 data |= valid_csum_mask;
3517 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003518 if (ret_val)
3519 return ret_val;
3520 ret_val = e1000e_update_nvm_checksum(hw);
3521 if (ret_val)
3522 return ret_val;
3523 }
3524
3525 return e1000e_validate_nvm_checksum_generic(hw);
3526}
3527
3528/**
Bruce Allan4a770352008-10-01 17:18:35 -07003529 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3530 * @hw: pointer to the HW structure
3531 *
3532 * To prevent malicious write/erase of the NVM, set it to be read-only
3533 * so that the hardware ignores all write/erase cycles of the NVM via
3534 * the flash control registers. The shadow-ram copy of the NVM will
3535 * still be updated, however any updates to this copy will not stick
3536 * across driver reloads.
3537 **/
3538void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3539{
Bruce Allanca15df52009-10-26 11:23:43 +00003540 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003541 union ich8_flash_protected_range pr0;
3542 union ich8_hws_flash_status hsfsts;
3543 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003544
Bruce Allan94d81862009-11-20 23:25:26 +00003545 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003546
3547 gfpreg = er32flash(ICH_FLASH_GFPREG);
3548
3549 /* Write-protect GbE Sector of NVM */
3550 pr0.regval = er32flash(ICH_FLASH_PR0);
3551 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3552 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3553 pr0.range.wpe = true;
3554 ew32flash(ICH_FLASH_PR0, pr0.regval);
3555
Bruce Allane921eb12012-11-28 09:28:37 +00003556 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003557 * PR0 to prevent the write-protection from being lifted.
3558 * Once FLOCKDN is set, the registers protected by it cannot
3559 * be written until FLOCKDN is cleared by a hardware reset.
3560 */
3561 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3562 hsfsts.hsf_status.flockdn = true;
3563 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3564
Bruce Allan94d81862009-11-20 23:25:26 +00003565 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003566}
3567
3568/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003569 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3570 * @hw: pointer to the HW structure
3571 * @offset: The offset (in bytes) of the byte/word to read.
3572 * @size: Size of data to read, 1=byte 2=word
3573 * @data: The byte(s) to write to the NVM.
3574 *
3575 * Writes one/two bytes to the NVM using the flash access registers.
3576 **/
3577static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3578 u8 size, u16 data)
3579{
3580 union ich8_hws_flash_status hsfsts;
3581 union ich8_hws_flash_ctrl hsflctl;
3582 u32 flash_linear_addr;
3583 u32 flash_data = 0;
3584 s32 ret_val;
3585 u8 count = 0;
3586
3587 if (size < 1 || size > 2 || data > size * 0xff ||
3588 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3589 return -E1000_ERR_NVM;
3590
Bruce Allanf0ff4392013-02-20 04:05:39 +00003591 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3592 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003593
3594 do {
3595 udelay(1);
3596 /* Steps */
3597 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3598 if (ret_val)
3599 break;
3600
3601 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3602 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
Bruce Allan362e20c2013-02-20 04:05:45 +00003603 hsflctl.hsf_ctrl.fldbcount = size - 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003604 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3605 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3606
3607 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3608
3609 if (size == 1)
3610 flash_data = (u32)data & 0x00FF;
3611 else
3612 flash_data = (u32)data;
3613
3614 ew32flash(ICH_FLASH_FDATA0, flash_data);
3615
Bruce Allane921eb12012-11-28 09:28:37 +00003616 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003617 * and try the whole sequence a few more times else done
3618 */
Bruce Allan17e813e2013-02-20 04:06:01 +00003619 ret_val =
3620 e1000_flash_cycle_ich8lan(hw,
3621 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003622 if (!ret_val)
3623 break;
3624
Bruce Allane921eb12012-11-28 09:28:37 +00003625 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003626 * completely hosed, but if the error condition
3627 * is detected, it won't hurt to give it another
3628 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3629 */
3630 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003631 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003632 /* Repeat for some time before giving up. */
3633 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003634 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003635 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003636 break;
3637 }
3638 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3639
3640 return ret_val;
3641}
3642
3643/**
3644 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3645 * @hw: pointer to the HW structure
3646 * @offset: The index of the byte to read.
3647 * @data: The byte to write to the NVM.
3648 *
3649 * Writes a single byte to the NVM using the flash access registers.
3650 **/
3651static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3652 u8 data)
3653{
3654 u16 word = (u16)data;
3655
3656 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3657}
3658
3659/**
3660 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3661 * @hw: pointer to the HW structure
3662 * @offset: The offset of the byte to write.
3663 * @byte: The byte to write to the NVM.
3664 *
3665 * Writes a single byte to the NVM using the flash access registers.
3666 * Goes through a retry algorithm before giving up.
3667 **/
3668static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3669 u32 offset, u8 byte)
3670{
3671 s32 ret_val;
3672 u16 program_retries;
3673
3674 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3675 if (!ret_val)
3676 return ret_val;
3677
3678 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003679 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Bruce Allance43a212013-02-20 04:06:32 +00003680 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003681 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3682 if (!ret_val)
3683 break;
3684 }
3685 if (program_retries == 100)
3686 return -E1000_ERR_NVM;
3687
3688 return 0;
3689}
3690
3691/**
3692 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3693 * @hw: pointer to the HW structure
3694 * @bank: 0 for first bank, 1 for second bank, etc.
3695 *
3696 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3697 * bank N is 4096 * N + flash_reg_addr.
3698 **/
3699static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3700{
3701 struct e1000_nvm_info *nvm = &hw->nvm;
3702 union ich8_hws_flash_status hsfsts;
3703 union ich8_hws_flash_ctrl hsflctl;
3704 u32 flash_linear_addr;
3705 /* bank size is in 16bit words - adjust to bytes */
3706 u32 flash_bank_size = nvm->flash_bank_size * 2;
3707 s32 ret_val;
3708 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003709 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003710
3711 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3712
Bruce Allane921eb12012-11-28 09:28:37 +00003713 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003714 * register
3715 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003716 * consecutive sectors. The start index for the nth Hw sector
3717 * can be calculated as = bank * 4096 + n * 256
3718 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3719 * The start index for the nth Hw sector can be calculated
3720 * as = bank * 4096
3721 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3722 * (ich9 only, otherwise error condition)
3723 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3724 */
3725 switch (hsfsts.hsf_status.berasesz) {
3726 case 0:
3727 /* Hw sector size 256 */
3728 sector_size = ICH_FLASH_SEG_SIZE_256;
3729 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3730 break;
3731 case 1:
3732 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003733 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003734 break;
3735 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003736 sector_size = ICH_FLASH_SEG_SIZE_8K;
3737 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003738 break;
3739 case 3:
3740 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003741 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003742 break;
3743 default:
3744 return -E1000_ERR_NVM;
3745 }
3746
3747 /* Start with the base address, then add the sector offset. */
3748 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003749 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003750
Bruce Allan53aa82d2013-02-20 04:06:06 +00003751 for (j = 0; j < iteration; j++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003752 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00003753 u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
3754
Auke Kokbc7f75f2007-09-17 12:30:59 -07003755 /* Steps */
3756 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3757 if (ret_val)
3758 return ret_val;
3759
Bruce Allane921eb12012-11-28 09:28:37 +00003760 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003761 * Cycle field in hw flash control
3762 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003763 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3764 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3765 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3766
Bruce Allane921eb12012-11-28 09:28:37 +00003767 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003768 * block into Flash Linear address field in Flash
3769 * Address.
3770 */
3771 flash_linear_addr += (j * sector_size);
3772 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3773
Bruce Allan17e813e2013-02-20 04:06:01 +00003774 ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003775 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003776 break;
3777
Bruce Allane921eb12012-11-28 09:28:37 +00003778 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003779 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003780 * a few more times else Done
3781 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003782 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003783 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003784 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003785 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003786 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003787 return ret_val;
3788 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3789 }
3790
3791 return 0;
3792}
3793
3794/**
3795 * e1000_valid_led_default_ich8lan - Set the default LED settings
3796 * @hw: pointer to the HW structure
3797 * @data: Pointer to the LED settings
3798 *
3799 * Reads the LED default settings from the NVM to data. If the NVM LED
3800 * settings is all 0's or F's, set the LED default to a valid LED default
3801 * setting.
3802 **/
3803static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3804{
3805 s32 ret_val;
3806
3807 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3808 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003809 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003810 return ret_val;
3811 }
3812
Bruce Allane5fe2542013-02-20 04:06:27 +00003813 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003814 *data = ID_LED_DEFAULT_ICH8LAN;
3815
3816 return 0;
3817}
3818
3819/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003820 * e1000_id_led_init_pchlan - store LED configurations
3821 * @hw: pointer to the HW structure
3822 *
3823 * PCH does not control LEDs via the LEDCTL register, rather it uses
3824 * the PHY LED configuration register.
3825 *
3826 * PCH also does not have an "always on" or "always off" mode which
3827 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003828 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003829 * use "link_up" mode. The LEDs will still ID on request if there is no
3830 * link based on logic in e1000_led_[on|off]_pchlan().
3831 **/
3832static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3833{
3834 struct e1000_mac_info *mac = &hw->mac;
3835 s32 ret_val;
3836 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3837 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3838 u16 data, i, temp, shift;
3839
3840 /* Get default ID LED modes */
3841 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3842 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003843 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003844
3845 mac->ledctl_default = er32(LEDCTL);
3846 mac->ledctl_mode1 = mac->ledctl_default;
3847 mac->ledctl_mode2 = mac->ledctl_default;
3848
3849 for (i = 0; i < 4; i++) {
3850 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3851 shift = (i * 5);
3852 switch (temp) {
3853 case ID_LED_ON1_DEF2:
3854 case ID_LED_ON1_ON2:
3855 case ID_LED_ON1_OFF2:
3856 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3857 mac->ledctl_mode1 |= (ledctl_on << shift);
3858 break;
3859 case ID_LED_OFF1_DEF2:
3860 case ID_LED_OFF1_ON2:
3861 case ID_LED_OFF1_OFF2:
3862 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3863 mac->ledctl_mode1 |= (ledctl_off << shift);
3864 break;
3865 default:
3866 /* Do nothing */
3867 break;
3868 }
3869 switch (temp) {
3870 case ID_LED_DEF1_ON2:
3871 case ID_LED_ON1_ON2:
3872 case ID_LED_OFF1_ON2:
3873 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3874 mac->ledctl_mode2 |= (ledctl_on << shift);
3875 break;
3876 case ID_LED_DEF1_OFF2:
3877 case ID_LED_ON1_OFF2:
3878 case ID_LED_OFF1_OFF2:
3879 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3880 mac->ledctl_mode2 |= (ledctl_off << shift);
3881 break;
3882 default:
3883 /* Do nothing */
3884 break;
3885 }
3886 }
3887
Bruce Allan5015e532012-02-08 02:55:56 +00003888 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003889}
3890
3891/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003892 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3893 * @hw: pointer to the HW structure
3894 *
3895 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3896 * register, so the the bus width is hard coded.
3897 **/
3898static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3899{
3900 struct e1000_bus_info *bus = &hw->bus;
3901 s32 ret_val;
3902
3903 ret_val = e1000e_get_bus_info_pcie(hw);
3904
Bruce Allane921eb12012-11-28 09:28:37 +00003905 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906 * a configuration space, but do not contain
3907 * PCI Express Capability registers, so bus width
3908 * must be hardcoded.
3909 */
3910 if (bus->width == e1000_bus_width_unknown)
3911 bus->width = e1000_bus_width_pcie_x1;
3912
3913 return ret_val;
3914}
3915
3916/**
3917 * e1000_reset_hw_ich8lan - Reset the hardware
3918 * @hw: pointer to the HW structure
3919 *
3920 * Does a full reset of the hardware which includes a reset of the PHY and
3921 * MAC.
3922 **/
3923static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3924{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003925 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003926 u16 kum_cfg;
3927 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003928 s32 ret_val;
3929
Bruce Allane921eb12012-11-28 09:28:37 +00003930 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003931 * on the last TLP read/write transaction when MAC is reset.
3932 */
3933 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003934 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003935 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003936
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003937 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938 ew32(IMC, 0xffffffff);
3939
Bruce Allane921eb12012-11-28 09:28:37 +00003940 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941 * any pending transactions to complete before we hit the MAC
3942 * with the global reset.
3943 */
3944 ew32(RCTL, 0);
3945 ew32(TCTL, E1000_TCTL_PSP);
3946 e1e_flush();
3947
Bruce Allan1bba4382011-03-19 00:27:20 +00003948 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003949
3950 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3951 if (hw->mac.type == e1000_ich8lan) {
3952 /* Set Tx and Rx buffer allocation to 8k apiece. */
3953 ew32(PBA, E1000_PBA_8K);
3954 /* Set Packet Buffer Size to 16k. */
3955 ew32(PBS, E1000_PBS_16K);
3956 }
3957
Bruce Allan1d5846b2009-10-29 13:46:05 +00003958 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003959 /* Save the NVM K1 bit setting */
3960 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003961 if (ret_val)
3962 return ret_val;
3963
Bruce Allan62bc8132012-03-20 03:47:57 +00003964 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003965 dev_spec->nvm_k1_enabled = true;
3966 else
3967 dev_spec->nvm_k1_enabled = false;
3968 }
3969
Auke Kokbc7f75f2007-09-17 12:30:59 -07003970 ctrl = er32(CTRL);
3971
Bruce Allan44abd5c2012-02-22 09:02:37 +00003972 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003973 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003974 * time to make sure the interface between MAC and the
3975 * external PHY is reset.
3976 */
3977 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003978
Bruce Allane921eb12012-11-28 09:28:37 +00003979 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003980 * non-managed 82579
3981 */
3982 if ((hw->mac.type == e1000_pch2lan) &&
3983 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3984 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003985 }
3986 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003987 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003988 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003989 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003990 msleep(20);
3991
Bruce Allan62bc8132012-03-20 03:47:57 +00003992 /* Set Phy Config Counter to 50msec */
3993 if (hw->mac.type == e1000_pch2lan) {
3994 reg = er32(FEXTNVM3);
3995 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3996 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3997 ew32(FEXTNVM3, reg);
3998 }
3999
Bruce Allanfc0c7762009-07-01 13:27:55 +00004000 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00004001 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07004002
Bruce Allane98cac42010-05-10 15:02:32 +00004003 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00004004 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00004005 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00004006 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004007
Bruce Allane98cac42010-05-10 15:02:32 +00004008 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00004009 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00004010 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00004011 }
Bruce Allane98cac42010-05-10 15:02:32 +00004012
Bruce Allane921eb12012-11-28 09:28:37 +00004013 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004014 * will be detected as a CRC error and be dropped rather than show up
4015 * as a bad packet to the DMA engine.
4016 */
4017 if (hw->mac.type == e1000_pchlan)
4018 ew32(CRC_OFFSET, 0x65656565);
4019
Auke Kokbc7f75f2007-09-17 12:30:59 -07004020 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00004021 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004022
Bruce Allan62bc8132012-03-20 03:47:57 +00004023 reg = er32(KABGTXD);
4024 reg |= E1000_KABGTXD_BGSQLBIAS;
4025 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004026
Bruce Allan5015e532012-02-08 02:55:56 +00004027 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004028}
4029
4030/**
4031 * e1000_init_hw_ich8lan - Initialize the hardware
4032 * @hw: pointer to the HW structure
4033 *
4034 * Prepares the hardware for transmit and receive by doing the following:
4035 * - initialize hardware bits
4036 * - initialize LED identification
4037 * - setup receive address registers
4038 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08004039 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07004040 * - clear statistics
4041 **/
4042static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
4043{
4044 struct e1000_mac_info *mac = &hw->mac;
4045 u32 ctrl_ext, txdctl, snoop;
4046 s32 ret_val;
4047 u16 i;
4048
4049 e1000_initialize_hw_bits_ich8lan(hw);
4050
4051 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00004052 ret_val = mac->ops.id_led_init(hw);
Bruce Allan33550ce2013-02-20 04:06:16 +00004053 /* An error is not fatal and we should not stop init due to this */
Bruce Allande39b752009-11-20 23:27:59 +00004054 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004055 e_dbg("Error initializing identification LED\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004056
4057 /* Setup the receive address. */
4058 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
4059
4060 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004061 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004062 for (i = 0; i < mac->mta_reg_count; i++)
4063 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
4064
Bruce Allane921eb12012-11-28 09:28:37 +00004065 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00004066 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00004067 * Reset the phy after disabling host wakeup to reset the Rx buffer.
4068 */
4069 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00004070 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
4071 i &= ~BM_WUC_HOST_WU_BIT;
4072 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00004073 ret_val = e1000_phy_hw_reset_ich8lan(hw);
4074 if (ret_val)
4075 return ret_val;
4076 }
4077
Auke Kokbc7f75f2007-09-17 12:30:59 -07004078 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00004079 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004080
4081 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004082 txdctl = er32(TXDCTL(0));
Bruce Allanf0ff4392013-02-20 04:05:39 +00004083 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
4084 E1000_TXDCTL_FULL_TX_DESC_WB);
4085 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
4086 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004087 ew32(TXDCTL(0), txdctl);
4088 txdctl = er32(TXDCTL(1));
Bruce Allanf0ff4392013-02-20 04:05:39 +00004089 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
4090 E1000_TXDCTL_FULL_TX_DESC_WB);
4091 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
4092 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004093 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004094
Bruce Allane921eb12012-11-28 09:28:37 +00004095 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07004096 * By default, we should use snoop behavior.
4097 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004098 if (mac->type == e1000_ich8lan)
4099 snoop = PCIE_ICH8_SNOOP_ALL;
4100 else
Bruce Allan53aa82d2013-02-20 04:06:06 +00004101 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004102 e1000e_set_pcie_no_snoop(hw, snoop);
4103
4104 ctrl_ext = er32(CTRL_EXT);
4105 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
4106 ew32(CTRL_EXT, ctrl_ext);
4107
Bruce Allane921eb12012-11-28 09:28:37 +00004108 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07004109 * important that we do this after we have tried to establish link
4110 * because the symbol error count will increment wildly if there
4111 * is no link.
4112 */
4113 e1000_clear_hw_cntrs_ich8lan(hw);
4114
Bruce Allane561a702012-02-08 02:55:46 +00004115 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004116}
Bruce Allanfc830b72013-02-20 04:06:11 +00004117
Auke Kokbc7f75f2007-09-17 12:30:59 -07004118/**
4119 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
4120 * @hw: pointer to the HW structure
4121 *
4122 * Sets/Clears required hardware bits necessary for correctly setting up the
4123 * hardware for transmit and receive.
4124 **/
4125static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
4126{
4127 u32 reg;
4128
4129 /* Extended Device Control */
4130 reg = er32(CTRL_EXT);
4131 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00004132 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
4133 if (hw->mac.type >= e1000_pchlan)
4134 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004135 ew32(CTRL_EXT, reg);
4136
4137 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004138 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004139 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004140 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004141
4142 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004143 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004144 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004145 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004146
4147 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004148 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004149 if (hw->mac.type == e1000_ich8lan)
4150 reg |= (1 << 28) | (1 << 29);
4151 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004152 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004153
4154 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004155 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004156 if (er32(TCTL) & E1000_TCTL_MULR)
4157 reg &= ~(1 << 28);
4158 else
4159 reg |= (1 << 28);
4160 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07004161 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004162
4163 /* Device Status */
4164 if (hw->mac.type == e1000_ich8lan) {
4165 reg = er32(STATUS);
4166 reg &= ~(1 << 31);
4167 ew32(STATUS, reg);
4168 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00004169
Bruce Allane921eb12012-11-28 09:28:37 +00004170 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00004171 * traffic, just disable the nfs filtering capability
4172 */
4173 reg = er32(RFCTL);
4174 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00004175
Bruce Allane921eb12012-11-28 09:28:37 +00004176 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00004177 * IPv6 headers can hang the Rx.
4178 */
4179 if (hw->mac.type == e1000_ich8lan)
4180 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00004181 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00004182
4183 /* Enable ECC on Lynxpoint */
4184 if (hw->mac.type == e1000_pch_lpt) {
4185 reg = er32(PBECCSTS);
4186 reg |= E1000_PBECCSTS_ECC_ENABLE;
4187 ew32(PBECCSTS, reg);
4188
4189 reg = er32(CTRL);
4190 reg |= E1000_CTRL_MEHE;
4191 ew32(CTRL, reg);
4192 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004193}
4194
4195/**
4196 * e1000_setup_link_ich8lan - Setup flow control and link settings
4197 * @hw: pointer to the HW structure
4198 *
4199 * Determines which flow control settings to use, then configures flow
4200 * control. Calls the appropriate media-specific link configuration
4201 * function. Assuming the adapter has a valid link partner, a valid link
4202 * should be established. Assumes the hardware has previously been reset
4203 * and the transmitter and receiver are not enabled.
4204 **/
4205static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
4206{
Auke Kokbc7f75f2007-09-17 12:30:59 -07004207 s32 ret_val;
4208
Bruce Allan44abd5c2012-02-22 09:02:37 +00004209 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004210 return 0;
4211
Bruce Allane921eb12012-11-28 09:28:37 +00004212 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07004213 * the default flow control setting, so we explicitly
4214 * set it to full.
4215 */
Bruce Allan37289d92009-06-02 11:29:37 +00004216 if (hw->fc.requested_mode == e1000_fc_default) {
4217 /* Workaround h/w hang when Tx flow control enabled */
4218 if (hw->mac.type == e1000_pchlan)
4219 hw->fc.requested_mode = e1000_fc_rx_pause;
4220 else
4221 hw->fc.requested_mode = e1000_fc_full;
4222 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004223
Bruce Allane921eb12012-11-28 09:28:37 +00004224 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08004225 * on the link partner's capabilities, we may or may not use this mode.
4226 */
4227 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004228
Bruce Allan17e813e2013-02-20 04:06:01 +00004229 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004230
4231 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00004232 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004233 if (ret_val)
4234 return ret_val;
4235
Jeff Kirsher318a94d2008-03-28 09:15:16 -07004236 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00004237 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004238 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004239 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004240 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00004241 ew32(FCRTV_PCH, hw->fc.refresh_time);
4242
Bruce Allan482fed82011-01-06 14:29:49 +00004243 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
4244 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00004245 if (ret_val)
4246 return ret_val;
4247 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004248
4249 return e1000e_set_fc_watermarks(hw);
4250}
4251
4252/**
4253 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
4254 * @hw: pointer to the HW structure
4255 *
4256 * Configures the kumeran interface to the PHY to wait the appropriate time
4257 * when polling the PHY, then call the generic setup_copper_link to finish
4258 * configuring the copper link.
4259 **/
4260static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
4261{
4262 u32 ctrl;
4263 s32 ret_val;
4264 u16 reg_data;
4265
4266 ctrl = er32(CTRL);
4267 ctrl |= E1000_CTRL_SLU;
4268 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
4269 ew32(CTRL, ctrl);
4270
Bruce Allane921eb12012-11-28 09:28:37 +00004271 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07004272 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07004273 * this fixes erroneous timeouts at 10Mbps.
4274 */
Bruce Allan07818952009-12-08 07:28:01 +00004275 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004276 if (ret_val)
4277 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00004278 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00004279 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004280 if (ret_val)
4281 return ret_val;
4282 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00004283 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00004284 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004285 if (ret_val)
4286 return ret_val;
4287
Bruce Allana4f58f52009-06-02 11:29:18 +00004288 switch (hw->phy.type) {
4289 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07004290 ret_val = e1000e_copper_link_setup_igp(hw);
4291 if (ret_val)
4292 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00004293 break;
4294 case e1000_phy_bm:
4295 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004296 ret_val = e1000e_copper_link_setup_m88(hw);
4297 if (ret_val)
4298 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00004299 break;
4300 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00004301 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00004302 ret_val = e1000_copper_link_setup_82577(hw);
4303 if (ret_val)
4304 return ret_val;
4305 break;
4306 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00004307 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004308 if (ret_val)
4309 return ret_val;
4310
4311 reg_data &= ~IFE_PMC_AUTO_MDIX;
4312
4313 switch (hw->phy.mdix) {
4314 case 1:
4315 reg_data &= ~IFE_PMC_FORCE_MDIX;
4316 break;
4317 case 2:
4318 reg_data |= IFE_PMC_FORCE_MDIX;
4319 break;
4320 case 0:
4321 default:
4322 reg_data |= IFE_PMC_AUTO_MDIX;
4323 break;
4324 }
Bruce Allan482fed82011-01-06 14:29:49 +00004325 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004326 if (ret_val)
4327 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00004328 break;
4329 default:
4330 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004331 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00004332
Auke Kokbc7f75f2007-09-17 12:30:59 -07004333 return e1000e_setup_copper_link(hw);
4334}
4335
4336/**
Bruce Allanea8179a2013-03-06 09:02:47 +00004337 * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
4338 * @hw: pointer to the HW structure
4339 *
4340 * Calls the PHY specific link setup function and then calls the
4341 * generic setup_copper_link to finish configuring the link for
4342 * Lynxpoint PCH devices
4343 **/
4344static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
4345{
4346 u32 ctrl;
4347 s32 ret_val;
4348
4349 ctrl = er32(CTRL);
4350 ctrl |= E1000_CTRL_SLU;
4351 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
4352 ew32(CTRL, ctrl);
4353
4354 ret_val = e1000_copper_link_setup_82577(hw);
4355 if (ret_val)
4356 return ret_val;
4357
4358 return e1000e_setup_copper_link(hw);
4359}
4360
4361/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004362 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
4363 * @hw: pointer to the HW structure
4364 * @speed: pointer to store current link speed
4365 * @duplex: pointer to store the current link duplex
4366 *
Bruce Allanad680762008-03-28 09:15:03 -07004367 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07004368 * information and then calls the Kumeran lock loss workaround for links at
4369 * gigabit speeds.
4370 **/
4371static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
4372 u16 *duplex)
4373{
4374 s32 ret_val;
4375
4376 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
4377 if (ret_val)
4378 return ret_val;
4379
4380 if ((hw->mac.type == e1000_ich8lan) &&
Bruce Allane5fe2542013-02-20 04:06:27 +00004381 (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004382 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
4383 }
4384
4385 return ret_val;
4386}
4387
4388/**
4389 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
4390 * @hw: pointer to the HW structure
4391 *
4392 * Work-around for 82566 Kumeran PCS lock loss:
4393 * On link status change (i.e. PCI reset, speed change) and link is up and
4394 * speed is gigabit-
4395 * 0) if workaround is optionally disabled do nothing
4396 * 1) wait 1ms for Kumeran link to come up
4397 * 2) check Kumeran Diagnostic register PCS lock loss bit
4398 * 3) if not set the link is locked (all is good), otherwise...
4399 * 4) reset the PHY
4400 * 5) repeat up to 10 times
4401 * Note: this is only called for IGP3 copper when speed is 1gb.
4402 **/
4403static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
4404{
4405 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4406 u32 phy_ctrl;
4407 s32 ret_val;
4408 u16 i, data;
4409 bool link;
4410
4411 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
4412 return 0;
4413
Bruce Allane921eb12012-11-28 09:28:37 +00004414 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004415 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07004416 * stability
4417 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004418 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
4419 if (!link)
4420 return 0;
4421
4422 for (i = 0; i < 10; i++) {
4423 /* read once to clear */
4424 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4425 if (ret_val)
4426 return ret_val;
4427 /* and again to get new status */
4428 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4429 if (ret_val)
4430 return ret_val;
4431
4432 /* check for PCS lock */
4433 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4434 return 0;
4435
4436 /* Issue PHY reset */
4437 e1000_phy_hw_reset(hw);
4438 mdelay(5);
4439 }
4440 /* Disable GigE link negotiation */
4441 phy_ctrl = er32(PHY_CTRL);
4442 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
4443 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4444 ew32(PHY_CTRL, phy_ctrl);
4445
Bruce Allane921eb12012-11-28 09:28:37 +00004446 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07004447 * any PHY registers
4448 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004449 e1000e_gig_downshift_workaround_ich8lan(hw);
4450
4451 /* unable to acquire PCS lock */
4452 return -E1000_ERR_PHY;
4453}
4454
4455/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00004456 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004457 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08004458 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004459 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00004460 * If ICH8, set the current Kumeran workaround state (enabled - true
4461 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07004462 **/
4463void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004464 bool state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004465{
4466 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4467
4468 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004469 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004470 return;
4471 }
4472
4473 dev_spec->kmrn_lock_loss_workaround_enabled = state;
4474}
4475
4476/**
4477 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
4478 * @hw: pointer to the HW structure
4479 *
4480 * Workaround for 82566 power-down on D3 entry:
4481 * 1) disable gigabit link
4482 * 2) write VR power-down enable
4483 * 3) read it back
4484 * Continue if successful, else issue LCD reset and repeat
4485 **/
4486void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
4487{
4488 u32 reg;
4489 u16 data;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004490 u8 retry = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004491
4492 if (hw->phy.type != e1000_phy_igp_3)
4493 return;
4494
4495 /* Try the workaround twice (if needed) */
4496 do {
4497 /* Disable link */
4498 reg = er32(PHY_CTRL);
4499 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4500 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4501 ew32(PHY_CTRL, reg);
4502
Bruce Allane921eb12012-11-28 09:28:37 +00004503 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07004504 * accessing any PHY registers
4505 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004506 if (hw->mac.type == e1000_ich8lan)
4507 e1000e_gig_downshift_workaround_ich8lan(hw);
4508
4509 /* Write VR power-down enable */
4510 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4511 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4512 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4513
4514 /* Read it back and test */
4515 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4516 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4517 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4518 break;
4519
4520 /* Issue PHY reset and repeat at most one more time */
4521 reg = er32(CTRL);
4522 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4523 retry++;
4524 } while (retry);
4525}
4526
4527/**
4528 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4529 * @hw: pointer to the HW structure
4530 *
4531 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004532 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004533 * 1) Set Kumeran Near-end loopback
4534 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004535 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004536 **/
4537void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4538{
4539 s32 ret_val;
4540 u16 reg_data;
4541
Bruce Allan462d5992011-09-30 08:07:11 +00004542 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004543 return;
4544
4545 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004546 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004547 if (ret_val)
4548 return;
4549 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4550 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004551 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004552 if (ret_val)
4553 return;
4554 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00004555 e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004556}
4557
4558/**
Bruce Allan99730e42011-05-13 07:19:48 +00004559 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004560 * @hw: pointer to the HW structure
4561 *
4562 * During S0 to Sx transition, it is possible the link remains at gig
4563 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004564 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4565 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4566 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4567 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004568 * Parts that support (and are linked to a partner which support) EEE in
4569 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4570 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004571 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004572void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004573{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004574 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004575 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004576 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004577
Bruce Allan17f085d2010-06-17 18:59:48 +00004578 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004579 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allane08f6262013-02-20 03:06:34 +00004580
Bruce Allan2fbe4522012-04-19 03:21:47 +00004581 if (hw->phy.type == e1000_phy_i217) {
Bruce Allane08f6262013-02-20 03:06:34 +00004582 u16 phy_reg, device_id = hw->adapter->pdev->device;
4583
4584 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
Bruce Allan91a3d822013-06-29 01:15:16 +00004585 (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
4586 (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
4587 (device_id == E1000_DEV_ID_PCH_I218_V3)) {
Bruce Allane08f6262013-02-20 03:06:34 +00004588 u32 fextnvm6 = er32(FEXTNVM6);
4589
4590 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
4591 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004592
4593 ret_val = hw->phy.ops.acquire(hw);
4594 if (ret_val)
4595 goto out;
4596
4597 if (!dev_spec->eee_disable) {
4598 u16 eee_advert;
4599
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004600 ret_val =
4601 e1000_read_emi_reg_locked(hw,
4602 I217_EEE_ADVERTISEMENT,
4603 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004604 if (ret_val)
4605 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004606
Bruce Allane921eb12012-11-28 09:28:37 +00004607 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004608 * EEE and 100Full is advertised on both ends of the
4609 * link.
4610 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004611 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004612 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004613 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004614 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4615 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4616 E1000_PHY_CTRL_NOND0A_LPLU);
4617 }
4618
Bruce Allane921eb12012-11-28 09:28:37 +00004619 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004620 * when the system is going into Sx and no manageability engine
4621 * is present, the driver must configure proxy to reset only on
4622 * power good. LPI (Low Power Idle) state must also reset only
4623 * on power good, as well as the MTA (Multicast table array).
4624 * The SMBus release must also be disabled on LCD reset.
4625 */
4626 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00004627 /* Enable proxy to reset only on power good. */
4628 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4629 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4630 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4631
Bruce Allane921eb12012-11-28 09:28:37 +00004632 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004633 * power good.
4634 */
4635 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004636 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004637 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4638
4639 /* Disable the SMB release on LCD reset. */
4640 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004641 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004642 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4643 }
4644
Bruce Allane921eb12012-11-28 09:28:37 +00004645 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004646 * Support
4647 */
4648 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004649 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004650 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4651
4652release:
4653 hw->phy.ops.release(hw);
4654 }
4655out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004656 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004657
Bruce Allan462d5992011-09-30 08:07:11 +00004658 if (hw->mac.type == e1000_ich8lan)
4659 e1000e_gig_downshift_workaround_ich8lan(hw);
4660
Bruce Allan8395ae82010-09-22 17:15:08 +00004661 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004662 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004663
4664 /* Reset PHY to activate OEM bits on 82577/8 */
4665 if (hw->mac.type == e1000_pchlan)
4666 e1000e_phy_hw_reset_generic(hw);
4667
Bruce Allan8395ae82010-09-22 17:15:08 +00004668 ret_val = hw->phy.ops.acquire(hw);
4669 if (ret_val)
4670 return;
4671 e1000_write_smbus_addr(hw);
4672 hw->phy.ops.release(hw);
4673 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004674}
4675
4676/**
Bruce Allan99730e42011-05-13 07:19:48 +00004677 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4678 * @hw: pointer to the HW structure
4679 *
4680 * During Sx to S0 transitions on non-managed devices or managed devices
4681 * on which PHY resets are not blocked, if the PHY registers cannot be
4682 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4683 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004684 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004685 **/
4686void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4687{
Bruce Allan90b82982011-12-16 00:46:33 +00004688 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004689
Bruce Allancb17aab2012-04-13 03:16:22 +00004690 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004691 return;
4692
Bruce Allancb17aab2012-04-13 03:16:22 +00004693 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004694 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004695 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004696 return;
4697 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004698
Bruce Allane921eb12012-11-28 09:28:37 +00004699 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004700 * is transitioning from Sx and no manageability engine is present
4701 * configure SMBus to restore on reset, disable proxy, and enable
4702 * the reset on MTA (Multicast table array).
4703 */
4704 if (hw->phy.type == e1000_phy_i217) {
4705 u16 phy_reg;
4706
4707 ret_val = hw->phy.ops.acquire(hw);
4708 if (ret_val) {
4709 e_dbg("Failed to setup iRST\n");
4710 return;
4711 }
4712
4713 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004714 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004715 * is present
4716 */
4717 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4718 if (ret_val)
4719 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004720 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004721 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4722
4723 /* Disable Proxy */
4724 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4725 }
4726 /* Enable reset on MTA */
4727 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4728 if (ret_val)
4729 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004730 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004731 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4732release:
4733 if (ret_val)
4734 e_dbg("Error %d in resume workarounds\n", ret_val);
4735 hw->phy.ops.release(hw);
4736 }
Bruce Allan99730e42011-05-13 07:19:48 +00004737}
4738
4739/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004740 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4741 * @hw: pointer to the HW structure
4742 *
4743 * Return the LED back to the default configuration.
4744 **/
4745static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4746{
4747 if (hw->phy.type == e1000_phy_ife)
4748 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4749
4750 ew32(LEDCTL, hw->mac.ledctl_default);
4751 return 0;
4752}
4753
4754/**
Auke Kok489815c2008-02-21 15:11:07 -08004755 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004756 * @hw: pointer to the HW structure
4757 *
Auke Kok489815c2008-02-21 15:11:07 -08004758 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004759 **/
4760static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4761{
4762 if (hw->phy.type == e1000_phy_ife)
4763 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4764 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4765
4766 ew32(LEDCTL, hw->mac.ledctl_mode2);
4767 return 0;
4768}
4769
4770/**
Auke Kok489815c2008-02-21 15:11:07 -08004771 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004772 * @hw: pointer to the HW structure
4773 *
Auke Kok489815c2008-02-21 15:11:07 -08004774 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004775 **/
4776static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4777{
4778 if (hw->phy.type == e1000_phy_ife)
4779 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004780 (IFE_PSCL_PROBE_MODE |
4781 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004782
4783 ew32(LEDCTL, hw->mac.ledctl_mode1);
4784 return 0;
4785}
4786
4787/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004788 * e1000_setup_led_pchlan - Configures SW controllable LED
4789 * @hw: pointer to the HW structure
4790 *
4791 * This prepares the SW controllable LED for use.
4792 **/
4793static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4794{
Bruce Allan482fed82011-01-06 14:29:49 +00004795 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004796}
4797
4798/**
4799 * e1000_cleanup_led_pchlan - Restore the default LED operation
4800 * @hw: pointer to the HW structure
4801 *
4802 * Return the LED back to the default configuration.
4803 **/
4804static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4805{
Bruce Allan482fed82011-01-06 14:29:49 +00004806 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004807}
4808
4809/**
4810 * e1000_led_on_pchlan - Turn LEDs on
4811 * @hw: pointer to the HW structure
4812 *
4813 * Turn on the LEDs.
4814 **/
4815static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4816{
4817 u16 data = (u16)hw->mac.ledctl_mode2;
4818 u32 i, led;
4819
Bruce Allane921eb12012-11-28 09:28:37 +00004820 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004821 * for each LED that's mode is "link_up" in ledctl_mode2.
4822 */
4823 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4824 for (i = 0; i < 3; i++) {
4825 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4826 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4827 E1000_LEDCTL_MODE_LINK_UP)
4828 continue;
4829 if (led & E1000_PHY_LED0_IVRT)
4830 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4831 else
4832 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4833 }
4834 }
4835
Bruce Allan482fed82011-01-06 14:29:49 +00004836 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004837}
4838
4839/**
4840 * e1000_led_off_pchlan - Turn LEDs off
4841 * @hw: pointer to the HW structure
4842 *
4843 * Turn off the LEDs.
4844 **/
4845static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4846{
4847 u16 data = (u16)hw->mac.ledctl_mode1;
4848 u32 i, led;
4849
Bruce Allane921eb12012-11-28 09:28:37 +00004850 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004851 * for each LED that's mode is "link_up" in ledctl_mode1.
4852 */
4853 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4854 for (i = 0; i < 3; i++) {
4855 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4856 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4857 E1000_LEDCTL_MODE_LINK_UP)
4858 continue;
4859 if (led & E1000_PHY_LED0_IVRT)
4860 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4861 else
4862 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4863 }
4864 }
4865
Bruce Allan482fed82011-01-06 14:29:49 +00004866 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004867}
4868
4869/**
Bruce Allane98cac42010-05-10 15:02:32 +00004870 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004871 * @hw: pointer to the HW structure
4872 *
Bruce Allane98cac42010-05-10 15:02:32 +00004873 * Read appropriate register for the config done bit for completion status
4874 * and configure the PHY through s/w for EEPROM-less parts.
4875 *
4876 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4877 * config done bit, so only an error is logged and continues. If we were
4878 * to return with error, EEPROM-less silicon would not be able to be reset
4879 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004880 **/
4881static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4882{
Bruce Allane98cac42010-05-10 15:02:32 +00004883 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004884 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004885 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004886
Bruce Allanfe908492013-01-05 08:06:14 +00004887 e1000e_get_cfg_done_generic(hw);
Bruce Allanf4187b52008-08-26 18:36:50 -07004888
Bruce Allane98cac42010-05-10 15:02:32 +00004889 /* Wait for indication from h/w that it has completed basic config */
4890 if (hw->mac.type >= e1000_ich10lan) {
4891 e1000_lan_init_done_ich8lan(hw);
4892 } else {
4893 ret_val = e1000e_get_auto_rd_done(hw);
4894 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004895 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004896 * return with an error. This can happen in situations
4897 * where there is no eeprom and prevents getting link.
4898 */
4899 e_dbg("Auto Read Done did not complete\n");
4900 ret_val = 0;
4901 }
4902 }
4903
4904 /* Clear PHY Reset Asserted bit */
4905 status = er32(STATUS);
4906 if (status & E1000_STATUS_PHYRA)
4907 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4908 else
4909 e_dbg("PHY Reset Asserted not set - needs delay\n");
4910
Bruce Allanf4187b52008-08-26 18:36:50 -07004911 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004912 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004913 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004914 (hw->phy.type == e1000_phy_igp_3)) {
4915 e1000e_phy_init_script_igp3(hw);
4916 }
4917 } else {
4918 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4919 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004920 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004921 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004922 }
4923 }
4924
Bruce Allane98cac42010-05-10 15:02:32 +00004925 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004926}
4927
4928/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004929 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4930 * @hw: pointer to the HW structure
4931 *
4932 * In the case of a PHY power down to save power, or to turn off link during a
4933 * driver unload, or wake on lan is not enabled, remove the link.
4934 **/
4935static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4936{
4937 /* If the management interface is not enabled, then power down */
4938 if (!(hw->mac.ops.check_mng_mode(hw) ||
4939 hw->phy.ops.check_reset_block(hw)))
4940 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004941}
4942
4943/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004944 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4945 * @hw: pointer to the HW structure
4946 *
4947 * Clears hardware counters specific to the silicon family and calls
4948 * clear_hw_cntrs_generic to clear all general purpose counters.
4949 **/
4950static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4951{
Bruce Allana4f58f52009-06-02 11:29:18 +00004952 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004953 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004954
4955 e1000e_clear_hw_cntrs_base(hw);
4956
Bruce Allan99673d92009-11-20 23:27:21 +00004957 er32(ALGNERRC);
4958 er32(RXERRC);
4959 er32(TNCRS);
4960 er32(CEXTERR);
4961 er32(TSCTC);
4962 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004963
Bruce Allan99673d92009-11-20 23:27:21 +00004964 er32(MGTPRC);
4965 er32(MGTPDC);
4966 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004967
Bruce Allan99673d92009-11-20 23:27:21 +00004968 er32(IAC);
4969 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004970
Bruce Allana4f58f52009-06-02 11:29:18 +00004971 /* Clear PHY statistics registers */
4972 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004973 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004974 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004975 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004976 ret_val = hw->phy.ops.acquire(hw);
4977 if (ret_val)
4978 return;
4979 ret_val = hw->phy.ops.set_page(hw,
4980 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4981 if (ret_val)
4982 goto release;
4983 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4984 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4985 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4986 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4987 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4988 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4989 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4990 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4991 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4992 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4993 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4994 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4995 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4996 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4997release:
4998 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004999 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07005000}
5001
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005002static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00005003 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00005004 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00005005 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07005006 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
5007 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00005008 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005009 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00005010 /* led_on dependent on mac type */
5011 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07005012 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005013 .reset_hw = e1000_reset_hw_ich8lan,
5014 .init_hw = e1000_init_hw_ich8lan,
5015 .setup_link = e1000_setup_link_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00005016 .setup_physical_interface = e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00005017 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00005018 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00005019 .rar_set = e1000e_rar_set_generic,
David Ertmanb3e5bf12014-05-06 03:50:17 +00005020 .rar_get_count = e1000e_rar_get_count_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005021};
5022
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005023static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00005024 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005025 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00005026 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07005027 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005028 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00005029 .read_reg = e1000e_read_phy_reg_igp,
5030 .release = e1000_release_swflag_ich8lan,
5031 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005032 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
5033 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00005034 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005035};
5036
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005037static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00005038 .acquire = e1000_acquire_nvm_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00005039 .read = e1000_read_nvm_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00005040 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00005041 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00005042 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005043 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00005044 .validate = e1000_validate_nvm_checksum_ich8lan,
5045 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005046};
5047
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005048const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005049 .mac = e1000_ich8lan,
5050 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005051 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07005052 | FLAG_HAS_CTRLEXT_ON_LOAD
5053 | FLAG_HAS_AMT
5054 | FLAG_HAS_FLASH
5055 | FLAG_APME_IN_WUC,
5056 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00005057 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005058 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005059 .mac_ops = &ich8_mac_ops,
5060 .phy_ops = &ich8_phy_ops,
5061 .nvm_ops = &ich8_nvm_ops,
5062};
5063
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005064const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07005065 .mac = e1000_ich9lan,
5066 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07005067 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07005068 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07005069 | FLAG_HAS_CTRLEXT_ON_LOAD
5070 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07005071 | FLAG_HAS_FLASH
5072 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00005073 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00005074 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07005075 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07005076 .mac_ops = &ich8_mac_ops,
5077 .phy_ops = &ich8_phy_ops,
5078 .nvm_ops = &ich8_nvm_ops,
5079};
5080
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005081const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07005082 .mac = e1000_ich10lan,
5083 .flags = FLAG_HAS_JUMBO_FRAMES
5084 | FLAG_IS_ICH
5085 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07005086 | FLAG_HAS_CTRLEXT_ON_LOAD
5087 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07005088 | FLAG_HAS_FLASH
5089 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00005090 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00005091 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07005092 .get_variants = e1000_get_variants_ich8lan,
5093 .mac_ops = &ich8_mac_ops,
5094 .phy_ops = &ich8_phy_ops,
5095 .nvm_ops = &ich8_nvm_ops,
5096};
Bruce Allana4f58f52009-06-02 11:29:18 +00005097
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005098const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00005099 .mac = e1000_pchlan,
5100 .flags = FLAG_IS_ICH
5101 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00005102 | FLAG_HAS_CTRLEXT_ON_LOAD
5103 | FLAG_HAS_AMT
5104 | FLAG_HAS_FLASH
5105 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00005106 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00005107 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00005108 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00005109 .pba = 26,
5110 .max_hw_frame_size = 4096,
5111 .get_variants = e1000_get_variants_ich8lan,
5112 .mac_ops = &ich8_mac_ops,
5113 .phy_ops = &ich8_phy_ops,
5114 .nvm_ops = &ich8_nvm_ops,
5115};
Bruce Alland3738bb2010-06-16 13:27:28 +00005116
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00005117const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00005118 .mac = e1000_pch2lan,
5119 .flags = FLAG_IS_ICH
5120 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00005121 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00005122 | FLAG_HAS_CTRLEXT_ON_LOAD
5123 | FLAG_HAS_AMT
5124 | FLAG_HAS_FLASH
5125 | FLAG_HAS_JUMBO_FRAMES
5126 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00005127 .flags2 = FLAG2_HAS_PHY_STATS
5128 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00005129 .pba = 26,
Bruce Allanc3d2dbf2013-01-09 01:20:46 +00005130 .max_hw_frame_size = 9018,
Bruce Alland3738bb2010-06-16 13:27:28 +00005131 .get_variants = e1000_get_variants_ich8lan,
5132 .mac_ops = &ich8_mac_ops,
5133 .phy_ops = &ich8_phy_ops,
5134 .nvm_ops = &ich8_nvm_ops,
5135};
Bruce Allan2fbe4522012-04-19 03:21:47 +00005136
5137const struct e1000_info e1000_pch_lpt_info = {
5138 .mac = e1000_pch_lpt,
5139 .flags = FLAG_IS_ICH
5140 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00005141 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00005142 | FLAG_HAS_CTRLEXT_ON_LOAD
5143 | FLAG_HAS_AMT
5144 | FLAG_HAS_FLASH
5145 | FLAG_HAS_JUMBO_FRAMES
5146 | FLAG_APME_IN_WUC,
5147 .flags2 = FLAG2_HAS_PHY_STATS
5148 | FLAG2_HAS_EEE,
5149 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00005150 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00005151 .get_variants = e1000_get_variants_ich8lan,
5152 .mac_ops = &ich8_mac_ops,
5153 .phy_ops = &ich8_phy_ops,
5154 .nvm_ops = &ich8_nvm_ops,
5155};