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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* hermon_ci.c
* Hermon Channel Interface (CI) Routines
*
* Implements all the routines necessary to interface with the IBTF.
* Pointers to all of these functions are passed to the IBTF at attach()
* time in the ibc_operations_t structure. These functions include all
* of the necessary routines to implement the required InfiniBand "verbs"
* and additional IBTF-specific interfaces.
*/
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/ib/adapters/hermon/hermon.h>
extern uint32_t hermon_kernel_data_ro;
extern uint32_t hermon_user_data_ro;
/* HCA and port related operations */
static ibt_status_t hermon_ci_query_hca_ports(ibc_hca_hdl_t, uint8_t,
ibt_hca_portinfo_t *);
static ibt_status_t hermon_ci_modify_ports(ibc_hca_hdl_t, uint8_t,
ibt_port_modify_flags_t, uint8_t);
static ibt_status_t hermon_ci_modify_system_image(ibc_hca_hdl_t, ib_guid_t);
/* Protection Domains */
static ibt_status_t hermon_ci_alloc_pd(ibc_hca_hdl_t, ibt_pd_flags_t,
ibc_pd_hdl_t *);
static ibt_status_t hermon_ci_free_pd(ibc_hca_hdl_t, ibc_pd_hdl_t);
/* Reliable Datagram Domains */
static ibt_status_t hermon_ci_alloc_rdd(ibc_hca_hdl_t, ibc_rdd_flags_t,
ibc_rdd_hdl_t *);
static ibt_status_t hermon_ci_free_rdd(ibc_hca_hdl_t, ibc_rdd_hdl_t);
/* Address Handles */
static ibt_status_t hermon_ci_alloc_ah(ibc_hca_hdl_t, ibt_ah_flags_t,
ibc_pd_hdl_t, ibt_adds_vect_t *, ibc_ah_hdl_t *);
static ibt_status_t hermon_ci_free_ah(ibc_hca_hdl_t, ibc_ah_hdl_t);
static ibt_status_t hermon_ci_query_ah(ibc_hca_hdl_t, ibc_ah_hdl_t,
ibc_pd_hdl_t *, ibt_adds_vect_t *);
static ibt_status_t hermon_ci_modify_ah(ibc_hca_hdl_t, ibc_ah_hdl_t,
ibt_adds_vect_t *);
/* Queue Pairs */
static ibt_status_t hermon_ci_alloc_qp(ibc_hca_hdl_t, ibtl_qp_hdl_t,
ibt_qp_type_t, ibt_qp_alloc_attr_t *, ibt_chan_sizes_t *, ib_qpn_t *,
ibc_qp_hdl_t *);
static ibt_status_t hermon_ci_alloc_special_qp(ibc_hca_hdl_t, uint8_t,
ibtl_qp_hdl_t, ibt_sqp_type_t, ibt_qp_alloc_attr_t *,
ibt_chan_sizes_t *, ibc_qp_hdl_t *);
static ibt_status_t hermon_ci_alloc_qp_range(ibc_hca_hdl_t, uint_t,
ibtl_qp_hdl_t *, ibt_qp_type_t, ibt_qp_alloc_attr_t *, ibt_chan_sizes_t *,
ibc_cq_hdl_t *, ibc_cq_hdl_t *, ib_qpn_t *, ibc_qp_hdl_t *);
static ibt_status_t hermon_ci_free_qp(ibc_hca_hdl_t, ibc_qp_hdl_t,
ibc_free_qp_flags_t, ibc_qpn_hdl_t *);
static ibt_status_t hermon_ci_release_qpn(ibc_hca_hdl_t, ibc_qpn_hdl_t);
static ibt_status_t hermon_ci_query_qp(ibc_hca_hdl_t, ibc_qp_hdl_t,
ibt_qp_query_attr_t *);
static ibt_status_t hermon_ci_modify_qp(ibc_hca_hdl_t, ibc_qp_hdl_t,
ibt_cep_modify_flags_t, ibt_qp_info_t *, ibt_queue_sizes_t *);
/* Completion Queues */
static ibt_status_t hermon_ci_alloc_cq(ibc_hca_hdl_t, ibt_cq_hdl_t,
ibt_cq_attr_t *, ibc_cq_hdl_t *, uint_t *);
static ibt_status_t hermon_ci_free_cq(ibc_hca_hdl_t, ibc_cq_hdl_t);
static ibt_status_t hermon_ci_query_cq(ibc_hca_hdl_t, ibc_cq_hdl_t,
uint_t *, uint_t *, uint_t *, ibt_cq_handler_id_t *);
static ibt_status_t hermon_ci_resize_cq(ibc_hca_hdl_t, ibc_cq_hdl_t,
uint_t, uint_t *);
static ibt_status_t hermon_ci_modify_cq(ibc_hca_hdl_t, ibc_cq_hdl_t,
uint_t, uint_t, ibt_cq_handler_id_t);
static ibt_status_t hermon_ci_alloc_cq_sched(ibc_hca_hdl_t,
ibt_cq_sched_attr_t *, ibc_sched_hdl_t *);
static ibt_status_t hermon_ci_free_cq_sched(ibc_hca_hdl_t, ibc_sched_hdl_t);
static ibt_status_t hermon_ci_query_cq_handler_id(ibc_hca_hdl_t,
ibt_cq_handler_id_t, ibt_cq_handler_attr_t *);
/* EE Contexts */
static ibt_status_t hermon_ci_alloc_eec(ibc_hca_hdl_t, ibc_eec_flags_t,
ibt_eec_hdl_t, ibc_rdd_hdl_t, ibc_eec_hdl_t *);
static ibt_status_t hermon_ci_free_eec(ibc_hca_hdl_t, ibc_eec_hdl_t);
static ibt_status_t hermon_ci_query_eec(ibc_hca_hdl_t, ibc_eec_hdl_t,
ibt_eec_query_attr_t *);
static ibt_status_t hermon_ci_modify_eec(ibc_hca_hdl_t, ibc_eec_hdl_t,
ibt_cep_modify_flags_t, ibt_eec_info_t *);
/* Memory Registration */
static ibt_status_t hermon_ci_register_mr(ibc_hca_hdl_t, ibc_pd_hdl_t,
ibt_mr_attr_t *, void *, ibc_mr_hdl_t *, ibt_mr_desc_t *);
static ibt_status_t hermon_ci_register_buf(ibc_hca_hdl_t, ibc_pd_hdl_t,
ibt_smr_attr_t *, struct buf *, void *, ibt_mr_hdl_t *, ibt_mr_desc_t *);
static ibt_status_t hermon_ci_register_shared_mr(ibc_hca_hdl_t,
ibc_mr_hdl_t, ibc_pd_hdl_t, ibt_smr_attr_t *, void *,
ibc_mr_hdl_t *, ibt_mr_desc_t *);
static ibt_status_t hermon_ci_deregister_mr(ibc_hca_hdl_t, ibc_mr_hdl_t);
static ibt_status_t hermon_ci_query_mr(ibc_hca_hdl_t, ibc_mr_hdl_t,
ibt_mr_query_attr_t *);
static ibt_status_t hermon_ci_reregister_mr(ibc_hca_hdl_t, ibc_mr_hdl_t,
ibc_pd_hdl_t, ibt_mr_attr_t *, void *, ibc_mr_hdl_t *,
ibt_mr_desc_t *);
static ibt_status_t hermon_ci_reregister_buf(ibc_hca_hdl_t, ibc_mr_hdl_t,
ibc_pd_hdl_t, ibt_smr_attr_t *, struct buf *, void *, ibc_mr_hdl_t *,
ibt_mr_desc_t *);
static ibt_status_t hermon_ci_sync_mr(ibc_hca_hdl_t, ibt_mr_sync_t *, size_t);
static ibt_status_t hermon_ci_register_dma_mr(ibc_hca_hdl_t, ibc_pd_hdl_t,
ibt_dmr_attr_t *, void *, ibc_mr_hdl_t *, ibt_mr_desc_t *);
/* Memory Windows */
static ibt_status_t hermon_ci_alloc_mw(ibc_hca_hdl_t, ibc_pd_hdl_t,
ibt_mw_flags_t, ibc_mw_hdl_t *, ibt_rkey_t *);
static ibt_status_t hermon_ci_free_mw(ibc_hca_hdl_t, ibc_mw_hdl_t);
static ibt_status_t hermon_ci_query_mw(ibc_hca_hdl_t, ibc_mw_hdl_t,
ibt_mw_query_attr_t *);
/* Multicast Groups */
static ibt_status_t hermon_ci_attach_mcg(ibc_hca_hdl_t, ibc_qp_hdl_t,
ib_gid_t, ib_lid_t);
static ibt_status_t hermon_ci_detach_mcg(ibc_hca_hdl_t, ibc_qp_hdl_t,
ib_gid_t, ib_lid_t);
/* Work Request and Completion Processing */
static ibt_status_t hermon_ci_post_send(ibc_hca_hdl_t, ibc_qp_hdl_t,
ibt_send_wr_t *, uint_t, uint_t *);
static ibt_status_t hermon_ci_post_recv(ibc_hca_hdl_t, ibc_qp_hdl_t,
ibt_recv_wr_t *, uint_t, uint_t *);
static ibt_status_t hermon_ci_poll_cq(ibc_hca_hdl_t, ibc_cq_hdl_t,
ibt_wc_t *, uint_t, uint_t *);
static ibt_status_t hermon_ci_notify_cq(ibc_hca_hdl_t, ibc_cq_hdl_t,
ibt_cq_notify_flags_t);
/* CI Object Private Data */
static ibt_status_t hermon_ci_ci_data_in(ibc_hca_hdl_t, ibt_ci_data_flags_t,
ibt_object_type_t, void *, void *, size_t);
/* CI Object Private Data */
static ibt_status_t hermon_ci_ci_data_out(ibc_hca_hdl_t, ibt_ci_data_flags_t,
ibt_object_type_t, void *, void *, size_t);
/* Shared Receive Queues */
static ibt_status_t hermon_ci_alloc_srq(ibc_hca_hdl_t, ibt_srq_flags_t,
ibt_srq_hdl_t, ibc_pd_hdl_t, ibt_srq_sizes_t *, ibc_srq_hdl_t *,
ibt_srq_sizes_t *);
static ibt_status_t hermon_ci_free_srq(ibc_hca_hdl_t, ibc_srq_hdl_t);
static ibt_status_t hermon_ci_query_srq(ibc_hca_hdl_t, ibc_srq_hdl_t,
ibc_pd_hdl_t *, ibt_srq_sizes_t *, uint_t *);
static ibt_status_t hermon_ci_modify_srq(ibc_hca_hdl_t, ibc_srq_hdl_t,
ibt_srq_modify_flags_t, uint_t, uint_t, uint_t *);
static ibt_status_t hermon_ci_post_srq(ibc_hca_hdl_t, ibc_srq_hdl_t,
ibt_recv_wr_t *, uint_t, uint_t *);
/* Address translation */
static ibt_status_t hermon_ci_map_mem_area(ibc_hca_hdl_t, ibt_va_attr_t *,
void *, uint_t, ibt_reg_req_t *, ibc_ma_hdl_t *);
static ibt_status_t hermon_ci_unmap_mem_area(ibc_hca_hdl_t, ibc_ma_hdl_t);
static ibt_status_t hermon_ci_map_mem_iov(ibc_hca_hdl_t, ibt_iov_attr_t *,
ibt_all_wr_t *, ibc_mi_hdl_t *);
static ibt_status_t hermon_ci_unmap_mem_iov(ibc_hca_hdl_t, ibc_mi_hdl_t);
/* Allocate L_Key */
static ibt_status_t hermon_ci_alloc_lkey(ibc_hca_hdl_t, ibc_pd_hdl_t,
ibt_lkey_flags_t, uint_t, ibc_mr_hdl_t *, ibt_pmr_desc_t *);
/* Physical Register Memory Region */
static ibt_status_t hermon_ci_register_physical_mr(ibc_hca_hdl_t, ibc_pd_hdl_t,
ibt_pmr_attr_t *, void *, ibc_mr_hdl_t *, ibt_pmr_desc_t *);
static ibt_status_t hermon_ci_reregister_physical_mr(ibc_hca_hdl_t,
ibc_mr_hdl_t, ibc_pd_hdl_t, ibt_pmr_attr_t *, void *, ibc_mr_hdl_t *,
ibt_pmr_desc_t *);
/* Mellanox FMR */
static ibt_status_t hermon_ci_create_fmr_pool(ibc_hca_hdl_t hca,
ibc_pd_hdl_t pd, ibt_fmr_pool_attr_t *fmr_params,
ibc_fmr_pool_hdl_t *fmr_pool);
static ibt_status_t hermon_ci_destroy_fmr_pool(ibc_hca_hdl_t hca,
ibc_fmr_pool_hdl_t fmr_pool);
static ibt_status_t hermon_ci_flush_fmr_pool(ibc_hca_hdl_t hca,
ibc_fmr_pool_hdl_t fmr_pool);
static ibt_status_t hermon_ci_register_physical_fmr(ibc_hca_hdl_t hca,
ibc_fmr_pool_hdl_t fmr_pool, ibt_pmr_attr_t *mem_pattr,
void *ibtl_reserved, ibc_mr_hdl_t *mr_hdl_p, ibt_pmr_desc_t *mem_desc_p);
static ibt_status_t hermon_ci_deregister_fmr(ibc_hca_hdl_t hca,
ibc_mr_hdl_t mr);
/* Memory Allocation/Deallocation */
static ibt_status_t hermon_ci_alloc_io_mem(ibc_hca_hdl_t hca, size_t size,
ibt_mr_flags_t mr_flag, caddr_t *kaddrp,
ibc_mem_alloc_hdl_t *mem_alloc_hdl_p);
static ibt_status_t hermon_ci_free_io_mem(ibc_hca_hdl_t hca,
ibc_mem_alloc_hdl_t mem_alloc_hdl);
static ibt_status_t hermon_ci_not_supported();
/*
* This ibc_operations_t structure includes pointers to all the entry points
* provided by the Hermon driver. This structure is passed to the IBTF at
* driver attach time, using the ibc_attach() call.
*/
ibc_operations_t hermon_ibc_ops = {
/* HCA and port related operations */
hermon_ci_query_hca_ports,
hermon_ci_modify_ports,
hermon_ci_modify_system_image,
/* Protection Domains */
hermon_ci_alloc_pd,
hermon_ci_free_pd,
/* Reliable Datagram Domains */
hermon_ci_alloc_rdd,
hermon_ci_free_rdd,
/* Address Handles */
hermon_ci_alloc_ah,
hermon_ci_free_ah,
hermon_ci_query_ah,
hermon_ci_modify_ah,
/* Queue Pairs */
hermon_ci_alloc_qp,
hermon_ci_alloc_special_qp,
hermon_ci_alloc_qp_range,
hermon_ci_free_qp,
hermon_ci_release_qpn,
hermon_ci_query_qp,
hermon_ci_modify_qp,
/* Completion Queues */
hermon_ci_alloc_cq,
hermon_ci_free_cq,
hermon_ci_query_cq,
hermon_ci_resize_cq,
hermon_ci_modify_cq,
hermon_ci_alloc_cq_sched,
hermon_ci_free_cq_sched,
hermon_ci_query_cq_handler_id,
/* EE Contexts */
hermon_ci_alloc_eec,
hermon_ci_free_eec,
hermon_ci_query_eec,
hermon_ci_modify_eec,
/* Memory Registration */
hermon_ci_register_mr,
hermon_ci_register_buf,
hermon_ci_register_shared_mr,
hermon_ci_deregister_mr,
hermon_ci_query_mr,
hermon_ci_reregister_mr,
hermon_ci_reregister_buf,
hermon_ci_sync_mr,
/* Memory Windows */
hermon_ci_alloc_mw,
hermon_ci_free_mw,
hermon_ci_query_mw,
/* Multicast Groups */
hermon_ci_attach_mcg,
hermon_ci_detach_mcg,
/* Work Request and Completion Processing */
hermon_ci_post_send,
hermon_ci_post_recv,
hermon_ci_poll_cq,
hermon_ci_notify_cq,
/* CI Object Mapping Data */
hermon_ci_ci_data_in,
hermon_ci_ci_data_out,
/* Shared Receive Queue */
hermon_ci_alloc_srq,
hermon_ci_free_srq,
hermon_ci_query_srq,
hermon_ci_modify_srq,
hermon_ci_post_srq,
/* Address translation */
hermon_ci_map_mem_area,
hermon_ci_unmap_mem_area,
hermon_ci_map_mem_iov,
hermon_ci_unmap_mem_iov,
/* Allocate L_key */
hermon_ci_alloc_lkey,
/* Physical Register Memory Region */
hermon_ci_register_physical_mr,
hermon_ci_reregister_physical_mr,
/* Mellanox FMR */
hermon_ci_create_fmr_pool,
hermon_ci_destroy_fmr_pool,
hermon_ci_flush_fmr_pool,
hermon_ci_register_physical_fmr,
hermon_ci_deregister_fmr,
/* Memory allocation */
hermon_ci_alloc_io_mem,
hermon_ci_free_io_mem,
/* XRC not yet supported */
hermon_ci_not_supported, /* ibc_alloc_xrc_domain */
hermon_ci_not_supported, /* ibc_free_xrc_domain */
hermon_ci_not_supported, /* ibc_alloc_xrc_srq */
hermon_ci_not_supported, /* ibc_free_xrc_srq */
hermon_ci_not_supported, /* ibc_query_xrc_srq */
hermon_ci_not_supported, /* ibc_modify_xrc_srq */
hermon_ci_not_supported, /* ibc_alloc_xrc_tgt_qp */
hermon_ci_not_supported, /* ibc_free_xrc_tgt_qp */
hermon_ci_not_supported, /* ibc_query_xrc_tgt_qp */
hermon_ci_not_supported, /* ibc_modify_xrc_tgt_qp */
/* Memory Region (physical) */
hermon_ci_register_dma_mr,
/* Next enhancements */
hermon_ci_not_supported, /* ibc_enhancement1 */
hermon_ci_not_supported, /* ibc_enhancement2 */
hermon_ci_not_supported, /* ibc_enhancement3 */
hermon_ci_not_supported, /* ibc_enhancement4 */
};
/*
* Not yet implemented OPS
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_not_supported()
{
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_ci_query_hca_ports()
* Returns HCA port attributes for either one or all of the HCA's ports.
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_query_hca_ports(ibc_hca_hdl_t hca, uint8_t query_port,
ibt_hca_portinfo_t *info_p)
{
hermon_state_t *state;
uint_t start, end, port;
int status, indx;
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/*
* If the specified port is zero, then we are supposed to query all
* ports. Otherwise, we query only the port number specified.
* Setup the start and end port numbers as appropriate for the loop
* below. Note: The first Hermon port is port number one (1).
*/
if (query_port == 0) {
start = 1;
end = start + (state->hs_cfg_profile->cp_num_ports - 1);
} else {
end = start = query_port;
}
/* Query the port(s) */
for (port = start, indx = 0; port <= end; port++, indx++) {
status = hermon_port_query(state, port, &info_p[indx]);
if (status != DDI_SUCCESS) {
return (status);
}
}
return (IBT_SUCCESS);
}
/*
* hermon_ci_modify_ports()
* Modify HCA port attributes
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_modify_ports(ibc_hca_hdl_t hca, uint8_t port,
ibt_port_modify_flags_t flags, uint8_t init_type)
{
hermon_state_t *state;
int status;
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/* Modify the port(s) */
status = hermon_port_modify(state, port, flags, init_type);
return (status);
}
/*
* hermon_ci_modify_system_image()
* Modify the System Image GUID
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_modify_system_image(ibc_hca_hdl_t hca, ib_guid_t sys_guid)
{
/*
* This is an unsupported interface for the Hermon driver. This
* interface is necessary to support modification of the System
* Image GUID. Hermon is only capable of modifying this parameter
* once (during driver initialization).
*/
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_ci_alloc_pd()
* Allocate a Protection Domain
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_alloc_pd(ibc_hca_hdl_t hca, ibt_pd_flags_t flags, ibc_pd_hdl_t *pd_p)
{
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
int status;
ASSERT(pd_p != NULL);
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/* Allocate the PD */
status = hermon_pd_alloc(state, &pdhdl, HERMON_NOSLEEP);
if (status != DDI_SUCCESS) {
return (status);
}
/* Return the Hermon PD handle */
*pd_p = (ibc_pd_hdl_t)pdhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_free_pd()
* Free a Protection Domain
* Context: Can be called only from user or kernel context
*/
static ibt_status_t
hermon_ci_free_pd(ibc_hca_hdl_t hca, ibc_pd_hdl_t pd)
{
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
int status;
/* Grab the Hermon softstate pointer and PD handle */
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
/* Free the PD */
status = hermon_pd_free(state, &pdhdl);
return (status);
}
/*
* hermon_ci_alloc_rdd()
* Allocate a Reliable Datagram Domain
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_alloc_rdd(ibc_hca_hdl_t hca, ibc_rdd_flags_t flags,
ibc_rdd_hdl_t *rdd_p)
{
/*
* This is an unsupported interface for the Hermon driver. This
* interface is necessary to support Reliable Datagram (RD)
* operations. Hermon does not support RD.
*/
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_free_rdd()
* Free a Reliable Datagram Domain
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_free_rdd(ibc_hca_hdl_t hca, ibc_rdd_hdl_t rdd)
{
/*
* This is an unsupported interface for the Hermon driver. This
* interface is necessary to support Reliable Datagram (RD)
* operations. Hermon does not support RD.
*/
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_ci_alloc_ah()
* Allocate an Address Handle
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_alloc_ah(ibc_hca_hdl_t hca, ibt_ah_flags_t flags, ibc_pd_hdl_t pd,
ibt_adds_vect_t *attr_p, ibc_ah_hdl_t *ah_p)
{
hermon_state_t *state;
hermon_ahhdl_t ahhdl;
hermon_pdhdl_t pdhdl;
int status;
/* Grab the Hermon softstate pointer and PD handle */
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
/* Allocate the AH */
status = hermon_ah_alloc(state, pdhdl, attr_p, &ahhdl, HERMON_NOSLEEP);
if (status != DDI_SUCCESS) {
return (status);
}
/* Return the Hermon AH handle */
*ah_p = (ibc_ah_hdl_t)ahhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_free_ah()
* Free an Address Handle
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_free_ah(ibc_hca_hdl_t hca, ibc_ah_hdl_t ah)
{
hermon_state_t *state;
hermon_ahhdl_t ahhdl;
int status;
/* Grab the Hermon softstate pointer and AH handle */
state = (hermon_state_t *)hca;
ahhdl = (hermon_ahhdl_t)ah;
/* Free the AH */
status = hermon_ah_free(state, &ahhdl, HERMON_NOSLEEP);
return (status);
}
/*
* hermon_ci_query_ah()
* Return the Address Vector information for a specified Address Handle
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_query_ah(ibc_hca_hdl_t hca, ibc_ah_hdl_t ah, ibc_pd_hdl_t *pd_p,
ibt_adds_vect_t *attr_p)
{
hermon_state_t *state;
hermon_ahhdl_t ahhdl;
hermon_pdhdl_t pdhdl;
int status;
/* Grab the Hermon softstate pointer and AH handle */
state = (hermon_state_t *)hca;
ahhdl = (hermon_ahhdl_t)ah;
/* Query the AH */
status = hermon_ah_query(state, ahhdl, &pdhdl, attr_p);
if (status != DDI_SUCCESS) {
return (status);
}
/* Return the Hermon PD handle */
*pd_p = (ibc_pd_hdl_t)pdhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_modify_ah()
* Modify the Address Vector information of a specified Address Handle
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_modify_ah(ibc_hca_hdl_t hca, ibc_ah_hdl_t ah, ibt_adds_vect_t *attr_p)
{
hermon_state_t *state;
hermon_ahhdl_t ahhdl;
int status;
/* Grab the Hermon softstate pointer and AH handle */
state = (hermon_state_t *)hca;
ahhdl = (hermon_ahhdl_t)ah;
/* Modify the AH */
status = hermon_ah_modify(state, ahhdl, attr_p);
return (status);
}
/*
* hermon_ci_alloc_qp()
* Allocate a Queue Pair
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_alloc_qp(ibc_hca_hdl_t hca, ibtl_qp_hdl_t ibt_qphdl,
ibt_qp_type_t type, ibt_qp_alloc_attr_t *attr_p,
ibt_chan_sizes_t *queue_sizes_p, ib_qpn_t *qpn, ibc_qp_hdl_t *qp_p)
{
hermon_state_t *state;
hermon_qp_info_t qpinfo;
int status;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*attr_p))
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*queue_sizes_p))
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/* Allocate the QP */
qpinfo.qpi_attrp = attr_p;
qpinfo.qpi_type = type;
qpinfo.qpi_ibt_qphdl = ibt_qphdl;
qpinfo.qpi_queueszp = queue_sizes_p;
qpinfo.qpi_qpn = qpn;
status = hermon_qp_alloc(state, &qpinfo, HERMON_NOSLEEP);
if (status != DDI_SUCCESS) {
return (status);
}
/* Return the Hermon QP handle */
*qp_p = (ibc_qp_hdl_t)qpinfo.qpi_qphdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_alloc_special_qp()
* Allocate a Special Queue Pair
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_alloc_special_qp(ibc_hca_hdl_t hca, uint8_t port,
ibtl_qp_hdl_t ibt_qphdl, ibt_sqp_type_t type,
ibt_qp_alloc_attr_t *attr_p, ibt_chan_sizes_t *queue_sizes_p,
ibc_qp_hdl_t *qp_p)
{
hermon_state_t *state;
hermon_qp_info_t qpinfo;
int status;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*attr_p))
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*queue_sizes_p))
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/* Allocate the Special QP */
qpinfo.qpi_attrp = attr_p;
qpinfo.qpi_type = type;
qpinfo.qpi_port = port;
qpinfo.qpi_ibt_qphdl = ibt_qphdl;
qpinfo.qpi_queueszp = queue_sizes_p;
status = hermon_special_qp_alloc(state, &qpinfo, HERMON_NOSLEEP);
if (status != DDI_SUCCESS) {
return (status);
}
/* Return the Hermon QP handle */
*qp_p = (ibc_qp_hdl_t)qpinfo.qpi_qphdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_alloc_qp_range()
* Free a Queue Pair
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_alloc_qp_range(ibc_hca_hdl_t hca, uint_t log2,
ibtl_qp_hdl_t *ibtl_qp, ibt_qp_type_t type,
ibt_qp_alloc_attr_t *attr_p, ibt_chan_sizes_t *queue_sizes_p,
ibc_cq_hdl_t *send_cq, ibc_cq_hdl_t *recv_cq,
ib_qpn_t *qpn, ibc_qp_hdl_t *qp_p)
{
hermon_state_t *state;
hermon_qp_info_t qpinfo;
int status;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*attr_p))
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*queue_sizes_p))
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/* Allocate the QP */
qpinfo.qpi_attrp = attr_p;
qpinfo.qpi_type = type;
qpinfo.qpi_queueszp = queue_sizes_p;
qpinfo.qpi_qpn = qpn;
status = hermon_qp_alloc_range(state, log2, &qpinfo, ibtl_qp,
send_cq, recv_cq, (hermon_qphdl_t *)qp_p, HERMON_NOSLEEP);
return (status);
}
/*
* hermon_ci_free_qp()
* Free a Queue Pair
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_free_qp(ibc_hca_hdl_t hca, ibc_qp_hdl_t qp,
ibc_free_qp_flags_t free_qp_flags, ibc_qpn_hdl_t *qpnh_p)
{
hermon_state_t *state;
hermon_qphdl_t qphdl;
int status;
/* Grab the Hermon softstate pointer and QP handle */
state = (hermon_state_t *)hca;
qphdl = (hermon_qphdl_t)qp;
/* Free the QP */
status = hermon_qp_free(state, &qphdl, free_qp_flags, qpnh_p,
HERMON_NOSLEEP);
return (status);
}
/*
* hermon_ci_release_qpn()
* Release a Queue Pair Number (QPN)
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_release_qpn(ibc_hca_hdl_t hca, ibc_qpn_hdl_t qpnh)
{
hermon_state_t *state;
hermon_qpn_entry_t *entry;
/* Grab the Hermon softstate pointer and QP handle */
state = (hermon_state_t *)hca;
entry = (hermon_qpn_entry_t *)qpnh;
/* Release the QP number */
hermon_qp_release_qpn(state, entry, HERMON_QPN_RELEASE);
return (IBT_SUCCESS);
}
/*
* hermon_ci_query_qp()
* Query a Queue Pair
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_query_qp(ibc_hca_hdl_t hca, ibc_qp_hdl_t qp,
ibt_qp_query_attr_t *attr_p)
{
hermon_state_t *state;
hermon_qphdl_t qphdl;
int status;
/* Grab the Hermon softstate pointer and QP handle */
state = (hermon_state_t *)hca;
qphdl = (hermon_qphdl_t)qp;
/* Query the QP */
status = hermon_qp_query(state, qphdl, attr_p);
return (status);
}
/*
* hermon_ci_modify_qp()
* Modify a Queue Pair
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_modify_qp(ibc_hca_hdl_t hca, ibc_qp_hdl_t qp,
ibt_cep_modify_flags_t flags, ibt_qp_info_t *info_p,
ibt_queue_sizes_t *actual_sz)
{
hermon_state_t *state;
hermon_qphdl_t qphdl;
int status;
/* Grab the Hermon softstate pointer and QP handle */
state = (hermon_state_t *)hca;
qphdl = (hermon_qphdl_t)qp;
/* Modify the QP */
status = hermon_qp_modify(state, qphdl, flags, info_p, actual_sz);
return (status);
}
/*
* hermon_ci_alloc_cq()
* Allocate a Completion Queue
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_alloc_cq(ibc_hca_hdl_t hca, ibt_cq_hdl_t ibt_cqhdl,
ibt_cq_attr_t *attr_p, ibc_cq_hdl_t *cq_p, uint_t *actual_size)
{
hermon_state_t *state;
hermon_cqhdl_t cqhdl;
int status;
state = (hermon_state_t *)hca;
/* Allocate the CQ */
status = hermon_cq_alloc(state, ibt_cqhdl, attr_p, actual_size,
&cqhdl, HERMON_NOSLEEP);
if (status != DDI_SUCCESS) {
return (status);
}
/* Return the Hermon CQ handle */
*cq_p = (ibc_cq_hdl_t)cqhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_free_cq()
* Free a Completion Queue
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_free_cq(ibc_hca_hdl_t hca, ibc_cq_hdl_t cq)
{
hermon_state_t *state;
hermon_cqhdl_t cqhdl;
int status;
/* Grab the Hermon softstate pointer and CQ handle */
state = (hermon_state_t *)hca;
cqhdl = (hermon_cqhdl_t)cq;
/* Free the CQ */
status = hermon_cq_free(state, &cqhdl, HERMON_NOSLEEP);
return (status);
}
/*
* hermon_ci_query_cq()
* Return the size of a Completion Queue
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_query_cq(ibc_hca_hdl_t hca, ibc_cq_hdl_t cq, uint_t *entries_p,
uint_t *count_p, uint_t *usec_p, ibt_cq_handler_id_t *hid_p)
{
hermon_state_t *state;
hermon_cqhdl_t cqhdl;
/* Grab the CQ handle */
state = (hermon_state_t *)hca;
cqhdl = (hermon_cqhdl_t)cq;
/* Query the current CQ size */
*entries_p = cqhdl->cq_bufsz;
*count_p = cqhdl->cq_intmod_count;
*usec_p = cqhdl->cq_intmod_usec;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*cqhdl))
*hid_p = HERMON_EQNUM_TO_HID(state, cqhdl->cq_eqnum);
return (IBT_SUCCESS);
}
/*
* hermon_ci_resize_cq()
* Change the size of a Completion Queue
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_resize_cq(ibc_hca_hdl_t hca, ibc_cq_hdl_t cq, uint_t size,
uint_t *actual_size)
{
hermon_state_t *state;
hermon_cqhdl_t cqhdl;
int status;
/* Grab the Hermon softstate pointer and CQ handle */
state = (hermon_state_t *)hca;
cqhdl = (hermon_cqhdl_t)cq;
/* Resize the CQ */
status = hermon_cq_resize(state, cqhdl, size, actual_size,
HERMON_NOSLEEP);
if (status != DDI_SUCCESS) {
return (status);
}
return (IBT_SUCCESS);
}
/*
* hermon_ci_modify_cq()
* Change the interrupt moderation values of a Completion Queue
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_modify_cq(ibc_hca_hdl_t hca, ibc_cq_hdl_t cq, uint_t count,
uint_t usec, ibt_cq_handler_id_t hid)
{
hermon_state_t *state;
hermon_cqhdl_t cqhdl;
int status;
/* Grab the Hermon softstate pointer and CQ handle */
state = (hermon_state_t *)hca;
cqhdl = (hermon_cqhdl_t)cq;
/* Resize the CQ */
status = hermon_cq_modify(state, cqhdl, count, usec, hid,
HERMON_NOSLEEP);
return (status);
}
/*
* hermon_ci_alloc_cq_sched()
* Reserve a CQ scheduling class resource
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_alloc_cq_sched(ibc_hca_hdl_t hca, ibt_cq_sched_attr_t *attr,
ibc_sched_hdl_t *sched_hdl_p)
{
int status;
status = hermon_cq_sched_alloc((hermon_state_t *)hca, attr,
(hermon_cq_sched_t **)sched_hdl_p);
return (status);
}
/*
* hermon_ci_free_cq_sched()
* Free a CQ scheduling class resource
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_free_cq_sched(ibc_hca_hdl_t hca, ibc_sched_hdl_t sched_hdl)
{
int status;
status = hermon_cq_sched_free((hermon_state_t *)hca,
(hermon_cq_sched_t *)sched_hdl);
return (status);
}
static ibt_status_t
hermon_ci_query_cq_handler_id(ibc_hca_hdl_t hca,
ibt_cq_handler_id_t hid, ibt_cq_handler_attr_t *attrs)
{
hermon_state_t *state;
state = (hermon_state_t *)hca;
if (!HERMON_HID_VALID(state, hid))
return (IBT_CQ_HID_INVALID);
if (attrs == NULL)
return (IBT_INVALID_PARAM);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*attrs))
attrs->cha_ih = state->hs_intrmsi_hdl[hid - 1];
attrs->cha_dip = state->hs_dip;
return (IBT_SUCCESS);
}
/*
* hermon_ci_alloc_eec()
* Allocate an End-to-End context
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_alloc_eec(ibc_hca_hdl_t hca, ibc_eec_flags_t flags,
ibt_eec_hdl_t ibt_eec, ibc_rdd_hdl_t rdd, ibc_eec_hdl_t *eec_p)
{
/*
* This is an unsupported interface for the Hermon driver. This
* interface is necessary to support Reliable Datagram (RD)
* operations. Hermon does not support RD.
*/
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_ci_free_eec()
* Free an End-to-End context
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_free_eec(ibc_hca_hdl_t hca, ibc_eec_hdl_t eec)
{
/*
* This is an unsupported interface for the Hermon driver. This
* interface is necessary to support Reliable Datagram (RD)
* operations. Hermon does not support RD.
*/
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_ci_query_eec()
* Query an End-to-End context
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_query_eec(ibc_hca_hdl_t hca, ibc_eec_hdl_t eec,
ibt_eec_query_attr_t *attr_p)
{
/*
* This is an unsupported interface for the Hermon driver. This
* interface is necessary to support Reliable Datagram (RD)
* operations. Hermon does not support RD.
*/
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_ci_modify_eec()
* Modify an End-to-End context
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_modify_eec(ibc_hca_hdl_t hca, ibc_eec_hdl_t eec,
ibt_cep_modify_flags_t flags, ibt_eec_info_t *info_p)
{
/*
* This is an unsupported interface for the Hermon driver. This
* interface is necessary to support Reliable Datagram (RD)
* operations. Hermon does not support RD.
*/
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_ci_register_mr()
* Prepare a virtually addressed Memory Region for use by an HCA
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_register_mr(ibc_hca_hdl_t hca, ibc_pd_hdl_t pd,
ibt_mr_attr_t *mr_attr, void *ibtl_reserved, ibc_mr_hdl_t *mr_p,
ibt_mr_desc_t *mr_desc)
{
hermon_mr_options_t op;
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_mrhdl_t mrhdl;
int status;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mr_desc))
ASSERT(mr_attr != NULL);
ASSERT(mr_p != NULL);
ASSERT(mr_desc != NULL);
/*
* Validate the access flags. Both Remote Write and Remote Atomic
* require the Local Write flag to be set
*/
if (((mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_ATOMIC)) &&
!(mr_attr->mr_flags & IBT_MR_ENABLE_LOCAL_WRITE)) {
return (IBT_MR_ACCESS_REQ_INVALID);
}
/* Grab the Hermon softstate pointer and PD handle */
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
/* Register the memory region */
op.mro_bind_type = state->hs_cfg_profile->cp_iommu_bypass;
op.mro_bind_dmahdl = NULL;
op.mro_bind_override_addr = 0;
status = hermon_mr_register(state, pdhdl, mr_attr, &mrhdl,
&op, HERMON_MPT_DMPT);
if (status != DDI_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mrhdl))
/* Fill in the mr_desc structure */
mr_desc->md_vaddr = mrhdl->mr_bindinfo.bi_addr;
mr_desc->md_lkey = mrhdl->mr_lkey;
/* Only set RKey if remote access was requested */
if ((mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_ATOMIC) ||
(mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_READ)) {
mr_desc->md_rkey = mrhdl->mr_rkey;
}
/*
* If region is mapped for streaming (i.e. noncoherent), then set
* sync is required
*/
mr_desc->md_sync_required = (mrhdl->mr_bindinfo.bi_flags &
IBT_MR_NONCOHERENT) ? B_TRUE : B_FALSE;
/* Return the Hermon MR handle */
*mr_p = (ibc_mr_hdl_t)mrhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_register_buf()
* Prepare a Memory Region specified by buf structure for use by an HCA
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_register_buf(ibc_hca_hdl_t hca, ibc_pd_hdl_t pd,
ibt_smr_attr_t *attrp, struct buf *buf, void *ibtl_reserved,
ibt_mr_hdl_t *mr_p, ibt_mr_desc_t *mr_desc)
{
hermon_mr_options_t op;
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_mrhdl_t mrhdl;
int status;
ibt_mr_flags_t flags = attrp->mr_flags;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mr_desc))
ASSERT(mr_p != NULL);
ASSERT(mr_desc != NULL);
/*
* Validate the access flags. Both Remote Write and Remote Atomic
* require the Local Write flag to be set
*/
if (((flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(flags & IBT_MR_ENABLE_REMOTE_ATOMIC)) &&
!(flags & IBT_MR_ENABLE_LOCAL_WRITE)) {
return (IBT_MR_ACCESS_REQ_INVALID);
}
/* Grab the Hermon softstate pointer and PD handle */
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
/* Register the memory region */
op.mro_bind_type = state->hs_cfg_profile->cp_iommu_bypass;
op.mro_bind_dmahdl = NULL;
op.mro_bind_override_addr = 0;
status = hermon_mr_register_buf(state, pdhdl, attrp, buf,
&mrhdl, &op, HERMON_MPT_DMPT);
if (status != DDI_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mrhdl))
/* Fill in the mr_desc structure */
mr_desc->md_vaddr = mrhdl->mr_bindinfo.bi_addr;
mr_desc->md_lkey = mrhdl->mr_lkey;
/* Only set RKey if remote access was requested */
if ((flags & IBT_MR_ENABLE_REMOTE_ATOMIC) ||
(flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(flags & IBT_MR_ENABLE_REMOTE_READ)) {
mr_desc->md_rkey = mrhdl->mr_rkey;
}
/*
* If region is mapped for streaming (i.e. noncoherent), then set
* sync is required
*/
mr_desc->md_sync_required = (mrhdl->mr_bindinfo.bi_flags &
IBT_MR_NONCOHERENT) ? B_TRUE : B_FALSE;
/* Return the Hermon MR handle */
*mr_p = (ibc_mr_hdl_t)mrhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_deregister_mr()
* Deregister a Memory Region from an HCA translation table
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_deregister_mr(ibc_hca_hdl_t hca, ibc_mr_hdl_t mr)
{
hermon_state_t *state;
hermon_mrhdl_t mrhdl;
int status;
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
mrhdl = (hermon_mrhdl_t)mr;
/*
* Deregister the memory region.
*/
status = hermon_mr_deregister(state, &mrhdl, HERMON_MR_DEREG_ALL,
HERMON_NOSLEEP);
return (status);
}
/*
* hermon_ci_query_mr()
* Retrieve information about a specified Memory Region
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_query_mr(ibc_hca_hdl_t hca, ibc_mr_hdl_t mr,
ibt_mr_query_attr_t *mr_attr)
{
hermon_state_t *state;
hermon_mrhdl_t mrhdl;
int status;
ASSERT(mr_attr != NULL);
/* Grab the Hermon softstate pointer and MR handle */
state = (hermon_state_t *)hca;
mrhdl = (hermon_mrhdl_t)mr;
/* Query the memory region */
status = hermon_mr_query(state, mrhdl, mr_attr);
return (status);
}
/*
* hermon_ci_register_shared_mr()
* Create a shared memory region matching an existing Memory Region
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_register_shared_mr(ibc_hca_hdl_t hca, ibc_mr_hdl_t mr,
ibc_pd_hdl_t pd, ibt_smr_attr_t *mr_attr, void *ibtl_reserved,
ibc_mr_hdl_t *mr_p, ibt_mr_desc_t *mr_desc)
{
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_mrhdl_t mrhdl, mrhdl_new;
int status;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mr_desc))
ASSERT(mr_attr != NULL);
ASSERT(mr_p != NULL);
ASSERT(mr_desc != NULL);
/*
* Validate the access flags. Both Remote Write and Remote Atomic
* require the Local Write flag to be set
*/
if (((mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_ATOMIC)) &&
!(mr_attr->mr_flags & IBT_MR_ENABLE_LOCAL_WRITE)) {
return (IBT_MR_ACCESS_REQ_INVALID);
}
/* Grab the Hermon softstate pointer and handles */
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
mrhdl = (hermon_mrhdl_t)mr;
/* Register the shared memory region */
status = hermon_mr_register_shared(state, mrhdl, pdhdl, mr_attr,
&mrhdl_new);
if (status != DDI_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mrhdl_new))
/* Fill in the mr_desc structure */
mr_desc->md_vaddr = mrhdl_new->mr_bindinfo.bi_addr;
mr_desc->md_lkey = mrhdl_new->mr_lkey;
/* Only set RKey if remote access was requested */
if ((mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_ATOMIC) ||
(mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_READ)) {
mr_desc->md_rkey = mrhdl_new->mr_rkey;
}
/*
* If shared region is mapped for streaming (i.e. noncoherent), then
* set sync is required
*/
mr_desc->md_sync_required = (mrhdl_new->mr_bindinfo.bi_flags &
IBT_MR_NONCOHERENT) ? B_TRUE : B_FALSE;
/* Return the Hermon MR handle */
*mr_p = (ibc_mr_hdl_t)mrhdl_new;
return (IBT_SUCCESS);
}
/*
* hermon_ci_reregister_mr()
* Modify the attributes of an existing Memory Region
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_reregister_mr(ibc_hca_hdl_t hca, ibc_mr_hdl_t mr, ibc_pd_hdl_t pd,
ibt_mr_attr_t *mr_attr, void *ibtl_reserved, ibc_mr_hdl_t *mr_new,
ibt_mr_desc_t *mr_desc)
{
hermon_mr_options_t op;
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_mrhdl_t mrhdl, mrhdl_new;
int status;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mr_desc))
ASSERT(mr_attr != NULL);
ASSERT(mr_new != NULL);
ASSERT(mr_desc != NULL);
/* Grab the Hermon softstate pointer, mrhdl, and pdhdl */
state = (hermon_state_t *)hca;
mrhdl = (hermon_mrhdl_t)mr;
pdhdl = (hermon_pdhdl_t)pd;
/* Reregister the memory region */
op.mro_bind_type = state->hs_cfg_profile->cp_iommu_bypass;
status = hermon_mr_reregister(state, mrhdl, pdhdl, mr_attr,
&mrhdl_new, &op);
if (status != DDI_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mrhdl_new))
/* Fill in the mr_desc structure */
mr_desc->md_vaddr = mrhdl_new->mr_bindinfo.bi_addr;
mr_desc->md_lkey = mrhdl_new->mr_lkey;
/* Only set RKey if remote access was requested */
if ((mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_ATOMIC) ||
(mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(mr_attr->mr_flags & IBT_MR_ENABLE_REMOTE_READ)) {
mr_desc->md_rkey = mrhdl_new->mr_rkey;
}
/*
* If region is mapped for streaming (i.e. noncoherent), then set
* sync is required
*/
mr_desc->md_sync_required = (mrhdl_new->mr_bindinfo.bi_flags &
IBT_MR_NONCOHERENT) ? B_TRUE : B_FALSE;
/* Return the Hermon MR handle */
*mr_new = (ibc_mr_hdl_t)mrhdl_new;
return (IBT_SUCCESS);
}
/*
* hermon_ci_reregister_buf()
* Modify the attributes of an existing Memory Region
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_reregister_buf(ibc_hca_hdl_t hca, ibc_mr_hdl_t mr, ibc_pd_hdl_t pd,
ibt_smr_attr_t *attrp, struct buf *buf, void *ibtl_reserved,
ibc_mr_hdl_t *mr_new, ibt_mr_desc_t *mr_desc)
{
hermon_mr_options_t op;
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_mrhdl_t mrhdl, mrhdl_new;
int status;
ibt_mr_flags_t flags = attrp->mr_flags;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mr_desc))
ASSERT(mr_new != NULL);
ASSERT(mr_desc != NULL);
/* Grab the Hermon softstate pointer, mrhdl, and pdhdl */
state = (hermon_state_t *)hca;
mrhdl = (hermon_mrhdl_t)mr;
pdhdl = (hermon_pdhdl_t)pd;
/* Reregister the memory region */
op.mro_bind_type = state->hs_cfg_profile->cp_iommu_bypass;
status = hermon_mr_reregister_buf(state, mrhdl, pdhdl, attrp, buf,
&mrhdl_new, &op);
if (status != DDI_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mrhdl_new))
/* Fill in the mr_desc structure */
mr_desc->md_vaddr = mrhdl_new->mr_bindinfo.bi_addr;
mr_desc->md_lkey = mrhdl_new->mr_lkey;
/* Only set RKey if remote access was requested */
if ((flags & IBT_MR_ENABLE_REMOTE_ATOMIC) ||
(flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(flags & IBT_MR_ENABLE_REMOTE_READ)) {
mr_desc->md_rkey = mrhdl_new->mr_rkey;
}
/*
* If region is mapped for streaming (i.e. noncoherent), then set
* sync is required
*/
mr_desc->md_sync_required = (mrhdl_new->mr_bindinfo.bi_flags &
IBT_MR_NONCOHERENT) ? B_TRUE : B_FALSE;
/* Return the Hermon MR handle */
*mr_new = (ibc_mr_hdl_t)mrhdl_new;
return (IBT_SUCCESS);
}
/*
* hermon_ci_sync_mr()
* Synchronize access to a Memory Region
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_sync_mr(ibc_hca_hdl_t hca, ibt_mr_sync_t *mr_segs, size_t num_segs)
{
hermon_state_t *state;
int status;
ASSERT(mr_segs != NULL);
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/* Sync the memory region */
status = hermon_mr_sync(state, mr_segs, num_segs);
return (status);
}
/*
* hermon_ci_alloc_mw()
* Allocate a Memory Window
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_alloc_mw(ibc_hca_hdl_t hca, ibc_pd_hdl_t pd, ibt_mw_flags_t flags,
ibc_mw_hdl_t *mw_p, ibt_rkey_t *rkey_p)
{
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_mwhdl_t mwhdl;
int status;
ASSERT(mw_p != NULL);
ASSERT(rkey_p != NULL);
/* Grab the Hermon softstate pointer and PD handle */
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
/* Allocate the memory window */
status = hermon_mw_alloc(state, pdhdl, flags, &mwhdl);
if (status != DDI_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mwhdl))
/* Return the MW handle and RKey */
*mw_p = (ibc_mw_hdl_t)mwhdl;
*rkey_p = mwhdl->mr_rkey;
return (IBT_SUCCESS);
}
/*
* hermon_ci_free_mw()
* Free a Memory Window
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_free_mw(ibc_hca_hdl_t hca, ibc_mw_hdl_t mw)
{
hermon_state_t *state;
hermon_mwhdl_t mwhdl;
int status;
/* Grab the Hermon softstate pointer and MW handle */
state = (hermon_state_t *)hca;
mwhdl = (hermon_mwhdl_t)mw;
/* Free the memory window */
status = hermon_mw_free(state, &mwhdl, HERMON_NOSLEEP);
return (status);
}
/*
* hermon_ci_query_mw()
* Return the attributes of the specified Memory Window
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_query_mw(ibc_hca_hdl_t hca, ibc_mw_hdl_t mw,
ibt_mw_query_attr_t *mw_attr_p)
{
hermon_mwhdl_t mwhdl;
ASSERT(mw_attr_p != NULL);
/* Query the memory window pointer and fill in the return values */
mwhdl = (hermon_mwhdl_t)mw;
mutex_enter(&mwhdl->mr_lock);
mw_attr_p->mw_pd = (ibc_pd_hdl_t)mwhdl->mr_pdhdl;
mw_attr_p->mw_rkey = mwhdl->mr_rkey;
mutex_exit(&mwhdl->mr_lock);
return (IBT_SUCCESS);
}
/*
* hermon_ci_register_dma_mr()
* Allocate a memory region that maps physical addresses.
* Context: Can be called only from user or kernel context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_register_dma_mr(ibc_hca_hdl_t hca, ibc_pd_hdl_t pd,
ibt_dmr_attr_t *mr_attr, void *ibtl_reserved, ibc_mr_hdl_t *mr_p,
ibt_mr_desc_t *mr_desc)
{
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_mrhdl_t mrhdl;
int status;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mr_desc))
ASSERT(mr_attr != NULL);
ASSERT(mr_p != NULL);
ASSERT(mr_desc != NULL);
/*
* Validate the access flags. Both Remote Write and Remote Atomic
* require the Local Write flag to be set
*/
if (((mr_attr->dmr_flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(mr_attr->dmr_flags & IBT_MR_ENABLE_REMOTE_ATOMIC)) &&
!(mr_attr->dmr_flags & IBT_MR_ENABLE_LOCAL_WRITE)) {
return (IBT_MR_ACCESS_REQ_INVALID);
}
/* Grab the Hermon softstate pointer and PD handle */
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
status = hermon_dma_mr_register(state, pdhdl, mr_attr, &mrhdl);
if (status != DDI_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mrhdl))
/* Fill in the mr_desc structure */
mr_desc->md_vaddr = mr_attr->dmr_paddr;
mr_desc->md_lkey = mrhdl->mr_lkey;
/* Only set RKey if remote access was requested */
if ((mr_attr->dmr_flags & IBT_MR_ENABLE_REMOTE_ATOMIC) ||
(mr_attr->dmr_flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(mr_attr->dmr_flags & IBT_MR_ENABLE_REMOTE_READ)) {
mr_desc->md_rkey = mrhdl->mr_rkey;
}
/*
* If region is mapped for streaming (i.e. noncoherent), then set
* sync is required
*/
mr_desc->md_sync_required = B_FALSE;
/* Return the Hermon MR handle */
*mr_p = (ibc_mr_hdl_t)mrhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_attach_mcg()
* Attach a Queue Pair to a Multicast Group
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_attach_mcg(ibc_hca_hdl_t hca, ibc_qp_hdl_t qp, ib_gid_t gid,
ib_lid_t lid)
{
hermon_state_t *state;
hermon_qphdl_t qphdl;
int status;
/* Grab the Hermon softstate pointer and QP handles */
state = (hermon_state_t *)hca;
qphdl = (hermon_qphdl_t)qp;
/* Attach the QP to the multicast group */
status = hermon_mcg_attach(state, qphdl, gid, lid);
return (status);
}
/*
* hermon_ci_detach_mcg()
* Detach a Queue Pair to a Multicast Group
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_detach_mcg(ibc_hca_hdl_t hca, ibc_qp_hdl_t qp, ib_gid_t gid,
ib_lid_t lid)
{
hermon_state_t *state;
hermon_qphdl_t qphdl;
int status;
/* Grab the Hermon softstate pointer and QP handle */
state = (hermon_state_t *)hca;
qphdl = (hermon_qphdl_t)qp;
/* Detach the QP from the multicast group */
status = hermon_mcg_detach(state, qphdl, gid, lid);
return (status);
}
/*
* hermon_ci_post_send()
* Post send work requests to the send queue on the specified QP
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_post_send(ibc_hca_hdl_t hca, ibc_qp_hdl_t qp, ibt_send_wr_t *wr_p,
uint_t num_wr, uint_t *num_posted_p)
{
hermon_state_t *state;
hermon_qphdl_t qphdl;
int status;
ASSERT(wr_p != NULL);
ASSERT(num_wr != 0);
/* Grab the Hermon softstate pointer and QP handle */
state = (hermon_state_t *)hca;
qphdl = (hermon_qphdl_t)qp;
/* Post the send WQEs */
status = hermon_post_send(state, qphdl, wr_p, num_wr, num_posted_p);
return (status);
}
/*
* hermon_ci_post_recv()
* Post receive work requests to the receive queue on the specified QP
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_post_recv(ibc_hca_hdl_t hca, ibc_qp_hdl_t qp, ibt_recv_wr_t *wr_p,
uint_t num_wr, uint_t *num_posted_p)
{
hermon_state_t *state;
hermon_qphdl_t qphdl;
int status;
ASSERT(wr_p != NULL);
ASSERT(num_wr != 0);
state = (hermon_state_t *)hca;
qphdl = (hermon_qphdl_t)qp;
/* Post the receive WQEs */
status = hermon_post_recv(state, qphdl, wr_p, num_wr, num_posted_p);
return (status);
}
/*
* hermon_ci_poll_cq()
* Poll for a work request completion
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_poll_cq(ibc_hca_hdl_t hca, ibc_cq_hdl_t cq, ibt_wc_t *wc_p,
uint_t num_wc, uint_t *num_polled)
{
hermon_state_t *state;
hermon_cqhdl_t cqhdl;
int status;
ASSERT(wc_p != NULL);
/* Check for valid num_wc field */
if (num_wc == 0) {
return (IBT_INVALID_PARAM);
}
/* Grab the Hermon softstate pointer and CQ handle */
state = (hermon_state_t *)hca;
cqhdl = (hermon_cqhdl_t)cq;
/* Poll for work request completions */
status = hermon_cq_poll(state, cqhdl, wc_p, num_wc, num_polled);
return (status);
}
/*
* hermon_ci_notify_cq()
* Enable notification events on the specified CQ
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_notify_cq(ibc_hca_hdl_t hca, ibc_cq_hdl_t cq_hdl,
ibt_cq_notify_flags_t flags)
{
hermon_state_t *state;
hermon_cqhdl_t cqhdl;
int status;
/* Grab the Hermon softstate pointer and CQ handle */
state = (hermon_state_t *)hca;
cqhdl = (hermon_cqhdl_t)cq_hdl;
/* Enable the CQ notification */
status = hermon_cq_notify(state, cqhdl, flags);
return (status);
}
/*
* hermon_ci_ci_data_in()
* Exchange CI-specific data.
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_ci_data_in(ibc_hca_hdl_t hca, ibt_ci_data_flags_t flags,
ibt_object_type_t object, void *ibc_object_handle, void *data_p,
size_t data_sz)
{
hermon_state_t *state;
int status;
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/* Get the Hermon userland mapping information */
status = hermon_umap_ci_data_in(state, flags, object,
ibc_object_handle, data_p, data_sz);
return (status);
}
/*
* hermon_ci_ci_data_out()
* Exchange CI-specific data.
* Context: Can be called only from user or kernel context.
*/
static ibt_status_t
hermon_ci_ci_data_out(ibc_hca_hdl_t hca, ibt_ci_data_flags_t flags,
ibt_object_type_t object, void *ibc_object_handle, void *data_p,
size_t data_sz)
{
hermon_state_t *state;
int status;
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
/* Get the Hermon userland mapping information */
status = hermon_umap_ci_data_out(state, flags, object,
ibc_object_handle, data_p, data_sz);
return (status);
}
/*
* hermon_ci_alloc_srq()
* Allocate a Shared Receive Queue (SRQ)
* Context: Can be called only from user or kernel context
*/
static ibt_status_t
hermon_ci_alloc_srq(ibc_hca_hdl_t hca, ibt_srq_flags_t flags,
ibt_srq_hdl_t ibt_srq, ibc_pd_hdl_t pd, ibt_srq_sizes_t *sizes,
ibc_srq_hdl_t *ibc_srq_p, ibt_srq_sizes_t *ret_sizes_p)
{
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_srqhdl_t srqhdl;
hermon_srq_info_t srqinfo;
int status;
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
srqinfo.srqi_ibt_srqhdl = ibt_srq;
srqinfo.srqi_pd = pdhdl;
srqinfo.srqi_sizes = sizes;
srqinfo.srqi_real_sizes = ret_sizes_p;
srqinfo.srqi_srqhdl = &srqhdl;
srqinfo.srqi_flags = flags;
status = hermon_srq_alloc(state, &srqinfo, HERMON_NOSLEEP);
if (status != DDI_SUCCESS) {
return (status);
}
*ibc_srq_p = (ibc_srq_hdl_t)srqhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_free_srq()
* Free a Shared Receive Queue (SRQ)
* Context: Can be called only from user or kernel context
*/
static ibt_status_t
hermon_ci_free_srq(ibc_hca_hdl_t hca, ibc_srq_hdl_t srq)
{
hermon_state_t *state;
hermon_srqhdl_t srqhdl;
int status;
state = (hermon_state_t *)hca;
/* Check for valid SRQ handle pointer */
if (srq == NULL) {
return (IBT_SRQ_HDL_INVALID);
}
srqhdl = (hermon_srqhdl_t)srq;
/* Free the SRQ */
status = hermon_srq_free(state, &srqhdl, HERMON_NOSLEEP);
return (status);
}
/*
* hermon_ci_query_srq()
* Query properties of a Shared Receive Queue (SRQ)
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_query_srq(ibc_hca_hdl_t hca, ibc_srq_hdl_t srq, ibc_pd_hdl_t *pd_p,
ibt_srq_sizes_t *sizes_p, uint_t *limit_p)
{
hermon_srqhdl_t srqhdl;
srqhdl = (hermon_srqhdl_t)srq;
mutex_enter(&srqhdl->srq_lock);
if (srqhdl->srq_state == HERMON_SRQ_STATE_ERROR) {
mutex_exit(&srqhdl->srq_lock);
return (IBT_SRQ_ERROR_STATE);
}
*pd_p = (ibc_pd_hdl_t)srqhdl->srq_pdhdl;
sizes_p->srq_wr_sz = srqhdl->srq_real_sizes.srq_wr_sz - 1;
sizes_p->srq_sgl_sz = srqhdl->srq_real_sizes.srq_sgl_sz;
mutex_exit(&srqhdl->srq_lock);
*limit_p = 0;
return (IBT_SUCCESS);
}
/*
* hermon_ci_modify_srq()
* Modify properties of a Shared Receive Queue (SRQ)
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_modify_srq(ibc_hca_hdl_t hca, ibc_srq_hdl_t srq,
ibt_srq_modify_flags_t flags, uint_t size, uint_t limit, uint_t *ret_size_p)
{
hermon_state_t *state;
hermon_srqhdl_t srqhdl;
uint_t resize_supported, cur_srq_size;
int status;
state = (hermon_state_t *)hca;
srqhdl = (hermon_srqhdl_t)srq;
/*
* Check Error State of SRQ.
* Also, while we are holding the lock we save away the current SRQ
* size for later use.
*/
mutex_enter(&srqhdl->srq_lock);
cur_srq_size = srqhdl->srq_wq_bufsz;
if (srqhdl->srq_state == HERMON_SRQ_STATE_ERROR) {
mutex_exit(&srqhdl->srq_lock);
return (IBT_SRQ_ERROR_STATE);
}
mutex_exit(&srqhdl->srq_lock);
/*
* Setting the limit watermark is not currently supported. This is a
* hermon hardware (firmware) limitation. We return NOT_SUPPORTED here,
* and have the limit code commented out for now.
*
* XXX If we enable the limit watermark support, we need to do checks
* and set the 'srq->srq_wr_limit' here, instead of returning not
* supported. The 'hermon_srq_modify' operation below is for resizing
* the SRQ only, the limit work should be done here. If this is
* changed to use the 'limit' field, the 'ARGSUSED' comment for this
* function should also be removed at that time.
*/
if (flags & IBT_SRQ_SET_LIMIT) {
return (IBT_NOT_SUPPORTED);
}
/*
* Check the SET_SIZE flag. If not set, we simply return success here.
* However if it is set, we check if resize is supported and only then
* do we continue on with our resize processing.
*/
if (!(flags & IBT_SRQ_SET_SIZE)) {
return (IBT_SUCCESS);
}
resize_supported = state->hs_ibtfinfo.hca_attr->hca_flags &
IBT_HCA_RESIZE_SRQ;
if ((flags & IBT_SRQ_SET_SIZE) && !resize_supported) {
return (IBT_NOT_SUPPORTED);
}
/*
* We do not support resizing an SRQ to be smaller than it's current
* size. If a smaller (or equal) size is requested, then we simply
* return success, and do nothing.
*/
if (size <= cur_srq_size) {
*ret_size_p = cur_srq_size;
return (IBT_SUCCESS);
}
status = hermon_srq_modify(state, srqhdl, size, ret_size_p,
HERMON_NOSLEEP);
if (status != DDI_SUCCESS) {
/* Set return value to current SRQ size */
*ret_size_p = cur_srq_size;
return (status);
}
return (IBT_SUCCESS);
}
/*
* hermon_ci_post_srq()
* Post a Work Request to the specified Shared Receive Queue (SRQ)
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_post_srq(ibc_hca_hdl_t hca, ibc_srq_hdl_t srq,
ibt_recv_wr_t *wr, uint_t num_wr, uint_t *num_posted_p)
{
hermon_state_t *state;
hermon_srqhdl_t srqhdl;
int status;
state = (hermon_state_t *)hca;
srqhdl = (hermon_srqhdl_t)srq;
status = hermon_post_srq(state, srqhdl, wr, num_wr, num_posted_p);
return (status);
}
/* Address translation */
struct ibc_ma_s {
int h_ma_addr_list_len;
void *h_ma_addr_list;
ddi_dma_handle_t h_ma_dmahdl;
ddi_dma_handle_t h_ma_list_hdl;
ddi_acc_handle_t h_ma_list_acc_hdl;
size_t h_ma_real_len;
caddr_t h_ma_kaddr;
ibt_phys_addr_t h_ma_list_cookie;
};
static ibt_status_t
hermon_map_mem_area_fmr(ibc_hca_hdl_t hca, ibt_va_attr_t *va_attrs,
uint_t list_len, ibt_pmr_attr_t *pmr, ibc_ma_hdl_t *ma_hdl_p)
{
int status;
ibt_status_t ibt_status;
ibc_ma_hdl_t ma_hdl;
ib_memlen_t len;
ddi_dma_attr_t dma_attr;
uint_t cookie_cnt;
ddi_dma_cookie_t dmacookie;
hermon_state_t *state;
uint64_t *kaddr;
uint64_t addr, endaddr, pagesize;
int i, kmflag;
int (*callback)(caddr_t);
if ((va_attrs->va_flags & IBT_VA_BUF) == 0) {
return (IBT_NOT_SUPPORTED); /* XXX - not yet implemented */
}
state = (hermon_state_t *)hca;
hermon_dma_attr_init(state, &dma_attr);
if (va_attrs->va_flags & IBT_VA_NOSLEEP) {
kmflag = KM_NOSLEEP;
callback = DDI_DMA_DONTWAIT;
} else {
kmflag = KM_SLEEP;
callback = DDI_DMA_SLEEP;
}
ma_hdl = kmem_zalloc(sizeof (*ma_hdl), kmflag);
if (ma_hdl == NULL) {
return (IBT_INSUFF_RESOURCE);
}
#ifdef __sparc
if (state->hs_cfg_profile->cp_iommu_bypass == HERMON_BINDMEM_BYPASS)
dma_attr.dma_attr_flags = DDI_DMA_FORCE_PHYSICAL;
if (hermon_kernel_data_ro == HERMON_RO_ENABLED)
dma_attr.dma_attr_flags |= DDI_DMA_RELAXED_ORDERING;
#endif
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*ma_hdl))
status = ddi_dma_alloc_handle(state->hs_dip, &dma_attr,
callback, NULL, &ma_hdl->h_ma_dmahdl);
if (status != DDI_SUCCESS) {
kmem_free(ma_hdl, sizeof (*ma_hdl));
return (IBT_INSUFF_RESOURCE);
}
status = ddi_dma_buf_bind_handle(ma_hdl->h_ma_dmahdl,
va_attrs->va_buf, DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
callback, NULL, &dmacookie, &cookie_cnt);
if (status != DDI_DMA_MAPPED) {
status = ibc_get_ci_failure(0);
goto marea_fail3;
}
ma_hdl->h_ma_real_len = list_len * sizeof (ibt_phys_addr_t);
ma_hdl->h_ma_kaddr = kmem_zalloc(ma_hdl->h_ma_real_len, kmflag);
if (ma_hdl->h_ma_kaddr == NULL) {
ibt_status = IBT_INSUFF_RESOURCE;
goto marea_fail4;
}
i = 0;
len = 0;
pagesize = PAGESIZE;
kaddr = (uint64_t *)(void *)ma_hdl->h_ma_kaddr;
while (cookie_cnt-- > 0) {
addr = dmacookie.dmac_laddress;
len += dmacookie.dmac_size;
endaddr = addr + (dmacookie.dmac_size - 1);
addr = addr & ~(pagesize - 1);
while (addr <= endaddr) {
if (i >= list_len) {
status = IBT_PBL_TOO_SMALL;
goto marea_fail5;
}
kaddr[i] = htonll(addr | HERMON_MTT_ENTRY_PRESENT);
i++;
addr += pagesize;
if (addr == 0) {
static int do_once = 1;
_NOTE(SCHEME_PROTECTS_DATA("safe sharing",
do_once))
if (do_once) {
do_once = 0;
cmn_err(CE_NOTE, "probable error in "
"dma_cookie address: map_mem_area");
}
break;
}
}
if (cookie_cnt != 0)
ddi_dma_nextcookie(ma_hdl->h_ma_dmahdl, &dmacookie);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*pmr))
pmr->pmr_addr_list = (ibt_phys_addr_t *)(void *)ma_hdl->h_ma_kaddr;
pmr->pmr_iova = va_attrs->va_vaddr;
pmr->pmr_len = len;
pmr->pmr_offset = va_attrs->va_vaddr & PAGEOFFSET;
pmr->pmr_buf_sz = PAGESHIFT; /* PRM says "Page Sice", but... */
pmr->pmr_num_buf = i;
pmr->pmr_ma = ma_hdl;
*ma_hdl_p = ma_hdl;
return (IBT_SUCCESS);
marea_fail5:
kmem_free(ma_hdl->h_ma_kaddr, ma_hdl->h_ma_real_len);
marea_fail4:
status = ddi_dma_unbind_handle(ma_hdl->h_ma_dmahdl);
marea_fail3:
ddi_dma_free_handle(&ma_hdl->h_ma_dmahdl);
kmem_free(ma_hdl, sizeof (*ma_hdl));
*ma_hdl_p = NULL;
return (ibt_status);
}
/*
* hermon_ci_map_mem_area()
* Context: Can be called from user or base context.
*
* Creates the memory mapping suitable for a subsequent posting of an
* FRWR work request. All the info about the memory area for the
* FRWR work request (wr member of "union ibt_reg_req_u") is filled
* such that the client only needs to point wr.rc.rcwr.reg_pmr to it,
* and then fill in the additional information only it knows.
*
* Alternatively, creates the memory mapping for FMR.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_map_mem_area(ibc_hca_hdl_t hca, ibt_va_attr_t *va_attrs,
void *ibtl_reserved, uint_t list_len, ibt_reg_req_t *reg_req,
ibc_ma_hdl_t *ma_hdl_p)
{
ibt_status_t ibt_status;
int status;
ibc_ma_hdl_t ma_hdl;
ibt_wr_reg_pmr_t *pmr;
ib_memlen_t len;
ddi_dma_attr_t dma_attr;
ddi_dma_handle_t khdl;
uint_t cookie_cnt;
ddi_dma_cookie_t dmacookie, kcookie;
hermon_state_t *state;
uint64_t *kaddr;
uint64_t addr, endaddr, pagesize, kcookie_paddr;
int i, j, kmflag;
int (*callback)(caddr_t);
if (va_attrs->va_flags & (IBT_VA_FMR | IBT_VA_REG_FN)) {
/* delegate FMR and Physical Register to other function */
return (hermon_map_mem_area_fmr(hca, va_attrs, list_len,
®_req->fn_arg, ma_hdl_p));
}
/* FRWR */
state = (hermon_state_t *)hca;
if (!(state->hs_ibtfinfo.hca_attr->hca_flags2 & IBT_HCA2_MEM_MGT_EXT))
return (IBT_NOT_SUPPORTED);
hermon_dma_attr_init(state, &dma_attr);
#ifdef __sparc
if (state->hs_cfg_profile->cp_iommu_bypass == HERMON_BINDMEM_BYPASS)
dma_attr.dma_attr_flags = DDI_DMA_FORCE_PHYSICAL;
if (hermon_kernel_data_ro == HERMON_RO_ENABLED)
dma_attr.dma_attr_flags |= DDI_DMA_RELAXED_ORDERING;
#endif
if (va_attrs->va_flags & IBT_VA_NOSLEEP) {
kmflag = KM_NOSLEEP;
callback = DDI_DMA_DONTWAIT;
} else {
kmflag = KM_SLEEP;
callback = DDI_DMA_SLEEP;
}
ma_hdl = kmem_zalloc(sizeof (*ma_hdl), kmflag);
if (ma_hdl == NULL) {
return (IBT_INSUFF_RESOURCE);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*ma_hdl))
status = ddi_dma_alloc_handle(state->hs_dip, &dma_attr,
callback, NULL, &ma_hdl->h_ma_dmahdl);
if (status != DDI_SUCCESS) {
ibt_status = IBT_INSUFF_RESOURCE;
goto marea_fail0;
}
dma_attr.dma_attr_align = 64; /* as per PRM */
status = ddi_dma_alloc_handle(state->hs_dip, &dma_attr,
callback, NULL, &ma_hdl->h_ma_list_hdl);
if (status != DDI_SUCCESS) {
ibt_status = IBT_INSUFF_RESOURCE;
goto marea_fail1;
}
/*
* Entries in the list in the last slot on each page cannot be used,
* so 1 extra ibt_phys_addr_t is allocated per page. We add 1 more
* to deal with the possibility of a less than 1 page allocation
* across a page boundary.
*/
status = ddi_dma_mem_alloc(ma_hdl->h_ma_list_hdl, (list_len + 1 +
list_len / (HERMON_PAGESIZE / sizeof (ibt_phys_addr_t))) *
sizeof (ibt_phys_addr_t),
&state->hs_reg_accattr, DDI_DMA_CONSISTENT, callback, NULL,
&ma_hdl->h_ma_kaddr, &ma_hdl->h_ma_real_len,
&ma_hdl->h_ma_list_acc_hdl);
if (status != DDI_SUCCESS) {
ibt_status = IBT_INSUFF_RESOURCE;
goto marea_fail2;
}
status = ddi_dma_addr_bind_handle(ma_hdl->h_ma_list_hdl, NULL,
ma_hdl->h_ma_kaddr, ma_hdl->h_ma_real_len, DDI_DMA_RDWR |
DDI_DMA_CONSISTENT, callback, NULL,
&kcookie, &cookie_cnt);
if (status != DDI_SUCCESS) {
ibt_status = IBT_INSUFF_RESOURCE;
goto marea_fail3;
}
if ((kcookie.dmac_laddress & 0x3f) != 0) {
cmn_err(CE_NOTE, "64-byte alignment assumption wrong");
ibt_status = ibc_get_ci_failure(0);
goto marea_fail4;
}
ma_hdl->h_ma_list_cookie.p_laddr = kcookie.dmac_laddress;
if (va_attrs->va_flags & IBT_VA_BUF) {
status = ddi_dma_buf_bind_handle(ma_hdl->h_ma_dmahdl,
va_attrs->va_buf, DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
callback, NULL, &dmacookie, &cookie_cnt);
} else {
status = ddi_dma_addr_bind_handle(ma_hdl->h_ma_dmahdl,
va_attrs->va_as, (caddr_t)(uintptr_t)va_attrs->va_vaddr,
va_attrs->va_len, DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
callback, NULL, &dmacookie, &cookie_cnt);
}
if (status != DDI_DMA_MAPPED) {
ibt_status = ibc_get_ci_failure(0);
goto marea_fail4;
}
i = 0; /* count the number of pbl entries */
j = 0; /* count the number of links to next HERMON_PAGE */
len = 0;
pagesize = PAGESIZE;
kaddr = (uint64_t *)(void *)ma_hdl->h_ma_kaddr;
kcookie.dmac_size += kcookie.dmac_laddress & HERMON_PAGEOFFSET;
kcookie_paddr = kcookie.dmac_laddress & HERMON_PAGEMASK;
khdl = ma_hdl->h_ma_list_hdl;
while (cookie_cnt-- > 0) {
addr = dmacookie.dmac_laddress;
len += dmacookie.dmac_size;
endaddr = addr + (dmacookie.dmac_size - 1);
addr = addr & ~(pagesize - 1);
while (addr <= endaddr) {
if (i >= list_len) {
ibt_status = IBT_PBL_TOO_SMALL;
goto marea_fail5;
}
/* Deal with last entry on page. */
if (!((uintptr_t)&kaddr[i+j+1] & HERMON_PAGEOFFSET)) {
if (kcookie.dmac_size > HERMON_PAGESIZE) {
kcookie_paddr += HERMON_PAGESIZE;
kcookie.dmac_size -= HERMON_PAGESIZE;
} else {
ddi_dma_nextcookie(khdl, &kcookie);
kcookie_paddr = kcookie.dmac_laddress;
}
kaddr[i+j] = htonll(kcookie_paddr);
j++;
}
kaddr[i+j] = htonll(addr | HERMON_MTT_ENTRY_PRESENT);
i++;
addr += pagesize;
if (addr == 0) {
static int do_once = 1;
_NOTE(SCHEME_PROTECTS_DATA("safe sharing",
do_once))
if (do_once) {
do_once = 0;
cmn_err(CE_NOTE, "probable error in "
"dma_cookie address: map_mem_area");
}
break;
}
}
if (cookie_cnt != 0)
ddi_dma_nextcookie(ma_hdl->h_ma_dmahdl, &dmacookie);
}
pmr = ®_req->wr;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*pmr))
pmr->pmr_len = len;
pmr->pmr_offset = va_attrs->va_vaddr & PAGEOFFSET;
pmr->pmr_buf_sz = PAGESHIFT; /* PRM says "Page Size", but... */
pmr->pmr_num_buf = i;
pmr->pmr_addr_list = &ma_hdl->h_ma_list_cookie;
*ma_hdl_p = ma_hdl;
return (IBT_SUCCESS);
marea_fail5:
status = ddi_dma_unbind_handle(ma_hdl->h_ma_dmahdl);
if (status != DDI_SUCCESS)
HERMON_WARNING(state, "failed to unbind DMA mapping");
marea_fail4:
status = ddi_dma_unbind_handle(ma_hdl->h_ma_list_hdl);
if (status != DDI_SUCCESS)
HERMON_WARNING(state, "failed to unbind DMA mapping");
marea_fail3:
ddi_dma_mem_free(&ma_hdl->h_ma_list_acc_hdl);
marea_fail2:
ddi_dma_free_handle(&ma_hdl->h_ma_list_hdl);
marea_fail1:
ddi_dma_free_handle(&ma_hdl->h_ma_dmahdl);
marea_fail0:
kmem_free(ma_hdl, sizeof (*ma_hdl));
*ma_hdl_p = NULL;
return (ibt_status);
}
/*
* hermon_ci_unmap_mem_area()
* Unmap the memory area
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_unmap_mem_area(ibc_hca_hdl_t hca, ibc_ma_hdl_t ma_hdl)
{
int status;
hermon_state_t *state;
if (ma_hdl == NULL) {
return (IBT_MA_HDL_INVALID);
}
state = (hermon_state_t *)hca;
if (ma_hdl->h_ma_list_hdl != NULL) {
status = ddi_dma_unbind_handle(ma_hdl->h_ma_list_hdl);
if (status != DDI_SUCCESS)
HERMON_WARNING(state, "failed to unbind DMA mapping");
ddi_dma_mem_free(&ma_hdl->h_ma_list_acc_hdl);
ddi_dma_free_handle(&ma_hdl->h_ma_list_hdl);
} else {
kmem_free(ma_hdl->h_ma_kaddr, ma_hdl->h_ma_real_len);
}
status = ddi_dma_unbind_handle(ma_hdl->h_ma_dmahdl);
if (status != DDI_SUCCESS)
HERMON_WARNING(state, "failed to unbind DMA mapping");
ddi_dma_free_handle(&ma_hdl->h_ma_dmahdl);
kmem_free(ma_hdl, sizeof (*ma_hdl));
return (IBT_SUCCESS);
}
struct ibc_mi_s {
int imh_len;
ddi_dma_handle_t imh_dmahandle[1];
};
_NOTE(SCHEME_PROTECTS_DATA("safe sharing",
ibc_mi_s::imh_len
ibc_mi_s::imh_dmahandle))
/*
* hermon_ci_map_mem_iov()
* Map the memory
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_map_mem_iov(ibc_hca_hdl_t hca, ibt_iov_attr_t *iov_attr,
ibt_all_wr_t *wr, ibc_mi_hdl_t *mi_hdl_p)
{
int status;
int i, j, nds, max_nds;
uint_t len;
ibt_status_t ibt_status;
ddi_dma_handle_t dmahdl;
ddi_dma_cookie_t dmacookie;
ddi_dma_attr_t dma_attr;
uint_t cookie_cnt;
ibc_mi_hdl_t mi_hdl;
ibt_lkey_t rsvd_lkey;
ibt_wr_ds_t *sgl;
hermon_state_t *state;
int kmflag;
int (*callback)(caddr_t);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*wr))
state = (hermon_state_t *)hca;
hermon_dma_attr_init(state, &dma_attr);
#ifdef __sparc
if (state->hs_cfg_profile->cp_iommu_bypass == HERMON_BINDMEM_BYPASS)
dma_attr.dma_attr_flags = DDI_DMA_FORCE_PHYSICAL;
if (hermon_kernel_data_ro == HERMON_RO_ENABLED)
dma_attr.dma_attr_flags |= DDI_DMA_RELAXED_ORDERING;
#endif
nds = 0;
max_nds = iov_attr->iov_wr_nds;
if (iov_attr->iov_lso_hdr_sz)
max_nds -= (iov_attr->iov_lso_hdr_sz + sizeof (uint32_t) +
0xf) >> 4; /* 0xf is for rounding up to a multiple of 16 */
rsvd_lkey = (iov_attr->iov_flags & IBT_IOV_ALT_LKEY) ?
iov_attr->iov_alt_lkey : state->hs_devlim.rsv_lkey;
if ((iov_attr->iov_flags & IBT_IOV_NOSLEEP) == 0) {
kmflag = KM_SLEEP;
callback = DDI_DMA_SLEEP;
} else {
kmflag = KM_NOSLEEP;
callback = DDI_DMA_DONTWAIT;
}
if (iov_attr->iov_flags & IBT_IOV_BUF) {
mi_hdl = kmem_alloc(sizeof (*mi_hdl), kmflag);
if (mi_hdl == NULL)
return (IBT_INSUFF_RESOURCE);
sgl = wr->send.wr_sgl;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*sgl))
status = ddi_dma_alloc_handle(state->hs_dip, &dma_attr,
callback, NULL, &dmahdl);
if (status != DDI_SUCCESS) {
kmem_free(mi_hdl, sizeof (*mi_hdl));
return (IBT_INSUFF_RESOURCE);
}
status = ddi_dma_buf_bind_handle(dmahdl, iov_attr->iov_buf,
DDI_DMA_RDWR | DDI_DMA_CONSISTENT, callback, NULL,
&dmacookie, &cookie_cnt);
if (status != DDI_DMA_MAPPED) {
ddi_dma_free_handle(&dmahdl);
kmem_free(mi_hdl, sizeof (*mi_hdl));
return (ibc_get_ci_failure(0));
}
while (cookie_cnt-- > 0) {
if (nds > max_nds) {
status = ddi_dma_unbind_handle(dmahdl);
if (status != DDI_SUCCESS)
HERMON_WARNING(state, "failed to "
"unbind DMA mapping");
ddi_dma_free_handle(&dmahdl);
return (IBT_SGL_TOO_SMALL);
}
sgl[nds].ds_va = dmacookie.dmac_laddress;
sgl[nds].ds_key = rsvd_lkey;
sgl[nds].ds_len = (ib_msglen_t)dmacookie.dmac_size;
nds++;
if (cookie_cnt != 0)
ddi_dma_nextcookie(dmahdl, &dmacookie);
}
wr->send.wr_nds = nds;
mi_hdl->imh_len = 1;
mi_hdl->imh_dmahandle[0] = dmahdl;
*mi_hdl_p = mi_hdl;
return (IBT_SUCCESS);
}
if (iov_attr->iov_flags & IBT_IOV_RECV)
sgl = wr->recv.wr_sgl;
else
sgl = wr->send.wr_sgl;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*sgl))
len = iov_attr->iov_list_len;
for (i = 0, j = 0; j < len; j++) {
if (iov_attr->iov[j].iov_len == 0)
continue;
i++;
}
mi_hdl = kmem_alloc(sizeof (*mi_hdl) +
(i - 1) * sizeof (ddi_dma_handle_t), kmflag);
if (mi_hdl == NULL)
return (IBT_INSUFF_RESOURCE);
mi_hdl->imh_len = i;
for (i = 0, j = 0; j < len; j++) {
if (iov_attr->iov[j].iov_len == 0)
continue;
status = ddi_dma_alloc_handle(state->hs_dip, &dma_attr,
callback, NULL, &dmahdl);
if (status != DDI_SUCCESS) {
ibt_status = IBT_INSUFF_RESOURCE;
goto fail2;
}
status = ddi_dma_addr_bind_handle(dmahdl, iov_attr->iov_as,
iov_attr->iov[j].iov_addr, iov_attr->iov[j].iov_len,
DDI_DMA_RDWR | DDI_DMA_CONSISTENT, callback, NULL,
&dmacookie, &cookie_cnt);
if (status != DDI_DMA_MAPPED) {
ibt_status = ibc_get_ci_failure(0);
goto fail1;
}
if (nds + cookie_cnt > max_nds) {
ibt_status = IBT_SGL_TOO_SMALL;
goto fail2;
}
while (cookie_cnt-- > 0) {
sgl[nds].ds_va = dmacookie.dmac_laddress;
sgl[nds].ds_key = rsvd_lkey;
sgl[nds].ds_len = (ib_msglen_t)dmacookie.dmac_size;
nds++;
if (cookie_cnt != 0)
ddi_dma_nextcookie(dmahdl, &dmacookie);
}
mi_hdl->imh_dmahandle[i] = dmahdl;
i++;
}
if (iov_attr->iov_flags & IBT_IOV_RECV)
wr->recv.wr_nds = nds;
else
wr->send.wr_nds = nds;
*mi_hdl_p = mi_hdl;
return (IBT_SUCCESS);
fail1:
ddi_dma_free_handle(&dmahdl);
fail2:
while (--i >= 0) {
status = ddi_dma_unbind_handle(mi_hdl->imh_dmahandle[i]);
if (status != DDI_SUCCESS)
HERMON_WARNING(state, "failed to unbind DMA mapping");
ddi_dma_free_handle(&mi_hdl->imh_dmahandle[i]);
}
kmem_free(mi_hdl, sizeof (*mi_hdl) +
(len - 1) * sizeof (ddi_dma_handle_t));
*mi_hdl_p = NULL;
return (ibt_status);
}
/*
* hermon_ci_unmap_mem_iov()
* Unmap the memory
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_unmap_mem_iov(ibc_hca_hdl_t hca, ibc_mi_hdl_t mi_hdl)
{
int status, i;
hermon_state_t *state;
state = (hermon_state_t *)hca;
for (i = mi_hdl->imh_len; --i >= 0; ) {
status = ddi_dma_unbind_handle(mi_hdl->imh_dmahandle[i]);
if (status != DDI_SUCCESS)
HERMON_WARNING(state, "failed to unbind DMA mapping");
ddi_dma_free_handle(&mi_hdl->imh_dmahandle[i]);
}
kmem_free(mi_hdl, sizeof (*mi_hdl) +
(mi_hdl->imh_len - 1) * sizeof (ddi_dma_handle_t));
return (IBT_SUCCESS);
}
/*
* hermon_ci_alloc_lkey()
* Allocate an empty memory region for use with FRWR.
* Context: Can be called from user or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_alloc_lkey(ibc_hca_hdl_t hca, ibc_pd_hdl_t pd,
ibt_lkey_flags_t flags, uint_t list_sz, ibc_mr_hdl_t *mr_p,
ibt_pmr_desc_t *mem_desc_p)
{
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_mrhdl_t mrhdl;
int status;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mem_desc_p))
ASSERT(mr_p != NULL);
ASSERT(mem_desc_p != NULL);
state = (hermon_state_t *)hca;
pdhdl = (hermon_pdhdl_t)pd;
if (!(state->hs_ibtfinfo.hca_attr->hca_flags2 & IBT_HCA2_MEM_MGT_EXT))
return (IBT_NOT_SUPPORTED);
status = hermon_mr_alloc_lkey(state, pdhdl, flags, list_sz, &mrhdl);
if (status != DDI_SUCCESS) {
return (status);
}
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mrhdl))
/* Fill in the mem_desc_p structure */
mem_desc_p->pmd_iova = 0;
mem_desc_p->pmd_phys_buf_list_sz = list_sz;
mem_desc_p->pmd_lkey = mrhdl->mr_lkey;
/* Only set RKey if remote access was requested */
if (flags & IBT_KEY_REMOTE) {
mem_desc_p->pmd_rkey = mrhdl->mr_rkey;
}
mem_desc_p->pmd_sync_required = B_FALSE;
/* Return the Hermon MR handle */
*mr_p = (ibc_mr_hdl_t)mrhdl;
return (IBT_SUCCESS);
}
/* Physical Register Memory Region */
/*
* hermon_ci_register_physical_mr()
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_register_physical_mr(ibc_hca_hdl_t hca, ibc_pd_hdl_t pd,
ibt_pmr_attr_t *mem_pattrs, void *ibtl_reserved, ibc_mr_hdl_t *mr_p,
ibt_pmr_desc_t *mem_desc_p)
{
return (IBT_NOT_SUPPORTED);
}
/*
* hermon_ci_reregister_physical_mr()
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_reregister_physical_mr(ibc_hca_hdl_t hca, ibc_mr_hdl_t mr,
ibc_pd_hdl_t pd, ibt_pmr_attr_t *mem_pattrs, void *ibtl_reserved,
ibc_mr_hdl_t *mr_p, ibt_pmr_desc_t *mr_desc_p)
{
return (IBT_NOT_SUPPORTED);
}
/* Mellanox FMR Support */
/*
* hermon_ci_create_fmr_pool()
* Creates a pool of memory regions suitable for FMR registration
* Context: Can be called from base context only
*/
static ibt_status_t
hermon_ci_create_fmr_pool(ibc_hca_hdl_t hca, ibc_pd_hdl_t pd,
ibt_fmr_pool_attr_t *params, ibc_fmr_pool_hdl_t *fmr_pool_p)
{
hermon_state_t *state;
hermon_pdhdl_t pdhdl;
hermon_fmrhdl_t fmrpoolhdl;
int status;
state = (hermon_state_t *)hca;
/* Check for valid PD handle pointer */
if (pd == NULL) {
return (IBT_PD_HDL_INVALID);
}
pdhdl = (hermon_pdhdl_t)pd;
/*
* Validate the access flags. Both Remote Write and Remote Atomic
* require the Local Write flag to be set
*/
if (((params->fmr_flags & IBT_MR_ENABLE_REMOTE_WRITE) ||
(params->fmr_flags & IBT_MR_ENABLE_REMOTE_ATOMIC)) &&
!(params->fmr_flags & IBT_MR_ENABLE_LOCAL_WRITE)) {
return (IBT_MR_ACCESS_REQ_INVALID);
}
status = hermon_create_fmr_pool(state, pdhdl, params, &fmrpoolhdl);
if (status != DDI_SUCCESS) {
return (status);
}
/* Set fmr_pool from hermon handle */
*fmr_pool_p = (ibc_fmr_pool_hdl_t)fmrpoolhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_destroy_fmr_pool()
* Free all resources associated with an FMR pool.
* Context: Can be called from base context only.
*/
static ibt_status_t
hermon_ci_destroy_fmr_pool(ibc_hca_hdl_t hca, ibc_fmr_pool_hdl_t fmr_pool)
{
hermon_state_t *state;
hermon_fmrhdl_t fmrpoolhdl;
int status;
state = (hermon_state_t *)hca;
fmrpoolhdl = (hermon_fmrhdl_t)fmr_pool;
status = hermon_destroy_fmr_pool(state, fmrpoolhdl);
return (status);
}
/*
* hermon_ci_flush_fmr_pool()
* Force a flush of the memory tables, cleaning up used FMR resources.
* Context: Can be called from interrupt or base context.
*/
static ibt_status_t
hermon_ci_flush_fmr_pool(ibc_hca_hdl_t hca, ibc_fmr_pool_hdl_t fmr_pool)
{
hermon_state_t *state;
hermon_fmrhdl_t fmrpoolhdl;
int status;
state = (hermon_state_t *)hca;
fmrpoolhdl = (hermon_fmrhdl_t)fmr_pool;
status = hermon_flush_fmr_pool(state, fmrpoolhdl);
return (status);
}
/*
* hermon_ci_register_physical_fmr()
* From the 'pool' of FMR regions passed in, performs register physical
* operation.
* Context: Can be called from interrupt or base context.
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_register_physical_fmr(ibc_hca_hdl_t hca,
ibc_fmr_pool_hdl_t fmr_pool, ibt_pmr_attr_t *mem_pattr,
void *ibtl_reserved, ibc_mr_hdl_t *mr_p, ibt_pmr_desc_t *mem_desc_p)
{
hermon_state_t *state;
hermon_mrhdl_t mrhdl;
hermon_fmrhdl_t fmrpoolhdl;
int status;
ASSERT(mem_pattr != NULL);
ASSERT(mr_p != NULL);
ASSERT(mem_desc_p != NULL);
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
fmrpoolhdl = (hermon_fmrhdl_t)fmr_pool;
status = hermon_register_physical_fmr(state, fmrpoolhdl, mem_pattr,
&mrhdl, mem_desc_p);
if (status != DDI_SUCCESS) {
return (status);
}
/*
* If region is mapped for streaming (i.e. noncoherent), then set
* sync is required
*/
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*mem_desc_p))
mem_desc_p->pmd_sync_required = (mrhdl->mr_bindinfo.bi_flags &
IBT_MR_NONCOHERENT) ? B_TRUE : B_FALSE;
if (mem_desc_p->pmd_sync_required == B_TRUE) {
/* Fill in DMA handle for future sync operations */
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(mrhdl->mr_bindinfo))
mrhdl->mr_bindinfo.bi_dmahdl =
(ddi_dma_handle_t)mem_pattr->pmr_ma;
}
/* Return the Hermon MR handle */
*mr_p = (ibc_mr_hdl_t)mrhdl;
return (IBT_SUCCESS);
}
/*
* hermon_ci_deregister_fmr()
* Moves an FMR (specified by 'mr') to the deregistered state.
* Context: Can be called from base context only.
*/
static ibt_status_t
hermon_ci_deregister_fmr(ibc_hca_hdl_t hca, ibc_mr_hdl_t mr)
{
hermon_state_t *state;
hermon_mrhdl_t mrhdl;
int status;
/* Grab the Hermon softstate pointer */
state = (hermon_state_t *)hca;
mrhdl = (hermon_mrhdl_t)mr;
/*
* Deregister the memory region, either "unmap" the FMR or deregister
* the normal memory region.
*/
status = hermon_deregister_fmr(state, mrhdl);
return (status);
}
static int
hermon_mem_alloc(hermon_state_t *state, size_t size, ibt_mr_flags_t flags,
caddr_t *kaddrp, ibc_mem_alloc_hdl_t *mem_hdl)
{
ddi_dma_handle_t dma_hdl;
ddi_dma_attr_t dma_attr;
ddi_acc_handle_t acc_hdl;
size_t real_len;
int status;
int (*ddi_cb)(caddr_t);
ibc_mem_alloc_hdl_t mem_alloc_hdl;
hermon_dma_attr_init(state, &dma_attr);
ddi_cb = (flags & IBT_MR_NOSLEEP) ? DDI_DMA_DONTWAIT : DDI_DMA_SLEEP;
/* Allocate a DMA handle */
status = ddi_dma_alloc_handle(state->hs_dip, &dma_attr, ddi_cb,
NULL, &dma_hdl);
if (status != DDI_SUCCESS) {
return (DDI_FAILURE);
}
/* Allocate DMA memory */
status = ddi_dma_mem_alloc(dma_hdl, size,
&state->hs_reg_accattr, DDI_DMA_CONSISTENT, ddi_cb,
NULL, kaddrp, &real_len, &acc_hdl);
if (status != DDI_SUCCESS) {
ddi_dma_free_handle(&dma_hdl);
return (DDI_FAILURE);
}
/* Package the hermon_dma_info contents and return */
mem_alloc_hdl = kmem_alloc(sizeof (**mem_hdl),
(flags & IBT_MR_NOSLEEP) ? KM_NOSLEEP : KM_SLEEP);
if (mem_alloc_hdl == NULL) {
ddi_dma_mem_free(&acc_hdl);
ddi_dma_free_handle(&dma_hdl);
return (DDI_FAILURE);
}
mem_alloc_hdl->ibc_dma_hdl = dma_hdl;
mem_alloc_hdl->ibc_acc_hdl = acc_hdl;
*mem_hdl = mem_alloc_hdl;
return (DDI_SUCCESS);
}
/*
* hermon_ci_alloc_io_mem()
* Allocate dma-able memory
*
*/
static ibt_status_t
hermon_ci_alloc_io_mem(ibc_hca_hdl_t hca, size_t size, ibt_mr_flags_t mr_flag,
caddr_t *kaddrp, ibc_mem_alloc_hdl_t *mem_alloc_hdl_p)
{
hermon_state_t *state;
int status;
/* Grab the Hermon softstate pointer and mem handle */
state = (hermon_state_t *)hca;
/* Allocate the memory and handles */
status = hermon_mem_alloc(state, size, mr_flag, kaddrp,
mem_alloc_hdl_p);
if (status != DDI_SUCCESS) {
*mem_alloc_hdl_p = NULL;
*kaddrp = NULL;
return (status);
}
return (IBT_SUCCESS);
}
/*
* hermon_ci_free_io_mem()
* Unbind handl and free the memory
*/
/* ARGSUSED */
static ibt_status_t
hermon_ci_free_io_mem(ibc_hca_hdl_t hca, ibc_mem_alloc_hdl_t mem_alloc_hdl)
{
/* Unbind the handles and free the memory */
(void) ddi_dma_unbind_handle(mem_alloc_hdl->ibc_dma_hdl);
ddi_dma_mem_free(&mem_alloc_hdl->ibc_acc_hdl);
ddi_dma_free_handle(&mem_alloc_hdl->ibc_dma_hdl);
kmem_free(mem_alloc_hdl, sizeof (*mem_alloc_hdl));
return (IBT_SUCCESS);
}
|