blob: 4f3da87f0cef1c90ef32ba0df769723bfcdd425f [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allane921eb12012-11-28 09:28:37 +000029/* 82562G 10/100 Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070030 * 82562G-2 10/100 Network Connection
31 * 82562GT 10/100 Network Connection
32 * 82562GT-2 10/100 Network Connection
33 * 82562V 10/100 Network Connection
34 * 82562V-2 10/100 Network Connection
35 * 82566DC-2 Gigabit Network Connection
36 * 82566DC Gigabit Network Connection
37 * 82566DM-2 Gigabit Network Connection
38 * 82566DM Gigabit Network Connection
39 * 82566MC Gigabit Network Connection
40 * 82566MM Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070041 * 82567LM Gigabit Network Connection
42 * 82567LF Gigabit Network Connection
Bruce Allan16059272008-11-21 16:51:06 -080043 * 82567V Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070044 * 82567LM-2 Gigabit Network Connection
45 * 82567LF-2 Gigabit Network Connection
46 * 82567V-2 Gigabit Network Connection
Bruce Allanf4187b52008-08-26 18:36:50 -070047 * 82567LF-3 Gigabit Network Connection
48 * 82567LM-3 Gigabit Network Connection
Bruce Allan2f15f9d2008-08-26 18:36:36 -070049 * 82567LM-4 Gigabit Network Connection
Bruce Allana4f58f52009-06-02 11:29:18 +000050 * 82577LM Gigabit Network Connection
51 * 82577LC Gigabit Network Connection
52 * 82578DM Gigabit Network Connection
53 * 82578DC Gigabit Network Connection
Bruce Alland3738bb2010-06-16 13:27:28 +000054 * 82579LM Gigabit Network Connection
55 * 82579V Gigabit Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070056 */
57
Auke Kokbc7f75f2007-09-17 12:30:59 -070058#include "e1000.h"
59
Auke Kokbc7f75f2007-09-17 12:30:59 -070060/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
61/* Offset 04h HSFSTS */
62union ich8_hws_flash_status {
63 struct ich8_hsfsts {
Bruce Allan362e20c2013-02-20 04:05:45 +000064 u16 flcdone:1; /* bit 0 Flash Cycle Done */
65 u16 flcerr:1; /* bit 1 Flash Cycle Error */
66 u16 dael:1; /* bit 2 Direct Access error Log */
67 u16 berasesz:2; /* bit 4:3 Sector Erase Size */
68 u16 flcinprog:1; /* bit 5 flash cycle in Progress */
69 u16 reserved1:2; /* bit 13:6 Reserved */
70 u16 reserved2:6; /* bit 13:6 Reserved */
71 u16 fldesvalid:1; /* bit 14 Flash Descriptor Valid */
72 u16 flockdn:1; /* bit 15 Flash Config Lock-Down */
Auke Kokbc7f75f2007-09-17 12:30:59 -070073 } hsf_status;
74 u16 regval;
75};
76
77/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
78/* Offset 06h FLCTL */
79union ich8_hws_flash_ctrl {
80 struct ich8_hsflctl {
Bruce Allan362e20c2013-02-20 04:05:45 +000081 u16 flcgo:1; /* 0 Flash Cycle Go */
82 u16 flcycle:2; /* 2:1 Flash Cycle */
83 u16 reserved:5; /* 7:3 Reserved */
84 u16 fldbcount:2; /* 9:8 Flash Data Byte Count */
85 u16 flockdn:6; /* 15:10 Reserved */
Auke Kokbc7f75f2007-09-17 12:30:59 -070086 } hsf_ctrl;
87 u16 regval;
88};
89
90/* ICH Flash Region Access Permissions */
91union ich8_hws_flash_regacc {
92 struct ich8_flracc {
Bruce Allan362e20c2013-02-20 04:05:45 +000093 u32 grra:8; /* 0:7 GbE region Read Access */
94 u32 grwa:8; /* 8:15 GbE region Write Access */
95 u32 gmrag:8; /* 23:16 GbE Master Read Access Grant */
96 u32 gmwag:8; /* 31:24 GbE Master Write Access Grant */
Auke Kokbc7f75f2007-09-17 12:30:59 -070097 } hsf_flregacc;
98 u16 regval;
99};
100
Bruce Allan4a770352008-10-01 17:18:35 -0700101/* ICH Flash Protected Region */
102union ich8_flash_protected_range {
103 struct ich8_pr {
Bruce Allane80bd1d2013-05-01 01:19:46 +0000104 u32 base:13; /* 0:12 Protected Range Base */
105 u32 reserved1:2; /* 13:14 Reserved */
106 u32 rpe:1; /* 15 Read Protection Enable */
107 u32 limit:13; /* 16:28 Protected Range Limit */
108 u32 reserved2:2; /* 29:30 Reserved */
109 u32 wpe:1; /* 31 Write Protection Enable */
Bruce Allan4a770352008-10-01 17:18:35 -0700110 } range;
111 u32 regval;
112};
113
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
115static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700116static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
117static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
118 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700119static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
120 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700121static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
122 u16 *data);
123static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
124 u8 size, u16 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700125static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000126static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
127static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
128static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
129static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
130static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
131static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
132static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
133static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000134static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000135static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000136static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1f96012d2013-01-05 03:06:54 +0000137static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000138static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000139static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
140static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan69e1e012012-04-14 03:28:50 +0000141static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000142static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000143static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000144static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
Bruce Allanea8179a2013-03-06 09:02:47 +0000145static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700146
147static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
148{
149 return readw(hw->flash_address + reg);
150}
151
152static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
153{
154 return readl(hw->flash_address + reg);
155}
156
157static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
158{
159 writew(val, hw->flash_address + reg);
160}
161
162static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
163{
164 writel(val, hw->flash_address + reg);
165}
166
167#define er16flash(reg) __er16flash(hw, (reg))
168#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000169#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
170#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700171
Bruce Allancb17aab2012-04-13 03:16:22 +0000172/**
173 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
174 * @hw: pointer to the HW structure
175 *
176 * Test access to the PHY registers by reading the PHY ID registers. If
177 * the PHY ID is already known (e.g. resume path) compare it with known ID,
178 * otherwise assume the read PHY ID is correct if it is valid.
179 *
180 * Assumes the sw/fw/hw semaphore is already acquired.
181 **/
182static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000183{
Bruce Allana52359b2012-07-14 04:23:58 +0000184 u16 phy_reg = 0;
185 u32 phy_id = 0;
186 s32 ret_val;
187 u16 retry_count;
Bruce Allan16b095a2013-06-29 07:42:39 +0000188 u32 mac_reg = 0;
Bruce Allan99730e42011-05-13 07:19:48 +0000189
Bruce Allana52359b2012-07-14 04:23:58 +0000190 for (retry_count = 0; retry_count < 2; retry_count++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000191 ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000192 if (ret_val || (phy_reg == 0xFFFF))
193 continue;
194 phy_id = (u32)(phy_reg << 16);
195
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000196 ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000197 if (ret_val || (phy_reg == 0xFFFF)) {
198 phy_id = 0;
199 continue;
200 }
201 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
202 break;
203 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000204
Bruce Allancb17aab2012-04-13 03:16:22 +0000205 if (hw->phy.id) {
206 if (hw->phy.id == phy_id)
Bruce Allan16b095a2013-06-29 07:42:39 +0000207 goto out;
Bruce Allana52359b2012-07-14 04:23:58 +0000208 } else if (phy_id) {
209 hw->phy.id = phy_id;
210 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allan16b095a2013-06-29 07:42:39 +0000211 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000212 }
213
Bruce Allane921eb12012-11-28 09:28:37 +0000214 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000215 * set slow mode and try to get the PHY id again.
216 */
217 hw->phy.ops.release(hw);
218 ret_val = e1000_set_mdio_slow_mode_hv(hw);
219 if (!ret_val)
220 ret_val = e1000e_get_phy_id(hw);
221 hw->phy.ops.acquire(hw);
222
Bruce Allan16b095a2013-06-29 07:42:39 +0000223 if (ret_val)
224 return false;
225out:
226 if (hw->mac.type == e1000_pch_lpt) {
227 /* Unforce SMBus mode in PHY */
228 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
229 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
230 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
231
232 /* Unforce SMBus mode in MAC */
233 mac_reg = er32(CTRL_EXT);
234 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
235 ew32(CTRL_EXT, mac_reg);
236 }
237
238 return true;
Bruce Allancb17aab2012-04-13 03:16:22 +0000239}
240
241/**
242 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
243 * @hw: pointer to the HW structure
244 *
245 * Workarounds/flow necessary for PHY initialization during driver load
246 * and resume paths.
247 **/
248static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
249{
David Ertmanf7235ef2014-01-23 06:29:13 +0000250 struct e1000_adapter *adapter = hw->adapter;
Bruce Allancb17aab2012-04-13 03:16:22 +0000251 u32 mac_reg, fwsm = er32(FWSM);
252 s32 ret_val;
253
Bruce Allan6e928b72012-12-12 04:45:51 +0000254 /* Gate automatic PHY configuration by hardware on managed and
255 * non-managed 82579 and newer adapters.
256 */
257 e1000_gate_hw_phy_config_ich8lan(hw, true);
258
Bruce Allancb17aab2012-04-13 03:16:22 +0000259 ret_val = hw->phy.ops.acquire(hw);
260 if (ret_val) {
261 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000262 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000263 }
264
Bruce Allane921eb12012-11-28 09:28:37 +0000265 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000266 * inaccessible and resetting the PHY is not blocked, toggle the
267 * LANPHYPC Value bit to force the interconnect to PCIe mode.
268 */
269 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000270 case e1000_pch_lpt:
271 if (e1000_phy_is_accessible_pchlan(hw))
272 break;
273
Bruce Allane921eb12012-11-28 09:28:37 +0000274 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000275 * forcing MAC to SMBus mode first.
276 */
277 mac_reg = er32(CTRL_EXT);
278 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
279 ew32(CTRL_EXT, mac_reg);
280
Bruce Allan16b095a2013-06-29 07:42:39 +0000281 /* Wait 50 milliseconds for MAC to finish any retries
282 * that it might be trying to perform from previous
283 * attempts to acknowledge any phy read requests.
284 */
285 msleep(50);
286
Bruce Allan2fbe4522012-04-19 03:21:47 +0000287 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000288 case e1000_pch2lan:
Bruce Allan16b095a2013-06-29 07:42:39 +0000289 if (e1000_phy_is_accessible_pchlan(hw))
Bruce Allancb17aab2012-04-13 03:16:22 +0000290 break;
291
292 /* fall-through */
293 case e1000_pchlan:
294 if ((hw->mac.type == e1000_pchlan) &&
295 (fwsm & E1000_ICH_FWSM_FW_VALID))
296 break;
297
298 if (hw->phy.ops.check_reset_block(hw)) {
299 e_dbg("Required LANPHYPC toggle blocked by ME\n");
Bruce Allan16b095a2013-06-29 07:42:39 +0000300 ret_val = -E1000_ERR_PHY;
Bruce Allancb17aab2012-04-13 03:16:22 +0000301 break;
302 }
303
304 e_dbg("Toggling LANPHYPC\n");
305
306 /* Set Phy Config Counter to 50msec */
307 mac_reg = er32(FEXTNVM3);
308 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
309 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
310 ew32(FEXTNVM3, mac_reg);
311
312 /* Toggle LANPHYPC Value bit */
313 mac_reg = er32(CTRL);
314 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
315 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
316 ew32(CTRL, mac_reg);
317 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +0000318 usleep_range(10, 20);
Bruce Allancb17aab2012-04-13 03:16:22 +0000319 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
320 ew32(CTRL, mac_reg);
321 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000322 if (hw->mac.type < e1000_pch_lpt) {
323 msleep(50);
324 } else {
325 u16 count = 20;
326 do {
327 usleep_range(5000, 10000);
328 } while (!(er32(CTRL_EXT) &
329 E1000_CTRL_EXT_LPCD) && count--);
Bruce Allan16b095a2013-06-29 07:42:39 +0000330 usleep_range(30000, 60000);
331 if (e1000_phy_is_accessible_pchlan(hw))
332 break;
333
334 /* Toggling LANPHYPC brings the PHY out of SMBus mode
335 * so ensure that the MAC is also out of SMBus mode
336 */
337 mac_reg = er32(CTRL_EXT);
338 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
339 ew32(CTRL_EXT, mac_reg);
340
341 if (e1000_phy_is_accessible_pchlan(hw))
342 break;
343
344 ret_val = -E1000_ERR_PHY;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000345 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000346 break;
347 default:
348 break;
349 }
350
351 hw->phy.ops.release(hw);
Bruce Allan16b095a2013-06-29 07:42:39 +0000352 if (!ret_val) {
David Ertmanf7235ef2014-01-23 06:29:13 +0000353
354 /* Check to see if able to reset PHY. Print error if not */
355 if (hw->phy.ops.check_reset_block(hw)) {
356 e_err("Reset blocked by ME\n");
357 goto out;
358 }
359
Bruce Allan16b095a2013-06-29 07:42:39 +0000360 /* Reset the PHY before any access to it. Doing so, ensures
361 * that the PHY is in a known good state before we read/write
362 * PHY registers. The generic reset is sufficient here,
363 * because we haven't determined the PHY type yet.
364 */
365 ret_val = e1000e_phy_hw_reset_generic(hw);
David Ertmanf7235ef2014-01-23 06:29:13 +0000366 if (ret_val)
367 goto out;
368
369 /* On a successful reset, possibly need to wait for the PHY
370 * to quiesce to an accessible state before returning control
371 * to the calling function. If the PHY does not quiesce, then
372 * return E1000E_BLK_PHY_RESET, as this is the condition that
373 * the PHY is in.
374 */
375 ret_val = hw->phy.ops.check_reset_block(hw);
376 if (ret_val)
377 e_err("ME blocked access to PHY after reset\n");
Bruce Allan16b095a2013-06-29 07:42:39 +0000378 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000379
Bruce Allan6e928b72012-12-12 04:45:51 +0000380out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000381 /* Ungate automatic PHY configuration on non-managed 82579 */
382 if ((hw->mac.type == e1000_pch2lan) &&
383 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
384 usleep_range(10000, 20000);
385 e1000_gate_hw_phy_config_ich8lan(hw, false);
386 }
387
388 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000389}
390
Auke Kokbc7f75f2007-09-17 12:30:59 -0700391/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000392 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
393 * @hw: pointer to the HW structure
394 *
395 * Initialize family-specific PHY parameters and function pointers.
396 **/
397static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
398{
399 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan70806a72013-01-05 05:08:37 +0000400 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000401
Bruce Allane80bd1d2013-05-01 01:19:46 +0000402 phy->addr = 1;
403 phy->reset_delay_us = 100;
Bruce Allana4f58f52009-06-02 11:29:18 +0000404
Bruce Allane80bd1d2013-05-01 01:19:46 +0000405 phy->ops.set_page = e1000_set_page_igp;
406 phy->ops.read_reg = e1000_read_phy_reg_hv;
407 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
408 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
409 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
410 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
411 phy->ops.write_reg = e1000_write_phy_reg_hv;
412 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
413 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
414 phy->ops.power_up = e1000_power_up_phy_copper;
415 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
416 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allana4f58f52009-06-02 11:29:18 +0000417
418 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000419
420 ret_val = e1000_init_phy_workarounds_pchlan(hw);
421 if (ret_val)
422 return ret_val;
423
424 if (phy->id == e1000_phy_unknown)
425 switch (hw->mac.type) {
426 default:
427 ret_val = e1000e_get_phy_id(hw);
428 if (ret_val)
429 return ret_val;
430 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
431 break;
432 /* fall-through */
433 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000434 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000435 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000436 * set slow mode and try to get the PHY id again.
437 */
438 ret_val = e1000_set_mdio_slow_mode_hv(hw);
439 if (ret_val)
440 return ret_val;
441 ret_val = e1000e_get_phy_id(hw);
442 if (ret_val)
443 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000444 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000445 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000446 phy->type = e1000e_get_phy_type_from_id(phy->id);
447
Bruce Allan0be84012009-12-02 17:03:18 +0000448 switch (phy->type) {
449 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000450 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000451 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000452 phy->ops.check_polarity = e1000_check_polarity_82577;
453 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000454 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000455 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000456 phy->ops.get_info = e1000_get_phy_info_82577;
457 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000458 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000459 case e1000_phy_82578:
460 phy->ops.check_polarity = e1000_check_polarity_m88;
461 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
462 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
463 phy->ops.get_info = e1000e_get_phy_info_m88;
464 break;
465 default:
466 ret_val = -E1000_ERR_PHY;
467 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000468 }
469
470 return ret_val;
471}
472
473/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700474 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
475 * @hw: pointer to the HW structure
476 *
477 * Initialize family-specific PHY parameters and function pointers.
478 **/
479static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
480{
481 struct e1000_phy_info *phy = &hw->phy;
482 s32 ret_val;
483 u16 i = 0;
484
Bruce Allane80bd1d2013-05-01 01:19:46 +0000485 phy->addr = 1;
486 phy->reset_delay_us = 100;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700487
Bruce Allane80bd1d2013-05-01 01:19:46 +0000488 phy->ops.power_up = e1000_power_up_phy_copper;
489 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allan17f208d2009-12-01 15:47:22 +0000490
Bruce Allane921eb12012-11-28 09:28:37 +0000491 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700492 * we'll set BM func pointers and try again
493 */
494 ret_val = e1000e_determine_phy_address(hw);
495 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000496 phy->ops.write_reg = e1000e_write_phy_reg_bm;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000497 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700498 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000499 if (ret_val) {
500 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700501 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000502 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700503 }
504
Auke Kokbc7f75f2007-09-17 12:30:59 -0700505 phy->id = 0;
506 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
507 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000508 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700509 ret_val = e1000e_get_phy_id(hw);
510 if (ret_val)
511 return ret_val;
512 }
513
514 /* Verify phy id */
515 switch (phy->id) {
516 case IGP03E1000_E_PHY_ID:
517 phy->type = e1000_phy_igp_3;
518 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000519 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
520 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000521 phy->ops.get_info = e1000e_get_phy_info_igp;
522 phy->ops.check_polarity = e1000_check_polarity_igp;
523 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700524 break;
525 case IFE_E_PHY_ID:
526 case IFE_PLUS_E_PHY_ID:
527 case IFE_C_E_PHY_ID:
528 phy->type = e1000_phy_ife;
529 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000530 phy->ops.get_info = e1000_get_phy_info_ife;
531 phy->ops.check_polarity = e1000_check_polarity_ife;
532 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700533 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700534 case BME1000_E_PHY_ID:
535 phy->type = e1000_phy_bm;
536 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000537 phy->ops.read_reg = e1000e_read_phy_reg_bm;
538 phy->ops.write_reg = e1000e_write_phy_reg_bm;
539 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000540 phy->ops.get_info = e1000e_get_phy_info_m88;
541 phy->ops.check_polarity = e1000_check_polarity_m88;
542 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700543 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544 default:
545 return -E1000_ERR_PHY;
546 break;
547 }
548
549 return 0;
550}
551
552/**
553 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
554 * @hw: pointer to the HW structure
555 *
556 * Initialize family-specific NVM parameters and function
557 * pointers.
558 **/
559static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
560{
561 struct e1000_nvm_info *nvm = &hw->nvm;
562 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000563 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700564 u16 i;
565
Bruce Allanad680762008-03-28 09:15:03 -0700566 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700567 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000568 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700569 return -E1000_ERR_CONFIG;
570 }
571
572 nvm->type = e1000_nvm_flash_sw;
573
574 gfpreg = er32flash(ICH_FLASH_GFPREG);
575
Bruce Allane921eb12012-11-28 09:28:37 +0000576 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700578 * the overall size.
579 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700580 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
581 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
582
583 /* flash_base_addr is byte-aligned */
584 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
585
Bruce Allane921eb12012-11-28 09:28:37 +0000586 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700587 * size represents two separate NVM banks.
588 */
Bruce Allanf0ff4392013-02-20 04:05:39 +0000589 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
590 << FLASH_SECTOR_ADDR_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700591 nvm->flash_bank_size /= 2;
592 /* Adjust to word count */
593 nvm->flash_bank_size /= sizeof(u16);
594
595 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
596
597 /* Clear shadow ram */
598 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000599 dev_spec->shadow_ram[i].modified = false;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000600 dev_spec->shadow_ram[i].value = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700601 }
602
603 return 0;
604}
605
606/**
607 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
608 * @hw: pointer to the HW structure
609 *
610 * Initialize family-specific MAC parameters and function
611 * pointers.
612 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000613static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700615 struct e1000_mac_info *mac = &hw->mac;
616
617 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700618 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700619
620 /* Set mta register count */
621 mac->mta_reg_count = 32;
622 /* Set rar entry count */
623 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
624 if (mac->type == e1000_ich8lan)
625 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000626 /* FWSM register */
627 mac->has_fwsm = true;
628 /* ARC subsystem not supported */
629 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000630 /* Adaptive IFS supported */
631 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700632
Bruce Allan2fbe4522012-04-19 03:21:47 +0000633 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000634 switch (mac->type) {
635 case e1000_ich8lan:
636 case e1000_ich9lan:
637 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000638 /* check management mode */
639 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000640 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000641 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000642 /* blink LED */
643 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000644 /* setup LED */
645 mac->ops.setup_led = e1000e_setup_led_generic;
646 /* cleanup LED */
647 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
648 /* turn on/off LED */
649 mac->ops.led_on = e1000_led_on_ich8lan;
650 mac->ops.led_off = e1000_led_off_ich8lan;
651 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000652 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000653 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
654 mac->ops.rar_set = e1000_rar_set_pch2lan;
655 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000656 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000657 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000658 /* check management mode */
659 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000660 /* ID LED init */
661 mac->ops.id_led_init = e1000_id_led_init_pchlan;
662 /* setup LED */
663 mac->ops.setup_led = e1000_setup_led_pchlan;
664 /* cleanup LED */
665 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
666 /* turn on/off LED */
667 mac->ops.led_on = e1000_led_on_pchlan;
668 mac->ops.led_off = e1000_led_off_pchlan;
669 break;
670 default:
671 break;
672 }
673
Bruce Allan2fbe4522012-04-19 03:21:47 +0000674 if (mac->type == e1000_pch_lpt) {
675 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
676 mac->ops.rar_set = e1000_rar_set_pch_lpt;
Bruce Allanea8179a2013-03-06 09:02:47 +0000677 mac->ops.setup_physical_interface =
678 e1000_setup_copper_link_pch_lpt;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000679 }
680
Auke Kokbc7f75f2007-09-17 12:30:59 -0700681 /* Enable PCS Lock-loss workaround for ICH8 */
682 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000683 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700684
685 return 0;
686}
687
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000688/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000689 * __e1000_access_emi_reg_locked - Read/write EMI register
690 * @hw: pointer to the HW structure
691 * @addr: EMI address to program
692 * @data: pointer to value to read/write from/to the EMI address
693 * @read: boolean flag to indicate read or write
694 *
695 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
696 **/
697static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
698 u16 *data, bool read)
699{
Bruce Allan70806a72013-01-05 05:08:37 +0000700 s32 ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000701
702 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
703 if (ret_val)
704 return ret_val;
705
706 if (read)
707 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
708 else
709 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
710
711 return ret_val;
712}
713
714/**
715 * e1000_read_emi_reg_locked - Read Extended Management Interface register
716 * @hw: pointer to the HW structure
717 * @addr: EMI address to program
718 * @data: value to be read from the EMI address
719 *
720 * Assumes the SW/FW/HW Semaphore is already acquired.
721 **/
Bruce Allan203e4152012-12-05 08:40:59 +0000722s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000723{
724 return __e1000_access_emi_reg_locked(hw, addr, data, true);
725}
726
727/**
728 * e1000_write_emi_reg_locked - Write Extended Management Interface register
729 * @hw: pointer to the HW structure
730 * @addr: EMI address to program
731 * @data: value to be written to the EMI address
732 *
733 * Assumes the SW/FW/HW Semaphore is already acquired.
734 **/
Bruce Alland495bcb2013-03-20 07:23:11 +0000735s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000736{
737 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
738}
739
740/**
Bruce Allane52997f2010-06-16 13:27:49 +0000741 * e1000_set_eee_pchlan - Enable/disable EEE support
742 * @hw: pointer to the HW structure
743 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000744 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
745 * the link and the EEE capabilities of the link partner. The LPI Control
746 * register bits will remain set only if/when link is up.
Bruce Allane52997f2010-06-16 13:27:49 +0000747 **/
748static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
749{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000750 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000751 s32 ret_val;
Bruce Alland495bcb2013-03-20 07:23:11 +0000752 u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
Bruce Allane52997f2010-06-16 13:27:49 +0000753
Bruce Alland495bcb2013-03-20 07:23:11 +0000754 switch (hw->phy.type) {
755 case e1000_phy_82579:
756 lpa = I82579_EEE_LP_ABILITY;
757 pcs_status = I82579_EEE_PCS_STATUS;
758 adv_addr = I82579_EEE_ADVERTISEMENT;
759 break;
760 case e1000_phy_i217:
761 lpa = I217_EEE_LP_ABILITY;
762 pcs_status = I217_EEE_PCS_STATUS;
763 adv_addr = I217_EEE_ADVERTISEMENT;
764 break;
765 default:
Bruce Allan5015e532012-02-08 02:55:56 +0000766 return 0;
Bruce Alland495bcb2013-03-20 07:23:11 +0000767 }
Bruce Allane52997f2010-06-16 13:27:49 +0000768
Bruce Allan3d4d5752012-12-05 06:26:08 +0000769 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000770 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000771 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000772
Bruce Allan3d4d5752012-12-05 06:26:08 +0000773 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000774 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000775 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000776
Bruce Allan3d4d5752012-12-05 06:26:08 +0000777 /* Clear bits that enable EEE in various speeds */
778 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
779
780 /* Enable EEE if not disabled by user */
781 if (!dev_spec->eee_disable) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000782 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000783 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000784 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000785 if (ret_val)
786 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000787
Bruce Alland495bcb2013-03-20 07:23:11 +0000788 /* Read EEE advertisement */
789 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
790 if (ret_val)
791 goto release;
792
Bruce Allan3d4d5752012-12-05 06:26:08 +0000793 /* Enable EEE only for speeds in which the link partner is
Bruce Alland495bcb2013-03-20 07:23:11 +0000794 * EEE capable and for which we advertise EEE.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000795 */
Bruce Alland495bcb2013-03-20 07:23:11 +0000796 if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000797 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
798
Bruce Alland495bcb2013-03-20 07:23:11 +0000799 if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000800 e1e_rphy_locked(hw, MII_LPA, &data);
801 if (data & LPA_100FULL)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000802 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
803 else
804 /* EEE is not supported in 100Half, so ignore
805 * partner's EEE in 100 ability if full-duplex
806 * is not advertised.
807 */
808 dev_spec->eee_lp_ability &=
809 ~I82579_EEE_100_SUPPORTED;
810 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000811 }
812
Bruce Alland495bcb2013-03-20 07:23:11 +0000813 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
814 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
815 if (ret_val)
816 goto release;
817
Bruce Allan3d4d5752012-12-05 06:26:08 +0000818 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
819release:
820 hw->phy.ops.release(hw);
821
822 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000823}
824
825/**
Bruce Allane08f6262013-02-20 03:06:34 +0000826 * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
827 * @hw: pointer to the HW structure
828 * @link: link up bool flag
829 *
830 * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
831 * preventing further DMA write requests. Workaround the issue by disabling
832 * the de-assertion of the clock request when in 1Gpbs mode.
Bruce Allane0236ad2013-06-21 09:07:13 +0000833 * Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
834 * speeds in order to avoid Tx hangs.
Bruce Allane08f6262013-02-20 03:06:34 +0000835 **/
836static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
837{
838 u32 fextnvm6 = er32(FEXTNVM6);
Bruce Allane0236ad2013-06-21 09:07:13 +0000839 u32 status = er32(STATUS);
Bruce Allane08f6262013-02-20 03:06:34 +0000840 s32 ret_val = 0;
Bruce Allane0236ad2013-06-21 09:07:13 +0000841 u16 reg;
Bruce Allane08f6262013-02-20 03:06:34 +0000842
Bruce Allane0236ad2013-06-21 09:07:13 +0000843 if (link && (status & E1000_STATUS_SPEED_1000)) {
Bruce Allane08f6262013-02-20 03:06:34 +0000844 ret_val = hw->phy.ops.acquire(hw);
845 if (ret_val)
846 return ret_val;
847
848 ret_val =
849 e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000850 &reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000851 if (ret_val)
852 goto release;
853
854 ret_val =
855 e1000e_write_kmrn_reg_locked(hw,
856 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000857 reg &
Bruce Allane08f6262013-02-20 03:06:34 +0000858 ~E1000_KMRNCTRLSTA_K1_ENABLE);
859 if (ret_val)
860 goto release;
861
862 usleep_range(10, 20);
863
864 ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
865
866 ret_val =
867 e1000e_write_kmrn_reg_locked(hw,
868 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000869 reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000870release:
871 hw->phy.ops.release(hw);
872 } else {
873 /* clear FEXTNVM6 bit 8 on link down or 10/100 */
Bruce Allane0236ad2013-06-21 09:07:13 +0000874 fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
875
876 if (!link || ((status & E1000_STATUS_SPEED_100) &&
877 (status & E1000_STATUS_FD)))
878 goto update_fextnvm6;
879
880 ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
881 if (ret_val)
882 return ret_val;
883
884 /* Clear link status transmit timeout */
885 reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
886
887 if (status & E1000_STATUS_SPEED_100) {
888 /* Set inband Tx timeout to 5x10us for 100Half */
889 reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
890
891 /* Do not extend the K1 entry latency for 100Half */
892 fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
893 } else {
894 /* Set inband Tx timeout to 50x10us for 10Full/Half */
895 reg |= 50 <<
896 I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
897
898 /* Extend the K1 entry latency for 10 Mbps */
899 fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
900 }
901
902 ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
903 if (ret_val)
904 return ret_val;
905
906update_fextnvm6:
907 ew32(FEXTNVM6, fextnvm6);
Bruce Allane08f6262013-02-20 03:06:34 +0000908 }
909
910 return ret_val;
911}
912
913/**
Bruce Allancf8fb732013-03-06 09:03:02 +0000914 * e1000_platform_pm_pch_lpt - Set platform power management values
915 * @hw: pointer to the HW structure
916 * @link: bool indicating link status
917 *
918 * Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
919 * GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
920 * when link is up (which must not exceed the maximum latency supported
921 * by the platform), otherwise specify there is no LTR requirement.
922 * Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
923 * latencies in the LTR Extended Capability Structure in the PCIe Extended
924 * Capability register set, on this device LTR is set by writing the
925 * equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
926 * set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
927 * message to the PMC.
928 **/
929static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
930{
931 u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
932 link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
933 u16 lat_enc = 0; /* latency encoded */
934
935 if (link) {
936 u16 speed, duplex, scale = 0;
937 u16 max_snoop, max_nosnoop;
938 u16 max_ltr_enc; /* max LTR latency encoded */
939 s64 lat_ns; /* latency (ns) */
940 s64 value;
941 u32 rxa;
942
943 if (!hw->adapter->max_frame_size) {
944 e_dbg("max_frame_size not set.\n");
945 return -E1000_ERR_CONFIG;
946 }
947
948 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
949 if (!speed) {
950 e_dbg("Speed not set.\n");
951 return -E1000_ERR_CONFIG;
952 }
953
954 /* Rx Packet Buffer Allocation size (KB) */
955 rxa = er32(PBA) & E1000_PBA_RXA_MASK;
956
957 /* Determine the maximum latency tolerated by the device.
958 *
959 * Per the PCIe spec, the tolerated latencies are encoded as
960 * a 3-bit encoded scale (only 0-5 are valid) multiplied by
961 * a 10-bit value (0-1023) to provide a range from 1 ns to
962 * 2^25*(2^10-1) ns. The scale is encoded as 0=2^0ns,
963 * 1=2^5ns, 2=2^10ns,...5=2^25ns.
964 */
965 lat_ns = ((s64)rxa * 1024 -
966 (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
967 if (lat_ns < 0)
968 lat_ns = 0;
969 else
970 do_div(lat_ns, speed);
971
972 value = lat_ns;
973 while (value > PCI_LTR_VALUE_MASK) {
974 scale++;
975 value = DIV_ROUND_UP(value, (1 << 5));
976 }
977 if (scale > E1000_LTRV_SCALE_MAX) {
978 e_dbg("Invalid LTR latency scale %d\n", scale);
979 return -E1000_ERR_CONFIG;
980 }
981 lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
982
983 /* Determine the maximum latency tolerated by the platform */
984 pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
985 &max_snoop);
986 pci_read_config_word(hw->adapter->pdev,
987 E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
988 max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
989
990 if (lat_enc > max_ltr_enc)
991 lat_enc = max_ltr_enc;
992 }
993
994 /* Set Snoop and No-Snoop latencies the same */
995 reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
996 ew32(LTRV, reg);
997
998 return 0;
999}
1000
1001/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001002 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
1003 * @hw: pointer to the HW structure
1004 *
1005 * Checks to see of the link status of the hardware has changed. If a
1006 * change in link status has been detected, then we read the PHY registers
1007 * to get the current speed/duplex if link exists.
1008 **/
1009static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
1010{
1011 struct e1000_mac_info *mac = &hw->mac;
1012 s32 ret_val;
1013 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001014 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001015
Bruce Allane921eb12012-11-28 09:28:37 +00001016 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001017 * has completed and/or if our link status has changed. The
1018 * get_link_status flag is set upon receiving a Link Status
1019 * Change or Rx Sequence Error interrupt.
1020 */
Bruce Allan5015e532012-02-08 02:55:56 +00001021 if (!mac->get_link_status)
1022 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001023
Bruce Allane921eb12012-11-28 09:28:37 +00001024 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001025 * link. If so, then we want to get the current speed/duplex
1026 * of the PHY.
1027 */
1028 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1029 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001030 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001031
Bruce Allan1d5846b2009-10-29 13:46:05 +00001032 if (hw->mac.type == e1000_pchlan) {
1033 ret_val = e1000_k1_gig_workaround_hv(hw, link);
1034 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001035 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001036 }
1037
Bruce Allan772d05c2013-03-06 09:02:36 +00001038 /* When connected at 10Mbps half-duplex, 82579 parts are excessively
1039 * aggressive resulting in many collisions. To avoid this, increase
1040 * the IPG and reduce Rx latency in the PHY.
1041 */
1042 if ((hw->mac.type == e1000_pch2lan) && link) {
1043 u32 reg;
1044 reg = er32(STATUS);
1045 if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
1046 reg = er32(TIPG);
1047 reg &= ~E1000_TIPG_IPGT_MASK;
1048 reg |= 0xFF;
1049 ew32(TIPG, reg);
1050
1051 /* Reduce Rx latency in analog PHY */
1052 ret_val = hw->phy.ops.acquire(hw);
1053 if (ret_val)
1054 return ret_val;
1055
1056 ret_val =
1057 e1000_write_emi_reg_locked(hw, I82579_RX_CONFIG, 0);
1058
1059 hw->phy.ops.release(hw);
1060
1061 if (ret_val)
1062 return ret_val;
1063 }
1064 }
1065
Bruce Allane08f6262013-02-20 03:06:34 +00001066 /* Work-around I218 hang issue */
1067 if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
Bruce Allan91a3d822013-06-29 01:15:16 +00001068 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
1069 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
1070 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
Bruce Allane08f6262013-02-20 03:06:34 +00001071 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
1072 if (ret_val)
1073 return ret_val;
1074 }
1075
Bruce Allancf8fb732013-03-06 09:03:02 +00001076 if (hw->mac.type == e1000_pch_lpt) {
1077 /* Set platform power management values for
1078 * Latency Tolerance Reporting (LTR)
1079 */
1080 ret_val = e1000_platform_pm_pch_lpt(hw, link);
1081 if (ret_val)
1082 return ret_val;
1083 }
1084
Bruce Allan2fbe4522012-04-19 03:21:47 +00001085 /* Clear link partner's EEE ability */
1086 hw->dev_spec.ich8lan.eee_lp_ability = 0;
1087
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001088 if (!link)
Bruce Allane80bd1d2013-05-01 01:19:46 +00001089 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001090
1091 mac->get_link_status = false;
1092
Bruce Allan1d2101a72011-07-22 06:21:56 +00001093 switch (hw->mac.type) {
1094 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +00001095 ret_val = e1000_k1_workaround_lv(hw);
1096 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001097 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001098 /* fall-thru */
1099 case e1000_pchlan:
1100 if (hw->phy.type == e1000_phy_82578) {
1101 ret_val = e1000_link_stall_workaround_hv(hw);
1102 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001103 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001104 }
1105
Bruce Allane921eb12012-11-28 09:28:37 +00001106 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +00001107 * Set the number of preambles removed from the packet
1108 * when it is passed from the PHY to the MAC to prevent
1109 * the MAC from misinterpreting the packet type.
1110 */
1111 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
1112 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
1113
1114 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
1115 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
1116
1117 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
1118 break;
1119 default:
1120 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001121 }
1122
Bruce Allane921eb12012-11-28 09:28:37 +00001123 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001124 * immediately after link-up
1125 */
1126 e1000e_check_downshift(hw);
1127
Bruce Allane52997f2010-06-16 13:27:49 +00001128 /* Enable/Disable EEE after link up */
1129 ret_val = e1000_set_eee_pchlan(hw);
1130 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001131 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +00001132
Bruce Allane921eb12012-11-28 09:28:37 +00001133 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001134 * we have already determined whether we have link or not.
1135 */
Bruce Allan5015e532012-02-08 02:55:56 +00001136 if (!mac->autoneg)
1137 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001138
Bruce Allane921eb12012-11-28 09:28:37 +00001139 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001140 * of MAC speed/duplex configuration. So we only need to
1141 * configure Collision Distance in the MAC.
1142 */
Bruce Allan57cde762012-02-22 09:02:58 +00001143 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001144
Bruce Allane921eb12012-11-28 09:28:37 +00001145 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001146 * First, we need to restore the desired flow control
1147 * settings because we may have had to re-autoneg with a
1148 * different link partner.
1149 */
1150 ret_val = e1000e_config_fc_after_link_up(hw);
1151 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001152 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001153
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001154 return ret_val;
1155}
1156
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001157static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158{
1159 struct e1000_hw *hw = &adapter->hw;
1160 s32 rc;
1161
Bruce Allanec34c172012-02-01 10:53:05 +00001162 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 if (rc)
1164 return rc;
1165
1166 rc = e1000_init_nvm_params_ich8lan(hw);
1167 if (rc)
1168 return rc;
1169
Bruce Alland3738bb2010-06-16 13:27:28 +00001170 switch (hw->mac.type) {
1171 case e1000_ich8lan:
1172 case e1000_ich9lan:
1173 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001174 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001175 break;
1176 case e1000_pchlan:
1177 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001178 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001179 rc = e1000_init_phy_params_pchlan(hw);
1180 break;
1181 default:
1182 break;
1183 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001184 if (rc)
1185 return rc;
1186
Bruce Allane921eb12012-11-28 09:28:37 +00001187 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001188 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1189 */
1190 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1191 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1192 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001193 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1194 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001195
1196 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001197 }
1198
Auke Kokbc7f75f2007-09-17 12:30:59 -07001199 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001200 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001201 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1202
Bruce Allanc6e7f512011-07-29 05:53:02 +00001203 /* Enable workaround for 82579 w/ ME enabled */
1204 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1205 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1206 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1207
Auke Kokbc7f75f2007-09-17 12:30:59 -07001208 return 0;
1209}
1210
Thomas Gleixner717d4382008-10-02 16:33:40 -07001211static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001212
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213/**
Bruce Allanca15df52009-10-26 11:23:43 +00001214 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1215 * @hw: pointer to the HW structure
1216 *
1217 * Acquires the mutex for performing NVM operations.
1218 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001219static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001220{
1221 mutex_lock(&nvm_mutex);
1222
1223 return 0;
1224}
1225
1226/**
1227 * e1000_release_nvm_ich8lan - Release NVM mutex
1228 * @hw: pointer to the HW structure
1229 *
1230 * Releases the mutex used while performing NVM operations.
1231 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001232static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001233{
1234 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001235}
1236
Bruce Allanca15df52009-10-26 11:23:43 +00001237/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001238 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1239 * @hw: pointer to the HW structure
1240 *
Bruce Allanca15df52009-10-26 11:23:43 +00001241 * Acquires the software control flag for performing PHY and select
1242 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001243 **/
1244static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1245{
Bruce Allan373a88d2009-08-07 07:41:37 +00001246 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1247 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001248
Bruce Allana90b4122011-10-07 03:50:38 +00001249 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1250 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001251 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001252 return -E1000_ERR_PHY;
1253 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001254
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255 while (timeout) {
1256 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001257 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1258 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001259
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260 mdelay(1);
1261 timeout--;
1262 }
1263
1264 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001265 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001266 ret_val = -E1000_ERR_CONFIG;
1267 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001268 }
1269
Bruce Allan53ac5a82009-10-26 11:23:06 +00001270 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001271
1272 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1273 ew32(EXTCNF_CTRL, extcnf_ctrl);
1274
1275 while (timeout) {
1276 extcnf_ctrl = er32(EXTCNF_CTRL);
1277 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1278 break;
1279
1280 mdelay(1);
1281 timeout--;
1282 }
1283
1284 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001285 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 +00001286 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001287 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1288 ew32(EXTCNF_CTRL, extcnf_ctrl);
1289 ret_val = -E1000_ERR_CONFIG;
1290 goto out;
1291 }
1292
1293out:
1294 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001295 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001296
1297 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001298}
1299
1300/**
1301 * e1000_release_swflag_ich8lan - Release software control flag
1302 * @hw: pointer to the HW structure
1303 *
Bruce Allanca15df52009-10-26 11:23:43 +00001304 * Releases the software control flag for performing PHY and select
1305 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001306 **/
1307static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1308{
1309 u32 extcnf_ctrl;
1310
1311 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001312
1313 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1314 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1315 ew32(EXTCNF_CTRL, extcnf_ctrl);
1316 } else {
1317 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1318 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001319
Bruce Allana90b4122011-10-07 03:50:38 +00001320 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001321}
1322
1323/**
Bruce Allan4662e822008-08-26 18:37:06 -07001324 * e1000_check_mng_mode_ich8lan - Checks management mode
1325 * @hw: pointer to the HW structure
1326 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001327 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001328 * This is a function pointer entry point only called by read/write
1329 * routines for the PHY and NVM parts.
1330 **/
1331static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1332{
Bruce Allana708dd82009-11-20 23:28:37 +00001333 u32 fwsm;
1334
1335 fwsm = er32(FWSM);
Bruce Allanf0ff4392013-02-20 04:05:39 +00001336 return ((fwsm & E1000_ICH_FWSM_FW_VALID) &&
1337 ((fwsm & E1000_FWSM_MODE_MASK) ==
1338 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)));
Bruce Allaneb7700d2010-06-16 13:27:05 +00001339}
Bruce Allan4662e822008-08-26 18:37:06 -07001340
Bruce Allaneb7700d2010-06-16 13:27:05 +00001341/**
1342 * e1000_check_mng_mode_pchlan - Checks management mode
1343 * @hw: pointer to the HW structure
1344 *
1345 * This checks if the adapter has iAMT enabled.
1346 * This is a function pointer entry point only called by read/write
1347 * routines for the PHY and NVM parts.
1348 **/
1349static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1350{
1351 u32 fwsm;
1352
1353 fwsm = er32(FWSM);
1354 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
Bruce Allanf0ff4392013-02-20 04:05:39 +00001355 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001356}
1357
1358/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001359 * e1000_rar_set_pch2lan - Set receive address register
1360 * @hw: pointer to the HW structure
1361 * @addr: pointer to the receive address
1362 * @index: receive address array register
1363 *
1364 * Sets the receive address array register at index to the address passed
1365 * in by addr. For 82579, RAR[0] is the base address register that is to
1366 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1367 * Use SHRA[0-3] in place of those reserved for ME.
1368 **/
1369static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1370{
1371 u32 rar_low, rar_high;
1372
Bruce Allane921eb12012-11-28 09:28:37 +00001373 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001374 * from network order (big endian) to little endian
1375 */
1376 rar_low = ((u32)addr[0] |
1377 ((u32)addr[1] << 8) |
1378 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1379
1380 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1381
1382 /* If MAC address zero, no need to set the AV bit */
1383 if (rar_low || rar_high)
1384 rar_high |= E1000_RAH_AV;
1385
1386 if (index == 0) {
1387 ew32(RAL(index), rar_low);
1388 e1e_flush();
1389 ew32(RAH(index), rar_high);
1390 e1e_flush();
1391 return;
1392 }
1393
David Ertmanc3a0dce2013-09-05 04:24:25 +00001394 /* RAR[1-6] are owned by manageability. Skip those and program the
1395 * next address into the SHRA register array.
1396 */
1397 if (index < (u32)(hw->mac.rar_entry_count - 6)) {
Bruce Allan69e1e012012-04-14 03:28:50 +00001398 s32 ret_val;
1399
1400 ret_val = e1000_acquire_swflag_ich8lan(hw);
1401 if (ret_val)
1402 goto out;
1403
1404 ew32(SHRAL(index - 1), rar_low);
1405 e1e_flush();
1406 ew32(SHRAH(index - 1), rar_high);
1407 e1e_flush();
1408
1409 e1000_release_swflag_ich8lan(hw);
1410
1411 /* verify the register updates */
1412 if ((er32(SHRAL(index - 1)) == rar_low) &&
1413 (er32(SHRAH(index - 1)) == rar_high))
1414 return;
1415
1416 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1417 (index - 1), er32(FWSM));
1418 }
1419
1420out:
1421 e_dbg("Failed to write receive address at index %d\n", index);
1422}
1423
1424/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001425 * e1000_rar_set_pch_lpt - Set receive address registers
1426 * @hw: pointer to the HW structure
1427 * @addr: pointer to the receive address
1428 * @index: receive address array register
1429 *
1430 * Sets the receive address register array at index to the address passed
1431 * in by addr. For LPT, RAR[0] is the base address register that is to
1432 * contain the MAC address. SHRA[0-10] are the shared receive address
1433 * registers that are shared between the Host and manageability engine (ME).
1434 **/
1435static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1436{
1437 u32 rar_low, rar_high;
1438 u32 wlock_mac;
1439
Bruce Allane921eb12012-11-28 09:28:37 +00001440 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001441 * from network order (big endian) to little endian
1442 */
1443 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1444 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1445
1446 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1447
1448 /* If MAC address zero, no need to set the AV bit */
1449 if (rar_low || rar_high)
1450 rar_high |= E1000_RAH_AV;
1451
1452 if (index == 0) {
1453 ew32(RAL(index), rar_low);
1454 e1e_flush();
1455 ew32(RAH(index), rar_high);
1456 e1e_flush();
1457 return;
1458 }
1459
Bruce Allane921eb12012-11-28 09:28:37 +00001460 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001461 * it is using - those registers are unavailable for use.
1462 */
1463 if (index < hw->mac.rar_entry_count) {
1464 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1465 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1466
1467 /* Check if all SHRAR registers are locked */
1468 if (wlock_mac == 1)
1469 goto out;
1470
1471 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1472 s32 ret_val;
1473
1474 ret_val = e1000_acquire_swflag_ich8lan(hw);
1475
1476 if (ret_val)
1477 goto out;
1478
1479 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1480 e1e_flush();
1481 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1482 e1e_flush();
1483
1484 e1000_release_swflag_ich8lan(hw);
1485
1486 /* verify the register updates */
1487 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1488 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1489 return;
1490 }
1491 }
1492
1493out:
1494 e_dbg("Failed to write receive address at index %d\n", index);
1495}
1496
1497/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001498 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1499 * @hw: pointer to the HW structure
1500 *
1501 * Checks if firmware is blocking the reset of the PHY.
1502 * This is a function pointer entry point only called by
1503 * reset routines.
1504 **/
1505static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1506{
David Ertmanf7235ef2014-01-23 06:29:13 +00001507 bool blocked = false;
1508 int i = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001509
David Ertmanf7235ef2014-01-23 06:29:13 +00001510 while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&
1511 (i++ < 10))
1512 usleep_range(10000, 20000);
1513 return blocked ? E1000_BLK_PHY_RESET : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001514}
1515
1516/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001517 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1518 * @hw: pointer to the HW structure
1519 *
1520 * Assumes semaphore already acquired.
1521 *
1522 **/
1523static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1524{
1525 u16 phy_data;
1526 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001527 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1528 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan70806a72013-01-05 05:08:37 +00001529 s32 ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001530
1531 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1532
1533 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1534 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001535 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001536
1537 phy_data &= ~HV_SMB_ADDR_MASK;
1538 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1539 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001540
Bruce Allan2fbe4522012-04-19 03:21:47 +00001541 if (hw->phy.type == e1000_phy_i217) {
1542 /* Restore SMBus frequency */
1543 if (freq--) {
1544 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1545 phy_data |= (freq & (1 << 0)) <<
1546 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1547 phy_data |= (freq & (1 << 1)) <<
1548 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1549 } else {
1550 e_dbg("Unsupported SMB frequency in PHY\n");
1551 }
1552 }
1553
Bruce Allan5015e532012-02-08 02:55:56 +00001554 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001555}
1556
1557/**
Bruce Allanf523d212009-10-29 13:45:45 +00001558 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1559 * @hw: pointer to the HW structure
1560 *
1561 * SW should configure the LCD from the NVM extended configuration region
1562 * as a workaround for certain parts.
1563 **/
1564static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1565{
1566 struct e1000_phy_info *phy = &hw->phy;
1567 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001568 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001569 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1570
Bruce Allane921eb12012-11-28 09:28:37 +00001571 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001572 * is needed due to an issue where the NVM configuration is
1573 * not properly autoloaded after power transitions.
1574 * Therefore, after each PHY reset, we will load the
1575 * configuration data out of the NVM manually.
1576 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001577 switch (hw->mac.type) {
1578 case e1000_ich8lan:
1579 if (phy->type != e1000_phy_igp_3)
1580 return ret_val;
1581
Bruce Allan5f3eed62010-09-22 17:15:54 +00001582 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1583 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001584 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1585 break;
1586 }
1587 /* Fall-thru */
1588 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001589 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001590 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001591 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001592 break;
1593 default:
1594 return ret_val;
1595 }
1596
1597 ret_val = hw->phy.ops.acquire(hw);
1598 if (ret_val)
1599 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001600
Bruce Allan8b802a72010-05-10 15:01:10 +00001601 data = er32(FEXTNVM);
1602 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001603 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001604
Bruce Allane921eb12012-11-28 09:28:37 +00001605 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001606 * extended configuration before SW configuration
1607 */
1608 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001609 if ((hw->mac.type < e1000_pch2lan) &&
1610 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1611 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001612
Bruce Allan8b802a72010-05-10 15:01:10 +00001613 cnf_size = er32(EXTCNF_SIZE);
1614 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1615 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1616 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001617 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001618
1619 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1620 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1621
Bruce Allan2fbe4522012-04-19 03:21:47 +00001622 if (((hw->mac.type == e1000_pchlan) &&
1623 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1624 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001625 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001626 * OEM and LCD Write Enable bits are set in the NVM.
1627 * When both NVM bits are cleared, SW will configure
1628 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001629 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001630 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001631 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001632 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001633
Bruce Allan8b802a72010-05-10 15:01:10 +00001634 data = er32(LEDCTL);
1635 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1636 (u16)data);
1637 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001638 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001639 }
1640
1641 /* Configure LCD from extended configuration region. */
1642
1643 /* cnf_base_addr is in DWORD */
1644 word_addr = (u16)(cnf_base_addr << 1);
1645
1646 for (i = 0; i < cnf_size; i++) {
Bruce Allane5fe2542013-02-20 04:06:27 +00001647 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001648 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001649 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001650
Bruce Allan8b802a72010-05-10 15:01:10 +00001651 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1652 1, &reg_addr);
1653 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001654 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001655
Bruce Allan8b802a72010-05-10 15:01:10 +00001656 /* Save off the PHY page for future writes. */
1657 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1658 phy_page = reg_data;
1659 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001660 }
Bruce Allanf523d212009-10-29 13:45:45 +00001661
Bruce Allan8b802a72010-05-10 15:01:10 +00001662 reg_addr &= PHY_REG_MASK;
1663 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001664
Bruce Allanf1430d62012-04-14 04:21:52 +00001665 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001666 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001667 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001668 }
1669
Bruce Allan75ce1532012-02-08 02:54:48 +00001670release:
Bruce Allan94d81862009-11-20 23:25:26 +00001671 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001672 return ret_val;
1673}
1674
1675/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001676 * e1000_k1_gig_workaround_hv - K1 Si workaround
1677 * @hw: pointer to the HW structure
1678 * @link: link up bool flag
1679 *
1680 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1681 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1682 * If link is down, the function will restore the default K1 setting located
1683 * in the NVM.
1684 **/
1685static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1686{
1687 s32 ret_val = 0;
1688 u16 status_reg = 0;
1689 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1690
1691 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001692 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001693
1694 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001695 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001696 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001697 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001698
1699 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1700 if (link) {
1701 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001702 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1703 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001704 if (ret_val)
1705 goto release;
1706
Bruce Allanf0ff4392013-02-20 04:05:39 +00001707 status_reg &= (BM_CS_STATUS_LINK_UP |
1708 BM_CS_STATUS_RESOLVED |
1709 BM_CS_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001710
1711 if (status_reg == (BM_CS_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001712 BM_CS_STATUS_RESOLVED |
1713 BM_CS_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001714 k1_enable = false;
1715 }
1716
1717 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001718 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001719 if (ret_val)
1720 goto release;
1721
Bruce Allanf0ff4392013-02-20 04:05:39 +00001722 status_reg &= (HV_M_STATUS_LINK_UP |
1723 HV_M_STATUS_AUTONEG_COMPLETE |
1724 HV_M_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001725
1726 if (status_reg == (HV_M_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001727 HV_M_STATUS_AUTONEG_COMPLETE |
1728 HV_M_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001729 k1_enable = false;
1730 }
1731
1732 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001733 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001734 if (ret_val)
1735 goto release;
1736
1737 } else {
1738 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001739 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001740 if (ret_val)
1741 goto release;
1742 }
1743
1744 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1745
1746release:
Bruce Allan94d81862009-11-20 23:25:26 +00001747 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001748
Bruce Allan1d5846b2009-10-29 13:46:05 +00001749 return ret_val;
1750}
1751
1752/**
1753 * e1000_configure_k1_ich8lan - Configure K1 power state
1754 * @hw: pointer to the HW structure
1755 * @enable: K1 state to configure
1756 *
1757 * Configure the K1 power state based on the provided parameter.
1758 * Assumes semaphore already acquired.
1759 *
1760 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1761 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001762s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001763{
Bruce Allan70806a72013-01-05 05:08:37 +00001764 s32 ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001765 u32 ctrl_reg = 0;
1766 u32 ctrl_ext = 0;
1767 u32 reg = 0;
1768 u16 kmrn_reg = 0;
1769
Bruce Allan3d3a1672012-02-23 03:13:18 +00001770 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1771 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001772 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001773 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001774
1775 if (k1_enable)
1776 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1777 else
1778 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1779
Bruce Allan3d3a1672012-02-23 03:13:18 +00001780 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1781 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001782 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001783 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001784
Bruce Allance43a212013-02-20 04:06:32 +00001785 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001786 ctrl_ext = er32(CTRL_EXT);
1787 ctrl_reg = er32(CTRL);
1788
1789 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1790 reg |= E1000_CTRL_FRCSPD;
1791 ew32(CTRL, reg);
1792
1793 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001794 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001795 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001796 ew32(CTRL, ctrl_reg);
1797 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001798 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001799 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001800
Bruce Allan5015e532012-02-08 02:55:56 +00001801 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001802}
1803
1804/**
Bruce Allanf523d212009-10-29 13:45:45 +00001805 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1806 * @hw: pointer to the HW structure
1807 * @d0_state: boolean if entering d0 or d3 device state
1808 *
1809 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1810 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1811 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1812 **/
1813static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1814{
1815 s32 ret_val = 0;
1816 u32 mac_reg;
1817 u16 oem_reg;
1818
Bruce Allan2fbe4522012-04-19 03:21:47 +00001819 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001820 return ret_val;
1821
Bruce Allan94d81862009-11-20 23:25:26 +00001822 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001823 if (ret_val)
1824 return ret_val;
1825
Bruce Allan2fbe4522012-04-19 03:21:47 +00001826 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001827 mac_reg = er32(EXTCNF_CTRL);
1828 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001829 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001830 }
Bruce Allanf523d212009-10-29 13:45:45 +00001831
1832 mac_reg = er32(FEXTNVM);
1833 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001834 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001835
1836 mac_reg = er32(PHY_CTRL);
1837
Bruce Allanf1430d62012-04-14 04:21:52 +00001838 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001839 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001840 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001841
1842 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1843
1844 if (d0_state) {
1845 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1846 oem_reg |= HV_OEM_BITS_GBE_DIS;
1847
1848 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1849 oem_reg |= HV_OEM_BITS_LPLU;
1850 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001851 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1852 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001853 oem_reg |= HV_OEM_BITS_GBE_DIS;
1854
Bruce Allan03299e42011-09-30 08:07:05 +00001855 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1856 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001857 oem_reg |= HV_OEM_BITS_LPLU;
1858 }
Bruce Allan03299e42011-09-30 08:07:05 +00001859
Bruce Allan92fe1732012-04-12 06:27:03 +00001860 /* Set Restart auto-neg to activate the bits */
1861 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1862 !hw->phy.ops.check_reset_block(hw))
1863 oem_reg |= HV_OEM_BITS_RESTART_AN;
1864
Bruce Allanf1430d62012-04-14 04:21:52 +00001865 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001866
Bruce Allan75ce1532012-02-08 02:54:48 +00001867release:
Bruce Allan94d81862009-11-20 23:25:26 +00001868 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001869
1870 return ret_val;
1871}
1872
Bruce Allanf523d212009-10-29 13:45:45 +00001873/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001874 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1875 * @hw: pointer to the HW structure
1876 **/
1877static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1878{
1879 s32 ret_val;
1880 u16 data;
1881
1882 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1883 if (ret_val)
1884 return ret_val;
1885
1886 data |= HV_KMRN_MDIO_SLOW;
1887
1888 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1889
1890 return ret_val;
1891}
1892
1893/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001894 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1895 * done after every PHY reset.
1896 **/
1897static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1898{
1899 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001900 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001901
1902 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001903 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001904
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001905 /* Set MDIO slow mode before any other MDIO access */
1906 if (hw->phy.type == e1000_phy_82577) {
1907 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1908 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001909 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001910 }
1911
Bruce Allana4f58f52009-06-02 11:29:18 +00001912 if (((hw->phy.type == e1000_phy_82577) &&
1913 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1914 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1915 /* Disable generation of early preamble */
1916 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1917 if (ret_val)
1918 return ret_val;
1919
1920 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001921 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001922 if (ret_val)
1923 return ret_val;
1924 }
1925
1926 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001927 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001928 * writing 0x3140 to the control register.
1929 */
1930 if (hw->phy.revision < 2) {
1931 e1000e_phy_sw_reset(hw);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001932 ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
Bruce Allana4f58f52009-06-02 11:29:18 +00001933 }
1934 }
1935
1936 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001937 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001938 if (ret_val)
1939 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001940
Bruce Allana4f58f52009-06-02 11:29:18 +00001941 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001942 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001943 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001944 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001945 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001946
Bruce Allane921eb12012-11-28 09:28:37 +00001947 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001948 * link so that it disables K1 if link is in 1Gbps.
1949 */
1950 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001951 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001952 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001953
Bruce Allanbaf86c92010-01-13 01:53:08 +00001954 /* Workaround for link disconnects on a busy hub in half duplex */
1955 ret_val = hw->phy.ops.acquire(hw);
1956 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001957 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001958 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001959 if (ret_val)
1960 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001961 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001962 if (ret_val)
1963 goto release;
1964
1965 /* set MSE higher to enable link to stay up when noise is high */
1966 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001967release:
1968 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001969
Bruce Allana4f58f52009-06-02 11:29:18 +00001970 return ret_val;
1971}
1972
1973/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001974 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1975 * @hw: pointer to the HW structure
1976 **/
1977void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1978{
1979 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001980 u16 i, phy_reg = 0;
1981 s32 ret_val;
1982
1983 ret_val = hw->phy.ops.acquire(hw);
1984 if (ret_val)
1985 return;
1986 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1987 if (ret_val)
1988 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001989
David Ertmanc3a0dce2013-09-05 04:24:25 +00001990 /* Copy both RAL/H (rar_entry_count) and SHRAL/H to PHY */
1991 for (i = 0; i < (hw->mac.rar_entry_count); i++) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001992 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001993 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1994 (u16)(mac_reg & 0xFFFF));
1995 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1996 (u16)((mac_reg >> 16) & 0xFFFF));
1997
Bruce Alland3738bb2010-06-16 13:27:28 +00001998 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001999 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
2000 (u16)(mac_reg & 0xFFFF));
2001 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
2002 (u16)((mac_reg & E1000_RAH_AV)
2003 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00002004 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00002005
2006 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2007
2008release:
2009 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00002010}
2011
Bruce Alland3738bb2010-06-16 13:27:28 +00002012/**
2013 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
2014 * with 82579 PHY
2015 * @hw: pointer to the HW structure
2016 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
2017 **/
2018s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
2019{
2020 s32 ret_val = 0;
2021 u16 phy_reg, data;
2022 u32 mac_reg;
2023 u16 i;
2024
Bruce Allan2fbe4522012-04-19 03:21:47 +00002025 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002026 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002027
2028 /* disable Rx path while enabling/disabling workaround */
2029 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
2030 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
2031 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002032 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002033
2034 if (enable) {
David Ertmanc3a0dce2013-09-05 04:24:25 +00002035 /* Write Rx addresses (rar_entry_count for RAL/H, and
Bruce Alland3738bb2010-06-16 13:27:28 +00002036 * SHRAL/H) and initial CRC values to the MAC
2037 */
David Ertmanc3a0dce2013-09-05 04:24:25 +00002038 for (i = 0; i < hw->mac.rar_entry_count; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002039 u8 mac_addr[ETH_ALEN] = { 0 };
Bruce Alland3738bb2010-06-16 13:27:28 +00002040 u32 addr_high, addr_low;
2041
2042 addr_high = er32(RAH(i));
2043 if (!(addr_high & E1000_RAH_AV))
2044 continue;
2045 addr_low = er32(RAL(i));
2046 mac_addr[0] = (addr_low & 0xFF);
2047 mac_addr[1] = ((addr_low >> 8) & 0xFF);
2048 mac_addr[2] = ((addr_low >> 16) & 0xFF);
2049 mac_addr[3] = ((addr_low >> 24) & 0xFF);
2050 mac_addr[4] = (addr_high & 0xFF);
2051 mac_addr[5] = ((addr_high >> 8) & 0xFF);
2052
Bruce Allanfe46f582011-01-06 14:29:51 +00002053 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00002054 }
2055
2056 /* Write Rx addresses to the PHY */
2057 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
2058
2059 /* Enable jumbo frame workaround in the MAC */
2060 mac_reg = er32(FFLT_DBG);
2061 mac_reg &= ~(1 << 14);
2062 mac_reg |= (7 << 15);
2063 ew32(FFLT_DBG, mac_reg);
2064
2065 mac_reg = er32(RCTL);
2066 mac_reg |= E1000_RCTL_SECRC;
2067 ew32(RCTL, mac_reg);
2068
2069 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002070 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2071 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002072 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002073 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002074 ret_val = e1000e_write_kmrn_reg(hw,
2075 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2076 data | (1 << 0));
2077 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002078 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002079 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002080 E1000_KMRNCTRLSTA_HD_CTRL,
2081 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002082 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002083 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002084 data &= ~(0xF << 8);
2085 data |= (0xB << 8);
2086 ret_val = e1000e_write_kmrn_reg(hw,
2087 E1000_KMRNCTRLSTA_HD_CTRL,
2088 data);
2089 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002090 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002091
2092 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00002093 e1e_rphy(hw, PHY_REG(769, 23), &data);
2094 data &= ~(0x7F << 5);
2095 data |= (0x37 << 5);
2096 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2097 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002098 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002099 e1e_rphy(hw, PHY_REG(769, 16), &data);
2100 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00002101 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2102 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002103 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002104 e1e_rphy(hw, PHY_REG(776, 20), &data);
2105 data &= ~(0x3FF << 2);
2106 data |= (0x1A << 2);
2107 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2108 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002109 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00002110 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00002111 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002112 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002113 e1e_rphy(hw, HV_PM_CTRL, &data);
2114 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
2115 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002116 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002117 } else {
2118 /* Write MAC register values back to h/w defaults */
2119 mac_reg = er32(FFLT_DBG);
2120 mac_reg &= ~(0xF << 14);
2121 ew32(FFLT_DBG, mac_reg);
2122
2123 mac_reg = er32(RCTL);
2124 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00002125 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00002126
2127 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002128 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2129 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002130 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002131 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002132 ret_val = e1000e_write_kmrn_reg(hw,
2133 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2134 data & ~(1 << 0));
2135 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002136 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002137 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002138 E1000_KMRNCTRLSTA_HD_CTRL,
2139 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002140 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002141 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002142 data &= ~(0xF << 8);
2143 data |= (0xB << 8);
2144 ret_val = e1000e_write_kmrn_reg(hw,
2145 E1000_KMRNCTRLSTA_HD_CTRL,
2146 data);
2147 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002148 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002149
2150 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002151 e1e_rphy(hw, PHY_REG(769, 23), &data);
2152 data &= ~(0x7F << 5);
2153 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2154 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002155 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002156 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002157 data |= (1 << 13);
2158 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2159 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002160 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002161 e1e_rphy(hw, PHY_REG(776, 20), &data);
2162 data &= ~(0x3FF << 2);
2163 data |= (0x8 << 2);
2164 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2165 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002166 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002167 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2168 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002169 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002170 e1e_rphy(hw, HV_PM_CTRL, &data);
2171 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2172 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002173 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002174 }
2175
2176 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002177 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002178}
2179
2180/**
2181 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2182 * done after every PHY reset.
2183 **/
2184static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2185{
2186 s32 ret_val = 0;
2187
2188 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002189 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002190
2191 /* Set MDIO slow mode before any other MDIO access */
2192 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002193 if (ret_val)
2194 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002195
Bruce Allan4d241362011-12-16 00:46:06 +00002196 ret_val = hw->phy.ops.acquire(hw);
2197 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002198 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002199 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002200 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002201 if (ret_val)
2202 goto release;
2203 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002204 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002205release:
2206 hw->phy.ops.release(hw);
2207
Bruce Alland3738bb2010-06-16 13:27:28 +00002208 return ret_val;
2209}
2210
2211/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002212 * e1000_k1_gig_workaround_lv - K1 Si workaround
2213 * @hw: pointer to the HW structure
2214 *
2215 * Workaround to set the K1 beacon duration for 82579 parts
2216 **/
2217static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2218{
2219 s32 ret_val = 0;
2220 u16 status_reg = 0;
2221 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002222 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002223
2224 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002225 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002226
2227 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2228 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2229 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002230 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002231
2232 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2233 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2234 mac_reg = er32(FEXTNVM4);
2235 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2236
Bruce Allan0ed013e2011-07-29 05:52:56 +00002237 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2238 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002239 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002240
Bruce Allan0ed013e2011-07-29 05:52:56 +00002241 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002242 u16 pm_phy_reg;
2243
Bruce Allan0ed013e2011-07-29 05:52:56 +00002244 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2245 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002246 /* LV 1G Packet drop issue wa */
2247 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2248 if (ret_val)
2249 return ret_val;
2250 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2251 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2252 if (ret_val)
2253 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002254 } else {
2255 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2256 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2257 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002258 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002259 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002260 }
2261
Bruce Allan831bd2e2010-09-22 17:16:18 +00002262 return ret_val;
2263}
2264
2265/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002266 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2267 * @hw: pointer to the HW structure
2268 * @gate: boolean set to true to gate, false to ungate
2269 *
2270 * Gate/ungate the automatic PHY configuration via hardware; perform
2271 * the configuration via software instead.
2272 **/
2273static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2274{
2275 u32 extcnf_ctrl;
2276
Bruce Allan2fbe4522012-04-19 03:21:47 +00002277 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002278 return;
2279
2280 extcnf_ctrl = er32(EXTCNF_CTRL);
2281
2282 if (gate)
2283 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2284 else
2285 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2286
2287 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002288}
2289
2290/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002291 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2292 * @hw: pointer to the HW structure
2293 *
2294 * Check the appropriate indication the MAC has finished configuring the
2295 * PHY after a software reset.
2296 **/
2297static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2298{
2299 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2300
2301 /* Wait for basic configuration completes before proceeding */
2302 do {
2303 data = er32(STATUS);
2304 data &= E1000_STATUS_LAN_INIT_DONE;
Bruce Allance43a212013-02-20 04:06:32 +00002305 usleep_range(100, 200);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002306 } while ((!data) && --loop);
2307
Bruce Allane921eb12012-11-28 09:28:37 +00002308 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002309 * count reaches 0, loading the configuration from NVM will
2310 * leave the PHY in a bad state possibly resulting in no link.
2311 */
2312 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002313 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002314
2315 /* Clear the Init Done bit for the next init event */
2316 data = er32(STATUS);
2317 data &= ~E1000_STATUS_LAN_INIT_DONE;
2318 ew32(STATUS, data);
2319}
2320
2321/**
Bruce Allane98cac42010-05-10 15:02:32 +00002322 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002323 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002325static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002326{
Bruce Allanf523d212009-10-29 13:45:45 +00002327 s32 ret_val = 0;
2328 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002329
Bruce Allan44abd5c2012-02-22 09:02:37 +00002330 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002331 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002332
Bruce Allan5f3eed62010-09-22 17:15:54 +00002333 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002334 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002335
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002336 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002337 switch (hw->mac.type) {
2338 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002339 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2340 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002341 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002342 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002343 case e1000_pch2lan:
2344 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2345 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002346 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002347 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002348 default:
2349 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002350 }
2351
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002352 /* Clear the host wakeup bit after lcd reset */
2353 if (hw->mac.type >= e1000_pchlan) {
2354 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2355 reg &= ~BM_WUC_HOST_WU_BIT;
2356 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2357 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002358
Bruce Allanf523d212009-10-29 13:45:45 +00002359 /* Configure the LCD with the extended configuration region in NVM */
2360 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2361 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002362 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002363
Bruce Allanf523d212009-10-29 13:45:45 +00002364 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002365 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002366
Bruce Allan1effb452011-02-25 06:58:03 +00002367 if (hw->mac.type == e1000_pch2lan) {
2368 /* Ungate automatic PHY configuration on non-managed 82579 */
2369 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002370 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002371 e1000_gate_hw_phy_config_ich8lan(hw, false);
2372 }
2373
2374 /* Set EEE LPI Update Timer to 200usec */
2375 ret_val = hw->phy.ops.acquire(hw);
2376 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002377 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002378 ret_val = e1000_write_emi_reg_locked(hw,
2379 I82579_LPI_UPDATE_TIMER,
2380 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002381 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002382 }
2383
Bruce Allane98cac42010-05-10 15:02:32 +00002384 return ret_val;
2385}
2386
2387/**
2388 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2389 * @hw: pointer to the HW structure
2390 *
2391 * Resets the PHY
2392 * This is a function pointer entry point called by drivers
2393 * or other shared routines.
2394 **/
2395static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2396{
2397 s32 ret_val = 0;
2398
Bruce Allan605c82b2010-09-22 17:17:01 +00002399 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2400 if ((hw->mac.type == e1000_pch2lan) &&
2401 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2402 e1000_gate_hw_phy_config_ich8lan(hw, true);
2403
Bruce Allane98cac42010-05-10 15:02:32 +00002404 ret_val = e1000e_phy_hw_reset_generic(hw);
2405 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002406 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002407
Bruce Allan5015e532012-02-08 02:55:56 +00002408 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002409}
2410
2411/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002412 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2413 * @hw: pointer to the HW structure
2414 * @active: true to enable LPLU, false to disable
2415 *
2416 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2417 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2418 * the phy speed. This function will manually set the LPLU bit and restart
2419 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2420 * since it configures the same bit.
2421 **/
2422static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2423{
Bruce Allan70806a72013-01-05 05:08:37 +00002424 s32 ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002425 u16 oem_reg;
2426
2427 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2428 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002429 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002430
2431 if (active)
2432 oem_reg |= HV_OEM_BITS_LPLU;
2433 else
2434 oem_reg &= ~HV_OEM_BITS_LPLU;
2435
Bruce Allan44abd5c2012-02-22 09:02:37 +00002436 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002437 oem_reg |= HV_OEM_BITS_RESTART_AN;
2438
Bruce Allan5015e532012-02-08 02:55:56 +00002439 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002440}
2441
2442/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002443 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2444 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002445 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002446 *
2447 * Sets the LPLU D0 state according to the active flag. When
2448 * activating LPLU this function also disables smart speed
2449 * and vice versa. LPLU will not be activated unless the
2450 * device autonegotiation advertisement meets standards of
2451 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2452 * This is a function pointer entry point only called by
2453 * PHY setup routines.
2454 **/
2455static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2456{
2457 struct e1000_phy_info *phy = &hw->phy;
2458 u32 phy_ctrl;
2459 s32 ret_val = 0;
2460 u16 data;
2461
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002462 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002463 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002464
2465 phy_ctrl = er32(PHY_CTRL);
2466
2467 if (active) {
2468 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2469 ew32(PHY_CTRL, phy_ctrl);
2470
Bruce Allan60f12922009-07-01 13:28:14 +00002471 if (phy->type != e1000_phy_igp_3)
2472 return 0;
2473
Bruce Allane921eb12012-11-28 09:28:37 +00002474 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002475 * any PHY registers
2476 */
Bruce Allan60f12922009-07-01 13:28:14 +00002477 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002478 e1000e_gig_downshift_workaround_ich8lan(hw);
2479
2480 /* When LPLU is enabled, we should disable SmartSpeed */
2481 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00002482 if (ret_val)
2483 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002484 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2485 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2486 if (ret_val)
2487 return ret_val;
2488 } else {
2489 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2490 ew32(PHY_CTRL, phy_ctrl);
2491
Bruce Allan60f12922009-07-01 13:28:14 +00002492 if (phy->type != e1000_phy_igp_3)
2493 return 0;
2494
Bruce Allane921eb12012-11-28 09:28:37 +00002495 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002496 * during Dx states where the power conservation is most
2497 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002498 * SmartSpeed, so performance is maintained.
2499 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002500 if (phy->smart_speed == e1000_smart_speed_on) {
2501 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002502 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002503 if (ret_val)
2504 return ret_val;
2505
2506 data |= IGP01E1000_PSCFR_SMART_SPEED;
2507 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002508 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002509 if (ret_val)
2510 return ret_val;
2511 } else if (phy->smart_speed == e1000_smart_speed_off) {
2512 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002513 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002514 if (ret_val)
2515 return ret_val;
2516
2517 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2518 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002519 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 if (ret_val)
2521 return ret_val;
2522 }
2523 }
2524
2525 return 0;
2526}
2527
2528/**
2529 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2530 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002531 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002532 *
2533 * Sets the LPLU D3 state according to the active flag. When
2534 * activating LPLU this function also disables smart speed
2535 * and vice versa. LPLU will not be activated unless the
2536 * device autonegotiation advertisement meets standards of
2537 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2538 * This is a function pointer entry point only called by
2539 * PHY setup routines.
2540 **/
2541static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2542{
2543 struct e1000_phy_info *phy = &hw->phy;
2544 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002545 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002546 u16 data;
2547
2548 phy_ctrl = er32(PHY_CTRL);
2549
2550 if (!active) {
2551 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2552 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002553
2554 if (phy->type != e1000_phy_igp_3)
2555 return 0;
2556
Bruce Allane921eb12012-11-28 09:28:37 +00002557 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002558 * during Dx states where the power conservation is most
2559 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002560 * SmartSpeed, so performance is maintained.
2561 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002562 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002563 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2564 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002565 if (ret_val)
2566 return ret_val;
2567
2568 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002569 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2570 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002571 if (ret_val)
2572 return ret_val;
2573 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002574 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2575 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002576 if (ret_val)
2577 return ret_val;
2578
2579 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002580 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2581 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002582 if (ret_val)
2583 return ret_val;
2584 }
2585 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2586 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2587 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2588 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2589 ew32(PHY_CTRL, phy_ctrl);
2590
Bruce Allan60f12922009-07-01 13:28:14 +00002591 if (phy->type != e1000_phy_igp_3)
2592 return 0;
2593
Bruce Allane921eb12012-11-28 09:28:37 +00002594 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002595 * any PHY registers
2596 */
Bruce Allan60f12922009-07-01 13:28:14 +00002597 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002598 e1000e_gig_downshift_workaround_ich8lan(hw);
2599
2600 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002601 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002602 if (ret_val)
2603 return ret_val;
2604
2605 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002606 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002607 }
2608
Bruce Alland7eb3382012-02-08 02:55:14 +00002609 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002610}
2611
2612/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002613 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2614 * @hw: pointer to the HW structure
2615 * @bank: pointer to the variable that returns the active bank
2616 *
2617 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002618 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002619 **/
2620static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2621{
Bruce Allane2434552008-11-21 17:02:41 -08002622 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002623 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002624 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2625 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002626 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002627 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002628
Bruce Allane2434552008-11-21 17:02:41 -08002629 switch (hw->mac.type) {
2630 case e1000_ich8lan:
2631 case e1000_ich9lan:
2632 eecd = er32(EECD);
2633 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2634 E1000_EECD_SEC1VAL_VALID_MASK) {
2635 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002636 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002637 else
2638 *bank = 0;
2639
2640 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002641 }
Bruce Allan434f1392011-12-16 00:46:54 +00002642 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002643 /* fall-thru */
2644 default:
2645 /* set bank to 0 in case flash read fails */
2646 *bank = 0;
2647
2648 /* Check bank 0 */
2649 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002650 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002651 if (ret_val)
2652 return ret_val;
2653 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2654 E1000_ICH_NVM_SIG_VALUE) {
2655 *bank = 0;
2656 return 0;
2657 }
2658
2659 /* Check bank 1 */
2660 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002661 bank1_offset,
2662 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002663 if (ret_val)
2664 return ret_val;
2665 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2666 E1000_ICH_NVM_SIG_VALUE) {
2667 *bank = 1;
2668 return 0;
2669 }
2670
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002671 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002672 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002673 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002674}
2675
2676/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002677 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2678 * @hw: pointer to the HW structure
2679 * @offset: The offset (in bytes) of the word(s) to read.
2680 * @words: Size of data to read in words
2681 * @data: Pointer to the word(s) to read at offset.
2682 *
2683 * Reads a word(s) from the NVM using the flash access registers.
2684 **/
2685static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2686 u16 *data)
2687{
2688 struct e1000_nvm_info *nvm = &hw->nvm;
2689 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2690 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002691 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002692 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002693 u16 i, word;
2694
2695 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2696 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002697 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002698 ret_val = -E1000_ERR_NVM;
2699 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002700 }
2701
Bruce Allan94d81862009-11-20 23:25:26 +00002702 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703
Bruce Allanf4187b52008-08-26 18:36:50 -07002704 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002705 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002706 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002707 bank = 0;
2708 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002709
2710 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002711 act_offset += offset;
2712
Bruce Allan148675a2009-08-07 07:41:56 +00002713 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002714 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002715 if (dev_spec->shadow_ram[offset + i].modified) {
2716 data[i] = dev_spec->shadow_ram[offset + i].value;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002717 } else {
2718 ret_val = e1000_read_flash_word_ich8lan(hw,
2719 act_offset + i,
2720 &word);
2721 if (ret_val)
2722 break;
2723 data[i] = word;
2724 }
2725 }
2726
Bruce Allan94d81862009-11-20 23:25:26 +00002727 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002728
Bruce Allane2434552008-11-21 17:02:41 -08002729out:
2730 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002731 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002732
Auke Kokbc7f75f2007-09-17 12:30:59 -07002733 return ret_val;
2734}
2735
2736/**
2737 * e1000_flash_cycle_init_ich8lan - Initialize flash
2738 * @hw: pointer to the HW structure
2739 *
2740 * This function does initial flash setup so that a new read/write/erase cycle
2741 * can be started.
2742 **/
2743static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2744{
2745 union ich8_hws_flash_status hsfsts;
2746 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002747
2748 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2749
2750 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002751 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002752 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002753 return -E1000_ERR_NVM;
2754 }
2755
2756 /* Clear FCERR and DAEL in hw status by writing 1 */
2757 hsfsts.hsf_status.flcerr = 1;
2758 hsfsts.hsf_status.dael = 1;
2759
2760 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2761
Bruce Allane921eb12012-11-28 09:28:37 +00002762 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002763 * bit to check against, in order to start a new cycle or
2764 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002765 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002766 * indication whether a cycle is in progress or has been
2767 * completed.
2768 */
2769
Bruce Allan04499ec2012-04-13 00:08:31 +00002770 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002771 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002772 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002773 * Begin by setting Flash Cycle Done.
2774 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002775 hsfsts.hsf_status.flcdone = 1;
2776 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2777 ret_val = 0;
2778 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002779 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002780
Bruce Allane921eb12012-11-28 09:28:37 +00002781 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002782 * cycle has a chance to end before giving up.
2783 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002784 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002785 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002786 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002787 ret_val = 0;
2788 break;
2789 }
2790 udelay(1);
2791 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002792 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002793 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002794 * now set the Flash Cycle Done.
2795 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002796 hsfsts.hsf_status.flcdone = 1;
2797 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2798 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002799 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002800 }
2801 }
2802
2803 return ret_val;
2804}
2805
2806/**
2807 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2808 * @hw: pointer to the HW structure
2809 * @timeout: maximum time to wait for completion
2810 *
2811 * This function starts a flash cycle and waits for its completion.
2812 **/
2813static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2814{
2815 union ich8_hws_flash_ctrl hsflctl;
2816 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002817 u32 i = 0;
2818
2819 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2820 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2821 hsflctl.hsf_ctrl.flcgo = 1;
2822 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2823
2824 /* wait till FDONE bit is set to 1 */
2825 do {
2826 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002827 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002828 break;
2829 udelay(1);
2830 } while (i++ < timeout);
2831
Bruce Allan04499ec2012-04-13 00:08:31 +00002832 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002833 return 0;
2834
Bruce Allan55920b52012-02-08 02:55:25 +00002835 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836}
2837
2838/**
2839 * e1000_read_flash_word_ich8lan - Read word from flash
2840 * @hw: pointer to the HW structure
2841 * @offset: offset to data location
2842 * @data: pointer to the location for storing the data
2843 *
2844 * Reads the flash word at offset into data. Offset is converted
2845 * to bytes before read.
2846 **/
2847static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2848 u16 *data)
2849{
2850 /* Must convert offset into bytes. */
2851 offset <<= 1;
2852
2853 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2854}
2855
2856/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002857 * e1000_read_flash_byte_ich8lan - Read byte from flash
2858 * @hw: pointer to the HW structure
2859 * @offset: The offset of the byte to read.
2860 * @data: Pointer to a byte to store the value read.
2861 *
2862 * Reads a single byte from the NVM using the flash access registers.
2863 **/
2864static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2865 u8 *data)
2866{
2867 s32 ret_val;
2868 u16 word = 0;
2869
2870 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2871 if (ret_val)
2872 return ret_val;
2873
2874 *data = (u8)word;
2875
2876 return 0;
2877}
2878
2879/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002880 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2881 * @hw: pointer to the HW structure
2882 * @offset: The offset (in bytes) of the byte or word to read.
2883 * @size: Size of data to read, 1=byte 2=word
2884 * @data: Pointer to the word to store the value read.
2885 *
2886 * Reads a byte or word from the NVM using the flash access registers.
2887 **/
2888static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2889 u8 size, u16 *data)
2890{
2891 union ich8_hws_flash_status hsfsts;
2892 union ich8_hws_flash_ctrl hsflctl;
2893 u32 flash_linear_addr;
2894 u32 flash_data = 0;
2895 s32 ret_val = -E1000_ERR_NVM;
2896 u8 count = 0;
2897
Bruce Allane80bd1d2013-05-01 01:19:46 +00002898 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002899 return -E1000_ERR_NVM;
2900
Bruce Allanf0ff4392013-02-20 04:05:39 +00002901 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2902 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002903
2904 do {
2905 udelay(1);
2906 /* Steps */
2907 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002908 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002909 break;
2910
2911 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2912 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2913 hsflctl.hsf_ctrl.fldbcount = size - 1;
2914 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2915 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2916
2917 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2918
Bruce Allan17e813e2013-02-20 04:06:01 +00002919 ret_val =
2920 e1000_flash_cycle_ich8lan(hw,
2921 ICH_FLASH_READ_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002922
Bruce Allane921eb12012-11-28 09:28:37 +00002923 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002924 * and try the whole sequence a few more times, else
2925 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002926 * least significant byte first msb to lsb
2927 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002928 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002929 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002930 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002931 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002932 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002933 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002934 break;
2935 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002936 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002937 * completely hosed, but if the error condition is
2938 * detected, it won't hurt to give it another try...
2939 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2940 */
2941 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002942 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002943 /* Repeat for some time before giving up. */
2944 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002945 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002946 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947 break;
2948 }
2949 }
2950 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2951
2952 return ret_val;
2953}
2954
2955/**
2956 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2957 * @hw: pointer to the HW structure
2958 * @offset: The offset (in bytes) of the word(s) to write.
2959 * @words: Size of data to write in words
2960 * @data: Pointer to the word(s) to write at offset.
2961 *
2962 * Writes a byte or word to the NVM using the flash access registers.
2963 **/
2964static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2965 u16 *data)
2966{
2967 struct e1000_nvm_info *nvm = &hw->nvm;
2968 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002969 u16 i;
2970
2971 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2972 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002973 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974 return -E1000_ERR_NVM;
2975 }
2976
Bruce Allan94d81862009-11-20 23:25:26 +00002977 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002978
Auke Kokbc7f75f2007-09-17 12:30:59 -07002979 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002980 dev_spec->shadow_ram[offset + i].modified = true;
2981 dev_spec->shadow_ram[offset + i].value = data[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07002982 }
2983
Bruce Allan94d81862009-11-20 23:25:26 +00002984 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002985
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986 return 0;
2987}
2988
2989/**
2990 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2991 * @hw: pointer to the HW structure
2992 *
2993 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2994 * which writes the checksum to the shadow ram. The changes in the shadow
2995 * ram are then committed to the EEPROM by processing each bank at a time
2996 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002997 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002998 * future writes.
2999 **/
3000static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
3001{
3002 struct e1000_nvm_info *nvm = &hw->nvm;
3003 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07003004 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003005 s32 ret_val;
3006 u16 data;
3007
3008 ret_val = e1000e_update_nvm_checksum_generic(hw);
3009 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08003010 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003011
3012 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08003013 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003014
Bruce Allan94d81862009-11-20 23:25:26 +00003015 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003016
Bruce Allane921eb12012-11-28 09:28:37 +00003017 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003018 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07003019 * is going to be written
3020 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00003021 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08003022 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003023 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00003024 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003025 }
Bruce Allanf4187b52008-08-26 18:36:50 -07003026
3027 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003028 new_bank_offset = nvm->flash_bank_size;
3029 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003030 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003031 if (ret_val)
3032 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003033 } else {
3034 old_bank_offset = nvm->flash_bank_size;
3035 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08003036 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003037 if (ret_val)
3038 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003039 }
3040
3041 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00003042 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07003043 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07003044 * in the shadow RAM
3045 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003046 if (dev_spec->shadow_ram[i].modified) {
3047 data = dev_spec->shadow_ram[i].value;
3048 } else {
Bruce Allane2434552008-11-21 17:02:41 -08003049 ret_val = e1000_read_flash_word_ich8lan(hw, i +
Bruce Allanf0ff4392013-02-20 04:05:39 +00003050 old_bank_offset,
3051 &data);
Bruce Allane2434552008-11-21 17:02:41 -08003052 if (ret_val)
3053 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003054 }
3055
Bruce Allane921eb12012-11-28 09:28:37 +00003056 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07003057 * (15:14) are 11b until the commit has completed.
3058 * This will allow us to write 10b which indicates the
3059 * signature is valid. We want to do this after the write
3060 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07003061 * while the write is still in progress
3062 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003063 if (i == E1000_ICH_NVM_SIG_WORD)
3064 data |= E1000_ICH_NVM_SIG_MASK;
3065
3066 /* Convert offset to bytes. */
3067 act_offset = (i + new_bank_offset) << 1;
3068
Bruce Allance43a212013-02-20 04:06:32 +00003069 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003070 /* Write the bytes to the new bank. */
3071 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3072 act_offset,
3073 (u8)data);
3074 if (ret_val)
3075 break;
3076
Bruce Allance43a212013-02-20 04:06:32 +00003077 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003078 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003079 act_offset + 1,
3080 (u8)(data >> 8));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003081 if (ret_val)
3082 break;
3083 }
3084
Bruce Allane921eb12012-11-28 09:28:37 +00003085 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07003086 * programming failed.
3087 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003088 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07003089 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003090 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00003091 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003092 }
3093
Bruce Allane921eb12012-11-28 09:28:37 +00003094 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07003095 * to 10b in word 0x13 , this can be done without an
3096 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07003097 * and we need to change bit 14 to 0b
3098 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003099 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08003100 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003101 if (ret_val)
3102 goto release;
3103
Auke Kokbc7f75f2007-09-17 12:30:59 -07003104 data &= 0xBFFF;
3105 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3106 act_offset * 2 + 1,
3107 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00003108 if (ret_val)
3109 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003110
Bruce Allane921eb12012-11-28 09:28:37 +00003111 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07003112 * its signature word (0x13) high_byte to 0b. This can be
3113 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07003114 * to 1's. We can write 1's to 0's without an erase
3115 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003116 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
3117 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003118 if (ret_val)
3119 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003120
3121 /* Great! Everything worked, we can now clear the cached entries. */
3122 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00003123 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003124 dev_spec->shadow_ram[i].value = 0xFFFF;
3125 }
3126
Bruce Allan9c5e2092010-05-10 15:00:31 +00003127release:
Bruce Allan94d81862009-11-20 23:25:26 +00003128 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003129
Bruce Allane921eb12012-11-28 09:28:37 +00003130 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07003131 * until after the next adapter reset.
3132 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00003133 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00003134 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00003135 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003136 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003137
Bruce Allane2434552008-11-21 17:02:41 -08003138out:
3139 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003140 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003141
Auke Kokbc7f75f2007-09-17 12:30:59 -07003142 return ret_val;
3143}
3144
3145/**
3146 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3147 * @hw: pointer to the HW structure
3148 *
3149 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3150 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3151 * calculated, in which case we need to calculate the checksum and set bit 6.
3152 **/
3153static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3154{
3155 s32 ret_val;
3156 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003157 u16 word;
3158 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003159
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003160 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3161 * the checksum needs to be fixed. This bit is an indication that
3162 * the NVM was prepared by OEM software and did not calculate
3163 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003164 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003165 switch (hw->mac.type) {
3166 case e1000_pch_lpt:
3167 word = NVM_COMPAT;
3168 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3169 break;
3170 default:
3171 word = NVM_FUTURE_INIT_WORD1;
3172 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3173 break;
3174 }
3175
3176 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003177 if (ret_val)
3178 return ret_val;
3179
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003180 if (!(data & valid_csum_mask)) {
3181 data |= valid_csum_mask;
3182 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003183 if (ret_val)
3184 return ret_val;
3185 ret_val = e1000e_update_nvm_checksum(hw);
3186 if (ret_val)
3187 return ret_val;
3188 }
3189
3190 return e1000e_validate_nvm_checksum_generic(hw);
3191}
3192
3193/**
Bruce Allan4a770352008-10-01 17:18:35 -07003194 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3195 * @hw: pointer to the HW structure
3196 *
3197 * To prevent malicious write/erase of the NVM, set it to be read-only
3198 * so that the hardware ignores all write/erase cycles of the NVM via
3199 * the flash control registers. The shadow-ram copy of the NVM will
3200 * still be updated, however any updates to this copy will not stick
3201 * across driver reloads.
3202 **/
3203void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3204{
Bruce Allanca15df52009-10-26 11:23:43 +00003205 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003206 union ich8_flash_protected_range pr0;
3207 union ich8_hws_flash_status hsfsts;
3208 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003209
Bruce Allan94d81862009-11-20 23:25:26 +00003210 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003211
3212 gfpreg = er32flash(ICH_FLASH_GFPREG);
3213
3214 /* Write-protect GbE Sector of NVM */
3215 pr0.regval = er32flash(ICH_FLASH_PR0);
3216 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3217 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3218 pr0.range.wpe = true;
3219 ew32flash(ICH_FLASH_PR0, pr0.regval);
3220
Bruce Allane921eb12012-11-28 09:28:37 +00003221 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003222 * PR0 to prevent the write-protection from being lifted.
3223 * Once FLOCKDN is set, the registers protected by it cannot
3224 * be written until FLOCKDN is cleared by a hardware reset.
3225 */
3226 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3227 hsfsts.hsf_status.flockdn = true;
3228 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3229
Bruce Allan94d81862009-11-20 23:25:26 +00003230 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003231}
3232
3233/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003234 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3235 * @hw: pointer to the HW structure
3236 * @offset: The offset (in bytes) of the byte/word to read.
3237 * @size: Size of data to read, 1=byte 2=word
3238 * @data: The byte(s) to write to the NVM.
3239 *
3240 * Writes one/two bytes to the NVM using the flash access registers.
3241 **/
3242static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3243 u8 size, u16 data)
3244{
3245 union ich8_hws_flash_status hsfsts;
3246 union ich8_hws_flash_ctrl hsflctl;
3247 u32 flash_linear_addr;
3248 u32 flash_data = 0;
3249 s32 ret_val;
3250 u8 count = 0;
3251
3252 if (size < 1 || size > 2 || data > size * 0xff ||
3253 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3254 return -E1000_ERR_NVM;
3255
Bruce Allanf0ff4392013-02-20 04:05:39 +00003256 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3257 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003258
3259 do {
3260 udelay(1);
3261 /* Steps */
3262 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3263 if (ret_val)
3264 break;
3265
3266 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3267 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
Bruce Allan362e20c2013-02-20 04:05:45 +00003268 hsflctl.hsf_ctrl.fldbcount = size - 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003269 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3270 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3271
3272 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3273
3274 if (size == 1)
3275 flash_data = (u32)data & 0x00FF;
3276 else
3277 flash_data = (u32)data;
3278
3279 ew32flash(ICH_FLASH_FDATA0, flash_data);
3280
Bruce Allane921eb12012-11-28 09:28:37 +00003281 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003282 * and try the whole sequence a few more times else done
3283 */
Bruce Allan17e813e2013-02-20 04:06:01 +00003284 ret_val =
3285 e1000_flash_cycle_ich8lan(hw,
3286 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003287 if (!ret_val)
3288 break;
3289
Bruce Allane921eb12012-11-28 09:28:37 +00003290 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003291 * completely hosed, but if the error condition
3292 * is detected, it won't hurt to give it another
3293 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3294 */
3295 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003296 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003297 /* Repeat for some time before giving up. */
3298 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003299 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003300 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003301 break;
3302 }
3303 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3304
3305 return ret_val;
3306}
3307
3308/**
3309 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3310 * @hw: pointer to the HW structure
3311 * @offset: The index of the byte to read.
3312 * @data: The byte to write to the NVM.
3313 *
3314 * Writes a single byte to the NVM using the flash access registers.
3315 **/
3316static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3317 u8 data)
3318{
3319 u16 word = (u16)data;
3320
3321 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3322}
3323
3324/**
3325 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3326 * @hw: pointer to the HW structure
3327 * @offset: The offset of the byte to write.
3328 * @byte: The byte to write to the NVM.
3329 *
3330 * Writes a single byte to the NVM using the flash access registers.
3331 * Goes through a retry algorithm before giving up.
3332 **/
3333static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3334 u32 offset, u8 byte)
3335{
3336 s32 ret_val;
3337 u16 program_retries;
3338
3339 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3340 if (!ret_val)
3341 return ret_val;
3342
3343 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003344 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Bruce Allance43a212013-02-20 04:06:32 +00003345 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003346 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3347 if (!ret_val)
3348 break;
3349 }
3350 if (program_retries == 100)
3351 return -E1000_ERR_NVM;
3352
3353 return 0;
3354}
3355
3356/**
3357 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3358 * @hw: pointer to the HW structure
3359 * @bank: 0 for first bank, 1 for second bank, etc.
3360 *
3361 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3362 * bank N is 4096 * N + flash_reg_addr.
3363 **/
3364static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3365{
3366 struct e1000_nvm_info *nvm = &hw->nvm;
3367 union ich8_hws_flash_status hsfsts;
3368 union ich8_hws_flash_ctrl hsflctl;
3369 u32 flash_linear_addr;
3370 /* bank size is in 16bit words - adjust to bytes */
3371 u32 flash_bank_size = nvm->flash_bank_size * 2;
3372 s32 ret_val;
3373 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003374 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003375
3376 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3377
Bruce Allane921eb12012-11-28 09:28:37 +00003378 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003379 * register
3380 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381 * consecutive sectors. The start index for the nth Hw sector
3382 * can be calculated as = bank * 4096 + n * 256
3383 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3384 * The start index for the nth Hw sector can be calculated
3385 * as = bank * 4096
3386 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3387 * (ich9 only, otherwise error condition)
3388 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3389 */
3390 switch (hsfsts.hsf_status.berasesz) {
3391 case 0:
3392 /* Hw sector size 256 */
3393 sector_size = ICH_FLASH_SEG_SIZE_256;
3394 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3395 break;
3396 case 1:
3397 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003398 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003399 break;
3400 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003401 sector_size = ICH_FLASH_SEG_SIZE_8K;
3402 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003403 break;
3404 case 3:
3405 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003406 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003407 break;
3408 default:
3409 return -E1000_ERR_NVM;
3410 }
3411
3412 /* Start with the base address, then add the sector offset. */
3413 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003414 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003415
Bruce Allan53aa82d2013-02-20 04:06:06 +00003416 for (j = 0; j < iteration; j++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003417 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00003418 u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
3419
Auke Kokbc7f75f2007-09-17 12:30:59 -07003420 /* Steps */
3421 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3422 if (ret_val)
3423 return ret_val;
3424
Bruce Allane921eb12012-11-28 09:28:37 +00003425 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003426 * Cycle field in hw flash control
3427 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003428 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3429 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3430 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3431
Bruce Allane921eb12012-11-28 09:28:37 +00003432 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003433 * block into Flash Linear address field in Flash
3434 * Address.
3435 */
3436 flash_linear_addr += (j * sector_size);
3437 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3438
Bruce Allan17e813e2013-02-20 04:06:01 +00003439 ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003440 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003441 break;
3442
Bruce Allane921eb12012-11-28 09:28:37 +00003443 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003444 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003445 * a few more times else Done
3446 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003447 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003448 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003449 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003450 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003451 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003452 return ret_val;
3453 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3454 }
3455
3456 return 0;
3457}
3458
3459/**
3460 * e1000_valid_led_default_ich8lan - Set the default LED settings
3461 * @hw: pointer to the HW structure
3462 * @data: Pointer to the LED settings
3463 *
3464 * Reads the LED default settings from the NVM to data. If the NVM LED
3465 * settings is all 0's or F's, set the LED default to a valid LED default
3466 * setting.
3467 **/
3468static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3469{
3470 s32 ret_val;
3471
3472 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3473 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003474 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003475 return ret_val;
3476 }
3477
Bruce Allane5fe2542013-02-20 04:06:27 +00003478 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003479 *data = ID_LED_DEFAULT_ICH8LAN;
3480
3481 return 0;
3482}
3483
3484/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003485 * e1000_id_led_init_pchlan - store LED configurations
3486 * @hw: pointer to the HW structure
3487 *
3488 * PCH does not control LEDs via the LEDCTL register, rather it uses
3489 * the PHY LED configuration register.
3490 *
3491 * PCH also does not have an "always on" or "always off" mode which
3492 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003493 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003494 * use "link_up" mode. The LEDs will still ID on request if there is no
3495 * link based on logic in e1000_led_[on|off]_pchlan().
3496 **/
3497static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3498{
3499 struct e1000_mac_info *mac = &hw->mac;
3500 s32 ret_val;
3501 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3502 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3503 u16 data, i, temp, shift;
3504
3505 /* Get default ID LED modes */
3506 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3507 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003508 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003509
3510 mac->ledctl_default = er32(LEDCTL);
3511 mac->ledctl_mode1 = mac->ledctl_default;
3512 mac->ledctl_mode2 = mac->ledctl_default;
3513
3514 for (i = 0; i < 4; i++) {
3515 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3516 shift = (i * 5);
3517 switch (temp) {
3518 case ID_LED_ON1_DEF2:
3519 case ID_LED_ON1_ON2:
3520 case ID_LED_ON1_OFF2:
3521 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3522 mac->ledctl_mode1 |= (ledctl_on << shift);
3523 break;
3524 case ID_LED_OFF1_DEF2:
3525 case ID_LED_OFF1_ON2:
3526 case ID_LED_OFF1_OFF2:
3527 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3528 mac->ledctl_mode1 |= (ledctl_off << shift);
3529 break;
3530 default:
3531 /* Do nothing */
3532 break;
3533 }
3534 switch (temp) {
3535 case ID_LED_DEF1_ON2:
3536 case ID_LED_ON1_ON2:
3537 case ID_LED_OFF1_ON2:
3538 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3539 mac->ledctl_mode2 |= (ledctl_on << shift);
3540 break;
3541 case ID_LED_DEF1_OFF2:
3542 case ID_LED_ON1_OFF2:
3543 case ID_LED_OFF1_OFF2:
3544 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3545 mac->ledctl_mode2 |= (ledctl_off << shift);
3546 break;
3547 default:
3548 /* Do nothing */
3549 break;
3550 }
3551 }
3552
Bruce Allan5015e532012-02-08 02:55:56 +00003553 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003554}
3555
3556/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003557 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3558 * @hw: pointer to the HW structure
3559 *
3560 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3561 * register, so the the bus width is hard coded.
3562 **/
3563static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3564{
3565 struct e1000_bus_info *bus = &hw->bus;
3566 s32 ret_val;
3567
3568 ret_val = e1000e_get_bus_info_pcie(hw);
3569
Bruce Allane921eb12012-11-28 09:28:37 +00003570 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003571 * a configuration space, but do not contain
3572 * PCI Express Capability registers, so bus width
3573 * must be hardcoded.
3574 */
3575 if (bus->width == e1000_bus_width_unknown)
3576 bus->width = e1000_bus_width_pcie_x1;
3577
3578 return ret_val;
3579}
3580
3581/**
3582 * e1000_reset_hw_ich8lan - Reset the hardware
3583 * @hw: pointer to the HW structure
3584 *
3585 * Does a full reset of the hardware which includes a reset of the PHY and
3586 * MAC.
3587 **/
3588static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3589{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003590 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003591 u16 kum_cfg;
3592 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003593 s32 ret_val;
3594
Bruce Allane921eb12012-11-28 09:28:37 +00003595 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003596 * on the last TLP read/write transaction when MAC is reset.
3597 */
3598 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003599 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003600 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003601
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003602 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003603 ew32(IMC, 0xffffffff);
3604
Bruce Allane921eb12012-11-28 09:28:37 +00003605 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003606 * any pending transactions to complete before we hit the MAC
3607 * with the global reset.
3608 */
3609 ew32(RCTL, 0);
3610 ew32(TCTL, E1000_TCTL_PSP);
3611 e1e_flush();
3612
Bruce Allan1bba4382011-03-19 00:27:20 +00003613 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003614
3615 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3616 if (hw->mac.type == e1000_ich8lan) {
3617 /* Set Tx and Rx buffer allocation to 8k apiece. */
3618 ew32(PBA, E1000_PBA_8K);
3619 /* Set Packet Buffer Size to 16k. */
3620 ew32(PBS, E1000_PBS_16K);
3621 }
3622
Bruce Allan1d5846b2009-10-29 13:46:05 +00003623 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003624 /* Save the NVM K1 bit setting */
3625 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003626 if (ret_val)
3627 return ret_val;
3628
Bruce Allan62bc8132012-03-20 03:47:57 +00003629 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003630 dev_spec->nvm_k1_enabled = true;
3631 else
3632 dev_spec->nvm_k1_enabled = false;
3633 }
3634
Auke Kokbc7f75f2007-09-17 12:30:59 -07003635 ctrl = er32(CTRL);
3636
Bruce Allan44abd5c2012-02-22 09:02:37 +00003637 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003638 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003639 * time to make sure the interface between MAC and the
3640 * external PHY is reset.
3641 */
3642 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003643
Bruce Allane921eb12012-11-28 09:28:37 +00003644 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003645 * non-managed 82579
3646 */
3647 if ((hw->mac.type == e1000_pch2lan) &&
3648 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3649 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003650 }
3651 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003652 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003653 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003654 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003655 msleep(20);
3656
Bruce Allan62bc8132012-03-20 03:47:57 +00003657 /* Set Phy Config Counter to 50msec */
3658 if (hw->mac.type == e1000_pch2lan) {
3659 reg = er32(FEXTNVM3);
3660 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3661 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3662 ew32(FEXTNVM3, reg);
3663 }
3664
Bruce Allanfc0c7762009-07-01 13:27:55 +00003665 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003666 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003667
Bruce Allane98cac42010-05-10 15:02:32 +00003668 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003669 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003670 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003671 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003672
Bruce Allane98cac42010-05-10 15:02:32 +00003673 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003674 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003675 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003676 }
Bruce Allane98cac42010-05-10 15:02:32 +00003677
Bruce Allane921eb12012-11-28 09:28:37 +00003678 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003679 * will be detected as a CRC error and be dropped rather than show up
3680 * as a bad packet to the DMA engine.
3681 */
3682 if (hw->mac.type == e1000_pchlan)
3683 ew32(CRC_OFFSET, 0x65656565);
3684
Auke Kokbc7f75f2007-09-17 12:30:59 -07003685 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003686 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003687
Bruce Allan62bc8132012-03-20 03:47:57 +00003688 reg = er32(KABGTXD);
3689 reg |= E1000_KABGTXD_BGSQLBIAS;
3690 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691
Bruce Allan5015e532012-02-08 02:55:56 +00003692 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003693}
3694
3695/**
3696 * e1000_init_hw_ich8lan - Initialize the hardware
3697 * @hw: pointer to the HW structure
3698 *
3699 * Prepares the hardware for transmit and receive by doing the following:
3700 * - initialize hardware bits
3701 * - initialize LED identification
3702 * - setup receive address registers
3703 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003704 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003705 * - clear statistics
3706 **/
3707static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3708{
3709 struct e1000_mac_info *mac = &hw->mac;
3710 u32 ctrl_ext, txdctl, snoop;
3711 s32 ret_val;
3712 u16 i;
3713
3714 e1000_initialize_hw_bits_ich8lan(hw);
3715
3716 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003717 ret_val = mac->ops.id_led_init(hw);
Bruce Allan33550ce2013-02-20 04:06:16 +00003718 /* An error is not fatal and we should not stop init due to this */
Bruce Allande39b752009-11-20 23:27:59 +00003719 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003720 e_dbg("Error initializing identification LED\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003721
3722 /* Setup the receive address. */
3723 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3724
3725 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003726 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003727 for (i = 0; i < mac->mta_reg_count; i++)
3728 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3729
Bruce Allane921eb12012-11-28 09:28:37 +00003730 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003731 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003732 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3733 */
3734 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003735 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3736 i &= ~BM_WUC_HOST_WU_BIT;
3737 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003738 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3739 if (ret_val)
3740 return ret_val;
3741 }
3742
Auke Kokbc7f75f2007-09-17 12:30:59 -07003743 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003744 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003745
3746 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003747 txdctl = er32(TXDCTL(0));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003748 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3749 E1000_TXDCTL_FULL_TX_DESC_WB);
3750 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3751 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003752 ew32(TXDCTL(0), txdctl);
3753 txdctl = er32(TXDCTL(1));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003754 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3755 E1000_TXDCTL_FULL_TX_DESC_WB);
3756 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3757 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003758 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759
Bruce Allane921eb12012-11-28 09:28:37 +00003760 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003761 * By default, we should use snoop behavior.
3762 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003763 if (mac->type == e1000_ich8lan)
3764 snoop = PCIE_ICH8_SNOOP_ALL;
3765 else
Bruce Allan53aa82d2013-02-20 04:06:06 +00003766 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003767 e1000e_set_pcie_no_snoop(hw, snoop);
3768
3769 ctrl_ext = er32(CTRL_EXT);
3770 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3771 ew32(CTRL_EXT, ctrl_ext);
3772
Bruce Allane921eb12012-11-28 09:28:37 +00003773 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003774 * important that we do this after we have tried to establish link
3775 * because the symbol error count will increment wildly if there
3776 * is no link.
3777 */
3778 e1000_clear_hw_cntrs_ich8lan(hw);
3779
Bruce Allane561a702012-02-08 02:55:46 +00003780 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003781}
Bruce Allanfc830b72013-02-20 04:06:11 +00003782
Auke Kokbc7f75f2007-09-17 12:30:59 -07003783/**
3784 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3785 * @hw: pointer to the HW structure
3786 *
3787 * Sets/Clears required hardware bits necessary for correctly setting up the
3788 * hardware for transmit and receive.
3789 **/
3790static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3791{
3792 u32 reg;
3793
3794 /* Extended Device Control */
3795 reg = er32(CTRL_EXT);
3796 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003797 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3798 if (hw->mac.type >= e1000_pchlan)
3799 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003800 ew32(CTRL_EXT, reg);
3801
3802 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003803 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003804 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003805 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003806
3807 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003808 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003809 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003810 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003811
3812 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003813 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003814 if (hw->mac.type == e1000_ich8lan)
3815 reg |= (1 << 28) | (1 << 29);
3816 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003817 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003818
3819 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003820 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003821 if (er32(TCTL) & E1000_TCTL_MULR)
3822 reg &= ~(1 << 28);
3823 else
3824 reg |= (1 << 28);
3825 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003826 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003827
3828 /* Device Status */
3829 if (hw->mac.type == e1000_ich8lan) {
3830 reg = er32(STATUS);
3831 reg &= ~(1 << 31);
3832 ew32(STATUS, reg);
3833 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003834
Bruce Allane921eb12012-11-28 09:28:37 +00003835 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003836 * traffic, just disable the nfs filtering capability
3837 */
3838 reg = er32(RFCTL);
3839 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003840
Bruce Allane921eb12012-11-28 09:28:37 +00003841 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003842 * IPv6 headers can hang the Rx.
3843 */
3844 if (hw->mac.type == e1000_ich8lan)
3845 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003846 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00003847
3848 /* Enable ECC on Lynxpoint */
3849 if (hw->mac.type == e1000_pch_lpt) {
3850 reg = er32(PBECCSTS);
3851 reg |= E1000_PBECCSTS_ECC_ENABLE;
3852 ew32(PBECCSTS, reg);
3853
3854 reg = er32(CTRL);
3855 reg |= E1000_CTRL_MEHE;
3856 ew32(CTRL, reg);
3857 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003858}
3859
3860/**
3861 * e1000_setup_link_ich8lan - Setup flow control and link settings
3862 * @hw: pointer to the HW structure
3863 *
3864 * Determines which flow control settings to use, then configures flow
3865 * control. Calls the appropriate media-specific link configuration
3866 * function. Assuming the adapter has a valid link partner, a valid link
3867 * should be established. Assumes the hardware has previously been reset
3868 * and the transmitter and receiver are not enabled.
3869 **/
3870static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3871{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003872 s32 ret_val;
3873
Bruce Allan44abd5c2012-02-22 09:02:37 +00003874 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003875 return 0;
3876
Bruce Allane921eb12012-11-28 09:28:37 +00003877 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003878 * the default flow control setting, so we explicitly
3879 * set it to full.
3880 */
Bruce Allan37289d92009-06-02 11:29:37 +00003881 if (hw->fc.requested_mode == e1000_fc_default) {
3882 /* Workaround h/w hang when Tx flow control enabled */
3883 if (hw->mac.type == e1000_pchlan)
3884 hw->fc.requested_mode = e1000_fc_rx_pause;
3885 else
3886 hw->fc.requested_mode = e1000_fc_full;
3887 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003888
Bruce Allane921eb12012-11-28 09:28:37 +00003889 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003890 * on the link partner's capabilities, we may or may not use this mode.
3891 */
3892 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003893
Bruce Allan17e813e2013-02-20 04:06:01 +00003894 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003895
3896 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003897 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003898 if (ret_val)
3899 return ret_val;
3900
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003901 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003902 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003903 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003904 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003905 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003906 ew32(FCRTV_PCH, hw->fc.refresh_time);
3907
Bruce Allan482fed82011-01-06 14:29:49 +00003908 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3909 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003910 if (ret_val)
3911 return ret_val;
3912 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003913
3914 return e1000e_set_fc_watermarks(hw);
3915}
3916
3917/**
3918 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3919 * @hw: pointer to the HW structure
3920 *
3921 * Configures the kumeran interface to the PHY to wait the appropriate time
3922 * when polling the PHY, then call the generic setup_copper_link to finish
3923 * configuring the copper link.
3924 **/
3925static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3926{
3927 u32 ctrl;
3928 s32 ret_val;
3929 u16 reg_data;
3930
3931 ctrl = er32(CTRL);
3932 ctrl |= E1000_CTRL_SLU;
3933 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3934 ew32(CTRL, ctrl);
3935
Bruce Allane921eb12012-11-28 09:28:37 +00003936 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003937 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003938 * this fixes erroneous timeouts at 10Mbps.
3939 */
Bruce Allan07818952009-12-08 07:28:01 +00003940 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941 if (ret_val)
3942 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003943 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003944 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003945 if (ret_val)
3946 return ret_val;
3947 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003948 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003949 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003950 if (ret_val)
3951 return ret_val;
3952
Bruce Allana4f58f52009-06-02 11:29:18 +00003953 switch (hw->phy.type) {
3954 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003955 ret_val = e1000e_copper_link_setup_igp(hw);
3956 if (ret_val)
3957 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003958 break;
3959 case e1000_phy_bm:
3960 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003961 ret_val = e1000e_copper_link_setup_m88(hw);
3962 if (ret_val)
3963 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003964 break;
3965 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003966 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00003967 ret_val = e1000_copper_link_setup_82577(hw);
3968 if (ret_val)
3969 return ret_val;
3970 break;
3971 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003972 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003973 if (ret_val)
3974 return ret_val;
3975
3976 reg_data &= ~IFE_PMC_AUTO_MDIX;
3977
3978 switch (hw->phy.mdix) {
3979 case 1:
3980 reg_data &= ~IFE_PMC_FORCE_MDIX;
3981 break;
3982 case 2:
3983 reg_data |= IFE_PMC_FORCE_MDIX;
3984 break;
3985 case 0:
3986 default:
3987 reg_data |= IFE_PMC_AUTO_MDIX;
3988 break;
3989 }
Bruce Allan482fed82011-01-06 14:29:49 +00003990 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003991 if (ret_val)
3992 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003993 break;
3994 default:
3995 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003996 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003997
Auke Kokbc7f75f2007-09-17 12:30:59 -07003998 return e1000e_setup_copper_link(hw);
3999}
4000
4001/**
Bruce Allanea8179a2013-03-06 09:02:47 +00004002 * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
4003 * @hw: pointer to the HW structure
4004 *
4005 * Calls the PHY specific link setup function and then calls the
4006 * generic setup_copper_link to finish configuring the link for
4007 * Lynxpoint PCH devices
4008 **/
4009static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
4010{
4011 u32 ctrl;
4012 s32 ret_val;
4013
4014 ctrl = er32(CTRL);
4015 ctrl |= E1000_CTRL_SLU;
4016 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
4017 ew32(CTRL, ctrl);
4018
4019 ret_val = e1000_copper_link_setup_82577(hw);
4020 if (ret_val)
4021 return ret_val;
4022
4023 return e1000e_setup_copper_link(hw);
4024}
4025
4026/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004027 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
4028 * @hw: pointer to the HW structure
4029 * @speed: pointer to store current link speed
4030 * @duplex: pointer to store the current link duplex
4031 *
Bruce Allanad680762008-03-28 09:15:03 -07004032 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07004033 * information and then calls the Kumeran lock loss workaround for links at
4034 * gigabit speeds.
4035 **/
4036static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
4037 u16 *duplex)
4038{
4039 s32 ret_val;
4040
4041 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
4042 if (ret_val)
4043 return ret_val;
4044
4045 if ((hw->mac.type == e1000_ich8lan) &&
Bruce Allane5fe2542013-02-20 04:06:27 +00004046 (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004047 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
4048 }
4049
4050 return ret_val;
4051}
4052
4053/**
4054 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
4055 * @hw: pointer to the HW structure
4056 *
4057 * Work-around for 82566 Kumeran PCS lock loss:
4058 * On link status change (i.e. PCI reset, speed change) and link is up and
4059 * speed is gigabit-
4060 * 0) if workaround is optionally disabled do nothing
4061 * 1) wait 1ms for Kumeran link to come up
4062 * 2) check Kumeran Diagnostic register PCS lock loss bit
4063 * 3) if not set the link is locked (all is good), otherwise...
4064 * 4) reset the PHY
4065 * 5) repeat up to 10 times
4066 * Note: this is only called for IGP3 copper when speed is 1gb.
4067 **/
4068static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
4069{
4070 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4071 u32 phy_ctrl;
4072 s32 ret_val;
4073 u16 i, data;
4074 bool link;
4075
4076 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
4077 return 0;
4078
Bruce Allane921eb12012-11-28 09:28:37 +00004079 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004080 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07004081 * stability
4082 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004083 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
4084 if (!link)
4085 return 0;
4086
4087 for (i = 0; i < 10; i++) {
4088 /* read once to clear */
4089 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4090 if (ret_val)
4091 return ret_val;
4092 /* and again to get new status */
4093 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4094 if (ret_val)
4095 return ret_val;
4096
4097 /* check for PCS lock */
4098 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4099 return 0;
4100
4101 /* Issue PHY reset */
4102 e1000_phy_hw_reset(hw);
4103 mdelay(5);
4104 }
4105 /* Disable GigE link negotiation */
4106 phy_ctrl = er32(PHY_CTRL);
4107 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
4108 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4109 ew32(PHY_CTRL, phy_ctrl);
4110
Bruce Allane921eb12012-11-28 09:28:37 +00004111 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07004112 * any PHY registers
4113 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004114 e1000e_gig_downshift_workaround_ich8lan(hw);
4115
4116 /* unable to acquire PCS lock */
4117 return -E1000_ERR_PHY;
4118}
4119
4120/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00004121 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004122 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08004123 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004124 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00004125 * If ICH8, set the current Kumeran workaround state (enabled - true
4126 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07004127 **/
4128void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004129 bool state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004130{
4131 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4132
4133 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004134 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004135 return;
4136 }
4137
4138 dev_spec->kmrn_lock_loss_workaround_enabled = state;
4139}
4140
4141/**
4142 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
4143 * @hw: pointer to the HW structure
4144 *
4145 * Workaround for 82566 power-down on D3 entry:
4146 * 1) disable gigabit link
4147 * 2) write VR power-down enable
4148 * 3) read it back
4149 * Continue if successful, else issue LCD reset and repeat
4150 **/
4151void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
4152{
4153 u32 reg;
4154 u16 data;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004155 u8 retry = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004156
4157 if (hw->phy.type != e1000_phy_igp_3)
4158 return;
4159
4160 /* Try the workaround twice (if needed) */
4161 do {
4162 /* Disable link */
4163 reg = er32(PHY_CTRL);
4164 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4165 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4166 ew32(PHY_CTRL, reg);
4167
Bruce Allane921eb12012-11-28 09:28:37 +00004168 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07004169 * accessing any PHY registers
4170 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004171 if (hw->mac.type == e1000_ich8lan)
4172 e1000e_gig_downshift_workaround_ich8lan(hw);
4173
4174 /* Write VR power-down enable */
4175 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4176 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4177 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4178
4179 /* Read it back and test */
4180 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4181 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4182 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4183 break;
4184
4185 /* Issue PHY reset and repeat at most one more time */
4186 reg = er32(CTRL);
4187 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4188 retry++;
4189 } while (retry);
4190}
4191
4192/**
4193 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4194 * @hw: pointer to the HW structure
4195 *
4196 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004197 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004198 * 1) Set Kumeran Near-end loopback
4199 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004200 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004201 **/
4202void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4203{
4204 s32 ret_val;
4205 u16 reg_data;
4206
Bruce Allan462d5992011-09-30 08:07:11 +00004207 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004208 return;
4209
4210 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004211 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004212 if (ret_val)
4213 return;
4214 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4215 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004216 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004217 if (ret_val)
4218 return;
4219 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00004220 e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004221}
4222
4223/**
Bruce Allan99730e42011-05-13 07:19:48 +00004224 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004225 * @hw: pointer to the HW structure
4226 *
4227 * During S0 to Sx transition, it is possible the link remains at gig
4228 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004229 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4230 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4231 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4232 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004233 * Parts that support (and are linked to a partner which support) EEE in
4234 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4235 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004236 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004237void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004238{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004239 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004240 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004241 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004242
Bruce Allan17f085d2010-06-17 18:59:48 +00004243 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004244 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allane08f6262013-02-20 03:06:34 +00004245
Bruce Allan2fbe4522012-04-19 03:21:47 +00004246 if (hw->phy.type == e1000_phy_i217) {
Bruce Allane08f6262013-02-20 03:06:34 +00004247 u16 phy_reg, device_id = hw->adapter->pdev->device;
4248
4249 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
Bruce Allan91a3d822013-06-29 01:15:16 +00004250 (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
4251 (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
4252 (device_id == E1000_DEV_ID_PCH_I218_V3)) {
Bruce Allane08f6262013-02-20 03:06:34 +00004253 u32 fextnvm6 = er32(FEXTNVM6);
4254
4255 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
4256 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004257
4258 ret_val = hw->phy.ops.acquire(hw);
4259 if (ret_val)
4260 goto out;
4261
4262 if (!dev_spec->eee_disable) {
4263 u16 eee_advert;
4264
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004265 ret_val =
4266 e1000_read_emi_reg_locked(hw,
4267 I217_EEE_ADVERTISEMENT,
4268 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004269 if (ret_val)
4270 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004271
Bruce Allane921eb12012-11-28 09:28:37 +00004272 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004273 * EEE and 100Full is advertised on both ends of the
4274 * link.
4275 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004276 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004277 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004278 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004279 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4280 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4281 E1000_PHY_CTRL_NOND0A_LPLU);
4282 }
4283
Bruce Allane921eb12012-11-28 09:28:37 +00004284 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004285 * when the system is going into Sx and no manageability engine
4286 * is present, the driver must configure proxy to reset only on
4287 * power good. LPI (Low Power Idle) state must also reset only
4288 * on power good, as well as the MTA (Multicast table array).
4289 * The SMBus release must also be disabled on LCD reset.
4290 */
4291 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00004292 /* Enable proxy to reset only on power good. */
4293 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4294 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4295 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4296
Bruce Allane921eb12012-11-28 09:28:37 +00004297 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004298 * power good.
4299 */
4300 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004301 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004302 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4303
4304 /* Disable the SMB release on LCD reset. */
4305 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004306 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004307 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4308 }
4309
Bruce Allane921eb12012-11-28 09:28:37 +00004310 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004311 * Support
4312 */
4313 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004314 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004315 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4316
4317release:
4318 hw->phy.ops.release(hw);
4319 }
4320out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004321 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004322
Bruce Allan462d5992011-09-30 08:07:11 +00004323 if (hw->mac.type == e1000_ich8lan)
4324 e1000e_gig_downshift_workaround_ich8lan(hw);
4325
Bruce Allan8395ae82010-09-22 17:15:08 +00004326 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004327 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004328
4329 /* Reset PHY to activate OEM bits on 82577/8 */
4330 if (hw->mac.type == e1000_pchlan)
4331 e1000e_phy_hw_reset_generic(hw);
4332
Bruce Allan8395ae82010-09-22 17:15:08 +00004333 ret_val = hw->phy.ops.acquire(hw);
4334 if (ret_val)
4335 return;
4336 e1000_write_smbus_addr(hw);
4337 hw->phy.ops.release(hw);
4338 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004339}
4340
4341/**
Bruce Allan99730e42011-05-13 07:19:48 +00004342 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4343 * @hw: pointer to the HW structure
4344 *
4345 * During Sx to S0 transitions on non-managed devices or managed devices
4346 * on which PHY resets are not blocked, if the PHY registers cannot be
4347 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4348 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004349 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004350 **/
4351void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4352{
Bruce Allan90b82982011-12-16 00:46:33 +00004353 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004354
Bruce Allancb17aab2012-04-13 03:16:22 +00004355 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004356 return;
4357
Bruce Allancb17aab2012-04-13 03:16:22 +00004358 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004359 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004360 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004361 return;
4362 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004363
Bruce Allane921eb12012-11-28 09:28:37 +00004364 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004365 * is transitioning from Sx and no manageability engine is present
4366 * configure SMBus to restore on reset, disable proxy, and enable
4367 * the reset on MTA (Multicast table array).
4368 */
4369 if (hw->phy.type == e1000_phy_i217) {
4370 u16 phy_reg;
4371
4372 ret_val = hw->phy.ops.acquire(hw);
4373 if (ret_val) {
4374 e_dbg("Failed to setup iRST\n");
4375 return;
4376 }
4377
4378 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004379 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004380 * is present
4381 */
4382 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4383 if (ret_val)
4384 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004385 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004386 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4387
4388 /* Disable Proxy */
4389 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4390 }
4391 /* Enable reset on MTA */
4392 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4393 if (ret_val)
4394 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004395 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004396 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4397release:
4398 if (ret_val)
4399 e_dbg("Error %d in resume workarounds\n", ret_val);
4400 hw->phy.ops.release(hw);
4401 }
Bruce Allan99730e42011-05-13 07:19:48 +00004402}
4403
4404/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004405 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4406 * @hw: pointer to the HW structure
4407 *
4408 * Return the LED back to the default configuration.
4409 **/
4410static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4411{
4412 if (hw->phy.type == e1000_phy_ife)
4413 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4414
4415 ew32(LEDCTL, hw->mac.ledctl_default);
4416 return 0;
4417}
4418
4419/**
Auke Kok489815c2008-02-21 15:11:07 -08004420 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004421 * @hw: pointer to the HW structure
4422 *
Auke Kok489815c2008-02-21 15:11:07 -08004423 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004424 **/
4425static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4426{
4427 if (hw->phy.type == e1000_phy_ife)
4428 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4429 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4430
4431 ew32(LEDCTL, hw->mac.ledctl_mode2);
4432 return 0;
4433}
4434
4435/**
Auke Kok489815c2008-02-21 15:11:07 -08004436 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004437 * @hw: pointer to the HW structure
4438 *
Auke Kok489815c2008-02-21 15:11:07 -08004439 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004440 **/
4441static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4442{
4443 if (hw->phy.type == e1000_phy_ife)
4444 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004445 (IFE_PSCL_PROBE_MODE |
4446 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004447
4448 ew32(LEDCTL, hw->mac.ledctl_mode1);
4449 return 0;
4450}
4451
4452/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004453 * e1000_setup_led_pchlan - Configures SW controllable LED
4454 * @hw: pointer to the HW structure
4455 *
4456 * This prepares the SW controllable LED for use.
4457 **/
4458static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4459{
Bruce Allan482fed82011-01-06 14:29:49 +00004460 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004461}
4462
4463/**
4464 * e1000_cleanup_led_pchlan - Restore the default LED operation
4465 * @hw: pointer to the HW structure
4466 *
4467 * Return the LED back to the default configuration.
4468 **/
4469static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4470{
Bruce Allan482fed82011-01-06 14:29:49 +00004471 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004472}
4473
4474/**
4475 * e1000_led_on_pchlan - Turn LEDs on
4476 * @hw: pointer to the HW structure
4477 *
4478 * Turn on the LEDs.
4479 **/
4480static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4481{
4482 u16 data = (u16)hw->mac.ledctl_mode2;
4483 u32 i, led;
4484
Bruce Allane921eb12012-11-28 09:28:37 +00004485 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004486 * for each LED that's mode is "link_up" in ledctl_mode2.
4487 */
4488 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4489 for (i = 0; i < 3; i++) {
4490 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4491 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4492 E1000_LEDCTL_MODE_LINK_UP)
4493 continue;
4494 if (led & E1000_PHY_LED0_IVRT)
4495 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4496 else
4497 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4498 }
4499 }
4500
Bruce Allan482fed82011-01-06 14:29:49 +00004501 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004502}
4503
4504/**
4505 * e1000_led_off_pchlan - Turn LEDs off
4506 * @hw: pointer to the HW structure
4507 *
4508 * Turn off the LEDs.
4509 **/
4510static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4511{
4512 u16 data = (u16)hw->mac.ledctl_mode1;
4513 u32 i, led;
4514
Bruce Allane921eb12012-11-28 09:28:37 +00004515 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004516 * for each LED that's mode is "link_up" in ledctl_mode1.
4517 */
4518 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4519 for (i = 0; i < 3; i++) {
4520 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4521 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4522 E1000_LEDCTL_MODE_LINK_UP)
4523 continue;
4524 if (led & E1000_PHY_LED0_IVRT)
4525 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4526 else
4527 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4528 }
4529 }
4530
Bruce Allan482fed82011-01-06 14:29:49 +00004531 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004532}
4533
4534/**
Bruce Allane98cac42010-05-10 15:02:32 +00004535 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004536 * @hw: pointer to the HW structure
4537 *
Bruce Allane98cac42010-05-10 15:02:32 +00004538 * Read appropriate register for the config done bit for completion status
4539 * and configure the PHY through s/w for EEPROM-less parts.
4540 *
4541 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4542 * config done bit, so only an error is logged and continues. If we were
4543 * to return with error, EEPROM-less silicon would not be able to be reset
4544 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004545 **/
4546static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4547{
Bruce Allane98cac42010-05-10 15:02:32 +00004548 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004549 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004550 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004551
Bruce Allanfe908492013-01-05 08:06:14 +00004552 e1000e_get_cfg_done_generic(hw);
Bruce Allanf4187b52008-08-26 18:36:50 -07004553
Bruce Allane98cac42010-05-10 15:02:32 +00004554 /* Wait for indication from h/w that it has completed basic config */
4555 if (hw->mac.type >= e1000_ich10lan) {
4556 e1000_lan_init_done_ich8lan(hw);
4557 } else {
4558 ret_val = e1000e_get_auto_rd_done(hw);
4559 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004560 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004561 * return with an error. This can happen in situations
4562 * where there is no eeprom and prevents getting link.
4563 */
4564 e_dbg("Auto Read Done did not complete\n");
4565 ret_val = 0;
4566 }
4567 }
4568
4569 /* Clear PHY Reset Asserted bit */
4570 status = er32(STATUS);
4571 if (status & E1000_STATUS_PHYRA)
4572 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4573 else
4574 e_dbg("PHY Reset Asserted not set - needs delay\n");
4575
Bruce Allanf4187b52008-08-26 18:36:50 -07004576 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004577 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004578 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004579 (hw->phy.type == e1000_phy_igp_3)) {
4580 e1000e_phy_init_script_igp3(hw);
4581 }
4582 } else {
4583 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4584 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004585 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004586 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004587 }
4588 }
4589
Bruce Allane98cac42010-05-10 15:02:32 +00004590 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004591}
4592
4593/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004594 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4595 * @hw: pointer to the HW structure
4596 *
4597 * In the case of a PHY power down to save power, or to turn off link during a
4598 * driver unload, or wake on lan is not enabled, remove the link.
4599 **/
4600static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4601{
4602 /* If the management interface is not enabled, then power down */
4603 if (!(hw->mac.ops.check_mng_mode(hw) ||
4604 hw->phy.ops.check_reset_block(hw)))
4605 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004606}
4607
4608/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004609 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4610 * @hw: pointer to the HW structure
4611 *
4612 * Clears hardware counters specific to the silicon family and calls
4613 * clear_hw_cntrs_generic to clear all general purpose counters.
4614 **/
4615static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4616{
Bruce Allana4f58f52009-06-02 11:29:18 +00004617 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004618 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004619
4620 e1000e_clear_hw_cntrs_base(hw);
4621
Bruce Allan99673d92009-11-20 23:27:21 +00004622 er32(ALGNERRC);
4623 er32(RXERRC);
4624 er32(TNCRS);
4625 er32(CEXTERR);
4626 er32(TSCTC);
4627 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004628
Bruce Allan99673d92009-11-20 23:27:21 +00004629 er32(MGTPRC);
4630 er32(MGTPDC);
4631 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004632
Bruce Allan99673d92009-11-20 23:27:21 +00004633 er32(IAC);
4634 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004635
Bruce Allana4f58f52009-06-02 11:29:18 +00004636 /* Clear PHY statistics registers */
4637 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004638 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004639 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004640 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004641 ret_val = hw->phy.ops.acquire(hw);
4642 if (ret_val)
4643 return;
4644 ret_val = hw->phy.ops.set_page(hw,
4645 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4646 if (ret_val)
4647 goto release;
4648 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4649 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4650 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4651 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4652 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4653 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4654 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4655 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4656 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4657 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4658 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4659 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4660 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4661 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4662release:
4663 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004664 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004665}
4666
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004667static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004668 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004669 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004670 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004671 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4672 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004673 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004674 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004675 /* led_on dependent on mac type */
4676 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004677 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004678 .reset_hw = e1000_reset_hw_ich8lan,
4679 .init_hw = e1000_init_hw_ich8lan,
4680 .setup_link = e1000_setup_link_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004681 .setup_physical_interface = e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004682 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004683 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004684 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004685};
4686
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004687static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004688 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004689 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004690 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004691 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004692 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004693 .read_reg = e1000e_read_phy_reg_igp,
4694 .release = e1000_release_swflag_ich8lan,
4695 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004696 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4697 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004698 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004699};
4700
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004701static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004702 .acquire = e1000_acquire_nvm_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004703 .read = e1000_read_nvm_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004704 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004705 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004706 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004707 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004708 .validate = e1000_validate_nvm_checksum_ich8lan,
4709 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004710};
4711
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004712const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004713 .mac = e1000_ich8lan,
4714 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004715 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004716 | FLAG_HAS_CTRLEXT_ON_LOAD
4717 | FLAG_HAS_AMT
4718 | FLAG_HAS_FLASH
4719 | FLAG_APME_IN_WUC,
4720 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004721 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004722 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004723 .mac_ops = &ich8_mac_ops,
4724 .phy_ops = &ich8_phy_ops,
4725 .nvm_ops = &ich8_nvm_ops,
4726};
4727
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004728const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004729 .mac = e1000_ich9lan,
4730 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004731 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004732 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004733 | FLAG_HAS_CTRLEXT_ON_LOAD
4734 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004735 | FLAG_HAS_FLASH
4736 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004737 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004738 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004739 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004740 .mac_ops = &ich8_mac_ops,
4741 .phy_ops = &ich8_phy_ops,
4742 .nvm_ops = &ich8_nvm_ops,
4743};
4744
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004745const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004746 .mac = e1000_ich10lan,
4747 .flags = FLAG_HAS_JUMBO_FRAMES
4748 | FLAG_IS_ICH
4749 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004750 | FLAG_HAS_CTRLEXT_ON_LOAD
4751 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004752 | FLAG_HAS_FLASH
4753 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004754 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004755 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004756 .get_variants = e1000_get_variants_ich8lan,
4757 .mac_ops = &ich8_mac_ops,
4758 .phy_ops = &ich8_phy_ops,
4759 .nvm_ops = &ich8_nvm_ops,
4760};
Bruce Allana4f58f52009-06-02 11:29:18 +00004761
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004762const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004763 .mac = e1000_pchlan,
4764 .flags = FLAG_IS_ICH
4765 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004766 | FLAG_HAS_CTRLEXT_ON_LOAD
4767 | FLAG_HAS_AMT
4768 | FLAG_HAS_FLASH
4769 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004770 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004771 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004772 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004773 .pba = 26,
4774 .max_hw_frame_size = 4096,
4775 .get_variants = e1000_get_variants_ich8lan,
4776 .mac_ops = &ich8_mac_ops,
4777 .phy_ops = &ich8_phy_ops,
4778 .nvm_ops = &ich8_nvm_ops,
4779};
Bruce Alland3738bb2010-06-16 13:27:28 +00004780
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004781const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004782 .mac = e1000_pch2lan,
4783 .flags = FLAG_IS_ICH
4784 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004785 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00004786 | FLAG_HAS_CTRLEXT_ON_LOAD
4787 | FLAG_HAS_AMT
4788 | FLAG_HAS_FLASH
4789 | FLAG_HAS_JUMBO_FRAMES
4790 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004791 .flags2 = FLAG2_HAS_PHY_STATS
4792 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004793 .pba = 26,
Bruce Allanc3d2dbf2013-01-09 01:20:46 +00004794 .max_hw_frame_size = 9018,
Bruce Alland3738bb2010-06-16 13:27:28 +00004795 .get_variants = e1000_get_variants_ich8lan,
4796 .mac_ops = &ich8_mac_ops,
4797 .phy_ops = &ich8_phy_ops,
4798 .nvm_ops = &ich8_nvm_ops,
4799};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004800
4801const struct e1000_info e1000_pch_lpt_info = {
4802 .mac = e1000_pch_lpt,
4803 .flags = FLAG_IS_ICH
4804 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004805 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00004806 | FLAG_HAS_CTRLEXT_ON_LOAD
4807 | FLAG_HAS_AMT
4808 | FLAG_HAS_FLASH
4809 | FLAG_HAS_JUMBO_FRAMES
4810 | FLAG_APME_IN_WUC,
4811 .flags2 = FLAG2_HAS_PHY_STATS
4812 | FLAG2_HAS_EEE,
4813 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00004814 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004815 .get_variants = e1000_get_variants_ich8lan,
4816 .mac_ops = &ich8_mac_ops,
4817 .phy_ops = &ich8_phy_ops,
4818 .nvm_ops = &ich8_nvm_ops,
4819};