xref: /freebsd-src/sys/dev/igc/igc_api.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1*517904deSPeter Grehan /*-
2*517904deSPeter Grehan  * Copyright 2021 Intel Corp
3*517904deSPeter Grehan  * Copyright 2021 Rubicon Communications, LLC (Netgate)
4*517904deSPeter Grehan  * SPDX-License-Identifier: BSD-3-Clause
5*517904deSPeter Grehan  */
6*517904deSPeter Grehan 
7*517904deSPeter Grehan #include <sys/cdefs.h>
8*517904deSPeter Grehan #include "igc_api.h"
9*517904deSPeter Grehan 
10*517904deSPeter Grehan /**
11*517904deSPeter Grehan  *  igc_init_mac_params - Initialize MAC function pointers
12*517904deSPeter Grehan  *  @hw: pointer to the HW structure
13*517904deSPeter Grehan  *
14*517904deSPeter Grehan  *  This function initializes the function pointers for the MAC
15*517904deSPeter Grehan  *  set of functions.  Called by drivers or by igc_setup_init_funcs.
16*517904deSPeter Grehan  **/
igc_init_mac_params(struct igc_hw * hw)17*517904deSPeter Grehan s32 igc_init_mac_params(struct igc_hw *hw)
18*517904deSPeter Grehan {
19*517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
20*517904deSPeter Grehan 
21*517904deSPeter Grehan 	if (hw->mac.ops.init_params) {
22*517904deSPeter Grehan 		ret_val = hw->mac.ops.init_params(hw);
23*517904deSPeter Grehan 		if (ret_val) {
24*517904deSPeter Grehan 			DEBUGOUT("MAC Initialization Error\n");
25*517904deSPeter Grehan 			goto out;
26*517904deSPeter Grehan 		}
27*517904deSPeter Grehan 	} else {
28*517904deSPeter Grehan 		DEBUGOUT("mac.init_mac_params was NULL\n");
29*517904deSPeter Grehan 		ret_val = -IGC_ERR_CONFIG;
30*517904deSPeter Grehan 	}
31*517904deSPeter Grehan 
32*517904deSPeter Grehan out:
33*517904deSPeter Grehan 	return ret_val;
34*517904deSPeter Grehan }
35*517904deSPeter Grehan 
36*517904deSPeter Grehan /**
37*517904deSPeter Grehan  *  igc_init_nvm_params - Initialize NVM function pointers
38*517904deSPeter Grehan  *  @hw: pointer to the HW structure
39*517904deSPeter Grehan  *
40*517904deSPeter Grehan  *  This function initializes the function pointers for the NVM
41*517904deSPeter Grehan  *  set of functions.  Called by drivers or by igc_setup_init_funcs.
42*517904deSPeter Grehan  **/
igc_init_nvm_params(struct igc_hw * hw)43*517904deSPeter Grehan s32 igc_init_nvm_params(struct igc_hw *hw)
44*517904deSPeter Grehan {
45*517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
46*517904deSPeter Grehan 
47*517904deSPeter Grehan 	if (hw->nvm.ops.init_params) {
48*517904deSPeter Grehan 		ret_val = hw->nvm.ops.init_params(hw);
49*517904deSPeter Grehan 		if (ret_val) {
50*517904deSPeter Grehan 			DEBUGOUT("NVM Initialization Error\n");
51*517904deSPeter Grehan 			goto out;
52*517904deSPeter Grehan 		}
53*517904deSPeter Grehan 	} else {
54*517904deSPeter Grehan 		DEBUGOUT("nvm.init_nvm_params was NULL\n");
55*517904deSPeter Grehan 		ret_val = -IGC_ERR_CONFIG;
56*517904deSPeter Grehan 	}
57*517904deSPeter Grehan 
58*517904deSPeter Grehan out:
59*517904deSPeter Grehan 	return ret_val;
60*517904deSPeter Grehan }
61*517904deSPeter Grehan 
62*517904deSPeter Grehan /**
63*517904deSPeter Grehan  *  igc_init_phy_params - Initialize PHY function pointers
64*517904deSPeter Grehan  *  @hw: pointer to the HW structure
65*517904deSPeter Grehan  *
66*517904deSPeter Grehan  *  This function initializes the function pointers for the PHY
67*517904deSPeter Grehan  *  set of functions.  Called by drivers or by igc_setup_init_funcs.
68*517904deSPeter Grehan  **/
igc_init_phy_params(struct igc_hw * hw)69*517904deSPeter Grehan s32 igc_init_phy_params(struct igc_hw *hw)
70*517904deSPeter Grehan {
71*517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
72*517904deSPeter Grehan 
73*517904deSPeter Grehan 	if (hw->phy.ops.init_params) {
74*517904deSPeter Grehan 		ret_val = hw->phy.ops.init_params(hw);
75*517904deSPeter Grehan 		if (ret_val) {
76*517904deSPeter Grehan 			DEBUGOUT("PHY Initialization Error\n");
77*517904deSPeter Grehan 			goto out;
78*517904deSPeter Grehan 		}
79*517904deSPeter Grehan 	} else {
80*517904deSPeter Grehan 		DEBUGOUT("phy.init_phy_params was NULL\n");
81*517904deSPeter Grehan 		ret_val =  -IGC_ERR_CONFIG;
82*517904deSPeter Grehan 	}
83*517904deSPeter Grehan 
84*517904deSPeter Grehan out:
85*517904deSPeter Grehan 	return ret_val;
86*517904deSPeter Grehan }
87*517904deSPeter Grehan 
88*517904deSPeter Grehan /**
89*517904deSPeter Grehan  *  igc_set_mac_type - Sets MAC type
90*517904deSPeter Grehan  *  @hw: pointer to the HW structure
91*517904deSPeter Grehan  *
92*517904deSPeter Grehan  *  This function sets the mac type of the adapter based on the
93*517904deSPeter Grehan  *  device ID stored in the hw structure.
94*517904deSPeter Grehan  *  MUST BE FIRST FUNCTION CALLED (explicitly or through
95*517904deSPeter Grehan  *  igc_setup_init_funcs()).
96*517904deSPeter Grehan  **/
igc_set_mac_type(struct igc_hw * hw)97*517904deSPeter Grehan s32 igc_set_mac_type(struct igc_hw *hw)
98*517904deSPeter Grehan {
99*517904deSPeter Grehan 	struct igc_mac_info *mac = &hw->mac;
100*517904deSPeter Grehan 	s32 ret_val = IGC_SUCCESS;
101*517904deSPeter Grehan 
102*517904deSPeter Grehan 	DEBUGFUNC("igc_set_mac_type");
103*517904deSPeter Grehan 
104*517904deSPeter Grehan 	switch (hw->device_id) {
105*517904deSPeter Grehan 	case IGC_DEV_ID_I225_LM:
106*517904deSPeter Grehan 	case IGC_DEV_ID_I225_V:
107*517904deSPeter Grehan 	case IGC_DEV_ID_I225_K:
108*517904deSPeter Grehan 	case IGC_DEV_ID_I225_I:
109*517904deSPeter Grehan 	case IGC_DEV_ID_I220_V:
110*517904deSPeter Grehan 	case IGC_DEV_ID_I225_K2:
111*517904deSPeter Grehan 	case IGC_DEV_ID_I225_LMVP:
112*517904deSPeter Grehan 	case IGC_DEV_ID_I225_IT:
113*517904deSPeter Grehan 	case IGC_DEV_ID_I226_LM:
114*517904deSPeter Grehan 	case IGC_DEV_ID_I226_V:
115*517904deSPeter Grehan 	case IGC_DEV_ID_I226_IT:
116*517904deSPeter Grehan 	case IGC_DEV_ID_I221_V:
117*517904deSPeter Grehan 	case IGC_DEV_ID_I226_BLANK_NVM:
118*517904deSPeter Grehan 	case IGC_DEV_ID_I225_BLANK_NVM:
119*517904deSPeter Grehan 		mac->type = igc_i225;
120*517904deSPeter Grehan 		break;
121*517904deSPeter Grehan 	default:
122*517904deSPeter Grehan 		/* Should never have loaded on this device */
123*517904deSPeter Grehan 		ret_val = -IGC_ERR_MAC_INIT;
124*517904deSPeter Grehan 		break;
125*517904deSPeter Grehan 	}
126*517904deSPeter Grehan 
127*517904deSPeter Grehan 	return ret_val;
128*517904deSPeter Grehan }
129*517904deSPeter Grehan 
130*517904deSPeter Grehan /**
131*517904deSPeter Grehan  *  igc_setup_init_funcs - Initializes function pointers
132*517904deSPeter Grehan  *  @hw: pointer to the HW structure
133*517904deSPeter Grehan  *  @init_device: true will initialize the rest of the function pointers
134*517904deSPeter Grehan  *		  getting the device ready for use.  FALSE will only set
135*517904deSPeter Grehan  *		  MAC type and the function pointers for the other init
136*517904deSPeter Grehan  *		  functions.  Passing FALSE will not generate any hardware
137*517904deSPeter Grehan  *		  reads or writes.
138*517904deSPeter Grehan  *
139*517904deSPeter Grehan  *  This function must be called by a driver in order to use the rest
140*517904deSPeter Grehan  *  of the 'shared' code files. Called by drivers only.
141*517904deSPeter Grehan  **/
igc_setup_init_funcs(struct igc_hw * hw,bool init_device)142*517904deSPeter Grehan s32 igc_setup_init_funcs(struct igc_hw *hw, bool init_device)
143*517904deSPeter Grehan {
144*517904deSPeter Grehan 	s32 ret_val;
145*517904deSPeter Grehan 
146*517904deSPeter Grehan 	/* Can't do much good without knowing the MAC type. */
147*517904deSPeter Grehan 	ret_val = igc_set_mac_type(hw);
148*517904deSPeter Grehan 	if (ret_val) {
149*517904deSPeter Grehan 		DEBUGOUT("ERROR: MAC type could not be set properly.\n");
150*517904deSPeter Grehan 		goto out;
151*517904deSPeter Grehan 	}
152*517904deSPeter Grehan 
153*517904deSPeter Grehan 	if (!hw->hw_addr) {
154*517904deSPeter Grehan 		DEBUGOUT("ERROR: Registers not mapped\n");
155*517904deSPeter Grehan 		ret_val = -IGC_ERR_CONFIG;
156*517904deSPeter Grehan 		goto out;
157*517904deSPeter Grehan 	}
158*517904deSPeter Grehan 
159*517904deSPeter Grehan 	/*
160*517904deSPeter Grehan 	 * Init function pointers to generic implementations. We do this first
161*517904deSPeter Grehan 	 * allowing a driver module to override it afterward.
162*517904deSPeter Grehan 	 */
163*517904deSPeter Grehan 	igc_init_mac_ops_generic(hw);
164*517904deSPeter Grehan 	igc_init_phy_ops_generic(hw);
165*517904deSPeter Grehan 	igc_init_nvm_ops_generic(hw);
166*517904deSPeter Grehan 
167*517904deSPeter Grehan 	/*
168*517904deSPeter Grehan 	 * Set up the init function pointers. These are functions within the
169*517904deSPeter Grehan 	 * adapter family file that sets up function pointers for the rest of
170*517904deSPeter Grehan 	 * the functions in that family.
171*517904deSPeter Grehan 	 */
172*517904deSPeter Grehan 	switch (hw->mac.type) {
173*517904deSPeter Grehan 	case igc_i225:
174*517904deSPeter Grehan 		igc_init_function_pointers_i225(hw);
175*517904deSPeter Grehan 		break;
176*517904deSPeter Grehan 	default:
177*517904deSPeter Grehan 		DEBUGOUT("Hardware not supported\n");
178*517904deSPeter Grehan 		ret_val = -IGC_ERR_CONFIG;
179*517904deSPeter Grehan 		break;
180*517904deSPeter Grehan 	}
181*517904deSPeter Grehan 
182*517904deSPeter Grehan 	/*
183*517904deSPeter Grehan 	 * Initialize the rest of the function pointers. These require some
184*517904deSPeter Grehan 	 * register reads/writes in some cases.
185*517904deSPeter Grehan 	 */
186*517904deSPeter Grehan 	if (!(ret_val) && init_device) {
187*517904deSPeter Grehan 		ret_val = igc_init_mac_params(hw);
188*517904deSPeter Grehan 		if (ret_val)
189*517904deSPeter Grehan 			goto out;
190*517904deSPeter Grehan 
191*517904deSPeter Grehan 		ret_val = igc_init_nvm_params(hw);
192*517904deSPeter Grehan 		if (ret_val)
193*517904deSPeter Grehan 			goto out;
194*517904deSPeter Grehan 
195*517904deSPeter Grehan 		ret_val = igc_init_phy_params(hw);
196*517904deSPeter Grehan 		if (ret_val)
197*517904deSPeter Grehan 			goto out;
198*517904deSPeter Grehan 	}
199*517904deSPeter Grehan 
200*517904deSPeter Grehan out:
201*517904deSPeter Grehan 	return ret_val;
202*517904deSPeter Grehan }
203*517904deSPeter Grehan 
204*517904deSPeter Grehan /**
205*517904deSPeter Grehan  *  igc_get_bus_info - Obtain bus information for adapter
206*517904deSPeter Grehan  *  @hw: pointer to the HW structure
207*517904deSPeter Grehan  *
208*517904deSPeter Grehan  *  This will obtain information about the HW bus for which the
209*517904deSPeter Grehan  *  adapter is attached and stores it in the hw structure. This is a
210*517904deSPeter Grehan  *  function pointer entry point called by drivers.
211*517904deSPeter Grehan  **/
igc_get_bus_info(struct igc_hw * hw)212*517904deSPeter Grehan s32 igc_get_bus_info(struct igc_hw *hw)
213*517904deSPeter Grehan {
214*517904deSPeter Grehan 	if (hw->mac.ops.get_bus_info)
215*517904deSPeter Grehan 		return hw->mac.ops.get_bus_info(hw);
216*517904deSPeter Grehan 
217*517904deSPeter Grehan 	return IGC_SUCCESS;
218*517904deSPeter Grehan }
219*517904deSPeter Grehan 
220*517904deSPeter Grehan /**
221*517904deSPeter Grehan  *  igc_clear_vfta - Clear VLAN filter table
222*517904deSPeter Grehan  *  @hw: pointer to the HW structure
223*517904deSPeter Grehan  *
224*517904deSPeter Grehan  *  This clears the VLAN filter table on the adapter. This is a function
225*517904deSPeter Grehan  *  pointer entry point called by drivers.
226*517904deSPeter Grehan  **/
igc_clear_vfta(struct igc_hw * hw)227*517904deSPeter Grehan void igc_clear_vfta(struct igc_hw *hw)
228*517904deSPeter Grehan {
229*517904deSPeter Grehan 	if (hw->mac.ops.clear_vfta)
230*517904deSPeter Grehan 		hw->mac.ops.clear_vfta(hw);
231*517904deSPeter Grehan }
232*517904deSPeter Grehan 
233*517904deSPeter Grehan /**
234*517904deSPeter Grehan  *  igc_write_vfta - Write value to VLAN filter table
235*517904deSPeter Grehan  *  @hw: pointer to the HW structure
236*517904deSPeter Grehan  *  @offset: the 32-bit offset in which to write the value to.
237*517904deSPeter Grehan  *  @value: the 32-bit value to write at location offset.
238*517904deSPeter Grehan  *
239*517904deSPeter Grehan  *  This writes a 32-bit value to a 32-bit offset in the VLAN filter
240*517904deSPeter Grehan  *  table. This is a function pointer entry point called by drivers.
241*517904deSPeter Grehan  **/
igc_write_vfta(struct igc_hw * hw,u32 offset,u32 value)242*517904deSPeter Grehan void igc_write_vfta(struct igc_hw *hw, u32 offset, u32 value)
243*517904deSPeter Grehan {
244*517904deSPeter Grehan 	if (hw->mac.ops.write_vfta)
245*517904deSPeter Grehan 		hw->mac.ops.write_vfta(hw, offset, value);
246*517904deSPeter Grehan }
247*517904deSPeter Grehan 
248*517904deSPeter Grehan /**
249*517904deSPeter Grehan  *  igc_update_mc_addr_list - Update Multicast addresses
250*517904deSPeter Grehan  *  @hw: pointer to the HW structure
251*517904deSPeter Grehan  *  @mc_addr_list: array of multicast addresses to program
252*517904deSPeter Grehan  *  @mc_addr_count: number of multicast addresses to program
253*517904deSPeter Grehan  *
254*517904deSPeter Grehan  *  Updates the Multicast Table Array.
255*517904deSPeter Grehan  *  The caller must have a packed mc_addr_list of multicast addresses.
256*517904deSPeter Grehan  **/
igc_update_mc_addr_list(struct igc_hw * hw,u8 * mc_addr_list,u32 mc_addr_count)257*517904deSPeter Grehan void igc_update_mc_addr_list(struct igc_hw *hw, u8 *mc_addr_list,
258*517904deSPeter Grehan 			       u32 mc_addr_count)
259*517904deSPeter Grehan {
260*517904deSPeter Grehan 	if (hw->mac.ops.update_mc_addr_list)
261*517904deSPeter Grehan 		hw->mac.ops.update_mc_addr_list(hw, mc_addr_list,
262*517904deSPeter Grehan 						mc_addr_count);
263*517904deSPeter Grehan }
264*517904deSPeter Grehan 
265*517904deSPeter Grehan /**
266*517904deSPeter Grehan  *  igc_force_mac_fc - Force MAC flow control
267*517904deSPeter Grehan  *  @hw: pointer to the HW structure
268*517904deSPeter Grehan  *
269*517904deSPeter Grehan  *  Force the MAC's flow control settings. Currently no func pointer exists
270*517904deSPeter Grehan  *  and all implementations are handled in the generic version of this
271*517904deSPeter Grehan  *  function.
272*517904deSPeter Grehan  **/
igc_force_mac_fc(struct igc_hw * hw)273*517904deSPeter Grehan s32 igc_force_mac_fc(struct igc_hw *hw)
274*517904deSPeter Grehan {
275*517904deSPeter Grehan 	return igc_force_mac_fc_generic(hw);
276*517904deSPeter Grehan }
277*517904deSPeter Grehan 
278*517904deSPeter Grehan /**
279*517904deSPeter Grehan  *  igc_check_for_link - Check/Store link connection
280*517904deSPeter Grehan  *  @hw: pointer to the HW structure
281*517904deSPeter Grehan  *
282*517904deSPeter Grehan  *  This checks the link condition of the adapter and stores the
283*517904deSPeter Grehan  *  results in the hw->mac structure. This is a function pointer entry
284*517904deSPeter Grehan  *  point called by drivers.
285*517904deSPeter Grehan  **/
igc_check_for_link(struct igc_hw * hw)286*517904deSPeter Grehan s32 igc_check_for_link(struct igc_hw *hw)
287*517904deSPeter Grehan {
288*517904deSPeter Grehan 	if (hw->mac.ops.check_for_link)
289*517904deSPeter Grehan 		return hw->mac.ops.check_for_link(hw);
290*517904deSPeter Grehan 
291*517904deSPeter Grehan 	return -IGC_ERR_CONFIG;
292*517904deSPeter Grehan }
293*517904deSPeter Grehan 
294*517904deSPeter Grehan /**
295*517904deSPeter Grehan  *  igc_reset_hw - Reset hardware
296*517904deSPeter Grehan  *  @hw: pointer to the HW structure
297*517904deSPeter Grehan  *
298*517904deSPeter Grehan  *  This resets the hardware into a known state. This is a function pointer
299*517904deSPeter Grehan  *  entry point called by drivers.
300*517904deSPeter Grehan  **/
igc_reset_hw(struct igc_hw * hw)301*517904deSPeter Grehan s32 igc_reset_hw(struct igc_hw *hw)
302*517904deSPeter Grehan {
303*517904deSPeter Grehan 	if (hw->mac.ops.reset_hw)
304*517904deSPeter Grehan 		return hw->mac.ops.reset_hw(hw);
305*517904deSPeter Grehan 
306*517904deSPeter Grehan 	return -IGC_ERR_CONFIG;
307*517904deSPeter Grehan }
308*517904deSPeter Grehan 
309*517904deSPeter Grehan /**
310*517904deSPeter Grehan  *  igc_init_hw - Initialize hardware
311*517904deSPeter Grehan  *  @hw: pointer to the HW structure
312*517904deSPeter Grehan  *
313*517904deSPeter Grehan  *  This inits the hardware readying it for operation. This is a function
314*517904deSPeter Grehan  *  pointer entry point called by drivers.
315*517904deSPeter Grehan  **/
igc_init_hw(struct igc_hw * hw)316*517904deSPeter Grehan s32 igc_init_hw(struct igc_hw *hw)
317*517904deSPeter Grehan {
318*517904deSPeter Grehan 	if (hw->mac.ops.init_hw)
319*517904deSPeter Grehan 		return hw->mac.ops.init_hw(hw);
320*517904deSPeter Grehan 
321*517904deSPeter Grehan 	return -IGC_ERR_CONFIG;
322*517904deSPeter Grehan }
323*517904deSPeter Grehan 
324*517904deSPeter Grehan /**
325*517904deSPeter Grehan  *  igc_setup_link - Configures link and flow control
326*517904deSPeter Grehan  *  @hw: pointer to the HW structure
327*517904deSPeter Grehan  *
328*517904deSPeter Grehan  *  This configures link and flow control settings for the adapter. This
329*517904deSPeter Grehan  *  is a function pointer entry point called by drivers. While modules can
330*517904deSPeter Grehan  *  also call this, they probably call their own version of this function.
331*517904deSPeter Grehan  **/
igc_setup_link(struct igc_hw * hw)332*517904deSPeter Grehan s32 igc_setup_link(struct igc_hw *hw)
333*517904deSPeter Grehan {
334*517904deSPeter Grehan 	if (hw->mac.ops.setup_link)
335*517904deSPeter Grehan 		return hw->mac.ops.setup_link(hw);
336*517904deSPeter Grehan 
337*517904deSPeter Grehan 	return -IGC_ERR_CONFIG;
338*517904deSPeter Grehan }
339*517904deSPeter Grehan 
340*517904deSPeter Grehan /**
341*517904deSPeter Grehan  *  igc_get_speed_and_duplex - Returns current speed and duplex
342*517904deSPeter Grehan  *  @hw: pointer to the HW structure
343*517904deSPeter Grehan  *  @speed: pointer to a 16-bit value to store the speed
344*517904deSPeter Grehan  *  @duplex: pointer to a 16-bit value to store the duplex.
345*517904deSPeter Grehan  *
346*517904deSPeter Grehan  *  This returns the speed and duplex of the adapter in the two 'out'
347*517904deSPeter Grehan  *  variables passed in. This is a function pointer entry point called
348*517904deSPeter Grehan  *  by drivers.
349*517904deSPeter Grehan  **/
igc_get_speed_and_duplex(struct igc_hw * hw,u16 * speed,u16 * duplex)350*517904deSPeter Grehan s32 igc_get_speed_and_duplex(struct igc_hw *hw, u16 *speed, u16 *duplex)
351*517904deSPeter Grehan {
352*517904deSPeter Grehan 	if (hw->mac.ops.get_link_up_info)
353*517904deSPeter Grehan 		return hw->mac.ops.get_link_up_info(hw, speed, duplex);
354*517904deSPeter Grehan 
355*517904deSPeter Grehan 	return -IGC_ERR_CONFIG;
356*517904deSPeter Grehan }
357*517904deSPeter Grehan 
358*517904deSPeter Grehan /**
359*517904deSPeter Grehan  *  igc_disable_pcie_master - Disable PCI-Express master access
360*517904deSPeter Grehan  *  @hw: pointer to the HW structure
361*517904deSPeter Grehan  *
362*517904deSPeter Grehan  *  Disables PCI-Express master access and verifies there are no pending
363*517904deSPeter Grehan  *  requests. Currently no func pointer exists and all implementations are
364*517904deSPeter Grehan  *  handled in the generic version of this function.
365*517904deSPeter Grehan  **/
igc_disable_pcie_master(struct igc_hw * hw)366*517904deSPeter Grehan s32 igc_disable_pcie_master(struct igc_hw *hw)
367*517904deSPeter Grehan {
368*517904deSPeter Grehan 	return igc_disable_pcie_master_generic(hw);
369*517904deSPeter Grehan }
370*517904deSPeter Grehan 
371*517904deSPeter Grehan /**
372*517904deSPeter Grehan  *  igc_config_collision_dist - Configure collision distance
373*517904deSPeter Grehan  *  @hw: pointer to the HW structure
374*517904deSPeter Grehan  *
375*517904deSPeter Grehan  *  Configures the collision distance to the default value and is used
376*517904deSPeter Grehan  *  during link setup.
377*517904deSPeter Grehan  **/
igc_config_collision_dist(struct igc_hw * hw)378*517904deSPeter Grehan void igc_config_collision_dist(struct igc_hw *hw)
379*517904deSPeter Grehan {
380*517904deSPeter Grehan 	if (hw->mac.ops.config_collision_dist)
381*517904deSPeter Grehan 		hw->mac.ops.config_collision_dist(hw);
382*517904deSPeter Grehan }
383*517904deSPeter Grehan 
384*517904deSPeter Grehan /**
385*517904deSPeter Grehan  *  igc_rar_set - Sets a receive address register
386*517904deSPeter Grehan  *  @hw: pointer to the HW structure
387*517904deSPeter Grehan  *  @addr: address to set the RAR to
388*517904deSPeter Grehan  *  @index: the RAR to set
389*517904deSPeter Grehan  *
390*517904deSPeter Grehan  *  Sets a Receive Address Register (RAR) to the specified address.
391*517904deSPeter Grehan  **/
igc_rar_set(struct igc_hw * hw,u8 * addr,u32 index)392*517904deSPeter Grehan int igc_rar_set(struct igc_hw *hw, u8 *addr, u32 index)
393*517904deSPeter Grehan {
394*517904deSPeter Grehan 	if (hw->mac.ops.rar_set)
395*517904deSPeter Grehan 		return hw->mac.ops.rar_set(hw, addr, index);
396*517904deSPeter Grehan 
397*517904deSPeter Grehan 	return IGC_SUCCESS;
398*517904deSPeter Grehan }
399*517904deSPeter Grehan 
400*517904deSPeter Grehan /**
401*517904deSPeter Grehan  *  igc_validate_mdi_setting - Ensures valid MDI/MDIX SW state
402*517904deSPeter Grehan  *  @hw: pointer to the HW structure
403*517904deSPeter Grehan  *
404*517904deSPeter Grehan  *  Ensures that the MDI/MDIX SW state is valid.
405*517904deSPeter Grehan  **/
igc_validate_mdi_setting(struct igc_hw * hw)406*517904deSPeter Grehan s32 igc_validate_mdi_setting(struct igc_hw *hw)
407*517904deSPeter Grehan {
408*517904deSPeter Grehan 	if (hw->mac.ops.validate_mdi_setting)
409*517904deSPeter Grehan 		return hw->mac.ops.validate_mdi_setting(hw);
410*517904deSPeter Grehan 
411*517904deSPeter Grehan 	return IGC_SUCCESS;
412*517904deSPeter Grehan }
413*517904deSPeter Grehan 
414*517904deSPeter Grehan /**
415*517904deSPeter Grehan  *  igc_hash_mc_addr - Determines address location in multicast table
416*517904deSPeter Grehan  *  @hw: pointer to the HW structure
417*517904deSPeter Grehan  *  @mc_addr: Multicast address to hash.
418*517904deSPeter Grehan  *
419*517904deSPeter Grehan  *  This hashes an address to determine its location in the multicast
420*517904deSPeter Grehan  *  table. Currently no func pointer exists and all implementations
421*517904deSPeter Grehan  *  are handled in the generic version of this function.
422*517904deSPeter Grehan  **/
igc_hash_mc_addr(struct igc_hw * hw,u8 * mc_addr)423*517904deSPeter Grehan u32 igc_hash_mc_addr(struct igc_hw *hw, u8 *mc_addr)
424*517904deSPeter Grehan {
425*517904deSPeter Grehan 	return igc_hash_mc_addr_generic(hw, mc_addr);
426*517904deSPeter Grehan }
427*517904deSPeter Grehan 
428*517904deSPeter Grehan /**
429*517904deSPeter Grehan  *  igc_check_reset_block - Verifies PHY can be reset
430*517904deSPeter Grehan  *  @hw: pointer to the HW structure
431*517904deSPeter Grehan  *
432*517904deSPeter Grehan  *  Checks if the PHY is in a state that can be reset or if manageability
433*517904deSPeter Grehan  *  has it tied up. This is a function pointer entry point called by drivers.
434*517904deSPeter Grehan  **/
igc_check_reset_block(struct igc_hw * hw)435*517904deSPeter Grehan s32 igc_check_reset_block(struct igc_hw *hw)
436*517904deSPeter Grehan {
437*517904deSPeter Grehan 	if (hw->phy.ops.check_reset_block)
438*517904deSPeter Grehan 		return hw->phy.ops.check_reset_block(hw);
439*517904deSPeter Grehan 
440*517904deSPeter Grehan 	return IGC_SUCCESS;
441*517904deSPeter Grehan }
442*517904deSPeter Grehan 
443*517904deSPeter Grehan /**
444*517904deSPeter Grehan  *  igc_read_phy_reg - Reads PHY register
445*517904deSPeter Grehan  *  @hw: pointer to the HW structure
446*517904deSPeter Grehan  *  @offset: the register to read
447*517904deSPeter Grehan  *  @data: the buffer to store the 16-bit read.
448*517904deSPeter Grehan  *
449*517904deSPeter Grehan  *  Reads the PHY register and returns the value in data.
450*517904deSPeter Grehan  *  This is a function pointer entry point called by drivers.
451*517904deSPeter Grehan  **/
igc_read_phy_reg(struct igc_hw * hw,u32 offset,u16 * data)452*517904deSPeter Grehan s32 igc_read_phy_reg(struct igc_hw *hw, u32 offset, u16 *data)
453*517904deSPeter Grehan {
454*517904deSPeter Grehan 	if (hw->phy.ops.read_reg)
455*517904deSPeter Grehan 		return hw->phy.ops.read_reg(hw, offset, data);
456*517904deSPeter Grehan 
457*517904deSPeter Grehan 	return IGC_SUCCESS;
458*517904deSPeter Grehan }
459*517904deSPeter Grehan 
460*517904deSPeter Grehan /**
461*517904deSPeter Grehan  *  igc_write_phy_reg - Writes PHY register
462*517904deSPeter Grehan  *  @hw: pointer to the HW structure
463*517904deSPeter Grehan  *  @offset: the register to write
464*517904deSPeter Grehan  *  @data: the value to write.
465*517904deSPeter Grehan  *
466*517904deSPeter Grehan  *  Writes the PHY register at offset with the value in data.
467*517904deSPeter Grehan  *  This is a function pointer entry point called by drivers.
468*517904deSPeter Grehan  **/
igc_write_phy_reg(struct igc_hw * hw,u32 offset,u16 data)469*517904deSPeter Grehan s32 igc_write_phy_reg(struct igc_hw *hw, u32 offset, u16 data)
470*517904deSPeter Grehan {
471*517904deSPeter Grehan 	if (hw->phy.ops.write_reg)
472*517904deSPeter Grehan 		return hw->phy.ops.write_reg(hw, offset, data);
473*517904deSPeter Grehan 
474*517904deSPeter Grehan 	return IGC_SUCCESS;
475*517904deSPeter Grehan }
476*517904deSPeter Grehan 
477*517904deSPeter Grehan /**
478*517904deSPeter Grehan  *  igc_release_phy - Generic release PHY
479*517904deSPeter Grehan  *  @hw: pointer to the HW structure
480*517904deSPeter Grehan  *
481*517904deSPeter Grehan  *  Return if silicon family does not require a semaphore when accessing the
482*517904deSPeter Grehan  *  PHY.
483*517904deSPeter Grehan  **/
igc_release_phy(struct igc_hw * hw)484*517904deSPeter Grehan void igc_release_phy(struct igc_hw *hw)
485*517904deSPeter Grehan {
486*517904deSPeter Grehan 	if (hw->phy.ops.release)
487*517904deSPeter Grehan 		hw->phy.ops.release(hw);
488*517904deSPeter Grehan }
489*517904deSPeter Grehan 
490*517904deSPeter Grehan /**
491*517904deSPeter Grehan  *  igc_acquire_phy - Generic acquire PHY
492*517904deSPeter Grehan  *  @hw: pointer to the HW structure
493*517904deSPeter Grehan  *
494*517904deSPeter Grehan  *  Return success if silicon family does not require a semaphore when
495*517904deSPeter Grehan  *  accessing the PHY.
496*517904deSPeter Grehan  **/
igc_acquire_phy(struct igc_hw * hw)497*517904deSPeter Grehan s32 igc_acquire_phy(struct igc_hw *hw)
498*517904deSPeter Grehan {
499*517904deSPeter Grehan 	if (hw->phy.ops.acquire)
500*517904deSPeter Grehan 		return hw->phy.ops.acquire(hw);
501*517904deSPeter Grehan 
502*517904deSPeter Grehan 	return IGC_SUCCESS;
503*517904deSPeter Grehan }
504*517904deSPeter Grehan 
505*517904deSPeter Grehan /**
506*517904deSPeter Grehan  *  igc_get_phy_info - Retrieves PHY information from registers
507*517904deSPeter Grehan  *  @hw: pointer to the HW structure
508*517904deSPeter Grehan  *
509*517904deSPeter Grehan  *  This function gets some information from various PHY registers and
510*517904deSPeter Grehan  *  populates hw->phy values with it. This is a function pointer entry
511*517904deSPeter Grehan  *  point called by drivers.
512*517904deSPeter Grehan  **/
igc_get_phy_info(struct igc_hw * hw)513*517904deSPeter Grehan s32 igc_get_phy_info(struct igc_hw *hw)
514*517904deSPeter Grehan {
515*517904deSPeter Grehan 	if (hw->phy.ops.get_info)
516*517904deSPeter Grehan 		return hw->phy.ops.get_info(hw);
517*517904deSPeter Grehan 
518*517904deSPeter Grehan 	return IGC_SUCCESS;
519*517904deSPeter Grehan }
520*517904deSPeter Grehan 
521*517904deSPeter Grehan /**
522*517904deSPeter Grehan  *  igc_phy_hw_reset - Hard PHY reset
523*517904deSPeter Grehan  *  @hw: pointer to the HW structure
524*517904deSPeter Grehan  *
525*517904deSPeter Grehan  *  Performs a hard PHY reset. This is a function pointer entry point called
526*517904deSPeter Grehan  *  by drivers.
527*517904deSPeter Grehan  **/
igc_phy_hw_reset(struct igc_hw * hw)528*517904deSPeter Grehan s32 igc_phy_hw_reset(struct igc_hw *hw)
529*517904deSPeter Grehan {
530*517904deSPeter Grehan 	if (hw->phy.ops.reset)
531*517904deSPeter Grehan 		return hw->phy.ops.reset(hw);
532*517904deSPeter Grehan 
533*517904deSPeter Grehan 	return IGC_SUCCESS;
534*517904deSPeter Grehan }
535*517904deSPeter Grehan 
536*517904deSPeter Grehan /**
537*517904deSPeter Grehan  *  igc_set_d0_lplu_state - Sets low power link up state for D0
538*517904deSPeter Grehan  *  @hw: pointer to the HW structure
539*517904deSPeter Grehan  *  @active: boolean used to enable/disable lplu
540*517904deSPeter Grehan  *
541*517904deSPeter Grehan  *  Success returns 0, Failure returns 1
542*517904deSPeter Grehan  *
543*517904deSPeter Grehan  *  The low power link up (lplu) state is set to the power management level D0
544*517904deSPeter Grehan  *  and SmartSpeed is disabled when active is true, else clear lplu for D0
545*517904deSPeter Grehan  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
546*517904deSPeter Grehan  *  is used during Dx states where the power conservation is most important.
547*517904deSPeter Grehan  *  During driver activity, SmartSpeed should be enabled so performance is
548*517904deSPeter Grehan  *  maintained.  This is a function pointer entry point called by drivers.
549*517904deSPeter Grehan  **/
igc_set_d0_lplu_state(struct igc_hw * hw,bool active)550*517904deSPeter Grehan s32 igc_set_d0_lplu_state(struct igc_hw *hw, bool active)
551*517904deSPeter Grehan {
552*517904deSPeter Grehan 	if (hw->phy.ops.set_d0_lplu_state)
553*517904deSPeter Grehan 		return hw->phy.ops.set_d0_lplu_state(hw, active);
554*517904deSPeter Grehan 
555*517904deSPeter Grehan 	return IGC_SUCCESS;
556*517904deSPeter Grehan }
557*517904deSPeter Grehan 
558*517904deSPeter Grehan /**
559*517904deSPeter Grehan  *  igc_set_d3_lplu_state - Sets low power link up state for D3
560*517904deSPeter Grehan  *  @hw: pointer to the HW structure
561*517904deSPeter Grehan  *  @active: boolean used to enable/disable lplu
562*517904deSPeter Grehan  *
563*517904deSPeter Grehan  *  Success returns 0, Failure returns 1
564*517904deSPeter Grehan  *
565*517904deSPeter Grehan  *  The low power link up (lplu) state is set to the power management level D3
566*517904deSPeter Grehan  *  and SmartSpeed is disabled when active is true, else clear lplu for D3
567*517904deSPeter Grehan  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
568*517904deSPeter Grehan  *  is used during Dx states where the power conservation is most important.
569*517904deSPeter Grehan  *  During driver activity, SmartSpeed should be enabled so performance is
570*517904deSPeter Grehan  *  maintained.  This is a function pointer entry point called by drivers.
571*517904deSPeter Grehan  **/
igc_set_d3_lplu_state(struct igc_hw * hw,bool active)572*517904deSPeter Grehan s32 igc_set_d3_lplu_state(struct igc_hw *hw, bool active)
573*517904deSPeter Grehan {
574*517904deSPeter Grehan 	if (hw->phy.ops.set_d3_lplu_state)
575*517904deSPeter Grehan 		return hw->phy.ops.set_d3_lplu_state(hw, active);
576*517904deSPeter Grehan 
577*517904deSPeter Grehan 	return IGC_SUCCESS;
578*517904deSPeter Grehan }
579*517904deSPeter Grehan 
580*517904deSPeter Grehan /**
581*517904deSPeter Grehan  *  igc_read_mac_addr - Reads MAC address
582*517904deSPeter Grehan  *  @hw: pointer to the HW structure
583*517904deSPeter Grehan  *
584*517904deSPeter Grehan  *  Reads the MAC address out of the adapter and stores it in the HW structure.
585*517904deSPeter Grehan  *  Currently no func pointer exists and all implementations are handled in the
586*517904deSPeter Grehan  *  generic version of this function.
587*517904deSPeter Grehan  **/
igc_read_mac_addr(struct igc_hw * hw)588*517904deSPeter Grehan s32 igc_read_mac_addr(struct igc_hw *hw)
589*517904deSPeter Grehan {
590*517904deSPeter Grehan 	if (hw->mac.ops.read_mac_addr)
591*517904deSPeter Grehan 		return hw->mac.ops.read_mac_addr(hw);
592*517904deSPeter Grehan 
593*517904deSPeter Grehan 	return igc_read_mac_addr_generic(hw);
594*517904deSPeter Grehan }
595*517904deSPeter Grehan 
596*517904deSPeter Grehan /**
597*517904deSPeter Grehan  *  igc_read_pba_string - Read device part number string
598*517904deSPeter Grehan  *  @hw: pointer to the HW structure
599*517904deSPeter Grehan  *  @pba_num: pointer to device part number
600*517904deSPeter Grehan  *  @pba_num_size: size of part number buffer
601*517904deSPeter Grehan  *
602*517904deSPeter Grehan  *  Reads the product board assembly (PBA) number from the EEPROM and stores
603*517904deSPeter Grehan  *  the value in pba_num.
604*517904deSPeter Grehan  *  Currently no func pointer exists and all implementations are handled in the
605*517904deSPeter Grehan  *  generic version of this function.
606*517904deSPeter Grehan  **/
igc_read_pba_string(struct igc_hw * hw,u8 * pba_num,u32 pba_num_size)607*517904deSPeter Grehan s32 igc_read_pba_string(struct igc_hw *hw, u8 *pba_num, u32 pba_num_size)
608*517904deSPeter Grehan {
609*517904deSPeter Grehan 	return igc_read_pba_string_generic(hw, pba_num, pba_num_size);
610*517904deSPeter Grehan }
611*517904deSPeter Grehan 
612*517904deSPeter Grehan /**
613*517904deSPeter Grehan  *  igc_validate_nvm_checksum - Verifies NVM (EEPROM) checksum
614*517904deSPeter Grehan  *  @hw: pointer to the HW structure
615*517904deSPeter Grehan  *
616*517904deSPeter Grehan  *  Validates the NVM checksum is correct. This is a function pointer entry
617*517904deSPeter Grehan  *  point called by drivers.
618*517904deSPeter Grehan  **/
igc_validate_nvm_checksum(struct igc_hw * hw)619*517904deSPeter Grehan s32 igc_validate_nvm_checksum(struct igc_hw *hw)
620*517904deSPeter Grehan {
621*517904deSPeter Grehan 	if (hw->nvm.ops.validate)
622*517904deSPeter Grehan 		return hw->nvm.ops.validate(hw);
623*517904deSPeter Grehan 
624*517904deSPeter Grehan 	return -IGC_ERR_CONFIG;
625*517904deSPeter Grehan }
626*517904deSPeter Grehan 
627*517904deSPeter Grehan /**
628*517904deSPeter Grehan  *  igc_update_nvm_checksum - Updates NVM (EEPROM) checksum
629*517904deSPeter Grehan  *  @hw: pointer to the HW structure
630*517904deSPeter Grehan  *
631*517904deSPeter Grehan  *  Updates the NVM checksum. Currently no func pointer exists and all
632*517904deSPeter Grehan  *  implementations are handled in the generic version of this function.
633*517904deSPeter Grehan  **/
igc_update_nvm_checksum(struct igc_hw * hw)634*517904deSPeter Grehan s32 igc_update_nvm_checksum(struct igc_hw *hw)
635*517904deSPeter Grehan {
636*517904deSPeter Grehan 	if (hw->nvm.ops.update)
637*517904deSPeter Grehan 		return hw->nvm.ops.update(hw);
638*517904deSPeter Grehan 
639*517904deSPeter Grehan 	return -IGC_ERR_CONFIG;
640*517904deSPeter Grehan }
641*517904deSPeter Grehan 
642*517904deSPeter Grehan /**
643*517904deSPeter Grehan  *  igc_reload_nvm - Reloads EEPROM
644*517904deSPeter Grehan  *  @hw: pointer to the HW structure
645*517904deSPeter Grehan  *
646*517904deSPeter Grehan  *  Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
647*517904deSPeter Grehan  *  extended control register.
648*517904deSPeter Grehan  **/
igc_reload_nvm(struct igc_hw * hw)649*517904deSPeter Grehan void igc_reload_nvm(struct igc_hw *hw)
650*517904deSPeter Grehan {
651*517904deSPeter Grehan 	if (hw->nvm.ops.reload)
652*517904deSPeter Grehan 		hw->nvm.ops.reload(hw);
653*517904deSPeter Grehan }
654*517904deSPeter Grehan 
655*517904deSPeter Grehan /**
656*517904deSPeter Grehan  *  igc_read_nvm - Reads NVM (EEPROM)
657*517904deSPeter Grehan  *  @hw: pointer to the HW structure
658*517904deSPeter Grehan  *  @offset: the word offset to read
659*517904deSPeter Grehan  *  @words: number of 16-bit words to read
660*517904deSPeter Grehan  *  @data: pointer to the properly sized buffer for the data.
661*517904deSPeter Grehan  *
662*517904deSPeter Grehan  *  Reads 16-bit chunks of data from the NVM (EEPROM). This is a function
663*517904deSPeter Grehan  *  pointer entry point called by drivers.
664*517904deSPeter Grehan  **/
igc_read_nvm(struct igc_hw * hw,u16 offset,u16 words,u16 * data)665*517904deSPeter Grehan s32 igc_read_nvm(struct igc_hw *hw, u16 offset, u16 words, u16 *data)
666*517904deSPeter Grehan {
667*517904deSPeter Grehan 	if (hw->nvm.ops.read)
668*517904deSPeter Grehan 		return hw->nvm.ops.read(hw, offset, words, data);
669*517904deSPeter Grehan 
670*517904deSPeter Grehan 	return -IGC_ERR_CONFIG;
671*517904deSPeter Grehan }
672*517904deSPeter Grehan 
673*517904deSPeter Grehan /**
674*517904deSPeter Grehan  *  igc_write_nvm - Writes to NVM (EEPROM)
675*517904deSPeter Grehan  *  @hw: pointer to the HW structure
676*517904deSPeter Grehan  *  @offset: the word offset to read
677*517904deSPeter Grehan  *  @words: number of 16-bit words to write
678*517904deSPeter Grehan  *  @data: pointer to the properly sized buffer for the data.
679*517904deSPeter Grehan  *
680*517904deSPeter Grehan  *  Writes 16-bit chunks of data to the NVM (EEPROM). This is a function
681*517904deSPeter Grehan  *  pointer entry point called by drivers.
682*517904deSPeter Grehan  **/
igc_write_nvm(struct igc_hw * hw,u16 offset,u16 words,u16 * data)683*517904deSPeter Grehan s32 igc_write_nvm(struct igc_hw *hw, u16 offset, u16 words, u16 *data)
684*517904deSPeter Grehan {
685*517904deSPeter Grehan 	if (hw->nvm.ops.write)
686*517904deSPeter Grehan 		return hw->nvm.ops.write(hw, offset, words, data);
687*517904deSPeter Grehan 
688*517904deSPeter Grehan 	return IGC_SUCCESS;
689*517904deSPeter Grehan }
690*517904deSPeter Grehan 
691*517904deSPeter Grehan /**
692*517904deSPeter Grehan  * igc_power_up_phy - Restores link in case of PHY power down
693*517904deSPeter Grehan  * @hw: pointer to the HW structure
694*517904deSPeter Grehan  *
695*517904deSPeter Grehan  * The phy may be powered down to save power, to turn off link when the
696*517904deSPeter Grehan  * driver is unloaded, or wake on lan is not enabled (among others).
697*517904deSPeter Grehan  **/
igc_power_up_phy(struct igc_hw * hw)698*517904deSPeter Grehan void igc_power_up_phy(struct igc_hw *hw)
699*517904deSPeter Grehan {
700*517904deSPeter Grehan 	if (hw->phy.ops.power_up)
701*517904deSPeter Grehan 		hw->phy.ops.power_up(hw);
702*517904deSPeter Grehan 
703*517904deSPeter Grehan 	igc_setup_link(hw);
704*517904deSPeter Grehan }
705*517904deSPeter Grehan 
706*517904deSPeter Grehan /**
707*517904deSPeter Grehan  * igc_power_down_phy - Power down PHY
708*517904deSPeter Grehan  * @hw: pointer to the HW structure
709*517904deSPeter Grehan  *
710*517904deSPeter Grehan  * The phy may be powered down to save power, to turn off link when the
711*517904deSPeter Grehan  * driver is unloaded, or wake on lan is not enabled (among others).
712*517904deSPeter Grehan  **/
igc_power_down_phy(struct igc_hw * hw)713*517904deSPeter Grehan void igc_power_down_phy(struct igc_hw *hw)
714*517904deSPeter Grehan {
715*517904deSPeter Grehan 	if (hw->phy.ops.power_down)
716*517904deSPeter Grehan 		hw->phy.ops.power_down(hw);
717*517904deSPeter Grehan }
718*517904deSPeter Grehan 
719