Files
@ 052c0cbc4bbf
Branch filter:
Location: vmkdrivers/vmkdrivers/src_9/vmklinux_9/vmware/linux_scsi_vmk_if.c
052c0cbc4bbf
63.0 KiB
text/x-csrc
ESXi-5.0-U3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 | /*
* ****************************************************************
* Portions Copyright 1998, 2010 VMware, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* ****************************************************************/
/*
* linux_scsi_vmk_if.c --
*
* Interface functions that deal with vmkernel storage stack.
*/
#include <scsi/scsi.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_tcq.h>
#include <scsi/scsi_transport.h>
#include <scsi/scsi_transport_fc.h>
#include <scsi/scsi_transport_sas.h>
#include <vmklinux_9/vmklinux_scsi.h>
#include "vmkapi.h"
#include "linux_stubs.h"
#include "linux_scsi.h"
#include "linux_scsi_transport.h"
#include "linux_stress.h"
#include "linux_stubs.h"
#define VMKLNX_LOG_HANDLE LinScsiVmk
#include "vmklinux_log.h"
/*
* Externs
*/
extern struct list_head linuxBHCommandList;
extern vmk_SpinlockIRQ linuxSCSIBHLock;
/*
* Static
*/
static vmk_AdapterStatus SCSILinuxAdapterStatus(void *vmkAdapter);
static vmk_RescanLinkStatus SCSILinuxRescanLink(void *vmkAdapter);
static vmk_FcLinkSpeed FcLinuxLinkSpeed(void *vmkAdapter);
static vmk_uint64 FcLinuxAdapterPortName(void *vmkAdapter);
static vmk_uint64 FcLinuxAdapterNodeName(void *vmkAdapter);
static vmk_uint32 FcLinuxAdapterPortId(void *vmkAdapter);
static vmk_FcPortType FcLinuxAdapterPortType(void *vmkAdapter);
static vmk_FcPortState FcLinuxAdapterPortState(void *vmkAdapter);
static VMK_ReturnStatus FcLinuxTargetAttributes(void *vmkAdapter,
vmk_FcTargetAttrs *vmkFcTarget,
vmk_uint32 channelNo, vmk_uint32 targetNo);
static vmk_uint64 SasLinuxInitiatorAddress(void *pAdapter);
static VMK_ReturnStatus SasLinuxTargetAttributes(void *pAdapter,
vmk_SasTargetAttrs *sasAttrib,
vmk_uint32 channelNo, vmk_uint32 targetNo);
static void FcLinuxPopulateCB(vmk_FcAdapter *pFcAdapter);
static VMK_ReturnStatus
FCOELinuxAdapterAttributes(void *pAdapter, vmk_FcoeAdapterAttrs *fcoeAttrs);
/*
*----------------------------------------------------------------------
*
* SCSILinuxDiscover --
*
* Create/Configure/Destroy a new paths
*
* Results:
* VMK_OK Success
* Other An error occured
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxDiscover(void *clientData, vmk_ScanAction action,
int channel, int target, int lun,
void **deviceData)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26ScsiAdapter->shost;
vmk_ScsiAdapter *vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
struct scsi_device *sdev;
VMK_ReturnStatus status;
VMK_ASSERT(sh);
VMK_ASSERT(sh->transportt);
switch (action) {
case VMK_SCSI_SCAN_CREATE_PATH: {
VMKLNX_DEBUG(5, "Create path %s:%d:%d:%d",
vmk_ScsiGetAdapterName(vmkAdapter), channel, target, lun);
status = SCSILinuxCreatePath(sh, channel, target, lun, &sdev);
if (status == VMK_OK) {
break;
} else {
return status;
}
break;
}
case VMK_SCSI_SCAN_CONFIGURE_PATH: {
VMKLNX_DEBUG(5, "Keep path %s:%d:%d:%d",
vmk_ScsiGetAdapterName(vmkAdapter), channel, target, lun);
status = SCSILinuxConfigurePath(sh, channel, target, lun);
return status;
}
case VMK_SCSI_SCAN_DESTROY_PATH: {
VMKLNX_DEBUG(5, "Destroy path %s:%d:%d:%d",
vmk_ScsiGetAdapterName(vmkAdapter), channel, target, lun);
status = SCSILinuxDestroyPath(sh, channel, target, lun);
if (status == VMK_OK) {
sdev = NULL;
} else {
return status;
}
break;
}
default:
VMKLNX_WARN("Unknown path discover request %s:%d:%d:%d",
vmk_ScsiGetAdapterName(vmkAdapter), channel, target, lun);
VMK_ASSERT(FALSE);
return VMK_NOT_IMPLEMENTED;
}
*deviceData = (void *)sdev;
return VMK_OK;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxCommand --
*
* Process a SCSI command.
*
* Results:
* VMK_OK if the IO was sent successfully.
* Error code otherwise.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxCommand(void *clientData, vmk_ScsiCommand *vmkCmdPtr,
void *deviceData)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26ScsiAdapter->shost;
struct scsi_device *sdev = (struct scsi_device *) deviceData;
if (sdev == NULL) {
VMK_ASSERT(sdev);
return VMK_FAILURE;
}
/* Never issue a command to the host ID */
VMK_ASSERT(sdev->id != sh->this_id);
if (VMKLNX_STRESS_DEBUG_COUNTER(stressScsiAdapterIssueFail)) {
VMKLNX_DEBUG(1, "SCSI_ADAPTER_ISSUE_FAIL Stress Counter Triggered");
return VMK_WOULD_BLOCK;
}
VMK_ASSERT((vmkCmdPtr->sgIOArray != NULL) ||
(vmkCmdPtr->dataDirection == VMK_SCSI_COMMAND_DIRECTION_NONE) ||
(vmkCmdPtr->requiredDataLen == 0));
return SCSILinuxQueueCommand(sh, sdev, vmkCmdPtr);
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxProcInfo --
*
* Call proc handler for the given SCSI host adapter.
*
* Results:
* VMK_OK on success, VMK_FAILURE if proc handler fails.
* VMK_NOT_SUPPORTED if host template has no proc handler.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxProcInfo(void *clientData,
char* buf,
vmk_ByteCountSmall offset,
vmk_ByteCountSmall count,
vmk_ByteCountSmall *nbytes,
int isWrite)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26ScsiAdapter->shost;
if (sh->hostt) {
if (sh->hostt->proc_info) {
char *start = buf;
VMKLNX_DEBUG(5, "off=%d count=%d", offset, count);
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(sh), *nbytes, sh->hostt->proc_info,
sh, buf, &start, offset, count, isWrite);
VMK_ASSERT(start == buf || *nbytes == 0);
if ((int32_t)*nbytes < 0) {
VMKLNX_DEBUG(5, "failed %d", *nbytes);
return VMK_FAILURE;
}
/*
* We don't support proc nodes that generate one page of data or more
*/
VMK_ASSERT(*nbytes <= count);
VMKLNX_DEBUG(2, "nbytes=%d", *nbytes);
return VMK_OK;
} else if (!isWrite) {
if (sh->hostt->info) {
const char *tmp_info;
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(sh), tmp_info, sh->hostt->info, sh);
*nbytes = snprintf(buf, count, "%s\n", tmp_info);
} else {
*nbytes = snprintf(buf, count,
"The driver does not yet support the proc-fs\n");
}
buf[count - 1] = '\0';
/*
* We don't support proc nodes that generate one page of data or more
*/
VMK_ASSERT(*nbytes <= count);
if (*nbytes < offset) {
*nbytes = 0;
}
return VMK_OK;
}
}
*nbytes = 0;
return VMK_NOT_SUPPORTED;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxClose --
*
* Close the SCSI device.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
SCSILinuxClose(void *clientData)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26ScsiAdapter->shost;
if (sh->hostt->release != NULL) {
/*
* This function should only be called if we are unloading the vmkernel.
* The module cleanup code is going to release this scsi adapter
* also.
*/
VMKLNX_DEBUG(0, "Releasing adapter");
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(sh), sh->hostt->release, sh);
} else {
VMKLNX_DEBUG(0, "No release function. Manually unload");
}
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxIoctl --
*
* Special ioctl commands.
*
* Results:
* VMK_OK - success, (Driver retval in out arg)
* VMK_NOT_SUPPORTED - no ioctl() for this driver.
* VMK_INVALID_TARGET - coudln't find device<target,lun>,
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxIoctl(void *clientData, // IN:
void *deviceData, // IN:
uint32_t fileFlags, // IN: ignored for SCSI ioctls
uint32_t cmd, // IN:
vmk_VA userArgsPtr, // IN/OUT:
vmk_IoctlCallerSize callerSize, // IN: ioctl caller size
int32_t *drvErr) // OUT: error returned by driver.
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26ScsiAdapter->shost;
struct scsi_device *sdev = (struct scsi_device *) deviceData;
int done;
VMKLNX_DEBUG(1, "start");
if (sh == NULL
|| sh->hostt == NULL
|| sh->hostt->ioctl == NULL) {
return VMK_NOT_SUPPORTED; /* most likely the third test failed. */
}
if (sdev == NULL) {
return VMK_INVALID_TARGET;
}
mutex_lock(&vmklnx26ScsiAdapter->ioctl_mutex);
done = 0;
if (callerSize == VMK_IOCTL_CALLER_32 && sh->hostt->compat_ioctl) {
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(sh), *drvErr, sh->hostt->compat_ioctl,
sdev, cmd, (void *)userArgsPtr);
if (*drvErr != -ENOIOCTLCMD) {
done = 1;
}
}
if (!done) {
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(sh), *drvErr, sh->hostt->ioctl,
sdev, cmd, (void *)userArgsPtr);
}
mutex_unlock(&vmklnx26ScsiAdapter->ioctl_mutex);
VMKLNX_DEBUG(1, "ret=%d", *drvErr);
return VMK_OK;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxQueryDeviceQueueDepth
*
* Result:
* This returns the queue depth set by the device.
*
* Side effects:
* None
*----------------------------------------------------------------------
*/
int
SCSILinuxQueryDeviceQueueDepth(void *clientData,
void *deviceData)
{
struct scsi_device *sdev = (struct scsi_device *) deviceData;
VMK_ASSERT(sdev);
/*
* We pass in clientData (aka vmklnx_ScsiAdapter) just in case
* we need it in the future.
*/
clientData = clientData;
return sdev ? sdev->queue_depth : 0;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxModifyDeviceQueueDepth
*
* If possible set a new queue depth.
*
* Result:
* This returns the queue depth set by the device.
*
* Side effects:
* None
*----------------------------------------------------------------------
*/
int
SCSILinuxModifyDeviceQueueDepth(void *clientData,
int qDepth,
void *deviceData)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26ScsiAdapter->shost;
struct scsi_device *sdev = (struct scsi_device *) deviceData;
VMK_ASSERT(sdev);
if (sdev == NULL) {
return 0;
}
/*
* Check if the drivers can set the new queue depth
* else, return the current queue depth
*/
if (sh->hostt->change_queue_depth) {
int ret;
/*
* Most drivers will turn around and call scsi_adjust_queue_depth here
* So be careful about reentrant code
*/
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(sh), ret, sh->hostt->change_queue_depth,
sdev, qDepth);
}
return sdev->queue_depth;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxDumpCommand --
*
* Queue up a SCSI command when dumping.
*
* Results:
* VMK_OK - cmd queued;
* VMK_FAILURE - couldn't queue cmd;
* VMK_WOULD_BLOCK - device queue full or host not accepting cmds;
* VMK_BUSY - eh active.
*
* Side effects:
* No one else can issue commands to this device anymore.
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxDumpCommand(void *clientData,
vmk_ScsiCommand *vmkCmdPtr,
void *deviceData)
{
struct vmklnx_ScsiAdapter *vmklnx26_ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26_ScsiAdapter->shost;
struct scsi_cmnd *scmd;
struct scsi_device *sdev = (struct scsi_device *) deviceData;
unsigned long flags;
int status = 0;
void *dump_done_fn = SCSILinuxDumpCmdDone;
static struct scsi_cmnd dump_scmd;
struct scatterlist *sg;
VMK_ASSERT(sdev);
if (sdev == NULL) {
VMKLNX_ALERT("Invalid sdev ptr during dump");
return VMK_FAILURE;
}
scmd = &dump_scmd;
memset(scmd, 0, sizeof(*scmd));
/*
* Fill in values required for dump command
*/
scmd->device = sdev;
SCSILinuxInitCommand(sdev, scmd);
scmd->done = dump_done_fn;
if (scmd->device->tagged_supported) {
scmd->tag = SIMPLE_QUEUE_TAG;
} else {
scmd->tag = 0;
}
/* Never issue a command to the host ID */
VMK_ASSERT(sdev->id != sh->this_id);
spin_lock_irqsave(sh->host_lock, flags);
sdev->dumpActive = 1;
/*
* First, make sure dumpCmd can be queued.
*/
if (scsi_host_in_recovery(sh)) {
VMKLNX_ALERT("In error recovery - %d", sh->shost_state);
}
if (sh->host_self_blocked
|| (sdev->device_busy == sdev->queue_depth)
|| (sh->host_busy == sh->can_queue)) {
VMKLNX_DEBUG(0, "devcif=%u depth=%u hostcif=%u "
"can_queue=%d self_blocked=%u",
sdev->device_busy, sdev->queue_depth,
sh->host_busy, sh->can_queue,
sh->host_self_blocked);
spin_unlock_irqrestore(sh->host_lock, flags);
return VMK_WOULD_BLOCK;
}
++scmd->device->host->host_busy;
++sdev->device_busy;
spin_unlock_irqrestore(sh->host_lock, flags);
/*
* should never fail unless someone changes SCSI_Dump
*/
VMK_ASSERT(vmkCmdPtr->sgArray->numElems == 1);
/*
* We should only get one element here
* XXX PR 688894 - USB relies on having only one element in the sg list
*/
memcpy(scmd->cmnd, vmkCmdPtr->cdb, vmkCmdPtr->cdbLen);
sg = scmd->vmksg;
VMKLNX_INIT_VMK_SG_WITH_ARRAYS(sg, vmkCmdPtr->sgArray, vmkCmdPtr->sgIOArray);
VMK_ASSERT(vmkCmdPtr->sgIOArray->numElems == 1);
scmd->use_sg = vmkCmdPtr->sgIOArray->numElems;
scmd->request_bufflen = vmkCmdPtr->sgIOArray->elem[0].length;
scmd->request_buffer = sg;
scmd->request_bufferMA = 0;
scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
scmd->vmkCmdPtr = vmkCmdPtr;
scmd->underflow = scmd->request_bufflen;
scmd->sc_data_direction = SCSILinuxGetDataDirection(scmd,
vmkCmdPtr->dataDirection);
VMK_ASSERT(valid_dma_direction(scmd->sc_data_direction));
/*
* Mark this as Dump Request
* We don't need to hold vmk_lock, because
* - no one has access to scmd at this point other than us
* Moreover,
* - dump path uses static data structures and can't be multithreaded
* - at this point, all the other CPUs have come to rest already
*/
scmd->vmkflags = VMK_FLAGS_NEED_CMDDONE | VMK_FLAGS_DUMP_REQUEST;
spin_lock_irqsave(sh->host_lock, flags);
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(sh), status, sh->hostt->queuecommand,
scmd, dump_done_fn);
spin_unlock_irqrestore(sh->host_lock, flags);
if (unlikely(status)) {
VMKLNX_ALERT("queuecommand failed with status = 0x%x %s",
status, vmk_StatusToString(status));
return VMK_FAILURE;
} else {
return VMK_OK;
}
}
#define VM_NAME_ARRAY_FILL_CHAR 0xFF
/*
*----------------------------------------------------------------------
*
* SCSILinuxVportOp --
*
* Entry point in vmklinux module for doing virtual link ops.
* Converts arguments to the appropriate form for the NPIV aware
* driver, and calls the driver's fc_transport NPIV handler entry
* points as needed. The interface used is based on Linux 2.6.23.
*
* Results:
* VMK_OK - success, (Driver retval in out arg)
* VMK_NOT_SUPPORTED - no NPIV support for this driver.
* VMK_FAILURE - for all driver related errors
*
* Side effects:
* When executing the VMK_VPORT_CREATE command, the driver will
* call scsi_add_host() to add the VPORT.
* When executing the VMK_VPORT_DELETE command, the driver will
* call scsi_remove_host() to remove the VPORT.
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxVportOp(void *clientData, // IN:
uint32_t cmd, // IN:
void *args, // IN/OUT:
int *drvErr) // OUT: error returned by driver.
{
struct Scsi_Host *shp, *shost;
vmk_ScsiVportArgs *vmkargs;
struct vmk_VportData data;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
vmk_ScsiAdapter *vmkAdapter;
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *)clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shp = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shp);
vmkargs = (vmk_ScsiVportArgs *) args;
VMK_ASSERT(vmkargs);
VMKLNX_DEBUG(5, "SCSILinuxVportOp: client=%p, host=%p, cmd=0x%x, uargs=%p",
clientData, shp, cmd, (void *)vmkargs);
if (shp == NULL
|| shp->transportt == NULL ||
shp->adapter == NULL) {
*drvErr = -1;
return VMK_NOT_SUPPORTED;
}
// need further checks for NPIV to work
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
if (vmkAdapter->mgmtAdapter.transport != VMK_STORAGE_ADAPTER_FC) {
*drvErr = -1;
return VMK_NOT_SUPPORTED;
}
switch (cmd) {
case VMK_VPORT_CREATE:
{
struct vmk_ScsiAdapter *aPhys, *aVport;
VMKLNX_DEBUG(2, "SCSILinuxVportOp: VMK_VPORT_CREATE: data=%p, args=%p",
(void *)&data, (void *)vmkargs->arg);
memset(&data, 0, sizeof(struct vmk_VportData));
memcpy(&data.node_name, &vmkargs->wwnn, sizeof(vmkargs->wwnn));
memcpy(&data.port_name, &vmkargs->wwpn, sizeof(vmkargs->wwpn));
if ((vmkargs->name != NULL) &&
((unsigned char)vmkargs->name[0] != VM_NAME_ARRAY_FILL_CHAR)) {
size_t nameLen;
nameLen = strlen(vmkargs->name);
if (nameLen >= sizeof data.symname) {
return VMK_NAME_TOO_LONG;
}
memcpy(&data.symname, vmkargs->name, nameLen + 1);
}
// not used yet...
data.role_id = VMK_VPORT_ROLE_FCP_INITIATOR;
// finally set the api version for drivers use
data.api_version = VMK_VPORT_API_VERSION;
// transfer legacy/creation status
data.options = vmkargs->flags;
*drvErr = vmk_fc_vport_create(shp, 0, scsi_get_device(shp), &data);
if (*drvErr) {
goto handle_driver_error;
}
vmkargs->virthost = data.vport_shost;
VMK_ASSERT(vmkargs->virthost);
aPhys = vmklnx26ScsiAdapter->vmkAdapter; // Physical hba
shost = (struct Scsi_Host *)vmkargs->virthost;
vmklnx26ScsiAdapter = shost->adapter; // Vport's lnxscsi adapter
aVport = vmklnx26ScsiAdapter->vmkAdapter; // Vport hba
vmkargs->virtAdapter = aVport;
// set the pae flag to match the physical hba
aVport->paeCapable = aPhys->paeCapable;
// set the sg fields from the physical hba
aVport->constraints.sgElemSizeMult = aPhys->constraints.sgElemSizeMult;
aVport->constraints.sgElemAlignment = aPhys->constraints.sgElemAlignment;
scsi_scan_host(data.vport_shost);
}
break;
case VMK_VPORT_DELETE:
VMKLNX_DEBUG(2, "SCSILinuxVportOp: VMK_VPORT_DELETE: virthost=%p, shp=%p",
(void *)vmkargs->virthost, (void *)shp);
*drvErr = vmk_fc_vport_delete(vmkargs->virthost);
break;
case VMK_VPORT_INFO:
{
void *host;
if (vmkargs->virthost) {
// use virtual host if passed
host = vmkargs->virthost;
}
else {
// otherwise, use the physical host
host = shp;
}
VMKLNX_DEBUG(5, "SCSILinuxVportOp: VMK_VPORT_INFO: host=%p, args=%p",
(void *)host, (void *)vmkargs->arg);
// the returned structure is already allocated by the vmkernel
*drvErr = vmk_fc_vport_getinfo(host, vmkargs->arg);
VMKLNX_DEBUG(5, "SCSILinuxVportOp: drvErr %x", *drvErr);
}
break;
case VMK_VPORT_SUSPEND:
VMKLNX_DEBUG(2, "SCSILinuxVportOp: VMK_VPORT_SUSPEND:"
" virthost=%p, shp=%p, flags=%x",
(void *)vmkargs->virthost, (void *)shp, vmkargs->flags);
*drvErr = vmk_fc_vport_suspend(vmkargs->virthost,
(vmkargs->flags & 1));
break;
default:
*drvErr = -ENOENT;
return VMK_NOT_SUPPORTED;
}
handle_driver_error:
switch(*drvErr) {
case 0:
return VMK_OK;
case -ENOENT:
// NPIV not support by this driver
return VMK_NOT_SUPPORTED;
case -ENOMEM:
// out of memory
return VMK_NOT_SUPPORTED;
case -ENOSPC:
// no more vports
return VMK_NOT_SUPPORTED;
default:
return VMK_FAILURE;
}
return VMK_OK;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxVportUpdate
*
* Stub called by scsi_add_host to handle updating the vport with
* scsi host data
*
*----------------------------------------------------------------------
*/
void SCSILinuxVportUpdate(void *clientdata, void *device)
{
struct Scsi_Host *sh;
struct device *dev;
struct fc_vport *vport;
sh = (struct Scsi_Host *) clientdata;
dev = (struct device *)device;
vport = dev_to_vport(dev);
vport->vhost = sh;
if (vport->flags & FC_VPORT_LEGACY) {
// set the vmkadapter flag
((vmk_ScsiAdapter*)sh->vmkAdapter)->flags |=
VMK_SCSI_ADAPTER_FLAG_NPIV_LEGACY_VPORT;
}
}
#define VPORT_DISCOVERY_RETRY_COUNT 10
#define VPORT_DISCOVERY_DELAY_COUNT 2000000 // delay in us = 2 sec
/*
*----------------------------------------------------------------------
*
* SCSILinuxVportDiscover
*
* Special front-end for SCSIScanPaths used to scan LUNs on a VPORT and
* delete vport related paths
*
* Result:
* See SCSIScanPaths
*
* Side Effects:
* Creates the LUN path if it is not found
* vmkAdapter is set to the correct pointer
* deviceData is set to the vmklnx_ScsiAdapter pointer
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxVportDiscover(void *clientData, vmk_ScanAction action,
int ctlr, int devNum, int lun,
vmk_ScsiAdapter **vmkAdapter,
void **deviceData)
{
struct Scsi_Host *hostPtr;
vmk_ScsiAdapter *adapter;
struct scsi_device *dp;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
VMK_ReturnStatus status;
uint32_t retryCount = 0;
unsigned long flags;
// Scsi_host pointer is passed
hostPtr = (struct Scsi_Host *)clientData;
VMK_ASSERT(hostPtr);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *)hostPtr->adapter;
VMK_ASSERT(vmklnx26ScsiAdapter);
adapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(adapter);
switch (action) {
case VMK_SCSI_SCAN_CREATE_PATH: {
VMKLNX_DEBUG(2, "SCSILinuxVportDiscover: client=%p, host=%p, adapter=%p",
clientData, hostPtr, adapter);
VMKLNX_DEBUG(1, "VPORT Adapter name=%s [%p]", vmk_NameToString(&adapter->name),
adapter);
if (vmkAdapter) {
*vmkAdapter = adapter;
}
/*
* scsi_device_lookup takes a reference on the scsi_device and that
* reference is released as part of VMK_SCSI_SCAN_DESTROY_PATH for
* vport devices
*/
if ((devNum != VMK_SCSI_PATH_ANY_TARGET) && (lun != VMK_SCSI_PATH_ANY_LUN)) {
dp = scsi_device_lookup(hostPtr, ctlr, devNum, lun);
if (dp) {
if (deviceData) {
*deviceData = dp;
}
// don't scan if the lun already exist
return VMK_OK;
}
}
vmk_WorldAssertIsSafeToBlock();
while (((status = vmk_ScsiScanPaths(&adapter->name,
ctlr, devNum, lun)) ==
VMK_BUSY) && (retryCount++ < VPORT_DISCOVERY_RETRY_COUNT)) {
vmk_WorldSleep(VPORT_DISCOVERY_DELAY_COUNT);
VMKLNX_DEBUG(1, "Retrying vmk_ScsiScanPaths %dth"
" time on VPORT Adapter name=%s [%p]",
retryCount, vmk_NameToString(&adapter->name),
adapter);
}
if ((status == VMK_BUSY) && (retryCount >= VPORT_DISCOVERY_RETRY_COUNT)) {
VMKLNX_WARN("Failed Discovery on VPORT Adapter name=%s [%p] with error: %d",
vmk_NameToString(&adapter->name), adapter, status);
return status;
}
if ((devNum != VMK_SCSI_PATH_ANY_TARGET) && (lun != VMK_SCSI_PATH_ANY_LUN)) {
// If this is for a specific LUN/TARGET, see if LUN is really found
dp = scsi_device_lookup(hostPtr, ctlr, devNum, lun);
if (dp) {
if (deviceData) {
*deviceData = dp;
}
return VMK_OK;
}
}
else {
return VMK_OK;
}
// LUN was not found, return failure
return VMK_NOT_FOUND;
}
case VMK_SCSI_SCAN_DESTROY_PATH: {
VMKLNX_DEBUG(2, "Destroy vport path %s:%d:%d:%d deviceData=%p",
vmk_NameToString(&adapter->name), ctlr, devNum,
lun, *deviceData);
spin_lock_irqsave(hostPtr->host_lock, flags);
dp = __scsi_device_lookup(hostPtr, ctlr, devNum, lun);
spin_unlock_irqrestore(hostPtr->host_lock, flags);
if (dp && (*deviceData != NULL)) {
/*
* Release reference that was taken while doing SCSI_SCAN_CREATE_PATH
* operation as part of vport discovery.
*/
scsi_device_put(dp);
}
status = SCSILinuxDestroyPath(hostPtr, ctlr, devNum, lun);
return status;
break;
}
case VMK_SCSI_SCAN_CONFIGURE_PATH:
// This is not used, added to make compiler happy
default:
VMKLNX_WARN("Unknown path discover request %s:%d:%d:%d",
vmk_NameToString(&adapter->name), ctlr, devNum, lun);
VMK_ASSERT(FALSE);
return VMK_NOT_IMPLEMENTED;
}
// Return failure if we reach here
return VMK_FAILURE;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxTaskMgmt --
*
* Process a task managemnet request.
*
* Results:
* VMK_OK
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxTaskMgmt(void *clientData, vmk_ScsiTaskMgmt *vmkTaskMgmt,
void *deviceData)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26ScsiAdapter->shost;
struct scsi_device *sdev = (struct scsi_device *) deviceData;
VMK_ReturnStatus status = VMK_FAILURE;
unsigned long flags;
VMK_ASSERT(sdev);
/* Never issue a command to the host ID */
VMK_ASSERT(sdev->id != sh->this_id);
VMKLNX_DEBUG(4, "Start processing %s of "
"initiator:%p S/N:%#"VMK_FMT64"x on "
SCSI_PATH_NAME_FMT,
vmk_ScsiGetTaskMgmtTypeName(vmkTaskMgmt->type),
vmkTaskMgmt->cmdId.initiator, vmkTaskMgmt->cmdId.serialNumber,
SCSI_PATH_NAME(sh, sdev->channel, sdev->id, sdev->lun));
switch (vmkTaskMgmt->type) {
case VMK_SCSI_TASKMGMT_ABORT:
status = SCSILinuxAbortCommands(sh, sdev, vmkTaskMgmt);
break;
case VMK_SCSI_TASKMGMT_LUN_RESET:
case VMK_SCSI_TASKMGMT_DEVICE_RESET:
case VMK_SCSI_TASKMGMT_BUS_RESET:
/*
* Set the state to recovery, some of the drivers dont like to
* receive commands at this time. See PR236958 for more info
*/
atomic_inc(&vmklnx26ScsiAdapter->tmfFlag);
spin_lock_irqsave(sh->host_lock, flags);
sh->shost_state = SHOST_RECOVERY;
spin_unlock_irqrestore(sh->host_lock, flags);
/*
* Destructive reset
*/
status = SCSILinuxResetCommand(sh, sdev, vmkTaskMgmt);
/*
* Set the state back to normal
*/
if (atomic_dec_and_test(&vmklnx26ScsiAdapter->tmfFlag)) {
spin_lock_irqsave(sh->host_lock, flags);
sh->shost_state = SHOST_RUNNING;
spin_unlock_irqrestore(sh->host_lock, flags);
}
break;
case VMK_SCSI_TASKMGMT_VIRT_RESET:
status = SCSILinuxAbortCommands(sh, sdev, vmkTaskMgmt);
break;
default:
VMKLNX_WARN("Unknown task management type 0x%x", vmkTaskMgmt->type);
VMK_ASSERT(FALSE);
}
VMKLNX_DEBUG(4, "Done");
return status;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxDumpQueue --
*
* Dump Queue details.
*
* Results:
* None
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
SCSILinuxDumpQueue(void *clientData)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *sh = vmklnx26ScsiAdapter->shost;
struct scsi_device *sdev;
struct scsi_cmnd *scmd;
unsigned long flags, cmdFlags;
VMK_ASSERT(sh);
spin_lock_irqsave(sh->host_lock, flags);
shost_for_each_device(sdev, sh) {
spin_lock_irqsave(&sdev->list_lock, cmdFlags);
list_for_each_entry(scmd, &sdev->cmd_list, list) {
VMKLNX_DEBUG(3, "%p", scmd);
}
spin_unlock_irqrestore(&sdev->list_lock, cmdFlags);
}
spin_unlock_irqrestore(sh->host_lock, flags);
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxCheckTarget --
*
* Check if a Target exists
*
* Results:
* VMK_OK if the Target exists.
* Error code otherwise.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
SCSILinuxCheckTarget(void *clientData,
int channelNo, int targetNo)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) clientData;
struct Scsi_Host *shost;
unsigned long flags;
struct scsi_target *sTarget;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
spin_lock_irqsave(shost->host_lock, flags);
sTarget = vmklnx_scsi_find_target(shost, channelNo, targetNo);
spin_unlock_irqrestore(shost->host_lock, flags);
if (!sTarget) {
VMKLNX_DEBUG(5, "No Valid targets bound (channel %d, target %d)",
channelNo, targetNo);
return VMK_FAILURE;
}
return VMK_OK;
}
/*
*----------------------------------------------------------------------
*
* FcLinuxLinkSpeed
*
* Get FC Link Speed
*
* Result:
*
* VMK_FC_SPEED_UNKNOWN
* VMK_FC_SPEED_1GBIT
* VMK_FC_SPEED_2GBIT
* VMK_FC_SPEED_4GBIT
* VMK_FC_SPEED_10GBIT
*----------------------------------------------------------------------
*/
static vmk_FcLinkSpeed
FcLinuxLinkSpeed(void *clientData)
{
vmk_FcLinkSpeed speed = VMK_FC_SPEED_UNKNOWN;
vmk_ScsiAdapter *vmkAdapter = (vmk_ScsiAdapter *)clientData;;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct fc_internal *i;
struct fc_host_attrs *fc_host;
struct Scsi_Host *shost;
VMK_ASSERT(vmkAdapter);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) vmkAdapter->clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
if(i->f->get_host_speed) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost),
i->f->get_host_speed, shost);
switch (fc_host->speed) {
case FC_PORTSPEED_1GBIT:
speed = VMK_FC_SPEED_1GBIT;
break;
case FC_PORTSPEED_2GBIT:
speed = VMK_FC_SPEED_2GBIT;
break;
case FC_PORTSPEED_4GBIT:
speed = VMK_FC_SPEED_4GBIT;
break;
case FC_PORTSPEED_10GBIT:
speed = VMK_FC_SPEED_10GBIT;
break;
case FC_PORTSPEED_8GBIT:
speed = VMK_FC_SPEED_8GBIT;
break;
case FC_PORTSPEED_16GBIT:
speed = VMK_FC_SPEED_16GBIT;
break;
case FC_PORTSPEED_NOT_NEGOTIATED:
case FC_PORTSPEED_UNKNOWN:
default:
speed = VMK_FC_SPEED_UNKNOWN;
}
}
return speed;
}
/*
*----------------------------------------------------------------------
*
* FcLinuxAdapterPortName
*
* Get FC Adapter Port Name
*
* Result:
* Return 64 bit port name
*----------------------------------------------------------------------
*/
static vmk_uint64
FcLinuxAdapterPortName(void *clientData)
{
vmk_ScsiAdapter *vmkAdapter = (vmk_ScsiAdapter *)clientData;;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct fc_host_attrs *fc_host;
struct Scsi_Host *shost;
VMK_ASSERT(vmkAdapter);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) vmkAdapter->clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
return (fc_host->port_name);
}
/*
*----------------------------------------------------------------------
*
* FcLinuxAdapterPortId
*
* Get FC Adapter Port Id
*
* Result:
* Return 32 bit port id
*----------------------------------------------------------------------
*/
static vmk_uint32
FcLinuxAdapterPortId(void *clientData)
{
vmk_uint32 portId = 0;
vmk_ScsiAdapter *vmkAdapter = (vmk_ScsiAdapter *)clientData;;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct fc_host_attrs *fc_host;
struct fc_internal *i;
struct Scsi_Host *shost;
VMK_ASSERT(vmkAdapter);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) vmkAdapter->clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
if (i->f->get_host_port_id) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost),
i->f->get_host_port_id, shost);
portId = fc_host->port_id;
}
return portId;
}
/*
*----------------------------------------------------------------------
*
* FcLinuxAdapterNodeName
*
* Get FC Adapter Node Name
*
* Result:
* Return 64 bit node name
*----------------------------------------------------------------------
*/
static vmk_uint64
FcLinuxAdapterNodeName(void *clientData)
{
vmk_ScsiAdapter *vmkAdapter = (vmk_ScsiAdapter *)clientData;;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct fc_host_attrs *fc_host;
struct Scsi_Host *shost;
VMK_ASSERT(vmkAdapter);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) vmkAdapter->clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
return (fc_host->node_name);
}
/*
*----------------------------------------------------------------------
*
* FcLinuxAdapterPortType
*
* Get FC Adapter Port Type
*
* Result:
* VMK_FC_PORTTYPE_UNKNOWN
* VMK_FC_PORTTYPE_OTHER
* VMK_FC_PORTTYPE_NOTPRESENT
* VMK_FC_PORTTYPE_NPORT
* VMK_FC_PORTTYPE_NLPORT
* VMK_FC_PORTTYPE_LPORT
* VMK_FC_PORTTYPE_PTP
*----------------------------------------------------------------------
*/
static vmk_FcPortType
FcLinuxAdapterPortType(void *clientData)
{
vmk_FcPortType portType = VMK_FC_PORTTYPE_UNKNOWN;
vmk_ScsiAdapter *vmkAdapter = (vmk_ScsiAdapter *)clientData;;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct fc_internal *i;
struct fc_host_attrs *fc_host;
struct Scsi_Host *shost;
VMK_ASSERT(vmkAdapter);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) vmkAdapter->clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
if (i->f->get_host_port_type) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost),
i->f->get_host_port_type, shost);
switch (fc_host->port_type) {
case FC_PORTTYPE_OTHER:
portType = VMK_FC_PORTTYPE_OTHER;
break;
case FC_PORTTYPE_NOTPRESENT:
portType = FC_PORTTYPE_NOTPRESENT;
break;
case FC_PORTTYPE_NPORT:
portType = VMK_FC_PORTTYPE_NPORT;
break;
case FC_PORTTYPE_NLPORT:
portType = VMK_FC_PORTTYPE_NLPORT;
break;
case FC_PORTTYPE_LPORT:
portType = VMK_FC_PORTTYPE_LPORT;
break;
case FC_PORTTYPE_PTP:
portType = VMK_FC_PORTTYPE_PTP;
break;
case FC_PORTTYPE_NPIV:
portType = VMK_FC_PORTTYPE_NPIV;
break;
case FC_PORTTYPE_UNKNOWN:
default:
portType = VMK_FC_PORTTYPE_UNKNOWN;
}
}
return portType;
}
/*
*----------------------------------------------------------------------
*
* FcLinuxAdapterPortState
*
* Get FC Adapter Port State
*
* Result:
* VMK_FC_PORTSTATE_UNKNOWN
* VMK_FC_PORTSTATE_NOTPRESENT
* VMK_FC_PORTSTATE_ONLINE
* VMK_FC_PORTSTATE_OFFLINE
* VMK_FC_PORTSTATE_BLOCKED
* VMK_FC_PORTSTATE_BYPASSED
* VMK_FC_PORTSTATE_DIAGNOSTICS
* VMK_FC_PORTSTATE_LINKDOWN
* VMK_FC_PORTSTATE_ERROR
* VMK_FC_PORTSTATE_LOOPBACK
* VMK_FC_PORTSTATE_DELETED
*----------------------------------------------------------------------
*/
static vmk_FcPortState
FcLinuxAdapterPortState(void *clientData)
{
vmk_FcPortType portState = VMK_FC_PORTSTATE_UNKNOWN;
vmk_ScsiAdapter *vmkAdapter = (vmk_ScsiAdapter *)clientData;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct fc_internal *i;
struct fc_host_attrs *fc_host;
struct Scsi_Host *shost;
VMK_ASSERT(vmkAdapter);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) vmkAdapter->clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
if (i->f->get_host_port_state) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost),
i->f->get_host_port_state, shost);
switch (fc_host->port_state) {
case FC_PORTSTATE_NOTPRESENT:
portState = VMK_FC_PORTSTATE_NOTPRESENT;
break;
case FC_PORTSTATE_ONLINE:
portState = VMK_FC_PORTSTATE_ONLINE;
break;
case FC_PORTSTATE_OFFLINE:
portState = VMK_FC_PORTSTATE_OFFLINE;
break;
case FC_PORTSTATE_BLOCKED:
portState = VMK_FC_PORTSTATE_BLOCKED;
break;
case FC_PORTSTATE_BYPASSED:
portState = VMK_FC_PORTSTATE_BYPASSED;
break;
case FC_PORTSTATE_DIAGNOSTICS:
portState = VMK_FC_PORTSTATE_DIAGNOSTICS;
break;
case FC_PORTSTATE_LINKDOWN:
portState = VMK_FC_PORTSTATE_LINKDOWN;
break;
case FC_PORTSTATE_ERROR:
portState = VMK_FC_PORTSTATE_ERROR;
break;
case FC_PORTSTATE_LOOPBACK:
portState = VMK_FC_PORTSTATE_LOOPBACK;
break;
case FC_PORTSTATE_DELETED:
portState = VMK_FC_PORTSTATE_DELETED;
break;
case FC_PORTSTATE_UNKNOWN:
default:
portState = VMK_FC_PORTSTATE_UNKNOWN;
}
}
return portState;
}
/*
*----------------------------------------------------------------------
*
* FcLinuxTargetAttributes
*
* Get FC Target Attributes
*
* Result:
* Return FC Transport information for the specified target
*----------------------------------------------------------------------
*/
static VMK_ReturnStatus
FcLinuxTargetAttributes(void *clientData, vmk_FcTargetAttrs *vmkFcTarget,
vmk_uint32 channelNo, vmk_uint32 targetNo)
{
struct scsi_target *sTarget;
vmk_ScsiAdapter *vmkAdapter = (vmk_ScsiAdapter *)clientData;;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct Scsi_Host *shost;
struct fc_internal *i;
unsigned long flags;
struct fc_rport *rport;
VMK_ASSERT(vmkAdapter);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) vmkAdapter->clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
spin_lock_irqsave(shost->host_lock, flags);
sTarget = vmklnx_scsi_find_target(shost, channelNo, targetNo);
spin_unlock_irqrestore(shost->host_lock, flags);
if (!sTarget) {
VMKLNX_DEBUG(0, "No Valid FC targets bound");
return VMK_FAILURE;
}
rport = starget_to_rport(sTarget);
if (!rport) {
VMKLNX_DEBUG(0, "No Valid rports found");
return VMK_FAILURE;
}
vmkFcTarget->nodeName = rport->node_name;
vmkFcTarget->portName = rport->port_name;
vmkFcTarget->portId = rport->port_id;
return VMK_OK;
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxAdapterStatus
*
* Get adapter status
*
* Result:
*
* VMK_ADAPTER_STATUS_UNKNOWN - Unknown adapter Status
* VMK_ADAPTER_STATUS_ONLINE - Adapter is Online and working
* VMK_ADAPTER_STATUS_OFFLINE - Adapter is not capable of accepting new
* commands
*----------------------------------------------------------------------
*/
static vmk_AdapterStatus
SCSILinuxAdapterStatus(void *vmkAdapter)
{
return VMK_ADAPTER_STATUS_ONLINE;
/*
* For now return as it is. We will have to add this entry point new
*/
}
/*
*----------------------------------------------------------------------
*
* SCSILinuxRescanLink
*
* Rescan Link
*
* Result:
*
* VMK_RESCAN_LINK_UNSUPPORTED - Rescanning the link not supported
* VMK_RESCAN_LINK_SUCCEEDED - Rescan succeeded
* VMK_RESCAN_LINK_FAILED - Rescan failed
*----------------------------------------------------------------------
*/
static vmk_RescanLinkStatus
SCSILinuxRescanLink(void *clientData)
{
return VMK_RESCAN_LINK_SUCCEEDED;
/*
* For now return as it is. Newer kernels > 2.6.18 do support
* link scan. If so, we can call them later
*/
}
/*
*----------------------------------------------------------------------
*
* FcLinuxAttachMgmtAdapter
*
* Attach FC mgmt Adapter structure
*
* Result:
* Attach to FC transport. Returns 0 on SUCCESS
*----------------------------------------------------------------------
*/
int
FcLinuxAttachMgmtAdapter(struct Scsi_Host *shost)
{
vmk_FcAdapter *pFcAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) shost->adapter;
vmk_ScsiAdapter *vmkAdapter;
VMK_ASSERT(shost);
VMK_ASSERT(vmklnx26ScsiAdapter);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
pFcAdapter =
(vmk_FcAdapter *)kzalloc(sizeof(vmk_FcAdapter), GFP_KERNEL);
if (!pFcAdapter) {
VMKLNX_WARN("No memory for FC adapter struct");
return -ENOMEM;
}
pFcAdapter->getFcAdapterStatus = SCSILinuxAdapterStatus;
pFcAdapter->rescanFcLink = SCSILinuxRescanLink;
pFcAdapter->getFcNodeName = FcLinuxAdapterNodeName;
pFcAdapter->getFcPortName = FcLinuxAdapterPortName;
pFcAdapter->getFcPortId = FcLinuxAdapterPortId;
pFcAdapter->getFcLinkSpeed = FcLinuxLinkSpeed;
pFcAdapter->getFcPortType = FcLinuxAdapterPortType;
pFcAdapter->getFcPortState = FcLinuxAdapterPortState;
pFcAdapter->getFcTargetAttributes = FcLinuxTargetAttributes;
vmkAdapter->mgmtAdapter.t.fc = pFcAdapter;
vmkAdapter->mgmtAdapter.transport = VMK_STORAGE_ADAPTER_FC;
return 0;
}
/*
*----------------------------------------------------------------------
*
* FcLinuxReleaseMgmtAdapter
*
* Free up the FC mgmt Adapter structure
*
* Result:
* Unregister the FC transport
*----------------------------------------------------------------------
*/
void
FcLinuxReleaseMgmtAdapter(struct Scsi_Host *shost)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
vmk_ScsiAdapter *vmkAdapter;
VMK_ASSERT(shost);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) shost->adapter;
VMK_ASSERT(vmklnx26ScsiAdapter);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
if ( vmkAdapter->mgmtAdapter.transport == VMK_STORAGE_ADAPTER_FC ) {
/*
* Make sure we mark this template as useless from now on
*/
vmkAdapter->mgmtAdapter.transport =
VMK_STORAGE_ADAPTER_TRANSPORT_UNKNOWN;
kfree(vmkAdapter->mgmtAdapter.t.fc);
}
return;
}
/**
*
* \globalfn find_initiator_sas_address - get the lowest initiator sas address
*
* \param dev a pointer to a struct device
* \param data a pointer to a u64 sas address
* \return 0
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
* None.
* \sa None.
* \comments -
*
*/
static int
find_initiator_sas_address(struct device *dev, void *data)
{
if (dev && data && (SAS_PHY_DEVICE_TYPE == dev->dev_type)) {
u64 * pSasAddr = (u64 *) data;
struct sas_phy *phy = dev_to_phy(dev);
if (phy && (phy->identify.sas_address < (*pSasAddr))) {
*pSasAddr = phy->identify.sas_address;
}
}
return 0;
}
/**
*
* \globalfn SasLinuxInitiatorAddress -- return inititator sas address
*
* \param pAdapter a pointer to a struct vmk_ScsiAdapter
* \return lowest initiator sas address or 0 if none
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
* None.
* \sa None.
* \comments -
*
*/
vmk_uint64
SasLinuxInitiatorAddress(void *pAdapter)
{
struct Scsi_Host *shost;
vmk_ScsiAdapter *vmkAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
vmk_uint64 initiatorAddress = 0;
vmkAdapter = (vmk_ScsiAdapter *)pAdapter;
if (NULL == vmkAdapter) {
return(initiatorAddress);
}
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *)vmkAdapter->clientData;
if (NULL == vmklnx26ScsiAdapter) {
return(initiatorAddress);
}
shost = vmklnx26ScsiAdapter->shost;
if (NULL == shost) {
return(initiatorAddress);
}
initiatorAddress = ~0;
device_for_each_child(&shost->shost_gendev,
(void *)&initiatorAddress, find_initiator_sas_address);
if((~0) == initiatorAddress) {
/* In case not found, set initiator sas address to 0 */
int ret = FAILED;
struct sas_internal *i = to_sas_internal(shost->transportt);
VMK_ASSERT(i);
initiatorAddress = 0;
if (i->f && i->f->get_initiator_sas_identifier) {
/*
* This provides a workaround for hpsa SAS driver and
* it should be removed when HP driver has real SAS transport support
*/
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), ret,
i->f->get_initiator_sas_identifier, shost, (u64 *)&initiatorAddress);
}
}
return(initiatorAddress);
}
/**
*
* \globalfn SasLinuxTargetAttributes -- retrieve target attributes
*
* \param pAdapter a pointer to a struct vmk_ScsiAdapter
* \param sasAttrib a pointer to vmk_SasTargetAttrs
* \param channelNo a channel number
* \param targetNo a target number
* \return VMK_ReturnStatus
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
* None.
* \sa None.
* \comments -
*
*/
VMK_ReturnStatus
SasLinuxTargetAttributes(void *pAdapter, vmk_SasTargetAttrs *sasAttrib,
vmk_uint32 channelNo, vmk_uint32 targetNo)
{
unsigned long flags;
struct Scsi_Host *shost;
struct sas_internal *i;
struct scsi_target *starget;
vmk_ScsiAdapter *vmkAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
int ret = FAILED;
if ((NULL == pAdapter) || (NULL == sasAttrib)) {
return(VMK_FAILURE);
}
memset(sasAttrib, 0, sizeof(vmk_SasTargetAttrs));
vmkAdapter = (vmk_ScsiAdapter *)pAdapter;
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *)vmkAdapter->clientData;
if ((NULL == vmklnx26ScsiAdapter) || (NULL == vmklnx26ScsiAdapter->shost)) {
return(VMK_FAILURE);
}
shost = vmklnx26ScsiAdapter->shost;
spin_lock_irqsave(shost->host_lock, flags);
starget = vmklnx_scsi_find_target(shost, channelNo, targetNo);
spin_unlock_irqrestore(shost->host_lock, flags);
if (NULL == starget) {
return(VMK_FAILURE);
}
i = to_sas_internal(shost->transportt);
VMK_ASSERT(i);
/* Let each individual driver to provide SAS target information */
if (i->f && i->f->get_target_sas_identifier) {
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), ret,
i->f->get_target_sas_identifier, starget, (u64 *)&sasAttrib->sasAddress);
}
if (SUCCESS != ret) {
VMKLNX_WARN("ret=0x%x - Cannot get SAS target identifier for "
"Channel=%d Target=%d. Please make sure driver can provide "
"SAS target information", ret, channelNo, targetNo);
return(VMK_FAILURE);
} else {
return(VMK_OK);
}
}
/*
*----------------------------------------------------------------------
*
* SasLinuxAttachMgmtAdapter
*
* Attach SAS mgmt Adapter structure
*
* Result:
* Attach to SAS transport. Returns 0 on SUCCESS
*----------------------------------------------------------------------
*/
int
SasLinuxAttachMgmtAdapter(struct Scsi_Host *shost)
{
vmk_SasAdapter *pSasAdapter;
vmk_ScsiAdapter *vmkAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
VMK_ASSERT(shost);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) shost->adapter;
VMK_ASSERT(vmklnx26ScsiAdapter);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
pSasAdapter = (vmk_SasAdapter *)kzalloc(sizeof(vmk_SasAdapter), GFP_KERNEL);
if (NULL == pSasAdapter) {
VMKLNX_WARN("No memory for SAS management adapter struct allocation");
return -ENOMEM;
}
pSasAdapter->getInitiatorSasAddress = SasLinuxInitiatorAddress;
pSasAdapter->getSasTargetAttributes = SasLinuxTargetAttributes;
vmkAdapter->mgmtAdapter.t.sas = pSasAdapter;
vmkAdapter->mgmtAdapter.transport = VMK_STORAGE_ADAPTER_SAS;
return 0;
}
/*
*----------------------------------------------------------------------
*
* SasLinuxReleaseMgmtAdapter
*
* Free up the SAS mgmt Adapter structure
*
* Result:
* Unregister the SAS transport
*----------------------------------------------------------------------
*/
void
SasLinuxReleaseMgmtAdapter(struct Scsi_Host *shost)
{
vmk_ScsiAdapter *vmkAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
VMK_ASSERT(shost);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) shost->adapter;
VMK_ASSERT(vmklnx26ScsiAdapter);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
if (VMK_STORAGE_ADAPTER_SAS == vmkAdapter->mgmtAdapter.transport) {
/*
* Make sure we mark this template as useless from now on
*/
vmkAdapter->mgmtAdapter.transport = VMK_STORAGE_ADAPTER_TRANSPORT_UNKNOWN;
kfree(vmkAdapter->mgmtAdapter.t.sas);
}
return;
}
/*
*----------------------------------------------------------------------
*
* XsanLinuxInitiatorID
*
* Return generic SAN inititator ID
*
* Result:
* Return generic SAN transport initiator ID in the initiatorID
*----------------------------------------------------------------------
*/
static VMK_ReturnStatus
XsanLinuxInitiatorID(void *pAdapter, vmk_XsanID *initiatorID)
{
struct Scsi_Host *shost;
vmk_ScsiAdapter *vmkAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct xsan_internal *i;
vmkAdapter = (vmk_ScsiAdapter *)pAdapter;
if (NULL == vmkAdapter) {
return VMK_FAILURE;
}
if (NULL == initiatorID) {
return VMK_FAILURE;
}
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *)vmkAdapter->clientData;
if (NULL == vmklnx26ScsiAdapter) {
return VMK_FAILURE;
}
shost = vmklnx26ScsiAdapter->shost;
if (NULL == shost) {
return VMK_FAILURE;
}
i = to_xsan_internal(shost->transportt);
VMK_ASSERT(i);
if (i->f && i->f->get_initiator_xsan_identifier) {
int ret = FAILED;
VMK_ASSERT_ON_COMPILE(sizeof(vmk_XsanID) == sizeof(struct xsan_id));
VMK_ASSERT_ON_COMPILE(offsetof(vmk_XsanID, L) == offsetof(struct xsan_id, L));
VMK_ASSERT_ON_COMPILE(offsetof(vmk_XsanID, H) == offsetof(struct xsan_id, H));
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), ret,
i->f->get_initiator_xsan_identifier, shost, (struct xsan_id *)initiatorID);
if (SUCCESS != ret) {
VMKLNX_WARN(
"ret=0x%x - Cannot get generic SAN initiator identifier for %s",
ret, vmk_ScsiGetAdapterName(vmkAdapter));
return VMK_FAILURE;
}
}
return VMK_OK;
}
/*
*----------------------------------------------------------------------
*
* XsanLinuxTargetAttributes
*
* Retrieve target attributes for generic SAN
*
* Result:
* Return generic SAN transport information for the specified target
* in the xsanAttrib.
*----------------------------------------------------------------------
*/
static VMK_ReturnStatus
XsanLinuxTargetAttributes(void *pAdapter, vmk_XsanTargetAttrs *xsanAttrib,
vmk_uint32 channelNo, vmk_uint32 targetNo)
{
unsigned long flags;
struct Scsi_Host *shost;
struct xsan_internal *i;
struct scsi_target *starget;
vmk_ScsiAdapter *vmkAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
int ret = FAILED;
if (NULL == pAdapter || NULL == xsanAttrib) {
return VMK_FAILURE;
}
memset(xsanAttrib, 0, sizeof(vmk_XsanTargetAttrs));
vmkAdapter = (vmk_ScsiAdapter *)pAdapter;
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *)vmkAdapter->clientData;
if (NULL == vmklnx26ScsiAdapter || NULL == vmklnx26ScsiAdapter->shost) {
return VMK_FAILURE;
}
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
spin_lock_irqsave(shost->host_lock, flags);
starget = vmklnx_scsi_find_target(shost, channelNo, targetNo);
spin_unlock_irqrestore(shost->host_lock, flags);
if (NULL == starget) {
return VMK_FAILURE;
}
i = to_xsan_internal(shost->transportt);
VMK_ASSERT(i);
/* Let each individual driver to provide generic SAN target information */
if (i->f && i->f->get_target_xsan_identifier) {
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), ret,
i->f->get_target_xsan_identifier, starget, (struct xsan_id *)&xsanAttrib->id);
}
if (SUCCESS != ret) {
VMKLNX_WARN("ret=0x%x - Cannot get generic SAN target identifier for "
"Channel=%d Target=%d. Please make sure driver can provide "
"generic SAN target information", ret, channelNo, targetNo);
return VMK_FAILURE;
}
return VMK_OK;
}
/*
*----------------------------------------------------------------------
*
* XsanLinuxAttachMgmtAdapter
*
* Attach generic SAN mgmt Adapter structure
*
* Result:
* Attach to generic SAN transport. Returns 0 on SUCCESS
*----------------------------------------------------------------------
*/
int
XsanLinuxAttachMgmtAdapter(struct Scsi_Host *shost)
{
vmk_XsanAdapter *pXsanAdapter;
vmk_ScsiAdapter *vmkAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
VMK_ASSERT(shost);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) shost->adapter;
VMK_ASSERT(vmklnx26ScsiAdapter);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
pXsanAdapter = (vmk_XsanAdapter *)kzalloc(sizeof(vmk_XsanAdapter), GFP_KERNEL);
if (NULL == pXsanAdapter) {
VMKLNX_WARN("No memory for generic SAN adapter struct allocation");
return -ENOMEM;
}
pXsanAdapter->getXsanInitiatorID = XsanLinuxInitiatorID;
pXsanAdapter->getXsanTargetAttributes = XsanLinuxTargetAttributes;
vmkAdapter->mgmtAdapter.t.xsan = pXsanAdapter;
vmkAdapter->mgmtAdapter.transport = VMK_STORAGE_ADAPTER_XSAN;
return 0;
}
/*
*----------------------------------------------------------------------
*
* XsanLinuxReleaseMgmtAdapter
*
* Free up the generic SAN mgmt Adapter structure
*
* Result:
* Unregister the generic SAN transport
*----------------------------------------------------------------------
*/
void
XsanLinuxReleaseMgmtAdapter(struct Scsi_Host *shost)
{
vmk_ScsiAdapter *vmkAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
VMK_ASSERT(shost);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) shost->adapter;
VMK_ASSERT(vmklnx26ScsiAdapter);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
if (VMK_STORAGE_ADAPTER_XSAN == vmkAdapter->mgmtAdapter.transport) {
/*
* Make sure we mark this template as useless from now on
*/
vmkAdapter->mgmtAdapter.transport = VMK_STORAGE_ADAPTER_TRANSPORT_UNKNOWN;
kfree(vmkAdapter->mgmtAdapter.t.xsan);
}
return;
}
/*
*----------------------------------------------------------------------
*
* FcoeLinuxAttachMgmtAdapter
*
* Attach FCoE mgmt Adapter structure
*
* Result:
* Attach to FCoE transport. Returns 0 on SUCCESS
*----------------------------------------------------------------------
*/
int
FcoeLinuxAttachMgmtAdapter(struct Scsi_Host *shost)
{
vmk_FcoeAdapter *pFcoeAdapter;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter =
(struct vmklnx_ScsiAdapter *) shost->adapter;
vmk_ScsiAdapter *vmkAdapter;
struct fc_host_attrs *fc_host;
vmk_FcoeAdapterAttrs *fcoeAttrs;
VMK_ASSERT(vmklnx26ScsiAdapter);
/*
* fc_host is allcoated during shost creation
*/
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
pFcoeAdapter =
(vmk_FcoeAdapter *)kzalloc(sizeof(vmk_FcoeAdapter), GFP_KERNEL);
if (!pFcoeAdapter) {
vmk_WarningMessage("No memory for FCoE adapter struct");
return -ENOMEM;
}
fcoeAttrs =
(vmk_FcoeAdapterAttrs *)kzalloc(sizeof(vmk_FcoeAdapterAttrs), GFP_KERNEL);
if (!fcoeAttrs) {
vmk_WarningMessage("No memory for FCoE adapter Attribute struct");
kfree(pFcoeAdapter);
return -ENOMEM;
}
fc_host->cna_ops = (void *) fcoeAttrs;
pFcoeAdapter->getFCoEAdapterAttributes = FCOELinuxAdapterAttributes;
FcLinuxPopulateCB(&pFcoeAdapter->fc);
pFcoeAdapter->fc.linkTimeout = 15;
vmkAdapter->mgmtAdapter.t.fcoe = pFcoeAdapter;
vmkAdapter->mgmtAdapter.transport = VMK_STORAGE_ADAPTER_FCOE;
return 0;
}
/*
*----------------------------------------------------------------------
*
* FcoeLinuxReleaseMgmtAdapter
*
* Free up the FCoE mgmt Adapter structure
*
* Result:
* Unregister the FCoE transport
*----------------------------------------------------------------------
*/
void
FcoeLinuxReleaseMgmtAdapter(struct Scsi_Host *shost)
{
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
vmk_ScsiAdapter *vmkAdapter;
struct fc_host_attrs *fc_host;
VMK_ASSERT(shost);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) shost->adapter;
VMK_ASSERT(vmklnx26ScsiAdapter);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
if (vmkAdapter->mgmtAdapter.transport == VMK_STORAGE_ADAPTER_FCOE) {
/*
* Make sure we mark this template as useless from now on
*/
vmkAdapter->mgmtAdapter.transport =
VMK_STORAGE_ADAPTER_TRANSPORT_UNKNOWN;
kfree(vmkAdapter->mgmtAdapter.t.fcoe);
kfree(fc_host->cna_ops);
}
return;
}
/*
*----------------------------------------------------------------------
*
* FCOELinuxAdapterAttributes
*
* Copy FCoE attributes to the management stack
*
* Result:
* VMK_OK on success, failure otherwise
*----------------------------------------------------------------------
*/
VMK_ReturnStatus
FCOELinuxAdapterAttributes(void *pAdapter, vmk_FcoeAdapterAttrs *fcoeAttrs)
{
vmk_ScsiAdapter *vmkAdapter = (vmk_ScsiAdapter *)pAdapter;;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
struct fc_host_attrs *fc_host;
struct Scsi_Host *shost;
VMK_ASSERT(vmkAdapter);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) vmkAdapter->clientData;
VMK_ASSERT(vmklnx26ScsiAdapter);
shost = vmklnx26ScsiAdapter->shost;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
/*
* Fill in the data structures
*/
memcpy(fcoeAttrs, fc_host->cna_ops, sizeof(*fcoeAttrs));
return VMK_OK;
}
/*
*----------------------------------------------------------------------
*
* FcLinuxPopulateCB -
*
* Populate Call back function for FC Mgmt
*
* Result:
* None
*----------------------------------------------------------------------
*/
static void
FcLinuxPopulateCB(vmk_FcAdapter *pFcAdapter)
{
pFcAdapter->getFcAdapterStatus = SCSILinuxAdapterStatus;
pFcAdapter->rescanFcLink = SCSILinuxRescanLink;
pFcAdapter->getFcNodeName = FcLinuxAdapterNodeName;
pFcAdapter->getFcPortName = FcLinuxAdapterPortName;
pFcAdapter->getFcPortId = FcLinuxAdapterPortId;
pFcAdapter->getFcLinkSpeed = FcLinuxLinkSpeed;
pFcAdapter->getFcPortType = FcLinuxAdapterPortType;
pFcAdapter->getFcPortState = FcLinuxAdapterPortState;
pFcAdapter->getFcTargetAttributes = FcLinuxTargetAttributes;
return;
}
/*
*----------------------------------------------------------------------
*
* SCSILinux_InitVmkIf
*
* Entry point for SCSI VMkernel interface-specific initialization.
* Called as part of SCSILinux_Init in linux_scsi.c.
*
* Results:
* None.
*
* Side effects:
* Initializes SCSI VMkernel interface log.
*
*----------------------------------------------------------------------
*/
void
SCSILinux_InitVmkIf(void)
{
VMKLNX_CREATE_LOG();
}
/*
*----------------------------------------------------------------------
*
* SCSILinux_CleanupVmkIf
*
* Entry point for SCSI VMkernel interface-specific teardown.
* Called as part of SCSILinux_Cleanup in linux_scsi.c.
*
* Results:
* None.
*
* Side effects:
* Cleans up SCSI VMkernel interface log.
*
*----------------------------------------------------------------------
*/
void
SCSILinux_CleanupVmkIf(void)
{
VMKLNX_DESTROY_LOG();
}
|