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