summaryrefslogtreecommitdiffstats
path: root/external_libs/ibverbs/include/infiniband/verbs_exp.h
blob: 9fef81879c541cb4874fad040233150bbba6757f (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
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
/*
 * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
 * Copyright (c) 2004, 2011-2012 Intel Corporation.  All rights reserved.
 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2005 PathScale, Inc.  All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef INFINIBAND_VERBS_EXP_H
#define INFINIBAND_VERBS_EXP_H

#include <infiniband/verbs.h>
#include <stdio.h>
#include <stdlib.h>

#if __GNUC__ >= 3
#  define __attribute_const __attribute__((const))
#else
#  define __attribute_const
#endif

BEGIN_C_DECLS

#define IBV_EXP_RET_ON_INVALID_COMP_MASK(val, valid_mask, ret)						\
	if ((val) > (valid_mask)) {									\
		fprintf(stderr, "%s: invalid comp_mask !!! (comp_mask = 0x%x valid_mask = 0x%x)\n",	\
			__FUNCTION__, val, valid_mask);							\
		errno = EINVAL;										\
		return ret;										\
	}

#define IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(val, valid_mask)	\
		IBV_EXP_RET_ON_INVALID_COMP_MASK(val, valid_mask, NULL)

#define IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(val, valid_mask)	\
		IBV_EXP_RET_ON_INVALID_COMP_MASK(val, valid_mask, EINVAL)


#define IBV_EXP_IMPLICIT_MR_SIZE (~((size_t)0))

enum ibv_exp_func_name {
	IBV_EXP_POST_SEND_FUNC,
	IBV_EXP_POLL_CQ_FUNC,
	IBV_POST_SEND_FUNC,
	IBV_POLL_CQ_FUNC,
	IBV_POST_RECV_FUNC
};

enum ibv_exp_start_values {
	IBV_EXP_START_ENUM	= 0x40,
	IBV_EXP_START_FLAG_LOC	= 0x20,
	IBV_EXP_START_FLAG	= (1ULL << IBV_EXP_START_FLAG_LOC),
};

/*
 * Capabilities for exp_atomic_cap field in ibv_exp_device_attr struct
 */
enum ibv_exp_atomic_cap {
	IBV_EXP_ATOMIC_NONE		= IBV_ATOMIC_NONE,
	IBV_EXP_ATOMIC_HCA		= IBV_ATOMIC_HCA,
	IBV_EXP_ATOMIC_GLOB		= IBV_ATOMIC_GLOB,

	IBV_EXP_ATOMIC_HCA_REPLY_BE	= IBV_EXP_START_ENUM /* HOST is LE and atomic reply is BE */
};

/*
 * Flags for exp_device_cap_flags field in ibv_exp_device_attr struct
 */
enum ibv_exp_device_cap_flags {
	IBV_EXP_DEVICE_RESIZE_MAX_WR		= IBV_DEVICE_RESIZE_MAX_WR,
	IBV_EXP_DEVICE_BAD_PKEY_CNTR		= IBV_DEVICE_BAD_PKEY_CNTR,
	IBV_EXP_DEVICE_BAD_QKEY_CNTR		= IBV_DEVICE_BAD_QKEY_CNTR,
	IBV_EXP_DEVICE_RAW_MULTI		= IBV_DEVICE_RAW_MULTI,
	IBV_EXP_DEVICE_AUTO_PATH_MIG		= IBV_DEVICE_AUTO_PATH_MIG,
	IBV_EXP_DEVICE_CHANGE_PHY_PORT		= IBV_DEVICE_CHANGE_PHY_PORT,
	IBV_EXP_DEVICE_UD_AV_PORT_ENFORCE	= IBV_DEVICE_UD_AV_PORT_ENFORCE,
	IBV_EXP_DEVICE_CURR_QP_STATE_MOD	= IBV_DEVICE_CURR_QP_STATE_MOD,
	IBV_EXP_DEVICE_SHUTDOWN_PORT		= IBV_DEVICE_SHUTDOWN_PORT,
	IBV_EXP_DEVICE_INIT_TYPE		= IBV_DEVICE_INIT_TYPE,
	IBV_EXP_DEVICE_PORT_ACTIVE_EVENT	= IBV_DEVICE_PORT_ACTIVE_EVENT,
	IBV_EXP_DEVICE_SYS_IMAGE_GUID		= IBV_DEVICE_SYS_IMAGE_GUID,
	IBV_EXP_DEVICE_RC_RNR_NAK_GEN		= IBV_DEVICE_RC_RNR_NAK_GEN,
	IBV_EXP_DEVICE_SRQ_RESIZE		= IBV_DEVICE_SRQ_RESIZE,
	IBV_EXP_DEVICE_N_NOTIFY_CQ		= IBV_DEVICE_N_NOTIFY_CQ,
	IBV_EXP_DEVICE_XRC			= IBV_DEVICE_XRC,

	IBV_EXP_DEVICE_DC_TRANSPORT		= (IBV_EXP_START_FLAG << 0),
	IBV_EXP_DEVICE_QPG			= (IBV_EXP_START_FLAG << 1),
	IBV_EXP_DEVICE_UD_RSS			= (IBV_EXP_START_FLAG << 2),
	IBV_EXP_DEVICE_UD_TSS			= (IBV_EXP_START_FLAG << 3),
	IBV_EXP_DEVICE_EXT_ATOMICS		= (IBV_EXP_START_FLAG << 4),
	IBV_EXP_DEVICE_NOP			= (IBV_EXP_START_FLAG << 5),
	IBV_EXP_DEVICE_UMR			= (IBV_EXP_START_FLAG << 6),
	IBV_EXP_DEVICE_ODP			= (IBV_EXP_START_FLAG << 7),
	IBV_EXP_DEVICE_VXLAN_SUPPORT		= (IBV_EXP_START_FLAG << 10),
	IBV_EXP_DEVICE_RX_CSUM_TCP_UDP_PKT	= (IBV_EXP_START_FLAG << 11),
	IBV_EXP_DEVICE_RX_CSUM_IP_PKT		= (IBV_EXP_START_FLAG << 12),
	IBV_EXP_DEVICE_EC_OFFLOAD		= (IBV_EXP_START_FLAG << 13),
	IBV_EXP_DEVICE_EXT_MASKED_ATOMICS	= (IBV_EXP_START_FLAG << 14),
	IBV_EXP_DEVICE_RX_TCP_UDP_PKT_TYPE	= (IBV_EXP_START_FLAG << 15),
	IBV_EXP_DEVICE_SCATTER_FCS		= (IBV_EXP_START_FLAG << 16),
	IBV_EXP_DEVICE_MEM_WINDOW		= (IBV_EXP_START_FLAG << 17),
	IBV_EXP_DEVICE_MEM_MGT_EXTENSIONS	= (IBV_EXP_START_FLAG << 21),
	IBV_EXP_DEVICE_DC_INFO			= (IBV_EXP_START_FLAG << 22),
	/* Jumping to 23 as of next capability in include/rdma/ib_verbs.h */
	IBV_EXP_DEVICE_MW_TYPE_2A		= (IBV_EXP_START_FLAG << 23),
	IBV_EXP_DEVICE_MW_TYPE_2B		= (IBV_EXP_START_FLAG << 24),
	IBV_EXP_DEVICE_CROSS_CHANNEL		= (IBV_EXP_START_FLAG << 28),
	IBV_EXP_DEVICE_MANAGED_FLOW_STEERING	= (IBV_EXP_START_FLAG << 29),
	IBV_EXP_DEVICE_MR_ALLOCATE		= (IBV_EXP_START_FLAG << 30),
	IBV_EXP_DEVICE_SHARED_MR		= (IBV_EXP_START_FLAG << 31),
};

/*
 * Flags for ibv_exp_device_attr struct comp_mask.
 */
enum ibv_exp_device_attr_comp_mask {
	IBV_EXP_DEVICE_ATTR_CALC_CAP		= (1 << 0),
	IBV_EXP_DEVICE_ATTR_WITH_TIMESTAMP_MASK	= (1 << 1),
	IBV_EXP_DEVICE_ATTR_WITH_HCA_CORE_CLOCK	= (1 << 2),
	IBV_EXP_DEVICE_ATTR_EXP_CAP_FLAGS	= (1 << 3),
	IBV_EXP_DEVICE_DC_RD_REQ		= (1 << 4),
	IBV_EXP_DEVICE_DC_RD_RES		= (1 << 5),
	IBV_EXP_DEVICE_ATTR_INLINE_RECV_SZ	= (1 << 6),
	IBV_EXP_DEVICE_ATTR_RSS_TBL_SZ		= (1 << 7),
	IBV_EXP_DEVICE_ATTR_EXT_ATOMIC_ARGS	= (1 << 8),
	IBV_EXP_DEVICE_ATTR_UMR                 = (1 << 9),
	IBV_EXP_DEVICE_ATTR_ODP			= (1 << 10),
	IBV_EXP_DEVICE_ATTR_MAX_DCT		= (1 << 11),
	IBV_EXP_DEVICE_ATTR_MAX_CTX_RES_DOMAIN	= (1 << 12),
	IBV_EXP_DEVICE_ATTR_RX_HASH		= (1 << 13),
	IBV_EXP_DEVICE_ATTR_MAX_WQ_TYPE_RQ	= (1 << 14),
	IBV_EXP_DEVICE_ATTR_MAX_DEVICE_CTX	= (1 << 15),
	IBV_EXP_DEVICE_ATTR_MP_RQ		= (1 << 16),
	IBV_EXP_DEVICE_ATTR_VLAN_OFFLOADS	= (1 << 17),
	IBV_EXP_DEVICE_ATTR_EC_CAPS		= (1 << 18),
	IBV_EXP_DEVICE_ATTR_MASKED_ATOMICS	= (1 << 19),
	IBV_EXP_DEVICE_ATTR_RX_PAD_END_ALIGN	= (1 << 20),
	IBV_EXP_DEVICE_ATTR_TSO_CAPS		= (1 << 21),
	IBV_EXP_DEVICE_ATTR_PACKET_PACING_CAPS	= (1 << 22),
	IBV_EXP_DEVICE_ATTR_EC_GF_BASE		= (1 << 23),
	/* set supported bits for validity check */
	IBV_EXP_DEVICE_ATTR_RESERVED		= (1 << 24),
};

struct ibv_exp_device_calc_cap {
	uint64_t		data_types;
	uint64_t		data_sizes;
	uint64_t		int_ops;
	uint64_t		uint_ops;
	uint64_t		fp_ops;
};

struct ibv_exp_ext_atomics_params {
	/* defines which masked operation sizes are supported with same
	 * endianness as stated in atomic_cap field
	 */
	uint64_t		log_atomic_arg_sizes; /* bit-mask of supported sizes */
	uint32_t		max_fa_bit_boundary;
	uint32_t		log_max_atomic_inline;
};

struct ibv_exp_masked_atomic_params {
	uint32_t	max_fa_bit_boundary;
	uint32_t	log_max_atomic_inline;
	uint64_t	masked_log_atomic_arg_sizes;
	uint64_t	masked_log_atomic_arg_sizes_network_endianness;
};

enum ibv_odp_general_cap_bits {
	IBV_EXP_ODP_SUPPORT = 1 << 0,
};

enum ibv_exp_odp_transport_cap_bits {
	IBV_EXP_ODP_SUPPORT_SEND     = 1 << 0,
	IBV_EXP_ODP_SUPPORT_RECV     = 1 << 1,
	IBV_EXP_ODP_SUPPORT_WRITE    = 1 << 2,
	IBV_EXP_ODP_SUPPORT_READ     = 1 << 3,
	IBV_EXP_ODP_SUPPORT_ATOMIC   = 1 << 4,
	IBV_EXP_ODP_SUPPORT_SRQ_RECV = 1 << 5,
};

struct ibv_exp_umr_caps {
	uint32_t                max_klm_list_size;
	uint32_t                max_send_wqe_inline_klms;
	uint32_t                max_umr_recursion_depth;
	uint32_t                max_umr_stride_dimension;
};

struct ibv_exp_odp_caps {
	uint64_t	general_odp_caps;
	struct {
		uint32_t	rc_odp_caps;
		uint32_t	uc_odp_caps;
		uint32_t	ud_odp_caps;
		uint32_t	dc_odp_caps;
		uint32_t	xrc_odp_caps;
		uint32_t	raw_eth_odp_caps;
	} per_transport_caps;
};

enum ibv_exp_supported_qp_types {
	IBV_EXP_QPT_RC		= 1ULL << 0,
	IBV_EXP_QPT_UC		= 1ULL << 1,
	IBV_EXP_QPT_UD		= 1ULL << 2,
	IBV_EXP_QPT_XRC_INIT	= 1ULL << 3,
	IBV_EXP_QPT_XRC_TGT	= 1ULL << 4,
	IBV_EXP_QPT_RAW_PACKET	= 1ULL << 5,
	IBV_EXP_QPT_RESERVED	= 1ULL << 6
};

struct ibv_exp_rx_hash_caps {
	uint32_t max_rwq_indirection_tables;
	uint32_t max_rwq_indirection_table_size;
	uint8_t  supported_hash_functions; /* from ibv_exp_rx_hash_function_flags */
	uint64_t supported_packet_fields;  /* from ibv_exp_rx_hash_fields */
	uint32_t supported_qps;		   /* from ibv_exp_supported_qp_types */
};

enum ibv_exp_mp_rq_shifts {
	IBV_EXP_MP_RQ_NO_SHIFT		= 0,
	IBV_EXP_MP_RQ_2BYTES_SHIFT	= 1 << 0
};

struct ibv_exp_mp_rq_caps {
	uint32_t supported_qps; /* use ibv_exp_supported_qp_types */
	uint32_t allowed_shifts; /* use ibv_exp_mp_rq_shifts */
	uint8_t min_single_wqe_log_num_of_strides;
	uint8_t max_single_wqe_log_num_of_strides;
	uint8_t min_single_stride_log_num_of_bytes;
	uint8_t max_single_stride_log_num_of_bytes;
};

struct ibv_exp_ec_caps {
	uint32_t	max_ec_data_vector_count;
	uint32_t	max_ec_calc_inflight_calcs;
};

#define ibv_is_qpt_supported(caps, qpt) ((caps) & (1 << (qpt)))

struct ibv_exp_tso_caps {
	uint32_t max_tso;
	uint32_t supported_qpts;
};

struct ibv_exp_packet_pacing_caps {
	uint32_t qp_rate_limit_min;
	uint32_t qp_rate_limit_max; /* In kbps */
	uint32_t supported_qpts;
	uint32_t reserved;
};

struct ibv_exp_device_attr {
	char			fw_ver[64];
	uint64_t		node_guid;
	uint64_t		sys_image_guid;
	uint64_t		max_mr_size;
	uint64_t		page_size_cap;
	uint32_t		vendor_id;
	uint32_t		vendor_part_id;
	uint32_t		hw_ver;
	int			max_qp;
	int			max_qp_wr;
	int			reserved; /* place holder to align with ibv_device_attr */
	int			max_sge;
	int			max_sge_rd;
	int			max_cq;
	int			max_cqe;
	int			max_mr;
	int			max_pd;
	int			max_qp_rd_atom;
	int			max_ee_rd_atom;
	int			max_res_rd_atom;
	int			max_qp_init_rd_atom;
	int			max_ee_init_rd_atom;
	enum ibv_exp_atomic_cap	exp_atomic_cap;
	int			max_ee;
	int			max_rdd;
	int			max_mw;
	int			max_raw_ipv6_qp;
	int			max_raw_ethy_qp;
	int			max_mcast_grp;
	int			max_mcast_qp_attach;
	int			max_total_mcast_qp_attach;
	int			max_ah;
	int			max_fmr;
	int			max_map_per_fmr;
	int			max_srq;
	int			max_srq_wr;
	int			max_srq_sge;
	uint16_t		max_pkeys;
	uint8_t			local_ca_ack_delay;
	uint8_t			phys_port_cnt;
	uint32_t                comp_mask;
	struct ibv_exp_device_calc_cap calc_cap;
	uint64_t		timestamp_mask;
	uint64_t		hca_core_clock;
	uint64_t		exp_device_cap_flags; /* use ibv_exp_device_cap_flags */
	int			max_dc_req_rd_atom;
	int			max_dc_res_rd_atom;
	int			inline_recv_sz;
	uint32_t		max_rss_tbl_sz;
	struct ibv_exp_ext_atomics_params ext_atom;
	struct ibv_exp_umr_caps umr_caps;
	struct ibv_exp_odp_caps	odp_caps;
	int			max_dct;
	int			max_ctx_res_domain;
	struct ibv_exp_rx_hash_caps	rx_hash_caps;
	uint32_t			max_wq_type_rq;
	int 				max_device_ctx;
	struct ibv_exp_mp_rq_caps	mp_rq_caps;
	uint16_t		wq_vlan_offloads_cap; /* use ibv_exp_vlan_offloads enum */
	struct ibv_exp_ec_caps         ec_caps;
	struct ibv_exp_masked_atomic_params masked_atomic;
	/*
	 * The alignment of the padding end address.
	 * When RX end of packet padding is enabled the device will pad the end
	 * of RX packet up until the next address which is aligned to the
	 * rx_pad_end_addr_align size.
	 * Expected size for this field is according to system cache line size,
	 * for example 64 or 128. When field is 0 padding is not supported.
	 */
	int			rx_pad_end_addr_align;
	struct ibv_exp_tso_caps	tso_caps;
	struct ibv_exp_packet_pacing_caps packet_pacing_caps;
	uint32_t ec_w_mask;
};

enum {
	IBV_EXP_ACCESS_FLAGS_SHIFT = 0x0F
};

enum ibv_exp_access_flags {
	IBV_EXP_ACCESS_LOCAL_WRITE	= IBV_ACCESS_LOCAL_WRITE,
	IBV_EXP_ACCESS_REMOTE_WRITE	= IBV_ACCESS_REMOTE_WRITE,
	IBV_EXP_ACCESS_REMOTE_READ	= IBV_ACCESS_REMOTE_READ,
	IBV_EXP_ACCESS_REMOTE_ATOMIC	= IBV_ACCESS_REMOTE_ATOMIC,
	IBV_EXP_ACCESS_MW_BIND		= IBV_ACCESS_MW_BIND,

	IBV_EXP_ACCESS_ALLOCATE_MR		= (IBV_EXP_START_FLAG << 5),
	IBV_EXP_ACCESS_SHARED_MR_USER_READ	= (IBV_EXP_START_FLAG << 6),
	IBV_EXP_ACCESS_SHARED_MR_USER_WRITE	= (IBV_EXP_START_FLAG << 7),
	IBV_EXP_ACCESS_SHARED_MR_GROUP_READ	= (IBV_EXP_START_FLAG << 8),
	IBV_EXP_ACCESS_SHARED_MR_GROUP_WRITE	= (IBV_EXP_START_FLAG << 9),
	IBV_EXP_ACCESS_SHARED_MR_OTHER_READ	= (IBV_EXP_START_FLAG << 10),
	IBV_EXP_ACCESS_SHARED_MR_OTHER_WRITE	= (IBV_EXP_START_FLAG << 11),
	IBV_EXP_ACCESS_NO_RDMA			= (IBV_EXP_START_FLAG << 12),
	IBV_EXP_ACCESS_MW_ZERO_BASED		= (IBV_EXP_START_FLAG << 13),
	IBV_EXP_ACCESS_ON_DEMAND		= (IBV_EXP_START_FLAG << 14),
	IBV_EXP_ACCESS_RELAXED			= (IBV_EXP_START_FLAG << 15),
	IBV_EXP_ACCESS_PHYSICAL_ADDR		= (IBV_EXP_START_FLAG << 16),
	/* set supported bits for validity check */
	IBV_EXP_ACCESS_RESERVED			= (IBV_EXP_START_FLAG << 17)
};

/* memory window information struct that is common to types 1 and 2 */
struct ibv_exp_mw_bind_info {
	struct ibv_mr	*mr;
	uint64_t	 addr;
	uint64_t	 length;
	uint64_t	 exp_mw_access_flags; /* use ibv_exp_access_flags */
};

/*
 * Flags for ibv_exp_mw_bind struct comp_mask
 */
enum ibv_exp_bind_mw_comp_mask {
	IBV_EXP_BIND_MW_RESERVED	= (1 << 0)
};

/* type 1 specific info */
struct ibv_exp_mw_bind {
	struct ibv_qp			*qp;
	struct ibv_mw			*mw;
	uint64_t			 wr_id;
	uint64_t			 exp_send_flags; /* use ibv_exp_send_flags */
	struct ibv_exp_mw_bind_info	 bind_info;
	uint32_t			 comp_mask; /* reserved for future growth (must be 0) */
};

enum ibv_exp_calc_op {
	IBV_EXP_CALC_OP_ADD	= 0,
	IBV_EXP_CALC_OP_MAXLOC,
	IBV_EXP_CALC_OP_BAND,
	IBV_EXP_CALC_OP_BXOR,
	IBV_EXP_CALC_OP_BOR,
	IBV_EXP_CALC_OP_NUMBER
};

enum ibv_exp_calc_data_type {
	IBV_EXP_CALC_DATA_TYPE_INT	= 0,
	IBV_EXP_CALC_DATA_TYPE_UINT,
	IBV_EXP_CALC_DATA_TYPE_FLOAT,
	IBV_EXP_CALC_DATA_TYPE_NUMBER
};

enum ibv_exp_calc_data_size {
	IBV_EXP_CALC_DATA_SIZE_64_BIT	= 0,
	IBV_EXP_CALC_DATA_SIZE_NUMBER
};

enum ibv_exp_wr_opcode {
	IBV_EXP_WR_RDMA_WRITE		= IBV_WR_RDMA_WRITE,
	IBV_EXP_WR_RDMA_WRITE_WITH_IMM	= IBV_WR_RDMA_WRITE_WITH_IMM,
	IBV_EXP_WR_SEND			= IBV_WR_SEND,
	IBV_EXP_WR_SEND_WITH_IMM	= IBV_WR_SEND_WITH_IMM,
	IBV_EXP_WR_RDMA_READ		= IBV_WR_RDMA_READ,
	IBV_EXP_WR_ATOMIC_CMP_AND_SWP	= IBV_WR_ATOMIC_CMP_AND_SWP,
	IBV_EXP_WR_ATOMIC_FETCH_AND_ADD	= IBV_WR_ATOMIC_FETCH_AND_ADD,
	IBV_EXP_WR_LOCAL_INV		= IBV_WR_LOCAL_INV,
	IBV_EXP_WR_BIND_MW		= IBV_WR_BIND_MW,
	IBV_EXP_WR_SEND_WITH_INV	= IBV_WR_SEND_WITH_INV,

	IBV_EXP_WR_TSO			= 15 + IBV_EXP_START_ENUM,
	IBV_EXP_WR_SEND_ENABLE		= 0x20 + IBV_EXP_START_ENUM,
	IBV_EXP_WR_RECV_ENABLE,
	IBV_EXP_WR_CQE_WAIT,
	IBV_EXP_WR_EXT_MASKED_ATOMIC_CMP_AND_SWP,
	IBV_EXP_WR_EXT_MASKED_ATOMIC_FETCH_AND_ADD,
	IBV_EXP_WR_NOP,
	IBV_EXP_WR_UMR_FILL,
	IBV_EXP_WR_UMR_INVALIDATE,
};

enum ibv_exp_send_flags {
	IBV_EXP_SEND_FENCE		= IBV_SEND_FENCE,
	IBV_EXP_SEND_SIGNALED		= IBV_SEND_SIGNALED,
	IBV_EXP_SEND_SOLICITED		= IBV_SEND_SOLICITED,
	IBV_EXP_SEND_INLINE		= IBV_SEND_INLINE,

	IBV_EXP_SEND_IP_CSUM		= (IBV_EXP_START_FLAG << 0),
	IBV_EXP_SEND_WITH_CALC		= (IBV_EXP_START_FLAG << 1),
	IBV_EXP_SEND_WAIT_EN_LAST	= (IBV_EXP_START_FLAG << 2),
	IBV_EXP_SEND_EXT_ATOMIC_INLINE	= (IBV_EXP_START_FLAG << 3),
};

struct ibv_exp_cmp_swap {
	uint64_t        compare_mask;
	uint64_t        compare_val;
	uint64_t        swap_val;
	uint64_t        swap_mask;
};

struct ibv_exp_fetch_add {
	uint64_t        add_val;
	uint64_t        field_boundary;
};

/*
 * Flags for ibv_exp_send_wr struct comp_mask
 */
enum ibv_exp_send_wr_comp_mask {
	IBV_EXP_SEND_WR_ATTR_RESERVED	= 1 << 0
};

struct ibv_exp_mem_region {
	uint64_t base_addr;
	struct ibv_mr *mr;
	size_t length;
};

struct ibv_exp_mem_repeat_block {
	uint64_t base_addr; /* array, size corresponds to ndim */
	struct ibv_mr *mr;
	size_t *byte_count; /* array, size corresponds to ndim */
	size_t *stride; /* array, size corresponds to ndim */
};

enum ibv_exp_umr_wr_type {
	IBV_EXP_UMR_MR_LIST,
	IBV_EXP_UMR_REPEAT
};

struct ibv_exp_send_wr {
	uint64_t		wr_id;
	struct ibv_exp_send_wr *next;
	struct ibv_sge	       *sg_list;
	int			num_sge;
	enum ibv_exp_wr_opcode	exp_opcode; /* use ibv_exp_wr_opcode */
	int			reserved; /* place holder to align with ibv_send_wr */
	union {
		uint32_t	imm_data; /* in network byte order */
		uint32_t	invalidate_rkey;
	} ex;
	union {
		struct {
			uint64_t	remote_addr;
			uint32_t	rkey;
		} rdma;
		struct {
			uint64_t	remote_addr;
			uint64_t	compare_add;
			uint64_t	swap;
			uint32_t	rkey;
		} atomic;
		struct {
			struct ibv_ah  *ah;
			uint32_t	remote_qpn;
			uint32_t	remote_qkey;
		} ud;
	} wr;
	union {
		union {
			struct {
				uint32_t    remote_srqn;
			} xrc;
		} qp_type;

		uint32_t		xrc_remote_srq_num;
	};
	union {
		struct {
			uint64_t		remote_addr;
			uint32_t		rkey;
		} rdma;
		struct {
			uint64_t		remote_addr;
			uint64_t		compare_add;
			uint64_t		swap;
			uint32_t		rkey;
		} atomic;
		struct {
			struct ibv_cq	*cq;
			int32_t  cq_count;
		} cqe_wait;
		struct {
			struct ibv_qp	*qp;
			int32_t  wqe_count;
		} wqe_enable;
	} task;
	union {
		struct {
			enum ibv_exp_calc_op        calc_op;
			enum ibv_exp_calc_data_type data_type;
			enum ibv_exp_calc_data_size data_size;
		} calc;
	} op;
	struct {
		struct ibv_ah   *ah;
		uint64_t        dct_access_key;
		uint32_t        dct_number;
	} dc;
	union {
		struct {
			struct ibv_mw			*mw;
			uint32_t			rkey;
			struct ibv_exp_mw_bind_info	bind_info;
		} bind_mw;
		struct {
			void				*hdr;
			uint16_t			hdr_sz;
			uint16_t			mss;
		} tso;
	};
	uint64_t	exp_send_flags; /* use ibv_exp_send_flags */
	uint32_t	comp_mask; /* reserved for future growth (must be 0) */
	union {
		struct {
			uint32_t umr_type; /* use ibv_exp_umr_wr_type */
			struct ibv_exp_mkey_list_container *memory_objects; /* used when IBV_EXP_SEND_INLINE is not set */
			uint64_t exp_access; /* use ibv_exp_access_flags */
			struct ibv_mr *modified_mr;
			uint64_t base_addr;
			uint32_t num_mrs; /* array size of mem_repeat_block_list or mem_reg_list */
			union {
				struct ibv_exp_mem_region *mem_reg_list; /* array, size corresponds to num_mrs */
				struct {
					struct ibv_exp_mem_repeat_block *mem_repeat_block_list; /* array,  size corresponds to num_mr */
					size_t *repeat_count; /* array size corresponds to stride_dim */
					uint32_t stride_dim;
				} rb;
			} mem_list;
		} umr;
		struct {
			uint32_t        log_arg_sz;
			uint64_t	remote_addr;
			uint32_t	rkey;
			union {
				struct {
					/* For the next four fields:
					 * If operand_size <= 8 then inline data is immediate
					 * from the corresponding field; for small opernands,
					 * ls bits are used.
					 * Else the fields are pointers in the process's address space
					 * where arguments are stored
					 */
					union {
						struct ibv_exp_cmp_swap cmp_swap;
						struct ibv_exp_fetch_add fetch_add;
					} op;
				} inline_data;       /* IBV_EXP_SEND_EXT_ATOMIC_INLINE is set */
				/* in the future add support for non-inline argument provisioning */
			} wr_data;
		} masked_atomics;
	} ext_op;
};

/*
 * Flags for ibv_exp_values struct comp_mask
 */
enum ibv_exp_values_comp_mask {
		IBV_EXP_VALUES_HW_CLOCK_NS	= 1 << 0,
		IBV_EXP_VALUES_HW_CLOCK		= 1 << 1,
		IBV_EXP_VALUES_RESERVED		= 1 << 2
};

struct ibv_exp_values {
	uint32_t comp_mask;
	uint64_t hwclock_ns;
	uint64_t hwclock;
};

/*
 * Flags for flags field in the ibv_exp_cq_init_attr struct
 */
enum ibv_exp_cq_create_flags {
	IBV_EXP_CQ_CREATE_CROSS_CHANNEL		= 1 << 0,
	IBV_EXP_CQ_TIMESTAMP			= 1 << 1,
	IBV_EXP_CQ_TIMESTAMP_TO_SYS_TIME	= 1 << 2,
	IBV_EXP_CQ_COMPRESSED_CQE		= 1 << 3,
	/*
	 * note: update IBV_EXP_CQ_CREATE_FLAGS_MASK when adding new fields
	 */
};

enum {
	IBV_EXP_CQ_CREATE_FLAGS_MASK	= IBV_EXP_CQ_CREATE_CROSS_CHANNEL |
					  IBV_EXP_CQ_TIMESTAMP |
					  IBV_EXP_CQ_TIMESTAMP_TO_SYS_TIME |
					  IBV_EXP_CQ_COMPRESSED_CQE,
};

/*
 * Flags for ibv_exp_cq_init_attr struct comp_mask
 * Set flags only when relevant field is valid
 */
enum ibv_exp_cq_init_attr_mask {
	IBV_EXP_CQ_INIT_ATTR_FLAGS		= 1 << 0,
	IBV_EXP_CQ_INIT_ATTR_RESERVED		= 1 << 1, /* This field is kept for backward compatibility
							   * of application which use the following to set comp_mask:
							   * cq_init_attr.comp_mask = IBV_EXP_CQ_INIT_ATTR_RESERVED - 1
							   * This kind of setting is no longer accepted and application
							   * may set only valid known fields, for example:
							   * cq_init_attr.comp_mask = IBV_EXP_CQ_INIT_ATTR_FLAGS |
							   *				IBV_EXP_CQ_INIT_ATTR_RES_DOMAIN
							   */
	IBV_EXP_CQ_INIT_ATTR_RES_DOMAIN		= 1 << 1,
	IBV_EXP_CQ_INIT_ATTR_PEER_DIRECT	= 1 << 2,
	IBV_EXP_CQ_INIT_ATTR_RESERVED1		= 1 << 3,
};

struct ibv_exp_res_domain {
	struct ibv_context     *context;
};

struct ibv_exp_cq_init_attr {
	uint32_t			 comp_mask;
	uint32_t			 flags;
	struct ibv_exp_res_domain	*res_domain;
	struct ibv_exp_peer_direct_attr *peer_direct_attrs;
};

/*
 * Flags for ibv_exp_ah_attr struct comp_mask
 */
enum ibv_exp_ah_attr_attr_comp_mask {
	IBV_EXP_AH_ATTR_LL		= 1 << 0,
	IBV_EXP_AH_ATTR_VID		= 1 << 1,
	IBV_EXP_AH_ATTR_RESERVED	= 1 << 2
};

enum ll_address_type {
	LL_ADDRESS_UNKNOWN,
	LL_ADDRESS_IB,
	LL_ADDRESS_ETH,
	LL_ADDRESS_SIZE
};

struct ibv_exp_ah_attr {
	struct ibv_global_route	grh;
	uint16_t		dlid;
	uint8_t			sl;
	uint8_t			src_path_bits;
	uint8_t			static_rate;
	uint8_t			is_global;
	uint8_t			port_num;
	uint32_t		comp_mask;
	struct {
		enum ll_address_type type;
		uint32_t	len;
		char		*address;
	} ll_address;
	uint16_t		vid;
};

/*
 * Flags for exp_attr_mask argument of ibv_exp_modify_qp
 */
enum ibv_exp_qp_attr_mask {
	IBV_EXP_QP_STATE		= IBV_QP_STATE,
	IBV_EXP_QP_CUR_STATE		= IBV_QP_CUR_STATE,
	IBV_EXP_QP_EN_SQD_ASYNC_NOTIFY	= IBV_QP_EN_SQD_ASYNC_NOTIFY,
	IBV_EXP_QP_ACCESS_FLAGS		= IBV_QP_ACCESS_FLAGS,
	IBV_EXP_QP_PKEY_INDEX		= IBV_QP_PKEY_INDEX,
	IBV_EXP_QP_PORT			= IBV_QP_PORT,
	IBV_EXP_QP_QKEY			= IBV_QP_QKEY,
	IBV_EXP_QP_AV			= IBV_QP_AV,
	IBV_EXP_QP_PATH_MTU		= IBV_QP_PATH_MTU,
	IBV_EXP_QP_TIMEOUT		= IBV_QP_TIMEOUT,
	IBV_EXP_QP_RETRY_CNT		= IBV_QP_RETRY_CNT,
	IBV_EXP_QP_RNR_RETRY		= IBV_QP_RNR_RETRY,
	IBV_EXP_QP_RQ_PSN		= IBV_QP_RQ_PSN,
	IBV_EXP_QP_MAX_QP_RD_ATOMIC	= IBV_QP_MAX_QP_RD_ATOMIC,
	IBV_EXP_QP_ALT_PATH		= IBV_QP_ALT_PATH,
	IBV_EXP_QP_MIN_RNR_TIMER	= IBV_QP_MIN_RNR_TIMER,
	IBV_EXP_QP_SQ_PSN		= IBV_QP_SQ_PSN,
	IBV_EXP_QP_MAX_DEST_RD_ATOMIC	= IBV_QP_MAX_DEST_RD_ATOMIC,
	IBV_EXP_QP_PATH_MIG_STATE	= IBV_QP_PATH_MIG_STATE,
	IBV_EXP_QP_CAP			= IBV_QP_CAP,
	IBV_EXP_QP_DEST_QPN		= IBV_QP_DEST_QPN,

	IBV_EXP_QP_GROUP_RSS		= IBV_EXP_START_FLAG << 21,
	IBV_EXP_QP_DC_KEY		= IBV_EXP_START_FLAG << 22,
	IBV_EXP_QP_FLOW_ENTROPY		= IBV_EXP_START_FLAG << 23,
	IBV_EXP_QP_RATE_LIMIT		= IBV_EXP_START_FLAG << 25,
};

/*
 * Flags for ibv_exp_qp_attr struct comp_mask
 * Set flags only when relevant field is valid
 */
enum ibv_exp_qp_attr_comp_mask {
	IBV_EXP_QP_ATTR_FLOW_ENTROPY	= 1UL << 0,
	IBV_EXP_QP_ATTR_RESERVED	= 1UL << 1
};

struct ibv_exp_qp_attr {
	enum ibv_qp_state	qp_state;
	enum ibv_qp_state	cur_qp_state;
	enum ibv_mtu		path_mtu;
	enum ibv_mig_state	path_mig_state;
	uint32_t		qkey;
	uint32_t		rq_psn;
	uint32_t		sq_psn;
	uint32_t		dest_qp_num;
	int			qp_access_flags; /* use ibv_access_flags form verbs.h */
	struct ibv_qp_cap	cap;
	struct ibv_ah_attr	ah_attr;
	struct ibv_ah_attr	alt_ah_attr;
	uint16_t		pkey_index;
	uint16_t		alt_pkey_index;
	uint8_t			en_sqd_async_notify;
	uint8_t			sq_draining;
	uint8_t			max_rd_atomic;
	uint8_t			max_dest_rd_atomic;
	uint8_t			min_rnr_timer;
	uint8_t			port_num;
	uint8_t			timeout;
	uint8_t			retry_cnt;
	uint8_t			rnr_retry;
	uint8_t			alt_port_num;
	uint8_t			alt_timeout;
	uint64_t		dct_key;
	uint32_t		comp_mask; /* reserved for future growth (must be 0) */
	uint32_t		flow_entropy;
	uint32_t		rate_limit;
};

/*
 * Flags for ibv_exp_qp_init_attr struct comp_mask
 * Set flags only when relevant field is valid
 */
enum ibv_exp_qp_init_attr_comp_mask {
	IBV_EXP_QP_INIT_ATTR_PD			= 1 << 0,
	IBV_EXP_QP_INIT_ATTR_XRCD		= 1 << 1,
	IBV_EXP_QP_INIT_ATTR_CREATE_FLAGS	= 1 << 2,
	IBV_EXP_QP_INIT_ATTR_INL_RECV		= 1 << 3,
	IBV_EXP_QP_INIT_ATTR_QPG		= 1 << 4,
	IBV_EXP_QP_INIT_ATTR_ATOMICS_ARG	= 1 << 5,
	IBV_EXP_QP_INIT_ATTR_MAX_INL_KLMS       = 1 << 6,
	IBV_EXP_QP_INIT_ATTR_RESERVED		= 1 << 7, /* This field is kept for backward compatibility
							   * of application which use the following to set comp_mask:
							   * qp_init_attr.comp_mask = IBV_EXP_QP_INIT_ATTR_RESERVED - 1
							   * This kind of setting is no longer accepted and application
							   * may set only valid known fields, for example:
							   * qp_init_attr.comp_mask = IBV_EXP_QP_INIT_ATTR_PD |
							   *				IBV_EXP_QP_INIT_ATTR_CREATE_FLAGS
							   */
	IBV_EXP_QP_INIT_ATTR_RES_DOMAIN         = 1 << 7,
	IBV_EXP_QP_INIT_ATTR_RX_HASH		= 1 << 8,
	IBV_EXP_QP_INIT_ATTR_PORT		= 1 << 9,
	IBV_EXP_QP_INIT_ATTR_PEER_DIRECT	= 1 << 10,
	IBV_EXP_QP_INIT_ATTR_MAX_TSO_HEADER	= 1 << 11,
	IBV_EXP_QP_INIT_ATTR_RESERVED1		= 1 << 12,
};

enum ibv_exp_qpg_type {
	IBV_EXP_QPG_NONE	= 0,
	IBV_EXP_QPG_PARENT	= (1<<0),
	IBV_EXP_QPG_CHILD_RX	= (1<<1),
	IBV_EXP_QPG_CHILD_TX	= (1<<2)
};

struct ibv_exp_qpg_init_attrib {
	uint32_t tss_child_count;
	uint32_t rss_child_count;
};

struct ibv_exp_qpg {
	uint32_t qpg_type;
	union {
		struct ibv_qp *qpg_parent; /* see qpg_type */
		struct ibv_exp_qpg_init_attrib parent_attrib;
	};
};

/*
 * RX Hash Function flags.
*/
enum ibv_exp_rx_hash_function_flags {
	IBV_EXP_RX_HASH_FUNC_TOEPLITZ	= 1 << 0,
	IBV_EXP_RX_HASH_FUNC_XOR	= 1 << 1
};

/*
 * RX Hash flags, these flags allows to set which incoming packet field should
 * participates in RX Hash. Each flag represent certain packet's field,
 * when the flag is set the field that is represented by the flag will
 * participate in RX Hash calculation.
 * Notice: *IPV4 and *IPV6 flags can't be enabled together on the same QP
 * and *TCP and *UDP flags can't be enabled together on the same QP.
*/
enum ibv_exp_rx_hash_fields {
	IBV_EXP_RX_HASH_SRC_IPV4		= 1 << 0,
	IBV_EXP_RX_HASH_DST_IPV4		= 1 << 1,
	IBV_EXP_RX_HASH_SRC_IPV6		= 1 << 2,
	IBV_EXP_RX_HASH_DST_IPV6		= 1 << 3,
	IBV_EXP_RX_HASH_SRC_PORT_TCP	= 1 << 4,
	IBV_EXP_RX_HASH_DST_PORT_TCP	= 1 << 5,
	IBV_EXP_RX_HASH_SRC_PORT_UDP	= 1 << 6,
	IBV_EXP_RX_HASH_DST_PORT_UDP	= 1 << 7
};

/*
 * RX Hash QP configuration. Sets hash function, hash types and
 * Indirection table for QPs with enabled IBV_QP_INIT_ATTR_RX_HASH flag.
*/
struct ibv_exp_rx_hash_conf {
	/* enum ibv_exp_rx_hash_function_flags */
	uint8_t				rx_hash_function;
	/* valid only for Toeplitz */
	uint8_t			rx_hash_key_len;
	uint8_t                        *rx_hash_key;
	/* enum ibv_exp_rx_hash_fields */
	uint64_t			rx_hash_fields_mask;
	struct ibv_exp_rwq_ind_table       *rwq_ind_tbl;
};

/*
 * Flags for exp_create_flags field in ibv_exp_qp_init_attr struct
 */
enum ibv_exp_qp_create_flags {
	IBV_EXP_QP_CREATE_CROSS_CHANNEL        = (1 << 2),
	IBV_EXP_QP_CREATE_MANAGED_SEND         = (1 << 3),
	IBV_EXP_QP_CREATE_MANAGED_RECV         = (1 << 4),
	IBV_EXP_QP_CREATE_IGNORE_SQ_OVERFLOW   = (1 << 6),
	IBV_EXP_QP_CREATE_IGNORE_RQ_OVERFLOW   = (1 << 7),
	IBV_EXP_QP_CREATE_ATOMIC_BE_REPLY      = (1 << 8),
	IBV_EXP_QP_CREATE_UMR		       = (1 << 9),
	IBV_EXP_QP_CREATE_EC_PARITY_EN	       = (1 << 10),
	IBV_EXP_QP_CREATE_RX_END_PADDING       = (1 << 11),
	IBV_EXP_QP_CREATE_SCATTER_FCS          = (1 << 12),
	IBV_EXP_QP_CREATE_INTERNAL_USE	       = (1 << 15),
	/* set supported bits for validity check */
	IBV_EXP_QP_CREATE_MASK                 = (0x00001FDC)
};

struct ibv_exp_qp_init_attr {
	void		       *qp_context;
	struct ibv_cq	       *send_cq;
	struct ibv_cq	       *recv_cq;
	struct ibv_srq	       *srq;
	struct ibv_qp_cap	cap;
	enum ibv_qp_type	qp_type;
	int			sq_sig_all;

	uint32_t		comp_mask; /* use ibv_exp_qp_init_attr_comp_mask */
	struct ibv_pd	       *pd;
	struct ibv_xrcd	       *xrcd;
	uint32_t		exp_create_flags; /* use ibv_exp_qp_create_flags */

	uint32_t		max_inl_recv;
	struct ibv_exp_qpg	qpg;
	uint32_t		max_atomic_arg;
	uint32_t                max_inl_send_klms;
	struct ibv_exp_res_domain *res_domain;
	struct ibv_exp_rx_hash_conf *rx_hash_conf;
	uint8_t port_num;
	struct ibv_exp_peer_direct_attr *peer_direct_attrs;
	uint16_t		max_tso_header;
};

/*
 * Flags for ibv_exp_dct_init_attr struct comp_mask
 */
enum ibv_exp_dct_init_attr_comp_mask {
	IBV_EXP_DCT_INIT_ATTR_RESERVED	= 1 << 0
};

enum {
	IBV_EXP_DCT_CREATE_FLAGS_MASK		= (1 << 0) - 1,
};

struct ibv_exp_dct_init_attr {
	struct ibv_pd	       *pd;
	struct ibv_cq	       *cq;
	struct ibv_srq	       *srq;
	uint64_t		dc_key;
	uint8_t			port;
	uint32_t		access_flags; /* use ibv_access_flags form verbs.h */
	uint8_t			min_rnr_timer;
	uint8_t			tclass;
	uint32_t		flow_label;
	enum ibv_mtu		mtu;
	uint8_t			pkey_index;
	uint8_t			gid_index;
	uint8_t			hop_limit;
	uint32_t		inline_size;
	uint32_t		create_flags;
	uint32_t		comp_mask; /* reserved for future growth (must be 0) */
};

enum {
	IBV_EXP_DCT_STATE_ACTIVE	= 0,
	IBV_EXP_DCT_STATE_DRAINING	= 1,
	IBV_EXP_DCT_STATE_DRAINED	= 2
};

/*
 * Flags for ibv_exp_dct_attr struct comp_mask
 */
enum ibv_exp_dct_attr_comp_mask {
	IBV_EXP_DCT_ATTR_RESERVED	= 1 << 0
};

struct ibv_exp_dct_attr {
	uint64_t		dc_key;
	uint8_t			port;
	uint32_t		access_flags; /* use ibv_access_flags form verbs.h */
	uint8_t			min_rnr_timer;
	uint8_t			tclass;
	uint32_t		flow_label;
	enum ibv_mtu		mtu;
	uint8_t			pkey_index;
	uint8_t			gid_index;
	uint8_t			hop_limit;
	uint32_t		key_violations;
	uint8_t			state;
	struct ibv_srq	       *srq;
	struct ibv_cq	       *cq;
	struct ibv_pd	       *pd;
	uint32_t		comp_mask; /* reserved for future growth (must be 0) */
};

enum {
	IBV_EXP_QUERY_PORT_STATE		= 1 << 0,
	IBV_EXP_QUERY_PORT_MAX_MTU		= 1 << 1,
	IBV_EXP_QUERY_PORT_ACTIVE_MTU		= 1 << 2,
	IBV_EXP_QUERY_PORT_GID_TBL_LEN		= 1 << 3,
	IBV_EXP_QUERY_PORT_CAP_FLAGS		= 1 << 4,
	IBV_EXP_QUERY_PORT_MAX_MSG_SZ		= 1 << 5,
	IBV_EXP_QUERY_PORT_BAD_PKEY_CNTR	= 1 << 6,
	IBV_EXP_QUERY_PORT_QKEY_VIOL_CNTR	= 1 << 7,
	IBV_EXP_QUERY_PORT_PKEY_TBL_LEN		= 1 << 8,
	IBV_EXP_QUERY_PORT_LID			= 1 << 9,
	IBV_EXP_QUERY_PORT_SM_LID		= 1 << 10,
	IBV_EXP_QUERY_PORT_LMC			= 1 << 11,
	IBV_EXP_QUERY_PORT_MAX_VL_NUM		= 1 << 12,
	IBV_EXP_QUERY_PORT_SM_SL		= 1 << 13,
	IBV_EXP_QUERY_PORT_SUBNET_TIMEOUT	= 1 << 14,
	IBV_EXP_QUERY_PORT_INIT_TYPE_REPLY	= 1 << 15,
	IBV_EXP_QUERY_PORT_ACTIVE_WIDTH		= 1 << 16,
	IBV_EXP_QUERY_PORT_ACTIVE_SPEED		= 1 << 17,
	IBV_EXP_QUERY_PORT_PHYS_STATE		= 1 << 18,
	IBV_EXP_QUERY_PORT_LINK_LAYER		= 1 << 19,
	/* mask of the fields that exists in the standard query_port_command */
	IBV_EXP_QUERY_PORT_STD_MASK		= (1 << 20) - 1,
	/* mask of all supported fields */
	IBV_EXP_QUERY_PORT_MASK			= IBV_EXP_QUERY_PORT_STD_MASK,
};

/*
 * Flags for ibv_exp_port_attr struct comp_mask
 * Set flags only when relevant field is valid
 */
enum ibv_exp_query_port_attr_comp_mask {
	IBV_EXP_QUERY_PORT_ATTR_MASK1		= 1 << 0,
	IBV_EXP_QUERY_PORT_ATTR_RESERVED	= 1 << 1,

	IBV_EXP_QUERY_PORT_ATTR_MASKS		= IBV_EXP_QUERY_PORT_ATTR_RESERVED - 1
};

struct ibv_exp_port_attr {
	union {
		struct {
			enum ibv_port_state	state;
			enum ibv_mtu		max_mtu;
			enum ibv_mtu		active_mtu;
			int			gid_tbl_len;
			uint32_t		port_cap_flags;
			uint32_t		max_msg_sz;
			uint32_t		bad_pkey_cntr;
			uint32_t		qkey_viol_cntr;
			uint16_t		pkey_tbl_len;
			uint16_t		lid;
			uint16_t		sm_lid;
			uint8_t			lmc;
			uint8_t			max_vl_num;
			uint8_t			sm_sl;
			uint8_t			subnet_timeout;
			uint8_t			init_type_reply;
			uint8_t			active_width;
			uint8_t			active_speed;
			uint8_t			phys_state;
			uint8_t			link_layer;
			uint8_t			reserved;
		};
		struct ibv_port_attr		port_attr;
	};
	uint32_t		comp_mask;
	uint32_t		mask1;
};

enum ibv_exp_cq_attr_mask {
	IBV_EXP_CQ_MODERATION                  = 1 << 0,
	IBV_EXP_CQ_CAP_FLAGS                   = 1 << 1
};

enum ibv_exp_cq_cap_flags {
	IBV_EXP_CQ_IGNORE_OVERRUN              = (1 << 0),
	/* set supported bits for validity check */
	IBV_EXP_CQ_CAP_MASK                    = (0x00000001)
};

/*
 * Flags for ibv_exp_cq_attr struct comp_mask
 * Set flags only when relevant field is valid
 */
enum ibv_exp_cq_attr_comp_mask {
	IBV_EXP_CQ_ATTR_MODERATION	= (1 << 0),
	IBV_EXP_CQ_ATTR_CQ_CAP_FLAGS	= (1 << 1),
	/* set supported bits for validity check */
	IBV_EXP_CQ_ATTR_RESERVED	= (1 << 2)
};

struct ibv_exp_cq_attr {
	uint32_t                comp_mask;
	struct {
		uint16_t        cq_count;
		uint16_t        cq_period;
	} moderation;
	uint32_t		cq_cap_flags;
};

/*
 * Flags for ibv_exp_reg_shared_mr_in struct comp_mask
 */
enum ibv_exp_reg_shared_mr_comp_mask {
	IBV_EXP_REG_SHARED_MR_RESERVED	= (1 << 0)
};

struct ibv_exp_reg_shared_mr_in {
	uint32_t mr_handle;
	struct ibv_pd *pd;
	void *addr;
	uint64_t exp_access; /* use ibv_exp_access_flags */
	uint32_t comp_mask; /* reserved for future growth (must be 0) */
};

enum ibv_exp_flow_flags {
	IBV_EXP_FLOW_ATTR_FLAGS_ALLOW_LOOP_BACK = 1,
};

enum ibv_exp_flow_attr_type {
	/* steering according to rule specifications */
	IBV_EXP_FLOW_ATTR_NORMAL		= 0x0,
	/* default unicast and multicast rule -
	 * receive all Eth traffic which isn't steered to any QP
	 */
	IBV_EXP_FLOW_ATTR_ALL_DEFAULT	= 0x1,
	/* default multicast rule -
	 * receive all Eth multicast traffic which isn't steered to any QP
	 */
	IBV_EXP_FLOW_ATTR_MC_DEFAULT	= 0x2,
	/* sniffer rule - receive all port traffic */
	IBV_EXP_FLOW_ATTR_SNIFFER		= 0x3,
};

enum ibv_exp_flow_spec_type {
	IBV_EXP_FLOW_SPEC_ETH		= 0x20,
	IBV_EXP_FLOW_SPEC_IB		= 0x21,
	IBV_EXP_FLOW_SPEC_IPV4		= 0x30,
	IBV_EXP_FLOW_SPEC_IPV6		= 0x31,
	IBV_EXP_FLOW_SPEC_IPV4_EXT	= 0x32,
	IBV_EXP_FLOW_SPEC_IPV6_EXT	= 0x33,
	IBV_EXP_FLOW_SPEC_TCP		= 0x40,
	IBV_EXP_FLOW_SPEC_UDP		= 0x41,
	IBV_EXP_FLOW_SPEC_VXLAN_TUNNEL	= 0x50,
	IBV_EXP_FLOW_SPEC_INNER		= 0x100,
	IBV_EXP_FLOW_SPEC_ACTION_TAG	= 0x1000,
};

struct ibv_exp_flow_eth_filter {
	uint8_t		dst_mac[6];
	uint8_t		src_mac[6];
	uint16_t	ether_type;
	/*
	 * same layout as 802.1q: prio 3, cfi 1, vlan id 12
	 */
	uint16_t	vlan_tag;
};

struct ibv_exp_flow_spec_eth {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	struct ibv_exp_flow_eth_filter val;
	struct ibv_exp_flow_eth_filter mask;
};

struct ibv_exp_flow_ib_filter {
	uint32_t qpn;
	uint8_t  dst_gid[16];
};

struct ibv_exp_flow_spec_ib {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	struct ibv_exp_flow_ib_filter val;
	struct ibv_exp_flow_ib_filter mask;
};

struct ibv_exp_flow_ipv4_filter {
	uint32_t src_ip;
	uint32_t dst_ip;
};

struct ibv_exp_flow_spec_ipv4 {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	struct ibv_exp_flow_ipv4_filter val;
	struct ibv_exp_flow_ipv4_filter mask;
};

struct ibv_exp_flow_ipv6_filter {
	uint8_t src_ip[16];
	uint8_t dst_ip[16];
};

struct ibv_exp_flow_spec_ipv6 {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	struct ibv_exp_flow_ipv6_filter val;
	struct ibv_exp_flow_ipv6_filter mask;
};

struct ibv_exp_flow_spec_action_tag {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	uint32_t  tag_id;
};

struct ibv_exp_flow_ipv6_ext_filter {
	uint8_t src_ip[16];
	uint8_t dst_ip[16];
	uint32_t flow_label;
	uint8_t  next_hdr;
	uint8_t  traffic_class;
	uint8_t  hop_limit;
};

struct ibv_exp_flow_spec_ipv6_ext {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	struct ibv_exp_flow_ipv6_ext_filter val;
	struct ibv_exp_flow_ipv6_ext_filter mask;
};

struct ibv_exp_flow_ipv4_ext_filter {
	uint32_t src_ip;
	uint32_t dst_ip;
	uint8_t  proto;
	uint8_t  tos;
	uint8_t  ttl;
	uint8_t  flags;
};

struct ibv_exp_flow_spec_ipv4_ext {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	struct ibv_exp_flow_ipv4_ext_filter val;
	struct ibv_exp_flow_ipv4_ext_filter mask;
};

struct ibv_exp_flow_tcp_udp_filter {
	uint16_t dst_port;
	uint16_t src_port;
};

struct ibv_exp_flow_spec_tcp_udp {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	struct ibv_exp_flow_tcp_udp_filter val;
	struct ibv_exp_flow_tcp_udp_filter mask;
};

struct ibv_exp_flow_tunnel_filter {
	uint32_t tunnel_id;
};

struct ibv_exp_flow_spec_tunnel {
	enum ibv_exp_flow_spec_type  type;
	uint16_t  size;
	struct ibv_exp_flow_tunnel_filter val;
	struct ibv_exp_flow_tunnel_filter mask;
};

struct ibv_exp_flow_spec {
	union {
		struct {
			uint32_t type;
			uint16_t size;
		} hdr;
		struct ibv_exp_flow_spec_ib ib;
		struct ibv_exp_flow_spec_eth eth;
		struct ibv_exp_flow_spec_ipv4 ipv4;
		struct ibv_exp_flow_spec_ipv4_ext ipv4_ext;
		struct ibv_exp_flow_spec_tcp_udp tcp_udp;
		struct ibv_exp_flow_spec_ipv6 ipv6;
		struct ibv_exp_flow_spec_ipv6_ext ipv6_ext;
		struct ibv_exp_flow_spec_tunnel tunnel;
		struct ibv_exp_flow_spec_action_tag flow_tag;
	};
};

struct ibv_exp_flow_attr {
	enum ibv_exp_flow_attr_type type;
	uint16_t size;
	uint16_t priority;
	uint8_t num_of_specs;
	uint8_t port;
	uint32_t flags;
	/* Following are the optional layers according to user request
	 * struct ibv_exp_flow_spec_xxx [L2]
	 * struct ibv_exp_flow_spec_yyy [L3/L4]
	 */
	uint64_t reserved; /* reserved for future growth (must be 0) */
};

struct ibv_exp_flow {
	struct ibv_context *context;
	uint32_t	   handle;
};

struct ibv_exp_dct {
	struct ibv_context     *context;
	uint32_t		handle;
	uint32_t		dct_num;
	struct ibv_pd	       *pd;
	struct ibv_srq	       *srq;
	struct ibv_cq	       *cq;
	pthread_mutex_t		mutex;
	pthread_cond_t		cond;
	uint32_t		events_completed;
};

enum ibv_exp_wc_opcode {
	IBV_EXP_WC_SEND,
	IBV_EXP_WC_RDMA_WRITE,
	IBV_EXP_WC_RDMA_READ,
	IBV_EXP_WC_COMP_SWAP,
	IBV_EXP_WC_FETCH_ADD,
	IBV_EXP_WC_BIND_MW,
	IBV_EXP_WC_LOCAL_INV,
	IBV_EXP_WC_MASKED_COMP_SWAP	=	9,
	IBV_EXP_WC_MASKED_FETCH_ADD	=	10,
	IBV_EXP_WC_TSO,
	IBV_EXP_WC_UMR			=	0x100,
/*
 * Set value of IBV_EXP_WC_RECV so consumers can test if a completion is a
 * receive by testing (opcode & IBV_EXP_WC_RECV).
 */
	IBV_EXP_WC_RECV			= 1 << 7,
	IBV_EXP_WC_RECV_RDMA_WITH_IMM
};

enum ibv_exp_wc_flags {
	IBV_EXP_WC_GRH		= IBV_WC_GRH,
	IBV_EXP_WC_WITH_IMM	= IBV_WC_WITH_IMM,
	IBV_EXP_WC_WITH_INV	= IBV_WC_WITH_INV,

	IBV_EXP_WC_WITH_SL			= IBV_EXP_START_FLAG << 4,
	IBV_EXP_WC_WITH_SLID			= IBV_EXP_START_FLAG << 5,
	IBV_EXP_WC_WITH_TIMESTAMP		= IBV_EXP_START_FLAG << 6,
	IBV_EXP_WC_QP				= IBV_EXP_START_FLAG << 7,
	IBV_EXP_WC_SRQ				= IBV_EXP_START_FLAG << 8,
	IBV_EXP_WC_DCT				= IBV_EXP_START_FLAG << 9,
	IBV_EXP_WC_RX_IP_CSUM_OK		= IBV_EXP_START_FLAG << 10,
	IBV_EXP_WC_RX_TCP_UDP_CSUM_OK		= IBV_EXP_START_FLAG << 11,
	IBV_EXP_WC_RX_IPV4_PACKET		= IBV_EXP_START_FLAG << 12,
	IBV_EXP_WC_RX_IPV6_PACKET		= IBV_EXP_START_FLAG << 13,
	IBV_EXP_WC_RX_TUNNEL_PACKET		= IBV_EXP_START_FLAG << 14,
	IBV_EXP_WC_RX_OUTER_IP_CSUM_OK		= IBV_EXP_START_FLAG << 15,
	IBV_EXP_WC_RX_OUTER_TCP_UDP_CSUM_OK	= IBV_EXP_START_FLAG << 16,
	IBV_EXP_WC_RX_OUTER_IPV4_PACKET		= IBV_EXP_START_FLAG << 17,
	IBV_EXP_WC_RX_OUTER_IPV6_PACKET		= IBV_EXP_START_FLAG << 18,
};

struct ibv_exp_wc {
	uint64_t		wr_id;
	enum ibv_wc_status	status;
	enum ibv_exp_wc_opcode	exp_opcode;
	uint32_t		vendor_err;
	uint32_t		byte_len;
	uint32_t		imm_data; /* in network byte order */
	uint32_t		qp_num;
	uint32_t		src_qp;
	int			reserved; /* place holder to align with ibv_wc */
	uint16_t		pkey_index;
	uint16_t		slid; /* invalid when TS is used */
	uint8_t			sl; /* invalid when TS is used */
	uint8_t			dlid_path_bits;
	uint64_t		timestamp;
	struct ibv_qp	       *qp;
	struct ibv_srq	       *srq;
	struct ibv_exp_dct     *dct;
	uint64_t		exp_wc_flags; /* use ibv_exp_wc_flags */
};

/*
 * Flags for ibv_exp_prefetch_mr comp_mask
 */
enum ibv_exp_prefetch_attr_comp_mask {
	IBV_EXP_PREFETCH_MR_RESERVED	= (1 << 0),
};

/*
 * Flags for ibv_exp_prefetch_mr flags
 */
enum ibv_exp_prefetch_attr_flags {
	/* request prefetching for write access. Used for both local and remote */
	IBV_EXP_PREFETCH_WRITE_ACCESS = (1 << 0),
};

struct ibv_exp_prefetch_attr {
	/* Use enum ibv_exp_prefetch_attr_flags */
	uint32_t flags;
	/* Address of the area to prefetch */
	void *addr;
	/* Length of the area to prefetch */
	size_t length;
	uint32_t comp_mask;
};

/*
 * Flags for ibv_exp_reg_mr_in struct comp_mask
 */
enum ibv_exp_reg_mr_in_comp_mask {
	/* set supported bits for validity check */
	IBV_EXP_REG_MR_CREATE_FLAGS	= (1 << 0),
	IBV_EXP_REG_MR_RESERVED		= (1 << 1)
};

enum ibv_exp_reg_mr_create_flags {
	IBV_EXP_REG_MR_CREATE_CONTIG		= (1 << 0)  /* register mr with contiguous pages */
};

struct ibv_exp_reg_mr_in {
	struct ibv_pd *pd;
	void *addr;
	size_t length;
	uint64_t exp_access; /* use ibv_exp_access_flags */
	uint32_t comp_mask; /* reserved for future growth (must be 0) */
	uint32_t create_flags; /* use ibv_exp_reg_mr_create_flags */
};


enum ibv_exp_task_type {
	IBV_EXP_TASK_SEND         = 0,
	IBV_EXP_TASK_RECV         = 1
};

/*
 * Flags for ibv_exp_task struct comp_mask
 */
enum ibv_exp_task_comp_mask {
	IBV_EXP_TASK_RESERVED	= (1 << 0)
};

struct ibv_exp_task {
	enum ibv_exp_task_type	task_type;
	struct {
		struct ibv_qp  *qp;
		union {
			struct ibv_exp_send_wr  *send_wr;
			struct ibv_recv_wr  *recv_wr;
		};
	} item;
	struct ibv_exp_task    *next;
	uint32_t                comp_mask; /* reserved for future growth (must be 0) */
};

/*
 * Flags for ibv_exp_arm_attr struct comp_mask
 */
enum ibv_exp_arm_attr_comp_mask {
	IBV_EXP_ARM_ATTR_RESERVED	= (1 << 0)
};
struct ibv_exp_arm_attr {
	uint32_t	comp_mask; /* reserved for future growth (must be 0) */
};

enum ibv_exp_mr_create_flags {
	IBV_EXP_MR_SIGNATURE_EN		= (1 << 0),
	IBV_EXP_MR_INDIRECT_KLMS	= (1 << 1)
};

struct ibv_exp_mr_init_attr {
	uint32_t max_klm_list_size; /* num of entries */
	uint32_t create_flags; /* use ibv_exp_mr_create_flags */
	uint64_t exp_access_flags; /* use ibv_exp_access_flags */
};

/*
 * Comp_mask for ibv_exp_create_mr_in struct comp_mask
 */
enum ibv_exp_create_mr_in_comp_mask {
	IBV_EXP_CREATE_MR_IN_RESERVED	= (1 << 0)
};

struct ibv_exp_create_mr_in {
	struct ibv_pd *pd;
	struct ibv_exp_mr_init_attr attr;
	uint32_t comp_mask; /* use ibv_exp_create_mr_in_comp_mask */
};

/*
 * Flags for ibv_exp_mkey_attr struct comp_mask
 */
enum ibv_exp_mkey_attr_comp_mask {
	IBV_EXP_MKEY_ATTR_RESERVED	= (1 << 0)
};

struct ibv_exp_mkey_attr {
	uint32_t max_klm_list_size;
	uint32_t comp_mask; /* use ibv_exp_mkey_attr_comp_mask */
};

struct ibv_exp_mkey_list_container {
	uint32_t max_klm_list_size;
	struct ibv_context *context;
};

enum ibv_exp_mkey_list_type {
	IBV_EXP_MKEY_LIST_TYPE_INDIRECT_MR
};

/*
 * Flags for ibv_exp_mkey_list_container_attr struct comp_mask
 */
enum ibv_exp_alloc_mkey_list_comp_mask {
	IBV_EXP_MKEY_LIST_CONTAINER_RESERVED	= (1 << 0)
};

struct ibv_exp_mkey_list_container_attr {
	struct ibv_pd *pd;
	uint32_t mkey_list_type;  /* use ibv_exp_mkey_list_type */
	uint32_t max_klm_list_size;
	uint32_t comp_mask; /*use ibv_exp_alloc_mkey_list_comp_mask */
};

/*
 * Flags for ibv_exp_dereg_out struct comp_mask
 */
enum ibv_exp_dereg_mr_comp_mask {
	IBV_EXP_DEREG_MR_RESERVED	= (1 << 0)
};

struct ibv_exp_dereg_out {
	int need_dofork;
	uint32_t comp_mask; /* use ibv_exp_dereg_mr_comp_mask */
};

struct verbs_env_item {
	char			*name;
	char			*value;
	struct verbs_env_item	*next;
};

struct verbs_environment {
	struct verbs_env_item  *head;
	pthread_mutex_t		mtx;
};

/* RSS stuff */

enum ibv_exp_wq_type {
	IBV_EXP_WQT_RQ,
	IBV_EXP_WQT_SRQ
};

enum ibv_exp_wq_state {
	IBV_EXP_WQS_RESET,
	IBV_EXP_WQS_RDY,
	IBV_EXP_WQS_ERR,
	IBV_EXP_WQS_UNKNOWN
};

/* VLAN Offloads */
enum ibv_exp_vlan_offloads {
	/* Represents C-VLAN stripping feature */
	IBV_EXP_RECEIVE_WQ_CVLAN_STRIP 			= (1 << 0),
	/* Represents C-VLAN insertion feature*/
	IBV_EXP_RECEIVE_WQ_CVLAN_INSERTION 		= (1 << 1),
	IBV_EXP_RECEIVE_WQ_VLAN_OFFLOADS_RESERVED 	= (1 << 2),
};

/*
 * Work Queue. QP can be created without internal WQs "packaged" inside it,
 * this QPs can be configured to use "external" WQ object as its
 * receive/send queue.
 * WQ associated (many to one) with Completion Queue it owns WQ properties
 * (PD, WQ size etc).
 * WQ of type IBV_EXP_WQT_RQ contains receive WQEs, in which case its PD serves
 * scatter as well.
 * WQ of type IBV_EXP_WQT_SRQ is associated (many to one) with regular ibv_srq,
 * in which case it does not hold receive WQEs.
 * QPs can be associated with IBV_EXP_WQT_S/RQ WQs via WQ Indirection Table.
 */
struct ibv_exp_wq {
	struct ibv_context     *context;
	void		       *wq_context; /* Associated Context of the WQ */
	uint32_t		handle;
	/* Protection domain WQ should be associated with */
	struct	ibv_pd	       *pd;
	/* CQ to be associated with the WQ */
	struct	ibv_cq	       *cq;
	/* SRQ handle if WQ is to be associated with an SRQ, otherwise NULL */
	struct	ibv_srq	       *srq;
	uint32_t		wq_num;
	enum ibv_exp_wq_state       state;
	enum ibv_exp_wq_type	wq_type;
	uint32_t		comp_mask;
};

enum ibv_exp_wq_init_attr_mask {
	IBV_EXP_CREATE_WQ_RES_DOMAIN	= (1 << 0),
	IBV_EXP_CREATE_WQ_MP_RQ		= (1 << 1),
	IBV_EXP_CREATE_WQ_VLAN_OFFLOADS = (1 << 2),
	IBV_EXP_CREATE_WQ_FLAGS		= (1 << 3),
	IBV_EXP_CREATE_WQ_RESERVED	= (1 << 4)
};

struct ibv_exp_wq_mp_rq {
	enum ibv_exp_mp_rq_shifts	use_shift;
	uint8_t				single_wqe_log_num_of_strides;
	uint8_t				single_stride_log_num_of_bytes;
};

enum ibv_exp_wq_init_attr_flags {
	IBV_EXP_CREATE_WQ_FLAG_RX_END_PADDING	= (1ULL << 0),
	IBV_EXP_CREATE_WQ_FLAG_SCATTER_FCS	= (1ULL << 1),
	IBV_EXP_CREATE_WQ_FLAG_RESERVED		= (1ULL << 2)
};

struct ibv_exp_wq_init_attr {
	/* Associated Context of the WQ */
	void		       *wq_context;
	enum ibv_exp_wq_type	wq_type;
	/* Valid for non IBV_EXP_WQT_SRQ WQ */
	uint32_t		max_recv_wr;
	/* Valid for non IBV_EXP_WQT_SRQ WQ */
	uint32_t		max_recv_sge;
	/* Protection domain WQ should be associated with */
	struct	ibv_pd	       *pd;
	/* CQ to be associated with the WQ */
	struct	ibv_cq	       *cq;
	/* SRQ handle if WQ is of type IBV_EXP_WQT_SRQ, otherwise NULL */
	struct	ibv_srq	       *srq;
	/* refers to ibv_exp_wq_init_attr_mask */
	uint32_t		comp_mask;
	struct ibv_exp_res_domain *res_domain;
	struct ibv_exp_wq_mp_rq	mp_rq;
	uint16_t		vlan_offloads; /* use ibv_exp_vlan_offloads enum */
	uint64_t		flags; /* general wq create flags */
};

enum ibv_exp_wq_attr_mask {
	IBV_EXP_WQ_ATTR_STATE		= 1 << 0,
	IBV_EXP_WQ_ATTR_CURR_STATE	= 1 << 1,
	IBV_EXP_WQ_ATTR_VLAN_OFFLOADS	= 1 << 2,
	IBV_EXP_WQ_ATTR_RESERVED	= 1 << 3
};

struct ibv_exp_wq_attr {
	/* enum ibv_exp_wq_attr_mask */
	uint32_t		attr_mask;
	/* Move the RQ to this state */
	enum	ibv_exp_wq_state	wq_state;
	/* Assume this is the current RQ state */
	enum	ibv_exp_wq_state	curr_wq_state;
	uint16_t		vlan_offloads; /* use ibv_exp_vlan_offloads enum */
};

/*
 * Receive Work Queue Indirection Table.
 * It's used in order to distribute incoming packets between different
 * Receive Work Queues. Associating Receive WQs with different CPU cores
 * allows to workload the traffic between different CPU cores.
 * The Indirection Table can contain only WQs of type IBV_EXP_WQT_S/RQ.
*/
struct ibv_exp_rwq_ind_table {
	struct ibv_context *context;
	struct ibv_pd *pd;
	int ind_tbl_handle;
	int ind_tbl_num;
	uint32_t comp_mask;
};

enum ibv_exp_ind_table_init_attr_mask {
	IBV_EXP_CREATE_IND_TABLE_RESERVED = (1 << 0)
};

/*
 * Receive Work Queue Indirection Table attributes
*/
struct ibv_exp_rwq_ind_table_init_attr {
	struct ibv_pd *pd;
	/* Log, base 2, of Indirection table size */
	uint32_t log_ind_tbl_size;
	/* Each entry is a pointer to Receive Work Queue */
	struct ibv_exp_wq **ind_tbl;
	uint32_t comp_mask;
};

/* Accelerated verbs */
enum ibv_exp_thread_model {
	IBV_EXP_THREAD_SAFE,	/* The lib responsible to protect the object in multithreaded environment */
	IBV_EXP_THREAD_UNSAFE,	/* The application responsible to protect the object in multithreaded environment */
	IBV_EXP_THREAD_SINGLE	/* The object is called from only one thread */
};

enum ibv_exp_msg_model {
	IBV_EXP_MSG_DEFAULT,		/* Use the provider default message model */
	IBV_EXP_MSG_LOW_LATENCY,	/* Hint the provider to optimize for low latency */
	IBV_EXP_MSG_HIGH_BW,		/* Hint the provider to optimize for high bandwidth */
	IBV_EXP_MSG_FORCE_LOW_LATENCY,	/* Force the provider to optimize for low latency */
};

/*
 * Resource domains
 */
enum ibv_exp_res_domain_init_attr_comp_mask {
	IBV_EXP_RES_DOMAIN_THREAD_MODEL	= (1 << 0),
	IBV_EXP_RES_DOMAIN_MSG_MODEL	= (1 << 1),
	IBV_EXP_RES_DOMAIN_RESERVED	= (1 << 2),
};

struct ibv_exp_res_domain_init_attr {
	uint32_t			comp_mask; /* use ibv_exp_res_domain_init_attr_comp_mask */
	enum ibv_exp_thread_model	thread_model;
	enum ibv_exp_msg_model		msg_model;
};

enum ibv_exp_destroy_res_domain_comp_mask {
	IBV_EXP_DESTROY_RES_DOMAIN_RESERVED	= (1 << 0),
};

struct ibv_exp_destroy_res_domain_attr {
	uint32_t	comp_mask; /* use ibv_exp_destroy_res_domain_comp_mask */
};

/*
 * Query interface (specialized Verbs)
 */

enum ibv_exp_query_intf_flags {
	/* Interface functions includes correctness and validity checks */
	IBV_EXP_QUERY_INTF_FLAG_ENABLE_CHECKS	= (1 << 0),
};

enum ibv_exp_intf_family {
	IBV_EXP_INTF_QP_BURST,
	IBV_EXP_INTF_CQ,
	IBV_EXP_INTF_WQ,
	IBV_EXP_INTF_RESERVED,
};

enum ibv_exp_experimental_intf_family {
	IBV_EXP_EXPERIMENTAL_INTF_RESERVED,
};

enum ibv_exp_intf_scope {
	IBV_EXP_INTF_GLOBAL, /* Permanent interface, identified by
	 	 	      * the ibv_exp_intf_family enum
	 	 	      */
	IBV_EXP_INTF_EXPERIMENTAL, /* Interface under evaluation, identified by
	 	 	 	    * the ibv_exp_experimental_intf_family enum
	 	 	 	    * This interface may change between lib
	 	 	 	    * versions
	 			    */
	IBV_EXP_INTF_VENDOR, /* Vendor specific interface, defined in vendor
			      * separate header file
			      */
	IBV_EXP_INTF_VENDOR_EXPERIMENTAL, /* Vendor interface under evaluation,
	 	 	 	 	   * defined in vendor separate header
	 	 	 	 	   * file
	 	 	 	 	   */
};

/* Return status from ibv_exp_query_intf */
enum ibv_exp_query_intf_status {
	IBV_EXP_INTF_STAT_OK,
	IBV_EXP_INTF_STAT_VENDOR_NOT_SUPPORTED, /* The provided 'vendor_guid' is not supported */
	IBV_EXP_INTF_STAT_INTF_NOT_SUPPORTED, /* The provided 'intf' is not supported */
	IBV_EXP_INTF_STAT_VERSION_NOT_SUPPORTED, /* The provided 'intf_version' is not supported */
	IBV_EXP_INTF_STAT_INVAL_PARARM, /* General invalid parameter */
	IBV_EXP_INTF_STAT_INVAL_OBJ_STATE, /* QP is not in INIT, RTR or RTS state */
	IBV_EXP_INTF_STAT_INVAL_OBJ, /* Mismatch between the provided 'obj'(CQ/QP/WQ) and requested 'intf' */
	IBV_EXP_INTF_STAT_FLAGS_NOT_SUPPORTED, /* The provided set of 'flags' is not supported */
	IBV_EXP_INTF_STAT_FAMILY_FLAGS_NOT_SUPPORTED, /* The provided set of 'family_flags' is not supported */
};

enum ibv_exp_query_intf_comp_mask {
	IBV_EXP_QUERY_INTF_RESERVED	= (1 << 0),
};

struct ibv_exp_query_intf_params {
	uint32_t			flags;		/* use ibv_exp_query_intf_flags */
	enum ibv_exp_intf_scope		intf_scope;
	uint64_t			vendor_guid;	/* set in case VENDOR intf_scope selected */
	uint32_t			intf;		/* for GLOBAL intf_scope use ibv_exp_intf_family enum */
	uint32_t			intf_version;	/* Version */
	void				*obj;		/* interface object (CQ/QP/WQ) */
	void				*family_params;	/* Family-specific params */
	uint32_t			family_flags;	/* Family-specific flags */
	uint32_t			comp_mask;	/* use ibv_exp_query_intf_comp_mask */
};

enum ibv_exp_release_intf_comp_mask {
	IBV_EXP_RELEASE_INTF_RESERVED =	(1 << 0),
};

struct ibv_exp_release_intf_params {
	uint32_t comp_mask; /* use ibv_exp_release_intf_comp_mask */
};

/*
 * Family interfaces
 */

/* QP burst family */

/* Flags to use in family_flags field of ibv_exp_query_intf_params on family creation */
enum ibv_exp_qp_burst_family_create_flags {
	/* To disable loop-back of multi-cast messages in RAW-ETH */
	IBV_EXP_QP_BURST_CREATE_DISABLE_ETH_LOOPBACK		= (1 << 0),
	/* To enable Multi-Packet send WR when possible */
	IBV_EXP_QP_BURST_CREATE_ENABLE_MULTI_PACKET_SEND_WR	= (1 << 1),
};

/* Flags to use on send functions of QP burst family */
enum ibv_exp_qp_burst_family_flags {
	IBV_EXP_QP_BURST_SIGNALED	= 1 << 0,
	IBV_EXP_QP_BURST_SOLICITED	= 1 << 1,
	IBV_EXP_QP_BURST_IP_CSUM	= 1 << 2,
	IBV_EXP_QP_BURST_TUNNEL		= 1 << 3,
	IBV_EXP_QP_BURST_FENCE		= 1 << 4,
};

/* All functions of QP family included in QP family version 1 */
struct ibv_exp_qp_burst_family {
	int (*send_pending)(struct ibv_qp *qp, uint64_t addr, uint32_t length, uint32_t lkey, uint32_t flags);
	int (*send_pending_inline)(struct ibv_qp *qp, void *addr, uint32_t length, uint32_t flags);
	int (*send_pending_sg_list)(struct ibv_qp *qp, struct ibv_sge *sg_list, uint32_t num, uint32_t flags);
	int (*send_flush)(struct ibv_qp *qp);
	int (*send_burst)(struct ibv_qp *qp, struct ibv_sge *msg_list, uint32_t num, uint32_t flags);
	int (*recv_burst)(struct ibv_qp *qp, struct ibv_sge *msg_list, uint32_t num);
};

struct ibv_exp_qp_burst_family_v1 {
	/*
	 * send_pending - Put one message in the provider send queue.
	 *
	 * Common usage: After calling several times to send_pending
	 *    the application need to call send_flush to ensure the send
	 *    of the pending messages.
	 * Note: Use ibv_exp_qp_burst_family_flags for the flags field
	 */
	int (*send_pending)(struct ibv_qp *qp, uint64_t addr, uint32_t length, uint32_t lkey, uint32_t flags);
	/*
	 * send_pending_inline - Put one inline message in the provider send queue.
	 *
	 * Common usage: Same as send_pending
	 * Notes:
	 *  - The message length must fit the max inline size of the QP.
	 *    Providing bigger messages may lead to data corruption and
	 *    segmentation fault.
	 *  - Use ibv_exp_qp_burst_family_flags for the flags field
	 */
	int (*send_pending_inline)(struct ibv_qp *qp, void *addr, uint32_t length, uint32_t flags);
	/*
	 * send_pending_sg_list - Put one scatter-gather(sg) message in the provider send queue.
	 *
	 * Common usage: Same as send_pending
	 * Notes:
	 *  - The number of sg entries must fit the max_send_sge of the QP.
	 *    Providing bigger list of sg entries may lead to data corruption and
	 *    segmentation fault.
	 *  - Use ibv_exp_qp_burst_family_flags for the flags field
	 */
	int (*send_pending_sg_list)(struct ibv_qp *qp, struct ibv_sge *sg_list, uint32_t num, uint32_t flags);
	/*
	 * send_flush - To flush the pending messages.
	 *
	 * Note: Use ibv_exp_qp_burst_family_flags for the flags field
	 */
	int (*send_flush)(struct ibv_qp *qp);
	/*
	 * send_burst - Send a list of 'num' messages (no send_flush required in this case)
	 */
	int (*send_burst)(struct ibv_qp *qp, struct ibv_sge *msg_list, uint32_t num, uint32_t flags);
	/*
	 * recv_burst - Post a set of 'num' receive buffers.
	 *
	 * Note: One sge per message is supported by this function
	 */
	int (*recv_burst)(struct ibv_qp *qp, struct ibv_sge *msg_list, uint32_t num);
	/*
	 * send_pending_vlan - Put one message in the provider send queue
	 * and insert vlan_tci to header.
	 *
	 * Common usage: Same as send_pending
	 * Note:
	 * - Same as send_pending
	 * - Not supported when MP enable.
	 */
	int (*send_pending_vlan)(struct ibv_qp *qp, uint64_t addr, uint32_t length,
				 uint32_t lkey, uint32_t flags, uint16_t *vlan_tci);
	/*
	 * send_pending_inline - Put one inline message in the provider send queue
	 * and insert vlan_tci to header.
	 *
	 * Common usage: Same as send_pending_inline
	 * Notes:
	 * - Same as send_pending_inline
	 * - Not supported when MP enable.
	 */
	int (*send_pending_inline_vlan)(struct ibv_qp *qp, void *addr, uint32_t length,
					uint32_t flags, uint16_t *vlan_tci);
	/*
	 * send_pending_sg_list - Put one scatter-gather(sg) message in the provider send queue
	 * and insert vlan_tci to header.
	 *
	 * Common usage: Same as send_pending_sg_list
	 * Notes:
	 * - Same as send_pending_sg_list
	 * - Not supported when MP enable.
	 */
	int (*send_pending_sg_list_vlan)(struct ibv_qp *qp, struct ibv_sge *sg_list, uint32_t num,
					 uint32_t flags, uint16_t *vlan_tci);
};

/* WQ family */
struct ibv_exp_wq_family {
	/*
	 * recv_sg_list - Post one scatter-gather(sg) receive buffer.
	 *
	 * Note:
	 *  - The number of sg entries must fit the max_recv_sge of the WQ.
	 *    Providing bigger list of sg entries may lead to data corruption and
	 *    segmentation fault.
	 */
	int (*recv_sg_list)(struct ibv_exp_wq *wq, struct ibv_sge *sg_list, uint32_t num_sg);
	/*
	 * recv_burst - Post a set of 'num' receive buffers.
	 *
	 * Note: One sge per message is supported by this function
	 */
	int (*recv_burst)(struct ibv_exp_wq *wq, struct ibv_sge *msg_list, uint32_t num);
};

/* CQ family */
enum ibv_exp_cq_family_flags {
	/* RX offloads flags */
							/* The cq_family_flags are applicable
							 * according to the existence of the
							 * related device capabilities flags */
	IBV_EXP_CQ_RX_IP_CSUM_OK		= 1 << 0, /* IBV_EXP_DEVICE_RX_CSUM_IP_PKT or IBV_EXP_DEVICE_RX_CSUM_TCP_UDP_PKT */
	IBV_EXP_CQ_RX_TCP_UDP_CSUM_OK		= 1 << 1, /* IBV_EXP_DEVICE_RX_CSUM_TCP_UDP_PKT */
	IBV_EXP_CQ_RX_IPV4_PACKET		= 1 << 2, /* IBV_EXP_DEVICE_RX_CSUM_IP_PKT or IBV_EXP_DEVICE_RX_CSUM_TCP_UDP_PKT */
	IBV_EXP_CQ_RX_IPV6_PACKET		= 1 << 3, /* IBV_EXP_DEVICE_RX_CSUM_IP_PKT or IBV_EXP_DEVICE_RX_CSUM_TCP_UDP_PKT */
	IBV_EXP_CQ_RX_TUNNEL_PACKET		= 1 << 4, /* IBV_EXP_DEVICE_VXLAN_SUPPORT */
	IBV_EXP_CQ_RX_OUTER_IP_CSUM_OK		= 1 << 5, /* IBV_EXP_DEVICE_VXLAN_SUPPORT */
	IBV_EXP_CQ_RX_OUTER_TCP_UDP_CSUM_OK	= 1 << 6, /* IBV_EXP_DEVICE_VXLAN_SUPPORT */
	IBV_EXP_CQ_RX_OUTER_IPV4_PACKET		= 1 << 7, /* IBV_EXP_DEVICE_VXLAN_SUPPORT */
	IBV_EXP_CQ_RX_OUTER_IPV6_PACKET		= 1 << 8, /* IBV_EXP_DEVICE_VXLAN_SUPPORT */

	/* Flags supported from CQ family version 1 */
	/* Multi-Packet RQ flag */
	IBV_EXP_CQ_RX_MULTI_PACKET_LAST_V1	= 1 << 9, /* Last packet on WR */
	/* CVLAN stripping RQ flag */
	IBV_EXP_CQ_RX_CVLAN_STRIPPED_V1		= 1 << 10, /*
							    * When set, CVLAN is stripped
							    * from incoming packets.
							    */

							   /* The RX TCP/UDP packet flags
							    * applicable according to
							    * IBV_EXP_DEVICE_RX_TCP_UDP_PKT_TYPE
							    * device capabilities flag
							    */
	IBV_EXP_CQ_RX_TCP_PACKET		= 1 << 11,
	IBV_EXP_CQ_RX_UDP_PACKET		= 1 << 12,
};

/* All functions of CQ family included in CQ family version 1 */
struct ibv_exp_cq_family {
	int32_t (*poll_cnt)(struct ibv_cq *cq, uint32_t max);
	int32_t (*poll_length)(struct ibv_cq *cq, void *buf, uint32_t *inl);
	int32_t (*poll_length_flags)(struct ibv_cq *cq, void *buf, uint32_t *inl, uint32_t *flags);
};

struct ibv_exp_cq_family_v1 {
	/*
	 * poll_cnt - Poll up to 'max' valid completions
	 *
	 * The function returns the number of valid completions it
	 * managed to drain from the CQ.
	 *
	 * Usage example: In case a CQ is connected to one send-queue
	 *                the application may use this function to get
	 *                the number of the QP send-completions.
	 *
	 * Return value (n):
	 *    n >= 0 : number extracted completions.
	 *    n == -1 : operation failed. completion is not extracted.
	 *              To extract this completion, ibv_poll_cq() must be used
	 *
	 * Note: The function designed to support TX completion, it may also be
	 *    used for RX completion but it is not supporting RX inline-scatter.
	 */
	int32_t (*poll_cnt)(struct ibv_cq *cq, uint32_t max);
	/*
	 * poll_length - Poll one receive completion and provide the related
	 *               message length.
	 *
	 * The function returns only the length of the completed message.
	 * In case of inline received message the message will be copied
	 * to the provided buffer ('buf') and the '*inl' status will be set.
	 * The function extracts only completion of regular receive-messages.
	 * In case of send-message completion or SRQ receive-message completion
	 * it returns -1.
	 *
	 * Usage example: In case a CQ is connected to one receive-queue
	 *                the application may use this function to get
	 *                the size of the next received message.
	 *
	 * Return value (n):
	 *    n > 0 : successful completion with positive length.
	 *            *inl will be set to 1 if data was copied to buffer.
	 *
	 *    0     : Empty.
	 *    n == -1 : operation failed. completion is not extracted.
	 *              To extract this completion, ibv_poll_cq() must be used
	 */
	int32_t (*poll_length)(struct ibv_cq *cq, void *buf, uint32_t *inl);
	/*
	 * poll_length_flags - Poll one receive completion and provide the related
	 *                     message length and completion flags.
	 *
	 * The same as poll_length but also retrieves completion flags as
	 * defined by the enum ibv_exp_cq_family_flags
	 */
	int32_t (*poll_length_flags)(struct ibv_cq *cq, void *buf, uint32_t *inl, uint32_t *flags);
	/*
	 * poll_length_flags_mp_rq - Poll one receive completion and provide the related
	 *                           message length, packet-offset and completion flags.
	 *
	 * The same as poll_length_flags but:
	 *  - Without the inline-receive support.
	 *  - Also retrieves offset in the WR posted buffer as defined by the WR SG list.
	 *    The start of the received packet is located in this offset.
	 */
	int32_t (*poll_length_flags_mp_rq)(struct ibv_cq *cq, uint32_t *offset, uint32_t *flags);
	/*
	 * poll_length_flags_cvlan - Poll one receive completion and provide the
	 *			     related message length, completion flags
	 *			     and CVLAN TCI.
	 *			     The CVLAN TCI value is valid only when
	 *			     IBV_EXP_CQ_RX_CVLAN_STRIPPED_V1 flag is
	 *			     set.
	 *
	 * The same as poll_length_flags but:
	 *  - Also retrievs the packet's CVLAN TCI that was stripped by the HW.
	 */
	int32_t (*poll_length_flags_cvlan)(struct ibv_cq *cq, void *buf,
					   uint32_t *inl, uint32_t *flags,
					   uint16_t *vlan_tci);
	/*
	 * poll_length_flags_mp_rq_cvlan - Poll one receive completion and provide
	 *				   the related message length,
	 *				   packet-offset, completion flags and
	 *				   CVLAN TCI
	 *
	 * The same as poll_length_flags_cvlan but:
	 *  - Without the inline-receive support.
	 *  - Also retrives offset in the WR posted buffer as defined by the
	 *    WR SG list. The start of the received packet is located in this
	 *    offset.
	 */
	int32_t (*poll_length_flags_mp_rq_cvlan)(struct ibv_cq *cq,
						 uint32_t *offset,
						 uint32_t *flags,
						 uint16_t *vlan_tci);
};

enum {
	IBV_EXP_NUM_DC_INFO_LIDS	= 30
};

struct ibv_exp_dc_info_ent {
	uint16_t	lid[IBV_EXP_NUM_DC_INFO_LIDS];
	uint32_t	seqnum;
};

enum ibv_exp_roce_gid_type {
	IBV_EXP_IB_ROCE_V1_GID_TYPE,
	IBV_EXP_ROCE_V2_GID_TYPE,
	IBV_EXP_ROCE_V1_5_GID_TYPE,
};

enum ibv_exp_query_gid_attr {
	IBV_EXP_QUERY_GID_ATTR_TYPE = (1 << 0),
	IBV_EXP_QUERY_GID_ATTR_GID	= (1 << 1),
	IBV_EXP_QUERY_GID_ATTR_RESERVED	= (1 << 2),
};

struct ibv_exp_gid_attr {
	uint32_t			comp_mask;
	enum ibv_exp_roce_gid_type	type;
	union ibv_gid			gid;
};

/**
 * enum ibv_exp_ec_calc_attr_comp_mask - erasure coding context
 *    init attributes compatibility enumeration
 */
enum ibv_exp_ec_calc_attr_comp_mask {
	IBV_EXP_EC_CALC_ATTR_MAX_INFLIGHT	= (1 << 0),
	IBV_EXP_EC_CALC_ATTR_K			= (1 << 1),
	IBV_EXP_EC_CALC_ATTR_M			= (1 << 2),
	IBV_EXP_EC_CALC_ATTR_W			= (1 << 3),
	IBV_EXP_EC_CALC_ATTR_MAX_DATA_SGE	= (1 << 4),
	IBV_EXP_EC_CALC_ATTR_MAX_CODE_SGE	= (1 << 5),
	IBV_EXP_EC_CALC_ATTR_ENCODE_MAT		= (1 << 6),
	IBV_EXP_EC_CALC_ATTR_AFFINITY		= (1 << 7),
	IBV_EXP_EC_CALC_ATTR_POLLING		= (1 << 8),
	IBV_EXP_EC_CALC_INIT_ATTR_RESERVED	= (1 << 9),
};

/**
 * struct ibv_exp_ec_calc_init_attr - erasure coding engine
 *     initialization attributes
 *
 * @comp_mask:            compatibility bitmask
 * @max_inflight_calcs:   maximum inflight calculations
 * @k:                    number of data blocks
 * @m:                    number of core blocks
 * @w:                    Galois field bits GF(2^w)
 * @max_data_sge:	  maximum data sg elements to be used for encode/decode
 * @max_code_sge:	  maximum code sg elements to be used for encode/decode
 * @encode_matrix:        buffer that contain the encoding matrix
 * @affinity_hint:        affinity hint for asynchronous calcs completion
 *                        steering.
 * @polling:              polling mode (if set no completions will be generated
 *                        by events).
 */
struct ibv_exp_ec_calc_init_attr {
	uint32_t		comp_mask;
	uint32_t		max_inflight_calcs;
	int			k;
	int			m;
	int			w;
	int			max_data_sge;
	int			max_code_sge;
	uint8_t			*encode_matrix;
	int			affinity_hint;
	int			polling;
};

/**
 * enum ibv_exp_ec_status - EX calculation status
 *
 * @IBV_EXP_EC_CALC_SUCCESS:   EC calc operation succeded
 * @IBV_EXP_EC_CALC_FAIL:      EC calc operation failed
 */
enum ibv_exp_ec_status {
	IBV_EXP_EC_CALC_SUCCESS,
	IBV_EXP_EC_CALC_FAIL,
};

/**
 * struct ibv_exp_ec_comp - completion context of EC calculation
 *
 * @done:      function handle of the EC calculation completion
 * @status:    status of the EC calculation
 *
 * The consumer is expected to embed this structure in his calculation context
 * so that the user context would be acquired back using offsetof()
 */
struct ibv_exp_ec_comp {
	void (*done)(struct ibv_exp_ec_comp *comp);
	enum ibv_exp_ec_status status;
};

/**
 * struct ibv_exp_ec_calc - erasure coding engine context
 *
 * @pd:                 protection domain
 */
struct ibv_exp_ec_calc {
	struct ibv_pd		*pd;
};

/**
 * struct ibv_exp_ec_mem - erasure coding memory layout context
 *
 * @data_blocks:        array of data sg elements
 * @num_data_sge:       number of data sg elements
 * @code_blocks:        array of code sg elements
 * @num_code_sge:       number of code sg elements
 * @block_size:         logical block size
 */
struct ibv_exp_ec_mem {
	struct ibv_sge		*data_blocks;
	int			num_data_sge;
	struct ibv_sge		*code_blocks;
	int			num_code_sge;
	int			block_size;
};

/**
 * struct ibv_exp_ec_stripe - erasure coding stripe descriptor
 *
 * @qp:    queue-pair connected to the relevant peer
 * @wr:    send work request, can either be a RDMA wr or a SEND
 */
struct ibv_exp_ec_stripe {
	struct ibv_qp		*qp;
	struct ibv_send_wr	*wr;
};

struct ibv_exp_peer_commit;
struct ibv_exp_rollback_ctx;


struct ibv_exp_peer_peek;
struct ibv_exp_peer_abort_peek;

struct verbs_context_exp {
	/*  "grows up" - new fields go here */
	struct ibv_ah * (*drv_exp_ibv_create_kah)(struct ibv_pd *pd,
						  struct ibv_exp_ah_attr *attr_exp);
	int (*exp_peer_peek_cq)(struct ibv_cq *ibcq,
				struct ibv_exp_peer_peek *peek_ctx);
	int (*exp_peer_abort_peek_cq)(struct ibv_cq *ibcq,
				      struct ibv_exp_peer_abort_peek *ack_ctx);
	int (*exp_peer_commit_qp)(struct ibv_qp *qp,
				  struct ibv_exp_peer_commit *peer);
	int (*exp_rollback_send)(struct ibv_qp *qp,
				 struct ibv_exp_rollback_ctx *rollback);
	int (*ec_update_sync)(struct ibv_exp_ec_calc *calc,
			      struct ibv_exp_ec_mem *ec_mem,
			      uint8_t *data_updates,
			      uint8_t *code_updates);
	int (*ec_update_async)(struct ibv_exp_ec_calc *calc,
			       struct ibv_exp_ec_mem *ec_mem,
			       uint8_t *data_updates,
			       uint8_t *code_updates,
			       struct ibv_exp_ec_comp *ec_comp);
	struct ibv_exp_ec_calc *(*alloc_ec_calc)(struct ibv_pd *pd,
						 struct ibv_exp_ec_calc_init_attr *attr);
	void (*dealloc_ec_calc)(struct ibv_exp_ec_calc *calc);
	int (*ec_encode_async)(struct ibv_exp_ec_calc *calc,
			       struct ibv_exp_ec_mem *ec_mem,
			       struct ibv_exp_ec_comp *ec_comp);
	int (*ec_encode_sync)(struct ibv_exp_ec_calc *calc,
			      struct ibv_exp_ec_mem *ec_mem);
	int (*ec_decode_async)(struct ibv_exp_ec_calc *calc,
			       struct ibv_exp_ec_mem *ec_mem,
			       uint8_t *erasures,
			       uint8_t *decode_matrix,
			       struct ibv_exp_ec_comp *ec_comp);
	int (*ec_decode_sync)(struct ibv_exp_ec_calc *calc,
			      struct ibv_exp_ec_mem *ec_mem,
			      uint8_t *erasures,
			      uint8_t *decode_matrix);
	int (*ec_poll)(struct ibv_exp_ec_calc *calc, int n);
	int (*ec_encode_send)(struct ibv_exp_ec_calc *calc,
			      struct ibv_exp_ec_mem *ec_mem,
			      struct ibv_exp_ec_stripe *data_stripes,
			      struct ibv_exp_ec_stripe *code_stripes);
	int (*exp_query_gid_attr)(struct ibv_context *context, uint8_t port_num,
				  unsigned int index,
				  struct ibv_exp_gid_attr *attr);
	int (*exp_destroy_rwq_ind_table)(struct ibv_exp_rwq_ind_table *rwq_ind_table);
	struct ibv_exp_rwq_ind_table *(*exp_create_rwq_ind_table)(struct ibv_context *context,
								  struct ibv_exp_rwq_ind_table_init_attr *init_attr);
	int (*exp_destroy_wq)(struct ibv_exp_wq *wq);
	int (*exp_modify_wq)(struct ibv_exp_wq *wq,
				 struct ibv_exp_wq_attr *wq_attr);
	struct ibv_exp_wq * (*exp_create_wq)(struct ibv_context *context,
						 struct ibv_exp_wq_init_attr *wq_init_attr);
	int (*drv_exp_poll_dc_info)(struct ibv_context *context,
				    struct ibv_exp_dc_info_ent *ents,
				    int nent, int port);
	void *(*exp_query_intf)(struct ibv_context *context, struct ibv_exp_query_intf_params *params,
				enum ibv_exp_query_intf_status *status);
	int (*exp_release_intf)(struct ibv_context *context, void *intf,
				struct ibv_exp_release_intf_params *params);
	struct ibv_exp_res_domain *(*exp_create_res_domain)(struct ibv_context *context,
							    struct ibv_exp_res_domain_init_attr *attr);
	int (*exp_destroy_res_domain)(struct ibv_context *context,
				      struct ibv_exp_res_domain *res_dom,
				      struct ibv_exp_destroy_res_domain_attr *attr);
	int (*lib_exp_use_priv_env)(struct ibv_context *context);
	int (*lib_exp_setenv)(struct ibv_context *context, const char *name,
			      const char *value, int overwrite);
	struct verbs_environment *venv;
	int (*drv_exp_dereg_mr)(struct ibv_mr *mr, struct ibv_exp_dereg_out *out);
	void (*ABI_placeholder2)(void);
	void (*ABI_placeholder1)(void);
	int (*drv_exp_prefetch_mr)(struct ibv_mr *mr,
				   struct ibv_exp_prefetch_attr *attr);
	int (*lib_exp_prefetch_mr)(struct ibv_mr *mr,
				   struct ibv_exp_prefetch_attr *attr);
	struct ibv_exp_mkey_list_container * (*drv_exp_alloc_mkey_list_memory)(struct ibv_exp_mkey_list_container_attr *attr);
	struct ibv_exp_mkey_list_container * (*lib_exp_alloc_mkey_list_memory)(struct ibv_exp_mkey_list_container_attr *attr);
	int (*drv_exp_dealloc_mkey_list_memory)(struct ibv_exp_mkey_list_container *mem);
	int (*lib_exp_dealloc_mkey_list_memory)(struct ibv_exp_mkey_list_container *mem);
	int (*drv_exp_query_mkey)(struct ibv_mr *mr, struct ibv_exp_mkey_attr *mkey_attr);
	int (*lib_exp_query_mkey)(struct ibv_mr *mr, struct ibv_exp_mkey_attr *mkey_attr);
	struct ibv_mr * (*drv_exp_create_mr)(struct ibv_exp_create_mr_in *in);
	struct ibv_mr * (*lib_exp_create_mr)(struct ibv_exp_create_mr_in *in);
	int (*drv_exp_arm_dct)(struct ibv_exp_dct *dct, struct ibv_exp_arm_attr *attr);
	int (*lib_exp_arm_dct)(struct ibv_exp_dct *dct, struct ibv_exp_arm_attr *attr);
	int (*drv_exp_bind_mw)(struct ibv_exp_mw_bind *mw_bind);
	int (*lib_exp_bind_mw)(struct ibv_exp_mw_bind *mw_bind);
	int (*drv_exp_post_send)(struct ibv_qp *qp,
				 struct ibv_exp_send_wr *wr,
				 struct ibv_exp_send_wr **bad_wr);
	struct ibv_mr * (*drv_exp_reg_mr)(struct ibv_exp_reg_mr_in *in);
	struct ibv_mr * (*lib_exp_reg_mr)(struct ibv_exp_reg_mr_in *in);
	struct ibv_ah * (*drv_exp_ibv_create_ah)(struct ibv_pd *pd,
						 struct ibv_exp_ah_attr *attr_exp);
	int (*drv_exp_query_values)(struct ibv_context *context, int q_values,
				    struct ibv_exp_values *values);
	struct ibv_cq * (*exp_create_cq)(struct ibv_context *context, int cqe,
					 struct ibv_comp_channel *channel,
					 int comp_vector, struct ibv_exp_cq_init_attr *attr);
	int (*drv_exp_ibv_poll_cq)(struct ibv_cq *ibcq, int num_entries,
				   struct ibv_exp_wc *wc, uint32_t wc_size);
	void * (*drv_exp_get_legacy_xrc) (struct ibv_srq *ibv_srq);
	void (*drv_exp_set_legacy_xrc) (struct ibv_srq *ibv_srq, void *legacy_xrc);
	struct ibv_mr * (*drv_exp_ibv_reg_shared_mr)(struct ibv_exp_reg_shared_mr_in *in);
	struct ibv_mr * (*lib_exp_ibv_reg_shared_mr)(struct ibv_exp_reg_shared_mr_in *in);
	int (*drv_exp_modify_qp)(struct ibv_qp *qp, struct ibv_exp_qp_attr *attr,
				 uint64_t exp_attr_mask);
	int (*lib_exp_modify_qp)(struct ibv_qp *qp, struct ibv_exp_qp_attr *attr,
				 uint64_t exp_attr_mask);
	int (*drv_exp_post_task)(struct ibv_context *context,
				 struct ibv_exp_task *task,
				 struct ibv_exp_task **bad_task);
	int (*lib_exp_post_task)(struct ibv_context *context,
				 struct ibv_exp_task *task,
				 struct ibv_exp_task **bad_task);
	int (*drv_exp_modify_cq)(struct ibv_cq *cq,
				 struct ibv_exp_cq_attr *attr, int attr_mask);
	int (*lib_exp_modify_cq)(struct ibv_cq *cq,
				 struct ibv_exp_cq_attr *attr, int attr_mask);
	int (*drv_exp_ibv_destroy_flow) (struct ibv_exp_flow *flow);
	int (*lib_exp_ibv_destroy_flow) (struct ibv_exp_flow *flow);
	struct ibv_exp_flow * (*drv_exp_ibv_create_flow) (struct ibv_qp *qp,
						      struct ibv_exp_flow_attr
						      *flow_attr);
	struct ibv_exp_flow * (*lib_exp_ibv_create_flow) (struct ibv_qp *qp,
							  struct ibv_exp_flow_attr
							  *flow_attr);

	int (*drv_exp_query_port)(struct ibv_context *context, uint8_t port_num,
				  struct ibv_exp_port_attr *port_attr);
	int (*lib_exp_query_port)(struct ibv_context *context, uint8_t port_num,
				  struct ibv_exp_port_attr *port_attr);
	struct ibv_exp_dct *(*create_dct)(struct ibv_context *context,
					  struct ibv_exp_dct_init_attr *attr);
	int (*destroy_dct)(struct ibv_exp_dct *dct);
	int (*query_dct)(struct ibv_exp_dct *dct, struct ibv_exp_dct_attr *attr);
	int (*drv_exp_query_device)(struct ibv_context *context,
				    struct ibv_exp_device_attr *attr);
	int (*lib_exp_query_device)(struct ibv_context *context,
				    struct ibv_exp_device_attr *attr);
	struct ibv_qp *(*drv_exp_create_qp)(struct ibv_context *context,
					    struct ibv_exp_qp_init_attr *init_attr);
	struct ibv_qp *(*lib_exp_create_qp)(struct ibv_context *context,
					    struct ibv_exp_qp_init_attr *init_attr);
	size_t sz;	/* Set by library on struct allocation,	*/
			/* must be located as last field	*/
};

#define ETHERNET_LL_SIZE 6

static inline struct verbs_context_exp *verbs_get_exp_ctx(struct ibv_context *ctx)
{
	struct verbs_context *app_ex_ctx = verbs_get_ctx(ctx);
	char *actual_ex_ctx;

	if (!app_ex_ctx || !(app_ex_ctx->has_comp_mask & VERBS_CONTEXT_EXP))
		return NULL;

	actual_ex_ctx = ((char *)ctx) - (app_ex_ctx->sz - sizeof(struct ibv_context));

	return (struct verbs_context_exp *)(actual_ex_ctx - sizeof(struct verbs_context_exp));
}

#define verbs_get_exp_ctx_op(ctx, op) ({ \
	struct verbs_context_exp *_vctx = verbs_get_exp_ctx(ctx); \
	(!_vctx || (_vctx->sz < sizeof(*_vctx) - offsetof(struct verbs_context_exp, op)) || \
	!_vctx->op) ? NULL : _vctx; })

