Files @ 2ee8c8344ccb
Branch filter:

Location: vmkdrivers/BLD/build/HEADERS/vmkapi-current-all-public-bincomp/generic/release/scsi/vmkapi_scsi.h

unknown
ESXi-6.0-U1a
   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
/***************************************************************************
 * Copyright 2004 - 2013 VMware, Inc.  All rights reserved.
 ***************************************************************************/

/*
 * @VMKAPIMOD_LICENSE@
 */

/*
 ***********************************************************************
 * SCSI                                                           */ /**
 * \addtogroup Storage
 * @{
 * \defgroup SCSI SCSI Interfaces
 * @{
 ***********************************************************************
 */

#ifndef _VMKAPI_SCSI_H_
#define _VMKAPI_SCSI_H_

/** \cond never */
#ifndef VMK_HEADER_INCLUDED_FROM_VMKAPI_H
#error This vmkapi file should never be included directly but only via vmkapi.h
#endif
/** \endcond never */

#include "scsi/vmkapi_scsi_const.h"
#include "scsi/vmkapi_scsi_types.h"

/*
 * Physical Path
 */

/*
 ***********************************************************************
 * vmk_ScsiDeviceClassToString --                                 */ /**
 *
 * \brief Convert a SCSI class identifier into a human-readable text
 *        string.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] sclass    SCSI class to convert.
 *
 * \return The description string.
 *
 ***********************************************************************
 */
const char *vmk_ScsiDeviceClassToString(
   vmk_ScsiDeviceClass sclass);

/*
 ***********************************************************************
 * vmk_ScsiScanPaths --                                           */ /**
 *
 * \brief Scan one or more physical paths.
 *
 * The discovered paths are automatically registered with the
 * storage stack.
 *
 * The sparse luns, max lun id and lun mask settings affect which
 * paths are actually scanned.
 *
 * \note If this routine returns an error, some paths may have been
 *       sucessfully discovered.
 *
 * \note This function may block.
 *
 * \param[in] adapterName  Name of the adapter to scan, or
 *                         VMK_SCSI_PATH_ANY_ADAPTER to scan all
 *                         adapters.
 * \param[in] channel      Channel to scan, or VMK_SCSI_PATH_ANY_CHANNEL
 *                         to scan all channels.
 * \param[in] target       Target id to scan, or VMK_SCSI_PATH_ANY_TARGET
 *                         to scan all targets.
 * \param[in] lun          LUN id to scan, or VMK_SCSI_PATH_ANY_LUN to
 *                         scan all LUNs.
 *
 *
 * \retval VMK_INVALID_NAME      The requested adapter was not found.
 * \retval VMK_BUSY              The requested adapter is currently being 
 *                               scanned by some other context.
 * \retval VMK_MAX_PATHS_CLAIMED The limit for maximum no. of paths that 
 *                               can be claimed is reached.
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiScanPaths(
   const vmk_Name *adapterName,
   vmk_uint32 channel,
   vmk_uint32 target,
   vmk_uint32 lun);

/*
 ***********************************************************************
 * vmk_ScsiScanAndClaimPaths --                                   */ /**
 *
 * \brief Scan one or more physical paths and run the plugin claim rules.
 *
 * The discovered paths are automatically registered with the
 * storage stack. Path claim is invoked after a successful scan.
 * This may result in new SCSI devices being registered with VMkernel.
 *
 * The sparse luns, max lun id and lun mask settings affect which
 * paths are actually scanned.
 *
 * \note This function may block.
 *
 * \param[in] adapterName  Name of the adapter to scan, or
 *                         \em VMK_SCSI_PATH_ANY_ADAPTER to scan all
 *                         adapters.
 * \param[in] channel      Channel to scan, or 
 *                         \em VMK_SCSI_PATH_ANY_CHANNEL to scan all 
 *                         channels.
 * \param[in] target       Target id to scan, or 
 *                         \em VMK_SCSI_PATH_ANY_TARGET to scan all 
 *                         targets.
 * \param[in] lun          LUN id to scan, or \em VMK_SCSI_PATH_ANY_LUN 
 *                         to scan all LUNs.
 *
 * \return It can return all the errors that vmk_ScsiScanPaths() can return.
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiScanAndClaimPaths(
   const vmk_Name *adapterName,
   vmk_uint32 channel,
   vmk_uint32 target,
   vmk_uint32 lun);

/*
 ***********************************************************************
 * vmk_ScsiScanDeleteAdapterPath --                               */ /**
 *
 * \brief Scan a physical path and remove it if dead
 *
 * The path will be unclaimed and removed only if it is dead.
 * This may result in a SCSI device being unregistered with VMkernel
 * in the case where this is the last path backing that device.
 * If there are users of the device and it is the last path to the
 * device, then the unclaim and deletion of the path will fail.
 *
 * The sparse luns, max lun id and lun mask settings affect whether
 * the path is actually scanned or not.
 *
 * \note This function may block.
 *
 * \note Do NOT use a loop around this call to rescan every possible
 *       path on an adapter. This API is only intended for removal of
 *       specific paths based on a plugins better knowledge of such a
 *       path being removed. In general VMware wants the end user to
 *       know about dead paths so misconfigurations can be fixed and
 *       a plugin should thus never remove a path if it does not have
 *       special knowledge from the backing device about the path
 *       being dead and that this knowledge is irrelevant to the user
 *       (e.g. because the user removed the device through device
 *       specific means etc.).
 *
 * \param[in] adapterName  Name of the adapter to scan
 * \param[in] channel      Channel to scan
 * \param[in] target       Target id to scan
 * \param[in] lun          LUN id to scan
 *
 * \return It can return all the errors that vmk_ScsiScanPaths() can
 *         return as well as VMK_BAD_PARAM if the channel/target/lun
 *         is an ANY parameter (you can only scan one specific path).
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiScanDeleteAdapterPath(
   const vmk_Name *adapterName,
   vmk_uint32 channel,
   vmk_uint32 target,
   vmk_uint32 lun);

/*
 ***********************************************************************
 * vmk_ScsiNotifyPathStateChange --                               */ /**
 *
 * \brief Notify the VMkernel of a possible path state change (sync).
 *
 * Path is identified by \em vmkAdapter, \em channel, \em target
 * and \em lun.
 * This interface does the path probe in the calling context.
 * The function returns the result from an attempt to probe the 
 * state of the path(s) without retrying on error conditions.
 *
 * \note This function may block.
 * \note No spin lock may be held when calling this function.
 *
 * \param[in] vmkAdapter   Name of the adapter for state change.
 * \param[in] channel      Channel for state change.
 * \param[in] target       Target for state change.
 * \param[in] lun          LUN for state change. If -1, scan all
 *                         LUNs on the given adapter, channel,
 *                         and target.
 *
 * \retval VMK_NOT_FOUND   Requested path was not found. This will
 *                         be returned only when a specific \em lun 
 *                         is mentioned (not for \em lun==-1).
 * \retval VMK_BUSY        Requested path is already being probed.
 *
 * \return Any other error indicates some plugin specific error while
 *          probing for the path.
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiNotifyPathStateChange(
   vmk_ScsiAdapter *vmkAdapter,
   vmk_int32 channel,
   vmk_int32 target,
   vmk_int32 lun);

/*
 ***********************************************************************
 * vmk_ScsiNotifyPathStateChangeAsync --                          */ /**
 *
 * \brief Notify the VMkernel of a possible path state change (async).
 *
 * Path is identified by \em vmkAdapter, \em channel, \em target, 
 * \em lun. Unlike vmk_ScsiNotifyPathStateChange(), which does the
 * path probe in the calling context, this function only schedules 
 * the path probe to happen in separate context. Hence there is no 
 * restriction on the calling context (interrupt, or bottom-half, 
 * or kernel context) and the locks held on entry. 
 *
 * The function returns the result of an attempt to schedule a
 * probe of the state of the path(s). The result of the probe 
 * itself is not returned.  In the face of error conditions, 
 * the probe will be retried a large number of times.
 *
 * \note This function will not block.
 *
 * \param[in] vmkAdapter   Name of the adapter for state change.
 * \param[in] channel      Channel for state change.
 * \param[in] target       Target for state change.
 * \param[in] lun          LUN for state change. If -1, scan all
 *                         LUNs on the given adapter, channel,
 *                         and target.
 * 
 * \retval VMK_NO_MEMORY      Out of memory.
 * \retval VMK_BAD_PARAM      Invalid adapter passed.
 * \retval VMK_NO_RESOURCES   Failed to schedule the asynchronous path 
 *                            probe due to lack of resources.
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiNotifyPathStateChangeAsync(
   vmk_ScsiAdapter *vmkAdapter,
   vmk_int32 channel,
   vmk_int32 target,
   vmk_int32 lun);

/*
 ***********************************************************************
 * vmk_ScsiInitTaskMgmt --                                        */ /**
 *
 * \brief Create a task management request filter.
 *
 * A task management request filter consists of two things:
 *
 * - A TASK MANAGEMENT action (abort, device reset, bus reset, lun 
 *   reset etc). This is the \em type parameter.
 *
 * - A rule to define the commands on which the above action should
 *   be performed. This is defined by the \em cmdId parameter.
 *
 * A task management request filter thus created can then be used by any 
 * subsequent functions that expect a \em vmk_ScsiTaskMgmt argument.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] vmkTask   The task management structure to initialize.
 * \param[in] type      Type of task management request.
 * \param[in] cmdId     Identifier of the command(s) to abort.
 *                      This field is only valid for abort and virtual
 *                      reset. It is ignored otherwise. 
 *                      \em VMK_SCSI_TASKMGMT_ANY_INITIATOR is only
 *                      valid for virtual reset.
 *                      cmdID.initiator may one of the following:
 *                      - cmdID.initiator from the vmk_ScsiCommand
 *                        structure.
 *                      - \em VMK_SCSI_TASKMGMT_ANY_INITIATOR.
 *                      - NULL
 *                      If initiator is from the vmk_ScsiCommand 
 *                      structure and type is \em VMK_SCSI_TASKMGMT_ABORT,
 *                      then cmdID.serialNumber can also be obtained
 *                      from vmk_ScsiCommand (cmdID.serialNumber)
 *                      else 0.
 *                      cmdID.serialNumber is only valid for abort.
 *                      It is ignored otherwise.
 * \param[in] worldId   World on behalf of whom the command was issued.
 *                      This argument is only valid for abort and
 *                      virtual reset.  It is ignored otherwise.
 *
 * \par Examples:
 * - Abort a specific I/O:
 *    \code
 *    vmk_ScsiInitTaskMgmt(task, VMK_SCSI_TASKMGMT_ABORT,
 *                         vmkCmd->cmdId, vmkCmd->worldId); 
 *    \endcode
 * - Abort all i/os issued by a single world:
 *    \code
 *    cmdId.initiator = VMK_SCSI_TASKMGMT_ANY_INITIATOR;
 *    cmdId.serialNumber = 0;
 *    vmk_ScsiInitTaskMgmt(task, VMK_SCSI_TASKMGMT_VIRT_RESET,
 *                         cmdId, worldId);
 *    \endcode
 * - Abort all i/os issued by a single world from a specific initiator:
 *    \code
 *    cmdId.initiator = originalInitiator:
 *    cmdId.serialNumber = 0;
 *    vmk_ScsiInitTaskMgmt(task, VMK_SCSI_TASKMGMT_VIRT_RESET,
 *                         cmdId, worldId);
 *    \endcode
 * - Abort all i/os issued by all worlds:
 *    \code
 *    cmdId.initiator = NULL;
 *    cmdId.serialNumber = 0;
 *    vmk_ScsiInitTaskMgmt(task, VMK_SCSI_TASKMGMT_LUN_RESET,
 *                         cmdId, worldId);
 *    \endcode
 *    The worldID should be the World ID of the reset issuer.
 *
 ***********************************************************************
 */
