blob: 3b1c1a7e5dac331ee0af8eb0195ca94b99180a55 [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 {
104 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 */
110 } 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 Allan99730e42011-05-13 07:19:48 +0000188
Bruce Allana52359b2012-07-14 04:23:58 +0000189 for (retry_count = 0; retry_count < 2; retry_count++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000190 ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000191 if (ret_val || (phy_reg == 0xFFFF))
192 continue;
193 phy_id = (u32)(phy_reg << 16);
194
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000195 ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000196 if (ret_val || (phy_reg == 0xFFFF)) {
197 phy_id = 0;
198 continue;
199 }
200 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
201 break;
202 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000203
Bruce Allancb17aab2012-04-13 03:16:22 +0000204 if (hw->phy.id) {
205 if (hw->phy.id == phy_id)
206 return true;
Bruce Allana52359b2012-07-14 04:23:58 +0000207 } else if (phy_id) {
208 hw->phy.id = phy_id;
209 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allancb17aab2012-04-13 03:16:22 +0000210 return true;
211 }
212
Bruce Allane921eb12012-11-28 09:28:37 +0000213 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000214 * set slow mode and try to get the PHY id again.
215 */
216 hw->phy.ops.release(hw);
217 ret_val = e1000_set_mdio_slow_mode_hv(hw);
218 if (!ret_val)
219 ret_val = e1000e_get_phy_id(hw);
220 hw->phy.ops.acquire(hw);
221
222 return !ret_val;
Bruce Allancb17aab2012-04-13 03:16:22 +0000223}
224
225/**
226 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
227 * @hw: pointer to the HW structure
228 *
229 * Workarounds/flow necessary for PHY initialization during driver load
230 * and resume paths.
231 **/
232static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
233{
234 u32 mac_reg, fwsm = er32(FWSM);
235 s32 ret_val;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000236 u16 phy_reg;
Bruce Allancb17aab2012-04-13 03:16:22 +0000237
Bruce Allan6e928b72012-12-12 04:45:51 +0000238 /* Gate automatic PHY configuration by hardware on managed and
239 * non-managed 82579 and newer adapters.
240 */
241 e1000_gate_hw_phy_config_ich8lan(hw, true);
242
Bruce Allancb17aab2012-04-13 03:16:22 +0000243 ret_val = hw->phy.ops.acquire(hw);
244 if (ret_val) {
245 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000246 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000247 }
248
Bruce Allane921eb12012-11-28 09:28:37 +0000249 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000250 * inaccessible and resetting the PHY is not blocked, toggle the
251 * LANPHYPC Value bit to force the interconnect to PCIe mode.
252 */
253 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000254 case e1000_pch_lpt:
255 if (e1000_phy_is_accessible_pchlan(hw))
256 break;
257
Bruce Allane921eb12012-11-28 09:28:37 +0000258 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000259 * forcing MAC to SMBus mode first.
260 */
261 mac_reg = er32(CTRL_EXT);
262 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
263 ew32(CTRL_EXT, mac_reg);
264
265 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000266 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000267 if (e1000_phy_is_accessible_pchlan(hw)) {
268 if (hw->mac.type == e1000_pch_lpt) {
269 /* Unforce SMBus mode in PHY */
270 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
271 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
272 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
273
274 /* Unforce SMBus mode in MAC */
275 mac_reg = er32(CTRL_EXT);
276 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
277 ew32(CTRL_EXT, mac_reg);
278 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000279 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000280 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000281
282 /* fall-through */
283 case e1000_pchlan:
284 if ((hw->mac.type == e1000_pchlan) &&
285 (fwsm & E1000_ICH_FWSM_FW_VALID))
286 break;
287
288 if (hw->phy.ops.check_reset_block(hw)) {
289 e_dbg("Required LANPHYPC toggle blocked by ME\n");
290 break;
291 }
292
293 e_dbg("Toggling LANPHYPC\n");
294
295 /* Set Phy Config Counter to 50msec */
296 mac_reg = er32(FEXTNVM3);
297 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
298 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
299 ew32(FEXTNVM3, mac_reg);
300
Bruce Allan4e035102013-01-04 09:53:19 +0000301 if (hw->mac.type == e1000_pch_lpt) {
302 /* Toggling LANPHYPC brings the PHY out of SMBus mode
303 * So ensure that the MAC is also out of SMBus mode
304 */
305 mac_reg = er32(CTRL_EXT);
306 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
307 ew32(CTRL_EXT, mac_reg);
308 }
309
Bruce Allancb17aab2012-04-13 03:16:22 +0000310 /* Toggle LANPHYPC Value bit */
311 mac_reg = er32(CTRL);
312 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
313 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
314 ew32(CTRL, mac_reg);
315 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +0000316 usleep_range(10, 20);
Bruce Allancb17aab2012-04-13 03:16:22 +0000317 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
318 ew32(CTRL, mac_reg);
319 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000320 if (hw->mac.type < e1000_pch_lpt) {
321 msleep(50);
322 } else {
323 u16 count = 20;
324 do {
325 usleep_range(5000, 10000);
326 } while (!(er32(CTRL_EXT) &
327 E1000_CTRL_EXT_LPCD) && count--);
328 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000329 break;
330 default:
331 break;
332 }
333
334 hw->phy.ops.release(hw);
335
Bruce Allane921eb12012-11-28 09:28:37 +0000336 /* Reset the PHY before any access to it. Doing so, ensures
Bruce Allancb17aab2012-04-13 03:16:22 +0000337 * that the PHY is in a known good state before we read/write
338 * PHY registers. The generic reset is sufficient here,
339 * because we haven't determined the PHY type yet.
340 */
341 ret_val = e1000e_phy_hw_reset_generic(hw);
342
Bruce Allan6e928b72012-12-12 04:45:51 +0000343out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000344 /* Ungate automatic PHY configuration on non-managed 82579 */
345 if ((hw->mac.type == e1000_pch2lan) &&
346 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
347 usleep_range(10000, 20000);
348 e1000_gate_hw_phy_config_ich8lan(hw, false);
349 }
350
351 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000352}
353
Auke Kokbc7f75f2007-09-17 12:30:59 -0700354/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000355 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
356 * @hw: pointer to the HW structure
357 *
358 * Initialize family-specific PHY parameters and function pointers.
359 **/
360static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
361{
362 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan70806a72013-01-05 05:08:37 +0000363 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000364
365 phy->addr = 1;
366 phy->reset_delay_us = 100;
367
Bruce Allan2b6b1682011-05-13 07:20:09 +0000368 phy->ops.set_page = e1000_set_page_igp;
Bruce Allan94d81862009-11-20 23:25:26 +0000369 phy->ops.read_reg = e1000_read_phy_reg_hv;
370 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000371 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000372 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
373 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000374 phy->ops.write_reg = e1000_write_phy_reg_hv;
375 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000376 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
Bruce Allan17f208d2009-12-01 15:47:22 +0000377 phy->ops.power_up = e1000_power_up_phy_copper;
378 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000379 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
380
381 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000382
383 ret_val = e1000_init_phy_workarounds_pchlan(hw);
384 if (ret_val)
385 return ret_val;
386
387 if (phy->id == e1000_phy_unknown)
388 switch (hw->mac.type) {
389 default:
390 ret_val = e1000e_get_phy_id(hw);
391 if (ret_val)
392 return ret_val;
393 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
394 break;
395 /* fall-through */
396 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000397 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000398 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000399 * set slow mode and try to get the PHY id again.
400 */
401 ret_val = e1000_set_mdio_slow_mode_hv(hw);
402 if (ret_val)
403 return ret_val;
404 ret_val = e1000e_get_phy_id(hw);
405 if (ret_val)
406 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000407 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000408 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000409 phy->type = e1000e_get_phy_type_from_id(phy->id);
410
Bruce Allan0be84012009-12-02 17:03:18 +0000411 switch (phy->type) {
412 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000413 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000414 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000415 phy->ops.check_polarity = e1000_check_polarity_82577;
416 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000417 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000418 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000419 phy->ops.get_info = e1000_get_phy_info_82577;
420 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000421 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000422 case e1000_phy_82578:
423 phy->ops.check_polarity = e1000_check_polarity_m88;
424 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
425 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
426 phy->ops.get_info = e1000e_get_phy_info_m88;
427 break;
428 default:
429 ret_val = -E1000_ERR_PHY;
430 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000431 }
432
433 return ret_val;
434}
435
436/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700437 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
438 * @hw: pointer to the HW structure
439 *
440 * Initialize family-specific PHY parameters and function pointers.
441 **/
442static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
443{
444 struct e1000_phy_info *phy = &hw->phy;
445 s32 ret_val;
446 u16 i = 0;
447
448 phy->addr = 1;
449 phy->reset_delay_us = 100;
450
Bruce Allan17f208d2009-12-01 15:47:22 +0000451 phy->ops.power_up = e1000_power_up_phy_copper;
452 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
453
Bruce Allane921eb12012-11-28 09:28:37 +0000454 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700455 * we'll set BM func pointers and try again
456 */
457 ret_val = e1000e_determine_phy_address(hw);
458 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000459 phy->ops.write_reg = e1000e_write_phy_reg_bm;
460 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700461 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000462 if (ret_val) {
463 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700464 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000465 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700466 }
467
Auke Kokbc7f75f2007-09-17 12:30:59 -0700468 phy->id = 0;
469 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
470 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000471 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700472 ret_val = e1000e_get_phy_id(hw);
473 if (ret_val)
474 return ret_val;
475 }
476
477 /* Verify phy id */
478 switch (phy->id) {
479 case IGP03E1000_E_PHY_ID:
480 phy->type = e1000_phy_igp_3;
481 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000482 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
483 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000484 phy->ops.get_info = e1000e_get_phy_info_igp;
485 phy->ops.check_polarity = e1000_check_polarity_igp;
486 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700487 break;
488 case IFE_E_PHY_ID:
489 case IFE_PLUS_E_PHY_ID:
490 case IFE_C_E_PHY_ID:
491 phy->type = e1000_phy_ife;
492 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000493 phy->ops.get_info = e1000_get_phy_info_ife;
494 phy->ops.check_polarity = e1000_check_polarity_ife;
495 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700496 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700497 case BME1000_E_PHY_ID:
498 phy->type = e1000_phy_bm;
499 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000500 phy->ops.read_reg = e1000e_read_phy_reg_bm;
501 phy->ops.write_reg = e1000e_write_phy_reg_bm;
502 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000503 phy->ops.get_info = e1000e_get_phy_info_m88;
504 phy->ops.check_polarity = e1000_check_polarity_m88;
505 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700506 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700507 default:
508 return -E1000_ERR_PHY;
509 break;
510 }
511
512 return 0;
513}
514
515/**
516 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
517 * @hw: pointer to the HW structure
518 *
519 * Initialize family-specific NVM parameters and function
520 * pointers.
521 **/
522static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
523{
524 struct e1000_nvm_info *nvm = &hw->nvm;
525 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000526 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700527 u16 i;
528
Bruce Allanad680762008-03-28 09:15:03 -0700529 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700530 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000531 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532 return -E1000_ERR_CONFIG;
533 }
534
535 nvm->type = e1000_nvm_flash_sw;
536
537 gfpreg = er32flash(ICH_FLASH_GFPREG);
538
Bruce Allane921eb12012-11-28 09:28:37 +0000539 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700540 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700541 * the overall size.
542 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700543 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
544 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
545
546 /* flash_base_addr is byte-aligned */
547 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
548
Bruce Allane921eb12012-11-28 09:28:37 +0000549 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700550 * size represents two separate NVM banks.
551 */
Bruce Allanf0ff4392013-02-20 04:05:39 +0000552 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
553 << FLASH_SECTOR_ADDR_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700554 nvm->flash_bank_size /= 2;
555 /* Adjust to word count */
556 nvm->flash_bank_size /= sizeof(u16);
557
558 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
559
560 /* Clear shadow ram */
561 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000562 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700563 dev_spec->shadow_ram[i].value = 0xFFFF;
564 }
565
566 return 0;
567}
568
569/**
570 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
571 * @hw: pointer to the HW structure
572 *
573 * Initialize family-specific MAC parameters and function
574 * pointers.
575 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000576static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700578 struct e1000_mac_info *mac = &hw->mac;
579
580 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700581 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700582
583 /* Set mta register count */
584 mac->mta_reg_count = 32;
585 /* Set rar entry count */
586 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
587 if (mac->type == e1000_ich8lan)
588 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000589 /* FWSM register */
590 mac->has_fwsm = true;
591 /* ARC subsystem not supported */
592 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000593 /* Adaptive IFS supported */
594 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700595
Bruce Allan2fbe4522012-04-19 03:21:47 +0000596 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000597 switch (mac->type) {
598 case e1000_ich8lan:
599 case e1000_ich9lan:
600 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000601 /* check management mode */
602 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000603 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000604 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000605 /* blink LED */
606 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000607 /* setup LED */
608 mac->ops.setup_led = e1000e_setup_led_generic;
609 /* cleanup LED */
610 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
611 /* turn on/off LED */
612 mac->ops.led_on = e1000_led_on_ich8lan;
613 mac->ops.led_off = e1000_led_off_ich8lan;
614 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000615 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000616 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
617 mac->ops.rar_set = e1000_rar_set_pch2lan;
618 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000619 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000620 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000621 /* check management mode */
622 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000623 /* ID LED init */
624 mac->ops.id_led_init = e1000_id_led_init_pchlan;
625 /* setup LED */
626 mac->ops.setup_led = e1000_setup_led_pchlan;
627 /* cleanup LED */
628 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
629 /* turn on/off LED */
630 mac->ops.led_on = e1000_led_on_pchlan;
631 mac->ops.led_off = e1000_led_off_pchlan;
632 break;
633 default:
634 break;
635 }
636
Bruce Allan2fbe4522012-04-19 03:21:47 +0000637 if (mac->type == e1000_pch_lpt) {
638 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
639 mac->ops.rar_set = e1000_rar_set_pch_lpt;
Bruce Allanea8179a2013-03-06 09:02:47 +0000640 mac->ops.setup_physical_interface =
641 e1000_setup_copper_link_pch_lpt;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000642 }
643
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644 /* Enable PCS Lock-loss workaround for ICH8 */
645 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000646 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700647
648 return 0;
649}
650
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000651/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000652 * __e1000_access_emi_reg_locked - Read/write EMI register
653 * @hw: pointer to the HW structure
654 * @addr: EMI address to program
655 * @data: pointer to value to read/write from/to the EMI address
656 * @read: boolean flag to indicate read or write
657 *
658 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
659 **/
660static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
661 u16 *data, bool read)
662{
Bruce Allan70806a72013-01-05 05:08:37 +0000663 s32 ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000664
665 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
666 if (ret_val)
667 return ret_val;
668
669 if (read)
670 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
671 else
672 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
673
674 return ret_val;
675}
676
677/**
678 * e1000_read_emi_reg_locked - Read Extended Management Interface register
679 * @hw: pointer to the HW structure
680 * @addr: EMI address to program
681 * @data: value to be read from the EMI address
682 *
683 * Assumes the SW/FW/HW Semaphore is already acquired.
684 **/
Bruce Allan203e41512012-12-05 08:40:59 +0000685s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000686{
687 return __e1000_access_emi_reg_locked(hw, addr, data, true);
688}
689
690/**
691 * e1000_write_emi_reg_locked - Write Extended Management Interface register
692 * @hw: pointer to the HW structure
693 * @addr: EMI address to program
694 * @data: value to be written to the EMI address
695 *
696 * Assumes the SW/FW/HW Semaphore is already acquired.
697 **/
698static s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
699{
700 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
701}
702
703/**
Bruce Allane52997f2010-06-16 13:27:49 +0000704 * e1000_set_eee_pchlan - Enable/disable EEE support
705 * @hw: pointer to the HW structure
706 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000707 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
708 * the link and the EEE capabilities of the link partner. The LPI Control
709 * register bits will remain set only if/when link is up.
Bruce Allane52997f2010-06-16 13:27:49 +0000710 **/
711static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
712{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000713 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000714 s32 ret_val;
715 u16 lpi_ctrl;
Bruce Allane52997f2010-06-16 13:27:49 +0000716
Bruce Allan2fbe4522012-04-19 03:21:47 +0000717 if ((hw->phy.type != e1000_phy_82579) &&
718 (hw->phy.type != e1000_phy_i217))
Bruce Allan5015e532012-02-08 02:55:56 +0000719 return 0;
Bruce Allane52997f2010-06-16 13:27:49 +0000720
Bruce Allan3d4d5752012-12-05 06:26:08 +0000721 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000722 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000723 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000724
Bruce Allan3d4d5752012-12-05 06:26:08 +0000725 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000726 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000727 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000728
Bruce Allan3d4d5752012-12-05 06:26:08 +0000729 /* Clear bits that enable EEE in various speeds */
730 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
731
732 /* Enable EEE if not disabled by user */
733 if (!dev_spec->eee_disable) {
734 u16 lpa, pcs_status, data;
735
Bruce Allan2fbe4522012-04-19 03:21:47 +0000736 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000737 switch (hw->phy.type) {
738 case e1000_phy_82579:
739 lpa = I82579_EEE_LP_ABILITY;
740 pcs_status = I82579_EEE_PCS_STATUS;
741 break;
742 case e1000_phy_i217:
743 lpa = I217_EEE_LP_ABILITY;
744 pcs_status = I217_EEE_PCS_STATUS;
745 break;
746 default:
747 ret_val = -E1000_ERR_PHY;
748 goto release;
749 }
750 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000751 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000752 if (ret_val)
753 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000754
Bruce Allan3d4d5752012-12-05 06:26:08 +0000755 /* Enable EEE only for speeds in which the link partner is
756 * EEE capable.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000757 */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000758 if (dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
759 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
760
761 if (dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000762 e1e_rphy_locked(hw, MII_LPA, &data);
763 if (data & LPA_100FULL)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000764 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
765 else
766 /* EEE is not supported in 100Half, so ignore
767 * partner's EEE in 100 ability if full-duplex
768 * is not advertised.
769 */
770 dev_spec->eee_lp_ability &=
771 ~I82579_EEE_100_SUPPORTED;
772 }
773
774 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
775 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
776 if (ret_val)
777 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000778 }
779
Bruce Allan3d4d5752012-12-05 06:26:08 +0000780 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
781release:
782 hw->phy.ops.release(hw);
783
784 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000785}
786
787/**
Bruce Allane08f6262013-02-20 03:06:34 +0000788 * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
789 * @hw: pointer to the HW structure
790 * @link: link up bool flag
791 *
792 * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
793 * preventing further DMA write requests. Workaround the issue by disabling
794 * the de-assertion of the clock request when in 1Gpbs mode.
795 **/
796static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
797{
798 u32 fextnvm6 = er32(FEXTNVM6);
799 s32 ret_val = 0;
800
801 if (link && (er32(STATUS) & E1000_STATUS_SPEED_1000)) {
802 u16 kmrn_reg;
803
804 ret_val = hw->phy.ops.acquire(hw);
805 if (ret_val)
806 return ret_val;
807
808 ret_val =
809 e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
810 &kmrn_reg);
811 if (ret_val)
812 goto release;
813
814 ret_val =
815 e1000e_write_kmrn_reg_locked(hw,
816 E1000_KMRNCTRLSTA_K1_CONFIG,
817 kmrn_reg &
818 ~E1000_KMRNCTRLSTA_K1_ENABLE);
819 if (ret_val)
820 goto release;
821
822 usleep_range(10, 20);
823
824 ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
825
826 ret_val =
827 e1000e_write_kmrn_reg_locked(hw,
828 E1000_KMRNCTRLSTA_K1_CONFIG,
829 kmrn_reg);
830release:
831 hw->phy.ops.release(hw);
832 } else {
833 /* clear FEXTNVM6 bit 8 on link down or 10/100 */
834 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
835 }
836
837 return ret_val;
838}
839
840/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000841 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
842 * @hw: pointer to the HW structure
843 *
844 * Checks to see of the link status of the hardware has changed. If a
845 * change in link status has been detected, then we read the PHY registers
846 * to get the current speed/duplex if link exists.
847 **/
848static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
849{
850 struct e1000_mac_info *mac = &hw->mac;
851 s32 ret_val;
852 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000853 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000854
Bruce Allane921eb12012-11-28 09:28:37 +0000855 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000856 * has completed and/or if our link status has changed. The
857 * get_link_status flag is set upon receiving a Link Status
858 * Change or Rx Sequence Error interrupt.
859 */
Bruce Allan5015e532012-02-08 02:55:56 +0000860 if (!mac->get_link_status)
861 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000862
Bruce Allane921eb12012-11-28 09:28:37 +0000863 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000864 * link. If so, then we want to get the current speed/duplex
865 * of the PHY.
866 */
867 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
868 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000869 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000870
Bruce Allan1d5846b2009-10-29 13:46:05 +0000871 if (hw->mac.type == e1000_pchlan) {
872 ret_val = e1000_k1_gig_workaround_hv(hw, link);
873 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000874 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +0000875 }
876
Bruce Allan772d05c2013-03-06 09:02:36 +0000877 /* When connected at 10Mbps half-duplex, 82579 parts are excessively
878 * aggressive resulting in many collisions. To avoid this, increase
879 * the IPG and reduce Rx latency in the PHY.
880 */
881 if ((hw->mac.type == e1000_pch2lan) && link) {
882 u32 reg;
883 reg = er32(STATUS);
884 if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
885 reg = er32(TIPG);
886 reg &= ~E1000_TIPG_IPGT_MASK;
887 reg |= 0xFF;
888 ew32(TIPG, reg);
889
890 /* Reduce Rx latency in analog PHY */
891 ret_val = hw->phy.ops.acquire(hw);
892 if (ret_val)
893 return ret_val;
894
895 ret_val =
896 e1000_write_emi_reg_locked(hw, I82579_RX_CONFIG, 0);
897
898 hw->phy.ops.release(hw);
899
900 if (ret_val)
901 return ret_val;
902 }
903 }
904
Bruce Allane08f6262013-02-20 03:06:34 +0000905 /* Work-around I218 hang issue */
906 if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
907 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V)) {
908 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
909 if (ret_val)
910 return ret_val;
911 }
912
Bruce Allan2fbe4522012-04-19 03:21:47 +0000913 /* Clear link partner's EEE ability */
914 hw->dev_spec.ich8lan.eee_lp_ability = 0;
915
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000916 if (!link)
Bruce Allan5015e532012-02-08 02:55:56 +0000917 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000918
919 mac->get_link_status = false;
920
Bruce Allan1d2101a72011-07-22 06:21:56 +0000921 switch (hw->mac.type) {
922 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +0000923 ret_val = e1000_k1_workaround_lv(hw);
924 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000925 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000926 /* fall-thru */
927 case e1000_pchlan:
928 if (hw->phy.type == e1000_phy_82578) {
929 ret_val = e1000_link_stall_workaround_hv(hw);
930 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000931 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000932 }
933
Bruce Allane921eb12012-11-28 09:28:37 +0000934 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +0000935 * Set the number of preambles removed from the packet
936 * when it is passed from the PHY to the MAC to prevent
937 * the MAC from misinterpreting the packet type.
938 */
939 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
940 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
941
942 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
943 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
944
945 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
946 break;
947 default:
948 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +0000949 }
950
Bruce Allane921eb12012-11-28 09:28:37 +0000951 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000952 * immediately after link-up
953 */
954 e1000e_check_downshift(hw);
955
Bruce Allane52997f2010-06-16 13:27:49 +0000956 /* Enable/Disable EEE after link up */
957 ret_val = e1000_set_eee_pchlan(hw);
958 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000959 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000960
Bruce Allane921eb12012-11-28 09:28:37 +0000961 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000962 * we have already determined whether we have link or not.
963 */
Bruce Allan5015e532012-02-08 02:55:56 +0000964 if (!mac->autoneg)
965 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000966
Bruce Allane921eb12012-11-28 09:28:37 +0000967 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000968 * of MAC speed/duplex configuration. So we only need to
969 * configure Collision Distance in the MAC.
970 */
Bruce Allan57cde762012-02-22 09:02:58 +0000971 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000972
Bruce Allane921eb12012-11-28 09:28:37 +0000973 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000974 * First, we need to restore the desired flow control
975 * settings because we may have had to re-autoneg with a
976 * different link partner.
977 */
978 ret_val = e1000e_config_fc_after_link_up(hw);
979 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000980 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000981
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000982 return ret_val;
983}
984
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700985static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700986{
987 struct e1000_hw *hw = &adapter->hw;
988 s32 rc;
989
Bruce Allanec34c172012-02-01 10:53:05 +0000990 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 if (rc)
992 return rc;
993
994 rc = e1000_init_nvm_params_ich8lan(hw);
995 if (rc)
996 return rc;
997
Bruce Alland3738bb2010-06-16 13:27:28 +0000998 switch (hw->mac.type) {
999 case e1000_ich8lan:
1000 case e1000_ich9lan:
1001 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001002 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001003 break;
1004 case e1000_pchlan:
1005 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001006 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001007 rc = e1000_init_phy_params_pchlan(hw);
1008 break;
1009 default:
1010 break;
1011 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001012 if (rc)
1013 return rc;
1014
Bruce Allane921eb12012-11-28 09:28:37 +00001015 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001016 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1017 */
1018 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1019 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1020 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001021 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1022 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001023
1024 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001025 }
1026
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001028 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001029 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1030
Bruce Allanc6e7f512011-07-29 05:53:02 +00001031 /* Enable workaround for 82579 w/ ME enabled */
1032 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1033 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1034 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1035
Bruce Allan5a86f282010-06-29 18:13:13 +00001036 /* Disable EEE by default until IEEE802.3az spec is finalized */
1037 if (adapter->flags2 & FLAG2_HAS_EEE)
1038 adapter->hw.dev_spec.ich8lan.eee_disable = true;
1039
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 return 0;
1041}
1042
Thomas Gleixner717d4382008-10-02 16:33:40 -07001043static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001044
Auke Kokbc7f75f2007-09-17 12:30:59 -07001045/**
Bruce Allanca15df52009-10-26 11:23:43 +00001046 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1047 * @hw: pointer to the HW structure
1048 *
1049 * Acquires the mutex for performing NVM operations.
1050 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001051static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001052{
1053 mutex_lock(&nvm_mutex);
1054
1055 return 0;
1056}
1057
1058/**
1059 * e1000_release_nvm_ich8lan - Release NVM mutex
1060 * @hw: pointer to the HW structure
1061 *
1062 * Releases the mutex used while performing NVM operations.
1063 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001064static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001065{
1066 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001067}
1068
Bruce Allanca15df52009-10-26 11:23:43 +00001069/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001070 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1071 * @hw: pointer to the HW structure
1072 *
Bruce Allanca15df52009-10-26 11:23:43 +00001073 * Acquires the software control flag for performing PHY and select
1074 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075 **/
1076static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1077{
Bruce Allan373a88d2009-08-07 07:41:37 +00001078 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1079 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001080
Bruce Allana90b4122011-10-07 03:50:38 +00001081 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1082 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001083 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001084 return -E1000_ERR_PHY;
1085 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001086
Auke Kokbc7f75f2007-09-17 12:30:59 -07001087 while (timeout) {
1088 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001089 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1090 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001091
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092 mdelay(1);
1093 timeout--;
1094 }
1095
1096 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001097 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001098 ret_val = -E1000_ERR_CONFIG;
1099 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001100 }
1101
Bruce Allan53ac5a82009-10-26 11:23:06 +00001102 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001103
1104 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1105 ew32(EXTCNF_CTRL, extcnf_ctrl);
1106
1107 while (timeout) {
1108 extcnf_ctrl = er32(EXTCNF_CTRL);
1109 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1110 break;
1111
1112 mdelay(1);
1113 timeout--;
1114 }
1115
1116 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001117 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 +00001118 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001119 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1120 ew32(EXTCNF_CTRL, extcnf_ctrl);
1121 ret_val = -E1000_ERR_CONFIG;
1122 goto out;
1123 }
1124
1125out:
1126 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001127 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001128
1129 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130}
1131
1132/**
1133 * e1000_release_swflag_ich8lan - Release software control flag
1134 * @hw: pointer to the HW structure
1135 *
Bruce Allanca15df52009-10-26 11:23:43 +00001136 * Releases the software control flag for performing PHY and select
1137 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138 **/
1139static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1140{
1141 u32 extcnf_ctrl;
1142
1143 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001144
1145 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1146 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1147 ew32(EXTCNF_CTRL, extcnf_ctrl);
1148 } else {
1149 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1150 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001151
Bruce Allana90b4122011-10-07 03:50:38 +00001152 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001153}
1154
1155/**
Bruce Allan4662e822008-08-26 18:37:06 -07001156 * e1000_check_mng_mode_ich8lan - Checks management mode
1157 * @hw: pointer to the HW structure
1158 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001159 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001160 * This is a function pointer entry point only called by read/write
1161 * routines for the PHY and NVM parts.
1162 **/
1163static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1164{
Bruce Allana708dd82009-11-20 23:28:37 +00001165 u32 fwsm;
1166
1167 fwsm = er32(FWSM);
Bruce Allanf0ff4392013-02-20 04:05:39 +00001168 return ((fwsm & E1000_ICH_FWSM_FW_VALID) &&
1169 ((fwsm & E1000_FWSM_MODE_MASK) ==
1170 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)));
Bruce Allaneb7700d2010-06-16 13:27:05 +00001171}
Bruce Allan4662e822008-08-26 18:37:06 -07001172
Bruce Allaneb7700d2010-06-16 13:27:05 +00001173/**
1174 * e1000_check_mng_mode_pchlan - Checks management mode
1175 * @hw: pointer to the HW structure
1176 *
1177 * This checks if the adapter has iAMT enabled.
1178 * This is a function pointer entry point only called by read/write
1179 * routines for the PHY and NVM parts.
1180 **/
1181static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1182{
1183 u32 fwsm;
1184
1185 fwsm = er32(FWSM);
1186 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
Bruce Allanf0ff4392013-02-20 04:05:39 +00001187 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001188}
1189
1190/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001191 * e1000_rar_set_pch2lan - Set receive address register
1192 * @hw: pointer to the HW structure
1193 * @addr: pointer to the receive address
1194 * @index: receive address array register
1195 *
1196 * Sets the receive address array register at index to the address passed
1197 * in by addr. For 82579, RAR[0] is the base address register that is to
1198 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1199 * Use SHRA[0-3] in place of those reserved for ME.
1200 **/
1201static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1202{
1203 u32 rar_low, rar_high;
1204
Bruce Allane921eb12012-11-28 09:28:37 +00001205 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001206 * from network order (big endian) to little endian
1207 */
1208 rar_low = ((u32)addr[0] |
1209 ((u32)addr[1] << 8) |
1210 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1211
1212 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1213
1214 /* If MAC address zero, no need to set the AV bit */
1215 if (rar_low || rar_high)
1216 rar_high |= E1000_RAH_AV;
1217
1218 if (index == 0) {
1219 ew32(RAL(index), rar_low);
1220 e1e_flush();
1221 ew32(RAH(index), rar_high);
1222 e1e_flush();
1223 return;
1224 }
1225
1226 if (index < hw->mac.rar_entry_count) {
1227 s32 ret_val;
1228
1229 ret_val = e1000_acquire_swflag_ich8lan(hw);
1230 if (ret_val)
1231 goto out;
1232
1233 ew32(SHRAL(index - 1), rar_low);
1234 e1e_flush();
1235 ew32(SHRAH(index - 1), rar_high);
1236 e1e_flush();
1237
1238 e1000_release_swflag_ich8lan(hw);
1239
1240 /* verify the register updates */
1241 if ((er32(SHRAL(index - 1)) == rar_low) &&
1242 (er32(SHRAH(index - 1)) == rar_high))
1243 return;
1244
1245 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1246 (index - 1), er32(FWSM));
1247 }
1248
1249out:
1250 e_dbg("Failed to write receive address at index %d\n", index);
1251}
1252
1253/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001254 * e1000_rar_set_pch_lpt - Set receive address registers
1255 * @hw: pointer to the HW structure
1256 * @addr: pointer to the receive address
1257 * @index: receive address array register
1258 *
1259 * Sets the receive address register array at index to the address passed
1260 * in by addr. For LPT, RAR[0] is the base address register that is to
1261 * contain the MAC address. SHRA[0-10] are the shared receive address
1262 * registers that are shared between the Host and manageability engine (ME).
1263 **/
1264static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1265{
1266 u32 rar_low, rar_high;
1267 u32 wlock_mac;
1268
Bruce Allane921eb12012-11-28 09:28:37 +00001269 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001270 * from network order (big endian) to little endian
1271 */
1272 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1273 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1274
1275 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1276
1277 /* If MAC address zero, no need to set the AV bit */
1278 if (rar_low || rar_high)
1279 rar_high |= E1000_RAH_AV;
1280
1281 if (index == 0) {
1282 ew32(RAL(index), rar_low);
1283 e1e_flush();
1284 ew32(RAH(index), rar_high);
1285 e1e_flush();
1286 return;
1287 }
1288
Bruce Allane921eb12012-11-28 09:28:37 +00001289 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001290 * it is using - those registers are unavailable for use.
1291 */
1292 if (index < hw->mac.rar_entry_count) {
1293 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1294 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1295
1296 /* Check if all SHRAR registers are locked */
1297 if (wlock_mac == 1)
1298 goto out;
1299
1300 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1301 s32 ret_val;
1302
1303 ret_val = e1000_acquire_swflag_ich8lan(hw);
1304
1305 if (ret_val)
1306 goto out;
1307
1308 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1309 e1e_flush();
1310 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1311 e1e_flush();
1312
1313 e1000_release_swflag_ich8lan(hw);
1314
1315 /* verify the register updates */
1316 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1317 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1318 return;
1319 }
1320 }
1321
1322out:
1323 e_dbg("Failed to write receive address at index %d\n", index);
1324}
1325
1326/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001327 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1328 * @hw: pointer to the HW structure
1329 *
1330 * Checks if firmware is blocking the reset of the PHY.
1331 * This is a function pointer entry point only called by
1332 * reset routines.
1333 **/
1334static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1335{
1336 u32 fwsm;
1337
1338 fwsm = er32(FWSM);
1339
1340 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
1341}
1342
1343/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001344 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1345 * @hw: pointer to the HW structure
1346 *
1347 * Assumes semaphore already acquired.
1348 *
1349 **/
1350static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1351{
1352 u16 phy_data;
1353 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001354 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1355 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan70806a72013-01-05 05:08:37 +00001356 s32 ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001357
1358 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1359
1360 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1361 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001362 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001363
1364 phy_data &= ~HV_SMB_ADDR_MASK;
1365 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1366 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001367
Bruce Allan2fbe4522012-04-19 03:21:47 +00001368 if (hw->phy.type == e1000_phy_i217) {
1369 /* Restore SMBus frequency */
1370 if (freq--) {
1371 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1372 phy_data |= (freq & (1 << 0)) <<
1373 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1374 phy_data |= (freq & (1 << 1)) <<
1375 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1376 } else {
1377 e_dbg("Unsupported SMB frequency in PHY\n");
1378 }
1379 }
1380
Bruce Allan5015e532012-02-08 02:55:56 +00001381 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001382}
1383
1384/**
Bruce Allanf523d212009-10-29 13:45:45 +00001385 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1386 * @hw: pointer to the HW structure
1387 *
1388 * SW should configure the LCD from the NVM extended configuration region
1389 * as a workaround for certain parts.
1390 **/
1391static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1392{
1393 struct e1000_phy_info *phy = &hw->phy;
1394 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001395 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001396 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1397
Bruce Allane921eb12012-11-28 09:28:37 +00001398 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001399 * is needed due to an issue where the NVM configuration is
1400 * not properly autoloaded after power transitions.
1401 * Therefore, after each PHY reset, we will load the
1402 * configuration data out of the NVM manually.
1403 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001404 switch (hw->mac.type) {
1405 case e1000_ich8lan:
1406 if (phy->type != e1000_phy_igp_3)
1407 return ret_val;
1408
Bruce Allan5f3eed62010-09-22 17:15:54 +00001409 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1410 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001411 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1412 break;
1413 }
1414 /* Fall-thru */
1415 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001416 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001417 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001418 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001419 break;
1420 default:
1421 return ret_val;
1422 }
1423
1424 ret_val = hw->phy.ops.acquire(hw);
1425 if (ret_val)
1426 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001427
Bruce Allan8b802a72010-05-10 15:01:10 +00001428 data = er32(FEXTNVM);
1429 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001430 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001431
Bruce Allane921eb12012-11-28 09:28:37 +00001432 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001433 * extended configuration before SW configuration
1434 */
1435 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001436 if ((hw->mac.type < e1000_pch2lan) &&
1437 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1438 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001439
Bruce Allan8b802a72010-05-10 15:01:10 +00001440 cnf_size = er32(EXTCNF_SIZE);
1441 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1442 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1443 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001444 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001445
1446 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1447 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1448
Bruce Allan2fbe4522012-04-19 03:21:47 +00001449 if (((hw->mac.type == e1000_pchlan) &&
1450 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1451 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001452 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001453 * OEM and LCD Write Enable bits are set in the NVM.
1454 * When both NVM bits are cleared, SW will configure
1455 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001456 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001457 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001458 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001459 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001460
Bruce Allan8b802a72010-05-10 15:01:10 +00001461 data = er32(LEDCTL);
1462 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1463 (u16)data);
1464 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001465 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001466 }
1467
1468 /* Configure LCD from extended configuration region. */
1469
1470 /* cnf_base_addr is in DWORD */
1471 word_addr = (u16)(cnf_base_addr << 1);
1472
1473 for (i = 0; i < cnf_size; i++) {
Bruce Allane5fe2542013-02-20 04:06:27 +00001474 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001475 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001476 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001477
Bruce Allan8b802a72010-05-10 15:01:10 +00001478 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1479 1, &reg_addr);
1480 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001481 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001482
Bruce Allan8b802a72010-05-10 15:01:10 +00001483 /* Save off the PHY page for future writes. */
1484 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1485 phy_page = reg_data;
1486 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001487 }
Bruce Allanf523d212009-10-29 13:45:45 +00001488
Bruce Allan8b802a72010-05-10 15:01:10 +00001489 reg_addr &= PHY_REG_MASK;
1490 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001491
Bruce Allanf1430d62012-04-14 04:21:52 +00001492 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001493 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001494 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001495 }
1496
Bruce Allan75ce1532012-02-08 02:54:48 +00001497release:
Bruce Allan94d81862009-11-20 23:25:26 +00001498 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001499 return ret_val;
1500}
1501
1502/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001503 * e1000_k1_gig_workaround_hv - K1 Si workaround
1504 * @hw: pointer to the HW structure
1505 * @link: link up bool flag
1506 *
1507 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1508 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1509 * If link is down, the function will restore the default K1 setting located
1510 * in the NVM.
1511 **/
1512static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1513{
1514 s32 ret_val = 0;
1515 u16 status_reg = 0;
1516 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1517
1518 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001519 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001520
1521 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001522 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001523 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001524 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001525
1526 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1527 if (link) {
1528 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001529 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1530 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001531 if (ret_val)
1532 goto release;
1533
Bruce Allanf0ff4392013-02-20 04:05:39 +00001534 status_reg &= (BM_CS_STATUS_LINK_UP |
1535 BM_CS_STATUS_RESOLVED |
1536 BM_CS_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001537
1538 if (status_reg == (BM_CS_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001539 BM_CS_STATUS_RESOLVED |
1540 BM_CS_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001541 k1_enable = false;
1542 }
1543
1544 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001545 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001546 if (ret_val)
1547 goto release;
1548
Bruce Allanf0ff4392013-02-20 04:05:39 +00001549 status_reg &= (HV_M_STATUS_LINK_UP |
1550 HV_M_STATUS_AUTONEG_COMPLETE |
1551 HV_M_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001552
1553 if (status_reg == (HV_M_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001554 HV_M_STATUS_AUTONEG_COMPLETE |
1555 HV_M_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001556 k1_enable = false;
1557 }
1558
1559 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001560 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001561 if (ret_val)
1562 goto release;
1563
1564 } else {
1565 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001566 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001567 if (ret_val)
1568 goto release;
1569 }
1570
1571 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1572
1573release:
Bruce Allan94d81862009-11-20 23:25:26 +00001574 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001575
Bruce Allan1d5846b2009-10-29 13:46:05 +00001576 return ret_val;
1577}
1578
1579/**
1580 * e1000_configure_k1_ich8lan - Configure K1 power state
1581 * @hw: pointer to the HW structure
1582 * @enable: K1 state to configure
1583 *
1584 * Configure the K1 power state based on the provided parameter.
1585 * Assumes semaphore already acquired.
1586 *
1587 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1588 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001589s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001590{
Bruce Allan70806a72013-01-05 05:08:37 +00001591 s32 ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001592 u32 ctrl_reg = 0;
1593 u32 ctrl_ext = 0;
1594 u32 reg = 0;
1595 u16 kmrn_reg = 0;
1596
Bruce Allan3d3a1672012-02-23 03:13:18 +00001597 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1598 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001599 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001600 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001601
1602 if (k1_enable)
1603 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1604 else
1605 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1606
Bruce Allan3d3a1672012-02-23 03:13:18 +00001607 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1608 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001609 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001610 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001611
Bruce Allance43a212013-02-20 04:06:32 +00001612 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001613 ctrl_ext = er32(CTRL_EXT);
1614 ctrl_reg = er32(CTRL);
1615
1616 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1617 reg |= E1000_CTRL_FRCSPD;
1618 ew32(CTRL, reg);
1619
1620 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001621 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001622 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001623 ew32(CTRL, ctrl_reg);
1624 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001625 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001626 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001627
Bruce Allan5015e532012-02-08 02:55:56 +00001628 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001629}
1630
1631/**
Bruce Allanf523d212009-10-29 13:45:45 +00001632 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1633 * @hw: pointer to the HW structure
1634 * @d0_state: boolean if entering d0 or d3 device state
1635 *
1636 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1637 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1638 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1639 **/
1640static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1641{
1642 s32 ret_val = 0;
1643 u32 mac_reg;
1644 u16 oem_reg;
1645
Bruce Allan2fbe4522012-04-19 03:21:47 +00001646 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001647 return ret_val;
1648
Bruce Allan94d81862009-11-20 23:25:26 +00001649 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001650 if (ret_val)
1651 return ret_val;
1652
Bruce Allan2fbe4522012-04-19 03:21:47 +00001653 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001654 mac_reg = er32(EXTCNF_CTRL);
1655 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001656 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001657 }
Bruce Allanf523d212009-10-29 13:45:45 +00001658
1659 mac_reg = er32(FEXTNVM);
1660 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001661 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001662
1663 mac_reg = er32(PHY_CTRL);
1664
Bruce Allanf1430d62012-04-14 04:21:52 +00001665 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001666 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001667 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001668
1669 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1670
1671 if (d0_state) {
1672 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1673 oem_reg |= HV_OEM_BITS_GBE_DIS;
1674
1675 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1676 oem_reg |= HV_OEM_BITS_LPLU;
1677 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001678 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1679 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001680 oem_reg |= HV_OEM_BITS_GBE_DIS;
1681
Bruce Allan03299e42011-09-30 08:07:05 +00001682 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1683 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001684 oem_reg |= HV_OEM_BITS_LPLU;
1685 }
Bruce Allan03299e42011-09-30 08:07:05 +00001686
Bruce Allan92fe1732012-04-12 06:27:03 +00001687 /* Set Restart auto-neg to activate the bits */
1688 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1689 !hw->phy.ops.check_reset_block(hw))
1690 oem_reg |= HV_OEM_BITS_RESTART_AN;
1691
Bruce Allanf1430d62012-04-14 04:21:52 +00001692 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001693
Bruce Allan75ce1532012-02-08 02:54:48 +00001694release:
Bruce Allan94d81862009-11-20 23:25:26 +00001695 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001696
1697 return ret_val;
1698}
1699
Bruce Allanf523d212009-10-29 13:45:45 +00001700/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001701 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1702 * @hw: pointer to the HW structure
1703 **/
1704static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1705{
1706 s32 ret_val;
1707 u16 data;
1708
1709 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1710 if (ret_val)
1711 return ret_val;
1712
1713 data |= HV_KMRN_MDIO_SLOW;
1714
1715 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1716
1717 return ret_val;
1718}
1719
1720/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001721 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1722 * done after every PHY reset.
1723 **/
1724static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1725{
1726 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001727 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001728
1729 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001730 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001731
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001732 /* Set MDIO slow mode before any other MDIO access */
1733 if (hw->phy.type == e1000_phy_82577) {
1734 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1735 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001736 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001737 }
1738
Bruce Allana4f58f52009-06-02 11:29:18 +00001739 if (((hw->phy.type == e1000_phy_82577) &&
1740 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1741 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1742 /* Disable generation of early preamble */
1743 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1744 if (ret_val)
1745 return ret_val;
1746
1747 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001748 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001749 if (ret_val)
1750 return ret_val;
1751 }
1752
1753 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001754 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001755 * writing 0x3140 to the control register.
1756 */
1757 if (hw->phy.revision < 2) {
1758 e1000e_phy_sw_reset(hw);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001759 ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
Bruce Allana4f58f52009-06-02 11:29:18 +00001760 }
1761 }
1762
1763 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001764 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001765 if (ret_val)
1766 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001767
Bruce Allana4f58f52009-06-02 11:29:18 +00001768 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001769 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001770 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001771 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001772 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001773
Bruce Allane921eb12012-11-28 09:28:37 +00001774 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001775 * link so that it disables K1 if link is in 1Gbps.
1776 */
1777 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001778 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001779 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001780
Bruce Allanbaf86c92010-01-13 01:53:08 +00001781 /* Workaround for link disconnects on a busy hub in half duplex */
1782 ret_val = hw->phy.ops.acquire(hw);
1783 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001784 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001785 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001786 if (ret_val)
1787 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001788 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001789 if (ret_val)
1790 goto release;
1791
1792 /* set MSE higher to enable link to stay up when noise is high */
1793 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001794release:
1795 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001796
Bruce Allana4f58f52009-06-02 11:29:18 +00001797 return ret_val;
1798}
1799
1800/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001801 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1802 * @hw: pointer to the HW structure
1803 **/
1804void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1805{
1806 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001807 u16 i, phy_reg = 0;
1808 s32 ret_val;
1809
1810 ret_val = hw->phy.ops.acquire(hw);
1811 if (ret_val)
1812 return;
1813 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1814 if (ret_val)
1815 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001816
1817 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1818 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1819 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001820 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1821 (u16)(mac_reg & 0xFFFF));
1822 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1823 (u16)((mac_reg >> 16) & 0xFFFF));
1824
Bruce Alland3738bb2010-06-16 13:27:28 +00001825 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001826 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1827 (u16)(mac_reg & 0xFFFF));
1828 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1829 (u16)((mac_reg & E1000_RAH_AV)
1830 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00001831 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00001832
1833 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1834
1835release:
1836 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001837}
1838
Bruce Alland3738bb2010-06-16 13:27:28 +00001839/**
1840 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1841 * with 82579 PHY
1842 * @hw: pointer to the HW structure
1843 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1844 **/
1845s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1846{
1847 s32 ret_val = 0;
1848 u16 phy_reg, data;
1849 u32 mac_reg;
1850 u16 i;
1851
Bruce Allan2fbe4522012-04-19 03:21:47 +00001852 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001853 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001854
1855 /* disable Rx path while enabling/disabling workaround */
1856 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1857 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1858 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001859 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001860
1861 if (enable) {
Bruce Allane921eb12012-11-28 09:28:37 +00001862 /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
Bruce Alland3738bb2010-06-16 13:27:28 +00001863 * SHRAL/H) and initial CRC values to the MAC
1864 */
1865 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00001866 u8 mac_addr[ETH_ALEN] = { 0 };
Bruce Alland3738bb2010-06-16 13:27:28 +00001867 u32 addr_high, addr_low;
1868
1869 addr_high = er32(RAH(i));
1870 if (!(addr_high & E1000_RAH_AV))
1871 continue;
1872 addr_low = er32(RAL(i));
1873 mac_addr[0] = (addr_low & 0xFF);
1874 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1875 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1876 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1877 mac_addr[4] = (addr_high & 0xFF);
1878 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1879
Bruce Allanfe46f582011-01-06 14:29:51 +00001880 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00001881 }
1882
1883 /* Write Rx addresses to the PHY */
1884 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1885
1886 /* Enable jumbo frame workaround in the MAC */
1887 mac_reg = er32(FFLT_DBG);
1888 mac_reg &= ~(1 << 14);
1889 mac_reg |= (7 << 15);
1890 ew32(FFLT_DBG, mac_reg);
1891
1892 mac_reg = er32(RCTL);
1893 mac_reg |= E1000_RCTL_SECRC;
1894 ew32(RCTL, mac_reg);
1895
1896 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00001897 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1898 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001899 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001900 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001901 ret_val = e1000e_write_kmrn_reg(hw,
1902 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1903 data | (1 << 0));
1904 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001905 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001906 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00001907 E1000_KMRNCTRLSTA_HD_CTRL,
1908 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001909 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001910 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001911 data &= ~(0xF << 8);
1912 data |= (0xB << 8);
1913 ret_val = e1000e_write_kmrn_reg(hw,
1914 E1000_KMRNCTRLSTA_HD_CTRL,
1915 data);
1916 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001917 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001918
1919 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001920 e1e_rphy(hw, PHY_REG(769, 23), &data);
1921 data &= ~(0x7F << 5);
1922 data |= (0x37 << 5);
1923 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1924 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001925 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001926 e1e_rphy(hw, PHY_REG(769, 16), &data);
1927 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00001928 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1929 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001930 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001931 e1e_rphy(hw, PHY_REG(776, 20), &data);
1932 data &= ~(0x3FF << 2);
1933 data |= (0x1A << 2);
1934 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1935 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001936 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00001937 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00001938 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001939 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001940 e1e_rphy(hw, HV_PM_CTRL, &data);
1941 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1942 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001943 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001944 } else {
1945 /* Write MAC register values back to h/w defaults */
1946 mac_reg = er32(FFLT_DBG);
1947 mac_reg &= ~(0xF << 14);
1948 ew32(FFLT_DBG, mac_reg);
1949
1950 mac_reg = er32(RCTL);
1951 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00001952 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00001953
1954 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00001955 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1956 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001957 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001958 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001959 ret_val = e1000e_write_kmrn_reg(hw,
1960 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1961 data & ~(1 << 0));
1962 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001963 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001964 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00001965 E1000_KMRNCTRLSTA_HD_CTRL,
1966 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001967 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001968 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001969 data &= ~(0xF << 8);
1970 data |= (0xB << 8);
1971 ret_val = e1000e_write_kmrn_reg(hw,
1972 E1000_KMRNCTRLSTA_HD_CTRL,
1973 data);
1974 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001975 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001976
1977 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00001978 e1e_rphy(hw, PHY_REG(769, 23), &data);
1979 data &= ~(0x7F << 5);
1980 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1981 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001982 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001983 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001984 data |= (1 << 13);
1985 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1986 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001987 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001988 e1e_rphy(hw, PHY_REG(776, 20), &data);
1989 data &= ~(0x3FF << 2);
1990 data |= (0x8 << 2);
1991 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1992 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001993 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001994 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
1995 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001996 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001997 e1e_rphy(hw, HV_PM_CTRL, &data);
1998 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
1999 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002000 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002001 }
2002
2003 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002004 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002005}
2006
2007/**
2008 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2009 * done after every PHY reset.
2010 **/
2011static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2012{
2013 s32 ret_val = 0;
2014
2015 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002016 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002017
2018 /* Set MDIO slow mode before any other MDIO access */
2019 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002020 if (ret_val)
2021 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002022
Bruce Allan4d241362011-12-16 00:46:06 +00002023 ret_val = hw->phy.ops.acquire(hw);
2024 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002025 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002026 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002027 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002028 if (ret_val)
2029 goto release;
2030 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002031 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002032release:
2033 hw->phy.ops.release(hw);
2034
Bruce Alland3738bb2010-06-16 13:27:28 +00002035 return ret_val;
2036}
2037
2038/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002039 * e1000_k1_gig_workaround_lv - K1 Si workaround
2040 * @hw: pointer to the HW structure
2041 *
2042 * Workaround to set the K1 beacon duration for 82579 parts
2043 **/
2044static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2045{
2046 s32 ret_val = 0;
2047 u16 status_reg = 0;
2048 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002049 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002050
2051 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002052 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002053
2054 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2055 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2056 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002057 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002058
2059 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2060 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2061 mac_reg = er32(FEXTNVM4);
2062 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2063
Bruce Allan0ed013e2011-07-29 05:52:56 +00002064 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2065 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002066 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002067
Bruce Allan0ed013e2011-07-29 05:52:56 +00002068 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002069 u16 pm_phy_reg;
2070
Bruce Allan0ed013e2011-07-29 05:52:56 +00002071 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2072 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002073 /* LV 1G Packet drop issue wa */
2074 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2075 if (ret_val)
2076 return ret_val;
2077 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2078 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2079 if (ret_val)
2080 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002081 } else {
2082 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2083 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2084 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002085 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002086 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002087 }
2088
Bruce Allan831bd2e2010-09-22 17:16:18 +00002089 return ret_val;
2090}
2091
2092/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002093 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2094 * @hw: pointer to the HW structure
2095 * @gate: boolean set to true to gate, false to ungate
2096 *
2097 * Gate/ungate the automatic PHY configuration via hardware; perform
2098 * the configuration via software instead.
2099 **/
2100static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2101{
2102 u32 extcnf_ctrl;
2103
Bruce Allan2fbe4522012-04-19 03:21:47 +00002104 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002105 return;
2106
2107 extcnf_ctrl = er32(EXTCNF_CTRL);
2108
2109 if (gate)
2110 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2111 else
2112 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2113
2114 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002115}
2116
2117/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002118 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2119 * @hw: pointer to the HW structure
2120 *
2121 * Check the appropriate indication the MAC has finished configuring the
2122 * PHY after a software reset.
2123 **/
2124static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2125{
2126 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2127
2128 /* Wait for basic configuration completes before proceeding */
2129 do {
2130 data = er32(STATUS);
2131 data &= E1000_STATUS_LAN_INIT_DONE;
Bruce Allance43a212013-02-20 04:06:32 +00002132 usleep_range(100, 200);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002133 } while ((!data) && --loop);
2134
Bruce Allane921eb12012-11-28 09:28:37 +00002135 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002136 * count reaches 0, loading the configuration from NVM will
2137 * leave the PHY in a bad state possibly resulting in no link.
2138 */
2139 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002140 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002141
2142 /* Clear the Init Done bit for the next init event */
2143 data = er32(STATUS);
2144 data &= ~E1000_STATUS_LAN_INIT_DONE;
2145 ew32(STATUS, data);
2146}
2147
2148/**
Bruce Allane98cac42010-05-10 15:02:32 +00002149 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002150 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002151 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002152static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002153{
Bruce Allanf523d212009-10-29 13:45:45 +00002154 s32 ret_val = 0;
2155 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002156
Bruce Allan44abd5c2012-02-22 09:02:37 +00002157 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002158 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002159
Bruce Allan5f3eed62010-09-22 17:15:54 +00002160 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002161 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002162
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002163 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002164 switch (hw->mac.type) {
2165 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002166 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2167 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002168 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002169 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002170 case e1000_pch2lan:
2171 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2172 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002173 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002174 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002175 default:
2176 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002177 }
2178
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002179 /* Clear the host wakeup bit after lcd reset */
2180 if (hw->mac.type >= e1000_pchlan) {
2181 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2182 reg &= ~BM_WUC_HOST_WU_BIT;
2183 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2184 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002185
Bruce Allanf523d212009-10-29 13:45:45 +00002186 /* Configure the LCD with the extended configuration region in NVM */
2187 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2188 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002189 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190
Bruce Allanf523d212009-10-29 13:45:45 +00002191 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002192 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002193
Bruce Allan1effb452011-02-25 06:58:03 +00002194 if (hw->mac.type == e1000_pch2lan) {
2195 /* Ungate automatic PHY configuration on non-managed 82579 */
2196 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002197 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002198 e1000_gate_hw_phy_config_ich8lan(hw, false);
2199 }
2200
2201 /* Set EEE LPI Update Timer to 200usec */
2202 ret_val = hw->phy.ops.acquire(hw);
2203 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002204 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002205 ret_val = e1000_write_emi_reg_locked(hw,
2206 I82579_LPI_UPDATE_TIMER,
2207 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002208 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002209 }
2210
Bruce Allane98cac42010-05-10 15:02:32 +00002211 return ret_val;
2212}
2213
2214/**
2215 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2216 * @hw: pointer to the HW structure
2217 *
2218 * Resets the PHY
2219 * This is a function pointer entry point called by drivers
2220 * or other shared routines.
2221 **/
2222static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2223{
2224 s32 ret_val = 0;
2225
Bruce Allan605c82b2010-09-22 17:17:01 +00002226 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2227 if ((hw->mac.type == e1000_pch2lan) &&
2228 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2229 e1000_gate_hw_phy_config_ich8lan(hw, true);
2230
Bruce Allane98cac42010-05-10 15:02:32 +00002231 ret_val = e1000e_phy_hw_reset_generic(hw);
2232 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002233 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002234
Bruce Allan5015e532012-02-08 02:55:56 +00002235 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002236}
2237
2238/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002239 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2240 * @hw: pointer to the HW structure
2241 * @active: true to enable LPLU, false to disable
2242 *
2243 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2244 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2245 * the phy speed. This function will manually set the LPLU bit and restart
2246 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2247 * since it configures the same bit.
2248 **/
2249static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2250{
Bruce Allan70806a72013-01-05 05:08:37 +00002251 s32 ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002252 u16 oem_reg;
2253
2254 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2255 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002256 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002257
2258 if (active)
2259 oem_reg |= HV_OEM_BITS_LPLU;
2260 else
2261 oem_reg &= ~HV_OEM_BITS_LPLU;
2262
Bruce Allan44abd5c2012-02-22 09:02:37 +00002263 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002264 oem_reg |= HV_OEM_BITS_RESTART_AN;
2265
Bruce Allan5015e532012-02-08 02:55:56 +00002266 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002267}
2268
2269/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002270 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2271 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002272 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002273 *
2274 * Sets the LPLU D0 state according to the active flag. When
2275 * activating LPLU this function also disables smart speed
2276 * and vice versa. LPLU will not be activated unless the
2277 * device autonegotiation advertisement meets standards of
2278 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2279 * This is a function pointer entry point only called by
2280 * PHY setup routines.
2281 **/
2282static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2283{
2284 struct e1000_phy_info *phy = &hw->phy;
2285 u32 phy_ctrl;
2286 s32 ret_val = 0;
2287 u16 data;
2288
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002289 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002290 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002291
2292 phy_ctrl = er32(PHY_CTRL);
2293
2294 if (active) {
2295 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2296 ew32(PHY_CTRL, phy_ctrl);
2297
Bruce Allan60f12922009-07-01 13:28:14 +00002298 if (phy->type != e1000_phy_igp_3)
2299 return 0;
2300
Bruce Allane921eb12012-11-28 09:28:37 +00002301 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002302 * any PHY registers
2303 */
Bruce Allan60f12922009-07-01 13:28:14 +00002304 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002305 e1000e_gig_downshift_workaround_ich8lan(hw);
2306
2307 /* When LPLU is enabled, we should disable SmartSpeed */
2308 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00002309 if (ret_val)
2310 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002311 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2312 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2313 if (ret_val)
2314 return ret_val;
2315 } else {
2316 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2317 ew32(PHY_CTRL, phy_ctrl);
2318
Bruce Allan60f12922009-07-01 13:28:14 +00002319 if (phy->type != e1000_phy_igp_3)
2320 return 0;
2321
Bruce Allane921eb12012-11-28 09:28:37 +00002322 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002323 * during Dx states where the power conservation is most
2324 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002325 * SmartSpeed, so performance is maintained.
2326 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327 if (phy->smart_speed == e1000_smart_speed_on) {
2328 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002329 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 if (ret_val)
2331 return ret_val;
2332
2333 data |= IGP01E1000_PSCFR_SMART_SPEED;
2334 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002335 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002336 if (ret_val)
2337 return ret_val;
2338 } else if (phy->smart_speed == e1000_smart_speed_off) {
2339 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002340 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341 if (ret_val)
2342 return ret_val;
2343
2344 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2345 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002346 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002347 if (ret_val)
2348 return ret_val;
2349 }
2350 }
2351
2352 return 0;
2353}
2354
2355/**
2356 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2357 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002358 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359 *
2360 * Sets the LPLU D3 state according to the active flag. When
2361 * activating LPLU this function also disables smart speed
2362 * and vice versa. LPLU will not be activated unless the
2363 * device autonegotiation advertisement meets standards of
2364 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2365 * This is a function pointer entry point only called by
2366 * PHY setup routines.
2367 **/
2368static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2369{
2370 struct e1000_phy_info *phy = &hw->phy;
2371 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002372 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002373 u16 data;
2374
2375 phy_ctrl = er32(PHY_CTRL);
2376
2377 if (!active) {
2378 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2379 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002380
2381 if (phy->type != e1000_phy_igp_3)
2382 return 0;
2383
Bruce Allane921eb12012-11-28 09:28:37 +00002384 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002385 * during Dx states where the power conservation is most
2386 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002387 * SmartSpeed, so performance is maintained.
2388 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002390 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2391 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002392 if (ret_val)
2393 return ret_val;
2394
2395 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002396 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2397 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002398 if (ret_val)
2399 return ret_val;
2400 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002401 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2402 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002403 if (ret_val)
2404 return ret_val;
2405
2406 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002407 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2408 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002409 if (ret_val)
2410 return ret_val;
2411 }
2412 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2413 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2414 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2415 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2416 ew32(PHY_CTRL, phy_ctrl);
2417
Bruce Allan60f12922009-07-01 13:28:14 +00002418 if (phy->type != e1000_phy_igp_3)
2419 return 0;
2420
Bruce Allane921eb12012-11-28 09:28:37 +00002421 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002422 * any PHY registers
2423 */
Bruce Allan60f12922009-07-01 13:28:14 +00002424 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002425 e1000e_gig_downshift_workaround_ich8lan(hw);
2426
2427 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002428 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002429 if (ret_val)
2430 return ret_val;
2431
2432 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002433 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434 }
2435
Bruce Alland7eb3382012-02-08 02:55:14 +00002436 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437}
2438
2439/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002440 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2441 * @hw: pointer to the HW structure
2442 * @bank: pointer to the variable that returns the active bank
2443 *
2444 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002445 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002446 **/
2447static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2448{
Bruce Allane2434552008-11-21 17:02:41 -08002449 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002450 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002451 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2452 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002453 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002454 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002455
Bruce Allane2434552008-11-21 17:02:41 -08002456 switch (hw->mac.type) {
2457 case e1000_ich8lan:
2458 case e1000_ich9lan:
2459 eecd = er32(EECD);
2460 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2461 E1000_EECD_SEC1VAL_VALID_MASK) {
2462 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002463 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002464 else
2465 *bank = 0;
2466
2467 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002468 }
Bruce Allan434f1392011-12-16 00:46:54 +00002469 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002470 /* fall-thru */
2471 default:
2472 /* set bank to 0 in case flash read fails */
2473 *bank = 0;
2474
2475 /* Check bank 0 */
2476 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002477 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002478 if (ret_val)
2479 return ret_val;
2480 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2481 E1000_ICH_NVM_SIG_VALUE) {
2482 *bank = 0;
2483 return 0;
2484 }
2485
2486 /* Check bank 1 */
2487 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002488 bank1_offset,
2489 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002490 if (ret_val)
2491 return ret_val;
2492 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2493 E1000_ICH_NVM_SIG_VALUE) {
2494 *bank = 1;
2495 return 0;
2496 }
2497
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002498 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002499 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002500 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002501}
2502
2503/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002504 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2505 * @hw: pointer to the HW structure
2506 * @offset: The offset (in bytes) of the word(s) to read.
2507 * @words: Size of data to read in words
2508 * @data: Pointer to the word(s) to read at offset.
2509 *
2510 * Reads a word(s) from the NVM using the flash access registers.
2511 **/
2512static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2513 u16 *data)
2514{
2515 struct e1000_nvm_info *nvm = &hw->nvm;
2516 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2517 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002518 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002519 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002520 u16 i, word;
2521
2522 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2523 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002524 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002525 ret_val = -E1000_ERR_NVM;
2526 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527 }
2528
Bruce Allan94d81862009-11-20 23:25:26 +00002529 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530
Bruce Allanf4187b52008-08-26 18:36:50 -07002531 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002532 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002533 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002534 bank = 0;
2535 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002536
2537 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002538 act_offset += offset;
2539
Bruce Allan148675a2009-08-07 07:41:56 +00002540 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002542 if (dev_spec->shadow_ram[offset + i].modified) {
2543 data[i] = dev_spec->shadow_ram[offset + i].value;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002544 } else {
2545 ret_val = e1000_read_flash_word_ich8lan(hw,
2546 act_offset + i,
2547 &word);
2548 if (ret_val)
2549 break;
2550 data[i] = word;
2551 }
2552 }
2553
Bruce Allan94d81862009-11-20 23:25:26 +00002554 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002555
Bruce Allane2434552008-11-21 17:02:41 -08002556out:
2557 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002558 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002559
Auke Kokbc7f75f2007-09-17 12:30:59 -07002560 return ret_val;
2561}
2562
2563/**
2564 * e1000_flash_cycle_init_ich8lan - Initialize flash
2565 * @hw: pointer to the HW structure
2566 *
2567 * This function does initial flash setup so that a new read/write/erase cycle
2568 * can be started.
2569 **/
2570static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2571{
2572 union ich8_hws_flash_status hsfsts;
2573 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002574
2575 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2576
2577 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002578 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002579 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002580 return -E1000_ERR_NVM;
2581 }
2582
2583 /* Clear FCERR and DAEL in hw status by writing 1 */
2584 hsfsts.hsf_status.flcerr = 1;
2585 hsfsts.hsf_status.dael = 1;
2586
2587 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2588
Bruce Allane921eb12012-11-28 09:28:37 +00002589 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002590 * bit to check against, in order to start a new cycle or
2591 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002592 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002593 * indication whether a cycle is in progress or has been
2594 * completed.
2595 */
2596
Bruce Allan04499ec2012-04-13 00:08:31 +00002597 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002598 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002599 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002600 * Begin by setting Flash Cycle Done.
2601 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002602 hsfsts.hsf_status.flcdone = 1;
2603 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2604 ret_val = 0;
2605 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002606 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002607
Bruce Allane921eb12012-11-28 09:28:37 +00002608 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002609 * cycle has a chance to end before giving up.
2610 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002612 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002613 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002614 ret_val = 0;
2615 break;
2616 }
2617 udelay(1);
2618 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002619 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002620 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002621 * now set the Flash Cycle Done.
2622 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002623 hsfsts.hsf_status.flcdone = 1;
2624 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2625 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002626 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002627 }
2628 }
2629
2630 return ret_val;
2631}
2632
2633/**
2634 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2635 * @hw: pointer to the HW structure
2636 * @timeout: maximum time to wait for completion
2637 *
2638 * This function starts a flash cycle and waits for its completion.
2639 **/
2640static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2641{
2642 union ich8_hws_flash_ctrl hsflctl;
2643 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002644 u32 i = 0;
2645
2646 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2647 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2648 hsflctl.hsf_ctrl.flcgo = 1;
2649 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2650
2651 /* wait till FDONE bit is set to 1 */
2652 do {
2653 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002654 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002655 break;
2656 udelay(1);
2657 } while (i++ < timeout);
2658
Bruce Allan04499ec2012-04-13 00:08:31 +00002659 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002660 return 0;
2661
Bruce Allan55920b52012-02-08 02:55:25 +00002662 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663}
2664
2665/**
2666 * e1000_read_flash_word_ich8lan - Read word from flash
2667 * @hw: pointer to the HW structure
2668 * @offset: offset to data location
2669 * @data: pointer to the location for storing the data
2670 *
2671 * Reads the flash word at offset into data. Offset is converted
2672 * to bytes before read.
2673 **/
2674static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2675 u16 *data)
2676{
2677 /* Must convert offset into bytes. */
2678 offset <<= 1;
2679
2680 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2681}
2682
2683/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002684 * e1000_read_flash_byte_ich8lan - Read byte from flash
2685 * @hw: pointer to the HW structure
2686 * @offset: The offset of the byte to read.
2687 * @data: Pointer to a byte to store the value read.
2688 *
2689 * Reads a single byte from the NVM using the flash access registers.
2690 **/
2691static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2692 u8 *data)
2693{
2694 s32 ret_val;
2695 u16 word = 0;
2696
2697 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2698 if (ret_val)
2699 return ret_val;
2700
2701 *data = (u8)word;
2702
2703 return 0;
2704}
2705
2706/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002707 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2708 * @hw: pointer to the HW structure
2709 * @offset: The offset (in bytes) of the byte or word to read.
2710 * @size: Size of data to read, 1=byte 2=word
2711 * @data: Pointer to the word to store the value read.
2712 *
2713 * Reads a byte or word from the NVM using the flash access registers.
2714 **/
2715static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2716 u8 size, u16 *data)
2717{
2718 union ich8_hws_flash_status hsfsts;
2719 union ich8_hws_flash_ctrl hsflctl;
2720 u32 flash_linear_addr;
2721 u32 flash_data = 0;
2722 s32 ret_val = -E1000_ERR_NVM;
2723 u8 count = 0;
2724
2725 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2726 return -E1000_ERR_NVM;
2727
Bruce Allanf0ff4392013-02-20 04:05:39 +00002728 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2729 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002730
2731 do {
2732 udelay(1);
2733 /* Steps */
2734 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002735 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002736 break;
2737
2738 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2739 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2740 hsflctl.hsf_ctrl.fldbcount = size - 1;
2741 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2742 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2743
2744 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2745
Bruce Allan17e813e2013-02-20 04:06:01 +00002746 ret_val =
2747 e1000_flash_cycle_ich8lan(hw,
2748 ICH_FLASH_READ_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002749
Bruce Allane921eb12012-11-28 09:28:37 +00002750 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002751 * and try the whole sequence a few more times, else
2752 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002753 * least significant byte first msb to lsb
2754 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002755 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002756 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002757 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002758 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002759 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002760 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002761 break;
2762 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002763 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002764 * completely hosed, but if the error condition is
2765 * detected, it won't hurt to give it another try...
2766 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2767 */
2768 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002769 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002770 /* Repeat for some time before giving up. */
2771 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002772 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002773 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002774 break;
2775 }
2776 }
2777 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2778
2779 return ret_val;
2780}
2781
2782/**
2783 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2784 * @hw: pointer to the HW structure
2785 * @offset: The offset (in bytes) of the word(s) to write.
2786 * @words: Size of data to write in words
2787 * @data: Pointer to the word(s) to write at offset.
2788 *
2789 * Writes a byte or word to the NVM using the flash access registers.
2790 **/
2791static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2792 u16 *data)
2793{
2794 struct e1000_nvm_info *nvm = &hw->nvm;
2795 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002796 u16 i;
2797
2798 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2799 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002800 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002801 return -E1000_ERR_NVM;
2802 }
2803
Bruce Allan94d81862009-11-20 23:25:26 +00002804 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002805
Auke Kokbc7f75f2007-09-17 12:30:59 -07002806 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002807 dev_spec->shadow_ram[offset + i].modified = true;
2808 dev_spec->shadow_ram[offset + i].value = data[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07002809 }
2810
Bruce Allan94d81862009-11-20 23:25:26 +00002811 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002812
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813 return 0;
2814}
2815
2816/**
2817 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2818 * @hw: pointer to the HW structure
2819 *
2820 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2821 * which writes the checksum to the shadow ram. The changes in the shadow
2822 * ram are then committed to the EEPROM by processing each bank at a time
2823 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002824 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002825 * future writes.
2826 **/
2827static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2828{
2829 struct e1000_nvm_info *nvm = &hw->nvm;
2830 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002831 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002832 s32 ret_val;
2833 u16 data;
2834
2835 ret_val = e1000e_update_nvm_checksum_generic(hw);
2836 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002837 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838
2839 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002840 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002841
Bruce Allan94d81862009-11-20 23:25:26 +00002842 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002843
Bruce Allane921eb12012-11-28 09:28:37 +00002844 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002845 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002846 * is going to be written
2847 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002848 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002849 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002850 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002851 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002852 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002853
2854 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002855 new_bank_offset = nvm->flash_bank_size;
2856 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002857 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002858 if (ret_val)
2859 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002860 } else {
2861 old_bank_offset = nvm->flash_bank_size;
2862 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002863 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002864 if (ret_val)
2865 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002866 }
2867
2868 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00002869 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002870 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002871 * in the shadow RAM
2872 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002873 if (dev_spec->shadow_ram[i].modified) {
2874 data = dev_spec->shadow_ram[i].value;
2875 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002876 ret_val = e1000_read_flash_word_ich8lan(hw, i +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002877 old_bank_offset,
2878 &data);
Bruce Allane2434552008-11-21 17:02:41 -08002879 if (ret_val)
2880 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002881 }
2882
Bruce Allane921eb12012-11-28 09:28:37 +00002883 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002884 * (15:14) are 11b until the commit has completed.
2885 * This will allow us to write 10b which indicates the
2886 * signature is valid. We want to do this after the write
2887 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002888 * while the write is still in progress
2889 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002890 if (i == E1000_ICH_NVM_SIG_WORD)
2891 data |= E1000_ICH_NVM_SIG_MASK;
2892
2893 /* Convert offset to bytes. */
2894 act_offset = (i + new_bank_offset) << 1;
2895
Bruce Allance43a212013-02-20 04:06:32 +00002896 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002897 /* Write the bytes to the new bank. */
2898 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2899 act_offset,
2900 (u8)data);
2901 if (ret_val)
2902 break;
2903
Bruce Allance43a212013-02-20 04:06:32 +00002904 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002906 act_offset + 1,
2907 (u8)(data >> 8));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002908 if (ret_val)
2909 break;
2910 }
2911
Bruce Allane921eb12012-11-28 09:28:37 +00002912 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07002913 * programming failed.
2914 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002915 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002916 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002917 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002918 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002919 }
2920
Bruce Allane921eb12012-11-28 09:28:37 +00002921 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002922 * to 10b in word 0x13 , this can be done without an
2923 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002924 * and we need to change bit 14 to 0b
2925 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002926 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002927 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002928 if (ret_val)
2929 goto release;
2930
Auke Kokbc7f75f2007-09-17 12:30:59 -07002931 data &= 0xBFFF;
2932 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2933 act_offset * 2 + 1,
2934 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002935 if (ret_val)
2936 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002937
Bruce Allane921eb12012-11-28 09:28:37 +00002938 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002939 * its signature word (0x13) high_byte to 0b. This can be
2940 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002941 * to 1's. We can write 1's to 0's without an erase
2942 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002943 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2944 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002945 if (ret_val)
2946 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947
2948 /* Great! Everything worked, we can now clear the cached entries. */
2949 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002950 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002951 dev_spec->shadow_ram[i].value = 0xFFFF;
2952 }
2953
Bruce Allan9c5e2092010-05-10 15:00:31 +00002954release:
Bruce Allan94d81862009-11-20 23:25:26 +00002955 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002956
Bruce Allane921eb12012-11-28 09:28:37 +00002957 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002958 * until after the next adapter reset.
2959 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002960 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00002961 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00002962 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002963 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002964
Bruce Allane2434552008-11-21 17:02:41 -08002965out:
2966 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002967 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002968
Auke Kokbc7f75f2007-09-17 12:30:59 -07002969 return ret_val;
2970}
2971
2972/**
2973 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2974 * @hw: pointer to the HW structure
2975 *
2976 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2977 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
2978 * calculated, in which case we need to calculate the checksum and set bit 6.
2979 **/
2980static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2981{
2982 s32 ret_val;
2983 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00002984 u16 word;
2985 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002986
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00002987 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
2988 * the checksum needs to be fixed. This bit is an indication that
2989 * the NVM was prepared by OEM software and did not calculate
2990 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002991 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00002992 switch (hw->mac.type) {
2993 case e1000_pch_lpt:
2994 word = NVM_COMPAT;
2995 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
2996 break;
2997 default:
2998 word = NVM_FUTURE_INIT_WORD1;
2999 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3000 break;
3001 }
3002
3003 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003004 if (ret_val)
3005 return ret_val;
3006
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003007 if (!(data & valid_csum_mask)) {
3008 data |= valid_csum_mask;
3009 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003010 if (ret_val)
3011 return ret_val;
3012 ret_val = e1000e_update_nvm_checksum(hw);
3013 if (ret_val)
3014 return ret_val;
3015 }
3016
3017 return e1000e_validate_nvm_checksum_generic(hw);
3018}
3019
3020/**
Bruce Allan4a770352008-10-01 17:18:35 -07003021 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3022 * @hw: pointer to the HW structure
3023 *
3024 * To prevent malicious write/erase of the NVM, set it to be read-only
3025 * so that the hardware ignores all write/erase cycles of the NVM via
3026 * the flash control registers. The shadow-ram copy of the NVM will
3027 * still be updated, however any updates to this copy will not stick
3028 * across driver reloads.
3029 **/
3030void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3031{
Bruce Allanca15df52009-10-26 11:23:43 +00003032 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003033 union ich8_flash_protected_range pr0;
3034 union ich8_hws_flash_status hsfsts;
3035 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003036
Bruce Allan94d81862009-11-20 23:25:26 +00003037 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003038
3039 gfpreg = er32flash(ICH_FLASH_GFPREG);
3040
3041 /* Write-protect GbE Sector of NVM */
3042 pr0.regval = er32flash(ICH_FLASH_PR0);
3043 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3044 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3045 pr0.range.wpe = true;
3046 ew32flash(ICH_FLASH_PR0, pr0.regval);
3047
Bruce Allane921eb12012-11-28 09:28:37 +00003048 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003049 * PR0 to prevent the write-protection from being lifted.
3050 * Once FLOCKDN is set, the registers protected by it cannot
3051 * be written until FLOCKDN is cleared by a hardware reset.
3052 */
3053 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3054 hsfsts.hsf_status.flockdn = true;
3055 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3056
Bruce Allan94d81862009-11-20 23:25:26 +00003057 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003058}
3059
3060/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003061 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3062 * @hw: pointer to the HW structure
3063 * @offset: The offset (in bytes) of the byte/word to read.
3064 * @size: Size of data to read, 1=byte 2=word
3065 * @data: The byte(s) to write to the NVM.
3066 *
3067 * Writes one/two bytes to the NVM using the flash access registers.
3068 **/
3069static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3070 u8 size, u16 data)
3071{
3072 union ich8_hws_flash_status hsfsts;
3073 union ich8_hws_flash_ctrl hsflctl;
3074 u32 flash_linear_addr;
3075 u32 flash_data = 0;
3076 s32 ret_val;
3077 u8 count = 0;
3078
3079 if (size < 1 || size > 2 || data > size * 0xff ||
3080 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3081 return -E1000_ERR_NVM;
3082
Bruce Allanf0ff4392013-02-20 04:05:39 +00003083 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3084 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003085
3086 do {
3087 udelay(1);
3088 /* Steps */
3089 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3090 if (ret_val)
3091 break;
3092
3093 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3094 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
Bruce Allan362e20c2013-02-20 04:05:45 +00003095 hsflctl.hsf_ctrl.fldbcount = size - 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003096 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3097 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3098
3099 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3100
3101 if (size == 1)
3102 flash_data = (u32)data & 0x00FF;
3103 else
3104 flash_data = (u32)data;
3105
3106 ew32flash(ICH_FLASH_FDATA0, flash_data);
3107
Bruce Allane921eb12012-11-28 09:28:37 +00003108 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003109 * and try the whole sequence a few more times else done
3110 */
Bruce Allan17e813e2013-02-20 04:06:01 +00003111 ret_val =
3112 e1000_flash_cycle_ich8lan(hw,
3113 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003114 if (!ret_val)
3115 break;
3116
Bruce Allane921eb12012-11-28 09:28:37 +00003117 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003118 * completely hosed, but if the error condition
3119 * is detected, it won't hurt to give it another
3120 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3121 */
3122 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003123 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003124 /* Repeat for some time before giving up. */
3125 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003126 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003127 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003128 break;
3129 }
3130 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3131
3132 return ret_val;
3133}
3134
3135/**
3136 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3137 * @hw: pointer to the HW structure
3138 * @offset: The index of the byte to read.
3139 * @data: The byte to write to the NVM.
3140 *
3141 * Writes a single byte to the NVM using the flash access registers.
3142 **/
3143static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3144 u8 data)
3145{
3146 u16 word = (u16)data;
3147
3148 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3149}
3150
3151/**
3152 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3153 * @hw: pointer to the HW structure
3154 * @offset: The offset of the byte to write.
3155 * @byte: The byte to write to the NVM.
3156 *
3157 * Writes a single byte to the NVM using the flash access registers.
3158 * Goes through a retry algorithm before giving up.
3159 **/
3160static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3161 u32 offset, u8 byte)
3162{
3163 s32 ret_val;
3164 u16 program_retries;
3165
3166 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3167 if (!ret_val)
3168 return ret_val;
3169
3170 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003171 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Bruce Allance43a212013-02-20 04:06:32 +00003172 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003173 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3174 if (!ret_val)
3175 break;
3176 }
3177 if (program_retries == 100)
3178 return -E1000_ERR_NVM;
3179
3180 return 0;
3181}
3182
3183/**
3184 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3185 * @hw: pointer to the HW structure
3186 * @bank: 0 for first bank, 1 for second bank, etc.
3187 *
3188 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3189 * bank N is 4096 * N + flash_reg_addr.
3190 **/
3191static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3192{
3193 struct e1000_nvm_info *nvm = &hw->nvm;
3194 union ich8_hws_flash_status hsfsts;
3195 union ich8_hws_flash_ctrl hsflctl;
3196 u32 flash_linear_addr;
3197 /* bank size is in 16bit words - adjust to bytes */
3198 u32 flash_bank_size = nvm->flash_bank_size * 2;
3199 s32 ret_val;
3200 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003201 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003202
3203 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3204
Bruce Allane921eb12012-11-28 09:28:37 +00003205 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003206 * register
3207 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003208 * consecutive sectors. The start index for the nth Hw sector
3209 * can be calculated as = bank * 4096 + n * 256
3210 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3211 * The start index for the nth Hw sector can be calculated
3212 * as = bank * 4096
3213 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3214 * (ich9 only, otherwise error condition)
3215 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3216 */
3217 switch (hsfsts.hsf_status.berasesz) {
3218 case 0:
3219 /* Hw sector size 256 */
3220 sector_size = ICH_FLASH_SEG_SIZE_256;
3221 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3222 break;
3223 case 1:
3224 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003225 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003226 break;
3227 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003228 sector_size = ICH_FLASH_SEG_SIZE_8K;
3229 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003230 break;
3231 case 3:
3232 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003233 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003234 break;
3235 default:
3236 return -E1000_ERR_NVM;
3237 }
3238
3239 /* Start with the base address, then add the sector offset. */
3240 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003241 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003242
Bruce Allan53aa82d2013-02-20 04:06:06 +00003243 for (j = 0; j < iteration; j++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003244 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00003245 u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
3246
Auke Kokbc7f75f2007-09-17 12:30:59 -07003247 /* Steps */
3248 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3249 if (ret_val)
3250 return ret_val;
3251
Bruce Allane921eb12012-11-28 09:28:37 +00003252 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003253 * Cycle field in hw flash control
3254 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003255 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3256 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3257 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3258
Bruce Allane921eb12012-11-28 09:28:37 +00003259 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003260 * block into Flash Linear address field in Flash
3261 * Address.
3262 */
3263 flash_linear_addr += (j * sector_size);
3264 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3265
Bruce Allan17e813e2013-02-20 04:06:01 +00003266 ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003267 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003268 break;
3269
Bruce Allane921eb12012-11-28 09:28:37 +00003270 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003271 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003272 * a few more times else Done
3273 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003274 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003275 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003276 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003277 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003278 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003279 return ret_val;
3280 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3281 }
3282
3283 return 0;
3284}
3285
3286/**
3287 * e1000_valid_led_default_ich8lan - Set the default LED settings
3288 * @hw: pointer to the HW structure
3289 * @data: Pointer to the LED settings
3290 *
3291 * Reads the LED default settings from the NVM to data. If the NVM LED
3292 * settings is all 0's or F's, set the LED default to a valid LED default
3293 * setting.
3294 **/
3295static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3296{
3297 s32 ret_val;
3298
3299 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3300 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003301 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302 return ret_val;
3303 }
3304
Bruce Allane5fe2542013-02-20 04:06:27 +00003305 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003306 *data = ID_LED_DEFAULT_ICH8LAN;
3307
3308 return 0;
3309}
3310
3311/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003312 * e1000_id_led_init_pchlan - store LED configurations
3313 * @hw: pointer to the HW structure
3314 *
3315 * PCH does not control LEDs via the LEDCTL register, rather it uses
3316 * the PHY LED configuration register.
3317 *
3318 * PCH also does not have an "always on" or "always off" mode which
3319 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003320 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003321 * use "link_up" mode. The LEDs will still ID on request if there is no
3322 * link based on logic in e1000_led_[on|off]_pchlan().
3323 **/
3324static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3325{
3326 struct e1000_mac_info *mac = &hw->mac;
3327 s32 ret_val;
3328 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3329 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3330 u16 data, i, temp, shift;
3331
3332 /* Get default ID LED modes */
3333 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3334 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003335 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003336
3337 mac->ledctl_default = er32(LEDCTL);
3338 mac->ledctl_mode1 = mac->ledctl_default;
3339 mac->ledctl_mode2 = mac->ledctl_default;
3340
3341 for (i = 0; i < 4; i++) {
3342 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3343 shift = (i * 5);
3344 switch (temp) {
3345 case ID_LED_ON1_DEF2:
3346 case ID_LED_ON1_ON2:
3347 case ID_LED_ON1_OFF2:
3348 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3349 mac->ledctl_mode1 |= (ledctl_on << shift);
3350 break;
3351 case ID_LED_OFF1_DEF2:
3352 case ID_LED_OFF1_ON2:
3353 case ID_LED_OFF1_OFF2:
3354 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3355 mac->ledctl_mode1 |= (ledctl_off << shift);
3356 break;
3357 default:
3358 /* Do nothing */
3359 break;
3360 }
3361 switch (temp) {
3362 case ID_LED_DEF1_ON2:
3363 case ID_LED_ON1_ON2:
3364 case ID_LED_OFF1_ON2:
3365 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3366 mac->ledctl_mode2 |= (ledctl_on << shift);
3367 break;
3368 case ID_LED_DEF1_OFF2:
3369 case ID_LED_ON1_OFF2:
3370 case ID_LED_OFF1_OFF2:
3371 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3372 mac->ledctl_mode2 |= (ledctl_off << shift);
3373 break;
3374 default:
3375 /* Do nothing */
3376 break;
3377 }
3378 }
3379
Bruce Allan5015e532012-02-08 02:55:56 +00003380 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003381}
3382
3383/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003384 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3385 * @hw: pointer to the HW structure
3386 *
3387 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3388 * register, so the the bus width is hard coded.
3389 **/
3390static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3391{
3392 struct e1000_bus_info *bus = &hw->bus;
3393 s32 ret_val;
3394
3395 ret_val = e1000e_get_bus_info_pcie(hw);
3396
Bruce Allane921eb12012-11-28 09:28:37 +00003397 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003398 * a configuration space, but do not contain
3399 * PCI Express Capability registers, so bus width
3400 * must be hardcoded.
3401 */
3402 if (bus->width == e1000_bus_width_unknown)
3403 bus->width = e1000_bus_width_pcie_x1;
3404
3405 return ret_val;
3406}
3407
3408/**
3409 * e1000_reset_hw_ich8lan - Reset the hardware
3410 * @hw: pointer to the HW structure
3411 *
3412 * Does a full reset of the hardware which includes a reset of the PHY and
3413 * MAC.
3414 **/
3415static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3416{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003417 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003418 u16 kum_cfg;
3419 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003420 s32 ret_val;
3421
Bruce Allane921eb12012-11-28 09:28:37 +00003422 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003423 * on the last TLP read/write transaction when MAC is reset.
3424 */
3425 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003426 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003427 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003428
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003429 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003430 ew32(IMC, 0xffffffff);
3431
Bruce Allane921eb12012-11-28 09:28:37 +00003432 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003433 * any pending transactions to complete before we hit the MAC
3434 * with the global reset.
3435 */
3436 ew32(RCTL, 0);
3437 ew32(TCTL, E1000_TCTL_PSP);
3438 e1e_flush();
3439
Bruce Allan1bba4382011-03-19 00:27:20 +00003440 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003441
3442 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3443 if (hw->mac.type == e1000_ich8lan) {
3444 /* Set Tx and Rx buffer allocation to 8k apiece. */
3445 ew32(PBA, E1000_PBA_8K);
3446 /* Set Packet Buffer Size to 16k. */
3447 ew32(PBS, E1000_PBS_16K);
3448 }
3449
Bruce Allan1d5846b2009-10-29 13:46:05 +00003450 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003451 /* Save the NVM K1 bit setting */
3452 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003453 if (ret_val)
3454 return ret_val;
3455
Bruce Allan62bc8132012-03-20 03:47:57 +00003456 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003457 dev_spec->nvm_k1_enabled = true;
3458 else
3459 dev_spec->nvm_k1_enabled = false;
3460 }
3461
Auke Kokbc7f75f2007-09-17 12:30:59 -07003462 ctrl = er32(CTRL);
3463
Bruce Allan44abd5c2012-02-22 09:02:37 +00003464 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003465 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003466 * time to make sure the interface between MAC and the
3467 * external PHY is reset.
3468 */
3469 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003470
Bruce Allane921eb12012-11-28 09:28:37 +00003471 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003472 * non-managed 82579
3473 */
3474 if ((hw->mac.type == e1000_pch2lan) &&
3475 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3476 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003477 }
3478 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003479 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003480 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003481 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003482 msleep(20);
3483
Bruce Allan62bc8132012-03-20 03:47:57 +00003484 /* Set Phy Config Counter to 50msec */
3485 if (hw->mac.type == e1000_pch2lan) {
3486 reg = er32(FEXTNVM3);
3487 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3488 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3489 ew32(FEXTNVM3, reg);
3490 }
3491
Bruce Allanfc0c7762009-07-01 13:27:55 +00003492 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003493 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003494
Bruce Allane98cac42010-05-10 15:02:32 +00003495 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003496 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003497 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003498 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003499
Bruce Allane98cac42010-05-10 15:02:32 +00003500 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003501 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003502 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003503 }
Bruce Allane98cac42010-05-10 15:02:32 +00003504
Bruce Allane921eb12012-11-28 09:28:37 +00003505 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003506 * will be detected as a CRC error and be dropped rather than show up
3507 * as a bad packet to the DMA engine.
3508 */
3509 if (hw->mac.type == e1000_pchlan)
3510 ew32(CRC_OFFSET, 0x65656565);
3511
Auke Kokbc7f75f2007-09-17 12:30:59 -07003512 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003513 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003514
Bruce Allan62bc8132012-03-20 03:47:57 +00003515 reg = er32(KABGTXD);
3516 reg |= E1000_KABGTXD_BGSQLBIAS;
3517 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003518
Bruce Allan5015e532012-02-08 02:55:56 +00003519 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003520}
3521
3522/**
3523 * e1000_init_hw_ich8lan - Initialize the hardware
3524 * @hw: pointer to the HW structure
3525 *
3526 * Prepares the hardware for transmit and receive by doing the following:
3527 * - initialize hardware bits
3528 * - initialize LED identification
3529 * - setup receive address registers
3530 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003531 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003532 * - clear statistics
3533 **/
3534static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3535{
3536 struct e1000_mac_info *mac = &hw->mac;
3537 u32 ctrl_ext, txdctl, snoop;
3538 s32 ret_val;
3539 u16 i;
3540
3541 e1000_initialize_hw_bits_ich8lan(hw);
3542
3543 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003544 ret_val = mac->ops.id_led_init(hw);
Bruce Allan33550ce2013-02-20 04:06:16 +00003545 /* An error is not fatal and we should not stop init due to this */
Bruce Allande39b752009-11-20 23:27:59 +00003546 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003547 e_dbg("Error initializing identification LED\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003548
3549 /* Setup the receive address. */
3550 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3551
3552 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003553 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003554 for (i = 0; i < mac->mta_reg_count; i++)
3555 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3556
Bruce Allane921eb12012-11-28 09:28:37 +00003557 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003558 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003559 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3560 */
3561 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003562 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3563 i &= ~BM_WUC_HOST_WU_BIT;
3564 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003565 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3566 if (ret_val)
3567 return ret_val;
3568 }
3569
Auke Kokbc7f75f2007-09-17 12:30:59 -07003570 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003571 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003572
3573 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003574 txdctl = er32(TXDCTL(0));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003575 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3576 E1000_TXDCTL_FULL_TX_DESC_WB);
3577 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3578 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003579 ew32(TXDCTL(0), txdctl);
3580 txdctl = er32(TXDCTL(1));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003581 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3582 E1000_TXDCTL_FULL_TX_DESC_WB);
3583 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3584 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003585 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003586
Bruce Allane921eb12012-11-28 09:28:37 +00003587 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003588 * By default, we should use snoop behavior.
3589 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003590 if (mac->type == e1000_ich8lan)
3591 snoop = PCIE_ICH8_SNOOP_ALL;
3592 else
Bruce Allan53aa82d2013-02-20 04:06:06 +00003593 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003594 e1000e_set_pcie_no_snoop(hw, snoop);
3595
3596 ctrl_ext = er32(CTRL_EXT);
3597 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3598 ew32(CTRL_EXT, ctrl_ext);
3599
Bruce Allane921eb12012-11-28 09:28:37 +00003600 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003601 * important that we do this after we have tried to establish link
3602 * because the symbol error count will increment wildly if there
3603 * is no link.
3604 */
3605 e1000_clear_hw_cntrs_ich8lan(hw);
3606
Bruce Allane561a702012-02-08 02:55:46 +00003607 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003608}
Bruce Allanfc830b72013-02-20 04:06:11 +00003609
Auke Kokbc7f75f2007-09-17 12:30:59 -07003610/**
3611 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3612 * @hw: pointer to the HW structure
3613 *
3614 * Sets/Clears required hardware bits necessary for correctly setting up the
3615 * hardware for transmit and receive.
3616 **/
3617static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3618{
3619 u32 reg;
3620
3621 /* Extended Device Control */
3622 reg = er32(CTRL_EXT);
3623 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003624 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3625 if (hw->mac.type >= e1000_pchlan)
3626 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003627 ew32(CTRL_EXT, reg);
3628
3629 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003630 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003631 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003632 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003633
3634 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003635 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003636 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003637 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003638
3639 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003640 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003641 if (hw->mac.type == e1000_ich8lan)
3642 reg |= (1 << 28) | (1 << 29);
3643 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003644 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003645
3646 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003647 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003648 if (er32(TCTL) & E1000_TCTL_MULR)
3649 reg &= ~(1 << 28);
3650 else
3651 reg |= (1 << 28);
3652 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003653 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003654
3655 /* Device Status */
3656 if (hw->mac.type == e1000_ich8lan) {
3657 reg = er32(STATUS);
3658 reg &= ~(1 << 31);
3659 ew32(STATUS, reg);
3660 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003661
Bruce Allane921eb12012-11-28 09:28:37 +00003662 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003663 * traffic, just disable the nfs filtering capability
3664 */
3665 reg = er32(RFCTL);
3666 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003667
Bruce Allane921eb12012-11-28 09:28:37 +00003668 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003669 * IPv6 headers can hang the Rx.
3670 */
3671 if (hw->mac.type == e1000_ich8lan)
3672 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003673 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00003674
3675 /* Enable ECC on Lynxpoint */
3676 if (hw->mac.type == e1000_pch_lpt) {
3677 reg = er32(PBECCSTS);
3678 reg |= E1000_PBECCSTS_ECC_ENABLE;
3679 ew32(PBECCSTS, reg);
3680
3681 reg = er32(CTRL);
3682 reg |= E1000_CTRL_MEHE;
3683 ew32(CTRL, reg);
3684 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003685}
3686
3687/**
3688 * e1000_setup_link_ich8lan - Setup flow control and link settings
3689 * @hw: pointer to the HW structure
3690 *
3691 * Determines which flow control settings to use, then configures flow
3692 * control. Calls the appropriate media-specific link configuration
3693 * function. Assuming the adapter has a valid link partner, a valid link
3694 * should be established. Assumes the hardware has previously been reset
3695 * and the transmitter and receiver are not enabled.
3696 **/
3697static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3698{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003699 s32 ret_val;
3700
Bruce Allan44abd5c2012-02-22 09:02:37 +00003701 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003702 return 0;
3703
Bruce Allane921eb12012-11-28 09:28:37 +00003704 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003705 * the default flow control setting, so we explicitly
3706 * set it to full.
3707 */
Bruce Allan37289d92009-06-02 11:29:37 +00003708 if (hw->fc.requested_mode == e1000_fc_default) {
3709 /* Workaround h/w hang when Tx flow control enabled */
3710 if (hw->mac.type == e1000_pchlan)
3711 hw->fc.requested_mode = e1000_fc_rx_pause;
3712 else
3713 hw->fc.requested_mode = e1000_fc_full;
3714 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003715
Bruce Allane921eb12012-11-28 09:28:37 +00003716 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003717 * on the link partner's capabilities, we may or may not use this mode.
3718 */
3719 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003720
Bruce Allan17e813e2013-02-20 04:06:01 +00003721 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003722
3723 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003724 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003725 if (ret_val)
3726 return ret_val;
3727
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003728 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003729 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003730 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003731 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003732 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003733 ew32(FCRTV_PCH, hw->fc.refresh_time);
3734
Bruce Allan482fed82011-01-06 14:29:49 +00003735 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3736 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003737 if (ret_val)
3738 return ret_val;
3739 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003740
3741 return e1000e_set_fc_watermarks(hw);
3742}
3743
3744/**
3745 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3746 * @hw: pointer to the HW structure
3747 *
3748 * Configures the kumeran interface to the PHY to wait the appropriate time
3749 * when polling the PHY, then call the generic setup_copper_link to finish
3750 * configuring the copper link.
3751 **/
3752static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3753{
3754 u32 ctrl;
3755 s32 ret_val;
3756 u16 reg_data;
3757
3758 ctrl = er32(CTRL);
3759 ctrl |= E1000_CTRL_SLU;
3760 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3761 ew32(CTRL, ctrl);
3762
Bruce Allane921eb12012-11-28 09:28:37 +00003763 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003764 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003765 * this fixes erroneous timeouts at 10Mbps.
3766 */
Bruce Allan07818952009-12-08 07:28:01 +00003767 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003768 if (ret_val)
3769 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003770 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003771 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003772 if (ret_val)
3773 return ret_val;
3774 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003775 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003776 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003777 if (ret_val)
3778 return ret_val;
3779
Bruce Allana4f58f52009-06-02 11:29:18 +00003780 switch (hw->phy.type) {
3781 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003782 ret_val = e1000e_copper_link_setup_igp(hw);
3783 if (ret_val)
3784 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003785 break;
3786 case e1000_phy_bm:
3787 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003788 ret_val = e1000e_copper_link_setup_m88(hw);
3789 if (ret_val)
3790 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003791 break;
3792 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003793 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00003794 ret_val = e1000_copper_link_setup_82577(hw);
3795 if (ret_val)
3796 return ret_val;
3797 break;
3798 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003799 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003800 if (ret_val)
3801 return ret_val;
3802
3803 reg_data &= ~IFE_PMC_AUTO_MDIX;
3804
3805 switch (hw->phy.mdix) {
3806 case 1:
3807 reg_data &= ~IFE_PMC_FORCE_MDIX;
3808 break;
3809 case 2:
3810 reg_data |= IFE_PMC_FORCE_MDIX;
3811 break;
3812 case 0:
3813 default:
3814 reg_data |= IFE_PMC_AUTO_MDIX;
3815 break;
3816 }
Bruce Allan482fed82011-01-06 14:29:49 +00003817 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003818 if (ret_val)
3819 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003820 break;
3821 default:
3822 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003823 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003824
Auke Kokbc7f75f2007-09-17 12:30:59 -07003825 return e1000e_setup_copper_link(hw);
3826}
3827
3828/**
Bruce Allanea8179a2013-03-06 09:02:47 +00003829 * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
3830 * @hw: pointer to the HW structure
3831 *
3832 * Calls the PHY specific link setup function and then calls the
3833 * generic setup_copper_link to finish configuring the link for
3834 * Lynxpoint PCH devices
3835 **/
3836static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
3837{
3838 u32 ctrl;
3839 s32 ret_val;
3840
3841 ctrl = er32(CTRL);
3842 ctrl |= E1000_CTRL_SLU;
3843 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3844 ew32(CTRL, ctrl);
3845
3846 ret_val = e1000_copper_link_setup_82577(hw);
3847 if (ret_val)
3848 return ret_val;
3849
3850 return e1000e_setup_copper_link(hw);
3851}
3852
3853/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003854 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3855 * @hw: pointer to the HW structure
3856 * @speed: pointer to store current link speed
3857 * @duplex: pointer to store the current link duplex
3858 *
Bruce Allanad680762008-03-28 09:15:03 -07003859 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003860 * information and then calls the Kumeran lock loss workaround for links at
3861 * gigabit speeds.
3862 **/
3863static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3864 u16 *duplex)
3865{
3866 s32 ret_val;
3867
3868 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3869 if (ret_val)
3870 return ret_val;
3871
3872 if ((hw->mac.type == e1000_ich8lan) &&
Bruce Allane5fe2542013-02-20 04:06:27 +00003873 (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003874 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3875 }
3876
3877 return ret_val;
3878}
3879
3880/**
3881 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3882 * @hw: pointer to the HW structure
3883 *
3884 * Work-around for 82566 Kumeran PCS lock loss:
3885 * On link status change (i.e. PCI reset, speed change) and link is up and
3886 * speed is gigabit-
3887 * 0) if workaround is optionally disabled do nothing
3888 * 1) wait 1ms for Kumeran link to come up
3889 * 2) check Kumeran Diagnostic register PCS lock loss bit
3890 * 3) if not set the link is locked (all is good), otherwise...
3891 * 4) reset the PHY
3892 * 5) repeat up to 10 times
3893 * Note: this is only called for IGP3 copper when speed is 1gb.
3894 **/
3895static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3896{
3897 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3898 u32 phy_ctrl;
3899 s32 ret_val;
3900 u16 i, data;
3901 bool link;
3902
3903 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3904 return 0;
3905
Bruce Allane921eb12012-11-28 09:28:37 +00003906 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003907 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003908 * stability
3909 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003910 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3911 if (!link)
3912 return 0;
3913
3914 for (i = 0; i < 10; i++) {
3915 /* read once to clear */
3916 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3917 if (ret_val)
3918 return ret_val;
3919 /* and again to get new status */
3920 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3921 if (ret_val)
3922 return ret_val;
3923
3924 /* check for PCS lock */
3925 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3926 return 0;
3927
3928 /* Issue PHY reset */
3929 e1000_phy_hw_reset(hw);
3930 mdelay(5);
3931 }
3932 /* Disable GigE link negotiation */
3933 phy_ctrl = er32(PHY_CTRL);
3934 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3935 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3936 ew32(PHY_CTRL, phy_ctrl);
3937
Bruce Allane921eb12012-11-28 09:28:37 +00003938 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07003939 * any PHY registers
3940 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003941 e1000e_gig_downshift_workaround_ich8lan(hw);
3942
3943 /* unable to acquire PCS lock */
3944 return -E1000_ERR_PHY;
3945}
3946
3947/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00003948 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003949 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003950 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003951 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003952 * If ICH8, set the current Kumeran workaround state (enabled - true
3953 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003954 **/
3955void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00003956 bool state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003957{
3958 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3959
3960 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003961 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003962 return;
3963 }
3964
3965 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3966}
3967
3968/**
3969 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3970 * @hw: pointer to the HW structure
3971 *
3972 * Workaround for 82566 power-down on D3 entry:
3973 * 1) disable gigabit link
3974 * 2) write VR power-down enable
3975 * 3) read it back
3976 * Continue if successful, else issue LCD reset and repeat
3977 **/
3978void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3979{
3980 u32 reg;
3981 u16 data;
3982 u8 retry = 0;
3983
3984 if (hw->phy.type != e1000_phy_igp_3)
3985 return;
3986
3987 /* Try the workaround twice (if needed) */
3988 do {
3989 /* Disable link */
3990 reg = er32(PHY_CTRL);
3991 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3992 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3993 ew32(PHY_CTRL, reg);
3994
Bruce Allane921eb12012-11-28 09:28:37 +00003995 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07003996 * accessing any PHY registers
3997 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003998 if (hw->mac.type == e1000_ich8lan)
3999 e1000e_gig_downshift_workaround_ich8lan(hw);
4000
4001 /* Write VR power-down enable */
4002 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4003 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4004 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4005
4006 /* Read it back and test */
4007 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4008 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4009 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4010 break;
4011
4012 /* Issue PHY reset and repeat at most one more time */
4013 reg = er32(CTRL);
4014 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4015 retry++;
4016 } while (retry);
4017}
4018
4019/**
4020 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4021 * @hw: pointer to the HW structure
4022 *
4023 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004024 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004025 * 1) Set Kumeran Near-end loopback
4026 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004027 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004028 **/
4029void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4030{
4031 s32 ret_val;
4032 u16 reg_data;
4033
Bruce Allan462d5992011-09-30 08:07:11 +00004034 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004035 return;
4036
4037 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004038 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039 if (ret_val)
4040 return;
4041 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4042 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004043 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004044 if (ret_val)
4045 return;
4046 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00004047 e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004048}
4049
4050/**
Bruce Allan99730e42011-05-13 07:19:48 +00004051 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004052 * @hw: pointer to the HW structure
4053 *
4054 * During S0 to Sx transition, it is possible the link remains at gig
4055 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004056 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4057 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4058 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4059 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004060 * Parts that support (and are linked to a partner which support) EEE in
4061 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4062 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004063 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004064void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004065{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004066 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004067 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004068 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004069
Bruce Allan17f085d2010-06-17 18:59:48 +00004070 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004071 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allane08f6262013-02-20 03:06:34 +00004072
Bruce Allan2fbe4522012-04-19 03:21:47 +00004073 if (hw->phy.type == e1000_phy_i217) {
Bruce Allane08f6262013-02-20 03:06:34 +00004074 u16 phy_reg, device_id = hw->adapter->pdev->device;
4075
4076 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
4077 (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V)) {
4078 u32 fextnvm6 = er32(FEXTNVM6);
4079
4080 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
4081 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004082
4083 ret_val = hw->phy.ops.acquire(hw);
4084 if (ret_val)
4085 goto out;
4086
4087 if (!dev_spec->eee_disable) {
4088 u16 eee_advert;
4089
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004090 ret_val =
4091 e1000_read_emi_reg_locked(hw,
4092 I217_EEE_ADVERTISEMENT,
4093 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004094 if (ret_val)
4095 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004096
Bruce Allane921eb12012-11-28 09:28:37 +00004097 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004098 * EEE and 100Full is advertised on both ends of the
4099 * link.
4100 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004101 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004102 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004103 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004104 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4105 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4106 E1000_PHY_CTRL_NOND0A_LPLU);
4107 }
4108
Bruce Allane921eb12012-11-28 09:28:37 +00004109 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004110 * when the system is going into Sx and no manageability engine
4111 * is present, the driver must configure proxy to reset only on
4112 * power good. LPI (Low Power Idle) state must also reset only
4113 * on power good, as well as the MTA (Multicast table array).
4114 * The SMBus release must also be disabled on LCD reset.
4115 */
4116 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00004117 /* Enable proxy to reset only on power good. */
4118 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4119 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4120 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4121
Bruce Allane921eb12012-11-28 09:28:37 +00004122 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004123 * power good.
4124 */
4125 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004126 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004127 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4128
4129 /* Disable the SMB release on LCD reset. */
4130 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004131 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004132 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4133 }
4134
Bruce Allane921eb12012-11-28 09:28:37 +00004135 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004136 * Support
4137 */
4138 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004139 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004140 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4141
4142release:
4143 hw->phy.ops.release(hw);
4144 }
4145out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004146 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004147
Bruce Allan462d5992011-09-30 08:07:11 +00004148 if (hw->mac.type == e1000_ich8lan)
4149 e1000e_gig_downshift_workaround_ich8lan(hw);
4150
Bruce Allan8395ae82010-09-22 17:15:08 +00004151 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004152 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004153
4154 /* Reset PHY to activate OEM bits on 82577/8 */
4155 if (hw->mac.type == e1000_pchlan)
4156 e1000e_phy_hw_reset_generic(hw);
4157
Bruce Allan8395ae82010-09-22 17:15:08 +00004158 ret_val = hw->phy.ops.acquire(hw);
4159 if (ret_val)
4160 return;
4161 e1000_write_smbus_addr(hw);
4162 hw->phy.ops.release(hw);
4163 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004164}
4165
4166/**
Bruce Allan99730e42011-05-13 07:19:48 +00004167 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4168 * @hw: pointer to the HW structure
4169 *
4170 * During Sx to S0 transitions on non-managed devices or managed devices
4171 * on which PHY resets are not blocked, if the PHY registers cannot be
4172 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4173 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004174 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004175 **/
4176void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4177{
Bruce Allan90b82982011-12-16 00:46:33 +00004178 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004179
Bruce Allancb17aab2012-04-13 03:16:22 +00004180 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004181 return;
4182
Bruce Allancb17aab2012-04-13 03:16:22 +00004183 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004184 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004185 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004186 return;
4187 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004188
Bruce Allane921eb12012-11-28 09:28:37 +00004189 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004190 * is transitioning from Sx and no manageability engine is present
4191 * configure SMBus to restore on reset, disable proxy, and enable
4192 * the reset on MTA (Multicast table array).
4193 */
4194 if (hw->phy.type == e1000_phy_i217) {
4195 u16 phy_reg;
4196
4197 ret_val = hw->phy.ops.acquire(hw);
4198 if (ret_val) {
4199 e_dbg("Failed to setup iRST\n");
4200 return;
4201 }
4202
4203 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004204 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004205 * is present
4206 */
4207 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4208 if (ret_val)
4209 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004210 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004211 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4212
4213 /* Disable Proxy */
4214 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4215 }
4216 /* Enable reset on MTA */
4217 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4218 if (ret_val)
4219 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004220 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004221 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4222release:
4223 if (ret_val)
4224 e_dbg("Error %d in resume workarounds\n", ret_val);
4225 hw->phy.ops.release(hw);
4226 }
Bruce Allan99730e42011-05-13 07:19:48 +00004227}
4228
4229/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004230 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4231 * @hw: pointer to the HW structure
4232 *
4233 * Return the LED back to the default configuration.
4234 **/
4235static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4236{
4237 if (hw->phy.type == e1000_phy_ife)
4238 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4239
4240 ew32(LEDCTL, hw->mac.ledctl_default);
4241 return 0;
4242}
4243
4244/**
Auke Kok489815c2008-02-21 15:11:07 -08004245 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 * @hw: pointer to the HW structure
4247 *
Auke Kok489815c2008-02-21 15:11:07 -08004248 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004249 **/
4250static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4251{
4252 if (hw->phy.type == e1000_phy_ife)
4253 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4254 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4255
4256 ew32(LEDCTL, hw->mac.ledctl_mode2);
4257 return 0;
4258}
4259
4260/**
Auke Kok489815c2008-02-21 15:11:07 -08004261 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262 * @hw: pointer to the HW structure
4263 *
Auke Kok489815c2008-02-21 15:11:07 -08004264 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004265 **/
4266static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4267{
4268 if (hw->phy.type == e1000_phy_ife)
4269 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004270 (IFE_PSCL_PROBE_MODE |
4271 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004272
4273 ew32(LEDCTL, hw->mac.ledctl_mode1);
4274 return 0;
4275}
4276
4277/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004278 * e1000_setup_led_pchlan - Configures SW controllable LED
4279 * @hw: pointer to the HW structure
4280 *
4281 * This prepares the SW controllable LED for use.
4282 **/
4283static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4284{
Bruce Allan482fed82011-01-06 14:29:49 +00004285 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004286}
4287
4288/**
4289 * e1000_cleanup_led_pchlan - Restore the default LED operation
4290 * @hw: pointer to the HW structure
4291 *
4292 * Return the LED back to the default configuration.
4293 **/
4294static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4295{
Bruce Allan482fed82011-01-06 14:29:49 +00004296 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004297}
4298
4299/**
4300 * e1000_led_on_pchlan - Turn LEDs on
4301 * @hw: pointer to the HW structure
4302 *
4303 * Turn on the LEDs.
4304 **/
4305static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4306{
4307 u16 data = (u16)hw->mac.ledctl_mode2;
4308 u32 i, led;
4309
Bruce Allane921eb12012-11-28 09:28:37 +00004310 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004311 * for each LED that's mode is "link_up" in ledctl_mode2.
4312 */
4313 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4314 for (i = 0; i < 3; i++) {
4315 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4316 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4317 E1000_LEDCTL_MODE_LINK_UP)
4318 continue;
4319 if (led & E1000_PHY_LED0_IVRT)
4320 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4321 else
4322 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4323 }
4324 }
4325
Bruce Allan482fed82011-01-06 14:29:49 +00004326 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004327}
4328
4329/**
4330 * e1000_led_off_pchlan - Turn LEDs off
4331 * @hw: pointer to the HW structure
4332 *
4333 * Turn off the LEDs.
4334 **/
4335static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4336{
4337 u16 data = (u16)hw->mac.ledctl_mode1;
4338 u32 i, led;
4339
Bruce Allane921eb12012-11-28 09:28:37 +00004340 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004341 * for each LED that's mode is "link_up" in ledctl_mode1.
4342 */
4343 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4344 for (i = 0; i < 3; i++) {
4345 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4346 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4347 E1000_LEDCTL_MODE_LINK_UP)
4348 continue;
4349 if (led & E1000_PHY_LED0_IVRT)
4350 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4351 else
4352 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4353 }
4354 }
4355
Bruce Allan482fed82011-01-06 14:29:49 +00004356 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004357}
4358
4359/**
Bruce Allane98cac42010-05-10 15:02:32 +00004360 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004361 * @hw: pointer to the HW structure
4362 *
Bruce Allane98cac42010-05-10 15:02:32 +00004363 * Read appropriate register for the config done bit for completion status
4364 * and configure the PHY through s/w for EEPROM-less parts.
4365 *
4366 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4367 * config done bit, so only an error is logged and continues. If we were
4368 * to return with error, EEPROM-less silicon would not be able to be reset
4369 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004370 **/
4371static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4372{
Bruce Allane98cac42010-05-10 15:02:32 +00004373 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004374 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004375 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004376
Bruce Allanfe908492013-01-05 08:06:14 +00004377 e1000e_get_cfg_done_generic(hw);
Bruce Allanf4187b52008-08-26 18:36:50 -07004378
Bruce Allane98cac42010-05-10 15:02:32 +00004379 /* Wait for indication from h/w that it has completed basic config */
4380 if (hw->mac.type >= e1000_ich10lan) {
4381 e1000_lan_init_done_ich8lan(hw);
4382 } else {
4383 ret_val = e1000e_get_auto_rd_done(hw);
4384 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004385 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004386 * return with an error. This can happen in situations
4387 * where there is no eeprom and prevents getting link.
4388 */
4389 e_dbg("Auto Read Done did not complete\n");
4390 ret_val = 0;
4391 }
4392 }
4393
4394 /* Clear PHY Reset Asserted bit */
4395 status = er32(STATUS);
4396 if (status & E1000_STATUS_PHYRA)
4397 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4398 else
4399 e_dbg("PHY Reset Asserted not set - needs delay\n");
4400
Bruce Allanf4187b52008-08-26 18:36:50 -07004401 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004402 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004403 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004404 (hw->phy.type == e1000_phy_igp_3)) {
4405 e1000e_phy_init_script_igp3(hw);
4406 }
4407 } else {
4408 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4409 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004410 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004411 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004412 }
4413 }
4414
Bruce Allane98cac42010-05-10 15:02:32 +00004415 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004416}
4417
4418/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004419 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4420 * @hw: pointer to the HW structure
4421 *
4422 * In the case of a PHY power down to save power, or to turn off link during a
4423 * driver unload, or wake on lan is not enabled, remove the link.
4424 **/
4425static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4426{
4427 /* If the management interface is not enabled, then power down */
4428 if (!(hw->mac.ops.check_mng_mode(hw) ||
4429 hw->phy.ops.check_reset_block(hw)))
4430 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004431}
4432
4433/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004434 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4435 * @hw: pointer to the HW structure
4436 *
4437 * Clears hardware counters specific to the silicon family and calls
4438 * clear_hw_cntrs_generic to clear all general purpose counters.
4439 **/
4440static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4441{
Bruce Allana4f58f52009-06-02 11:29:18 +00004442 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004443 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004444
4445 e1000e_clear_hw_cntrs_base(hw);
4446
Bruce Allan99673d92009-11-20 23:27:21 +00004447 er32(ALGNERRC);
4448 er32(RXERRC);
4449 er32(TNCRS);
4450 er32(CEXTERR);
4451 er32(TSCTC);
4452 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004453
Bruce Allan99673d92009-11-20 23:27:21 +00004454 er32(MGTPRC);
4455 er32(MGTPDC);
4456 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004457
Bruce Allan99673d92009-11-20 23:27:21 +00004458 er32(IAC);
4459 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004460
Bruce Allana4f58f52009-06-02 11:29:18 +00004461 /* Clear PHY statistics registers */
4462 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004463 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004464 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004465 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004466 ret_val = hw->phy.ops.acquire(hw);
4467 if (ret_val)
4468 return;
4469 ret_val = hw->phy.ops.set_page(hw,
4470 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4471 if (ret_val)
4472 goto release;
4473 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4474 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4475 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4476 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4477 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4478 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4479 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4480 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4481 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4482 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4483 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4484 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4485 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4486 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4487release:
4488 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004489 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004490}
4491
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004492static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004493 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004494 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004495 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004496 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4497 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004498 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004499 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004500 /* led_on dependent on mac type */
4501 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004502 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004503 .reset_hw = e1000_reset_hw_ich8lan,
4504 .init_hw = e1000_init_hw_ich8lan,
4505 .setup_link = e1000_setup_link_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004506 .setup_physical_interface = e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004507 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004508 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004509 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004510};
4511
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004512static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004513 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004514 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004515 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004516 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004517 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004518 .read_reg = e1000e_read_phy_reg_igp,
4519 .release = e1000_release_swflag_ich8lan,
4520 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004521 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4522 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004523 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004524};
4525
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004526static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004527 .acquire = e1000_acquire_nvm_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004528 .read = e1000_read_nvm_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004529 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004530 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004531 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004532 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004533 .validate = e1000_validate_nvm_checksum_ich8lan,
4534 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004535};
4536
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004537const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004538 .mac = e1000_ich8lan,
4539 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004540 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004541 | FLAG_HAS_CTRLEXT_ON_LOAD
4542 | FLAG_HAS_AMT
4543 | FLAG_HAS_FLASH
4544 | FLAG_APME_IN_WUC,
4545 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004546 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004547 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004548 .mac_ops = &ich8_mac_ops,
4549 .phy_ops = &ich8_phy_ops,
4550 .nvm_ops = &ich8_nvm_ops,
4551};
4552
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004553const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004554 .mac = e1000_ich9lan,
4555 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004556 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004558 | FLAG_HAS_CTRLEXT_ON_LOAD
4559 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004560 | FLAG_HAS_FLASH
4561 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004562 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004563 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004564 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004565 .mac_ops = &ich8_mac_ops,
4566 .phy_ops = &ich8_phy_ops,
4567 .nvm_ops = &ich8_nvm_ops,
4568};
4569
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004570const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004571 .mac = e1000_ich10lan,
4572 .flags = FLAG_HAS_JUMBO_FRAMES
4573 | FLAG_IS_ICH
4574 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004575 | FLAG_HAS_CTRLEXT_ON_LOAD
4576 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004577 | FLAG_HAS_FLASH
4578 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004579 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004580 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004581 .get_variants = e1000_get_variants_ich8lan,
4582 .mac_ops = &ich8_mac_ops,
4583 .phy_ops = &ich8_phy_ops,
4584 .nvm_ops = &ich8_nvm_ops,
4585};
Bruce Allana4f58f52009-06-02 11:29:18 +00004586
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004587const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004588 .mac = e1000_pchlan,
4589 .flags = FLAG_IS_ICH
4590 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004591 | FLAG_HAS_CTRLEXT_ON_LOAD
4592 | FLAG_HAS_AMT
4593 | FLAG_HAS_FLASH
4594 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004595 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004596 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004597 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004598 .pba = 26,
4599 .max_hw_frame_size = 4096,
4600 .get_variants = e1000_get_variants_ich8lan,
4601 .mac_ops = &ich8_mac_ops,
4602 .phy_ops = &ich8_phy_ops,
4603 .nvm_ops = &ich8_nvm_ops,
4604};
Bruce Alland3738bb2010-06-16 13:27:28 +00004605
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004606const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004607 .mac = e1000_pch2lan,
4608 .flags = FLAG_IS_ICH
4609 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004610 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00004611 | FLAG_HAS_CTRLEXT_ON_LOAD
4612 | FLAG_HAS_AMT
4613 | FLAG_HAS_FLASH
4614 | FLAG_HAS_JUMBO_FRAMES
4615 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004616 .flags2 = FLAG2_HAS_PHY_STATS
4617 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004618 .pba = 26,
Bruce Allanc3d2dbf2013-01-09 01:20:46 +00004619 .max_hw_frame_size = 9018,
Bruce Alland3738bb2010-06-16 13:27:28 +00004620 .get_variants = e1000_get_variants_ich8lan,
4621 .mac_ops = &ich8_mac_ops,
4622 .phy_ops = &ich8_phy_ops,
4623 .nvm_ops = &ich8_nvm_ops,
4624};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004625
4626const struct e1000_info e1000_pch_lpt_info = {
4627 .mac = e1000_pch_lpt,
4628 .flags = FLAG_IS_ICH
4629 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004630 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00004631 | FLAG_HAS_CTRLEXT_ON_LOAD
4632 | FLAG_HAS_AMT
4633 | FLAG_HAS_FLASH
4634 | FLAG_HAS_JUMBO_FRAMES
4635 | FLAG_APME_IN_WUC,
4636 .flags2 = FLAG2_HAS_PHY_STATS
4637 | FLAG2_HAS_EEE,
4638 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00004639 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004640 .get_variants = e1000_get_variants_ich8lan,
4641 .mac_ops = &ich8_mac_ops,
4642 .phy_ops = &ich8_phy_ops,
4643 .nvm_ops = &ich8_nvm_ops,
4644};