#define verbs_set_exp_ctx_op(_vctx, op, ptr) ({ \
	struct verbs_context_exp *vctx = _vctx; \
	if (vctx && (vctx->sz >= sizeof(*vctx) - offsetof(struct verbs_context_exp, op))) \
		vctx->op = ptr; })


/*
 * ibv_exp_alloc_ec_calc() - allocate an erasure coding
 *     calculation offload context
 * @pd:          user allocated protection domain
 * @attrs:       initialization attributes
 *
 * Returns handle handle to the EC calculation APIs
 */
static inline struct ibv_exp_ec_calc *
ibv_exp_alloc_ec_calc(struct ibv_pd *pd,
		      struct ibv_exp_ec_calc_init_attr *attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(pd->context, alloc_ec_calc);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}
	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(attr->comp_mask,
					      IBV_EXP_EC_CALC_INIT_ATTR_RESERVED - 1);

	return vctx->alloc_ec_calc(pd, attr);
}

/*
 * ibv_exp_dealloc_ec_calc() - free an erasure coding
 *     calculation offload context
 * @ec_calc:       ec context
 */
static inline void ibv_exp_dealloc_ec_calc(struct ibv_exp_ec_calc *calc)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, dealloc_ec_calc);
	if (!vctx) {
		errno = ENOSYS;
		return;
	}

	vctx->dealloc_ec_calc(calc);
}

