summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/drivers/event/octeontx2/otx2_evdev.c
blob: 630073de50ec7a1f53cb873912e909d03542c6ec (plain)
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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(C) 2019 Marvell International Ltd.
 */

#include <inttypes.h>

#include <rte_bus_pci.h>
#include <rte_common.h>
#include <rte_eal.h>
#include <rte_eventdev_pmd_pci.h>
#include <rte_kvargs.h>
#include <rte_mbuf_pool_ops.h>
#include <rte_pci.h>

#include "otx2_evdev_stats.h"
#include "otx2_evdev.h"
#include "otx2_irq.h"
#include "otx2_tim_evdev.h"

static inline int
sso_get_msix_offsets(const struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	uint8_t nb_ports = dev->nb_event_ports * (dev->dual_ws ? 2 : 1);
	struct otx2_mbox *mbox = dev->mbox;
	struct msix_offset_rsp *msix_rsp;
	int i, rc;

	/* Get SSO and SSOW MSIX vector offsets */
	otx2_mbox_alloc_msg_msix_offset(mbox);
	rc = otx2_mbox_process_msg(mbox, (void *)&msix_rsp);

	for (i = 0; i < nb_ports; i++)
		dev->ssow_msixoff[i] = msix_rsp->ssow_msixoff[i];

	for (i = 0; i < dev->nb_event_queues; i++)
		dev->sso_msixoff[i] = msix_rsp->sso_msixoff[i];

	return rc;
}

void
sso_fastpath_fns_set(struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	/* Single WS modes */
	const event_dequeue_t ssogws_deq[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] = otx2_ssogws_deq_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_burst_t ssogws_deq_burst[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] = otx2_ssogws_deq_burst_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_t ssogws_deq_timeout[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] = otx2_ssogws_deq_timeout_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_burst_t
		ssogws_deq_timeout_burst[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_deq_timeout_burst_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_t ssogws_deq_seg[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] = otx2_ssogws_deq_seg_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_burst_t
		ssogws_deq_seg_burst[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_deq_seg_burst_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_t ssogws_deq_seg_timeout[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_deq_seg_timeout_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_burst_t
		ssogws_deq_seg_timeout_burst[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
				otx2_ssogws_deq_seg_timeout_burst_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};


	/* Dual WS modes */
	const event_dequeue_t ssogws_dual_deq[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] = otx2_ssogws_dual_deq_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_burst_t
		ssogws_dual_deq_burst[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_dual_deq_burst_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_t ssogws_dual_deq_timeout[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_dual_deq_timeout_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_burst_t
		ssogws_dual_deq_timeout_burst[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
	[f6][f5][f4][f3][f2][f1][f0] =					\
			otx2_ssogws_dual_deq_timeout_burst_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_t ssogws_dual_deq_seg[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] = otx2_ssogws_dual_deq_seg_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_burst_t
		ssogws_dual_deq_seg_burst[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_dual_deq_seg_burst_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_t
		ssogws_dual_deq_seg_timeout[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_dual_deq_seg_timeout_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	const event_dequeue_burst_t
		ssogws_dual_deq_seg_timeout_burst[2][2][2][2][2][2][2] = {
#define R(name, f6, f5, f4, f3, f2, f1, f0, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_dual_deq_seg_timeout_burst_ ##name,
SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
#undef R
	};

	/* Tx modes */
	const event_tx_adapter_enqueue
		ssogws_tx_adptr_enq[2][2][2][2][2][2][2] = {
#define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_tx_adptr_enq_ ## name,
SSO_TX_ADPTR_ENQ_FASTPATH_FUNC
#undef T
	};

	const event_tx_adapter_enqueue
		ssogws_tx_adptr_enq_seg[2][2][2][2][2][2][2] = {
#define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_tx_adptr_enq_seg_ ## name,
SSO_TX_ADPTR_ENQ_FASTPATH_FUNC
#undef T
	};

	const event_tx_adapter_enqueue
		ssogws_dual_tx_adptr_enq[2][2][2][2][2][2][2] = {
#define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_dual_tx_adptr_enq_ ## name,
SSO_TX_ADPTR_ENQ_FASTPATH_FUNC
#undef T
	};

	const event_tx_adapter_enqueue
		ssogws_dual_tx_adptr_enq_seg[2][2][2][2][2][2][2] = {
#define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags)			\
		[f6][f5][f4][f3][f2][f1][f0] =				\
			otx2_ssogws_dual_tx_adptr_enq_seg_ ## name,
SSO_TX_ADPTR_ENQ_FASTPATH_FUNC
#undef T
	};

	event_dev->enqueue			= otx2_ssogws_enq;
	event_dev->enqueue_burst		= otx2_ssogws_enq_burst;
	event_dev->enqueue_new_burst		= otx2_ssogws_enq_new_burst;
	event_dev->enqueue_forward_burst	= otx2_ssogws_enq_fwd_burst;
	if (dev->rx_offloads & NIX_RX_MULTI_SEG_F) {
		event_dev->dequeue		= ssogws_deq_seg
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
		event_dev->dequeue_burst	= ssogws_deq_seg_burst
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
		if (dev->is_timeout_deq) {
			event_dev->dequeue	= ssogws_deq_seg_timeout
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
			event_dev->dequeue_burst	=
				ssogws_deq_seg_timeout_burst
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
		}
	} else {
		event_dev->dequeue			= ssogws_deq
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
		event_dev->dequeue_burst		= ssogws_deq_burst
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
		if (dev->is_timeout_deq) {
			event_dev->dequeue		= ssogws_deq_timeout
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
			event_dev->dequeue_burst	=
				ssogws_deq_timeout_burst
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
			[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
		}
	}

	if (dev->tx_offloads & NIX_TX_MULTI_SEG_F) {
		/* [SEC] [TSMP] [MBUF_NOFF] [VLAN] [OL3_L4_CSUM] [L3_L4_CSUM] */
		event_dev->txa_enqueue = ssogws_tx_adptr_enq_seg
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_SECURITY_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSO_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSTAMP_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_MBUF_NOFF_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_VLAN_QINQ_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_OL3_OL4_CSUM_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_L3_L4_CSUM_F)];
	} else {
		event_dev->txa_enqueue = ssogws_tx_adptr_enq
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_SECURITY_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSO_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSTAMP_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_MBUF_NOFF_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_VLAN_QINQ_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_OL3_OL4_CSUM_F)]
			[!!(dev->tx_offloads & NIX_TX_OFFLOAD_L3_L4_CSUM_F)];
	}

	if (dev->dual_ws) {
		event_dev->enqueue		= otx2_ssogws_dual_enq;
		event_dev->enqueue_burst	= otx2_ssogws_dual_enq_burst;
		event_dev->enqueue_new_burst	=
					otx2_ssogws_dual_enq_new_burst;
		event_dev->enqueue_forward_burst =
					otx2_ssogws_dual_enq_fwd_burst;

		if (dev->rx_offloads & NIX_RX_MULTI_SEG_F) {
			event_dev->dequeue	= ssogws_dual_deq_seg
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_SECURITY_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_TSTAMP_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_MARK_UPDATE_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_VLAN_STRIP_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_CHECKSUM_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
			event_dev->dequeue_burst = ssogws_dual_deq_seg_burst
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_SECURITY_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_MARK_UPDATE_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_VLAN_STRIP_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_CHECKSUM_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
			if (dev->is_timeout_deq) {
				event_dev->dequeue	=
					ssogws_dual_deq_seg_timeout
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_SECURITY_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_TSTAMP_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_MARK_UPDATE_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_VLAN_STRIP_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_CHECKSUM_F)]
					[!!(dev->rx_offloads &
							NIX_RX_OFFLOAD_PTYPE_F)]
					[!!(dev->rx_offloads &
							NIX_RX_OFFLOAD_RSS_F)];
				event_dev->dequeue_burst =
					ssogws_dual_deq_seg_timeout_burst
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_SECURITY_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_TSTAMP_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_MARK_UPDATE_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_VLAN_STRIP_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_CHECKSUM_F)]
					[!!(dev->rx_offloads &
							NIX_RX_OFFLOAD_PTYPE_F)]
					[!!(dev->rx_offloads &
							NIX_RX_OFFLOAD_RSS_F)];
			}
		} else {
			event_dev->dequeue		= ssogws_dual_deq
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_SECURITY_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_TSTAMP_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_MARK_UPDATE_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_VLAN_STRIP_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_CHECKSUM_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
			event_dev->dequeue_burst	= ssogws_dual_deq_burst
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_SECURITY_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_TSTAMP_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_MARK_UPDATE_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_VLAN_STRIP_F)]
				[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_CHECKSUM_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)]
				[!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)];
			if (dev->is_timeout_deq) {
				event_dev->dequeue	=
					ssogws_dual_deq_timeout
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_SECURITY_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_TSTAMP_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_MARK_UPDATE_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_VLAN_STRIP_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_CHECKSUM_F)]
					[!!(dev->rx_offloads &
							NIX_RX_OFFLOAD_PTYPE_F)]
					[!!(dev->rx_offloads &
							NIX_RX_OFFLOAD_RSS_F)];
				event_dev->dequeue_burst =
					ssogws_dual_deq_timeout_burst
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_SECURITY_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_TSTAMP_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_MARK_UPDATE_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_VLAN_STRIP_F)]
					[!!(dev->rx_offloads &
						NIX_RX_OFFLOAD_CHECKSUM_F)]
					[!!(dev->rx_offloads &
							NIX_RX_OFFLOAD_PTYPE_F)]
					[!!(dev->rx_offloads &
							NIX_RX_OFFLOAD_RSS_F)];
			}
		}

		if (dev->tx_offloads & NIX_TX_MULTI_SEG_F) {
		/* [SEC] [TSMP] [MBUF_NOFF] [VLAN] [OL3_L4_CSUM] [L3_L4_CSUM] */
			event_dev->txa_enqueue = ssogws_dual_tx_adptr_enq_seg
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_SECURITY_F)]
				[!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSO_F)]
				[!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSTAMP_F)]
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_MBUF_NOFF_F)]
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_VLAN_QINQ_F)]
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_OL3_OL4_CSUM_F)]
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_L3_L4_CSUM_F)];
		} else {
			event_dev->txa_enqueue = ssogws_dual_tx_adptr_enq
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_SECURITY_F)]
				[!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSO_F)]
				[!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSTAMP_F)]
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_MBUF_NOFF_F)]
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_VLAN_QINQ_F)]
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_OL3_OL4_CSUM_F)]
				[!!(dev->tx_offloads &
						NIX_TX_OFFLOAD_L3_L4_CSUM_F)];
		}
	}

	event_dev->txa_enqueue_same_dest = event_dev->txa_enqueue;
	rte_mb();
}

