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