]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/qlogic/qlcnic/qlcnic_ethtool.c
18ced0fb6cf05324a8f3869bfd90f1907b377ad2
[karo-tx-linux.git] / drivers / net / ethernet / qlogic / qlcnic / qlcnic_ethtool.c
1 /*
2  * QLogic qlcnic NIC Driver
3  * Copyright (c) 2009-2013 QLogic Corporation
4  *
5  * See LICENSE.qlcnic for copyright and licensing details.
6  */
7
8 #include <linux/types.h>
9 #include <linux/delay.h>
10 #include <linux/pci.h>
11 #include <linux/io.h>
12 #include <linux/netdevice.h>
13 #include <linux/ethtool.h>
14
15 #include "qlcnic.h"
16
17 struct qlcnic_stats {
18         char stat_string[ETH_GSTRING_LEN];
19         int sizeof_stat;
20         int stat_offset;
21 };
22
23 #define QLC_SIZEOF(m) FIELD_SIZEOF(struct qlcnic_adapter, m)
24 #define QLC_OFF(m) offsetof(struct qlcnic_adapter, m)
25 static const u32 qlcnic_fw_dump_level[] = {
26         0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff
27 };
28
29 static const struct qlcnic_stats qlcnic_gstrings_stats[] = {
30         {"xmit_on", QLC_SIZEOF(stats.xmit_on), QLC_OFF(stats.xmit_on)},
31         {"xmit_off", QLC_SIZEOF(stats.xmit_off), QLC_OFF(stats.xmit_off)},
32         {"xmit_called", QLC_SIZEOF(stats.xmitcalled),
33          QLC_OFF(stats.xmitcalled)},
34         {"xmit_finished", QLC_SIZEOF(stats.xmitfinished),
35          QLC_OFF(stats.xmitfinished)},
36         {"tx dma map error", QLC_SIZEOF(stats.tx_dma_map_error),
37          QLC_OFF(stats.tx_dma_map_error)},
38         {"tx_bytes", QLC_SIZEOF(stats.txbytes), QLC_OFF(stats.txbytes)},
39         {"tx_dropped", QLC_SIZEOF(stats.txdropped), QLC_OFF(stats.txdropped)},
40         {"rx dma map error", QLC_SIZEOF(stats.rx_dma_map_error),
41          QLC_OFF(stats.rx_dma_map_error)},
42         {"rx_pkts", QLC_SIZEOF(stats.rx_pkts), QLC_OFF(stats.rx_pkts)},
43         {"rx_bytes", QLC_SIZEOF(stats.rxbytes), QLC_OFF(stats.rxbytes)},
44         {"rx_dropped", QLC_SIZEOF(stats.rxdropped), QLC_OFF(stats.rxdropped)},
45         {"null rxbuf", QLC_SIZEOF(stats.null_rxbuf), QLC_OFF(stats.null_rxbuf)},
46         {"csummed", QLC_SIZEOF(stats.csummed), QLC_OFF(stats.csummed)},
47         {"lro_pkts", QLC_SIZEOF(stats.lro_pkts), QLC_OFF(stats.lro_pkts)},
48         {"lrobytes", QLC_SIZEOF(stats.lrobytes), QLC_OFF(stats.lrobytes)},
49         {"lso_frames", QLC_SIZEOF(stats.lso_frames), QLC_OFF(stats.lso_frames)},
50         {"skb_alloc_failure", QLC_SIZEOF(stats.skb_alloc_failure),
51          QLC_OFF(stats.skb_alloc_failure)},
52         {"mac_filter_limit_overrun", QLC_SIZEOF(stats.mac_filter_limit_overrun),
53          QLC_OFF(stats.mac_filter_limit_overrun)},
54         {"spurious intr", QLC_SIZEOF(stats.spurious_intr),
55          QLC_OFF(stats.spurious_intr)},
56
57 };
58
59 static const char qlcnic_device_gstrings_stats[][ETH_GSTRING_LEN] = {
60         "tx unicast frames",
61         "tx multicast frames",
62         "tx broadcast frames",
63         "tx dropped frames",
64         "tx errors",
65         "tx local frames",
66         "tx numbytes",
67         "rx unicast frames",
68         "rx multicast frames",
69         "rx broadcast frames",
70         "rx dropped frames",
71         "rx errors",
72         "rx local frames",
73         "rx numbytes",
74 };
75
76 static const char qlcnic_83xx_tx_stats_strings[][ETH_GSTRING_LEN] = {
77         "ctx_tx_bytes",
78         "ctx_tx_pkts",
79         "ctx_tx_errors",
80         "ctx_tx_dropped_pkts",
81         "ctx_tx_num_buffers",
82 };
83
84 static const char qlcnic_83xx_mac_stats_strings[][ETH_GSTRING_LEN] = {
85         "mac_tx_frames",
86         "mac_tx_bytes",
87         "mac_tx_mcast_pkts",
88         "mac_tx_bcast_pkts",
89         "mac_tx_pause_cnt",
90         "mac_tx_ctrl_pkt",
91         "mac_tx_lt_64b_pkts",
92         "mac_tx_lt_127b_pkts",
93         "mac_tx_lt_255b_pkts",
94         "mac_tx_lt_511b_pkts",
95         "mac_tx_lt_1023b_pkts",
96         "mac_tx_lt_1518b_pkts",
97         "mac_tx_gt_1518b_pkts",
98         "mac_rx_frames",
99         "mac_rx_bytes",
100         "mac_rx_mcast_pkts",
101         "mac_rx_bcast_pkts",
102         "mac_rx_pause_cnt",
103         "mac_rx_ctrl_pkt",
104         "mac_rx_lt_64b_pkts",
105         "mac_rx_lt_127b_pkts",
106         "mac_rx_lt_255b_pkts",
107         "mac_rx_lt_511b_pkts",
108         "mac_rx_lt_1023b_pkts",
109         "mac_rx_lt_1518b_pkts",
110         "mac_rx_gt_1518b_pkts",
111         "mac_rx_length_error",
112         "mac_rx_length_small",
113         "mac_rx_length_large",
114         "mac_rx_jabber",
115         "mac_rx_dropped",
116         "mac_crc_error",
117         "mac_align_error",
118         "eswitch_frames",
119         "eswitch_bytes",
120         "eswitch_multicast_frames",
121         "eswitch_broadcast_frames",
122         "eswitch_unicast_frames",
123         "eswitch_error_free_frames",
124         "eswitch_error_free_bytes",
125 };
126
127 #define QLCNIC_STATS_LEN        ARRAY_SIZE(qlcnic_gstrings_stats)
128
129 static const char qlcnic_tx_queue_stats_strings[][ETH_GSTRING_LEN] = {
130         "xmit_on",
131         "xmit_off",
132         "xmit_called",
133         "xmit_finished",
134         "tx_bytes",
135 };
136
137 #define QLCNIC_TX_STATS_LEN     ARRAY_SIZE(qlcnic_tx_queue_stats_strings)
138
139 static const char qlcnic_83xx_rx_stats_strings[][ETH_GSTRING_LEN] = {
140         "ctx_rx_bytes",
141         "ctx_rx_pkts",
142         "ctx_lro_pkt_cnt",
143         "ctx_ip_csum_error",
144         "ctx_rx_pkts_wo_ctx",
145         "ctx_rx_pkts_drop_wo_sds_on_card",
146         "ctx_rx_pkts_drop_wo_sds_on_host",
147         "ctx_rx_osized_pkts",
148         "ctx_rx_pkts_dropped_wo_rds",
149         "ctx_rx_unexpected_mcast_pkts",
150         "ctx_invalid_mac_address",
151         "ctx_rx_rds_ring_prim_attempted",
152         "ctx_rx_rds_ring_prim_success",
153         "ctx_num_lro_flows_added",
154         "ctx_num_lro_flows_removed",
155         "ctx_num_lro_flows_active",
156         "ctx_pkts_dropped_unknown",
157 };
158
159 static const char qlcnic_gstrings_test[][ETH_GSTRING_LEN] = {
160         "Register_Test_on_offline",
161         "Link_Test_on_offline",
162         "Interrupt_Test_offline",
163         "Internal_Loopback_offline",
164         "External_Loopback_offline",
165         "EEPROM_Test_offline"
166 };
167
168 #define QLCNIC_TEST_LEN ARRAY_SIZE(qlcnic_gstrings_test)
169
170 static inline int qlcnic_82xx_statistics(struct qlcnic_adapter *adapter)
171 {
172         return ARRAY_SIZE(qlcnic_gstrings_stats) +
173                ARRAY_SIZE(qlcnic_83xx_mac_stats_strings) +
174                QLCNIC_TX_STATS_LEN * adapter->drv_tx_rings;
175 }
176
177 static inline int qlcnic_83xx_statistics(struct qlcnic_adapter *adapter)
178 {
179         return ARRAY_SIZE(qlcnic_gstrings_stats) +
180                ARRAY_SIZE(qlcnic_83xx_tx_stats_strings) +
181                ARRAY_SIZE(qlcnic_83xx_mac_stats_strings) +
182                ARRAY_SIZE(qlcnic_83xx_rx_stats_strings) +
183                QLCNIC_TX_STATS_LEN * adapter->drv_tx_rings;
184 }
185
186 static int qlcnic_dev_statistics_len(struct qlcnic_adapter *adapter)
187 {
188         int len = -1;
189
190         if (qlcnic_82xx_check(adapter)) {
191                 len = qlcnic_82xx_statistics(adapter);
192                 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
193                         len += ARRAY_SIZE(qlcnic_device_gstrings_stats);
194         } else if (qlcnic_83xx_check(adapter)) {
195                 len = qlcnic_83xx_statistics(adapter);
196         }
197
198         return len;
199 }
200
201 #define QLCNIC_TX_INTR_NOT_CONFIGURED   0X78563412
202
203 #define QLCNIC_MAX_EEPROM_LEN   1024
204
205 static const u32 diag_registers[] = {
206         QLCNIC_CMDPEG_STATE,
207         QLCNIC_RCVPEG_STATE,
208         QLCNIC_FW_CAPABILITIES,
209         QLCNIC_CRB_DRV_ACTIVE,
210         QLCNIC_CRB_DEV_STATE,
211         QLCNIC_CRB_DRV_STATE,
212         QLCNIC_CRB_DRV_SCRATCH,
213         QLCNIC_CRB_DEV_PARTITION_INFO,
214         QLCNIC_CRB_DRV_IDC_VER,
215         QLCNIC_PEG_ALIVE_COUNTER,
216         QLCNIC_PEG_HALT_STATUS1,
217         QLCNIC_PEG_HALT_STATUS2,
218         -1
219 };
220
221
222 static const u32 ext_diag_registers[] = {
223         CRB_XG_STATE_P3P,
224         ISR_INT_STATE_REG,
225         QLCNIC_CRB_PEG_NET_0+0x3c,
226         QLCNIC_CRB_PEG_NET_1+0x3c,
227         QLCNIC_CRB_PEG_NET_2+0x3c,
228         QLCNIC_CRB_PEG_NET_4+0x3c,
229         -1
230 };
231
232 #define QLCNIC_MGMT_API_VERSION 3
233 #define QLCNIC_ETHTOOL_REGS_VER 4
234
235 static inline int qlcnic_get_ring_regs_len(struct qlcnic_adapter *adapter)
236 {
237         int ring_regs_cnt = (adapter->drv_tx_rings * 5) +
238                             (adapter->max_rds_rings * 2) +
239                             (adapter->drv_sds_rings * 3) + 5;
240         return ring_regs_cnt * sizeof(u32);
241 }
242
243 static int qlcnic_get_regs_len(struct net_device *dev)
244 {
245         struct qlcnic_adapter *adapter = netdev_priv(dev);
246         u32 len;
247
248         if (qlcnic_83xx_check(adapter))
249                 len = qlcnic_83xx_get_regs_len(adapter);
250         else
251                 len = sizeof(ext_diag_registers) + sizeof(diag_registers);
252
253         len += ((QLCNIC_DEV_INFO_SIZE + 2) * sizeof(u32));
254         len += qlcnic_get_ring_regs_len(adapter);
255         return len;
256 }
257
258 static int qlcnic_get_eeprom_len(struct net_device *dev)
259 {
260         return QLCNIC_FLASH_TOTAL_SIZE;
261 }
262
263 static void
264 qlcnic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
265 {
266         struct qlcnic_adapter *adapter = netdev_priv(dev);
267         u32 fw_major, fw_minor, fw_build;
268         fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
269         fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
270         fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
271         snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
272                 "%d.%d.%d", fw_major, fw_minor, fw_build);
273
274         strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
275                 sizeof(drvinfo->bus_info));
276         strlcpy(drvinfo->driver, qlcnic_driver_name, sizeof(drvinfo->driver));
277         strlcpy(drvinfo->version, QLCNIC_LINUX_VERSIONID,
278                 sizeof(drvinfo->version));
279 }
280
281 static int
282 qlcnic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
283 {
284         struct qlcnic_adapter *adapter = netdev_priv(dev);
285
286         if (qlcnic_82xx_check(adapter))
287                 return qlcnic_82xx_get_settings(adapter, ecmd);
288         else if (qlcnic_83xx_check(adapter))
289                 return qlcnic_83xx_get_settings(adapter, ecmd);
290
291         return -EIO;
292 }
293
294 int qlcnic_82xx_get_settings(struct qlcnic_adapter *adapter,
295                              struct ethtool_cmd *ecmd)
296 {
297         struct qlcnic_hardware_context *ahw = adapter->ahw;
298         u32 speed, reg;
299         int check_sfp_module = 0, err = 0;
300         u16 pcifn = ahw->pci_func;
301
302         /* read which mode */
303         if (adapter->ahw->port_type == QLCNIC_GBE) {
304                 ecmd->supported = (SUPPORTED_10baseT_Half |
305                                    SUPPORTED_10baseT_Full |
306                                    SUPPORTED_100baseT_Half |
307                                    SUPPORTED_100baseT_Full |
308                                    SUPPORTED_1000baseT_Half |
309                                    SUPPORTED_1000baseT_Full);
310
311                 ecmd->advertising = (ADVERTISED_100baseT_Half |
312                                      ADVERTISED_100baseT_Full |
313                                      ADVERTISED_1000baseT_Half |
314                                      ADVERTISED_1000baseT_Full);
315
316                 ethtool_cmd_speed_set(ecmd, adapter->ahw->link_speed);
317                 ecmd->duplex = adapter->ahw->link_duplex;
318                 ecmd->autoneg = adapter->ahw->link_autoneg;
319
320         } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
321                 u32 val = 0;
322                 val = QLCRD32(adapter, QLCNIC_PORT_MODE_ADDR, &err);
323
324                 if (val == QLCNIC_PORT_MODE_802_3_AP) {
325                         ecmd->supported = SUPPORTED_1000baseT_Full;
326                         ecmd->advertising = ADVERTISED_1000baseT_Full;
327                 } else {
328                         ecmd->supported = SUPPORTED_10000baseT_Full;
329                         ecmd->advertising = ADVERTISED_10000baseT_Full;
330                 }
331
332                 if (netif_running(adapter->netdev) && ahw->has_link_events) {
333                         if (ahw->linkup) {
334                                 reg = QLCRD32(adapter,
335                                               P3P_LINK_SPEED_REG(pcifn), &err);
336                                 speed = P3P_LINK_SPEED_VAL(pcifn, reg);
337                                 ahw->link_speed = speed * P3P_LINK_SPEED_MHZ;
338                         }
339
340                         ethtool_cmd_speed_set(ecmd, ahw->link_speed);
341                         ecmd->autoneg = ahw->link_autoneg;
342                         ecmd->duplex = ahw->link_duplex;
343                         goto skip;
344                 }
345
346                 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
347                 ecmd->duplex = DUPLEX_UNKNOWN;
348                 ecmd->autoneg = AUTONEG_DISABLE;
349         } else
350                 return -EIO;
351
352 skip:
353         ecmd->phy_address = adapter->ahw->physical_port;
354         ecmd->transceiver = XCVR_EXTERNAL;
355
356         switch (adapter->ahw->board_type) {
357         case QLCNIC_BRDTYPE_P3P_REF_QG:
358         case QLCNIC_BRDTYPE_P3P_4_GB:
359         case QLCNIC_BRDTYPE_P3P_4_GB_MM:
360
361                 ecmd->supported |= SUPPORTED_Autoneg;
362                 ecmd->advertising |= ADVERTISED_Autoneg;
363         case QLCNIC_BRDTYPE_P3P_10G_CX4:
364         case QLCNIC_BRDTYPE_P3P_10G_CX4_LP:
365         case QLCNIC_BRDTYPE_P3P_10000_BASE_T:
366                 ecmd->supported |= SUPPORTED_TP;
367                 ecmd->advertising |= ADVERTISED_TP;
368                 ecmd->port = PORT_TP;
369                 ecmd->autoneg =  adapter->ahw->link_autoneg;
370                 break;
371         case QLCNIC_BRDTYPE_P3P_IMEZ:
372         case QLCNIC_BRDTYPE_P3P_XG_LOM:
373         case QLCNIC_BRDTYPE_P3P_HMEZ:
374                 ecmd->supported |= SUPPORTED_MII;
375                 ecmd->advertising |= ADVERTISED_MII;
376                 ecmd->port = PORT_MII;
377                 ecmd->autoneg = AUTONEG_DISABLE;
378                 break;
379         case QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS:
380         case QLCNIC_BRDTYPE_P3P_10G_SFP_CT:
381         case QLCNIC_BRDTYPE_P3P_10G_SFP_QT:
382                 ecmd->advertising |= ADVERTISED_TP;
383                 ecmd->supported |= SUPPORTED_TP;
384                 check_sfp_module = netif_running(adapter->netdev) &&
385                                    ahw->has_link_events;
386         case QLCNIC_BRDTYPE_P3P_10G_XFP:
387                 ecmd->supported |= SUPPORTED_FIBRE;
388                 ecmd->advertising |= ADVERTISED_FIBRE;
389                 ecmd->port = PORT_FIBRE;
390                 ecmd->autoneg = AUTONEG_DISABLE;
391                 break;
392         case QLCNIC_BRDTYPE_P3P_10G_TP:
393                 if (adapter->ahw->port_type == QLCNIC_XGBE) {
394                         ecmd->autoneg = AUTONEG_DISABLE;
395                         ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
396                         ecmd->advertising |=
397                                 (ADVERTISED_FIBRE | ADVERTISED_TP);
398                         ecmd->port = PORT_FIBRE;
399                         check_sfp_module = netif_running(adapter->netdev) &&
400                                            ahw->has_link_events;
401                 } else {
402                         ecmd->autoneg = AUTONEG_ENABLE;
403                         ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
404                         ecmd->advertising |=
405                                 (ADVERTISED_TP | ADVERTISED_Autoneg);
406                         ecmd->port = PORT_TP;
407                 }
408                 break;
409         default:
410                 dev_err(&adapter->pdev->dev, "Unsupported board model %d\n",
411                         adapter->ahw->board_type);
412                 return -EIO;
413         }
414
415         if (check_sfp_module) {
416                 switch (adapter->ahw->module_type) {
417                 case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
418                 case LINKEVENT_MODULE_OPTICAL_SRLR:
419                 case LINKEVENT_MODULE_OPTICAL_LRM:
420                 case LINKEVENT_MODULE_OPTICAL_SFP_1G:
421                         ecmd->port = PORT_FIBRE;
422                         break;
423                 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
424                 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
425                 case LINKEVENT_MODULE_TWINAX:
426                         ecmd->port = PORT_TP;
427                         break;
428                 default:
429                         ecmd->port = PORT_OTHER;
430                 }
431         }
432
433         return 0;
434 }
435
436 static int qlcnic_set_port_config(struct qlcnic_adapter *adapter,
437                                   struct ethtool_cmd *ecmd)
438 {
439         u32 ret = 0, config = 0;
440         /* read which mode */
441         if (ecmd->duplex)
442                 config |= 0x1;
443
444         if (ecmd->autoneg)
445                 config |= 0x2;
446
447         switch (ethtool_cmd_speed(ecmd)) {
448         case SPEED_10:
449                 config |= (0 << 8);
450                 break;
451         case SPEED_100:
452                 config |= (1 << 8);
453                 break;
454         case SPEED_1000:
455                 config |= (10 << 8);
456                 break;
457         default:
458                 return -EIO;
459         }
460
461         ret = qlcnic_fw_cmd_set_port(adapter, config);
462
463         if (ret == QLCNIC_RCODE_NOT_SUPPORTED)
464                 return -EOPNOTSUPP;
465         else if (ret)
466                 return -EIO;
467         return ret;
468 }
469
470 static int qlcnic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
471 {
472         u32 ret = 0;
473         struct qlcnic_adapter *adapter = netdev_priv(dev);
474
475         if (adapter->ahw->port_type != QLCNIC_GBE)
476                 return -EOPNOTSUPP;
477
478         if (qlcnic_83xx_check(adapter))
479                 ret = qlcnic_83xx_set_settings(adapter, ecmd);
480         else
481                 ret = qlcnic_set_port_config(adapter, ecmd);
482
483         if (!ret)
484                 return ret;
485
486         adapter->ahw->link_speed = ethtool_cmd_speed(ecmd);
487         adapter->ahw->link_duplex = ecmd->duplex;
488         adapter->ahw->link_autoneg = ecmd->autoneg;
489
490         if (!netif_running(dev))
491                 return 0;
492
493         dev->netdev_ops->ndo_stop(dev);
494         return dev->netdev_ops->ndo_open(dev);
495 }
496
497 static int qlcnic_82xx_get_registers(struct qlcnic_adapter *adapter,
498                                      u32 *regs_buff)
499 {
500         int i, j = 0, err = 0;
501
502         for (i = QLCNIC_DEV_INFO_SIZE + 1; diag_registers[j] != -1; j++, i++)
503                 regs_buff[i] = QLC_SHARED_REG_RD32(adapter, diag_registers[j]);
504         j = 0;
505         while (ext_diag_registers[j] != -1)
506                 regs_buff[i++] = QLCRD32(adapter, ext_diag_registers[j++],
507                                          &err);
508         return i;
509 }
510
511 static void
512 qlcnic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
513 {
514         struct qlcnic_adapter *adapter = netdev_priv(dev);
515         struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
516         struct qlcnic_host_sds_ring *sds_ring;
517         struct qlcnic_host_rds_ring *rds_rings;
518         struct qlcnic_host_tx_ring *tx_ring;
519         u32 *regs_buff = p;
520         int ring, i = 0;
521
522         memset(p, 0, qlcnic_get_regs_len(dev));
523
524         regs->version = (QLCNIC_ETHTOOL_REGS_VER << 24) |
525                 (adapter->ahw->revision_id << 16) | (adapter->pdev)->device;
526
527         regs_buff[0] = (0xcafe0000 | (QLCNIC_DEV_INFO_SIZE & 0xffff));
528         regs_buff[1] = QLCNIC_MGMT_API_VERSION;
529
530         if (adapter->ahw->capabilities & QLC_83XX_ESWITCH_CAPABILITY)
531                 regs_buff[2] = adapter->ahw->max_vnic_func;
532
533         if (qlcnic_82xx_check(adapter))
534                 i = qlcnic_82xx_get_registers(adapter, regs_buff);
535         else
536                 i = qlcnic_83xx_get_registers(adapter, regs_buff);
537
538         if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
539                 return;
540
541         /* Marker btw regs and TX ring count */
542         regs_buff[i++] = 0xFFEFCDAB;
543
544         regs_buff[i++] = adapter->drv_tx_rings; /* No. of TX ring */
545         for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
546                 tx_ring = &adapter->tx_ring[ring];
547                 regs_buff[i++] = le32_to_cpu(*(tx_ring->hw_consumer));
548                 regs_buff[i++] = tx_ring->sw_consumer;
549                 regs_buff[i++] = readl(tx_ring->crb_cmd_producer);
550                 regs_buff[i++] = tx_ring->producer;
551                 if (tx_ring->crb_intr_mask)
552                         regs_buff[i++] = readl(tx_ring->crb_intr_mask);
553                 else
554                         regs_buff[i++] = QLCNIC_TX_INTR_NOT_CONFIGURED;
555         }
556
557         regs_buff[i++] = adapter->max_rds_rings; /* No. of RX ring */
558         for (ring = 0; ring < adapter->max_rds_rings; ring++) {
559                 rds_rings = &recv_ctx->rds_rings[ring];
560                 regs_buff[i++] = readl(rds_rings->crb_rcv_producer);
561                 regs_buff[i++] = rds_rings->producer;
562         }
563
564         regs_buff[i++] = adapter->drv_sds_rings; /* No. of SDS ring */
565         for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
566                 sds_ring = &(recv_ctx->sds_rings[ring]);
567                 regs_buff[i++] = readl(sds_ring->crb_sts_consumer);
568                 regs_buff[i++] = sds_ring->consumer;
569                 regs_buff[i++] = readl(sds_ring->crb_intr_mask);
570         }
571 }
572
573 static u32 qlcnic_test_link(struct net_device *dev)
574 {
575         struct qlcnic_adapter *adapter = netdev_priv(dev);
576         int err = 0;
577         u32 val;
578
579         if (qlcnic_83xx_check(adapter)) {
580                 val = qlcnic_83xx_test_link(adapter);
581                 return (val & 1) ? 0 : 1;
582         }
583         val = QLCRD32(adapter, CRB_XG_STATE_P3P, &err);
584         if (err == -EIO)
585                 return err;
586         val = XG_LINK_STATE_P3P(adapter->ahw->pci_func, val);
587         return (val == XG_LINK_UP_P3P) ? 0 : 1;
588 }
589
590 static int
591 qlcnic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
592                       u8 *bytes)
593 {
594         struct qlcnic_adapter *adapter = netdev_priv(dev);
595         int offset;
596         int ret = -1;
597
598         if (qlcnic_83xx_check(adapter))
599                 return 0;
600         if (eeprom->len == 0)
601                 return -EINVAL;
602
603         eeprom->magic = (adapter->pdev)->vendor |
604                         ((adapter->pdev)->device << 16);
605         offset = eeprom->offset;
606
607         if (qlcnic_82xx_check(adapter))
608                 ret = qlcnic_rom_fast_read_words(adapter, offset, bytes,
609                                                  eeprom->len);
610         if (ret < 0)
611                 return ret;
612
613         return 0;
614 }
615
616 static void
617 qlcnic_get_ringparam(struct net_device *dev,
618                 struct ethtool_ringparam *ring)
619 {
620         struct qlcnic_adapter *adapter = netdev_priv(dev);
621
622         ring->rx_pending = adapter->num_rxd;
623         ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
624         ring->tx_pending = adapter->num_txd;
625
626         ring->rx_max_pending = adapter->max_rxd;
627         ring->rx_jumbo_max_pending = adapter->max_jumbo_rxd;
628         ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
629 }
630
631 static u32
632 qlcnic_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
633 {
634         u32 num_desc;
635         num_desc = max(val, min);
636         num_desc = min(num_desc, max);
637         num_desc = roundup_pow_of_two(num_desc);
638
639         if (val != num_desc) {
640                 printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
641                        qlcnic_driver_name, r_name, num_desc, val);
642         }
643
644         return num_desc;
645 }
646
647 static int
648 qlcnic_set_ringparam(struct net_device *dev,
649                 struct ethtool_ringparam *ring)
650 {
651         struct qlcnic_adapter *adapter = netdev_priv(dev);
652         u16 num_rxd, num_jumbo_rxd, num_txd;
653
654         if (ring->rx_mini_pending)
655                 return -EOPNOTSUPP;
656
657         num_rxd = qlcnic_validate_ringparam(ring->rx_pending,
658                         MIN_RCV_DESCRIPTORS, adapter->max_rxd, "rx");
659
660         num_jumbo_rxd = qlcnic_validate_ringparam(ring->rx_jumbo_pending,
661                         MIN_JUMBO_DESCRIPTORS, adapter->max_jumbo_rxd,
662                                                 "rx jumbo");
663
664         num_txd = qlcnic_validate_ringparam(ring->tx_pending,
665                         MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
666
667         if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
668                         num_jumbo_rxd == adapter->num_jumbo_rxd)
669                 return 0;
670
671         adapter->num_rxd = num_rxd;
672         adapter->num_jumbo_rxd = num_jumbo_rxd;
673         adapter->num_txd = num_txd;
674
675         return qlcnic_reset_context(adapter);
676 }
677
678 static int qlcnic_validate_ring_count(struct qlcnic_adapter *adapter,
679                                       u8 rx_ring, u8 tx_ring)
680 {
681         if (rx_ring == 0 || tx_ring == 0)
682                 return -EINVAL;
683
684         if (rx_ring != 0) {
685                 if (rx_ring > adapter->max_sds_rings) {
686                         netdev_err(adapter->netdev,
687                                    "Invalid ring count, SDS ring count %d should not be greater than max %d driver sds rings.\n",
688                                    rx_ring, adapter->max_sds_rings);
689                         return -EINVAL;
690                 }
691         }
692
693          if (tx_ring != 0) {
694                 if (tx_ring > adapter->max_tx_rings) {
695                         netdev_err(adapter->netdev,
696                                    "Invalid ring count, Tx ring count %d should not be greater than max %d driver Tx rings.\n",
697                                    tx_ring, adapter->max_tx_rings);
698                         return -EINVAL;
699                 }
700         }
701
702         return 0;
703 }
704
705 static void qlcnic_get_channels(struct net_device *dev,
706                 struct ethtool_channels *channel)
707 {
708         struct qlcnic_adapter *adapter = netdev_priv(dev);
709
710         channel->max_rx = adapter->max_sds_rings;
711         channel->max_tx = adapter->max_tx_rings;
712         channel->rx_count = adapter->drv_sds_rings;
713         channel->tx_count = adapter->drv_tx_rings;
714 }
715
716 static int qlcnic_set_channels(struct net_device *dev,
717                                struct ethtool_channels *channel)
718 {
719         struct qlcnic_adapter *adapter = netdev_priv(dev);
720         int err;
721
722         if (channel->other_count || channel->combined_count)
723                 return -EINVAL;
724
725         err = qlcnic_validate_ring_count(adapter, channel->rx_count,
726                                          channel->tx_count);
727         if (err)
728                 return err;
729
730         if (channel->rx_count) {
731                 err = qlcnic_validate_rings(adapter, channel->rx_count,
732                                             QLCNIC_RX_QUEUE);
733                 if (err) {
734                         netdev_err(dev, "Unable to configure %u SDS rings\n",
735                                    channel->rx_count);
736                         return err;
737                 }
738         }
739
740         if (channel->tx_count) {
741                 err = qlcnic_validate_rings(adapter, channel->tx_count,
742                                             QLCNIC_TX_QUEUE);
743                 if (err) {
744                         netdev_err(dev, "Unable to configure %u Tx rings\n",
745                                    channel->tx_count);
746                         return err;
747                 }
748         }
749
750         err = qlcnic_setup_rings(adapter, channel->rx_count,
751                                  channel->tx_count);
752         netdev_info(dev, "Allocated %d SDS rings and %d Tx rings\n",
753                     adapter->drv_sds_rings, adapter->drv_tx_rings);
754
755         return err;
756 }
757
758 static void
759 qlcnic_get_pauseparam(struct net_device *netdev,
760                           struct ethtool_pauseparam *pause)
761 {
762         struct qlcnic_adapter *adapter = netdev_priv(netdev);
763         int port = adapter->ahw->physical_port;
764         int err = 0;
765         __u32 val;
766
767         if (qlcnic_83xx_check(adapter)) {
768                 qlcnic_83xx_get_pauseparam(adapter, pause);
769                 return;
770         }
771         if (adapter->ahw->port_type == QLCNIC_GBE) {
772                 if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
773                         return;
774                 /* get flow control settings */
775                 val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), &err);
776                 if (err == -EIO)
777                         return;
778                 pause->rx_pause = qlcnic_gb_get_rx_flowctl(val);
779                 val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, &err);
780                 if (err == -EIO)
781                         return;
782                 switch (port) {
783                 case 0:
784                         pause->tx_pause = !(qlcnic_gb_get_gb0_mask(val));
785                         break;
786                 case 1:
787                         pause->tx_pause = !(qlcnic_gb_get_gb1_mask(val));
788                         break;
789                 case 2:
790                         pause->tx_pause = !(qlcnic_gb_get_gb2_mask(val));
791                         break;
792                 case 3:
793                 default:
794                         pause->tx_pause = !(qlcnic_gb_get_gb3_mask(val));
795                         break;
796                 }
797         } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
798                 if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
799                         return;
800                 pause->rx_pause = 1;
801                 val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, &err);
802                 if (err == -EIO)
803                         return;
804                 if (port == 0)
805                         pause->tx_pause = !(qlcnic_xg_get_xg0_mask(val));
806                 else
807                         pause->tx_pause = !(qlcnic_xg_get_xg1_mask(val));
808         } else {
809                 dev_err(&netdev->dev, "Unknown board type: %x\n",
810                                         adapter->ahw->port_type);
811         }
812 }
813
814 static int
815 qlcnic_set_pauseparam(struct net_device *netdev,
816                           struct ethtool_pauseparam *pause)
817 {
818         struct qlcnic_adapter *adapter = netdev_priv(netdev);
819         int port = adapter->ahw->physical_port;
820         int err = 0;
821         __u32 val;
822
823         if (qlcnic_83xx_check(adapter))
824                 return qlcnic_83xx_set_pauseparam(adapter, pause);
825
826         /* read mode */
827         if (adapter->ahw->port_type == QLCNIC_GBE) {
828                 if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
829                         return -EIO;
830                 /* set flow control */
831                 val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), &err);
832                 if (err == -EIO)
833                         return err;
834
835                 if (pause->rx_pause)
836                         qlcnic_gb_rx_flowctl(val);
837                 else
838                         qlcnic_gb_unset_rx_flowctl(val);
839
840                 QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port),
841                                 val);
842                 QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), val);
843                 /* set autoneg */
844                 val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, &err);
845                 if (err == -EIO)
846                         return err;
847                 switch (port) {
848                 case 0:
849                         if (pause->tx_pause)
850                                 qlcnic_gb_unset_gb0_mask(val);
851                         else
852                                 qlcnic_gb_set_gb0_mask(val);
853                         break;
854                 case 1:
855                         if (pause->tx_pause)
856                                 qlcnic_gb_unset_gb1_mask(val);
857                         else
858                                 qlcnic_gb_set_gb1_mask(val);
859                         break;
860                 case 2:
861                         if (pause->tx_pause)
862                                 qlcnic_gb_unset_gb2_mask(val);
863                         else
864                                 qlcnic_gb_set_gb2_mask(val);
865                         break;
866                 case 3:
867                 default:
868                         if (pause->tx_pause)
869                                 qlcnic_gb_unset_gb3_mask(val);
870                         else
871                                 qlcnic_gb_set_gb3_mask(val);
872                         break;
873                 }
874                 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, val);
875         } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
876                 if (!pause->rx_pause || pause->autoneg)
877                         return -EOPNOTSUPP;
878
879                 if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
880                         return -EIO;
881
882                 val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, &err);
883                 if (err == -EIO)
884                         return err;
885                 if (port == 0) {
886                         if (pause->tx_pause)
887                                 qlcnic_xg_unset_xg0_mask(val);
888                         else
889                                 qlcnic_xg_set_xg0_mask(val);
890                 } else {
891                         if (pause->tx_pause)
892                                 qlcnic_xg_unset_xg1_mask(val);
893                         else
894                                 qlcnic_xg_set_xg1_mask(val);
895                 }
896                 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, val);
897         } else {
898                 dev_err(&netdev->dev, "Unknown board type: %x\n",
899                                 adapter->ahw->port_type);
900         }
901         return 0;
902 }
903
904 static int qlcnic_reg_test(struct net_device *dev)
905 {
906         struct qlcnic_adapter *adapter = netdev_priv(dev);
907         u32 data_read;
908         int err = 0;
909
910         if (qlcnic_83xx_check(adapter))
911                 return qlcnic_83xx_reg_test(adapter);
912
913         data_read = QLCRD32(adapter, QLCNIC_PCIX_PH_REG(0), &err);
914         if (err == -EIO)
915                 return err;
916         if ((data_read & 0xffff) != adapter->pdev->vendor)
917                 return 1;
918
919         return 0;
920 }
921
922 static int qlcnic_eeprom_test(struct net_device *dev)
923 {
924         struct qlcnic_adapter *adapter = netdev_priv(dev);
925
926         if (qlcnic_82xx_check(adapter))
927                 return 0;
928
929         return qlcnic_83xx_flash_test(adapter);
930 }
931
932 static int qlcnic_get_sset_count(struct net_device *dev, int sset)
933 {
934
935         struct qlcnic_adapter *adapter = netdev_priv(dev);
936         switch (sset) {
937         case ETH_SS_TEST:
938                 return QLCNIC_TEST_LEN;
939         case ETH_SS_STATS:
940                 return qlcnic_dev_statistics_len(adapter);
941         default:
942                 return -EOPNOTSUPP;
943         }
944 }
945
946 static int qlcnic_irq_test(struct net_device *netdev)
947 {
948         struct qlcnic_adapter *adapter = netdev_priv(netdev);
949         struct qlcnic_hardware_context *ahw = adapter->ahw;
950         struct qlcnic_cmd_args cmd;
951         int ret, drv_sds_rings = adapter->drv_sds_rings;
952         int drv_tx_rings = adapter->drv_tx_rings;
953
954         if (qlcnic_83xx_check(adapter))
955                 return qlcnic_83xx_interrupt_test(netdev);
956
957         if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
958                 return -EIO;
959
960         ret = qlcnic_diag_alloc_res(netdev, QLCNIC_INTERRUPT_TEST);
961         if (ret)
962                 goto clear_diag_irq;
963
964         ahw->diag_cnt = 0;
965         ret = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_INTRPT_TEST);
966         if (ret)
967                 goto free_diag_res;
968
969         cmd.req.arg[1] = ahw->pci_func;
970         ret = qlcnic_issue_cmd(adapter, &cmd);
971         if (ret)
972                 goto done;
973
974         usleep_range(1000, 12000);
975         ret = !ahw->diag_cnt;
976
977 done:
978         qlcnic_free_mbx_args(&cmd);
979
980 free_diag_res:
981         qlcnic_diag_free_res(netdev, drv_sds_rings);
982
983 clear_diag_irq:
984         adapter->drv_sds_rings = drv_sds_rings;
985         adapter->drv_tx_rings = drv_tx_rings;
986         clear_bit(__QLCNIC_RESETTING, &adapter->state);
987
988         return ret;
989 }
990
991 #define QLCNIC_ILB_PKT_SIZE             64
992 #define QLCNIC_NUM_ILB_PKT              16
993 #define QLCNIC_ILB_MAX_RCV_LOOP         10
994 #define QLCNIC_LB_PKT_POLL_DELAY_MSEC   1
995 #define QLCNIC_LB_PKT_POLL_COUNT        20
996
997 static void qlcnic_create_loopback_buff(unsigned char *data, u8 mac[])
998 {
999         unsigned char random_data[] = {0xa8, 0x06, 0x45, 0x00};
1000
1001         memset(data, 0x4e, QLCNIC_ILB_PKT_SIZE);
1002
1003         memcpy(data, mac, ETH_ALEN);
1004         memcpy(data + ETH_ALEN, mac, ETH_ALEN);
1005
1006         memcpy(data + 2 * ETH_ALEN, random_data, sizeof(random_data));
1007 }
1008
1009 int qlcnic_check_loopback_buff(unsigned char *data, u8 mac[])
1010 {
1011         unsigned char buff[QLCNIC_ILB_PKT_SIZE];
1012         qlcnic_create_loopback_buff(buff, mac);
1013         return memcmp(data, buff, QLCNIC_ILB_PKT_SIZE);
1014 }
1015
1016 int qlcnic_do_lb_test(struct qlcnic_adapter *adapter, u8 mode)
1017 {
1018         struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1019         struct qlcnic_host_sds_ring *sds_ring = &recv_ctx->sds_rings[0];
1020         struct sk_buff *skb;
1021         int i, loop, cnt = 0;
1022
1023         for (i = 0; i < QLCNIC_NUM_ILB_PKT; i++) {
1024                 skb = netdev_alloc_skb(adapter->netdev, QLCNIC_ILB_PKT_SIZE);
1025                 qlcnic_create_loopback_buff(skb->data, adapter->mac_addr);
1026                 skb_put(skb, QLCNIC_ILB_PKT_SIZE);
1027                 adapter->ahw->diag_cnt = 0;
1028                 qlcnic_xmit_frame(skb, adapter->netdev);
1029                 loop = 0;
1030
1031                 do {
1032                         msleep(QLCNIC_LB_PKT_POLL_DELAY_MSEC);
1033                         qlcnic_process_rcv_ring_diag(sds_ring);
1034                         if (loop++ > QLCNIC_LB_PKT_POLL_COUNT)
1035                                 break;
1036                 } while (!adapter->ahw->diag_cnt);
1037
1038                 dev_kfree_skb_any(skb);
1039
1040                 if (!adapter->ahw->diag_cnt)
1041                         dev_warn(&adapter->pdev->dev,
1042                                  "LB Test: packet #%d was not received\n",
1043                                  i + 1);
1044                 else
1045                         cnt++;
1046         }
1047         if (cnt != i) {
1048                 dev_err(&adapter->pdev->dev,
1049                         "LB Test: failed, TX[%d], RX[%d]\n", i, cnt);
1050                 if (mode != QLCNIC_ILB_MODE)
1051                         dev_warn(&adapter->pdev->dev,
1052                                  "WARNING: Please check loopback cable\n");
1053                 return -1;
1054         }
1055         return 0;
1056 }
1057
1058 int qlcnic_loopback_test(struct net_device *netdev, u8 mode)
1059 {
1060         struct qlcnic_adapter *adapter = netdev_priv(netdev);
1061         int drv_tx_rings = adapter->drv_tx_rings;
1062         int drv_sds_rings = adapter->drv_sds_rings;
1063         struct qlcnic_host_sds_ring *sds_ring;
1064         struct qlcnic_hardware_context *ahw = adapter->ahw;
1065         int loop = 0;
1066         int ret;
1067
1068         if (qlcnic_83xx_check(adapter))
1069                 return qlcnic_83xx_loopback_test(netdev, mode);
1070
1071         if (!(ahw->capabilities & QLCNIC_FW_CAPABILITY_MULTI_LOOPBACK)) {
1072                 dev_info(&adapter->pdev->dev,
1073                          "Firmware do not support loopback test\n");
1074                 return -EOPNOTSUPP;
1075         }
1076
1077         dev_warn(&adapter->pdev->dev, "%s loopback test in progress\n",
1078                  mode == QLCNIC_ILB_MODE ? "internal" : "external");
1079         if (ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
1080                 dev_warn(&adapter->pdev->dev,
1081                          "Loopback test not supported in nonprivileged mode\n");
1082                 return 0;
1083         }
1084
1085         if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1086                 return -EBUSY;
1087
1088         ret = qlcnic_diag_alloc_res(netdev, QLCNIC_LOOPBACK_TEST);
1089         if (ret)
1090                 goto clear_it;
1091
1092         sds_ring = &adapter->recv_ctx->sds_rings[0];
1093         ret = qlcnic_set_lb_mode(adapter, mode);
1094         if (ret)
1095                 goto free_res;
1096
1097         ahw->diag_cnt = 0;
1098         do {
1099                 msleep(500);
1100                 qlcnic_process_rcv_ring_diag(sds_ring);
1101                 if (loop++ > QLCNIC_ILB_MAX_RCV_LOOP) {
1102                         netdev_info(netdev,
1103                                     "Firmware didn't sent link up event to loopback request\n");
1104                         ret = -ETIMEDOUT;
1105                         goto free_res;
1106                 } else if (adapter->ahw->diag_cnt) {
1107                         ret = adapter->ahw->diag_cnt;
1108                         goto free_res;
1109                 }
1110         } while (!QLCNIC_IS_LB_CONFIGURED(ahw->loopback_state));
1111
1112         ret = qlcnic_do_lb_test(adapter, mode);
1113
1114         qlcnic_clear_lb_mode(adapter, mode);
1115
1116  free_res:
1117         qlcnic_diag_free_res(netdev, drv_sds_rings);
1118
1119  clear_it:
1120         adapter->drv_sds_rings = drv_sds_rings;
1121         adapter->drv_tx_rings = drv_tx_rings;
1122         clear_bit(__QLCNIC_RESETTING, &adapter->state);
1123         return ret;
1124 }
1125
1126 static void
1127 qlcnic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
1128                      u64 *data)
1129 {
1130         memset(data, 0, sizeof(u64) * QLCNIC_TEST_LEN);
1131
1132         data[0] = qlcnic_reg_test(dev);
1133         if (data[0])
1134                 eth_test->flags |= ETH_TEST_FL_FAILED;
1135
1136         data[1] = (u64) qlcnic_test_link(dev);
1137         if (data[1])
1138                 eth_test->flags |= ETH_TEST_FL_FAILED;
1139
1140         if (eth_test->flags & ETH_TEST_FL_OFFLINE) {
1141                 data[2] = qlcnic_irq_test(dev);
1142                 if (data[2])
1143                         eth_test->flags |= ETH_TEST_FL_FAILED;
1144
1145                 data[3] = qlcnic_loopback_test(dev, QLCNIC_ILB_MODE);
1146                 if (data[3])
1147                         eth_test->flags |= ETH_TEST_FL_FAILED;
1148
1149                 if (eth_test->flags & ETH_TEST_FL_EXTERNAL_LB) {
1150                         data[4] = qlcnic_loopback_test(dev, QLCNIC_ELB_MODE);
1151                         if (data[4])
1152                                 eth_test->flags |= ETH_TEST_FL_FAILED;
1153                         eth_test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
1154                 }
1155
1156                 data[5] = qlcnic_eeprom_test(dev);
1157                 if (data[5])
1158                         eth_test->flags |= ETH_TEST_FL_FAILED;
1159         }
1160 }
1161
1162 static void
1163 qlcnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1164 {
1165         struct qlcnic_adapter *adapter = netdev_priv(dev);
1166         int index, i, num_stats;
1167
1168         switch (stringset) {
1169         case ETH_SS_TEST:
1170                 memcpy(data, *qlcnic_gstrings_test,
1171                        QLCNIC_TEST_LEN * ETH_GSTRING_LEN);
1172                 break;
1173         case ETH_SS_STATS:
1174                 num_stats = ARRAY_SIZE(qlcnic_tx_queue_stats_strings);
1175                 for (i = 0; i < adapter->drv_tx_rings; i++) {
1176                         for (index = 0; index < num_stats; index++) {
1177                                 sprintf(data, "tx_queue_%d %s", i,
1178                                         qlcnic_tx_queue_stats_strings[index]);
1179                                 data += ETH_GSTRING_LEN;
1180                         }
1181                 }
1182
1183                 for (index = 0; index < QLCNIC_STATS_LEN; index++) {
1184                         memcpy(data + index * ETH_GSTRING_LEN,
1185                                qlcnic_gstrings_stats[index].stat_string,
1186                                ETH_GSTRING_LEN);
1187                 }
1188
1189                 if (qlcnic_83xx_check(adapter)) {
1190                         num_stats = ARRAY_SIZE(qlcnic_83xx_tx_stats_strings);
1191                         for (i = 0; i < num_stats; i++, index++)
1192                                 memcpy(data + index * ETH_GSTRING_LEN,
1193                                        qlcnic_83xx_tx_stats_strings[i],
1194                                        ETH_GSTRING_LEN);
1195                         num_stats = ARRAY_SIZE(qlcnic_83xx_mac_stats_strings);
1196                         for (i = 0; i < num_stats; i++, index++)
1197                                 memcpy(data + index * ETH_GSTRING_LEN,
1198                                        qlcnic_83xx_mac_stats_strings[i],
1199                                        ETH_GSTRING_LEN);
1200                         num_stats = ARRAY_SIZE(qlcnic_83xx_rx_stats_strings);
1201                         for (i = 0; i < num_stats; i++, index++)
1202                                 memcpy(data + index * ETH_GSTRING_LEN,
1203                                        qlcnic_83xx_rx_stats_strings[i],
1204                                        ETH_GSTRING_LEN);
1205                         return;
1206                 } else {
1207                         num_stats = ARRAY_SIZE(qlcnic_83xx_mac_stats_strings);
1208                         for (i = 0; i < num_stats; i++, index++)
1209                                 memcpy(data + index * ETH_GSTRING_LEN,
1210                                        qlcnic_83xx_mac_stats_strings[i],
1211                                        ETH_GSTRING_LEN);
1212                 }
1213                 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1214                         return;
1215                 num_stats = ARRAY_SIZE(qlcnic_device_gstrings_stats);
1216                 for (i = 0; i < num_stats; index++, i++) {
1217                         memcpy(data + index * ETH_GSTRING_LEN,
1218                                qlcnic_device_gstrings_stats[i],
1219                                ETH_GSTRING_LEN);
1220                 }
1221         }
1222 }
1223
1224 static u64 *qlcnic_fill_stats(u64 *data, void *stats, int type)
1225 {
1226         if (type == QLCNIC_MAC_STATS) {
1227                 struct qlcnic_mac_statistics *mac_stats =
1228                                         (struct qlcnic_mac_statistics *)stats;
1229                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_frames);
1230                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_bytes);
1231                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_mcast_pkts);
1232                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_bcast_pkts);
1233                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_pause_cnt);
1234                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_ctrl_pkt);
1235                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_64b_pkts);
1236                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_127b_pkts);
1237                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_255b_pkts);
1238                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_511b_pkts);
1239                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_1023b_pkts);
1240                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_1518b_pkts);
1241                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_gt_1518b_pkts);
1242                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_frames);
1243                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_bytes);
1244                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_mcast_pkts);
1245                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_bcast_pkts);
1246                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_pause_cnt);
1247                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_ctrl_pkt);
1248                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_64b_pkts);
1249                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_127b_pkts);
1250                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_255b_pkts);
1251                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_511b_pkts);
1252                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_1023b_pkts);
1253                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_1518b_pkts);
1254                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_gt_1518b_pkts);
1255                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_error);
1256                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_small);
1257                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_large);
1258                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_jabber);
1259                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_dropped);
1260                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_crc_error);
1261                 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_align_error);
1262         } else if (type == QLCNIC_ESW_STATS) {
1263                 struct __qlcnic_esw_statistics *esw_stats =
1264                                 (struct __qlcnic_esw_statistics *)stats;
1265                 *data++ = QLCNIC_FILL_STATS(esw_stats->unicast_frames);
1266                 *data++ = QLCNIC_FILL_STATS(esw_stats->multicast_frames);
1267                 *data++ = QLCNIC_FILL_STATS(esw_stats->broadcast_frames);
1268                 *data++ = QLCNIC_FILL_STATS(esw_stats->dropped_frames);
1269                 *data++ = QLCNIC_FILL_STATS(esw_stats->errors);
1270                 *data++ = QLCNIC_FILL_STATS(esw_stats->local_frames);
1271                 *data++ = QLCNIC_FILL_STATS(esw_stats->numbytes);
1272         }
1273         return data;
1274 }
1275
1276 void qlcnic_update_stats(struct qlcnic_adapter *adapter)
1277 {
1278         struct qlcnic_host_tx_ring *tx_ring;
1279         int ring;
1280
1281         for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
1282                 tx_ring = &adapter->tx_ring[ring];
1283                 adapter->stats.xmit_on += tx_ring->tx_stats.xmit_on;
1284                 adapter->stats.xmit_off += tx_ring->tx_stats.xmit_off;
1285                 adapter->stats.xmitcalled += tx_ring->tx_stats.xmit_called;
1286                 adapter->stats.xmitfinished += tx_ring->tx_stats.xmit_finished;
1287                 adapter->stats.txbytes += tx_ring->tx_stats.tx_bytes;
1288         }
1289 }
1290
1291 static u64 *qlcnic_fill_tx_queue_stats(u64 *data, void *stats)
1292 {
1293         struct qlcnic_host_tx_ring *tx_ring;
1294
1295         tx_ring = (struct qlcnic_host_tx_ring *)stats;
1296
1297         *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_on);
1298         *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_off);
1299         *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_called);
1300         *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_finished);
1301         *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.tx_bytes);
1302
1303         return data;
1304 }
1305
1306 static void qlcnic_get_ethtool_stats(struct net_device *dev,
1307                                      struct ethtool_stats *stats, u64 *data)
1308 {
1309         struct qlcnic_adapter *adapter = netdev_priv(dev);
1310         struct qlcnic_host_tx_ring *tx_ring;
1311         struct qlcnic_esw_statistics port_stats;
1312         struct qlcnic_mac_statistics mac_stats;
1313         int index, ret, length, size, tx_size, ring;
1314         char *p;
1315
1316         tx_size = adapter->drv_tx_rings * QLCNIC_TX_STATS_LEN;
1317
1318         memset(data, 0, tx_size * sizeof(u64));
1319         for (ring = 0, index = 0; ring < adapter->drv_tx_rings; ring++) {
1320                 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
1321                         tx_ring = &adapter->tx_ring[ring];
1322                         data = qlcnic_fill_tx_queue_stats(data, tx_ring);
1323                         qlcnic_update_stats(adapter);
1324                 }
1325         }
1326
1327         memset(data, 0, stats->n_stats * sizeof(u64));
1328         length = QLCNIC_STATS_LEN;
1329         for (index = 0; index < length; index++) {
1330                 p = (char *)adapter + qlcnic_gstrings_stats[index].stat_offset;
1331                 size = qlcnic_gstrings_stats[index].sizeof_stat;
1332                 *data++ = (size == sizeof(u64)) ? (*(u64 *)p) : ((*(u32 *)p));
1333         }
1334
1335         if (qlcnic_83xx_check(adapter)) {
1336                 if (adapter->ahw->linkup)
1337                         qlcnic_83xx_get_stats(adapter, data);
1338                 return;
1339         } else {
1340                 /* Retrieve MAC statistics from firmware */
1341                 memset(&mac_stats, 0, sizeof(struct qlcnic_mac_statistics));
1342                 qlcnic_get_mac_stats(adapter, &mac_stats);
1343                 data = qlcnic_fill_stats(data, &mac_stats, QLCNIC_MAC_STATS);
1344         }
1345
1346         if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1347                 return;
1348
1349         memset(&port_stats, 0, sizeof(struct qlcnic_esw_statistics));
1350         ret = qlcnic_get_port_stats(adapter, adapter->ahw->pci_func,
1351                         QLCNIC_QUERY_RX_COUNTER, &port_stats.rx);
1352         if (ret)
1353                 return;
1354
1355         data = qlcnic_fill_stats(data, &port_stats.rx, QLCNIC_ESW_STATS);
1356         ret = qlcnic_get_port_stats(adapter, adapter->ahw->pci_func,
1357                         QLCNIC_QUERY_TX_COUNTER, &port_stats.tx);
1358         if (ret)
1359                 return;
1360
1361         qlcnic_fill_stats(data, &port_stats.tx, QLCNIC_ESW_STATS);
1362 }
1363
1364 static int qlcnic_set_led(struct net_device *dev,
1365                           enum ethtool_phys_id_state state)
1366 {
1367         struct qlcnic_adapter *adapter = netdev_priv(dev);
1368         int drv_sds_rings = adapter->drv_sds_rings;
1369         int err = -EIO, active = 1;
1370
1371         if (qlcnic_83xx_check(adapter))
1372                 return qlcnic_83xx_set_led(dev, state);
1373
1374         if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
1375                 netdev_warn(dev, "LED test not supported for non "
1376                                 "privilege function\n");
1377                 return -EOPNOTSUPP;
1378         }
1379
1380         switch (state) {
1381         case ETHTOOL_ID_ACTIVE:
1382                 if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state))
1383                         return -EBUSY;
1384
1385                 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
1386                         break;
1387
1388                 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
1389                         if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
1390                                 break;
1391                         set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
1392                 }
1393
1394                 if (adapter->nic_ops->config_led(adapter, 1, 0xf) == 0) {
1395                         err = 0;
1396                         break;
1397                 }
1398
1399                 dev_err(&adapter->pdev->dev,
1400                         "Failed to set LED blink state.\n");
1401                 break;
1402
1403         case ETHTOOL_ID_INACTIVE:
1404                 active = 0;
1405
1406                 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
1407                         break;
1408
1409                 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
1410                         if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
1411                                 break;
1412                         set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
1413                 }
1414
1415                 if (adapter->nic_ops->config_led(adapter, 0, 0xf))
1416                         dev_err(&adapter->pdev->dev,
1417                                 "Failed to reset LED blink state.\n");
1418
1419                 break;
1420
1421         default:
1422                 return -EINVAL;
1423         }
1424
1425         if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
1426                 qlcnic_diag_free_res(dev, drv_sds_rings);
1427
1428         if (!active || err)
1429                 clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
1430
1431         return err;
1432 }
1433
1434 static void
1435 qlcnic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1436 {
1437         struct qlcnic_adapter *adapter = netdev_priv(dev);
1438         u32 wol_cfg;
1439         int err = 0;
1440
1441         if (qlcnic_83xx_check(adapter))
1442                 return;
1443         wol->supported = 0;
1444         wol->wolopts = 0;
1445
1446         wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV, &err);
1447         if (err == -EIO)
1448                 return;
1449         if (wol_cfg & (1UL << adapter->portnum))
1450                 wol->supported |= WAKE_MAGIC;
1451
1452         wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG, &err);
1453         if (wol_cfg & (1UL << adapter->portnum))
1454                 wol->wolopts |= WAKE_MAGIC;
1455 }
1456
1457 static int
1458 qlcnic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1459 {
1460         struct qlcnic_adapter *adapter = netdev_priv(dev);
1461         u32 wol_cfg;
1462         int err = 0;
1463
1464         if (qlcnic_83xx_check(adapter))
1465                 return -EOPNOTSUPP;
1466         if (wol->wolopts & ~WAKE_MAGIC)
1467                 return -EINVAL;
1468
1469         wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV, &err);
1470         if (err == -EIO)
1471                 return err;
1472         if (!(wol_cfg & (1 << adapter->portnum)))
1473                 return -EOPNOTSUPP;
1474
1475         wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG, &err);
1476         if (err == -EIO)
1477                 return err;
1478         if (wol->wolopts & WAKE_MAGIC)
1479                 wol_cfg |= 1UL << adapter->portnum;
1480         else
1481                 wol_cfg &= ~(1UL << adapter->portnum);
1482
1483         QLCWR32(adapter, QLCNIC_WOL_CONFIG, wol_cfg);
1484
1485         return 0;
1486 }
1487
1488 /*
1489  * Set the coalescing parameters. Currently only normal is supported.
1490  * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
1491  * firmware coalescing to default.
1492  */
1493 static int qlcnic_set_intr_coalesce(struct net_device *netdev,
1494                         struct ethtool_coalesce *ethcoal)
1495 {
1496         struct qlcnic_adapter *adapter = netdev_priv(netdev);
1497         struct qlcnic_nic_intr_coalesce *coal;
1498         u32 rx_coalesce_usecs, rx_max_frames;
1499         u32 tx_coalesce_usecs, tx_max_frames;
1500
1501         if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
1502                 return -EINVAL;
1503
1504         /*
1505         * Return Error if unsupported values or
1506         * unsupported parameters are set.
1507         */
1508         if (ethcoal->rx_coalesce_usecs > 0xffff ||
1509                 ethcoal->rx_max_coalesced_frames > 0xffff ||
1510                 ethcoal->tx_coalesce_usecs > 0xffff ||
1511                 ethcoal->tx_max_coalesced_frames > 0xffff ||
1512                 ethcoal->rx_coalesce_usecs_irq ||
1513                 ethcoal->rx_max_coalesced_frames_irq ||
1514                 ethcoal->tx_coalesce_usecs_irq ||
1515                 ethcoal->tx_max_coalesced_frames_irq ||
1516                 ethcoal->stats_block_coalesce_usecs ||
1517                 ethcoal->use_adaptive_rx_coalesce ||
1518                 ethcoal->use_adaptive_tx_coalesce ||
1519                 ethcoal->pkt_rate_low ||
1520                 ethcoal->rx_coalesce_usecs_low ||
1521                 ethcoal->rx_max_coalesced_frames_low ||
1522                 ethcoal->tx_coalesce_usecs_low ||
1523                 ethcoal->tx_max_coalesced_frames_low ||
1524                 ethcoal->pkt_rate_high ||
1525                 ethcoal->rx_coalesce_usecs_high ||
1526                 ethcoal->rx_max_coalesced_frames_high ||
1527                 ethcoal->tx_coalesce_usecs_high ||
1528                 ethcoal->tx_max_coalesced_frames_high)
1529                 return -EINVAL;
1530
1531         coal = &adapter->ahw->coal;
1532
1533         if (qlcnic_83xx_check(adapter)) {
1534                 if (!ethcoal->tx_coalesce_usecs ||
1535                     !ethcoal->tx_max_coalesced_frames ||
1536                     !ethcoal->rx_coalesce_usecs ||
1537                     !ethcoal->rx_max_coalesced_frames) {
1538                         coal->flag = QLCNIC_INTR_DEFAULT;
1539                         coal->type = QLCNIC_INTR_COAL_TYPE_RX;
1540                         coal->rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1541                         coal->rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1542                         coal->tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1543                         coal->tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1544                 } else {
1545                         tx_coalesce_usecs = ethcoal->tx_coalesce_usecs;
1546                         tx_max_frames = ethcoal->tx_max_coalesced_frames;
1547                         rx_coalesce_usecs = ethcoal->rx_coalesce_usecs;
1548                         rx_max_frames = ethcoal->rx_max_coalesced_frames;
1549                         coal->flag = 0;
1550
1551                         if ((coal->rx_time_us == rx_coalesce_usecs) &&
1552                             (coal->rx_packets == rx_max_frames)) {
1553                                 coal->type = QLCNIC_INTR_COAL_TYPE_TX;
1554                                 coal->tx_time_us = tx_coalesce_usecs;
1555                                 coal->tx_packets = tx_max_frames;
1556                         } else if ((coal->tx_time_us == tx_coalesce_usecs) &&
1557                                    (coal->tx_packets == tx_max_frames)) {
1558                                 coal->type = QLCNIC_INTR_COAL_TYPE_RX;
1559                                 coal->rx_time_us = rx_coalesce_usecs;
1560                                 coal->rx_packets = rx_max_frames;
1561                         } else {
1562                                 coal->type = QLCNIC_INTR_COAL_TYPE_RX;
1563                                 coal->rx_time_us = rx_coalesce_usecs;
1564                                 coal->rx_packets = rx_max_frames;
1565                                 coal->tx_time_us = tx_coalesce_usecs;
1566                                 coal->tx_packets = tx_max_frames;
1567                         }
1568                 }
1569         } else {
1570                 if (!ethcoal->rx_coalesce_usecs ||
1571                     !ethcoal->rx_max_coalesced_frames) {
1572                         coal->flag = QLCNIC_INTR_DEFAULT;
1573                         coal->rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1574                         coal->rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1575                 } else {
1576                         coal->flag = 0;
1577                         coal->rx_time_us = ethcoal->rx_coalesce_usecs;
1578                         coal->rx_packets = ethcoal->rx_max_coalesced_frames;
1579                 }
1580         }
1581
1582         qlcnic_config_intr_coalesce(adapter);
1583
1584         return 0;
1585 }
1586
1587 static int qlcnic_get_intr_coalesce(struct net_device *netdev,
1588                         struct ethtool_coalesce *ethcoal)
1589 {
1590         struct qlcnic_adapter *adapter = netdev_priv(netdev);
1591
1592         if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1593                 return -EINVAL;
1594
1595         ethcoal->rx_coalesce_usecs = adapter->ahw->coal.rx_time_us;
1596         ethcoal->rx_max_coalesced_frames = adapter->ahw->coal.rx_packets;
1597         ethcoal->tx_coalesce_usecs = adapter->ahw->coal.tx_time_us;
1598         ethcoal->tx_max_coalesced_frames = adapter->ahw->coal.tx_packets;
1599
1600         return 0;
1601 }
1602
1603 static u32 qlcnic_get_msglevel(struct net_device *netdev)
1604 {
1605         struct qlcnic_adapter *adapter = netdev_priv(netdev);
1606
1607         return adapter->ahw->msg_enable;
1608 }
1609
1610 static void qlcnic_set_msglevel(struct net_device *netdev, u32 msglvl)
1611 {
1612         struct qlcnic_adapter *adapter = netdev_priv(netdev);
1613
1614         adapter->ahw->msg_enable = msglvl;
1615 }
1616
1617 int qlcnic_enable_fw_dump_state(struct qlcnic_adapter *adapter)
1618 {
1619         struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1620         u32 val;
1621
1622         if (qlcnic_84xx_check(adapter)) {
1623                 if (qlcnic_83xx_lock_driver(adapter))
1624                         return -EBUSY;
1625
1626                 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1627                 val &= ~QLC_83XX_IDC_DISABLE_FW_DUMP;
1628                 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1629
1630                 qlcnic_83xx_unlock_driver(adapter);
1631         } else {
1632                 fw_dump->enable = true;
1633         }
1634
1635         dev_info(&adapter->pdev->dev, "FW dump enabled\n");
1636
1637         return 0;
1638 }
1639
1640 static int qlcnic_disable_fw_dump_state(struct qlcnic_adapter *adapter)
1641 {
1642         struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1643         u32 val;
1644
1645         if (qlcnic_84xx_check(adapter)) {
1646                 if (qlcnic_83xx_lock_driver(adapter))
1647                         return -EBUSY;
1648
1649                 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1650                 val |= QLC_83XX_IDC_DISABLE_FW_DUMP;
1651                 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1652
1653                 qlcnic_83xx_unlock_driver(adapter);
1654         } else {
1655                 fw_dump->enable = false;
1656         }
1657
1658         dev_info(&adapter->pdev->dev, "FW dump disabled\n");
1659
1660         return 0;
1661 }
1662
1663 bool qlcnic_check_fw_dump_state(struct qlcnic_adapter *adapter)
1664 {
1665         struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1666         bool state;
1667         u32 val;
1668
1669         if (qlcnic_84xx_check(adapter)) {
1670                 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1671                 state = (val & QLC_83XX_IDC_DISABLE_FW_DUMP) ? false : true;
1672         } else {
1673                 state = fw_dump->enable;
1674         }
1675
1676         return state;
1677 }
1678
1679 static int
1680 qlcnic_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
1681 {
1682         struct qlcnic_adapter *adapter = netdev_priv(netdev);
1683         struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1684
1685         if (!fw_dump->tmpl_hdr) {
1686                 netdev_err(adapter->netdev, "FW Dump not supported\n");
1687                 return -ENOTSUPP;
1688         }
1689
1690         if (fw_dump->clr)
1691                 dump->len = fw_dump->tmpl_hdr->size + fw_dump->size;
1692         else
1693                 dump->len = 0;
1694
1695         if (!qlcnic_check_fw_dump_state(adapter))
1696                 dump->flag = ETH_FW_DUMP_DISABLE;
1697         else
1698                 dump->flag = fw_dump->tmpl_hdr->drv_cap_mask;
1699
1700         dump->version = adapter->fw_version;
1701         return 0;
1702 }
1703
1704 static int
1705 qlcnic_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
1706                         void *buffer)
1707 {
1708         int i, copy_sz;
1709         u32 *hdr_ptr;
1710         __le32 *data;
1711         struct qlcnic_adapter *adapter = netdev_priv(netdev);
1712         struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1713
1714         if (!fw_dump->tmpl_hdr) {
1715                 netdev_err(netdev, "FW Dump not supported\n");
1716                 return -ENOTSUPP;
1717         }
1718
1719         if (!fw_dump->clr) {
1720                 netdev_info(netdev, "Dump not available\n");
1721                 return -EINVAL;
1722         }
1723         /* Copy template header first */
1724         copy_sz = fw_dump->tmpl_hdr->size;
1725         hdr_ptr = (u32 *) fw_dump->tmpl_hdr;
1726         data = buffer;
1727         for (i = 0; i < copy_sz/sizeof(u32); i++)
1728                 *data++ = cpu_to_le32(*hdr_ptr++);
1729
1730         /* Copy captured dump data */
1731         memcpy(buffer + copy_sz, fw_dump->data, fw_dump->size);
1732         dump->len = copy_sz + fw_dump->size;
1733         dump->flag = fw_dump->tmpl_hdr->drv_cap_mask;
1734
1735         /* Free dump area once data has been captured */
1736         vfree(fw_dump->data);
1737         fw_dump->data = NULL;
1738         fw_dump->clr = 0;
1739         netdev_info(netdev, "extracted the FW dump Successfully\n");
1740         return 0;
1741 }
1742
1743 static int qlcnic_set_dump_mask(struct qlcnic_adapter *adapter, u32 mask)
1744 {
1745         struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1746         struct net_device *netdev = adapter->netdev;
1747
1748         if (!qlcnic_check_fw_dump_state(adapter)) {
1749                 netdev_info(netdev,
1750                             "Can not change driver mask to 0x%x. FW dump not enabled\n",
1751                             mask);
1752                 return -EOPNOTSUPP;
1753         }
1754
1755         fw_dump->tmpl_hdr->drv_cap_mask = mask;
1756         netdev_info(netdev, "Driver mask changed to: 0x%x\n", mask);
1757         return 0;
1758 }
1759
1760 static int
1761 qlcnic_set_dump(struct net_device *netdev, struct ethtool_dump *val)
1762 {
1763         struct qlcnic_adapter *adapter = netdev_priv(netdev);
1764         struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1765         bool valid_mask = false;
1766         int i, ret = 0;
1767
1768         switch (val->flag) {
1769         case QLCNIC_FORCE_FW_DUMP_KEY:
1770                 if (!fw_dump->tmpl_hdr) {
1771                         netdev_err(netdev, "FW dump not supported\n");
1772                         ret = -EOPNOTSUPP;
1773                         break;
1774                 }
1775
1776                 if (!qlcnic_check_fw_dump_state(adapter)) {
1777                         netdev_info(netdev, "FW dump not enabled\n");
1778                         ret = -EOPNOTSUPP;
1779                         break;
1780                 }
1781
1782                 if (fw_dump->clr) {
1783                         netdev_info(netdev,
1784                                     "Previous dump not cleared, not forcing dump\n");
1785                         break;
1786                 }
1787
1788                 netdev_info(netdev, "Forcing a FW dump\n");
1789                 qlcnic_dev_request_reset(adapter, val->flag);
1790                 break;
1791         case QLCNIC_DISABLE_FW_DUMP:
1792                 if (!fw_dump->tmpl_hdr) {
1793                         netdev_err(netdev, "FW dump not supported\n");
1794                         ret = -EOPNOTSUPP;
1795                         break;
1796                 }
1797
1798                 ret = qlcnic_disable_fw_dump_state(adapter);
1799                 break;
1800
1801         case QLCNIC_ENABLE_FW_DUMP:
1802                 if (!fw_dump->tmpl_hdr) {
1803                         netdev_err(netdev, "FW dump not supported\n");
1804                         ret = -EOPNOTSUPP;
1805                         break;
1806                 }
1807
1808                 ret = qlcnic_enable_fw_dump_state(adapter);
1809                 break;
1810
1811         case QLCNIC_FORCE_FW_RESET:
1812                 netdev_info(netdev, "Forcing a FW reset\n");
1813                 qlcnic_dev_request_reset(adapter, val->flag);
1814                 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
1815                 break;
1816
1817         case QLCNIC_SET_QUIESCENT:
1818         case QLCNIC_RESET_QUIESCENT:
1819                 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state))
1820                         netdev_info(netdev, "Device is in non-operational state\n");
1821                 break;
1822
1823         default:
1824                 if (!fw_dump->tmpl_hdr) {
1825                         netdev_err(netdev, "FW dump not supported\n");
1826                         ret = -EOPNOTSUPP;
1827                         break;
1828                 }
1829
1830                 for (i = 0; i < ARRAY_SIZE(qlcnic_fw_dump_level); i++) {
1831                         if (val->flag == qlcnic_fw_dump_level[i]) {
1832                                 valid_mask = true;
1833                                 break;
1834                         }
1835                 }
1836
1837                 if (valid_mask) {
1838                         ret = qlcnic_set_dump_mask(adapter, val->flag);
1839                 } else {
1840                         netdev_info(netdev, "Invalid dump level: 0x%x\n",
1841                                     val->flag);
1842                         ret = -EINVAL;
1843                 }
1844         }
1845         return ret;
1846 }
1847
1848 const struct ethtool_ops qlcnic_ethtool_ops = {
1849         .get_settings = qlcnic_get_settings,
1850         .set_settings = qlcnic_set_settings,
1851         .get_drvinfo = qlcnic_get_drvinfo,
1852         .get_regs_len = qlcnic_get_regs_len,
1853         .get_regs = qlcnic_get_regs,
1854         .get_link = ethtool_op_get_link,
1855         .get_eeprom_len = qlcnic_get_eeprom_len,
1856         .get_eeprom = qlcnic_get_eeprom,
1857         .get_ringparam = qlcnic_get_ringparam,
1858         .set_ringparam = qlcnic_set_ringparam,
1859         .get_channels = qlcnic_get_channels,
1860         .set_channels = qlcnic_set_channels,
1861         .get_pauseparam = qlcnic_get_pauseparam,
1862         .set_pauseparam = qlcnic_set_pauseparam,
1863         .get_wol = qlcnic_get_wol,
1864         .set_wol = qlcnic_set_wol,
1865         .self_test = qlcnic_diag_test,
1866         .get_strings = qlcnic_get_strings,
1867         .get_ethtool_stats = qlcnic_get_ethtool_stats,
1868         .get_sset_count = qlcnic_get_sset_count,
1869         .get_coalesce = qlcnic_get_intr_coalesce,
1870         .set_coalesce = qlcnic_set_intr_coalesce,
1871         .set_phys_id = qlcnic_set_led,
1872         .set_msglevel = qlcnic_set_msglevel,
1873         .get_msglevel = qlcnic_get_msglevel,
1874         .get_dump_flag = qlcnic_get_dump_flag,
1875         .get_dump_data = qlcnic_get_dump_data,
1876         .set_dump = qlcnic_set_dump,
1877 };
1878
1879 const struct ethtool_ops qlcnic_sriov_vf_ethtool_ops = {
1880         .get_settings           = qlcnic_get_settings,
1881         .get_drvinfo            = qlcnic_get_drvinfo,
1882         .get_regs_len           = qlcnic_get_regs_len,
1883         .get_regs               = qlcnic_get_regs,
1884         .get_link               = ethtool_op_get_link,
1885         .get_eeprom_len         = qlcnic_get_eeprom_len,
1886         .get_eeprom             = qlcnic_get_eeprom,
1887         .get_ringparam          = qlcnic_get_ringparam,
1888         .set_ringparam          = qlcnic_set_ringparam,
1889         .get_channels           = qlcnic_get_channels,
1890         .get_pauseparam         = qlcnic_get_pauseparam,
1891         .get_wol                = qlcnic_get_wol,
1892         .get_strings            = qlcnic_get_strings,
1893         .get_ethtool_stats      = qlcnic_get_ethtool_stats,
1894         .get_sset_count         = qlcnic_get_sset_count,
1895         .get_coalesce           = qlcnic_get_intr_coalesce,
1896         .set_coalesce           = qlcnic_set_intr_coalesce,
1897         .set_msglevel           = qlcnic_set_msglevel,
1898         .get_msglevel           = qlcnic_get_msglevel,
1899 };
1900
1901 const struct ethtool_ops qlcnic_ethtool_failed_ops = {
1902         .get_settings           = qlcnic_get_settings,
1903         .get_drvinfo            = qlcnic_get_drvinfo,
1904         .set_msglevel           = qlcnic_set_msglevel,
1905         .get_msglevel           = qlcnic_get_msglevel,
1906         .set_dump               = qlcnic_set_dump,
1907 };