1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
|
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* LDoms virtual disk client (vdc) device driver
*
* This driver runs on a guest logical domain and communicates with the virtual
* disk server (vds) driver running on the service domain which is exporting
* virtualized "disks" to the guest logical domain.
*
* The driver can be divided into four sections:
*
* 1) generic device driver housekeeping
* _init, _fini, attach, detach, ops structures, etc.
*
* 2) communication channel setup
* Setup the communications link over the LDC channel that vdc uses to
* talk to the vDisk server. Initialise the descriptor ring which
* allows the LDC clients to transfer data via memory mappings.
*
* 3) Support exported to upper layers (filesystems, etc)
* The upper layers call into vdc via strategy(9E) and DKIO(7I)
* ioctl calls. vdc will copy the data to be written to the descriptor
* ring or maps the buffer to store the data read by the vDisk
* server into the descriptor ring. It then sends a message to the
* vDisk server requesting it to complete the operation.
*
* 4) Handling responses from vDisk server.
* The vDisk server will ACK some or all of the messages vdc sends to it
* (this is configured during the handshake). Upon receipt of an ACK
* vdc will check the descriptor ring and signal to the upper layer
* code waiting on the IO.
*/
#include <sys/atomic.h>
#include <sys/conf.h>
#include <sys/disp.h>
#include <sys/ddi.h>
#include <sys/dkio.h>
#include <sys/efi_partition.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/mach_descrip.h>
#include <sys/modctl.h>
#include <sys/mdeg.h>
#include <sys/note.h>
#include <sys/open.h>
#include <sys/sdt.h>
#include <sys/stat.h>
#include <sys/sunddi.h>
#include <sys/types.h>
#include <sys/promif.h>
#include <sys/vtoc.h>
#include <sys/archsystm.h>
#include <sys/sysmacros.h>
#include <sys/cdio.h>
#include <sys/dktp/fdisk.h>
#include <sys/dktp/dadkio.h>
#include <sys/scsi/generic/sense.h>
#include <sys/scsi/impl/uscsi.h> /* Needed for defn of USCSICMD ioctl */
#include <sys/ldoms.h>
#include <sys/ldc.h>
#include <sys/vio_common.h>
#include <sys/vio_mailbox.h>
#include <sys/vdsk_common.h>
#include <sys/vdsk_mailbox.h>
#include <sys/vdc.h>
/*
* function prototypes
*/
/* standard driver functions */
static int vdc_open(dev_t *dev, int flag, int otyp, cred_t *cred);
static int vdc_close(dev_t dev, int flag, int otyp, cred_t *cred);
static int vdc_strategy(struct buf *buf);
static int vdc_print(dev_t dev, char *str);
static int vdc_dump(dev_t dev, caddr_t addr, daddr_t blkno, int nblk);
static int vdc_read(dev_t dev, struct uio *uio, cred_t *cred);
static int vdc_write(dev_t dev, struct uio *uio, cred_t *cred);
static int vdc_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
cred_t *credp, int *rvalp);
static int vdc_aread(dev_t dev, struct aio_req *aio, cred_t *cred);
static int vdc_awrite(dev_t dev, struct aio_req *aio, cred_t *cred);
static int vdc_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd,
void *arg, void **resultp);
static int vdc_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
static int vdc_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
/* setup */
static void vdc_min(struct buf *bufp);
static int vdc_send(vdc_t *vdc, caddr_t pkt, size_t *msglen);
static int vdc_do_ldc_init(vdc_t *vdc);
static int vdc_start_ldc_connection(vdc_t *vdc);
static int vdc_create_device_nodes(vdc_t *vdc);
static int vdc_create_device_nodes_efi(vdc_t *vdc);
static int vdc_create_device_nodes_vtoc(vdc_t *vdc);
static int vdc_create_device_nodes_props(vdc_t *vdc);
static int vdc_get_ldc_id(dev_info_t *dip, uint64_t *ldc_id);
static int vdc_do_ldc_up(vdc_t *vdc);
static void vdc_terminate_ldc(vdc_t *vdc);
static int vdc_init_descriptor_ring(vdc_t *vdc);
static void vdc_destroy_descriptor_ring(vdc_t *vdc);
static int vdc_setup_devid(vdc_t *vdc);
static void vdc_store_efi(vdc_t *vdc, struct dk_gpt *efi);
/* handshake with vds */
static int vdc_init_ver_negotiation(vdc_t *vdc, vio_ver_t ver);
static int vdc_ver_negotiation(vdc_t *vdcp);
static int vdc_init_attr_negotiation(vdc_t *vdc);
static int vdc_attr_negotiation(vdc_t *vdcp);
static int vdc_init_dring_negotiate(vdc_t *vdc);
static int vdc_dring_negotiation(vdc_t *vdcp);
static int vdc_send_rdx(vdc_t *vdcp);
static int vdc_rdx_exchange(vdc_t *vdcp);
static boolean_t vdc_is_supported_version(vio_ver_msg_t *ver_msg);
/* processing incoming messages from vDisk server */
static void vdc_process_msg_thread(vdc_t *vdc);
static int vdc_recv(vdc_t *vdc, vio_msg_t *msgp, size_t *nbytesp);
static uint_t vdc_handle_cb(uint64_t event, caddr_t arg);
static int vdc_process_data_msg(vdc_t *vdc, vio_msg_t *msg);
static int vdc_process_err_msg(vdc_t *vdc, vio_msg_t msg);
static int vdc_handle_ver_msg(vdc_t *vdc, vio_ver_msg_t *ver_msg);
static int vdc_handle_attr_msg(vdc_t *vdc, vd_attr_msg_t *attr_msg);
static int vdc_handle_dring_reg_msg(vdc_t *vdc, vio_dring_reg_msg_t *msg);
static int vdc_send_request(vdc_t *vdcp, int operation,
caddr_t addr, size_t nbytes, int slice, diskaddr_t offset,
int cb_type, void *cb_arg, vio_desc_direction_t dir);
static int vdc_map_to_shared_dring(vdc_t *vdcp, int idx);
static int vdc_populate_descriptor(vdc_t *vdcp, int operation,
caddr_t addr, size_t nbytes, int slice, diskaddr_t offset,
int cb_type, void *cb_arg, vio_desc_direction_t dir);
static int vdc_do_sync_op(vdc_t *vdcp, int operation,
caddr_t addr, size_t nbytes, int slice, diskaddr_t offset,
int cb_type, void *cb_arg, vio_desc_direction_t dir);
static int vdc_wait_for_response(vdc_t *vdcp, vio_msg_t *msgp);
static int vdc_drain_response(vdc_t *vdcp);
static int vdc_depopulate_descriptor(vdc_t *vdc, uint_t idx);
static int vdc_populate_mem_hdl(vdc_t *vdcp, vdc_local_desc_t *ldep);
static int vdc_verify_seq_num(vdc_t *vdc, vio_dring_msg_t *dring_msg);
/* dkio */
static int vd_process_ioctl(dev_t dev, int cmd, caddr_t arg, int mode);
static int vdc_create_fake_geometry(vdc_t *vdc);
static int vdc_setup_disk_layout(vdc_t *vdc);
static int vdc_null_copy_func(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_get_wce_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_set_wce_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_get_vtoc_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_set_vtoc_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_get_geom_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_set_geom_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_uscsicmd_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_get_efi_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
static int vdc_set_efi_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir);
/*
* Module variables
*/
/*
* Tunable variables to control how long vdc waits before timing out on
* various operations
*/
static int vdc_retries = 10;
static int vdc_hshake_retries = 3;
/* calculated from 'vdc_usec_timeout' during attach */
static uint64_t vdc_hz_timeout; /* units: Hz */
static uint64_t vdc_usec_timeout = 30 * MICROSEC; /* 30s units: ns */
static uint64_t vdc_hz_min_ldc_delay;
static uint64_t vdc_min_timeout_ldc = 1 * MILLISEC;
static uint64_t vdc_hz_max_ldc_delay;
static uint64_t vdc_max_timeout_ldc = 100 * MILLISEC;
static uint64_t vdc_ldc_read_init_delay = 1 * MILLISEC;
static uint64_t vdc_ldc_read_max_delay = 100 * MILLISEC;
/* values for dumping - need to run in a tighter loop */
static uint64_t vdc_usec_timeout_dump = 100 * MILLISEC; /* 0.1s units: ns */
static int vdc_dump_retries = 100;
/* Count of the number of vdc instances attached */
static volatile uint32_t vdc_instance_count = 0;
/* Soft state pointer */
static void *vdc_state;
/*
* Controlling the verbosity of the error/debug messages
*
* vdc_msglevel - controls level of messages
* vdc_matchinst - 64-bit variable where each bit corresponds
* to the vdc instance the vdc_msglevel applies.
*/
int vdc_msglevel = 0x0;
uint64_t vdc_matchinst = 0ull;
/*
* Supported vDisk protocol version pairs.
*
* The first array entry is the latest and preferred version.
*/
static const vio_ver_t vdc_version[] = {{1, 0}};
static struct cb_ops vdc_cb_ops = {
vdc_open, /* cb_open */
vdc_close, /* cb_close */
vdc_strategy, /* cb_strategy */
vdc_print, /* cb_print */
vdc_dump, /* cb_dump */
vdc_read, /* cb_read */
vdc_write, /* cb_write */
vdc_ioctl, /* cb_ioctl */
nodev, /* cb_devmap */
nodev, /* cb_mmap */
nodev, /* cb_segmap */
nochpoll, /* cb_chpoll */
ddi_prop_op, /* cb_prop_op */
NULL, /* cb_str */
D_MP | D_64BIT, /* cb_flag */
CB_REV, /* cb_rev */
vdc_aread, /* cb_aread */
vdc_awrite /* cb_awrite */
};
static struct dev_ops vdc_ops = {
DEVO_REV, /* devo_rev */
0, /* devo_refcnt */
vdc_getinfo, /* devo_getinfo */
nulldev, /* devo_identify */
nulldev, /* devo_probe */
vdc_attach, /* devo_attach */
vdc_detach, /* devo_detach */
nodev, /* devo_reset */
&vdc_cb_ops, /* devo_cb_ops */
NULL, /* devo_bus_ops */
nulldev /* devo_power */
};
static struct modldrv modldrv = {
&mod_driverops,
"virtual disk client %I%",
&vdc_ops,
};
static struct modlinkage modlinkage = {
MODREV_1,
&modldrv,
NULL
};
/* -------------------------------------------------------------------------- */
/*
* Device Driver housekeeping and setup
*/
int
_init(void)
{
int status;
if ((status = ddi_soft_state_init(&vdc_state, sizeof (vdc_t), 1)) != 0)
return (status);
if ((status = mod_install(&modlinkage)) != 0)
ddi_soft_state_fini(&vdc_state);
vdc_efi_init(vd_process_ioctl);
return (status);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
int
_fini(void)
{
int status;
if ((status = mod_remove(&modlinkage)) != 0)
return (status);
vdc_efi_fini();
ddi_soft_state_fini(&vdc_state);
return (0);
}
static int
vdc_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **resultp)
{
_NOTE(ARGUNUSED(dip))
int instance = VDCUNIT((dev_t)arg);
vdc_t *vdc = NULL;
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
if ((vdc = ddi_get_soft_state(vdc_state, instance)) == NULL) {
*resultp = NULL;
return (DDI_FAILURE);
}
*resultp = vdc->dip;
return (DDI_SUCCESS);
case DDI_INFO_DEVT2INSTANCE:
*resultp = (void *)(uintptr_t)instance;
return (DDI_SUCCESS);
default:
*resultp = NULL;
return (DDI_FAILURE);
}
}
static int
vdc_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
{
int instance;
int rv;
vdc_t *vdc = NULL;
switch (cmd) {
case DDI_DETACH:
/* the real work happens below */
break;
case DDI_SUSPEND:
/* nothing to do for this non-device */
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
ASSERT(cmd == DDI_DETACH);
instance = ddi_get_instance(dip);
DMSGX(1, "[%d] Entered\n", instance);
if ((vdc = ddi_get_soft_state(vdc_state, instance)) == NULL) {
cmn_err(CE_NOTE, "[%d] Couldn't get state structure", instance);
return (DDI_FAILURE);
}
if (vdc->open_count) {
DMSG(vdc, 0, "[%d] Cannot detach: device is open", instance);
return (DDI_FAILURE);
}
DMSG(vdc, 0, "[%d] proceeding...\n", instance);
/* mark instance as detaching */
vdc->lifecycle = VDC_LC_DETACHING;
/*
* try and disable callbacks to prevent another handshake
*/
rv = ldc_set_cb_mode(vdc->ldc_handle, LDC_CB_DISABLE);
DMSG(vdc, 0, "callback disabled (rv=%d)\n", rv);
if (vdc->initialized & VDC_THREAD) {
mutex_enter(&vdc->read_lock);
if ((vdc->read_state == VDC_READ_WAITING) ||
(vdc->read_state == VDC_READ_RESET)) {
vdc->read_state = VDC_READ_RESET;
cv_signal(&vdc->read_cv);
}
mutex_exit(&vdc->read_lock);
/* wake up any thread waiting for connection to come online */
mutex_enter(&vdc->lock);
if (vdc->state == VDC_STATE_INIT_WAITING) {
DMSG(vdc, 0,
"[%d] write reset - move to resetting state...\n",
instance);
vdc->state = VDC_STATE_RESETTING;
cv_signal(&vdc->initwait_cv);
}
mutex_exit(&vdc->lock);
/* now wait until state transitions to VDC_STATE_DETACH */
thread_join(vdc->msg_proc_thr->t_did);
ASSERT(vdc->state == VDC_STATE_DETACH);
DMSG(vdc, 0, "[%d] Reset thread exit and join ..\n",
vdc->instance);
}
mutex_enter(&vdc->lock);
if (vdc->initialized & VDC_DRING)
vdc_destroy_descriptor_ring(vdc);
if (vdc->initialized & VDC_LDC)
vdc_terminate_ldc(vdc);
mutex_exit(&vdc->lock);
if (vdc->initialized & VDC_MINOR) {
ddi_prop_remove_all(dip);
ddi_remove_minor_node(dip, NULL);
}
if (vdc->initialized & VDC_LOCKS) {
mutex_destroy(&vdc->lock);
mutex_destroy(&vdc->read_lock);
cv_destroy(&vdc->initwait_cv);
cv_destroy(&vdc->dring_free_cv);
cv_destroy(&vdc->membind_cv);
cv_destroy(&vdc->sync_pending_cv);
cv_destroy(&vdc->sync_blocked_cv);
cv_destroy(&vdc->read_cv);
cv_destroy(&vdc->running_cv);
}
if (vdc->minfo)
kmem_free(vdc->minfo, sizeof (struct dk_minfo));
if (vdc->cinfo)
kmem_free(vdc->cinfo, sizeof (struct dk_cinfo));
if (vdc->vtoc)
kmem_free(vdc->vtoc, sizeof (struct vtoc));
if (vdc->label)
kmem_free(vdc->label, DK_LABEL_SIZE);
if (vdc->devid) {
ddi_devid_unregister(dip);
ddi_devid_free(vdc->devid);
}
if (vdc->initialized & VDC_SOFT_STATE)
ddi_soft_state_free(vdc_state, instance);
DMSG(vdc, 0, "[%d] End %p\n", instance, (void *)vdc);
return (DDI_SUCCESS);
}
static int
vdc_do_attach(dev_info_t *dip)
{
int instance;
vdc_t *vdc = NULL;
int status;
ASSERT(dip != NULL);
instance = ddi_get_instance(dip);
if (ddi_soft_state_zalloc(vdc_state, instance) != DDI_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't alloc state structure",
instance);
return (DDI_FAILURE);
}
if ((vdc = ddi_get_soft_state(vdc_state, instance)) == NULL) {
cmn_err(CE_NOTE, "[%d] Couldn't get state structure", instance);
return (DDI_FAILURE);
}
/*
* We assign the value to initialized in this case to zero out the
* variable and then set bits in it to indicate what has been done
*/
vdc->initialized = VDC_SOFT_STATE;
vdc_hz_timeout = drv_usectohz(vdc_usec_timeout);
vdc_hz_min_ldc_delay = drv_usectohz(vdc_min_timeout_ldc);
vdc_hz_max_ldc_delay = drv_usectohz(vdc_max_timeout_ldc);
vdc->dip = dip;
vdc->instance = instance;
vdc->open_count = 0;
vdc->vdisk_type = VD_DISK_TYPE_UNK;
vdc->vdisk_label = VD_DISK_LABEL_UNK;
vdc->state = VDC_STATE_INIT;
vdc->lifecycle = VDC_LC_ATTACHING;
vdc->ldc_state = 0;
vdc->session_id = 0;
vdc->block_size = DEV_BSIZE;
vdc->max_xfer_sz = maxphys / DEV_BSIZE;
vdc->vtoc = NULL;
vdc->cinfo = NULL;
vdc->minfo = NULL;
mutex_init(&vdc->lock, NULL, MUTEX_DRIVER, NULL);
cv_init(&vdc->initwait_cv, NULL, CV_DRIVER, NULL);
cv_init(&vdc->dring_free_cv, NULL, CV_DRIVER, NULL);
cv_init(&vdc->membind_cv, NULL, CV_DRIVER, NULL);
cv_init(&vdc->running_cv, NULL, CV_DRIVER, NULL);
vdc->threads_pending = 0;
vdc->sync_op_pending = B_FALSE;
vdc->sync_op_blocked = B_FALSE;
cv_init(&vdc->sync_pending_cv, NULL, CV_DRIVER, NULL);
cv_init(&vdc->sync_blocked_cv, NULL, CV_DRIVER, NULL);
/* init blocking msg read functionality */
mutex_init(&vdc->read_lock, NULL, MUTEX_DRIVER, NULL);
cv_init(&vdc->read_cv, NULL, CV_DRIVER, NULL);
vdc->read_state = VDC_READ_IDLE;
vdc->initialized |= VDC_LOCKS;
/* initialise LDC channel which will be used to communicate with vds */
if ((status = vdc_do_ldc_init(vdc)) != 0) {
cmn_err(CE_NOTE, "[%d] Couldn't initialize LDC", instance);
goto return_status;
}
/* initialize the thread responsible for managing state with server */
vdc->msg_proc_thr = thread_create(NULL, 0, vdc_process_msg_thread,
vdc, 0, &p0, TS_RUN, minclsyspri);
if (vdc->msg_proc_thr == NULL) {
cmn_err(CE_NOTE, "[%d] Failed to create msg processing thread",
instance);
return (DDI_FAILURE);
}
vdc->initialized |= VDC_THREAD;
atomic_inc_32(&vdc_instance_count);
/*
* Once the handshake is complete, we can use the DRing to send
* requests to the vDisk server to calculate the geometry and
* VTOC of the "disk"
*/
status = vdc_setup_disk_layout(vdc);
if (status != 0) {
DMSG(vdc, 0, "[%d] Failed to discover disk layout (err%d)",
vdc->instance, status);
goto return_status;
}
/*
* Now that we have the device info we can create the
* device nodes and properties
*/
status = vdc_create_device_nodes(vdc);
if (status) {
DMSG(vdc, 0, "[%d] Failed to create device nodes",
instance);
goto return_status;
}
status = vdc_create_device_nodes_props(vdc);
if (status) {
DMSG(vdc, 0, "[%d] Failed to create device nodes"
" properties (%d)", instance, status);
goto return_status;
}
/*
* Setup devid
*/
if (vdc_setup_devid(vdc)) {
DMSG(vdc, 0, "[%d] No device id available\n", instance);
}
ddi_report_dev(dip);
vdc->lifecycle = VDC_LC_ONLINE;
DMSG(vdc, 0, "[%d] Attach tasks successful\n", instance);
return_status:
DMSG(vdc, 0, "[%d] Attach completed\n", instance);
return (status);
}
static int
vdc_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
int status;
switch (cmd) {
case DDI_ATTACH:
if ((status = vdc_do_attach(dip)) != 0)
(void) vdc_detach(dip, DDI_DETACH);
return (status);
case DDI_RESUME:
/* nothing to do for this non-device */
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
static int
vdc_do_ldc_init(vdc_t *vdc)
{
int status = 0;
ldc_status_t ldc_state;
ldc_attr_t ldc_attr;
uint64_t ldc_id = 0;
dev_info_t *dip = NULL;
ASSERT(vdc != NULL);
dip = vdc->dip;
vdc->initialized |= VDC_LDC;
if ((status = vdc_get_ldc_id(dip, &ldc_id)) != 0) {
DMSG(vdc, 0, "[%d] Failed to get LDC channel ID property",
vdc->instance);
return (EIO);
}
vdc->ldc_id = ldc_id;
ldc_attr.devclass = LDC_DEV_BLK;
ldc_attr.instance = vdc->instance;
ldc_attr.mode = LDC_MODE_UNRELIABLE; /* unreliable transport */
ldc_attr.mtu = VD_LDC_MTU;
if ((vdc->initialized & VDC_LDC_INIT) == 0) {
status = ldc_init(ldc_id, &ldc_attr, &vdc->ldc_handle);
if (status != 0) {
DMSG(vdc, 0, "[%d] ldc_init(chan %ld) returned %d",
vdc->instance, ldc_id, status);
return (status);
}
vdc->initialized |= VDC_LDC_INIT;
}
status = ldc_status(vdc->ldc_handle, &ldc_state);
if (status != 0) {
DMSG(vdc, 0, "[%d] Cannot discover LDC status [err=%d]",
vdc->instance, status);
return (status);
}
vdc->ldc_state = ldc_state;
if ((vdc->initialized & VDC_LDC_CB) == 0) {
status = ldc_reg_callback(vdc->ldc_handle, vdc_handle_cb,
(caddr_t)vdc);
if (status != 0) {
DMSG(vdc, 0, "[%d] LDC callback reg. failed (%d)",
vdc->instance, status);
return (status);
}
vdc->initialized |= VDC_LDC_CB;
}
vdc->initialized |= VDC_LDC;
/*
* At this stage we have initialised LDC, we will now try and open
* the connection.
*/
if (vdc->ldc_state == LDC_INIT) {
status = ldc_open(vdc->ldc_handle);
if (status != 0) {
DMSG(vdc, 0, "[%d] ldc_open(chan %ld) returned %d",
vdc->instance, vdc->ldc_id, status);
return (status);
}
vdc->initialized |= VDC_LDC_OPEN;
}
return (status);
}
static int
vdc_start_ldc_connection(vdc_t *vdc)
{
int status = 0;
ASSERT(vdc != NULL);
ASSERT(MUTEX_HELD(&vdc->lock));
status = vdc_do_ldc_up(vdc);
DMSG(vdc, 0, "[%d] Finished bringing up LDC\n", vdc->instance);
return (status);
}
static int
vdc_stop_ldc_connection(vdc_t *vdcp)
{
int status;
DMSG(vdcp, 0, ": Resetting connection to vDisk server : state %d\n",
vdcp->state);
status = ldc_down(vdcp->ldc_handle);
DMSG(vdcp, 0, "ldc_down() = %d\n", status);
vdcp->initialized &= ~VDC_HANDSHAKE;
DMSG(vdcp, 0, "initialized=%x\n", vdcp->initialized);
return (status);
}
static int
vdc_create_device_nodes_efi(vdc_t *vdc)
{
ddi_remove_minor_node(vdc->dip, "h");
ddi_remove_minor_node(vdc->dip, "h,raw");
if (ddi_create_minor_node(vdc->dip, "wd", S_IFBLK,
VD_MAKE_DEV(vdc->instance, VD_EFI_WD_SLICE),
DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't add block node 'wd'",
vdc->instance);
return (EIO);
}
/* if any device node is created we set this flag */
vdc->initialized |= VDC_MINOR;
if (ddi_create_minor_node(vdc->dip, "wd,raw", S_IFCHR,
VD_MAKE_DEV(vdc->instance, VD_EFI_WD_SLICE),
DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't add block node 'wd,raw'",
vdc->instance);
return (EIO);
}
return (0);
}
static int
vdc_create_device_nodes_vtoc(vdc_t *vdc)
{
ddi_remove_minor_node(vdc->dip, "wd");
ddi_remove_minor_node(vdc->dip, "wd,raw");
if (ddi_create_minor_node(vdc->dip, "h", S_IFBLK,
VD_MAKE_DEV(vdc->instance, VD_EFI_WD_SLICE),
DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't add block node 'h'",
vdc->instance);
return (EIO);
}
/* if any device node is created we set this flag */
vdc->initialized |= VDC_MINOR;
if (ddi_create_minor_node(vdc->dip, "h,raw", S_IFCHR,
VD_MAKE_DEV(vdc->instance, VD_EFI_WD_SLICE),
DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't add block node 'h,raw'",
vdc->instance);
return (EIO);
}
return (0);
}
/*
* Function:
* vdc_create_device_nodes
*
* Description:
* This function creates the block and character device nodes under
* /devices along with the node properties. It is called as part of
* the attach(9E) of the instance during the handshake with vds after
* vds has sent the attributes to vdc.
*
* If the device is of type VD_DISK_TYPE_SLICE then the minor node
* of 2 is used in keeping with the Solaris convention that slice 2
* refers to a whole disk. Slices start at 'a'
*
* Parameters:
* vdc - soft state pointer
*
* Return Values
* 0 - Success
* EIO - Failed to create node
* EINVAL - Unknown type of disk exported
*/
static int
vdc_create_device_nodes(vdc_t *vdc)
{
char name[sizeof ("s,raw")];
dev_info_t *dip = NULL;
int instance, status;
int num_slices = 1;
int i;
ASSERT(vdc != NULL);
instance = vdc->instance;
dip = vdc->dip;
switch (vdc->vdisk_type) {
case VD_DISK_TYPE_DISK:
num_slices = V_NUMPAR;
break;
case VD_DISK_TYPE_SLICE:
num_slices = 1;
break;
case VD_DISK_TYPE_UNK:
default:
return (EINVAL);
}
/*
* Minor nodes are different for EFI disks: EFI disks do not have
* a minor node 'g' for the minor number corresponding to slice
* VD_EFI_WD_SLICE (slice 7) instead they have a minor node 'wd'
* representing the whole disk.
*/
for (i = 0; i < num_slices; i++) {
if (i == VD_EFI_WD_SLICE) {
if (vdc->vdisk_label == VD_DISK_LABEL_EFI)
status = vdc_create_device_nodes_efi(vdc);
else
status = vdc_create_device_nodes_vtoc(vdc);
if (status != 0)
return (status);
continue;
}
(void) snprintf(name, sizeof (name), "%c", 'a' + i);
if (ddi_create_minor_node(dip, name, S_IFBLK,
VD_MAKE_DEV(instance, i), DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't add block node '%s'",
instance, name);
return (EIO);
}
/* if any device node is created we set this flag */
vdc->initialized |= VDC_MINOR;
(void) snprintf(name, sizeof (name), "%c%s", 'a' + i, ",raw");
if (ddi_create_minor_node(dip, name, S_IFCHR,
VD_MAKE_DEV(instance, i), DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't add raw node '%s'",
instance, name);
return (EIO);
}
}
return (0);
}
/*
* Function:
* vdc_create_device_nodes_props
*
* Description:
* This function creates the block and character device nodes under
* /devices along with the node properties. It is called as part of
* the attach(9E) of the instance during the handshake with vds after
* vds has sent the attributes to vdc.
*
* Parameters:
* vdc - soft state pointer
*
* Return Values
* 0 - Success
* EIO - Failed to create device node property
* EINVAL - Unknown type of disk exported
*/
static int
vdc_create_device_nodes_props(vdc_t *vdc)
{
dev_info_t *dip = NULL;
int instance;
int num_slices = 1;
int64_t size = 0;
dev_t dev;
int rv;
int i;
ASSERT(vdc != NULL);
instance = vdc->instance;
dip = vdc->dip;
if ((vdc->vtoc == NULL) || (vdc->vtoc->v_sanity != VTOC_SANE)) {
DMSG(vdc, 0, "![%d] Could not create device node property."
" No VTOC available", instance);
return (ENXIO);
}
switch (vdc->vdisk_type) {
case VD_DISK_TYPE_DISK:
num_slices = V_NUMPAR;
break;
case VD_DISK_TYPE_SLICE:
num_slices = 1;
break;
case VD_DISK_TYPE_UNK:
default:
return (EINVAL);
}
for (i = 0; i < num_slices; i++) {
dev = makedevice(ddi_driver_major(dip),
VD_MAKE_DEV(instance, i));
size = vdc->vtoc->v_part[i].p_size * vdc->vtoc->v_sectorsz;
DMSG(vdc, 0, "[%d] sz %ld (%ld Mb) p_size %lx\n",
instance, size, size / (1024 * 1024),
vdc->vtoc->v_part[i].p_size);
rv = ddi_prop_update_int64(dev, dip, VDC_SIZE_PROP_NAME, size);
if (rv != DDI_PROP_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't add '%s' prop of [%ld]",
instance, VDC_SIZE_PROP_NAME, size);
return (EIO);
}
rv = ddi_prop_update_int64(dev, dip, VDC_NBLOCKS_PROP_NAME,
lbtodb(size));
if (rv != DDI_PROP_SUCCESS) {
cmn_err(CE_NOTE, "[%d] Couldn't add '%s' prop [%llu]",
instance, VDC_NBLOCKS_PROP_NAME, lbtodb(size));
return (EIO);
}
}
return (0);
}
static int
vdc_open(dev_t *dev, int flag, int otyp, cred_t *cred)
{
_NOTE(ARGUNUSED(cred))
int instance;
vdc_t *vdc;
ASSERT(dev != NULL);
instance = VDCUNIT(*dev);
if ((otyp != OTYP_CHR) && (otyp != OTYP_BLK))
return (EINVAL);
if ((vdc = ddi_get_soft_state(vdc_state, instance)) == NULL) {
cmn_err(CE_NOTE, "[%d] Couldn't get state structure", instance);
return (ENXIO);
}
DMSG(vdc, 0, "minor = %d flag = %x, otyp = %x\n",
getminor(*dev), flag, otyp);
mutex_enter(&vdc->lock);
vdc->open_count++;
mutex_exit(&vdc->lock);
return (0);
}
static int
vdc_close(dev_t dev, int flag, int otyp, cred_t *cred)
{
_NOTE(ARGUNUSED(cred))
int instance;
vdc_t *vdc;
instance = VDCUNIT(dev);
if ((otyp != OTYP_CHR) && (otyp != OTYP_BLK))
return (EINVAL);
if ((vdc = ddi_get_soft_state(vdc_state, instance)) == NULL) {
cmn_err(CE_NOTE, "[%d] Couldn't get state structure", instance);
return (ENXIO);
}
DMSG(vdc, 0, "[%d] flag = %x, otyp = %x\n", instance, flag, otyp);
if (vdc->dkio_flush_pending) {
DMSG(vdc, 0,
"[%d] Cannot detach: %d outstanding DKIO flushes\n",
instance, vdc->dkio_flush_pending);
return (EBUSY);
}
/*
* Should not need the mutex here, since the framework should protect
* against more opens on this device, but just in case.
*/
mutex_enter(&vdc->lock);
vdc->open_count--;
mutex_exit(&vdc->lock);
return (0);
}
static int
vdc_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp)
{
_NOTE(ARGUNUSED(credp))
_NOTE(ARGUNUSED(rvalp))
return (vd_process_ioctl(dev, cmd, (caddr_t)arg, mode));
}
static int
vdc_print(dev_t dev, char *str)
{
cmn_err(CE_NOTE, "vdc%d: %s", VDCUNIT(dev), str);
return (0);
}
static int
vdc_dump(dev_t dev, caddr_t addr, daddr_t blkno, int nblk)
{
int rv;
size_t nbytes = nblk * DEV_BSIZE;
int instance = VDCUNIT(dev);
vdc_t *vdc = NULL;
if ((vdc = ddi_get_soft_state(vdc_state, instance)) == NULL) {
cmn_err(CE_NOTE, "[%d] Couldn't get state structure", instance);
return (ENXIO);
}
DMSG(vdc, 2, "[%d] dump %ld bytes at block 0x%lx : addr=0x%p\n",
instance, nbytes, blkno, (void *)addr);
rv = vdc_send_request(vdc, VD_OP_BWRITE, addr, nbytes,
VDCPART(dev), blkno, CB_STRATEGY, 0, VIO_write_dir);
if (rv) {
DMSG(vdc, 0, "Failed to do a disk dump (err=%d)\n", rv);
return (rv);
}
if (ddi_in_panic())
(void) vdc_drain_response(vdc);
DMSG(vdc, 0, "[%d] End\n", instance);
return (0);
}
/* -------------------------------------------------------------------------- */
/*
* Disk access routines
*
*/
/*
* vdc_strategy()
*
* Return Value:
* 0: As per strategy(9E), the strategy() function must return 0
* [ bioerror(9f) sets b_flags to the proper error code ]
*/
static int
vdc_strategy(struct buf *buf)
{
int rv = -1;
vdc_t *vdc = NULL;
int instance = VDCUNIT(buf->b_edev);
int op = (buf->b_flags & B_READ) ? VD_OP_BREAD : VD_OP_BWRITE;
int slice;
if ((vdc = ddi_get_soft_state(vdc_state, instance)) == NULL) {
cmn_err(CE_NOTE, "[%d] Couldn't get state structure", instance);
bioerror(buf, ENXIO);
biodone(buf);
return (0);
}
DMSG(vdc, 2, "[%d] %s %ld bytes at block %llx : b_addr=0x%p\n",
instance, (buf->b_flags & B_READ) ? "Read" : "Write",
buf->b_bcount, buf->b_lblkno, (void *)buf->b_un.b_addr);
DTRACE_IO2(vstart, buf_t *, buf, vdc_t *, vdc);
bp_mapin(buf);
if ((long)buf->b_private == VD_SLICE_NONE) {
/* I/O using an absolute disk offset */
slice = VD_SLICE_NONE;
} else {
slice = VDCPART(buf->b_edev);
}
rv = vdc_send_request(vdc, op, (caddr_t)buf->b_un.b_addr,
buf->b_bcount, slice, buf->b_lblkno,
CB_STRATEGY, buf, (op == VD_OP_BREAD) ? VIO_read_dir :
VIO_write_dir);
/*
* If the request was successfully sent, the strategy call returns and
* the ACK handler calls the bioxxx functions when the vDisk server is
* done.
*/
if (rv) {
DMSG(vdc, 0, "Failed to read/write (err=%d)\n", rv);
bioerror(buf, rv);
biodone(buf);
}
return (0);
}
/*
* Function:
* vdc_min
*
* Description:
* Routine to limit the size of a data transfer. Used in
* conjunction with physio(9F).
*
* Arguments:
* bp - pointer to the indicated buf(9S) struct.
*
*/
static void
vdc_min(struct buf *bufp)
{
vdc_t *vdc = NULL;
int instance = VDCUNIT(bufp->b_edev);
vdc = ddi_get_soft_state(vdc_state, instance);
VERIFY(vdc != NULL);
if (bufp->b_bcount > (vdc->max_xfer_sz * vdc->block_size)) {
bufp->b_bcount = vdc->max_xfer_sz * vdc->block_size;
}
}
static int
vdc_read(dev_t dev, struct uio *uio, cred_t *cred)
{
_NOTE(ARGUNUSED(cred))
DMSGX(1, "[%d] Entered", VDCUNIT(dev));
return (physio(vdc_strategy, NULL, dev, B_READ, vdc_min, uio));
}
static int
vdc_write(dev_t dev, struct uio *uio, cred_t *cred)
{
_NOTE(ARGUNUSED(cred))
DMSGX(1, "[%d] Entered", VDCUNIT(dev));
return (physio(vdc_strategy, NULL, dev, B_WRITE, vdc_min, uio));
}
static int
vdc_aread(dev_t dev, struct aio_req *aio, cred_t *cred)
{
_NOTE(ARGUNUSED(cred))
DMSGX(1, "[%d] Entered", VDCUNIT(dev));
return (aphysio(vdc_strategy, anocancel, dev, B_READ, vdc_min, aio));
}
static int
vdc_awrite(dev_t dev, struct aio_req *aio, cred_t *cred)
{
_NOTE(ARGUNUSED(cred))
DMSGX(1, "[%d] Entered", VDCUNIT(dev));
return (aphysio(vdc_strategy, anocancel, dev, B_WRITE, vdc_min, aio));
}
/* -------------------------------------------------------------------------- */
/*
* Handshake support
*/
/*
* Function:
* vdc_init_ver_negotiation()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_init_ver_negotiation(vdc_t *vdc, vio_ver_t ver)
{
vio_ver_msg_t pkt;
size_t msglen = sizeof (pkt);
int status = -1;
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
DMSG(vdc, 0, "[%d] Entered.\n", vdc->instance);
/*
* set the Session ID to a unique value
* (the lower 32 bits of the clock tick)
*/
vdc->session_id = ((uint32_t)gettick() & 0xffffffff);
DMSG(vdc, 0, "[%d] Set SID to 0x%lx\n", vdc->instance, vdc->session_id);
pkt.tag.vio_msgtype = VIO_TYPE_CTRL;
pkt.tag.vio_subtype = VIO_SUBTYPE_INFO;
pkt.tag.vio_subtype_env = VIO_VER_INFO;
pkt.tag.vio_sid = vdc->session_id;
pkt.dev_class = VDEV_DISK;
pkt.ver_major = ver.major;
pkt.ver_minor = ver.minor;
status = vdc_send(vdc, (caddr_t)&pkt, &msglen);
DMSG(vdc, 0, "[%d] Ver info sent (status = %d)\n",
vdc->instance, status);
if ((status != 0) || (msglen != sizeof (vio_ver_msg_t))) {
DMSG(vdc, 0, "[%d] Failed to send Ver negotiation info: "
"id(%lx) rv(%d) size(%ld)", vdc->instance, vdc->ldc_handle,
status, msglen);
if (msglen != sizeof (vio_ver_msg_t))
status = ENOMSG;
}
return (status);
}
/*
* Function:
* vdc_ver_negotiation()
*
* Description:
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_ver_negotiation(vdc_t *vdcp)
{
vio_msg_t vio_msg;
int status;
if (status = vdc_init_ver_negotiation(vdcp, vdc_version[0]))
return (status);
/* release lock and wait for response */
mutex_exit(&vdcp->lock);
status = vdc_wait_for_response(vdcp, &vio_msg);
mutex_enter(&vdcp->lock);
if (status) {
DMSG(vdcp, 0,
"[%d] Failed waiting for Ver negotiation response, rv(%d)",
vdcp->instance, status);
return (status);
}
/* check type and sub_type ... */
if (vio_msg.tag.vio_msgtype != VIO_TYPE_CTRL ||
vio_msg.tag.vio_subtype == VIO_SUBTYPE_INFO) {
DMSG(vdcp, 0, "[%d] Invalid ver negotiation response\n",
vdcp->instance);
return (EPROTO);
}
return (vdc_handle_ver_msg(vdcp, (vio_ver_msg_t *)&vio_msg));
}
/*
* Function:
* vdc_init_attr_negotiation()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_init_attr_negotiation(vdc_t *vdc)
{
vd_attr_msg_t pkt;
size_t msglen = sizeof (pkt);
int status;
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
DMSG(vdc, 0, "[%d] entered\n", vdc->instance);
/* fill in tag */
pkt.tag.vio_msgtype = VIO_TYPE_CTRL;
pkt.tag.vio_subtype = VIO_SUBTYPE_INFO;
pkt.tag.vio_subtype_env = VIO_ATTR_INFO;
pkt.tag.vio_sid = vdc->session_id;
/* fill in payload */
pkt.max_xfer_sz = vdc->max_xfer_sz;
pkt.vdisk_block_size = vdc->block_size;
pkt.xfer_mode = VIO_DRING_MODE;
pkt.operations = 0; /* server will set bits of valid operations */
pkt.vdisk_type = 0; /* server will set to valid device type */
pkt.vdisk_size = 0; /* server will set to valid size */
status = vdc_send(vdc, (caddr_t)&pkt, &msglen);
DMSG(vdc, 0, "Attr info sent (status = %d)\n", status);
if ((status != 0) || (msglen != sizeof (vio_ver_msg_t))) {
DMSG(vdc, 0, "[%d] Failed to send Attr negotiation info: "
"id(%lx) rv(%d) size(%ld)", vdc->instance, vdc->ldc_handle,
status, msglen);
if (msglen != sizeof (vio_ver_msg_t))
status = ENOMSG;
}
return (status);
}
/*
* Function:
* vdc_attr_negotiation()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_attr_negotiation(vdc_t *vdcp)
{
int status;
vio_msg_t vio_msg;
if (status = vdc_init_attr_negotiation(vdcp))
return (status);
/* release lock and wait for response */
mutex_exit(&vdcp->lock);
status = vdc_wait_for_response(vdcp, &vio_msg);
mutex_enter(&vdcp->lock);
if (status) {
DMSG(vdcp, 0,
"[%d] Failed waiting for Attr negotiation response, rv(%d)",
vdcp->instance, status);
return (status);
}
/* check type and sub_type ... */
if (vio_msg.tag.vio_msgtype != VIO_TYPE_CTRL ||
vio_msg.tag.vio_subtype == VIO_SUBTYPE_INFO) {
DMSG(vdcp, 0, "[%d] Invalid attr negotiation response\n",
vdcp->instance);
return (EPROTO);
}
return (vdc_handle_attr_msg(vdcp, (vd_attr_msg_t *)&vio_msg));
}
/*
* Function:
* vdc_init_dring_negotiate()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_init_dring_negotiate(vdc_t *vdc)
{
vio_dring_reg_msg_t pkt;
size_t msglen = sizeof (pkt);
int status = -1;
int retry;
int nretries = 10;
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
for (retry = 0; retry < nretries; retry++) {
status = vdc_init_descriptor_ring(vdc);
if (status != EAGAIN)
break;
drv_usecwait(vdc_min_timeout_ldc);
}
if (status != 0) {
DMSG(vdc, 0, "[%d] Failed to init DRing (status = %d)\n",
vdc->instance, status);
return (status);
}
DMSG(vdc, 0, "[%d] Init of descriptor ring completed (status = %d)\n",
vdc->instance, status);
/* fill in tag */
pkt.tag.vio_msgtype = VIO_TYPE_CTRL;
pkt.tag.vio_subtype = VIO_SUBTYPE_INFO;
pkt.tag.vio_subtype_env = VIO_DRING_REG;
pkt.tag.vio_sid = vdc->session_id;
/* fill in payload */
pkt.dring_ident = 0;
pkt.num_descriptors = vdc->dring_len;
pkt.descriptor_size = vdc->dring_entry_size;
pkt.options = (VIO_TX_DRING | VIO_RX_DRING);
pkt.ncookies = vdc->dring_cookie_count;
pkt.cookie[0] = vdc->dring_cookie[0]; /* for now just one cookie */
status = vdc_send(vdc, (caddr_t)&pkt, &msglen);
if (status != 0) {
DMSG(vdc, 0, "[%d] Failed to register DRing (err = %d)",
vdc->instance, status);
}
return (status);
}
/*
* Function:
* vdc_dring_negotiation()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_dring_negotiation(vdc_t *vdcp)
{
int status;
vio_msg_t vio_msg;
if (status = vdc_init_dring_negotiate(vdcp))
return (status);
/* release lock and wait for response */
mutex_exit(&vdcp->lock);
status = vdc_wait_for_response(vdcp, &vio_msg);
mutex_enter(&vdcp->lock);
if (status) {
DMSG(vdcp, 0,
"[%d] Failed waiting for Dring negotiation response,"
" rv(%d)", vdcp->instance, status);
return (status);
}
/* check type and sub_type ... */
if (vio_msg.tag.vio_msgtype != VIO_TYPE_CTRL ||
vio_msg.tag.vio_subtype == VIO_SUBTYPE_INFO) {
DMSG(vdcp, 0, "[%d] Invalid Dring negotiation response\n",
vdcp->instance);
return (EPROTO);
}
return (vdc_handle_dring_reg_msg(vdcp,
(vio_dring_reg_msg_t *)&vio_msg));
}
/*
* Function:
* vdc_send_rdx()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_send_rdx(vdc_t *vdcp)
{
vio_msg_t msg;
size_t msglen = sizeof (vio_msg_t);
int status;
/*
* Send an RDX message to vds to indicate we are ready
* to send data
*/
msg.tag.vio_msgtype = VIO_TYPE_CTRL;
msg.tag.vio_subtype = VIO_SUBTYPE_INFO;
msg.tag.vio_subtype_env = VIO_RDX;
msg.tag.vio_sid = vdcp->session_id;
status = vdc_send(vdcp, (caddr_t)&msg, &msglen);
if (status != 0) {
DMSG(vdcp, 0, "[%d] Failed to send RDX message (%d)",
vdcp->instance, status);
}
return (status);
}
/*
* Function:
* vdc_handle_rdx()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* msgp - received msg
*
* Return Code:
* 0 - Success
*/
static int
vdc_handle_rdx(vdc_t *vdcp, vio_rdx_msg_t *msgp)
{
_NOTE(ARGUNUSED(vdcp))
_NOTE(ARGUNUSED(msgp))
ASSERT(msgp->tag.vio_msgtype == VIO_TYPE_CTRL);
ASSERT(msgp->tag.vio_subtype == VIO_SUBTYPE_ACK);
ASSERT(msgp->tag.vio_subtype_env == VIO_RDX);
DMSG(vdcp, 1, "[%d] Got an RDX msg", vdcp->instance);
return (0);
}
/*
* Function:
* vdc_rdx_exchange()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_rdx_exchange(vdc_t *vdcp)
{
int status;
vio_msg_t vio_msg;
if (status = vdc_send_rdx(vdcp))
return (status);
/* release lock and wait for response */
mutex_exit(&vdcp->lock);
status = vdc_wait_for_response(vdcp, &vio_msg);
mutex_enter(&vdcp->lock);
if (status) {
DMSG(vdcp, 0, "[%d] Failed waiting for RDX response, rv(%d)",
vdcp->instance, status);
return (status);
}
/* check type and sub_type ... */
if (vio_msg.tag.vio_msgtype != VIO_TYPE_CTRL ||
vio_msg.tag.vio_subtype != VIO_SUBTYPE_ACK) {
DMSG(vdcp, 0, "[%d] Invalid RDX response\n", vdcp->instance);
return (EPROTO);
}
return (vdc_handle_rdx(vdcp, (vio_rdx_msg_t *)&vio_msg));
}
/* -------------------------------------------------------------------------- */
/*
* LDC helper routines
*/
static int
vdc_recv(vdc_t *vdc, vio_msg_t *msgp, size_t *nbytesp)
{
int status;
boolean_t q_has_pkts = B_FALSE;
int delay_time;
size_t len;
mutex_enter(&vdc->read_lock);
if (vdc->read_state == VDC_READ_IDLE)
vdc->read_state = VDC_READ_WAITING;
while (vdc->read_state != VDC_READ_PENDING) {
/* detect if the connection has been reset */
if (vdc->read_state == VDC_READ_RESET) {
status = ECONNRESET;
goto done;
}
cv_wait(&vdc->read_cv, &vdc->read_lock);
}
/*
* Until we get a blocking ldc read we have to retry
* until the entire LDC message has arrived before
* ldc_read() will succeed. Note we also bail out if
* the channel is reset or goes away.
*/
delay_time = vdc_ldc_read_init_delay;
loop:
len = *nbytesp;
status = ldc_read(vdc->ldc_handle, (caddr_t)msgp, &len);
switch (status) {
case EAGAIN:
delay_time *= 2;
if (delay_time >= vdc_ldc_read_max_delay)
delay_time = vdc_ldc_read_max_delay;
delay(delay_time);
goto loop;
case 0:
if (len == 0) {
DMSG(vdc, 0, "[%d] ldc_read returned 0 bytes with "
"no error!\n", vdc->instance);
goto loop;
}
*nbytesp = len;
/*
* If there are pending messages, leave the
* read state as pending. Otherwise, set the state
* back to idle.
*/
status = ldc_chkq(vdc->ldc_handle, &q_has_pkts);
if (status == 0 && !q_has_pkts)
vdc->read_state = VDC_READ_IDLE;
break;
default:
DMSG(vdc, 0, "ldc_read returned %d\n", status);
break;
}
done:
mutex_exit(&vdc->read_lock);
return (status);
}
#ifdef DEBUG
void
vdc_decode_tag(vdc_t *vdcp, vio_msg_t *msg)
{
char *ms, *ss, *ses;
switch (msg->tag.vio_msgtype) {
#define Q(_s) case _s : ms = #_s; break;
Q(VIO_TYPE_CTRL)
Q(VIO_TYPE_DATA)
Q(VIO_TYPE_ERR)
#undef Q
default: ms = "unknown"; break;
}
switch (msg->tag.vio_subtype) {
#define Q(_s) case _s : ss = #_s; break;
Q(VIO_SUBTYPE_INFO)
Q(VIO_SUBTYPE_ACK)
Q(VIO_SUBTYPE_NACK)
#undef Q
default: ss = "unknown"; break;
}
switch (msg->tag.vio_subtype_env) {
#define Q(_s) case _s : ses = #_s; break;
Q(VIO_VER_INFO)
Q(VIO_ATTR_INFO)
Q(VIO_DRING_REG)
Q(VIO_DRING_UNREG)
Q(VIO_RDX)
Q(VIO_PKT_DATA)
Q(VIO_DESC_DATA)
Q(VIO_DRING_DATA)
#undef Q
default: ses = "unknown"; break;
}
DMSG(vdcp, 3, "(%x/%x/%x) message : (%s/%s/%s)\n",
msg->tag.vio_msgtype, msg->tag.vio_subtype,
msg->tag.vio_subtype_env, ms, ss, ses);
}
#endif
/*
* Function:
* vdc_send()
*
* Description:
* The function encapsulates the call to write a message using LDC.
* If LDC indicates that the call failed due to the queue being full,
* we retry the ldc_write() [ up to 'vdc_retries' time ], otherwise
* we return the error returned by LDC.
*
* Arguments:
* ldc_handle - LDC handle for the channel this instance of vdc uses
* pkt - address of LDC message to be sent
* msglen - the size of the message being sent. When the function
* returns, this contains the number of bytes written.
*
* Return Code:
* 0 - Success.
* EINVAL - pkt or msglen were NULL
* ECONNRESET - The connection was not up.
* EWOULDBLOCK - LDC queue is full
* xxx - other error codes returned by ldc_write
*/
static int
vdc_send(vdc_t *vdc, caddr_t pkt, size_t *msglen)
{
size_t size = 0;
int status = 0;
clock_t delay_ticks;
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
ASSERT(msglen != NULL);
ASSERT(*msglen != 0);
#ifdef DEBUG
vdc_decode_tag(vdc, (vio_msg_t *)pkt);
#endif
/*
* Wait indefinitely to send if channel
* is busy, but bail out if we succeed or
* if the channel closes or is reset.
*/
delay_ticks = vdc_hz_min_ldc_delay;
do {
size = *msglen;
status = ldc_write(vdc->ldc_handle, pkt, &size);
if (status == EWOULDBLOCK) {
delay(delay_ticks);
/* geometric backoff */
delay_ticks *= 2;
if (delay_ticks > vdc_hz_max_ldc_delay)
delay_ticks = vdc_hz_max_ldc_delay;
}
} while (status == EWOULDBLOCK);
/* if LDC had serious issues --- reset vdc state */
if (status == EIO || status == ECONNRESET) {
/* LDC had serious issues --- reset vdc state */
mutex_enter(&vdc->read_lock);
if ((vdc->read_state == VDC_READ_WAITING) ||
(vdc->read_state == VDC_READ_RESET))
cv_signal(&vdc->read_cv);
vdc->read_state = VDC_READ_RESET;
mutex_exit(&vdc->read_lock);
/* wake up any waiters in the reset thread */
if (vdc->state == VDC_STATE_INIT_WAITING) {
DMSG(vdc, 0, "[%d] write reset - "
"vdc is resetting ..\n", vdc->instance);
vdc->state = VDC_STATE_RESETTING;
cv_signal(&vdc->initwait_cv);
}
return (ECONNRESET);
}
/* return the last size written */
*msglen = size;
return (status);
}
/*
* Function:
* vdc_get_ldc_id()
*
* Description:
* This function gets the 'ldc-id' for this particular instance of vdc.
* The id returned is the guest domain channel endpoint LDC uses for
* communication with vds.
*
* Arguments:
* dip - dev info pointer for this instance of the device driver.
* ldc_id - pointer to variable used to return the 'ldc-id' found.
*
* Return Code:
* 0 - Success.
* ENOENT - Expected node or property did not exist.
* ENXIO - Unexpected error communicating with MD framework
*/
static int
vdc_get_ldc_id(dev_info_t *dip, uint64_t *ldc_id)
{
int status = ENOENT;
char *node_name = NULL;
md_t *mdp = NULL;
int num_nodes;
int num_vdevs;
int num_chans;
mde_cookie_t rootnode;
mde_cookie_t *listp = NULL;
mde_cookie_t *chanp = NULL;
boolean_t found_inst = B_FALSE;
int listsz;
int idx;
uint64_t md_inst;
int obp_inst;
int instance = ddi_get_instance(dip);
ASSERT(ldc_id != NULL);
*ldc_id = 0;
/*
* Get the OBP instance number for comparison with the MD instance
*
* The "cfg-handle" property of a vdc node in an MD contains the MD's
* notion of "instance", or unique identifier, for that node; OBP
* stores the value of the "cfg-handle" MD property as the value of
* the "reg" property on the node in the device tree it builds from
* the MD and passes to Solaris. Thus, we look up the devinfo node's
* "reg" property value to uniquely identify this device instance.
* If the "reg" property cannot be found, the device tree state is
* presumably so broken that there is no point in continuing.
*/
if (!ddi_prop_exists(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, OBP_REG)) {
cmn_err(CE_WARN, "'%s' property does not exist", OBP_REG);
return (ENOENT);
}
obp_inst = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
OBP_REG, -1);
DMSGX(1, "[%d] OBP inst=%d\n", instance, obp_inst);
/*
* We now walk the MD nodes and if an instance of a vdc node matches
* the instance got from OBP we get the ldc-id property.
*/
if ((mdp = md_get_handle()) == NULL) {
cmn_err(CE_WARN, "unable to init machine description");
return (ENXIO);
}
num_nodes = md_node_count(mdp);
ASSERT(num_nodes > 0);
listsz = num_nodes * sizeof (mde_cookie_t);
/* allocate memory for nodes */
listp = kmem_zalloc(listsz, KM_SLEEP);
chanp = kmem_zalloc(listsz, KM_SLEEP);
rootnode = md_root_node(mdp);
ASSERT(rootnode != MDE_INVAL_ELEM_COOKIE);
/*
* Search for all the virtual devices, we will then check to see which
* ones are disk nodes.
*/
num_vdevs = md_scan_dag(mdp, rootnode,
md_find_name(mdp, VDC_MD_VDEV_NAME),
md_find_name(mdp, "fwd"), listp);
if (num_vdevs <= 0) {
cmn_err(CE_NOTE, "No '%s' node found", VDC_MD_VDEV_NAME);
status = ENOENT;
goto done;
}
DMSGX(1, "[%d] num_vdevs=%d\n", instance, num_vdevs);
for (idx = 0; idx < num_vdevs; idx++) {
status = md_get_prop_str(mdp, listp[idx], "name", &node_name);
if ((status != 0) || (node_name == NULL)) {
cmn_err(CE_NOTE, "Unable to get name of node type '%s'"
": err %d", VDC_MD_VDEV_NAME, status);
continue;
}
DMSGX(1, "[%d] Found node '%s'\n", instance, node_name);
if (strcmp(VDC_MD_DISK_NAME, node_name) == 0) {
status = md_get_prop_val(mdp, listp[idx],
VDC_MD_CFG_HDL, &md_inst);
DMSGX(1, "[%d] vdc inst in MD=%lx\n",
instance, md_inst);
if ((status == 0) && (md_inst == obp_inst)) {
found_inst = B_TRUE;
break;
}
}
}
if (!found_inst) {
DMSGX(0, "Unable to find correct '%s' node", VDC_MD_DISK_NAME);
status = ENOENT;
goto done;
}
DMSGX(0, "[%d] MD inst=%lx\n", instance, md_inst);
/* get the channels for this node */
num_chans = md_scan_dag(mdp, listp[idx],
md_find_name(mdp, VDC_MD_CHAN_NAME),
md_find_name(mdp, "fwd"), chanp);
/* expecting at least one channel */
if (num_chans <= 0) {
cmn_err(CE_NOTE, "No '%s' node for '%s' port",
VDC_MD_CHAN_NAME, VDC_MD_VDEV_NAME);
status = ENOENT;
goto done;
} else if (num_chans != 1) {
DMSGX(0, "[%d] Expected 1 '%s' node for '%s' port, found %d\n",
instance, VDC_MD_CHAN_NAME, VDC_MD_VDEV_NAME,
num_chans);
}
/*
* We use the first channel found (index 0), irrespective of how
* many are there in total.
*/
if (md_get_prop_val(mdp, chanp[0], VDC_ID_PROP, ldc_id) != 0) {
cmn_err(CE_NOTE, "Channel '%s' property not found",
VDC_ID_PROP);
status = ENOENT;
}
DMSGX(0, "[%d] LDC id is 0x%lx\n", instance, *ldc_id);
done:
if (chanp)
kmem_free(chanp, listsz);
if (listp)
kmem_free(listp, listsz);
(void) md_fini_handle(mdp);
return (status);
}
static int
vdc_do_ldc_up(vdc_t *vdc)
{
int status;
ldc_status_t ldc_state;
DMSG(vdc, 0, "[%d] Bringing up channel %lx\n",
vdc->instance, vdc->ldc_id);
if (vdc->lifecycle == VDC_LC_DETACHING)
return (EINVAL);
if ((status = ldc_up(vdc->ldc_handle)) != 0) {
switch (status) {
case ECONNREFUSED: /* listener not ready at other end */
DMSG(vdc, 0, "[%d] ldc_up(%lx,...) return %d\n",
vdc->instance, vdc->ldc_id, status);
status = 0;
break;
default:
DMSG(vdc, 0, "[%d] Failed to bring up LDC: "
"channel=%ld, err=%d", vdc->instance, vdc->ldc_id,
status);
break;
}
}
if (ldc_status(vdc->ldc_handle, &ldc_state) == 0) {
vdc->ldc_state = ldc_state;
if (ldc_state == LDC_UP) {
DMSG(vdc, 0, "[%d] LDC channel already up\n",
vdc->instance);
vdc->seq_num = 1;
vdc->seq_num_reply = 0;
}
}
return (status);
}
/*
* Function:
* vdc_terminate_ldc()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* None
*/
static void
vdc_terminate_ldc(vdc_t *vdc)
{
int instance = ddi_get_instance(vdc->dip);
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
DMSG(vdc, 0, "[%d] initialized=%x\n", instance, vdc->initialized);
if (vdc->initialized & VDC_LDC_OPEN) {
DMSG(vdc, 0, "[%d] ldc_close()\n", instance);
(void) ldc_close(vdc->ldc_handle);
}
if (vdc->initialized & VDC_LDC_CB) {
DMSG(vdc, 0, "[%d] ldc_unreg_callback()\n", instance);
(void) ldc_unreg_callback(vdc->ldc_handle);
}
if (vdc->initialized & VDC_LDC) {
DMSG(vdc, 0, "[%d] ldc_fini()\n", instance);
(void) ldc_fini(vdc->ldc_handle);
vdc->ldc_handle = NULL;
}
vdc->initialized &= ~(VDC_LDC | VDC_LDC_CB | VDC_LDC_OPEN);
}
/* -------------------------------------------------------------------------- */
/*
* Descriptor Ring helper routines
*/
/*
* Function:
* vdc_init_descriptor_ring()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_init_descriptor_ring(vdc_t *vdc)
{
vd_dring_entry_t *dep = NULL; /* DRing Entry pointer */
int status = 0;
int i;
DMSG(vdc, 0, "[%d] initialized=%x\n", vdc->instance, vdc->initialized);
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
ASSERT(vdc->ldc_handle != NULL);
/* ensure we have enough room to store max sized block */
ASSERT(maxphys <= VD_MAX_BLOCK_SIZE);
if ((vdc->initialized & VDC_DRING_INIT) == 0) {
DMSG(vdc, 0, "[%d] ldc_mem_dring_create\n", vdc->instance);
/*
* Calculate the maximum block size we can transmit using one
* Descriptor Ring entry from the attributes returned by the
* vDisk server. This is subject to a minimum of 'maxphys'
* as we do not have the capability to split requests over
* multiple DRing entries.
*/
if ((vdc->max_xfer_sz * vdc->block_size) < maxphys) {
DMSG(vdc, 0, "[%d] using minimum DRing size\n",
vdc->instance);
vdc->dring_max_cookies = maxphys / PAGESIZE;
} else {
vdc->dring_max_cookies =
(vdc->max_xfer_sz * vdc->block_size) / PAGESIZE;
}
vdc->dring_entry_size = (sizeof (vd_dring_entry_t) +
(sizeof (ldc_mem_cookie_t) *
(vdc->dring_max_cookies - 1)));
vdc->dring_len = VD_DRING_LEN;
status = ldc_mem_dring_create(vdc->dring_len,
vdc->dring_entry_size, &vdc->ldc_dring_hdl);
if ((vdc->ldc_dring_hdl == NULL) || (status != 0)) {
DMSG(vdc, 0, "[%d] Descriptor ring creation failed",
vdc->instance);
return (status);
}
vdc->initialized |= VDC_DRING_INIT;
}
if ((vdc->initialized & VDC_DRING_BOUND) == 0) {
DMSG(vdc, 0, "[%d] ldc_mem_dring_bind\n", vdc->instance);
vdc->dring_cookie =
kmem_zalloc(sizeof (ldc_mem_cookie_t), KM_SLEEP);
status = ldc_mem_dring_bind(vdc->ldc_handle, vdc->ldc_dring_hdl,
LDC_SHADOW_MAP|LDC_DIRECT_MAP, LDC_MEM_RW,
&vdc->dring_cookie[0],
&vdc->dring_cookie_count);
if (status != 0) {
DMSG(vdc, 0, "[%d] Failed to bind descriptor ring "
"(%lx) to channel (%lx) status=%d\n",
vdc->instance, vdc->ldc_dring_hdl,
vdc->ldc_handle, status);
return (status);
}
ASSERT(vdc->dring_cookie_count == 1);
vdc->initialized |= VDC_DRING_BOUND;
}
status = ldc_mem_dring_info(vdc->ldc_dring_hdl, &vdc->dring_mem_info);
if (status != 0) {
DMSG(vdc, 0,
"[%d] Failed to get info for descriptor ring (%lx)\n",
vdc->instance, vdc->ldc_dring_hdl);
return (status);
}
if ((vdc->initialized & VDC_DRING_LOCAL) == 0) {
DMSG(vdc, 0, "[%d] local dring\n", vdc->instance);
/* Allocate the local copy of this dring */
vdc->local_dring =
kmem_zalloc(vdc->dring_len * sizeof (vdc_local_desc_t),
KM_SLEEP);
vdc->initialized |= VDC_DRING_LOCAL;
}
/*
* Mark all DRing entries as free and initialize the private
* descriptor's memory handles. If any entry is initialized,
* we need to free it later so we set the bit in 'initialized'
* at the start.
*/
vdc->initialized |= VDC_DRING_ENTRY;
for (i = 0; i < vdc->dring_len; i++) {
dep = VDC_GET_DRING_ENTRY_PTR(vdc, i);
dep->hdr.dstate = VIO_DESC_FREE;
status = ldc_mem_alloc_handle(vdc->ldc_handle,
&vdc->local_dring[i].desc_mhdl);
if (status != 0) {
DMSG(vdc, 0, "![%d] Failed to alloc mem handle for"
" descriptor %d", vdc->instance, i);
return (status);
}
vdc->local_dring[i].is_free = B_TRUE;
vdc->local_dring[i].dep = dep;
}
/* Initialize the starting index */
vdc->dring_curr_idx = 0;
return (status);
}
/*
* Function:
* vdc_destroy_descriptor_ring()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* None
*/
static void
vdc_destroy_descriptor_ring(vdc_t *vdc)
{
vdc_local_desc_t *ldep = NULL; /* Local Dring Entry Pointer */
ldc_mem_handle_t mhdl = NULL;
ldc_mem_info_t minfo;
int status = -1;
int i; /* loop */
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
DMSG(vdc, 0, "[%d] Entered\n", vdc->instance);
if (vdc->initialized & VDC_DRING_ENTRY) {
DMSG(vdc, 0,
"[%d] Removing Local DRing entries\n", vdc->instance);
for (i = 0; i < vdc->dring_len; i++) {
ldep = &vdc->local_dring[i];
mhdl = ldep->desc_mhdl;
if (mhdl == NULL)
continue;
if ((status = ldc_mem_info(mhdl, &minfo)) != 0) {
DMSG(vdc, 0,
"ldc_mem_info returned an error: %d\n",
status);
/*
* This must mean that the mem handle
* is not valid. Clear it out so that
* no one tries to use it.
*/
ldep->desc_mhdl = NULL;
continue;
}
if (minfo.status == LDC_BOUND) {
(void) ldc_mem_unbind_handle(mhdl);
}
(void) ldc_mem_free_handle(mhdl);
ldep->desc_mhdl = NULL;
}
vdc->initialized &= ~VDC_DRING_ENTRY;
}
if (vdc->initialized & VDC_DRING_LOCAL) {
DMSG(vdc, 0, "[%d] Freeing Local DRing\n", vdc->instance);
kmem_free(vdc->local_dring,
vdc->dring_len * sizeof (vdc_local_desc_t));
vdc->initialized &= ~VDC_DRING_LOCAL;
}
if (vdc->initialized & VDC_DRING_BOUND) {
DMSG(vdc, 0, "[%d] Unbinding DRing\n", vdc->instance);
status = ldc_mem_dring_unbind(vdc->ldc_dring_hdl);
if (status == 0) {
vdc->initialized &= ~VDC_DRING_BOUND;
} else {
DMSG(vdc, 0, "[%d] Error %d unbinding DRing %lx",
vdc->instance, status, vdc->ldc_dring_hdl);
}
kmem_free(vdc->dring_cookie, sizeof (ldc_mem_cookie_t));
}
if (vdc->initialized & VDC_DRING_INIT) {
DMSG(vdc, 0, "[%d] Destroying DRing\n", vdc->instance);
status = ldc_mem_dring_destroy(vdc->ldc_dring_hdl);
if (status == 0) {
vdc->ldc_dring_hdl = NULL;
bzero(&vdc->dring_mem_info, sizeof (ldc_mem_info_t));
vdc->initialized &= ~VDC_DRING_INIT;
} else {
DMSG(vdc, 0, "[%d] Error %d destroying DRing (%lx)",
vdc->instance, status, vdc->ldc_dring_hdl);
}
}
}
/*
* Function:
* vdc_map_to_shared_ring()
*
* Description:
* Copy contents of the local descriptor to the shared
* memory descriptor.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
* idx - descriptor ring index
*
* Return Code:
* None
*/
static int
vdc_map_to_shared_dring(vdc_t *vdcp, int idx)
{
vdc_local_desc_t *ldep;
vd_dring_entry_t *dep;
int rv;
ldep = &(vdcp->local_dring[idx]);
/* for now leave in the old pop_mem_hdl stuff */
if (ldep->nbytes > 0) {
rv = vdc_populate_mem_hdl(vdcp, ldep);
if (rv) {
DMSG(vdcp, 0, "[%d] Cannot populate mem handle\n",
vdcp->instance);
return (rv);
}
}
/*
* fill in the data details into the DRing
*/
dep = ldep->dep;
ASSERT(dep != NULL);
dep->payload.req_id = VDC_GET_NEXT_REQ_ID(vdcp);
dep->payload.operation = ldep->operation;
dep->payload.addr = ldep->offset;
dep->payload.nbytes = ldep->nbytes;
dep->payload.status = (uint32_t)-1; /* vds will set valid value */
dep->payload.slice = ldep->slice;
dep->hdr.dstate = VIO_DESC_READY;
dep->hdr.ack = 1; /* request an ACK for every message */
return (0);
}
/*
* Function:
* vdc_send_request
*
* Description:
* This routine writes the data to be transmitted to vds into the
* descriptor, notifies vds that the ring has been updated and
* then waits for the request to be processed.
*
* Arguments:
* vdcp - the soft state pointer
* operation - operation we want vds to perform (VD_OP_XXX)
* addr - address of data buf to be read/written.
* nbytes - number of bytes to read/write
* slice - the disk slice this request is for
* offset - relative disk offset
* cb_type - type of call - STRATEGY or SYNC
* cb_arg - parameter to be sent to server (depends on VD_OP_XXX type)
* . mode for ioctl(9e)
* . LP64 diskaddr_t (block I/O)
* dir - direction of operation (READ/WRITE/BOTH)
*
* Return Codes:
* 0
* ENXIO
*/
static int
vdc_send_request(vdc_t *vdcp, int operation, caddr_t addr,
size_t nbytes, int slice, diskaddr_t offset, int cb_type,
void *cb_arg, vio_desc_direction_t dir)
{
ASSERT(vdcp != NULL);
ASSERT(slice == VD_SLICE_NONE || slice < V_NUMPAR);
mutex_enter(&vdcp->lock);
do {
while (vdcp->state != VDC_STATE_RUNNING) {
cv_wait(&vdcp->running_cv, &vdcp->lock);
/* return error if detaching */
if (vdcp->state == VDC_STATE_DETACH) {
mutex_exit(&vdcp->lock);
return (ENXIO);
}
}
} while (vdc_populate_descriptor(vdcp, operation, addr,
nbytes, slice, offset, cb_type, cb_arg, dir));
mutex_exit(&vdcp->lock);
return (0);
}
/*
* Function:
* vdc_populate_descriptor
*
* Description:
* This routine writes the data to be transmitted to vds into the
* descriptor, notifies vds that the ring has been updated and
* then waits for the request to be processed.
*
* Arguments:
* vdcp - the soft state pointer
* operation - operation we want vds to perform (VD_OP_XXX)
* addr - address of data buf to be read/written.
* nbytes - number of bytes to read/write
* slice - the disk slice this request is for
* offset - relative disk offset
* cb_type - type of call - STRATEGY or SYNC
* cb_arg - parameter to be sent to server (depends on VD_OP_XXX type)
* . mode for ioctl(9e)
* . LP64 diskaddr_t (block I/O)
* dir - direction of operation (READ/WRITE/BOTH)
*
* Return Codes:
* 0
* EAGAIN
* EFAULT
* ENXIO
* EIO
*/
static int
vdc_populate_descriptor(vdc_t *vdcp, int operation, caddr_t addr,
size_t nbytes, int slice, diskaddr_t offset, int cb_type,
void *cb_arg, vio_desc_direction_t dir)
{
vdc_local_desc_t *local_dep = NULL; /* Local Dring Pointer */
int idx; /* Index of DRing entry used */
int next_idx;
vio_dring_msg_t dmsg;
size_t msglen;
int rv;
ASSERT(MUTEX_HELD(&vdcp->lock));
vdcp->threads_pending++;
loop:
DMSG(vdcp, 2, ": dring_curr_idx = %d\n", vdcp->dring_curr_idx);
/* Get next available D-Ring entry */
idx = vdcp->dring_curr_idx;
local_dep = &(vdcp->local_dring[idx]);
if (!local_dep->is_free) {
DMSG(vdcp, 2, "[%d]: dring full - waiting for space\n",
vdcp->instance);
cv_wait(&vdcp->dring_free_cv, &vdcp->lock);
if (vdcp->state == VDC_STATE_RUNNING ||
vdcp->state == VDC_STATE_HANDLE_PENDING) {
goto loop;
}
vdcp->threads_pending--;
return (ECONNRESET);
}
next_idx = idx + 1;
if (next_idx >= vdcp->dring_len)
next_idx = 0;
vdcp->dring_curr_idx = next_idx;
ASSERT(local_dep->is_free);
local_dep->operation = operation;
local_dep->addr = addr;
local_dep->nbytes = nbytes;
local_dep->slice = slice;
local_dep->offset = offset;
local_dep->cb_type = cb_type;
local_dep->cb_arg = cb_arg;
local_dep->dir = dir;
local_dep->is_free = B_FALSE;
rv = vdc_map_to_shared_dring(vdcp, idx);
if (rv) {
DMSG(vdcp, 0, "[%d]: cannot bind memory - waiting ..\n",
vdcp->instance);
/* free the descriptor */
local_dep->is_free = B_TRUE;
vdcp->dring_curr_idx = idx;
cv_wait(&vdcp->membind_cv, &vdcp->lock);
if (vdcp->state == VDC_STATE_RUNNING ||
vdcp->state == VDC_STATE_HANDLE_PENDING) {
goto loop;
}
vdcp->threads_pending--;
return (ECONNRESET);
}
/*
* Send a msg with the DRing details to vds
*/
VIO_INIT_DRING_DATA_TAG(dmsg);
VDC_INIT_DRING_DATA_MSG_IDS(dmsg, vdcp);
dmsg.dring_ident = vdcp->dring_ident;
dmsg.start_idx = idx;
dmsg.end_idx = idx;
vdcp->seq_num++;
DTRACE_IO2(send, vio_dring_msg_t *, &dmsg, vdc_t *, vdcp);
DMSG(vdcp, 2, "ident=0x%lx, st=%u, end=%u, seq=%ld\n",
vdcp->dring_ident, dmsg.start_idx, dmsg.end_idx, dmsg.seq_num);
/*
* note we're still holding the lock here to
* make sure the message goes out in order !!!...
*/
msglen = sizeof (dmsg);
rv = vdc_send(vdcp, (caddr_t)&dmsg, &msglen);
switch (rv) {
case ECONNRESET:
/*
* vdc_send initiates the reset on failure.
* Since the transaction has already been put
* on the local dring, it will automatically get
* retried when the channel is reset. Given that,
* it is ok to just return success even though the
* send failed.
*/
rv = 0;
break;
case 0: /* EOK */
DMSG(vdcp, 1, "sent via LDC: rv=%d\n", rv);
break;
default:
goto cleanup_and_exit;
}
vdcp->threads_pending--;
return (rv);
cleanup_and_exit:
DMSG(vdcp, 0, "unexpected error, rv=%d\n", rv);
return (ENXIO);
}
/*
* Function:
* vdc_do_sync_op
*
* Description:
* Wrapper around vdc_populate_descriptor that blocks until the
* response to the message is available.
*
* Arguments:
* vdcp - the soft state pointer
* operation - operation we want vds to perform (VD_OP_XXX)
* addr - address of data buf to be read/written.
* nbytes - number of bytes to read/write
* slice - the disk slice this request is for
* offset - relative disk offset
* cb_type - type of call - STRATEGY or SYNC
* cb_arg - parameter to be sent to server (depends on VD_OP_XXX type)
* . mode for ioctl(9e)
* . LP64 diskaddr_t (block I/O)
* dir - direction of operation (READ/WRITE/BOTH)
*
* Return Codes:
* 0
* EAGAIN
* EFAULT
* ENXIO
* EIO
*/
static int
vdc_do_sync_op(vdc_t *vdcp, int operation, caddr_t addr, size_t nbytes,
int slice, diskaddr_t offset, int cb_type, void *cb_arg,
vio_desc_direction_t dir)
{
int status;
ASSERT(cb_type == CB_SYNC);
/*
* Grab the lock, if blocked wait until the server
* response causes us to wake up again.
*/
mutex_enter(&vdcp->lock);
vdcp->sync_op_cnt++;
while (vdcp->sync_op_blocked && vdcp->state != VDC_STATE_DETACH)
cv_wait(&vdcp->sync_blocked_cv, &vdcp->lock);
if (vdcp->state == VDC_STATE_DETACH) {
cv_broadcast(&vdcp->sync_blocked_cv);
vdcp->sync_op_cnt--;
mutex_exit(&vdcp->lock);
return (ENXIO);
}
/* now block anyone other thread entering after us */
vdcp->sync_op_blocked = B_TRUE;
vdcp->sync_op_pending = B_TRUE;
mutex_exit(&vdcp->lock);
/*
* No need to check return value - will return error only
* in the DETACH case and we can fall through
*/
(void) vdc_send_request(vdcp, operation, addr,
nbytes, slice, offset, cb_type, cb_arg, dir);
/*
* block until our transaction completes.
* Also anyone else waiting also gets to go next.
*/
mutex_enter(&vdcp->lock);
while (vdcp->sync_op_pending && vdcp->state != VDC_STATE_DETACH)
cv_wait(&vdcp->sync_pending_cv, &vdcp->lock);
DMSG(vdcp, 2, ": operation returned %d\n", vdcp->sync_op_status);
if (vdcp->state == VDC_STATE_DETACH) {
vdcp->sync_op_pending = B_FALSE;
status = ENXIO;
} else {
status = vdcp->sync_op_status;
}
vdcp->sync_op_status = 0;
vdcp->sync_op_blocked = B_FALSE;
vdcp->sync_op_cnt--;
/* signal the next waiting thread */
cv_signal(&vdcp->sync_blocked_cv);
mutex_exit(&vdcp->lock);
return (status);
}
/*
* Function:
* vdc_drain_response()
*
* Description:
* When a guest is panicking, the completion of requests needs to be
* handled differently because interrupts are disabled and vdc
* will not get messages. We have to poll for the messages instead.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_drain_response(vdc_t *vdc)
{
int rv, idx, retries;
size_t msglen;
vdc_local_desc_t *ldep = NULL; /* Local Dring Entry Pointer */
vio_dring_msg_t dmsg;
mutex_enter(&vdc->lock);
retries = 0;
for (;;) {
msglen = sizeof (dmsg);
rv = ldc_read(vdc->ldc_handle, (caddr_t)&dmsg, &msglen);
if (rv) {
rv = EINVAL;
break;
}
/*
* if there are no packets wait and check again
*/
if ((rv == 0) && (msglen == 0)) {
if (retries++ > vdc_dump_retries) {
rv = EAGAIN;
break;
}
drv_usecwait(vdc_usec_timeout_dump);
continue;
}
/*
* Ignore all messages that are not ACKs/NACKs to
* DRing requests.
*/
if ((dmsg.tag.vio_msgtype != VIO_TYPE_DATA) ||
(dmsg.tag.vio_subtype_env != VIO_DRING_DATA)) {
DMSG(vdc, 0, "discard pkt: type=%d sub=%d env=%d\n",
dmsg.tag.vio_msgtype,
dmsg.tag.vio_subtype,
dmsg.tag.vio_subtype_env);
continue;
}
/*
* set the appropriate return value for the current request.
*/
switch (dmsg.tag.vio_subtype) {
case VIO_SUBTYPE_ACK:
rv = 0;
break;
case VIO_SUBTYPE_NACK:
rv = EAGAIN;
break;
default:
continue;
}
idx = dmsg.start_idx;
if (idx >= vdc->dring_len) {
DMSG(vdc, 0, "[%d] Bogus ack data : start %d\n",
vdc->instance, idx);
continue;
}
ldep = &vdc->local_dring[idx];
if (ldep->dep->hdr.dstate != VIO_DESC_DONE) {
DMSG(vdc, 0, "[%d] Entry @ %d - state !DONE %d\n",
vdc->instance, idx, ldep->dep->hdr.dstate);
continue;
}
DMSG(vdc, 1, "[%d] Depopulating idx=%d state=%d\n",
vdc->instance, idx, ldep->dep->hdr.dstate);
rv = vdc_depopulate_descriptor(vdc, idx);
if (rv) {
DMSG(vdc, 0,
"[%d] Entry @ %d - depopulate failed ..\n",
vdc->instance, idx);
}
/* if this is the last descriptor - break out of loop */
if ((idx + 1) % vdc->dring_len == vdc->dring_curr_idx)
break;
}
mutex_exit(&vdc->lock);
DMSG(vdc, 0, "End idx=%d\n", idx);
return (rv);
}
/*
* Function:
* vdc_depopulate_descriptor()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* idx - Index of the Descriptor Ring entry being modified
*
* Return Code:
* 0 - Success
*/
static int
vdc_depopulate_descriptor(vdc_t *vdc, uint_t idx)
{
vd_dring_entry_t *dep = NULL; /* Dring Entry Pointer */
vdc_local_desc_t *ldep = NULL; /* Local Dring Entry Pointer */
int status = ENXIO;
int rv = 0;
ASSERT(vdc != NULL);
ASSERT(idx < vdc->dring_len);
ldep = &vdc->local_dring[idx];
ASSERT(ldep != NULL);
ASSERT(MUTEX_HELD(&vdc->lock));
DMSG(vdc, 2, ": idx = %d\n", idx);
dep = ldep->dep;
ASSERT(dep != NULL);
ASSERT((dep->hdr.dstate == VIO_DESC_DONE) ||
(dep->payload.status == ECANCELED));
VDC_MARK_DRING_ENTRY_FREE(vdc, idx);
ldep->is_free = B_TRUE;
DMSG(vdc, 2, ": is_free = %d\n", ldep->is_free);
status = dep->payload.status;
/*
* If no buffers were used to transfer information to the server when
* populating the descriptor then no memory handles need to be unbound
* and we can return now.
*/
if (ldep->nbytes == 0) {
cv_signal(&vdc->dring_free_cv);
return (status);
}
/*
* If the upper layer passed in a misaligned address we copied the
* data into an aligned buffer before sending it to LDC - we now
* copy it back to the original buffer.
*/
if (ldep->align_addr) {
ASSERT(ldep->addr != NULL);
if (dep->payload.nbytes > 0)
bcopy(ldep->align_addr, ldep->addr,
dep->payload.nbytes);
kmem_free(ldep->align_addr,
sizeof (caddr_t) * P2ROUNDUP(ldep->nbytes, 8));
ldep->align_addr = NULL;
}
rv = ldc_mem_unbind_handle(ldep->desc_mhdl);
if (rv != 0) {
DMSG(vdc, 0, "?[%d] unbind mhdl 0x%lx @ idx %d failed (%d)",
vdc->instance, ldep->desc_mhdl, idx, rv);
/*
* The error returned by the vDisk server is more informative
* and thus has a higher priority but if it isn't set we ensure
* that this function returns an error.
*/
if (status == 0)
status = EINVAL;
}
cv_signal(&vdc->membind_cv);
cv_signal(&vdc->dring_free_cv);
return (status);
}
/*
* Function:
* vdc_populate_mem_hdl()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* idx - Index of the Descriptor Ring entry being modified
* addr - virtual address being mapped in
* nybtes - number of bytes in 'addr'
* operation - the vDisk operation being performed (VD_OP_xxx)
*
* Return Code:
* 0 - Success
*/
static int
vdc_populate_mem_hdl(vdc_t *vdcp, vdc_local_desc_t *ldep)
{
vd_dring_entry_t *dep = NULL;
ldc_mem_handle_t mhdl;
caddr_t vaddr;
size_t nbytes;
uint8_t perm = LDC_MEM_RW;
uint8_t maptype;
int rv = 0;
int i;
ASSERT(vdcp != NULL);
dep = ldep->dep;
mhdl = ldep->desc_mhdl;
switch (ldep->dir) {
case VIO_read_dir:
perm = LDC_MEM_W;
break;
case VIO_write_dir:
perm = LDC_MEM_R;
break;
case VIO_both_dir:
perm = LDC_MEM_RW;
break;
default:
ASSERT(0); /* catch bad programming in vdc */
}
/*
* LDC expects any addresses passed in to be 8-byte aligned. We need
* to copy the contents of any misaligned buffers to a newly allocated
* buffer and bind it instead (and copy the the contents back to the
* original buffer passed in when depopulating the descriptor)
*/
vaddr = ldep->addr;
nbytes = ldep->nbytes;
if (((uint64_t)vaddr & 0x7) != 0) {
ASSERT(ldep->align_addr == NULL);
ldep->align_addr =
kmem_alloc(sizeof (caddr_t) *
P2ROUNDUP(nbytes, 8), KM_SLEEP);
DMSG(vdcp, 0, "[%d] Misaligned address %p reallocating "
"(buf=%p nb=%ld op=%d)\n",
vdcp->instance, (void *)vaddr, (void *)ldep->align_addr,
nbytes, ldep->operation);
if (perm != LDC_MEM_W)
bcopy(vaddr, ldep->align_addr, nbytes);
vaddr = ldep->align_addr;
}
maptype = LDC_IO_MAP|LDC_SHADOW_MAP|LDC_DIRECT_MAP;
rv = ldc_mem_bind_handle(mhdl, vaddr, P2ROUNDUP(nbytes, 8),
maptype, perm, &dep->payload.cookie[0], &dep->payload.ncookies);
DMSG(vdcp, 2, "[%d] bound mem handle; ncookies=%d\n",
vdcp->instance, dep->payload.ncookies);
if (rv != 0) {
DMSG(vdcp, 0, "[%d] Failed to bind LDC memory handle "
"(mhdl=%p, buf=%p, err=%d)\n",
vdcp->instance, (void *)mhdl, (void *)vaddr, rv);
if (ldep->align_addr) {
kmem_free(ldep->align_addr,
sizeof (caddr_t) * P2ROUNDUP(nbytes, 8));
ldep->align_addr = NULL;
}
return (EAGAIN);
}
/*
* Get the other cookies (if any).
*/
for (i = 1; i < dep->payload.ncookies; i++) {
rv = ldc_mem_nextcookie(mhdl, &dep->payload.cookie[i]);
if (rv != 0) {
(void) ldc_mem_unbind_handle(mhdl);
DMSG(vdcp, 0, "?[%d] Failed to get next cookie "
"(mhdl=%lx cnum=%d), err=%d",
vdcp->instance, mhdl, i, rv);
if (ldep->align_addr) {
kmem_free(ldep->align_addr,
sizeof (caddr_t) * ldep->nbytes);
ldep->align_addr = NULL;
}
return (EAGAIN);
}
}
return (rv);
}
/*
* Interrupt handlers for messages from LDC
*/
/*
* Function:
* vdc_handle_cb()
*
* Description:
*
* Arguments:
* event - Type of event (LDC_EVT_xxx) that triggered the callback
* arg - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static uint_t
vdc_handle_cb(uint64_t event, caddr_t arg)
{
ldc_status_t ldc_state;
int rv = 0;
vdc_t *vdc = (vdc_t *)(void *)arg;
ASSERT(vdc != NULL);
DMSG(vdc, 1, "evt=%lx seqID=%ld\n", event, vdc->seq_num);
/*
* Depending on the type of event that triggered this callback,
* we modify the handshake state or read the data.
*
* NOTE: not done as a switch() as event could be triggered by
* a state change and a read request. Also the ordering of the
* check for the event types is deliberate.
*/
if (event & LDC_EVT_UP) {
DMSG(vdc, 0, "[%d] Received LDC_EVT_UP\n", vdc->instance);
mutex_enter(&vdc->lock);
/* get LDC state */
rv = ldc_status(vdc->ldc_handle, &ldc_state);
if (rv != 0) {
DMSG(vdc, 0, "[%d] Couldn't get LDC status %d",
vdc->instance, rv);
return (LDC_SUCCESS);
}
if (vdc->ldc_state != LDC_UP && ldc_state == LDC_UP) {
/*
* Reset the transaction sequence numbers when
* LDC comes up. We then kick off the handshake
* negotiation with the vDisk server.
*/
vdc->seq_num = 1;
vdc->seq_num_reply = 0;
vdc->ldc_state = ldc_state;
cv_signal(&vdc->initwait_cv);
}
mutex_exit(&vdc->lock);
}
if (event & LDC_EVT_READ) {
DMSG(vdc, 0, "[%d] Received LDC_EVT_READ\n", vdc->instance);
mutex_enter(&vdc->read_lock);
cv_signal(&vdc->read_cv);
vdc->read_state = VDC_READ_PENDING;
mutex_exit(&vdc->read_lock);
/* that's all we have to do - no need to handle DOWN/RESET */
return (LDC_SUCCESS);
}
if (event & (LDC_EVT_RESET|LDC_EVT_DOWN)) {
DMSG(vdc, 0, "[%d] Received LDC RESET event\n", vdc->instance);
mutex_enter(&vdc->lock);
/*
* Need to wake up any readers so they will
* detect that a reset has occurred.
*/
mutex_enter(&vdc->read_lock);
if ((vdc->read_state == VDC_READ_WAITING) ||
(vdc->read_state == VDC_READ_RESET))
cv_signal(&vdc->read_cv);
vdc->read_state = VDC_READ_RESET;
mutex_exit(&vdc->read_lock);
/* wake up any threads waiting for connection to come up */
if (vdc->state == VDC_STATE_INIT_WAITING) {
vdc->state = VDC_STATE_RESETTING;
cv_signal(&vdc->initwait_cv);
}
mutex_exit(&vdc->lock);
}
if (event & ~(LDC_EVT_UP | LDC_EVT_RESET | LDC_EVT_DOWN | LDC_EVT_READ))
DMSG(vdc, 0, "![%d] Unexpected LDC event (%lx) received",
vdc->instance, event);
return (LDC_SUCCESS);
}
/*
* Function:
* vdc_wait_for_response()
*
* Description:
* Block waiting for a response from the server. If there is
* no data the thread block on the read_cv that is signalled
* by the callback when an EVT_READ occurs.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_wait_for_response(vdc_t *vdcp, vio_msg_t *msgp)
{
size_t nbytes = sizeof (*msgp);
int status;
ASSERT(vdcp != NULL);
DMSG(vdcp, 1, "[%d] Entered\n", vdcp->instance);
status = vdc_recv(vdcp, msgp, &nbytes);
DMSG(vdcp, 3, "vdc_read() done.. status=0x%x size=0x%x\n",
status, (int)nbytes);
if (status) {
DMSG(vdcp, 0, "?[%d] Error %d reading LDC msg\n",
vdcp->instance, status);
return (status);
}
if (nbytes < sizeof (vio_msg_tag_t)) {
DMSG(vdcp, 0, "?[%d] Expect %lu bytes; recv'd %lu\n",
vdcp->instance, sizeof (vio_msg_tag_t), nbytes);
return (ENOMSG);
}
DMSG(vdcp, 2, "[%d] (%x/%x/%x)\n", vdcp->instance,
msgp->tag.vio_msgtype,
msgp->tag.vio_subtype,
msgp->tag.vio_subtype_env);
/*
* Verify the Session ID of the message
*
* Every message after the Version has been negotiated should
* have the correct session ID set.
*/
if ((msgp->tag.vio_sid != vdcp->session_id) &&
(msgp->tag.vio_subtype_env != VIO_VER_INFO)) {
DMSG(vdcp, 0, "[%d] Invalid SID: received 0x%x, "
"expected 0x%lx [seq num %lx @ %d]",
vdcp->instance, msgp->tag.vio_sid,
vdcp->session_id,
((vio_dring_msg_t *)msgp)->seq_num,
((vio_dring_msg_t *)msgp)->start_idx);
return (ENOMSG);
}
return (0);
}
/*
* Function:
* vdc_resubmit_backup_dring()
*
* Description:
* Resubmit each descriptor in the backed up dring to
* vDisk server. The Dring was backed up during connection
* reset.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_resubmit_backup_dring(vdc_t *vdcp)
{
int count;
int b_idx;
int rv;
int dring_size;
int status;
vio_msg_t vio_msg;
vdc_local_desc_t *curr_ldep;
ASSERT(MUTEX_NOT_HELD(&vdcp->lock));
ASSERT(vdcp->state == VDC_STATE_HANDLE_PENDING);
DMSG(vdcp, 1, "restoring pending dring entries (len=%d, tail=%d)\n",
vdcp->local_dring_backup_len, vdcp->local_dring_backup_tail);
/*
* Walk the backup copy of the local descriptor ring and
* resubmit all the outstanding transactions.
*/
b_idx = vdcp->local_dring_backup_tail;
for (count = 0; count < vdcp->local_dring_backup_len; count++) {
curr_ldep = &(vdcp->local_dring_backup[b_idx]);
/* only resubmit outstanding transactions */
if (!curr_ldep->is_free) {
DMSG(vdcp, 1, "resubmitting entry idx=%x\n", b_idx);
mutex_enter(&vdcp->lock);
rv = vdc_populate_descriptor(vdcp, curr_ldep->operation,
curr_ldep->addr, curr_ldep->nbytes,
curr_ldep->slice, curr_ldep->offset,
curr_ldep->cb_type, curr_ldep->cb_arg,
curr_ldep->dir);
mutex_exit(&vdcp->lock);
if (rv) {
DMSG(vdcp, 1, "[%d] cannot resubmit entry %d\n",
vdcp->instance, b_idx);
return (rv);
}
/* Wait for the response message. */
DMSG(vdcp, 1, "waiting for response to idx=%x\n",
b_idx);
status = vdc_wait_for_response(vdcp, &vio_msg);
if (status) {
DMSG(vdcp, 1, "[%d] wait_for_response "
"returned err=%d\n", vdcp->instance,
status);
return (status);
}
DMSG(vdcp, 1, "processing msg for idx=%x\n", b_idx);
status = vdc_process_data_msg(vdcp, &vio_msg);
if (status) {
DMSG(vdcp, 1, "[%d] process_data_msg "
"returned err=%d\n", vdcp->instance,
status);
return (status);
}
}
/* get the next element to submit */
if (++b_idx >= vdcp->local_dring_backup_len)
b_idx = 0;
}
/* all done - now clear up pending dring copy */
dring_size = vdcp->local_dring_backup_len *
sizeof (vdcp->local_dring_backup[0]);
(void) kmem_free(vdcp->local_dring_backup, dring_size);
vdcp->local_dring_backup = NULL;
return (0);
}
/*
* Function:
* vdc_backup_local_dring()
*
* Description:
* Backup the current dring in the event of a reset. The Dring
* transactions will be resubmitted to the server when the
* connection is restored.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* NONE
*/
static void
vdc_backup_local_dring(vdc_t *vdcp)
{
int dring_size;
ASSERT(vdcp->state == VDC_STATE_RESETTING);
/*
* If the backup dring is stil around, it means
* that the last restore did not complete. However,
* since we never got back into the running state,
* the backup copy we have is still valid.
*/
if (vdcp->local_dring_backup != NULL) {
DMSG(vdcp, 1, "reusing local descriptor ring backup "
"(len=%d, tail=%d)\n", vdcp->local_dring_backup_len,
vdcp->local_dring_backup_tail);
return;
}
DMSG(vdcp, 1, "backing up the local descriptor ring (len=%d, "
"tail=%d)\n", vdcp->dring_len, vdcp->dring_curr_idx);
dring_size = vdcp->dring_len * sizeof (vdcp->local_dring[0]);
vdcp->local_dring_backup = kmem_alloc(dring_size, KM_SLEEP);
bcopy(vdcp->local_dring, vdcp->local_dring_backup, dring_size);
vdcp->local_dring_backup_tail = vdcp->dring_curr_idx;
vdcp->local_dring_backup_len = vdcp->dring_len;
}
/* -------------------------------------------------------------------------- */
/*
* The following functions process the incoming messages from vds
*/
/*
* Function:
* vdc_process_msg_thread()
*
* Description:
*
* Main VDC message processing thread. Each vDisk instance
* consists of a copy of this thread. This thread triggers
* all the handshakes and data exchange with the server. It
* also handles all channel resets
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* None
*/
static void
vdc_process_msg_thread(vdc_t *vdcp)
{
int status;
mutex_enter(&vdcp->lock);
for (;;) {
#define Q(_s) (vdcp->state == _s) ? #_s :
DMSG(vdcp, 3, "state = %d (%s)\n", vdcp->state,
Q(VDC_STATE_INIT)
Q(VDC_STATE_INIT_WAITING)
Q(VDC_STATE_NEGOTIATE)
Q(VDC_STATE_HANDLE_PENDING)
Q(VDC_STATE_RUNNING)
Q(VDC_STATE_RESETTING)
Q(VDC_STATE_DETACH)
"UNKNOWN");
switch (vdcp->state) {
case VDC_STATE_INIT:
/* Check if have re-initializing repeatedly */
if (vdcp->hshake_cnt++ > vdc_hshake_retries) {
cmn_err(CE_NOTE, "[%d] disk access failed.\n",
vdcp->instance);
vdcp->state = VDC_STATE_DETACH;
break;
}
/* Bring up connection with vds via LDC */
status = vdc_start_ldc_connection(vdcp);
switch (status) {
case EINVAL:
DMSG(vdcp, 0, "[%d] Could not start LDC",
vdcp->instance);
vdcp->state = VDC_STATE_DETACH;
break;
case 0:
vdcp->state = VDC_STATE_INIT_WAITING;
break;
default:
vdcp->state = VDC_STATE_INIT_WAITING;
break;
}
break;
case VDC_STATE_INIT_WAITING:
/*
* Let the callback event move us on
* when channel is open to server
*/
while (vdcp->ldc_state != LDC_UP) {
cv_wait(&vdcp->initwait_cv, &vdcp->lock);
if (vdcp->state != VDC_STATE_INIT_WAITING) {
DMSG(vdcp, 0,
"state moved to %d out from under us...\n",
vdcp->state);
break;
}
}
if (vdcp->state == VDC_STATE_INIT_WAITING &&
vdcp->ldc_state == LDC_UP) {
vdcp->state = VDC_STATE_NEGOTIATE;
}
break;
case VDC_STATE_NEGOTIATE:
switch (status = vdc_ver_negotiation(vdcp)) {
case 0:
break;
default:
DMSG(vdcp, 0, "ver negotiate failed (%d)..\n",
status);
goto reset;
}
switch (status = vdc_attr_negotiation(vdcp)) {
case 0:
break;
default:
DMSG(vdcp, 0, "attr negotiate failed (%d)..\n",
status);
goto reset;
}
switch (status = vdc_dring_negotiation(vdcp)) {
case 0:
break;
default:
DMSG(vdcp, 0, "dring negotiate failed (%d)..\n",
status);
goto reset;
}
switch (status = vdc_rdx_exchange(vdcp)) {
case 0:
vdcp->state = VDC_STATE_HANDLE_PENDING;
goto done;
default:
DMSG(vdcp, 0, "RDX xchg failed ..(%d)\n",
status);
goto reset;
}
reset:
DMSG(vdcp, 0, "negotiation failed: resetting (%d)\n",
status);
vdcp->state = VDC_STATE_RESETTING;
done:
DMSG(vdcp, 0, "negotiation complete (state=0x%x)...\n",
vdcp->state);
break;
case VDC_STATE_HANDLE_PENDING:
mutex_exit(&vdcp->lock);
status = vdc_resubmit_backup_dring(vdcp);
mutex_enter(&vdcp->lock);
if (status)
vdcp->state = VDC_STATE_RESETTING;
else
vdcp->state = VDC_STATE_RUNNING;
break;
/* enter running state */
case VDC_STATE_RUNNING:
/*
* Signal anyone waiting for the connection
* to come on line.
*/
vdcp->hshake_cnt = 0;
cv_broadcast(&vdcp->running_cv);
mutex_exit(&vdcp->lock);
for (;;) {
vio_msg_t msg;
status = vdc_wait_for_response(vdcp, &msg);
if (status) break;
DMSG(vdcp, 1, "[%d] new pkt(s) available\n",
vdcp->instance);
status = vdc_process_data_msg(vdcp, &msg);
if (status) {
DMSG(vdcp, 1, "[%d] process_data_msg "
"returned err=%d\n", vdcp->instance,
status);
break;
}
}
mutex_enter(&vdcp->lock);
vdcp->state = VDC_STATE_RESETTING;
vdcp->self_reset = B_TRUE;
break;
case VDC_STATE_RESETTING:
DMSG(vdcp, 0, "Initiating channel reset "
"(pending = %d)\n", (int)vdcp->threads_pending);
if (vdcp->self_reset) {
DMSG(vdcp, 0,
"[%d] calling stop_ldc_connection.\n",
vdcp->instance);
status = vdc_stop_ldc_connection(vdcp);
vdcp->self_reset = B_FALSE;
}
/*
* Wait for all threads currently waiting
* for a free dring entry to use.
*/
while (vdcp->threads_pending) {
cv_broadcast(&vdcp->membind_cv);
cv_broadcast(&vdcp->dring_free_cv);
mutex_exit(&vdcp->lock);
/* let them wake up */
drv_usecwait(vdc_min_timeout_ldc);
mutex_enter(&vdcp->lock);
}
ASSERT(vdcp->threads_pending == 0);
/* Sanity check that no thread is receiving */
ASSERT(vdcp->read_state != VDC_READ_WAITING);
vdcp->read_state = VDC_READ_IDLE;
vdc_backup_local_dring(vdcp);
/* cleanup the old d-ring */
vdc_destroy_descriptor_ring(vdcp);
/* go and start again */
vdcp->state = VDC_STATE_INIT;
break;
case VDC_STATE_DETACH:
DMSG(vdcp, 0, "[%d] Reset thread exit cleanup ..\n",
vdcp->instance);
/*
* Signal anyone waiting for connection
* to come online
*/
cv_broadcast(&vdcp->running_cv);
while (vdcp->sync_op_pending) {
cv_signal(&vdcp->sync_pending_cv);
cv_signal(&vdcp->sync_blocked_cv);
mutex_exit(&vdcp->lock);
drv_usecwait(vdc_min_timeout_ldc);
mutex_enter(&vdcp->lock);
}
mutex_exit(&vdcp->lock);
DMSG(vdcp, 0, "[%d] Msg processing thread exiting ..\n",
vdcp->instance);
thread_exit();
break;
}
}
}
/*
* Function:
* vdc_process_data_msg()
*
* Description:
* This function is called by the message processing thread each time
* a message with a msgtype of VIO_TYPE_DATA is received. It will either
* be an ACK or NACK from vds[1] which vdc handles as follows.
* ACK - wake up the waiting thread
* NACK - resend any messages necessary
*
* [1] Although the message format allows it, vds should not send a
* VIO_SUBTYPE_INFO message to vdc asking it to read data; if for
* some bizarre reason it does, vdc will reset the connection.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* msg - the LDC message sent by vds
*
* Return Code:
* 0 - Success.
* > 0 - error value returned by LDC
*/
static int
vdc_process_data_msg(vdc_t *vdcp, vio_msg_t *msg)
{
int status = 0;
vio_dring_msg_t *dring_msg;
vdc_local_desc_t *ldep = NULL;
int start, end;
int idx;
dring_msg = (vio_dring_msg_t *)msg;
ASSERT(msg->tag.vio_msgtype == VIO_TYPE_DATA);
ASSERT(vdcp != NULL);
mutex_enter(&vdcp->lock);
/*
* Check to see if the message has bogus data
*/
idx = start = dring_msg->start_idx;
end = dring_msg->end_idx;
if ((start >= vdcp->dring_len) ||
(end >= vdcp->dring_len) || (end < -1)) {
DMSG(vdcp, 0, "[%d] Bogus ACK data : start %d, end %d\n",
vdcp->instance, start, end);
mutex_exit(&vdcp->lock);
return (EINVAL);
}
/*
* Verify that the sequence number is what vdc expects.
*/
switch (vdc_verify_seq_num(vdcp, dring_msg)) {
case VDC_SEQ_NUM_TODO:
break; /* keep processing this message */
case VDC_SEQ_NUM_SKIP:
mutex_exit(&vdcp->lock);
return (0);
case VDC_SEQ_NUM_INVALID:
mutex_exit(&vdcp->lock);
DMSG(vdcp, 0, "[%d] invalid seqno\n", vdcp->instance);
return (ENXIO);
}
if (msg->tag.vio_subtype == VIO_SUBTYPE_NACK) {
DMSG(vdcp, 0, "[%d] DATA NACK\n", vdcp->instance);
VDC_DUMP_DRING_MSG(dring_msg);
mutex_exit(&vdcp->lock);
return (EIO);
} else if (msg->tag.vio_subtype == VIO_SUBTYPE_INFO) {
mutex_exit(&vdcp->lock);
return (EPROTO);
}
DTRACE_IO2(recv, vio_dring_msg_t, dring_msg, vdc_t *, vdcp);
DMSG(vdcp, 1, ": start %d end %d\n", start, end);
ASSERT(start == end);
ldep = &vdcp->local_dring[idx];
DMSG(vdcp, 1, ": state 0x%x - cb_type 0x%x\n",
ldep->dep->hdr.dstate, ldep->cb_type);
if (ldep->dep->hdr.dstate == VIO_DESC_DONE) {
struct buf *bufp;
switch (ldep->cb_type) {
case CB_SYNC:
ASSERT(vdcp->sync_op_pending);
status = vdc_depopulate_descriptor(vdcp, idx);
vdcp->sync_op_status = status;
vdcp->sync_op_pending = B_FALSE;
cv_signal(&vdcp->sync_pending_cv);
break;
case CB_STRATEGY:
bufp = ldep->cb_arg;
ASSERT(bufp != NULL);
bufp->b_resid =
bufp->b_bcount - ldep->dep->payload.nbytes;
status = ldep->dep->payload.status; /* Future:ntoh */
if (status != 0) {
DMSG(vdcp, 1, "strategy status=%d\n", status);
bioerror(bufp, status);
}
status = vdc_depopulate_descriptor(vdcp, idx);
biodone(bufp);
DMSG(vdcp, 1,
"strategy complete req=%ld bytes resp=%ld bytes\n",
bufp->b_bcount, ldep->dep->payload.nbytes);
break;
default:
ASSERT(0);
}
}
/* let the arrival signal propogate */
mutex_exit(&vdcp->lock);
/* probe gives the count of how many entries were processed */
DTRACE_IO2(processed, int, 1, vdc_t *, vdcp);
return (0);
}
/*
* Function:
* vdc_process_err_msg()
*
* NOTE: No error messages are used as part of the vDisk protocol
*/
static int
vdc_process_err_msg(vdc_t *vdc, vio_msg_t msg)
{
_NOTE(ARGUNUSED(vdc))
_NOTE(ARGUNUSED(msg))
ASSERT(msg.tag.vio_msgtype == VIO_TYPE_ERR);
DMSG(vdc, 1, "[%d] Got an ERR msg", vdc->instance);
return (ENOTSUP);
}
/*
* Function:
* vdc_handle_ver_msg()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* ver_msg - LDC message sent by vDisk server
*
* Return Code:
* 0 - Success
*/
static int
vdc_handle_ver_msg(vdc_t *vdc, vio_ver_msg_t *ver_msg)
{
int status = 0;
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
if (ver_msg->tag.vio_subtype_env != VIO_VER_INFO) {
return (EPROTO);
}
if (ver_msg->dev_class != VDEV_DISK_SERVER) {
return (EINVAL);
}
switch (ver_msg->tag.vio_subtype) {
case VIO_SUBTYPE_ACK:
/*
* We check to see if the version returned is indeed supported
* (The server may have also adjusted the minor number downwards
* and if so 'ver_msg' will contain the actual version agreed)
*/
if (vdc_is_supported_version(ver_msg)) {
vdc->ver.major = ver_msg->ver_major;
vdc->ver.minor = ver_msg->ver_minor;
ASSERT(vdc->ver.major > 0);
} else {
status = EPROTO;
}
break;
case VIO_SUBTYPE_NACK:
/*
* call vdc_is_supported_version() which will return the next
* supported version (if any) in 'ver_msg'
*/
(void) vdc_is_supported_version(ver_msg);
if (ver_msg->ver_major > 0) {
size_t len = sizeof (*ver_msg);
ASSERT(vdc->ver.major > 0);
/* reset the necessary fields and resend */
ver_msg->tag.vio_subtype = VIO_SUBTYPE_INFO;
ver_msg->dev_class = VDEV_DISK;
status = vdc_send(vdc, (caddr_t)ver_msg, &len);
DMSG(vdc, 0, "[%d] Resend VER info (LDC status = %d)\n",
vdc->instance, status);
if (len != sizeof (*ver_msg))
status = EBADMSG;
} else {
DMSG(vdc, 0, "[%d] No common version with vDisk server",
vdc->instance);
status = ENOTSUP;
}
break;
case VIO_SUBTYPE_INFO:
/*
* Handle the case where vds starts handshake
* (for now only vdc is the instigator)
*/
status = ENOTSUP;
break;
default:
status = EINVAL;
break;
}
return (status);
}
/*
* Function:
* vdc_handle_attr_msg()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* attr_msg - LDC message sent by vDisk server
*
* Return Code:
* 0 - Success
*/
static int
vdc_handle_attr_msg(vdc_t *vdc, vd_attr_msg_t *attr_msg)
{
int status = 0;
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
if (attr_msg->tag.vio_subtype_env != VIO_ATTR_INFO) {
return (EPROTO);
}
switch (attr_msg->tag.vio_subtype) {
case VIO_SUBTYPE_ACK:
/*
* We now verify the attributes sent by vds.
*/
vdc->vdisk_size = attr_msg->vdisk_size;
vdc->vdisk_type = attr_msg->vdisk_type;
DMSG(vdc, 0, "[%d] max_xfer_sz: sent %lx acked %lx\n",
vdc->instance, vdc->max_xfer_sz, attr_msg->max_xfer_sz);
DMSG(vdc, 0, "[%d] vdisk_block_size: sent %lx acked %x\n",
vdc->instance, vdc->block_size,
attr_msg->vdisk_block_size);
/*
* We don't know at compile time what the vDisk server will
* think are good values but we apply an large (arbitrary)
* upper bound to prevent memory exhaustion in vdc if it was
* allocating a DRing based of huge values sent by the server.
* We probably will never exceed this except if the message
* was garbage.
*/
if ((attr_msg->max_xfer_sz * attr_msg->vdisk_block_size) <=
(PAGESIZE * DEV_BSIZE)) {
vdc->max_xfer_sz = attr_msg->max_xfer_sz;
vdc->block_size = attr_msg->vdisk_block_size;
} else {
DMSG(vdc, 0, "[%d] vds block transfer size too big;"
" using max supported by vdc", vdc->instance);
}
if ((attr_msg->xfer_mode != VIO_DRING_MODE) ||
(attr_msg->vdisk_size > INT64_MAX) ||
(attr_msg->vdisk_type > VD_DISK_TYPE_DISK)) {
DMSG(vdc, 0, "[%d] Invalid attributes from vds",
vdc->instance);
status = EINVAL;
break;
}
break;
case VIO_SUBTYPE_NACK:
/*
* vds could not handle the attributes we sent so we
* stop negotiating.
*/
status = EPROTO;
break;
case VIO_SUBTYPE_INFO:
/*
* Handle the case where vds starts the handshake
* (for now; vdc is the only supported instigatior)
*/
status = ENOTSUP;
break;
default:
status = ENOTSUP;
break;
}
return (status);
}
/*
* Function:
* vdc_handle_dring_reg_msg()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the driver.
* dring_msg - LDC message sent by vDisk server
*
* Return Code:
* 0 - Success
*/
static int
vdc_handle_dring_reg_msg(vdc_t *vdc, vio_dring_reg_msg_t *dring_msg)
{
int status = 0;
ASSERT(vdc != NULL);
ASSERT(mutex_owned(&vdc->lock));
if (dring_msg->tag.vio_subtype_env != VIO_DRING_REG) {
return (EPROTO);
}
switch (dring_msg->tag.vio_subtype) {
case VIO_SUBTYPE_ACK:
/* save the received dring_ident */
vdc->dring_ident = dring_msg->dring_ident;
DMSG(vdc, 0, "[%d] Received dring ident=0x%lx\n",
vdc->instance, vdc->dring_ident);
break;
case VIO_SUBTYPE_NACK:
/*
* vds could not handle the DRing info we sent so we
* stop negotiating.
*/
DMSG(vdc, 0, "[%d] server could not register DRing\n",
vdc->instance);
status = EPROTO;
break;
case VIO_SUBTYPE_INFO:
/*
* Handle the case where vds starts handshake
* (for now only vdc is the instigatior)
*/
status = ENOTSUP;
break;
default:
status = ENOTSUP;
}
return (status);
}
/*
* Function:
* vdc_verify_seq_num()
*
* Description:
* This functions verifies that the sequence number sent back by the vDisk
* server with the latest message is what is expected (i.e. it is greater
* than the last seq num sent by the vDisk server and less than or equal
* to the last seq num generated by vdc).
*
* It then checks the request ID to see if any requests need processing
* in the DRing.
*
* Arguments:
* vdc - soft state pointer for this instance of the driver.
* dring_msg - pointer to the LDC message sent by vds
*
* Return Code:
* VDC_SEQ_NUM_TODO - Message needs to be processed
* VDC_SEQ_NUM_SKIP - Message has already been processed
* VDC_SEQ_NUM_INVALID - The seq numbers are so out of sync,
* vdc cannot deal with them
*/
static int
vdc_verify_seq_num(vdc_t *vdc, vio_dring_msg_t *dring_msg)
{
ASSERT(vdc != NULL);
ASSERT(dring_msg != NULL);
ASSERT(mutex_owned(&vdc->lock));
/*
* Check to see if the messages were responded to in the correct
* order by vds.
*/
if ((dring_msg->seq_num <= vdc->seq_num_reply) ||
(dring_msg->seq_num > vdc->seq_num)) {
DMSG(vdc, 0, "?[%d] Bogus sequence_number %lu: "
"%lu > expected <= %lu (last proc req %lu sent %lu)\n",
vdc->instance, dring_msg->seq_num,
vdc->seq_num_reply, vdc->seq_num,
vdc->req_id_proc, vdc->req_id);
return (VDC_SEQ_NUM_INVALID);
}
vdc->seq_num_reply = dring_msg->seq_num;
if (vdc->req_id_proc < vdc->req_id)
return (VDC_SEQ_NUM_TODO);
else
return (VDC_SEQ_NUM_SKIP);
}
/*
* Function:
* vdc_is_supported_version()
*
* Description:
* This routine checks if the major/minor version numbers specified in
* 'ver_msg' are supported. If not it finds the next version that is
* in the supported version list 'vdc_version[]' and sets the fields in
* 'ver_msg' to those values
*
* Arguments:
* ver_msg - LDC message sent by vDisk server
*
* Return Code:
* B_TRUE - Success
* B_FALSE - Version not supported
*/
static boolean_t
vdc_is_supported_version(vio_ver_msg_t *ver_msg)
{
int vdc_num_versions = sizeof (vdc_version) / sizeof (vdc_version[0]);
for (int i = 0; i < vdc_num_versions; i++) {
ASSERT(vdc_version[i].major > 0);
ASSERT((i == 0) ||
(vdc_version[i].major < vdc_version[i-1].major));
/*
* If the major versions match, adjust the minor version, if
* necessary, down to the highest value supported by this
* client. The server should support all minor versions lower
* than the value it sent
*/
if (ver_msg->ver_major == vdc_version[i].major) {
if (ver_msg->ver_minor > vdc_version[i].minor) {
DMSGX(0,
"Adjusting minor version from %u to %u",
ver_msg->ver_minor, vdc_version[i].minor);
ver_msg->ver_minor = vdc_version[i].minor;
}
return (B_TRUE);
}
/*
* If the message contains a higher major version number, set
* the message's major/minor versions to the current values
* and return false, so this message will get resent with
* these values, and the server will potentially try again
* with the same or a lower version
*/
if (ver_msg->ver_major > vdc_version[i].major) {
ver_msg->ver_major = vdc_version[i].major;
ver_msg->ver_minor = vdc_version[i].minor;
DMSGX(0, "Suggesting major/minor (0x%x/0x%x)\n",
ver_msg->ver_major, ver_msg->ver_minor);
return (B_FALSE);
}
/*
* Otherwise, the message's major version is less than the
* current major version, so continue the loop to the next
* (lower) supported version
*/
}
/*
* No common version was found; "ground" the version pair in the
* message to terminate negotiation
*/
ver_msg->ver_major = 0;
ver_msg->ver_minor = 0;
return (B_FALSE);
}
/* -------------------------------------------------------------------------- */
/*
* DKIO(7) support
*/
typedef struct vdc_dk_arg {
struct dk_callback dkc;
int mode;
dev_t dev;
vdc_t *vdc;
} vdc_dk_arg_t;
/*
* Function:
* vdc_dkio_flush_cb()
*
* Description:
* This routine is a callback for DKIOCFLUSHWRITECACHE which can be called
* by kernel code.
*
* Arguments:
* arg - a pointer to a vdc_dk_arg_t structure.
*/
void
vdc_dkio_flush_cb(void *arg)
{
struct vdc_dk_arg *dk_arg = (struct vdc_dk_arg *)arg;
struct dk_callback *dkc = NULL;
vdc_t *vdc = NULL;
int rv;
if (dk_arg == NULL) {
cmn_err(CE_NOTE, "?[Unk] DKIOCFLUSHWRITECACHE arg is NULL\n");
return;
}
dkc = &dk_arg->dkc;
vdc = dk_arg->vdc;
ASSERT(vdc != NULL);
rv = vdc_do_sync_op(vdc, VD_OP_FLUSH, NULL, 0,
VDCPART(dk_arg->dev), 0, CB_SYNC, 0, VIO_both_dir);
if (rv != 0) {
DMSG(vdc, 0, "[%d] DKIOCFLUSHWRITECACHE failed %d : model %x\n",
vdc->instance, rv,
ddi_model_convert_from(dk_arg->mode & FMODELS));
}
/*
* Trigger the call back to notify the caller the the ioctl call has
* been completed.
*/
if ((dk_arg->mode & FKIOCTL) &&
(dkc != NULL) &&
(dkc->dkc_callback != NULL)) {
ASSERT(dkc->dkc_cookie != NULL);
(*dkc->dkc_callback)(dkc->dkc_cookie, rv);
}
/* Indicate that one less DKIO write flush is outstanding */
mutex_enter(&vdc->lock);
vdc->dkio_flush_pending--;
ASSERT(vdc->dkio_flush_pending >= 0);
mutex_exit(&vdc->lock);
/* free the mem that was allocated when the callback was dispatched */
kmem_free(arg, sizeof (vdc_dk_arg_t));
}
/*
* Function:
* vdc_dkio_get_partition()
*
* Description:
* This function implements the DKIOCGAPART ioctl.
*
* Arguments:
* dev - device
* arg - a pointer to a dk_map[NDKMAP] or dk_map32[NDKMAP] structure
* flag - ioctl flags
*/
static int
vdc_dkio_get_partition(dev_t dev, caddr_t arg, int flag)
{
struct dk_geom geom;
struct vtoc vtoc;
union {
struct dk_map map[NDKMAP];
struct dk_map32 map32[NDKMAP];
} data;
int i, rv, size;
rv = vd_process_ioctl(dev, DKIOCGGEOM, (caddr_t)&geom, FKIOCTL);
if (rv != 0)
return (rv);
rv = vd_process_ioctl(dev, DKIOCGVTOC, (caddr_t)&vtoc, FKIOCTL);
if (rv != 0)
return (rv);
if (vtoc.v_nparts != NDKMAP ||
geom.dkg_nhead == 0 || geom.dkg_nsect == 0)
return (EINVAL);
if (ddi_model_convert_from(flag & FMODELS) == DDI_MODEL_ILP32) {
for (i = 0; i < NDKMAP; i++) {
data.map32[i].dkl_cylno = vtoc.v_part[i].p_start /
(geom.dkg_nhead * geom.dkg_nsect);
data.map32[i].dkl_nblk = vtoc.v_part[i].p_size;
}
size = NDKMAP * sizeof (struct dk_map32);
} else {
for (i = 0; i < NDKMAP; i++) {
data.map[i].dkl_cylno = vtoc.v_part[i].p_start /
(geom.dkg_nhead * geom.dkg_nsect);
data.map[i].dkl_nblk = vtoc.v_part[i].p_size;
}
size = NDKMAP * sizeof (struct dk_map);
}
if (ddi_copyout(&data, arg, size, flag) != 0)
return (EFAULT);
return (0);
}
/*
* Function:
* vdc_dioctl_rwcmd()
*
* Description:
* This function implements the DIOCTL_RWCMD ioctl. This ioctl is used
* for DKC_DIRECT disks to read or write at an absolute disk offset.
*
* Arguments:
* dev - device
* arg - a pointer to a dadkio_rwcmd or dadkio_rwcmd32 structure
* flag - ioctl flags
*/
static int
vdc_dioctl_rwcmd(dev_t dev, caddr_t arg, int flag)
{
struct dadkio_rwcmd32 rwcmd32;
struct dadkio_rwcmd rwcmd;
struct iovec aiov;
struct uio auio;
int rw, status;
struct buf *buf;
if (ddi_model_convert_from(flag & FMODELS) == DDI_MODEL_ILP32) {
if (ddi_copyin((caddr_t)arg, (caddr_t)&rwcmd32,
sizeof (struct dadkio_rwcmd32), flag)) {
return (EFAULT);
}
rwcmd.cmd = rwcmd32.cmd;
rwcmd.flags = rwcmd32.flags;
rwcmd.blkaddr = (daddr_t)rwcmd32.blkaddr;
rwcmd.buflen = rwcmd32.buflen;
rwcmd.bufaddr = (caddr_t)(uintptr_t)rwcmd32.bufaddr;
} else {
if (ddi_copyin((caddr_t)arg, (caddr_t)&rwcmd,
sizeof (struct dadkio_rwcmd), flag)) {
return (EFAULT);
}
}
switch (rwcmd.cmd) {
case DADKIO_RWCMD_READ:
rw = B_READ;
break;
case DADKIO_RWCMD_WRITE:
rw = B_WRITE;
break;
default:
return (EINVAL);
}
bzero((caddr_t)&aiov, sizeof (struct iovec));
aiov.iov_base = rwcmd.bufaddr;
aiov.iov_len = rwcmd.buflen;
bzero((caddr_t)&auio, sizeof (struct uio));
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_loffset = rwcmd.blkaddr * DEV_BSIZE;
auio.uio_resid = rwcmd.buflen;
auio.uio_segflg = flag & FKIOCTL ? UIO_SYSSPACE : UIO_USERSPACE;
buf = kmem_alloc(sizeof (buf_t), KM_SLEEP);
bioinit(buf);
/*
* We use the private field of buf to specify that this is an
* I/O using an absolute offset.
*/
buf->b_private = (void *)VD_SLICE_NONE;
status = physio(vdc_strategy, buf, dev, rw, vdc_min, &auio);
biofini(buf);
kmem_free(buf, sizeof (buf_t));
return (status);
}
/*
* This structure is used in the DKIO(7I) array below.
*/
typedef struct vdc_dk_ioctl {
uint8_t op; /* VD_OP_XXX value */
int cmd; /* Solaris ioctl operation number */
size_t nbytes; /* size of structure to be copied */
/* function to convert between vDisk and Solaris structure formats */
int (*convert)(vdc_t *vdc, void *vd_buf, void *ioctl_arg,
int mode, int dir);
} vdc_dk_ioctl_t;
/*
* Subset of DKIO(7I) operations currently supported
*/
static vdc_dk_ioctl_t dk_ioctl[] = {
{VD_OP_FLUSH, DKIOCFLUSHWRITECACHE, 0,
vdc_null_copy_func},
{VD_OP_GET_WCE, DKIOCGETWCE, sizeof (int),
vdc_get_wce_convert},
{VD_OP_SET_WCE, DKIOCSETWCE, sizeof (int),
vdc_set_wce_convert},
{VD_OP_GET_VTOC, DKIOCGVTOC, sizeof (vd_vtoc_t),
vdc_get_vtoc_convert},
{VD_OP_SET_VTOC, DKIOCSVTOC, sizeof (vd_vtoc_t),
vdc_set_vtoc_convert},
{VD_OP_GET_DISKGEOM, DKIOCGGEOM, sizeof (vd_geom_t),
vdc_get_geom_convert},
{VD_OP_GET_DISKGEOM, DKIOCG_PHYGEOM, sizeof (vd_geom_t),
vdc_get_geom_convert},
{VD_OP_GET_DISKGEOM, DKIOCG_VIRTGEOM, sizeof (vd_geom_t),
vdc_get_geom_convert},
{VD_OP_SET_DISKGEOM, DKIOCSGEOM, sizeof (vd_geom_t),
vdc_set_geom_convert},
{VD_OP_GET_EFI, DKIOCGETEFI, 0,
vdc_get_efi_convert},
{VD_OP_SET_EFI, DKIOCSETEFI, 0,
vdc_set_efi_convert},
/* DIOCTL_RWCMD is converted to a read or a write */
{0, DIOCTL_RWCMD, sizeof (struct dadkio_rwcmd), NULL},
/*
* These particular ioctls are not sent to the server - vdc fakes up
* the necessary info.
*/
{0, DKIOCINFO, sizeof (struct dk_cinfo), vdc_null_copy_func},
{0, DKIOCGMEDIAINFO, sizeof (struct dk_minfo), vdc_null_copy_func},
{0, USCSICMD, sizeof (struct uscsi_cmd), vdc_null_copy_func},
{0, DKIOCGAPART, 0, vdc_null_copy_func },
{0, DKIOCREMOVABLE, 0, vdc_null_copy_func},
{0, CDROMREADOFFSET, 0, vdc_null_copy_func}
};
/*
* Function:
* vd_process_ioctl()
*
* Description:
* This routine processes disk specific ioctl calls
*
* Arguments:
* dev - the device number
* cmd - the operation [dkio(7I)] to be processed
* arg - pointer to user provided structure
* (contains data to be set or reference parameter for get)
* mode - bit flag, indicating open settings, 32/64 bit type, etc
*
* Return Code:
* 0
* EFAULT
* ENXIO
* EIO
* ENOTSUP
*/
static int
vd_process_ioctl(dev_t dev, int cmd, caddr_t arg, int mode)
{
int instance = VDCUNIT(dev);
vdc_t *vdc = NULL;
int rv = -1;
int idx = 0; /* index into dk_ioctl[] */
size_t len = 0; /* #bytes to send to vds */
size_t alloc_len = 0; /* #bytes to allocate mem for */
caddr_t mem_p = NULL;
size_t nioctls = (sizeof (dk_ioctl)) / (sizeof (dk_ioctl[0]));
struct vtoc vtoc_saved;
vdc_dk_ioctl_t *iop;
vdc = ddi_get_soft_state(vdc_state, instance);
if (vdc == NULL) {
cmn_err(CE_NOTE, "![%d] Could not get soft state structure",
instance);
return (ENXIO);
}
DMSG(vdc, 0, "[%d] Processing ioctl(%x) for dev %lx : model %x\n",
instance, cmd, dev, ddi_model_convert_from(mode & FMODELS));
/*
* Validate the ioctl operation to be performed.
*
* If we have looped through the array without finding a match then we
* don't support this ioctl.
*/
for (idx = 0; idx < nioctls; idx++) {
if (cmd == dk_ioctl[idx].cmd)
break;
}
if (idx >= nioctls) {
DMSG(vdc, 0, "[%d] Unsupported ioctl (0x%x)\n",
vdc->instance, cmd);
return (ENOTSUP);
}
iop = &(dk_ioctl[idx]);
if (cmd == DKIOCGETEFI || cmd == DKIOCSETEFI) {
/* size is not fixed for EFI ioctls, it depends on ioctl arg */
dk_efi_t dk_efi;
rv = ddi_copyin(arg, &dk_efi, sizeof (dk_efi_t), mode);
if (rv != 0)
return (EFAULT);
len = sizeof (vd_efi_t) - 1 + dk_efi.dki_length;
} else {
len = iop->nbytes;
}
/*
* Deal with the ioctls which the server does not provide. vdc can
* fake these up and return immediately
*/
switch (cmd) {
case CDROMREADOFFSET:
case DKIOCREMOVABLE:
case USCSICMD:
return (ENOTTY);
case DIOCTL_RWCMD:
{
if (vdc->cinfo->dki_ctype != DKC_DIRECT)
return (ENOTTY);
return (vdc_dioctl_rwcmd(dev, arg, mode));
}
case DKIOCGAPART:
{
if (vdc->vdisk_label != VD_DISK_LABEL_VTOC)
return (ENOTSUP);
return (vdc_dkio_get_partition(dev, arg, mode));
}
case DKIOCINFO:
{
struct dk_cinfo cinfo;
if (vdc->cinfo == NULL)
return (ENXIO);
bcopy(vdc->cinfo, &cinfo, sizeof (struct dk_cinfo));
cinfo.dki_partition = VDCPART(dev);
rv = ddi_copyout(&cinfo, (void *)arg,
sizeof (struct dk_cinfo), mode);
if (rv != 0)
return (EFAULT);
return (0);
}
case DKIOCGMEDIAINFO:
{
if (vdc->minfo == NULL)
return (ENXIO);
rv = ddi_copyout(vdc->minfo, (void *)arg,
sizeof (struct dk_minfo), mode);
if (rv != 0)
return (EFAULT);
return (0);
}
case DKIOCFLUSHWRITECACHE:
{
struct dk_callback *dkc = (struct dk_callback *)arg;
vdc_dk_arg_t *dkarg = NULL;
DMSG(vdc, 1, "[%d] Flush W$: mode %x\n",
instance, mode);
/*
* If the backing device is not a 'real' disk then the
* W$ operation request to the vDisk server will fail
* so we might as well save the cycles and return now.
*/
if (vdc->vdisk_type != VD_DISK_TYPE_DISK)
return (ENOTTY);
/*
* If arg is NULL, then there is no callback function
* registered and the call operates synchronously; we
* break and continue with the rest of the function and
* wait for vds to return (i.e. after the request to
* vds returns successfully, all writes completed prior
* to the ioctl will have been flushed from the disk
* write cache to persistent media.
*
* If a callback function is registered, we dispatch
* the request on a task queue and return immediately.
* The callback will deal with informing the calling
* thread that the flush request is completed.
*/
if (dkc == NULL)
break;
/*
* the asynchronous callback is only supported if
* invoked from within the kernel
*/
if ((mode & FKIOCTL) == 0)
return (ENOTSUP);
dkarg = kmem_zalloc(sizeof (vdc_dk_arg_t), KM_SLEEP);
dkarg->mode = mode;
dkarg->dev = dev;
bcopy(dkc, &dkarg->dkc, sizeof (*dkc));
mutex_enter(&vdc->lock);
vdc->dkio_flush_pending++;
dkarg->vdc = vdc;
mutex_exit(&vdc->lock);
/* put the request on a task queue */
rv = taskq_dispatch(system_taskq, vdc_dkio_flush_cb,
(void *)dkarg, DDI_SLEEP);
if (rv == NULL) {
/* clean up if dispatch fails */
mutex_enter(&vdc->lock);
vdc->dkio_flush_pending--;
kmem_free(dkarg, sizeof (vdc_dk_arg_t));
}
return (rv == NULL ? ENOMEM : 0);
}
}
/* catch programming error in vdc - should be a VD_OP_XXX ioctl */
ASSERT(iop->op != 0);
/* LDC requires that the memory being mapped is 8-byte aligned */
alloc_len = P2ROUNDUP(len, sizeof (uint64_t));
DMSG(vdc, 1, "[%d] struct size %ld alloc %ld\n",
instance, len, alloc_len);
ASSERT(alloc_len >= 0); /* sanity check */
if (alloc_len > 0)
mem_p = kmem_zalloc(alloc_len, KM_SLEEP);
if (cmd == DKIOCSVTOC) {
/*
* Save a copy of the current VTOC so that we can roll back
* if the setting of the new VTOC fails.
*/
bcopy(vdc->vtoc, &vtoc_saved, sizeof (struct vtoc));
}
/*
* Call the conversion function for this ioctl which, if necessary,
* converts from the Solaris format to the format ARC'ed
* as part of the vDisk protocol (FWARC 2006/195)
*/
ASSERT(iop->convert != NULL);
rv = (iop->convert)(vdc, arg, mem_p, mode, VD_COPYIN);
if (rv != 0) {
DMSG(vdc, 0, "[%d] convert func returned %d for ioctl 0x%x\n",
instance, rv, cmd);
if (mem_p != NULL)
kmem_free(mem_p, alloc_len);
return (rv);
}
/*
* send request to vds to service the ioctl.
*/
rv = vdc_do_sync_op(vdc, iop->op, mem_p, alloc_len,
VDCPART(dev), 0, CB_SYNC, (void *)(uint64_t)mode,
VIO_both_dir);
if (rv != 0) {
/*
* This is not necessarily an error. The ioctl could
* be returning a value such as ENOTTY to indicate
* that the ioctl is not applicable.
*/
DMSG(vdc, 0, "[%d] vds returned %d for ioctl 0x%x\n",
instance, rv, cmd);
if (mem_p != NULL)
kmem_free(mem_p, alloc_len);
if (cmd == DKIOCSVTOC) {
/* update of the VTOC has failed, roll back */
bcopy(&vtoc_saved, vdc->vtoc, sizeof (struct vtoc));
}
return (rv);
}
if (cmd == DKIOCSVTOC) {
/*
* The VTOC has been changed. We need to update the device
* nodes to handle the case where an EFI label has been
* changed to a VTOC label. We also try and update the device
* node properties. Failing to set the properties should
* not cause an error to be return the caller though.
*/
vdc->vdisk_label = VD_DISK_LABEL_VTOC;
(void) vdc_create_device_nodes_vtoc(vdc);
if (vdc_create_device_nodes_props(vdc)) {
DMSG(vdc, 0, "![%d] Failed to update device nodes"
" properties", vdc->instance);
}
} else if (cmd == DKIOCSETEFI) {
/*
* The EFI has been changed. We need to update the device
* nodes to handle the case where a VTOC label has been
* changed to an EFI label. We also try and update the device
* node properties. Failing to set the properties should
* not cause an error to be return the caller though.
*/
struct dk_gpt *efi;
size_t efi_len;
vdc->vdisk_label = VD_DISK_LABEL_EFI;
(void) vdc_create_device_nodes_efi(vdc);
rv = vdc_efi_alloc_and_read(dev, &efi, &efi_len);
if (rv == 0) {
vdc_store_efi(vdc, efi);
rv = vdc_create_device_nodes_props(vdc);
vd_efi_free(efi, efi_len);
}
if (rv) {
DMSG(vdc, 0, "![%d] Failed to update device nodes"
" properties", vdc->instance);
}
}
/*
* Call the conversion function (if it exists) for this ioctl
* which converts from the format ARC'ed as part of the vDisk
* protocol (FWARC 2006/195) back to a format understood by
* the rest of Solaris.
*/
rv = (iop->convert)(vdc, mem_p, arg, mode, VD_COPYOUT);
if (rv != 0) {
DMSG(vdc, 0, "[%d] convert func returned %d for ioctl 0x%x\n",
instance, rv, cmd);
if (mem_p != NULL)
kmem_free(mem_p, alloc_len);
return (rv);
}
if (mem_p != NULL)
kmem_free(mem_p, alloc_len);
return (rv);
}
/*
* Function:
*
* Description:
* This is an empty conversion function used by ioctl calls which
* do not need to convert the data being passed in/out to userland
*/
static int
vdc_null_copy_func(vdc_t *vdc, void *from, void *to, int mode, int dir)
{
_NOTE(ARGUNUSED(vdc))
_NOTE(ARGUNUSED(from))
_NOTE(ARGUNUSED(to))
_NOTE(ARGUNUSED(mode))
_NOTE(ARGUNUSED(dir))
return (0);
}
static int
vdc_get_wce_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir)
{
_NOTE(ARGUNUSED(vdc))
if (dir == VD_COPYIN)
return (0); /* nothing to do */
if (ddi_copyout(from, to, sizeof (int), mode) != 0)
return (EFAULT);
return (0);
}
static int
vdc_set_wce_convert(vdc_t *vdc, void *from, void *to,
int mode, int dir)
{
_NOTE(ARGUNUSED(vdc))
if (dir == VD_COPYOUT)
return (0); /* nothing to do */
if (ddi_copyin(from, to, sizeof (int), mode) != 0)
return (EFAULT);
return (0);
}
/*
* Function:
* vdc_get_vtoc_convert()
*
* Description:
* This routine performs the necessary convertions from the DKIOCGVTOC
* Solaris structure to the format defined in FWARC 2006/195.
*
* In the struct vtoc definition, the timestamp field is marked as not
* supported so it is not part of vDisk protocol (FWARC 2006/195).
* However SVM uses that field to check it can write into the VTOC,
* so we fake up the info of that field.
*
* Arguments:
* vdc - the vDisk client
* from - the buffer containing the data to be copied from
* to - the buffer to be copied to
* mode - flags passed to ioctl() call
* dir - the "direction" of the copy - VD_COPYIN or VD_COPYOUT
*
* Return Code:
* 0 - Success
* ENXIO - incorrect buffer passed in.
* EFAULT - ddi_copyout routine encountered an error.
*/
static int
vdc_get_vtoc_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
{
int i;
void *tmp_mem = NULL;
void *tmp_memp;
struct vtoc vt;
struct vtoc32 vt32;
int copy_len = 0;
int rv = 0;
if (dir != VD_COPYOUT)
return (0); /* nothing to do */
if ((from == NULL) || (to == NULL))
return (ENXIO);
if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32)
copy_len = sizeof (struct vtoc32);
else
copy_len = sizeof (struct vtoc);
tmp_mem = kmem_alloc(copy_len, KM_SLEEP);
VD_VTOC2VTOC((vd_vtoc_t *)from, &vt);
/* fake the VTOC timestamp field */
for (i = 0; i < V_NUMPAR; i++) {
vt.timestamp[i] = vdc->vtoc->timestamp[i];
}
if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
vtoctovtoc32(vt, vt32);
tmp_memp = &vt32;
} else {
tmp_memp = &vt;
}
rv = ddi_copyout(tmp_memp, to, copy_len, mode);
if (rv != 0)
rv = EFAULT;
kmem_free(tmp_mem, copy_len);
return (rv);
}
/*
* Function:
* vdc_set_vtoc_convert()
*
* Description:
* This routine performs the necessary convertions from the DKIOCSVTOC
* Solaris structure to the format defined in FWARC 2006/195.
*
* Arguments:
* vdc - the vDisk client
* from - Buffer with data
* to - Buffer where data is to be copied to
* mode - flags passed to ioctl
* dir - direction of copy (in or out)
*
* Return Code:
* 0 - Success
* ENXIO - Invalid buffer passed in
* EFAULT - ddi_copyin of data failed
*/
static int
vdc_set_vtoc_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
{
void *tmp_mem = NULL;
struct vtoc vt;
struct vtoc *vtp = &vt;
vd_vtoc_t vtvd;
int copy_len = 0;
int rv = 0;
if (dir != VD_COPYIN)
return (0); /* nothing to do */
if ((from == NULL) || (to == NULL))
return (ENXIO);
if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32)
copy_len = sizeof (struct vtoc32);
else
copy_len = sizeof (struct vtoc);
tmp_mem = kmem_alloc(copy_len, KM_SLEEP);
rv = ddi_copyin(from, tmp_mem, copy_len, mode);
if (rv != 0) {
kmem_free(tmp_mem, copy_len);
return (EFAULT);
}
if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
vtoc32tovtoc((*(struct vtoc32 *)tmp_mem), vt);
} else {
vtp = tmp_mem;
}
/*
* The VTOC is being changed, then vdc needs to update the copy
* it saved in the soft state structure.
*/
bcopy(vtp, vdc->vtoc, sizeof (struct vtoc));
VTOC2VD_VTOC(vtp, &vtvd);
bcopy(&vtvd, to, sizeof (vd_vtoc_t));
kmem_free(tmp_mem, copy_len);
return (0);
}
/*
* Function:
* vdc_get_geom_convert()
*
* Description:
* This routine performs the necessary convertions from the DKIOCGGEOM,
* DKIOCG_PHYSGEOM and DKIOG_VIRTGEOM Solaris structures to the format
* defined in FWARC 2006/195
*
* Arguments:
* vdc - the vDisk client
* from - Buffer with data
* to - Buffer where data is to be copied to
* mode - flags passed to ioctl
* dir - direction of copy (in or out)
*
* Return Code:
* 0 - Success
* ENXIO - Invalid buffer passed in
* EFAULT - ddi_copyout of data failed
*/
static int
vdc_get_geom_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
{
_NOTE(ARGUNUSED(vdc))
struct dk_geom geom;
int copy_len = sizeof (struct dk_geom);
int rv = 0;
if (dir != VD_COPYOUT)
return (0); /* nothing to do */
if ((from == NULL) || (to == NULL))
return (ENXIO);
VD_GEOM2DK_GEOM((vd_geom_t *)from, &geom);
rv = ddi_copyout(&geom, to, copy_len, mode);
if (rv != 0)
rv = EFAULT;
return (rv);
}
/*
* Function:
* vdc_set_geom_convert()
*
* Description:
* This routine performs the necessary convertions from the DKIOCSGEOM
* Solaris structure to the format defined in FWARC 2006/195.
*
* Arguments:
* vdc - the vDisk client
* from - Buffer with data
* to - Buffer where data is to be copied to
* mode - flags passed to ioctl
* dir - direction of copy (in or out)
*
* Return Code:
* 0 - Success
* ENXIO - Invalid buffer passed in
* EFAULT - ddi_copyin of data failed
*/
static int
vdc_set_geom_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
{
_NOTE(ARGUNUSED(vdc))
vd_geom_t vdgeom;
void *tmp_mem = NULL;
int copy_len = sizeof (struct dk_geom);
int rv = 0;
if (dir != VD_COPYIN)
return (0); /* nothing to do */
if ((from == NULL) || (to == NULL))
return (ENXIO);
tmp_mem = kmem_alloc(copy_len, KM_SLEEP);
rv = ddi_copyin(from, tmp_mem, copy_len, mode);
if (rv != 0) {
kmem_free(tmp_mem, copy_len);
return (EFAULT);
}
DK_GEOM2VD_GEOM((struct dk_geom *)tmp_mem, &vdgeom);
bcopy(&vdgeom, to, sizeof (vdgeom));
kmem_free(tmp_mem, copy_len);
return (0);
}
static int
vdc_get_efi_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
{
_NOTE(ARGUNUSED(vdc))
vd_efi_t *vd_efi;
dk_efi_t dk_efi;
int rv = 0;
void *uaddr;
if ((from == NULL) || (to == NULL))
return (ENXIO);
if (dir == VD_COPYIN) {
vd_efi = (vd_efi_t *)to;
rv = ddi_copyin(from, &dk_efi, sizeof (dk_efi_t), mode);
if (rv != 0)
return (EFAULT);
vd_efi->lba = dk_efi.dki_lba;
vd_efi->length = dk_efi.dki_length;
bzero(vd_efi->data, vd_efi->length);
} else {
rv = ddi_copyin(to, &dk_efi, sizeof (dk_efi_t), mode);
if (rv != 0)
return (EFAULT);
uaddr = dk_efi.dki_data;
dk_efi.dki_data = kmem_alloc(dk_efi.dki_length, KM_SLEEP);
VD_EFI2DK_EFI((vd_efi_t *)from, &dk_efi);
rv = ddi_copyout(dk_efi.dki_data, uaddr, dk_efi.dki_length,
mode);
if (rv != 0)
return (EFAULT);
kmem_free(dk_efi.dki_data, dk_efi.dki_length);
}
return (0);
}
static int
vdc_set_efi_convert(vdc_t *vdc, void *from, void *to, int mode, int dir)
{
_NOTE(ARGUNUSED(vdc))
dk_efi_t dk_efi;
void *uaddr;
if (dir == VD_COPYOUT)
return (0); /* nothing to do */
if ((from == NULL) || (to == NULL))
return (ENXIO);
if (ddi_copyin(from, &dk_efi, sizeof (dk_efi_t), mode) != 0)
return (EFAULT);
uaddr = dk_efi.dki_data;
dk_efi.dki_data = kmem_alloc(dk_efi.dki_length, KM_SLEEP);
if (ddi_copyin(uaddr, dk_efi.dki_data, dk_efi.dki_length, mode) != 0)
return (EFAULT);
DK_EFI2VD_EFI(&dk_efi, (vd_efi_t *)to);
kmem_free(dk_efi.dki_data, dk_efi.dki_length);
return (0);
}
/*
* Function:
* vdc_create_fake_geometry()
*
* Description:
* This routine fakes up the disk info needed for some DKIO ioctls.
* - DKIOCINFO
* - DKIOCGMEDIAINFO
*
* [ just like lofi(7D) and ramdisk(7D) ]
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_create_fake_geometry(vdc_t *vdc)
{
ASSERT(vdc != NULL);
/*
* Check if max_xfer_sz and vdisk_size are valid
*/
if (vdc->vdisk_size == 0 || vdc->max_xfer_sz == 0)
return (EIO);
/*
* DKIOCINFO support
*/
vdc->cinfo = kmem_zalloc(sizeof (struct dk_cinfo), KM_SLEEP);
(void) strcpy(vdc->cinfo->dki_cname, VDC_DRIVER_NAME);
(void) strcpy(vdc->cinfo->dki_dname, VDC_DRIVER_NAME);
/* max_xfer_sz is #blocks so we don't need to divide by DEV_BSIZE */
vdc->cinfo->dki_maxtransfer = vdc->max_xfer_sz;
/*
* We currently set the controller type to DKC_DIRECT for any disk.
* When SCSI support is implemented, we will eventually change this
* type to DKC_SCSI_CCS for disks supporting the SCSI protocol.
*/
vdc->cinfo->dki_ctype = DKC_DIRECT;
vdc->cinfo->dki_flags = DKI_FMTVOL;
vdc->cinfo->dki_cnum = 0;
vdc->cinfo->dki_addr = 0;
vdc->cinfo->dki_space = 0;
vdc->cinfo->dki_prio = 0;
vdc->cinfo->dki_vec = 0;
vdc->cinfo->dki_unit = vdc->instance;
vdc->cinfo->dki_slave = 0;
/*
* The partition number will be created on the fly depending on the
* actual slice (i.e. minor node) that is used to request the data.
*/
vdc->cinfo->dki_partition = 0;
/*
* DKIOCGMEDIAINFO support
*/
if (vdc->minfo == NULL)
vdc->minfo = kmem_zalloc(sizeof (struct dk_minfo), KM_SLEEP);
vdc->minfo->dki_media_type = DK_FIXED_DISK;
vdc->minfo->dki_capacity = vdc->vdisk_size;
vdc->minfo->dki_lbsize = DEV_BSIZE;
return (0);
}
/*
* Function:
* vdc_setup_disk_layout()
*
* Description:
* This routine discovers all the necessary details about the "disk"
* by requesting the data that is available from the vDisk server and by
* faking up the rest of the data.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
vdc_setup_disk_layout(vdc_t *vdc)
{
buf_t *buf; /* BREAD requests need to be in a buf_t structure */
dev_t dev;
int slice = 0;
int rv, error;
ASSERT(vdc != NULL);
if (vdc->vtoc == NULL)
vdc->vtoc = kmem_zalloc(sizeof (struct vtoc), KM_SLEEP);
dev = makedevice(ddi_driver_major(vdc->dip),
VD_MAKE_DEV(vdc->instance, 0));
rv = vd_process_ioctl(dev, DKIOCGVTOC, (caddr_t)vdc->vtoc, FKIOCTL);
if (rv && rv != ENOTSUP) {
DMSG(vdc, 0, "[%d] Failed to get VTOC (err=%d)",
vdc->instance, rv);
return (rv);
}
/*
* The process of attempting to read VTOC will initiate
* the handshake and establish a connection. Following
* handshake, go ahead and create geometry.
*/
error = vdc_create_fake_geometry(vdc);
if (error != 0) {
DMSG(vdc, 0, "[%d] Failed to create disk geometry (err%d)",
vdc->instance, error);
return (error);
}
if (rv == ENOTSUP) {
/*
* If the device does not support VTOC then we try
* to read an EFI label.
*/
struct dk_gpt *efi;
size_t efi_len;
rv = vdc_efi_alloc_and_read(dev, &efi, &efi_len);
if (rv) {
DMSG(vdc, 0, "[%d] Failed to get EFI (err=%d)",
vdc->instance, rv);
return (rv);
}
vdc->vdisk_label = VD_DISK_LABEL_EFI;
vdc_store_efi(vdc, efi);
vd_efi_free(efi, efi_len);
return (0);
}
vdc->vdisk_label = VD_DISK_LABEL_VTOC;
/*
* FUTURE: This could be default way for reading the VTOC
* from the disk as supposed to sending the VD_OP_GET_VTOC
* to the server. Currently this is a sanity check.
*
* find the slice that represents the entire "disk" and use that to
* read the disk label. The convention in Solaris is that slice 2
* represents the whole disk so we check that it is, otherwise we
* default to slice 0
*/
if ((vdc->vdisk_type == VD_DISK_TYPE_DISK) &&
(vdc->vtoc->v_part[2].p_tag == V_BACKUP)) {
slice = 2;
} else {
slice = 0;
}
/*
* Read disk label from start of disk
*/
vdc->label = kmem_zalloc(DK_LABEL_SIZE, KM_SLEEP);
buf = kmem_alloc(sizeof (buf_t), KM_SLEEP);
bioinit(buf);
buf->b_un.b_addr = (caddr_t)vdc->label;
buf->b_bcount = DK_LABEL_SIZE;
buf->b_flags = B_BUSY | B_READ;
buf->b_dev = dev;
rv = vdc_send_request(vdc, VD_OP_BREAD, (caddr_t)vdc->label,
DK_LABEL_SIZE, slice, 0, CB_STRATEGY, buf, VIO_read_dir);
if (rv) {
DMSG(vdc, 1, "[%d] Failed to read disk block 0\n",
vdc->instance);
kmem_free(buf, sizeof (buf_t));
return (rv);
}
rv = biowait(buf);
biofini(buf);
kmem_free(buf, sizeof (buf_t));
return (rv);
}
/*
* Function:
* vdc_setup_devid()
*
* Description:
* This routine discovers the devid of a vDisk. It requests the devid of
* the underlying device from the vDisk server, builds an encapsulated
* devid based on the retrieved devid and registers that new devid to
* the vDisk.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - A devid was succesfully registered for the vDisk
*/
static int
vdc_setup_devid(vdc_t *vdc)
{
int rv;
vd_devid_t *vd_devid;
size_t bufsize, bufid_len;
/*
* At first sight, we don't know the size of the devid that the
* server will return but this size will be encoded into the
* reply. So we do a first request using a default size then we
* check if this size was large enough. If not then we do a second
* request with the correct size returned by the server. Note that
* ldc requires size to be 8-byte aligned.
*/
bufsize = P2ROUNDUP(VD_DEVID_SIZE(VD_DEVID_DEFAULT_LEN),
sizeof (uint64_t));
vd_devid = kmem_zalloc(bufsize, KM_SLEEP);
bufid_len = bufsize - sizeof (vd_efi_t) - 1;
rv = vdc_do_sync_op(vdc, VD_OP_GET_DEVID, (caddr_t)vd_devid,
bufsize, 0, 0, CB_SYNC, 0, VIO_both_dir);
DMSG(vdc, 2, "sync_op returned %d\n", rv);
if (rv) {
kmem_free(vd_devid, bufsize);
return (rv);
}
if (vd_devid->length > bufid_len) {
/*
* The returned devid is larger than the buffer used. Try again
* with a buffer with the right size.
*/
kmem_free(vd_devid, bufsize);
bufsize = P2ROUNDUP(VD_DEVID_SIZE(vd_devid->length),
sizeof (uint64_t));
vd_devid = kmem_zalloc(bufsize, KM_SLEEP);
bufid_len = bufsize - sizeof (vd_efi_t) - 1;
rv = vdc_do_sync_op(vdc, VD_OP_GET_DEVID,
(caddr_t)vd_devid, bufsize, 0, 0, CB_SYNC, 0,
VIO_both_dir);
if (rv) {
kmem_free(vd_devid, bufsize);
return (rv);
}
}
/*
* The virtual disk should have the same device id as the one associated
* with the physical disk it is mapped on, otherwise sharing a disk
* between a LDom and a non-LDom may not work (for example for a shared
* SVM disk set).
*
* The DDI framework does not allow creating a device id with any
* type so we first create a device id of type DEVID_ENCAP and then
* we restore the orignal type of the physical device.
*/
DMSG(vdc, 2, ": devid length = %d\n", vd_devid->length);
/* build an encapsulated devid based on the returned devid */
if (ddi_devid_init(vdc->dip, DEVID_ENCAP, vd_devid->length,
vd_devid->id, &vdc->devid) != DDI_SUCCESS) {
DMSG(vdc, 1, "[%d] Fail to created devid\n", vdc->instance);
kmem_free(vd_devid, bufsize);
return (1);
}
DEVID_FORMTYPE((impl_devid_t *)vdc->devid, vd_devid->type);
ASSERT(ddi_devid_valid(vdc->devid) == DDI_SUCCESS);
kmem_free(vd_devid, bufsize);
if (ddi_devid_register(vdc->dip, vdc->devid) != DDI_SUCCESS) {
DMSG(vdc, 1, "[%d] Fail to register devid\n", vdc->instance);
return (1);
}
return (0);
}
static void
vdc_store_efi(vdc_t *vdc, struct dk_gpt *efi)
{
struct vtoc *vtoc = vdc->vtoc;
vd_efi_to_vtoc(efi, vtoc);
if (vdc->vdisk_type == VD_DISK_TYPE_SLICE) {
/*
* vd_efi_to_vtoc() will store information about the EFI Sun
* reserved partition (representing the entire disk) into
* partition 7. However single-slice device will only have
* that single partition and the vdc driver expects to find
* information about that partition in slice 0. So we need
* to copy information from slice 7 to slice 0.
*/
vtoc->v_part[0].p_tag = vtoc->v_part[VD_EFI_WD_SLICE].p_tag;
vtoc->v_part[0].p_flag = vtoc->v_part[VD_EFI_WD_SLICE].p_flag;
vtoc->v_part[0].p_start = vtoc->v_part[VD_EFI_WD_SLICE].p_start;
vtoc->v_part[0].p_size = vtoc->v_part[VD_EFI_WD_SLICE].p_size;
}
}
|