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