xref: /freebsd/sys/dev/e1000/e1000_api.c (revision eb6219e337483cb80eccb6f2b4ad649bc1d751ec)
1 /******************************************************************************
2 
3   Copyright (c) 2001-2009, Intel Corporation
4   All rights reserved.
5 
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are met:
8 
9    1. Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11 
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in the
14       documentation and/or other materials provided with the distribution.
15 
16    3. Neither the name of the Intel Corporation nor the names of its
17       contributors may be used to endorse or promote products derived from
18       this software without specific prior written permission.
19 
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31 
32 ******************************************************************************/
33 /*$FreeBSD$*/
34 
35 #include "e1000_api.h"
36 
37 /**
38  *  e1000_init_mac_params - Initialize MAC function pointers
39  *  @hw: pointer to the HW structure
40  *
41  *  This function initializes the function pointers for the MAC
42  *  set of functions.  Called by drivers or by e1000_setup_init_funcs.
43  **/
44 s32 e1000_init_mac_params(struct e1000_hw *hw)
45 {
46 	s32 ret_val = E1000_SUCCESS;
47 
48 	if (hw->mac.ops.init_params) {
49 		ret_val = hw->mac.ops.init_params(hw);
50 		if (ret_val) {
51 			DEBUGOUT("MAC Initialization Error\n");
52 			goto out;
53 		}
54 	} else {
55 		DEBUGOUT("mac.init_mac_params was NULL\n");
56 		ret_val = -E1000_ERR_CONFIG;
57 	}
58 
59 out:
60 	return ret_val;
61 }
62 
63 /**
64  *  e1000_init_nvm_params - Initialize NVM function pointers
65  *  @hw: pointer to the HW structure
66  *
67  *  This function initializes the function pointers for the NVM
68  *  set of functions.  Called by drivers or by e1000_setup_init_funcs.
69  **/
70 s32 e1000_init_nvm_params(struct e1000_hw *hw)
71 {
72 	s32 ret_val = E1000_SUCCESS;
73 
74 	if (hw->nvm.ops.init_params) {
75 		ret_val = hw->nvm.ops.init_params(hw);
76 		if (ret_val) {
77 			DEBUGOUT("NVM Initialization Error\n");
78 			goto out;
79 		}
80 	} else {
81 		DEBUGOUT("nvm.init_nvm_params was NULL\n");
82 		ret_val = -E1000_ERR_CONFIG;
83 	}
84 
85 out:
86 	return ret_val;
87 }
88 
89 /**
90  *  e1000_init_phy_params - Initialize PHY function pointers
91  *  @hw: pointer to the HW structure
92  *
93  *  This function initializes the function pointers for the PHY
94  *  set of functions.  Called by drivers or by e1000_setup_init_funcs.
95  **/
96 s32 e1000_init_phy_params(struct e1000_hw *hw)
97 {
98 	s32 ret_val = E1000_SUCCESS;
99 
100 	if (hw->phy.ops.init_params) {
101 		ret_val = hw->phy.ops.init_params(hw);
102 		if (ret_val) {
103 			DEBUGOUT("PHY Initialization Error\n");
104 			goto out;
105 		}
106 	} else {
107 		DEBUGOUT("phy.init_phy_params was NULL\n");
108 		ret_val =  -E1000_ERR_CONFIG;
109 	}
110 
111 out:
112 	return ret_val;
113 }
114 
115 
116 /**
117  *  e1000_set_mac_type - Sets MAC type
118  *  @hw: pointer to the HW structure
119  *
120  *  This function sets the mac type of the adapter based on the
121  *  device ID stored in the hw structure.
122  *  MUST BE FIRST FUNCTION CALLED (explicitly or through
123  *  e1000_setup_init_funcs()).
124  **/
125 s32 e1000_set_mac_type(struct e1000_hw *hw)
126 {
127 	struct e1000_mac_info *mac = &hw->mac;
128 	s32 ret_val = E1000_SUCCESS;
129 
130 	DEBUGFUNC("e1000_set_mac_type");
131 
132 	switch (hw->device_id) {
133 	case E1000_DEV_ID_82542:
134 		mac->type = e1000_82542;
135 		break;
136 	case E1000_DEV_ID_82543GC_FIBER:
137 	case E1000_DEV_ID_82543GC_COPPER:
138 		mac->type = e1000_82543;
139 		break;
140 	case E1000_DEV_ID_82544EI_COPPER:
141 	case E1000_DEV_ID_82544EI_FIBER:
142 	case E1000_DEV_ID_82544GC_COPPER:
143 	case E1000_DEV_ID_82544GC_LOM:
144 		mac->type = e1000_82544;
145 		break;
146 	case E1000_DEV_ID_82540EM:
147 	case E1000_DEV_ID_82540EM_LOM:
148 	case E1000_DEV_ID_82540EP:
149 	case E1000_DEV_ID_82540EP_LOM:
150 	case E1000_DEV_ID_82540EP_LP:
151 		mac->type = e1000_82540;
152 		break;
153 	case E1000_DEV_ID_82545EM_COPPER:
154 	case E1000_DEV_ID_82545EM_FIBER:
155 		mac->type = e1000_82545;
156 		break;
157 	case E1000_DEV_ID_82545GM_COPPER:
158 	case E1000_DEV_ID_82545GM_FIBER:
159 	case E1000_DEV_ID_82545GM_SERDES:
160 		mac->type = e1000_82545_rev_3;
161 		break;
162 	case E1000_DEV_ID_82546EB_COPPER:
163 	case E1000_DEV_ID_82546EB_FIBER:
164 	case E1000_DEV_ID_82546EB_QUAD_COPPER:
165 		mac->type = e1000_82546;
166 		break;
167 	case E1000_DEV_ID_82546GB_COPPER:
168 	case E1000_DEV_ID_82546GB_FIBER:
169 	case E1000_DEV_ID_82546GB_SERDES:
170 	case E1000_DEV_ID_82546GB_PCIE:
171 	case E1000_DEV_ID_82546GB_QUAD_COPPER:
172 	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
173 		mac->type = e1000_82546_rev_3;
174 		break;
175 	case E1000_DEV_ID_82541EI:
176 	case E1000_DEV_ID_82541EI_MOBILE:
177 	case E1000_DEV_ID_82541ER_LOM:
178 		mac->type = e1000_82541;
179 		break;
180 	case E1000_DEV_ID_82541ER:
181 	case E1000_DEV_ID_82541GI:
182 	case E1000_DEV_ID_82541GI_LF:
183 	case E1000_DEV_ID_82541GI_MOBILE:
184 		mac->type = e1000_82541_rev_2;
185 		break;
186 	case E1000_DEV_ID_82547EI:
187 	case E1000_DEV_ID_82547EI_MOBILE:
188 		mac->type = e1000_82547;
189 		break;
190 	case E1000_DEV_ID_82547GI:
191 		mac->type = e1000_82547_rev_2;
192 		break;
193 	case E1000_DEV_ID_82571EB_COPPER:
194 	case E1000_DEV_ID_82571EB_FIBER:
195 	case E1000_DEV_ID_82571EB_SERDES:
196 	case E1000_DEV_ID_82571EB_SERDES_DUAL:
197 	case E1000_DEV_ID_82571EB_SERDES_QUAD:
198 	case E1000_DEV_ID_82571EB_QUAD_COPPER:
199 	case E1000_DEV_ID_82571PT_QUAD_COPPER:
200 	case E1000_DEV_ID_82571EB_QUAD_FIBER:
201 	case E1000_DEV_ID_82571EB_QUAD_COPPER_LP:
202 		mac->type = e1000_82571;
203 		break;
204 	case E1000_DEV_ID_82572EI:
205 	case E1000_DEV_ID_82572EI_COPPER:
206 	case E1000_DEV_ID_82572EI_FIBER:
207 	case E1000_DEV_ID_82572EI_SERDES:
208 		mac->type = e1000_82572;
209 		break;
210 	case E1000_DEV_ID_82573E:
211 	case E1000_DEV_ID_82573E_IAMT:
212 	case E1000_DEV_ID_82573L:
213 		mac->type = e1000_82573;
214 		break;
215 	case E1000_DEV_ID_82574L:
216 		mac->type = e1000_82574;
217 		break;
218 	case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
219 	case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
220 	case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
221 	case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
222 		mac->type = e1000_80003es2lan;
223 		break;
224 	case E1000_DEV_ID_ICH8_IFE:
225 	case E1000_DEV_ID_ICH8_IFE_GT:
226 	case E1000_DEV_ID_ICH8_IFE_G:
227 	case E1000_DEV_ID_ICH8_IGP_M:
228 	case E1000_DEV_ID_ICH8_IGP_M_AMT:
229 	case E1000_DEV_ID_ICH8_IGP_AMT:
230 	case E1000_DEV_ID_ICH8_IGP_C:
231 		mac->type = e1000_ich8lan;
232 		break;
233 	case E1000_DEV_ID_ICH9_IFE:
234 	case E1000_DEV_ID_ICH9_IFE_GT:
235 	case E1000_DEV_ID_ICH9_IFE_G:
236 	case E1000_DEV_ID_ICH9_IGP_M:
237 	case E1000_DEV_ID_ICH9_IGP_M_AMT:
238 	case E1000_DEV_ID_ICH9_IGP_M_V:
239 	case E1000_DEV_ID_ICH9_IGP_AMT:
240 	case E1000_DEV_ID_ICH9_BM:
241 	case E1000_DEV_ID_ICH9_IGP_C:
242 	case E1000_DEV_ID_ICH10_R_BM_LM:
243 	case E1000_DEV_ID_ICH10_R_BM_LF:
244 	case E1000_DEV_ID_ICH10_R_BM_V:
245 		mac->type = e1000_ich9lan;
246 		break;
247 	case E1000_DEV_ID_ICH10_D_BM_LM:
248 	case E1000_DEV_ID_ICH10_D_BM_LF:
249 		mac->type = e1000_ich10lan;
250 		break;
251 	case E1000_DEV_ID_82575EB_COPPER:
252 	case E1000_DEV_ID_82575EB_FIBER_SERDES:
253 	case E1000_DEV_ID_82575GB_QUAD_COPPER:
254 	case E1000_DEV_ID_82575GB_QUAD_COPPER_PM:
255 		mac->type = e1000_82575;
256 		break;
257 	case E1000_DEV_ID_82576:
258 	case E1000_DEV_ID_82576_FIBER:
259 	case E1000_DEV_ID_82576_SERDES:
260 	case E1000_DEV_ID_82576_QUAD_COPPER:
261 	case E1000_DEV_ID_82576_NS:
262 		mac->type = e1000_82576;
263 		break;
264 	default:
265 		/* Should never have loaded on this device */
266 		ret_val = -E1000_ERR_MAC_INIT;
267 		break;
268 	}
269 
270 	return ret_val;
271 }
272 
273 /**
274  *  e1000_setup_init_funcs - Initializes function pointers
275  *  @hw: pointer to the HW structure
276  *  @init_device: TRUE will initialize the rest of the function pointers
277  *                 getting the device ready for use.  FALSE will only set
278  *                 MAC type and the function pointers for the other init
279  *                 functions.  Passing FALSE will not generate any hardware
280  *                 reads or writes.
281  *
282  *  This function must be called by a driver in order to use the rest
283  *  of the 'shared' code files. Called by drivers only.
284  **/
285 s32 e1000_setup_init_funcs(struct e1000_hw *hw, bool init_device)
286 {
287 	s32 ret_val;
288 
289 	/* Can't do much good without knowing the MAC type. */
290 	ret_val = e1000_set_mac_type(hw);
291 	if (ret_val) {
292 		DEBUGOUT("ERROR: MAC type could not be set properly.\n");
293 		goto out;
294 	}
295 
296 	if (!hw->hw_addr) {
297 		DEBUGOUT("ERROR: Registers not mapped\n");
298 		ret_val = -E1000_ERR_CONFIG;
299 		goto out;
300 	}
301 
302 	/*
303 	 * Init function pointers to generic implementations. We do this first
304 	 * allowing a driver module to override it afterward.
305 	 */
306 	e1000_init_mac_ops_generic(hw);
307 	e1000_init_phy_ops_generic(hw);
308 	e1000_init_nvm_ops_generic(hw);
309 
310 	/*
311 	 * Set up the init function pointers. These are functions within the
312 	 * adapter family file that sets up function pointers for the rest of
313 	 * the functions in that family.
314 	 */
315 	switch (hw->mac.type) {
316 	case e1000_82542:
317 		e1000_init_function_pointers_82542(hw);
318 		break;
319 	case e1000_82543:
320 	case e1000_82544:
321 		e1000_init_function_pointers_82543(hw);
322 		break;
323 	case e1000_82540:
324 	case e1000_82545:
325 	case e1000_82545_rev_3:
326 	case e1000_82546:
327 	case e1000_82546_rev_3:
328 		e1000_init_function_pointers_82540(hw);
329 		break;
330 	case e1000_82541:
331 	case e1000_82541_rev_2:
332 	case e1000_82547:
333 	case e1000_82547_rev_2:
334 		e1000_init_function_pointers_82541(hw);
335 		break;
336 	case e1000_82571:
337 	case e1000_82572:
338 	case e1000_82573:
339 	case e1000_82574:
340 		e1000_init_function_pointers_82571(hw);
341 		break;
342 	case e1000_80003es2lan:
343 		e1000_init_function_pointers_80003es2lan(hw);
344 		break;
345 	case e1000_ich8lan:
346 	case e1000_ich9lan:
347 	case e1000_ich10lan:
348 		e1000_init_function_pointers_ich8lan(hw);
349 		break;
350 	case e1000_82575:
351 	case e1000_82576:
352 		e1000_init_function_pointers_82575(hw);
353 		break;
354 	default:
355 		DEBUGOUT("Hardware not supported\n");
356 		ret_val = -E1000_ERR_CONFIG;
357 		break;
358 	}
359 
360 	/*
361 	 * Initialize the rest of the function pointers. These require some
362 	 * register reads/writes in some cases.
363 	 */
364 	if (!(ret_val) && init_device) {
365 		ret_val = e1000_init_mac_params(hw);
366 		if (ret_val)
367 			goto out;
368 
369 		ret_val = e1000_init_nvm_params(hw);
370 		if (ret_val)
371 			goto out;
372 
373 		ret_val = e1000_init_phy_params(hw);
374 		if (ret_val)
375 			goto out;
376 	}
377 
378 out:
379 	return ret_val;
380 }
381 
382 /**
383  *  e1000_get_bus_info - Obtain bus information for adapter
384  *  @hw: pointer to the HW structure
385  *
386  *  This will obtain information about the HW bus for which the
387  *  adapter is attached and stores it in the hw structure. This is a
388  *  function pointer entry point called by drivers.
389  **/
390 s32 e1000_get_bus_info(struct e1000_hw *hw)
391 {
392 	if (hw->mac.ops.get_bus_info)
393 		return hw->mac.ops.get_bus_info(hw);
394 
395 	return E1000_SUCCESS;
396 }
397 
398 /**
399  *  e1000_clear_vfta - Clear VLAN filter table
400  *  @hw: pointer to the HW structure
401  *
402  *  This clears the VLAN filter table on the adapter. This is a function
403  *  pointer entry point called by drivers.
404  **/
405 void e1000_clear_vfta(struct e1000_hw *hw)
406 {
407 	if (hw->mac.ops.clear_vfta)
408 		hw->mac.ops.clear_vfta(hw);
409 }
410 
411 /**
412  *  e1000_write_vfta - Write value to VLAN filter table
413  *  @hw: pointer to the HW structure
414  *  @offset: the 32-bit offset in which to write the value to.
415  *  @value: the 32-bit value to write at location offset.
416  *
417  *  This writes a 32-bit value to a 32-bit offset in the VLAN filter
418  *  table. This is a function pointer entry point called by drivers.
419  **/
420 void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
421 {
422 	if (hw->mac.ops.write_vfta)
423 		hw->mac.ops.write_vfta(hw, offset, value);
424 }
425 
426 /**
427  *  e1000_update_mc_addr_list - Update Multicast addresses
428  *  @hw: pointer to the HW structure
429  *  @mc_addr_list: array of multicast addresses to program
430  *  @mc_addr_count: number of multicast addresses to program
431  *
432  *  Updates the Multicast Table Array.
433  *  The caller must have a packed mc_addr_list of multicast addresses.
434  **/
435 void e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
436                                u32 mc_addr_count)
437 {
438 	if (hw->mac.ops.update_mc_addr_list)
439 		hw->mac.ops.update_mc_addr_list(hw, mc_addr_list,
440 		                                mc_addr_count);
441 }
442 
443 /**
444  *  e1000_force_mac_fc - Force MAC flow control
445  *  @hw: pointer to the HW structure
446  *
447  *  Force the MAC's flow control settings. Currently no func pointer exists
448  *  and all implementations are handled in the generic version of this
449  *  function.
450  **/
451 s32 e1000_force_mac_fc(struct e1000_hw *hw)
452 {
453 	return e1000_force_mac_fc_generic(hw);
454 }
455 
456 /**
457  *  e1000_check_for_link - Check/Store link connection
458  *  @hw: pointer to the HW structure
459  *
460  *  This checks the link condition of the adapter and stores the
461  *  results in the hw->mac structure. This is a function pointer entry
462  *  point called by drivers.
463  **/
464 s32 e1000_check_for_link(struct e1000_hw *hw)
465 {
466 	if (hw->mac.ops.check_for_link)
467 		return hw->mac.ops.check_for_link(hw);
468 
469 	return -E1000_ERR_CONFIG;
470 }
471 
472 /**
473  *  e1000_check_mng_mode - Check management mode
474  *  @hw: pointer to the HW structure
475  *
476  *  This checks if the adapter has manageability enabled.
477  *  This is a function pointer entry point called by drivers.
478  **/
479 bool e1000_check_mng_mode(struct e1000_hw *hw)
480 {
481 	if (hw->mac.ops.check_mng_mode)
482 		return hw->mac.ops.check_mng_mode(hw);
483 
484 	return FALSE;
485 }
486 
487 /**
488  *  e1000_mng_write_dhcp_info - Writes DHCP info to host interface
489  *  @hw: pointer to the HW structure
490  *  @buffer: pointer to the host interface
491  *  @length: size of the buffer
492  *
493  *  Writes the DHCP information to the host interface.
494  **/
495 s32 e1000_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length)
496 {
497 	return e1000_mng_write_dhcp_info_generic(hw, buffer, length);
498 }
499 
500 /**
501  *  e1000_reset_hw - Reset hardware
502  *  @hw: pointer to the HW structure
503  *
504  *  This resets the hardware into a known state. This is a function pointer
505  *  entry point called by drivers.
506  **/
507 s32 e1000_reset_hw(struct e1000_hw *hw)
508 {
509 	if (hw->mac.ops.reset_hw)
510 		return hw->mac.ops.reset_hw(hw);
511 
512 	return -E1000_ERR_CONFIG;
513 }
514 
515 /**
516  *  e1000_init_hw - Initialize hardware
517  *  @hw: pointer to the HW structure
518  *
519  *  This inits the hardware readying it for operation. This is a function
520  *  pointer entry point called by drivers.
521  **/
522 s32 e1000_init_hw(struct e1000_hw *hw)
523 {
524 	if (hw->mac.ops.init_hw)
525 		return hw->mac.ops.init_hw(hw);
526 
527 	return -E1000_ERR_CONFIG;
528 }
529 
530 /**
531  *  e1000_setup_link - Configures link and flow control
532  *  @hw: pointer to the HW structure
533  *
534  *  This configures link and flow control settings for the adapter. This
535  *  is a function pointer entry point called by drivers. While modules can
536  *  also call this, they probably call their own version of this function.
537  **/
538 s32 e1000_setup_link(struct e1000_hw *hw)
539 {
540 	if (hw->mac.ops.setup_link)
541 		return hw->mac.ops.setup_link(hw);
542 
543 	return -E1000_ERR_CONFIG;
544 }
545 
546 /**
547  *  e1000_get_speed_and_duplex - Returns current speed and duplex
548  *  @hw: pointer to the HW structure
549  *  @speed: pointer to a 16-bit value to store the speed
550  *  @duplex: pointer to a 16-bit value to store the duplex.
551  *
552  *  This returns the speed and duplex of the adapter in the two 'out'
553  *  variables passed in. This is a function pointer entry point called
554  *  by drivers.
555  **/
556 s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
557 {
558 	if (hw->mac.ops.get_link_up_info)
559 		return hw->mac.ops.get_link_up_info(hw, speed, duplex);
560 
561 	return -E1000_ERR_CONFIG;
562 }
563 
564 /**
565  *  e1000_setup_led - Configures SW controllable LED
566  *  @hw: pointer to the HW structure
567  *
568  *  This prepares the SW controllable LED for use and saves the current state
569  *  of the LED so it can be later restored. This is a function pointer entry
570  *  point called by drivers.
571  **/
572 s32 e1000_setup_led(struct e1000_hw *hw)
573 {
574 	if (hw->mac.ops.setup_led)
575 		return hw->mac.ops.setup_led(hw);
576 
577 	return E1000_SUCCESS;
578 }
579 
580 /**
581  *  e1000_cleanup_led - Restores SW controllable LED
582  *  @hw: pointer to the HW structure
583  *
584  *  This restores the SW controllable LED to the value saved off by
585  *  e1000_setup_led. This is a function pointer entry point called by drivers.
586  **/
587 s32 e1000_cleanup_led(struct e1000_hw *hw)
588 {
589 	if (hw->mac.ops.cleanup_led)
590 		return hw->mac.ops.cleanup_led(hw);
591 
592 	return E1000_SUCCESS;
593 }
594 
595 /**
596  *  e1000_blink_led - Blink SW controllable LED
597  *  @hw: pointer to the HW structure
598  *
599  *  This starts the adapter LED blinking. Request the LED to be setup first
600  *  and cleaned up after. This is a function pointer entry point called by
601  *  drivers.
602  **/
603 s32 e1000_blink_led(struct e1000_hw *hw)
604 {
605 	if (hw->mac.ops.blink_led)
606 		return hw->mac.ops.blink_led(hw);
607 
608 	return E1000_SUCCESS;
609 }
610 
611 /**
612  *  e1000_id_led_init - store LED configurations in SW
613  *  @hw: pointer to the HW structure
614  *
615  *  Initializes the LED config in SW. This is a function pointer entry point
616  *  called by drivers.
617  **/
618 s32 e1000_id_led_init(struct e1000_hw *hw)
619 {
620 	if (hw->mac.ops.id_led_init)
621 		return hw->mac.ops.id_led_init(hw);
622 
623 	return E1000_SUCCESS;
624 }
625 
626 /**
627  *  e1000_led_on - Turn on SW controllable LED
628  *  @hw: pointer to the HW structure
629  *
630  *  Turns the SW defined LED on. This is a function pointer entry point
631  *  called by drivers.
632  **/
633 s32 e1000_led_on(struct e1000_hw *hw)
634 {
635 	if (hw->mac.ops.led_on)
636 		return hw->mac.ops.led_on(hw);
637 
638 	return E1000_SUCCESS;
639 }
640 
641 /**
642  *  e1000_led_off - Turn off SW controllable LED
643  *  @hw: pointer to the HW structure
644  *
645  *  Turns the SW defined LED off. This is a function pointer entry point
646  *  called by drivers.
647  **/
648 s32 e1000_led_off(struct e1000_hw *hw)
649 {
650 	if (hw->mac.ops.led_off)
651 		return hw->mac.ops.led_off(hw);
652 
653 	return E1000_SUCCESS;
654 }
655 
656 /**
657  *  e1000_reset_adaptive - Reset adaptive IFS
658  *  @hw: pointer to the HW structure
659  *
660  *  Resets the adaptive IFS. Currently no func pointer exists and all
661  *  implementations are handled in the generic version of this function.
662  **/
663 void e1000_reset_adaptive(struct e1000_hw *hw)
664 {
665 	e1000_reset_adaptive_generic(hw);
666 }
667 
668 /**
669  *  e1000_update_adaptive - Update adaptive IFS
670  *  @hw: pointer to the HW structure
671  *
672  *  Updates adapter IFS. Currently no func pointer exists and all
673  *  implementations are handled in the generic version of this function.
674  **/
675 void e1000_update_adaptive(struct e1000_hw *hw)
676 {
677 	e1000_update_adaptive_generic(hw);
678 }
679 
680 /**
681  *  e1000_disable_pcie_master - Disable PCI-Express master access
682  *  @hw: pointer to the HW structure
683  *
684  *  Disables PCI-Express master access and verifies there are no pending
685  *  requests. Currently no func pointer exists and all implementations are
686  *  handled in the generic version of this function.
687  **/
688 s32 e1000_disable_pcie_master(struct e1000_hw *hw)
689 {
690 	return e1000_disable_pcie_master_generic(hw);
691 }
692 
693 /**
694  *  e1000_config_collision_dist - Configure collision distance
695  *  @hw: pointer to the HW structure
696  *
697  *  Configures the collision distance to the default value and is used
698  *  during link setup.
699  **/
700 void e1000_config_collision_dist(struct e1000_hw *hw)
701 {
702 	if (hw->mac.ops.config_collision_dist)
703 		hw->mac.ops.config_collision_dist(hw);
704 }
705 
706 /**
707  *  e1000_rar_set - Sets a receive address register
708  *  @hw: pointer to the HW structure
709  *  @addr: address to set the RAR to
710  *  @index: the RAR to set
711  *
712  *  Sets a Receive Address Register (RAR) to the specified address.
713  **/
714 void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
715 {
716 	if (hw->mac.ops.rar_set)
717 		hw->mac.ops.rar_set(hw, addr, index);
718 }
719 
720 /**
721  *  e1000_validate_mdi_setting - Ensures valid MDI/MDIX SW state
722  *  @hw: pointer to the HW structure
723  *
724  *  Ensures that the MDI/MDIX SW state is valid.
725  **/
726 s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
727 {
728 	if (hw->mac.ops.validate_mdi_setting)
729 		return hw->mac.ops.validate_mdi_setting(hw);
730 
731 	return E1000_SUCCESS;
732 }
733 
734 /**
735  *  e1000_mta_set - Sets multicast table bit
736  *  @hw: pointer to the HW structure
737  *  @hash_value: Multicast hash value.
738  *
739  *  This sets the bit in the multicast table corresponding to the
740  *  hash value.  This is a function pointer entry point called by drivers.
741  **/
742 void e1000_mta_set(struct e1000_hw *hw, u32 hash_value)
743 {
744 	if (hw->mac.ops.mta_set)
745 		hw->mac.ops.mta_set(hw, hash_value);
746 }
747 
748 /**
749  *  e1000_hash_mc_addr - Determines address location in multicast table
750  *  @hw: pointer to the HW structure
751  *  @mc_addr: Multicast address to hash.
752  *
753  *  This hashes an address to determine its location in the multicast
754  *  table. Currently no func pointer exists and all implementations
755  *  are handled in the generic version of this function.
756  **/
757 u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
758 {
759 	return e1000_hash_mc_addr_generic(hw, mc_addr);
760 }
761 
762 /**
763  *  e1000_enable_tx_pkt_filtering - Enable packet filtering on TX
764  *  @hw: pointer to the HW structure
765  *
766  *  Enables packet filtering on transmit packets if manageability is enabled
767  *  and host interface is enabled.
768  *  Currently no func pointer exists and all implementations are handled in the
769  *  generic version of this function.
770  **/
771 bool e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
772 {
773 	return e1000_enable_tx_pkt_filtering_generic(hw);
774 }
775 
776 /**
777  *  e1000_mng_host_if_write - Writes to the manageability host interface
778  *  @hw: pointer to the HW structure
779  *  @buffer: pointer to the host interface buffer
780  *  @length: size of the buffer
781  *  @offset: location in the buffer to write to
782  *  @sum: sum of the data (not checksum)
783  *
784  *  This function writes the buffer content at the offset given on the host if.
785  *  It also does alignment considerations to do the writes in most efficient
786  *  way.  Also fills up the sum of the buffer in *buffer parameter.
787  **/
788 s32 e1000_mng_host_if_write(struct e1000_hw * hw, u8 *buffer, u16 length,
789                             u16 offset, u8 *sum)
790 {
791 	if (hw->mac.ops.mng_host_if_write)
792 		return hw->mac.ops.mng_host_if_write(hw, buffer, length,
793 		                                     offset, sum);
794 
795 	return E1000_NOT_IMPLEMENTED;
796 }
797 
798 /**
799  *  e1000_mng_write_cmd_header - Writes manageability command header
800  *  @hw: pointer to the HW structure
801  *  @hdr: pointer to the host interface command header
802  *
803  *  Writes the command header after does the checksum calculation.
804  **/
805 s32 e1000_mng_write_cmd_header(struct e1000_hw *hw,
806                                struct e1000_host_mng_command_header *hdr)
807 {
808 	if (hw->mac.ops.mng_write_cmd_header)
809 		return hw->mac.ops.mng_write_cmd_header(hw, hdr);
810 
811 	return E1000_NOT_IMPLEMENTED;
812 }
813 
814 /**
815  *  e1000_mng_enable_host_if - Checks host interface is enabled
816  *  @hw: pointer to the HW structure
817  *
818  *  Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
819  *
820  *  This function checks whether the HOST IF is enabled for command operation
821  *  and also checks whether the previous command is completed.  It busy waits
822  *  in case of previous command is not completed.
823  **/
824 s32 e1000_mng_enable_host_if(struct e1000_hw * hw)
825 {
826 	if (hw->mac.ops.mng_enable_host_if)
827 		return hw->mac.ops.mng_enable_host_if(hw);
828 
829 	return E1000_NOT_IMPLEMENTED;
830 }
831 
832 /**
833  *  e1000_wait_autoneg - Waits for autonegotiation completion
834  *  @hw: pointer to the HW structure
835  *
836  *  Waits for autoneg to complete. Currently no func pointer exists and all
837  *  implementations are handled in the generic version of this function.
838  **/
839 s32 e1000_wait_autoneg(struct e1000_hw *hw)
840 {
841 	if (hw->mac.ops.wait_autoneg)
842 		return hw->mac.ops.wait_autoneg(hw);
843 
844 	return E1000_SUCCESS;
845 }
846 
847 /**
848  *  e1000_check_reset_block - Verifies PHY can be reset
849  *  @hw: pointer to the HW structure
850  *
851  *  Checks if the PHY is in a state that can be reset or if manageability
852  *  has it tied up. This is a function pointer entry point called by drivers.
853  **/
854 s32 e1000_check_reset_block(struct e1000_hw *hw)
855 {
856 	if (hw->phy.ops.check_reset_block)
857 		return hw->phy.ops.check_reset_block(hw);
858 
859 	return E1000_SUCCESS;
860 }
861 
862 /**
863  *  e1000_read_phy_reg - Reads PHY register
864  *  @hw: pointer to the HW structure
865  *  @offset: the register to read
866  *  @data: the buffer to store the 16-bit read.
867  *
868  *  Reads the PHY register and returns the value in data.
869  *  This is a function pointer entry point called by drivers.
870  **/
871 s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 offset, u16 *data)
872 {
873 	if (hw->phy.ops.read_reg)
874 		return hw->phy.ops.read_reg(hw, offset, data);
875 
876 	return E1000_SUCCESS;
877 }
878 
879 /**
880  *  e1000_write_phy_reg - Writes PHY register
881  *  @hw: pointer to the HW structure
882  *  @offset: the register to write
883  *  @data: the value to write.
884  *
885  *  Writes the PHY register at offset with the value in data.
886  *  This is a function pointer entry point called by drivers.
887  **/
888 s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 offset, u16 data)
889 {
890 	if (hw->phy.ops.write_reg)
891 		return hw->phy.ops.write_reg(hw, offset, data);
892 
893 	return E1000_SUCCESS;
894 }
895 
896 /**
897  *  e1000_release_phy - Generic release PHY
898  *  @hw: pointer to the HW structure
899  *
900  *  Return if silicon family does not require a semaphore when accessing the
901  *  PHY.
902  **/
903 void e1000_release_phy(struct e1000_hw *hw)
904 {
905 	if (hw->phy.ops.release)
906 		hw->phy.ops.release(hw);
907 }
908 
909 /**
910  *  e1000_acquire_phy - Generic acquire PHY
911  *  @hw: pointer to the HW structure
912  *
913  *  Return success if silicon family does not require a semaphore when
914  *  accessing the PHY.
915  **/
916 s32 e1000_acquire_phy(struct e1000_hw *hw)
917 {
918 	if (hw->phy.ops.acquire)
919 		return hw->phy.ops.acquire(hw);
920 
921 	return E1000_SUCCESS;
922 }
923 
924 /**
925  *  e1000_cfg_on_link_up - Configure PHY upon link up
926  *  @hw: pointer to the HW structure
927  **/
928 s32 e1000_cfg_on_link_up(struct e1000_hw *hw)
929 {
930 	if (hw->phy.ops.cfg_on_link_up)
931 		return hw->phy.ops.cfg_on_link_up(hw);
932 
933 	return E1000_SUCCESS;
934 }
935 
936 /**
937  *  e1000_read_kmrn_reg - Reads register using Kumeran interface
938  *  @hw: pointer to the HW structure
939  *  @offset: the register to read
940  *  @data: the location to store the 16-bit value read.
941  *
942  *  Reads a register out of the Kumeran interface. Currently no func pointer
943  *  exists and all implementations are handled in the generic version of
944  *  this function.
945  **/
946 s32 e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
947 {
948 	return e1000_read_kmrn_reg_generic(hw, offset, data);
949 }
950 
951 /**
952  *  e1000_write_kmrn_reg - Writes register using Kumeran interface
953  *  @hw: pointer to the HW structure
954  *  @offset: the register to write
955  *  @data: the value to write.
956  *
957  *  Writes a register to the Kumeran interface. Currently no func pointer
958  *  exists and all implementations are handled in the generic version of
959  *  this function.
960  **/
961 s32 e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
962 {
963 	return e1000_write_kmrn_reg_generic(hw, offset, data);
964 }
965 
966 /**
967  *  e1000_get_cable_length - Retrieves cable length estimation
968  *  @hw: pointer to the HW structure
969  *
970  *  This function estimates the cable length and stores them in
971  *  hw->phy.min_length and hw->phy.max_length. This is a function pointer
972  *  entry point called by drivers.
973  **/
974 s32 e1000_get_cable_length(struct e1000_hw *hw)
975 {
976 	if (hw->phy.ops.get_cable_length)
977 		return hw->phy.ops.get_cable_length(hw);
978 
979 	return E1000_SUCCESS;
980 }
981 
982 /**
983  *  e1000_get_phy_info - Retrieves PHY information from registers
984  *  @hw: pointer to the HW structure
985  *
986  *  This function gets some information from various PHY registers and
987  *  populates hw->phy values with it. This is a function pointer entry
988  *  point called by drivers.
989  **/
990 s32 e1000_get_phy_info(struct e1000_hw *hw)
991 {
992 	if (hw->phy.ops.get_info)
993 		return hw->phy.ops.get_info(hw);
994 
995 	return E1000_SUCCESS;
996 }
997 
998 /**
999  *  e1000_phy_hw_reset - Hard PHY reset
1000  *  @hw: pointer to the HW structure
1001  *
1002  *  Performs a hard PHY reset. This is a function pointer entry point called
1003  *  by drivers.
1004  **/
1005 s32 e1000_phy_hw_reset(struct e1000_hw *hw)
1006 {
1007 	if (hw->phy.ops.reset)
1008 		return hw->phy.ops.reset(hw);
1009 
1010 	return E1000_SUCCESS;
1011 }
1012 
1013 /**
1014  *  e1000_phy_commit - Soft PHY reset
1015  *  @hw: pointer to the HW structure
1016  *
1017  *  Performs a soft PHY reset on those that apply. This is a function pointer
1018  *  entry point called by drivers.
1019  **/
1020 s32 e1000_phy_commit(struct e1000_hw *hw)
1021 {
1022 	if (hw->phy.ops.commit)
1023 		return hw->phy.ops.commit(hw);
1024 
1025 	return E1000_SUCCESS;
1026 }
1027 
1028 /**
1029  *  e1000_set_d0_lplu_state - Sets low power link up state for D0
1030  *  @hw: pointer to the HW structure
1031  *  @active: boolean used to enable/disable lplu
1032  *
1033  *  Success returns 0, Failure returns 1
1034  *
1035  *  The low power link up (lplu) state is set to the power management level D0
1036  *  and SmartSpeed is disabled when active is TRUE, else clear lplu for D0
1037  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
1038  *  is used during Dx states where the power conservation is most important.
1039  *  During driver activity, SmartSpeed should be enabled so performance is
1040  *  maintained.  This is a function pointer entry point called by drivers.
1041  **/
1042 s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
1043 {
1044 	if (hw->phy.ops.set_d0_lplu_state)
1045 		return hw->phy.ops.set_d0_lplu_state(hw, active);
1046 
1047 	return E1000_SUCCESS;
1048 }
1049 
1050 /**
1051  *  e1000_set_d3_lplu_state - Sets low power link up state for D3
1052  *  @hw: pointer to the HW structure
1053  *  @active: boolean used to enable/disable lplu
1054  *
1055  *  Success returns 0, Failure returns 1
1056  *
1057  *  The low power link up (lplu) state is set to the power management level D3
1058  *  and SmartSpeed is disabled when active is TRUE, else clear lplu for D3
1059  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
1060  *  is used during Dx states where the power conservation is most important.
1061  *  During driver activity, SmartSpeed should be enabled so performance is
1062  *  maintained.  This is a function pointer entry point called by drivers.
1063  **/
1064 s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1065 {
1066 	if (hw->phy.ops.set_d3_lplu_state)
1067 		return hw->phy.ops.set_d3_lplu_state(hw, active);
1068 
1069 	return E1000_SUCCESS;
1070 }
1071 
1072 /**
1073  *  e1000_read_mac_addr - Reads MAC address
1074  *  @hw: pointer to the HW structure
1075  *
1076  *  Reads the MAC address out of the adapter and stores it in the HW structure.
1077  *  Currently no func pointer exists and all implementations are handled in the
1078  *  generic version of this function.
1079  **/
1080 s32 e1000_read_mac_addr(struct e1000_hw *hw)
1081 {
1082 	if (hw->mac.ops.read_mac_addr)
1083 		return hw->mac.ops.read_mac_addr(hw);
1084 
1085 	return e1000_read_mac_addr_generic(hw);
1086 }
1087 
1088 /**
1089  *  e1000_read_pba_num - Read device part number
1090  *  @hw: pointer to the HW structure
1091  *  @pba_num: pointer to device part number
1092  *
1093  *  Reads the product board assembly (PBA) number from the EEPROM and stores
1094  *  the value in pba_num.
1095  *  Currently no func pointer exists and all implementations are handled in the
1096  *  generic version of this function.
1097  **/
1098 s32 e1000_read_pba_num(struct e1000_hw *hw, u32 *pba_num)
1099 {
1100 	return e1000_read_pba_num_generic(hw, pba_num);
1101 }
1102 
1103 /**
1104  *  e1000_validate_nvm_checksum - Verifies NVM (EEPROM) checksum
1105  *  @hw: pointer to the HW structure
1106  *
1107  *  Validates the NVM checksum is correct. This is a function pointer entry
1108  *  point called by drivers.
1109  **/
1110 s32 e1000_validate_nvm_checksum(struct e1000_hw *hw)
1111 {
1112 	if (hw->nvm.ops.validate)
1113 		return hw->nvm.ops.validate(hw);
1114 
1115 	return -E1000_ERR_CONFIG;
1116 }
1117 
1118 /**
1119  *  e1000_update_nvm_checksum - Updates NVM (EEPROM) checksum
1120  *  @hw: pointer to the HW structure
1121  *
1122  *  Updates the NVM checksum. Currently no func pointer exists and all
1123  *  implementations are handled in the generic version of this function.
1124  **/
1125 s32 e1000_update_nvm_checksum(struct e1000_hw *hw)
1126 {
1127 	if (hw->nvm.ops.update)
1128 		return hw->nvm.ops.update(hw);
1129 
1130 	return -E1000_ERR_CONFIG;
1131 }
1132 
1133 /**
1134  *  e1000_reload_nvm - Reloads EEPROM
1135  *  @hw: pointer to the HW structure
1136  *
1137  *  Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
1138  *  extended control register.
1139  **/
1140 void e1000_reload_nvm(struct e1000_hw *hw)
1141 {
1142 	if (hw->nvm.ops.reload)
1143 		hw->nvm.ops.reload(hw);
1144 }
1145 
1146 /**
1147  *  e1000_read_nvm - Reads NVM (EEPROM)
1148  *  @hw: pointer to the HW structure
1149  *  @offset: the word offset to read
1150  *  @words: number of 16-bit words to read
1151  *  @data: pointer to the properly sized buffer for the data.
1152  *
1153  *  Reads 16-bit chunks of data from the NVM (EEPROM). This is a function
1154  *  pointer entry point called by drivers.
1155  **/
1156 s32 e1000_read_nvm(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
1157 {
1158 	if (hw->nvm.ops.read)
1159 		return hw->nvm.ops.read(hw, offset, words, data);
1160 
1161 	return -E1000_ERR_CONFIG;
1162 }
1163 
1164 /**
1165  *  e1000_write_nvm - Writes to NVM (EEPROM)
1166  *  @hw: pointer to the HW structure
1167  *  @offset: the word offset to read
1168  *  @words: number of 16-bit words to write
1169  *  @data: pointer to the properly sized buffer for the data.
1170  *
1171  *  Writes 16-bit chunks of data to the NVM (EEPROM). This is a function
1172  *  pointer entry point called by drivers.
1173  **/
1174 s32 e1000_write_nvm(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
1175 {
1176 	if (hw->nvm.ops.write)
1177 		return hw->nvm.ops.write(hw, offset, words, data);
1178 
1179 	return E1000_SUCCESS;
1180 }
1181 
1182 /**
1183  *  e1000_write_8bit_ctrl_reg - Writes 8bit Control register
1184  *  @hw: pointer to the HW structure
1185  *  @reg: 32bit register offset
1186  *  @offset: the register to write
1187  *  @data: the value to write.
1188  *
1189  *  Writes the PHY register at offset with the value in data.
1190  *  This is a function pointer entry point called by drivers.
1191  **/
1192 s32 e1000_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg, u32 offset,
1193                               u8 data)
1194 {
1195 	return e1000_write_8bit_ctrl_reg_generic(hw, reg, offset, data);
1196 }
1197 
1198 /**
1199  * e1000_power_up_phy - Restores link in case of PHY power down
1200  * @hw: pointer to the HW structure
1201  *
1202  * The phy may be powered down to save power, to turn off link when the
1203  * driver is unloaded, or wake on lan is not enabled (among others).
1204  **/
1205 void e1000_power_up_phy(struct e1000_hw *hw)
1206 {
1207 	if (hw->phy.ops.power_up)
1208 		hw->phy.ops.power_up(hw);
1209 
1210 	e1000_setup_link(hw);
1211 }
1212 
1213 /**
1214  * e1000_power_down_phy - Power down PHY
1215  * @hw: pointer to the HW structure
1216  *
1217  * The phy may be powered down to save power, to turn off link when the
1218  * driver is unloaded, or wake on lan is not enabled (among others).
1219  **/
1220 void e1000_power_down_phy(struct e1000_hw *hw)
1221 {
1222 	if (hw->phy.ops.power_down)
1223 		hw->phy.ops.power_down(hw);
1224 }
1225 
1226 /**
1227  *  e1000_shutdown_fiber_serdes_link - Remove link during power down
1228  *  @hw: pointer to the HW structure
1229  *
1230  *  Shutdown the optics and PCS on driver unload.
1231  **/
1232 void e1000_shutdown_fiber_serdes_link(struct e1000_hw *hw)
1233 {
1234 	if (hw->mac.ops.shutdown_serdes)
1235 		hw->mac.ops.shutdown_serdes(hw);
1236 }
1237 
1238