void vmk_ScsiInitTaskMgmt(
   vmk_ScsiTaskMgmt *vmkTask,
   vmk_ScsiTaskMgmtType type,
   vmk_ScsiCommandId cmdId,
   vmk_uint32 worldId);

/*
 ***********************************************************************
 * vmk_ScsiQueryTaskMgmt --                                       */ /**
 *
 * \brief   Matches a SCSI command against a task management request
 *          filter, and returns the action to be taken for that command.
 *
 * The task management request filter is obtained by a call to
 * vmk_ScsiInitTaskMgmt()
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] vmkTaskMgmt     Task management request.
 * \param[in] cmd             Command to check.
 *
 * \retval VMK_SCSI_TASKMGMT_ACTION_IGNORE   No task management action to
 *                                           be taken for this command.
 * \retval VMK_SCSI_TASKMGMT_ACTION_ABORT    Complete this command with
 *                                           status 
 *                                           \em vmkTaskMgmt->\em status
 *
 ***********************************************************************
 */
vmk_ScsiTaskMgmtAction vmk_ScsiQueryTaskMgmt(
   const vmk_ScsiTaskMgmt *vmkTaskMgmt,
   const vmk_ScsiCommand *cmd);

/*
 ***********************************************************************
 * vmk_ScsiGetTaskMgmtTypeName --                                 */ /**
 *
 * \brief Returns a human readable description of the task management
 *        request.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] taskMgmtType    Task management type to convert to a
 *                            string.
 *
 * \return The description string.
 *
 ***********************************************************************
 */
const char *vmk_ScsiGetTaskMgmtTypeName(
   vmk_ScsiTaskMgmtType taskMgmtType);

/*
 ***********************************************************************
 * vmk_ScsiDebugDropCommand --                                    */ /**
 *
 * \brief Tell whether a command should be dropped.
 *
 * This is used for fault injection.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] adapter   Adapter the command would be issued to.
 * \param[in] cmd       Command to check.
 *
 * \retval VMK_TRUE     The command should be dropped.
 * \retval VMK_FALSE    The command should not be dropped.
 *
 * \note vmk_ScsiDebugDropCommand() always returns VMK_FALSE for release
 *       builds.
 *
 ***********************************************************************
 */
vmk_Bool
vmk_ScsiDebugDropCommand(vmk_ScsiAdapter *adapter, vmk_ScsiCommand *cmd);

/*
 ***********************************************************************
 * vmk_ScsiAdapterEvent --                                        */ /**
 *
 * \brief Notifies the VMkernel of a specific event on the
 *        specified adapter.
 *
 * \note This function will not block.
 *
 * \param[in] adapter   Pointer to the adapter to signal the event on.
 * \param[in] eventType Event to signal.
 * 
 * \retval VMK_BUSY        Another adapter event is being processed.
 * \retval VMK_NO_MEMORY   Out of memory.
 *
 * \return  Any other error value indicates some internal error
 *          encountered while notifying VMkernel.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiAdapterEvent(vmk_ScsiAdapter *adapter, vmk_uint32 eventType);

/*
 ***********************************************************************
 * vmk_ScsiAdapterIsPAECapable --                                 */ /**
 *
 * \brief Determines if the adapter supports DMA beyond 32 bits of
 *        machine-address space.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] adapter   Adapter to check.
 *
 * \retval VMK_TRUE     The adapter supports DMA beyond 32 bits.
 * \retval VMK_FALSE    The adapter is limited to DMA in the lower
 *                      32 bits of machine-address space
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiAdapterIsPAECapable(vmk_ScsiAdapter *adapter)
{
   return adapter->paeCapable;
}

/*
 ***********************************************************************
 * vmk_ScsiCmdStatusIsGood --                                     */ /**
 *
 * \brief Determine if a command status indicates a successful
 *        completion.  Note that this function returns false
 *        if the device returns a check condition with a
 *        recovered error sense code.  See vmk_ScsiCmdIsSuccessful()
 *        to test for both conditions.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] status    Status to check.
 *
 * \retval VMK_TRUE     The status indicates successful completion.
 * \retval VMK_FALSE    The status indicates some error. Use
 *                      vmk_ScsiCmdStatusIsCheck() and
 *                      vmk_ScsiExtractSenseData() to get the actual
 *                      error.
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiCmdStatusIsGood(vmk_ScsiCmdStatus status)
{
   return (status.device == VMK_SCSI_DEVICE_GOOD &&
           status.host == VMK_SCSI_HOST_OK &&
           status.plugin == VMK_SCSI_PLUGIN_GOOD) ? VMK_TRUE : VMK_FALSE;
}

/*
 ***********************************************************************
 * vmk_ScsiCmdIsRecoveredError --                                 */ /**
 *
 * \brief Determine if a command status indicates a recovered
 *        error.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] vmkCmd    Command to check.
 *
 * \retval VMK_TRUE     The status indicates a command completed with
 *                      a recovered error status.
 * \retval VMK_FALSE    The status indicates a command did not
 *                      complete with a recovered error status.
 *
 ***********************************************************************
 */
vmk_Bool
vmk_ScsiCmdIsRecoveredError(const vmk_ScsiCommand *vmkCmd);

