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