/**
 * ibv_exp_ec_encode_async() - asynchronous encode of given data blocks
 *    and place in code_blocks
 * @ec_calc:          erasure coding calculation engine
 * @ec_mem:           erasure coding memory layout
 * @ec_comp:          EC calculation completion context
 *
 * Restrictions:
 * - ec_calc is an initialized erasure coding calc engine structure
 * - ec_mem.data_blocks sg array must describe the data memory
 *   layout, the total length of the sg elements must satisfy
 *   k * ec_mem.block_size.
 * - ec_mem.num_data_sg must not exceed the calc max_data_sge
 * - ec_mem.code_blocks sg array must describe the code memory
 *   layout, the total length of the sg elements must satisfy
 *   m * ec_mem.block_size.
 * - ec_mem.num_code_sg must not exceed the calc max_code_sge
 *
 * Notes:
 * The ec_calc will perform the erasure coding calc operation,
 * once it completes, it will call ec_comp->done() handle.
 * The caller will take it from there.
 */
static inline int
ibv_exp_ec_encode_async(struct ibv_exp_ec_calc *calc,
			struct ibv_exp_ec_mem *ec_mem,
			struct ibv_exp_ec_comp *ec_comp)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, ec_encode_async);
	if (!vctx)
		return ENOSYS;

	return vctx->ec_encode_async(calc, ec_mem, ec_comp);
}

