2 * Copyright (C) 2005 - 2015 Emulex
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.
10 * Contact Information:
11 * linux-drivers@emulex.com
15 * Costa Mesa, CA 92626
20 #include <linux/ethtool.h>
22 struct be_ethtool_stat {
23 char desc[ETH_GSTRING_LEN];
29 enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
30 #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
31 offsetof(_struct, field)
32 #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\
33 FIELDINFO(struct be_tx_stats, field)
34 #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\
35 FIELDINFO(struct be_rx_stats, field)
36 #define DRVSTAT_INFO(field) #field, DRVSTAT,\
37 FIELDINFO(struct be_drv_stats, field)
39 static const struct be_ethtool_stat et_stats[] = {
40 {DRVSTAT_INFO(rx_crc_errors)},
41 {DRVSTAT_INFO(rx_alignment_symbol_errors)},
42 {DRVSTAT_INFO(rx_pause_frames)},
43 {DRVSTAT_INFO(rx_control_frames)},
44 /* Received packets dropped when the Ethernet length field
45 * is not equal to the actual Ethernet data length.
47 {DRVSTAT_INFO(rx_in_range_errors)},
48 /* Received packets dropped when their length field is >= 1501 bytes
51 {DRVSTAT_INFO(rx_out_range_errors)},
52 /* Received packets dropped when they are longer than 9216 bytes */
53 {DRVSTAT_INFO(rx_frame_too_long)},
54 /* Received packets dropped when they don't pass the unicast or
55 * multicast address filtering.
57 {DRVSTAT_INFO(rx_address_filtered)},
58 /* Received packets dropped when IP packet length field is less than
59 * the IP header length field.
61 {DRVSTAT_INFO(rx_dropped_too_small)},
62 /* Received packets dropped when IP length field is greater than
63 * the actual packet length.
65 {DRVSTAT_INFO(rx_dropped_too_short)},
66 /* Received packets dropped when the IP header length field is less
69 {DRVSTAT_INFO(rx_dropped_header_too_small)},
70 /* Received packets dropped when the TCP header length field is less
71 * than 5 or the TCP header length + IP header length is more
72 * than IP packet length.
74 {DRVSTAT_INFO(rx_dropped_tcp_length)},
75 {DRVSTAT_INFO(rx_dropped_runt)},
76 /* Number of received packets dropped when a fifo for descriptors going
77 * into the packet demux block overflows. In normal operation, this
78 * fifo must never overflow.
80 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
81 /* Received packets dropped when the RX block runs out of space in
82 * one of its input FIFOs. This could happen due a long burst of
83 * minimum-sized (64b) frames in the receive path.
84 * This counter may also be erroneously incremented rarely.
86 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
87 {DRVSTAT_INFO(rx_ip_checksum_errs)},
88 {DRVSTAT_INFO(rx_tcp_checksum_errs)},
89 {DRVSTAT_INFO(rx_udp_checksum_errs)},
90 {DRVSTAT_INFO(tx_pauseframes)},
91 {DRVSTAT_INFO(tx_controlframes)},
92 {DRVSTAT_INFO(rx_priority_pause_frames)},
93 {DRVSTAT_INFO(tx_priority_pauseframes)},
94 /* Received packets dropped when an internal fifo going into
95 * main packet buffer tank (PMEM) overflows.
97 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
98 {DRVSTAT_INFO(jabber_events)},
99 /* Received packets dropped due to lack of available HW packet buffers
100 * used to temporarily hold the received packets.
102 {DRVSTAT_INFO(rx_drops_no_pbuf)},
103 /* Received packets dropped due to input receive buffer
104 * descriptor fifo overflowing.
106 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
107 /* Packets dropped because the internal FIFO to the offloaded TCP
108 * receive processing block is full. This could happen only for
109 * offloaded iSCSI or FCoE trarffic.
111 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
112 /* Received packets dropped when they need more than 8
113 * receive buffers. This cannot happen as the driver configures
114 * 2048 byte receive buffers.
116 {DRVSTAT_INFO(rx_drops_too_many_frags)},
117 {DRVSTAT_INFO(forwarded_packets)},
118 /* Received packets dropped when the frame length
119 * is more than 9018 bytes
121 {DRVSTAT_INFO(rx_drops_mtu)},
122 /* Number of dma mapping errors */
123 {DRVSTAT_INFO(dma_map_errors)},
124 /* Number of packets dropped due to random early drop function */
125 {DRVSTAT_INFO(eth_red_drops)},
126 {DRVSTAT_INFO(rx_roce_bytes_lsd)},
127 {DRVSTAT_INFO(rx_roce_bytes_msd)},
128 {DRVSTAT_INFO(rx_roce_frames)},
129 {DRVSTAT_INFO(roce_drops_payload_len)},
130 {DRVSTAT_INFO(roce_drops_crc)}
133 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
135 /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
136 * are first and second members respectively.
138 static const struct be_ethtool_stat et_rx_stats[] = {
139 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
140 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
141 {DRVSTAT_RX_INFO(rx_vxlan_offload_pkts)},
142 {DRVSTAT_RX_INFO(rx_compl)},
143 {DRVSTAT_RX_INFO(rx_compl_err)},
144 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
145 /* Number of page allocation failures while posting receive buffers
148 {DRVSTAT_RX_INFO(rx_post_fail)},
149 /* Recevied packets dropped due to skb allocation failure */
150 {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
151 /* Received packets dropped due to lack of available fetched buffers
152 * posted by the driver.
154 {DRVSTAT_RX_INFO(rx_drops_no_frags)}
157 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
159 /* Stats related to multi TX queues: get_stats routine assumes compl is the
162 static const struct be_ethtool_stat et_tx_stats[] = {
163 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
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.
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.
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
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
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.
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.
191 {DRVSTAT_TX_INFO(tx_internal_parity_err)},
192 {DRVSTAT_TX_INFO(tx_bytes)},
193 {DRVSTAT_TX_INFO(tx_pkts)},
194 {DRVSTAT_TX_INFO(tx_vxlan_offload_pkts)},
195 /* Number of skbs queued for trasmission by the driver */
196 {DRVSTAT_TX_INFO(tx_reqs)},
197 /* Number of times the TX queue was stopped due to lack
198 * of spaces in the TXQ.
200 {DRVSTAT_TX_INFO(tx_stops)},
201 /* Pkts dropped in the driver's transmit path */
202 {DRVSTAT_TX_INFO(tx_drv_drops)}
205 #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
207 static const char et_self_tests[][ETH_GSTRING_LEN] = {
210 "External Loopback test",
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
219 #define BE_NO_LOOPBACK 0xff
221 static void be_get_drvinfo(struct net_device *netdev,
222 struct ethtool_drvinfo *drvinfo)
224 struct be_adapter *adapter = netdev_priv(netdev);
226 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
227 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
228 if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN))
229 strlcpy(drvinfo->fw_version, adapter->fw_ver,
230 sizeof(drvinfo->fw_version));
232 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
233 "%s [%s]", adapter->fw_ver, adapter->fw_on_flash);
235 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
236 sizeof(drvinfo->bus_info));
239 static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
241 u32 data_read = 0, eof;
243 struct be_dma_mem data_len_cmd;
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,
249 file_name, &data_read, &eof,
255 static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
256 u32 buf_len, void *buf)
258 struct be_dma_mem read_cmd;
259 u32 read_len = 0, total_read_len = 0, chunk_size;
264 read_cmd.size = LANCER_READ_FILE_CHUNK;
265 read_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, read_cmd.size,
266 &read_cmd.dma, GFP_ATOMIC);
269 dev_err(&adapter->pdev->dev,
270 "Memory allocation failure while reading dump\n");
274 while ((total_read_len < buf_len) && !eof) {
275 chunk_size = min_t(u32, (buf_len - total_read_len),
276 LANCER_READ_FILE_CHUNK);
277 chunk_size = ALIGN(chunk_size, 4);
278 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
279 total_read_len, file_name,
280 &read_len, &eof, &addn_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;
290 dma_free_coherent(&adapter->pdev->dev, read_cmd.size, read_cmd.va,
296 static int be_get_reg_len(struct net_device *netdev)
298 struct be_adapter *adapter = netdev_priv(netdev);
301 if (!check_privilege(adapter, MAX_PRIVILEGES))
304 if (be_physfn(adapter)) {
305 if (lancer_chip(adapter))
306 log_size = lancer_cmd_get_file_len(adapter,
307 LANCER_FW_DUMP_FILE);
309 be_cmd_get_reg_len(adapter, &log_size);
315 be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
317 struct be_adapter *adapter = netdev_priv(netdev);
319 if (be_physfn(adapter)) {
320 memset(buf, 0, regs->len);
321 if (lancer_chip(adapter))
322 lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
325 be_cmd_get_regs(adapter, regs->len, buf);
329 static int be_get_coalesce(struct net_device *netdev,
330 struct ethtool_coalesce *et)
332 struct be_adapter *adapter = netdev_priv(netdev);
333 struct be_aic_obj *aic = &adapter->aic_obj[0];
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;
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;
343 et->use_adaptive_rx_coalesce = aic->enable;
344 et->use_adaptive_tx_coalesce = aic->enable;
349 /* TX attributes are ignored. Only RX attributes are considered
350 * eqd cmd is issued in the worker thread.
352 static int be_set_coalesce(struct net_device *netdev,
353 struct ethtool_coalesce *et)
355 struct be_adapter *adapter = netdev_priv(netdev);
356 struct be_aic_obj *aic = &adapter->aic_obj[0];
357 struct be_eq_obj *eqo;
360 for_all_evt_queues(adapter, eqo, i) {
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);
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
374 if (!et->use_adaptive_rx_coalesce && skyhawk_chip(adapter))
375 be_eqd_update(adapter, true);
380 static void be_get_ethtool_stats(struct net_device *netdev,
381 struct ethtool_stats *stats, uint64_t *data)
383 struct be_adapter *adapter = netdev_priv(netdev);
384 struct be_rx_obj *rxo;
385 struct be_tx_obj *txo;
387 unsigned int i, j, base = 0, start;
389 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
390 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
393 base += ETHTOOL_STATS_NUM;
395 for_all_rx_queues(adapter, rxo, j) {
396 struct be_rx_stats *stats = rx_stats(rxo);
399 start = u64_stats_fetch_begin_irq(&stats->sync);
400 data[base] = stats->rx_bytes;
401 data[base + 1] = stats->rx_pkts;
402 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
404 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
405 p = (u8 *)stats + et_rx_stats[i].offset;
406 data[base + i] = *(u32 *)p;
408 base += ETHTOOL_RXSTATS_NUM;
411 for_all_tx_queues(adapter, txo, j) {
412 struct be_tx_stats *stats = tx_stats(txo);
415 start = u64_stats_fetch_begin_irq(&stats->sync_compl);
416 data[base] = stats->tx_compl;
417 } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
420 start = u64_stats_fetch_begin_irq(&stats->sync);
421 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
422 p = (u8 *)stats + et_tx_stats[i].offset;
424 (et_tx_stats[i].size == sizeof(u64)) ?
425 *(u64 *)p : *(u32 *)p;
427 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
428 base += ETHTOOL_TXSTATS_NUM;
432 static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
435 struct be_adapter *adapter = netdev_priv(netdev);
440 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
441 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
442 data += ETH_GSTRING_LEN;
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;
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;
460 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
461 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
462 data += ETH_GSTRING_LEN;
468 static int be_get_sset_count(struct net_device *netdev, int stringset)
470 struct be_adapter *adapter = netdev_priv(netdev);
474 return ETHTOOL_TESTS_NUM;
476 return ETHTOOL_STATS_NUM +
477 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
478 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
484 static u32 be_get_port_type(struct be_adapter *adapter)
488 switch (adapter->phy.interface_type) {
489 case PHY_TYPE_BASET_1GB:
490 case PHY_TYPE_BASEX_1GB:
494 case PHY_TYPE_SFP_PLUS_10GB:
495 if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE)
501 if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE)
506 case PHY_TYPE_XFP_10GB:
507 case PHY_TYPE_SFP_1GB:
510 case PHY_TYPE_BASET_10GB:
520 static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
524 switch (adapter->phy.interface_type) {
525 case PHY_TYPE_BASET_1GB:
526 case PHY_TYPE_BASEX_1GB:
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;
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;
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;
550 case PHY_TYPE_KR_10GB:
551 val |= SUPPORTED_Backplane |
552 SUPPORTED_10000baseKR_Full;
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;
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;
567 case QSFP_PLUS_LR4_CABLE:
568 val |= SUPPORTED_40000baseLR4_Full;
571 val |= SUPPORTED_40000baseSR4_Full;
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;
584 case PHY_TYPE_BASET_10GB:
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;
600 bool be_pause_supported(struct be_adapter *adapter)
602 return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
603 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
607 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
609 struct be_adapter *adapter = netdev_priv(netdev);
616 if (adapter->phy.link_speed < 0) {
617 status = be_cmd_link_status_query(adapter, &link_speed,
620 be_link_status_update(adapter, link_status);
621 ethtool_cmd_speed_set(ecmd, link_speed);
623 status = be_cmd_get_phy_info(adapter);
625 auto_speeds = adapter->phy.auto_speeds_supported;
626 fixed_speeds = adapter->phy.fixed_speeds_supported;
628 be_cmd_query_cable_type(adapter);
631 convert_to_et_setting(adapter,
635 convert_to_et_setting(adapter, auto_speeds);
637 ecmd->port = be_get_port_type(adapter);
639 if (adapter->phy.auto_speeds_supported) {
640 ecmd->supported |= SUPPORTED_Autoneg;
641 ecmd->autoneg = AUTONEG_ENABLE;
642 ecmd->advertising |= ADVERTISED_Autoneg;
645 ecmd->supported |= SUPPORTED_Pause;
646 if (be_pause_supported(adapter))
647 ecmd->advertising |= ADVERTISED_Pause;
649 switch (adapter->phy.interface_type) {
650 case PHY_TYPE_KR_10GB:
651 case PHY_TYPE_KX4_10GB:
652 ecmd->transceiver = XCVR_INTERNAL;
655 ecmd->transceiver = XCVR_EXTERNAL;
659 ecmd->port = PORT_OTHER;
660 ecmd->autoneg = AUTONEG_DISABLE;
661 ecmd->transceiver = XCVR_DUMMY1;
664 /* Save for future use */
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;
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;
680 ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
681 ecmd->phy_address = adapter->port_num;
686 static void be_get_ringparam(struct net_device *netdev,
687 struct ethtool_ringparam *ring)
689 struct be_adapter *adapter = netdev_priv(netdev);
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;
698 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
700 struct be_adapter *adapter = netdev_priv(netdev);
702 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
703 ecmd->autoneg = adapter->phy.fc_autoneg;
707 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
709 struct be_adapter *adapter = netdev_priv(netdev);
712 if (ecmd->autoneg != adapter->phy.fc_autoneg)
715 status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
718 dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
719 return be_cmd_status(status);
722 adapter->tx_fc = ecmd->tx_pause;
723 adapter->rx_fc = ecmd->rx_pause;
727 static int be_set_phys_id(struct net_device *netdev,
728 enum ethtool_phys_id_state state)
730 struct be_adapter *adapter = netdev_priv(netdev);
733 case ETHTOOL_ID_ACTIVE:
734 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
735 &adapter->beacon_state);
736 return 1; /* cycle on/off once per second */
739 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
740 BEACON_STATE_ENABLED);
744 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
745 BEACON_STATE_DISABLED);
748 case ETHTOOL_ID_INACTIVE:
749 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
750 adapter->beacon_state);
756 static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
758 struct be_adapter *adapter = netdev_priv(netdev);
759 struct device *dev = &adapter->pdev->dev;
762 if (!lancer_chip(adapter) ||
763 !check_privilege(adapter, MAX_PRIVILEGES))
766 switch (dump->flag) {
767 case LANCER_INITIATE_FW_DUMP:
768 status = lancer_initiate_dump(adapter);
770 dev_info(dev, "FW dump initiated successfully\n");
772 case LANCER_DELETE_FW_DUMP:
773 status = lancer_delete_dump(adapter);
775 dev_info(dev, "FW dump deleted successfully\n");
778 dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
784 static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
786 struct be_adapter *adapter = netdev_priv(netdev);
788 if (adapter->wol_cap & BE_WOL_CAP) {
789 wol->supported |= WAKE_MAGIC;
791 wol->wolopts |= WAKE_MAGIC;
795 memset(&wol->sopass, 0, sizeof(wol->sopass));
798 static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
800 struct be_adapter *adapter = netdev_priv(netdev);
802 if (wol->wolopts & ~WAKE_MAGIC)
805 if (!(adapter->wol_cap & BE_WOL_CAP)) {
806 dev_warn(&adapter->pdev->dev, "WOL not supported\n");
810 if (wol->wolopts & WAKE_MAGIC)
811 adapter->wol_en = true;
813 adapter->wol_en = false;
818 static int be_test_ddr_dma(struct be_adapter *adapter)
821 struct be_dma_mem ddrdma_cmd;
822 static const u64 pattern[2] = {
823 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
826 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
827 ddrdma_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
828 ddrdma_cmd.size, &ddrdma_cmd.dma,
833 for (i = 0; i < 2; i++) {
834 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
841 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
843 return be_cmd_status(ret);
846 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
851 ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
856 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
857 loopback_type, 1500, 2, 0xabc);
859 ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
867 static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
870 struct be_adapter *adapter = netdev_priv(netdev);
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;
880 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
882 if (test->flags & ETH_TEST_FL_OFFLINE) {
883 if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
884 test->flags |= ETH_TEST_FL_FAILED;
886 if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
887 test->flags |= ETH_TEST_FL_FAILED;
889 if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
890 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
892 test->flags |= ETH_TEST_FL_FAILED;
893 test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
897 if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
899 test->flags |= ETH_TEST_FL_FAILED;
902 status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
904 test->flags |= ETH_TEST_FL_FAILED;
906 } else if (!link_status) {
907 test->flags |= ETH_TEST_FL_FAILED;
912 static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
914 struct be_adapter *adapter = netdev_priv(netdev);
916 return be_load_fw(adapter, efl->data);
919 static int be_get_eeprom_len(struct net_device *netdev)
921 struct be_adapter *adapter = netdev_priv(netdev);
923 if (!check_privilege(adapter, MAX_PRIVILEGES))
926 if (lancer_chip(adapter)) {
927 if (be_physfn(adapter))
928 return lancer_cmd_get_file_len(adapter,
931 return lancer_cmd_get_file_len(adapter,
934 return BE_READ_SEEPROM_LEN;
938 static int be_read_eeprom(struct net_device *netdev,
939 struct ethtool_eeprom *eeprom, uint8_t *data)
941 struct be_adapter *adapter = netdev_priv(netdev);
942 struct be_dma_mem eeprom_cmd;
943 struct be_cmd_resp_seeprom_read *resp;
949 if (lancer_chip(adapter)) {
950 if (be_physfn(adapter))
951 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
954 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
958 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
960 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
961 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
962 eeprom_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
963 eeprom_cmd.size, &eeprom_cmd.dma,
969 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
972 resp = eeprom_cmd.va;
973 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
975 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
978 return be_cmd_status(status);
981 static u32 be_get_msg_level(struct net_device *netdev)
983 struct be_adapter *adapter = netdev_priv(netdev);
985 return adapter->msg_enable;
988 static void be_set_msg_level(struct net_device *netdev, u32 level)
990 struct be_adapter *adapter = netdev_priv(netdev);
992 if (adapter->msg_enable == level)
995 if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
996 if (BEx_chip(adapter))
997 be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
998 FW_LOG_LEVEL_DEFAULT :
1000 adapter->msg_enable = level;
1003 static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
1007 switch (flow_type) {
1009 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
1010 data |= RXH_IP_DST | RXH_IP_SRC;
1011 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
1012 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1015 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
1016 data |= RXH_IP_DST | RXH_IP_SRC;
1017 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
1018 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1021 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1022 data |= RXH_IP_DST | RXH_IP_SRC;
1023 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
1024 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1027 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1028 data |= RXH_IP_DST | RXH_IP_SRC;
1029 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
1030 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1037 static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1040 struct be_adapter *adapter = netdev_priv(netdev);
1042 if (!be_multi_rxq(adapter)) {
1043 dev_info(&adapter->pdev->dev,
1044 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
1050 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
1052 case ETHTOOL_GRXRINGS:
1053 cmd->data = adapter->num_rx_qs - 1;
1062 static int be_set_rss_hash_opts(struct be_adapter *adapter,
1063 struct ethtool_rxnfc *cmd)
1065 struct be_rx_obj *rxo;
1066 int status = 0, i, j;
1068 u32 rss_flags = adapter->rss_info.rss_flags;
1070 if (cmd->data != L3_RSS_FLAGS &&
1071 cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
1074 switch (cmd->flow_type) {
1076 if (cmd->data == L3_RSS_FLAGS)
1077 rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1078 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1079 rss_flags |= RSS_ENABLE_IPV4 |
1080 RSS_ENABLE_TCP_IPV4;
1083 if (cmd->data == L3_RSS_FLAGS)
1084 rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1085 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1086 rss_flags |= RSS_ENABLE_IPV6 |
1087 RSS_ENABLE_TCP_IPV6;
1090 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1094 if (cmd->data == L3_RSS_FLAGS)
1095 rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1096 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1097 rss_flags |= RSS_ENABLE_IPV4 |
1098 RSS_ENABLE_UDP_IPV4;
1101 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1105 if (cmd->data == L3_RSS_FLAGS)
1106 rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1107 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1108 rss_flags |= RSS_ENABLE_IPV6 |
1109 RSS_ENABLE_UDP_IPV6;
1115 if (rss_flags == adapter->rss_info.rss_flags)
1118 if (be_multi_rxq(adapter)) {
1119 for (j = 0; j < 128; j += adapter->num_rss_qs) {
1120 for_all_rss_queues(adapter, rxo, i) {
1123 rsstable[j + i] = rxo->rss_id;
1128 status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
1129 rss_flags, 128, adapter->rss_info.rss_hkey);
1131 adapter->rss_info.rss_flags = rss_flags;
1133 return be_cmd_status(status);
1136 static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1138 struct be_adapter *adapter = netdev_priv(netdev);
1141 if (!be_multi_rxq(adapter)) {
1142 dev_err(&adapter->pdev->dev,
1143 "ethtool::set_rxnfc: RX flow hashing is disabled\n");
1149 status = be_set_rss_hash_opts(adapter, cmd);
1158 static void be_get_channels(struct net_device *netdev,
1159 struct ethtool_channels *ch)
1161 struct be_adapter *adapter = netdev_priv(netdev);
1163 ch->combined_count = adapter->num_evt_qs;
1164 ch->max_combined = be_max_qs(adapter);
1167 static int be_set_channels(struct net_device *netdev,
1168 struct ethtool_channels *ch)
1170 struct be_adapter *adapter = netdev_priv(netdev);
1173 if (ch->rx_count || ch->tx_count || ch->other_count ||
1174 !ch->combined_count || ch->combined_count > be_max_qs(adapter))
1177 adapter->cfg_num_qs = ch->combined_count;
1179 status = be_update_queues(adapter);
1180 return be_cmd_status(status);
1183 static u32 be_get_rxfh_indir_size(struct net_device *netdev)
1185 return RSS_INDIR_TABLE_LEN;
1188 static u32 be_get_rxfh_key_size(struct net_device *netdev)
1190 return RSS_HASH_KEY_LEN;
1193 static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
1196 struct be_adapter *adapter = netdev_priv(netdev);
1198 struct rss_info *rss = &adapter->rss_info;
1201 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
1202 indir[i] = rss->rss_queue[i];
1206 memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
1209 *hfunc = ETH_RSS_HASH_TOP;
1214 static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
1215 const u8 *hkey, const u8 hfunc)
1218 struct be_adapter *adapter = netdev_priv(netdev);
1219 u8 rsstable[RSS_INDIR_TABLE_LEN];
1221 /* We do not allow change in unsupported parameters */
1222 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1226 struct be_rx_obj *rxo;
1228 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
1230 rxo = &adapter->rx_obj[j];
1231 rsstable[i] = rxo->rss_id;
1232 adapter->rss_info.rss_queue[i] = j;
1235 memcpy(rsstable, adapter->rss_info.rsstable,
1236 RSS_INDIR_TABLE_LEN);
1240 hkey = adapter->rss_info.rss_hkey;
1242 rc = be_cmd_rss_config(adapter, rsstable,
1243 adapter->rss_info.rss_flags,
1244 RSS_INDIR_TABLE_LEN, hkey);
1246 adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
1249 memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
1250 memcpy(adapter->rss_info.rsstable, rsstable,
1251 RSS_INDIR_TABLE_LEN);
1255 static int be_get_module_info(struct net_device *netdev,
1256 struct ethtool_modinfo *modinfo)
1258 struct be_adapter *adapter = netdev_priv(netdev);
1259 u8 page_data[PAGE_DATA_LEN];
1262 if (!check_privilege(adapter, MAX_PRIVILEGES))
1265 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1268 if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
1269 modinfo->type = ETH_MODULE_SFF_8079;
1270 modinfo->eeprom_len = PAGE_DATA_LEN;
1272 modinfo->type = ETH_MODULE_SFF_8472;
1273 modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
1276 return be_cmd_status(status);
1279 static int be_get_module_eeprom(struct net_device *netdev,
1280 struct ethtool_eeprom *eeprom, u8 *data)
1282 struct be_adapter *adapter = netdev_priv(netdev);
1285 if (!check_privilege(adapter, MAX_PRIVILEGES))
1288 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1293 if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
1294 status = be_cmd_read_port_transceiver_data(adapter,
1302 memcpy(data, data + eeprom->offset, eeprom->len);
1304 return be_cmd_status(status);
1307 const struct ethtool_ops be_ethtool_ops = {
1308 .get_settings = be_get_settings,
1309 .get_drvinfo = be_get_drvinfo,
1310 .get_wol = be_get_wol,
1311 .set_wol = be_set_wol,
1312 .get_link = ethtool_op_get_link,
1313 .get_eeprom_len = be_get_eeprom_len,
1314 .get_eeprom = be_read_eeprom,
1315 .get_coalesce = be_get_coalesce,
1316 .set_coalesce = be_set_coalesce,
1317 .get_ringparam = be_get_ringparam,
1318 .get_pauseparam = be_get_pauseparam,
1319 .set_pauseparam = be_set_pauseparam,
1320 .get_strings = be_get_stat_strings,
1321 .set_phys_id = be_set_phys_id,
1322 .set_dump = be_set_dump,
1323 .get_msglevel = be_get_msg_level,
1324 .set_msglevel = be_set_msg_level,
1325 .get_sset_count = be_get_sset_count,
1326 .get_ethtool_stats = be_get_ethtool_stats,
1327 .get_regs_len = be_get_reg_len,
1328 .get_regs = be_get_regs,
1329 .flash_device = be_do_flash,
1330 .self_test = be_self_test,
1331 .get_rxnfc = be_get_rxnfc,
1332 .set_rxnfc = be_set_rxnfc,
1333 .get_rxfh_indir_size = be_get_rxfh_indir_size,
1334 .get_rxfh_key_size = be_get_rxfh_key_size,
1335 .get_rxfh = be_get_rxfh,
1336 .set_rxfh = be_set_rxfh,
1337 .get_channels = be_get_channels,
1338 .set_channels = be_set_channels,
1339 .get_module_info = be_get_module_info,
1340 .get_module_eeprom = be_get_module_eeprom