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