/**
 * ibv_exp_ec_encode_sync() - synchronous encode of given data blocks
 *    and place in code_blocks
 * @ec_calc:          erasure coding calculation engine
 * @ec_mem:           erasure coding memory layout
 *
 * Restrictions:
 * - ec_calc is an initialized erasure coding calc engine structure
 * - ec_mem.data_blocks sg array must describe the data memory
 *   layout, the total length of the sg elements must satisfy
 *   k * ec_mem.block_size.
 * - ec_mem.num_data_sg must not exceed the calc max_data_sge
 * - ec_mem.code_blocks sg array must describe the code memory
 *   layout, the total length of the sg elements must satisfy
 *   m * ec_mem.block_size.
 * - ec_mem.num_code_sg must not exceed the calc max_code_sge
 *
 * Returns 0 on success, non-zero on failure.
 *
 */
static inline int
ibv_exp_ec_encode_sync(struct ibv_exp_ec_calc *calc,
		       struct ibv_exp_ec_mem *ec_mem)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, ec_encode_sync);
	if (!vctx)
		return ENOSYS;

	return vctx->ec_encode_sync(calc, ec_mem);
}

/**
 * ibv_exp_ec_decode_async() - decode a given set of data blocks
 *    and code_blocks and place into output recovery blocks
 * @ec_calc:          erasure coding calculation engine
 * @ec_mem:           erasure coding memory layout
 * @erasures:         pointer to byte-map of which blocks were erased
 * 		      and needs to be recovered
 * @decode_matrix:    buffer that contains the decode matrix
 * @ec_comp:          EC calculation completion context
 *
 * Restrictions:
 * - ec_calc is an initialized erasure coding calc engine structure
 * - ec_mem.data_blocks sg array must describe the data memory
 *   layout, the total length of the sg elements must satisfy
 *   k * ec_mem.block_size.
 * - ec_mem.num_data_sg must not exceed the calc max_data_sge
 * - ec_mem.code_blocks sg array must describe the code memory
 *   layout, the total length of the sg elements must satisfy
 *   number of missing blocks * ec_mem.block_size.
 * - ec_mem.num_code_sg must not exceed the calc max_code_sge
 * - erasures byte-mask consists of the survived and erased blocks.
 *   The first k bytes stand for the k data blocks followed by
 *   m bytes that stand for the code blocks.
 *
 * Returns 0 on success, or non-zero on failure with a corresponding
 * errno.
 *
 * Notes:
 * The ec_calc will perform the erasure coding calc operation,
 * once it completes, it will call ec_comp->done() handle.
 * The caller will take it from there
 */
