blob: b56c61acbac104175818912fb49e2ae09e28bd4a [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allane921eb12012-11-28 09:28:37 +000029/* 82562G 10/100 Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070030 * 82562G-2 10/100 Network Connection
31 * 82562GT 10/100 Network Connection
32 * 82562GT-2 10/100 Network Connection
33 * 82562V 10/100 Network Connection
34 * 82562V-2 10/100 Network Connection
35 * 82566DC-2 Gigabit Network Connection
36 * 82566DC Gigabit Network Connection
37 * 82566DM-2 Gigabit Network Connection
38 * 82566DM Gigabit Network Connection
39 * 82566MC Gigabit Network Connection
40 * 82566MM Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070041 * 82567LM Gigabit Network Connection
42 * 82567LF Gigabit Network Connection
Bruce Allan16059272008-11-21 16:51:06 -080043 * 82567V Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070044 * 82567LM-2 Gigabit Network Connection
45 * 82567LF-2 Gigabit Network Connection
46 * 82567V-2 Gigabit Network Connection
Bruce Allanf4187b52008-08-26 18:36:50 -070047 * 82567LF-3 Gigabit Network Connection
48 * 82567LM-3 Gigabit Network Connection
Bruce Allan2f15f9d2008-08-26 18:36:36 -070049 * 82567LM-4 Gigabit Network Connection
Bruce Allana4f58f52009-06-02 11:29:18 +000050 * 82577LM Gigabit Network Connection
51 * 82577LC Gigabit Network Connection
52 * 82578DM Gigabit Network Connection
53 * 82578DC Gigabit Network Connection
Bruce Alland3738bb2010-06-16 13:27:28 +000054 * 82579LM Gigabit Network Connection
55 * 82579V Gigabit Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070056 */
57
Auke Kokbc7f75f2007-09-17 12:30:59 -070058#include "e1000.h"
59
Auke Kokbc7f75f2007-09-17 12:30:59 -070060/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
61/* Offset 04h HSFSTS */
62union ich8_hws_flash_status {
63 struct ich8_hsfsts {
Bruce Allan362e20c2013-02-20 04:05:45 +000064 u16 flcdone:1; /* bit 0 Flash Cycle Done */
65 u16 flcerr:1; /* bit 1 Flash Cycle Error */
66 u16 dael:1; /* bit 2 Direct Access error Log */
67 u16 berasesz:2; /* bit 4:3 Sector Erase Size */
68 u16 flcinprog:1; /* bit 5 flash cycle in Progress */
69 u16 reserved1:2; /* bit 13:6 Reserved */
70 u16 reserved2:6; /* bit 13:6 Reserved */
71 u16 fldesvalid:1; /* bit 14 Flash Descriptor Valid */
72 u16 flockdn:1; /* bit 15 Flash Config Lock-Down */
Auke Kokbc7f75f2007-09-17 12:30:59 -070073 } hsf_status;
74 u16 regval;
75};
76
77/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
78/* Offset 06h FLCTL */
79union ich8_hws_flash_ctrl {
80 struct ich8_hsflctl {
Bruce Allan362e20c2013-02-20 04:05:45 +000081 u16 flcgo:1; /* 0 Flash Cycle Go */
82 u16 flcycle:2; /* 2:1 Flash Cycle */
83 u16 reserved:5; /* 7:3 Reserved */
84 u16 fldbcount:2; /* 9:8 Flash Data Byte Count */
85 u16 flockdn:6; /* 15:10 Reserved */
Auke Kokbc7f75f2007-09-17 12:30:59 -070086 } hsf_ctrl;
87 u16 regval;
88};
89
90/* ICH Flash Region Access Permissions */
91union ich8_hws_flash_regacc {
92 struct ich8_flracc {
Bruce Allan362e20c2013-02-20 04:05:45 +000093 u32 grra:8; /* 0:7 GbE region Read Access */
94 u32 grwa:8; /* 8:15 GbE region Write Access */
95 u32 gmrag:8; /* 23:16 GbE Master Read Access Grant */
96 u32 gmwag:8; /* 31:24 GbE Master Write Access Grant */
Auke Kokbc7f75f2007-09-17 12:30:59 -070097 } hsf_flregacc;
98 u16 regval;
99};
100
Bruce Allan4a770352008-10-01 17:18:35 -0700101/* ICH Flash Protected Region */
102union ich8_flash_protected_range {
103 struct ich8_pr {
Bruce Allane80bd1d2013-05-01 01:19:46 +0000104 u32 base:13; /* 0:12 Protected Range Base */
105 u32 reserved1:2; /* 13:14 Reserved */
106 u32 rpe:1; /* 15 Read Protection Enable */
107 u32 limit:13; /* 16:28 Protected Range Limit */
108 u32 reserved2:2; /* 29:30 Reserved */
109 u32 wpe:1; /* 31 Write Protection Enable */
Bruce Allan4a770352008-10-01 17:18:35 -0700110 } range;
111 u32 regval;
112};
113
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
115static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700116static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
117static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
118 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700119static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
120 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700121static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
122 u16 *data);
123static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
124 u8 size, u16 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700125static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000126static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
127static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
128static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
129static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
130static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
131static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
132static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
133static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000134static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000135static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000136static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1f96012d2013-01-05 03:06:54 +0000137static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000138static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000139static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
140static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan69e1e012012-04-14 03:28:50 +0000141static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000142static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000143static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000144static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
Bruce Allanea8179a2013-03-06 09:02:47 +0000145static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700146
147static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
148{
149 return readw(hw->flash_address + reg);
150}
151
152static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
153{
154 return readl(hw->flash_address + reg);
155}
156
157static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
158{
159 writew(val, hw->flash_address + reg);
160}
161
162static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
163{
164 writel(val, hw->flash_address + reg);
165}
166
167#define er16flash(reg) __er16flash(hw, (reg))
168#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000169#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
170#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700171
Bruce Allancb17aab2012-04-13 03:16:22 +0000172/**
173 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
174 * @hw: pointer to the HW structure
175 *
176 * Test access to the PHY registers by reading the PHY ID registers. If
177 * the PHY ID is already known (e.g. resume path) compare it with known ID,
178 * otherwise assume the read PHY ID is correct if it is valid.
179 *
180 * Assumes the sw/fw/hw semaphore is already acquired.
181 **/
182static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000183{
Bruce Allana52359b2012-07-14 04:23:58 +0000184 u16 phy_reg = 0;
185 u32 phy_id = 0;
186 s32 ret_val;
187 u16 retry_count;
Bruce Allan99730e42011-05-13 07:19:48 +0000188
Bruce Allana52359b2012-07-14 04:23:58 +0000189 for (retry_count = 0; retry_count < 2; retry_count++) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000190 ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000191 if (ret_val || (phy_reg == 0xFFFF))
192 continue;
193 phy_id = (u32)(phy_reg << 16);
194
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000195 ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
Bruce Allana52359b2012-07-14 04:23:58 +0000196 if (ret_val || (phy_reg == 0xFFFF)) {
197 phy_id = 0;
198 continue;
199 }
200 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
201 break;
202 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000203
Bruce Allancb17aab2012-04-13 03:16:22 +0000204 if (hw->phy.id) {
205 if (hw->phy.id == phy_id)
206 return true;
Bruce Allana52359b2012-07-14 04:23:58 +0000207 } else if (phy_id) {
208 hw->phy.id = phy_id;
209 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allancb17aab2012-04-13 03:16:22 +0000210 return true;
211 }
212
Bruce Allane921eb12012-11-28 09:28:37 +0000213 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000214 * set slow mode and try to get the PHY id again.
215 */
216 hw->phy.ops.release(hw);
217 ret_val = e1000_set_mdio_slow_mode_hv(hw);
218 if (!ret_val)
219 ret_val = e1000e_get_phy_id(hw);
220 hw->phy.ops.acquire(hw);
221
222 return !ret_val;
Bruce Allancb17aab2012-04-13 03:16:22 +0000223}
224
225/**
226 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
227 * @hw: pointer to the HW structure
228 *
229 * Workarounds/flow necessary for PHY initialization during driver load
230 * and resume paths.
231 **/
232static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
233{
234 u32 mac_reg, fwsm = er32(FWSM);
235 s32 ret_val;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000236 u16 phy_reg;
Bruce Allancb17aab2012-04-13 03:16:22 +0000237
Bruce Allan6e928b72012-12-12 04:45:51 +0000238 /* Gate automatic PHY configuration by hardware on managed and
239 * non-managed 82579 and newer adapters.
240 */
241 e1000_gate_hw_phy_config_ich8lan(hw, true);
242
Bruce Allancb17aab2012-04-13 03:16:22 +0000243 ret_val = hw->phy.ops.acquire(hw);
244 if (ret_val) {
245 e_dbg("Failed to initialize PHY flow\n");
Bruce Allan6e928b72012-12-12 04:45:51 +0000246 goto out;
Bruce Allancb17aab2012-04-13 03:16:22 +0000247 }
248
Bruce Allane921eb12012-11-28 09:28:37 +0000249 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000250 * inaccessible and resetting the PHY is not blocked, toggle the
251 * LANPHYPC Value bit to force the interconnect to PCIe mode.
252 */
253 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000254 case e1000_pch_lpt:
255 if (e1000_phy_is_accessible_pchlan(hw))
256 break;
257
Bruce Allane921eb12012-11-28 09:28:37 +0000258 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000259 * forcing MAC to SMBus mode first.
260 */
261 mac_reg = er32(CTRL_EXT);
262 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
263 ew32(CTRL_EXT, mac_reg);
264
265 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000266 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000267 if (e1000_phy_is_accessible_pchlan(hw)) {
268 if (hw->mac.type == e1000_pch_lpt) {
269 /* Unforce SMBus mode in PHY */
270 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
271 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
272 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
273
274 /* Unforce SMBus mode in MAC */
275 mac_reg = er32(CTRL_EXT);
276 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
277 ew32(CTRL_EXT, mac_reg);
278 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000279 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000280 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000281
282 /* fall-through */
283 case e1000_pchlan:
284 if ((hw->mac.type == e1000_pchlan) &&
285 (fwsm & E1000_ICH_FWSM_FW_VALID))
286 break;
287
288 if (hw->phy.ops.check_reset_block(hw)) {
289 e_dbg("Required LANPHYPC toggle blocked by ME\n");
290 break;
291 }
292
293 e_dbg("Toggling LANPHYPC\n");
294
295 /* Set Phy Config Counter to 50msec */
296 mac_reg = er32(FEXTNVM3);
297 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
298 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
299 ew32(FEXTNVM3, mac_reg);
300
Bruce Allan4e035102013-01-04 09:53:19 +0000301 if (hw->mac.type == e1000_pch_lpt) {
302 /* Toggling LANPHYPC brings the PHY out of SMBus mode
303 * So ensure that the MAC is also out of SMBus mode
304 */
305 mac_reg = er32(CTRL_EXT);
306 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
307 ew32(CTRL_EXT, mac_reg);
308 }
309
Bruce Allancb17aab2012-04-13 03:16:22 +0000310 /* Toggle LANPHYPC Value bit */
311 mac_reg = er32(CTRL);
312 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
313 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
314 ew32(CTRL, mac_reg);
315 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +0000316 usleep_range(10, 20);
Bruce Allancb17aab2012-04-13 03:16:22 +0000317 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
318 ew32(CTRL, mac_reg);
319 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000320 if (hw->mac.type < e1000_pch_lpt) {
321 msleep(50);
322 } else {
323 u16 count = 20;
324 do {
325 usleep_range(5000, 10000);
326 } while (!(er32(CTRL_EXT) &
327 E1000_CTRL_EXT_LPCD) && count--);
328 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000329 break;
330 default:
331 break;
332 }
333
334 hw->phy.ops.release(hw);
335
Bruce Allane921eb12012-11-28 09:28:37 +0000336 /* Reset the PHY before any access to it. Doing so, ensures
Bruce Allancb17aab2012-04-13 03:16:22 +0000337 * that the PHY is in a known good state before we read/write
338 * PHY registers. The generic reset is sufficient here,
339 * because we haven't determined the PHY type yet.
340 */
341 ret_val = e1000e_phy_hw_reset_generic(hw);
342
Bruce Allan6e928b72012-12-12 04:45:51 +0000343out:
Bruce Allancb17aab2012-04-13 03:16:22 +0000344 /* Ungate automatic PHY configuration on non-managed 82579 */
345 if ((hw->mac.type == e1000_pch2lan) &&
346 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
347 usleep_range(10000, 20000);
348 e1000_gate_hw_phy_config_ich8lan(hw, false);
349 }
350
351 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000352}
353
Auke Kokbc7f75f2007-09-17 12:30:59 -0700354/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000355 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
356 * @hw: pointer to the HW structure
357 *
358 * Initialize family-specific PHY parameters and function pointers.
359 **/
360static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
361{
362 struct e1000_phy_info *phy = &hw->phy;
Bruce Allan70806a72013-01-05 05:08:37 +0000363 s32 ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +0000364
Bruce Allane80bd1d2013-05-01 01:19:46 +0000365 phy->addr = 1;
366 phy->reset_delay_us = 100;
Bruce Allana4f58f52009-06-02 11:29:18 +0000367
Bruce Allane80bd1d2013-05-01 01:19:46 +0000368 phy->ops.set_page = e1000_set_page_igp;
369 phy->ops.read_reg = e1000_read_phy_reg_hv;
370 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
371 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
372 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
373 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
374 phy->ops.write_reg = e1000_write_phy_reg_hv;
375 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
376 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
377 phy->ops.power_up = e1000_power_up_phy_copper;
378 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
379 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allana4f58f52009-06-02 11:29:18 +0000380
381 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000382
383 ret_val = e1000_init_phy_workarounds_pchlan(hw);
384 if (ret_val)
385 return ret_val;
386
387 if (phy->id == e1000_phy_unknown)
388 switch (hw->mac.type) {
389 default:
390 ret_val = e1000e_get_phy_id(hw);
391 if (ret_val)
392 return ret_val;
393 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
394 break;
395 /* fall-through */
396 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000397 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000398 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000399 * set slow mode and try to get the PHY id again.
400 */
401 ret_val = e1000_set_mdio_slow_mode_hv(hw);
402 if (ret_val)
403 return ret_val;
404 ret_val = e1000e_get_phy_id(hw);
405 if (ret_val)
406 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000407 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000408 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000409 phy->type = e1000e_get_phy_type_from_id(phy->id);
410
Bruce Allan0be84012009-12-02 17:03:18 +0000411 switch (phy->type) {
412 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000413 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000414 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000415 phy->ops.check_polarity = e1000_check_polarity_82577;
416 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000417 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000418 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000419 phy->ops.get_info = e1000_get_phy_info_82577;
420 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000421 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000422 case e1000_phy_82578:
423 phy->ops.check_polarity = e1000_check_polarity_m88;
424 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
425 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
426 phy->ops.get_info = e1000e_get_phy_info_m88;
427 break;
428 default:
429 ret_val = -E1000_ERR_PHY;
430 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000431 }
432
433 return ret_val;
434}
435
436/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700437 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
438 * @hw: pointer to the HW structure
439 *
440 * Initialize family-specific PHY parameters and function pointers.
441 **/
442static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
443{
444 struct e1000_phy_info *phy = &hw->phy;
445 s32 ret_val;
446 u16 i = 0;
447
Bruce Allane80bd1d2013-05-01 01:19:46 +0000448 phy->addr = 1;
449 phy->reset_delay_us = 100;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700450
Bruce Allane80bd1d2013-05-01 01:19:46 +0000451 phy->ops.power_up = e1000_power_up_phy_copper;
452 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allan17f208d2009-12-01 15:47:22 +0000453
Bruce Allane921eb12012-11-28 09:28:37 +0000454 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700455 * we'll set BM func pointers and try again
456 */
457 ret_val = e1000e_determine_phy_address(hw);
458 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000459 phy->ops.write_reg = e1000e_write_phy_reg_bm;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000460 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700461 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000462 if (ret_val) {
463 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700464 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000465 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700466 }
467
Auke Kokbc7f75f2007-09-17 12:30:59 -0700468 phy->id = 0;
469 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
470 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000471 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700472 ret_val = e1000e_get_phy_id(hw);
473 if (ret_val)
474 return ret_val;
475 }
476
477 /* Verify phy id */
478 switch (phy->id) {
479 case IGP03E1000_E_PHY_ID:
480 phy->type = e1000_phy_igp_3;
481 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000482 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
483 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000484 phy->ops.get_info = e1000e_get_phy_info_igp;
485 phy->ops.check_polarity = e1000_check_polarity_igp;
486 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700487 break;
488 case IFE_E_PHY_ID:
489 case IFE_PLUS_E_PHY_ID:
490 case IFE_C_E_PHY_ID:
491 phy->type = e1000_phy_ife;
492 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000493 phy->ops.get_info = e1000_get_phy_info_ife;
494 phy->ops.check_polarity = e1000_check_polarity_ife;
495 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700496 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700497 case BME1000_E_PHY_ID:
498 phy->type = e1000_phy_bm;
499 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000500 phy->ops.read_reg = e1000e_read_phy_reg_bm;
501 phy->ops.write_reg = e1000e_write_phy_reg_bm;
502 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000503 phy->ops.get_info = e1000e_get_phy_info_m88;
504 phy->ops.check_polarity = e1000_check_polarity_m88;
505 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700506 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700507 default:
508 return -E1000_ERR_PHY;
509 break;
510 }
511
512 return 0;
513}
514
515/**
516 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
517 * @hw: pointer to the HW structure
518 *
519 * Initialize family-specific NVM parameters and function
520 * pointers.
521 **/
522static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
523{
524 struct e1000_nvm_info *nvm = &hw->nvm;
525 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000526 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700527 u16 i;
528
Bruce Allanad680762008-03-28 09:15:03 -0700529 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700530 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000531 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532 return -E1000_ERR_CONFIG;
533 }
534
535 nvm->type = e1000_nvm_flash_sw;
536
537 gfpreg = er32flash(ICH_FLASH_GFPREG);
538
Bruce Allane921eb12012-11-28 09:28:37 +0000539 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700540 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700541 * the overall size.
542 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700543 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
544 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
545
546 /* flash_base_addr is byte-aligned */
547 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
548
Bruce Allane921eb12012-11-28 09:28:37 +0000549 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700550 * size represents two separate NVM banks.
551 */
Bruce Allanf0ff4392013-02-20 04:05:39 +0000552 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
553 << FLASH_SECTOR_ADDR_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700554 nvm->flash_bank_size /= 2;
555 /* Adjust to word count */
556 nvm->flash_bank_size /= sizeof(u16);
557
558 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
559
560 /* Clear shadow ram */
561 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000562 dev_spec->shadow_ram[i].modified = false;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000563 dev_spec->shadow_ram[i].value = 0xFFFF;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700564 }
565
566 return 0;
567}
568
569/**
570 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
571 * @hw: pointer to the HW structure
572 *
573 * Initialize family-specific MAC parameters and function
574 * pointers.
575 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000576static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700578 struct e1000_mac_info *mac = &hw->mac;
579
580 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700581 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700582
583 /* Set mta register count */
584 mac->mta_reg_count = 32;
585 /* Set rar entry count */
586 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
587 if (mac->type == e1000_ich8lan)
588 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000589 /* FWSM register */
590 mac->has_fwsm = true;
591 /* ARC subsystem not supported */
592 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000593 /* Adaptive IFS supported */
594 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700595
Bruce Allan2fbe4522012-04-19 03:21:47 +0000596 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000597 switch (mac->type) {
598 case e1000_ich8lan:
599 case e1000_ich9lan:
600 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000601 /* check management mode */
602 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000603 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000604 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000605 /* blink LED */
606 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000607 /* setup LED */
608 mac->ops.setup_led = e1000e_setup_led_generic;
609 /* cleanup LED */
610 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
611 /* turn on/off LED */
612 mac->ops.led_on = e1000_led_on_ich8lan;
613 mac->ops.led_off = e1000_led_off_ich8lan;
614 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000615 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000616 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
617 mac->ops.rar_set = e1000_rar_set_pch2lan;
618 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000619 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000620 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000621 /* check management mode */
622 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000623 /* ID LED init */
624 mac->ops.id_led_init = e1000_id_led_init_pchlan;
625 /* setup LED */
626 mac->ops.setup_led = e1000_setup_led_pchlan;
627 /* cleanup LED */
628 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
629 /* turn on/off LED */
630 mac->ops.led_on = e1000_led_on_pchlan;
631 mac->ops.led_off = e1000_led_off_pchlan;
632 break;
633 default:
634 break;
635 }
636
Bruce Allan2fbe4522012-04-19 03:21:47 +0000637 if (mac->type == e1000_pch_lpt) {
638 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
639 mac->ops.rar_set = e1000_rar_set_pch_lpt;
Bruce Allanea8179a2013-03-06 09:02:47 +0000640 mac->ops.setup_physical_interface =
641 e1000_setup_copper_link_pch_lpt;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000642 }
643
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644 /* Enable PCS Lock-loss workaround for ICH8 */
645 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000646 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700647
648 return 0;
649}
650
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000651/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000652 * __e1000_access_emi_reg_locked - Read/write EMI register
653 * @hw: pointer to the HW structure
654 * @addr: EMI address to program
655 * @data: pointer to value to read/write from/to the EMI address
656 * @read: boolean flag to indicate read or write
657 *
658 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
659 **/
660static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
661 u16 *data, bool read)
662{
Bruce Allan70806a72013-01-05 05:08:37 +0000663 s32 ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000664
665 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
666 if (ret_val)
667 return ret_val;
668
669 if (read)
670 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
671 else
672 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
673
674 return ret_val;
675}
676
677/**
678 * e1000_read_emi_reg_locked - Read Extended Management Interface register
679 * @hw: pointer to the HW structure
680 * @addr: EMI address to program
681 * @data: value to be read from the EMI address
682 *
683 * Assumes the SW/FW/HW Semaphore is already acquired.
684 **/
Bruce Allan203e4152012-12-05 08:40:59 +0000685s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000686{
687 return __e1000_access_emi_reg_locked(hw, addr, data, true);
688}
689
690/**
691 * e1000_write_emi_reg_locked - Write Extended Management Interface register
692 * @hw: pointer to the HW structure
693 * @addr: EMI address to program
694 * @data: value to be written to the EMI address
695 *
696 * Assumes the SW/FW/HW Semaphore is already acquired.
697 **/
Bruce Alland495bcb2013-03-20 07:23:11 +0000698s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000699{
700 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
701}
702
703/**
Bruce Allane52997f2010-06-16 13:27:49 +0000704 * e1000_set_eee_pchlan - Enable/disable EEE support
705 * @hw: pointer to the HW structure
706 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000707 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
708 * the link and the EEE capabilities of the link partner. The LPI Control
709 * register bits will remain set only if/when link is up.
Bruce Allane52997f2010-06-16 13:27:49 +0000710 **/
711static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
712{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000713 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000714 s32 ret_val;
Bruce Alland495bcb2013-03-20 07:23:11 +0000715 u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
Bruce Allane52997f2010-06-16 13:27:49 +0000716
Bruce Alland495bcb2013-03-20 07:23:11 +0000717 switch (hw->phy.type) {
718 case e1000_phy_82579:
719 lpa = I82579_EEE_LP_ABILITY;
720 pcs_status = I82579_EEE_PCS_STATUS;
721 adv_addr = I82579_EEE_ADVERTISEMENT;
722 break;
723 case e1000_phy_i217:
724 lpa = I217_EEE_LP_ABILITY;
725 pcs_status = I217_EEE_PCS_STATUS;
726 adv_addr = I217_EEE_ADVERTISEMENT;
727 break;
728 default:
Bruce Allan5015e532012-02-08 02:55:56 +0000729 return 0;
Bruce Alland495bcb2013-03-20 07:23:11 +0000730 }
Bruce Allane52997f2010-06-16 13:27:49 +0000731
Bruce Allan3d4d5752012-12-05 06:26:08 +0000732 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000733 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000734 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000735
Bruce Allan3d4d5752012-12-05 06:26:08 +0000736 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000737 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000738 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000739
Bruce Allan3d4d5752012-12-05 06:26:08 +0000740 /* Clear bits that enable EEE in various speeds */
741 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
742
743 /* Enable EEE if not disabled by user */
744 if (!dev_spec->eee_disable) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000745 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000746 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000747 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000748 if (ret_val)
749 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000750
Bruce Alland495bcb2013-03-20 07:23:11 +0000751 /* Read EEE advertisement */
752 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
753 if (ret_val)
754 goto release;
755
Bruce Allan3d4d5752012-12-05 06:26:08 +0000756 /* Enable EEE only for speeds in which the link partner is
Bruce Alland495bcb2013-03-20 07:23:11 +0000757 * EEE capable and for which we advertise EEE.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000758 */
Bruce Alland495bcb2013-03-20 07:23:11 +0000759 if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000760 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
761
Bruce Alland495bcb2013-03-20 07:23:11 +0000762 if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000763 e1e_rphy_locked(hw, MII_LPA, &data);
764 if (data & LPA_100FULL)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000765 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
766 else
767 /* EEE is not supported in 100Half, so ignore
768 * partner's EEE in 100 ability if full-duplex
769 * is not advertised.
770 */
771 dev_spec->eee_lp_ability &=
772 ~I82579_EEE_100_SUPPORTED;
773 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000774 }
775
Bruce Alland495bcb2013-03-20 07:23:11 +0000776 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
777 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
778 if (ret_val)
779 goto release;
780
Bruce Allan3d4d5752012-12-05 06:26:08 +0000781 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
782release:
783 hw->phy.ops.release(hw);
784
785 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000786}
787
788/**
Bruce Allane08f6262013-02-20 03:06:34 +0000789 * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
790 * @hw: pointer to the HW structure
791 * @link: link up bool flag
792 *
793 * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
794 * preventing further DMA write requests. Workaround the issue by disabling
795 * the de-assertion of the clock request when in 1Gpbs mode.
Bruce Allane0236ad2013-06-21 09:07:13 +0000796 * Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
797 * speeds in order to avoid Tx hangs.
Bruce Allane08f6262013-02-20 03:06:34 +0000798 **/
799static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
800{
801 u32 fextnvm6 = er32(FEXTNVM6);
Bruce Allane0236ad2013-06-21 09:07:13 +0000802 u32 status = er32(STATUS);
Bruce Allane08f6262013-02-20 03:06:34 +0000803 s32 ret_val = 0;
Bruce Allane0236ad2013-06-21 09:07:13 +0000804 u16 reg;
Bruce Allane08f6262013-02-20 03:06:34 +0000805
Bruce Allane0236ad2013-06-21 09:07:13 +0000806 if (link && (status & E1000_STATUS_SPEED_1000)) {
Bruce Allane08f6262013-02-20 03:06:34 +0000807 ret_val = hw->phy.ops.acquire(hw);
808 if (ret_val)
809 return ret_val;
810
811 ret_val =
812 e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000813 &reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000814 if (ret_val)
815 goto release;
816
817 ret_val =
818 e1000e_write_kmrn_reg_locked(hw,
819 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000820 reg &
Bruce Allane08f6262013-02-20 03:06:34 +0000821 ~E1000_KMRNCTRLSTA_K1_ENABLE);
822 if (ret_val)
823 goto release;
824
825 usleep_range(10, 20);
826
827 ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
828
829 ret_val =
830 e1000e_write_kmrn_reg_locked(hw,
831 E1000_KMRNCTRLSTA_K1_CONFIG,
Bruce Allane0236ad2013-06-21 09:07:13 +0000832 reg);
Bruce Allane08f6262013-02-20 03:06:34 +0000833release:
834 hw->phy.ops.release(hw);
835 } else {
836 /* clear FEXTNVM6 bit 8 on link down or 10/100 */
Bruce Allane0236ad2013-06-21 09:07:13 +0000837 fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
838
839 if (!link || ((status & E1000_STATUS_SPEED_100) &&
840 (status & E1000_STATUS_FD)))
841 goto update_fextnvm6;
842
843 ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
844 if (ret_val)
845 return ret_val;
846
847 /* Clear link status transmit timeout */
848 reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
849
850 if (status & E1000_STATUS_SPEED_100) {
851 /* Set inband Tx timeout to 5x10us for 100Half */
852 reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
853
854 /* Do not extend the K1 entry latency for 100Half */
855 fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
856 } else {
857 /* Set inband Tx timeout to 50x10us for 10Full/Half */
858 reg |= 50 <<
859 I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
860
861 /* Extend the K1 entry latency for 10 Mbps */
862 fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
863 }
864
865 ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
866 if (ret_val)
867 return ret_val;
868
869update_fextnvm6:
870 ew32(FEXTNVM6, fextnvm6);
Bruce Allane08f6262013-02-20 03:06:34 +0000871 }
872
873 return ret_val;
874}
875
876/**
Bruce Allancf8fb732013-03-06 09:03:02 +0000877 * e1000_platform_pm_pch_lpt - Set platform power management values
878 * @hw: pointer to the HW structure
879 * @link: bool indicating link status
880 *
881 * Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
882 * GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
883 * when link is up (which must not exceed the maximum latency supported
884 * by the platform), otherwise specify there is no LTR requirement.
885 * Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
886 * latencies in the LTR Extended Capability Structure in the PCIe Extended
887 * Capability register set, on this device LTR is set by writing the
888 * equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
889 * set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
890 * message to the PMC.
891 **/
892static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
893{
894 u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
895 link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
896 u16 lat_enc = 0; /* latency encoded */
897
898 if (link) {
899 u16 speed, duplex, scale = 0;
900 u16 max_snoop, max_nosnoop;
901 u16 max_ltr_enc; /* max LTR latency encoded */
902 s64 lat_ns; /* latency (ns) */
903 s64 value;
904 u32 rxa;
905
906 if (!hw->adapter->max_frame_size) {
907 e_dbg("max_frame_size not set.\n");
908 return -E1000_ERR_CONFIG;
909 }
910
911 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
912 if (!speed) {
913 e_dbg("Speed not set.\n");
914 return -E1000_ERR_CONFIG;
915 }
916
917 /* Rx Packet Buffer Allocation size (KB) */
918 rxa = er32(PBA) & E1000_PBA_RXA_MASK;
919
920 /* Determine the maximum latency tolerated by the device.
921 *
922 * Per the PCIe spec, the tolerated latencies are encoded as
923 * a 3-bit encoded scale (only 0-5 are valid) multiplied by
924 * a 10-bit value (0-1023) to provide a range from 1 ns to
925 * 2^25*(2^10-1) ns. The scale is encoded as 0=2^0ns,
926 * 1=2^5ns, 2=2^10ns,...5=2^25ns.
927 */
928 lat_ns = ((s64)rxa * 1024 -
929 (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
930 if (lat_ns < 0)
931 lat_ns = 0;
932 else
933 do_div(lat_ns, speed);
934
935 value = lat_ns;
936 while (value > PCI_LTR_VALUE_MASK) {
937 scale++;
938 value = DIV_ROUND_UP(value, (1 << 5));
939 }
940 if (scale > E1000_LTRV_SCALE_MAX) {
941 e_dbg("Invalid LTR latency scale %d\n", scale);
942 return -E1000_ERR_CONFIG;
943 }
944 lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
945
946 /* Determine the maximum latency tolerated by the platform */
947 pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
948 &max_snoop);
949 pci_read_config_word(hw->adapter->pdev,
950 E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
951 max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
952
953 if (lat_enc > max_ltr_enc)
954 lat_enc = max_ltr_enc;
955 }
956
957 /* Set Snoop and No-Snoop latencies the same */
958 reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
959 ew32(LTRV, reg);
960
961 return 0;
962}
963
964/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000965 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
966 * @hw: pointer to the HW structure
967 *
968 * Checks to see of the link status of the hardware has changed. If a
969 * change in link status has been detected, then we read the PHY registers
970 * to get the current speed/duplex if link exists.
971 **/
972static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
973{
974 struct e1000_mac_info *mac = &hw->mac;
975 s32 ret_val;
976 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000977 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000978
Bruce Allane921eb12012-11-28 09:28:37 +0000979 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000980 * has completed and/or if our link status has changed. The
981 * get_link_status flag is set upon receiving a Link Status
982 * Change or Rx Sequence Error interrupt.
983 */
Bruce Allan5015e532012-02-08 02:55:56 +0000984 if (!mac->get_link_status)
985 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000986
Bruce Allane921eb12012-11-28 09:28:37 +0000987 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000988 * link. If so, then we want to get the current speed/duplex
989 * of the PHY.
990 */
991 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
992 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000993 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000994
Bruce Allan1d5846b2009-10-29 13:46:05 +0000995 if (hw->mac.type == e1000_pchlan) {
996 ret_val = e1000_k1_gig_workaround_hv(hw, link);
997 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000998 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +0000999 }
1000
Bruce Allan772d05c2013-03-06 09:02:36 +00001001 /* When connected at 10Mbps half-duplex, 82579 parts are excessively
1002 * aggressive resulting in many collisions. To avoid this, increase
1003 * the IPG and reduce Rx latency in the PHY.
1004 */
1005 if ((hw->mac.type == e1000_pch2lan) && link) {
1006 u32 reg;
1007 reg = er32(STATUS);
1008 if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
1009 reg = er32(TIPG);
1010 reg &= ~E1000_TIPG_IPGT_MASK;
1011 reg |= 0xFF;
1012 ew32(TIPG, reg);
1013
1014 /* Reduce Rx latency in analog PHY */
1015 ret_val = hw->phy.ops.acquire(hw);
1016 if (ret_val)
1017 return ret_val;
1018
1019 ret_val =
1020 e1000_write_emi_reg_locked(hw, I82579_RX_CONFIG, 0);
1021
1022 hw->phy.ops.release(hw);
1023
1024 if (ret_val)
1025 return ret_val;
1026 }
1027 }
1028
Bruce Allane08f6262013-02-20 03:06:34 +00001029 /* Work-around I218 hang issue */
1030 if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
1031 (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V)) {
1032 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
1033 if (ret_val)
1034 return ret_val;
1035 }
1036
Bruce Allancf8fb732013-03-06 09:03:02 +00001037 if (hw->mac.type == e1000_pch_lpt) {
1038 /* Set platform power management values for
1039 * Latency Tolerance Reporting (LTR)
1040 */
1041 ret_val = e1000_platform_pm_pch_lpt(hw, link);
1042 if (ret_val)
1043 return ret_val;
1044 }
1045
Bruce Allan2fbe4522012-04-19 03:21:47 +00001046 /* Clear link partner's EEE ability */
1047 hw->dev_spec.ich8lan.eee_lp_ability = 0;
1048
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001049 if (!link)
Bruce Allane80bd1d2013-05-01 01:19:46 +00001050 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001051
1052 mac->get_link_status = false;
1053
Bruce Allan1d2101a72011-07-22 06:21:56 +00001054 switch (hw->mac.type) {
1055 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +00001056 ret_val = e1000_k1_workaround_lv(hw);
1057 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001058 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001059 /* fall-thru */
1060 case e1000_pchlan:
1061 if (hw->phy.type == e1000_phy_82578) {
1062 ret_val = e1000_link_stall_workaround_hv(hw);
1063 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001064 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +00001065 }
1066
Bruce Allane921eb12012-11-28 09:28:37 +00001067 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +00001068 * Set the number of preambles removed from the packet
1069 * when it is passed from the PHY to the MAC to prevent
1070 * the MAC from misinterpreting the packet type.
1071 */
1072 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
1073 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
1074
1075 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
1076 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
1077
1078 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
1079 break;
1080 default:
1081 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001082 }
1083
Bruce Allane921eb12012-11-28 09:28:37 +00001084 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001085 * immediately after link-up
1086 */
1087 e1000e_check_downshift(hw);
1088
Bruce Allane52997f2010-06-16 13:27:49 +00001089 /* Enable/Disable EEE after link up */
1090 ret_val = e1000_set_eee_pchlan(hw);
1091 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001092 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +00001093
Bruce Allane921eb12012-11-28 09:28:37 +00001094 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001095 * we have already determined whether we have link or not.
1096 */
Bruce Allan5015e532012-02-08 02:55:56 +00001097 if (!mac->autoneg)
1098 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001099
Bruce Allane921eb12012-11-28 09:28:37 +00001100 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001101 * of MAC speed/duplex configuration. So we only need to
1102 * configure Collision Distance in the MAC.
1103 */
Bruce Allan57cde762012-02-22 09:02:58 +00001104 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001105
Bruce Allane921eb12012-11-28 09:28:37 +00001106 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001107 * First, we need to restore the desired flow control
1108 * settings because we may have had to re-autoneg with a
1109 * different link partner.
1110 */
1111 ret_val = e1000e_config_fc_after_link_up(hw);
1112 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001113 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001114
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001115 return ret_val;
1116}
1117
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001118static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119{
1120 struct e1000_hw *hw = &adapter->hw;
1121 s32 rc;
1122
Bruce Allanec34c172012-02-01 10:53:05 +00001123 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001124 if (rc)
1125 return rc;
1126
1127 rc = e1000_init_nvm_params_ich8lan(hw);
1128 if (rc)
1129 return rc;
1130
Bruce Alland3738bb2010-06-16 13:27:28 +00001131 switch (hw->mac.type) {
1132 case e1000_ich8lan:
1133 case e1000_ich9lan:
1134 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001135 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001136 break;
1137 case e1000_pchlan:
1138 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001139 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001140 rc = e1000_init_phy_params_pchlan(hw);
1141 break;
1142 default:
1143 break;
1144 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145 if (rc)
1146 return rc;
1147
Bruce Allane921eb12012-11-28 09:28:37 +00001148 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001149 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1150 */
1151 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1152 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1153 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001154 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1155 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001156
1157 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001158 }
1159
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001161 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1163
Bruce Allanc6e7f512011-07-29 05:53:02 +00001164 /* Enable workaround for 82579 w/ ME enabled */
1165 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1166 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1167 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1168
Auke Kokbc7f75f2007-09-17 12:30:59 -07001169 return 0;
1170}
1171
Thomas Gleixner717d4382008-10-02 16:33:40 -07001172static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001173
Auke Kokbc7f75f2007-09-17 12:30:59 -07001174/**
Bruce Allanca15df52009-10-26 11:23:43 +00001175 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1176 * @hw: pointer to the HW structure
1177 *
1178 * Acquires the mutex for performing NVM operations.
1179 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001180static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001181{
1182 mutex_lock(&nvm_mutex);
1183
1184 return 0;
1185}
1186
1187/**
1188 * e1000_release_nvm_ich8lan - Release NVM mutex
1189 * @hw: pointer to the HW structure
1190 *
1191 * Releases the mutex used while performing NVM operations.
1192 **/
Bruce Allan8bb62862013-01-16 08:46:49 +00001193static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
Bruce Allanca15df52009-10-26 11:23:43 +00001194{
1195 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001196}
1197
Bruce Allanca15df52009-10-26 11:23:43 +00001198/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001199 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1200 * @hw: pointer to the HW structure
1201 *
Bruce Allanca15df52009-10-26 11:23:43 +00001202 * Acquires the software control flag for performing PHY and select
1203 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001204 **/
1205static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1206{
Bruce Allan373a88d2009-08-07 07:41:37 +00001207 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1208 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209
Bruce Allana90b4122011-10-07 03:50:38 +00001210 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1211 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001212 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001213 return -E1000_ERR_PHY;
1214 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001215
Auke Kokbc7f75f2007-09-17 12:30:59 -07001216 while (timeout) {
1217 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001218 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1219 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001220
Auke Kokbc7f75f2007-09-17 12:30:59 -07001221 mdelay(1);
1222 timeout--;
1223 }
1224
1225 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001226 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001227 ret_val = -E1000_ERR_CONFIG;
1228 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001229 }
1230
Bruce Allan53ac5a82009-10-26 11:23:06 +00001231 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001232
1233 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1234 ew32(EXTCNF_CTRL, extcnf_ctrl);
1235
1236 while (timeout) {
1237 extcnf_ctrl = er32(EXTCNF_CTRL);
1238 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1239 break;
1240
1241 mdelay(1);
1242 timeout--;
1243 }
1244
1245 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001246 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 +00001247 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001248 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1249 ew32(EXTCNF_CTRL, extcnf_ctrl);
1250 ret_val = -E1000_ERR_CONFIG;
1251 goto out;
1252 }
1253
1254out:
1255 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001256 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001257
1258 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001259}
1260
1261/**
1262 * e1000_release_swflag_ich8lan - Release software control flag
1263 * @hw: pointer to the HW structure
1264 *
Bruce Allanca15df52009-10-26 11:23:43 +00001265 * Releases the software control flag for performing PHY and select
1266 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001267 **/
1268static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1269{
1270 u32 extcnf_ctrl;
1271
1272 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001273
1274 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1275 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1276 ew32(EXTCNF_CTRL, extcnf_ctrl);
1277 } else {
1278 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1279 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001280
Bruce Allana90b4122011-10-07 03:50:38 +00001281 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282}
1283
1284/**
Bruce Allan4662e822008-08-26 18:37:06 -07001285 * e1000_check_mng_mode_ich8lan - Checks management mode
1286 * @hw: pointer to the HW structure
1287 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001288 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001289 * This is a function pointer entry point only called by read/write
1290 * routines for the PHY and NVM parts.
1291 **/
1292static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1293{
Bruce Allana708dd82009-11-20 23:28:37 +00001294 u32 fwsm;
1295
1296 fwsm = er32(FWSM);
Bruce Allanf0ff4392013-02-20 04:05:39 +00001297 return ((fwsm & E1000_ICH_FWSM_FW_VALID) &&
1298 ((fwsm & E1000_FWSM_MODE_MASK) ==
1299 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)));
Bruce Allaneb7700d2010-06-16 13:27:05 +00001300}
Bruce Allan4662e822008-08-26 18:37:06 -07001301
Bruce Allaneb7700d2010-06-16 13:27:05 +00001302/**
1303 * e1000_check_mng_mode_pchlan - Checks management mode
1304 * @hw: pointer to the HW structure
1305 *
1306 * This checks if the adapter has iAMT enabled.
1307 * This is a function pointer entry point only called by read/write
1308 * routines for the PHY and NVM parts.
1309 **/
1310static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1311{
1312 u32 fwsm;
1313
1314 fwsm = er32(FWSM);
1315 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
Bruce Allanf0ff4392013-02-20 04:05:39 +00001316 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001317}
1318
1319/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001320 * e1000_rar_set_pch2lan - Set receive address register
1321 * @hw: pointer to the HW structure
1322 * @addr: pointer to the receive address
1323 * @index: receive address array register
1324 *
1325 * Sets the receive address array register at index to the address passed
1326 * in by addr. For 82579, RAR[0] is the base address register that is to
1327 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1328 * Use SHRA[0-3] in place of those reserved for ME.
1329 **/
1330static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1331{
1332 u32 rar_low, rar_high;
1333
Bruce Allane921eb12012-11-28 09:28:37 +00001334 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001335 * from network order (big endian) to little endian
1336 */
1337 rar_low = ((u32)addr[0] |
1338 ((u32)addr[1] << 8) |
1339 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1340
1341 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1342
1343 /* If MAC address zero, no need to set the AV bit */
1344 if (rar_low || rar_high)
1345 rar_high |= E1000_RAH_AV;
1346
1347 if (index == 0) {
1348 ew32(RAL(index), rar_low);
1349 e1e_flush();
1350 ew32(RAH(index), rar_high);
1351 e1e_flush();
1352 return;
1353 }
1354
1355 if (index < hw->mac.rar_entry_count) {
1356 s32 ret_val;
1357
1358 ret_val = e1000_acquire_swflag_ich8lan(hw);
1359 if (ret_val)
1360 goto out;
1361
1362 ew32(SHRAL(index - 1), rar_low);
1363 e1e_flush();
1364 ew32(SHRAH(index - 1), rar_high);
1365 e1e_flush();
1366
1367 e1000_release_swflag_ich8lan(hw);
1368
1369 /* verify the register updates */
1370 if ((er32(SHRAL(index - 1)) == rar_low) &&
1371 (er32(SHRAH(index - 1)) == rar_high))
1372 return;
1373
1374 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1375 (index - 1), er32(FWSM));
1376 }
1377
1378out:
1379 e_dbg("Failed to write receive address at index %d\n", index);
1380}
1381
1382/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001383 * e1000_rar_set_pch_lpt - Set receive address registers
1384 * @hw: pointer to the HW structure
1385 * @addr: pointer to the receive address
1386 * @index: receive address array register
1387 *
1388 * Sets the receive address register array at index to the address passed
1389 * in by addr. For LPT, RAR[0] is the base address register that is to
1390 * contain the MAC address. SHRA[0-10] are the shared receive address
1391 * registers that are shared between the Host and manageability engine (ME).
1392 **/
1393static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1394{
1395 u32 rar_low, rar_high;
1396 u32 wlock_mac;
1397
Bruce Allane921eb12012-11-28 09:28:37 +00001398 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001399 * from network order (big endian) to little endian
1400 */
1401 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1402 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1403
1404 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1405
1406 /* If MAC address zero, no need to set the AV bit */
1407 if (rar_low || rar_high)
1408 rar_high |= E1000_RAH_AV;
1409
1410 if (index == 0) {
1411 ew32(RAL(index), rar_low);
1412 e1e_flush();
1413 ew32(RAH(index), rar_high);
1414 e1e_flush();
1415 return;
1416 }
1417
Bruce Allane921eb12012-11-28 09:28:37 +00001418 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001419 * it is using - those registers are unavailable for use.
1420 */
1421 if (index < hw->mac.rar_entry_count) {
1422 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1423 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1424
1425 /* Check if all SHRAR registers are locked */
1426 if (wlock_mac == 1)
1427 goto out;
1428
1429 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1430 s32 ret_val;
1431
1432 ret_val = e1000_acquire_swflag_ich8lan(hw);
1433
1434 if (ret_val)
1435 goto out;
1436
1437 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1438 e1e_flush();
1439 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1440 e1e_flush();
1441
1442 e1000_release_swflag_ich8lan(hw);
1443
1444 /* verify the register updates */
1445 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1446 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1447 return;
1448 }
1449 }
1450
1451out:
1452 e_dbg("Failed to write receive address at index %d\n", index);
1453}
1454
1455/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001456 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1457 * @hw: pointer to the HW structure
1458 *
1459 * Checks if firmware is blocking the reset of the PHY.
1460 * This is a function pointer entry point only called by
1461 * reset routines.
1462 **/
1463static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1464{
1465 u32 fwsm;
1466
1467 fwsm = er32(FWSM);
1468
1469 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
1470}
1471
1472/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001473 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1474 * @hw: pointer to the HW structure
1475 *
1476 * Assumes semaphore already acquired.
1477 *
1478 **/
1479static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1480{
1481 u16 phy_data;
1482 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001483 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1484 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan70806a72013-01-05 05:08:37 +00001485 s32 ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001486
1487 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1488
1489 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1490 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001491 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001492
1493 phy_data &= ~HV_SMB_ADDR_MASK;
1494 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1495 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001496
Bruce Allan2fbe4522012-04-19 03:21:47 +00001497 if (hw->phy.type == e1000_phy_i217) {
1498 /* Restore SMBus frequency */
1499 if (freq--) {
1500 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1501 phy_data |= (freq & (1 << 0)) <<
1502 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1503 phy_data |= (freq & (1 << 1)) <<
1504 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1505 } else {
1506 e_dbg("Unsupported SMB frequency in PHY\n");
1507 }
1508 }
1509
Bruce Allan5015e532012-02-08 02:55:56 +00001510 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001511}
1512
1513/**
Bruce Allanf523d212009-10-29 13:45:45 +00001514 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1515 * @hw: pointer to the HW structure
1516 *
1517 * SW should configure the LCD from the NVM extended configuration region
1518 * as a workaround for certain parts.
1519 **/
1520static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1521{
1522 struct e1000_phy_info *phy = &hw->phy;
1523 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001524 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001525 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1526
Bruce Allane921eb12012-11-28 09:28:37 +00001527 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001528 * is needed due to an issue where the NVM configuration is
1529 * not properly autoloaded after power transitions.
1530 * Therefore, after each PHY reset, we will load the
1531 * configuration data out of the NVM manually.
1532 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001533 switch (hw->mac.type) {
1534 case e1000_ich8lan:
1535 if (phy->type != e1000_phy_igp_3)
1536 return ret_val;
1537
Bruce Allan5f3eed62010-09-22 17:15:54 +00001538 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1539 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001540 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1541 break;
1542 }
1543 /* Fall-thru */
1544 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001545 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001546 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001547 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001548 break;
1549 default:
1550 return ret_val;
1551 }
1552
1553 ret_val = hw->phy.ops.acquire(hw);
1554 if (ret_val)
1555 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001556
Bruce Allan8b802a72010-05-10 15:01:10 +00001557 data = er32(FEXTNVM);
1558 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001559 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001560
Bruce Allane921eb12012-11-28 09:28:37 +00001561 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001562 * extended configuration before SW configuration
1563 */
1564 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001565 if ((hw->mac.type < e1000_pch2lan) &&
1566 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1567 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001568
Bruce Allan8b802a72010-05-10 15:01:10 +00001569 cnf_size = er32(EXTCNF_SIZE);
1570 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1571 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1572 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001573 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001574
1575 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1576 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1577
Bruce Allan2fbe4522012-04-19 03:21:47 +00001578 if (((hw->mac.type == e1000_pchlan) &&
1579 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1580 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001581 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001582 * OEM and LCD Write Enable bits are set in the NVM.
1583 * When both NVM bits are cleared, SW will configure
1584 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001585 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001586 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001587 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001588 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001589
Bruce Allan8b802a72010-05-10 15:01:10 +00001590 data = er32(LEDCTL);
1591 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1592 (u16)data);
1593 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001594 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001595 }
1596
1597 /* Configure LCD from extended configuration region. */
1598
1599 /* cnf_base_addr is in DWORD */
1600 word_addr = (u16)(cnf_base_addr << 1);
1601
1602 for (i = 0; i < cnf_size; i++) {
Bruce Allane5fe2542013-02-20 04:06:27 +00001603 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001604 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001605 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001606
Bruce Allan8b802a72010-05-10 15:01:10 +00001607 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1608 1, &reg_addr);
1609 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001610 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001611
Bruce Allan8b802a72010-05-10 15:01:10 +00001612 /* Save off the PHY page for future writes. */
1613 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1614 phy_page = reg_data;
1615 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001616 }
Bruce Allanf523d212009-10-29 13:45:45 +00001617
Bruce Allan8b802a72010-05-10 15:01:10 +00001618 reg_addr &= PHY_REG_MASK;
1619 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001620
Bruce Allanf1430d62012-04-14 04:21:52 +00001621 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001622 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001623 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001624 }
1625
Bruce Allan75ce1532012-02-08 02:54:48 +00001626release:
Bruce Allan94d81862009-11-20 23:25:26 +00001627 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001628 return ret_val;
1629}
1630
1631/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001632 * e1000_k1_gig_workaround_hv - K1 Si workaround
1633 * @hw: pointer to the HW structure
1634 * @link: link up bool flag
1635 *
1636 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1637 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1638 * If link is down, the function will restore the default K1 setting located
1639 * in the NVM.
1640 **/
1641static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1642{
1643 s32 ret_val = 0;
1644 u16 status_reg = 0;
1645 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1646
1647 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001648 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001649
1650 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001651 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001652 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001653 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001654
1655 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1656 if (link) {
1657 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001658 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1659 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001660 if (ret_val)
1661 goto release;
1662
Bruce Allanf0ff4392013-02-20 04:05:39 +00001663 status_reg &= (BM_CS_STATUS_LINK_UP |
1664 BM_CS_STATUS_RESOLVED |
1665 BM_CS_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001666
1667 if (status_reg == (BM_CS_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001668 BM_CS_STATUS_RESOLVED |
1669 BM_CS_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001670 k1_enable = false;
1671 }
1672
1673 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001674 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001675 if (ret_val)
1676 goto release;
1677
Bruce Allanf0ff4392013-02-20 04:05:39 +00001678 status_reg &= (HV_M_STATUS_LINK_UP |
1679 HV_M_STATUS_AUTONEG_COMPLETE |
1680 HV_M_STATUS_SPEED_MASK);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001681
1682 if (status_reg == (HV_M_STATUS_LINK_UP |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001683 HV_M_STATUS_AUTONEG_COMPLETE |
1684 HV_M_STATUS_SPEED_1000))
Bruce Allan1d5846b2009-10-29 13:46:05 +00001685 k1_enable = false;
1686 }
1687
1688 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001689 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001690 if (ret_val)
1691 goto release;
1692
1693 } else {
1694 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001695 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001696 if (ret_val)
1697 goto release;
1698 }
1699
1700 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1701
1702release:
Bruce Allan94d81862009-11-20 23:25:26 +00001703 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001704
Bruce Allan1d5846b2009-10-29 13:46:05 +00001705 return ret_val;
1706}
1707
1708/**
1709 * e1000_configure_k1_ich8lan - Configure K1 power state
1710 * @hw: pointer to the HW structure
1711 * @enable: K1 state to configure
1712 *
1713 * Configure the K1 power state based on the provided parameter.
1714 * Assumes semaphore already acquired.
1715 *
1716 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1717 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001718s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001719{
Bruce Allan70806a72013-01-05 05:08:37 +00001720 s32 ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001721 u32 ctrl_reg = 0;
1722 u32 ctrl_ext = 0;
1723 u32 reg = 0;
1724 u16 kmrn_reg = 0;
1725
Bruce Allan3d3a1672012-02-23 03:13:18 +00001726 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1727 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001728 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001729 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001730
1731 if (k1_enable)
1732 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1733 else
1734 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1735
Bruce Allan3d3a1672012-02-23 03:13:18 +00001736 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1737 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001738 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001739 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001740
Bruce Allance43a212013-02-20 04:06:32 +00001741 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001742 ctrl_ext = er32(CTRL_EXT);
1743 ctrl_reg = er32(CTRL);
1744
1745 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1746 reg |= E1000_CTRL_FRCSPD;
1747 ew32(CTRL, reg);
1748
1749 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001750 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001751 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001752 ew32(CTRL, ctrl_reg);
1753 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001754 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001755 usleep_range(20, 40);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001756
Bruce Allan5015e532012-02-08 02:55:56 +00001757 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001758}
1759
1760/**
Bruce Allanf523d212009-10-29 13:45:45 +00001761 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1762 * @hw: pointer to the HW structure
1763 * @d0_state: boolean if entering d0 or d3 device state
1764 *
1765 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1766 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1767 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1768 **/
1769static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1770{
1771 s32 ret_val = 0;
1772 u32 mac_reg;
1773 u16 oem_reg;
1774
Bruce Allan2fbe4522012-04-19 03:21:47 +00001775 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001776 return ret_val;
1777
Bruce Allan94d81862009-11-20 23:25:26 +00001778 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001779 if (ret_val)
1780 return ret_val;
1781
Bruce Allan2fbe4522012-04-19 03:21:47 +00001782 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001783 mac_reg = er32(EXTCNF_CTRL);
1784 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001785 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001786 }
Bruce Allanf523d212009-10-29 13:45:45 +00001787
1788 mac_reg = er32(FEXTNVM);
1789 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001790 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001791
1792 mac_reg = er32(PHY_CTRL);
1793
Bruce Allanf1430d62012-04-14 04:21:52 +00001794 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001795 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001796 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001797
1798 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1799
1800 if (d0_state) {
1801 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1802 oem_reg |= HV_OEM_BITS_GBE_DIS;
1803
1804 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1805 oem_reg |= HV_OEM_BITS_LPLU;
1806 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001807 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1808 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001809 oem_reg |= HV_OEM_BITS_GBE_DIS;
1810
Bruce Allan03299e42011-09-30 08:07:05 +00001811 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1812 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001813 oem_reg |= HV_OEM_BITS_LPLU;
1814 }
Bruce Allan03299e42011-09-30 08:07:05 +00001815
Bruce Allan92fe1732012-04-12 06:27:03 +00001816 /* Set Restart auto-neg to activate the bits */
1817 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1818 !hw->phy.ops.check_reset_block(hw))
1819 oem_reg |= HV_OEM_BITS_RESTART_AN;
1820
Bruce Allanf1430d62012-04-14 04:21:52 +00001821 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001822
Bruce Allan75ce1532012-02-08 02:54:48 +00001823release:
Bruce Allan94d81862009-11-20 23:25:26 +00001824 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001825
1826 return ret_val;
1827}
1828
Bruce Allanf523d212009-10-29 13:45:45 +00001829/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001830 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1831 * @hw: pointer to the HW structure
1832 **/
1833static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1834{
1835 s32 ret_val;
1836 u16 data;
1837
1838 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1839 if (ret_val)
1840 return ret_val;
1841
1842 data |= HV_KMRN_MDIO_SLOW;
1843
1844 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1845
1846 return ret_val;
1847}
1848
1849/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001850 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1851 * done after every PHY reset.
1852 **/
1853static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1854{
1855 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001856 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001857
1858 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001859 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001860
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001861 /* Set MDIO slow mode before any other MDIO access */
1862 if (hw->phy.type == e1000_phy_82577) {
1863 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1864 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001865 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001866 }
1867
Bruce Allana4f58f52009-06-02 11:29:18 +00001868 if (((hw->phy.type == e1000_phy_82577) &&
1869 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1870 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1871 /* Disable generation of early preamble */
1872 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1873 if (ret_val)
1874 return ret_val;
1875
1876 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001877 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001878 if (ret_val)
1879 return ret_val;
1880 }
1881
1882 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001883 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001884 * writing 0x3140 to the control register.
1885 */
1886 if (hw->phy.revision < 2) {
1887 e1000e_phy_sw_reset(hw);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001888 ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
Bruce Allana4f58f52009-06-02 11:29:18 +00001889 }
1890 }
1891
1892 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001893 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001894 if (ret_val)
1895 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001896
Bruce Allana4f58f52009-06-02 11:29:18 +00001897 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001898 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001899 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001900 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001901 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001902
Bruce Allane921eb12012-11-28 09:28:37 +00001903 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001904 * link so that it disables K1 if link is in 1Gbps.
1905 */
1906 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001907 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001908 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001909
Bruce Allanbaf86c92010-01-13 01:53:08 +00001910 /* Workaround for link disconnects on a busy hub in half duplex */
1911 ret_val = hw->phy.ops.acquire(hw);
1912 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001913 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001914 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001915 if (ret_val)
1916 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001917 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001918 if (ret_val)
1919 goto release;
1920
1921 /* set MSE higher to enable link to stay up when noise is high */
1922 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001923release:
1924 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001925
Bruce Allana4f58f52009-06-02 11:29:18 +00001926 return ret_val;
1927}
1928
1929/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001930 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1931 * @hw: pointer to the HW structure
1932 **/
1933void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1934{
1935 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001936 u16 i, phy_reg = 0;
1937 s32 ret_val;
1938
1939 ret_val = hw->phy.ops.acquire(hw);
1940 if (ret_val)
1941 return;
1942 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1943 if (ret_val)
1944 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001945
1946 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1947 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1948 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001949 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1950 (u16)(mac_reg & 0xFFFF));
1951 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1952 (u16)((mac_reg >> 16) & 0xFFFF));
1953
Bruce Alland3738bb2010-06-16 13:27:28 +00001954 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001955 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1956 (u16)(mac_reg & 0xFFFF));
1957 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1958 (u16)((mac_reg & E1000_RAH_AV)
1959 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00001960 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00001961
1962 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1963
1964release:
1965 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001966}
1967
Bruce Alland3738bb2010-06-16 13:27:28 +00001968/**
1969 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1970 * with 82579 PHY
1971 * @hw: pointer to the HW structure
1972 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1973 **/
1974s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1975{
1976 s32 ret_val = 0;
1977 u16 phy_reg, data;
1978 u32 mac_reg;
1979 u16 i;
1980
Bruce Allan2fbe4522012-04-19 03:21:47 +00001981 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001982 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001983
1984 /* disable Rx path while enabling/disabling workaround */
1985 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1986 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1987 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001988 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001989
1990 if (enable) {
Bruce Allane921eb12012-11-28 09:28:37 +00001991 /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
Bruce Alland3738bb2010-06-16 13:27:28 +00001992 * SHRAL/H) and initial CRC values to the MAC
1993 */
1994 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00001995 u8 mac_addr[ETH_ALEN] = { 0 };
Bruce Alland3738bb2010-06-16 13:27:28 +00001996 u32 addr_high, addr_low;
1997
1998 addr_high = er32(RAH(i));
1999 if (!(addr_high & E1000_RAH_AV))
2000 continue;
2001 addr_low = er32(RAL(i));
2002 mac_addr[0] = (addr_low & 0xFF);
2003 mac_addr[1] = ((addr_low >> 8) & 0xFF);
2004 mac_addr[2] = ((addr_low >> 16) & 0xFF);
2005 mac_addr[3] = ((addr_low >> 24) & 0xFF);
2006 mac_addr[4] = (addr_high & 0xFF);
2007 mac_addr[5] = ((addr_high >> 8) & 0xFF);
2008
Bruce Allanfe46f582011-01-06 14:29:51 +00002009 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00002010 }
2011
2012 /* Write Rx addresses to the PHY */
2013 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
2014
2015 /* Enable jumbo frame workaround in the MAC */
2016 mac_reg = er32(FFLT_DBG);
2017 mac_reg &= ~(1 << 14);
2018 mac_reg |= (7 << 15);
2019 ew32(FFLT_DBG, mac_reg);
2020
2021 mac_reg = er32(RCTL);
2022 mac_reg |= E1000_RCTL_SECRC;
2023 ew32(RCTL, mac_reg);
2024
2025 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002026 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2027 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002028 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002029 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002030 ret_val = e1000e_write_kmrn_reg(hw,
2031 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2032 data | (1 << 0));
2033 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002034 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002035 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002036 E1000_KMRNCTRLSTA_HD_CTRL,
2037 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002038 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002039 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002040 data &= ~(0xF << 8);
2041 data |= (0xB << 8);
2042 ret_val = e1000e_write_kmrn_reg(hw,
2043 E1000_KMRNCTRLSTA_HD_CTRL,
2044 data);
2045 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002046 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002047
2048 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00002049 e1e_rphy(hw, PHY_REG(769, 23), &data);
2050 data &= ~(0x7F << 5);
2051 data |= (0x37 << 5);
2052 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2053 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002054 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002055 e1e_rphy(hw, PHY_REG(769, 16), &data);
2056 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00002057 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2058 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002059 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002060 e1e_rphy(hw, PHY_REG(776, 20), &data);
2061 data &= ~(0x3FF << 2);
2062 data |= (0x1A << 2);
2063 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2064 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002065 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00002066 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00002067 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002068 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002069 e1e_rphy(hw, HV_PM_CTRL, &data);
2070 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
2071 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002072 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002073 } else {
2074 /* Write MAC register values back to h/w defaults */
2075 mac_reg = er32(FFLT_DBG);
2076 mac_reg &= ~(0xF << 14);
2077 ew32(FFLT_DBG, mac_reg);
2078
2079 mac_reg = er32(RCTL);
2080 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00002081 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00002082
2083 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002084 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2085 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002086 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002087 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002088 ret_val = e1000e_write_kmrn_reg(hw,
2089 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2090 data & ~(1 << 0));
2091 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002092 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002093 ret_val = e1000e_read_kmrn_reg(hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00002094 E1000_KMRNCTRLSTA_HD_CTRL,
2095 &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002096 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002097 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002098 data &= ~(0xF << 8);
2099 data |= (0xB << 8);
2100 ret_val = e1000e_write_kmrn_reg(hw,
2101 E1000_KMRNCTRLSTA_HD_CTRL,
2102 data);
2103 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002104 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002105
2106 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002107 e1e_rphy(hw, PHY_REG(769, 23), &data);
2108 data &= ~(0x7F << 5);
2109 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2110 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002111 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002112 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002113 data |= (1 << 13);
2114 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2115 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002116 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002117 e1e_rphy(hw, PHY_REG(776, 20), &data);
2118 data &= ~(0x3FF << 2);
2119 data |= (0x8 << 2);
2120 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2121 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002122 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002123 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2124 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002125 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002126 e1e_rphy(hw, HV_PM_CTRL, &data);
2127 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2128 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002129 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002130 }
2131
2132 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002133 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002134}
2135
2136/**
2137 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2138 * done after every PHY reset.
2139 **/
2140static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2141{
2142 s32 ret_val = 0;
2143
2144 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002145 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002146
2147 /* Set MDIO slow mode before any other MDIO access */
2148 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002149 if (ret_val)
2150 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002151
Bruce Allan4d241362011-12-16 00:46:06 +00002152 ret_val = hw->phy.ops.acquire(hw);
2153 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002154 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002155 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002156 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002157 if (ret_val)
2158 goto release;
2159 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002160 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002161release:
2162 hw->phy.ops.release(hw);
2163
Bruce Alland3738bb2010-06-16 13:27:28 +00002164 return ret_val;
2165}
2166
2167/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002168 * e1000_k1_gig_workaround_lv - K1 Si workaround
2169 * @hw: pointer to the HW structure
2170 *
2171 * Workaround to set the K1 beacon duration for 82579 parts
2172 **/
2173static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2174{
2175 s32 ret_val = 0;
2176 u16 status_reg = 0;
2177 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002178 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002179
2180 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002181 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002182
2183 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2184 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2185 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002186 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002187
2188 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2189 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2190 mac_reg = er32(FEXTNVM4);
2191 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2192
Bruce Allan0ed013e2011-07-29 05:52:56 +00002193 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2194 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002195 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002196
Bruce Allan0ed013e2011-07-29 05:52:56 +00002197 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002198 u16 pm_phy_reg;
2199
Bruce Allan0ed013e2011-07-29 05:52:56 +00002200 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2201 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002202 /* LV 1G Packet drop issue wa */
2203 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2204 if (ret_val)
2205 return ret_val;
2206 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2207 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2208 if (ret_val)
2209 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002210 } else {
2211 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2212 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2213 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002214 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002215 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002216 }
2217
Bruce Allan831bd2e2010-09-22 17:16:18 +00002218 return ret_val;
2219}
2220
2221/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002222 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2223 * @hw: pointer to the HW structure
2224 * @gate: boolean set to true to gate, false to ungate
2225 *
2226 * Gate/ungate the automatic PHY configuration via hardware; perform
2227 * the configuration via software instead.
2228 **/
2229static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2230{
2231 u32 extcnf_ctrl;
2232
Bruce Allan2fbe4522012-04-19 03:21:47 +00002233 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002234 return;
2235
2236 extcnf_ctrl = er32(EXTCNF_CTRL);
2237
2238 if (gate)
2239 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2240 else
2241 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2242
2243 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002244}
2245
2246/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002247 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2248 * @hw: pointer to the HW structure
2249 *
2250 * Check the appropriate indication the MAC has finished configuring the
2251 * PHY after a software reset.
2252 **/
2253static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2254{
2255 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2256
2257 /* Wait for basic configuration completes before proceeding */
2258 do {
2259 data = er32(STATUS);
2260 data &= E1000_STATUS_LAN_INIT_DONE;
Bruce Allance43a212013-02-20 04:06:32 +00002261 usleep_range(100, 200);
Bruce Allanfc0c7762009-07-01 13:27:55 +00002262 } while ((!data) && --loop);
2263
Bruce Allane921eb12012-11-28 09:28:37 +00002264 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002265 * count reaches 0, loading the configuration from NVM will
2266 * leave the PHY in a bad state possibly resulting in no link.
2267 */
2268 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002269 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002270
2271 /* Clear the Init Done bit for the next init event */
2272 data = er32(STATUS);
2273 data &= ~E1000_STATUS_LAN_INIT_DONE;
2274 ew32(STATUS, data);
2275}
2276
2277/**
Bruce Allane98cac42010-05-10 15:02:32 +00002278 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002279 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002280 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002281static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002282{
Bruce Allanf523d212009-10-29 13:45:45 +00002283 s32 ret_val = 0;
2284 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002285
Bruce Allan44abd5c2012-02-22 09:02:37 +00002286 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002287 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002288
Bruce Allan5f3eed62010-09-22 17:15:54 +00002289 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002290 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002291
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002292 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002293 switch (hw->mac.type) {
2294 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002295 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2296 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002297 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002298 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002299 case e1000_pch2lan:
2300 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2301 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002302 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002303 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002304 default:
2305 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002306 }
2307
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002308 /* Clear the host wakeup bit after lcd reset */
2309 if (hw->mac.type >= e1000_pchlan) {
2310 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2311 reg &= ~BM_WUC_HOST_WU_BIT;
2312 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2313 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002314
Bruce Allanf523d212009-10-29 13:45:45 +00002315 /* Configure the LCD with the extended configuration region in NVM */
2316 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2317 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002318 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002319
Bruce Allanf523d212009-10-29 13:45:45 +00002320 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002321 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322
Bruce Allan1effb452011-02-25 06:58:03 +00002323 if (hw->mac.type == e1000_pch2lan) {
2324 /* Ungate automatic PHY configuration on non-managed 82579 */
2325 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002326 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002327 e1000_gate_hw_phy_config_ich8lan(hw, false);
2328 }
2329
2330 /* Set EEE LPI Update Timer to 200usec */
2331 ret_val = hw->phy.ops.acquire(hw);
2332 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002333 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002334 ret_val = e1000_write_emi_reg_locked(hw,
2335 I82579_LPI_UPDATE_TIMER,
2336 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002337 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002338 }
2339
Bruce Allane98cac42010-05-10 15:02:32 +00002340 return ret_val;
2341}
2342
2343/**
2344 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2345 * @hw: pointer to the HW structure
2346 *
2347 * Resets the PHY
2348 * This is a function pointer entry point called by drivers
2349 * or other shared routines.
2350 **/
2351static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2352{
2353 s32 ret_val = 0;
2354
Bruce Allan605c82b2010-09-22 17:17:01 +00002355 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2356 if ((hw->mac.type == e1000_pch2lan) &&
2357 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2358 e1000_gate_hw_phy_config_ich8lan(hw, true);
2359
Bruce Allane98cac42010-05-10 15:02:32 +00002360 ret_val = e1000e_phy_hw_reset_generic(hw);
2361 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002362 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002363
Bruce Allan5015e532012-02-08 02:55:56 +00002364 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365}
2366
2367/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002368 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2369 * @hw: pointer to the HW structure
2370 * @active: true to enable LPLU, false to disable
2371 *
2372 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2373 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2374 * the phy speed. This function will manually set the LPLU bit and restart
2375 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2376 * since it configures the same bit.
2377 **/
2378static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2379{
Bruce Allan70806a72013-01-05 05:08:37 +00002380 s32 ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002381 u16 oem_reg;
2382
2383 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2384 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002385 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002386
2387 if (active)
2388 oem_reg |= HV_OEM_BITS_LPLU;
2389 else
2390 oem_reg &= ~HV_OEM_BITS_LPLU;
2391
Bruce Allan44abd5c2012-02-22 09:02:37 +00002392 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002393 oem_reg |= HV_OEM_BITS_RESTART_AN;
2394
Bruce Allan5015e532012-02-08 02:55:56 +00002395 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002396}
2397
2398/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002399 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2400 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002401 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002402 *
2403 * Sets the LPLU D0 state according to the active flag. When
2404 * activating LPLU this function also disables smart speed
2405 * and vice versa. LPLU will not be activated unless the
2406 * device autonegotiation advertisement meets standards of
2407 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2408 * This is a function pointer entry point only called by
2409 * PHY setup routines.
2410 **/
2411static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2412{
2413 struct e1000_phy_info *phy = &hw->phy;
2414 u32 phy_ctrl;
2415 s32 ret_val = 0;
2416 u16 data;
2417
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002418 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002419 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002420
2421 phy_ctrl = er32(PHY_CTRL);
2422
2423 if (active) {
2424 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2425 ew32(PHY_CTRL, phy_ctrl);
2426
Bruce Allan60f12922009-07-01 13:28:14 +00002427 if (phy->type != e1000_phy_igp_3)
2428 return 0;
2429
Bruce Allane921eb12012-11-28 09:28:37 +00002430 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002431 * any PHY registers
2432 */
Bruce Allan60f12922009-07-01 13:28:14 +00002433 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002434 e1000e_gig_downshift_workaround_ich8lan(hw);
2435
2436 /* When LPLU is enabled, we should disable SmartSpeed */
2437 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00002438 if (ret_val)
2439 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002440 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2441 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2442 if (ret_val)
2443 return ret_val;
2444 } else {
2445 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2446 ew32(PHY_CTRL, phy_ctrl);
2447
Bruce Allan60f12922009-07-01 13:28:14 +00002448 if (phy->type != e1000_phy_igp_3)
2449 return 0;
2450
Bruce Allane921eb12012-11-28 09:28:37 +00002451 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002452 * during Dx states where the power conservation is most
2453 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002454 * SmartSpeed, so performance is maintained.
2455 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002456 if (phy->smart_speed == e1000_smart_speed_on) {
2457 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002458 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002459 if (ret_val)
2460 return ret_val;
2461
2462 data |= IGP01E1000_PSCFR_SMART_SPEED;
2463 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002464 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002465 if (ret_val)
2466 return ret_val;
2467 } else if (phy->smart_speed == e1000_smart_speed_off) {
2468 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002469 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470 if (ret_val)
2471 return ret_val;
2472
2473 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2474 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002475 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002476 if (ret_val)
2477 return ret_val;
2478 }
2479 }
2480
2481 return 0;
2482}
2483
2484/**
2485 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2486 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002487 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002488 *
2489 * Sets the LPLU D3 state according to the active flag. When
2490 * activating LPLU this function also disables smart speed
2491 * and vice versa. LPLU will not be activated unless the
2492 * device autonegotiation advertisement meets standards of
2493 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2494 * This is a function pointer entry point only called by
2495 * PHY setup routines.
2496 **/
2497static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2498{
2499 struct e1000_phy_info *phy = &hw->phy;
2500 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002501 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002502 u16 data;
2503
2504 phy_ctrl = er32(PHY_CTRL);
2505
2506 if (!active) {
2507 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2508 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002509
2510 if (phy->type != e1000_phy_igp_3)
2511 return 0;
2512
Bruce Allane921eb12012-11-28 09:28:37 +00002513 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002514 * during Dx states where the power conservation is most
2515 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002516 * SmartSpeed, so performance is maintained.
2517 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002518 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002519 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2520 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002521 if (ret_val)
2522 return ret_val;
2523
2524 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002525 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2526 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002527 if (ret_val)
2528 return ret_val;
2529 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002530 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2531 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002532 if (ret_val)
2533 return ret_val;
2534
2535 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002536 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2537 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002538 if (ret_val)
2539 return ret_val;
2540 }
2541 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2542 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2543 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2544 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2545 ew32(PHY_CTRL, phy_ctrl);
2546
Bruce Allan60f12922009-07-01 13:28:14 +00002547 if (phy->type != e1000_phy_igp_3)
2548 return 0;
2549
Bruce Allane921eb12012-11-28 09:28:37 +00002550 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002551 * any PHY registers
2552 */
Bruce Allan60f12922009-07-01 13:28:14 +00002553 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002554 e1000e_gig_downshift_workaround_ich8lan(hw);
2555
2556 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002557 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002558 if (ret_val)
2559 return ret_val;
2560
2561 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002562 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002563 }
2564
Bruce Alland7eb3382012-02-08 02:55:14 +00002565 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002566}
2567
2568/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002569 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2570 * @hw: pointer to the HW structure
2571 * @bank: pointer to the variable that returns the active bank
2572 *
2573 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002574 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002575 **/
2576static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2577{
Bruce Allane2434552008-11-21 17:02:41 -08002578 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002579 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002580 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2581 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002582 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002583 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002584
Bruce Allane2434552008-11-21 17:02:41 -08002585 switch (hw->mac.type) {
2586 case e1000_ich8lan:
2587 case e1000_ich9lan:
2588 eecd = er32(EECD);
2589 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2590 E1000_EECD_SEC1VAL_VALID_MASK) {
2591 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002592 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002593 else
2594 *bank = 0;
2595
2596 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002597 }
Bruce Allan434f1392011-12-16 00:46:54 +00002598 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002599 /* fall-thru */
2600 default:
2601 /* set bank to 0 in case flash read fails */
2602 *bank = 0;
2603
2604 /* Check bank 0 */
2605 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
Bruce Allanf0ff4392013-02-20 04:05:39 +00002606 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002607 if (ret_val)
2608 return ret_val;
2609 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2610 E1000_ICH_NVM_SIG_VALUE) {
2611 *bank = 0;
2612 return 0;
2613 }
2614
2615 /* Check bank 1 */
2616 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002617 bank1_offset,
2618 &sig_byte);
Bruce Allane2434552008-11-21 17:02:41 -08002619 if (ret_val)
2620 return ret_val;
2621 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2622 E1000_ICH_NVM_SIG_VALUE) {
2623 *bank = 1;
2624 return 0;
2625 }
2626
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002627 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002628 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002629 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002630}
2631
2632/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002633 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2634 * @hw: pointer to the HW structure
2635 * @offset: The offset (in bytes) of the word(s) to read.
2636 * @words: Size of data to read in words
2637 * @data: Pointer to the word(s) to read at offset.
2638 *
2639 * Reads a word(s) from the NVM using the flash access registers.
2640 **/
2641static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2642 u16 *data)
2643{
2644 struct e1000_nvm_info *nvm = &hw->nvm;
2645 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2646 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002647 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002648 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002649 u16 i, word;
2650
2651 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2652 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002653 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002654 ret_val = -E1000_ERR_NVM;
2655 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002656 }
2657
Bruce Allan94d81862009-11-20 23:25:26 +00002658 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002659
Bruce Allanf4187b52008-08-26 18:36:50 -07002660 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002661 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002662 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002663 bank = 0;
2664 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002665
2666 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002667 act_offset += offset;
2668
Bruce Allan148675a2009-08-07 07:41:56 +00002669 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002670 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002671 if (dev_spec->shadow_ram[offset + i].modified) {
2672 data[i] = dev_spec->shadow_ram[offset + i].value;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002673 } else {
2674 ret_val = e1000_read_flash_word_ich8lan(hw,
2675 act_offset + i,
2676 &word);
2677 if (ret_val)
2678 break;
2679 data[i] = word;
2680 }
2681 }
2682
Bruce Allan94d81862009-11-20 23:25:26 +00002683 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002684
Bruce Allane2434552008-11-21 17:02:41 -08002685out:
2686 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002687 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002688
Auke Kokbc7f75f2007-09-17 12:30:59 -07002689 return ret_val;
2690}
2691
2692/**
2693 * e1000_flash_cycle_init_ich8lan - Initialize flash
2694 * @hw: pointer to the HW structure
2695 *
2696 * This function does initial flash setup so that a new read/write/erase cycle
2697 * can be started.
2698 **/
2699static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2700{
2701 union ich8_hws_flash_status hsfsts;
2702 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002703
2704 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2705
2706 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002707 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002708 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002709 return -E1000_ERR_NVM;
2710 }
2711
2712 /* Clear FCERR and DAEL in hw status by writing 1 */
2713 hsfsts.hsf_status.flcerr = 1;
2714 hsfsts.hsf_status.dael = 1;
2715
2716 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2717
Bruce Allane921eb12012-11-28 09:28:37 +00002718 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002719 * bit to check against, in order to start a new cycle or
2720 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002721 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002722 * indication whether a cycle is in progress or has been
2723 * completed.
2724 */
2725
Bruce Allan04499ec2012-04-13 00:08:31 +00002726 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002727 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002728 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002729 * Begin by setting Flash Cycle Done.
2730 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002731 hsfsts.hsf_status.flcdone = 1;
2732 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2733 ret_val = 0;
2734 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002735 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002736
Bruce Allane921eb12012-11-28 09:28:37 +00002737 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002738 * cycle has a chance to end before giving up.
2739 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002740 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002741 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002742 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002743 ret_val = 0;
2744 break;
2745 }
2746 udelay(1);
2747 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002748 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002749 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002750 * now set the Flash Cycle Done.
2751 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002752 hsfsts.hsf_status.flcdone = 1;
2753 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2754 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002755 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002756 }
2757 }
2758
2759 return ret_val;
2760}
2761
2762/**
2763 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2764 * @hw: pointer to the HW structure
2765 * @timeout: maximum time to wait for completion
2766 *
2767 * This function starts a flash cycle and waits for its completion.
2768 **/
2769static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2770{
2771 union ich8_hws_flash_ctrl hsflctl;
2772 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002773 u32 i = 0;
2774
2775 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2776 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2777 hsflctl.hsf_ctrl.flcgo = 1;
2778 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2779
2780 /* wait till FDONE bit is set to 1 */
2781 do {
2782 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002783 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002784 break;
2785 udelay(1);
2786 } while (i++ < timeout);
2787
Bruce Allan04499ec2012-04-13 00:08:31 +00002788 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002789 return 0;
2790
Bruce Allan55920b52012-02-08 02:55:25 +00002791 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002792}
2793
2794/**
2795 * e1000_read_flash_word_ich8lan - Read word from flash
2796 * @hw: pointer to the HW structure
2797 * @offset: offset to data location
2798 * @data: pointer to the location for storing the data
2799 *
2800 * Reads the flash word at offset into data. Offset is converted
2801 * to bytes before read.
2802 **/
2803static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2804 u16 *data)
2805{
2806 /* Must convert offset into bytes. */
2807 offset <<= 1;
2808
2809 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2810}
2811
2812/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002813 * e1000_read_flash_byte_ich8lan - Read byte from flash
2814 * @hw: pointer to the HW structure
2815 * @offset: The offset of the byte to read.
2816 * @data: Pointer to a byte to store the value read.
2817 *
2818 * Reads a single byte from the NVM using the flash access registers.
2819 **/
2820static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2821 u8 *data)
2822{
2823 s32 ret_val;
2824 u16 word = 0;
2825
2826 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2827 if (ret_val)
2828 return ret_val;
2829
2830 *data = (u8)word;
2831
2832 return 0;
2833}
2834
2835/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002836 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2837 * @hw: pointer to the HW structure
2838 * @offset: The offset (in bytes) of the byte or word to read.
2839 * @size: Size of data to read, 1=byte 2=word
2840 * @data: Pointer to the word to store the value read.
2841 *
2842 * Reads a byte or word from the NVM using the flash access registers.
2843 **/
2844static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2845 u8 size, u16 *data)
2846{
2847 union ich8_hws_flash_status hsfsts;
2848 union ich8_hws_flash_ctrl hsflctl;
2849 u32 flash_linear_addr;
2850 u32 flash_data = 0;
2851 s32 ret_val = -E1000_ERR_NVM;
2852 u8 count = 0;
2853
Bruce Allane80bd1d2013-05-01 01:19:46 +00002854 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002855 return -E1000_ERR_NVM;
2856
Bruce Allanf0ff4392013-02-20 04:05:39 +00002857 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2858 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002859
2860 do {
2861 udelay(1);
2862 /* Steps */
2863 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002864 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002865 break;
2866
2867 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2868 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2869 hsflctl.hsf_ctrl.fldbcount = size - 1;
2870 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2871 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2872
2873 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2874
Bruce Allan17e813e2013-02-20 04:06:01 +00002875 ret_val =
2876 e1000_flash_cycle_ich8lan(hw,
2877 ICH_FLASH_READ_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002878
Bruce Allane921eb12012-11-28 09:28:37 +00002879 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002880 * and try the whole sequence a few more times, else
2881 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002882 * least significant byte first msb to lsb
2883 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002884 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002885 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002886 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002887 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002888 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002889 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002890 break;
2891 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002892 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002893 * completely hosed, but if the error condition is
2894 * detected, it won't hurt to give it another try...
2895 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2896 */
2897 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002898 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002899 /* Repeat for some time before giving up. */
2900 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002901 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002902 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002903 break;
2904 }
2905 }
2906 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2907
2908 return ret_val;
2909}
2910
2911/**
2912 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2913 * @hw: pointer to the HW structure
2914 * @offset: The offset (in bytes) of the word(s) to write.
2915 * @words: Size of data to write in words
2916 * @data: Pointer to the word(s) to write at offset.
2917 *
2918 * Writes a byte or word to the NVM using the flash access registers.
2919 **/
2920static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2921 u16 *data)
2922{
2923 struct e1000_nvm_info *nvm = &hw->nvm;
2924 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002925 u16 i;
2926
2927 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2928 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002929 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002930 return -E1000_ERR_NVM;
2931 }
2932
Bruce Allan94d81862009-11-20 23:25:26 +00002933 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002934
Auke Kokbc7f75f2007-09-17 12:30:59 -07002935 for (i = 0; i < words; i++) {
Bruce Allan362e20c2013-02-20 04:05:45 +00002936 dev_spec->shadow_ram[offset + i].modified = true;
2937 dev_spec->shadow_ram[offset + i].value = data[i];
Auke Kokbc7f75f2007-09-17 12:30:59 -07002938 }
2939
Bruce Allan94d81862009-11-20 23:25:26 +00002940 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002941
Auke Kokbc7f75f2007-09-17 12:30:59 -07002942 return 0;
2943}
2944
2945/**
2946 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2947 * @hw: pointer to the HW structure
2948 *
2949 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2950 * which writes the checksum to the shadow ram. The changes in the shadow
2951 * ram are then committed to the EEPROM by processing each bank at a time
2952 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002953 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002954 * future writes.
2955 **/
2956static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2957{
2958 struct e1000_nvm_info *nvm = &hw->nvm;
2959 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002960 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002961 s32 ret_val;
2962 u16 data;
2963
2964 ret_val = e1000e_update_nvm_checksum_generic(hw);
2965 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002966 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002967
2968 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002969 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002970
Bruce Allan94d81862009-11-20 23:25:26 +00002971 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002972
Bruce Allane921eb12012-11-28 09:28:37 +00002973 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002974 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002975 * is going to be written
2976 */
Bruce Allane80bd1d2013-05-01 01:19:46 +00002977 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002978 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002979 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002980 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002981 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002982
2983 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002984 new_bank_offset = nvm->flash_bank_size;
2985 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002986 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002987 if (ret_val)
2988 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002989 } else {
2990 old_bank_offset = nvm->flash_bank_size;
2991 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002992 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002993 if (ret_val)
2994 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002995 }
2996
2997 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00002998 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002999 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07003000 * in the shadow RAM
3001 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003002 if (dev_spec->shadow_ram[i].modified) {
3003 data = dev_spec->shadow_ram[i].value;
3004 } else {
Bruce Allane2434552008-11-21 17:02:41 -08003005 ret_val = e1000_read_flash_word_ich8lan(hw, i +
Bruce Allanf0ff4392013-02-20 04:05:39 +00003006 old_bank_offset,
3007 &data);
Bruce Allane2434552008-11-21 17:02:41 -08003008 if (ret_val)
3009 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003010 }
3011
Bruce Allane921eb12012-11-28 09:28:37 +00003012 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07003013 * (15:14) are 11b until the commit has completed.
3014 * This will allow us to write 10b which indicates the
3015 * signature is valid. We want to do this after the write
3016 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07003017 * while the write is still in progress
3018 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003019 if (i == E1000_ICH_NVM_SIG_WORD)
3020 data |= E1000_ICH_NVM_SIG_MASK;
3021
3022 /* Convert offset to bytes. */
3023 act_offset = (i + new_bank_offset) << 1;
3024
Bruce Allance43a212013-02-20 04:06:32 +00003025 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003026 /* Write the bytes to the new bank. */
3027 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3028 act_offset,
3029 (u8)data);
3030 if (ret_val)
3031 break;
3032
Bruce Allance43a212013-02-20 04:06:32 +00003033 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003034 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003035 act_offset + 1,
3036 (u8)(data >> 8));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003037 if (ret_val)
3038 break;
3039 }
3040
Bruce Allane921eb12012-11-28 09:28:37 +00003041 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07003042 * programming failed.
3043 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003044 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07003045 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003046 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00003047 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003048 }
3049
Bruce Allane921eb12012-11-28 09:28:37 +00003050 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07003051 * to 10b in word 0x13 , this can be done without an
3052 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07003053 * and we need to change bit 14 to 0b
3054 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003055 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08003056 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003057 if (ret_val)
3058 goto release;
3059
Auke Kokbc7f75f2007-09-17 12:30:59 -07003060 data &= 0xBFFF;
3061 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
3062 act_offset * 2 + 1,
3063 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00003064 if (ret_val)
3065 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003066
Bruce Allane921eb12012-11-28 09:28:37 +00003067 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07003068 * its signature word (0x13) high_byte to 0b. This can be
3069 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07003070 * to 1's. We can write 1's to 0's without an erase
3071 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003072 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
3073 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003074 if (ret_val)
3075 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003076
3077 /* Great! Everything worked, we can now clear the cached entries. */
3078 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00003079 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003080 dev_spec->shadow_ram[i].value = 0xFFFF;
3081 }
3082
Bruce Allan9c5e2092010-05-10 15:00:31 +00003083release:
Bruce Allan94d81862009-11-20 23:25:26 +00003084 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003085
Bruce Allane921eb12012-11-28 09:28:37 +00003086 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07003087 * until after the next adapter reset.
3088 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00003089 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00003090 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00003091 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003092 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003093
Bruce Allane2434552008-11-21 17:02:41 -08003094out:
3095 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003096 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003097
Auke Kokbc7f75f2007-09-17 12:30:59 -07003098 return ret_val;
3099}
3100
3101/**
3102 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3103 * @hw: pointer to the HW structure
3104 *
3105 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3106 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3107 * calculated, in which case we need to calculate the checksum and set bit 6.
3108 **/
3109static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3110{
3111 s32 ret_val;
3112 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003113 u16 word;
3114 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003115
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003116 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3117 * the checksum needs to be fixed. This bit is an indication that
3118 * the NVM was prepared by OEM software and did not calculate
3119 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003120 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003121 switch (hw->mac.type) {
3122 case e1000_pch_lpt:
3123 word = NVM_COMPAT;
3124 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3125 break;
3126 default:
3127 word = NVM_FUTURE_INIT_WORD1;
3128 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3129 break;
3130 }
3131
3132 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003133 if (ret_val)
3134 return ret_val;
3135
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003136 if (!(data & valid_csum_mask)) {
3137 data |= valid_csum_mask;
3138 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003139 if (ret_val)
3140 return ret_val;
3141 ret_val = e1000e_update_nvm_checksum(hw);
3142 if (ret_val)
3143 return ret_val;
3144 }
3145
3146 return e1000e_validate_nvm_checksum_generic(hw);
3147}
3148
3149/**
Bruce Allan4a770352008-10-01 17:18:35 -07003150 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3151 * @hw: pointer to the HW structure
3152 *
3153 * To prevent malicious write/erase of the NVM, set it to be read-only
3154 * so that the hardware ignores all write/erase cycles of the NVM via
3155 * the flash control registers. The shadow-ram copy of the NVM will
3156 * still be updated, however any updates to this copy will not stick
3157 * across driver reloads.
3158 **/
3159void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3160{
Bruce Allanca15df52009-10-26 11:23:43 +00003161 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003162 union ich8_flash_protected_range pr0;
3163 union ich8_hws_flash_status hsfsts;
3164 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003165
Bruce Allan94d81862009-11-20 23:25:26 +00003166 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003167
3168 gfpreg = er32flash(ICH_FLASH_GFPREG);
3169
3170 /* Write-protect GbE Sector of NVM */
3171 pr0.regval = er32flash(ICH_FLASH_PR0);
3172 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3173 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3174 pr0.range.wpe = true;
3175 ew32flash(ICH_FLASH_PR0, pr0.regval);
3176
Bruce Allane921eb12012-11-28 09:28:37 +00003177 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003178 * PR0 to prevent the write-protection from being lifted.
3179 * Once FLOCKDN is set, the registers protected by it cannot
3180 * be written until FLOCKDN is cleared by a hardware reset.
3181 */
3182 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3183 hsfsts.hsf_status.flockdn = true;
3184 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3185
Bruce Allan94d81862009-11-20 23:25:26 +00003186 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003187}
3188
3189/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003190 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3191 * @hw: pointer to the HW structure
3192 * @offset: The offset (in bytes) of the byte/word to read.
3193 * @size: Size of data to read, 1=byte 2=word
3194 * @data: The byte(s) to write to the NVM.
3195 *
3196 * Writes one/two bytes to the NVM using the flash access registers.
3197 **/
3198static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3199 u8 size, u16 data)
3200{
3201 union ich8_hws_flash_status hsfsts;
3202 union ich8_hws_flash_ctrl hsflctl;
3203 u32 flash_linear_addr;
3204 u32 flash_data = 0;
3205 s32 ret_val;
3206 u8 count = 0;
3207
3208 if (size < 1 || size > 2 || data > size * 0xff ||
3209 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3210 return -E1000_ERR_NVM;
3211
Bruce Allanf0ff4392013-02-20 04:05:39 +00003212 flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3213 hw->nvm.flash_base_addr);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003214
3215 do {
3216 udelay(1);
3217 /* Steps */
3218 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3219 if (ret_val)
3220 break;
3221
3222 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3223 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
Bruce Allan362e20c2013-02-20 04:05:45 +00003224 hsflctl.hsf_ctrl.fldbcount = size - 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003225 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3226 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3227
3228 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3229
3230 if (size == 1)
3231 flash_data = (u32)data & 0x00FF;
3232 else
3233 flash_data = (u32)data;
3234
3235 ew32flash(ICH_FLASH_FDATA0, flash_data);
3236
Bruce Allane921eb12012-11-28 09:28:37 +00003237 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003238 * and try the whole sequence a few more times else done
3239 */
Bruce Allan17e813e2013-02-20 04:06:01 +00003240 ret_val =
3241 e1000_flash_cycle_ich8lan(hw,
3242 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003243 if (!ret_val)
3244 break;
3245
Bruce Allane921eb12012-11-28 09:28:37 +00003246 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003247 * completely hosed, but if the error condition
3248 * is detected, it won't hurt to give it another
3249 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3250 */
3251 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003252 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003253 /* Repeat for some time before giving up. */
3254 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003255 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003256 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003257 break;
3258 }
3259 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3260
3261 return ret_val;
3262}
3263
3264/**
3265 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3266 * @hw: pointer to the HW structure
3267 * @offset: The index of the byte to read.
3268 * @data: The byte to write to the NVM.
3269 *
3270 * Writes a single byte to the NVM using the flash access registers.
3271 **/
3272static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3273 u8 data)
3274{
3275 u16 word = (u16)data;
3276
3277 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3278}
3279
3280/**
3281 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3282 * @hw: pointer to the HW structure
3283 * @offset: The offset of the byte to write.
3284 * @byte: The byte to write to the NVM.
3285 *
3286 * Writes a single byte to the NVM using the flash access registers.
3287 * Goes through a retry algorithm before giving up.
3288 **/
3289static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3290 u32 offset, u8 byte)
3291{
3292 s32 ret_val;
3293 u16 program_retries;
3294
3295 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3296 if (!ret_val)
3297 return ret_val;
3298
3299 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003300 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Bruce Allance43a212013-02-20 04:06:32 +00003301 usleep_range(100, 200);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003302 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3303 if (!ret_val)
3304 break;
3305 }
3306 if (program_retries == 100)
3307 return -E1000_ERR_NVM;
3308
3309 return 0;
3310}
3311
3312/**
3313 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3314 * @hw: pointer to the HW structure
3315 * @bank: 0 for first bank, 1 for second bank, etc.
3316 *
3317 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3318 * bank N is 4096 * N + flash_reg_addr.
3319 **/
3320static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3321{
3322 struct e1000_nvm_info *nvm = &hw->nvm;
3323 union ich8_hws_flash_status hsfsts;
3324 union ich8_hws_flash_ctrl hsflctl;
3325 u32 flash_linear_addr;
3326 /* bank size is in 16bit words - adjust to bytes */
3327 u32 flash_bank_size = nvm->flash_bank_size * 2;
3328 s32 ret_val;
3329 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003330 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003331
3332 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3333
Bruce Allane921eb12012-11-28 09:28:37 +00003334 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003335 * register
3336 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003337 * consecutive sectors. The start index for the nth Hw sector
3338 * can be calculated as = bank * 4096 + n * 256
3339 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3340 * The start index for the nth Hw sector can be calculated
3341 * as = bank * 4096
3342 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3343 * (ich9 only, otherwise error condition)
3344 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3345 */
3346 switch (hsfsts.hsf_status.berasesz) {
3347 case 0:
3348 /* Hw sector size 256 */
3349 sector_size = ICH_FLASH_SEG_SIZE_256;
3350 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3351 break;
3352 case 1:
3353 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003354 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003355 break;
3356 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003357 sector_size = ICH_FLASH_SEG_SIZE_8K;
3358 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003359 break;
3360 case 3:
3361 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003362 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003363 break;
3364 default:
3365 return -E1000_ERR_NVM;
3366 }
3367
3368 /* Start with the base address, then add the sector offset. */
3369 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003370 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003371
Bruce Allan53aa82d2013-02-20 04:06:06 +00003372 for (j = 0; j < iteration; j++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07003373 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00003374 u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
3375
Auke Kokbc7f75f2007-09-17 12:30:59 -07003376 /* Steps */
3377 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3378 if (ret_val)
3379 return ret_val;
3380
Bruce Allane921eb12012-11-28 09:28:37 +00003381 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003382 * Cycle field in hw flash control
3383 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003384 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3385 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3386 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3387
Bruce Allane921eb12012-11-28 09:28:37 +00003388 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003389 * block into Flash Linear address field in Flash
3390 * Address.
3391 */
3392 flash_linear_addr += (j * sector_size);
3393 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3394
Bruce Allan17e813e2013-02-20 04:06:01 +00003395 ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003396 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003397 break;
3398
Bruce Allane921eb12012-11-28 09:28:37 +00003399 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003400 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003401 * a few more times else Done
3402 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003403 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003404 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003405 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003406 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003407 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003408 return ret_val;
3409 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3410 }
3411
3412 return 0;
3413}
3414
3415/**
3416 * e1000_valid_led_default_ich8lan - Set the default LED settings
3417 * @hw: pointer to the HW structure
3418 * @data: Pointer to the LED settings
3419 *
3420 * Reads the LED default settings from the NVM to data. If the NVM LED
3421 * settings is all 0's or F's, set the LED default to a valid LED default
3422 * setting.
3423 **/
3424static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3425{
3426 s32 ret_val;
3427
3428 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3429 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003430 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003431 return ret_val;
3432 }
3433
Bruce Allane5fe2542013-02-20 04:06:27 +00003434 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003435 *data = ID_LED_DEFAULT_ICH8LAN;
3436
3437 return 0;
3438}
3439
3440/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003441 * e1000_id_led_init_pchlan - store LED configurations
3442 * @hw: pointer to the HW structure
3443 *
3444 * PCH does not control LEDs via the LEDCTL register, rather it uses
3445 * the PHY LED configuration register.
3446 *
3447 * PCH also does not have an "always on" or "always off" mode which
3448 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003449 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003450 * use "link_up" mode. The LEDs will still ID on request if there is no
3451 * link based on logic in e1000_led_[on|off]_pchlan().
3452 **/
3453static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3454{
3455 struct e1000_mac_info *mac = &hw->mac;
3456 s32 ret_val;
3457 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3458 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3459 u16 data, i, temp, shift;
3460
3461 /* Get default ID LED modes */
3462 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3463 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003464 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003465
3466 mac->ledctl_default = er32(LEDCTL);
3467 mac->ledctl_mode1 = mac->ledctl_default;
3468 mac->ledctl_mode2 = mac->ledctl_default;
3469
3470 for (i = 0; i < 4; i++) {
3471 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3472 shift = (i * 5);
3473 switch (temp) {
3474 case ID_LED_ON1_DEF2:
3475 case ID_LED_ON1_ON2:
3476 case ID_LED_ON1_OFF2:
3477 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3478 mac->ledctl_mode1 |= (ledctl_on << shift);
3479 break;
3480 case ID_LED_OFF1_DEF2:
3481 case ID_LED_OFF1_ON2:
3482 case ID_LED_OFF1_OFF2:
3483 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3484 mac->ledctl_mode1 |= (ledctl_off << shift);
3485 break;
3486 default:
3487 /* Do nothing */
3488 break;
3489 }
3490 switch (temp) {
3491 case ID_LED_DEF1_ON2:
3492 case ID_LED_ON1_ON2:
3493 case ID_LED_OFF1_ON2:
3494 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3495 mac->ledctl_mode2 |= (ledctl_on << shift);
3496 break;
3497 case ID_LED_DEF1_OFF2:
3498 case ID_LED_ON1_OFF2:
3499 case ID_LED_OFF1_OFF2:
3500 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3501 mac->ledctl_mode2 |= (ledctl_off << shift);
3502 break;
3503 default:
3504 /* Do nothing */
3505 break;
3506 }
3507 }
3508
Bruce Allan5015e532012-02-08 02:55:56 +00003509 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003510}
3511
3512/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003513 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3514 * @hw: pointer to the HW structure
3515 *
3516 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3517 * register, so the the bus width is hard coded.
3518 **/
3519static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3520{
3521 struct e1000_bus_info *bus = &hw->bus;
3522 s32 ret_val;
3523
3524 ret_val = e1000e_get_bus_info_pcie(hw);
3525
Bruce Allane921eb12012-11-28 09:28:37 +00003526 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003527 * a configuration space, but do not contain
3528 * PCI Express Capability registers, so bus width
3529 * must be hardcoded.
3530 */
3531 if (bus->width == e1000_bus_width_unknown)
3532 bus->width = e1000_bus_width_pcie_x1;
3533
3534 return ret_val;
3535}
3536
3537/**
3538 * e1000_reset_hw_ich8lan - Reset the hardware
3539 * @hw: pointer to the HW structure
3540 *
3541 * Does a full reset of the hardware which includes a reset of the PHY and
3542 * MAC.
3543 **/
3544static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3545{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003546 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003547 u16 kum_cfg;
3548 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003549 s32 ret_val;
3550
Bruce Allane921eb12012-11-28 09:28:37 +00003551 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003552 * on the last TLP read/write transaction when MAC is reset.
3553 */
3554 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003555 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003556 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003557
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003558 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003559 ew32(IMC, 0xffffffff);
3560
Bruce Allane921eb12012-11-28 09:28:37 +00003561 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003562 * any pending transactions to complete before we hit the MAC
3563 * with the global reset.
3564 */
3565 ew32(RCTL, 0);
3566 ew32(TCTL, E1000_TCTL_PSP);
3567 e1e_flush();
3568
Bruce Allan1bba4382011-03-19 00:27:20 +00003569 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003570
3571 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3572 if (hw->mac.type == e1000_ich8lan) {
3573 /* Set Tx and Rx buffer allocation to 8k apiece. */
3574 ew32(PBA, E1000_PBA_8K);
3575 /* Set Packet Buffer Size to 16k. */
3576 ew32(PBS, E1000_PBS_16K);
3577 }
3578
Bruce Allan1d5846b2009-10-29 13:46:05 +00003579 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003580 /* Save the NVM K1 bit setting */
3581 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003582 if (ret_val)
3583 return ret_val;
3584
Bruce Allan62bc8132012-03-20 03:47:57 +00003585 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003586 dev_spec->nvm_k1_enabled = true;
3587 else
3588 dev_spec->nvm_k1_enabled = false;
3589 }
3590
Auke Kokbc7f75f2007-09-17 12:30:59 -07003591 ctrl = er32(CTRL);
3592
Bruce Allan44abd5c2012-02-22 09:02:37 +00003593 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003594 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003595 * time to make sure the interface between MAC and the
3596 * external PHY is reset.
3597 */
3598 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003599
Bruce Allane921eb12012-11-28 09:28:37 +00003600 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003601 * non-managed 82579
3602 */
3603 if ((hw->mac.type == e1000_pch2lan) &&
3604 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3605 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003606 }
3607 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003608 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003609 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003610 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003611 msleep(20);
3612
Bruce Allan62bc8132012-03-20 03:47:57 +00003613 /* Set Phy Config Counter to 50msec */
3614 if (hw->mac.type == e1000_pch2lan) {
3615 reg = er32(FEXTNVM3);
3616 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3617 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3618 ew32(FEXTNVM3, reg);
3619 }
3620
Bruce Allanfc0c7762009-07-01 13:27:55 +00003621 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003622 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003623
Bruce Allane98cac42010-05-10 15:02:32 +00003624 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003625 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003626 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003627 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003628
Bruce Allane98cac42010-05-10 15:02:32 +00003629 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003630 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003631 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003632 }
Bruce Allane98cac42010-05-10 15:02:32 +00003633
Bruce Allane921eb12012-11-28 09:28:37 +00003634 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003635 * will be detected as a CRC error and be dropped rather than show up
3636 * as a bad packet to the DMA engine.
3637 */
3638 if (hw->mac.type == e1000_pchlan)
3639 ew32(CRC_OFFSET, 0x65656565);
3640
Auke Kokbc7f75f2007-09-17 12:30:59 -07003641 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003642 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003643
Bruce Allan62bc8132012-03-20 03:47:57 +00003644 reg = er32(KABGTXD);
3645 reg |= E1000_KABGTXD_BGSQLBIAS;
3646 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003647
Bruce Allan5015e532012-02-08 02:55:56 +00003648 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003649}
3650
3651/**
3652 * e1000_init_hw_ich8lan - Initialize the hardware
3653 * @hw: pointer to the HW structure
3654 *
3655 * Prepares the hardware for transmit and receive by doing the following:
3656 * - initialize hardware bits
3657 * - initialize LED identification
3658 * - setup receive address registers
3659 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003660 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003661 * - clear statistics
3662 **/
3663static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3664{
3665 struct e1000_mac_info *mac = &hw->mac;
3666 u32 ctrl_ext, txdctl, snoop;
3667 s32 ret_val;
3668 u16 i;
3669
3670 e1000_initialize_hw_bits_ich8lan(hw);
3671
3672 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003673 ret_val = mac->ops.id_led_init(hw);
Bruce Allan33550ce2013-02-20 04:06:16 +00003674 /* An error is not fatal and we should not stop init due to this */
Bruce Allande39b752009-11-20 23:27:59 +00003675 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003676 e_dbg("Error initializing identification LED\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003677
3678 /* Setup the receive address. */
3679 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3680
3681 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003682 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003683 for (i = 0; i < mac->mta_reg_count; i++)
3684 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3685
Bruce Allane921eb12012-11-28 09:28:37 +00003686 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003687 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003688 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3689 */
3690 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003691 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3692 i &= ~BM_WUC_HOST_WU_BIT;
3693 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003694 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3695 if (ret_val)
3696 return ret_val;
3697 }
3698
Auke Kokbc7f75f2007-09-17 12:30:59 -07003699 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003700 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003701
3702 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003703 txdctl = er32(TXDCTL(0));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003704 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3705 E1000_TXDCTL_FULL_TX_DESC_WB);
3706 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3707 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003708 ew32(TXDCTL(0), txdctl);
3709 txdctl = er32(TXDCTL(1));
Bruce Allanf0ff4392013-02-20 04:05:39 +00003710 txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
3711 E1000_TXDCTL_FULL_TX_DESC_WB);
3712 txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
3713 E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003714 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003715
Bruce Allane921eb12012-11-28 09:28:37 +00003716 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003717 * By default, we should use snoop behavior.
3718 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003719 if (mac->type == e1000_ich8lan)
3720 snoop = PCIE_ICH8_SNOOP_ALL;
3721 else
Bruce Allan53aa82d2013-02-20 04:06:06 +00003722 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003723 e1000e_set_pcie_no_snoop(hw, snoop);
3724
3725 ctrl_ext = er32(CTRL_EXT);
3726 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3727 ew32(CTRL_EXT, ctrl_ext);
3728
Bruce Allane921eb12012-11-28 09:28:37 +00003729 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003730 * important that we do this after we have tried to establish link
3731 * because the symbol error count will increment wildly if there
3732 * is no link.
3733 */
3734 e1000_clear_hw_cntrs_ich8lan(hw);
3735
Bruce Allane561a702012-02-08 02:55:46 +00003736 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003737}
Bruce Allanfc830b72013-02-20 04:06:11 +00003738
Auke Kokbc7f75f2007-09-17 12:30:59 -07003739/**
3740 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3741 * @hw: pointer to the HW structure
3742 *
3743 * Sets/Clears required hardware bits necessary for correctly setting up the
3744 * hardware for transmit and receive.
3745 **/
3746static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3747{
3748 u32 reg;
3749
3750 /* Extended Device Control */
3751 reg = er32(CTRL_EXT);
3752 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003753 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3754 if (hw->mac.type >= e1000_pchlan)
3755 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003756 ew32(CTRL_EXT, reg);
3757
3758 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003759 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003760 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003761 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003762
3763 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003764 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003765 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003766 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003767
3768 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003769 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003770 if (hw->mac.type == e1000_ich8lan)
3771 reg |= (1 << 28) | (1 << 29);
3772 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003773 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003774
3775 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003776 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003777 if (er32(TCTL) & E1000_TCTL_MULR)
3778 reg &= ~(1 << 28);
3779 else
3780 reg |= (1 << 28);
3781 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003782 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003783
3784 /* Device Status */
3785 if (hw->mac.type == e1000_ich8lan) {
3786 reg = er32(STATUS);
3787 reg &= ~(1 << 31);
3788 ew32(STATUS, reg);
3789 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003790
Bruce Allane921eb12012-11-28 09:28:37 +00003791 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003792 * traffic, just disable the nfs filtering capability
3793 */
3794 reg = er32(RFCTL);
3795 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003796
Bruce Allane921eb12012-11-28 09:28:37 +00003797 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003798 * IPv6 headers can hang the Rx.
3799 */
3800 if (hw->mac.type == e1000_ich8lan)
3801 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003802 ew32(RFCTL, reg);
Bruce Allan94fb8482013-01-23 09:00:03 +00003803
3804 /* Enable ECC on Lynxpoint */
3805 if (hw->mac.type == e1000_pch_lpt) {
3806 reg = er32(PBECCSTS);
3807 reg |= E1000_PBECCSTS_ECC_ENABLE;
3808 ew32(PBECCSTS, reg);
3809
3810 reg = er32(CTRL);
3811 reg |= E1000_CTRL_MEHE;
3812 ew32(CTRL, reg);
3813 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003814}
3815
3816/**
3817 * e1000_setup_link_ich8lan - Setup flow control and link settings
3818 * @hw: pointer to the HW structure
3819 *
3820 * Determines which flow control settings to use, then configures flow
3821 * control. Calls the appropriate media-specific link configuration
3822 * function. Assuming the adapter has a valid link partner, a valid link
3823 * should be established. Assumes the hardware has previously been reset
3824 * and the transmitter and receiver are not enabled.
3825 **/
3826static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3827{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003828 s32 ret_val;
3829
Bruce Allan44abd5c2012-02-22 09:02:37 +00003830 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003831 return 0;
3832
Bruce Allane921eb12012-11-28 09:28:37 +00003833 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003834 * the default flow control setting, so we explicitly
3835 * set it to full.
3836 */
Bruce Allan37289d92009-06-02 11:29:37 +00003837 if (hw->fc.requested_mode == e1000_fc_default) {
3838 /* Workaround h/w hang when Tx flow control enabled */
3839 if (hw->mac.type == e1000_pchlan)
3840 hw->fc.requested_mode = e1000_fc_rx_pause;
3841 else
3842 hw->fc.requested_mode = e1000_fc_full;
3843 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003844
Bruce Allane921eb12012-11-28 09:28:37 +00003845 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003846 * on the link partner's capabilities, we may or may not use this mode.
3847 */
3848 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003849
Bruce Allan17e813e2013-02-20 04:06:01 +00003850 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003851
3852 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003853 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003854 if (ret_val)
3855 return ret_val;
3856
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003857 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003858 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003859 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003860 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003861 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003862 ew32(FCRTV_PCH, hw->fc.refresh_time);
3863
Bruce Allan482fed82011-01-06 14:29:49 +00003864 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3865 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003866 if (ret_val)
3867 return ret_val;
3868 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003869
3870 return e1000e_set_fc_watermarks(hw);
3871}
3872
3873/**
3874 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3875 * @hw: pointer to the HW structure
3876 *
3877 * Configures the kumeran interface to the PHY to wait the appropriate time
3878 * when polling the PHY, then call the generic setup_copper_link to finish
3879 * configuring the copper link.
3880 **/
3881static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3882{
3883 u32 ctrl;
3884 s32 ret_val;
3885 u16 reg_data;
3886
3887 ctrl = er32(CTRL);
3888 ctrl |= E1000_CTRL_SLU;
3889 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3890 ew32(CTRL, ctrl);
3891
Bruce Allane921eb12012-11-28 09:28:37 +00003892 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003893 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003894 * this fixes erroneous timeouts at 10Mbps.
3895 */
Bruce Allan07818952009-12-08 07:28:01 +00003896 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003897 if (ret_val)
3898 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003899 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003900 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003901 if (ret_val)
3902 return ret_val;
3903 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003904 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
Bruce Allanf0ff4392013-02-20 04:05:39 +00003905 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003906 if (ret_val)
3907 return ret_val;
3908
Bruce Allana4f58f52009-06-02 11:29:18 +00003909 switch (hw->phy.type) {
3910 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003911 ret_val = e1000e_copper_link_setup_igp(hw);
3912 if (ret_val)
3913 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003914 break;
3915 case e1000_phy_bm:
3916 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003917 ret_val = e1000e_copper_link_setup_m88(hw);
3918 if (ret_val)
3919 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003920 break;
3921 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003922 case e1000_phy_82579:
Bruce Allana4f58f52009-06-02 11:29:18 +00003923 ret_val = e1000_copper_link_setup_82577(hw);
3924 if (ret_val)
3925 return ret_val;
3926 break;
3927 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003928 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003929 if (ret_val)
3930 return ret_val;
3931
3932 reg_data &= ~IFE_PMC_AUTO_MDIX;
3933
3934 switch (hw->phy.mdix) {
3935 case 1:
3936 reg_data &= ~IFE_PMC_FORCE_MDIX;
3937 break;
3938 case 2:
3939 reg_data |= IFE_PMC_FORCE_MDIX;
3940 break;
3941 case 0:
3942 default:
3943 reg_data |= IFE_PMC_AUTO_MDIX;
3944 break;
3945 }
Bruce Allan482fed82011-01-06 14:29:49 +00003946 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003947 if (ret_val)
3948 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003949 break;
3950 default:
3951 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003952 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003953
Auke Kokbc7f75f2007-09-17 12:30:59 -07003954 return e1000e_setup_copper_link(hw);
3955}
3956
3957/**
Bruce Allanea8179a2013-03-06 09:02:47 +00003958 * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
3959 * @hw: pointer to the HW structure
3960 *
3961 * Calls the PHY specific link setup function and then calls the
3962 * generic setup_copper_link to finish configuring the link for
3963 * Lynxpoint PCH devices
3964 **/
3965static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
3966{
3967 u32 ctrl;
3968 s32 ret_val;
3969
3970 ctrl = er32(CTRL);
3971 ctrl |= E1000_CTRL_SLU;
3972 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3973 ew32(CTRL, ctrl);
3974
3975 ret_val = e1000_copper_link_setup_82577(hw);
3976 if (ret_val)
3977 return ret_val;
3978
3979 return e1000e_setup_copper_link(hw);
3980}
3981
3982/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003983 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3984 * @hw: pointer to the HW structure
3985 * @speed: pointer to store current link speed
3986 * @duplex: pointer to store the current link duplex
3987 *
Bruce Allanad680762008-03-28 09:15:03 -07003988 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003989 * information and then calls the Kumeran lock loss workaround for links at
3990 * gigabit speeds.
3991 **/
3992static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3993 u16 *duplex)
3994{
3995 s32 ret_val;
3996
3997 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3998 if (ret_val)
3999 return ret_val;
4000
4001 if ((hw->mac.type == e1000_ich8lan) &&
Bruce Allane5fe2542013-02-20 04:06:27 +00004002 (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004003 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
4004 }
4005
4006 return ret_val;
4007}
4008
4009/**
4010 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
4011 * @hw: pointer to the HW structure
4012 *
4013 * Work-around for 82566 Kumeran PCS lock loss:
4014 * On link status change (i.e. PCI reset, speed change) and link is up and
4015 * speed is gigabit-
4016 * 0) if workaround is optionally disabled do nothing
4017 * 1) wait 1ms for Kumeran link to come up
4018 * 2) check Kumeran Diagnostic register PCS lock loss bit
4019 * 3) if not set the link is locked (all is good), otherwise...
4020 * 4) reset the PHY
4021 * 5) repeat up to 10 times
4022 * Note: this is only called for IGP3 copper when speed is 1gb.
4023 **/
4024static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
4025{
4026 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4027 u32 phy_ctrl;
4028 s32 ret_val;
4029 u16 i, data;
4030 bool link;
4031
4032 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
4033 return 0;
4034
Bruce Allane921eb12012-11-28 09:28:37 +00004035 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004036 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07004037 * stability
4038 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004039 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
4040 if (!link)
4041 return 0;
4042
4043 for (i = 0; i < 10; i++) {
4044 /* read once to clear */
4045 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4046 if (ret_val)
4047 return ret_val;
4048 /* and again to get new status */
4049 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
4050 if (ret_val)
4051 return ret_val;
4052
4053 /* check for PCS lock */
4054 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4055 return 0;
4056
4057 /* Issue PHY reset */
4058 e1000_phy_hw_reset(hw);
4059 mdelay(5);
4060 }
4061 /* Disable GigE link negotiation */
4062 phy_ctrl = er32(PHY_CTRL);
4063 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
4064 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4065 ew32(PHY_CTRL, phy_ctrl);
4066
Bruce Allane921eb12012-11-28 09:28:37 +00004067 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07004068 * any PHY registers
4069 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004070 e1000e_gig_downshift_workaround_ich8lan(hw);
4071
4072 /* unable to acquire PCS lock */
4073 return -E1000_ERR_PHY;
4074}
4075
4076/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00004077 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004078 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08004079 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07004080 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00004081 * If ICH8, set the current Kumeran workaround state (enabled - true
4082 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07004083 **/
4084void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
Bruce Allan17e813e2013-02-20 04:06:01 +00004085 bool state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07004086{
4087 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
4088
4089 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004090 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07004091 return;
4092 }
4093
4094 dev_spec->kmrn_lock_loss_workaround_enabled = state;
4095}
4096
4097/**
4098 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
4099 * @hw: pointer to the HW structure
4100 *
4101 * Workaround for 82566 power-down on D3 entry:
4102 * 1) disable gigabit link
4103 * 2) write VR power-down enable
4104 * 3) read it back
4105 * Continue if successful, else issue LCD reset and repeat
4106 **/
4107void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
4108{
4109 u32 reg;
4110 u16 data;
Bruce Allane80bd1d2013-05-01 01:19:46 +00004111 u8 retry = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004112
4113 if (hw->phy.type != e1000_phy_igp_3)
4114 return;
4115
4116 /* Try the workaround twice (if needed) */
4117 do {
4118 /* Disable link */
4119 reg = er32(PHY_CTRL);
4120 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4121 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4122 ew32(PHY_CTRL, reg);
4123
Bruce Allane921eb12012-11-28 09:28:37 +00004124 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07004125 * accessing any PHY registers
4126 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004127 if (hw->mac.type == e1000_ich8lan)
4128 e1000e_gig_downshift_workaround_ich8lan(hw);
4129
4130 /* Write VR power-down enable */
4131 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4132 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4133 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4134
4135 /* Read it back and test */
4136 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4137 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4138 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4139 break;
4140
4141 /* Issue PHY reset and repeat at most one more time */
4142 reg = er32(CTRL);
4143 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4144 retry++;
4145 } while (retry);
4146}
4147
4148/**
4149 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4150 * @hw: pointer to the HW structure
4151 *
4152 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004153 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004154 * 1) Set Kumeran Near-end loopback
4155 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004156 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004157 **/
4158void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4159{
4160 s32 ret_val;
4161 u16 reg_data;
4162
Bruce Allan462d5992011-09-30 08:07:11 +00004163 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004164 return;
4165
4166 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004167 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004168 if (ret_val)
4169 return;
4170 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4171 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
Bruce Allan17e813e2013-02-20 04:06:01 +00004172 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004173 if (ret_val)
4174 return;
4175 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
Bruce Allan7dbbe5d2013-01-05 05:08:31 +00004176 e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004177}
4178
4179/**
Bruce Allan99730e42011-05-13 07:19:48 +00004180 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004181 * @hw: pointer to the HW structure
4182 *
4183 * During S0 to Sx transition, it is possible the link remains at gig
4184 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004185 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4186 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4187 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4188 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004189 * Parts that support (and are linked to a partner which support) EEE in
4190 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4191 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004192 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004193void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004194{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004195 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004196 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004197 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004198
Bruce Allan17f085d2010-06-17 18:59:48 +00004199 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004200 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allane08f6262013-02-20 03:06:34 +00004201
Bruce Allan2fbe4522012-04-19 03:21:47 +00004202 if (hw->phy.type == e1000_phy_i217) {
Bruce Allane08f6262013-02-20 03:06:34 +00004203 u16 phy_reg, device_id = hw->adapter->pdev->device;
4204
4205 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
4206 (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V)) {
4207 u32 fextnvm6 = er32(FEXTNVM6);
4208
4209 ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
4210 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004211
4212 ret_val = hw->phy.ops.acquire(hw);
4213 if (ret_val)
4214 goto out;
4215
4216 if (!dev_spec->eee_disable) {
4217 u16 eee_advert;
4218
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004219 ret_val =
4220 e1000_read_emi_reg_locked(hw,
4221 I217_EEE_ADVERTISEMENT,
4222 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004223 if (ret_val)
4224 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004225
Bruce Allane921eb12012-11-28 09:28:37 +00004226 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004227 * EEE and 100Full is advertised on both ends of the
4228 * link.
4229 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004230 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004231 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004232 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004233 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4234 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4235 E1000_PHY_CTRL_NOND0A_LPLU);
4236 }
4237
Bruce Allane921eb12012-11-28 09:28:37 +00004238 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004239 * when the system is going into Sx and no manageability engine
4240 * is present, the driver must configure proxy to reset only on
4241 * power good. LPI (Low Power Idle) state must also reset only
4242 * on power good, as well as the MTA (Multicast table array).
4243 * The SMBus release must also be disabled on LCD reset.
4244 */
4245 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan2fbe4522012-04-19 03:21:47 +00004246 /* Enable proxy to reset only on power good. */
4247 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4248 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4249 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4250
Bruce Allane921eb12012-11-28 09:28:37 +00004251 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004252 * power good.
4253 */
4254 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004255 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004256 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4257
4258 /* Disable the SMB release on LCD reset. */
4259 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004260 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004261 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4262 }
4263
Bruce Allane921eb12012-11-28 09:28:37 +00004264 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004265 * Support
4266 */
4267 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004268 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004269 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4270
4271release:
4272 hw->phy.ops.release(hw);
4273 }
4274out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004275 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004276
Bruce Allan462d5992011-09-30 08:07:11 +00004277 if (hw->mac.type == e1000_ich8lan)
4278 e1000e_gig_downshift_workaround_ich8lan(hw);
4279
Bruce Allan8395ae82010-09-22 17:15:08 +00004280 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004281 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004282
4283 /* Reset PHY to activate OEM bits on 82577/8 */
4284 if (hw->mac.type == e1000_pchlan)
4285 e1000e_phy_hw_reset_generic(hw);
4286
Bruce Allan8395ae82010-09-22 17:15:08 +00004287 ret_val = hw->phy.ops.acquire(hw);
4288 if (ret_val)
4289 return;
4290 e1000_write_smbus_addr(hw);
4291 hw->phy.ops.release(hw);
4292 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004293}
4294
4295/**
Bruce Allan99730e42011-05-13 07:19:48 +00004296 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4297 * @hw: pointer to the HW structure
4298 *
4299 * During Sx to S0 transitions on non-managed devices or managed devices
4300 * on which PHY resets are not blocked, if the PHY registers cannot be
4301 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4302 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004303 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004304 **/
4305void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4306{
Bruce Allan90b82982011-12-16 00:46:33 +00004307 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004308
Bruce Allancb17aab2012-04-13 03:16:22 +00004309 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004310 return;
4311
Bruce Allancb17aab2012-04-13 03:16:22 +00004312 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004313 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004314 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004315 return;
4316 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004317
Bruce Allane921eb12012-11-28 09:28:37 +00004318 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004319 * is transitioning from Sx and no manageability engine is present
4320 * configure SMBus to restore on reset, disable proxy, and enable
4321 * the reset on MTA (Multicast table array).
4322 */
4323 if (hw->phy.type == e1000_phy_i217) {
4324 u16 phy_reg;
4325
4326 ret_val = hw->phy.ops.acquire(hw);
4327 if (ret_val) {
4328 e_dbg("Failed to setup iRST\n");
4329 return;
4330 }
4331
4332 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004333 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004334 * is present
4335 */
4336 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4337 if (ret_val)
4338 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004339 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004340 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4341
4342 /* Disable Proxy */
4343 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4344 }
4345 /* Enable reset on MTA */
4346 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4347 if (ret_val)
4348 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004349 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004350 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4351release:
4352 if (ret_val)
4353 e_dbg("Error %d in resume workarounds\n", ret_val);
4354 hw->phy.ops.release(hw);
4355 }
Bruce Allan99730e42011-05-13 07:19:48 +00004356}
4357
4358/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004359 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4360 * @hw: pointer to the HW structure
4361 *
4362 * Return the LED back to the default configuration.
4363 **/
4364static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4365{
4366 if (hw->phy.type == e1000_phy_ife)
4367 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4368
4369 ew32(LEDCTL, hw->mac.ledctl_default);
4370 return 0;
4371}
4372
4373/**
Auke Kok489815c2008-02-21 15:11:07 -08004374 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004375 * @hw: pointer to the HW structure
4376 *
Auke Kok489815c2008-02-21 15:11:07 -08004377 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004378 **/
4379static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4380{
4381 if (hw->phy.type == e1000_phy_ife)
4382 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4383 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4384
4385 ew32(LEDCTL, hw->mac.ledctl_mode2);
4386 return 0;
4387}
4388
4389/**
Auke Kok489815c2008-02-21 15:11:07 -08004390 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004391 * @hw: pointer to the HW structure
4392 *
Auke Kok489815c2008-02-21 15:11:07 -08004393 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004394 **/
4395static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4396{
4397 if (hw->phy.type == e1000_phy_ife)
4398 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004399 (IFE_PSCL_PROBE_MODE |
4400 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004401
4402 ew32(LEDCTL, hw->mac.ledctl_mode1);
4403 return 0;
4404}
4405
4406/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004407 * e1000_setup_led_pchlan - Configures SW controllable LED
4408 * @hw: pointer to the HW structure
4409 *
4410 * This prepares the SW controllable LED for use.
4411 **/
4412static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4413{
Bruce Allan482fed82011-01-06 14:29:49 +00004414 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004415}
4416
4417/**
4418 * e1000_cleanup_led_pchlan - Restore the default LED operation
4419 * @hw: pointer to the HW structure
4420 *
4421 * Return the LED back to the default configuration.
4422 **/
4423static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4424{
Bruce Allan482fed82011-01-06 14:29:49 +00004425 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004426}
4427
4428/**
4429 * e1000_led_on_pchlan - Turn LEDs on
4430 * @hw: pointer to the HW structure
4431 *
4432 * Turn on the LEDs.
4433 **/
4434static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4435{
4436 u16 data = (u16)hw->mac.ledctl_mode2;
4437 u32 i, led;
4438
Bruce Allane921eb12012-11-28 09:28:37 +00004439 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004440 * for each LED that's mode is "link_up" in ledctl_mode2.
4441 */
4442 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4443 for (i = 0; i < 3; i++) {
4444 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4445 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4446 E1000_LEDCTL_MODE_LINK_UP)
4447 continue;
4448 if (led & E1000_PHY_LED0_IVRT)
4449 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4450 else
4451 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4452 }
4453 }
4454
Bruce Allan482fed82011-01-06 14:29:49 +00004455 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004456}
4457
4458/**
4459 * e1000_led_off_pchlan - Turn LEDs off
4460 * @hw: pointer to the HW structure
4461 *
4462 * Turn off the LEDs.
4463 **/
4464static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4465{
4466 u16 data = (u16)hw->mac.ledctl_mode1;
4467 u32 i, led;
4468
Bruce Allane921eb12012-11-28 09:28:37 +00004469 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004470 * for each LED that's mode is "link_up" in ledctl_mode1.
4471 */
4472 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4473 for (i = 0; i < 3; i++) {
4474 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4475 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4476 E1000_LEDCTL_MODE_LINK_UP)
4477 continue;
4478 if (led & E1000_PHY_LED0_IVRT)
4479 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4480 else
4481 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4482 }
4483 }
4484
Bruce Allan482fed82011-01-06 14:29:49 +00004485 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004486}
4487
4488/**
Bruce Allane98cac42010-05-10 15:02:32 +00004489 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004490 * @hw: pointer to the HW structure
4491 *
Bruce Allane98cac42010-05-10 15:02:32 +00004492 * Read appropriate register for the config done bit for completion status
4493 * and configure the PHY through s/w for EEPROM-less parts.
4494 *
4495 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4496 * config done bit, so only an error is logged and continues. If we were
4497 * to return with error, EEPROM-less silicon would not be able to be reset
4498 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004499 **/
4500static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4501{
Bruce Allane98cac42010-05-10 15:02:32 +00004502 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004503 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004504 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004505
Bruce Allanfe908492013-01-05 08:06:14 +00004506 e1000e_get_cfg_done_generic(hw);
Bruce Allanf4187b52008-08-26 18:36:50 -07004507
Bruce Allane98cac42010-05-10 15:02:32 +00004508 /* Wait for indication from h/w that it has completed basic config */
4509 if (hw->mac.type >= e1000_ich10lan) {
4510 e1000_lan_init_done_ich8lan(hw);
4511 } else {
4512 ret_val = e1000e_get_auto_rd_done(hw);
4513 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004514 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004515 * return with an error. This can happen in situations
4516 * where there is no eeprom and prevents getting link.
4517 */
4518 e_dbg("Auto Read Done did not complete\n");
4519 ret_val = 0;
4520 }
4521 }
4522
4523 /* Clear PHY Reset Asserted bit */
4524 status = er32(STATUS);
4525 if (status & E1000_STATUS_PHYRA)
4526 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4527 else
4528 e_dbg("PHY Reset Asserted not set - needs delay\n");
4529
Bruce Allanf4187b52008-08-26 18:36:50 -07004530 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004531 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004532 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004533 (hw->phy.type == e1000_phy_igp_3)) {
4534 e1000e_phy_init_script_igp3(hw);
4535 }
4536 } else {
4537 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4538 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004539 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004540 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004541 }
4542 }
4543
Bruce Allane98cac42010-05-10 15:02:32 +00004544 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004545}
4546
4547/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004548 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4549 * @hw: pointer to the HW structure
4550 *
4551 * In the case of a PHY power down to save power, or to turn off link during a
4552 * driver unload, or wake on lan is not enabled, remove the link.
4553 **/
4554static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4555{
4556 /* If the management interface is not enabled, then power down */
4557 if (!(hw->mac.ops.check_mng_mode(hw) ||
4558 hw->phy.ops.check_reset_block(hw)))
4559 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004560}
4561
4562/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004563 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4564 * @hw: pointer to the HW structure
4565 *
4566 * Clears hardware counters specific to the silicon family and calls
4567 * clear_hw_cntrs_generic to clear all general purpose counters.
4568 **/
4569static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4570{
Bruce Allana4f58f52009-06-02 11:29:18 +00004571 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004572 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004573
4574 e1000e_clear_hw_cntrs_base(hw);
4575
Bruce Allan99673d92009-11-20 23:27:21 +00004576 er32(ALGNERRC);
4577 er32(RXERRC);
4578 er32(TNCRS);
4579 er32(CEXTERR);
4580 er32(TSCTC);
4581 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004582
Bruce Allan99673d92009-11-20 23:27:21 +00004583 er32(MGTPRC);
4584 er32(MGTPDC);
4585 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004586
Bruce Allan99673d92009-11-20 23:27:21 +00004587 er32(IAC);
4588 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004589
Bruce Allana4f58f52009-06-02 11:29:18 +00004590 /* Clear PHY statistics registers */
4591 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004592 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004593 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004594 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004595 ret_val = hw->phy.ops.acquire(hw);
4596 if (ret_val)
4597 return;
4598 ret_val = hw->phy.ops.set_page(hw,
4599 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4600 if (ret_val)
4601 goto release;
4602 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4603 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4604 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4605 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4606 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4607 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4608 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4609 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4610 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4611 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4612 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4613 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4614 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4615 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4616release:
4617 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004618 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004619}
4620
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004621static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004622 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004623 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004624 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004625 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4626 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004627 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004628 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004629 /* led_on dependent on mac type */
4630 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004631 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004632 .reset_hw = e1000_reset_hw_ich8lan,
4633 .init_hw = e1000_init_hw_ich8lan,
4634 .setup_link = e1000_setup_link_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004635 .setup_physical_interface = e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004636 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004637 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004638 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004639};
4640
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004641static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004642 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004643 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004644 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004645 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004646 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004647 .read_reg = e1000e_read_phy_reg_igp,
4648 .release = e1000_release_swflag_ich8lan,
4649 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004650 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4651 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004652 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004653};
4654
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004655static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004656 .acquire = e1000_acquire_nvm_ich8lan,
Bruce Allan55c5f552013-01-12 07:28:24 +00004657 .read = e1000_read_nvm_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004658 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004659 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004660 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004661 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004662 .validate = e1000_validate_nvm_checksum_ich8lan,
4663 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004664};
4665
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004666const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004667 .mac = e1000_ich8lan,
4668 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004669 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004670 | FLAG_HAS_CTRLEXT_ON_LOAD
4671 | FLAG_HAS_AMT
4672 | FLAG_HAS_FLASH
4673 | FLAG_APME_IN_WUC,
4674 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004675 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004676 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004677 .mac_ops = &ich8_mac_ops,
4678 .phy_ops = &ich8_phy_ops,
4679 .nvm_ops = &ich8_nvm_ops,
4680};
4681
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004682const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004683 .mac = e1000_ich9lan,
4684 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004685 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004686 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004687 | FLAG_HAS_CTRLEXT_ON_LOAD
4688 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004689 | FLAG_HAS_FLASH
4690 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004691 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004692 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004693 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004694 .mac_ops = &ich8_mac_ops,
4695 .phy_ops = &ich8_phy_ops,
4696 .nvm_ops = &ich8_nvm_ops,
4697};
4698
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004699const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004700 .mac = e1000_ich10lan,
4701 .flags = FLAG_HAS_JUMBO_FRAMES
4702 | FLAG_IS_ICH
4703 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004704 | FLAG_HAS_CTRLEXT_ON_LOAD
4705 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004706 | FLAG_HAS_FLASH
4707 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004708 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004709 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004710 .get_variants = e1000_get_variants_ich8lan,
4711 .mac_ops = &ich8_mac_ops,
4712 .phy_ops = &ich8_phy_ops,
4713 .nvm_ops = &ich8_nvm_ops,
4714};
Bruce Allana4f58f52009-06-02 11:29:18 +00004715
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004716const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004717 .mac = e1000_pchlan,
4718 .flags = FLAG_IS_ICH
4719 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004720 | FLAG_HAS_CTRLEXT_ON_LOAD
4721 | FLAG_HAS_AMT
4722 | FLAG_HAS_FLASH
4723 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004724 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004725 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004726 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004727 .pba = 26,
4728 .max_hw_frame_size = 4096,
4729 .get_variants = e1000_get_variants_ich8lan,
4730 .mac_ops = &ich8_mac_ops,
4731 .phy_ops = &ich8_phy_ops,
4732 .nvm_ops = &ich8_nvm_ops,
4733};
Bruce Alland3738bb2010-06-16 13:27:28 +00004734
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004735const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004736 .mac = e1000_pch2lan,
4737 .flags = FLAG_IS_ICH
4738 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004739 | FLAG_HAS_HW_TIMESTAMP
Bruce Alland3738bb2010-06-16 13:27:28 +00004740 | FLAG_HAS_CTRLEXT_ON_LOAD
4741 | FLAG_HAS_AMT
4742 | FLAG_HAS_FLASH
4743 | FLAG_HAS_JUMBO_FRAMES
4744 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004745 .flags2 = FLAG2_HAS_PHY_STATS
4746 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004747 .pba = 26,
Bruce Allanc3d2dbf2013-01-09 01:20:46 +00004748 .max_hw_frame_size = 9018,
Bruce Alland3738bb2010-06-16 13:27:28 +00004749 .get_variants = e1000_get_variants_ich8lan,
4750 .mac_ops = &ich8_mac_ops,
4751 .phy_ops = &ich8_phy_ops,
4752 .nvm_ops = &ich8_nvm_ops,
4753};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004754
4755const struct e1000_info e1000_pch_lpt_info = {
4756 .mac = e1000_pch_lpt,
4757 .flags = FLAG_IS_ICH
4758 | FLAG_HAS_WOL
Bruce Allanb67e1912012-12-27 08:32:33 +00004759 | FLAG_HAS_HW_TIMESTAMP
Bruce Allan2fbe4522012-04-19 03:21:47 +00004760 | FLAG_HAS_CTRLEXT_ON_LOAD
4761 | FLAG_HAS_AMT
4762 | FLAG_HAS_FLASH
4763 | FLAG_HAS_JUMBO_FRAMES
4764 | FLAG_APME_IN_WUC,
4765 .flags2 = FLAG2_HAS_PHY_STATS
4766 | FLAG2_HAS_EEE,
4767 .pba = 26,
Bruce Allaned1a4262013-01-04 09:51:36 +00004768 .max_hw_frame_size = 9018,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004769 .get_variants = e1000_get_variants_ich8lan,
4770 .mac_ops = &ich8_mac_ops,
4771 .phy_ops = &ich8_phy_ops,
4772 .nvm_ops = &ich8_nvm_ops,
4773};