static void
otx2_sso_info_get(struct rte_eventdev *event_dev,
		  struct rte_event_dev_info *dev_info)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);

	dev_info->driver_name = RTE_STR(EVENTDEV_NAME_OCTEONTX2_PMD);
	dev_info->min_dequeue_timeout_ns = dev->min_dequeue_timeout_ns;
	dev_info->max_dequeue_timeout_ns = dev->max_dequeue_timeout_ns;
	dev_info->max_event_queues = dev->max_event_queues;
	dev_info->max_event_queue_flows = (1ULL << 20);
	dev_info->max_event_queue_priority_levels = 8;
	dev_info->max_event_priority_levels = 1;
	dev_info->max_event_ports = dev->max_event_ports;
	dev_info->max_event_port_dequeue_depth = 1;
	dev_info->max_event_port_enqueue_depth = 1;
	dev_info->max_num_events =  dev->max_num_events;
	dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
					RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
					RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES |
					RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK |
					RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT |
					RTE_EVENT_DEV_CAP_NONSEQ_MODE;
}

static void
sso_port_link_modify(struct otx2_ssogws *ws, uint8_t queue, uint8_t enable)
{
	uintptr_t base = OTX2_SSOW_GET_BASE_ADDR(ws->getwrk_op);
	uint64_t val;

	val = queue;
	val |= 0ULL << 12; /* SET 0 */
	val |= 0x8000800080000000; /* Dont modify rest of the masks */
	val |= (uint64_t)enable << 14;   /* Enable/Disable Membership. */

	otx2_write64(val, base + SSOW_LF_GWS_GRPMSK_CHG);
}

static int
otx2_sso_port_link(struct rte_eventdev *event_dev, void *port,
		   const uint8_t queues[], const uint8_t priorities[],
		   uint16_t nb_links)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	uint8_t port_id = 0;
	uint16_t link;

	RTE_SET_USED(priorities);
	for (link = 0; link < nb_links; link++) {
		if (dev->dual_ws) {
			struct otx2_ssogws_dual *ws = port;

			port_id = ws->port;
			sso_port_link_modify((struct otx2_ssogws *)
					&ws->ws_state[0], queues[link], true);
			sso_port_link_modify((struct otx2_ssogws *)
					&ws->ws_state[1], queues[link], true);
		} else {
			struct otx2_ssogws *ws = port;

			port_id = ws->port;
			sso_port_link_modify(ws, queues[link], true);
		}
	}
	sso_func_trace("Port=%d nb_links=%d", port_id, nb_links);

	return (int)nb_links;
}

static int
otx2_sso_port_unlink(struct rte_eventdev *event_dev, void *port,
		     uint8_t queues[], uint16_t nb_unlinks)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	uint8_t port_id = 0;
	uint16_t unlink;

	for (unlink = 0; unlink < nb_unlinks; unlink++) {
		if (dev->dual_ws) {
			struct otx2_ssogws_dual *ws = port;

			port_id = ws->port;
			sso_port_link_modify((struct otx2_ssogws *)
					&ws->ws_state[0], queues[unlink],
					false);
			sso_port_link_modify((struct otx2_ssogws *)
					&ws->ws_state[1], queues[unlink],
					false);
		} else {
			struct otx2_ssogws *ws = port;

			port_id = ws->port;
			sso_port_link_modify(ws, queues[unlink], false);
		}
	}
	sso_func_trace("Port=%d nb_unlinks=%d", port_id, nb_unlinks);

	return (int)nb_unlinks;
}