static inline int
ibv_exp_ec_decode_async(struct ibv_exp_ec_calc *calc,
			struct ibv_exp_ec_mem *ec_mem,
			uint8_t *erasures,
			uint8_t *decode_matrix,
			struct ibv_exp_ec_comp *ec_comp)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, ec_decode_async);
	if (!vctx)
		return ENOSYS;

	return vctx->ec_decode_async(calc, ec_mem, erasures,
				     decode_matrix, ec_comp);
}

/**
 * ibv_exp_ec_decode_sync() - decode a given set of data blocks
 *    and code_blocks and place into output recovery blocks
 * @ec_calc:          erasure coding calculation engine
 * @ec_mem:           erasure coding memory layout
 * @erasures:         pointer to byte-map of which blocks were erased
 * 		      and needs to be recovered
 * @decode_matrix:    registered buffer of the decode matrix
 *
 * Restrictions:
 * - ec_calc is an initialized erasure coding calc engine structure
 * - ec_mem.data_blocks sg array must describe the data memory
 *   layout, the total length of the sg elements must satisfy
 *   k * ec_mem.block_size.
 * - ec_mem.num_data_sg must not exceed the calc max_data_sge
 * - ec_mem.code_blocks sg array must describe the code memory
 *   layout, the total length of the sg elements must satisfy
 *   number of missing blocks * ec_mem.block_size.
 * - ec_mem.num_code_sg must not exceed the calc max_code_sge
 * - erasures byte-map consists of the survived and erased blocks.
 *   The first k bytes stand for the k data blocks followed by
 *   m bytes that stand for the code blocks.
 *
 * Returns 0 on success, or non-zero on failure with a corresponding
 * errno.
 */