/*
 ***********************************************************************
 * vmk_ScsiCmdIsSuccessful --                                     */ /**
 *
 * \brief Determine if vmk_ScsiCommand completed successfully.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] vmkCmd    vmkCmd to check
 *
 * \retval VMK_TRUE     The status indicates the i/o completed
 *                      successfully
 * \retval VMK_FALSE    The status indicates some error. Use
 *                      vmk_ScsiCmdStatusIsCheck() and
 *                      vmk_ScsiExtractSenseData() to get the actual
 *                      error.
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiCmdIsSuccessful(const vmk_ScsiCommand *vmkCmd)
{
   return vmk_ScsiCmdStatusIsGood(vmkCmd->status) ||
      vmk_ScsiCmdIsRecoveredError(vmkCmd);
}

/*
 ***********************************************************************
 * vmk_ScsiCmdStatusIsResvConflict --                             */ /**
 *
 * \brief Determine if a command status indicates a reservation
 *        conflict.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] status    Status to check.
 *
 * \retval VMK_TRUE     The status is reservation conflict.
 * \retval VMK_FALSE    The status is not a reservation conflict.
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiCmdStatusIsResvConflict(vmk_ScsiCmdStatus status)
{
   return (status.device == VMK_SCSI_DEVICE_RESERVATION_CONFLICT &&
           status.host == VMK_SCSI_HOST_OK &&
           status.plugin == VMK_SCSI_PLUGIN_GOOD);
}

/*
 ***********************************************************************
 * vmk_ScsiCmdStatusIsCheck --                                    */ /**
 *
 * \brief Determine if a command status indicates a check condition.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] status    Status to check.
 *
 * \retval VMK_TRUE     The status indicates a check condition.
 * \retval VMK_FALSE    The status is not a check condition.
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiCmdStatusIsCheck(vmk_ScsiCmdStatus status)
{
   return (status.device == VMK_SCSI_DEVICE_CHECK_CONDITION &&
           status.host == VMK_SCSI_HOST_OK &&
           status.plugin == VMK_SCSI_PLUGIN_GOOD) ? VMK_TRUE : VMK_FALSE;
}

/*
 ***********************************************************************
 * vmk_ScsiCmdSenseIsPOR --                                       */ /**
 *
 * \brief Determine if sense data is a unit attention with Power-On Reset
 *        as the additional sense code.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] senseData sense data to inspect.
 *
 * \retval VMK_TRUE     The status indicates a unit attention with
 *                      POWER ON, RESET, or BUS DEVICE RESET occured. 
 * \retval VMK_FALSE    The status is not a power-on reset unit attention.
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiCmdSenseIsPOR(const vmk_ScsiSenseData *senseData)
{
   return ((senseData->key == VMK_SCSI_SENSE_KEY_UNIT_ATTENTION) &&
           (senseData->optLen >= 6) &&
           (senseData->asc == VMK_SCSI_ASC_POWER_ON_OR_RESET) &&
           (senseData->ascq <= 4));
}

/*
 ***********************************************************************
 * vmk_ScsiCmdSenseIsResvReleased --                              */ /**
 *
 * \brief Determine if sense data is a unit attention with reservation
 *        released as the additional sense code.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] senseData sense data to inspect.
 *
 * \retval VMK_TRUE     The senses data is a unit attention with 
 *                      reservation released.
 * \retval VMK_FALSE    The senses data is not a unit attention with 
 *                      reservation released.
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiCmdSenseIsResvReleased(const vmk_ScsiSenseData *senseData)
{
   return ((senseData->key == VMK_SCSI_SENSE_KEY_UNIT_ATTENTION) &&
           (senseData->asc == VMK_SCSI_ASC_PARAMS_CHANGED) &&
           (senseData->ascq == 
            VMK_SCSI_ASC_PARAMS_CHANGED_ASCQ_RESERVATIONS_RELEASED));
}

/*
 ***********************************************************************
 * vmk_ScsiCmdSenseIsMediumNotPresent --                          */ /**
 *
 * \brief Determine if sense data is a sense key not ready with medium
 *        not present as the additional sense code.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] senseData sense data to inspect.
 *
 * \retval VMK_TRUE     The senses data is sense key not ready with
 *                      medium not present.
 * \retval VMK_FALSE    The senses data is not a sense key not ready 
 *                      with medium not present.
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiCmdSenseIsMediumNotPresent(const vmk_ScsiSenseData *senseData)
{
   return ((senseData->key == VMK_SCSI_SENSE_KEY_NOT_READY) &&
           (senseData->asc == VMK_SCSI_ASC_MEDIUM_NOT_PRESENT));
}

/*
 ***********************************************************************
 * vmk_ScsiGetLbaLbc --                                           */ /**
 *
 * \brief Parse a SCSI CDB and pull out lba and lbc.
 *
 * Determine the lba and lbc for a given cdb.  This is most useful
 * for READ and WRITE cdb's.  This function will deal with converting
 * endianness & differences between the sizes of cdbs.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in]  cdb         SCSI cdb to parse.
 * \param[in]  cdbLen      Length of cdb in bytes.
 * \param[in]  devClass    SCSI Device Class.
 * \param[out] lba         Logical Block Address.
 * \param[out] lbc         Logical Block Count.
 *
 * \retval VMK_NOT_SUPPORTED     \em devClass is none of 
 *                               \em SCSI_CLASS_DISK, \em SCSI_CLASS_CDROM,
 *                               \em SCSI_CLASS_TAPE, or,
 *                               \em devClass is
 *                               \em SCSI_CLASS_CDROM and \em cdb[0] does 
 *                               not contain 10/12 byte READ/WRITE SCSI
 *                               command opcode.
 * \retval VMK_BAD_PARAM         \em cdb[0] does not contain 6/10/12/16
 *                               byte READ/WRITE SCSI command opcode.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiGetLbaLbc(unsigned char *cdb, vmk_ByteCount cdbLen,
                  vmk_ScsiDeviceClass devClass, vmk_uint64 *lba,
                  vmk_uint32 *lbc);

/*
 ***********************************************************************
 * vmk_ScsiSetLbaLbc --                                           */ /**
 *
 * \brief Set lba and lbc fields in a given SCSI CDB.
 *
 * Set the lba and lbc for a given cdb. This is most useful
 * for READ and WRITE cdb's. This function will deal with converting
 * endianness & differences between the sizes of cdb's. Callers
 * must set \em cdb[0] before making this call.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in,out] cdb         SCSI cdb to set.
 * \param[in]     cdbLen      Length of cdb in bytes.
 * \param[in]     devClass    SCSI Device Class.
 * \param[out]    lba         Logical Block Address.
 * \param[out]    lbc         Logical Block Count.
 *
 * \retval VMK_NOT_SUPPORTED     \em devClass is none of 
 *                               \em SCSI_CLASS_DISK, 
 *                               \em SCSI_CLASS_CDROM, or,
 *                               \em devClass is \em SCSI_CLASS_CDROM and 
 *                               \em cdb[0] does not contain 10/12 byte
 *                               READ/WRITE SCSI command opcode.
 * \retval VMK_BAD_PARAM         \em cdb[0] does not contain 6/10/12/16
 *                               byte SCSI READ/WRITE command opcode.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiSetLbaLbc(unsigned char *cdb, vmk_ByteCount cdbLen,
                  vmk_ScsiDeviceClass devClass, vmk_uint64 *lba,
                  vmk_uint32 *lbc);

/*
 ***********************************************************************
 * vmk_ScsiAllocateAdapter --                                     */ /**
 *
 * \brief Allocate an adapter.
 *
 * \note This function may block.
 *
 * After successful return, the adapter is in \em allocated state.
 * Use vmk_ScsiFreeAdapter() to free this adapter structure.
 *
 * \return New adapter.
 * \retval NULL   Out of memory.
 *
 ***********************************************************************
 */
vmk_ScsiAdapter *vmk_ScsiAllocateAdapter(void);

