afd7172a9cc855a02ac56d43ed29137a7fc1441e
[dpdk.git] / drivers / net / txgbe / base / txgbe_hw.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020
3  */
4
5 #include "txgbe_type.h"
6 #include "txgbe_phy.h"
7 #include "txgbe_eeprom.h"
8 #include "txgbe_mng.h"
9 #include "txgbe_hw.h"
10
11 #define TXGBE_RAPTOR_MAX_TX_QUEUES 128
12 #define TXGBE_RAPTOR_MAX_RX_QUEUES 128
13 #define TXGBE_RAPTOR_RAR_ENTRIES   128
14 #define TXGBE_RAPTOR_MC_TBL_SIZE   128
15
16 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
17                                          u32 speed,
18                                          bool autoneg_wait_to_complete);
19
20 static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr);
21 static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
22                                          u16 *san_mac_offset);
23
24 /**
25  *  txgbe_start_hw - Prepare hardware for Tx/Rx
26  *  @hw: pointer to hardware structure
27  *
28  *  Starts the hardware by filling the bus info structure and media type, clears
29  *  all on chip counters, initializes receive address registers, multicast
30  *  table, VLAN filter table, calls routine to set up link and flow control
31  *  settings, and leaves transmit and receive units disabled and uninitialized
32  **/
33 s32 txgbe_start_hw(struct txgbe_hw *hw)
34 {
35         u16 device_caps;
36
37         DEBUGFUNC("txgbe_start_hw");
38
39         /* Set the media type */
40         hw->phy.media_type = hw->phy.get_media_type(hw);
41
42         /* Clear statistics registers */
43         hw->mac.clear_hw_cntrs(hw);
44
45         /* Cache bit indicating need for crosstalk fix */
46         switch (hw->mac.type) {
47         case txgbe_mac_raptor:
48                 hw->mac.get_device_caps(hw, &device_caps);
49                 if (device_caps & TXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
50                         hw->need_crosstalk_fix = false;
51                 else
52                         hw->need_crosstalk_fix = true;
53                 break;
54         default:
55                 hw->need_crosstalk_fix = false;
56                 break;
57         }
58
59         /* Clear adapter stopped flag */
60         hw->adapter_stopped = false;
61
62         return 0;
63 }
64
65 /**
66  *  txgbe_start_hw_gen2 - Init sequence for common device family
67  *  @hw: pointer to hw structure
68  *
69  * Performs the init sequence common to the second generation
70  * of 10 GbE devices.
71  **/
72 s32 txgbe_start_hw_gen2(struct txgbe_hw *hw)
73 {
74         u32 i;
75
76         /* Clear the rate limiters */
77         for (i = 0; i < hw->mac.max_tx_queues; i++) {
78                 wr32(hw, TXGBE_ARBPOOLIDX, i);
79                 wr32(hw, TXGBE_ARBTXRATE, 0);
80         }
81         txgbe_flush(hw);
82
83         /* We need to run link autotry after the driver loads */
84         hw->mac.autotry_restart = true;
85
86         return 0;
87 }
88
89 /**
90  *  txgbe_init_hw - Generic hardware initialization
91  *  @hw: pointer to hardware structure
92  *
93  *  Initialize the hardware by resetting the hardware, filling the bus info
94  *  structure and media type, clears all on chip counters, initializes receive
95  *  address registers, multicast table, VLAN filter table, calls routine to set
96  *  up link and flow control settings, and leaves transmit and receive units
97  *  disabled and uninitialized
98  **/
99 s32 txgbe_init_hw(struct txgbe_hw *hw)
100 {
101         s32 status;
102
103         DEBUGFUNC("txgbe_init_hw");
104
105         /* Reset the hardware */
106         status = hw->mac.reset_hw(hw);
107         if (status == 0 || status == TXGBE_ERR_SFP_NOT_PRESENT) {
108                 /* Start the HW */
109                 status = hw->mac.start_hw(hw);
110         }
111
112         if (status != 0)
113                 DEBUGOUT("Failed to initialize HW, STATUS = %d\n", status);
114
115         return status;
116 }
117
118 /**
119  *  txgbe_get_mac_addr - Generic get MAC address
120  *  @hw: pointer to hardware structure
121  *  @mac_addr: Adapter MAC address
122  *
123  *  Reads the adapter's MAC address from first Receive Address Register (RAR0)
124  *  A reset of the adapter must be performed prior to calling this function
125  *  in order for the MAC address to have been loaded from the EEPROM into RAR0
126  **/
127 s32 txgbe_get_mac_addr(struct txgbe_hw *hw, u8 *mac_addr)
128 {
129         u32 rar_high;
130         u32 rar_low;
131         u16 i;
132
133         DEBUGFUNC("txgbe_get_mac_addr");
134
135         wr32(hw, TXGBE_ETHADDRIDX, 0);
136         rar_high = rd32(hw, TXGBE_ETHADDRH);
137         rar_low = rd32(hw, TXGBE_ETHADDRL);
138
139         for (i = 0; i < 2; i++)
140                 mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
141
142         for (i = 0; i < 4; i++)
143                 mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
144
145         return 0;
146 }
147
148 /**
149  *  txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
150  *  @hw: pointer to the HW structure
151  *
152  *  Determines the LAN function id by reading memory-mapped registers and swaps
153  *  the port value if requested, and set MAC instance for devices.
154  **/
155 void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
156 {
157         struct txgbe_bus_info *bus = &hw->bus;
158         u32 reg;
159
160         DEBUGFUNC("txgbe_set_lan_id_multi_port_pcie");
161
162         reg = rd32(hw, TXGBE_PORTSTAT);
163         bus->lan_id = TXGBE_PORTSTAT_ID(reg);
164
165         /* check for single port */
166         reg = rd32(hw, TXGBE_PWR);
167         if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
168                 bus->func = 0;
169         else
170                 bus->func = bus->lan_id;
171 }
172
173 /**
174  *  txgbe_stop_hw - Generic stop Tx/Rx units
175  *  @hw: pointer to hardware structure
176  *
177  *  Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
178  *  disables transmit and receive units. The adapter_stopped flag is used by
179  *  the shared code and drivers to determine if the adapter is in a stopped
180  *  state and should not touch the hardware.
181  **/
182 s32 txgbe_stop_hw(struct txgbe_hw *hw)
183 {
184         u32 reg_val;
185         u16 i;
186
187         DEBUGFUNC("txgbe_stop_hw");
188
189         /*
190          * Set the adapter_stopped flag so other driver functions stop touching
191          * the hardware
192          */
193         hw->adapter_stopped = true;
194
195         /* Disable the receive unit */
196         txgbe_disable_rx(hw);
197
198         /* Clear interrupt mask to stop interrupts from being generated */
199         wr32(hw, TXGBE_IENMISC, 0);
200         wr32(hw, TXGBE_IMS(0), TXGBE_IMS_MASK);
201         wr32(hw, TXGBE_IMS(1), TXGBE_IMS_MASK);
202
203         /* Clear any pending interrupts, flush previous writes */
204         wr32(hw, TXGBE_ICRMISC, TXGBE_ICRMISC_MASK);
205         wr32(hw, TXGBE_ICR(0), TXGBE_ICR_MASK);
206         wr32(hw, TXGBE_ICR(1), TXGBE_ICR_MASK);
207
208         /* Disable the transmit unit.  Each queue must be disabled. */
209         for (i = 0; i < hw->mac.max_tx_queues; i++)
210                 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
211
212         /* Disable the receive unit by stopping each queue */
213         for (i = 0; i < hw->mac.max_rx_queues; i++) {
214                 reg_val = rd32(hw, TXGBE_RXCFG(i));
215                 reg_val &= ~TXGBE_RXCFG_ENA;
216                 wr32(hw, TXGBE_RXCFG(i), reg_val);
217         }
218
219         /* flush all queues disables */
220         txgbe_flush(hw);
221         msec_delay(2);
222
223         return 0;
224 }
225
226 /**
227  *  txgbe_validate_mac_addr - Validate MAC address
228  *  @mac_addr: pointer to MAC address.
229  *
230  *  Tests a MAC address to ensure it is a valid Individual Address.
231  **/
232 s32 txgbe_validate_mac_addr(u8 *mac_addr)
233 {
234         s32 status = 0;
235
236         DEBUGFUNC("txgbe_validate_mac_addr");
237
238         /* Make sure it is not a multicast address */
239         if (TXGBE_IS_MULTICAST(mac_addr)) {
240                 status = TXGBE_ERR_INVALID_MAC_ADDR;
241         /* Not a broadcast address */
242         } else if (TXGBE_IS_BROADCAST(mac_addr)) {
243                 status = TXGBE_ERR_INVALID_MAC_ADDR;
244         /* Reject the zero address */
245         } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
246                    mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
247                 status = TXGBE_ERR_INVALID_MAC_ADDR;
248         }
249         return status;
250 }
251
252 /**
253  *  txgbe_set_rar - Set Rx address register
254  *  @hw: pointer to hardware structure
255  *  @index: Receive address register to write
256  *  @addr: Address to put into receive address register
257  *  @vmdq: VMDq "set" or "pool" index
258  *  @enable_addr: set flag that address is active
259  *
260  *  Puts an ethernet address into a receive address register.
261  **/
262 s32 txgbe_set_rar(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
263                           u32 enable_addr)
264 {
265         u32 rar_low, rar_high;
266         u32 rar_entries = hw->mac.num_rar_entries;
267
268         DEBUGFUNC("txgbe_set_rar");
269
270         /* Make sure we are using a valid rar index range */
271         if (index >= rar_entries) {
272                 DEBUGOUT("RAR index %d is out of range.\n", index);
273                 return TXGBE_ERR_INVALID_ARGUMENT;
274         }
275
276         /* setup VMDq pool selection before this RAR gets enabled */
277         hw->mac.set_vmdq(hw, index, vmdq);
278
279         /*
280          * HW expects these in little endian so we reverse the byte
281          * order from network order (big endian) to little endian
282          */
283         rar_low = TXGBE_ETHADDRL_AD0(addr[5]) |
284                   TXGBE_ETHADDRL_AD1(addr[4]) |
285                   TXGBE_ETHADDRL_AD2(addr[3]) |
286                   TXGBE_ETHADDRL_AD3(addr[2]);
287         /*
288          * Some parts put the VMDq setting in the extra RAH bits,
289          * so save everything except the lower 16 bits that hold part
290          * of the address and the address valid bit.
291          */
292         rar_high = rd32(hw, TXGBE_ETHADDRH);
293         rar_high &= ~TXGBE_ETHADDRH_AD_MASK;
294         rar_high |= (TXGBE_ETHADDRH_AD4(addr[1]) |
295                      TXGBE_ETHADDRH_AD5(addr[0]));
296
297         rar_high &= ~TXGBE_ETHADDRH_VLD;
298         if (enable_addr != 0)
299                 rar_high |= TXGBE_ETHADDRH_VLD;
300
301         wr32(hw, TXGBE_ETHADDRIDX, index);
302         wr32(hw, TXGBE_ETHADDRL, rar_low);
303         wr32(hw, TXGBE_ETHADDRH, rar_high);
304
305         return 0;
306 }
307
308 /**
309  *  txgbe_clear_rar - Remove Rx address register
310  *  @hw: pointer to hardware structure
311  *  @index: Receive address register to write
312  *
313  *  Clears an ethernet address from a receive address register.
314  **/
315 s32 txgbe_clear_rar(struct txgbe_hw *hw, u32 index)
316 {
317         u32 rar_high;
318         u32 rar_entries = hw->mac.num_rar_entries;
319
320         DEBUGFUNC("txgbe_clear_rar");
321
322         /* Make sure we are using a valid rar index range */
323         if (index >= rar_entries) {
324                 DEBUGOUT("RAR index %d is out of range.\n", index);
325                 return TXGBE_ERR_INVALID_ARGUMENT;
326         }
327
328         /*
329          * Some parts put the VMDq setting in the extra RAH bits,
330          * so save everything except the lower 16 bits that hold part
331          * of the address and the address valid bit.
332          */
333         wr32(hw, TXGBE_ETHADDRIDX, index);
334         rar_high = rd32(hw, TXGBE_ETHADDRH);
335         rar_high &= ~(TXGBE_ETHADDRH_AD_MASK | TXGBE_ETHADDRH_VLD);
336
337         wr32(hw, TXGBE_ETHADDRL, 0);
338         wr32(hw, TXGBE_ETHADDRH, rar_high);
339
340         /* clear VMDq pool/queue selection for this RAR */
341         hw->mac.clear_vmdq(hw, index, BIT_MASK32);
342
343         return 0;
344 }
345
346 /**
347  *  txgbe_init_rx_addrs - Initializes receive address filters.
348  *  @hw: pointer to hardware structure
349  *
350  *  Places the MAC address in receive address register 0 and clears the rest
351  *  of the receive address registers. Clears the multicast table. Assumes
352  *  the receiver is in reset when the routine is called.
353  **/
354 s32 txgbe_init_rx_addrs(struct txgbe_hw *hw)
355 {
356         u32 i;
357         u32 psrctl;
358         u32 rar_entries = hw->mac.num_rar_entries;
359
360         DEBUGFUNC("txgbe_init_rx_addrs");
361
362         /*
363          * If the current mac address is valid, assume it is a software override
364          * to the permanent address.
365          * Otherwise, use the permanent address from the eeprom.
366          */
367         if (txgbe_validate_mac_addr(hw->mac.addr) ==
368             TXGBE_ERR_INVALID_MAC_ADDR) {
369                 /* Get the MAC address from the RAR0 for later reference */
370                 hw->mac.get_mac_addr(hw, hw->mac.addr);
371
372                 DEBUGOUT(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
373                           hw->mac.addr[0], hw->mac.addr[1],
374                           hw->mac.addr[2]);
375                 DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
376                           hw->mac.addr[4], hw->mac.addr[5]);
377         } else {
378                 /* Setup the receive address. */
379                 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
380                 DEBUGOUT(" New MAC Addr =%.2X %.2X %.2X ",
381                           hw->mac.addr[0], hw->mac.addr[1],
382                           hw->mac.addr[2]);
383                 DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
384                           hw->mac.addr[4], hw->mac.addr[5]);
385
386                 hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
387         }
388
389         /* clear VMDq pool/queue selection for RAR 0 */
390         hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
391
392         hw->addr_ctrl.overflow_promisc = 0;
393
394         hw->addr_ctrl.rar_used_count = 1;
395
396         /* Zero out the other receive addresses. */
397         DEBUGOUT("Clearing RAR[1-%d]\n", rar_entries - 1);
398         for (i = 1; i < rar_entries; i++) {
399                 wr32(hw, TXGBE_ETHADDRIDX, i);
400                 wr32(hw, TXGBE_ETHADDRL, 0);
401                 wr32(hw, TXGBE_ETHADDRH, 0);
402         }
403
404         /* Clear the MTA */
405         hw->addr_ctrl.mta_in_use = 0;
406         psrctl = rd32(hw, TXGBE_PSRCTL);
407         psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
408         psrctl |= TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
409         wr32(hw, TXGBE_PSRCTL, psrctl);
410
411         DEBUGOUT(" Clearing MTA\n");
412         for (i = 0; i < hw->mac.mcft_size; i++)
413                 wr32(hw, TXGBE_MCADDRTBL(i), 0);
414
415         txgbe_init_uta_tables(hw);
416
417         return 0;
418 }
419
420 /**
421  *  txgbe_mta_vector - Determines bit-vector in multicast table to set
422  *  @hw: pointer to hardware structure
423  *  @mc_addr: the multicast address
424  *
425  *  Extracts the 12 bits, from a multicast address, to determine which
426  *  bit-vector to set in the multicast table. The hardware uses 12 bits, from
427  *  incoming rx multicast addresses, to determine the bit-vector to check in
428  *  the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
429  *  by the MO field of the PSRCTRL. The MO field is set during initialization
430  *  to mc_filter_type.
431  **/
432 static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
433 {
434         u32 vector = 0;
435
436         DEBUGFUNC("txgbe_mta_vector");
437
438         switch (hw->mac.mc_filter_type) {
439         case 0:   /* use bits [47:36] of the address */
440                 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
441                 break;
442         case 1:   /* use bits [46:35] of the address */
443                 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
444                 break;
445         case 2:   /* use bits [45:34] of the address */
446                 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
447                 break;
448         case 3:   /* use bits [43:32] of the address */
449                 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
450                 break;
451         default:  /* Invalid mc_filter_type */
452                 DEBUGOUT("MC filter type param set incorrectly\n");
453                 ASSERT(0);
454                 break;
455         }
456
457         /* vector can only be 12-bits or boundary will be exceeded */
458         vector &= 0xFFF;
459         return vector;
460 }
461
462 /**
463  *  txgbe_set_mta - Set bit-vector in multicast table
464  *  @hw: pointer to hardware structure
465  *  @mc_addr: Multicast address
466  *
467  *  Sets the bit-vector in the multicast table.
468  **/
469 void txgbe_set_mta(struct txgbe_hw *hw, u8 *mc_addr)
470 {
471         u32 vector;
472         u32 vector_bit;
473         u32 vector_reg;
474
475         DEBUGFUNC("txgbe_set_mta");
476
477         hw->addr_ctrl.mta_in_use++;
478
479         vector = txgbe_mta_vector(hw, mc_addr);
480         DEBUGOUT(" bit-vector = 0x%03X\n", vector);
481
482         /*
483          * The MTA is a register array of 128 32-bit registers. It is treated
484          * like an array of 4096 bits.  We want to set bit
485          * BitArray[vector_value]. So we figure out what register the bit is
486          * in, read it, OR in the new bit, then write back the new value.  The
487          * register is determined by the upper 7 bits of the vector value and
488          * the bit within that register are determined by the lower 5 bits of
489          * the value.
490          */
491         vector_reg = (vector >> 5) & 0x7F;
492         vector_bit = vector & 0x1F;
493         hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
494 }
495
496 /**
497  *  txgbe_update_mc_addr_list - Updates MAC list of multicast addresses
498  *  @hw: pointer to hardware structure
499  *  @mc_addr_list: the list of new multicast addresses
500  *  @mc_addr_count: number of addresses
501  *  @next: iterator function to walk the multicast address list
502  *  @clear: flag, when set clears the table beforehand
503  *
504  *  When the clear flag is set, the given list replaces any existing list.
505  *  Hashes the given addresses into the multicast table.
506  **/
507 s32 txgbe_update_mc_addr_list(struct txgbe_hw *hw, u8 *mc_addr_list,
508                                       u32 mc_addr_count, txgbe_mc_addr_itr next,
509                                       bool clear)
510 {
511         u32 i;
512         u32 vmdq;
513
514         DEBUGFUNC("txgbe_update_mc_addr_list");
515
516         /*
517          * Set the new number of MC addresses that we are being requested to
518          * use.
519          */
520         hw->addr_ctrl.num_mc_addrs = mc_addr_count;
521         hw->addr_ctrl.mta_in_use = 0;
522
523         /* Clear mta_shadow */
524         if (clear) {
525                 DEBUGOUT(" Clearing MTA\n");
526                 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
527         }
528
529         /* Update mta_shadow */
530         for (i = 0; i < mc_addr_count; i++) {
531                 DEBUGOUT(" Adding the multicast addresses:\n");
532                 txgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
533         }
534
535         /* Enable mta */
536         for (i = 0; i < hw->mac.mcft_size; i++)
537                 wr32a(hw, TXGBE_MCADDRTBL(0), i,
538                                       hw->mac.mta_shadow[i]);
539
540         if (hw->addr_ctrl.mta_in_use > 0) {
541                 u32 psrctl = rd32(hw, TXGBE_PSRCTL);
542                 psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
543                 psrctl |= TXGBE_PSRCTL_MCHFENA |
544                          TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
545                 wr32(hw, TXGBE_PSRCTL, psrctl);
546         }
547
548         DEBUGOUT("txgbe update mc addr list complete\n");
549         return 0;
550 }
551
552 /**
553  *  txgbe_disable_sec_rx_path - Stops the receive data path
554  *  @hw: pointer to hardware structure
555  *
556  *  Stops the receive data path and waits for the HW to internally empty
557  *  the Rx security block
558  **/
559 s32 txgbe_disable_sec_rx_path(struct txgbe_hw *hw)
560 {
561 #define TXGBE_MAX_SECRX_POLL 4000
562
563         int i;
564         u32 secrxreg;
565
566         DEBUGFUNC("txgbe_disable_sec_rx_path");
567
568         secrxreg = rd32(hw, TXGBE_SECRXCTL);
569         secrxreg |= TXGBE_SECRXCTL_XDSA;
570         wr32(hw, TXGBE_SECRXCTL, secrxreg);
571         for (i = 0; i < TXGBE_MAX_SECRX_POLL; i++) {
572                 secrxreg = rd32(hw, TXGBE_SECRXSTAT);
573                 if (!(secrxreg & TXGBE_SECRXSTAT_RDY))
574                         /* Use interrupt-safe sleep just in case */
575                         usec_delay(10);
576                 else
577                         break;
578         }
579
580         /* For informational purposes only */
581         if (i >= TXGBE_MAX_SECRX_POLL)
582                 DEBUGOUT("Rx unit being enabled before security "
583                          "path fully disabled.  Continuing with init.\n");
584
585         return 0;
586 }
587
588 /**
589  *  txgbe_enable_sec_rx_path - Enables the receive data path
590  *  @hw: pointer to hardware structure
591  *
592  *  Enables the receive data path.
593  **/
594 s32 txgbe_enable_sec_rx_path(struct txgbe_hw *hw)
595 {
596         u32 secrxreg;
597
598         DEBUGFUNC("txgbe_enable_sec_rx_path");
599
600         secrxreg = rd32(hw, TXGBE_SECRXCTL);
601         secrxreg &= ~TXGBE_SECRXCTL_XDSA;
602         wr32(hw, TXGBE_SECRXCTL, secrxreg);
603         txgbe_flush(hw);
604
605         return 0;
606 }
607
608 /**
609  *  txgbe_disable_sec_tx_path - Stops the transmit data path
610  *  @hw: pointer to hardware structure
611  *
612  *  Stops the transmit data path and waits for the HW to internally empty
613  *  the Tx security block
614  **/
615 int txgbe_disable_sec_tx_path(struct txgbe_hw *hw)
616 {
617 #define TXGBE_MAX_SECTX_POLL 40
618
619         int i;
620         u32 sectxreg;
621
622         sectxreg = rd32(hw, TXGBE_SECTXCTL);
623         sectxreg |= TXGBE_SECTXCTL_XDSA;
624         wr32(hw, TXGBE_SECTXCTL, sectxreg);
625         for (i = 0; i < TXGBE_MAX_SECTX_POLL; i++) {
626                 sectxreg = rd32(hw, TXGBE_SECTXSTAT);
627                 if (sectxreg & TXGBE_SECTXSTAT_RDY)
628                         break;
629                 /* Use interrupt-safe sleep just in case */
630                 usec_delay(1000);
631         }
632
633         /* For informational purposes only */
634         if (i >= TXGBE_MAX_SECTX_POLL)
635                 PMD_DRV_LOG(DEBUG, "Tx unit being enabled before security "
636                          "path fully disabled.  Continuing with init.");
637
638         return 0;
639 }
640
641 /**
642  *  txgbe_enable_sec_tx_path - Enables the transmit data path
643  *  @hw: pointer to hardware structure
644  *
645  *  Enables the transmit data path.
646  **/
647 int txgbe_enable_sec_tx_path(struct txgbe_hw *hw)
648 {
649         uint32_t sectxreg;
650
651         sectxreg = rd32(hw, TXGBE_SECTXCTL);
652         sectxreg &= ~TXGBE_SECTXCTL_XDSA;
653         wr32(hw, TXGBE_SECTXCTL, sectxreg);
654         txgbe_flush(hw);
655
656         return 0;
657 }
658
659 /**
660  *  txgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
661  *  @hw: pointer to hardware structure
662  *  @san_mac_offset: SAN MAC address offset
663  *
664  *  This function will read the EEPROM location for the SAN MAC address
665  *  pointer, and returns the value at that location.  This is used in both
666  *  get and set mac_addr routines.
667  **/
668 static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
669                                          u16 *san_mac_offset)
670 {
671         s32 err;
672
673         DEBUGFUNC("txgbe_get_san_mac_addr_offset");
674
675         /*
676          * First read the EEPROM pointer to see if the MAC addresses are
677          * available.
678          */
679         err = hw->rom.readw_sw(hw, TXGBE_SAN_MAC_ADDR_PTR,
680                                       san_mac_offset);
681         if (err) {
682                 DEBUGOUT("eeprom at offset %d failed",
683                          TXGBE_SAN_MAC_ADDR_PTR);
684         }
685
686         return err;
687 }
688
689 /**
690  *  txgbe_get_san_mac_addr - SAN MAC address retrieval from the EEPROM
691  *  @hw: pointer to hardware structure
692  *  @san_mac_addr: SAN MAC address
693  *
694  *  Reads the SAN MAC address from the EEPROM, if it's available.  This is
695  *  per-port, so set_lan_id() must be called before reading the addresses.
696  *  set_lan_id() is called by identify_sfp(), but this cannot be relied
697  *  upon for non-SFP connections, so we must call it here.
698  **/
699 s32 txgbe_get_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
700 {
701         u16 san_mac_data, san_mac_offset;
702         u8 i;
703         s32 err;
704
705         DEBUGFUNC("txgbe_get_san_mac_addr");
706
707         /*
708          * First read the EEPROM pointer to see if the MAC addresses are
709          * available. If they're not, no point in calling set_lan_id() here.
710          */
711         err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
712         if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
713                 goto san_mac_addr_out;
714
715         /* apply the port offset to the address offset */
716         (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
717                          (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
718         for (i = 0; i < 3; i++) {
719                 err = hw->rom.read16(hw, san_mac_offset,
720                                               &san_mac_data);
721                 if (err) {
722                         DEBUGOUT("eeprom read at offset %d failed",
723                                  san_mac_offset);
724                         goto san_mac_addr_out;
725                 }
726                 san_mac_addr[i * 2] = (u8)(san_mac_data);
727                 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
728                 san_mac_offset++;
729         }
730         return 0;
731
732 san_mac_addr_out:
733         /*
734          * No addresses available in this EEPROM.  It's not an
735          * error though, so just wipe the local address and return.
736          */
737         for (i = 0; i < 6; i++)
738                 san_mac_addr[i] = 0xFF;
739         return 0;
740 }
741
742 /**
743  *  txgbe_set_san_mac_addr - Write the SAN MAC address to the EEPROM
744  *  @hw: pointer to hardware structure
745  *  @san_mac_addr: SAN MAC address
746  *
747  *  Write a SAN MAC address to the EEPROM.
748  **/
749 s32 txgbe_set_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
750 {
751         s32 err;
752         u16 san_mac_data, san_mac_offset;
753         u8 i;
754
755         DEBUGFUNC("txgbe_set_san_mac_addr");
756
757         /* Look for SAN mac address pointer.  If not defined, return */
758         err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
759         if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
760                 return TXGBE_ERR_NO_SAN_ADDR_PTR;
761
762         /* Apply the port offset to the address offset */
763         (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
764                          (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
765
766         for (i = 0; i < 3; i++) {
767                 san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
768                 san_mac_data |= (u16)(san_mac_addr[i * 2]);
769                 hw->rom.write16(hw, san_mac_offset, san_mac_data);
770                 san_mac_offset++;
771         }
772
773         return 0;
774 }
775
776 /**
777  *  txgbe_init_uta_tables - Initialize the Unicast Table Array
778  *  @hw: pointer to hardware structure
779  **/
780 s32 txgbe_init_uta_tables(struct txgbe_hw *hw)
781 {
782         int i;
783
784         DEBUGFUNC("txgbe_init_uta_tables");
785         DEBUGOUT(" Clearing UTA\n");
786
787         for (i = 0; i < 128; i++)
788                 wr32(hw, TXGBE_UCADDRTBL(i), 0);
789
790         return 0;
791 }
792
793 /**
794  *  txgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
795  *  @hw: pointer to hardware structure
796  *
797  *  Contains the logic to identify if we need to verify link for the
798  *  crosstalk fix
799  **/
800 static bool txgbe_need_crosstalk_fix(struct txgbe_hw *hw)
801 {
802         /* Does FW say we need the fix */
803         if (!hw->need_crosstalk_fix)
804                 return false;
805
806         /* Only consider SFP+ PHYs i.e. media type fiber */
807         switch (hw->phy.media_type) {
808         case txgbe_media_type_fiber:
809         case txgbe_media_type_fiber_qsfp:
810                 break;
811         default:
812                 return false;
813         }
814
815         return true;
816 }
817
818 /**
819  *  txgbe_check_mac_link - Determine link and speed status
820  *  @hw: pointer to hardware structure
821  *  @speed: pointer to link speed
822  *  @link_up: true when link is up
823  *  @link_up_wait_to_complete: bool used to wait for link up or not
824  *
825  *  Reads the links register to determine if link is up and the current speed
826  **/
827 s32 txgbe_check_mac_link(struct txgbe_hw *hw, u32 *speed,
828                                  bool *link_up, bool link_up_wait_to_complete)
829 {
830         u32 links_reg, links_orig;
831         u32 i;
832
833         DEBUGFUNC("txgbe_check_mac_link");
834
835         /* If Crosstalk fix enabled do the sanity check of making sure
836          * the SFP+ cage is full.
837          */
838         if (txgbe_need_crosstalk_fix(hw)) {
839                 u32 sfp_cage_full;
840
841                 switch (hw->mac.type) {
842                 case txgbe_mac_raptor:
843                         sfp_cage_full = !rd32m(hw, TXGBE_GPIODATA,
844                                         TXGBE_GPIOBIT_2);
845                         break;
846                 default:
847                         /* sanity check - No SFP+ devices here */
848                         sfp_cage_full = false;
849                         break;
850                 }
851
852                 if (!sfp_cage_full) {
853                         *link_up = false;
854                         *speed = TXGBE_LINK_SPEED_UNKNOWN;
855                         return 0;
856                 }
857         }
858
859         /* clear the old state */
860         links_orig = rd32(hw, TXGBE_PORTSTAT);
861
862         links_reg = rd32(hw, TXGBE_PORTSTAT);
863
864         if (links_orig != links_reg) {
865                 DEBUGOUT("LINKS changed from %08X to %08X\n",
866                           links_orig, links_reg);
867         }
868
869         if (link_up_wait_to_complete) {
870                 for (i = 0; i < hw->mac.max_link_up_time; i++) {
871                         if (!(links_reg & TXGBE_PORTSTAT_UP)) {
872                                 *link_up = false;
873                         } else {
874                                 *link_up = true;
875                                 break;
876                         }
877                         msec_delay(100);
878                         links_reg = rd32(hw, TXGBE_PORTSTAT);
879                 }
880         } else {
881                 if (links_reg & TXGBE_PORTSTAT_UP)
882                         *link_up = true;
883                 else
884                         *link_up = false;
885         }
886
887         switch (links_reg & TXGBE_PORTSTAT_BW_MASK) {
888         case TXGBE_PORTSTAT_BW_10G:
889                 *speed = TXGBE_LINK_SPEED_10GB_FULL;
890                 break;
891         case TXGBE_PORTSTAT_BW_1G:
892                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
893                 break;
894         case TXGBE_PORTSTAT_BW_100M:
895                 *speed = TXGBE_LINK_SPEED_100M_FULL;
896                 break;
897         default:
898                 *speed = TXGBE_LINK_SPEED_UNKNOWN;
899         }
900
901         return 0;
902 }
903
904 /**
905  *  txgbe_get_device_caps - Get additional device capabilities
906  *  @hw: pointer to hardware structure
907  *  @device_caps: the EEPROM word with the extra device capabilities
908  *
909  *  This function will read the EEPROM location for the device capabilities,
910  *  and return the word through device_caps.
911  **/
912 s32 txgbe_get_device_caps(struct txgbe_hw *hw, u16 *device_caps)
913 {
914         DEBUGFUNC("txgbe_get_device_caps");
915
916         hw->rom.readw_sw(hw, TXGBE_DEVICE_CAPS, device_caps);
917
918         return 0;
919 }
920
921 /**
922  * txgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
923  * @hw: pointer to the hardware structure
924  *
925  * The MACs can experience issues if TX work is still pending
926  * when a reset occurs.  This function prevents this by flushing the PCIe
927  * buffers on the system.
928  **/
929 void txgbe_clear_tx_pending(struct txgbe_hw *hw)
930 {
931         u32 hlreg0, i, poll;
932
933         /*
934          * If double reset is not requested then all transactions should
935          * already be clear and as such there is no work to do
936          */
937         if (!(hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
938                 return;
939
940         hlreg0 = rd32(hw, TXGBE_PSRCTL);
941         wr32(hw, TXGBE_PSRCTL, hlreg0 | TXGBE_PSRCTL_LBENA);
942
943         /* Wait for a last completion before clearing buffers */
944         txgbe_flush(hw);
945         msec_delay(3);
946
947         /*
948          * Before proceeding, make sure that the PCIe block does not have
949          * transactions pending.
950          */
951         poll = (800 * 11) / 10;
952         for (i = 0; i < poll; i++)
953                 usec_delay(100);
954
955         /* Flush all writes and allow 20usec for all transactions to clear */
956         txgbe_flush(hw);
957         usec_delay(20);
958
959         /* restore previous register values */
960         wr32(hw, TXGBE_PSRCTL, hlreg0);
961 }
962
963 /**
964  *  txgbe_get_thermal_sensor_data - Gathers thermal sensor data
965  *  @hw: pointer to hardware structure
966  *
967  *  Returns the thermal sensor data structure
968  **/
969 s32 txgbe_get_thermal_sensor_data(struct txgbe_hw *hw)
970 {
971         struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
972         s64 tsv;
973         u32 ts_stat;
974
975         DEBUGFUNC("txgbe_get_thermal_sensor_data");
976
977         /* Only support thermal sensors attached to physical port 0 */
978         if (hw->bus.lan_id != 0)
979                 return TXGBE_NOT_IMPLEMENTED;
980
981         ts_stat = rd32(hw, TXGBE_TSSTAT);
982         tsv = (s64)TXGBE_TSSTAT_DATA(ts_stat);
983         tsv = tsv > 1200 ? tsv : 1200;
984         tsv = -(48380 << 8) / 1000
985                 + tsv * (31020 << 8) / 100000
986                 - tsv * tsv * (18201 << 8) / 100000000
987                 + tsv * tsv * tsv * (81542 << 8) / 1000000000000
988                 - tsv * tsv * tsv * tsv * (16743 << 8) / 1000000000000000;
989         tsv >>= 8;
990
991         data->sensor[0].temp = (s16)tsv;
992
993         return 0;
994 }
995
996 /**
997  *  txgbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
998  *  @hw: pointer to hardware structure
999  *
1000  *  Inits the thermal sensor thresholds according to the NVM map
1001  *  and save off the threshold and location values into mac.thermal_sensor_data
1002  **/
1003 s32 txgbe_init_thermal_sensor_thresh(struct txgbe_hw *hw)
1004 {
1005         struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
1006
1007         DEBUGFUNC("txgbe_init_thermal_sensor_thresh");
1008
1009         memset(data, 0, sizeof(struct txgbe_thermal_sensor_data));
1010
1011         if (hw->bus.lan_id != 0)
1012                 return TXGBE_NOT_IMPLEMENTED;
1013
1014         wr32(hw, TXGBE_TSCTRL, TXGBE_TSCTRL_EVALMD);
1015         wr32(hw, TXGBE_TSINTR,
1016                 TXGBE_TSINTR_AEN | TXGBE_TSINTR_DEN);
1017         wr32(hw, TXGBE_TSEN, TXGBE_TSEN_ENA);
1018
1019
1020         data->sensor[0].alarm_thresh = 100;
1021         wr32(hw, TXGBE_TSATHRE, 677);
1022         data->sensor[0].dalarm_thresh = 90;
1023         wr32(hw, TXGBE_TSDTHRE, 614);
1024
1025         return 0;
1026 }
1027
1028 void txgbe_disable_rx(struct txgbe_hw *hw)
1029 {
1030         u32 pfdtxgswc;
1031
1032         pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
1033         if (pfdtxgswc & TXGBE_PSRCTL_LBENA) {
1034                 pfdtxgswc &= ~TXGBE_PSRCTL_LBENA;
1035                 wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
1036                 hw->mac.set_lben = true;
1037         } else {
1038                 hw->mac.set_lben = false;
1039         }
1040
1041         wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
1042         wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
1043 }
1044
1045 void txgbe_enable_rx(struct txgbe_hw *hw)
1046 {
1047         u32 pfdtxgswc;
1048
1049         wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, TXGBE_MACRXCFG_ENA);
1050         wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, TXGBE_PBRXCTL_ENA);
1051
1052         if (hw->mac.set_lben) {
1053                 pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
1054                 pfdtxgswc |= TXGBE_PSRCTL_LBENA;
1055                 wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
1056                 hw->mac.set_lben = false;
1057         }
1058 }
1059
1060 /**
1061  *  txgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
1062  *  @hw: pointer to hardware structure
1063  *  @speed: new link speed
1064  *  @autoneg_wait_to_complete: true when waiting for completion is needed
1065  *
1066  *  Set the link speed in the MAC and/or PHY register and restarts link.
1067  **/
1068 s32 txgbe_setup_mac_link_multispeed_fiber(struct txgbe_hw *hw,
1069                                           u32 speed,
1070                                           bool autoneg_wait_to_complete)
1071 {
1072         u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
1073         u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
1074         s32 status = 0;
1075         u32 speedcnt = 0;
1076         u32 i = 0;
1077         bool autoneg, link_up = false;
1078
1079         DEBUGFUNC("txgbe_setup_mac_link_multispeed_fiber");
1080
1081         /* Mask off requested but non-supported speeds */
1082         status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
1083         if (status != 0)
1084                 return status;
1085
1086         speed &= link_speed;
1087
1088         /* Try each speed one by one, highest priority first.  We do this in
1089          * software because 10Gb fiber doesn't support speed autonegotiation.
1090          */
1091         if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
1092                 speedcnt++;
1093                 highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;
1094
1095                 /* Set the module link speed */
1096                 switch (hw->phy.media_type) {
1097                 case txgbe_media_type_fiber:
1098                         hw->mac.set_rate_select_speed(hw,
1099                                 TXGBE_LINK_SPEED_10GB_FULL);
1100                         break;
1101                 case txgbe_media_type_fiber_qsfp:
1102                         /* QSFP module automatically detects MAC link speed */
1103                         break;
1104                 default:
1105                         DEBUGOUT("Unexpected media type.\n");
1106                         break;
1107                 }
1108
1109                 /* Allow module to change analog characteristics (1G->10G) */
1110                 msec_delay(40);
1111
1112                 status = hw->mac.setup_mac_link(hw,
1113                                 TXGBE_LINK_SPEED_10GB_FULL,
1114                                 autoneg_wait_to_complete);
1115                 if (status != 0)
1116                         return status;
1117
1118                 /* Flap the Tx laser if it has not already been done */
1119                 hw->mac.flap_tx_laser(hw);
1120
1121                 /* Wait for the controller to acquire link.  Per IEEE 802.3ap,
1122                  * Section 73.10.2, we may have to wait up to 500ms if KR is
1123                  * attempted.  uses the same timing for 10g SFI.
1124                  */
1125                 for (i = 0; i < 5; i++) {
1126                         /* Wait for the link partner to also set speed */
1127                         msec_delay(100);
1128
1129                         /* If we have link, just jump out */
1130                         status = hw->mac.check_link(hw, &link_speed,
1131                                 &link_up, false);
1132                         if (status != 0)
1133                                 return status;
1134
1135                         if (link_up)
1136                                 goto out;
1137                 }
1138         }
1139
1140         if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
1141                 speedcnt++;
1142                 if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
1143                         highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL;
1144
1145                 /* Set the module link speed */
1146                 switch (hw->phy.media_type) {
1147                 case txgbe_media_type_fiber:
1148                         hw->mac.set_rate_select_speed(hw,
1149                                 TXGBE_LINK_SPEED_1GB_FULL);
1150                         break;
1151                 case txgbe_media_type_fiber_qsfp:
1152                         /* QSFP module automatically detects link speed */
1153                         break;
1154                 default:
1155                         DEBUGOUT("Unexpected media type.\n");
1156                         break;
1157                 }
1158
1159                 /* Allow module to change analog characteristics (10G->1G) */
1160                 msec_delay(40);
1161
1162                 status = hw->mac.setup_mac_link(hw,
1163                                 TXGBE_LINK_SPEED_1GB_FULL,
1164                                 autoneg_wait_to_complete);
1165                 if (status != 0)
1166                         return status;
1167
1168                 /* Flap the Tx laser if it has not already been done */
1169                 hw->mac.flap_tx_laser(hw);
1170
1171                 /* Wait for the link partner to also set speed */
1172                 msec_delay(100);
1173
1174                 /* If we have link, just jump out */
1175                 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
1176                 if (status != 0)
1177                         return status;
1178
1179                 if (link_up)
1180                         goto out;
1181         }
1182
1183         /* We didn't get link.  Configure back to the highest speed we tried,
1184          * (if there was more than one).  We call ourselves back with just the
1185          * single highest speed that the user requested.
1186          */
1187         if (speedcnt > 1)
1188                 status = txgbe_setup_mac_link_multispeed_fiber(hw,
1189                                                       highest_link_speed,
1190                                                       autoneg_wait_to_complete);
1191
1192 out:
1193         /* Set autoneg_advertised value based on input link speed */
1194         hw->phy.autoneg_advertised = 0;
1195
1196         if (speed & TXGBE_LINK_SPEED_10GB_FULL)
1197                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
1198
1199         if (speed & TXGBE_LINK_SPEED_1GB_FULL)
1200                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
1201
1202         return status;
1203 }
1204
1205 /**
1206  *  txgbe_init_shared_code - Initialize the shared code
1207  *  @hw: pointer to hardware structure
1208  *
1209  *  This will assign function pointers and assign the MAC type and PHY code.
1210  *  Does not touch the hardware. This function must be called prior to any
1211  *  other function in the shared code. The txgbe_hw structure should be
1212  *  memset to 0 prior to calling this function.  The following fields in
1213  *  hw structure should be filled in prior to calling this function:
1214  *  hw_addr, back, device_id, vendor_id, subsystem_device_id,
1215  *  subsystem_vendor_id, and revision_id
1216  **/
1217 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
1218 {
1219         s32 status;
1220
1221         DEBUGFUNC("txgbe_init_shared_code");
1222
1223         /*
1224          * Set the mac type
1225          */
1226         txgbe_set_mac_type(hw);
1227
1228         txgbe_init_ops_dummy(hw);
1229         switch (hw->mac.type) {
1230         case txgbe_mac_raptor:
1231                 status = txgbe_init_ops_pf(hw);
1232                 break;
1233         default:
1234                 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
1235                 break;
1236         }
1237         hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
1238
1239         hw->bus.set_lan_id(hw);
1240
1241         return status;
1242 }
1243
1244 /**
1245  *  txgbe_set_mac_type - Sets MAC type
1246  *  @hw: pointer to the HW structure
1247  *
1248  *  This function sets the mac type of the adapter based on the
1249  *  vendor ID and device ID stored in the hw structure.
1250  **/
1251 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
1252 {
1253         s32 err = 0;
1254
1255         DEBUGFUNC("txgbe_set_mac_type");
1256
1257         if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
1258                 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
1259                 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
1260         }
1261
1262         switch (hw->device_id) {
1263         case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
1264                 hw->phy.media_type = txgbe_media_type_backplane;
1265                 hw->mac.type = txgbe_mac_raptor;
1266                 break;
1267         case TXGBE_DEV_ID_RAPTOR_XAUI:
1268         case TXGBE_DEV_ID_RAPTOR_SGMII:
1269                 hw->phy.media_type = txgbe_media_type_copper;
1270                 hw->mac.type = txgbe_mac_raptor;
1271                 break;
1272         case TXGBE_DEV_ID_RAPTOR_SFP:
1273         case TXGBE_DEV_ID_WX1820_SFP:
1274                 hw->phy.media_type = txgbe_media_type_fiber;
1275                 hw->mac.type = txgbe_mac_raptor;
1276                 break;
1277         case TXGBE_DEV_ID_RAPTOR_QSFP:
1278                 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
1279                 hw->mac.type = txgbe_mac_raptor;
1280                 break;
1281         case TXGBE_DEV_ID_RAPTOR_VF:
1282         case TXGBE_DEV_ID_RAPTOR_VF_HV:
1283                 hw->phy.media_type = txgbe_media_type_virtual;
1284                 hw->mac.type = txgbe_mac_raptor_vf;
1285                 break;
1286         default:
1287                 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
1288                 DEBUGOUT("Unsupported device id: %x", hw->device_id);
1289                 break;
1290         }
1291
1292         DEBUGOUT("found mac: %d media: %d, returns: %d\n",
1293                   hw->mac.type, hw->phy.media_type, err);
1294         return err;
1295 }
1296
1297 void txgbe_init_mac_link_ops(struct txgbe_hw *hw)
1298 {
1299         struct txgbe_mac_info *mac = &hw->mac;
1300
1301         DEBUGFUNC("txgbe_init_mac_link_ops");
1302
1303         /*
1304          * enable the laser control functions for SFP+ fiber
1305          * and MNG not enabled
1306          */
1307         if (hw->phy.media_type == txgbe_media_type_fiber &&
1308             !txgbe_mng_enabled(hw)) {
1309                 mac->disable_tx_laser =
1310                         txgbe_disable_tx_laser_multispeed_fiber;
1311                 mac->enable_tx_laser =
1312                         txgbe_enable_tx_laser_multispeed_fiber;
1313                 mac->flap_tx_laser =
1314                         txgbe_flap_tx_laser_multispeed_fiber;
1315         }
1316
1317         if ((hw->phy.media_type == txgbe_media_type_fiber ||
1318              hw->phy.media_type == txgbe_media_type_fiber_qsfp) &&
1319             hw->phy.multispeed_fiber) {
1320                 /* Set up dual speed SFP+ support */
1321                 mac->setup_link = txgbe_setup_mac_link_multispeed_fiber;
1322                 mac->setup_mac_link = txgbe_setup_mac_link;
1323                 mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
1324         } else if ((hw->phy.media_type == txgbe_media_type_backplane) &&
1325                     (hw->phy.smart_speed == txgbe_smart_speed_auto ||
1326                      hw->phy.smart_speed == txgbe_smart_speed_on) &&
1327                      !txgbe_verify_lesm_fw_enabled_raptor(hw)) {
1328                 mac->setup_link = txgbe_setup_mac_link_smartspeed;
1329         } else {
1330                 mac->setup_link = txgbe_setup_mac_link;
1331         }
1332 }
1333
1334 /**
1335  *  txgbe_init_phy_raptor - PHY/SFP specific init
1336  *  @hw: pointer to hardware structure
1337  *
1338  *  Initialize any function pointers that were not able to be
1339  *  set during init_shared_code because the PHY/SFP type was
1340  *  not known.  Perform the SFP init if necessary.
1341  *
1342  **/
1343 s32 txgbe_init_phy_raptor(struct txgbe_hw *hw)
1344 {
1345         struct txgbe_mac_info *mac = &hw->mac;
1346         struct txgbe_phy_info *phy = &hw->phy;
1347         s32 err = 0;
1348
1349         DEBUGFUNC("txgbe_init_phy_raptor");
1350
1351         if (hw->device_id == TXGBE_DEV_ID_RAPTOR_QSFP) {
1352                 /* Store flag indicating I2C bus access control unit. */
1353                 hw->phy.qsfp_shared_i2c_bus = TRUE;
1354
1355                 /* Initialize access to QSFP+ I2C bus */
1356                 txgbe_flush(hw);
1357         }
1358
1359         /* Identify the PHY or SFP module */
1360         err = phy->identify(hw);
1361         if (err == TXGBE_ERR_SFP_NOT_SUPPORTED)
1362                 goto init_phy_ops_out;
1363
1364         /* Setup function pointers based on detected SFP module and speeds */
1365         txgbe_init_mac_link_ops(hw);
1366
1367         /* If copper media, overwrite with copper function pointers */
1368         if (phy->media_type == txgbe_media_type_copper) {
1369                 mac->setup_link = txgbe_setup_copper_link_raptor;
1370                 mac->get_link_capabilities =
1371                                   txgbe_get_copper_link_capabilities;
1372         }
1373
1374         /* Set necessary function pointers based on PHY type */
1375         switch (hw->phy.type) {
1376         case txgbe_phy_tn:
1377                 phy->setup_link = txgbe_setup_phy_link_tnx;
1378                 phy->check_link = txgbe_check_phy_link_tnx;
1379                 break;
1380         default:
1381                 break;
1382         }
1383
1384 init_phy_ops_out:
1385         return err;
1386 }
1387
1388 s32 txgbe_setup_sfp_modules(struct txgbe_hw *hw)
1389 {
1390         s32 err = 0;
1391
1392         DEBUGFUNC("txgbe_setup_sfp_modules");
1393
1394         if (hw->phy.sfp_type == txgbe_sfp_type_unknown)
1395                 return 0;
1396
1397         txgbe_init_mac_link_ops(hw);
1398
1399         /* PHY config will finish before releasing the semaphore */
1400         err = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
1401         if (err != 0)
1402                 return TXGBE_ERR_SWFW_SYNC;
1403
1404         /* Release the semaphore */
1405         hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
1406
1407         /* Delay obtaining semaphore again to allow FW access
1408          * prot_autoc_write uses the semaphore too.
1409          */
1410         msec_delay(hw->rom.semaphore_delay);
1411
1412         if (err) {
1413                 DEBUGOUT("sfp module setup not complete\n");
1414                 return TXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
1415         }
1416
1417         return err;
1418 }
1419
1420 /**
1421  *  txgbe_init_ops_pf - Inits func ptrs and MAC type
1422  *  @hw: pointer to hardware structure
1423  *
1424  *  Initialize the function pointers and assign the MAC type.
1425  *  Does not touch the hardware.
1426  **/
1427 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
1428 {
1429         struct txgbe_bus_info *bus = &hw->bus;
1430         struct txgbe_mac_info *mac = &hw->mac;
1431         struct txgbe_phy_info *phy = &hw->phy;
1432         struct txgbe_rom_info *rom = &hw->rom;
1433
1434         DEBUGFUNC("txgbe_init_ops_pf");
1435
1436         /* BUS */
1437         bus->set_lan_id = txgbe_set_lan_id_multi_port;
1438
1439         /* PHY */
1440         phy->get_media_type = txgbe_get_media_type_raptor;
1441         phy->identify = txgbe_identify_phy;
1442         phy->init = txgbe_init_phy_raptor;
1443         phy->read_reg = txgbe_read_phy_reg;
1444         phy->write_reg = txgbe_write_phy_reg;
1445         phy->read_reg_mdi = txgbe_read_phy_reg_mdi;
1446         phy->write_reg_mdi = txgbe_write_phy_reg_mdi;
1447         phy->setup_link = txgbe_setup_phy_link;
1448         phy->setup_link_speed = txgbe_setup_phy_link_speed;
1449         phy->read_i2c_byte = txgbe_read_i2c_byte;
1450         phy->write_i2c_byte = txgbe_write_i2c_byte;
1451         phy->read_i2c_eeprom = txgbe_read_i2c_eeprom;
1452         phy->write_i2c_eeprom = txgbe_write_i2c_eeprom;
1453         phy->reset = txgbe_reset_phy;
1454
1455         /* MAC */
1456         mac->init_hw = txgbe_init_hw;
1457         mac->start_hw = txgbe_start_hw_raptor;
1458         mac->enable_rx_dma = txgbe_enable_rx_dma_raptor;
1459         mac->get_mac_addr = txgbe_get_mac_addr;
1460         mac->stop_hw = txgbe_stop_hw;
1461         mac->reset_hw = txgbe_reset_hw;
1462
1463         mac->disable_sec_rx_path = txgbe_disable_sec_rx_path;
1464         mac->enable_sec_rx_path = txgbe_enable_sec_rx_path;
1465         mac->disable_sec_tx_path = txgbe_disable_sec_tx_path;
1466         mac->enable_sec_tx_path = txgbe_enable_sec_tx_path;
1467         mac->get_san_mac_addr = txgbe_get_san_mac_addr;
1468         mac->set_san_mac_addr = txgbe_set_san_mac_addr;
1469         mac->get_device_caps = txgbe_get_device_caps;
1470         mac->autoc_read = txgbe_autoc_read;
1471         mac->autoc_write = txgbe_autoc_write;
1472
1473         mac->set_rar = txgbe_set_rar;
1474         mac->clear_rar = txgbe_clear_rar;
1475         mac->init_rx_addrs = txgbe_init_rx_addrs;
1476         mac->enable_rx = txgbe_enable_rx;
1477         mac->disable_rx = txgbe_disable_rx;
1478         mac->init_uta_tables = txgbe_init_uta_tables;
1479         mac->setup_sfp = txgbe_setup_sfp_modules;
1480         /* Link */
1481         mac->get_link_capabilities = txgbe_get_link_capabilities_raptor;
1482         mac->check_link = txgbe_check_mac_link;
1483
1484         /* Manageability interface */
1485         mac->get_thermal_sensor_data = txgbe_get_thermal_sensor_data;
1486         mac->init_thermal_sensor_thresh = txgbe_init_thermal_sensor_thresh;
1487
1488         /* EEPROM */
1489         rom->init_params = txgbe_init_eeprom_params;
1490         rom->read16 = txgbe_ee_read16;
1491         rom->readw_buffer = txgbe_ee_readw_buffer;
1492         rom->readw_sw = txgbe_ee_readw_sw;
1493         rom->read32 = txgbe_ee_read32;
1494         rom->write16 = txgbe_ee_write16;
1495         rom->writew_buffer = txgbe_ee_writew_buffer;
1496         rom->writew_sw = txgbe_ee_writew_sw;
1497         rom->write32 = txgbe_ee_write32;
1498         rom->validate_checksum = txgbe_validate_eeprom_checksum;
1499         rom->update_checksum = txgbe_update_eeprom_checksum;
1500         rom->calc_checksum = txgbe_calc_eeprom_checksum;
1501
1502         mac->mcft_size          = TXGBE_RAPTOR_MC_TBL_SIZE;
1503         mac->num_rar_entries    = TXGBE_RAPTOR_RAR_ENTRIES;
1504         mac->max_rx_queues      = TXGBE_RAPTOR_MAX_RX_QUEUES;
1505         mac->max_tx_queues      = TXGBE_RAPTOR_MAX_TX_QUEUES;
1506
1507         return 0;
1508 }
1509
1510 /**
1511  *  txgbe_get_link_capabilities_raptor - Determines link capabilities
1512  *  @hw: pointer to hardware structure
1513  *  @speed: pointer to link speed
1514  *  @autoneg: true when autoneg or autotry is enabled
1515  *
1516  *  Determines the link capabilities by reading the AUTOC register.
1517  **/
1518 s32 txgbe_get_link_capabilities_raptor(struct txgbe_hw *hw,
1519                                       u32 *speed,
1520                                       bool *autoneg)
1521 {
1522         s32 status = 0;
1523         u32 autoc = 0;
1524
1525         DEBUGFUNC("txgbe_get_link_capabilities_raptor");
1526
1527         /* Check if 1G SFP module. */
1528         if (hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
1529             hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
1530             hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
1531             hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
1532             hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
1533             hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1) {
1534                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
1535                 *autoneg = true;
1536                 return 0;
1537         }
1538
1539         /*
1540          * Determine link capabilities based on the stored value of AUTOC,
1541          * which represents EEPROM defaults.  If AUTOC value has not
1542          * been stored, use the current register values.
1543          */
1544         if (hw->mac.orig_link_settings_stored)
1545                 autoc = hw->mac.orig_autoc;
1546         else
1547                 autoc = hw->mac.autoc_read(hw);
1548
1549         switch (autoc & TXGBE_AUTOC_LMS_MASK) {
1550         case TXGBE_AUTOC_LMS_1G_LINK_NO_AN:
1551                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
1552                 *autoneg = false;
1553                 break;
1554
1555         case TXGBE_AUTOC_LMS_10G_LINK_NO_AN:
1556                 *speed = TXGBE_LINK_SPEED_10GB_FULL;
1557                 *autoneg = false;
1558                 break;
1559
1560         case TXGBE_AUTOC_LMS_1G_AN:
1561                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
1562                 *autoneg = true;
1563                 break;
1564
1565         case TXGBE_AUTOC_LMS_10G:
1566                 *speed = TXGBE_LINK_SPEED_10GB_FULL;
1567                 *autoneg = false;
1568                 break;
1569
1570         case TXGBE_AUTOC_LMS_KX4_KX_KR:
1571         case TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
1572                 *speed = TXGBE_LINK_SPEED_UNKNOWN;
1573                 if (autoc & TXGBE_AUTOC_KR_SUPP)
1574                         *speed |= TXGBE_LINK_SPEED_10GB_FULL;
1575                 if (autoc & TXGBE_AUTOC_KX4_SUPP)
1576                         *speed |= TXGBE_LINK_SPEED_10GB_FULL;
1577                 if (autoc & TXGBE_AUTOC_KX_SUPP)
1578                         *speed |= TXGBE_LINK_SPEED_1GB_FULL;
1579                 *autoneg = true;
1580                 break;
1581
1582         case TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
1583                 *speed = TXGBE_LINK_SPEED_100M_FULL;
1584                 if (autoc & TXGBE_AUTOC_KR_SUPP)
1585                         *speed |= TXGBE_LINK_SPEED_10GB_FULL;
1586                 if (autoc & TXGBE_AUTOC_KX4_SUPP)
1587                         *speed |= TXGBE_LINK_SPEED_10GB_FULL;
1588                 if (autoc & TXGBE_AUTOC_KX_SUPP)
1589                         *speed |= TXGBE_LINK_SPEED_1GB_FULL;
1590                 *autoneg = true;
1591                 break;
1592
1593         case TXGBE_AUTOC_LMS_SGMII_1G_100M:
1594                 *speed = TXGBE_LINK_SPEED_1GB_FULL |
1595                          TXGBE_LINK_SPEED_100M_FULL |
1596                          TXGBE_LINK_SPEED_10M_FULL;
1597                 *autoneg = false;
1598                 break;
1599
1600         default:
1601                 return TXGBE_ERR_LINK_SETUP;
1602         }
1603
1604         if (hw->phy.multispeed_fiber) {
1605                 *speed |= TXGBE_LINK_SPEED_10GB_FULL |
1606                           TXGBE_LINK_SPEED_1GB_FULL;
1607
1608                 /* QSFP must not enable full auto-negotiation
1609                  * Limited autoneg is enabled at 1G
1610                  */
1611                 if (hw->phy.media_type == txgbe_media_type_fiber_qsfp)
1612                         *autoneg = false;
1613                 else
1614                         *autoneg = true;
1615         }
1616
1617         return status;
1618 }
1619
1620 /**
1621  *  txgbe_get_media_type_raptor - Get media type
1622  *  @hw: pointer to hardware structure
1623  *
1624  *  Returns the media type (fiber, copper, backplane)
1625  **/
1626 u32 txgbe_get_media_type_raptor(struct txgbe_hw *hw)
1627 {
1628         u32 media_type;
1629
1630         DEBUGFUNC("txgbe_get_media_type_raptor");
1631
1632         /* Detect if there is a copper PHY attached. */
1633         switch (hw->phy.type) {
1634         case txgbe_phy_cu_unknown:
1635         case txgbe_phy_tn:
1636                 media_type = txgbe_media_type_copper;
1637                 return media_type;
1638         default:
1639                 break;
1640         }
1641
1642         switch (hw->device_id) {
1643         case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
1644                 /* Default device ID is mezzanine card KX/KX4 */
1645                 media_type = txgbe_media_type_backplane;
1646                 break;
1647         case TXGBE_DEV_ID_RAPTOR_SFP:
1648         case TXGBE_DEV_ID_WX1820_SFP:
1649                 media_type = txgbe_media_type_fiber;
1650                 break;
1651         case TXGBE_DEV_ID_RAPTOR_QSFP:
1652                 media_type = txgbe_media_type_fiber_qsfp;
1653                 break;
1654         case TXGBE_DEV_ID_RAPTOR_XAUI:
1655         case TXGBE_DEV_ID_RAPTOR_SGMII:
1656                 media_type = txgbe_media_type_copper;
1657                 break;
1658         default:
1659                 media_type = txgbe_media_type_unknown;
1660                 break;
1661         }
1662
1663         return media_type;
1664 }
1665
1666 /**
1667  *  txgbe_start_mac_link_raptor - Setup MAC link settings
1668  *  @hw: pointer to hardware structure
1669  *  @autoneg_wait_to_complete: true when waiting for completion is needed
1670  *
1671  *  Configures link settings based on values in the txgbe_hw struct.
1672  *  Restarts the link.  Performs autonegotiation if needed.
1673  **/
1674 s32 txgbe_start_mac_link_raptor(struct txgbe_hw *hw,
1675                                bool autoneg_wait_to_complete)
1676 {
1677         s32 status = 0;
1678         bool got_lock = false;
1679
1680         DEBUGFUNC("txgbe_start_mac_link_raptor");
1681
1682         UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
1683
1684         /*  reset_pipeline requires us to hold this lock as it writes to
1685          *  AUTOC.
1686          */
1687         if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
1688                 status = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
1689                 if (status != 0)
1690                         goto out;
1691
1692                 got_lock = true;
1693         }
1694
1695         /* Restart link */
1696         txgbe_reset_pipeline_raptor(hw);
1697
1698         if (got_lock)
1699                 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
1700
1701         /* Add delay to filter out noises during initial link setup */
1702         msec_delay(50);
1703
1704 out:
1705         return status;
1706 }
1707
1708 /**
1709  *  txgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
1710  *  @hw: pointer to hardware structure
1711  *
1712  *  The base drivers may require better control over SFP+ module
1713  *  PHY states.  This includes selectively shutting down the Tx
1714  *  laser on the PHY, effectively halting physical link.
1715  **/
1716 void txgbe_disable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
1717 {
1718         u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
1719
1720         /* Blocked by MNG FW so bail */
1721         if (txgbe_check_reset_blocked(hw))
1722                 return;
1723
1724         /* Disable Tx laser; allow 100us to go dark per spec */
1725         esdp_reg |= (TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
1726         wr32(hw, TXGBE_GPIODATA, esdp_reg);
1727         txgbe_flush(hw);
1728         usec_delay(100);
1729 }
1730
1731 /**
1732  *  txgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
1733  *  @hw: pointer to hardware structure
1734  *
1735  *  The base drivers may require better control over SFP+ module
1736  *  PHY states.  This includes selectively turning on the Tx
1737  *  laser on the PHY, effectively starting physical link.
1738  **/
1739 void txgbe_enable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
1740 {
1741         u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
1742
1743         /* Enable Tx laser; allow 100ms to light up */
1744         esdp_reg &= ~(TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
1745         wr32(hw, TXGBE_GPIODATA, esdp_reg);
1746         txgbe_flush(hw);
1747         msec_delay(100);
1748 }
1749
1750 /**
1751  *  txgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
1752  *  @hw: pointer to hardware structure
1753  *
1754  *  When the driver changes the link speeds that it can support,
1755  *  it sets autotry_restart to true to indicate that we need to
1756  *  initiate a new autotry session with the link partner.  To do
1757  *  so, we set the speed then disable and re-enable the Tx laser, to
1758  *  alert the link partner that it also needs to restart autotry on its
1759  *  end.  This is consistent with true clause 37 autoneg, which also
1760  *  involves a loss of signal.
1761  **/
1762 void txgbe_flap_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
1763 {
1764         DEBUGFUNC("txgbe_flap_tx_laser_multispeed_fiber");
1765
1766         /* Blocked by MNG FW so bail */
1767         if (txgbe_check_reset_blocked(hw))
1768                 return;
1769
1770         if (hw->mac.autotry_restart) {
1771                 txgbe_disable_tx_laser_multispeed_fiber(hw);
1772                 txgbe_enable_tx_laser_multispeed_fiber(hw);
1773                 hw->mac.autotry_restart = false;
1774         }
1775 }
1776
1777 /**
1778  *  txgbe_set_hard_rate_select_speed - Set module link speed
1779  *  @hw: pointer to hardware structure
1780  *  @speed: link speed to set
1781  *
1782  *  Set module link speed via RS0/RS1 rate select pins.
1783  */
1784 void txgbe_set_hard_rate_select_speed(struct txgbe_hw *hw,
1785                                         u32 speed)
1786 {
1787         u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
1788
1789         switch (speed) {
1790         case TXGBE_LINK_SPEED_10GB_FULL:
1791                 esdp_reg |= (TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
1792                 break;
1793         case TXGBE_LINK_SPEED_1GB_FULL:
1794                 esdp_reg &= ~(TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
1795                 break;
1796         default:
1797                 DEBUGOUT("Invalid fixed module speed\n");
1798                 return;
1799         }
1800
1801         wr32(hw, TXGBE_GPIODATA, esdp_reg);
1802         txgbe_flush(hw);
1803 }
1804
1805 /**
1806  *  txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
1807  *  @hw: pointer to hardware structure
1808  *  @speed: new link speed
1809  *  @autoneg_wait_to_complete: true when waiting for completion is needed
1810  *
1811  *  Implements the Intel SmartSpeed algorithm.
1812  **/
1813 s32 txgbe_setup_mac_link_smartspeed(struct txgbe_hw *hw,
1814                                     u32 speed,
1815                                     bool autoneg_wait_to_complete)
1816 {
1817         s32 status = 0;
1818         u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
1819         s32 i, j;
1820         bool link_up = false;
1821         u32 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
1822
1823         DEBUGFUNC("txgbe_setup_mac_link_smartspeed");
1824
1825          /* Set autoneg_advertised value based on input link speed */
1826         hw->phy.autoneg_advertised = 0;
1827
1828         if (speed & TXGBE_LINK_SPEED_10GB_FULL)
1829                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
1830
1831         if (speed & TXGBE_LINK_SPEED_1GB_FULL)
1832                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
1833
1834         if (speed & TXGBE_LINK_SPEED_100M_FULL)
1835                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
1836
1837         /*
1838          * Implement Intel SmartSpeed algorithm.  SmartSpeed will reduce the
1839          * autoneg advertisement if link is unable to be established at the
1840          * highest negotiated rate.  This can sometimes happen due to integrity
1841          * issues with the physical media connection.
1842          */
1843
1844         /* First, try to get link with full advertisement */
1845         hw->phy.smart_speed_active = false;
1846         for (j = 0; j < TXGBE_SMARTSPEED_MAX_RETRIES; j++) {
1847                 status = txgbe_setup_mac_link(hw, speed,
1848                                                     autoneg_wait_to_complete);
1849                 if (status != 0)
1850                         goto out;
1851
1852                 /*
1853                  * Wait for the controller to acquire link.  Per IEEE 802.3ap,
1854                  * Section 73.10.2, we may have to wait up to 500ms if KR is
1855                  * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
1856                  * Table 9 in the AN MAS.
1857                  */
1858                 for (i = 0; i < 5; i++) {
1859                         msec_delay(100);
1860
1861                         /* If we have link, just jump out */
1862                         status = hw->mac.check_link(hw, &link_speed, &link_up,
1863                                                   false);
1864                         if (status != 0)
1865                                 goto out;
1866
1867                         if (link_up)
1868                                 goto out;
1869                 }
1870         }
1871
1872         /*
1873          * We didn't get link.  If we advertised KR plus one of KX4/KX
1874          * (or BX4/BX), then disable KR and try again.
1875          */
1876         if (((autoc_reg & TXGBE_AUTOC_KR_SUPP) == 0) ||
1877             ((autoc_reg & TXGBE_AUTOC_KX_SUPP) == 0 &&
1878              (autoc_reg & TXGBE_AUTOC_KX4_SUPP) == 0))
1879                 goto out;
1880
1881         /* Turn SmartSpeed on to disable KR support */
1882         hw->phy.smart_speed_active = true;
1883         status = txgbe_setup_mac_link(hw, speed,
1884                                             autoneg_wait_to_complete);
1885         if (status != 0)
1886                 goto out;
1887
1888         /*
1889          * Wait for the controller to acquire link.  600ms will allow for
1890          * the AN link_fail_inhibit_timer as well for multiple cycles of
1891          * parallel detect, both 10g and 1g. This allows for the maximum
1892          * connect attempts as defined in the AN MAS table 73-7.
1893          */
1894         for (i = 0; i < 6; i++) {
1895                 msec_delay(100);
1896
1897                 /* If we have link, just jump out */
1898                 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
1899                 if (status != 0)
1900                         goto out;
1901
1902                 if (link_up)
1903                         goto out;
1904         }
1905
1906         /* We didn't get link.  Turn SmartSpeed back off. */
1907         hw->phy.smart_speed_active = false;
1908         status = txgbe_setup_mac_link(hw, speed,
1909                                             autoneg_wait_to_complete);
1910
1911 out:
1912         if (link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL)
1913                 DEBUGOUT("Smartspeed has downgraded the link speed "
1914                 "from the maximum advertised\n");
1915         return status;
1916 }
1917
1918 /**
1919  *  txgbe_setup_mac_link - Set MAC link speed
1920  *  @hw: pointer to hardware structure
1921  *  @speed: new link speed
1922  *  @autoneg_wait_to_complete: true when waiting for completion is needed
1923  *
1924  *  Set the link speed in the AUTOC register and restarts link.
1925  **/
1926 s32 txgbe_setup_mac_link(struct txgbe_hw *hw,
1927                                u32 speed,
1928                                bool autoneg_wait_to_complete)
1929 {
1930         bool autoneg = false;
1931         s32 status = 0;
1932
1933         u64 autoc = hw->mac.autoc_read(hw);
1934         u64 pma_pmd_10gs = autoc & TXGBE_AUTOC_10GS_PMA_PMD_MASK;
1935         u64 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
1936         u64 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
1937         u64 current_autoc = autoc;
1938         u64 orig_autoc = 0;
1939         u32 links_reg;
1940         u32 i;
1941         u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN;
1942
1943         DEBUGFUNC("txgbe_setup_mac_link");
1944
1945         /* Check to see if speed passed in is supported. */
1946         status = hw->mac.get_link_capabilities(hw,
1947                         &link_capabilities, &autoneg);
1948         if (status)
1949                 return status;
1950
1951         speed &= link_capabilities;
1952         if (speed == TXGBE_LINK_SPEED_UNKNOWN)
1953                 return TXGBE_ERR_LINK_SETUP;
1954
1955         /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
1956         if (hw->mac.orig_link_settings_stored)
1957                 orig_autoc = hw->mac.orig_autoc;
1958         else
1959                 orig_autoc = autoc;
1960
1961         link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
1962         pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
1963
1964         if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
1965             link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
1966             link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
1967                 /* Set KX4/KX/KR support according to speed requested */
1968                 autoc &= ~(TXGBE_AUTOC_KX_SUPP |
1969                            TXGBE_AUTOC_KX4_SUPP |
1970                            TXGBE_AUTOC_KR_SUPP);
1971                 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
1972                         if (orig_autoc & TXGBE_AUTOC_KX4_SUPP)
1973                                 autoc |= TXGBE_AUTOC_KX4_SUPP;
1974                         if ((orig_autoc & TXGBE_AUTOC_KR_SUPP) &&
1975                             !hw->phy.smart_speed_active)
1976                                 autoc |= TXGBE_AUTOC_KR_SUPP;
1977                 }
1978                 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
1979                         autoc |= TXGBE_AUTOC_KX_SUPP;
1980         } else if ((pma_pmd_1g == TXGBE_AUTOC_1G_SFI) &&
1981                    (link_mode == TXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
1982                     link_mode == TXGBE_AUTOC_LMS_1G_AN)) {
1983                 /* Switch from 1G SFI to 10G SFI if requested */
1984                 if (speed == TXGBE_LINK_SPEED_10GB_FULL &&
1985                     pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) {
1986                         autoc &= ~TXGBE_AUTOC_LMS_MASK;
1987                         autoc |= TXGBE_AUTOC_LMS_10G;
1988                 }
1989         } else if ((pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) &&
1990                    (link_mode == TXGBE_AUTOC_LMS_10G)) {
1991                 /* Switch from 10G SFI to 1G SFI if requested */
1992                 if (speed == TXGBE_LINK_SPEED_1GB_FULL &&
1993                     pma_pmd_1g == TXGBE_AUTOC_1G_SFI) {
1994                         autoc &= ~TXGBE_AUTOC_LMS_MASK;
1995                         if (autoneg || hw->phy.type == txgbe_phy_qsfp_intel)
1996                                 autoc |= TXGBE_AUTOC_LMS_1G_AN;
1997                         else
1998                                 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
1999                 }
2000         }
2001
2002         if (autoc == current_autoc)
2003                 return status;
2004
2005         autoc &= ~TXGBE_AUTOC_SPEED_MASK;
2006         autoc |= TXGBE_AUTOC_SPEED(speed);
2007         autoc |= (autoneg ? TXGBE_AUTOC_AUTONEG : 0);
2008
2009         /* Restart link */
2010         hw->mac.autoc_write(hw, autoc);
2011
2012         /* Only poll for autoneg to complete if specified to do so */
2013         if (autoneg_wait_to_complete) {
2014                 if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
2015                     link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
2016                     link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
2017                         links_reg = 0; /*Just in case Autoneg time=0*/
2018                         for (i = 0; i < TXGBE_AUTO_NEG_TIME; i++) {
2019                                 links_reg = rd32(hw, TXGBE_PORTSTAT);
2020                                 if (links_reg & TXGBE_PORTSTAT_UP)
2021                                         break;
2022                                 msec_delay(100);
2023                         }
2024                         if (!(links_reg & TXGBE_PORTSTAT_UP)) {
2025                                 status = TXGBE_ERR_AUTONEG_NOT_COMPLETE;
2026                                 DEBUGOUT("Autoneg did not complete.\n");
2027                         }
2028                 }
2029         }
2030
2031         /* Add delay to filter out noises during initial link setup */
2032         msec_delay(50);
2033
2034         return status;
2035 }
2036
2037 /**
2038  *  txgbe_setup_copper_link_raptor - Set the PHY autoneg advertised field
2039  *  @hw: pointer to hardware structure
2040  *  @speed: new link speed
2041  *  @autoneg_wait_to_complete: true if waiting is needed to complete
2042  *
2043  *  Restarts link on PHY and MAC based on settings passed in.
2044  **/
2045 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
2046                                          u32 speed,
2047                                          bool autoneg_wait_to_complete)
2048 {
2049         s32 status;
2050
2051         DEBUGFUNC("txgbe_setup_copper_link_raptor");
2052
2053         /* Setup the PHY according to input speed */
2054         status = hw->phy.setup_link_speed(hw, speed,
2055                                               autoneg_wait_to_complete);
2056         /* Set up MAC */
2057         txgbe_start_mac_link_raptor(hw, autoneg_wait_to_complete);
2058
2059         return status;
2060 }
2061
2062 static int
2063 txgbe_check_flash_load(struct txgbe_hw *hw, u32 check_bit)
2064 {
2065         u32 reg = 0;
2066         u32 i;
2067         int err = 0;
2068         /* if there's flash existing */
2069         if (!(rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_BPFLASH)) {
2070                 /* wait hw load flash done */
2071                 for (i = 0; i < 10; i++) {
2072                         reg = rd32(hw, TXGBE_ILDRSTAT);
2073                         if (!(reg & check_bit)) {
2074                                 /* done */
2075                                 break;
2076                         }
2077                         msleep(100);
2078                 }
2079                 if (i == 10)
2080                         err = TXGBE_ERR_FLASH_LOADING_FAILED;
2081         }
2082         return err;
2083 }
2084
2085 static void
2086 txgbe_reset_misc(struct txgbe_hw *hw)
2087 {
2088         int i;
2089         u32 value;
2090
2091         wr32(hw, TXGBE_ISBADDRL, hw->isb_dma & 0x00000000FFFFFFFF);
2092         wr32(hw, TXGBE_ISBADDRH, hw->isb_dma >> 32);
2093
2094         value = rd32_epcs(hw, SR_XS_PCS_CTRL2);
2095         if ((value & 0x3) != SR_PCS_CTRL2_TYPE_SEL_X)
2096                 hw->link_status = TXGBE_LINK_STATUS_NONE;
2097
2098         /* receive packets that size > 2048 */
2099         wr32m(hw, TXGBE_MACRXCFG,
2100                 TXGBE_MACRXCFG_JUMBO, TXGBE_MACRXCFG_JUMBO);
2101
2102         wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
2103                 TXGBE_FRMSZ_MAX(TXGBE_FRAME_SIZE_DFT));
2104
2105         /* clear counters on read */
2106         wr32m(hw, TXGBE_MACCNTCTL,
2107                 TXGBE_MACCNTCTL_RC, TXGBE_MACCNTCTL_RC);
2108
2109         wr32m(hw, TXGBE_RXFCCFG,
2110                 TXGBE_RXFCCFG_FC, TXGBE_RXFCCFG_FC);
2111         wr32m(hw, TXGBE_TXFCCFG,
2112                 TXGBE_TXFCCFG_FC, TXGBE_TXFCCFG_FC);
2113
2114         wr32m(hw, TXGBE_MACRXFLT,
2115                 TXGBE_MACRXFLT_PROMISC, TXGBE_MACRXFLT_PROMISC);
2116
2117         wr32m(hw, TXGBE_RSTSTAT,
2118                 TXGBE_RSTSTAT_TMRINIT_MASK, TXGBE_RSTSTAT_TMRINIT(30));
2119
2120         /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
2121         wr32(hw, TXGBE_MNGFLEXSEL, 0);
2122         for (i = 0; i < 16; i++) {
2123                 wr32(hw, TXGBE_MNGFLEXDWL(i), 0);
2124                 wr32(hw, TXGBE_MNGFLEXDWH(i), 0);
2125                 wr32(hw, TXGBE_MNGFLEXMSK(i), 0);
2126         }
2127         wr32(hw, TXGBE_LANFLEXSEL, 0);
2128         for (i = 0; i < 16; i++) {
2129                 wr32(hw, TXGBE_LANFLEXDWL(i), 0);
2130                 wr32(hw, TXGBE_LANFLEXDWH(i), 0);
2131                 wr32(hw, TXGBE_LANFLEXMSK(i), 0);
2132         }
2133
2134         /* set pause frame dst mac addr */
2135         wr32(hw, TXGBE_RXPBPFCDMACL, 0xC2000001);
2136         wr32(hw, TXGBE_RXPBPFCDMACH, 0x0180);
2137
2138         hw->mac.init_thermal_sensor_thresh(hw);
2139
2140         /* enable mac transmitter */
2141         wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE, TXGBE_MACTXCFG_TXE);
2142
2143         for (i = 0; i < 4; i++)
2144                 wr32m(hw, TXGBE_IVAR(i), 0x80808080, 0);
2145 }
2146
2147 /**
2148  *  txgbe_reset_hw - Perform hardware reset
2149  *  @hw: pointer to hardware structure
2150  *
2151  *  Resets the hardware by resetting the transmit and receive units, masks
2152  *  and clears all interrupts, perform a PHY reset, and perform a link (MAC)
2153  *  reset.
2154  **/
2155 s32 txgbe_reset_hw(struct txgbe_hw *hw)
2156 {
2157         s32 status;
2158         u32 autoc;
2159
2160         DEBUGFUNC("txgbe_reset_hw");
2161
2162         /* Call adapter stop to disable tx/rx and clear interrupts */
2163         status = hw->mac.stop_hw(hw);
2164         if (status != 0)
2165                 return status;
2166
2167         /* flush pending Tx transactions */
2168         txgbe_clear_tx_pending(hw);
2169
2170         /* Identify PHY and related function pointers */
2171         status = hw->phy.init(hw);
2172         if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
2173                 return status;
2174
2175         /* Setup SFP module if there is one present. */
2176         if (hw->phy.sfp_setup_needed) {
2177                 status = hw->mac.setup_sfp(hw);
2178                 hw->phy.sfp_setup_needed = false;
2179         }
2180         if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
2181                 return status;
2182
2183         /* Reset PHY */
2184         if (!hw->phy.reset_disable)
2185                 hw->phy.reset(hw);
2186
2187         /* remember AUTOC from before we reset */
2188         autoc = hw->mac.autoc_read(hw);
2189
2190 mac_reset_top:
2191         /*
2192          * Issue global reset to the MAC.  Needs to be SW reset if link is up.
2193          * If link reset is used when link is up, it might reset the PHY when
2194          * mng is using it.  If link is down or the flag to force full link
2195          * reset is set, then perform link reset.
2196          */
2197         if (txgbe_mng_present(hw)) {
2198                 txgbe_hic_reset(hw);
2199         } else {
2200                 wr32(hw, TXGBE_RST, TXGBE_RST_LAN(hw->bus.lan_id));
2201                 txgbe_flush(hw);
2202         }
2203         usec_delay(10);
2204
2205         txgbe_reset_misc(hw);
2206
2207         if (hw->bus.lan_id == 0) {
2208                 status = txgbe_check_flash_load(hw,
2209                                 TXGBE_ILDRSTAT_SWRST_LAN0);
2210         } else {
2211                 status = txgbe_check_flash_load(hw,
2212                                 TXGBE_ILDRSTAT_SWRST_LAN1);
2213         }
2214         if (status != 0)
2215                 return status;
2216
2217         msec_delay(50);
2218
2219         /*
2220          * Double resets are required for recovery from certain error
2221          * conditions.  Between resets, it is necessary to stall to
2222          * allow time for any pending HW events to complete.
2223          */
2224         if (hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
2225                 hw->mac.flags &= ~TXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2226                 goto mac_reset_top;
2227         }
2228
2229         /*
2230          * Store the original AUTOC/AUTOC2 values if they have not been
2231          * stored off yet.  Otherwise restore the stored original
2232          * values since the reset operation sets back to defaults.
2233          */
2234         if (!hw->mac.orig_link_settings_stored) {
2235                 hw->mac.orig_autoc = hw->mac.autoc_read(hw);
2236                 hw->mac.autoc_write(hw, hw->mac.orig_autoc);
2237                 hw->mac.orig_link_settings_stored = true;
2238         } else {
2239                 hw->mac.orig_autoc = autoc;
2240         }
2241
2242         /* Store the permanent mac address */
2243         hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
2244
2245         /*
2246          * Store MAC address from RAR0, clear receive address registers, and
2247          * clear the multicast table.  Also reset num_rar_entries to 128,
2248          * since we modify this value when programming the SAN MAC address.
2249          */
2250         hw->mac.num_rar_entries = 128;
2251         hw->mac.init_rx_addrs(hw);
2252
2253         /* Store the permanent SAN mac address */
2254         hw->mac.get_san_mac_addr(hw, hw->mac.san_addr);
2255
2256         /* Add the SAN MAC address to the RAR only if it's a valid address */
2257         if (txgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
2258                 /* Save the SAN MAC RAR index */
2259                 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
2260
2261                 hw->mac.set_rar(hw, hw->mac.san_mac_rar_index,
2262                                     hw->mac.san_addr, 0, true);
2263
2264                 /* clear VMDq pool/queue selection for this RAR */
2265                 hw->mac.clear_vmdq(hw, hw->mac.san_mac_rar_index,
2266                                        BIT_MASK32);
2267
2268                 /* Reserve the last RAR for the SAN MAC address */
2269                 hw->mac.num_rar_entries--;
2270         }
2271
2272         /* Store the alternative WWNN/WWPN prefix */
2273         hw->mac.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
2274                                    &hw->mac.wwpn_prefix);
2275
2276         return status;
2277 }
2278
2279 /**
2280  *  txgbe_start_hw_raptor - Prepare hardware for Tx/Rx
2281  *  @hw: pointer to hardware structure
2282  *
2283  *  Starts the hardware using the generic start_hw function
2284  *  and the generation start_hw function.
2285  *  Then performs revision-specific operations, if any.
2286  **/
2287 s32 txgbe_start_hw_raptor(struct txgbe_hw *hw)
2288 {
2289         s32 err = 0;
2290
2291         DEBUGFUNC("txgbe_start_hw_raptor");
2292
2293         err = txgbe_start_hw(hw);
2294         if (err != 0)
2295                 goto out;
2296
2297         err = txgbe_start_hw_gen2(hw);
2298         if (err != 0)
2299                 goto out;
2300
2301         /* We need to run link autotry after the driver loads */
2302         hw->mac.autotry_restart = true;
2303
2304 out:
2305         return err;
2306 }
2307
2308 /**
2309  *  txgbe_enable_rx_dma_raptor - Enable the Rx DMA unit
2310  *  @hw: pointer to hardware structure
2311  *  @regval: register value to write to RXCTRL
2312  *
2313  *  Enables the Rx DMA unit
2314  **/
2315 s32 txgbe_enable_rx_dma_raptor(struct txgbe_hw *hw, u32 regval)
2316 {
2317         DEBUGFUNC("txgbe_enable_rx_dma_raptor");
2318
2319         /*
2320          * Workaround silicon errata when enabling the Rx datapath.
2321          * If traffic is incoming before we enable the Rx unit, it could hang
2322          * the Rx DMA unit.  Therefore, make sure the security engine is
2323          * completely disabled prior to enabling the Rx unit.
2324          */
2325
2326         hw->mac.disable_sec_rx_path(hw);
2327
2328         if (regval & TXGBE_PBRXCTL_ENA)
2329                 txgbe_enable_rx(hw);
2330         else
2331                 txgbe_disable_rx(hw);
2332
2333         hw->mac.enable_sec_rx_path(hw);
2334
2335         return 0;
2336 }
2337
2338 /**
2339  *  txgbe_verify_lesm_fw_enabled_raptor - Checks LESM FW module state.
2340  *  @hw: pointer to hardware structure
2341  *
2342  *  Returns true if the LESM FW module is present and enabled. Otherwise
2343  *  returns false. Smart Speed must be disabled if LESM FW module is enabled.
2344  **/
2345 bool txgbe_verify_lesm_fw_enabled_raptor(struct txgbe_hw *hw)
2346 {
2347         bool lesm_enabled = false;
2348         u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
2349         s32 status;
2350
2351         DEBUGFUNC("txgbe_verify_lesm_fw_enabled_raptor");
2352
2353         /* get the offset to the Firmware Module block */
2354         status = hw->rom.read16(hw, TXGBE_FW_PTR, &fw_offset);
2355
2356         if (status != 0 || fw_offset == 0 || fw_offset == 0xFFFF)
2357                 goto out;
2358
2359         /* get the offset to the LESM Parameters block */
2360         status = hw->rom.read16(hw, (fw_offset +
2361                                      TXGBE_FW_LESM_PARAMETERS_PTR),
2362                                      &fw_lesm_param_offset);
2363
2364         if (status != 0 ||
2365             fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
2366                 goto out;
2367
2368         /* get the LESM state word */
2369         status = hw->rom.read16(hw, (fw_lesm_param_offset +
2370                                      TXGBE_FW_LESM_STATE_1),
2371                                      &fw_lesm_state);
2372
2373         if (status == 0 && (fw_lesm_state & TXGBE_FW_LESM_STATE_ENABLED))
2374                 lesm_enabled = true;
2375
2376 out:
2377         lesm_enabled = false;
2378         return lesm_enabled;
2379 }
2380
2381 /**
2382  * txgbe_reset_pipeline_raptor - perform pipeline reset
2383  *
2384  *  @hw: pointer to hardware structure
2385  *
2386  * Reset pipeline by asserting Restart_AN together with LMS change to ensure
2387  * full pipeline reset.  This function assumes the SW/FW lock is held.
2388  **/
2389 s32 txgbe_reset_pipeline_raptor(struct txgbe_hw *hw)
2390 {
2391         s32 err = 0;
2392         u64 autoc;
2393
2394         autoc = hw->mac.autoc_read(hw);
2395
2396         /* Enable link if disabled in NVM */
2397         if (autoc & TXGBE_AUTOC_LINK_DIA_MASK)
2398                 autoc &= ~TXGBE_AUTOC_LINK_DIA_MASK;
2399
2400         autoc |= TXGBE_AUTOC_AN_RESTART;
2401         /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
2402         hw->mac.autoc_write(hw, autoc ^ TXGBE_AUTOC_LMS_AN);
2403
2404         /* Write AUTOC register with original LMS field and Restart_AN */
2405         hw->mac.autoc_write(hw, autoc);
2406         txgbe_flush(hw);
2407
2408         return err;
2409 }
2410