Merge remote-tracking branch 'mmc-uh/next'
[deliverable/linux.git] / drivers / net / ethernet / emulex / benet / be_ethtool.c
CommitLineData
6b7c5b94 1/*
7dfbe7d7 2 * Copyright (C) 2005 - 2016 Broadcom
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;
de49bd5a
PR
244
245 memset(&data_len_cmd, 0, sizeof(data_len_cmd));
246 /* data_offset and data_size should be 0 to get reg len */
d37b4c0a
IV
247 lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0, file_name,
248 &data_read, &eof, &addn_status);
de49bd5a
PR
249
250 return data_read;
251}
252
fd7ff6f0
VD
253static int be_get_dump_len(struct be_adapter *adapter)
254{
255 u32 dump_size = 0;
256
257 if (lancer_chip(adapter))
258 dump_size = lancer_cmd_get_file_len(adapter,
259 LANCER_FW_DUMP_FILE);
260 else
261 dump_size = adapter->fat_dump_len;
262
263 return dump_size;
264}
265
05e4c6a3
SP
266static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
267 u32 buf_len, void *buf)
de49bd5a
PR
268{
269 struct be_dma_mem read_cmd;
270 u32 read_len = 0, total_read_len = 0, chunk_size;
271 u32 eof = 0;
272 u8 addn_status;
273 int status = 0;
274
275 read_cmd.size = LANCER_READ_FILE_CHUNK;
e51000db
SB
276 read_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, read_cmd.size,
277 &read_cmd.dma, GFP_ATOMIC);
de49bd5a
PR
278
279 if (!read_cmd.va) {
280 dev_err(&adapter->pdev->dev,
05e4c6a3 281 "Memory allocation failure while reading dump\n");
de49bd5a
PR
282 return -ENOMEM;
283 }
284
285 while ((total_read_len < buf_len) && !eof) {
286 chunk_size = min_t(u32, (buf_len - total_read_len),
cd3307aa 287 LANCER_READ_FILE_CHUNK);
de49bd5a
PR
288 chunk_size = ALIGN(chunk_size, 4);
289 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
05e4c6a3
SP
290 total_read_len, file_name,
291 &read_len, &eof, &addn_status);
de49bd5a
PR
292 if (!status) {
293 memcpy(buf + total_read_len, read_cmd.va, read_len);
294 total_read_len += read_len;
295 eof &= LANCER_READ_FILE_EOF_MASK;
296 } else {
297 status = -EIO;
298 break;
299 }
300 }
e51000db
SB
301 dma_free_coherent(&adapter->pdev->dev, read_cmd.size, read_cmd.va,
302 read_cmd.dma);
de49bd5a
PR
303
304 return status;
305}
306
fd7ff6f0
VD
307static int be_read_dump_data(struct be_adapter *adapter, u32 dump_len,
308 void *buf)
311fddc7 309{
fd7ff6f0 310 int status = 0;
311fddc7 311
fd7ff6f0
VD
312 if (lancer_chip(adapter))
313 status = lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
314 dump_len, buf);
315 else
316 status = be_cmd_get_fat_dump(adapter, dump_len, buf);
311fddc7 317
fd7ff6f0 318 return status;
311fddc7
SK
319}
320
10ef9ab4
SP
321static int be_get_coalesce(struct net_device *netdev,
322 struct ethtool_coalesce *et)
6b7c5b94
SP
323{
324 struct be_adapter *adapter = netdev_priv(netdev);
2632bafd 325 struct be_aic_obj *aic = &adapter->aic_obj[0];
10ef9ab4 326
2632bafd
SP
327 et->rx_coalesce_usecs = aic->prev_eqd;
328 et->rx_coalesce_usecs_high = aic->max_eqd;
329 et->rx_coalesce_usecs_low = aic->min_eqd;
6b7c5b94 330
2632bafd
SP
331 et->tx_coalesce_usecs = aic->prev_eqd;
332 et->tx_coalesce_usecs_high = aic->max_eqd;
333 et->tx_coalesce_usecs_low = aic->min_eqd;
6b7c5b94 334
2632bafd
SP
335 et->use_adaptive_rx_coalesce = aic->enable;
336 et->use_adaptive_tx_coalesce = aic->enable;
6b7c5b94
SP
337
338 return 0;
339}
340
10ef9ab4
SP
341/* TX attributes are ignored. Only RX attributes are considered
342 * eqd cmd is issued in the worker thread.
6b7c5b94 343 */
10ef9ab4
SP
344static int be_set_coalesce(struct net_device *netdev,
345 struct ethtool_coalesce *et)
6b7c5b94
SP
346{
347 struct be_adapter *adapter = netdev_priv(netdev);
2632bafd 348 struct be_aic_obj *aic = &adapter->aic_obj[0];
10ef9ab4
SP
349 struct be_eq_obj *eqo;
350 int i;
351
352 for_all_evt_queues(adapter, eqo, i) {
2632bafd
SP
353 aic->enable = et->use_adaptive_rx_coalesce;
354 aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
355 aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
356 aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
357 aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
358 aic++;
6b7c5b94
SP
359 }
360
20947770
PR
361 /* For Skyhawk, the EQD setting happens via EQ_DB when AIC is enabled.
362 * When AIC is disabled, persistently force set EQD value via the
363 * FW cmd, so that we don't have to calculate the delay multiplier
364 * encode value each time EQ_DB is rung
365 */
366 if (!et->use_adaptive_rx_coalesce && skyhawk_chip(adapter))
367 be_eqd_update(adapter, true);
368
6b7c5b94
SP
369 return 0;
370}
371
05e4c6a3
SP
372static void be_get_ethtool_stats(struct net_device *netdev,
373 struct ethtool_stats *stats, uint64_t *data)
6b7c5b94
SP
374{
375 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 376 struct be_rx_obj *rxo;
3c8def97 377 struct be_tx_obj *txo;
ac124ff9 378 void *p;
ab1594e9 379 unsigned int i, j, base = 0, start;
6b7c5b94
SP
380
381 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
ac124ff9 382 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
ab1594e9 383 data[i] = *(u32 *)p;
6b7c5b94 384 }
ab1594e9 385 base += ETHTOOL_STATS_NUM;
3abcdeda
SP
386
387 for_all_rx_queues(adapter, rxo, j) {
ab1594e9
SP
388 struct be_rx_stats *stats = rx_stats(rxo);
389
390 do {
57a7744e 391 start = u64_stats_fetch_begin_irq(&stats->sync);
ab1594e9
SP
392 data[base] = stats->rx_bytes;
393 data[base + 1] = stats->rx_pkts;
57a7744e 394 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
ab1594e9
SP
395
396 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
397 p = (u8 *)stats + et_rx_stats[i].offset;
398 data[base + i] = *(u32 *)p;
3abcdeda 399 }
ab1594e9 400 base += ETHTOOL_RXSTATS_NUM;
3abcdeda 401 }
3c8def97 402
3c8def97 403 for_all_tx_queues(adapter, txo, j) {
ab1594e9
SP
404 struct be_tx_stats *stats = tx_stats(txo);
405
406 do {
57a7744e 407 start = u64_stats_fetch_begin_irq(&stats->sync_compl);
ab1594e9 408 data[base] = stats->tx_compl;
57a7744e 409 } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
ab1594e9
SP
410
411 do {
57a7744e 412 start = u64_stats_fetch_begin_irq(&stats->sync);
ab1594e9
SP
413 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
414 p = (u8 *)stats + et_tx_stats[i].offset;
415 data[base + i] =
416 (et_tx_stats[i].size == sizeof(u64)) ?
417 *(u64 *)p : *(u32 *)p;
418 }
57a7744e 419 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
ab1594e9 420 base += ETHTOOL_TXSTATS_NUM;
3c8def97 421 }
6b7c5b94
SP
422}
423
710f3e59
SB
424static const char be_priv_flags[][ETH_GSTRING_LEN] = {
425 "disable-tpe-recovery"
426};
427
05e4c6a3
SP
428static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
429 uint8_t *data)
6b7c5b94 430{
3abcdeda
SP
431 struct be_adapter *adapter = netdev_priv(netdev);
432 int i, j;
433
6b7c5b94
SP
434 switch (stringset) {
435 case ETH_SS_STATS:
436 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
437 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
438 data += ETH_GSTRING_LEN;
439 }
3abcdeda
SP
440 for (i = 0; i < adapter->num_rx_qs; i++) {
441 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
442 sprintf(data, "rxq%d: %s", i,
443 et_rx_stats[j].desc);
444 data += ETH_GSTRING_LEN;
445 }
446 }
3c8def97
SP
447 for (i = 0; i < adapter->num_tx_qs; i++) {
448 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
449 sprintf(data, "txq%d: %s", i,
450 et_tx_stats[j].desc);
451 data += ETH_GSTRING_LEN;
452 }
453 }
6b7c5b94 454 break;
ff33a6e2
S
455 case ETH_SS_TEST:
456 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
457 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
458 data += ETH_GSTRING_LEN;
459 }
460 break;
710f3e59
SB
461 case ETH_SS_PRIV_FLAGS:
462 for (i = 0; i < ARRAY_SIZE(be_priv_flags); i++)
463 strcpy(data + i * ETH_GSTRING_LEN, be_priv_flags[i]);
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;
710f3e59
SB
479 case ETH_SS_PRIV_FLAGS:
480 return ARRAY_SIZE(be_priv_flags);
15f0a394
BH
481 default:
482 return -EINVAL;
483 }
6b7c5b94
SP
484}
485
6809cee0 486static u32 be_get_port_type(struct be_adapter *adapter)
42f11cf2
AK
487{
488 u32 port;
489
6809cee0 490 switch (adapter->phy.interface_type) {
42f11cf2
AK
491 case PHY_TYPE_BASET_1GB:
492 case PHY_TYPE_BASEX_1GB:
493 case PHY_TYPE_SGMII:
494 port = PORT_TP;
495 break;
496 case PHY_TYPE_SFP_PLUS_10GB:
6809cee0
RN
497 if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE)
498 port = PORT_DA;
499 else
500 port = PORT_FIBRE;
501 break;
502 case PHY_TYPE_QSFP:
503 if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE)
504 port = PORT_DA;
505 else
506 port = PORT_FIBRE;
42f11cf2
AK
507 break;
508 case PHY_TYPE_XFP_10GB:
509 case PHY_TYPE_SFP_1GB:
510 port = PORT_FIBRE;
511 break;
512 case PHY_TYPE_BASET_10GB:
513 port = PORT_TP;
514 break;
515 default:
516 port = PORT_OTHER;
517 }
518
519 return port;
520}
521
6809cee0 522static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
42f11cf2
AK
523{
524 u32 val = 0;
525
6809cee0 526 switch (adapter->phy.interface_type) {
42f11cf2
AK
527 case PHY_TYPE_BASET_1GB:
528 case PHY_TYPE_BASEX_1GB:
529 case PHY_TYPE_SGMII:
530 val |= SUPPORTED_TP;
531 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
532 val |= SUPPORTED_1000baseT_Full;
533 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
534 val |= SUPPORTED_100baseT_Full;
535 if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
536 val |= SUPPORTED_10baseT_Full;
537 break;
538 case PHY_TYPE_KX4_10GB:
539 val |= SUPPORTED_Backplane;
540 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
541 val |= SUPPORTED_1000baseKX_Full;
542 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
543 val |= SUPPORTED_10000baseKX4_Full;
544 break;
d6b7a9b7
VV
545 case PHY_TYPE_KR2_20GB:
546 val |= SUPPORTED_Backplane;
547 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
548 val |= SUPPORTED_10000baseKR_Full;
549 if (if_speeds & BE_SUPPORTED_SPEED_20GBPS)
550 val |= SUPPORTED_20000baseKR2_Full;
551 break;
42f11cf2
AK
552 case PHY_TYPE_KR_10GB:
553 val |= SUPPORTED_Backplane |
554 SUPPORTED_10000baseKR_Full;
555 break;
ca39076c
KA
556 case PHY_TYPE_KR4_40GB:
557 val |= SUPPORTED_Backplane;
558 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
559 val |= SUPPORTED_10000baseKR_Full;
560 if (if_speeds & BE_SUPPORTED_SPEED_40GBPS)
561 val |= SUPPORTED_40000baseKR4_Full;
562 break;
6809cee0
RN
563 case PHY_TYPE_QSFP:
564 if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) {
565 switch (adapter->phy.cable_type) {
566 case QSFP_PLUS_CR4_CABLE:
567 val |= SUPPORTED_40000baseCR4_Full;
568 break;
569 case QSFP_PLUS_LR4_CABLE:
570 val |= SUPPORTED_40000baseLR4_Full;
571 break;
572 default:
573 val |= SUPPORTED_40000baseSR4_Full;
574 break;
575 }
576 }
42f11cf2
AK
577 case PHY_TYPE_SFP_PLUS_10GB:
578 case PHY_TYPE_XFP_10GB:
579 case PHY_TYPE_SFP_1GB:
580 val |= SUPPORTED_FIBRE;
581 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
582 val |= SUPPORTED_10000baseT_Full;
583 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
584 val |= SUPPORTED_1000baseT_Full;
585 break;
586 case PHY_TYPE_BASET_10GB:
587 val |= SUPPORTED_TP;
588 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
589 val |= SUPPORTED_10000baseT_Full;
590 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
591 val |= SUPPORTED_1000baseT_Full;
592 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
593 val |= SUPPORTED_100baseT_Full;
594 break;
595 default:
596 val |= SUPPORTED_TP;
597 }
598
599 return val;
600}
601
42f11cf2
AK
602bool be_pause_supported(struct be_adapter *adapter)
603{
604 return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
605 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
606 false : true;
607}
608
6b7c5b94
SP
609static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
610{
0388f251 611 struct be_adapter *adapter = netdev_priv(netdev);
b236916a 612 u8 link_status;
323ff71e 613 u16 link_speed = 0;
0dffc83e 614 int status;
db15dfa9
PR
615 u32 auto_speeds;
616 u32 fixed_speeds;
0dffc83e 617
323ff71e
SP
618 if (adapter->phy.link_speed < 0) {
619 status = be_cmd_link_status_query(adapter, &link_speed,
620 &link_status, 0);
621 if (!status)
622 be_link_status_update(adapter, link_status);
623 ethtool_cmd_speed_set(ecmd, link_speed);
42f11cf2
AK
624
625 status = be_cmd_get_phy_info(adapter);
db15dfa9 626 if (!status) {
db15dfa9
PR
627 auto_speeds = adapter->phy.auto_speeds_supported;
628 fixed_speeds = adapter->phy.fixed_speeds_supported;
6809cee0
RN
629
630 be_cmd_query_cable_type(adapter);
db15dfa9
PR
631
632 ecmd->supported =
6809cee0 633 convert_to_et_setting(adapter,
db15dfa9
PR
634 auto_speeds |
635 fixed_speeds);
636 ecmd->advertising =
6809cee0 637 convert_to_et_setting(adapter, auto_speeds);
db15dfa9 638
6809cee0 639 ecmd->port = be_get_port_type(adapter);
db15dfa9
PR
640
641 if (adapter->phy.auto_speeds_supported) {
642 ecmd->supported |= SUPPORTED_Autoneg;
643 ecmd->autoneg = AUTONEG_ENABLE;
644 ecmd->advertising |= ADVERTISED_Autoneg;
645 }
42f11cf2 646
42f11cf2 647 ecmd->supported |= SUPPORTED_Pause;
db15dfa9
PR
648 if (be_pause_supported(adapter))
649 ecmd->advertising |= ADVERTISED_Pause;
650
651 switch (adapter->phy.interface_type) {
652 case PHY_TYPE_KR_10GB:
653 case PHY_TYPE_KX4_10GB:
654 ecmd->transceiver = XCVR_INTERNAL;
655 break;
656 default:
657 ecmd->transceiver = XCVR_EXTERNAL;
658 break;
659 }
660 } else {
661 ecmd->port = PORT_OTHER;
662 ecmd->autoneg = AUTONEG_DISABLE;
663 ecmd->transceiver = XCVR_DUMMY1;
0388f251 664 }
0dffc83e
AK
665
666 /* Save for future use */
42f11cf2
AK
667 adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
668 adapter->phy.port_type = ecmd->port;
669 adapter->phy.transceiver = ecmd->transceiver;
670 adapter->phy.autoneg = ecmd->autoneg;
671 adapter->phy.advertising = ecmd->advertising;
672 adapter->phy.supported = ecmd->supported;
0dffc83e 673 } else {
42f11cf2
AK
674 ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
675 ecmd->port = adapter->phy.port_type;
676 ecmd->transceiver = adapter->phy.transceiver;
677 ecmd->autoneg = adapter->phy.autoneg;
678 ecmd->advertising = adapter->phy.advertising;
679 ecmd->supported = adapter->phy.supported;
0388f251 680 }
0dffc83e 681
682256db 682 ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
0388f251 683 ecmd->phy_address = adapter->port_num;
ee3cb629 684
6b7c5b94
SP
685 return 0;
686}
687
110b82bc
SP
688static void be_get_ringparam(struct net_device *netdev,
689 struct ethtool_ringparam *ring)
6b7c5b94
SP
690{
691 struct be_adapter *adapter = netdev_priv(netdev);
692
5f820b6c
KA
693 ring->rx_max_pending = adapter->rx_obj[0].q.len;
694 ring->rx_pending = adapter->rx_obj[0].q.len;
695 ring->tx_max_pending = adapter->tx_obj[0].q.len;
696 ring->tx_pending = adapter->tx_obj[0].q.len;
6b7c5b94
SP
697}
698
699static void
700be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
701{
702 struct be_adapter *adapter = netdev_priv(netdev);
703
8788fdc2 704 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
42f11cf2 705 ecmd->autoneg = adapter->phy.fc_autoneg;
6b7c5b94
SP
706}
707
708static int
709be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
710{
711 struct be_adapter *adapter = netdev_priv(netdev);
712 int status;
713
c871c5f2 714 if (ecmd->autoneg != adapter->phy.fc_autoneg)
6b7c5b94
SP
715 return -EINVAL;
716
00d594c3
KA
717 status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
718 ecmd->rx_pause);
719 if (status) {
50762667 720 dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
00d594c3
KA
721 return be_cmd_status(status);
722 }
6b7c5b94 723
00d594c3
KA
724 adapter->tx_fc = ecmd->tx_pause;
725 adapter->rx_fc = ecmd->rx_pause;
726 return 0;
6b7c5b94
SP
727}
728
05e4c6a3
SP
729static int be_set_phys_id(struct net_device *netdev,
730 enum ethtool_phys_id_state state)
fad9ab2c
SB
731{
732 struct be_adapter *adapter = netdev_priv(netdev);
a5a773a5 733 int status = 0;
fad9ab2c 734
1a642469 735 switch (state) {
736 case ETHTOOL_ID_ACTIVE:
a5a773a5
SR
737 status = be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
738 &adapter->beacon_state);
739 if (status)
740 return be_cmd_status(status);
741 return 1; /* cycle on/off once per second */
fad9ab2c 742
1a642469 743 case ETHTOOL_ID_ON:
a5a773a5
SR
744 status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
745 0, 0, BEACON_STATE_ENABLED);
1a642469 746 break;
fad9ab2c 747
1a642469 748 case ETHTOOL_ID_OFF:
a5a773a5
SR
749 status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
750 0, 0, BEACON_STATE_DISABLED);
1a642469 751 break;
fad9ab2c 752
1a642469 753 case ETHTOOL_ID_INACTIVE:
a5a773a5
SR
754 status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
755 0, 0, adapter->beacon_state);
1a642469 756 }
fad9ab2c 757
a5a773a5 758 return be_cmd_status(status);
fad9ab2c
SB
759}
760
5c510811
SK
761static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
762{
763 struct be_adapter *adapter = netdev_priv(netdev);
764 struct device *dev = &adapter->pdev->dev;
765 int status;
766
f0613380
KA
767 if (!lancer_chip(adapter) ||
768 !check_privilege(adapter, MAX_PRIVILEGES))
5c510811 769 return -EOPNOTSUPP;
5c510811
SK
770
771 switch (dump->flag) {
772 case LANCER_INITIATE_FW_DUMP:
773 status = lancer_initiate_dump(adapter);
774 if (!status)
f0613380 775 dev_info(dev, "FW dump initiated successfully\n");
5c510811 776 break;
f0613380
KA
777 case LANCER_DELETE_FW_DUMP:
778 status = lancer_delete_dump(adapter);
779 if (!status)
780 dev_info(dev, "FW dump deleted successfully\n");
781 break;
5c510811
SK
782 default:
783 dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
784 return -EINVAL;
785 }
786 return status;
787}
dcf96f1f 788
05e4c6a3 789static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
71d8d1b5
AK
790{
791 struct be_adapter *adapter = netdev_priv(netdev);
792
76a9e08e 793 if (adapter->wol_cap & BE_WOL_CAP) {
4762f6ce 794 wol->supported |= WAKE_MAGIC;
76a9e08e 795 if (adapter->wol_en)
b424332d 796 wol->wolopts |= WAKE_MAGIC;
76a9e08e 797 } else {
71d8d1b5 798 wol->wolopts = 0;
76a9e08e 799 }
71d8d1b5 800 memset(&wol->sopass, 0, sizeof(wol->sopass));
71d8d1b5
AK
801}
802
05e4c6a3 803static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
71d8d1b5
AK
804{
805 struct be_adapter *adapter = netdev_priv(netdev);
45f13df7
SB
806 struct device *dev = &adapter->pdev->dev;
807 struct be_dma_mem cmd;
808 u8 mac[ETH_ALEN];
809 bool enable;
810 int status;
71d8d1b5
AK
811
812 if (wol->wolopts & ~WAKE_MAGIC)
4762f6ce
AK
813 return -EOPNOTSUPP;
814
76a9e08e 815 if (!(adapter->wol_cap & BE_WOL_CAP)) {
4762f6ce
AK
816 dev_warn(&adapter->pdev->dev, "WOL not supported\n");
817 return -EOPNOTSUPP;
818 }
71d8d1b5 819
45f13df7
SB
820 cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config);
821 cmd.va = dma_zalloc_coherent(dev, cmd.size, &cmd.dma, GFP_KERNEL);
822 if (!cmd.va)
823 return -ENOMEM;
71d8d1b5 824
45f13df7
SB
825 eth_zero_addr(mac);
826
827 enable = wol->wolopts & WAKE_MAGIC;
828 if (enable)
829 ether_addr_copy(mac, adapter->netdev->dev_addr);
830
831 status = be_cmd_enable_magic_wol(adapter, mac, &cmd);
832 if (status) {
833 dev_err(dev, "Could not set Wake-on-lan mac address\n");
834 status = be_cmd_status(status);
835 goto err;
836 }
837
838 pci_enable_wake(adapter->pdev, PCI_D3hot, enable);
839 pci_enable_wake(adapter->pdev, PCI_D3cold, enable);
840
841 adapter->wol_en = enable ? true : false;
842
843err:
844 dma_free_coherent(dev, cmd.size, cmd.va, cmd.dma);
845 return status;
71d8d1b5
AK
846}
847
05e4c6a3 848static int be_test_ddr_dma(struct be_adapter *adapter)
ff33a6e2
S
849{
850 int ret, i;
851 struct be_dma_mem ddrdma_cmd;
215faf9c
JP
852 static const u64 pattern[2] = {
853 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
854 };
ff33a6e2
S
855
856 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
e51000db
SB
857 ddrdma_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
858 ddrdma_cmd.size, &ddrdma_cmd.dma,
859 GFP_KERNEL);
d0320f75 860 if (!ddrdma_cmd.va)
ff33a6e2 861 return -ENOMEM;
ff33a6e2
S
862
863 for (i = 0; i < 2; i++) {
864 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
05e4c6a3 865 4096, &ddrdma_cmd);
ff33a6e2
S
866 if (ret != 0)
867 goto err;
868 }
869
870err:
2b7bcebf
IV
871 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
872 ddrdma_cmd.dma);
0532d4e3 873 return be_cmd_status(ret);
ff33a6e2
S
874}
875
fced9999 876static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
05e4c6a3 877 u64 *status)
fced9999 878{
9c855975
SR
879 int ret;
880
881 ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
882 loopback_type, 1);
883 if (ret)
884 return ret;
885
9e1453c5 886 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
05e4c6a3 887 loopback_type, 1500, 2, 0xabc);
9c855975
SR
888
889 ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
890 BE_NO_LOOPBACK, 1);
891 if (ret)
892 return ret;
893
fced9999
SB
894 return *status;
895}
896
05e4c6a3
SP
897static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
898 u64 *data)
ff33a6e2
S
899{
900 struct be_adapter *adapter = netdev_priv(netdev);
323ff71e
SP
901 int status;
902 u8 link_status = 0;
ff33a6e2 903
78d0b11d
SR
904 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
905 dev_err(&adapter->pdev->dev, "Self test not supported\n");
906 test->flags |= ETH_TEST_FL_FAILED;
907 return;
908 }
909
ff33a6e2
S
910 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
911
912 if (test->flags & ETH_TEST_FL_OFFLINE) {
05e4c6a3 913 if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
ff33a6e2 914 test->flags |= ETH_TEST_FL_FAILED;
5a8a1ab7 915
05e4c6a3 916 if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
ff33a6e2 917 test->flags |= ETH_TEST_FL_FAILED;
5a8a1ab7
IV
918
919 if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
920 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
921 &data[2]) != 0)
922 test->flags |= ETH_TEST_FL_FAILED;
923 test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
fced9999 924 }
8f47afe0 925 }
ff33a6e2 926
a7047394 927 if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
8f47afe0
SB
928 data[3] = 1;
929 test->flags |= ETH_TEST_FL_FAILED;
ff33a6e2
S
930 }
931
323ff71e
SP
932 status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
933 if (status) {
4276e47e
SB
934 test->flags |= ETH_TEST_FL_FAILED;
935 data[4] = -1;
323ff71e 936 } else if (!link_status) {
4ee77214 937 test->flags |= ETH_TEST_FL_FAILED;
4276e47e
SB
938 data[4] = 1;
939 }
ff33a6e2
S
940}
941
05e4c6a3 942static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
84517482
AK
943{
944 struct be_adapter *adapter = netdev_priv(netdev);
84517482 945
786f5281 946 return be_load_fw(adapter, efl->data);
84517482
AK
947}
948
fd7ff6f0
VD
949static int
950be_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
951{
952 struct be_adapter *adapter = netdev_priv(netdev);
953
954 if (!check_privilege(adapter, MAX_PRIVILEGES))
955 return -EOPNOTSUPP;
956
957 dump->len = be_get_dump_len(adapter);
958 dump->version = 1;
959 dump->flag = 0x1; /* FW dump is enabled */
960 return 0;
961}
962
963static int
964be_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
965 void *buf)
966{
967 struct be_adapter *adapter = netdev_priv(netdev);
968 int status;
969
970 if (!check_privilege(adapter, MAX_PRIVILEGES))
971 return -EOPNOTSUPP;
972
973 status = be_read_dump_data(adapter, dump->len, buf);
974 return be_cmd_status(status);
975}
976
05e4c6a3 977static int be_get_eeprom_len(struct net_device *netdev)
368c0ca2 978{
af5875bd 979 struct be_adapter *adapter = netdev_priv(netdev);
f25b119c
PR
980
981 if (!check_privilege(adapter, MAX_PRIVILEGES))
982 return 0;
983
af5875bd
PR
984 if (lancer_chip(adapter)) {
985 if (be_physfn(adapter))
986 return lancer_cmd_get_file_len(adapter,
05e4c6a3 987 LANCER_VPD_PF_FILE);
af5875bd
PR
988 else
989 return lancer_cmd_get_file_len(adapter,
05e4c6a3 990 LANCER_VPD_VF_FILE);
af5875bd
PR
991 } else {
992 return BE_READ_SEEPROM_LEN;
993 }
368c0ca2
SB
994}
995
05e4c6a3
SP
996static int be_read_eeprom(struct net_device *netdev,
997 struct ethtool_eeprom *eeprom, uint8_t *data)
368c0ca2
SB
998{
999 struct be_adapter *adapter = netdev_priv(netdev);
1000 struct be_dma_mem eeprom_cmd;
1001 struct be_cmd_resp_seeprom_read *resp;
1002 int status;
1003
1004 if (!eeprom->len)
1005 return -EINVAL;
1006
af5875bd
PR
1007 if (lancer_chip(adapter)) {
1008 if (be_physfn(adapter))
1009 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
05e4c6a3 1010 eeprom->len, data);
af5875bd
PR
1011 else
1012 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
05e4c6a3 1013 eeprom->len, data);
af5875bd
PR
1014 }
1015
368c0ca2
SB
1016 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
1017
1018 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
1019 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
e51000db
SB
1020 eeprom_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
1021 eeprom_cmd.size, &eeprom_cmd.dma,
1022 GFP_KERNEL);
368c0ca2 1023
d0320f75 1024 if (!eeprom_cmd.va)
368c0ca2 1025 return -ENOMEM;
368c0ca2
SB
1026
1027 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
1028
1029 if (!status) {
43d620c8 1030 resp = eeprom_cmd.va;
c0ad9845 1031 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
368c0ca2 1032 }
2b7bcebf
IV
1033 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
1034 eeprom_cmd.dma);
368c0ca2 1035
0532d4e3 1036 return be_cmd_status(status);
368c0ca2
SB
1037}
1038
941a77d5
SK
1039static u32 be_get_msg_level(struct net_device *netdev)
1040{
1041 struct be_adapter *adapter = netdev_priv(netdev);
1042
941a77d5
SK
1043 return adapter->msg_enable;
1044}
1045
941a77d5
SK
1046static void be_set_msg_level(struct net_device *netdev, u32 level)
1047{
1048 struct be_adapter *adapter = netdev_priv(netdev);
1049
941a77d5
SK
1050 if (adapter->msg_enable == level)
1051 return;
1052
1053 if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
baaa08d1
VV
1054 if (BEx_chip(adapter))
1055 be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
1056 FW_LOG_LEVEL_DEFAULT :
1057 FW_LOG_LEVEL_FATAL);
941a77d5 1058 adapter->msg_enable = level;
941a77d5
SK
1059}
1060
594ad54a
SR
1061static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
1062{
1063 u64 data = 0;
1064
1065 switch (flow_type) {
1066 case TCP_V4_FLOW:
e2557877 1067 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
594ad54a 1068 data |= RXH_IP_DST | RXH_IP_SRC;
e2557877 1069 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
594ad54a
SR
1070 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1071 break;
1072 case UDP_V4_FLOW:
e2557877 1073 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
594ad54a 1074 data |= RXH_IP_DST | RXH_IP_SRC;
e2557877 1075 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
594ad54a
SR
1076 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1077 break;
1078 case TCP_V6_FLOW:
e2557877 1079 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
594ad54a 1080 data |= RXH_IP_DST | RXH_IP_SRC;
e2557877 1081 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
594ad54a
SR
1082 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1083 break;
1084 case UDP_V6_FLOW:
e2557877 1085 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
594ad54a 1086 data |= RXH_IP_DST | RXH_IP_SRC;
e2557877 1087 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
594ad54a
SR
1088 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1089 break;
1090 }
1091
1092 return data;
1093}
1094
1095static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
05e4c6a3 1096 u32 *rule_locs)
594ad54a
SR
1097{
1098 struct be_adapter *adapter = netdev_priv(netdev);
1099
1100 if (!be_multi_rxq(adapter)) {
1101 dev_info(&adapter->pdev->dev,
1102 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
1103 return -EINVAL;
1104 }
1105
1106 switch (cmd->cmd) {
1107 case ETHTOOL_GRXFH:
1108 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
1109 break;
1110 case ETHTOOL_GRXRINGS:
1111 cmd->data = adapter->num_rx_qs - 1;
1112 break;
1113 default:
1114 return -EINVAL;
1115 }
1116
1117 return 0;
1118}
1119
1120static int be_set_rss_hash_opts(struct be_adapter *adapter,
1121 struct ethtool_rxnfc *cmd)
1122{
4114ec90 1123 int status;
e2557877 1124 u32 rss_flags = adapter->rss_info.rss_flags;
594ad54a
SR
1125
1126 if (cmd->data != L3_RSS_FLAGS &&
1127 cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
1128 return -EINVAL;
1129
1130 switch (cmd->flow_type) {
1131 case TCP_V4_FLOW:
1132 if (cmd->data == L3_RSS_FLAGS)
1133 rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1134 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1135 rss_flags |= RSS_ENABLE_IPV4 |
1136 RSS_ENABLE_TCP_IPV4;
1137 break;
1138 case TCP_V6_FLOW:
1139 if (cmd->data == L3_RSS_FLAGS)
1140 rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1141 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1142 rss_flags |= RSS_ENABLE_IPV6 |
1143 RSS_ENABLE_TCP_IPV6;
1144 break;
1145 case UDP_V4_FLOW:
1146 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1147 BEx_chip(adapter))
1148 return -EINVAL;
1149
1150 if (cmd->data == L3_RSS_FLAGS)
1151 rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1152 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1153 rss_flags |= RSS_ENABLE_IPV4 |
1154 RSS_ENABLE_UDP_IPV4;
1155 break;
1156 case UDP_V6_FLOW:
1157 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1158 BEx_chip(adapter))
1159 return -EINVAL;
1160
1161 if (cmd->data == L3_RSS_FLAGS)
1162 rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1163 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1164 rss_flags |= RSS_ENABLE_IPV6 |
1165 RSS_ENABLE_UDP_IPV6;
1166 break;
1167 default:
1168 return -EINVAL;
1169 }
1170
e2557877 1171 if (rss_flags == adapter->rss_info.rss_flags)
4114ec90 1172 return 0;
e2557877
VD
1173
1174 status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
d5d30981
IV
1175 rss_flags, RSS_INDIR_TABLE_LEN,
1176 adapter->rss_info.rss_hkey);
594ad54a 1177 if (!status)
e2557877 1178 adapter->rss_info.rss_flags = rss_flags;
594ad54a 1179
0532d4e3 1180 return be_cmd_status(status);
594ad54a
SR
1181}
1182
1183static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1184{
1185 struct be_adapter *adapter = netdev_priv(netdev);
1186 int status = 0;
1187
1188 if (!be_multi_rxq(adapter)) {
1189 dev_err(&adapter->pdev->dev,
1190 "ethtool::set_rxnfc: RX flow hashing is disabled\n");
1191 return -EINVAL;
1192 }
1193
1194 switch (cmd->cmd) {
1195 case ETHTOOL_SRXFH:
1196 status = be_set_rss_hash_opts(adapter, cmd);
1197 break;
1198 default:
1199 return -EINVAL;
1200 }
1201
1202 return status;
1203}
1204
68d7bdcb
SP
1205static void be_get_channels(struct net_device *netdev,
1206 struct ethtool_channels *ch)
1207{
1208 struct be_adapter *adapter = netdev_priv(netdev);
e261768e 1209 u16 num_rx_irqs = max_t(u16, adapter->num_rss_qs, 1);
68d7bdcb 1210
e261768e
SP
1211 /* num_tx_qs is always same as the number of irqs used for TX */
1212 ch->combined_count = min(adapter->num_tx_qs, num_rx_irqs);
1213 ch->rx_count = num_rx_irqs - ch->combined_count;
1214 ch->tx_count = adapter->num_tx_qs - ch->combined_count;
1215
1216 ch->max_combined = be_max_qp_irqs(adapter);
1217 /* The user must create atleast one combined channel */
1218 ch->max_rx = be_max_rx_irqs(adapter) - 1;
1219 ch->max_tx = be_max_tx_irqs(adapter) - 1;
68d7bdcb
SP
1220}
1221
1222static int be_set_channels(struct net_device *netdev,
1223 struct ethtool_channels *ch)
1224{
1225 struct be_adapter *adapter = netdev_priv(netdev);
0532d4e3 1226 int status;
68d7bdcb 1227
e261768e
SP
1228 /* we support either only combined channels or a combination of
1229 * combined and either RX-only or TX-only channels.
1230 */
1231 if (ch->other_count || !ch->combined_count ||
1232 (ch->rx_count && ch->tx_count))
1233 return -EINVAL;
1234
1235 if (ch->combined_count > be_max_qp_irqs(adapter) ||
1236 (ch->rx_count &&
1237 (ch->rx_count + ch->combined_count) > be_max_rx_irqs(adapter)) ||
1238 (ch->tx_count &&
1239 (ch->tx_count + ch->combined_count) > be_max_tx_irqs(adapter)))
68d7bdcb
SP
1240 return -EINVAL;
1241
e261768e
SP
1242 adapter->cfg_num_rx_irqs = ch->combined_count + ch->rx_count;
1243 adapter->cfg_num_tx_irqs = ch->combined_count + ch->tx_count;
68d7bdcb 1244
0532d4e3
KA
1245 status = be_update_queues(adapter);
1246 return be_cmd_status(status);
68d7bdcb
SP
1247}
1248
e2557877
VD
1249static u32 be_get_rxfh_indir_size(struct net_device *netdev)
1250{
1251 return RSS_INDIR_TABLE_LEN;
1252}
1253
1254static u32 be_get_rxfh_key_size(struct net_device *netdev)
1255{
1256 return RSS_HASH_KEY_LEN;
1257}
1258
892311f6
EP
1259static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
1260 u8 *hfunc)
e2557877
VD
1261{
1262 struct be_adapter *adapter = netdev_priv(netdev);
1263 int i;
1264 struct rss_info *rss = &adapter->rss_info;
1265
1266 if (indir) {
1267 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
1268 indir[i] = rss->rss_queue[i];
1269 }
1270
1271 if (hkey)
1272 memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
1273
892311f6
EP
1274 if (hfunc)
1275 *hfunc = ETH_RSS_HASH_TOP;
1276
e2557877
VD
1277 return 0;
1278}
1279
33cb0fa7 1280static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
892311f6 1281 const u8 *hkey, const u8 hfunc)
e2557877
VD
1282{
1283 int rc = 0, i, j;
1284 struct be_adapter *adapter = netdev_priv(netdev);
1285 u8 rsstable[RSS_INDIR_TABLE_LEN];
1286
892311f6
EP
1287 /* We do not allow change in unsupported parameters */
1288 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1289 return -EOPNOTSUPP;
1290
e2557877
VD
1291 if (indir) {
1292 struct be_rx_obj *rxo;
03d28ffe 1293
e2557877
VD
1294 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
1295 j = indir[i];
1296 rxo = &adapter->rx_obj[j];
1297 rsstable[i] = rxo->rss_id;
1298 adapter->rss_info.rss_queue[i] = j;
1299 }
1300 } else {
1301 memcpy(rsstable, adapter->rss_info.rsstable,
1302 RSS_INDIR_TABLE_LEN);
1303 }
1304
1305 if (!hkey)
1306 hkey = adapter->rss_info.rss_hkey;
1307
1308 rc = be_cmd_rss_config(adapter, rsstable,
cd3307aa
KA
1309 adapter->rss_info.rss_flags,
1310 RSS_INDIR_TABLE_LEN, hkey);
e2557877
VD
1311 if (rc) {
1312 adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
1313 return -EIO;
1314 }
1315 memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
1316 memcpy(adapter->rss_info.rsstable, rsstable,
1317 RSS_INDIR_TABLE_LEN);
1318 return 0;
1319}
1320
e36edd9d
ML
1321static int be_get_module_info(struct net_device *netdev,
1322 struct ethtool_modinfo *modinfo)
1323{
1324 struct be_adapter *adapter = netdev_priv(netdev);
1325 u8 page_data[PAGE_DATA_LEN];
1326 int status;
1327
1328 if (!check_privilege(adapter, MAX_PRIVILEGES))
1329 return -EOPNOTSUPP;
1330
1331 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1332 page_data);
1333 if (!status) {
1334 if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
1335 modinfo->type = ETH_MODULE_SFF_8079;
1336 modinfo->eeprom_len = PAGE_DATA_LEN;
1337 } else {
1338 modinfo->type = ETH_MODULE_SFF_8472;
1339 modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
1340 }
1341 }
1342 return be_cmd_status(status);
1343}
1344
1345static int be_get_module_eeprom(struct net_device *netdev,
1346 struct ethtool_eeprom *eeprom, u8 *data)
1347{
1348 struct be_adapter *adapter = netdev_priv(netdev);
1349 int status;
1350
1351 if (!check_privilege(adapter, MAX_PRIVILEGES))
1352 return -EOPNOTSUPP;
1353
1354 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1355 data);
1356 if (status)
1357 goto err;
1358
1359 if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
1360 status = be_cmd_read_port_transceiver_data(adapter,
1361 TR_PAGE_A2,
1362 data +
1363 PAGE_DATA_LEN);
1364 if (status)
1365 goto err;
1366 }
1367 if (eeprom->offset)
1368 memcpy(data, data + eeprom->offset, eeprom->len);
1369err:
1370 return be_cmd_status(status);
1371}
1372
710f3e59
SB
1373static u32 be_get_priv_flags(struct net_device *netdev)
1374{
1375 struct be_adapter *adapter = netdev_priv(netdev);
1376
1377 return adapter->priv_flags;
1378}
1379
1380static int be_set_priv_flags(struct net_device *netdev, u32 flags)
1381{
1382 struct be_adapter *adapter = netdev_priv(netdev);
1383 bool tpe_old = !!(adapter->priv_flags & BE_DISABLE_TPE_RECOVERY);
1384 bool tpe_new = !!(flags & BE_DISABLE_TPE_RECOVERY);
1385
1386 if (tpe_old != tpe_new) {
1387 if (tpe_new) {
1388 adapter->priv_flags |= BE_DISABLE_TPE_RECOVERY;
1389 dev_info(&adapter->pdev->dev,
1390 "HW error recovery is disabled\n");
1391 } else {
1392 adapter->priv_flags &= ~BE_DISABLE_TPE_RECOVERY;
1393 dev_info(&adapter->pdev->dev,
1394 "HW error recovery is enabled\n");
1395 }
1396 }
1397
1398 return 0;
1399}
1400
0fc0b732 1401const struct ethtool_ops be_ethtool_ops = {
6b7c5b94
SP
1402 .get_settings = be_get_settings,
1403 .get_drvinfo = be_get_drvinfo,
71d8d1b5
AK
1404 .get_wol = be_get_wol,
1405 .set_wol = be_set_wol,
6b7c5b94 1406 .get_link = ethtool_op_get_link,
368c0ca2
SB
1407 .get_eeprom_len = be_get_eeprom_len,
1408 .get_eeprom = be_read_eeprom,
6b7c5b94
SP
1409 .get_coalesce = be_get_coalesce,
1410 .set_coalesce = be_set_coalesce,
1411 .get_ringparam = be_get_ringparam,
1412 .get_pauseparam = be_get_pauseparam,
1413 .set_pauseparam = be_set_pauseparam,
710f3e59
SB
1414 .set_priv_flags = be_set_priv_flags,
1415 .get_priv_flags = be_get_priv_flags,
6b7c5b94 1416 .get_strings = be_get_stat_strings,
1a642469 1417 .set_phys_id = be_set_phys_id,
5c510811 1418 .set_dump = be_set_dump,
941a77d5
SK
1419 .get_msglevel = be_get_msg_level,
1420 .set_msglevel = be_set_msg_level,
15f0a394 1421 .get_sset_count = be_get_sset_count,
6b7c5b94 1422 .get_ethtool_stats = be_get_ethtool_stats,
84517482 1423 .flash_device = be_do_flash,
ff33a6e2 1424 .self_test = be_self_test,
594ad54a
SR
1425 .get_rxnfc = be_get_rxnfc,
1426 .set_rxnfc = be_set_rxnfc,
e2557877
VD
1427 .get_rxfh_indir_size = be_get_rxfh_indir_size,
1428 .get_rxfh_key_size = be_get_rxfh_key_size,
1429 .get_rxfh = be_get_rxfh,
1430 .set_rxfh = be_set_rxfh,
fd7ff6f0
VD
1431 .get_dump_flag = be_get_dump_flag,
1432 .get_dump_data = be_get_dump_data,
68d7bdcb 1433 .get_channels = be_get_channels,
e36edd9d
ML
1434 .set_channels = be_set_channels,
1435 .get_module_info = be_get_module_info,
1436 .get_module_eeprom = be_get_module_eeprom
6b7c5b94 1437};
This page took 0.795096 seconds and 5 git commands to generate.