blob: 051dfda75fc02df651022fa750270a0e259b6bb2 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanf5e261e2012-01-01 16:00:03 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Bruce Allane921eb12012-11-28 09:28:37 +000029/* 82562G 10/100 Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070030 * 82562G-2 10/100 Network Connection
31 * 82562GT 10/100 Network Connection
32 * 82562GT-2 10/100 Network Connection
33 * 82562V 10/100 Network Connection
34 * 82562V-2 10/100 Network Connection
35 * 82566DC-2 Gigabit Network Connection
36 * 82566DC Gigabit Network Connection
37 * 82566DM-2 Gigabit Network Connection
38 * 82566DM Gigabit Network Connection
39 * 82566MC Gigabit Network Connection
40 * 82566MM Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070041 * 82567LM Gigabit Network Connection
42 * 82567LF Gigabit Network Connection
Bruce Allan16059272008-11-21 16:51:06 -080043 * 82567V Gigabit Network Connection
Bruce Allan97ac8ca2008-04-29 09:16:05 -070044 * 82567LM-2 Gigabit Network Connection
45 * 82567LF-2 Gigabit Network Connection
46 * 82567V-2 Gigabit Network Connection
Bruce Allanf4187b52008-08-26 18:36:50 -070047 * 82567LF-3 Gigabit Network Connection
48 * 82567LM-3 Gigabit Network Connection
Bruce Allan2f15f9d2008-08-26 18:36:36 -070049 * 82567LM-4 Gigabit Network Connection
Bruce Allana4f58f52009-06-02 11:29:18 +000050 * 82577LM Gigabit Network Connection
51 * 82577LC Gigabit Network Connection
52 * 82578DM Gigabit Network Connection
53 * 82578DC Gigabit Network Connection
Bruce Alland3738bb2010-06-16 13:27:28 +000054 * 82579LM Gigabit Network Connection
55 * 82579V Gigabit Network Connection
Auke Kokbc7f75f2007-09-17 12:30:59 -070056 */
57
Auke Kokbc7f75f2007-09-17 12:30:59 -070058#include "e1000.h"
59
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
Bruce Allan4a770352008-10-01 17:18:35 -070065#define ICH_FLASH_PR0 0x0074
Auke Kokbc7f75f2007-09-17 12:30:59 -070066
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 */
Bruce Allan6dfaa762010-05-05 22:00:06 +000087/* FW established a valid mode */
88#define E1000_ICH_FWSM_FW_VALID 0x00008000
Auke Kokbc7f75f2007-09-17 12:30:59 -070089
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
Bruce Allane2434552008-11-21 17:02:41 -080099#define E1000_ICH_NVM_VALID_SIG_MASK 0xC0
100#define E1000_ICH_NVM_SIG_VALUE 0x80
Auke Kokbc7f75f2007-09-17 12:30:59 -0700101
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
Bruce Allan62bc8132012-03-20 03:47:57 +0000107#define E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK 0x0C000000
108#define E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC 0x08000000
109
Bruce Allan831bd2e2010-09-22 17:16:18 +0000110#define E1000_FEXTNVM4_BEACON_DURATION_MASK 0x7
111#define E1000_FEXTNVM4_BEACON_DURATION_8USEC 0x7
112#define E1000_FEXTNVM4_BEACON_DURATION_16USEC 0x3
113
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
115
116#define E1000_ICH_RAR_ENTRIES 7
Bruce Allan69e1e012012-04-14 03:28:50 +0000117#define E1000_PCH2_RAR_ENTRIES 5 /* RAR[0], SHRA[0-3] */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000118#define E1000_PCH_LPT_RAR_ENTRIES 12 /* RAR[0], SHRA[0-10] */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700119
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
Bruce Allana4f58f52009-06-02 11:29:18 +0000130#define HV_LED_CONFIG PHY_REG(768, 30) /* LED Configuration */
131
Bruce Allan53ac5a82009-10-26 11:23:06 +0000132#define SW_FLAG_TIMEOUT 1000 /* SW Semaphore flag timeout in milliseconds */
133
Bruce Allan2fbe4522012-04-19 03:21:47 +0000134/* SMBus Control Phy Register */
135#define CV_SMB_CTRL PHY_REG(769, 23)
136#define CV_SMB_CTRL_FORCE_SMBUS 0x0001
137
Bruce Allanf523d212009-10-29 13:45:45 +0000138/* SMBus Address Phy Register */
139#define HV_SMB_ADDR PHY_REG(768, 26)
Bruce Allan8395ae82010-09-22 17:15:08 +0000140#define HV_SMB_ADDR_MASK 0x007F
Bruce Allanf523d212009-10-29 13:45:45 +0000141#define HV_SMB_ADDR_PEC_EN 0x0200
142#define HV_SMB_ADDR_VALID 0x0080
Bruce Allan2fbe4522012-04-19 03:21:47 +0000143#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
Bruce Allanf523d212009-10-29 13:45:45 +0000146
Bruce Alland3738bb2010-06-16 13:27:28 +0000147/* PHY Power Management Control */
148#define HV_PM_CTRL PHY_REG(770, 17)
Bruce Allan36ceeb42012-03-20 03:47:47 +0000149#define HV_PM_CTRL_PLL_STOP_IN_K1_GIGA 0x100
Bruce Alland3738bb2010-06-16 13:27:28 +0000150
Bruce Allane52997f2010-06-16 13:27:49 +0000151/* PHY Low Power Idle Control */
Bruce Allan0ed013e2011-07-29 05:52:56 +0000152#define I82579_LPI_CTRL PHY_REG(772, 20)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000153#define I82579_LPI_CTRL_100_ENABLE 0x2000
154#define I82579_LPI_CTRL_1000_ENABLE 0x4000
Bruce Allan0ed013e2011-07-29 05:52:56 +0000155#define I82579_LPI_CTRL_ENABLE_MASK 0x6000
156#define I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT 0x80
Bruce Allane52997f2010-06-16 13:27:49 +0000157
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000158/* Extended Management Interface (EMI) Registers */
Bruce Allan1effb452011-02-25 06:58:03 +0000159#define I82579_EMI_ADDR 0x10
160#define I82579_EMI_DATA 0x11
161#define I82579_LPI_UPDATE_TIMER 0x4805 /* in 40ns units + 40 ns base value */
Bruce Allan651fb102012-12-05 06:26:03 +0000162#define I82579_MSE_THRESHOLD 0x084F /* 82579 Mean Square Error Threshold */
163#define I82577_MSE_THRESHOLD 0x0887 /* 82577 Mean Square Error Threshold */
Bruce Allan4d241362011-12-16 00:46:06 +0000164#define I82579_MSE_LINK_DOWN 0x2411 /* MSE count before dropping link */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000165#define I82579_EEE_PCS_STATUS 0x182D /* IEEE MMD Register 3.1 >> 8 */
166#define I82579_EEE_LP_ABILITY 0x040F /* IEEE MMD Register 7.61 */
167#define I82579_EEE_100_SUPPORTED (1 << 1) /* 100BaseTx EEE supported */
168#define I82579_EEE_1000_SUPPORTED (1 << 2) /* 1000BaseTx EEE supported */
169#define I217_EEE_PCS_STATUS 0x9401 /* IEEE MMD Register 3.1 */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000170#define I217_EEE_ADVERTISEMENT 0x8001 /* IEEE MMD Register 7.60 */
171#define I217_EEE_LP_ABILITY 0x8002 /* IEEE MMD Register 7.61 */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000172
173/* Intel Rapid Start Technology Support */
Bruce Allan6d7407b2012-05-10 02:51:17 +0000174#define I217_PROXY_CTRL BM_PHY_REG(BM_WUC_PAGE, 70)
Bruce Allan2fbe4522012-04-19 03:21:47 +0000175#define I217_PROXY_CTRL_AUTO_DISABLE 0x0080
176#define I217_SxCTRL PHY_REG(BM_PORT_CTRL_PAGE, 28)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000177#define I217_SxCTRL_ENABLE_LPI_RESET 0x1000
Bruce Allan2fbe4522012-04-19 03:21:47 +0000178#define I217_CGFREG PHY_REG(772, 29)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000179#define I217_CGFREG_ENABLE_MTA_RESET 0x0002
Bruce Allan2fbe4522012-04-19 03:21:47 +0000180#define I217_MEMPWR PHY_REG(772, 26)
Bruce Allan6d7407b2012-05-10 02:51:17 +0000181#define I217_MEMPWR_DISABLE_SMB_RELEASE 0x0010
Bruce Allan1effb452011-02-25 06:58:03 +0000182
Bruce Allanf523d212009-10-29 13:45:45 +0000183/* Strapping Option Register - RO */
184#define E1000_STRAP 0x0000C
185#define E1000_STRAP_SMBUS_ADDRESS_MASK 0x00FE0000
186#define E1000_STRAP_SMBUS_ADDRESS_SHIFT 17
Bruce Allan2fbe4522012-04-19 03:21:47 +0000187#define E1000_STRAP_SMT_FREQ_MASK 0x00003000
188#define E1000_STRAP_SMT_FREQ_SHIFT 12
Bruce Allanf523d212009-10-29 13:45:45 +0000189
Bruce Allanfa2ce132009-10-26 11:23:25 +0000190/* OEM Bits Phy Register */
191#define HV_OEM_BITS PHY_REG(768, 25)
192#define HV_OEM_BITS_LPLU 0x0004 /* Low Power Link Up */
Bruce Allanf523d212009-10-29 13:45:45 +0000193#define HV_OEM_BITS_GBE_DIS 0x0040 /* Gigabit Disable */
Bruce Allanfa2ce132009-10-26 11:23:25 +0000194#define HV_OEM_BITS_RESTART_AN 0x0400 /* Restart Auto-negotiation */
195
Bruce Allan1d5846b2009-10-29 13:46:05 +0000196#define E1000_NVM_K1_CONFIG 0x1B /* NVM K1 Config Word */
197#define E1000_NVM_K1_ENABLE 0x1 /* NVM Enable K1 bit */
198
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000199/* KMRN Mode Control */
200#define HV_KMRN_MODE_CTRL PHY_REG(769, 16)
201#define HV_KMRN_MDIO_SLOW 0x0400
202
Bruce Allan1d2101a72011-07-22 06:21:56 +0000203/* KMRN FIFO Control and Status */
204#define HV_KMRN_FIFO_CTRLSTA PHY_REG(770, 16)
205#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK 0x7000
206#define HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT 12
207
Auke Kokbc7f75f2007-09-17 12:30:59 -0700208/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
209/* Offset 04h HSFSTS */
210union ich8_hws_flash_status {
211 struct ich8_hsfsts {
212 u16 flcdone :1; /* bit 0 Flash Cycle Done */
213 u16 flcerr :1; /* bit 1 Flash Cycle Error */
214 u16 dael :1; /* bit 2 Direct Access error Log */
215 u16 berasesz :2; /* bit 4:3 Sector Erase Size */
216 u16 flcinprog :1; /* bit 5 flash cycle in Progress */
217 u16 reserved1 :2; /* bit 13:6 Reserved */
218 u16 reserved2 :6; /* bit 13:6 Reserved */
219 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
220 u16 flockdn :1; /* bit 15 Flash Config Lock-Down */
221 } hsf_status;
222 u16 regval;
223};
224
225/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
226/* Offset 06h FLCTL */
227union ich8_hws_flash_ctrl {
228 struct ich8_hsflctl {
229 u16 flcgo :1; /* 0 Flash Cycle Go */
230 u16 flcycle :2; /* 2:1 Flash Cycle */
231 u16 reserved :5; /* 7:3 Reserved */
232 u16 fldbcount :2; /* 9:8 Flash Data Byte Count */
233 u16 flockdn :6; /* 15:10 Reserved */
234 } hsf_ctrl;
235 u16 regval;
236};
237
238/* ICH Flash Region Access Permissions */
239union ich8_hws_flash_regacc {
240 struct ich8_flracc {
241 u32 grra :8; /* 0:7 GbE region Read Access */
242 u32 grwa :8; /* 8:15 GbE region Write Access */
243 u32 gmrag :8; /* 23:16 GbE Master Read Access Grant */
244 u32 gmwag :8; /* 31:24 GbE Master Write Access Grant */
245 } hsf_flregacc;
246 u16 regval;
247};
248
Bruce Allan4a770352008-10-01 17:18:35 -0700249/* ICH Flash Protected Region */
250union ich8_flash_protected_range {
251 struct ich8_pr {
252 u32 base:13; /* 0:12 Protected Range Base */
253 u32 reserved1:2; /* 13:14 Reserved */
254 u32 rpe:1; /* 15 Read Protection Enable */
255 u32 limit:13; /* 16:28 Protected Range Limit */
256 u32 reserved2:2; /* 29:30 Reserved */
257 u32 wpe:1; /* 31 Write Protection Enable */
258 } range;
259 u32 regval;
260};
261
Auke Kokbc7f75f2007-09-17 12:30:59 -0700262static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw);
263static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
264static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700265static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
266static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
267 u32 offset, u8 byte);
Bruce Allanf4187b52008-08-26 18:36:50 -0700268static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
269 u8 *data);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700270static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
271 u16 *data);
272static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
273 u8 size, u16 *data);
274static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
275static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
Bruce Allanf4187b52008-08-26 18:36:50 -0700276static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
Bruce Allana4f58f52009-06-02 11:29:18 +0000277static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
278static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
279static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
280static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
281static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
282static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
283static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
284static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
Bruce Allanfa2ce132009-10-26 11:23:25 +0000285static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
Bruce Allan17f208d2009-12-01 15:47:22 +0000286static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
Bruce Allanf523d212009-10-29 13:45:45 +0000287static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +0000288static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
Bruce Allanfddaa1a2010-01-13 01:52:49 +0000289static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
Bruce Allaneb7700d2010-06-16 13:27:05 +0000290static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
291static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
Bruce Allan69e1e012012-04-14 03:28:50 +0000292static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000293static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan831bd2e2010-09-22 17:16:18 +0000294static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
Bruce Allan605c82b2010-09-22 17:17:01 +0000295static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700296
297static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
298{
299 return readw(hw->flash_address + reg);
300}
301
302static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
303{
304 return readl(hw->flash_address + reg);
305}
306
307static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
308{
309 writew(val, hw->flash_address + reg);
310}
311
312static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
313{
314 writel(val, hw->flash_address + reg);
315}
316
317#define er16flash(reg) __er16flash(hw, (reg))
318#define er32flash(reg) __er32flash(hw, (reg))
Bruce Allan0e15df42012-01-31 06:37:11 +0000319#define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
320#define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700321
Bruce Allancb17aab2012-04-13 03:16:22 +0000322/**
323 * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
324 * @hw: pointer to the HW structure
325 *
326 * Test access to the PHY registers by reading the PHY ID registers. If
327 * the PHY ID is already known (e.g. resume path) compare it with known ID,
328 * otherwise assume the read PHY ID is correct if it is valid.
329 *
330 * Assumes the sw/fw/hw semaphore is already acquired.
331 **/
332static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
Bruce Allan99730e42011-05-13 07:19:48 +0000333{
Bruce Allana52359b2012-07-14 04:23:58 +0000334 u16 phy_reg = 0;
335 u32 phy_id = 0;
336 s32 ret_val;
337 u16 retry_count;
Bruce Allan99730e42011-05-13 07:19:48 +0000338
Bruce Allana52359b2012-07-14 04:23:58 +0000339 for (retry_count = 0; retry_count < 2; retry_count++) {
340 ret_val = e1e_rphy_locked(hw, PHY_ID1, &phy_reg);
341 if (ret_val || (phy_reg == 0xFFFF))
342 continue;
343 phy_id = (u32)(phy_reg << 16);
344
345 ret_val = e1e_rphy_locked(hw, PHY_ID2, &phy_reg);
346 if (ret_val || (phy_reg == 0xFFFF)) {
347 phy_id = 0;
348 continue;
349 }
350 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
351 break;
352 }
Bruce Allan62bc8132012-03-20 03:47:57 +0000353
Bruce Allancb17aab2012-04-13 03:16:22 +0000354 if (hw->phy.id) {
355 if (hw->phy.id == phy_id)
356 return true;
Bruce Allana52359b2012-07-14 04:23:58 +0000357 } else if (phy_id) {
358 hw->phy.id = phy_id;
359 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
Bruce Allancb17aab2012-04-13 03:16:22 +0000360 return true;
361 }
362
Bruce Allane921eb12012-11-28 09:28:37 +0000363 /* In case the PHY needs to be in mdio slow mode,
Bruce Allana52359b2012-07-14 04:23:58 +0000364 * set slow mode and try to get the PHY id again.
365 */
366 hw->phy.ops.release(hw);
367 ret_val = e1000_set_mdio_slow_mode_hv(hw);
368 if (!ret_val)
369 ret_val = e1000e_get_phy_id(hw);
370 hw->phy.ops.acquire(hw);
371
372 return !ret_val;
Bruce Allancb17aab2012-04-13 03:16:22 +0000373}
374
375/**
376 * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
377 * @hw: pointer to the HW structure
378 *
379 * Workarounds/flow necessary for PHY initialization during driver load
380 * and resume paths.
381 **/
382static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
383{
384 u32 mac_reg, fwsm = er32(FWSM);
385 s32 ret_val;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000386 u16 phy_reg;
Bruce Allancb17aab2012-04-13 03:16:22 +0000387
388 ret_val = hw->phy.ops.acquire(hw);
389 if (ret_val) {
390 e_dbg("Failed to initialize PHY flow\n");
391 return ret_val;
392 }
393
Bruce Allane921eb12012-11-28 09:28:37 +0000394 /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
Bruce Allancb17aab2012-04-13 03:16:22 +0000395 * inaccessible and resetting the PHY is not blocked, toggle the
396 * LANPHYPC Value bit to force the interconnect to PCIe mode.
397 */
398 switch (hw->mac.type) {
Bruce Allan2fbe4522012-04-19 03:21:47 +0000399 case e1000_pch_lpt:
400 if (e1000_phy_is_accessible_pchlan(hw))
401 break;
402
Bruce Allane921eb12012-11-28 09:28:37 +0000403 /* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan2fbe4522012-04-19 03:21:47 +0000404 * forcing MAC to SMBus mode first.
405 */
406 mac_reg = er32(CTRL_EXT);
407 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
408 ew32(CTRL_EXT, mac_reg);
409
410 /* fall-through */
Bruce Allancb17aab2012-04-13 03:16:22 +0000411 case e1000_pch2lan:
Bruce Allane921eb12012-11-28 09:28:37 +0000412 /* Gate automatic PHY configuration by hardware on
Bruce Allancb17aab2012-04-13 03:16:22 +0000413 * non-managed 82579
414 */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000415 if ((hw->mac.type == e1000_pch2lan) &&
416 !(fwsm & E1000_ICH_FWSM_FW_VALID))
Bruce Allancb17aab2012-04-13 03:16:22 +0000417 e1000_gate_hw_phy_config_ich8lan(hw, true);
418
Bruce Allan2fbe4522012-04-19 03:21:47 +0000419 if (e1000_phy_is_accessible_pchlan(hw)) {
420 if (hw->mac.type == e1000_pch_lpt) {
421 /* Unforce SMBus mode in PHY */
422 e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
423 phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
424 e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
425
426 /* Unforce SMBus mode in MAC */
427 mac_reg = er32(CTRL_EXT);
428 mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
429 ew32(CTRL_EXT, mac_reg);
430 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000431 break;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000432 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000433
434 /* fall-through */
435 case e1000_pchlan:
436 if ((hw->mac.type == e1000_pchlan) &&
437 (fwsm & E1000_ICH_FWSM_FW_VALID))
438 break;
439
440 if (hw->phy.ops.check_reset_block(hw)) {
441 e_dbg("Required LANPHYPC toggle blocked by ME\n");
442 break;
443 }
444
445 e_dbg("Toggling LANPHYPC\n");
446
447 /* Set Phy Config Counter to 50msec */
448 mac_reg = er32(FEXTNVM3);
449 mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
450 mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
451 ew32(FEXTNVM3, mac_reg);
452
453 /* Toggle LANPHYPC Value bit */
454 mac_reg = er32(CTRL);
455 mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
456 mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
457 ew32(CTRL, mac_reg);
458 e1e_flush();
459 udelay(10);
460 mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
461 ew32(CTRL, mac_reg);
462 e1e_flush();
Bruce Allan2fbe4522012-04-19 03:21:47 +0000463 if (hw->mac.type < e1000_pch_lpt) {
464 msleep(50);
465 } else {
466 u16 count = 20;
467 do {
468 usleep_range(5000, 10000);
469 } while (!(er32(CTRL_EXT) &
470 E1000_CTRL_EXT_LPCD) && count--);
471 }
Bruce Allancb17aab2012-04-13 03:16:22 +0000472 break;
473 default:
474 break;
475 }
476
477 hw->phy.ops.release(hw);
478
Bruce Allane921eb12012-11-28 09:28:37 +0000479 /* Reset the PHY before any access to it. Doing so, ensures
Bruce Allancb17aab2012-04-13 03:16:22 +0000480 * that the PHY is in a known good state before we read/write
481 * PHY registers. The generic reset is sufficient here,
482 * because we haven't determined the PHY type yet.
483 */
484 ret_val = e1000e_phy_hw_reset_generic(hw);
485
486 /* Ungate automatic PHY configuration on non-managed 82579 */
487 if ((hw->mac.type == e1000_pch2lan) &&
488 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
489 usleep_range(10000, 20000);
490 e1000_gate_hw_phy_config_ich8lan(hw, false);
491 }
492
493 return ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +0000494}
495
Auke Kokbc7f75f2007-09-17 12:30:59 -0700496/**
Bruce Allana4f58f52009-06-02 11:29:18 +0000497 * e1000_init_phy_params_pchlan - Initialize PHY function pointers
498 * @hw: pointer to the HW structure
499 *
500 * Initialize family-specific PHY parameters and function pointers.
501 **/
502static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
503{
504 struct e1000_phy_info *phy = &hw->phy;
505 s32 ret_val = 0;
506
507 phy->addr = 1;
508 phy->reset_delay_us = 100;
509
Bruce Allan2b6b1682011-05-13 07:20:09 +0000510 phy->ops.set_page = e1000_set_page_igp;
Bruce Allan94d81862009-11-20 23:25:26 +0000511 phy->ops.read_reg = e1000_read_phy_reg_hv;
512 phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000513 phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
Bruce Allanfa2ce132009-10-26 11:23:25 +0000514 phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
515 phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
Bruce Allan94d81862009-11-20 23:25:26 +0000516 phy->ops.write_reg = e1000_write_phy_reg_hv;
517 phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
Bruce Allan2b6b1682011-05-13 07:20:09 +0000518 phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
Bruce Allan17f208d2009-12-01 15:47:22 +0000519 phy->ops.power_up = e1000_power_up_phy_copper;
520 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000521 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
522
523 phy->id = e1000_phy_unknown;
Bruce Allancb17aab2012-04-13 03:16:22 +0000524
525 ret_val = e1000_init_phy_workarounds_pchlan(hw);
526 if (ret_val)
527 return ret_val;
528
529 if (phy->id == e1000_phy_unknown)
530 switch (hw->mac.type) {
531 default:
532 ret_val = e1000e_get_phy_id(hw);
533 if (ret_val)
534 return ret_val;
535 if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
536 break;
537 /* fall-through */
538 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000539 case e1000_pch_lpt:
Bruce Allane921eb12012-11-28 09:28:37 +0000540 /* In case the PHY needs to be in mdio slow mode,
Bruce Allancb17aab2012-04-13 03:16:22 +0000541 * set slow mode and try to get the PHY id again.
542 */
543 ret_val = e1000_set_mdio_slow_mode_hv(hw);
544 if (ret_val)
545 return ret_val;
546 ret_val = e1000e_get_phy_id(hw);
547 if (ret_val)
548 return ret_val;
Bruce Allan664dc872010-11-24 06:01:46 +0000549 break;
Bruce Allancb17aab2012-04-13 03:16:22 +0000550 }
Bruce Allana4f58f52009-06-02 11:29:18 +0000551 phy->type = e1000e_get_phy_type_from_id(phy->id);
552
Bruce Allan0be84012009-12-02 17:03:18 +0000553 switch (phy->type) {
554 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +0000555 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000556 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +0000557 phy->ops.check_polarity = e1000_check_polarity_82577;
558 phy->ops.force_speed_duplex =
Bruce Allan6cc7aae2011-02-25 06:25:18 +0000559 e1000_phy_force_speed_duplex_82577;
Bruce Allan0be84012009-12-02 17:03:18 +0000560 phy->ops.get_cable_length = e1000_get_cable_length_82577;
Bruce Allan94d81862009-11-20 23:25:26 +0000561 phy->ops.get_info = e1000_get_phy_info_82577;
562 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allaneab50ff2010-05-10 15:01:30 +0000563 break;
Bruce Allan0be84012009-12-02 17:03:18 +0000564 case e1000_phy_82578:
565 phy->ops.check_polarity = e1000_check_polarity_m88;
566 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
567 phy->ops.get_cable_length = e1000e_get_cable_length_m88;
568 phy->ops.get_info = e1000e_get_phy_info_m88;
569 break;
570 default:
571 ret_val = -E1000_ERR_PHY;
572 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000573 }
574
575 return ret_val;
576}
577
578/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579 * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
580 * @hw: pointer to the HW structure
581 *
582 * Initialize family-specific PHY parameters and function pointers.
583 **/
584static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
585{
586 struct e1000_phy_info *phy = &hw->phy;
587 s32 ret_val;
588 u16 i = 0;
589
590 phy->addr = 1;
591 phy->reset_delay_us = 100;
592
Bruce Allan17f208d2009-12-01 15:47:22 +0000593 phy->ops.power_up = e1000_power_up_phy_copper;
594 phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
595
Bruce Allane921eb12012-11-28 09:28:37 +0000596 /* We may need to do this twice - once for IGP and if that fails,
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700597 * we'll set BM func pointers and try again
598 */
599 ret_val = e1000e_determine_phy_address(hw);
600 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +0000601 phy->ops.write_reg = e1000e_write_phy_reg_bm;
602 phy->ops.read_reg = e1000e_read_phy_reg_bm;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700603 ret_val = e1000e_determine_phy_address(hw);
Bruce Allan9b71b412009-12-01 15:53:07 +0000604 if (ret_val) {
605 e_dbg("Cannot determine PHY addr. Erroring out\n");
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700606 return ret_val;
Bruce Allan9b71b412009-12-01 15:53:07 +0000607 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700608 }
609
Auke Kokbc7f75f2007-09-17 12:30:59 -0700610 phy->id = 0;
611 while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
612 (i++ < 100)) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000613 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614 ret_val = e1000e_get_phy_id(hw);
615 if (ret_val)
616 return ret_val;
617 }
618
619 /* Verify phy id */
620 switch (phy->id) {
621 case IGP03E1000_E_PHY_ID:
622 phy->type = e1000_phy_igp_3;
623 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000624 phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
625 phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
Bruce Allan0be84012009-12-02 17:03:18 +0000626 phy->ops.get_info = e1000e_get_phy_info_igp;
627 phy->ops.check_polarity = e1000_check_polarity_igp;
628 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700629 break;
630 case IFE_E_PHY_ID:
631 case IFE_PLUS_E_PHY_ID:
632 case IFE_C_E_PHY_ID:
633 phy->type = e1000_phy_ife;
634 phy->autoneg_mask = E1000_ALL_NOT_GIG;
Bruce Allan0be84012009-12-02 17:03:18 +0000635 phy->ops.get_info = e1000_get_phy_info_ife;
636 phy->ops.check_polarity = e1000_check_polarity_ife;
637 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700638 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700639 case BME1000_E_PHY_ID:
640 phy->type = e1000_phy_bm;
641 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
Bruce Allan94d81862009-11-20 23:25:26 +0000642 phy->ops.read_reg = e1000e_read_phy_reg_bm;
643 phy->ops.write_reg = e1000e_write_phy_reg_bm;
644 phy->ops.commit = e1000e_phy_sw_reset;
Bruce Allan0be84012009-12-02 17:03:18 +0000645 phy->ops.get_info = e1000e_get_phy_info_m88;
646 phy->ops.check_polarity = e1000_check_polarity_m88;
647 phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700648 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700649 default:
650 return -E1000_ERR_PHY;
651 break;
652 }
653
654 return 0;
655}
656
657/**
658 * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
659 * @hw: pointer to the HW structure
660 *
661 * Initialize family-specific NVM parameters and function
662 * pointers.
663 **/
664static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
665{
666 struct e1000_nvm_info *nvm = &hw->nvm;
667 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan148675a2009-08-07 07:41:56 +0000668 u32 gfpreg, sector_base_addr, sector_end_addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700669 u16 i;
670
Bruce Allanad680762008-03-28 09:15:03 -0700671 /* Can't read flash registers if the register set isn't mapped. */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700672 if (!hw->flash_address) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000673 e_dbg("ERROR: Flash registers not mapped\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 return -E1000_ERR_CONFIG;
675 }
676
677 nvm->type = e1000_nvm_flash_sw;
678
679 gfpreg = er32flash(ICH_FLASH_GFPREG);
680
Bruce Allane921eb12012-11-28 09:28:37 +0000681 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682 * Add 1 to sector_end_addr since this sector is included in
Bruce Allanad680762008-03-28 09:15:03 -0700683 * the overall size.
684 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700685 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
686 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
687
688 /* flash_base_addr is byte-aligned */
689 nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
690
Bruce Allane921eb12012-11-28 09:28:37 +0000691 /* find total size of the NVM, then cut in half since the total
Bruce Allanad680762008-03-28 09:15:03 -0700692 * size represents two separate NVM banks.
693 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700694 nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
695 << FLASH_SECTOR_ADDR_SHIFT;
696 nvm->flash_bank_size /= 2;
697 /* Adjust to word count */
698 nvm->flash_bank_size /= sizeof(u16);
699
700 nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
701
702 /* Clear shadow ram */
703 for (i = 0; i < nvm->word_size; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +0000704 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705 dev_spec->shadow_ram[i].value = 0xFFFF;
706 }
707
708 return 0;
709}
710
711/**
712 * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
713 * @hw: pointer to the HW structure
714 *
715 * Initialize family-specific MAC parameters and function
716 * pointers.
717 **/
Bruce Allanec34c172012-02-01 10:53:05 +0000718static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700719{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700720 struct e1000_mac_info *mac = &hw->mac;
721
722 /* Set media type function pointer */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700723 hw->phy.media_type = e1000_media_type_copper;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700724
725 /* Set mta register count */
726 mac->mta_reg_count = 32;
727 /* Set rar entry count */
728 mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
729 if (mac->type == e1000_ich8lan)
730 mac->rar_entry_count--;
Bruce Allana65a4a02010-05-10 15:01:51 +0000731 /* FWSM register */
732 mac->has_fwsm = true;
733 /* ARC subsystem not supported */
734 mac->arc_subsystem_valid = false;
Bruce Allanf464ba82010-01-07 16:31:35 +0000735 /* Adaptive IFS supported */
736 mac->adaptive_ifs = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700737
Bruce Allan2fbe4522012-04-19 03:21:47 +0000738 /* LED and other operations */
Bruce Allana4f58f52009-06-02 11:29:18 +0000739 switch (mac->type) {
740 case e1000_ich8lan:
741 case e1000_ich9lan:
742 case e1000_ich10lan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000743 /* check management mode */
744 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000745 /* ID LED init */
Bruce Alland1964eb2012-02-22 09:02:21 +0000746 mac->ops.id_led_init = e1000e_id_led_init_generic;
Bruce Allandbf80dc2011-04-16 00:34:40 +0000747 /* blink LED */
748 mac->ops.blink_led = e1000e_blink_led_generic;
Bruce Allana4f58f52009-06-02 11:29:18 +0000749 /* setup LED */
750 mac->ops.setup_led = e1000e_setup_led_generic;
751 /* cleanup LED */
752 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
753 /* turn on/off LED */
754 mac->ops.led_on = e1000_led_on_ich8lan;
755 mac->ops.led_off = e1000_led_off_ich8lan;
756 break;
Bruce Alland3738bb2010-06-16 13:27:28 +0000757 case e1000_pch2lan:
Bruce Allan69e1e012012-04-14 03:28:50 +0000758 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
759 mac->ops.rar_set = e1000_rar_set_pch2lan;
760 /* fall-through */
Bruce Allan2fbe4522012-04-19 03:21:47 +0000761 case e1000_pch_lpt:
Bruce Allan69e1e012012-04-14 03:28:50 +0000762 case e1000_pchlan:
Bruce Allaneb7700d2010-06-16 13:27:05 +0000763 /* check management mode */
764 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
Bruce Allana4f58f52009-06-02 11:29:18 +0000765 /* ID LED init */
766 mac->ops.id_led_init = e1000_id_led_init_pchlan;
767 /* setup LED */
768 mac->ops.setup_led = e1000_setup_led_pchlan;
769 /* cleanup LED */
770 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
771 /* turn on/off LED */
772 mac->ops.led_on = e1000_led_on_pchlan;
773 mac->ops.led_off = e1000_led_off_pchlan;
774 break;
775 default:
776 break;
777 }
778
Bruce Allan2fbe4522012-04-19 03:21:47 +0000779 if (mac->type == e1000_pch_lpt) {
780 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
781 mac->ops.rar_set = e1000_rar_set_pch_lpt;
782 }
783
Auke Kokbc7f75f2007-09-17 12:30:59 -0700784 /* Enable PCS Lock-loss workaround for ICH8 */
785 if (mac->type == e1000_ich8lan)
Bruce Allan564ea9b2009-11-20 23:26:44 +0000786 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700787
Bruce Allane921eb12012-11-28 09:28:37 +0000788 /* Gate automatic PHY configuration by hardware on managed
Bruce Allan2fbe4522012-04-19 03:21:47 +0000789 * 82579 and i217
790 */
791 if ((mac->type == e1000_pch2lan || mac->type == e1000_pch_lpt) &&
Bruce Allan605c82b2010-09-22 17:17:01 +0000792 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
793 e1000_gate_hw_phy_config_ich8lan(hw, true);
Bruce Alland3738bb2010-06-16 13:27:28 +0000794
Auke Kokbc7f75f2007-09-17 12:30:59 -0700795 return 0;
796}
797
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000798/**
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000799 * __e1000_access_emi_reg_locked - Read/write EMI register
800 * @hw: pointer to the HW structure
801 * @addr: EMI address to program
802 * @data: pointer to value to read/write from/to the EMI address
803 * @read: boolean flag to indicate read or write
804 *
805 * This helper function assumes the SW/FW/HW Semaphore is already acquired.
806 **/
807static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
808 u16 *data, bool read)
809{
810 s32 ret_val = 0;
811
812 ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
813 if (ret_val)
814 return ret_val;
815
816 if (read)
817 ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
818 else
819 ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
820
821 return ret_val;
822}
823
824/**
825 * e1000_read_emi_reg_locked - Read Extended Management Interface register
826 * @hw: pointer to the HW structure
827 * @addr: EMI address to program
828 * @data: value to be read from the EMI address
829 *
830 * Assumes the SW/FW/HW Semaphore is already acquired.
831 **/
832static s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
833{
834 return __e1000_access_emi_reg_locked(hw, addr, data, true);
835}
836
837/**
838 * e1000_write_emi_reg_locked - Write Extended Management Interface register
839 * @hw: pointer to the HW structure
840 * @addr: EMI address to program
841 * @data: value to be written to the EMI address
842 *
843 * Assumes the SW/FW/HW Semaphore is already acquired.
844 **/
845static s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
846{
847 return __e1000_access_emi_reg_locked(hw, addr, &data, false);
848}
849
850/**
Bruce Allane52997f2010-06-16 13:27:49 +0000851 * e1000_set_eee_pchlan - Enable/disable EEE support
852 * @hw: pointer to the HW structure
853 *
Bruce Allan3d4d5752012-12-05 06:26:08 +0000854 * Enable/disable EEE based on setting in dev_spec structure, the duplex of
855 * the link and the EEE capabilities of the link partner. The LPI Control
856 * register bits will remain set only if/when link is up.
Bruce Allane52997f2010-06-16 13:27:49 +0000857 **/
858static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
859{
Bruce Allan2fbe4522012-04-19 03:21:47 +0000860 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan3d4d5752012-12-05 06:26:08 +0000861 s32 ret_val;
862 u16 lpi_ctrl;
Bruce Allane52997f2010-06-16 13:27:49 +0000863
Bruce Allan2fbe4522012-04-19 03:21:47 +0000864 if ((hw->phy.type != e1000_phy_82579) &&
865 (hw->phy.type != e1000_phy_i217))
Bruce Allan5015e532012-02-08 02:55:56 +0000866 return 0;
Bruce Allane52997f2010-06-16 13:27:49 +0000867
Bruce Allan3d4d5752012-12-05 06:26:08 +0000868 ret_val = hw->phy.ops.acquire(hw);
Bruce Allane52997f2010-06-16 13:27:49 +0000869 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000870 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000871
Bruce Allan3d4d5752012-12-05 06:26:08 +0000872 ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000873 if (ret_val)
Bruce Allan3d4d5752012-12-05 06:26:08 +0000874 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000875
Bruce Allan3d4d5752012-12-05 06:26:08 +0000876 /* Clear bits that enable EEE in various speeds */
877 lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
878
879 /* Enable EEE if not disabled by user */
880 if (!dev_spec->eee_disable) {
881 u16 lpa, pcs_status, data;
882
Bruce Allan2fbe4522012-04-19 03:21:47 +0000883 /* Save off link partner's EEE ability */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000884 switch (hw->phy.type) {
885 case e1000_phy_82579:
886 lpa = I82579_EEE_LP_ABILITY;
887 pcs_status = I82579_EEE_PCS_STATUS;
888 break;
889 case e1000_phy_i217:
890 lpa = I217_EEE_LP_ABILITY;
891 pcs_status = I217_EEE_PCS_STATUS;
892 break;
893 default:
894 ret_val = -E1000_ERR_PHY;
895 goto release;
896 }
897 ret_val = e1000_read_emi_reg_locked(hw, lpa,
Bruce Allan4ddc48a2012-12-05 06:25:58 +0000898 &dev_spec->eee_lp_ability);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000899 if (ret_val)
900 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000901
Bruce Allan3d4d5752012-12-05 06:26:08 +0000902 /* Enable EEE only for speeds in which the link partner is
903 * EEE capable.
Bruce Allan2fbe4522012-04-19 03:21:47 +0000904 */
Bruce Allan3d4d5752012-12-05 06:26:08 +0000905 if (dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
906 lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
907
908 if (dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
909 e1e_rphy_locked(hw, PHY_LP_ABILITY, &data);
910 if (data & NWAY_LPAR_100TX_FD_CAPS)
911 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
912 else
913 /* EEE is not supported in 100Half, so ignore
914 * partner's EEE in 100 ability if full-duplex
915 * is not advertised.
916 */
917 dev_spec->eee_lp_ability &=
918 ~I82579_EEE_100_SUPPORTED;
919 }
920
921 /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
922 ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
923 if (ret_val)
924 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000925 }
926
Bruce Allan3d4d5752012-12-05 06:26:08 +0000927 ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
928release:
929 hw->phy.ops.release(hw);
930
931 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +0000932}
933
934/**
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000935 * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
936 * @hw: pointer to the HW structure
937 *
938 * Checks to see of the link status of the hardware has changed. If a
939 * change in link status has been detected, then we read the PHY registers
940 * to get the current speed/duplex if link exists.
941 **/
942static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
943{
944 struct e1000_mac_info *mac = &hw->mac;
945 s32 ret_val;
946 bool link;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000947 u16 phy_reg;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000948
Bruce Allane921eb12012-11-28 09:28:37 +0000949 /* We only want to go out to the PHY registers to see if Auto-Neg
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000950 * has completed and/or if our link status has changed. The
951 * get_link_status flag is set upon receiving a Link Status
952 * Change or Rx Sequence Error interrupt.
953 */
Bruce Allan5015e532012-02-08 02:55:56 +0000954 if (!mac->get_link_status)
955 return 0;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000956
Bruce Allane921eb12012-11-28 09:28:37 +0000957 /* First we want to see if the MII Status Register reports
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000958 * link. If so, then we want to get the current speed/duplex
959 * of the PHY.
960 */
961 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
962 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000963 return ret_val;
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000964
Bruce Allan1d5846b2009-10-29 13:46:05 +0000965 if (hw->mac.type == e1000_pchlan) {
966 ret_val = e1000_k1_gig_workaround_hv(hw, link);
967 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000968 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +0000969 }
970
Bruce Allan2fbe4522012-04-19 03:21:47 +0000971 /* Clear link partner's EEE ability */
972 hw->dev_spec.ich8lan.eee_lp_ability = 0;
973
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000974 if (!link)
Bruce Allan5015e532012-02-08 02:55:56 +0000975 return 0; /* No link detected */
Bruce Allan7d3cabb2009-07-01 13:29:08 +0000976
977 mac->get_link_status = false;
978
Bruce Allan1d2101a72011-07-22 06:21:56 +0000979 switch (hw->mac.type) {
980 case e1000_pch2lan:
Bruce Allan831bd2e2010-09-22 17:16:18 +0000981 ret_val = e1000_k1_workaround_lv(hw);
982 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000983 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000984 /* fall-thru */
985 case e1000_pchlan:
986 if (hw->phy.type == e1000_phy_82578) {
987 ret_val = e1000_link_stall_workaround_hv(hw);
988 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +0000989 return ret_val;
Bruce Allan1d2101a72011-07-22 06:21:56 +0000990 }
991
Bruce Allane921eb12012-11-28 09:28:37 +0000992 /* Workaround for PCHx parts in half-duplex:
Bruce Allan1d2101a72011-07-22 06:21:56 +0000993 * Set the number of preambles removed from the packet
994 * when it is passed from the PHY to the MAC to prevent
995 * the MAC from misinterpreting the packet type.
996 */
997 e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
998 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
999
1000 if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
1001 phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
1002
1003 e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
1004 break;
1005 default:
1006 break;
Bruce Allan831bd2e2010-09-22 17:16:18 +00001007 }
1008
Bruce Allane921eb12012-11-28 09:28:37 +00001009 /* Check if there was DownShift, must be checked
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001010 * immediately after link-up
1011 */
1012 e1000e_check_downshift(hw);
1013
Bruce Allane52997f2010-06-16 13:27:49 +00001014 /* Enable/Disable EEE after link up */
1015 ret_val = e1000_set_eee_pchlan(hw);
1016 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001017 return ret_val;
Bruce Allane52997f2010-06-16 13:27:49 +00001018
Bruce Allane921eb12012-11-28 09:28:37 +00001019 /* If we are forcing speed/duplex, then we simply return since
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001020 * we have already determined whether we have link or not.
1021 */
Bruce Allan5015e532012-02-08 02:55:56 +00001022 if (!mac->autoneg)
1023 return -E1000_ERR_CONFIG;
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001024
Bruce Allane921eb12012-11-28 09:28:37 +00001025 /* Auto-Neg is enabled. Auto Speed Detection takes care
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001026 * of MAC speed/duplex configuration. So we only need to
1027 * configure Collision Distance in the MAC.
1028 */
Bruce Allan57cde762012-02-22 09:02:58 +00001029 mac->ops.config_collision_dist(hw);
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001030
Bruce Allane921eb12012-11-28 09:28:37 +00001031 /* Configure Flow Control now that Auto-Neg has completed.
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001032 * First, we need to restore the desired flow control
1033 * settings because we may have had to re-autoneg with a
1034 * different link partner.
1035 */
1036 ret_val = e1000e_config_fc_after_link_up(hw);
1037 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001038 e_dbg("Error configuring flow control\n");
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001039
Bruce Allan7d3cabb2009-07-01 13:29:08 +00001040 return ret_val;
1041}
1042
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07001043static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001044{
1045 struct e1000_hw *hw = &adapter->hw;
1046 s32 rc;
1047
Bruce Allanec34c172012-02-01 10:53:05 +00001048 rc = e1000_init_mac_params_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049 if (rc)
1050 return rc;
1051
1052 rc = e1000_init_nvm_params_ich8lan(hw);
1053 if (rc)
1054 return rc;
1055
Bruce Alland3738bb2010-06-16 13:27:28 +00001056 switch (hw->mac.type) {
1057 case e1000_ich8lan:
1058 case e1000_ich9lan:
1059 case e1000_ich10lan:
Bruce Allana4f58f52009-06-02 11:29:18 +00001060 rc = e1000_init_phy_params_ich8lan(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001061 break;
1062 case e1000_pchlan:
1063 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001064 case e1000_pch_lpt:
Bruce Alland3738bb2010-06-16 13:27:28 +00001065 rc = e1000_init_phy_params_pchlan(hw);
1066 break;
1067 default:
1068 break;
1069 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001070 if (rc)
1071 return rc;
1072
Bruce Allane921eb12012-11-28 09:28:37 +00001073 /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
Bruce Allan23e4f062011-02-25 07:44:51 +00001074 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
1075 */
1076 if ((adapter->hw.phy.type == e1000_phy_ife) ||
1077 ((adapter->hw.mac.type >= e1000_pch2lan) &&
1078 (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
Bruce Allan2adc55c2009-06-02 11:28:58 +00001079 adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
1080 adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
Bruce Allandbf80dc2011-04-16 00:34:40 +00001081
1082 hw->mac.ops.blink_led = NULL;
Bruce Allan2adc55c2009-06-02 11:28:58 +00001083 }
1084
Auke Kokbc7f75f2007-09-17 12:30:59 -07001085 if ((adapter->hw.mac.type == e1000_ich8lan) &&
Bruce Allan462d5992011-09-30 08:07:11 +00001086 (adapter->hw.phy.type != e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001087 adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
1088
Bruce Allanc6e7f512011-07-29 05:53:02 +00001089 /* Enable workaround for 82579 w/ ME enabled */
1090 if ((adapter->hw.mac.type == e1000_pch2lan) &&
1091 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1092 adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
1093
Bruce Allan5a86f282010-06-29 18:13:13 +00001094 /* Disable EEE by default until IEEE802.3az spec is finalized */
1095 if (adapter->flags2 & FLAG2_HAS_EEE)
1096 adapter->hw.dev_spec.ich8lan.eee_disable = true;
1097
Auke Kokbc7f75f2007-09-17 12:30:59 -07001098 return 0;
1099}
1100
Thomas Gleixner717d4382008-10-02 16:33:40 -07001101static DEFINE_MUTEX(nvm_mutex);
Thomas Gleixner717d4382008-10-02 16:33:40 -07001102
Auke Kokbc7f75f2007-09-17 12:30:59 -07001103/**
Bruce Allanca15df52009-10-26 11:23:43 +00001104 * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
1105 * @hw: pointer to the HW structure
1106 *
1107 * Acquires the mutex for performing NVM operations.
1108 **/
1109static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
1110{
1111 mutex_lock(&nvm_mutex);
1112
1113 return 0;
1114}
1115
1116/**
1117 * e1000_release_nvm_ich8lan - Release NVM mutex
1118 * @hw: pointer to the HW structure
1119 *
1120 * Releases the mutex used while performing NVM operations.
1121 **/
1122static void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
1123{
1124 mutex_unlock(&nvm_mutex);
Bruce Allanca15df52009-10-26 11:23:43 +00001125}
1126
Bruce Allanca15df52009-10-26 11:23:43 +00001127/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 * e1000_acquire_swflag_ich8lan - Acquire software control flag
1129 * @hw: pointer to the HW structure
1130 *
Bruce Allanca15df52009-10-26 11:23:43 +00001131 * Acquires the software control flag for performing PHY and select
1132 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001133 **/
1134static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
1135{
Bruce Allan373a88d2009-08-07 07:41:37 +00001136 u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
1137 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138
Bruce Allana90b4122011-10-07 03:50:38 +00001139 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
1140 &hw->adapter->state)) {
Bruce Allan34c9ef82011-10-21 04:33:47 +00001141 e_dbg("contention for Phy access\n");
Bruce Allana90b4122011-10-07 03:50:38 +00001142 return -E1000_ERR_PHY;
1143 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001144
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145 while (timeout) {
1146 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allan373a88d2009-08-07 07:41:37 +00001147 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
1148 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001149
Auke Kokbc7f75f2007-09-17 12:30:59 -07001150 mdelay(1);
1151 timeout--;
1152 }
1153
1154 if (!timeout) {
Bruce Allana90b4122011-10-07 03:50:38 +00001155 e_dbg("SW has already locked the resource.\n");
Bruce Allan373a88d2009-08-07 07:41:37 +00001156 ret_val = -E1000_ERR_CONFIG;
1157 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158 }
1159
Bruce Allan53ac5a82009-10-26 11:23:06 +00001160 timeout = SW_FLAG_TIMEOUT;
Bruce Allan373a88d2009-08-07 07:41:37 +00001161
1162 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
1163 ew32(EXTCNF_CTRL, extcnf_ctrl);
1164
1165 while (timeout) {
1166 extcnf_ctrl = er32(EXTCNF_CTRL);
1167 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
1168 break;
1169
1170 mdelay(1);
1171 timeout--;
1172 }
1173
1174 if (!timeout) {
Bruce Allan434f1392011-12-16 00:46:54 +00001175 e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
Bruce Allana90b4122011-10-07 03:50:38 +00001176 er32(FWSM), extcnf_ctrl);
Bruce Allan373a88d2009-08-07 07:41:37 +00001177 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1178 ew32(EXTCNF_CTRL, extcnf_ctrl);
1179 ret_val = -E1000_ERR_CONFIG;
1180 goto out;
1181 }
1182
1183out:
1184 if (ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00001185 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Bruce Allan373a88d2009-08-07 07:41:37 +00001186
1187 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188}
1189
1190/**
1191 * e1000_release_swflag_ich8lan - Release software control flag
1192 * @hw: pointer to the HW structure
1193 *
Bruce Allanca15df52009-10-26 11:23:43 +00001194 * Releases the software control flag for performing PHY and select
1195 * MAC CSR accesses.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001196 **/
1197static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
1198{
1199 u32 extcnf_ctrl;
1200
1201 extcnf_ctrl = er32(EXTCNF_CTRL);
Bruce Allanc5caf482011-05-13 07:19:53 +00001202
1203 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
1204 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
1205 ew32(EXTCNF_CTRL, extcnf_ctrl);
1206 } else {
1207 e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
1208 }
Thomas Gleixner717d4382008-10-02 16:33:40 -07001209
Bruce Allana90b4122011-10-07 03:50:38 +00001210 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211}
1212
1213/**
Bruce Allan4662e822008-08-26 18:37:06 -07001214 * e1000_check_mng_mode_ich8lan - Checks management mode
1215 * @hw: pointer to the HW structure
1216 *
Bruce Allaneb7700d2010-06-16 13:27:05 +00001217 * This checks if the adapter has any manageability enabled.
Bruce Allan4662e822008-08-26 18:37:06 -07001218 * This is a function pointer entry point only called by read/write
1219 * routines for the PHY and NVM parts.
1220 **/
1221static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
1222{
Bruce Allana708dd82009-11-20 23:28:37 +00001223 u32 fwsm;
1224
1225 fwsm = er32(FWSM);
Bruce Allaneb7700d2010-06-16 13:27:05 +00001226 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1227 ((fwsm & E1000_FWSM_MODE_MASK) ==
1228 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1229}
Bruce Allan4662e822008-08-26 18:37:06 -07001230
Bruce Allaneb7700d2010-06-16 13:27:05 +00001231/**
1232 * e1000_check_mng_mode_pchlan - Checks management mode
1233 * @hw: pointer to the HW structure
1234 *
1235 * This checks if the adapter has iAMT enabled.
1236 * This is a function pointer entry point only called by read/write
1237 * routines for the PHY and NVM parts.
1238 **/
1239static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
1240{
1241 u32 fwsm;
1242
1243 fwsm = er32(FWSM);
1244 return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1245 (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
Bruce Allan4662e822008-08-26 18:37:06 -07001246}
1247
1248/**
Bruce Allan69e1e012012-04-14 03:28:50 +00001249 * e1000_rar_set_pch2lan - Set receive address register
1250 * @hw: pointer to the HW structure
1251 * @addr: pointer to the receive address
1252 * @index: receive address array register
1253 *
1254 * Sets the receive address array register at index to the address passed
1255 * in by addr. For 82579, RAR[0] is the base address register that is to
1256 * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
1257 * Use SHRA[0-3] in place of those reserved for ME.
1258 **/
1259static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
1260{
1261 u32 rar_low, rar_high;
1262
Bruce Allane921eb12012-11-28 09:28:37 +00001263 /* HW expects these in little endian so we reverse the byte order
Bruce Allan69e1e012012-04-14 03:28:50 +00001264 * from network order (big endian) to little endian
1265 */
1266 rar_low = ((u32)addr[0] |
1267 ((u32)addr[1] << 8) |
1268 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1269
1270 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1271
1272 /* If MAC address zero, no need to set the AV bit */
1273 if (rar_low || rar_high)
1274 rar_high |= E1000_RAH_AV;
1275
1276 if (index == 0) {
1277 ew32(RAL(index), rar_low);
1278 e1e_flush();
1279 ew32(RAH(index), rar_high);
1280 e1e_flush();
1281 return;
1282 }
1283
1284 if (index < hw->mac.rar_entry_count) {
1285 s32 ret_val;
1286
1287 ret_val = e1000_acquire_swflag_ich8lan(hw);
1288 if (ret_val)
1289 goto out;
1290
1291 ew32(SHRAL(index - 1), rar_low);
1292 e1e_flush();
1293 ew32(SHRAH(index - 1), rar_high);
1294 e1e_flush();
1295
1296 e1000_release_swflag_ich8lan(hw);
1297
1298 /* verify the register updates */
1299 if ((er32(SHRAL(index - 1)) == rar_low) &&
1300 (er32(SHRAH(index - 1)) == rar_high))
1301 return;
1302
1303 e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
1304 (index - 1), er32(FWSM));
1305 }
1306
1307out:
1308 e_dbg("Failed to write receive address at index %d\n", index);
1309}
1310
1311/**
Bruce Allan2fbe4522012-04-19 03:21:47 +00001312 * e1000_rar_set_pch_lpt - Set receive address registers
1313 * @hw: pointer to the HW structure
1314 * @addr: pointer to the receive address
1315 * @index: receive address array register
1316 *
1317 * Sets the receive address register array at index to the address passed
1318 * in by addr. For LPT, RAR[0] is the base address register that is to
1319 * contain the MAC address. SHRA[0-10] are the shared receive address
1320 * registers that are shared between the Host and manageability engine (ME).
1321 **/
1322static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
1323{
1324 u32 rar_low, rar_high;
1325 u32 wlock_mac;
1326
Bruce Allane921eb12012-11-28 09:28:37 +00001327 /* HW expects these in little endian so we reverse the byte order
Bruce Allan2fbe4522012-04-19 03:21:47 +00001328 * from network order (big endian) to little endian
1329 */
1330 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
1331 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
1332
1333 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
1334
1335 /* If MAC address zero, no need to set the AV bit */
1336 if (rar_low || rar_high)
1337 rar_high |= E1000_RAH_AV;
1338
1339 if (index == 0) {
1340 ew32(RAL(index), rar_low);
1341 e1e_flush();
1342 ew32(RAH(index), rar_high);
1343 e1e_flush();
1344 return;
1345 }
1346
Bruce Allane921eb12012-11-28 09:28:37 +00001347 /* The manageability engine (ME) can lock certain SHRAR registers that
Bruce Allan2fbe4522012-04-19 03:21:47 +00001348 * it is using - those registers are unavailable for use.
1349 */
1350 if (index < hw->mac.rar_entry_count) {
1351 wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
1352 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
1353
1354 /* Check if all SHRAR registers are locked */
1355 if (wlock_mac == 1)
1356 goto out;
1357
1358 if ((wlock_mac == 0) || (index <= wlock_mac)) {
1359 s32 ret_val;
1360
1361 ret_val = e1000_acquire_swflag_ich8lan(hw);
1362
1363 if (ret_val)
1364 goto out;
1365
1366 ew32(SHRAL_PCH_LPT(index - 1), rar_low);
1367 e1e_flush();
1368 ew32(SHRAH_PCH_LPT(index - 1), rar_high);
1369 e1e_flush();
1370
1371 e1000_release_swflag_ich8lan(hw);
1372
1373 /* verify the register updates */
1374 if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
1375 (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
1376 return;
1377 }
1378 }
1379
1380out:
1381 e_dbg("Failed to write receive address at index %d\n", index);
1382}
1383
1384/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001385 * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
1386 * @hw: pointer to the HW structure
1387 *
1388 * Checks if firmware is blocking the reset of the PHY.
1389 * This is a function pointer entry point only called by
1390 * reset routines.
1391 **/
1392static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
1393{
1394 u32 fwsm;
1395
1396 fwsm = er32(FWSM);
1397
1398 return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? 0 : E1000_BLK_PHY_RESET;
1399}
1400
1401/**
Bruce Allan8395ae82010-09-22 17:15:08 +00001402 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
1403 * @hw: pointer to the HW structure
1404 *
1405 * Assumes semaphore already acquired.
1406 *
1407 **/
1408static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
1409{
1410 u16 phy_data;
1411 u32 strap = er32(STRAP);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001412 u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
1413 E1000_STRAP_SMT_FREQ_SHIFT;
Bruce Allan8395ae82010-09-22 17:15:08 +00001414 s32 ret_val = 0;
1415
1416 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
1417
1418 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
1419 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001420 return ret_val;
Bruce Allan8395ae82010-09-22 17:15:08 +00001421
1422 phy_data &= ~HV_SMB_ADDR_MASK;
1423 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
1424 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
Bruce Allan8395ae82010-09-22 17:15:08 +00001425
Bruce Allan2fbe4522012-04-19 03:21:47 +00001426 if (hw->phy.type == e1000_phy_i217) {
1427 /* Restore SMBus frequency */
1428 if (freq--) {
1429 phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
1430 phy_data |= (freq & (1 << 0)) <<
1431 HV_SMB_ADDR_FREQ_LOW_SHIFT;
1432 phy_data |= (freq & (1 << 1)) <<
1433 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
1434 } else {
1435 e_dbg("Unsupported SMB frequency in PHY\n");
1436 }
1437 }
1438
Bruce Allan5015e532012-02-08 02:55:56 +00001439 return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
Bruce Allan8395ae82010-09-22 17:15:08 +00001440}
1441
1442/**
Bruce Allanf523d212009-10-29 13:45:45 +00001443 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
1444 * @hw: pointer to the HW structure
1445 *
1446 * SW should configure the LCD from the NVM extended configuration region
1447 * as a workaround for certain parts.
1448 **/
1449static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
1450{
1451 struct e1000_phy_info *phy = &hw->phy;
1452 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
Bruce Allan8b802a72010-05-10 15:01:10 +00001453 s32 ret_val = 0;
Bruce Allanf523d212009-10-29 13:45:45 +00001454 u16 word_addr, reg_data, reg_addr, phy_page = 0;
1455
Bruce Allane921eb12012-11-28 09:28:37 +00001456 /* Initialize the PHY from the NVM on ICH platforms. This
Bruce Allanf523d212009-10-29 13:45:45 +00001457 * is needed due to an issue where the NVM configuration is
1458 * not properly autoloaded after power transitions.
1459 * Therefore, after each PHY reset, we will load the
1460 * configuration data out of the NVM manually.
1461 */
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001462 switch (hw->mac.type) {
1463 case e1000_ich8lan:
1464 if (phy->type != e1000_phy_igp_3)
1465 return ret_val;
1466
Bruce Allan5f3eed62010-09-22 17:15:54 +00001467 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
1468 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001469 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
1470 break;
1471 }
1472 /* Fall-thru */
1473 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +00001474 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +00001475 case e1000_pch_lpt:
Bruce Allan8b802a72010-05-10 15:01:10 +00001476 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
Bruce Allan3f0c16e2010-06-16 13:26:17 +00001477 break;
1478 default:
1479 return ret_val;
1480 }
1481
1482 ret_val = hw->phy.ops.acquire(hw);
1483 if (ret_val)
1484 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00001485
Bruce Allan8b802a72010-05-10 15:01:10 +00001486 data = er32(FEXTNVM);
1487 if (!(data & sw_cfg_mask))
Bruce Allan75ce1532012-02-08 02:54:48 +00001488 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001489
Bruce Allane921eb12012-11-28 09:28:37 +00001490 /* Make sure HW does not configure LCD from PHY
Bruce Allan8b802a72010-05-10 15:01:10 +00001491 * extended configuration before SW configuration
1492 */
1493 data = er32(EXTCNF_CTRL);
Bruce Allan2fbe4522012-04-19 03:21:47 +00001494 if ((hw->mac.type < e1000_pch2lan) &&
1495 (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
1496 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001497
Bruce Allan8b802a72010-05-10 15:01:10 +00001498 cnf_size = er32(EXTCNF_SIZE);
1499 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
1500 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
1501 if (!cnf_size)
Bruce Allan75ce1532012-02-08 02:54:48 +00001502 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001503
1504 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
1505 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
1506
Bruce Allan2fbe4522012-04-19 03:21:47 +00001507 if (((hw->mac.type == e1000_pchlan) &&
1508 !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
1509 (hw->mac.type > e1000_pchlan)) {
Bruce Allane921eb12012-11-28 09:28:37 +00001510 /* HW configures the SMBus address and LEDs when the
Bruce Allan8b802a72010-05-10 15:01:10 +00001511 * OEM and LCD Write Enable bits are set in the NVM.
1512 * When both NVM bits are cleared, SW will configure
1513 * them instead.
Bruce Allanf523d212009-10-29 13:45:45 +00001514 */
Bruce Allan8395ae82010-09-22 17:15:08 +00001515 ret_val = e1000_write_smbus_addr(hw);
Bruce Allan8b802a72010-05-10 15:01:10 +00001516 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001517 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001518
Bruce Allan8b802a72010-05-10 15:01:10 +00001519 data = er32(LEDCTL);
1520 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
1521 (u16)data);
1522 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001523 goto release;
Bruce Allan8b802a72010-05-10 15:01:10 +00001524 }
1525
1526 /* Configure LCD from extended configuration region. */
1527
1528 /* cnf_base_addr is in DWORD */
1529 word_addr = (u16)(cnf_base_addr << 1);
1530
1531 for (i = 0; i < cnf_size; i++) {
1532 ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1,
1533 &reg_data);
1534 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001535 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001536
Bruce Allan8b802a72010-05-10 15:01:10 +00001537 ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
1538 1, &reg_addr);
1539 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001540 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001541
Bruce Allan8b802a72010-05-10 15:01:10 +00001542 /* Save off the PHY page for future writes. */
1543 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
1544 phy_page = reg_data;
1545 continue;
Bruce Allanf523d212009-10-29 13:45:45 +00001546 }
Bruce Allanf523d212009-10-29 13:45:45 +00001547
Bruce Allan8b802a72010-05-10 15:01:10 +00001548 reg_addr &= PHY_REG_MASK;
1549 reg_addr |= phy_page;
Bruce Allanf523d212009-10-29 13:45:45 +00001550
Bruce Allanf1430d62012-04-14 04:21:52 +00001551 ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
Bruce Allan8b802a72010-05-10 15:01:10 +00001552 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001553 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001554 }
1555
Bruce Allan75ce1532012-02-08 02:54:48 +00001556release:
Bruce Allan94d81862009-11-20 23:25:26 +00001557 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001558 return ret_val;
1559}
1560
1561/**
Bruce Allan1d5846b2009-10-29 13:46:05 +00001562 * e1000_k1_gig_workaround_hv - K1 Si workaround
1563 * @hw: pointer to the HW structure
1564 * @link: link up bool flag
1565 *
1566 * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
1567 * from a lower speed. This workaround disables K1 whenever link is at 1Gig
1568 * If link is down, the function will restore the default K1 setting located
1569 * in the NVM.
1570 **/
1571static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
1572{
1573 s32 ret_val = 0;
1574 u16 status_reg = 0;
1575 bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
1576
1577 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001578 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001579
1580 /* Wrap the whole flow with the sw flag */
Bruce Allan94d81862009-11-20 23:25:26 +00001581 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001582 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001583 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001584
1585 /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
1586 if (link) {
1587 if (hw->phy.type == e1000_phy_82578) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001588 ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
1589 &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001590 if (ret_val)
1591 goto release;
1592
1593 status_reg &= BM_CS_STATUS_LINK_UP |
1594 BM_CS_STATUS_RESOLVED |
1595 BM_CS_STATUS_SPEED_MASK;
1596
1597 if (status_reg == (BM_CS_STATUS_LINK_UP |
1598 BM_CS_STATUS_RESOLVED |
1599 BM_CS_STATUS_SPEED_1000))
1600 k1_enable = false;
1601 }
1602
1603 if (hw->phy.type == e1000_phy_82577) {
Bruce Allanf1430d62012-04-14 04:21:52 +00001604 ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001605 if (ret_val)
1606 goto release;
1607
1608 status_reg &= HV_M_STATUS_LINK_UP |
1609 HV_M_STATUS_AUTONEG_COMPLETE |
1610 HV_M_STATUS_SPEED_MASK;
1611
1612 if (status_reg == (HV_M_STATUS_LINK_UP |
1613 HV_M_STATUS_AUTONEG_COMPLETE |
1614 HV_M_STATUS_SPEED_1000))
1615 k1_enable = false;
1616 }
1617
1618 /* Link stall fix for link up */
Bruce Allanf1430d62012-04-14 04:21:52 +00001619 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001620 if (ret_val)
1621 goto release;
1622
1623 } else {
1624 /* Link stall fix for link down */
Bruce Allanf1430d62012-04-14 04:21:52 +00001625 ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001626 if (ret_val)
1627 goto release;
1628 }
1629
1630 ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1631
1632release:
Bruce Allan94d81862009-11-20 23:25:26 +00001633 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001634
Bruce Allan1d5846b2009-10-29 13:46:05 +00001635 return ret_val;
1636}
1637
1638/**
1639 * e1000_configure_k1_ich8lan - Configure K1 power state
1640 * @hw: pointer to the HW structure
1641 * @enable: K1 state to configure
1642 *
1643 * Configure the K1 power state based on the provided parameter.
1644 * Assumes semaphore already acquired.
1645 *
1646 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1647 **/
Bruce Allanbb436b22009-11-20 23:24:11 +00001648s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
Bruce Allan1d5846b2009-10-29 13:46:05 +00001649{
1650 s32 ret_val = 0;
1651 u32 ctrl_reg = 0;
1652 u32 ctrl_ext = 0;
1653 u32 reg = 0;
1654 u16 kmrn_reg = 0;
1655
Bruce Allan3d3a1672012-02-23 03:13:18 +00001656 ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1657 &kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001658 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001659 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001660
1661 if (k1_enable)
1662 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1663 else
1664 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1665
Bruce Allan3d3a1672012-02-23 03:13:18 +00001666 ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
1667 kmrn_reg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001668 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001669 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001670
1671 udelay(20);
1672 ctrl_ext = er32(CTRL_EXT);
1673 ctrl_reg = er32(CTRL);
1674
1675 reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1676 reg |= E1000_CTRL_FRCSPD;
1677 ew32(CTRL, reg);
1678
1679 ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001680 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001681 udelay(20);
1682 ew32(CTRL, ctrl_reg);
1683 ew32(CTRL_EXT, ctrl_ext);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001684 e1e_flush();
Bruce Allan1d5846b2009-10-29 13:46:05 +00001685 udelay(20);
1686
Bruce Allan5015e532012-02-08 02:55:56 +00001687 return 0;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001688}
1689
1690/**
Bruce Allanf523d212009-10-29 13:45:45 +00001691 * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1692 * @hw: pointer to the HW structure
1693 * @d0_state: boolean if entering d0 or d3 device state
1694 *
1695 * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1696 * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
1697 * in NVM determines whether HW should configure LPLU and Gbe Disable.
1698 **/
1699static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1700{
1701 s32 ret_val = 0;
1702 u32 mac_reg;
1703 u16 oem_reg;
1704
Bruce Allan2fbe4522012-04-19 03:21:47 +00001705 if (hw->mac.type < e1000_pchlan)
Bruce Allanf523d212009-10-29 13:45:45 +00001706 return ret_val;
1707
Bruce Allan94d81862009-11-20 23:25:26 +00001708 ret_val = hw->phy.ops.acquire(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001709 if (ret_val)
1710 return ret_val;
1711
Bruce Allan2fbe4522012-04-19 03:21:47 +00001712 if (hw->mac.type == e1000_pchlan) {
Bruce Alland3738bb2010-06-16 13:27:28 +00001713 mac_reg = er32(EXTCNF_CTRL);
1714 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
Bruce Allan75ce1532012-02-08 02:54:48 +00001715 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001716 }
Bruce Allanf523d212009-10-29 13:45:45 +00001717
1718 mac_reg = er32(FEXTNVM);
1719 if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
Bruce Allan75ce1532012-02-08 02:54:48 +00001720 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001721
1722 mac_reg = er32(PHY_CTRL);
1723
Bruce Allanf1430d62012-04-14 04:21:52 +00001724 ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001725 if (ret_val)
Bruce Allan75ce1532012-02-08 02:54:48 +00001726 goto release;
Bruce Allanf523d212009-10-29 13:45:45 +00001727
1728 oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1729
1730 if (d0_state) {
1731 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1732 oem_reg |= HV_OEM_BITS_GBE_DIS;
1733
1734 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1735 oem_reg |= HV_OEM_BITS_LPLU;
1736 } else {
Bruce Allan03299e42011-09-30 08:07:05 +00001737 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
1738 E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
Bruce Allanf523d212009-10-29 13:45:45 +00001739 oem_reg |= HV_OEM_BITS_GBE_DIS;
1740
Bruce Allan03299e42011-09-30 08:07:05 +00001741 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
1742 E1000_PHY_CTRL_NOND0A_LPLU))
Bruce Allanf523d212009-10-29 13:45:45 +00001743 oem_reg |= HV_OEM_BITS_LPLU;
1744 }
Bruce Allan03299e42011-09-30 08:07:05 +00001745
Bruce Allan92fe1732012-04-12 06:27:03 +00001746 /* Set Restart auto-neg to activate the bits */
1747 if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
1748 !hw->phy.ops.check_reset_block(hw))
1749 oem_reg |= HV_OEM_BITS_RESTART_AN;
1750
Bruce Allanf1430d62012-04-14 04:21:52 +00001751 ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
Bruce Allanf523d212009-10-29 13:45:45 +00001752
Bruce Allan75ce1532012-02-08 02:54:48 +00001753release:
Bruce Allan94d81862009-11-20 23:25:26 +00001754 hw->phy.ops.release(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00001755
1756 return ret_val;
1757}
1758
1759
1760/**
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001761 * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1762 * @hw: pointer to the HW structure
1763 **/
1764static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1765{
1766 s32 ret_val;
1767 u16 data;
1768
1769 ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
1770 if (ret_val)
1771 return ret_val;
1772
1773 data |= HV_KMRN_MDIO_SLOW;
1774
1775 ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
1776
1777 return ret_val;
1778}
1779
1780/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001781 * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1782 * done after every PHY reset.
1783 **/
1784static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1785{
1786 s32 ret_val = 0;
Bruce Allanbaf86c92010-01-13 01:53:08 +00001787 u16 phy_data;
Bruce Allana4f58f52009-06-02 11:29:18 +00001788
1789 if (hw->mac.type != e1000_pchlan)
Bruce Allan5015e532012-02-08 02:55:56 +00001790 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00001791
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001792 /* Set MDIO slow mode before any other MDIO access */
1793 if (hw->phy.type == e1000_phy_82577) {
1794 ret_val = e1000_set_mdio_slow_mode_hv(hw);
1795 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001796 return ret_val;
Bruce Allanfddaa1a2010-01-13 01:52:49 +00001797 }
1798
Bruce Allana4f58f52009-06-02 11:29:18 +00001799 if (((hw->phy.type == e1000_phy_82577) &&
1800 ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1801 ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1802 /* Disable generation of early preamble */
1803 ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
1804 if (ret_val)
1805 return ret_val;
1806
1807 /* Preamble tuning for SSC */
Bruce Allan1d2101a72011-07-22 06:21:56 +00001808 ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
Bruce Allana4f58f52009-06-02 11:29:18 +00001809 if (ret_val)
1810 return ret_val;
1811 }
1812
1813 if (hw->phy.type == e1000_phy_82578) {
Bruce Allane921eb12012-11-28 09:28:37 +00001814 /* Return registers to default by doing a soft reset then
Bruce Allana4f58f52009-06-02 11:29:18 +00001815 * writing 0x3140 to the control register.
1816 */
1817 if (hw->phy.revision < 2) {
1818 e1000e_phy_sw_reset(hw);
1819 ret_val = e1e_wphy(hw, PHY_CONTROL, 0x3140);
1820 }
1821 }
1822
1823 /* Select page 0 */
Bruce Allan94d81862009-11-20 23:25:26 +00001824 ret_val = hw->phy.ops.acquire(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001825 if (ret_val)
1826 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001827
Bruce Allana4f58f52009-06-02 11:29:18 +00001828 hw->phy.addr = 1;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001829 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001830 hw->phy.ops.release(hw);
Bruce Allan1d5846b2009-10-29 13:46:05 +00001831 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001832 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00001833
Bruce Allane921eb12012-11-28 09:28:37 +00001834 /* Configure the K1 Si workaround during phy reset assuming there is
Bruce Allan1d5846b2009-10-29 13:46:05 +00001835 * link so that it disables K1 if link is in 1Gbps.
1836 */
1837 ret_val = e1000_k1_gig_workaround_hv(hw, true);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001838 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001839 return ret_val;
Bruce Allan1d5846b2009-10-29 13:46:05 +00001840
Bruce Allanbaf86c92010-01-13 01:53:08 +00001841 /* Workaround for link disconnects on a busy hub in half duplex */
1842 ret_val = hw->phy.ops.acquire(hw);
1843 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001844 return ret_val;
Bruce Allanf1430d62012-04-14 04:21:52 +00001845 ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001846 if (ret_val)
1847 goto release;
Bruce Allanf1430d62012-04-14 04:21:52 +00001848 ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
Bruce Allan651fb102012-12-05 06:26:03 +00001849 if (ret_val)
1850 goto release;
1851
1852 /* set MSE higher to enable link to stay up when noise is high */
1853 ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
Bruce Allanbaf86c92010-01-13 01:53:08 +00001854release:
1855 hw->phy.ops.release(hw);
Bruce Allan5015e532012-02-08 02:55:56 +00001856
Bruce Allana4f58f52009-06-02 11:29:18 +00001857 return ret_val;
1858}
1859
1860/**
Bruce Alland3738bb2010-06-16 13:27:28 +00001861 * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
1862 * @hw: pointer to the HW structure
1863 **/
1864void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
1865{
1866 u32 mac_reg;
Bruce Allan2b6b1682011-05-13 07:20:09 +00001867 u16 i, phy_reg = 0;
1868 s32 ret_val;
1869
1870 ret_val = hw->phy.ops.acquire(hw);
1871 if (ret_val)
1872 return;
1873 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1874 if (ret_val)
1875 goto release;
Bruce Alland3738bb2010-06-16 13:27:28 +00001876
1877 /* Copy both RAL/H (rar_entry_count) and SHRAL/H (+4) to PHY */
1878 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1879 mac_reg = er32(RAL(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001880 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
1881 (u16)(mac_reg & 0xFFFF));
1882 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
1883 (u16)((mac_reg >> 16) & 0xFFFF));
1884
Bruce Alland3738bb2010-06-16 13:27:28 +00001885 mac_reg = er32(RAH(i));
Bruce Allan2b6b1682011-05-13 07:20:09 +00001886 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
1887 (u16)(mac_reg & 0xFFFF));
1888 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
1889 (u16)((mac_reg & E1000_RAH_AV)
1890 >> 16));
Bruce Alland3738bb2010-06-16 13:27:28 +00001891 }
Bruce Allan2b6b1682011-05-13 07:20:09 +00001892
1893 e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
1894
1895release:
1896 hw->phy.ops.release(hw);
Bruce Alland3738bb2010-06-16 13:27:28 +00001897}
1898
Bruce Alland3738bb2010-06-16 13:27:28 +00001899/**
1900 * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
1901 * with 82579 PHY
1902 * @hw: pointer to the HW structure
1903 * @enable: flag to enable/disable workaround when enabling/disabling jumbos
1904 **/
1905s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1906{
1907 s32 ret_val = 0;
1908 u16 phy_reg, data;
1909 u32 mac_reg;
1910 u16 i;
1911
Bruce Allan2fbe4522012-04-19 03:21:47 +00001912 if (hw->mac.type < e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00001913 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00001914
1915 /* disable Rx path while enabling/disabling workaround */
1916 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1917 ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
1918 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001919 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001920
1921 if (enable) {
Bruce Allane921eb12012-11-28 09:28:37 +00001922 /* Write Rx addresses (rar_entry_count for RAL/H, +4 for
Bruce Alland3738bb2010-06-16 13:27:28 +00001923 * SHRAL/H) and initial CRC values to the MAC
1924 */
1925 for (i = 0; i < (hw->mac.rar_entry_count + 4); i++) {
1926 u8 mac_addr[ETH_ALEN] = {0};
1927 u32 addr_high, addr_low;
1928
1929 addr_high = er32(RAH(i));
1930 if (!(addr_high & E1000_RAH_AV))
1931 continue;
1932 addr_low = er32(RAL(i));
1933 mac_addr[0] = (addr_low & 0xFF);
1934 mac_addr[1] = ((addr_low >> 8) & 0xFF);
1935 mac_addr[2] = ((addr_low >> 16) & 0xFF);
1936 mac_addr[3] = ((addr_low >> 24) & 0xFF);
1937 mac_addr[4] = (addr_high & 0xFF);
1938 mac_addr[5] = ((addr_high >> 8) & 0xFF);
1939
Bruce Allanfe46f582011-01-06 14:29:51 +00001940 ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
Bruce Alland3738bb2010-06-16 13:27:28 +00001941 }
1942
1943 /* Write Rx addresses to the PHY */
1944 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
1945
1946 /* Enable jumbo frame workaround in the MAC */
1947 mac_reg = er32(FFLT_DBG);
1948 mac_reg &= ~(1 << 14);
1949 mac_reg |= (7 << 15);
1950 ew32(FFLT_DBG, mac_reg);
1951
1952 mac_reg = er32(RCTL);
1953 mac_reg |= E1000_RCTL_SECRC;
1954 ew32(RCTL, mac_reg);
1955
1956 ret_val = e1000e_read_kmrn_reg(hw,
1957 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1958 &data);
1959 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001960 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001961 ret_val = e1000e_write_kmrn_reg(hw,
1962 E1000_KMRNCTRLSTA_CTRL_OFFSET,
1963 data | (1 << 0));
1964 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001965 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001966 ret_val = e1000e_read_kmrn_reg(hw,
1967 E1000_KMRNCTRLSTA_HD_CTRL,
1968 &data);
1969 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001970 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001971 data &= ~(0xF << 8);
1972 data |= (0xB << 8);
1973 ret_val = e1000e_write_kmrn_reg(hw,
1974 E1000_KMRNCTRLSTA_HD_CTRL,
1975 data);
1976 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001977 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001978
1979 /* Enable jumbo frame workaround in the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001980 e1e_rphy(hw, PHY_REG(769, 23), &data);
1981 data &= ~(0x7F << 5);
1982 data |= (0x37 << 5);
1983 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1984 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001985 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001986 e1e_rphy(hw, PHY_REG(769, 16), &data);
1987 data &= ~(1 << 13);
Bruce Alland3738bb2010-06-16 13:27:28 +00001988 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1989 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001990 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00001991 e1e_rphy(hw, PHY_REG(776, 20), &data);
1992 data &= ~(0x3FF << 2);
1993 data |= (0x1A << 2);
1994 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
1995 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001996 return ret_val;
Bruce Allanb64e9dd2011-09-30 08:07:00 +00001997 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
Bruce Alland3738bb2010-06-16 13:27:28 +00001998 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00001999 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002000 e1e_rphy(hw, HV_PM_CTRL, &data);
2001 ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
2002 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002003 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002004 } else {
2005 /* Write MAC register values back to h/w defaults */
2006 mac_reg = er32(FFLT_DBG);
2007 mac_reg &= ~(0xF << 14);
2008 ew32(FFLT_DBG, mac_reg);
2009
2010 mac_reg = er32(RCTL);
2011 mac_reg &= ~E1000_RCTL_SECRC;
Bruce Allana1ce6472010-09-22 17:16:40 +00002012 ew32(RCTL, mac_reg);
Bruce Alland3738bb2010-06-16 13:27:28 +00002013
2014 ret_val = e1000e_read_kmrn_reg(hw,
2015 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2016 &data);
2017 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002018 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002019 ret_val = e1000e_write_kmrn_reg(hw,
2020 E1000_KMRNCTRLSTA_CTRL_OFFSET,
2021 data & ~(1 << 0));
2022 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002023 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002024 ret_val = e1000e_read_kmrn_reg(hw,
2025 E1000_KMRNCTRLSTA_HD_CTRL,
2026 &data);
2027 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002028 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002029 data &= ~(0xF << 8);
2030 data |= (0xB << 8);
2031 ret_val = e1000e_write_kmrn_reg(hw,
2032 E1000_KMRNCTRLSTA_HD_CTRL,
2033 data);
2034 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002035 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002036
2037 /* Write PHY register values back to h/w defaults */
Bruce Alland3738bb2010-06-16 13:27:28 +00002038 e1e_rphy(hw, PHY_REG(769, 23), &data);
2039 data &= ~(0x7F << 5);
2040 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
2041 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002042 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002043 e1e_rphy(hw, PHY_REG(769, 16), &data);
Bruce Alland3738bb2010-06-16 13:27:28 +00002044 data |= (1 << 13);
2045 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
2046 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002047 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002048 e1e_rphy(hw, PHY_REG(776, 20), &data);
2049 data &= ~(0x3FF << 2);
2050 data |= (0x8 << 2);
2051 ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
2052 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002053 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002054 ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
2055 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002056 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002057 e1e_rphy(hw, HV_PM_CTRL, &data);
2058 ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
2059 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002060 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002061 }
2062
2063 /* re-enable Rx path after enabling/disabling workaround */
Bruce Allan5015e532012-02-08 02:55:56 +00002064 return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
Bruce Alland3738bb2010-06-16 13:27:28 +00002065}
2066
2067/**
2068 * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
2069 * done after every PHY reset.
2070 **/
2071static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
2072{
2073 s32 ret_val = 0;
2074
2075 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002076 return 0;
Bruce Alland3738bb2010-06-16 13:27:28 +00002077
2078 /* Set MDIO slow mode before any other MDIO access */
2079 ret_val = e1000_set_mdio_slow_mode_hv(hw);
Bruce Allan8e5ab422012-12-05 06:26:19 +00002080 if (ret_val)
2081 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002082
Bruce Allan4d241362011-12-16 00:46:06 +00002083 ret_val = hw->phy.ops.acquire(hw);
2084 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002085 return ret_val;
Bruce Allan4d241362011-12-16 00:46:06 +00002086 /* set MSE higher to enable link to stay up when noise is high */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002087 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
Bruce Allan4d241362011-12-16 00:46:06 +00002088 if (ret_val)
2089 goto release;
2090 /* drop link after 5 times MSE threshold was reached */
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002091 ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
Bruce Allan4d241362011-12-16 00:46:06 +00002092release:
2093 hw->phy.ops.release(hw);
2094
Bruce Alland3738bb2010-06-16 13:27:28 +00002095 return ret_val;
2096}
2097
2098/**
Bruce Allan831bd2e2010-09-22 17:16:18 +00002099 * e1000_k1_gig_workaround_lv - K1 Si workaround
2100 * @hw: pointer to the HW structure
2101 *
2102 * Workaround to set the K1 beacon duration for 82579 parts
2103 **/
2104static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
2105{
2106 s32 ret_val = 0;
2107 u16 status_reg = 0;
2108 u32 mac_reg;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002109 u16 phy_reg;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002110
2111 if (hw->mac.type != e1000_pch2lan)
Bruce Allan5015e532012-02-08 02:55:56 +00002112 return 0;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002113
2114 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
2115 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
2116 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002117 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002118
2119 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
2120 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
2121 mac_reg = er32(FEXTNVM4);
2122 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
2123
Bruce Allan0ed013e2011-07-29 05:52:56 +00002124 ret_val = e1e_rphy(hw, I82579_LPI_CTRL, &phy_reg);
2125 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002126 return ret_val;
Bruce Allan831bd2e2010-09-22 17:16:18 +00002127
Bruce Allan0ed013e2011-07-29 05:52:56 +00002128 if (status_reg & HV_M_STATUS_SPEED_1000) {
Bruce Allan36ceeb42012-03-20 03:47:47 +00002129 u16 pm_phy_reg;
2130
Bruce Allan0ed013e2011-07-29 05:52:56 +00002131 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
2132 phy_reg &= ~I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
Bruce Allan36ceeb42012-03-20 03:47:47 +00002133 /* LV 1G Packet drop issue wa */
2134 ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
2135 if (ret_val)
2136 return ret_val;
2137 pm_phy_reg &= ~HV_PM_CTRL_PLL_STOP_IN_K1_GIGA;
2138 ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
2139 if (ret_val)
2140 return ret_val;
Bruce Allan0ed013e2011-07-29 05:52:56 +00002141 } else {
2142 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
2143 phy_reg |= I82579_LPI_CTRL_FORCE_PLL_LOCK_COUNT;
2144 }
Bruce Allan831bd2e2010-09-22 17:16:18 +00002145 ew32(FEXTNVM4, mac_reg);
Bruce Allan0ed013e2011-07-29 05:52:56 +00002146 ret_val = e1e_wphy(hw, I82579_LPI_CTRL, phy_reg);
Bruce Allan831bd2e2010-09-22 17:16:18 +00002147 }
2148
Bruce Allan831bd2e2010-09-22 17:16:18 +00002149 return ret_val;
2150}
2151
2152/**
Bruce Allan605c82b2010-09-22 17:17:01 +00002153 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
2154 * @hw: pointer to the HW structure
2155 * @gate: boolean set to true to gate, false to ungate
2156 *
2157 * Gate/ungate the automatic PHY configuration via hardware; perform
2158 * the configuration via software instead.
2159 **/
2160static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
2161{
2162 u32 extcnf_ctrl;
2163
Bruce Allan2fbe4522012-04-19 03:21:47 +00002164 if (hw->mac.type < e1000_pch2lan)
Bruce Allan605c82b2010-09-22 17:17:01 +00002165 return;
2166
2167 extcnf_ctrl = er32(EXTCNF_CTRL);
2168
2169 if (gate)
2170 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2171 else
2172 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
2173
2174 ew32(EXTCNF_CTRL, extcnf_ctrl);
Bruce Allan605c82b2010-09-22 17:17:01 +00002175}
2176
2177/**
Bruce Allanfc0c7762009-07-01 13:27:55 +00002178 * e1000_lan_init_done_ich8lan - Check for PHY config completion
2179 * @hw: pointer to the HW structure
2180 *
2181 * Check the appropriate indication the MAC has finished configuring the
2182 * PHY after a software reset.
2183 **/
2184static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
2185{
2186 u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
2187
2188 /* Wait for basic configuration completes before proceeding */
2189 do {
2190 data = er32(STATUS);
2191 data &= E1000_STATUS_LAN_INIT_DONE;
2192 udelay(100);
2193 } while ((!data) && --loop);
2194
Bruce Allane921eb12012-11-28 09:28:37 +00002195 /* If basic configuration is incomplete before the above loop
Bruce Allanfc0c7762009-07-01 13:27:55 +00002196 * count reaches 0, loading the configuration from NVM will
2197 * leave the PHY in a bad state possibly resulting in no link.
2198 */
2199 if (loop == 0)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002200 e_dbg("LAN_INIT_DONE not set, increase timeout\n");
Bruce Allanfc0c7762009-07-01 13:27:55 +00002201
2202 /* Clear the Init Done bit for the next init event */
2203 data = er32(STATUS);
2204 data &= ~E1000_STATUS_LAN_INIT_DONE;
2205 ew32(STATUS, data);
2206}
2207
2208/**
Bruce Allane98cac42010-05-10 15:02:32 +00002209 * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
Auke Kokbc7f75f2007-09-17 12:30:59 -07002210 * @hw: pointer to the HW structure
Auke Kokbc7f75f2007-09-17 12:30:59 -07002211 **/
Bruce Allane98cac42010-05-10 15:02:32 +00002212static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002213{
Bruce Allanf523d212009-10-29 13:45:45 +00002214 s32 ret_val = 0;
2215 u16 reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002216
Bruce Allan44abd5c2012-02-22 09:02:37 +00002217 if (hw->phy.ops.check_reset_block(hw))
Bruce Allan5015e532012-02-08 02:55:56 +00002218 return 0;
Bruce Allanfc0c7762009-07-01 13:27:55 +00002219
Bruce Allan5f3eed62010-09-22 17:15:54 +00002220 /* Allow time for h/w to get to quiescent state after reset */
Bruce Allan1bba4382011-03-19 00:27:20 +00002221 usleep_range(10000, 20000);
Bruce Allan5f3eed62010-09-22 17:15:54 +00002222
Bruce Allanfddaa1a2010-01-13 01:52:49 +00002223 /* Perform any necessary post-reset workarounds */
Bruce Allane98cac42010-05-10 15:02:32 +00002224 switch (hw->mac.type) {
2225 case e1000_pchlan:
Bruce Allana4f58f52009-06-02 11:29:18 +00002226 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2227 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002228 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002229 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00002230 case e1000_pch2lan:
2231 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
2232 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002233 return ret_val;
Bruce Alland3738bb2010-06-16 13:27:28 +00002234 break;
Bruce Allane98cac42010-05-10 15:02:32 +00002235 default:
2236 break;
Bruce Allana4f58f52009-06-02 11:29:18 +00002237 }
2238
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00002239 /* Clear the host wakeup bit after lcd reset */
2240 if (hw->mac.type >= e1000_pchlan) {
2241 e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
2242 reg &= ~BM_WUC_HOST_WU_BIT;
2243 e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
2244 }
Bruce Allandb2932e2009-10-26 11:22:47 +00002245
Bruce Allanf523d212009-10-29 13:45:45 +00002246 /* Configure the LCD with the extended configuration region in NVM */
2247 ret_val = e1000_sw_lcd_config_ich8lan(hw);
2248 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002249 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002250
Bruce Allanf523d212009-10-29 13:45:45 +00002251 /* Configure the LCD with the OEM bits in NVM */
Bruce Allane98cac42010-05-10 15:02:32 +00002252 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002253
Bruce Allan1effb452011-02-25 06:58:03 +00002254 if (hw->mac.type == e1000_pch2lan) {
2255 /* Ungate automatic PHY configuration on non-managed 82579 */
2256 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allan1bba4382011-03-19 00:27:20 +00002257 usleep_range(10000, 20000);
Bruce Allan1effb452011-02-25 06:58:03 +00002258 e1000_gate_hw_phy_config_ich8lan(hw, false);
2259 }
2260
2261 /* Set EEE LPI Update Timer to 200usec */
2262 ret_val = hw->phy.ops.acquire(hw);
2263 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002264 return ret_val;
Bruce Allan4ddc48a2012-12-05 06:25:58 +00002265 ret_val = e1000_write_emi_reg_locked(hw,
2266 I82579_LPI_UPDATE_TIMER,
2267 0x1387);
Bruce Allan1effb452011-02-25 06:58:03 +00002268 hw->phy.ops.release(hw);
Bruce Allan605c82b2010-09-22 17:17:01 +00002269 }
2270
Bruce Allane98cac42010-05-10 15:02:32 +00002271 return ret_val;
2272}
2273
2274/**
2275 * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
2276 * @hw: pointer to the HW structure
2277 *
2278 * Resets the PHY
2279 * This is a function pointer entry point called by drivers
2280 * or other shared routines.
2281 **/
2282static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
2283{
2284 s32 ret_val = 0;
2285
Bruce Allan605c82b2010-09-22 17:17:01 +00002286 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
2287 if ((hw->mac.type == e1000_pch2lan) &&
2288 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
2289 e1000_gate_hw_phy_config_ich8lan(hw, true);
2290
Bruce Allane98cac42010-05-10 15:02:32 +00002291 ret_val = e1000e_phy_hw_reset_generic(hw);
2292 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002293 return ret_val;
Bruce Allane98cac42010-05-10 15:02:32 +00002294
Bruce Allan5015e532012-02-08 02:55:56 +00002295 return e1000_post_phy_reset_ich8lan(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002296}
2297
2298/**
Bruce Allanfa2ce132009-10-26 11:23:25 +00002299 * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
2300 * @hw: pointer to the HW structure
2301 * @active: true to enable LPLU, false to disable
2302 *
2303 * Sets the LPLU state according to the active flag. For PCH, if OEM write
2304 * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
2305 * the phy speed. This function will manually set the LPLU bit and restart
2306 * auto-neg as hw would do. D3 and D0 LPLU will call the same function
2307 * since it configures the same bit.
2308 **/
2309static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
2310{
2311 s32 ret_val = 0;
2312 u16 oem_reg;
2313
2314 ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
2315 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00002316 return ret_val;
Bruce Allanfa2ce132009-10-26 11:23:25 +00002317
2318 if (active)
2319 oem_reg |= HV_OEM_BITS_LPLU;
2320 else
2321 oem_reg &= ~HV_OEM_BITS_LPLU;
2322
Bruce Allan44abd5c2012-02-22 09:02:37 +00002323 if (!hw->phy.ops.check_reset_block(hw))
Bruce Allan464c85e2011-12-16 00:46:49 +00002324 oem_reg |= HV_OEM_BITS_RESTART_AN;
2325
Bruce Allan5015e532012-02-08 02:55:56 +00002326 return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
Bruce Allanfa2ce132009-10-26 11:23:25 +00002327}
2328
2329/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
2331 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002332 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002333 *
2334 * Sets the LPLU D0 state according to the active flag. When
2335 * activating LPLU this function also disables smart speed
2336 * and vice versa. LPLU will not be activated unless the
2337 * device autonegotiation advertisement meets standards of
2338 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2339 * This is a function pointer entry point only called by
2340 * PHY setup routines.
2341 **/
2342static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2343{
2344 struct e1000_phy_info *phy = &hw->phy;
2345 u32 phy_ctrl;
2346 s32 ret_val = 0;
2347 u16 data;
2348
Bruce Allan97ac8ca2008-04-29 09:16:05 -07002349 if (phy->type == e1000_phy_ife)
Bruce Allan82607252012-02-08 02:55:09 +00002350 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002351
2352 phy_ctrl = er32(PHY_CTRL);
2353
2354 if (active) {
2355 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2356 ew32(PHY_CTRL, phy_ctrl);
2357
Bruce Allan60f12922009-07-01 13:28:14 +00002358 if (phy->type != e1000_phy_igp_3)
2359 return 0;
2360
Bruce Allane921eb12012-11-28 09:28:37 +00002361 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002362 * any PHY registers
2363 */
Bruce Allan60f12922009-07-01 13:28:14 +00002364 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002365 e1000e_gig_downshift_workaround_ich8lan(hw);
2366
2367 /* When LPLU is enabled, we should disable SmartSpeed */
2368 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
2369 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2370 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
2371 if (ret_val)
2372 return ret_val;
2373 } else {
2374 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2375 ew32(PHY_CTRL, phy_ctrl);
2376
Bruce Allan60f12922009-07-01 13:28:14 +00002377 if (phy->type != e1000_phy_igp_3)
2378 return 0;
2379
Bruce Allane921eb12012-11-28 09:28:37 +00002380 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002381 * during Dx states where the power conservation is most
2382 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002383 * SmartSpeed, so performance is maintained.
2384 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002385 if (phy->smart_speed == e1000_smart_speed_on) {
2386 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002387 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002388 if (ret_val)
2389 return ret_val;
2390
2391 data |= IGP01E1000_PSCFR_SMART_SPEED;
2392 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002393 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002394 if (ret_val)
2395 return ret_val;
2396 } else if (phy->smart_speed == e1000_smart_speed_off) {
2397 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002398 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002399 if (ret_val)
2400 return ret_val;
2401
2402 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2403 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
Bruce Allanad680762008-03-28 09:15:03 -07002404 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002405 if (ret_val)
2406 return ret_val;
2407 }
2408 }
2409
2410 return 0;
2411}
2412
2413/**
2414 * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
2415 * @hw: pointer to the HW structure
Bruce Allan564ea9b2009-11-20 23:26:44 +00002416 * @active: true to enable LPLU, false to disable
Auke Kokbc7f75f2007-09-17 12:30:59 -07002417 *
2418 * Sets the LPLU D3 state according to the active flag. When
2419 * activating LPLU this function also disables smart speed
2420 * and vice versa. LPLU will not be activated unless the
2421 * device autonegotiation advertisement meets standards of
2422 * either 10 or 10/100 or 10/100/1000 at all duplexes.
2423 * This is a function pointer entry point only called by
2424 * PHY setup routines.
2425 **/
2426static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
2427{
2428 struct e1000_phy_info *phy = &hw->phy;
2429 u32 phy_ctrl;
Bruce Alland7eb3382012-02-08 02:55:14 +00002430 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002431 u16 data;
2432
2433 phy_ctrl = er32(PHY_CTRL);
2434
2435 if (!active) {
2436 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2437 ew32(PHY_CTRL, phy_ctrl);
Bruce Allan60f12922009-07-01 13:28:14 +00002438
2439 if (phy->type != e1000_phy_igp_3)
2440 return 0;
2441
Bruce Allane921eb12012-11-28 09:28:37 +00002442 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
Auke Kokbc7f75f2007-09-17 12:30:59 -07002443 * during Dx states where the power conservation is most
2444 * important. During driver activity we should enable
Bruce Allanad680762008-03-28 09:15:03 -07002445 * SmartSpeed, so performance is maintained.
2446 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002447 if (phy->smart_speed == e1000_smart_speed_on) {
Bruce Allanad680762008-03-28 09:15:03 -07002448 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2449 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002450 if (ret_val)
2451 return ret_val;
2452
2453 data |= IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002454 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2455 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002456 if (ret_val)
2457 return ret_val;
2458 } else if (phy->smart_speed == e1000_smart_speed_off) {
Bruce Allanad680762008-03-28 09:15:03 -07002459 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2460 &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002461 if (ret_val)
2462 return ret_val;
2463
2464 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002465 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
2466 data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002467 if (ret_val)
2468 return ret_val;
2469 }
2470 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2471 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2472 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2473 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2474 ew32(PHY_CTRL, phy_ctrl);
2475
Bruce Allan60f12922009-07-01 13:28:14 +00002476 if (phy->type != e1000_phy_igp_3)
2477 return 0;
2478
Bruce Allane921eb12012-11-28 09:28:37 +00002479 /* Call gig speed drop workaround on LPLU before accessing
Bruce Allanad680762008-03-28 09:15:03 -07002480 * any PHY registers
2481 */
Bruce Allan60f12922009-07-01 13:28:14 +00002482 if (hw->mac.type == e1000_ich8lan)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 e1000e_gig_downshift_workaround_ich8lan(hw);
2484
2485 /* When LPLU is enabled, we should disable SmartSpeed */
Bruce Allanad680762008-03-28 09:15:03 -07002486 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002487 if (ret_val)
2488 return ret_val;
2489
2490 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Bruce Allanad680762008-03-28 09:15:03 -07002491 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002492 }
2493
Bruce Alland7eb3382012-02-08 02:55:14 +00002494 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002495}
2496
2497/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002498 * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
2499 * @hw: pointer to the HW structure
2500 * @bank: pointer to the variable that returns the active bank
2501 *
2502 * Reads signature byte from the NVM using the flash access registers.
Bruce Allane2434552008-11-21 17:02:41 -08002503 * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
Bruce Allanf4187b52008-08-26 18:36:50 -07002504 **/
2505static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
2506{
Bruce Allane2434552008-11-21 17:02:41 -08002507 u32 eecd;
Bruce Allanf4187b52008-08-26 18:36:50 -07002508 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allanf4187b52008-08-26 18:36:50 -07002509 u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
2510 u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
Bruce Allane2434552008-11-21 17:02:41 -08002511 u8 sig_byte = 0;
Bruce Allanf71dde62012-02-08 02:55:35 +00002512 s32 ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07002513
Bruce Allane2434552008-11-21 17:02:41 -08002514 switch (hw->mac.type) {
2515 case e1000_ich8lan:
2516 case e1000_ich9lan:
2517 eecd = er32(EECD);
2518 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
2519 E1000_EECD_SEC1VAL_VALID_MASK) {
2520 if (eecd & E1000_EECD_SEC1VAL)
Bruce Allanf4187b52008-08-26 18:36:50 -07002521 *bank = 1;
Bruce Allane2434552008-11-21 17:02:41 -08002522 else
2523 *bank = 0;
2524
2525 return 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002526 }
Bruce Allan434f1392011-12-16 00:46:54 +00002527 e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
Bruce Allane2434552008-11-21 17:02:41 -08002528 /* fall-thru */
2529 default:
2530 /* set bank to 0 in case flash read fails */
2531 *bank = 0;
2532
2533 /* Check bank 0 */
2534 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
2535 &sig_byte);
2536 if (ret_val)
2537 return ret_val;
2538 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2539 E1000_ICH_NVM_SIG_VALUE) {
2540 *bank = 0;
2541 return 0;
2542 }
2543
2544 /* Check bank 1 */
2545 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
2546 bank1_offset,
2547 &sig_byte);
2548 if (ret_val)
2549 return ret_val;
2550 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
2551 E1000_ICH_NVM_SIG_VALUE) {
2552 *bank = 1;
2553 return 0;
2554 }
2555
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002556 e_dbg("ERROR: No valid NVM bank present\n");
Bruce Allane2434552008-11-21 17:02:41 -08002557 return -E1000_ERR_NVM;
Bruce Allanf4187b52008-08-26 18:36:50 -07002558 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002559}
2560
2561/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002562 * e1000_read_nvm_ich8lan - Read word(s) from the NVM
2563 * @hw: pointer to the HW structure
2564 * @offset: The offset (in bytes) of the word(s) to read.
2565 * @words: Size of data to read in words
2566 * @data: Pointer to the word(s) to read at offset.
2567 *
2568 * Reads a word(s) from the NVM using the flash access registers.
2569 **/
2570static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2571 u16 *data)
2572{
2573 struct e1000_nvm_info *nvm = &hw->nvm;
2574 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2575 u32 act_offset;
Bruce Allan148675a2009-08-07 07:41:56 +00002576 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07002577 u32 bank = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002578 u16 i, word;
2579
2580 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2581 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002582 e_dbg("nvm parameter(s) out of bounds\n");
Bruce Allanca15df52009-10-26 11:23:43 +00002583 ret_val = -E1000_ERR_NVM;
2584 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002585 }
2586
Bruce Allan94d81862009-11-20 23:25:26 +00002587 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002588
Bruce Allanf4187b52008-08-26 18:36:50 -07002589 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allan148675a2009-08-07 07:41:56 +00002590 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002591 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002592 bank = 0;
2593 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002594
2595 act_offset = (bank) ? nvm->flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002596 act_offset += offset;
2597
Bruce Allan148675a2009-08-07 07:41:56 +00002598 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002599 for (i = 0; i < words; i++) {
Bruce Allanb9e06f72011-07-22 06:21:41 +00002600 if (dev_spec->shadow_ram[offset+i].modified) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002601 data[i] = dev_spec->shadow_ram[offset+i].value;
2602 } else {
2603 ret_val = e1000_read_flash_word_ich8lan(hw,
2604 act_offset + i,
2605 &word);
2606 if (ret_val)
2607 break;
2608 data[i] = word;
2609 }
2610 }
2611
Bruce Allan94d81862009-11-20 23:25:26 +00002612 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002613
Bruce Allane2434552008-11-21 17:02:41 -08002614out:
2615 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002616 e_dbg("NVM read error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08002617
Auke Kokbc7f75f2007-09-17 12:30:59 -07002618 return ret_val;
2619}
2620
2621/**
2622 * e1000_flash_cycle_init_ich8lan - Initialize flash
2623 * @hw: pointer to the HW structure
2624 *
2625 * This function does initial flash setup so that a new read/write/erase cycle
2626 * can be started.
2627 **/
2628static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
2629{
2630 union ich8_hws_flash_status hsfsts;
2631 s32 ret_val = -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002632
2633 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
2634
2635 /* Check if the flash descriptor is valid */
Bruce Allan04499ec2012-04-13 00:08:31 +00002636 if (!hsfsts.hsf_status.fldesvalid) {
Bruce Allan434f1392011-12-16 00:46:54 +00002637 e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002638 return -E1000_ERR_NVM;
2639 }
2640
2641 /* Clear FCERR and DAEL in hw status by writing 1 */
2642 hsfsts.hsf_status.flcerr = 1;
2643 hsfsts.hsf_status.dael = 1;
2644
2645 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2646
Bruce Allane921eb12012-11-28 09:28:37 +00002647 /* Either we should have a hardware SPI cycle in progress
Auke Kokbc7f75f2007-09-17 12:30:59 -07002648 * bit to check against, in order to start a new cycle or
2649 * FDONE bit should be changed in the hardware so that it
Auke Kok489815c2008-02-21 15:11:07 -08002650 * is 1 after hardware reset, which can then be used as an
Auke Kokbc7f75f2007-09-17 12:30:59 -07002651 * indication whether a cycle is in progress or has been
2652 * completed.
2653 */
2654
Bruce Allan04499ec2012-04-13 00:08:31 +00002655 if (!hsfsts.hsf_status.flcinprog) {
Bruce Allane921eb12012-11-28 09:28:37 +00002656 /* There is no cycle running at present,
Bruce Allan5ff5b662009-12-01 15:51:11 +00002657 * so we can start a cycle.
Bruce Allanad680762008-03-28 09:15:03 -07002658 * Begin by setting Flash Cycle Done.
2659 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002660 hsfsts.hsf_status.flcdone = 1;
2661 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2662 ret_val = 0;
2663 } else {
Bruce Allanf71dde62012-02-08 02:55:35 +00002664 s32 i;
Bruce Allan90da0662011-01-06 07:02:53 +00002665
Bruce Allane921eb12012-11-28 09:28:37 +00002666 /* Otherwise poll for sometime so the current
Bruce Allanad680762008-03-28 09:15:03 -07002667 * cycle has a chance to end before giving up.
2668 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002669 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
Bruce Allanc8243ee2011-12-17 08:32:57 +00002670 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002671 if (!hsfsts.hsf_status.flcinprog) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002672 ret_val = 0;
2673 break;
2674 }
2675 udelay(1);
2676 }
Bruce Allan9e2d7652012-01-31 06:37:27 +00002677 if (!ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00002678 /* Successful in waiting for previous cycle to timeout,
Bruce Allanad680762008-03-28 09:15:03 -07002679 * now set the Flash Cycle Done.
2680 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002681 hsfsts.hsf_status.flcdone = 1;
2682 ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
2683 } else {
Joe Perches2c73e1f2010-03-26 20:16:59 +00002684 e_dbg("Flash controller busy, cannot get access\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002685 }
2686 }
2687
2688 return ret_val;
2689}
2690
2691/**
2692 * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
2693 * @hw: pointer to the HW structure
2694 * @timeout: maximum time to wait for completion
2695 *
2696 * This function starts a flash cycle and waits for its completion.
2697 **/
2698static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
2699{
2700 union ich8_hws_flash_ctrl hsflctl;
2701 union ich8_hws_flash_status hsfsts;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002702 u32 i = 0;
2703
2704 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
2705 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2706 hsflctl.hsf_ctrl.flcgo = 1;
2707 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2708
2709 /* wait till FDONE bit is set to 1 */
2710 do {
2711 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002712 if (hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002713 break;
2714 udelay(1);
2715 } while (i++ < timeout);
2716
Bruce Allan04499ec2012-04-13 00:08:31 +00002717 if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002718 return 0;
2719
Bruce Allan55920b52012-02-08 02:55:25 +00002720 return -E1000_ERR_NVM;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002721}
2722
2723/**
2724 * e1000_read_flash_word_ich8lan - Read word from flash
2725 * @hw: pointer to the HW structure
2726 * @offset: offset to data location
2727 * @data: pointer to the location for storing the data
2728 *
2729 * Reads the flash word at offset into data. Offset is converted
2730 * to bytes before read.
2731 **/
2732static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
2733 u16 *data)
2734{
2735 /* Must convert offset into bytes. */
2736 offset <<= 1;
2737
2738 return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
2739}
2740
2741/**
Bruce Allanf4187b52008-08-26 18:36:50 -07002742 * e1000_read_flash_byte_ich8lan - Read byte from flash
2743 * @hw: pointer to the HW structure
2744 * @offset: The offset of the byte to read.
2745 * @data: Pointer to a byte to store the value read.
2746 *
2747 * Reads a single byte from the NVM using the flash access registers.
2748 **/
2749static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2750 u8 *data)
2751{
2752 s32 ret_val;
2753 u16 word = 0;
2754
2755 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
2756 if (ret_val)
2757 return ret_val;
2758
2759 *data = (u8)word;
2760
2761 return 0;
2762}
2763
2764/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002765 * e1000_read_flash_data_ich8lan - Read byte or word from NVM
2766 * @hw: pointer to the HW structure
2767 * @offset: The offset (in bytes) of the byte or word to read.
2768 * @size: Size of data to read, 1=byte 2=word
2769 * @data: Pointer to the word to store the value read.
2770 *
2771 * Reads a byte or word from the NVM using the flash access registers.
2772 **/
2773static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2774 u8 size, u16 *data)
2775{
2776 union ich8_hws_flash_status hsfsts;
2777 union ich8_hws_flash_ctrl hsflctl;
2778 u32 flash_linear_addr;
2779 u32 flash_data = 0;
2780 s32 ret_val = -E1000_ERR_NVM;
2781 u8 count = 0;
2782
2783 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
2784 return -E1000_ERR_NVM;
2785
2786 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2787 hw->nvm.flash_base_addr;
2788
2789 do {
2790 udelay(1);
2791 /* Steps */
2792 ret_val = e1000_flash_cycle_init_ich8lan(hw);
Bruce Allan9e2d7652012-01-31 06:37:27 +00002793 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002794 break;
2795
2796 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
2797 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2798 hsflctl.hsf_ctrl.fldbcount = size - 1;
2799 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
2800 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
2801
2802 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
2803
2804 ret_val = e1000_flash_cycle_ich8lan(hw,
2805 ICH_FLASH_READ_COMMAND_TIMEOUT);
2806
Bruce Allane921eb12012-11-28 09:28:37 +00002807 /* Check if FCERR is set to 1, if set to 1, clear it
Auke Kokbc7f75f2007-09-17 12:30:59 -07002808 * and try the whole sequence a few more times, else
2809 * read in (shift in) the Flash Data0, the order is
Bruce Allanad680762008-03-28 09:15:03 -07002810 * least significant byte first msb to lsb
2811 */
Bruce Allan9e2d7652012-01-31 06:37:27 +00002812 if (!ret_val) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002813 flash_data = er32flash(ICH_FLASH_FDATA0);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002814 if (size == 1)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002815 *data = (u8)(flash_data & 0x000000FF);
Bruce Allanb1cdfea2010-12-11 05:53:47 +00002816 else if (size == 2)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002817 *data = (u16)(flash_data & 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002818 break;
2819 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00002820 /* If we've gotten here, then things are probably
Auke Kokbc7f75f2007-09-17 12:30:59 -07002821 * completely hosed, but if the error condition is
2822 * detected, it won't hurt to give it another try...
2823 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
2824 */
2825 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00002826 if (hsfsts.hsf_status.flcerr) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002827 /* Repeat for some time before giving up. */
2828 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00002829 } else if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00002830 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002831 break;
2832 }
2833 }
2834 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2835
2836 return ret_val;
2837}
2838
2839/**
2840 * e1000_write_nvm_ich8lan - Write word(s) to the NVM
2841 * @hw: pointer to the HW structure
2842 * @offset: The offset (in bytes) of the word(s) to write.
2843 * @words: Size of data to write in words
2844 * @data: Pointer to the word(s) to write at offset.
2845 *
2846 * Writes a byte or word to the NVM using the flash access registers.
2847 **/
2848static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
2849 u16 *data)
2850{
2851 struct e1000_nvm_info *nvm = &hw->nvm;
2852 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002853 u16 i;
2854
2855 if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2856 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002857 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002858 return -E1000_ERR_NVM;
2859 }
2860
Bruce Allan94d81862009-11-20 23:25:26 +00002861 nvm->ops.acquire(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002862
Auke Kokbc7f75f2007-09-17 12:30:59 -07002863 for (i = 0; i < words; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002864 dev_spec->shadow_ram[offset+i].modified = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002865 dev_spec->shadow_ram[offset+i].value = data[i];
2866 }
2867
Bruce Allan94d81862009-11-20 23:25:26 +00002868 nvm->ops.release(hw);
Bruce Allanca15df52009-10-26 11:23:43 +00002869
Auke Kokbc7f75f2007-09-17 12:30:59 -07002870 return 0;
2871}
2872
2873/**
2874 * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2875 * @hw: pointer to the HW structure
2876 *
2877 * The NVM checksum is updated by calling the generic update_nvm_checksum,
2878 * which writes the checksum to the shadow ram. The changes in the shadow
2879 * ram are then committed to the EEPROM by processing each bank at a time
2880 * checking for the modified bit and writing only the pending changes.
Auke Kok489815c2008-02-21 15:11:07 -08002881 * After a successful commit, the shadow ram is cleared and is ready for
Auke Kokbc7f75f2007-09-17 12:30:59 -07002882 * future writes.
2883 **/
2884static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2885{
2886 struct e1000_nvm_info *nvm = &hw->nvm;
2887 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allanf4187b52008-08-26 18:36:50 -07002888 u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002889 s32 ret_val;
2890 u16 data;
2891
2892 ret_val = e1000e_update_nvm_checksum_generic(hw);
2893 if (ret_val)
Bruce Allane2434552008-11-21 17:02:41 -08002894 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002895
2896 if (nvm->type != e1000_nvm_flash_sw)
Bruce Allane2434552008-11-21 17:02:41 -08002897 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002898
Bruce Allan94d81862009-11-20 23:25:26 +00002899 nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002900
Bruce Allane921eb12012-11-28 09:28:37 +00002901 /* We're writing to the opposite bank so if we're on bank 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002902 * write to bank 0 etc. We also need to erase the segment that
Bruce Allanad680762008-03-28 09:15:03 -07002903 * is going to be written
2904 */
Bruce Allanf4187b52008-08-26 18:36:50 -07002905 ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
Bruce Allane2434552008-11-21 17:02:41 -08002906 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002907 e_dbg("Could not detect valid bank, assuming bank 0\n");
Bruce Allan148675a2009-08-07 07:41:56 +00002908 bank = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002909 }
Bruce Allanf4187b52008-08-26 18:36:50 -07002910
2911 if (bank == 0) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002912 new_bank_offset = nvm->flash_bank_size;
2913 old_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002914 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002915 if (ret_val)
2916 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002917 } else {
2918 old_bank_offset = nvm->flash_bank_size;
2919 new_bank_offset = 0;
Bruce Allane2434552008-11-21 17:02:41 -08002920 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002921 if (ret_val)
2922 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002923 }
2924
2925 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allane921eb12012-11-28 09:28:37 +00002926 /* Determine whether to write the value stored
Auke Kokbc7f75f2007-09-17 12:30:59 -07002927 * in the other NVM bank or a modified value stored
Bruce Allanad680762008-03-28 09:15:03 -07002928 * in the shadow RAM
2929 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002930 if (dev_spec->shadow_ram[i].modified) {
2931 data = dev_spec->shadow_ram[i].value;
2932 } else {
Bruce Allane2434552008-11-21 17:02:41 -08002933 ret_val = e1000_read_flash_word_ich8lan(hw, i +
2934 old_bank_offset,
2935 &data);
2936 if (ret_val)
2937 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002938 }
2939
Bruce Allane921eb12012-11-28 09:28:37 +00002940 /* If the word is 0x13, then make sure the signature bits
Auke Kokbc7f75f2007-09-17 12:30:59 -07002941 * (15:14) are 11b until the commit has completed.
2942 * This will allow us to write 10b which indicates the
2943 * signature is valid. We want to do this after the write
2944 * has completed so that we don't mark the segment valid
Bruce Allanad680762008-03-28 09:15:03 -07002945 * while the write is still in progress
2946 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002947 if (i == E1000_ICH_NVM_SIG_WORD)
2948 data |= E1000_ICH_NVM_SIG_MASK;
2949
2950 /* Convert offset to bytes. */
2951 act_offset = (i + new_bank_offset) << 1;
2952
2953 udelay(100);
2954 /* Write the bytes to the new bank. */
2955 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2956 act_offset,
2957 (u8)data);
2958 if (ret_val)
2959 break;
2960
2961 udelay(100);
2962 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2963 act_offset + 1,
2964 (u8)(data >> 8));
2965 if (ret_val)
2966 break;
2967 }
2968
Bruce Allane921eb12012-11-28 09:28:37 +00002969 /* Don't bother writing the segment valid bits if sector
Bruce Allanad680762008-03-28 09:15:03 -07002970 * programming failed.
2971 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002972 if (ret_val) {
Bruce Allan4a770352008-10-01 17:18:35 -07002973 /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002974 e_dbg("Flash commit failed.\n");
Bruce Allan9c5e2092010-05-10 15:00:31 +00002975 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002976 }
2977
Bruce Allane921eb12012-11-28 09:28:37 +00002978 /* Finally validate the new segment by setting bit 15:14
Auke Kokbc7f75f2007-09-17 12:30:59 -07002979 * to 10b in word 0x13 , this can be done without an
2980 * erase as well since these bits are 11 to start with
Bruce Allanad680762008-03-28 09:15:03 -07002981 * and we need to change bit 14 to 0b
2982 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002983 act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
Bruce Allane2434552008-11-21 17:02:41 -08002984 ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
Bruce Allan9c5e2092010-05-10 15:00:31 +00002985 if (ret_val)
2986 goto release;
2987
Auke Kokbc7f75f2007-09-17 12:30:59 -07002988 data &= 0xBFFF;
2989 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2990 act_offset * 2 + 1,
2991 (u8)(data >> 8));
Bruce Allan9c5e2092010-05-10 15:00:31 +00002992 if (ret_val)
2993 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002994
Bruce Allane921eb12012-11-28 09:28:37 +00002995 /* And invalidate the previously valid segment by setting
Auke Kokbc7f75f2007-09-17 12:30:59 -07002996 * its signature word (0x13) high_byte to 0b. This can be
2997 * done without an erase because flash erase sets all bits
Bruce Allanad680762008-03-28 09:15:03 -07002998 * to 1's. We can write 1's to 0's without an erase
2999 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003000 act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
3001 ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003002 if (ret_val)
3003 goto release;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003004
3005 /* Great! Everything worked, we can now clear the cached entries. */
3006 for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00003007 dev_spec->shadow_ram[i].modified = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003008 dev_spec->shadow_ram[i].value = 0xFFFF;
3009 }
3010
Bruce Allan9c5e2092010-05-10 15:00:31 +00003011release:
Bruce Allan94d81862009-11-20 23:25:26 +00003012 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003013
Bruce Allane921eb12012-11-28 09:28:37 +00003014 /* Reload the EEPROM, or else modifications will not appear
Auke Kokbc7f75f2007-09-17 12:30:59 -07003015 * until after the next adapter reset.
3016 */
Bruce Allan9c5e2092010-05-10 15:00:31 +00003017 if (!ret_val) {
Bruce Allane85e3632012-02-22 09:03:14 +00003018 nvm->ops.reload(hw);
Bruce Allan1bba4382011-03-19 00:27:20 +00003019 usleep_range(10000, 20000);
Bruce Allan9c5e2092010-05-10 15:00:31 +00003020 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003021
Bruce Allane2434552008-11-21 17:02:41 -08003022out:
3023 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003024 e_dbg("NVM update error: %d\n", ret_val);
Bruce Allane2434552008-11-21 17:02:41 -08003025
Auke Kokbc7f75f2007-09-17 12:30:59 -07003026 return ret_val;
3027}
3028
3029/**
3030 * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
3031 * @hw: pointer to the HW structure
3032 *
3033 * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
3034 * If the bit is 0, that the EEPROM had been modified, but the checksum was not
3035 * calculated, in which case we need to calculate the checksum and set bit 6.
3036 **/
3037static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
3038{
3039 s32 ret_val;
3040 u16 data;
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003041 u16 word;
3042 u16 valid_csum_mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003043
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003044 /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
3045 * the checksum needs to be fixed. This bit is an indication that
3046 * the NVM was prepared by OEM software and did not calculate
3047 * the checksum...a likely scenario.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003048 */
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003049 switch (hw->mac.type) {
3050 case e1000_pch_lpt:
3051 word = NVM_COMPAT;
3052 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
3053 break;
3054 default:
3055 word = NVM_FUTURE_INIT_WORD1;
3056 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
3057 break;
3058 }
3059
3060 ret_val = e1000_read_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003061 if (ret_val)
3062 return ret_val;
3063
Bruce Allan1cc7a3a2013-01-09 08:15:42 +00003064 if (!(data & valid_csum_mask)) {
3065 data |= valid_csum_mask;
3066 ret_val = e1000_write_nvm(hw, word, 1, &data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003067 if (ret_val)
3068 return ret_val;
3069 ret_val = e1000e_update_nvm_checksum(hw);
3070 if (ret_val)
3071 return ret_val;
3072 }
3073
3074 return e1000e_validate_nvm_checksum_generic(hw);
3075}
3076
3077/**
Bruce Allan4a770352008-10-01 17:18:35 -07003078 * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
3079 * @hw: pointer to the HW structure
3080 *
3081 * To prevent malicious write/erase of the NVM, set it to be read-only
3082 * so that the hardware ignores all write/erase cycles of the NVM via
3083 * the flash control registers. The shadow-ram copy of the NVM will
3084 * still be updated, however any updates to this copy will not stick
3085 * across driver reloads.
3086 **/
3087void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
3088{
Bruce Allanca15df52009-10-26 11:23:43 +00003089 struct e1000_nvm_info *nvm = &hw->nvm;
Bruce Allan4a770352008-10-01 17:18:35 -07003090 union ich8_flash_protected_range pr0;
3091 union ich8_hws_flash_status hsfsts;
3092 u32 gfpreg;
Bruce Allan4a770352008-10-01 17:18:35 -07003093
Bruce Allan94d81862009-11-20 23:25:26 +00003094 nvm->ops.acquire(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003095
3096 gfpreg = er32flash(ICH_FLASH_GFPREG);
3097
3098 /* Write-protect GbE Sector of NVM */
3099 pr0.regval = er32flash(ICH_FLASH_PR0);
3100 pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
3101 pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
3102 pr0.range.wpe = true;
3103 ew32flash(ICH_FLASH_PR0, pr0.regval);
3104
Bruce Allane921eb12012-11-28 09:28:37 +00003105 /* Lock down a subset of GbE Flash Control Registers, e.g.
Bruce Allan4a770352008-10-01 17:18:35 -07003106 * PR0 to prevent the write-protection from being lifted.
3107 * Once FLOCKDN is set, the registers protected by it cannot
3108 * be written until FLOCKDN is cleared by a hardware reset.
3109 */
3110 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3111 hsfsts.hsf_status.flockdn = true;
3112 ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
3113
Bruce Allan94d81862009-11-20 23:25:26 +00003114 nvm->ops.release(hw);
Bruce Allan4a770352008-10-01 17:18:35 -07003115}
3116
3117/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003118 * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
3119 * @hw: pointer to the HW structure
3120 * @offset: The offset (in bytes) of the byte/word to read.
3121 * @size: Size of data to read, 1=byte 2=word
3122 * @data: The byte(s) to write to the NVM.
3123 *
3124 * Writes one/two bytes to the NVM using the flash access registers.
3125 **/
3126static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
3127 u8 size, u16 data)
3128{
3129 union ich8_hws_flash_status hsfsts;
3130 union ich8_hws_flash_ctrl hsflctl;
3131 u32 flash_linear_addr;
3132 u32 flash_data = 0;
3133 s32 ret_val;
3134 u8 count = 0;
3135
3136 if (size < 1 || size > 2 || data > size * 0xff ||
3137 offset > ICH_FLASH_LINEAR_ADDR_MASK)
3138 return -E1000_ERR_NVM;
3139
3140 flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
3141 hw->nvm.flash_base_addr;
3142
3143 do {
3144 udelay(1);
3145 /* Steps */
3146 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3147 if (ret_val)
3148 break;
3149
3150 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3151 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
3152 hsflctl.hsf_ctrl.fldbcount = size -1;
3153 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
3154 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3155
3156 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3157
3158 if (size == 1)
3159 flash_data = (u32)data & 0x00FF;
3160 else
3161 flash_data = (u32)data;
3162
3163 ew32flash(ICH_FLASH_FDATA0, flash_data);
3164
Bruce Allane921eb12012-11-28 09:28:37 +00003165 /* check if FCERR is set to 1 , if set to 1, clear it
Bruce Allanad680762008-03-28 09:15:03 -07003166 * and try the whole sequence a few more times else done
3167 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003168 ret_val = e1000_flash_cycle_ich8lan(hw,
3169 ICH_FLASH_WRITE_COMMAND_TIMEOUT);
3170 if (!ret_val)
3171 break;
3172
Bruce Allane921eb12012-11-28 09:28:37 +00003173 /* If we're here, then things are most likely
Auke Kokbc7f75f2007-09-17 12:30:59 -07003174 * completely hosed, but if the error condition
3175 * is detected, it won't hurt to give it another
3176 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
3177 */
3178 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003179 if (hsfsts.hsf_status.flcerr)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003180 /* Repeat for some time before giving up. */
3181 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003182 if (!hsfsts.hsf_status.flcdone) {
Bruce Allan434f1392011-12-16 00:46:54 +00003183 e_dbg("Timeout error - flash cycle did not complete.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003184 break;
3185 }
3186 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
3187
3188 return ret_val;
3189}
3190
3191/**
3192 * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
3193 * @hw: pointer to the HW structure
3194 * @offset: The index of the byte to read.
3195 * @data: The byte to write to the NVM.
3196 *
3197 * Writes a single byte to the NVM using the flash access registers.
3198 **/
3199static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
3200 u8 data)
3201{
3202 u16 word = (u16)data;
3203
3204 return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
3205}
3206
3207/**
3208 * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
3209 * @hw: pointer to the HW structure
3210 * @offset: The offset of the byte to write.
3211 * @byte: The byte to write to the NVM.
3212 *
3213 * Writes a single byte to the NVM using the flash access registers.
3214 * Goes through a retry algorithm before giving up.
3215 **/
3216static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
3217 u32 offset, u8 byte)
3218{
3219 s32 ret_val;
3220 u16 program_retries;
3221
3222 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3223 if (!ret_val)
3224 return ret_val;
3225
3226 for (program_retries = 0; program_retries < 100; program_retries++) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003227 e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003228 udelay(100);
3229 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
3230 if (!ret_val)
3231 break;
3232 }
3233 if (program_retries == 100)
3234 return -E1000_ERR_NVM;
3235
3236 return 0;
3237}
3238
3239/**
3240 * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
3241 * @hw: pointer to the HW structure
3242 * @bank: 0 for first bank, 1 for second bank, etc.
3243 *
3244 * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
3245 * bank N is 4096 * N + flash_reg_addr.
3246 **/
3247static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
3248{
3249 struct e1000_nvm_info *nvm = &hw->nvm;
3250 union ich8_hws_flash_status hsfsts;
3251 union ich8_hws_flash_ctrl hsflctl;
3252 u32 flash_linear_addr;
3253 /* bank size is in 16bit words - adjust to bytes */
3254 u32 flash_bank_size = nvm->flash_bank_size * 2;
3255 s32 ret_val;
3256 s32 count = 0;
Bruce Allana708dd82009-11-20 23:28:37 +00003257 s32 j, iteration, sector_size;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003258
3259 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
3260
Bruce Allane921eb12012-11-28 09:28:37 +00003261 /* Determine HW Sector size: Read BERASE bits of hw flash status
Bruce Allanad680762008-03-28 09:15:03 -07003262 * register
3263 * 00: The Hw sector is 256 bytes, hence we need to erase 16
Auke Kokbc7f75f2007-09-17 12:30:59 -07003264 * consecutive sectors. The start index for the nth Hw sector
3265 * can be calculated as = bank * 4096 + n * 256
3266 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
3267 * The start index for the nth Hw sector can be calculated
3268 * as = bank * 4096
3269 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
3270 * (ich9 only, otherwise error condition)
3271 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
3272 */
3273 switch (hsfsts.hsf_status.berasesz) {
3274 case 0:
3275 /* Hw sector size 256 */
3276 sector_size = ICH_FLASH_SEG_SIZE_256;
3277 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
3278 break;
3279 case 1:
3280 sector_size = ICH_FLASH_SEG_SIZE_4K;
Bruce Allan28c91952009-07-01 13:28:32 +00003281 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003282 break;
3283 case 2:
Bruce Allan148675a2009-08-07 07:41:56 +00003284 sector_size = ICH_FLASH_SEG_SIZE_8K;
3285 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003286 break;
3287 case 3:
3288 sector_size = ICH_FLASH_SEG_SIZE_64K;
Bruce Allan28c91952009-07-01 13:28:32 +00003289 iteration = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003290 break;
3291 default:
3292 return -E1000_ERR_NVM;
3293 }
3294
3295 /* Start with the base address, then add the sector offset. */
3296 flash_linear_addr = hw->nvm.flash_base_addr;
Bruce Allan148675a2009-08-07 07:41:56 +00003297 flash_linear_addr += (bank) ? flash_bank_size : 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003298
3299 for (j = 0; j < iteration ; j++) {
3300 do {
3301 /* Steps */
3302 ret_val = e1000_flash_cycle_init_ich8lan(hw);
3303 if (ret_val)
3304 return ret_val;
3305
Bruce Allane921eb12012-11-28 09:28:37 +00003306 /* Write a value 11 (block Erase) in Flash
Bruce Allanad680762008-03-28 09:15:03 -07003307 * Cycle field in hw flash control
3308 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003309 hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
3310 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
3311 ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
3312
Bruce Allane921eb12012-11-28 09:28:37 +00003313 /* Write the last 24 bits of an index within the
Auke Kokbc7f75f2007-09-17 12:30:59 -07003314 * block into Flash Linear address field in Flash
3315 * Address.
3316 */
3317 flash_linear_addr += (j * sector_size);
3318 ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
3319
3320 ret_val = e1000_flash_cycle_ich8lan(hw,
3321 ICH_FLASH_ERASE_COMMAND_TIMEOUT);
Bruce Allan9e2d7652012-01-31 06:37:27 +00003322 if (!ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003323 break;
3324
Bruce Allane921eb12012-11-28 09:28:37 +00003325 /* Check if FCERR is set to 1. If 1,
Auke Kokbc7f75f2007-09-17 12:30:59 -07003326 * clear it and try the whole sequence
Bruce Allanad680762008-03-28 09:15:03 -07003327 * a few more times else Done
3328 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003329 hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
Bruce Allan04499ec2012-04-13 00:08:31 +00003330 if (hsfsts.hsf_status.flcerr)
Bruce Allanad680762008-03-28 09:15:03 -07003331 /* repeat for some time before giving up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003332 continue;
Bruce Allan04499ec2012-04-13 00:08:31 +00003333 else if (!hsfsts.hsf_status.flcdone)
Auke Kokbc7f75f2007-09-17 12:30:59 -07003334 return ret_val;
3335 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
3336 }
3337
3338 return 0;
3339}
3340
3341/**
3342 * e1000_valid_led_default_ich8lan - Set the default LED settings
3343 * @hw: pointer to the HW structure
3344 * @data: Pointer to the LED settings
3345 *
3346 * Reads the LED default settings from the NVM to data. If the NVM LED
3347 * settings is all 0's or F's, set the LED default to a valid LED default
3348 * setting.
3349 **/
3350static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
3351{
3352 s32 ret_val;
3353
3354 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
3355 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003356 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003357 return ret_val;
3358 }
3359
3360 if (*data == ID_LED_RESERVED_0000 ||
3361 *data == ID_LED_RESERVED_FFFF)
3362 *data = ID_LED_DEFAULT_ICH8LAN;
3363
3364 return 0;
3365}
3366
3367/**
Bruce Allana4f58f52009-06-02 11:29:18 +00003368 * e1000_id_led_init_pchlan - store LED configurations
3369 * @hw: pointer to the HW structure
3370 *
3371 * PCH does not control LEDs via the LEDCTL register, rather it uses
3372 * the PHY LED configuration register.
3373 *
3374 * PCH also does not have an "always on" or "always off" mode which
3375 * complicates the ID feature. Instead of using the "on" mode to indicate
Bruce Alland1964eb2012-02-22 09:02:21 +00003376 * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
Bruce Allana4f58f52009-06-02 11:29:18 +00003377 * use "link_up" mode. The LEDs will still ID on request if there is no
3378 * link based on logic in e1000_led_[on|off]_pchlan().
3379 **/
3380static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
3381{
3382 struct e1000_mac_info *mac = &hw->mac;
3383 s32 ret_val;
3384 const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
3385 const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
3386 u16 data, i, temp, shift;
3387
3388 /* Get default ID LED modes */
3389 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
3390 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003391 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003392
3393 mac->ledctl_default = er32(LEDCTL);
3394 mac->ledctl_mode1 = mac->ledctl_default;
3395 mac->ledctl_mode2 = mac->ledctl_default;
3396
3397 for (i = 0; i < 4; i++) {
3398 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
3399 shift = (i * 5);
3400 switch (temp) {
3401 case ID_LED_ON1_DEF2:
3402 case ID_LED_ON1_ON2:
3403 case ID_LED_ON1_OFF2:
3404 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3405 mac->ledctl_mode1 |= (ledctl_on << shift);
3406 break;
3407 case ID_LED_OFF1_DEF2:
3408 case ID_LED_OFF1_ON2:
3409 case ID_LED_OFF1_OFF2:
3410 mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
3411 mac->ledctl_mode1 |= (ledctl_off << shift);
3412 break;
3413 default:
3414 /* Do nothing */
3415 break;
3416 }
3417 switch (temp) {
3418 case ID_LED_DEF1_ON2:
3419 case ID_LED_ON1_ON2:
3420 case ID_LED_OFF1_ON2:
3421 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3422 mac->ledctl_mode2 |= (ledctl_on << shift);
3423 break;
3424 case ID_LED_DEF1_OFF2:
3425 case ID_LED_ON1_OFF2:
3426 case ID_LED_OFF1_OFF2:
3427 mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
3428 mac->ledctl_mode2 |= (ledctl_off << shift);
3429 break;
3430 default:
3431 /* Do nothing */
3432 break;
3433 }
3434 }
3435
Bruce Allan5015e532012-02-08 02:55:56 +00003436 return 0;
Bruce Allana4f58f52009-06-02 11:29:18 +00003437}
3438
3439/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07003440 * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
3441 * @hw: pointer to the HW structure
3442 *
3443 * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
3444 * register, so the the bus width is hard coded.
3445 **/
3446static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
3447{
3448 struct e1000_bus_info *bus = &hw->bus;
3449 s32 ret_val;
3450
3451 ret_val = e1000e_get_bus_info_pcie(hw);
3452
Bruce Allane921eb12012-11-28 09:28:37 +00003453 /* ICH devices are "PCI Express"-ish. They have
Auke Kokbc7f75f2007-09-17 12:30:59 -07003454 * a configuration space, but do not contain
3455 * PCI Express Capability registers, so bus width
3456 * must be hardcoded.
3457 */
3458 if (bus->width == e1000_bus_width_unknown)
3459 bus->width = e1000_bus_width_pcie_x1;
3460
3461 return ret_val;
3462}
3463
3464/**
3465 * e1000_reset_hw_ich8lan - Reset the hardware
3466 * @hw: pointer to the HW structure
3467 *
3468 * Does a full reset of the hardware which includes a reset of the PHY and
3469 * MAC.
3470 **/
3471static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
3472{
Bruce Allan1d5846b2009-10-29 13:46:05 +00003473 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan62bc8132012-03-20 03:47:57 +00003474 u16 kum_cfg;
3475 u32 ctrl, reg;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003476 s32 ret_val;
3477
Bruce Allane921eb12012-11-28 09:28:37 +00003478 /* Prevent the PCI-E bus from sticking if there is no TLP connection
Auke Kokbc7f75f2007-09-17 12:30:59 -07003479 * on the last TLP read/write transaction when MAC is reset.
3480 */
3481 ret_val = e1000e_disable_pcie_master(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003482 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003483 e_dbg("PCI-E Master disable polling has failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003484
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003485 e_dbg("Masking off all interrupts\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003486 ew32(IMC, 0xffffffff);
3487
Bruce Allane921eb12012-11-28 09:28:37 +00003488 /* Disable the Transmit and Receive units. Then delay to allow
Auke Kokbc7f75f2007-09-17 12:30:59 -07003489 * any pending transactions to complete before we hit the MAC
3490 * with the global reset.
3491 */
3492 ew32(RCTL, 0);
3493 ew32(TCTL, E1000_TCTL_PSP);
3494 e1e_flush();
3495
Bruce Allan1bba4382011-03-19 00:27:20 +00003496 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003497
3498 /* Workaround for ICH8 bit corruption issue in FIFO memory */
3499 if (hw->mac.type == e1000_ich8lan) {
3500 /* Set Tx and Rx buffer allocation to 8k apiece. */
3501 ew32(PBA, E1000_PBA_8K);
3502 /* Set Packet Buffer Size to 16k. */
3503 ew32(PBS, E1000_PBS_16K);
3504 }
3505
Bruce Allan1d5846b2009-10-29 13:46:05 +00003506 if (hw->mac.type == e1000_pchlan) {
Bruce Allan62bc8132012-03-20 03:47:57 +00003507 /* Save the NVM K1 bit setting */
3508 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
Bruce Allan1d5846b2009-10-29 13:46:05 +00003509 if (ret_val)
3510 return ret_val;
3511
Bruce Allan62bc8132012-03-20 03:47:57 +00003512 if (kum_cfg & E1000_NVM_K1_ENABLE)
Bruce Allan1d5846b2009-10-29 13:46:05 +00003513 dev_spec->nvm_k1_enabled = true;
3514 else
3515 dev_spec->nvm_k1_enabled = false;
3516 }
3517
Auke Kokbc7f75f2007-09-17 12:30:59 -07003518 ctrl = er32(CTRL);
3519
Bruce Allan44abd5c2012-02-22 09:02:37 +00003520 if (!hw->phy.ops.check_reset_block(hw)) {
Bruce Allane921eb12012-11-28 09:28:37 +00003521 /* Full-chip reset requires MAC and PHY reset at the same
Auke Kokbc7f75f2007-09-17 12:30:59 -07003522 * time to make sure the interface between MAC and the
3523 * external PHY is reset.
3524 */
3525 ctrl |= E1000_CTRL_PHY_RST;
Bruce Allan605c82b2010-09-22 17:17:01 +00003526
Bruce Allane921eb12012-11-28 09:28:37 +00003527 /* Gate automatic PHY configuration by hardware on
Bruce Allan605c82b2010-09-22 17:17:01 +00003528 * non-managed 82579
3529 */
3530 if ((hw->mac.type == e1000_pch2lan) &&
3531 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3532 e1000_gate_hw_phy_config_ich8lan(hw, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003533 }
3534 ret_val = e1000_acquire_swflag_ich8lan(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003535 e_dbg("Issuing a global reset to ich8lan\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003536 ew32(CTRL, (ctrl | E1000_CTRL_RST));
Jesse Brandeburg945a5152011-07-20 00:56:21 +00003537 /* cannot issue a flush here because it hangs the hardware */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003538 msleep(20);
3539
Bruce Allan62bc8132012-03-20 03:47:57 +00003540 /* Set Phy Config Counter to 50msec */
3541 if (hw->mac.type == e1000_pch2lan) {
3542 reg = er32(FEXTNVM3);
3543 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
3544 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
3545 ew32(FEXTNVM3, reg);
3546 }
3547
Bruce Allanfc0c7762009-07-01 13:27:55 +00003548 if (!ret_val)
Bruce Allana90b4122011-10-07 03:50:38 +00003549 clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
Jesse Brandeburg37f40232008-10-02 16:33:20 -07003550
Bruce Allane98cac42010-05-10 15:02:32 +00003551 if (ctrl & E1000_CTRL_PHY_RST) {
Bruce Allanfc0c7762009-07-01 13:27:55 +00003552 ret_val = hw->phy.ops.get_cfg_done(hw);
Bruce Allane98cac42010-05-10 15:02:32 +00003553 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003554 return ret_val;
Bruce Allanfc0c7762009-07-01 13:27:55 +00003555
Bruce Allane98cac42010-05-10 15:02:32 +00003556 ret_val = e1000_post_phy_reset_ich8lan(hw);
Bruce Allanf523d212009-10-29 13:45:45 +00003557 if (ret_val)
Bruce Allan5015e532012-02-08 02:55:56 +00003558 return ret_val;
Bruce Allanf523d212009-10-29 13:45:45 +00003559 }
Bruce Allane98cac42010-05-10 15:02:32 +00003560
Bruce Allane921eb12012-11-28 09:28:37 +00003561 /* For PCH, this write will make sure that any noise
Bruce Allan7d3cabb2009-07-01 13:29:08 +00003562 * will be detected as a CRC error and be dropped rather than show up
3563 * as a bad packet to the DMA engine.
3564 */
3565 if (hw->mac.type == e1000_pchlan)
3566 ew32(CRC_OFFSET, 0x65656565);
3567
Auke Kokbc7f75f2007-09-17 12:30:59 -07003568 ew32(IMC, 0xffffffff);
Bruce Allandd93f952011-01-06 14:29:48 +00003569 er32(ICR);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003570
Bruce Allan62bc8132012-03-20 03:47:57 +00003571 reg = er32(KABGTXD);
3572 reg |= E1000_KABGTXD_BGSQLBIAS;
3573 ew32(KABGTXD, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003574
Bruce Allan5015e532012-02-08 02:55:56 +00003575 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003576}
3577
3578/**
3579 * e1000_init_hw_ich8lan - Initialize the hardware
3580 * @hw: pointer to the HW structure
3581 *
3582 * Prepares the hardware for transmit and receive by doing the following:
3583 * - initialize hardware bits
3584 * - initialize LED identification
3585 * - setup receive address registers
3586 * - setup flow control
Auke Kok489815c2008-02-21 15:11:07 -08003587 * - setup transmit descriptors
Auke Kokbc7f75f2007-09-17 12:30:59 -07003588 * - clear statistics
3589 **/
3590static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
3591{
3592 struct e1000_mac_info *mac = &hw->mac;
3593 u32 ctrl_ext, txdctl, snoop;
3594 s32 ret_val;
3595 u16 i;
3596
3597 e1000_initialize_hw_bits_ich8lan(hw);
3598
3599 /* Initialize identification LED */
Bruce Allana4f58f52009-06-02 11:29:18 +00003600 ret_val = mac->ops.id_led_init(hw);
Bruce Allande39b752009-11-20 23:27:59 +00003601 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003602 e_dbg("Error initializing identification LED\n");
Bruce Allande39b752009-11-20 23:27:59 +00003603 /* This is not fatal and we should not stop init due to this */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003604
3605 /* Setup the receive address. */
3606 e1000e_init_rx_addrs(hw, mac->rar_entry_count);
3607
3608 /* Zero out the Multicast HASH table */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003609 e_dbg("Zeroing the MTA\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003610 for (i = 0; i < mac->mta_reg_count; i++)
3611 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
3612
Bruce Allane921eb12012-11-28 09:28:37 +00003613 /* The 82578 Rx buffer will stall if wakeup is enabled in host and
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003614 * the ME. Disable wakeup by clearing the host wakeup bit.
Bruce Allanfc0c7762009-07-01 13:27:55 +00003615 * Reset the phy after disabling host wakeup to reset the Rx buffer.
3616 */
3617 if (hw->phy.type == e1000_phy_82578) {
Bruce Allan3ebfc7c2011-05-13 07:20:14 +00003618 e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
3619 i &= ~BM_WUC_HOST_WU_BIT;
3620 e1e_wphy(hw, BM_PORT_GEN_CFG, i);
Bruce Allanfc0c7762009-07-01 13:27:55 +00003621 ret_val = e1000_phy_hw_reset_ich8lan(hw);
3622 if (ret_val)
3623 return ret_val;
3624 }
3625
Auke Kokbc7f75f2007-09-17 12:30:59 -07003626 /* Setup link and flow control */
Bruce Allan1a46b402012-02-22 09:02:26 +00003627 ret_val = mac->ops.setup_link(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003628
3629 /* Set the transmit descriptor write-back policy for both queues */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003630 txdctl = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003631 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3632 E1000_TXDCTL_FULL_TX_DESC_WB;
3633 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3634 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003635 ew32(TXDCTL(0), txdctl);
3636 txdctl = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003637 txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
3638 E1000_TXDCTL_FULL_TX_DESC_WB;
3639 txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
3640 E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003641 ew32(TXDCTL(1), txdctl);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003642
Bruce Allane921eb12012-11-28 09:28:37 +00003643 /* ICH8 has opposite polarity of no_snoop bits.
Bruce Allanad680762008-03-28 09:15:03 -07003644 * By default, we should use snoop behavior.
3645 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003646 if (mac->type == e1000_ich8lan)
3647 snoop = PCIE_ICH8_SNOOP_ALL;
3648 else
3649 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
3650 e1000e_set_pcie_no_snoop(hw, snoop);
3651
3652 ctrl_ext = er32(CTRL_EXT);
3653 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
3654 ew32(CTRL_EXT, ctrl_ext);
3655
Bruce Allane921eb12012-11-28 09:28:37 +00003656 /* Clear all of the statistics registers (clear on read). It is
Auke Kokbc7f75f2007-09-17 12:30:59 -07003657 * important that we do this after we have tried to establish link
3658 * because the symbol error count will increment wildly if there
3659 * is no link.
3660 */
3661 e1000_clear_hw_cntrs_ich8lan(hw);
3662
Bruce Allane561a702012-02-08 02:55:46 +00003663 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003664}
3665/**
3666 * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
3667 * @hw: pointer to the HW structure
3668 *
3669 * Sets/Clears required hardware bits necessary for correctly setting up the
3670 * hardware for transmit and receive.
3671 **/
3672static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
3673{
3674 u32 reg;
3675
3676 /* Extended Device Control */
3677 reg = er32(CTRL_EXT);
3678 reg |= (1 << 22);
Bruce Allana4f58f52009-06-02 11:29:18 +00003679 /* Enable PHY low-power state when MAC is at D3 w/o WoL */
3680 if (hw->mac.type >= e1000_pchlan)
3681 reg |= E1000_CTRL_EXT_PHYPDEN;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003682 ew32(CTRL_EXT, reg);
3683
3684 /* Transmit Descriptor Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003685 reg = er32(TXDCTL(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003686 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003687 ew32(TXDCTL(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003688
3689 /* Transmit Descriptor Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003690 reg = er32(TXDCTL(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003691 reg |= (1 << 22);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003692 ew32(TXDCTL(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003693
3694 /* Transmit Arbitration Control 0 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003695 reg = er32(TARC(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003696 if (hw->mac.type == e1000_ich8lan)
3697 reg |= (1 << 28) | (1 << 29);
3698 reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003699 ew32(TARC(0), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003700
3701 /* Transmit Arbitration Control 1 */
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003702 reg = er32(TARC(1));
Auke Kokbc7f75f2007-09-17 12:30:59 -07003703 if (er32(TCTL) & E1000_TCTL_MULR)
3704 reg &= ~(1 << 28);
3705 else
3706 reg |= (1 << 28);
3707 reg |= (1 << 24) | (1 << 26) | (1 << 30);
Jeff Kirshere9ec2c02008-04-02 13:48:13 -07003708 ew32(TARC(1), reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003709
3710 /* Device Status */
3711 if (hw->mac.type == e1000_ich8lan) {
3712 reg = er32(STATUS);
3713 reg &= ~(1 << 31);
3714 ew32(STATUS, reg);
3715 }
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003716
Bruce Allane921eb12012-11-28 09:28:37 +00003717 /* work-around descriptor data corruption issue during nfs v2 udp
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003718 * traffic, just disable the nfs filtering capability
3719 */
3720 reg = er32(RFCTL);
3721 reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
Matthew Vickf6bd5572012-04-25 08:01:05 +00003722
Bruce Allane921eb12012-11-28 09:28:37 +00003723 /* Disable IPv6 extension header parsing because some malformed
Matthew Vickf6bd5572012-04-25 08:01:05 +00003724 * IPv6 headers can hang the Rx.
3725 */
3726 if (hw->mac.type == e1000_ich8lan)
3727 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
Jesse Brandeburga80483d2010-03-05 02:21:44 +00003728 ew32(RFCTL, reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003729}
3730
3731/**
3732 * e1000_setup_link_ich8lan - Setup flow control and link settings
3733 * @hw: pointer to the HW structure
3734 *
3735 * Determines which flow control settings to use, then configures flow
3736 * control. Calls the appropriate media-specific link configuration
3737 * function. Assuming the adapter has a valid link partner, a valid link
3738 * should be established. Assumes the hardware has previously been reset
3739 * and the transmitter and receiver are not enabled.
3740 **/
3741static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
3742{
Auke Kokbc7f75f2007-09-17 12:30:59 -07003743 s32 ret_val;
3744
Bruce Allan44abd5c2012-02-22 09:02:37 +00003745 if (hw->phy.ops.check_reset_block(hw))
Auke Kokbc7f75f2007-09-17 12:30:59 -07003746 return 0;
3747
Bruce Allane921eb12012-11-28 09:28:37 +00003748 /* ICH parts do not have a word in the NVM to determine
Auke Kokbc7f75f2007-09-17 12:30:59 -07003749 * the default flow control setting, so we explicitly
3750 * set it to full.
3751 */
Bruce Allan37289d92009-06-02 11:29:37 +00003752 if (hw->fc.requested_mode == e1000_fc_default) {
3753 /* Workaround h/w hang when Tx flow control enabled */
3754 if (hw->mac.type == e1000_pchlan)
3755 hw->fc.requested_mode = e1000_fc_rx_pause;
3756 else
3757 hw->fc.requested_mode = e1000_fc_full;
3758 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003759
Bruce Allane921eb12012-11-28 09:28:37 +00003760 /* Save off the requested flow control mode for use later. Depending
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003761 * on the link partner's capabilities, we may or may not use this mode.
3762 */
3763 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -07003764
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003765 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08003766 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003767
3768 /* Continue to configure the copper link. */
Bruce Allan944ce012012-02-22 09:02:42 +00003769 ret_val = hw->mac.ops.setup_physical_interface(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003770 if (ret_val)
3771 return ret_val;
3772
Jeff Kirsher318a94d2008-03-28 09:15:16 -07003773 ew32(FCTTV, hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003774 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00003775 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00003776 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00003777 (hw->phy.type == e1000_phy_82577)) {
Bruce Allana3055952010-05-10 15:02:12 +00003778 ew32(FCRTV_PCH, hw->fc.refresh_time);
3779
Bruce Allan482fed82011-01-06 14:29:49 +00003780 ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
3781 hw->fc.pause_time);
Bruce Allana4f58f52009-06-02 11:29:18 +00003782 if (ret_val)
3783 return ret_val;
3784 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07003785
3786 return e1000e_set_fc_watermarks(hw);
3787}
3788
3789/**
3790 * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
3791 * @hw: pointer to the HW structure
3792 *
3793 * Configures the kumeran interface to the PHY to wait the appropriate time
3794 * when polling the PHY, then call the generic setup_copper_link to finish
3795 * configuring the copper link.
3796 **/
3797static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
3798{
3799 u32 ctrl;
3800 s32 ret_val;
3801 u16 reg_data;
3802
3803 ctrl = er32(CTRL);
3804 ctrl |= E1000_CTRL_SLU;
3805 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3806 ew32(CTRL, ctrl);
3807
Bruce Allane921eb12012-11-28 09:28:37 +00003808 /* Set the mac to wait the maximum time between each iteration
Auke Kokbc7f75f2007-09-17 12:30:59 -07003809 * and increase the max iterations when polling the phy;
Bruce Allanad680762008-03-28 09:15:03 -07003810 * this fixes erroneous timeouts at 10Mbps.
3811 */
Bruce Allan07818952009-12-08 07:28:01 +00003812 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003813 if (ret_val)
3814 return ret_val;
Bruce Allan07818952009-12-08 07:28:01 +00003815 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3816 &reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003817 if (ret_val)
3818 return ret_val;
3819 reg_data |= 0x3F;
Bruce Allan07818952009-12-08 07:28:01 +00003820 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
3821 reg_data);
Auke Kokbc7f75f2007-09-17 12:30:59 -07003822 if (ret_val)
3823 return ret_val;
3824
Bruce Allana4f58f52009-06-02 11:29:18 +00003825 switch (hw->phy.type) {
3826 case e1000_phy_igp_3:
Auke Kokbc7f75f2007-09-17 12:30:59 -07003827 ret_val = e1000e_copper_link_setup_igp(hw);
3828 if (ret_val)
3829 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003830 break;
3831 case e1000_phy_bm:
3832 case e1000_phy_82578:
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003833 ret_val = e1000e_copper_link_setup_m88(hw);
3834 if (ret_val)
3835 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003836 break;
3837 case e1000_phy_82577:
Bruce Alland3738bb2010-06-16 13:27:28 +00003838 case e1000_phy_82579:
Bruce Allan2fbe4522012-04-19 03:21:47 +00003839 case e1000_phy_i217:
Bruce Allana4f58f52009-06-02 11:29:18 +00003840 ret_val = e1000_copper_link_setup_82577(hw);
3841 if (ret_val)
3842 return ret_val;
3843 break;
3844 case e1000_phy_ife:
Bruce Allan482fed82011-01-06 14:29:49 +00003845 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003846 if (ret_val)
3847 return ret_val;
3848
3849 reg_data &= ~IFE_PMC_AUTO_MDIX;
3850
3851 switch (hw->phy.mdix) {
3852 case 1:
3853 reg_data &= ~IFE_PMC_FORCE_MDIX;
3854 break;
3855 case 2:
3856 reg_data |= IFE_PMC_FORCE_MDIX;
3857 break;
3858 case 0:
3859 default:
3860 reg_data |= IFE_PMC_AUTO_MDIX;
3861 break;
3862 }
Bruce Allan482fed82011-01-06 14:29:49 +00003863 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003864 if (ret_val)
3865 return ret_val;
Bruce Allana4f58f52009-06-02 11:29:18 +00003866 break;
3867 default:
3868 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07003869 }
Bruce Allan3fa8293632012-02-08 02:55:40 +00003870
Auke Kokbc7f75f2007-09-17 12:30:59 -07003871 return e1000e_setup_copper_link(hw);
3872}
3873
3874/**
3875 * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3876 * @hw: pointer to the HW structure
3877 * @speed: pointer to store current link speed
3878 * @duplex: pointer to store the current link duplex
3879 *
Bruce Allanad680762008-03-28 09:15:03 -07003880 * Calls the generic get_speed_and_duplex to retrieve the current link
Auke Kokbc7f75f2007-09-17 12:30:59 -07003881 * information and then calls the Kumeran lock loss workaround for links at
3882 * gigabit speeds.
3883 **/
3884static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3885 u16 *duplex)
3886{
3887 s32 ret_val;
3888
3889 ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
3890 if (ret_val)
3891 return ret_val;
3892
3893 if ((hw->mac.type == e1000_ich8lan) &&
3894 (hw->phy.type == e1000_phy_igp_3) &&
3895 (*speed == SPEED_1000)) {
3896 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3897 }
3898
3899 return ret_val;
3900}
3901
3902/**
3903 * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3904 * @hw: pointer to the HW structure
3905 *
3906 * Work-around for 82566 Kumeran PCS lock loss:
3907 * On link status change (i.e. PCI reset, speed change) and link is up and
3908 * speed is gigabit-
3909 * 0) if workaround is optionally disabled do nothing
3910 * 1) wait 1ms for Kumeran link to come up
3911 * 2) check Kumeran Diagnostic register PCS lock loss bit
3912 * 3) if not set the link is locked (all is good), otherwise...
3913 * 4) reset the PHY
3914 * 5) repeat up to 10 times
3915 * Note: this is only called for IGP3 copper when speed is 1gb.
3916 **/
3917static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3918{
3919 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3920 u32 phy_ctrl;
3921 s32 ret_val;
3922 u16 i, data;
3923 bool link;
3924
3925 if (!dev_spec->kmrn_lock_loss_workaround_enabled)
3926 return 0;
3927
Bruce Allane921eb12012-11-28 09:28:37 +00003928 /* Make sure link is up before proceeding. If not just return.
Auke Kokbc7f75f2007-09-17 12:30:59 -07003929 * Attempting this while link is negotiating fouled up link
Bruce Allanad680762008-03-28 09:15:03 -07003930 * stability
3931 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003932 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3933 if (!link)
3934 return 0;
3935
3936 for (i = 0; i < 10; i++) {
3937 /* read once to clear */
3938 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3939 if (ret_val)
3940 return ret_val;
3941 /* and again to get new status */
3942 ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
3943 if (ret_val)
3944 return ret_val;
3945
3946 /* check for PCS lock */
3947 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3948 return 0;
3949
3950 /* Issue PHY reset */
3951 e1000_phy_hw_reset(hw);
3952 mdelay(5);
3953 }
3954 /* Disable GigE link negotiation */
3955 phy_ctrl = er32(PHY_CTRL);
3956 phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3957 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3958 ew32(PHY_CTRL, phy_ctrl);
3959
Bruce Allane921eb12012-11-28 09:28:37 +00003960 /* Call gig speed drop workaround on Gig disable before accessing
Bruce Allanad680762008-03-28 09:15:03 -07003961 * any PHY registers
3962 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07003963 e1000e_gig_downshift_workaround_ich8lan(hw);
3964
3965 /* unable to acquire PCS lock */
3966 return -E1000_ERR_PHY;
3967}
3968
3969/**
Bruce Allan6e3c8072012-02-22 09:02:47 +00003970 * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003971 * @hw: pointer to the HW structure
Auke Kok489815c2008-02-21 15:11:07 -08003972 * @state: boolean value used to set the current Kumeran workaround state
Auke Kokbc7f75f2007-09-17 12:30:59 -07003973 *
Bruce Allan564ea9b2009-11-20 23:26:44 +00003974 * If ICH8, set the current Kumeran workaround state (enabled - true
3975 * /disabled - false).
Auke Kokbc7f75f2007-09-17 12:30:59 -07003976 **/
3977void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3978 bool state)
3979{
3980 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3981
3982 if (hw->mac.type != e1000_ich8lan) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00003983 e_dbg("Workaround applies to ICH8 only.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07003984 return;
3985 }
3986
3987 dev_spec->kmrn_lock_loss_workaround_enabled = state;
3988}
3989
3990/**
3991 * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3992 * @hw: pointer to the HW structure
3993 *
3994 * Workaround for 82566 power-down on D3 entry:
3995 * 1) disable gigabit link
3996 * 2) write VR power-down enable
3997 * 3) read it back
3998 * Continue if successful, else issue LCD reset and repeat
3999 **/
4000void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
4001{
4002 u32 reg;
4003 u16 data;
4004 u8 retry = 0;
4005
4006 if (hw->phy.type != e1000_phy_igp_3)
4007 return;
4008
4009 /* Try the workaround twice (if needed) */
4010 do {
4011 /* Disable link */
4012 reg = er32(PHY_CTRL);
4013 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
4014 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4015 ew32(PHY_CTRL, reg);
4016
Bruce Allane921eb12012-11-28 09:28:37 +00004017 /* Call gig speed drop workaround on Gig disable before
Bruce Allanad680762008-03-28 09:15:03 -07004018 * accessing any PHY registers
4019 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004020 if (hw->mac.type == e1000_ich8lan)
4021 e1000e_gig_downshift_workaround_ich8lan(hw);
4022
4023 /* Write VR power-down enable */
4024 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4025 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4026 e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
4027
4028 /* Read it back and test */
4029 e1e_rphy(hw, IGP3_VR_CTRL, &data);
4030 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
4031 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
4032 break;
4033
4034 /* Issue PHY reset and repeat at most one more time */
4035 reg = er32(CTRL);
4036 ew32(CTRL, reg | E1000_CTRL_PHY_RST);
4037 retry++;
4038 } while (retry);
4039}
4040
4041/**
4042 * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
4043 * @hw: pointer to the HW structure
4044 *
4045 * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
Auke Kok489815c2008-02-21 15:11:07 -08004046 * LPLU, Gig disable, MDIC PHY reset):
Auke Kokbc7f75f2007-09-17 12:30:59 -07004047 * 1) Set Kumeran Near-end loopback
4048 * 2) Clear Kumeran Near-end loopback
Bruce Allan462d5992011-09-30 08:07:11 +00004049 * Should only be called for ICH8[m] devices with any 1G Phy.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004050 **/
4051void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
4052{
4053 s32 ret_val;
4054 u16 reg_data;
4055
Bruce Allan462d5992011-09-30 08:07:11 +00004056 if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
Auke Kokbc7f75f2007-09-17 12:30:59 -07004057 return;
4058
4059 ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4060 &reg_data);
4061 if (ret_val)
4062 return;
4063 reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
4064 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4065 reg_data);
4066 if (ret_val)
4067 return;
4068 reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
4069 ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
4070 reg_data);
4071}
4072
4073/**
Bruce Allan99730e42011-05-13 07:19:48 +00004074 * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004075 * @hw: pointer to the HW structure
4076 *
4077 * During S0 to Sx transition, it is possible the link remains at gig
4078 * instead of negotiating to a lower speed. Before going to Sx, set
Bruce Allanc077a902011-12-16 00:46:38 +00004079 * 'Gig Disable' to force link speed negotiation to a lower speed based on
4080 * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
4081 * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
4082 * needs to be written.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004083 * Parts that support (and are linked to a partner which support) EEE in
4084 * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
4085 * than 10Mbps w/o EEE.
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004086 **/
Bruce Allan99730e42011-05-13 07:19:48 +00004087void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004088{
Bruce Allan2fbe4522012-04-19 03:21:47 +00004089 struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004090 u32 phy_ctrl;
Bruce Allan8395ae82010-09-22 17:15:08 +00004091 s32 ret_val;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004092
Bruce Allan17f085d2010-06-17 18:59:48 +00004093 phy_ctrl = er32(PHY_CTRL);
Bruce Allanc077a902011-12-16 00:46:38 +00004094 phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004095 if (hw->phy.type == e1000_phy_i217) {
4096 u16 phy_reg;
4097
4098 ret_val = hw->phy.ops.acquire(hw);
4099 if (ret_val)
4100 goto out;
4101
4102 if (!dev_spec->eee_disable) {
4103 u16 eee_advert;
4104
Bruce Allan4ddc48a2012-12-05 06:25:58 +00004105 ret_val =
4106 e1000_read_emi_reg_locked(hw,
4107 I217_EEE_ADVERTISEMENT,
4108 &eee_advert);
Bruce Allan2fbe4522012-04-19 03:21:47 +00004109 if (ret_val)
4110 goto release;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004111
Bruce Allane921eb12012-11-28 09:28:37 +00004112 /* Disable LPLU if both link partners support 100BaseT
Bruce Allan2fbe4522012-04-19 03:21:47 +00004113 * EEE and 100Full is advertised on both ends of the
4114 * link.
4115 */
Bruce Allan3d4d5752012-12-05 06:26:08 +00004116 if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004117 (dev_spec->eee_lp_ability &
Bruce Allan3d4d5752012-12-05 06:26:08 +00004118 I82579_EEE_100_SUPPORTED) &&
Bruce Allan2fbe4522012-04-19 03:21:47 +00004119 (hw->phy.autoneg_advertised & ADVERTISE_100_FULL))
4120 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
4121 E1000_PHY_CTRL_NOND0A_LPLU);
4122 }
4123
Bruce Allane921eb12012-11-28 09:28:37 +00004124 /* For i217 Intel Rapid Start Technology support,
Bruce Allan2fbe4522012-04-19 03:21:47 +00004125 * when the system is going into Sx and no manageability engine
4126 * is present, the driver must configure proxy to reset only on
4127 * power good. LPI (Low Power Idle) state must also reset only
4128 * on power good, as well as the MTA (Multicast table array).
4129 * The SMBus release must also be disabled on LCD reset.
4130 */
4131 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
4132
4133 /* Enable proxy to reset only on power good. */
4134 e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
4135 phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
4136 e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
4137
Bruce Allane921eb12012-11-28 09:28:37 +00004138 /* Set bit enable LPI (EEE) to reset only on
Bruce Allan2fbe4522012-04-19 03:21:47 +00004139 * power good.
4140 */
4141 e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004142 phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004143 e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
4144
4145 /* Disable the SMB release on LCD reset. */
4146 e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004147 phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004148 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4149 }
4150
Bruce Allane921eb12012-11-28 09:28:37 +00004151 /* Enable MTA to reset for Intel Rapid Start Technology
Bruce Allan2fbe4522012-04-19 03:21:47 +00004152 * Support
4153 */
4154 e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
Bruce Allan6d7407b2012-05-10 02:51:17 +00004155 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004156 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4157
4158release:
4159 hw->phy.ops.release(hw);
4160 }
4161out:
Bruce Allan17f085d2010-06-17 18:59:48 +00004162 ew32(PHY_CTRL, phy_ctrl);
Bruce Allana4f58f52009-06-02 11:29:18 +00004163
Bruce Allan462d5992011-09-30 08:07:11 +00004164 if (hw->mac.type == e1000_ich8lan)
4165 e1000e_gig_downshift_workaround_ich8lan(hw);
4166
Bruce Allan8395ae82010-09-22 17:15:08 +00004167 if (hw->mac.type >= e1000_pchlan) {
Bruce Allance54afd2010-11-24 06:01:41 +00004168 e1000_oem_bits_config_ich8lan(hw, false);
Bruce Allan92fe1732012-04-12 06:27:03 +00004169
4170 /* Reset PHY to activate OEM bits on 82577/8 */
4171 if (hw->mac.type == e1000_pchlan)
4172 e1000e_phy_hw_reset_generic(hw);
4173
Bruce Allan8395ae82010-09-22 17:15:08 +00004174 ret_val = hw->phy.ops.acquire(hw);
4175 if (ret_val)
4176 return;
4177 e1000_write_smbus_addr(hw);
4178 hw->phy.ops.release(hw);
4179 }
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004180}
4181
4182/**
Bruce Allan99730e42011-05-13 07:19:48 +00004183 * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
4184 * @hw: pointer to the HW structure
4185 *
4186 * During Sx to S0 transitions on non-managed devices or managed devices
4187 * on which PHY resets are not blocked, if the PHY registers cannot be
4188 * accessed properly by the s/w toggle the LANPHYPC value to power cycle
4189 * the PHY.
Bruce Allan2fbe4522012-04-19 03:21:47 +00004190 * On i217, setup Intel Rapid Start Technology.
Bruce Allan99730e42011-05-13 07:19:48 +00004191 **/
4192void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
4193{
Bruce Allan90b82982011-12-16 00:46:33 +00004194 s32 ret_val;
Bruce Allan99730e42011-05-13 07:19:48 +00004195
Bruce Allancb17aab2012-04-13 03:16:22 +00004196 if (hw->mac.type < e1000_pch2lan)
Bruce Allan99730e42011-05-13 07:19:48 +00004197 return;
4198
Bruce Allancb17aab2012-04-13 03:16:22 +00004199 ret_val = e1000_init_phy_workarounds_pchlan(hw);
Bruce Allan90b82982011-12-16 00:46:33 +00004200 if (ret_val) {
Bruce Allancb17aab2012-04-13 03:16:22 +00004201 e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
Bruce Allan99730e42011-05-13 07:19:48 +00004202 return;
4203 }
Bruce Allan2fbe4522012-04-19 03:21:47 +00004204
Bruce Allane921eb12012-11-28 09:28:37 +00004205 /* For i217 Intel Rapid Start Technology support when the system
Bruce Allan2fbe4522012-04-19 03:21:47 +00004206 * is transitioning from Sx and no manageability engine is present
4207 * configure SMBus to restore on reset, disable proxy, and enable
4208 * the reset on MTA (Multicast table array).
4209 */
4210 if (hw->phy.type == e1000_phy_i217) {
4211 u16 phy_reg;
4212
4213 ret_val = hw->phy.ops.acquire(hw);
4214 if (ret_val) {
4215 e_dbg("Failed to setup iRST\n");
4216 return;
4217 }
4218
4219 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
Bruce Allane921eb12012-11-28 09:28:37 +00004220 /* Restore clear on SMB if no manageability engine
Bruce Allan2fbe4522012-04-19 03:21:47 +00004221 * is present
4222 */
4223 ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
4224 if (ret_val)
4225 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004226 phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004227 e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
4228
4229 /* Disable Proxy */
4230 e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
4231 }
4232 /* Enable reset on MTA */
4233 ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
4234 if (ret_val)
4235 goto release;
Bruce Allan6d7407b2012-05-10 02:51:17 +00004236 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
Bruce Allan2fbe4522012-04-19 03:21:47 +00004237 e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
4238release:
4239 if (ret_val)
4240 e_dbg("Error %d in resume workarounds\n", ret_val);
4241 hw->phy.ops.release(hw);
4242 }
Bruce Allan99730e42011-05-13 07:19:48 +00004243}
4244
4245/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004246 * e1000_cleanup_led_ich8lan - Restore the default LED operation
4247 * @hw: pointer to the HW structure
4248 *
4249 * Return the LED back to the default configuration.
4250 **/
4251static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
4252{
4253 if (hw->phy.type == e1000_phy_ife)
4254 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
4255
4256 ew32(LEDCTL, hw->mac.ledctl_default);
4257 return 0;
4258}
4259
4260/**
Auke Kok489815c2008-02-21 15:11:07 -08004261 * e1000_led_on_ich8lan - Turn LEDs on
Auke Kokbc7f75f2007-09-17 12:30:59 -07004262 * @hw: pointer to the HW structure
4263 *
Auke Kok489815c2008-02-21 15:11:07 -08004264 * Turn on the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004265 **/
4266static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
4267{
4268 if (hw->phy.type == e1000_phy_ife)
4269 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
4270 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
4271
4272 ew32(LEDCTL, hw->mac.ledctl_mode2);
4273 return 0;
4274}
4275
4276/**
Auke Kok489815c2008-02-21 15:11:07 -08004277 * e1000_led_off_ich8lan - Turn LEDs off
Auke Kokbc7f75f2007-09-17 12:30:59 -07004278 * @hw: pointer to the HW structure
4279 *
Auke Kok489815c2008-02-21 15:11:07 -08004280 * Turn off the LEDs.
Auke Kokbc7f75f2007-09-17 12:30:59 -07004281 **/
4282static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
4283{
4284 if (hw->phy.type == e1000_phy_ife)
4285 return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
Bruce Allan482fed82011-01-06 14:29:49 +00004286 (IFE_PSCL_PROBE_MODE |
4287 IFE_PSCL_PROBE_LEDS_OFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07004288
4289 ew32(LEDCTL, hw->mac.ledctl_mode1);
4290 return 0;
4291}
4292
4293/**
Bruce Allana4f58f52009-06-02 11:29:18 +00004294 * e1000_setup_led_pchlan - Configures SW controllable LED
4295 * @hw: pointer to the HW structure
4296 *
4297 * This prepares the SW controllable LED for use.
4298 **/
4299static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
4300{
Bruce Allan482fed82011-01-06 14:29:49 +00004301 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
Bruce Allana4f58f52009-06-02 11:29:18 +00004302}
4303
4304/**
4305 * e1000_cleanup_led_pchlan - Restore the default LED operation
4306 * @hw: pointer to the HW structure
4307 *
4308 * Return the LED back to the default configuration.
4309 **/
4310static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
4311{
Bruce Allan482fed82011-01-06 14:29:49 +00004312 return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
Bruce Allana4f58f52009-06-02 11:29:18 +00004313}
4314
4315/**
4316 * e1000_led_on_pchlan - Turn LEDs on
4317 * @hw: pointer to the HW structure
4318 *
4319 * Turn on the LEDs.
4320 **/
4321static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
4322{
4323 u16 data = (u16)hw->mac.ledctl_mode2;
4324 u32 i, led;
4325
Bruce Allane921eb12012-11-28 09:28:37 +00004326 /* If no link, then turn LED on by setting the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004327 * for each LED that's mode is "link_up" in ledctl_mode2.
4328 */
4329 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4330 for (i = 0; i < 3; i++) {
4331 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4332 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4333 E1000_LEDCTL_MODE_LINK_UP)
4334 continue;
4335 if (led & E1000_PHY_LED0_IVRT)
4336 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4337 else
4338 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4339 }
4340 }
4341
Bruce Allan482fed82011-01-06 14:29:49 +00004342 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004343}
4344
4345/**
4346 * e1000_led_off_pchlan - Turn LEDs off
4347 * @hw: pointer to the HW structure
4348 *
4349 * Turn off the LEDs.
4350 **/
4351static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
4352{
4353 u16 data = (u16)hw->mac.ledctl_mode1;
4354 u32 i, led;
4355
Bruce Allane921eb12012-11-28 09:28:37 +00004356 /* If no link, then turn LED off by clearing the invert bit
Bruce Allana4f58f52009-06-02 11:29:18 +00004357 * for each LED that's mode is "link_up" in ledctl_mode1.
4358 */
4359 if (!(er32(STATUS) & E1000_STATUS_LU)) {
4360 for (i = 0; i < 3; i++) {
4361 led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
4362 if ((led & E1000_PHY_LED0_MODE_MASK) !=
4363 E1000_LEDCTL_MODE_LINK_UP)
4364 continue;
4365 if (led & E1000_PHY_LED0_IVRT)
4366 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
4367 else
4368 data |= (E1000_PHY_LED0_IVRT << (i * 5));
4369 }
4370 }
4371
Bruce Allan482fed82011-01-06 14:29:49 +00004372 return e1e_wphy(hw, HV_LED_CONFIG, data);
Bruce Allana4f58f52009-06-02 11:29:18 +00004373}
4374
4375/**
Bruce Allane98cac42010-05-10 15:02:32 +00004376 * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
Bruce Allanf4187b52008-08-26 18:36:50 -07004377 * @hw: pointer to the HW structure
4378 *
Bruce Allane98cac42010-05-10 15:02:32 +00004379 * Read appropriate register for the config done bit for completion status
4380 * and configure the PHY through s/w for EEPROM-less parts.
4381 *
4382 * NOTE: some silicon which is EEPROM-less will fail trying to read the
4383 * config done bit, so only an error is logged and continues. If we were
4384 * to return with error, EEPROM-less silicon would not be able to be reset
4385 * or change link.
Bruce Allanf4187b52008-08-26 18:36:50 -07004386 **/
4387static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
4388{
Bruce Allane98cac42010-05-10 15:02:32 +00004389 s32 ret_val = 0;
Bruce Allanf4187b52008-08-26 18:36:50 -07004390 u32 bank = 0;
Bruce Allane98cac42010-05-10 15:02:32 +00004391 u32 status;
Bruce Allanfc0c7762009-07-01 13:27:55 +00004392
Bruce Allanf4187b52008-08-26 18:36:50 -07004393 e1000e_get_cfg_done(hw);
4394
Bruce Allane98cac42010-05-10 15:02:32 +00004395 /* Wait for indication from h/w that it has completed basic config */
4396 if (hw->mac.type >= e1000_ich10lan) {
4397 e1000_lan_init_done_ich8lan(hw);
4398 } else {
4399 ret_val = e1000e_get_auto_rd_done(hw);
4400 if (ret_val) {
Bruce Allane921eb12012-11-28 09:28:37 +00004401 /* When auto config read does not complete, do not
Bruce Allane98cac42010-05-10 15:02:32 +00004402 * return with an error. This can happen in situations
4403 * where there is no eeprom and prevents getting link.
4404 */
4405 e_dbg("Auto Read Done did not complete\n");
4406 ret_val = 0;
4407 }
4408 }
4409
4410 /* Clear PHY Reset Asserted bit */
4411 status = er32(STATUS);
4412 if (status & E1000_STATUS_PHYRA)
4413 ew32(STATUS, status & ~E1000_STATUS_PHYRA);
4414 else
4415 e_dbg("PHY Reset Asserted not set - needs delay\n");
4416
Bruce Allanf4187b52008-08-26 18:36:50 -07004417 /* If EEPROM is not marked present, init the IGP 3 PHY manually */
Bruce Allane98cac42010-05-10 15:02:32 +00004418 if (hw->mac.type <= e1000_ich9lan) {
Bruce Allan04499ec2012-04-13 00:08:31 +00004419 if (!(er32(EECD) & E1000_EECD_PRES) &&
Bruce Allanf4187b52008-08-26 18:36:50 -07004420 (hw->phy.type == e1000_phy_igp_3)) {
4421 e1000e_phy_init_script_igp3(hw);
4422 }
4423 } else {
4424 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
4425 /* Maybe we should do a basic PHY config */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00004426 e_dbg("EEPROM not present\n");
Bruce Allane98cac42010-05-10 15:02:32 +00004427 ret_val = -E1000_ERR_CONFIG;
Bruce Allanf4187b52008-08-26 18:36:50 -07004428 }
4429 }
4430
Bruce Allane98cac42010-05-10 15:02:32 +00004431 return ret_val;
Bruce Allanf4187b52008-08-26 18:36:50 -07004432}
4433
4434/**
Bruce Allan17f208d2009-12-01 15:47:22 +00004435 * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
4436 * @hw: pointer to the HW structure
4437 *
4438 * In the case of a PHY power down to save power, or to turn off link during a
4439 * driver unload, or wake on lan is not enabled, remove the link.
4440 **/
4441static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
4442{
4443 /* If the management interface is not enabled, then power down */
4444 if (!(hw->mac.ops.check_mng_mode(hw) ||
4445 hw->phy.ops.check_reset_block(hw)))
4446 e1000_power_down_phy_copper(hw);
Bruce Allan17f208d2009-12-01 15:47:22 +00004447}
4448
4449/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07004450 * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
4451 * @hw: pointer to the HW structure
4452 *
4453 * Clears hardware counters specific to the silicon family and calls
4454 * clear_hw_cntrs_generic to clear all general purpose counters.
4455 **/
4456static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
4457{
Bruce Allana4f58f52009-06-02 11:29:18 +00004458 u16 phy_data;
Bruce Allan2b6b1682011-05-13 07:20:09 +00004459 s32 ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07004460
4461 e1000e_clear_hw_cntrs_base(hw);
4462
Bruce Allan99673d92009-11-20 23:27:21 +00004463 er32(ALGNERRC);
4464 er32(RXERRC);
4465 er32(TNCRS);
4466 er32(CEXTERR);
4467 er32(TSCTC);
4468 er32(TSCTFC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004469
Bruce Allan99673d92009-11-20 23:27:21 +00004470 er32(MGTPRC);
4471 er32(MGTPDC);
4472 er32(MGTPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004473
Bruce Allan99673d92009-11-20 23:27:21 +00004474 er32(IAC);
4475 er32(ICRXOC);
Auke Kokbc7f75f2007-09-17 12:30:59 -07004476
Bruce Allana4f58f52009-06-02 11:29:18 +00004477 /* Clear PHY statistics registers */
4478 if ((hw->phy.type == e1000_phy_82578) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00004479 (hw->phy.type == e1000_phy_82579) ||
Bruce Allan2fbe4522012-04-19 03:21:47 +00004480 (hw->phy.type == e1000_phy_i217) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00004481 (hw->phy.type == e1000_phy_82577)) {
Bruce Allan2b6b1682011-05-13 07:20:09 +00004482 ret_val = hw->phy.ops.acquire(hw);
4483 if (ret_val)
4484 return;
4485 ret_val = hw->phy.ops.set_page(hw,
4486 HV_STATS_PAGE << IGP_PAGE_SHIFT);
4487 if (ret_val)
4488 goto release;
4489 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
4490 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
4491 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
4492 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
4493 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
4494 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
4495 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
4496 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
4497 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
4498 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
4499 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
4500 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
4501 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
4502 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
4503release:
4504 hw->phy.ops.release(hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00004505 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07004506}
4507
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004508static const struct e1000_mac_operations ich8_mac_ops = {
Bruce Allaneb7700d2010-06-16 13:27:05 +00004509 /* check_mng_mode dependent on mac type */
Bruce Allan7d3cabb2009-07-01 13:29:08 +00004510 .check_for_link = e1000_check_for_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004511 /* cleanup_led dependent on mac type */
Auke Kokbc7f75f2007-09-17 12:30:59 -07004512 .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
4513 .get_bus_info = e1000_get_bus_info_ich8lan,
Bruce Allanf4d2dd42010-01-13 02:05:18 +00004514 .set_lan_id = e1000_set_lan_id_single_port,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004515 .get_link_up_info = e1000_get_link_up_info_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004516 /* led_on dependent on mac type */
4517 /* led_off dependent on mac type */
Jeff Kirshere2de3eb2008-03-28 09:15:11 -07004518 .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004519 .reset_hw = e1000_reset_hw_ich8lan,
4520 .init_hw = e1000_init_hw_ich8lan,
4521 .setup_link = e1000_setup_link_ich8lan,
4522 .setup_physical_interface= e1000_setup_copper_link_ich8lan,
Bruce Allana4f58f52009-06-02 11:29:18 +00004523 /* id_led_init dependent on mac type */
Bruce Allan57cde762012-02-22 09:02:58 +00004524 .config_collision_dist = e1000e_config_collision_dist_generic,
Bruce Allan69e1e012012-04-14 03:28:50 +00004525 .rar_set = e1000e_rar_set_generic,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004526};
4527
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004528static const struct e1000_phy_operations ich8_phy_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004529 .acquire = e1000_acquire_swflag_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004530 .check_reset_block = e1000_check_reset_block_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004531 .commit = NULL,
Bruce Allanf4187b52008-08-26 18:36:50 -07004532 .get_cfg_done = e1000_get_cfg_done_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004533 .get_cable_length = e1000e_get_cable_length_igp_2,
Bruce Allan94d81862009-11-20 23:25:26 +00004534 .read_reg = e1000e_read_phy_reg_igp,
4535 .release = e1000_release_swflag_ich8lan,
4536 .reset = e1000_phy_hw_reset_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004537 .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
4538 .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004539 .write_reg = e1000e_write_phy_reg_igp,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004540};
4541
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004542static const struct e1000_nvm_operations ich8_nvm_ops = {
Bruce Allan94d81862009-11-20 23:25:26 +00004543 .acquire = e1000_acquire_nvm_ich8lan,
4544 .read = e1000_read_nvm_ich8lan,
4545 .release = e1000_release_nvm_ich8lan,
Bruce Allane85e3632012-02-22 09:03:14 +00004546 .reload = e1000e_reload_nvm_generic,
Bruce Allan94d81862009-11-20 23:25:26 +00004547 .update = e1000_update_nvm_checksum_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004548 .valid_led_default = e1000_valid_led_default_ich8lan,
Bruce Allan94d81862009-11-20 23:25:26 +00004549 .validate = e1000_validate_nvm_checksum_ich8lan,
4550 .write = e1000_write_nvm_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004551};
4552
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004553const struct e1000_info e1000_ich8_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004554 .mac = e1000_ich8lan,
4555 .flags = FLAG_HAS_WOL
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004556 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004557 | FLAG_HAS_CTRLEXT_ON_LOAD
4558 | FLAG_HAS_AMT
4559 | FLAG_HAS_FLASH
4560 | FLAG_APME_IN_WUC,
4561 .pba = 8,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004562 .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004563 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004564 .mac_ops = &ich8_mac_ops,
4565 .phy_ops = &ich8_phy_ops,
4566 .nvm_ops = &ich8_nvm_ops,
4567};
4568
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004569const struct e1000_info e1000_ich9_info = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07004570 .mac = e1000_ich9lan,
4571 .flags = FLAG_HAS_JUMBO_FRAMES
Bruce Allan97ac8ca2008-04-29 09:16:05 -07004572 | FLAG_IS_ICH
Auke Kokbc7f75f2007-09-17 12:30:59 -07004573 | FLAG_HAS_WOL
Auke Kokbc7f75f2007-09-17 12:30:59 -07004574 | FLAG_HAS_CTRLEXT_ON_LOAD
4575 | FLAG_HAS_AMT
Auke Kokbc7f75f2007-09-17 12:30:59 -07004576 | FLAG_HAS_FLASH
4577 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004578 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004579 .max_hw_frame_size = DEFAULT_JUMBO,
Jeff Kirsher69e3fd82008-04-02 13:48:18 -07004580 .get_variants = e1000_get_variants_ich8lan,
Auke Kokbc7f75f2007-09-17 12:30:59 -07004581 .mac_ops = &ich8_mac_ops,
4582 .phy_ops = &ich8_phy_ops,
4583 .nvm_ops = &ich8_nvm_ops,
4584};
4585
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004586const struct e1000_info e1000_ich10_info = {
Bruce Allanf4187b52008-08-26 18:36:50 -07004587 .mac = e1000_ich10lan,
4588 .flags = FLAG_HAS_JUMBO_FRAMES
4589 | FLAG_IS_ICH
4590 | FLAG_HAS_WOL
Bruce Allanf4187b52008-08-26 18:36:50 -07004591 | FLAG_HAS_CTRLEXT_ON_LOAD
4592 | FLAG_HAS_AMT
Bruce Allanf4187b52008-08-26 18:36:50 -07004593 | FLAG_HAS_FLASH
4594 | FLAG_APME_IN_WUC,
Bruce Allan7f1557e2011-12-16 00:46:43 +00004595 .pba = 18,
Bruce Allan2adc55c2009-06-02 11:28:58 +00004596 .max_hw_frame_size = DEFAULT_JUMBO,
Bruce Allanf4187b52008-08-26 18:36:50 -07004597 .get_variants = e1000_get_variants_ich8lan,
4598 .mac_ops = &ich8_mac_ops,
4599 .phy_ops = &ich8_phy_ops,
4600 .nvm_ops = &ich8_nvm_ops,
4601};
Bruce Allana4f58f52009-06-02 11:29:18 +00004602
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004603const struct e1000_info e1000_pch_info = {
Bruce Allana4f58f52009-06-02 11:29:18 +00004604 .mac = e1000_pchlan,
4605 .flags = FLAG_IS_ICH
4606 | FLAG_HAS_WOL
Bruce Allana4f58f52009-06-02 11:29:18 +00004607 | FLAG_HAS_CTRLEXT_ON_LOAD
4608 | FLAG_HAS_AMT
4609 | FLAG_HAS_FLASH
4610 | FLAG_HAS_JUMBO_FRAMES
Bruce Allan38eb3942009-11-19 12:34:20 +00004611 | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
Bruce Allana4f58f52009-06-02 11:29:18 +00004612 | FLAG_APME_IN_WUC,
Bruce Allan8c7bbb92010-06-16 13:26:41 +00004613 .flags2 = FLAG2_HAS_PHY_STATS,
Bruce Allana4f58f52009-06-02 11:29:18 +00004614 .pba = 26,
4615 .max_hw_frame_size = 4096,
4616 .get_variants = e1000_get_variants_ich8lan,
4617 .mac_ops = &ich8_mac_ops,
4618 .phy_ops = &ich8_phy_ops,
4619 .nvm_ops = &ich8_nvm_ops,
4620};
Bruce Alland3738bb2010-06-16 13:27:28 +00004621
Jeff Kirsher8ce9d6c2011-09-24 13:23:52 +00004622const struct e1000_info e1000_pch2_info = {
Bruce Alland3738bb2010-06-16 13:27:28 +00004623 .mac = e1000_pch2lan,
4624 .flags = FLAG_IS_ICH
4625 | FLAG_HAS_WOL
Bruce Alland3738bb2010-06-16 13:27:28 +00004626 | FLAG_HAS_CTRLEXT_ON_LOAD
4627 | FLAG_HAS_AMT
4628 | FLAG_HAS_FLASH
4629 | FLAG_HAS_JUMBO_FRAMES
4630 | FLAG_APME_IN_WUC,
Bruce Allane52997f2010-06-16 13:27:49 +00004631 .flags2 = FLAG2_HAS_PHY_STATS
4632 | FLAG2_HAS_EEE,
Bruce Allan828bac82010-09-29 21:39:37 +00004633 .pba = 26,
Bruce Alland3738bb2010-06-16 13:27:28 +00004634 .max_hw_frame_size = DEFAULT_JUMBO,
4635 .get_variants = e1000_get_variants_ich8lan,
4636 .mac_ops = &ich8_mac_ops,
4637 .phy_ops = &ich8_phy_ops,
4638 .nvm_ops = &ich8_nvm_ops,
4639};
Bruce Allan2fbe4522012-04-19 03:21:47 +00004640
4641const struct e1000_info e1000_pch_lpt_info = {
4642 .mac = e1000_pch_lpt,
4643 .flags = FLAG_IS_ICH
4644 | FLAG_HAS_WOL
4645 | FLAG_HAS_CTRLEXT_ON_LOAD
4646 | FLAG_HAS_AMT
4647 | FLAG_HAS_FLASH
4648 | FLAG_HAS_JUMBO_FRAMES
4649 | FLAG_APME_IN_WUC,
4650 .flags2 = FLAG2_HAS_PHY_STATS
4651 | FLAG2_HAS_EEE,
4652 .pba = 26,
4653 .max_hw_frame_size = DEFAULT_JUMBO,
4654 .get_variants = e1000_get_variants_ich8lan,
4655 .mac_ops = &ich8_mac_ops,
4656 .phy_ops = &ich8_phy_ops,
4657 .nvm_ops = &ich8_nvm_ops,
4658};