static inline int
ibv_exp_ec_decode_sync(struct ibv_exp_ec_calc *calc,
		       struct ibv_exp_ec_mem *ec_mem,
		       uint8_t *erasures,
		       uint8_t *decode_matrix)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, ec_decode_sync);
	if (!vctx)
		return ENOSYS;

	return vctx->ec_decode_sync(calc, ec_mem, erasures, decode_matrix);
}

/**
 * ibv_exp_ec_update_async() - copmutes redundancies based on updated blocks,
 *    their replacements and old redundancies and place into output code blocks
 * @ec_calc:          erasure coding calculation engine
 * @ec_mem:           erasure coding memory layout
 * @data_updates:     array which is a map of data blocks that are updated
 * @code_updates:     array which is a map of code blocks to be computed
 * @ec_comp:          EC calculation completion context
 *
 * Restrictions:
 * - ec_calc is an initialized erasure coding calc engine structure
 * - ec_mem.data_blocks sg array must describe the data memory
 *   layout in the following way:
 *   assume we want to update blocks d_i and d_j with i<j,
 *   then sg enries should be as follows:
 *   c_0 ... c_m d_i d'_i d_j d'_j
 *   were c_0 ... c_m are all previous redundancies,
 *   d_i is an original i-th block, d'_i is new i-th block
 * - ec_mem.num_data_sg should be equal to the number of sg entries,
 *   i.e. to num of code blocks to be updated + 2*num of updates
 * - ec_mem.code_blocks sg array must describe the code memory
 *   layout, the total length of the sg elements must satisfy
 *   number of overall code blocks to be updated.
 * - ec_mem.num_code_sg must be equal to the number of code blocks
 *   to be updated and not to exceed the calc max_code_sge
 * - data_updates is an array of size k (=number of data blocks)
 *   and is a byte-map for blocks to be updated, i.e
 *   if we want to update i-th block and do not want to update j-th block,
 *   then data_updates[i]=1 and data_updates[j]=0.
 * - code_updates is an array of size m(=number of code blocks)
 *   and is a byte-map of code blocks that should be computed, i.e
 *   if we want to compute i-th block and do not want to compute j-th block,
 *   then code_updates[i]=1 and code_updates[j]=0.
 *
 * Returns 0 on success, or non-zero on failure with a corresponding
 * errno.
 */

