]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/net/ethernet/intel/e1000e/ich8lan.c
e1000e: cleanup: remove unnecessary function prototypes
[mirror_ubuntu-hirsute-kernel.git] / drivers / net / ethernet / intel / e1000e / ich8lan.c
CommitLineData
bc7f75fa
AK
1/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
bf67044b 4 Copyright(c) 1999 - 2013 Intel Corporation.
bc7f75fa
AK
5
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
e921eb1a 29/* 82562G 10/100 Network Connection
bc7f75fa
AK
30 * 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
97ac8cae
BA
41 * 82567LM Gigabit Network Connection
42 * 82567LF Gigabit Network Connection
1605927f 43 * 82567V Gigabit Network Connection
97ac8cae
BA
44 * 82567LM-2 Gigabit Network Connection
45 * 82567LF-2 Gigabit Network Connection
46 * 82567V-2 Gigabit Network Connection
f4187b56
BA
47 * 82567LF-3 Gigabit Network Connection
48 * 82567LM-3 Gigabit Network Connection
2f15f9d6 49 * 82567LM-4 Gigabit Network Connection
a4f58f54
BA
50 * 82577LM Gigabit Network Connection
51 * 82577LC Gigabit Network Connection
52 * 82578DM Gigabit Network Connection
53 * 82578DC Gigabit Network Connection
d3738bb8
BA
54 * 82579LM Gigabit Network Connection
55 * 82579V Gigabit Network Connection
bc7f75fa
AK
56 */
57
bc7f75fa
AK
58#include "e1000.h"
59
60#define ICH_FLASH_GFPREG 0x0000
61#define ICH_FLASH_HSFSTS 0x0004
62#define ICH_FLASH_HSFCTL 0x0006
63#define ICH_FLASH_FADDR 0x0008
64#define ICH_FLASH_FDATA0 0x0010
4a770358 65#define ICH_FLASH_PR0 0x0074
bc7f75fa
AK
66
67#define ICH_FLASH_READ_COMMAND_TIMEOUT 500
68#define ICH_FLASH_WRITE_COMMAND_TIMEOUT 500
69#define ICH_FLASH_ERASE_COMMAND_TIMEOUT 3000000
70#define ICH_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
71#define ICH_FLASH_CYCLE_REPEAT_COUNT 10
72
73#define ICH_CYCLE_READ 0
74#define ICH_CYCLE_WRITE 2
75#define ICH_CYCLE_ERASE 3
76
77#define FLASH_GFPREG_BASE_MASK 0x1FFF
78#define FLASH_SECTOR_ADDR_SHIFT 12
79
80#define ICH_FLASH_SEG_SIZE_256 256
81#define ICH_FLASH_SEG_SIZE_4K 4096
82#define ICH_FLASH_SEG_SIZE_8K 8192
83#define ICH_FLASH_SEG_SIZE_64K 65536
84
85
86#define E1000_ICH_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI Reset */
6dfaa769
BA
87/* FW established a valid mode */
88#define E1000_ICH_FWSM_FW_VALID 0x00008000
bc7f75fa
AK
89
90#define E1000_ICH_MNG_IAMT_MODE 0x2
91
92#define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
93 (ID_LED_DEF1_OFF2 << 8) | \
94 (ID_LED_DEF1_ON2 << 4) | \
95 (ID_LED_DEF1_DEF2))
96
97#define E1000_ICH_NVM_SIG_WORD 0x13
98#define E1000_ICH_NVM_SIG_MASK 0xC000
e243455d
BA
99#define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
100#define E1000_ICH_NVM_SIG_VALUE 0x80
bc7f75fa
AK
101
102#define E1000_ICH8_LAN_INIT_TIMEOUT 1500
103
104#define E1000_FEXTNVM_SW_CONFIG 1
105#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
106
62bc813e
BA
107#define E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK 0x0C000000
108#define E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC 0x08000000
109
831bd2e6
BA
110#define E1000_FEXTNVM4_BEACON_DURATION_MASK 0x7
111#define E1000_FEXTNVM4_BEACON_DURATION_8USEC 0x7
112#define E1000_FEXTNVM4_BEACON_DURATION_16USEC 0x3
113
bc7f75fa
AK
114#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
115
116#define E1000_ICH_RAR_ENTRIES 7
69e1e019 117#define E1000_PCH2_RAR_ENTRIES 5 /* RAR[0], SHRA[0-3] */
2fbe4526 118#define E1000_PCH_LPT_RAR_ENTRIES 12 /* RAR[0], SHRA[0-10] */
bc7f75fa
AK
119
120#define PHY_PAGE_SHIFT 5
121#define PHY_REG(page, reg) (((page) << PHY_PAGE_SHIFT) | \
122 ((reg) & MAX_PHY_REG_ADDRESS))
123#define IGP3_KMRN_DIAG PHY_REG(770, 19) /* KMRN Diagnostic */
124#define IGP3_VR_CTRL PHY_REG(776, 18) /* Voltage Regulator Control */
125
126#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002
127#define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK 0x0300
128#define IGP3_VR_CTRL_MODE_SHUTDOWN 0x0200
129
a4f58f54
BA
130#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
131
53ac5a88
BA
132#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
133
2fbe4526
BA
134/* SMBus Control Phy Register */
135#define CV_SMB_CTRL PHY_REG(769, 23)
136#define CV_SMB_CTRL_FORCE_SMBUS 0x0001
137
f523d211
BA
138/* SMBus Address Phy Register */
139#define HV_SMB_ADDR PHY_REG(768, 26)
8395ae83 140#define HV_SMB_ADDR_MASK 0x007F
f523d211
BA
141#define HV_SMB_ADDR_PEC_EN 0x0200
142#define HV_SMB_ADDR_VALID 0x0080
2fbe4526
BA
143#define HV_SMB_ADDR_FREQ_MASK 0x1100
144#define HV_SMB_ADDR_FREQ_LOW_SHIFT 8
145#define HV_SMB_ADDR_FREQ_HIGH_SHIFT 12
f523d211 146
d3738bb8
BA
147/* PHY Power Management Control */
148#define HV_PM_CTRL PHY_REG(770, 17)
36ceeb43 149#define HV_PM_CTRL_PLL_STOP_IN_K1_GIGA 0x100
d3738bb8 150
2fbe4526 151/* Intel Rapid Start Technology Support */
6d7407bf 152#define I217_PROXY_CTRL BM_PHY_REG(BM_WUC_PAGE, 70)
2fbe4526
BA
153#define I217_PROXY_CTRL_AUTO_DISABLE 0x0080
154#define I217_SxCTRL PHY_REG(BM_PORT_CTRL_PAGE, 28)
6d7407bf 155#define I217_SxCTRL_ENABLE_LPI_RESET 0x1000
2fbe4526 156#define I217_CGFREG PHY_REG(772, 29)
6d7407bf 157#define I217_CGFREG_ENABLE_MTA_RESET 0x0002
2fbe4526 158#define I217_MEMPWR PHY_REG(772, 26)
6d7407bf 159#define I217_MEMPWR_DISABLE_SMB_RELEASE 0x0010
1effb45c 160
f523d211
BA
161/* Strapping Option Register - RO */
162#define E1000_STRAP 0x0000C
163#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
164#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
2fbe4526
BA
165#define E1000_STRAP_SMT_FREQ_MASK 0x00003000
166#define E1000_STRAP_SMT_FREQ_SHIFT 12
f523d211 167
fa2ce13c
BA
168/* OEM Bits Phy Register */
169#define HV_OEM_BITS PHY_REG(768, 25)
170#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
f523d211 171#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
fa2ce13c
BA
172#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
173
1d5846b9
BA
174#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
175#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
176
fddaa1af
BA
177/* KMRN Mode Control */
178#define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
179#define HV_KMRN_MDIO_SLOW 0x0400
180
1d2101a7
BA
181/* KMRN FIFO Control and Status */
182#define HV_KMRN_FIFO_CTRLSTA PHY_REG(770, 16)
183#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK 0x7000
184#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT 12
185
bc7f75fa
AK
186/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
187/* Offset 04h HSFSTS */
188union ich8_hws_flash_status {
189 struct ich8_hsfsts {
190 u16 flcdone :1; /* bit 0 Flash Cycle Done */
191 u16 flcerr :1; /* bit 1 Flash Cycle Error */
192 u16 dael :1; /* bit 2 Direct Access error Log */
193 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
194 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
195 u16 reserved1 :2; /* bit 13:6 Reserved */
196 u16 reserved2 :6; /* bit 13:6 Reserved */
197 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
198 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
199 } hsf_status;
200 u16 regval;
201};
202
203/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
204/* Offset 06h FLCTL */
205union ich8_hws_flash_ctrl {
206 struct ich8_hsflctl {
207 u16 flcgo :1; /* 0 Flash Cycle Go */
208 u16 flcycle :2; /* 2:1 Flash Cycle */
209 u16 reserved :5; /* 7:3 Reserved */
210 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
211 u16 flockdn :6; /* 15:10 Reserved */
212 } hsf_ctrl;
213 u16 regval;
214};
215
216/* ICH Flash Region Access Permissions */
217union ich8_hws_flash_regacc {
218 struct ich8_flracc {
219 u32 grra :8; /* 0:7 GbE region Read Access */
220 u32 grwa :8; /* 8:15 GbE region Write Access */
221 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
222 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
223 } hsf_flregacc;
224 u16 regval;
225};
226
4a770358
BA
227/* ICH Flash Protected Region */
228union ich8_flash_protected_range {
229 struct ich8_pr {
230 u32 base:13; /* 0:12 Protected Range Base */
231 u32 reserved1:2; /* 13:14 Reserved */
232 u32 rpe:1; /* 15 Read Protection Enable */
233 u32 limit:13; /* 16:28 Protected Range Limit */
234 u32 reserved2:2; /* 29:30 Reserved */
235 u32 wpe:1; /* 31 Write Protection Enable */
236 } range;
237 u32 regval;
238};
239
bc7f75fa
AK
240static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
241static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
bc7f75fa
AK
242static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
243static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
244 u32 offset, u8 byte);
f4187b56
BA
245static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
246 u8 *data);
bc7f75fa
AK
247static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
248 u16 *data);
249static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
250 u8 size, u16 *data);
bc7f75fa 251static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
a4f58f54
BA
252static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
253static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
254static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
255static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
256static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
257static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
258static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
259static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
fa2ce13c 260static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
17f208de 261static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
f523d211 262static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
1f96012d 263static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
fddaa1af 264static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
eb7700dc
BA
265static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
266static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
69e1e019 267static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
2fbe4526 268static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
831bd2e6 269static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
605c82ba 270static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
bc7f75fa
AK
271
272static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
273{
274 return readw(hw->flash_address + reg);
275}
276
277static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
278{
279 return readl(hw->flash_address + reg);
280}
281
282static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
283{
284 writew(val, hw->flash_address + reg);
285}
286
287static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
288{
289 writel(val, hw->flash_address + reg);
290}
291
292#define er16flash(reg) __er16flash(hw, (reg))
293#define er32flash(reg) __er32flash(hw, (reg))
0e15df49
BA
294#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
295#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
bc7f75fa 296
cb17aab9
BA
297/**
298 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
299 * @hw: pointer to the HW structure
300 *
301 * Test access to the PHY registers by reading the PHY ID registers. If
302 * the PHY ID is already known (e.g. resume path) compare it with known ID,
303 * otherwise assume the read PHY ID is correct if it is valid.
304 *
305 * Assumes the sw/fw/hw semaphore is already acquired.
306 **/
307static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
99730e4c 308{
a52359b5
BA
309 u16 phy_reg = 0;
310 u32 phy_id = 0;
311 s32 ret_val;
312 u16 retry_count;
313
314 for (retry_count = 0; retry_count < 2; retry_count++) {
315 ret_val = e1e_rphy_locked(hw, PHY_ID1, &phy_reg);
316 if (ret_val || (phy_reg == 0xFFFF))
317 continue;
318 phy_id = (u32)(phy_reg << 16);
319
320 ret_val = e1e_rphy_locked(hw, PHY_ID2, &phy_reg);
321 if (ret_val || (phy_reg == 0xFFFF)) {
322 phy_id = 0;
323 continue;
324 }
325 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
326 break;
327 }
cb17aab9
BA
328
329 if (hw->phy.id) {
330 if (hw->phy.id == phy_id)
331 return true;
a52359b5
BA
332 } else if (phy_id) {
333 hw->phy.id = phy_id;
334 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
cb17aab9
BA
335 return true;
336 }
337
e921eb1a 338 /* In case the PHY needs to be in mdio slow mode,
a52359b5
BA
339 * set slow mode and try to get the PHY id again.
340 */
341 hw->phy.ops.release(hw);
342 ret_val = e1000_set_mdio_slow_mode_hv(hw);
343 if (!ret_val)
344 ret_val = e1000e_get_phy_id(hw);
345 hw->phy.ops.acquire(hw);
346
347 return !ret_val;
cb17aab9
BA
348}
349
350/**
351 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
352 * @hw: pointer to the HW structure
353 *
354 * Workarounds/flow necessary for PHY initialization during driver load
355 * and resume paths.
356 **/
357static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
358{
359 u32 mac_reg, fwsm = er32(FWSM);
360 s32 ret_val;
2fbe4526 361 u16 phy_reg;
cb17aab9 362
6e928b72
BA
363 /* Gate automatic PHY configuration by hardware on managed and
364 * non-managed 82579 and newer adapters.
365 */
366 e1000_gate_hw_phy_config_ich8lan(hw, true);
367
cb17aab9
BA
368 ret_val = hw->phy.ops.acquire(hw);
369 if (ret_val) {
370 e_dbg("Failed to initialize PHY flow\n");
6e928b72 371 goto out;
cb17aab9
BA
372 }
373
e921eb1a 374 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
cb17aab9
BA
375 * inaccessible and resetting the PHY is not blocked, toggle the
376 * LANPHYPC Value bit to force the interconnect to PCIe mode.
377 */
378 switch (hw->mac.type) {
2fbe4526
BA
379 case e1000_pch_lpt:
380 if (e1000_phy_is_accessible_pchlan(hw))
381 break;
382
e921eb1a 383 /* Before toggling LANPHYPC, see if PHY is accessible by
2fbe4526
BA
384 * forcing MAC to SMBus mode first.
385 */
386 mac_reg = er32(CTRL_EXT);
387 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
388 ew32(CTRL_EXT, mac_reg);
389
390 /* fall-through */
cb17aab9 391 case e1000_pch2lan:
2fbe4526
BA
392 if (e1000_phy_is_accessible_pchlan(hw)) {
393 if (hw->mac.type == e1000_pch_lpt) {
394 /* Unforce SMBus mode in PHY */
395 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
396 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
397 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
398
399 /* Unforce SMBus mode in MAC */
400 mac_reg = er32(CTRL_EXT);
401 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
402 ew32(CTRL_EXT, mac_reg);
403 }
cb17aab9 404 break;
2fbe4526 405 }
cb17aab9
BA
406
407 /* fall-through */
408 case e1000_pchlan:
409 if ((hw->mac.type == e1000_pchlan) &&
410 (fwsm & E1000_ICH_FWSM_FW_VALID))
411 break;
412
413 if (hw->phy.ops.check_reset_block(hw)) {
414 e_dbg("Required LANPHYPC toggle blocked by ME\n");
415 break;
416 }
417
418 e_dbg("Toggling LANPHYPC\n");
419
420 /* Set Phy Config Counter to 50msec */
421 mac_reg = er32(FEXTNVM3);
422 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
423 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
424 ew32(FEXTNVM3, mac_reg);
425
4e03510b
BA
426 if (hw->mac.type == e1000_pch_lpt) {
427 /* Toggling LANPHYPC brings the PHY out of SMBus mode
428 * So ensure that the MAC is also out of SMBus mode
429 */
430 mac_reg = er32(CTRL_EXT);
431 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
432 ew32(CTRL_EXT, mac_reg);
433 }
434
cb17aab9
BA
435 /* Toggle LANPHYPC Value bit */
436 mac_reg = er32(CTRL);
437 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
438 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
439 ew32(CTRL, mac_reg);
440 e1e_flush();
441 udelay(10);
442 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
443 ew32(CTRL, mac_reg);
444 e1e_flush();
2fbe4526
BA
445 if (hw->mac.type < e1000_pch_lpt) {
446 msleep(50);
447 } else {
448 u16 count = 20;
449 do {
450 usleep_range(5000, 10000);
451 } while (!(er32(CTRL_EXT) &
452 E1000_CTRL_EXT_LPCD) && count--);
453 }
cb17aab9
BA
454 break;
455 default:
456 break;
457 }
458
459 hw->phy.ops.release(hw);
460
e921eb1a 461 /* Reset the PHY before any access to it. Doing so, ensures
cb17aab9
BA
462 * that the PHY is in a known good state before we read/write
463 * PHY registers. The generic reset is sufficient here,
464 * because we haven't determined the PHY type yet.
465 */
466 ret_val = e1000e_phy_hw_reset_generic(hw);
467
6e928b72 468out:
cb17aab9
BA
469 /* Ungate automatic PHY configuration on non-managed 82579 */
470 if ((hw->mac.type == e1000_pch2lan) &&
471 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
472 usleep_range(10000, 20000);
473 e1000_gate_hw_phy_config_ich8lan(hw, false);
474 }
475
476 return ret_val;
99730e4c
BA
477}
478
a4f58f54
BA
479/**
480 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
481 * @hw: pointer to the HW structure
482 *
483 * Initialize family-specific PHY parameters and function pointers.
484 **/
485static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
486{
487 struct e1000_phy_info *phy = &hw->phy;
488 s32 ret_val = 0;
489
490 phy->addr = 1;
491 phy->reset_delay_us = 100;
492
2b6b168d 493 phy->ops.set_page = e1000_set_page_igp;
94d8186a
BA
494 phy->ops.read_reg = e1000_read_phy_reg_hv;
495 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
2b6b168d 496 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
fa2ce13c
BA
497 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
498 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
94d8186a
BA
499 phy->ops.write_reg = e1000_write_phy_reg_hv;
500 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
2b6b168d 501 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
17f208de
BA
502 phy->ops.power_up = e1000_power_up_phy_copper;
503 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
a4f58f54
BA
504 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
505
cb17aab9 506 phy->id = e1000_phy_unknown;
627c8a04 507
cb17aab9
BA
508 ret_val = e1000_init_phy_workarounds_pchlan(hw);
509 if (ret_val)
510 return ret_val;
605c82ba 511
cb17aab9
BA
512 if (phy->id == e1000_phy_unknown)
513 switch (hw->mac.type) {
514 default:
515 ret_val = e1000e_get_phy_id(hw);
516 if (ret_val)
517 return ret_val;
518 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
519 break;
520 /* fall-through */
521 case e1000_pch2lan:
2fbe4526 522 case e1000_pch_lpt:
e921eb1a 523 /* In case the PHY needs to be in mdio slow mode,
cb17aab9
BA
524 * set slow mode and try to get the PHY id again.
525 */
526 ret_val = e1000_set_mdio_slow_mode_hv(hw);
527 if (ret_val)
528 return ret_val;
529 ret_val = e1000e_get_phy_id(hw);
530 if (ret_val)
531 return ret_val;
664dc878 532 break;
cb17aab9 533 }
a4f58f54
BA
534 phy->type = e1000e_get_phy_type_from_id(phy->id);
535
0be84010
BA
536 switch (phy->type) {
537 case e1000_phy_82577:
d3738bb8 538 case e1000_phy_82579:
2fbe4526 539 case e1000_phy_i217:
a4f58f54
BA
540 phy->ops.check_polarity = e1000_check_polarity_82577;
541 phy->ops.force_speed_duplex =
6cc7aaed 542 e1000_phy_force_speed_duplex_82577;
0be84010 543 phy->ops.get_cable_length = e1000_get_cable_length_82577;
94d8186a
BA
544 phy->ops.get_info = e1000_get_phy_info_82577;
545 phy->ops.commit = e1000e_phy_sw_reset;
eab50ffb 546 break;
0be84010
BA
547 case e1000_phy_82578:
548 phy->ops.check_polarity = e1000_check_polarity_m88;
549 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
550 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
551 phy->ops.get_info = e1000e_get_phy_info_m88;
552 break;
553 default:
554 ret_val = -E1000_ERR_PHY;
555 break;
a4f58f54
BA
556 }
557
558 return ret_val;
559}
560
bc7f75fa
AK
561/**
562 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
563 * @hw: pointer to the HW structure
564 *
565 * Initialize family-specific PHY parameters and function pointers.
566 **/
567static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
568{
569 struct e1000_phy_info *phy = &hw->phy;
570 s32 ret_val;
571 u16 i = 0;
572
573 phy->addr = 1;
574 phy->reset_delay_us = 100;
575
17f208de
BA
576 phy->ops.power_up = e1000_power_up_phy_copper;
577 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
578
e921eb1a 579 /* We may need to do this twice - once for IGP and if that fails,
97ac8cae
BA
580 * we'll set BM func pointers and try again
581 */
582 ret_val = e1000e_determine_phy_address(hw);
583 if (ret_val) {
94d8186a
BA
584 phy->ops.write_reg = e1000e_write_phy_reg_bm;
585 phy->ops.read_reg = e1000e_read_phy_reg_bm;
97ac8cae 586 ret_val = e1000e_determine_phy_address(hw);
9b71b419
BA
587 if (ret_val) {
588 e_dbg("Cannot determine PHY addr. Erroring out\n");
97ac8cae 589 return ret_val;
9b71b419 590 }
97ac8cae
BA
591 }
592
bc7f75fa
AK
593 phy->id = 0;
594 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
595 (i++ < 100)) {
1bba4386 596 usleep_range(1000, 2000);
bc7f75fa
AK
597 ret_val = e1000e_get_phy_id(hw);
598 if (ret_val)
599 return ret_val;
600 }
601
602 /* Verify phy id */
603 switch (phy->id) {
604 case IGP03E1000_E_PHY_ID:
605 phy->type = e1000_phy_igp_3;
606 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
94d8186a
BA
607 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
608 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
0be84010
BA
609 phy->ops.get_info = e1000e_get_phy_info_igp;
610 phy->ops.check_polarity = e1000_check_polarity_igp;
611 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
bc7f75fa
AK
612 break;
613 case IFE_E_PHY_ID:
614 case IFE_PLUS_E_PHY_ID:
615 case IFE_C_E_PHY_ID:
616 phy->type = e1000_phy_ife;
617 phy->autoneg_mask = E1000_ALL_NOT_GIG;
0be84010
BA
618 phy->ops.get_info = e1000_get_phy_info_ife;
619 phy->ops.check_polarity = e1000_check_polarity_ife;
620 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
bc7f75fa 621 break;
97ac8cae
BA
622 case BME1000_E_PHY_ID:
623 phy->type = e1000_phy_bm;
624 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
94d8186a
BA
625 phy->ops.read_reg = e1000e_read_phy_reg_bm;
626 phy->ops.write_reg = e1000e_write_phy_reg_bm;
627 phy->ops.commit = e1000e_phy_sw_reset;
0be84010
BA
628 phy->ops.get_info = e1000e_get_phy_info_m88;
629 phy->ops.check_polarity = e1000_check_polarity_m88;
630 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
97ac8cae 631 break;
bc7f75fa
AK
632 default:
633 return -E1000_ERR_PHY;
634 break;
635 }
636
637 return 0;
638}
639
640/**
641 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
642 * @hw: pointer to the HW structure
643 *
644 * Initialize family-specific NVM parameters and function
645 * pointers.
646 **/
647static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
648{
649 struct e1000_nvm_info *nvm = &hw->nvm;
650 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
148675a7 651 u32 gfpreg, sector_base_addr, sector_end_addr;
bc7f75fa
AK
652 u16 i;
653
ad68076e 654 /* Can't read flash registers if the register set isn't mapped. */
bc7f75fa 655 if (!hw->flash_address) {
3bb99fe2 656 e_dbg("ERROR: Flash registers not mapped\n");
bc7f75fa
AK
657 return -E1000_ERR_CONFIG;
658 }
659
660 nvm->type = e1000_nvm_flash_sw;
661
662 gfpreg = er32flash(ICH_FLASH_GFPREG);
663
e921eb1a 664 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
bc7f75fa 665 * Add 1 to sector_end_addr since this sector is included in
ad68076e
BA
666 * the overall size.
667 */
bc7f75fa
AK
668 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
669 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
670
671 /* flash_base_addr is byte-aligned */
672 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
673
e921eb1a 674 /* find total size of the NVM, then cut in half since the total
ad68076e
BA
675 * size represents two separate NVM banks.
676 */
bc7f75fa
AK
677 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
678 << FLASH_SECTOR_ADDR_SHIFT;
679 nvm->flash_bank_size /= 2;
680 /* Adjust to word count */
681 nvm->flash_bank_size /= sizeof(u16);
682
683 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
684
685 /* Clear shadow ram */
686 for (i = 0; i < nvm->word_size; i++) {
564ea9bb 687 dev_spec->shadow_ram[i].modified = false;
bc7f75fa
AK
688 dev_spec->shadow_ram[i].value = 0xFFFF;
689 }
690
691 return 0;
692}
693
694/**
695 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
696 * @hw: pointer to the HW structure
697 *
698 * Initialize family-specific MAC parameters and function
699 * pointers.
700 **/
ec34c170 701static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
bc7f75fa 702{
bc7f75fa
AK
703 struct e1000_mac_info *mac = &hw->mac;
704
705 /* Set media type function pointer */
318a94d6 706 hw->phy.media_type = e1000_media_type_copper;
bc7f75fa
AK
707
708 /* Set mta register count */
709 mac->mta_reg_count = 32;
710 /* Set rar entry count */
711 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
712 if (mac->type == e1000_ich8lan)
713 mac->rar_entry_count--;
a65a4a0d
BA
714 /* FWSM register */
715 mac->has_fwsm = true;
716 /* ARC subsystem not supported */
717 mac->arc_subsystem_valid = false;
f464ba87
BA
718 /* Adaptive IFS supported */
719 mac->adaptive_ifs = true;
bc7f75fa 720
2fbe4526 721 /* LED and other operations */
a4f58f54
BA
722 switch (mac->type) {
723 case e1000_ich8lan:
724 case e1000_ich9lan:
725 case e1000_ich10lan:
eb7700dc
BA
726 /* check management mode */
727 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
a4f58f54 728 /* ID LED init */
d1964eb1 729 mac->ops.id_led_init = e1000e_id_led_init_generic;
dbf80dcb
BA
730 /* blink LED */
731 mac->ops.blink_led = e1000e_blink_led_generic;
a4f58f54
BA
732 /* setup LED */
733 mac->ops.setup_led = e1000e_setup_led_generic;
734 /* cleanup LED */
735 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
736 /* turn on/off LED */
737 mac->ops.led_on = e1000_led_on_ich8lan;
738 mac->ops.led_off = e1000_led_off_ich8lan;
739 break;
d3738bb8 740 case e1000_pch2lan:
69e1e019
BA
741 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
742 mac->ops.rar_set = e1000_rar_set_pch2lan;
743 /* fall-through */
2fbe4526 744 case e1000_pch_lpt:
69e1e019 745 case e1000_pchlan:
eb7700dc
BA
746 /* check management mode */
747 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
a4f58f54
BA
748 /* ID LED init */
749 mac->ops.id_led_init = e1000_id_led_init_pchlan;
750 /* setup LED */
751 mac->ops.setup_led = e1000_setup_led_pchlan;
752 /* cleanup LED */
753 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
754 /* turn on/off LED */
755 mac->ops.led_on = e1000_led_on_pchlan;
756 mac->ops.led_off = e1000_led_off_pchlan;
757 break;
758 default:
759 break;
760 }
761
2fbe4526
BA
762 if (mac->type == e1000_pch_lpt) {
763 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
764 mac->ops.rar_set = e1000_rar_set_pch_lpt;
765 }
766
bc7f75fa
AK
767 /* Enable PCS Lock-loss workaround for ICH8 */
768 if (mac->type == e1000_ich8lan)
564ea9bb 769 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
bc7f75fa
AK
770
771 return 0;
772}
773
4ddc48a9
BA
774/**
775 * __e1000_access_emi_reg_locked - Read/write EMI register
776 * @hw: pointer to the HW structure
777 * @addr: EMI address to program
778 * @data: pointer to value to read/write from/to the EMI address
779 * @read: boolean flag to indicate read or write
780 *
781 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
782 **/
783static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
784 u16 *data, bool read)
785{
786 s32 ret_val = 0;
787
788 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
789 if (ret_val)
790 return ret_val;
791
792 if (read)
793 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
794 else
795 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
796
797 return ret_val;
798}
799
800/**
801 * e1000_read_emi_reg_locked - Read Extended Management Interface register
802 * @hw: pointer to the HW structure
803 * @addr: EMI address to program
804 * @data: value to be read from the EMI address
805 *
806 * Assumes the SW/FW/HW Semaphore is already acquired.
807 **/
203e4151 808s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
4ddc48a9
BA
809{
810 return __e1000_access_emi_reg_locked(hw, addr, data, true);
811}
812
813/**
814 * e1000_write_emi_reg_locked - Write Extended Management Interface register
815 * @hw: pointer to the HW structure
816 * @addr: EMI address to program
817 * @data: value to be written to the EMI address
818 *
819 * Assumes the SW/FW/HW Semaphore is already acquired.
820 **/
821static s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
822{
823 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
824}
825
e52997f9
BA
826/**
827 * e1000_set_eee_pchlan - Enable/disable EEE support
828 * @hw: pointer to the HW structure
829 *
3d4d5755
BA
830 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
831 * the link and the EEE capabilities of the link partner. The LPI Control
832 * register bits will remain set only if/when link is up.
e52997f9
BA
833 **/
834static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
835{
2fbe4526 836 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3d4d5755
BA
837 s32 ret_val;
838 u16 lpi_ctrl;
e52997f9 839
2fbe4526
BA
840 if ((hw->phy.type != e1000_phy_82579) &&
841 (hw->phy.type != e1000_phy_i217))
5015e53a 842 return 0;
e52997f9 843
3d4d5755 844 ret_val = hw->phy.ops.acquire(hw);
e52997f9 845 if (ret_val)
5015e53a 846 return ret_val;
e52997f9 847
3d4d5755 848 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
2fbe4526 849 if (ret_val)
3d4d5755
BA
850 goto release;
851
852 /* Clear bits that enable EEE in various speeds */
853 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
854
855 /* Enable EEE if not disabled by user */
856 if (!dev_spec->eee_disable) {
857 u16 lpa, pcs_status, data;
2fbe4526 858
2fbe4526 859 /* Save off link partner's EEE ability */
3d4d5755
BA
860 switch (hw->phy.type) {
861 case e1000_phy_82579:
862 lpa = I82579_EEE_LP_ABILITY;
863 pcs_status = I82579_EEE_PCS_STATUS;
864 break;
865 case e1000_phy_i217:
866 lpa = I217_EEE_LP_ABILITY;
867 pcs_status = I217_EEE_PCS_STATUS;
868 break;
869 default:
870 ret_val = -E1000_ERR_PHY;
871 goto release;
872 }
873 ret_val = e1000_read_emi_reg_locked(hw, lpa,
4ddc48a9 874 &dev_spec->eee_lp_ability);
2fbe4526
BA
875 if (ret_val)
876 goto release;
2fbe4526 877
3d4d5755
BA
878 /* Enable EEE only for speeds in which the link partner is
879 * EEE capable.
2fbe4526 880 */
3d4d5755
BA
881 if (dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
882 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
883
884 if (dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
885 e1e_rphy_locked(hw, PHY_LP_ABILITY, &data);
886 if (data & NWAY_LPAR_100TX_FD_CAPS)
887 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
888 else
889 /* EEE is not supported in 100Half, so ignore
890 * partner's EEE in 100 ability if full-duplex
891 * is not advertised.
892 */
893 dev_spec->eee_lp_ability &=
894 ~I82579_EEE_100_SUPPORTED;
895 }
896
897 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
898 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
899 if (ret_val)
900 goto release;
2fbe4526
BA
901 }
902
3d4d5755
BA
903 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
904release:
905 hw->phy.ops.release(hw);
906
907 return ret_val;
e52997f9
BA
908}
909
7d3cabbc
BA
910/**
911 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
912 * @hw: pointer to the HW structure
913 *
914 * Checks to see of the link status of the hardware has changed. If a
915 * change in link status has been detected, then we read the PHY registers
916 * to get the current speed/duplex if link exists.
917 **/
918static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
919{
920 struct e1000_mac_info *mac = &hw->mac;
921 s32 ret_val;
922 bool link;
1d2101a7 923 u16 phy_reg;
7d3cabbc 924
e921eb1a 925 /* We only want to go out to the PHY registers to see if Auto-Neg
7d3cabbc
BA
926 * has completed and/or if our link status has changed. The
927 * get_link_status flag is set upon receiving a Link Status
928 * Change or Rx Sequence Error interrupt.
929 */
5015e53a
BA
930 if (!mac->get_link_status)
931 return 0;
7d3cabbc 932
e921eb1a 933 /* First we want to see if the MII Status Register reports
7d3cabbc
BA
934 * link. If so, then we want to get the current speed/duplex
935 * of the PHY.
936 */
937 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
938 if (ret_val)
5015e53a 939 return ret_val;
7d3cabbc 940
1d5846b9
BA
941 if (hw->mac.type == e1000_pchlan) {
942 ret_val = e1000_k1_gig_workaround_hv(hw, link);
943 if (ret_val)
5015e53a 944 return ret_val;
1d5846b9
BA
945 }
946
2fbe4526
BA
947 /* Clear link partner's EEE ability */
948 hw->dev_spec.ich8lan.eee_lp_ability = 0;
949
7d3cabbc 950 if (!link)
5015e53a 951 return 0; /* No link detected */
7d3cabbc
BA
952
953 mac->get_link_status = false;
954
1d2101a7
BA
955 switch (hw->mac.type) {
956 case e1000_pch2lan:
831bd2e6
BA
957 ret_val = e1000_k1_workaround_lv(hw);
958 if (ret_val)
5015e53a 959 return ret_val;
1d2101a7
BA
960 /* fall-thru */
961 case e1000_pchlan:
962 if (hw->phy.type == e1000_phy_82578) {
963 ret_val = e1000_link_stall_workaround_hv(hw);
964 if (ret_val)
5015e53a 965 return ret_val;
1d2101a7
BA
966 }
967
e921eb1a 968 /* Workaround for PCHx parts in half-duplex:
1d2101a7
BA
969 * Set the number of preambles removed from the packet
970 * when it is passed from the PHY to the MAC to prevent
971 * the MAC from misinterpreting the packet type.
972 */
973 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
974 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
975
976 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
977 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
978
979 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
980 break;
981 default:
982 break;
831bd2e6
BA
983 }
984
e921eb1a 985 /* Check if there was DownShift, must be checked
7d3cabbc
BA
986 * immediately after link-up
987 */
988 e1000e_check_downshift(hw);
989
e52997f9
BA
990 /* Enable/Disable EEE after link up */
991 ret_val = e1000_set_eee_pchlan(hw);
992 if (ret_val)
5015e53a 993 return ret_val;
e52997f9 994
e921eb1a 995 /* If we are forcing speed/duplex, then we simply return since
7d3cabbc
BA
996 * we have already determined whether we have link or not.
997 */
5015e53a
BA
998 if (!mac->autoneg)
999 return -E1000_ERR_CONFIG;
7d3cabbc 1000
e921eb1a 1001 /* Auto-Neg is enabled. Auto Speed Detection takes care
7d3cabbc
BA
1002 * of MAC speed/duplex configuration. So we only need to
1003 * configure Collision Distance in the MAC.
1004 */
57cde763 1005 mac->ops.config_collision_dist(hw);
7d3cabbc 1006
e921eb1a 1007 /* Configure Flow Control now that Auto-Neg has completed.
7d3cabbc
BA
1008 * First, we need to restore the desired flow control
1009 * settings because we may have had to re-autoneg with a
1010 * different link partner.
1011 */
1012 ret_val = e1000e_config_fc_after_link_up(hw);
1013 if (ret_val)
3bb99fe2 1014 e_dbg("Error configuring flow control\n");
7d3cabbc 1015
7d3cabbc
BA
1016 return ret_val;
1017}
1018
69e3fd8c 1019static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
bc7f75fa
AK
1020{
1021 struct e1000_hw *hw = &adapter->hw;
1022 s32 rc;
1023
ec34c170 1024 rc = e1000_init_mac_params_ich8lan(hw);
bc7f75fa
AK
1025 if (rc)
1026 return rc;
1027
1028 rc = e1000_init_nvm_params_ich8lan(hw);
1029 if (rc)
1030 return rc;
1031
d3738bb8
BA
1032 switch (hw->mac.type) {
1033 case e1000_ich8lan:
1034 case e1000_ich9lan:
1035 case e1000_ich10lan:
a4f58f54 1036 rc = e1000_init_phy_params_ich8lan(hw);
d3738bb8
BA
1037 break;
1038 case e1000_pchlan:
1039 case e1000_pch2lan:
2fbe4526 1040 case e1000_pch_lpt:
d3738bb8
BA
1041 rc = e1000_init_phy_params_pchlan(hw);
1042 break;
1043 default:
1044 break;
1045 }
bc7f75fa
AK
1046 if (rc)
1047 return rc;
1048
e921eb1a 1049 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
23e4f061
BA
1050 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1051 */
1052 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1053 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1054 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
2adc55c9
BA
1055 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1056 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
dbf80dcb
BA
1057
1058 hw->mac.ops.blink_led = NULL;
2adc55c9
BA
1059 }
1060
bc7f75fa 1061 if ((adapter->hw.mac.type == e1000_ich8lan) &&
462d5994 1062 (adapter->hw.phy.type != e1000_phy_ife))
bc7f75fa
AK
1063 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1064
c6e7f51e
BA
1065 /* Enable workaround for 82579 w/ ME enabled */
1066 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1067 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1068 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1069
5a86f28f
BA
1070 /* Disable EEE by default until IEEE802.3az spec is finalized */
1071 if (adapter->flags2 & FLAG2_HAS_EEE)
1072 adapter->hw.dev_spec.ich8lan.eee_disable = true;
1073
bc7f75fa
AK
1074 return 0;
1075}
1076
717d438d 1077static DEFINE_MUTEX(nvm_mutex);
717d438d 1078
ca15df58
BA
1079/**
1080 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1081 * @hw: pointer to the HW structure
1082 *
1083 * Acquires the mutex for performing NVM operations.
1084 **/
1085static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
1086{
1087 mutex_lock(&nvm_mutex);
1088
1089 return 0;
1090}
1091
1092/**
1093 * e1000_release_nvm_ich8lan - Release NVM mutex
1094 * @hw: pointer to the HW structure
1095 *
1096 * Releases the mutex used while performing NVM operations.
1097 **/
1098static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
1099{
1100 mutex_unlock(&nvm_mutex);
ca15df58
BA
1101}
1102
bc7f75fa
AK
1103/**
1104 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1105 * @hw: pointer to the HW structure
1106 *
ca15df58
BA
1107 * Acquires the software control flag for performing PHY and select
1108 * MAC CSR accesses.
bc7f75fa
AK
1109 **/
1110static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1111{
373a88d7
BA
1112 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1113 s32 ret_val = 0;
bc7f75fa 1114
a90b412c
BA
1115 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1116 &hw->adapter->state)) {
34c9ef8b 1117 e_dbg("contention for Phy access\n");
a90b412c
BA
1118 return -E1000_ERR_PHY;
1119 }
717d438d 1120
bc7f75fa
AK
1121 while (timeout) {
1122 extcnf_ctrl = er32(EXTCNF_CTRL);
373a88d7
BA
1123 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1124 break;
bc7f75fa 1125
373a88d7
BA
1126 mdelay(1);
1127 timeout--;
1128 }
1129
1130 if (!timeout) {
a90b412c 1131 e_dbg("SW has already locked the resource.\n");
373a88d7
BA
1132 ret_val = -E1000_ERR_CONFIG;
1133 goto out;
1134 }
1135
53ac5a88 1136 timeout = SW_FLAG_TIMEOUT;
373a88d7
BA
1137
1138 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1139 ew32(EXTCNF_CTRL, extcnf_ctrl);
1140
1141 while (timeout) {
1142 extcnf_ctrl = er32(EXTCNF_CTRL);
1143 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1144 break;
a4f58f54 1145
bc7f75fa
AK
1146 mdelay(1);
1147 timeout--;
1148 }
1149
1150 if (!timeout) {
434f1392 1151 e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
a90b412c 1152 er32(FWSM), extcnf_ctrl);
2e2e8d53
BA
1153 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1154 ew32(EXTCNF_CTRL, extcnf_ctrl);
373a88d7
BA
1155 ret_val = -E1000_ERR_CONFIG;
1156 goto out;
bc7f75fa
AK
1157 }
1158
373a88d7
BA
1159out:
1160 if (ret_val)
a90b412c 1161 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
373a88d7
BA
1162
1163 return ret_val;
bc7f75fa
AK
1164}
1165
1166/**
1167 * e1000_release_swflag_ich8lan - Release software control flag
1168 * @hw: pointer to the HW structure
1169 *
ca15df58
BA
1170 * Releases the software control flag for performing PHY and select
1171 * MAC CSR accesses.
bc7f75fa
AK
1172 **/
1173static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1174{
1175 u32 extcnf_ctrl;
1176
1177 extcnf_ctrl = er32(EXTCNF_CTRL);
c5caf482
BA
1178
1179 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1180 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1181 ew32(EXTCNF_CTRL, extcnf_ctrl);
1182 } else {
1183 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1184 }
717d438d 1185
a90b412c 1186 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
bc7f75fa
AK
1187}
1188
4662e82b
BA
1189/**
1190 * e1000_check_mng_mode_ich8lan - Checks management mode
1191 * @hw: pointer to the HW structure
1192 *
eb7700dc 1193 * This checks if the adapter has any manageability enabled.
4662e82b
BA
1194 * This is a function pointer entry point only called by read/write
1195 * routines for the PHY and NVM parts.
1196 **/
1197static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1198{
a708dd88
BA
1199 u32 fwsm;
1200
1201 fwsm = er32(FWSM);
eb7700dc
BA
1202 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1203 ((fwsm & E1000_FWSM_MODE_MASK) ==
1204 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1205}
4662e82b 1206
eb7700dc
BA
1207/**
1208 * e1000_check_mng_mode_pchlan - Checks management mode
1209 * @hw: pointer to the HW structure
1210 *
1211 * This checks if the adapter has iAMT enabled.
1212 * This is a function pointer entry point only called by read/write
1213 * routines for the PHY and NVM parts.
1214 **/
1215static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1216{
1217 u32 fwsm;
1218
1219 fwsm = er32(FWSM);
1220 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1221 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
4662e82b
BA
1222}
1223
69e1e019
BA
1224/**
1225 * e1000_rar_set_pch2lan - Set receive address register
1226 * @hw: pointer to the HW structure
1227 * @addr: pointer to the receive address
1228 * @index: receive address array register
1229 *
1230 * Sets the receive address array register at index to the address passed
1231 * in by addr. For 82579, RAR[0] is the base address register that is to
1232 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1233 * Use SHRA[0-3] in place of those reserved for ME.
1234 **/
1235static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1236{
1237 u32 rar_low, rar_high;
1238
e921eb1a 1239 /* HW expects these in little endian so we reverse the byte order
69e1e019
BA
1240 * from network order (big endian) to little endian
1241 */
1242 rar_low = ((u32)addr[0] |
1243 ((u32)addr[1] << 8) |
1244 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1245
1246 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1247
1248 /* If MAC address zero, no need to set the AV bit */
1249 if (rar_low || rar_high)
1250 rar_high |= E1000_RAH_AV;
1251
1252 if (index == 0) {
1253 ew32(RAL(index), rar_low);
1254 e1e_flush();
1255 ew32(RAH(index), rar_high);
1256 e1e_flush();
1257 return;
1258 }
1259
1260 if (index < hw->mac.rar_entry_count) {
1261 s32 ret_val;
1262
1263 ret_val = e1000_acquire_swflag_ich8lan(hw);
1264 if (ret_val)
1265 goto out;
1266
1267 ew32(SHRAL(index - 1), rar_low);
1268 e1e_flush();
1269 ew32(SHRAH(index - 1), rar_high);
1270 e1e_flush();
1271
1272 e1000_release_swflag_ich8lan(hw);
1273
1274 /* verify the register updates */
1275 if ((er32(SHRAL(index - 1)) == rar_low) &&
1276 (er32(SHRAH(index - 1)) == rar_high))
1277 return;
1278
1279 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1280 (index - 1), er32(FWSM));
1281 }
1282
1283out:
1284 e_dbg("Failed to write receive address at index %d\n", index);
1285}
1286
2fbe4526
BA
1287/**
1288 * e1000_rar_set_pch_lpt - Set receive address registers
1289 * @hw: pointer to the HW structure
1290 * @addr: pointer to the receive address
1291 * @index: receive address array register
1292 *
1293 * Sets the receive address register array at index to the address passed
1294 * in by addr. For LPT, RAR[0] is the base address register that is to
1295 * contain the MAC address. SHRA[0-10] are the shared receive address
1296 * registers that are shared between the Host and manageability engine (ME).
1297 **/
1298static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1299{
1300 u32 rar_low, rar_high;
1301 u32 wlock_mac;
1302
e921eb1a 1303 /* HW expects these in little endian so we reverse the byte order
2fbe4526
BA
1304 * from network order (big endian) to little endian
1305 */
1306 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1307 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1308
1309 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1310
1311 /* If MAC address zero, no need to set the AV bit */
1312 if (rar_low || rar_high)
1313 rar_high |= E1000_RAH_AV;
1314
1315 if (index == 0) {
1316 ew32(RAL(index), rar_low);
1317 e1e_flush();
1318 ew32(RAH(index), rar_high);
1319 e1e_flush();
1320 return;
1321 }
1322
e921eb1a 1323 /* The manageability engine (ME) can lock certain SHRAR registers that
2fbe4526
BA
1324 * it is using - those registers are unavailable for use.
1325 */
1326 if (index < hw->mac.rar_entry_count) {
1327 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1328 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1329
1330 /* Check if all SHRAR registers are locked */
1331 if (wlock_mac == 1)
1332 goto out;
1333
1334 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1335 s32 ret_val;
1336
1337 ret_val = e1000_acquire_swflag_ich8lan(hw);
1338
1339 if (ret_val)
1340 goto out;
1341
1342 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1343 e1e_flush();
1344 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1345 e1e_flush();
1346
1347 e1000_release_swflag_ich8lan(hw);
1348
1349 /* verify the register updates */
1350 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1351 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1352 return;
1353 }
1354 }
1355
1356out:
1357 e_dbg("Failed to write receive address at index %d\n", index);
1358}
1359
bc7f75fa
AK
1360/**
1361 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1362 * @hw: pointer to the HW structure
1363 *
1364 * Checks if firmware is blocking the reset of the PHY.
1365 * This is a function pointer entry point only called by
1366 * reset routines.
1367 **/
1368static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1369{
1370 u32 fwsm;
1371
1372 fwsm = er32(FWSM);
1373
1374 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
1375}
1376
8395ae83
BA
1377/**
1378 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1379 * @hw: pointer to the HW structure
1380 *
1381 * Assumes semaphore already acquired.
1382 *
1383 **/
1384static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1385{
1386 u16 phy_data;
1387 u32 strap = er32(STRAP);
2fbe4526
BA
1388 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1389 E1000_STRAP_SMT_FREQ_SHIFT;
8395ae83
BA
1390 s32 ret_val = 0;
1391
1392 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1393
1394 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1395 if (ret_val)
5015e53a 1396 return ret_val;
8395ae83
BA
1397
1398 phy_data &= ~HV_SMB_ADDR_MASK;
1399 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1400 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
8395ae83 1401
2fbe4526
BA
1402 if (hw->phy.type == e1000_phy_i217) {
1403 /* Restore SMBus frequency */
1404 if (freq--) {
1405 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1406 phy_data |= (freq & (1 << 0)) <<
1407 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1408 phy_data |= (freq & (1 << 1)) <<
1409 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1410 } else {
1411 e_dbg("Unsupported SMB frequency in PHY\n");
1412 }
1413 }
1414
5015e53a 1415 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
8395ae83
BA
1416}
1417
f523d211
BA
1418/**
1419 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1420 * @hw: pointer to the HW structure
1421 *
1422 * SW should configure the LCD from the NVM extended configuration region
1423 * as a workaround for certain parts.
1424 **/
1425static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1426{
1427 struct e1000_phy_info *phy = &hw->phy;
1428 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
8b802a7e 1429 s32 ret_val = 0;
f523d211
BA
1430 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1431
e921eb1a 1432 /* Initialize the PHY from the NVM on ICH platforms. This
f523d211
BA
1433 * is needed due to an issue where the NVM configuration is
1434 * not properly autoloaded after power transitions.
1435 * Therefore, after each PHY reset, we will load the
1436 * configuration data out of the NVM manually.
1437 */
3f0c16e8
BA
1438 switch (hw->mac.type) {
1439 case e1000_ich8lan:
1440 if (phy->type != e1000_phy_igp_3)
1441 return ret_val;
1442
5f3eed6f
BA
1443 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1444 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
3f0c16e8
BA
1445 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1446 break;
1447 }
1448 /* Fall-thru */
1449 case e1000_pchlan:
d3738bb8 1450 case e1000_pch2lan:
2fbe4526 1451 case e1000_pch_lpt:
8b802a7e 1452 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
3f0c16e8
BA
1453 break;
1454 default:
1455 return ret_val;
1456 }
1457
1458 ret_val = hw->phy.ops.acquire(hw);
1459 if (ret_val)
1460 return ret_val;
8b802a7e
BA
1461
1462 data = er32(FEXTNVM);
1463 if (!(data & sw_cfg_mask))
75ce1532 1464 goto release;
f523d211 1465
e921eb1a 1466 /* Make sure HW does not configure LCD from PHY
8b802a7e
BA
1467 * extended configuration before SW configuration
1468 */
1469 data = er32(EXTCNF_CTRL);
2fbe4526
BA
1470 if ((hw->mac.type < e1000_pch2lan) &&
1471 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1472 goto release;
8b802a7e
BA
1473
1474 cnf_size = er32(EXTCNF_SIZE);
1475 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1476 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1477 if (!cnf_size)
75ce1532 1478 goto release;
8b802a7e
BA
1479
1480 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1481 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1482
2fbe4526
BA
1483 if (((hw->mac.type == e1000_pchlan) &&
1484 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1485 (hw->mac.type > e1000_pchlan)) {
e921eb1a 1486 /* HW configures the SMBus address and LEDs when the
8b802a7e
BA
1487 * OEM and LCD Write Enable bits are set in the NVM.
1488 * When both NVM bits are cleared, SW will configure
1489 * them instead.
f523d211 1490 */
8395ae83 1491 ret_val = e1000_write_smbus_addr(hw);
8b802a7e 1492 if (ret_val)
75ce1532 1493 goto release;
f523d211 1494
8b802a7e
BA
1495 data = er32(LEDCTL);
1496 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1497 (u16)data);
1498 if (ret_val)
75ce1532 1499 goto release;
8b802a7e 1500 }
f523d211 1501
8b802a7e
BA
1502 /* Configure LCD from extended configuration region. */
1503
1504 /* cnf_base_addr is in DWORD */
1505 word_addr = (u16)(cnf_base_addr << 1);
1506
1507 for (i = 0; i < cnf_size; i++) {
1508 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
1509 &reg_data);
1510 if (ret_val)
75ce1532 1511 goto release;
8b802a7e
BA
1512
1513 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1514 1, &reg_addr);
1515 if (ret_val)
75ce1532 1516 goto release;
8b802a7e
BA
1517
1518 /* Save off the PHY page for future writes. */
1519 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1520 phy_page = reg_data;
1521 continue;
f523d211 1522 }
8b802a7e
BA
1523
1524 reg_addr &= PHY_REG_MASK;
1525 reg_addr |= phy_page;
1526
f1430d69 1527 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
8b802a7e 1528 if (ret_val)
75ce1532 1529 goto release;
f523d211
BA
1530 }
1531
75ce1532 1532release:
94d8186a 1533 hw->phy.ops.release(hw);
f523d211
BA
1534 return ret_val;
1535}
1536
1d5846b9
BA
1537/**
1538 * e1000_k1_gig_workaround_hv - K1 Si workaround
1539 * @hw: pointer to the HW structure
1540 * @link: link up bool flag
1541 *
1542 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1543 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1544 * If link is down, the function will restore the default K1 setting located
1545 * in the NVM.
1546 **/
1547static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1548{
1549 s32 ret_val = 0;
1550 u16 status_reg = 0;
1551 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1552
1553 if (hw->mac.type != e1000_pchlan)
5015e53a 1554 return 0;
1d5846b9
BA
1555
1556 /* Wrap the whole flow with the sw flag */
94d8186a 1557 ret_val = hw->phy.ops.acquire(hw);
1d5846b9 1558 if (ret_val)
5015e53a 1559 return ret_val;
1d5846b9
BA
1560
1561 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1562 if (link) {
1563 if (hw->phy.type == e1000_phy_82578) {
f1430d69
BA
1564 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1565 &status_reg);
1d5846b9
BA
1566 if (ret_val)
1567 goto release;
1568
1569 status_reg &= BM_CS_STATUS_LINK_UP |
1570 BM_CS_STATUS_RESOLVED |
1571 BM_CS_STATUS_SPEED_MASK;
1572
1573 if (status_reg == (BM_CS_STATUS_LINK_UP |
1574 BM_CS_STATUS_RESOLVED |
1575 BM_CS_STATUS_SPEED_1000))
1576 k1_enable = false;
1577 }
1578
1579 if (hw->phy.type == e1000_phy_82577) {
f1430d69 1580 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
1d5846b9
BA
1581 if (ret_val)
1582 goto release;
1583
1584 status_reg &= HV_M_STATUS_LINK_UP |
1585 HV_M_STATUS_AUTONEG_COMPLETE |
1586 HV_M_STATUS_SPEED_MASK;
1587
1588 if (status_reg == (HV_M_STATUS_LINK_UP |
1589 HV_M_STATUS_AUTONEG_COMPLETE |
1590 HV_M_STATUS_SPEED_1000))
1591 k1_enable = false;
1592 }
1593
1594 /* Link stall fix for link up */
f1430d69 1595 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
1d5846b9
BA
1596 if (ret_val)
1597 goto release;
1598
1599 } else {
1600 /* Link stall fix for link down */
f1430d69 1601 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
1d5846b9
BA
1602 if (ret_val)
1603 goto release;
1604 }
1605
1606 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1607
1608release:
94d8186a 1609 hw->phy.ops.release(hw);
5015e53a 1610
1d5846b9
BA
1611 return ret_val;
1612}
1613
1614/**
1615 * e1000_configure_k1_ich8lan - Configure K1 power state
1616 * @hw: pointer to the HW structure
1617 * @enable: K1 state to configure
1618 *
1619 * Configure the K1 power state based on the provided parameter.
1620 * Assumes semaphore already acquired.
1621 *
1622 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1623 **/
bb436b20 1624s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
1d5846b9
BA
1625{
1626 s32 ret_val = 0;
1627 u32 ctrl_reg = 0;
1628 u32 ctrl_ext = 0;
1629 u32 reg = 0;
1630 u16 kmrn_reg = 0;
1631
3d3a1676
BA
1632 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1633 &kmrn_reg);
1d5846b9 1634 if (ret_val)
5015e53a 1635 return ret_val;
1d5846b9
BA
1636
1637 if (k1_enable)
1638 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1639 else
1640 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1641
3d3a1676
BA
1642 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1643 kmrn_reg);
1d5846b9 1644 if (ret_val)
5015e53a 1645 return ret_val;
1d5846b9
BA
1646
1647 udelay(20);
1648 ctrl_ext = er32(CTRL_EXT);
1649 ctrl_reg = er32(CTRL);
1650
1651 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1652 reg |= E1000_CTRL_FRCSPD;
1653 ew32(CTRL, reg);
1654
1655 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
945a5151 1656 e1e_flush();
1d5846b9
BA
1657 udelay(20);
1658 ew32(CTRL, ctrl_reg);
1659 ew32(CTRL_EXT, ctrl_ext);
945a5151 1660 e1e_flush();
1d5846b9
BA
1661 udelay(20);
1662
5015e53a 1663 return 0;
1d5846b9
BA
1664}
1665
f523d211
BA
1666/**
1667 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1668 * @hw: pointer to the HW structure
1669 * @d0_state: boolean if entering d0 or d3 device state
1670 *
1671 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1672 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1673 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1674 **/
1675static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1676{
1677 s32 ret_val = 0;
1678 u32 mac_reg;
1679 u16 oem_reg;
1680
2fbe4526 1681 if (hw->mac.type < e1000_pchlan)
f523d211
BA
1682 return ret_val;
1683
94d8186a 1684 ret_val = hw->phy.ops.acquire(hw);
f523d211
BA
1685 if (ret_val)
1686 return ret_val;
1687
2fbe4526 1688 if (hw->mac.type == e1000_pchlan) {
d3738bb8
BA
1689 mac_reg = er32(EXTCNF_CTRL);
1690 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
75ce1532 1691 goto release;
d3738bb8 1692 }
f523d211
BA
1693
1694 mac_reg = er32(FEXTNVM);
1695 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
75ce1532 1696 goto release;
f523d211
BA
1697
1698 mac_reg = er32(PHY_CTRL);
1699
f1430d69 1700 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
f523d211 1701 if (ret_val)
75ce1532 1702 goto release;
f523d211
BA
1703
1704 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1705
1706 if (d0_state) {
1707 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1708 oem_reg |= HV_OEM_BITS_GBE_DIS;
1709
1710 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1711 oem_reg |= HV_OEM_BITS_LPLU;
1712 } else {
03299e46
BA
1713 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1714 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
f523d211
BA
1715 oem_reg |= HV_OEM_BITS_GBE_DIS;
1716
03299e46
BA
1717 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1718 E1000_PHY_CTRL_NOND0A_LPLU))
f523d211
BA
1719 oem_reg |= HV_OEM_BITS_LPLU;
1720 }
03299e46 1721
92fe1733
BA
1722 /* Set Restart auto-neg to activate the bits */
1723 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1724 !hw->phy.ops.check_reset_block(hw))
1725 oem_reg |= HV_OEM_BITS_RESTART_AN;
1726
f1430d69 1727 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
f523d211 1728
75ce1532 1729release:
94d8186a 1730 hw->phy.ops.release(hw);
f523d211
BA
1731
1732 return ret_val;
1733}
1734
1735
fddaa1af
BA
1736/**
1737 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1738 * @hw: pointer to the HW structure
1739 **/
1740static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1741{
1742 s32 ret_val;
1743 u16 data;
1744
1745 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1746 if (ret_val)
1747 return ret_val;
1748
1749 data |= HV_KMRN_MDIO_SLOW;
1750
1751 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1752
1753 return ret_val;
1754}
1755
a4f58f54
BA
1756/**
1757 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1758 * done after every PHY reset.
1759 **/
1760static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1761{
1762 s32 ret_val = 0;
baf86c9d 1763 u16 phy_data;
a4f58f54
BA
1764
1765 if (hw->mac.type != e1000_pchlan)
5015e53a 1766 return 0;
a4f58f54 1767
fddaa1af
BA
1768 /* Set MDIO slow mode before any other MDIO access */
1769 if (hw->phy.type == e1000_phy_82577) {
1770 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1771 if (ret_val)
5015e53a 1772 return ret_val;
fddaa1af
BA
1773 }
1774
a4f58f54
BA
1775 if (((hw->phy.type == e1000_phy_82577) &&
1776 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1777 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1778 /* Disable generation of early preamble */
1779 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1780 if (ret_val)
1781 return ret_val;
1782
1783 /* Preamble tuning for SSC */
1d2101a7 1784 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
a4f58f54
BA
1785 if (ret_val)
1786 return ret_val;
1787 }
1788
1789 if (hw->phy.type == e1000_phy_82578) {
e921eb1a 1790 /* Return registers to default by doing a soft reset then
a4f58f54
BA
1791 * writing 0x3140 to the control register.
1792 */
1793 if (hw->phy.revision < 2) {
1794 e1000e_phy_sw_reset(hw);
1795 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1796 }
1797 }
1798
1799 /* Select page 0 */
94d8186a 1800 ret_val = hw->phy.ops.acquire(hw);
a4f58f54
BA
1801 if (ret_val)
1802 return ret_val;
1d5846b9 1803
a4f58f54 1804 hw->phy.addr = 1;
1d5846b9 1805 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
baf86c9d 1806 hw->phy.ops.release(hw);
1d5846b9 1807 if (ret_val)
5015e53a 1808 return ret_val;
a4f58f54 1809
e921eb1a 1810 /* Configure the K1 Si workaround during phy reset assuming there is
1d5846b9
BA
1811 * link so that it disables K1 if link is in 1Gbps.
1812 */
1813 ret_val = e1000_k1_gig_workaround_hv(hw, true);
baf86c9d 1814 if (ret_val)
5015e53a 1815 return ret_val;
1d5846b9 1816
baf86c9d
BA
1817 /* Workaround for link disconnects on a busy hub in half duplex */
1818 ret_val = hw->phy.ops.acquire(hw);
1819 if (ret_val)
5015e53a 1820 return ret_val;
f1430d69 1821 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
baf86c9d
BA
1822 if (ret_val)
1823 goto release;
f1430d69 1824 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
651fb102
BA
1825 if (ret_val)
1826 goto release;
1827
1828 /* set MSE higher to enable link to stay up when noise is high */
1829 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
baf86c9d
BA
1830release:
1831 hw->phy.ops.release(hw);
5015e53a 1832
a4f58f54
BA
1833 return ret_val;
1834}
1835
d3738bb8
BA
1836/**
1837 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1838 * @hw: pointer to the HW structure
1839 **/
1840void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1841{
1842 u32 mac_reg;
2b6b168d
BA
1843 u16 i, phy_reg = 0;
1844 s32 ret_val;
1845
1846 ret_val = hw->phy.ops.acquire(hw);
1847 if (ret_val)
1848 return;
1849 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1850 if (ret_val)
1851 goto release;
d3738bb8
BA
1852
1853 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1854 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1855 mac_reg = er32(RAL(i));
2b6b168d
BA
1856 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1857 (u16)(mac_reg & 0xFFFF));
1858 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1859 (u16)((mac_reg >> 16) & 0xFFFF));
1860
d3738bb8 1861 mac_reg = er32(RAH(i));
2b6b168d
BA
1862 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1863 (u16)(mac_reg & 0xFFFF));
1864 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1865 (u16)((mac_reg & E1000_RAH_AV)
1866 >> 16));
d3738bb8 1867 }
2b6b168d
BA
1868
1869 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1870
1871release:
1872 hw->phy.ops.release(hw);
d3738bb8
BA
1873}
1874
d3738bb8
BA
1875/**
1876 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1877 * with 82579 PHY
1878 * @hw: pointer to the HW structure
1879 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1880 **/
1881s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1882{
1883 s32 ret_val = 0;
1884 u16 phy_reg, data;
1885 u32 mac_reg;
1886 u16 i;
1887
2fbe4526 1888 if (hw->mac.type < e1000_pch2lan)
5015e53a 1889 return 0;
d3738bb8
BA
1890
1891 /* disable Rx path while enabling/disabling workaround */
1892 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1893 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1894 if (ret_val)
5015e53a 1895 return ret_val;
d3738bb8
BA
1896
1897 if (enable) {
e921eb1a 1898 /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
d3738bb8
BA
1899 * SHRAL/H) and initial CRC values to the MAC
1900 */
1901 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1902 u8 mac_addr[ETH_ALEN] = {0};
1903 u32 addr_high, addr_low;
1904
1905 addr_high = er32(RAH(i));
1906 if (!(addr_high & E1000_RAH_AV))
1907 continue;
1908 addr_low = er32(RAL(i));
1909 mac_addr[0] = (addr_low & 0xFF);
1910 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1911 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1912 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1913 mac_addr[4] = (addr_high & 0xFF);
1914 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1915
fe46f58f 1916 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
d3738bb8
BA
1917 }
1918
1919 /* Write Rx addresses to the PHY */
1920 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1921
1922 /* Enable jumbo frame workaround in the MAC */
1923 mac_reg = er32(FFLT_DBG);
1924 mac_reg &= ~(1 << 14);
1925 mac_reg |= (7 << 15);
1926 ew32(FFLT_DBG, mac_reg);
1927
1928 mac_reg = er32(RCTL);
1929 mac_reg |= E1000_RCTL_SECRC;
1930 ew32(RCTL, mac_reg);
1931
1932 ret_val = e1000e_read_kmrn_reg(hw,
1933 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1934 &data);
1935 if (ret_val)
5015e53a 1936 return ret_val;
d3738bb8
BA
1937 ret_val = e1000e_write_kmrn_reg(hw,
1938 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1939 data | (1 << 0));
1940 if (ret_val)
5015e53a 1941 return ret_val;
d3738bb8
BA
1942 ret_val = e1000e_read_kmrn_reg(hw,
1943 E1000_KMRNCTRLSTA_HD_CTRL,
1944 &data);
1945 if (ret_val)
5015e53a 1946 return ret_val;
d3738bb8
BA
1947 data &= ~(0xF << 8);
1948 data |= (0xB << 8);
1949 ret_val = e1000e_write_kmrn_reg(hw,
1950 E1000_KMRNCTRLSTA_HD_CTRL,
1951 data);
1952 if (ret_val)
5015e53a 1953 return ret_val;
d3738bb8
BA
1954
1955 /* Enable jumbo frame workaround in the PHY */
d3738bb8
BA
1956 e1e_rphy(hw, PHY_REG(769, 23), &data);
1957 data &= ~(0x7F << 5);
1958 data |= (0x37 << 5);
1959 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1960 if (ret_val)
5015e53a 1961 return ret_val;
d3738bb8
BA
1962 e1e_rphy(hw, PHY_REG(769, 16), &data);
1963 data &= ~(1 << 13);
d3738bb8
BA
1964 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1965 if (ret_val)
5015e53a 1966 return ret_val;
d3738bb8
BA
1967 e1e_rphy(hw, PHY_REG(776, 20), &data);
1968 data &= ~(0x3FF << 2);
1969 data |= (0x1A << 2);
1970 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1971 if (ret_val)
5015e53a 1972 return ret_val;
b64e9dd5 1973 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
d3738bb8 1974 if (ret_val)
5015e53a 1975 return ret_val;
d3738bb8
BA
1976 e1e_rphy(hw, HV_PM_CTRL, &data);
1977 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
1978 if (ret_val)
5015e53a 1979 return ret_val;
d3738bb8
BA
1980 } else {
1981 /* Write MAC register values back to h/w defaults */
1982 mac_reg = er32(FFLT_DBG);
1983 mac_reg &= ~(0xF << 14);
1984 ew32(FFLT_DBG, mac_reg);
1985
1986 mac_reg = er32(RCTL);
1987 mac_reg &= ~E1000_RCTL_SECRC;
a1ce6473 1988 ew32(RCTL, mac_reg);
d3738bb8
BA
1989
1990 ret_val = e1000e_read_kmrn_reg(hw,
1991 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1992 &data);
1993 if (ret_val)
5015e53a 1994 return ret_val;
d3738bb8
BA
1995 ret_val = e1000e_write_kmrn_reg(hw,
1996 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1997 data & ~(1 << 0));
1998 if (ret_val)
5015e53a 1999 return ret_val;
d3738bb8
BA
2000 ret_val = e1000e_read_kmrn_reg(hw,
2001 E1000_KMRNCTRLSTA_HD_CTRL,
2002 &data);
2003 if (ret_val)
5015e53a 2004 return ret_val;
d3738bb8
BA
2005 data &= ~(0xF << 8);
2006 data |= (0xB << 8);
2007 ret_val = e1000e_write_kmrn_reg(hw,
2008 E1000_KMRNCTRLSTA_HD_CTRL,
2009 data);
2010 if (ret_val)
5015e53a 2011 return ret_val;
d3738bb8
BA
2012
2013 /* Write PHY register values back to h/w defaults */
d3738bb8
BA
2014 e1e_rphy(hw, PHY_REG(769, 23), &data);
2015 data &= ~(0x7F << 5);
2016 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2017 if (ret_val)
5015e53a 2018 return ret_val;
d3738bb8 2019 e1e_rphy(hw, PHY_REG(769, 16), &data);
d3738bb8
BA
2020 data |= (1 << 13);
2021 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2022 if (ret_val)
5015e53a 2023 return ret_val;
d3738bb8
BA
2024 e1e_rphy(hw, PHY_REG(776, 20), &data);
2025 data &= ~(0x3FF << 2);
2026 data |= (0x8 << 2);
2027 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2028 if (ret_val)
5015e53a 2029 return ret_val;
d3738bb8
BA
2030 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2031 if (ret_val)
5015e53a 2032 return ret_val;
d3738bb8
BA
2033 e1e_rphy(hw, HV_PM_CTRL, &data);
2034 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2035 if (ret_val)
5015e53a 2036 return ret_val;
d3738bb8
BA
2037 }
2038
2039 /* re-enable Rx path after enabling/disabling workaround */
5015e53a 2040 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
d3738bb8
BA
2041}
2042
2043/**
2044 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2045 * done after every PHY reset.
2046 **/
2047static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2048{
2049 s32 ret_val = 0;
2050
2051 if (hw->mac.type != e1000_pch2lan)
5015e53a 2052 return 0;
d3738bb8
BA
2053
2054 /* Set MDIO slow mode before any other MDIO access */
2055 ret_val = e1000_set_mdio_slow_mode_hv(hw);
8e5ab42d
BA
2056 if (ret_val)
2057 return ret_val;
d3738bb8 2058
4d24136c
BA
2059 ret_val = hw->phy.ops.acquire(hw);
2060 if (ret_val)
5015e53a 2061 return ret_val;
4d24136c 2062 /* set MSE higher to enable link to stay up when noise is high */
4ddc48a9 2063 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
4d24136c
BA
2064 if (ret_val)
2065 goto release;
2066 /* drop link after 5 times MSE threshold was reached */
4ddc48a9 2067 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
4d24136c
BA
2068release:
2069 hw->phy.ops.release(hw);
2070
d3738bb8
BA
2071 return ret_val;
2072}
2073
831bd2e6
BA
2074/**
2075 * e1000_k1_gig_workaround_lv - K1 Si workaround
2076 * @hw: pointer to the HW structure
2077 *
2078 * Workaround to set the K1 beacon duration for 82579 parts
2079 **/
2080static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2081{
2082 s32 ret_val = 0;
2083 u16 status_reg = 0;
2084 u32 mac_reg;
0ed013e2 2085 u16 phy_reg;
831bd2e6
BA
2086
2087 if (hw->mac.type != e1000_pch2lan)
5015e53a 2088 return 0;
831bd2e6
BA
2089
2090 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2091 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2092 if (ret_val)
5015e53a 2093 return ret_val;
831bd2e6
BA
2094
2095 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2096 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2097 mac_reg = er32(FEXTNVM4);
2098 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2099
0ed013e2
BA
2100 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2101 if (ret_val)
5015e53a 2102 return ret_val;
0ed013e2
BA
2103
2104 if (status_reg & HV_M_STATUS_SPEED_1000) {
36ceeb43
BA
2105 u16 pm_phy_reg;
2106
831bd2e6 2107 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
0ed013e2 2108 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
36ceeb43
BA
2109 /* LV 1G Packet drop issue wa */
2110 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2111 if (ret_val)
2112 return ret_val;
2113 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2114 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2115 if (ret_val)
2116 return ret_val;
0ed013e2 2117 } else {
831bd2e6 2118 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
0ed013e2
BA
2119 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2120 }
831bd2e6 2121 ew32(FEXTNVM4, mac_reg);
0ed013e2 2122 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
831bd2e6
BA
2123 }
2124
831bd2e6
BA
2125 return ret_val;
2126}
2127
605c82ba
BA
2128/**
2129 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2130 * @hw: pointer to the HW structure
2131 * @gate: boolean set to true to gate, false to ungate
2132 *
2133 * Gate/ungate the automatic PHY configuration via hardware; perform
2134 * the configuration via software instead.
2135 **/
2136static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2137{
2138 u32 extcnf_ctrl;
2139
2fbe4526 2140 if (hw->mac.type < e1000_pch2lan)
605c82ba
BA
2141 return;
2142
2143 extcnf_ctrl = er32(EXTCNF_CTRL);
2144
2145 if (gate)
2146 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2147 else
2148 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2149
2150 ew32(EXTCNF_CTRL, extcnf_ctrl);
605c82ba
BA
2151}
2152
fc0c7760
BA
2153/**
2154 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2155 * @hw: pointer to the HW structure
2156 *
2157 * Check the appropriate indication the MAC has finished configuring the
2158 * PHY after a software reset.
2159 **/
2160static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2161{
2162 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2163
2164 /* Wait for basic configuration completes before proceeding */
2165 do {
2166 data = er32(STATUS);
2167 data &= E1000_STATUS_LAN_INIT_DONE;
2168 udelay(100);
2169 } while ((!data) && --loop);
2170
e921eb1a 2171 /* If basic configuration is incomplete before the above loop
fc0c7760
BA
2172 * count reaches 0, loading the configuration from NVM will
2173 * leave the PHY in a bad state possibly resulting in no link.
2174 */
2175 if (loop == 0)
3bb99fe2 2176 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
fc0c7760
BA
2177
2178 /* Clear the Init Done bit for the next init event */
2179 data = er32(STATUS);
2180 data &= ~E1000_STATUS_LAN_INIT_DONE;
2181 ew32(STATUS, data);
2182}
2183
bc7f75fa 2184/**
e98cac44 2185 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
bc7f75fa 2186 * @hw: pointer to the HW structure
bc7f75fa 2187 **/
e98cac44 2188static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
bc7f75fa 2189{
f523d211
BA
2190 s32 ret_val = 0;
2191 u16 reg;
bc7f75fa 2192
44abd5c1 2193 if (hw->phy.ops.check_reset_block(hw))
5015e53a 2194 return 0;
fc0c7760 2195
5f3eed6f 2196 /* Allow time for h/w to get to quiescent state after reset */
1bba4386 2197 usleep_range(10000, 20000);
5f3eed6f 2198
fddaa1af 2199 /* Perform any necessary post-reset workarounds */
e98cac44
BA
2200 switch (hw->mac.type) {
2201 case e1000_pchlan:
a4f58f54
BA
2202 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2203 if (ret_val)
5015e53a 2204 return ret_val;
e98cac44 2205 break;
d3738bb8
BA
2206 case e1000_pch2lan:
2207 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2208 if (ret_val)
5015e53a 2209 return ret_val;
d3738bb8 2210 break;
e98cac44
BA
2211 default:
2212 break;
a4f58f54
BA
2213 }
2214
3ebfc7c9
BA
2215 /* Clear the host wakeup bit after lcd reset */
2216 if (hw->mac.type >= e1000_pchlan) {
2217 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2218 reg &= ~BM_WUC_HOST_WU_BIT;
2219 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2220 }
db2932ec 2221
f523d211
BA
2222 /* Configure the LCD with the extended configuration region in NVM */
2223 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2224 if (ret_val)
5015e53a 2225 return ret_val;
bc7f75fa 2226
f523d211 2227 /* Configure the LCD with the OEM bits in NVM */
e98cac44 2228 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
bc7f75fa 2229
1effb45c
BA
2230 if (hw->mac.type == e1000_pch2lan) {
2231 /* Ungate automatic PHY configuration on non-managed 82579 */
2232 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
1bba4386 2233 usleep_range(10000, 20000);
1effb45c
BA
2234 e1000_gate_hw_phy_config_ich8lan(hw, false);
2235 }
2236
2237 /* Set EEE LPI Update Timer to 200usec */
2238 ret_val = hw->phy.ops.acquire(hw);
2239 if (ret_val)
5015e53a 2240 return ret_val;
4ddc48a9
BA
2241 ret_val = e1000_write_emi_reg_locked(hw,
2242 I82579_LPI_UPDATE_TIMER,
2243 0x1387);
1effb45c 2244 hw->phy.ops.release(hw);
605c82ba
BA
2245 }
2246
e98cac44
BA
2247 return ret_val;
2248}
2249
2250/**
2251 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2252 * @hw: pointer to the HW structure
2253 *
2254 * Resets the PHY
2255 * This is a function pointer entry point called by drivers
2256 * or other shared routines.
2257 **/
2258static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2259{
2260 s32 ret_val = 0;
2261
605c82ba
BA
2262 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2263 if ((hw->mac.type == e1000_pch2lan) &&
2264 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2265 e1000_gate_hw_phy_config_ich8lan(hw, true);
2266
e98cac44
BA
2267 ret_val = e1000e_phy_hw_reset_generic(hw);
2268 if (ret_val)
5015e53a 2269 return ret_val;
e98cac44 2270
5015e53a 2271 return e1000_post_phy_reset_ich8lan(hw);
bc7f75fa
AK
2272}
2273
fa2ce13c
BA
2274/**
2275 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2276 * @hw: pointer to the HW structure
2277 * @active: true to enable LPLU, false to disable
2278 *
2279 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2280 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2281 * the phy speed. This function will manually set the LPLU bit and restart
2282 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2283 * since it configures the same bit.
2284 **/
2285static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2286{
2287 s32 ret_val = 0;
2288 u16 oem_reg;
2289
2290 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2291 if (ret_val)
5015e53a 2292 return ret_val;
fa2ce13c
BA
2293
2294 if (active)
2295 oem_reg |= HV_OEM_BITS_LPLU;
2296 else
2297 oem_reg &= ~HV_OEM_BITS_LPLU;
2298
44abd5c1 2299 if (!hw->phy.ops.check_reset_block(hw))
464c85e3
BA
2300 oem_reg |= HV_OEM_BITS_RESTART_AN;
2301
5015e53a 2302 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
fa2ce13c
BA
2303}
2304
bc7f75fa
AK
2305/**
2306 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2307 * @hw: pointer to the HW structure
564ea9bb 2308 * @active: true to enable LPLU, false to disable
bc7f75fa
AK
2309 *
2310 * Sets the LPLU D0 state according to the active flag. When
2311 * activating LPLU this function also disables smart speed
2312 * and vice versa. LPLU will not be activated unless the
2313 * device autonegotiation advertisement meets standards of
2314 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2315 * This is a function pointer entry point only called by
2316 * PHY setup routines.
2317 **/
2318static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2319{
2320 struct e1000_phy_info *phy = &hw->phy;
2321 u32 phy_ctrl;
2322 s32 ret_val = 0;
2323 u16 data;
2324
97ac8cae 2325 if (phy->type == e1000_phy_ife)
82607255 2326 return 0;
bc7f75fa
AK
2327
2328 phy_ctrl = er32(PHY_CTRL);
2329
2330 if (active) {
2331 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2332 ew32(PHY_CTRL, phy_ctrl);
2333
60f1292f
BA
2334 if (phy->type != e1000_phy_igp_3)
2335 return 0;
2336
e921eb1a 2337 /* Call gig speed drop workaround on LPLU before accessing
ad68076e
BA
2338 * any PHY registers
2339 */
60f1292f 2340 if (hw->mac.type == e1000_ich8lan)
bc7f75fa
AK
2341 e1000e_gig_downshift_workaround_ich8lan(hw);
2342
2343 /* When LPLU is enabled, we should disable SmartSpeed */
2344 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
2345 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2346 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2347 if (ret_val)
2348 return ret_val;
2349 } else {
2350 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2351 ew32(PHY_CTRL, phy_ctrl);
2352
60f1292f
BA
2353 if (phy->type != e1000_phy_igp_3)
2354 return 0;
2355
e921eb1a 2356 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
bc7f75fa
AK
2357 * during Dx states where the power conservation is most
2358 * important. During driver activity we should enable
ad68076e
BA
2359 * SmartSpeed, so performance is maintained.
2360 */
bc7f75fa
AK
2361 if (phy->smart_speed == e1000_smart_speed_on) {
2362 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
ad68076e 2363 &data);
bc7f75fa
AK
2364 if (ret_val)
2365 return ret_val;
2366
2367 data |= IGP01E1000_PSCFR_SMART_SPEED;
2368 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
ad68076e 2369 data);
bc7f75fa
AK
2370 if (ret_val)
2371 return ret_val;
2372 } else if (phy->smart_speed == e1000_smart_speed_off) {
2373 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
ad68076e 2374 &data);
bc7f75fa
AK
2375 if (ret_val)
2376 return ret_val;
2377
2378 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2379 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
ad68076e 2380 data);
bc7f75fa
AK
2381 if (ret_val)
2382 return ret_val;
2383 }
2384 }
2385
2386 return 0;
2387}
2388
2389/**
2390 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2391 * @hw: pointer to the HW structure
564ea9bb 2392 * @active: true to enable LPLU, false to disable
bc7f75fa
AK
2393 *
2394 * Sets the LPLU D3 state according to the active flag. When
2395 * activating LPLU this function also disables smart speed
2396 * and vice versa. LPLU will not be activated unless the
2397 * device autonegotiation advertisement meets standards of
2398 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2399 * This is a function pointer entry point only called by
2400 * PHY setup routines.
2401 **/
2402static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2403{
2404 struct e1000_phy_info *phy = &hw->phy;
2405 u32 phy_ctrl;
d7eb3384 2406 s32 ret_val = 0;
bc7f75fa
AK
2407 u16 data;
2408
2409 phy_ctrl = er32(PHY_CTRL);
2410
2411 if (!active) {
2412 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2413 ew32(PHY_CTRL, phy_ctrl);
60f1292f
BA
2414
2415 if (phy->type != e1000_phy_igp_3)
2416 return 0;
2417
e921eb1a 2418 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
bc7f75fa
AK
2419 * during Dx states where the power conservation is most
2420 * important. During driver activity we should enable
ad68076e
BA
2421 * SmartSpeed, so performance is maintained.
2422 */
bc7f75fa 2423 if (phy->smart_speed == e1000_smart_speed_on) {
ad68076e
BA
2424 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2425 &data);
bc7f75fa
AK
2426 if (ret_val)
2427 return ret_val;
2428
2429 data |= IGP01E1000_PSCFR_SMART_SPEED;
ad68076e
BA
2430 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2431 data);
bc7f75fa
AK
2432 if (ret_val)
2433 return ret_val;
2434 } else if (phy->smart_speed == e1000_smart_speed_off) {
ad68076e
BA
2435 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2436 &data);
bc7f75fa
AK
2437 if (ret_val)
2438 return ret_val;
2439
2440 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
ad68076e
BA
2441 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2442 data);
bc7f75fa
AK
2443 if (ret_val)
2444 return ret_val;
2445 }
2446 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2447 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2448 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2449 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2450 ew32(PHY_CTRL, phy_ctrl);
2451
60f1292f
BA
2452 if (phy->type != e1000_phy_igp_3)
2453 return 0;
2454
e921eb1a 2455 /* Call gig speed drop workaround on LPLU before accessing
ad68076e
BA
2456 * any PHY registers
2457 */
60f1292f 2458 if (hw->mac.type == e1000_ich8lan)
bc7f75fa
AK
2459 e1000e_gig_downshift_workaround_ich8lan(hw);
2460
2461 /* When LPLU is enabled, we should disable SmartSpeed */
ad68076e 2462 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
bc7f75fa
AK
2463 if (ret_val)
2464 return ret_val;
2465
2466 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
ad68076e 2467 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
bc7f75fa
AK
2468 }
2469
d7eb3384 2470 return ret_val;
bc7f75fa
AK
2471}
2472
f4187b56
BA
2473/**
2474 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2475 * @hw: pointer to the HW structure
2476 * @bank: pointer to the variable that returns the active bank
2477 *
2478 * Reads signature byte from the NVM using the flash access registers.
e243455d 2479 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
f4187b56
BA
2480 **/
2481static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2482{
e243455d 2483 u32 eecd;
f4187b56 2484 struct e1000_nvm_info *nvm = &hw->nvm;
f4187b56
BA
2485 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2486 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
e243455d 2487 u8 sig_byte = 0;
f71dde6a 2488 s32 ret_val;
f4187b56 2489
e243455d
BA
2490 switch (hw->mac.type) {
2491 case e1000_ich8lan:
2492 case e1000_ich9lan:
2493 eecd = er32(EECD);
2494 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2495 E1000_EECD_SEC1VAL_VALID_MASK) {
2496 if (eecd & E1000_EECD_SEC1VAL)
2497 *bank = 1;
2498 else
2499 *bank = 0;
2500
2501 return 0;
2502 }
434f1392 2503 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
e243455d
BA
2504 /* fall-thru */
2505 default:
2506 /* set bank to 0 in case flash read fails */
2507 *bank = 0;
2508
2509 /* Check bank 0 */
2510 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
2511 &sig_byte);
2512 if (ret_val)
2513 return ret_val;
2514 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2515 E1000_ICH_NVM_SIG_VALUE) {
f4187b56 2516 *bank = 0;
e243455d
BA
2517 return 0;
2518 }
f4187b56 2519
e243455d
BA
2520 /* Check bank 1 */
2521 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
2522 bank1_offset,
2523 &sig_byte);
2524 if (ret_val)
2525 return ret_val;
2526 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2527 E1000_ICH_NVM_SIG_VALUE) {
2528 *bank = 1;
2529 return 0;
f4187b56 2530 }
e243455d 2531
3bb99fe2 2532 e_dbg("ERROR: No valid NVM bank present\n");
e243455d 2533 return -E1000_ERR_NVM;
f4187b56 2534 }
f4187b56
BA
2535}
2536
bc7f75fa
AK
2537/**
2538 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2539 * @hw: pointer to the HW structure
2540 * @offset: The offset (in bytes) of the word(s) to read.
2541 * @words: Size of data to read in words
2542 * @data: Pointer to the word(s) to read at offset.
2543 *
2544 * Reads a word(s) from the NVM using the flash access registers.
2545 **/
2546static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2547 u16 *data)
2548{
2549 struct e1000_nvm_info *nvm = &hw->nvm;
2550 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2551 u32 act_offset;
148675a7 2552 s32 ret_val = 0;
f4187b56 2553 u32 bank = 0;
bc7f75fa
AK
2554 u16 i, word;
2555
2556 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2557 (words == 0)) {
3bb99fe2 2558 e_dbg("nvm parameter(s) out of bounds\n");
ca15df58
BA
2559 ret_val = -E1000_ERR_NVM;
2560 goto out;
bc7f75fa
AK
2561 }
2562
94d8186a 2563 nvm->ops.acquire(hw);
bc7f75fa 2564
f4187b56 2565 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
148675a7 2566 if (ret_val) {
3bb99fe2 2567 e_dbg("Could not detect valid bank, assuming bank 0\n");
148675a7
BA
2568 bank = 0;
2569 }
f4187b56
BA
2570
2571 act_offset = (bank) ? nvm->flash_bank_size : 0;
bc7f75fa
AK
2572 act_offset += offset;
2573
148675a7 2574 ret_val = 0;
bc7f75fa 2575 for (i = 0; i < words; i++) {
b9e06f70 2576 if (dev_spec->shadow_ram[offset+i].modified) {
bc7f75fa
AK
2577 data[i] = dev_spec->shadow_ram[offset+i].value;
2578 } else {
2579 ret_val = e1000_read_flash_word_ich8lan(hw,
2580 act_offset + i,
2581 &word);
2582 if (ret_val)
2583 break;
2584 data[i] = word;
2585 }
2586 }
2587
94d8186a 2588 nvm->ops.release(hw);
bc7f75fa 2589
e243455d
BA
2590out:
2591 if (ret_val)
3bb99fe2 2592 e_dbg("NVM read error: %d\n", ret_val);
e243455d 2593
bc7f75fa
AK
2594 return ret_val;
2595}
2596
2597/**
2598 * e1000_flash_cycle_init_ich8lan - Initialize flash
2599 * @hw: pointer to the HW structure
2600 *
2601 * This function does initial flash setup so that a new read/write/erase cycle
2602 * can be started.
2603 **/
2604static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2605{
2606 union ich8_hws_flash_status hsfsts;
2607 s32 ret_val = -E1000_ERR_NVM;
bc7f75fa
AK
2608
2609 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2610
2611 /* Check if the flash descriptor is valid */
04499ec4 2612 if (!hsfsts.hsf_status.fldesvalid) {
434f1392 2613 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
bc7f75fa
AK
2614 return -E1000_ERR_NVM;
2615 }
2616
2617 /* Clear FCERR and DAEL in hw status by writing 1 */
2618 hsfsts.hsf_status.flcerr = 1;
2619 hsfsts.hsf_status.dael = 1;
2620
2621 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2622
e921eb1a 2623 /* Either we should have a hardware SPI cycle in progress
bc7f75fa
AK
2624 * bit to check against, in order to start a new cycle or
2625 * FDONE bit should be changed in the hardware so that it
489815ce 2626 * is 1 after hardware reset, which can then be used as an
bc7f75fa
AK
2627 * indication whether a cycle is in progress or has been
2628 * completed.
2629 */
2630
04499ec4 2631 if (!hsfsts.hsf_status.flcinprog) {
e921eb1a 2632 /* There is no cycle running at present,
5ff5b664 2633 * so we can start a cycle.
ad68076e
BA
2634 * Begin by setting Flash Cycle Done.
2635 */
bc7f75fa
AK
2636 hsfsts.hsf_status.flcdone = 1;
2637 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2638 ret_val = 0;
2639 } else {
f71dde6a 2640 s32 i;
90da0669 2641
e921eb1a 2642 /* Otherwise poll for sometime so the current
ad68076e
BA
2643 * cycle has a chance to end before giving up.
2644 */
bc7f75fa 2645 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
c8243ee0 2646 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
04499ec4 2647 if (!hsfsts.hsf_status.flcinprog) {
bc7f75fa
AK
2648 ret_val = 0;
2649 break;
2650 }
2651 udelay(1);
2652 }
9e2d7657 2653 if (!ret_val) {
e921eb1a 2654 /* Successful in waiting for previous cycle to timeout,
ad68076e
BA
2655 * now set the Flash Cycle Done.
2656 */
bc7f75fa
AK
2657 hsfsts.hsf_status.flcdone = 1;
2658 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2659 } else {
2c73e1fe 2660 e_dbg("Flash controller busy, cannot get access\n");
bc7f75fa
AK
2661 }
2662 }
2663
2664 return ret_val;
2665}
2666
2667/**
2668 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2669 * @hw: pointer to the HW structure
2670 * @timeout: maximum time to wait for completion
2671 *
2672 * This function starts a flash cycle and waits for its completion.
2673 **/
2674static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2675{
2676 union ich8_hws_flash_ctrl hsflctl;
2677 union ich8_hws_flash_status hsfsts;
bc7f75fa
AK
2678 u32 i = 0;
2679
2680 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2681 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2682 hsflctl.hsf_ctrl.flcgo = 1;
2683 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2684
2685 /* wait till FDONE bit is set to 1 */
2686 do {
2687 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
04499ec4 2688 if (hsfsts.hsf_status.flcdone)
bc7f75fa
AK
2689 break;
2690 udelay(1);
2691 } while (i++ < timeout);
2692
04499ec4 2693 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
bc7f75fa
AK
2694 return 0;
2695
55920b5e 2696 return -E1000_ERR_NVM;
bc7f75fa
AK
2697}
2698
2699/**
2700 * e1000_read_flash_word_ich8lan - Read word from flash
2701 * @hw: pointer to the HW structure
2702 * @offset: offset to data location
2703 * @data: pointer to the location for storing the data
2704 *
2705 * Reads the flash word at offset into data. Offset is converted
2706 * to bytes before read.
2707 **/
2708static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2709 u16 *data)
2710{
2711 /* Must convert offset into bytes. */
2712 offset <<= 1;
2713
2714 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2715}
2716
f4187b56
BA
2717/**
2718 * e1000_read_flash_byte_ich8lan - Read byte from flash
2719 * @hw: pointer to the HW structure
2720 * @offset: The offset of the byte to read.
2721 * @data: Pointer to a byte to store the value read.
2722 *
2723 * Reads a single byte from the NVM using the flash access registers.
2724 **/
2725static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2726 u8 *data)
2727{
2728 s32 ret_val;
2729 u16 word = 0;
2730
2731 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2732 if (ret_val)
2733 return ret_val;
2734
2735 *data = (u8)word;
2736
2737 return 0;
2738}
2739
bc7f75fa
AK
2740/**
2741 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2742 * @hw: pointer to the HW structure
2743 * @offset: The offset (in bytes) of the byte or word to read.
2744 * @size: Size of data to read, 1=byte 2=word
2745 * @data: Pointer to the word to store the value read.
2746 *
2747 * Reads a byte or word from the NVM using the flash access registers.
2748 **/
2749static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2750 u8 size, u16 *data)
2751{
2752 union ich8_hws_flash_status hsfsts;
2753 union ich8_hws_flash_ctrl hsflctl;
2754 u32 flash_linear_addr;
2755 u32 flash_data = 0;
2756 s32 ret_val = -E1000_ERR_NVM;
2757 u8 count = 0;
2758
2759 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2760 return -E1000_ERR_NVM;
2761
2762 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2763 hw->nvm.flash_base_addr;
2764
2765 do {
2766 udelay(1);
2767 /* Steps */
2768 ret_val = e1000_flash_cycle_init_ich8lan(hw);
9e2d7657 2769 if (ret_val)
bc7f75fa
AK
2770 break;
2771
2772 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2773 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2774 hsflctl.hsf_ctrl.fldbcount = size - 1;
2775 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2776 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2777
2778 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2779
2780 ret_val = e1000_flash_cycle_ich8lan(hw,
2781 ICH_FLASH_READ_COMMAND_TIMEOUT);
2782
e921eb1a 2783 /* Check if FCERR is set to 1, if set to 1, clear it
bc7f75fa
AK
2784 * and try the whole sequence a few more times, else
2785 * read in (shift in) the Flash Data0, the order is
ad68076e
BA
2786 * least significant byte first msb to lsb
2787 */
9e2d7657 2788 if (!ret_val) {
bc7f75fa 2789 flash_data = er32flash(ICH_FLASH_FDATA0);
b1cdfead 2790 if (size == 1)
bc7f75fa 2791 *data = (u8)(flash_data & 0x000000FF);
b1cdfead 2792 else if (size == 2)
bc7f75fa 2793 *data = (u16)(flash_data & 0x0000FFFF);
bc7f75fa
AK
2794 break;
2795 } else {
e921eb1a 2796 /* If we've gotten here, then things are probably
bc7f75fa
AK
2797 * completely hosed, but if the error condition is
2798 * detected, it won't hurt to give it another try...
2799 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2800 */
2801 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
04499ec4 2802 if (hsfsts.hsf_status.flcerr) {
bc7f75fa
AK
2803 /* Repeat for some time before giving up. */
2804 continue;
04499ec4 2805 } else if (!hsfsts.hsf_status.flcdone) {
434f1392 2806 e_dbg("Timeout error - flash cycle did not complete.\n");
bc7f75fa
AK
2807 break;
2808 }
2809 }
2810 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2811
2812 return ret_val;
2813}
2814
2815/**
2816 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2817 * @hw: pointer to the HW structure
2818 * @offset: The offset (in bytes) of the word(s) to write.
2819 * @words: Size of data to write in words
2820 * @data: Pointer to the word(s) to write at offset.
2821 *
2822 * Writes a byte or word to the NVM using the flash access registers.
2823 **/
2824static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2825 u16 *data)
2826{
2827 struct e1000_nvm_info *nvm = &hw->nvm;
2828 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
bc7f75fa
AK
2829 u16 i;
2830
2831 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2832 (words == 0)) {
3bb99fe2 2833 e_dbg("nvm parameter(s) out of bounds\n");
bc7f75fa
AK
2834 return -E1000_ERR_NVM;
2835 }
2836
94d8186a 2837 nvm->ops.acquire(hw);
ca15df58 2838
bc7f75fa 2839 for (i = 0; i < words; i++) {
564ea9bb 2840 dev_spec->shadow_ram[offset+i].modified = true;
bc7f75fa
AK
2841 dev_spec->shadow_ram[offset+i].value = data[i];
2842 }
2843
94d8186a 2844 nvm->ops.release(hw);
ca15df58 2845
bc7f75fa
AK
2846 return 0;
2847}
2848
2849/**
2850 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2851 * @hw: pointer to the HW structure
2852 *
2853 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2854 * which writes the checksum to the shadow ram. The changes in the shadow
2855 * ram are then committed to the EEPROM by processing each bank at a time
2856 * checking for the modified bit and writing only the pending changes.
489815ce 2857 * After a successful commit, the shadow ram is cleared and is ready for
bc7f75fa
AK
2858 * future writes.
2859 **/
2860static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2861{
2862 struct e1000_nvm_info *nvm = &hw->nvm;
2863 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
f4187b56 2864 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
bc7f75fa
AK
2865 s32 ret_val;
2866 u16 data;
2867
2868 ret_val = e1000e_update_nvm_checksum_generic(hw);
2869 if (ret_val)
e243455d 2870 goto out;
bc7f75fa
AK
2871
2872 if (nvm->type != e1000_nvm_flash_sw)
e243455d 2873 goto out;
bc7f75fa 2874
94d8186a 2875 nvm->ops.acquire(hw);
bc7f75fa 2876
e921eb1a 2877 /* We're writing to the opposite bank so if we're on bank 1,
bc7f75fa 2878 * write to bank 0 etc. We also need to erase the segment that
ad68076e
BA
2879 * is going to be written
2880 */
f4187b56 2881 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
e243455d 2882 if (ret_val) {
3bb99fe2 2883 e_dbg("Could not detect valid bank, assuming bank 0\n");
148675a7 2884 bank = 0;
e243455d 2885 }
f4187b56
BA
2886
2887 if (bank == 0) {
bc7f75fa
AK
2888 new_bank_offset = nvm->flash_bank_size;
2889 old_bank_offset = 0;
e243455d 2890 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
9c5e209d
BA
2891 if (ret_val)
2892 goto release;
bc7f75fa
AK
2893 } else {
2894 old_bank_offset = nvm->flash_bank_size;
2895 new_bank_offset = 0;
e243455d 2896 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
9c5e209d
BA
2897 if (ret_val)
2898 goto release;
bc7f75fa
AK
2899 }
2900
2901 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
e921eb1a 2902 /* Determine whether to write the value stored
bc7f75fa 2903 * in the other NVM bank or a modified value stored
ad68076e
BA
2904 * in the shadow RAM
2905 */
bc7f75fa
AK
2906 if (dev_spec->shadow_ram[i].modified) {
2907 data = dev_spec->shadow_ram[i].value;
2908 } else {
e243455d
BA
2909 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2910 old_bank_offset,
2911 &data);
2912 if (ret_val)
2913 break;
bc7f75fa
AK
2914 }
2915
e921eb1a 2916 /* If the word is 0x13, then make sure the signature bits
bc7f75fa
AK
2917 * (15:14) are 11b until the commit has completed.
2918 * This will allow us to write 10b which indicates the
2919 * signature is valid. We want to do this after the write
2920 * has completed so that we don't mark the segment valid
ad68076e
BA
2921 * while the write is still in progress
2922 */
bc7f75fa
AK
2923 if (i == E1000_ICH_NVM_SIG_WORD)
2924 data |= E1000_ICH_NVM_SIG_MASK;
2925
2926 /* Convert offset to bytes. */
2927 act_offset = (i + new_bank_offset) << 1;
2928
2929 udelay(100);
2930 /* Write the bytes to the new bank. */
2931 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2932 act_offset,
2933 (u8)data);
2934 if (ret_val)
2935 break;
2936
2937 udelay(100);
2938 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2939 act_offset + 1,
2940 (u8)(data >> 8));
2941 if (ret_val)
2942 break;
2943 }
2944
e921eb1a 2945 /* Don't bother writing the segment valid bits if sector
ad68076e
BA
2946 * programming failed.
2947 */
bc7f75fa 2948 if (ret_val) {
4a770358 2949 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
3bb99fe2 2950 e_dbg("Flash commit failed.\n");
9c5e209d 2951 goto release;
bc7f75fa
AK
2952 }
2953
e921eb1a 2954 /* Finally validate the new segment by setting bit 15:14
bc7f75fa
AK
2955 * to 10b in word 0x13 , this can be done without an
2956 * erase as well since these bits are 11 to start with
ad68076e
BA
2957 * and we need to change bit 14 to 0b
2958 */
bc7f75fa 2959 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
e243455d 2960 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
9c5e209d
BA
2961 if (ret_val)
2962 goto release;
2963
bc7f75fa
AK
2964 data &= 0xBFFF;
2965 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2966 act_offset * 2 + 1,
2967 (u8)(data >> 8));
9c5e209d
BA
2968 if (ret_val)
2969 goto release;
bc7f75fa 2970
e921eb1a 2971 /* And invalidate the previously valid segment by setting
bc7f75fa
AK
2972 * its signature word (0x13) high_byte to 0b. This can be
2973 * done without an erase because flash erase sets all bits
ad68076e
BA
2974 * to 1's. We can write 1's to 0's without an erase
2975 */
bc7f75fa
AK
2976 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2977 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
9c5e209d
BA
2978 if (ret_val)
2979 goto release;
bc7f75fa
AK
2980
2981 /* Great! Everything worked, we can now clear the cached entries. */
2982 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
564ea9bb 2983 dev_spec->shadow_ram[i].modified = false;
bc7f75fa
AK
2984 dev_spec->shadow_ram[i].value = 0xFFFF;
2985 }
2986
9c5e209d 2987release:
94d8186a 2988 nvm->ops.release(hw);
bc7f75fa 2989
e921eb1a 2990 /* Reload the EEPROM, or else modifications will not appear
bc7f75fa
AK
2991 * until after the next adapter reset.
2992 */
9c5e209d 2993 if (!ret_val) {
e85e3639 2994 nvm->ops.reload(hw);
1bba4386 2995 usleep_range(10000, 20000);
9c5e209d 2996 }
bc7f75fa 2997
e243455d
BA
2998out:
2999 if (ret_val)
3bb99fe2 3000 e_dbg("NVM update error: %d\n", ret_val);
e243455d 3001
bc7f75fa
AK
3002 return ret_val;
3003}
3004
3005/**
3006 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3007 * @hw: pointer to the HW structure
3008 *
3009 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3010 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3011 * calculated, in which case we need to calculate the checksum and set bit 6.
3012 **/
3013static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3014{
3015 s32 ret_val;
3016 u16 data;
1cc7a3a1
BA
3017 u16 word;
3018 u16 valid_csum_mask;
bc7f75fa 3019
1cc7a3a1
BA
3020 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3021 * the checksum needs to be fixed. This bit is an indication that
3022 * the NVM was prepared by OEM software and did not calculate
3023 * the checksum...a likely scenario.
bc7f75fa 3024 */
1cc7a3a1
BA
3025 switch (hw->mac.type) {
3026 case e1000_pch_lpt:
3027 word = NVM_COMPAT;
3028 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3029 break;
3030 default:
3031 word = NVM_FUTURE_INIT_WORD1;
3032 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3033 break;
3034 }
3035
3036 ret_val = e1000_read_nvm(hw, word, 1, &data);
bc7f75fa
AK
3037 if (ret_val)
3038 return ret_val;
3039
1cc7a3a1
BA
3040 if (!(data & valid_csum_mask)) {
3041 data |= valid_csum_mask;
3042 ret_val = e1000_write_nvm(hw, word, 1, &data);
bc7f75fa
AK
3043 if (ret_val)
3044 return ret_val;
3045 ret_val = e1000e_update_nvm_checksum(hw);
3046 if (ret_val)
3047 return ret_val;
3048 }
3049
3050 return e1000e_validate_nvm_checksum_generic(hw);
3051}
3052
4a770358
BA
3053/**
3054 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3055 * @hw: pointer to the HW structure
3056 *
3057 * To prevent malicious write/erase of the NVM, set it to be read-only
3058 * so that the hardware ignores all write/erase cycles of the NVM via
3059 * the flash control registers. The shadow-ram copy of the NVM will
3060 * still be updated, however any updates to this copy will not stick
3061 * across driver reloads.
3062 **/
3063void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3064{
ca15df58 3065 struct e1000_nvm_info *nvm = &hw->nvm;
4a770358
BA
3066 union ich8_flash_protected_range pr0;
3067 union ich8_hws_flash_status hsfsts;
3068 u32 gfpreg;
4a770358 3069
94d8186a 3070 nvm->ops.acquire(hw);
4a770358
BA
3071
3072 gfpreg = er32flash(ICH_FLASH_GFPREG);
3073
3074 /* Write-protect GbE Sector of NVM */
3075 pr0.regval = er32flash(ICH_FLASH_PR0);
3076 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3077 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3078 pr0.range.wpe = true;
3079 ew32flash(ICH_FLASH_PR0, pr0.regval);
3080
e921eb1a 3081 /* Lock down a subset of GbE Flash Control Registers, e.g.
4a770358
BA
3082 * PR0 to prevent the write-protection from being lifted.
3083 * Once FLOCKDN is set, the registers protected by it cannot
3084 * be written until FLOCKDN is cleared by a hardware reset.
3085 */
3086 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3087 hsfsts.hsf_status.flockdn = true;
3088 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3089
94d8186a 3090 nvm->ops.release(hw);
4a770358
BA
3091}
3092
bc7f75fa
AK
3093/**
3094 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3095 * @hw: pointer to the HW structure
3096 * @offset: The offset (in bytes) of the byte/word to read.
3097 * @size: Size of data to read, 1=byte 2=word
3098 * @data: The byte(s) to write to the NVM.
3099 *
3100 * Writes one/two bytes to the NVM using the flash access registers.
3101 **/
3102static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3103 u8 size, u16 data)
3104{
3105 union ich8_hws_flash_status hsfsts;
3106 union ich8_hws_flash_ctrl hsflctl;
3107 u32 flash_linear_addr;
3108 u32 flash_data = 0;
3109 s32 ret_val;
3110 u8 count = 0;
3111
3112 if (size < 1 || size > 2 || data > size * 0xff ||
3113 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3114 return -E1000_ERR_NVM;
3115
3116 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3117 hw->nvm.flash_base_addr;
3118
3119 do {
3120 udelay(1);
3121 /* Steps */
3122 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3123 if (ret_val)
3124 break;
3125
3126 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3127 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
3128 hsflctl.hsf_ctrl.fldbcount = size -1;
3129 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3130 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3131
3132 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3133
3134 if (size == 1)
3135 flash_data = (u32)data & 0x00FF;
3136 else
3137 flash_data = (u32)data;
3138
3139 ew32flash(ICH_FLASH_FDATA0, flash_data);
3140
e921eb1a 3141 /* check if FCERR is set to 1 , if set to 1, clear it
ad68076e
BA
3142 * and try the whole sequence a few more times else done
3143 */
bc7f75fa
AK
3144 ret_val = e1000_flash_cycle_ich8lan(hw,
3145 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
3146 if (!ret_val)
3147 break;
3148
e921eb1a 3149 /* If we're here, then things are most likely
bc7f75fa
AK
3150 * completely hosed, but if the error condition
3151 * is detected, it won't hurt to give it another
3152 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3153 */
3154 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
04499ec4 3155 if (hsfsts.hsf_status.flcerr)
bc7f75fa
AK
3156 /* Repeat for some time before giving up. */
3157 continue;
04499ec4 3158 if (!hsfsts.hsf_status.flcdone) {
434f1392 3159 e_dbg("Timeout error - flash cycle did not complete.\n");
bc7f75fa
AK
3160 break;
3161 }
3162 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3163
3164 return ret_val;
3165}
3166
3167/**
3168 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3169 * @hw: pointer to the HW structure
3170 * @offset: The index of the byte to read.
3171 * @data: The byte to write to the NVM.
3172 *
3173 * Writes a single byte to the NVM using the flash access registers.
3174 **/
3175static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3176 u8 data)
3177{
3178 u16 word = (u16)data;
3179
3180 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3181}
3182
3183/**
3184 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3185 * @hw: pointer to the HW structure
3186 * @offset: The offset of the byte to write.
3187 * @byte: The byte to write to the NVM.
3188 *
3189 * Writes a single byte to the NVM using the flash access registers.
3190 * Goes through a retry algorithm before giving up.
3191 **/
3192static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3193 u32 offset, u8 byte)
3194{
3195 s32 ret_val;
3196 u16 program_retries;
3197
3198 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3199 if (!ret_val)
3200 return ret_val;
3201
3202 for (program_retries = 0; program_retries < 100; program_retries++) {
3bb99fe2 3203 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
bc7f75fa
AK
3204 udelay(100);
3205 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3206 if (!ret_val)
3207 break;
3208 }
3209 if (program_retries == 100)
3210 return -E1000_ERR_NVM;
3211
3212 return 0;
3213}
3214
3215/**
3216 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3217 * @hw: pointer to the HW structure
3218 * @bank: 0 for first bank, 1 for second bank, etc.
3219 *
3220 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3221 * bank N is 4096 * N + flash_reg_addr.
3222 **/
3223static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3224{
3225 struct e1000_nvm_info *nvm = &hw->nvm;
3226 union ich8_hws_flash_status hsfsts;
3227 union ich8_hws_flash_ctrl hsflctl;
3228 u32 flash_linear_addr;
3229 /* bank size is in 16bit words - adjust to bytes */
3230 u32 flash_bank_size = nvm->flash_bank_size * 2;
3231 s32 ret_val;
3232 s32 count = 0;
a708dd88 3233 s32 j, iteration, sector_size;
bc7f75fa
AK
3234
3235 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3236
e921eb1a 3237 /* Determine HW Sector size: Read BERASE bits of hw flash status
ad68076e
BA
3238 * register
3239 * 00: The Hw sector is 256 bytes, hence we need to erase 16
bc7f75fa
AK
3240 * consecutive sectors. The start index for the nth Hw sector
3241 * can be calculated as = bank * 4096 + n * 256
3242 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3243 * The start index for the nth Hw sector can be calculated
3244 * as = bank * 4096
3245 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3246 * (ich9 only, otherwise error condition)
3247 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3248 */
3249 switch (hsfsts.hsf_status.berasesz) {
3250 case 0:
3251 /* Hw sector size 256 */
3252 sector_size = ICH_FLASH_SEG_SIZE_256;
3253 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3254 break;
3255 case 1:
3256 sector_size = ICH_FLASH_SEG_SIZE_4K;
28c9195a 3257 iteration = 1;
bc7f75fa
AK
3258 break;
3259 case 2:
148675a7
BA
3260 sector_size = ICH_FLASH_SEG_SIZE_8K;
3261 iteration = 1;
bc7f75fa
AK
3262 break;
3263 case 3:
3264 sector_size = ICH_FLASH_SEG_SIZE_64K;
28c9195a 3265 iteration = 1;
bc7f75fa
AK
3266 break;
3267 default:
3268 return -E1000_ERR_NVM;
3269 }
3270
3271 /* Start with the base address, then add the sector offset. */
3272 flash_linear_addr = hw->nvm.flash_base_addr;
148675a7 3273 flash_linear_addr += (bank) ? flash_bank_size : 0;
bc7f75fa
AK
3274
3275 for (j = 0; j < iteration ; j++) {
3276 do {
3277 /* Steps */
3278 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3279 if (ret_val)
3280 return ret_val;
3281
e921eb1a 3282 /* Write a value 11 (block Erase) in Flash
ad68076e
BA
3283 * Cycle field in hw flash control
3284 */
bc7f75fa
AK
3285 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3286 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3287 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3288
e921eb1a 3289 /* Write the last 24 bits of an index within the
bc7f75fa
AK
3290 * block into Flash Linear address field in Flash
3291 * Address.
3292 */
3293 flash_linear_addr += (j * sector_size);
3294 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3295
3296 ret_val = e1000_flash_cycle_ich8lan(hw,
3297 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
9e2d7657 3298 if (!ret_val)
bc7f75fa
AK
3299 break;
3300
e921eb1a 3301 /* Check if FCERR is set to 1. If 1,
bc7f75fa 3302 * clear it and try the whole sequence
ad68076e
BA
3303 * a few more times else Done
3304 */
bc7f75fa 3305 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
04499ec4 3306 if (hsfsts.hsf_status.flcerr)
ad68076e 3307 /* repeat for some time before giving up */
bc7f75fa 3308 continue;
04499ec4 3309 else if (!hsfsts.hsf_status.flcdone)
bc7f75fa
AK
3310 return ret_val;
3311 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3312 }
3313
3314 return 0;
3315}
3316
3317/**
3318 * e1000_valid_led_default_ich8lan - Set the default LED settings
3319 * @hw: pointer to the HW structure
3320 * @data: Pointer to the LED settings
3321 *
3322 * Reads the LED default settings from the NVM to data. If the NVM LED
3323 * settings is all 0's or F's, set the LED default to a valid LED default
3324 * setting.
3325 **/
3326static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3327{
3328 s32 ret_val;
3329
3330 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3331 if (ret_val) {
3bb99fe2 3332 e_dbg("NVM Read Error\n");
bc7f75fa
AK
3333 return ret_val;
3334 }
3335
3336 if (*data == ID_LED_RESERVED_0000 ||
3337 *data == ID_LED_RESERVED_FFFF)
3338 *data = ID_LED_DEFAULT_ICH8LAN;
3339
3340 return 0;
3341}
3342
a4f58f54
BA
3343/**
3344 * e1000_id_led_init_pchlan - store LED configurations
3345 * @hw: pointer to the HW structure
3346 *
3347 * PCH does not control LEDs via the LEDCTL register, rather it uses
3348 * the PHY LED configuration register.
3349 *
3350 * PCH also does not have an "always on" or "always off" mode which
3351 * complicates the ID feature. Instead of using the "on" mode to indicate
d1964eb1 3352 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
a4f58f54
BA
3353 * use "link_up" mode. The LEDs will still ID on request if there is no
3354 * link based on logic in e1000_led_[on|off]_pchlan().
3355 **/
3356static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3357{
3358 struct e1000_mac_info *mac = &hw->mac;
3359 s32 ret_val;
3360 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3361 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3362 u16 data, i, temp, shift;
3363
3364 /* Get default ID LED modes */
3365 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3366 if (ret_val)
5015e53a 3367 return ret_val;
a4f58f54
BA
3368
3369 mac->ledctl_default = er32(LEDCTL);
3370 mac->ledctl_mode1 = mac->ledctl_default;
3371 mac->ledctl_mode2 = mac->ledctl_default;
3372
3373 for (i = 0; i < 4; i++) {
3374 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3375 shift = (i * 5);
3376 switch (temp) {
3377 case ID_LED_ON1_DEF2:
3378 case ID_LED_ON1_ON2:
3379 case ID_LED_ON1_OFF2:
3380 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3381 mac->ledctl_mode1 |= (ledctl_on << shift);
3382 break;
3383 case ID_LED_OFF1_DEF2:
3384 case ID_LED_OFF1_ON2:
3385 case ID_LED_OFF1_OFF2:
3386 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3387 mac->ledctl_mode1 |= (ledctl_off << shift);
3388 break;
3389 default:
3390 /* Do nothing */
3391 break;
3392 }
3393 switch (temp) {
3394 case ID_LED_DEF1_ON2:
3395 case ID_LED_ON1_ON2:
3396 case ID_LED_OFF1_ON2:
3397 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3398 mac->ledctl_mode2 |= (ledctl_on << shift);
3399 break;
3400 case ID_LED_DEF1_OFF2:
3401 case ID_LED_ON1_OFF2:
3402 case ID_LED_OFF1_OFF2:
3403 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3404 mac->ledctl_mode2 |= (ledctl_off << shift);
3405 break;
3406 default:
3407 /* Do nothing */
3408 break;
3409 }
3410 }
3411
5015e53a 3412 return 0;
a4f58f54
BA
3413}
3414
bc7f75fa
AK
3415/**
3416 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3417 * @hw: pointer to the HW structure
3418 *
3419 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3420 * register, so the the bus width is hard coded.
3421 **/
3422static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3423{
3424 struct e1000_bus_info *bus = &hw->bus;
3425 s32 ret_val;
3426
3427 ret_val = e1000e_get_bus_info_pcie(hw);
3428
e921eb1a 3429 /* ICH devices are "PCI Express"-ish. They have
bc7f75fa
AK
3430 * a configuration space, but do not contain
3431 * PCI Express Capability registers, so bus width
3432 * must be hardcoded.
3433 */
3434 if (bus->width == e1000_bus_width_unknown)
3435 bus->width = e1000_bus_width_pcie_x1;
3436
3437 return ret_val;
3438}
3439
3440/**
3441 * e1000_reset_hw_ich8lan - Reset the hardware
3442 * @hw: pointer to the HW structure
3443 *
3444 * Does a full reset of the hardware which includes a reset of the PHY and
3445 * MAC.
3446 **/
3447static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3448{
1d5846b9 3449 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
62bc813e
BA
3450 u16 kum_cfg;
3451 u32 ctrl, reg;
bc7f75fa
AK
3452 s32 ret_val;
3453
e921eb1a 3454 /* Prevent the PCI-E bus from sticking if there is no TLP connection
bc7f75fa
AK
3455 * on the last TLP read/write transaction when MAC is reset.
3456 */
3457 ret_val = e1000e_disable_pcie_master(hw);
e98cac44 3458 if (ret_val)
3bb99fe2 3459 e_dbg("PCI-E Master disable polling has failed.\n");
bc7f75fa 3460
3bb99fe2 3461 e_dbg("Masking off all interrupts\n");
bc7f75fa
AK
3462 ew32(IMC, 0xffffffff);
3463
e921eb1a 3464 /* Disable the Transmit and Receive units. Then delay to allow
bc7f75fa
AK
3465 * any pending transactions to complete before we hit the MAC
3466 * with the global reset.
3467 */
3468 ew32(RCTL, 0);
3469 ew32(TCTL, E1000_TCTL_PSP);
3470 e1e_flush();
3471
1bba4386 3472 usleep_range(10000, 20000);
bc7f75fa
AK
3473
3474 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3475 if (hw->mac.type == e1000_ich8lan) {
3476 /* Set Tx and Rx buffer allocation to 8k apiece. */
3477 ew32(PBA, E1000_PBA_8K);
3478 /* Set Packet Buffer Size to 16k. */
3479 ew32(PBS, E1000_PBS_16K);
3480 }
3481
1d5846b9 3482 if (hw->mac.type == e1000_pchlan) {
62bc813e
BA
3483 /* Save the NVM K1 bit setting */
3484 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
1d5846b9
BA
3485 if (ret_val)
3486 return ret_val;
3487
62bc813e 3488 if (kum_cfg & E1000_NVM_K1_ENABLE)
1d5846b9
BA
3489 dev_spec->nvm_k1_enabled = true;
3490 else
3491 dev_spec->nvm_k1_enabled = false;
3492 }
3493
bc7f75fa
AK
3494 ctrl = er32(CTRL);
3495
44abd5c1 3496 if (!hw->phy.ops.check_reset_block(hw)) {
e921eb1a 3497 /* Full-chip reset requires MAC and PHY reset at the same
bc7f75fa
AK
3498 * time to make sure the interface between MAC and the
3499 * external PHY is reset.
3500 */
3501 ctrl |= E1000_CTRL_PHY_RST;
605c82ba 3502
e921eb1a 3503 /* Gate automatic PHY configuration by hardware on
605c82ba
BA
3504 * non-managed 82579
3505 */
3506 if ((hw->mac.type == e1000_pch2lan) &&
3507 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3508 e1000_gate_hw_phy_config_ich8lan(hw, true);
bc7f75fa
AK
3509 }
3510 ret_val = e1000_acquire_swflag_ich8lan(hw);
3bb99fe2 3511 e_dbg("Issuing a global reset to ich8lan\n");
bc7f75fa 3512 ew32(CTRL, (ctrl | E1000_CTRL_RST));
945a5151 3513 /* cannot issue a flush here because it hangs the hardware */
bc7f75fa
AK
3514 msleep(20);
3515
62bc813e
BA
3516 /* Set Phy Config Counter to 50msec */
3517 if (hw->mac.type == e1000_pch2lan) {
3518 reg = er32(FEXTNVM3);
3519 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3520 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3521 ew32(FEXTNVM3, reg);
3522 }
3523
fc0c7760 3524 if (!ret_val)
a90b412c 3525 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
37f40239 3526
e98cac44 3527 if (ctrl & E1000_CTRL_PHY_RST) {
fc0c7760 3528 ret_val = hw->phy.ops.get_cfg_done(hw);
e98cac44 3529 if (ret_val)
5015e53a 3530 return ret_val;
fc0c7760 3531
e98cac44 3532 ret_val = e1000_post_phy_reset_ich8lan(hw);
f523d211 3533 if (ret_val)
5015e53a 3534 return ret_val;
f523d211 3535 }
e98cac44 3536
e921eb1a 3537 /* For PCH, this write will make sure that any noise
7d3cabbc
BA
3538 * will be detected as a CRC error and be dropped rather than show up
3539 * as a bad packet to the DMA engine.
3540 */
3541 if (hw->mac.type == e1000_pchlan)
3542 ew32(CRC_OFFSET, 0x65656565);
3543
bc7f75fa 3544 ew32(IMC, 0xffffffff);
dd93f95e 3545 er32(ICR);
bc7f75fa 3546
62bc813e
BA
3547 reg = er32(KABGTXD);
3548 reg |= E1000_KABGTXD_BGSQLBIAS;
3549 ew32(KABGTXD, reg);
bc7f75fa 3550
5015e53a 3551 return 0;
bc7f75fa
AK
3552}
3553
3554/**
3555 * e1000_init_hw_ich8lan - Initialize the hardware
3556 * @hw: pointer to the HW structure
3557 *
3558 * Prepares the hardware for transmit and receive by doing the following:
3559 * - initialize hardware bits
3560 * - initialize LED identification
3561 * - setup receive address registers
3562 * - setup flow control
489815ce 3563 * - setup transmit descriptors
bc7f75fa
AK
3564 * - clear statistics
3565 **/
3566static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3567{
3568 struct e1000_mac_info *mac = &hw->mac;
3569 u32 ctrl_ext, txdctl, snoop;
3570 s32 ret_val;
3571 u16 i;
3572
3573 e1000_initialize_hw_bits_ich8lan(hw);
3574
3575 /* Initialize identification LED */
a4f58f54 3576 ret_val = mac->ops.id_led_init(hw);
de39b752 3577 if (ret_val)
3bb99fe2 3578 e_dbg("Error initializing identification LED\n");
de39b752 3579 /* This is not fatal and we should not stop init due to this */
bc7f75fa
AK
3580
3581 /* Setup the receive address. */
3582 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3583
3584 /* Zero out the Multicast HASH table */
3bb99fe2 3585 e_dbg("Zeroing the MTA\n");
bc7f75fa
AK
3586 for (i = 0; i < mac->mta_reg_count; i++)
3587 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3588
e921eb1a 3589 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
3ebfc7c9 3590 * the ME. Disable wakeup by clearing the host wakeup bit.
fc0c7760
BA
3591 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3592 */
3593 if (hw->phy.type == e1000_phy_82578) {
3ebfc7c9
BA
3594 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3595 i &= ~BM_WUC_HOST_WU_BIT;
3596 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
fc0c7760
BA
3597 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3598 if (ret_val)
3599 return ret_val;
3600 }
3601
bc7f75fa 3602 /* Setup link and flow control */
1a46b40f 3603 ret_val = mac->ops.setup_link(hw);
bc7f75fa
AK
3604
3605 /* Set the transmit descriptor write-back policy for both queues */
e9ec2c0f 3606 txdctl = er32(TXDCTL(0));
bc7f75fa
AK
3607 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3608 E1000_TXDCTL_FULL_TX_DESC_WB;
3609 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3610 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
e9ec2c0f
JK
3611 ew32(TXDCTL(0), txdctl);
3612 txdctl = er32(TXDCTL(1));
bc7f75fa
AK
3613 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3614 E1000_TXDCTL_FULL_TX_DESC_WB;
3615 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3616 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
e9ec2c0f 3617 ew32(TXDCTL(1), txdctl);
bc7f75fa 3618
e921eb1a 3619 /* ICH8 has opposite polarity of no_snoop bits.
ad68076e
BA
3620 * By default, we should use snoop behavior.
3621 */
bc7f75fa
AK
3622 if (mac->type == e1000_ich8lan)
3623 snoop = PCIE_ICH8_SNOOP_ALL;
3624 else
3625 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
3626 e1000e_set_pcie_no_snoop(hw, snoop);
3627
3628 ctrl_ext = er32(CTRL_EXT);
3629 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3630 ew32(CTRL_EXT, ctrl_ext);
3631
e921eb1a 3632 /* Clear all of the statistics registers (clear on read). It is
bc7f75fa
AK
3633 * important that we do this after we have tried to establish link
3634 * because the symbol error count will increment wildly if there
3635 * is no link.
3636 */
3637 e1000_clear_hw_cntrs_ich8lan(hw);
3638
e561a705 3639 return ret_val;
bc7f75fa
AK
3640}
3641/**
3642 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3643 * @hw: pointer to the HW structure
3644 *
3645 * Sets/Clears required hardware bits necessary for correctly setting up the
3646 * hardware for transmit and receive.
3647 **/
3648static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3649{
3650 u32 reg;
3651
3652 /* Extended Device Control */
3653 reg = er32(CTRL_EXT);
3654 reg |= (1 << 22);
a4f58f54
BA
3655 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3656 if (hw->mac.type >= e1000_pchlan)
3657 reg |= E1000_CTRL_EXT_PHYPDEN;
bc7f75fa
AK
3658 ew32(CTRL_EXT, reg);
3659
3660 /* Transmit Descriptor Control 0 */
e9ec2c0f 3661 reg = er32(TXDCTL(0));
bc7f75fa 3662 reg |= (1 << 22);
e9ec2c0f 3663 ew32(TXDCTL(0), reg);
bc7f75fa
AK
3664
3665 /* Transmit Descriptor Control 1 */
e9ec2c0f 3666 reg = er32(TXDCTL(1));
bc7f75fa 3667 reg |= (1 << 22);
e9ec2c0f 3668 ew32(TXDCTL(1), reg);
bc7f75fa
AK
3669
3670 /* Transmit Arbitration Control 0 */
e9ec2c0f 3671 reg = er32(TARC(0));
bc7f75fa
AK
3672 if (hw->mac.type == e1000_ich8lan)
3673 reg |= (1 << 28) | (1 << 29);
3674 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
e9ec2c0f 3675 ew32(TARC(0), reg);
bc7f75fa
AK
3676
3677 /* Transmit Arbitration Control 1 */
e9ec2c0f 3678 reg = er32(TARC(1));
bc7f75fa
AK
3679 if (er32(TCTL) & E1000_TCTL_MULR)
3680 reg &= ~(1 << 28);
3681 else
3682 reg |= (1 << 28);
3683 reg |= (1 << 24) | (1 << 26) | (1 << 30);
e9ec2c0f 3684 ew32(TARC(1), reg);
bc7f75fa
AK
3685
3686 /* Device Status */
3687 if (hw->mac.type == e1000_ich8lan) {
3688 reg = er32(STATUS);
3689 reg &= ~(1 << 31);
3690 ew32(STATUS, reg);
3691 }
a80483d3 3692
e921eb1a 3693 /* work-around descriptor data corruption issue during nfs v2 udp
a80483d3
JB
3694 * traffic, just disable the nfs filtering capability
3695 */
3696 reg = er32(RFCTL);
3697 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
f6bd5577 3698
e921eb1a 3699 /* Disable IPv6 extension header parsing because some malformed
f6bd5577
MV
3700 * IPv6 headers can hang the Rx.
3701 */
3702 if (hw->mac.type == e1000_ich8lan)
3703 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
a80483d3 3704 ew32(RFCTL, reg);
94fb848b
BA
3705
3706 /* Enable ECC on Lynxpoint */
3707 if (hw->mac.type == e1000_pch_lpt) {
3708 reg = er32(PBECCSTS);
3709 reg |= E1000_PBECCSTS_ECC_ENABLE;
3710 ew32(PBECCSTS, reg);
3711
3712 reg = er32(CTRL);
3713 reg |= E1000_CTRL_MEHE;
3714 ew32(CTRL, reg);
3715 }
bc7f75fa
AK
3716}
3717
3718/**
3719 * e1000_setup_link_ich8lan - Setup flow control and link settings
3720 * @hw: pointer to the HW structure
3721 *
3722 * Determines which flow control settings to use, then configures flow
3723 * control. Calls the appropriate media-specific link configuration
3724 * function. Assuming the adapter has a valid link partner, a valid link
3725 * should be established. Assumes the hardware has previously been reset
3726 * and the transmitter and receiver are not enabled.
3727 **/
3728static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3729{
bc7f75fa
AK
3730 s32 ret_val;
3731
44abd5c1 3732 if (hw->phy.ops.check_reset_block(hw))
bc7f75fa
AK
3733 return 0;
3734
e921eb1a 3735 /* ICH parts do not have a word in the NVM to determine
bc7f75fa
AK
3736 * the default flow control setting, so we explicitly
3737 * set it to full.
3738 */
37289d9c
BA
3739 if (hw->fc.requested_mode == e1000_fc_default) {
3740 /* Workaround h/w hang when Tx flow control enabled */
3741 if (hw->mac.type == e1000_pchlan)
3742 hw->fc.requested_mode = e1000_fc_rx_pause;
3743 else
3744 hw->fc.requested_mode = e1000_fc_full;
3745 }
bc7f75fa 3746
e921eb1a 3747 /* Save off the requested flow control mode for use later. Depending
5c48ef3e
BA
3748 * on the link partner's capabilities, we may or may not use this mode.
3749 */
3750 hw->fc.current_mode = hw->fc.requested_mode;
bc7f75fa 3751
3bb99fe2 3752 e_dbg("After fix-ups FlowControl is now = %x\n",
5c48ef3e 3753 hw->fc.current_mode);
bc7f75fa
AK
3754
3755 /* Continue to configure the copper link. */
944ce011 3756 ret_val = hw->mac.ops.setup_physical_interface(hw);
bc7f75fa
AK
3757 if (ret_val)
3758 return ret_val;
3759
318a94d6 3760 ew32(FCTTV, hw->fc.pause_time);
a4f58f54 3761 if ((hw->phy.type == e1000_phy_82578) ||
d3738bb8 3762 (hw->phy.type == e1000_phy_82579) ||
2fbe4526 3763 (hw->phy.type == e1000_phy_i217) ||
a4f58f54 3764 (hw->phy.type == e1000_phy_82577)) {
a305595b
BA
3765 ew32(FCRTV_PCH, hw->fc.refresh_time);
3766
482fed85
BA
3767 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3768 hw->fc.pause_time);
a4f58f54
BA
3769 if (ret_val)
3770 return ret_val;
3771 }
bc7f75fa
AK
3772
3773 return e1000e_set_fc_watermarks(hw);
3774}
3775
3776/**
3777 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3778 * @hw: pointer to the HW structure
3779 *
3780 * Configures the kumeran interface to the PHY to wait the appropriate time
3781 * when polling the PHY, then call the generic setup_copper_link to finish
3782 * configuring the copper link.
3783 **/
3784static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3785{
3786 u32 ctrl;
3787 s32 ret_val;
3788 u16 reg_data;
3789
3790 ctrl = er32(CTRL);
3791 ctrl |= E1000_CTRL_SLU;
3792 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3793 ew32(CTRL, ctrl);
3794
e921eb1a 3795 /* Set the mac to wait the maximum time between each iteration
bc7f75fa 3796 * and increase the max iterations when polling the phy;
ad68076e
BA
3797 * this fixes erroneous timeouts at 10Mbps.
3798 */
07818950 3799 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
bc7f75fa
AK
3800 if (ret_val)
3801 return ret_val;
07818950
BA
3802 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3803 &reg_data);
bc7f75fa
AK
3804 if (ret_val)
3805 return ret_val;
3806 reg_data |= 0x3F;
07818950
BA
3807 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3808 reg_data);
bc7f75fa
AK
3809 if (ret_val)
3810 return ret_val;
3811
a4f58f54
BA
3812 switch (hw->phy.type) {
3813 case e1000_phy_igp_3:
bc7f75fa
AK
3814 ret_val = e1000e_copper_link_setup_igp(hw);
3815 if (ret_val)
3816 return ret_val;
a4f58f54
BA
3817 break;
3818 case e1000_phy_bm:
3819 case e1000_phy_82578:
97ac8cae
BA
3820 ret_val = e1000e_copper_link_setup_m88(hw);
3821 if (ret_val)
3822 return ret_val;
a4f58f54
BA
3823 break;
3824 case e1000_phy_82577:
d3738bb8 3825 case e1000_phy_82579:
2fbe4526 3826 case e1000_phy_i217:
a4f58f54
BA
3827 ret_val = e1000_copper_link_setup_82577(hw);
3828 if (ret_val)
3829 return ret_val;
3830 break;
3831 case e1000_phy_ife:
482fed85 3832 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
97ac8cae
BA
3833 if (ret_val)
3834 return ret_val;
3835
3836 reg_data &= ~IFE_PMC_AUTO_MDIX;
3837
3838 switch (hw->phy.mdix) {
3839 case 1:
3840 reg_data &= ~IFE_PMC_FORCE_MDIX;
3841 break;
3842 case 2:
3843 reg_data |= IFE_PMC_FORCE_MDIX;
3844 break;
3845 case 0:
3846 default:
3847 reg_data |= IFE_PMC_AUTO_MDIX;
3848 break;
3849 }
482fed85 3850 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
97ac8cae
BA
3851 if (ret_val)
3852 return ret_val;
a4f58f54
BA
3853 break;
3854 default:
3855 break;
97ac8cae 3856 }
3fa82936 3857
bc7f75fa
AK
3858 return e1000e_setup_copper_link(hw);
3859}
3860
3861/**
3862 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3863 * @hw: pointer to the HW structure
3864 * @speed: pointer to store current link speed
3865 * @duplex: pointer to store the current link duplex
3866 *
ad68076e 3867 * Calls the generic get_speed_and_duplex to retrieve the current link
bc7f75fa
AK
3868 * information and then calls the Kumeran lock loss workaround for links at
3869 * gigabit speeds.
3870 **/
3871static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3872 u16 *duplex)
3873{
3874 s32 ret_val;
3875
3876 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3877 if (ret_val)
3878 return ret_val;
3879
3880 if ((hw->mac.type == e1000_ich8lan) &&
3881 (hw->phy.type == e1000_phy_igp_3) &&
3882 (*speed == SPEED_1000)) {
3883 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3884 }
3885
3886 return ret_val;
3887}
3888
3889/**
3890 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3891 * @hw: pointer to the HW structure
3892 *
3893 * Work-around for 82566 Kumeran PCS lock loss:
3894 * On link status change (i.e. PCI reset, speed change) and link is up and
3895 * speed is gigabit-
3896 * 0) if workaround is optionally disabled do nothing
3897 * 1) wait 1ms for Kumeran link to come up
3898 * 2) check Kumeran Diagnostic register PCS lock loss bit
3899 * 3) if not set the link is locked (all is good), otherwise...
3900 * 4) reset the PHY
3901 * 5) repeat up to 10 times
3902 * Note: this is only called for IGP3 copper when speed is 1gb.
3903 **/
3904static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3905{
3906 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3907 u32 phy_ctrl;
3908 s32 ret_val;
3909 u16 i, data;
3910 bool link;
3911
3912 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3913 return 0;
3914
e921eb1a 3915 /* Make sure link is up before proceeding. If not just return.
bc7f75fa 3916 * Attempting this while link is negotiating fouled up link
ad68076e
BA
3917 * stability
3918 */
bc7f75fa
AK
3919 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3920 if (!link)
3921 return 0;
3922
3923 for (i = 0; i < 10; i++) {
3924 /* read once to clear */
3925 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3926 if (ret_val)
3927 return ret_val;
3928 /* and again to get new status */
3929 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3930 if (ret_val)
3931 return ret_val;
3932
3933 /* check for PCS lock */
3934 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3935 return 0;
3936
3937 /* Issue PHY reset */
3938 e1000_phy_hw_reset(hw);
3939 mdelay(5);
3940 }
3941 /* Disable GigE link negotiation */
3942 phy_ctrl = er32(PHY_CTRL);
3943 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3944 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3945 ew32(PHY_CTRL, phy_ctrl);
3946
e921eb1a 3947 /* Call gig speed drop workaround on Gig disable before accessing
ad68076e
BA
3948 * any PHY registers
3949 */
bc7f75fa
AK
3950 e1000e_gig_downshift_workaround_ich8lan(hw);
3951
3952 /* unable to acquire PCS lock */
3953 return -E1000_ERR_PHY;
3954}
3955
3956/**
6e3c8075 3957 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
bc7f75fa 3958 * @hw: pointer to the HW structure
489815ce 3959 * @state: boolean value used to set the current Kumeran workaround state
bc7f75fa 3960 *
564ea9bb
BA
3961 * If ICH8, set the current Kumeran workaround state (enabled - true
3962 * /disabled - false).
bc7f75fa
AK
3963 **/
3964void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3965 bool state)
3966{
3967 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3968
3969 if (hw->mac.type != e1000_ich8lan) {
3bb99fe2 3970 e_dbg("Workaround applies to ICH8 only.\n");
bc7f75fa
AK
3971 return;
3972 }
3973
3974 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3975}
3976
3977/**
3978 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3979 * @hw: pointer to the HW structure
3980 *
3981 * Workaround for 82566 power-down on D3 entry:
3982 * 1) disable gigabit link
3983 * 2) write VR power-down enable
3984 * 3) read it back
3985 * Continue if successful, else issue LCD reset and repeat
3986 **/
3987void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3988{
3989 u32 reg;
3990 u16 data;
3991 u8 retry = 0;
3992
3993 if (hw->phy.type != e1000_phy_igp_3)
3994 return;
3995
3996 /* Try the workaround twice (if needed) */
3997 do {
3998 /* Disable link */
3999 reg = er32(PHY_CTRL);
4000 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4001 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4002 ew32(PHY_CTRL, reg);
4003
e921eb1a 4004 /* Call gig speed drop workaround on Gig disable before
ad68076e
BA
4005 * accessing any PHY registers
4006 */
bc7f75fa
AK
4007 if (hw->mac.type == e1000_ich8lan)
4008 e1000e_gig_downshift_workaround_ich8lan(hw);
4009
4010 /* Write VR power-down enable */
4011 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4012 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4013 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4014
4015 /* Read it back and test */
4016 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4017 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4018 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4019 break;
4020
4021 /* Issue PHY reset and repeat at most one more time */
4022 reg = er32(CTRL);
4023 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4024 retry++;
4025 } while (retry);
4026}
4027
4028/**
4029 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4030 * @hw: pointer to the HW structure
4031 *
4032 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
489815ce 4033 * LPLU, Gig disable, MDIC PHY reset):
bc7f75fa
AK
4034 * 1) Set Kumeran Near-end loopback
4035 * 2) Clear Kumeran Near-end loopback
462d5994 4036 * Should only be called for ICH8[m] devices with any 1G Phy.
bc7f75fa
AK
4037 **/
4038void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4039{
4040 s32 ret_val;
4041 u16 reg_data;
4042
462d5994 4043 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
bc7f75fa
AK
4044 return;
4045
4046 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4047 &reg_data);
4048 if (ret_val)
4049 return;
4050 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4051 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4052 reg_data);
4053 if (ret_val)
4054 return;
4055 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
4056 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4057 reg_data);
4058}
4059
97ac8cae 4060/**
99730e4c 4061 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
97ac8cae
BA
4062 * @hw: pointer to the HW structure
4063 *
4064 * During S0 to Sx transition, it is possible the link remains at gig
4065 * instead of negotiating to a lower speed. Before going to Sx, set
c077a906
BA
4066 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4067 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4068 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4069 * needs to be written.
2fbe4526
BA
4070 * Parts that support (and are linked to a partner which support) EEE in
4071 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4072 * than 10Mbps w/o EEE.
97ac8cae 4073 **/
99730e4c 4074void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
97ac8cae 4075{
2fbe4526 4076 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
97ac8cae 4077 u32 phy_ctrl;
8395ae83 4078 s32 ret_val;
97ac8cae 4079
17f085df 4080 phy_ctrl = er32(PHY_CTRL);
c077a906 4081 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
2fbe4526
BA
4082 if (hw->phy.type == e1000_phy_i217) {
4083 u16 phy_reg;
4084
4085 ret_val = hw->phy.ops.acquire(hw);
4086 if (ret_val)
4087 goto out;
4088
4089 if (!dev_spec->eee_disable) {
4090 u16 eee_advert;
4091
4ddc48a9
BA
4092 ret_val =
4093 e1000_read_emi_reg_locked(hw,
4094 I217_EEE_ADVERTISEMENT,
4095 &eee_advert);
2fbe4526
BA
4096 if (ret_val)
4097 goto release;
2fbe4526 4098
e921eb1a 4099 /* Disable LPLU if both link partners support 100BaseT
2fbe4526
BA
4100 * EEE and 100Full is advertised on both ends of the
4101 * link.
4102 */
3d4d5755 4103 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
2fbe4526 4104 (dev_spec->eee_lp_ability &
3d4d5755 4105 I82579_EEE_100_SUPPORTED) &&
2fbe4526
BA
4106 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4107 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4108 E1000_PHY_CTRL_NOND0A_LPLU);
4109 }
4110
e921eb1a 4111 /* For i217 Intel Rapid Start Technology support,
2fbe4526
BA
4112 * when the system is going into Sx and no manageability engine
4113 * is present, the driver must configure proxy to reset only on
4114 * power good. LPI (Low Power Idle) state must also reset only
4115 * on power good, as well as the MTA (Multicast table array).
4116 * The SMBus release must also be disabled on LCD reset.
4117 */
4118 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
4119
4120 /* Enable proxy to reset only on power good. */
4121 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4122 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4123 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4124
e921eb1a 4125 /* Set bit enable LPI (EEE) to reset only on
2fbe4526
BA
4126 * power good.
4127 */
4128 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
6d7407bf 4129 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
2fbe4526
BA
4130 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4131
4132 /* Disable the SMB release on LCD reset. */
4133 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
6d7407bf 4134 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
2fbe4526
BA
4135 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4136 }
4137
e921eb1a 4138 /* Enable MTA to reset for Intel Rapid Start Technology
2fbe4526
BA
4139 * Support
4140 */
4141 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
6d7407bf 4142 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
2fbe4526
BA
4143 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4144
4145release:
4146 hw->phy.ops.release(hw);
4147 }
4148out:
17f085df 4149 ew32(PHY_CTRL, phy_ctrl);
a4f58f54 4150
462d5994
BA
4151 if (hw->mac.type == e1000_ich8lan)
4152 e1000e_gig_downshift_workaround_ich8lan(hw);
4153
8395ae83 4154 if (hw->mac.type >= e1000_pchlan) {
ce54afd1 4155 e1000_oem_bits_config_ich8lan(hw, false);
92fe1733
BA
4156
4157 /* Reset PHY to activate OEM bits on 82577/8 */
4158 if (hw->mac.type == e1000_pchlan)
4159 e1000e_phy_hw_reset_generic(hw);
4160
8395ae83
BA
4161 ret_val = hw->phy.ops.acquire(hw);
4162 if (ret_val)
4163 return;
4164 e1000_write_smbus_addr(hw);
4165 hw->phy.ops.release(hw);
4166 }
97ac8cae
BA
4167}
4168
99730e4c
BA
4169/**
4170 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4171 * @hw: pointer to the HW structure
4172 *
4173 * During Sx to S0 transitions on non-managed devices or managed devices
4174 * on which PHY resets are not blocked, if the PHY registers cannot be
4175 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4176 * the PHY.
2fbe4526 4177 * On i217, setup Intel Rapid Start Technology.
99730e4c
BA
4178 **/
4179void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4180{
90b82984 4181 s32 ret_val;
99730e4c 4182
cb17aab9 4183 if (hw->mac.type < e1000_pch2lan)
99730e4c
BA
4184 return;
4185
cb17aab9 4186 ret_val = e1000_init_phy_workarounds_pchlan(hw);
90b82984 4187 if (ret_val) {
cb17aab9 4188 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
90b82984
BA
4189 return;
4190 }
2fbe4526 4191
e921eb1a 4192 /* For i217 Intel Rapid Start Technology support when the system
2fbe4526
BA
4193 * is transitioning from Sx and no manageability engine is present
4194 * configure SMBus to restore on reset, disable proxy, and enable
4195 * the reset on MTA (Multicast table array).
4196 */
4197 if (hw->phy.type == e1000_phy_i217) {
4198 u16 phy_reg;
4199
4200 ret_val = hw->phy.ops.acquire(hw);
4201 if (ret_val) {
4202 e_dbg("Failed to setup iRST\n");
4203 return;
4204 }
4205
4206 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
e921eb1a 4207 /* Restore clear on SMB if no manageability engine
2fbe4526
BA
4208 * is present
4209 */
4210 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4211 if (ret_val)
4212 goto release;
6d7407bf 4213 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
2fbe4526
BA
4214 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4215
4216 /* Disable Proxy */
4217 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4218 }
4219 /* Enable reset on MTA */
4220 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4221 if (ret_val)
4222 goto release;
6d7407bf 4223 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
2fbe4526
BA
4224 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4225release:
4226 if (ret_val)
4227 e_dbg("Error %d in resume workarounds\n", ret_val);
4228 hw->phy.ops.release(hw);
4229 }
99730e4c
BA
4230}
4231
bc7f75fa
AK
4232/**
4233 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4234 * @hw: pointer to the HW structure
4235 *
4236 * Return the LED back to the default configuration.
4237 **/
4238static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4239{
4240 if (hw->phy.type == e1000_phy_ife)
4241 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4242
4243 ew32(LEDCTL, hw->mac.ledctl_default);
4244 return 0;
4245}
4246
4247/**
489815ce 4248 * e1000_led_on_ich8lan - Turn LEDs on
bc7f75fa
AK
4249 * @hw: pointer to the HW structure
4250 *
489815ce 4251 * Turn on the LEDs.
bc7f75fa
AK
4252 **/
4253static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4254{
4255 if (hw->phy.type == e1000_phy_ife)
4256 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4257 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4258
4259 ew32(LEDCTL, hw->mac.ledctl_mode2);
4260 return 0;
4261}
4262
4263/**
489815ce 4264 * e1000_led_off_ich8lan - Turn LEDs off
bc7f75fa
AK
4265 * @hw: pointer to the HW structure
4266 *
489815ce 4267 * Turn off the LEDs.
bc7f75fa
AK
4268 **/
4269static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4270{
4271 if (hw->phy.type == e1000_phy_ife)
4272 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
482fed85
BA
4273 (IFE_PSCL_PROBE_MODE |
4274 IFE_PSCL_PROBE_LEDS_OFF));
bc7f75fa
AK
4275
4276 ew32(LEDCTL, hw->mac.ledctl_mode1);
4277 return 0;
4278}
4279
a4f58f54
BA
4280/**
4281 * e1000_setup_led_pchlan - Configures SW controllable LED
4282 * @hw: pointer to the HW structure
4283 *
4284 * This prepares the SW controllable LED for use.
4285 **/
4286static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4287{
482fed85 4288 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
a4f58f54
BA
4289}
4290
4291/**
4292 * e1000_cleanup_led_pchlan - Restore the default LED operation
4293 * @hw: pointer to the HW structure
4294 *
4295 * Return the LED back to the default configuration.
4296 **/
4297static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4298{
482fed85 4299 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
a4f58f54
BA
4300}
4301
4302/**
4303 * e1000_led_on_pchlan - Turn LEDs on
4304 * @hw: pointer to the HW structure
4305 *
4306 * Turn on the LEDs.
4307 **/
4308static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4309{
4310 u16 data = (u16)hw->mac.ledctl_mode2;
4311 u32 i, led;
4312
e921eb1a 4313 /* If no link, then turn LED on by setting the invert bit
a4f58f54
BA
4314 * for each LED that's mode is "link_up" in ledctl_mode2.
4315 */
4316 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4317 for (i = 0; i < 3; i++) {
4318 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4319 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4320 E1000_LEDCTL_MODE_LINK_UP)
4321 continue;
4322 if (led & E1000_PHY_LED0_IVRT)
4323 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4324 else
4325 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4326 }
4327 }
4328
482fed85 4329 return e1e_wphy(hw, HV_LED_CONFIG, data);
a4f58f54
BA
4330}
4331
4332/**
4333 * e1000_led_off_pchlan - Turn LEDs off
4334 * @hw: pointer to the HW structure
4335 *
4336 * Turn off the LEDs.
4337 **/
4338static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4339{
4340 u16 data = (u16)hw->mac.ledctl_mode1;
4341 u32 i, led;
4342
e921eb1a 4343 /* If no link, then turn LED off by clearing the invert bit
a4f58f54
BA
4344 * for each LED that's mode is "link_up" in ledctl_mode1.
4345 */
4346 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4347 for (i = 0; i < 3; i++) {
4348 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4349 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4350 E1000_LEDCTL_MODE_LINK_UP)
4351 continue;
4352 if (led & E1000_PHY_LED0_IVRT)
4353 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4354 else
4355 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4356 }
4357 }
4358
482fed85 4359 return e1e_wphy(hw, HV_LED_CONFIG, data);
a4f58f54
BA
4360}
4361
f4187b56 4362/**
e98cac44 4363 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
f4187b56
BA
4364 * @hw: pointer to the HW structure
4365 *
e98cac44
BA
4366 * Read appropriate register for the config done bit for completion status
4367 * and configure the PHY through s/w for EEPROM-less parts.
4368 *
4369 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4370 * config done bit, so only an error is logged and continues. If we were
4371 * to return with error, EEPROM-less silicon would not be able to be reset
4372 * or change link.
f4187b56
BA
4373 **/
4374static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4375{
e98cac44 4376 s32 ret_val = 0;
f4187b56 4377 u32 bank = 0;
e98cac44 4378 u32 status;
f4187b56 4379
e98cac44 4380 e1000e_get_cfg_done(hw);
fc0c7760 4381
e98cac44
BA
4382 /* Wait for indication from h/w that it has completed basic config */
4383 if (hw->mac.type >= e1000_ich10lan) {
4384 e1000_lan_init_done_ich8lan(hw);
4385 } else {
4386 ret_val = e1000e_get_auto_rd_done(hw);
4387 if (ret_val) {
e921eb1a 4388 /* When auto config read does not complete, do not
e98cac44
BA
4389 * return with an error. This can happen in situations
4390 * where there is no eeprom and prevents getting link.
4391 */
4392 e_dbg("Auto Read Done did not complete\n");
4393 ret_val = 0;
4394 }
fc0c7760
BA
4395 }
4396
e98cac44
BA
4397 /* Clear PHY Reset Asserted bit */
4398 status = er32(STATUS);
4399 if (status & E1000_STATUS_PHYRA)
4400 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4401 else
4402 e_dbg("PHY Reset Asserted not set - needs delay\n");
f4187b56
BA
4403
4404 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
e98cac44 4405 if (hw->mac.type <= e1000_ich9lan) {
04499ec4 4406 if (!(er32(EECD) & E1000_EECD_PRES) &&
f4187b56
BA
4407 (hw->phy.type == e1000_phy_igp_3)) {
4408 e1000e_phy_init_script_igp3(hw);
4409 }
4410 } else {
4411 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4412 /* Maybe we should do a basic PHY config */
3bb99fe2 4413 e_dbg("EEPROM not present\n");
e98cac44 4414 ret_val = -E1000_ERR_CONFIG;
f4187b56
BA
4415 }
4416 }
4417
e98cac44 4418 return ret_val;
f4187b56
BA
4419}
4420
17f208de
BA
4421/**
4422 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4423 * @hw: pointer to the HW structure
4424 *
4425 * In the case of a PHY power down to save power, or to turn off link during a
4426 * driver unload, or wake on lan is not enabled, remove the link.
4427 **/
4428static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4429{
4430 /* If the management interface is not enabled, then power down */
4431 if (!(hw->mac.ops.check_mng_mode(hw) ||
4432 hw->phy.ops.check_reset_block(hw)))
4433 e1000_power_down_phy_copper(hw);
17f208de
BA
4434}
4435
bc7f75fa
AK
4436/**
4437 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4438 * @hw: pointer to the HW structure
4439 *
4440 * Clears hardware counters specific to the silicon family and calls
4441 * clear_hw_cntrs_generic to clear all general purpose counters.
4442 **/
4443static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4444{
a4f58f54 4445 u16 phy_data;
2b6b168d 4446 s32 ret_val;
bc7f75fa
AK
4447
4448 e1000e_clear_hw_cntrs_base(hw);
4449
99673d9b
BA
4450 er32(ALGNERRC);
4451 er32(RXERRC);
4452 er32(TNCRS);
4453 er32(CEXTERR);
4454 er32(TSCTC);
4455 er32(TSCTFC);
bc7f75fa 4456
99673d9b
BA
4457 er32(MGTPRC);
4458 er32(MGTPDC);
4459 er32(MGTPTC);
bc7f75fa 4460
99673d9b
BA
4461 er32(IAC);
4462 er32(ICRXOC);
bc7f75fa 4463
a4f58f54
BA
4464 /* Clear PHY statistics registers */
4465 if ((hw->phy.type == e1000_phy_82578) ||
d3738bb8 4466 (hw->phy.type == e1000_phy_82579) ||
2fbe4526 4467 (hw->phy.type == e1000_phy_i217) ||
a4f58f54 4468 (hw->phy.type == e1000_phy_82577)) {
2b6b168d
BA
4469 ret_val = hw->phy.ops.acquire(hw);
4470 if (ret_val)
4471 return;
4472 ret_val = hw->phy.ops.set_page(hw,
4473 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4474 if (ret_val)
4475 goto release;
4476 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4477 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4478 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4479 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4480 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4481 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4482 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4483 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4484 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4485 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4486 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4487 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4488 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4489 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4490release:
4491 hw->phy.ops.release(hw);
a4f58f54 4492 }
bc7f75fa
AK
4493}
4494
8ce9d6c7 4495static const struct e1000_mac_operations ich8_mac_ops = {
eb7700dc 4496 /* check_mng_mode dependent on mac type */
7d3cabbc 4497 .check_for_link = e1000_check_for_copper_link_ich8lan,
a4f58f54 4498 /* cleanup_led dependent on mac type */
bc7f75fa
AK
4499 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4500 .get_bus_info = e1000_get_bus_info_ich8lan,
f4d2dd4c 4501 .set_lan_id = e1000_set_lan_id_single_port,
bc7f75fa 4502 .get_link_up_info = e1000_get_link_up_info_ich8lan,
a4f58f54
BA
4503 /* led_on dependent on mac type */
4504 /* led_off dependent on mac type */
e2de3eb6 4505 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
bc7f75fa
AK
4506 .reset_hw = e1000_reset_hw_ich8lan,
4507 .init_hw = e1000_init_hw_ich8lan,
4508 .setup_link = e1000_setup_link_ich8lan,
4509 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
a4f58f54 4510 /* id_led_init dependent on mac type */
57cde763 4511 .config_collision_dist = e1000e_config_collision_dist_generic,
69e1e019 4512 .rar_set = e1000e_rar_set_generic,
bc7f75fa
AK
4513};
4514
8ce9d6c7 4515static const struct e1000_phy_operations ich8_phy_ops = {
94d8186a 4516 .acquire = e1000_acquire_swflag_ich8lan,
bc7f75fa 4517 .check_reset_block = e1000_check_reset_block_ich8lan,
94d8186a 4518 .commit = NULL,
f4187b56 4519 .get_cfg_done = e1000_get_cfg_done_ich8lan,
bc7f75fa 4520 .get_cable_length = e1000e_get_cable_length_igp_2,
94d8186a
BA
4521 .read_reg = e1000e_read_phy_reg_igp,
4522 .release = e1000_release_swflag_ich8lan,
4523 .reset = e1000_phy_hw_reset_ich8lan,
bc7f75fa
AK
4524 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4525 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
94d8186a 4526 .write_reg = e1000e_write_phy_reg_igp,
bc7f75fa
AK
4527};
4528
8ce9d6c7 4529static const struct e1000_nvm_operations ich8_nvm_ops = {
94d8186a
BA
4530 .acquire = e1000_acquire_nvm_ich8lan,
4531 .read = e1000_read_nvm_ich8lan,
4532 .release = e1000_release_nvm_ich8lan,
e85e3639 4533 .reload = e1000e_reload_nvm_generic,
94d8186a 4534 .update = e1000_update_nvm_checksum_ich8lan,
bc7f75fa 4535 .valid_led_default = e1000_valid_led_default_ich8lan,
94d8186a
BA
4536 .validate = e1000_validate_nvm_checksum_ich8lan,
4537 .write = e1000_write_nvm_ich8lan,
bc7f75fa
AK
4538};
4539
8ce9d6c7 4540const struct e1000_info e1000_ich8_info = {
bc7f75fa
AK
4541 .mac = e1000_ich8lan,
4542 .flags = FLAG_HAS_WOL
97ac8cae 4543 | FLAG_IS_ICH
bc7f75fa
AK
4544 | FLAG_HAS_CTRLEXT_ON_LOAD
4545 | FLAG_HAS_AMT
4546 | FLAG_HAS_FLASH
4547 | FLAG_APME_IN_WUC,
4548 .pba = 8,
2adc55c9 4549 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
69e3fd8c 4550 .get_variants = e1000_get_variants_ich8lan,
bc7f75fa
AK
4551 .mac_ops = &ich8_mac_ops,
4552 .phy_ops = &ich8_phy_ops,
4553 .nvm_ops = &ich8_nvm_ops,
4554};
4555
8ce9d6c7 4556const struct e1000_info e1000_ich9_info = {
bc7f75fa
AK
4557 .mac = e1000_ich9lan,
4558 .flags = FLAG_HAS_JUMBO_FRAMES
97ac8cae 4559 | FLAG_IS_ICH
bc7f75fa 4560 | FLAG_HAS_WOL
bc7f75fa
AK
4561 | FLAG_HAS_CTRLEXT_ON_LOAD
4562 | FLAG_HAS_AMT
bc7f75fa
AK
4563 | FLAG_HAS_FLASH
4564 | FLAG_APME_IN_WUC,
7f1557e1 4565 .pba = 18,
2adc55c9 4566 .max_hw_frame_size = DEFAULT_JUMBO,
69e3fd8c 4567 .get_variants = e1000_get_variants_ich8lan,
bc7f75fa
AK
4568 .mac_ops = &ich8_mac_ops,
4569 .phy_ops = &ich8_phy_ops,
4570 .nvm_ops = &ich8_nvm_ops,
4571};
4572
8ce9d6c7 4573const struct e1000_info e1000_ich10_info = {
f4187b56
BA
4574 .mac = e1000_ich10lan,
4575 .flags = FLAG_HAS_JUMBO_FRAMES
4576 | FLAG_IS_ICH
4577 | FLAG_HAS_WOL
f4187b56
BA
4578 | FLAG_HAS_CTRLEXT_ON_LOAD
4579 | FLAG_HAS_AMT
f4187b56
BA
4580 | FLAG_HAS_FLASH
4581 | FLAG_APME_IN_WUC,
7f1557e1 4582 .pba = 18,
2adc55c9 4583 .max_hw_frame_size = DEFAULT_JUMBO,
f4187b56
BA
4584 .get_variants = e1000_get_variants_ich8lan,
4585 .mac_ops = &ich8_mac_ops,
4586 .phy_ops = &ich8_phy_ops,
4587 .nvm_ops = &ich8_nvm_ops,
4588};
a4f58f54 4589
8ce9d6c7 4590const struct e1000_info e1000_pch_info = {
a4f58f54
BA
4591 .mac = e1000_pchlan,
4592 .flags = FLAG_IS_ICH
4593 | FLAG_HAS_WOL
a4f58f54
BA
4594 | FLAG_HAS_CTRLEXT_ON_LOAD
4595 | FLAG_HAS_AMT
4596 | FLAG_HAS_FLASH
4597 | FLAG_HAS_JUMBO_FRAMES
38eb394e 4598 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
a4f58f54 4599 | FLAG_APME_IN_WUC,
8c7bbb92 4600 .flags2 = FLAG2_HAS_PHY_STATS,
a4f58f54
BA
4601 .pba = 26,
4602 .max_hw_frame_size = 4096,
4603 .get_variants = e1000_get_variants_ich8lan,
4604 .mac_ops = &ich8_mac_ops,
4605 .phy_ops = &ich8_phy_ops,
4606 .nvm_ops = &ich8_nvm_ops,
4607};
d3738bb8 4608
8ce9d6c7 4609const struct e1000_info e1000_pch2_info = {
d3738bb8
BA
4610 .mac = e1000_pch2lan,
4611 .flags = FLAG_IS_ICH
4612 | FLAG_HAS_WOL
b67e1913 4613 | FLAG_HAS_HW_TIMESTAMP
d3738bb8
BA
4614 | FLAG_HAS_CTRLEXT_ON_LOAD
4615 | FLAG_HAS_AMT
4616 | FLAG_HAS_FLASH
4617 | FLAG_HAS_JUMBO_FRAMES
4618 | FLAG_APME_IN_WUC,
e52997f9
BA
4619 .flags2 = FLAG2_HAS_PHY_STATS
4620 | FLAG2_HAS_EEE,
828bac87 4621 .pba = 26,
d3738bb8
BA
4622 .max_hw_frame_size = DEFAULT_JUMBO,
4623 .get_variants = e1000_get_variants_ich8lan,
4624 .mac_ops = &ich8_mac_ops,
4625 .phy_ops = &ich8_phy_ops,
4626 .nvm_ops = &ich8_nvm_ops,
4627};
2fbe4526
BA
4628
4629const struct e1000_info e1000_pch_lpt_info = {
4630 .mac = e1000_pch_lpt,
4631 .flags = FLAG_IS_ICH
4632 | FLAG_HAS_WOL
b67e1913 4633 | FLAG_HAS_HW_TIMESTAMP
2fbe4526
BA
4634 | FLAG_HAS_CTRLEXT_ON_LOAD
4635 | FLAG_HAS_AMT
4636 | FLAG_HAS_FLASH
4637 | FLAG_HAS_JUMBO_FRAMES
4638 | FLAG_APME_IN_WUC,
4639 .flags2 = FLAG2_HAS_PHY_STATS
4640 | FLAG2_HAS_EEE,
4641 .pba = 26,
ed1a4265 4642 .max_hw_frame_size = 9018,
2fbe4526
BA
4643 .get_variants = e1000_get_variants_ich8lan,
4644 .mac_ops = &ich8_mac_ops,
4645 .phy_ops = &ich8_phy_ops,
4646 .nvm_ops = &ich8_nvm_ops,
4647};