treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / ethernet / emulex / benet / be_ethtool.c
blob022a54a1805b46c85819964d79ac6ca3114cc379
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2005 - 2016 Broadcom
4 * All rights reserved.
6 * Contact Information:
7 * linux-drivers@emulex.com
9 * Emulex
10 * 3333 Susan Street
11 * Costa Mesa, CA 92626
14 #include "be.h"
15 #include "be_cmds.h"
16 #include <linux/ethtool.h>
18 struct be_ethtool_stat {
19 char desc[ETH_GSTRING_LEN];
20 int type;
21 int size;
22 int offset;
25 enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
26 #define FIELDINFO(_struct, field) sizeof_field(_struct, field), \
27 offsetof(_struct, field)
28 #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\
29 FIELDINFO(struct be_tx_stats, field)
30 #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\
31 FIELDINFO(struct be_rx_stats, field)
32 #define DRVSTAT_INFO(field) #field, DRVSTAT,\
33 FIELDINFO(struct be_drv_stats, field)
35 static const struct be_ethtool_stat et_stats[] = {
36 {DRVSTAT_INFO(rx_crc_errors)},
37 {DRVSTAT_INFO(rx_alignment_symbol_errors)},
38 {DRVSTAT_INFO(rx_pause_frames)},
39 {DRVSTAT_INFO(rx_control_frames)},
40 /* Received packets dropped when the Ethernet length field
41 * is not equal to the actual Ethernet data length.
43 {DRVSTAT_INFO(rx_in_range_errors)},
44 /* Received packets dropped when their length field is >= 1501 bytes
45 * and <= 1535 bytes.
47 {DRVSTAT_INFO(rx_out_range_errors)},
48 /* Received packets dropped when they are longer than 9216 bytes */
49 {DRVSTAT_INFO(rx_frame_too_long)},
50 /* Received packets dropped when they don't pass the unicast or
51 * multicast address filtering.
53 {DRVSTAT_INFO(rx_address_filtered)},
54 /* Received packets dropped when IP packet length field is less than
55 * the IP header length field.
57 {DRVSTAT_INFO(rx_dropped_too_small)},
58 /* Received packets dropped when IP length field is greater than
59 * the actual packet length.
61 {DRVSTAT_INFO(rx_dropped_too_short)},
62 /* Received packets dropped when the IP header length field is less
63 * than 5.
65 {DRVSTAT_INFO(rx_dropped_header_too_small)},
66 /* Received packets dropped when the TCP header length field is less
67 * than 5 or the TCP header length + IP header length is more
68 * than IP packet length.
70 {DRVSTAT_INFO(rx_dropped_tcp_length)},
71 {DRVSTAT_INFO(rx_dropped_runt)},
72 /* Number of received packets dropped when a fifo for descriptors going
73 * into the packet demux block overflows. In normal operation, this
74 * fifo must never overflow.
76 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
77 /* Received packets dropped when the RX block runs out of space in
78 * one of its input FIFOs. This could happen due a long burst of
79 * minimum-sized (64b) frames in the receive path.
80 * This counter may also be erroneously incremented rarely.
82 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
83 {DRVSTAT_INFO(rx_ip_checksum_errs)},
84 {DRVSTAT_INFO(rx_tcp_checksum_errs)},
85 {DRVSTAT_INFO(rx_udp_checksum_errs)},
86 {DRVSTAT_INFO(tx_pauseframes)},
87 {DRVSTAT_INFO(tx_controlframes)},
88 {DRVSTAT_INFO(rx_priority_pause_frames)},
89 {DRVSTAT_INFO(tx_priority_pauseframes)},
90 /* Received packets dropped when an internal fifo going into
91 * main packet buffer tank (PMEM) overflows.
93 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
94 {DRVSTAT_INFO(jabber_events)},
95 /* Received packets dropped due to lack of available HW packet buffers
96 * used to temporarily hold the received packets.
98 {DRVSTAT_INFO(rx_drops_no_pbuf)},
99 /* Received packets dropped due to input receive buffer
100 * descriptor fifo overflowing.
102 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
103 /* Packets dropped because the internal FIFO to the offloaded TCP
104 * receive processing block is full. This could happen only for
105 * offloaded iSCSI or FCoE trarffic.
107 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
108 /* Received packets dropped when they need more than 8
109 * receive buffers. This cannot happen as the driver configures
110 * 2048 byte receive buffers.
112 {DRVSTAT_INFO(rx_drops_too_many_frags)},
113 {DRVSTAT_INFO(forwarded_packets)},
114 /* Received packets dropped when the frame length
115 * is more than 9018 bytes
117 {DRVSTAT_INFO(rx_drops_mtu)},
118 /* Number of dma mapping errors */
119 {DRVSTAT_INFO(dma_map_errors)},
120 /* Number of packets dropped due to random early drop function */
121 {DRVSTAT_INFO(eth_red_drops)},
122 {DRVSTAT_INFO(rx_roce_bytes_lsd)},
123 {DRVSTAT_INFO(rx_roce_bytes_msd)},
124 {DRVSTAT_INFO(rx_roce_frames)},
125 {DRVSTAT_INFO(roce_drops_payload_len)},
126 {DRVSTAT_INFO(roce_drops_crc)}
129 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
131 /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
132 * are first and second members respectively.
134 static const struct be_ethtool_stat et_rx_stats[] = {
135 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
136 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
137 {DRVSTAT_RX_INFO(rx_vxlan_offload_pkts)},
138 {DRVSTAT_RX_INFO(rx_compl)},
139 {DRVSTAT_RX_INFO(rx_compl_err)},
140 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
141 /* Number of page allocation failures while posting receive buffers
142 * to HW.
144 {DRVSTAT_RX_INFO(rx_post_fail)},
145 /* Recevied packets dropped due to skb allocation failure */
146 {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
147 /* Received packets dropped due to lack of available fetched buffers
148 * posted by the driver.
150 {DRVSTAT_RX_INFO(rx_drops_no_frags)}
153 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
155 /* Stats related to multi TX queues: get_stats routine assumes compl is the
156 * first member
158 static const struct be_ethtool_stat et_tx_stats[] = {
159 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
160 /* This counter is incremented when the HW encounters an error while
161 * parsing the packet header of an outgoing TX request. This counter is
162 * applicable only for BE2, BE3 and Skyhawk based adapters.
164 {DRVSTAT_TX_INFO(tx_hdr_parse_err)},
165 /* This counter is incremented when an error occurs in the DMA
166 * operation associated with the TX request from the host to the device.
168 {DRVSTAT_TX_INFO(tx_dma_err)},
169 /* This counter is incremented when MAC or VLAN spoof checking is
170 * enabled on the interface and the TX request fails the spoof check
171 * in HW.
173 {DRVSTAT_TX_INFO(tx_spoof_check_err)},
174 /* This counter is incremented when the HW encounters an error while
175 * performing TSO offload. This counter is applicable only for Lancer
176 * adapters.
178 {DRVSTAT_TX_INFO(tx_tso_err)},
179 /* This counter is incremented when the HW detects Q-in-Q style VLAN
180 * tagging in a packet and such tagging is not expected on the outgoing
181 * interface. This counter is applicable only for Lancer adapters.
183 {DRVSTAT_TX_INFO(tx_qinq_err)},
184 /* This counter is incremented when the HW detects parity errors in the
185 * packet data. This counter is applicable only for Lancer adapters.
187 {DRVSTAT_TX_INFO(tx_internal_parity_err)},
188 {DRVSTAT_TX_INFO(tx_sge_err)},
189 {DRVSTAT_TX_INFO(tx_bytes)},
190 {DRVSTAT_TX_INFO(tx_pkts)},
191 {DRVSTAT_TX_INFO(tx_vxlan_offload_pkts)},
192 /* Number of skbs queued for trasmission by the driver */
193 {DRVSTAT_TX_INFO(tx_reqs)},
194 /* Number of times the TX queue was stopped due to lack
195 * of spaces in the TXQ.
197 {DRVSTAT_TX_INFO(tx_stops)},
198 /* Pkts dropped in the driver's transmit path */
199 {DRVSTAT_TX_INFO(tx_drv_drops)}
202 #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
204 static const char et_self_tests[][ETH_GSTRING_LEN] = {
205 "MAC Loopback test",
206 "PHY Loopback test",
207 "External Loopback test",
208 "DDR DMA test",
209 "Link test"
212 #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
213 #define BE_MAC_LOOPBACK 0x0
214 #define BE_PHY_LOOPBACK 0x1
215 #define BE_ONE_PORT_EXT_LOOPBACK 0x2
216 #define BE_NO_LOOPBACK 0xff
218 static void be_get_drvinfo(struct net_device *netdev,
219 struct ethtool_drvinfo *drvinfo)
221 struct be_adapter *adapter = netdev_priv(netdev);
223 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
224 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
225 if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN))
226 strlcpy(drvinfo->fw_version, adapter->fw_ver,
227 sizeof(drvinfo->fw_version));
228 else
229 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
230 "%s [%s]", adapter->fw_ver, adapter->fw_on_flash);
232 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
233 sizeof(drvinfo->bus_info));
236 static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
238 u32 data_read = 0, eof;
239 u8 addn_status;
240 struct be_dma_mem data_len_cmd;
242 memset(&data_len_cmd, 0, sizeof(data_len_cmd));
243 /* data_offset and data_size should be 0 to get reg len */
244 lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0, file_name,
245 &data_read, &eof, &addn_status);
247 return data_read;
250 static int be_get_dump_len(struct be_adapter *adapter)
252 u32 dump_size = 0;
254 if (lancer_chip(adapter))
255 dump_size = lancer_cmd_get_file_len(adapter,
256 LANCER_FW_DUMP_FILE);
257 else
258 dump_size = adapter->fat_dump_len;
260 return dump_size;
263 static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
264 u32 buf_len, void *buf)
266 struct be_dma_mem read_cmd;
267 u32 read_len = 0, total_read_len = 0, chunk_size;
268 u32 eof = 0;
269 u8 addn_status;
270 int status = 0;
272 read_cmd.size = LANCER_READ_FILE_CHUNK;
273 read_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, read_cmd.size,
274 &read_cmd.dma, GFP_ATOMIC);
276 if (!read_cmd.va) {
277 dev_err(&adapter->pdev->dev,
278 "Memory allocation failure while reading dump\n");
279 return -ENOMEM;
282 while ((total_read_len < buf_len) && !eof) {
283 chunk_size = min_t(u32, (buf_len - total_read_len),
284 LANCER_READ_FILE_CHUNK);
285 chunk_size = ALIGN(chunk_size, 4);
286 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
287 total_read_len, file_name,
288 &read_len, &eof, &addn_status);
289 if (!status) {
290 memcpy(buf + total_read_len, read_cmd.va, read_len);
291 total_read_len += read_len;
292 eof &= LANCER_READ_FILE_EOF_MASK;
293 } else {
294 status = -EIO;
295 break;
298 dma_free_coherent(&adapter->pdev->dev, read_cmd.size, read_cmd.va,
299 read_cmd.dma);
301 return status;
304 static int be_read_dump_data(struct be_adapter *adapter, u32 dump_len,
305 void *buf)
307 int status = 0;
309 if (lancer_chip(adapter))
310 status = lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
311 dump_len, buf);
312 else
313 status = be_cmd_get_fat_dump(adapter, dump_len, buf);
315 return status;
318 static int be_get_coalesce(struct net_device *netdev,
319 struct ethtool_coalesce *et)
321 struct be_adapter *adapter = netdev_priv(netdev);
322 struct be_aic_obj *aic = &adapter->aic_obj[0];
324 et->rx_coalesce_usecs = aic->prev_eqd;
325 et->rx_coalesce_usecs_high = aic->max_eqd;
326 et->rx_coalesce_usecs_low = aic->min_eqd;
328 et->tx_coalesce_usecs = aic->prev_eqd;
329 et->tx_coalesce_usecs_high = aic->max_eqd;
330 et->tx_coalesce_usecs_low = aic->min_eqd;
332 et->use_adaptive_rx_coalesce = adapter->aic_enabled;
333 et->use_adaptive_tx_coalesce = adapter->aic_enabled;
335 return 0;
338 /* TX attributes are ignored. Only RX attributes are considered
339 * eqd cmd is issued in the worker thread.
341 static int be_set_coalesce(struct net_device *netdev,
342 struct ethtool_coalesce *et)
344 struct be_adapter *adapter = netdev_priv(netdev);
345 struct be_aic_obj *aic = &adapter->aic_obj[0];
346 struct be_eq_obj *eqo;
347 int i;
349 adapter->aic_enabled = et->use_adaptive_rx_coalesce;
351 for_all_evt_queues(adapter, eqo, i) {
352 aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
353 aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
354 aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
355 aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
356 aic++;
359 /* For Skyhawk, the EQD setting happens via EQ_DB when AIC is enabled.
360 * When AIC is disabled, persistently force set EQD value via the
361 * FW cmd, so that we don't have to calculate the delay multiplier
362 * encode value each time EQ_DB is rung
364 if (!et->use_adaptive_rx_coalesce && skyhawk_chip(adapter))
365 be_eqd_update(adapter, true);
367 return 0;
370 static void be_get_ethtool_stats(struct net_device *netdev,
371 struct ethtool_stats *stats, uint64_t *data)
373 struct be_adapter *adapter = netdev_priv(netdev);
374 struct be_rx_obj *rxo;
375 struct be_tx_obj *txo;
376 void *p;
377 unsigned int i, j, base = 0, start;
379 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
380 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
381 data[i] = *(u32 *)p;
383 base += ETHTOOL_STATS_NUM;
385 for_all_rx_queues(adapter, rxo, j) {
386 struct be_rx_stats *stats = rx_stats(rxo);
388 do {
389 start = u64_stats_fetch_begin_irq(&stats->sync);
390 data[base] = stats->rx_bytes;
391 data[base + 1] = stats->rx_pkts;
392 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
394 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
395 p = (u8 *)stats + et_rx_stats[i].offset;
396 data[base + i] = *(u32 *)p;
398 base += ETHTOOL_RXSTATS_NUM;
401 for_all_tx_queues(adapter, txo, j) {
402 struct be_tx_stats *stats = tx_stats(txo);
404 do {
405 start = u64_stats_fetch_begin_irq(&stats->sync_compl);
406 data[base] = stats->tx_compl;
407 } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
409 do {
410 start = u64_stats_fetch_begin_irq(&stats->sync);
411 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
412 p = (u8 *)stats + et_tx_stats[i].offset;
413 data[base + i] =
414 (et_tx_stats[i].size == sizeof(u64)) ?
415 *(u64 *)p : *(u32 *)p;
417 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
418 base += ETHTOOL_TXSTATS_NUM;
422 static const char be_priv_flags[][ETH_GSTRING_LEN] = {
423 "disable-tpe-recovery"
426 static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
427 uint8_t *data)
429 struct be_adapter *adapter = netdev_priv(netdev);
430 int i, j;
432 switch (stringset) {
433 case ETH_SS_STATS:
434 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
435 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
436 data += ETH_GSTRING_LEN;
438 for (i = 0; i < adapter->num_rx_qs; i++) {
439 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
440 sprintf(data, "rxq%d: %s", i,
441 et_rx_stats[j].desc);
442 data += ETH_GSTRING_LEN;
445 for (i = 0; i < adapter->num_tx_qs; i++) {
446 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
447 sprintf(data, "txq%d: %s", i,
448 et_tx_stats[j].desc);
449 data += ETH_GSTRING_LEN;
452 break;
453 case ETH_SS_TEST:
454 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
455 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
456 data += ETH_GSTRING_LEN;
458 break;
459 case ETH_SS_PRIV_FLAGS:
460 for (i = 0; i < ARRAY_SIZE(be_priv_flags); i++)
461 strcpy(data + i * ETH_GSTRING_LEN, be_priv_flags[i]);
462 break;
466 static int be_get_sset_count(struct net_device *netdev, int stringset)
468 struct be_adapter *adapter = netdev_priv(netdev);
470 switch (stringset) {
471 case ETH_SS_TEST:
472 return ETHTOOL_TESTS_NUM;
473 case ETH_SS_STATS:
474 return ETHTOOL_STATS_NUM +
475 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
476 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
477 case ETH_SS_PRIV_FLAGS:
478 return ARRAY_SIZE(be_priv_flags);
479 default:
480 return -EINVAL;
484 static u32 be_get_port_type(struct be_adapter *adapter)
486 u32 port;
488 switch (adapter->phy.interface_type) {
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:
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;
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;
517 return port;
520 static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
522 u32 val = 0;
524 switch (adapter->phy.interface_type) {
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;
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;
550 case PHY_TYPE_KR_10GB:
551 val |= SUPPORTED_Backplane |
552 SUPPORTED_10000baseKR_Full;
553 break;
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;
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;
575 /* fall through */
576 case PHY_TYPE_SFP_PLUS_10GB:
577 case PHY_TYPE_XFP_10GB:
578 case PHY_TYPE_SFP_1GB:
579 val |= SUPPORTED_FIBRE;
580 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
581 val |= SUPPORTED_10000baseT_Full;
582 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
583 val |= SUPPORTED_1000baseT_Full;
584 break;
585 case PHY_TYPE_BASET_10GB:
586 val |= SUPPORTED_TP;
587 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
588 val |= SUPPORTED_10000baseT_Full;
589 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
590 val |= SUPPORTED_1000baseT_Full;
591 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
592 val |= SUPPORTED_100baseT_Full;
593 break;
594 default:
595 val |= SUPPORTED_TP;
598 return val;
601 bool be_pause_supported(struct be_adapter *adapter)
603 return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
604 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
605 false : true;
608 static int be_get_link_ksettings(struct net_device *netdev,
609 struct ethtool_link_ksettings *cmd)
611 struct be_adapter *adapter = netdev_priv(netdev);
612 u8 link_status;
613 u16 link_speed = 0;
614 int status;
615 u32 auto_speeds;
616 u32 fixed_speeds;
617 u32 supported = 0, advertising = 0;
619 if (adapter->phy.link_speed < 0) {
620 status = be_cmd_link_status_query(adapter, &link_speed,
621 &link_status, 0);
622 if (!status)
623 be_link_status_update(adapter, link_status);
624 cmd->base.speed = link_speed;
626 status = be_cmd_get_phy_info(adapter);
627 if (!status) {
628 auto_speeds = adapter->phy.auto_speeds_supported;
629 fixed_speeds = adapter->phy.fixed_speeds_supported;
631 be_cmd_query_cable_type(adapter);
633 supported =
634 convert_to_et_setting(adapter,
635 auto_speeds |
636 fixed_speeds);
637 advertising =
638 convert_to_et_setting(adapter, auto_speeds);
640 cmd->base.port = be_get_port_type(adapter);
642 if (adapter->phy.auto_speeds_supported) {
643 supported |= SUPPORTED_Autoneg;
644 cmd->base.autoneg = AUTONEG_ENABLE;
645 advertising |= ADVERTISED_Autoneg;
648 supported |= SUPPORTED_Pause;
649 if (be_pause_supported(adapter))
650 advertising |= ADVERTISED_Pause;
651 } else {
652 cmd->base.port = PORT_OTHER;
653 cmd->base.autoneg = AUTONEG_DISABLE;
656 /* Save for future use */
657 adapter->phy.link_speed = cmd->base.speed;
658 adapter->phy.port_type = cmd->base.port;
659 adapter->phy.autoneg = cmd->base.autoneg;
660 adapter->phy.advertising = advertising;
661 adapter->phy.supported = supported;
662 } else {
663 cmd->base.speed = adapter->phy.link_speed;
664 cmd->base.port = adapter->phy.port_type;
665 cmd->base.autoneg = adapter->phy.autoneg;
666 advertising = adapter->phy.advertising;
667 supported = adapter->phy.supported;
670 cmd->base.duplex = netif_carrier_ok(netdev) ?
671 DUPLEX_FULL : DUPLEX_UNKNOWN;
672 cmd->base.phy_address = adapter->port_num;
674 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
675 supported);
676 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
677 advertising);
679 return 0;
682 static void be_get_ringparam(struct net_device *netdev,
683 struct ethtool_ringparam *ring)
685 struct be_adapter *adapter = netdev_priv(netdev);
687 ring->rx_max_pending = adapter->rx_obj[0].q.len;
688 ring->rx_pending = adapter->rx_obj[0].q.len;
689 ring->tx_max_pending = adapter->tx_obj[0].q.len;
690 ring->tx_pending = adapter->tx_obj[0].q.len;
693 static void
694 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
696 struct be_adapter *adapter = netdev_priv(netdev);
698 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
699 ecmd->autoneg = adapter->phy.fc_autoneg;
702 static int
703 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
705 struct be_adapter *adapter = netdev_priv(netdev);
706 int status;
708 if (ecmd->autoneg != adapter->phy.fc_autoneg)
709 return -EINVAL;
711 status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
712 ecmd->rx_pause);
713 if (status) {
714 dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
715 return be_cmd_status(status);
718 adapter->tx_fc = ecmd->tx_pause;
719 adapter->rx_fc = ecmd->rx_pause;
720 return 0;
723 static int be_set_phys_id(struct net_device *netdev,
724 enum ethtool_phys_id_state state)
726 struct be_adapter *adapter = netdev_priv(netdev);
727 int status = 0;
729 switch (state) {
730 case ETHTOOL_ID_ACTIVE:
731 status = be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
732 &adapter->beacon_state);
733 if (status)
734 return be_cmd_status(status);
735 return 1; /* cycle on/off once per second */
737 case ETHTOOL_ID_ON:
738 status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
739 0, 0, BEACON_STATE_ENABLED);
740 break;
742 case ETHTOOL_ID_OFF:
743 status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
744 0, 0, BEACON_STATE_DISABLED);
745 break;
747 case ETHTOOL_ID_INACTIVE:
748 status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
749 0, 0, adapter->beacon_state);
752 return be_cmd_status(status);
755 static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
757 struct be_adapter *adapter = netdev_priv(netdev);
758 struct device *dev = &adapter->pdev->dev;
759 int status;
761 if (!lancer_chip(adapter) ||
762 !check_privilege(adapter, MAX_PRIVILEGES))
763 return -EOPNOTSUPP;
765 switch (dump->flag) {
766 case LANCER_INITIATE_FW_DUMP:
767 status = lancer_initiate_dump(adapter);
768 if (!status)
769 dev_info(dev, "FW dump initiated successfully\n");
770 break;
771 case LANCER_DELETE_FW_DUMP:
772 status = lancer_delete_dump(adapter);
773 if (!status)
774 dev_info(dev, "FW dump deleted successfully\n");
775 break;
776 default:
777 dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
778 return -EINVAL;
780 return status;
783 static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
785 struct be_adapter *adapter = netdev_priv(netdev);
787 if (adapter->wol_cap & BE_WOL_CAP) {
788 wol->supported |= WAKE_MAGIC;
789 if (adapter->wol_en)
790 wol->wolopts |= WAKE_MAGIC;
791 } else {
792 wol->wolopts = 0;
794 memset(&wol->sopass, 0, sizeof(wol->sopass));
797 static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
799 struct be_adapter *adapter = netdev_priv(netdev);
800 struct device *dev = &adapter->pdev->dev;
801 struct be_dma_mem cmd;
802 u8 mac[ETH_ALEN];
803 bool enable;
804 int status;
806 if (wol->wolopts & ~WAKE_MAGIC)
807 return -EOPNOTSUPP;
809 if (!(adapter->wol_cap & BE_WOL_CAP)) {
810 dev_warn(&adapter->pdev->dev, "WOL not supported\n");
811 return -EOPNOTSUPP;
814 cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config);
815 cmd.va = dma_alloc_coherent(dev, cmd.size, &cmd.dma, GFP_KERNEL);
816 if (!cmd.va)
817 return -ENOMEM;
819 eth_zero_addr(mac);
821 enable = wol->wolopts & WAKE_MAGIC;
822 if (enable)
823 ether_addr_copy(mac, adapter->netdev->dev_addr);
825 status = be_cmd_enable_magic_wol(adapter, mac, &cmd);
826 if (status) {
827 dev_err(dev, "Could not set Wake-on-lan mac address\n");
828 status = be_cmd_status(status);
829 goto err;
832 pci_enable_wake(adapter->pdev, PCI_D3hot, enable);
833 pci_enable_wake(adapter->pdev, PCI_D3cold, enable);
835 adapter->wol_en = enable ? true : false;
837 err:
838 dma_free_coherent(dev, cmd.size, cmd.va, cmd.dma);
839 return status;
842 static int be_test_ddr_dma(struct be_adapter *adapter)
844 int ret, i;
845 struct be_dma_mem ddrdma_cmd;
846 static const u64 pattern[2] = {
847 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
850 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
851 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
852 ddrdma_cmd.size, &ddrdma_cmd.dma,
853 GFP_KERNEL);
854 if (!ddrdma_cmd.va)
855 return -ENOMEM;
857 for (i = 0; i < 2; i++) {
858 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
859 4096, &ddrdma_cmd);
860 if (ret != 0)
861 goto err;
864 err:
865 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
866 ddrdma_cmd.dma);
867 return be_cmd_status(ret);
870 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
871 u64 *status)
873 int ret;
875 ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
876 loopback_type, 1);
877 if (ret)
878 return ret;
880 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
881 loopback_type, 1500, 2, 0xabc);
883 ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
884 BE_NO_LOOPBACK, 1);
885 if (ret)
886 return ret;
888 return *status;
891 static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
892 u64 *data)
894 struct be_adapter *adapter = netdev_priv(netdev);
895 int status, cnt;
896 u8 link_status = 0;
898 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
899 dev_err(&adapter->pdev->dev, "Self test not supported\n");
900 test->flags |= ETH_TEST_FL_FAILED;
901 return;
904 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
906 /* check link status before offline tests */
907 link_status = netif_carrier_ok(netdev);
909 if (test->flags & ETH_TEST_FL_OFFLINE) {
910 if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
911 test->flags |= ETH_TEST_FL_FAILED;
913 if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
914 test->flags |= ETH_TEST_FL_FAILED;
916 if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
917 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
918 &data[2]) != 0)
919 test->flags |= ETH_TEST_FL_FAILED;
920 test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
924 if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
925 data[3] = 1;
926 test->flags |= ETH_TEST_FL_FAILED;
929 /* link status was down prior to test */
930 if (!link_status) {
931 test->flags |= ETH_TEST_FL_FAILED;
932 data[4] = 1;
933 return;
936 for (cnt = 10; cnt; cnt--) {
937 status = be_cmd_link_status_query(adapter, NULL, &link_status,
939 if (status) {
940 test->flags |= ETH_TEST_FL_FAILED;
941 data[4] = -1;
942 break;
945 if (link_status)
946 break;
948 msleep_interruptible(500);
952 static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
954 struct be_adapter *adapter = netdev_priv(netdev);
956 return be_load_fw(adapter, efl->data);
959 static int
960 be_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
962 struct be_adapter *adapter = netdev_priv(netdev);
964 if (!check_privilege(adapter, MAX_PRIVILEGES))
965 return -EOPNOTSUPP;
967 dump->len = be_get_dump_len(adapter);
968 dump->version = 1;
969 dump->flag = 0x1; /* FW dump is enabled */
970 return 0;
973 static int
974 be_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
975 void *buf)
977 struct be_adapter *adapter = netdev_priv(netdev);
978 int status;
980 if (!check_privilege(adapter, MAX_PRIVILEGES))
981 return -EOPNOTSUPP;
983 status = be_read_dump_data(adapter, dump->len, buf);
984 return be_cmd_status(status);
987 static int be_get_eeprom_len(struct net_device *netdev)
989 struct be_adapter *adapter = netdev_priv(netdev);
991 if (!check_privilege(adapter, MAX_PRIVILEGES))
992 return 0;
994 if (lancer_chip(adapter)) {
995 if (be_physfn(adapter))
996 return lancer_cmd_get_file_len(adapter,
997 LANCER_VPD_PF_FILE);
998 else
999 return lancer_cmd_get_file_len(adapter,
1000 LANCER_VPD_VF_FILE);
1001 } else {
1002 return BE_READ_SEEPROM_LEN;
1006 static int be_read_eeprom(struct net_device *netdev,
1007 struct ethtool_eeprom *eeprom, uint8_t *data)
1009 struct be_adapter *adapter = netdev_priv(netdev);
1010 struct be_dma_mem eeprom_cmd;
1011 struct be_cmd_resp_seeprom_read *resp;
1012 int status;
1014 if (!eeprom->len)
1015 return -EINVAL;
1017 if (lancer_chip(adapter)) {
1018 if (be_physfn(adapter))
1019 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
1020 eeprom->len, data);
1021 else
1022 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
1023 eeprom->len, data);
1026 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
1028 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
1029 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
1030 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
1031 eeprom_cmd.size, &eeprom_cmd.dma,
1032 GFP_KERNEL);
1034 if (!eeprom_cmd.va)
1035 return -ENOMEM;
1037 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
1039 if (!status) {
1040 resp = eeprom_cmd.va;
1041 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
1043 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
1044 eeprom_cmd.dma);
1046 return be_cmd_status(status);
1049 static u32 be_get_msg_level(struct net_device *netdev)
1051 struct be_adapter *adapter = netdev_priv(netdev);
1053 return adapter->msg_enable;
1056 static void be_set_msg_level(struct net_device *netdev, u32 level)
1058 struct be_adapter *adapter = netdev_priv(netdev);
1060 if (adapter->msg_enable == level)
1061 return;
1063 if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
1064 if (BEx_chip(adapter))
1065 be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
1066 FW_LOG_LEVEL_DEFAULT :
1067 FW_LOG_LEVEL_FATAL);
1068 adapter->msg_enable = level;
1071 static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
1073 u64 data = 0;
1075 switch (flow_type) {
1076 case TCP_V4_FLOW:
1077 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
1078 data |= RXH_IP_DST | RXH_IP_SRC;
1079 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
1080 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1081 break;
1082 case UDP_V4_FLOW:
1083 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
1084 data |= RXH_IP_DST | RXH_IP_SRC;
1085 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
1086 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1087 break;
1088 case TCP_V6_FLOW:
1089 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1090 data |= RXH_IP_DST | RXH_IP_SRC;
1091 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
1092 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1093 break;
1094 case UDP_V6_FLOW:
1095 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1096 data |= RXH_IP_DST | RXH_IP_SRC;
1097 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
1098 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1099 break;
1102 return data;
1105 static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1106 u32 *rule_locs)
1108 struct be_adapter *adapter = netdev_priv(netdev);
1110 if (!be_multi_rxq(adapter)) {
1111 dev_info(&adapter->pdev->dev,
1112 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
1113 return -EINVAL;
1116 switch (cmd->cmd) {
1117 case ETHTOOL_GRXFH:
1118 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
1119 break;
1120 case ETHTOOL_GRXRINGS:
1121 cmd->data = adapter->num_rx_qs;
1122 break;
1123 default:
1124 return -EINVAL;
1127 return 0;
1130 static int be_set_rss_hash_opts(struct be_adapter *adapter,
1131 struct ethtool_rxnfc *cmd)
1133 int status;
1134 u32 rss_flags = adapter->rss_info.rss_flags;
1136 if (cmd->data != L3_RSS_FLAGS &&
1137 cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
1138 return -EINVAL;
1140 switch (cmd->flow_type) {
1141 case TCP_V4_FLOW:
1142 if (cmd->data == L3_RSS_FLAGS)
1143 rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1144 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1145 rss_flags |= RSS_ENABLE_IPV4 |
1146 RSS_ENABLE_TCP_IPV4;
1147 break;
1148 case TCP_V6_FLOW:
1149 if (cmd->data == L3_RSS_FLAGS)
1150 rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1151 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1152 rss_flags |= RSS_ENABLE_IPV6 |
1153 RSS_ENABLE_TCP_IPV6;
1154 break;
1155 case UDP_V4_FLOW:
1156 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1157 BEx_chip(adapter))
1158 return -EINVAL;
1160 if (cmd->data == L3_RSS_FLAGS)
1161 rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1162 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1163 rss_flags |= RSS_ENABLE_IPV4 |
1164 RSS_ENABLE_UDP_IPV4;
1165 break;
1166 case UDP_V6_FLOW:
1167 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1168 BEx_chip(adapter))
1169 return -EINVAL;
1171 if (cmd->data == L3_RSS_FLAGS)
1172 rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1173 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1174 rss_flags |= RSS_ENABLE_IPV6 |
1175 RSS_ENABLE_UDP_IPV6;
1176 break;
1177 default:
1178 return -EINVAL;
1181 if (rss_flags == adapter->rss_info.rss_flags)
1182 return 0;
1184 status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
1185 rss_flags, RSS_INDIR_TABLE_LEN,
1186 adapter->rss_info.rss_hkey);
1187 if (!status)
1188 adapter->rss_info.rss_flags = rss_flags;
1190 return be_cmd_status(status);
1193 static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1195 struct be_adapter *adapter = netdev_priv(netdev);
1196 int status = 0;
1198 if (!be_multi_rxq(adapter)) {
1199 dev_err(&adapter->pdev->dev,
1200 "ethtool::set_rxnfc: RX flow hashing is disabled\n");
1201 return -EINVAL;
1204 switch (cmd->cmd) {
1205 case ETHTOOL_SRXFH:
1206 status = be_set_rss_hash_opts(adapter, cmd);
1207 break;
1208 default:
1209 return -EINVAL;
1212 return status;
1215 static void be_get_channels(struct net_device *netdev,
1216 struct ethtool_channels *ch)
1218 struct be_adapter *adapter = netdev_priv(netdev);
1219 u16 num_rx_irqs = max_t(u16, adapter->num_rss_qs, 1);
1221 /* num_tx_qs is always same as the number of irqs used for TX */
1222 ch->combined_count = min(adapter->num_tx_qs, num_rx_irqs);
1223 ch->rx_count = num_rx_irqs - ch->combined_count;
1224 ch->tx_count = adapter->num_tx_qs - ch->combined_count;
1226 ch->max_combined = be_max_qp_irqs(adapter);
1227 /* The user must create atleast one combined channel */
1228 ch->max_rx = be_max_rx_irqs(adapter) - 1;
1229 ch->max_tx = be_max_tx_irqs(adapter) - 1;
1232 static int be_set_channels(struct net_device *netdev,
1233 struct ethtool_channels *ch)
1235 struct be_adapter *adapter = netdev_priv(netdev);
1236 int status;
1238 /* we support either only combined channels or a combination of
1239 * combined and either RX-only or TX-only channels.
1241 if (ch->other_count || !ch->combined_count ||
1242 (ch->rx_count && ch->tx_count))
1243 return -EINVAL;
1245 if (ch->combined_count > be_max_qp_irqs(adapter) ||
1246 (ch->rx_count &&
1247 (ch->rx_count + ch->combined_count) > be_max_rx_irqs(adapter)) ||
1248 (ch->tx_count &&
1249 (ch->tx_count + ch->combined_count) > be_max_tx_irqs(adapter)))
1250 return -EINVAL;
1252 adapter->cfg_num_rx_irqs = ch->combined_count + ch->rx_count;
1253 adapter->cfg_num_tx_irqs = ch->combined_count + ch->tx_count;
1255 status = be_update_queues(adapter);
1256 return be_cmd_status(status);
1259 static u32 be_get_rxfh_indir_size(struct net_device *netdev)
1261 return RSS_INDIR_TABLE_LEN;
1264 static u32 be_get_rxfh_key_size(struct net_device *netdev)
1266 return RSS_HASH_KEY_LEN;
1269 static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
1270 u8 *hfunc)
1272 struct be_adapter *adapter = netdev_priv(netdev);
1273 int i;
1274 struct rss_info *rss = &adapter->rss_info;
1276 if (indir) {
1277 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
1278 indir[i] = rss->rss_queue[i];
1281 if (hkey)
1282 memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
1284 if (hfunc)
1285 *hfunc = ETH_RSS_HASH_TOP;
1287 return 0;
1290 static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
1291 const u8 *hkey, const u8 hfunc)
1293 int rc = 0, i, j;
1294 struct be_adapter *adapter = netdev_priv(netdev);
1295 u8 rsstable[RSS_INDIR_TABLE_LEN];
1297 /* We do not allow change in unsupported parameters */
1298 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1299 return -EOPNOTSUPP;
1301 if (indir) {
1302 struct be_rx_obj *rxo;
1304 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
1305 j = indir[i];
1306 rxo = &adapter->rx_obj[j];
1307 rsstable[i] = rxo->rss_id;
1308 adapter->rss_info.rss_queue[i] = j;
1310 } else {
1311 memcpy(rsstable, adapter->rss_info.rsstable,
1312 RSS_INDIR_TABLE_LEN);
1315 if (!hkey)
1316 hkey = adapter->rss_info.rss_hkey;
1318 rc = be_cmd_rss_config(adapter, rsstable,
1319 adapter->rss_info.rss_flags,
1320 RSS_INDIR_TABLE_LEN, hkey);
1321 if (rc) {
1322 adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
1323 return -EIO;
1325 memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
1326 memcpy(adapter->rss_info.rsstable, rsstable,
1327 RSS_INDIR_TABLE_LEN);
1328 return 0;
1331 static int be_get_module_info(struct net_device *netdev,
1332 struct ethtool_modinfo *modinfo)
1334 struct be_adapter *adapter = netdev_priv(netdev);
1335 u8 page_data[PAGE_DATA_LEN];
1336 int status;
1338 if (!check_privilege(adapter, MAX_PRIVILEGES))
1339 return -EOPNOTSUPP;
1341 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1342 page_data);
1343 if (!status) {
1344 if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
1345 modinfo->type = ETH_MODULE_SFF_8079;
1346 modinfo->eeprom_len = PAGE_DATA_LEN;
1347 } else {
1348 modinfo->type = ETH_MODULE_SFF_8472;
1349 modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
1352 return be_cmd_status(status);
1355 static int be_get_module_eeprom(struct net_device *netdev,
1356 struct ethtool_eeprom *eeprom, u8 *data)
1358 struct be_adapter *adapter = netdev_priv(netdev);
1359 int status;
1361 if (!check_privilege(adapter, MAX_PRIVILEGES))
1362 return -EOPNOTSUPP;
1364 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1365 data);
1366 if (status)
1367 goto err;
1369 if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
1370 status = be_cmd_read_port_transceiver_data(adapter,
1371 TR_PAGE_A2,
1372 data +
1373 PAGE_DATA_LEN);
1374 if (status)
1375 goto err;
1377 if (eeprom->offset)
1378 memcpy(data, data + eeprom->offset, eeprom->len);
1379 err:
1380 return be_cmd_status(status);
1383 static u32 be_get_priv_flags(struct net_device *netdev)
1385 struct be_adapter *adapter = netdev_priv(netdev);
1387 return adapter->priv_flags;
1390 static int be_set_priv_flags(struct net_device *netdev, u32 flags)
1392 struct be_adapter *adapter = netdev_priv(netdev);
1393 bool tpe_old = !!(adapter->priv_flags & BE_DISABLE_TPE_RECOVERY);
1394 bool tpe_new = !!(flags & BE_DISABLE_TPE_RECOVERY);
1396 if (tpe_old != tpe_new) {
1397 if (tpe_new) {
1398 adapter->priv_flags |= BE_DISABLE_TPE_RECOVERY;
1399 dev_info(&adapter->pdev->dev,
1400 "HW error recovery is disabled\n");
1401 } else {
1402 adapter->priv_flags &= ~BE_DISABLE_TPE_RECOVERY;
1403 dev_info(&adapter->pdev->dev,
1404 "HW error recovery is enabled\n");
1408 return 0;
1411 const struct ethtool_ops be_ethtool_ops = {
1412 .get_drvinfo = be_get_drvinfo,
1413 .get_wol = be_get_wol,
1414 .set_wol = be_set_wol,
1415 .get_link = ethtool_op_get_link,
1416 .get_eeprom_len = be_get_eeprom_len,
1417 .get_eeprom = be_read_eeprom,
1418 .get_coalesce = be_get_coalesce,
1419 .set_coalesce = be_set_coalesce,
1420 .get_ringparam = be_get_ringparam,
1421 .get_pauseparam = be_get_pauseparam,
1422 .set_pauseparam = be_set_pauseparam,
1423 .set_priv_flags = be_set_priv_flags,
1424 .get_priv_flags = be_get_priv_flags,
1425 .get_strings = be_get_stat_strings,
1426 .set_phys_id = be_set_phys_id,
1427 .set_dump = be_set_dump,
1428 .get_msglevel = be_get_msg_level,
1429 .set_msglevel = be_set_msg_level,
1430 .get_sset_count = be_get_sset_count,
1431 .get_ethtool_stats = be_get_ethtool_stats,
1432 .flash_device = be_do_flash,
1433 .self_test = be_self_test,
1434 .get_rxnfc = be_get_rxnfc,
1435 .set_rxnfc = be_set_rxnfc,
1436 .get_rxfh_indir_size = be_get_rxfh_indir_size,
1437 .get_rxfh_key_size = be_get_rxfh_key_size,
1438 .get_rxfh = be_get_rxfh,
1439 .set_rxfh = be_set_rxfh,
1440 .get_dump_flag = be_get_dump_flag,
1441 .get_dump_data = be_get_dump_data,
1442 .get_channels = be_get_channels,
1443 .set_channels = be_set_channels,
1444 .get_module_info = be_get_module_info,
1445 .get_module_eeprom = be_get_module_eeprom,
1446 .get_link_ksettings = be_get_link_ksettings,