1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All rights reserved.
6 #include <linux/ethtool.h>
9 #include "ena_netdev.h"
12 char name[ETH_GSTRING_LEN];
16 #define ENA_STAT_ENA_COM_ENTRY(stat) { \
18 .stat_offset = offsetof(struct ena_com_stats_admin, stat) / sizeof(u64) \
21 #define ENA_STAT_ENTRY(stat, stat_type) { \
23 .stat_offset = offsetof(struct ena_stats_##stat_type, stat) / sizeof(u64) \
26 #define ENA_STAT_HW_ENTRY(stat, stat_type) { \
28 .stat_offset = offsetof(struct ena_admin_##stat_type, stat) / sizeof(u64) \
31 #define ENA_STAT_RX_ENTRY(stat) \
32 ENA_STAT_ENTRY(stat, rx)
34 #define ENA_STAT_TX_ENTRY(stat) \
35 ENA_STAT_ENTRY(stat, tx)
37 #define ENA_STAT_GLOBAL_ENTRY(stat) \
38 ENA_STAT_ENTRY(stat, dev)
40 #define ENA_STAT_ENI_ENTRY(stat) \
41 ENA_STAT_HW_ENTRY(stat, eni_stats)
43 static const struct ena_stats ena_stats_global_strings[] = {
44 ENA_STAT_GLOBAL_ENTRY(tx_timeout),
45 ENA_STAT_GLOBAL_ENTRY(suspend),
46 ENA_STAT_GLOBAL_ENTRY(resume),
47 ENA_STAT_GLOBAL_ENTRY(wd_expired),
48 ENA_STAT_GLOBAL_ENTRY(interface_up),
49 ENA_STAT_GLOBAL_ENTRY(interface_down),
50 ENA_STAT_GLOBAL_ENTRY(admin_q_pause),
53 static const struct ena_stats ena_stats_eni_strings[] = {
54 ENA_STAT_ENI_ENTRY(bw_in_allowance_exceeded),
55 ENA_STAT_ENI_ENTRY(bw_out_allowance_exceeded),
56 ENA_STAT_ENI_ENTRY(pps_allowance_exceeded),
57 ENA_STAT_ENI_ENTRY(conntrack_allowance_exceeded),
58 ENA_STAT_ENI_ENTRY(linklocal_allowance_exceeded),
61 static const struct ena_stats ena_stats_tx_strings[] = {
62 ENA_STAT_TX_ENTRY(cnt),
63 ENA_STAT_TX_ENTRY(bytes),
64 ENA_STAT_TX_ENTRY(queue_stop),
65 ENA_STAT_TX_ENTRY(queue_wakeup),
66 ENA_STAT_TX_ENTRY(dma_mapping_err),
67 ENA_STAT_TX_ENTRY(linearize),
68 ENA_STAT_TX_ENTRY(linearize_failed),
69 ENA_STAT_TX_ENTRY(napi_comp),
70 ENA_STAT_TX_ENTRY(tx_poll),
71 ENA_STAT_TX_ENTRY(doorbells),
72 ENA_STAT_TX_ENTRY(prepare_ctx_err),
73 ENA_STAT_TX_ENTRY(bad_req_id),
74 ENA_STAT_TX_ENTRY(llq_buffer_copy),
75 ENA_STAT_TX_ENTRY(missed_tx),
76 ENA_STAT_TX_ENTRY(unmask_interrupt),
79 static const struct ena_stats ena_stats_rx_strings[] = {
80 ENA_STAT_RX_ENTRY(cnt),
81 ENA_STAT_RX_ENTRY(bytes),
82 ENA_STAT_RX_ENTRY(rx_copybreak_pkt),
83 ENA_STAT_RX_ENTRY(csum_good),
84 ENA_STAT_RX_ENTRY(refil_partial),
85 ENA_STAT_RX_ENTRY(csum_bad),
86 ENA_STAT_RX_ENTRY(page_alloc_fail),
87 ENA_STAT_RX_ENTRY(skb_alloc_fail),
88 ENA_STAT_RX_ENTRY(dma_mapping_err),
89 ENA_STAT_RX_ENTRY(bad_desc_num),
90 ENA_STAT_RX_ENTRY(bad_req_id),
91 ENA_STAT_RX_ENTRY(empty_rx_ring),
92 ENA_STAT_RX_ENTRY(csum_unchecked),
93 ENA_STAT_RX_ENTRY(xdp_aborted),
94 ENA_STAT_RX_ENTRY(xdp_drop),
95 ENA_STAT_RX_ENTRY(xdp_pass),
96 ENA_STAT_RX_ENTRY(xdp_tx),
97 ENA_STAT_RX_ENTRY(xdp_invalid),
98 ENA_STAT_RX_ENTRY(xdp_redirect),
101 static const struct ena_stats ena_stats_ena_com_strings[] = {
102 ENA_STAT_ENA_COM_ENTRY(aborted_cmd),
103 ENA_STAT_ENA_COM_ENTRY(submitted_cmd),
104 ENA_STAT_ENA_COM_ENTRY(completed_cmd),
105 ENA_STAT_ENA_COM_ENTRY(out_of_space),
106 ENA_STAT_ENA_COM_ENTRY(no_completion),
109 #define ENA_STATS_ARRAY_GLOBAL ARRAY_SIZE(ena_stats_global_strings)
110 #define ENA_STATS_ARRAY_TX ARRAY_SIZE(ena_stats_tx_strings)
111 #define ENA_STATS_ARRAY_RX ARRAY_SIZE(ena_stats_rx_strings)
112 #define ENA_STATS_ARRAY_ENA_COM ARRAY_SIZE(ena_stats_ena_com_strings)
113 #define ENA_STATS_ARRAY_ENI(adapter) ARRAY_SIZE(ena_stats_eni_strings)
115 static void ena_safe_update_stat(u64 *src, u64 *dst,
116 struct u64_stats_sync *syncp)
121 start = u64_stats_fetch_begin_irq(syncp);
123 } while (u64_stats_fetch_retry_irq(syncp, start));
126 static void ena_queue_stats(struct ena_adapter *adapter, u64 **data)
128 const struct ena_stats *ena_stats;
129 struct ena_ring *ring;
134 for (i = 0; i < adapter->num_io_queues + adapter->xdp_num_queues; i++) {
136 ring = &adapter->tx_ring[i];
138 for (j = 0; j < ENA_STATS_ARRAY_TX; j++) {
139 ena_stats = &ena_stats_tx_strings[j];
141 ptr = (u64 *)&ring->tx_stats + ena_stats->stat_offset;
143 ena_safe_update_stat(ptr, (*data)++, &ring->syncp);
145 /* XDP TX queues don't have a RX queue counterpart */
146 if (!ENA_IS_XDP_INDEX(adapter, i)) {
148 ring = &adapter->rx_ring[i];
150 for (j = 0; j < ENA_STATS_ARRAY_RX; j++) {
151 ena_stats = &ena_stats_rx_strings[j];
153 ptr = (u64 *)&ring->rx_stats +
154 ena_stats->stat_offset;
156 ena_safe_update_stat(ptr, (*data)++, &ring->syncp);
162 static void ena_dev_admin_queue_stats(struct ena_adapter *adapter, u64 **data)
164 const struct ena_stats *ena_stats;
168 for (i = 0; i < ENA_STATS_ARRAY_ENA_COM; i++) {
169 ena_stats = &ena_stats_ena_com_strings[i];
171 ptr = (u64 *)&adapter->ena_dev->admin_queue.stats +
172 ena_stats->stat_offset;
178 static void ena_get_stats(struct ena_adapter *adapter,
180 bool eni_stats_needed)
182 const struct ena_stats *ena_stats;
186 for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
187 ena_stats = &ena_stats_global_strings[i];
189 ptr = (u64 *)&adapter->dev_stats + ena_stats->stat_offset;
191 ena_safe_update_stat(ptr, data++, &adapter->syncp);
194 if (eni_stats_needed) {
195 ena_update_hw_stats(adapter);
196 for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
197 ena_stats = &ena_stats_eni_strings[i];
199 ptr = (u64 *)&adapter->eni_stats +
200 ena_stats->stat_offset;
202 ena_safe_update_stat(ptr, data++, &adapter->syncp);
206 ena_queue_stats(adapter, &data);
207 ena_dev_admin_queue_stats(adapter, &data);
210 static void ena_get_ethtool_stats(struct net_device *netdev,
211 struct ethtool_stats *stats,
214 struct ena_adapter *adapter = netdev_priv(netdev);
215 struct ena_com_dev *dev = adapter->ena_dev;
217 ena_get_stats(adapter, data, ena_com_get_cap(dev, ENA_ADMIN_ENI_STATS));
220 static int ena_get_sw_stats_count(struct ena_adapter *adapter)
222 return adapter->num_io_queues * (ENA_STATS_ARRAY_TX + ENA_STATS_ARRAY_RX)
223 + adapter->xdp_num_queues * ENA_STATS_ARRAY_TX
224 + ENA_STATS_ARRAY_GLOBAL + ENA_STATS_ARRAY_ENA_COM;
227 static int ena_get_hw_stats_count(struct ena_adapter *adapter)
229 bool supported = ena_com_get_cap(adapter->ena_dev, ENA_ADMIN_ENI_STATS);
231 return ENA_STATS_ARRAY_ENI(adapter) * supported;
234 int ena_get_sset_count(struct net_device *netdev, int sset)
236 struct ena_adapter *adapter = netdev_priv(netdev);
240 return ena_get_sw_stats_count(adapter) +
241 ena_get_hw_stats_count(adapter);
247 static void ena_queue_strings(struct ena_adapter *adapter, u8 **data)
249 const struct ena_stats *ena_stats;
253 for (i = 0; i < adapter->num_io_queues + adapter->xdp_num_queues; i++) {
254 is_xdp = ENA_IS_XDP_INDEX(adapter, i);
256 for (j = 0; j < ENA_STATS_ARRAY_TX; j++) {
257 ena_stats = &ena_stats_tx_strings[j];
259 ethtool_sprintf(data,
261 is_xdp ? "xdp_tx" : "tx",
266 /* RX stats, in XDP there isn't a RX queue
269 for (j = 0; j < ENA_STATS_ARRAY_RX; j++) {
270 ena_stats = &ena_stats_rx_strings[j];
272 ethtool_sprintf(data,
280 static void ena_com_dev_strings(u8 **data)
282 const struct ena_stats *ena_stats;
285 for (i = 0; i < ENA_STATS_ARRAY_ENA_COM; i++) {
286 ena_stats = &ena_stats_ena_com_strings[i];
288 ethtool_sprintf(data,
289 "ena_admin_q_%s", ena_stats->name);
293 static void ena_get_strings(struct ena_adapter *adapter,
295 bool eni_stats_needed)
297 const struct ena_stats *ena_stats;
300 for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
301 ena_stats = &ena_stats_global_strings[i];
302 ethtool_sprintf(&data, ena_stats->name);
305 if (eni_stats_needed) {
306 for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
307 ena_stats = &ena_stats_eni_strings[i];
308 ethtool_sprintf(&data, ena_stats->name);
312 ena_queue_strings(adapter, &data);
313 ena_com_dev_strings(&data);
316 static void ena_get_ethtool_strings(struct net_device *netdev,
320 struct ena_adapter *adapter = netdev_priv(netdev);
321 struct ena_com_dev *dev = adapter->ena_dev;
325 ena_get_strings(adapter, data, ena_com_get_cap(dev, ENA_ADMIN_ENI_STATS));
330 static int ena_get_link_ksettings(struct net_device *netdev,
331 struct ethtool_link_ksettings *link_ksettings)
333 struct ena_adapter *adapter = netdev_priv(netdev);
334 struct ena_com_dev *ena_dev = adapter->ena_dev;
335 struct ena_admin_get_feature_link_desc *link;
336 struct ena_admin_get_feat_resp feat_resp;
339 rc = ena_com_get_link_params(ena_dev, &feat_resp);
343 link = &feat_resp.u.link;
344 link_ksettings->base.speed = link->speed;
346 if (link->flags & ENA_ADMIN_GET_FEATURE_LINK_DESC_AUTONEG_MASK) {
347 ethtool_link_ksettings_add_link_mode(link_ksettings,
349 ethtool_link_ksettings_add_link_mode(link_ksettings,
353 link_ksettings->base.autoneg =
354 (link->flags & ENA_ADMIN_GET_FEATURE_LINK_DESC_AUTONEG_MASK) ?
355 AUTONEG_ENABLE : AUTONEG_DISABLE;
357 link_ksettings->base.duplex = DUPLEX_FULL;
362 static int ena_get_coalesce(struct net_device *net_dev,
363 struct ethtool_coalesce *coalesce,
364 struct kernel_ethtool_coalesce *kernel_coal,
365 struct netlink_ext_ack *extack)
367 struct ena_adapter *adapter = netdev_priv(net_dev);
368 struct ena_com_dev *ena_dev = adapter->ena_dev;
370 if (!ena_com_interrupt_moderation_supported(ena_dev))
373 coalesce->tx_coalesce_usecs =
374 ena_com_get_nonadaptive_moderation_interval_tx(ena_dev) *
375 ena_dev->intr_delay_resolution;
377 coalesce->rx_coalesce_usecs =
378 ena_com_get_nonadaptive_moderation_interval_rx(ena_dev)
379 * ena_dev->intr_delay_resolution;
381 coalesce->use_adaptive_rx_coalesce =
382 ena_com_get_adaptive_moderation_enabled(ena_dev);
387 static void ena_update_tx_rings_nonadaptive_intr_moderation(struct ena_adapter *adapter)
392 val = ena_com_get_nonadaptive_moderation_interval_tx(adapter->ena_dev);
394 for (i = 0; i < adapter->num_io_queues; i++)
395 adapter->tx_ring[i].smoothed_interval = val;
398 static void ena_update_rx_rings_nonadaptive_intr_moderation(struct ena_adapter *adapter)
403 val = ena_com_get_nonadaptive_moderation_interval_rx(adapter->ena_dev);
405 for (i = 0; i < adapter->num_io_queues; i++)
406 adapter->rx_ring[i].smoothed_interval = val;
409 static int ena_set_coalesce(struct net_device *net_dev,
410 struct ethtool_coalesce *coalesce,
411 struct kernel_ethtool_coalesce *kernel_coal,
412 struct netlink_ext_ack *extack)
414 struct ena_adapter *adapter = netdev_priv(net_dev);
415 struct ena_com_dev *ena_dev = adapter->ena_dev;
418 if (!ena_com_interrupt_moderation_supported(ena_dev))
421 rc = ena_com_update_nonadaptive_moderation_interval_tx(ena_dev,
422 coalesce->tx_coalesce_usecs);
426 ena_update_tx_rings_nonadaptive_intr_moderation(adapter);
428 rc = ena_com_update_nonadaptive_moderation_interval_rx(ena_dev,
429 coalesce->rx_coalesce_usecs);
433 ena_update_rx_rings_nonadaptive_intr_moderation(adapter);
435 if (coalesce->use_adaptive_rx_coalesce &&
436 !ena_com_get_adaptive_moderation_enabled(ena_dev))
437 ena_com_enable_adaptive_moderation(ena_dev);
439 if (!coalesce->use_adaptive_rx_coalesce &&
440 ena_com_get_adaptive_moderation_enabled(ena_dev))
441 ena_com_disable_adaptive_moderation(ena_dev);
446 static u32 ena_get_msglevel(struct net_device *netdev)
448 struct ena_adapter *adapter = netdev_priv(netdev);
450 return adapter->msg_enable;
453 static void ena_set_msglevel(struct net_device *netdev, u32 value)
455 struct ena_adapter *adapter = netdev_priv(netdev);
457 adapter->msg_enable = value;
460 static void ena_get_drvinfo(struct net_device *dev,
461 struct ethtool_drvinfo *info)
463 struct ena_adapter *adapter = netdev_priv(dev);
465 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
466 strlcpy(info->bus_info, pci_name(adapter->pdev),
467 sizeof(info->bus_info));
470 static void ena_get_ringparam(struct net_device *netdev,
471 struct ethtool_ringparam *ring,
472 struct kernel_ethtool_ringparam *kernel_ring,
473 struct netlink_ext_ack *extack)
475 struct ena_adapter *adapter = netdev_priv(netdev);
477 ring->tx_max_pending = adapter->max_tx_ring_size;
478 ring->rx_max_pending = adapter->max_rx_ring_size;
479 ring->tx_pending = adapter->tx_ring[0].ring_size;
480 ring->rx_pending = adapter->rx_ring[0].ring_size;
483 static int ena_set_ringparam(struct net_device *netdev,
484 struct ethtool_ringparam *ring,
485 struct kernel_ethtool_ringparam *kernel_ring,
486 struct netlink_ext_ack *extack)
488 struct ena_adapter *adapter = netdev_priv(netdev);
489 u32 new_tx_size, new_rx_size;
491 new_tx_size = ring->tx_pending < ENA_MIN_RING_SIZE ?
492 ENA_MIN_RING_SIZE : ring->tx_pending;
493 new_tx_size = rounddown_pow_of_two(new_tx_size);
495 new_rx_size = ring->rx_pending < ENA_MIN_RING_SIZE ?
496 ENA_MIN_RING_SIZE : ring->rx_pending;
497 new_rx_size = rounddown_pow_of_two(new_rx_size);
499 if (new_tx_size == adapter->requested_tx_ring_size &&
500 new_rx_size == adapter->requested_rx_ring_size)
503 return ena_update_queue_sizes(adapter, new_tx_size, new_rx_size);
506 static u32 ena_flow_hash_to_flow_type(u16 hash_fields)
510 if (hash_fields & ENA_ADMIN_RSS_L2_DA)
513 if (hash_fields & ENA_ADMIN_RSS_L3_DA)
516 if (hash_fields & ENA_ADMIN_RSS_L3_SA)
519 if (hash_fields & ENA_ADMIN_RSS_L4_DP)
520 data |= RXH_L4_B_2_3;
522 if (hash_fields & ENA_ADMIN_RSS_L4_SP)
523 data |= RXH_L4_B_0_1;
528 static u16 ena_flow_data_to_flow_hash(u32 hash_fields)
532 if (hash_fields & RXH_L2DA)
533 data |= ENA_ADMIN_RSS_L2_DA;
535 if (hash_fields & RXH_IP_DST)
536 data |= ENA_ADMIN_RSS_L3_DA;
538 if (hash_fields & RXH_IP_SRC)
539 data |= ENA_ADMIN_RSS_L3_SA;
541 if (hash_fields & RXH_L4_B_2_3)
542 data |= ENA_ADMIN_RSS_L4_DP;
544 if (hash_fields & RXH_L4_B_0_1)
545 data |= ENA_ADMIN_RSS_L4_SP;
550 static int ena_get_rss_hash(struct ena_com_dev *ena_dev,
551 struct ethtool_rxnfc *cmd)
553 enum ena_admin_flow_hash_proto proto;
559 switch (cmd->flow_type) {
561 proto = ENA_ADMIN_RSS_TCP4;
564 proto = ENA_ADMIN_RSS_UDP4;
567 proto = ENA_ADMIN_RSS_TCP6;
570 proto = ENA_ADMIN_RSS_UDP6;
573 proto = ENA_ADMIN_RSS_IP4;
576 proto = ENA_ADMIN_RSS_IP6;
579 proto = ENA_ADMIN_RSS_NOT_IP;
592 rc = ena_com_get_hash_ctrl(ena_dev, proto, &hash_fields);
596 cmd->data = ena_flow_hash_to_flow_type(hash_fields);
601 static int ena_set_rss_hash(struct ena_com_dev *ena_dev,
602 struct ethtool_rxnfc *cmd)
604 enum ena_admin_flow_hash_proto proto;
607 switch (cmd->flow_type) {
609 proto = ENA_ADMIN_RSS_TCP4;
612 proto = ENA_ADMIN_RSS_UDP4;
615 proto = ENA_ADMIN_RSS_TCP6;
618 proto = ENA_ADMIN_RSS_UDP6;
621 proto = ENA_ADMIN_RSS_IP4;
624 proto = ENA_ADMIN_RSS_IP6;
627 proto = ENA_ADMIN_RSS_NOT_IP;
640 hash_fields = ena_flow_data_to_flow_hash(cmd->data);
642 return ena_com_fill_hash_ctrl(ena_dev, proto, hash_fields);
645 static int ena_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info)
647 struct ena_adapter *adapter = netdev_priv(netdev);
652 rc = ena_set_rss_hash(adapter->ena_dev, info);
654 case ETHTOOL_SRXCLSRLDEL:
655 case ETHTOOL_SRXCLSRLINS:
657 netif_err(adapter, drv, netdev,
658 "Command parameter %d is not supported\n", info->cmd);
665 static int ena_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
668 struct ena_adapter *adapter = netdev_priv(netdev);
672 case ETHTOOL_GRXRINGS:
673 info->data = adapter->num_io_queues;
677 rc = ena_get_rss_hash(adapter->ena_dev, info);
679 case ETHTOOL_GRXCLSRLCNT:
680 case ETHTOOL_GRXCLSRULE:
681 case ETHTOOL_GRXCLSRLALL:
683 netif_err(adapter, drv, netdev,
684 "Command parameter %d is not supported\n", info->cmd);
691 static u32 ena_get_rxfh_indir_size(struct net_device *netdev)
693 return ENA_RX_RSS_TABLE_SIZE;
696 static u32 ena_get_rxfh_key_size(struct net_device *netdev)
698 return ENA_HASH_KEY_SIZE;
701 static int ena_indirection_table_set(struct ena_adapter *adapter,
704 struct ena_com_dev *ena_dev = adapter->ena_dev;
707 for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
708 rc = ena_com_indirect_table_fill_entry(ena_dev,
710 ENA_IO_RXQ_IDX(indir[i]));
712 netif_err(adapter, drv, adapter->netdev,
713 "Cannot fill indirect table (index is too large)\n");
718 rc = ena_com_indirect_table_set(ena_dev);
720 netif_err(adapter, drv, adapter->netdev,
721 "Cannot set indirect table\n");
722 return rc == -EPERM ? -EOPNOTSUPP : rc;
727 static int ena_indirection_table_get(struct ena_adapter *adapter, u32 *indir)
729 struct ena_com_dev *ena_dev = adapter->ena_dev;
735 rc = ena_com_indirect_table_get(ena_dev, indir);
739 /* Our internal representation of the indices is: even indices
740 * for Tx and uneven indices for Rx. We need to convert the Rx
741 * indices to be consecutive
743 for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++)
744 indir[i] = ENA_IO_RXQ_IDX_TO_COMBINED_IDX(indir[i]);
749 static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
752 struct ena_adapter *adapter = netdev_priv(netdev);
753 enum ena_admin_hash_functions ena_func;
757 rc = ena_indirection_table_get(adapter, indir);
761 /* We call this function in order to check if the device
762 * supports getting/setting the hash function.
764 rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func);
766 if (rc == -EOPNOTSUPP)
772 rc = ena_com_get_hash_key(adapter->ena_dev, key);
777 case ENA_ADMIN_TOEPLITZ:
778 func = ETH_RSS_HASH_TOP;
780 case ENA_ADMIN_CRC32:
781 func = ETH_RSS_HASH_CRC32;
784 netif_err(adapter, drv, netdev,
785 "Command parameter is not supported\n");
795 static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
796 const u8 *key, const u8 hfunc)
798 struct ena_adapter *adapter = netdev_priv(netdev);
799 struct ena_com_dev *ena_dev = adapter->ena_dev;
800 enum ena_admin_hash_functions func = 0;
804 rc = ena_indirection_table_set(adapter, indir);
810 case ETH_RSS_HASH_NO_CHANGE:
811 func = ena_com_get_current_hash_function(ena_dev);
813 case ETH_RSS_HASH_TOP:
814 func = ENA_ADMIN_TOEPLITZ;
816 case ETH_RSS_HASH_CRC32:
817 func = ENA_ADMIN_CRC32;
820 netif_err(adapter, drv, netdev, "Unsupported hfunc %d\n",
826 rc = ena_com_fill_hash_function(ena_dev, func, key,
830 netif_err(adapter, drv, netdev, "Cannot fill key\n");
831 return rc == -EPERM ? -EOPNOTSUPP : rc;
838 static void ena_get_channels(struct net_device *netdev,
839 struct ethtool_channels *channels)
841 struct ena_adapter *adapter = netdev_priv(netdev);
843 channels->max_combined = adapter->max_num_io_queues;
844 channels->combined_count = adapter->num_io_queues;
847 static int ena_set_channels(struct net_device *netdev,
848 struct ethtool_channels *channels)
850 struct ena_adapter *adapter = netdev_priv(netdev);
851 u32 count = channels->combined_count;
852 /* The check for max value is already done in ethtool */
853 if (count < ENA_MIN_NUM_IO_QUEUES ||
854 (ena_xdp_present(adapter) &&
855 !ena_xdp_legal_queue_count(adapter, count)))
858 return ena_update_queue_count(adapter, count);
861 static int ena_get_tunable(struct net_device *netdev,
862 const struct ethtool_tunable *tuna, void *data)
864 struct ena_adapter *adapter = netdev_priv(netdev);
868 case ETHTOOL_RX_COPYBREAK:
869 *(u32 *)data = adapter->rx_copybreak;
879 static int ena_set_tunable(struct net_device *netdev,
880 const struct ethtool_tunable *tuna,
883 struct ena_adapter *adapter = netdev_priv(netdev);
888 case ETHTOOL_RX_COPYBREAK:
890 if (len > adapter->netdev->mtu) {
894 adapter->rx_copybreak = len;
904 static const struct ethtool_ops ena_ethtool_ops = {
905 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
906 ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
907 .get_link_ksettings = ena_get_link_ksettings,
908 .get_drvinfo = ena_get_drvinfo,
909 .get_msglevel = ena_get_msglevel,
910 .set_msglevel = ena_set_msglevel,
911 .get_link = ethtool_op_get_link,
912 .get_coalesce = ena_get_coalesce,
913 .set_coalesce = ena_set_coalesce,
914 .get_ringparam = ena_get_ringparam,
915 .set_ringparam = ena_set_ringparam,
916 .get_sset_count = ena_get_sset_count,
917 .get_strings = ena_get_ethtool_strings,
918 .get_ethtool_stats = ena_get_ethtool_stats,
919 .get_rxnfc = ena_get_rxnfc,
920 .set_rxnfc = ena_set_rxnfc,
921 .get_rxfh_indir_size = ena_get_rxfh_indir_size,
922 .get_rxfh_key_size = ena_get_rxfh_key_size,
923 .get_rxfh = ena_get_rxfh,
924 .set_rxfh = ena_set_rxfh,
925 .get_channels = ena_get_channels,
926 .set_channels = ena_set_channels,
927 .get_tunable = ena_get_tunable,
928 .set_tunable = ena_set_tunable,
929 .get_ts_info = ethtool_op_get_ts_info,
932 void ena_set_ethtool_ops(struct net_device *netdev)
934 netdev->ethtool_ops = &ena_ethtool_ops;
937 static void ena_dump_stats_ex(struct ena_adapter *adapter, u8 *buf)
939 struct net_device *netdev = adapter->netdev;
945 strings_num = ena_get_sw_stats_count(adapter);
946 if (strings_num <= 0) {
947 netif_err(adapter, drv, netdev, "Can't get stats num\n");
951 strings_buf = devm_kcalloc(&adapter->pdev->dev,
952 ETH_GSTRING_LEN, strings_num,
955 netif_err(adapter, drv, netdev,
956 "Failed to allocate strings_buf\n");
960 data_buf = devm_kcalloc(&adapter->pdev->dev,
961 strings_num, sizeof(u64),
964 netif_err(adapter, drv, netdev,
965 "Failed to allocate data buf\n");
966 devm_kfree(&adapter->pdev->dev, strings_buf);
970 ena_get_strings(adapter, strings_buf, false);
971 ena_get_stats(adapter, data_buf, false);
973 /* If there is a buffer, dump stats, otherwise print them to dmesg */
975 for (i = 0; i < strings_num; i++) {
976 rc = snprintf(buf, ETH_GSTRING_LEN + sizeof(u64),
978 strings_buf + i * ETH_GSTRING_LEN,
983 for (i = 0; i < strings_num; i++)
984 netif_err(adapter, drv, netdev, "%s: %llu\n",
985 strings_buf + i * ETH_GSTRING_LEN,
988 devm_kfree(&adapter->pdev->dev, strings_buf);
989 devm_kfree(&adapter->pdev->dev, data_buf);
992 void ena_dump_stats_to_buf(struct ena_adapter *adapter, u8 *buf)
997 ena_dump_stats_ex(adapter, buf);
1000 void ena_dump_stats_to_dmesg(struct ena_adapter *adapter)
1002 ena_dump_stats_ex(adapter, NULL);