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