e1000_ich8lan.c revision 205869
1177867Sjfv/******************************************************************************
2169240Sjfv
3203049Sjfv  Copyright (c) 2001-2010, Intel Corporation
4169240Sjfv  All rights reserved.
5169240Sjfv
6169240Sjfv  Redistribution and use in source and binary forms, with or without
7169240Sjfv  modification, are permitted provided that the following conditions are met:
8169240Sjfv
9169240Sjfv   1. Redistributions of source code must retain the above copyright notice,
10169240Sjfv      this list of conditions and the following disclaimer.
11169240Sjfv
12169240Sjfv   2. Redistributions in binary form must reproduce the above copyright
13169240Sjfv      notice, this list of conditions and the following disclaimer in the
14169240Sjfv      documentation and/or other materials provided with the distribution.
15169240Sjfv
16169240Sjfv   3. Neither the name of the Intel Corporation nor the names of its
17169240Sjfv      contributors may be used to endorse or promote products derived from
18169240Sjfv      this software without specific prior written permission.
19169240Sjfv
20169240Sjfv  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21169240Sjfv  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22169240Sjfv  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23169240Sjfv  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24169240Sjfv  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25169240Sjfv  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26169240Sjfv  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27169240Sjfv  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28169240Sjfv  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29169240Sjfv  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30169240Sjfv  POSSIBILITY OF SUCH DAMAGE.
31169240Sjfv
32177867Sjfv******************************************************************************/
33177867Sjfv/*$FreeBSD: head/sys/dev/e1000/e1000_ich8lan.c 205869 2010-03-29 23:36:34Z jfv $*/
34169240Sjfv
35185353Sjfv/*
36185353Sjfv * 82562G 10/100 Network Connection
37185353Sjfv * 82562G-2 10/100 Network Connection
38185353Sjfv * 82562GT 10/100 Network Connection
39185353Sjfv * 82562GT-2 10/100 Network Connection
40185353Sjfv * 82562V 10/100 Network Connection
41185353Sjfv * 82562V-2 10/100 Network Connection
42185353Sjfv * 82566DC-2 Gigabit Network Connection
43185353Sjfv * 82566DC Gigabit Network Connection
44185353Sjfv * 82566DM-2 Gigabit Network Connection
45185353Sjfv * 82566DM Gigabit Network Connection
46185353Sjfv * 82566MC Gigabit Network Connection
47185353Sjfv * 82566MM Gigabit Network Connection
48185353Sjfv * 82567LM Gigabit Network Connection
49185353Sjfv * 82567LF Gigabit Network Connection
50185353Sjfv * 82567V Gigabit Network Connection
51185353Sjfv * 82567LM-2 Gigabit Network Connection
52185353Sjfv * 82567LF-2 Gigabit Network Connection
53185353Sjfv * 82567V-2 Gigabit Network Connection
54185353Sjfv * 82567LF-3 Gigabit Network Connection
55185353Sjfv * 82567LM-3 Gigabit Network Connection
56185353Sjfv * 82567LM-4 Gigabit Network Connection
57194865Sjfv * 82577LM Gigabit Network Connection
58194865Sjfv * 82577LC Gigabit Network Connection
59194865Sjfv * 82578DM Gigabit Network Connection
60194865Sjfv * 82578DC Gigabit Network Connection
61169240Sjfv */
62169240Sjfv
63169589Sjfv#include "e1000_api.h"
64169240Sjfv
65177867Sjfvstatic s32  e1000_init_phy_params_ich8lan(struct e1000_hw *hw);
66194865Sjfvstatic s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw);
67177867Sjfvstatic s32  e1000_init_nvm_params_ich8lan(struct e1000_hw *hw);
68177867Sjfvstatic s32  e1000_init_mac_params_ich8lan(struct e1000_hw *hw);
69177867Sjfvstatic s32  e1000_acquire_swflag_ich8lan(struct e1000_hw *hw);
70177867Sjfvstatic void e1000_release_swflag_ich8lan(struct e1000_hw *hw);
71200243Sjfvstatic s32  e1000_acquire_nvm_ich8lan(struct e1000_hw *hw);
72200243Sjfvstatic void e1000_release_nvm_ich8lan(struct e1000_hw *hw);
73177867Sjfvstatic bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
74177867Sjfvstatic s32  e1000_check_reset_block_ich8lan(struct e1000_hw *hw);
75177867Sjfvstatic s32  e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw);
76200243Sjfvstatic s32  e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
77177867Sjfvstatic s32  e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw,
78173788Sjfv                                            bool active);
79177867Sjfvstatic s32  e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw,
80173788Sjfv                                            bool active);
81177867Sjfvstatic s32  e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset,
82173788Sjfv                                   u16 words, u16 *data);
83177867Sjfvstatic s32  e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset,
84173788Sjfv                                    u16 words, u16 *data);
85177867Sjfvstatic s32  e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw);
86177867Sjfvstatic s32  e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw);
87177867Sjfvstatic s32  e1000_valid_led_default_ich8lan(struct e1000_hw *hw,
88173788Sjfv                                            u16 *data);
89194865Sjfvstatic s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
90177867Sjfvstatic s32  e1000_get_bus_info_ich8lan(struct e1000_hw *hw);
91177867Sjfvstatic s32  e1000_reset_hw_ich8lan(struct e1000_hw *hw);
92177867Sjfvstatic s32  e1000_init_hw_ich8lan(struct e1000_hw *hw);
93177867Sjfvstatic s32  e1000_setup_link_ich8lan(struct e1000_hw *hw);
94177867Sjfvstatic s32  e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
95177867Sjfvstatic s32  e1000_get_link_up_info_ich8lan(struct e1000_hw *hw,
96173788Sjfv                                           u16 *speed, u16 *duplex);
97177867Sjfvstatic s32  e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
98177867Sjfvstatic s32  e1000_led_on_ich8lan(struct e1000_hw *hw);
99177867Sjfvstatic s32  e1000_led_off_ich8lan(struct e1000_hw *hw);
100200243Sjfvstatic s32  e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
101194865Sjfvstatic s32  e1000_setup_led_pchlan(struct e1000_hw *hw);
102194865Sjfvstatic s32  e1000_cleanup_led_pchlan(struct e1000_hw *hw);
103194865Sjfvstatic s32  e1000_led_on_pchlan(struct e1000_hw *hw);
104194865Sjfvstatic s32  e1000_led_off_pchlan(struct e1000_hw *hw);
105177867Sjfvstatic void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
106177867Sjfvstatic s32  e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
107173788Sjfvstatic s32  e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout);
108173788Sjfvstatic s32  e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw);
109173788Sjfvstatic void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
110173788Sjfvstatic s32  e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
111178523Sjfvstatic s32  e1000_read_flash_byte_ich8lan(struct e1000_hw *hw,
112185353Sjfv                                          u32 offset, u8 *data);
113173788Sjfvstatic s32  e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
114185353Sjfv                                          u8 size, u16 *data);
115177867Sjfvstatic s32  e1000_read_flash_word_ich8lan(struct e1000_hw *hw,
116173788Sjfv                                          u32 offset, u16 *data);
117173788Sjfvstatic s32  e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
118173788Sjfv                                                 u32 offset, u8 byte);
119177867Sjfvstatic s32  e1000_write_flash_byte_ich8lan(struct e1000_hw *hw,
120173788Sjfv                                           u32 offset, u8 data);
121173788Sjfvstatic s32  e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
122173788Sjfv                                           u8 size, u16 data);
123177867Sjfvstatic s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
124177867Sjfvstatic void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
125200243Sjfvstatic s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw);
126200243Sjfvstatic void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
127200243Sjfvstatic s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw);
128203049Sjfvstatic s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
129169240Sjfv
130169240Sjfv/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
131169240Sjfv/* Offset 04h HSFSTS */
132169240Sjfvunion ich8_hws_flash_status {
133169240Sjfv	struct ich8_hsfsts {
134169240Sjfv		u16 flcdone    :1; /* bit 0 Flash Cycle Done */
135169240Sjfv		u16 flcerr     :1; /* bit 1 Flash Cycle Error */
136169240Sjfv		u16 dael       :1; /* bit 2 Direct Access error Log */
137169240Sjfv		u16 berasesz   :2; /* bit 4:3 Sector Erase Size */
138169240Sjfv		u16 flcinprog  :1; /* bit 5 flash cycle in Progress */
139169240Sjfv		u16 reserved1  :2; /* bit 13:6 Reserved */
140169240Sjfv		u16 reserved2  :6; /* bit 13:6 Reserved */
141169240Sjfv		u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
142169240Sjfv		u16 flockdn    :1; /* bit 15 Flash Config Lock-Down */
143169240Sjfv	} hsf_status;
144169240Sjfv	u16 regval;
145169240Sjfv};
146169240Sjfv
147169240Sjfv/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
148169240Sjfv/* Offset 06h FLCTL */
149169240Sjfvunion ich8_hws_flash_ctrl {
150169240Sjfv	struct ich8_hsflctl {
151169240Sjfv		u16 flcgo      :1;   /* 0 Flash Cycle Go */
152169240Sjfv		u16 flcycle    :2;   /* 2:1 Flash Cycle */
153169240Sjfv		u16 reserved   :5;   /* 7:3 Reserved  */
154169240Sjfv		u16 fldbcount  :2;   /* 9:8 Flash Data Byte Count */
155169240Sjfv		u16 flockdn    :6;   /* 15:10 Reserved */
156169240Sjfv	} hsf_ctrl;
157169240Sjfv	u16 regval;
158169240Sjfv};
159169240Sjfv
160169240Sjfv/* ICH Flash Region Access Permissions */
161169240Sjfvunion ich8_hws_flash_regacc {
162169240Sjfv	struct ich8_flracc {
163169240Sjfv		u32 grra      :8; /* 0:7 GbE region Read Access */
164169240Sjfv		u32 grwa      :8; /* 8:15 GbE region Write Access */
165169240Sjfv		u32 gmrag     :8; /* 23:16 GbE Master Read Access Grant */
166169240Sjfv		u32 gmwag     :8; /* 31:24 GbE Master Write Access Grant */
167169240Sjfv	} hsf_flregacc;
168169240Sjfv	u16 regval;
169169240Sjfv};
170169240Sjfv
171169240Sjfv/**
172194865Sjfv *  e1000_init_phy_params_pchlan - Initialize PHY function pointers
173194865Sjfv *  @hw: pointer to the HW structure
174194865Sjfv *
175194865Sjfv *  Initialize family-specific PHY parameters and function pointers.
176194865Sjfv **/
177194865Sjfvstatic s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
178194865Sjfv{
179194865Sjfv	struct e1000_phy_info *phy = &hw->phy;
180205869Sjfv	u32 ctrl;
181194865Sjfv	s32 ret_val = E1000_SUCCESS;
182194865Sjfv
183194865Sjfv	DEBUGFUNC("e1000_init_phy_params_pchlan");
184194865Sjfv
185194865Sjfv	phy->addr                     = 1;
186194865Sjfv	phy->reset_delay_us           = 100;
187194865Sjfv
188194865Sjfv	phy->ops.acquire              = e1000_acquire_swflag_ich8lan;
189194865Sjfv	phy->ops.check_reset_block    = e1000_check_reset_block_ich8lan;
190194865Sjfv	phy->ops.get_cfg_done         = e1000_get_cfg_done_ich8lan;
191194865Sjfv	phy->ops.read_reg             = e1000_read_phy_reg_hv;
192200243Sjfv	phy->ops.read_reg_locked      = e1000_read_phy_reg_hv_locked;
193194865Sjfv	phy->ops.release              = e1000_release_swflag_ich8lan;
194194865Sjfv	phy->ops.reset                = e1000_phy_hw_reset_ich8lan;
195200243Sjfv	phy->ops.set_d0_lplu_state    = e1000_set_lplu_state_pchlan;
196200243Sjfv	phy->ops.set_d3_lplu_state    = e1000_set_lplu_state_pchlan;
197194865Sjfv	phy->ops.write_reg            = e1000_write_phy_reg_hv;
198200243Sjfv	phy->ops.write_reg_locked     = e1000_write_phy_reg_hv_locked;
199194865Sjfv	phy->ops.power_up             = e1000_power_up_phy_copper;
200194865Sjfv	phy->ops.power_down           = e1000_power_down_phy_copper_ich8lan;
201194865Sjfv	phy->autoneg_mask             = AUTONEG_ADVERTISE_SPEED_DEFAULT;
202194865Sjfv
203205869Sjfv	if ((hw->mac.type == e1000_pchlan) &&
204205869Sjfv	    (!(E1000_READ_REG(hw, E1000_FWSM) & E1000_ICH_FWSM_FW_VALID))) {
205205869Sjfv
206205869Sjfv		/*
207205869Sjfv		 * The MAC-PHY interconnect may still be in SMBus mode
208205869Sjfv		 * after Sx->S0.  Toggle the LANPHYPC Value bit to force
209205869Sjfv		 * the interconnect to PCIe mode, but only if there is no
210205869Sjfv		 * firmware present otherwise firmware will have done it.
211205869Sjfv		 */
212205869Sjfv		ctrl = E1000_READ_REG(hw, E1000_CTRL);
213205869Sjfv		ctrl |=  E1000_CTRL_LANPHYPC_OVERRIDE;
214205869Sjfv		ctrl &= ~E1000_CTRL_LANPHYPC_VALUE;
215205869Sjfv		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
216205869Sjfv		usec_delay(10);
217205869Sjfv		ctrl &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
218205869Sjfv		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
219205869Sjfv		msec_delay(50);
220205869Sjfv	}
221205869Sjfv
222205869Sjfv	/*
223205869Sjfv	 * Reset the PHY before any acccess to it.  Doing so, ensures that
224205869Sjfv	 * the PHY is in a known good state before we read/write PHY registers.
225205869Sjfv	 * The generic reset is sufficient here, because we haven't determined
226205869Sjfv	 * the PHY type yet.
227205869Sjfv	 */
228205869Sjfv	ret_val = e1000_phy_hw_reset_generic(hw);
229205869Sjfv	if (ret_val)
230205869Sjfv		goto out;
231205869Sjfv
232194865Sjfv	phy->id = e1000_phy_unknown;
233203049Sjfv	ret_val = e1000_get_phy_id(hw);
234203049Sjfv	if (ret_val)
235203049Sjfv		goto out;
236203049Sjfv	if ((phy->id == 0) || (phy->id == PHY_REVISION_MASK)) {
237203049Sjfv		/*
238203049Sjfv		 * In case the PHY needs to be in mdio slow mode (eg. 82577),
239203049Sjfv		 * set slow mode and try to get the PHY id again.
240203049Sjfv		 */
241203049Sjfv		ret_val = e1000_set_mdio_slow_mode_hv(hw);
242203049Sjfv		if (ret_val)
243203049Sjfv			goto out;
244203049Sjfv		ret_val = e1000_get_phy_id(hw);
245203049Sjfv		if (ret_val)
246203049Sjfv			goto out;
247203049Sjfv	}
248194865Sjfv	phy->type = e1000_get_phy_type_from_id(phy->id);
249194865Sjfv
250200243Sjfv	switch (phy->type) {
251200243Sjfv	case e1000_phy_82577:
252194865Sjfv		phy->ops.check_polarity = e1000_check_polarity_82577;
253194865Sjfv		phy->ops.force_speed_duplex =
254194865Sjfv			e1000_phy_force_speed_duplex_82577;
255200243Sjfv		phy->ops.get_cable_length = e1000_get_cable_length_82577;
256194865Sjfv		phy->ops.get_info = e1000_get_phy_info_82577;
257194865Sjfv		phy->ops.commit = e1000_phy_sw_reset_generic;
258205869Sjfv		break;
259200243Sjfv	case e1000_phy_82578:
260200243Sjfv		phy->ops.check_polarity = e1000_check_polarity_m88;
261200243Sjfv		phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
262200243Sjfv		phy->ops.get_cable_length = e1000_get_cable_length_m88;
263200243Sjfv		phy->ops.get_info = e1000_get_phy_info_m88;
264200243Sjfv		break;
265200243Sjfv	default:
266200243Sjfv		ret_val = -E1000_ERR_PHY;
267200243Sjfv		break;
268194865Sjfv	}
269194865Sjfv
270203049Sjfvout:
271194865Sjfv	return ret_val;
272194865Sjfv}
273194865Sjfv
274194865Sjfv/**
275169240Sjfv *  e1000_init_phy_params_ich8lan - Initialize PHY function pointers
276169589Sjfv *  @hw: pointer to the HW structure
277169240Sjfv *
278169240Sjfv *  Initialize family-specific PHY parameters and function pointers.
279169240Sjfv **/
280177867Sjfvstatic s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
281169240Sjfv{
282169240Sjfv	struct e1000_phy_info *phy = &hw->phy;
283169240Sjfv	s32 ret_val = E1000_SUCCESS;
284169589Sjfv	u16 i = 0;
285169240Sjfv
286169240Sjfv	DEBUGFUNC("e1000_init_phy_params_ich8lan");
287169240Sjfv
288177867Sjfv	phy->addr                     = 1;
289177867Sjfv	phy->reset_delay_us           = 100;
290169240Sjfv
291177867Sjfv	phy->ops.acquire              = e1000_acquire_swflag_ich8lan;
292177867Sjfv	phy->ops.check_reset_block    = e1000_check_reset_block_ich8lan;
293177867Sjfv	phy->ops.get_cable_length     = e1000_get_cable_length_igp_2;
294177867Sjfv	phy->ops.get_cfg_done         = e1000_get_cfg_done_ich8lan;
295177867Sjfv	phy->ops.read_reg             = e1000_read_phy_reg_igp;
296177867Sjfv	phy->ops.release              = e1000_release_swflag_ich8lan;
297177867Sjfv	phy->ops.reset                = e1000_phy_hw_reset_ich8lan;
298177867Sjfv	phy->ops.set_d0_lplu_state    = e1000_set_d0_lplu_state_ich8lan;
299177867Sjfv	phy->ops.set_d3_lplu_state    = e1000_set_d3_lplu_state_ich8lan;
300177867Sjfv	phy->ops.write_reg            = e1000_write_phy_reg_igp;
301177867Sjfv	phy->ops.power_up             = e1000_power_up_phy_copper;
302177867Sjfv	phy->ops.power_down           = e1000_power_down_phy_copper_ich8lan;
303169240Sjfv
304176667Sjfv	/*
305176667Sjfv	 * We may need to do this twice - once for IGP and if that fails,
306176667Sjfv	 * we'll set BM func pointers and try again
307176667Sjfv	 */
308176667Sjfv	ret_val = e1000_determine_phy_address(hw);
309176667Sjfv	if (ret_val) {
310177867Sjfv		phy->ops.write_reg = e1000_write_phy_reg_bm;
311177867Sjfv		phy->ops.read_reg  = e1000_read_phy_reg_bm;
312176667Sjfv		ret_val = e1000_determine_phy_address(hw);
313176667Sjfv		if (ret_val) {
314190872Sjfv			DEBUGOUT("Cannot determine PHY addr. Erroring out\n");
315176667Sjfv			goto out;
316176667Sjfv		}
317176667Sjfv	}
318169240Sjfv
319169589Sjfv	phy->id = 0;
320169589Sjfv	while ((e1000_phy_unknown == e1000_get_phy_type_from_id(phy->id)) &&
321169589Sjfv	       (i++ < 100)) {
322169589Sjfv		msec_delay(1);
323169589Sjfv		ret_val = e1000_get_phy_id(hw);
324169589Sjfv		if (ret_val)
325169589Sjfv			goto out;
326169589Sjfv	}
327169589Sjfv
328169240Sjfv	/* Verify phy id */
329169240Sjfv	switch (phy->id) {
330169240Sjfv	case IGP03E1000_E_PHY_ID:
331169240Sjfv		phy->type = e1000_phy_igp_3;
332169240Sjfv		phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
333200243Sjfv		phy->ops.read_reg_locked = e1000_read_phy_reg_igp_locked;
334200243Sjfv		phy->ops.write_reg_locked = e1000_write_phy_reg_igp_locked;
335200243Sjfv		phy->ops.get_info = e1000_get_phy_info_igp;
336200243Sjfv		phy->ops.check_polarity = e1000_check_polarity_igp;
337200243Sjfv		phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_igp;
338169240Sjfv		break;
339169240Sjfv	case IFE_E_PHY_ID:
340169240Sjfv	case IFE_PLUS_E_PHY_ID:
341169240Sjfv	case IFE_C_E_PHY_ID:
342169240Sjfv		phy->type = e1000_phy_ife;
343169240Sjfv		phy->autoneg_mask = E1000_ALL_NOT_GIG;
344200243Sjfv		phy->ops.get_info = e1000_get_phy_info_ife;
345200243Sjfv		phy->ops.check_polarity = e1000_check_polarity_ife;
346200243Sjfv		phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
347169240Sjfv		break;
348176667Sjfv	case BME1000_E_PHY_ID:
349176667Sjfv		phy->type = e1000_phy_bm;
350176667Sjfv		phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
351177867Sjfv		phy->ops.read_reg = e1000_read_phy_reg_bm;
352177867Sjfv		phy->ops.write_reg = e1000_write_phy_reg_bm;
353177867Sjfv		phy->ops.commit = e1000_phy_sw_reset_generic;
354200243Sjfv		phy->ops.get_info = e1000_get_phy_info_m88;
355200243Sjfv		phy->ops.check_polarity = e1000_check_polarity_m88;
356200243Sjfv		phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
357176667Sjfv		break;
358169240Sjfv	default:
359169240Sjfv		ret_val = -E1000_ERR_PHY;
360169240Sjfv		goto out;
361169240Sjfv	}
362169240Sjfv
363169240Sjfvout:
364169240Sjfv	return ret_val;
365169240Sjfv}
366169240Sjfv
367169240Sjfv/**
368169240Sjfv *  e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
369169589Sjfv *  @hw: pointer to the HW structure
370169240Sjfv *
371169240Sjfv *  Initialize family-specific NVM parameters and function
372169240Sjfv *  pointers.
373169240Sjfv **/
374177867Sjfvstatic s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
375169240Sjfv{
376169240Sjfv	struct e1000_nvm_info *nvm = &hw->nvm;
377185353Sjfv	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
378169240Sjfv	u32 gfpreg, sector_base_addr, sector_end_addr;
379173788Sjfv	s32 ret_val = E1000_SUCCESS;
380169240Sjfv	u16 i;
381169240Sjfv
382169240Sjfv	DEBUGFUNC("e1000_init_nvm_params_ich8lan");
383169240Sjfv
384173788Sjfv	/* Can't read flash registers if the register set isn't mapped. */
385169240Sjfv	if (!hw->flash_address) {
386169240Sjfv		DEBUGOUT("ERROR: Flash registers not mapped\n");
387169240Sjfv		ret_val = -E1000_ERR_CONFIG;
388169240Sjfv		goto out;
389169240Sjfv	}
390169240Sjfv
391185353Sjfv	nvm->type = e1000_nvm_flash_sw;
392169240Sjfv
393169240Sjfv	gfpreg = E1000_READ_FLASH_REG(hw, ICH_FLASH_GFPREG);
394169240Sjfv
395173788Sjfv	/*
396173788Sjfv	 * sector_X_addr is a "sector"-aligned address (4096 bytes)
397169240Sjfv	 * Add 1 to sector_end_addr since this sector is included in
398173788Sjfv	 * the overall size.
399173788Sjfv	 */
400169240Sjfv	sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
401169240Sjfv	sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
402169240Sjfv
403169240Sjfv	/* flash_base_addr is byte-aligned */
404185353Sjfv	nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
405169240Sjfv
406173788Sjfv	/*
407173788Sjfv	 * find total size of the NVM, then cut in half since the total
408173788Sjfv	 * size represents two separate NVM banks.
409173788Sjfv	 */
410185353Sjfv	nvm->flash_bank_size = (sector_end_addr - sector_base_addr)
411169240Sjfv	                          << FLASH_SECTOR_ADDR_SHIFT;
412185353Sjfv	nvm->flash_bank_size /= 2;
413169240Sjfv	/* Adjust to word count */
414185353Sjfv	nvm->flash_bank_size /= sizeof(u16);
415169240Sjfv
416185353Sjfv	nvm->word_size = E1000_SHADOW_RAM_WORDS;
417169240Sjfv
418169240Sjfv	/* Clear shadow ram */
419169240Sjfv	for (i = 0; i < nvm->word_size; i++) {
420169240Sjfv		dev_spec->shadow_ram[i].modified = FALSE;
421169240Sjfv		dev_spec->shadow_ram[i].value    = 0xFFFF;
422169240Sjfv	}
423169240Sjfv
424200243Sjfv	E1000_MUTEX_INIT(&dev_spec->nvm_mutex);
425200243Sjfv	E1000_MUTEX_INIT(&dev_spec->swflag_mutex);
426200243Sjfv
427169240Sjfv	/* Function Pointers */
428200243Sjfv	nvm->ops.acquire       = e1000_acquire_nvm_ich8lan;
429200243Sjfv	nvm->ops.release       = e1000_release_nvm_ich8lan;
430177867Sjfv	nvm->ops.read          = e1000_read_nvm_ich8lan;
431177867Sjfv	nvm->ops.update        = e1000_update_nvm_checksum_ich8lan;
432177867Sjfv	nvm->ops.valid_led_default = e1000_valid_led_default_ich8lan;
433177867Sjfv	nvm->ops.validate      = e1000_validate_nvm_checksum_ich8lan;
434177867Sjfv	nvm->ops.write         = e1000_write_nvm_ich8lan;
435169240Sjfv
436169240Sjfvout:
437169240Sjfv	return ret_val;
438169240Sjfv}
439169240Sjfv
440169240Sjfv/**
441169240Sjfv *  e1000_init_mac_params_ich8lan - Initialize MAC function pointers
442169589Sjfv *  @hw: pointer to the HW structure
443169240Sjfv *
444169240Sjfv *  Initialize family-specific MAC parameters and function
445169240Sjfv *  pointers.
446169240Sjfv **/
447177867Sjfvstatic s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
448169240Sjfv{
449169240Sjfv	struct e1000_mac_info *mac = &hw->mac;
450190872Sjfv	u16 pci_cfg;
451169240Sjfv
452169240Sjfv	DEBUGFUNC("e1000_init_mac_params_ich8lan");
453169240Sjfv
454169240Sjfv	/* Set media type function pointer */
455173788Sjfv	hw->phy.media_type = e1000_media_type_copper;
456169240Sjfv
457169240Sjfv	/* Set mta register count */
458169240Sjfv	mac->mta_reg_count = 32;
459169240Sjfv	/* Set rar entry count */
460169240Sjfv	mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
461169240Sjfv	if (mac->type == e1000_ich8lan)
462169240Sjfv		mac->rar_entry_count--;
463169240Sjfv	/* Set if part includes ASF firmware */
464169240Sjfv	mac->asf_firmware_present = TRUE;
465205869Sjfv	/* FWSM register */
466205869Sjfv	mac->has_fwsm = TRUE;
467205869Sjfv	/* ARC subsystem not supported */
468205869Sjfv	mac->arc_subsystem_valid = FALSE;
469200243Sjfv	/* Adaptive IFS supported */
470200243Sjfv	mac->adaptive_ifs = TRUE;
471169240Sjfv
472169240Sjfv	/* Function pointers */
473169240Sjfv
474169240Sjfv	/* bus type/speed/width */
475177867Sjfv	mac->ops.get_bus_info = e1000_get_bus_info_ich8lan;
476185353Sjfv	/* function id */
477185353Sjfv	mac->ops.set_lan_id = e1000_set_lan_id_single_port;
478169240Sjfv	/* reset */
479177867Sjfv	mac->ops.reset_hw = e1000_reset_hw_ich8lan;
480169240Sjfv	/* hw initialization */
481177867Sjfv	mac->ops.init_hw = e1000_init_hw_ich8lan;
482169240Sjfv	/* link setup */
483177867Sjfv	mac->ops.setup_link = e1000_setup_link_ich8lan;
484169240Sjfv	/* physical interface setup */
485177867Sjfv	mac->ops.setup_physical_interface = e1000_setup_copper_link_ich8lan;
486169240Sjfv	/* check for link */
487200243Sjfv	mac->ops.check_for_link = e1000_check_for_copper_link_ich8lan;
488169240Sjfv	/* check management mode */
489177867Sjfv	mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
490169240Sjfv	/* link info */
491177867Sjfv	mac->ops.get_link_up_info = e1000_get_link_up_info_ich8lan;
492169240Sjfv	/* multicast address update */
493177867Sjfv	mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
494169240Sjfv	/* clear hardware counters */
495177867Sjfv	mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan;
496169240Sjfv
497190872Sjfv	/* LED operations */
498190872Sjfv	switch (mac->type) {
499190872Sjfv	case e1000_ich8lan:
500190872Sjfv	case e1000_ich9lan:
501190872Sjfv	case e1000_ich10lan:
502190872Sjfv		/* ID LED init */
503190872Sjfv		mac->ops.id_led_init = e1000_id_led_init_generic;
504190872Sjfv		/* blink LED */
505190872Sjfv		mac->ops.blink_led = e1000_blink_led_generic;
506190872Sjfv		/* setup LED */
507190872Sjfv		mac->ops.setup_led = e1000_setup_led_generic;
508190872Sjfv		/* cleanup LED */
509190872Sjfv		mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
510190872Sjfv		/* turn on/off LED */
511190872Sjfv		mac->ops.led_on = e1000_led_on_ich8lan;
512190872Sjfv		mac->ops.led_off = e1000_led_off_ich8lan;
513190872Sjfv		break;
514194865Sjfv	case e1000_pchlan:
515194865Sjfv		/* save PCH revision_id */
516194865Sjfv		e1000_read_pci_cfg(hw, 0x2, &pci_cfg);
517194865Sjfv		hw->revision_id = (u8)(pci_cfg &= 0x000F);
518194865Sjfv		/* ID LED init */
519194865Sjfv		mac->ops.id_led_init = e1000_id_led_init_pchlan;
520194865Sjfv		/* setup LED */
521194865Sjfv		mac->ops.setup_led = e1000_setup_led_pchlan;
522194865Sjfv		/* cleanup LED */
523194865Sjfv		mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
524194865Sjfv		/* turn on/off LED */
525194865Sjfv		mac->ops.led_on = e1000_led_on_pchlan;
526194865Sjfv		mac->ops.led_off = e1000_led_off_pchlan;
527194865Sjfv		break;
528190872Sjfv	default:
529190872Sjfv		break;
530190872Sjfv	}
531190872Sjfv
532169240Sjfv	/* Enable PCS Lock-loss workaround for ICH8 */
533169240Sjfv	if (mac->type == e1000_ich8lan)
534169240Sjfv		e1000_set_kmrn_lock_loss_workaround_ich8lan(hw, TRUE);
535169240Sjfv
536185353Sjfv	return E1000_SUCCESS;
537169240Sjfv}
538169240Sjfv
539169240Sjfv/**
540200243Sjfv *  e1000_check_for_copper_link_ich8lan - Check for link (Copper)
541200243Sjfv *  @hw: pointer to the HW structure
542200243Sjfv *
543200243Sjfv *  Checks to see of the link status of the hardware has changed.  If a
544200243Sjfv *  change in link status has been detected, then we read the PHY registers
545200243Sjfv *  to get the current speed/duplex if link exists.
546200243Sjfv **/
547200243Sjfvstatic s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
548200243Sjfv{
549200243Sjfv	struct e1000_mac_info *mac = &hw->mac;
550200243Sjfv	s32 ret_val;
551200243Sjfv	bool link;
552200243Sjfv
553200243Sjfv	DEBUGFUNC("e1000_check_for_copper_link_ich8lan");
554200243Sjfv
555200243Sjfv	/*
556200243Sjfv	 * We only want to go out to the PHY registers to see if Auto-Neg
557200243Sjfv	 * has completed and/or if our link status has changed.  The
558200243Sjfv	 * get_link_status flag is set upon receiving a Link Status
559200243Sjfv	 * Change or Rx Sequence Error interrupt.
560200243Sjfv	 */
561200243Sjfv	if (!mac->get_link_status) {
562200243Sjfv		ret_val = E1000_SUCCESS;
563200243Sjfv		goto out;
564200243Sjfv	}
565200243Sjfv
566200243Sjfv	/*
567200243Sjfv	 * First we want to see if the MII Status Register reports
568200243Sjfv	 * link.  If so, then we want to get the current speed/duplex
569200243Sjfv	 * of the PHY.
570200243Sjfv	 */
571200243Sjfv	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
572200243Sjfv	if (ret_val)
573200243Sjfv		goto out;
574200243Sjfv
575200243Sjfv	if (hw->mac.type == e1000_pchlan) {
576200243Sjfv		ret_val = e1000_k1_gig_workaround_hv(hw, link);
577200243Sjfv		if (ret_val)
578200243Sjfv			goto out;
579200243Sjfv	}
580200243Sjfv
581200243Sjfv	if (!link)
582200243Sjfv		goto out; /* No link detected */
583200243Sjfv
584200243Sjfv	mac->get_link_status = FALSE;
585200243Sjfv
586200243Sjfv	if (hw->phy.type == e1000_phy_82578) {
587200243Sjfv		ret_val = e1000_link_stall_workaround_hv(hw);
588200243Sjfv		if (ret_val)
589200243Sjfv			goto out;
590200243Sjfv	}
591200243Sjfv
592200243Sjfv	/*
593200243Sjfv	 * Check if there was DownShift, must be checked
594200243Sjfv	 * immediately after link-up
595200243Sjfv	 */
596200243Sjfv	e1000_check_downshift_generic(hw);
597200243Sjfv
598200243Sjfv	/*
599200243Sjfv	 * If we are forcing speed/duplex, then we simply return since
600200243Sjfv	 * we have already determined whether we have link or not.
601200243Sjfv	 */
602200243Sjfv	if (!mac->autoneg) {
603200243Sjfv		ret_val = -E1000_ERR_CONFIG;
604200243Sjfv		goto out;
605200243Sjfv	}
606200243Sjfv
607200243Sjfv	/*
608200243Sjfv	 * Auto-Neg is enabled.  Auto Speed Detection takes care
609200243Sjfv	 * of MAC speed/duplex configuration.  So we only need to
610200243Sjfv	 * configure Collision Distance in the MAC.
611200243Sjfv	 */
612200243Sjfv	e1000_config_collision_dist_generic(hw);
613200243Sjfv
614200243Sjfv	/*
615200243Sjfv	 * Configure Flow Control now that Auto-Neg has completed.
616200243Sjfv	 * First, we need to restore the desired flow control
617200243Sjfv	 * settings because we may have had to re-autoneg with a
618200243Sjfv	 * different link partner.
619200243Sjfv	 */
620200243Sjfv	ret_val = e1000_config_fc_after_link_up_generic(hw);
621200243Sjfv	if (ret_val)
622200243Sjfv		DEBUGOUT("Error configuring flow control\n");
623200243Sjfv
624200243Sjfvout:
625200243Sjfv	return ret_val;
626200243Sjfv}
627200243Sjfv
628200243Sjfv/**
629169240Sjfv *  e1000_init_function_pointers_ich8lan - Initialize ICH8 function pointers
630169589Sjfv *  @hw: pointer to the HW structure
631169240Sjfv *
632169240Sjfv *  Initialize family-specific function pointers for PHY, MAC, and NVM.
633169240Sjfv **/
634173788Sjfvvoid e1000_init_function_pointers_ich8lan(struct e1000_hw *hw)
635169240Sjfv{
636169240Sjfv	DEBUGFUNC("e1000_init_function_pointers_ich8lan");
637169240Sjfv
638177867Sjfv	hw->mac.ops.init_params = e1000_init_mac_params_ich8lan;
639177867Sjfv	hw->nvm.ops.init_params = e1000_init_nvm_params_ich8lan;
640194865Sjfv	switch (hw->mac.type) {
641194865Sjfv	case e1000_ich8lan:
642194865Sjfv	case e1000_ich9lan:
643194865Sjfv	case e1000_ich10lan:
644194865Sjfv		hw->phy.ops.init_params = e1000_init_phy_params_ich8lan;
645194865Sjfv		break;
646194865Sjfv	case e1000_pchlan:
647194865Sjfv		hw->phy.ops.init_params = e1000_init_phy_params_pchlan;
648194865Sjfv		break;
649194865Sjfv	default:
650194865Sjfv		break;
651194865Sjfv	}
652169240Sjfv}
653169240Sjfv
654169240Sjfv/**
655200243Sjfv *  e1000_acquire_nvm_ich8lan - Acquire NVM mutex
656200243Sjfv *  @hw: pointer to the HW structure
657200243Sjfv *
658200243Sjfv *  Acquires the mutex for performing NVM operations.
659200243Sjfv **/
660200243Sjfvstatic s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
661200243Sjfv{
662200243Sjfv	DEBUGFUNC("e1000_acquire_nvm_ich8lan");
663200243Sjfv
664200243Sjfv	E1000_MUTEX_LOCK(&hw->dev_spec.ich8lan.nvm_mutex);
665200243Sjfv
666200243Sjfv	return E1000_SUCCESS;
667200243Sjfv}
668200243Sjfv
669200243Sjfv/**
670200243Sjfv *  e1000_release_nvm_ich8lan - Release NVM mutex
671200243Sjfv *  @hw: pointer to the HW structure
672200243Sjfv *
673200243Sjfv *  Releases the mutex used while performing NVM operations.
674200243Sjfv **/
675200243Sjfvstatic void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
676200243Sjfv{
677200243Sjfv	DEBUGFUNC("e1000_release_nvm_ich8lan");
678200243Sjfv
679200243Sjfv	E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.nvm_mutex);
680200243Sjfv
681200243Sjfv	return;
682200243Sjfv}
683200243Sjfv
684200243Sjfv/**
685169240Sjfv *  e1000_acquire_swflag_ich8lan - Acquire software control flag
686169589Sjfv *  @hw: pointer to the HW structure
687169240Sjfv *
688200243Sjfv *  Acquires the software control flag for performing PHY and select
689200243Sjfv *  MAC CSR accesses.
690169240Sjfv **/
691177867Sjfvstatic s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
692169240Sjfv{
693169240Sjfv	u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
694169240Sjfv	s32 ret_val = E1000_SUCCESS;
695169240Sjfv
696169240Sjfv	DEBUGFUNC("e1000_acquire_swflag_ich8lan");
697169240Sjfv
698200243Sjfv	E1000_MUTEX_LOCK(&hw->dev_spec.ich8lan.swflag_mutex);
699200243Sjfv
700169240Sjfv	while (timeout) {
701169240Sjfv		extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
702200243Sjfv		if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
703200243Sjfv			break;
704169240Sjfv
705200243Sjfv		msec_delay_irq(1);
706200243Sjfv		timeout--;
707200243Sjfv	}
708194865Sjfv
709200243Sjfv	if (!timeout) {
710200243Sjfv		DEBUGOUT("SW/FW/HW has locked the resource for too long.\n");
711200243Sjfv		ret_val = -E1000_ERR_CONFIG;
712200243Sjfv		goto out;
713200243Sjfv	}
714200243Sjfv
715200243Sjfv	timeout = SW_FLAG_TIMEOUT;
716200243Sjfv
717200243Sjfv	extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
718200243Sjfv	E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
719200243Sjfv
720200243Sjfv	while (timeout) {
721200243Sjfv		extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
722200243Sjfv		if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
723200243Sjfv			break;
724200243Sjfv
725169240Sjfv		msec_delay_irq(1);
726169240Sjfv		timeout--;
727169240Sjfv	}
728169240Sjfv
729169240Sjfv	if (!timeout) {
730200243Sjfv		DEBUGOUT("Failed to acquire the semaphore.\n");
731173788Sjfv		extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
732173788Sjfv		E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
733169240Sjfv		ret_val = -E1000_ERR_CONFIG;
734169240Sjfv		goto out;
735169240Sjfv	}
736169240Sjfv
737169240Sjfvout:
738200243Sjfv	if (ret_val)
739200243Sjfv		E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.swflag_mutex);
740200243Sjfv
741169240Sjfv	return ret_val;
742169240Sjfv}
743169240Sjfv
744169240Sjfv/**
745169240Sjfv *  e1000_release_swflag_ich8lan - Release software control flag
746169589Sjfv *  @hw: pointer to the HW structure
747169240Sjfv *
748200243Sjfv *  Releases the software control flag for performing PHY and select
749200243Sjfv *  MAC CSR accesses.
750169240Sjfv **/
751177867Sjfvstatic void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
752169240Sjfv{
753169240Sjfv	u32 extcnf_ctrl;
754169240Sjfv
755169240Sjfv	DEBUGFUNC("e1000_release_swflag_ich8lan");
756169240Sjfv
757169240Sjfv	extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
758169240Sjfv	extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
759169240Sjfv	E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
760169240Sjfv
761200243Sjfv	E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.swflag_mutex);
762200243Sjfv
763169240Sjfv	return;
764169240Sjfv}
765169240Sjfv
766169240Sjfv/**
767169240Sjfv *  e1000_check_mng_mode_ich8lan - Checks management mode
768169589Sjfv *  @hw: pointer to the HW structure
769169240Sjfv *
770169240Sjfv *  This checks if the adapter has manageability enabled.
771169240Sjfv *  This is a function pointer entry point only called by read/write
772169240Sjfv *  routines for the PHY and NVM parts.
773169240Sjfv **/
774177867Sjfvstatic bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
775169240Sjfv{
776169240Sjfv	u32 fwsm;
777169240Sjfv
778169240Sjfv	DEBUGFUNC("e1000_check_mng_mode_ich8lan");
779169240Sjfv
780169240Sjfv	fwsm = E1000_READ_REG(hw, E1000_FWSM);
781169240Sjfv
782185353Sjfv	return (fwsm & E1000_FWSM_MODE_MASK) ==
783185353Sjfv	        (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
784169240Sjfv}
785169240Sjfv
786169240Sjfv/**
787169240Sjfv *  e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
788169589Sjfv *  @hw: pointer to the HW structure
789169240Sjfv *
790169240Sjfv *  Checks if firmware is blocking the reset of the PHY.
791169240Sjfv *  This is a function pointer entry point only called by
792169240Sjfv *  reset routines.
793169240Sjfv **/
794177867Sjfvstatic s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
795169240Sjfv{
796169240Sjfv	u32 fwsm;
797169240Sjfv
798169240Sjfv	DEBUGFUNC("e1000_check_reset_block_ich8lan");
799169240Sjfv
800205869Sjfv	if (hw->phy.reset_disable)
801205869Sjfv		return E1000_BLK_PHY_RESET;
802205869Sjfv
803169240Sjfv	fwsm = E1000_READ_REG(hw, E1000_FWSM);
804169240Sjfv
805169240Sjfv	return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? E1000_SUCCESS
806169240Sjfv	                                        : E1000_BLK_PHY_RESET;
807169240Sjfv}
808169240Sjfv
809169240Sjfv/**
810200243Sjfv *  e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
811200243Sjfv *  @hw:   pointer to the HW structure
812200243Sjfv *
813200243Sjfv *  SW should configure the LCD from the NVM extended configuration region
814200243Sjfv *  as a workaround for certain parts.
815200243Sjfv **/
816200243Sjfvstatic s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
817200243Sjfv{
818200243Sjfv	struct e1000_phy_info *phy = &hw->phy;
819200243Sjfv	u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
820203049Sjfv	s32 ret_val = E1000_SUCCESS;
821200243Sjfv	u16 word_addr, reg_data, reg_addr, phy_page = 0;
822200243Sjfv
823203049Sjfv	if (!(hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) &&
824203049Sjfv		!(hw->mac.type == e1000_pchlan))
825203049Sjfv		return ret_val;
826203049Sjfv
827200243Sjfv	ret_val = hw->phy.ops.acquire(hw);
828200243Sjfv	if (ret_val)
829200243Sjfv		return ret_val;
830200243Sjfv
831200243Sjfv	/*
832200243Sjfv	 * Initialize the PHY from the NVM on ICH platforms.  This
833200243Sjfv	 * is needed due to an issue where the NVM configuration is
834200243Sjfv	 * not properly autoloaded after power transitions.
835200243Sjfv	 * Therefore, after each PHY reset, we will load the
836200243Sjfv	 * configuration data out of the NVM manually.
837200243Sjfv	 */
838203049Sjfv	if ((hw->device_id == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
839203049Sjfv	    (hw->device_id == E1000_DEV_ID_ICH8_IGP_M) ||
840203049Sjfv	    (hw->mac.type == e1000_pchlan))
841203049Sjfv		sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
842203049Sjfv	else
843203049Sjfv		sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
844200243Sjfv
845203049Sjfv	data = E1000_READ_REG(hw, E1000_FEXTNVM);
846203049Sjfv	if (!(data & sw_cfg_mask))
847203049Sjfv		goto out;
848200243Sjfv
849203049Sjfv	/* Wait for basic configuration completes before proceeding */
850203049Sjfv	e1000_lan_init_done_ich8lan(hw);
851200243Sjfv
852203049Sjfv	/*
853203049Sjfv	 * Make sure HW does not configure LCD from PHY
854203049Sjfv	 * extended configuration before SW configuration
855203049Sjfv	 */
856203049Sjfv	data = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
857203049Sjfv	if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
858203049Sjfv		goto out;
859203049Sjfv
860203049Sjfv	cnf_size = E1000_READ_REG(hw, E1000_EXTCNF_SIZE);
861203049Sjfv	cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
862203049Sjfv	cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
863203049Sjfv	if (!cnf_size)
864203049Sjfv		goto out;
865203049Sjfv
866203049Sjfv	cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
867203049Sjfv	cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
868203049Sjfv
869203049Sjfv	if (!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
870203049Sjfv	    (hw->mac.type == e1000_pchlan)) {
871200243Sjfv		/*
872203049Sjfv		 * HW configures the SMBus address and LEDs when the
873203049Sjfv		 * OEM and LCD Write Enable bits are set in the NVM.
874203049Sjfv		 * When both NVM bits are cleared, SW will configure
875203049Sjfv		 * them instead.
876200243Sjfv		 */
877203049Sjfv		data = E1000_READ_REG(hw, E1000_STRAP);
878203049Sjfv		data &= E1000_STRAP_SMBUS_ADDRESS_MASK;
879203049Sjfv		reg_data = data >> E1000_STRAP_SMBUS_ADDRESS_SHIFT;
880203049Sjfv		reg_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
881203049Sjfv		ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR,
882203049Sjfv							reg_data);
883203049Sjfv		if (ret_val)
884200243Sjfv			goto out;
885200243Sjfv
886203049Sjfv		data = E1000_READ_REG(hw, E1000_LEDCTL);
887203049Sjfv		ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
888203049Sjfv							(u16)data);
889203049Sjfv		if (ret_val)
890200243Sjfv			goto out;
891203049Sjfv	}
892200243Sjfv
893203049Sjfv	/* Configure LCD from extended configuration region. */
894200243Sjfv
895203049Sjfv	/* cnf_base_addr is in DWORD */
896203049Sjfv	word_addr = (u16)(cnf_base_addr << 1);
897200243Sjfv
898203049Sjfv	for (i = 0; i < cnf_size; i++) {
899203049Sjfv		ret_val = hw->nvm.ops.read(hw, (word_addr + i * 2), 1,
900203049Sjfv					   &reg_data);
901203049Sjfv		if (ret_val)
902203049Sjfv			goto out;
903200243Sjfv
904203049Sjfv		ret_val = hw->nvm.ops.read(hw, (word_addr + i * 2 + 1),
905203049Sjfv					   1, &reg_addr);
906203049Sjfv		if (ret_val)
907203049Sjfv			goto out;
908200243Sjfv
909203049Sjfv		/* Save off the PHY page for future writes. */
910203049Sjfv		if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
911203049Sjfv			phy_page = reg_data;
912203049Sjfv			continue;
913203049Sjfv		}
914200243Sjfv
915203049Sjfv		reg_addr &= PHY_REG_MASK;
916203049Sjfv		reg_addr |= phy_page;
917200243Sjfv
918203049Sjfv		ret_val = phy->ops.write_reg_locked(hw, (u32)reg_addr,
919203049Sjfv						    reg_data);
920203049Sjfv		if (ret_val)
921203049Sjfv			goto out;
922200243Sjfv	}
923200243Sjfv
924200243Sjfvout:
925200243Sjfv	hw->phy.ops.release(hw);
926200243Sjfv	return ret_val;
927200243Sjfv}
928200243Sjfv
929200243Sjfv/**
930200243Sjfv *  e1000_k1_gig_workaround_hv - K1 Si workaround
931200243Sjfv *  @hw:   pointer to the HW structure
932200243Sjfv *  @link: link up bool flag
933200243Sjfv *
934200243Sjfv *  If K1 is enabled for 1Gbps, the MAC might stall when transitioning
935200243Sjfv *  from a lower speed.  This workaround disables K1 whenever link is at 1Gig
936200243Sjfv *  If link is down, the function will restore the default K1 setting located
937200243Sjfv *  in the NVM.
938200243Sjfv **/
939200243Sjfvstatic s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
940200243Sjfv{
941200243Sjfv	s32 ret_val = E1000_SUCCESS;
942200243Sjfv	u16 status_reg = 0;
943200243Sjfv	bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
944200243Sjfv
945200243Sjfv	DEBUGFUNC("e1000_k1_gig_workaround_hv");
946200243Sjfv
947200243Sjfv	if (hw->mac.type != e1000_pchlan)
948200243Sjfv		goto out;
949200243Sjfv
950200243Sjfv	/* Wrap the whole flow with the sw flag */
951200243Sjfv	ret_val = hw->phy.ops.acquire(hw);
952200243Sjfv	if (ret_val)
953200243Sjfv		goto out;
954200243Sjfv
955200243Sjfv	/* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
956200243Sjfv	if (link) {
957200243Sjfv		if (hw->phy.type == e1000_phy_82578) {
958200243Sjfv			ret_val = hw->phy.ops.read_reg_locked(hw, BM_CS_STATUS,
959200243Sjfv			                                      &status_reg);
960200243Sjfv			if (ret_val)
961200243Sjfv				goto release;
962200243Sjfv
963200243Sjfv			status_reg &= BM_CS_STATUS_LINK_UP |
964200243Sjfv			              BM_CS_STATUS_RESOLVED |
965200243Sjfv			              BM_CS_STATUS_SPEED_MASK;
966200243Sjfv
967200243Sjfv			if (status_reg == (BM_CS_STATUS_LINK_UP |
968200243Sjfv			                   BM_CS_STATUS_RESOLVED |
969200243Sjfv			                   BM_CS_STATUS_SPEED_1000))
970200243Sjfv				k1_enable = FALSE;
971200243Sjfv		}
972200243Sjfv
973200243Sjfv		if (hw->phy.type == e1000_phy_82577) {
974200243Sjfv			ret_val = hw->phy.ops.read_reg_locked(hw, HV_M_STATUS,
975200243Sjfv			                                      &status_reg);
976200243Sjfv			if (ret_val)
977200243Sjfv				goto release;
978200243Sjfv
979200243Sjfv			status_reg &= HV_M_STATUS_LINK_UP |
980200243Sjfv			              HV_M_STATUS_AUTONEG_COMPLETE |
981200243Sjfv			              HV_M_STATUS_SPEED_MASK;
982200243Sjfv
983200243Sjfv			if (status_reg == (HV_M_STATUS_LINK_UP |
984200243Sjfv			                   HV_M_STATUS_AUTONEG_COMPLETE |
985200243Sjfv			                   HV_M_STATUS_SPEED_1000))
986200243Sjfv				k1_enable = FALSE;
987200243Sjfv		}
988200243Sjfv
989200243Sjfv		/* Link stall fix for link up */
990200243Sjfv		ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
991200243Sjfv		                                       0x0100);
992200243Sjfv		if (ret_val)
993200243Sjfv			goto release;
994200243Sjfv
995200243Sjfv	} else {
996200243Sjfv		/* Link stall fix for link down */
997200243Sjfv		ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
998200243Sjfv		                                       0x4100);
999200243Sjfv		if (ret_val)
1000200243Sjfv			goto release;
1001200243Sjfv	}
1002200243Sjfv
1003200243Sjfv	ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
1004200243Sjfv
1005200243Sjfvrelease:
1006200243Sjfv	hw->phy.ops.release(hw);
1007200243Sjfvout:
1008200243Sjfv	return ret_val;
1009200243Sjfv}
1010200243Sjfv
1011200243Sjfv/**
1012200243Sjfv *  e1000_configure_k1_ich8lan - Configure K1 power state
1013200243Sjfv *  @hw: pointer to the HW structure
1014200243Sjfv *  @enable: K1 state to configure
1015200243Sjfv *
1016200243Sjfv *  Configure the K1 power state based on the provided parameter.
1017200243Sjfv *  Assumes semaphore already acquired.
1018200243Sjfv *
1019200243Sjfv *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1020200243Sjfv **/
1021200243Sjfvs32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
1022200243Sjfv{
1023200243Sjfv	s32 ret_val = E1000_SUCCESS;
1024200243Sjfv	u32 ctrl_reg = 0;
1025200243Sjfv	u32 ctrl_ext = 0;
1026200243Sjfv	u32 reg = 0;
1027200243Sjfv	u16 kmrn_reg = 0;
1028200243Sjfv
1029200243Sjfv	ret_val = e1000_read_kmrn_reg_locked(hw,
1030200243Sjfv	                                     E1000_KMRNCTRLSTA_K1_CONFIG,
1031200243Sjfv	                                     &kmrn_reg);
1032200243Sjfv	if (ret_val)
1033200243Sjfv		goto out;
1034200243Sjfv
1035200243Sjfv	if (k1_enable)
1036200243Sjfv		kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
1037200243Sjfv	else
1038200243Sjfv		kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
1039200243Sjfv
1040200243Sjfv	ret_val = e1000_write_kmrn_reg_locked(hw,
1041200243Sjfv	                                      E1000_KMRNCTRLSTA_K1_CONFIG,
1042200243Sjfv	                                      kmrn_reg);
1043200243Sjfv	if (ret_val)
1044200243Sjfv		goto out;
1045200243Sjfv
1046200243Sjfv	usec_delay(20);
1047200243Sjfv	ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1048200243Sjfv	ctrl_reg = E1000_READ_REG(hw, E1000_CTRL);
1049200243Sjfv
1050200243Sjfv	reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1051200243Sjfv	reg |= E1000_CTRL_FRCSPD;
1052200243Sjfv	E1000_WRITE_REG(hw, E1000_CTRL, reg);
1053200243Sjfv
1054200243Sjfv	E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
1055200243Sjfv	usec_delay(20);
1056200243Sjfv	E1000_WRITE_REG(hw, E1000_CTRL, ctrl_reg);
1057200243Sjfv	E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1058200243Sjfv	usec_delay(20);
1059200243Sjfv
1060200243Sjfvout:
1061200243Sjfv	return ret_val;
1062200243Sjfv}
1063200243Sjfv
1064200243Sjfv/**
1065200243Sjfv *  e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
1066200243Sjfv *  @hw:       pointer to the HW structure
1067200243Sjfv *  @d0_state: boolean if entering d0 or d3 device state
1068200243Sjfv *
1069200243Sjfv *  SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
1070200243Sjfv *  collectively called OEM bits.  The OEM Write Enable bit and SW Config bit
1071200243Sjfv *  in NVM determines whether HW should configure LPLU and Gbe Disable.
1072200243Sjfv **/
1073200243Sjfvs32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
1074200243Sjfv{
1075200243Sjfv	s32 ret_val = 0;
1076200243Sjfv	u32 mac_reg;
1077200243Sjfv	u16 oem_reg;
1078200243Sjfv
1079200243Sjfv	if (hw->mac.type != e1000_pchlan)
1080200243Sjfv		return ret_val;
1081200243Sjfv
1082200243Sjfv	ret_val = hw->phy.ops.acquire(hw);
1083200243Sjfv	if (ret_val)
1084200243Sjfv		return ret_val;
1085200243Sjfv
1086200243Sjfv	mac_reg = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
1087200243Sjfv	if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
1088200243Sjfv		goto out;
1089200243Sjfv
1090200243Sjfv	mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM);
1091200243Sjfv	if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
1092200243Sjfv		goto out;
1093200243Sjfv
1094200243Sjfv	mac_reg = E1000_READ_REG(hw, E1000_PHY_CTRL);
1095200243Sjfv
1096200243Sjfv	ret_val = hw->phy.ops.read_reg_locked(hw, HV_OEM_BITS, &oem_reg);
1097200243Sjfv	if (ret_val)
1098200243Sjfv		goto out;
1099200243Sjfv
1100200243Sjfv	oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
1101200243Sjfv
1102200243Sjfv	if (d0_state) {
1103200243Sjfv		if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
1104200243Sjfv			oem_reg |= HV_OEM_BITS_GBE_DIS;
1105200243Sjfv
1106200243Sjfv		if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
1107200243Sjfv			oem_reg |= HV_OEM_BITS_LPLU;
1108200243Sjfv	} else {
1109200243Sjfv		if (mac_reg & E1000_PHY_CTRL_NOND0A_GBE_DISABLE)
1110200243Sjfv			oem_reg |= HV_OEM_BITS_GBE_DIS;
1111200243Sjfv
1112200243Sjfv		if (mac_reg & E1000_PHY_CTRL_NOND0A_LPLU)
1113200243Sjfv			oem_reg |= HV_OEM_BITS_LPLU;
1114200243Sjfv	}
1115200243Sjfv	/* Restart auto-neg to activate the bits */
1116200243Sjfv	if (!hw->phy.ops.check_reset_block(hw))
1117200243Sjfv		oem_reg |= HV_OEM_BITS_RESTART_AN;
1118200243Sjfv	ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
1119200243Sjfv
1120200243Sjfvout:
1121200243Sjfv	hw->phy.ops.release(hw);
1122200243Sjfv
1123200243Sjfv	return ret_val;
1124200243Sjfv}
1125200243Sjfv
1126200243Sjfv
1127200243Sjfv/**
1128194865Sjfv *  e1000_hv_phy_powerdown_workaround_ich8lan - Power down workaround on Sx
1129169589Sjfv *  @hw: pointer to the HW structure
1130169240Sjfv **/
1131194865Sjfvs32 e1000_hv_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
1132169240Sjfv{
1133194865Sjfv	if ((hw->phy.type != e1000_phy_82577) || (hw->revision_id > 2))
1134194865Sjfv		return E1000_SUCCESS;
1135169240Sjfv
1136194865Sjfv	return hw->phy.ops.write_reg(hw, PHY_REG(768, 25), 0x0444);
1137194865Sjfv}
1138169240Sjfv
1139194865Sjfv/**
1140203049Sjfv *  e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
1141203049Sjfv *  @hw:   pointer to the HW structure
1142203049Sjfv **/
1143203049Sjfvstatic s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
1144203049Sjfv{
1145203049Sjfv	s32 ret_val;
1146203049Sjfv	u16 data;
1147203049Sjfv
1148203049Sjfv	ret_val = hw->phy.ops.read_reg(hw, HV_KMRN_MODE_CTRL, &data);
1149203049Sjfv	if (ret_val)
1150203049Sjfv		return ret_val;
1151203049Sjfv
1152203049Sjfv	data |= HV_KMRN_MDIO_SLOW;
1153203049Sjfv
1154203049Sjfv	ret_val = hw->phy.ops.write_reg(hw, HV_KMRN_MODE_CTRL, data);
1155203049Sjfv
1156203049Sjfv	return ret_val;
1157203049Sjfv}
1158203049Sjfv
1159203049Sjfv/**
1160194865Sjfv *  e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
1161194865Sjfv *  done after every PHY reset.
1162194865Sjfv **/
1163194865Sjfvstatic s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
1164194865Sjfv{
1165194865Sjfv	s32 ret_val = E1000_SUCCESS;
1166203049Sjfv	u16 phy_data;
1167194865Sjfv
1168194865Sjfv	if (hw->mac.type != e1000_pchlan)
1169200243Sjfv		goto out;
1170194865Sjfv
1171203049Sjfv	/* Set MDIO slow mode before any other MDIO access */
1172203049Sjfv	if (hw->phy.type == e1000_phy_82577) {
1173203049Sjfv		ret_val = e1000_set_mdio_slow_mode_hv(hw);
1174203049Sjfv		if (ret_val)
1175203049Sjfv			goto out;
1176203049Sjfv	}
1177203049Sjfv
1178194865Sjfv	/* Hanksville M Phy init for IEEE. */
1179194865Sjfv	if ((hw->revision_id == 2) &&
1180194865Sjfv	    (hw->phy.type == e1000_phy_82577) &&
1181194865Sjfv	    ((hw->phy.revision == 2) || (hw->phy.revision == 3))) {
1182194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x8823);
1183194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0018);
1184194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x8824);
1185194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0016);
1186194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x8825);
1187194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x001A);
1188194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x888C);
1189194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0007);
1190194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x888D);
1191194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0007);
1192194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x888E);
1193194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0007);
1194194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x8827);
1195194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0001);
1196194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x8835);
1197194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0001);
1198194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x8834);
1199194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0001);
1200194865Sjfv		hw->phy.ops.write_reg(hw, 0x10, 0x8833);
1201194865Sjfv		hw->phy.ops.write_reg(hw, 0x11, 0x0002);
1202169240Sjfv	}
1203169240Sjfv
1204194865Sjfv	if (((hw->phy.type == e1000_phy_82577) &&
1205194865Sjfv	     ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
1206194865Sjfv	    ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
1207194865Sjfv		/* Disable generation of early preamble */
1208194865Sjfv		ret_val = hw->phy.ops.write_reg(hw, PHY_REG(769, 25), 0x4431);
1209194865Sjfv		if (ret_val)
1210200243Sjfv			goto out;
1211169240Sjfv
1212194865Sjfv		/* Preamble tuning for SSC */
1213194865Sjfv		ret_val = hw->phy.ops.write_reg(hw, PHY_REG(770, 16), 0xA204);
1214194865Sjfv		if (ret_val)
1215200243Sjfv			goto out;
1216194865Sjfv	}
1217169240Sjfv
1218194865Sjfv	if (hw->phy.type == e1000_phy_82578) {
1219194865Sjfv		if (hw->revision_id < 3) {
1220194865Sjfv			/* PHY config */
1221194865Sjfv			ret_val = hw->phy.ops.write_reg(hw, (1 << 6) | 0x29,
1222194865Sjfv			                                0x66C0);
1223194865Sjfv			if (ret_val)
1224200243Sjfv				goto out;
1225169240Sjfv
1226194865Sjfv			/* PHY config */
1227194865Sjfv			ret_val = hw->phy.ops.write_reg(hw, (1 << 6) | 0x1E,
1228194865Sjfv			                                0xFFFF);
1229194865Sjfv			if (ret_val)
1230200243Sjfv				goto out;
1231194865Sjfv		}
1232169240Sjfv
1233194865Sjfv		/*
1234194865Sjfv		 * Return registers to default by doing a soft reset then
1235194865Sjfv		 * writing 0x3140 to the control register.
1236194865Sjfv		 */
1237194865Sjfv		if (hw->phy.revision < 2) {
1238194865Sjfv			e1000_phy_sw_reset_generic(hw);
1239194865Sjfv			ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL,
1240194865Sjfv			                                0x3140);
1241194865Sjfv		}
1242194865Sjfv	}
1243169240Sjfv
1244194865Sjfv	if ((hw->revision_id == 2) &&
1245194865Sjfv	    (hw->phy.type == e1000_phy_82577) &&
1246194865Sjfv	    ((hw->phy.revision == 2) || (hw->phy.revision == 3))) {
1247194865Sjfv		/*
1248194865Sjfv		 * Workaround for OEM (GbE) not operating after reset -
1249194865Sjfv		 * restart AN (twice)
1250194865Sjfv		 */
1251194865Sjfv		ret_val = hw->phy.ops.write_reg(hw, PHY_REG(768, 25), 0x0400);
1252194865Sjfv		if (ret_val)
1253200243Sjfv			goto out;
1254194865Sjfv		ret_val = hw->phy.ops.write_reg(hw, PHY_REG(768, 25), 0x0400);
1255194865Sjfv		if (ret_val)
1256200243Sjfv			goto out;
1257194865Sjfv	}
1258194865Sjfv
1259194865Sjfv	/* Select page 0 */
1260194865Sjfv	ret_val = hw->phy.ops.acquire(hw);
1261169240Sjfv	if (ret_val)
1262200243Sjfv		goto out;
1263200243Sjfv
1264194865Sjfv	hw->phy.addr = 1;
1265200243Sjfv	ret_val = e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
1266203049Sjfv	hw->phy.ops.release(hw);
1267200243Sjfv	if (ret_val)
1268200243Sjfv		goto out;
1269169240Sjfv
1270200243Sjfv	/*
1271200243Sjfv	 * Configure the K1 Si workaround during phy reset assuming there is
1272200243Sjfv	 * link so that it disables K1 if link is in 1Gbps.
1273200243Sjfv	 */
1274200243Sjfv	ret_val = e1000_k1_gig_workaround_hv(hw, TRUE);
1275203049Sjfv	if (ret_val)
1276203049Sjfv		goto out;
1277200243Sjfv
1278203049Sjfv	/* Workaround for link disconnects on a busy hub in half duplex */
1279203049Sjfv	ret_val = hw->phy.ops.acquire(hw);
1280203049Sjfv	if (ret_val)
1281203049Sjfv		goto out;
1282203049Sjfv	ret_val = hw->phy.ops.read_reg_locked(hw,
1283203049Sjfv	                                      PHY_REG(BM_PORT_CTRL_PAGE, 17),
1284203049Sjfv	                                      &phy_data);
1285203049Sjfv	if (ret_val)
1286203049Sjfv		goto release;
1287203049Sjfv	ret_val = hw->phy.ops.write_reg_locked(hw,
1288203049Sjfv	                                       PHY_REG(BM_PORT_CTRL_PAGE, 17),
1289203049Sjfv	                                       phy_data & 0x00FF);
1290203049Sjfvrelease:
1291203049Sjfv	hw->phy.ops.release(hw);
1292200243Sjfvout:
1293194865Sjfv	return ret_val;
1294194865Sjfv}
1295169240Sjfv
1296194865Sjfv/**
1297194865Sjfv *  e1000_lan_init_done_ich8lan - Check for PHY config completion
1298194865Sjfv *  @hw: pointer to the HW structure
1299194865Sjfv *
1300194865Sjfv *  Check the appropriate indication the MAC has finished configuring the
1301194865Sjfv *  PHY after a software reset.
1302194865Sjfv **/
1303194865Sjfvstatic void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
1304194865Sjfv{
1305194865Sjfv	u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
1306169240Sjfv
1307194865Sjfv	DEBUGFUNC("e1000_lan_init_done_ich8lan");
1308169240Sjfv
1309194865Sjfv	/* Wait for basic configuration completes before proceeding */
1310194865Sjfv	do {
1311194865Sjfv		data = E1000_READ_REG(hw, E1000_STATUS);
1312194865Sjfv		data &= E1000_STATUS_LAN_INIT_DONE;
1313194865Sjfv		usec_delay(100);
1314194865Sjfv	} while ((!data) && --loop);
1315169240Sjfv
1316194865Sjfv	/*
1317194865Sjfv	 * If basic configuration is incomplete before the above loop
1318194865Sjfv	 * count reaches 0, loading the configuration from NVM will
1319194865Sjfv	 * leave the PHY in a bad state possibly resulting in no link.
1320194865Sjfv	 */
1321194865Sjfv	if (loop == 0)
1322194865Sjfv		DEBUGOUT("LAN_INIT_DONE not set, increase timeout\n");
1323169240Sjfv
1324194865Sjfv	/* Clear the Init Done bit for the next init event */
1325194865Sjfv	data = E1000_READ_REG(hw, E1000_STATUS);
1326194865Sjfv	data &= ~E1000_STATUS_LAN_INIT_DONE;
1327194865Sjfv	E1000_WRITE_REG(hw, E1000_STATUS, data);
1328169240Sjfv}
1329169240Sjfv
1330169240Sjfv/**
1331169240Sjfv *  e1000_phy_hw_reset_ich8lan - Performs a PHY reset
1332169589Sjfv *  @hw: pointer to the HW structure
1333169240Sjfv *
1334169240Sjfv *  Resets the PHY
1335169240Sjfv *  This is a function pointer entry point called by drivers
1336169240Sjfv *  or other shared routines.
1337169240Sjfv **/
1338177867Sjfvstatic s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
1339169240Sjfv{
1340200243Sjfv	s32 ret_val = E1000_SUCCESS;
1341200243Sjfv	u16 reg;
1342169240Sjfv
1343169240Sjfv	DEBUGFUNC("e1000_phy_hw_reset_ich8lan");
1344169240Sjfv
1345169240Sjfv	ret_val = e1000_phy_hw_reset_generic(hw);
1346169240Sjfv	if (ret_val)
1347169240Sjfv		goto out;
1348169240Sjfv
1349194865Sjfv	/* Allow time for h/w to get to a quiescent state after reset */
1350194865Sjfv	msec_delay(10);
1351194865Sjfv
1352203049Sjfv	/* Perform any necessary post-reset workarounds */
1353203049Sjfv	switch (hw->mac.type) {
1354203049Sjfv	case e1000_pchlan:
1355194865Sjfv		ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
1356194865Sjfv		if (ret_val)
1357194865Sjfv			goto out;
1358203049Sjfv		break;
1359203049Sjfv	default:
1360203049Sjfv		break;
1361194865Sjfv	}
1362194865Sjfv
1363200243Sjfv	/* Dummy read to clear the phy wakeup bit after lcd reset */
1364200243Sjfv	if (hw->mac.type == e1000_pchlan)
1365200243Sjfv		hw->phy.ops.read_reg(hw, BM_WUC, &reg);
1366169240Sjfv
1367200243Sjfv	/* Configure the LCD with the extended configuration region in NVM */
1368200243Sjfv	ret_val = e1000_sw_lcd_config_ich8lan(hw);
1369200243Sjfv	if (ret_val)
1370200243Sjfv		goto out;
1371169240Sjfv
1372200243Sjfv	/* Configure the LCD with the OEM bits in NVM */
1373203049Sjfv	ret_val = e1000_oem_bits_config_ich8lan(hw, TRUE);
1374169240Sjfv
1375169240Sjfvout:
1376169240Sjfv	return ret_val;
1377169240Sjfv}
1378169240Sjfv
1379169240Sjfv/**
1380200243Sjfv *  e1000_set_lplu_state_pchlan - Set Low Power Link Up state
1381169589Sjfv *  @hw: pointer to the HW structure
1382200243Sjfv *  @active: TRUE to enable LPLU, FALSE to disable
1383169240Sjfv *
1384200243Sjfv *  Sets the LPLU state according to the active flag.  For PCH, if OEM write
1385200243Sjfv *  bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
1386200243Sjfv *  the phy speed. This function will manually set the LPLU bit and restart
1387200243Sjfv *  auto-neg as hw would do. D3 and D0 LPLU will call the same function
1388200243Sjfv *  since it configures the same bit.
1389169240Sjfv **/
1390200243Sjfvstatic s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
1391169240Sjfv{
1392200243Sjfv	s32 ret_val = E1000_SUCCESS;
1393200243Sjfv	u16 oem_reg;
1394169240Sjfv
1395200243Sjfv	DEBUGFUNC("e1000_set_lplu_state_pchlan");
1396169240Sjfv
1397200243Sjfv	ret_val = hw->phy.ops.read_reg(hw, HV_OEM_BITS, &oem_reg);
1398169240Sjfv	if (ret_val)
1399169240Sjfv		goto out;
1400169240Sjfv
1401200243Sjfv	if (active)
1402200243Sjfv		oem_reg |= HV_OEM_BITS_LPLU;
1403200243Sjfv	else
1404200243Sjfv		oem_reg &= ~HV_OEM_BITS_LPLU;
1405169240Sjfv
1406200243Sjfv	oem_reg |= HV_OEM_BITS_RESTART_AN;
1407200243Sjfv	ret_val = hw->phy.ops.write_reg(hw, HV_OEM_BITS, oem_reg);
1408169240Sjfv
1409169240Sjfvout:
1410169240Sjfv	return ret_val;
1411169240Sjfv}
1412169240Sjfv
1413169240Sjfv/**
1414169240Sjfv *  e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
1415169589Sjfv *  @hw: pointer to the HW structure
1416169589Sjfv *  @active: TRUE to enable LPLU, FALSE to disable
1417169240Sjfv *
1418169240Sjfv *  Sets the LPLU D0 state according to the active flag.  When
1419169240Sjfv *  activating LPLU this function also disables smart speed
1420169240Sjfv *  and vice versa.  LPLU will not be activated unless the
1421169240Sjfv *  device autonegotiation advertisement meets standards of
1422169240Sjfv *  either 10 or 10/100 or 10/100/1000 at all duplexes.
1423169240Sjfv *  This is a function pointer entry point only called by
1424169240Sjfv *  PHY setup routines.
1425169240Sjfv **/
1426185353Sjfvstatic s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1427169240Sjfv{
1428169240Sjfv	struct e1000_phy_info *phy = &hw->phy;
1429169240Sjfv	u32 phy_ctrl;
1430169240Sjfv	s32 ret_val = E1000_SUCCESS;
1431169240Sjfv	u16 data;
1432169240Sjfv
1433169240Sjfv	DEBUGFUNC("e1000_set_d0_lplu_state_ich8lan");
1434169240Sjfv
1435173788Sjfv	if (phy->type == e1000_phy_ife)
1436169240Sjfv		goto out;
1437169240Sjfv
1438169240Sjfv	phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
1439169240Sjfv
1440169240Sjfv	if (active) {
1441169240Sjfv		phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
1442169240Sjfv		E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
1443169240Sjfv
1444194865Sjfv		if (phy->type != e1000_phy_igp_3)
1445194865Sjfv			goto out;
1446194865Sjfv
1447173788Sjfv		/*
1448173788Sjfv		 * Call gig speed drop workaround on LPLU before accessing
1449173788Sjfv		 * any PHY registers
1450173788Sjfv		 */
1451194865Sjfv		if (hw->mac.type == e1000_ich8lan)
1452169240Sjfv			e1000_gig_downshift_workaround_ich8lan(hw);
1453169240Sjfv
1454169240Sjfv		/* When LPLU is enabled, we should disable SmartSpeed */
1455177867Sjfv		ret_val = phy->ops.read_reg(hw,
1456169240Sjfv		                            IGP01E1000_PHY_PORT_CONFIG,
1457169240Sjfv		                            &data);
1458169240Sjfv		data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1459177867Sjfv		ret_val = phy->ops.write_reg(hw,
1460169240Sjfv		                             IGP01E1000_PHY_PORT_CONFIG,
1461169240Sjfv		                             data);
1462169240Sjfv		if (ret_val)
1463169240Sjfv			goto out;
1464169240Sjfv	} else {
1465169240Sjfv		phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
1466169240Sjfv		E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
1467169240Sjfv
1468194865Sjfv		if (phy->type != e1000_phy_igp_3)
1469194865Sjfv			goto out;
1470194865Sjfv
1471173788Sjfv		/*
1472173788Sjfv		 * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
1473169240Sjfv		 * during Dx states where the power conservation is most
1474169240Sjfv		 * important.  During driver activity we should enable
1475173788Sjfv		 * SmartSpeed, so performance is maintained.
1476173788Sjfv		 */
1477169240Sjfv		if (phy->smart_speed == e1000_smart_speed_on) {
1478177867Sjfv			ret_val = phy->ops.read_reg(hw,
1479169240Sjfv			                            IGP01E1000_PHY_PORT_CONFIG,
1480169240Sjfv			                            &data);
1481169240Sjfv			if (ret_val)
1482169240Sjfv				goto out;
1483169240Sjfv
1484169240Sjfv			data |= IGP01E1000_PSCFR_SMART_SPEED;
1485177867Sjfv			ret_val = phy->ops.write_reg(hw,
1486169240Sjfv			                             IGP01E1000_PHY_PORT_CONFIG,
1487169240Sjfv			                             data);
1488169240Sjfv			if (ret_val)
1489169240Sjfv				goto out;
1490169240Sjfv		} else if (phy->smart_speed == e1000_smart_speed_off) {
1491177867Sjfv			ret_val = phy->ops.read_reg(hw,
1492169240Sjfv			                            IGP01E1000_PHY_PORT_CONFIG,
1493169240Sjfv			                            &data);
1494169240Sjfv			if (ret_val)
1495169240Sjfv				goto out;
1496169240Sjfv
1497169240Sjfv			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1498177867Sjfv			ret_val = phy->ops.write_reg(hw,
1499169240Sjfv			                             IGP01E1000_PHY_PORT_CONFIG,
1500169240Sjfv			                             data);
1501169240Sjfv			if (ret_val)
1502169240Sjfv				goto out;
1503169240Sjfv		}
1504169240Sjfv	}
1505169240Sjfv
1506169240Sjfvout:
1507169240Sjfv	return ret_val;
1508169240Sjfv}
1509169240Sjfv
1510169240Sjfv/**
1511169240Sjfv *  e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
1512169589Sjfv *  @hw: pointer to the HW structure
1513169589Sjfv *  @active: TRUE to enable LPLU, FALSE to disable
1514169240Sjfv *
1515169240Sjfv *  Sets the LPLU D3 state according to the active flag.  When
1516169240Sjfv *  activating LPLU this function also disables smart speed
1517169240Sjfv *  and vice versa.  LPLU will not be activated unless the
1518169240Sjfv *  device autonegotiation advertisement meets standards of
1519169240Sjfv *  either 10 or 10/100 or 10/100/1000 at all duplexes.
1520169240Sjfv *  This is a function pointer entry point only called by
1521169240Sjfv *  PHY setup routines.
1522169240Sjfv **/
1523185353Sjfvstatic s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
1524169240Sjfv{
1525169240Sjfv	struct e1000_phy_info *phy = &hw->phy;
1526169240Sjfv	u32 phy_ctrl;
1527169240Sjfv	s32 ret_val = E1000_SUCCESS;
1528169240Sjfv	u16 data;
1529169240Sjfv
1530169240Sjfv	DEBUGFUNC("e1000_set_d3_lplu_state_ich8lan");
1531169240Sjfv
1532169240Sjfv	phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
1533169240Sjfv
1534169240Sjfv	if (!active) {
1535169240Sjfv		phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
1536169240Sjfv		E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
1537194865Sjfv
1538194865Sjfv		if (phy->type != e1000_phy_igp_3)
1539194865Sjfv			goto out;
1540194865Sjfv
1541173788Sjfv		/*
1542173788Sjfv		 * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
1543169240Sjfv		 * during Dx states where the power conservation is most
1544169240Sjfv		 * important.  During driver activity we should enable
1545173788Sjfv		 * SmartSpeed, so performance is maintained.
1546173788Sjfv		 */
1547169240Sjfv		if (phy->smart_speed == e1000_smart_speed_on) {
1548177867Sjfv			ret_val = phy->ops.read_reg(hw,
1549169240Sjfv			                            IGP01E1000_PHY_PORT_CONFIG,
1550169240Sjfv			                            &data);
1551169240Sjfv			if (ret_val)
1552169240Sjfv				goto out;
1553169240Sjfv
1554169240Sjfv			data |= IGP01E1000_PSCFR_SMART_SPEED;
1555177867Sjfv			ret_val = phy->ops.write_reg(hw,
1556169240Sjfv			                             IGP01E1000_PHY_PORT_CONFIG,
1557169240Sjfv			                             data);
1558169240Sjfv			if (ret_val)
1559169240Sjfv				goto out;
1560169240Sjfv		} else if (phy->smart_speed == e1000_smart_speed_off) {
1561177867Sjfv			ret_val = phy->ops.read_reg(hw,
1562169240Sjfv			                            IGP01E1000_PHY_PORT_CONFIG,
1563169240Sjfv			                            &data);
1564169240Sjfv			if (ret_val)
1565169240Sjfv				goto out;
1566169240Sjfv
1567169240Sjfv			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1568177867Sjfv			ret_val = phy->ops.write_reg(hw,
1569169240Sjfv			                             IGP01E1000_PHY_PORT_CONFIG,
1570169240Sjfv			                             data);
1571169240Sjfv			if (ret_val)
1572169240Sjfv				goto out;
1573169240Sjfv		}
1574169240Sjfv	} else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1575169240Sjfv	           (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1576169240Sjfv	           (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1577169240Sjfv		phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
1578169240Sjfv		E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
1579169240Sjfv
1580194865Sjfv		if (phy->type != e1000_phy_igp_3)
1581194865Sjfv			goto out;
1582194865Sjfv
1583173788Sjfv		/*
1584173788Sjfv		 * Call gig speed drop workaround on LPLU before accessing
1585173788Sjfv		 * any PHY registers
1586173788Sjfv		 */
1587194865Sjfv		if (hw->mac.type == e1000_ich8lan)
1588169240Sjfv			e1000_gig_downshift_workaround_ich8lan(hw);
1589169240Sjfv
1590169240Sjfv		/* When LPLU is enabled, we should disable SmartSpeed */
1591177867Sjfv		ret_val = phy->ops.read_reg(hw,
1592169240Sjfv		                            IGP01E1000_PHY_PORT_CONFIG,
1593169240Sjfv		                            &data);
1594169240Sjfv		if (ret_val)
1595169240Sjfv			goto out;
1596169240Sjfv
1597169240Sjfv		data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1598177867Sjfv		ret_val = phy->ops.write_reg(hw,
1599169240Sjfv		                             IGP01E1000_PHY_PORT_CONFIG,
1600169240Sjfv		                             data);
1601169240Sjfv	}
1602169240Sjfv
1603169240Sjfvout:
1604169240Sjfv	return ret_val;
1605169240Sjfv}
1606169240Sjfv
1607169240Sjfv/**
1608173788Sjfv *  e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
1609173788Sjfv *  @hw: pointer to the HW structure
1610173788Sjfv *  @bank:  pointer to the variable that returns the active bank
1611173788Sjfv *
1612173788Sjfv *  Reads signature byte from the NVM using the flash access registers.
1613190872Sjfv *  Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
1614173788Sjfv **/
1615177867Sjfvstatic s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
1616173788Sjfv{
1617190872Sjfv	u32 eecd;
1618178523Sjfv	struct e1000_nvm_info *nvm = &hw->nvm;
1619178523Sjfv	u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
1620178523Sjfv	u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
1621190872Sjfv	u8 sig_byte = 0;
1622190872Sjfv	s32 ret_val = E1000_SUCCESS;
1623178523Sjfv
1624190872Sjfv	switch (hw->mac.type) {
1625190872Sjfv	case e1000_ich8lan:
1626190872Sjfv	case e1000_ich9lan:
1627190872Sjfv		eecd = E1000_READ_REG(hw, E1000_EECD);
1628190872Sjfv		if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
1629190872Sjfv		    E1000_EECD_SEC1VAL_VALID_MASK) {
1630190872Sjfv			if (eecd & E1000_EECD_SEC1VAL)
1631190872Sjfv				*bank = 1;
1632190872Sjfv			else
1633190872Sjfv				*bank = 0;
1634190872Sjfv
1635190872Sjfv			goto out;
1636190872Sjfv		}
1637190872Sjfv		DEBUGOUT("Unable to determine valid NVM bank via EEC - "
1638190872Sjfv		         "reading flash signature\n");
1639190872Sjfv		/* fall-thru */
1640190872Sjfv	default:
1641190872Sjfv		/* set bank to 0 in case flash read fails */
1642190872Sjfv		*bank = 0;
1643190872Sjfv
1644190872Sjfv		/* Check bank 0 */
1645190872Sjfv		ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
1646190872Sjfv		                                        &sig_byte);
1647190872Sjfv		if (ret_val)
1648190872Sjfv			goto out;
1649190872Sjfv		if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1650200243Sjfv		    E1000_ICH_NVM_SIG_VALUE) {
1651178523Sjfv			*bank = 0;
1652190872Sjfv			goto out;
1653190872Sjfv		}
1654185353Sjfv
1655190872Sjfv		/* Check bank 1 */
1656190872Sjfv		ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
1657190872Sjfv		                                        bank1_offset,
1658200243Sjfv		                                        &sig_byte);
1659190872Sjfv		if (ret_val)
1660190872Sjfv			goto out;
1661190872Sjfv		if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
1662200243Sjfv		    E1000_ICH_NVM_SIG_VALUE) {
1663190872Sjfv			*bank = 1;
1664190872Sjfv			goto out;
1665178523Sjfv		}
1666190872Sjfv
1667190872Sjfv		DEBUGOUT("ERROR: No valid NVM bank present\n");
1668190872Sjfv		ret_val = -E1000_ERR_NVM;
1669190872Sjfv		break;
1670178523Sjfv	}
1671190872Sjfvout:
1672173788Sjfv	return ret_val;
1673173788Sjfv}
1674173788Sjfv
1675173788Sjfv/**
1676169240Sjfv *  e1000_read_nvm_ich8lan - Read word(s) from the NVM
1677169589Sjfv *  @hw: pointer to the HW structure
1678169589Sjfv *  @offset: The offset (in bytes) of the word(s) to read.
1679169589Sjfv *  @words: Size of data to read in words
1680169589Sjfv *  @data: Pointer to the word(s) to read at offset.
1681169240Sjfv *
1682169240Sjfv *  Reads a word(s) from the NVM using the flash access registers.
1683169240Sjfv **/
1684177867Sjfvstatic s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1685173788Sjfv                                  u16 *data)
1686169240Sjfv{
1687169240Sjfv	struct e1000_nvm_info *nvm = &hw->nvm;
1688185353Sjfv	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
1689169240Sjfv	u32 act_offset;
1690169240Sjfv	s32 ret_val = E1000_SUCCESS;
1691173788Sjfv	u32 bank = 0;
1692169240Sjfv	u16 i, word;
1693169240Sjfv
1694169240Sjfv	DEBUGFUNC("e1000_read_nvm_ich8lan");
1695169240Sjfv
1696169240Sjfv	if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
1697169240Sjfv	    (words == 0)) {
1698169240Sjfv		DEBUGOUT("nvm parameter(s) out of bounds\n");
1699169240Sjfv		ret_val = -E1000_ERR_NVM;
1700169240Sjfv		goto out;
1701169240Sjfv	}
1702169240Sjfv
1703200243Sjfv	nvm->ops.acquire(hw);
1704169240Sjfv
1705173788Sjfv	ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
1706200243Sjfv	if (ret_val != E1000_SUCCESS) {
1707200243Sjfv		DEBUGOUT("Could not detect valid bank, assuming bank 0\n");
1708200243Sjfv		bank = 0;
1709200243Sjfv	}
1710173788Sjfv
1711173788Sjfv	act_offset = (bank) ? nvm->flash_bank_size : 0;
1712169240Sjfv	act_offset += offset;
1713169240Sjfv
1714200243Sjfv	ret_val = E1000_SUCCESS;
1715169240Sjfv	for (i = 0; i < words; i++) {
1716173788Sjfv		if ((dev_spec->shadow_ram) &&
1717173788Sjfv		    (dev_spec->shadow_ram[offset+i].modified)) {
1718169240Sjfv			data[i] = dev_spec->shadow_ram[offset+i].value;
1719169240Sjfv		} else {
1720169240Sjfv			ret_val = e1000_read_flash_word_ich8lan(hw,
1721169240Sjfv			                                        act_offset + i,
1722169240Sjfv			                                        &word);
1723169240Sjfv			if (ret_val)
1724169240Sjfv				break;
1725169240Sjfv			data[i] = word;
1726169240Sjfv		}
1727169240Sjfv	}
1728169240Sjfv
1729177867Sjfv	nvm->ops.release(hw);
1730169240Sjfv
1731169240Sjfvout:
1732190872Sjfv	if (ret_val)
1733190872Sjfv		DEBUGOUT1("NVM read error: %d\n", ret_val);
1734190872Sjfv
1735169240Sjfv	return ret_val;
1736169240Sjfv}
1737169240Sjfv
1738169240Sjfv/**
1739169240Sjfv *  e1000_flash_cycle_init_ich8lan - Initialize flash
1740169589Sjfv *  @hw: pointer to the HW structure
1741169240Sjfv *
1742169240Sjfv *  This function does initial flash setup so that a new read/write/erase cycle
1743169240Sjfv *  can be started.
1744169240Sjfv **/
1745173788Sjfvstatic s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
1746169240Sjfv{
1747169240Sjfv	union ich8_hws_flash_status hsfsts;
1748169240Sjfv	s32 ret_val = -E1000_ERR_NVM;
1749169240Sjfv	s32 i = 0;
1750169240Sjfv
1751169240Sjfv	DEBUGFUNC("e1000_flash_cycle_init_ich8lan");
1752169240Sjfv
1753169240Sjfv	hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
1754169240Sjfv
1755169240Sjfv	/* Check if the flash descriptor is valid */
1756169240Sjfv	if (hsfsts.hsf_status.fldesvalid == 0) {
1757169240Sjfv		DEBUGOUT("Flash descriptor invalid.  "
1758169240Sjfv		         "SW Sequencing must be used.");
1759169240Sjfv		goto out;
1760169240Sjfv	}
1761169240Sjfv
1762169240Sjfv	/* Clear FCERR and DAEL in hw status by writing 1 */
1763169240Sjfv	hsfsts.hsf_status.flcerr = 1;
1764169240Sjfv	hsfsts.hsf_status.dael = 1;
1765169240Sjfv
1766169240Sjfv	E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
1767169240Sjfv
1768173788Sjfv	/*
1769173788Sjfv	 * Either we should have a hardware SPI cycle in progress
1770169240Sjfv	 * bit to check against, in order to start a new cycle or
1771169240Sjfv	 * FDONE bit should be changed in the hardware so that it
1772176667Sjfv	 * is 1 after hardware reset, which can then be used as an
1773169240Sjfv	 * indication whether a cycle is in progress or has been
1774169240Sjfv	 * completed.
1775169240Sjfv	 */
1776169240Sjfv
1777169240Sjfv	if (hsfsts.hsf_status.flcinprog == 0) {
1778173788Sjfv		/*
1779173788Sjfv		 * There is no cycle running at present,
1780173788Sjfv		 * so we can start a cycle.
1781173788Sjfv		 * Begin by setting Flash Cycle Done.
1782173788Sjfv		 */
1783169240Sjfv		hsfsts.hsf_status.flcdone = 1;
1784169240Sjfv		E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
1785169240Sjfv		ret_val = E1000_SUCCESS;
1786169240Sjfv	} else {
1787173788Sjfv		/*
1788173788Sjfv		 * Otherwise poll for sometime so the current
1789173788Sjfv		 * cycle has a chance to end before giving up.
1790173788Sjfv		 */
1791169240Sjfv		for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
1792169240Sjfv			hsfsts.regval = E1000_READ_FLASH_REG16(hw,
1793169240Sjfv			                                      ICH_FLASH_HSFSTS);
1794169240Sjfv			if (hsfsts.hsf_status.flcinprog == 0) {
1795169240Sjfv				ret_val = E1000_SUCCESS;
1796169240Sjfv				break;
1797169240Sjfv			}
1798169240Sjfv			usec_delay(1);
1799169240Sjfv		}
1800169240Sjfv		if (ret_val == E1000_SUCCESS) {
1801173788Sjfv			/*
1802173788Sjfv			 * Successful in waiting for previous cycle to timeout,
1803173788Sjfv			 * now set the Flash Cycle Done.
1804173788Sjfv			 */
1805169240Sjfv			hsfsts.hsf_status.flcdone = 1;
1806185353Sjfv			E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS,
1807169240Sjfv			                        hsfsts.regval);
1808169240Sjfv		} else {
1809169240Sjfv			DEBUGOUT("Flash controller busy, cannot get access");
1810169240Sjfv		}
1811169240Sjfv	}
1812169240Sjfv
1813169240Sjfvout:
1814169240Sjfv	return ret_val;
1815169240Sjfv}
1816169240Sjfv
1817169240Sjfv/**
1818169240Sjfv *  e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
1819169589Sjfv *  @hw: pointer to the HW structure
1820169589Sjfv *  @timeout: maximum time to wait for completion
1821169240Sjfv *
1822169240Sjfv *  This function starts a flash cycle and waits for its completion.
1823169240Sjfv **/
1824173788Sjfvstatic s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
1825169240Sjfv{
1826169240Sjfv	union ich8_hws_flash_ctrl hsflctl;
1827169240Sjfv	union ich8_hws_flash_status hsfsts;
1828169240Sjfv	s32 ret_val = -E1000_ERR_NVM;
1829169240Sjfv	u32 i = 0;
1830169240Sjfv
1831169240Sjfv	DEBUGFUNC("e1000_flash_cycle_ich8lan");
1832169240Sjfv
1833169240Sjfv	/* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
1834169240Sjfv	hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
1835169240Sjfv	hsflctl.hsf_ctrl.flcgo = 1;
1836169240Sjfv	E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
1837169240Sjfv
1838169240Sjfv	/* wait till FDONE bit is set to 1 */
1839169240Sjfv	do {
1840169240Sjfv		hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
1841169240Sjfv		if (hsfsts.hsf_status.flcdone == 1)
1842169240Sjfv			break;
1843169240Sjfv		usec_delay(1);
1844169240Sjfv	} while (i++ < timeout);
1845169240Sjfv
1846169240Sjfv	if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
1847169240Sjfv		ret_val = E1000_SUCCESS;
1848169240Sjfv
1849169240Sjfv	return ret_val;
1850169240Sjfv}
1851169240Sjfv
1852169240Sjfv/**
1853169240Sjfv *  e1000_read_flash_word_ich8lan - Read word from flash
1854169589Sjfv *  @hw: pointer to the HW structure
1855169589Sjfv *  @offset: offset to data location
1856169589Sjfv *  @data: pointer to the location for storing the data
1857169240Sjfv *
1858169240Sjfv *  Reads the flash word at offset into data.  Offset is converted
1859169240Sjfv *  to bytes before read.
1860169240Sjfv **/
1861177867Sjfvstatic s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
1862173788Sjfv                                         u16 *data)
1863169240Sjfv{
1864169240Sjfv	s32 ret_val;
1865169240Sjfv
1866169240Sjfv	DEBUGFUNC("e1000_read_flash_word_ich8lan");
1867169240Sjfv
1868173788Sjfv	if (!data) {
1869169240Sjfv		ret_val = -E1000_ERR_NVM;
1870169240Sjfv		goto out;
1871169240Sjfv	}
1872169240Sjfv
1873169240Sjfv	/* Must convert offset into bytes. */
1874169240Sjfv	offset <<= 1;
1875169240Sjfv
1876169240Sjfv	ret_val = e1000_read_flash_data_ich8lan(hw, offset, 2, data);
1877169240Sjfv
1878169240Sjfvout:
1879169240Sjfv	return ret_val;
1880169240Sjfv}
1881169240Sjfv
1882169240Sjfv/**
1883178523Sjfv *  e1000_read_flash_byte_ich8lan - Read byte from flash
1884178523Sjfv *  @hw: pointer to the HW structure
1885178523Sjfv *  @offset: The offset of the byte to read.
1886178523Sjfv *  @data: Pointer to a byte to store the value read.
1887178523Sjfv *
1888178523Sjfv *  Reads a single byte from the NVM using the flash access registers.
1889178523Sjfv **/
1890178523Sjfvstatic s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
1891185353Sjfv                                         u8 *data)
1892178523Sjfv{
1893178523Sjfv	s32 ret_val = E1000_SUCCESS;
1894178523Sjfv	u16 word = 0;
1895178523Sjfv
1896178523Sjfv	ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
1897178523Sjfv	if (ret_val)
1898178523Sjfv		goto out;
1899178523Sjfv
1900178523Sjfv	*data = (u8)word;
1901178523Sjfv
1902178523Sjfvout:
1903178523Sjfv	return ret_val;
1904178523Sjfv}
1905178523Sjfv
1906178523Sjfv/**
1907169240Sjfv *  e1000_read_flash_data_ich8lan - Read byte or word from NVM
1908169589Sjfv *  @hw: pointer to the HW structure
1909169589Sjfv *  @offset: The offset (in bytes) of the byte or word to read.
1910169589Sjfv *  @size: Size of data to read, 1=byte 2=word
1911169589Sjfv *  @data: Pointer to the word to store the value read.
1912169240Sjfv *
1913169240Sjfv *  Reads a byte or word from the NVM using the flash access registers.
1914169240Sjfv **/
1915173788Sjfvstatic s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
1916185353Sjfv                                         u8 size, u16 *data)
1917169240Sjfv{
1918169240Sjfv	union ich8_hws_flash_status hsfsts;
1919169240Sjfv	union ich8_hws_flash_ctrl hsflctl;
1920169240Sjfv	u32 flash_linear_addr;
1921169240Sjfv	u32 flash_data = 0;
1922169240Sjfv	s32 ret_val = -E1000_ERR_NVM;
1923169240Sjfv	u8 count = 0;
1924169240Sjfv
1925169240Sjfv	DEBUGFUNC("e1000_read_flash_data_ich8lan");
1926169240Sjfv
1927173788Sjfv	if (size < 1  || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
1928169240Sjfv		goto out;
1929169240Sjfv
1930169240Sjfv	flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
1931169240Sjfv	                    hw->nvm.flash_base_addr;
1932169240Sjfv
1933169240Sjfv	do {
1934169240Sjfv		usec_delay(1);
1935169240Sjfv		/* Steps */
1936169240Sjfv		ret_val = e1000_flash_cycle_init_ich8lan(hw);
1937169240Sjfv		if (ret_val != E1000_SUCCESS)
1938169240Sjfv			break;
1939169240Sjfv
1940169240Sjfv		hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
1941169240Sjfv		/* 0b/1b corresponds to 1 or 2 byte size, respectively. */
1942169240Sjfv		hsflctl.hsf_ctrl.fldbcount = size - 1;
1943169240Sjfv		hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
1944169240Sjfv		E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
1945169240Sjfv
1946169240Sjfv		E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
1947169240Sjfv
1948169240Sjfv		ret_val = e1000_flash_cycle_ich8lan(hw,
1949169240Sjfv		                                ICH_FLASH_READ_COMMAND_TIMEOUT);
1950169240Sjfv
1951173788Sjfv		/*
1952173788Sjfv		 * Check if FCERR is set to 1, if set to 1, clear it
1953169240Sjfv		 * and try the whole sequence a few more times, else
1954169240Sjfv		 * read in (shift in) the Flash Data0, the order is
1955173788Sjfv		 * least significant byte first msb to lsb
1956173788Sjfv		 */
1957169240Sjfv		if (ret_val == E1000_SUCCESS) {
1958169240Sjfv			flash_data = E1000_READ_FLASH_REG(hw, ICH_FLASH_FDATA0);
1959185353Sjfv			if (size == 1)
1960169240Sjfv				*data = (u8)(flash_data & 0x000000FF);
1961185353Sjfv			else if (size == 2)
1962169240Sjfv				*data = (u16)(flash_data & 0x0000FFFF);
1963169240Sjfv			break;
1964169240Sjfv		} else {
1965173788Sjfv			/*
1966173788Sjfv			 * If we've gotten here, then things are probably
1967169240Sjfv			 * completely hosed, but if the error condition is
1968169240Sjfv			 * detected, it won't hurt to give it another try...
1969169240Sjfv			 * ICH_FLASH_CYCLE_REPEAT_COUNT times.
1970169240Sjfv			 */
1971169240Sjfv			hsfsts.regval = E1000_READ_FLASH_REG16(hw,
1972169240Sjfv			                                      ICH_FLASH_HSFSTS);
1973169240Sjfv			if (hsfsts.hsf_status.flcerr == 1) {
1974169240Sjfv				/* Repeat for some time before giving up. */
1975169240Sjfv				continue;
1976169240Sjfv			} else if (hsfsts.hsf_status.flcdone == 0) {
1977169240Sjfv				DEBUGOUT("Timeout error - flash cycle "
1978169240Sjfv				         "did not complete.");
1979169240Sjfv				break;
1980169240Sjfv			}
1981169240Sjfv		}
1982169240Sjfv	} while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
1983169240Sjfv
1984169240Sjfvout:
1985169240Sjfv	return ret_val;
1986169240Sjfv}
1987169240Sjfv
1988169240Sjfv/**
1989169240Sjfv *  e1000_write_nvm_ich8lan - Write word(s) to the NVM
1990169589Sjfv *  @hw: pointer to the HW structure
1991169589Sjfv *  @offset: The offset (in bytes) of the word(s) to write.
1992169589Sjfv *  @words: Size of data to write in words
1993169589Sjfv *  @data: Pointer to the word(s) to write at offset.
1994169240Sjfv *
1995169240Sjfv *  Writes a byte or word to the NVM using the flash access registers.
1996169240Sjfv **/
1997177867Sjfvstatic s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
1998173788Sjfv                                   u16 *data)
1999169240Sjfv{
2000169240Sjfv	struct e1000_nvm_info *nvm = &hw->nvm;
2001185353Sjfv	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2002169240Sjfv	s32 ret_val = E1000_SUCCESS;
2003169240Sjfv	u16 i;
2004169240Sjfv
2005169240Sjfv	DEBUGFUNC("e1000_write_nvm_ich8lan");
2006169240Sjfv
2007169240Sjfv	if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
2008169240Sjfv	    (words == 0)) {
2009169240Sjfv		DEBUGOUT("nvm parameter(s) out of bounds\n");
2010169240Sjfv		ret_val = -E1000_ERR_NVM;
2011169240Sjfv		goto out;
2012169240Sjfv	}
2013169240Sjfv
2014200243Sjfv	nvm->ops.acquire(hw);
2015169240Sjfv
2016169240Sjfv	for (i = 0; i < words; i++) {
2017169240Sjfv		dev_spec->shadow_ram[offset+i].modified = TRUE;
2018169240Sjfv		dev_spec->shadow_ram[offset+i].value = data[i];
2019169240Sjfv	}
2020169240Sjfv
2021177867Sjfv	nvm->ops.release(hw);
2022169240Sjfv
2023169240Sjfvout:
2024169240Sjfv	return ret_val;
2025169240Sjfv}
2026169240Sjfv
2027169240Sjfv/**
2028169240Sjfv *  e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
2029169589Sjfv *  @hw: pointer to the HW structure
2030169240Sjfv *
2031169240Sjfv *  The NVM checksum is updated by calling the generic update_nvm_checksum,
2032169240Sjfv *  which writes the checksum to the shadow ram.  The changes in the shadow
2033169240Sjfv *  ram are then committed to the EEPROM by processing each bank at a time
2034169240Sjfv *  checking for the modified bit and writing only the pending changes.
2035176667Sjfv *  After a successful commit, the shadow ram is cleared and is ready for
2036169240Sjfv *  future writes.
2037169240Sjfv **/
2038177867Sjfvstatic s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
2039169240Sjfv{
2040169240Sjfv	struct e1000_nvm_info *nvm = &hw->nvm;
2041185353Sjfv	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2042173788Sjfv	u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
2043169240Sjfv	s32 ret_val;
2044169240Sjfv	u16 data;
2045169240Sjfv
2046169240Sjfv	DEBUGFUNC("e1000_update_nvm_checksum_ich8lan");
2047169240Sjfv
2048169240Sjfv	ret_val = e1000_update_nvm_checksum_generic(hw);
2049169240Sjfv	if (ret_val)
2050169240Sjfv		goto out;
2051169240Sjfv
2052169240Sjfv	if (nvm->type != e1000_nvm_flash_sw)
2053169240Sjfv		goto out;
2054169240Sjfv
2055200243Sjfv	nvm->ops.acquire(hw);
2056169240Sjfv
2057173788Sjfv	/*
2058173788Sjfv	 * We're writing to the opposite bank so if we're on bank 1,
2059169240Sjfv	 * write to bank 0 etc.  We also need to erase the segment that
2060173788Sjfv	 * is going to be written
2061173788Sjfv	 */
2062173788Sjfv	ret_val =  e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
2063190872Sjfv	if (ret_val != E1000_SUCCESS) {
2064200243Sjfv		DEBUGOUT("Could not detect valid bank, assuming bank 0\n");
2065200243Sjfv		bank = 0;
2066190872Sjfv	}
2067173788Sjfv
2068173788Sjfv	if (bank == 0) {
2069169240Sjfv		new_bank_offset = nvm->flash_bank_size;
2070169240Sjfv		old_bank_offset = 0;
2071190872Sjfv		ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
2072203049Sjfv		if (ret_val)
2073203049Sjfv			goto release;
2074169240Sjfv	} else {
2075169240Sjfv		old_bank_offset = nvm->flash_bank_size;
2076169240Sjfv		new_bank_offset = 0;
2077190872Sjfv		ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
2078203049Sjfv		if (ret_val)
2079203049Sjfv			goto release;
2080169240Sjfv	}
2081169240Sjfv
2082169240Sjfv	for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
2083173788Sjfv		/*
2084173788Sjfv		 * Determine whether to write the value stored
2085169240Sjfv		 * in the other NVM bank or a modified value stored
2086173788Sjfv		 * in the shadow RAM
2087173788Sjfv		 */
2088173788Sjfv		if (dev_spec->shadow_ram[i].modified) {
2089169240Sjfv			data = dev_spec->shadow_ram[i].value;
2090169240Sjfv		} else {
2091190872Sjfv			ret_val = e1000_read_flash_word_ich8lan(hw, i +
2092190872Sjfv			                                        old_bank_offset,
2093190872Sjfv			                                        &data);
2094190872Sjfv			if (ret_val)
2095190872Sjfv				break;
2096169240Sjfv		}
2097169240Sjfv
2098173788Sjfv		/*
2099173788Sjfv		 * If the word is 0x13, then make sure the signature bits
2100169240Sjfv		 * (15:14) are 11b until the commit has completed.
2101169240Sjfv		 * This will allow us to write 10b which indicates the
2102169240Sjfv		 * signature is valid.  We want to do this after the write
2103169240Sjfv		 * has completed so that we don't mark the segment valid
2104173788Sjfv		 * while the write is still in progress
2105173788Sjfv		 */
2106169240Sjfv		if (i == E1000_ICH_NVM_SIG_WORD)
2107169240Sjfv			data |= E1000_ICH_NVM_SIG_MASK;
2108169240Sjfv
2109169240Sjfv		/* Convert offset to bytes. */
2110169240Sjfv		act_offset = (i + new_bank_offset) << 1;
2111169240Sjfv
2112169240Sjfv		usec_delay(100);
2113169240Sjfv		/* Write the bytes to the new bank. */
2114169240Sjfv		ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2115169240Sjfv		                                               act_offset,
2116169240Sjfv		                                               (u8)data);
2117169240Sjfv		if (ret_val)
2118169240Sjfv			break;
2119169240Sjfv
2120169240Sjfv		usec_delay(100);
2121169240Sjfv		ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2122169240Sjfv		                                          act_offset + 1,
2123169240Sjfv		                                          (u8)(data >> 8));
2124169240Sjfv		if (ret_val)
2125169240Sjfv			break;
2126169240Sjfv	}
2127169240Sjfv
2128173788Sjfv	/*
2129173788Sjfv	 * Don't bother writing the segment valid bits if sector
2130173788Sjfv	 * programming failed.
2131173788Sjfv	 */
2132169240Sjfv	if (ret_val) {
2133169240Sjfv		DEBUGOUT("Flash commit failed.\n");
2134203049Sjfv		goto release;
2135169240Sjfv	}
2136169240Sjfv
2137173788Sjfv	/*
2138173788Sjfv	 * Finally validate the new segment by setting bit 15:14
2139169240Sjfv	 * to 10b in word 0x13 , this can be done without an
2140169240Sjfv	 * erase as well since these bits are 11 to start with
2141173788Sjfv	 * and we need to change bit 14 to 0b
2142173788Sjfv	 */
2143169240Sjfv	act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
2144190872Sjfv	ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
2145203049Sjfv	if (ret_val)
2146203049Sjfv		goto release;
2147200243Sjfv
2148169240Sjfv	data &= 0xBFFF;
2149169240Sjfv	ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
2150169240Sjfv	                                               act_offset * 2 + 1,
2151169240Sjfv	                                               (u8)(data >> 8));
2152203049Sjfv	if (ret_val)
2153203049Sjfv		goto release;
2154169240Sjfv
2155173788Sjfv	/*
2156173788Sjfv	 * And invalidate the previously valid segment by setting
2157169240Sjfv	 * its signature word (0x13) high_byte to 0b. This can be
2158169240Sjfv	 * done without an erase because flash erase sets all bits
2159173788Sjfv	 * to 1's. We can write 1's to 0's without an erase
2160173788Sjfv	 */
2161169240Sjfv	act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
2162169240Sjfv	ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
2163203049Sjfv	if (ret_val)
2164203049Sjfv		goto release;
2165169240Sjfv
2166169240Sjfv	/* Great!  Everything worked, we can now clear the cached entries. */
2167169240Sjfv	for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
2168169240Sjfv		dev_spec->shadow_ram[i].modified = FALSE;
2169169240Sjfv		dev_spec->shadow_ram[i].value = 0xFFFF;
2170169240Sjfv	}
2171169240Sjfv
2172203049Sjfvrelease:
2173177867Sjfv	nvm->ops.release(hw);
2174169240Sjfv
2175173788Sjfv	/*
2176173788Sjfv	 * Reload the EEPROM, or else modifications will not appear
2177169240Sjfv	 * until after the next adapter reset.
2178169240Sjfv	 */
2179203049Sjfv	if (!ret_val) {
2180203049Sjfv		nvm->ops.reload(hw);
2181203049Sjfv		msec_delay(10);
2182203049Sjfv	}
2183169240Sjfv
2184169240Sjfvout:
2185190872Sjfv	if (ret_val)
2186190872Sjfv		DEBUGOUT1("NVM update error: %d\n", ret_val);
2187190872Sjfv
2188169240Sjfv	return ret_val;
2189169240Sjfv}
2190169240Sjfv
2191169240Sjfv/**
2192169240Sjfv *  e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
2193169589Sjfv *  @hw: pointer to the HW structure
2194169240Sjfv *
2195169240Sjfv *  Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
2196185353Sjfv *  If the bit is 0, that the EEPROM had been modified, but the checksum was not
2197185353Sjfv *  calculated, in which case we need to calculate the checksum and set bit 6.
2198169240Sjfv **/
2199177867Sjfvstatic s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
2200169240Sjfv{
2201169240Sjfv	s32 ret_val = E1000_SUCCESS;
2202169240Sjfv	u16 data;
2203169240Sjfv
2204169240Sjfv	DEBUGFUNC("e1000_validate_nvm_checksum_ich8lan");
2205169240Sjfv
2206173788Sjfv	/*
2207173788Sjfv	 * Read 0x19 and check bit 6.  If this bit is 0, the checksum
2208169240Sjfv	 * needs to be fixed.  This bit is an indication that the NVM
2209169240Sjfv	 * was prepared by OEM software and did not calculate the
2210169240Sjfv	 * checksum...a likely scenario.
2211169240Sjfv	 */
2212177867Sjfv	ret_val = hw->nvm.ops.read(hw, 0x19, 1, &data);
2213169240Sjfv	if (ret_val)
2214169240Sjfv		goto out;
2215169240Sjfv
2216169240Sjfv	if ((data & 0x40) == 0) {
2217169240Sjfv		data |= 0x40;
2218177867Sjfv		ret_val = hw->nvm.ops.write(hw, 0x19, 1, &data);
2219169240Sjfv		if (ret_val)
2220169240Sjfv			goto out;
2221177867Sjfv		ret_val = hw->nvm.ops.update(hw);
2222169240Sjfv		if (ret_val)
2223169240Sjfv			goto out;
2224169240Sjfv	}
2225169240Sjfv
2226169240Sjfv	ret_val = e1000_validate_nvm_checksum_generic(hw);
2227169240Sjfv
2228169240Sjfvout:
2229169240Sjfv	return ret_val;
2230169240Sjfv}
2231169240Sjfv
2232169240Sjfv/**
2233169240Sjfv *  e1000_write_flash_data_ich8lan - Writes bytes to the NVM
2234169589Sjfv *  @hw: pointer to the HW structure
2235169589Sjfv *  @offset: The offset (in bytes) of the byte/word to read.
2236169589Sjfv *  @size: Size of data to read, 1=byte 2=word
2237169589Sjfv *  @data: The byte(s) to write to the NVM.
2238169240Sjfv *
2239169240Sjfv *  Writes one/two bytes to the NVM using the flash access registers.
2240169240Sjfv **/
2241173788Sjfvstatic s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
2242173788Sjfv                                          u8 size, u16 data)
2243169240Sjfv{
2244169240Sjfv	union ich8_hws_flash_status hsfsts;
2245169240Sjfv	union ich8_hws_flash_ctrl hsflctl;
2246169240Sjfv	u32 flash_linear_addr;
2247169240Sjfv	u32 flash_data = 0;
2248169240Sjfv	s32 ret_val = -E1000_ERR_NVM;
2249169240Sjfv	u8 count = 0;
2250169240Sjfv
2251169240Sjfv	DEBUGFUNC("e1000_write_ich8_data");
2252169240Sjfv
2253169240Sjfv	if (size < 1 || size > 2 || data > size * 0xff ||
2254169240Sjfv	    offset > ICH_FLASH_LINEAR_ADDR_MASK)
2255169240Sjfv		goto out;
2256169240Sjfv
2257169240Sjfv	flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
2258169240Sjfv	                    hw->nvm.flash_base_addr;
2259169240Sjfv
2260169240Sjfv	do {
2261169240Sjfv		usec_delay(1);
2262169240Sjfv		/* Steps */
2263169240Sjfv		ret_val = e1000_flash_cycle_init_ich8lan(hw);
2264169240Sjfv		if (ret_val != E1000_SUCCESS)
2265169240Sjfv			break;
2266169240Sjfv
2267169240Sjfv		hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
2268169240Sjfv		/* 0b/1b corresponds to 1 or 2 byte size, respectively. */
2269185353Sjfv		hsflctl.hsf_ctrl.fldbcount = size - 1;
2270169240Sjfv		hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
2271169240Sjfv		E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
2272169240Sjfv
2273169240Sjfv		E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
2274169240Sjfv
2275169240Sjfv		if (size == 1)
2276169240Sjfv			flash_data = (u32)data & 0x00FF;
2277169240Sjfv		else
2278169240Sjfv			flash_data = (u32)data;
2279169240Sjfv
2280169240Sjfv		E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
2281169240Sjfv
2282173788Sjfv		/*
2283173788Sjfv		 * check if FCERR is set to 1 , if set to 1, clear it
2284173788Sjfv		 * and try the whole sequence a few more times else done
2285173788Sjfv		 */
2286169240Sjfv		ret_val = e1000_flash_cycle_ich8lan(hw,
2287169240Sjfv		                               ICH_FLASH_WRITE_COMMAND_TIMEOUT);
2288185353Sjfv		if (ret_val == E1000_SUCCESS)
2289169240Sjfv			break;
2290185353Sjfv
2291185353Sjfv		/*
2292185353Sjfv		 * If we're here, then things are most likely
2293185353Sjfv		 * completely hosed, but if the error condition
2294185353Sjfv		 * is detected, it won't hurt to give it another
2295185353Sjfv		 * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
2296185353Sjfv		 */
2297185353Sjfv		hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
2298200243Sjfv		if (hsfsts.hsf_status.flcerr == 1)
2299185353Sjfv			/* Repeat for some time before giving up. */
2300185353Sjfv			continue;
2301200243Sjfv		if (hsfsts.hsf_status.flcdone == 0) {
2302185353Sjfv			DEBUGOUT("Timeout error - flash cycle "
2303185353Sjfv				 "did not complete.");
2304185353Sjfv			break;
2305169240Sjfv		}
2306169240Sjfv	} while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
2307169240Sjfv
2308169240Sjfvout:
2309169240Sjfv	return ret_val;
2310169240Sjfv}
2311169240Sjfv
2312169240Sjfv/**
2313169240Sjfv *  e1000_write_flash_byte_ich8lan - Write a single byte to NVM
2314169589Sjfv *  @hw: pointer to the HW structure
2315169589Sjfv *  @offset: The index of the byte to read.
2316169589Sjfv *  @data: The byte to write to the NVM.
2317169240Sjfv *
2318169240Sjfv *  Writes a single byte to the NVM using the flash access registers.
2319169240Sjfv **/
2320177867Sjfvstatic s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
2321173788Sjfv                                          u8 data)
2322169240Sjfv{
2323169240Sjfv	u16 word = (u16)data;
2324169240Sjfv
2325169240Sjfv	DEBUGFUNC("e1000_write_flash_byte_ich8lan");
2326169240Sjfv
2327169240Sjfv	return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
2328169240Sjfv}
2329169240Sjfv
2330169240Sjfv/**
2331169240Sjfv *  e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
2332169589Sjfv *  @hw: pointer to the HW structure
2333169589Sjfv *  @offset: The offset of the byte to write.
2334169589Sjfv *  @byte: The byte to write to the NVM.
2335169240Sjfv *
2336169240Sjfv *  Writes a single byte to the NVM using the flash access registers.
2337169240Sjfv *  Goes through a retry algorithm before giving up.
2338169240Sjfv **/
2339176667Sjfvstatic s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
2340176667Sjfv                                                u32 offset, u8 byte)
2341169240Sjfv{
2342169240Sjfv	s32 ret_val;
2343169240Sjfv	u16 program_retries;
2344169240Sjfv
2345169240Sjfv	DEBUGFUNC("e1000_retry_write_flash_byte_ich8lan");
2346169240Sjfv
2347169240Sjfv	ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2348173788Sjfv	if (ret_val == E1000_SUCCESS)
2349169240Sjfv		goto out;
2350169240Sjfv
2351169240Sjfv	for (program_retries = 0; program_retries < 100; program_retries++) {
2352169240Sjfv		DEBUGOUT2("Retrying Byte %2.2X at offset %u\n", byte, offset);
2353169240Sjfv		usec_delay(100);
2354169240Sjfv		ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
2355169240Sjfv		if (ret_val == E1000_SUCCESS)
2356169240Sjfv			break;
2357169240Sjfv	}
2358169240Sjfv	if (program_retries == 100) {
2359169240Sjfv		ret_val = -E1000_ERR_NVM;
2360169240Sjfv		goto out;
2361169240Sjfv	}
2362169240Sjfv
2363169240Sjfvout:
2364169240Sjfv	return ret_val;
2365169240Sjfv}
2366169240Sjfv
2367169240Sjfv/**
2368169240Sjfv *  e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
2369169589Sjfv *  @hw: pointer to the HW structure
2370169589Sjfv *  @bank: 0 for first bank, 1 for second bank, etc.
2371169240Sjfv *
2372169240Sjfv *  Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
2373169240Sjfv *  bank N is 4096 * N + flash_reg_addr.
2374169240Sjfv **/
2375177867Sjfvstatic s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
2376169240Sjfv{
2377169240Sjfv	struct e1000_nvm_info *nvm = &hw->nvm;
2378169240Sjfv	union ich8_hws_flash_status hsfsts;
2379169240Sjfv	union ich8_hws_flash_ctrl hsflctl;
2380169240Sjfv	u32 flash_linear_addr;
2381173788Sjfv	/* bank size is in 16bit words - adjust to bytes */
2382173788Sjfv	u32 flash_bank_size = nvm->flash_bank_size * 2;
2383185353Sjfv	s32 ret_val = E1000_SUCCESS;
2384185353Sjfv	s32 count = 0;
2385185353Sjfv	s32 j, iteration, sector_size;
2386169240Sjfv
2387169240Sjfv	DEBUGFUNC("e1000_erase_flash_bank_ich8lan");
2388169240Sjfv
2389169240Sjfv	hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
2390169240Sjfv
2391173788Sjfv	/*
2392173788Sjfv	 * Determine HW Sector size: Read BERASE bits of hw flash status
2393173788Sjfv	 * register
2394173788Sjfv	 * 00: The Hw sector is 256 bytes, hence we need to erase 16
2395169240Sjfv	 *     consecutive sectors.  The start index for the nth Hw sector
2396169240Sjfv	 *     can be calculated as = bank * 4096 + n * 256
2397169240Sjfv	 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
2398169240Sjfv	 *     The start index for the nth Hw sector can be calculated
2399169240Sjfv	 *     as = bank * 4096
2400169240Sjfv	 * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
2401169240Sjfv	 *     (ich9 only, otherwise error condition)
2402169240Sjfv	 * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
2403169240Sjfv	 */
2404169240Sjfv	switch (hsfsts.hsf_status.berasesz) {
2405169240Sjfv	case 0:
2406169240Sjfv		/* Hw sector size 256 */
2407169240Sjfv		sector_size = ICH_FLASH_SEG_SIZE_256;
2408169240Sjfv		iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
2409169240Sjfv		break;
2410169240Sjfv	case 1:
2411169240Sjfv		sector_size = ICH_FLASH_SEG_SIZE_4K;
2412194865Sjfv		iteration = 1;
2413169240Sjfv		break;
2414169240Sjfv	case 2:
2415195850Sjfv		sector_size = ICH_FLASH_SEG_SIZE_8K;
2416195850Sjfv		iteration = 1;
2417169240Sjfv		break;
2418169240Sjfv	case 3:
2419169240Sjfv		sector_size = ICH_FLASH_SEG_SIZE_64K;
2420194865Sjfv		iteration = 1;
2421169240Sjfv		break;
2422169240Sjfv	default:
2423169240Sjfv		ret_val = -E1000_ERR_NVM;
2424169240Sjfv		goto out;
2425169240Sjfv	}
2426169240Sjfv
2427169240Sjfv	/* Start with the base address, then add the sector offset. */
2428169240Sjfv	flash_linear_addr = hw->nvm.flash_base_addr;
2429200243Sjfv	flash_linear_addr += (bank) ? flash_bank_size : 0;
2430169240Sjfv
2431169240Sjfv	for (j = 0; j < iteration ; j++) {
2432169240Sjfv		do {
2433169240Sjfv			/* Steps */
2434169240Sjfv			ret_val = e1000_flash_cycle_init_ich8lan(hw);
2435169240Sjfv			if (ret_val)
2436169240Sjfv				goto out;
2437169240Sjfv
2438173788Sjfv			/*
2439173788Sjfv			 * Write a value 11 (block Erase) in Flash
2440173788Sjfv			 * Cycle field in hw flash control
2441173788Sjfv			 */
2442169240Sjfv			hsflctl.regval = E1000_READ_FLASH_REG16(hw,
2443169240Sjfv			                                      ICH_FLASH_HSFCTL);
2444169240Sjfv			hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
2445185353Sjfv			E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL,
2446169240Sjfv			                        hsflctl.regval);
2447169240Sjfv
2448173788Sjfv			/*
2449173788Sjfv			 * Write the last 24 bits of an index within the
2450169240Sjfv			 * block into Flash Linear address field in Flash
2451169240Sjfv			 * Address.
2452169240Sjfv			 */
2453169240Sjfv			flash_linear_addr += (j * sector_size);
2454185353Sjfv			E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR,
2455169240Sjfv			                      flash_linear_addr);
2456169240Sjfv
2457169240Sjfv			ret_val = e1000_flash_cycle_ich8lan(hw,
2458169240Sjfv			                       ICH_FLASH_ERASE_COMMAND_TIMEOUT);
2459185353Sjfv			if (ret_val == E1000_SUCCESS)
2460169240Sjfv				break;
2461185353Sjfv
2462185353Sjfv			/*
2463185353Sjfv			 * Check if FCERR is set to 1.  If 1,
2464185353Sjfv			 * clear it and try the whole sequence
2465185353Sjfv			 * a few more times else Done
2466185353Sjfv			 */
2467185353Sjfv			hsfsts.regval = E1000_READ_FLASH_REG16(hw,
2468185353Sjfv						      ICH_FLASH_HSFSTS);
2469185353Sjfv			if (hsfsts.hsf_status.flcerr == 1)
2470185353Sjfv				/* repeat for some time before giving up */
2471185353Sjfv				continue;
2472185353Sjfv			else if (hsfsts.hsf_status.flcdone == 0)
2473185353Sjfv				goto out;
2474169240Sjfv		} while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
2475169240Sjfv	}
2476169240Sjfv
2477169240Sjfvout:
2478169240Sjfv	return ret_val;
2479169240Sjfv}
2480169240Sjfv
2481169240Sjfv/**
2482169240Sjfv *  e1000_valid_led_default_ich8lan - Set the default LED settings
2483169589Sjfv *  @hw: pointer to the HW structure
2484169589Sjfv *  @data: Pointer to the LED settings
2485169240Sjfv *
2486169240Sjfv *  Reads the LED default settings from the NVM to data.  If the NVM LED
2487169240Sjfv *  settings is all 0's or F's, set the LED default to a valid LED default
2488169240Sjfv *  setting.
2489169240Sjfv **/
2490177867Sjfvstatic s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
2491169240Sjfv{
2492169240Sjfv	s32 ret_val;
2493169240Sjfv
2494169240Sjfv	DEBUGFUNC("e1000_valid_led_default_ich8lan");
2495169240Sjfv
2496177867Sjfv	ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
2497169240Sjfv	if (ret_val) {
2498169240Sjfv		DEBUGOUT("NVM Read Error\n");
2499169240Sjfv		goto out;
2500169240Sjfv	}
2501169240Sjfv
2502169240Sjfv	if (*data == ID_LED_RESERVED_0000 ||
2503169240Sjfv	    *data == ID_LED_RESERVED_FFFF)
2504169240Sjfv		*data = ID_LED_DEFAULT_ICH8LAN;
2505169240Sjfv
2506169240Sjfvout:
2507169240Sjfv	return ret_val;
2508169240Sjfv}
2509169240Sjfv
2510169240Sjfv/**
2511194865Sjfv *  e1000_id_led_init_pchlan - store LED configurations
2512194865Sjfv *  @hw: pointer to the HW structure
2513194865Sjfv *
2514194865Sjfv *  PCH does not control LEDs via the LEDCTL register, rather it uses
2515194865Sjfv *  the PHY LED configuration register.
2516194865Sjfv *
2517194865Sjfv *  PCH also does not have an "always on" or "always off" mode which
2518194865Sjfv *  complicates the ID feature.  Instead of using the "on" mode to indicate
2519194865Sjfv *  in ledctl_mode2 the LEDs to use for ID (see e1000_id_led_init_generic()),
2520194865Sjfv *  use "link_up" mode.  The LEDs will still ID on request if there is no
2521194865Sjfv *  link based on logic in e1000_led_[on|off]_pchlan().
2522194865Sjfv **/
2523194865Sjfvstatic s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
2524194865Sjfv{
2525194865Sjfv	struct e1000_mac_info *mac = &hw->mac;
2526194865Sjfv	s32 ret_val;
2527194865Sjfv	const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
2528194865Sjfv	const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
2529194865Sjfv	u16 data, i, temp, shift;
2530194865Sjfv
2531194865Sjfv	DEBUGFUNC("e1000_id_led_init_pchlan");
2532194865Sjfv
2533194865Sjfv	/* Get default ID LED modes */
2534194865Sjfv	ret_val = hw->nvm.ops.valid_led_default(hw, &data);
2535194865Sjfv	if (ret_val)
2536194865Sjfv		goto out;
2537194865Sjfv
2538194865Sjfv	mac->ledctl_default = E1000_READ_REG(hw, E1000_LEDCTL);
2539194865Sjfv	mac->ledctl_mode1 = mac->ledctl_default;
2540194865Sjfv	mac->ledctl_mode2 = mac->ledctl_default;
2541194865Sjfv
2542194865Sjfv	for (i = 0; i < 4; i++) {
2543194865Sjfv		temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
2544194865Sjfv		shift = (i * 5);
2545194865Sjfv		switch (temp) {
2546194865Sjfv		case ID_LED_ON1_DEF2:
2547194865Sjfv		case ID_LED_ON1_ON2:
2548194865Sjfv		case ID_LED_ON1_OFF2:
2549194865Sjfv			mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2550194865Sjfv			mac->ledctl_mode1 |= (ledctl_on << shift);
2551194865Sjfv			break;
2552194865Sjfv		case ID_LED_OFF1_DEF2:
2553194865Sjfv		case ID_LED_OFF1_ON2:
2554194865Sjfv		case ID_LED_OFF1_OFF2:
2555194865Sjfv			mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
2556194865Sjfv			mac->ledctl_mode1 |= (ledctl_off << shift);
2557194865Sjfv			break;
2558194865Sjfv		default:
2559194865Sjfv			/* Do nothing */
2560194865Sjfv			break;
2561194865Sjfv		}
2562194865Sjfv		switch (temp) {
2563194865Sjfv		case ID_LED_DEF1_ON2:
2564194865Sjfv		case ID_LED_ON1_ON2:
2565194865Sjfv		case ID_LED_OFF1_ON2:
2566194865Sjfv			mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2567194865Sjfv			mac->ledctl_mode2 |= (ledctl_on << shift);
2568194865Sjfv			break;
2569194865Sjfv		case ID_LED_DEF1_OFF2:
2570194865Sjfv		case ID_LED_ON1_OFF2:
2571194865Sjfv		case ID_LED_OFF1_OFF2:
2572194865Sjfv			mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
2573194865Sjfv			mac->ledctl_mode2 |= (ledctl_off << shift);
2574194865Sjfv			break;
2575194865Sjfv		default:
2576194865Sjfv			/* Do nothing */
2577194865Sjfv			break;
2578194865Sjfv		}
2579194865Sjfv	}
2580194865Sjfv
2581194865Sjfvout:
2582194865Sjfv	return ret_val;
2583194865Sjfv}
2584194865Sjfv
2585194865Sjfv/**
2586169240Sjfv *  e1000_get_bus_info_ich8lan - Get/Set the bus type and width
2587169589Sjfv *  @hw: pointer to the HW structure
2588169240Sjfv *
2589169240Sjfv *  ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
2590169240Sjfv *  register, so the the bus width is hard coded.
2591169240Sjfv **/
2592177867Sjfvstatic s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
2593169240Sjfv{
2594169240Sjfv	struct e1000_bus_info *bus = &hw->bus;
2595169240Sjfv	s32 ret_val;
2596169240Sjfv
2597169240Sjfv	DEBUGFUNC("e1000_get_bus_info_ich8lan");
2598169240Sjfv
2599169240Sjfv	ret_val = e1000_get_bus_info_pcie_generic(hw);
2600169240Sjfv
2601173788Sjfv	/*
2602173788Sjfv	 * ICH devices are "PCI Express"-ish.  They have
2603169240Sjfv	 * a configuration space, but do not contain
2604169240Sjfv	 * PCI Express Capability registers, so bus width
2605169240Sjfv	 * must be hardcoded.
2606169240Sjfv	 */
2607169240Sjfv	if (bus->width == e1000_bus_width_unknown)
2608169240Sjfv		bus->width = e1000_bus_width_pcie_x1;
2609169240Sjfv
2610169240Sjfv	return ret_val;
2611169240Sjfv}
2612169240Sjfv
2613169240Sjfv/**
2614169240Sjfv *  e1000_reset_hw_ich8lan - Reset the hardware
2615169589Sjfv *  @hw: pointer to the HW structure
2616169240Sjfv *
2617169240Sjfv *  Does a full reset of the hardware which includes a reset of the PHY and
2618169240Sjfv *  MAC.
2619169240Sjfv **/
2620177867Sjfvstatic s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2621169240Sjfv{
2622200243Sjfv	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
2623200243Sjfv	u16 reg;
2624169240Sjfv	u32 ctrl, icr, kab;
2625169240Sjfv	s32 ret_val;
2626169240Sjfv
2627169240Sjfv	DEBUGFUNC("e1000_reset_hw_ich8lan");
2628169240Sjfv
2629173788Sjfv	/*
2630173788Sjfv	 * Prevent the PCI-E bus from sticking if there is no TLP connection
2631169240Sjfv	 * on the last TLP read/write transaction when MAC is reset.
2632169240Sjfv	 */
2633169240Sjfv	ret_val = e1000_disable_pcie_master_generic(hw);
2634185353Sjfv	if (ret_val)
2635169240Sjfv		DEBUGOUT("PCI-E Master disable polling has failed.\n");
2636169240Sjfv
2637169240Sjfv	DEBUGOUT("Masking off all interrupts\n");
2638169240Sjfv	E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2639169240Sjfv
2640173788Sjfv	/*
2641173788Sjfv	 * Disable the Transmit and Receive units.  Then delay to allow
2642169240Sjfv	 * any pending transactions to complete before we hit the MAC
2643169240Sjfv	 * with the global reset.
2644169240Sjfv	 */
2645169240Sjfv	E1000_WRITE_REG(hw, E1000_RCTL, 0);
2646169240Sjfv	E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
2647169240Sjfv	E1000_WRITE_FLUSH(hw);
2648169240Sjfv
2649169240Sjfv	msec_delay(10);
2650169240Sjfv
2651169240Sjfv	/* Workaround for ICH8 bit corruption issue in FIFO memory */
2652169240Sjfv	if (hw->mac.type == e1000_ich8lan) {
2653169240Sjfv		/* Set Tx and Rx buffer allocation to 8k apiece. */
2654169240Sjfv		E1000_WRITE_REG(hw, E1000_PBA, E1000_PBA_8K);
2655169240Sjfv		/* Set Packet Buffer Size to 16k. */
2656169240Sjfv		E1000_WRITE_REG(hw, E1000_PBS, E1000_PBS_16K);
2657169240Sjfv	}
2658169240Sjfv
2659200243Sjfv	if (hw->mac.type == e1000_pchlan) {
2660200243Sjfv		/* Save the NVM K1 bit setting*/
2661200243Sjfv		ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &reg);
2662200243Sjfv		if (ret_val)
2663200243Sjfv			return ret_val;
2664200243Sjfv
2665200243Sjfv		if (reg & E1000_NVM_K1_ENABLE)
2666200243Sjfv			dev_spec->nvm_k1_enabled = TRUE;
2667200243Sjfv		else
2668200243Sjfv			dev_spec->nvm_k1_enabled = FALSE;
2669200243Sjfv	}
2670200243Sjfv
2671169240Sjfv	ctrl = E1000_READ_REG(hw, E1000_CTRL);
2672169240Sjfv
2673177867Sjfv	if (!hw->phy.ops.check_reset_block(hw) && !hw->phy.reset_disable) {
2674194865Sjfv		/* Clear PHY Reset Asserted bit */
2675194865Sjfv		if (hw->mac.type >= e1000_pchlan) {
2676194865Sjfv			u32 status = E1000_READ_REG(hw, E1000_STATUS);
2677194865Sjfv			E1000_WRITE_REG(hw, E1000_STATUS, status &
2678194865Sjfv			                ~E1000_STATUS_PHYRA);
2679194865Sjfv		}
2680194865Sjfv
2681173788Sjfv		/*
2682173788Sjfv		 * PHY HW reset requires MAC CORE reset at the same
2683169240Sjfv		 * time to make sure the interface between MAC and the
2684169240Sjfv		 * external PHY is reset.
2685169240Sjfv		 */
2686169240Sjfv		ctrl |= E1000_CTRL_PHY_RST;
2687169240Sjfv	}
2688169240Sjfv	ret_val = e1000_acquire_swflag_ich8lan(hw);
2689185353Sjfv	DEBUGOUT("Issuing a global reset to ich8lan\n");
2690169240Sjfv	E1000_WRITE_REG(hw, E1000_CTRL, (ctrl | E1000_CTRL_RST));
2691169240Sjfv	msec_delay(20);
2692169240Sjfv
2693194865Sjfv	if (!ret_val)
2694194865Sjfv		e1000_release_swflag_ich8lan(hw);
2695194865Sjfv
2696203049Sjfv	/* Perform any necessary post-reset workarounds */
2697203049Sjfv	switch (hw->mac.type) {
2698203049Sjfv	case e1000_pchlan:
2699203049Sjfv		ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
2700203049Sjfv		if (ret_val)
2701203049Sjfv			goto out;
2702203049Sjfv		break;
2703203049Sjfv	default:
2704203049Sjfv		break;
2705203049Sjfv	}
2706203049Sjfv
2707194865Sjfv	if (ctrl & E1000_CTRL_PHY_RST)
2708194865Sjfv		ret_val = hw->phy.ops.get_cfg_done(hw);
2709194865Sjfv
2710194865Sjfv	if (hw->mac.type >= e1000_ich10lan) {
2711194865Sjfv		e1000_lan_init_done_ich8lan(hw);
2712194865Sjfv	} else {
2713194865Sjfv		ret_val = e1000_get_auto_rd_done_generic(hw);
2714194865Sjfv		if (ret_val) {
2715194865Sjfv			/*
2716194865Sjfv			 * When auto config read does not complete, do not
2717194865Sjfv			 * return with an error. This can happen in situations
2718194865Sjfv			 * where there is no eeprom and prevents getting link.
2719194865Sjfv			 */
2720194865Sjfv			DEBUGOUT("Auto Read Done did not complete\n");
2721194865Sjfv		}
2722169240Sjfv	}
2723205869Sjfv	/* Dummy read to clear the phy wakeup bit after lcd reset */
2724200243Sjfv	if (hw->mac.type == e1000_pchlan)
2725200243Sjfv		hw->phy.ops.read_reg(hw, BM_WUC, &reg);
2726169240Sjfv
2727200243Sjfv	ret_val = e1000_sw_lcd_config_ich8lan(hw);
2728200243Sjfv	if (ret_val)
2729200243Sjfv		goto out;
2730200243Sjfv
2731203049Sjfv	ret_val = e1000_oem_bits_config_ich8lan(hw, TRUE);
2732203049Sjfv	if (ret_val)
2733203049Sjfv		goto out;
2734200243Sjfv	/*
2735200243Sjfv	 * For PCH, this write will make sure that any noise
2736200243Sjfv	 * will be detected as a CRC error and be dropped rather than show up
2737200243Sjfv	 * as a bad packet to the DMA engine.
2738200243Sjfv	 */
2739200243Sjfv	if (hw->mac.type == e1000_pchlan)
2740200243Sjfv		E1000_WRITE_REG(hw, E1000_CRC_OFFSET, 0x65656565);
2741200243Sjfv
2742169240Sjfv	E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
2743169240Sjfv	icr = E1000_READ_REG(hw, E1000_ICR);
2744169240Sjfv
2745169240Sjfv	kab = E1000_READ_REG(hw, E1000_KABGTXD);
2746169240Sjfv	kab |= E1000_KABGTXD_BGSQLBIAS;
2747169240Sjfv	E1000_WRITE_REG(hw, E1000_KABGTXD, kab);
2748169240Sjfv
2749200243Sjfvout:
2750169240Sjfv	return ret_val;
2751169240Sjfv}
2752169240Sjfv
2753169240Sjfv/**
2754169240Sjfv *  e1000_init_hw_ich8lan - Initialize the hardware
2755169589Sjfv *  @hw: pointer to the HW structure
2756169240Sjfv *
2757169240Sjfv *  Prepares the hardware for transmit and receive by doing the following:
2758169240Sjfv *   - initialize hardware bits
2759169240Sjfv *   - initialize LED identification
2760169240Sjfv *   - setup receive address registers
2761169240Sjfv *   - setup flow control
2762176667Sjfv *   - setup transmit descriptors
2763169240Sjfv *   - clear statistics
2764169240Sjfv **/
2765177867Sjfvstatic s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
2766169240Sjfv{
2767169240Sjfv	struct e1000_mac_info *mac = &hw->mac;
2768169240Sjfv	u32 ctrl_ext, txdctl, snoop;
2769169240Sjfv	s32 ret_val;
2770169240Sjfv	u16 i;
2771169240Sjfv
2772169240Sjfv	DEBUGFUNC("e1000_init_hw_ich8lan");
2773169240Sjfv
2774169240Sjfv	e1000_initialize_hw_bits_ich8lan(hw);
2775169240Sjfv
2776169240Sjfv	/* Initialize identification LED */
2777190872Sjfv	ret_val = mac->ops.id_led_init(hw);
2778190872Sjfv	if (ret_val)
2779200243Sjfv		DEBUGOUT("Error initializing identification LED\n");
2780190872Sjfv		/* This is not fatal and we should not stop init due to this */
2781169240Sjfv
2782169240Sjfv	/* Setup the receive address. */
2783169240Sjfv	e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
2784169240Sjfv
2785169240Sjfv	/* Zero out the Multicast HASH table */
2786169240Sjfv	DEBUGOUT("Zeroing the MTA\n");
2787169240Sjfv	for (i = 0; i < mac->mta_reg_count; i++)
2788169240Sjfv		E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
2789169240Sjfv
2790194865Sjfv	/*
2791194865Sjfv	 * The 82578 Rx buffer will stall if wakeup is enabled in host and
2792194865Sjfv	 * the ME.  Reading the BM_WUC register will clear the host wakeup bit.
2793194865Sjfv	 * Reset the phy after disabling host wakeup to reset the Rx buffer.
2794194865Sjfv	 */
2795194865Sjfv	if (hw->phy.type == e1000_phy_82578) {
2796194865Sjfv		hw->phy.ops.read_reg(hw, BM_WUC, &i);
2797194865Sjfv		ret_val = e1000_phy_hw_reset_ich8lan(hw);
2798194865Sjfv		if (ret_val)
2799194865Sjfv			return ret_val;
2800194865Sjfv	}
2801194865Sjfv
2802169240Sjfv	/* Setup link and flow control */
2803177867Sjfv	ret_val = mac->ops.setup_link(hw);
2804169240Sjfv
2805169240Sjfv	/* Set the transmit descriptor write-back policy for both queues */
2806173788Sjfv	txdctl = E1000_READ_REG(hw, E1000_TXDCTL(0));
2807169240Sjfv	txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2808169240Sjfv		 E1000_TXDCTL_FULL_TX_DESC_WB;
2809169240Sjfv	txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2810169240Sjfv	         E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
2811173788Sjfv	E1000_WRITE_REG(hw, E1000_TXDCTL(0), txdctl);
2812173788Sjfv	txdctl = E1000_READ_REG(hw, E1000_TXDCTL(1));
2813169240Sjfv	txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
2814169240Sjfv		 E1000_TXDCTL_FULL_TX_DESC_WB;
2815169240Sjfv	txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
2816169240Sjfv	         E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
2817173788Sjfv	E1000_WRITE_REG(hw, E1000_TXDCTL(1), txdctl);
2818169240Sjfv
2819173788Sjfv	/*
2820173788Sjfv	 * ICH8 has opposite polarity of no_snoop bits.
2821173788Sjfv	 * By default, we should use snoop behavior.
2822173788Sjfv	 */
2823169240Sjfv	if (mac->type == e1000_ich8lan)
2824169240Sjfv		snoop = PCIE_ICH8_SNOOP_ALL;
2825169240Sjfv	else
2826200243Sjfv		snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
2827169240Sjfv	e1000_set_pcie_no_snoop_generic(hw, snoop);
2828169240Sjfv
2829169240Sjfv	ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2830169240Sjfv	ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2831169240Sjfv	E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
2832169240Sjfv
2833173788Sjfv	/*
2834173788Sjfv	 * Clear all of the statistics registers (clear on read).  It is
2835169240Sjfv	 * important that we do this after we have tried to establish link
2836169240Sjfv	 * because the symbol error count will increment wildly if there
2837169240Sjfv	 * is no link.
2838169240Sjfv	 */
2839169240Sjfv	e1000_clear_hw_cntrs_ich8lan(hw);
2840169240Sjfv
2841169240Sjfv	return ret_val;
2842169240Sjfv}
2843169240Sjfv/**
2844169240Sjfv *  e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
2845169589Sjfv *  @hw: pointer to the HW structure
2846169240Sjfv *
2847169240Sjfv *  Sets/Clears required hardware bits necessary for correctly setting up the
2848169240Sjfv *  hardware for transmit and receive.
2849169240Sjfv **/
2850173788Sjfvstatic void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
2851169240Sjfv{
2852169240Sjfv	u32 reg;
2853169240Sjfv
2854169240Sjfv	DEBUGFUNC("e1000_initialize_hw_bits_ich8lan");
2855169240Sjfv
2856169240Sjfv	/* Extended Device Control */
2857169240Sjfv	reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2858169240Sjfv	reg |= (1 << 22);
2859194865Sjfv	/* Enable PHY low-power state when MAC is at D3 w/o WoL */
2860194865Sjfv	if (hw->mac.type >= e1000_pchlan)
2861194865Sjfv		reg |= E1000_CTRL_EXT_PHYPDEN;
2862169240Sjfv	E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2863169240Sjfv
2864169240Sjfv	/* Transmit Descriptor Control 0 */
2865173788Sjfv	reg = E1000_READ_REG(hw, E1000_TXDCTL(0));
2866169240Sjfv	reg |= (1 << 22);
2867173788Sjfv	E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg);
2868169240Sjfv
2869169240Sjfv	/* Transmit Descriptor Control 1 */
2870173788Sjfv	reg = E1000_READ_REG(hw, E1000_TXDCTL(1));
2871169240Sjfv	reg |= (1 << 22);
2872173788Sjfv	E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg);
2873169240Sjfv
2874169240Sjfv	/* Transmit Arbitration Control 0 */
2875173788Sjfv	reg = E1000_READ_REG(hw, E1000_TARC(0));
2876169240Sjfv	if (hw->mac.type == e1000_ich8lan)
2877169240Sjfv		reg |= (1 << 28) | (1 << 29);
2878169240Sjfv	reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
2879173788Sjfv	E1000_WRITE_REG(hw, E1000_TARC(0), reg);
2880169240Sjfv
2881169240Sjfv	/* Transmit Arbitration Control 1 */
2882173788Sjfv	reg = E1000_READ_REG(hw, E1000_TARC(1));
2883169240Sjfv	if (E1000_READ_REG(hw, E1000_TCTL) & E1000_TCTL_MULR)
2884169240Sjfv		reg &= ~(1 << 28);
2885169240Sjfv	else
2886169240Sjfv		reg |= (1 << 28);
2887169240Sjfv	reg |= (1 << 24) | (1 << 26) | (1 << 30);
2888173788Sjfv	E1000_WRITE_REG(hw, E1000_TARC(1), reg);
2889169240Sjfv
2890169240Sjfv	/* Device Status */
2891169240Sjfv	if (hw->mac.type == e1000_ich8lan) {
2892169240Sjfv		reg = E1000_READ_REG(hw, E1000_STATUS);
2893169240Sjfv		reg &= ~(1 << 31);
2894169240Sjfv		E1000_WRITE_REG(hw, E1000_STATUS, reg);
2895169240Sjfv	}
2896169240Sjfv
2897205869Sjfv	/*
2898205869Sjfv	 * work-around descriptor data corruption issue during nfs v2 udp
2899205869Sjfv	 * traffic, just disable the nfs filtering capability
2900205869Sjfv	 */
2901205869Sjfv	reg = E1000_READ_REG(hw, E1000_RFCTL);
2902205869Sjfv	reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
2903205869Sjfv	E1000_WRITE_REG(hw, E1000_RFCTL, reg);
2904205869Sjfv
2905169240Sjfv	return;
2906169240Sjfv}
2907169240Sjfv
2908169240Sjfv/**
2909169240Sjfv *  e1000_setup_link_ich8lan - Setup flow control and link settings
2910169589Sjfv *  @hw: pointer to the HW structure
2911169240Sjfv *
2912169240Sjfv *  Determines which flow control settings to use, then configures flow
2913169240Sjfv *  control.  Calls the appropriate media-specific link configuration
2914169240Sjfv *  function.  Assuming the adapter has a valid link partner, a valid link
2915169240Sjfv *  should be established.  Assumes the hardware has previously been reset
2916169240Sjfv *  and the transmitter and receiver are not enabled.
2917169240Sjfv **/
2918177867Sjfvstatic s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
2919169240Sjfv{
2920169240Sjfv	s32 ret_val = E1000_SUCCESS;
2921169240Sjfv
2922169240Sjfv	DEBUGFUNC("e1000_setup_link_ich8lan");
2923169240Sjfv
2924177867Sjfv	if (hw->phy.ops.check_reset_block(hw))
2925169240Sjfv		goto out;
2926169240Sjfv
2927173788Sjfv	/*
2928173788Sjfv	 * ICH parts do not have a word in the NVM to determine
2929169240Sjfv	 * the default flow control setting, so we explicitly
2930169240Sjfv	 * set it to full.
2931169240Sjfv	 */
2932185353Sjfv	if (hw->fc.requested_mode == e1000_fc_default)
2933185353Sjfv		hw->fc.requested_mode = e1000_fc_full;
2934169240Sjfv
2935185353Sjfv	/*
2936185353Sjfv	 * Save off the requested flow control mode for use later.  Depending
2937185353Sjfv	 * on the link partner's capabilities, we may or may not use this mode.
2938185353Sjfv	 */
2939185353Sjfv	hw->fc.current_mode = hw->fc.requested_mode;
2940169240Sjfv
2941185353Sjfv	DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
2942190872Sjfv		hw->fc.current_mode);
2943169240Sjfv
2944169240Sjfv	/* Continue to configure the copper link. */
2945177867Sjfv	ret_val = hw->mac.ops.setup_physical_interface(hw);
2946169240Sjfv	if (ret_val)
2947169240Sjfv		goto out;
2948169240Sjfv
2949173788Sjfv	E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
2950194865Sjfv	if ((hw->phy.type == e1000_phy_82578) ||
2951194865Sjfv	    (hw->phy.type == e1000_phy_82577)) {
2952194865Sjfv		ret_val = hw->phy.ops.write_reg(hw,
2953194865Sjfv		                             PHY_REG(BM_PORT_CTRL_PAGE, 27),
2954194865Sjfv		                             hw->fc.pause_time);
2955194865Sjfv		if (ret_val)
2956194865Sjfv			goto out;
2957194865Sjfv	}
2958169240Sjfv
2959169240Sjfv	ret_val = e1000_set_fc_watermarks_generic(hw);
2960169240Sjfv
2961169240Sjfvout:
2962169240Sjfv	return ret_val;
2963169240Sjfv}
2964169240Sjfv
2965169240Sjfv/**
2966169240Sjfv *  e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
2967169589Sjfv *  @hw: pointer to the HW structure
2968169240Sjfv *
2969169240Sjfv *  Configures the kumeran interface to the PHY to wait the appropriate time
2970169240Sjfv *  when polling the PHY, then call the generic setup_copper_link to finish
2971169240Sjfv *  configuring the copper link.
2972169240Sjfv **/
2973177867Sjfvstatic s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
2974169240Sjfv{
2975169240Sjfv	u32 ctrl;
2976169240Sjfv	s32 ret_val;
2977169240Sjfv	u16 reg_data;
2978169240Sjfv
2979169240Sjfv	DEBUGFUNC("e1000_setup_copper_link_ich8lan");
2980169240Sjfv
2981169240Sjfv	ctrl = E1000_READ_REG(hw, E1000_CTRL);
2982169240Sjfv	ctrl |= E1000_CTRL_SLU;
2983169240Sjfv	ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2984169240Sjfv	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2985169240Sjfv
2986173788Sjfv	/*
2987173788Sjfv	 * Set the mac to wait the maximum time between each iteration
2988169240Sjfv	 * and increase the max iterations when polling the phy;
2989173788Sjfv	 * this fixes erroneous timeouts at 10Mbps.
2990173788Sjfv	 */
2991200243Sjfv	ret_val = e1000_write_kmrn_reg_generic(hw, E1000_KMRNCTRLSTA_TIMEOUTS,
2992181027Sjfv	                                       0xFFFF);
2993169240Sjfv	if (ret_val)
2994169240Sjfv		goto out;
2995194865Sjfv	ret_val = e1000_read_kmrn_reg_generic(hw,
2996194865Sjfv	                                      E1000_KMRNCTRLSTA_INBAND_PARAM,
2997181027Sjfv	                                      &reg_data);
2998169240Sjfv	if (ret_val)
2999169240Sjfv		goto out;
3000169240Sjfv	reg_data |= 0x3F;
3001194865Sjfv	ret_val = e1000_write_kmrn_reg_generic(hw,
3002194865Sjfv	                                       E1000_KMRNCTRLSTA_INBAND_PARAM,
3003181027Sjfv	                                       reg_data);
3004169240Sjfv	if (ret_val)
3005169240Sjfv		goto out;
3006169240Sjfv
3007190872Sjfv	switch (hw->phy.type) {
3008190872Sjfv	case e1000_phy_igp_3:
3009169240Sjfv		ret_val = e1000_copper_link_setup_igp(hw);
3010169240Sjfv		if (ret_val)
3011169240Sjfv			goto out;
3012190872Sjfv		break;
3013190872Sjfv	case e1000_phy_bm:
3014194865Sjfv	case e1000_phy_82578:
3015176667Sjfv		ret_val = e1000_copper_link_setup_m88(hw);
3016176667Sjfv		if (ret_val)
3017176667Sjfv			goto out;
3018190872Sjfv		break;
3019194865Sjfv	case e1000_phy_82577:
3020194865Sjfv		ret_val = e1000_copper_link_setup_82577(hw);
3021194865Sjfv		if (ret_val)
3022194865Sjfv			goto out;
3023194865Sjfv		break;
3024190872Sjfv	case e1000_phy_ife:
3025177867Sjfv		ret_val = hw->phy.ops.read_reg(hw, IFE_PHY_MDIX_CONTROL,
3026177867Sjfv		                               &reg_data);
3027173788Sjfv		if (ret_val)
3028173788Sjfv			goto out;
3029173788Sjfv
3030173788Sjfv		reg_data &= ~IFE_PMC_AUTO_MDIX;
3031173788Sjfv
3032173788Sjfv		switch (hw->phy.mdix) {
3033173788Sjfv		case 1:
3034173788Sjfv			reg_data &= ~IFE_PMC_FORCE_MDIX;
3035173788Sjfv			break;
3036173788Sjfv		case 2:
3037173788Sjfv			reg_data |= IFE_PMC_FORCE_MDIX;
3038173788Sjfv			break;
3039173788Sjfv		case 0:
3040173788Sjfv		default:
3041173788Sjfv			reg_data |= IFE_PMC_AUTO_MDIX;
3042173788Sjfv			break;
3043173788Sjfv		}
3044177867Sjfv		ret_val = hw->phy.ops.write_reg(hw, IFE_PHY_MDIX_CONTROL,
3045177867Sjfv		                                reg_data);
3046173788Sjfv		if (ret_val)
3047173788Sjfv			goto out;
3048190872Sjfv		break;
3049190872Sjfv	default:
3050190872Sjfv		break;
3051173788Sjfv	}
3052169240Sjfv	ret_val = e1000_setup_copper_link_generic(hw);
3053169240Sjfv
3054169240Sjfvout:
3055169240Sjfv	return ret_val;
3056169240Sjfv}
3057169240Sjfv
3058169240Sjfv/**
3059169240Sjfv *  e1000_get_link_up_info_ich8lan - Get current link speed and duplex
3060169589Sjfv *  @hw: pointer to the HW structure
3061169589Sjfv *  @speed: pointer to store current link speed
3062169589Sjfv *  @duplex: pointer to store the current link duplex
3063169240Sjfv *
3064176667Sjfv *  Calls the generic get_speed_and_duplex to retrieve the current link
3065169240Sjfv *  information and then calls the Kumeran lock loss workaround for links at
3066169240Sjfv *  gigabit speeds.
3067169240Sjfv **/
3068177867Sjfvstatic s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
3069173788Sjfv                                          u16 *duplex)
3070169240Sjfv{
3071169240Sjfv	s32 ret_val;
3072169240Sjfv
3073169240Sjfv	DEBUGFUNC("e1000_get_link_up_info_ich8lan");
3074169240Sjfv
3075169240Sjfv	ret_val = e1000_get_speed_and_duplex_copper_generic(hw, speed, duplex);
3076169240Sjfv	if (ret_val)
3077169240Sjfv		goto out;
3078169240Sjfv
3079169240Sjfv	if ((hw->mac.type == e1000_ich8lan) &&
3080169240Sjfv	    (hw->phy.type == e1000_phy_igp_3) &&
3081169240Sjfv	    (*speed == SPEED_1000)) {
3082169240Sjfv		ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
3083169240Sjfv	}
3084169240Sjfv
3085169240Sjfvout:
3086169240Sjfv	return ret_val;
3087169240Sjfv}
3088169240Sjfv
3089169240Sjfv/**
3090169240Sjfv *  e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
3091169589Sjfv *  @hw: pointer to the HW structure
3092169240Sjfv *
3093169240Sjfv *  Work-around for 82566 Kumeran PCS lock loss:
3094169240Sjfv *  On link status change (i.e. PCI reset, speed change) and link is up and
3095169240Sjfv *  speed is gigabit-
3096169240Sjfv *    0) if workaround is optionally disabled do nothing
3097169240Sjfv *    1) wait 1ms for Kumeran link to come up
3098169240Sjfv *    2) check Kumeran Diagnostic register PCS lock loss bit
3099169240Sjfv *    3) if not set the link is locked (all is good), otherwise...
3100169240Sjfv *    4) reset the PHY
3101169240Sjfv *    5) repeat up to 10 times
3102169240Sjfv *  Note: this is only called for IGP3 copper when speed is 1gb.
3103169240Sjfv **/
3104173788Sjfvstatic s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
3105169240Sjfv{
3106185353Sjfv	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3107169240Sjfv	u32 phy_ctrl;
3108169240Sjfv	s32 ret_val = E1000_SUCCESS;
3109169240Sjfv	u16 i, data;
3110173788Sjfv	bool link;
3111169240Sjfv
3112169240Sjfv	DEBUGFUNC("e1000_kmrn_lock_loss_workaround_ich8lan");
3113169240Sjfv
3114173788Sjfv	if (!(dev_spec->kmrn_lock_loss_workaround_enabled))
3115169240Sjfv		goto out;
3116169240Sjfv
3117173788Sjfv	/*
3118173788Sjfv	 * Make sure link is up before proceeding.  If not just return.
3119169240Sjfv	 * Attempting this while link is negotiating fouled up link
3120173788Sjfv	 * stability
3121173788Sjfv	 */
3122169240Sjfv	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
3123169240Sjfv	if (!link) {
3124169240Sjfv		ret_val = E1000_SUCCESS;
3125169240Sjfv		goto out;
3126169240Sjfv	}
3127169240Sjfv
3128169240Sjfv	for (i = 0; i < 10; i++) {
3129169240Sjfv		/* read once to clear */
3130177867Sjfv		ret_val = hw->phy.ops.read_reg(hw, IGP3_KMRN_DIAG, &data);
3131169240Sjfv		if (ret_val)
3132169240Sjfv			goto out;
3133169240Sjfv		/* and again to get new status */
3134177867Sjfv		ret_val = hw->phy.ops.read_reg(hw, IGP3_KMRN_DIAG, &data);
3135169240Sjfv		if (ret_val)
3136169240Sjfv			goto out;
3137169240Sjfv
3138169240Sjfv		/* check for PCS lock */
3139169240Sjfv		if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS)) {
3140169240Sjfv			ret_val = E1000_SUCCESS;
3141169240Sjfv			goto out;
3142169240Sjfv		}
3143169240Sjfv
3144169240Sjfv		/* Issue PHY reset */
3145177867Sjfv		hw->phy.ops.reset(hw);
3146169240Sjfv		msec_delay_irq(5);
3147169240Sjfv	}
3148169240Sjfv	/* Disable GigE link negotiation */
3149169240Sjfv	phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
3150169240Sjfv	phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
3151169240Sjfv	             E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3152169240Sjfv	E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
3153169240Sjfv
3154173788Sjfv	/*
3155176667Sjfv	 * Call gig speed drop workaround on Gig disable before accessing
3156173788Sjfv	 * any PHY registers
3157173788Sjfv	 */
3158169240Sjfv	e1000_gig_downshift_workaround_ich8lan(hw);
3159169240Sjfv
3160169240Sjfv	/* unable to acquire PCS lock */
3161169240Sjfv	ret_val = -E1000_ERR_PHY;
3162169240Sjfv
3163169240Sjfvout:
3164169240Sjfv	return ret_val;
3165169240Sjfv}
3166169240Sjfv
3167169240Sjfv/**
3168176667Sjfv *  e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
3169169589Sjfv *  @hw: pointer to the HW structure
3170176667Sjfv *  @state: boolean value used to set the current Kumeran workaround state
3171169240Sjfv *
3172169240Sjfv *  If ICH8, set the current Kumeran workaround state (enabled - TRUE
3173169240Sjfv *  /disabled - FALSE).
3174169240Sjfv **/
3175173788Sjfvvoid e1000_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
3176173788Sjfv                                                 bool state)
3177169240Sjfv{
3178185353Sjfv	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
3179169240Sjfv
3180169240Sjfv	DEBUGFUNC("e1000_set_kmrn_lock_loss_workaround_ich8lan");
3181169240Sjfv
3182169240Sjfv	if (hw->mac.type != e1000_ich8lan) {
3183169240Sjfv		DEBUGOUT("Workaround applies to ICH8 only.\n");
3184185353Sjfv		return;
3185169240Sjfv	}
3186169240Sjfv
3187169240Sjfv	dev_spec->kmrn_lock_loss_workaround_enabled = state;
3188169240Sjfv
3189169240Sjfv	return;
3190169240Sjfv}
3191169240Sjfv
3192169240Sjfv/**
3193169240Sjfv *  e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
3194169589Sjfv *  @hw: pointer to the HW structure
3195169240Sjfv *
3196169240Sjfv *  Workaround for 82566 power-down on D3 entry:
3197169240Sjfv *    1) disable gigabit link
3198169240Sjfv *    2) write VR power-down enable
3199169240Sjfv *    3) read it back
3200169240Sjfv *  Continue if successful, else issue LCD reset and repeat
3201169240Sjfv **/
3202173788Sjfvvoid e1000_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
3203169240Sjfv{
3204169240Sjfv	u32 reg;
3205169240Sjfv	u16 data;
3206169240Sjfv	u8  retry = 0;
3207169240Sjfv
3208169240Sjfv	DEBUGFUNC("e1000_igp3_phy_powerdown_workaround_ich8lan");
3209169240Sjfv
3210169240Sjfv	if (hw->phy.type != e1000_phy_igp_3)
3211169240Sjfv		goto out;
3212169240Sjfv
3213169240Sjfv	/* Try the workaround twice (if needed) */
3214169240Sjfv	do {
3215169240Sjfv		/* Disable link */
3216169240Sjfv		reg = E1000_READ_REG(hw, E1000_PHY_CTRL);
3217169240Sjfv		reg |= (E1000_PHY_CTRL_GBE_DISABLE |
3218169240Sjfv		        E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3219169240Sjfv		E1000_WRITE_REG(hw, E1000_PHY_CTRL, reg);
3220169240Sjfv
3221173788Sjfv		/*
3222176667Sjfv		 * Call gig speed drop workaround on Gig disable before
3223173788Sjfv		 * accessing any PHY registers
3224173788Sjfv		 */
3225169240Sjfv		if (hw->mac.type == e1000_ich8lan)
3226169240Sjfv			e1000_gig_downshift_workaround_ich8lan(hw);
3227169240Sjfv
3228169240Sjfv		/* Write VR power-down enable */
3229177867Sjfv		hw->phy.ops.read_reg(hw, IGP3_VR_CTRL, &data);
3230169240Sjfv		data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3231185353Sjfv		hw->phy.ops.write_reg(hw, IGP3_VR_CTRL,
3232169240Sjfv		                   data | IGP3_VR_CTRL_MODE_SHUTDOWN);
3233169240Sjfv
3234169240Sjfv		/* Read it back and test */
3235177867Sjfv		hw->phy.ops.read_reg(hw, IGP3_VR_CTRL, &data);
3236169589Sjfv		data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
3237169589Sjfv		if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
3238169240Sjfv			break;
3239169240Sjfv
3240169240Sjfv		/* Issue PHY reset and repeat at most one more time */
3241169240Sjfv		reg = E1000_READ_REG(hw, E1000_CTRL);
3242169240Sjfv		E1000_WRITE_REG(hw, E1000_CTRL, reg | E1000_CTRL_PHY_RST);
3243169240Sjfv		retry++;
3244169240Sjfv	} while (retry);
3245169240Sjfv
3246169240Sjfvout:
3247169240Sjfv	return;
3248169240Sjfv}
3249169240Sjfv
3250169240Sjfv/**
3251169240Sjfv *  e1000_gig_downshift_workaround_ich8lan - WoL from S5 stops working
3252169589Sjfv *  @hw: pointer to the HW structure
3253169240Sjfv *
3254169240Sjfv *  Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
3255176667Sjfv *  LPLU, Gig disable, MDIC PHY reset):
3256169240Sjfv *    1) Set Kumeran Near-end loopback
3257169240Sjfv *    2) Clear Kumeran Near-end loopback
3258169240Sjfv *  Should only be called for ICH8[m] devices with IGP_3 Phy.
3259169240Sjfv **/
3260173788Sjfvvoid e1000_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
3261169240Sjfv{
3262169240Sjfv	s32 ret_val = E1000_SUCCESS;
3263169240Sjfv	u16 reg_data;
3264169240Sjfv
3265169240Sjfv	DEBUGFUNC("e1000_gig_downshift_workaround_ich8lan");
3266169240Sjfv
3267169240Sjfv	if ((hw->mac.type != e1000_ich8lan) ||
3268169240Sjfv	    (hw->phy.type != e1000_phy_igp_3))
3269169240Sjfv		goto out;
3270169240Sjfv
3271181027Sjfv	ret_val = e1000_read_kmrn_reg_generic(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
3272181027Sjfv	                                      &reg_data);
3273169240Sjfv	if (ret_val)
3274169240Sjfv		goto out;
3275169240Sjfv	reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
3276181027Sjfv	ret_val = e1000_write_kmrn_reg_generic(hw,
3277181027Sjfv	                                       E1000_KMRNCTRLSTA_DIAG_OFFSET,
3278181027Sjfv	                                       reg_data);
3279169240Sjfv	if (ret_val)
3280169240Sjfv		goto out;
3281169240Sjfv	reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
3282181027Sjfv	ret_val = e1000_write_kmrn_reg_generic(hw,
3283181027Sjfv	                                       E1000_KMRNCTRLSTA_DIAG_OFFSET,
3284181027Sjfv	                                       reg_data);
3285169240Sjfvout:
3286169240Sjfv	return;
3287169240Sjfv}
3288169240Sjfv
3289169240Sjfv/**
3290176667Sjfv *  e1000_disable_gig_wol_ich8lan - disable gig during WoL
3291176667Sjfv *  @hw: pointer to the HW structure
3292176667Sjfv *
3293176667Sjfv *  During S0 to Sx transition, it is possible the link remains at gig
3294176667Sjfv *  instead of negotiating to a lower speed.  Before going to Sx, set
3295176667Sjfv *  'LPLU Enabled' and 'Gig Disable' to force link speed negotiation
3296176667Sjfv *  to a lower speed.
3297176667Sjfv *
3298190872Sjfv *  Should only be called for applicable parts.
3299176667Sjfv **/
3300176667Sjfvvoid e1000_disable_gig_wol_ich8lan(struct e1000_hw *hw)
3301176667Sjfv{
3302176667Sjfv	u32 phy_ctrl;
3303176667Sjfv
3304190872Sjfv	switch (hw->mac.type) {
3305200243Sjfv	case e1000_ich8lan:
3306190872Sjfv	case e1000_ich9lan:
3307190872Sjfv	case e1000_ich10lan:
3308194865Sjfv	case e1000_pchlan:
3309176667Sjfv		phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
3310176667Sjfv		phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU |
3311176667Sjfv		            E1000_PHY_CTRL_GBE_DISABLE;
3312176667Sjfv		E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
3313194865Sjfv
3314194865Sjfv		if (hw->mac.type == e1000_pchlan)
3315200243Sjfv			e1000_phy_hw_reset_ich8lan(hw);
3316190872Sjfv	default:
3317190872Sjfv		break;
3318176667Sjfv	}
3319176667Sjfv
3320176667Sjfv	return;
3321176667Sjfv}
3322176667Sjfv
3323176667Sjfv/**
3324169240Sjfv *  e1000_cleanup_led_ich8lan - Restore the default LED operation
3325169589Sjfv *  @hw: pointer to the HW structure
3326169240Sjfv *
3327169240Sjfv *  Return the LED back to the default configuration.
3328169240Sjfv **/
3329177867Sjfvstatic s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
3330169240Sjfv{
3331169240Sjfv	DEBUGFUNC("e1000_cleanup_led_ich8lan");
3332169240Sjfv
3333169240Sjfv	if (hw->phy.type == e1000_phy_ife)
3334203049Sjfv		return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3335203049Sjfv		                             0);
3336169240Sjfv
3337203049Sjfv	E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default);
3338203049Sjfv	return E1000_SUCCESS;
3339169240Sjfv}
3340169240Sjfv
3341169240Sjfv/**
3342176667Sjfv *  e1000_led_on_ich8lan - Turn LEDs on
3343169589Sjfv *  @hw: pointer to the HW structure
3344169240Sjfv *
3345176667Sjfv *  Turn on the LEDs.
3346169240Sjfv **/
3347177867Sjfvstatic s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
3348169240Sjfv{
3349169240Sjfv	DEBUGFUNC("e1000_led_on_ich8lan");
3350169240Sjfv
3351169240Sjfv	if (hw->phy.type == e1000_phy_ife)
3352203049Sjfv		return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3353169240Sjfv		                (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
3354169240Sjfv
3355203049Sjfv	E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode2);
3356203049Sjfv	return E1000_SUCCESS;
3357169240Sjfv}
3358169240Sjfv
3359169240Sjfv/**
3360176667Sjfv *  e1000_led_off_ich8lan - Turn LEDs off
3361169589Sjfv *  @hw: pointer to the HW structure
3362169240Sjfv *
3363176667Sjfv *  Turn off the LEDs.
3364169240Sjfv **/
3365177867Sjfvstatic s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
3366169240Sjfv{
3367169240Sjfv	DEBUGFUNC("e1000_led_off_ich8lan");
3368169240Sjfv
3369169240Sjfv	if (hw->phy.type == e1000_phy_ife)
3370203049Sjfv		return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
3371169240Sjfv		               (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
3372169240Sjfv
3373203049Sjfv	E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
3374203049Sjfv	return E1000_SUCCESS;
3375169240Sjfv}
3376169240Sjfv
3377169240Sjfv/**
3378194865Sjfv *  e1000_setup_led_pchlan - Configures SW controllable LED
3379194865Sjfv *  @hw: pointer to the HW structure
3380194865Sjfv *
3381194865Sjfv *  This prepares the SW controllable LED for use.
3382194865Sjfv **/
3383194865Sjfvstatic s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
3384194865Sjfv{
3385194865Sjfv	DEBUGFUNC("e1000_setup_led_pchlan");
3386194865Sjfv
3387194865Sjfv	return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
3388194865Sjfv					(u16)hw->mac.ledctl_mode1);
3389194865Sjfv}
3390194865Sjfv
3391194865Sjfv/**
3392194865Sjfv *  e1000_cleanup_led_pchlan - Restore the default LED operation
3393194865Sjfv *  @hw: pointer to the HW structure
3394194865Sjfv *
3395194865Sjfv *  Return the LED back to the default configuration.
3396194865Sjfv **/
3397194865Sjfvstatic s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
3398194865Sjfv{
3399194865Sjfv	DEBUGFUNC("e1000_cleanup_led_pchlan");
3400194865Sjfv
3401194865Sjfv	return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
3402194865Sjfv					(u16)hw->mac.ledctl_default);
3403194865Sjfv}
3404194865Sjfv
3405194865Sjfv/**
3406194865Sjfv *  e1000_led_on_pchlan - Turn LEDs on
3407194865Sjfv *  @hw: pointer to the HW structure
3408194865Sjfv *
3409194865Sjfv *  Turn on the LEDs.
3410194865Sjfv **/
3411194865Sjfvstatic s32 e1000_led_on_pchlan(struct e1000_hw *hw)
3412194865Sjfv{
3413194865Sjfv	u16 data = (u16)hw->mac.ledctl_mode2;
3414194865Sjfv	u32 i, led;
3415194865Sjfv
3416194865Sjfv	DEBUGFUNC("e1000_led_on_pchlan");
3417194865Sjfv
3418194865Sjfv	/*
3419194865Sjfv	 * If no link, then turn LED on by setting the invert bit
3420194865Sjfv	 * for each LED that's mode is "link_up" in ledctl_mode2.
3421194865Sjfv	 */
3422194865Sjfv	if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
3423194865Sjfv		for (i = 0; i < 3; i++) {
3424194865Sjfv			led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3425194865Sjfv			if ((led & E1000_PHY_LED0_MODE_MASK) !=
3426194865Sjfv			    E1000_LEDCTL_MODE_LINK_UP)
3427194865Sjfv				continue;
3428194865Sjfv			if (led & E1000_PHY_LED0_IVRT)
3429194865Sjfv				data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3430194865Sjfv			else
3431194865Sjfv				data |= (E1000_PHY_LED0_IVRT << (i * 5));
3432194865Sjfv		}
3433194865Sjfv	}
3434194865Sjfv
3435194865Sjfv	return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
3436194865Sjfv}
3437194865Sjfv
3438194865Sjfv/**
3439194865Sjfv *  e1000_led_off_pchlan - Turn LEDs off
3440194865Sjfv *  @hw: pointer to the HW structure
3441194865Sjfv *
3442194865Sjfv *  Turn off the LEDs.
3443194865Sjfv **/
3444194865Sjfvstatic s32 e1000_led_off_pchlan(struct e1000_hw *hw)
3445194865Sjfv{
3446194865Sjfv	u16 data = (u16)hw->mac.ledctl_mode1;
3447194865Sjfv	u32 i, led;
3448194865Sjfv
3449194865Sjfv	DEBUGFUNC("e1000_led_off_pchlan");
3450194865Sjfv
3451194865Sjfv	/*
3452194865Sjfv	 * If no link, then turn LED off by clearing the invert bit
3453194865Sjfv	 * for each LED that's mode is "link_up" in ledctl_mode1.
3454194865Sjfv	 */
3455194865Sjfv	if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
3456194865Sjfv		for (i = 0; i < 3; i++) {
3457194865Sjfv			led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
3458194865Sjfv			if ((led & E1000_PHY_LED0_MODE_MASK) !=
3459194865Sjfv			    E1000_LEDCTL_MODE_LINK_UP)
3460194865Sjfv				continue;
3461194865Sjfv			if (led & E1000_PHY_LED0_IVRT)
3462194865Sjfv				data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
3463194865Sjfv			else
3464194865Sjfv				data |= (E1000_PHY_LED0_IVRT << (i * 5));
3465194865Sjfv		}
3466194865Sjfv	}
3467194865Sjfv
3468194865Sjfv	return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
3469194865Sjfv}
3470194865Sjfv
3471194865Sjfv/**
3472169240Sjfv *  e1000_get_cfg_done_ich8lan - Read config done bit
3473169589Sjfv *  @hw: pointer to the HW structure
3474169240Sjfv *
3475169240Sjfv *  Read the management control register for the config done bit for
3476169240Sjfv *  completion status.  NOTE: silicon which is EEPROM-less will fail trying
3477169240Sjfv *  to read the config done bit, so an error is *ONLY* logged and returns
3478169240Sjfv *  E1000_SUCCESS.  If we were to return with error, EEPROM-less silicon
3479169240Sjfv *  would not be able to be reset or change link.
3480169240Sjfv **/
3481177867Sjfvstatic s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
3482169240Sjfv{
3483173788Sjfv	s32 ret_val = E1000_SUCCESS;
3484178523Sjfv	u32 bank = 0;
3485173788Sjfv
3486194865Sjfv	if (hw->mac.type >= e1000_pchlan) {
3487194865Sjfv		u32 status = E1000_READ_REG(hw, E1000_STATUS);
3488194865Sjfv
3489200243Sjfv		if (status & E1000_STATUS_PHYRA)
3490194865Sjfv			E1000_WRITE_REG(hw, E1000_STATUS, status &
3491194865Sjfv			                ~E1000_STATUS_PHYRA);
3492200243Sjfv		else
3493194865Sjfv			DEBUGOUT("PHY Reset Asserted not set - needs delay\n");
3494194865Sjfv	}
3495194865Sjfv
3496169240Sjfv	e1000_get_cfg_done_generic(hw);
3497169240Sjfv
3498169240Sjfv	/* If EEPROM is not marked present, init the IGP 3 PHY manually */
3499200243Sjfv	if (hw->mac.type <= e1000_ich9lan) {
3500178523Sjfv		if (((E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_PRES) == 0) &&
3501185353Sjfv		    (hw->phy.type == e1000_phy_igp_3)) {
3502178523Sjfv			e1000_phy_init_script_igp3(hw);
3503178523Sjfv		}
3504178523Sjfv	} else {
3505178523Sjfv		if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
3506185353Sjfv			/* Maybe we should do a basic PHY config */
3507178523Sjfv			DEBUGOUT("EEPROM not present\n");
3508178523Sjfv			ret_val = -E1000_ERR_CONFIG;
3509178523Sjfv		}
3510169240Sjfv	}
3511169240Sjfv
3512173788Sjfv	return ret_val;
3513169240Sjfv}
3514169240Sjfv
3515169240Sjfv/**
3516173788Sjfv * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
3517173788Sjfv * @hw: pointer to the HW structure
3518173788Sjfv *
3519173788Sjfv * In the case of a PHY power down to save power, or to turn off link during a
3520173788Sjfv * driver unload, or wake on lan is not enabled, remove the link.
3521173788Sjfv **/
3522177867Sjfvstatic void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
3523173788Sjfv{
3524173788Sjfv	/* If the management interface is not enabled, then power down */
3525185353Sjfv	if (!(hw->mac.ops.check_mng_mode(hw) ||
3526185353Sjfv	      hw->phy.ops.check_reset_block(hw)))
3527173788Sjfv		e1000_power_down_phy_copper(hw);
3528173788Sjfv
3529173788Sjfv	return;
3530173788Sjfv}
3531173788Sjfv
3532173788Sjfv/**
3533169240Sjfv *  e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
3534169589Sjfv *  @hw: pointer to the HW structure
3535169240Sjfv *
3536169240Sjfv *  Clears hardware counters specific to the silicon family and calls
3537169240Sjfv *  clear_hw_cntrs_generic to clear all general purpose counters.
3538169240Sjfv **/
3539177867Sjfvstatic void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
3540169240Sjfv{
3541194865Sjfv	u16 phy_data;
3542194865Sjfv
3543169240Sjfv	DEBUGFUNC("e1000_clear_hw_cntrs_ich8lan");
3544169240Sjfv
3545169240Sjfv	e1000_clear_hw_cntrs_base_generic(hw);
3546169240Sjfv
3547185353Sjfv	E1000_READ_REG(hw, E1000_ALGNERRC);
3548185353Sjfv	E1000_READ_REG(hw, E1000_RXERRC);
3549185353Sjfv	E1000_READ_REG(hw, E1000_TNCRS);
3550185353Sjfv	E1000_READ_REG(hw, E1000_CEXTERR);
3551185353Sjfv	E1000_READ_REG(hw, E1000_TSCTC);
3552185353Sjfv	E1000_READ_REG(hw, E1000_TSCTFC);
3553169240Sjfv
3554185353Sjfv	E1000_READ_REG(hw, E1000_MGTPRC);
3555185353Sjfv	E1000_READ_REG(hw, E1000_MGTPDC);
3556185353Sjfv	E1000_READ_REG(hw, E1000_MGTPTC);
3557169240Sjfv
3558185353Sjfv	E1000_READ_REG(hw, E1000_IAC);
3559185353Sjfv	E1000_READ_REG(hw, E1000_ICRXOC);
3560194865Sjfv
3561194865Sjfv	/* Clear PHY statistics registers */
3562194865Sjfv	if ((hw->phy.type == e1000_phy_82578) ||
3563194865Sjfv	    (hw->phy.type == e1000_phy_82577)) {
3564194865Sjfv		hw->phy.ops.read_reg(hw, HV_SCC_UPPER, &phy_data);
3565194865Sjfv		hw->phy.ops.read_reg(hw, HV_SCC_LOWER, &phy_data);
3566194865Sjfv		hw->phy.ops.read_reg(hw, HV_ECOL_UPPER, &phy_data);
3567194865Sjfv		hw->phy.ops.read_reg(hw, HV_ECOL_LOWER, &phy_data);
3568194865Sjfv		hw->phy.ops.read_reg(hw, HV_MCC_UPPER, &phy_data);
3569194865Sjfv		hw->phy.ops.read_reg(hw, HV_MCC_LOWER, &phy_data);
3570194865Sjfv		hw->phy.ops.read_reg(hw, HV_LATECOL_UPPER, &phy_data);
3571194865Sjfv		hw->phy.ops.read_reg(hw, HV_LATECOL_LOWER, &phy_data);
3572194865Sjfv		hw->phy.ops.read_reg(hw, HV_COLC_UPPER, &phy_data);
3573194865Sjfv		hw->phy.ops.read_reg(hw, HV_COLC_LOWER, &phy_data);
3574194865Sjfv		hw->phy.ops.read_reg(hw, HV_DC_UPPER, &phy_data);
3575194865Sjfv		hw->phy.ops.read_reg(hw, HV_DC_LOWER, &phy_data);
3576194865Sjfv		hw->phy.ops.read_reg(hw, HV_TNCRS_UPPER, &phy_data);
3577194865Sjfv		hw->phy.ops.read_reg(hw, HV_TNCRS_LOWER, &phy_data);
3578194865Sjfv	}
3579169240Sjfv}
3580169240Sjfv
3581