static int
sso_hw_lf_cfg(struct otx2_mbox *mbox, enum otx2_sso_lf_type type,
	      uint16_t nb_lf, uint8_t attach)
{
	if (attach) {
		struct rsrc_attach_req *req;

		req = otx2_mbox_alloc_msg_attach_resources(mbox);
		switch (type) {
		case SSO_LF_GGRP:
			req->sso = nb_lf;
			break;
		case SSO_LF_GWS:
			req->ssow = nb_lf;
			break;
		default:
			return -EINVAL;
		}
		req->modify = true;
		if (otx2_mbox_process(mbox) < 0)
			return -EIO;
	} else {
		struct rsrc_detach_req *req;

		req = otx2_mbox_alloc_msg_detach_resources(mbox);
		switch (type) {
		case SSO_LF_GGRP:
			req->sso = true;
			break;
		case SSO_LF_GWS:
			req->ssow = true;
			break;
		default:
			return -EINVAL;
		}
		req->partial = true;
		if (otx2_mbox_process(mbox) < 0)
			return -EIO;
	}

	return 0;
}

static int
sso_lf_cfg(struct otx2_sso_evdev *dev, struct otx2_mbox *mbox,
	   enum otx2_sso_lf_type type, uint16_t nb_lf, uint8_t alloc)
{
	void *rsp;
	int rc;

	if (alloc) {
		switch (type) {
		case SSO_LF_GGRP:
			{
			struct sso_lf_alloc_req *req_ggrp;
			req_ggrp = otx2_mbox_alloc_msg_sso_lf_alloc(mbox);
			req_ggrp->hwgrps = nb_lf;
			}
			break;
		case SSO_LF_GWS:
			{
			struct ssow_lf_alloc_req *req_hws;
			req_hws = otx2_mbox_alloc_msg_ssow_lf_alloc(mbox);
			req_hws->hws = nb_lf;
			}
			break;
		default:
			return -EINVAL;
		}
	} else {
		switch (type) {
		case SSO_LF_GGRP:
			{
			struct sso_lf_free_req *req_ggrp;
			req_ggrp = otx2_mbox_alloc_msg_sso_lf_free(mbox);
			req_ggrp->hwgrps = nb_lf;
			}
			break;
		case SSO_LF_GWS:
			{
			struct ssow_lf_free_req *req_hws;
			req_hws = otx2_mbox_alloc_msg_ssow_lf_free(mbox);
			req_hws->hws = nb_lf;
			}
			break;
		default:
			return -EINVAL;
		}
	}

	rc = otx2_mbox_process_msg_tmo(mbox, (void **)&rsp, ~0);
	if (rc < 0)
		return rc;

	if (alloc && type == SSO_LF_GGRP) {
		struct sso_lf_alloc_rsp *rsp_ggrp = rsp;

		dev->xaq_buf_size = rsp_ggrp->xaq_buf_size;
		dev->xae_waes = rsp_ggrp->xaq_wq_entries;
		dev->iue = rsp_ggrp->in_unit_entries;
	}

	return 0;
}

static void
otx2_sso_port_release(void *port)
{
	rte_free(port);
}

static void
otx2_sso_queue_release(struct rte_eventdev *event_dev, uint8_t queue_id)
{
	RTE_SET_USED(event_dev);
	RTE_SET_USED(queue_id);
}

static void
sso_clr_links(const struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	int i, j;

	for (i = 0; i < dev->nb_event_ports; i++) {
		if (dev->dual_ws) {
			struct otx2_ssogws_dual *ws;

			ws = event_dev->data->ports[i];
			for (j = 0; j < dev->nb_event_queues; j++) {
				sso_port_link_modify((struct otx2_ssogws *)
						&ws->ws_state[0], j, false);
				sso_port_link_modify((struct otx2_ssogws *)
						&ws->ws_state[1], j, false);
			}
		} else {
			struct otx2_ssogws *ws;

			ws = event_dev->data->ports[i];
			for (j = 0; j < dev->nb_event_queues; j++)
				sso_port_link_modify(ws, j, false);
		}
	}
}

static void
sso_set_port_ops(struct otx2_ssogws *ws, uintptr_t base)
{
	ws->tag_op		= base + SSOW_LF_GWS_TAG;
	ws->wqp_op		= base + SSOW_LF_GWS_WQP;
	ws->getwrk_op		= base + SSOW_LF_GWS_OP_GET_WORK;
	ws->swtp_op		= base + SSOW_LF_GWS_SWTP;
	ws->swtag_norm_op	= base + SSOW_LF_GWS_OP_SWTAG_NORM;
	ws->swtag_desched_op	= base + SSOW_LF_GWS_OP_SWTAG_DESCHED;
}

static int
sso_configure_dual_ports(const struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	struct otx2_mbox *mbox = dev->mbox;
	uint8_t vws = 0;
	uint8_t nb_lf;
	int i, rc;

	otx2_sso_dbg("Configuring event ports %d", dev->nb_event_ports);

	nb_lf = dev->nb_event_ports * 2;
	/* Ask AF to attach required LFs. */
	rc = sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, true);
	if (rc < 0) {
		otx2_err("Failed to attach SSO GWS LF");
		return -ENODEV;
	}

	if (sso_lf_cfg(dev, mbox, SSO_LF_GWS, nb_lf, true) < 0) {
		sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, false);
		otx2_err("Failed to init SSO GWS LF");
		return -ENODEV;
	}

	for (i = 0; i < dev->nb_event_ports; i++) {
		struct otx2_ssogws_dual *ws;
		uintptr_t base;

		/* Free memory prior to re-allocation if needed */
		if (event_dev->data->ports[i] != NULL) {
			ws = event_dev->data->ports[i];
			rte_free(ws);
			ws = NULL;
		}

		/* Allocate event port memory */
		ws = rte_zmalloc_socket("otx2_sso_ws",
					sizeof(struct otx2_ssogws_dual),
					RTE_CACHE_LINE_SIZE,
					event_dev->data->socket_id);
		if (ws == NULL) {
			otx2_err("Failed to alloc memory for port=%d", i);
			rc = -ENOMEM;
			break;
		}

		ws->port = i;
		base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | vws << 12);
		sso_set_port_ops((struct otx2_ssogws *)&ws->ws_state[0], base);
		vws++;

		base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | vws << 12);
		sso_set_port_ops((struct otx2_ssogws *)&ws->ws_state[1], base);
		vws++;

		event_dev->data->ports[i] = ws;
	}

	if (rc < 0) {
		sso_lf_cfg(dev, mbox, SSO_LF_GWS, nb_lf, false);
		sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, false);
	}

	return rc;
}

static int
sso_configure_ports(const struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	struct otx2_mbox *mbox = dev->mbox;
	uint8_t nb_lf;
	int i, rc;

	otx2_sso_dbg("Configuring event ports %d", dev->nb_event_ports);

	nb_lf = dev->nb_event_ports;
	/* Ask AF to attach required LFs. */
	rc = sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, true);
	if (rc < 0) {
		otx2_err("Failed to attach SSO GWS LF");
		return -ENODEV;
	}

	if (sso_lf_cfg(dev, mbox, SSO_LF_GWS, nb_lf, true) < 0) {
		sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, false);
		otx2_err("Failed to init SSO GWS LF");
		return -ENODEV;
	}

	for (i = 0; i < nb_lf; i++) {
		struct otx2_ssogws *ws;
		uintptr_t base;

		/* Free memory prior to re-allocation if needed */
		if (event_dev->data->ports[i] != NULL) {
			ws = event_dev->data->ports[i];
			rte_free(ws);
			ws = NULL;
		}

		/* Allocate event port memory */
		ws = rte_zmalloc_socket("otx2_sso_ws",
					sizeof(struct otx2_ssogws),
					RTE_CACHE_LINE_SIZE,
					event_dev->data->socket_id);
		if (ws == NULL) {
			otx2_err("Failed to alloc memory for port=%d", i);
			rc = -ENOMEM;
			break;
		}

		ws->port = i;
		base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | i << 12);
		sso_set_port_ops(ws, base);

		event_dev->data->ports[i] = ws;
	}

	if (rc < 0) {
		sso_lf_cfg(dev, mbox, SSO_LF_GWS, nb_lf, false);
		sso_hw_lf_cfg(mbox, SSO_LF_GWS, nb_lf, false);
	}

	return rc;
}

