xref: /freebsd/sys/dev/igc/igc_i225.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1517904deSPeter Grehan /*-
2517904deSPeter Grehan  * Copyright 2021 Intel Corp
3517904deSPeter Grehan  * Copyright 2021 Rubicon Communications, LLC (Netgate)
4517904deSPeter Grehan  * SPDX-License-Identifier: BSD-3-Clause
5517904deSPeter Grehan  */
6517904deSPeter Grehan 
7517904deSPeter Grehan #include <sys/cdefs.h>
8517904deSPeter Grehan #include "igc_api.h"
9517904deSPeter Grehan 
10517904deSPeter Grehan static s32 igc_init_nvm_params_i225(struct igc_hw *hw);
11517904deSPeter Grehan static s32 igc_init_mac_params_i225(struct igc_hw *hw);
12517904deSPeter Grehan static s32 igc_init_phy_params_i225(struct igc_hw *hw);
13517904deSPeter Grehan static s32 igc_reset_hw_i225(struct igc_hw *hw);
14517904deSPeter Grehan static s32 igc_acquire_nvm_i225(struct igc_hw *hw);
15517904deSPeter Grehan static void igc_release_nvm_i225(struct igc_hw *hw);
16517904deSPeter Grehan static s32 igc_get_hw_semaphore_i225(struct igc_hw *hw);
17517904deSPeter Grehan static s32 __igc_write_nvm_srwr(struct igc_hw *hw, u16 offset, u16 words,
18517904deSPeter Grehan 				  u16 *data);
19517904deSPeter Grehan static s32 igc_pool_flash_update_done_i225(struct igc_hw *hw);
20517904deSPeter Grehan 
21517904deSPeter Grehan /**
22517904deSPeter Grehan  *  igc_init_nvm_params_i225 - Init NVM func ptrs.
23517904deSPeter Grehan  *  @hw: pointer to the HW structure
24517904deSPeter Grehan  **/
igc_init_nvm_params_i225(struct igc_hw * hw)25517904deSPeter Grehan static s32 igc_init_nvm_params_i225(struct igc_hw *hw)
26517904deSPeter Grehan {
27517904deSPeter Grehan 	struct igc_nvm_info *nvm = &hw->nvm;
28517904deSPeter Grehan 	u32 eecd = IGC_READ_REG(hw, IGC_EECD);
29517904deSPeter Grehan 	u16 size;
30517904deSPeter Grehan 
31517904deSPeter Grehan 	DEBUGFUNC("igc_init_nvm_params_i225");
32517904deSPeter Grehan 
33517904deSPeter Grehan 	size = (u16)((eecd & IGC_EECD_SIZE_EX_MASK) >>
34517904deSPeter Grehan 		     IGC_EECD_SIZE_EX_SHIFT);
35517904deSPeter Grehan 	/*
36517904deSPeter Grehan 	 * Added to a constant, "size" becomes the left-shift value
37517904deSPeter Grehan 	 * for setting word_size.
38517904deSPeter Grehan 	 */
39517904deSPeter Grehan 	size += NVM_WORD_SIZE_BASE_SHIFT;
40517904deSPeter Grehan 
41517904deSPeter Grehan 	/* Just in case size is out of range, cap it to the largest
42517904deSPeter Grehan 	 * EEPROM size supported
43517904deSPeter Grehan 	 */
44517904deSPeter Grehan 	if (size > 15)
45517904deSPeter Grehan 		size = 15;
46517904deSPeter Grehan 
47517904deSPeter Grehan 	nvm->word_size = 1 << size;
48517904deSPeter Grehan 	nvm->opcode_bits = 8;
49517904deSPeter Grehan 	nvm->delay_usec = 1;
50517904deSPeter Grehan 	nvm->type = igc_nvm_eeprom_spi;
51517904deSPeter Grehan 
52517904deSPeter Grehan 
53517904deSPeter Grehan 	nvm->page_size = eecd & IGC_EECD_ADDR_BITS ? 32 : 8;
54517904deSPeter Grehan 	nvm->address_bits = eecd & IGC_EECD_ADDR_BITS ?
55517904deSPeter Grehan 			    16 : 8;
56517904deSPeter Grehan 
57517904deSPeter Grehan 	if (nvm->word_size == (1 << 15))
58517904deSPeter Grehan 		nvm->page_size = 128;
59517904deSPeter Grehan 
60517904deSPeter Grehan 	nvm->ops.acquire = igc_acquire_nvm_i225;
61517904deSPeter Grehan 	nvm->ops.release = igc_release_nvm_i225;
62517904deSPeter Grehan 	if (igc_get_flash_presence_i225(hw)) {
63517904deSPeter Grehan 		hw->nvm.type = igc_nvm_flash_hw;
64517904deSPeter Grehan 		nvm->ops.read    = igc_read_nvm_srrd_i225;
65517904deSPeter Grehan 		nvm->ops.write   = igc_write_nvm_srwr_i225;
66517904deSPeter Grehan 		nvm->ops.validate = igc_validate_nvm_checksum_i225;
67517904deSPeter Grehan 		nvm->ops.update   = igc_update_nvm_checksum_i225;
68517904deSPeter Grehan 	} else {
69517904deSPeter Grehan 		hw->nvm.type = igc_nvm_invm;
70517904deSPeter Grehan 		nvm->ops.write    = igc_null_write_nvm;
71517904deSPeter Grehan 		nvm->ops.validate = igc_null_ops_generic;
72517904deSPeter Grehan 		nvm->ops.update   = igc_null_ops_generic;
73517904deSPeter Grehan 	}
74517904deSPeter Grehan 
75517904deSPeter Grehan 	return IGC_SUCCESS;
76517904deSPeter Grehan }
77517904deSPeter Grehan 
78517904deSPeter Grehan /**
79517904deSPeter Grehan  *  igc_init_mac_params_i225 - Init MAC func ptrs.
80517904deSPeter Grehan  *  @hw: pointer to the HW structure
81517904deSPeter Grehan  **/
igc_init_mac_params_i225(struct igc_hw * hw)82517904deSPeter Grehan static s32 igc_init_mac_params_i225(struct igc_hw *hw)
83517904deSPeter Grehan {
84517904deSPeter Grehan 	struct igc_mac_info *mac = &hw->mac;
85517904deSPeter Grehan 	struct igc_dev_spec_i225 *dev_spec = &hw->dev_spec._i225;
86517904deSPeter Grehan 
87517904deSPeter Grehan 	DEBUGFUNC("igc_init_mac_params_i225");
88517904deSPeter Grehan 
89517904deSPeter Grehan 	/* Initialize function pointer */
90517904deSPeter Grehan 	igc_init_mac_ops_generic(hw);
91517904deSPeter Grehan 
92517904deSPeter Grehan 	/* Set media type */
93517904deSPeter Grehan 	hw->phy.media_type = igc_media_type_copper;
94517904deSPeter Grehan 	/* Set mta register count */
95517904deSPeter Grehan 	mac->mta_reg_count = 128;
96517904deSPeter Grehan 	/* Set rar entry count */
97517904deSPeter Grehan 	mac->rar_entry_count = IGC_RAR_ENTRIES_BASE;
98517904deSPeter Grehan 
99517904deSPeter Grehan 	/* reset */
100517904deSPeter Grehan 	mac->ops.reset_hw = igc_reset_hw_i225;
101517904deSPeter Grehan 	/* hw initialization */
102517904deSPeter Grehan 	mac->ops.init_hw = igc_init_hw_i225;
103517904deSPeter Grehan 	/* link setup */
104517904deSPeter Grehan 	mac->ops.setup_link = igc_setup_link_generic;
105517904deSPeter Grehan 	/* check for link */
106517904deSPeter Grehan 	mac->ops.check_for_link = igc_check_for_link_i225;
107517904deSPeter Grehan 	/* link info */
108517904deSPeter Grehan 	mac->ops.get_link_up_info = igc_get_speed_and_duplex_copper_generic;
109517904deSPeter Grehan 	/* acquire SW_FW sync */
110517904deSPeter Grehan 	mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
111517904deSPeter Grehan 	/* release SW_FW sync */
112517904deSPeter Grehan 	mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
113517904deSPeter Grehan 
114517904deSPeter Grehan 	/* Allow a single clear of the SW semaphore on I225 */
115517904deSPeter Grehan 	dev_spec->clear_semaphore_once = true;
116517904deSPeter Grehan 	mac->ops.setup_physical_interface = igc_setup_copper_link_i225;
117517904deSPeter Grehan 
118517904deSPeter Grehan 	/* Set if part includes ASF firmware */
119517904deSPeter Grehan 	mac->asf_firmware_present = true;
120517904deSPeter Grehan 
121517904deSPeter Grehan 	/* multicast address update */
122517904deSPeter Grehan 	mac->ops.update_mc_addr_list = igc_update_mc_addr_list_generic;
123517904deSPeter Grehan 
124517904deSPeter Grehan 	mac->ops.write_vfta = igc_write_vfta_generic;
125517904deSPeter Grehan 
126517904deSPeter Grehan 	return IGC_SUCCESS;
127517904deSPeter Grehan }
128517904deSPeter Grehan 
129517904deSPeter Grehan /**
130517904deSPeter Grehan  *  igc_init_phy_params_i225 - Init PHY func ptrs.
131517904deSPeter Grehan  *  @hw: pointer to the HW structure
132517904deSPeter Grehan  **/
igc_init_phy_params_i225(struct igc_hw * hw)133517904deSPeter Grehan static s32 igc_init_phy_params_i225(struct igc_hw *hw)
134517904deSPeter Grehan {
135517904deSPeter Grehan 	struct igc_phy_info *phy = &hw->phy;
136517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
137517904deSPeter Grehan 
138517904deSPeter Grehan 	DEBUGFUNC("igc_init_phy_params_i225");
139517904deSPeter Grehan 
140517904deSPeter Grehan 
141517904deSPeter Grehan 	if (hw->phy.media_type != igc_media_type_copper) {
142517904deSPeter Grehan 		phy->type = igc_phy_none;
143517904deSPeter Grehan 		goto out;
144517904deSPeter Grehan 	}
145517904deSPeter Grehan 
146517904deSPeter Grehan 	phy->ops.power_up   = igc_power_up_phy_copper;
147517904deSPeter Grehan 	phy->ops.power_down = igc_power_down_phy_copper_base;
148517904deSPeter Grehan 
149517904deSPeter Grehan 	phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT_2500;
150517904deSPeter Grehan 
151517904deSPeter Grehan 	phy->reset_delay_us	= 100;
152517904deSPeter Grehan 
153517904deSPeter Grehan 	phy->ops.acquire	= igc_acquire_phy_base;
154517904deSPeter Grehan 	phy->ops.check_reset_block = igc_check_reset_block_generic;
155517904deSPeter Grehan 	phy->ops.release	= igc_release_phy_base;
156*561cd74bSPeter Grehan 	phy->ops.reset		= igc_phy_hw_reset_generic;
157*561cd74bSPeter Grehan 	phy->ops.read_reg	= igc_read_phy_reg_gpy;
158*561cd74bSPeter Grehan 	phy->ops.write_reg	= igc_write_phy_reg_gpy;
159517904deSPeter Grehan 
160517904deSPeter Grehan 	/* Make sure the PHY is in a good state. Several people have reported
161517904deSPeter Grehan 	 * firmware leaving the PHY's page select register set to something
162517904deSPeter Grehan 	 * other than the default of zero, which causes the PHY ID read to
163517904deSPeter Grehan 	 * access something other than the intended register.
164517904deSPeter Grehan 	 */
165517904deSPeter Grehan 	ret_val = hw->phy.ops.reset(hw);
166517904deSPeter Grehan 	if (ret_val)
167517904deSPeter Grehan 		goto out;
168517904deSPeter Grehan 
169517904deSPeter Grehan 	ret_val = igc_get_phy_id(hw);
170517904deSPeter Grehan 	phy->type = igc_phy_i225;
171517904deSPeter Grehan 
172517904deSPeter Grehan out:
173517904deSPeter Grehan 	return ret_val;
174517904deSPeter Grehan }
175517904deSPeter Grehan 
176517904deSPeter Grehan /**
177517904deSPeter Grehan  *  igc_reset_hw_i225 - Reset hardware
178517904deSPeter Grehan  *  @hw: pointer to the HW structure
179517904deSPeter Grehan  *
180517904deSPeter Grehan  *  This resets the hardware into a known state.
181517904deSPeter Grehan  **/
igc_reset_hw_i225(struct igc_hw * hw)182517904deSPeter Grehan static s32 igc_reset_hw_i225(struct igc_hw *hw)
183517904deSPeter Grehan {
184517904deSPeter Grehan 	u32 ctrl;
185517904deSPeter Grehan 	s32 ret_val;
186517904deSPeter Grehan 
187517904deSPeter Grehan 	DEBUGFUNC("igc_reset_hw_i225");
188517904deSPeter Grehan 
189517904deSPeter Grehan 	/*
190517904deSPeter Grehan 	 * Prevent the PCI-E bus from sticking if there is no TLP connection
191517904deSPeter Grehan 	 * on the last TLP read/write transaction when MAC is reset.
192517904deSPeter Grehan 	 */
193517904deSPeter Grehan 	ret_val = igc_disable_pcie_master_generic(hw);
194517904deSPeter Grehan 	if (ret_val)
195517904deSPeter Grehan 		DEBUGOUT("PCI-E Master disable polling has failed.\n");
196517904deSPeter Grehan 
197517904deSPeter Grehan 	DEBUGOUT("Masking off all interrupts\n");
198517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_IMC, 0xffffffff);
199517904deSPeter Grehan 
200517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_RCTL, 0);
201517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_TCTL, IGC_TCTL_PSP);
202517904deSPeter Grehan 	IGC_WRITE_FLUSH(hw);
203517904deSPeter Grehan 
204517904deSPeter Grehan 	msec_delay(10);
205517904deSPeter Grehan 
206517904deSPeter Grehan 	ctrl = IGC_READ_REG(hw, IGC_CTRL);
207517904deSPeter Grehan 
208517904deSPeter Grehan 	DEBUGOUT("Issuing a global reset to MAC\n");
209517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_CTRL, ctrl | IGC_CTRL_DEV_RST);
210517904deSPeter Grehan 
211517904deSPeter Grehan 	ret_val = igc_get_auto_rd_done_generic(hw);
212517904deSPeter Grehan 	if (ret_val) {
213517904deSPeter Grehan 		/*
214517904deSPeter Grehan 		 * When auto config read does not complete, do not
215517904deSPeter Grehan 		 * return with an error. This can happen in situations
216517904deSPeter Grehan 		 * where there is no eeprom and prevents getting link.
217517904deSPeter Grehan 		 */
218517904deSPeter Grehan 		DEBUGOUT("Auto Read Done did not complete\n");
219517904deSPeter Grehan 	}
220517904deSPeter Grehan 
221517904deSPeter Grehan 	/* Clear any pending interrupt events. */
222517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_IMC, 0xffffffff);
223517904deSPeter Grehan 	IGC_READ_REG(hw, IGC_ICR);
224517904deSPeter Grehan 
225517904deSPeter Grehan 	/* Install any alternate MAC address into RAR0 */
226517904deSPeter Grehan 	ret_val = igc_check_alt_mac_addr_generic(hw);
227517904deSPeter Grehan 
228517904deSPeter Grehan 	return ret_val;
229517904deSPeter Grehan }
230517904deSPeter Grehan 
231517904deSPeter Grehan /* igc_acquire_nvm_i225 - Request for access to EEPROM
232517904deSPeter Grehan  * @hw: pointer to the HW structure
233517904deSPeter Grehan  *
234517904deSPeter Grehan  * Acquire the necessary semaphores for exclusive access to the EEPROM.
235517904deSPeter Grehan  * Set the EEPROM access request bit and wait for EEPROM access grant bit.
236517904deSPeter Grehan  * Return successful if access grant bit set, else clear the request for
237517904deSPeter Grehan  * EEPROM access and return -IGC_ERR_NVM (-1).
238517904deSPeter Grehan  */
igc_acquire_nvm_i225(struct igc_hw * hw)239517904deSPeter Grehan static s32 igc_acquire_nvm_i225(struct igc_hw *hw)
240517904deSPeter Grehan {
241517904deSPeter Grehan 	s32 ret_val;
242517904deSPeter Grehan 
243517904deSPeter Grehan 	DEBUGFUNC("igc_acquire_nvm_i225");
244517904deSPeter Grehan 
245517904deSPeter Grehan 	ret_val = igc_acquire_swfw_sync_i225(hw, IGC_SWFW_EEP_SM);
246517904deSPeter Grehan 
247517904deSPeter Grehan 	return ret_val;
248517904deSPeter Grehan }
249517904deSPeter Grehan 
250517904deSPeter Grehan /* igc_release_nvm_i225 - Release exclusive access to EEPROM
251517904deSPeter Grehan  * @hw: pointer to the HW structure
252517904deSPeter Grehan  *
253517904deSPeter Grehan  * Stop any current commands to the EEPROM and clear the EEPROM request bit,
254517904deSPeter Grehan  * then release the semaphores acquired.
255517904deSPeter Grehan  */
igc_release_nvm_i225(struct igc_hw * hw)256517904deSPeter Grehan static void igc_release_nvm_i225(struct igc_hw *hw)
257517904deSPeter Grehan {
258517904deSPeter Grehan 	DEBUGFUNC("igc_release_nvm_i225");
259517904deSPeter Grehan 
260517904deSPeter Grehan 	igc_release_swfw_sync_i225(hw, IGC_SWFW_EEP_SM);
261517904deSPeter Grehan }
262517904deSPeter Grehan 
263517904deSPeter Grehan /* igc_acquire_swfw_sync_i225 - Acquire SW/FW semaphore
264517904deSPeter Grehan  * @hw: pointer to the HW structure
265517904deSPeter Grehan  * @mask: specifies which semaphore to acquire
266517904deSPeter Grehan  *
267517904deSPeter Grehan  * Acquire the SW/FW semaphore to access the PHY or NVM.  The mask
268517904deSPeter Grehan  * will also specify which port we're acquiring the lock for.
269517904deSPeter Grehan  */
igc_acquire_swfw_sync_i225(struct igc_hw * hw,u16 mask)270517904deSPeter Grehan s32 igc_acquire_swfw_sync_i225(struct igc_hw *hw, u16 mask)
271517904deSPeter Grehan {
272517904deSPeter Grehan 	u32 swfw_sync;
273517904deSPeter Grehan 	u32 swmask = mask;
274517904deSPeter Grehan 	u32 fwmask = mask << 16;
275517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
276517904deSPeter Grehan 	s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
277517904deSPeter Grehan 
278517904deSPeter Grehan 	DEBUGFUNC("igc_acquire_swfw_sync_i225");
279517904deSPeter Grehan 
280517904deSPeter Grehan 	while (i < timeout) {
281517904deSPeter Grehan 		if (igc_get_hw_semaphore_i225(hw)) {
282517904deSPeter Grehan 			ret_val = -IGC_ERR_SWFW_SYNC;
283517904deSPeter Grehan 			goto out;
284517904deSPeter Grehan 		}
285517904deSPeter Grehan 
286517904deSPeter Grehan 		swfw_sync = IGC_READ_REG(hw, IGC_SW_FW_SYNC);
287517904deSPeter Grehan 		if (!(swfw_sync & (fwmask | swmask)))
288517904deSPeter Grehan 			break;
289517904deSPeter Grehan 
290517904deSPeter Grehan 		/* Firmware currently using resource (fwmask)
291517904deSPeter Grehan 		 * or other software thread using resource (swmask)
292517904deSPeter Grehan 		 */
293517904deSPeter Grehan 		igc_put_hw_semaphore_generic(hw);
294517904deSPeter Grehan 		msec_delay_irq(5);
295517904deSPeter Grehan 		i++;
296517904deSPeter Grehan 	}
297517904deSPeter Grehan 
298517904deSPeter Grehan 	if (i == timeout) {
299517904deSPeter Grehan 		DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
300517904deSPeter Grehan 		ret_val = -IGC_ERR_SWFW_SYNC;
301517904deSPeter Grehan 		goto out;
302517904deSPeter Grehan 	}
303517904deSPeter Grehan 
304517904deSPeter Grehan 	swfw_sync |= swmask;
305517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_SW_FW_SYNC, swfw_sync);
306517904deSPeter Grehan 
307517904deSPeter Grehan 	igc_put_hw_semaphore_generic(hw);
308517904deSPeter Grehan 
309517904deSPeter Grehan out:
310517904deSPeter Grehan 	return ret_val;
311517904deSPeter Grehan }
312517904deSPeter Grehan 
313517904deSPeter Grehan /* igc_release_swfw_sync_i225 - Release SW/FW semaphore
314517904deSPeter Grehan  * @hw: pointer to the HW structure
315517904deSPeter Grehan  * @mask: specifies which semaphore to acquire
316517904deSPeter Grehan  *
317517904deSPeter Grehan  * Release the SW/FW semaphore used to access the PHY or NVM.  The mask
318517904deSPeter Grehan  * will also specify which port we're releasing the lock for.
319517904deSPeter Grehan  */
igc_release_swfw_sync_i225(struct igc_hw * hw,u16 mask)320517904deSPeter Grehan void igc_release_swfw_sync_i225(struct igc_hw *hw, u16 mask)
321517904deSPeter Grehan {
322517904deSPeter Grehan 	u32 swfw_sync;
323517904deSPeter Grehan 
324517904deSPeter Grehan 	DEBUGFUNC("igc_release_swfw_sync_i225");
325517904deSPeter Grehan 
326517904deSPeter Grehan 	while (igc_get_hw_semaphore_i225(hw) != IGC_SUCCESS)
327517904deSPeter Grehan 		; /* Empty */
328517904deSPeter Grehan 
329517904deSPeter Grehan 	swfw_sync = IGC_READ_REG(hw, IGC_SW_FW_SYNC);
330517904deSPeter Grehan 	swfw_sync &= ~mask;
331517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_SW_FW_SYNC, swfw_sync);
332517904deSPeter Grehan 
333517904deSPeter Grehan 	igc_put_hw_semaphore_generic(hw);
334517904deSPeter Grehan }
335517904deSPeter Grehan 
336517904deSPeter Grehan /*
337517904deSPeter Grehan  * igc_setup_copper_link_i225 - Configure copper link settings
338517904deSPeter Grehan  * @hw: pointer to the HW structure
339517904deSPeter Grehan  *
340517904deSPeter Grehan  * Configures the link for auto-neg or forced speed and duplex.  Then we check
341517904deSPeter Grehan  * for link, once link is established calls to configure collision distance
342517904deSPeter Grehan  * and flow control are called.
343517904deSPeter Grehan  */
igc_setup_copper_link_i225(struct igc_hw * hw)344517904deSPeter Grehan s32 igc_setup_copper_link_i225(struct igc_hw *hw)
345517904deSPeter Grehan {
346517904deSPeter Grehan 	u32 phpm_reg;
347517904deSPeter Grehan 	s32 ret_val;
348517904deSPeter Grehan 	u32 ctrl;
349517904deSPeter Grehan 
350517904deSPeter Grehan 	DEBUGFUNC("igc_setup_copper_link_i225");
351517904deSPeter Grehan 
352517904deSPeter Grehan 	ctrl = IGC_READ_REG(hw, IGC_CTRL);
353517904deSPeter Grehan 	ctrl |= IGC_CTRL_SLU;
354517904deSPeter Grehan 	ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
355517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_CTRL, ctrl);
356517904deSPeter Grehan 
357517904deSPeter Grehan 	phpm_reg = IGC_READ_REG(hw, IGC_I225_PHPM);
358517904deSPeter Grehan 	phpm_reg &= ~IGC_I225_PHPM_GO_LINKD;
359517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_I225_PHPM, phpm_reg);
360517904deSPeter Grehan 
361517904deSPeter Grehan 	ret_val = igc_setup_copper_link_generic(hw);
362517904deSPeter Grehan 
363517904deSPeter Grehan 	return ret_val;
364517904deSPeter Grehan }
365517904deSPeter Grehan 
366517904deSPeter Grehan /* igc_get_hw_semaphore_i225 - Acquire hardware semaphore
367517904deSPeter Grehan  * @hw: pointer to the HW structure
368517904deSPeter Grehan  *
369517904deSPeter Grehan  * Acquire the HW semaphore to access the PHY or NVM
370517904deSPeter Grehan  */
igc_get_hw_semaphore_i225(struct igc_hw * hw)371517904deSPeter Grehan static s32 igc_get_hw_semaphore_i225(struct igc_hw *hw)
372517904deSPeter Grehan {
373517904deSPeter Grehan 	u32 swsm;
374517904deSPeter Grehan 	s32 timeout = hw->nvm.word_size + 1;
375517904deSPeter Grehan 	s32 i = 0;
376517904deSPeter Grehan 
377517904deSPeter Grehan 	DEBUGFUNC("igc_get_hw_semaphore_i225");
378517904deSPeter Grehan 
379517904deSPeter Grehan 	/* Get the SW semaphore */
380517904deSPeter Grehan 	while (i < timeout) {
381517904deSPeter Grehan 		swsm = IGC_READ_REG(hw, IGC_SWSM);
382517904deSPeter Grehan 		if (!(swsm & IGC_SWSM_SMBI))
383517904deSPeter Grehan 			break;
384517904deSPeter Grehan 
385517904deSPeter Grehan 		usec_delay(50);
386517904deSPeter Grehan 		i++;
387517904deSPeter Grehan 	}
388517904deSPeter Grehan 
389517904deSPeter Grehan 	if (i == timeout) {
390517904deSPeter Grehan 		/* In rare circumstances, the SW semaphore may already be held
391517904deSPeter Grehan 		 * unintentionally. Clear the semaphore once before giving up.
392517904deSPeter Grehan 		 */
393517904deSPeter Grehan 		if (hw->dev_spec._i225.clear_semaphore_once) {
394517904deSPeter Grehan 			hw->dev_spec._i225.clear_semaphore_once = false;
395517904deSPeter Grehan 			igc_put_hw_semaphore_generic(hw);
396517904deSPeter Grehan 			for (i = 0; i < timeout; i++) {
397517904deSPeter Grehan 				swsm = IGC_READ_REG(hw, IGC_SWSM);
398517904deSPeter Grehan 				if (!(swsm & IGC_SWSM_SMBI))
399517904deSPeter Grehan 					break;
400517904deSPeter Grehan 
401517904deSPeter Grehan 				usec_delay(50);
402517904deSPeter Grehan 			}
403517904deSPeter Grehan 		}
404517904deSPeter Grehan 
405517904deSPeter Grehan 		/* If we do not have the semaphore here, we have to give up. */
406517904deSPeter Grehan 		if (i == timeout) {
407517904deSPeter Grehan 			DEBUGOUT("Driver can't access device -\n");
408517904deSPeter Grehan 			DEBUGOUT("SMBI bit is set.\n");
409517904deSPeter Grehan 			return -IGC_ERR_NVM;
410517904deSPeter Grehan 		}
411517904deSPeter Grehan 	}
412517904deSPeter Grehan 
413517904deSPeter Grehan 	/* Get the FW semaphore. */
414517904deSPeter Grehan 	for (i = 0; i < timeout; i++) {
415517904deSPeter Grehan 		swsm = IGC_READ_REG(hw, IGC_SWSM);
416517904deSPeter Grehan 		IGC_WRITE_REG(hw, IGC_SWSM, swsm | IGC_SWSM_SWESMBI);
417517904deSPeter Grehan 
418517904deSPeter Grehan 		/* Semaphore acquired if bit latched */
419517904deSPeter Grehan 		if (IGC_READ_REG(hw, IGC_SWSM) & IGC_SWSM_SWESMBI)
420517904deSPeter Grehan 			break;
421517904deSPeter Grehan 
422517904deSPeter Grehan 		usec_delay(50);
423517904deSPeter Grehan 	}
424517904deSPeter Grehan 
425517904deSPeter Grehan 	if (i == timeout) {
426517904deSPeter Grehan 		/* Release semaphores */
427517904deSPeter Grehan 		igc_put_hw_semaphore_generic(hw);
428517904deSPeter Grehan 		DEBUGOUT("Driver can't access the NVM\n");
429517904deSPeter Grehan 		return -IGC_ERR_NVM;
430517904deSPeter Grehan 	}
431517904deSPeter Grehan 
432517904deSPeter Grehan 	return IGC_SUCCESS;
433517904deSPeter Grehan }
434517904deSPeter Grehan 
435517904deSPeter Grehan /* igc_read_nvm_srrd_i225 - Reads Shadow Ram using EERD register
436517904deSPeter Grehan  * @hw: pointer to the HW structure
437517904deSPeter Grehan  * @offset: offset of word in the Shadow Ram to read
438517904deSPeter Grehan  * @words: number of words to read
439517904deSPeter Grehan  * @data: word read from the Shadow Ram
440517904deSPeter Grehan  *
441517904deSPeter Grehan  * Reads a 16 bit word from the Shadow Ram using the EERD register.
442517904deSPeter Grehan  * Uses necessary synchronization semaphores.
443517904deSPeter Grehan  */
igc_read_nvm_srrd_i225(struct igc_hw * hw,u16 offset,u16 words,u16 * data)444517904deSPeter Grehan s32 igc_read_nvm_srrd_i225(struct igc_hw *hw, u16 offset, u16 words,
445517904deSPeter Grehan 			     u16 *data)
446517904deSPeter Grehan {
447517904deSPeter Grehan 	s32 status = IGC_SUCCESS;
448517904deSPeter Grehan 	u16 i, count;
449517904deSPeter Grehan 
450517904deSPeter Grehan 	DEBUGFUNC("igc_read_nvm_srrd_i225");
451517904deSPeter Grehan 
452517904deSPeter Grehan 	/* We cannot hold synchronization semaphores for too long,
453517904deSPeter Grehan 	 * because of forceful takeover procedure. However it is more efficient
454517904deSPeter Grehan 	 * to read in bursts than synchronizing access for each word.
455517904deSPeter Grehan 	 */
456517904deSPeter Grehan 	for (i = 0; i < words; i += IGC_EERD_EEWR_MAX_COUNT) {
457517904deSPeter Grehan 		count = (words - i) / IGC_EERD_EEWR_MAX_COUNT > 0 ?
458517904deSPeter Grehan 			IGC_EERD_EEWR_MAX_COUNT : (words - i);
459517904deSPeter Grehan 		if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
460517904deSPeter Grehan 			status = igc_read_nvm_eerd(hw, offset, count,
461517904deSPeter Grehan 						     data + i);
462517904deSPeter Grehan 			hw->nvm.ops.release(hw);
463517904deSPeter Grehan 		} else {
464517904deSPeter Grehan 			status = IGC_ERR_SWFW_SYNC;
465517904deSPeter Grehan 		}
466517904deSPeter Grehan 
467517904deSPeter Grehan 		if (status != IGC_SUCCESS)
468517904deSPeter Grehan 			break;
469517904deSPeter Grehan 	}
470517904deSPeter Grehan 
471517904deSPeter Grehan 	return status;
472517904deSPeter Grehan }
473517904deSPeter Grehan 
474517904deSPeter Grehan /* igc_write_nvm_srwr_i225 - Write to Shadow RAM using EEWR
475517904deSPeter Grehan  * @hw: pointer to the HW structure
476517904deSPeter Grehan  * @offset: offset within the Shadow RAM to be written to
477517904deSPeter Grehan  * @words: number of words to write
478517904deSPeter Grehan  * @data: 16 bit word(s) to be written to the Shadow RAM
479517904deSPeter Grehan  *
480517904deSPeter Grehan  * Writes data to Shadow RAM at offset using EEWR register.
481517904deSPeter Grehan  *
482517904deSPeter Grehan  * If igc_update_nvm_checksum is not called after this function , the
483517904deSPeter Grehan  * data will not be committed to FLASH and also Shadow RAM will most likely
484517904deSPeter Grehan  * contain an invalid checksum.
485517904deSPeter Grehan  *
486517904deSPeter Grehan  * If error code is returned, data and Shadow RAM may be inconsistent - buffer
487517904deSPeter Grehan  * partially written.
488517904deSPeter Grehan  */
igc_write_nvm_srwr_i225(struct igc_hw * hw,u16 offset,u16 words,u16 * data)489517904deSPeter Grehan s32 igc_write_nvm_srwr_i225(struct igc_hw *hw, u16 offset, u16 words,
490517904deSPeter Grehan 			      u16 *data)
491517904deSPeter Grehan {
492517904deSPeter Grehan 	s32 status = IGC_SUCCESS;
493517904deSPeter Grehan 	u16 i, count;
494517904deSPeter Grehan 
495517904deSPeter Grehan 	DEBUGFUNC("igc_write_nvm_srwr_i225");
496517904deSPeter Grehan 
497517904deSPeter Grehan 	/* We cannot hold synchronization semaphores for too long,
498517904deSPeter Grehan 	 * because of forceful takeover procedure. However it is more efficient
499517904deSPeter Grehan 	 * to write in bursts than synchronizing access for each word.
500517904deSPeter Grehan 	 */
501517904deSPeter Grehan 	for (i = 0; i < words; i += IGC_EERD_EEWR_MAX_COUNT) {
502517904deSPeter Grehan 		count = (words - i) / IGC_EERD_EEWR_MAX_COUNT > 0 ?
503517904deSPeter Grehan 			IGC_EERD_EEWR_MAX_COUNT : (words - i);
504517904deSPeter Grehan 		if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
505517904deSPeter Grehan 			status = __igc_write_nvm_srwr(hw, offset, count,
506517904deSPeter Grehan 							data + i);
507517904deSPeter Grehan 			hw->nvm.ops.release(hw);
508517904deSPeter Grehan 		} else {
509517904deSPeter Grehan 			status = IGC_ERR_SWFW_SYNC;
510517904deSPeter Grehan 		}
511517904deSPeter Grehan 
512517904deSPeter Grehan 		if (status != IGC_SUCCESS)
513517904deSPeter Grehan 			break;
514517904deSPeter Grehan 	}
515517904deSPeter Grehan 
516517904deSPeter Grehan 	return status;
517517904deSPeter Grehan }
518517904deSPeter Grehan 
519517904deSPeter Grehan /* __igc_write_nvm_srwr - Write to Shadow Ram using EEWR
520517904deSPeter Grehan  * @hw: pointer to the HW structure
521517904deSPeter Grehan  * @offset: offset within the Shadow Ram to be written to
522517904deSPeter Grehan  * @words: number of words to write
523517904deSPeter Grehan  * @data: 16 bit word(s) to be written to the Shadow Ram
524517904deSPeter Grehan  *
525517904deSPeter Grehan  * Writes data to Shadow Ram at offset using EEWR register.
526517904deSPeter Grehan  *
527517904deSPeter Grehan  * If igc_update_nvm_checksum is not called after this function , the
528517904deSPeter Grehan  * Shadow Ram will most likely contain an invalid checksum.
529517904deSPeter Grehan  */
__igc_write_nvm_srwr(struct igc_hw * hw,u16 offset,u16 words,u16 * data)530517904deSPeter Grehan static s32 __igc_write_nvm_srwr(struct igc_hw *hw, u16 offset, u16 words,
531517904deSPeter Grehan 				  u16 *data)
532517904deSPeter Grehan {
533517904deSPeter Grehan 	struct igc_nvm_info *nvm = &hw->nvm;
534517904deSPeter Grehan 	u32 i, k, eewr = 0;
535517904deSPeter Grehan 	u32 attempts = 100000;
536517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
537517904deSPeter Grehan 
538517904deSPeter Grehan 	DEBUGFUNC("__igc_write_nvm_srwr");
539517904deSPeter Grehan 
540517904deSPeter Grehan 	/* A check for invalid values:  offset too large, too many words,
541517904deSPeter Grehan 	 * too many words for the offset, and not enough words.
542517904deSPeter Grehan 	 */
543517904deSPeter Grehan 	if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
544517904deSPeter Grehan 	    (words == 0)) {
545517904deSPeter Grehan 		DEBUGOUT("nvm parameter(s) out of bounds\n");
546517904deSPeter Grehan 		ret_val = -IGC_ERR_NVM;
547517904deSPeter Grehan 		goto out;
548517904deSPeter Grehan 	}
549517904deSPeter Grehan 
550517904deSPeter Grehan 	for (i = 0; i < words; i++) {
551517904deSPeter Grehan 		eewr = ((offset + i) << IGC_NVM_RW_ADDR_SHIFT) |
552517904deSPeter Grehan 			(data[i] << IGC_NVM_RW_REG_DATA) |
553517904deSPeter Grehan 			IGC_NVM_RW_REG_START;
554517904deSPeter Grehan 
555517904deSPeter Grehan 		IGC_WRITE_REG(hw, IGC_SRWR, eewr);
556517904deSPeter Grehan 
557517904deSPeter Grehan 		for (k = 0; k < attempts; k++) {
558517904deSPeter Grehan 			if (IGC_NVM_RW_REG_DONE &
559517904deSPeter Grehan 			    IGC_READ_REG(hw, IGC_SRWR)) {
560517904deSPeter Grehan 				ret_val = IGC_SUCCESS;
561517904deSPeter Grehan 				break;
562517904deSPeter Grehan 			}
563517904deSPeter Grehan 			usec_delay(5);
564517904deSPeter Grehan 		}
565517904deSPeter Grehan 
566517904deSPeter Grehan 		if (ret_val != IGC_SUCCESS) {
567517904deSPeter Grehan 			DEBUGOUT("Shadow RAM write EEWR timed out\n");
568517904deSPeter Grehan 			break;
569517904deSPeter Grehan 		}
570517904deSPeter Grehan 	}
571517904deSPeter Grehan 
572517904deSPeter Grehan out:
573517904deSPeter Grehan 	return ret_val;
574517904deSPeter Grehan }
575517904deSPeter Grehan 
576517904deSPeter Grehan /* igc_validate_nvm_checksum_i225 - Validate EEPROM checksum
577517904deSPeter Grehan  * @hw: pointer to the HW structure
578517904deSPeter Grehan  *
579517904deSPeter Grehan  * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
580517904deSPeter Grehan  * and then verifies that the sum of the EEPROM is equal to 0xBABA.
581517904deSPeter Grehan  */
igc_validate_nvm_checksum_i225(struct igc_hw * hw)582517904deSPeter Grehan s32 igc_validate_nvm_checksum_i225(struct igc_hw *hw)
583517904deSPeter Grehan {
584517904deSPeter Grehan 	s32 status = IGC_SUCCESS;
585517904deSPeter Grehan 	s32 (*read_op_ptr)(struct igc_hw *, u16, u16, u16 *);
586517904deSPeter Grehan 
587517904deSPeter Grehan 	DEBUGFUNC("igc_validate_nvm_checksum_i225");
588517904deSPeter Grehan 
589517904deSPeter Grehan 	if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
590517904deSPeter Grehan 		/* Replace the read function with semaphore grabbing with
591517904deSPeter Grehan 		 * the one that skips this for a while.
592517904deSPeter Grehan 		 * We have semaphore taken already here.
593517904deSPeter Grehan 		 */
594517904deSPeter Grehan 		read_op_ptr = hw->nvm.ops.read;
595517904deSPeter Grehan 		hw->nvm.ops.read = igc_read_nvm_eerd;
596517904deSPeter Grehan 
597517904deSPeter Grehan 		status = igc_validate_nvm_checksum_generic(hw);
598517904deSPeter Grehan 
599517904deSPeter Grehan 		/* Revert original read operation. */
600517904deSPeter Grehan 		hw->nvm.ops.read = read_op_ptr;
601517904deSPeter Grehan 
602517904deSPeter Grehan 		hw->nvm.ops.release(hw);
603517904deSPeter Grehan 	} else {
604517904deSPeter Grehan 		status = IGC_ERR_SWFW_SYNC;
605517904deSPeter Grehan 	}
606517904deSPeter Grehan 
607517904deSPeter Grehan 	return status;
608517904deSPeter Grehan }
609517904deSPeter Grehan 
610517904deSPeter Grehan /* igc_update_nvm_checksum_i225 - Update EEPROM checksum
611517904deSPeter Grehan  * @hw: pointer to the HW structure
612517904deSPeter Grehan  *
613517904deSPeter Grehan  * Updates the EEPROM checksum by reading/adding each word of the EEPROM
614517904deSPeter Grehan  * up to the checksum.  Then calculates the EEPROM checksum and writes the
615517904deSPeter Grehan  * value to the EEPROM. Next commit EEPROM data onto the Flash.
616517904deSPeter Grehan  */
igc_update_nvm_checksum_i225(struct igc_hw * hw)617517904deSPeter Grehan s32 igc_update_nvm_checksum_i225(struct igc_hw *hw)
618517904deSPeter Grehan {
619517904deSPeter Grehan 	s32 ret_val;
620517904deSPeter Grehan 	u16 checksum = 0;
621517904deSPeter Grehan 	u16 i, nvm_data;
622517904deSPeter Grehan 
623517904deSPeter Grehan 	DEBUGFUNC("igc_update_nvm_checksum_i225");
624517904deSPeter Grehan 
625517904deSPeter Grehan 	/* Read the first word from the EEPROM. If this times out or fails, do
626517904deSPeter Grehan 	 * not continue or we could be in for a very long wait while every
627517904deSPeter Grehan 	 * EEPROM read fails
628517904deSPeter Grehan 	 */
629517904deSPeter Grehan 	ret_val = igc_read_nvm_eerd(hw, 0, 1, &nvm_data);
630517904deSPeter Grehan 	if (ret_val != IGC_SUCCESS) {
631517904deSPeter Grehan 		DEBUGOUT("EEPROM read failed\n");
632517904deSPeter Grehan 		goto out;
633517904deSPeter Grehan 	}
634517904deSPeter Grehan 
635517904deSPeter Grehan 	if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
636517904deSPeter Grehan 		/* Do not use hw->nvm.ops.write, hw->nvm.ops.read
637517904deSPeter Grehan 		 * because we do not want to take the synchronization
638517904deSPeter Grehan 		 * semaphores twice here.
639517904deSPeter Grehan 		 */
640517904deSPeter Grehan 
641517904deSPeter Grehan 		for (i = 0; i < NVM_CHECKSUM_REG; i++) {
642517904deSPeter Grehan 			ret_val = igc_read_nvm_eerd(hw, i, 1, &nvm_data);
643517904deSPeter Grehan 			if (ret_val) {
644517904deSPeter Grehan 				hw->nvm.ops.release(hw);
645517904deSPeter Grehan 				DEBUGOUT("NVM Read Error while updating\n");
646517904deSPeter Grehan 				DEBUGOUT("checksum.\n");
647517904deSPeter Grehan 				goto out;
648517904deSPeter Grehan 			}
649517904deSPeter Grehan 			checksum += nvm_data;
650517904deSPeter Grehan 		}
651517904deSPeter Grehan 		checksum = (u16)NVM_SUM - checksum;
652517904deSPeter Grehan 		ret_val = __igc_write_nvm_srwr(hw, NVM_CHECKSUM_REG, 1,
653517904deSPeter Grehan 						 &checksum);
654517904deSPeter Grehan 		if (ret_val != IGC_SUCCESS) {
655517904deSPeter Grehan 			hw->nvm.ops.release(hw);
656517904deSPeter Grehan 			DEBUGOUT("NVM Write Error while updating checksum.\n");
657517904deSPeter Grehan 			goto out;
658517904deSPeter Grehan 		}
659517904deSPeter Grehan 
660517904deSPeter Grehan 		hw->nvm.ops.release(hw);
661517904deSPeter Grehan 
662517904deSPeter Grehan 		ret_val = igc_update_flash_i225(hw);
663517904deSPeter Grehan 	} else {
664517904deSPeter Grehan 		ret_val = IGC_ERR_SWFW_SYNC;
665517904deSPeter Grehan 	}
666517904deSPeter Grehan out:
667517904deSPeter Grehan 	return ret_val;
668517904deSPeter Grehan }
669517904deSPeter Grehan 
670517904deSPeter Grehan /* igc_get_flash_presence_i225 - Check if flash device is detected.
671517904deSPeter Grehan  * @hw: pointer to the HW structure
672517904deSPeter Grehan  */
igc_get_flash_presence_i225(struct igc_hw * hw)673517904deSPeter Grehan bool igc_get_flash_presence_i225(struct igc_hw *hw)
674517904deSPeter Grehan {
675517904deSPeter Grehan 	u32 eec = 0;
676517904deSPeter Grehan 	bool ret_val = false;
677517904deSPeter Grehan 
678517904deSPeter Grehan 	DEBUGFUNC("igc_get_flash_presence_i225");
679517904deSPeter Grehan 
680517904deSPeter Grehan 	eec = IGC_READ_REG(hw, IGC_EECD);
681517904deSPeter Grehan 
682517904deSPeter Grehan 	if (eec & IGC_EECD_FLASH_DETECTED_I225)
683517904deSPeter Grehan 		ret_val = true;
684517904deSPeter Grehan 
685517904deSPeter Grehan 	return ret_val;
686517904deSPeter Grehan }
687517904deSPeter Grehan 
688517904deSPeter Grehan /* igc_set_flsw_flash_burst_counter_i225 - sets FLSW NVM Burst
689517904deSPeter Grehan  * Counter in FLSWCNT register.
690517904deSPeter Grehan  *
691517904deSPeter Grehan  * @hw: pointer to the HW structure
692517904deSPeter Grehan  * @burst_counter: size in bytes of the Flash burst to read or write
693517904deSPeter Grehan  */
igc_set_flsw_flash_burst_counter_i225(struct igc_hw * hw,u32 burst_counter)694517904deSPeter Grehan s32 igc_set_flsw_flash_burst_counter_i225(struct igc_hw *hw,
695517904deSPeter Grehan 					    u32 burst_counter)
696517904deSPeter Grehan {
697517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
698517904deSPeter Grehan 
699517904deSPeter Grehan 	DEBUGFUNC("igc_set_flsw_flash_burst_counter_i225");
700517904deSPeter Grehan 
701517904deSPeter Grehan 	/* Validate input data */
702517904deSPeter Grehan 	if (burst_counter < IGC_I225_SHADOW_RAM_SIZE) {
703517904deSPeter Grehan 		/* Write FLSWCNT - burst counter */
704517904deSPeter Grehan 		IGC_WRITE_REG(hw, IGC_I225_FLSWCNT, burst_counter);
705517904deSPeter Grehan 	} else {
706517904deSPeter Grehan 		ret_val = IGC_ERR_INVALID_ARGUMENT;
707517904deSPeter Grehan 	}
708517904deSPeter Grehan 
709517904deSPeter Grehan 	return ret_val;
710517904deSPeter Grehan }
711517904deSPeter Grehan 
712517904deSPeter Grehan /* igc_write_erase_flash_command_i225 - write/erase to a sector
713517904deSPeter Grehan  * region on a given address.
714517904deSPeter Grehan  *
715517904deSPeter Grehan  * @hw: pointer to the HW structure
716517904deSPeter Grehan  * @opcode: opcode to be used for the write command
717517904deSPeter Grehan  * @address: the offset to write into the FLASH image
718517904deSPeter Grehan  */
igc_write_erase_flash_command_i225(struct igc_hw * hw,u32 opcode,u32 address)719517904deSPeter Grehan s32 igc_write_erase_flash_command_i225(struct igc_hw *hw, u32 opcode,
720517904deSPeter Grehan 					 u32 address)
721517904deSPeter Grehan {
722517904deSPeter Grehan 	u32 flswctl = 0;
723517904deSPeter Grehan 	s32 timeout = IGC_NVM_GRANT_ATTEMPTS;
724517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
725517904deSPeter Grehan 
726517904deSPeter Grehan 	DEBUGFUNC("igc_write_erase_flash_command_i225");
727517904deSPeter Grehan 
728517904deSPeter Grehan 	flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
729517904deSPeter Grehan 	/* Polling done bit on FLSWCTL register */
730517904deSPeter Grehan 	while (timeout) {
731517904deSPeter Grehan 		if (flswctl & IGC_FLSWCTL_DONE)
732517904deSPeter Grehan 			break;
733517904deSPeter Grehan 		usec_delay(5);
734517904deSPeter Grehan 		flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
735517904deSPeter Grehan 		timeout--;
736517904deSPeter Grehan 	}
737517904deSPeter Grehan 
738517904deSPeter Grehan 	if (!timeout) {
739517904deSPeter Grehan 		DEBUGOUT("Flash transaction was not done\n");
740517904deSPeter Grehan 		return -IGC_ERR_NVM;
741517904deSPeter Grehan 	}
742517904deSPeter Grehan 
743517904deSPeter Grehan 	/* Build and issue command on FLSWCTL register */
744517904deSPeter Grehan 	flswctl = address | opcode;
745517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_I225_FLSWCTL, flswctl);
746517904deSPeter Grehan 
747517904deSPeter Grehan 	/* Check if issued command is valid on FLSWCTL register */
748517904deSPeter Grehan 	flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
749517904deSPeter Grehan 	if (!(flswctl & IGC_FLSWCTL_CMDV)) {
750517904deSPeter Grehan 		DEBUGOUT("Write flash command failed\n");
751517904deSPeter Grehan 		ret_val = IGC_ERR_INVALID_ARGUMENT;
752517904deSPeter Grehan 	}
753517904deSPeter Grehan 
754517904deSPeter Grehan 	return ret_val;
755517904deSPeter Grehan }
756517904deSPeter Grehan 
757517904deSPeter Grehan /* igc_update_flash_i225 - Commit EEPROM to the flash
758517904deSPeter Grehan  * if fw_valid_bit is set, FW is active. setting FLUPD bit in EEC
759517904deSPeter Grehan  * register makes the FW load the internal shadow RAM into the flash.
760517904deSPeter Grehan  * Otherwise, fw_valid_bit is 0. if FL_SECU.block_prtotected_sw = 0
761517904deSPeter Grehan  * then FW is not active so the SW is responsible shadow RAM dump.
762517904deSPeter Grehan  *
763517904deSPeter Grehan  * @hw: pointer to the HW structure
764517904deSPeter Grehan  */
igc_update_flash_i225(struct igc_hw * hw)765517904deSPeter Grehan s32 igc_update_flash_i225(struct igc_hw *hw)
766517904deSPeter Grehan {
767517904deSPeter Grehan 	u16 current_offset_data = 0;
768517904deSPeter Grehan 	u32 block_sw_protect = 1;
769517904deSPeter Grehan 	u16 base_address = 0x0;
770517904deSPeter Grehan 	u32 i, fw_valid_bit;
771517904deSPeter Grehan 	u16 current_offset;
772517904deSPeter Grehan 	s32 ret_val = 0;
773517904deSPeter Grehan 	u32 flup;
774517904deSPeter Grehan 
775517904deSPeter Grehan 	DEBUGFUNC("igc_update_flash_i225");
776517904deSPeter Grehan 
777517904deSPeter Grehan 	block_sw_protect = IGC_READ_REG(hw, IGC_I225_FLSECU) &
778517904deSPeter Grehan 					  IGC_FLSECU_BLK_SW_ACCESS_I225;
779517904deSPeter Grehan 	fw_valid_bit = IGC_READ_REG(hw, IGC_FWSM) &
780517904deSPeter Grehan 				      IGC_FWSM_FW_VALID_I225;
781517904deSPeter Grehan 	if (fw_valid_bit) {
782517904deSPeter Grehan 		ret_val = igc_pool_flash_update_done_i225(hw);
783517904deSPeter Grehan 		if (ret_val == -IGC_ERR_NVM) {
784517904deSPeter Grehan 			DEBUGOUT("Flash update time out\n");
785517904deSPeter Grehan 			goto out;
786517904deSPeter Grehan 		}
787517904deSPeter Grehan 
788517904deSPeter Grehan 		flup = IGC_READ_REG(hw, IGC_EECD) | IGC_EECD_FLUPD_I225;
789517904deSPeter Grehan 		IGC_WRITE_REG(hw, IGC_EECD, flup);
790517904deSPeter Grehan 
791517904deSPeter Grehan 		ret_val = igc_pool_flash_update_done_i225(hw);
792517904deSPeter Grehan 		if (ret_val == IGC_SUCCESS)
793517904deSPeter Grehan 			DEBUGOUT("Flash update complete\n");
794517904deSPeter Grehan 		else
795517904deSPeter Grehan 			DEBUGOUT("Flash update time out\n");
796517904deSPeter Grehan 	} else if (!block_sw_protect) {
797517904deSPeter Grehan 		/* FW is not active and security protection is disabled.
798517904deSPeter Grehan 		 * therefore, SW is in charge of shadow RAM dump.
799517904deSPeter Grehan 		 * Check which sector is valid. if sector 0 is valid,
800517904deSPeter Grehan 		 * base address remains 0x0. otherwise, sector 1 is
801517904deSPeter Grehan 		 * valid and it's base address is 0x1000
802517904deSPeter Grehan 		 */
803517904deSPeter Grehan 		if (IGC_READ_REG(hw, IGC_EECD) & IGC_EECD_SEC1VAL_I225)
804517904deSPeter Grehan 			base_address = 0x1000;
805517904deSPeter Grehan 
806517904deSPeter Grehan 		/* Valid sector erase */
807517904deSPeter Grehan 		ret_val = igc_write_erase_flash_command_i225(hw,
808517904deSPeter Grehan 						  IGC_I225_ERASE_CMD_OPCODE,
809517904deSPeter Grehan 						  base_address);
810517904deSPeter Grehan 		if (!ret_val) {
811517904deSPeter Grehan 			DEBUGOUT("Sector erase failed\n");
812517904deSPeter Grehan 			goto out;
813517904deSPeter Grehan 		}
814517904deSPeter Grehan 
815517904deSPeter Grehan 		current_offset = base_address;
816517904deSPeter Grehan 
817517904deSPeter Grehan 		/* Write */
818517904deSPeter Grehan 		for (i = 0; i < IGC_I225_SHADOW_RAM_SIZE / 2; i++) {
819517904deSPeter Grehan 			/* Set burst write length */
820517904deSPeter Grehan 			ret_val = igc_set_flsw_flash_burst_counter_i225(hw,
821517904deSPeter Grehan 									  0x2);
822517904deSPeter Grehan 			if (ret_val != IGC_SUCCESS)
823517904deSPeter Grehan 				break;
824517904deSPeter Grehan 
825517904deSPeter Grehan 			/* Set address and opcode */
826517904deSPeter Grehan 			ret_val = igc_write_erase_flash_command_i225(hw,
827517904deSPeter Grehan 						IGC_I225_WRITE_CMD_OPCODE,
828517904deSPeter Grehan 						2 * current_offset);
829517904deSPeter Grehan 			if (ret_val != IGC_SUCCESS)
830517904deSPeter Grehan 				break;
831517904deSPeter Grehan 
832517904deSPeter Grehan 			ret_val = igc_read_nvm_eerd(hw, current_offset,
833517904deSPeter Grehan 						      1, &current_offset_data);
834517904deSPeter Grehan 			if (ret_val) {
835517904deSPeter Grehan 				DEBUGOUT("Failed to read from EEPROM\n");
836517904deSPeter Grehan 				goto out;
837517904deSPeter Grehan 			}
838517904deSPeter Grehan 
839517904deSPeter Grehan 			/* Write CurrentOffseData to FLSWDATA register */
840517904deSPeter Grehan 			IGC_WRITE_REG(hw, IGC_I225_FLSWDATA,
841517904deSPeter Grehan 					current_offset_data);
842517904deSPeter Grehan 			current_offset++;
843517904deSPeter Grehan 
844517904deSPeter Grehan 			/* Wait till operation has finished */
845517904deSPeter Grehan 			ret_val = igc_poll_eerd_eewr_done(hw,
846517904deSPeter Grehan 						IGC_NVM_POLL_READ);
847517904deSPeter Grehan 			if (ret_val)
848517904deSPeter Grehan 				break;
849517904deSPeter Grehan 
850517904deSPeter Grehan 			usec_delay(1000);
851517904deSPeter Grehan 		}
852517904deSPeter Grehan 	}
853517904deSPeter Grehan out:
854517904deSPeter Grehan 	return ret_val;
855517904deSPeter Grehan }
856517904deSPeter Grehan 
857517904deSPeter Grehan /* igc_pool_flash_update_done_i225 - Pool FLUDONE status.
858517904deSPeter Grehan  * @hw: pointer to the HW structure
859517904deSPeter Grehan  */
igc_pool_flash_update_done_i225(struct igc_hw * hw)860517904deSPeter Grehan s32 igc_pool_flash_update_done_i225(struct igc_hw *hw)
861517904deSPeter Grehan {
862517904deSPeter Grehan 	s32 ret_val = -IGC_ERR_NVM;
863517904deSPeter Grehan 	u32 i, reg;
864517904deSPeter Grehan 
865517904deSPeter Grehan 	DEBUGFUNC("igc_pool_flash_update_done_i225");
866517904deSPeter Grehan 
867517904deSPeter Grehan 	for (i = 0; i < IGC_FLUDONE_ATTEMPTS; i++) {
868517904deSPeter Grehan 		reg = IGC_READ_REG(hw, IGC_EECD);
869517904deSPeter Grehan 		if (reg & IGC_EECD_FLUDONE_I225) {
870517904deSPeter Grehan 			ret_val = IGC_SUCCESS;
871517904deSPeter Grehan 			break;
872517904deSPeter Grehan 		}
873517904deSPeter Grehan 		usec_delay(5);
874517904deSPeter Grehan 	}
875517904deSPeter Grehan 
876517904deSPeter Grehan 	return ret_val;
877517904deSPeter Grehan }
878517904deSPeter Grehan 
879517904deSPeter Grehan /* igc_set_ltr_i225 - Set Latency Tolerance Reporting thresholds.
880517904deSPeter Grehan  * @hw: pointer to the HW structure
881517904deSPeter Grehan  * @link: bool indicating link status
882517904deSPeter Grehan  *
883517904deSPeter Grehan  * Set the LTR thresholds based on the link speed (Mbps), EEE, and DMAC
884517904deSPeter Grehan  * settings, otherwise specify that there is no LTR requirement.
885517904deSPeter Grehan  */
igc_set_ltr_i225(struct igc_hw * hw,bool link)886517904deSPeter Grehan static s32 igc_set_ltr_i225(struct igc_hw *hw, bool link)
887517904deSPeter Grehan {
888517904deSPeter Grehan 	u16 speed, duplex;
889517904deSPeter Grehan 	u32 tw_system, ltrc, ltrv, ltr_min, ltr_max, scale_min, scale_max;
890517904deSPeter Grehan 	s32 size;
891517904deSPeter Grehan 
892517904deSPeter Grehan 	DEBUGFUNC("igc_set_ltr_i225");
893517904deSPeter Grehan 
894517904deSPeter Grehan 	/* If we do not have link, LTR thresholds are zero. */
895517904deSPeter Grehan 	if (link) {
896517904deSPeter Grehan 		hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
897517904deSPeter Grehan 
898517904deSPeter Grehan 		/* Check if using copper interface with EEE enabled or if the
899517904deSPeter Grehan 		 * link speed is 10 Mbps.
900517904deSPeter Grehan 		 */
901517904deSPeter Grehan 		if ((hw->phy.media_type == igc_media_type_copper) &&
902517904deSPeter Grehan 		    !(hw->dev_spec._i225.eee_disable) &&
903517904deSPeter Grehan 		     (speed != SPEED_10)) {
904517904deSPeter Grehan 			/* EEE enabled, so send LTRMAX threshold. */
905517904deSPeter Grehan 			ltrc = IGC_READ_REG(hw, IGC_LTRC) |
906517904deSPeter Grehan 				IGC_LTRC_EEEMS_EN;
907517904deSPeter Grehan 			IGC_WRITE_REG(hw, IGC_LTRC, ltrc);
908517904deSPeter Grehan 
909517904deSPeter Grehan 			/* Calculate tw_system (nsec). */
910517904deSPeter Grehan 			if (speed == SPEED_100) {
911517904deSPeter Grehan 				tw_system = ((IGC_READ_REG(hw, IGC_EEE_SU) &
912517904deSPeter Grehan 					     IGC_TW_SYSTEM_100_MASK) >>
913517904deSPeter Grehan 					     IGC_TW_SYSTEM_100_SHIFT) * 500;
914517904deSPeter Grehan 			} else {
915517904deSPeter Grehan 				tw_system = (IGC_READ_REG(hw, IGC_EEE_SU) &
916517904deSPeter Grehan 					     IGC_TW_SYSTEM_1000_MASK) * 500;
917517904deSPeter Grehan 				}
918517904deSPeter Grehan 		} else {
919517904deSPeter Grehan 			tw_system = 0;
920517904deSPeter Grehan 			}
921517904deSPeter Grehan 
922517904deSPeter Grehan 		/* Get the Rx packet buffer size. */
923517904deSPeter Grehan 		size = IGC_READ_REG(hw, IGC_RXPBS) &
924517904deSPeter Grehan 			IGC_RXPBS_SIZE_I225_MASK;
925517904deSPeter Grehan 
926517904deSPeter Grehan 		/* Calculations vary based on DMAC settings. */
927517904deSPeter Grehan 		if (IGC_READ_REG(hw, IGC_DMACR) & IGC_DMACR_DMAC_EN) {
928517904deSPeter Grehan 			size -= (IGC_READ_REG(hw, IGC_DMACR) &
929517904deSPeter Grehan 				 IGC_DMACR_DMACTHR_MASK) >>
930517904deSPeter Grehan 				 IGC_DMACR_DMACTHR_SHIFT;
931517904deSPeter Grehan 			/* Convert size to bits. */
932517904deSPeter Grehan 			size *= 1024 * 8;
933517904deSPeter Grehan 		} else {
934517904deSPeter Grehan 			/* Convert size to bytes, subtract the MTU, and then
935517904deSPeter Grehan 			 * convert the size to bits.
936517904deSPeter Grehan 			 */
937517904deSPeter Grehan 			size *= 1024;
938517904deSPeter Grehan 			size -= hw->dev_spec._i225.mtu;
939517904deSPeter Grehan 			size *= 8;
940517904deSPeter Grehan 		}
941517904deSPeter Grehan 
942517904deSPeter Grehan 		if (size < 0) {
943517904deSPeter Grehan 			DEBUGOUT1("Invalid effective Rx buffer size %d\n",
944517904deSPeter Grehan 				  size);
945517904deSPeter Grehan 			return -IGC_ERR_CONFIG;
946517904deSPeter Grehan 		}
947517904deSPeter Grehan 
948517904deSPeter Grehan 		/* Calculate the thresholds. Since speed is in Mbps, simplify
949517904deSPeter Grehan 		 * the calculation by multiplying size/speed by 1000 for result
950517904deSPeter Grehan 		 * to be in nsec before dividing by the scale in nsec. Set the
951517904deSPeter Grehan 		 * scale such that the LTR threshold fits in the register.
952517904deSPeter Grehan 		 */
953517904deSPeter Grehan 		ltr_min = (1000 * size) / speed;
954517904deSPeter Grehan 		ltr_max = ltr_min + tw_system;
955517904deSPeter Grehan 		scale_min = (ltr_min / 1024) < 1024 ? IGC_LTRMINV_SCALE_1024 :
956517904deSPeter Grehan 			    IGC_LTRMINV_SCALE_32768;
957517904deSPeter Grehan 		scale_max = (ltr_max / 1024) < 1024 ? IGC_LTRMAXV_SCALE_1024 :
958517904deSPeter Grehan 			    IGC_LTRMAXV_SCALE_32768;
959517904deSPeter Grehan 		ltr_min /= scale_min == IGC_LTRMINV_SCALE_1024 ? 1024 : 32768;
960517904deSPeter Grehan 		ltr_max /= scale_max == IGC_LTRMAXV_SCALE_1024 ? 1024 : 32768;
961517904deSPeter Grehan 
962517904deSPeter Grehan 		/* Only write the LTR thresholds if they differ from before. */
963517904deSPeter Grehan 		ltrv = IGC_READ_REG(hw, IGC_LTRMINV);
964517904deSPeter Grehan 		if (ltr_min != (ltrv & IGC_LTRMINV_LTRV_MASK)) {
965517904deSPeter Grehan 			ltrv = IGC_LTRMINV_LSNP_REQ | ltr_min |
966517904deSPeter Grehan 			      (scale_min << IGC_LTRMINV_SCALE_SHIFT);
967517904deSPeter Grehan 			IGC_WRITE_REG(hw, IGC_LTRMINV, ltrv);
968517904deSPeter Grehan 		}
969517904deSPeter Grehan 
970517904deSPeter Grehan 		ltrv = IGC_READ_REG(hw, IGC_LTRMAXV);
971517904deSPeter Grehan 		if (ltr_max != (ltrv & IGC_LTRMAXV_LTRV_MASK)) {
972517904deSPeter Grehan 			ltrv = IGC_LTRMAXV_LSNP_REQ | ltr_max |
973517904deSPeter Grehan 			      (scale_min << IGC_LTRMAXV_SCALE_SHIFT);
974517904deSPeter Grehan 			IGC_WRITE_REG(hw, IGC_LTRMAXV, ltrv);
975517904deSPeter Grehan 		}
976517904deSPeter Grehan 	}
977517904deSPeter Grehan 
978517904deSPeter Grehan 	return IGC_SUCCESS;
979517904deSPeter Grehan }
980517904deSPeter Grehan 
981517904deSPeter Grehan /* igc_check_for_link_i225 - Check for link
982517904deSPeter Grehan  * @hw: pointer to the HW structure
983517904deSPeter Grehan  *
984517904deSPeter Grehan  * Checks to see of the link status of the hardware has changed.  If a
985517904deSPeter Grehan  * change in link status has been detected, then we read the PHY registers
986517904deSPeter Grehan  * to get the current speed/duplex if link exists.
987517904deSPeter Grehan  */
igc_check_for_link_i225(struct igc_hw * hw)988517904deSPeter Grehan s32 igc_check_for_link_i225(struct igc_hw *hw)
989517904deSPeter Grehan {
990517904deSPeter Grehan 	struct igc_mac_info *mac = &hw->mac;
991517904deSPeter Grehan 	s32 ret_val;
992517904deSPeter Grehan 	bool link = false;
993517904deSPeter Grehan 
994517904deSPeter Grehan 	DEBUGFUNC("igc_check_for_link_i225");
995517904deSPeter Grehan 
996517904deSPeter Grehan 	/* We only want to go out to the PHY registers to see if
997517904deSPeter Grehan 	 * Auto-Neg has completed and/or if our link status has
998517904deSPeter Grehan 	 * changed.  The get_link_status flag is set upon receiving
999517904deSPeter Grehan 	 * a Link Status Change or Rx Sequence Error interrupt.
1000517904deSPeter Grehan 	 */
1001517904deSPeter Grehan 	if (!mac->get_link_status) {
1002517904deSPeter Grehan 		ret_val = IGC_SUCCESS;
1003517904deSPeter Grehan 		goto out;
1004517904deSPeter Grehan 	}
1005517904deSPeter Grehan 
1006517904deSPeter Grehan 	/* First we want to see if the MII Status Register reports
1007517904deSPeter Grehan 	 * link.  If so, then we want to get the current speed/duplex
1008517904deSPeter Grehan 	 * of the PHY.
1009517904deSPeter Grehan 	 */
1010517904deSPeter Grehan 	ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
1011517904deSPeter Grehan 	if (ret_val)
1012517904deSPeter Grehan 		goto out;
1013517904deSPeter Grehan 
1014517904deSPeter Grehan 	if (!link)
1015517904deSPeter Grehan 		goto out; /* No link detected */
1016517904deSPeter Grehan 
1017517904deSPeter Grehan 	/* First we want to see if the MII Status Register reports
1018517904deSPeter Grehan 	 * link.  If so, then we want to get the current speed/duplex
1019517904deSPeter Grehan 	 * of the PHY.
1020517904deSPeter Grehan 	 */
1021517904deSPeter Grehan 	ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
1022517904deSPeter Grehan 	if (ret_val)
1023517904deSPeter Grehan 		goto out;
1024517904deSPeter Grehan 
1025517904deSPeter Grehan 	if (!link)
1026517904deSPeter Grehan 		goto out; /* No link detected */
1027517904deSPeter Grehan 
1028517904deSPeter Grehan 	mac->get_link_status = false;
1029517904deSPeter Grehan 
1030517904deSPeter Grehan 	/* Check if there was DownShift, must be checked
1031517904deSPeter Grehan 	 * immediately after link-up
1032517904deSPeter Grehan 	 */
1033517904deSPeter Grehan 	igc_check_downshift_generic(hw);
1034517904deSPeter Grehan 
1035517904deSPeter Grehan 	/* If we are forcing speed/duplex, then we simply return since
1036517904deSPeter Grehan 	 * we have already determined whether we have link or not.
1037517904deSPeter Grehan 	 */
1038517904deSPeter Grehan 	if (!mac->autoneg)
1039517904deSPeter Grehan 		goto out;
1040517904deSPeter Grehan 
1041517904deSPeter Grehan 	/* Auto-Neg is enabled.  Auto Speed Detection takes care
1042517904deSPeter Grehan 	 * of MAC speed/duplex configuration.  So we only need to
1043517904deSPeter Grehan 	 * configure Collision Distance in the MAC.
1044517904deSPeter Grehan 	 */
1045517904deSPeter Grehan 	mac->ops.config_collision_dist(hw);
1046517904deSPeter Grehan 
1047517904deSPeter Grehan 	/* Configure Flow Control now that Auto-Neg has completed.
1048517904deSPeter Grehan 	 * First, we need to restore the desired flow control
1049517904deSPeter Grehan 	 * settings because we may have had to re-autoneg with a
1050517904deSPeter Grehan 	 * different link partner.
1051517904deSPeter Grehan 	 */
1052517904deSPeter Grehan 	ret_val = igc_config_fc_after_link_up_generic(hw);
1053517904deSPeter Grehan 	if (ret_val)
1054517904deSPeter Grehan 		DEBUGOUT("Error configuring flow control\n");
1055517904deSPeter Grehan out:
1056517904deSPeter Grehan 	/* Now that we are aware of our link settings, we can set the LTR
1057517904deSPeter Grehan 	 * thresholds.
1058517904deSPeter Grehan 	 */
1059517904deSPeter Grehan 	ret_val = igc_set_ltr_i225(hw, link);
1060517904deSPeter Grehan 
1061517904deSPeter Grehan 	return ret_val;
1062517904deSPeter Grehan }
1063517904deSPeter Grehan 
1064517904deSPeter Grehan /* igc_init_function_pointers_i225 - Init func ptrs.
1065517904deSPeter Grehan  * @hw: pointer to the HW structure
1066517904deSPeter Grehan  *
1067517904deSPeter Grehan  * Called to initialize all function pointers and parameters.
1068517904deSPeter Grehan  */
igc_init_function_pointers_i225(struct igc_hw * hw)1069517904deSPeter Grehan void igc_init_function_pointers_i225(struct igc_hw *hw)
1070517904deSPeter Grehan {
1071517904deSPeter Grehan 	igc_init_mac_ops_generic(hw);
1072517904deSPeter Grehan 	igc_init_phy_ops_generic(hw);
1073517904deSPeter Grehan 	igc_init_nvm_ops_generic(hw);
1074517904deSPeter Grehan 	hw->mac.ops.init_params = igc_init_mac_params_i225;
1075517904deSPeter Grehan 	hw->nvm.ops.init_params = igc_init_nvm_params_i225;
1076517904deSPeter Grehan 	hw->phy.ops.init_params = igc_init_phy_params_i225;
1077517904deSPeter Grehan }
1078517904deSPeter Grehan 
1079517904deSPeter Grehan /* igc_init_hw_i225 - Init hw for I225
1080517904deSPeter Grehan  * @hw: pointer to the HW structure
1081517904deSPeter Grehan  *
1082517904deSPeter Grehan  * Called to initialize hw for i225 hw family.
1083517904deSPeter Grehan  */
igc_init_hw_i225(struct igc_hw * hw)1084517904deSPeter Grehan s32 igc_init_hw_i225(struct igc_hw *hw)
1085517904deSPeter Grehan {
1086517904deSPeter Grehan 	s32 ret_val;
1087517904deSPeter Grehan 
1088517904deSPeter Grehan 	DEBUGFUNC("igc_init_hw_i225");
1089517904deSPeter Grehan 
1090517904deSPeter Grehan 	ret_val = igc_init_hw_base(hw);
1091517904deSPeter Grehan 	return ret_val;
1092517904deSPeter Grehan }
1093517904deSPeter Grehan 
1094517904deSPeter Grehan /*
1095517904deSPeter Grehan  * igc_set_d0_lplu_state_i225 - Set Low-Power-Link-Up (LPLU) D0 state
1096517904deSPeter Grehan  * @hw: pointer to the HW structure
1097517904deSPeter Grehan  * @active: true to enable LPLU, false to disable
1098517904deSPeter Grehan  *
1099517904deSPeter Grehan  * Note: since I225 does not actually support LPLU, this function
1100517904deSPeter Grehan  * simply enables/disables 1G and 2.5G speeds in D0.
1101517904deSPeter Grehan  */
igc_set_d0_lplu_state_i225(struct igc_hw * hw,bool active)1102517904deSPeter Grehan s32 igc_set_d0_lplu_state_i225(struct igc_hw *hw, bool active)
1103517904deSPeter Grehan {
1104517904deSPeter Grehan 	u32 data;
1105517904deSPeter Grehan 
1106517904deSPeter Grehan 	DEBUGFUNC("igc_set_d0_lplu_state_i225");
1107517904deSPeter Grehan 
1108517904deSPeter Grehan 	data = IGC_READ_REG(hw, IGC_I225_PHPM);
1109517904deSPeter Grehan 
1110517904deSPeter Grehan 	if (active) {
1111517904deSPeter Grehan 		data |= IGC_I225_PHPM_DIS_1000;
1112517904deSPeter Grehan 		data |= IGC_I225_PHPM_DIS_2500;
1113517904deSPeter Grehan 	} else {
1114517904deSPeter Grehan 		data &= ~IGC_I225_PHPM_DIS_1000;
1115517904deSPeter Grehan 		data &= ~IGC_I225_PHPM_DIS_2500;
1116517904deSPeter Grehan 	}
1117517904deSPeter Grehan 
1118517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_I225_PHPM, data);
1119517904deSPeter Grehan 	return IGC_SUCCESS;
1120517904deSPeter Grehan }
1121517904deSPeter Grehan 
1122517904deSPeter Grehan /*
1123517904deSPeter Grehan  * igc_set_d3_lplu_state_i225 - Set Low-Power-Link-Up (LPLU) D3 state
1124517904deSPeter Grehan  * @hw: pointer to the HW structure
1125517904deSPeter Grehan  * @active: true to enable LPLU, false to disable
1126517904deSPeter Grehan  *
1127517904deSPeter Grehan  * Note: since I225 does not actually support LPLU, this function
1128517904deSPeter Grehan  * simply enables/disables 100M, 1G and 2.5G speeds in D3.
1129517904deSPeter Grehan  */
igc_set_d3_lplu_state_i225(struct igc_hw * hw,bool active)1130517904deSPeter Grehan s32 igc_set_d3_lplu_state_i225(struct igc_hw *hw, bool active)
1131517904deSPeter Grehan {
1132517904deSPeter Grehan 	u32 data;
1133517904deSPeter Grehan 
1134517904deSPeter Grehan 	DEBUGFUNC("igc_set_d3_lplu_state_i225");
1135517904deSPeter Grehan 
1136517904deSPeter Grehan 	data = IGC_READ_REG(hw, IGC_I225_PHPM);
1137517904deSPeter Grehan 
1138517904deSPeter Grehan 	if (active) {
1139517904deSPeter Grehan 		data |= IGC_I225_PHPM_DIS_100_D3;
1140517904deSPeter Grehan 		data |= IGC_I225_PHPM_DIS_1000_D3;
1141517904deSPeter Grehan 		data |= IGC_I225_PHPM_DIS_2500_D3;
1142517904deSPeter Grehan 	} else {
1143517904deSPeter Grehan 		data &= ~IGC_I225_PHPM_DIS_100_D3;
1144517904deSPeter Grehan 		data &= ~IGC_I225_PHPM_DIS_1000_D3;
1145517904deSPeter Grehan 		data &= ~IGC_I225_PHPM_DIS_2500_D3;
1146517904deSPeter Grehan 	}
1147517904deSPeter Grehan 
1148517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_I225_PHPM, data);
1149517904deSPeter Grehan 	return IGC_SUCCESS;
1150517904deSPeter Grehan }
1151517904deSPeter Grehan 
1152517904deSPeter Grehan /**
1153517904deSPeter Grehan  *  igc_set_eee_i225 - Enable/disable EEE support
1154517904deSPeter Grehan  *  @hw: pointer to the HW structure
1155517904deSPeter Grehan  *  @adv2p5G: boolean flag enabling 2.5G EEE advertisement
1156517904deSPeter Grehan  *  @adv1G: boolean flag enabling 1G EEE advertisement
1157517904deSPeter Grehan  *  @adv100M: boolean flag enabling 100M EEE advertisement
1158517904deSPeter Grehan  *
1159517904deSPeter Grehan  *  Enable/disable EEE based on setting in dev_spec structure.
1160517904deSPeter Grehan  *
1161517904deSPeter Grehan  **/
igc_set_eee_i225(struct igc_hw * hw,bool adv2p5G,bool adv1G,bool adv100M)1162517904deSPeter Grehan s32 igc_set_eee_i225(struct igc_hw *hw, bool adv2p5G, bool adv1G,
1163517904deSPeter Grehan 		       bool adv100M)
1164517904deSPeter Grehan {
1165517904deSPeter Grehan 	u32 ipcnfg, eeer;
1166517904deSPeter Grehan 
1167517904deSPeter Grehan 	DEBUGFUNC("igc_set_eee_i225");
1168517904deSPeter Grehan 
1169517904deSPeter Grehan 	if (hw->mac.type != igc_i225 ||
1170517904deSPeter Grehan 	    hw->phy.media_type != igc_media_type_copper)
1171517904deSPeter Grehan 		goto out;
1172517904deSPeter Grehan 	ipcnfg = IGC_READ_REG(hw, IGC_IPCNFG);
1173517904deSPeter Grehan 	eeer = IGC_READ_REG(hw, IGC_EEER);
1174517904deSPeter Grehan 
1175517904deSPeter Grehan 	/* enable or disable per user setting */
1176517904deSPeter Grehan 	if (!(hw->dev_spec._i225.eee_disable)) {
1177517904deSPeter Grehan 		u32 eee_su = IGC_READ_REG(hw, IGC_EEE_SU);
1178517904deSPeter Grehan 
1179517904deSPeter Grehan 		if (adv100M)
1180517904deSPeter Grehan 			ipcnfg |= IGC_IPCNFG_EEE_100M_AN;
1181517904deSPeter Grehan 		else
1182517904deSPeter Grehan 			ipcnfg &= ~IGC_IPCNFG_EEE_100M_AN;
1183517904deSPeter Grehan 
1184517904deSPeter Grehan 		if (adv1G)
1185517904deSPeter Grehan 			ipcnfg |= IGC_IPCNFG_EEE_1G_AN;
1186517904deSPeter Grehan 		else
1187517904deSPeter Grehan 			ipcnfg &= ~IGC_IPCNFG_EEE_1G_AN;
1188517904deSPeter Grehan 
1189517904deSPeter Grehan 		if (adv2p5G)
1190517904deSPeter Grehan 			ipcnfg |= IGC_IPCNFG_EEE_2_5G_AN;
1191517904deSPeter Grehan 		else
1192517904deSPeter Grehan 			ipcnfg &= ~IGC_IPCNFG_EEE_2_5G_AN;
1193517904deSPeter Grehan 
1194517904deSPeter Grehan 		eeer |= (IGC_EEER_TX_LPI_EN | IGC_EEER_RX_LPI_EN |
1195517904deSPeter Grehan 			IGC_EEER_LPI_FC);
1196517904deSPeter Grehan 
1197517904deSPeter Grehan 		/* This bit should not be set in normal operation. */
1198517904deSPeter Grehan 		if (eee_su & IGC_EEE_SU_LPI_CLK_STP)
1199517904deSPeter Grehan 			DEBUGOUT("LPI Clock Stop Bit should not be set!\n");
1200517904deSPeter Grehan 	} else {
1201517904deSPeter Grehan 		ipcnfg &= ~(IGC_IPCNFG_EEE_2_5G_AN | IGC_IPCNFG_EEE_1G_AN |
1202517904deSPeter Grehan 			IGC_IPCNFG_EEE_100M_AN);
1203517904deSPeter Grehan 		eeer &= ~(IGC_EEER_TX_LPI_EN | IGC_EEER_RX_LPI_EN |
1204517904deSPeter Grehan 			IGC_EEER_LPI_FC);
1205517904deSPeter Grehan 	}
1206517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_IPCNFG, ipcnfg);
1207517904deSPeter Grehan 	IGC_WRITE_REG(hw, IGC_EEER, eeer);
1208517904deSPeter Grehan 	IGC_READ_REG(hw, IGC_IPCNFG);
1209517904deSPeter Grehan 	IGC_READ_REG(hw, IGC_EEER);
1210517904deSPeter Grehan out:
1211517904deSPeter Grehan 
1212517904deSPeter Grehan 	return IGC_SUCCESS;
1213517904deSPeter Grehan }
1214517904deSPeter Grehan 
1215