2 * Copyright 2015 Amazon.com, Inc. or its affiliates.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/pci.h>
35 #include "ena_netdev.h"
38 char name
[ETH_GSTRING_LEN
];
42 #define ENA_STAT_ENA_COM_ENTRY(stat) { \
44 .stat_offset = offsetof(struct ena_com_stats_admin, stat) \
47 #define ENA_STAT_ENTRY(stat, stat_type) { \
49 .stat_offset = offsetof(struct ena_stats_##stat_type, stat) \
52 #define ENA_STAT_RX_ENTRY(stat) \
53 ENA_STAT_ENTRY(stat, rx)
55 #define ENA_STAT_TX_ENTRY(stat) \
56 ENA_STAT_ENTRY(stat, tx)
58 #define ENA_STAT_GLOBAL_ENTRY(stat) \
59 ENA_STAT_ENTRY(stat, dev)
61 static const struct ena_stats ena_stats_global_strings
[] = {
62 ENA_STAT_GLOBAL_ENTRY(tx_timeout
),
63 ENA_STAT_GLOBAL_ENTRY(io_suspend
),
64 ENA_STAT_GLOBAL_ENTRY(io_resume
),
65 ENA_STAT_GLOBAL_ENTRY(wd_expired
),
66 ENA_STAT_GLOBAL_ENTRY(interface_up
),
67 ENA_STAT_GLOBAL_ENTRY(interface_down
),
68 ENA_STAT_GLOBAL_ENTRY(admin_q_pause
),
71 static const struct ena_stats ena_stats_tx_strings
[] = {
72 ENA_STAT_TX_ENTRY(cnt
),
73 ENA_STAT_TX_ENTRY(bytes
),
74 ENA_STAT_TX_ENTRY(queue_stop
),
75 ENA_STAT_TX_ENTRY(queue_wakeup
),
76 ENA_STAT_TX_ENTRY(dma_mapping_err
),
77 ENA_STAT_TX_ENTRY(linearize
),
78 ENA_STAT_TX_ENTRY(linearize_failed
),
79 ENA_STAT_TX_ENTRY(napi_comp
),
80 ENA_STAT_TX_ENTRY(tx_poll
),
81 ENA_STAT_TX_ENTRY(doorbells
),
82 ENA_STAT_TX_ENTRY(prepare_ctx_err
),
83 ENA_STAT_TX_ENTRY(bad_req_id
),
86 static const struct ena_stats ena_stats_rx_strings
[] = {
87 ENA_STAT_RX_ENTRY(cnt
),
88 ENA_STAT_RX_ENTRY(bytes
),
89 ENA_STAT_RX_ENTRY(refil_partial
),
90 ENA_STAT_RX_ENTRY(bad_csum
),
91 ENA_STAT_RX_ENTRY(page_alloc_fail
),
92 ENA_STAT_RX_ENTRY(skb_alloc_fail
),
93 ENA_STAT_RX_ENTRY(dma_mapping_err
),
94 ENA_STAT_RX_ENTRY(bad_desc_num
),
95 ENA_STAT_RX_ENTRY(rx_copybreak_pkt
),
96 ENA_STAT_RX_ENTRY(empty_rx_ring
),
99 static const struct ena_stats ena_stats_ena_com_strings
[] = {
100 ENA_STAT_ENA_COM_ENTRY(aborted_cmd
),
101 ENA_STAT_ENA_COM_ENTRY(submitted_cmd
),
102 ENA_STAT_ENA_COM_ENTRY(completed_cmd
),
103 ENA_STAT_ENA_COM_ENTRY(out_of_space
),
104 ENA_STAT_ENA_COM_ENTRY(no_completion
),
107 #define ENA_STATS_ARRAY_GLOBAL ARRAY_SIZE(ena_stats_global_strings)
108 #define ENA_STATS_ARRAY_TX ARRAY_SIZE(ena_stats_tx_strings)
109 #define ENA_STATS_ARRAY_RX ARRAY_SIZE(ena_stats_rx_strings)
110 #define ENA_STATS_ARRAY_ENA_COM ARRAY_SIZE(ena_stats_ena_com_strings)
112 static void ena_safe_update_stat(u64
*src
, u64
*dst
,
113 struct u64_stats_sync
*syncp
)
118 start
= u64_stats_fetch_begin_irq(syncp
);
120 } while (u64_stats_fetch_retry_irq(syncp
, start
));
123 static void ena_queue_stats(struct ena_adapter
*adapter
, u64
**data
)
125 const struct ena_stats
*ena_stats
;
126 struct ena_ring
*ring
;
131 for (i
= 0; i
< adapter
->num_queues
; i
++) {
133 ring
= &adapter
->tx_ring
[i
];
135 for (j
= 0; j
< ENA_STATS_ARRAY_TX
; j
++) {
136 ena_stats
= &ena_stats_tx_strings
[j
];
138 ptr
= (u64
*)((uintptr_t)&ring
->tx_stats
+
139 (uintptr_t)ena_stats
->stat_offset
);
141 ena_safe_update_stat(ptr
, (*data
)++, &ring
->syncp
);
145 ring
= &adapter
->rx_ring
[i
];
147 for (j
= 0; j
< ENA_STATS_ARRAY_RX
; j
++) {
148 ena_stats
= &ena_stats_rx_strings
[j
];
150 ptr
= (u64
*)((uintptr_t)&ring
->rx_stats
+
151 (uintptr_t)ena_stats
->stat_offset
);
153 ena_safe_update_stat(ptr
, (*data
)++, &ring
->syncp
);
158 static void ena_dev_admin_queue_stats(struct ena_adapter
*adapter
, u64
**data
)
160 const struct ena_stats
*ena_stats
;
164 for (i
= 0; i
< ENA_STATS_ARRAY_ENA_COM
; i
++) {
165 ena_stats
= &ena_stats_ena_com_strings
[i
];
167 ptr
= (u32
*)((uintptr_t)&adapter
->ena_dev
->admin_queue
.stats
+
168 (uintptr_t)ena_stats
->stat_offset
);
174 static void ena_get_ethtool_stats(struct net_device
*netdev
,
175 struct ethtool_stats
*stats
,
178 struct ena_adapter
*adapter
= netdev_priv(netdev
);
179 const struct ena_stats
*ena_stats
;
183 for (i
= 0; i
< ENA_STATS_ARRAY_GLOBAL
; i
++) {
184 ena_stats
= &ena_stats_global_strings
[i
];
186 ptr
= (u64
*)((uintptr_t)&adapter
->dev_stats
+
187 (uintptr_t)ena_stats
->stat_offset
);
189 ena_safe_update_stat(ptr
, data
++, &adapter
->syncp
);
192 ena_queue_stats(adapter
, &data
);
193 ena_dev_admin_queue_stats(adapter
, &data
);
196 int ena_get_sset_count(struct net_device
*netdev
, int sset
)
198 struct ena_adapter
*adapter
= netdev_priv(netdev
);
200 if (sset
!= ETH_SS_STATS
)
203 return adapter
->num_queues
* (ENA_STATS_ARRAY_TX
+ ENA_STATS_ARRAY_RX
)
204 + ENA_STATS_ARRAY_GLOBAL
+ ENA_STATS_ARRAY_ENA_COM
;
207 static void ena_queue_strings(struct ena_adapter
*adapter
, u8
**data
)
209 const struct ena_stats
*ena_stats
;
212 for (i
= 0; i
< adapter
->num_queues
; i
++) {
214 for (j
= 0; j
< ENA_STATS_ARRAY_TX
; j
++) {
215 ena_stats
= &ena_stats_tx_strings
[j
];
217 snprintf(*data
, ETH_GSTRING_LEN
,
218 "queue_%u_tx_%s", i
, ena_stats
->name
);
219 (*data
) += ETH_GSTRING_LEN
;
222 for (j
= 0; j
< ENA_STATS_ARRAY_RX
; j
++) {
223 ena_stats
= &ena_stats_rx_strings
[j
];
225 snprintf(*data
, ETH_GSTRING_LEN
,
226 "queue_%u_rx_%s", i
, ena_stats
->name
);
227 (*data
) += ETH_GSTRING_LEN
;
232 static void ena_com_dev_strings(u8
**data
)
234 const struct ena_stats
*ena_stats
;
237 for (i
= 0; i
< ENA_STATS_ARRAY_ENA_COM
; i
++) {
238 ena_stats
= &ena_stats_ena_com_strings
[i
];
240 snprintf(*data
, ETH_GSTRING_LEN
,
241 "ena_admin_q_%s", ena_stats
->name
);
242 (*data
) += ETH_GSTRING_LEN
;
246 static void ena_get_strings(struct net_device
*netdev
, u32 sset
, u8
*data
)
248 struct ena_adapter
*adapter
= netdev_priv(netdev
);
249 const struct ena_stats
*ena_stats
;
252 if (sset
!= ETH_SS_STATS
)
255 for (i
= 0; i
< ENA_STATS_ARRAY_GLOBAL
; i
++) {
256 ena_stats
= &ena_stats_global_strings
[i
];
258 memcpy(data
, ena_stats
->name
, ETH_GSTRING_LEN
);
259 data
+= ETH_GSTRING_LEN
;
262 ena_queue_strings(adapter
, &data
);
263 ena_com_dev_strings(&data
);
266 static int ena_get_link_ksettings(struct net_device
*netdev
,
267 struct ethtool_link_ksettings
*link_ksettings
)
269 struct ena_adapter
*adapter
= netdev_priv(netdev
);
270 struct ena_com_dev
*ena_dev
= adapter
->ena_dev
;
271 struct ena_admin_get_feature_link_desc
*link
;
272 struct ena_admin_get_feat_resp feat_resp
;
275 rc
= ena_com_get_link_params(ena_dev
, &feat_resp
);
279 link
= &feat_resp
.u
.link
;
280 link_ksettings
->base
.speed
= link
->speed
;
282 if (link
->flags
& ENA_ADMIN_GET_FEATURE_LINK_DESC_AUTONEG_MASK
) {
283 ethtool_link_ksettings_add_link_mode(link_ksettings
,
285 ethtool_link_ksettings_add_link_mode(link_ksettings
,
289 link_ksettings
->base
.autoneg
=
290 (link
->flags
& ENA_ADMIN_GET_FEATURE_LINK_DESC_AUTONEG_MASK
) ?
291 AUTONEG_ENABLE
: AUTONEG_DISABLE
;
293 link_ksettings
->base
.duplex
= DUPLEX_FULL
;
298 static int ena_get_coalesce(struct net_device
*net_dev
,
299 struct ethtool_coalesce
*coalesce
)
301 struct ena_adapter
*adapter
= netdev_priv(net_dev
);
302 struct ena_com_dev
*ena_dev
= adapter
->ena_dev
;
303 struct ena_intr_moder_entry intr_moder_entry
;
305 if (!ena_com_interrupt_moderation_supported(ena_dev
)) {
306 /* the devie doesn't support interrupt moderation */
309 coalesce
->tx_coalesce_usecs
=
310 ena_com_get_nonadaptive_moderation_interval_tx(ena_dev
) /
311 ena_dev
->intr_delay_resolution
;
312 if (!ena_com_get_adaptive_moderation_enabled(ena_dev
)) {
313 coalesce
->rx_coalesce_usecs
=
314 ena_com_get_nonadaptive_moderation_interval_rx(ena_dev
)
315 / ena_dev
->intr_delay_resolution
;
317 ena_com_get_intr_moderation_entry(adapter
->ena_dev
, ENA_INTR_MODER_LOWEST
, &intr_moder_entry
);
318 coalesce
->rx_coalesce_usecs_low
= intr_moder_entry
.intr_moder_interval
;
319 coalesce
->rx_max_coalesced_frames_low
= intr_moder_entry
.pkts_per_interval
;
321 ena_com_get_intr_moderation_entry(adapter
->ena_dev
, ENA_INTR_MODER_MID
, &intr_moder_entry
);
322 coalesce
->rx_coalesce_usecs
= intr_moder_entry
.intr_moder_interval
;
323 coalesce
->rx_max_coalesced_frames
= intr_moder_entry
.pkts_per_interval
;
325 ena_com_get_intr_moderation_entry(adapter
->ena_dev
, ENA_INTR_MODER_HIGHEST
, &intr_moder_entry
);
326 coalesce
->rx_coalesce_usecs_high
= intr_moder_entry
.intr_moder_interval
;
327 coalesce
->rx_max_coalesced_frames_high
= intr_moder_entry
.pkts_per_interval
;
329 coalesce
->use_adaptive_rx_coalesce
=
330 ena_com_get_adaptive_moderation_enabled(ena_dev
);
335 static void ena_update_tx_rings_intr_moderation(struct ena_adapter
*adapter
)
340 val
= ena_com_get_nonadaptive_moderation_interval_tx(adapter
->ena_dev
);
342 for (i
= 0; i
< adapter
->num_queues
; i
++)
343 adapter
->tx_ring
[i
].smoothed_interval
= val
;
346 static int ena_set_coalesce(struct net_device
*net_dev
,
347 struct ethtool_coalesce
*coalesce
)
349 struct ena_adapter
*adapter
= netdev_priv(net_dev
);
350 struct ena_com_dev
*ena_dev
= adapter
->ena_dev
;
351 struct ena_intr_moder_entry intr_moder_entry
;
354 if (!ena_com_interrupt_moderation_supported(ena_dev
)) {
355 /* the devie doesn't support interrupt moderation */
359 if (coalesce
->rx_coalesce_usecs_irq
||
360 coalesce
->rx_max_coalesced_frames_irq
||
361 coalesce
->tx_coalesce_usecs_irq
||
362 coalesce
->tx_max_coalesced_frames
||
363 coalesce
->tx_max_coalesced_frames_irq
||
364 coalesce
->stats_block_coalesce_usecs
||
365 coalesce
->use_adaptive_tx_coalesce
||
366 coalesce
->pkt_rate_low
||
367 coalesce
->tx_coalesce_usecs_low
||
368 coalesce
->tx_max_coalesced_frames_low
||
369 coalesce
->pkt_rate_high
||
370 coalesce
->tx_coalesce_usecs_high
||
371 coalesce
->tx_max_coalesced_frames_high
||
372 coalesce
->rate_sample_interval
)
375 rc
= ena_com_update_nonadaptive_moderation_interval_tx(ena_dev
,
376 coalesce
->tx_coalesce_usecs
);
380 ena_update_tx_rings_intr_moderation(adapter
);
382 if (ena_com_get_adaptive_moderation_enabled(ena_dev
)) {
383 if (!coalesce
->use_adaptive_rx_coalesce
) {
384 ena_com_disable_adaptive_moderation(ena_dev
);
385 rc
= ena_com_update_nonadaptive_moderation_interval_rx(ena_dev
,
386 coalesce
->rx_coalesce_usecs
);
389 } else { /* was in non-adaptive mode */
390 if (coalesce
->use_adaptive_rx_coalesce
) {
391 ena_com_enable_adaptive_moderation(ena_dev
);
393 rc
= ena_com_update_nonadaptive_moderation_interval_rx(ena_dev
,
394 coalesce
->rx_coalesce_usecs
);
399 intr_moder_entry
.intr_moder_interval
= coalesce
->rx_coalesce_usecs_low
;
400 intr_moder_entry
.pkts_per_interval
= coalesce
->rx_max_coalesced_frames_low
;
401 intr_moder_entry
.bytes_per_interval
= ENA_INTR_BYTE_COUNT_NOT_SUPPORTED
;
402 ena_com_init_intr_moderation_entry(adapter
->ena_dev
, ENA_INTR_MODER_LOWEST
, &intr_moder_entry
);
404 intr_moder_entry
.intr_moder_interval
= coalesce
->rx_coalesce_usecs
;
405 intr_moder_entry
.pkts_per_interval
= coalesce
->rx_max_coalesced_frames
;
406 intr_moder_entry
.bytes_per_interval
= ENA_INTR_BYTE_COUNT_NOT_SUPPORTED
;
407 ena_com_init_intr_moderation_entry(adapter
->ena_dev
, ENA_INTR_MODER_MID
, &intr_moder_entry
);
409 intr_moder_entry
.intr_moder_interval
= coalesce
->rx_coalesce_usecs_high
;
410 intr_moder_entry
.pkts_per_interval
= coalesce
->rx_max_coalesced_frames_high
;
411 intr_moder_entry
.bytes_per_interval
= ENA_INTR_BYTE_COUNT_NOT_SUPPORTED
;
412 ena_com_init_intr_moderation_entry(adapter
->ena_dev
, ENA_INTR_MODER_HIGHEST
, &intr_moder_entry
);
417 static u32
ena_get_msglevel(struct net_device
*netdev
)
419 struct ena_adapter
*adapter
= netdev_priv(netdev
);
421 return adapter
->msg_enable
;
424 static void ena_set_msglevel(struct net_device
*netdev
, u32 value
)
426 struct ena_adapter
*adapter
= netdev_priv(netdev
);
428 adapter
->msg_enable
= value
;
431 static void ena_get_drvinfo(struct net_device
*dev
,
432 struct ethtool_drvinfo
*info
)
434 struct ena_adapter
*adapter
= netdev_priv(dev
);
436 strlcpy(info
->driver
, DRV_MODULE_NAME
, sizeof(info
->driver
));
437 strlcpy(info
->version
, DRV_MODULE_VERSION
, sizeof(info
->version
));
438 strlcpy(info
->bus_info
, pci_name(adapter
->pdev
),
439 sizeof(info
->bus_info
));
442 static void ena_get_ringparam(struct net_device
*netdev
,
443 struct ethtool_ringparam
*ring
)
445 struct ena_adapter
*adapter
= netdev_priv(netdev
);
446 struct ena_ring
*tx_ring
= &adapter
->tx_ring
[0];
447 struct ena_ring
*rx_ring
= &adapter
->rx_ring
[0];
449 ring
->rx_max_pending
= rx_ring
->ring_size
;
450 ring
->tx_max_pending
= tx_ring
->ring_size
;
451 ring
->rx_pending
= rx_ring
->ring_size
;
452 ring
->tx_pending
= tx_ring
->ring_size
;
455 static u32
ena_flow_hash_to_flow_type(u16 hash_fields
)
459 if (hash_fields
& ENA_ADMIN_RSS_L2_DA
)
462 if (hash_fields
& ENA_ADMIN_RSS_L3_DA
)
465 if (hash_fields
& ENA_ADMIN_RSS_L3_SA
)
468 if (hash_fields
& ENA_ADMIN_RSS_L4_DP
)
469 data
|= RXH_L4_B_2_3
;
471 if (hash_fields
& ENA_ADMIN_RSS_L4_SP
)
472 data
|= RXH_L4_B_0_1
;
477 static u16
ena_flow_data_to_flow_hash(u32 hash_fields
)
481 if (hash_fields
& RXH_L2DA
)
482 data
|= ENA_ADMIN_RSS_L2_DA
;
484 if (hash_fields
& RXH_IP_DST
)
485 data
|= ENA_ADMIN_RSS_L3_DA
;
487 if (hash_fields
& RXH_IP_SRC
)
488 data
|= ENA_ADMIN_RSS_L3_SA
;
490 if (hash_fields
& RXH_L4_B_2_3
)
491 data
|= ENA_ADMIN_RSS_L4_DP
;
493 if (hash_fields
& RXH_L4_B_0_1
)
494 data
|= ENA_ADMIN_RSS_L4_SP
;
499 static int ena_get_rss_hash(struct ena_com_dev
*ena_dev
,
500 struct ethtool_rxnfc
*cmd
)
502 enum ena_admin_flow_hash_proto proto
;
508 switch (cmd
->flow_type
) {
510 proto
= ENA_ADMIN_RSS_TCP4
;
513 proto
= ENA_ADMIN_RSS_UDP4
;
516 proto
= ENA_ADMIN_RSS_TCP6
;
519 proto
= ENA_ADMIN_RSS_UDP6
;
522 proto
= ENA_ADMIN_RSS_IP4
;
525 proto
= ENA_ADMIN_RSS_IP6
;
528 proto
= ENA_ADMIN_RSS_NOT_IP
;
541 rc
= ena_com_get_hash_ctrl(ena_dev
, proto
, &hash_fields
);
545 cmd
->data
= ena_flow_hash_to_flow_type(hash_fields
);
550 static int ena_set_rss_hash(struct ena_com_dev
*ena_dev
,
551 struct ethtool_rxnfc
*cmd
)
553 enum ena_admin_flow_hash_proto proto
;
556 switch (cmd
->flow_type
) {
558 proto
= ENA_ADMIN_RSS_TCP4
;
561 proto
= ENA_ADMIN_RSS_UDP4
;
564 proto
= ENA_ADMIN_RSS_TCP6
;
567 proto
= ENA_ADMIN_RSS_UDP6
;
570 proto
= ENA_ADMIN_RSS_IP4
;
573 proto
= ENA_ADMIN_RSS_IP6
;
576 proto
= ENA_ADMIN_RSS_NOT_IP
;
589 hash_fields
= ena_flow_data_to_flow_hash(cmd
->data
);
591 return ena_com_fill_hash_ctrl(ena_dev
, proto
, hash_fields
);
594 static int ena_set_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*info
)
596 struct ena_adapter
*adapter
= netdev_priv(netdev
);
601 rc
= ena_set_rss_hash(adapter
->ena_dev
, info
);
603 case ETHTOOL_SRXCLSRLDEL
:
604 case ETHTOOL_SRXCLSRLINS
:
606 netif_err(adapter
, drv
, netdev
,
607 "Command parameter %d is not supported\n", info
->cmd
);
614 static int ena_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*info
,
617 struct ena_adapter
*adapter
= netdev_priv(netdev
);
621 case ETHTOOL_GRXRINGS
:
622 info
->data
= adapter
->num_queues
;
626 rc
= ena_get_rss_hash(adapter
->ena_dev
, info
);
628 case ETHTOOL_GRXCLSRLCNT
:
629 case ETHTOOL_GRXCLSRULE
:
630 case ETHTOOL_GRXCLSRLALL
:
632 netif_err(adapter
, drv
, netdev
,
633 "Command parameter %d is not supported\n", info
->cmd
);
640 static u32
ena_get_rxfh_indir_size(struct net_device
*netdev
)
642 return ENA_RX_RSS_TABLE_SIZE
;
645 static u32
ena_get_rxfh_key_size(struct net_device
*netdev
)
647 return ENA_HASH_KEY_SIZE
;
650 static int ena_get_rxfh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
653 struct ena_adapter
*adapter
= netdev_priv(netdev
);
654 enum ena_admin_hash_functions ena_func
;
658 rc
= ena_com_indirect_table_get(adapter
->ena_dev
, indir
);
662 rc
= ena_com_get_hash_function(adapter
->ena_dev
, &ena_func
, key
);
667 case ENA_ADMIN_TOEPLITZ
:
668 func
= ETH_RSS_HASH_TOP
;
670 case ENA_ADMIN_CRC32
:
671 func
= ETH_RSS_HASH_XOR
;
674 netif_err(adapter
, drv
, netdev
,
675 "Command parameter is not supported\n");
685 static int ena_set_rxfh(struct net_device
*netdev
, const u32
*indir
,
686 const u8
*key
, const u8 hfunc
)
688 struct ena_adapter
*adapter
= netdev_priv(netdev
);
689 struct ena_com_dev
*ena_dev
= adapter
->ena_dev
;
690 enum ena_admin_hash_functions func
;
694 for (i
= 0; i
< ENA_RX_RSS_TABLE_SIZE
; i
++) {
695 rc
= ena_com_indirect_table_fill_entry(ena_dev
,
696 ENA_IO_RXQ_IDX(indir
[i
]),
699 netif_err(adapter
, drv
, netdev
,
700 "Cannot fill indirect table (index is too large)\n");
705 rc
= ena_com_indirect_table_set(ena_dev
);
707 netif_err(adapter
, drv
, netdev
,
708 "Cannot set indirect table\n");
709 return rc
== -EPERM
? -EOPNOTSUPP
: rc
;
714 case ETH_RSS_HASH_TOP
:
715 func
= ENA_ADMIN_TOEPLITZ
;
717 case ETH_RSS_HASH_XOR
:
718 func
= ENA_ADMIN_CRC32
;
721 netif_err(adapter
, drv
, netdev
, "Unsupported hfunc %d\n",
727 rc
= ena_com_fill_hash_function(ena_dev
, func
, key
,
731 netif_err(adapter
, drv
, netdev
, "Cannot fill key\n");
732 return rc
== -EPERM
? -EOPNOTSUPP
: rc
;
739 static void ena_get_channels(struct net_device
*netdev
,
740 struct ethtool_channels
*channels
)
742 struct ena_adapter
*adapter
= netdev_priv(netdev
);
744 channels
->max_rx
= ENA_MAX_NUM_IO_QUEUES
;
745 channels
->max_tx
= ENA_MAX_NUM_IO_QUEUES
;
746 channels
->max_other
= 0;
747 channels
->max_combined
= 0;
748 channels
->rx_count
= adapter
->num_queues
;
749 channels
->tx_count
= adapter
->num_queues
;
750 channels
->other_count
= 0;
751 channels
->combined_count
= 0;
754 static int ena_get_tunable(struct net_device
*netdev
,
755 const struct ethtool_tunable
*tuna
, void *data
)
757 struct ena_adapter
*adapter
= netdev_priv(netdev
);
761 case ETHTOOL_RX_COPYBREAK
:
762 *(u32
*)data
= adapter
->rx_copybreak
;
772 static int ena_set_tunable(struct net_device
*netdev
,
773 const struct ethtool_tunable
*tuna
,
776 struct ena_adapter
*adapter
= netdev_priv(netdev
);
781 case ETHTOOL_RX_COPYBREAK
:
783 if (len
> adapter
->netdev
->mtu
) {
787 adapter
->rx_copybreak
= len
;
797 static const struct ethtool_ops ena_ethtool_ops
= {
798 .get_link_ksettings
= ena_get_link_ksettings
,
799 .get_drvinfo
= ena_get_drvinfo
,
800 .get_msglevel
= ena_get_msglevel
,
801 .set_msglevel
= ena_set_msglevel
,
802 .get_link
= ethtool_op_get_link
,
803 .get_coalesce
= ena_get_coalesce
,
804 .set_coalesce
= ena_set_coalesce
,
805 .get_ringparam
= ena_get_ringparam
,
806 .get_sset_count
= ena_get_sset_count
,
807 .get_strings
= ena_get_strings
,
808 .get_ethtool_stats
= ena_get_ethtool_stats
,
809 .get_rxnfc
= ena_get_rxnfc
,
810 .set_rxnfc
= ena_set_rxnfc
,
811 .get_rxfh_indir_size
= ena_get_rxfh_indir_size
,
812 .get_rxfh_key_size
= ena_get_rxfh_key_size
,
813 .get_rxfh
= ena_get_rxfh
,
814 .set_rxfh
= ena_set_rxfh
,
815 .get_channels
= ena_get_channels
,
816 .get_tunable
= ena_get_tunable
,
817 .set_tunable
= ena_set_tunable
,
820 void ena_set_ethtool_ops(struct net_device
*netdev
)
822 netdev
->ethtool_ops
= &ena_ethtool_ops
;
825 static void ena_dump_stats_ex(struct ena_adapter
*adapter
, u8
*buf
)
827 struct net_device
*netdev
= adapter
->netdev
;
833 strings_num
= ena_get_sset_count(netdev
, ETH_SS_STATS
);
834 if (strings_num
<= 0) {
835 netif_err(adapter
, drv
, netdev
, "Can't get stats num\n");
839 strings_buf
= devm_kzalloc(&adapter
->pdev
->dev
,
840 strings_num
* ETH_GSTRING_LEN
,
843 netif_err(adapter
, drv
, netdev
,
844 "failed to alloc strings_buf\n");
848 data_buf
= devm_kzalloc(&adapter
->pdev
->dev
,
849 strings_num
* sizeof(u64
),
852 netif_err(adapter
, drv
, netdev
,
853 "failed to allocate data buf\n");
854 devm_kfree(&adapter
->pdev
->dev
, strings_buf
);
858 ena_get_strings(netdev
, ETH_SS_STATS
, strings_buf
);
859 ena_get_ethtool_stats(netdev
, NULL
, data_buf
);
861 /* If there is a buffer, dump stats, otherwise print them to dmesg */
863 for (i
= 0; i
< strings_num
; i
++) {
864 rc
= snprintf(buf
, ETH_GSTRING_LEN
+ sizeof(u64
),
866 strings_buf
+ i
* ETH_GSTRING_LEN
,
871 for (i
= 0; i
< strings_num
; i
++)
872 netif_err(adapter
, drv
, netdev
, "%s: %llu\n",
873 strings_buf
+ i
* ETH_GSTRING_LEN
,
876 devm_kfree(&adapter
->pdev
->dev
, strings_buf
);
877 devm_kfree(&adapter
->pdev
->dev
, data_buf
);
880 void ena_dump_stats_to_buf(struct ena_adapter
*adapter
, u8
*buf
)
885 ena_dump_stats_ex(adapter
, buf
);
888 void ena_dump_stats_to_dmesg(struct ena_adapter
*adapter
)
890 ena_dump_stats_ex(adapter
, NULL
);