static int
sso_configure_queues(const struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	struct otx2_mbox *mbox = dev->mbox;
	uint8_t nb_lf;
	int rc;

	otx2_sso_dbg("Configuring event queues %d", dev->nb_event_queues);

	nb_lf = dev->nb_event_queues;
	/* Ask AF to attach required LFs. */
	rc = sso_hw_lf_cfg(mbox, SSO_LF_GGRP, nb_lf, true);
	if (rc < 0) {
		otx2_err("Failed to attach SSO GGRP LF");
		return -ENODEV;
	}

	if (sso_lf_cfg(dev, mbox, SSO_LF_GGRP, nb_lf, true) < 0) {
		sso_hw_lf_cfg(mbox, SSO_LF_GGRP, nb_lf, false);
		otx2_err("Failed to init SSO GGRP LF");
		return -ENODEV;
	}

	return rc;
}

static int
sso_xaq_allocate(struct otx2_sso_evdev *dev)
{
	const struct rte_memzone *mz;
	struct npa_aura_s *aura;
	static int reconfig_cnt;
	char pool_name[RTE_MEMZONE_NAMESIZE];
	uint32_t xaq_cnt;
	int rc;

	if (dev->xaq_pool)
		rte_mempool_free(dev->xaq_pool);

	/*
	 * Allocate memory for Add work backpressure.
	 */
	mz = rte_memzone_lookup(OTX2_SSO_FC_NAME);
	if (mz == NULL)
		mz = rte_memzone_reserve_aligned(OTX2_SSO_FC_NAME,
						 OTX2_ALIGN +
						 sizeof(struct npa_aura_s),
						 rte_socket_id(),
						 RTE_MEMZONE_IOVA_CONTIG,
						 OTX2_ALIGN);
	if (mz == NULL) {
		otx2_err("Failed to allocate mem for fcmem");
		return -ENOMEM;
	}

	dev->fc_iova = mz->iova;
	dev->fc_mem = mz->addr;

	aura = (struct npa_aura_s *)((uintptr_t)dev->fc_mem + OTX2_ALIGN);
	memset(aura, 0, sizeof(struct npa_aura_s));

	aura->fc_ena = 1;
	aura->fc_addr = dev->fc_iova;
	aura->fc_hyst_bits = 0; /* Store count on all updates */

	/* Taken from HRM 14.3.3(4) */
	xaq_cnt = dev->nb_event_queues * OTX2_SSO_XAQ_CACHE_CNT;
	if (dev->xae_cnt)
		xaq_cnt += dev->xae_cnt / dev->xae_waes;
	else if (dev->adptr_xae_cnt)
		xaq_cnt += (dev->adptr_xae_cnt / dev->xae_waes) +
			(OTX2_SSO_XAQ_SLACK * dev->nb_event_queues);
	else
		xaq_cnt += (dev->iue / dev->xae_waes) +
			(OTX2_SSO_XAQ_SLACK * dev->nb_event_queues);

	otx2_sso_dbg("Configuring %d xaq buffers", xaq_cnt);
	/* Setup XAQ based on number of nb queues. */
	snprintf(pool_name, 30, "otx2_xaq_buf_pool_%d", reconfig_cnt);
	dev->xaq_pool = (void *)rte_mempool_create_empty(pool_name,
			xaq_cnt, dev->xaq_buf_size, 0, 0,
			rte_socket_id(), 0);

	if (dev->xaq_pool == NULL) {
		otx2_err("Unable to create empty mempool.");
		rte_memzone_free(mz);
		return -ENOMEM;
	}

	rc = rte_mempool_set_ops_byname(dev->xaq_pool,
					rte_mbuf_platform_mempool_ops(), aura);
	if (rc != 0) {
		otx2_err("Unable to set xaqpool ops.");
		goto alloc_fail;
	}

	rc = rte_mempool_populate_default(dev->xaq_pool);
	if (rc < 0) {
		otx2_err("Unable to set populate xaqpool.");
		goto alloc_fail;
	}
	reconfig_cnt++;
	/* When SW does addwork (enqueue) check if there is space in XAQ by
	 * comparing fc_addr above against the xaq_lmt calculated below.
	 * There should be a minimum headroom (OTX2_SSO_XAQ_SLACK / 2) for SSO
	 * to request XAQ to cache them even before enqueue is called.
	 */
	dev->xaq_lmt = xaq_cnt - (OTX2_SSO_XAQ_SLACK / 2 *
				  dev->nb_event_queues);
	dev->nb_xaq_cfg = xaq_cnt;

	return 0;
alloc_fail:
	rte_mempool_free(dev->xaq_pool);
	rte_memzone_free(mz);
	return rc;
}

static int
sso_ggrp_alloc_xaq(struct otx2_sso_evdev *dev)
{
	struct otx2_mbox *mbox = dev->mbox;
	struct sso_hw_setconfig *req;

	otx2_sso_dbg("Configuring XAQ for GGRPs");
	req = otx2_mbox_alloc_msg_sso_hw_setconfig(mbox);
	req->npa_pf_func = otx2_npa_pf_func_get();
	req->npa_aura_id = npa_lf_aura_handle_to_aura(dev->xaq_pool->pool_id);
	req->hwgrps = dev->nb_event_queues;

	return otx2_mbox_process(mbox);
}

static void
sso_lf_teardown(struct otx2_sso_evdev *dev,
		enum otx2_sso_lf_type lf_type)
{
	uint8_t nb_lf;

	switch (lf_type) {
	case SSO_LF_GGRP:
		nb_lf = dev->nb_event_queues;
		break;
	case SSO_LF_GWS:
		nb_lf = dev->nb_event_ports;
		nb_lf *= dev->dual_ws ? 2 : 1;
		break;
	default:
		return;
	}

	sso_lf_cfg(dev, dev->mbox, lf_type, nb_lf, false);
	sso_hw_lf_cfg(dev->mbox, lf_type, nb_lf, false);
}

