blob: 4f2f0f69a48ebf31a9c89b2f36f27c404ace5132 [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);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700145
146static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
147{
148 return readw(hw->flash_address + reg);
149}
150
151static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
152{
153 return readl(hw->flash_address + reg);
154}
155
156static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
157{
158 writew(val, hw->flash_address + reg);
159}
160
161static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
162{
163 writel(val, hw->flash_address + reg);
164}
165
166#define er16flash(reg) __er16flash(hw, (reg))
167#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000168#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
169#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700170
Bruce Allancb17aab2012-04-13 03:16:22 +0000171/**
172 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
173 * @hw: pointer to the HW structure
174 *
175 * Test access to the PHY registers by reading the PHY ID registers. If
176 * the PHY ID is already known (e.g. resume path) compare it with known ID,
177 * otherwise assume the read PHY ID is correct if it is valid.
178 *
179 * Assumes the sw/fw/hw semaphore is already acquired.
180 **/
181static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000182{
Bruce Allana52359b2012-07-14 04:23:58 +0000183 u16 phy_reg = 0;
184 u32 phy_id = 0;
185 s32 ret_val;
186 u16 retry_count;
Bruce Allan99730e42011-05-13 07:19:48 +0000187
Bruce Allana52359b2012-07-14 04:23:58 +0000188 for (retry_count = 0; retry_count < 2; retry_count++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000189 ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000190 if (ret_val || (phy_reg == 0xFFFF))
191 continue;
192 phy_id = (u32)(phy_reg << 16);
193
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000194 ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000195 if (ret_val || (phy_reg == 0xFFFF)) {
196 phy_id = 0;
197 continue;
198 }
199 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
200 break;
201 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000202
Bruce Allancb17aab2012-04-13 03:16:22 +0000203 if (hw->phy.id) {
204 if (hw->phy.id == phy_id)
205 return true;
Bruce Allana52359b2012-07-14 04:23:58 +0000206 } else if (phy_id) {
207 hw->phy.id = phy_id;
208 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allancb17aab2012-04-13 03:16:22 +0000209 return true;
210 }
211
Bruce Allane921eb12012-11-28 09:28:37 +0000212 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000213 * set slow mode and try to get the PHY id again.
214 */
215 hw->phy.ops.release(hw);
216 ret_val = e1000_set_mdio_slow_mode_hv(hw);
217 if (!ret_val)
218 ret_val = e1000e_get_phy_id(hw);
219 hw->phy.ops.acquire(hw);
220
221 return !ret_val;
Bruce Allancb17aab2012-04-13 03:16:22 +0000222}
223
224/**
225 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
226 * @hw: pointer to the HW structure
227 *
228 * Workarounds/flow necessary for PHY initialization during driver load
229 * and resume paths.
230 **/
231static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
232{
233 u32 mac_reg, fwsm = er32(FWSM);
234 s32 ret_val;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000235 u16 phy_reg;
Bruce Allancb17aab2012-04-13 03:16:22 +0000236
Bruce Allan6e928b72012-12-12 04:45:51 +0000237 /* Gate automatic PHY configuration by hardware on managed and
238 * non-managed 82579 and newer adapters.
239 */
240 e1000_gate_hw_phy_config_ich8lan(hw, true);
241
Bruce Allancb17aab2012-04-13 03:16:22 +0000242 ret_val = hw->phy.ops.acquire(hw);
243 if (ret_val) {
244 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000245 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000246 }
247
Bruce Allane921eb12012-11-28 09:28:37 +0000248 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000249 * inaccessible and resetting the PHY is not blocked, toggle the
250 * LANPHYPC Value bit to force the interconnect to PCIe mode.
251 */
252 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000253 case e1000_pch_lpt:
254 if (e1000_phy_is_accessible_pchlan(hw))
255 break;
256
Bruce Allane921eb12012-11-28 09:28:37 +0000257 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000258 * forcing MAC to SMBus mode first.
259 */
260 mac_reg = er32(CTRL_EXT);
261 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
262 ew32(CTRL_EXT, mac_reg);
263
264 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000265 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000266 if (e1000_phy_is_accessible_pchlan(hw)) {
267 if (hw->mac.type == e1000_pch_lpt) {
268 /* Unforce SMBus mode in PHY */
269 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
270 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
271 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
272
273 /* Unforce SMBus mode in MAC */
274 mac_reg = er32(CTRL_EXT);
275 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
276 ew32(CTRL_EXT, mac_reg);
277 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000278 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000279 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000280
281 /* fall-through */
282 case e1000_pchlan:
283 if ((hw->mac.type == e1000_pchlan) &&
284 (fwsm & E1000_ICH_FWSM_FW_VALID))
285 break;
286
287 if (hw->phy.ops.check_reset_block(hw)) {
288 e_dbg("Required LANPHYPC toggle blocked by ME\n");
289 break;
290 }
291
292 e_dbg("Toggling LANPHYPC\n");
293
294 /* Set Phy Config Counter to 50msec */
295 mac_reg = er32(FEXTNVM3);
296 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
297 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
298 ew32(FEXTNVM3, mac_reg);
299
Bruce Allan4e035102013-01-04 09:53:19 +0000300 if (hw->mac.type == e1000_pch_lpt) {
301 /* Toggling LANPHYPC brings the PHY out of SMBus mode
302 * So ensure that the MAC is also out of SMBus mode
303 */
304 mac_reg = er32(CTRL_EXT);
305 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
306 ew32(CTRL_EXT, mac_reg);
307 }
308
Bruce Allancb17aab2012-04-13 03:16:22 +0000309 /* Toggle LANPHYPC Value bit */
310 mac_reg = er32(CTRL);
311 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
312 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
313 ew32(CTRL, mac_reg);
314 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +0000315 usleep_range(10, 20);
Bruce Allancb17aab2012-04-13 03:16:22 +0000316 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
317 ew32(CTRL, mac_reg);
318 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000319 if (hw->mac.type < e1000_pch_lpt) {
320 msleep(50);
321 } else {
322 u16 count = 20;
323 do {
324 usleep_range(5000, 10000);
325 } while (!(er32(CTRL_EXT) &
326 E1000_CTRL_EXT_LPCD) && count--);
327 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000328 break;
329 default:
330 break;
331 }
332
333 hw->phy.ops.release(hw);
334
Bruce Allane921eb12012-11-28 09:28:37 +0000335 /* Reset the PHY before any access to it. Doing so, ensures
Bruce Allancb17aab2012-04-13 03:16:22 +0000336 * that the PHY is in a known good state before we read/write
337 * PHY registers. The generic reset is sufficient here,
338 * because we haven't determined the PHY type yet.
339 */
340 ret_val = e1000e_phy_hw_reset_generic(hw);
341
Bruce Allan6e928b72012-12-12 04:45:51 +0000342out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000343 /* Ungate automatic PHY configuration on non-managed 82579 */
344 if ((hw->mac.type == e1000_pch2lan) &&
345 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
346 usleep_range(10000, 20000);
347 e1000_gate_hw_phy_config_ich8lan(hw, false);
348 }
349
350 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000351}
352
Auke Kokbc7f75f2007-09-17 12:30:59 -0700353/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000354 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
355 * @hw: pointer to the HW structure
356 *
357 * Initialize family-specific PHY parameters and function pointers.
358 **/
359static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
360{
361 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan70806a72013-01-05 05:08:37 +0000362 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000363
364 phy->addr = 1;
365 phy->reset_delay_us = 100;
366
Bruce Allan2b6b1682011-05-13 07:20:09 +0000367 phy->ops.set_page = e1000_set_page_igp;
Bruce Allan94d81862009-11-20 23:25:26 +0000368 phy->ops.read_reg = e1000_read_phy_reg_hv;
369 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000370 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000371 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
372 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000373 phy->ops.write_reg = e1000_write_phy_reg_hv;
374 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000375 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
Bruce Allan17f208d2009-12-01 15:47:22 +0000376 phy->ops.power_up = e1000_power_up_phy_copper;
377 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000378 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
379
380 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000381
382 ret_val = e1000_init_phy_workarounds_pchlan(hw);
383 if (ret_val)
384 return ret_val;
385
386 if (phy->id == e1000_phy_unknown)
387 switch (hw->mac.type) {
388 default:
389 ret_val = e1000e_get_phy_id(hw);
390 if (ret_val)
391 return ret_val;
392 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
393 break;
394 /* fall-through */
395 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000396 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000397 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000398 * set slow mode and try to get the PHY id again.
399 */
400 ret_val = e1000_set_mdio_slow_mode_hv(hw);
401 if (ret_val)
402 return ret_val;
403 ret_val = e1000e_get_phy_id(hw);
404 if (ret_val)
405 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000406 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000407 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000408 phy->type = e1000e_get_phy_type_from_id(phy->id);
409
Bruce Allan0be84012009-12-02 17:03:18 +0000410 switch (phy->type) {
411 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000412 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000413 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000414 phy->ops.check_polarity = e1000_check_polarity_82577;
415 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000416 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000417 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000418 phy->ops.get_info = e1000_get_phy_info_82577;
419 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000420 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000421 case e1000_phy_82578:
422 phy->ops.check_polarity = e1000_check_polarity_m88;
423 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
424 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
425 phy->ops.get_info = e1000e_get_phy_info_m88;
426 break;
427 default:
428 ret_val = -E1000_ERR_PHY;
429 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000430 }
431
432 return ret_val;
433}
434
435/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700436 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
437 * @hw: pointer to the HW structure
438 *
439 * Initialize family-specific PHY parameters and function pointers.
440 **/
441static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
442{
443 struct e1000_phy_info *phy = &hw->phy;
444 s32 ret_val;
445 u16 i = 0;
446
447 phy->addr = 1;
448 phy->reset_delay_us = 100;
449
Bruce Allan17f208d2009-12-01 15:47:22 +0000450 phy->ops.power_up = e1000_power_up_phy_copper;
451 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
452
Bruce Allane921eb12012-11-28 09:28:37 +0000453 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700454 * we'll set BM func pointers and try again
455 */
456 ret_val = e1000e_determine_phy_address(hw);
457 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000458 phy->ops.write_reg = e1000e_write_phy_reg_bm;
459 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700460 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000461 if (ret_val) {
462 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700463 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000464 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700465 }
466
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467 phy->id = 0;
468 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
469 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000470 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700471 ret_val = e1000e_get_phy_id(hw);
472 if (ret_val)
473 return ret_val;
474 }
475
476 /* Verify phy id */
477 switch (phy->id) {
478 case IGP03E1000_E_PHY_ID:
479 phy->type = e1000_phy_igp_3;
480 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000481 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
482 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000483 phy->ops.get_info = e1000e_get_phy_info_igp;
484 phy->ops.check_polarity = e1000_check_polarity_igp;
485 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700486 break;
487 case IFE_E_PHY_ID:
488 case IFE_PLUS_E_PHY_ID:
489 case IFE_C_E_PHY_ID:
490 phy->type = e1000_phy_ife;
491 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000492 phy->ops.get_info = e1000_get_phy_info_ife;
493 phy->ops.check_polarity = e1000_check_polarity_ife;
494 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700495 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700496 case BME1000_E_PHY_ID:
497 phy->type = e1000_phy_bm;
498 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000499 phy->ops.read_reg = e1000e_read_phy_reg_bm;
500 phy->ops.write_reg = e1000e_write_phy_reg_bm;
501 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000502 phy->ops.get_info = e1000e_get_phy_info_m88;
503 phy->ops.check_polarity = e1000_check_polarity_m88;
504 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700505 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700506 default:
507 return -E1000_ERR_PHY;
508 break;
509 }
510
511 return 0;
512}
513
514/**
515 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
516 * @hw: pointer to the HW structure
517 *
518 * Initialize family-specific NVM parameters and function
519 * pointers.
520 **/
521static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
522{
523 struct e1000_nvm_info *nvm = &hw->nvm;
524 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000525 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700526 u16 i;
527
Bruce Allanad680762008-03-28 09:15:03 -0700528 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700529 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000530 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700531 return -E1000_ERR_CONFIG;
532 }
533
534 nvm->type = e1000_nvm_flash_sw;
535
536 gfpreg = er32flash(ICH_FLASH_GFPREG);
537
Bruce Allane921eb12012-11-28 09:28:37 +0000538 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700539 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700540 * the overall size.
541 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700542 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
543 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
544
545 /* flash_base_addr is byte-aligned */
546 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
547
Bruce Allane921eb12012-11-28 09:28:37 +0000548 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700549 * size represents two separate NVM banks.
550 */
Bruce Allanf0ff4392013-02-20 04:05:39 +0000551 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
552 << FLASH_SECTOR_ADDR_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700553 nvm->flash_bank_size /= 2;
554 /* Adjust to word count */
555 nvm->flash_bank_size /= sizeof(u16);
556
557 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
558
559 /* Clear shadow ram */
560 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000561 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562 dev_spec->shadow_ram[i].value = 0xFFFF;
563 }
564
565 return 0;
566}
567
568/**
569 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
570 * @hw: pointer to the HW structure
571 *
572 * Initialize family-specific MAC parameters and function
573 * pointers.
574 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000575static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700576{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577 struct e1000_mac_info *mac = &hw->mac;
578
579 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700580 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700581
582 /* Set mta register count */
583 mac->mta_reg_count = 32;
584 /* Set rar entry count */
585 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
586 if (mac->type == e1000_ich8lan)
587 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000588 /* FWSM register */
589 mac->has_fwsm = true;
590 /* ARC subsystem not supported */
591 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000592 /* Adaptive IFS supported */
593 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700594
Bruce Allan2fbe4522012-04-19 03:21:47 +0000595 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000596 switch (mac->type) {
597 case e1000_ich8lan:
598 case e1000_ich9lan:
599 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000600 /* check management mode */
601 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000602 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000603 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000604 /* blink LED */
605 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000606 /* setup LED */
607 mac->ops.setup_led = e1000e_setup_led_generic;
608 /* cleanup LED */
609 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
610 /* turn on/off LED */
611 mac->ops.led_on = e1000_led_on_ich8lan;
612 mac->ops.led_off = e1000_led_off_ich8lan;
613 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000614 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000615 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
616 mac->ops.rar_set = e1000_rar_set_pch2lan;
617 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000618 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000619 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000620 /* check management mode */
621 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000622 /* ID LED init */
623 mac->ops.id_led_init = e1000_id_led_init_pchlan;
624 /* setup LED */
625 mac->ops.setup_led = e1000_setup_led_pchlan;
626 /* cleanup LED */
627 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
628 /* turn on/off LED */
629 mac->ops.led_on = e1000_led_on_pchlan;
630 mac->ops.led_off = e1000_led_off_pchlan;
631 break;
632 default:
633 break;
634 }
635
Bruce Allan2fbe4522012-04-19 03:21:47 +0000636 if (mac->type == e1000_pch_lpt) {
637 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
638 mac->ops.rar_set = e1000_rar_set_pch_lpt;
639 }
640
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641 /* Enable PCS Lock-loss workaround for ICH8 */
642 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000643 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644
645 return 0;
646}
647
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000648/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000649 * __e1000_access_emi_reg_locked - Read/write EMI register
650 * @hw: pointer to the HW structure
651 * @addr: EMI address to program
652 * @data: pointer to value to read/write from/to the EMI address
653 * @read: boolean flag to indicate read or write
654 *
655 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
656 **/
657static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
658 u16 *data, bool read)
659{
Bruce Allan70806a72013-01-05 05:08:37 +0000660 s32 ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000661
662 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
663 if (ret_val)
664 return ret_val;
665
666 if (read)
667 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
668 else
669 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
670
671 return ret_val;
672}
673
674/**
675 * e1000_read_emi_reg_locked - Read Extended Management Interface register
676 * @hw: pointer to the HW structure
677 * @addr: EMI address to program
678 * @data: value to be read from the EMI address
679 *
680 * Assumes the SW/FW/HW Semaphore is already acquired.
681 **/
Bruce Allan203e4152012-12-05 08:40:59 +0000682s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000683{
684 return __e1000_access_emi_reg_locked(hw, addr, data, true);
685}
686
687/**
688 * e1000_write_emi_reg_locked - Write Extended Management Interface register
689 * @hw: pointer to the HW structure
690 * @addr: EMI address to program
691 * @data: value to be written to the EMI address
692 *
693 * Assumes the SW/FW/HW Semaphore is already acquired.
694 **/
695static s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
696{
697 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
698}
699
700/**
Bruce Allane52997f2010-06-16 13:27:49 +0000701 * e1000_set_eee_pchlan - Enable/disable EEE support
702 * @hw: pointer to the HW structure
703 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000704 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
705 * the link and the EEE capabilities of the link partner. The LPI Control
706 * register bits will remain set only if/when link is up.
Bruce Allane52997f2010-06-16 13:27:49 +0000707 **/
708static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
709{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000710 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000711 s32 ret_val;
712 u16 lpi_ctrl;
Bruce Allane52997f2010-06-16 13:27:49 +0000713
Bruce Allan2fbe4522012-04-19 03:21:47 +0000714 if ((hw->phy.type != e1000_phy_82579) &&
715 (hw->phy.type != e1000_phy_i217))
Bruce Allan5015e532012-02-08 02:55:56 +0000716 return 0;
Bruce Allane52997f2010-06-16 13:27:49 +0000717
Bruce Allan3d4d5752012-12-05 06:26:08 +0000718 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000719 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000720 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000721
Bruce Allan3d4d5752012-12-05 06:26:08 +0000722 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000723 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000724 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000725
Bruce Allan3d4d5752012-12-05 06:26:08 +0000726 /* Clear bits that enable EEE in various speeds */
727 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
728
729 /* Enable EEE if not disabled by user */
730 if (!dev_spec->eee_disable) {
731 u16 lpa, pcs_status, data;
732
Bruce Allan2fbe4522012-04-19 03:21:47 +0000733 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000734 switch (hw->phy.type) {
735 case e1000_phy_82579:
736 lpa = I82579_EEE_LP_ABILITY;
737 pcs_status = I82579_EEE_PCS_STATUS;
738 break;
739 case e1000_phy_i217:
740 lpa = I217_EEE_LP_ABILITY;
741 pcs_status = I217_EEE_PCS_STATUS;
742 break;
743 default:
744 ret_val = -E1000_ERR_PHY;
745 goto release;
746 }
747 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000748 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000749 if (ret_val)
750 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000751
Bruce Allan3d4d5752012-12-05 06:26:08 +0000752 /* Enable EEE only for speeds in which the link partner is
753 * EEE capable.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000754 */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000755 if (dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
756 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
757
758 if (dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000759 e1e_rphy_locked(hw, MII_LPA, &data);
760 if (data & LPA_100FULL)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000761 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
762 else
763 /* EEE is not supported in 100Half, so ignore
764 * partner's EEE in 100 ability if full-duplex
765 * is not advertised.
766 */
767 dev_spec->eee_lp_ability &=
768 ~I82579_EEE_100_SUPPORTED;
769 }
770
771 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
772 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
773 if (ret_val)
774 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000775 }
776
Bruce Allan3d4d5752012-12-05 06:26:08 +0000777 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
778release:
779 hw->phy.ops.release(hw);
780
781 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000782}
783
784/**
Bruce Allane08f6262013-02-20 03:06:34 +0000785 * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
786 * @hw: pointer to the HW structure
787 * @link: link up bool flag
788 *
789 * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
790 * preventing further DMA write requests. Workaround the issue by disabling
791 * the de-assertion of the clock request when in 1Gpbs mode.
792 **/
793static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
794{
795 u32 fextnvm6 = er32(FEXTNVM6);
796 s32 ret_val = 0;
797
798 if (link && (er32(STATUS) & E1000_STATUS_SPEED_1000)) {
799 u16 kmrn_reg;
800
801 ret_val = hw->phy.ops.acquire(hw);
802 if (ret_val)
803 return ret_val;
804
805 ret_val =
806 e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
807 &kmrn_reg);
808 if (ret_val)
809 goto release;
810
811 ret_val =
812 e1000e_write_kmrn_reg_locked(hw,
813 E1000_KMRNCTRLSTA_K1_CONFIG,
814 kmrn_reg &
815 ~E1000_KMRNCTRLSTA_K1_ENABLE);
816 if (ret_val)
817 goto release;
818
819 usleep_range(10, 20);
820
821 ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
822
823 ret_val =
824 e1000e_write_kmrn_reg_locked(hw,
825 E1000_KMRNCTRLSTA_K1_CONFIG,
826 kmrn_reg);
827release:
828 hw->phy.ops.release(hw);
829 } else {
830 /* clear FEXTNVM6 bit 8 on link down or 10/100 */
831 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
832 }
833
834 return ret_val;
835}
836
837/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000838 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
839 * @hw: pointer to the HW structure
840 *
841 * Checks to see of the link status of the hardware has changed. If a
842 * change in link status has been detected, then we read the PHY registers
843 * to get the current speed/duplex if link exists.
844 **/
845static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
846{
847 struct e1000_mac_info *mac = &hw->mac;
848 s32 ret_val;
849 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000850 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000851
Bruce Allane921eb12012-11-28 09:28:37 +0000852 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000853 * has completed and/or if our link status has changed. The
854 * get_link_status flag is set upon receiving a Link Status
855 * Change or Rx Sequence Error interrupt.
856 */
Bruce Allan5015e532012-02-08 02:55:56 +0000857 if (!mac->get_link_status)
858 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000859
Bruce Allane921eb12012-11-28 09:28:37 +0000860 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000861 * link. If so, then we want to get the current speed/duplex
862 * of the PHY.
863 */
864 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
865 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000866 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000867
Bruce Allan1d5846b2009-10-29 13:46:05 +0000868 if (hw->mac.type == e1000_pchlan) {
869 ret_val = e1000_k1_gig_workaround_hv(hw, link);
870 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000871 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +0000872 }
873
Bruce Allan772d05c2013-03-06 09:02:36 +0000874 /* When connected at 10Mbps half-duplex, 82579 parts are excessively
875 * aggressive resulting in many collisions. To avoid this, increase
876 * the IPG and reduce Rx latency in the PHY.
877 */
878 if ((hw->mac.type == e1000_pch2lan) && link) {
879 u32 reg;
880 reg = er32(STATUS);
881 if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
882 reg = er32(TIPG);
883 reg &= ~E1000_TIPG_IPGT_MASK;
884 reg |= 0xFF;
885 ew32(TIPG, reg);
886
887 /* Reduce Rx latency in analog PHY */
888 ret_val = hw->phy.ops.acquire(hw);
889 if (ret_val)
890 return ret_val;
891
892 ret_val =
893 e1000_write_emi_reg_locked(hw, I82579_RX_CONFIG, 0);
894
895 hw->phy.ops.release(hw);
896
897 if (ret_val)
898 return ret_val;
899 }
900 }
901
Bruce Allane08f6262013-02-20 03:06:34 +0000902 /* Work-around I218 hang issue */
903 if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
904 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V)) {
905 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
906 if (ret_val)
907 return ret_val;
908 }
909
Bruce Allan2fbe4522012-04-19 03:21:47 +0000910 /* Clear link partner's EEE ability */
911 hw->dev_spec.ich8lan.eee_lp_ability = 0;
912
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000913 if (!link)
Bruce Allan5015e532012-02-08 02:55:56 +0000914 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000915
916 mac->get_link_status = false;
917
Bruce Allan1d2101a72011-07-22 06:21:56 +0000918 switch (hw->mac.type) {
919 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +0000920 ret_val = e1000_k1_workaround_lv(hw);
921 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000922 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000923 /* fall-thru */
924 case e1000_pchlan:
925 if (hw->phy.type == e1000_phy_82578) {
926 ret_val = e1000_link_stall_workaround_hv(hw);
927 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000928 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000929 }
930
Bruce Allane921eb12012-11-28 09:28:37 +0000931 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +0000932 * Set the number of preambles removed from the packet
933 * when it is passed from the PHY to the MAC to prevent
934 * the MAC from misinterpreting the packet type.
935 */
936 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
937 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
938
939 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
940 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
941
942 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
943 break;
944 default:
945 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +0000946 }
947
Bruce Allane921eb12012-11-28 09:28:37 +0000948 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000949 * immediately after link-up
950 */
951 e1000e_check_downshift(hw);
952
Bruce Allane52997f2010-06-16 13:27:49 +0000953 /* Enable/Disable EEE after link up */
954 ret_val = e1000_set_eee_pchlan(hw);
955 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000956 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000957
Bruce Allane921eb12012-11-28 09:28:37 +0000958 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000959 * we have already determined whether we have link or not.
960 */
Bruce Allan5015e532012-02-08 02:55:56 +0000961 if (!mac->autoneg)
962 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000963
Bruce Allane921eb12012-11-28 09:28:37 +0000964 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000965 * of MAC speed/duplex configuration. So we only need to
966 * configure Collision Distance in the MAC.
967 */
Bruce Allan57cde762012-02-22 09:02:58 +0000968 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000969
Bruce Allane921eb12012-11-28 09:28:37 +0000970 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000971 * First, we need to restore the desired flow control
972 * settings because we may have had to re-autoneg with a
973 * different link partner.
974 */
975 ret_val = e1000e_config_fc_after_link_up(hw);
976 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000977 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000978
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000979 return ret_val;
980}
981
Jeff Kirsher69e3fd82008-04-02 13:48:18 -0700982static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700983{
984 struct e1000_hw *hw = &adapter->hw;
985 s32 rc;
986
Bruce Allanec34c172012-02-01 10:53:05 +0000987 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 if (rc)
989 return rc;
990
991 rc = e1000_init_nvm_params_ich8lan(hw);
992 if (rc)
993 return rc;
994
Bruce Alland3738bb2010-06-16 13:27:28 +0000995 switch (hw->mac.type) {
996 case e1000_ich8lan:
997 case e1000_ich9lan:
998 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000999 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001000 break;
1001 case e1000_pchlan:
1002 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001003 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001004 rc = e1000_init_phy_params_pchlan(hw);
1005 break;
1006 default:
1007 break;
1008 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009 if (rc)
1010 return rc;
1011
Bruce Allane921eb12012-11-28 09:28:37 +00001012 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001013 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1014 */
1015 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1016 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1017 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001018 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1019 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001020
1021 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001022 }
1023
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001025 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1027
Bruce Allanc6e7f512011-07-29 05:53:02 +00001028 /* Enable workaround for 82579 w/ ME enabled */
1029 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1030 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1031 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1032
Bruce Allan5a86f282010-06-29 18:13:13 +00001033 /* Disable EEE by default until IEEE802.3az spec is finalized */
1034 if (adapter->flags2 & FLAG2_HAS_EEE)
1035 adapter->hw.dev_spec.ich8lan.eee_disable = true;
1036
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037 return 0;
1038}
1039
Thomas Gleixner717d4382008-10-02 16:33:40 -07001040static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001041
Auke Kokbc7f75f2007-09-17 12:30:59 -07001042/**
Bruce Allanca15df52009-10-26 11:23:43 +00001043 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1044 * @hw: pointer to the HW structure
1045 *
1046 * Acquires the mutex for performing NVM operations.
1047 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001048static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001049{
1050 mutex_lock(&nvm_mutex);
1051
1052 return 0;
1053}
1054
1055/**
1056 * e1000_release_nvm_ich8lan - Release NVM mutex
1057 * @hw: pointer to the HW structure
1058 *
1059 * Releases the mutex used while performing NVM operations.
1060 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001061static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001062{
1063 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001064}
1065
Bruce Allanca15df52009-10-26 11:23:43 +00001066/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001067 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1068 * @hw: pointer to the HW structure
1069 *
Bruce Allanca15df52009-10-26 11:23:43 +00001070 * Acquires the software control flag for performing PHY and select
1071 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001072 **/
1073static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1074{
Bruce Allan373a88d2009-08-07 07:41:37 +00001075 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1076 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001077
Bruce Allana90b4122011-10-07 03:50:38 +00001078 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1079 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001080 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001081 return -E1000_ERR_PHY;
1082 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001083
Auke Kokbc7f75f2007-09-17 12:30:59 -07001084 while (timeout) {
1085 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001086 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1087 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001088
Auke Kokbc7f75f2007-09-17 12:30:59 -07001089 mdelay(1);
1090 timeout--;
1091 }
1092
1093 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001094 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001095 ret_val = -E1000_ERR_CONFIG;
1096 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 }
1098
Bruce Allan53ac5a82009-10-26 11:23:06 +00001099 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001100
1101 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1102 ew32(EXTCNF_CTRL, extcnf_ctrl);
1103
1104 while (timeout) {
1105 extcnf_ctrl = er32(EXTCNF_CTRL);
1106 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1107 break;
1108
1109 mdelay(1);
1110 timeout--;
1111 }
1112
1113 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001114 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 +00001115 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001116 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1117 ew32(EXTCNF_CTRL, extcnf_ctrl);
1118 ret_val = -E1000_ERR_CONFIG;
1119 goto out;
1120 }
1121
1122out:
1123 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001124 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001125
1126 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127}
1128
1129/**
1130 * e1000_release_swflag_ich8lan - Release software control flag
1131 * @hw: pointer to the HW structure
1132 *
Bruce Allanca15df52009-10-26 11:23:43 +00001133 * Releases the software control flag for performing PHY and select
1134 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001135 **/
1136static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1137{
1138 u32 extcnf_ctrl;
1139
1140 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001141
1142 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1143 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1144 ew32(EXTCNF_CTRL, extcnf_ctrl);
1145 } else {
1146 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1147 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001148
Bruce Allana90b4122011-10-07 03:50:38 +00001149 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001150}
1151
1152/**
Bruce Allan4662e822008-08-26 18:37:06 -07001153 * e1000_check_mng_mode_ich8lan - Checks management mode
1154 * @hw: pointer to the HW structure
1155 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001156 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001157 * This is a function pointer entry point only called by read/write
1158 * routines for the PHY and NVM parts.
1159 **/
1160static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1161{
Bruce Allana708dd82009-11-20 23:28:37 +00001162 u32 fwsm;
1163
1164 fwsm = er32(FWSM);
Bruce Allanf0ff4392013-02-20 04:05:39 +00001165 return ((fwsm & E1000_ICH_FWSM_FW_VALID) &&
1166 ((fwsm & E1000_FWSM_MODE_MASK) ==
1167 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)));
Bruce Allaneb7700d2010-06-16 13:27:05 +00001168}
Bruce Allan4662e822008-08-26 18:37:06 -07001169
Bruce Allaneb7700d2010-06-16 13:27:05 +00001170/**
1171 * e1000_check_mng_mode_pchlan - Checks management mode
1172 * @hw: pointer to the HW structure
1173 *
1174 * This checks if the adapter has iAMT enabled.
1175 * This is a function pointer entry point only called by read/write
1176 * routines for the PHY and NVM parts.
1177 **/
1178static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1179{
1180 u32 fwsm;
1181
1182 fwsm = er32(FWSM);
1183 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
Bruce Allanf0ff4392013-02-20 04:05:39 +00001184 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001185}
1186
1187/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001188 * e1000_rar_set_pch2lan - Set receive address register
1189 * @hw: pointer to the HW structure
1190 * @addr: pointer to the receive address
1191 * @index: receive address array register
1192 *
1193 * Sets the receive address array register at index to the address passed
1194 * in by addr. For 82579, RAR[0] is the base address register that is to
1195 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1196 * Use SHRA[0-3] in place of those reserved for ME.
1197 **/
1198static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1199{
1200 u32 rar_low, rar_high;
1201
Bruce Allane921eb12012-11-28 09:28:37 +00001202 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001203 * from network order (big endian) to little endian
1204 */
1205 rar_low = ((u32)addr[0] |
1206 ((u32)addr[1] << 8) |
1207 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1208
1209 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1210
1211 /* If MAC address zero, no need to set the AV bit */
1212 if (rar_low || rar_high)
1213 rar_high |= E1000_RAH_AV;
1214
1215 if (index == 0) {
1216 ew32(RAL(index), rar_low);
1217 e1e_flush();
1218 ew32(RAH(index), rar_high);
1219 e1e_flush();
1220 return;
1221 }
1222
1223 if (index < hw->mac.rar_entry_count) {
1224 s32 ret_val;
1225
1226 ret_val = e1000_acquire_swflag_ich8lan(hw);
1227 if (ret_val)
1228 goto out;
1229
1230 ew32(SHRAL(index - 1), rar_low);
1231 e1e_flush();
1232 ew32(SHRAH(index - 1), rar_high);
1233 e1e_flush();
1234
1235 e1000_release_swflag_ich8lan(hw);
1236
1237 /* verify the register updates */
1238 if ((er32(SHRAL(index - 1)) == rar_low) &&
1239 (er32(SHRAH(index - 1)) == rar_high))
1240 return;
1241
1242 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1243 (index - 1), er32(FWSM));
1244 }
1245
1246out:
1247 e_dbg("Failed to write receive address at index %d\n", index);
1248}
1249
1250/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001251 * e1000_rar_set_pch_lpt - Set receive address registers
1252 * @hw: pointer to the HW structure
1253 * @addr: pointer to the receive address
1254 * @index: receive address array register
1255 *
1256 * Sets the receive address register array at index to the address passed
1257 * in by addr. For LPT, RAR[0] is the base address register that is to
1258 * contain the MAC address. SHRA[0-10] are the shared receive address
1259 * registers that are shared between the Host and manageability engine (ME).
1260 **/
1261static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1262{
1263 u32 rar_low, rar_high;
1264 u32 wlock_mac;
1265
Bruce Allane921eb12012-11-28 09:28:37 +00001266 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001267 * from network order (big endian) to little endian
1268 */
1269 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1270 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1271
1272 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1273
1274 /* If MAC address zero, no need to set the AV bit */
1275 if (rar_low || rar_high)
1276 rar_high |= E1000_RAH_AV;
1277
1278 if (index == 0) {
1279 ew32(RAL(index), rar_low);
1280 e1e_flush();
1281 ew32(RAH(index), rar_high);
1282 e1e_flush();
1283 return;
1284 }
1285
Bruce Allane921eb12012-11-28 09:28:37 +00001286 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001287 * it is using - those registers are unavailable for use.
1288 */
1289 if (index < hw->mac.rar_entry_count) {
1290 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1291 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1292
1293 /* Check if all SHRAR registers are locked */
1294 if (wlock_mac == 1)
1295 goto out;
1296
1297 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1298 s32 ret_val;
1299
1300 ret_val = e1000_acquire_swflag_ich8lan(hw);
1301
1302 if (ret_val)
1303 goto out;
1304
1305 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1306 e1e_flush();
1307 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1308 e1e_flush();
1309
1310 e1000_release_swflag_ich8lan(hw);
1311
1312 /* verify the register updates */
1313 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1314 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1315 return;
1316 }
1317 }
1318
1319out:
1320 e_dbg("Failed to write receive address at index %d\n", index);
1321}
1322
1323/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001324 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1325 * @hw: pointer to the HW structure
1326 *
1327 * Checks if firmware is blocking the reset of the PHY.
1328 * This is a function pointer entry point only called by
1329 * reset routines.
1330 **/
1331static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1332{
1333 u32 fwsm;
1334
1335 fwsm = er32(FWSM);
1336
1337 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
1338}
1339
1340/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001341 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1342 * @hw: pointer to the HW structure
1343 *
1344 * Assumes semaphore already acquired.
1345 *
1346 **/
1347static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1348{
1349 u16 phy_data;
1350 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001351 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1352 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan70806a72013-01-05 05:08:37 +00001353 s32 ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001354
1355 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1356
1357 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1358 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001359 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001360
1361 phy_data &= ~HV_SMB_ADDR_MASK;
1362 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1363 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001364
Bruce Allan2fbe4522012-04-19 03:21:47 +00001365 if (hw->phy.type == e1000_phy_i217) {
1366 /* Restore SMBus frequency */
1367 if (freq--) {
1368 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1369 phy_data |= (freq & (1 << 0)) <<
1370 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1371 phy_data |= (freq & (1 << 1)) <<
1372 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1373 } else {
1374 e_dbg("Unsupported SMB frequency in PHY\n");
1375 }
1376 }
1377
Bruce Allan5015e532012-02-08 02:55:56 +00001378 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001379}
1380
1381/**
Bruce Allanf523d212009-10-29 13:45:45 +00001382 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1383 * @hw: pointer to the HW structure
1384 *
1385 * SW should configure the LCD from the NVM extended configuration region
1386 * as a workaround for certain parts.
1387 **/
1388static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1389{
1390 struct e1000_phy_info *phy = &hw->phy;
1391 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001392 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001393 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1394
Bruce Allane921eb12012-11-28 09:28:37 +00001395 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001396 * is needed due to an issue where the NVM configuration is
1397 * not properly autoloaded after power transitions.
1398 * Therefore, after each PHY reset, we will load the
1399 * configuration data out of the NVM manually.
1400 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001401 switch (hw->mac.type) {
1402 case e1000_ich8lan:
1403 if (phy->type != e1000_phy_igp_3)
1404 return ret_val;
1405
Bruce Allan5f3eed62010-09-22 17:15:54 +00001406 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1407 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001408 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1409 break;
1410 }
1411 /* Fall-thru */
1412 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001413 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001414 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001415 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001416 break;
1417 default:
1418 return ret_val;
1419 }
1420
1421 ret_val = hw->phy.ops.acquire(hw);
1422 if (ret_val)
1423 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001424
Bruce Allan8b802a72010-05-10 15:01:10 +00001425 data = er32(FEXTNVM);
1426 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001427 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001428
Bruce Allane921eb12012-11-28 09:28:37 +00001429 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001430 * extended configuration before SW configuration
1431 */
1432 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001433 if ((hw->mac.type < e1000_pch2lan) &&
1434 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1435 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001436
Bruce Allan8b802a72010-05-10 15:01:10 +00001437 cnf_size = er32(EXTCNF_SIZE);
1438 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1439 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1440 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001441 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001442
1443 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1444 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1445
Bruce Allan2fbe4522012-04-19 03:21:47 +00001446 if (((hw->mac.type == e1000_pchlan) &&
1447 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1448 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001449 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001450 * OEM and LCD Write Enable bits are set in the NVM.
1451 * When both NVM bits are cleared, SW will configure
1452 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001453 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001454 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001455 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001456 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001457
Bruce Allan8b802a72010-05-10 15:01:10 +00001458 data = er32(LEDCTL);
1459 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1460 (u16)data);
1461 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001462 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001463 }
1464
1465 /* Configure LCD from extended configuration region. */
1466
1467 /* cnf_base_addr is in DWORD */
1468 word_addr = (u16)(cnf_base_addr << 1);
1469
1470 for (i = 0; i < cnf_size; i++) {
Bruce Allane5fe2542013-02-20 04:06:27 +00001471 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001472 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001473 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001474
Bruce Allan8b802a72010-05-10 15:01:10 +00001475 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1476 1, &reg_addr);
1477 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001478 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001479
Bruce Allan8b802a72010-05-10 15:01:10 +00001480 /* Save off the PHY page for future writes. */
1481 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1482 phy_page = reg_data;
1483 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001484 }
Bruce Allanf523d212009-10-29 13:45:45 +00001485
Bruce Allan8b802a72010-05-10 15:01:10 +00001486 reg_addr &= PHY_REG_MASK;
1487 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001488
Bruce Allanf1430d62012-04-14 04:21:52 +00001489 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001490 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001491 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001492 }
1493
Bruce Allan75ce1532012-02-08 02:54:48 +00001494release:
Bruce Allan94d81862009-11-20 23:25:26 +00001495 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001496 return ret_val;
1497}
1498
1499/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001500 * e1000_k1_gig_workaround_hv - K1 Si workaround
1501 * @hw: pointer to the HW structure
1502 * @link: link up bool flag
1503 *
1504 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1505 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1506 * If link is down, the function will restore the default K1 setting located
1507 * in the NVM.
1508 **/
1509static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1510{
1511 s32 ret_val = 0;
1512 u16 status_reg = 0;
1513 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1514
1515 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001516 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001517
1518 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001519 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001520 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001521 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001522
1523 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1524 if (link) {
1525 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001526 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1527 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001528 if (ret_val)
1529 goto release;
1530
Bruce Allanf0ff4392013-02-20 04:05:39 +00001531 status_reg &= (BM_CS_STATUS_LINK_UP |
1532 BM_CS_STATUS_RESOLVED |
1533 BM_CS_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001534
1535 if (status_reg == (BM_CS_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001536 BM_CS_STATUS_RESOLVED |
1537 BM_CS_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001538 k1_enable = false;
1539 }
1540
1541 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001542 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001543 if (ret_val)
1544 goto release;
1545
Bruce Allanf0ff4392013-02-20 04:05:39 +00001546 status_reg &= (HV_M_STATUS_LINK_UP |
1547 HV_M_STATUS_AUTONEG_COMPLETE |
1548 HV_M_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001549
1550 if (status_reg == (HV_M_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001551 HV_M_STATUS_AUTONEG_COMPLETE |
1552 HV_M_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001553 k1_enable = false;
1554 }
1555
1556 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001557 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001558 if (ret_val)
1559 goto release;
1560
1561 } else {
1562 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001563 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001564 if (ret_val)
1565 goto release;
1566 }
1567
1568 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1569
1570release:
Bruce Allan94d81862009-11-20 23:25:26 +00001571 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001572
Bruce Allan1d5846b2009-10-29 13:46:05 +00001573 return ret_val;
1574}
1575
1576/**
1577 * e1000_configure_k1_ich8lan - Configure K1 power state
1578 * @hw: pointer to the HW structure
1579 * @enable: K1 state to configure
1580 *
1581 * Configure the K1 power state based on the provided parameter.
1582 * Assumes semaphore already acquired.
1583 *
1584 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1585 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001586s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001587{
Bruce Allan70806a72013-01-05 05:08:37 +00001588 s32 ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001589 u32 ctrl_reg = 0;
1590 u32 ctrl_ext = 0;
1591 u32 reg = 0;
1592 u16 kmrn_reg = 0;
1593
Bruce Allan3d3a1672012-02-23 03:13:18 +00001594 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1595 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001596 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001597 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001598
1599 if (k1_enable)
1600 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1601 else
1602 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1603
Bruce Allan3d3a1672012-02-23 03:13:18 +00001604 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1605 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001606 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001607 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001608
Bruce Allance43a212013-02-20 04:06:32 +00001609 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001610 ctrl_ext = er32(CTRL_EXT);
1611 ctrl_reg = er32(CTRL);
1612
1613 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1614 reg |= E1000_CTRL_FRCSPD;
1615 ew32(CTRL, reg);
1616
1617 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001618 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001619 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001620 ew32(CTRL, ctrl_reg);
1621 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001622 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001623 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001624
Bruce Allan5015e532012-02-08 02:55:56 +00001625 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001626}
1627
1628/**
Bruce Allanf523d212009-10-29 13:45:45 +00001629 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1630 * @hw: pointer to the HW structure
1631 * @d0_state: boolean if entering d0 or d3 device state
1632 *
1633 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1634 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1635 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1636 **/
1637static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1638{
1639 s32 ret_val = 0;
1640 u32 mac_reg;
1641 u16 oem_reg;
1642
Bruce Allan2fbe4522012-04-19 03:21:47 +00001643 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001644 return ret_val;
1645
Bruce Allan94d81862009-11-20 23:25:26 +00001646 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001647 if (ret_val)
1648 return ret_val;
1649
Bruce Allan2fbe4522012-04-19 03:21:47 +00001650 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001651 mac_reg = er32(EXTCNF_CTRL);
1652 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001653 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001654 }
Bruce Allanf523d212009-10-29 13:45:45 +00001655
1656 mac_reg = er32(FEXTNVM);
1657 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001658 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001659
1660 mac_reg = er32(PHY_CTRL);
1661
Bruce Allanf1430d62012-04-14 04:21:52 +00001662 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001663 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001664 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001665
1666 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1667
1668 if (d0_state) {
1669 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1670 oem_reg |= HV_OEM_BITS_GBE_DIS;
1671
1672 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1673 oem_reg |= HV_OEM_BITS_LPLU;
1674 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001675 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1676 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001677 oem_reg |= HV_OEM_BITS_GBE_DIS;
1678
Bruce Allan03299e42011-09-30 08:07:05 +00001679 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1680 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001681 oem_reg |= HV_OEM_BITS_LPLU;
1682 }
Bruce Allan03299e42011-09-30 08:07:05 +00001683
Bruce Allan92fe1732012-04-12 06:27:03 +00001684 /* Set Restart auto-neg to activate the bits */
1685 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1686 !hw->phy.ops.check_reset_block(hw))
1687 oem_reg |= HV_OEM_BITS_RESTART_AN;
1688
Bruce Allanf1430d62012-04-14 04:21:52 +00001689 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001690
Bruce Allan75ce1532012-02-08 02:54:48 +00001691release:
Bruce Allan94d81862009-11-20 23:25:26 +00001692 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001693
1694 return ret_val;
1695}
1696
Bruce Allanf523d212009-10-29 13:45:45 +00001697/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001698 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1699 * @hw: pointer to the HW structure
1700 **/
1701static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1702{
1703 s32 ret_val;
1704 u16 data;
1705
1706 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1707 if (ret_val)
1708 return ret_val;
1709
1710 data |= HV_KMRN_MDIO_SLOW;
1711
1712 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1713
1714 return ret_val;
1715}
1716
1717/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001718 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1719 * done after every PHY reset.
1720 **/
1721static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1722{
1723 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001724 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001725
1726 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001727 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001728
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001729 /* Set MDIO slow mode before any other MDIO access */
1730 if (hw->phy.type == e1000_phy_82577) {
1731 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1732 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001733 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001734 }
1735
Bruce Allana4f58f52009-06-02 11:29:18 +00001736 if (((hw->phy.type == e1000_phy_82577) &&
1737 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1738 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1739 /* Disable generation of early preamble */
1740 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1741 if (ret_val)
1742 return ret_val;
1743
1744 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001745 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001746 if (ret_val)
1747 return ret_val;
1748 }
1749
1750 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001751 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001752 * writing 0x3140 to the control register.
1753 */
1754 if (hw->phy.revision < 2) {
1755 e1000e_phy_sw_reset(hw);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001756 ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
Bruce Allana4f58f52009-06-02 11:29:18 +00001757 }
1758 }
1759
1760 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001761 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001762 if (ret_val)
1763 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001764
Bruce Allana4f58f52009-06-02 11:29:18 +00001765 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001766 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001767 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001768 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001769 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001770
Bruce Allane921eb12012-11-28 09:28:37 +00001771 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001772 * link so that it disables K1 if link is in 1Gbps.
1773 */
1774 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001775 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001776 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001777
Bruce Allanbaf86c92010-01-13 01:53:08 +00001778 /* Workaround for link disconnects on a busy hub in half duplex */
1779 ret_val = hw->phy.ops.acquire(hw);
1780 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001781 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001782 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001783 if (ret_val)
1784 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001785 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001786 if (ret_val)
1787 goto release;
1788
1789 /* set MSE higher to enable link to stay up when noise is high */
1790 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001791release:
1792 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001793
Bruce Allana4f58f52009-06-02 11:29:18 +00001794 return ret_val;
1795}
1796
1797/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001798 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1799 * @hw: pointer to the HW structure
1800 **/
1801void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1802{
1803 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001804 u16 i, phy_reg = 0;
1805 s32 ret_val;
1806
1807 ret_val = hw->phy.ops.acquire(hw);
1808 if (ret_val)
1809 return;
1810 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1811 if (ret_val)
1812 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001813
1814 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1815 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1816 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001817 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1818 (u16)(mac_reg & 0xFFFF));
1819 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1820 (u16)((mac_reg >> 16) & 0xFFFF));
1821
Bruce Alland3738bb2010-06-16 13:27:28 +00001822 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001823 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1824 (u16)(mac_reg & 0xFFFF));
1825 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1826 (u16)((mac_reg & E1000_RAH_AV)
1827 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00001828 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00001829
1830 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1831
1832release:
1833 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001834}
1835
Bruce Alland3738bb2010-06-16 13:27:28 +00001836/**
1837 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1838 * with 82579 PHY
1839 * @hw: pointer to the HW structure
1840 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1841 **/
1842s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1843{
1844 s32 ret_val = 0;
1845 u16 phy_reg, data;
1846 u32 mac_reg;
1847 u16 i;
1848
Bruce Allan2fbe4522012-04-19 03:21:47 +00001849 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001850 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001851
1852 /* disable Rx path while enabling/disabling workaround */
1853 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1854 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1855 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001856 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001857
1858 if (enable) {
Bruce Allane921eb12012-11-28 09:28:37 +00001859 /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
Bruce Alland3738bb2010-06-16 13:27:28 +00001860 * SHRAL/H) and initial CRC values to the MAC
1861 */
1862 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00001863 u8 mac_addr[ETH_ALEN] = { 0 };
Bruce Alland3738bb2010-06-16 13:27:28 +00001864 u32 addr_high, addr_low;
1865
1866 addr_high = er32(RAH(i));
1867 if (!(addr_high & E1000_RAH_AV))
1868 continue;
1869 addr_low = er32(RAL(i));
1870 mac_addr[0] = (addr_low & 0xFF);
1871 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1872 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1873 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1874 mac_addr[4] = (addr_high & 0xFF);
1875 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1876
Bruce Allanfe46f582011-01-06 14:29:51 +00001877 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00001878 }
1879
1880 /* Write Rx addresses to the PHY */
1881 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1882
1883 /* Enable jumbo frame workaround in the MAC */
1884 mac_reg = er32(FFLT_DBG);
1885 mac_reg &= ~(1 << 14);
1886 mac_reg |= (7 << 15);
1887 ew32(FFLT_DBG, mac_reg);
1888
1889 mac_reg = er32(RCTL);
1890 mac_reg |= E1000_RCTL_SECRC;
1891 ew32(RCTL, mac_reg);
1892
1893 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00001894 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1895 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001896 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001897 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001898 ret_val = e1000e_write_kmrn_reg(hw,
1899 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1900 data | (1 << 0));
1901 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001902 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001903 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00001904 E1000_KMRNCTRLSTA_HD_CTRL,
1905 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001906 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001907 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001908 data &= ~(0xF << 8);
1909 data |= (0xB << 8);
1910 ret_val = e1000e_write_kmrn_reg(hw,
1911 E1000_KMRNCTRLSTA_HD_CTRL,
1912 data);
1913 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001914 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001915
1916 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001917 e1e_rphy(hw, PHY_REG(769, 23), &data);
1918 data &= ~(0x7F << 5);
1919 data |= (0x37 << 5);
1920 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1921 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001922 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001923 e1e_rphy(hw, PHY_REG(769, 16), &data);
1924 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00001925 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1926 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001927 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001928 e1e_rphy(hw, PHY_REG(776, 20), &data);
1929 data &= ~(0x3FF << 2);
1930 data |= (0x1A << 2);
1931 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1932 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001933 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00001934 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00001935 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001936 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001937 e1e_rphy(hw, HV_PM_CTRL, &data);
1938 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1939 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001940 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001941 } else {
1942 /* Write MAC register values back to h/w defaults */
1943 mac_reg = er32(FFLT_DBG);
1944 mac_reg &= ~(0xF << 14);
1945 ew32(FFLT_DBG, mac_reg);
1946
1947 mac_reg = er32(RCTL);
1948 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00001949 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00001950
1951 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00001952 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1953 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001954 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001955 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001956 ret_val = e1000e_write_kmrn_reg(hw,
1957 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1958 data & ~(1 << 0));
1959 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001960 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001961 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00001962 E1000_KMRNCTRLSTA_HD_CTRL,
1963 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001964 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001965 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001966 data &= ~(0xF << 8);
1967 data |= (0xB << 8);
1968 ret_val = e1000e_write_kmrn_reg(hw,
1969 E1000_KMRNCTRLSTA_HD_CTRL,
1970 data);
1971 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001972 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001973
1974 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00001975 e1e_rphy(hw, PHY_REG(769, 23), &data);
1976 data &= ~(0x7F << 5);
1977 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1978 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001979 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001980 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00001981 data |= (1 << 13);
1982 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1983 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001984 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001985 e1e_rphy(hw, PHY_REG(776, 20), &data);
1986 data &= ~(0x3FF << 2);
1987 data |= (0x8 << 2);
1988 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1989 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001990 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001991 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
1992 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001993 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001994 e1e_rphy(hw, HV_PM_CTRL, &data);
1995 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
1996 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001997 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001998 }
1999
2000 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002001 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002002}
2003
2004/**
2005 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2006 * done after every PHY reset.
2007 **/
2008static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2009{
2010 s32 ret_val = 0;
2011
2012 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002013 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002014
2015 /* Set MDIO slow mode before any other MDIO access */
2016 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002017 if (ret_val)
2018 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002019
Bruce Allan4d241362011-12-16 00:46:06 +00002020 ret_val = hw->phy.ops.acquire(hw);
2021 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002022 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002023 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002024 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002025 if (ret_val)
2026 goto release;
2027 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002028 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002029release:
2030 hw->phy.ops.release(hw);
2031
Bruce Alland3738bb2010-06-16 13:27:28 +00002032 return ret_val;
2033}
2034
2035/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002036 * e1000_k1_gig_workaround_lv - K1 Si workaround
2037 * @hw: pointer to the HW structure
2038 *
2039 * Workaround to set the K1 beacon duration for 82579 parts
2040 **/
2041static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2042{
2043 s32 ret_val = 0;
2044 u16 status_reg = 0;
2045 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002046 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002047
2048 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002049 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002050
2051 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2052 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2053 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002054 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002055
2056 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2057 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2058 mac_reg = er32(FEXTNVM4);
2059 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2060
Bruce Allan0ed013e2011-07-29 05:52:56 +00002061 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2062 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002063 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002064
Bruce Allan0ed013e2011-07-29 05:52:56 +00002065 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002066 u16 pm_phy_reg;
2067
Bruce Allan0ed013e2011-07-29 05:52:56 +00002068 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2069 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002070 /* LV 1G Packet drop issue wa */
2071 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2072 if (ret_val)
2073 return ret_val;
2074 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2075 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2076 if (ret_val)
2077 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002078 } else {
2079 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2080 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2081 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002082 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002083 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002084 }
2085
Bruce Allan831bd2e2010-09-22 17:16:18 +00002086 return ret_val;
2087}
2088
2089/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002090 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2091 * @hw: pointer to the HW structure
2092 * @gate: boolean set to true to gate, false to ungate
2093 *
2094 * Gate/ungate the automatic PHY configuration via hardware; perform
2095 * the configuration via software instead.
2096 **/
2097static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2098{
2099 u32 extcnf_ctrl;
2100
Bruce Allan2fbe4522012-04-19 03:21:47 +00002101 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002102 return;
2103
2104 extcnf_ctrl = er32(EXTCNF_CTRL);
2105
2106 if (gate)
2107 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2108 else
2109 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2110
2111 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002112}
2113
2114/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002115 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2116 * @hw: pointer to the HW structure
2117 *
2118 * Check the appropriate indication the MAC has finished configuring the
2119 * PHY after a software reset.
2120 **/
2121static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2122{
2123 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2124
2125 /* Wait for basic configuration completes before proceeding */
2126 do {
2127 data = er32(STATUS);
2128 data &= E1000_STATUS_LAN_INIT_DONE;
Bruce Allance43a212013-02-20 04:06:32 +00002129 usleep_range(100, 200);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002130 } while ((!data) && --loop);
2131
Bruce Allane921eb12012-11-28 09:28:37 +00002132 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002133 * count reaches 0, loading the configuration from NVM will
2134 * leave the PHY in a bad state possibly resulting in no link.
2135 */
2136 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002137 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002138
2139 /* Clear the Init Done bit for the next init event */
2140 data = er32(STATUS);
2141 data &= ~E1000_STATUS_LAN_INIT_DONE;
2142 ew32(STATUS, data);
2143}
2144
2145/**
Bruce Allane98cac42010-05-10 15:02:32 +00002146 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002147 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002148 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002149static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002150{
Bruce Allanf523d212009-10-29 13:45:45 +00002151 s32 ret_val = 0;
2152 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002153
Bruce Allan44abd5c2012-02-22 09:02:37 +00002154 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002155 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002156
Bruce Allan5f3eed62010-09-22 17:15:54 +00002157 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002158 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002159
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002160 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002161 switch (hw->mac.type) {
2162 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002163 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2164 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002165 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002166 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002167 case e1000_pch2lan:
2168 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2169 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002170 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002171 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002172 default:
2173 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002174 }
2175
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002176 /* Clear the host wakeup bit after lcd reset */
2177 if (hw->mac.type >= e1000_pchlan) {
2178 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2179 reg &= ~BM_WUC_HOST_WU_BIT;
2180 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2181 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002182
Bruce Allanf523d212009-10-29 13:45:45 +00002183 /* Configure the LCD with the extended configuration region in NVM */
2184 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2185 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002186 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002187
Bruce Allanf523d212009-10-29 13:45:45 +00002188 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002189 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002190
Bruce Allan1effb452011-02-25 06:58:03 +00002191 if (hw->mac.type == e1000_pch2lan) {
2192 /* Ungate automatic PHY configuration on non-managed 82579 */
2193 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002194 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002195 e1000_gate_hw_phy_config_ich8lan(hw, false);
2196 }
2197
2198 /* Set EEE LPI Update Timer to 200usec */
2199 ret_val = hw->phy.ops.acquire(hw);
2200 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002201 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002202 ret_val = e1000_write_emi_reg_locked(hw,
2203 I82579_LPI_UPDATE_TIMER,
2204 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002205 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002206 }
2207
Bruce Allane98cac42010-05-10 15:02:32 +00002208 return ret_val;
2209}
2210
2211/**
2212 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2213 * @hw: pointer to the HW structure
2214 *
2215 * Resets the PHY
2216 * This is a function pointer entry point called by drivers
2217 * or other shared routines.
2218 **/
2219static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2220{
2221 s32 ret_val = 0;
2222
Bruce Allan605c82b2010-09-22 17:17:01 +00002223 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2224 if ((hw->mac.type == e1000_pch2lan) &&
2225 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2226 e1000_gate_hw_phy_config_ich8lan(hw, true);
2227
Bruce Allane98cac42010-05-10 15:02:32 +00002228 ret_val = e1000e_phy_hw_reset_generic(hw);
2229 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002230 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002231
Bruce Allan5015e532012-02-08 02:55:56 +00002232 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002233}
2234
2235/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002236 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2237 * @hw: pointer to the HW structure
2238 * @active: true to enable LPLU, false to disable
2239 *
2240 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2241 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2242 * the phy speed. This function will manually set the LPLU bit and restart
2243 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2244 * since it configures the same bit.
2245 **/
2246static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2247{
Bruce Allan70806a72013-01-05 05:08:37 +00002248 s32 ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002249 u16 oem_reg;
2250
2251 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2252 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002253 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002254
2255 if (active)
2256 oem_reg |= HV_OEM_BITS_LPLU;
2257 else
2258 oem_reg &= ~HV_OEM_BITS_LPLU;
2259
Bruce Allan44abd5c2012-02-22 09:02:37 +00002260 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002261 oem_reg |= HV_OEM_BITS_RESTART_AN;
2262
Bruce Allan5015e532012-02-08 02:55:56 +00002263 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002264}
2265
2266/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002267 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2268 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002269 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002270 *
2271 * Sets the LPLU D0 state according to the active flag. When
2272 * activating LPLU this function also disables smart speed
2273 * and vice versa. LPLU will not be activated unless the
2274 * device autonegotiation advertisement meets standards of
2275 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2276 * This is a function pointer entry point only called by
2277 * PHY setup routines.
2278 **/
2279static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2280{
2281 struct e1000_phy_info *phy = &hw->phy;
2282 u32 phy_ctrl;
2283 s32 ret_val = 0;
2284 u16 data;
2285
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002286 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002287 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002288
2289 phy_ctrl = er32(PHY_CTRL);
2290
2291 if (active) {
2292 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2293 ew32(PHY_CTRL, phy_ctrl);
2294
Bruce Allan60f12922009-07-01 13:28:14 +00002295 if (phy->type != e1000_phy_igp_3)
2296 return 0;
2297
Bruce Allane921eb12012-11-28 09:28:37 +00002298 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002299 * any PHY registers
2300 */
Bruce Allan60f12922009-07-01 13:28:14 +00002301 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002302 e1000e_gig_downshift_workaround_ich8lan(hw);
2303
2304 /* When LPLU is enabled, we should disable SmartSpeed */
2305 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00002306 if (ret_val)
2307 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002308 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2309 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2310 if (ret_val)
2311 return ret_val;
2312 } else {
2313 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2314 ew32(PHY_CTRL, phy_ctrl);
2315
Bruce Allan60f12922009-07-01 13:28:14 +00002316 if (phy->type != e1000_phy_igp_3)
2317 return 0;
2318
Bruce Allane921eb12012-11-28 09:28:37 +00002319 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002320 * during Dx states where the power conservation is most
2321 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002322 * SmartSpeed, so performance is maintained.
2323 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324 if (phy->smart_speed == e1000_smart_speed_on) {
2325 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002326 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002327 if (ret_val)
2328 return ret_val;
2329
2330 data |= IGP01E1000_PSCFR_SMART_SPEED;
2331 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002332 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333 if (ret_val)
2334 return ret_val;
2335 } else if (phy->smart_speed == e1000_smart_speed_off) {
2336 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002337 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338 if (ret_val)
2339 return ret_val;
2340
2341 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2342 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002343 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344 if (ret_val)
2345 return ret_val;
2346 }
2347 }
2348
2349 return 0;
2350}
2351
2352/**
2353 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2354 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002355 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002356 *
2357 * Sets the LPLU D3 state according to the active flag. When
2358 * activating LPLU this function also disables smart speed
2359 * and vice versa. LPLU will not be activated unless the
2360 * device autonegotiation advertisement meets standards of
2361 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2362 * This is a function pointer entry point only called by
2363 * PHY setup routines.
2364 **/
2365static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2366{
2367 struct e1000_phy_info *phy = &hw->phy;
2368 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002369 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002370 u16 data;
2371
2372 phy_ctrl = er32(PHY_CTRL);
2373
2374 if (!active) {
2375 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2376 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002377
2378 if (phy->type != e1000_phy_igp_3)
2379 return 0;
2380
Bruce Allane921eb12012-11-28 09:28:37 +00002381 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002382 * during Dx states where the power conservation is most
2383 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002384 * SmartSpeed, so performance is maintained.
2385 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002386 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002387 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2388 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 if (ret_val)
2390 return ret_val;
2391
2392 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002393 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2394 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002395 if (ret_val)
2396 return ret_val;
2397 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002398 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2399 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002400 if (ret_val)
2401 return ret_val;
2402
2403 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002404 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2405 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002406 if (ret_val)
2407 return ret_val;
2408 }
2409 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2410 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2411 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2412 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2413 ew32(PHY_CTRL, phy_ctrl);
2414
Bruce Allan60f12922009-07-01 13:28:14 +00002415 if (phy->type != e1000_phy_igp_3)
2416 return 0;
2417
Bruce Allane921eb12012-11-28 09:28:37 +00002418 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002419 * any PHY registers
2420 */
Bruce Allan60f12922009-07-01 13:28:14 +00002421 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002422 e1000e_gig_downshift_workaround_ich8lan(hw);
2423
2424 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002425 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002426 if (ret_val)
2427 return ret_val;
2428
2429 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002430 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 }
2432
Bruce Alland7eb3382012-02-08 02:55:14 +00002433 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434}
2435
2436/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002437 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2438 * @hw: pointer to the HW structure
2439 * @bank: pointer to the variable that returns the active bank
2440 *
2441 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002442 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002443 **/
2444static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2445{
Bruce Allane2434552008-11-21 17:02:41 -08002446 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002447 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002448 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2449 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002450 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002451 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002452
Bruce Allane2434552008-11-21 17:02:41 -08002453 switch (hw->mac.type) {
2454 case e1000_ich8lan:
2455 case e1000_ich9lan:
2456 eecd = er32(EECD);
2457 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2458 E1000_EECD_SEC1VAL_VALID_MASK) {
2459 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002460 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002461 else
2462 *bank = 0;
2463
2464 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002465 }
Bruce Allan434f1392011-12-16 00:46:54 +00002466 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002467 /* fall-thru */
2468 default:
2469 /* set bank to 0 in case flash read fails */
2470 *bank = 0;
2471
2472 /* Check bank 0 */
2473 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002474 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002475 if (ret_val)
2476 return ret_val;
2477 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2478 E1000_ICH_NVM_SIG_VALUE) {
2479 *bank = 0;
2480 return 0;
2481 }
2482
2483 /* Check bank 1 */
2484 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002485 bank1_offset,
2486 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002487 if (ret_val)
2488 return ret_val;
2489 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2490 E1000_ICH_NVM_SIG_VALUE) {
2491 *bank = 1;
2492 return 0;
2493 }
2494
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002495 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002496 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002497 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002498}
2499
2500/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002501 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2502 * @hw: pointer to the HW structure
2503 * @offset: The offset (in bytes) of the word(s) to read.
2504 * @words: Size of data to read in words
2505 * @data: Pointer to the word(s) to read at offset.
2506 *
2507 * Reads a word(s) from the NVM using the flash access registers.
2508 **/
2509static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2510 u16 *data)
2511{
2512 struct e1000_nvm_info *nvm = &hw->nvm;
2513 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2514 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002515 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002516 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002517 u16 i, word;
2518
2519 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2520 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002521 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002522 ret_val = -E1000_ERR_NVM;
2523 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002524 }
2525
Bruce Allan94d81862009-11-20 23:25:26 +00002526 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527
Bruce Allanf4187b52008-08-26 18:36:50 -07002528 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002529 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002530 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002531 bank = 0;
2532 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002533
2534 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002535 act_offset += offset;
2536
Bruce Allan148675a2009-08-07 07:41:56 +00002537 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002538 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002539 if (dev_spec->shadow_ram[offset + i].modified) {
2540 data[i] = dev_spec->shadow_ram[offset + i].value;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002541 } else {
2542 ret_val = e1000_read_flash_word_ich8lan(hw,
2543 act_offset + i,
2544 &word);
2545 if (ret_val)
2546 break;
2547 data[i] = word;
2548 }
2549 }
2550
Bruce Allan94d81862009-11-20 23:25:26 +00002551 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002552
Bruce Allane2434552008-11-21 17:02:41 -08002553out:
2554 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002555 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002556
Auke Kokbc7f75f2007-09-17 12:30:59 -07002557 return ret_val;
2558}
2559
2560/**
2561 * e1000_flash_cycle_init_ich8lan - Initialize flash
2562 * @hw: pointer to the HW structure
2563 *
2564 * This function does initial flash setup so that a new read/write/erase cycle
2565 * can be started.
2566 **/
2567static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2568{
2569 union ich8_hws_flash_status hsfsts;
2570 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002571
2572 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2573
2574 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002575 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002576 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002577 return -E1000_ERR_NVM;
2578 }
2579
2580 /* Clear FCERR and DAEL in hw status by writing 1 */
2581 hsfsts.hsf_status.flcerr = 1;
2582 hsfsts.hsf_status.dael = 1;
2583
2584 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2585
Bruce Allane921eb12012-11-28 09:28:37 +00002586 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002587 * bit to check against, in order to start a new cycle or
2588 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002589 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002590 * indication whether a cycle is in progress or has been
2591 * completed.
2592 */
2593
Bruce Allan04499ec2012-04-13 00:08:31 +00002594 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002595 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002596 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002597 * Begin by setting Flash Cycle Done.
2598 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002599 hsfsts.hsf_status.flcdone = 1;
2600 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2601 ret_val = 0;
2602 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002603 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002604
Bruce Allane921eb12012-11-28 09:28:37 +00002605 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002606 * cycle has a chance to end before giving up.
2607 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002608 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002609 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002610 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002611 ret_val = 0;
2612 break;
2613 }
2614 udelay(1);
2615 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002616 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002617 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002618 * now set the Flash Cycle Done.
2619 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002620 hsfsts.hsf_status.flcdone = 1;
2621 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2622 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002623 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002624 }
2625 }
2626
2627 return ret_val;
2628}
2629
2630/**
2631 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2632 * @hw: pointer to the HW structure
2633 * @timeout: maximum time to wait for completion
2634 *
2635 * This function starts a flash cycle and waits for its completion.
2636 **/
2637static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2638{
2639 union ich8_hws_flash_ctrl hsflctl;
2640 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002641 u32 i = 0;
2642
2643 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2644 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2645 hsflctl.hsf_ctrl.flcgo = 1;
2646 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2647
2648 /* wait till FDONE bit is set to 1 */
2649 do {
2650 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002651 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002652 break;
2653 udelay(1);
2654 } while (i++ < timeout);
2655
Bruce Allan04499ec2012-04-13 00:08:31 +00002656 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002657 return 0;
2658
Bruce Allan55920b52012-02-08 02:55:25 +00002659 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002660}
2661
2662/**
2663 * e1000_read_flash_word_ich8lan - Read word from flash
2664 * @hw: pointer to the HW structure
2665 * @offset: offset to data location
2666 * @data: pointer to the location for storing the data
2667 *
2668 * Reads the flash word at offset into data. Offset is converted
2669 * to bytes before read.
2670 **/
2671static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2672 u16 *data)
2673{
2674 /* Must convert offset into bytes. */
2675 offset <<= 1;
2676
2677 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2678}
2679
2680/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002681 * e1000_read_flash_byte_ich8lan - Read byte from flash
2682 * @hw: pointer to the HW structure
2683 * @offset: The offset of the byte to read.
2684 * @data: Pointer to a byte to store the value read.
2685 *
2686 * Reads a single byte from the NVM using the flash access registers.
2687 **/
2688static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2689 u8 *data)
2690{
2691 s32 ret_val;
2692 u16 word = 0;
2693
2694 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2695 if (ret_val)
2696 return ret_val;
2697
2698 *data = (u8)word;
2699
2700 return 0;
2701}
2702
2703/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002704 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2705 * @hw: pointer to the HW structure
2706 * @offset: The offset (in bytes) of the byte or word to read.
2707 * @size: Size of data to read, 1=byte 2=word
2708 * @data: Pointer to the word to store the value read.
2709 *
2710 * Reads a byte or word from the NVM using the flash access registers.
2711 **/
2712static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2713 u8 size, u16 *data)
2714{
2715 union ich8_hws_flash_status hsfsts;
2716 union ich8_hws_flash_ctrl hsflctl;
2717 u32 flash_linear_addr;
2718 u32 flash_data = 0;
2719 s32 ret_val = -E1000_ERR_NVM;
2720 u8 count = 0;
2721
2722 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2723 return -E1000_ERR_NVM;
2724
Bruce Allanf0ff4392013-02-20 04:05:39 +00002725 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2726 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002727
2728 do {
2729 udelay(1);
2730 /* Steps */
2731 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002732 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002733 break;
2734
2735 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2736 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2737 hsflctl.hsf_ctrl.fldbcount = size - 1;
2738 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2739 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2740
2741 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2742
Bruce Allan17e813e2013-02-20 04:06:01 +00002743 ret_val =
2744 e1000_flash_cycle_ich8lan(hw,
2745 ICH_FLASH_READ_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002746
Bruce Allane921eb12012-11-28 09:28:37 +00002747 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002748 * and try the whole sequence a few more times, else
2749 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002750 * least significant byte first msb to lsb
2751 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002752 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002753 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002754 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002755 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002756 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002757 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002758 break;
2759 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002760 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002761 * completely hosed, but if the error condition is
2762 * detected, it won't hurt to give it another try...
2763 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2764 */
2765 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002766 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002767 /* Repeat for some time before giving up. */
2768 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002769 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002770 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002771 break;
2772 }
2773 }
2774 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2775
2776 return ret_val;
2777}
2778
2779/**
2780 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2781 * @hw: pointer to the HW structure
2782 * @offset: The offset (in bytes) of the word(s) to write.
2783 * @words: Size of data to write in words
2784 * @data: Pointer to the word(s) to write at offset.
2785 *
2786 * Writes a byte or word to the NVM using the flash access registers.
2787 **/
2788static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2789 u16 *data)
2790{
2791 struct e1000_nvm_info *nvm = &hw->nvm;
2792 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002793 u16 i;
2794
2795 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2796 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002797 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002798 return -E1000_ERR_NVM;
2799 }
2800
Bruce Allan94d81862009-11-20 23:25:26 +00002801 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002802
Auke Kokbc7f75f2007-09-17 12:30:59 -07002803 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002804 dev_spec->shadow_ram[offset + i].modified = true;
2805 dev_spec->shadow_ram[offset + i].value = data[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07002806 }
2807
Bruce Allan94d81862009-11-20 23:25:26 +00002808 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002809
Auke Kokbc7f75f2007-09-17 12:30:59 -07002810 return 0;
2811}
2812
2813/**
2814 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2815 * @hw: pointer to the HW structure
2816 *
2817 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2818 * which writes the checksum to the shadow ram. The changes in the shadow
2819 * ram are then committed to the EEPROM by processing each bank at a time
2820 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002821 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002822 * future writes.
2823 **/
2824static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2825{
2826 struct e1000_nvm_info *nvm = &hw->nvm;
2827 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002828 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002829 s32 ret_val;
2830 u16 data;
2831
2832 ret_val = e1000e_update_nvm_checksum_generic(hw);
2833 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002834 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002835
2836 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002837 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002838
Bruce Allan94d81862009-11-20 23:25:26 +00002839 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002840
Bruce Allane921eb12012-11-28 09:28:37 +00002841 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002842 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002843 * is going to be written
2844 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002845 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002846 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002847 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002848 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002849 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002850
2851 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002852 new_bank_offset = nvm->flash_bank_size;
2853 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002854 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002855 if (ret_val)
2856 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002857 } else {
2858 old_bank_offset = nvm->flash_bank_size;
2859 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002860 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002861 if (ret_val)
2862 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002863 }
2864
2865 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00002866 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002867 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002868 * in the shadow RAM
2869 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002870 if (dev_spec->shadow_ram[i].modified) {
2871 data = dev_spec->shadow_ram[i].value;
2872 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002873 ret_val = e1000_read_flash_word_ich8lan(hw, i +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002874 old_bank_offset,
2875 &data);
Bruce Allane2434552008-11-21 17:02:41 -08002876 if (ret_val)
2877 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002878 }
2879
Bruce Allane921eb12012-11-28 09:28:37 +00002880 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002881 * (15:14) are 11b until the commit has completed.
2882 * This will allow us to write 10b which indicates the
2883 * signature is valid. We want to do this after the write
2884 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002885 * while the write is still in progress
2886 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002887 if (i == E1000_ICH_NVM_SIG_WORD)
2888 data |= E1000_ICH_NVM_SIG_MASK;
2889
2890 /* Convert offset to bytes. */
2891 act_offset = (i + new_bank_offset) << 1;
2892
Bruce Allance43a212013-02-20 04:06:32 +00002893 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002894 /* Write the bytes to the new bank. */
2895 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2896 act_offset,
2897 (u8)data);
2898 if (ret_val)
2899 break;
2900
Bruce Allance43a212013-02-20 04:06:32 +00002901 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002902 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002903 act_offset + 1,
2904 (u8)(data >> 8));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002905 if (ret_val)
2906 break;
2907 }
2908
Bruce Allane921eb12012-11-28 09:28:37 +00002909 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07002910 * programming failed.
2911 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002912 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002913 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002914 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002915 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002916 }
2917
Bruce Allane921eb12012-11-28 09:28:37 +00002918 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002919 * to 10b in word 0x13 , this can be done without an
2920 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002921 * and we need to change bit 14 to 0b
2922 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002923 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002924 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002925 if (ret_val)
2926 goto release;
2927
Auke Kokbc7f75f2007-09-17 12:30:59 -07002928 data &= 0xBFFF;
2929 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2930 act_offset * 2 + 1,
2931 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002932 if (ret_val)
2933 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002934
Bruce Allane921eb12012-11-28 09:28:37 +00002935 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002936 * its signature word (0x13) high_byte to 0b. This can be
2937 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002938 * to 1's. We can write 1's to 0's without an erase
2939 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002940 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2941 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002942 if (ret_val)
2943 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002944
2945 /* Great! Everything worked, we can now clear the cached entries. */
2946 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002947 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002948 dev_spec->shadow_ram[i].value = 0xFFFF;
2949 }
2950
Bruce Allan9c5e2092010-05-10 15:00:31 +00002951release:
Bruce Allan94d81862009-11-20 23:25:26 +00002952 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002953
Bruce Allane921eb12012-11-28 09:28:37 +00002954 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07002955 * until after the next adapter reset.
2956 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00002957 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00002958 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00002959 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002960 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961
Bruce Allane2434552008-11-21 17:02:41 -08002962out:
2963 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002964 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002965
Auke Kokbc7f75f2007-09-17 12:30:59 -07002966 return ret_val;
2967}
2968
2969/**
2970 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2971 * @hw: pointer to the HW structure
2972 *
2973 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2974 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
2975 * calculated, in which case we need to calculate the checksum and set bit 6.
2976 **/
2977static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2978{
2979 s32 ret_val;
2980 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00002981 u16 word;
2982 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002983
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00002984 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
2985 * the checksum needs to be fixed. This bit is an indication that
2986 * the NVM was prepared by OEM software and did not calculate
2987 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002988 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00002989 switch (hw->mac.type) {
2990 case e1000_pch_lpt:
2991 word = NVM_COMPAT;
2992 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
2993 break;
2994 default:
2995 word = NVM_FUTURE_INIT_WORD1;
2996 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
2997 break;
2998 }
2999
3000 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003001 if (ret_val)
3002 return ret_val;
3003
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003004 if (!(data & valid_csum_mask)) {
3005 data |= valid_csum_mask;
3006 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003007 if (ret_val)
3008 return ret_val;
3009 ret_val = e1000e_update_nvm_checksum(hw);
3010 if (ret_val)
3011 return ret_val;
3012 }
3013
3014 return e1000e_validate_nvm_checksum_generic(hw);
3015}
3016
3017/**
Bruce Allan4a770352008-10-01 17:18:35 -07003018 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3019 * @hw: pointer to the HW structure
3020 *
3021 * To prevent malicious write/erase of the NVM, set it to be read-only
3022 * so that the hardware ignores all write/erase cycles of the NVM via
3023 * the flash control registers. The shadow-ram copy of the NVM will
3024 * still be updated, however any updates to this copy will not stick
3025 * across driver reloads.
3026 **/
3027void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3028{
Bruce Allanca15df52009-10-26 11:23:43 +00003029 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003030 union ich8_flash_protected_range pr0;
3031 union ich8_hws_flash_status hsfsts;
3032 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003033
Bruce Allan94d81862009-11-20 23:25:26 +00003034 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003035
3036 gfpreg = er32flash(ICH_FLASH_GFPREG);
3037
3038 /* Write-protect GbE Sector of NVM */
3039 pr0.regval = er32flash(ICH_FLASH_PR0);
3040 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3041 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3042 pr0.range.wpe = true;
3043 ew32flash(ICH_FLASH_PR0, pr0.regval);
3044
Bruce Allane921eb12012-11-28 09:28:37 +00003045 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003046 * PR0 to prevent the write-protection from being lifted.
3047 * Once FLOCKDN is set, the registers protected by it cannot
3048 * be written until FLOCKDN is cleared by a hardware reset.
3049 */
3050 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3051 hsfsts.hsf_status.flockdn = true;
3052 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3053
Bruce Allan94d81862009-11-20 23:25:26 +00003054 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003055}
3056
3057/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003058 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3059 * @hw: pointer to the HW structure
3060 * @offset: The offset (in bytes) of the byte/word to read.
3061 * @size: Size of data to read, 1=byte 2=word
3062 * @data: The byte(s) to write to the NVM.
3063 *
3064 * Writes one/two bytes to the NVM using the flash access registers.
3065 **/
3066static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3067 u8 size, u16 data)
3068{
3069 union ich8_hws_flash_status hsfsts;
3070 union ich8_hws_flash_ctrl hsflctl;
3071 u32 flash_linear_addr;
3072 u32 flash_data = 0;
3073 s32 ret_val;
3074 u8 count = 0;
3075
3076 if (size < 1 || size > 2 || data > size * 0xff ||
3077 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3078 return -E1000_ERR_NVM;
3079
Bruce Allanf0ff4392013-02-20 04:05:39 +00003080 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3081 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003082
3083 do {
3084 udelay(1);
3085 /* Steps */
3086 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3087 if (ret_val)
3088 break;
3089
3090 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3091 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
Bruce Allan362e20c2013-02-20 04:05:45 +00003092 hsflctl.hsf_ctrl.fldbcount = size - 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3094 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3095
3096 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3097
3098 if (size == 1)
3099 flash_data = (u32)data & 0x00FF;
3100 else
3101 flash_data = (u32)data;
3102
3103 ew32flash(ICH_FLASH_FDATA0, flash_data);
3104
Bruce Allane921eb12012-11-28 09:28:37 +00003105 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003106 * and try the whole sequence a few more times else done
3107 */
Bruce Allan17e813e2013-02-20 04:06:01 +00003108 ret_val =
3109 e1000_flash_cycle_ich8lan(hw,
3110 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003111 if (!ret_val)
3112 break;
3113
Bruce Allane921eb12012-11-28 09:28:37 +00003114 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003115 * completely hosed, but if the error condition
3116 * is detected, it won't hurt to give it another
3117 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3118 */
3119 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003120 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003121 /* Repeat for some time before giving up. */
3122 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003123 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003124 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003125 break;
3126 }
3127 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3128
3129 return ret_val;
3130}
3131
3132/**
3133 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3134 * @hw: pointer to the HW structure
3135 * @offset: The index of the byte to read.
3136 * @data: The byte to write to the NVM.
3137 *
3138 * Writes a single byte to the NVM using the flash access registers.
3139 **/
3140static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3141 u8 data)
3142{
3143 u16 word = (u16)data;
3144
3145 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3146}
3147
3148/**
3149 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3150 * @hw: pointer to the HW structure
3151 * @offset: The offset of the byte to write.
3152 * @byte: The byte to write to the NVM.
3153 *
3154 * Writes a single byte to the NVM using the flash access registers.
3155 * Goes through a retry algorithm before giving up.
3156 **/
3157static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3158 u32 offset, u8 byte)
3159{
3160 s32 ret_val;
3161 u16 program_retries;
3162
3163 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3164 if (!ret_val)
3165 return ret_val;
3166
3167 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003168 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Bruce Allance43a212013-02-20 04:06:32 +00003169 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003170 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3171 if (!ret_val)
3172 break;
3173 }
3174 if (program_retries == 100)
3175 return -E1000_ERR_NVM;
3176
3177 return 0;
3178}
3179
3180/**
3181 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3182 * @hw: pointer to the HW structure
3183 * @bank: 0 for first bank, 1 for second bank, etc.
3184 *
3185 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3186 * bank N is 4096 * N + flash_reg_addr.
3187 **/
3188static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3189{
3190 struct e1000_nvm_info *nvm = &hw->nvm;
3191 union ich8_hws_flash_status hsfsts;
3192 union ich8_hws_flash_ctrl hsflctl;
3193 u32 flash_linear_addr;
3194 /* bank size is in 16bit words - adjust to bytes */
3195 u32 flash_bank_size = nvm->flash_bank_size * 2;
3196 s32 ret_val;
3197 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003198 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003199
3200 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3201
Bruce Allane921eb12012-11-28 09:28:37 +00003202 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003203 * register
3204 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003205 * consecutive sectors. The start index for the nth Hw sector
3206 * can be calculated as = bank * 4096 + n * 256
3207 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3208 * The start index for the nth Hw sector can be calculated
3209 * as = bank * 4096
3210 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3211 * (ich9 only, otherwise error condition)
3212 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3213 */
3214 switch (hsfsts.hsf_status.berasesz) {
3215 case 0:
3216 /* Hw sector size 256 */
3217 sector_size = ICH_FLASH_SEG_SIZE_256;
3218 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3219 break;
3220 case 1:
3221 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003222 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003223 break;
3224 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003225 sector_size = ICH_FLASH_SEG_SIZE_8K;
3226 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003227 break;
3228 case 3:
3229 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003230 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003231 break;
3232 default:
3233 return -E1000_ERR_NVM;
3234 }
3235
3236 /* Start with the base address, then add the sector offset. */
3237 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003238 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003239
Bruce Allan53aa82d2013-02-20 04:06:06 +00003240 for (j = 0; j < iteration; j++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003241 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00003242 u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
3243
Auke Kokbc7f75f2007-09-17 12:30:59 -07003244 /* Steps */
3245 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3246 if (ret_val)
3247 return ret_val;
3248
Bruce Allane921eb12012-11-28 09:28:37 +00003249 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003250 * Cycle field in hw flash control
3251 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003252 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3253 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3254 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3255
Bruce Allane921eb12012-11-28 09:28:37 +00003256 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003257 * block into Flash Linear address field in Flash
3258 * Address.
3259 */
3260 flash_linear_addr += (j * sector_size);
3261 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3262
Bruce Allan17e813e2013-02-20 04:06:01 +00003263 ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003264 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003265 break;
3266
Bruce Allane921eb12012-11-28 09:28:37 +00003267 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003268 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003269 * a few more times else Done
3270 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003271 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003272 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003273 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003274 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003275 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003276 return ret_val;
3277 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3278 }
3279
3280 return 0;
3281}
3282
3283/**
3284 * e1000_valid_led_default_ich8lan - Set the default LED settings
3285 * @hw: pointer to the HW structure
3286 * @data: Pointer to the LED settings
3287 *
3288 * Reads the LED default settings from the NVM to data. If the NVM LED
3289 * settings is all 0's or F's, set the LED default to a valid LED default
3290 * setting.
3291 **/
3292static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3293{
3294 s32 ret_val;
3295
3296 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3297 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003298 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003299 return ret_val;
3300 }
3301
Bruce Allane5fe2542013-02-20 04:06:27 +00003302 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003303 *data = ID_LED_DEFAULT_ICH8LAN;
3304
3305 return 0;
3306}
3307
3308/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003309 * e1000_id_led_init_pchlan - store LED configurations
3310 * @hw: pointer to the HW structure
3311 *
3312 * PCH does not control LEDs via the LEDCTL register, rather it uses
3313 * the PHY LED configuration register.
3314 *
3315 * PCH also does not have an "always on" or "always off" mode which
3316 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003317 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003318 * use "link_up" mode. The LEDs will still ID on request if there is no
3319 * link based on logic in e1000_led_[on|off]_pchlan().
3320 **/
3321static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3322{
3323 struct e1000_mac_info *mac = &hw->mac;
3324 s32 ret_val;
3325 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3326 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3327 u16 data, i, temp, shift;
3328
3329 /* Get default ID LED modes */
3330 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3331 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003332 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003333
3334 mac->ledctl_default = er32(LEDCTL);
3335 mac->ledctl_mode1 = mac->ledctl_default;
3336 mac->ledctl_mode2 = mac->ledctl_default;
3337
3338 for (i = 0; i < 4; i++) {
3339 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3340 shift = (i * 5);
3341 switch (temp) {
3342 case ID_LED_ON1_DEF2:
3343 case ID_LED_ON1_ON2:
3344 case ID_LED_ON1_OFF2:
3345 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3346 mac->ledctl_mode1 |= (ledctl_on << shift);
3347 break;
3348 case ID_LED_OFF1_DEF2:
3349 case ID_LED_OFF1_ON2:
3350 case ID_LED_OFF1_OFF2:
3351 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3352 mac->ledctl_mode1 |= (ledctl_off << shift);
3353 break;
3354 default:
3355 /* Do nothing */
3356 break;
3357 }
3358 switch (temp) {
3359 case ID_LED_DEF1_ON2:
3360 case ID_LED_ON1_ON2:
3361 case ID_LED_OFF1_ON2:
3362 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3363 mac->ledctl_mode2 |= (ledctl_on << shift);
3364 break;
3365 case ID_LED_DEF1_OFF2:
3366 case ID_LED_ON1_OFF2:
3367 case ID_LED_OFF1_OFF2:
3368 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3369 mac->ledctl_mode2 |= (ledctl_off << shift);
3370 break;
3371 default:
3372 /* Do nothing */
3373 break;
3374 }
3375 }
3376
Bruce Allan5015e532012-02-08 02:55:56 +00003377 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003378}
3379
3380/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003381 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3382 * @hw: pointer to the HW structure
3383 *
3384 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3385 * register, so the the bus width is hard coded.
3386 **/
3387static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3388{
3389 struct e1000_bus_info *bus = &hw->bus;
3390 s32 ret_val;
3391
3392 ret_val = e1000e_get_bus_info_pcie(hw);
3393
Bruce Allane921eb12012-11-28 09:28:37 +00003394 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003395 * a configuration space, but do not contain
3396 * PCI Express Capability registers, so bus width
3397 * must be hardcoded.
3398 */
3399 if (bus->width == e1000_bus_width_unknown)
3400 bus->width = e1000_bus_width_pcie_x1;
3401
3402 return ret_val;
3403}
3404
3405/**
3406 * e1000_reset_hw_ich8lan - Reset the hardware
3407 * @hw: pointer to the HW structure
3408 *
3409 * Does a full reset of the hardware which includes a reset of the PHY and
3410 * MAC.
3411 **/
3412static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3413{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003414 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003415 u16 kum_cfg;
3416 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003417 s32 ret_val;
3418
Bruce Allane921eb12012-11-28 09:28:37 +00003419 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003420 * on the last TLP read/write transaction when MAC is reset.
3421 */
3422 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003423 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003424 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003425
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003426 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003427 ew32(IMC, 0xffffffff);
3428
Bruce Allane921eb12012-11-28 09:28:37 +00003429 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003430 * any pending transactions to complete before we hit the MAC
3431 * with the global reset.
3432 */
3433 ew32(RCTL, 0);
3434 ew32(TCTL, E1000_TCTL_PSP);
3435 e1e_flush();
3436
Bruce Allan1bba4382011-03-19 00:27:20 +00003437 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003438
3439 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3440 if (hw->mac.type == e1000_ich8lan) {
3441 /* Set Tx and Rx buffer allocation to 8k apiece. */
3442 ew32(PBA, E1000_PBA_8K);
3443 /* Set Packet Buffer Size to 16k. */
3444 ew32(PBS, E1000_PBS_16K);
3445 }
3446
Bruce Allan1d5846b2009-10-29 13:46:05 +00003447 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003448 /* Save the NVM K1 bit setting */
3449 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003450 if (ret_val)
3451 return ret_val;
3452
Bruce Allan62bc8132012-03-20 03:47:57 +00003453 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003454 dev_spec->nvm_k1_enabled = true;
3455 else
3456 dev_spec->nvm_k1_enabled = false;
3457 }
3458
Auke Kokbc7f75f2007-09-17 12:30:59 -07003459 ctrl = er32(CTRL);
3460
Bruce Allan44abd5c2012-02-22 09:02:37 +00003461 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003462 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003463 * time to make sure the interface between MAC and the
3464 * external PHY is reset.
3465 */
3466 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003467
Bruce Allane921eb12012-11-28 09:28:37 +00003468 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003469 * non-managed 82579
3470 */
3471 if ((hw->mac.type == e1000_pch2lan) &&
3472 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3473 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003474 }
3475 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003476 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003477 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003478 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003479 msleep(20);
3480
Bruce Allan62bc8132012-03-20 03:47:57 +00003481 /* Set Phy Config Counter to 50msec */
3482 if (hw->mac.type == e1000_pch2lan) {
3483 reg = er32(FEXTNVM3);
3484 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3485 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3486 ew32(FEXTNVM3, reg);
3487 }
3488
Bruce Allanfc0c7762009-07-01 13:27:55 +00003489 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003490 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003491
Bruce Allane98cac42010-05-10 15:02:32 +00003492 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003493 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003494 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003495 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003496
Bruce Allane98cac42010-05-10 15:02:32 +00003497 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003498 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003499 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003500 }
Bruce Allane98cac42010-05-10 15:02:32 +00003501
Bruce Allane921eb12012-11-28 09:28:37 +00003502 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003503 * will be detected as a CRC error and be dropped rather than show up
3504 * as a bad packet to the DMA engine.
3505 */
3506 if (hw->mac.type == e1000_pchlan)
3507 ew32(CRC_OFFSET, 0x65656565);
3508
Auke Kokbc7f75f2007-09-17 12:30:59 -07003509 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003510 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003511
Bruce Allan62bc8132012-03-20 03:47:57 +00003512 reg = er32(KABGTXD);
3513 reg |= E1000_KABGTXD_BGSQLBIAS;
3514 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003515
Bruce Allan5015e532012-02-08 02:55:56 +00003516 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003517}
3518
3519/**
3520 * e1000_init_hw_ich8lan - Initialize the hardware
3521 * @hw: pointer to the HW structure
3522 *
3523 * Prepares the hardware for transmit and receive by doing the following:
3524 * - initialize hardware bits
3525 * - initialize LED identification
3526 * - setup receive address registers
3527 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003528 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003529 * - clear statistics
3530 **/
3531static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3532{
3533 struct e1000_mac_info *mac = &hw->mac;
3534 u32 ctrl_ext, txdctl, snoop;
3535 s32 ret_val;
3536 u16 i;
3537
3538 e1000_initialize_hw_bits_ich8lan(hw);
3539
3540 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003541 ret_val = mac->ops.id_led_init(hw);
Bruce Allan33550ce2013-02-20 04:06:16 +00003542 /* An error is not fatal and we should not stop init due to this */
Bruce Allande39b752009-11-20 23:27:59 +00003543 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003544 e_dbg("Error initializing identification LED\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003545
3546 /* Setup the receive address. */
3547 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3548
3549 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003550 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003551 for (i = 0; i < mac->mta_reg_count; i++)
3552 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3553
Bruce Allane921eb12012-11-28 09:28:37 +00003554 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003555 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003556 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3557 */
3558 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003559 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3560 i &= ~BM_WUC_HOST_WU_BIT;
3561 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003562 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3563 if (ret_val)
3564 return ret_val;
3565 }
3566
Auke Kokbc7f75f2007-09-17 12:30:59 -07003567 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003568 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003569
3570 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003571 txdctl = er32(TXDCTL(0));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003572 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3573 E1000_TXDCTL_FULL_TX_DESC_WB);
3574 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3575 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003576 ew32(TXDCTL(0), txdctl);
3577 txdctl = er32(TXDCTL(1));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003578 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3579 E1000_TXDCTL_FULL_TX_DESC_WB);
3580 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3581 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003582 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003583
Bruce Allane921eb12012-11-28 09:28:37 +00003584 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003585 * By default, we should use snoop behavior.
3586 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003587 if (mac->type == e1000_ich8lan)
3588 snoop = PCIE_ICH8_SNOOP_ALL;
3589 else
Bruce Allan53aa82d2013-02-20 04:06:06 +00003590 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003591 e1000e_set_pcie_no_snoop(hw, snoop);
3592
3593 ctrl_ext = er32(CTRL_EXT);
3594 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3595 ew32(CTRL_EXT, ctrl_ext);
3596
Bruce Allane921eb12012-11-28 09:28:37 +00003597 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003598 * important that we do this after we have tried to establish link
3599 * because the symbol error count will increment wildly if there
3600 * is no link.
3601 */
3602 e1000_clear_hw_cntrs_ich8lan(hw);
3603
Bruce Allane561a702012-02-08 02:55:46 +00003604 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003605}
Bruce Allanfc830b72013-02-20 04:06:11 +00003606
Auke Kokbc7f75f2007-09-17 12:30:59 -07003607/**
3608 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3609 * @hw: pointer to the HW structure
3610 *
3611 * Sets/Clears required hardware bits necessary for correctly setting up the
3612 * hardware for transmit and receive.
3613 **/
3614static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3615{
3616 u32 reg;
3617
3618 /* Extended Device Control */
3619 reg = er32(CTRL_EXT);
3620 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003621 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3622 if (hw->mac.type >= e1000_pchlan)
3623 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003624 ew32(CTRL_EXT, reg);
3625
3626 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003627 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003628 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003629 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003630
3631 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003632 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003633 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003634 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003635
3636 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003637 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003638 if (hw->mac.type == e1000_ich8lan)
3639 reg |= (1 << 28) | (1 << 29);
3640 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003641 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003642
3643 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003644 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003645 if (er32(TCTL) & E1000_TCTL_MULR)
3646 reg &= ~(1 << 28);
3647 else
3648 reg |= (1 << 28);
3649 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003650 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003651
3652 /* Device Status */
3653 if (hw->mac.type == e1000_ich8lan) {
3654 reg = er32(STATUS);
3655 reg &= ~(1 << 31);
3656 ew32(STATUS, reg);
3657 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003658
Bruce Allane921eb12012-11-28 09:28:37 +00003659 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003660 * traffic, just disable the nfs filtering capability
3661 */
3662 reg = er32(RFCTL);
3663 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003664
Bruce Allane921eb12012-11-28 09:28:37 +00003665 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003666 * IPv6 headers can hang the Rx.
3667 */
3668 if (hw->mac.type == e1000_ich8lan)
3669 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003670 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00003671
3672 /* Enable ECC on Lynxpoint */
3673 if (hw->mac.type == e1000_pch_lpt) {
3674 reg = er32(PBECCSTS);
3675 reg |= E1000_PBECCSTS_ECC_ENABLE;
3676 ew32(PBECCSTS, reg);
3677
3678 reg = er32(CTRL);
3679 reg |= E1000_CTRL_MEHE;
3680 ew32(CTRL, reg);
3681 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682}
3683
3684/**
3685 * e1000_setup_link_ich8lan - Setup flow control and link settings
3686 * @hw: pointer to the HW structure
3687 *
3688 * Determines which flow control settings to use, then configures flow
3689 * control. Calls the appropriate media-specific link configuration
3690 * function. Assuming the adapter has a valid link partner, a valid link
3691 * should be established. Assumes the hardware has previously been reset
3692 * and the transmitter and receiver are not enabled.
3693 **/
3694static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3695{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696 s32 ret_val;
3697
Bruce Allan44abd5c2012-02-22 09:02:37 +00003698 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003699 return 0;
3700
Bruce Allane921eb12012-11-28 09:28:37 +00003701 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003702 * the default flow control setting, so we explicitly
3703 * set it to full.
3704 */
Bruce Allan37289d92009-06-02 11:29:37 +00003705 if (hw->fc.requested_mode == e1000_fc_default) {
3706 /* Workaround h/w hang when Tx flow control enabled */
3707 if (hw->mac.type == e1000_pchlan)
3708 hw->fc.requested_mode = e1000_fc_rx_pause;
3709 else
3710 hw->fc.requested_mode = e1000_fc_full;
3711 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003712
Bruce Allane921eb12012-11-28 09:28:37 +00003713 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003714 * on the link partner's capabilities, we may or may not use this mode.
3715 */
3716 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003717
Bruce Allan17e813e2013-02-20 04:06:01 +00003718 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003719
3720 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003721 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003722 if (ret_val)
3723 return ret_val;
3724
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003725 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003726 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003727 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003728 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003729 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003730 ew32(FCRTV_PCH, hw->fc.refresh_time);
3731
Bruce Allan482fed82011-01-06 14:29:49 +00003732 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3733 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003734 if (ret_val)
3735 return ret_val;
3736 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003737
3738 return e1000e_set_fc_watermarks(hw);
3739}
3740
3741/**
3742 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3743 * @hw: pointer to the HW structure
3744 *
3745 * Configures the kumeran interface to the PHY to wait the appropriate time
3746 * when polling the PHY, then call the generic setup_copper_link to finish
3747 * configuring the copper link.
3748 **/
3749static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3750{
3751 u32 ctrl;
3752 s32 ret_val;
3753 u16 reg_data;
3754
3755 ctrl = er32(CTRL);
3756 ctrl |= E1000_CTRL_SLU;
3757 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3758 ew32(CTRL, ctrl);
3759
Bruce Allane921eb12012-11-28 09:28:37 +00003760 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003761 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003762 * this fixes erroneous timeouts at 10Mbps.
3763 */
Bruce Allan07818952009-12-08 07:28:01 +00003764 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003765 if (ret_val)
3766 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003767 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003768 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003769 if (ret_val)
3770 return ret_val;
3771 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003772 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003773 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003774 if (ret_val)
3775 return ret_val;
3776
Bruce Allana4f58f52009-06-02 11:29:18 +00003777 switch (hw->phy.type) {
3778 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003779 ret_val = e1000e_copper_link_setup_igp(hw);
3780 if (ret_val)
3781 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003782 break;
3783 case e1000_phy_bm:
3784 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003785 ret_val = e1000e_copper_link_setup_m88(hw);
3786 if (ret_val)
3787 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003788 break;
3789 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003790 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003791 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +00003792 ret_val = e1000_copper_link_setup_82577(hw);
3793 if (ret_val)
3794 return ret_val;
3795 break;
3796 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003797 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003798 if (ret_val)
3799 return ret_val;
3800
3801 reg_data &= ~IFE_PMC_AUTO_MDIX;
3802
3803 switch (hw->phy.mdix) {
3804 case 1:
3805 reg_data &= ~IFE_PMC_FORCE_MDIX;
3806 break;
3807 case 2:
3808 reg_data |= IFE_PMC_FORCE_MDIX;
3809 break;
3810 case 0:
3811 default:
3812 reg_data |= IFE_PMC_AUTO_MDIX;
3813 break;
3814 }
Bruce Allan482fed82011-01-06 14:29:49 +00003815 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003816 if (ret_val)
3817 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003818 break;
3819 default:
3820 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003821 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003822
Auke Kokbc7f75f2007-09-17 12:30:59 -07003823 return e1000e_setup_copper_link(hw);
3824}
3825
3826/**
3827 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3828 * @hw: pointer to the HW structure
3829 * @speed: pointer to store current link speed
3830 * @duplex: pointer to store the current link duplex
3831 *
Bruce Allanad680762008-03-28 09:15:03 -07003832 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003833 * information and then calls the Kumeran lock loss workaround for links at
3834 * gigabit speeds.
3835 **/
3836static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3837 u16 *duplex)
3838{
3839 s32 ret_val;
3840
3841 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3842 if (ret_val)
3843 return ret_val;
3844
3845 if ((hw->mac.type == e1000_ich8lan) &&
Bruce Allane5fe2542013-02-20 04:06:27 +00003846 (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003847 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3848 }
3849
3850 return ret_val;
3851}
3852
3853/**
3854 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3855 * @hw: pointer to the HW structure
3856 *
3857 * Work-around for 82566 Kumeran PCS lock loss:
3858 * On link status change (i.e. PCI reset, speed change) and link is up and
3859 * speed is gigabit-
3860 * 0) if workaround is optionally disabled do nothing
3861 * 1) wait 1ms for Kumeran link to come up
3862 * 2) check Kumeran Diagnostic register PCS lock loss bit
3863 * 3) if not set the link is locked (all is good), otherwise...
3864 * 4) reset the PHY
3865 * 5) repeat up to 10 times
3866 * Note: this is only called for IGP3 copper when speed is 1gb.
3867 **/
3868static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3869{
3870 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3871 u32 phy_ctrl;
3872 s32 ret_val;
3873 u16 i, data;
3874 bool link;
3875
3876 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3877 return 0;
3878
Bruce Allane921eb12012-11-28 09:28:37 +00003879 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003880 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003881 * stability
3882 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003883 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3884 if (!link)
3885 return 0;
3886
3887 for (i = 0; i < 10; i++) {
3888 /* read once to clear */
3889 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3890 if (ret_val)
3891 return ret_val;
3892 /* and again to get new status */
3893 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3894 if (ret_val)
3895 return ret_val;
3896
3897 /* check for PCS lock */
3898 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3899 return 0;
3900
3901 /* Issue PHY reset */
3902 e1000_phy_hw_reset(hw);
3903 mdelay(5);
3904 }
3905 /* Disable GigE link negotiation */
3906 phy_ctrl = er32(PHY_CTRL);
3907 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3908 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3909 ew32(PHY_CTRL, phy_ctrl);
3910
Bruce Allane921eb12012-11-28 09:28:37 +00003911 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07003912 * any PHY registers
3913 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003914 e1000e_gig_downshift_workaround_ich8lan(hw);
3915
3916 /* unable to acquire PCS lock */
3917 return -E1000_ERR_PHY;
3918}
3919
3920/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00003921 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003922 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003923 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003924 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003925 * If ICH8, set the current Kumeran workaround state (enabled - true
3926 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003927 **/
3928void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00003929 bool state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003930{
3931 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3932
3933 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003934 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003935 return;
3936 }
3937
3938 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3939}
3940
3941/**
3942 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3943 * @hw: pointer to the HW structure
3944 *
3945 * Workaround for 82566 power-down on D3 entry:
3946 * 1) disable gigabit link
3947 * 2) write VR power-down enable
3948 * 3) read it back
3949 * Continue if successful, else issue LCD reset and repeat
3950 **/
3951void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3952{
3953 u32 reg;
3954 u16 data;
3955 u8 retry = 0;
3956
3957 if (hw->phy.type != e1000_phy_igp_3)
3958 return;
3959
3960 /* Try the workaround twice (if needed) */
3961 do {
3962 /* Disable link */
3963 reg = er32(PHY_CTRL);
3964 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3965 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3966 ew32(PHY_CTRL, reg);
3967
Bruce Allane921eb12012-11-28 09:28:37 +00003968 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07003969 * accessing any PHY registers
3970 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003971 if (hw->mac.type == e1000_ich8lan)
3972 e1000e_gig_downshift_workaround_ich8lan(hw);
3973
3974 /* Write VR power-down enable */
3975 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3976 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3977 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
3978
3979 /* Read it back and test */
3980 e1e_rphy(hw, IGP3_VR_CTRL, &data);
3981 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3982 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
3983 break;
3984
3985 /* Issue PHY reset and repeat at most one more time */
3986 reg = er32(CTRL);
3987 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
3988 retry++;
3989 } while (retry);
3990}
3991
3992/**
3993 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
3994 * @hw: pointer to the HW structure
3995 *
3996 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08003997 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07003998 * 1) Set Kumeran Near-end loopback
3999 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004000 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004001 **/
4002void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4003{
4004 s32 ret_val;
4005 u16 reg_data;
4006
Bruce Allan462d5992011-09-30 08:07:11 +00004007 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004008 return;
4009
4010 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004011 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004012 if (ret_val)
4013 return;
4014 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4015 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004016 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004017 if (ret_val)
4018 return;
4019 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00004020 e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004021}
4022
4023/**
Bruce Allan99730e42011-05-13 07:19:48 +00004024 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004025 * @hw: pointer to the HW structure
4026 *
4027 * During S0 to Sx transition, it is possible the link remains at gig
4028 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004029 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4030 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4031 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4032 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004033 * Parts that support (and are linked to a partner which support) EEE in
4034 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4035 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004036 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004037void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004038{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004039 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004040 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004041 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004042
Bruce Allan17f085d2010-06-17 18:59:48 +00004043 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004044 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allane08f6262013-02-20 03:06:34 +00004045
Bruce Allan2fbe4522012-04-19 03:21:47 +00004046 if (hw->phy.type == e1000_phy_i217) {
Bruce Allane08f6262013-02-20 03:06:34 +00004047 u16 phy_reg, device_id = hw->adapter->pdev->device;
4048
4049 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
4050 (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V)) {
4051 u32 fextnvm6 = er32(FEXTNVM6);
4052
4053 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
4054 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004055
4056 ret_val = hw->phy.ops.acquire(hw);
4057 if (ret_val)
4058 goto out;
4059
4060 if (!dev_spec->eee_disable) {
4061 u16 eee_advert;
4062
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004063 ret_val =
4064 e1000_read_emi_reg_locked(hw,
4065 I217_EEE_ADVERTISEMENT,
4066 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004067 if (ret_val)
4068 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004069
Bruce Allane921eb12012-11-28 09:28:37 +00004070 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004071 * EEE and 100Full is advertised on both ends of the
4072 * link.
4073 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004074 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004075 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004076 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004077 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4078 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4079 E1000_PHY_CTRL_NOND0A_LPLU);
4080 }
4081
Bruce Allane921eb12012-11-28 09:28:37 +00004082 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004083 * when the system is going into Sx and no manageability engine
4084 * is present, the driver must configure proxy to reset only on
4085 * power good. LPI (Low Power Idle) state must also reset only
4086 * on power good, as well as the MTA (Multicast table array).
4087 * The SMBus release must also be disabled on LCD reset.
4088 */
4089 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00004090 /* Enable proxy to reset only on power good. */
4091 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4092 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4093 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4094
Bruce Allane921eb12012-11-28 09:28:37 +00004095 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004096 * power good.
4097 */
4098 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004099 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004100 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4101
4102 /* Disable the SMB release on LCD reset. */
4103 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004104 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004105 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4106 }
4107
Bruce Allane921eb12012-11-28 09:28:37 +00004108 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004109 * Support
4110 */
4111 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004112 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004113 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4114
4115release:
4116 hw->phy.ops.release(hw);
4117 }
4118out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004119 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004120
Bruce Allan462d5992011-09-30 08:07:11 +00004121 if (hw->mac.type == e1000_ich8lan)
4122 e1000e_gig_downshift_workaround_ich8lan(hw);
4123
Bruce Allan8395ae82010-09-22 17:15:08 +00004124 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004125 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004126
4127 /* Reset PHY to activate OEM bits on 82577/8 */
4128 if (hw->mac.type == e1000_pchlan)
4129 e1000e_phy_hw_reset_generic(hw);
4130
Bruce Allan8395ae82010-09-22 17:15:08 +00004131 ret_val = hw->phy.ops.acquire(hw);
4132 if (ret_val)
4133 return;
4134 e1000_write_smbus_addr(hw);
4135 hw->phy.ops.release(hw);
4136 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004137}
4138
4139/**
Bruce Allan99730e42011-05-13 07:19:48 +00004140 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4141 * @hw: pointer to the HW structure
4142 *
4143 * During Sx to S0 transitions on non-managed devices or managed devices
4144 * on which PHY resets are not blocked, if the PHY registers cannot be
4145 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4146 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004147 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004148 **/
4149void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4150{
Bruce Allan90b82982011-12-16 00:46:33 +00004151 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004152
Bruce Allancb17aab2012-04-13 03:16:22 +00004153 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004154 return;
4155
Bruce Allancb17aab2012-04-13 03:16:22 +00004156 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004157 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004158 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004159 return;
4160 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004161
Bruce Allane921eb12012-11-28 09:28:37 +00004162 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004163 * is transitioning from Sx and no manageability engine is present
4164 * configure SMBus to restore on reset, disable proxy, and enable
4165 * the reset on MTA (Multicast table array).
4166 */
4167 if (hw->phy.type == e1000_phy_i217) {
4168 u16 phy_reg;
4169
4170 ret_val = hw->phy.ops.acquire(hw);
4171 if (ret_val) {
4172 e_dbg("Failed to setup iRST\n");
4173 return;
4174 }
4175
4176 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004177 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004178 * is present
4179 */
4180 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4181 if (ret_val)
4182 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004183 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004184 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4185
4186 /* Disable Proxy */
4187 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4188 }
4189 /* Enable reset on MTA */
4190 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4191 if (ret_val)
4192 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004193 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004194 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4195release:
4196 if (ret_val)
4197 e_dbg("Error %d in resume workarounds\n", ret_val);
4198 hw->phy.ops.release(hw);
4199 }
Bruce Allan99730e42011-05-13 07:19:48 +00004200}
4201
4202/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004203 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4204 * @hw: pointer to the HW structure
4205 *
4206 * Return the LED back to the default configuration.
4207 **/
4208static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4209{
4210 if (hw->phy.type == e1000_phy_ife)
4211 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4212
4213 ew32(LEDCTL, hw->mac.ledctl_default);
4214 return 0;
4215}
4216
4217/**
Auke Kok489815c2008-02-21 15:11:07 -08004218 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004219 * @hw: pointer to the HW structure
4220 *
Auke Kok489815c2008-02-21 15:11:07 -08004221 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004222 **/
4223static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4224{
4225 if (hw->phy.type == e1000_phy_ife)
4226 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4227 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4228
4229 ew32(LEDCTL, hw->mac.ledctl_mode2);
4230 return 0;
4231}
4232
4233/**
Auke Kok489815c2008-02-21 15:11:07 -08004234 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004235 * @hw: pointer to the HW structure
4236 *
Auke Kok489815c2008-02-21 15:11:07 -08004237 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004238 **/
4239static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4240{
4241 if (hw->phy.type == e1000_phy_ife)
4242 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004243 (IFE_PSCL_PROBE_MODE |
4244 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004245
4246 ew32(LEDCTL, hw->mac.ledctl_mode1);
4247 return 0;
4248}
4249
4250/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004251 * e1000_setup_led_pchlan - Configures SW controllable LED
4252 * @hw: pointer to the HW structure
4253 *
4254 * This prepares the SW controllable LED for use.
4255 **/
4256static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4257{
Bruce Allan482fed82011-01-06 14:29:49 +00004258 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004259}
4260
4261/**
4262 * e1000_cleanup_led_pchlan - Restore the default LED operation
4263 * @hw: pointer to the HW structure
4264 *
4265 * Return the LED back to the default configuration.
4266 **/
4267static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4268{
Bruce Allan482fed82011-01-06 14:29:49 +00004269 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004270}
4271
4272/**
4273 * e1000_led_on_pchlan - Turn LEDs on
4274 * @hw: pointer to the HW structure
4275 *
4276 * Turn on the LEDs.
4277 **/
4278static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4279{
4280 u16 data = (u16)hw->mac.ledctl_mode2;
4281 u32 i, led;
4282
Bruce Allane921eb12012-11-28 09:28:37 +00004283 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004284 * for each LED that's mode is "link_up" in ledctl_mode2.
4285 */
4286 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4287 for (i = 0; i < 3; i++) {
4288 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4289 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4290 E1000_LEDCTL_MODE_LINK_UP)
4291 continue;
4292 if (led & E1000_PHY_LED0_IVRT)
4293 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4294 else
4295 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4296 }
4297 }
4298
Bruce Allan482fed82011-01-06 14:29:49 +00004299 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004300}
4301
4302/**
4303 * e1000_led_off_pchlan - Turn LEDs off
4304 * @hw: pointer to the HW structure
4305 *
4306 * Turn off the LEDs.
4307 **/
4308static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4309{
4310 u16 data = (u16)hw->mac.ledctl_mode1;
4311 u32 i, led;
4312
Bruce Allane921eb12012-11-28 09:28:37 +00004313 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004314 * for each LED that's mode is "link_up" in ledctl_mode1.
4315 */
4316 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4317 for (i = 0; i < 3; i++) {
4318 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4319 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4320 E1000_LEDCTL_MODE_LINK_UP)
4321 continue;
4322 if (led & E1000_PHY_LED0_IVRT)
4323 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4324 else
4325 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4326 }
4327 }
4328
Bruce Allan482fed82011-01-06 14:29:49 +00004329 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004330}
4331
4332/**
Bruce Allane98cac42010-05-10 15:02:32 +00004333 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004334 * @hw: pointer to the HW structure
4335 *
Bruce Allane98cac42010-05-10 15:02:32 +00004336 * Read appropriate register for the config done bit for completion status
4337 * and configure the PHY through s/w for EEPROM-less parts.
4338 *
4339 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4340 * config done bit, so only an error is logged and continues. If we were
4341 * to return with error, EEPROM-less silicon would not be able to be reset
4342 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004343 **/
4344static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4345{
Bruce Allane98cac42010-05-10 15:02:32 +00004346 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004347 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004348 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004349
Bruce Allanfe908492013-01-05 08:06:14 +00004350 e1000e_get_cfg_done_generic(hw);
Bruce Allanf4187b52008-08-26 18:36:50 -07004351
Bruce Allane98cac42010-05-10 15:02:32 +00004352 /* Wait for indication from h/w that it has completed basic config */
4353 if (hw->mac.type >= e1000_ich10lan) {
4354 e1000_lan_init_done_ich8lan(hw);
4355 } else {
4356 ret_val = e1000e_get_auto_rd_done(hw);
4357 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004358 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004359 * return with an error. This can happen in situations
4360 * where there is no eeprom and prevents getting link.
4361 */
4362 e_dbg("Auto Read Done did not complete\n");
4363 ret_val = 0;
4364 }
4365 }
4366
4367 /* Clear PHY Reset Asserted bit */
4368 status = er32(STATUS);
4369 if (status & E1000_STATUS_PHYRA)
4370 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4371 else
4372 e_dbg("PHY Reset Asserted not set - needs delay\n");
4373
Bruce Allanf4187b52008-08-26 18:36:50 -07004374 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004375 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004376 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004377 (hw->phy.type == e1000_phy_igp_3)) {
4378 e1000e_phy_init_script_igp3(hw);
4379 }
4380 } else {
4381 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4382 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004383 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004384 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004385 }
4386 }
4387
Bruce Allane98cac42010-05-10 15:02:32 +00004388 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004389}
4390
4391/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004392 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4393 * @hw: pointer to the HW structure
4394 *
4395 * In the case of a PHY power down to save power, or to turn off link during a
4396 * driver unload, or wake on lan is not enabled, remove the link.
4397 **/
4398static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4399{
4400 /* If the management interface is not enabled, then power down */
4401 if (!(hw->mac.ops.check_mng_mode(hw) ||
4402 hw->phy.ops.check_reset_block(hw)))
4403 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004404}
4405
4406/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004407 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4408 * @hw: pointer to the HW structure
4409 *
4410 * Clears hardware counters specific to the silicon family and calls
4411 * clear_hw_cntrs_generic to clear all general purpose counters.
4412 **/
4413static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4414{
Bruce Allana4f58f52009-06-02 11:29:18 +00004415 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004416 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004417
4418 e1000e_clear_hw_cntrs_base(hw);
4419
Bruce Allan99673d92009-11-20 23:27:21 +00004420 er32(ALGNERRC);
4421 er32(RXERRC);
4422 er32(TNCRS);
4423 er32(CEXTERR);
4424 er32(TSCTC);
4425 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004426
Bruce Allan99673d92009-11-20 23:27:21 +00004427 er32(MGTPRC);
4428 er32(MGTPDC);
4429 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004430
Bruce Allan99673d92009-11-20 23:27:21 +00004431 er32(IAC);
4432 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004433
Bruce Allana4f58f52009-06-02 11:29:18 +00004434 /* Clear PHY statistics registers */
4435 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004436 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004437 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004438 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004439 ret_val = hw->phy.ops.acquire(hw);
4440 if (ret_val)
4441 return;
4442 ret_val = hw->phy.ops.set_page(hw,
4443 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4444 if (ret_val)
4445 goto release;
4446 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4447 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4448 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4449 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4450 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4451 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4452 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4453 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4454 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4455 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4456 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4457 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4458 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4459 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4460release:
4461 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004462 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004463}
4464
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004465static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004466 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004467 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004468 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004469 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4470 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004471 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004472 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004473 /* led_on dependent on mac type */
4474 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004475 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476 .reset_hw = e1000_reset_hw_ich8lan,
4477 .init_hw = e1000_init_hw_ich8lan,
4478 .setup_link = e1000_setup_link_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004479 .setup_physical_interface = e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004480 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004481 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004482 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004483};
4484
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004485static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004486 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004487 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004488 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004489 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004490 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004491 .read_reg = e1000e_read_phy_reg_igp,
4492 .release = e1000_release_swflag_ich8lan,
4493 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004494 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4495 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004496 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004497};
4498
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004499static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004500 .acquire = e1000_acquire_nvm_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004501 .read = e1000_read_nvm_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004502 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004503 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004504 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004505 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004506 .validate = e1000_validate_nvm_checksum_ich8lan,
4507 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004508};
4509
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004510const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004511 .mac = e1000_ich8lan,
4512 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004513 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004514 | FLAG_HAS_CTRLEXT_ON_LOAD
4515 | FLAG_HAS_AMT
4516 | FLAG_HAS_FLASH
4517 | FLAG_APME_IN_WUC,
4518 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004519 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004520 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004521 .mac_ops = &ich8_mac_ops,
4522 .phy_ops = &ich8_phy_ops,
4523 .nvm_ops = &ich8_nvm_ops,
4524};
4525
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004526const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004527 .mac = e1000_ich9lan,
4528 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004529 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004530 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004531 | FLAG_HAS_CTRLEXT_ON_LOAD
4532 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004533 | FLAG_HAS_FLASH
4534 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004535 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004536 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004537 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004538 .mac_ops = &ich8_mac_ops,
4539 .phy_ops = &ich8_phy_ops,
4540 .nvm_ops = &ich8_nvm_ops,
4541};
4542
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004543const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004544 .mac = e1000_ich10lan,
4545 .flags = FLAG_HAS_JUMBO_FRAMES
4546 | FLAG_IS_ICH
4547 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004548 | FLAG_HAS_CTRLEXT_ON_LOAD
4549 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004550 | FLAG_HAS_FLASH
4551 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004552 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004553 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004554 .get_variants = e1000_get_variants_ich8lan,
4555 .mac_ops = &ich8_mac_ops,
4556 .phy_ops = &ich8_phy_ops,
4557 .nvm_ops = &ich8_nvm_ops,
4558};
Bruce Allana4f58f52009-06-02 11:29:18 +00004559
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004560const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004561 .mac = e1000_pchlan,
4562 .flags = FLAG_IS_ICH
4563 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004564 | FLAG_HAS_CTRLEXT_ON_LOAD
4565 | FLAG_HAS_AMT
4566 | FLAG_HAS_FLASH
4567 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004568 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004569 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004570 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004571 .pba = 26,
4572 .max_hw_frame_size = 4096,
4573 .get_variants = e1000_get_variants_ich8lan,
4574 .mac_ops = &ich8_mac_ops,
4575 .phy_ops = &ich8_phy_ops,
4576 .nvm_ops = &ich8_nvm_ops,
4577};
Bruce Alland3738bb2010-06-16 13:27:28 +00004578
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004579const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004580 .mac = e1000_pch2lan,
4581 .flags = FLAG_IS_ICH
4582 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004583 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00004584 | FLAG_HAS_CTRLEXT_ON_LOAD
4585 | FLAG_HAS_AMT
4586 | FLAG_HAS_FLASH
4587 | FLAG_HAS_JUMBO_FRAMES
4588 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004589 .flags2 = FLAG2_HAS_PHY_STATS
4590 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004591 .pba = 26,
Bruce Allanc3d2dbf2013-01-09 01:20:46 +00004592 .max_hw_frame_size = 9018,
Bruce Alland3738bb2010-06-16 13:27:28 +00004593 .get_variants = e1000_get_variants_ich8lan,
4594 .mac_ops = &ich8_mac_ops,
4595 .phy_ops = &ich8_phy_ops,
4596 .nvm_ops = &ich8_nvm_ops,
4597};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004598
4599const struct e1000_info e1000_pch_lpt_info = {
4600 .mac = e1000_pch_lpt,
4601 .flags = FLAG_IS_ICH
4602 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004603 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00004604 | FLAG_HAS_CTRLEXT_ON_LOAD
4605 | FLAG_HAS_AMT
4606 | FLAG_HAS_FLASH
4607 | FLAG_HAS_JUMBO_FRAMES
4608 | FLAG_APME_IN_WUC,
4609 .flags2 = FLAG2_HAS_PHY_STATS
4610 | FLAG2_HAS_EEE,
4611 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00004612 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004613 .get_variants = e1000_get_variants_ich8lan,
4614 .mac_ops = &ich8_mac_ops,
4615 .phy_ops = &ich8_phy_ops,
4616 .nvm_ops = &ich8_nvm_ops,
4617};