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