static int
otx2_sso_configure(const struct rte_eventdev *event_dev)
{
	struct rte_event_dev_config *conf = &event_dev->data->dev_conf;
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	uint32_t deq_tmo_ns;
	int rc;

	sso_func_trace();
	deq_tmo_ns = conf->dequeue_timeout_ns;

	if (deq_tmo_ns == 0)
		deq_tmo_ns = dev->min_dequeue_timeout_ns;

	if (deq_tmo_ns < dev->min_dequeue_timeout_ns ||
	    deq_tmo_ns > dev->max_dequeue_timeout_ns) {
		otx2_err("Unsupported dequeue timeout requested");
		return -EINVAL;
	}

	if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT)
		dev->is_timeout_deq = 1;

	dev->deq_tmo_ns = deq_tmo_ns;

	if (conf->nb_event_ports > dev->max_event_ports ||
	    conf->nb_event_queues > dev->max_event_queues) {
		otx2_err("Unsupported event queues/ports requested");
		return -EINVAL;
	}

	if (conf->nb_event_port_dequeue_depth > 1) {
		otx2_err("Unsupported event port deq depth requested");
		return -EINVAL;
	}

	if (conf->nb_event_port_enqueue_depth > 1) {
		otx2_err("Unsupported event port enq depth requested");
		return -EINVAL;
	}

	if (dev->configured)
		sso_unregister_irqs(event_dev);

	if (dev->nb_event_queues) {
		/* Finit any previous queues. */
		sso_lf_teardown(dev, SSO_LF_GGRP);
	}
	if (dev->nb_event_ports) {
		/* Finit any previous ports. */
		sso_lf_teardown(dev, SSO_LF_GWS);
	}

	dev->nb_event_queues = conf->nb_event_queues;
	dev->nb_event_ports = conf->nb_event_ports;

	if (dev->dual_ws)
		rc = sso_configure_dual_ports(event_dev);
	else
		rc = sso_configure_ports(event_dev);

	if (rc < 0) {
		otx2_err("Failed to configure event ports");
		return -ENODEV;
	}

	if (sso_configure_queues(event_dev) < 0) {
		otx2_err("Failed to configure event queues");
		rc = -ENODEV;
		goto teardown_hws;
	}

	if (sso_xaq_allocate(dev) < 0) {
		rc = -ENOMEM;
		goto teardown_hwggrp;
	}

	/* Clear any prior port-queue mapping. */
	sso_clr_links(event_dev);
	rc = sso_ggrp_alloc_xaq(dev);
	if (rc < 0) {
		otx2_err("Failed to alloc xaq to ggrp %d", rc);
		goto teardown_hwggrp;
	}

	rc = sso_get_msix_offsets(event_dev);
	if (rc < 0) {
		otx2_err("Failed to get msix offsets %d", rc);
		goto teardown_hwggrp;
	}

	rc = sso_register_irqs(event_dev);
	if (rc < 0) {
		otx2_err("Failed to register irq %d", rc);
		goto teardown_hwggrp;
	}

	dev->configured = 1;
	rte_mb();

	return 0;
teardown_hwggrp:
	sso_lf_teardown(dev, SSO_LF_GGRP);
teardown_hws:
	sso_lf_teardown(dev, SSO_LF_GWS);
	dev->nb_event_queues = 0;
	dev->nb_event_ports = 0;
	dev->configured = 0;
	return rc;
}

static void
otx2_sso_queue_def_conf(struct rte_eventdev *event_dev, uint8_t queue_id,
			struct rte_event_queue_conf *queue_conf)
{
	RTE_SET_USED(event_dev);
	RTE_SET_USED(queue_id);

	queue_conf->nb_atomic_flows = (1ULL << 20);
	queue_conf->nb_atomic_order_sequences = (1ULL << 20);
	queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
	queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
}

static int
otx2_sso_queue_setup(struct rte_eventdev *event_dev, uint8_t queue_id,
		     const struct rte_event_queue_conf *queue_conf)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	struct otx2_mbox *mbox = dev->mbox;
	struct sso_grp_priority *req;
	int rc;

	sso_func_trace("Queue=%d prio=%d", queue_id, queue_conf->priority);

	req = otx2_mbox_alloc_msg_sso_grp_set_priority(dev->mbox);
	req->grp = queue_id;
	req->weight = 0xFF;
	req->affinity = 0xFF;
	/* Normalize <0-255> to <0-7> */
	req->priority = queue_conf->priority / 32;

	rc = otx2_mbox_process(mbox);
	if (rc < 0) {
		otx2_err("Failed to set priority queue=%d", queue_id);
		return rc;
	}

	return 0;
}

static void
otx2_sso_port_def_conf(struct rte_eventdev *event_dev, uint8_t port_id,
		       struct rte_event_port_conf *port_conf)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);

	RTE_SET_USED(port_id);
	port_conf->new_event_threshold = dev->max_num_events;
	port_conf->dequeue_depth = 1;
	port_conf->enqueue_depth = 1;
}

static int
otx2_sso_port_setup(struct rte_eventdev *event_dev, uint8_t port_id,
		    const struct rte_event_port_conf *port_conf)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	uintptr_t grps_base[OTX2_SSO_MAX_VHGRP] = {0};
	uint64_t val;
	uint16_t q;

	sso_func_trace("Port=%d", port_id);
	RTE_SET_USED(port_conf);

	if (event_dev->data->ports[port_id] == NULL) {
		otx2_err("Invalid port Id %d", port_id);
		return -EINVAL;
	}

	for (q = 0; q < dev->nb_event_queues; q++) {
		grps_base[q] = dev->bar2 + (RVU_BLOCK_ADDR_SSO << 20 | q << 12);
		if (grps_base[q] == 0) {
			otx2_err("Failed to get grp[%d] base addr", q);
			return -EINVAL;
		}
	}

	/* Set get_work timeout for HWS */
	val = NSEC2USEC(dev->deq_tmo_ns) - 1;

	if (dev->dual_ws) {
		struct otx2_ssogws_dual *ws = event_dev->data->ports[port_id];

		rte_memcpy(ws->grps_base, grps_base,
			   sizeof(uintptr_t) * OTX2_SSO_MAX_VHGRP);
		ws->fc_mem = dev->fc_mem;
		ws->xaq_lmt = dev->xaq_lmt;
		ws->tstamp = dev->tstamp;
		otx2_write64(val, OTX2_SSOW_GET_BASE_ADDR(
			     ws->ws_state[0].getwrk_op) + SSOW_LF_GWS_NW_TIM);
		otx2_write64(val, OTX2_SSOW_GET_BASE_ADDR(
			     ws->ws_state[1].getwrk_op) + SSOW_LF_GWS_NW_TIM);
	} else {
		struct otx2_ssogws *ws = event_dev->data->ports[port_id];
		uintptr_t base = OTX2_SSOW_GET_BASE_ADDR(ws->getwrk_op);

		rte_memcpy(ws->grps_base, grps_base,
			   sizeof(uintptr_t) * OTX2_SSO_MAX_VHGRP);
		ws->fc_mem = dev->fc_mem;
		ws->xaq_lmt = dev->xaq_lmt;
		ws->tstamp = dev->tstamp;
		otx2_write64(val, base + SSOW_LF_GWS_NW_TIM);
	}

	otx2_sso_dbg("Port=%d ws=%p", port_id, event_dev->data->ports[port_id]);

	return 0;
}

static int
otx2_sso_timeout_ticks(struct rte_eventdev *event_dev, uint64_t ns,
		       uint64_t *tmo_ticks)
{
	RTE_SET_USED(event_dev);
	*tmo_ticks = NSEC2TICK(ns, rte_get_timer_hz());

	return 0;
}

