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