/*
 ***********************************************************************
 * vmk_ScsiRegisterAdapter --                                     */ /**
 *
 * \deprecated This call should no longer be called directly by a
 *             Native Driver as it is only used internally by PSA.
 *             It is likely to go away in a future release.
 *
 * \brief Register an adapter with the VMkernel.
 *
 * After successful return, the adapter is in \em enabled state and 
 * drivers can issue a scan on that adapter.
 *
 * If \em ScanOnDriverLoad config option is set and 
 * \em vmk_ScsiAdapter->\em flag
 * has \em VMK_SCSI_ADAPTER_FLAG_REGISTER_WITHOUT_SCAN bit clear, then
 * VMkernel will scan all the LUs connected to this adapter. Path 
 * claiming will be run which might result in new SCSI devices being 
 * registered with VMkernel.
 *
 * If you do not want this autoscan and claim process to happen, you can
 * set the \em VMK_SCSI_ADAPTER_FLAG_REGISTER_WITHOUT_SCAN in
 * \em vmk_ScsiAdapter->\em flag, before calling vmk_ScsiRegisterAdapter(). 
 * This can be useful for some drivers f.e. iSCSI, where a usual SCSI 
 * scan does not make sense.
 *
 * \note The scan and claim is done in a deferred context and hence might
 *       not have completed when vmk_ScsiRegisterAdapter() returns.
 *
 * \note This function may block.
 *
 * \param[in] adapter   Adapter to register. This should have been 
 *                      allocated with a prior call to 
 *                      vmk_ScsiAllocateAdapter().
 *
 * \retval VMK_OK          The adapter was successfully registered. Scan 
 *                         and path claim might be still running.
 * \retval VMK_EXISTS      An adapter with same name already registered.
 * \retval VMK_BAD_PARAM   One or more adapter fields are not initialized
 *                         correctly.
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiRegisterAdapter(
   vmk_ScsiAdapter *adapter);

/*
 ***********************************************************************
 * vmk_ScsiUnregisterAdapter --                                   */ /**
 *
 * \deprecated This call should no longer be called directly by a
 *             Native Driver as it is only used internally by PSA.
 *             It is likely to go away in a future release.
 *
 * \brief Unregister an adapter previously registered by
 *        vmk_ScsiRegisterAdapter().
 *
 * \note This function may block indefinitely, waiting for all the 
 *       references on the adapter to be released.
 *
 * \param[in] adapter   Adapter to unregister.
 *
 * \retval VMK_OK       Successfully unregistered. The adapter will go
 *                      to \em allocated state and can be used for a
 *                      subsequent vmk_ScsiRegisterAdapter() call.
 * \retval VMK_BUSY     One or more paths originating from this adapter
 *                      are claimed by some plugin.
 * \retval VMK_FAILURE  Adapter is neither in \em enabled, \em disabled
 *                      or \em allocated state. An appropriate message is
 *                      logged.
 * 
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiUnregisterAdapter(
   vmk_ScsiAdapter *adapter);

/*
 ***********************************************************************
 * vmk_ScsiFreeAdapter --                                         */ /**
 *
 * \brief Free an adapter previously allocated by
 *        vmk_ScsiAllocateAdapter().
 * 
 * \warning Do not call vmk_ScsiFreeAdapter() for a registered adapter.
 *          The adapter should be in \em allocated state.
 *
 * \note This function may block.
 *
 * \param[in]  adapter  Adapter to free.
 *
 ***********************************************************************
 */
void vmk_ScsiFreeAdapter(
   vmk_ScsiAdapter *adapter);

/*
 ***********************************************************************
 * vmk_ScsiRemovePath --                                          */ /**
 *
 * \brief Destroy the path identified by \em adapter, \em channel, 
 *        \em targetId and \em lunId.
 *
 * If the path to be removed is claimed by an MP plugin, VMkernel will
 * first try to unclaim the path by calling the plugin's \em unclaim 
 * entrypoint.
 *
 * \note This function may block indefinitely, waiting for all the 
 *       references held on the path to be released.
 *
 * \param[in] adapter   Adapter for path to remove.
 * \param[in] channel   Channel for path to remove.
 * \param[in] targetId  Target ID for path to remove.
 * \param[in] lunId     LUN ID for path to remove.
 *
 * \retval VMK_TRUE     The path was removed successfully.
 * \retval VMK_FALSE    The path doesn't exist or the path exists but is
 *                      claimed by a plugin and could not be successfully 
 *                      unclaimed.
 *
 ***********************************************************************
 */
vmk_Bool vmk_ScsiRemovePath(
   vmk_ScsiAdapter *adapter,
   vmk_uint32 channel,
   vmk_uint32 targetId,
   vmk_uint32 lunId);


/*
 ***********************************************************************
 * vmk_ScsiRegisterIRQ --                                         */ /**
 *
 * \brief Registers an adapter's interrupt handler and interrupt vector
 *        with the VMkernel for polling during a core dump.
 *
 *  To unregister, simply call vmk_ScsiRegisterIRQ() with NULL for 
 *  \em intrHandler.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] adapter            Adapter to register on behalf of.
 * \param[in] intrCookie         Interrupt cookie number to register.
 * \param[in] intrHandler        Interrupt handler callback to invoke
 *                               when an interrupt needs to be serviced.
 * \param[in] intrHandlerData    Private data to pass to the handler.
 *
 * \return  vmk_ScsiRegisterIRQ() always succeeds.
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiRegisterIRQ(
   vmk_ScsiAdapter *adapter,
   vmk_IntrCookie intrCookie,
   vmk_IntrHandler intrHandler,
   void *intrHandlerData);

/*    
 ***********************************************************************
 * vmk_ScsiHostStatusToString --                                  */ /**
 *
 * \brief Take a SCSI host status and return a static string describing it.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] hostStatus   Status to convert.
 *
 * \return Host status as a human readable string.
 *                            
 ***********************************************************************
 */   
char *
vmk_ScsiHostStatusToString(vmk_ScsiHostStatus hostStatus);

/*
 ***********************************************************************
 * vmk_ScsiDeviceStatusToString --                                */ /**
 *
 * \brief Take a SCSI device status and return a static string describing
 *        it.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] deviceStatus    Status to convert.
 *
 * \return Device status as a human readable string.
 *
 ***********************************************************************
 */
char *
vmk_ScsiDeviceStatusToString(vmk_ScsiDeviceStatus deviceStatus);

/*
 ***********************************************************************
 * vmk_ScsiSenseKeyToString --                                    */ /**
 *
 * \brief Take a SCSI sense key and return a static string describing it.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] senseKey   SCSI sense key to convert.
 *
 * \return Sense key as a human readable string.
 *
 ***********************************************************************
 */
char *
vmk_ScsiSenseKeyToString(vmk_uint32 senseKey);

/*
 ***********************************************************************
 * vmk_ScsiAdditionalSenseToString --                             */ /**
 *
 * \brief Take a SCSI ASC/ASCQ and return a static string describing it.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] asc    SCSI ASC value to convert.
 * \param[in] ascq   SCSI ASCQ value to convert.
 *
 * \return ASC/ASCQ as a human readable string.
 *
 ***********************************************************************
 */
char *
vmk_ScsiAdditionalSenseToString(vmk_uint32 asc,
                                vmk_uint32 ascq);

/*                                                                                        
 **********************************************************************
 * vmk_ScsiExtractSenseData --                                   */ /**
 *
 * \brief Extract the SCSI Check Condition.
 *
 * Examine the contents of the senseBuffer and return the SCSI check
 * condtion key, the Additional Sense Code, and the Additional Sense
 * Code Qualifier.
 *
 * \note The routine only handles sense buffers with a response
 *       code of 0x70 or 0x71 (Section 4.5.3 in the SCSI-3 spec).
 *       It does not handle response codes of 0x72, 0x73 or any
 *       vendor specific response codes.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in]  senseBuffer    The sense buffer to be examined.
 * \param[out] sense_key      The sense key to be extracted.
 * \param[out] asc            The Additional Sense Code to be extracted.
 * \param[out] ascq           The Additional Sense Code Qualifier to be
 *                            extracted.
 *
 * \retval VMK_TRUE     The sense buffer indicates a SCSI error condition,
 *                      and sense_key, asc and ascq have been correctly
 *                      set.
 * \retval VMK_FALSE    There was no error indicated on the current or
 *                      previous command.
 *
 ***********************************************************************
 */
vmk_Bool
vmk_ScsiExtractSenseData(vmk_ScsiSenseData *senseBuffer,
                         vmk_uint8 *sense_key,
                         vmk_uint8 *asc,
                         vmk_uint8 *ascq);