static void
ssogws_dump(struct otx2_ssogws *ws, FILE *f)
{
	uintptr_t base = OTX2_SSOW_GET_BASE_ADDR(ws->getwrk_op);

	fprintf(f, "SSOW_LF_GWS Base addr   0x%" PRIx64 "\n", (uint64_t)base);
	fprintf(f, "SSOW_LF_GWS_LINKS       0x%" PRIx64 "\n",
		otx2_read64(base + SSOW_LF_GWS_LINKS));
	fprintf(f, "SSOW_LF_GWS_PENDWQP     0x%" PRIx64 "\n",
		otx2_read64(base + SSOW_LF_GWS_PENDWQP));
	fprintf(f, "SSOW_LF_GWS_PENDSTATE   0x%" PRIx64 "\n",
		otx2_read64(base + SSOW_LF_GWS_PENDSTATE));
	fprintf(f, "SSOW_LF_GWS_NW_TIM      0x%" PRIx64 "\n",
		otx2_read64(base + SSOW_LF_GWS_NW_TIM));
	fprintf(f, "SSOW_LF_GWS_TAG         0x%" PRIx64 "\n",
		otx2_read64(base + SSOW_LF_GWS_TAG));
	fprintf(f, "SSOW_LF_GWS_WQP         0x%" PRIx64 "\n",
		otx2_read64(base + SSOW_LF_GWS_TAG));
	fprintf(f, "SSOW_LF_GWS_SWTP        0x%" PRIx64 "\n",
		otx2_read64(base + SSOW_LF_GWS_SWTP));
	fprintf(f, "SSOW_LF_GWS_PENDTAG     0x%" PRIx64 "\n",
		otx2_read64(base + SSOW_LF_GWS_PENDTAG));
}

static void
ssoggrp_dump(uintptr_t base, FILE *f)
{
	fprintf(f, "SSO_LF_GGRP Base addr   0x%" PRIx64 "\n", (uint64_t)base);
	fprintf(f, "SSO_LF_GGRP_QCTL        0x%" PRIx64 "\n",
		otx2_read64(base + SSO_LF_GGRP_QCTL));
	fprintf(f, "SSO_LF_GGRP_XAQ_CNT     0x%" PRIx64 "\n",
		otx2_read64(base + SSO_LF_GGRP_XAQ_CNT));
	fprintf(f, "SSO_LF_GGRP_INT_THR     0x%" PRIx64 "\n",
		otx2_read64(base + SSO_LF_GGRP_INT_THR));
	fprintf(f, "SSO_LF_GGRP_INT_CNT     0x%" PRIX64 "\n",
		otx2_read64(base + SSO_LF_GGRP_INT_CNT));
	fprintf(f, "SSO_LF_GGRP_AQ_CNT      0x%" PRIX64 "\n",
		otx2_read64(base + SSO_LF_GGRP_AQ_CNT));
	fprintf(f, "SSO_LF_GGRP_AQ_THR      0x%" PRIX64 "\n",
		otx2_read64(base + SSO_LF_GGRP_AQ_THR));
	fprintf(f, "SSO_LF_GGRP_MISC_CNT    0x%" PRIx64 "\n",
		otx2_read64(base + SSO_LF_GGRP_MISC_CNT));
}

static void
otx2_sso_dump(struct rte_eventdev *event_dev, FILE *f)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	uint8_t queue;
	uint8_t port;

	fprintf(f, "[%s] SSO running in [%s] mode\n", __func__, dev->dual_ws ?
		"dual_ws" : "single_ws");
	/* Dump SSOW registers */
	for (port = 0; port < dev->nb_event_ports; port++) {
		if (dev->dual_ws) {
			struct otx2_ssogws_dual *ws =
				event_dev->data->ports[port];

			fprintf(f, "[%s] SSO dual workslot[%d] vws[%d] dump\n",
				__func__, port, 0);
			ssogws_dump((struct otx2_ssogws *)&ws->ws_state[0], f);
			fprintf(f, "[%s]SSO dual workslot[%d] vws[%d] dump\n",
				__func__, port, 1);
			ssogws_dump((struct otx2_ssogws *)&ws->ws_state[1], f);
		} else {
			fprintf(f, "[%s]SSO single workslot[%d] dump\n",
				__func__, port);
			ssogws_dump(event_dev->data->ports[port], f);
		}
	}

	/* Dump SSO registers */
	for (queue = 0; queue < dev->nb_event_queues; queue++) {
		fprintf(f, "[%s]SSO group[%d] dump\n", __func__, queue);
		if (dev->dual_ws) {
			struct otx2_ssogws_dual *ws = event_dev->data->ports[0];
			ssoggrp_dump(ws->grps_base[queue], f);
		} else {
			struct otx2_ssogws *ws = event_dev->data->ports[0];
			ssoggrp_dump(ws->grps_base[queue], f);
		}
	}
}

static void
otx2_handle_event(void *arg, struct rte_event event)
{
	struct rte_eventdev *event_dev = arg;

	if (event_dev->dev_ops->dev_stop_flush != NULL)
		event_dev->dev_ops->dev_stop_flush(event_dev->data->dev_id,
				event, event_dev->data->dev_stop_flush_arg);
}

static void
sso_qos_cfg(struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	struct sso_grp_qos_cfg *req;
	uint16_t i;

	for (i = 0; i < dev->qos_queue_cnt; i++) {
		uint8_t xaq_prcnt = dev->qos_parse_data[i].xaq_prcnt;
		uint8_t iaq_prcnt = dev->qos_parse_data[i].iaq_prcnt;
		uint8_t taq_prcnt = dev->qos_parse_data[i].taq_prcnt;

		if (dev->qos_parse_data[i].queue >= dev->nb_event_queues)
			continue;

		req = otx2_mbox_alloc_msg_sso_grp_qos_config(dev->mbox);
		req->xaq_limit = (dev->nb_xaq_cfg *
				  (xaq_prcnt ? xaq_prcnt : 100)) / 100;
		req->taq_thr = (SSO_HWGRP_IAQ_MAX_THR_MASK *
				(iaq_prcnt ? iaq_prcnt : 100)) / 100;
		req->iaq_thr = (SSO_HWGRP_TAQ_MAX_THR_MASK *
				(taq_prcnt ? taq_prcnt : 100)) / 100;
	}

	if (dev->qos_queue_cnt)
		otx2_mbox_process(dev->mbox);
}

