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