/*
 ***********************************************************************
 * vmk_ScsiCmdGetSenseData --                                     */ /**
 *
 * \brief Obtain sense data associated with the given SCSI command.
 *
 * Command is identified by \em vmkCmd.  Sense data is identified by
 * \em buf.  This buffer will be filled with the contents of SCSI command's
 * sense data buffer.  The caller passes in the size of the sense buffer in
 * \em bufLen.  Depending on the number of sense data bytes required, the caller
 * can allocate a buffer of the appropriate size and pass the size of this
 * buffer in \em bufLen.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \note The max size of SCSI command's sense buffer is obtained by calling
 * vmk_ScsiGetSupportedCmdSenseDataSize.  If the call is made with a buffer
 * larger than the max supported size, only the max supported number of bytes
 * will be set.  The contents of the input buffer beyond that will be set to 0.
 *
 * \note For a small sense buffer, see vmk_ScsiSenseDataSimple.
 *
 * \param[in] vmkCmd       Address of the SCSI command
 * \param[out] buf         Address of the buffer that will
 *                         be filled with sense data
 * \param[in] bufLen       Length of the sense buffer
 *                         above.
 *
 * \retval VMK_OK          Sense data was successfully
 *                         obtained.
 * \retval VMK_BAD_PARAM   A bad argument was passed.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdGetSenseData(vmk_ScsiCommand *vmkCmd,
                        vmk_ScsiSenseData *buf,
                        vmk_ByteCount bufLen);

/*
 ***********************************************************************
 * vmk_ScsiCmdSetSenseData --                                     */ /**
 *
 * \brief Set the sense data of a SCSI command.
 *
 * Command is identified by \em vmkCmd.  Sense data in \em buf is copied
 * to the storage area for sense data in \em vmkCmd.  The number of bytes
 * that will be copied is identified by \em bufLen.  If \em bufLen
 * is less than SCSI command's max sense buffer size(obtained by calling
 * vmk_ScsiGetSupportedCmdSenseDataSize), the remaining bytes in SCSI
 * command's sense buffer are set to 0.  If \em bufLen is larger than
 * SCSI command's max sense buffer size, only max sense buffer size of
 * sense data will be written, ie, sense data will be truncated to the max
 * supported size.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] buf          Address of the buffer that
 *                         holds sense data bytes to be
 *                         copied.
 * \param[in] vmkCmd       Address of the SCSI command
 *                         that contains the destination
 *                         sense buffer.
 * \param[in] bufLen       The number of bytes to be
 *                         copied.
 *
 * \retval VMK_OK          Sense data was successfully
 *                         set.
 * \retval VMK_BAD_PARAM   A bad argument was passed.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdSetSenseData(vmk_ScsiSenseData *buf,
                        vmk_ScsiCommand *vmkCmd,
                        vmk_ByteCount bufLen);

/*
 ***********************************************************************
 * vmk_ScsiCmdClearSenseData --                                   */ /**
 *
 * \brief Clear the sense data attached to a SCSI command
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * Command is identified by \em vmkCmd.
 *
 * \param[in] vmkCmd       Address of the SCSI command
 *
 * \retval VMK_OK          Sense data was successfully
 *                         cleared.
 * \retval VMK_BAD_PARAM   A bad argument was passed.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdClearSenseData(vmk_ScsiCommand *vmkCmd);

/*
 ***********************************************************************
 * vmk_ScsiGetSupportedCmdSenseDataSize --                        */ /**
 *
 * \brief Get the size of the SCSI command's sense data buffer.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \retval The SCSI command's supported buffer size
 *
 ***********************************************************************
 */
vmk_ByteCount
vmk_ScsiGetSupportedCmdSenseDataSize(void);

/*
 ***********************************************************************
 * vmk_ScsiVPDPageSize --                                         */ /**
 *
 * \brief Get the size of a VPD page.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] response  SCSI VPD Inquiry response header. This is usually 
 *                      the SCSI Inquiry response obtained by a prior 
 *                      vmk_ScsiGetPathInquiry() call.
 *                                                                   
 * \return Size of VPD Page in bytes.
 *
 * \note The routine assumes that VPD length field is one byte for
 *       all pages except for page 83 which has 2 byte length.
 *
 ***********************************************************************
 */
vmk_ByteCountSmall 
vmk_ScsiVPDPageSize(vmk_ScsiInquiryVPDResponse *response);

/*
 ***********************************************************************
 * vmk_ScsiIllegalRequest --                                      */ /**
 *
 * \brief Generates "illegal request" sense buffer data.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[out] senseBuffer   The sense buffer to be modified
 * \param[in]  asc           The Additional Sense Code
 * \param[in]  ascq          The Additional Sense Code Qualifier
 *
 * \note Status must be set to VMK_SCSI_DEVICE_CHECK_CONDITION
 *       in order for the sense buffer to be examined.
 *
 ***********************************************************************
 */
void
vmk_ScsiIllegalRequest(vmk_ScsiSenseData *senseBuffer,
                       vmk_uint8 asc,
                       vmk_uint8 ascq);

/*
 ***********************************************************************
 * vmk_ScsiIsReadCdb --                                           */ /**
 *
 * \brief   Check whether the given SCSI opcode is one of the READ
 *          commands. 
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \retval VMK_TRUE  Opcode is a READ CDB opcode.
 * \retval VMK_FALSE Opcode is not a READ CDB opcode. 
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiIsReadCdb(vmk_uint8 cdb0)
{
   return cdb0 == VMK_SCSI_CMD_READ6 
      || cdb0 == VMK_SCSI_CMD_READ10
      || cdb0 == VMK_SCSI_CMD_READ12
      || cdb0 == VMK_SCSI_CMD_READ16;
}

/*
 ***********************************************************************
 * vmk_ScsiIsWriteCdb --                                          */ /**
 *
 * \brief   Check whether the given SCSI opcode is one of the WRITE
 *          commands. 
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \retval VMK_TRUE  Opcode is a WRITE CDB opcode.
 * \retval VMK_FALSE Opcode is not a WRITE CDB opcode. 
 *
 ***********************************************************************
 */
static inline vmk_Bool
vmk_ScsiIsWriteCdb(vmk_uint8 cdb0)
{
   return cdb0 == VMK_SCSI_CMD_WRITE6 
      || cdb0 == VMK_SCSI_CMD_WRITE10
      || cdb0 == VMK_SCSI_CMD_WRITE12
      || cdb0 == VMK_SCSI_CMD_WRITE16;
}

/*
 ***********************************************************************
 * vmk_ScsiGetAdapterName --                                      */ /**
 *
 * \brief Return the adapter's name
 *
 * \note Spin locks can be held while calling into this function
 *
 * \note This function will not block.
 *
 ***********************************************************************
 */
static inline const char *
vmk_ScsiGetAdapterName(const vmk_ScsiAdapter *vmkAdapter)
{
   return vmk_NameToString((vmk_Name *)&vmkAdapter->name);
}

/*                                                                                        
 **********************************************************************                  
 * vmk_ScsiSetPathXferLimit --                                   */ /**                  
 *                                                                                        
 * \brief Set the maximum single transfer size limit for a path.
 *                                                             
 * \param[in] vmkAdapter   The target adapter.
 * \param[in] channel      The target channel.
 * \param[in] target       The target number.
 * \param[in] lun          The target LUN.
 * \param[in] maxXfer      The new maximum transfer size in bytes.
 *
 * \retval VMK_OK          The max transfer size was set successfully.
 * \retval VMK_NOT_FOUND   The requested path was not found.
 *
 * \warning Do not set maximum transfer size to 0. This will result
 *          in undefined behaviour.
 *
 * \note    You should not set maximum transfer size to a value greater
 *          than the adapter's maximum transfer size. Most adapters 
 *          support a maximum transfer size of 256K, so it is safe to 
 *          set a \em maxXfer value <= 256K.
 *
 * \note This function will not block.
 *
 ***********************************************************************                  
 */
VMK_ReturnStatus
vmk_ScsiSetPathXferLimit(vmk_ScsiAdapter *vmkAdapter,
                         vmk_int32 channel,
                         vmk_int32 target,
                         vmk_int32 lun,
                         vmk_ByteCount maxXfer);

/*                                                                                        
 **********************************************************************
 * vmk_ScsiModifyQueueDepth --                                   */ /**
 *
 * \brief Set the queue depth of the path specified by \em vmkAdapter 
 *       \em channel, \em target, and \em lun.
 *
 * For multiple paths going through the same SCSI adapter, the path
 * queue depth controls the share of that path in the adapter's queue.
 * Setting path queue depth to a value greater than the underlying 
 * adapter's queue depth is inconsequential and should not be done.
 *        
 * \note This function will not block.
 *
 * \param[in] vmkAdapter   The target adapter.
 * \param[in] channel      The target channel.
 * \param[in] target       The target number.
 * \param[in] lun          The target LUN.
 * \param[in] qdepth       The new queue depth value.
 *
 * \retval VMK_OK          The queue depth was set successfully.
 * \retval VMK_NOT_FOUND   The requested path was not found.
 *
 * \warning Do not set qdepth to 0. This will result in undefined 
 *          behaviour.
 *
 ***********************************************************************                  
 */
VMK_ReturnStatus
vmk_ScsiModifyQueueDepth(vmk_ScsiAdapter *vmkAdapter,
                         vmk_int32 channel,
                         vmk_int32 target,
                         vmk_int32 lun,
                         vmk_uint32 qdepth);

/*
 ***********************************************************************
 * vmk_ScsiAllFCPathsDown --                                      */ /**
 *
 * \brief Check if all Fibre Channel transport paths are dead.
 *
 * \note This function will not block.
 *
 * \retval VMK_TRUE  There are one or more Fibre Channel paths but all
 *                   of them are currently down.
 * \retval VMK_FALSE There are no Fibre Channel paths or one or more 
 *                   Fibre Channel paths are up.
 *
 ***********************************************************************
 */
vmk_Bool vmk_ScsiAllFCPathsDown(void);

/*
 ***********************************************************************
 * vmk_ScsiAdapterUniqueName --                                   */ /**
 *
 * \ingroup DeviceName
 * \deprecated This call should no longer be called directly by a
 *             Native Driver as it is only used internally by PSA.
 *             It is likely to go away in a future release.
 *
 * \brief Create a new unique adapter name.
 *
 * This function returns a new unique adapter name.
 *
 * \note This function will not block.
 *
 * \param[out] adapterName  Pointer to an element of type vmk_Name to
 *                          receive the new adapter name.
 ***********************************************************************
 */