static void
sso_cleanup(struct rte_eventdev *event_dev, uint8_t enable)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	uint16_t i;

	for (i = 0; i < dev->nb_event_ports; i++) {
		if (dev->dual_ws) {
			struct otx2_ssogws_dual *ws;

			ws = event_dev->data->ports[i];
			ssogws_reset((struct otx2_ssogws *)&ws->ws_state[0]);
			ssogws_reset((struct otx2_ssogws *)&ws->ws_state[1]);
			ws->swtag_req = 0;
			ws->vws = 0;
			ws->ws_state[0].cur_grp = 0;
			ws->ws_state[0].cur_tt = SSO_SYNC_EMPTY;
			ws->ws_state[1].cur_grp = 0;
			ws->ws_state[1].cur_tt = SSO_SYNC_EMPTY;
		} else {
			struct otx2_ssogws *ws;

			ws = event_dev->data->ports[i];
			ssogws_reset(ws);
			ws->swtag_req = 0;
			ws->cur_grp = 0;
			ws->cur_tt = SSO_SYNC_EMPTY;
		}
	}

	rte_mb();
	if (dev->dual_ws) {
		struct otx2_ssogws_dual *ws = event_dev->data->ports[0];
		struct otx2_ssogws temp_ws;

		memcpy(&temp_ws, &ws->ws_state[0],
		       sizeof(struct otx2_ssogws_state));
		for (i = 0; i < dev->nb_event_queues; i++) {
			/* Consume all the events through HWS0 */
			ssogws_flush_events(&temp_ws, i, ws->grps_base[i],
					    otx2_handle_event, event_dev);
			/* Enable/Disable SSO GGRP */
			otx2_write64(enable, ws->grps_base[i] +
				     SSO_LF_GGRP_QCTL);
		}
		ws->ws_state[0].cur_grp = 0;
		ws->ws_state[0].cur_tt = SSO_SYNC_EMPTY;
	} else {
		struct otx2_ssogws *ws = event_dev->data->ports[0];

		for (i = 0; i < dev->nb_event_queues; i++) {
			/* Consume all the events through HWS0 */
			ssogws_flush_events(ws, i, ws->grps_base[i],
					    otx2_handle_event, event_dev);
			/* Enable/Disable SSO GGRP */
			otx2_write64(enable, ws->grps_base[i] +
				     SSO_LF_GGRP_QCTL);
		}
		ws->cur_grp = 0;
		ws->cur_tt = SSO_SYNC_EMPTY;
	}

	/* reset SSO GWS cache */
	otx2_mbox_alloc_msg_sso_ws_cache_inv(dev->mbox);
	otx2_mbox_process(dev->mbox);
}

int
sso_xae_reconfigure(struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	struct rte_mempool *prev_xaq_pool;
	int rc = 0;

	if (event_dev->data->dev_started)
		sso_cleanup(event_dev, 0);

	prev_xaq_pool = dev->xaq_pool;
	dev->xaq_pool = NULL;
	rc = sso_xaq_allocate(dev);
	if (rc < 0) {
		otx2_err("Failed to alloc xaq pool %d", rc);
		rte_mempool_free(prev_xaq_pool);
		return rc;
	}
	rc = sso_ggrp_alloc_xaq(dev);
	if (rc < 0) {
		otx2_err("Failed to alloc xaq to ggrp %d", rc);
		rte_mempool_free(prev_xaq_pool);
		return rc;
	}

	rte_mempool_free(prev_xaq_pool);
	rte_mb();
	if (event_dev->data->dev_started)
		sso_cleanup(event_dev, 1);

	return 0;
}

static int
otx2_sso_start(struct rte_eventdev *event_dev)
{
	sso_func_trace();
	sso_qos_cfg(event_dev);
	sso_cleanup(event_dev, 1);
	sso_fastpath_fns_set(event_dev);

	return 0;
}

static void
otx2_sso_stop(struct rte_eventdev *event_dev)
{
	sso_func_trace();
	sso_cleanup(event_dev, 0);
	rte_mb();
}

static int
otx2_sso_close(struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
	uint16_t i;

	if (!dev->configured)
		return 0;

	sso_unregister_irqs(event_dev);

	for (i = 0; i < dev->nb_event_queues; i++)
		all_queues[i] = i;

	for (i = 0; i < dev->nb_event_ports; i++)
		otx2_sso_port_unlink(event_dev, event_dev->data->ports[i],
				     all_queues, dev->nb_event_queues);

	sso_lf_teardown(dev, SSO_LF_GGRP);
	sso_lf_teardown(dev, SSO_LF_GWS);
	dev->nb_event_ports = 0;
	dev->nb_event_queues = 0;
	rte_mempool_free(dev->xaq_pool);
	rte_memzone_free(rte_memzone_lookup(OTX2_SSO_FC_NAME));

	return 0;
}

/* Initialize and register event driver with DPDK Application */
static struct rte_eventdev_ops otx2_sso_ops = {
	.dev_infos_get    = otx2_sso_info_get,
	.dev_configure    = otx2_sso_configure,
	.queue_def_conf   = otx2_sso_queue_def_conf,
	.queue_setup      = otx2_sso_queue_setup,
	.queue_release    = otx2_sso_queue_release,
	.port_def_conf    = otx2_sso_port_def_conf,
	.port_setup       = otx2_sso_port_setup,
	.port_release     = otx2_sso_port_release,
	.port_link        = otx2_sso_port_link,
	.port_unlink      = otx2_sso_port_unlink,
	.timeout_ticks    = otx2_sso_timeout_ticks,

	.eth_rx_adapter_caps_get  = otx2_sso_rx_adapter_caps_get,
	.eth_rx_adapter_queue_add = otx2_sso_rx_adapter_queue_add,
	.eth_rx_adapter_queue_del = otx2_sso_rx_adapter_queue_del,
	.eth_rx_adapter_start = otx2_sso_rx_adapter_start,
	.eth_rx_adapter_stop = otx2_sso_rx_adapter_stop,

	.eth_tx_adapter_caps_get = otx2_sso_tx_adapter_caps_get,
	.eth_tx_adapter_queue_add = otx2_sso_tx_adapter_queue_add,
	.eth_tx_adapter_queue_del = otx2_sso_tx_adapter_queue_del,

	.timer_adapter_caps_get = otx2_tim_caps_get,

	.xstats_get       = otx2_sso_xstats_get,
	.xstats_reset     = otx2_sso_xstats_reset,
	.xstats_get_names = otx2_sso_xstats_get_names,

	.dump             = otx2_sso_dump,
	.dev_start        = otx2_sso_start,
	.dev_stop         = otx2_sso_stop,
	.dev_close        = otx2_sso_close,
	.dev_selftest     = otx2_sso_selftest,
};

#define OTX2_SSO_XAE_CNT	"xae_cnt"
#define OTX2_SSO_SINGLE_WS	"single_ws"
#define OTX2_SSO_GGRP_QOS	"qos"
#define OTX2_SSO_SELFTEST	"selftest"

static void
parse_queue_param(char *value, void *opaque)
{
	struct otx2_sso_qos queue_qos = {0};
	uint8_t *val = (uint8_t *)&queue_qos;
	struct otx2_sso_evdev *dev = opaque;
	char *tok = strtok(value, "-");
	struct otx2_sso_qos *old_ptr;

	if (!strlen(value))
		return;

	while (tok != NULL) {
		*val = atoi(tok);
		tok = strtok(NULL, "-");
		val++;
	}

	if (val != (&queue_qos.iaq_prcnt + 1)) {
		otx2_err("Invalid QoS parameter expected [Qx-XAQ-TAQ-IAQ]");
		return;
	}

	dev->qos_queue_cnt++;
	old_ptr = dev->qos_parse_data;
	dev->qos_parse_data = rte_realloc(dev->qos_parse_data,
					  sizeof(struct otx2_sso_qos) *
					  dev->qos_queue_cnt, 0);
	if (dev->qos_parse_data == NULL) {
		dev->qos_parse_data = old_ptr;
		dev->qos_queue_cnt--;
		return;
	}
	dev->qos_parse_data[dev->qos_queue_cnt - 1] = queue_qos;
}

static void
parse_qos_list(const char *value, void *opaque)
{
	char *s = strdup(value);
	char *start = NULL;
	char *end = NULL;
	char *f = s;

	while (*s) {
		if (*s == '[')
			start = s;
		else if (*s == ']')
			end = s;

		if (start && start < end) {
			*end = 0;
			parse_queue_param(start + 1, opaque);
			s = end;
			start = end;
		}
		s++;
	}

	free(f);
}

