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
|
/*
* 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) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright (c) 2005 SilverStorm Technologies, 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.
*
*/
/*
* Sun elects to include this software in Sun product
* under the OpenIB BSD license.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/ib/clients/rds/rdsib_cm.h>
#include <sys/ib/clients/rds/rdsib_ib.h>
#include <sys/ib/clients/rds/rdsib_buf.h>
#include <sys/ib/clients/rds/rdsib_ep.h>
#include <sys/ib/clients/rds/rds_kstat.h>
static void rds_async_handler(void *clntp, ibt_hca_hdl_t hdl,
ibt_async_code_t code, ibt_async_event_t *event);
static struct ibt_clnt_modinfo_s rds_ib_modinfo = {
IBTI_V_CURR,
IBT_NETWORK,
rds_async_handler,
NULL,
"RDS"
};
/* performance tunables */
uint_t rds_no_interrupts = 0;
uint_t rds_poll_percent_full = 25;
uint_t rds_wc_signal = IBT_NEXT_SOLICITED;
uint_t rds_waittime_ms = 100; /* ms */
extern dev_info_t *rdsib_dev_info;
extern void rds_close_sessions();
static void
rdsib_validate_chan_sizes(ibt_hca_attr_t *hattrp)
{
/* The SQ size should not be more than that supported by the HCA */
if (((MaxDataSendBuffers + RDS_NUM_ACKS) > hattrp->hca_max_chan_sz) ||
((MaxDataSendBuffers + RDS_NUM_ACKS) > hattrp->hca_max_cq_sz)) {
RDS_DPRINTF2("RDSIB", "MaxDataSendBuffers + %d is greater "
"than that supported by the HCA driver "
"(%d + %d > %d or %d), lowering it to a supported value.",
RDS_NUM_ACKS, MaxDataSendBuffers, RDS_NUM_ACKS,
hattrp->hca_max_chan_sz, hattrp->hca_max_cq_sz);
MaxDataSendBuffers = (hattrp->hca_max_chan_sz >
hattrp->hca_max_cq_sz) ?
hattrp->hca_max_cq_sz - RDS_NUM_ACKS :
hattrp->hca_max_chan_sz - RDS_NUM_ACKS;
}
/* The RQ size should not be more than that supported by the HCA */
if ((MaxDataRecvBuffers > hattrp->hca_max_chan_sz) ||
(MaxDataRecvBuffers > hattrp->hca_max_cq_sz)) {
RDS_DPRINTF2("RDSIB", "MaxDataRecvBuffers is greater than that "
"supported by the HCA driver (%d > %d or %d), lowering it "
"to a supported value.", MaxDataRecvBuffers,
hattrp->hca_max_chan_sz, hattrp->hca_max_cq_sz);
MaxDataRecvBuffers = (hattrp->hca_max_chan_sz >
hattrp->hca_max_cq_sz) ? hattrp->hca_max_cq_sz :
hattrp->hca_max_chan_sz;
}
/* The SQ size should not be more than that supported by the HCA */
if ((MaxCtrlSendBuffers > hattrp->hca_max_chan_sz) ||
(MaxCtrlSendBuffers > hattrp->hca_max_cq_sz)) {
RDS_DPRINTF2("RDSIB", "MaxCtrlSendBuffers is greater than that "
"supported by the HCA driver (%d > %d or %d), lowering it "
"to a supported value.", MaxCtrlSendBuffers,
hattrp->hca_max_chan_sz, hattrp->hca_max_cq_sz);
MaxCtrlSendBuffers = (hattrp->hca_max_chan_sz >
hattrp->hca_max_cq_sz) ? hattrp->hca_max_cq_sz :
hattrp->hca_max_chan_sz;
}
/* The RQ size should not be more than that supported by the HCA */
if ((MaxCtrlRecvBuffers > hattrp->hca_max_chan_sz) ||
(MaxCtrlRecvBuffers > hattrp->hca_max_cq_sz)) {
RDS_DPRINTF2("RDSIB", "MaxCtrlRecvBuffers is greater than that "
"supported by the HCA driver (%d > %d or %d), lowering it "
"to a supported value.", MaxCtrlRecvBuffers,
hattrp->hca_max_chan_sz, hattrp->hca_max_cq_sz);
MaxCtrlRecvBuffers = (hattrp->hca_max_chan_sz >
hattrp->hca_max_cq_sz) ? hattrp->hca_max_cq_sz :
hattrp->hca_max_chan_sz;
}
/* The MaxRecvMemory should be less than that supported by the HCA */
if ((NDataRX * RdsPktSize) > hattrp->hca_max_memr_len) {
RDS_DPRINTF2("RDSIB", "MaxRecvMemory is greater than that "
"supported by the HCA driver (%d > %d), lowering it to %d",
NDataRX * RdsPktSize, hattrp->hca_max_memr_len,
hattrp->hca_max_memr_len);
NDataRX = hattrp->hca_max_memr_len/RdsPktSize;
}
}
/* Return hcap, given the hca guid */
rds_hca_t *
rds_lkup_hca(ib_guid_t hca_guid)
{
rds_hca_t *hcap;
RDS_DPRINTF4("rds_lkup_hca", "Enter: statep: 0x%p "
"guid: %llx", rdsib_statep, hca_guid);
rw_enter(&rdsib_statep->rds_hca_lock, RW_READER);
hcap = rdsib_statep->rds_hcalistp;
while ((hcap != NULL) && (hcap->hca_guid != hca_guid)) {
hcap = hcap->hca_nextp;
}
rw_exit(&rdsib_statep->rds_hca_lock);
RDS_DPRINTF4("rds_lkup_hca", "return");
return (hcap);
}
void rds_randomize_qps(rds_hca_t *hcap);
static rds_hca_t *
rdsib_init_hca(ib_guid_t hca_guid)
{
rds_hca_t *hcap;
boolean_t alloc = B_FALSE;
int ret;
RDS_DPRINTF2("rdsib_init_hca", "enter: HCA 0x%llx", hca_guid);
/* Do a HCA lookup */
hcap = rds_lkup_hca(hca_guid);
if (hcap != NULL && hcap->hca_hdl != NULL) {
/*
* This can happen if we get IBT_HCA_ATTACH_EVENT on an HCA
* that we have already opened. Just return NULL so that
* we'll not end up reinitializing the HCA again.
*/
RDS_DPRINTF2("rdsib_init_hca", "HCA already initialized");
return (NULL);
}
if (hcap == NULL) {
RDS_DPRINTF2("rdsib_init_hca", "New HCA is added");
hcap = (rds_hca_t *)kmem_zalloc(sizeof (rds_hca_t), KM_SLEEP);
alloc = B_TRUE;
}
hcap->hca_guid = hca_guid;
ret = ibt_open_hca(rdsib_statep->rds_ibhdl, hca_guid,
&hcap->hca_hdl);
if (ret != IBT_SUCCESS) {
if (ret == IBT_HCA_IN_USE) {
RDS_DPRINTF2("rdsib_init_hca",
"ibt_open_hca: 0x%llx returned IBT_HCA_IN_USE",
hca_guid);
} else {
RDS_DPRINTF2("rdsib_init_hca",
"ibt_open_hca: 0x%llx failed: %d", hca_guid, ret);
}
if (alloc == B_TRUE) {
kmem_free(hcap, sizeof (rds_hca_t));
}
return (NULL);
}
ret = ibt_query_hca(hcap->hca_hdl, &hcap->hca_attr);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rdsib_init_hca",
"Query HCA: 0x%llx failed: %d", hca_guid, ret);
ret = ibt_close_hca(hcap->hca_hdl);
ASSERT(ret == IBT_SUCCESS);
if (alloc == B_TRUE) {
kmem_free(hcap, sizeof (rds_hca_t));
} else {
hcap->hca_hdl = NULL;
}
return (NULL);
}
ret = ibt_query_hca_ports(hcap->hca_hdl, 0,
&hcap->hca_pinfop, &hcap->hca_nports, &hcap->hca_pinfo_sz);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rdsib_init_hca",
"Query HCA 0x%llx ports failed: %d", hca_guid,
ret);
ret = ibt_close_hca(hcap->hca_hdl);
hcap->hca_hdl = NULL;
ASSERT(ret == IBT_SUCCESS);
if (alloc == B_TRUE) {
kmem_free(hcap, sizeof (rds_hca_t));
} else {
hcap->hca_hdl = NULL;
}
return (NULL);
}
/* Only one PD per HCA is allocated, so do it here */
ret = ibt_alloc_pd(hcap->hca_hdl, IBT_PD_NO_FLAGS,
&hcap->hca_pdhdl);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rdsib_init_hca",
"ibt_alloc_pd 0x%llx failed: %d", hca_guid, ret);
(void) ibt_free_portinfo(hcap->hca_pinfop,
hcap->hca_pinfo_sz);
ret = ibt_close_hca(hcap->hca_hdl);
ASSERT(ret == IBT_SUCCESS);
hcap->hca_hdl = NULL;
if (alloc == B_TRUE) {
kmem_free(hcap, sizeof (rds_hca_t));
} else {
hcap->hca_hdl = NULL;
}
return (NULL);
}
rdsib_validate_chan_sizes(&hcap->hca_attr);
/* To minimize stale connections after ungraceful reboots */
rds_randomize_qps(hcap);
rw_enter(&rdsib_statep->rds_hca_lock, RW_WRITER);
hcap->hca_state = RDS_HCA_STATE_OPEN;
if (alloc == B_TRUE) {
/* this is a new HCA, add it to the list */
rdsib_statep->rds_nhcas++;
hcap->hca_nextp = rdsib_statep->rds_hcalistp;
rdsib_statep->rds_hcalistp = hcap;
}
rw_exit(&rdsib_statep->rds_hca_lock);
RDS_DPRINTF2("rdsib_init_hca", "return: HCA 0x%llx", hca_guid);
return (hcap);
}
/*
* Called from attach
*/
int
rdsib_initialize_ib()
{
ib_guid_t *guidp;
rds_hca_t *hcap;
uint_t ix, hcaix, nhcas;
int ret;
RDS_DPRINTF2("rdsib_initialize_ib", "enter: statep %p", rdsib_statep);
ASSERT(rdsib_statep != NULL);
if (rdsib_statep == NULL) {
RDS_DPRINTF1("rdsib_initialize_ib",
"RDS Statep not initialized");
return (-1);
}
/* How many hcas are there? */
nhcas = ibt_get_hca_list(&guidp);
if (nhcas == 0) {
RDS_DPRINTF2("rdsib_initialize_ib", "No IB HCAs Available");
return (-1);
}
RDS_DPRINTF3("rdsib_initialize_ib", "Number of HCAs: %d", nhcas);
/* Register with IBTF */
ret = ibt_attach(&rds_ib_modinfo, rdsib_dev_info, rdsib_statep,
&rdsib_statep->rds_ibhdl);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rdsib_initialize_ib", "ibt_attach failed: %d",
ret);
(void) ibt_free_hca_list(guidp, nhcas);
return (-1);
}
/*
* Open each HCA and gather its information. Don't care about HCAs
* that cannot be opened. It is OK as long as atleast one HCA can be
* opened.
* Initialize a HCA only if all the information is available.
*/
for (ix = 0, hcaix = 0; ix < nhcas; ix++) {
RDS_DPRINTF3(LABEL, "Open HCA: 0x%llx", guidp[ix]);
hcap = rdsib_init_hca(guidp[ix]);
if (hcap != NULL) hcaix++;
}
/* free the HCA list, we are done with it */
(void) ibt_free_hca_list(guidp, nhcas);
if (hcaix == 0) {
/* Failed to Initialize even one HCA */
RDS_DPRINTF2("rdsib_initialize_ib", "No HCAs are initialized");
(void) ibt_detach(rdsib_statep->rds_ibhdl);
rdsib_statep->rds_ibhdl = NULL;
return (-1);
}
if (hcaix < nhcas) {
RDS_DPRINTF2("rdsib_open_ib", "HCAs %d/%d failed to initialize",
(nhcas - hcaix), nhcas);
}
RDS_DPRINTF2("rdsib_initialize_ib", "return: statep %p", rdsib_statep);
return (0);
}
/*
* Called from detach
*/
void
rdsib_deinitialize_ib()
{
rds_hca_t *hcap, *nextp;
int ret;
RDS_DPRINTF2("rdsib_deinitialize_ib", "enter: statep %p", rdsib_statep);
/* close and destroy all the sessions */
rds_close_sessions(NULL);
/* Release all HCA resources */
rw_enter(&rdsib_statep->rds_hca_lock, RW_WRITER);
RDS_DPRINTF2("rdsib_deinitialize_ib", "HCA List: %p, NHCA: %d",
rdsib_statep->rds_hcalistp, rdsib_statep->rds_nhcas);
hcap = rdsib_statep->rds_hcalistp;
rdsib_statep->rds_hcalistp = NULL;
rdsib_statep->rds_nhcas = 0;
rw_exit(&rdsib_statep->rds_hca_lock);
while (hcap != NULL) {
nextp = hcap->hca_nextp;
if (hcap->hca_hdl != NULL) {
ret = ibt_free_pd(hcap->hca_hdl, hcap->hca_pdhdl);
ASSERT(ret == IBT_SUCCESS);
(void) ibt_free_portinfo(hcap->hca_pinfop,
hcap->hca_pinfo_sz);
ret = ibt_close_hca(hcap->hca_hdl);
ASSERT(ret == IBT_SUCCESS);
}
kmem_free(hcap, sizeof (rds_hca_t));
hcap = nextp;
}
/* Deregister with IBTF */
if (rdsib_statep->rds_ibhdl != NULL) {
(void) ibt_detach(rdsib_statep->rds_ibhdl);
rdsib_statep->rds_ibhdl = NULL;
}
RDS_DPRINTF2("rdsib_deinitialize_ib", "return: statep %p",
rdsib_statep);
}
/*
* Called on open of first RDS socket
*/
int
rdsib_open_ib()
{
int ret;
RDS_DPRINTF2("rdsib_open_ib", "enter: statep %p", rdsib_statep);
/* Enable incoming connection requests */
if (rdsib_statep->rds_srvhdl == NULL) {
rdsib_statep->rds_srvhdl =
rds_register_service(rdsib_statep->rds_ibhdl);
if (rdsib_statep->rds_srvhdl == NULL) {
RDS_DPRINTF2("rdsib_open_ib",
"Service registration failed");
return (-1);
} else {
/* bind the service on all available ports */
ret = rds_bind_service(rdsib_statep);
if (ret != 0) {
RDS_DPRINTF2("rdsib_open_ib",
"Bind service failed: %d", ret);
}
}
}
RDS_DPRINTF2("rdsib_open_ib", "return: statep %p", rdsib_statep);
return (0);
}
/*
* Called when all ports are closed.
*/
void
rdsib_close_ib()
{
int ret;
RDS_DPRINTF2("rdsib_close_ib", "enter: statep %p", rdsib_statep);
/* Disable incoming connection requests */
if (rdsib_statep->rds_srvhdl != NULL) {
ret = ibt_unbind_all_services(rdsib_statep->rds_srvhdl);
if (ret != 0) {
RDS_DPRINTF2("rdsib_close_ib",
"ibt_unbind_all_services failed: %d\n", ret);
}
ret = ibt_deregister_service(rdsib_statep->rds_ibhdl,
rdsib_statep->rds_srvhdl);
if (ret != 0) {
RDS_DPRINTF2("rdsib_close_ib",
"ibt_deregister_service failed: %d\n", ret);
} else {
rdsib_statep->rds_srvhdl = NULL;
}
}
RDS_DPRINTF2("rdsib_close_ib", "return: statep %p", rdsib_statep);
}
/* Return hcap, given the hca guid */
rds_hca_t *
rds_get_hcap(rds_state_t *statep, ib_guid_t hca_guid)
{
rds_hca_t *hcap;
RDS_DPRINTF4("rds_get_hcap", "rds_get_hcap: Enter: statep: 0x%p "
"guid: %llx", statep, hca_guid);
rw_enter(&statep->rds_hca_lock, RW_READER);
hcap = statep->rds_hcalistp;
while ((hcap != NULL) && (hcap->hca_guid != hca_guid)) {
hcap = hcap->hca_nextp;
}
/*
* don't let anyone use this HCA until the RECV memory
* is registered with this HCA
*/
if ((hcap != NULL) &&
(hcap->hca_state == RDS_HCA_STATE_MEM_REGISTERED)) {
ASSERT(hcap->hca_mrhdl != NULL);
rw_exit(&statep->rds_hca_lock);
return (hcap);
}
RDS_DPRINTF2("rds_get_hcap",
"HCA (0x%p, 0x%llx) is not initialized", hcap, hca_guid);
rw_exit(&statep->rds_hca_lock);
RDS_DPRINTF4("rds_get_hcap", "rds_get_hcap: return");
return (NULL);
}
/* Return hcap, given a gid */
rds_hca_t *
rds_gid_to_hcap(rds_state_t *statep, ib_gid_t gid)
{
rds_hca_t *hcap;
uint_t ix;
RDS_DPRINTF4("rds_gid_to_hcap", "Enter: statep: 0x%p gid: %llx:%llx",
statep, gid.gid_prefix, gid.gid_guid);
rw_enter(&statep->rds_hca_lock, RW_READER);
hcap = statep->rds_hcalistp;
while (hcap != NULL) {
/*
* don't let anyone use this HCA until the RECV memory
* is registered with this HCA
*/
if (hcap->hca_state != RDS_HCA_STATE_MEM_REGISTERED) {
RDS_DPRINTF3("rds_gid_to_hcap",
"HCA (0x%p, 0x%llx) is not initialized",
hcap, gid.gid_guid);
hcap = hcap->hca_nextp;
continue;
}
for (ix = 0; ix < hcap->hca_nports; ix++) {
if ((hcap->hca_pinfop[ix].p_sgid_tbl[0].gid_prefix ==
gid.gid_prefix) &&
(hcap->hca_pinfop[ix].p_sgid_tbl[0].gid_guid ==
gid.gid_guid)) {
RDS_DPRINTF4("rds_gid_to_hcap",
"gid found in hcap: 0x%p", hcap);
rw_exit(&statep->rds_hca_lock);
return (hcap);
}
}
hcap = hcap->hca_nextp;
}
rw_exit(&statep->rds_hca_lock);
return (NULL);
}
/* This is called from the send CQ handler */
void
rds_send_acknowledgement(rds_ep_t *ep)
{
int ret;
uint_t ix;
RDS_DPRINTF4("rds_send_acknowledgement", "Enter EP(%p)", ep);
mutex_enter(&ep->ep_lock);
ASSERT(ep->ep_rdmacnt != 0);
/*
* The previous ACK completed successfully, send the next one
* if more messages were received after sending the last ACK
*/
if (ep->ep_rbufid != *(uintptr_t *)(uintptr_t)ep->ep_ackds.ds_va) {
*(uintptr_t *)(uintptr_t)ep->ep_ackds.ds_va = ep->ep_rbufid;
mutex_exit(&ep->ep_lock);
/* send acknowledgement */
RDS_INCR_TXACKS();
ret = ibt_post_send(ep->ep_chanhdl, &ep->ep_ackwr, 1, &ix);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rds_send_acknowledgement",
"EP(%p): ibt_post_send for acknowledgement "
"failed: %d, SQ depth: %d",
ep, ret, ep->ep_sndpool.pool_nbusy);
mutex_enter(&ep->ep_lock);
ep->ep_rdmacnt--;
mutex_exit(&ep->ep_lock);
}
} else {
/* ACKed all messages, no more to ACK */
ep->ep_rdmacnt--;
mutex_exit(&ep->ep_lock);
return;
}
RDS_DPRINTF4("rds_send_acknowledgement", "Return EP(%p)", ep);
}
static int
rds_poll_ctrl_completions(ibt_cq_hdl_t cq, rds_ep_t *ep)
{
ibt_wc_t wc;
uint_t npolled;
rds_buf_t *bp;
rds_ctrl_pkt_t *cpkt;
rds_qp_t *recvqp;
int ret = IBT_SUCCESS;
RDS_DPRINTF4("rds_poll_ctrl_completions", "Enter: EP(%p)", ep);
bzero(&wc, sizeof (ibt_wc_t));
ret = ibt_poll_cq(cq, &wc, 1, &npolled);
if (ret != IBT_SUCCESS) {
if (ret != IBT_CQ_EMPTY) {
RDS_DPRINTF2(LABEL, "EP(%p) CQ(%p): ibt_poll_cq "
"returned: %d", ep, cq, ret);
} else {
RDS_DPRINTF5(LABEL, "EP(%p) CQ(%p): ibt_poll_cq "
"returned: IBT_CQ_EMPTY", ep, cq);
}
return (ret);
}
bp = (rds_buf_t *)(uintptr_t)wc.wc_id;
if (wc.wc_status != IBT_WC_SUCCESS) {
mutex_enter(&ep->ep_recvqp.qp_lock);
ep->ep_recvqp.qp_level--;
mutex_exit(&ep->ep_recvqp.qp_lock);
/* Free the buffer */
bp->buf_state = RDS_RCVBUF_FREE;
rds_free_recv_buf(bp, 1);
/* Receive completion failure */
if (wc.wc_status != IBT_WC_WR_FLUSHED_ERR) {
RDS_DPRINTF2("rds_poll_ctrl_completions",
"EP(%p) CQ(%p) BP(%p): WC Error Status: %d",
ep, cq, wc.wc_id, wc.wc_status);
}
return (ret);
}
/* there is one less in the RQ */
recvqp = &ep->ep_recvqp;
mutex_enter(&recvqp->qp_lock);
recvqp->qp_level--;
if ((recvqp->qp_taskqpending == B_FALSE) &&
(recvqp->qp_level <= recvqp->qp_lwm)) {
/* Time to post more buffers into the RQ */
recvqp->qp_taskqpending = B_TRUE;
mutex_exit(&recvqp->qp_lock);
ret = ddi_taskq_dispatch(rds_taskq,
rds_post_recv_buf, (void *)ep->ep_chanhdl, DDI_NOSLEEP);
if (ret != DDI_SUCCESS) {
RDS_DPRINTF2(LABEL, "ddi_taskq_dispatch failed: %d",
ret);
mutex_enter(&recvqp->qp_lock);
recvqp->qp_taskqpending = B_FALSE;
mutex_exit(&recvqp->qp_lock);
}
} else {
mutex_exit(&recvqp->qp_lock);
}
cpkt = (rds_ctrl_pkt_t *)(uintptr_t)bp->buf_ds.ds_va;
rds_handle_control_message(ep->ep_sp, cpkt);
bp->buf_state = RDS_RCVBUF_FREE;
rds_free_recv_buf(bp, 1);
RDS_DPRINTF4("rds_poll_ctrl_completions", "Return: EP(%p)", ep);
return (ret);
}
#define RDS_POST_FEW_ATATIME 100
/* Post recv WRs into the RQ. Assumes the ep->refcnt is already incremented */
void
rds_post_recv_buf(void *arg)
{
ibt_channel_hdl_t chanhdl;
rds_ep_t *ep;
rds_session_t *sp;
rds_qp_t *recvqp;
rds_bufpool_t *gp;
rds_buf_t *bp, *bp1;
ibt_recv_wr_t *wrp, wr[RDS_POST_FEW_ATATIME];
rds_hca_t *hcap;
uint_t npost, nspace, rcv_len;
uint_t ix, jx, kx;
int ret;
chanhdl = (ibt_channel_hdl_t)arg;
RDS_DPRINTF4("rds_post_recv_buf", "Enter: CHAN(%p)", chanhdl);
RDS_INCR_POST_RCV_BUF_CALLS();
ep = (rds_ep_t *)ibt_get_chan_private(chanhdl);
ASSERT(ep != NULL);
sp = ep->ep_sp;
recvqp = &ep->ep_recvqp;
RDS_DPRINTF5("rds_post_recv_buf", "EP(%p)", ep);
/* get the hcap for the HCA hosting this channel */
hcap = rds_lkup_hca(ep->ep_hca_guid);
if (hcap == NULL) {
RDS_DPRINTF2("rds_post_recv_buf", "HCA (0x%llx) not found",
ep->ep_hca_guid);
return;
}
/* Make sure the session is still connected */
rw_enter(&sp->session_lock, RW_READER);
if ((sp->session_state != RDS_SESSION_STATE_INIT) &&
(sp->session_state != RDS_SESSION_STATE_CONNECTED) &&
(sp->session_state != RDS_SESSION_STATE_HCA_CLOSING)) {
RDS_DPRINTF2("rds_post_recv_buf", "EP(%p): Session is not "
"in active state (%d)", ep, sp->session_state);
rw_exit(&sp->session_lock);
return;
}
rw_exit(&sp->session_lock);
/* how many can be posted */
mutex_enter(&recvqp->qp_lock);
nspace = recvqp->qp_depth - recvqp->qp_level;
if (nspace == 0) {
RDS_DPRINTF2("rds_post_recv_buf", "RQ is FULL");
recvqp->qp_taskqpending = B_FALSE;
mutex_exit(&recvqp->qp_lock);
return;
}
mutex_exit(&recvqp->qp_lock);
if (ep->ep_type == RDS_EP_TYPE_DATA) {
gp = &rds_dpool;
rcv_len = RdsPktSize;
} else {
gp = &rds_cpool;
rcv_len = RDS_CTRLPKT_SIZE;
}
bp = rds_get_buf(gp, nspace, &jx);
if (bp == NULL) {
RDS_DPRINTF2(LABEL, "EP(%p): No Recv buffers available", ep);
/* try again later */
ret = ddi_taskq_dispatch(rds_taskq, rds_post_recv_buf,
(void *)chanhdl, DDI_NOSLEEP);
if (ret != DDI_SUCCESS) {
RDS_DPRINTF2(LABEL, "ddi_taskq_dispatch failed: %d",
ret);
mutex_enter(&recvqp->qp_lock);
recvqp->qp_taskqpending = B_FALSE;
mutex_exit(&recvqp->qp_lock);
}
return;
}
if (jx != nspace) {
RDS_DPRINTF2(LABEL, "EP(%p): Recv buffers "
"needed: %d available: %d", ep, nspace, jx);
nspace = jx;
}
bp1 = bp;
for (ix = 0; ix < nspace; ix++) {
bp1->buf_ep = ep;
ASSERT(bp1->buf_state == RDS_RCVBUF_FREE);
bp1->buf_state = RDS_RCVBUF_POSTED;
bp1->buf_ds.ds_key = hcap->hca_lkey;
bp1->buf_ds.ds_len = rcv_len;
bp1 = bp1->buf_nextp;
}
#if 0
wrp = kmem_zalloc(RDS_POST_FEW_ATATIME * sizeof (ibt_recv_wr_t),
KM_SLEEP);
#else
wrp = &wr[0];
#endif
npost = nspace;
while (npost) {
jx = (npost > RDS_POST_FEW_ATATIME) ?
RDS_POST_FEW_ATATIME : npost;
for (ix = 0; ix < jx; ix++) {
wrp[ix].wr_id = (uintptr_t)bp;
wrp[ix].wr_nds = 1;
wrp[ix].wr_sgl = &bp->buf_ds;
bp = bp->buf_nextp;
}
ret = ibt_post_recv(chanhdl, wrp, jx, &kx);
if ((ret != IBT_SUCCESS) || (kx != jx)) {
RDS_DPRINTF2(LABEL, "ibt_post_recv for %d WRs failed: "
"%d", npost, ret);
npost -= kx;
break;
}
npost -= jx;
}
mutex_enter(&recvqp->qp_lock);
if (npost != 0) {
RDS_DPRINTF2("rds_post_recv_buf",
"EP(%p) Failed to post %d WRs", ep, npost);
recvqp->qp_level += (nspace - npost);
} else {
recvqp->qp_level += nspace;
}
/*
* sometimes, the recv WRs can get consumed as soon as they are
* posted. In that case, taskq thread to post more WRs to the RQ will
* not be scheduled as the taskqpending flag is still set.
*/
if (recvqp->qp_level == 0) {
mutex_exit(&recvqp->qp_lock);
ret = ddi_taskq_dispatch(rds_taskq,
rds_post_recv_buf, (void *)chanhdl, DDI_NOSLEEP);
if (ret != DDI_SUCCESS) {
RDS_DPRINTF2("rds_post_recv_buf",
"ddi_taskq_dispatch failed: %d", ret);
mutex_enter(&recvqp->qp_lock);
recvqp->qp_taskqpending = B_FALSE;
mutex_exit(&recvqp->qp_lock);
}
} else {
recvqp->qp_taskqpending = B_FALSE;
mutex_exit(&recvqp->qp_lock);
}
#if 0
kmem_free(wrp, RDS_POST_FEW_ATATIME * sizeof (ibt_recv_wr_t));
#endif
RDS_DPRINTF4("rds_post_recv_buf", "Return: EP(%p)", ep);
}
static int
rds_poll_data_completions(ibt_cq_hdl_t cq, rds_ep_t *ep)
{
ibt_wc_t wc;
rds_buf_t *bp;
rds_data_hdr_t *pktp;
rds_qp_t *recvqp;
uint_t npolled;
int ret = IBT_SUCCESS;
RDS_DPRINTF4("rds_poll_data_completions", "Enter: EP(%p)", ep);
bzero(&wc, sizeof (ibt_wc_t));
ret = ibt_poll_cq(cq, &wc, 1, &npolled);
if (ret != IBT_SUCCESS) {
if (ret != IBT_CQ_EMPTY) {
RDS_DPRINTF2(LABEL, "EP(%p) CQ(%p): ibt_poll_cq "
"returned: %d", ep, cq, ret);
} else {
RDS_DPRINTF5(LABEL, "EP(%p) CQ(%p): ibt_poll_cq "
"returned: IBT_CQ_EMPTY", ep, cq);
}
return (ret);
}
bp = (rds_buf_t *)(uintptr_t)wc.wc_id;
ASSERT(bp->buf_state == RDS_RCVBUF_POSTED);
bp->buf_state = RDS_RCVBUF_ONSOCKQ;
bp->buf_nextp = NULL;
if (wc.wc_status != IBT_WC_SUCCESS) {
mutex_enter(&ep->ep_recvqp.qp_lock);
ep->ep_recvqp.qp_level--;
mutex_exit(&ep->ep_recvqp.qp_lock);
/* free the buffer */
bp->buf_state = RDS_RCVBUF_FREE;
rds_free_recv_buf(bp, 1);
/* Receive completion failure */
if (wc.wc_status != IBT_WC_WR_FLUSHED_ERR) {
RDS_DPRINTF2("rds_poll_data_completions",
"EP(%p) CQ(%p) BP(%p): WC Error Status: %d",
ep, cq, wc.wc_id, wc.wc_status);
RDS_INCR_RXERRS();
}
return (ret);
}
/* there is one less in the RQ */
recvqp = &ep->ep_recvqp;
mutex_enter(&recvqp->qp_lock);
recvqp->qp_level--;
if ((recvqp->qp_taskqpending == B_FALSE) &&
(recvqp->qp_level <= recvqp->qp_lwm)) {
/* Time to post more buffers into the RQ */
recvqp->qp_taskqpending = B_TRUE;
mutex_exit(&recvqp->qp_lock);
ret = ddi_taskq_dispatch(rds_taskq,
rds_post_recv_buf, (void *)ep->ep_chanhdl, DDI_NOSLEEP);
if (ret != DDI_SUCCESS) {
RDS_DPRINTF2(LABEL, "ddi_taskq_dispatch failed: %d",
ret);
mutex_enter(&recvqp->qp_lock);
recvqp->qp_taskqpending = B_FALSE;
mutex_exit(&recvqp->qp_lock);
}
} else {
mutex_exit(&recvqp->qp_lock);
}
pktp = (rds_data_hdr_t *)(uintptr_t)bp->buf_ds.ds_va;
ASSERT(pktp->dh_datalen != 0);
RDS_DPRINTF5(LABEL, "Message Received: sendIP: 0x%x recvIP: 0x%x "
"sendport: %d recvport: %d npkts: %d pktno: %d", ep->ep_remip,
ep->ep_myip, pktp->dh_sendport, pktp->dh_recvport,
pktp->dh_npkts, pktp->dh_psn);
RDS_DPRINTF3(LABEL, "BP(%p): npkts: %d psn: %d", bp,
pktp->dh_npkts, pktp->dh_psn);
if (pktp->dh_npkts == 1) {
/* single pkt or last packet */
if (pktp->dh_psn != 0) {
/* last packet of a segmented message */
ASSERT(ep->ep_seglbp != NULL);
ep->ep_seglbp->buf_nextp = bp;
ep->ep_seglbp = bp;
rds_received_msg(ep, ep->ep_segfbp);
ep->ep_segfbp = NULL;
ep->ep_seglbp = NULL;
} else {
/* single packet */
rds_received_msg(ep, bp);
}
} else {
/* multi-pkt msg */
if (pktp->dh_psn == 0) {
/* first packet */
ASSERT(ep->ep_segfbp == NULL);
ep->ep_segfbp = bp;
ep->ep_seglbp = bp;
} else {
/* intermediate packet */
ASSERT(ep->ep_segfbp != NULL);
ep->ep_seglbp->buf_nextp = bp;
ep->ep_seglbp = bp;
}
}
RDS_DPRINTF4("rds_poll_data_completions", "Return: EP(%p)", ep);
return (ret);
}
void
rds_recvcq_handler(ibt_cq_hdl_t cq, void *arg)
{
rds_ep_t *ep;
int ret = IBT_SUCCESS;
int (*func)(ibt_cq_hdl_t, rds_ep_t *);
ep = (rds_ep_t *)arg;
RDS_DPRINTF4("rds_recvcq_handler", "enter: EP(%p)", ep);
if (ep->ep_type == RDS_EP_TYPE_DATA) {
func = rds_poll_data_completions;
} else {
func = rds_poll_ctrl_completions;
}
do {
ret = func(cq, ep);
} while (ret != IBT_CQ_EMPTY);
/* enable the CQ */
ret = ibt_enable_cq_notify(cq, rds_wc_signal);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL, "EP(%p) CQ(%p): ibt_enable_cq_notify "
"failed: %d", ep, cq, ret);
return;
}
do {
ret = func(cq, ep);
} while (ret != IBT_CQ_EMPTY);
RDS_DPRINTF4("rds_recvcq_handler", "Return: EP(%p)", ep);
}
void
rds_poll_send_completions(ibt_cq_hdl_t cq, rds_ep_t *ep, boolean_t lock)
{
ibt_wc_t wc[RDS_NUM_DATA_SEND_WCS];
uint_t npolled, nret, send_error = 0;
rds_buf_t *headp, *tailp, *bp;
int ret, ix;
RDS_DPRINTF4("rds_poll_send_completions", "Enter EP(%p)", ep);
headp = NULL;
tailp = NULL;
npolled = 0;
do {
ret = ibt_poll_cq(cq, wc, RDS_NUM_DATA_SEND_WCS, &nret);
if (ret != IBT_SUCCESS) {
if (ret != IBT_CQ_EMPTY) {
RDS_DPRINTF2(LABEL, "EP(%p) CQ(%p): "
"ibt_poll_cq returned: %d", ep, cq, ret);
} else {
RDS_DPRINTF5(LABEL, "EP(%p) CQ(%p): "
"ibt_poll_cq returned: IBT_CQ_EMPTY",
ep, cq);
}
break;
}
for (ix = 0; ix < nret; ix++) {
if (wc[ix].wc_status == IBT_WC_SUCCESS) {
if (wc[ix].wc_type == IBT_WRC_RDMAW) {
rds_send_acknowledgement(ep);
continue;
}
bp = (rds_buf_t *)(uintptr_t)wc[ix].wc_id;
ASSERT(bp->buf_state == RDS_SNDBUF_PENDING);
bp->buf_state = RDS_SNDBUF_FREE;
} else if (wc[ix].wc_status == IBT_WC_WR_FLUSHED_ERR) {
RDS_INCR_TXERRS();
RDS_DPRINTF5("rds_poll_send_completions",
"EP(%p): WC ID: %p ERROR: %d", ep,
wc[ix].wc_id, wc[ix].wc_status);
send_error = 1;
if (wc[ix].wc_id == RDS_RDMAW_WRID) {
mutex_enter(&ep->ep_lock);
ep->ep_rdmacnt--;
mutex_exit(&ep->ep_lock);
continue;
}
bp = (rds_buf_t *)(uintptr_t)wc[ix].wc_id;
ASSERT(bp->buf_state == RDS_SNDBUF_PENDING);
bp->buf_state = RDS_SNDBUF_FREE;
} else {
RDS_INCR_TXERRS();
RDS_DPRINTF2("rds_poll_send_completions",
"EP(%p): WC ID: %p ERROR: %d", ep,
wc[ix].wc_id, wc[ix].wc_status);
if (send_error == 0) {
rds_session_t *sp = ep->ep_sp;
/* don't let anyone send anymore */
rw_enter(&sp->session_lock, RW_WRITER);
if (sp->session_state !=
RDS_SESSION_STATE_ERROR) {
sp->session_state =
RDS_SESSION_STATE_ERROR;
/* Make this the active end */
sp->session_type =
RDS_SESSION_ACTIVE;
}
rw_exit(&sp->session_lock);
}
send_error = 1;
if (wc[ix].wc_id == RDS_RDMAW_WRID) {
mutex_enter(&ep->ep_lock);
ep->ep_rdmacnt--;
mutex_exit(&ep->ep_lock);
continue;
}
bp = (rds_buf_t *)(uintptr_t)wc[ix].wc_id;
ASSERT(bp->buf_state == RDS_SNDBUF_PENDING);
bp->buf_state = RDS_SNDBUF_FREE;
}
bp->buf_nextp = NULL;
if (headp) {
tailp->buf_nextp = bp;
tailp = bp;
} else {
headp = bp;
tailp = bp;
}
npolled++;
}
if (rds_no_interrupts && (npolled > 100)) {
break;
}
if (rds_no_interrupts == 1) {
break;
}
} while (ret != IBT_CQ_EMPTY);
RDS_DPRINTF5("rds_poll_send_completions", "Npolled: %d send_error: %d",
npolled, send_error);
/* put the buffers to the pool */
if (npolled != 0) {
rds_free_send_buf(ep, headp, tailp, npolled, lock);
}
if (send_error != 0) {
rds_handle_send_error(ep);
}
RDS_DPRINTF4("rds_poll_send_completions", "Return EP(%p)", ep);
}
void
rds_sendcq_handler(ibt_cq_hdl_t cq, void *arg)
{
rds_ep_t *ep;
int ret;
ep = (rds_ep_t *)arg;
RDS_DPRINTF4("rds_sendcq_handler", "Enter: EP(%p)", ep);
/* enable the CQ */
ret = ibt_enable_cq_notify(cq, IBT_NEXT_COMPLETION);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL, "EP(%p) CQ(%p): ibt_enable_cq_notify "
"failed: %d", ep, cq, ret);
return;
}
rds_poll_send_completions(cq, ep, B_FALSE);
RDS_DPRINTF4("rds_sendcq_handler", "Return: EP(%p)", ep);
}
void
rds_ep_free_rc_channel(rds_ep_t *ep)
{
int ret;
RDS_DPRINTF2("rds_ep_free_rc_channel", "EP(%p) - Enter", ep);
ASSERT(mutex_owned(&ep->ep_lock));
/* free the QP */
if (ep->ep_chanhdl != NULL) {
/* wait until the RQ is empty */
(void) ibt_flush_channel(ep->ep_chanhdl);
(void) rds_is_recvq_empty(ep, B_TRUE);
ret = ibt_free_channel(ep->ep_chanhdl);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rds_ep_free_rc_channel", "EP(%p) "
"ibt_free_channel returned: %d", ep, ret);
}
ep->ep_chanhdl = NULL;
} else {
RDS_DPRINTF2("rds_ep_free_rc_channel",
"EP(%p) Channel is ALREADY FREE", ep);
}
/* free the Send CQ */
if (ep->ep_sendcq != NULL) {
ret = ibt_free_cq(ep->ep_sendcq);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rds_ep_free_rc_channel",
"EP(%p) - for sendcq, ibt_free_cq returned %d",
ep, ret);
}
ep->ep_sendcq = NULL;
} else {
RDS_DPRINTF2("rds_ep_free_rc_channel",
"EP(%p) SendCQ is ALREADY FREE", ep);
}
/* free the Recv CQ */
if (ep->ep_recvcq != NULL) {
ret = ibt_free_cq(ep->ep_recvcq);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rds_ep_free_rc_channel",
"EP(%p) - for recvcq, ibt_free_cq returned %d",
ep, ret);
}
ep->ep_recvcq = NULL;
} else {
RDS_DPRINTF2("rds_ep_free_rc_channel",
"EP(%p) RecvCQ is ALREADY FREE", ep);
}
RDS_DPRINTF2("rds_ep_free_rc_channel", "EP(%p) - Return", ep);
}
/* Allocate resources for RC channel */
ibt_channel_hdl_t
rds_ep_alloc_rc_channel(rds_ep_t *ep, uint8_t hca_port)
{
int ret = IBT_SUCCESS;
ibt_cq_attr_t scqattr, rcqattr;
ibt_rc_chan_alloc_args_t chanargs;
ibt_channel_hdl_t chanhdl;
rds_session_t *sp;
rds_hca_t *hcap;
RDS_DPRINTF4("rds_ep_alloc_rc_channel", "Enter: 0x%p port: %d",
ep, hca_port);
/* Update the EP with the right IP address and HCA guid */
sp = ep->ep_sp;
ASSERT(sp != NULL);
rw_enter(&sp->session_lock, RW_READER);
mutex_enter(&ep->ep_lock);
ep->ep_myip = sp->session_myip;
ep->ep_remip = sp->session_remip;
hcap = rds_gid_to_hcap(rdsib_statep, sp->session_lgid);
ep->ep_hca_guid = hcap->hca_guid;
mutex_exit(&ep->ep_lock);
rw_exit(&sp->session_lock);
/* reset taskqpending flag here */
ep->ep_recvqp.qp_taskqpending = B_FALSE;
if (ep->ep_type == RDS_EP_TYPE_CTRL) {
scqattr.cq_size = MaxCtrlSendBuffers;
scqattr.cq_sched = NULL;
scqattr.cq_flags = IBT_CQ_NO_FLAGS;
rcqattr.cq_size = MaxCtrlRecvBuffers;
rcqattr.cq_sched = NULL;
rcqattr.cq_flags = IBT_CQ_NO_FLAGS;
chanargs.rc_sizes.cs_sq = MaxCtrlSendBuffers;
chanargs.rc_sizes.cs_rq = MaxCtrlRecvBuffers;
chanargs.rc_sizes.cs_sq_sgl = 1;
chanargs.rc_sizes.cs_rq_sgl = 1;
} else {
scqattr.cq_size = MaxDataSendBuffers + RDS_NUM_ACKS;
scqattr.cq_sched = NULL;
scqattr.cq_flags = IBT_CQ_NO_FLAGS;
rcqattr.cq_size = MaxDataRecvBuffers;
rcqattr.cq_sched = NULL;
rcqattr.cq_flags = IBT_CQ_NO_FLAGS;
chanargs.rc_sizes.cs_sq = MaxDataSendBuffers + RDS_NUM_ACKS;
chanargs.rc_sizes.cs_rq = MaxDataRecvBuffers;
chanargs.rc_sizes.cs_sq_sgl = 1;
chanargs.rc_sizes.cs_rq_sgl = 1;
}
mutex_enter(&ep->ep_lock);
if (ep->ep_sendcq == NULL) {
/* returned size is always greater than the requested size */
ret = ibt_alloc_cq(hcap->hca_hdl, &scqattr,
&ep->ep_sendcq, NULL);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL, "ibt_alloc_cq for sendCQ "
"failed, size = %d: %d", scqattr.cq_size, ret);
mutex_exit(&ep->ep_lock);
return (NULL);
}
(void) ibt_set_cq_handler(ep->ep_sendcq, rds_sendcq_handler,
ep);
if (rds_no_interrupts == 0) {
ret = ibt_enable_cq_notify(ep->ep_sendcq,
IBT_NEXT_COMPLETION);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL,
"ibt_enable_cq_notify failed: %d", ret);
(void) ibt_free_cq(ep->ep_sendcq);
ep->ep_sendcq = NULL;
mutex_exit(&ep->ep_lock);
return (NULL);
}
}
}
if (ep->ep_recvcq == NULL) {
/* returned size is always greater than the requested size */
ret = ibt_alloc_cq(hcap->hca_hdl, &rcqattr,
&ep->ep_recvcq, NULL);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL, "ibt_alloc_cq for recvCQ "
"failed, size = %d: %d", rcqattr.cq_size, ret);
(void) ibt_free_cq(ep->ep_sendcq);
ep->ep_sendcq = NULL;
mutex_exit(&ep->ep_lock);
return (NULL);
}
(void) ibt_set_cq_handler(ep->ep_recvcq, rds_recvcq_handler,
ep);
ret = ibt_enable_cq_notify(ep->ep_recvcq, rds_wc_signal);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL,
"ibt_enable_cq_notify failed: %d", ret);
(void) ibt_free_cq(ep->ep_recvcq);
ep->ep_recvcq = NULL;
(void) ibt_free_cq(ep->ep_sendcq);
ep->ep_sendcq = NULL;
mutex_exit(&ep->ep_lock);
return (NULL);
}
}
chanargs.rc_flags = IBT_ALL_SIGNALED;
chanargs.rc_control = IBT_CEP_RDMA_RD | IBT_CEP_RDMA_WR |
IBT_CEP_ATOMIC;
chanargs.rc_hca_port_num = hca_port;
chanargs.rc_scq = ep->ep_sendcq;
chanargs.rc_rcq = ep->ep_recvcq;
chanargs.rc_pd = hcap->hca_pdhdl;
chanargs.rc_srq = NULL;
ret = ibt_alloc_rc_channel(hcap->hca_hdl,
IBT_ACHAN_NO_FLAGS, &chanargs, &chanhdl, NULL);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL, "ibt_alloc_rc_channel fail: %d",
ret);
(void) ibt_free_cq(ep->ep_recvcq);
ep->ep_recvcq = NULL;
(void) ibt_free_cq(ep->ep_sendcq);
ep->ep_sendcq = NULL;
mutex_exit(&ep->ep_lock);
return (NULL);
}
mutex_exit(&ep->ep_lock);
/* Chan private should contain the ep */
(void) ibt_set_chan_private(chanhdl, ep);
RDS_DPRINTF4("rds_ep_alloc_rc_channel", "Return: 0x%p", chanhdl);
return (chanhdl);
}
#if 0
/* Return node guid given a port gid */
ib_guid_t
rds_gid_to_node_guid(ib_gid_t gid)
{
ibt_node_info_t nodeinfo;
int ret;
RDS_DPRINTF4("rds_gid_to_node_guid", "Enter: gid: %llx:%llx",
gid.gid_prefix, gid.gid_guid);
ret = ibt_gid_to_node_info(gid, &nodeinfo);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL, "ibt_gid_node_info for gid: %llx:%llx "
"failed", gid.gid_prefix, gid.gid_guid);
return (0LL);
}
RDS_DPRINTF4("rds_gid_to_node_guid", "Return: Node guid: %llx",
nodeinfo.n_node_guid);
return (nodeinfo.n_node_guid);
}
#endif
static void
rds_handle_portup_event(rds_state_t *statep, ibt_hca_hdl_t hdl,
ibt_async_event_t *event)
{
rds_hca_t *hcap;
ibt_hca_portinfo_t *newpinfop, *oldpinfop;
uint_t newsize, oldsize, nport;
ib_gid_t gid;
int ret;
RDS_DPRINTF2("rds_handle_portup_event",
"Enter: GUID: 0x%llx Statep: %p", event->ev_hca_guid, statep);
rw_enter(&statep->rds_hca_lock, RW_WRITER);
hcap = statep->rds_hcalistp;
while ((hcap != NULL) && (hcap->hca_guid != event->ev_hca_guid)) {
hcap = hcap->hca_nextp;
}
if (hcap == NULL) {
RDS_DPRINTF2("rds_handle_portup_event", "HCA: 0x%llx is "
"not in our list", event->ev_hca_guid);
rw_exit(&statep->rds_hca_lock);
return;
}
ret = ibt_query_hca_ports(hdl, 0, &newpinfop, &nport, &newsize);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2(LABEL, "ibt_query_hca_ports failed: %d", ret);
rw_exit(&statep->rds_hca_lock);
return;
}
oldpinfop = hcap->hca_pinfop;
oldsize = hcap->hca_pinfo_sz;
hcap->hca_pinfop = newpinfop;
hcap->hca_pinfo_sz = newsize;
(void) ibt_free_portinfo(oldpinfop, oldsize);
/* If RDS service is not registered then no bind is needed */
if (statep->rds_srvhdl == NULL) {
RDS_DPRINTF2("rds_handle_portup_event",
"RDS Service is not registered, so no action needed");
rw_exit(&statep->rds_hca_lock);
return;
}
/*
* If the service was previously bound on this port and
* if this port has changed state down and now up, we do not
* need to bind the service again. The bind is expected to
* persist across state changes. If the service was never bound
* before then we bind it this time.
*/
if (hcap->hca_bindhdl[event->ev_port - 1] == NULL) {
/* structure copy */
gid = newpinfop[event->ev_port - 1].p_sgid_tbl[0];
/* bind RDS service on the port, pass statep as cm_private */
ret = ibt_bind_service(statep->rds_srvhdl, gid, NULL, statep,
&hcap->hca_bindhdl[event->ev_port - 1]);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rds_handle_portup_event",
"Bind service for HCA: 0x%llx Port: %d "
"gid %llx:%llx returned: %d", event->ev_hca_guid,
event->ev_port, gid.gid_prefix, gid.gid_guid, ret);
}
}
rw_exit(&statep->rds_hca_lock);
RDS_DPRINTF2("rds_handle_portup_event", "Return: GUID: 0x%llx",
event->ev_hca_guid);
}
static void
rdsib_add_hca(ib_guid_t hca_guid)
{
rds_hca_t *hcap;
ibt_mr_attr_t mem_attr;
ibt_mr_desc_t mem_desc;
int ret;
RDS_DPRINTF2("rdsib_add_hca", "Enter: GUID: 0x%llx", hca_guid);
hcap = rdsib_init_hca(hca_guid);
if (hcap == NULL)
return;
/* register the recv memory with this hca */
mutex_enter(&rds_dpool.pool_lock);
if (rds_dpool.pool_memp == NULL) {
/* no memory to register */
RDS_DPRINTF2("rdsib_add_hca", "No memory to register");
mutex_exit(&rds_dpool.pool_lock);
return;
}
mem_attr.mr_vaddr = (ib_vaddr_t)(uintptr_t)rds_dpool.pool_memp;
mem_attr.mr_len = rds_dpool.pool_memsize;
mem_attr.mr_as = NULL;
mem_attr.mr_flags = IBT_MR_ENABLE_LOCAL_WRITE;
ret = ibt_register_mr(hcap->hca_hdl, hcap->hca_pdhdl, &mem_attr,
&hcap->hca_mrhdl, &mem_desc);
mutex_exit(&rds_dpool.pool_lock);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rdsib_add_hca", "ibt_register_mr failed: %d",
ret);
} else {
rw_enter(&rdsib_statep->rds_hca_lock, RW_WRITER);
hcap->hca_state = RDS_HCA_STATE_MEM_REGISTERED;
hcap->hca_lkey = mem_desc.md_lkey;
hcap->hca_rkey = mem_desc.md_rkey;
rw_exit(&rdsib_statep->rds_hca_lock);
}
RDS_DPRINTF2("rdsib_add_hca", "Retrun: GUID: 0x%llx", hca_guid);
}
void rds_close_this_session(rds_session_t *sp, uint8_t wait);
int rds_post_control_message(rds_session_t *sp, uint8_t code, in_port_t port);
static void
rdsib_del_hca(rds_state_t *statep, ib_guid_t hca_guid)
{
rds_session_t *sp;
rds_hca_t *hcap;
rds_hca_state_t saved_state;
int ret, ix;
RDS_DPRINTF2("rdsib_del_hca", "Enter: GUID: 0x%llx", hca_guid);
/*
* This should be a write lock as we don't want anyone to get access
* to the hcap while we are modifing its contents
*/
rw_enter(&statep->rds_hca_lock, RW_WRITER);
hcap = statep->rds_hcalistp;
while ((hcap != NULL) && (hcap->hca_guid != hca_guid)) {
hcap = hcap->hca_nextp;
}
/* Prevent initiating any new activity on this HCA */
ASSERT(hcap != NULL);
saved_state = hcap->hca_state;
hcap->hca_state = RDS_HCA_STATE_STOPPING;
rw_exit(&statep->rds_hca_lock);
/*
* stop the outgoing traffic and close any active sessions on this hca.
* Any pending messages in the SQ will be allowed to complete.
*/
rw_enter(&statep->rds_sessionlock, RW_READER);
sp = statep->rds_sessionlistp;
while (sp) {
if (sp->session_hca_guid != hca_guid) {
sp = sp->session_nextp;
continue;
}
rw_enter(&sp->session_lock, RW_WRITER);
RDS_DPRINTF2("rdsib_del_hca", "SP(%p) State: %d", sp,
sp->session_state);
/*
* We are changing the session state in advance. This prevents
* further messages to be posted to the SQ. We then
* send a control message to the remote and tell it close
* the session.
*/
sp->session_state = RDS_SESSION_STATE_HCA_CLOSING;
RDS_DPRINTF3("rds_handle_cm_conn_closed", "SP(%p) State "
"RDS_SESSION_STATE_PASSIVE_CLOSING", sp);
rw_exit(&sp->session_lock);
/*
* wait until the sendq is empty then tell the remote to
* close this session. This enables for graceful shutdown of
* the session
*/
(void) rds_is_sendq_empty(&sp->session_dataep, 2);
(void) rds_post_control_message(sp,
RDS_CTRL_CODE_CLOSE_SESSION, 0);
sp = sp->session_nextp;
}
/* wait until all the sessions are off this HCA */
sp = statep->rds_sessionlistp;
while (sp) {
if (sp->session_hca_guid != hca_guid) {
sp = sp->session_nextp;
continue;
}
rw_enter(&sp->session_lock, RW_READER);
RDS_DPRINTF2("rdsib_del_hca", "SP(%p) State: %d", sp,
sp->session_state);
while ((sp->session_state == RDS_SESSION_STATE_HCA_CLOSING) ||
(sp->session_state == RDS_SESSION_STATE_ERROR) ||
(sp->session_state == RDS_SESSION_STATE_PASSIVE_CLOSING) ||
(sp->session_state == RDS_SESSION_STATE_CLOSED)) {
rw_exit(&sp->session_lock);
delay(drv_usectohz(1000000));
rw_enter(&sp->session_lock, RW_READER);
RDS_DPRINTF2("rdsib_del_hca", "SP(%p) State: %d", sp,
sp->session_state);
}
rw_exit(&sp->session_lock);
sp = sp->session_nextp;
}
rw_exit(&statep->rds_sessionlock);
/*
* if rdsib_close_ib was called before this, then that would have
* unbound the service on all ports. In that case, the HCA structs
* will contain stale bindhdls. Hence, we do not call unbind unless
* the service is still registered.
*/
if (statep->rds_srvhdl != NULL) {
/* unbind RDS service on all ports on this HCA */
for (ix = 0; ix < hcap->hca_nports; ix++) {
if (hcap->hca_bindhdl[ix] == NULL) {
continue;
}
RDS_DPRINTF2("rdsib_del_hca",
"Unbinding Service: port: %d, bindhdl: %p",
ix + 1, hcap->hca_bindhdl[ix]);
(void) ibt_unbind_service(rdsib_statep->rds_srvhdl,
hcap->hca_bindhdl[ix]);
hcap->hca_bindhdl[ix] = NULL;
}
}
RDS_DPRINTF2("rdsib_del_hca", "HCA(%p) State: %d", hcap,
hcap->hca_state);
switch (saved_state) {
case RDS_HCA_STATE_MEM_REGISTERED:
ASSERT(hcap->hca_mrhdl != NULL);
ret = ibt_deregister_mr(hcap->hca_hdl, hcap->hca_mrhdl);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rdsib_del_hca",
"ibt_deregister_mr failed: %d", ret);
return;
}
hcap->hca_mrhdl = NULL;
/* FALLTHRU */
case RDS_HCA_STATE_OPEN:
ASSERT(hcap->hca_hdl != NULL);
ASSERT(hcap->hca_pdhdl != NULL);
ret = ibt_free_pd(hcap->hca_hdl, hcap->hca_pdhdl);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rdsib_del_hca",
"ibt_free_pd failed: %d", ret);
}
(void) ibt_free_portinfo(hcap->hca_pinfop, hcap->hca_pinfo_sz);
ret = ibt_close_hca(hcap->hca_hdl);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rdsib_del_hca",
"ibt_close_hca failed: %d", ret);
}
hcap->hca_hdl = NULL;
hcap->hca_pdhdl = NULL;
hcap->hca_lkey = 0;
hcap->hca_rkey = 0;
}
/*
* This should be a write lock as we don't want anyone to get access
* to the hcap while we are modifing its contents
*/
rw_enter(&statep->rds_hca_lock, RW_WRITER);
hcap->hca_state = RDS_HCA_STATE_REMOVED;
rw_exit(&statep->rds_hca_lock);
RDS_DPRINTF2("rdsib_del_hca", "Return: GUID: 0x%llx", hca_guid);
}
static void
rds_async_handler(void *clntp, ibt_hca_hdl_t hdl, ibt_async_code_t code,
ibt_async_event_t *event)
{
rds_state_t *statep = (rds_state_t *)clntp;
RDS_DPRINTF2("rds_async_handler", "Async code: %d", code);
switch (code) {
case IBT_EVENT_PORT_UP:
rds_handle_portup_event(statep, hdl, event);
break;
case IBT_HCA_ATTACH_EVENT:
/*
* NOTE: In some error recovery paths, it is possible to
* receive IBT_HCA_ATTACH_EVENTs on already known HCAs.
*/
(void) rdsib_add_hca(event->ev_hca_guid);
break;
case IBT_HCA_DETACH_EVENT:
(void) rdsib_del_hca(statep, event->ev_hca_guid);
break;
default:
RDS_DPRINTF2(LABEL, "Async event: %d not handled", code);
}
RDS_DPRINTF2("rds_async_handler", "Return: code: %d", code);
}
/*
* This routine exists to minimize stale connections across ungraceful
* reboots of nodes in a cluster.
*/
void
rds_randomize_qps(rds_hca_t *hcap)
{
ibt_cq_attr_t cqattr;
ibt_rc_chan_alloc_args_t chanargs;
ibt_channel_hdl_t qp1, qp2;
ibt_cq_hdl_t cq_hdl;
hrtime_t nsec;
uint8_t i, j, rand1, rand2;
int ret;
bzero(&cqattr, sizeof (ibt_cq_attr_t));
cqattr.cq_size = 1;
cqattr.cq_sched = NULL;
cqattr.cq_flags = IBT_CQ_NO_FLAGS;
ret = ibt_alloc_cq(hcap->hca_hdl, &cqattr, &cq_hdl, NULL);
if (ret != IBT_SUCCESS) {
RDS_DPRINTF2("rds_randomize_qps",
"ibt_alloc_cq failed: %d", ret);
return;
}
bzero(&chanargs, sizeof (ibt_rc_chan_alloc_args_t));
chanargs.rc_flags = IBT_ALL_SIGNALED;
chanargs.rc_control = IBT_CEP_RDMA_RD | IBT_CEP_RDMA_WR |
IBT_CEP_ATOMIC;
chanargs.rc_hca_port_num = 1;
chanargs.rc_scq = cq_hdl;
chanargs.rc_rcq = cq_hdl;
chanargs.rc_pd = hcap->hca_pdhdl;
chanargs.rc_srq = NULL;
nsec = gethrtime();
rand1 = (nsec & 0xF);
rand2 = (nsec >> 4) & 0xF;
RDS_DPRINTF2("rds_randomize_qps", "rand1: %d rand2: %d",
rand1, rand2);
for (i = 0; i < rand1 + 3; i++) {
if (ibt_alloc_rc_channel(hcap->hca_hdl,
IBT_ACHAN_NO_FLAGS, &chanargs, &qp1, NULL) !=
IBT_SUCCESS) {
RDS_DPRINTF2("rds_randomize_qps",
"Bailing at i: %d", i);
(void) ibt_free_cq(cq_hdl);
return;
}
for (j = 0; j < rand2 + 3; j++) {
if (ibt_alloc_rc_channel(hcap->hca_hdl,
IBT_ACHAN_NO_FLAGS, &chanargs, &qp2,
NULL) != IBT_SUCCESS) {
RDS_DPRINTF2("rds_randomize_qps",
"Bailing at i: %d j: %d", i, j);
(void) ibt_free_channel(qp1);
(void) ibt_free_cq(cq_hdl);
return;
}
(void) ibt_free_channel(qp2);
}
(void) ibt_free_channel(qp1);
}
(void) ibt_free_cq(cq_hdl);
}
|