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