b2476dbfd103120affb5e216a31d304dda570a67
[cascardo/linux.git] / drivers / net / ethernet / emulex / benet / be_ethtool.c
1 /*
2  * Copyright (C) 2005 - 2015 Emulex
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation.  The full GNU General
8  * Public License is included in this distribution in the file called COPYING.
9  *
10  * Contact Information:
11  * linux-drivers@emulex.com
12  *
13  * Emulex
14  * 3333 Susan Street
15  * Costa Mesa, CA 92626
16  */
17
18 #include "be.h"
19 #include "be_cmds.h"
20 #include <linux/ethtool.h>
21
22 struct be_ethtool_stat {
23         char desc[ETH_GSTRING_LEN];
24         int type;
25         int size;
26         int offset;
27 };
28
29 enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
30 #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
31                                         offsetof(_struct, field)
32 #define DRVSTAT_TX_INFO(field)  #field, DRVSTAT_TX,\
33                                         FIELDINFO(struct be_tx_stats, field)
34 #define DRVSTAT_RX_INFO(field)  #field, DRVSTAT_RX,\
35                                         FIELDINFO(struct be_rx_stats, field)
36 #define DRVSTAT_INFO(field)     #field, DRVSTAT,\
37                                         FIELDINFO(struct be_drv_stats, field)
38
39 static const struct be_ethtool_stat et_stats[] = {
40         {DRVSTAT_INFO(rx_crc_errors)},
41         {DRVSTAT_INFO(rx_alignment_symbol_errors)},
42         {DRVSTAT_INFO(rx_pause_frames)},
43         {DRVSTAT_INFO(rx_control_frames)},
44         /* Received packets dropped when the Ethernet length field
45          * is not equal to the actual Ethernet data length.
46          */
47         {DRVSTAT_INFO(rx_in_range_errors)},
48         /* Received packets dropped when their length field is >= 1501 bytes
49          * and <= 1535 bytes.
50          */
51         {DRVSTAT_INFO(rx_out_range_errors)},
52         /* Received packets dropped when they are longer than 9216 bytes */
53         {DRVSTAT_INFO(rx_frame_too_long)},
54         /* Received packets dropped when they don't pass the unicast or
55          * multicast address filtering.
56          */
57         {DRVSTAT_INFO(rx_address_filtered)},
58         /* Received packets dropped when IP packet length field is less than
59          * the IP header length field.
60          */
61         {DRVSTAT_INFO(rx_dropped_too_small)},
62         /* Received packets dropped when IP length field is greater than
63          * the actual packet length.
64          */
65         {DRVSTAT_INFO(rx_dropped_too_short)},
66         /* Received packets dropped when the IP header length field is less
67          * than 5.
68          */
69         {DRVSTAT_INFO(rx_dropped_header_too_small)},
70         /* Received packets dropped when the TCP header length field is less
71          * than 5 or the TCP header length + IP header length is more
72          * than IP packet length.
73          */
74         {DRVSTAT_INFO(rx_dropped_tcp_length)},
75         {DRVSTAT_INFO(rx_dropped_runt)},
76         /* Number of received packets dropped when a fifo for descriptors going
77          * into the packet demux block overflows. In normal operation, this
78          * fifo must never overflow.
79          */
80         {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
81         /* Received packets dropped when the RX block runs out of space in
82          * one of its input FIFOs. This could happen due a long burst of
83          * minimum-sized (64b) frames in the receive path.
84          * This counter may also be erroneously incremented rarely.
85          */
86         {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
87         {DRVSTAT_INFO(rx_ip_checksum_errs)},
88         {DRVSTAT_INFO(rx_tcp_checksum_errs)},
89         {DRVSTAT_INFO(rx_udp_checksum_errs)},
90         {DRVSTAT_INFO(tx_pauseframes)},
91         {DRVSTAT_INFO(tx_controlframes)},
92         {DRVSTAT_INFO(rx_priority_pause_frames)},
93         {DRVSTAT_INFO(tx_priority_pauseframes)},
94         /* Received packets dropped when an internal fifo going into
95          * main packet buffer tank (PMEM) overflows.
96          */
97         {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
98         {DRVSTAT_INFO(jabber_events)},
99         /* Received packets dropped due to lack of available HW packet buffers
100          * used to temporarily hold the received packets.
101          */
102         {DRVSTAT_INFO(rx_drops_no_pbuf)},
103         /* Received packets dropped due to input receive buffer
104          * descriptor fifo overflowing.
105          */
106         {DRVSTAT_INFO(rx_drops_no_erx_descr)},
107         /* Packets dropped because the internal FIFO to the offloaded TCP
108          * receive processing block is full. This could happen only for
109          * offloaded iSCSI or FCoE trarffic.
110          */
111         {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
112         /* Received packets dropped when they need more than 8
113          * receive buffers. This cannot happen as the driver configures
114          * 2048 byte receive buffers.
115          */
116         {DRVSTAT_INFO(rx_drops_too_many_frags)},
117         {DRVSTAT_INFO(forwarded_packets)},
118         /* Received packets dropped when the frame length
119          * is more than 9018 bytes
120          */
121         {DRVSTAT_INFO(rx_drops_mtu)},
122         /* Number of dma mapping errors */
123         {DRVSTAT_INFO(dma_map_errors)},
124         /* Number of packets dropped due to random early drop function */
125         {DRVSTAT_INFO(eth_red_drops)},
126         {DRVSTAT_INFO(rx_roce_bytes_lsd)},
127         {DRVSTAT_INFO(rx_roce_bytes_msd)},
128         {DRVSTAT_INFO(rx_roce_frames)},
129         {DRVSTAT_INFO(roce_drops_payload_len)},
130         {DRVSTAT_INFO(roce_drops_crc)}
131 };
132
133 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
134
135 /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
136  * are first and second members respectively.
137  */
138 static const struct be_ethtool_stat et_rx_stats[] = {
139         {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
140         {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
141         {DRVSTAT_RX_INFO(rx_compl)},
142         {DRVSTAT_RX_INFO(rx_compl_err)},
143         {DRVSTAT_RX_INFO(rx_mcast_pkts)},
144         /* Number of page allocation failures while posting receive buffers
145          * to HW.
146          */
147         {DRVSTAT_RX_INFO(rx_post_fail)},
148         /* Recevied packets dropped due to skb allocation failure */
149         {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
150         /* Received packets dropped due to lack of available fetched buffers
151          * posted by the driver.
152          */
153         {DRVSTAT_RX_INFO(rx_drops_no_frags)}
154 };
155
156 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
157
158 /* Stats related to multi TX queues: get_stats routine assumes compl is the
159  * first member
160  */
161 static const struct be_ethtool_stat et_tx_stats[] = {
162         {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
163         /* This counter is incremented when the HW encounters an error while
164          * parsing the packet header of an outgoing TX request. This counter is
165          * applicable only for BE2, BE3 and Skyhawk based adapters.
166          */
167         {DRVSTAT_TX_INFO(tx_hdr_parse_err)},
168         /* This counter is incremented when an error occurs in the DMA
169          * operation associated with the TX request from the host to the device.
170          */
171         {DRVSTAT_TX_INFO(tx_dma_err)},
172         /* This counter is incremented when MAC or VLAN spoof checking is
173          * enabled on the interface and the TX request fails the spoof check
174          * in HW.
175          */
176         {DRVSTAT_TX_INFO(tx_spoof_check_err)},
177         /* This counter is incremented when the HW encounters an error while
178          * performing TSO offload. This counter is applicable only for Lancer
179          * adapters.
180          */
181         {DRVSTAT_TX_INFO(tx_tso_err)},
182         /* This counter is incremented when the HW detects Q-in-Q style VLAN
183          * tagging in a packet and such tagging is not expected on the outgoing
184          * interface. This counter is applicable only for Lancer adapters.
185          */
186         {DRVSTAT_TX_INFO(tx_qinq_err)},
187         /* This counter is incremented when the HW detects parity errors in the
188          * packet data. This counter is applicable only for Lancer adapters.
189          */
190         {DRVSTAT_TX_INFO(tx_internal_parity_err)},
191         {DRVSTAT_TX_INFO(tx_bytes)},
192         {DRVSTAT_TX_INFO(tx_pkts)},
193         /* Number of skbs queued for trasmission by the driver */
194         {DRVSTAT_TX_INFO(tx_reqs)},
195         /* Number of times the TX queue was stopped due to lack
196          * of spaces in the TXQ.
197          */
198         {DRVSTAT_TX_INFO(tx_stops)},
199         /* Pkts dropped in the driver's transmit path */
200         {DRVSTAT_TX_INFO(tx_drv_drops)}
201 };
202
203 #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
204
205 static const char et_self_tests[][ETH_GSTRING_LEN] = {
206         "MAC Loopback test",
207         "PHY Loopback test",
208         "External Loopback test",
209         "DDR DMA test",
210         "Link test"
211 };
212
213 #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
214 #define BE_MAC_LOOPBACK 0x0
215 #define BE_PHY_LOOPBACK 0x1
216 #define BE_ONE_PORT_EXT_LOOPBACK 0x2
217 #define BE_NO_LOOPBACK 0xff
218
219 static void be_get_drvinfo(struct net_device *netdev,
220                            struct ethtool_drvinfo *drvinfo)
221 {
222         struct be_adapter *adapter = netdev_priv(netdev);
223
224         strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
225         strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
226         if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN))
227                 strlcpy(drvinfo->fw_version, adapter->fw_ver,
228                         sizeof(drvinfo->fw_version));
229         else
230                 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
231                          "%s [%s]", adapter->fw_ver, adapter->fw_on_flash);
232
233         strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
234                 sizeof(drvinfo->bus_info));
235         drvinfo->testinfo_len = 0;
236         drvinfo->regdump_len = 0;
237         drvinfo->eedump_len = 0;
238 }
239
240 static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
241 {
242         u32 data_read = 0, eof;
243         u8 addn_status;
244         struct be_dma_mem data_len_cmd;
245         int status;
246
247         memset(&data_len_cmd, 0, sizeof(data_len_cmd));
248         /* data_offset and data_size should be 0 to get reg len */
249         status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
250                                         file_name, &data_read, &eof,
251                                         &addn_status);
252
253         return data_read;
254 }
255
256 static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
257                                 u32 buf_len, void *buf)
258 {
259         struct be_dma_mem read_cmd;
260         u32 read_len = 0, total_read_len = 0, chunk_size;
261         u32 eof = 0;
262         u8 addn_status;
263         int status = 0;
264
265         read_cmd.size = LANCER_READ_FILE_CHUNK;
266         read_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, read_cmd.size,
267                                           &read_cmd.dma, GFP_ATOMIC);
268
269         if (!read_cmd.va) {
270                 dev_err(&adapter->pdev->dev,
271                         "Memory allocation failure while reading dump\n");
272                 return -ENOMEM;
273         }
274
275         while ((total_read_len < buf_len) && !eof) {
276                 chunk_size = min_t(u32, (buf_len - total_read_len),
277                                    LANCER_READ_FILE_CHUNK);
278                 chunk_size = ALIGN(chunk_size, 4);
279                 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
280                                                 total_read_len, file_name,
281                                                 &read_len, &eof, &addn_status);
282                 if (!status) {
283                         memcpy(buf + total_read_len, read_cmd.va, read_len);
284                         total_read_len += read_len;
285                         eof &= LANCER_READ_FILE_EOF_MASK;
286                 } else {
287                         status = -EIO;
288                         break;
289                 }
290         }
291         dma_free_coherent(&adapter->pdev->dev, read_cmd.size, read_cmd.va,
292                           read_cmd.dma);
293
294         return status;
295 }
296
297 static int be_get_reg_len(struct net_device *netdev)
298 {
299         struct be_adapter *adapter = netdev_priv(netdev);
300         u32 log_size = 0;
301
302         if (!check_privilege(adapter, MAX_PRIVILEGES))
303                 return 0;
304
305         if (be_physfn(adapter)) {
306                 if (lancer_chip(adapter))
307                         log_size = lancer_cmd_get_file_len(adapter,
308                                                            LANCER_FW_DUMP_FILE);
309                 else
310                         be_cmd_get_reg_len(adapter, &log_size);
311         }
312         return log_size;
313 }
314
315 static void
316 be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
317 {
318         struct be_adapter *adapter = netdev_priv(netdev);
319
320         if (be_physfn(adapter)) {
321                 memset(buf, 0, regs->len);
322                 if (lancer_chip(adapter))
323                         lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
324                                              regs->len, buf);
325                 else
326                         be_cmd_get_regs(adapter, regs->len, buf);
327         }
328 }
329
330 static int be_get_coalesce(struct net_device *netdev,
331                            struct ethtool_coalesce *et)
332 {
333         struct be_adapter *adapter = netdev_priv(netdev);
334         struct be_aic_obj *aic = &adapter->aic_obj[0];
335
336         et->rx_coalesce_usecs = aic->prev_eqd;
337         et->rx_coalesce_usecs_high = aic->max_eqd;
338         et->rx_coalesce_usecs_low = aic->min_eqd;
339
340         et->tx_coalesce_usecs = aic->prev_eqd;
341         et->tx_coalesce_usecs_high = aic->max_eqd;
342         et->tx_coalesce_usecs_low = aic->min_eqd;
343
344         et->use_adaptive_rx_coalesce = aic->enable;
345         et->use_adaptive_tx_coalesce = aic->enable;
346
347         return 0;
348 }
349
350 /* TX attributes are ignored. Only RX attributes are considered
351  * eqd cmd is issued in the worker thread.
352  */
353 static int be_set_coalesce(struct net_device *netdev,
354                            struct ethtool_coalesce *et)
355 {
356         struct be_adapter *adapter = netdev_priv(netdev);
357         struct be_aic_obj *aic = &adapter->aic_obj[0];
358         struct be_eq_obj *eqo;
359         int i;
360
361         for_all_evt_queues(adapter, eqo, i) {
362                 aic->enable = et->use_adaptive_rx_coalesce;
363                 aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
364                 aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
365                 aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
366                 aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
367                 aic++;
368         }
369
370         /* For Skyhawk, the EQD setting happens via EQ_DB when AIC is enabled.
371          * When AIC is disabled, persistently force set EQD value via the
372          * FW cmd, so that we don't have to calculate the delay multiplier
373          * encode value each time EQ_DB is rung
374          */
375         if (!et->use_adaptive_rx_coalesce && skyhawk_chip(adapter))
376                 be_eqd_update(adapter, true);
377
378         return 0;
379 }
380
381 static void be_get_ethtool_stats(struct net_device *netdev,
382                                  struct ethtool_stats *stats, uint64_t *data)
383 {
384         struct be_adapter *adapter = netdev_priv(netdev);
385         struct be_rx_obj *rxo;
386         struct be_tx_obj *txo;
387         void *p;
388         unsigned int i, j, base = 0, start;
389
390         for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
391                 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
392                 data[i] = *(u32 *)p;
393         }
394         base += ETHTOOL_STATS_NUM;
395
396         for_all_rx_queues(adapter, rxo, j) {
397                 struct be_rx_stats *stats = rx_stats(rxo);
398
399                 do {
400                         start = u64_stats_fetch_begin_irq(&stats->sync);
401                         data[base] = stats->rx_bytes;
402                         data[base + 1] = stats->rx_pkts;
403                 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
404
405                 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
406                         p = (u8 *)stats + et_rx_stats[i].offset;
407                         data[base + i] = *(u32 *)p;
408                 }
409                 base += ETHTOOL_RXSTATS_NUM;
410         }
411
412         for_all_tx_queues(adapter, txo, j) {
413                 struct be_tx_stats *stats = tx_stats(txo);
414
415                 do {
416                         start = u64_stats_fetch_begin_irq(&stats->sync_compl);
417                         data[base] = stats->tx_compl;
418                 } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
419
420                 do {
421                         start = u64_stats_fetch_begin_irq(&stats->sync);
422                         for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
423                                 p = (u8 *)stats + et_tx_stats[i].offset;
424                                 data[base + i] =
425                                         (et_tx_stats[i].size == sizeof(u64)) ?
426                                                 *(u64 *)p : *(u32 *)p;
427                         }
428                 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
429                 base += ETHTOOL_TXSTATS_NUM;
430         }
431 }
432
433 static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
434                                 uint8_t *data)
435 {
436         struct be_adapter *adapter = netdev_priv(netdev);
437         int i, j;
438
439         switch (stringset) {
440         case ETH_SS_STATS:
441                 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
442                         memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
443                         data += ETH_GSTRING_LEN;
444                 }
445                 for (i = 0; i < adapter->num_rx_qs; i++) {
446                         for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
447                                 sprintf(data, "rxq%d: %s", i,
448                                         et_rx_stats[j].desc);
449                                 data += ETH_GSTRING_LEN;
450                         }
451                 }
452                 for (i = 0; i < adapter->num_tx_qs; i++) {
453                         for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
454                                 sprintf(data, "txq%d: %s", i,
455                                         et_tx_stats[j].desc);
456                                 data += ETH_GSTRING_LEN;
457                         }
458                 }
459                 break;
460         case ETH_SS_TEST:
461                 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
462                         memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
463                         data += ETH_GSTRING_LEN;
464                 }
465                 break;
466         }
467 }
468
469 static int be_get_sset_count(struct net_device *netdev, int stringset)
470 {
471         struct be_adapter *adapter = netdev_priv(netdev);
472
473         switch (stringset) {
474         case ETH_SS_TEST:
475                 return ETHTOOL_TESTS_NUM;
476         case ETH_SS_STATS:
477                 return ETHTOOL_STATS_NUM +
478                         adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
479                         adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
480         default:
481                 return -EINVAL;
482         }
483 }
484
485 static u32 be_get_port_type(struct be_adapter *adapter)
486 {
487         u32 port;
488
489         switch (adapter->phy.interface_type) {
490         case PHY_TYPE_BASET_1GB:
491         case PHY_TYPE_BASEX_1GB:
492         case PHY_TYPE_SGMII:
493                 port = PORT_TP;
494                 break;
495         case PHY_TYPE_SFP_PLUS_10GB:
496                 if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE)
497                         port = PORT_DA;
498                 else
499                         port = PORT_FIBRE;
500                 break;
501         case PHY_TYPE_QSFP:
502                 if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE)
503                         port = PORT_DA;
504                 else
505                         port = PORT_FIBRE;
506                 break;
507         case PHY_TYPE_XFP_10GB:
508         case PHY_TYPE_SFP_1GB:
509                 port = PORT_FIBRE;
510                 break;
511         case PHY_TYPE_BASET_10GB:
512                 port = PORT_TP;
513                 break;
514         default:
515                 port = PORT_OTHER;
516         }
517
518         return port;
519 }
520
521 static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
522 {
523         u32 val = 0;
524
525         switch (adapter->phy.interface_type) {
526         case PHY_TYPE_BASET_1GB:
527         case PHY_TYPE_BASEX_1GB:
528         case PHY_TYPE_SGMII:
529                 val |= SUPPORTED_TP;
530                 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
531                         val |= SUPPORTED_1000baseT_Full;
532                 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
533                         val |= SUPPORTED_100baseT_Full;
534                 if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
535                         val |= SUPPORTED_10baseT_Full;
536                 break;
537         case PHY_TYPE_KX4_10GB:
538                 val |= SUPPORTED_Backplane;
539                 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
540                         val |= SUPPORTED_1000baseKX_Full;
541                 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
542                         val |= SUPPORTED_10000baseKX4_Full;
543                 break;
544         case PHY_TYPE_KR2_20GB:
545                 val |= SUPPORTED_Backplane;
546                 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
547                         val |= SUPPORTED_10000baseKR_Full;
548                 if (if_speeds & BE_SUPPORTED_SPEED_20GBPS)
549                         val |= SUPPORTED_20000baseKR2_Full;
550                 break;
551         case PHY_TYPE_KR_10GB:
552                 val |= SUPPORTED_Backplane |
553                                 SUPPORTED_10000baseKR_Full;
554                 break;
555         case PHY_TYPE_KR4_40GB:
556                 val |= SUPPORTED_Backplane;
557                 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
558                         val |= SUPPORTED_10000baseKR_Full;
559                 if (if_speeds & BE_SUPPORTED_SPEED_40GBPS)
560                         val |= SUPPORTED_40000baseKR4_Full;
561                 break;
562         case PHY_TYPE_QSFP:
563                 if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) {
564                         switch (adapter->phy.cable_type) {
565                         case QSFP_PLUS_CR4_CABLE:
566                                 val |= SUPPORTED_40000baseCR4_Full;
567                                 break;
568                         case QSFP_PLUS_LR4_CABLE:
569                                 val |= SUPPORTED_40000baseLR4_Full;
570                                 break;
571                         default:
572                                 val |= SUPPORTED_40000baseSR4_Full;
573                                 break;
574                         }
575                 }
576         case PHY_TYPE_SFP_PLUS_10GB:
577         case PHY_TYPE_XFP_10GB:
578         case PHY_TYPE_SFP_1GB:
579                 val |= SUPPORTED_FIBRE;
580                 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
581                         val |= SUPPORTED_10000baseT_Full;
582                 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
583                         val |= SUPPORTED_1000baseT_Full;
584                 break;
585         case PHY_TYPE_BASET_10GB:
586                 val |= SUPPORTED_TP;
587                 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
588                         val |= SUPPORTED_10000baseT_Full;
589                 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
590                         val |= SUPPORTED_1000baseT_Full;
591                 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
592                         val |= SUPPORTED_100baseT_Full;
593                 break;
594         default:
595                 val |= SUPPORTED_TP;
596         }
597
598         return val;
599 }
600
601 bool be_pause_supported(struct be_adapter *adapter)
602 {
603         return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
604                 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
605                 false : true;
606 }
607
608 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
609 {
610         struct be_adapter *adapter = netdev_priv(netdev);
611         u8 link_status;
612         u16 link_speed = 0;
613         int status;
614         u32 auto_speeds;
615         u32 fixed_speeds;
616
617         if (adapter->phy.link_speed < 0) {
618                 status = be_cmd_link_status_query(adapter, &link_speed,
619                                                   &link_status, 0);
620                 if (!status)
621                         be_link_status_update(adapter, link_status);
622                 ethtool_cmd_speed_set(ecmd, link_speed);
623
624                 status = be_cmd_get_phy_info(adapter);
625                 if (!status) {
626                         auto_speeds = adapter->phy.auto_speeds_supported;
627                         fixed_speeds = adapter->phy.fixed_speeds_supported;
628
629                         be_cmd_query_cable_type(adapter);
630
631                         ecmd->supported =
632                                 convert_to_et_setting(adapter,
633                                                       auto_speeds |
634                                                       fixed_speeds);
635                         ecmd->advertising =
636                                 convert_to_et_setting(adapter, auto_speeds);
637
638                         ecmd->port = be_get_port_type(adapter);
639
640                         if (adapter->phy.auto_speeds_supported) {
641                                 ecmd->supported |= SUPPORTED_Autoneg;
642                                 ecmd->autoneg = AUTONEG_ENABLE;
643                                 ecmd->advertising |= ADVERTISED_Autoneg;
644                         }
645
646                         ecmd->supported |= SUPPORTED_Pause;
647                         if (be_pause_supported(adapter))
648                                 ecmd->advertising |= ADVERTISED_Pause;
649
650                         switch (adapter->phy.interface_type) {
651                         case PHY_TYPE_KR_10GB:
652                         case PHY_TYPE_KX4_10GB:
653                                 ecmd->transceiver = XCVR_INTERNAL;
654                                 break;
655                         default:
656                                 ecmd->transceiver = XCVR_EXTERNAL;
657                                 break;
658                         }
659                 } else {
660                         ecmd->port = PORT_OTHER;
661                         ecmd->autoneg = AUTONEG_DISABLE;
662                         ecmd->transceiver = XCVR_DUMMY1;
663                 }
664
665                 /* Save for future use */
666                 adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
667                 adapter->phy.port_type = ecmd->port;
668                 adapter->phy.transceiver = ecmd->transceiver;
669                 adapter->phy.autoneg = ecmd->autoneg;
670                 adapter->phy.advertising = ecmd->advertising;
671                 adapter->phy.supported = ecmd->supported;
672         } else {
673                 ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
674                 ecmd->port = adapter->phy.port_type;
675                 ecmd->transceiver = adapter->phy.transceiver;
676                 ecmd->autoneg = adapter->phy.autoneg;
677                 ecmd->advertising = adapter->phy.advertising;
678                 ecmd->supported = adapter->phy.supported;
679         }
680
681         ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
682         ecmd->phy_address = adapter->port_num;
683
684         return 0;
685 }
686
687 static void be_get_ringparam(struct net_device *netdev,
688                              struct ethtool_ringparam *ring)
689 {
690         struct be_adapter *adapter = netdev_priv(netdev);
691
692         ring->rx_max_pending = adapter->rx_obj[0].q.len;
693         ring->rx_pending = adapter->rx_obj[0].q.len;
694         ring->tx_max_pending = adapter->tx_obj[0].q.len;
695         ring->tx_pending = adapter->tx_obj[0].q.len;
696 }
697
698 static void
699 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
700 {
701         struct be_adapter *adapter = netdev_priv(netdev);
702
703         be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
704         ecmd->autoneg = adapter->phy.fc_autoneg;
705 }
706
707 static int
708 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
709 {
710         struct be_adapter *adapter = netdev_priv(netdev);
711         int status;
712
713         if (ecmd->autoneg != adapter->phy.fc_autoneg)
714                 return -EINVAL;
715
716         status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
717                                          ecmd->rx_pause);
718         if (status) {
719                 dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
720                 return be_cmd_status(status);
721         }
722
723         adapter->tx_fc = ecmd->tx_pause;
724         adapter->rx_fc = ecmd->rx_pause;
725         return 0;
726 }
727
728 static int be_set_phys_id(struct net_device *netdev,
729                           enum ethtool_phys_id_state state)
730 {
731         struct be_adapter *adapter = netdev_priv(netdev);
732
733         switch (state) {
734         case ETHTOOL_ID_ACTIVE:
735                 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
736                                         &adapter->beacon_state);
737                 return 1;       /* cycle on/off once per second */
738
739         case ETHTOOL_ID_ON:
740                 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
741                                         BEACON_STATE_ENABLED);
742                 break;
743
744         case ETHTOOL_ID_OFF:
745                 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
746                                         BEACON_STATE_DISABLED);
747                 break;
748
749         case ETHTOOL_ID_INACTIVE:
750                 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
751                                         adapter->beacon_state);
752         }
753
754         return 0;
755 }
756
757 static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
758 {
759         struct be_adapter *adapter = netdev_priv(netdev);
760         struct device *dev = &adapter->pdev->dev;
761         int status;
762
763         if (!lancer_chip(adapter) ||
764             !check_privilege(adapter, MAX_PRIVILEGES))
765                 return -EOPNOTSUPP;
766
767         switch (dump->flag) {
768         case LANCER_INITIATE_FW_DUMP:
769                 status = lancer_initiate_dump(adapter);
770                 if (!status)
771                         dev_info(dev, "FW dump initiated successfully\n");
772                 break;
773         case LANCER_DELETE_FW_DUMP:
774                 status = lancer_delete_dump(adapter);
775                 if (!status)
776                         dev_info(dev, "FW dump deleted successfully\n");
777         break;
778         default:
779                 dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
780                 return -EINVAL;
781         }
782         return status;
783 }
784
785 static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
786 {
787         struct be_adapter *adapter = netdev_priv(netdev);
788
789         if (adapter->wol_cap & BE_WOL_CAP) {
790                 wol->supported |= WAKE_MAGIC;
791                 if (adapter->wol_en)
792                         wol->wolopts |= WAKE_MAGIC;
793         } else {
794                 wol->wolopts = 0;
795         }
796         memset(&wol->sopass, 0, sizeof(wol->sopass));
797 }
798
799 static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
800 {
801         struct be_adapter *adapter = netdev_priv(netdev);
802
803         if (wol->wolopts & ~WAKE_MAGIC)
804                 return -EOPNOTSUPP;
805
806         if (!(adapter->wol_cap & BE_WOL_CAP)) {
807                 dev_warn(&adapter->pdev->dev, "WOL not supported\n");
808                 return -EOPNOTSUPP;
809         }
810
811         if (wol->wolopts & WAKE_MAGIC)
812                 adapter->wol_en = true;
813         else
814                 adapter->wol_en = false;
815
816         return 0;
817 }
818
819 static int be_test_ddr_dma(struct be_adapter *adapter)
820 {
821         int ret, i;
822         struct be_dma_mem ddrdma_cmd;
823         static const u64 pattern[2] = {
824                 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
825         };
826
827         ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
828         ddrdma_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
829                                             ddrdma_cmd.size, &ddrdma_cmd.dma,
830                                             GFP_KERNEL);
831         if (!ddrdma_cmd.va)
832                 return -ENOMEM;
833
834         for (i = 0; i < 2; i++) {
835                 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
836                                           4096, &ddrdma_cmd);
837                 if (ret != 0)
838                         goto err;
839         }
840
841 err:
842         dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
843                           ddrdma_cmd.dma);
844         return be_cmd_status(ret);
845 }
846
847 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
848                             u64 *status)
849 {
850         be_cmd_set_loopback(adapter, adapter->hba_port_num, loopback_type, 1);
851         *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
852                                        loopback_type, 1500, 2, 0xabc);
853         be_cmd_set_loopback(adapter, adapter->hba_port_num, BE_NO_LOOPBACK, 1);
854         return *status;
855 }
856
857 static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
858                          u64 *data)
859 {
860         struct be_adapter *adapter = netdev_priv(netdev);
861         int status;
862         u8 link_status = 0;
863
864         if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
865                 dev_err(&adapter->pdev->dev, "Self test not supported\n");
866                 test->flags |= ETH_TEST_FL_FAILED;
867                 return;
868         }
869
870         memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
871
872         if (test->flags & ETH_TEST_FL_OFFLINE) {
873                 if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
874                         test->flags |= ETH_TEST_FL_FAILED;
875
876                 if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
877                         test->flags |= ETH_TEST_FL_FAILED;
878
879                 if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
880                         if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
881                                              &data[2]) != 0)
882                                 test->flags |= ETH_TEST_FL_FAILED;
883                         test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
884                 }
885         }
886
887         if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
888                 data[3] = 1;
889                 test->flags |= ETH_TEST_FL_FAILED;
890         }
891
892         status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
893         if (status) {
894                 test->flags |= ETH_TEST_FL_FAILED;
895                 data[4] = -1;
896         } else if (!link_status) {
897                 test->flags |= ETH_TEST_FL_FAILED;
898                 data[4] = 1;
899         }
900 }
901
902 static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
903 {
904         struct be_adapter *adapter = netdev_priv(netdev);
905
906         return be_load_fw(adapter, efl->data);
907 }
908
909 static int be_get_eeprom_len(struct net_device *netdev)
910 {
911         struct be_adapter *adapter = netdev_priv(netdev);
912
913         if (!check_privilege(adapter, MAX_PRIVILEGES))
914                 return 0;
915
916         if (lancer_chip(adapter)) {
917                 if (be_physfn(adapter))
918                         return lancer_cmd_get_file_len(adapter,
919                                                        LANCER_VPD_PF_FILE);
920                 else
921                         return lancer_cmd_get_file_len(adapter,
922                                                        LANCER_VPD_VF_FILE);
923         } else {
924                 return BE_READ_SEEPROM_LEN;
925         }
926 }
927
928 static int be_read_eeprom(struct net_device *netdev,
929                           struct ethtool_eeprom *eeprom, uint8_t *data)
930 {
931         struct be_adapter *adapter = netdev_priv(netdev);
932         struct be_dma_mem eeprom_cmd;
933         struct be_cmd_resp_seeprom_read *resp;
934         int status;
935
936         if (!eeprom->len)
937                 return -EINVAL;
938
939         if (lancer_chip(adapter)) {
940                 if (be_physfn(adapter))
941                         return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
942                                                     eeprom->len, data);
943                 else
944                         return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
945                                                     eeprom->len, data);
946         }
947
948         eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
949
950         memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
951         eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
952         eeprom_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
953                                             eeprom_cmd.size, &eeprom_cmd.dma,
954                                             GFP_KERNEL);
955
956         if (!eeprom_cmd.va)
957                 return -ENOMEM;
958
959         status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
960
961         if (!status) {
962                 resp = eeprom_cmd.va;
963                 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
964         }
965         dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
966                           eeprom_cmd.dma);
967
968         return be_cmd_status(status);
969 }
970
971 static u32 be_get_msg_level(struct net_device *netdev)
972 {
973         struct be_adapter *adapter = netdev_priv(netdev);
974
975         return adapter->msg_enable;
976 }
977
978 static void be_set_msg_level(struct net_device *netdev, u32 level)
979 {
980         struct be_adapter *adapter = netdev_priv(netdev);
981
982         if (adapter->msg_enable == level)
983                 return;
984
985         if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
986                 if (BEx_chip(adapter))
987                         be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
988                                                 FW_LOG_LEVEL_DEFAULT :
989                                                 FW_LOG_LEVEL_FATAL);
990         adapter->msg_enable = level;
991 }
992
993 static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
994 {
995         u64 data = 0;
996
997         switch (flow_type) {
998         case TCP_V4_FLOW:
999                 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
1000                         data |= RXH_IP_DST | RXH_IP_SRC;
1001                 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
1002                         data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1003                 break;
1004         case UDP_V4_FLOW:
1005                 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
1006                         data |= RXH_IP_DST | RXH_IP_SRC;
1007                 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
1008                         data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1009                 break;
1010         case TCP_V6_FLOW:
1011                 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1012                         data |= RXH_IP_DST | RXH_IP_SRC;
1013                 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
1014                         data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1015                 break;
1016         case UDP_V6_FLOW:
1017                 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1018                         data |= RXH_IP_DST | RXH_IP_SRC;
1019                 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
1020                         data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1021                 break;
1022         }
1023
1024         return data;
1025 }
1026
1027 static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1028                         u32 *rule_locs)
1029 {
1030         struct be_adapter *adapter = netdev_priv(netdev);
1031
1032         if (!be_multi_rxq(adapter)) {
1033                 dev_info(&adapter->pdev->dev,
1034                          "ethtool::get_rxnfc: RX flow hashing is disabled\n");
1035                 return -EINVAL;
1036         }
1037
1038         switch (cmd->cmd) {
1039         case ETHTOOL_GRXFH:
1040                 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
1041                 break;
1042         case ETHTOOL_GRXRINGS:
1043                 cmd->data = adapter->num_rx_qs - 1;
1044                 break;
1045         default:
1046                 return -EINVAL;
1047         }
1048
1049         return 0;
1050 }
1051
1052 static int be_set_rss_hash_opts(struct be_adapter *adapter,
1053                                 struct ethtool_rxnfc *cmd)
1054 {
1055         struct be_rx_obj *rxo;
1056         int status = 0, i, j;
1057         u8 rsstable[128];
1058         u32 rss_flags = adapter->rss_info.rss_flags;
1059
1060         if (cmd->data != L3_RSS_FLAGS &&
1061             cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
1062                 return -EINVAL;
1063
1064         switch (cmd->flow_type) {
1065         case TCP_V4_FLOW:
1066                 if (cmd->data == L3_RSS_FLAGS)
1067                         rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1068                 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1069                         rss_flags |= RSS_ENABLE_IPV4 |
1070                                         RSS_ENABLE_TCP_IPV4;
1071                 break;
1072         case TCP_V6_FLOW:
1073                 if (cmd->data == L3_RSS_FLAGS)
1074                         rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1075                 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1076                         rss_flags |= RSS_ENABLE_IPV6 |
1077                                         RSS_ENABLE_TCP_IPV6;
1078                 break;
1079         case UDP_V4_FLOW:
1080                 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1081                     BEx_chip(adapter))
1082                         return -EINVAL;
1083
1084                 if (cmd->data == L3_RSS_FLAGS)
1085                         rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1086                 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1087                         rss_flags |= RSS_ENABLE_IPV4 |
1088                                         RSS_ENABLE_UDP_IPV4;
1089                 break;
1090         case UDP_V6_FLOW:
1091                 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1092                     BEx_chip(adapter))
1093                         return -EINVAL;
1094
1095                 if (cmd->data == L3_RSS_FLAGS)
1096                         rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1097                 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1098                         rss_flags |= RSS_ENABLE_IPV6 |
1099                                         RSS_ENABLE_UDP_IPV6;
1100                 break;
1101         default:
1102                 return -EINVAL;
1103         }
1104
1105         if (rss_flags == adapter->rss_info.rss_flags)
1106                 return status;
1107
1108         if (be_multi_rxq(adapter)) {
1109                 for (j = 0; j < 128; j += adapter->num_rss_qs) {
1110                         for_all_rss_queues(adapter, rxo, i) {
1111                                 if ((j + i) >= 128)
1112                                         break;
1113                                 rsstable[j + i] = rxo->rss_id;
1114                         }
1115                 }
1116         }
1117
1118         status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
1119                                    rss_flags, 128, adapter->rss_info.rss_hkey);
1120         if (!status)
1121                 adapter->rss_info.rss_flags = rss_flags;
1122
1123         return be_cmd_status(status);
1124 }
1125
1126 static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1127 {
1128         struct be_adapter *adapter = netdev_priv(netdev);
1129         int status = 0;
1130
1131         if (!be_multi_rxq(adapter)) {
1132                 dev_err(&adapter->pdev->dev,
1133                         "ethtool::set_rxnfc: RX flow hashing is disabled\n");
1134                 return -EINVAL;
1135         }
1136
1137         switch (cmd->cmd) {
1138         case ETHTOOL_SRXFH:
1139                 status = be_set_rss_hash_opts(adapter, cmd);
1140                 break;
1141         default:
1142                 return -EINVAL;
1143         }
1144
1145         return status;
1146 }
1147
1148 static void be_get_channels(struct net_device *netdev,
1149                             struct ethtool_channels *ch)
1150 {
1151         struct be_adapter *adapter = netdev_priv(netdev);
1152
1153         ch->combined_count = adapter->num_evt_qs;
1154         ch->max_combined = be_max_qs(adapter);
1155 }
1156
1157 static int be_set_channels(struct net_device  *netdev,
1158                            struct ethtool_channels *ch)
1159 {
1160         struct be_adapter *adapter = netdev_priv(netdev);
1161         int status;
1162
1163         if (ch->rx_count || ch->tx_count || ch->other_count ||
1164             !ch->combined_count || ch->combined_count > be_max_qs(adapter))
1165                 return -EINVAL;
1166
1167         adapter->cfg_num_qs = ch->combined_count;
1168
1169         status = be_update_queues(adapter);
1170         return be_cmd_status(status);
1171 }
1172
1173 static u32 be_get_rxfh_indir_size(struct net_device *netdev)
1174 {
1175         return RSS_INDIR_TABLE_LEN;
1176 }
1177
1178 static u32 be_get_rxfh_key_size(struct net_device *netdev)
1179 {
1180         return RSS_HASH_KEY_LEN;
1181 }
1182
1183 static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
1184                        u8 *hfunc)
1185 {
1186         struct be_adapter *adapter = netdev_priv(netdev);
1187         int i;
1188         struct rss_info *rss = &adapter->rss_info;
1189
1190         if (indir) {
1191                 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
1192                         indir[i] = rss->rss_queue[i];
1193         }
1194
1195         if (hkey)
1196                 memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
1197
1198         if (hfunc)
1199                 *hfunc = ETH_RSS_HASH_TOP;
1200
1201         return 0;
1202 }
1203
1204 static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
1205                        const u8 *hkey, const u8 hfunc)
1206 {
1207         int rc = 0, i, j;
1208         struct be_adapter *adapter = netdev_priv(netdev);
1209         u8 rsstable[RSS_INDIR_TABLE_LEN];
1210
1211         /* We do not allow change in unsupported parameters */
1212         if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1213                 return -EOPNOTSUPP;
1214
1215         if (indir) {
1216                 struct be_rx_obj *rxo;
1217
1218                 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
1219                         j = indir[i];
1220                         rxo = &adapter->rx_obj[j];
1221                         rsstable[i] = rxo->rss_id;
1222                         adapter->rss_info.rss_queue[i] = j;
1223                 }
1224         } else {
1225                 memcpy(rsstable, adapter->rss_info.rsstable,
1226                        RSS_INDIR_TABLE_LEN);
1227         }
1228
1229         if (!hkey)
1230                 hkey =  adapter->rss_info.rss_hkey;
1231
1232         rc = be_cmd_rss_config(adapter, rsstable,
1233                                adapter->rss_info.rss_flags,
1234                                RSS_INDIR_TABLE_LEN, hkey);
1235         if (rc) {
1236                 adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
1237                 return -EIO;
1238         }
1239         memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
1240         memcpy(adapter->rss_info.rsstable, rsstable,
1241                RSS_INDIR_TABLE_LEN);
1242         return 0;
1243 }
1244
1245 static int be_get_module_info(struct net_device *netdev,
1246                               struct ethtool_modinfo *modinfo)
1247 {
1248         struct be_adapter *adapter = netdev_priv(netdev);
1249         u8 page_data[PAGE_DATA_LEN];
1250         int status;
1251
1252         if (!check_privilege(adapter, MAX_PRIVILEGES))
1253                 return -EOPNOTSUPP;
1254
1255         status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1256                                                    page_data);
1257         if (!status) {
1258                 if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
1259                         modinfo->type = ETH_MODULE_SFF_8079;
1260                         modinfo->eeprom_len = PAGE_DATA_LEN;
1261                 } else {
1262                         modinfo->type = ETH_MODULE_SFF_8472;
1263                         modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
1264                 }
1265         }
1266         return be_cmd_status(status);
1267 }
1268
1269 static int be_get_module_eeprom(struct net_device *netdev,
1270                                 struct ethtool_eeprom *eeprom, u8 *data)
1271 {
1272         struct be_adapter *adapter = netdev_priv(netdev);
1273         int status;
1274
1275         if (!check_privilege(adapter, MAX_PRIVILEGES))
1276                 return -EOPNOTSUPP;
1277
1278         status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1279                                                    data);
1280         if (status)
1281                 goto err;
1282
1283         if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
1284                 status = be_cmd_read_port_transceiver_data(adapter,
1285                                                            TR_PAGE_A2,
1286                                                            data +
1287                                                            PAGE_DATA_LEN);
1288                 if (status)
1289                         goto err;
1290         }
1291         if (eeprom->offset)
1292                 memcpy(data, data + eeprom->offset, eeprom->len);
1293 err:
1294         return be_cmd_status(status);
1295 }
1296
1297 const struct ethtool_ops be_ethtool_ops = {
1298         .get_settings = be_get_settings,
1299         .get_drvinfo = be_get_drvinfo,
1300         .get_wol = be_get_wol,
1301         .set_wol = be_set_wol,
1302         .get_link = ethtool_op_get_link,
1303         .get_eeprom_len = be_get_eeprom_len,
1304         .get_eeprom = be_read_eeprom,
1305         .get_coalesce = be_get_coalesce,
1306         .set_coalesce = be_set_coalesce,
1307         .get_ringparam = be_get_ringparam,
1308         .get_pauseparam = be_get_pauseparam,
1309         .set_pauseparam = be_set_pauseparam,
1310         .get_strings = be_get_stat_strings,
1311         .set_phys_id = be_set_phys_id,
1312         .set_dump = be_set_dump,
1313         .get_msglevel = be_get_msg_level,
1314         .set_msglevel = be_set_msg_level,
1315         .get_sset_count = be_get_sset_count,
1316         .get_ethtool_stats = be_get_ethtool_stats,
1317         .get_regs_len = be_get_reg_len,
1318         .get_regs = be_get_regs,
1319         .flash_device = be_do_flash,
1320         .self_test = be_self_test,
1321         .get_rxnfc = be_get_rxnfc,
1322         .set_rxnfc = be_set_rxnfc,
1323         .get_rxfh_indir_size = be_get_rxfh_indir_size,
1324         .get_rxfh_key_size = be_get_rxfh_key_size,
1325         .get_rxfh = be_get_rxfh,
1326         .set_rxfh = be_set_rxfh,
1327         .get_channels = be_get_channels,
1328         .set_channels = be_set_channels,
1329         .get_module_info = be_get_module_info,
1330         .get_module_eeprom = be_get_module_eeprom
1331 };