void vmk_ScsiAdapterUniqueName(vmk_Name *adapterName);

/*
 ***********************************************************************
 * vmk_ScsiGetIdentifierFromPage83Inquiry --                      */ /**
 *
 * \brief Get a UID of given type from a page 83 inquiry buffer
 *
 * Get the identifier of the given idType from the given page 83
 * inquiry data buffer. The id descriptor is returned if parameter
 * desc is non-NULL.
 *
 * \note The returned descriptor is not NULL terminated (many ID types
 *       can contain NULL as valid data). The length of the returned
 *       descriptor is in the desc->idLen field.
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in]  inquiryBuf     Buffer with VPD page 83
 * \param[in]  inquiryBufLen  Length of the inquiryBuf buffer
 * \param[in]  idType         SCSI identifier type
 * \param[in]  assoc          SCSI association type
 * \param[out] id             Identifier buffer
 * \param[in]  idLength       Size of identifier buffer
 * \param[out] desc
 *
 * \retval VMK_NOT_FOUND   An identifier descriptor of the given idType
 *                         could not be found in the page 83 inquiry 
 *                         response
 * \retval VMK_OK          An identifier descriptor of the given idType
 *                         was found and the identifier was copied into
 *                         the provided id buffer
 * \retval VMK_BAD_PARAM   An identifier descriptor of the given idType
 *                         was found but the identifier was larger than
 *                         the provided id[] array.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiGetIdentifierFromPage83Inquiry(vmk_uint8 *inquiryBuf,
                                       vmk_ByteCountSmall inquiryBufLen,
                                       vmk_ScsiIdentifierType idType,
                                       vmk_ScsiAssociationType assoc,
                                       vmk_uint8 *id,
                                       vmk_ByteCountSmall  idLength,
                                       vmk_ScsiInquiryVPD83IdDesc *desc);

/*
 ***********************************************************************
 * vmk_ScsiGetSystemLimits --                                     */ /**
 *
 * \brief Retrieve the max number of Scsi devices and paths supported
 *
 * \note This function will not block.
 *
 * \param[out] limits   pointer to a structure containing 
 *                      max number of supported devices and paths
 *
 ***********************************************************************
 */
void
vmk_ScsiGetSystemLimits(vmk_ScsiSystemLimits *limits);

/*
 ***********************************************************************
 * vmk_ScsiCommandGetCompletionHandle --                          */ /**
 *
 * \deprecated Do not use in Native Drivers - please see
 *             vmk_ScsiCommandGetCompletionQueue instead
 *
 * \brief Get the Completion handle for the SCSI command.
 *
 * This function will return the Completion handle which the VMkernel
 * wants the lower layer to preferably use to process this command.
 *
 * \pre Adapter's Completion Objects should have been registered.
 *
 * \see  vmk_ScsiRegisterCompObjects()
 *
 * \note This function will not block.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] vmkAdapter SCSI Adapter for which handle is extracted.
 * \param[in] vmkCmd     vmk_ScsiCommand for which handle is extracted.
 *
 ***********************************************************************
 */
vmk_ScsiCompletionHandle
vmk_ScsiCommandGetCompletionHandle(vmk_ScsiAdapter *vmkAdapter,
                                   vmk_ScsiCommand *vmkCmd);

/*
 ***********************************************************************
 * vmk_ScsiRegisterCompObjects --                                 */ /**
 *
 * \deprecated Do not use in Native Drivers - please see
 *             vmk_ScsiStartCompletionQueues instead
 *
 * \brief Register the completion objects for the adapter with vmkernel
 *
 * This function registers the completion objects created by vmkLinux
 * for the adapter with the VMkernel. The VMkernel will save the handle
 * for the completion objects internally.
 * While processing the SCSI command the adapter can ask the VMkernel 
 * for the completion object in the adapter to be used to process the
 * command.
 *
 * \pre  The adapter should have been registered with vmkernel
 *
 * \see  vmk_ScsiCommandGetCompletionHandle()
 *
 * \note This function may block.
 *
 * \param[in] vmkAdapter     ScsiAdapter having the Completion Object
 * \param[in] numCompObjects number of Completion Objects.
 * \param[in] compObj        array of compObjects created by lower layer
 *
 ***********************************************************************
 */
VMK_ReturnStatus vmk_ScsiRegisterCompObjects(vmk_ScsiAdapter *vmkAdapter,
                                             vmk_uint32 numCompObjects,
                                             vmk_ScsiCompObjectInfo compObj[]);

/*
 ***********************************************************************
 * vmk_ScsiGetNumCompObjects --                                   */ /**
 *
 * \deprecated Do not use in Native Drivers - please see
 *             vmk_ScsiGetMaxNumCompletionQueues instead
 *
 * \brief Queries VMKernel for number of Completion Objects
 *
 * \note This function will not block.
 *
 * \return Maximum Number of Completion Objects that can be created 
 *
 ***********************************************************************
 */
vmk_uint32 vmk_ScsiGetNumCompObjects(void);

/*
 ***********************************************************************
 * vmk_ScsiGetMaxNumCompletionQueues --                           */ /**
 *
 * \brief Provide max number of Completion queues to create for adapter
 *
 * \note This function will not block.
 *
 * \return Maximum Number of Completion queues that can be created for
 *         any adapter.
 *
 ***********************************************************************
 */
vmk_uint32 vmk_ScsiGetMaxNumCompletionQueues(void);

/*
 ***********************************************************************
 * vmk_ScsiStartCompletionQueues --                               */ /**
 *
 * \brief Create Completion queues and completion worlds for an adapter
 *
 * PSA will go ahead and create the number of completion queues passed
 * as well as the associated completion worlds to drive up completions.
 * This means that the driver can call vmkCmd->done from any context
 * since the command will simply be queued and driven to completion
 * by a separate completion world.
 *
 * \note This function may block.
 *
 * \note There will always be one completion world for native adapters
 *       so the driver never has to create it's own completion worlds.
 *
 * \note The number of completion worlds can be raised dynamically, but
 *       cannot currently be decreased. The completion worlds will be
 *       destroyed when the adapter is unregistered, so no special
 *       cleanup has to be done for multiple completion queues.
 *
 * \note If anything fails when creating or extending the number of
 *       completion worlds we will leave the number of completion
 *       worlds to what it was previously.
 *
 * \param[in] vmkAdapter   ScsiAdapter to create/increase queues for
 * \param[in] numQueues    Number of Completion queues to create
 *
 * \retval  VMK_OK         If queues were created, error otherwise
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiStartCompletionQueues(vmk_ScsiAdapter *vmkAdapter,
                              vmk_uint32 numQueues);

/*
 ***********************************************************************
 * vmk_ScsiCommandGetCompletionQueue --                           */ /**
 *
 * \brief Get the Completion queue that should be used for a command
 *
 * This function is for instance used by the driver before issuing the
 * command so it can be issued to the right adapter queue (what the
 * VMkernel would like as it optimizes this dynamically based on what
 * PCPUs a given VM/issuer is running on).
 *
 * \note This function will not block.
 *
 * \param[in] vmkAdapter   ScsiAdapter having the Completion queue
 * \param[in] vmkCmd       The SCSI command to get queue for
 *
 * \returns The queue number to issue this command on
 *
 ***********************************************************************
 */
vmk_uint32
vmk_ScsiCommandGetCompletionQueue(vmk_ScsiAdapter *vmkAdapter,
                                  vmk_ScsiCommand *vmkCmd);

