hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/net/ethernet/amazon/ena/ena_ethtool.c
....@@ -1,33 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
12 /*
2
- * Copyright 2015 Amazon.com, Inc. or its affiliates.
3
- *
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
8
- * BSD license below:
9
- *
10
- * Redistribution and use in source and binary forms, with or
11
- * without modification, are permitted provided that the following
12
- * conditions are met:
13
- *
14
- * - Redistributions of source code must retain the above
15
- * copyright notice, this list of conditions and the following
16
- * disclaimer.
17
- *
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.
22
- *
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
30
- * SOFTWARE.
3
+ * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All rights reserved.
314 */
325
336 #include <linux/pci.h>
....@@ -41,12 +14,17 @@
4114
4215 #define ENA_STAT_ENA_COM_ENTRY(stat) { \
4316 .name = #stat, \
44
- .stat_offset = offsetof(struct ena_com_stats_admin, stat) \
17
+ .stat_offset = offsetof(struct ena_com_stats_admin, stat) / sizeof(u64) \
4518 }
4619
4720 #define ENA_STAT_ENTRY(stat, stat_type) { \
4821 .name = #stat, \
49
- .stat_offset = offsetof(struct ena_stats_##stat_type, stat) \
22
+ .stat_offset = offsetof(struct ena_stats_##stat_type, stat) / sizeof(u64) \
23
+}
24
+
25
+#define ENA_STAT_HW_ENTRY(stat, stat_type) { \
26
+ .name = #stat, \
27
+ .stat_offset = offsetof(struct ena_admin_##stat_type, stat) / sizeof(u64) \
5028 }
5129
5230 #define ENA_STAT_RX_ENTRY(stat) \
....@@ -58,6 +36,9 @@
5836 #define ENA_STAT_GLOBAL_ENTRY(stat) \
5937 ENA_STAT_ENTRY(stat, dev)
6038
39
+#define ENA_STAT_ENI_ENTRY(stat) \
40
+ ENA_STAT_HW_ENTRY(stat, eni_stats)
41
+
6142 static const struct ena_stats ena_stats_global_strings[] = {
6243 ENA_STAT_GLOBAL_ENTRY(tx_timeout),
6344 ENA_STAT_GLOBAL_ENTRY(suspend),
....@@ -66,6 +47,14 @@
6647 ENA_STAT_GLOBAL_ENTRY(interface_up),
6748 ENA_STAT_GLOBAL_ENTRY(interface_down),
6849 ENA_STAT_GLOBAL_ENTRY(admin_q_pause),
50
+};
51
+
52
+static const struct ena_stats ena_stats_eni_strings[] = {
53
+ ENA_STAT_ENI_ENTRY(bw_in_allowance_exceeded),
54
+ ENA_STAT_ENI_ENTRY(bw_out_allowance_exceeded),
55
+ ENA_STAT_ENI_ENTRY(pps_allowance_exceeded),
56
+ ENA_STAT_ENI_ENTRY(conntrack_allowance_exceeded),
57
+ ENA_STAT_ENI_ENTRY(linklocal_allowance_exceeded),
6958 };
7059
7160 static const struct ena_stats ena_stats_tx_strings[] = {
....@@ -81,21 +70,30 @@
8170 ENA_STAT_TX_ENTRY(doorbells),
8271 ENA_STAT_TX_ENTRY(prepare_ctx_err),
8372 ENA_STAT_TX_ENTRY(bad_req_id),
73
+ ENA_STAT_TX_ENTRY(llq_buffer_copy),
8474 ENA_STAT_TX_ENTRY(missed_tx),
75
+ ENA_STAT_TX_ENTRY(unmask_interrupt),
8576 };
8677
8778 static const struct ena_stats ena_stats_rx_strings[] = {
8879 ENA_STAT_RX_ENTRY(cnt),
8980 ENA_STAT_RX_ENTRY(bytes),
81
+ ENA_STAT_RX_ENTRY(rx_copybreak_pkt),
82
+ ENA_STAT_RX_ENTRY(csum_good),
9083 ENA_STAT_RX_ENTRY(refil_partial),
9184 ENA_STAT_RX_ENTRY(bad_csum),
9285 ENA_STAT_RX_ENTRY(page_alloc_fail),
9386 ENA_STAT_RX_ENTRY(skb_alloc_fail),
9487 ENA_STAT_RX_ENTRY(dma_mapping_err),
9588 ENA_STAT_RX_ENTRY(bad_desc_num),
96
- ENA_STAT_RX_ENTRY(rx_copybreak_pkt),
9789 ENA_STAT_RX_ENTRY(bad_req_id),
9890 ENA_STAT_RX_ENTRY(empty_rx_ring),
91
+ ENA_STAT_RX_ENTRY(csum_unchecked),
92
+ ENA_STAT_RX_ENTRY(xdp_aborted),
93
+ ENA_STAT_RX_ENTRY(xdp_drop),
94
+ ENA_STAT_RX_ENTRY(xdp_pass),
95
+ ENA_STAT_RX_ENTRY(xdp_tx),
96
+ ENA_STAT_RX_ENTRY(xdp_invalid),
9997 };
10098
10199 static const struct ena_stats ena_stats_ena_com_strings[] = {
....@@ -106,10 +104,12 @@
106104 ENA_STAT_ENA_COM_ENTRY(no_completion),
107105 };
108106
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)
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)
111
+#define ENA_STATS_ARRAY_ENI(adapter) \
112
+ (ARRAY_SIZE(ena_stats_eni_strings) * (adapter)->eni_stats_supported)
113113
114114 static void ena_safe_update_stat(u64 *src, u64 *dst,
115115 struct u64_stats_sync *syncp)
....@@ -130,29 +130,30 @@
130130 u64 *ptr;
131131 int i, j;
132132
133
- for (i = 0; i < adapter->num_queues; i++) {
133
+ for (i = 0; i < adapter->num_io_queues + adapter->xdp_num_queues; i++) {
134134 /* Tx stats */
135135 ring = &adapter->tx_ring[i];
136136
137137 for (j = 0; j < ENA_STATS_ARRAY_TX; j++) {
138138 ena_stats = &ena_stats_tx_strings[j];
139139
140
- ptr = (u64 *)((uintptr_t)&ring->tx_stats +
141
- (uintptr_t)ena_stats->stat_offset);
140
+ ptr = (u64 *)&ring->tx_stats + ena_stats->stat_offset;
142141
143142 ena_safe_update_stat(ptr, (*data)++, &ring->syncp);
144143 }
144
+ /* XDP TX queues don't have a RX queue counterpart */
145
+ if (!ENA_IS_XDP_INDEX(adapter, i)) {
146
+ /* Rx stats */
147
+ ring = &adapter->rx_ring[i];
145148
146
- /* Rx stats */
147
- ring = &adapter->rx_ring[i];
149
+ for (j = 0; j < ENA_STATS_ARRAY_RX; j++) {
150
+ ena_stats = &ena_stats_rx_strings[j];
148151
149
- for (j = 0; j < ENA_STATS_ARRAY_RX; j++) {
150
- ena_stats = &ena_stats_rx_strings[j];
152
+ ptr = (u64 *)&ring->rx_stats +
153
+ ena_stats->stat_offset;
151154
152
- ptr = (u64 *)((uintptr_t)&ring->rx_stats +
153
- (uintptr_t)ena_stats->stat_offset);
154
-
155
- ena_safe_update_stat(ptr, (*data)++, &ring->syncp);
155
+ ena_safe_update_stat(ptr, (*data)++, &ring->syncp);
156
+ }
156157 }
157158 }
158159 }
....@@ -160,24 +161,23 @@
160161 static void ena_dev_admin_queue_stats(struct ena_adapter *adapter, u64 **data)
161162 {
162163 const struct ena_stats *ena_stats;
163
- u32 *ptr;
164
+ u64 *ptr;
164165 int i;
165166
166167 for (i = 0; i < ENA_STATS_ARRAY_ENA_COM; i++) {
167168 ena_stats = &ena_stats_ena_com_strings[i];
168169
169
- ptr = (u32 *)((uintptr_t)&adapter->ena_dev->admin_queue.stats +
170
- (uintptr_t)ena_stats->stat_offset);
170
+ ptr = (u64 *)&adapter->ena_dev->admin_queue.stats +
171
+ ena_stats->stat_offset;
171172
172173 *(*data)++ = *ptr;
173174 }
174175 }
175176
176
-static void ena_get_ethtool_stats(struct net_device *netdev,
177
- struct ethtool_stats *stats,
178
- u64 *data)
177
+static void ena_get_stats(struct ena_adapter *adapter,
178
+ u64 *data,
179
+ bool eni_stats_needed)
179180 {
180
- struct ena_adapter *adapter = netdev_priv(netdev);
181181 const struct ena_stats *ena_stats;
182182 u64 *ptr;
183183 int i;
....@@ -185,14 +185,46 @@
185185 for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
186186 ena_stats = &ena_stats_global_strings[i];
187187
188
- ptr = (u64 *)((uintptr_t)&adapter->dev_stats +
189
- (uintptr_t)ena_stats->stat_offset);
188
+ ptr = (u64 *)&adapter->dev_stats + ena_stats->stat_offset;
190189
191190 ena_safe_update_stat(ptr, data++, &adapter->syncp);
192191 }
193192
193
+ if (eni_stats_needed) {
194
+ ena_update_hw_stats(adapter);
195
+ for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
196
+ ena_stats = &ena_stats_eni_strings[i];
197
+
198
+ ptr = (u64 *)&adapter->eni_stats +
199
+ ena_stats->stat_offset;
200
+
201
+ ena_safe_update_stat(ptr, data++, &adapter->syncp);
202
+ }
203
+ }
204
+
194205 ena_queue_stats(adapter, &data);
195206 ena_dev_admin_queue_stats(adapter, &data);
207
+}
208
+
209
+static void ena_get_ethtool_stats(struct net_device *netdev,
210
+ struct ethtool_stats *stats,
211
+ u64 *data)
212
+{
213
+ struct ena_adapter *adapter = netdev_priv(netdev);
214
+
215
+ ena_get_stats(adapter, data, adapter->eni_stats_supported);
216
+}
217
+
218
+static int ena_get_sw_stats_count(struct ena_adapter *adapter)
219
+{
220
+ return adapter->num_io_queues * (ENA_STATS_ARRAY_TX + ENA_STATS_ARRAY_RX)
221
+ + adapter->xdp_num_queues * ENA_STATS_ARRAY_TX
222
+ + ENA_STATS_ARRAY_GLOBAL + ENA_STATS_ARRAY_ENA_COM;
223
+}
224
+
225
+static int ena_get_hw_stats_count(struct ena_adapter *adapter)
226
+{
227
+ return ENA_STATS_ARRAY_ENI(adapter);
196228 }
197229
198230 int ena_get_sset_count(struct net_device *netdev, int sset)
....@@ -202,31 +234,38 @@
202234 if (sset != ETH_SS_STATS)
203235 return -EOPNOTSUPP;
204236
205
- return adapter->num_queues * (ENA_STATS_ARRAY_TX + ENA_STATS_ARRAY_RX)
206
- + ENA_STATS_ARRAY_GLOBAL + ENA_STATS_ARRAY_ENA_COM;
237
+ return ena_get_sw_stats_count(adapter) + ena_get_hw_stats_count(adapter);
207238 }
208239
209240 static void ena_queue_strings(struct ena_adapter *adapter, u8 **data)
210241 {
211242 const struct ena_stats *ena_stats;
243
+ bool is_xdp;
212244 int i, j;
213245
214
- for (i = 0; i < adapter->num_queues; i++) {
246
+ for (i = 0; i < adapter->num_io_queues + adapter->xdp_num_queues; i++) {
247
+ is_xdp = ENA_IS_XDP_INDEX(adapter, i);
215248 /* Tx stats */
216249 for (j = 0; j < ENA_STATS_ARRAY_TX; j++) {
217250 ena_stats = &ena_stats_tx_strings[j];
218251
219252 snprintf(*data, ETH_GSTRING_LEN,
220
- "queue_%u_tx_%s", i, ena_stats->name);
221
- (*data) += ETH_GSTRING_LEN;
222
- }
223
- /* Rx stats */
224
- for (j = 0; j < ENA_STATS_ARRAY_RX; j++) {
225
- ena_stats = &ena_stats_rx_strings[j];
226
-
227
- snprintf(*data, ETH_GSTRING_LEN,
228
- "queue_%u_rx_%s", i, ena_stats->name);
253
+ "queue_%u_%s_%s", i,
254
+ is_xdp ? "xdp_tx" : "tx", ena_stats->name);
229255 (*data) += ETH_GSTRING_LEN;
256
+ }
257
+
258
+ if (!is_xdp) {
259
+ /* RX stats, in XDP there isn't a RX queue
260
+ * counterpart
261
+ */
262
+ for (j = 0; j < ENA_STATS_ARRAY_RX; j++) {
263
+ ena_stats = &ena_stats_rx_strings[j];
264
+
265
+ snprintf(*data, ETH_GSTRING_LEN,
266
+ "queue_%u_rx_%s", i, ena_stats->name);
267
+ (*data) += ETH_GSTRING_LEN;
268
+ }
230269 }
231270 }
232271 }
....@@ -245,24 +284,41 @@
245284 }
246285 }
247286
248
-static void ena_get_strings(struct net_device *netdev, u32 sset, u8 *data)
287
+static void ena_get_strings(struct ena_adapter *adapter,
288
+ u8 *data,
289
+ bool eni_stats_needed)
249290 {
250
- struct ena_adapter *adapter = netdev_priv(netdev);
251291 const struct ena_stats *ena_stats;
252292 int i;
253293
254
- if (sset != ETH_SS_STATS)
255
- return;
256
-
257294 for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
258295 ena_stats = &ena_stats_global_strings[i];
259
-
260296 memcpy(data, ena_stats->name, ETH_GSTRING_LEN);
261297 data += ETH_GSTRING_LEN;
262298 }
263299
300
+ if (eni_stats_needed) {
301
+ for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
302
+ ena_stats = &ena_stats_eni_strings[i];
303
+ memcpy(data, ena_stats->name, ETH_GSTRING_LEN);
304
+ data += ETH_GSTRING_LEN;
305
+ }
306
+ }
307
+
264308 ena_queue_strings(adapter, &data);
265309 ena_com_dev_strings(&data);
310
+}
311
+
312
+static void ena_get_ethtool_strings(struct net_device *netdev,
313
+ u32 sset,
314
+ u8 *data)
315
+{
316
+ struct ena_adapter *adapter = netdev_priv(netdev);
317
+
318
+ if (sset != ETH_SS_STATS)
319
+ return;
320
+
321
+ ena_get_strings(adapter, data, adapter->eni_stats_supported);
266322 }
267323
268324 static int ena_get_link_ksettings(struct net_device *netdev,
....@@ -302,47 +358,44 @@
302358 {
303359 struct ena_adapter *adapter = netdev_priv(net_dev);
304360 struct ena_com_dev *ena_dev = adapter->ena_dev;
305
- struct ena_intr_moder_entry intr_moder_entry;
306361
307
- if (!ena_com_interrupt_moderation_supported(ena_dev)) {
308
- /* the devie doesn't support interrupt moderation */
362
+ if (!ena_com_interrupt_moderation_supported(ena_dev))
309363 return -EOPNOTSUPP;
310
- }
364
+
311365 coalesce->tx_coalesce_usecs =
312
- ena_com_get_nonadaptive_moderation_interval_tx(ena_dev) /
366
+ ena_com_get_nonadaptive_moderation_interval_tx(ena_dev) *
313367 ena_dev->intr_delay_resolution;
314
- if (!ena_com_get_adaptive_moderation_enabled(ena_dev)) {
315
- coalesce->rx_coalesce_usecs =
316
- ena_com_get_nonadaptive_moderation_interval_rx(ena_dev)
317
- / ena_dev->intr_delay_resolution;
318
- } else {
319
- ena_com_get_intr_moderation_entry(adapter->ena_dev, ENA_INTR_MODER_LOWEST, &intr_moder_entry);
320
- coalesce->rx_coalesce_usecs_low = intr_moder_entry.intr_moder_interval;
321
- coalesce->rx_max_coalesced_frames_low = intr_moder_entry.pkts_per_interval;
322368
323
- ena_com_get_intr_moderation_entry(adapter->ena_dev, ENA_INTR_MODER_MID, &intr_moder_entry);
324
- coalesce->rx_coalesce_usecs = intr_moder_entry.intr_moder_interval;
325
- coalesce->rx_max_coalesced_frames = intr_moder_entry.pkts_per_interval;
369
+ coalesce->rx_coalesce_usecs =
370
+ ena_com_get_nonadaptive_moderation_interval_rx(ena_dev)
371
+ * ena_dev->intr_delay_resolution;
326372
327
- ena_com_get_intr_moderation_entry(adapter->ena_dev, ENA_INTR_MODER_HIGHEST, &intr_moder_entry);
328
- coalesce->rx_coalesce_usecs_high = intr_moder_entry.intr_moder_interval;
329
- coalesce->rx_max_coalesced_frames_high = intr_moder_entry.pkts_per_interval;
330
- }
331373 coalesce->use_adaptive_rx_coalesce =
332374 ena_com_get_adaptive_moderation_enabled(ena_dev);
333375
334376 return 0;
335377 }
336378
337
-static void ena_update_tx_rings_intr_moderation(struct ena_adapter *adapter)
379
+static void ena_update_tx_rings_nonadaptive_intr_moderation(struct ena_adapter *adapter)
338380 {
339381 unsigned int val;
340382 int i;
341383
342384 val = ena_com_get_nonadaptive_moderation_interval_tx(adapter->ena_dev);
343385
344
- for (i = 0; i < adapter->num_queues; i++)
386
+ for (i = 0; i < adapter->num_io_queues; i++)
345387 adapter->tx_ring[i].smoothed_interval = val;
388
+}
389
+
390
+static void ena_update_rx_rings_nonadaptive_intr_moderation(struct ena_adapter *adapter)
391
+{
392
+ unsigned int val;
393
+ int i;
394
+
395
+ val = ena_com_get_nonadaptive_moderation_interval_rx(adapter->ena_dev);
396
+
397
+ for (i = 0; i < adapter->num_io_queues; i++)
398
+ adapter->rx_ring[i].smoothed_interval = val;
346399 }
347400
348401 static int ena_set_coalesce(struct net_device *net_dev,
....@@ -350,68 +403,32 @@
350403 {
351404 struct ena_adapter *adapter = netdev_priv(net_dev);
352405 struct ena_com_dev *ena_dev = adapter->ena_dev;
353
- struct ena_intr_moder_entry intr_moder_entry;
354406 int rc;
355407
356
- if (!ena_com_interrupt_moderation_supported(ena_dev)) {
357
- /* the devie doesn't support interrupt moderation */
408
+ if (!ena_com_interrupt_moderation_supported(ena_dev))
358409 return -EOPNOTSUPP;
359
- }
360
-
361
- if (coalesce->rx_coalesce_usecs_irq ||
362
- coalesce->rx_max_coalesced_frames_irq ||
363
- coalesce->tx_coalesce_usecs_irq ||
364
- coalesce->tx_max_coalesced_frames ||
365
- coalesce->tx_max_coalesced_frames_irq ||
366
- coalesce->stats_block_coalesce_usecs ||
367
- coalesce->use_adaptive_tx_coalesce ||
368
- coalesce->pkt_rate_low ||
369
- coalesce->tx_coalesce_usecs_low ||
370
- coalesce->tx_max_coalesced_frames_low ||
371
- coalesce->pkt_rate_high ||
372
- coalesce->tx_coalesce_usecs_high ||
373
- coalesce->tx_max_coalesced_frames_high ||
374
- coalesce->rate_sample_interval)
375
- return -EINVAL;
376410
377411 rc = ena_com_update_nonadaptive_moderation_interval_tx(ena_dev,
378412 coalesce->tx_coalesce_usecs);
379413 if (rc)
380414 return rc;
381415
382
- ena_update_tx_rings_intr_moderation(adapter);
416
+ ena_update_tx_rings_nonadaptive_intr_moderation(adapter);
383417
384
- if (ena_com_get_adaptive_moderation_enabled(ena_dev)) {
385
- if (!coalesce->use_adaptive_rx_coalesce) {
386
- ena_com_disable_adaptive_moderation(ena_dev);
387
- rc = ena_com_update_nonadaptive_moderation_interval_rx(ena_dev,
388
- coalesce->rx_coalesce_usecs);
389
- return rc;
390
- }
391
- } else { /* was in non-adaptive mode */
392
- if (coalesce->use_adaptive_rx_coalesce) {
393
- ena_com_enable_adaptive_moderation(ena_dev);
394
- } else {
395
- rc = ena_com_update_nonadaptive_moderation_interval_rx(ena_dev,
396
- coalesce->rx_coalesce_usecs);
397
- return rc;
398
- }
399
- }
418
+ rc = ena_com_update_nonadaptive_moderation_interval_rx(ena_dev,
419
+ coalesce->rx_coalesce_usecs);
420
+ if (rc)
421
+ return rc;
400422
401
- intr_moder_entry.intr_moder_interval = coalesce->rx_coalesce_usecs_low;
402
- intr_moder_entry.pkts_per_interval = coalesce->rx_max_coalesced_frames_low;
403
- intr_moder_entry.bytes_per_interval = ENA_INTR_BYTE_COUNT_NOT_SUPPORTED;
404
- ena_com_init_intr_moderation_entry(adapter->ena_dev, ENA_INTR_MODER_LOWEST, &intr_moder_entry);
423
+ ena_update_rx_rings_nonadaptive_intr_moderation(adapter);
405424
406
- intr_moder_entry.intr_moder_interval = coalesce->rx_coalesce_usecs;
407
- intr_moder_entry.pkts_per_interval = coalesce->rx_max_coalesced_frames;
408
- intr_moder_entry.bytes_per_interval = ENA_INTR_BYTE_COUNT_NOT_SUPPORTED;
409
- ena_com_init_intr_moderation_entry(adapter->ena_dev, ENA_INTR_MODER_MID, &intr_moder_entry);
425
+ if (coalesce->use_adaptive_rx_coalesce &&
426
+ !ena_com_get_adaptive_moderation_enabled(ena_dev))
427
+ ena_com_enable_adaptive_moderation(ena_dev);
410428
411
- intr_moder_entry.intr_moder_interval = coalesce->rx_coalesce_usecs_high;
412
- intr_moder_entry.pkts_per_interval = coalesce->rx_max_coalesced_frames_high;
413
- intr_moder_entry.bytes_per_interval = ENA_INTR_BYTE_COUNT_NOT_SUPPORTED;
414
- ena_com_init_intr_moderation_entry(adapter->ena_dev, ENA_INTR_MODER_HIGHEST, &intr_moder_entry);
429
+ if (!coalesce->use_adaptive_rx_coalesce &&
430
+ ena_com_get_adaptive_moderation_enabled(ena_dev))
431
+ ena_com_disable_adaptive_moderation(ena_dev);
415432
416433 return 0;
417434 }
....@@ -436,7 +453,6 @@
436453 struct ena_adapter *adapter = netdev_priv(dev);
437454
438455 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
439
- strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
440456 strlcpy(info->bus_info, pci_name(adapter->pdev),
441457 sizeof(info->bus_info));
442458 }
....@@ -445,13 +461,32 @@
445461 struct ethtool_ringparam *ring)
446462 {
447463 struct ena_adapter *adapter = netdev_priv(netdev);
448
- struct ena_ring *tx_ring = &adapter->tx_ring[0];
449
- struct ena_ring *rx_ring = &adapter->rx_ring[0];
450464
451
- ring->rx_max_pending = rx_ring->ring_size;
452
- ring->tx_max_pending = tx_ring->ring_size;
453
- ring->rx_pending = rx_ring->ring_size;
454
- ring->tx_pending = tx_ring->ring_size;
465
+ ring->tx_max_pending = adapter->max_tx_ring_size;
466
+ ring->rx_max_pending = adapter->max_rx_ring_size;
467
+ ring->tx_pending = adapter->tx_ring[0].ring_size;
468
+ ring->rx_pending = adapter->rx_ring[0].ring_size;
469
+}
470
+
471
+static int ena_set_ringparam(struct net_device *netdev,
472
+ struct ethtool_ringparam *ring)
473
+{
474
+ struct ena_adapter *adapter = netdev_priv(netdev);
475
+ u32 new_tx_size, new_rx_size;
476
+
477
+ new_tx_size = ring->tx_pending < ENA_MIN_RING_SIZE ?
478
+ ENA_MIN_RING_SIZE : ring->tx_pending;
479
+ new_tx_size = rounddown_pow_of_two(new_tx_size);
480
+
481
+ new_rx_size = ring->rx_pending < ENA_MIN_RING_SIZE ?
482
+ ENA_MIN_RING_SIZE : ring->rx_pending;
483
+ new_rx_size = rounddown_pow_of_two(new_rx_size);
484
+
485
+ if (new_tx_size == adapter->requested_tx_ring_size &&
486
+ new_rx_size == adapter->requested_rx_ring_size)
487
+ return 0;
488
+
489
+ return ena_update_queue_sizes(adapter, new_tx_size, new_rx_size);
455490 }
456491
457492 static u32 ena_flow_hash_to_flow_type(u16 hash_fields)
....@@ -621,7 +656,7 @@
621656
622657 switch (info->cmd) {
623658 case ETHTOOL_GRXRINGS:
624
- info->data = adapter->num_queues;
659
+ info->data = adapter->num_io_queues;
625660 rc = 0;
626661 break;
627662 case ETHTOOL_GRXFH:
....@@ -647,6 +682,32 @@
647682 static u32 ena_get_rxfh_key_size(struct net_device *netdev)
648683 {
649684 return ENA_HASH_KEY_SIZE;
685
+}
686
+
687
+static int ena_indirection_table_set(struct ena_adapter *adapter,
688
+ const u32 *indir)
689
+{
690
+ struct ena_com_dev *ena_dev = adapter->ena_dev;
691
+ int i, rc;
692
+
693
+ for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
694
+ rc = ena_com_indirect_table_fill_entry(ena_dev,
695
+ i,
696
+ ENA_IO_RXQ_IDX(indir[i]));
697
+ if (unlikely(rc)) {
698
+ netif_err(adapter, drv, adapter->netdev,
699
+ "Cannot fill indirect table (index is too large)\n");
700
+ return rc;
701
+ }
702
+ }
703
+
704
+ rc = ena_com_indirect_table_set(ena_dev);
705
+ if (rc) {
706
+ netif_err(adapter, drv, adapter->netdev,
707
+ "Cannot set indirect table\n");
708
+ return rc == -EPERM ? -EOPNOTSUPP : rc;
709
+ }
710
+ return rc;
650711 }
651712
652713 static int ena_indirection_table_get(struct ena_adapter *adapter, u32 *indir)
....@@ -686,18 +747,15 @@
686747 /* We call this function in order to check if the device
687748 * supports getting/setting the hash function.
688749 */
689
- rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func, key);
690
-
750
+ rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func);
691751 if (rc) {
692
- if (rc == -EOPNOTSUPP) {
693
- key = NULL;
694
- hfunc = NULL;
752
+ if (rc == -EOPNOTSUPP)
695753 rc = 0;
696
- }
697754
698755 return rc;
699756 }
700757
758
+ rc = ena_com_get_hash_key(adapter->ena_dev, key);
701759 if (rc)
702760 return rc;
703761
....@@ -717,7 +775,7 @@
717775 if (hfunc)
718776 *hfunc = func;
719777
720
- return rc;
778
+ return 0;
721779 }
722780
723781 static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
....@@ -725,27 +783,13 @@
725783 {
726784 struct ena_adapter *adapter = netdev_priv(netdev);
727785 struct ena_com_dev *ena_dev = adapter->ena_dev;
728
- enum ena_admin_hash_functions func;
729
- int rc, i;
786
+ enum ena_admin_hash_functions func = 0;
787
+ int rc;
730788
731789 if (indir) {
732
- for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
733
- rc = ena_com_indirect_table_fill_entry(ena_dev,
734
- i,
735
- ENA_IO_RXQ_IDX(indir[i]));
736
- if (unlikely(rc)) {
737
- netif_err(adapter, drv, netdev,
738
- "Cannot fill indirect table (index is too large)\n");
739
- return rc;
740
- }
741
- }
742
-
743
- rc = ena_com_indirect_table_set(ena_dev);
744
- if (rc) {
745
- netif_err(adapter, drv, netdev,
746
- "Cannot set indirect table\n");
747
- return rc == -EPERM ? -EOPNOTSUPP : rc;
748
- }
790
+ rc = ena_indirection_table_set(adapter, indir);
791
+ if (rc)
792
+ return rc;
749793 }
750794
751795 switch (hfunc) {
....@@ -764,7 +808,7 @@
764808 return -EOPNOTSUPP;
765809 }
766810
767
- if (key) {
811
+ if (key || func) {
768812 rc = ena_com_fill_hash_function(ena_dev, func, key,
769813 ENA_HASH_KEY_SIZE,
770814 0xFFFFFFFF);
....@@ -782,14 +826,22 @@
782826 {
783827 struct ena_adapter *adapter = netdev_priv(netdev);
784828
785
- channels->max_rx = adapter->num_queues;
786
- channels->max_tx = adapter->num_queues;
787
- channels->max_other = 0;
788
- channels->max_combined = 0;
789
- channels->rx_count = adapter->num_queues;
790
- channels->tx_count = adapter->num_queues;
791
- channels->other_count = 0;
792
- channels->combined_count = 0;
829
+ channels->max_combined = adapter->max_num_io_queues;
830
+ channels->combined_count = adapter->num_io_queues;
831
+}
832
+
833
+static int ena_set_channels(struct net_device *netdev,
834
+ struct ethtool_channels *channels)
835
+{
836
+ struct ena_adapter *adapter = netdev_priv(netdev);
837
+ u32 count = channels->combined_count;
838
+ /* The check for max value is already done in ethtool */
839
+ if (count < ENA_MIN_NUM_IO_QUEUES ||
840
+ (ena_xdp_present(adapter) &&
841
+ !ena_xdp_legal_queue_count(adapter, channels->combined_count)))
842
+ return -EINVAL;
843
+
844
+ return ena_update_queue_count(adapter, count);
793845 }
794846
795847 static int ena_get_tunable(struct net_device *netdev,
....@@ -836,6 +888,8 @@
836888 }
837889
838890 static const struct ethtool_ops ena_ethtool_ops = {
891
+ .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
892
+ ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
839893 .get_link_ksettings = ena_get_link_ksettings,
840894 .get_drvinfo = ena_get_drvinfo,
841895 .get_msglevel = ena_get_msglevel,
....@@ -844,8 +898,9 @@
844898 .get_coalesce = ena_get_coalesce,
845899 .set_coalesce = ena_set_coalesce,
846900 .get_ringparam = ena_get_ringparam,
901
+ .set_ringparam = ena_set_ringparam,
847902 .get_sset_count = ena_get_sset_count,
848
- .get_strings = ena_get_strings,
903
+ .get_strings = ena_get_ethtool_strings,
849904 .get_ethtool_stats = ena_get_ethtool_stats,
850905 .get_rxnfc = ena_get_rxnfc,
851906 .set_rxnfc = ena_set_rxnfc,
....@@ -854,6 +909,7 @@
854909 .get_rxfh = ena_get_rxfh,
855910 .set_rxfh = ena_set_rxfh,
856911 .get_channels = ena_get_channels,
912
+ .set_channels = ena_set_channels,
857913 .get_tunable = ena_get_tunable,
858914 .set_tunable = ena_set_tunable,
859915 .get_ts_info = ethtool_op_get_ts_info,
....@@ -872,7 +928,7 @@
872928 int strings_num;
873929 int i, rc;
874930
875
- strings_num = ena_get_sset_count(netdev, ETH_SS_STATS);
931
+ strings_num = ena_get_sw_stats_count(adapter);
876932 if (strings_num <= 0) {
877933 netif_err(adapter, drv, netdev, "Can't get stats num\n");
878934 return;
....@@ -883,7 +939,7 @@
883939 GFP_ATOMIC);
884940 if (!strings_buf) {
885941 netif_err(adapter, drv, netdev,
886
- "failed to alloc strings_buf\n");
942
+ "Failed to allocate strings_buf\n");
887943 return;
888944 }
889945
....@@ -892,13 +948,13 @@
892948 GFP_ATOMIC);
893949 if (!data_buf) {
894950 netif_err(adapter, drv, netdev,
895
- "failed to allocate data buf\n");
951
+ "Failed to allocate data buf\n");
896952 devm_kfree(&adapter->pdev->dev, strings_buf);
897953 return;
898954 }
899955
900
- ena_get_strings(netdev, ETH_SS_STATS, strings_buf);
901
- ena_get_ethtool_stats(netdev, NULL, data_buf);
956
+ ena_get_strings(adapter, strings_buf, false);
957
+ ena_get_stats(adapter, data_buf, false);
902958
903959 /* If there is a buffer, dump stats, otherwise print them to dmesg */
904960 if (buf)