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
|
/*
* 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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <sys/ib/ibtl/impl/ibtl.h>
#include <sys/ib/ibtl/impl/ibtl_cm.h>
#include <sys/taskq.h>
#include <sys/disp.h>
#include <sys/callb.h>
#include <sys/proc.h>
/*
* ibtl_handlers.c
*/
/*
* What's in this file?
*
* This file started as an implementation of Asynchronous Event/Error
* handling and Completion Queue handling. As the implementation
* evolved, code has been added for other ibc_* interfaces (resume,
* predetach, etc.) that use the same mechanisms as used for asyncs.
*
* Async and CQ handling at interrupt level.
*
* CQ handling is normally done at interrupt level using the CQ callback
* handler to call the appropriate IBT Client (owner of the CQ). For
* clients that would prefer a fully flexible non-interrupt context to
* do their CQ handling, a CQ can be created so that its handler is
* called from a non-interrupt thread. CQ handling is done frequently
* whereas Async handling is expected to occur very infrequently.
*
* Async handling is done by marking (or'ing in of an async_code of) the
* pertinent IBTL data structure, and then notifying the async_thread(s)
* that the data structure has async work to be done. The notification
* occurs by linking the data structure through its async_link onto a
* list of like data structures and waking up an async_thread. This
* list append is not done if there is already async work pending on
* this data structure (IBTL_ASYNC_PENDING).
*
* Async Mutex and CQ Mutex
*
* The global ibtl_async_mutex is "the" mutex used to control access
* to all the data needed by ibc_async_handler. All the threads that
* use this mutex are written so that the mutex is held for very short
* periods of time, and never held while making calls to functions
* that may block.
*
* The global ibtl_cq_mutex is used similarly by ibc_cq_handler and
* the ibtl_cq_thread(s).
*
* Mutex hierarchy
*
* The ibtl_clnt_list_mutex is above the ibtl_async_mutex.
* ibtl_clnt_list_mutex protects all of the various lists.
* The ibtl_async_mutex is below this in the hierarchy.
*
* The ibtl_cq_mutex is independent of the above mutexes.
*
* Threads
*
* There are "ibtl_cq_threads" number of threads created for handling
* Completion Queues in threads. If this feature really gets used,
* then we will want to do some suitable tuning. Similarly, we may
* want to tune the number of "ibtl_async_thread_init".
*
* The function ibtl_cq_thread is the main loop for handling a CQ in a
* thread. There can be multiple threads executing this same code.
* The code sleeps when there is no work to be done (list is empty),
* otherwise it pulls the first CQ structure off the list and performs
* the CQ handler callback to the client. After that returns, a check
* is made, and if another ibc_cq_handler call was made for this CQ,
* the client is called again.
*
* The function ibtl_async_thread is the main loop for handling async
* events/errors. There can be multiple threads executing this same code.
* The code sleeps when there is no work to be done (lists are empty),
* otherwise it pulls the first structure off one of the lists and
* performs the async callback(s) to the client(s). Note that HCA
* async handling is done by calling each of the clients using the HCA.
* When the async handling completes, the data structure having the async
* event/error is checked for more work before it's considered "done".
*
* Taskq
*
* The async_taskq is used here for allowing async handler callbacks to
* occur simultaneously to multiple clients of an HCA. This taskq could
* be used for other purposes, e.g., if all the async_threads are in
* use, but this is deemed as overkill since asyncs should occur rarely.
*/
/* Globals */
static char ibtf_handlers[] = "ibtl_handlers";
/* priority for IBTL threads (async, cq, and taskq) */
static pri_t ibtl_pri = MAXCLSYSPRI - 1; /* maybe override in /etc/system */
/* taskq used for HCA asyncs */
#define ibtl_async_taskq system_taskq
/* data for async handling by threads */
static kmutex_t ibtl_async_mutex; /* protects most *_async_* data */
static kcondvar_t ibtl_async_cv; /* async_threads wait on this */
static kcondvar_t ibtl_clnt_cv; /* ibt_detach might wait on this */
static void ibtl_dec_clnt_async_cnt(ibtl_clnt_t *clntp);
static void ibtl_inc_clnt_async_cnt(ibtl_clnt_t *clntp);
static kt_did_t *ibtl_async_did; /* for thread_join() */
int ibtl_async_thread_init = 4; /* total # of async_threads to create */
static int ibtl_async_thread_exit = 0; /* set if/when thread(s) should exit */
/* async lists for various structures */
static ibtl_hca_devinfo_t *ibtl_async_hca_list_start, *ibtl_async_hca_list_end;
static ibtl_eec_t *ibtl_async_eec_list_start, *ibtl_async_eec_list_end;
static ibtl_qp_t *ibtl_async_qp_list_start, *ibtl_async_qp_list_end;
static ibtl_cq_t *ibtl_async_cq_list_start, *ibtl_async_cq_list_end;
static ibtl_srq_t *ibtl_async_srq_list_start, *ibtl_async_srq_list_end;
/* data for CQ completion handling by threads */
static kmutex_t ibtl_cq_mutex; /* protects the cv and the list below */
static kcondvar_t ibtl_cq_cv;
static ibtl_cq_t *ibtl_cq_list_start, *ibtl_cq_list_end;
static int ibtl_cq_threads = 0; /* total # of cq threads */
static int ibtl_cqs_using_threads = 0; /* total # of cqs using threads */
static int ibtl_cq_thread_exit = 0; /* set if/when thread(s) should exit */
/* value used to tell IBTL threads to exit */
#define IBTL_THREAD_EXIT 0x1b7fdead /* IBTF DEAD */
/* Cisco Topspin Vendor ID for Rereg hack */
#define IBT_VENDOR_CISCO 0x05ad
int ibtl_eec_not_supported = 1;
char *ibtl_last_client_name; /* may help debugging */
typedef ibt_status_t (*ibtl_node_info_cb_t)(ib_guid_t, uint8_t, ib_lid_t,
ibt_node_info_t *);
ibtl_node_info_cb_t ibtl_node_info_cb;
_NOTE(LOCK_ORDER(ibtl_clnt_list_mutex ibtl_async_mutex))
void
ibtl_cm_set_node_info_cb(ibt_status_t (*node_info_cb)(ib_guid_t, uint8_t,
ib_lid_t, ibt_node_info_t *))
{
mutex_enter(&ibtl_clnt_list_mutex);
ibtl_node_info_cb = node_info_cb;
mutex_exit(&ibtl_clnt_list_mutex);
}
/*
* ibc_async_handler()
*
* Asynchronous Event/Error Handler.
*
* This is the function called HCA drivers to post various async
* event and errors mention in the IB architecture spec. See
* ibtl_types.h for additional details of this.
*
* This function marks the pertinent IBTF object with the async_code,
* and queues the object for handling by an ibtl_async_thread. If
* the object is NOT already marked for async processing, it is added
* to the associated list for that type of object, and an
* ibtl_async_thread is signaled to finish the async work.
*/
void
ibc_async_handler(ibc_clnt_hdl_t hca_devp, ibt_async_code_t code,
ibc_async_event_t *event_p)
{
ibtl_qp_t *ibtl_qp;
ibtl_cq_t *ibtl_cq;
ibtl_srq_t *ibtl_srq;
ibtl_eec_t *ibtl_eec;
uint8_t port_minus1;
ibtl_async_port_event_t *portp;
IBTF_DPRINTF_L2(ibtf_handlers, "ibc_async_handler(%p, 0x%x, %p)",
hca_devp, code, event_p);
mutex_enter(&ibtl_async_mutex);
switch (code) {
case IBT_EVENT_PATH_MIGRATED_QP:
case IBT_EVENT_SQD:
case IBT_ERROR_CATASTROPHIC_QP:
case IBT_ERROR_PATH_MIGRATE_REQ_QP:
case IBT_EVENT_COM_EST_QP:
case IBT_ERROR_INVALID_REQUEST_QP:
case IBT_ERROR_ACCESS_VIOLATION_QP:
case IBT_EVENT_EMPTY_QP:
case IBT_FEXCH_ERROR:
ibtl_qp = event_p->ev_qp_hdl;
if (ibtl_qp == NULL) {
IBTF_DPRINTF_L2(ibtf_handlers, "ibc_async_handler: "
"bad qp handle");
break;
}
switch (code) {
case IBT_ERROR_CATASTROPHIC_QP:
ibtl_qp->qp_cat_fma_ena = event_p->ev_fma_ena; break;
case IBT_ERROR_PATH_MIGRATE_REQ_QP:
ibtl_qp->qp_pth_fma_ena = event_p->ev_fma_ena; break;
case IBT_ERROR_INVALID_REQUEST_QP:
ibtl_qp->qp_inv_fma_ena = event_p->ev_fma_ena; break;
case IBT_ERROR_ACCESS_VIOLATION_QP:
ibtl_qp->qp_acc_fma_ena = event_p->ev_fma_ena; break;
}
ibtl_qp->qp_async_codes |= code;
if ((ibtl_qp->qp_async_flags & IBTL_ASYNC_PENDING) == 0) {
ibtl_qp->qp_async_flags |= IBTL_ASYNC_PENDING;
ibtl_qp->qp_async_link = NULL;
if (ibtl_async_qp_list_end == NULL)
ibtl_async_qp_list_start = ibtl_qp;
else
ibtl_async_qp_list_end->qp_async_link = ibtl_qp;
ibtl_async_qp_list_end = ibtl_qp;
cv_signal(&ibtl_async_cv);
}
break;
case IBT_ERROR_CQ:
ibtl_cq = event_p->ev_cq_hdl;
if (ibtl_cq == NULL) {
IBTF_DPRINTF_L2(ibtf_handlers, "ibc_async_handler: "
"bad cq handle");
break;
}
ibtl_cq->cq_async_codes |= code;
ibtl_cq->cq_fma_ena = event_p->ev_fma_ena;
if ((ibtl_cq->cq_async_flags & IBTL_ASYNC_PENDING) == 0) {
ibtl_cq->cq_async_flags |= IBTL_ASYNC_PENDING;
ibtl_cq->cq_async_link = NULL;
if (ibtl_async_cq_list_end == NULL)
ibtl_async_cq_list_start = ibtl_cq;
else
ibtl_async_cq_list_end->cq_async_link = ibtl_cq;
ibtl_async_cq_list_end = ibtl_cq;
cv_signal(&ibtl_async_cv);
}
break;
case IBT_ERROR_CATASTROPHIC_SRQ:
case IBT_EVENT_LIMIT_REACHED_SRQ:
ibtl_srq = event_p->ev_srq_hdl;
if (ibtl_srq == NULL) {
IBTF_DPRINTF_L2(ibtf_handlers, "ibc_async_handler: "
"bad srq handle");
break;
}
ibtl_srq->srq_async_codes |= code;
ibtl_srq->srq_fma_ena = event_p->ev_fma_ena;
if ((ibtl_srq->srq_async_flags & IBTL_ASYNC_PENDING) == 0) {
ibtl_srq->srq_async_flags |= IBTL_ASYNC_PENDING;
ibtl_srq->srq_async_link = NULL;
if (ibtl_async_srq_list_end == NULL)
ibtl_async_srq_list_start = ibtl_srq;
else
ibtl_async_srq_list_end->srq_async_link =
ibtl_srq;
ibtl_async_srq_list_end = ibtl_srq;
cv_signal(&ibtl_async_cv);
}
break;
case IBT_EVENT_PATH_MIGRATED_EEC:
case IBT_ERROR_PATH_MIGRATE_REQ_EEC:
case IBT_ERROR_CATASTROPHIC_EEC:
case IBT_EVENT_COM_EST_EEC:
if (ibtl_eec_not_supported) {
IBTF_DPRINTF_L2(ibtf_handlers, "ibc_async_handler: "
"EEC events are disabled.");
break;
}
ibtl_eec = event_p->ev_eec_hdl;
if (ibtl_eec == NULL) {
IBTF_DPRINTF_L2(ibtf_handlers, "ibc_async_handler: "
"bad eec handle");
break;
}
switch (code) {
case IBT_ERROR_PATH_MIGRATE_REQ_EEC:
ibtl_eec->eec_pth_fma_ena = event_p->ev_fma_ena; break;
case IBT_ERROR_CATASTROPHIC_EEC:
ibtl_eec->eec_cat_fma_ena = event_p->ev_fma_ena; break;
}
ibtl_eec->eec_async_codes |= code;
if ((ibtl_eec->eec_async_flags & IBTL_ASYNC_PENDING) == 0) {
ibtl_eec->eec_async_flags |= IBTL_ASYNC_PENDING;
ibtl_eec->eec_async_link = NULL;
if (ibtl_async_eec_list_end == NULL)
ibtl_async_eec_list_start = ibtl_eec;
else
ibtl_async_eec_list_end->eec_async_link =
ibtl_eec;
ibtl_async_eec_list_end = ibtl_eec;
cv_signal(&ibtl_async_cv);
}
break;
case IBT_ERROR_LOCAL_CATASTROPHIC:
hca_devp->hd_async_codes |= code;
hca_devp->hd_fma_ena = event_p->ev_fma_ena;
/* FALLTHROUGH */
case IBT_EVENT_PORT_UP:
case IBT_PORT_CHANGE_EVENT:
case IBT_CLNT_REREG_EVENT:
case IBT_ERROR_PORT_DOWN:
if ((code & IBT_PORT_EVENTS) != 0) {
if ((port_minus1 = event_p->ev_port - 1) >=
hca_devp->hd_hca_attr->hca_nports) {
IBTF_DPRINTF_L2(ibtf_handlers,
"ibc_async_handler: bad port #: %d",
event_p->ev_port);
break;
}
portp = &hca_devp->hd_async_port[port_minus1];
if (code == IBT_EVENT_PORT_UP) {
/*
* The port is just coming UP we can't have any
* valid older events.
*/
portp->status = IBTL_HCA_PORT_UP;
} else if (code == IBT_ERROR_PORT_DOWN) {
/*
* The port is going DOWN older events don't
* count.
*/
portp->status = IBTL_HCA_PORT_DOWN;
} else if (code == IBT_PORT_CHANGE_EVENT) {
/*
* For port UP and DOWN events only the latest
* event counts. If we get a UP after DOWN it
* is sufficient to send just UP and vice versa.
* In the case of port CHANGE event it is valid
* only when the port is UP already but if we
* receive it after UP but before UP is
* delivered we still need to deliver CHANGE
* after we deliver UP event.
*
* We will not get a CHANGE event when the port
* is down or DOWN event is pending.
*/
portp->flags |= event_p->ev_port_flags;
portp->status |= IBTL_HCA_PORT_CHG;
} else if (code == IBT_CLNT_REREG_EVENT) {
/*
* SM has requested a re-register of
* subscription to SM events notification.
*/
portp->status |= IBTL_HCA_PORT_ASYNC_CLNT_REREG;
}
hca_devp->hd_async_codes |= code;
}
if ((hca_devp->hd_async_flags & IBTL_ASYNC_PENDING) == 0) {
hca_devp->hd_async_flags |= IBTL_ASYNC_PENDING;
hca_devp->hd_async_link = NULL;
if (ibtl_async_hca_list_end == NULL)
ibtl_async_hca_list_start = hca_devp;
else
ibtl_async_hca_list_end->hd_async_link =
hca_devp;
ibtl_async_hca_list_end = hca_devp;
cv_signal(&ibtl_async_cv);
}
break;
default:
IBTF_DPRINTF_L1(ibtf_handlers, "ibc_async_handler: "
"invalid code (0x%x)", code);
}
mutex_exit(&ibtl_async_mutex);
}
/* Finally, make the async call to the client. */
static void
ibtl_async_client_call(ibtl_hca_t *ibt_hca, ibt_async_code_t code,
ibt_async_event_t *event_p)
{
ibtl_clnt_t *clntp;
void *client_private;
ibt_async_handler_t async_handler;
char *client_name;
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_async_client_call(%p, 0x%x, %p)",
ibt_hca, code, event_p);
clntp = ibt_hca->ha_clnt_devp;
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibtl_last_client_name))
/* Record who is being called (just a debugging aid) */
ibtl_last_client_name = client_name = clntp->clnt_name;
_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibtl_last_client_name))
client_private = clntp->clnt_private;
async_handler = clntp->clnt_modinfop->mi_async_handler;
if (code & (IBT_EVENT_COM_EST_QP | IBT_EVENT_COM_EST_EEC)) {
mutex_enter(&ibtl_clnt_list_mutex);
async_handler = ibtl_cm_async_handler;
client_private = ibtl_cm_clnt_private;
mutex_exit(&ibtl_clnt_list_mutex);
ibt_hca = NULL;
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_async_client_call: "
"calling CM for COM_EST");
} else {
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_async_client_call: "
"calling client '%s'", client_name);
}
if (async_handler != NULL)
async_handler(client_private, ibt_hca, code, event_p);
else
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_async_client_call: "
"client '%s' has no async handler", client_name);
}
/*
* Inform CM or DM about HCA events.
*
* We use taskqs to allow simultaneous notification, with sleeping.
* Since taskqs only allow one argument, we define a structure
* because we need to pass in more than one argument.
*/
struct ibtl_mgr_s {
ibtl_hca_devinfo_t *mgr_hca_devp;
ibt_async_handler_t mgr_async_handler;
void *mgr_clnt_private;
};
/*
* Asyncs of HCA level events for CM and DM. Call CM or DM and tell them
* about the HCA for the event recorded in the ibtl_hca_devinfo_t.
*/
static void
ibtl_do_mgr_async_task(void *arg)
{
struct ibtl_mgr_s *mgrp = (struct ibtl_mgr_s *)arg;
ibtl_hca_devinfo_t *hca_devp = mgrp->mgr_hca_devp;
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_do_mgr_async_task(0x%x)",
hca_devp->hd_async_code);
mgrp->mgr_async_handler(mgrp->mgr_clnt_private, NULL,
hca_devp->hd_async_code, &hca_devp->hd_async_event);
kmem_free(mgrp, sizeof (*mgrp));
mutex_enter(&ibtl_clnt_list_mutex);
if (--hca_devp->hd_async_task_cnt == 0)
cv_signal(&hca_devp->hd_async_task_cv);
mutex_exit(&ibtl_clnt_list_mutex);
}
static void
ibt_cisco_embedded_sm_rereg_fix(void *arg)
{
struct ibtl_mgr_s *mgrp = arg;
ibtl_hca_devinfo_t *hca_devp;
ibt_node_info_t node_info;
ibt_status_t ibt_status;
ibtl_async_port_event_t *portp;
ib_lid_t sm_lid;
ib_guid_t hca_guid;
ibt_async_event_t *event_p;
ibt_hca_portinfo_t *pinfop;
uint8_t port;
hca_devp = mgrp->mgr_hca_devp;
mutex_enter(&ibtl_clnt_list_mutex);
event_p = &hca_devp->hd_async_event;
port = event_p->ev_port;
portp = &hca_devp->hd_async_port[port - 1];
pinfop = &hca_devp->hd_portinfop[port - 1];
sm_lid = pinfop->p_sm_lid;
hca_guid = hca_devp->hd_hca_attr->hca_node_guid;
mutex_exit(&ibtl_clnt_list_mutex);
ibt_status = ((ibtl_node_info_cb_t)(uintptr_t)
mgrp->mgr_async_handler)(hca_guid, port, sm_lid, &node_info);
if (ibt_status == IBT_SUCCESS) {
if ((node_info.n_vendor_id == IBT_VENDOR_CISCO) &&
(node_info.n_node_type == IBT_NODE_TYPE_SWITCH)) {
mutex_enter(&ibtl_async_mutex);
portp->status |= IBTL_HCA_PORT_ASYNC_CLNT_REREG;
hca_devp->hd_async_codes |= IBT_CLNT_REREG_EVENT;
mutex_exit(&ibtl_async_mutex);
}
}
kmem_free(mgrp, sizeof (*mgrp));
mutex_enter(&ibtl_clnt_list_mutex);
if (--hca_devp->hd_async_task_cnt == 0)
cv_signal(&hca_devp->hd_async_task_cv);
mutex_exit(&ibtl_clnt_list_mutex);
}
static void
ibtl_cm_get_node_info(ibtl_hca_devinfo_t *hca_devp,
ibt_async_handler_t async_handler)
{
struct ibtl_mgr_s *mgrp;
if (async_handler == NULL)
return;
_NOTE(NO_COMPETING_THREADS_NOW)
mgrp = kmem_alloc(sizeof (*mgrp), KM_SLEEP);
mgrp->mgr_hca_devp = hca_devp;
mgrp->mgr_async_handler = async_handler;
mgrp->mgr_clnt_private = NULL;
hca_devp->hd_async_task_cnt++;
(void) taskq_dispatch(ibtl_async_taskq,
ibt_cisco_embedded_sm_rereg_fix, mgrp, TQ_SLEEP);
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
}
static void
ibtl_tell_mgr(ibtl_hca_devinfo_t *hca_devp, ibt_async_handler_t async_handler,
void *clnt_private)
{
struct ibtl_mgr_s *mgrp;
if (async_handler == NULL)
return;
_NOTE(NO_COMPETING_THREADS_NOW)
mgrp = kmem_alloc(sizeof (*mgrp), KM_SLEEP);
mgrp->mgr_hca_devp = hca_devp;
mgrp->mgr_async_handler = async_handler;
mgrp->mgr_clnt_private = clnt_private;
hca_devp->hd_async_task_cnt++;
(void) taskq_dispatch(ibtl_async_taskq, ibtl_do_mgr_async_task, mgrp,
TQ_SLEEP);
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
}
/*
* Per client-device asyncs for HCA level events. Call each client that is
* using the HCA for the event recorded in the ibtl_hca_devinfo_t.
*/
static void
ibtl_hca_client_async_task(void *arg)
{
ibtl_hca_t *ibt_hca = (ibtl_hca_t *)arg;
ibtl_hca_devinfo_t *hca_devp = ibt_hca->ha_hca_devp;
ibtl_clnt_t *clntp = ibt_hca->ha_clnt_devp;
ibt_async_event_t async_event;
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_hca_client_async_task(%p, 0x%x)",
ibt_hca, hca_devp->hd_async_code);
bcopy(&hca_devp->hd_async_event, &async_event, sizeof (async_event));
ibtl_async_client_call(ibt_hca, hca_devp->hd_async_code, &async_event);
mutex_enter(&ibtl_async_mutex);
if (--ibt_hca->ha_async_cnt == 0 &&
(ibt_hca->ha_async_flags & IBTL_ASYNC_FREE_OBJECT)) {
mutex_exit(&ibtl_async_mutex);
kmem_free(ibt_hca, sizeof (ibtl_hca_t));
} else
mutex_exit(&ibtl_async_mutex);
mutex_enter(&ibtl_clnt_list_mutex);
if (--hca_devp->hd_async_task_cnt == 0)
cv_signal(&hca_devp->hd_async_task_cv);
if (--clntp->clnt_async_cnt == 0)
cv_broadcast(&ibtl_clnt_cv);
mutex_exit(&ibtl_clnt_list_mutex);
}
/*
* Asyncs for HCA level events.
*
* The function continues to run until there are no more async
* events/errors for this HCA. An event is chosen for dispatch
* to all clients of this HCA. This thread dispatches them via
* the ibtl_async_taskq, then sleeps until all tasks are done.
*
* This thread records the async_code and async_event in the
* ibtl_hca_devinfo_t for all client taskq threads to reference.
*
* This is called from an async or taskq thread with ibtl_async_mutex held.
*/
static void
ibtl_do_hca_asyncs(ibtl_hca_devinfo_t *hca_devp)
{
ibtl_hca_t *ibt_hca;
ibt_async_event_t *eventp;
ibt_async_code_t code;
ibtl_async_port_status_t temp;
uint8_t nports;
uint8_t port_minus1;
ibtl_async_port_event_t *portp;
mutex_exit(&ibtl_async_mutex);
mutex_enter(&ibtl_clnt_list_mutex);
while (hca_devp->hd_async_busy)
cv_wait(&hca_devp->hd_async_busy_cv, &ibtl_clnt_list_mutex);
hca_devp->hd_async_busy = 1;
mutex_enter(&ibtl_async_mutex);
bzero(&hca_devp->hd_async_event, sizeof (hca_devp->hd_async_event));
for (;;) {
hca_devp->hd_async_event.ev_fma_ena = 0;
code = hca_devp->hd_async_codes;
if (code & IBT_ERROR_LOCAL_CATASTROPHIC) {
code = IBT_ERROR_LOCAL_CATASTROPHIC;
hca_devp->hd_async_event.ev_fma_ena =
hca_devp->hd_fma_ena;
} else if (code & IBT_ERROR_PORT_DOWN) {
code = IBT_ERROR_PORT_DOWN;
temp = IBTL_HCA_PORT_DOWN;
} else if (code & IBT_EVENT_PORT_UP) {
code = IBT_EVENT_PORT_UP;
temp = IBTL_HCA_PORT_UP;
} else if (code & IBT_PORT_CHANGE_EVENT) {
code = IBT_PORT_CHANGE_EVENT;
temp = IBTL_HCA_PORT_CHG;
} else if (code & IBT_CLNT_REREG_EVENT) {
code = IBT_CLNT_REREG_EVENT;
temp = IBTL_HCA_PORT_ASYNC_CLNT_REREG;
} else {
hca_devp->hd_async_codes = 0;
code = 0;
}
if (code == 0) {
hca_devp->hd_async_flags &= ~IBTL_ASYNC_PENDING;
break;
}
hca_devp->hd_async_codes &= ~code;
/* PORT_UP, PORT_CHANGE, PORT_DOWN or ASYNC_REREG */
if ((code & IBT_PORT_EVENTS) != 0) {
portp = hca_devp->hd_async_port;
nports = hca_devp->hd_hca_attr->hca_nports;
for (port_minus1 = 0; port_minus1 < nports;
port_minus1++) {
/*
* Matching event in this port, let's go handle
* it.
*/
if ((portp[port_minus1].status & temp) != 0)
break;
}
if (port_minus1 >= nports) {
/* we checked again, but found nothing */
continue;
}
IBTF_DPRINTF_L4(ibtf_handlers, "ibtl_do_hca_asyncs: "
"async: port# %x code %x", port_minus1 + 1, code);
/* mark it to check for other ports after we're done */
hca_devp->hd_async_codes |= code;
/*
* Copy the event information into hca_devp and clear
* event information from the per port data.
*/
hca_devp->hd_async_event.ev_port = port_minus1 + 1;
if (temp == IBTL_HCA_PORT_CHG) {
hca_devp->hd_async_event.ev_port_flags =
hca_devp->hd_async_port[port_minus1].flags;
hca_devp->hd_async_port[port_minus1].flags = 0;
}
hca_devp->hd_async_port[port_minus1].status &= ~temp;
mutex_exit(&ibtl_async_mutex);
ibtl_reinit_hca_portinfo(hca_devp, port_minus1 + 1);
mutex_enter(&ibtl_async_mutex);
eventp = &hca_devp->hd_async_event;
eventp->ev_hca_guid =
hca_devp->hd_hca_attr->hca_node_guid;
}
hca_devp->hd_async_code = code;
hca_devp->hd_async_event.ev_hca_guid =
hca_devp->hd_hca_attr->hca_node_guid;
mutex_exit(&ibtl_async_mutex);
/*
* Make sure to inform CM, DM, and IBMA if we know of them.
* Also, make sure not to inform them a second time, which
* would occur if they have the HCA open.
*/
if (ibtl_ibma_async_handler)
ibtl_tell_mgr(hca_devp, ibtl_ibma_async_handler,
ibtl_ibma_clnt_private);
/* wait for all tasks to complete */
while (hca_devp->hd_async_task_cnt != 0)
cv_wait(&hca_devp->hd_async_task_cv,
&ibtl_clnt_list_mutex);
/*
* Hack Alert:
* The ibmf handler would have updated the Master SM LID if it
* was SM LID change event. Now lets check if the new Master SM
* is a Embedded Cisco Topspin SM.
*/
if ((code == IBT_PORT_CHANGE_EVENT) &&
eventp->ev_port_flags & IBT_PORT_CHANGE_SM_LID)
ibtl_cm_get_node_info(hca_devp,
(ibt_async_handler_t)(uintptr_t)ibtl_node_info_cb);
/* wait for node info task to complete */
while (hca_devp->hd_async_task_cnt != 0)
cv_wait(&hca_devp->hd_async_task_cv,
&ibtl_clnt_list_mutex);
if (ibtl_dm_async_handler)
ibtl_tell_mgr(hca_devp, ibtl_dm_async_handler,
ibtl_dm_clnt_private);
if (ibtl_cm_async_handler)
ibtl_tell_mgr(hca_devp, ibtl_cm_async_handler,
ibtl_cm_clnt_private);
/* wait for all tasks to complete */
while (hca_devp->hd_async_task_cnt != 0)
cv_wait(&hca_devp->hd_async_task_cv,
&ibtl_clnt_list_mutex);
for (ibt_hca = hca_devp->hd_clnt_list;
ibt_hca != NULL;
ibt_hca = ibt_hca->ha_clnt_link) {
/* Managers are handled above */
if (IBTL_HCA2MODI_P(ibt_hca)->mi_async_handler ==
ibtl_cm_async_handler)
continue;
if (IBTL_HCA2MODI_P(ibt_hca)->mi_async_handler ==
ibtl_dm_async_handler)
continue;
if (IBTL_HCA2MODI_P(ibt_hca)->mi_async_handler ==
ibtl_ibma_async_handler)
continue;
++ibt_hca->ha_clnt_devp->clnt_async_cnt;
mutex_enter(&ibtl_async_mutex);
ibt_hca->ha_async_cnt++;
mutex_exit(&ibtl_async_mutex);
hca_devp->hd_async_task_cnt++;
(void) taskq_dispatch(ibtl_async_taskq,
ibtl_hca_client_async_task, ibt_hca, TQ_SLEEP);
}
/* wait for all tasks to complete */
while (hca_devp->hd_async_task_cnt != 0)
cv_wait(&hca_devp->hd_async_task_cv,
&ibtl_clnt_list_mutex);
mutex_enter(&ibtl_async_mutex);
}
hca_devp->hd_async_code = 0;
hca_devp->hd_async_busy = 0;
cv_broadcast(&hca_devp->hd_async_busy_cv);
mutex_exit(&ibtl_clnt_list_mutex);
}
/*
* Asyncs for QP objects.
*
* The function continues to run until there are no more async
* events/errors for this object.
*/
static void
ibtl_do_qp_asyncs(ibtl_qp_t *ibtl_qp)
{
ibt_async_code_t code;
ibt_async_event_t async_event;
ASSERT(MUTEX_HELD(&ibtl_async_mutex));
bzero(&async_event, sizeof (async_event));
async_event.ev_chan_hdl = IBTL_QP2CHAN(ibtl_qp);
while ((code = ibtl_qp->qp_async_codes) != 0) {
async_event.ev_fma_ena = 0;
if (ibtl_qp->qp_async_flags & IBTL_ASYNC_FREE_OBJECT)
code = 0; /* fallthrough to "kmem_free" */
else if (code & IBT_ERROR_CATASTROPHIC_QP) {
code = IBT_ERROR_CATASTROPHIC_QP;
async_event.ev_fma_ena = ibtl_qp->qp_cat_fma_ena;
} else if (code & IBT_ERROR_INVALID_REQUEST_QP) {
code = IBT_ERROR_INVALID_REQUEST_QP;
async_event.ev_fma_ena = ibtl_qp->qp_inv_fma_ena;
} else if (code & IBT_ERROR_ACCESS_VIOLATION_QP) {
code = IBT_ERROR_ACCESS_VIOLATION_QP;
async_event.ev_fma_ena = ibtl_qp->qp_acc_fma_ena;
} else if (code & IBT_ERROR_PATH_MIGRATE_REQ_QP) {
code = IBT_ERROR_PATH_MIGRATE_REQ_QP;
async_event.ev_fma_ena = ibtl_qp->qp_pth_fma_ena;
} else if (code & IBT_EVENT_PATH_MIGRATED_QP)
code = IBT_EVENT_PATH_MIGRATED_QP;
else if (code & IBT_EVENT_SQD)
code = IBT_EVENT_SQD;
else if (code & IBT_EVENT_COM_EST_QP)
code = IBT_EVENT_COM_EST_QP;
else if (code & IBT_EVENT_EMPTY_QP)
code = IBT_EVENT_EMPTY_QP;
else {
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_do_qp_asyncs: "
"async: unexpected QP async code 0x%x", code);
ibtl_qp->qp_async_codes = 0;
code = 0;
}
ibtl_qp->qp_async_codes &= ~code;
if (code) {
mutex_exit(&ibtl_async_mutex);
ibtl_async_client_call(ibtl_qp->qp_hca,
code, &async_event);
mutex_enter(&ibtl_async_mutex);
}
if (ibtl_qp->qp_async_flags & IBTL_ASYNC_FREE_OBJECT) {
mutex_exit(&ibtl_async_mutex);
cv_destroy(&(IBTL_QP2CHAN(ibtl_qp))->ch_cm_cv);
mutex_destroy(&(IBTL_QP2CHAN(ibtl_qp))->ch_cm_mutex);
kmem_free(IBTL_QP2CHAN(ibtl_qp),
sizeof (ibtl_channel_t));
mutex_enter(&ibtl_async_mutex);
return;
}
}
ibtl_qp->qp_async_flags &= ~IBTL_ASYNC_PENDING;
}
/*
* Asyncs for SRQ objects.
*
* The function continues to run until there are no more async
* events/errors for this object.
*/
static void
ibtl_do_srq_asyncs(ibtl_srq_t *ibtl_srq)
{
ibt_async_code_t code;
ibt_async_event_t async_event;
ASSERT(MUTEX_HELD(&ibtl_async_mutex));
bzero(&async_event, sizeof (async_event));
async_event.ev_srq_hdl = ibtl_srq;
async_event.ev_fma_ena = ibtl_srq->srq_fma_ena;
while ((code = ibtl_srq->srq_async_codes) != 0) {
if (ibtl_srq->srq_async_flags & IBTL_ASYNC_FREE_OBJECT)
code = 0; /* fallthrough to "kmem_free" */
else if (code & IBT_ERROR_CATASTROPHIC_SRQ)
code = IBT_ERROR_CATASTROPHIC_SRQ;
else if (code & IBT_EVENT_LIMIT_REACHED_SRQ)
code = IBT_EVENT_LIMIT_REACHED_SRQ;
else {
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_do_srq_asyncs: "
"async: unexpected SRQ async code 0x%x", code);
ibtl_srq->srq_async_codes = 0;
code = 0;
}
ibtl_srq->srq_async_codes &= ~code;
if (code) {
mutex_exit(&ibtl_async_mutex);
ibtl_async_client_call(ibtl_srq->srq_hca,
code, &async_event);
mutex_enter(&ibtl_async_mutex);
}
if (ibtl_srq->srq_async_flags & IBTL_ASYNC_FREE_OBJECT) {
mutex_exit(&ibtl_async_mutex);
kmem_free(ibtl_srq, sizeof (struct ibtl_srq_s));
mutex_enter(&ibtl_async_mutex);
return;
}
}
ibtl_srq->srq_async_flags &= ~IBTL_ASYNC_PENDING;
}
/*
* Asyncs for CQ objects.
*
* The function continues to run until there are no more async
* events/errors for this object.
*/
static void
ibtl_do_cq_asyncs(ibtl_cq_t *ibtl_cq)
{
ibt_async_code_t code;
ibt_async_event_t async_event;
ASSERT(MUTEX_HELD(&ibtl_async_mutex));
bzero(&async_event, sizeof (async_event));
async_event.ev_cq_hdl = ibtl_cq;
async_event.ev_fma_ena = ibtl_cq->cq_fma_ena;
while ((code = ibtl_cq->cq_async_codes) != 0) {
if (ibtl_cq->cq_async_flags & IBTL_ASYNC_FREE_OBJECT)
code = 0; /* fallthrough to "kmem_free" */
else if (code & IBT_ERROR_CQ)
code = IBT_ERROR_CQ;
else {
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_do_cq_asyncs: "
"async: unexpected CQ async code 0x%x", code);
ibtl_cq->cq_async_codes = 0;
code = 0;
}
ibtl_cq->cq_async_codes &= ~code;
if (code) {
mutex_exit(&ibtl_async_mutex);
ibtl_async_client_call(ibtl_cq->cq_hca,
code, &async_event);
mutex_enter(&ibtl_async_mutex);
}
if (ibtl_cq->cq_async_flags & IBTL_ASYNC_FREE_OBJECT) {
mutex_exit(&ibtl_async_mutex);
mutex_destroy(&ibtl_cq->cq_mutex);
kmem_free(ibtl_cq, sizeof (struct ibtl_cq_s));
mutex_enter(&ibtl_async_mutex);
return;
}
}
ibtl_cq->cq_async_flags &= ~IBTL_ASYNC_PENDING;
}
/*
* Asyncs for EEC objects.
*
* The function continues to run until there are no more async
* events/errors for this object.
*/
static void
ibtl_do_eec_asyncs(ibtl_eec_t *ibtl_eec)
{
ibt_async_code_t code;
ibt_async_event_t async_event;
ASSERT(MUTEX_HELD(&ibtl_async_mutex));
bzero(&async_event, sizeof (async_event));
async_event.ev_chan_hdl = ibtl_eec->eec_channel;
while ((code = ibtl_eec->eec_async_codes) != 0) {
async_event.ev_fma_ena = 0;
if (ibtl_eec->eec_async_flags & IBTL_ASYNC_FREE_OBJECT)
code = 0; /* fallthrough to "kmem_free" */
else if (code & IBT_ERROR_CATASTROPHIC_EEC) {
code = IBT_ERROR_CATASTROPHIC_CHAN;
async_event.ev_fma_ena = ibtl_eec->eec_cat_fma_ena;
} else if (code & IBT_ERROR_PATH_MIGRATE_REQ_EEC) {
code = IBT_ERROR_PATH_MIGRATE_REQ;
async_event.ev_fma_ena = ibtl_eec->eec_pth_fma_ena;
} else if (code & IBT_EVENT_PATH_MIGRATED_EEC)
code = IBT_EVENT_PATH_MIGRATED;
else if (code & IBT_EVENT_COM_EST_EEC)
code = IBT_EVENT_COM_EST;
else {
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_do_eec_asyncs: "
"async: unexpected code 0x%x", code);
ibtl_eec->eec_async_codes = 0;
code = 0;
}
ibtl_eec->eec_async_codes &= ~code;
if (code) {
mutex_exit(&ibtl_async_mutex);
ibtl_async_client_call(ibtl_eec->eec_hca,
code, &async_event);
mutex_enter(&ibtl_async_mutex);
}
if (ibtl_eec->eec_async_flags & IBTL_ASYNC_FREE_OBJECT) {
mutex_exit(&ibtl_async_mutex);
kmem_free(ibtl_eec, sizeof (struct ibtl_eec_s));
mutex_enter(&ibtl_async_mutex);
return;
}
}
ibtl_eec->eec_async_flags &= ~IBTL_ASYNC_PENDING;
}
#ifdef __lock_lint
kmutex_t cpr_mutex;
#endif
/*
* Loop forever, calling async_handlers until all of the async lists
* are empty.
*/
static void
ibtl_async_thread(void)
{
#ifndef __lock_lint
kmutex_t cpr_mutex;
#endif
callb_cpr_t cprinfo;
_NOTE(MUTEX_PROTECTS_DATA(cpr_mutex, cprinfo))
_NOTE(NO_COMPETING_THREADS_NOW)
mutex_init(&cpr_mutex, NULL, MUTEX_DRIVER, NULL);
CALLB_CPR_INIT(&cprinfo, &cpr_mutex, callb_generic_cpr,
"ibtl_async_thread");
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
mutex_enter(&ibtl_async_mutex);
for (;;) {
if (ibtl_async_hca_list_start) {
ibtl_hca_devinfo_t *hca_devp;
/* remove first entry from list */
hca_devp = ibtl_async_hca_list_start;
ibtl_async_hca_list_start = hca_devp->hd_async_link;
hca_devp->hd_async_link = NULL;
if (ibtl_async_hca_list_start == NULL)
ibtl_async_hca_list_end = NULL;
ibtl_do_hca_asyncs(hca_devp);
} else if (ibtl_async_qp_list_start) {
ibtl_qp_t *ibtl_qp;
/* remove from list */
ibtl_qp = ibtl_async_qp_list_start;
ibtl_async_qp_list_start = ibtl_qp->qp_async_link;
ibtl_qp->qp_async_link = NULL;
if (ibtl_async_qp_list_start == NULL)
ibtl_async_qp_list_end = NULL;
ibtl_do_qp_asyncs(ibtl_qp);
} else if (ibtl_async_srq_list_start) {
ibtl_srq_t *ibtl_srq;
/* remove from list */
ibtl_srq = ibtl_async_srq_list_start;
ibtl_async_srq_list_start = ibtl_srq->srq_async_link;
ibtl_srq->srq_async_link = NULL;
if (ibtl_async_srq_list_start == NULL)
ibtl_async_srq_list_end = NULL;
ibtl_do_srq_asyncs(ibtl_srq);
} else if (ibtl_async_eec_list_start) {
ibtl_eec_t *ibtl_eec;
/* remove from list */
ibtl_eec = ibtl_async_eec_list_start;
ibtl_async_eec_list_start = ibtl_eec->eec_async_link;
ibtl_eec->eec_async_link = NULL;
if (ibtl_async_eec_list_start == NULL)
ibtl_async_eec_list_end = NULL;
ibtl_do_eec_asyncs(ibtl_eec);
} else if (ibtl_async_cq_list_start) {
ibtl_cq_t *ibtl_cq;
/* remove from list */
ibtl_cq = ibtl_async_cq_list_start;
ibtl_async_cq_list_start = ibtl_cq->cq_async_link;
ibtl_cq->cq_async_link = NULL;
if (ibtl_async_cq_list_start == NULL)
ibtl_async_cq_list_end = NULL;
ibtl_do_cq_asyncs(ibtl_cq);
} else {
if (ibtl_async_thread_exit == IBTL_THREAD_EXIT)
break;
mutex_enter(&cpr_mutex);
CALLB_CPR_SAFE_BEGIN(&cprinfo);
mutex_exit(&cpr_mutex);
cv_wait(&ibtl_async_cv, &ibtl_async_mutex);
mutex_exit(&ibtl_async_mutex);
mutex_enter(&cpr_mutex);
CALLB_CPR_SAFE_END(&cprinfo, &cpr_mutex);
mutex_exit(&cpr_mutex);
mutex_enter(&ibtl_async_mutex);
}
}
mutex_exit(&ibtl_async_mutex);
#ifndef __lock_lint
mutex_enter(&cpr_mutex);
CALLB_CPR_EXIT(&cprinfo);
#endif
mutex_destroy(&cpr_mutex);
}
void
ibtl_free_qp_async_check(ibtl_qp_t *ibtl_qp)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_free_qp_async_check(%p)", ibtl_qp);
mutex_enter(&ibtl_async_mutex);
/*
* If there is an active async, mark this object to be freed
* by the async_thread when it's done.
*/
if (ibtl_qp->qp_async_flags & IBTL_ASYNC_PENDING) {
ibtl_qp->qp_async_flags |= IBTL_ASYNC_FREE_OBJECT;
mutex_exit(&ibtl_async_mutex);
} else { /* free the object now */
mutex_exit(&ibtl_async_mutex);
cv_destroy(&(IBTL_QP2CHAN(ibtl_qp))->ch_cm_cv);
mutex_destroy(&(IBTL_QP2CHAN(ibtl_qp))->ch_cm_mutex);
kmem_free(IBTL_QP2CHAN(ibtl_qp), sizeof (ibtl_channel_t));
}
}
void
ibtl_free_cq_async_check(ibtl_cq_t *ibtl_cq)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_free_cq_async_check(%p)", ibtl_cq);
mutex_enter(&ibtl_async_mutex);
/* if there is an active async, mark this object to be freed */
if (ibtl_cq->cq_async_flags & IBTL_ASYNC_PENDING) {
ibtl_cq->cq_async_flags |= IBTL_ASYNC_FREE_OBJECT;
mutex_exit(&ibtl_async_mutex);
} else { /* free the object now */
mutex_exit(&ibtl_async_mutex);
mutex_destroy(&ibtl_cq->cq_mutex);
kmem_free(ibtl_cq, sizeof (struct ibtl_cq_s));
}
}
void
ibtl_free_srq_async_check(ibtl_srq_t *ibtl_srq)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_free_srq_async_check(%p)",
ibtl_srq);
mutex_enter(&ibtl_async_mutex);
/* if there is an active async, mark this object to be freed */
if (ibtl_srq->srq_async_flags & IBTL_ASYNC_PENDING) {
ibtl_srq->srq_async_flags |= IBTL_ASYNC_FREE_OBJECT;
mutex_exit(&ibtl_async_mutex);
} else { /* free the object now */
mutex_exit(&ibtl_async_mutex);
kmem_free(ibtl_srq, sizeof (struct ibtl_srq_s));
}
}
void
ibtl_free_eec_async_check(ibtl_eec_t *ibtl_eec)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_free_eec_async_check(%p)",
ibtl_eec);
mutex_enter(&ibtl_async_mutex);
/* if there is an active async, mark this object to be freed */
if (ibtl_eec->eec_async_flags & IBTL_ASYNC_PENDING) {
ibtl_eec->eec_async_flags |= IBTL_ASYNC_FREE_OBJECT;
mutex_exit(&ibtl_async_mutex);
} else { /* free the object now */
mutex_exit(&ibtl_async_mutex);
kmem_free(ibtl_eec, sizeof (struct ibtl_eec_s));
}
}
/*
* This function differs from above in that we assume this is called
* from non-interrupt context, and never called from the async_thread.
*/
void
ibtl_free_hca_async_check(ibtl_hca_t *ibt_hca)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_free_hca_async_check(%p)",
ibt_hca);
mutex_enter(&ibtl_async_mutex);
/* if there is an active async, mark this object to be freed */
if (ibt_hca->ha_async_cnt > 0) {
ibt_hca->ha_async_flags |= IBTL_ASYNC_FREE_OBJECT;
mutex_exit(&ibtl_async_mutex);
} else { /* free the object now */
mutex_exit(&ibtl_async_mutex);
kmem_free(ibt_hca, sizeof (ibtl_hca_t));
}
}
/*
* Completion Queue Handling.
*
* A completion queue can be handled through a simple callback
* at interrupt level, or it may be queued for an ibtl_cq_thread
* to handle. The latter is chosen during ibt_alloc_cq when the
* IBTF_CQ_HANDLER_IN_THREAD is specified.
*/
static void
ibtl_cq_handler_call(ibtl_cq_t *ibtl_cq)
{
ibt_cq_handler_t cq_handler;
void *arg;
IBTF_DPRINTF_L4(ibtf_handlers, "ibtl_cq_handler_call(%p)", ibtl_cq);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*ibtl_cq))
cq_handler = ibtl_cq->cq_comp_handler;
arg = ibtl_cq->cq_arg;
if (cq_handler != NULL)
cq_handler(ibtl_cq, arg);
else
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_cq_handler_call: "
"no cq_handler for cq %p", ibtl_cq);
}
/*
* Before ibt_free_cq can continue, we need to ensure no more cq_handler
* callbacks can occur. When we get the mutex, we know there are no
* outstanding cq_handler callbacks. We set the cq_handler to NULL to
* prohibit future callbacks.
*/
void
ibtl_free_cq_check(ibtl_cq_t *ibtl_cq)
{
mutex_enter(&ibtl_cq->cq_mutex);
ibtl_cq->cq_comp_handler = NULL;
mutex_exit(&ibtl_cq->cq_mutex);
if (ibtl_cq->cq_in_thread) {
mutex_enter(&ibtl_cq_mutex);
--ibtl_cqs_using_threads;
while (ibtl_cq->cq_impl_flags & IBTL_CQ_PENDING) {
ibtl_cq->cq_impl_flags &= ~IBTL_CQ_CALL_CLIENT;
ibtl_cq->cq_impl_flags |= IBTL_CQ_FREE;
cv_wait(&ibtl_cq_cv, &ibtl_cq_mutex);
}
mutex_exit(&ibtl_cq_mutex);
}
}
/*
* Loop forever, calling cq_handlers until the cq list
* is empty.
*/
static void
ibtl_cq_thread(void)
{
#ifndef __lock_lint
kmutex_t cpr_mutex;
#endif
callb_cpr_t cprinfo;
_NOTE(MUTEX_PROTECTS_DATA(cpr_mutex, cprinfo))
_NOTE(NO_COMPETING_THREADS_NOW)
mutex_init(&cpr_mutex, NULL, MUTEX_DRIVER, NULL);
CALLB_CPR_INIT(&cprinfo, &cpr_mutex, callb_generic_cpr,
"ibtl_cq_thread");
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
mutex_enter(&ibtl_cq_mutex);
for (;;) {
if (ibtl_cq_list_start) {
ibtl_cq_t *ibtl_cq;
ibtl_cq = ibtl_cq_list_start;
ibtl_cq_list_start = ibtl_cq->cq_link;
ibtl_cq->cq_link = NULL;
if (ibtl_cq == ibtl_cq_list_end)
ibtl_cq_list_end = NULL;
while (ibtl_cq->cq_impl_flags & IBTL_CQ_CALL_CLIENT) {
ibtl_cq->cq_impl_flags &= ~IBTL_CQ_CALL_CLIENT;
mutex_exit(&ibtl_cq_mutex);
ibtl_cq_handler_call(ibtl_cq);
mutex_enter(&ibtl_cq_mutex);
}
ibtl_cq->cq_impl_flags &= ~IBTL_CQ_PENDING;
if (ibtl_cq->cq_impl_flags & IBTL_CQ_FREE)
cv_broadcast(&ibtl_cq_cv);
} else {
if (ibtl_cq_thread_exit == IBTL_THREAD_EXIT)
break;
mutex_enter(&cpr_mutex);
CALLB_CPR_SAFE_BEGIN(&cprinfo);
mutex_exit(&cpr_mutex);
cv_wait(&ibtl_cq_cv, &ibtl_cq_mutex);
mutex_exit(&ibtl_cq_mutex);
mutex_enter(&cpr_mutex);
CALLB_CPR_SAFE_END(&cprinfo, &cpr_mutex);
mutex_exit(&cpr_mutex);
mutex_enter(&ibtl_cq_mutex);
}
}
mutex_exit(&ibtl_cq_mutex);
#ifndef __lock_lint
mutex_enter(&cpr_mutex);
CALLB_CPR_EXIT(&cprinfo);
#endif
mutex_destroy(&cpr_mutex);
}
/*
* ibc_cq_handler()
*
* Completion Queue Notification Handler.
*
*/
/*ARGSUSED*/
void
ibc_cq_handler(ibc_clnt_hdl_t ibc_hdl, ibt_cq_hdl_t ibtl_cq)
{
IBTF_DPRINTF_L4(ibtf_handlers, "ibc_cq_handler(%p, %p)",
ibc_hdl, ibtl_cq);
if (ibtl_cq->cq_in_thread) {
mutex_enter(&ibtl_cq_mutex);
ibtl_cq->cq_impl_flags |= IBTL_CQ_CALL_CLIENT;
if ((ibtl_cq->cq_impl_flags & IBTL_CQ_PENDING) == 0) {
ibtl_cq->cq_impl_flags |= IBTL_CQ_PENDING;
ibtl_cq->cq_link = NULL;
if (ibtl_cq_list_end == NULL)
ibtl_cq_list_start = ibtl_cq;
else
ibtl_cq_list_end->cq_link = ibtl_cq;
ibtl_cq_list_end = ibtl_cq;
cv_signal(&ibtl_cq_cv);
}
mutex_exit(&ibtl_cq_mutex);
return;
} else
ibtl_cq_handler_call(ibtl_cq);
}
/*
* ibt_enable_cq_notify()
* Enable Notification requests on the specified CQ.
*
* ibt_cq The CQ handle.
*
* notify_type Enable notifications for all (IBT_NEXT_COMPLETION)
* completions, or the next Solicited completion
* (IBT_NEXT_SOLICITED) only.
*
* Completion notifications are disabled by setting the completion
* handler to NULL by calling ibt_set_cq_handler().
*/
ibt_status_t
ibt_enable_cq_notify(ibt_cq_hdl_t ibtl_cq, ibt_cq_notify_flags_t notify_type)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibt_enable_cq_notify(%p, %d)",
ibtl_cq, notify_type);
return (IBTL_CQ2CIHCAOPS_P(ibtl_cq)->ibc_notify_cq(
IBTL_CQ2CIHCA(ibtl_cq), ibtl_cq->cq_ibc_cq_hdl, notify_type));
}
/*
* ibt_set_cq_handler()
* Register a work request completion handler with the IBTF.
*
* ibt_cq The CQ handle.
*
* completion_handler The completion handler.
*
* arg The IBTF client private argument to be passed
* back to the client when calling the CQ
* completion handler.
*
* Completion notifications are disabled by setting the completion
* handler to NULL. When setting the handler to NULL, no additional
* calls to the previous CQ handler will be initiated, but there may
* be one in progress.
*
* This function does not otherwise change the state of previous
* calls to ibt_enable_cq_notify().
*/
void
ibt_set_cq_handler(ibt_cq_hdl_t ibtl_cq, ibt_cq_handler_t completion_handler,
void *arg)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibt_set_cq_handler(%p, %p, %p)",
ibtl_cq, completion_handler, arg);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*ibtl_cq))
ibtl_cq->cq_comp_handler = completion_handler;
ibtl_cq->cq_arg = arg;
}
/*
* Inform IBT clients about New HCAs.
*
* We use taskqs to allow simultaneous notification, with sleeping.
* Since taskqs only allow one argument, we define a structure
* because we need to pass in two arguments.
*/
struct ibtl_new_hca_s {
ibtl_clnt_t *nh_clntp;
ibtl_hca_devinfo_t *nh_hca_devp;
ibt_async_code_t nh_code;
};
static void
ibtl_tell_client_about_new_hca(void *arg)
{
struct ibtl_new_hca_s *new_hcap = (struct ibtl_new_hca_s *)arg;
ibtl_clnt_t *clntp = new_hcap->nh_clntp;
ibt_async_event_t async_event;
ibtl_hca_devinfo_t *hca_devp = new_hcap->nh_hca_devp;
bzero(&async_event, sizeof (async_event));
async_event.ev_hca_guid = hca_devp->hd_hca_attr->hca_node_guid;
clntp->clnt_modinfop->mi_async_handler(
clntp->clnt_private, NULL, new_hcap->nh_code, &async_event);
kmem_free(new_hcap, sizeof (*new_hcap));
#ifdef __lock_lint
{
ibt_hca_hdl_t hca_hdl;
(void) ibt_open_hca(clntp, 0ULL, &hca_hdl);
}
#endif
mutex_enter(&ibtl_clnt_list_mutex);
if (--hca_devp->hd_async_task_cnt == 0)
cv_signal(&hca_devp->hd_async_task_cv);
if (--clntp->clnt_async_cnt == 0)
cv_broadcast(&ibtl_clnt_cv);
mutex_exit(&ibtl_clnt_list_mutex);
}
/*
* ibtl_announce_new_hca:
*
* o First attach these clients in the given order
* IBMA
* IBCM
*
* o Next attach all other clients in parallel.
*
* NOTE: Use the taskq to simultaneously notify all clients of the new HCA.
* Retval from clients is ignored.
*/
void
ibtl_announce_new_hca(ibtl_hca_devinfo_t *hca_devp)
{
ibtl_clnt_t *clntp;
struct ibtl_new_hca_s *new_hcap;
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_announce_new_hca(%p, %llX)",
hca_devp, hca_devp->hd_hca_attr->hca_node_guid);
mutex_enter(&ibtl_clnt_list_mutex);
clntp = ibtl_clnt_list;
while (clntp != NULL) {
if (clntp->clnt_modinfop->mi_clnt_class == IBT_IBMA) {
IBTF_DPRINTF_L4(ibtf_handlers,
"ibtl_announce_new_hca: calling IBMF");
if (clntp->clnt_modinfop->mi_async_handler) {
_NOTE(NO_COMPETING_THREADS_NOW)
new_hcap = kmem_alloc(sizeof (*new_hcap),
KM_SLEEP);
new_hcap->nh_clntp = clntp;
new_hcap->nh_hca_devp = hca_devp;
new_hcap->nh_code = IBT_HCA_ATTACH_EVENT;
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
clntp->clnt_async_cnt++;
hca_devp->hd_async_task_cnt++;
(void) taskq_dispatch(ibtl_async_taskq,
ibtl_tell_client_about_new_hca, new_hcap,
TQ_SLEEP);
}
break;
}
clntp = clntp->clnt_list_link;
}
if (clntp != NULL)
while (clntp->clnt_async_cnt > 0)
cv_wait(&ibtl_clnt_cv, &ibtl_clnt_list_mutex);
clntp = ibtl_clnt_list;
while (clntp != NULL) {
if (clntp->clnt_modinfop->mi_clnt_class == IBT_DM) {
IBTF_DPRINTF_L4(ibtf_handlers, "ibtl_announce_new_hca: "
"calling %s", clntp->clnt_modinfop->mi_clnt_name);
if (clntp->clnt_modinfop->mi_async_handler) {
_NOTE(NO_COMPETING_THREADS_NOW)
new_hcap = kmem_alloc(sizeof (*new_hcap),
KM_SLEEP);
new_hcap->nh_clntp = clntp;
new_hcap->nh_hca_devp = hca_devp;
new_hcap->nh_code = IBT_HCA_ATTACH_EVENT;
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
clntp->clnt_async_cnt++;
hca_devp->hd_async_task_cnt++;
mutex_exit(&ibtl_clnt_list_mutex);
(void) ibtl_tell_client_about_new_hca(
new_hcap);
mutex_enter(&ibtl_clnt_list_mutex);
}
break;
}
clntp = clntp->clnt_list_link;
}
clntp = ibtl_clnt_list;
while (clntp != NULL) {
if (clntp->clnt_modinfop->mi_clnt_class == IBT_CM) {
IBTF_DPRINTF_L4(ibtf_handlers, "ibtl_announce_new_hca: "
"calling %s", clntp->clnt_modinfop->mi_clnt_name);
if (clntp->clnt_modinfop->mi_async_handler) {
_NOTE(NO_COMPETING_THREADS_NOW)
new_hcap = kmem_alloc(sizeof (*new_hcap),
KM_SLEEP);
new_hcap->nh_clntp = clntp;
new_hcap->nh_hca_devp = hca_devp;
new_hcap->nh_code = IBT_HCA_ATTACH_EVENT;
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
clntp->clnt_async_cnt++;
hca_devp->hd_async_task_cnt++;
(void) taskq_dispatch(ibtl_async_taskq,
ibtl_tell_client_about_new_hca, new_hcap,
TQ_SLEEP);
}
break;
}
clntp = clntp->clnt_list_link;
}
if (clntp != NULL)
while (clntp->clnt_async_cnt > 0)
cv_wait(&ibtl_clnt_cv, &ibtl_clnt_list_mutex);
clntp = ibtl_clnt_list;
while (clntp != NULL) {
if ((clntp->clnt_modinfop->mi_clnt_class != IBT_DM) &&
(clntp->clnt_modinfop->mi_clnt_class != IBT_CM) &&
(clntp->clnt_modinfop->mi_clnt_class != IBT_IBMA)) {
IBTF_DPRINTF_L4(ibtf_handlers,
"ibtl_announce_new_hca: Calling %s ",
clntp->clnt_modinfop->mi_clnt_name);
if (clntp->clnt_modinfop->mi_async_handler) {
_NOTE(NO_COMPETING_THREADS_NOW)
new_hcap = kmem_alloc(sizeof (*new_hcap),
KM_SLEEP);
new_hcap->nh_clntp = clntp;
new_hcap->nh_hca_devp = hca_devp;
new_hcap->nh_code = IBT_HCA_ATTACH_EVENT;
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
clntp->clnt_async_cnt++;
hca_devp->hd_async_task_cnt++;
(void) taskq_dispatch(ibtl_async_taskq,
ibtl_tell_client_about_new_hca, new_hcap,
TQ_SLEEP);
}
}
clntp = clntp->clnt_list_link;
}
/* wait for all tasks to complete */
while (hca_devp->hd_async_task_cnt != 0)
cv_wait(&hca_devp->hd_async_task_cv, &ibtl_clnt_list_mutex);
/* wakeup thread that may be waiting to send an HCA async */
ASSERT(hca_devp->hd_async_busy == 1);
hca_devp->hd_async_busy = 0;
cv_broadcast(&hca_devp->hd_async_busy_cv);
mutex_exit(&ibtl_clnt_list_mutex);
}
/*
* ibtl_detach_all_clients:
*
* Return value - 0 for Success, 1 for Failure
*
* o First detach general clients.
*
* o Next detach these clients
* IBCM
* IBDM
*
* o Finally, detach this client
* IBMA
*/
int
ibtl_detach_all_clients(ibtl_hca_devinfo_t *hca_devp)
{
ib_guid_t hcaguid = hca_devp->hd_hca_attr->hca_node_guid;
ibtl_hca_t *ibt_hca;
ibtl_clnt_t *clntp;
int retval;
IBTF_DPRINTF_L2(ibtf_handlers, "ibtl_detach_all_clients(%llX)",
hcaguid);
ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
while (hca_devp->hd_async_busy)
cv_wait(&hca_devp->hd_async_busy_cv, &ibtl_clnt_list_mutex);
hca_devp->hd_async_busy = 1;
/* First inform general clients asynchronously */
hca_devp->hd_async_event.ev_hca_guid = hcaguid;
hca_devp->hd_async_event.ev_fma_ena = 0;
hca_devp->hd_async_event.ev_chan_hdl = NULL;
hca_devp->hd_async_event.ev_cq_hdl = NULL;
hca_devp->hd_async_code = IBT_HCA_DETACH_EVENT;
ibt_hca = hca_devp->hd_clnt_list;
while (ibt_hca != NULL) {
clntp = ibt_hca->ha_clnt_devp;
if (IBTL_GENERIC_CLIENT(clntp)) {
++ibt_hca->ha_clnt_devp->clnt_async_cnt;
mutex_enter(&ibtl_async_mutex);
ibt_hca->ha_async_cnt++;
mutex_exit(&ibtl_async_mutex);
hca_devp->hd_async_task_cnt++;
(void) taskq_dispatch(ibtl_async_taskq,
ibtl_hca_client_async_task, ibt_hca, TQ_SLEEP);
}
ibt_hca = ibt_hca->ha_clnt_link;
}
/* wait for all clients to complete */
while (hca_devp->hd_async_task_cnt != 0) {
cv_wait(&hca_devp->hd_async_task_cv, &ibtl_clnt_list_mutex);
}
/* Go thru the clients and check if any have not closed this HCA. */
retval = 0;
ibt_hca = hca_devp->hd_clnt_list;
while (ibt_hca != NULL) {
clntp = ibt_hca->ha_clnt_devp;
if (IBTL_GENERIC_CLIENT(clntp)) {
IBTF_DPRINTF_L2(ibtf_handlers,
"ibtl_detach_all_clients: "
"client '%s' failed to close the HCA.",
ibt_hca->ha_clnt_devp->clnt_modinfop->mi_clnt_name);
retval = 1;
}
ibt_hca = ibt_hca->ha_clnt_link;
}
if (retval == 1)
goto bailout;
/* Next inform IBDM asynchronously */
ibt_hca = hca_devp->hd_clnt_list;
while (ibt_hca != NULL) {
clntp = ibt_hca->ha_clnt_devp;
if (clntp->clnt_modinfop->mi_clnt_class == IBT_DM) {
++ibt_hca->ha_clnt_devp->clnt_async_cnt;
mutex_enter(&ibtl_async_mutex);
ibt_hca->ha_async_cnt++;
mutex_exit(&ibtl_async_mutex);
hca_devp->hd_async_task_cnt++;
mutex_exit(&ibtl_clnt_list_mutex);
ibtl_hca_client_async_task(ibt_hca);
mutex_enter(&ibtl_clnt_list_mutex);
break;
}
ibt_hca = ibt_hca->ha_clnt_link;
}
/*
* Next inform IBCM.
* As IBCM doesn't perform ibt_open_hca(), IBCM will not be
* accessible via hca_devp->hd_clnt_list.
* ibtl_cm_async_handler will NOT be NULL, if IBCM is registered.
*/
if (ibtl_cm_async_handler) {
ibtl_tell_mgr(hca_devp, ibtl_cm_async_handler,
ibtl_cm_clnt_private);
/* wait for all tasks to complete */
while (hca_devp->hd_async_task_cnt != 0)
cv_wait(&hca_devp->hd_async_task_cv,
&ibtl_clnt_list_mutex);
}
/* Go thru the clients and check if any have not closed this HCA. */
retval = 0;
ibt_hca = hca_devp->hd_clnt_list;
while (ibt_hca != NULL) {
clntp = ibt_hca->ha_clnt_devp;
if (clntp->clnt_modinfop->mi_clnt_class != IBT_IBMA) {
IBTF_DPRINTF_L2(ibtf_handlers,
"ibtl_detach_all_clients: "
"client '%s' failed to close the HCA.",
ibt_hca->ha_clnt_devp->clnt_modinfop->mi_clnt_name);
retval = 1;
}
ibt_hca = ibt_hca->ha_clnt_link;
}
if (retval == 1)
goto bailout;
/* Finally, inform IBMA */
ibt_hca = hca_devp->hd_clnt_list;
while (ibt_hca != NULL) {
clntp = ibt_hca->ha_clnt_devp;
if (clntp->clnt_modinfop->mi_clnt_class == IBT_IBMA) {
++ibt_hca->ha_clnt_devp->clnt_async_cnt;
mutex_enter(&ibtl_async_mutex);
ibt_hca->ha_async_cnt++;
mutex_exit(&ibtl_async_mutex);
hca_devp->hd_async_task_cnt++;
(void) taskq_dispatch(ibtl_async_taskq,
ibtl_hca_client_async_task, ibt_hca, TQ_SLEEP);
} else
IBTF_DPRINTF_L2(ibtf_handlers,
"ibtl_detach_all_clients: "
"client '%s' is unexpectedly on the client list",
ibt_hca->ha_clnt_devp->clnt_modinfop->mi_clnt_name);
ibt_hca = ibt_hca->ha_clnt_link;
}
/* wait for IBMA to complete */
while (hca_devp->hd_async_task_cnt != 0) {
cv_wait(&hca_devp->hd_async_task_cv, &ibtl_clnt_list_mutex);
}
/* Check if this HCA's client list is empty. */
ibt_hca = hca_devp->hd_clnt_list;
if (ibt_hca != NULL) {
IBTF_DPRINTF_L2(ibtf_handlers,
"ibtl_detach_all_clients: "
"client '%s' failed to close the HCA.",
ibt_hca->ha_clnt_devp->clnt_modinfop->mi_clnt_name);
retval = 1;
} else
retval = 0;
bailout:
if (retval) {
hca_devp->hd_state = IBTL_HCA_DEV_ATTACHED; /* fix hd_state */
mutex_exit(&ibtl_clnt_list_mutex);
ibtl_announce_new_hca(hca_devp);
mutex_enter(&ibtl_clnt_list_mutex);
} else {
hca_devp->hd_async_busy = 0;
cv_broadcast(&hca_devp->hd_async_busy_cv);
}
return (retval);
}
void
ibtl_free_clnt_async_check(ibtl_clnt_t *clntp)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_free_clnt_async_check(%p)", clntp);
ASSERT(MUTEX_HELD(&ibtl_clnt_list_mutex));
/* wait for all asyncs based on "ibtl_clnt_list" to complete */
while (clntp->clnt_async_cnt != 0) {
cv_wait(&ibtl_clnt_cv, &ibtl_clnt_list_mutex);
}
}
static void
ibtl_dec_clnt_async_cnt(ibtl_clnt_t *clntp)
{
mutex_enter(&ibtl_clnt_list_mutex);
if (--clntp->clnt_async_cnt == 0) {
cv_broadcast(&ibtl_clnt_cv);
}
mutex_exit(&ibtl_clnt_list_mutex);
}
static void
ibtl_inc_clnt_async_cnt(ibtl_clnt_t *clntp)
{
mutex_enter(&ibtl_clnt_list_mutex);
++clntp->clnt_async_cnt;
mutex_exit(&ibtl_clnt_list_mutex);
}
/*
* Functions and data structures to inform clients that a notification
* has occurred about Multicast Groups that might interest them.
*/
struct ibtl_sm_notice {
ibt_clnt_hdl_t np_ibt_hdl;
ib_gid_t np_sgid;
ibt_subnet_event_code_t np_code;
ibt_subnet_event_t np_event;
};
static void
ibtl_sm_notice_task(void *arg)
{
struct ibtl_sm_notice *noticep = (struct ibtl_sm_notice *)arg;
ibt_clnt_hdl_t ibt_hdl = noticep->np_ibt_hdl;
ibt_sm_notice_handler_t sm_notice_handler;
sm_notice_handler = ibt_hdl->clnt_sm_trap_handler;
if (sm_notice_handler != NULL)
sm_notice_handler(ibt_hdl->clnt_sm_trap_handler_arg,
noticep->np_sgid, noticep->np_code, ¬icep->np_event);
kmem_free(noticep, sizeof (*noticep));
ibtl_dec_clnt_async_cnt(ibt_hdl);
}
/*
* Inform the client that MCG notices are not working at this time.
*/
void
ibtl_cm_sm_notice_init_failure(ibtl_cm_sm_init_fail_t *ifail)
{
ibt_clnt_hdl_t ibt_hdl = ifail->smf_ibt_hdl;
struct ibtl_sm_notice *noticep;
ib_gid_t *sgidp = &ifail->smf_sgid[0];
int i;
for (i = 0; i < ifail->smf_num_sgids; i++) {
_NOTE(NO_COMPETING_THREADS_NOW)
noticep = kmem_zalloc(sizeof (*noticep), KM_SLEEP);
noticep->np_ibt_hdl = ibt_hdl;
noticep->np_sgid = *sgidp++;
noticep->np_code = IBT_SM_EVENT_UNAVAILABLE;
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
ibtl_inc_clnt_async_cnt(ibt_hdl);
(void) taskq_dispatch(ibtl_async_taskq,
ibtl_sm_notice_task, noticep, TQ_SLEEP);
}
}
/*
* Inform all clients of the event.
*/
void
ibtl_cm_sm_notice_handler(ib_gid_t sgid, ibt_subnet_event_code_t code,
ibt_subnet_event_t *event)
{
_NOTE(NO_COMPETING_THREADS_NOW)
struct ibtl_sm_notice *noticep;
ibtl_clnt_t *clntp;
mutex_enter(&ibtl_clnt_list_mutex);
clntp = ibtl_clnt_list;
while (clntp != NULL) {
if (clntp->clnt_sm_trap_handler) {
noticep = kmem_zalloc(sizeof (*noticep), KM_SLEEP);
noticep->np_ibt_hdl = clntp;
noticep->np_sgid = sgid;
noticep->np_code = code;
noticep->np_event = *event;
++clntp->clnt_async_cnt;
(void) taskq_dispatch(ibtl_async_taskq,
ibtl_sm_notice_task, noticep, TQ_SLEEP);
}
clntp = clntp->clnt_list_link;
}
mutex_exit(&ibtl_clnt_list_mutex);
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
}
/*
* Record the handler for this client.
*/
void
ibtl_cm_set_sm_notice_handler(ibt_clnt_hdl_t ibt_hdl,
ibt_sm_notice_handler_t sm_notice_handler, void *private)
{
_NOTE(NO_COMPETING_THREADS_NOW)
ibt_hdl->clnt_sm_trap_handler = sm_notice_handler;
ibt_hdl->clnt_sm_trap_handler_arg = private;
#ifndef lint
_NOTE(COMPETING_THREADS_NOW)
#endif
}
/*
* ibtl_another_cq_handler_in_thread()
*
* Conditionally increase the number of cq_threads.
* The number of threads grows, based on the number of cqs using threads.
*
* The table below controls the number of threads as follows:
*
* Number of CQs Number of cq_threads
* 0 0
* 1 1
* 2-3 2
* 4-5 3
* 6-9 4
* 10-15 5
* 16-23 6
* 24-31 7
* 32+ 8
*/
#define IBTL_CQ_MAXTHREADS 8
static uint8_t ibtl_cq_scaling[IBTL_CQ_MAXTHREADS] = {
1, 2, 4, 6, 10, 16, 24, 32
};
static kt_did_t ibtl_cq_did[IBTL_CQ_MAXTHREADS];
void
ibtl_another_cq_handler_in_thread(void)
{
kthread_t *t;
int my_idx;
mutex_enter(&ibtl_cq_mutex);
if ((ibtl_cq_threads == IBTL_CQ_MAXTHREADS) ||
(++ibtl_cqs_using_threads < ibtl_cq_scaling[ibtl_cq_threads])) {
mutex_exit(&ibtl_cq_mutex);
return;
}
my_idx = ibtl_cq_threads++;
mutex_exit(&ibtl_cq_mutex);
t = thread_create(NULL, 0, ibtl_cq_thread, NULL, 0, &p0, TS_RUN,
ibtl_pri - 1);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibtl_cq_did))
ibtl_cq_did[my_idx] = t->t_did; /* save for thread_join() */
_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibtl_cq_did))
}
void
ibtl_thread_init(void)
{
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_thread_init()");
mutex_init(&ibtl_async_mutex, NULL, MUTEX_DEFAULT, NULL);
cv_init(&ibtl_async_cv, NULL, CV_DEFAULT, NULL);
cv_init(&ibtl_clnt_cv, NULL, CV_DEFAULT, NULL);
mutex_init(&ibtl_cq_mutex, NULL, MUTEX_DEFAULT, NULL);
cv_init(&ibtl_cq_cv, NULL, CV_DEFAULT, NULL);
}
void
ibtl_thread_init2(void)
{
int i;
static int initted = 0;
kthread_t *t;
mutex_enter(&ibtl_async_mutex);
if (initted == 1) {
mutex_exit(&ibtl_async_mutex);
return;
}
initted = 1;
mutex_exit(&ibtl_async_mutex);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibtl_async_did))
ibtl_async_did = kmem_zalloc(ibtl_async_thread_init * sizeof (kt_did_t),
KM_SLEEP);
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_thread_init2()");
for (i = 0; i < ibtl_async_thread_init; i++) {
t = thread_create(NULL, 0, ibtl_async_thread, NULL, 0, &p0,
TS_RUN, ibtl_pri - 1);
ibtl_async_did[i] = t->t_did; /* thread_join() */
}
_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibtl_async_did))
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibtl_cq_threads))
for (i = 0; i < ibtl_cq_threads; i++) {
t = thread_create(NULL, 0, ibtl_cq_thread, NULL, 0, &p0,
TS_RUN, ibtl_pri - 1);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibtl_cq_did))
ibtl_cq_did[i] = t->t_did; /* save for thread_join() */
_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibtl_cq_did))
}
_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibtl_cq_threads))
}
void
ibtl_thread_fini(void)
{
int i;
IBTF_DPRINTF_L3(ibtf_handlers, "ibtl_thread_fini()");
/* undo the work done by ibtl_thread_init() */
mutex_enter(&ibtl_cq_mutex);
ibtl_cq_thread_exit = IBTL_THREAD_EXIT;
cv_broadcast(&ibtl_cq_cv);
mutex_exit(&ibtl_cq_mutex);
mutex_enter(&ibtl_async_mutex);
ibtl_async_thread_exit = IBTL_THREAD_EXIT;
cv_broadcast(&ibtl_async_cv);
mutex_exit(&ibtl_async_mutex);
_NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(ibtl_cq_threads))
for (i = 0; i < ibtl_cq_threads; i++)
thread_join(ibtl_cq_did[i]);
_NOTE(NOW_VISIBLE_TO_OTHER_THREADS(ibtl_cq_threads))
if (ibtl_async_did) {
for (i = 0; i < ibtl_async_thread_init; i++)
thread_join(ibtl_async_did[i]);
kmem_free(ibtl_async_did,
ibtl_async_thread_init * sizeof (kt_did_t));
}
mutex_destroy(&ibtl_cq_mutex);
cv_destroy(&ibtl_cq_cv);
mutex_destroy(&ibtl_async_mutex);
cv_destroy(&ibtl_async_cv);
cv_destroy(&ibtl_clnt_cv);
}
/* ARGSUSED */
ibt_status_t ibtl_dummy_node_info_cb(ib_guid_t hca_guid, uint8_t port,
ib_lid_t lid, ibt_node_info_t *node_info)
{
return (IBT_SUCCESS);
}
|