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