-
Notifications
You must be signed in to change notification settings - Fork 4
/
sfc_ethdev.c
2340 lines (1910 loc) · 57.3 KB
/
sfc_ethdev.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2019-2020 Xilinx, Inc.
* Copyright(c) 2016-2019 Solarflare Communications Inc.
*
* This software was jointly developed between OKTET Labs (under contract
* for Solarflare) and Solarflare Communications, Inc.
*/
#include <rte_dev.h>
#include <rte_ethdev_driver.h>
#include <rte_ethdev_pci.h>
#include <rte_pci.h>
#include <rte_bus_pci.h>
#include <rte_errno.h>
#include <rte_string_fns.h>
#include <rte_ether.h>
#include "efx.h"
#include "sfc.h"
#include "sfc_debug.h"
#include "sfc_log.h"
#include "sfc_kvargs.h"
#include "sfc_ev.h"
#include "sfc_rx.h"
#include "sfc_tx.h"
#include "sfc_flow.h"
#include "sfc_dp.h"
#include "sfc_dp_rx.h"
uint32_t sfc_logtype_driver;
static struct sfc_dp_list sfc_dp_head =
TAILQ_HEAD_INITIALIZER(sfc_dp_head);
static void sfc_eth_dev_clear_ops(struct rte_eth_dev *dev);
static int
sfc_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
efx_nic_fw_info_t enfi;
int ret;
int rc;
rc = efx_nic_get_fw_version(sa->nic, &enfi);
if (rc != 0)
return -rc;
ret = snprintf(fw_version, fw_size,
"%" PRIu16 ".%" PRIu16 ".%" PRIu16 ".%" PRIu16,
enfi.enfi_mc_fw_version[0], enfi.enfi_mc_fw_version[1],
enfi.enfi_mc_fw_version[2], enfi.enfi_mc_fw_version[3]);
if (ret < 0)
return ret;
if (enfi.enfi_dpcpu_fw_ids_valid) {
size_t dpcpu_fw_ids_offset = MIN(fw_size - 1, (size_t)ret);
int ret_extra;
ret_extra = snprintf(fw_version + dpcpu_fw_ids_offset,
fw_size - dpcpu_fw_ids_offset,
" rx%" PRIx16 " tx%" PRIx16,
enfi.enfi_rx_dpcpu_fw_id,
enfi.enfi_tx_dpcpu_fw_id);
if (ret_extra < 0)
return ret_extra;
ret += ret_extra;
}
if (fw_size < (size_t)(++ret))
return ret;
else
return 0;
}
static int
sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct sfc_rss *rss = &sas->rss;
struct sfc_mae *mae = &sa->mae;
sfc_log_init(sa, "entry");
dev_info->min_mtu = RTE_ETHER_MIN_MTU;
dev_info->max_mtu = EFX_MAC_SDU_MAX;
dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX;
dev_info->max_vfs = sa->sriov.num_vfs;
/* Autonegotiation may be disabled */
dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_1000FDX))
dev_info->speed_capa |= ETH_LINK_SPEED_1G;
if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_10000FDX))
dev_info->speed_capa |= ETH_LINK_SPEED_10G;
if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_25000FDX))
dev_info->speed_capa |= ETH_LINK_SPEED_25G;
if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_40000FDX))
dev_info->speed_capa |= ETH_LINK_SPEED_40G;
if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_50000FDX))
dev_info->speed_capa |= ETH_LINK_SPEED_50G;
if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_100000FDX))
dev_info->speed_capa |= ETH_LINK_SPEED_100G;
dev_info->max_rx_queues = sa->rxq_max;
dev_info->max_tx_queues = sa->txq_max;
/* By default packets are dropped if no descriptors are available */
dev_info->default_rxconf.rx_drop_en = 1;
dev_info->rx_queue_offload_capa = sfc_rx_get_queue_offload_caps(sa);
/*
* rx_offload_capa includes both device and queue offloads since
* the latter may be requested on a per device basis which makes
* sense when some offloads are needed to be set on all queues.
*/
dev_info->rx_offload_capa = sfc_rx_get_dev_offload_caps(sa) |
dev_info->rx_queue_offload_capa;
dev_info->tx_queue_offload_capa = sfc_tx_get_queue_offload_caps(sa);
/*
* tx_offload_capa includes both device and queue offloads since
* the latter may be requested on a per device basis which makes
* sense when some offloads are needed to be set on all queues.
*/
dev_info->tx_offload_capa = sfc_tx_get_dev_offload_caps(sa) |
dev_info->tx_queue_offload_capa;
if (rss->context_type != EFX_RX_SCALE_UNAVAILABLE) {
uint64_t rte_hf = 0;
unsigned int i;
for (i = 0; i < rss->hf_map_nb_entries; ++i)
rte_hf |= rss->hf_map[i].rte;
dev_info->reta_size = EFX_RSS_TBL_SIZE;
dev_info->hash_key_size = EFX_RSS_KEY_SIZE;
dev_info->flow_type_rss_offloads = rte_hf;
}
/* Initialize to hardware limits */
dev_info->rx_desc_lim.nb_max = sa->rxq_max_entries;
dev_info->rx_desc_lim.nb_min = sa->rxq_min_entries;
/* The RXQ hardware requires that the descriptor count is a power
* of 2, but rx_desc_lim cannot properly describe that constraint.
*/
dev_info->rx_desc_lim.nb_align = sa->rxq_min_entries;
/* Initialize to hardware limits */
dev_info->tx_desc_lim.nb_max = sa->txq_max_entries;
dev_info->tx_desc_lim.nb_min = sa->txq_min_entries;
/*
* The TXQ hardware requires that the descriptor count is a power
* of 2, but tx_desc_lim cannot properly describe that constraint
*/
dev_info->tx_desc_lim.nb_align = sa->txq_min_entries;
if (sap->dp_rx->get_dev_info != NULL)
sap->dp_rx->get_dev_info(dev_info);
if (sap->dp_tx->get_dev_info != NULL)
sap->dp_tx->get_dev_info(dev_info);
dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
if (mae->status == SFC_MAE_STATUS_SUPPORTED) {
dev_info->switch_info.name = dev->device->driver->name;
dev_info->switch_info.domain_id = mae->switch_domain_id;
dev_info->switch_info.port_id = mae->switch_port_id;
}
return 0;
}
static const uint32_t *
sfc_dev_supported_ptypes_get(struct rte_eth_dev *dev)
{
const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
return sap->dp_rx->supported_ptypes_get(sap->shared->tunnel_encaps);
}
static int
sfc_dev_configure(struct rte_eth_dev *dev)
{
struct rte_eth_dev_data *dev_data = dev->data;
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
int rc;
sfc_log_init(sa, "entry n_rxq=%u n_txq=%u",
dev_data->nb_rx_queues, dev_data->nb_tx_queues);
sfc_adapter_lock(sa);
switch (sa->state) {
case SFC_ADAPTER_CONFIGURED:
/* FALLTHROUGH */
case SFC_ADAPTER_INITIALIZED:
rc = sfc_configure(sa);
break;
default:
sfc_err(sa, "unexpected adapter state %u to configure",
sa->state);
rc = EINVAL;
break;
}
sfc_adapter_unlock(sa);
sfc_log_init(sa, "done %d", rc);
SFC_ASSERT(rc >= 0);
return -rc;
}
static int
sfc_dev_start(struct rte_eth_dev *dev)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
int rc;
sfc_log_init(sa, "entry");
sfc_adapter_lock(sa);
rc = sfc_start(sa);
sfc_adapter_unlock(sa);
sfc_log_init(sa, "done %d", rc);
SFC_ASSERT(rc >= 0);
return -rc;
}
static int
sfc_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct rte_eth_link current_link;
int ret;
sfc_log_init(sa, "entry");
if (sa->state != SFC_ADAPTER_STARTED) {
sfc_port_link_mode_to_info(EFX_LINK_UNKNOWN, ¤t_link);
} else if (wait_to_complete) {
efx_link_mode_t link_mode;
if (efx_port_poll(sa->nic, &link_mode) != 0)
link_mode = EFX_LINK_UNKNOWN;
sfc_port_link_mode_to_info(link_mode, ¤t_link);
} else {
sfc_ev_mgmt_qpoll(sa);
rte_eth_linkstatus_get(dev, ¤t_link);
}
ret = rte_eth_linkstatus_set(dev, ¤t_link);
if (ret == 0)
sfc_notice(sa, "Link status is %s",
current_link.link_status ? "UP" : "DOWN");
return ret;
}
static int
sfc_dev_stop(struct rte_eth_dev *dev)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
sfc_log_init(sa, "entry");
sfc_adapter_lock(sa);
sfc_stop(sa);
sfc_adapter_unlock(sa);
sfc_log_init(sa, "done");
return 0;
}
static int
sfc_dev_set_link_up(struct rte_eth_dev *dev)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
int rc;
sfc_log_init(sa, "entry");
sfc_adapter_lock(sa);
rc = sfc_start(sa);
sfc_adapter_unlock(sa);
SFC_ASSERT(rc >= 0);
return -rc;
}
static int
sfc_dev_set_link_down(struct rte_eth_dev *dev)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
sfc_log_init(sa, "entry");
sfc_adapter_lock(sa);
sfc_stop(sa);
sfc_adapter_unlock(sa);
return 0;
}
static void
sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev)
{
free(dev->process_private);
rte_eth_dev_release_port(dev);
}
static int
sfc_dev_close(struct rte_eth_dev *dev)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
sfc_log_init(sa, "entry");
if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
sfc_eth_dev_secondary_clear_ops(dev);
return 0;
}
sfc_adapter_lock(sa);
switch (sa->state) {
case SFC_ADAPTER_STARTED:
sfc_stop(sa);
SFC_ASSERT(sa->state == SFC_ADAPTER_CONFIGURED);
/* FALLTHROUGH */
case SFC_ADAPTER_CONFIGURED:
sfc_close(sa);
SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED);
/* FALLTHROUGH */
case SFC_ADAPTER_INITIALIZED:
break;
default:
sfc_err(sa, "unexpected adapter state %u on close", sa->state);
break;
}
/*
* Cleanup all resources.
* Rollback primary process sfc_eth_dev_init() below.
*/
sfc_eth_dev_clear_ops(dev);
sfc_detach(sa);
sfc_unprobe(sa);
sfc_kvargs_cleanup(sa);
sfc_adapter_unlock(sa);
sfc_adapter_lock_fini(sa);
sfc_log_init(sa, "done");
/* Required for logging, so cleanup last */
sa->eth_dev = NULL;
free(sa);
return 0;
}
static int
sfc_dev_filter_set(struct rte_eth_dev *dev, enum sfc_dev_filter_mode mode,
boolean_t enabled)
{
struct sfc_port *port;
boolean_t *toggle;
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
boolean_t allmulti = (mode == SFC_DEV_FILTER_MODE_ALLMULTI);
const char *desc = (allmulti) ? "all-multi" : "promiscuous";
int rc = 0;
sfc_adapter_lock(sa);
port = &sa->port;
toggle = (allmulti) ? (&port->allmulti) : (&port->promisc);
if (*toggle != enabled) {
*toggle = enabled;
if (sfc_sa2shared(sa)->isolated) {
sfc_warn(sa, "isolated mode is active on the port");
sfc_warn(sa, "the change is to be applied on the next "
"start provided that isolated mode is "
"disabled prior the next start");
} else if ((sa->state == SFC_ADAPTER_STARTED) &&
((rc = sfc_set_rx_mode(sa)) != 0)) {
*toggle = !(enabled);
sfc_warn(sa, "Failed to %s %s mode, rc = %d",
((enabled) ? "enable" : "disable"), desc, rc);
/*
* For promiscuous and all-multicast filters a
* permission failure should be reported as an
* unsupported filter.
*/
if (rc == EPERM)
rc = ENOTSUP;
}
}
sfc_adapter_unlock(sa);
return rc;
}
static int
sfc_dev_promisc_enable(struct rte_eth_dev *dev)
{
int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_TRUE);
SFC_ASSERT(rc >= 0);
return -rc;
}
static int
sfc_dev_promisc_disable(struct rte_eth_dev *dev)
{
int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_FALSE);
SFC_ASSERT(rc >= 0);
return -rc;
}
static int
sfc_dev_allmulti_enable(struct rte_eth_dev *dev)
{
int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_TRUE);
SFC_ASSERT(rc >= 0);
return -rc;
}
static int
sfc_dev_allmulti_disable(struct rte_eth_dev *dev)
{
int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_FALSE);
SFC_ASSERT(rc >= 0);
return -rc;
}
static int
sfc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
uint16_t nb_rx_desc, unsigned int socket_id,
const struct rte_eth_rxconf *rx_conf,
struct rte_mempool *mb_pool)
{
struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
int rc;
sfc_log_init(sa, "RxQ=%u nb_rx_desc=%u socket_id=%u",
rx_queue_id, nb_rx_desc, socket_id);
sfc_adapter_lock(sa);
rc = sfc_rx_qinit(sa, rx_queue_id, nb_rx_desc, socket_id,
rx_conf, mb_pool);
if (rc != 0)
goto fail_rx_qinit;
dev->data->rx_queues[rx_queue_id] = sas->rxq_info[rx_queue_id].dp;
sfc_adapter_unlock(sa);
return 0;
fail_rx_qinit:
sfc_adapter_unlock(sa);
SFC_ASSERT(rc > 0);
return -rc;
}
static void
sfc_rx_queue_release(void *queue)
{
struct sfc_dp_rxq *dp_rxq = queue;
struct sfc_rxq *rxq;
struct sfc_adapter *sa;
unsigned int sw_index;
if (dp_rxq == NULL)
return;
rxq = sfc_rxq_by_dp_rxq(dp_rxq);
sa = rxq->evq->sa;
sfc_adapter_lock(sa);
sw_index = dp_rxq->dpq.queue_id;
sfc_log_init(sa, "RxQ=%u", sw_index);
sfc_rx_qfini(sa, sw_index);
sfc_adapter_unlock(sa);
}
static int
sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
uint16_t nb_tx_desc, unsigned int socket_id,
const struct rte_eth_txconf *tx_conf)
{
struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
int rc;
sfc_log_init(sa, "TxQ = %u, nb_tx_desc = %u, socket_id = %u",
tx_queue_id, nb_tx_desc, socket_id);
sfc_adapter_lock(sa);
rc = sfc_tx_qinit(sa, tx_queue_id, nb_tx_desc, socket_id, tx_conf);
if (rc != 0)
goto fail_tx_qinit;
dev->data->tx_queues[tx_queue_id] = sas->txq_info[tx_queue_id].dp;
sfc_adapter_unlock(sa);
return 0;
fail_tx_qinit:
sfc_adapter_unlock(sa);
SFC_ASSERT(rc > 0);
return -rc;
}
static void
sfc_tx_queue_release(void *queue)
{
struct sfc_dp_txq *dp_txq = queue;
struct sfc_txq *txq;
unsigned int sw_index;
struct sfc_adapter *sa;
if (dp_txq == NULL)
return;
txq = sfc_txq_by_dp_txq(dp_txq);
sw_index = dp_txq->dpq.queue_id;
SFC_ASSERT(txq->evq != NULL);
sa = txq->evq->sa;
sfc_log_init(sa, "TxQ = %u", sw_index);
sfc_adapter_lock(sa);
sfc_tx_qfini(sa, sw_index);
sfc_adapter_unlock(sa);
}
/*
* Some statistics are computed as A - B where A and B each increase
* monotonically with some hardware counter(s) and the counters are read
* asynchronously.
*
* If packet X is counted in A, but not counted in B yet, computed value is
* greater than real.
*
* If packet X is not counted in A at the moment of reading the counter,
* but counted in B at the moment of reading the counter, computed value
* is less than real.
*
* However, counter which grows backward is worse evil than slightly wrong
* value. So, let's try to guarantee that it never happens except may be
* the case when the MAC stats are zeroed as a result of a NIC reset.
*/
static void
sfc_update_diff_stat(uint64_t *stat, uint64_t newval)
{
if ((int64_t)(newval - *stat) > 0 || newval == 0)
*stat = newval;
}
static int
sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct sfc_port *port = &sa->port;
uint64_t *mac_stats;
int ret;
sfc_adapter_lock(sa);
ret = sfc_port_update_mac_stats(sa, B_FALSE);
if (ret != 0)
goto unlock;
mac_stats = port->mac_stats_buf;
if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask,
EFX_MAC_VADAPTER_RX_UNICAST_PACKETS)) {
stats->ipackets =
mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS] +
mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS] +
mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS];
stats->opackets =
mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS] +
mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS] +
mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS];
stats->ibytes =
mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_BYTES] +
mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES] +
mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES];
stats->obytes =
mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_BYTES] +
mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES] +
mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES];
stats->imissed = mac_stats[EFX_MAC_VADAPTER_RX_BAD_PACKETS];
stats->oerrors = mac_stats[EFX_MAC_VADAPTER_TX_BAD_PACKETS];
/* CRC is included in these stats, but shouldn't be */
stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
stats->obytes -= stats->opackets * RTE_ETHER_CRC_LEN;
} else {
stats->opackets = mac_stats[EFX_MAC_TX_PKTS];
stats->ibytes = mac_stats[EFX_MAC_RX_OCTETS];
stats->obytes = mac_stats[EFX_MAC_TX_OCTETS];
/* CRC is included in these stats, but shouldn't be */
stats->ibytes -= mac_stats[EFX_MAC_RX_PKTS] * RTE_ETHER_CRC_LEN;
stats->obytes -= mac_stats[EFX_MAC_TX_PKTS] * RTE_ETHER_CRC_LEN;
/*
* Take into account stats which are whenever supported
* on EF10. If some stat is not supported by current
* firmware variant or HW revision, it is guaranteed
* to be zero in mac_stats.
*/
stats->imissed =
mac_stats[EFX_MAC_RX_NODESC_DROP_CNT] +
mac_stats[EFX_MAC_PM_TRUNC_BB_OVERFLOW] +
mac_stats[EFX_MAC_PM_DISCARD_BB_OVERFLOW] +
mac_stats[EFX_MAC_PM_TRUNC_VFIFO_FULL] +
mac_stats[EFX_MAC_PM_DISCARD_VFIFO_FULL] +
mac_stats[EFX_MAC_PM_TRUNC_QBB] +
mac_stats[EFX_MAC_PM_DISCARD_QBB] +
mac_stats[EFX_MAC_PM_DISCARD_MAPPING] +
mac_stats[EFX_MAC_RXDP_Q_DISABLED_PKTS] +
mac_stats[EFX_MAC_RXDP_DI_DROPPED_PKTS];
stats->ierrors =
mac_stats[EFX_MAC_RX_FCS_ERRORS] +
mac_stats[EFX_MAC_RX_ALIGN_ERRORS] +
mac_stats[EFX_MAC_RX_JABBER_PKTS];
/* no oerrors counters supported on EF10 */
/* Exclude missed, errors and pauses from Rx packets */
sfc_update_diff_stat(&port->ipackets,
mac_stats[EFX_MAC_RX_PKTS] -
mac_stats[EFX_MAC_RX_PAUSE_PKTS] -
stats->imissed - stats->ierrors);
stats->ipackets = port->ipackets;
}
unlock:
sfc_adapter_unlock(sa);
SFC_ASSERT(ret >= 0);
return -ret;
}
static int
sfc_stats_reset(struct rte_eth_dev *dev)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct sfc_port *port = &sa->port;
int rc;
sfc_adapter_lock(sa);
if (sa->state != SFC_ADAPTER_STARTED) {
/*
* The operation cannot be done if port is not started; it
* will be scheduled to be done during the next port start
*/
port->mac_stats_reset_pending = B_TRUE;
sfc_adapter_unlock(sa);
return 0;
}
rc = sfc_port_reset_mac_stats(sa);
if (rc != 0)
sfc_err(sa, "failed to reset statistics (rc = %d)", rc);
sfc_adapter_unlock(sa);
SFC_ASSERT(rc >= 0);
return -rc;
}
static int
sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
unsigned int xstats_count)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct sfc_port *port = &sa->port;
uint64_t *mac_stats;
int rc;
unsigned int i;
int nstats = 0;
sfc_adapter_lock(sa);
rc = sfc_port_update_mac_stats(sa, B_FALSE);
if (rc != 0) {
SFC_ASSERT(rc > 0);
nstats = -rc;
goto unlock;
}
mac_stats = port->mac_stats_buf;
for (i = 0; i < EFX_MAC_NSTATS; ++i) {
if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
if (xstats != NULL && nstats < (int)xstats_count) {
xstats[nstats].id = nstats;
xstats[nstats].value = mac_stats[i];
}
nstats++;
}
}
unlock:
sfc_adapter_unlock(sa);
return nstats;
}
static int
sfc_xstats_get_names(struct rte_eth_dev *dev,
struct rte_eth_xstat_name *xstats_names,
unsigned int xstats_count)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct sfc_port *port = &sa->port;
unsigned int i;
unsigned int nstats = 0;
for (i = 0; i < EFX_MAC_NSTATS; ++i) {
if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
if (xstats_names != NULL && nstats < xstats_count)
strlcpy(xstats_names[nstats].name,
efx_mac_stat_name(sa->nic, i),
sizeof(xstats_names[0].name));
nstats++;
}
}
return nstats;
}
static int
sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
uint64_t *values, unsigned int n)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct sfc_port *port = &sa->port;
uint64_t *mac_stats;
unsigned int i;
int ret;
int rc;
if (unlikely(ids == NULL || values == NULL))
return -EINVAL;
sfc_adapter_lock(sa);
rc = sfc_port_update_mac_stats(sa, B_FALSE);
if (rc != 0) {
SFC_ASSERT(rc > 0);
ret = -rc;
goto unlock;
}
mac_stats = port->mac_stats_buf;
SFC_ASSERT(port->mac_stats_nb_supported <=
RTE_DIM(port->mac_stats_by_id));
for (i = 0; i < n; i++) {
if (ids[i] < port->mac_stats_nb_supported) {
values[i] = mac_stats[port->mac_stats_by_id[ids[i]]];
} else {
ret = i;
goto unlock;
}
}
ret = n;
unlock:
sfc_adapter_unlock(sa);
return ret;
}
static int
sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
struct rte_eth_xstat_name *xstats_names,
const uint64_t *ids, unsigned int size)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct sfc_port *port = &sa->port;
unsigned int nb_supported;
unsigned int i;
if (unlikely(xstats_names == NULL && ids != NULL) ||
unlikely(xstats_names != NULL && ids == NULL))
return -EINVAL;
sfc_adapter_lock(sa);
if (unlikely(xstats_names == NULL && ids == NULL)) {
nb_supported = port->mac_stats_nb_supported;
sfc_adapter_unlock(sa);
return nb_supported;
}
SFC_ASSERT(port->mac_stats_nb_supported <=
RTE_DIM(port->mac_stats_by_id));
for (i = 0; i < size; i++) {
if (ids[i] < port->mac_stats_nb_supported) {
strlcpy(xstats_names[i].name,
efx_mac_stat_name(sa->nic,
port->mac_stats_by_id[ids[i]]),
sizeof(xstats_names[0].name));
} else {
sfc_adapter_unlock(sa);
return i;
}
}
sfc_adapter_unlock(sa);
return size;
}
static int
sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
unsigned int wanted_fc, link_fc;
memset(fc_conf, 0, sizeof(*fc_conf));
sfc_adapter_lock(sa);
if (sa->state == SFC_ADAPTER_STARTED)
efx_mac_fcntl_get(sa->nic, &wanted_fc, &link_fc);
else
link_fc = sa->port.flow_ctrl;
switch (link_fc) {
case 0:
fc_conf->mode = RTE_FC_NONE;
break;
case EFX_FCNTL_RESPOND:
fc_conf->mode = RTE_FC_RX_PAUSE;
break;
case EFX_FCNTL_GENERATE:
fc_conf->mode = RTE_FC_TX_PAUSE;
break;
case (EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE):
fc_conf->mode = RTE_FC_FULL;
break;
default:
sfc_err(sa, "%s: unexpected flow control value %#x",
__func__, link_fc);
}
fc_conf->autoneg = sa->port.flow_ctrl_autoneg;
sfc_adapter_unlock(sa);
return 0;
}
static int
sfc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
struct sfc_port *port = &sa->port;
unsigned int fcntl;
int rc;
if (fc_conf->high_water != 0 || fc_conf->low_water != 0 ||
fc_conf->pause_time != 0 || fc_conf->send_xon != 0 ||
fc_conf->mac_ctrl_frame_fwd != 0) {
sfc_err(sa, "unsupported flow control settings specified");
rc = EINVAL;
goto fail_inval;
}
switch (fc_conf->mode) {
case RTE_FC_NONE:
fcntl = 0;
break;
case RTE_FC_RX_PAUSE:
fcntl = EFX_FCNTL_RESPOND;
break;
case RTE_FC_TX_PAUSE:
fcntl = EFX_FCNTL_GENERATE;
break;
case RTE_FC_FULL:
fcntl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
break;
default:
rc = EINVAL;
goto fail_inval;
}
sfc_adapter_lock(sa);
if (sa->state == SFC_ADAPTER_STARTED) {
rc = efx_mac_fcntl_set(sa->nic, fcntl, fc_conf->autoneg);
if (rc != 0)
goto fail_mac_fcntl_set;
}
port->flow_ctrl = fcntl;
port->flow_ctrl_autoneg = fc_conf->autoneg;
sfc_adapter_unlock(sa);
return 0;
fail_mac_fcntl_set:
sfc_adapter_unlock(sa);
fail_inval:
SFC_ASSERT(rc > 0);
return -rc;
}
static int
sfc_check_scatter_on_all_rx_queues(struct sfc_adapter *sa, size_t pdu)
{
struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
boolean_t scatter_enabled;
const char *error;
unsigned int i;
for (i = 0; i < sas->rxq_count; i++) {
if ((sas->rxq_info[i].state & SFC_RXQ_INITIALIZED) == 0)
continue;
scatter_enabled = (sas->rxq_info[i].type_flags &
EFX_RXQ_FLAG_SCATTER);
if (!sfc_rx_check_scatter(pdu, sa->rxq_ctrl[i].buf_size,
encp->enc_rx_prefix_size,
scatter_enabled,
encp->enc_rx_scatter_max, &error)) {
sfc_err(sa, "MTU check for RxQ %u failed: %s", i,
error);
return EINVAL;
}
}
return 0;
}
static int
sfc_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
{
struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
size_t pdu = EFX_MAC_PDU(mtu);
size_t old_pdu;
int rc;
sfc_log_init(sa, "mtu=%u", mtu);
rc = EINVAL;
if (pdu < EFX_MAC_PDU_MIN) {
sfc_err(sa, "too small MTU %u (PDU size %u less than min %u)",
(unsigned int)mtu, (unsigned int)pdu,
EFX_MAC_PDU_MIN);
goto fail_inval;
}
if (pdu > EFX_MAC_PDU_MAX) {
sfc_err(sa, "too big MTU %u (PDU size %u greater than max %u)",
(unsigned int)mtu, (unsigned int)pdu,