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