1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
|
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Interface for Serengeti IOSRAM mailbox
* OS <-> SC communication protocol
*/
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/kmem.h>
#include <sys/uadmin.h>
#include <sys/machsystm.h>
#include <sys/disp.h>
#include <sys/taskq.h>
#include <sys/sgevents.h>
#include <sys/sgsbbc_priv.h>
#include <sys/sgsbbc_iosram_priv.h>
#include <sys/sgsbbc_mailbox_priv.h>
#include <sys/plat_ecc_unum.h>
#include <sys/plat_ecc_dimm.h>
#include <sys/serengeti.h>
#include <sys/fm/util.h>
#include <sys/promif.h>
#include <sys/plat_datapath.h>
sbbc_mailbox_t *master_mbox = NULL;
/*
* Panic Shutdown event support
*/
static kmutex_t panic_hdlr_lock;
/*
* The ID of the soft interrupt which triggers the bringing down of a Domain
* when a PANIC_SHUTDOWN event is received.
*/
static ddi_softintr_t panic_softintr_id = 0;
static sg_panic_shutdown_t panic_payload;
static sbbc_msg_t panic_payload_msg;
/*
* A queue for making sure outgoing messages are in order as ScApp
* does not support interleaving messages.
*/
static kcondvar_t outbox_queue;
static kmutex_t outbox_queue_lock;
/*
* Handle unsolicited capability message.
*/
static plat_capability_data_t cap_payload;
static sbbc_msg_t cap_payload_msg;
static kmutex_t cap_msg_hdlr_lock;
/*
* Datapath error and fault messages arrive unsolicited. The message data
* is contained in a plat_datapath_info_t structure.
*/
typedef struct {
uint8_t type; /* CDS, DX, CP */
uint8_t pad; /* for alignment */
uint16_t cpuid; /* Safari ID of base CPU */
uint32_t t_value; /* SERD timeout threshold (seconds) */
} plat_datapath_info_t;
/*
* Unsolicited datapath error messages are processed via a soft interrupt,
* triggered in unsolicited interrupt processing.
*/
static ddi_softintr_t dp_softintr_id = 0;
static kmutex_t dp_hdlr_lock;
static plat_datapath_info_t dp_payload;
static sbbc_msg_t dp_payload_msg;
static char *dperrtype[] = {
DP_ERROR_CDS,
DP_ERROR_DX,
DP_ERROR_RP
};
/*
* Variable indicating if we are already processing requests.
* Setting this value must be protected by outbox_queue_lock.
*/
static int outbox_busy = 0;
/*
* local stuff
*/
static int sbbc_mbox_send_msg(sbbc_msg_t *, int, uint_t, time_t, clock_t);
static int sbbc_mbox_recv_msg();
static int mbox_write(struct sbbc_mbox_header *,
struct sbbc_fragment *, sbbc_msg_t *);
static int mbox_read(struct sbbc_mbox_header *, struct sbbc_fragment *,
sbbc_msg_t *);
static int mbox_has_free_space(struct sbbc_mbox_header *);
static void mbox_skip_next_msg(struct sbbc_mbox_header *);
static int mbox_read_header(uint32_t, struct sbbc_mbox_header *);
static void mbox_update_header(uint32_t, struct sbbc_mbox_header *);
static int mbox_read_frag(struct sbbc_mbox_header *, struct sbbc_fragment *);
static struct sbbc_msg_waiter *mbox_find_waiter(uint16_t, uint32_t);
static void wakeup_next(void);
static uint_t sbbc_panic_shutdown_handler(char *arg);
static uint_t sbbc_do_fast_shutdown(char *arg);
static void sbbc_mbox_post_reg(sbbc_softstate_t *softsp);
static uint_t cap_ecc_msg_handler(char *);
static uint_t sbbc_datapath_error_msg_handler(char *arg);
static uint_t sbbc_datapath_fault_msg_handler(char *arg);
static uint_t sbbc_dp_trans_event(char *arg);
/*
* Interrupt handlers
*/
static int sbbc_mbox_msgin(void);
static int sbbc_mbox_msgout(void);
static int sbbc_mbox_spacein(void);
static int sbbc_mbox_spaceout(void);
/*
* ECC event mailbox message taskq and parameters
*/
static taskq_t *sbbc_ecc_mbox_taskq = NULL;
static int sbbc_ecc_mbox_taskq_errs = 0;
static int sbbc_ecc_mbox_send_errs = 0;
static int sbbc_ecc_mbox_inval_errs = 0;
static int sbbc_ecc_mbox_other_errs = 0;
int sbbc_ecc_mbox_err_throttle = ECC_MBOX_TASKQ_ERR_THROTTLE;
/*
* Called when SBBC driver is loaded
* Initialise global mailbox stuff, etc
*/
void
sbbc_mbox_init()
{
int i;
master_mbox = kmem_zalloc(sizeof (sbbc_mailbox_t), KM_NOSLEEP);
if (master_mbox == NULL) {
cmn_err(CE_PANIC, "Can't allocate memory for mailbox\n");
}
/*
* mutex'es for the wait-lists
*/
for (i = 0; i < SBBC_MBOX_MSG_TYPES; i++) {
mutex_init(&master_mbox->mbox_wait_lock[i],
NULL, MUTEX_DEFAULT, NULL);
master_mbox->mbox_wait_list[i] = NULL;
}
for (i = 0; i < SBBC_MBOX_MSG_TYPES; i++)
master_mbox->intrs[i] = NULL;
/*
* Two mailbox channels SC -> OS , read-only
* OS -> SC, read/write
*/
master_mbox->mbox_in = kmem_zalloc(sizeof (sbbc_mbox_t), KM_NOSLEEP);
if (master_mbox->mbox_in == NULL) {
cmn_err(CE_PANIC,
"Can't allocate memory for inbound mailbox\n");
}
master_mbox->mbox_out = kmem_zalloc(sizeof (sbbc_mbox_t), KM_NOSLEEP);
if (master_mbox->mbox_out == NULL) {
cmn_err(CE_PANIC,
"Can't allocate memory for outbound mailbox\n");
}
mutex_init(&master_mbox->mbox_in->mb_lock, NULL,
MUTEX_DEFAULT, NULL);
mutex_init(&master_mbox->mbox_out->mb_lock, NULL,
MUTEX_DEFAULT, NULL);
/*
* Add PANIC_SHUTDOWN Event mutex
*/
mutex_init(&panic_hdlr_lock, NULL, MUTEX_DEFAULT, NULL);
/* Initialize datapath error message handler mutex */
mutex_init(&dp_hdlr_lock, NULL, MUTEX_DEFAULT, NULL);
/* Initialize capability message handler event mutex */
mutex_init(&cap_msg_hdlr_lock, NULL, MUTEX_DEFAULT, NULL);
/*
* NOT USED YET
*/
master_mbox->mbox_in->mb_type =
master_mbox->mbox_out->mb_type = 0;
cv_init(&outbox_queue, NULL, CV_DEFAULT, NULL);
mutex_init(&outbox_queue_lock, NULL, MUTEX_DEFAULT, NULL);
}
/*
* called when the SBBC driver is unloaded
*/
void
sbbc_mbox_fini()
{
int i;
int err;
/*
* destroy ECC event mailbox taskq
*/
if (sbbc_ecc_mbox_taskq != NULL) {
taskq_destroy(sbbc_ecc_mbox_taskq);
sbbc_ecc_mbox_taskq = NULL;
sbbc_ecc_mbox_taskq_errs = 0;
}
/*
* unregister interrupts
*/
(void) iosram_unreg_intr(SBBC_MAILBOX_IN);
(void) iosram_unreg_intr(SBBC_MAILBOX_IN);
(void) iosram_unreg_intr(SBBC_MAILBOX_SPACE_IN);
(void) iosram_unreg_intr(SBBC_MAILBOX_SPACE_OUT);
/*
* Remove Panic Shutdown and Datapath Error event support.
*
* NOTE: If we have not added the soft interrupt handlers for these
* then we know that we have not registered the event handlers either.
*/
if (panic_softintr_id != 0) {
ddi_remove_softintr(panic_softintr_id);
err = sbbc_mbox_unreg_intr(MBOX_EVENT_PANIC_SHUTDOWN,
sbbc_panic_shutdown_handler);
if (err != 0) {
cmn_err(CE_WARN, "Failed to unreg Panic Shutdown "
"handler. Err=%d", err);
}
}
if (dp_softintr_id != 0) {
ddi_remove_softintr(dp_softintr_id);
err = sbbc_mbox_unreg_intr(MBOX_EVENT_DP_ERROR,
sbbc_datapath_error_msg_handler);
err |= sbbc_mbox_unreg_intr(MBOX_EVENT_DP_FAULT,
sbbc_datapath_fault_msg_handler);
if (err != 0) {
cmn_err(CE_WARN, "Failed to unreg Datapath Error "
"handler. Err=%d", err);
}
}
/*
* destroy all its mutex'es, lists etc
*/
/*
* mutex'es for the wait-lists
*/
for (i = 0; i < SBBC_MBOX_MSG_TYPES; i++) {
mutex_destroy(&master_mbox->mbox_wait_lock[i]);
}
mutex_destroy(&master_mbox->mbox_in->mb_lock);
mutex_destroy(&master_mbox->mbox_out->mb_lock);
mutex_destroy(&panic_hdlr_lock);
mutex_destroy(&dp_hdlr_lock);
kmem_free(master_mbox->mbox_in, sizeof (sbbc_mbox_t));
kmem_free(master_mbox->mbox_out, sizeof (sbbc_mbox_t));
kmem_free(master_mbox, sizeof (sbbc_mailbox_t));
cv_destroy(&outbox_queue);
mutex_destroy(&outbox_queue_lock);
err = sbbc_mbox_unreg_intr(INFO_MBOX, cap_ecc_msg_handler);
if (err != 0) {
cmn_err(CE_WARN, "Failed to unregister capability message "
"handler. Err=%d", err);
}
mutex_destroy(&cap_msg_hdlr_lock);
}
/*
* Update iosram_sbbc to the new softstate after a tunnel switch.
* Move software interrupts from the old dip to the new dip.
*/
int
sbbc_mbox_switch(sbbc_softstate_t *softsp)
{
sbbc_intrs_t *intr;
int msg_type;
int rc = 0;
int err;
if (master_mbox == NULL)
return (ENXIO);
ASSERT(MUTEX_HELD(&master_iosram->iosram_lock));
for (msg_type = 0; msg_type < SBBC_MBOX_MSG_TYPES; msg_type++) {
for (intr = master_mbox->intrs[msg_type]; intr != NULL;
intr = intr->sbbc_intr_next) {
if (intr->sbbc_intr_id) {
ddi_remove_softintr(intr->sbbc_intr_id);
if (ddi_add_softintr(softsp->dip,
DDI_SOFTINT_HIGH,
&intr->sbbc_intr_id, NULL, NULL,
intr->sbbc_handler, intr->sbbc_arg)
!= DDI_SUCCESS) {
cmn_err(CE_WARN,
"Can't add SBBC mailbox "
"softint for msg_type %x\n",
msg_type);
rc = ENXIO;
}
}
}
}
/*
* Add PANIC_SHUTDOWN Event handler
*/
if (panic_softintr_id) {
ddi_remove_softintr(panic_softintr_id);
err = ddi_add_softintr(softsp->dip, DDI_SOFTINT_LOW,
&panic_softintr_id, NULL, NULL,
sbbc_do_fast_shutdown, NULL);
if (err != DDI_SUCCESS) {
cmn_err(CE_WARN, "Failed to register Panic "
"Shutdown handler. Err=%d", err);
(void) sbbc_mbox_unreg_intr(MBOX_EVENT_PANIC_SHUTDOWN,
sbbc_panic_shutdown_handler);
rc = ENXIO;
}
}
/*
* Add Datapath Error Event handler
*/
if (dp_softintr_id) {
ddi_remove_softintr(dp_softintr_id);
err = ddi_add_softintr(softsp->dip, DDI_SOFTINT_LOW,
&dp_softintr_id, NULL, NULL,
sbbc_dp_trans_event, NULL);
if (err != DDI_SUCCESS) {
cmn_err(CE_WARN, "Failed to register Datapath "
"Error Event handler. Err=%d", err);
(void) sbbc_mbox_unreg_intr(MBOX_EVENT_DP_ERROR,
sbbc_datapath_error_msg_handler);
(void) sbbc_mbox_unreg_intr(MBOX_EVENT_DP_FAULT,
sbbc_datapath_fault_msg_handler);
rc = ENXIO;
}
}
return (rc);
}
/*
* Called when the IOSRAM tunnel is created for the 'chosen' node.
*
* Read the mailbox header from the IOSRAM
* tunnel[SBBC_MAILBOX_KEY]
* Register the mailbox interrupt handlers
* for messages in/space etc
*/
int
sbbc_mbox_create(sbbc_softstate_t *softsp)
{
struct sbbc_mbox_header header;
int i;
int err;
int rc = 0;
/*
* This function should only be called once when
* the chosen node is initialized.
*/
ASSERT(MUTEX_HELD(&chosen_lock));
if (master_mbox == NULL)
return (ENXIO);
/*
* read the header at offset 0
* check magic/version etc
*/
if (rc = iosram_read(SBBC_MAILBOX_KEY, 0, (caddr_t)&header,
sizeof (struct sbbc_mbox_header))) {
return (rc);
}
/*
* add the interrupt handlers for the mailbox
* interrupts
*/
for (i = 0; i < MBOX_INTRS; i++) {
sbbc_intrfunc_t intr_handler;
uint_t *state;
kmutex_t *lock;
uint32_t intr_num;
switch (i) {
case MBOX_MSGIN_INTR:
intr_handler = (sbbc_intrfunc_t)sbbc_mbox_msgin;
intr_num = SBBC_MAILBOX_IN;
break;
case MBOX_MSGOUT_INTR:
intr_handler = (sbbc_intrfunc_t)sbbc_mbox_msgout;
intr_num = SBBC_MAILBOX_OUT;
break;
case MBOX_SPACEIN_INTR:
intr_handler = (sbbc_intrfunc_t)sbbc_mbox_spacein;
intr_num = SBBC_MAILBOX_SPACE_IN;
break;
case MBOX_SPACEOUT_INTR:
intr_handler = (sbbc_intrfunc_t)sbbc_mbox_spaceout;
intr_num = SBBC_MAILBOX_SPACE_OUT;
break;
}
state = (uint_t *)&master_mbox->intr_state[i].mbox_intr_state;
lock = &master_mbox->intr_state[i].mbox_intr_lock;
if (iosram_reg_intr(intr_num, intr_handler, (caddr_t)NULL,
state, lock)) {
cmn_err(CE_WARN,
"Can't register Mailbox interrupts \n");
}
}
/*
* Add PANIC_SHUTDOWN Event handler
*/
panic_payload_msg.msg_buf = (caddr_t)&panic_payload;
panic_payload_msg.msg_len = sizeof (panic_payload);
err = ddi_add_softintr(softsp->dip, DDI_SOFTINT_LOW, &panic_softintr_id,
NULL, NULL, sbbc_do_fast_shutdown, NULL);
if (err == DDI_SUCCESS) {
err = sbbc_mbox_reg_intr(MBOX_EVENT_PANIC_SHUTDOWN,
sbbc_panic_shutdown_handler, &panic_payload_msg,
NULL, &panic_hdlr_lock);
if (err != 0) {
cmn_err(CE_WARN, "Failed to register Panic "
"Shutdown handler. Err=%d", err);
}
} else {
cmn_err(CE_WARN, "Failed to add Panic Shutdown "
"softintr handler");
}
/*
* Add Unsolicited Datapath Error Events handler
*/
dp_payload_msg.msg_buf = (caddr_t)&dp_payload;
dp_payload_msg.msg_len = sizeof (dp_payload);
err = ddi_add_softintr(softsp->dip, DDI_SOFTINT_LOW, &dp_softintr_id,
NULL, NULL, sbbc_dp_trans_event, NULL);
if (err == DDI_SUCCESS) {
err = sbbc_mbox_reg_intr(MBOX_EVENT_DP_ERROR,
sbbc_datapath_error_msg_handler, &dp_payload_msg,
NULL, &dp_hdlr_lock);
err |= sbbc_mbox_reg_intr(MBOX_EVENT_DP_FAULT,
sbbc_datapath_fault_msg_handler, &dp_payload_msg,
NULL, &dp_hdlr_lock);
if (err != 0) {
cmn_err(CE_WARN, "Failed to register Datapath "
"error handler. Err=%d", err);
}
} else {
cmn_err(CE_WARN, "Failed to add Datapath error "
"softintr handler");
}
/*
* Register an interrupt handler with the sgbbc driver for the
* unsolicited INFO_MBOX response for the capability bitmap.
* This message is expected whenever the SC is (re)booted or
* failed over.
*/
cap_payload_msg.msg_buf = (caddr_t)&cap_payload;
cap_payload_msg.msg_len = sizeof (cap_payload);
err = sbbc_mbox_reg_intr(INFO_MBOX, cap_ecc_msg_handler,
&cap_payload_msg, NULL, &cap_msg_hdlr_lock);
if (err != 0) {
cmn_err(CE_WARN, "Failed to register capability message"
" handler with Err=%d", err);
}
/*
* Now is the opportunity to register
* the deferred mbox intrs.
*/
sbbc_mbox_post_reg(softsp);
return (rc);
}
/*
* Called when chosen IOSRAM is initialized
* to register the deferred mbox intrs.
*/
static void
sbbc_mbox_post_reg(sbbc_softstate_t *softsp)
{
uint32_t msg_type;
sbbc_intrs_t *intr;
ASSERT(master_mbox);
for (msg_type = 0; msg_type < SBBC_MBOX_MSG_TYPES; msg_type++) {
intr = master_mbox->intrs[msg_type];
while (intr != NULL) {
if (!intr->registered) {
SGSBBC_DBG_INTR(CE_CONT, "sbbc_mbox_post_reg: "
"postreg for msgtype=%x\n", msg_type);
if (ddi_add_softintr(softsp->dip,
DDI_SOFTINT_HIGH, &intr->sbbc_intr_id,
NULL, NULL, intr->sbbc_handler,
(caddr_t)intr->sbbc_arg)
!= DDI_SUCCESS) {
cmn_err(CE_WARN, "Can't add SBBC "
"deferred mailbox softint \n");
} else
intr->registered = 1;
}
intr = intr->sbbc_intr_next;
}
}
}
/*
* Register a handler for a message type
* NB NB NB
* arg must be either NULL or the address of a sbbc_fragment
* pointer
*/
int
sbbc_mbox_reg_intr(uint32_t msg_type, sbbc_intrfunc_t intr_handler,
sbbc_msg_t *arg, uint_t *state, kmutex_t *lock)
{
sbbc_intrs_t *intr, *previntr;
int rc = 0;
/*
* Validate arguments
*/
if (msg_type >= SBBC_MBOX_MSG_TYPES)
return (EINVAL);
/*
* Verify that we have already set up the master sbbc
*/
if (master_iosram == NULL || master_mbox == NULL)
return (ENXIO);
mutex_enter(&master_iosram->iosram_lock);
msg_type &= SBBC_MSG_TYPE_MASK;
previntr = intr = master_mbox->intrs[msg_type];
/* Find the end of the link list */
while (intr != NULL && intr->sbbc_handler != intr_handler) {
previntr = intr;
intr = intr->sbbc_intr_next;
}
/* Return if the handler has been registered */
if (intr != NULL) {
mutex_exit(&master_iosram->iosram_lock);
return (EBUSY);
}
/*
* The requested handler has not been installed.
* Allocate some memory.
*/
intr = kmem_zalloc(sizeof (sbbc_intrs_t), KM_SLEEP);
intr->sbbc_handler = intr_handler;
intr->sbbc_arg = (caddr_t)arg;
intr->sbbc_intr_state = state;
intr->sbbc_intr_lock = lock;
intr->sbbc_intr_next = NULL;
/* not registered yet */
intr->registered = 0;
if (previntr != NULL)
previntr->sbbc_intr_next = intr;
else
master_mbox->intrs[msg_type] = intr;
/*
* register only if the chosen IOSRAM is
* initialized, otherwise defer the registration
* until IOSRAM initialization.
*/
if (master_iosram->iosram_sbbc) {
if (ddi_add_softintr(master_iosram->iosram_sbbc->dip,
DDI_SOFTINT_HIGH,
&intr->sbbc_intr_id, NULL, NULL,
intr_handler, (caddr_t)arg) != DDI_SUCCESS) {
cmn_err(CE_WARN, "Can't add SBBC mailbox softint \n");
rc = ENXIO;
} else
intr->registered = 1;
} else {
SGSBBC_DBG_INTR(CE_CONT, "sbbc_mbox_reg_intr: "
"deferring msg=%x registration\n", msg_type);
}
mutex_exit(&master_iosram->iosram_lock);
return (rc);
}
/*
* Unregister a handler for a message type
*/
int
sbbc_mbox_unreg_intr(uint32_t msg_type, sbbc_intrfunc_t intr_handler)
{
sbbc_intrs_t *intr, *previntr, *nextintr;
/*
* Verify that we have already set up the master sbbc
*/
if (master_iosram == NULL || master_mbox == NULL)
return (ENXIO);
msg_type &= SBBC_MSG_TYPE_MASK;
if (msg_type >= SBBC_MBOX_MSG_TYPES ||
intr_handler == (sbbc_intrfunc_t)NULL) {
return (EINVAL);
}
mutex_enter(&master_iosram->iosram_lock);
previntr = intr = master_mbox->intrs[msg_type];
/*
* No handlers installed
*/
if (intr == NULL) {
mutex_exit(&master_iosram->iosram_lock);
return (EINVAL);
}
while (intr != NULL) {
/* Save the next pointer */
nextintr = intr->sbbc_intr_next;
/* Found a match. Remove it from the link list */
if (intr->sbbc_handler == intr_handler) {
if (intr->sbbc_intr_id)
ddi_remove_softintr(intr->sbbc_intr_id);
kmem_free(intr, sizeof (sbbc_intrs_t));
if (previntr != master_mbox->intrs[msg_type])
previntr->sbbc_intr_next = nextintr;
else
master_mbox->intrs[msg_type] = nextintr;
break;
}
/* update pointers */
previntr = intr;
intr = nextintr;
}
mutex_exit(&master_iosram->iosram_lock);
return (0);
}
/*
* Interrupt handlers - one for each mailbox
* interrupt type
*/
/*
* mailbox message received
*/
static int
sbbc_mbox_msgin()
{
mutex_enter(&master_mbox->intr_state[MBOX_MSGIN_INTR].mbox_intr_lock);
master_mbox->intr_state[MBOX_MSGIN_INTR].mbox_intr_state =
SBBC_INTR_RUNNING;
mutex_exit(&master_mbox->intr_state[MBOX_MSGIN_INTR].mbox_intr_lock);
/*
* We are only locking the InBox here, not the whole
* mailbox. This is based on the assumption of
* complete separation of mailboxes - outbox is
* read/write, inbox is read-only.
* We only ever update the producer for the
* outbox and the consumer for the inbox.
*/
mutex_enter(&master_mbox->mbox_in->mb_lock);
for (;;) {
/*
* Get as many incoming messages as possible
*/
while (sbbc_mbox_recv_msg() == 0)
/* empty */;
/*
* send interrupt to SC to let it know that
* space is available over here
*/
(void) iosram_send_intr(SBBC_MAILBOX_SPACE_IN);
mutex_enter(&master_mbox->intr_state[MBOX_MSGIN_INTR].
mbox_intr_lock);
/*
* Read the inbox one more time to see if new messages
* has come in after we exit the loop.
*/
if (sbbc_mbox_recv_msg() == 0) {
mutex_exit(&master_mbox->intr_state[MBOX_MSGIN_INTR].
mbox_intr_lock);
} else {
master_mbox->intr_state[MBOX_MSGIN_INTR].
mbox_intr_state = SBBC_INTR_IDLE;
mutex_exit(&master_mbox->intr_state[MBOX_MSGIN_INTR].
mbox_intr_lock);
break;
}
}
mutex_exit(&master_mbox->mbox_in->mb_lock);
return (DDI_INTR_CLAIMED);
}
/*
* mailbox message sent
*/
static int
sbbc_mbox_msgout()
{
/*
* Should never get this
*/
return (DDI_INTR_CLAIMED);
}
/*
* space in the inbox
*/
static int
sbbc_mbox_spacein()
{
/*
* Should never get this
*/
return (DDI_INTR_CLAIMED);
}
/*
* space in the outbox
*/
static int
sbbc_mbox_spaceout()
{
/*
* cv_broadcast() the threads waiting on the
* outbox's mb_full
*/
mutex_enter(&master_mbox->mbox_out->mb_lock);
cv_broadcast(&master_mbox->mbox_out->mb_full);
mutex_exit(&master_mbox->mbox_out->mb_lock);
return (DDI_INTR_CLAIMED);
}
/*
* Client Interface
*
* The main interface will be
*
* sbbc_mbox_request_response(sbbc_msg_t *request,
* sbbc_msg_t *response, time_t wait_time)
*
* 1) the client calls request_response
* 2) a new unique msg ID is assigned for that msg
* 3) if there is space available in the outbox
* - the request msg is written to the mbox_out mailbox
* and the mailbox info updated.
* - allocate a sbbc_msg_waiter struct for this
* message, initialise the w_cv condvar.
* - get the mailbox mbox_wait_lock mutex for this
* message type
* - the response msg is put on the mbox_wait_list for
* that message type to await the SC's response
* - wait on the w_cv condvar protected by the
* mbox_wait_lock
* - SBBC_MAILBOX_OUT interrupt is sent to the SC
*
* 4) if no space in the outbox,
* - the request message blocks waiting
* for a SBBC_MAILBOX_SPACE_OUT interrupt
* It will block on the mailbox mb_full condvar.
* - go to (3) above
* 5) When we get a SBBC_MAILBOX_IN interrupt.
* - read the message ID of the next message (FIFO)
* - find that ID on the wait list
* - no wait list entry => unsolicited message. If theres
* a handler, trigger it
* - if someone is waiting, read the message in from
* SRAM, handling fragmentation, wraparound, etc
* - if the whole message has been read, signal
* the waiter
* - read next message until mailbox empty
* - send SBBC_MAILBOX_SPACE_IN interrupt to the SC
*
* 6) If a response is required and none is received, the client
* will timeout after <wait_time> seconds and the message
* status will be set to ETIMEDOUT.
*/
int
sbbc_mbox_request_response(sbbc_msg_t *request,
sbbc_msg_t *response, time_t wait_time)
{
struct sbbc_msg_waiter *waiter;
uint_t msg_id;
int rc = 0;
int flags;
uint16_t msg_type;
clock_t stop_time;
clock_t clockleft;
kmutex_t *mbox_wait_lock;
kmutex_t *mb_lock;
static fn_t f = "sbbc_mbox_request_response";
if ((request == NULL) ||
(request->msg_type.type >= SBBC_MBOX_MSG_TYPES) ||
((response != NULL) &&
(response->msg_type.type >= SBBC_MBOX_MSG_TYPES)))
return (EINVAL);
msg_type = request->msg_type.type;
/*
* Verify that we have already set up the master sbbc
*/
if (master_mbox == NULL)
return (ENXIO);
mbox_wait_lock = &master_mbox->mbox_wait_lock[msg_type];
flags = WAIT_FOR_REPLY|WAIT_FOR_SPACE;
/*
* We want to place a lower limit on the shortest amount of time we
* will wait before timing out while communicating with the SC via
* the mailbox.
*/
if (wait_time < sbbc_mbox_min_timeout)
wait_time = sbbc_mbox_default_timeout;
stop_time = ddi_get_lbolt() + wait_time * drv_usectohz(MICROSEC);
/*
* If there is a message being processed, sleep until it is our turn.
*/
mutex_enter(&outbox_queue_lock);
/*
* allocate an ID for this message, let it wrap
* around transparently.
* msg_id == 0 is unsolicited message
*/
msg_id = ++(master_mbox->mbox_msg_id);
if (msg_id == 0)
msg_id = ++(master_mbox->mbox_msg_id);
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x, msg_len = 0x%x\n",
f, msg_id, request->msg_len);
/*
* A new message can actually grab the lock before the thread
* that has just been signaled. Therefore, we need to double
* check to make sure that outbox_busy is not already set
* after we wake up.
*
* Potentially this could mean starvation for certain unfortunate
* threads that keep getting woken up and putting back to sleep.
* But the window of such contention is very small to begin with.
*/
while (outbox_busy) {
clockleft = cv_timedwait(&outbox_queue, &outbox_queue_lock,
stop_time);
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x is woken up\n", f, msg_id);
/*
* If we have timed out, set status to ETIMEOUT and return.
*/
if (clockleft < 0) {
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x has timed out\n",
f, msg_id);
cmn_err(CE_NOTE,
"Timed out obtaining SBBC outbox lock");
request->msg_status = ETIMEDOUT;
if (response != NULL)
response->msg_status = ETIMEDOUT;
mutex_exit(&outbox_queue_lock);
return (ETIMEDOUT);
}
}
outbox_busy = 1;
mutex_exit(&outbox_queue_lock);
/*
* We are only locking the OutBox from here, not the whole
* mailbox. This is based on the assumption of
* complete separation of mailboxes - outbox is
* read/write, inbox is read-only.
* We only ever update the producer for the
* outbox and the consumer for the inbox.
*/
mb_lock = &master_mbox->mbox_out->mb_lock;
mutex_enter(mb_lock);
/*
* No response expected ? Just send the message and return
*/
if (response == NULL) {
rc = sbbc_mbox_send_msg(request, flags, msg_id, wait_time,
stop_time);
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x send rc = %d\n",
f, msg_id, rc);
wakeup_next();
mutex_exit(mb_lock);
request->msg_status = rc;
return (rc);
}
/*
* allocate/initialise a waiter
*/
waiter = kmem_zalloc(sizeof (struct sbbc_msg_waiter), KM_NOSLEEP);
if (waiter == (struct sbbc_msg_waiter *)NULL) {
cmn_err(CE_WARN, "SBBC Mailbox can't allocate waiter\n");
wakeup_next();
mutex_exit(mb_lock);
return (ENOMEM);
}
waiter->w_id = 0; /* Until we get an ID from the send */
waiter->w_msg = response;
waiter->w_msg->msg_status = EINPROGRESS;
cv_init(&waiter->w_cv, NULL, CV_DEFAULT, NULL);
rc = sbbc_mbox_send_msg(request, flags, msg_id, wait_time, stop_time);
wakeup_next();
if (rc != 0) {
request->msg_status = response->msg_status = rc;
mutex_exit(mb_lock);
/* Free the waiter */
cv_destroy(&waiter->w_cv);
kmem_free(waiter, sizeof (struct sbbc_msg_waiter));
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x send rc = %d\n",
f, msg_id, rc);
return (rc);
}
waiter->w_id = msg_id;
/*
* Lock this waiter list and add the waiter
*/
mutex_enter(mbox_wait_lock);
if (master_mbox->mbox_wait_list[msg_type] == NULL) {
master_mbox->mbox_wait_list[msg_type] = waiter;
waiter->w_next = NULL;
} else {
struct sbbc_msg_waiter *tmp;
tmp = master_mbox->mbox_wait_list[msg_type];
master_mbox->mbox_wait_list[msg_type] = waiter;
waiter->w_next = tmp;
}
mutex_exit(mb_lock);
/*
* wait here for a response to our message
* holding the mbox_wait_lock for the list ensures
* that the interrupt handler can't get in before
* we block.
* NOTE: We use the request msg_type for the
* the wait_list. This ensures that the
* msg_type won't change.
*/
clockleft = cv_timedwait(&waiter->w_cv, mbox_wait_lock, stop_time);
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x is woken up for response\n",
f, msg_id);
/*
* If we have timed out, set msg_status to ETIMEDOUT,
* and remove the waiter from the waiter list.
*/
if (clockleft < 0) {
/*
* Remove the waiter from the waiter list.
* If we can't find the waiter in the list,
* 1. msg_status == EINPROGRESS
* It is being processed. We will give it
* a chance to finish.
* 2. msg_status != EINPROGRESS
* It is done processing. We can safely
* remove it.
* If we can find the waiter, it has timed out.
*/
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x has timed out\n",
f, msg_id);
if (mbox_find_waiter(msg_type, msg_id) == NULL) {
if (waiter->w_msg->msg_status == EINPROGRESS) {
SGSBBC_DBG_MBOX("%s: Waiting for msg_id = 0x%x "
"complete.\n", f, msg_id);
cv_wait(&waiter->w_cv, mbox_wait_lock);
}
} else {
SGSBBC_DBG_MBOX("%s: setting msg_id = 0x%x "
"to ETIMEDOUT\n", f, msg_id);
cmn_err(CE_NOTE, "Timed out waiting for SC response");
rc = waiter->w_msg->msg_status = ETIMEDOUT;
}
}
/*
* lose the waiter
*/
cv_destroy(&waiter->w_cv);
kmem_free(waiter, sizeof (struct sbbc_msg_waiter));
mutex_exit(mbox_wait_lock);
return (rc);
}
static void
wakeup_next()
{
/*
* Done sending the current message or encounter an error.
* Wake up the one request in the outbox_queue.
*/
mutex_enter(&outbox_queue_lock);
outbox_busy = 0;
cv_signal(&outbox_queue);
mutex_exit(&outbox_queue_lock);
}
/* ARGSUSED */
int
sbbc_mbox_send_msg(sbbc_msg_t *msg, int flags, uint_t msg_id,
time_t wait_time, clock_t stop_time)
{
struct sbbc_mbox_header header;
struct sbbc_fragment frag;
int rc = 0;
int bytes_written;
uint32_t intr_enabled;
clock_t clockleft;
static fn_t f = "sbbc_mbox_send_msg";
/*
* First check that the SC has enabled its mailbox
*/
rc = iosram_read(SBBC_INTR_SC_ENABLED_KEY, 0,
(caddr_t)&intr_enabled, sizeof (intr_enabled));
if (rc)
return (rc);
if (!(intr_enabled & SBBC_MAILBOX_OUT))
return (ENOTSUP);
/*
* read the mailbox header
*/
if (rc = mbox_read_header(SBBC_OUTBOX, &header))
return (rc);
/*
* Allocate/initialise a fragment for this message
*/
frag.f_id = msg_id;
frag.f_type = msg->msg_type;
frag.f_status = 0;
frag.f_total_len = msg->msg_len;
frag.f_frag_offset = 0;
/*
* Throw in the message data
*/
bcopy(&msg->msg_data, &frag.f_data, sizeof (msg->msg_data));
/*
* If not enough space is available
* write what we can and wait for
* an interrupt to tell us that more
* space is available
*/
bytes_written = 0;
do {
rc = mbox_write(&header, &frag, msg);
if (rc != 0 && rc != ENOSPC) {
return (rc);
}
if (rc == 0) {
/*
* Always tell the SC when there is a message.
* Ignore returned value as not being able to
* signal the SC about space available does
* not stop the SC from processing input.
*/
(void) iosram_send_intr(SBBC_MAILBOX_OUT);
}
bytes_written += frag.f_frag_len;
frag.f_frag_offset += frag.f_frag_len;
if ((bytes_written < msg->msg_len) || (rc == ENOSPC)) {
if (mbox_has_free_space(&header) <=
sizeof (struct sbbc_fragment)) {
int tmprc;
clockleft = cv_timedwait(
&master_mbox->mbox_out->mb_full,
&master_mbox->mbox_out->mb_lock,
stop_time);
/* Return ETIMEDOUT if we timed out */
if (clockleft < 0) {
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x "
"has timed out\n", f, msg_id);
cmn_err(CE_NOTE,
"Timed out sending message "
"to SC");
return (ETIMEDOUT);
}
/* Read updated header from IOSRAM */
if (tmprc = mbox_read_header(SBBC_OUTBOX,
&header)) {
return (tmprc);
}
}
}
SGSBBC_DBG_MBOX("%s: msg_id = 0x%x, bytes_written = 0x%x, "
"msg_len = 0x%x\n", f,
msg_id, bytes_written, msg->msg_len);
} while ((bytes_written < msg->msg_len) || (rc == ENOSPC));
/*
* this could be a spurious interrupt
* as the SC may be merrily readings its
* mail even as send, but what can you do ? No
* synchronization method between SC <-> OS
* SRAM data eaters means that this is inevitable.
* It would take a bigger brain to fix this.
*
*/
(void) iosram_send_intr(SBBC_MAILBOX_OUT);
return (rc);
}
/*
* get next message
* Read the next message from SRAM
* Check if theres an entry on the wait queue
* for this message
* If yes, read the message in and signal
* the waiter (if all the message has been received)
* No, its unsolicited, if theres a handler installed for
* this message type trigger it, otherwise toss
* the message
*/
int
sbbc_mbox_recv_msg()
{
struct sbbc_mbox_header header;
struct sbbc_fragment frag;
sbbc_msg_t tmpmsg; /* Temporary msg storage */
int rc = 0, i, first_hdlr, last_hdlr;
uint32_t intr_enabled;
sbbc_intrs_t *intr;
struct sbbc_msg_waiter *waiter;
uint16_t type; /* frag.f_type.type */
uint32_t f_id; /* frag.f_id */
uint32_t f_frag_offset, f_frag_len;
kmutex_t *mbox_wait_lock;
static fn_t f = "sbbc_mbox_recv_msg";
/*
* First check that the OS has enabled its mailbox
*/
rc = iosram_read(SBBC_SC_INTR_ENABLED_KEY, 0,
(caddr_t)&intr_enabled, sizeof (intr_enabled));
if (rc) {
return (rc);
}
if (!(intr_enabled & SBBC_MAILBOX_IN))
return (ENOTSUP);
/*
* read the mailbox header
*/
if (rc = mbox_read_header(SBBC_INBOX, &header))
return (rc);
/*
* check if any messages available. If
* consumer == producer then no more
* messages
*/
if ((header.mailboxes[SBBC_INBOX].mbox_consumer ==
header.mailboxes[SBBC_INBOX].mbox_producer)) {
return (-1);
}
/*
* read the fragment header for this message
*/
if (rc = mbox_read_frag(&header, &frag)) {
return (rc);
}
/* Save to local variable for easy reading */
type = frag.f_type.type;
f_id = frag.f_id;
SGSBBC_DBG_MBOX("%s: f_id = 0x%x\n", f, f_id);
/*
* check the message type. If its invalid, we will
* just toss the message
*/
if (type >= SBBC_MBOX_MSG_TYPES) {
goto done;
}
/*
* if theres no waiters for this message type, and theres
* no message handler installed, toss it.
*
* Unsolicited messages (f_id == 0) are tricky because we won't know
* when the handler has finished so that we can
* remove the message, so, given the small brains in operation
* here, what we do is restrict junk mail to zero-length
* messages, then we allocate a fragment using kmem,
* make a copy of the fragment in this memory,
* pass this pointer to the fragment, then skip the message.
* So even if there is data associated with the junkmail,
* the message handler doesn't get to see it
* We expect the mesaage handler to free the memory.
*/
if (type == SBBC_BROADCAST_MSG) {
/*
* Broadcast message, trigger all handlers
*/
first_hdlr = 0;
last_hdlr = SBBC_MBOX_MSG_TYPES - 1;
} else if ((master_mbox->mbox_wait_list[type] == NULL) || (f_id == 0)) {
/*
* Theres no waiters, or its unsolicited anyway
*/
first_hdlr = last_hdlr = type;
} else {
/*
* check the fragment message type, look at the wait list for
* that type to find its associated message
*
* First find the message. If we get it, take it off
* the waiter list and read the data. We will
* put it back on the list if necessary.
* This avoids the problem of a second message-in
* interrupt playing with this waiter.
* This will cut down on mutex spinning on the wait
* list locks, also, expect the next fragment to be
* for this messageso we might as well have it at the
* start of the list.
*
* its possible that a return message has a different type,
* (possible but not recommended!). So, if we don't find
* it on the list pointed to by the request type,
* go look at all the other lists
*/
mbox_wait_lock = &master_mbox->mbox_wait_lock[type];
mutex_enter(mbox_wait_lock);
if ((waiter = mbox_find_waiter(type, f_id)) == NULL) {
for (i = 0; i < SBBC_MBOX_MSG_TYPES; i++) {
if (i == type)
continue;
if ((waiter = mbox_find_waiter(i, f_id))
!= NULL)
break;
}
}
mutex_exit(mbox_wait_lock);
if (waiter == NULL) {
rc = -1;
/*
* there's no waiter for this message, but that
* could mean that this message is the start of
* a send/receive to us, and every 'first' request
* must by definition be unsolicited,
* so trigger the handler
*/
first_hdlr = last_hdlr = type;
} else {
SGSBBC_DBG_MBOX("%s: f_id = 0x%x, msg_id = 0x%x, "
"msg_len = 0x%x\n",
f, f_id, waiter->w_id,
waiter->w_msg->msg_len);
rc = mbox_read(&header, &frag, waiter->w_msg);
SGSBBC_DBG_MBOX("%s: f_id = 0x%x, offset = 0x%x, "
"len = 0x%x, total_len = 0x%x\n",
f, frag.f_id, frag.f_frag_offset,
frag.f_frag_len, frag.f_total_len);
if (rc || ((frag.f_frag_offset + frag.f_frag_len) ==
frag.f_total_len)) {
/*
* failed or all the message has been read in
*/
mutex_enter(mbox_wait_lock);
waiter->w_msg->msg_status = (rc == ENOMEM)?
rc : frag.f_status;
SGSBBC_DBG_MBOX("%s: msg_status = %d\n",
f, waiter->w_msg->msg_status);
cv_signal(&waiter->w_cv);
mutex_exit(mbox_wait_lock);
} else {
/*
* back on the wait list
*/
mutex_enter(mbox_wait_lock);
if (waiter->w_msg->msg_status == ETIMEDOUT) {
cv_signal(&waiter->w_cv);
mutex_exit(mbox_wait_lock);
goto done;
}
if (master_mbox->mbox_wait_list[type] == NULL) {
master_mbox->mbox_wait_list[type] =
waiter;
waiter->w_next = NULL;
} else {
struct sbbc_msg_waiter *tmp;
tmp = master_mbox->mbox_wait_list[type];
master_mbox->mbox_wait_list[type] =
waiter;
waiter->w_next = tmp;
}
mutex_exit(mbox_wait_lock);
}
goto done;
}
}
/*
* Set msg_len to f_frag_len so msg_buf will be large enough
* to contain what is in the fragment.
*/
f_frag_len = tmpmsg.msg_len = frag.f_frag_len;
/*
* Save the f_frag_offset for copying into client's space.
* Set frag.f_frag_offset to 0 so we don't have to allocate
* too much space for reading in the message.
*/
f_frag_offset = frag.f_frag_offset;
frag.f_frag_offset = 0;
/* Allocate space for msg_buf */
if (f_frag_len != 0 && (tmpmsg.msg_buf =
kmem_alloc(f_frag_len, KM_NOSLEEP)) == NULL) {
rc = ENOMEM;
cmn_err(CE_WARN, "Can't allocate memory"
" for unsolicited messages\n");
} else {
/* Save the incoming message in tmpmsg */
rc = mbox_read(&header, &frag, &tmpmsg);
for (i = first_hdlr; rc == 0 && i <= last_hdlr; i++) {
intr = master_mbox->intrs[i];
if ((intr == NULL) || (intr->sbbc_intr_id == 0)) {
continue;
}
while (intr != NULL) {
/*
* If the client has allocated enough space
* for incoming message, copy into the
* client buffer.
*/
sbbc_msg_t *arg = (sbbc_msg_t *)intr->sbbc_arg;
if (arg != (void *)NULL) {
if (arg->msg_len >= frag.f_total_len) {
if (f_frag_len > 0)
bcopy(tmpmsg.msg_buf,
arg->msg_buf +
f_frag_offset,
f_frag_len);
} else {
arg->msg_status = ENOMEM;
}
}
/*
* Only trigger the interrupt when we
* have received the whole message.
*/
if (f_frag_offset + f_frag_len ==
frag.f_total_len) {
ddi_trigger_softintr(
intr->sbbc_intr_id);
}
intr = intr->sbbc_intr_next;
}
}
if (f_frag_len != 0) {
/* Don't forget to free the buffer */
kmem_free(tmpmsg.msg_buf, f_frag_len);
}
}
done:
mbox_skip_next_msg(&header);
return (rc);
}
/*
* available free space in the outbox
*/
static int
mbox_has_free_space(struct sbbc_mbox_header *header)
{
uint32_t space = 0;
ASSERT(MUTEX_HELD(&master_mbox->mbox_out->mb_lock));
if (header->mailboxes[SBBC_OUTBOX].mbox_producer ==
header->mailboxes[SBBC_OUTBOX].mbox_consumer) {
/*
* mailbox is empty
*/
space += header->mailboxes[SBBC_OUTBOX].mbox_len -
header->mailboxes[SBBC_OUTBOX].mbox_producer;
space +=
header->mailboxes[SBBC_OUTBOX].mbox_producer;
} else if (header->mailboxes[SBBC_OUTBOX].mbox_producer >
header->mailboxes[SBBC_OUTBOX].mbox_consumer) {
space += header->mailboxes[SBBC_OUTBOX].mbox_len -
header->mailboxes[SBBC_OUTBOX].mbox_producer;
space += header->mailboxes[SBBC_OUTBOX].mbox_consumer;
} else {
/*
* mailbox wrapped around
*/
space += header->mailboxes[SBBC_OUTBOX].mbox_consumer -
header->mailboxes[SBBC_OUTBOX].mbox_producer;
}
/*
* Need to make sure that the mailbox never
* gets completely full, as consumer == producer is
* our test for empty, so we drop MBOX_ALIGN_BYTES.
*/
if (space >= MBOX_ALIGN_BYTES)
space -= MBOX_ALIGN_BYTES;
else
space = 0;
return (space);
}
/*
* Write the data to IOSRAM
* Update the SRAM mailbox header
* Update the local mailbox pointers
* Only write a single fragment. If possible,
* put the whole message into a fragment.
*
* Note: We assume that there is no 'max' message
* size. We will just keep fragmenting.
* Note: We always write to SBBC_OUTBOX and
* read from SBBC_INBOX
*
* If we get an error at any time, return immediately
* without updating the mailbox header in SRAM
*/
static int
mbox_write(struct sbbc_mbox_header *header,
struct sbbc_fragment *frag, sbbc_msg_t *msg)
{
int bytes_written, bytes_remaining, free_space;
int rc = 0;
caddr_t src;
uint32_t sram_dst;
int space_at_end, space_at_start;
uint32_t mbox_offset, mbox_len;
uint32_t mbox_producer, mbox_consumer;
uint32_t f_total_len, f_frag_offset;
uint32_t frag_header_size;
static fn_t f = "mbox_write";
ASSERT(MUTEX_HELD(&master_mbox->mbox_out->mb_lock));
/*
* Save to local variables to make code more readable
*/
mbox_offset = header->mailboxes[SBBC_OUTBOX].mbox_offset;
mbox_len = header->mailboxes[SBBC_OUTBOX].mbox_len;
mbox_producer = header->mailboxes[SBBC_OUTBOX].mbox_producer;
mbox_consumer = header->mailboxes[SBBC_OUTBOX].mbox_consumer;
f_total_len = frag->f_total_len;
f_frag_offset = frag->f_frag_offset;
frag_header_size = sizeof (struct sbbc_fragment);
SGSBBC_DBG_MBOX("%s: mbox_consumer = 0x%x, "
"mbox_producer = 0x%x\n", f, mbox_consumer, mbox_producer);
/*
* Write pointer in SRAM
*/
sram_dst = mbox_offset + mbox_producer;
/*
* NB We assume that the consumer stays constant
* during the write. It may not necessarily
* be the case but it won't cause us any problems, just means
* we fragment more than is absolutely necessary
*
* possible cases
* 1) consumer == producer, mailbox empty
* space_at_end == mailbox end - producer
* space_at_start == producer - MBOX_ALIGN_BYTES
* 2) producer < consumer
* space_at_end = (consumer - producer - MBOX_ALIGN_BYTES)
* space_at_start == 0
* 3) producer > consumer
* space_at_end = mailbox end - producer
* space_at_start = consumer - MBOX_ALIGN_BYTES
*
* (space - MBOX_ALIGN_BYTES) because we need to avoid the
* scenario where the producer wraps around completely and
* producer == consumer, as this is our test for 'empty'.
* Also we want it to be 8-byte aligned.
* Note: start is assumed = 0
*/
if (mbox_producer < mbox_consumer) {
space_at_end = mbox_consumer - mbox_producer - MBOX_ALIGN_BYTES;
if (space_at_end < 0)
space_at_end = 0;
space_at_start = 0;
} else {
space_at_end = mbox_len - mbox_producer;
if (mbox_consumer == 0)
space_at_end -= MBOX_ALIGN_BYTES;
space_at_start = mbox_consumer - MBOX_ALIGN_BYTES;
if (space_at_start < 0)
space_at_start = 0;
}
SGSBBC_DBG_MBOX("%s: space_at_end = 0x%x, space_at_start = 0x%x\n",
f, space_at_end, space_at_start);
free_space = space_at_end + space_at_start;
if (free_space < frag_header_size) {
/*
* can't even write a fragment header, so just return
* the caller will block waiting for space
*/
frag->f_frag_len = 0;
return (ENOSPC);
}
/*
* How many bytes will be in the fragment ?
*/
bytes_remaining = f_total_len - f_frag_offset;
frag->f_frag_len = min(bytes_remaining, free_space - frag_header_size);
SGSBBC_DBG_MBOX("%s: writing header:sram_dst = 0x%x\n",
f, sram_dst);
/*
* we can write the fragment header and some data
* First, the fragment header
*/
if (space_at_end >= frag_header_size) {
rc = iosram_write(SBBC_MAILBOX_KEY, sram_dst, (caddr_t)frag,
frag_header_size);
if (rc)
return (rc);
sram_dst = (uint32_t)(sram_dst + frag_header_size);
/*
* Wrap around if we reach the end
*/
if (sram_dst >= (mbox_len + mbox_offset)) {
sram_dst = mbox_offset;
}
space_at_end -= frag_header_size;
} else {
/* wraparound */
if (space_at_end) {
rc = iosram_write(SBBC_MAILBOX_KEY, sram_dst,
(caddr_t)frag, space_at_end);
if (rc)
return (rc);
sram_dst = (uint32_t)mbox_offset;
}
rc = iosram_write(SBBC_MAILBOX_KEY, sram_dst,
(caddr_t)((caddr_t)frag + space_at_end),
(frag_header_size - space_at_end));
if (rc)
return (rc);
sram_dst += frag_header_size - space_at_end;
space_at_start -= (frag_header_size - space_at_end);
space_at_end = 0;
}
SGSBBC_DBG_MBOX("%s: space_at_end = 0x%x, space_at_start = 0x%x\n",
f, space_at_end, space_at_start);
/*
* Now the fragment data
*/
free_space -= frag_header_size;
src = (caddr_t)(msg->msg_buf + f_frag_offset);
bytes_written = 0;
if (space_at_end) {
SGSBBC_DBG_MBOX("%s: writing data:sram_dst = 0x%x, "
"bytes_remaining = 0x%x\n",
f, sram_dst, bytes_remaining);
if (space_at_end < bytes_remaining)
bytes_written = space_at_end;
else
bytes_written = bytes_remaining;
rc = iosram_write(SBBC_MAILBOX_KEY, sram_dst, src,
bytes_written);
if (rc)
return (rc);
sram_dst = (uint32_t)(sram_dst + bytes_written);
/*
* Wrap around if we reach the end
*/
if (sram_dst >= (mbox_len + mbox_offset)) {
sram_dst = mbox_offset;
}
src = (caddr_t)(src + bytes_written);
bytes_remaining -= bytes_written;
}
if ((bytes_remaining > 0) && space_at_start) {
SGSBBC_DBG_MBOX("%s: writing the rest:sram_dst = 0x%x, "
"bytes_remaining = 0x%x\n",
f, sram_dst, bytes_remaining);
if (space_at_start < bytes_remaining) {
rc = iosram_write(SBBC_MAILBOX_KEY, sram_dst, src,
space_at_start);
bytes_written += space_at_start;
} else {
rc = iosram_write(SBBC_MAILBOX_KEY, sram_dst, src,
bytes_remaining);
bytes_written += bytes_remaining;
}
if (rc)
return (rc);
}
frag->f_frag_len = bytes_written;
/*
* update header->mbox_producer (bytes_written + frag_size)
*/
sram_dst = mbox_producer + bytes_written + frag_header_size;
if (sram_dst >= mbox_len) {
sram_dst = sram_dst % mbox_len;
}
SGSBBC_DBG_MBOX("%s: after writing data:sram_dst = 0x%x, "
"bytes_written = 0x%x\n", f, sram_dst, bytes_written);
header->mailboxes[SBBC_OUTBOX].mbox_producer = sram_dst;
mbox_update_header(SBBC_OUTBOX, header);
return (rc);
}
/*
* Get the next frag from IOSRAM.
* Write it to the corresponding msg buf.
* The caller must update the SRAM pointers etc.
*/
static int
mbox_read(struct sbbc_mbox_header *header,
struct sbbc_fragment *frag, sbbc_msg_t *msg)
{
int rc = 0;
uint32_t sram_src, sram_end;
caddr_t msg_buf;
int bytes_at_start, bytes_at_end;
int bytes_to_read;
uint32_t frag_header_size, frag_total_size;
uint32_t f_frag_offset, f_frag_len;
uint32_t mbox_producer, mbox_consumer;
uint32_t mbox_len, mbox_offset;
static fn_t f = "mbox_read";
ASSERT(MUTEX_HELD(&master_mbox->mbox_in->mb_lock));
/*
* Save to local variables to make code more readable
*/
mbox_producer = header->mailboxes[SBBC_INBOX].mbox_producer;
mbox_consumer = header->mailboxes[SBBC_INBOX].mbox_consumer;
mbox_len = header->mailboxes[SBBC_INBOX].mbox_len;
mbox_offset = header->mailboxes[SBBC_INBOX].mbox_offset;
frag_header_size = sizeof (struct sbbc_fragment);
f_frag_offset = frag->f_frag_offset;
f_frag_len = frag->f_frag_len;
frag_total_size = frag_header_size + f_frag_len;
/*
* If the message buffer size is smaller than the fragment
* size, return an error.
*/
if (msg->msg_len < f_frag_len) {
rc = ENOMEM;
goto done;
}
msg_buf = (caddr_t)(msg->msg_buf + f_frag_offset);
/*
* Throw in the message data
*/
bcopy(&frag->f_data, &msg->msg_data, sizeof (msg->msg_data));
/*
* We have it all, waiter, message, so lets
* go get that puppy!
* Message could be in one or two chunks -
* consumer < producer: 1 chunk, (producer - consumer)
* consumer > producer: 2 chunks, (end - consumer)
* (producer - start)
*/
sram_end = (uint32_t)(mbox_offset + mbox_len);
sram_src = (uint32_t)(mbox_offset + mbox_consumer + frag_header_size);
/*
* wraparound
*/
if (sram_src >= sram_end)
sram_src -= mbox_len;
/*
* find where the data is
* possible cases
* 1) consumer == producer, mailbox empty
* error
* 2) producer < consumer
* bytes_at_end = mailbox end - consumer
* bytes_at_start = producer
* 3) producer > consumer
* bytes_at_end = producer - consumer
* bytes_at_start = 0
*/
SGSBBC_DBG_MBOX("%s: mbox_consumer = 0x%x, mbox_producer = 0x%x, "
"frag_len = 0x%x\n",
f, mbox_consumer, mbox_producer, f_frag_len);
if (mbox_producer == mbox_consumer) {
bytes_at_end = bytes_at_start = 0;
} else if (mbox_producer < mbox_consumer) {
bytes_at_end = mbox_len - mbox_consumer;
bytes_at_start = mbox_producer;
} else {
bytes_at_end = mbox_producer - mbox_consumer;
bytes_at_start = 0;
}
SGSBBC_DBG_MBOX("%s: bytes_at_end = 0x%x, "
"bytes_at_start = 0x%x\n", f, bytes_at_end, bytes_at_start);
if ((bytes_at_end + bytes_at_start) < frag_total_size) {
/*
* mailbox is corrupt
* but what to do ?
*/
cmn_err(CE_PANIC, "Corrupt INBOX!\n"
"producer = %x, consumer = %x, bytes_at_start = %x, "
"bytes_at_end = %x\n", mbox_producer, mbox_consumer,
bytes_at_start, bytes_at_end);
}
/*
* If bytes_at_end is greater than header size, read the
* part at the end of the mailbox, and then update the
* pointers and bytes_to_read.
*/
if (bytes_at_end > frag_header_size) {
/*
* We are only interested in the data segment.
*/
bytes_at_end -= frag_header_size;
bytes_to_read = (bytes_at_end >= f_frag_len)?
f_frag_len : bytes_at_end;
SGSBBC_DBG_MBOX("%s: reading data: sram_src = 0x%x, "
"bytes_to_read = 0x%x\n", f, sram_src, bytes_to_read);
rc = iosram_read(SBBC_MAILBOX_KEY, sram_src, msg_buf,
bytes_to_read);
if (rc) {
goto done;
}
/*
* Update pointers in SRAM and message buffer.
*/
sram_src = (uint32_t)mbox_offset;
msg_buf = (caddr_t)(msg_buf + bytes_to_read);
bytes_to_read = f_frag_len - bytes_to_read;
} else {
bytes_to_read = f_frag_len;
}
/*
* wraparound to start of mailbox
*/
if (bytes_to_read > 0) {
SGSBBC_DBG_MBOX("%s: reading the rest: sram_src = 0x%x, "
"bytes_to_read = 0x%x\n", f, sram_src, bytes_to_read);
rc = iosram_read(SBBC_MAILBOX_KEY, sram_src, msg_buf,
bytes_to_read);
}
done:
msg->msg_bytes += f_frag_len;
return (rc);
}
/*
* move past the next message in the inbox
*/
static void
mbox_skip_next_msg(struct sbbc_mbox_header *header)
{
struct sbbc_fragment frag;
uint32_t next_msg;
ASSERT(MUTEX_HELD(&master_mbox->mbox_in->mb_lock));
if (mbox_read_frag(header, &frag)) {
cmn_err(CE_PANIC, "INBOX is Corrupt !\n");
}
/*
* Move on to the next message
*/
next_msg = header->mailboxes[SBBC_INBOX].mbox_consumer;
next_msg += sizeof (struct sbbc_fragment);
next_msg += frag.f_frag_len;
if (next_msg >= header->mailboxes[SBBC_INBOX].mbox_len) {
next_msg = (next_msg +
header->mailboxes[SBBC_INBOX].mbox_len) %
header->mailboxes[SBBC_INBOX].mbox_len;
}
header->mailboxes[SBBC_INBOX].mbox_consumer =
next_msg;
mbox_update_header(SBBC_INBOX, header);
return;
}
static struct sbbc_msg_waiter *
mbox_find_waiter(uint16_t msg_type, uint32_t msg_id)
{
struct sbbc_msg_waiter *waiter, *prev;
prev = NULL;
for (waiter = master_mbox->mbox_wait_list[msg_type];
waiter != NULL; waiter = waiter->w_next) {
if (waiter->w_id == msg_id) {
if (prev != NULL) {
prev->w_next = waiter->w_next;
} else {
master_mbox->mbox_wait_list[msg_type] =
waiter->w_next;
}
break;
}
prev = waiter;
}
return (waiter);
}
static int
mbox_read_header(uint32_t mailbox, struct sbbc_mbox_header *header)
{
struct sbbc_mbox_header *hd;
uint32_t offset;
int rc;
/*
* Initialize a sbbc_mbox_header pointer to 0 so that we
* can use it to calculate the offsets of fields inside
* the structure.
*/
hd = (struct sbbc_mbox_header *)0;
if (rc = iosram_read(SBBC_MAILBOX_KEY, 0, (caddr_t)header,
sizeof (struct sbbc_mbox_header)))
return (rc);
/*
* Since the header is read in a byte-by-byte fashion
* using ddi_rep_get8, we need to re-read the producer
* or consumer pointer as integer in case it has changed
* after part of the previous value has been read.
*/
switch (mailbox) {
case SBBC_INBOX:
offset = (uint32_t)(uintptr_t)
(&hd->mailboxes[SBBC_INBOX].mbox_producer);
rc = iosram_read(SBBC_MAILBOX_KEY, offset,
(caddr_t)&header->mailboxes[SBBC_INBOX].mbox_producer,
sizeof (uint32_t));
break;
case SBBC_OUTBOX:
offset = (uint32_t)(uintptr_t)
(&hd->mailboxes[SBBC_OUTBOX].mbox_consumer);
rc = iosram_read(SBBC_MAILBOX_KEY, offset,
(caddr_t)&header->mailboxes[SBBC_OUTBOX].mbox_consumer,
sizeof (uint32_t));
break;
default:
cmn_err(CE_PANIC, "Invalid Mbox header type\n");
break;
}
return (rc);
}
/*
* There are only two fields updated by the domain,
* the inbox consumer field and the outbox producer
* field. These fields are protected by the respective
* mbox_{in|out}->mb_lock so that accesses will
* be serialised. The only coherency issue is writing
* back the header, so we do it here after grabbing
* the global mailbox lock.
*/
static void
mbox_update_header(uint32_t mailbox, struct sbbc_mbox_header *header)
{
struct sbbc_mbox_header *hd;
uint32_t value, offset, mbox_len;
/*
* Initialize a sbbc_mbox_header pointer to 0 so that we
* can use it to calculate the offsets of fields inside
* the structure.
*/
hd = (struct sbbc_mbox_header *)0;
switch (mailbox) {
case SBBC_INBOX:
value = header->mailboxes[SBBC_INBOX].mbox_consumer;
offset = (uint32_t)(uintptr_t)
(&hd->mailboxes[SBBC_INBOX].mbox_consumer);
mbox_len = header->mailboxes[SBBC_INBOX].mbox_len;
break;
case SBBC_OUTBOX:
value = header->mailboxes[SBBC_OUTBOX].mbox_producer;
offset = (uint32_t)(uintptr_t)
(&hd->mailboxes[SBBC_OUTBOX].mbox_producer);
mbox_len = header->mailboxes[SBBC_OUTBOX].mbox_len;
break;
default:
cmn_err(CE_PANIC, "Invalid Mbox header type\n");
break;
}
/*
* If the last read/write would cause the next read/write
* to be unaligned, we skip on modulo MBOX_ALIGN_BYTES.
* This is OK because all the mailbox handlers will
* conform to this.
*/
if (value % MBOX_ALIGN_BYTES) {
value += (MBOX_ALIGN_BYTES - (value % MBOX_ALIGN_BYTES));
value %= mbox_len;
}
if (iosram_write(SBBC_MAILBOX_KEY, offset, (caddr_t)&value,
sizeof (uint32_t))) {
cmn_err(CE_PANIC, "Mailbox Corrupt ! \n");
}
/*
* Update internal pointers so they won't be out of sync with
* the values in IOSRAM.
*/
switch (mailbox) {
case SBBC_INBOX:
header->mailboxes[SBBC_INBOX].mbox_consumer = value;
break;
case SBBC_OUTBOX:
header->mailboxes[SBBC_OUTBOX].mbox_producer = value;
break;
}
}
static int
mbox_read_frag(struct sbbc_mbox_header *header,
struct sbbc_fragment *frag)
{
int rc = 0;
uint32_t sram_src, bytes;
caddr_t dst;
ASSERT(MUTEX_HELD(&master_mbox->mbox_in->mb_lock));
/*
* read the fragment header for this message
*/
sram_src = (uint32_t)(header->mailboxes[SBBC_INBOX].mbox_offset +
header->mailboxes[SBBC_INBOX].mbox_consumer);
/*
* wraparound ?
*/
if ((header->mailboxes[SBBC_INBOX].mbox_consumer +
sizeof (struct sbbc_fragment)) >=
header->mailboxes[SBBC_INBOX].mbox_len) {
dst = (caddr_t)frag;
bytes = header->mailboxes[SBBC_INBOX].mbox_len -
header->mailboxes[SBBC_INBOX].mbox_consumer;
if (rc = iosram_read(SBBC_MAILBOX_KEY, sram_src, dst, bytes)) {
return (rc);
}
dst += bytes;
sram_src = header->mailboxes[SBBC_INBOX].mbox_offset;
bytes = (header->mailboxes[SBBC_INBOX].mbox_consumer +
sizeof (struct sbbc_fragment)) %
header->mailboxes[SBBC_INBOX].mbox_len;
if (rc = iosram_read(SBBC_MAILBOX_KEY, sram_src,
dst, bytes)) {
return (rc);
}
} else {
if (rc = iosram_read(SBBC_MAILBOX_KEY, sram_src, (caddr_t)frag,
sizeof (struct sbbc_fragment))) {
return (rc);
}
}
return (0);
}
/*
* This function is triggered by a soft interrupt and it's purpose is to call
* to kadmin() to shutdown the Domain.
*/
/*ARGSUSED0*/
static uint_t
sbbc_do_fast_shutdown(char *arg)
{
(void) kadmin(A_SHUTDOWN, AD_POWEROFF, NULL, kcred);
/*
* If kadmin fails for some reason then we bring the system down
* via power_down(), or failing that using halt().
*/
power_down("kadmin() failed, trying power_down()");
halt("power_down() failed, trying halt()");
/*
* We should never make it this far, so something must have gone
* horribly, horribly wrong.
*/
/*NOTREACHED*/
return (DDI_INTR_UNCLAIMED);
}
/*
* This function handles unsolicited PANIC_SHUTDOWN events
*/
static uint_t
sbbc_panic_shutdown_handler(char *arg)
{
static fn_t f = "sbbc_panic_shutdown_handler()";
sg_panic_shutdown_t *payload = NULL;
sbbc_msg_t *msg = NULL;
if (arg == NULL) {
SGSBBC_DBG_EVENT(CE_NOTE, "%s: arg == NULL", f);
return (DDI_INTR_UNCLAIMED);
}
msg = (sbbc_msg_t *)arg;
if (msg->msg_buf == NULL) {
SGSBBC_DBG_EVENT(CE_NOTE, "%s: msg_buf == NULL", f);
return (DDI_INTR_UNCLAIMED);
}
payload = (sg_panic_shutdown_t *)msg->msg_buf;
switch (*payload) {
case SC_EVENT_PANIC_ENV:
/*
* Let the user know why the domain is going down.
*/
cmn_err(CE_WARN, "%s", PANIC_ENV_EVENT_MSG);
/*
* trigger sbbc_do_fast_shutdown().
*/
ddi_trigger_softintr(panic_softintr_id);
/*NOTREACHED*/
break;
case SC_EVENT_PANIC_KEYSWITCH:
/*
* The SC warns a user if they try a destructive keyswitch
* command on a Domain which is currently running Solaris.
* If the user chooses to continue despite our best advise
* then we bring down the Domain immediately without trying
* to shut the system down gracefully.
*/
break;
default:
SGSBBC_DBG_EVENT(CE_NOTE, "%s: Unknown payload:%d", f,
*payload);
return (DDI_INTR_UNCLAIMED);
}
return (DDI_INTR_CLAIMED);
}
/*
* dp_get_cores()
*
* Checks cpu implementation for the input cpuid and returns
* the number of cores.
* If implementation cannot be determined, returns 1
*/
static int
dp_get_cores(uint16_t cpuid)
{
int bd, ii, impl, nc;
bd = cpuid / 4;
nc = SG_MAX_CPUS_PER_BD;
/* find first with valid implementation */
for (ii = 0; ii < nc; ii++)
if (cpu[MAKE_CPUID(bd, ii)]) {
impl = cpunodes[MAKE_CPUID(bd, ii)].implementation;
break;
}
if (IS_JAGUAR(impl) || IS_PANTHER(impl))
return (2);
else
return (1);
}
/*
* dp_payload_add_cpus()
*
* From datapath mailbox message, determines the number of and safari IDs
* for affected cpus, then adds this info to the datapath ereport.
*
*/
static int
dp_payload_add_cpus(plat_datapath_info_t *dpmsg, nvlist_t *erp)
{
int jj = 0, numcpus = 0;
int bd, procpos, ii, num, ncores, ret;
uint16_t *dparray, cpuid;
uint64_t *snarray;
/* check for multiple core architectures */
ncores = dp_get_cores(dpmsg->cpuid);
switch (dpmsg->type) {
case DP_CDS_TYPE:
numcpus = ncores;
break;
case DP_DX_TYPE:
numcpus = 2 * ncores;
break;
case DP_RP_TYPE:
numcpus = SG_MAX_CPUS_PER_BD;
break;
default:
ASSERT(0);
return (-1);
}
num = numcpus;
/*
* populate dparray with impacted cores (only those present)
*/
dparray = kmem_zalloc(num * sizeof (uint16_t *), KM_SLEEP);
bd = SG_PORTID_TO_BOARD_NUM(SG_CPUID_TO_PORTID(dpmsg->cpuid));
procpos = SG_CPUID_TO_PORTID(dpmsg->cpuid) & 0x3;
mutex_enter(&cpu_lock);
switch (dpmsg->type) {
case DP_CDS_TYPE:
/*
* For a CDS error, it's the reporting cpuid
* and it's other core (if present)
*/
cpuid = dpmsg->cpuid & 0x1FF; /* core 0 */
if (cpu[cpuid])
dparray[jj++] = cpuid;
cpuid = dpmsg->cpuid | SG_CORE_ID_MASK; /* core 1 */
if (cpu[cpuid])
dparray[jj++] = cpuid;
break;
case DP_DX_TYPE:
/*
* For a DX error, it's the reporting cpuid (all
* cores) and the other CPU sharing the same
* DX<-->DCDS interface (all cores)
*/
/* reporting cpuid */
cpuid = dpmsg->cpuid & 0x1FF; /* core 0 */
if (cpu[cpuid])
dparray[jj++] = cpuid;
cpuid = dpmsg->cpuid | SG_CORE_ID_MASK; /* core 1 */
if (cpu[cpuid])
dparray[jj++] = cpuid;
/* find partner cpuid */
if (procpos == 0 || procpos == 2)
cpuid = dpmsg->cpuid + 1;
else
cpuid = dpmsg->cpuid - 1;
/* add partner cpuid */
cpuid &= 0x1FF; /* core 0 */
if (cpu[cpuid])
dparray[jj++] = cpuid;
cpuid |= SG_CORE_ID_MASK; /* core 1 */
if (cpu[cpuid])
dparray[jj++] = cpuid;
break;
case DP_RP_TYPE:
/*
* For a RP error, it's all cpuids (all cores) on
* the reporting board
*/
for (ii = 0; ii < SG_MAX_CMPS_PER_BD; ii++) {
cpuid = MAKE_CPUID(bd, ii);
if (cpu[cpuid]) /* core 0 */
dparray[jj++] = cpuid;
cpuid |= SG_CORE_ID_MASK;
if (cpu[cpuid]) /* core 1 */
dparray[jj++] = cpuid;
}
break;
}
mutex_exit(&cpu_lock);
/*
* The datapath message could not be associated with any
* configured CPU.
*/
if (!jj) {
kmem_free(dparray, num * sizeof (uint16_t *));
ret = nvlist_add_uint32(erp, DP_LIST_SIZE, jj);
ASSERT(ret == 0);
return (-1);
}
snarray = kmem_zalloc(jj * sizeof (uint64_t), KM_SLEEP);
for (ii = 0; ii < jj; ii++)
snarray[ii] = cpunodes[dparray[ii]].device_id;
ret = nvlist_add_uint32(erp, DP_LIST_SIZE, jj);
ret |= nvlist_add_uint16_array(erp, DP_LIST, dparray, jj);
ret |= nvlist_add_uint64_array(erp, SN_LIST, snarray, jj);
ASSERT(ret == 0);
kmem_free(dparray, num * sizeof (uint16_t *));
kmem_free(snarray, jj * sizeof (uint64_t *));
return (0);
}
/*
* sbbc_dp_trans_event() - datapath message handler.
*
* Process datapath error and fault messages received from the SC. Checks
* for, and disregards, messages associated with I/O boards. Otherwise,
* extracts message info to produce a datapath ereport.
*/
/*ARGSUSED*/
static uint_t
sbbc_dp_trans_event(char *arg)
{
const char *f = "sbbc_dp_trans_event()";
nvlist_t *erp, *detector, *hcelem;
char buf[FM_MAX_CLASS];
int board;
plat_datapath_info_t *dpmsg;
sbbc_msg_t *msg;
int msgtype;
/* set i/f message and payload pointers */
msg = &dp_payload_msg;
dpmsg = &dp_payload;
msgtype = msg->msg_type.type;
cmn_err(CE_NOTE, "%s: msgtype=0x%x\n", f, msgtype);
cmn_err(CE_NOTE, "type=0x%x cpuid=0x%x t_value=0x%x\n", dpmsg->type,
dpmsg->cpuid, dpmsg->t_value);
/* check for valid type */
if (dpmsg->type > DP_RP_TYPE) {
cmn_err(CE_WARN, "%s: dpmsg type 0x%x invalid\n",
f, dpmsg->type);
return (DDI_INTR_CLAIMED);
}
/* check for I/O board message - Schizo AIDs are 25 - 30 */
if (dpmsg->cpuid > 23) {
cmn_err(CE_NOTE, "%s: ignore I/O board msg\n", f);
return (DDI_INTR_CLAIMED);
}
/* allocate space for ereport */
erp = fm_nvlist_create(NULL);
/*
* Member Name Data Type Comments
* ----------- --------- -----------
* version uint8 0
* class string "asic"
* ENA uint64 ENA Format 1
* detector fmri aggregated ID data for SC-DE
*
* Datapath ereport subclasses and data payloads:
* There will be two types of ereports (error and fault) which will be
* identified by the "type" member.
*
* ereport.asic.serengeti.cds.cds-dp
* ereport.asic.serengeti.dx.dx-dp (board)
* ereport.asic.serengeti.rp.rp-dp (centerplane)
*
* Member Name Data Type Comments
* ----------- --------- -----------
* erptype uint16 derived from message type: error or
* fault
* t-value uint32 SC's datapath SERD timeout threshold
* dp-list-sz uint8 number of dp-list array elements
* dp-list array of uint16 Safari IDs of affected cpus
* sn-list array of uint64 Serial numbers of affected cpus
*/
/* compose common ereport elements */
detector = fm_nvlist_create(NULL);
/*
* Create legacy FMRI for the detector
*/
board = SG_PORTID_TO_BOARD_NUM(SG_CPUID_TO_PORTID(dpmsg->cpuid));
switch (dpmsg->type) {
case DP_CDS_TYPE:
case DP_DX_TYPE:
(void) snprintf(buf, FM_MAX_CLASS, "SB%d", board);
break;
case DP_RP_TYPE:
(void) snprintf(buf, FM_MAX_CLASS, "RP");
break;
default:
(void) snprintf(buf, FM_MAX_CLASS, "UNKNOWN");
break;
}
hcelem = fm_nvlist_create(NULL);
(void) nvlist_add_string(hcelem, FM_FMRI_HC_NAME, FM_FMRI_LEGACY_HC);
(void) nvlist_add_string(hcelem, FM_FMRI_HC_ID, buf);
(void) nvlist_add_uint8(detector, FM_VERSION, FM_HC_SCHEME_VERSION);
(void) nvlist_add_string(detector, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC);
(void) nvlist_add_string(detector, FM_FMRI_HC_ROOT, "");
(void) nvlist_add_uint32(detector, FM_FMRI_HC_LIST_SZ, 1);
(void) nvlist_add_nvlist_array(detector, FM_FMRI_HC_LIST, &hcelem, 1);
/* build ereport class name */
(void) snprintf(buf, FM_MAX_CLASS, "asic.serengeti.%s.%s-%s",
dperrtype[dpmsg->type], dperrtype[dpmsg->type],
FM_ERROR_DATAPATH);
fm_ereport_set(erp, FM_EREPORT_VERSION, buf,
fm_ena_generate(0, FM_ENA_FMT1), detector, NULL);
/* add payload elements */
if (msgtype == MBOX_EVENT_DP_ERROR)
fm_payload_set(erp,
DP_EREPORT_TYPE, DATA_TYPE_UINT16, DP_ERROR, NULL);
else
fm_payload_set(erp,
DP_EREPORT_TYPE, DATA_TYPE_UINT16, DP_FAULT, NULL);
fm_payload_set(erp, DP_TVALUE, DATA_TYPE_UINT32, dpmsg->t_value, NULL);
(void) dp_payload_add_cpus(dpmsg, erp);
/* post ereport */
fm_ereport_post(erp, EVCH_SLEEP);
/* free ereport memory */
fm_nvlist_destroy(erp, FM_NVA_FREE);
fm_nvlist_destroy(detector, FM_NVA_FREE);
return (DDI_INTR_CLAIMED);
}
static uint_t
sbbc_datapath_error_msg_handler(char *arg)
{
static fn_t f = "sbbc_datapath_error_msg_handler()";
sbbc_msg_t *msg = NULL;
if (arg == NULL) {
SGSBBC_DBG_EVENT(CE_NOTE, "%s: arg == NULL", f);
return (DDI_INTR_UNCLAIMED);
}
msg = (sbbc_msg_t *)arg;
if (msg->msg_buf == NULL) {
SGSBBC_DBG_EVENT(CE_NOTE, "%s: msg_buf == NULL", f);
return (DDI_INTR_UNCLAIMED);
}
msg->msg_type.type = MBOX_EVENT_DP_ERROR;
/* trigger sbbc_dp_trans_event() */
ddi_trigger_softintr(dp_softintr_id);
return (DDI_INTR_CLAIMED);
}
static uint_t
sbbc_datapath_fault_msg_handler(char *arg)
{
static fn_t f = "sbbc_datapath_fault_msg_handler()";
sbbc_msg_t *msg = NULL;
if (arg == NULL) {
SGSBBC_DBG_EVENT(CE_NOTE, "%s: arg == NULL", f);
return (DDI_INTR_UNCLAIMED);
}
msg = (sbbc_msg_t *)arg;
if (msg->msg_buf == NULL) {
SGSBBC_DBG_EVENT(CE_NOTE, "%s: msg_buf == NULL", f);
return (DDI_INTR_UNCLAIMED);
}
msg->msg_type.type = MBOX_EVENT_DP_FAULT;
/* trigger sbbc_dp_trans_event() */
ddi_trigger_softintr(dp_softintr_id);
return (DDI_INTR_CLAIMED);
}
/*
* Log an ECC event message to the SC. This is called from the
* sbbc_ecc_mbox_taskq or directly from plat_send_ecc_mailbox_msg
* for indictment messages.
*/
int
sbbc_mbox_ecc_output(sbbc_ecc_mbox_t *msgp)
{
int rv;
plat_capability_data_t *cap;
plat_dimm_sid_board_data_t *ddata;
plat_ecc_msg_hdr_t *hdr;
rv = sbbc_mbox_request_response(&msgp->ecc_req, &msgp->ecc_resp,
sbbc_mbox_default_timeout);
if (rv != 0) {
/*
* Indictment messages use the return value to indicate a
* problem in the mailbox. For Error mailbox messages, we'll
* have to use a syslog message.
*/
if (msgp->ecc_log_error) {
if (sbbc_ecc_mbox_send_errs == 0) {
cmn_err(CE_NOTE, "!Solaris failed to send a "
"message (0x%x/0x%x) to the System "
"Controller. Error: %d, Message Status: %d",
msgp->ecc_resp.msg_type.type,
msgp->ecc_resp.msg_type.sub_type,
rv, msgp->ecc_resp.msg_status);
}
if (++sbbc_ecc_mbox_send_errs >=
sbbc_ecc_mbox_err_throttle) {
sbbc_ecc_mbox_send_errs = 0;
}
}
} else if (msgp->ecc_resp.msg_status != 0) {
if (msgp->ecc_resp.msg_type.type == INFO_MBOX) {
switch (msgp->ecc_resp.msg_type.sub_type) {
case INFO_MBOX_ECC:
hdr = (plat_ecc_msg_hdr_t *)
msgp->ecc_req.msg_buf;
if (hdr->emh_msg_type ==
PLAT_ECC_DIMM_SID_MESSAGE) {
rv = msgp->ecc_resp.msg_status;
break;
}
/*FALLTHROUGH*/
case INFO_MBOX_ECC_CAP:
/*
* The positive response comes only
* from the AVL FS1 updated SC.
* If the firmware is either downgraded
* or failover to an older version, then
* lets reset the SC capability to
* default.
*/
plat_ecc_capability_sc_set
(PLAT_ECC_CAPABILITY_SC_DEFAULT);
break;
default:
break;
}
}
if (msgp->ecc_log_error) {
if (sbbc_ecc_mbox_inval_errs == 0) {
cmn_err(CE_NOTE, "!An internal error (%d) "
"occurred in the System Controller while "
"processing this message (0x%x/0x%x)",
msgp->ecc_resp.msg_status,
msgp->ecc_resp.msg_type.type,
msgp->ecc_resp.msg_type.sub_type);
}
if (msgp->ecc_resp.msg_status == EINVAL) {
if (++sbbc_ecc_mbox_inval_errs >=
sbbc_ecc_mbox_err_throttle) {
sbbc_ecc_mbox_inval_errs = 0;
}
rv = ENOMSG;
} else {
if (++sbbc_ecc_mbox_other_errs >=
sbbc_ecc_mbox_err_throttle) {
sbbc_ecc_mbox_other_errs = 0;
}
rv = msgp->ecc_resp.msg_status;
}
}
} else {
if (msgp->ecc_resp.msg_type.type == INFO_MBOX) {
switch (msgp->ecc_resp.msg_type.sub_type) {
case INFO_MBOX_ECC_CAP:
/*
* Successfully received the response
* for the capability message, so updating
* the SC ECC messaging capability.
*/
cap = (plat_capability_data_t *)
msgp->ecc_resp.msg_buf;
plat_ecc_capability_sc_set
(cap->capd_capability);
break;
case INFO_MBOX_ECC:
hdr = (plat_ecc_msg_hdr_t *)
msgp->ecc_resp.msg_buf;
if (hdr && (hdr->emh_msg_type ==
PLAT_ECC_DIMM_SID_MESSAGE)) {
/*
* Successfully received a response
* to a request for DIMM serial ids.
*/
ddata = (plat_dimm_sid_board_data_t *)
msgp->ecc_resp.msg_buf;
(void) plat_store_mem_sids(ddata);
}
break;
default:
break;
}
}
}
if (msgp->ecc_resp.msg_buf)
kmem_free((void *)msgp->ecc_resp.msg_buf,
(size_t)msgp->ecc_resp.msg_len);
kmem_free((void *)msgp->ecc_req.msg_buf, (size_t)msgp->ecc_req.msg_len);
kmem_free(msgp, sizeof (sbbc_ecc_mbox_t));
return (rv);
}
/*
* Enqueue ECC event message on taskq to SC. This is invoked from
* plat_send_ecc_mailbox_msg() for each ECC event generating a message.
*/
void
sbbc_mbox_queue_ecc_event(sbbc_ecc_mbox_t *sbbc_ecc_msgp)
{
/*
* Create the ECC event mailbox taskq, if it does not yet exist.
* This must be done here rather than in sbbc_mbox_init(). The
* sgsbbc driver is loaded very early in the boot flow. Calling
* taskq_create() from sbbc_mbox_init could lead to a boot deadlock.
*
* There might be a tiny probability that two ECC handlers on
* different processors could arrive here simultaneously. If
* the taskq has not been created previously, then these two
* simultaneous events could cause the creation of an extra taskq.
* Given the extremely small likelihood (if not outright impossibility)
* of this occurrence, sbbc_ecc_mbox_taskq is not protected by a lock.
*/
if (sbbc_ecc_mbox_taskq == NULL) {
sbbc_ecc_mbox_taskq = taskq_create("ECC_event_mailbox", 1,
minclsyspri, ECC_MBOX_TASKQ_MIN, ECC_MBOX_TASKQ_MAX,
TASKQ_PREPOPULATE);
if (sbbc_ecc_mbox_taskq == NULL) {
if (sbbc_ecc_mbox_taskq_errs == 0) {
cmn_err(CE_NOTE, "Unable to create mailbox "
"task queue for ECC event logging to "
"System Controller");
}
if (++sbbc_ecc_mbox_taskq_errs >=
sbbc_ecc_mbox_err_throttle) {
sbbc_ecc_mbox_taskq_errs = 0;
}
kmem_free((void *)sbbc_ecc_msgp->ecc_req.msg_buf,
(size_t)sbbc_ecc_msgp->ecc_req.msg_len);
kmem_free((void *)sbbc_ecc_msgp,
sizeof (sbbc_ecc_mbox_t));
return;
}
/*
* Reset error counter so that first taskq_dispatch
* error will be output
*/
sbbc_ecc_mbox_taskq_errs = 0;
}
/*
* Enqueue the message
*/
if (taskq_dispatch(sbbc_ecc_mbox_taskq,
(task_func_t *)sbbc_mbox_ecc_output, sbbc_ecc_msgp,
TQ_NOSLEEP) == TASKQID_INVALID) {
if (sbbc_ecc_mbox_taskq_errs == 0) {
cmn_err(CE_NOTE, "Unable to send ECC event "
"message to System Controller");
}
if (++sbbc_ecc_mbox_taskq_errs >= sbbc_ecc_mbox_err_throttle) {
sbbc_ecc_mbox_taskq_errs = 0;
}
kmem_free((void *)sbbc_ecc_msgp->ecc_req.msg_buf,
(size_t)sbbc_ecc_msgp->ecc_req.msg_len);
kmem_free((void *)sbbc_ecc_msgp, sizeof (sbbc_ecc_mbox_t));
}
}
static uint_t
cap_ecc_msg_handler(char *addr)
{
sbbc_msg_t *msg = NULL;
plat_capability_data_t *cap = NULL;
static fn_t f = "cap_ecc_msg_handler";
msg = (sbbc_msg_t *)addr;
if (msg == NULL) {
SGSBBC_DBG_EVENT(CE_WARN, "cap_ecc_msg_handler() called with "
"null addr");
return (DDI_INTR_CLAIMED);
}
if (msg->msg_buf == NULL) {
SGSBBC_DBG_EVENT(CE_WARN, "cap_ecc_msg_handler() called with "
"null data buffer");
return (DDI_INTR_CLAIMED);
}
cap = (plat_capability_data_t *)msg->msg_buf;
switch (cap->capd_msg_type) {
case PLAT_ECC_CAPABILITY_MESSAGE:
SGSBBC_DBG_MBOX("%s: capability 0x%x\n", f,
cap->capd_capability);
plat_ecc_capability_sc_set(cap->capd_capability);
break;
default:
SGSBBC_DBG_MBOX("%s: Unknown message type = 0x%x\n", f,
cap->capd_msg_type);
break;
}
return (DDI_INTR_CLAIMED);
}
|