static int
parse_sso_kvargs_dict(const char *key, const char *value, void *opaque)
{
	RTE_SET_USED(key);

	/* Dict format [Qx-XAQ-TAQ-IAQ][Qz-XAQ-TAQ-IAQ] use '-' cause ','
	 * isn't allowed. Everything is expressed in percentages, 0 represents
	 * default.
	 */
	parse_qos_list(value, opaque);

	return 0;
}

static void
sso_parse_devargs(struct otx2_sso_evdev *dev, struct rte_devargs *devargs)
{
	struct rte_kvargs *kvlist;
	uint8_t single_ws = 0;

	if (devargs == NULL)
		return;
	kvlist = rte_kvargs_parse(devargs->args, NULL);
	if (kvlist == NULL)
		return;

	rte_kvargs_process(kvlist, OTX2_SSO_SELFTEST, &parse_kvargs_flag,
			   &dev->selftest);
	rte_kvargs_process(kvlist, OTX2_SSO_XAE_CNT, &parse_kvargs_value,
			   &dev->xae_cnt);
	rte_kvargs_process(kvlist, OTX2_SSO_SINGLE_WS, &parse_kvargs_flag,
			   &single_ws);
	rte_kvargs_process(kvlist, OTX2_SSO_GGRP_QOS, &parse_sso_kvargs_dict,
			   dev);
	otx2_parse_common_devargs(kvlist);
	dev->dual_ws = !single_ws;
	rte_kvargs_free(kvlist);
}

static int
otx2_sso_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
{
	return rte_event_pmd_pci_probe(pci_drv, pci_dev,
				       sizeof(struct otx2_sso_evdev),
				       otx2_sso_init);
}

static int
otx2_sso_remove(struct rte_pci_device *pci_dev)
{
	return rte_event_pmd_pci_remove(pci_dev, otx2_sso_fini);
}

static const struct rte_pci_id pci_sso_map[] = {
	{
		RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
			       PCI_DEVID_OCTEONTX2_RVU_SSO_TIM_PF)
	},
	{
		.vendor_id = 0,
	},
};

static struct rte_pci_driver pci_sso = {
	.id_table = pci_sso_map,
	.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
	.probe = otx2_sso_probe,
	.remove = otx2_sso_remove,
};

int
otx2_sso_init(struct rte_eventdev *event_dev)
{
	struct free_rsrcs_rsp *rsrc_cnt;
	struct rte_pci_device *pci_dev;
	struct otx2_sso_evdev *dev;
	int rc;

	event_dev->dev_ops = &otx2_sso_ops;
	/* For secondary processes, the primary has done all the work */
	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
		sso_fastpath_fns_set(event_dev);
		return 0;
	}

	dev = sso_pmd_priv(event_dev);

	pci_dev = container_of(event_dev->dev, struct rte_pci_device, device);

	/* Initialize the base otx2_dev object */
	rc = otx2_dev_init(pci_dev, dev);
	if (rc < 0) {
		otx2_err("Failed to initialize otx2_dev rc=%d", rc);
		goto error;
	}

	/* Get SSO and SSOW MSIX rsrc cnt */
	otx2_mbox_alloc_msg_free_rsrc_cnt(dev->mbox);
	rc = otx2_mbox_process_msg(dev->mbox, (void *)&rsrc_cnt);
	if (rc < 0) {
		otx2_err("Unable to get free rsrc count");
		goto otx2_dev_uninit;
	}
	otx2_sso_dbg("SSO %d SSOW %d NPA %d provisioned", rsrc_cnt->sso,
		     rsrc_cnt->ssow, rsrc_cnt->npa);

	dev->max_event_ports = RTE_MIN(rsrc_cnt->ssow, OTX2_SSO_MAX_VHWS);
	dev->max_event_queues = RTE_MIN(rsrc_cnt->sso, OTX2_SSO_MAX_VHGRP);
	/* Grab the NPA LF if required */
	rc = otx2_npa_lf_init(pci_dev, dev);
	if (rc < 0) {
		otx2_err("Unable to init NPA lf. It might not be provisioned");
		goto otx2_dev_uninit;
	}

	dev->drv_inited = true;
	dev->is_timeout_deq = 0;
	dev->min_dequeue_timeout_ns = USEC2NSEC(1);
	dev->max_dequeue_timeout_ns = USEC2NSEC(0x3FF);
	dev->max_num_events = -1;
	dev->nb_event_queues = 0;
	dev->nb_event_ports = 0;

	if (!dev->max_event_ports || !dev->max_event_queues) {
		otx2_err("Not enough eventdev resource queues=%d ports=%d",
			 dev->max_event_queues, dev->max_event_ports);
		rc = -ENODEV;
		goto otx2_npa_lf_uninit;
	}

	dev->dual_ws = 1;
	sso_parse_devargs(dev, pci_dev->device.devargs);
	if (dev->dual_ws) {
		otx2_sso_dbg("Using dual workslot mode");
		dev->max_event_ports = dev->max_event_ports / 2;
	} else {
		otx2_sso_dbg("Using single workslot mode");
	}

	otx2_sso_pf_func_set(dev->pf_func);
	otx2_sso_dbg("Initializing %s max_queues=%d max_ports=%d",
		     event_dev->data->name, dev->max_event_queues,
		     dev->max_event_ports);
	if (dev->selftest) {
		event_dev->dev->driver = &pci_sso.driver;
		event_dev->dev_ops->dev_selftest();
	}

	otx2_tim_init(pci_dev, (struct otx2_dev *)dev);

	return 0;

otx2_npa_lf_uninit:
	otx2_npa_lf_fini();
otx2_dev_uninit:
	otx2_dev_fini(pci_dev, dev);
error:
	return rc;
}

int
otx2_sso_fini(struct rte_eventdev *event_dev)
{
	struct otx2_sso_evdev *dev = sso_pmd_priv(event_dev);
	struct rte_pci_device *pci_dev;

	/* For secondary processes, nothing to be done */
	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
		return 0;

	pci_dev = container_of(event_dev->dev, struct rte_pci_device, device);

	if (!dev->drv_inited)
		goto dev_fini;

	dev->drv_inited = false;
	otx2_npa_lf_fini();

dev_fini:
	if (otx2_npa_lf_active(dev)) {
		otx2_info("Common resource in use by other devices");
		return -EAGAIN;
	}

	otx2_tim_fini();
	otx2_dev_fini(pci_dev, dev);

	return 0;
}

RTE_PMD_REGISTER_PCI(event_octeontx2, pci_sso);
RTE_PMD_REGISTER_PCI_TABLE(event_octeontx2, pci_sso_map);
RTE_PMD_REGISTER_KMOD_DEP(event_octeontx2, "vfio-pci");
RTE_PMD_REGISTER_PARAM_STRING(event_octeontx2, OTX2_SSO_XAE_CNT "=<int>"
			      OTX2_SSO_SINGLE_WS "=1"
			      OTX2_SSO_GGRP_QOS "=<string>"
			      OTX2_SSO_SELFTEST "=1"
			      OTX2_NPA_LOCK_MASK "=<1-65535>");