blob: 83184cf3949943526f4f3526f33fd8be96721b30 [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
Auke Kokbc7f75f2007-09-17 12:30:59 -070049 */
50
Auke Kokbc7f75f2007-09-17 12:30:59 -070051#include "e1000.h"
52
Auke Kokbc7f75f2007-09-17 12:30:59 -070053/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
54/* Offset 04h HSFSTS */
55union ich8_hws_flash_status {
56 struct ich8_hsfsts {
Bruce Allan362e20c2013-02-20 04:05:45 +000057 u16 flcdone:1; /* bit 0 Flash Cycle Done */
58 u16 flcerr:1; /* bit 1 Flash Cycle Error */
59 u16 dael:1; /* bit 2 Direct Access error Log */
60 u16 berasesz:2; /* bit 4:3 Sector Erase Size */
61 u16 flcinprog:1; /* bit 5 flash cycle in Progress */
62 u16 reserved1:2; /* bit 13:6 Reserved */
63 u16 reserved2:6; /* bit 13:6 Reserved */
64 u16 fldesvalid:1; /* bit 14 Flash Descriptor Valid */
65 u16 flockdn:1; /* bit 15 Flash Config Lock-Down */
Auke Kokbc7f75f2007-09-17 12:30:59 -070066 } hsf_status;
67 u16 regval;
68};
69
70/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
71/* Offset 06h FLCTL */
72union ich8_hws_flash_ctrl {
73 struct ich8_hsflctl {
Bruce Allan362e20c2013-02-20 04:05:45 +000074 u16 flcgo:1; /* 0 Flash Cycle Go */
75 u16 flcycle:2; /* 2:1 Flash Cycle */
76 u16 reserved:5; /* 7:3 Reserved */
77 u16 fldbcount:2; /* 9:8 Flash Data Byte Count */
78 u16 flockdn:6; /* 15:10 Reserved */
Auke Kokbc7f75f2007-09-17 12:30:59 -070079 } hsf_ctrl;
80 u16 regval;
81};
82
83/* ICH Flash Region Access Permissions */
84union ich8_hws_flash_regacc {
85 struct ich8_flracc {
Bruce Allan362e20c2013-02-20 04:05:45 +000086 u32 grra:8; /* 0:7 GbE region Read Access */
87 u32 grwa:8; /* 8:15 GbE region Write Access */
88 u32 gmrag:8; /* 23:16 GbE Master Read Access Grant */
89 u32 gmwag:8; /* 31:24 GbE Master Write Access Grant */
Auke Kokbc7f75f2007-09-17 12:30:59 -070090 } hsf_flregacc;
91 u16 regval;
92};
93
Bruce Allan4a770352008-10-01 17:18:35 -070094/* ICH Flash Protected Region */
95union ich8_flash_protected_range {
96 struct ich8_pr {
Bruce Allane80bd1d2013-05-01 01:19:46 +000097 u32 base:13; /* 0:12 Protected Range Base */
98 u32 reserved1:2; /* 13:14 Reserved */
99 u32 rpe:1; /* 15 Read Protection Enable */
100 u32 limit:13; /* 16:28 Protected Range Limit */
101 u32 reserved2:2; /* 29:30 Reserved */
102 u32 wpe:1; /* 31 Write Protection Enable */
Bruce Allan4a770352008-10-01 17:18:35 -0700103 } range;
104 u32 regval;
105};
106
Auke Kokbc7f75f2007-09-17 12:30:59 -0700107static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
108static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700109static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
110static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
111 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700112static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
113 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
115 u16 *data);
116static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
117 u8 size, u16 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700118static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000119static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
120static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
121static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
122static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
123static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
124static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
125static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
126static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000127static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000128static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000129static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1f96012d2013-01-05 03:06:54 +0000130static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000131static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000132static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
133static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan69e1e012012-04-14 03:28:50 +0000134static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000135static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000136static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000137static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
Bruce Allanea8179a2013-03-06 09:02:47 +0000138static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700139
140static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
141{
142 return readw(hw->flash_address + reg);
143}
144
145static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
146{
147 return readl(hw->flash_address + reg);
148}
149
150static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
151{
152 writew(val, hw->flash_address + reg);
153}
154
155static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
156{
157 writel(val, hw->flash_address + reg);
158}
159
160#define er16flash(reg) __er16flash(hw, (reg))
161#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000162#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
163#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700164
Bruce Allancb17aab2012-04-13 03:16:22 +0000165/**
166 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
167 * @hw: pointer to the HW structure
168 *
169 * Test access to the PHY registers by reading the PHY ID registers. If
170 * the PHY ID is already known (e.g. resume path) compare it with known ID,
171 * otherwise assume the read PHY ID is correct if it is valid.
172 *
173 * Assumes the sw/fw/hw semaphore is already acquired.
174 **/
175static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000176{
Bruce Allana52359b2012-07-14 04:23:58 +0000177 u16 phy_reg = 0;
178 u32 phy_id = 0;
179 s32 ret_val;
180 u16 retry_count;
Bruce Allan16b095a2013-06-29 07:42:39 +0000181 u32 mac_reg = 0;
Bruce Allan99730e42011-05-13 07:19:48 +0000182
Bruce Allana52359b2012-07-14 04:23:58 +0000183 for (retry_count = 0; retry_count < 2; retry_count++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000184 ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000185 if (ret_val || (phy_reg == 0xFFFF))
186 continue;
187 phy_id = (u32)(phy_reg << 16);
188
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000189 ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000190 if (ret_val || (phy_reg == 0xFFFF)) {
191 phy_id = 0;
192 continue;
193 }
194 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
195 break;
196 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000197
Bruce Allancb17aab2012-04-13 03:16:22 +0000198 if (hw->phy.id) {
199 if (hw->phy.id == phy_id)
Bruce Allan16b095a2013-06-29 07:42:39 +0000200 goto out;
Bruce Allana52359b2012-07-14 04:23:58 +0000201 } else if (phy_id) {
202 hw->phy.id = phy_id;
203 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allan16b095a2013-06-29 07:42:39 +0000204 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000205 }
206
Bruce Allane921eb12012-11-28 09:28:37 +0000207 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000208 * set slow mode and try to get the PHY id again.
209 */
210 hw->phy.ops.release(hw);
211 ret_val = e1000_set_mdio_slow_mode_hv(hw);
212 if (!ret_val)
213 ret_val = e1000e_get_phy_id(hw);
214 hw->phy.ops.acquire(hw);
215
Bruce Allan16b095a2013-06-29 07:42:39 +0000216 if (ret_val)
217 return false;
218out:
219 if (hw->mac.type == e1000_pch_lpt) {
220 /* Unforce SMBus mode in PHY */
221 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
222 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
223 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
224
225 /* Unforce SMBus mode in MAC */
226 mac_reg = er32(CTRL_EXT);
227 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
228 ew32(CTRL_EXT, mac_reg);
229 }
230
231 return true;
Bruce Allancb17aab2012-04-13 03:16:22 +0000232}
233
234/**
235 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
236 * @hw: pointer to the HW structure
237 *
238 * Workarounds/flow necessary for PHY initialization during driver load
239 * and resume paths.
240 **/
241static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
242{
David Ertmanf7235ef2014-01-23 06:29:13 +0000243 struct e1000_adapter *adapter = hw->adapter;
Bruce Allancb17aab2012-04-13 03:16:22 +0000244 u32 mac_reg, fwsm = er32(FWSM);
245 s32 ret_val;
246
Bruce Allan6e928b72012-12-12 04:45:51 +0000247 /* Gate automatic PHY configuration by hardware on managed and
248 * non-managed 82579 and newer adapters.
249 */
250 e1000_gate_hw_phy_config_ich8lan(hw, true);
251
Bruce Allancb17aab2012-04-13 03:16:22 +0000252 ret_val = hw->phy.ops.acquire(hw);
253 if (ret_val) {
254 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000255 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000256 }
257
Bruce Allane921eb12012-11-28 09:28:37 +0000258 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000259 * inaccessible and resetting the PHY is not blocked, toggle the
260 * LANPHYPC Value bit to force the interconnect to PCIe mode.
261 */
262 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000263 case e1000_pch_lpt:
264 if (e1000_phy_is_accessible_pchlan(hw))
265 break;
266
Bruce Allane921eb12012-11-28 09:28:37 +0000267 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000268 * forcing MAC to SMBus mode first.
269 */
270 mac_reg = er32(CTRL_EXT);
271 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
272 ew32(CTRL_EXT, mac_reg);
273
Bruce Allan16b095a2013-06-29 07:42:39 +0000274 /* Wait 50 milliseconds for MAC to finish any retries
275 * that it might be trying to perform from previous
276 * attempts to acknowledge any phy read requests.
277 */
278 msleep(50);
279
Bruce Allan2fbe4522012-04-19 03:21:47 +0000280 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000281 case e1000_pch2lan:
Bruce Allan16b095a2013-06-29 07:42:39 +0000282 if (e1000_phy_is_accessible_pchlan(hw))
Bruce Allancb17aab2012-04-13 03:16:22 +0000283 break;
284
285 /* fall-through */
286 case e1000_pchlan:
287 if ((hw->mac.type == e1000_pchlan) &&
288 (fwsm & E1000_ICH_FWSM_FW_VALID))
289 break;
290
291 if (hw->phy.ops.check_reset_block(hw)) {
292 e_dbg("Required LANPHYPC toggle blocked by ME\n");
Bruce Allan16b095a2013-06-29 07:42:39 +0000293 ret_val = -E1000_ERR_PHY;
Bruce Allancb17aab2012-04-13 03:16:22 +0000294 break;
295 }
296
297 e_dbg("Toggling LANPHYPC\n");
298
299 /* Set Phy Config Counter to 50msec */
300 mac_reg = er32(FEXTNVM3);
301 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
302 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
303 ew32(FEXTNVM3, mac_reg);
304
305 /* Toggle LANPHYPC Value bit */
306 mac_reg = er32(CTRL);
307 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
308 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
309 ew32(CTRL, mac_reg);
310 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +0000311 usleep_range(10, 20);
Bruce Allancb17aab2012-04-13 03:16:22 +0000312 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
313 ew32(CTRL, mac_reg);
314 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000315 if (hw->mac.type < e1000_pch_lpt) {
316 msleep(50);
317 } else {
318 u16 count = 20;
319 do {
320 usleep_range(5000, 10000);
321 } while (!(er32(CTRL_EXT) &
322 E1000_CTRL_EXT_LPCD) && count--);
Bruce Allan16b095a2013-06-29 07:42:39 +0000323 usleep_range(30000, 60000);
324 if (e1000_phy_is_accessible_pchlan(hw))
325 break;
326
327 /* Toggling LANPHYPC brings the PHY out of SMBus mode
328 * so ensure that the MAC is also out of SMBus mode
329 */
330 mac_reg = er32(CTRL_EXT);
331 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
332 ew32(CTRL_EXT, mac_reg);
333
334 if (e1000_phy_is_accessible_pchlan(hw))
335 break;
336
337 ret_val = -E1000_ERR_PHY;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000338 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000339 break;
340 default:
341 break;
342 }
343
344 hw->phy.ops.release(hw);
Bruce Allan16b095a2013-06-29 07:42:39 +0000345 if (!ret_val) {
David Ertmanf7235ef2014-01-23 06:29:13 +0000346
347 /* Check to see if able to reset PHY. Print error if not */
348 if (hw->phy.ops.check_reset_block(hw)) {
349 e_err("Reset blocked by ME\n");
350 goto out;
351 }
352
Bruce Allan16b095a2013-06-29 07:42:39 +0000353 /* Reset the PHY before any access to it. Doing so, ensures
354 * that the PHY is in a known good state before we read/write
355 * PHY registers. The generic reset is sufficient here,
356 * because we haven't determined the PHY type yet.
357 */
358 ret_val = e1000e_phy_hw_reset_generic(hw);
David Ertmanf7235ef2014-01-23 06:29:13 +0000359 if (ret_val)
360 goto out;
361
362 /* On a successful reset, possibly need to wait for the PHY
363 * to quiesce to an accessible state before returning control
364 * to the calling function. If the PHY does not quiesce, then
365 * return E1000E_BLK_PHY_RESET, as this is the condition that
366 * the PHY is in.
367 */
368 ret_val = hw->phy.ops.check_reset_block(hw);
369 if (ret_val)
370 e_err("ME blocked access to PHY after reset\n");
Bruce Allan16b095a2013-06-29 07:42:39 +0000371 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000372
Bruce Allan6e928b72012-12-12 04:45:51 +0000373out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000374 /* Ungate automatic PHY configuration on non-managed 82579 */
375 if ((hw->mac.type == e1000_pch2lan) &&
376 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
377 usleep_range(10000, 20000);
378 e1000_gate_hw_phy_config_ich8lan(hw, false);
379 }
380
381 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000382}
383
Auke Kokbc7f75f2007-09-17 12:30:59 -0700384/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000385 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
386 * @hw: pointer to the HW structure
387 *
388 * Initialize family-specific PHY parameters and function pointers.
389 **/
390static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
391{
392 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan70806a72013-01-05 05:08:37 +0000393 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000394
Bruce Allane80bd1d2013-05-01 01:19:46 +0000395 phy->addr = 1;
396 phy->reset_delay_us = 100;
Bruce Allana4f58f52009-06-02 11:29:18 +0000397
Bruce Allane80bd1d2013-05-01 01:19:46 +0000398 phy->ops.set_page = e1000_set_page_igp;
399 phy->ops.read_reg = e1000_read_phy_reg_hv;
400 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
401 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
402 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
403 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
404 phy->ops.write_reg = e1000_write_phy_reg_hv;
405 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
406 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
407 phy->ops.power_up = e1000_power_up_phy_copper;
408 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
409 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allana4f58f52009-06-02 11:29:18 +0000410
411 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000412
413 ret_val = e1000_init_phy_workarounds_pchlan(hw);
414 if (ret_val)
415 return ret_val;
416
417 if (phy->id == e1000_phy_unknown)
418 switch (hw->mac.type) {
419 default:
420 ret_val = e1000e_get_phy_id(hw);
421 if (ret_val)
422 return ret_val;
423 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
424 break;
425 /* fall-through */
426 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000427 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000428 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000429 * set slow mode and try to get the PHY id again.
430 */
431 ret_val = e1000_set_mdio_slow_mode_hv(hw);
432 if (ret_val)
433 return ret_val;
434 ret_val = e1000e_get_phy_id(hw);
435 if (ret_val)
436 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000437 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000438 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000439 phy->type = e1000e_get_phy_type_from_id(phy->id);
440
Bruce Allan0be84012009-12-02 17:03:18 +0000441 switch (phy->type) {
442 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000443 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000444 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000445 phy->ops.check_polarity = e1000_check_polarity_82577;
446 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000447 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000448 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000449 phy->ops.get_info = e1000_get_phy_info_82577;
450 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000451 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000452 case e1000_phy_82578:
453 phy->ops.check_polarity = e1000_check_polarity_m88;
454 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
455 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
456 phy->ops.get_info = e1000e_get_phy_info_m88;
457 break;
458 default:
459 ret_val = -E1000_ERR_PHY;
460 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000461 }
462
463 return ret_val;
464}
465
466/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
468 * @hw: pointer to the HW structure
469 *
470 * Initialize family-specific PHY parameters and function pointers.
471 **/
472static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
473{
474 struct e1000_phy_info *phy = &hw->phy;
475 s32 ret_val;
476 u16 i = 0;
477
Bruce Allane80bd1d2013-05-01 01:19:46 +0000478 phy->addr = 1;
479 phy->reset_delay_us = 100;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700480
Bruce Allane80bd1d2013-05-01 01:19:46 +0000481 phy->ops.power_up = e1000_power_up_phy_copper;
482 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allan17f208d2009-12-01 15:47:22 +0000483
Bruce Allane921eb12012-11-28 09:28:37 +0000484 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700485 * we'll set BM func pointers and try again
486 */
487 ret_val = e1000e_determine_phy_address(hw);
488 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000489 phy->ops.write_reg = e1000e_write_phy_reg_bm;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000490 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700491 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000492 if (ret_val) {
493 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700494 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000495 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700496 }
497
Auke Kokbc7f75f2007-09-17 12:30:59 -0700498 phy->id = 0;
499 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
500 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000501 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700502 ret_val = e1000e_get_phy_id(hw);
503 if (ret_val)
504 return ret_val;
505 }
506
507 /* Verify phy id */
508 switch (phy->id) {
509 case IGP03E1000_E_PHY_ID:
510 phy->type = e1000_phy_igp_3;
511 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000512 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
513 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000514 phy->ops.get_info = e1000e_get_phy_info_igp;
515 phy->ops.check_polarity = e1000_check_polarity_igp;
516 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700517 break;
518 case IFE_E_PHY_ID:
519 case IFE_PLUS_E_PHY_ID:
520 case IFE_C_E_PHY_ID:
521 phy->type = e1000_phy_ife;
522 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000523 phy->ops.get_info = e1000_get_phy_info_ife;
524 phy->ops.check_polarity = e1000_check_polarity_ife;
525 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700526 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700527 case BME1000_E_PHY_ID:
528 phy->type = e1000_phy_bm;
529 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000530 phy->ops.read_reg = e1000e_read_phy_reg_bm;
531 phy->ops.write_reg = e1000e_write_phy_reg_bm;
532 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000533 phy->ops.get_info = e1000e_get_phy_info_m88;
534 phy->ops.check_polarity = e1000_check_polarity_m88;
535 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700536 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700537 default:
538 return -E1000_ERR_PHY;
539 break;
540 }
541
542 return 0;
543}
544
545/**
546 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
547 * @hw: pointer to the HW structure
548 *
549 * Initialize family-specific NVM parameters and function
550 * pointers.
551 **/
552static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
553{
554 struct e1000_nvm_info *nvm = &hw->nvm;
555 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000556 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557 u16 i;
558
Bruce Allanad680762008-03-28 09:15:03 -0700559 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700560 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000561 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562 return -E1000_ERR_CONFIG;
563 }
564
565 nvm->type = e1000_nvm_flash_sw;
566
567 gfpreg = er32flash(ICH_FLASH_GFPREG);
568
Bruce Allane921eb12012-11-28 09:28:37 +0000569 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700570 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700571 * the overall size.
572 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700573 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
574 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
575
576 /* flash_base_addr is byte-aligned */
577 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
578
Bruce Allane921eb12012-11-28 09:28:37 +0000579 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700580 * size represents two separate NVM banks.
581 */
Bruce Allanf0ff4392013-02-20 04:05:39 +0000582 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
583 << FLASH_SECTOR_ADDR_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700584 nvm->flash_bank_size /= 2;
585 /* Adjust to word count */
586 nvm->flash_bank_size /= sizeof(u16);
587
588 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
589
590 /* Clear shadow ram */
591 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000592 dev_spec->shadow_ram[i].modified = false;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000593 dev_spec->shadow_ram[i].value = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700594 }
595
596 return 0;
597}
598
599/**
600 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
601 * @hw: pointer to the HW structure
602 *
603 * Initialize family-specific MAC parameters and function
604 * pointers.
605 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000606static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700607{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700608 struct e1000_mac_info *mac = &hw->mac;
609
610 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700611 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700612
613 /* Set mta register count */
614 mac->mta_reg_count = 32;
615 /* Set rar entry count */
616 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
617 if (mac->type == e1000_ich8lan)
618 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000619 /* FWSM register */
620 mac->has_fwsm = true;
621 /* ARC subsystem not supported */
622 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000623 /* Adaptive IFS supported */
624 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700625
Bruce Allan2fbe4522012-04-19 03:21:47 +0000626 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000627 switch (mac->type) {
628 case e1000_ich8lan:
629 case e1000_ich9lan:
630 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000631 /* check management mode */
632 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000633 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000634 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000635 /* blink LED */
636 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000637 /* setup LED */
638 mac->ops.setup_led = e1000e_setup_led_generic;
639 /* cleanup LED */
640 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
641 /* turn on/off LED */
642 mac->ops.led_on = e1000_led_on_ich8lan;
643 mac->ops.led_off = e1000_led_off_ich8lan;
644 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000645 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000646 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
647 mac->ops.rar_set = e1000_rar_set_pch2lan;
648 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000649 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000650 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000651 /* check management mode */
652 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000653 /* ID LED init */
654 mac->ops.id_led_init = e1000_id_led_init_pchlan;
655 /* setup LED */
656 mac->ops.setup_led = e1000_setup_led_pchlan;
657 /* cleanup LED */
658 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
659 /* turn on/off LED */
660 mac->ops.led_on = e1000_led_on_pchlan;
661 mac->ops.led_off = e1000_led_off_pchlan;
662 break;
663 default:
664 break;
665 }
666
Bruce Allan2fbe4522012-04-19 03:21:47 +0000667 if (mac->type == e1000_pch_lpt) {
668 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
669 mac->ops.rar_set = e1000_rar_set_pch_lpt;
Bruce Allanea8179a2013-03-06 09:02:47 +0000670 mac->ops.setup_physical_interface =
671 e1000_setup_copper_link_pch_lpt;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000672 }
673
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 /* Enable PCS Lock-loss workaround for ICH8 */
675 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000676 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700677
678 return 0;
679}
680
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000681/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000682 * __e1000_access_emi_reg_locked - Read/write EMI register
683 * @hw: pointer to the HW structure
684 * @addr: EMI address to program
685 * @data: pointer to value to read/write from/to the EMI address
686 * @read: boolean flag to indicate read or write
687 *
688 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
689 **/
690static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
691 u16 *data, bool read)
692{
Bruce Allan70806a72013-01-05 05:08:37 +0000693 s32 ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000694
695 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
696 if (ret_val)
697 return ret_val;
698
699 if (read)
700 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
701 else
702 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
703
704 return ret_val;
705}
706
707/**
708 * e1000_read_emi_reg_locked - Read Extended Management Interface register
709 * @hw: pointer to the HW structure
710 * @addr: EMI address to program
711 * @data: value to be read from the EMI address
712 *
713 * Assumes the SW/FW/HW Semaphore is already acquired.
714 **/
Bruce Allan203e4152012-12-05 08:40:59 +0000715s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000716{
717 return __e1000_access_emi_reg_locked(hw, addr, data, true);
718}
719
720/**
721 * e1000_write_emi_reg_locked - Write Extended Management Interface register
722 * @hw: pointer to the HW structure
723 * @addr: EMI address to program
724 * @data: value to be written to the EMI address
725 *
726 * Assumes the SW/FW/HW Semaphore is already acquired.
727 **/
Bruce Alland495bcb2013-03-20 07:23:11 +0000728s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000729{
730 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
731}
732
733/**
Bruce Allane52997f2010-06-16 13:27:49 +0000734 * e1000_set_eee_pchlan - Enable/disable EEE support
735 * @hw: pointer to the HW structure
736 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000737 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
738 * the link and the EEE capabilities of the link partner. The LPI Control
739 * register bits will remain set only if/when link is up.
David Ertmana03206e2014-01-24 23:07:48 +0000740 *
741 * EEE LPI must not be asserted earlier than one second after link is up.
742 * On 82579, EEE LPI should not be enabled until such time otherwise there
743 * can be link issues with some switches. Other devices can have EEE LPI
744 * enabled immediately upon link up since they have a timer in hardware which
745 * prevents LPI from being asserted too early.
Bruce Allane52997f2010-06-16 13:27:49 +0000746 **/
David Ertmana03206e2014-01-24 23:07:48 +0000747s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
Bruce Allane52997f2010-06-16 13:27:49 +0000748{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000749 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000750 s32 ret_val;
Bruce Alland495bcb2013-03-20 07:23:11 +0000751 u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
Bruce Allane52997f2010-06-16 13:27:49 +0000752
Bruce Alland495bcb2013-03-20 07:23:11 +0000753 switch (hw->phy.type) {
754 case e1000_phy_82579:
755 lpa = I82579_EEE_LP_ABILITY;
756 pcs_status = I82579_EEE_PCS_STATUS;
757 adv_addr = I82579_EEE_ADVERTISEMENT;
758 break;
759 case e1000_phy_i217:
760 lpa = I217_EEE_LP_ABILITY;
761 pcs_status = I217_EEE_PCS_STATUS;
762 adv_addr = I217_EEE_ADVERTISEMENT;
763 break;
764 default:
Bruce Allan5015e532012-02-08 02:55:56 +0000765 return 0;
Bruce Alland495bcb2013-03-20 07:23:11 +0000766 }
Bruce Allane52997f2010-06-16 13:27:49 +0000767
Bruce Allan3d4d5752012-12-05 06:26:08 +0000768 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000769 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000770 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000771
Bruce Allan3d4d5752012-12-05 06:26:08 +0000772 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000773 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000774 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000775
Bruce Allan3d4d5752012-12-05 06:26:08 +0000776 /* Clear bits that enable EEE in various speeds */
777 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
778
779 /* Enable EEE if not disabled by user */
780 if (!dev_spec->eee_disable) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000781 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000782 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000783 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000784 if (ret_val)
785 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000786
Bruce Alland495bcb2013-03-20 07:23:11 +0000787 /* Read EEE advertisement */
788 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
789 if (ret_val)
790 goto release;
791
Bruce Allan3d4d5752012-12-05 06:26:08 +0000792 /* Enable EEE only for speeds in which the link partner is
Bruce Alland495bcb2013-03-20 07:23:11 +0000793 * EEE capable and for which we advertise EEE.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000794 */
Bruce Alland495bcb2013-03-20 07:23:11 +0000795 if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000796 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
797
Bruce Alland495bcb2013-03-20 07:23:11 +0000798 if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000799 e1e_rphy_locked(hw, MII_LPA, &data);
800 if (data & LPA_100FULL)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000801 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
802 else
803 /* EEE is not supported in 100Half, so ignore
804 * partner's EEE in 100 ability if full-duplex
805 * is not advertised.
806 */
807 dev_spec->eee_lp_ability &=
808 ~I82579_EEE_100_SUPPORTED;
809 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000810 }
811
Bruce Alland495bcb2013-03-20 07:23:11 +0000812 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
813 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
814 if (ret_val)
815 goto release;
816
Bruce Allan3d4d5752012-12-05 06:26:08 +0000817 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
818release:
819 hw->phy.ops.release(hw);
820
821 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000822}
823
824/**
Bruce Allane08f6262013-02-20 03:06:34 +0000825 * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
826 * @hw: pointer to the HW structure
827 * @link: link up bool flag
828 *
829 * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
830 * preventing further DMA write requests. Workaround the issue by disabling
831 * the de-assertion of the clock request when in 1Gpbs mode.
Bruce Allane0236ad2013-06-21 09:07:13 +0000832 * Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
833 * speeds in order to avoid Tx hangs.
Bruce Allane08f6262013-02-20 03:06:34 +0000834 **/
835static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
836{
837 u32 fextnvm6 = er32(FEXTNVM6);
Bruce Allane0236ad2013-06-21 09:07:13 +0000838 u32 status = er32(STATUS);
Bruce Allane08f6262013-02-20 03:06:34 +0000839 s32 ret_val = 0;
Bruce Allane0236ad2013-06-21 09:07:13 +0000840 u16 reg;
Bruce Allane08f6262013-02-20 03:06:34 +0000841
Bruce Allane0236ad2013-06-21 09:07:13 +0000842 if (link && (status & E1000_STATUS_SPEED_1000)) {
Bruce Allane08f6262013-02-20 03:06:34 +0000843 ret_val = hw->phy.ops.acquire(hw);
844 if (ret_val)
845 return ret_val;
846
847 ret_val =
848 e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000849 &reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000850 if (ret_val)
851 goto release;
852
853 ret_val =
854 e1000e_write_kmrn_reg_locked(hw,
855 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000856 reg &
Bruce Allane08f6262013-02-20 03:06:34 +0000857 ~E1000_KMRNCTRLSTA_K1_ENABLE);
858 if (ret_val)
859 goto release;
860
861 usleep_range(10, 20);
862
863 ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
864
865 ret_val =
866 e1000e_write_kmrn_reg_locked(hw,
867 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000868 reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000869release:
870 hw->phy.ops.release(hw);
871 } else {
872 /* clear FEXTNVM6 bit 8 on link down or 10/100 */
Bruce Allane0236ad2013-06-21 09:07:13 +0000873 fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
874
875 if (!link || ((status & E1000_STATUS_SPEED_100) &&
876 (status & E1000_STATUS_FD)))
877 goto update_fextnvm6;
878
879 ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
880 if (ret_val)
881 return ret_val;
882
883 /* Clear link status transmit timeout */
884 reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
885
886 if (status & E1000_STATUS_SPEED_100) {
887 /* Set inband Tx timeout to 5x10us for 100Half */
888 reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
889
890 /* Do not extend the K1 entry latency for 100Half */
891 fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
892 } else {
893 /* Set inband Tx timeout to 50x10us for 10Full/Half */
894 reg |= 50 <<
895 I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
896
897 /* Extend the K1 entry latency for 10 Mbps */
898 fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
899 }
900
901 ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
902 if (ret_val)
903 return ret_val;
904
905update_fextnvm6:
906 ew32(FEXTNVM6, fextnvm6);
Bruce Allane08f6262013-02-20 03:06:34 +0000907 }
908
909 return ret_val;
910}
911
912/**
Bruce Allancf8fb732013-03-06 09:03:02 +0000913 * e1000_platform_pm_pch_lpt - Set platform power management values
914 * @hw: pointer to the HW structure
915 * @link: bool indicating link status
916 *
917 * Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
918 * GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
919 * when link is up (which must not exceed the maximum latency supported
920 * by the platform), otherwise specify there is no LTR requirement.
921 * Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
922 * latencies in the LTR Extended Capability Structure in the PCIe Extended
923 * Capability register set, on this device LTR is set by writing the
924 * equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
925 * set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
926 * message to the PMC.
927 **/
928static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
929{
930 u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
931 link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
932 u16 lat_enc = 0; /* latency encoded */
933
934 if (link) {
935 u16 speed, duplex, scale = 0;
936 u16 max_snoop, max_nosnoop;
937 u16 max_ltr_enc; /* max LTR latency encoded */
938 s64 lat_ns; /* latency (ns) */
939 s64 value;
940 u32 rxa;
941
942 if (!hw->adapter->max_frame_size) {
943 e_dbg("max_frame_size not set.\n");
944 return -E1000_ERR_CONFIG;
945 }
946
947 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
948 if (!speed) {
949 e_dbg("Speed not set.\n");
950 return -E1000_ERR_CONFIG;
951 }
952
953 /* Rx Packet Buffer Allocation size (KB) */
954 rxa = er32(PBA) & E1000_PBA_RXA_MASK;
955
956 /* Determine the maximum latency tolerated by the device.
957 *
958 * Per the PCIe spec, the tolerated latencies are encoded as
959 * a 3-bit encoded scale (only 0-5 are valid) multiplied by
960 * a 10-bit value (0-1023) to provide a range from 1 ns to
961 * 2^25*(2^10-1) ns. The scale is encoded as 0=2^0ns,
962 * 1=2^5ns, 2=2^10ns,...5=2^25ns.
963 */
964 lat_ns = ((s64)rxa * 1024 -
965 (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
966 if (lat_ns < 0)
967 lat_ns = 0;
968 else
969 do_div(lat_ns, speed);
970
971 value = lat_ns;
972 while (value > PCI_LTR_VALUE_MASK) {
973 scale++;
974 value = DIV_ROUND_UP(value, (1 << 5));
975 }
976 if (scale > E1000_LTRV_SCALE_MAX) {
977 e_dbg("Invalid LTR latency scale %d\n", scale);
978 return -E1000_ERR_CONFIG;
979 }
980 lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
981
982 /* Determine the maximum latency tolerated by the platform */
983 pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
984 &max_snoop);
985 pci_read_config_word(hw->adapter->pdev,
986 E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
987 max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
988
989 if (lat_enc > max_ltr_enc)
990 lat_enc = max_ltr_enc;
991 }
992
993 /* Set Snoop and No-Snoop latencies the same */
994 reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
995 ew32(LTRV, reg);
996
997 return 0;
998}
999
1000/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001001 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
1002 * @hw: pointer to the HW structure
1003 *
1004 * Checks to see of the link status of the hardware has changed. If a
1005 * change in link status has been detected, then we read the PHY registers
1006 * to get the current speed/duplex if link exists.
1007 **/
1008static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1009{
1010 struct e1000_mac_info *mac = &hw->mac;
1011 s32 ret_val;
1012 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001013 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001014
Bruce Allane921eb12012-11-28 09:28:37 +00001015 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001016 * has completed and/or if our link status has changed. The
1017 * get_link_status flag is set upon receiving a Link Status
1018 * Change or Rx Sequence Error interrupt.
1019 */
Bruce Allan5015e532012-02-08 02:55:56 +00001020 if (!mac->get_link_status)
1021 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001022
Bruce Allane921eb12012-11-28 09:28:37 +00001023 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001024 * link. If so, then we want to get the current speed/duplex
1025 * of the PHY.
1026 */
1027 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1028 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001029 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001030
Bruce Allan1d5846b2009-10-29 13:46:05 +00001031 if (hw->mac.type == e1000_pchlan) {
1032 ret_val = e1000_k1_gig_workaround_hv(hw, link);
1033 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001034 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001035 }
1036
Bruce Allan772d05c2013-03-06 09:02:36 +00001037 /* When connected at 10Mbps half-duplex, 82579 parts are excessively
1038 * aggressive resulting in many collisions. To avoid this, increase
1039 * the IPG and reduce Rx latency in the PHY.
1040 */
1041 if ((hw->mac.type == e1000_pch2lan) && link) {
1042 u32 reg;
1043 reg = er32(STATUS);
1044 if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
1045 reg = er32(TIPG);
1046 reg &= ~E1000_TIPG_IPGT_MASK;
1047 reg |= 0xFF;
1048 ew32(TIPG, reg);
1049
1050 /* Reduce Rx latency in analog PHY */
1051 ret_val = hw->phy.ops.acquire(hw);
1052 if (ret_val)
1053 return ret_val;
1054
1055 ret_val =
1056 e1000_write_emi_reg_locked(hw, I82579_RX_CONFIG, 0);
1057
1058 hw->phy.ops.release(hw);
1059
1060 if (ret_val)
1061 return ret_val;
1062 }
1063 }
1064
Bruce Allane08f6262013-02-20 03:06:34 +00001065 /* Work-around I218 hang issue */
1066 if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
Bruce Allan91a3d822013-06-29 01:15:16 +00001067 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
1068 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
1069 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
Bruce Allane08f6262013-02-20 03:06:34 +00001070 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
1071 if (ret_val)
1072 return ret_val;
1073 }
1074
Bruce Allancf8fb732013-03-06 09:03:02 +00001075 if (hw->mac.type == e1000_pch_lpt) {
1076 /* Set platform power management values for
1077 * Latency Tolerance Reporting (LTR)
1078 */
1079 ret_val = e1000_platform_pm_pch_lpt(hw, link);
1080 if (ret_val)
1081 return ret_val;
1082 }
1083
Bruce Allan2fbe4522012-04-19 03:21:47 +00001084 /* Clear link partner's EEE ability */
1085 hw->dev_spec.ich8lan.eee_lp_ability = 0;
1086
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001087 if (!link)
Bruce Allane80bd1d2013-05-01 01:19:46 +00001088 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001089
1090 mac->get_link_status = false;
1091
Bruce Allan1d2101a72011-07-22 06:21:56 +00001092 switch (hw->mac.type) {
1093 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +00001094 ret_val = e1000_k1_workaround_lv(hw);
1095 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001096 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001097 /* fall-thru */
1098 case e1000_pchlan:
1099 if (hw->phy.type == e1000_phy_82578) {
1100 ret_val = e1000_link_stall_workaround_hv(hw);
1101 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001102 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001103 }
1104
Bruce Allane921eb12012-11-28 09:28:37 +00001105 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +00001106 * Set the number of preambles removed from the packet
1107 * when it is passed from the PHY to the MAC to prevent
1108 * the MAC from misinterpreting the packet type.
1109 */
1110 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
1111 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
1112
1113 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
1114 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
1115
1116 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
1117 break;
1118 default:
1119 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001120 }
1121
Bruce Allane921eb12012-11-28 09:28:37 +00001122 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001123 * immediately after link-up
1124 */
1125 e1000e_check_downshift(hw);
1126
Bruce Allane52997f2010-06-16 13:27:49 +00001127 /* Enable/Disable EEE after link up */
David Ertmana03206e2014-01-24 23:07:48 +00001128 if (hw->phy.type > e1000_phy_82579) {
1129 ret_val = e1000_set_eee_pchlan(hw);
1130 if (ret_val)
1131 return ret_val;
1132 }
Bruce Allane52997f2010-06-16 13:27:49 +00001133
Bruce Allane921eb12012-11-28 09:28:37 +00001134 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001135 * we have already determined whether we have link or not.
1136 */
Bruce Allan5015e532012-02-08 02:55:56 +00001137 if (!mac->autoneg)
1138 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001139
Bruce Allane921eb12012-11-28 09:28:37 +00001140 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001141 * of MAC speed/duplex configuration. So we only need to
1142 * configure Collision Distance in the MAC.
1143 */
Bruce Allan57cde762012-02-22 09:02:58 +00001144 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001145
Bruce Allane921eb12012-11-28 09:28:37 +00001146 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001147 * First, we need to restore the desired flow control
1148 * settings because we may have had to re-autoneg with a
1149 * different link partner.
1150 */
1151 ret_val = e1000e_config_fc_after_link_up(hw);
1152 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001153 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001154
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001155 return ret_val;
1156}
1157
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001158static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001159{
1160 struct e1000_hw *hw = &adapter->hw;
1161 s32 rc;
1162
Bruce Allanec34c172012-02-01 10:53:05 +00001163 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001164 if (rc)
1165 return rc;
1166
1167 rc = e1000_init_nvm_params_ich8lan(hw);
1168 if (rc)
1169 return rc;
1170
Bruce Alland3738bb2010-06-16 13:27:28 +00001171 switch (hw->mac.type) {
1172 case e1000_ich8lan:
1173 case e1000_ich9lan:
1174 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001175 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001176 break;
1177 case e1000_pchlan:
1178 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001179 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001180 rc = e1000_init_phy_params_pchlan(hw);
1181 break;
1182 default:
1183 break;
1184 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 if (rc)
1186 return rc;
1187
Bruce Allane921eb12012-11-28 09:28:37 +00001188 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001189 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1190 */
1191 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1192 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1193 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001194 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1195 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001196
1197 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001198 }
1199
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001201 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1203
Bruce Allanc6e7f512011-07-29 05:53:02 +00001204 /* Enable workaround for 82579 w/ ME enabled */
1205 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1206 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1207 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1208
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209 return 0;
1210}
1211
Thomas Gleixner717d4382008-10-02 16:33:40 -07001212static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001213
Auke Kokbc7f75f2007-09-17 12:30:59 -07001214/**
Bruce Allanca15df52009-10-26 11:23:43 +00001215 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1216 * @hw: pointer to the HW structure
1217 *
1218 * Acquires the mutex for performing NVM operations.
1219 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001220static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001221{
1222 mutex_lock(&nvm_mutex);
1223
1224 return 0;
1225}
1226
1227/**
1228 * e1000_release_nvm_ich8lan - Release NVM mutex
1229 * @hw: pointer to the HW structure
1230 *
1231 * Releases the mutex used while performing NVM operations.
1232 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001233static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001234{
1235 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001236}
1237
Bruce Allanca15df52009-10-26 11:23:43 +00001238/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001239 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1240 * @hw: pointer to the HW structure
1241 *
Bruce Allanca15df52009-10-26 11:23:43 +00001242 * Acquires the software control flag for performing PHY and select
1243 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 **/
1245static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1246{
Bruce Allan373a88d2009-08-07 07:41:37 +00001247 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1248 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249
Bruce Allana90b4122011-10-07 03:50:38 +00001250 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1251 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001252 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001253 return -E1000_ERR_PHY;
1254 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001255
Auke Kokbc7f75f2007-09-17 12:30:59 -07001256 while (timeout) {
1257 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001258 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1259 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260
Auke Kokbc7f75f2007-09-17 12:30:59 -07001261 mdelay(1);
1262 timeout--;
1263 }
1264
1265 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001266 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001267 ret_val = -E1000_ERR_CONFIG;
1268 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001269 }
1270
Bruce Allan53ac5a82009-10-26 11:23:06 +00001271 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001272
1273 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1274 ew32(EXTCNF_CTRL, extcnf_ctrl);
1275
1276 while (timeout) {
1277 extcnf_ctrl = er32(EXTCNF_CTRL);
1278 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1279 break;
1280
1281 mdelay(1);
1282 timeout--;
1283 }
1284
1285 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001286 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 +00001287 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001288 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1289 ew32(EXTCNF_CTRL, extcnf_ctrl);
1290 ret_val = -E1000_ERR_CONFIG;
1291 goto out;
1292 }
1293
1294out:
1295 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001296 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001297
1298 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001299}
1300
1301/**
1302 * e1000_release_swflag_ich8lan - Release software control flag
1303 * @hw: pointer to the HW structure
1304 *
Bruce Allanca15df52009-10-26 11:23:43 +00001305 * Releases the software control flag for performing PHY and select
1306 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001307 **/
1308static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1309{
1310 u32 extcnf_ctrl;
1311
1312 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001313
1314 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1315 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1316 ew32(EXTCNF_CTRL, extcnf_ctrl);
1317 } else {
1318 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1319 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001320
Bruce Allana90b4122011-10-07 03:50:38 +00001321 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001322}
1323
1324/**
Bruce Allan4662e822008-08-26 18:37:06 -07001325 * e1000_check_mng_mode_ich8lan - Checks management mode
1326 * @hw: pointer to the HW structure
1327 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001328 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001329 * This is a function pointer entry point only called by read/write
1330 * routines for the PHY and NVM parts.
1331 **/
1332static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1333{
Bruce Allana708dd82009-11-20 23:28:37 +00001334 u32 fwsm;
1335
1336 fwsm = er32(FWSM);
Bruce Allanf0ff4392013-02-20 04:05:39 +00001337 return ((fwsm & E1000_ICH_FWSM_FW_VALID) &&
1338 ((fwsm & E1000_FWSM_MODE_MASK) ==
1339 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)));
Bruce Allaneb7700d2010-06-16 13:27:05 +00001340}
Bruce Allan4662e822008-08-26 18:37:06 -07001341
Bruce Allaneb7700d2010-06-16 13:27:05 +00001342/**
1343 * e1000_check_mng_mode_pchlan - Checks management mode
1344 * @hw: pointer to the HW structure
1345 *
1346 * This checks if the adapter has iAMT enabled.
1347 * This is a function pointer entry point only called by read/write
1348 * routines for the PHY and NVM parts.
1349 **/
1350static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1351{
1352 u32 fwsm;
1353
1354 fwsm = er32(FWSM);
1355 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
Bruce Allanf0ff4392013-02-20 04:05:39 +00001356 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001357}
1358
1359/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001360 * e1000_rar_set_pch2lan - Set receive address register
1361 * @hw: pointer to the HW structure
1362 * @addr: pointer to the receive address
1363 * @index: receive address array register
1364 *
1365 * Sets the receive address array register at index to the address passed
1366 * in by addr. For 82579, RAR[0] is the base address register that is to
1367 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1368 * Use SHRA[0-3] in place of those reserved for ME.
1369 **/
1370static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1371{
1372 u32 rar_low, rar_high;
1373
Bruce Allane921eb12012-11-28 09:28:37 +00001374 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001375 * from network order (big endian) to little endian
1376 */
1377 rar_low = ((u32)addr[0] |
1378 ((u32)addr[1] << 8) |
1379 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1380
1381 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1382
1383 /* If MAC address zero, no need to set the AV bit */
1384 if (rar_low || rar_high)
1385 rar_high |= E1000_RAH_AV;
1386
1387 if (index == 0) {
1388 ew32(RAL(index), rar_low);
1389 e1e_flush();
1390 ew32(RAH(index), rar_high);
1391 e1e_flush();
1392 return;
1393 }
1394
David Ertmanc3a0dce2013-09-05 04:24:25 +00001395 /* RAR[1-6] are owned by manageability. Skip those and program the
1396 * next address into the SHRA register array.
1397 */
1398 if (index < (u32)(hw->mac.rar_entry_count - 6)) {
Bruce Allan69e1e012012-04-14 03:28:50 +00001399 s32 ret_val;
1400
1401 ret_val = e1000_acquire_swflag_ich8lan(hw);
1402 if (ret_val)
1403 goto out;
1404
1405 ew32(SHRAL(index - 1), rar_low);
1406 e1e_flush();
1407 ew32(SHRAH(index - 1), rar_high);
1408 e1e_flush();
1409
1410 e1000_release_swflag_ich8lan(hw);
1411
1412 /* verify the register updates */
1413 if ((er32(SHRAL(index - 1)) == rar_low) &&
1414 (er32(SHRAH(index - 1)) == rar_high))
1415 return;
1416
1417 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1418 (index - 1), er32(FWSM));
1419 }
1420
1421out:
1422 e_dbg("Failed to write receive address at index %d\n", index);
1423}
1424
1425/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001426 * e1000_rar_set_pch_lpt - Set receive address registers
1427 * @hw: pointer to the HW structure
1428 * @addr: pointer to the receive address
1429 * @index: receive address array register
1430 *
1431 * Sets the receive address register array at index to the address passed
1432 * in by addr. For LPT, RAR[0] is the base address register that is to
1433 * contain the MAC address. SHRA[0-10] are the shared receive address
1434 * registers that are shared between the Host and manageability engine (ME).
1435 **/
1436static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1437{
1438 u32 rar_low, rar_high;
1439 u32 wlock_mac;
1440
Bruce Allane921eb12012-11-28 09:28:37 +00001441 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001442 * from network order (big endian) to little endian
1443 */
1444 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1445 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1446
1447 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1448
1449 /* If MAC address zero, no need to set the AV bit */
1450 if (rar_low || rar_high)
1451 rar_high |= E1000_RAH_AV;
1452
1453 if (index == 0) {
1454 ew32(RAL(index), rar_low);
1455 e1e_flush();
1456 ew32(RAH(index), rar_high);
1457 e1e_flush();
1458 return;
1459 }
1460
Bruce Allane921eb12012-11-28 09:28:37 +00001461 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001462 * it is using - those registers are unavailable for use.
1463 */
1464 if (index < hw->mac.rar_entry_count) {
1465 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1466 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1467
1468 /* Check if all SHRAR registers are locked */
1469 if (wlock_mac == 1)
1470 goto out;
1471
1472 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1473 s32 ret_val;
1474
1475 ret_val = e1000_acquire_swflag_ich8lan(hw);
1476
1477 if (ret_val)
1478 goto out;
1479
1480 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1481 e1e_flush();
1482 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1483 e1e_flush();
1484
1485 e1000_release_swflag_ich8lan(hw);
1486
1487 /* verify the register updates */
1488 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1489 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1490 return;
1491 }
1492 }
1493
1494out:
1495 e_dbg("Failed to write receive address at index %d\n", index);
1496}
1497
1498/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001499 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1500 * @hw: pointer to the HW structure
1501 *
1502 * Checks if firmware is blocking the reset of the PHY.
1503 * This is a function pointer entry point only called by
1504 * reset routines.
1505 **/
1506static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1507{
David Ertmanf7235ef2014-01-23 06:29:13 +00001508 bool blocked = false;
1509 int i = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001510
David Ertmanf7235ef2014-01-23 06:29:13 +00001511 while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&
1512 (i++ < 10))
1513 usleep_range(10000, 20000);
1514 return blocked ? E1000_BLK_PHY_RESET : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001515}
1516
1517/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001518 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1519 * @hw: pointer to the HW structure
1520 *
1521 * Assumes semaphore already acquired.
1522 *
1523 **/
1524static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1525{
1526 u16 phy_data;
1527 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001528 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1529 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan70806a72013-01-05 05:08:37 +00001530 s32 ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001531
1532 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1533
1534 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1535 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001536 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001537
1538 phy_data &= ~HV_SMB_ADDR_MASK;
1539 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1540 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001541
Bruce Allan2fbe4522012-04-19 03:21:47 +00001542 if (hw->phy.type == e1000_phy_i217) {
1543 /* Restore SMBus frequency */
1544 if (freq--) {
1545 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1546 phy_data |= (freq & (1 << 0)) <<
1547 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1548 phy_data |= (freq & (1 << 1)) <<
1549 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1550 } else {
1551 e_dbg("Unsupported SMB frequency in PHY\n");
1552 }
1553 }
1554
Bruce Allan5015e532012-02-08 02:55:56 +00001555 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001556}
1557
1558/**
Bruce Allanf523d212009-10-29 13:45:45 +00001559 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1560 * @hw: pointer to the HW structure
1561 *
1562 * SW should configure the LCD from the NVM extended configuration region
1563 * as a workaround for certain parts.
1564 **/
1565static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1566{
1567 struct e1000_phy_info *phy = &hw->phy;
1568 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001569 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001570 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1571
Bruce Allane921eb12012-11-28 09:28:37 +00001572 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001573 * is needed due to an issue where the NVM configuration is
1574 * not properly autoloaded after power transitions.
1575 * Therefore, after each PHY reset, we will load the
1576 * configuration data out of the NVM manually.
1577 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001578 switch (hw->mac.type) {
1579 case e1000_ich8lan:
1580 if (phy->type != e1000_phy_igp_3)
1581 return ret_val;
1582
Bruce Allan5f3eed62010-09-22 17:15:54 +00001583 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1584 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001585 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1586 break;
1587 }
1588 /* Fall-thru */
1589 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001590 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001591 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001592 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001593 break;
1594 default:
1595 return ret_val;
1596 }
1597
1598 ret_val = hw->phy.ops.acquire(hw);
1599 if (ret_val)
1600 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001601
Bruce Allan8b802a72010-05-10 15:01:10 +00001602 data = er32(FEXTNVM);
1603 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001604 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001605
Bruce Allane921eb12012-11-28 09:28:37 +00001606 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001607 * extended configuration before SW configuration
1608 */
1609 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001610 if ((hw->mac.type < e1000_pch2lan) &&
1611 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1612 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001613
Bruce Allan8b802a72010-05-10 15:01:10 +00001614 cnf_size = er32(EXTCNF_SIZE);
1615 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1616 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1617 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001618 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001619
1620 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1621 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1622
Bruce Allan2fbe4522012-04-19 03:21:47 +00001623 if (((hw->mac.type == e1000_pchlan) &&
1624 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1625 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001626 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001627 * OEM and LCD Write Enable bits are set in the NVM.
1628 * When both NVM bits are cleared, SW will configure
1629 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001630 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001631 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001632 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001633 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001634
Bruce Allan8b802a72010-05-10 15:01:10 +00001635 data = er32(LEDCTL);
1636 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1637 (u16)data);
1638 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001639 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001640 }
1641
1642 /* Configure LCD from extended configuration region. */
1643
1644 /* cnf_base_addr is in DWORD */
1645 word_addr = (u16)(cnf_base_addr << 1);
1646
1647 for (i = 0; i < cnf_size; i++) {
Bruce Allane5fe2542013-02-20 04:06:27 +00001648 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001649 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001650 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001651
Bruce Allan8b802a72010-05-10 15:01:10 +00001652 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1653 1, &reg_addr);
1654 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001655 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001656
Bruce Allan8b802a72010-05-10 15:01:10 +00001657 /* Save off the PHY page for future writes. */
1658 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1659 phy_page = reg_data;
1660 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001661 }
Bruce Allanf523d212009-10-29 13:45:45 +00001662
Bruce Allan8b802a72010-05-10 15:01:10 +00001663 reg_addr &= PHY_REG_MASK;
1664 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001665
Bruce Allanf1430d62012-04-14 04:21:52 +00001666 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001667 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001668 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001669 }
1670
Bruce Allan75ce1532012-02-08 02:54:48 +00001671release:
Bruce Allan94d81862009-11-20 23:25:26 +00001672 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001673 return ret_val;
1674}
1675
1676/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001677 * e1000_k1_gig_workaround_hv - K1 Si workaround
1678 * @hw: pointer to the HW structure
1679 * @link: link up bool flag
1680 *
1681 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1682 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1683 * If link is down, the function will restore the default K1 setting located
1684 * in the NVM.
1685 **/
1686static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1687{
1688 s32 ret_val = 0;
1689 u16 status_reg = 0;
1690 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1691
1692 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001693 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001694
1695 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001696 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001697 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001698 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001699
1700 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1701 if (link) {
1702 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001703 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1704 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001705 if (ret_val)
1706 goto release;
1707
Bruce Allanf0ff4392013-02-20 04:05:39 +00001708 status_reg &= (BM_CS_STATUS_LINK_UP |
1709 BM_CS_STATUS_RESOLVED |
1710 BM_CS_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001711
1712 if (status_reg == (BM_CS_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001713 BM_CS_STATUS_RESOLVED |
1714 BM_CS_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001715 k1_enable = false;
1716 }
1717
1718 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001719 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001720 if (ret_val)
1721 goto release;
1722
Bruce Allanf0ff4392013-02-20 04:05:39 +00001723 status_reg &= (HV_M_STATUS_LINK_UP |
1724 HV_M_STATUS_AUTONEG_COMPLETE |
1725 HV_M_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001726
1727 if (status_reg == (HV_M_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001728 HV_M_STATUS_AUTONEG_COMPLETE |
1729 HV_M_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001730 k1_enable = false;
1731 }
1732
1733 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001734 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001735 if (ret_val)
1736 goto release;
1737
1738 } else {
1739 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001740 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001741 if (ret_val)
1742 goto release;
1743 }
1744
1745 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1746
1747release:
Bruce Allan94d81862009-11-20 23:25:26 +00001748 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001749
Bruce Allan1d5846b2009-10-29 13:46:05 +00001750 return ret_val;
1751}
1752
1753/**
1754 * e1000_configure_k1_ich8lan - Configure K1 power state
1755 * @hw: pointer to the HW structure
1756 * @enable: K1 state to configure
1757 *
1758 * Configure the K1 power state based on the provided parameter.
1759 * Assumes semaphore already acquired.
1760 *
1761 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1762 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001763s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001764{
Bruce Allan70806a72013-01-05 05:08:37 +00001765 s32 ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001766 u32 ctrl_reg = 0;
1767 u32 ctrl_ext = 0;
1768 u32 reg = 0;
1769 u16 kmrn_reg = 0;
1770
Bruce Allan3d3a1672012-02-23 03:13:18 +00001771 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1772 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001773 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001774 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001775
1776 if (k1_enable)
1777 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1778 else
1779 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1780
Bruce Allan3d3a1672012-02-23 03:13:18 +00001781 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1782 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001783 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001784 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001785
Bruce Allance43a212013-02-20 04:06:32 +00001786 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001787 ctrl_ext = er32(CTRL_EXT);
1788 ctrl_reg = er32(CTRL);
1789
1790 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1791 reg |= E1000_CTRL_FRCSPD;
1792 ew32(CTRL, reg);
1793
1794 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001795 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001796 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001797 ew32(CTRL, ctrl_reg);
1798 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001799 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001800 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001801
Bruce Allan5015e532012-02-08 02:55:56 +00001802 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001803}
1804
1805/**
Bruce Allanf523d212009-10-29 13:45:45 +00001806 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1807 * @hw: pointer to the HW structure
1808 * @d0_state: boolean if entering d0 or d3 device state
1809 *
1810 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1811 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1812 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1813 **/
1814static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1815{
1816 s32 ret_val = 0;
1817 u32 mac_reg;
1818 u16 oem_reg;
1819
Bruce Allan2fbe4522012-04-19 03:21:47 +00001820 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001821 return ret_val;
1822
Bruce Allan94d81862009-11-20 23:25:26 +00001823 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001824 if (ret_val)
1825 return ret_val;
1826
Bruce Allan2fbe4522012-04-19 03:21:47 +00001827 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001828 mac_reg = er32(EXTCNF_CTRL);
1829 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001830 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001831 }
Bruce Allanf523d212009-10-29 13:45:45 +00001832
1833 mac_reg = er32(FEXTNVM);
1834 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001835 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001836
1837 mac_reg = er32(PHY_CTRL);
1838
Bruce Allanf1430d62012-04-14 04:21:52 +00001839 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001840 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001841 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001842
1843 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1844
1845 if (d0_state) {
1846 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1847 oem_reg |= HV_OEM_BITS_GBE_DIS;
1848
1849 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1850 oem_reg |= HV_OEM_BITS_LPLU;
1851 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001852 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1853 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001854 oem_reg |= HV_OEM_BITS_GBE_DIS;
1855
Bruce Allan03299e42011-09-30 08:07:05 +00001856 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1857 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001858 oem_reg |= HV_OEM_BITS_LPLU;
1859 }
Bruce Allan03299e42011-09-30 08:07:05 +00001860
Bruce Allan92fe1732012-04-12 06:27:03 +00001861 /* Set Restart auto-neg to activate the bits */
1862 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1863 !hw->phy.ops.check_reset_block(hw))
1864 oem_reg |= HV_OEM_BITS_RESTART_AN;
1865
Bruce Allanf1430d62012-04-14 04:21:52 +00001866 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001867
Bruce Allan75ce1532012-02-08 02:54:48 +00001868release:
Bruce Allan94d81862009-11-20 23:25:26 +00001869 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001870
1871 return ret_val;
1872}
1873
Bruce Allanf523d212009-10-29 13:45:45 +00001874/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001875 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1876 * @hw: pointer to the HW structure
1877 **/
1878static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1879{
1880 s32 ret_val;
1881 u16 data;
1882
1883 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1884 if (ret_val)
1885 return ret_val;
1886
1887 data |= HV_KMRN_MDIO_SLOW;
1888
1889 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1890
1891 return ret_val;
1892}
1893
1894/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001895 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1896 * done after every PHY reset.
1897 **/
1898static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1899{
1900 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001901 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001902
1903 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001904 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001905
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001906 /* Set MDIO slow mode before any other MDIO access */
1907 if (hw->phy.type == e1000_phy_82577) {
1908 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1909 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001910 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001911 }
1912
Bruce Allana4f58f52009-06-02 11:29:18 +00001913 if (((hw->phy.type == e1000_phy_82577) &&
1914 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1915 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1916 /* Disable generation of early preamble */
1917 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1918 if (ret_val)
1919 return ret_val;
1920
1921 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001922 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001923 if (ret_val)
1924 return ret_val;
1925 }
1926
1927 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001928 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001929 * writing 0x3140 to the control register.
1930 */
1931 if (hw->phy.revision < 2) {
1932 e1000e_phy_sw_reset(hw);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001933 ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
Bruce Allana4f58f52009-06-02 11:29:18 +00001934 }
1935 }
1936
1937 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001938 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001939 if (ret_val)
1940 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001941
Bruce Allana4f58f52009-06-02 11:29:18 +00001942 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001943 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001944 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001945 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001946 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001947
Bruce Allane921eb12012-11-28 09:28:37 +00001948 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001949 * link so that it disables K1 if link is in 1Gbps.
1950 */
1951 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001952 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001953 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001954
Bruce Allanbaf86c92010-01-13 01:53:08 +00001955 /* Workaround for link disconnects on a busy hub in half duplex */
1956 ret_val = hw->phy.ops.acquire(hw);
1957 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001958 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001959 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001960 if (ret_val)
1961 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001962 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001963 if (ret_val)
1964 goto release;
1965
1966 /* set MSE higher to enable link to stay up when noise is high */
1967 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001968release:
1969 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001970
Bruce Allana4f58f52009-06-02 11:29:18 +00001971 return ret_val;
1972}
1973
1974/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001975 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1976 * @hw: pointer to the HW structure
1977 **/
1978void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1979{
1980 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001981 u16 i, phy_reg = 0;
1982 s32 ret_val;
1983
1984 ret_val = hw->phy.ops.acquire(hw);
1985 if (ret_val)
1986 return;
1987 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1988 if (ret_val)
1989 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001990
David Ertmanc3a0dce2013-09-05 04:24:25 +00001991 /* Copy both RAL/H (rar_entry_count) and SHRAL/H to PHY */
1992 for (i = 0; i < (hw->mac.rar_entry_count); i++) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001993 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001994 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1995 (u16)(mac_reg & 0xFFFF));
1996 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1997 (u16)((mac_reg >> 16) & 0xFFFF));
1998
Bruce Alland3738bb2010-06-16 13:27:28 +00001999 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00002000 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
2001 (u16)(mac_reg & 0xFFFF));
2002 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
2003 (u16)((mac_reg & E1000_RAH_AV)
2004 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00002005 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00002006
2007 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2008
2009release:
2010 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00002011}
2012
Bruce Alland3738bb2010-06-16 13:27:28 +00002013/**
2014 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
2015 * with 82579 PHY
2016 * @hw: pointer to the HW structure
2017 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
2018 **/
2019s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
2020{
2021 s32 ret_val = 0;
2022 u16 phy_reg, data;
2023 u32 mac_reg;
2024 u16 i;
2025
Bruce Allan2fbe4522012-04-19 03:21:47 +00002026 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002027 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002028
2029 /* disable Rx path while enabling/disabling workaround */
2030 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
2031 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
2032 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002033 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002034
2035 if (enable) {
David Ertmanc3a0dce2013-09-05 04:24:25 +00002036 /* Write Rx addresses (rar_entry_count for RAL/H, and
Bruce Alland3738bb2010-06-16 13:27:28 +00002037 * SHRAL/H) and initial CRC values to the MAC
2038 */
David Ertmanc3a0dce2013-09-05 04:24:25 +00002039 for (i = 0; i < hw->mac.rar_entry_count; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002040 u8 mac_addr[ETH_ALEN] = { 0 };
Bruce Alland3738bb2010-06-16 13:27:28 +00002041 u32 addr_high, addr_low;
2042
2043 addr_high = er32(RAH(i));
2044 if (!(addr_high & E1000_RAH_AV))
2045 continue;
2046 addr_low = er32(RAL(i));
2047 mac_addr[0] = (addr_low & 0xFF);
2048 mac_addr[1] = ((addr_low >> 8) & 0xFF);
2049 mac_addr[2] = ((addr_low >> 16) & 0xFF);
2050 mac_addr[3] = ((addr_low >> 24) & 0xFF);
2051 mac_addr[4] = (addr_high & 0xFF);
2052 mac_addr[5] = ((addr_high >> 8) & 0xFF);
2053
Bruce Allanfe46f582011-01-06 14:29:51 +00002054 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00002055 }
2056
2057 /* Write Rx addresses to the PHY */
2058 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
2059
2060 /* Enable jumbo frame workaround in the MAC */
2061 mac_reg = er32(FFLT_DBG);
2062 mac_reg &= ~(1 << 14);
2063 mac_reg |= (7 << 15);
2064 ew32(FFLT_DBG, mac_reg);
2065
2066 mac_reg = er32(RCTL);
2067 mac_reg |= E1000_RCTL_SECRC;
2068 ew32(RCTL, mac_reg);
2069
2070 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002071 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2072 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002073 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002074 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002075 ret_val = e1000e_write_kmrn_reg(hw,
2076 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2077 data | (1 << 0));
2078 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002079 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002080 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002081 E1000_KMRNCTRLSTA_HD_CTRL,
2082 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002083 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002084 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002085 data &= ~(0xF << 8);
2086 data |= (0xB << 8);
2087 ret_val = e1000e_write_kmrn_reg(hw,
2088 E1000_KMRNCTRLSTA_HD_CTRL,
2089 data);
2090 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002091 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002092
2093 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00002094 e1e_rphy(hw, PHY_REG(769, 23), &data);
2095 data &= ~(0x7F << 5);
2096 data |= (0x37 << 5);
2097 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2098 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002099 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002100 e1e_rphy(hw, PHY_REG(769, 16), &data);
2101 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00002102 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2103 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002104 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002105 e1e_rphy(hw, PHY_REG(776, 20), &data);
2106 data &= ~(0x3FF << 2);
2107 data |= (0x1A << 2);
2108 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2109 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002110 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00002111 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00002112 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002113 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002114 e1e_rphy(hw, HV_PM_CTRL, &data);
2115 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
2116 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002117 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002118 } else {
2119 /* Write MAC register values back to h/w defaults */
2120 mac_reg = er32(FFLT_DBG);
2121 mac_reg &= ~(0xF << 14);
2122 ew32(FFLT_DBG, mac_reg);
2123
2124 mac_reg = er32(RCTL);
2125 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00002126 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00002127
2128 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002129 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2130 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002131 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002132 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002133 ret_val = e1000e_write_kmrn_reg(hw,
2134 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2135 data & ~(1 << 0));
2136 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002137 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002138 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002139 E1000_KMRNCTRLSTA_HD_CTRL,
2140 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002141 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002142 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002143 data &= ~(0xF << 8);
2144 data |= (0xB << 8);
2145 ret_val = e1000e_write_kmrn_reg(hw,
2146 E1000_KMRNCTRLSTA_HD_CTRL,
2147 data);
2148 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002149 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002150
2151 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002152 e1e_rphy(hw, PHY_REG(769, 23), &data);
2153 data &= ~(0x7F << 5);
2154 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2155 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002156 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002157 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002158 data |= (1 << 13);
2159 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2160 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002161 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002162 e1e_rphy(hw, PHY_REG(776, 20), &data);
2163 data &= ~(0x3FF << 2);
2164 data |= (0x8 << 2);
2165 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2166 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002167 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002168 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2169 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002170 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002171 e1e_rphy(hw, HV_PM_CTRL, &data);
2172 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2173 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002174 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002175 }
2176
2177 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002178 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002179}
2180
2181/**
2182 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2183 * done after every PHY reset.
2184 **/
2185static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2186{
2187 s32 ret_val = 0;
2188
2189 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002190 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002191
2192 /* Set MDIO slow mode before any other MDIO access */
2193 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002194 if (ret_val)
2195 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002196
Bruce Allan4d241362011-12-16 00:46:06 +00002197 ret_val = hw->phy.ops.acquire(hw);
2198 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002199 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002200 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002201 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002202 if (ret_val)
2203 goto release;
2204 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002205 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002206release:
2207 hw->phy.ops.release(hw);
2208
Bruce Alland3738bb2010-06-16 13:27:28 +00002209 return ret_val;
2210}
2211
2212/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002213 * e1000_k1_gig_workaround_lv - K1 Si workaround
2214 * @hw: pointer to the HW structure
2215 *
2216 * Workaround to set the K1 beacon duration for 82579 parts
2217 **/
2218static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2219{
2220 s32 ret_val = 0;
2221 u16 status_reg = 0;
2222 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002223 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002224
2225 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002226 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002227
2228 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2229 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2230 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002231 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002232
2233 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2234 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2235 mac_reg = er32(FEXTNVM4);
2236 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2237
Bruce Allan0ed013e2011-07-29 05:52:56 +00002238 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2239 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002240 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002241
Bruce Allan0ed013e2011-07-29 05:52:56 +00002242 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002243 u16 pm_phy_reg;
2244
Bruce Allan0ed013e2011-07-29 05:52:56 +00002245 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2246 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002247 /* LV 1G Packet drop issue wa */
2248 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2249 if (ret_val)
2250 return ret_val;
2251 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2252 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2253 if (ret_val)
2254 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002255 } else {
2256 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2257 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2258 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002259 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002260 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002261 }
2262
Bruce Allan831bd2e2010-09-22 17:16:18 +00002263 return ret_val;
2264}
2265
2266/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002267 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2268 * @hw: pointer to the HW structure
2269 * @gate: boolean set to true to gate, false to ungate
2270 *
2271 * Gate/ungate the automatic PHY configuration via hardware; perform
2272 * the configuration via software instead.
2273 **/
2274static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2275{
2276 u32 extcnf_ctrl;
2277
Bruce Allan2fbe4522012-04-19 03:21:47 +00002278 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002279 return;
2280
2281 extcnf_ctrl = er32(EXTCNF_CTRL);
2282
2283 if (gate)
2284 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2285 else
2286 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2287
2288 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002289}
2290
2291/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002292 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2293 * @hw: pointer to the HW structure
2294 *
2295 * Check the appropriate indication the MAC has finished configuring the
2296 * PHY after a software reset.
2297 **/
2298static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2299{
2300 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2301
2302 /* Wait for basic configuration completes before proceeding */
2303 do {
2304 data = er32(STATUS);
2305 data &= E1000_STATUS_LAN_INIT_DONE;
Bruce Allance43a212013-02-20 04:06:32 +00002306 usleep_range(100, 200);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002307 } while ((!data) && --loop);
2308
Bruce Allane921eb12012-11-28 09:28:37 +00002309 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002310 * count reaches 0, loading the configuration from NVM will
2311 * leave the PHY in a bad state possibly resulting in no link.
2312 */
2313 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002314 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002315
2316 /* Clear the Init Done bit for the next init event */
2317 data = er32(STATUS);
2318 data &= ~E1000_STATUS_LAN_INIT_DONE;
2319 ew32(STATUS, data);
2320}
2321
2322/**
Bruce Allane98cac42010-05-10 15:02:32 +00002323 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002326static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327{
Bruce Allanf523d212009-10-29 13:45:45 +00002328 s32 ret_val = 0;
2329 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330
Bruce Allan44abd5c2012-02-22 09:02:37 +00002331 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002332 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002333
Bruce Allan5f3eed62010-09-22 17:15:54 +00002334 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002335 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002336
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002337 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002338 switch (hw->mac.type) {
2339 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002340 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2341 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002342 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002343 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002344 case e1000_pch2lan:
2345 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2346 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002347 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002348 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002349 default:
2350 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002351 }
2352
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002353 /* Clear the host wakeup bit after lcd reset */
2354 if (hw->mac.type >= e1000_pchlan) {
2355 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2356 reg &= ~BM_WUC_HOST_WU_BIT;
2357 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2358 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002359
Bruce Allanf523d212009-10-29 13:45:45 +00002360 /* Configure the LCD with the extended configuration region in NVM */
2361 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2362 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002363 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002364
Bruce Allanf523d212009-10-29 13:45:45 +00002365 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002366 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002367
Bruce Allan1effb452011-02-25 06:58:03 +00002368 if (hw->mac.type == e1000_pch2lan) {
2369 /* Ungate automatic PHY configuration on non-managed 82579 */
2370 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002371 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002372 e1000_gate_hw_phy_config_ich8lan(hw, false);
2373 }
2374
2375 /* Set EEE LPI Update Timer to 200usec */
2376 ret_val = hw->phy.ops.acquire(hw);
2377 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002378 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002379 ret_val = e1000_write_emi_reg_locked(hw,
2380 I82579_LPI_UPDATE_TIMER,
2381 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002382 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002383 }
2384
Bruce Allane98cac42010-05-10 15:02:32 +00002385 return ret_val;
2386}
2387
2388/**
2389 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2390 * @hw: pointer to the HW structure
2391 *
2392 * Resets the PHY
2393 * This is a function pointer entry point called by drivers
2394 * or other shared routines.
2395 **/
2396static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2397{
2398 s32 ret_val = 0;
2399
Bruce Allan605c82b2010-09-22 17:17:01 +00002400 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2401 if ((hw->mac.type == e1000_pch2lan) &&
2402 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2403 e1000_gate_hw_phy_config_ich8lan(hw, true);
2404
Bruce Allane98cac42010-05-10 15:02:32 +00002405 ret_val = e1000e_phy_hw_reset_generic(hw);
2406 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002407 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002408
Bruce Allan5015e532012-02-08 02:55:56 +00002409 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002410}
2411
2412/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002413 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2414 * @hw: pointer to the HW structure
2415 * @active: true to enable LPLU, false to disable
2416 *
2417 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2418 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2419 * the phy speed. This function will manually set the LPLU bit and restart
2420 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2421 * since it configures the same bit.
2422 **/
2423static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2424{
Bruce Allan70806a72013-01-05 05:08:37 +00002425 s32 ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002426 u16 oem_reg;
2427
2428 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2429 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002430 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002431
2432 if (active)
2433 oem_reg |= HV_OEM_BITS_LPLU;
2434 else
2435 oem_reg &= ~HV_OEM_BITS_LPLU;
2436
Bruce Allan44abd5c2012-02-22 09:02:37 +00002437 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002438 oem_reg |= HV_OEM_BITS_RESTART_AN;
2439
Bruce Allan5015e532012-02-08 02:55:56 +00002440 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002441}
2442
2443/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002444 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2445 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002446 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002447 *
2448 * Sets the LPLU D0 state according to the active flag. When
2449 * activating LPLU this function also disables smart speed
2450 * and vice versa. LPLU will not be activated unless the
2451 * device autonegotiation advertisement meets standards of
2452 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2453 * This is a function pointer entry point only called by
2454 * PHY setup routines.
2455 **/
2456static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2457{
2458 struct e1000_phy_info *phy = &hw->phy;
2459 u32 phy_ctrl;
2460 s32 ret_val = 0;
2461 u16 data;
2462
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002463 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002464 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465
2466 phy_ctrl = er32(PHY_CTRL);
2467
2468 if (active) {
2469 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2470 ew32(PHY_CTRL, phy_ctrl);
2471
Bruce Allan60f12922009-07-01 13:28:14 +00002472 if (phy->type != e1000_phy_igp_3)
2473 return 0;
2474
Bruce Allane921eb12012-11-28 09:28:37 +00002475 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002476 * any PHY registers
2477 */
Bruce Allan60f12922009-07-01 13:28:14 +00002478 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002479 e1000e_gig_downshift_workaround_ich8lan(hw);
2480
2481 /* When LPLU is enabled, we should disable SmartSpeed */
2482 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00002483 if (ret_val)
2484 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002485 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2486 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2487 if (ret_val)
2488 return ret_val;
2489 } else {
2490 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2491 ew32(PHY_CTRL, phy_ctrl);
2492
Bruce Allan60f12922009-07-01 13:28:14 +00002493 if (phy->type != e1000_phy_igp_3)
2494 return 0;
2495
Bruce Allane921eb12012-11-28 09:28:37 +00002496 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002497 * during Dx states where the power conservation is most
2498 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002499 * SmartSpeed, so performance is maintained.
2500 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002501 if (phy->smart_speed == e1000_smart_speed_on) {
2502 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002503 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504 if (ret_val)
2505 return ret_val;
2506
2507 data |= IGP01E1000_PSCFR_SMART_SPEED;
2508 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002509 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002510 if (ret_val)
2511 return ret_val;
2512 } else if (phy->smart_speed == e1000_smart_speed_off) {
2513 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002514 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002515 if (ret_val)
2516 return ret_val;
2517
2518 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2519 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002520 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 if (ret_val)
2522 return ret_val;
2523 }
2524 }
2525
2526 return 0;
2527}
2528
2529/**
2530 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2531 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002532 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002533 *
2534 * Sets the LPLU D3 state according to the active flag. When
2535 * activating LPLU this function also disables smart speed
2536 * and vice versa. LPLU will not be activated unless the
2537 * device autonegotiation advertisement meets standards of
2538 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2539 * This is a function pointer entry point only called by
2540 * PHY setup routines.
2541 **/
2542static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2543{
2544 struct e1000_phy_info *phy = &hw->phy;
2545 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002546 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002547 u16 data;
2548
2549 phy_ctrl = er32(PHY_CTRL);
2550
2551 if (!active) {
2552 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2553 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002554
2555 if (phy->type != e1000_phy_igp_3)
2556 return 0;
2557
Bruce Allane921eb12012-11-28 09:28:37 +00002558 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002559 * during Dx states where the power conservation is most
2560 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002561 * SmartSpeed, so performance is maintained.
2562 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002564 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2565 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566 if (ret_val)
2567 return ret_val;
2568
2569 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002570 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2571 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002572 if (ret_val)
2573 return ret_val;
2574 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002575 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2576 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577 if (ret_val)
2578 return ret_val;
2579
2580 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002581 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2582 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002583 if (ret_val)
2584 return ret_val;
2585 }
2586 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2587 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2588 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2589 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2590 ew32(PHY_CTRL, phy_ctrl);
2591
Bruce Allan60f12922009-07-01 13:28:14 +00002592 if (phy->type != e1000_phy_igp_3)
2593 return 0;
2594
Bruce Allane921eb12012-11-28 09:28:37 +00002595 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002596 * any PHY registers
2597 */
Bruce Allan60f12922009-07-01 13:28:14 +00002598 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002599 e1000e_gig_downshift_workaround_ich8lan(hw);
2600
2601 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002602 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002603 if (ret_val)
2604 return ret_val;
2605
2606 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002607 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002608 }
2609
Bruce Alland7eb3382012-02-08 02:55:14 +00002610 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611}
2612
2613/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002614 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2615 * @hw: pointer to the HW structure
2616 * @bank: pointer to the variable that returns the active bank
2617 *
2618 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002619 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002620 **/
2621static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2622{
Bruce Allane2434552008-11-21 17:02:41 -08002623 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002624 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002625 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2626 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002627 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002628 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002629
Bruce Allane2434552008-11-21 17:02:41 -08002630 switch (hw->mac.type) {
2631 case e1000_ich8lan:
2632 case e1000_ich9lan:
2633 eecd = er32(EECD);
2634 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2635 E1000_EECD_SEC1VAL_VALID_MASK) {
2636 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002637 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002638 else
2639 *bank = 0;
2640
2641 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002642 }
Bruce Allan434f1392011-12-16 00:46:54 +00002643 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002644 /* fall-thru */
2645 default:
2646 /* set bank to 0 in case flash read fails */
2647 *bank = 0;
2648
2649 /* Check bank 0 */
2650 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002651 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002652 if (ret_val)
2653 return ret_val;
2654 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2655 E1000_ICH_NVM_SIG_VALUE) {
2656 *bank = 0;
2657 return 0;
2658 }
2659
2660 /* Check bank 1 */
2661 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002662 bank1_offset,
2663 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002664 if (ret_val)
2665 return ret_val;
2666 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2667 E1000_ICH_NVM_SIG_VALUE) {
2668 *bank = 1;
2669 return 0;
2670 }
2671
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002672 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002673 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002674 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002675}
2676
2677/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002678 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2679 * @hw: pointer to the HW structure
2680 * @offset: The offset (in bytes) of the word(s) to read.
2681 * @words: Size of data to read in words
2682 * @data: Pointer to the word(s) to read at offset.
2683 *
2684 * Reads a word(s) from the NVM using the flash access registers.
2685 **/
2686static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2687 u16 *data)
2688{
2689 struct e1000_nvm_info *nvm = &hw->nvm;
2690 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2691 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002692 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002693 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002694 u16 i, word;
2695
2696 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2697 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002698 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002699 ret_val = -E1000_ERR_NVM;
2700 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002701 }
2702
Bruce Allan94d81862009-11-20 23:25:26 +00002703 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002704
Bruce Allanf4187b52008-08-26 18:36:50 -07002705 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002706 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002707 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002708 bank = 0;
2709 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002710
2711 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002712 act_offset += offset;
2713
Bruce Allan148675a2009-08-07 07:41:56 +00002714 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002715 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002716 if (dev_spec->shadow_ram[offset + i].modified) {
2717 data[i] = dev_spec->shadow_ram[offset + i].value;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718 } else {
2719 ret_val = e1000_read_flash_word_ich8lan(hw,
2720 act_offset + i,
2721 &word);
2722 if (ret_val)
2723 break;
2724 data[i] = word;
2725 }
2726 }
2727
Bruce Allan94d81862009-11-20 23:25:26 +00002728 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002729
Bruce Allane2434552008-11-21 17:02:41 -08002730out:
2731 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002732 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002733
Auke Kokbc7f75f2007-09-17 12:30:59 -07002734 return ret_val;
2735}
2736
2737/**
2738 * e1000_flash_cycle_init_ich8lan - Initialize flash
2739 * @hw: pointer to the HW structure
2740 *
2741 * This function does initial flash setup so that a new read/write/erase cycle
2742 * can be started.
2743 **/
2744static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2745{
2746 union ich8_hws_flash_status hsfsts;
2747 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002748
2749 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2750
2751 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002752 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002753 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002754 return -E1000_ERR_NVM;
2755 }
2756
2757 /* Clear FCERR and DAEL in hw status by writing 1 */
2758 hsfsts.hsf_status.flcerr = 1;
2759 hsfsts.hsf_status.dael = 1;
2760
2761 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2762
Bruce Allane921eb12012-11-28 09:28:37 +00002763 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002764 * bit to check against, in order to start a new cycle or
2765 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002766 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002767 * indication whether a cycle is in progress or has been
2768 * completed.
2769 */
2770
Bruce Allan04499ec2012-04-13 00:08:31 +00002771 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002772 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002773 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002774 * Begin by setting Flash Cycle Done.
2775 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002776 hsfsts.hsf_status.flcdone = 1;
2777 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2778 ret_val = 0;
2779 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002780 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002781
Bruce Allane921eb12012-11-28 09:28:37 +00002782 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002783 * cycle has a chance to end before giving up.
2784 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002785 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002786 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002787 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002788 ret_val = 0;
2789 break;
2790 }
2791 udelay(1);
2792 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002793 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002794 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002795 * now set the Flash Cycle Done.
2796 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002797 hsfsts.hsf_status.flcdone = 1;
2798 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2799 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002800 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801 }
2802 }
2803
2804 return ret_val;
2805}
2806
2807/**
2808 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2809 * @hw: pointer to the HW structure
2810 * @timeout: maximum time to wait for completion
2811 *
2812 * This function starts a flash cycle and waits for its completion.
2813 **/
2814static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2815{
2816 union ich8_hws_flash_ctrl hsflctl;
2817 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002818 u32 i = 0;
2819
2820 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2821 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2822 hsflctl.hsf_ctrl.flcgo = 1;
2823 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2824
2825 /* wait till FDONE bit is set to 1 */
2826 do {
2827 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002828 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 break;
2830 udelay(1);
2831 } while (i++ < timeout);
2832
Bruce Allan04499ec2012-04-13 00:08:31 +00002833 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002834 return 0;
2835
Bruce Allan55920b52012-02-08 02:55:25 +00002836 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002837}
2838
2839/**
2840 * e1000_read_flash_word_ich8lan - Read word from flash
2841 * @hw: pointer to the HW structure
2842 * @offset: offset to data location
2843 * @data: pointer to the location for storing the data
2844 *
2845 * Reads the flash word at offset into data. Offset is converted
2846 * to bytes before read.
2847 **/
2848static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2849 u16 *data)
2850{
2851 /* Must convert offset into bytes. */
2852 offset <<= 1;
2853
2854 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2855}
2856
2857/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002858 * e1000_read_flash_byte_ich8lan - Read byte from flash
2859 * @hw: pointer to the HW structure
2860 * @offset: The offset of the byte to read.
2861 * @data: Pointer to a byte to store the value read.
2862 *
2863 * Reads a single byte from the NVM using the flash access registers.
2864 **/
2865static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2866 u8 *data)
2867{
2868 s32 ret_val;
2869 u16 word = 0;
2870
2871 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2872 if (ret_val)
2873 return ret_val;
2874
2875 *data = (u8)word;
2876
2877 return 0;
2878}
2879
2880/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002881 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2882 * @hw: pointer to the HW structure
2883 * @offset: The offset (in bytes) of the byte or word to read.
2884 * @size: Size of data to read, 1=byte 2=word
2885 * @data: Pointer to the word to store the value read.
2886 *
2887 * Reads a byte or word from the NVM using the flash access registers.
2888 **/
2889static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2890 u8 size, u16 *data)
2891{
2892 union ich8_hws_flash_status hsfsts;
2893 union ich8_hws_flash_ctrl hsflctl;
2894 u32 flash_linear_addr;
2895 u32 flash_data = 0;
2896 s32 ret_val = -E1000_ERR_NVM;
2897 u8 count = 0;
2898
Bruce Allane80bd1d2013-05-01 01:19:46 +00002899 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002900 return -E1000_ERR_NVM;
2901
Bruce Allanf0ff4392013-02-20 04:05:39 +00002902 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2903 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002904
2905 do {
2906 udelay(1);
2907 /* Steps */
2908 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002909 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002910 break;
2911
2912 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2913 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2914 hsflctl.hsf_ctrl.fldbcount = size - 1;
2915 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2916 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2917
2918 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2919
Bruce Allan17e813e2013-02-20 04:06:01 +00002920 ret_val =
2921 e1000_flash_cycle_ich8lan(hw,
2922 ICH_FLASH_READ_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002923
Bruce Allane921eb12012-11-28 09:28:37 +00002924 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002925 * and try the whole sequence a few more times, else
2926 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002927 * least significant byte first msb to lsb
2928 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002929 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002930 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002931 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002932 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002933 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002934 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002935 break;
2936 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002937 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002938 * completely hosed, but if the error condition is
2939 * detected, it won't hurt to give it another try...
2940 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2941 */
2942 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002943 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944 /* Repeat for some time before giving up. */
2945 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002946 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002947 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002948 break;
2949 }
2950 }
2951 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2952
2953 return ret_val;
2954}
2955
2956/**
2957 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2958 * @hw: pointer to the HW structure
2959 * @offset: The offset (in bytes) of the word(s) to write.
2960 * @words: Size of data to write in words
2961 * @data: Pointer to the word(s) to write at offset.
2962 *
2963 * Writes a byte or word to the NVM using the flash access registers.
2964 **/
2965static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2966 u16 *data)
2967{
2968 struct e1000_nvm_info *nvm = &hw->nvm;
2969 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002970 u16 i;
2971
2972 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2973 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002974 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002975 return -E1000_ERR_NVM;
2976 }
2977
Bruce Allan94d81862009-11-20 23:25:26 +00002978 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002979
Auke Kokbc7f75f2007-09-17 12:30:59 -07002980 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002981 dev_spec->shadow_ram[offset + i].modified = true;
2982 dev_spec->shadow_ram[offset + i].value = data[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07002983 }
2984
Bruce Allan94d81862009-11-20 23:25:26 +00002985 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002986
Auke Kokbc7f75f2007-09-17 12:30:59 -07002987 return 0;
2988}
2989
2990/**
2991 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2992 * @hw: pointer to the HW structure
2993 *
2994 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2995 * which writes the checksum to the shadow ram. The changes in the shadow
2996 * ram are then committed to the EEPROM by processing each bank at a time
2997 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002998 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002999 * future writes.
3000 **/
3001static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
3002{
3003 struct e1000_nvm_info *nvm = &hw->nvm;
3004 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07003005 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003006 s32 ret_val;
3007 u16 data;
3008
3009 ret_val = e1000e_update_nvm_checksum_generic(hw);
3010 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08003011 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003012
3013 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08003014 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003015
Bruce Allan94d81862009-11-20 23:25:26 +00003016 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003017
Bruce Allane921eb12012-11-28 09:28:37 +00003018 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003019 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07003020 * is going to be written
3021 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003022 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08003023 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003024 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00003025 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003026 }
Bruce Allanf4187b52008-08-26 18:36:50 -07003027
3028 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003029 new_bank_offset = nvm->flash_bank_size;
3030 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003031 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003032 if (ret_val)
3033 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003034 } else {
3035 old_bank_offset = nvm->flash_bank_size;
3036 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003037 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003038 if (ret_val)
3039 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003040 }
3041
3042 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00003043 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07003044 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07003045 * in the shadow RAM
3046 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003047 if (dev_spec->shadow_ram[i].modified) {
3048 data = dev_spec->shadow_ram[i].value;
3049 } else {
Bruce Allane2434552008-11-21 17:02:41 -08003050 ret_val = e1000_read_flash_word_ich8lan(hw, i +
Bruce Allanf0ff4392013-02-20 04:05:39 +00003051 old_bank_offset,
3052 &data);
Bruce Allane2434552008-11-21 17:02:41 -08003053 if (ret_val)
3054 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003055 }
3056
Bruce Allane921eb12012-11-28 09:28:37 +00003057 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07003058 * (15:14) are 11b until the commit has completed.
3059 * This will allow us to write 10b which indicates the
3060 * signature is valid. We want to do this after the write
3061 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07003062 * while the write is still in progress
3063 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003064 if (i == E1000_ICH_NVM_SIG_WORD)
3065 data |= E1000_ICH_NVM_SIG_MASK;
3066
3067 /* Convert offset to bytes. */
3068 act_offset = (i + new_bank_offset) << 1;
3069
Bruce Allance43a212013-02-20 04:06:32 +00003070 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003071 /* Write the bytes to the new bank. */
3072 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3073 act_offset,
3074 (u8)data);
3075 if (ret_val)
3076 break;
3077
Bruce Allance43a212013-02-20 04:06:32 +00003078 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003079 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003080 act_offset + 1,
3081 (u8)(data >> 8));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003082 if (ret_val)
3083 break;
3084 }
3085
Bruce Allane921eb12012-11-28 09:28:37 +00003086 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07003087 * programming failed.
3088 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003089 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07003090 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003091 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00003092 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093 }
3094
Bruce Allane921eb12012-11-28 09:28:37 +00003095 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096 * to 10b in word 0x13 , this can be done without an
3097 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07003098 * and we need to change bit 14 to 0b
3099 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003100 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08003101 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003102 if (ret_val)
3103 goto release;
3104
Auke Kokbc7f75f2007-09-17 12:30:59 -07003105 data &= 0xBFFF;
3106 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3107 act_offset * 2 + 1,
3108 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00003109 if (ret_val)
3110 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003111
Bruce Allane921eb12012-11-28 09:28:37 +00003112 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07003113 * its signature word (0x13) high_byte to 0b. This can be
3114 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07003115 * to 1's. We can write 1's to 0's without an erase
3116 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003117 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
3118 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003119 if (ret_val)
3120 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003121
3122 /* Great! Everything worked, we can now clear the cached entries. */
3123 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00003124 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003125 dev_spec->shadow_ram[i].value = 0xFFFF;
3126 }
3127
Bruce Allan9c5e2092010-05-10 15:00:31 +00003128release:
Bruce Allan94d81862009-11-20 23:25:26 +00003129 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003130
Bruce Allane921eb12012-11-28 09:28:37 +00003131 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07003132 * until after the next adapter reset.
3133 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00003134 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00003135 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00003136 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003137 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003138
Bruce Allane2434552008-11-21 17:02:41 -08003139out:
3140 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003141 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003142
Auke Kokbc7f75f2007-09-17 12:30:59 -07003143 return ret_val;
3144}
3145
3146/**
3147 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3148 * @hw: pointer to the HW structure
3149 *
3150 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3151 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3152 * calculated, in which case we need to calculate the checksum and set bit 6.
3153 **/
3154static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3155{
3156 s32 ret_val;
3157 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003158 u16 word;
3159 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003160
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003161 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3162 * the checksum needs to be fixed. This bit is an indication that
3163 * the NVM was prepared by OEM software and did not calculate
3164 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003165 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003166 switch (hw->mac.type) {
3167 case e1000_pch_lpt:
3168 word = NVM_COMPAT;
3169 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3170 break;
3171 default:
3172 word = NVM_FUTURE_INIT_WORD1;
3173 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3174 break;
3175 }
3176
3177 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003178 if (ret_val)
3179 return ret_val;
3180
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003181 if (!(data & valid_csum_mask)) {
3182 data |= valid_csum_mask;
3183 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003184 if (ret_val)
3185 return ret_val;
3186 ret_val = e1000e_update_nvm_checksum(hw);
3187 if (ret_val)
3188 return ret_val;
3189 }
3190
3191 return e1000e_validate_nvm_checksum_generic(hw);
3192}
3193
3194/**
Bruce Allan4a770352008-10-01 17:18:35 -07003195 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3196 * @hw: pointer to the HW structure
3197 *
3198 * To prevent malicious write/erase of the NVM, set it to be read-only
3199 * so that the hardware ignores all write/erase cycles of the NVM via
3200 * the flash control registers. The shadow-ram copy of the NVM will
3201 * still be updated, however any updates to this copy will not stick
3202 * across driver reloads.
3203 **/
3204void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3205{
Bruce Allanca15df52009-10-26 11:23:43 +00003206 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003207 union ich8_flash_protected_range pr0;
3208 union ich8_hws_flash_status hsfsts;
3209 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003210
Bruce Allan94d81862009-11-20 23:25:26 +00003211 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003212
3213 gfpreg = er32flash(ICH_FLASH_GFPREG);
3214
3215 /* Write-protect GbE Sector of NVM */
3216 pr0.regval = er32flash(ICH_FLASH_PR0);
3217 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3218 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3219 pr0.range.wpe = true;
3220 ew32flash(ICH_FLASH_PR0, pr0.regval);
3221
Bruce Allane921eb12012-11-28 09:28:37 +00003222 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003223 * PR0 to prevent the write-protection from being lifted.
3224 * Once FLOCKDN is set, the registers protected by it cannot
3225 * be written until FLOCKDN is cleared by a hardware reset.
3226 */
3227 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3228 hsfsts.hsf_status.flockdn = true;
3229 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3230
Bruce Allan94d81862009-11-20 23:25:26 +00003231 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003232}
3233
3234/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003235 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3236 * @hw: pointer to the HW structure
3237 * @offset: The offset (in bytes) of the byte/word to read.
3238 * @size: Size of data to read, 1=byte 2=word
3239 * @data: The byte(s) to write to the NVM.
3240 *
3241 * Writes one/two bytes to the NVM using the flash access registers.
3242 **/
3243static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3244 u8 size, u16 data)
3245{
3246 union ich8_hws_flash_status hsfsts;
3247 union ich8_hws_flash_ctrl hsflctl;
3248 u32 flash_linear_addr;
3249 u32 flash_data = 0;
3250 s32 ret_val;
3251 u8 count = 0;
3252
3253 if (size < 1 || size > 2 || data > size * 0xff ||
3254 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3255 return -E1000_ERR_NVM;
3256
Bruce Allanf0ff4392013-02-20 04:05:39 +00003257 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3258 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003259
3260 do {
3261 udelay(1);
3262 /* Steps */
3263 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3264 if (ret_val)
3265 break;
3266
3267 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3268 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
Bruce Allan362e20c2013-02-20 04:05:45 +00003269 hsflctl.hsf_ctrl.fldbcount = size - 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003270 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3271 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3272
3273 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3274
3275 if (size == 1)
3276 flash_data = (u32)data & 0x00FF;
3277 else
3278 flash_data = (u32)data;
3279
3280 ew32flash(ICH_FLASH_FDATA0, flash_data);
3281
Bruce Allane921eb12012-11-28 09:28:37 +00003282 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003283 * and try the whole sequence a few more times else done
3284 */
Bruce Allan17e813e2013-02-20 04:06:01 +00003285 ret_val =
3286 e1000_flash_cycle_ich8lan(hw,
3287 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003288 if (!ret_val)
3289 break;
3290
Bruce Allane921eb12012-11-28 09:28:37 +00003291 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003292 * completely hosed, but if the error condition
3293 * is detected, it won't hurt to give it another
3294 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3295 */
3296 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003297 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003298 /* Repeat for some time before giving up. */
3299 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003300 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003301 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302 break;
3303 }
3304 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3305
3306 return ret_val;
3307}
3308
3309/**
3310 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3311 * @hw: pointer to the HW structure
3312 * @offset: The index of the byte to read.
3313 * @data: The byte to write to the NVM.
3314 *
3315 * Writes a single byte to the NVM using the flash access registers.
3316 **/
3317static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3318 u8 data)
3319{
3320 u16 word = (u16)data;
3321
3322 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3323}
3324
3325/**
3326 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3327 * @hw: pointer to the HW structure
3328 * @offset: The offset of the byte to write.
3329 * @byte: The byte to write to the NVM.
3330 *
3331 * Writes a single byte to the NVM using the flash access registers.
3332 * Goes through a retry algorithm before giving up.
3333 **/
3334static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3335 u32 offset, u8 byte)
3336{
3337 s32 ret_val;
3338 u16 program_retries;
3339
3340 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3341 if (!ret_val)
3342 return ret_val;
3343
3344 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003345 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Bruce Allance43a212013-02-20 04:06:32 +00003346 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003347 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3348 if (!ret_val)
3349 break;
3350 }
3351 if (program_retries == 100)
3352 return -E1000_ERR_NVM;
3353
3354 return 0;
3355}
3356
3357/**
3358 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3359 * @hw: pointer to the HW structure
3360 * @bank: 0 for first bank, 1 for second bank, etc.
3361 *
3362 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3363 * bank N is 4096 * N + flash_reg_addr.
3364 **/
3365static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3366{
3367 struct e1000_nvm_info *nvm = &hw->nvm;
3368 union ich8_hws_flash_status hsfsts;
3369 union ich8_hws_flash_ctrl hsflctl;
3370 u32 flash_linear_addr;
3371 /* bank size is in 16bit words - adjust to bytes */
3372 u32 flash_bank_size = nvm->flash_bank_size * 2;
3373 s32 ret_val;
3374 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003375 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003376
3377 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3378
Bruce Allane921eb12012-11-28 09:28:37 +00003379 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003380 * register
3381 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003382 * consecutive sectors. The start index for the nth Hw sector
3383 * can be calculated as = bank * 4096 + n * 256
3384 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3385 * The start index for the nth Hw sector can be calculated
3386 * as = bank * 4096
3387 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3388 * (ich9 only, otherwise error condition)
3389 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3390 */
3391 switch (hsfsts.hsf_status.berasesz) {
3392 case 0:
3393 /* Hw sector size 256 */
3394 sector_size = ICH_FLASH_SEG_SIZE_256;
3395 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3396 break;
3397 case 1:
3398 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003399 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003400 break;
3401 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003402 sector_size = ICH_FLASH_SEG_SIZE_8K;
3403 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003404 break;
3405 case 3:
3406 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003407 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003408 break;
3409 default:
3410 return -E1000_ERR_NVM;
3411 }
3412
3413 /* Start with the base address, then add the sector offset. */
3414 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003415 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003416
Bruce Allan53aa82d2013-02-20 04:06:06 +00003417 for (j = 0; j < iteration; j++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003418 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00003419 u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
3420
Auke Kokbc7f75f2007-09-17 12:30:59 -07003421 /* Steps */
3422 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3423 if (ret_val)
3424 return ret_val;
3425
Bruce Allane921eb12012-11-28 09:28:37 +00003426 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003427 * Cycle field in hw flash control
3428 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003429 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3430 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3431 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3432
Bruce Allane921eb12012-11-28 09:28:37 +00003433 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003434 * block into Flash Linear address field in Flash
3435 * Address.
3436 */
3437 flash_linear_addr += (j * sector_size);
3438 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3439
Bruce Allan17e813e2013-02-20 04:06:01 +00003440 ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003441 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003442 break;
3443
Bruce Allane921eb12012-11-28 09:28:37 +00003444 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003445 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003446 * a few more times else Done
3447 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003448 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003449 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003450 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003451 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003452 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003453 return ret_val;
3454 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3455 }
3456
3457 return 0;
3458}
3459
3460/**
3461 * e1000_valid_led_default_ich8lan - Set the default LED settings
3462 * @hw: pointer to the HW structure
3463 * @data: Pointer to the LED settings
3464 *
3465 * Reads the LED default settings from the NVM to data. If the NVM LED
3466 * settings is all 0's or F's, set the LED default to a valid LED default
3467 * setting.
3468 **/
3469static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3470{
3471 s32 ret_val;
3472
3473 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3474 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003475 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003476 return ret_val;
3477 }
3478
Bruce Allane5fe2542013-02-20 04:06:27 +00003479 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003480 *data = ID_LED_DEFAULT_ICH8LAN;
3481
3482 return 0;
3483}
3484
3485/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003486 * e1000_id_led_init_pchlan - store LED configurations
3487 * @hw: pointer to the HW structure
3488 *
3489 * PCH does not control LEDs via the LEDCTL register, rather it uses
3490 * the PHY LED configuration register.
3491 *
3492 * PCH also does not have an "always on" or "always off" mode which
3493 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003494 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003495 * use "link_up" mode. The LEDs will still ID on request if there is no
3496 * link based on logic in e1000_led_[on|off]_pchlan().
3497 **/
3498static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3499{
3500 struct e1000_mac_info *mac = &hw->mac;
3501 s32 ret_val;
3502 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3503 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3504 u16 data, i, temp, shift;
3505
3506 /* Get default ID LED modes */
3507 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3508 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003509 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003510
3511 mac->ledctl_default = er32(LEDCTL);
3512 mac->ledctl_mode1 = mac->ledctl_default;
3513 mac->ledctl_mode2 = mac->ledctl_default;
3514
3515 for (i = 0; i < 4; i++) {
3516 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3517 shift = (i * 5);
3518 switch (temp) {
3519 case ID_LED_ON1_DEF2:
3520 case ID_LED_ON1_ON2:
3521 case ID_LED_ON1_OFF2:
3522 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3523 mac->ledctl_mode1 |= (ledctl_on << shift);
3524 break;
3525 case ID_LED_OFF1_DEF2:
3526 case ID_LED_OFF1_ON2:
3527 case ID_LED_OFF1_OFF2:
3528 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3529 mac->ledctl_mode1 |= (ledctl_off << shift);
3530 break;
3531 default:
3532 /* Do nothing */
3533 break;
3534 }
3535 switch (temp) {
3536 case ID_LED_DEF1_ON2:
3537 case ID_LED_ON1_ON2:
3538 case ID_LED_OFF1_ON2:
3539 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3540 mac->ledctl_mode2 |= (ledctl_on << shift);
3541 break;
3542 case ID_LED_DEF1_OFF2:
3543 case ID_LED_ON1_OFF2:
3544 case ID_LED_OFF1_OFF2:
3545 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3546 mac->ledctl_mode2 |= (ledctl_off << shift);
3547 break;
3548 default:
3549 /* Do nothing */
3550 break;
3551 }
3552 }
3553
Bruce Allan5015e532012-02-08 02:55:56 +00003554 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003555}
3556
3557/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003558 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3559 * @hw: pointer to the HW structure
3560 *
3561 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3562 * register, so the the bus width is hard coded.
3563 **/
3564static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3565{
3566 struct e1000_bus_info *bus = &hw->bus;
3567 s32 ret_val;
3568
3569 ret_val = e1000e_get_bus_info_pcie(hw);
3570
Bruce Allane921eb12012-11-28 09:28:37 +00003571 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003572 * a configuration space, but do not contain
3573 * PCI Express Capability registers, so bus width
3574 * must be hardcoded.
3575 */
3576 if (bus->width == e1000_bus_width_unknown)
3577 bus->width = e1000_bus_width_pcie_x1;
3578
3579 return ret_val;
3580}
3581
3582/**
3583 * e1000_reset_hw_ich8lan - Reset the hardware
3584 * @hw: pointer to the HW structure
3585 *
3586 * Does a full reset of the hardware which includes a reset of the PHY and
3587 * MAC.
3588 **/
3589static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3590{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003591 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003592 u16 kum_cfg;
3593 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003594 s32 ret_val;
3595
Bruce Allane921eb12012-11-28 09:28:37 +00003596 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003597 * on the last TLP read/write transaction when MAC is reset.
3598 */
3599 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003600 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003601 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003602
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003603 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003604 ew32(IMC, 0xffffffff);
3605
Bruce Allane921eb12012-11-28 09:28:37 +00003606 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003607 * any pending transactions to complete before we hit the MAC
3608 * with the global reset.
3609 */
3610 ew32(RCTL, 0);
3611 ew32(TCTL, E1000_TCTL_PSP);
3612 e1e_flush();
3613
Bruce Allan1bba4382011-03-19 00:27:20 +00003614 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003615
3616 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3617 if (hw->mac.type == e1000_ich8lan) {
3618 /* Set Tx and Rx buffer allocation to 8k apiece. */
3619 ew32(PBA, E1000_PBA_8K);
3620 /* Set Packet Buffer Size to 16k. */
3621 ew32(PBS, E1000_PBS_16K);
3622 }
3623
Bruce Allan1d5846b2009-10-29 13:46:05 +00003624 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003625 /* Save the NVM K1 bit setting */
3626 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003627 if (ret_val)
3628 return ret_val;
3629
Bruce Allan62bc8132012-03-20 03:47:57 +00003630 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003631 dev_spec->nvm_k1_enabled = true;
3632 else
3633 dev_spec->nvm_k1_enabled = false;
3634 }
3635
Auke Kokbc7f75f2007-09-17 12:30:59 -07003636 ctrl = er32(CTRL);
3637
Bruce Allan44abd5c2012-02-22 09:02:37 +00003638 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003639 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003640 * time to make sure the interface between MAC and the
3641 * external PHY is reset.
3642 */
3643 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003644
Bruce Allane921eb12012-11-28 09:28:37 +00003645 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003646 * non-managed 82579
3647 */
3648 if ((hw->mac.type == e1000_pch2lan) &&
3649 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3650 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003651 }
3652 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003653 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003654 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003655 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003656 msleep(20);
3657
Bruce Allan62bc8132012-03-20 03:47:57 +00003658 /* Set Phy Config Counter to 50msec */
3659 if (hw->mac.type == e1000_pch2lan) {
3660 reg = er32(FEXTNVM3);
3661 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3662 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3663 ew32(FEXTNVM3, reg);
3664 }
3665
Bruce Allanfc0c7762009-07-01 13:27:55 +00003666 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003667 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003668
Bruce Allane98cac42010-05-10 15:02:32 +00003669 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003670 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003671 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003672 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003673
Bruce Allane98cac42010-05-10 15:02:32 +00003674 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003675 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003676 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003677 }
Bruce Allane98cac42010-05-10 15:02:32 +00003678
Bruce Allane921eb12012-11-28 09:28:37 +00003679 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003680 * will be detected as a CRC error and be dropped rather than show up
3681 * as a bad packet to the DMA engine.
3682 */
3683 if (hw->mac.type == e1000_pchlan)
3684 ew32(CRC_OFFSET, 0x65656565);
3685
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003687 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003688
Bruce Allan62bc8132012-03-20 03:47:57 +00003689 reg = er32(KABGTXD);
3690 reg |= E1000_KABGTXD_BGSQLBIAS;
3691 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003692
Bruce Allan5015e532012-02-08 02:55:56 +00003693 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003694}
3695
3696/**
3697 * e1000_init_hw_ich8lan - Initialize the hardware
3698 * @hw: pointer to the HW structure
3699 *
3700 * Prepares the hardware for transmit and receive by doing the following:
3701 * - initialize hardware bits
3702 * - initialize LED identification
3703 * - setup receive address registers
3704 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003705 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003706 * - clear statistics
3707 **/
3708static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3709{
3710 struct e1000_mac_info *mac = &hw->mac;
3711 u32 ctrl_ext, txdctl, snoop;
3712 s32 ret_val;
3713 u16 i;
3714
3715 e1000_initialize_hw_bits_ich8lan(hw);
3716
3717 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003718 ret_val = mac->ops.id_led_init(hw);
Bruce Allan33550ce2013-02-20 04:06:16 +00003719 /* An error is not fatal and we should not stop init due to this */
Bruce Allande39b752009-11-20 23:27:59 +00003720 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003721 e_dbg("Error initializing identification LED\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003722
3723 /* Setup the receive address. */
3724 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3725
3726 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003727 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003728 for (i = 0; i < mac->mta_reg_count; i++)
3729 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3730
Bruce Allane921eb12012-11-28 09:28:37 +00003731 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003732 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003733 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3734 */
3735 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003736 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3737 i &= ~BM_WUC_HOST_WU_BIT;
3738 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003739 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3740 if (ret_val)
3741 return ret_val;
3742 }
3743
Auke Kokbc7f75f2007-09-17 12:30:59 -07003744 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003745 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003746
3747 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003748 txdctl = er32(TXDCTL(0));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003749 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3750 E1000_TXDCTL_FULL_TX_DESC_WB);
3751 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3752 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003753 ew32(TXDCTL(0), txdctl);
3754 txdctl = er32(TXDCTL(1));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003755 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3756 E1000_TXDCTL_FULL_TX_DESC_WB);
3757 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3758 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003759 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003760
Bruce Allane921eb12012-11-28 09:28:37 +00003761 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003762 * By default, we should use snoop behavior.
3763 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003764 if (mac->type == e1000_ich8lan)
3765 snoop = PCIE_ICH8_SNOOP_ALL;
3766 else
Bruce Allan53aa82d2013-02-20 04:06:06 +00003767 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003768 e1000e_set_pcie_no_snoop(hw, snoop);
3769
3770 ctrl_ext = er32(CTRL_EXT);
3771 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3772 ew32(CTRL_EXT, ctrl_ext);
3773
Bruce Allane921eb12012-11-28 09:28:37 +00003774 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003775 * important that we do this after we have tried to establish link
3776 * because the symbol error count will increment wildly if there
3777 * is no link.
3778 */
3779 e1000_clear_hw_cntrs_ich8lan(hw);
3780
Bruce Allane561a702012-02-08 02:55:46 +00003781 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003782}
Bruce Allanfc830b72013-02-20 04:06:11 +00003783
Auke Kokbc7f75f2007-09-17 12:30:59 -07003784/**
3785 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3786 * @hw: pointer to the HW structure
3787 *
3788 * Sets/Clears required hardware bits necessary for correctly setting up the
3789 * hardware for transmit and receive.
3790 **/
3791static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3792{
3793 u32 reg;
3794
3795 /* Extended Device Control */
3796 reg = er32(CTRL_EXT);
3797 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003798 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3799 if (hw->mac.type >= e1000_pchlan)
3800 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003801 ew32(CTRL_EXT, reg);
3802
3803 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003804 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003805 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003806 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003807
3808 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003809 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003810 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003811 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003812
3813 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003814 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003815 if (hw->mac.type == e1000_ich8lan)
3816 reg |= (1 << 28) | (1 << 29);
3817 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003818 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003819
3820 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003821 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003822 if (er32(TCTL) & E1000_TCTL_MULR)
3823 reg &= ~(1 << 28);
3824 else
3825 reg |= (1 << 28);
3826 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003827 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003828
3829 /* Device Status */
3830 if (hw->mac.type == e1000_ich8lan) {
3831 reg = er32(STATUS);
3832 reg &= ~(1 << 31);
3833 ew32(STATUS, reg);
3834 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003835
Bruce Allane921eb12012-11-28 09:28:37 +00003836 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003837 * traffic, just disable the nfs filtering capability
3838 */
3839 reg = er32(RFCTL);
3840 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003841
Bruce Allane921eb12012-11-28 09:28:37 +00003842 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003843 * IPv6 headers can hang the Rx.
3844 */
3845 if (hw->mac.type == e1000_ich8lan)
3846 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003847 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00003848
3849 /* Enable ECC on Lynxpoint */
3850 if (hw->mac.type == e1000_pch_lpt) {
3851 reg = er32(PBECCSTS);
3852 reg |= E1000_PBECCSTS_ECC_ENABLE;
3853 ew32(PBECCSTS, reg);
3854
3855 reg = er32(CTRL);
3856 reg |= E1000_CTRL_MEHE;
3857 ew32(CTRL, reg);
3858 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003859}
3860
3861/**
3862 * e1000_setup_link_ich8lan - Setup flow control and link settings
3863 * @hw: pointer to the HW structure
3864 *
3865 * Determines which flow control settings to use, then configures flow
3866 * control. Calls the appropriate media-specific link configuration
3867 * function. Assuming the adapter has a valid link partner, a valid link
3868 * should be established. Assumes the hardware has previously been reset
3869 * and the transmitter and receiver are not enabled.
3870 **/
3871static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3872{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003873 s32 ret_val;
3874
Bruce Allan44abd5c2012-02-22 09:02:37 +00003875 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003876 return 0;
3877
Bruce Allane921eb12012-11-28 09:28:37 +00003878 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003879 * the default flow control setting, so we explicitly
3880 * set it to full.
3881 */
Bruce Allan37289d92009-06-02 11:29:37 +00003882 if (hw->fc.requested_mode == e1000_fc_default) {
3883 /* Workaround h/w hang when Tx flow control enabled */
3884 if (hw->mac.type == e1000_pchlan)
3885 hw->fc.requested_mode = e1000_fc_rx_pause;
3886 else
3887 hw->fc.requested_mode = e1000_fc_full;
3888 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003889
Bruce Allane921eb12012-11-28 09:28:37 +00003890 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003891 * on the link partner's capabilities, we may or may not use this mode.
3892 */
3893 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003894
Bruce Allan17e813e2013-02-20 04:06:01 +00003895 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003896
3897 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003898 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003899 if (ret_val)
3900 return ret_val;
3901
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003902 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003903 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003904 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003905 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003906 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003907 ew32(FCRTV_PCH, hw->fc.refresh_time);
3908
Bruce Allan482fed82011-01-06 14:29:49 +00003909 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3910 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003911 if (ret_val)
3912 return ret_val;
3913 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914
3915 return e1000e_set_fc_watermarks(hw);
3916}
3917
3918/**
3919 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3920 * @hw: pointer to the HW structure
3921 *
3922 * Configures the kumeran interface to the PHY to wait the appropriate time
3923 * when polling the PHY, then call the generic setup_copper_link to finish
3924 * configuring the copper link.
3925 **/
3926static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3927{
3928 u32 ctrl;
3929 s32 ret_val;
3930 u16 reg_data;
3931
3932 ctrl = er32(CTRL);
3933 ctrl |= E1000_CTRL_SLU;
3934 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3935 ew32(CTRL, ctrl);
3936
Bruce Allane921eb12012-11-28 09:28:37 +00003937 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003938 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003939 * this fixes erroneous timeouts at 10Mbps.
3940 */
Bruce Allan07818952009-12-08 07:28:01 +00003941 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003942 if (ret_val)
3943 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003944 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003945 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003946 if (ret_val)
3947 return ret_val;
3948 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003949 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003950 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003951 if (ret_val)
3952 return ret_val;
3953
Bruce Allana4f58f52009-06-02 11:29:18 +00003954 switch (hw->phy.type) {
3955 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003956 ret_val = e1000e_copper_link_setup_igp(hw);
3957 if (ret_val)
3958 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003959 break;
3960 case e1000_phy_bm:
3961 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003962 ret_val = e1000e_copper_link_setup_m88(hw);
3963 if (ret_val)
3964 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003965 break;
3966 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003967 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00003968 ret_val = e1000_copper_link_setup_82577(hw);
3969 if (ret_val)
3970 return ret_val;
3971 break;
3972 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003973 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003974 if (ret_val)
3975 return ret_val;
3976
3977 reg_data &= ~IFE_PMC_AUTO_MDIX;
3978
3979 switch (hw->phy.mdix) {
3980 case 1:
3981 reg_data &= ~IFE_PMC_FORCE_MDIX;
3982 break;
3983 case 2:
3984 reg_data |= IFE_PMC_FORCE_MDIX;
3985 break;
3986 case 0:
3987 default:
3988 reg_data |= IFE_PMC_AUTO_MDIX;
3989 break;
3990 }
Bruce Allan482fed82011-01-06 14:29:49 +00003991 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003992 if (ret_val)
3993 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003994 break;
3995 default:
3996 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003997 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003998
Auke Kokbc7f75f2007-09-17 12:30:59 -07003999 return e1000e_setup_copper_link(hw);
4000}
4001
4002/**
Bruce Allanea8179a2013-03-06 09:02:47 +00004003 * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
4004 * @hw: pointer to the HW structure
4005 *
4006 * Calls the PHY specific link setup function and then calls the
4007 * generic setup_copper_link to finish configuring the link for
4008 * Lynxpoint PCH devices
4009 **/
4010static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
4011{
4012 u32 ctrl;
4013 s32 ret_val;
4014
4015 ctrl = er32(CTRL);
4016 ctrl |= E1000_CTRL_SLU;
4017 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
4018 ew32(CTRL, ctrl);
4019
4020 ret_val = e1000_copper_link_setup_82577(hw);
4021 if (ret_val)
4022 return ret_val;
4023
4024 return e1000e_setup_copper_link(hw);
4025}
4026
4027/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004028 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
4029 * @hw: pointer to the HW structure
4030 * @speed: pointer to store current link speed
4031 * @duplex: pointer to store the current link duplex
4032 *
Bruce Allanad680762008-03-28 09:15:03 -07004033 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07004034 * information and then calls the Kumeran lock loss workaround for links at
4035 * gigabit speeds.
4036 **/
4037static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
4038 u16 *duplex)
4039{
4040 s32 ret_val;
4041
4042 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
4043 if (ret_val)
4044 return ret_val;
4045
4046 if ((hw->mac.type == e1000_ich8lan) &&
Bruce Allane5fe2542013-02-20 04:06:27 +00004047 (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004048 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
4049 }
4050
4051 return ret_val;
4052}
4053
4054/**
4055 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
4056 * @hw: pointer to the HW structure
4057 *
4058 * Work-around for 82566 Kumeran PCS lock loss:
4059 * On link status change (i.e. PCI reset, speed change) and link is up and
4060 * speed is gigabit-
4061 * 0) if workaround is optionally disabled do nothing
4062 * 1) wait 1ms for Kumeran link to come up
4063 * 2) check Kumeran Diagnostic register PCS lock loss bit
4064 * 3) if not set the link is locked (all is good), otherwise...
4065 * 4) reset the PHY
4066 * 5) repeat up to 10 times
4067 * Note: this is only called for IGP3 copper when speed is 1gb.
4068 **/
4069static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
4070{
4071 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4072 u32 phy_ctrl;
4073 s32 ret_val;
4074 u16 i, data;
4075 bool link;
4076
4077 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
4078 return 0;
4079
Bruce Allane921eb12012-11-28 09:28:37 +00004080 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004081 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07004082 * stability
4083 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004084 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
4085 if (!link)
4086 return 0;
4087
4088 for (i = 0; i < 10; i++) {
4089 /* read once to clear */
4090 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4091 if (ret_val)
4092 return ret_val;
4093 /* and again to get new status */
4094 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4095 if (ret_val)
4096 return ret_val;
4097
4098 /* check for PCS lock */
4099 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4100 return 0;
4101
4102 /* Issue PHY reset */
4103 e1000_phy_hw_reset(hw);
4104 mdelay(5);
4105 }
4106 /* Disable GigE link negotiation */
4107 phy_ctrl = er32(PHY_CTRL);
4108 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
4109 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4110 ew32(PHY_CTRL, phy_ctrl);
4111
Bruce Allane921eb12012-11-28 09:28:37 +00004112 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07004113 * any PHY registers
4114 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004115 e1000e_gig_downshift_workaround_ich8lan(hw);
4116
4117 /* unable to acquire PCS lock */
4118 return -E1000_ERR_PHY;
4119}
4120
4121/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00004122 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004123 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08004124 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004125 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00004126 * If ICH8, set the current Kumeran workaround state (enabled - true
4127 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07004128 **/
4129void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004130 bool state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004131{
4132 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4133
4134 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004135 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004136 return;
4137 }
4138
4139 dev_spec->kmrn_lock_loss_workaround_enabled = state;
4140}
4141
4142/**
4143 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
4144 * @hw: pointer to the HW structure
4145 *
4146 * Workaround for 82566 power-down on D3 entry:
4147 * 1) disable gigabit link
4148 * 2) write VR power-down enable
4149 * 3) read it back
4150 * Continue if successful, else issue LCD reset and repeat
4151 **/
4152void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
4153{
4154 u32 reg;
4155 u16 data;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004156 u8 retry = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004157
4158 if (hw->phy.type != e1000_phy_igp_3)
4159 return;
4160
4161 /* Try the workaround twice (if needed) */
4162 do {
4163 /* Disable link */
4164 reg = er32(PHY_CTRL);
4165 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4166 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4167 ew32(PHY_CTRL, reg);
4168
Bruce Allane921eb12012-11-28 09:28:37 +00004169 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07004170 * accessing any PHY registers
4171 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004172 if (hw->mac.type == e1000_ich8lan)
4173 e1000e_gig_downshift_workaround_ich8lan(hw);
4174
4175 /* Write VR power-down enable */
4176 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4177 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4178 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4179
4180 /* Read it back and test */
4181 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4182 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4183 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4184 break;
4185
4186 /* Issue PHY reset and repeat at most one more time */
4187 reg = er32(CTRL);
4188 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4189 retry++;
4190 } while (retry);
4191}
4192
4193/**
4194 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4195 * @hw: pointer to the HW structure
4196 *
4197 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004198 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004199 * 1) Set Kumeran Near-end loopback
4200 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004201 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004202 **/
4203void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4204{
4205 s32 ret_val;
4206 u16 reg_data;
4207
Bruce Allan462d5992011-09-30 08:07:11 +00004208 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004209 return;
4210
4211 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004212 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004213 if (ret_val)
4214 return;
4215 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4216 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004217 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004218 if (ret_val)
4219 return;
4220 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00004221 e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222}
4223
4224/**
Bruce Allan99730e42011-05-13 07:19:48 +00004225 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004226 * @hw: pointer to the HW structure
4227 *
4228 * During S0 to Sx transition, it is possible the link remains at gig
4229 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004230 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4231 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4232 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4233 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004234 * Parts that support (and are linked to a partner which support) EEE in
4235 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4236 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004237 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004238void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004239{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004240 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004241 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004242 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004243
Bruce Allan17f085d2010-06-17 18:59:48 +00004244 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004245 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allane08f6262013-02-20 03:06:34 +00004246
Bruce Allan2fbe4522012-04-19 03:21:47 +00004247 if (hw->phy.type == e1000_phy_i217) {
Bruce Allane08f6262013-02-20 03:06:34 +00004248 u16 phy_reg, device_id = hw->adapter->pdev->device;
4249
4250 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
Bruce Allan91a3d822013-06-29 01:15:16 +00004251 (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
4252 (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
4253 (device_id == E1000_DEV_ID_PCH_I218_V3)) {
Bruce Allane08f6262013-02-20 03:06:34 +00004254 u32 fextnvm6 = er32(FEXTNVM6);
4255
4256 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
4257 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004258
4259 ret_val = hw->phy.ops.acquire(hw);
4260 if (ret_val)
4261 goto out;
4262
4263 if (!dev_spec->eee_disable) {
4264 u16 eee_advert;
4265
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004266 ret_val =
4267 e1000_read_emi_reg_locked(hw,
4268 I217_EEE_ADVERTISEMENT,
4269 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004270 if (ret_val)
4271 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004272
Bruce Allane921eb12012-11-28 09:28:37 +00004273 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004274 * EEE and 100Full is advertised on both ends of the
4275 * link.
4276 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004277 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004278 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004279 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004280 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4281 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4282 E1000_PHY_CTRL_NOND0A_LPLU);
4283 }
4284
Bruce Allane921eb12012-11-28 09:28:37 +00004285 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004286 * when the system is going into Sx and no manageability engine
4287 * is present, the driver must configure proxy to reset only on
4288 * power good. LPI (Low Power Idle) state must also reset only
4289 * on power good, as well as the MTA (Multicast table array).
4290 * The SMBus release must also be disabled on LCD reset.
4291 */
4292 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00004293 /* Enable proxy to reset only on power good. */
4294 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4295 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4296 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4297
Bruce Allane921eb12012-11-28 09:28:37 +00004298 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004299 * power good.
4300 */
4301 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004302 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004303 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4304
4305 /* Disable the SMB release on LCD reset. */
4306 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004307 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004308 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4309 }
4310
Bruce Allane921eb12012-11-28 09:28:37 +00004311 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004312 * Support
4313 */
4314 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004315 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004316 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4317
4318release:
4319 hw->phy.ops.release(hw);
4320 }
4321out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004322 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004323
Bruce Allan462d5992011-09-30 08:07:11 +00004324 if (hw->mac.type == e1000_ich8lan)
4325 e1000e_gig_downshift_workaround_ich8lan(hw);
4326
Bruce Allan8395ae82010-09-22 17:15:08 +00004327 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004328 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004329
4330 /* Reset PHY to activate OEM bits on 82577/8 */
4331 if (hw->mac.type == e1000_pchlan)
4332 e1000e_phy_hw_reset_generic(hw);
4333
Bruce Allan8395ae82010-09-22 17:15:08 +00004334 ret_val = hw->phy.ops.acquire(hw);
4335 if (ret_val)
4336 return;
4337 e1000_write_smbus_addr(hw);
4338 hw->phy.ops.release(hw);
4339 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004340}
4341
4342/**
Bruce Allan99730e42011-05-13 07:19:48 +00004343 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4344 * @hw: pointer to the HW structure
4345 *
4346 * During Sx to S0 transitions on non-managed devices or managed devices
4347 * on which PHY resets are not blocked, if the PHY registers cannot be
4348 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4349 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004350 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004351 **/
4352void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4353{
Bruce Allan90b82982011-12-16 00:46:33 +00004354 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004355
Bruce Allancb17aab2012-04-13 03:16:22 +00004356 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004357 return;
4358
Bruce Allancb17aab2012-04-13 03:16:22 +00004359 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004360 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004361 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004362 return;
4363 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004364
Bruce Allane921eb12012-11-28 09:28:37 +00004365 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004366 * is transitioning from Sx and no manageability engine is present
4367 * configure SMBus to restore on reset, disable proxy, and enable
4368 * the reset on MTA (Multicast table array).
4369 */
4370 if (hw->phy.type == e1000_phy_i217) {
4371 u16 phy_reg;
4372
4373 ret_val = hw->phy.ops.acquire(hw);
4374 if (ret_val) {
4375 e_dbg("Failed to setup iRST\n");
4376 return;
4377 }
4378
4379 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004380 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004381 * is present
4382 */
4383 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4384 if (ret_val)
4385 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004386 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004387 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4388
4389 /* Disable Proxy */
4390 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4391 }
4392 /* Enable reset on MTA */
4393 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4394 if (ret_val)
4395 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004396 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004397 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4398release:
4399 if (ret_val)
4400 e_dbg("Error %d in resume workarounds\n", ret_val);
4401 hw->phy.ops.release(hw);
4402 }
Bruce Allan99730e42011-05-13 07:19:48 +00004403}
4404
4405/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004406 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4407 * @hw: pointer to the HW structure
4408 *
4409 * Return the LED back to the default configuration.
4410 **/
4411static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4412{
4413 if (hw->phy.type == e1000_phy_ife)
4414 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4415
4416 ew32(LEDCTL, hw->mac.ledctl_default);
4417 return 0;
4418}
4419
4420/**
Auke Kok489815c2008-02-21 15:11:07 -08004421 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004422 * @hw: pointer to the HW structure
4423 *
Auke Kok489815c2008-02-21 15:11:07 -08004424 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004425 **/
4426static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4427{
4428 if (hw->phy.type == e1000_phy_ife)
4429 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4430 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4431
4432 ew32(LEDCTL, hw->mac.ledctl_mode2);
4433 return 0;
4434}
4435
4436/**
Auke Kok489815c2008-02-21 15:11:07 -08004437 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004438 * @hw: pointer to the HW structure
4439 *
Auke Kok489815c2008-02-21 15:11:07 -08004440 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004441 **/
4442static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4443{
4444 if (hw->phy.type == e1000_phy_ife)
4445 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004446 (IFE_PSCL_PROBE_MODE |
4447 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004448
4449 ew32(LEDCTL, hw->mac.ledctl_mode1);
4450 return 0;
4451}
4452
4453/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004454 * e1000_setup_led_pchlan - Configures SW controllable LED
4455 * @hw: pointer to the HW structure
4456 *
4457 * This prepares the SW controllable LED for use.
4458 **/
4459static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4460{
Bruce Allan482fed82011-01-06 14:29:49 +00004461 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004462}
4463
4464/**
4465 * e1000_cleanup_led_pchlan - Restore the default LED operation
4466 * @hw: pointer to the HW structure
4467 *
4468 * Return the LED back to the default configuration.
4469 **/
4470static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4471{
Bruce Allan482fed82011-01-06 14:29:49 +00004472 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004473}
4474
4475/**
4476 * e1000_led_on_pchlan - Turn LEDs on
4477 * @hw: pointer to the HW structure
4478 *
4479 * Turn on the LEDs.
4480 **/
4481static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4482{
4483 u16 data = (u16)hw->mac.ledctl_mode2;
4484 u32 i, led;
4485
Bruce Allane921eb12012-11-28 09:28:37 +00004486 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004487 * for each LED that's mode is "link_up" in ledctl_mode2.
4488 */
4489 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4490 for (i = 0; i < 3; i++) {
4491 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4492 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4493 E1000_LEDCTL_MODE_LINK_UP)
4494 continue;
4495 if (led & E1000_PHY_LED0_IVRT)
4496 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4497 else
4498 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4499 }
4500 }
4501
Bruce Allan482fed82011-01-06 14:29:49 +00004502 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004503}
4504
4505/**
4506 * e1000_led_off_pchlan - Turn LEDs off
4507 * @hw: pointer to the HW structure
4508 *
4509 * Turn off the LEDs.
4510 **/
4511static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4512{
4513 u16 data = (u16)hw->mac.ledctl_mode1;
4514 u32 i, led;
4515
Bruce Allane921eb12012-11-28 09:28:37 +00004516 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004517 * for each LED that's mode is "link_up" in ledctl_mode1.
4518 */
4519 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4520 for (i = 0; i < 3; i++) {
4521 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4522 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4523 E1000_LEDCTL_MODE_LINK_UP)
4524 continue;
4525 if (led & E1000_PHY_LED0_IVRT)
4526 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4527 else
4528 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4529 }
4530 }
4531
Bruce Allan482fed82011-01-06 14:29:49 +00004532 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004533}
4534
4535/**
Bruce Allane98cac42010-05-10 15:02:32 +00004536 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004537 * @hw: pointer to the HW structure
4538 *
Bruce Allane98cac42010-05-10 15:02:32 +00004539 * Read appropriate register for the config done bit for completion status
4540 * and configure the PHY through s/w for EEPROM-less parts.
4541 *
4542 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4543 * config done bit, so only an error is logged and continues. If we were
4544 * to return with error, EEPROM-less silicon would not be able to be reset
4545 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004546 **/
4547static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4548{
Bruce Allane98cac42010-05-10 15:02:32 +00004549 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004550 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004551 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004552
Bruce Allanfe908492013-01-05 08:06:14 +00004553 e1000e_get_cfg_done_generic(hw);
Bruce Allanf4187b52008-08-26 18:36:50 -07004554
Bruce Allane98cac42010-05-10 15:02:32 +00004555 /* Wait for indication from h/w that it has completed basic config */
4556 if (hw->mac.type >= e1000_ich10lan) {
4557 e1000_lan_init_done_ich8lan(hw);
4558 } else {
4559 ret_val = e1000e_get_auto_rd_done(hw);
4560 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004561 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004562 * return with an error. This can happen in situations
4563 * where there is no eeprom and prevents getting link.
4564 */
4565 e_dbg("Auto Read Done did not complete\n");
4566 ret_val = 0;
4567 }
4568 }
4569
4570 /* Clear PHY Reset Asserted bit */
4571 status = er32(STATUS);
4572 if (status & E1000_STATUS_PHYRA)
4573 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4574 else
4575 e_dbg("PHY Reset Asserted not set - needs delay\n");
4576
Bruce Allanf4187b52008-08-26 18:36:50 -07004577 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004578 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004579 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004580 (hw->phy.type == e1000_phy_igp_3)) {
4581 e1000e_phy_init_script_igp3(hw);
4582 }
4583 } else {
4584 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4585 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004586 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004587 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004588 }
4589 }
4590
Bruce Allane98cac42010-05-10 15:02:32 +00004591 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004592}
4593
4594/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004595 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4596 * @hw: pointer to the HW structure
4597 *
4598 * In the case of a PHY power down to save power, or to turn off link during a
4599 * driver unload, or wake on lan is not enabled, remove the link.
4600 **/
4601static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4602{
4603 /* If the management interface is not enabled, then power down */
4604 if (!(hw->mac.ops.check_mng_mode(hw) ||
4605 hw->phy.ops.check_reset_block(hw)))
4606 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004607}
4608
4609/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004610 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4611 * @hw: pointer to the HW structure
4612 *
4613 * Clears hardware counters specific to the silicon family and calls
4614 * clear_hw_cntrs_generic to clear all general purpose counters.
4615 **/
4616static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4617{
Bruce Allana4f58f52009-06-02 11:29:18 +00004618 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004619 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004620
4621 e1000e_clear_hw_cntrs_base(hw);
4622
Bruce Allan99673d92009-11-20 23:27:21 +00004623 er32(ALGNERRC);
4624 er32(RXERRC);
4625 er32(TNCRS);
4626 er32(CEXTERR);
4627 er32(TSCTC);
4628 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004629
Bruce Allan99673d92009-11-20 23:27:21 +00004630 er32(MGTPRC);
4631 er32(MGTPDC);
4632 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004633
Bruce Allan99673d92009-11-20 23:27:21 +00004634 er32(IAC);
4635 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004636
Bruce Allana4f58f52009-06-02 11:29:18 +00004637 /* Clear PHY statistics registers */
4638 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004639 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004640 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004641 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004642 ret_val = hw->phy.ops.acquire(hw);
4643 if (ret_val)
4644 return;
4645 ret_val = hw->phy.ops.set_page(hw,
4646 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4647 if (ret_val)
4648 goto release;
4649 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4650 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4651 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4652 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4653 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4654 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4655 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4656 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4657 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4658 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4659 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4660 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4661 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4662 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4663release:
4664 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004665 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004666}
4667
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004668static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004669 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004670 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004671 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004672 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4673 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004674 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004675 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004676 /* led_on dependent on mac type */
4677 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004678 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004679 .reset_hw = e1000_reset_hw_ich8lan,
4680 .init_hw = e1000_init_hw_ich8lan,
4681 .setup_link = e1000_setup_link_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004682 .setup_physical_interface = e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004683 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004684 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004685 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004686};
4687
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004688static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004689 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004690 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004691 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004692 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004693 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004694 .read_reg = e1000e_read_phy_reg_igp,
4695 .release = e1000_release_swflag_ich8lan,
4696 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004697 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4698 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004699 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004700};
4701
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004702static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004703 .acquire = e1000_acquire_nvm_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004704 .read = e1000_read_nvm_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004705 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004706 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004707 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004708 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004709 .validate = e1000_validate_nvm_checksum_ich8lan,
4710 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004711};
4712
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004713const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004714 .mac = e1000_ich8lan,
4715 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004716 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004717 | FLAG_HAS_CTRLEXT_ON_LOAD
4718 | FLAG_HAS_AMT
4719 | FLAG_HAS_FLASH
4720 | FLAG_APME_IN_WUC,
4721 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004722 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004723 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004724 .mac_ops = &ich8_mac_ops,
4725 .phy_ops = &ich8_phy_ops,
4726 .nvm_ops = &ich8_nvm_ops,
4727};
4728
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004729const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004730 .mac = e1000_ich9lan,
4731 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004732 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004733 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004734 | FLAG_HAS_CTRLEXT_ON_LOAD
4735 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004736 | FLAG_HAS_FLASH
4737 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004738 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004739 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004740 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004741 .mac_ops = &ich8_mac_ops,
4742 .phy_ops = &ich8_phy_ops,
4743 .nvm_ops = &ich8_nvm_ops,
4744};
4745
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004746const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004747 .mac = e1000_ich10lan,
4748 .flags = FLAG_HAS_JUMBO_FRAMES
4749 | FLAG_IS_ICH
4750 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004751 | FLAG_HAS_CTRLEXT_ON_LOAD
4752 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004753 | FLAG_HAS_FLASH
4754 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004755 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004756 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004757 .get_variants = e1000_get_variants_ich8lan,
4758 .mac_ops = &ich8_mac_ops,
4759 .phy_ops = &ich8_phy_ops,
4760 .nvm_ops = &ich8_nvm_ops,
4761};
Bruce Allana4f58f52009-06-02 11:29:18 +00004762
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004763const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004764 .mac = e1000_pchlan,
4765 .flags = FLAG_IS_ICH
4766 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004767 | FLAG_HAS_CTRLEXT_ON_LOAD
4768 | FLAG_HAS_AMT
4769 | FLAG_HAS_FLASH
4770 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004771 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004772 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004773 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004774 .pba = 26,
4775 .max_hw_frame_size = 4096,
4776 .get_variants = e1000_get_variants_ich8lan,
4777 .mac_ops = &ich8_mac_ops,
4778 .phy_ops = &ich8_phy_ops,
4779 .nvm_ops = &ich8_nvm_ops,
4780};
Bruce Alland3738bb2010-06-16 13:27:28 +00004781
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004782const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004783 .mac = e1000_pch2lan,
4784 .flags = FLAG_IS_ICH
4785 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004786 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00004787 | FLAG_HAS_CTRLEXT_ON_LOAD
4788 | FLAG_HAS_AMT
4789 | FLAG_HAS_FLASH
4790 | FLAG_HAS_JUMBO_FRAMES
4791 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004792 .flags2 = FLAG2_HAS_PHY_STATS
4793 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004794 .pba = 26,
Bruce Allanc3d2dbf2013-01-09 01:20:46 +00004795 .max_hw_frame_size = 9018,
Bruce Alland3738bb2010-06-16 13:27:28 +00004796 .get_variants = e1000_get_variants_ich8lan,
4797 .mac_ops = &ich8_mac_ops,
4798 .phy_ops = &ich8_phy_ops,
4799 .nvm_ops = &ich8_nvm_ops,
4800};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004801
4802const struct e1000_info e1000_pch_lpt_info = {
4803 .mac = e1000_pch_lpt,
4804 .flags = FLAG_IS_ICH
4805 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004806 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00004807 | FLAG_HAS_CTRLEXT_ON_LOAD
4808 | FLAG_HAS_AMT
4809 | FLAG_HAS_FLASH
4810 | FLAG_HAS_JUMBO_FRAMES
4811 | FLAG_APME_IN_WUC,
4812 .flags2 = FLAG2_HAS_PHY_STATS
4813 | FLAG2_HAS_EEE,
4814 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00004815 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004816 .get_variants = e1000_get_variants_ich8lan,
4817 .mac_ops = &ich8_mac_ops,
4818 .phy_ops = &ich8_phy_ops,
4819 .nvm_ops = &ich8_nvm_ops,
4820};