static inline int
ibv_exp_ec_update_async(struct ibv_exp_ec_calc *calc,
			struct ibv_exp_ec_mem *ec_mem,
			uint8_t *data_updates,
			uint8_t *code_updates,
			struct ibv_exp_ec_comp *ec_comp)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, ec_update_async);
	if (!vctx)
		return -ENOSYS;

	return vctx->ec_update_async(calc, ec_mem, data_updates,
				     code_updates, ec_comp);
}

/**
 * ibv_exp_ec_update_sync() - copmutes redundancies based on updated blocks,
 *    their replacements and old redundancies and place into output code blocks
 * @ec_calc:          erasure coding calculation engine
 * @ec_mem:           erasure coding memory layout
 * @data_updates:     array which is a map of data blocks that are updated
 * @code_updates:     array which is a map of code blocks to be computed
 *
 * Restrictions:
 * - ec_calc is an initialized erasure coding calc engine structure
 * - ec_mem.data_blocks sg array must describe the data memory
 *   layout in the following way:
 *   assume we want to update blocks d_i and d_j with i<j,
 *   then enries of sg should be as follows:
 *   c_0..c_m d_i d'_i d_j d'_j
 *   were c_0 .. c_m are previous redundancies,
 *   d_i is an original i-th block, d'_i is new i-th block
 * - ec_mem.num_data_sg should be equal to the number of sg entries,
 *   i.e. to num of code blocks to be updated + 2*num of updates
 * - ec_mem.code_blocks sg array must describe the code memory
 *   layout, the total length of the sg elements must satisfy
 *   number of overall code blocks to be updated.
 * - ec_mem.num_code_sg must be equal to the number of code blocks
 *   to be updated and not to exceed the calc max_code_sge
 * - data_updates is an array of size k (=number of data blocks)
 *   and is a byte-map for blocks to be updated, i.e
 *   if we want to update i-th block and do not want to update j-th block,
 *   then data_updates[i]=1 and data_updates[j]=0.
 * - code_updates is an array of size m(=number of code blocks)
 *   and is a bytemap of code blocks that should be computed, i.e
 *   if we want to compute i-th block and do not want to compute j-th block,
 *   then code_updates[i]=1 and code_updates[j]=0.
 *
 * Returns 0 on success, or non-zero on failure with a corresponding
 * errno.
 */

static inline int
ibv_exp_ec_update_sync(struct ibv_exp_ec_calc *calc,
		       struct ibv_exp_ec_mem *ec_mem,
		       uint8_t *data_updates,
		       uint8_t *code_updates)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, ec_update_sync);
	if (!vctx)
		return -ENOSYS;

	return vctx->ec_update_sync(calc, ec_mem, data_updates, code_updates);
}
/**
 * ibv_exp_ec_calc_poll() - poll for EC calculation
 *
 * @calc: EC calc context
 * @n: number of calculations to poll
 *
 * Returns the number of calc completions processed which
 * is lower or equal to n. Relevant only when EC calc context
 * was allocated in polling mode.
 */
static inline int
ibv_exp_ec_poll(struct ibv_exp_ec_calc *calc, int n)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, ec_poll);
	if (!vctx)
		return ENOSYS;

	return vctx->ec_poll(calc, n);
}

/**
 * ibv_exp_ec_encode_send() - encode a given data blocks
 *    initiate the data and code blocks transfers to the wire with the qps array.
 * @ec_calc:          erasure coding calculation engine
 * @ec_mem:           erasure coding memory layout context
 * @data_stripes:     array of stripe handles, each represents a data block channel
 * @code_stripes:     array of qp handles, each represents a code block channel
 *
 * Restrictions:
 * - ec_calc is an initialized erasure coding calc engine structure
 * - ec_mem.data_blocks sg array must describe the data memory
 *   layout, the total length of the sg elements must satisfy
 *   k * ec_mem.block_size.
 * - ec_mem.num_data_sg must not exceed the calc max_data_sge
 * - ec_mem.code_blocks sg array must describe the code memory
 *   layout, the total length of the sg elements must satisfy
 *   m * ec_mem.block_size.
 * - ec_mem.num_code_sg must not exceed the calc max_code_sge
 *
 * Returns 0 on success, or non-zero on failure with a corresponding
 * errno.
 */
static inline int
ibv_exp_ec_encode_send(struct ibv_exp_ec_calc *calc,
		       struct ibv_exp_ec_mem *ec_mem,
		       struct ibv_exp_ec_stripe *data_stripes,
		       struct ibv_exp_ec_stripe *code_stripes)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(calc->pd->context, ec_encode_send);
	if (!vctx)
		return -ENOSYS;

	return vctx->ec_encode_send(calc, ec_mem, data_stripes, code_stripes);
}

static inline struct ibv_qp *
ibv_exp_create_qp(struct ibv_context *context, struct ibv_exp_qp_init_attr *qp_init_attr)
{
	struct verbs_context_exp *vctx;
	uint32_t mask = qp_init_attr->comp_mask;

	if (mask == IBV_EXP_QP_INIT_ATTR_PD)
		return ibv_create_qp(qp_init_attr->pd,
				     (struct ibv_qp_init_attr *) qp_init_attr);

	vctx = verbs_get_exp_ctx_op(context, lib_exp_create_qp);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}
	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(qp_init_attr->comp_mask,
					      IBV_EXP_QP_INIT_ATTR_RESERVED1 - 1);

	return vctx->lib_exp_create_qp(context, qp_init_attr);
}

/*
 * ibv_exp_use_priv_env
 *
 * switch to use private environment
 */
static inline int ibv_exp_use_priv_env(struct ibv_context *context)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, lib_exp_use_priv_env);
	if (!vctx) {
		errno = ENOSYS;
		return -1;
	}

	return vctx->lib_exp_use_priv_env(context);
}

/*
 * ibv_exp_poll_dc_info
 *
 * The function is not thread safe. Any locking must be done by the user.
 *
 * Return: >= 0 number of returned entries
 *	   < 0 error
 *
 */
static inline int ibv_exp_poll_dc_info(struct ibv_context *context,
				       struct ibv_exp_dc_info_ent *ents,
				       int nent, int port)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, drv_exp_poll_dc_info);
	if (!vctx) {
		errno = ENOSYS;
		return -1;
	}

	return vctx->drv_exp_poll_dc_info(context, ents, nent, port);
}

/*
 * ibv_exp_setenv
 *
 * see man setenv for parameter description
 */
static inline int ibv_exp_setenv(struct ibv_context *context,
				 const char *name,
				 const char *value,
				 int overwrite)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, lib_exp_setenv);
	if (!vctx)
		return setenv(name, value, overwrite);

	return vctx->lib_exp_setenv(context, name, value, overwrite);
}

static inline int ibv_exp_query_device(struct ibv_context *context,
				       struct ibv_exp_device_attr *attr)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(context,
							      lib_exp_query_device);
	if (!vctx)
		return ENOSYS;

	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(attr->comp_mask,
						IBV_EXP_DEVICE_ATTR_RESERVED - 1);
	return vctx->lib_exp_query_device(context, attr);
}

static inline struct ibv_exp_dct *
ibv_exp_create_dct(struct ibv_context *context,
		   struct ibv_exp_dct_init_attr *attr)
{
	struct verbs_context_exp *vctx;
	struct ibv_exp_dct *dct;

	vctx = verbs_get_exp_ctx_op(context, create_dct);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}

	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(attr->comp_mask,
					      IBV_EXP_DCT_INIT_ATTR_RESERVED - 1);
	pthread_mutex_lock(&context->mutex);
	dct = vctx->create_dct(context, attr);
	if (dct)
		dct->context = context;

	pthread_mutex_unlock(&context->mutex);

	return dct;
}

static inline int ibv_exp_destroy_dct(struct ibv_exp_dct *dct)
{
	struct verbs_context_exp *vctx;
	struct ibv_context *context = dct->context;
	int err;

	vctx = verbs_get_exp_ctx_op(context, destroy_dct);
	if (!vctx) {
		errno = ENOSYS;
		return errno;
	}

	pthread_mutex_lock(&context->mutex);
	err = vctx->destroy_dct(dct);
	pthread_mutex_unlock(&context->mutex);

	return err;
}

static inline int ibv_exp_query_dct(struct ibv_exp_dct *dct,
				    struct ibv_exp_dct_attr *attr)
{
	struct verbs_context_exp *vctx;
	struct ibv_context *context = dct->context;
	int err;

	vctx = verbs_get_exp_ctx_op(context, query_dct);
	if (!vctx) {
		errno = ENOSYS;
		return errno;
	}

	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(attr->comp_mask,
						IBV_EXP_DCT_ATTR_RESERVED - 1);
	pthread_mutex_lock(&context->mutex);
	err = vctx->query_dct(dct, attr);
	pthread_mutex_unlock(&context->mutex);

	return err;
}

static inline int ibv_exp_arm_dct(struct ibv_exp_dct *dct,
				  struct ibv_exp_arm_attr *attr)
{
	struct verbs_context_exp *vctx;
	struct ibv_context *context = dct->context;
	int err;

	vctx = verbs_get_exp_ctx_op(context, lib_exp_arm_dct);
	if (!vctx) {
		errno = ENOSYS;
		return errno;
	}

	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(attr->comp_mask,
						IBV_EXP_ARM_ATTR_RESERVED - 1);
	pthread_mutex_lock(&context->mutex);
	err = vctx->lib_exp_arm_dct(dct, attr);
	pthread_mutex_unlock(&context->mutex);

	return err;
}

static inline int ibv_exp_query_port(struct ibv_context *context,
				     uint8_t port_num,
				     struct ibv_exp_port_attr *port_attr)
{
	struct verbs_context_exp *vctx;

	if (0 == port_attr->comp_mask)
		return ibv_query_port(context, port_num,
				      &port_attr->port_attr);