/*
 ***********************************************************************
 * vmk_ScsiCheckPluginRegistered --                               */ /**
 *
 * \brief Check if Plugin is registered.
 *
 * \note This function will not block.
 *
 * \retval  VMK_OK         If plugin is registered.
 * \retval  VMK_NOT_FOUND  If plugin is not registered.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCheckPluginRegistered(const char *plugin);

/*
 ***********************************************************************
 * vmk_ScsiGetRegisteredModuleName --                             */ /**
 *
 * \brief Get the the Module name for the Plugin specified.
 *
 * \note This function will not block.
 *
 * \param[in]   plugin   Plugin name.
 * \param[out]  name     Buffer for module name.
 *
 * \retval  VMK_OK             If plugin module name is copied to "name".
 * \retval  VMK_NOT_FOUND      If plugin is not registered.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiGetRegisteredModuleName(const char *plugin, vmk_Name *name);

/*
 ***********************************************************************
 * vmk_ScsiResolveRegisteredPluginDependencies --                 */ /**
 *
 * \brief Resolve all dependencies for module "name".
 *        Dependent Modules may get loaded.
 *
 * \note This function may block.
 *
 * \returns VMK_OK         If all dependencies are resolved.
 *          VMK_NOT_FOUND  If module "name" is not registered.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiResolveRegisteredPluginDependencies(const char *name);

/*
 ***********************************************************************
 * vmk_ScsiCmdGetVMUuid --                                        */ /**
 *
 * \brief Get the UUID of the VM associated with the specified command.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd  Scsi command whose associated VM UUID is queried.
 * \param[out] uuid    Pointer to a buffer to fill in with the UUID.
 * \param[in]  len     Length of the supplied buffer.
 *
 * \returns VMK_OK              uuid updated with the VM UUID.
 *          VMK_NOT_FOUND       VM UUID could not be found.
 *          VMK_NOT_INITIALIZED No VM UUID has been set for this VM.
 *          VMK_BUF_TOO_SMALL   Supplied buffer is too small.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdGetVMUuid(vmk_ScsiCommand *vmkCmd, char *uuid, vmk_ByteCount len);

/*
 ***********************************************************************
 * vmk_ScsiCmdGetSecondLevelLunId --                              */ /**
 *
 * \brief Get the Second-level lun id for specified command.
 *
 * The second level lun id is used to address SCSI target devices that
 * require two levels of addressing.
 *
 * Only 6 most significant bytes of the returned ID are valid.
 * - The 2 least significant bytes of the ID are invalid and should
 *   be 0.
 * - The 1st most significant byte encodes the SAM5 address method,
 *   length, and extended address method.
 * - The next 3 or 5 most significant bytes encode the actual LUN ID.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd  SCSI Command.
 *
 * \returns Second-level lun id or VMK_SCSI_INVALID_SECONDLEVEL_ID if
 *          second-level adressing is not used for the command.
 *
 ***********************************************************************
 */
vmk_ScsiSecondLevelId
vmk_ScsiCmdGetSecondLevelLunId(const vmk_ScsiCommand *vmkCmd);

/*
 ***********************************************************************
 * vmk_ScsiCmdSetSecondLevelLunId --                              */ /**
 *
 * \brief Set the Second-level lun id for specified command.
 *
 * The second level lun id is used to address SCSI target devices that
 * require two levels of addressing. Devices that make use of single
 * level addressing, must not call this API.
 *
 * Only 6 most significant bytes of the Id are valid.
 * - The 2 least significant bytes of the Id are invalid and should
 *   be 0.
 * - The 1st most significant byte encodes the SAM5 address method,
 *   length, and extended address method.
 * - The next 3 or 5 most significant bytes encode the actual
 *   LUN Id.
 *
 * \note This function will not block.
 *
 * \param[in] vmkCmd   SCSI command.
 * \param[in] sllid    Second-level lun id.
 *
 * \retval VMK_OK      Second-level lun id was set for SCSI command,
 *                     error otherwise.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdSetSecondLevelLunId(vmk_ScsiCommand *vmkCmd,
                               vmk_ScsiSecondLevelId sllid);

/*
 ***********************************************************************
 * vmk_ScsiSetPathLostByDevice --                                 */ /**
 *
 * \brief Mark a path as permanently lost by device, triggering PDL
 *
 * Path is identified by \em adaperName, \em channel, \em target
 * and \em lun.
 * This interface updates the path flags in the calling context.
 *
 * \param[in] adapterName  Name of the adapter for state change.
 * \param[in] channel      Channel for state change.
 * \param[in] target       Target for state change.
 * \param[in] lun          LUN for state change. If -1, scan all
 *                         LUNs on the given adapter, channel,
 *                         and target.
 *
 * \retval VMK_OK          Path state successfully updated.
 *
 * \retval VMK_NOT_FOUND   Requested adapter or path was not found.
 *                         This will be returned for a path only when
 *                         a specific \em lun is supplied (not for
 *                         \em lun==-1).
 *
 * \retval VMK_BAD_PARAM   Adapter name is NULL.
 *
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiSetPathLostByDevice(const vmk_Name *adapterName,
                            vmk_int32 channel,
                            vmk_int32 target,
                            vmk_int32 lun);


/*
 ***********************************************************************
 * vmk_ScsiAdapterSetCapabilities  --                             */ /**
 *
 * \brief Set SCSI adapter capabilities.
 *
 * \note This function will not block.
 * \note Must be called before the adapter is registered.
 *
 * \param[in] adapter      Adapter whose capability is to be set.
 * \param[in] capabilities Capabilities to be set.
 *
 * \retval  VMK_OK         Capability mask set for adapter successfully,
 *                         error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiAdapterSetCapabilities(vmk_ScsiAdapter *adapter,
                               vmk_ScsiAdapterCapabilities capabilities);


/*
 ***********************************************************************
 * vmk_ScsiAdapterGetCapabilities  --                             */ /**
 *
 * \brief Get bitmask of enabled adapter capabilities.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkAdapter  Adapter whose capabilities need to be
 *                         retrieved.
 * \param[out] mask        Pointer to capabilities mask buffer.
 *
 * \retval VMK_OK   Successfully retrieved capabilities mask for
 *                  adapter, error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiAdapterGetCapabilities(const vmk_ScsiAdapter *vmkAdapter,
                               vmk_ScsiAdapterCapabilitiesMask *mask);


/*
 ***********************************************************************
 * vmk_ScsiAdapterHasCapabilities  --                             */ /**
 *
 * \brief Verify if adapter has certain capabilities set.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkAdapter        Adapter whose capabilities needs to be
 *                               checked.
 * \param[in]  mask              Capabilities mask to be verified.
 * \param[out] hasCapabilities   Pointer to boolean flag.
 *
 * \retval VMK_OK         Capability check operation was successful,
 *                        error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiAdapterHasCapabilities(const vmk_ScsiAdapter *vmkAdapter,
                               vmk_ScsiAdapterCapabilitiesMask mask,
                               vmk_Bool *hasCapabilities);


/*
 ***********************************************************************
 * vmk_ScsiAdapterSetProtMask  --                                 */ /**
 *
 * \brief Set supported protection types for a SCSI adapter.
 *
 * This interface is used to indicate the protection operations
 * supported by the adapter to the storage stack.
 *
 * DIX (Data Integrity Extensions) support implies data protection is
 * enabled from adapter to OS while an adapter supporting T10 protection
 * types will provide I/O data protection to a device (formatted with
 * similar protection type) from adapter to the target device.
 *
 * \note This function will not block.
 * \note Must be called before the adapter is registered.
 *
 * \param[in]  vmkAdapter     Adapter whose protection types need to
 *                            be set.
 * \param[in]  protTypesMask  Mask of supported protection types.
 *
 * \retval VMK_OK         Setting of protection types was successful,
 *                        error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiAdapterSetProtMask(struct vmk_ScsiAdapter *vmkAdapter,
                           vmk_ScsiProtTypes protTypesMask);


/*
 ***********************************************************************
 * vmk_ScsiAdapterGetProtMask  --                                 */ /**
 *
 * \brief Get supported protection types for a SCSI adapter.
 *
 * This interface is used to get supported data integrity operations by
 * the adapter. The storage stack uses this interface for the following,
 *
 * - Check if DIX (Data Integrity Extensions) operations are supported
 *   by the adapter.
 * - Match SCSI T10 protection type that the target device is formatted
 *   with and the adapter supported protection types.
 *
 *   For data protection from adapter to target, it is necessary that
 *   the target device is formatted with the correct SCSI protection
 *   type that matches with the adapter supported protection types.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkAdapter  Adapter whose supported protection types need
 *                         to be retrieved.
 * \param[out] protMask    Pointer to protection mask buffer.
 *
 * \retval VMK_OK          Successfully retrieved protection mask for
 *                         adapter, error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiAdapterGetProtMask(const struct vmk_ScsiAdapter *vmkAdapter,
                           vmk_ScsiProtTypes *protMask);


/*
 ***********************************************************************
 * vmk_ScsiAdapterSetSupportedGuardTypes  --                      */ /**
 *
 * \brief Set supported guard types for a SCSI adapter.
 *
 * For DIX (Data Integrity Extensions) operations, this interface is
 * used to indicate what guard types the adapter can support (e.g. CRC,
 * IP or both) for the I/O data checksum generation by the OS. Once
 * adapter registration is done, the supported guard types must not be
 * changed by calling this interface again. For T10 PI support, CRC 
 * guard type must be supported by the adapter.
 *
 * \note This function will not block.
 * \note Must be called before the adapter is registered.
 * \note Adapter MUST have set the capability
 *       VMK_SCSI_ADAPTER_CAP_DATA_INTEGRITY before using this vmkAPI
 *       (otherwise it will fail).
 *
 * \param[in]  vmkAdapter  Adapter whose guard type needs to be set.
 * \param[in]  guardTypes  Supported guard types to be set for adapter.
 *
 * \retval VMK_OK          Successfully set guard types for adapter,
 *                         error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiAdapterSetSupportedGuardTypes(struct vmk_ScsiAdapter *vmkAdapter,
                                      vmk_ScsiGuardTypes guardTypes);


/*
 ***********************************************************************
 * vmk_ScsiAdapterGetSupportedGuardTypes  --                      */ /**
 *
 * \brief Get supported guard types for a SCSI adapter.
 *
 * The OS will make use of this interface to determine the guard type
 * (e.g CRC or IP) for checksum generation.
 *
 * For devices supporting SCSI T10 protection types, when DIX (Data
 * Integrity Extension) is supported by the adapter, the OS will attach
 * WRITE I/Os with checksum protection data using the default guard
 * type supported by the adapter. For devices that are not formatted
 * with a SCSI T10 protection type, the adapter will strip off the
 * protection data in the I/O.
 *
 * For DIX-enabled READ I/Os, the adapter must provide the OS protection
 * information in the cmd protection scatter-gather array using the
 * default guard type set by the adapter.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkAdapter  Adapter whose guard types needs to be
 *                         retrieved.
 * \param[out] guardTypes  Pointer to guard type buffer.
 *
 * \retval VMK_OK          Successfully retrieved guard types for
 *                         adapter, error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiAdapterGetSupportedGuardTypes(const struct vmk_ScsiAdapter *vmkAdapter,
                                      vmk_ScsiGuardTypes *guardTypes);


/*
 ***********************************************************************
 * vmk_ScsiCmdGetProtOps  --                                      */ /**
 *
 * \brief Get protection operation type for the given SCSI command.
 *
 * This interface is used by the adapter to get the operations to be
 * performed on the protection data for a specific SCSI command.
 *
 * For SCSI T10 protection formatted devices, the OS generates the
 * protection data for WRITEs and receives protection data from the
 * target device for READs. The OS indicates adapter operation to be
 * performed for a given I/O based on the following,
 *
 * - SCSI T10 protection type supported by device and adapter.
 * - DIX support by adapter.
 *
 * If the device protection type is not supported by the adapter, then
 * the adapter will be asked to STRIP the protection data for every
 * WRITE I/O and INSERT the protection data for every READ I/O.
 *
 * Similarly, if DIX is not supported by the adapter, it will be
 * instructed to INSERT protection data for WRITEs and to STRIP
 * protection data for READs.
 *
 * If there are no dissimilarities between supported protection types
 * and DIX is supported by the adapter, the instruction will be to PASS
 * the protection data.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd   SCSI command for which the protection operation
 *                      type needs to be retrieved.
 * \param[out] protOps  Pointer to protection operation type buffer.
 *
 * \retval VMK_OK       Successfully retrieved protection operation type
 *                      for SCSI command, error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdGetProtOps(const vmk_ScsiCommand *vmkCmd,
                      vmk_ScsiCommandProtOps *protOps);


/*
 ***********************************************************************
 * vmk_ScsiCmdSetTargetProtType  --                               */ /**
 *
 * \brief Set target SCSI T10 protection type for the SCSI command.
 *
 * This interface is used to set the SCSI T10 protection type in the
 * SCSI command. The OS uses this interface to set the type to the one
 * supported by the target device.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd    SCSI command for which the protection type
 *                       needs to be set.
 * \param[in]  protType  SCSI T10 protection type.
 *
 * \retval VMK_OK        Successfully set protection type for SCSI
 *                       command, error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdSetTargetProtType(vmk_ScsiCommand *vmkCmd,
                             vmk_ScsiTargetProtTypes protType);


/*
 ***********************************************************************
 * vmk_ScsiCmdGetTargetProtType  --                               */ /**
 *
 * \brief Get target SCSI T10 protection type for the SCSI command.
 *
 * For devices formatted with a SCSI T10 protection type, the adapter
 * driver can use this interface to determine the protection type in the
 * protection data. The protection type is set by the OS for a SCSI
 * command, based on what is supported by the target device.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd    SCSI command for which the SCSI T10 protection
 *                       type needs to be retrieved.
 * \param[out] protType  Pointer to protection type buffer.
 *
 * \retval VMK_OK       Successfully retrieved protection type for SCSI
 *                      command, error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdGetTargetProtType(const vmk_ScsiCommand *vmkCmd,
                             vmk_ScsiTargetProtTypes *protType);


/*
 ***********************************************************************
 * vmk_ScsiCmdSetProtSgArray  --                                  */ /**
 *
 * \brief Sets the protection scatter-gather array for the SCSI command.
 *
 * The OS uses this interface to set the protection data for a given
 * SCSI command.
 *
 * For WRITE I/Os, the data format in this scatter-gather array depends
 * on the target device protection type and the adapter supported
 * guard type.
 *
 * For READ I/Os, the OS will use this interface to pass the
 * uninitialzed scatter-gather array that will subsequently be set by
 * the adapter.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd        SCSI command for which the protection
 *                           scatter-gather array needs to be set.
 * \param[in]  sgProtArray   protection scatter-gather array.
 *
 * \retval VMK_OK       Successfully set protection scatter-gather
 *                      array for SCSI command, error otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdSetProtSgArray(vmk_ScsiCommand *vmkCmd,
                          vmk_SgArray *sgProtArray);


/*
 ***********************************************************************
 * vmk_ScsiCmdGetProtSgArray  --                                  */ /**
 *
 * \brief Gets the protection scatter-gather array for the SCSI command.
 *
 * This interface is used by software drivers to get the protection
 * data sgArray for a SCSI command.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd   SCSI command for which the protection
 *                      scatter-gather array needs to be retrieved.
 *
 * \retval  Returns the protection scatter-gather array element for the
 *          given SCSI command.
 ***********************************************************************
 */
