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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (C) 2020 Marvell International Ltd.
*/
#include <rte_bitmap.h>
#include <rte_ethdev.h>
#include <rte_eventdev.h>
#include <rte_event_eth_rx_adapter.h>
#include <rte_event_eth_tx_adapter.h>
#include <rte_malloc.h>
#include <stdbool.h>
#include "event_helper.h"
static volatile bool eth_core_running;
static int
eh_get_enabled_cores(struct rte_bitmap *eth_core_mask)
{
int i, count = 0;
RTE_LCORE_FOREACH(i) {
/* Check if this core is enabled in core mask*/
if (rte_bitmap_get(eth_core_mask, i)) {
/* Found enabled core */
count++;
}
}
return count;
}
static inline unsigned int
eh_get_next_eth_core(struct eventmode_conf *em_conf)
{
static unsigned int prev_core = -1;
unsigned int next_core;
/*
* Make sure we have at least one eth core running, else the following
* logic would lead to an infinite loop.
*/
if (eh_get_enabled_cores(em_conf->eth_core_mask) == 0) {
EH_LOG_ERR("No enabled eth core found");
return RTE_MAX_LCORE;
}
/* Only some cores are marked as eth cores, skip others */
do {
/* Get the next core */
next_core = rte_get_next_lcore(prev_core, 0, 1);
/* Check if we have reached max lcores */
if (next_core == RTE_MAX_LCORE)
return next_core;
/* Update prev_core */
prev_core = next_core;
} while (!(rte_bitmap_get(em_conf->eth_core_mask, next_core)));
return next_core;
}
static inline unsigned int
eh_get_next_active_core(struct eventmode_conf *em_conf, unsigned int prev_core)
{
unsigned int next_core;
/* Get next active core skipping cores reserved as eth cores */
do {
/* Get the next core */
next_core = rte_get_next_lcore(prev_core, 0, 0);
/* Check if we have reached max lcores */
if (next_core == RTE_MAX_LCORE)
return next_core;
prev_core = next_core;
} while (rte_bitmap_get(em_conf->eth_core_mask, next_core));
return next_core;
}
static struct eventdev_params *
eh_get_eventdev_params(struct eventmode_conf *em_conf, uint8_t eventdev_id)
{
int i;
for (i = 0; i < em_conf->nb_eventdev; i++) {
if (em_conf->eventdev_config[i].eventdev_id == eventdev_id)
break;
}
/* No match */
if (i == em_conf->nb_eventdev)
return NULL;
return &(em_conf->eventdev_config[i]);
}
static inline bool
eh_dev_has_rx_internal_port(uint8_t eventdev_id)
{
bool flag = true;
int j, ret;
RTE_ETH_FOREACH_DEV(j) {
uint32_t caps = 0;
ret = rte_event_eth_rx_adapter_caps_get(eventdev_id, j, &caps);
if (ret < 0)
return false;
if (!(caps & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT))
flag = false;
}
return flag;
}
static inline bool
eh_dev_has_tx_internal_port(uint8_t eventdev_id)
{
bool flag = true;
int j, ret;
RTE_ETH_FOREACH_DEV(j) {
uint32_t caps = 0;
ret = rte_event_eth_tx_adapter_caps_get(eventdev_id, j, &caps);
if (ret < 0)
return false;
if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
flag = false;
}
return flag;
}
static inline bool
eh_dev_has_burst_mode(uint8_t dev_id)
{
struct rte_event_dev_info dev_info;
rte_event_dev_info_get(dev_id, &dev_info);
return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) ?
true : false;
}
static int
eh_set_default_conf_eventdev(struct eventmode_conf *em_conf)
{
int lcore_count, nb_eventdev, nb_eth_dev, ret;
struct eventdev_params *eventdev_config;
struct rte_event_dev_info dev_info;
/* Get the number of event devices */
nb_eventdev = rte_event_dev_count();
if (nb_eventdev == 0) {
EH_LOG_ERR("No event devices detected");
return -EINVAL;
}
if (nb_eventdev != 1) {
EH_LOG_ERR("Event mode does not support multiple event devices. "
"Please provide only one event device.");
return -EINVAL;
}
/* Get the number of eth devs */
nb_eth_dev = rte_eth_dev_count_avail();
if (nb_eth_dev == 0) {
EH_LOG_ERR("No eth devices detected");
return -EINVAL;
}
/* Get the number of lcores */
lcore_count = rte_lcore_count();
/* Read event device info */
ret = rte_event_dev_info_get(0, &dev_info);
if (ret < 0) {
EH_LOG_ERR("Failed to read event device info %d", ret);
return ret;
}
/* Check if enough ports are available */
if (dev_info.max_event_ports < 2) {
EH_LOG_ERR("Not enough event ports available");
return -EINVAL;
}
/* Get the first event dev conf */
eventdev_config = &(em_conf->eventdev_config[0]);
/* Save number of queues & ports available */
eventdev_config->eventdev_id = 0;
eventdev_config->nb_eventqueue = dev_info.max_event_queues;
eventdev_config->nb_eventport = dev_info.max_event_ports;
eventdev_config->ev_queue_mode = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
/* Check if there are more queues than required */
if (eventdev_config->nb_eventqueue > nb_eth_dev + 1) {
/* One queue is reserved for Tx */
eventdev_config->nb_eventqueue = nb_eth_dev + 1;
}
/* Check if there are more ports than required */
if (eventdev_config->nb_eventport > lcore_count) {
/* One port per lcore is enough */
eventdev_config->nb_eventport = lcore_count;
}
/* Update the number of event devices */
em_conf->nb_eventdev++;
return 0;
}
static void
eh_do_capability_check(struct eventmode_conf *em_conf)
{
struct eventdev_params *eventdev_config;
int all_internal_ports = 1;
uint32_t eventdev_id;
int i;
for (i = 0; i < em_conf->nb_eventdev; i++) {
/* Get the event dev conf */
eventdev_config = &(em_conf->eventdev_config[i]);
eventdev_id = eventdev_config->eventdev_id;
/* Check if event device has internal port for Rx & Tx */
if (eh_dev_has_rx_internal_port(eventdev_id) &&
eh_dev_has_tx_internal_port(eventdev_id)) {
eventdev_config->all_internal_ports = 1;
} else {
all_internal_ports = 0;
}
}
/*
* If Rx & Tx internal ports are supported by all event devices then
* eth cores won't be required. Override the eth core mask requested
* and decrement number of event queues by one as it won't be needed
* for Tx.
*/
if (all_internal_ports) {
rte_bitmap_reset(em_conf->eth_core_mask);
for (i = 0; i < em_conf->nb_eventdev; i++)
em_conf->eventdev_config[i].nb_eventqueue--;
}
}
static int
eh_set_default_conf_link(struct eventmode_conf *em_conf)
{
struct eventdev_params *eventdev_config;
struct eh_event_link_info *link;
unsigned int lcore_id = -1;
int i, link_index;
/*
* Create a 1:1 mapping from event ports to cores. If the number
* of event ports is lesser than the cores, some cores won't
* execute worker. If there are more event ports, then some ports
* won't be used.
*
*/
/*
* The event queue-port mapping is done according to the link. Since
* we are falling back to the default link config, enabling
* "all_ev_queue_to_ev_port" mode flag. This will map all queues
* to the port.
*/
em_conf->ext_params.all_ev_queue_to_ev_port = 1;
/* Get first event dev conf */
eventdev_config = &(em_conf->eventdev_config[0]);
/* Loop through the ports */
for (i = 0; i < eventdev_config->nb_eventport; i++) {
/* Get next active core id */
lcore_id = eh_get_next_active_core(em_conf,
lcore_id);
if (lcore_id == RTE_MAX_LCORE) {
/* Reached max cores */
return 0;
}
/* Save the current combination as one link */
/* Get the index */
link_index = em_conf->nb_link;
/* Get the corresponding link */
link = &(em_conf->link[link_index]);
/* Save link */
link->eventdev_id = eventdev_config->eventdev_id;
link->event_port_id = i;
link->lcore_id = lcore_id;
/*
* Don't set eventq_id as by default all queues
* need to be mapped to the port, which is controlled
* by the operating mode.
*/
/* Update number of links */
em_conf->nb_link++;
}
return 0;
}
static int
eh_set_default_conf_rx_adapter(struct eventmode_conf *em_conf)
{
struct rx_adapter_connection_info *conn;
struct eventdev_params *eventdev_config;
struct rx_adapter_conf *adapter;
bool rx_internal_port = true;
bool single_ev_queue = false;
int nb_eventqueue;
uint32_t caps = 0;
int eventdev_id;
int nb_eth_dev;
int adapter_id;
int conn_id;
int ret;
int i;
/* Create one adapter with eth queues mapped to event queue(s) */
if (em_conf->nb_eventdev == 0) {
EH_LOG_ERR("No event devs registered");
return -EINVAL;
}
/* Get the number of eth devs */
nb_eth_dev = rte_eth_dev_count_avail();
/* Use the first event dev */
eventdev_config = &(em_conf->eventdev_config[0]);
/* Get eventdev ID */
eventdev_id = eventdev_config->eventdev_id;
adapter_id = 0;
/* Get adapter conf */
adapter = &(em_conf->rx_adapter[adapter_id]);
/* Set adapter conf */
adapter->eventdev_id = eventdev_id;
adapter->adapter_id = adapter_id;
/*
* If event device does not have internal ports for passing
* packets then reserved one queue for Tx path
*/
nb_eventqueue = eventdev_config->all_internal_ports ?
eventdev_config->nb_eventqueue :
eventdev_config->nb_eventqueue - 1;
/*
* Map all queues of eth device (port) to an event queue. If there
* are more event queues than eth ports then create 1:1 mapping.
* Otherwise map all eth ports to a single event queue.
*/
if (nb_eth_dev > nb_eventqueue)
single_ev_queue = true;
for (i = 0; i < nb_eth_dev; i++) {
/* Use only the ports enabled */
if ((em_conf->eth_portmask & (1 << i)) == 0)
continue;
/* Get the connection id */
conn_id = adapter->nb_connections;
/* Get the connection */
conn = &(adapter->conn[conn_id]);
/* Set mapping between eth ports & event queues*/
conn->ethdev_id = i;
conn->eventq_id = single_ev_queue ? 0 : i;
/* Add all eth queues eth port to event queue */
conn->ethdev_rx_qid = -1;
/* Get Rx adapter capabilities */
ret = rte_event_eth_rx_adapter_caps_get(eventdev_id, i, &caps);
if (ret < 0) {
EH_LOG_ERR("Failed to get event device %d eth rx adapter"
" capabilities for port %d", eventdev_id, i);
return ret;
}
if (!(caps & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT))
rx_internal_port = false;
/* Update no of connections */
adapter->nb_connections++;
}
if (rx_internal_port) {
/* Rx core is not required */
adapter->rx_core_id = -1;
} else {
/* Rx core is required */
adapter->rx_core_id = eh_get_next_eth_core(em_conf);
}
/* We have setup one adapter */
em_conf->nb_rx_adapter = 1;
return 0;
}
static int
eh_set_default_conf_tx_adapter(struct eventmode_conf *em_conf)
{
struct tx_adapter_connection_info *conn;
struct eventdev_params *eventdev_config;
struct tx_adapter_conf *tx_adapter;
bool tx_internal_port = true;
uint32_t caps = 0;
int eventdev_id;
int adapter_id;
int nb_eth_dev;
int conn_id;
int ret;
int i;
/*
* Create one Tx adapter with all eth queues mapped to event queues
* 1:1.
*/
if (em_conf->nb_eventdev == 0) {
EH_LOG_ERR("No event devs registered");
return -EINVAL;
}
/* Get the number of eth devs */
nb_eth_dev = rte_eth_dev_count_avail();
/* Use the first event dev */
eventdev_config = &(em_conf->eventdev_config[0]);
/* Get eventdev ID */
eventdev_id = eventdev_config->eventdev_id;
adapter_id = 0;
/* Get adapter conf */
tx_adapter = &(em_conf->tx_adapter[adapter_id]);
/* Set adapter conf */
tx_adapter->eventdev_id = eventdev_id;
tx_adapter->adapter_id = adapter_id;
/*
* Map all Tx queues of the eth device (port) to the event device.
*/
/* Set defaults for connections */
/*
* One eth device (port) is one connection. Map all Tx queues
* of the device to the Tx adapter.
*/
for (i = 0; i < nb_eth_dev; i++) {
/* Use only the ports enabled */
if ((em_conf->eth_portmask & (1 << i)) == 0)
continue;
/* Get the connection id */
conn_id = tx_adapter->nb_connections;
/* Get the connection */
conn = &(tx_adapter->conn[conn_id]);
/* Add ethdev to connections */
conn->ethdev_id = i;
/* Add all eth tx queues to adapter */
conn->ethdev_tx_qid = -1;
/* Get Tx adapter capabilities */
ret = rte_event_eth_tx_adapter_caps_get(eventdev_id, i, &caps);
if (ret < 0) {
EH_LOG_ERR("Failed to get event device %d eth tx adapter"
" capabilities for port %d", eventdev_id, i);
return ret;
}
if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
tx_internal_port = false;
/* Update no of connections */
tx_adapter->nb_connections++;
}
if (tx_internal_port) {
/* Tx core is not required */
tx_adapter->tx_core_id = -1;
} else {
/* Tx core is required */
tx_adapter->tx_core_id = eh_get_next_eth_core(em_conf);
/*
* Use one event queue per adapter for submitting packets
* for Tx. Reserving the last queue available
*/
/* Queue numbers start at 0 */
tx_adapter->tx_ev_queue = eventdev_config->nb_eventqueue - 1;
}
/* We have setup one adapter */
em_conf->nb_tx_adapter = 1;
return 0;
}
static int
eh_validate_conf(struct eventmode_conf *em_conf)
{
int ret;
/*
* Check if event devs are specified. Else probe the event devices
* and initialize the config with all ports & queues available
*/
if (em_conf->nb_eventdev == 0) {
ret = eh_set_default_conf_eventdev(em_conf);
if (ret != 0)
return ret;
}
/* Perform capability check for the selected event devices */
eh_do_capability_check(em_conf);
/*
* Check if links are specified. Else generate a default config for
* the event ports used.
*/
if (em_conf->nb_link == 0) {
ret = eh_set_default_conf_link(em_conf);
if (ret != 0)
return ret;
}
/*
* Check if rx adapters are specified. Else generate a default config
* with one rx adapter and all eth queues - event queue mapped.
*/
if (em_conf->nb_rx_adapter == 0) {
ret = eh_set_default_conf_rx_adapter(em_conf);
if (ret != 0)
return ret;
}
/*
* Check if tx adapters are specified. Else generate a default config
* with one tx adapter.
*/
if (em_conf->nb_tx_adapter == 0) {
ret = eh_set_default_conf_tx_adapter(em_conf);
if (ret != 0)
return ret;
}
return 0;
}
static int
eh_initialize_eventdev(struct eventmode_conf *em_conf)
{
struct rte_event_queue_conf eventq_conf = {0};
struct rte_event_dev_info evdev_default_conf;
struct rte_event_dev_config eventdev_conf;
struct eventdev_params *eventdev_config;
int nb_eventdev = em_conf->nb_eventdev;
struct eh_event_link_info *link;
uint8_t *queue = NULL;
uint8_t eventdev_id;
int nb_eventqueue;
uint8_t i, j;
int ret;
for (i = 0; i < nb_eventdev; i++) {
/* Get eventdev config */
eventdev_config = &(em_conf->eventdev_config[i]);
/* Get event dev ID */
eventdev_id = eventdev_config->eventdev_id;
/* Get the number of queues */
nb_eventqueue = eventdev_config->nb_eventqueue;
/* Reset the default conf */
memset(&evdev_default_conf, 0,
sizeof(struct rte_event_dev_info));
/* Get default conf of eventdev */
ret = rte_event_dev_info_get(eventdev_id, &evdev_default_conf);
if (ret < 0) {
EH_LOG_ERR(
"Error in getting event device info[devID:%d]",
eventdev_id);
return ret;
}
memset(&eventdev_conf, 0, sizeof(struct rte_event_dev_config));
eventdev_conf.nb_events_limit =
evdev_default_conf.max_num_events;
eventdev_conf.nb_event_queues = nb_eventqueue;
eventdev_conf.nb_event_ports =
eventdev_config->nb_eventport;
eventdev_conf.nb_event_queue_flows =
evdev_default_conf.max_event_queue_flows;
eventdev_conf.nb_event_port_dequeue_depth =
evdev_default_conf.max_event_port_dequeue_depth;
eventdev_conf.nb_event_port_enqueue_depth =
evdev_default_conf.max_event_port_enqueue_depth;
/* Configure event device */
ret = rte_event_dev_configure(eventdev_id, &eventdev_conf);
if (ret < 0) {
EH_LOG_ERR("Error in configuring event device");
return ret;
}
/* Configure event queues */
for (j = 0; j < nb_eventqueue; j++) {
memset(&eventq_conf, 0,
sizeof(struct rte_event_queue_conf));
/* Per event dev queues can be ATQ or SINGLE LINK */
eventq_conf.event_queue_cfg =
eventdev_config->ev_queue_mode;
/*
* All queues need to be set with sched_type as
* schedule type for the application stage. One
* queue would be reserved for the final eth tx
* stage if event device does not have internal
* ports. This will be an atomic queue.
*/
if (!eventdev_config->all_internal_ports &&
j == nb_eventqueue-1) {
eventq_conf.schedule_type =
RTE_SCHED_TYPE_ATOMIC;
} else {
eventq_conf.schedule_type =
em_conf->ext_params.sched_type;
}
/* Set max atomic flows to 1024 */
eventq_conf.nb_atomic_flows = 1024;
eventq_conf.nb_atomic_order_sequences = 1024;
/* Setup the queue */
ret = rte_event_queue_setup(eventdev_id, j,
&eventq_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to setup event queue %d",
ret);
return ret;
}
}
/* Configure event ports */
for (j = 0; j < eventdev_config->nb_eventport; j++) {
ret = rte_event_port_setup(eventdev_id, j, NULL);
if (ret < 0) {
EH_LOG_ERR("Failed to setup event port %d",
ret);
return ret;
}
}
}
/* Make event queue - event port link */
for (j = 0; j < em_conf->nb_link; j++) {
/* Get link info */
link = &(em_conf->link[j]);
/* Get event dev ID */
eventdev_id = link->eventdev_id;
/*
* If "all_ev_queue_to_ev_port" params flag is selected, all
* queues need to be mapped to the port.
*/
if (em_conf->ext_params.all_ev_queue_to_ev_port)
queue = NULL;
else
queue = &(link->eventq_id);
/* Link queue to port */
ret = rte_event_port_link(eventdev_id, link->event_port_id,
queue, NULL, 1);
if (ret < 0) {
EH_LOG_ERR("Failed to link event port %d", ret);
return ret;
}
}
/* Start event devices */
for (i = 0; i < nb_eventdev; i++) {
/* Get eventdev config */
eventdev_config = &(em_conf->eventdev_config[i]);
ret = rte_event_dev_start(eventdev_config->eventdev_id);
if (ret < 0) {
EH_LOG_ERR("Failed to start event device %d, %d",
i, ret);
return ret;
}
}
return 0;
}
static int
eh_rx_adapter_configure(struct eventmode_conf *em_conf,
struct rx_adapter_conf *adapter)
{
struct rte_event_eth_rx_adapter_queue_conf queue_conf = {0};
struct rte_event_dev_info evdev_default_conf = {0};
struct rte_event_port_conf port_conf = {0};
struct rx_adapter_connection_info *conn;
uint8_t eventdev_id;
uint32_t service_id;
int ret;
int j;
/* Get event dev ID */
eventdev_id = adapter->eventdev_id;
/* Get default configuration of event dev */
ret = rte_event_dev_info_get(eventdev_id, &evdev_default_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to get event dev info %d", ret);
return ret;
}
/* Setup port conf */
port_conf.new_event_threshold = 1200;
port_conf.dequeue_depth =
evdev_default_conf.max_event_port_dequeue_depth;
port_conf.enqueue_depth =
evdev_default_conf.max_event_port_enqueue_depth;
/* Create Rx adapter */
ret = rte_event_eth_rx_adapter_create(adapter->adapter_id,
adapter->eventdev_id, &port_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to create rx adapter %d", ret);
return ret;
}
/* Setup various connections in the adapter */
for (j = 0; j < adapter->nb_connections; j++) {
/* Get connection */
conn = &(adapter->conn[j]);
/* Setup queue conf */
queue_conf.ev.queue_id = conn->eventq_id;
queue_conf.ev.sched_type = em_conf->ext_params.sched_type;
queue_conf.ev.event_type = RTE_EVENT_TYPE_ETHDEV;
/* Add queue to the adapter */
ret = rte_event_eth_rx_adapter_queue_add(adapter->adapter_id,
conn->ethdev_id, conn->ethdev_rx_qid,
&queue_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to add eth queue to rx adapter %d",
ret);
return ret;
}
}
/* Get the service ID used by rx adapter */
ret = rte_event_eth_rx_adapter_service_id_get(adapter->adapter_id,
&service_id);
if (ret != -ESRCH && ret < 0) {
EH_LOG_ERR("Failed to get service id used by rx adapter %d",
ret);
return ret;
}
rte_service_set_runstate_mapped_check(service_id, 0);
/* Start adapter */
ret = rte_event_eth_rx_adapter_start(adapter->adapter_id);
if (ret < 0) {
EH_LOG_ERR("Failed to start rx adapter %d", ret);
return ret;
}
return 0;
}
static int
eh_initialize_rx_adapter(struct eventmode_conf *em_conf)
{
struct rx_adapter_conf *adapter;
int i, ret;
/* Configure rx adapters */
for (i = 0; i < em_conf->nb_rx_adapter; i++) {
adapter = &(em_conf->rx_adapter[i]);
ret = eh_rx_adapter_configure(em_conf, adapter);
if (ret < 0) {
EH_LOG_ERR("Failed to configure rx adapter %d", ret);
return ret;
}
}
return 0;
}
static int32_t
eh_start_worker_eth_core(struct eventmode_conf *conf, uint32_t lcore_id)
{
uint32_t service_id[EVENT_MODE_MAX_ADAPTERS_PER_RX_CORE];
struct rx_adapter_conf *rx_adapter;
struct tx_adapter_conf *tx_adapter;
int service_count = 0;
int adapter_id;
int32_t ret;
int i;
EH_LOG_INFO("Entering eth_core processing on lcore %u", lcore_id);
/*
* Parse adapter config to check which of all Rx adapters need
* to be handled by this core.
*/
for (i = 0; i < conf->nb_rx_adapter; i++) {
/* Check if we have exceeded the max allowed */
if (service_count > EVENT_MODE_MAX_ADAPTERS_PER_RX_CORE) {
EH_LOG_ERR(
"Exceeded the max allowed adapters per rx core");
break;
}
rx_adapter = &(conf->rx_adapter[i]);
if (rx_adapter->rx_core_id != lcore_id)
continue;
/* Adapter is handled by this core */
adapter_id = rx_adapter->adapter_id;
/* Get the service ID for the adapters */
ret = rte_event_eth_rx_adapter_service_id_get(adapter_id,
&(service_id[service_count]));
if (ret != -ESRCH && ret < 0) {
EH_LOG_ERR(
"Failed to get service id used by rx adapter");
return ret;
}
/* Update service count */
service_count++;
}
/*
* Parse adapter config to see which of all Tx adapters need
* to be handled by this core.
*/
for (i = 0; i < conf->nb_tx_adapter; i++) {
/* Check if we have exceeded the max allowed */
if (service_count > EVENT_MODE_MAX_ADAPTERS_PER_TX_CORE) {
EH_LOG_ERR(
"Exceeded the max allowed adapters per tx core");
break;
}
tx_adapter = &conf->tx_adapter[i];
if (tx_adapter->tx_core_id != lcore_id)
continue;
/* Adapter is handled by this core */
adapter_id = tx_adapter->adapter_id;
/* Get the service ID for the adapters */
ret = rte_event_eth_tx_adapter_service_id_get(adapter_id,
&(service_id[service_count]));
if (ret != -ESRCH && ret < 0) {
EH_LOG_ERR(
"Failed to get service id used by tx adapter");
return ret;
}
/* Update service count */
service_count++;
}
eth_core_running = true;
while (eth_core_running) {
for (i = 0; i < service_count; i++) {
/* Initiate adapter service */
rte_service_run_iter_on_app_lcore(service_id[i], 0);
}
}
return 0;
}
static int32_t
eh_stop_worker_eth_core(void)
{
if (eth_core_running) {
EH_LOG_INFO("Stopping eth cores");
eth_core_running = false;
}
return 0;
}
static struct eh_app_worker_params *
eh_find_worker(uint32_t lcore_id, struct eh_conf *conf,
struct eh_app_worker_params *app_wrkrs, uint8_t nb_wrkr_param)
{
struct eh_app_worker_params curr_conf = { {{0} }, NULL};
struct eh_event_link_info *link = NULL;
struct eh_app_worker_params *tmp_wrkr;
struct eventmode_conf *em_conf;
uint8_t eventdev_id;
int i;
/* Get eventmode config */
em_conf = conf->mode_params;
/*
* Use event device from the first lcore-event link.
*
* Assumption: All lcore-event links tied to a core are using the
* same event device. In other words, one core would be polling on
* queues of a single event device only.
*/
/* Get a link for this lcore */
for (i = 0; i < em_conf->nb_link; i++) {
link = &(em_conf->link[i]);
if (link->lcore_id == lcore_id)
break;
}
if (link == NULL) {
EH_LOG_ERR("No valid link found for lcore %d", lcore_id);
return NULL;
}
/* Get event dev ID */
eventdev_id = link->eventdev_id;
/* Populate the curr_conf with the capabilities */
/* Check for Tx internal port */
if (eh_dev_has_tx_internal_port(eventdev_id))
curr_conf.cap.tx_internal_port = EH_TX_TYPE_INTERNAL_PORT;
else
curr_conf.cap.tx_internal_port = EH_TX_TYPE_NO_INTERNAL_PORT;
/* Check for burst mode */
if (eh_dev_has_burst_mode(eventdev_id))
curr_conf.cap.burst = EH_RX_TYPE_BURST;
else
curr_conf.cap.burst = EH_RX_TYPE_NON_BURST;
curr_conf.cap.ipsec_mode = conf->ipsec_mode;
/* Parse the passed list and see if we have matching capabilities */
/* Initialize the pointer used to traverse the list */
tmp_wrkr = app_wrkrs;
for (i = 0; i < nb_wrkr_param; i++, tmp_wrkr++) {
/* Skip this if capabilities are not matching */
if (tmp_wrkr->cap.u64 != curr_conf.cap.u64)
continue;
/* If the checks pass, we have a match */
return tmp_wrkr;
}
return NULL;
}
static int
eh_verify_match_worker(struct eh_app_worker_params *match_wrkr)
{
/* Verify registered worker */
if (match_wrkr->worker_thread == NULL) {
EH_LOG_ERR("No worker registered");
return 0;
}
/* Success */
return 1;
}
static uint8_t
eh_get_event_lcore_links(uint32_t lcore_id, struct eh_conf *conf,
struct eh_event_link_info **links)
{
struct eh_event_link_info *link_cache;
struct eventmode_conf *em_conf = NULL;
struct eh_event_link_info *link;
uint8_t lcore_nb_link = 0;
size_t single_link_size;
size_t cache_size;
int index = 0;
int i;
if (conf == NULL || links == NULL) {
EH_LOG_ERR("Invalid args");
return -EINVAL;
}
/* Get eventmode conf */
em_conf = conf->mode_params;
if (em_conf == NULL) {
EH_LOG_ERR("Invalid event mode parameters");
return -EINVAL;
}
/* Get the number of links registered */
for (i = 0; i < em_conf->nb_link; i++) {
/* Get link */
link = &(em_conf->link[i]);
/* Check if we have link intended for this lcore */
if (link->lcore_id == lcore_id) {
/* Update the number of links for this core */
lcore_nb_link++;
}
}
/* Compute size of one entry to be copied */
single_link_size = sizeof(struct eh_event_link_info);
/* Compute size of the buffer required */
cache_size = lcore_nb_link * sizeof(struct eh_event_link_info);
/* Compute size of the buffer required */
link_cache = calloc(1, cache_size);
/* Get the number of links registered */
for (i = 0; i < em_conf->nb_link; i++) {
/* Get link */
link = &(em_conf->link[i]);
/* Check if we have link intended for this lcore */
if (link->lcore_id == lcore_id) {
/* Cache the link */
memcpy(&link_cache[index], link, single_link_size);
/* Update index */
index++;
}
}
/* Update the links for application to use the cached links */
*links = link_cache;
/* Return the number of cached links */
return lcore_nb_link;
}
static int
eh_tx_adapter_configure(struct eventmode_conf *em_conf,
struct tx_adapter_conf *adapter)
{
struct rte_event_dev_info evdev_default_conf = {0};
struct rte_event_port_conf port_conf = {0};
struct tx_adapter_connection_info *conn;
struct eventdev_params *eventdev_config;
uint8_t tx_port_id = 0;
uint8_t eventdev_id;
uint32_t service_id;
int ret, j;
/* Get event dev ID */
eventdev_id = adapter->eventdev_id;
/* Get event device conf */
eventdev_config = eh_get_eventdev_params(em_conf, eventdev_id);
/* Create Tx adapter */
/* Get default configuration of event dev */
ret = rte_event_dev_info_get(eventdev_id, &evdev_default_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to get event dev info %d", ret);
return ret;
}
/* Setup port conf */
port_conf.new_event_threshold =
evdev_default_conf.max_num_events;
port_conf.dequeue_depth =
evdev_default_conf.max_event_port_dequeue_depth;
port_conf.enqueue_depth =
evdev_default_conf.max_event_port_enqueue_depth;
/* Create adapter */
ret = rte_event_eth_tx_adapter_create(adapter->adapter_id,
adapter->eventdev_id, &port_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to create tx adapter %d", ret);
return ret;
}
/* Setup various connections in the adapter */
for (j = 0; j < adapter->nb_connections; j++) {
/* Get connection */
conn = &(adapter->conn[j]);
/* Add queue to the adapter */
ret = rte_event_eth_tx_adapter_queue_add(adapter->adapter_id,
conn->ethdev_id, conn->ethdev_tx_qid);
if (ret < 0) {
EH_LOG_ERR("Failed to add eth queue to tx adapter %d",
ret);
return ret;
}
}
/*
* Check if Tx core is assigned. If Tx core is not assigned then
* the adapter has internal port for submitting Tx packets and
* Tx event queue & port setup is not required
*/
if (adapter->tx_core_id == (uint32_t) (-1)) {
/* Internal port is present */
goto skip_tx_queue_port_setup;
}
/* Setup Tx queue & port */
/* Get event port used by the adapter */
ret = rte_event_eth_tx_adapter_event_port_get(
adapter->adapter_id, &tx_port_id);
if (ret) {
EH_LOG_ERR("Failed to get tx adapter port id %d", ret);
return ret;
}
/*
* Tx event queue is reserved for Tx adapter. Unlink this queue
* from all other ports
*
*/
for (j = 0; j < eventdev_config->nb_eventport; j++) {
rte_event_port_unlink(eventdev_id, j,
&(adapter->tx_ev_queue), 1);
}
/* Link Tx event queue to Tx port */
ret = rte_event_port_link(eventdev_id, tx_port_id,
&(adapter->tx_ev_queue), NULL, 1);
if (ret != 1) {
EH_LOG_ERR("Failed to link event queue to port");
return ret;
}
/* Get the service ID used by Tx adapter */
ret = rte_event_eth_tx_adapter_service_id_get(adapter->adapter_id,
&service_id);
if (ret != -ESRCH && ret < 0) {
EH_LOG_ERR("Failed to get service id used by tx adapter %d",
ret);
return ret;
}
rte_service_set_runstate_mapped_check(service_id, 0);
skip_tx_queue_port_setup:
/* Start adapter */
ret = rte_event_eth_tx_adapter_start(adapter->adapter_id);
if (ret < 0) {
EH_LOG_ERR("Failed to start tx adapter %d", ret);
return ret;
}
return 0;
}
static int
eh_initialize_tx_adapter(struct eventmode_conf *em_conf)
{
struct tx_adapter_conf *adapter;
int i, ret;
/* Configure Tx adapters */
for (i = 0; i < em_conf->nb_tx_adapter; i++) {
adapter = &(em_conf->tx_adapter[i]);
ret = eh_tx_adapter_configure(em_conf, adapter);
if (ret < 0) {
EH_LOG_ERR("Failed to configure tx adapter %d", ret);
return ret;
}
}
return 0;
}
static void
eh_display_operating_mode(struct eventmode_conf *em_conf)
{
char sched_types[][32] = {
"RTE_SCHED_TYPE_ORDERED",
"RTE_SCHED_TYPE_ATOMIC",
"RTE_SCHED_TYPE_PARALLEL",
};
EH_LOG_INFO("Operating mode:");
EH_LOG_INFO("\tScheduling type: \t%s",
sched_types[em_conf->ext_params.sched_type]);
EH_LOG_INFO("");
}
static void
eh_display_event_dev_conf(struct eventmode_conf *em_conf)
{
char queue_mode[][32] = {
"",
"ATQ (ALL TYPE QUEUE)",
"SINGLE LINK",
};
char print_buf[256] = { 0 };
int i;
EH_LOG_INFO("Event Device Configuration:");
for (i = 0; i < em_conf->nb_eventdev; i++) {
sprintf(print_buf,
"\tDev ID: %-2d \tQueues: %-2d \tPorts: %-2d",
em_conf->eventdev_config[i].eventdev_id,
em_conf->eventdev_config[i].nb_eventqueue,
em_conf->eventdev_config[i].nb_eventport);
sprintf(print_buf + strlen(print_buf),
"\tQueue mode: %s",
queue_mode[em_conf->eventdev_config[i].ev_queue_mode]);
EH_LOG_INFO("%s", print_buf);
}
EH_LOG_INFO("");
}
static void
eh_display_rx_adapter_conf(struct eventmode_conf *em_conf)
{
int nb_rx_adapter = em_conf->nb_rx_adapter;
struct rx_adapter_connection_info *conn;
struct rx_adapter_conf *adapter;
char print_buf[256] = { 0 };
int i, j;
EH_LOG_INFO("Rx adapters configured: %d", nb_rx_adapter);
for (i = 0; i < nb_rx_adapter; i++) {
adapter = &(em_conf->rx_adapter[i]);
sprintf(print_buf,
"\tRx adaper ID: %-2d\tConnections: %-2d\tEvent dev ID: %-2d",
adapter->adapter_id,
adapter->nb_connections,
adapter->eventdev_id);
if (adapter->rx_core_id == (uint32_t)-1)
sprintf(print_buf + strlen(print_buf),
"\tRx core: %-2s", "[INTERNAL PORT]");
else if (adapter->rx_core_id == RTE_MAX_LCORE)
sprintf(print_buf + strlen(print_buf),
"\tRx core: %-2s", "[NONE]");
else
sprintf(print_buf + strlen(print_buf),
"\tRx core: %-2d", adapter->rx_core_id);
EH_LOG_INFO("%s", print_buf);
for (j = 0; j < adapter->nb_connections; j++) {
conn = &(adapter->conn[j]);
sprintf(print_buf,
"\t\tEthdev ID: %-2d", conn->ethdev_id);
if (conn->ethdev_rx_qid == -1)
sprintf(print_buf + strlen(print_buf),
"\tEth rx queue: %-2s", "ALL");
else
sprintf(print_buf + strlen(print_buf),
"\tEth rx queue: %-2d",
conn->ethdev_rx_qid);
sprintf(print_buf + strlen(print_buf),
"\tEvent queue: %-2d", conn->eventq_id);
EH_LOG_INFO("%s", print_buf);
}
}
EH_LOG_INFO("");
}
static void
eh_display_tx_adapter_conf(struct eventmode_conf *em_conf)
{
int nb_tx_adapter = em_conf->nb_tx_adapter;
struct tx_adapter_connection_info *conn;
struct tx_adapter_conf *adapter;
char print_buf[256] = { 0 };
int i, j;
EH_LOG_INFO("Tx adapters configured: %d", nb_tx_adapter);
for (i = 0; i < nb_tx_adapter; i++) {
adapter = &(em_conf->tx_adapter[i]);
sprintf(print_buf,
"\tTx adapter ID: %-2d\tConnections: %-2d\tEvent dev ID: %-2d",
adapter->adapter_id,
adapter->nb_connections,
adapter->eventdev_id);
if (adapter->tx_core_id == (uint32_t)-1)
sprintf(print_buf + strlen(print_buf),
"\tTx core: %-2s", "[INTERNAL PORT]");
else if (adapter->tx_core_id == RTE_MAX_LCORE)
sprintf(print_buf + strlen(print_buf),
"\tTx core: %-2s", "[NONE]");
else
sprintf(print_buf + strlen(print_buf),
"\tTx core: %-2d,\tInput event queue: %-2d",
adapter->tx_core_id, adapter->tx_ev_queue);
EH_LOG_INFO("%s", print_buf);
for (j = 0; j < adapter->nb_connections; j++) {
conn = &(adapter->conn[j]);
sprintf(print_buf,
"\t\tEthdev ID: %-2d", conn->ethdev_id);
if (conn->ethdev_tx_qid == -1)
sprintf(print_buf + strlen(print_buf),
"\tEth tx queue: %-2s", "ALL");
else
sprintf(print_buf + strlen(print_buf),
"\tEth tx queue: %-2d",
conn->ethdev_tx_qid);
EH_LOG_INFO("%s", print_buf);
}
}
EH_LOG_INFO("");
}
static void
eh_display_link_conf(struct eventmode_conf *em_conf)
{
struct eh_event_link_info *link;
char print_buf[256] = { 0 };
int i;
EH_LOG_INFO("Links configured: %d", em_conf->nb_link);
for (i = 0; i < em_conf->nb_link; i++) {
link = &(em_conf->link[i]);
sprintf(print_buf,
"\tEvent dev ID: %-2d\tEvent port: %-2d",
link->eventdev_id,
link->event_port_id);
if (em_conf->ext_params.all_ev_queue_to_ev_port)
sprintf(print_buf + strlen(print_buf),
"Event queue: %-2s\t", "ALL");
else
sprintf(print_buf + strlen(print_buf),
"Event queue: %-2d\t", link->eventq_id);
sprintf(print_buf + strlen(print_buf),
"Lcore: %-2d", link->lcore_id);
EH_LOG_INFO("%s", print_buf);
}
EH_LOG_INFO("");
}
struct eh_conf *
eh_conf_init(void)
{
struct eventmode_conf *em_conf = NULL;
struct eh_conf *conf = NULL;
unsigned int eth_core_id;
void *bitmap = NULL;
uint32_t nb_bytes;
/* Allocate memory for config */
conf = calloc(1, sizeof(struct eh_conf));
if (conf == NULL) {
EH_LOG_ERR("Failed to allocate memory for eventmode helper "
"config");
return NULL;
}
/* Set default conf */
/* Packet transfer mode: poll */
conf->mode = EH_PKT_TRANSFER_MODE_POLL;
conf->ipsec_mode = EH_IPSEC_MODE_TYPE_APP;
/* Keep all ethernet ports enabled by default */
conf->eth_portmask = -1;
/* Allocate memory for event mode params */
conf->mode_params = calloc(1, sizeof(struct eventmode_conf));
if (conf->mode_params == NULL) {
EH_LOG_ERR("Failed to allocate memory for event mode params");
goto free_conf;
}
/* Get eventmode conf */
em_conf = conf->mode_params;
/* Allocate and initialize bitmap for eth cores */
nb_bytes = rte_bitmap_get_memory_footprint(RTE_MAX_LCORE);
if (!nb_bytes) {
EH_LOG_ERR("Failed to get bitmap footprint");
goto free_em_conf;
}
bitmap = rte_zmalloc("event-helper-ethcore-bitmap", nb_bytes,
RTE_CACHE_LINE_SIZE);
if (!bitmap) {
EH_LOG_ERR("Failed to allocate memory for eth cores bitmap\n");
goto free_em_conf;
}
em_conf->eth_core_mask = rte_bitmap_init(RTE_MAX_LCORE, bitmap,
nb_bytes);
if (!em_conf->eth_core_mask) {
EH_LOG_ERR("Failed to initialize bitmap");
goto free_bitmap;
}
/* Set schedule type as not set */
em_conf->ext_params.sched_type = SCHED_TYPE_NOT_SET;
/* Set two cores as eth cores for Rx & Tx */
/* Use first core other than master core as Rx core */
eth_core_id = rte_get_next_lcore(0, /* curr core */
1, /* skip master core */
0 /* wrap */);
rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
/* Use next core as Tx core */
eth_core_id = rte_get_next_lcore(eth_core_id, /* curr core */
1, /* skip master core */
0 /* wrap */);
rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
return conf;
free_bitmap:
rte_free(bitmap);
free_em_conf:
free(em_conf);
free_conf:
free(conf);
return NULL;
}
void
eh_conf_uninit(struct eh_conf *conf)
{
struct eventmode_conf *em_conf = NULL;
if (!conf || !conf->mode_params)
return;
/* Get eventmode conf */
em_conf = conf->mode_params;
/* Free evenmode configuration memory */
rte_free(em_conf->eth_core_mask);
free(em_conf);
free(conf);
}
void
eh_display_conf(struct eh_conf *conf)
{
struct eventmode_conf *em_conf;
if (conf == NULL) {
EH_LOG_ERR("Invalid event helper configuration");
return;
}
if (conf->mode != EH_PKT_TRANSFER_MODE_EVENT)
return;
if (conf->mode_params == NULL) {
EH_LOG_ERR("Invalid event mode parameters");
return;
}
/* Get eventmode conf */
em_conf = (struct eventmode_conf *)(conf->mode_params);
/* Display user exposed operating modes */
eh_display_operating_mode(em_conf);
/* Display event device conf */
eh_display_event_dev_conf(em_conf);
/* Display Rx adapter conf */
eh_display_rx_adapter_conf(em_conf);
/* Display Tx adapter conf */
eh_display_tx_adapter_conf(em_conf);
/* Display event-lcore link */
eh_display_link_conf(em_conf);
}
int32_t
eh_devs_init(struct eh_conf *conf)
{
struct eventmode_conf *em_conf;
uint16_t port_id;
int ret;
if (conf == NULL) {
EH_LOG_ERR("Invalid event helper configuration");
return -EINVAL;
}
if (conf->mode != EH_PKT_TRANSFER_MODE_EVENT)
return 0;
if (conf->mode_params == NULL) {
EH_LOG_ERR("Invalid event mode parameters");
return -EINVAL;
}
/* Get eventmode conf */
em_conf = conf->mode_params;
/* Eventmode conf would need eth portmask */
em_conf->eth_portmask = conf->eth_portmask;
/* Validate the requested config */
ret = eh_validate_conf(em_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to validate the requested config %d", ret);
return ret;
}
/* Display the current configuration */
eh_display_conf(conf);
/* Stop eth devices before setting up adapter */
RTE_ETH_FOREACH_DEV(port_id) {
/* Use only the ports enabled */
if ((conf->eth_portmask & (1 << port_id)) == 0)
continue;
rte_eth_dev_stop(port_id);
}
/* Setup eventdev */
ret = eh_initialize_eventdev(em_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to initialize event dev %d", ret);
return ret;
}
/* Setup Rx adapter */
ret = eh_initialize_rx_adapter(em_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to initialize rx adapter %d", ret);
return ret;
}
/* Setup Tx adapter */
ret = eh_initialize_tx_adapter(em_conf);
if (ret < 0) {
EH_LOG_ERR("Failed to initialize tx adapter %d", ret);
return ret;
}
/* Start eth devices after setting up adapter */
RTE_ETH_FOREACH_DEV(port_id) {
/* Use only the ports enabled */
if ((conf->eth_portmask & (1 << port_id)) == 0)
continue;
ret = rte_eth_dev_start(port_id);
if (ret < 0) {
EH_LOG_ERR("Failed to start eth dev %d, %d",
port_id, ret);
return ret;
}
}
return 0;
}
int32_t
eh_devs_uninit(struct eh_conf *conf)
{
struct eventmode_conf *em_conf;
int ret, i, j;
uint16_t id;
if (conf == NULL) {
EH_LOG_ERR("Invalid event helper configuration");
return -EINVAL;
}
if (conf->mode != EH_PKT_TRANSFER_MODE_EVENT)
return 0;
if (conf->mode_params == NULL) {
EH_LOG_ERR("Invalid event mode parameters");
return -EINVAL;
}
/* Get eventmode conf */
em_conf = conf->mode_params;
/* Stop and release rx adapters */
for (i = 0; i < em_conf->nb_rx_adapter; i++) {
id = em_conf->rx_adapter[i].adapter_id;
ret = rte_event_eth_rx_adapter_stop(id);
if (ret < 0) {
EH_LOG_ERR("Failed to stop rx adapter %d", ret);
return ret;
}
for (j = 0; j < em_conf->rx_adapter[i].nb_connections; j++) {
ret = rte_event_eth_rx_adapter_queue_del(id,
em_conf->rx_adapter[i].conn[j].ethdev_id, -1);
if (ret < 0) {
EH_LOG_ERR(
"Failed to remove rx adapter queues %d",
ret);
return ret;
}
}
ret = rte_event_eth_rx_adapter_free(id);
if (ret < 0) {
EH_LOG_ERR("Failed to free rx adapter %d", ret);
return ret;
}
}
/* Stop and release event devices */
for (i = 0; i < em_conf->nb_eventdev; i++) {
id = em_conf->eventdev_config[i].eventdev_id;
rte_event_dev_stop(id);
ret = rte_event_dev_close(id);
if (ret < 0) {
EH_LOG_ERR("Failed to close event dev %d, %d", id, ret);
return ret;
}
}
/* Stop and release tx adapters */
for (i = 0; i < em_conf->nb_tx_adapter; i++) {
id = em_conf->tx_adapter[i].adapter_id;
ret = rte_event_eth_tx_adapter_stop(id);
if (ret < 0) {
EH_LOG_ERR("Failed to stop tx adapter %d", ret);
return ret;
}
for (j = 0; j < em_conf->tx_adapter[i].nb_connections; j++) {
ret = rte_event_eth_tx_adapter_queue_del(id,
em_conf->tx_adapter[i].conn[j].ethdev_id, -1);
if (ret < 0) {
EH_LOG_ERR(
"Failed to remove tx adapter queues %d",
ret);
return ret;
}
}
ret = rte_event_eth_tx_adapter_free(id);
if (ret < 0) {
EH_LOG_ERR("Failed to free tx adapter %d", ret);
return ret;
}
}
return 0;
}
void
eh_launch_worker(struct eh_conf *conf, struct eh_app_worker_params *app_wrkr,
uint8_t nb_wrkr_param)
{
struct eh_app_worker_params *match_wrkr;
struct eh_event_link_info *links = NULL;
struct eventmode_conf *em_conf;
uint32_t lcore_id;
uint8_t nb_links;
if (conf == NULL) {
EH_LOG_ERR("Invalid event helper configuration");
return;
}
if (conf->mode_params == NULL) {
EH_LOG_ERR("Invalid event mode parameters");
return;
}
/* Get eventmode conf */
em_conf = conf->mode_params;
/* Get core ID */
lcore_id = rte_lcore_id();
/* Check if this is eth core */
if (rte_bitmap_get(em_conf->eth_core_mask, lcore_id)) {
eh_start_worker_eth_core(em_conf, lcore_id);
return;
}
if (app_wrkr == NULL || nb_wrkr_param == 0) {
EH_LOG_ERR("Invalid args");
return;
}
/*
* This is a regular worker thread. The application registers
* multiple workers with various capabilities. Run worker
* based on the selected capabilities of the event
* device configured.
*/
/* Get the first matching worker for the event device */
match_wrkr = eh_find_worker(lcore_id, conf, app_wrkr, nb_wrkr_param);
if (match_wrkr == NULL) {
EH_LOG_ERR("Failed to match worker registered for lcore %d",
lcore_id);
goto clean_and_exit;
}
/* Verify sanity of the matched worker */
if (eh_verify_match_worker(match_wrkr) != 1) {
EH_LOG_ERR("Failed to validate the matched worker");
goto clean_and_exit;
}
/* Get worker links */
nb_links = eh_get_event_lcore_links(lcore_id, conf, &links);
/* Launch the worker thread */
match_wrkr->worker_thread(links, nb_links);
/* Free links info memory */
free(links);
clean_and_exit:
/* Flag eth_cores to stop, if started */
eh_stop_worker_eth_core();
}
uint8_t
eh_get_tx_queue(struct eh_conf *conf, uint8_t eventdev_id)
{
struct eventdev_params *eventdev_config;
struct eventmode_conf *em_conf;
if (conf == NULL) {
EH_LOG_ERR("Invalid event helper configuration");
return -EINVAL;
}
if (conf->mode_params == NULL) {
EH_LOG_ERR("Invalid event mode parameters");
return -EINVAL;
}
/* Get eventmode conf */
em_conf = conf->mode_params;
/* Get event device conf */
eventdev_config = eh_get_eventdev_params(em_conf, eventdev_id);
if (eventdev_config == NULL) {
EH_LOG_ERR("Failed to read eventdev config");
return -EINVAL;
}
/*
* The last queue is reserved to be used as atomic queue for the
* last stage (eth packet tx stage)
*/
return eventdev_config->nb_eventqueue - 1;
}
|