f9fa721b6718aa00445b2c762ed4c807d632748c
[dpdk.git] / drivers / net / ngbe / base / ngbe_hw.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3  * Copyright(c) 2010-2017 Intel Corporation
4  */
5
6 #include "ngbe_type.h"
7 #include "ngbe_phy.h"
8 #include "ngbe_eeprom.h"
9 #include "ngbe_mng.h"
10 #include "ngbe_hw.h"
11
12 /**
13  *  ngbe_start_hw - Prepare hardware for Tx/Rx
14  *  @hw: pointer to hardware structure
15  *
16  *  Starts the hardware.
17  **/
18 s32 ngbe_start_hw(struct ngbe_hw *hw)
19 {
20         DEBUGFUNC("ngbe_start_hw");
21
22         /* Clear the VLAN filter table */
23         hw->mac.clear_vfta(hw);
24
25         /* Clear statistics registers */
26         hw->mac.clear_hw_cntrs(hw);
27
28         /* Clear adapter stopped flag */
29         hw->adapter_stopped = false;
30
31         return 0;
32 }
33
34 /**
35  *  ngbe_init_hw - Generic hardware initialization
36  *  @hw: pointer to hardware structure
37  *
38  *  Initialize the hardware by resetting the hardware, filling the bus info
39  *  structure and media type, clears all on chip counters, initializes receive
40  *  address registers, multicast table, VLAN filter table, calls routine to set
41  *  up link and flow control settings, and leaves transmit and receive units
42  *  disabled and uninitialized
43  **/
44 s32 ngbe_init_hw(struct ngbe_hw *hw)
45 {
46         s32 status;
47
48         DEBUGFUNC("ngbe_init_hw");
49
50         ngbe_save_eeprom_version(hw);
51
52         /* Reset the hardware */
53         status = hw->mac.reset_hw(hw);
54         if (status == 0) {
55                 /* Start the HW */
56                 status = hw->mac.start_hw(hw);
57         }
58
59         if (status != 0)
60                 DEBUGOUT("Failed to initialize HW, STATUS = %d\n", status);
61
62         return status;
63 }
64
65 static void
66 ngbe_reset_misc_em(struct ngbe_hw *hw)
67 {
68         int i;
69
70         wr32(hw, NGBE_ISBADDRL, hw->isb_dma & 0xFFFFFFFF);
71         wr32(hw, NGBE_ISBADDRH, hw->isb_dma >> 32);
72
73         /* receive packets that size > 2048 */
74         wr32m(hw, NGBE_MACRXCFG,
75                 NGBE_MACRXCFG_JUMBO, NGBE_MACRXCFG_JUMBO);
76
77         wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
78                 NGBE_FRMSZ_MAX(NGBE_FRAME_SIZE_DFT));
79
80         /* clear counters on read */
81         wr32m(hw, NGBE_MACCNTCTL,
82                 NGBE_MACCNTCTL_RC, NGBE_MACCNTCTL_RC);
83
84         wr32m(hw, NGBE_RXFCCFG,
85                 NGBE_RXFCCFG_FC, NGBE_RXFCCFG_FC);
86         wr32m(hw, NGBE_TXFCCFG,
87                 NGBE_TXFCCFG_FC, NGBE_TXFCCFG_FC);
88
89         wr32m(hw, NGBE_MACRXFLT,
90                 NGBE_MACRXFLT_PROMISC, NGBE_MACRXFLT_PROMISC);
91
92         wr32m(hw, NGBE_RSTSTAT,
93                 NGBE_RSTSTAT_TMRINIT_MASK, NGBE_RSTSTAT_TMRINIT(30));
94
95         /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
96         wr32(hw, NGBE_MNGFLEXSEL, 0);
97         for (i = 0; i < 16; i++) {
98                 wr32(hw, NGBE_MNGFLEXDWL(i), 0);
99                 wr32(hw, NGBE_MNGFLEXDWH(i), 0);
100                 wr32(hw, NGBE_MNGFLEXMSK(i), 0);
101         }
102         wr32(hw, NGBE_LANFLEXSEL, 0);
103         for (i = 0; i < 16; i++) {
104                 wr32(hw, NGBE_LANFLEXDWL(i), 0);
105                 wr32(hw, NGBE_LANFLEXDWH(i), 0);
106                 wr32(hw, NGBE_LANFLEXMSK(i), 0);
107         }
108
109         /* set pause frame dst mac addr */
110         wr32(hw, NGBE_RXPBPFCDMACL, 0xC2000001);
111         wr32(hw, NGBE_RXPBPFCDMACH, 0x0180);
112
113         wr32(hw, NGBE_MDIOMODE, 0xF);
114
115         wr32m(hw, NGBE_GPIE, NGBE_GPIE_MSIX, NGBE_GPIE_MSIX);
116
117         if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
118                 (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
119                 /* gpio0 is used to power on/off control*/
120                 wr32(hw, NGBE_GPIODIR, NGBE_GPIODIR_DDR(1));
121                 wr32(hw, NGBE_GPIODATA, NGBE_GPIOBIT_0);
122         }
123
124         hw->mac.init_thermal_sensor_thresh(hw);
125
126         /* enable mac transmitter */
127         wr32m(hw, NGBE_MACTXCFG, NGBE_MACTXCFG_TE, NGBE_MACTXCFG_TE);
128
129         /* sellect GMII */
130         wr32m(hw, NGBE_MACTXCFG,
131                 NGBE_MACTXCFG_SPEED_MASK, NGBE_MACTXCFG_SPEED_1G);
132
133         for (i = 0; i < 4; i++)
134                 wr32m(hw, NGBE_IVAR(i), 0x80808080, 0);
135 }
136
137 /**
138  *  ngbe_reset_hw_em - Perform hardware reset
139  *  @hw: pointer to hardware structure
140  *
141  *  Resets the hardware by resetting the transmit and receive units, masks
142  *  and clears all interrupts, perform a PHY reset, and perform a link (MAC)
143  *  reset.
144  **/
145 s32 ngbe_reset_hw_em(struct ngbe_hw *hw)
146 {
147         s32 status;
148
149         DEBUGFUNC("ngbe_reset_hw_em");
150
151         /* Call adapter stop to disable tx/rx and clear interrupts */
152         status = hw->mac.stop_hw(hw);
153         if (status != 0)
154                 return status;
155
156         /* Identify PHY and related function pointers */
157         status = ngbe_init_phy(hw);
158         if (status)
159                 return status;
160
161         /* Reset PHY */
162         if (!hw->phy.reset_disable)
163                 hw->phy.reset_hw(hw);
164
165         wr32(hw, NGBE_RST, NGBE_RST_LAN(hw->bus.lan_id));
166         ngbe_flush(hw);
167         msec_delay(50);
168
169         ngbe_reset_misc_em(hw);
170         hw->mac.clear_hw_cntrs(hw);
171
172         msec_delay(50);
173
174         /* Store the permanent mac address */
175         hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
176
177         /*
178          * Store MAC address from RAR0, clear receive address registers, and
179          * clear the multicast table.
180          */
181         hw->mac.num_rar_entries = NGBE_EM_RAR_ENTRIES;
182         hw->mac.init_rx_addrs(hw);
183
184         return status;
185 }
186
187 /**
188  *  ngbe_clear_hw_cntrs - Generic clear hardware counters
189  *  @hw: pointer to hardware structure
190  *
191  *  Clears all hardware statistics counters by reading them from the hardware
192  *  Statistics counters are clear on read.
193  **/
194 s32 ngbe_clear_hw_cntrs(struct ngbe_hw *hw)
195 {
196         u16 i = 0;
197
198         DEBUGFUNC("ngbe_clear_hw_cntrs");
199
200         /* QP Stats */
201         /* don't write clear queue stats */
202         for (i = 0; i < NGBE_MAX_QP; i++) {
203                 hw->qp_last[i].rx_qp_packets = 0;
204                 hw->qp_last[i].tx_qp_packets = 0;
205                 hw->qp_last[i].rx_qp_bytes = 0;
206                 hw->qp_last[i].tx_qp_bytes = 0;
207                 hw->qp_last[i].rx_qp_mc_packets = 0;
208                 hw->qp_last[i].tx_qp_mc_packets = 0;
209                 hw->qp_last[i].rx_qp_bc_packets = 0;
210                 hw->qp_last[i].tx_qp_bc_packets = 0;
211         }
212
213         /* PB Stats */
214         rd32(hw, NGBE_PBRXLNKXON);
215         rd32(hw, NGBE_PBRXLNKXOFF);
216         rd32(hw, NGBE_PBTXLNKXON);
217         rd32(hw, NGBE_PBTXLNKXOFF);
218
219         /* DMA Stats */
220         rd32(hw, NGBE_DMARXPKT);
221         rd32(hw, NGBE_DMATXPKT);
222
223         rd64(hw, NGBE_DMARXOCTL);
224         rd64(hw, NGBE_DMATXOCTL);
225
226         /* MAC Stats */
227         rd64(hw, NGBE_MACRXERRCRCL);
228         rd64(hw, NGBE_MACRXMPKTL);
229         rd64(hw, NGBE_MACTXMPKTL);
230
231         rd64(hw, NGBE_MACRXPKTL);
232         rd64(hw, NGBE_MACTXPKTL);
233         rd64(hw, NGBE_MACRXGBOCTL);
234
235         rd64(hw, NGBE_MACRXOCTL);
236         rd32(hw, NGBE_MACTXOCTL);
237
238         rd64(hw, NGBE_MACRX1TO64L);
239         rd64(hw, NGBE_MACRX65TO127L);
240         rd64(hw, NGBE_MACRX128TO255L);
241         rd64(hw, NGBE_MACRX256TO511L);
242         rd64(hw, NGBE_MACRX512TO1023L);
243         rd64(hw, NGBE_MACRX1024TOMAXL);
244         rd64(hw, NGBE_MACTX1TO64L);
245         rd64(hw, NGBE_MACTX65TO127L);
246         rd64(hw, NGBE_MACTX128TO255L);
247         rd64(hw, NGBE_MACTX256TO511L);
248         rd64(hw, NGBE_MACTX512TO1023L);
249         rd64(hw, NGBE_MACTX1024TOMAXL);
250
251         rd64(hw, NGBE_MACRXERRLENL);
252         rd32(hw, NGBE_MACRXOVERSIZE);
253         rd32(hw, NGBE_MACRXJABBER);
254
255         /* MACsec Stats */
256         rd32(hw, NGBE_LSECTX_UTPKT);
257         rd32(hw, NGBE_LSECTX_ENCPKT);
258         rd32(hw, NGBE_LSECTX_PROTPKT);
259         rd32(hw, NGBE_LSECTX_ENCOCT);
260         rd32(hw, NGBE_LSECTX_PROTOCT);
261         rd32(hw, NGBE_LSECRX_UTPKT);
262         rd32(hw, NGBE_LSECRX_BTPKT);
263         rd32(hw, NGBE_LSECRX_NOSCIPKT);
264         rd32(hw, NGBE_LSECRX_UNSCIPKT);
265         rd32(hw, NGBE_LSECRX_DECOCT);
266         rd32(hw, NGBE_LSECRX_VLDOCT);
267         rd32(hw, NGBE_LSECRX_UNCHKPKT);
268         rd32(hw, NGBE_LSECRX_DLYPKT);
269         rd32(hw, NGBE_LSECRX_LATEPKT);
270         for (i = 0; i < 2; i++) {
271                 rd32(hw, NGBE_LSECRX_OKPKT(i));
272                 rd32(hw, NGBE_LSECRX_INVPKT(i));
273                 rd32(hw, NGBE_LSECRX_BADPKT(i));
274         }
275         for (i = 0; i < 4; i++) {
276                 rd32(hw, NGBE_LSECRX_INVSAPKT(i));
277                 rd32(hw, NGBE_LSECRX_BADSAPKT(i));
278         }
279
280         return 0;
281 }
282
283 /**
284  *  ngbe_get_mac_addr - Generic get MAC address
285  *  @hw: pointer to hardware structure
286  *  @mac_addr: Adapter MAC address
287  *
288  *  Reads the adapter's MAC address from first Receive Address Register (RAR0)
289  *  A reset of the adapter must be performed prior to calling this function
290  *  in order for the MAC address to have been loaded from the EEPROM into RAR0
291  **/
292 s32 ngbe_get_mac_addr(struct ngbe_hw *hw, u8 *mac_addr)
293 {
294         u32 rar_high;
295         u32 rar_low;
296         u16 i;
297
298         DEBUGFUNC("ngbe_get_mac_addr");
299
300         wr32(hw, NGBE_ETHADDRIDX, 0);
301         rar_high = rd32(hw, NGBE_ETHADDRH);
302         rar_low = rd32(hw, NGBE_ETHADDRL);
303
304         for (i = 0; i < 2; i++)
305                 mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
306
307         for (i = 0; i < 4; i++)
308                 mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
309
310         return 0;
311 }
312
313 /**
314  *  ngbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
315  *  @hw: pointer to the HW structure
316  *
317  *  Determines the LAN function id by reading memory-mapped registers and swaps
318  *  the port value if requested, and set MAC instance for devices.
319  **/
320 void ngbe_set_lan_id_multi_port(struct ngbe_hw *hw)
321 {
322         struct ngbe_bus_info *bus = &hw->bus;
323         u32 reg = 0;
324
325         DEBUGFUNC("ngbe_set_lan_id_multi_port");
326
327         reg = rd32(hw, NGBE_PORTSTAT);
328         bus->lan_id = NGBE_PORTSTAT_ID(reg);
329         bus->func = bus->lan_id;
330 }
331
332 /**
333  *  ngbe_stop_hw - Generic stop Tx/Rx units
334  *  @hw: pointer to hardware structure
335  *
336  *  Sets the adapter_stopped flag within ngbe_hw struct. Clears interrupts,
337  *  disables transmit and receive units. The adapter_stopped flag is used by
338  *  the shared code and drivers to determine if the adapter is in a stopped
339  *  state and should not touch the hardware.
340  **/
341 s32 ngbe_stop_hw(struct ngbe_hw *hw)
342 {
343         u32 reg_val;
344         u16 i;
345
346         DEBUGFUNC("ngbe_stop_hw");
347
348         /*
349          * Set the adapter_stopped flag so other driver functions stop touching
350          * the hardware
351          */
352         hw->adapter_stopped = true;
353
354         /* Disable the receive unit */
355         ngbe_disable_rx(hw);
356
357         /* Clear interrupt mask to stop interrupts from being generated */
358         wr32(hw, NGBE_IENMISC, 0);
359         wr32(hw, NGBE_IMS(0), NGBE_IMS_MASK);
360
361         /* Clear any pending interrupts, flush previous writes */
362         wr32(hw, NGBE_ICRMISC, NGBE_ICRMISC_MASK);
363         wr32(hw, NGBE_ICR(0), NGBE_ICR_MASK);
364
365         /* Disable the transmit unit.  Each queue must be disabled. */
366         for (i = 0; i < hw->mac.max_tx_queues; i++)
367                 wr32(hw, NGBE_TXCFG(i), NGBE_TXCFG_FLUSH);
368
369         /* Disable the receive unit by stopping each queue */
370         for (i = 0; i < hw->mac.max_rx_queues; i++) {
371                 reg_val = rd32(hw, NGBE_RXCFG(i));
372                 reg_val &= ~NGBE_RXCFG_ENA;
373                 wr32(hw, NGBE_RXCFG(i), reg_val);
374         }
375
376         /* flush all queues disables */
377         ngbe_flush(hw);
378         msec_delay(2);
379
380         return 0;
381 }
382
383 /**
384  *  ngbe_validate_mac_addr - Validate MAC address
385  *  @mac_addr: pointer to MAC address.
386  *
387  *  Tests a MAC address to ensure it is a valid Individual Address.
388  **/
389 s32 ngbe_validate_mac_addr(u8 *mac_addr)
390 {
391         s32 status = 0;
392
393         DEBUGFUNC("ngbe_validate_mac_addr");
394
395         /* Make sure it is not a multicast address */
396         if (NGBE_IS_MULTICAST((struct rte_ether_addr *)mac_addr)) {
397                 status = NGBE_ERR_INVALID_MAC_ADDR;
398         /* Not a broadcast address */
399         } else if (NGBE_IS_BROADCAST((struct rte_ether_addr *)mac_addr)) {
400                 status = NGBE_ERR_INVALID_MAC_ADDR;
401         /* Reject the zero address */
402         } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
403                    mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
404                 status = NGBE_ERR_INVALID_MAC_ADDR;
405         }
406         return status;
407 }
408
409 /**
410  *  ngbe_set_rar - Set Rx address register
411  *  @hw: pointer to hardware structure
412  *  @index: Receive address register to write
413  *  @addr: Address to put into receive address register
414  *  @vmdq: VMDq "set" or "pool" index
415  *  @enable_addr: set flag that address is active
416  *
417  *  Puts an ethernet address into a receive address register.
418  **/
419 s32 ngbe_set_rar(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
420                           u32 enable_addr)
421 {
422         u32 rar_low, rar_high;
423         u32 rar_entries = hw->mac.num_rar_entries;
424
425         DEBUGFUNC("ngbe_set_rar");
426
427         /* Make sure we are using a valid rar index range */
428         if (index >= rar_entries) {
429                 DEBUGOUT("RAR index %d is out of range.\n", index);
430                 return NGBE_ERR_INVALID_ARGUMENT;
431         }
432
433         /* setup VMDq pool selection before this RAR gets enabled */
434         hw->mac.set_vmdq(hw, index, vmdq);
435
436         /*
437          * HW expects these in little endian so we reverse the byte
438          * order from network order (big endian) to little endian
439          */
440         rar_low = NGBE_ETHADDRL_AD0(addr[5]) |
441                   NGBE_ETHADDRL_AD1(addr[4]) |
442                   NGBE_ETHADDRL_AD2(addr[3]) |
443                   NGBE_ETHADDRL_AD3(addr[2]);
444         /*
445          * Some parts put the VMDq setting in the extra RAH bits,
446          * so save everything except the lower 16 bits that hold part
447          * of the address and the address valid bit.
448          */
449         rar_high = rd32(hw, NGBE_ETHADDRH);
450         rar_high &= ~NGBE_ETHADDRH_AD_MASK;
451         rar_high |= (NGBE_ETHADDRH_AD4(addr[1]) |
452                      NGBE_ETHADDRH_AD5(addr[0]));
453
454         rar_high &= ~NGBE_ETHADDRH_VLD;
455         if (enable_addr != 0)
456                 rar_high |= NGBE_ETHADDRH_VLD;
457
458         wr32(hw, NGBE_ETHADDRIDX, index);
459         wr32(hw, NGBE_ETHADDRL, rar_low);
460         wr32(hw, NGBE_ETHADDRH, rar_high);
461
462         return 0;
463 }
464
465 /**
466  *  ngbe_clear_rar - Remove Rx address register
467  *  @hw: pointer to hardware structure
468  *  @index: Receive address register to write
469  *
470  *  Clears an ethernet address from a receive address register.
471  **/
472 s32 ngbe_clear_rar(struct ngbe_hw *hw, u32 index)
473 {
474         u32 rar_high;
475         u32 rar_entries = hw->mac.num_rar_entries;
476
477         DEBUGFUNC("ngbe_clear_rar");
478
479         /* Make sure we are using a valid rar index range */
480         if (index >= rar_entries) {
481                 DEBUGOUT("RAR index %d is out of range.\n", index);
482                 return NGBE_ERR_INVALID_ARGUMENT;
483         }
484
485         /*
486          * Some parts put the VMDq setting in the extra RAH bits,
487          * so save everything except the lower 16 bits that hold part
488          * of the address and the address valid bit.
489          */
490         wr32(hw, NGBE_ETHADDRIDX, index);
491         rar_high = rd32(hw, NGBE_ETHADDRH);
492         rar_high &= ~(NGBE_ETHADDRH_AD_MASK | NGBE_ETHADDRH_VLD);
493
494         wr32(hw, NGBE_ETHADDRL, 0);
495         wr32(hw, NGBE_ETHADDRH, rar_high);
496
497         /* clear VMDq pool/queue selection for this RAR */
498         hw->mac.clear_vmdq(hw, index, BIT_MASK32);
499
500         return 0;
501 }
502
503 /**
504  *  ngbe_init_rx_addrs - Initializes receive address filters.
505  *  @hw: pointer to hardware structure
506  *
507  *  Places the MAC address in receive address register 0 and clears the rest
508  *  of the receive address registers. Clears the multicast table. Assumes
509  *  the receiver is in reset when the routine is called.
510  **/
511 s32 ngbe_init_rx_addrs(struct ngbe_hw *hw)
512 {
513         u32 i;
514         u32 psrctl;
515         u32 rar_entries = hw->mac.num_rar_entries;
516
517         DEBUGFUNC("ngbe_init_rx_addrs");
518
519         /*
520          * If the current mac address is valid, assume it is a software override
521          * to the permanent address.
522          * Otherwise, use the permanent address from the eeprom.
523          */
524         if (ngbe_validate_mac_addr(hw->mac.addr) ==
525             NGBE_ERR_INVALID_MAC_ADDR) {
526                 /* Get the MAC address from the RAR0 for later reference */
527                 hw->mac.get_mac_addr(hw, hw->mac.addr);
528
529                 DEBUGOUT(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
530                           hw->mac.addr[0], hw->mac.addr[1],
531                           hw->mac.addr[2]);
532                 DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
533                           hw->mac.addr[4], hw->mac.addr[5]);
534         } else {
535                 /* Setup the receive address. */
536                 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
537                 DEBUGOUT(" New MAC Addr =%.2X %.2X %.2X ",
538                           hw->mac.addr[0], hw->mac.addr[1],
539                           hw->mac.addr[2]);
540                 DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
541                           hw->mac.addr[4], hw->mac.addr[5]);
542
543                 hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
544         }
545
546         /* clear VMDq pool/queue selection for RAR 0 */
547         hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
548
549         /* Zero out the other receive addresses. */
550         DEBUGOUT("Clearing RAR[1-%d]\n", rar_entries - 1);
551         for (i = 1; i < rar_entries; i++) {
552                 wr32(hw, NGBE_ETHADDRIDX, i);
553                 wr32(hw, NGBE_ETHADDRL, 0);
554                 wr32(hw, NGBE_ETHADDRH, 0);
555         }
556
557         /* Clear the MTA */
558         hw->addr_ctrl.mta_in_use = 0;
559         psrctl = rd32(hw, NGBE_PSRCTL);
560         psrctl &= ~(NGBE_PSRCTL_ADHF12_MASK | NGBE_PSRCTL_MCHFENA);
561         psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
562         wr32(hw, NGBE_PSRCTL, psrctl);
563
564         DEBUGOUT(" Clearing MTA\n");
565         for (i = 0; i < hw->mac.mcft_size; i++)
566                 wr32(hw, NGBE_MCADDRTBL(i), 0);
567
568         ngbe_init_uta_tables(hw);
569
570         return 0;
571 }
572
573 /**
574  *  ngbe_acquire_swfw_sync - Acquire SWFW semaphore
575  *  @hw: pointer to hardware structure
576  *  @mask: Mask to specify which semaphore to acquire
577  *
578  *  Acquires the SWFW semaphore through the MNGSEM register for the specified
579  *  function (CSR, PHY0, PHY1, EEPROM, Flash)
580  **/
581 s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask)
582 {
583         u32 mngsem = 0;
584         u32 swmask = NGBE_MNGSEM_SW(mask);
585         u32 fwmask = NGBE_MNGSEM_FW(mask);
586         u32 timeout = 200;
587         u32 i;
588
589         DEBUGFUNC("ngbe_acquire_swfw_sync");
590
591         for (i = 0; i < timeout; i++) {
592                 /*
593                  * SW NVM semaphore bit is used for access to all
594                  * SW_FW_SYNC bits (not just NVM)
595                  */
596                 if (ngbe_get_eeprom_semaphore(hw))
597                         return NGBE_ERR_SWFW_SYNC;
598
599                 mngsem = rd32(hw, NGBE_MNGSEM);
600                 if (mngsem & (fwmask | swmask)) {
601                         /* Resource is currently in use by FW or SW */
602                         ngbe_release_eeprom_semaphore(hw);
603                         msec_delay(5);
604                 } else {
605                         mngsem |= swmask;
606                         wr32(hw, NGBE_MNGSEM, mngsem);
607                         ngbe_release_eeprom_semaphore(hw);
608                         return 0;
609                 }
610         }
611
612         /* If time expired clear the bits holding the lock and retry */
613         if (mngsem & (fwmask | swmask))
614                 ngbe_release_swfw_sync(hw, mngsem & (fwmask | swmask));
615
616         msec_delay(5);
617         return NGBE_ERR_SWFW_SYNC;
618 }
619
620 /**
621  *  ngbe_release_swfw_sync - Release SWFW semaphore
622  *  @hw: pointer to hardware structure
623  *  @mask: Mask to specify which semaphore to release
624  *
625  *  Releases the SWFW semaphore through the MNGSEM register for the specified
626  *  function (CSR, PHY0, PHY1, EEPROM, Flash)
627  **/
628 void ngbe_release_swfw_sync(struct ngbe_hw *hw, u32 mask)
629 {
630         u32 mngsem;
631         u32 swmask = mask;
632
633         DEBUGFUNC("ngbe_release_swfw_sync");
634
635         ngbe_get_eeprom_semaphore(hw);
636
637         mngsem = rd32(hw, NGBE_MNGSEM);
638         mngsem &= ~swmask;
639         wr32(hw, NGBE_MNGSEM, mngsem);
640
641         ngbe_release_eeprom_semaphore(hw);
642 }
643
644 /**
645  *  ngbe_disable_sec_rx_path - Stops the receive data path
646  *  @hw: pointer to hardware structure
647  *
648  *  Stops the receive data path and waits for the HW to internally empty
649  *  the Rx security block
650  **/
651 s32 ngbe_disable_sec_rx_path(struct ngbe_hw *hw)
652 {
653 #define NGBE_MAX_SECRX_POLL 4000
654
655         int i;
656         u32 secrxreg;
657
658         DEBUGFUNC("ngbe_disable_sec_rx_path");
659
660
661         secrxreg = rd32(hw, NGBE_SECRXCTL);
662         secrxreg |= NGBE_SECRXCTL_XDSA;
663         wr32(hw, NGBE_SECRXCTL, secrxreg);
664         for (i = 0; i < NGBE_MAX_SECRX_POLL; i++) {
665                 secrxreg = rd32(hw, NGBE_SECRXSTAT);
666                 if (!(secrxreg & NGBE_SECRXSTAT_RDY))
667                         /* Use interrupt-safe sleep just in case */
668                         usec_delay(10);
669                 else
670                         break;
671         }
672
673         /* For informational purposes only */
674         if (i >= NGBE_MAX_SECRX_POLL)
675                 DEBUGOUT("Rx unit being enabled before security "
676                          "path fully disabled.  Continuing with init.\n");
677
678         return 0;
679 }
680
681 /**
682  *  ngbe_enable_sec_rx_path - Enables the receive data path
683  *  @hw: pointer to hardware structure
684  *
685  *  Enables the receive data path.
686  **/
687 s32 ngbe_enable_sec_rx_path(struct ngbe_hw *hw)
688 {
689         u32 secrxreg;
690
691         DEBUGFUNC("ngbe_enable_sec_rx_path");
692
693         secrxreg = rd32(hw, NGBE_SECRXCTL);
694         secrxreg &= ~NGBE_SECRXCTL_XDSA;
695         wr32(hw, NGBE_SECRXCTL, secrxreg);
696         ngbe_flush(hw);
697
698         return 0;
699 }
700
701 /**
702  *  ngbe_clear_vmdq - Disassociate a VMDq pool index from a rx address
703  *  @hw: pointer to hardware struct
704  *  @rar: receive address register index to disassociate
705  *  @vmdq: VMDq pool index to remove from the rar
706  **/
707 s32 ngbe_clear_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
708 {
709         u32 mpsar;
710         u32 rar_entries = hw->mac.num_rar_entries;
711
712         DEBUGFUNC("ngbe_clear_vmdq");
713
714         /* Make sure we are using a valid rar index range */
715         if (rar >= rar_entries) {
716                 DEBUGOUT("RAR index %d is out of range.\n", rar);
717                 return NGBE_ERR_INVALID_ARGUMENT;
718         }
719
720         wr32(hw, NGBE_ETHADDRIDX, rar);
721         mpsar = rd32(hw, NGBE_ETHADDRASS);
722
723         if (NGBE_REMOVED(hw->hw_addr))
724                 goto done;
725
726         if (!mpsar)
727                 goto done;
728
729         mpsar &= ~(1 << vmdq);
730         wr32(hw, NGBE_ETHADDRASS, mpsar);
731
732         /* was that the last pool using this rar? */
733         if (mpsar == 0 && rar != 0)
734                 hw->mac.clear_rar(hw, rar);
735 done:
736         return 0;
737 }
738
739 /**
740  *  ngbe_set_vmdq - Associate a VMDq pool index with a rx address
741  *  @hw: pointer to hardware struct
742  *  @rar: receive address register index to associate with a VMDq index
743  *  @vmdq: VMDq pool index
744  **/
745 s32 ngbe_set_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
746 {
747         u32 mpsar;
748         u32 rar_entries = hw->mac.num_rar_entries;
749
750         DEBUGFUNC("ngbe_set_vmdq");
751
752         /* Make sure we are using a valid rar index range */
753         if (rar >= rar_entries) {
754                 DEBUGOUT("RAR index %d is out of range.\n", rar);
755                 return NGBE_ERR_INVALID_ARGUMENT;
756         }
757
758         wr32(hw, NGBE_ETHADDRIDX, rar);
759
760         mpsar = rd32(hw, NGBE_ETHADDRASS);
761         mpsar |= 1 << vmdq;
762         wr32(hw, NGBE_ETHADDRASS, mpsar);
763
764         return 0;
765 }
766
767 /**
768  *  ngbe_init_uta_tables - Initialize the Unicast Table Array
769  *  @hw: pointer to hardware structure
770  **/
771 s32 ngbe_init_uta_tables(struct ngbe_hw *hw)
772 {
773         int i;
774
775         DEBUGFUNC("ngbe_init_uta_tables");
776         DEBUGOUT(" Clearing UTA\n");
777
778         for (i = 0; i < 128; i++)
779                 wr32(hw, NGBE_UCADDRTBL(i), 0);
780
781         return 0;
782 }
783
784 /**
785  *  ngbe_clear_vfta - Clear VLAN filter table
786  *  @hw: pointer to hardware structure
787  *
788  *  Clears the VLAN filer table, and the VMDq index associated with the filter
789  **/
790 s32 ngbe_clear_vfta(struct ngbe_hw *hw)
791 {
792         u32 offset;
793
794         DEBUGFUNC("ngbe_clear_vfta");
795
796         for (offset = 0; offset < hw->mac.vft_size; offset++)
797                 wr32(hw, NGBE_VLANTBL(offset), 0);
798
799         for (offset = 0; offset < NGBE_NUM_POOL; offset++) {
800                 wr32(hw, NGBE_PSRVLANIDX, offset);
801                 wr32(hw, NGBE_PSRVLAN, 0);
802                 wr32(hw, NGBE_PSRVLANPLM(0), 0);
803         }
804
805         return 0;
806 }
807
808 /**
809  *  ngbe_check_mac_link_em - Determine link and speed status
810  *  @hw: pointer to hardware structure
811  *  @speed: pointer to link speed
812  *  @link_up: true when link is up
813  *  @link_up_wait_to_complete: bool used to wait for link up or not
814  *
815  *  Reads the links register to determine if link is up and the current speed
816  **/
817 s32 ngbe_check_mac_link_em(struct ngbe_hw *hw, u32 *speed,
818                         bool *link_up, bool link_up_wait_to_complete)
819 {
820         u32 i, reg;
821         s32 status = 0;
822
823         DEBUGFUNC("ngbe_check_mac_link_em");
824
825         reg = rd32(hw, NGBE_GPIOINTSTAT);
826         wr32(hw, NGBE_GPIOEOI, reg);
827
828         if (link_up_wait_to_complete) {
829                 for (i = 0; i < hw->mac.max_link_up_time; i++) {
830                         status = hw->phy.check_link(hw, speed, link_up);
831                         if (*link_up)
832                                 break;
833                         msec_delay(100);
834                 }
835         } else {
836                 status = hw->phy.check_link(hw, speed, link_up);
837         }
838
839         return status;
840 }
841
842 s32 ngbe_get_link_capabilities_em(struct ngbe_hw *hw,
843                                       u32 *speed,
844                                       bool *autoneg)
845 {
846         s32 status = 0;
847
848         DEBUGFUNC("\n");
849
850         hw->mac.autoneg = *autoneg;
851
852         switch (hw->sub_device_id) {
853         case NGBE_SUB_DEV_ID_EM_RTL_SGMII:
854                 *speed = NGBE_LINK_SPEED_1GB_FULL |
855                         NGBE_LINK_SPEED_100M_FULL |
856                         NGBE_LINK_SPEED_10M_FULL;
857                 break;
858         default:
859                 break;
860         }
861
862         return status;
863 }
864
865 s32 ngbe_setup_mac_link_em(struct ngbe_hw *hw,
866                                u32 speed,
867                                bool autoneg_wait_to_complete)
868 {
869         s32 status;
870
871         DEBUGFUNC("\n");
872
873         /* Setup the PHY according to input speed */
874         status = hw->phy.setup_link(hw, speed, autoneg_wait_to_complete);
875
876         return status;
877 }
878
879 /**
880  *  ngbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
881  *  @hw: pointer to hardware structure
882  *
883  *  Inits the thermal sensor thresholds according to the NVM map
884  *  and save off the threshold and location values into mac.thermal_sensor_data
885  **/
886 s32 ngbe_init_thermal_sensor_thresh(struct ngbe_hw *hw)
887 {
888         struct ngbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
889
890         DEBUGFUNC("ngbe_init_thermal_sensor_thresh");
891
892         memset(data, 0, sizeof(struct ngbe_thermal_sensor_data));
893
894         if (hw->bus.lan_id != 0)
895                 return NGBE_NOT_IMPLEMENTED;
896
897         wr32(hw, NGBE_TSINTR,
898                 NGBE_TSINTR_AEN | NGBE_TSINTR_DEN);
899         wr32(hw, NGBE_TSEN, NGBE_TSEN_ENA);
900
901
902         data->sensor[0].alarm_thresh = 115;
903         wr32(hw, NGBE_TSATHRE, 0x344);
904         data->sensor[0].dalarm_thresh = 110;
905         wr32(hw, NGBE_TSDTHRE, 0x330);
906
907         return 0;
908 }
909
910 s32 ngbe_mac_check_overtemp(struct ngbe_hw *hw)
911 {
912         s32 status = 0;
913         u32 ts_state;
914
915         DEBUGFUNC("ngbe_mac_check_overtemp");
916
917         /* Check that the LASI temp alarm status was triggered */
918         ts_state = rd32(hw, NGBE_TSALM);
919
920         if (ts_state & NGBE_TSALM_HI)
921                 status = NGBE_ERR_UNDERTEMP;
922         else if (ts_state & NGBE_TSALM_LO)
923                 status = NGBE_ERR_OVERTEMP;
924
925         return status;
926 }
927
928 void ngbe_disable_rx(struct ngbe_hw *hw)
929 {
930         u32 pfdtxgswc;
931
932         pfdtxgswc = rd32(hw, NGBE_PSRCTL);
933         if (pfdtxgswc & NGBE_PSRCTL_LBENA) {
934                 pfdtxgswc &= ~NGBE_PSRCTL_LBENA;
935                 wr32(hw, NGBE_PSRCTL, pfdtxgswc);
936                 hw->mac.set_lben = true;
937         } else {
938                 hw->mac.set_lben = false;
939         }
940
941         wr32m(hw, NGBE_PBRXCTL, NGBE_PBRXCTL_ENA, 0);
942         wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_ENA, 0);
943 }
944
945 void ngbe_enable_rx(struct ngbe_hw *hw)
946 {
947         u32 pfdtxgswc;
948
949         wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_ENA, NGBE_MACRXCFG_ENA);
950         wr32m(hw, NGBE_PBRXCTL, NGBE_PBRXCTL_ENA, NGBE_PBRXCTL_ENA);
951
952         if (hw->mac.set_lben) {
953                 pfdtxgswc = rd32(hw, NGBE_PSRCTL);
954                 pfdtxgswc |= NGBE_PSRCTL_LBENA;
955                 wr32(hw, NGBE_PSRCTL, pfdtxgswc);
956                 hw->mac.set_lben = false;
957         }
958 }
959
960 /**
961  *  ngbe_set_mac_type - Sets MAC type
962  *  @hw: pointer to the HW structure
963  *
964  *  This function sets the mac type of the adapter based on the
965  *  vendor ID and device ID stored in the hw structure.
966  **/
967 s32 ngbe_set_mac_type(struct ngbe_hw *hw)
968 {
969         s32 err = 0;
970
971         DEBUGFUNC("ngbe_set_mac_type");
972
973         if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
974                 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
975                 return NGBE_ERR_DEVICE_NOT_SUPPORTED;
976         }
977
978         switch (hw->sub_device_id) {
979         case NGBE_SUB_DEV_ID_EM_RTL_SGMII:
980         case NGBE_SUB_DEV_ID_EM_MVL_RGMII:
981                 hw->phy.media_type = ngbe_media_type_copper;
982                 hw->mac.type = ngbe_mac_em;
983                 break;
984         case NGBE_SUB_DEV_ID_EM_MVL_SFP:
985         case NGBE_SUB_DEV_ID_EM_YT8521S_SFP:
986                 hw->phy.media_type = ngbe_media_type_fiber;
987                 hw->mac.type = ngbe_mac_em;
988                 break;
989         case NGBE_SUB_DEV_ID_EM_VF:
990                 hw->phy.media_type = ngbe_media_type_virtual;
991                 hw->mac.type = ngbe_mac_em_vf;
992                 break;
993         default:
994                 err = NGBE_ERR_DEVICE_NOT_SUPPORTED;
995                 hw->phy.media_type = ngbe_media_type_unknown;
996                 hw->mac.type = ngbe_mac_unknown;
997                 DEBUGOUT("Unsupported device id: %x", hw->device_id);
998                 break;
999         }
1000
1001         DEBUGOUT("found mac: %d media: %d, returns: %d\n",
1002                   hw->mac.type, hw->phy.media_type, err);
1003         return err;
1004 }
1005
1006 /**
1007  *  ngbe_enable_rx_dma - Enable the Rx DMA unit
1008  *  @hw: pointer to hardware structure
1009  *  @regval: register value to write to RXCTRL
1010  *
1011  *  Enables the Rx DMA unit
1012  **/
1013 s32 ngbe_enable_rx_dma(struct ngbe_hw *hw, u32 regval)
1014 {
1015         DEBUGFUNC("ngbe_enable_rx_dma");
1016
1017         /*
1018          * Workaround silicon errata when enabling the Rx datapath.
1019          * If traffic is incoming before we enable the Rx unit, it could hang
1020          * the Rx DMA unit.  Therefore, make sure the security engine is
1021          * completely disabled prior to enabling the Rx unit.
1022          */
1023
1024         hw->mac.disable_sec_rx_path(hw);
1025
1026         if (regval & NGBE_PBRXCTL_ENA)
1027                 ngbe_enable_rx(hw);
1028         else
1029                 ngbe_disable_rx(hw);
1030
1031         hw->mac.enable_sec_rx_path(hw);
1032
1033         return 0;
1034 }
1035
1036 void ngbe_map_device_id(struct ngbe_hw *hw)
1037 {
1038         u16 oem = hw->sub_system_id & NGBE_OEM_MASK;
1039         u16 internal = hw->sub_system_id & NGBE_INTERNAL_MASK;
1040         hw->is_pf = true;
1041
1042         /* move subsystem_device_id to device_id */
1043         switch (hw->device_id) {
1044         case NGBE_DEV_ID_EM_WX1860AL_W_VF:
1045         case NGBE_DEV_ID_EM_WX1860A2_VF:
1046         case NGBE_DEV_ID_EM_WX1860A2S_VF:
1047         case NGBE_DEV_ID_EM_WX1860A4_VF:
1048         case NGBE_DEV_ID_EM_WX1860A4S_VF:
1049         case NGBE_DEV_ID_EM_WX1860AL2_VF:
1050         case NGBE_DEV_ID_EM_WX1860AL2S_VF:
1051         case NGBE_DEV_ID_EM_WX1860AL4_VF:
1052         case NGBE_DEV_ID_EM_WX1860AL4S_VF:
1053         case NGBE_DEV_ID_EM_WX1860NCSI_VF:
1054         case NGBE_DEV_ID_EM_WX1860A1_VF:
1055         case NGBE_DEV_ID_EM_WX1860A1L_VF:
1056                 hw->device_id = NGBE_DEV_ID_EM_VF;
1057                 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_VF;
1058                 hw->is_pf = false;
1059                 break;
1060         case NGBE_DEV_ID_EM_WX1860AL_W:
1061         case NGBE_DEV_ID_EM_WX1860A2:
1062         case NGBE_DEV_ID_EM_WX1860A2S:
1063         case NGBE_DEV_ID_EM_WX1860A4:
1064         case NGBE_DEV_ID_EM_WX1860A4S:
1065         case NGBE_DEV_ID_EM_WX1860AL2:
1066         case NGBE_DEV_ID_EM_WX1860AL2S:
1067         case NGBE_DEV_ID_EM_WX1860AL4:
1068         case NGBE_DEV_ID_EM_WX1860AL4S:
1069         case NGBE_DEV_ID_EM_WX1860NCSI:
1070         case NGBE_DEV_ID_EM_WX1860A1:
1071         case NGBE_DEV_ID_EM_WX1860A1L:
1072                 hw->device_id = NGBE_DEV_ID_EM;
1073                 if (oem == NGBE_LY_M88E1512_SFP ||
1074                                 internal == NGBE_INTERNAL_SFP)
1075                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_SFP;
1076                 else if (hw->sub_system_id == NGBE_SUB_DEV_ID_EM_M88E1512_RJ45)
1077                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_RGMII;
1078                 else if (oem == NGBE_YT8521S_SFP ||
1079                                 oem == NGBE_LY_YT8521S_SFP)
1080                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_YT8521S_SFP;
1081                 else
1082                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_SGMII;
1083                 break;
1084         default:
1085                 break;
1086         }
1087 }
1088
1089 /**
1090  *  ngbe_init_ops_pf - Inits func ptrs and MAC type
1091  *  @hw: pointer to hardware structure
1092  *
1093  *  Initialize the function pointers and assign the MAC type.
1094  *  Does not touch the hardware.
1095  **/
1096 s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
1097 {
1098         struct ngbe_bus_info *bus = &hw->bus;
1099         struct ngbe_mac_info *mac = &hw->mac;
1100         struct ngbe_phy_info *phy = &hw->phy;
1101         struct ngbe_rom_info *rom = &hw->rom;
1102
1103         DEBUGFUNC("ngbe_init_ops_pf");
1104
1105         /* BUS */
1106         bus->set_lan_id = ngbe_set_lan_id_multi_port;
1107
1108         /* PHY */
1109         phy->identify = ngbe_identify_phy;
1110         phy->read_reg = ngbe_read_phy_reg;
1111         phy->write_reg = ngbe_write_phy_reg;
1112         phy->read_reg_unlocked = ngbe_read_phy_reg_mdi;
1113         phy->write_reg_unlocked = ngbe_write_phy_reg_mdi;
1114         phy->reset_hw = ngbe_reset_phy;
1115
1116         /* MAC */
1117         mac->init_hw = ngbe_init_hw;
1118         mac->reset_hw = ngbe_reset_hw_em;
1119         mac->start_hw = ngbe_start_hw;
1120         mac->clear_hw_cntrs = ngbe_clear_hw_cntrs;
1121         mac->enable_rx_dma = ngbe_enable_rx_dma;
1122         mac->get_mac_addr = ngbe_get_mac_addr;
1123         mac->stop_hw = ngbe_stop_hw;
1124         mac->acquire_swfw_sync = ngbe_acquire_swfw_sync;
1125         mac->release_swfw_sync = ngbe_release_swfw_sync;
1126
1127         mac->disable_sec_rx_path = ngbe_disable_sec_rx_path;
1128         mac->enable_sec_rx_path = ngbe_enable_sec_rx_path;
1129         /* RAR, VLAN */
1130         mac->set_rar = ngbe_set_rar;
1131         mac->clear_rar = ngbe_clear_rar;
1132         mac->init_rx_addrs = ngbe_init_rx_addrs;
1133         mac->set_vmdq = ngbe_set_vmdq;
1134         mac->clear_vmdq = ngbe_clear_vmdq;
1135         mac->clear_vfta = ngbe_clear_vfta;
1136
1137         /* Link */
1138         mac->get_link_capabilities = ngbe_get_link_capabilities_em;
1139         mac->check_link = ngbe_check_mac_link_em;
1140         mac->setup_link = ngbe_setup_mac_link_em;
1141
1142         /* Manageability interface */
1143         mac->init_thermal_sensor_thresh = ngbe_init_thermal_sensor_thresh;
1144         mac->check_overtemp = ngbe_mac_check_overtemp;
1145
1146         /* EEPROM */
1147         rom->init_params = ngbe_init_eeprom_params;
1148         rom->read32 = ngbe_ee_read32;
1149         rom->validate_checksum = ngbe_validate_eeprom_checksum_em;
1150
1151         mac->mcft_size          = NGBE_EM_MC_TBL_SIZE;
1152         mac->vft_size           = NGBE_EM_VFT_TBL_SIZE;
1153         mac->num_rar_entries    = NGBE_EM_RAR_ENTRIES;
1154         mac->max_rx_queues      = NGBE_EM_MAX_RX_QUEUES;
1155         mac->max_tx_queues      = NGBE_EM_MAX_TX_QUEUES;
1156
1157         mac->default_speeds = NGBE_LINK_SPEED_10M_FULL |
1158                                 NGBE_LINK_SPEED_100M_FULL |
1159                                 NGBE_LINK_SPEED_1GB_FULL;
1160
1161         return 0;
1162 }
1163
1164 /**
1165  *  ngbe_init_shared_code - Initialize the shared code
1166  *  @hw: pointer to hardware structure
1167  *
1168  *  This will assign function pointers and assign the MAC type and PHY code.
1169  *  Does not touch the hardware. This function must be called prior to any
1170  *  other function in the shared code. The ngbe_hw structure should be
1171  *  memset to 0 prior to calling this function.  The following fields in
1172  *  hw structure should be filled in prior to calling this function:
1173  *  hw_addr, back, device_id, vendor_id, subsystem_device_id
1174  **/
1175 s32 ngbe_init_shared_code(struct ngbe_hw *hw)
1176 {
1177         s32 status = 0;
1178
1179         DEBUGFUNC("ngbe_init_shared_code");
1180
1181         /*
1182          * Set the mac type
1183          */
1184         ngbe_set_mac_type(hw);
1185
1186         ngbe_init_ops_dummy(hw);
1187         switch (hw->mac.type) {
1188         case ngbe_mac_em:
1189                 ngbe_init_ops_pf(hw);
1190                 break;
1191         default:
1192                 status = NGBE_ERR_DEVICE_NOT_SUPPORTED;
1193                 break;
1194         }
1195         hw->mac.max_link_up_time = NGBE_LINK_UP_TIME;
1196
1197         hw->bus.set_lan_id(hw);
1198
1199         return status;
1200 }
1201