vmk_SgArray*
vmk_ScsiCmdGetProtSgArray(const vmk_ScsiCommand *vmkCmd);


/*
 ***********************************************************************
 * vmk_ScsiCmdGetProtSgIOArray  --                                */ /**
 *
 * \brief Gets the DMA-mapped protection sgArray for the SCSI command.
 *
 * This interface is used to get the DMA mapped protection IO data
 * scatter-gather array for the given SCSI command. Drivers can use this
 * interface to get the protection data and send it to their hardware.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd   SCSI command for which the DMA-mapped protection
 *                      scatter-gather array needs to be retrieved.
 *
 * \retval  Returns the DMA-mapped protection scatter-gather array
 *          element for the given SCSI command.
 ***********************************************************************
 */
vmk_SgArray*
vmk_ScsiCmdGetProtSgIOArray(const vmk_ScsiCommand *vmkCmd);

/*
 ***********************************************************************
 * vmk_ScsiCmdSetProtSgIOArray  --                                */ /**
 *
 * \brief Sets DMA-mapped protection sgArray for the SCSI command.
 *
 * This interface is used to set the DMA-mapped protection IO data
 * scatter-gather array for a given SCSI command.
 *
 * \note This function will not block.
 *
 * \param[in]  vmkCmd          SCSI command for which the protection
 *                             scatter-gather array needs to be set.
 * \param[in]  sgProtIOArray   protection scatter-gather array.
 *
 * \retval VMK_OK       Successfully set the DMA-mapped protection
 *                      scatter-gather array for SCSI command, error
 *                      otherwise.
 ***********************************************************************
 */
VMK_ReturnStatus
vmk_ScsiCmdSetProtSgIOArray(vmk_ScsiCommand *vmkCmd,
                            vmk_SgArray *sgProtIOArray);


/*
 ***********************************************************************
 * vmk_ScsiSchedCommandCompletion --                              */ /**
 *
 * \brief Schedules a non-blocking context to complete the command.
 *
 * This function schedules a non-blocking context to complete a
 * command. The intent is to use this from the issuing path where
 * a command cannot be completed directly since that could lead to
 * stack exhaustion due to recursive calls to the issuing path from
 * the completion path.
 *
 * \note This is a non-blocking call.
 *
 * \note Spin locks can be held while calling into this function
 *
 * \param[in] command   The cmd to complete.
 *
 ***********************************************************************
 */
void vmk_ScsiSchedCommandCompletion(
   vmk_ScsiCommand *command);

/*
 ***********************************************************************
 * vmk_ScsiIsCommandVmIo  --                                   */ /**
 *
 * \brief Determine whether a vmk_ScsiCommand is VM IO.
 *
 * This function checks if the command is from a VM.
 *
 * \note This function will not block.
 *
 * \param[in] vmkCmd vmk_ScsiCommand command to check
 *
 * \retval VMK_TRUE  vmkCmd is VM IO
 * \retval VMK_FALSE vmkCmd is not VM IO
 *
 ***********************************************************************
 */
vmk_Bool
vmk_ScsiIsCommandVmIo(vmk_ScsiCommand *vmkCmd);

#endif  /* _VMKAPI_SCSI_H_ */
/** @} */
/** @} */