xref: /onnv-gate/usr/src/uts/common/io/igb/igb_api.c (revision 5812:ab06e6e0aa03)
1 /*
2  * CDDL HEADER START
3  *
4  * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at:
10  *	http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When using or redistributing this file, you may do so under the
15  * License only. No other modification of this header is permitted.
16  *
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 
24 /*
25  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms of the CDDL.
27  */
28 
29 /* IntelVersion: 1.73 v2007-12-10_dragonlake5 */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include "igb_api.h"
34 #include "igb_mac.h"
35 #include "igb_nvm.h"
36 #include "igb_phy.h"
37 
38 /*
39  * e1000_init_mac_params - Initialize MAC function pointers
40  * @hw: pointer to the HW structure
41  *
42  * This function initializes the function pointers for the MAC
43  * set of functions.  Called by drivers or by e1000_setup_init_funcs.
44  */
45 s32
46 e1000_init_mac_params(struct e1000_hw *hw)
47 {
48 	s32 ret_val = E1000_SUCCESS;
49 
50 	if (hw->func.init_mac_params) {
51 		ret_val = hw->func.init_mac_params(hw);
52 		if (ret_val) {
53 			DEBUGOUT("MAC Initialization Error\n");
54 			goto out;
55 		}
56 	} else {
57 		DEBUGOUT("mac.init_mac_params was NULL\n");
58 		ret_val = -E1000_ERR_CONFIG;
59 	}
60 
61 out:
62 	return (ret_val);
63 }
64 
65 /*
66  * e1000_init_nvm_params - Initialize NVM function pointers
67  * @hw: pointer to the HW structure
68  *
69  * This function initializes the function pointers for the NVM
70  * set of functions.  Called by drivers or by e1000_setup_init_funcs.
71  */
72 s32
73 e1000_init_nvm_params(struct e1000_hw *hw)
74 {
75 	s32 ret_val = E1000_SUCCESS;
76 
77 	if (hw->func.init_nvm_params) {
78 		ret_val = hw->func.init_nvm_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 
88 out:
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  */
99 s32
100 e1000_init_phy_params(struct e1000_hw *hw)
101 {
102 	s32 ret_val = E1000_SUCCESS;
103 
104 	if (hw->func.init_phy_params) {
105 		ret_val = hw->func.init_phy_params(hw);
106 		if (ret_val) {
107 			DEBUGOUT("PHY Initialization Error\n");
108 			goto out;
109 		}
110 	} else {
111 		DEBUGOUT("phy.init_phy_params was NULL\n");
112 		ret_val =  -E1000_ERR_CONFIG;
113 	}
114 
115 out:
116 	return (ret_val);
117 }
118 
119 /*
120  * e1000_set_mac_type - Sets MAC type
121  * @hw: pointer to the HW structure
122  *
123  * This function sets the mac type of the adapter based on the
124  * device ID stored in the hw structure.
125  * MUST BE FIRST FUNCTION CALLED (explicitly or through
126  * e1000_setup_init_funcs()).
127  */
128 s32
129 e1000_set_mac_type(struct e1000_hw *hw)
130 {
131 	struct e1000_mac_info *mac = &hw->mac;
132 	s32 ret_val = E1000_SUCCESS;
133 
134 	DEBUGFUNC("e1000_set_mac_type");
135 
136 	switch (hw->device_id) {
137 	case E1000_DEV_ID_82575EB_COPPER:
138 	case E1000_DEV_ID_82575EB_FIBER_SERDES:
139 	case E1000_DEV_ID_82575GB_QUAD_COPPER:
140 		mac->type = e1000_82575;
141 		break;
142 	default:
143 		/* Should never have loaded on this device */
144 		ret_val = -E1000_ERR_MAC_INIT;
145 		break;
146 	}
147 
148 	return (ret_val);
149 }
150 
151 /*
152  * e1000_setup_init_funcs - Initializes function pointers
153  * @hw: pointer to the HW structure
154  * @init_device: TRUE will initialize the rest of the function pointers
155  *		getting the device ready for use.  FALSE will only set
156  *		MAC type and the function pointers for the other init
157  *		functions.  Passing FALSE will not generate any hardware
158  *		reads or writes.
159  *
160  * This function must be called by a driver in order to use the rest
161  * of the 'shared' code files. Called by drivers only.
162  */
163 s32
164 e1000_setup_init_funcs(struct e1000_hw *hw, bool init_device)
165 {
166 	s32 ret_val;
167 
168 	/* Can't do much good without knowing the MAC type. */
169 	ret_val = e1000_set_mac_type(hw);
170 	if (ret_val) {
171 		DEBUGOUT("ERROR: MAC type could not be set properly.\n");
172 		goto out;
173 	}
174 
175 	if (!hw->hw_addr) {
176 		DEBUGOUT("ERROR: Registers not mapped\n");
177 		ret_val = -E1000_ERR_CONFIG;
178 		goto out;
179 	}
180 
181 	/*
182 	 * Init some generic function pointers that are currently all pointing
183 	 * to generic implementations. We do this first allowing a driver
184 	 * module to override it afterwards.
185 	 */
186 	hw->func.config_collision_dist = e1000_config_collision_dist_generic;
187 	hw->func.rar_set = e1000_rar_set_generic;
188 	hw->func.validate_mdi_setting = e1000_validate_mdi_setting_generic;
189 	hw->func.mng_host_if_write = e1000_mng_host_if_write_generic;
190 	hw->func.mng_write_cmd_header = e1000_mng_write_cmd_header_generic;
191 	hw->func.mng_enable_host_if = e1000_mng_enable_host_if_generic;
192 	hw->func.wait_autoneg = e1000_wait_autoneg_generic;
193 	hw->func.reload_nvm = e1000_reload_nvm_generic;
194 
195 	/*
196 	 * Set up the init function pointers. These are functions within the
197 	 * adapter family file that sets up function pointers for the rest of
198 	 * the functions in that family.
199 	 */
200 	switch (hw->mac.type) {
201 	case e1000_82575:
202 		e1000_init_function_pointers_82575(hw);
203 		break;
204 	default:
205 		DEBUGOUT("Hardware not supported\n");
206 		ret_val = -E1000_ERR_CONFIG;
207 		break;
208 	}
209 
210 	/*
211 	 * Initialize the rest of the function pointers. These require some
212 	 * register reads/writes in some cases.
213 	 */
214 	if (!(ret_val) && init_device) {
215 		ret_val = e1000_init_mac_params(hw);
216 		if (ret_val)
217 			goto out;
218 
219 		ret_val = e1000_init_nvm_params(hw);
220 		if (ret_val)
221 			goto out;
222 
223 		ret_val = e1000_init_phy_params(hw);
224 		if (ret_val)
225 			goto out;
226 
227 	}
228 
229 out:
230 	return (ret_val);
231 }
232 
233 /*
234  * e1000_remove_device - Free device specific structure
235  * @hw: pointer to the HW structure
236  *
237  * If a device specific structure was allocated, this function will
238  * free it. This is a function pointer entry point called by drivers.
239  */
240 void
241 e1000_remove_device(struct e1000_hw *hw)
242 {
243 	if (hw->func.remove_device)
244 		hw->func.remove_device(hw);
245 }
246 
247 /*
248  * e1000_get_bus_info - Obtain bus information for adapter
249  * @hw: pointer to the HW structure
250  *
251  * This will obtain information about the HW bus for which the
252  * adaper is attached and stores it in the hw structure. This is a
253  * function pointer entry point called by drivers.
254  */
255 s32
256 e1000_get_bus_info(struct e1000_hw *hw)
257 {
258 	if (hw->func.get_bus_info)
259 		return (hw->func.get_bus_info(hw));
260 
261 	return (E1000_SUCCESS);
262 }
263 
264 /*
265  * e1000_clear_vfta - Clear VLAN filter table
266  * @hw: pointer to the HW structure
267  *
268  * This clears the VLAN filter table on the adapter. This is a function
269  * pointer entry point called by drivers.
270  */
271 void
272 e1000_clear_vfta(struct e1000_hw *hw)
273 {
274 	if (hw->func.clear_vfta)
275 		hw->func.clear_vfta(hw);
276 }
277 
278 /*
279  * e1000_write_vfta - Write value to VLAN filter table
280  * @hw: pointer to the HW structure
281  * @offset: the 32-bit offset in which to write the value to.
282  * @value: the 32-bit value to write at location offset.
283  *
284  * This writes a 32-bit value to a 32-bit offset in the VLAN filter
285  * table. This is a function pointer entry point called by drivers.
286  */
287 void
288 e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
289 {
290 	if (hw->func.write_vfta)
291 		hw->func.write_vfta(hw, offset, value);
292 }
293 
294 /*
295  * e1000_update_mc_addr_list - Update Multicast addresses
296  * @hw: pointer to the HW structure
297  * @mc_addr_list: array of multicast addresses to program
298  * @mc_addr_count: number of multicast addresses to program
299  * @rar_used_count: the first RAR register free to program
300  * @rar_count: total number of supported Receive Address Registers
301  *
302  * Updates the Receive Address Registers and Multicast Table Array.
303  * The caller must have a packed mc_addr_list of multicast addresses.
304  * The parameter rar_count will usually be hw->mac.rar_entry_count
305  * unless there are workarounds that change this.  Currently no func pointer
306  * exists and all implementations are handled in the generic version of this
307  * function.
308  */
309 void
310 e1000_update_mc_addr_list(struct e1000_hw *hw, u8 *mc_addr_list,
311     u32 mc_addr_count, u32 rar_used_count, u32 rar_count)
312 {
313 	if (hw->func.update_mc_addr_list)
314 		hw->func.update_mc_addr_list(hw,
315 		    mc_addr_list,
316 		    mc_addr_count,
317 		    rar_used_count,
318 		    rar_count);
319 }
320 
321 /*
322  * e1000_force_mac_fc - Force MAC flow control
323  * @hw: pointer to the HW structure
324  *
325  * Force the MAC's flow control settings. Currently no func pointer exists
326  * and all implementations are handled in the generic version of this
327  * function.
328  */
329 s32
330 e1000_force_mac_fc(struct e1000_hw *hw)
331 {
332 	return (e1000_force_mac_fc_generic(hw));
333 }
334 
335 /*
336  * e1000_check_for_link - Check/Store link connection
337  * @hw: pointer to the HW structure
338  *
339  * This checks the link condition of the adapter and stores the
340  * results in the hw->mac structure. This is a function pointer entry
341  * point called by drivers.
342  */
343 s32
344 e1000_check_for_link(struct e1000_hw *hw)
345 {
346 	if (hw->func.check_for_link)
347 		return (hw->func.check_for_link(hw));
348 
349 	return (-E1000_ERR_CONFIG);
350 }
351 
352 /*
353  * e1000_check_mng_mode - Check management mode
354  * @hw: pointer to the HW structure
355  *
356  * This checks if the adapter has manageability enabled.
357  * This is a function pointer entry point called by drivers.
358  */
359 bool
360 e1000_check_mng_mode(struct e1000_hw *hw)
361 {
362 	if (hw->func.check_mng_mode)
363 		return (hw->func.check_mng_mode(hw));
364 
365 	return (FALSE);
366 }
367 
368 /*
369  * e1000_mng_write_dhcp_info - Writes DHCP info to host interface
370  * @hw: pointer to the HW structure
371  * @buffer: pointer to the host interface
372  * @length: size of the buffer
373  *
374  * Writes the DHCP information to the host interface.
375  */
376 s32
377 e1000_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length)
378 {
379 	return (e1000_mng_write_dhcp_info_generic(hw, buffer, length));
380 }
381 
382 /*
383  * e1000_reset_hw - Reset hardware
384  * @hw: pointer to the HW structure
385  *
386  * This resets the hardware into a known state. This is a function pointer
387  * entry point called by drivers.
388  */
389 s32
390 e1000_reset_hw(struct e1000_hw *hw)
391 {
392 	if (hw->func.reset_hw)
393 		return (hw->func.reset_hw(hw));
394 
395 	return (-E1000_ERR_CONFIG);
396 }
397 
398 /*
399  * e1000_init_hw - Initialize hardware
400  * @hw: pointer to the HW structure
401  *
402  * This inits the hardware readying it for operation. This is a function
403  * pointer entry point called by drivers.
404  */
405 s32
406 e1000_init_hw(struct e1000_hw *hw)
407 {
408 	if (hw->func.init_hw)
409 		return (hw->func.init_hw(hw));
410 
411 	return (-E1000_ERR_CONFIG);
412 }
413 
414 /*
415  * e1000_setup_link - Configures link and flow control
416  * @hw: pointer to the HW structure
417  *
418  * This configures link and flow control settings for the adapter. This
419  * is a function pointer entry point called by drivers. While modules can
420  * also call this, they probably call their own version of this function.
421  */
422 s32
423 e1000_setup_link(struct e1000_hw *hw)
424 {
425 	if (hw->func.setup_link)
426 		return (hw->func.setup_link(hw));
427 
428 	return (-E1000_ERR_CONFIG);
429 }
430 
431 /*
432  * e1000_get_speed_and_duplex - Returns current speed and duplex
433  * @hw: pointer to the HW structure
434  * @speed: pointer to a 16-bit value to store the speed
435  * @duplex: pointer to a 16-bit value to store the duplex.
436  *
437  * This returns the speed and duplex of the adapter in the two 'out'
438  * variables passed in. This is a function pointer entry point called
439  * by drivers.
440  */
441 s32
442 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
443 {
444 	if (hw->func.get_link_up_info)
445 		return (hw->func.get_link_up_info(hw, speed, duplex));
446 
447 	return (-E1000_ERR_CONFIG);
448 }
449 
450 /*
451  * e1000_setup_led - Configures SW controllable LED
452  * @hw: pointer to the HW structure
453  *
454  * This prepares the SW controllable LED for use and saves the current state
455  * of the LED so it can be later restored. This is a function pointer entry
456  * point called by drivers.
457  */
458 s32
459 e1000_setup_led(struct e1000_hw *hw)
460 {
461 	if (hw->func.setup_led)
462 		return (hw->func.setup_led(hw));
463 
464 	return (E1000_SUCCESS);
465 }
466 
467 /*
468  * e1000_cleanup_led - Restores SW controllable LED
469  * @hw: pointer to the HW structure
470  *
471  * This restores the SW controllable LED to the value saved off by
472  * e1000_setup_led. This is a function pointer entry point called by drivers.
473  */
474 s32
475 e1000_cleanup_led(struct e1000_hw *hw)
476 {
477 	if (hw->func.cleanup_led)
478 		return (hw->func.cleanup_led(hw));
479 
480 	return (E1000_SUCCESS);
481 }
482 
483 /*
484  * e1000_blink_led - Blink SW controllable LED
485  * @hw: pointer to the HW structure
486  *
487  * This starts the adapter LED blinking. Request the LED to be setup first
488  * and cleaned up after. This is a function pointer entry point called by
489  * drivers.
490  */
491 s32
492 e1000_blink_led(struct e1000_hw *hw)
493 {
494 	if (hw->func.blink_led)
495 		return (hw->func.blink_led(hw));
496 
497 	return (E1000_SUCCESS);
498 }
499 
500 /*
501  * e1000_led_on - Turn on SW controllable LED
502  * @hw: pointer to the HW structure
503  *
504  * Turns the SW defined LED on. This is a function pointer entry point
505  * called by drivers.
506  */
507 s32
508 e1000_led_on(struct e1000_hw *hw)
509 {
510 	if (hw->func.led_on)
511 		return (hw->func.led_on(hw));
512 
513 	return (E1000_SUCCESS);
514 }
515 
516 /*
517  * e1000_led_off - Turn off SW controllable LED
518  * @hw: pointer to the HW structure
519  *
520  * Turns the SW defined LED off. This is a function pointer entry point
521  * called by drivers.
522  */
523 s32
524 e1000_led_off(struct e1000_hw *hw)
525 {
526 	if (hw->func.led_off)
527 		return (hw->func.led_off(hw));
528 
529 	return (E1000_SUCCESS);
530 }
531 
532 /*
533  * e1000_reset_adaptive - Reset adaptive IFS
534  * @hw: pointer to the HW structure
535  *
536  * Resets the adaptive IFS. Currently no func pointer exists and all
537  * implementations are handled in the generic version of this function.
538  */
539 void
540 e1000_reset_adaptive(struct e1000_hw *hw)
541 {
542 	e1000_reset_adaptive_generic(hw);
543 }
544 
545 /*
546  * e1000_update_adaptive - Update adaptive IFS
547  * @hw: pointer to the HW structure
548  *
549  * Updates adapter IFS. Currently no func pointer exists and all
550  * implementations are handled in the generic version of this function.
551  */
552 void
553 e1000_update_adaptive(struct e1000_hw *hw)
554 {
555 	e1000_update_adaptive_generic(hw);
556 }
557 
558 /*
559  * e1000_disable_pcie_master - Disable PCI-Express master access
560  * @hw: pointer to the HW structure
561  *
562  * Disables PCI-Express master access and verifies there are no pending
563  * requests. Currently no func pointer exists and all implementations are
564  * handled in the generic version of this function.
565  */
566 s32
567 e1000_disable_pcie_master(struct e1000_hw *hw)
568 {
569 	return (e1000_disable_pcie_master_generic(hw));
570 }
571 
572 /*
573  * e1000_config_collision_dist - Configure collision distance
574  * @hw: pointer to the HW structure
575  *
576  * Configures the collision distance to the default value and is used
577  * during link setup.
578  */
579 void
580 e1000_config_collision_dist(struct e1000_hw *hw)
581 {
582 	if (hw->func.config_collision_dist)
583 		hw->func.config_collision_dist(hw);
584 }
585 
586 /*
587  * e1000_rar_set - Sets a receive address register
588  * @hw: pointer to the HW structure
589  * @addr: address to set the RAR to
590  * @index: the RAR to set
591  *
592  * Sets a Receive Address Register (RAR) to the specified address.
593  */
594 void
595 e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
596 {
597 	if (hw->func.rar_set)
598 		hw->func.rar_set(hw, addr, index);
599 }
600 
601 /*
602  * e1000_validate_mdi_setting - Ensures valid MDI/MDIX SW state
603  * @hw: pointer to the HW structure
604  *
605  * Ensures that the MDI/MDIX SW state is valid.
606  */
607 s32
608 e1000_validate_mdi_setting(struct e1000_hw *hw)
609 {
610 	if (hw->func.validate_mdi_setting)
611 		return (hw->func.validate_mdi_setting(hw));
612 
613 	return (E1000_SUCCESS);
614 }
615 
616 /*
617  * e1000_mta_set - Sets multicast table bit
618  * @hw: pointer to the HW structure
619  * @hash_value: Multicast hash value.
620  *
621  * This sets the bit in the multicast table corresponding to the
622  * hash value.  This is a function pointer entry point called by drivers.
623  */
624 void
625 e1000_mta_set(struct e1000_hw *hw, u32 hash_value)
626 {
627 	if (hw->func.mta_set)
628 		hw->func.mta_set(hw, hash_value);
629 }
630 
631 /*
632  * e1000_hash_mc_addr - Determines address location in multicast table
633  * @hw: pointer to the HW structure
634  * @mc_addr: Multicast address to hash.
635  *
636  * This hashes an address to determine its location in the multicast
637  * table. Currently no func pointer exists and all implementations
638  * are handled in the generic version of this function.
639  */
640 u32
641 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
642 {
643 	return (e1000_hash_mc_addr_generic(hw, mc_addr));
644 }
645 
646 /*
647  * e1000_enable_tx_pkt_filtering - Enable packet filtering on TX
648  * @hw: pointer to the HW structure
649  *
650  * Enables packet filtering on transmit packets if manageability is enabled
651  * and host interface is enabled.
652  * Currently no func pointer exists and all implementations are handled in the
653  * generic version of this function.
654  */
655 bool
656 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
657 {
658 	return (e1000_enable_tx_pkt_filtering_generic(hw));
659 }
660 
661 /*
662  * e1000_mng_host_if_write - Writes to the manageability host interface
663  * @hw: pointer to the HW structure
664  * @buffer: pointer to the host interface buffer
665  * @length: size of the buffer
666  * @offset: location in the buffer to write to
667  * @sum: sum of the data (not checksum)
668  *
669  * This function writes the buffer content at the offset given on the host if.
670  * It also does alignment considerations to do the writes in most efficient
671  * way.  Also fills up the sum of the buffer in *buffer parameter.
672  */
673 s32
674 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, u16 length,
675     u16 offset, u8 *sum)
676 {
677 	if (hw->func.mng_host_if_write)
678 		return (hw->func.mng_host_if_write(hw, buffer, length, offset,
679 		    sum));
680 
681 	return (E1000_NOT_IMPLEMENTED);
682 }
683 
684 /*
685  * e1000_mng_write_cmd_header - Writes manageability command header
686  * @hw: pointer to the HW structure
687  * @hdr: pointer to the host interface command header
688  *
689  * Writes the command header after does the checksum calculation.
690  */
691 s32
692 e1000_mng_write_cmd_header(struct e1000_hw *hw,
693     struct e1000_host_mng_command_header *hdr)
694 {
695 	if (hw->func.mng_write_cmd_header)
696 		return (hw->func.mng_write_cmd_header(hw, hdr));
697 
698 	return (E1000_NOT_IMPLEMENTED);
699 }
700 
701 /*
702  * e1000_mng_enable_host_if - Checks host interface is enabled
703  * @hw: pointer to the HW structure
704  *
705  * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
706  *
707  * This function checks whether the HOST IF is enabled for command operaton
708  * and also checks whether the previous command is completed.  It busy waits
709  * in case of previous command is not completed.
710  */
711 s32
712 e1000_mng_enable_host_if(struct e1000_hw *hw)
713 {
714 	if (hw->func.mng_enable_host_if)
715 		return (hw->func.mng_enable_host_if(hw));
716 
717 	return (E1000_NOT_IMPLEMENTED);
718 }
719 
720 /*
721  * e1000_wait_autoneg - Waits for autonegotiation completion
722  * @hw: pointer to the HW structure
723  *
724  * Waits for autoneg to complete. Currently no func pointer exists and all
725  * implementations are handled in the generic version of this function.
726  */
727 s32
728 e1000_wait_autoneg(struct e1000_hw *hw)
729 {
730 	if (hw->func.wait_autoneg)
731 		return (hw->func.wait_autoneg(hw));
732 
733 	return (E1000_SUCCESS);
734 }
735 
736 /*
737  * e1000_check_reset_block - Verifies PHY can be reset
738  * @hw: pointer to the HW structure
739  *
740  * Checks if the PHY is in a state that can be reset or if manageability
741  * has it tied up. This is a function pointer entry point called by drivers.
742  */
743 s32
744 e1000_check_reset_block(struct e1000_hw *hw)
745 {
746 	if (hw->func.check_reset_block)
747 		return (hw->func.check_reset_block(hw));
748 
749 	return (E1000_SUCCESS);
750 }
751 
752 /*
753  * e1000_read_phy_reg - Reads PHY register
754  * @hw: pointer to the HW structure
755  * @offset: the register to read
756  * @data: the buffer to store the 16-bit read.
757  *
758  * Reads the PHY register and returns the value in data.
759  * This is a function pointer entry point called by drivers.
760  */
761 s32
762 e1000_read_phy_reg(struct e1000_hw *hw, u32 offset, u16 *data)
763 {
764 	if (hw->func.read_phy_reg)
765 		return (hw->func.read_phy_reg(hw, offset, data));
766 
767 	return (E1000_SUCCESS);
768 }
769 
770 /*
771  * e1000_write_phy_reg - Writes PHY register
772  * @hw: pointer to the HW structure
773  * @offset: the register to write
774  * @data: the value to write.
775  *
776  * Writes the PHY register at offset with the value in data.
777  * This is a function pointer entry point called by drivers.
778  */
779 s32
780 e1000_write_phy_reg(struct e1000_hw *hw, u32 offset, u16 data)
781 {
782 	if (hw->func.write_phy_reg)
783 		return (hw->func.write_phy_reg(hw, offset, data));
784 
785 	return (E1000_SUCCESS);
786 }
787 
788 /*
789  * e1000_read_kmrn_reg - Reads register using Kumeran interface
790  * @hw: pointer to the HW structure
791  * @offset: the register to read
792  * @data: the location to store the 16-bit value read.
793  *
794  * Reads a register out of the Kumeran interface. Currently no func pointer
795  * exists and all implementations are handled in the generic version of
796  * this function.
797  */
798 s32
799 e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
800 {
801 	return (e1000_read_kmrn_reg_generic(hw, offset, data));
802 }
803 
804 /*
805  * e1000_write_kmrn_reg - Writes register using Kumeran interface
806  * @hw: pointer to the HW structure
807  * @offset: the register to write
808  * @data: the value to write.
809  *
810  * Writes a register to the Kumeran interface. Currently no func pointer
811  * exists and all implementations are handled in the generic version of
812  * this function.
813  */
814 s32
815 e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
816 {
817 	return (e1000_write_kmrn_reg_generic(hw, offset, data));
818 }
819 
820 /*
821  * e1000_get_cable_length - Retrieves cable length estimation
822  * @hw: pointer to the HW structure
823  *
824  * This function estimates the cable length and stores them in
825  * hw->phy.min_length and hw->phy.max_length. This is a function pointer
826  * entry point called by drivers.
827  */
828 s32
829 e1000_get_cable_length(struct e1000_hw *hw)
830 {
831 	if (hw->func.get_cable_length)
832 		return (hw->func.get_cable_length(hw));
833 
834 	return (E1000_SUCCESS);
835 }
836 
837 /*
838  * e1000_get_phy_info - Retrieves PHY information from registers
839  * @hw: pointer to the HW structure
840  *
841  * This function gets some information from various PHY registers and
842  * populates hw->phy values with it. This is a function pointer entry
843  * point called by drivers.
844  */
845 s32
846 e1000_get_phy_info(struct e1000_hw *hw)
847 {
848 	if (hw->func.get_phy_info)
849 		return (hw->func.get_phy_info(hw));
850 
851 	return (E1000_SUCCESS);
852 }
853 
854 /*
855  * e1000_phy_hw_reset - Hard PHY reset
856  * @hw: pointer to the HW structure
857  *
858  * Performs a hard PHY reset. This is a function pointer entry point called
859  * by drivers.
860  */
861 s32
862 e1000_phy_hw_reset(struct e1000_hw *hw)
863 {
864 	if (hw->func.reset_phy)
865 		return (hw->func.reset_phy(hw));
866 
867 	return (E1000_SUCCESS);
868 }
869 
870 /*
871  * e1000_phy_commit - Soft PHY reset
872  * @hw: pointer to the HW structure
873  *
874  * Performs a soft PHY reset on those that apply. This is a function pointer
875  * entry point called by drivers.
876  */
877 s32
878 e1000_phy_commit(struct e1000_hw *hw)
879 {
880 	if (hw->func.commit_phy)
881 		return (hw->func.commit_phy(hw));
882 
883 	return (E1000_SUCCESS);
884 }
885 
886 /*
887  * e1000_set_d3_lplu_state - Sets low power link up state for D0
888  * @hw: pointer to the HW structure
889  * @active: boolean used to enable/disable lplu
890  *
891  * Success returns 0, Failure returns 1
892  *
893  * The low power link up (lplu) state is set to the power management level D0
894  * and SmartSpeed is disabled when active is true, else clear lplu for D0
895  * and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
896  * is used during Dx states where the power conservation is most important.
897  * During driver activity, SmartSpeed should be enabled so performance is
898  * maintained.  This is a function pointer entry point called by drivers.
899  */
900 s32
901 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
902 {
903 	if (hw->func.set_d0_lplu_state)
904 		return (hw->func.set_d0_lplu_state(hw, active));
905 
906 	return (E1000_SUCCESS);
907 }
908 
909 /*
910  * e1000_set_d3_lplu_state - Sets low power link up state for D3
911  * @hw: pointer to the HW structure
912  * @active: boolean used to enable/disable lplu
913  *
914  * Success returns 0, Failure returns 1
915  *
916  * The low power link up (lplu) state is set to the power management level D3
917  * and SmartSpeed is disabled when active is true, else clear lplu for D3
918  * and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
919  * is used during Dx states where the power conservation is most important.
920  * During driver activity, SmartSpeed should be enabled so performance is
921  * maintained.  This is a function pointer entry point called by drivers.
922  */
923 s32
924 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
925 {
926 	if (hw->func.set_d3_lplu_state)
927 		return (hw->func.set_d3_lplu_state(hw, active));
928 
929 	return (E1000_SUCCESS);
930 }
931 
932 /*
933  * e1000_read_mac_addr - Reads MAC address
934  * @hw: pointer to the HW structure
935  *
936  * Reads the MAC address out of the adapter and stores it in the HW structure.
937  * Currently no func pointer exists and all implementations are handled in the
938  * generic version of this function.
939  */
940 s32
941 e1000_read_mac_addr(struct e1000_hw *hw)
942 {
943 	if (hw->func.read_mac_addr)
944 		return (hw->func.read_mac_addr(hw));
945 
946 	return (e1000_read_mac_addr_generic(hw));
947 }
948 
949 /*
950  * e1000_read_pba_num - Read device part number
951  * @hw: pointer to the HW structure
952  * @pba_num: pointer to device part number
953  *
954  * Reads the product board assembly (PBA) number from the EEPROM and stores
955  * the value in pba_num.
956  * Currently no func pointer exists and all implementations are handled in the
957  * generic version of this function.
958  */
959 s32
960 e1000_read_pba_num(struct e1000_hw *hw, u32 *pba_num)
961 {
962 	return (e1000_read_pba_num_generic(hw, pba_num));
963 }
964 
965 /*
966  * e1000_validate_nvm_checksum - Verifies NVM (EEPROM) checksum
967  * @hw: pointer to the HW structure
968  *
969  * Validates the NVM checksum is correct. This is a function pointer entry
970  * point called by drivers.
971  */
972 s32
973 e1000_validate_nvm_checksum(struct e1000_hw *hw)
974 {
975 	if (hw->func.validate_nvm)
976 		return (hw->func.validate_nvm(hw));
977 
978 	return (-E1000_ERR_CONFIG);
979 }
980 
981 /*
982  * e1000_update_nvm_checksum - Updates NVM (EEPROM) checksum
983  * @hw: pointer to the HW structure
984  *
985  * Updates the NVM checksum. Currently no func pointer exists and all
986  * implementations are handled in the generic version of this function.
987  */
988 s32
989 e1000_update_nvm_checksum(struct e1000_hw *hw)
990 {
991 	if (hw->func.update_nvm)
992 		return (hw->func.update_nvm(hw));
993 
994 	return (-E1000_ERR_CONFIG);
995 }
996 
997 /*
998  * e1000_reload_nvm - Reloads EEPROM
999  * @hw: pointer to the HW structure
1000  *
1001  * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
1002  * extended control register.
1003  */
1004 void
1005 e1000_reload_nvm(struct e1000_hw *hw)
1006 {
1007 	if (hw->func.reload_nvm)
1008 		hw->func.reload_nvm(hw);
1009 }
1010 
1011 /*
1012  * e1000_read_nvm - Reads NVM (EEPROM)
1013  * @hw: pointer to the HW structure
1014  * @offset: the word offset to read
1015  * @words: number of 16-bit words to read
1016  * @data: pointer to the properly sized buffer for the data.
1017  *
1018  * Reads 16-bit chunks of data from the NVM (EEPROM). This is a function
1019  * pointer entry point called by drivers.
1020  */
1021 s32
1022 e1000_read_nvm(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
1023 {
1024 	if (hw->func.read_nvm)
1025 		return (hw->func.read_nvm(hw, offset, words, data));
1026 
1027 	return (-E1000_ERR_CONFIG);
1028 }
1029 
1030 /*
1031  * e1000_write_nvm - Writes to NVM (EEPROM)
1032  * @hw: pointer to the HW structure
1033  * @offset: the word offset to read
1034  * @words: number of 16-bit words to write
1035  * @data: pointer to the properly sized buffer for the data.
1036  *
1037  * Writes 16-bit chunks of data to the NVM (EEPROM). This is a function
1038  * pointer entry point called by drivers.
1039  */
1040 s32
1041 e1000_write_nvm(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
1042 {
1043 	if (hw->func.write_nvm)
1044 		return (hw->func.write_nvm(hw, offset, words, data));
1045 
1046 	return (E1000_SUCCESS);
1047 }
1048 
1049 /*
1050  * e1000_write_8bit_ctrl_reg - Writes 8bit Control register
1051  * @hw: pointer to the HW structure
1052  * @reg: 32bit register offset
1053  * @offset: the register to write
1054  * @data: the value to write.
1055  *
1056  * Writes the PHY register at offset with the value in data.
1057  * This is a function pointer entry point called by drivers.
1058  */
1059 s32
1060 e1000_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg, u32 offset, u8 data)
1061 {
1062 	return (e1000_write_8bit_ctrl_reg_generic(hw, reg, offset, data));
1063 }
1064 
1065 /*
1066  * e1000_power_up_phy - Restores link in case of PHY power down
1067  * @hw: pointer to the HW structure
1068  *
1069  * The phy may be powered down to save power, to turn off link when the
1070  * driver is unloaded, or wake on lan is not enabled (among others).
1071  */
1072 void
1073 e1000_power_up_phy(struct e1000_hw *hw)
1074 {
1075 	if (hw->func.power_up_phy)
1076 		hw->func.power_up_phy(hw);
1077 
1078 	(void) e1000_setup_link(hw);
1079 }
1080 
1081 /*
1082  * e1000_power_down_phy - Power down PHY
1083  * @hw: pointer to the HW structure
1084  *
1085  * The phy may be powered down to save power, to turn off link when the
1086  * driver is unloaded, or wake on lan is not enabled (among others).
1087  */
1088 void
1089 e1000_power_down_phy(struct e1000_hw *hw)
1090 {
1091 	if (hw->func.power_down_phy)
1092 		hw->func.power_down_phy(hw);
1093 }
1094