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
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2022 Intel Corporation
*/
#include <ctype.h>
#include <stdalign.h>
#include <stdlib.h>
#include <pthread.h>
#include <rte_kvargs.h>
#include <rte_malloc.h>
#include "ethdev_driver.h"
#include "ethdev_private.h"
#include "rte_flow_driver.h"
/**
* A set of values to describe the possible states of a switch domain.
*/
enum rte_eth_switch_domain_state {
RTE_ETH_SWITCH_DOMAIN_UNUSED = 0,
RTE_ETH_SWITCH_DOMAIN_ALLOCATED
};
/**
* Array of switch domains available for allocation. Array is sized to
* RTE_MAX_ETHPORTS elements as there cannot be more active switch domains than
* ethdev ports in a single process.
*/
static struct rte_eth_dev_switch {
enum rte_eth_switch_domain_state state;
} eth_dev_switch_domains[RTE_MAX_ETHPORTS];
static struct rte_eth_dev *
eth_dev_allocated(const char *name)
{
uint16_t i;
RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >= UINT16_MAX);
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
if (rte_eth_devices[i].data != NULL &&
strcmp(rte_eth_devices[i].data->name, name) == 0)
return &rte_eth_devices[i];
}
return NULL;
}
static uint16_t
eth_dev_find_free_port(void)
__rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock())
{
uint16_t i;
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
/* Using shared name field to find a free port. */
if (eth_dev_shared_data->data[i].name[0] == '\0') {
RTE_ASSERT(rte_eth_devices[i].state ==
RTE_ETH_DEV_UNUSED);
return i;
}
}
return RTE_MAX_ETHPORTS;
}
static struct rte_eth_dev *
eth_dev_get(uint16_t port_id)
__rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock())
{
struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
eth_dev->data = ð_dev_shared_data->data[port_id];
return eth_dev;
}
struct rte_eth_dev *
rte_eth_dev_allocate(const char *name)
{
uint16_t port_id;
struct rte_eth_dev *eth_dev = NULL;
size_t name_len;
name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN);
if (name_len == 0) {
RTE_ETHDEV_LOG_LINE(ERR, "Zero length Ethernet device name");
return NULL;
}
if (name_len >= RTE_ETH_NAME_MAX_LEN) {
RTE_ETHDEV_LOG_LINE(ERR, "Ethernet device name is too long");
return NULL;
}
/* Synchronize port creation between primary and secondary processes. */
rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
if (eth_dev_shared_data_prepare() == NULL)
goto unlock;
if (eth_dev_allocated(name) != NULL) {
RTE_ETHDEV_LOG_LINE(ERR,
"Ethernet device with name %s already allocated",
name);
goto unlock;
}
port_id = eth_dev_find_free_port();
if (port_id == RTE_MAX_ETHPORTS) {
RTE_ETHDEV_LOG_LINE(ERR,
"Reached maximum number of Ethernet ports");
goto unlock;
}
eth_dev = eth_dev_get(port_id);
eth_dev->flow_fp_ops = &rte_flow_fp_default_ops;
strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
eth_dev->data->port_id = port_id;
eth_dev->data->backer_port_id = RTE_MAX_ETHPORTS;
eth_dev->data->mtu = RTE_ETHER_MTU;
pthread_mutex_init(ð_dev->data->flow_ops_mutex, NULL);
RTE_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
eth_dev_shared_data->allocated_ports++;
unlock:
rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
return eth_dev;
}
struct rte_eth_dev *
rte_eth_dev_allocated(const char *name)
{
struct rte_eth_dev *ethdev;
rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
if (eth_dev_shared_data_prepare() != NULL)
ethdev = eth_dev_allocated(name);
else
ethdev = NULL;
rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
return ethdev;
}
/*
* Attach to a port already registered by the primary process, which
* makes sure that the same device would have the same port ID both
* in the primary and secondary process.
*/
struct rte_eth_dev *
rte_eth_dev_attach_secondary(const char *name)
{
uint16_t i;
struct rte_eth_dev *eth_dev = NULL;
/* Synchronize port attachment to primary port creation and release. */
rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
if (eth_dev_shared_data_prepare() == NULL)
goto unlock;
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
if (strcmp(eth_dev_shared_data->data[i].name, name) == 0)
break;
}
if (i == RTE_MAX_ETHPORTS) {
RTE_ETHDEV_LOG_LINE(ERR,
"Device %s is not driven by the primary process",
name);
} else {
eth_dev = eth_dev_get(i);
RTE_ASSERT(eth_dev->data->port_id == i);
}
unlock:
rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
return eth_dev;
}
int
rte_eth_dev_callback_process(struct rte_eth_dev *dev,
enum rte_eth_event_type event, void *ret_param)
{
struct rte_eth_dev_callback *cb_lst;
struct rte_eth_dev_callback dev_cb;
int rc = 0;
rte_spinlock_lock(ð_dev_cb_lock);
TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
if (cb_lst->cb_fn == NULL || cb_lst->event != event)
continue;
dev_cb = *cb_lst;
cb_lst->active = 1;
if (ret_param != NULL)
dev_cb.ret_param = ret_param;
rte_spinlock_unlock(ð_dev_cb_lock);
rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
dev_cb.cb_arg, dev_cb.ret_param);
rte_spinlock_lock(ð_dev_cb_lock);
cb_lst->active = 0;
}
rte_spinlock_unlock(ð_dev_cb_lock);
return rc;
}
void
rte_eth_dev_probing_finish(struct rte_eth_dev *dev)
{
if (dev == NULL)
return;
/*
* for secondary process, at that point we expect device
* to be already 'usable', so shared data and all function pointers
* for fast-path devops have to be setup properly inside rte_eth_dev.
*/
if (rte_eal_process_type() == RTE_PROC_SECONDARY)
eth_dev_fp_ops_setup(rte_eth_fp_ops + dev->data->port_id, dev);
rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL);
dev->state = RTE_ETH_DEV_ATTACHED;
}
int
rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
{
int ret;
if (eth_dev == NULL)
return -EINVAL;
rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
if (eth_dev_shared_data_prepare() == NULL)
ret = -EINVAL;
else
ret = 0;
rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
if (ret != 0)
return ret;
if (eth_dev->state != RTE_ETH_DEV_UNUSED)
rte_eth_dev_callback_process(eth_dev,
RTE_ETH_EVENT_DESTROY, NULL);
eth_dev_fp_ops_reset(rte_eth_fp_ops + eth_dev->data->port_id);
eth_dev->flow_fp_ops = &rte_flow_fp_default_ops;
rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
eth_dev->state = RTE_ETH_DEV_UNUSED;
eth_dev->device = NULL;
eth_dev->process_private = NULL;
eth_dev->intr_handle = NULL;
eth_dev->rx_pkt_burst = NULL;
eth_dev->tx_pkt_burst = NULL;
eth_dev->tx_pkt_prepare = NULL;
eth_dev->rx_queue_count = NULL;
eth_dev->rx_descriptor_status = NULL;
eth_dev->tx_descriptor_status = NULL;
eth_dev->dev_ops = NULL;
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
rte_free(eth_dev->data->rx_queues);
rte_free(eth_dev->data->tx_queues);
rte_free(eth_dev->data->mac_addrs);
rte_free(eth_dev->data->hash_mac_addrs);
rte_free(eth_dev->data->dev_private);
pthread_mutex_destroy(ð_dev->data->flow_ops_mutex);
memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
eth_dev->data = NULL;
eth_dev_shared_data->allocated_ports--;
eth_dev_shared_data_release();
}
rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
return 0;
}
int
rte_eth_dev_create(struct rte_device *device, const char *name,
size_t priv_data_size,
ethdev_bus_specific_init ethdev_bus_specific_init,
void *bus_init_params,
ethdev_init_t ethdev_init, void *init_params)
{
struct rte_eth_dev *ethdev;
int retval;
if (*ethdev_init == NULL)
return -EINVAL;
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
ethdev = rte_eth_dev_allocate(name);
if (!ethdev)
return -ENODEV;
if (priv_data_size) {
/* try alloc private data on device-local node. */
ethdev->data->dev_private = rte_zmalloc_socket(
name, priv_data_size, RTE_CACHE_LINE_SIZE,
device->numa_node);
/* fall back to alloc on any socket on failure */
if (ethdev->data->dev_private == NULL) {
ethdev->data->dev_private = rte_zmalloc(name,
priv_data_size, RTE_CACHE_LINE_SIZE);
if (ethdev->data->dev_private == NULL) {
RTE_ETHDEV_LOG_LINE(ERR, "failed to allocate private data");
retval = -ENOMEM;
goto probe_failed;
}
/* got memory, but not local, so issue warning */
RTE_ETHDEV_LOG_LINE(WARNING,
"Private data for ethdev '%s' not allocated on local NUMA node %d",
device->name, device->numa_node);
}
}
} else {
ethdev = rte_eth_dev_attach_secondary(name);
if (!ethdev) {
RTE_ETHDEV_LOG_LINE(ERR,
"secondary process attach failed, ethdev doesn't exist");
return -ENODEV;
}
}
ethdev->device = device;
if (ethdev_bus_specific_init) {
retval = ethdev_bus_specific_init(ethdev, bus_init_params);
if (retval) {
RTE_ETHDEV_LOG_LINE(ERR,
"ethdev bus specific initialisation failed");
goto probe_failed;
}
}
retval = ethdev_init(ethdev, init_params);
if (retval) {
RTE_ETHDEV_LOG_LINE(ERR, "ethdev initialisation failed");
goto probe_failed;
}
rte_eth_dev_probing_finish(ethdev);
return retval;
probe_failed:
rte_eth_dev_release_port(ethdev);
return retval;
}
int
rte_eth_dev_destroy(struct rte_eth_dev *ethdev,
ethdev_uninit_t ethdev_uninit)
{
int ret;
ethdev = rte_eth_dev_allocated(ethdev->data->name);
if (!ethdev)
return -ENODEV;
if (*ethdev_uninit == NULL)
return -EINVAL;
ret = ethdev_uninit(ethdev);
if (ret)
return ret;
return rte_eth_dev_release_port(ethdev);
}
struct rte_eth_dev *
rte_eth_dev_get_by_name(const char *name)
{
uint16_t pid;
if (rte_eth_dev_get_port_by_name(name, &pid))
return NULL;
return &rte_eth_devices[pid];
}
int
rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
{
if (dev->data->rx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_HAIRPIN)
return 1;
return 0;
}
int
rte_eth_dev_is_tx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id)
{
if (dev->data->tx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_HAIRPIN)
return 1;
return 0;
}
void
rte_eth_dev_internal_reset(struct rte_eth_dev *dev)
{
if (dev->data->dev_started) {
RTE_ETHDEV_LOG_LINE(ERR, "Port %u must be stopped to allow reset",
dev->data->port_id);
return;
}
eth_dev_rx_queue_config(dev, 0);
eth_dev_tx_queue_config(dev, 0);
memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
}
static int
eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
{
int state;
struct rte_kvargs_pair *pair;
char *letter;
arglist->str = strdup(str_in);
if (arglist->str == NULL)
return -ENOMEM;
letter = arglist->str;
state = 0;
arglist->count = 0;
pair = &arglist->pairs[0];
while (1) {
switch (state) {
case 0: /* Initial */
if (*letter == '=')
return -EINVAL;
else if (*letter == '\0')
return 0;
state = 1;
pair->key = letter;
/* fallthrough */
case 1: /* Parsing key */
if (*letter == '=') {
*letter = '\0';
pair->value = letter + 1;
state = 2;
} else if (*letter == ',' || *letter == '\0')
return -EINVAL;
break;
case 2: /* Parsing value */
if (*letter == '[')
state = 3;
else if (*letter == ',') {
*letter = '\0';
arglist->count++;
pair = &arglist->pairs[arglist->count];
state = 0;
} else if (*letter == '\0') {
letter--;
arglist->count++;
pair = &arglist->pairs[arglist->count];
state = 0;
}
break;
case 3: /* Parsing list */
if (*letter == ']') {
/* For devargs having singles lists move to state 2 once letter
* becomes ']' so each can be considered as different pair key
* value. But in nested lists case e.g. multiple representors
* case i.e. [pf[0-3],pfvf[3,4-6]], complete nested list should
* be considered as one pair value, hence checking if end of outer
* list ']' is reached else stay on state 3.
*/
if ((strcmp("representor", pair->key) == 0) &&
(*(letter + 1) != '\0' && *(letter + 2) != '\0' &&
*(letter + 3) != '\0') &&
((*(letter + 2) == 'p' && *(letter + 3) == 'f') ||
(*(letter + 2) == 'v' && *(letter + 3) == 'f') ||
(*(letter + 2) == 's' && *(letter + 3) == 'f') ||
(*(letter + 2) == 'c' && isdigit(*(letter + 3))) ||
(*(letter + 2) == '[' && isdigit(*(letter + 3))) ||
(isdigit(*(letter + 2)))))
state = 3;
else
state = 2;
} else if (*letter == '\0') {
return -EINVAL;
}
break;
}
letter++;
}
}
static int
devargs_parse_representor_ports(struct rte_eth_devargs *eth_devargs, char
*da_val, unsigned int da_idx, unsigned int nb_da)
{
struct rte_eth_devargs *eth_da;
int result = 0;
if (da_idx + 1 > nb_da) {
RTE_ETHDEV_LOG_LINE(ERR, "Devargs parsed %d > max array size %d",
da_idx + 1, nb_da);
result = -1;
goto parse_cleanup;
}
eth_da = ð_devargs[da_idx];
memset(eth_da, 0, sizeof(*eth_da));
RTE_ETHDEV_LOG_LINE(DEBUG, " Devargs idx %d value %s", da_idx, da_val);
result = rte_eth_devargs_parse_representor_ports(da_val, eth_da);
parse_cleanup:
return result;
}
static int
eth_dev_tokenise_representor_list(char *p_val, struct rte_eth_devargs *eth_devargs,
unsigned int nb_da)
{
char da_val[BUFSIZ], str[BUFSIZ];
bool is_rep_portid_list = true;
unsigned int devargs = 0;
int result = 0, len = 0;
int i = 0, j = 0;
char *pos;
pos = p_val;
/* Length of consolidated list */
while (*pos++ != '\0') {
len++;
if (isalpha(*pos))
is_rep_portid_list = false;
}
/* List of representor portIDs i.e.[1,2,3] should be considered as single representor case*/
if (is_rep_portid_list) {
result = devargs_parse_representor_ports(eth_devargs, p_val, 0, 1);
if (result < 0)
return result;
devargs++;
return devargs;
}
memset(str, 0, BUFSIZ);
memset(da_val, 0, BUFSIZ);
/* Remove the exterior [] of the consolidated list */
strncpy(str, &p_val[1], len - 2);
while (1) {
if (str[i] == '\0') {
if (da_val[0] != '\0') {
result = devargs_parse_representor_ports(eth_devargs, da_val,
devargs, nb_da);
if (result < 0)
goto parse_cleanup;
devargs++;
}
break;
}
if (str[i] == ',' || str[i] == '[') {
if (str[i] == ',') {
if (da_val[0] != '\0') {
da_val[j + 1] = '\0';
result = devargs_parse_representor_ports(eth_devargs,
da_val, devargs,
nb_da);
if (result < 0)
goto parse_cleanup;
devargs++;
j = 0;
memset(da_val, 0, BUFSIZ);
}
}
if (str[i] == '[') {
while (str[i] != ']' || isalpha(str[i + 1])) {
da_val[j] = str[i];
j++;
i++;
}
da_val[j] = ']';
da_val[j + 1] = '\0';
result = devargs_parse_representor_ports(eth_devargs, da_val,
devargs, nb_da);
if (result < 0)
goto parse_cleanup;
devargs++;
j = 0;
memset(da_val, 0, BUFSIZ);
}
} else {
da_val[j] = str[i];
j++;
}
i++;
}
result = devargs;
parse_cleanup:
return result;
}
int
rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_devargs,
unsigned int nb_da)
{
struct rte_kvargs_pair *pair;
struct rte_kvargs args;
bool dup_rep = false;
int devargs = 0;
unsigned int i;
int result = 0;
memset(eth_devargs, 0, nb_da * sizeof(*eth_devargs));
result = eth_dev_devargs_tokenise(&args, dargs);
if (result < 0)
goto parse_cleanup;
for (i = 0; i < args.count; i++) {
pair = &args.pairs[i];
if (strcmp("representor", pair->key) == 0) {
if (dup_rep) {
RTE_ETHDEV_LOG_LINE(ERR, "Duplicated representor key: %s",
pair->value);
result = -1;
goto parse_cleanup;
}
RTE_ETHDEV_LOG_LINE(DEBUG, "Devarg pattern: %s", pair->value);
if (pair->value[0] == '[') {
/* Multiple representor list case */
devargs = eth_dev_tokenise_representor_list(pair->value,
eth_devargs, nb_da);
if (devargs < 0)
goto parse_cleanup;
} else {
/* Single representor case */
devargs = devargs_parse_representor_ports(eth_devargs, pair->value,
0, 1);
if (devargs < 0)
goto parse_cleanup;
devargs++;
}
dup_rep = true;
}
}
RTE_ETHDEV_LOG_LINE(DEBUG, "Total devargs parsed %d", devargs);
result = devargs;
parse_cleanup:
free(args.str);
return result;
}
static inline int
eth_dev_dma_mzone_name(char *name, size_t len, uint16_t port_id, uint16_t queue_id,
const char *ring_name)
{
return snprintf(name, len, "eth_p%d_q%d_%s",
port_id, queue_id, ring_name);
}
int
rte_eth_dma_zone_free(const struct rte_eth_dev *dev, const char *ring_name,
uint16_t queue_id)
{
char z_name[RTE_MEMZONE_NAMESIZE];
const struct rte_memzone *mz;
int rc = 0;
rc = eth_dev_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id,
queue_id, ring_name);
if (rc >= RTE_MEMZONE_NAMESIZE) {
RTE_ETHDEV_LOG_LINE(ERR, "ring name too long");
return -ENAMETOOLONG;
}
mz = rte_memzone_lookup(z_name);
if (mz)
rc = rte_memzone_free(mz);
else
rc = -ENOENT;
return rc;
}
const struct rte_memzone *
rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
uint16_t queue_id, size_t size, unsigned int align,
int socket_id)
{
char z_name[RTE_MEMZONE_NAMESIZE];
const struct rte_memzone *mz;
int rc;
rc = eth_dev_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id,
queue_id, ring_name);
if (rc >= RTE_MEMZONE_NAMESIZE) {
RTE_ETHDEV_LOG_LINE(ERR, "ring name too long");
rte_errno = ENAMETOOLONG;
return NULL;
}
mz = rte_memzone_lookup(z_name);
if (mz) {
if ((socket_id != SOCKET_ID_ANY && socket_id != mz->socket_id) ||
size > mz->len ||
((uintptr_t)mz->addr & (align - 1)) != 0) {
RTE_ETHDEV_LOG_LINE(ERR,
"memzone %s does not justify the requested attributes",
mz->name);
return NULL;
}
return mz;
}
return rte_memzone_reserve_aligned(z_name, size, socket_id,
RTE_MEMZONE_IOVA_CONTIG, align);
}
int
rte_eth_hairpin_queue_peer_bind(uint16_t cur_port, uint16_t cur_queue,
struct rte_hairpin_peer_info *peer_info,
uint32_t direction)
{
struct rte_eth_dev *dev;
if (peer_info == NULL)
return -EINVAL;
/* No need to check the validity again. */
dev = &rte_eth_devices[cur_port];
if (*dev->dev_ops->hairpin_queue_peer_bind == NULL)
return -ENOTSUP;
return (*dev->dev_ops->hairpin_queue_peer_bind)(dev, cur_queue,
peer_info, direction);
}
int
rte_eth_hairpin_queue_peer_unbind(uint16_t cur_port, uint16_t cur_queue,
uint32_t direction)
{
struct rte_eth_dev *dev;
/* No need to check the validity again. */
dev = &rte_eth_devices[cur_port];
if (*dev->dev_ops->hairpin_queue_peer_unbind == NULL)
return -ENOTSUP;
return (*dev->dev_ops->hairpin_queue_peer_unbind)(dev, cur_queue,
direction);
}
int
rte_eth_hairpin_queue_peer_update(uint16_t peer_port, uint16_t peer_queue,
struct rte_hairpin_peer_info *cur_info,
struct rte_hairpin_peer_info *peer_info,
uint32_t direction)
{
struct rte_eth_dev *dev;
/* Current queue information is not mandatory. */
if (peer_info == NULL)
return -EINVAL;
/* No need to check the validity again. */
dev = &rte_eth_devices[peer_port];
if (*dev->dev_ops->hairpin_queue_peer_update == NULL)
return -ENOTSUP;
return (*dev->dev_ops->hairpin_queue_peer_update)(dev, peer_queue,
cur_info, peer_info, direction);
}
int
rte_eth_ip_reassembly_dynfield_register(int *field_offset, int *flag_offset)
{
static const struct rte_mbuf_dynfield field_desc = {
.name = RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME,
.size = sizeof(rte_eth_ip_reassembly_dynfield_t),
.align = alignof(rte_eth_ip_reassembly_dynfield_t),
};
static const struct rte_mbuf_dynflag ip_reassembly_dynflag = {
.name = RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME,
};
int offset;
offset = rte_mbuf_dynfield_register(&field_desc);
if (offset < 0)
return -1;
if (field_offset != NULL)
*field_offset = offset;
offset = rte_mbuf_dynflag_register(&ip_reassembly_dynflag);
if (offset < 0)
return -1;
if (flag_offset != NULL)
*flag_offset = offset;
return 0;
}
uint16_t
rte_eth_pkt_burst_dummy(void *queue __rte_unused,
struct rte_mbuf **pkts __rte_unused,
uint16_t nb_pkts __rte_unused)
{
return 0;
}
int
rte_eth_representor_id_get(uint16_t port_id,
enum rte_eth_representor_type type,
int controller, int pf, int representor_port,
uint16_t *repr_id)
{
int ret, n, count;
uint32_t i;
struct rte_eth_representor_info *info = NULL;
size_t size;
if (type == RTE_ETH_REPRESENTOR_NONE)
return 0;
if (repr_id == NULL)
return -EINVAL;
/* Get PMD representor range info. */
ret = rte_eth_representor_info_get(port_id, NULL);
if (ret == -ENOTSUP && type == RTE_ETH_REPRESENTOR_VF &&
controller == -1 && pf == -1) {
/* Direct mapping for legacy VF representor. */
*repr_id = representor_port;
return 0;
} else if (ret < 0) {
return ret;
}
n = ret;
size = sizeof(*info) + n * sizeof(info->ranges[0]);
info = calloc(1, size);
if (info == NULL)
return -ENOMEM;
info->nb_ranges_alloc = n;
ret = rte_eth_representor_info_get(port_id, info);
if (ret < 0)
goto out;
/* Default controller and pf to caller. */
if (controller == -1)
controller = info->controller;
if (pf == -1)
pf = info->pf;
/* Locate representor ID. */
ret = -ENOENT;
for (i = 0; i < info->nb_ranges; ++i) {
if (info->ranges[i].type != type)
continue;
if (info->ranges[i].controller != controller)
continue;
if (info->ranges[i].id_end < info->ranges[i].id_base) {
RTE_ETHDEV_LOG_LINE(WARNING, "Port %hu invalid representor ID Range %u - %u, entry %d",
port_id, info->ranges[i].id_base,
info->ranges[i].id_end, i);
continue;
}
count = info->ranges[i].id_end - info->ranges[i].id_base + 1;
switch (info->ranges[i].type) {
case RTE_ETH_REPRESENTOR_PF:
if (pf < info->ranges[i].pf ||
pf >= info->ranges[i].pf + count)
continue;
*repr_id = info->ranges[i].id_base +
(pf - info->ranges[i].pf);
ret = 0;
goto out;
case RTE_ETH_REPRESENTOR_VF:
if (info->ranges[i].pf != pf)
continue;
if (representor_port < info->ranges[i].vf ||
representor_port >= info->ranges[i].vf + count)
continue;
*repr_id = info->ranges[i].id_base +
(representor_port - info->ranges[i].vf);
ret = 0;
goto out;
case RTE_ETH_REPRESENTOR_SF:
if (info->ranges[i].pf != pf)
continue;
if (representor_port < info->ranges[i].sf ||
representor_port >= info->ranges[i].sf + count)
continue;
*repr_id = info->ranges[i].id_base +
(representor_port - info->ranges[i].sf);
ret = 0;
goto out;
default:
break;
}
}
out:
free(info);
return ret;
}
int
rte_eth_switch_domain_alloc(uint16_t *domain_id)
{
uint16_t i;
*domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
if (eth_dev_switch_domains[i].state ==
RTE_ETH_SWITCH_DOMAIN_UNUSED) {
eth_dev_switch_domains[i].state =
RTE_ETH_SWITCH_DOMAIN_ALLOCATED;
*domain_id = i;
return 0;
}
}
return -ENOSPC;
}
int
rte_eth_switch_domain_free(uint16_t domain_id)
{
if (domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID ||
domain_id >= RTE_MAX_ETHPORTS)
return -EINVAL;
if (eth_dev_switch_domains[domain_id].state !=
RTE_ETH_SWITCH_DOMAIN_ALLOCATED)
return -EINVAL;
eth_dev_switch_domains[domain_id].state = RTE_ETH_SWITCH_DOMAIN_UNUSED;
return 0;
}
uint64_t
rte_eth_get_restore_flags(struct rte_eth_dev *dev, enum rte_eth_dev_operation op)
{
if (dev->dev_ops->get_restore_flags != NULL)
return dev->dev_ops->get_restore_flags(dev, op);
else
return RTE_ETH_RESTORE_ALL;
}
|