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