	/* Check that only valid flags were given */
	if (!(port_attr->comp_mask & IBV_EXP_QUERY_PORT_ATTR_MASK1) ||
	    (port_attr->comp_mask & ~IBV_EXP_QUERY_PORT_ATTR_MASKS) ||
	    (port_attr->mask1 & ~IBV_EXP_QUERY_PORT_MASK)) {
		errno = EINVAL;
		return -errno;
	}

	vctx = verbs_get_exp_ctx_op(context, lib_exp_query_port);

	if (!vctx) {
		/* Fallback to legacy mode */
		if (port_attr->comp_mask == IBV_EXP_QUERY_PORT_ATTR_MASK1 &&
		    !(port_attr->mask1 & ~IBV_EXP_QUERY_PORT_STD_MASK))
			return ibv_query_port(context, port_num,
					      &port_attr->port_attr);

		/* Unsupported field was requested */
		errno = ENOSYS;
		return -errno;
	}
	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(port_attr->comp_mask,
						IBV_EXP_QUERY_PORT_ATTR_RESERVED - 1);

	return vctx->lib_exp_query_port(context, port_num, port_attr);
}

/**
 * ibv_exp_post_task - Post a list of tasks to different QPs.
 */
static inline int ibv_exp_post_task(struct ibv_context *context,
				    struct ibv_exp_task *task,
				    struct ibv_exp_task **bad_task)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(context,
							      lib_exp_post_task);
	if (!vctx)
		return ENOSYS;

	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(task->comp_mask,
						IBV_EXP_TASK_RESERVED - 1);

	return vctx->lib_exp_post_task(context, task, bad_task);
}

static inline int ibv_exp_query_values(struct ibv_context *context, int q_values,
				       struct ibv_exp_values *values)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(context,
							      drv_exp_query_values);
	if (!vctx) {
		errno = ENOSYS;
		return -errno;
	}
	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(values->comp_mask,
						IBV_EXP_VALUES_RESERVED - 1);

	return vctx->drv_exp_query_values(context, q_values, values);
}

static inline struct ibv_exp_flow *ibv_exp_create_flow(struct ibv_qp *qp,
						       struct ibv_exp_flow_attr *flow)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(qp->context,
							      lib_exp_ibv_create_flow);
	if (!vctx || !vctx->lib_exp_ibv_create_flow)
		return NULL;

	if (flow->reserved != 0L) {
		fprintf(stderr, "%s:%d: flow->reserved must be 0\n", __FUNCTION__, __LINE__);
		flow->reserved = 0L;
	}

	return vctx->lib_exp_ibv_create_flow(qp, flow);
}

static inline int ibv_exp_destroy_flow(struct ibv_exp_flow *flow_id)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(flow_id->context,
							      lib_exp_ibv_destroy_flow);
	if (!vctx || !vctx->lib_exp_ibv_destroy_flow)
		return -ENOSYS;

	return vctx->lib_exp_ibv_destroy_flow(flow_id);
}

static inline int ibv_exp_poll_cq(struct ibv_cq *ibcq, int num_entries,
				  struct ibv_exp_wc *wc, uint32_t wc_size)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(ibcq->context,
							      drv_exp_ibv_poll_cq);
	if (!vctx)
		return -ENOSYS;

	return vctx->drv_exp_ibv_poll_cq(ibcq, num_entries, wc, wc_size);
}

/**
 * ibv_exp_post_send - Post a list of work requests to a send queue.
 */
static inline int ibv_exp_post_send(struct ibv_qp *qp,
				    struct ibv_exp_send_wr *wr,
				    struct ibv_exp_send_wr **bad_wr)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(qp->context,
							      drv_exp_post_send);
	if (!vctx)
		return -ENOSYS;

	return vctx->drv_exp_post_send(qp, wr, bad_wr);
}

/**
 * ibv_exp_reg_shared_mr - Register to an existing shared memory region
 * @in - Experimental register shared MR input data.
 */
static inline struct ibv_mr *ibv_exp_reg_shared_mr(struct ibv_exp_reg_shared_mr_in *mr_in)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(mr_in->pd->context,
							      lib_exp_ibv_reg_shared_mr);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}
	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(mr_in->comp_mask,
					      IBV_EXP_REG_SHARED_MR_RESERVED - 1);

	return vctx->lib_exp_ibv_reg_shared_mr(mr_in);
}

/**
 * ibv_exp_modify_cq - Modifies the attributes for the specified CQ.
 * @cq: The CQ to modify.
 * @cq_attr: Specifies the CQ attributes to modify.
 * @cq_attr_mask: A bit-mask used to specify which attributes of the CQ
 *   are being modified.
 */
static inline int ibv_exp_modify_cq(struct ibv_cq *cq,
				    struct ibv_exp_cq_attr *cq_attr,
				    int cq_attr_mask)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(cq->context,
							      lib_exp_modify_cq);
	if (!vctx)
		return ENOSYS;

	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(cq_attr->comp_mask,
						IBV_EXP_CQ_ATTR_RESERVED - 1);

	return vctx->lib_exp_modify_cq(cq, cq_attr, cq_attr_mask);
}

static inline struct ibv_cq *ibv_exp_create_cq(struct ibv_context *context,
					       int cqe,
					       void *cq_context,
					       struct ibv_comp_channel *channel,
					       int comp_vector,
					       struct ibv_exp_cq_init_attr *attr)
{
	struct verbs_context_exp *vctx;
	struct ibv_cq *cq;

	vctx = verbs_get_exp_ctx_op(context, exp_create_cq);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}

	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(attr->comp_mask,
					      IBV_EXP_CQ_INIT_ATTR_RESERVED1 - 1);
	pthread_mutex_lock(&context->mutex);
	cq = vctx->exp_create_cq(context, cqe, channel, comp_vector, attr);
	if (cq) {
		cq->context		   = context;
		cq->channel		   = channel;
		if (channel)
			++channel->refcnt;
		cq->cq_context		   = cq_context;
		cq->comp_events_completed  = 0;
		cq->async_events_completed = 0;
		pthread_mutex_init(&cq->mutex, NULL);
		pthread_cond_init(&cq->cond, NULL);
	}

	pthread_mutex_unlock(&context->mutex);

	return cq;
}

/**
 * ibv_exp_modify_qp - Modify a queue pair.
 * The argument exp_attr_mask specifies the QP attributes to be modified.
 * Use ibv_exp_qp_attr_mask for this argument.
 */
static inline int
ibv_exp_modify_qp(struct ibv_qp *qp, struct ibv_exp_qp_attr *attr, uint64_t exp_attr_mask)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(qp->context, lib_exp_modify_qp);
	if (!vctx) {
		errno = ENOSYS;
		return errno;
	}
	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(attr->comp_mask,
						IBV_EXP_QP_ATTR_RESERVED - 1);

	return vctx->lib_exp_modify_qp(qp, attr, exp_attr_mask);
}

/**
 * ibv_exp_reg_mr - Register a memory region
 */
static inline struct ibv_mr *ibv_exp_reg_mr(struct ibv_exp_reg_mr_in *in)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(in->pd->context, lib_exp_reg_mr);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}
	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(in->comp_mask,
					      IBV_EXP_REG_MR_RESERVED - 1);

	return vctx->lib_exp_reg_mr(in);
}


/**
 * ibv_exp_bind_mw - Bind a memory window to a region
 */
static inline int ibv_exp_bind_mw(struct ibv_exp_mw_bind *mw_bind)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(mw_bind->mw->context, lib_exp_bind_mw);
	if (!vctx) {
		errno = ENOSYS;
		return errno;
	}
	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(mw_bind->comp_mask,
						IBV_EXP_BIND_MW_RESERVED - 1);

	return vctx->lib_exp_bind_mw(mw_bind);
}

/**
 * ibv_exp_prefetch_mr - Prefetch part of a memory region.
 *
 * Can be used only with MRs registered with IBV_EXP_ACCESS_ON_DEMAND
 *
 * Returns 0 on success,
 * - ENOSYS libibverbs or provider driver doesn't support the prefetching verb.
 * - EFAULT when the range requested is out of the memory region bounds, or when
 *   parts of it are not part of the process address space.
 * - EINVAL when the MR is invalid.
 */
static inline int ibv_exp_prefetch_mr(
		struct ibv_mr *mr,
		struct ibv_exp_prefetch_attr *attr)
{
	struct verbs_context_exp *vctx = verbs_get_exp_ctx_op(mr->context,
			lib_exp_prefetch_mr);

	if (!vctx) {
		errno = ENOSYS;
		return errno;
	}
	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(attr->comp_mask,
						IBV_EXP_PREFETCH_MR_RESERVED - 1);

	return vctx->lib_exp_prefetch_mr(mr, attr);
}

typedef int (*drv_exp_post_send_func)(struct ibv_qp *qp,
				 struct ibv_exp_send_wr *wr,
				 struct ibv_exp_send_wr **bad_wr);
typedef int (*drv_post_send_func)(struct ibv_qp *qp, struct ibv_send_wr *wr,
				struct ibv_send_wr **bad_wr);
typedef int (*drv_exp_poll_cq_func)(struct ibv_cq *ibcq, int num_entries,
				   struct ibv_exp_wc *wc, uint32_t wc_size);
typedef int (*drv_poll_cq_func)(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc);
typedef int (*drv_post_recv_func)(struct ibv_qp *qp, struct ibv_recv_wr *wr,
			 struct ibv_recv_wr **bad_wr);

static inline void *ibv_exp_get_provider_func(struct ibv_context *context,
						enum ibv_exp_func_name name)
{
	struct verbs_context_exp *vctx;

	switch (name) {
	case IBV_EXP_POST_SEND_FUNC:
		vctx = verbs_get_exp_ctx_op(context, drv_exp_post_send);
		if (!vctx)
			goto error;

		return (void *)vctx->drv_exp_post_send;

	case IBV_EXP_POLL_CQ_FUNC:
		vctx = verbs_get_exp_ctx_op(context, drv_exp_ibv_poll_cq);
		if (!vctx)
			goto error;

		return (void *)vctx->drv_exp_ibv_poll_cq;

	case IBV_POST_SEND_FUNC:
		if (!context->ops.post_send)
			goto error;

		return (void *)context->ops.post_send;

	case IBV_POLL_CQ_FUNC:
		if (!context->ops.poll_cq)
			goto error;

		return (void *)context->ops.poll_cq;

	case IBV_POST_RECV_FUNC:
		if (!context->ops.post_recv)
			goto error;

		return (void *)context->ops.post_recv;

	default:
		break;
	}

error:
	errno = ENOSYS;
	return NULL;
}

static inline struct ibv_mr *ibv_exp_create_mr(struct ibv_exp_create_mr_in *in)
{
	struct verbs_context_exp *vctx;
	struct ibv_mr *mr;

	vctx = verbs_get_exp_ctx_op(in->pd->context, lib_exp_create_mr);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}

	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(in->comp_mask,
					      IBV_EXP_CREATE_MR_IN_RESERVED - 1);
	mr = vctx->lib_exp_create_mr(in);
	if (mr)
		mr->pd = in->pd;

	return mr;
}

static inline int ibv_exp_query_mkey(struct ibv_mr *mr,
				     struct ibv_exp_mkey_attr *attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(mr->context, lib_exp_query_mkey);
	if (!vctx) {
		errno = ENOSYS;
		return errno;
	}

	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(attr->comp_mask,
						IBV_EXP_MKEY_ATTR_RESERVED - 1);

	return vctx->lib_exp_query_mkey(mr, attr);
}

static inline int ibv_exp_dealloc_mkey_list_memory(struct ibv_exp_mkey_list_container *mem)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(mem->context,
				    lib_exp_dealloc_mkey_list_memory);
	if (!vctx) {
		errno = ENOSYS;
		return errno;
	}

	return vctx->lib_exp_dealloc_mkey_list_memory(mem);
}

static inline struct ibv_exp_mkey_list_container *
ibv_exp_alloc_mkey_list_memory(struct ibv_exp_mkey_list_container_attr *attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(attr->pd->context,
				    lib_exp_alloc_mkey_list_memory);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}

	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(attr->comp_mask,
					      IBV_EXP_MKEY_LIST_CONTAINER_RESERVED - 1);

	return vctx->lib_exp_alloc_mkey_list_memory(attr);
}

/**
 * ibv_exp_create_res_domain - create resource domain
 */
static inline struct ibv_exp_res_domain *ibv_exp_create_res_domain(struct ibv_context *context,
								   struct ibv_exp_res_domain_init_attr *attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, exp_create_res_domain);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}

	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(attr->comp_mask,
					      IBV_EXP_RES_DOMAIN_RESERVED - 1);

	return vctx->exp_create_res_domain(context, attr);
}

/**
 * ibv_exp_destroy_res_domain - destroy resource domain
 */
static inline int ibv_exp_destroy_res_domain(struct ibv_context *context,
					     struct ibv_exp_res_domain *res_dom,
					     struct ibv_exp_destroy_res_domain_attr *attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, exp_destroy_res_domain);
	if (!vctx)
		return errno = ENOSYS;

	if (attr)
		IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(attr->comp_mask,
							IBV_EXP_DESTROY_RES_DOMAIN_RESERVED - 1);

	return vctx->exp_destroy_res_domain(context, res_dom, attr);
}

/**
 * ibv_exp_query_intf - query for family of verbs interface for specific QP/CQ
 *
 * Usually family of data-path verbs.
 * Application may call ibv_exp_query_intf for QPs in the following states:
 *    IBV_QPS_INIT, IBV_QPS_RTR and IBV_QPS_RTS
 *
 * Returns the family of verbs.
 * On failure returns NULL. The failure reason provided by the 'status'
 * output variable.
 */
static inline void *ibv_exp_query_intf(struct ibv_context *context,
				       struct ibv_exp_query_intf_params *params,
				       enum ibv_exp_query_intf_status *status)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, exp_query_intf);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}

	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(params->comp_mask,
					      IBV_EXP_QUERY_INTF_RESERVED - 1);

	return vctx->exp_query_intf(context, params, status);
}

/**
 * ibv_exp_release_intf - release the queried interface
 */
static inline int ibv_exp_release_intf(struct ibv_context *context, void *intf,
				       struct ibv_exp_release_intf_params *params)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, exp_release_intf);
	if (!vctx)
		return errno = ENOSYS;

	if (params)
		IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(params->comp_mask,
							IBV_EXP_RELEASE_INTF_RESERVED - 1);

	return vctx->exp_release_intf(context, intf, params);
}

static inline struct ibv_exp_wq *ibv_exp_create_wq(struct ibv_context *context,
						   struct ibv_exp_wq_init_attr *wq_init_attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, exp_create_wq);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}

	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(wq_init_attr->comp_mask,
							IBV_EXP_CREATE_WQ_RESERVED - 1);

	return vctx->exp_create_wq(context, wq_init_attr);
}

static inline int ibv_exp_modify_wq(struct ibv_exp_wq *wq, struct ibv_exp_wq_attr *wq_attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(wq->context, exp_modify_wq);
	if (!vctx)
		return ENOSYS;

	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(wq_attr->attr_mask,
							IBV_EXP_WQ_ATTR_RESERVED - 1);
	return vctx->exp_modify_wq(wq, wq_attr);
}

static inline int ibv_exp_destroy_wq(struct ibv_exp_wq *wq)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(wq->context, exp_destroy_wq);
	if (!vctx)
		return ENOSYS;

	return vctx->exp_destroy_wq(wq);
}

/*
 * ibv_exp_create_rwq_ind_table - Creates a RQ Indirection Table associated
 * with the specified protection domain.
 * @pd: The protection domain associated with the Indirection Table.
 * @ibv_exp_rwq_ind_table_init_attr: A list of initial attributes required to
 * create the Indirection Table.
 * Return Value
 * ibv_exp_create_rwq_ind_table returns a pointer to the created
 * Indirection Table, or NULL if the request fails.
 */
static inline struct ibv_exp_rwq_ind_table *ibv_exp_create_rwq_ind_table(struct ibv_context *context,
									 struct ibv_exp_rwq_ind_table_init_attr *init_attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, exp_create_rwq_ind_table);
	if (!vctx) {
		errno = ENOSYS;
		return NULL;
	}

	IBV_EXP_RET_NULL_ON_INVALID_COMP_MASK(init_attr->comp_mask,
					      IBV_EXP_CREATE_IND_TABLE_RESERVED - 1);
	return vctx->exp_create_rwq_ind_table(context, init_attr);
}

/*
 * ibv_exp_destroy_rwq_ind_table - Destroys the specified Indirection Table.
 * @rwq_ind_table: The Indirection Table to destroy.
 * Return Value
 * ibv_destroy_rwq_ind_table() returns 0 on success, or the value of errno
 * on failure (which indicates the failure reason).
*/
static inline int ibv_exp_destroy_rwq_ind_table(struct ibv_exp_rwq_ind_table *rwq_ind_table)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(rwq_ind_table->context, exp_destroy_rwq_ind_table);
	if (!vctx)
		return ENOSYS;

	return vctx->exp_destroy_rwq_ind_table(rwq_ind_table);
}

/*
 * ibv_exp_query_gid_attr - query a GID attributes
 * @context: ib context
 * @port_num: port number
 * @index: gid index in the gids table
 * @attr: the gid attributes of index in the gids table
 * Return value
 * ibv_exp_query_gid_attr return 0 on success, or the value of errno on failure.
 */
static inline int ibv_exp_query_gid_attr(struct ibv_context *context,
					 uint8_t port_num,
					 unsigned int index,
					 struct ibv_exp_gid_attr *attr)
{
	struct verbs_context_exp *vctx;

	vctx = verbs_get_exp_ctx_op(context, exp_query_gid_attr);
	if (!vctx)
		return ENOSYS;

	IBV_EXP_RET_EINVAL_ON_INVALID_COMP_MASK(attr->comp_mask,
						IBV_EXP_QUERY_GID_ATTR_RESERVED - 1);
	return vctx->exp_query_gid_attr(context, port_num, index, attr);
}
END_C_DECLS

#define VERBS_MAX_ENV_VAL 4096

#  undef __attribute_const


#endif /* INFINIBAND_VERBS_EXP_H */