Files
@ 052c0cbc4bbf
Branch filter:
Location: vmkdrivers/vmkdrivers/src_9/vmklinux_9/vmware/linux_scsi_transport.c
052c0cbc4bbf
123.8 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 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 | /* ****************************************************************
* Portions Copyright 1998, 2009-2011 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_transport.c
*
* Linux scsi transport emulation. Covers transport functionality of
* SCSI drivers - pSCSI, FC(with NPIV) and SAS
*
* From linux-2.6.18-8/drivers/scsi/scsi_transport_fc.c:
*
* Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
* Copyright (C) 2004-2005 James Smart, Emulex Corporation
*
* From linux-2.6.18-8/drivers/scsi/scsi_transport_sas.c:
*
* Copyright (C) 2005-2006 Dell Inc.
*
* From linux-2.6.18-8/drivers/scsi/scsi_transport_spi.c:
*
* Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
* Copyright (c) 2004, 2005 James Bottomley <James.Bottomley@SteelEye.com>
*
* From linux-2.6.18-8/drivers/scsi/scsi.c:
*
* Copyright (C) 1992 Drew Eckhardt
* Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
* Copyright (C) 2002, 2003 Christoph Hellwig
*
******************************************************************/
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_dbg.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_eh.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_tcq.h>
#include <scsi/scsi_transport.h>
#include <scsi/scsi_transport_spi.h>
#include <scsi/scsi_transport_fc.h>
#include <scsi/scsi_transport_sas.h>
#include <vmklinux_9/vmklinux_scsi.h>
#include <linux/pci.h>
#include <linux/delay.h>
#include "vmkapi.h"
#include "linux_scsi.h" /* To be used for SCSI emulation */
#include "linux_scsi_transport.h" /* To be used for SCSI transport */
#include "linux_stubs.h"
#define VMKLNX_LOG_HANDLE LinScsiTransport
#include "vmklinux_log.h"
/*
* The PPR values at which you calculate the period in ns by multiplying
* by 4
*/
#define SPI_STATIC_PPR 0x0c
static const int ppr_to_ps[] = {
/* The PPR values 0-6 are reserved, fill them in when
* the committee defines them */
-1, /* 0x00 */
-1, /* 0x01 */
-1, /* 0x02 */
-1, /* 0x03 */
-1, /* 0x04 */
-1, /* 0x05 */
-1, /* 0x06 */
3125, /* 0x07 */
6250, /* 0x08 */
12500, /* 0x09 */
25000, /* 0x0a */
30300, /* 0x0b */
50000, /* 0x0c */
};
static atomic_t fc_event_seq;
/*
* dev_loss_tmo: the default number of seconds that the FC transport
* should insulate the loss of a remote port.
* The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
*/
static unsigned int fc_dev_loss_tmo = 10; /* seconds */
/*
* remove_on_dev_loss: controls whether the transport will
* remove a scsi target after the device loss timer expires.
* Removal on disconnect is modeled after the USB subsystem
* and expects subsystems layered on SCSI to be aware of
* potential device loss and handle it appropriately. However,
* many subsystems do not support device removal, leaving situations
* where structure references may remain, causing new device
* name assignments, etc., if the target returns.
*/
static unsigned int fc_remove_on_dev_loss = 0;
static void
spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer);
static enum spi_compare_returns
spi_dv_device_compare_inquiry(struct scsi_device *sdev, u8 *buffer,
u8 *ptr, const int retries);
static enum spi_compare_returns
spi_dv_retrain(struct scsi_device *sdev, u8 *buffer, u8 *ptr,
enum spi_compare_returns
(*compare_fn)(struct scsi_device *, u8 *, u8 *, int));
static int spi_execute(struct scsi_device *sdev, const void *cmd,
enum dma_data_direction dir,
void *buffer, unsigned bufflen,
struct scsi_sense_hdr *sshdr);
static int fc_queue_work(struct Scsi_Host *shost, struct work_struct *work);
static void fc_timeout_deleted_rport(struct work_struct *work);
static void fc_timeout_fail_rport_io(struct work_struct *work);
static void fc_scsi_scan_rport(struct work_struct *work);
static void fc_starget_delete(struct work_struct *work);
static void fc_rport_final_delete(struct work_struct *work);
static void fc_flush_work(struct Scsi_Host *shost);
static void fc_flush_devloss(struct Scsi_Host *shost);
static int fc_queue_devloss_work(struct Scsi_Host *shost,
struct delayed_work *dwork, unsigned long delay);
static void fc_rport_dev_release(struct device *dev);
static void fc_vport_dev_release(struct device *dev);
static void fc_vport_sched_delete(struct work_struct *work);
static int vmk_fc_vport_terminate(struct fc_vport *vport);
static void sas_phy_release(struct device *dev);
static void sas_port_release(struct device *dev);
static void sas_end_device_release(struct device *dev);
static void sas_expander_release(struct device *dev);
static int sas_assign_scsi_target_id(struct sas_rphy *rphy,
struct sas_host_attrs *sas_host);
static int sas_scsi_target_reparent(struct device *dev, void *data);
static int fc_host_setup(struct Scsi_Host *shost);
static void fc_host_free(struct Scsi_Host *shost);
static int sas_remove_scsi_target(struct device *dev, void *data);
/**
**********************************************************************
* vmklnx_alloc_scsimod -- */ /**
*
* \brief alloc and init a vmklnx_ScsiModule
*
* \param type transport type
* \param data transport data
*
* \retval initialized vmklnx_ScsiModule
* \retval NULL out of memory
*
**********************************************************************
*/
static struct vmklnx_ScsiModule *
vmklnx_alloc_scsimod(vmklnx_ScsiTransportType type, void *data)
{
struct vmklnx_ScsiModule *vmklnx26ScsiModule;
vmklnx26ScsiModule = kzalloc(sizeof(struct vmklnx_ScsiModule), GFP_KERNEL);
VMK_ASSERT(vmklnx26ScsiModule);
if (!vmklnx26ScsiModule) {
VMKLNX_WARN("Unable to allocate memory for vmklnx_ScsiModule");
return NULL;
}
vmklnx26ScsiModule->moduleID = vmk_ModuleStackTop();
vmklnx26ScsiModule->transportType = type;
vmklnx26ScsiModule->transportData = data;
return vmklnx26ScsiModule;
}
/**
* vmklnx_generic_san_attach_transport - Attach generic transport ScsiModule
* @ft: Pointer to the xsan_function_template
* @target_size: size of target(transport) attributes
* @host_size: size of host attributes
*
* Allocate and initialize all the vmklinux data structures and attach the
* passed in pointer to the xsan_function_template. With generic SAN transport
* type, it allows unique adapter/target ID, RDMs and periodic rescanning for
* new LUNs. Caller should free allocated generic transport when finished
* with vmklnx_generic_san_release_transport.
*
* RETURN VALUE:
* - initialized scsi_transport_template if successful
* - returns NULL if out of memory
*
*/
/* _VMKLNX_CODECHECK_: vmklnx_generic_san_attach_transport */
struct scsi_transport_template *
vmklnx_generic_san_attach_transport(
struct xsan_function_template *ft,
size_t target_size,
size_t host_size
)
{
struct vmklnx_ScsiModule *vmklnx26ScsiModule;
struct xsan_internal *i = kzalloc(sizeof(struct xsan_internal), GFP_KERNEL);
if (unlikely(!i)) {
VMKLNX_WARN("Unable to allocate memory for xsan_internal");
return NULL;
}
vmklnx26ScsiModule =
vmklnx_alloc_scsimod(VMKLNX_SCSI_TRANSPORT_TYPE_XSAN, i);
if (!vmklnx26ScsiModule) {
kfree(i);
return NULL;
}
i->t.module = (void *)vmklnx26ScsiModule;
i->t.target_size = target_size;
i->t.host_size = host_size;
i->f = ft;
return &i->t;
}
EXPORT_SYMBOL(vmklnx_generic_san_attach_transport);
/**
* vmklnx_generic_san_release_transport - Release generic transport
* @t: transport template
*
* Releases a generic SAN transport previously registered with
* vmklnx_generic_san_attach_transport. Caller must have previously
* allocated generic transport with vmklnx_generic_san_attach_transport.
*
* RETURN VALUE:
* None.
*
*/
/* _VMKLNX_CODECHECK_: vmklnx_generic_san_release_transport */
void
vmklnx_generic_san_release_transport(struct scsi_transport_template *t)
{
struct xsan_internal *i = to_xsan_internal(t);
VMK_ASSERT(t->module);
VMK_ASSERT(((struct vmklnx_ScsiModule *)(t->module))->transportData == i);
kfree(t->module);
kfree(i);
}
EXPORT_SYMBOL(vmklnx_generic_san_release_transport);
/*
*----------------------------------------------------------------------
*
* vmklnx_xsan_host_setup --
*
* Initialize generic SAN host attributes
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
vmklnx_xsan_host_setup(struct Scsi_Host *shost)
{
struct xsan_internal *i;
int ret = 0;
VMK_ASSERT(shost);
/*
* Create Mgmt Adapter Instance to our management
*/
if (XsanLinuxAttachMgmtAdapter(shost)) {
return -ENOMEM;
}
VMK_ASSERT(shost->transportt);
i = to_xsan_internal(shost->transportt);
if (i->f->setup_host_attributes) {
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), ret,
i->f->setup_host_attributes, shost);
}
return ret;
}
/*
*----------------------------------------------------------------------
*
* xsan_setup_transport_attrs --
*
* Initialize generic SAN transport attributes
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
xsan_setup_transport_attrs( struct Scsi_Host *shost, struct scsi_target *starget)
{
struct xsan_internal *i = to_xsan_internal(shost->transportt);
int ret = 0;
if (i->f->setup_transport_attributes) {
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), ret,
i->f->setup_transport_attributes, shost, starget);
}
return ret;
}
/**
* spi_attach_transport - Attach pSCSI transport
* @ft: Pointer to the spi_function_template
*
* Allocate and initialize all the vmklinux data structures and attach the
* passed in pointer to the spi_function_template.
*
* ESX Deviation Notes:
* This function also does the necessary initialization of data structures for
* the vmklinux storage stack
*
* RETURN VALUE:
* non-NULL is a success and is a pointer to the new template
* NULL is a failure.
*/
/* _VMKLNX_CODECHECK_: spi_attach_transport */
struct scsi_transport_template *
spi_attach_transport(struct spi_function_template *ft)
{
struct vmklnx_ScsiModule *vmklnx26ScsiModule;
struct spi_internal *i = kzalloc(sizeof(struct spi_internal), GFP_KERNEL);
if (unlikely(!i)) {
VMKLNX_WARN("Unable to allocate memory for spi_internal");
return NULL;
}
vmklnx26ScsiModule =
vmklnx_alloc_scsimod(VMKLNX_SCSI_TRANSPORT_TYPE_PSCSI, i);
if (!vmklnx26ScsiModule) {
kfree(i);
return NULL;
}
i->t.module = (void *)vmklnx26ScsiModule;
i->t.target_size = sizeof(struct spi_transport_attrs);
i->t.host_size = sizeof(struct spi_host_attrs);
i->f = ft;
return &i->t;
}
EXPORT_SYMBOL(spi_attach_transport);
/**
* spi_release_transport - Releases pSCSI transport
* @t: pointer to scsi_transport_template
*
* Releases pSCSI transport
*
* RETURN VALUE:
* None
*/
/* _VMKLNX_CODECHECK_: spi_release_transport */
void spi_release_transport(struct scsi_transport_template *t)
{
struct spi_internal *i = to_spi_internal(t);
/*
* Free up the module structure
*/
kfree(t->module);
/*
* Free up the transport_internal structure
*/
kfree(i);
}
EXPORT_SYMBOL(spi_release_transport);
/*
*----------------------------------------------------------------------
*
* spi_setup_transport_attrs --
*
* Initialize pSCSI transport attributes
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
spi_setup_transport_attrs(struct scsi_target *starget)
{
spi_period(starget) = -1; /* illegal value */
spi_min_period(starget) = 0;
spi_offset(starget) = 0; /* async */
spi_max_offset(starget) = 255;
spi_width(starget) = 0; /* narrow */
spi_max_width(starget) = 1;
spi_iu(starget) = 0; /* no IU */
spi_dt(starget) = 0; /* ST */
spi_qas(starget) = 0;
spi_wr_flow(starget) = 0;
spi_rd_strm(starget) = 0;
spi_rti(starget) = 0;
spi_pcomp_en(starget) = 0;
spi_hold_mcs(starget) = 0;
spi_dv_pending(starget) = 0;
spi_dv_in_progress(starget) = 0;
spi_initial_dv(starget) = 0;
mutex_init(&spi_dv_mutex(starget));
spi_attr_initialized(starget) = 1;
return 0;
}
/** spi_dv_device - Do Domain Validation on the device
* @sdev: scsi device to validate
*
* Performs the domain validation on the given device in the
* current execution thread. Since DV operations may sleep,
* the current thread must have user context. Also no SCSI
* related locks that would deadlock I/O issued by the DV may
* be held.
*/
/* _VMKLNX_CODECHECK_: spi_dv_device */
void
spi_dv_device(struct scsi_device *sdev)
{
struct scsi_target *stgt = sdev->sdev_target;
u8 *buffer;
const int len = SPI_MAX_ECHO_BUFFER_SIZE*2;
VMK_ASSERT(sdev);
if (unlikely(spi_dv_in_progress(stgt))) {
return;
}
if (unlikely(scsi_device_get(sdev))) {
return;
}
spi_dv_in_progress(stgt) = 1;
buffer = vmklnx_kzmalloc(vmklnxLowHeap, len, GFP_KERNEL);
if (!buffer) {
spi_dv_in_progress(stgt) = 0;
scsi_device_put(sdev);
return;
}
/*
* Drain out all commands on target before we start domain validation
* Also dont accept commands from the storage stack
*/
scsi_target_quiesce(stgt);
spi_dv_pending(stgt) = 1;
mutex_lock(&spi_dv_mutex(stgt));
VMKLNX_DEBUG(0, "Beginning Domain Validation");
spi_dv_device_internal(sdev, buffer);
VMKLNX_DEBUG(0, "Ending Domain Validation");
mutex_unlock(&spi_dv_mutex(stgt));
spi_dv_pending(stgt) = 0;
scsi_target_resume(stgt);
spi_initial_dv(stgt) = 1;
vmklnx_kfree(vmklnxLowHeap, buffer);
spi_dv_in_progress(stgt) = 0;
scsi_device_put(sdev);
}
EXPORT_SYMBOL(spi_dv_device);
/**
* scsi_device_quiesce - Block user issued commands.
* @sdev: scsi device to quiesce.
*
* This works by trying to transition to the SDEV_QUIESCE state
* (which must be a legal transition). When the device is in this
* state, only special requests will be accepted, all others will
* be deferred. Unlike Linux behavior, requeues are handled
* outside the vmklinux layer rather than as special requests
* within the vmklinux layer.
*
* Returns zero if unsuccessful or an error if not.
**/
void
vmklnx_scsi_device_quiesce(struct scsi_device *sdev, void *ref)
{
sdev->sdev_state = SDEV_QUIESCE;
/*
* Give some time before all commands are flushed out
*/
while (sdev->device_busy) {
/*
* There is no way to know if all the commands are flushed out
* This is an arbitary number that seems to work with mptspi
* and aic79xx driver. Use caution when modifying this value
*/
if(!in_interrupt()) {
msleep_interruptible(1);
} else {
mdelay(1);
}
}
}
/**
* scsi_device_resume - Restart user issued commands to a quiesced device.
* @sdev: scsi device to resume.
*
* Moves the device from quiesced back to running and restarts the
* queues.
*
* Must be called with user context, may sleep.
**/
void
vmklnx_scsi_device_resume(struct scsi_device *sdev, void *ref)
{
sdev->sdev_state = SDEV_RUNNING;
}
void
scsi_target_quiesce(struct scsi_target *starget)
{
VMK_ASSERT(starget);
starget_for_each_device(starget, NULL, vmklnx_scsi_device_quiesce);
}
void
scsi_target_resume(struct scsi_target *starget)
{
VMK_ASSERT(starget);
starget_for_each_device(starget, NULL, vmklnx_scsi_device_resume);
}
/**
* starget_for_each_device - helper to walk all devices of a target
* @starget: target whose devices we want to iterate over.
*
* Using host_lock instead of reference counting
* This traverses over each devices of @shost. The devices have
* a reference that must be released by scsi_host_put when breaking
* out of the loop. host_lock can not be held on this
*/
/* _VMKLNX_CODECHECK_: starget_for_each_device */
void
starget_for_each_device(struct scsi_target *stgt, void * data,
void (*fn)(struct scsi_device *, void *))
{
struct Scsi_Host *sh;
struct scsi_device *sdev;
VMK_ASSERT(stgt);
sh = dev_to_shost(stgt->dev.parent);
VMK_ASSERT(sh);
shost_for_each_device(sdev, sh) {
if ((sdev->channel == stgt->channel) &&
(sdev->id == stgt->id))
fn(sdev, data);
}
}
EXPORT_SYMBOL(starget_for_each_device);
/*
*----------------------------------------------------------------------
*
* spi_dv_device_internal --
*
* Process DV for pSCSI
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static void
spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer)
{
struct spi_internal *i = to_spi_internal(sdev->host->transportt);
struct scsi_target *starget = sdev->sdev_target;
struct Scsi_Host *shost = sdev->host;
int len = sdev->inquiry_len;
VMK_ASSERT(sdev);
VMK_ASSERT(buffer);
/*
* first set us up for narrow async
*/
DV_SET(offset, 0);
DV_SET(width, 0);
if (spi_dv_device_compare_inquiry(sdev, buffer, buffer, DV_LOOPS)
!= SPI_COMPARE_SUCCESS) {
VMKLNX_DEBUG(0, "Domain Validation Initial Inquiry"
" Failed for adapter %s, channel %d, id %d",
sdev->host->hostt->name, sdev->channel, sdev->id);
return;
}
/* test width */
if (i->f->set_width && spi_max_width(starget) && scsi_device_wide(sdev)) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->set_width, starget, 1);
if (spi_dv_device_compare_inquiry(sdev, buffer, buffer + len,
DV_LOOPS) != SPI_COMPARE_SUCCESS) {
VMKLNX_DEBUG(0, "Wide transfers failed for "
"adapter %s, channel %d, id %d",
sdev->host->hostt->name, sdev->channel, sdev->id);
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->set_width,
starget, 0);
}
}
if (!i->f->set_period) {
return;
}
/* device can't handle synchronous */
if (!scsi_device_sync(sdev) && !scsi_device_dt(sdev)) {
return;
}
/*
* len == -1 is the signal that we need to ascertain the
* presence of an echo buffer before trying to use it. len ==
* 0 means we don't have an echo buffer
*/
len = -1;
/* now set up to the maximum */
DV_SET(offset, spi_max_offset(starget));
DV_SET(period, spi_min_period(starget));
/* try QAS requests; this should be harmless to set if the
* target supports it */
if (scsi_device_qas(sdev)) {
DV_SET(qas, 1);
} else {
DV_SET(qas, 0);
}
if (scsi_device_ius(sdev) && spi_min_period(starget) < 9) {
/* This u320 (or u640). Set IU transfers */
DV_SET(iu, 1);
/* Then set the optional parameters */
DV_SET(rd_strm, 1);
DV_SET(wr_flow, 1);
DV_SET(rti, 1);
if (spi_min_period(starget) == 8)
DV_SET(pcomp_en, 1);
} else {
DV_SET(iu, 0);
}
/*
* now that we've done all this, actually check the bus
* signal type (if known). Some devices are stupid on
* a SE bus and still claim they can try LVD only settings
*/
if (i->f->get_signalling) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->get_signalling, shost);
}
if (spi_signalling(shost) == SPI_SIGNAL_SE ||
spi_signalling(shost) == SPI_SIGNAL_HVD ||
!scsi_device_dt(sdev)) {
DV_SET(dt, 0);
} else {
DV_SET(dt, 1);
}
/* Do the read only INQUIRY tests */
spi_dv_retrain(sdev, buffer, buffer + sdev->inquiry_len,
spi_dv_device_compare_inquiry);
/* See if we actually managed to negotiate and sustain DT */
if (i->f->get_dt) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->get_dt, starget);
}
/*
* Linux does additional tests, like reading and writing tests
* But these tests dont set any parameters in the driver. So for now
* behaving as though the device has no echo buffer in place
*/
return;
}
/*
*----------------------------------------------------------------------
*
* spi_dv_retrain --
*
* Perform various DV
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static enum spi_compare_returns
spi_dv_retrain(struct scsi_device *sdev, u8 *buffer, u8 *ptr,
enum spi_compare_returns
(*compare_fn)(struct scsi_device *, u8 *, u8 *, int))
{
struct spi_internal *i = to_spi_internal(sdev->host->transportt);
struct scsi_target *starget = sdev->sdev_target;
int period = 0, prevperiod = 0;
enum spi_compare_returns retval;
struct Scsi_Host *shost = sdev->host;
for (;;) {
int newperiod;
retval = compare_fn(sdev, buffer, ptr, DV_LOOPS);
if (retval == SPI_COMPARE_SUCCESS
|| retval == SPI_COMPARE_SKIP_TEST) {
break;
}
/* OK, retrain, fallback */
if (i->f->get_iu) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->get_iu, starget);
}
if (i->f->get_qas) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->get_qas, starget);
}
if (i->f->get_period) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->get_period,
starget);
}
/*
* Here's the fallback sequence; first try turning off
* IU, then QAS (if we can control them), then finally
* fall down the periods
*/
if (i->f->set_iu && spi_iu(starget)) {
VMKLNX_DEBUG(0, "Domain Validation disabling"
" information %s, channel %d, id %d",
sdev->host->hostt->name, sdev->channel, sdev->id);
DV_SET(iu, 0);
} else if (i->f->set_qas && spi_qas(starget)) {
VMKLNX_DEBUG(0, "Domain Validation disabling"
" quick arbitration selection %s, channel %d, id %d",
sdev->host->hostt->name, sdev->channel, sdev->id);
DV_SET(qas, 0);
} else {
newperiod = spi_period(starget);
period = newperiod > period ? newperiod : period;
if (period < 0x0d) {
period++;
} else {
period += period >> 1;
}
if (unlikely(period > 0xff || period == prevperiod)) {
/* Total failure; set to async and return */
VMKLNX_DEBUG(0, "Domain Validation failure, "
"dropping back to async %s, channel %d, id %d",
sdev->host->hostt->name, sdev->channel, sdev->id);
DV_SET(offset, 0);
return SPI_COMPARE_FAILURE;
}
VMKLNX_DEBUG(0, "Domain Validation failure,"
" dropping back for %s, channel %d, id %d",
sdev->host->hostt->name, sdev->channel, sdev->id);
DV_SET(period, period);
prevperiod = period;
}
}
return retval;
}
/*
*----------------------------------------------------------------------
*
* spi_dv_device_compare_inquiry --
*
* This is for the simplest form of Domain Validation: a read test
* on the inquiry data from the device
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static enum spi_compare_returns
spi_dv_device_compare_inquiry(struct scsi_device *sdev, u8 *buffer,
u8 *ptr, const int retries)
{
int r, result, readlen = VMK_SECTOR_SIZE; /* Required for mptscsi */
const int len = sdev->inquiry_len;
const char spi_inquiry[] = {
INQUIRY, 0, 0, 0, len, 0
};
VMK_ASSERT(sdev);
VMK_ASSERT(retries != 0);
if (readlen < len) {
readlen = len;
}
for (r = 0; r < retries; r++) {
memset(ptr, 0, readlen);
result = spi_execute(sdev, spi_inquiry, DMA_FROM_DEVICE,
ptr, readlen, NULL);
if(result || !scsi_device_online(sdev)) {
return SPI_COMPARE_FAILURE;
}
/* If we don't have the inquiry data already, the
* first read gets it */
if (ptr == buffer) {
ptr += readlen;
--r;
continue;
}
if (memcmp(buffer, ptr, len) != 0) {
/* failure */
return SPI_COMPARE_FAILURE;
}
}
return SPI_COMPARE_SUCCESS;
}
/*
*----------------------------------------------------------------------
*
* spi_execute --
*
* Send down Commands for DV
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
spi_execute(struct scsi_device *sdev, const void *cmd,
enum dma_data_direction dir,
void *buffer, unsigned bufflen,
struct scsi_sense_hdr *sshdr)
{
int i, result;
unsigned char sense[SCSI_SENSE_BUFFERSIZE];
VMK_ASSERT(sdev);
for(i = 0; i < DV_RETRIES; i++) {
result = scsi_execute(sdev, cmd, dir, buffer, bufflen,
sense, DV_TIMEOUT, /* retries */ 1,
REQ_FAILFAST);
if (result & DRIVER_SENSE) {
struct scsi_sense_hdr sshdr_tmp;
if (!sshdr) {
sshdr = &sshdr_tmp;
}
if (scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, sshdr)
&& sshdr->sense_key == UNIT_ATTENTION) {
continue;
}
}
break;
}
return result;
}
/*
*----------------------------------------------------------------------
*
* sprint_frac --
*
* Print the fraction details
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
sprint_frac(char *dest, int value, int denom)
{
int frac = value % denom;
int result = sprintf(dest, "%d", value / denom);
if (frac == 0) {
return result;
}
dest[result++] = '.';
do {
denom /= 10;
sprintf(dest + result, "%d", frac / denom);
result++;
frac %= denom;
} while (frac);
dest[result++] = '\0';
return result;
}
/**
* spi_display_xfer_agreement - Prints transfer details
* @starget: pointer to scsi_target
*
* Each SPI port is required to maintain a transfer agreement for each
* other port on the bus. This function prints a one-line summary of
* the current agreement;
*
* RETURN VALUE:
* None
*/
/* _VMKLNX_CODECHECK_: spi_display_xfer_agreement */
void
spi_display_xfer_agreement(struct scsi_target *starget)
{
struct spi_transport_attrs *tp;
VMK_ASSERT(starget);
tp = (struct spi_transport_attrs *)&starget->starget_data;
VMK_ASSERT(tp);
if (tp->offset > 0 && tp->period > 0) {
unsigned int picosec, kb100;
char *scsi = "FAST-?";
char tmp[8];
if (tp->period <= SPI_STATIC_PPR) {
picosec = ppr_to_ps[tp->period];
switch (tp->period) {
case 7: scsi = "FAST-320"; break;
case 8: scsi = "FAST-160"; break;
case 9: scsi = "FAST-80"; break;
case 10:
case 11: scsi = "FAST-40"; break;
case 12: scsi = "FAST-20"; break;
}
} else {
picosec = tp->period * 4000;
if (tp->period < 25) {
scsi = "FAST-20";
} else if (tp->period < 50) {
scsi = "FAST-10";
} else
scsi = "FAST-5";
}
kb100 = (10000000 + picosec / 2) / picosec;
if (tp->width) {
kb100 *= 2;
}
sprint_frac(tmp, picosec, 1000);
VMKLNX_DEBUG(0,
"%s %sSCSI %d.%d MB/s %s%s%s%s%s%s%s%s (%s ns, offset %d)",
scsi, tp->width ? "WIDE " : "", kb100/10, kb100 % 10,
tp->dt ? "DT" : "ST",
tp->iu ? " IU" : "",
tp->qas ? " QAS" : "",
tp->rd_strm ? " RDSTRM" : "",
tp->rti ? " RTI" : "",
tp->wr_flow ? " WRFLOW" : "",
tp->pcomp_en ? " PCOMP" : "",
tp->hold_mcs ? " HMCS" : "",
tmp, tp->offset);
} else {
VMKLNX_DEBUG(2, "%sasynchronous", tp->width ? "wide " : "");
}
}
EXPORT_SYMBOL(spi_display_xfer_agreement);
/**
**********************************************************************
* \globalfn spi_populate_ppr_msg -- Populate the message fields
*
* \param Pointer to message field
* \param Period
* \param Offset
* \param Width
* \param Options
* \return 8
* \par Include
* scsi/scsi_transport_spi.h
* \par ESX Deviation Notes None
* \sa None.
**********************************************************************
*/
int
spi_populate_ppr_msg(unsigned char *msg, int period, int offset,
int width, int options)
{
msg[0] = EXTENDED_MESSAGE;
msg[1] = 6;
msg[2] = EXTENDED_PPR;
msg[3] = period;
msg[4] = 0;
msg[5] = offset;
msg[6] = width;
msg[7] = options;
return 8;
}
EXPORT_SYMBOL(spi_populate_ppr_msg);
/**
**********************************************************************
* \globalfn spi_populate_width_msg -- Populate the width message fields
*
* \param Pointer to message field
* \param Width
* \return 4
* \par Include
* scsi/scsi_transport_spi.h
* \par ESX Deviation Notes None
* \sa None.
**********************************************************************
*/
int
spi_populate_width_msg(unsigned char *msg, int width)
{
msg[0] = EXTENDED_MESSAGE;
msg[1] = 2;
msg[2] = EXTENDED_WDTR;
msg[3] = width;
return 4;
}
EXPORT_SYMBOL(spi_populate_width_msg);
/**
**********************************************************************
* \globalfn spi_populate_sync_msg -- Populate the sync message fields
*
* \param Pointer to message field
* \param Period
* \param Offset
* \return 5
* \par Include
* scsi/scsi_transport_spi.h
* \par ESX Deviation Notes None
* \sa None.
**********************************************************************
*/
int
spi_populate_sync_msg(unsigned char *msg, int period, int offset)
{
msg[0] = EXTENDED_MESSAGE;
msg[1] = 3;
msg[2] = EXTENDED_SDTR;
msg[3] = period;
msg[4] = offset;
return 5;
}
EXPORT_SYMBOL(spi_populate_sync_msg);
/**
* fc_attach_transport - attaches an FC transport
* @ft: functions used to communicate with driver
*
* Registers an FC transport with vmklinux
*
* RETURN VALUES:
* A populated scsi_transport_template upon success,
* NULL if memory could not be allocated to register the transport
*
* SEE ALSO:
* fc_release_transport
*/
/* _VMKLNX_CODECHECK_: fc_attach_transport */
struct scsi_transport_template *
fc_attach_transport(struct fc_function_template *ft)
{
struct vmklnx_ScsiModule *vmklnx26ScsiModule;
struct fc_internal *i = kzalloc(sizeof(struct fc_internal), GFP_KERNEL);
VMK_ASSERT(ft);
VMK_ASSERT(i);
if (unlikely(!i)) {
VMKLNX_WARN("Unable to allocate memory for fc_internal");
return NULL;
}
vmklnx26ScsiModule = vmklnx_alloc_scsimod(VMKLNX_SCSI_TRANSPORT_TYPE_FC, i);
if (!vmklnx26ScsiModule) {
kfree(i);
return NULL;
}
/*
* FC Transport uses the shost workq for scsi scanning
* rport->scan_work = consumer
*/
i->t.create_work_queue = 1;
i->t.module = (void *)vmklnx26ScsiModule;
i->t.host_size = sizeof(struct fc_host_attrs);
i->t.target_size = sizeof(struct fc_starget_attrs);
i->f = ft;
return &i->t;
}
EXPORT_SYMBOL(fc_attach_transport);
/**
* fc_release_transport - releases an FC transport
* @t: scsi_transport_template as returned by fc_attach_transport
*
* Releases an FC transport previously registered with fc_attach_transport
*
* SEE ALSO:
* fc_attach_transport
*
* RETURN VALUE:
* This function does not return a value
*/
/* _VMKLNX_CODECHECK_: fc_release_transport */
void fc_release_transport(struct scsi_transport_template *t)
{
struct fc_internal *i;
VMK_ASSERT(t);
i = to_fc_internal(t);
VMK_ASSERT(i);
/*
* Free up the module structure
*/
kfree(t->module);
/*
* Free up the transport_internal structure
*/
kfree(i);
}
EXPORT_SYMBOL(fc_release_transport);
/*
*----------------------------------------------------------------------
*
* vmklnx_fc_host_setup
*
* Slightly deviated version of fc_host_setup. Exports information
* required by vmk_FcAdapter
*
* Results:
* 0 on Success
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
int
fc_host_setup(struct Scsi_Host *shost)
{
struct fc_host_attrs *fc_host;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
/*
* Set default values easily detected by the midlayer as
* failure cases. The scsi lldd is responsible for initializing
* all transport attributes to valid values per host.
*/
fc_host->node_name = -1;
fc_host->port_name = -1;
fc_host->permanent_port_name = -1;
fc_host->supported_classes = FC_COS_UNSPECIFIED;
memset(fc_host->supported_fc4s, 0, sizeof(fc_host->supported_fc4s));
fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN;
fc_host->maxframe_size = -1;
fc_host->max_npiv_vports = 0;
memset(fc_host->serial_number, 0, sizeof(fc_host->serial_number));
fc_host->port_id = -1;
fc_host->port_type = FC_PORTTYPE_UNKNOWN;
fc_host->port_state = FC_PORTSTATE_UNKNOWN;
memset(fc_host->active_fc4s, 0, sizeof(fc_host->active_fc4s));
fc_host->speed = FC_PORTSPEED_UNKNOWN;
fc_host->fabric_name = -1;
memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name));
memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname));
fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN;
INIT_LIST_HEAD(&fc_host->rports);
INIT_LIST_HEAD(&fc_host->rport_bindings);
INIT_LIST_HEAD(&fc_host->vports);
fc_host->next_rport_number = 0;
fc_host->next_target_id = 0;
fc_host->next_vport_number = 0;
fc_host->npiv_vports_inuse = 0;
/*
* Create a work queue to handle FC requests
* Refer fc_queue_work to handle below consumers
* rport_delete_work
* stgt_delete_work
*/
snprintf(fc_host->work_q_name, FC_MAX_WORK_QUEUE_NAME, "fc_wq_%d",
shost->host_no);
fc_host->work_q = create_singlethread_workqueue(fc_host->work_q_name);
if (!fc_host->work_q) {
VMKLNX_WARN("Error: Could not create FC WQ");
return -ENOMEM;
}
/*
* Create a work queue to handle FC devloss requests
* Refer fc_queue_devloss_work for below consumers
* dev_loss_work,
* fail_io_work
*/
snprintf(fc_host->devloss_work_q_name, FC_MAX_WORK_QUEUE_NAME, "fc_dl_%d",
shost->host_no);
fc_host->devloss_work_q = create_singlethread_workqueue(
fc_host->devloss_work_q_name);
if (!fc_host->devloss_work_q) {
VMKLNX_WARN("Error: Could not create FC Devloss WQ");
destroy_workqueue(fc_host->work_q);
fc_host->work_q = NULL;
return -ENOMEM;
}
/*
* This flag is used to catch cases where
* some drivers tend to do rport operation
* after fc_host is destroyed
*/
atomic_set(&fc_host->vmklnx_flag, VMKLNX_FC_HOST_READY);
return 0;
}
/*
*----------------------------------------------------------------------
*
* vmklnx_fc_host_setup
*
* Sets ups FC adapters and corresponding mgmt information
*
* Results:
* 0 on Success
*
* Side effects:
* None
*----------------------------------------------------------------------
*/
int vmklnx_fc_host_setup(struct Scsi_Host *shost)
{
int status;
VMK_ASSERT(shost);
/*
* Create Mgmt Adapter Instance to our management
*/
if ((status = FcLinuxAttachMgmtAdapter(shost))) {
vmk_WarningMessage("Failed to attach FC attributes to VMKernel");
return status;
}
if ((status = fc_host_setup(shost))) {
vmk_WarningMessage("Failed to setup FC attributes");
FcLinuxReleaseMgmtAdapter(shost);
return status;
}
return 0;
}
/*
*----------------------------------------------------------------------
*
* vmklnx_fcoe_host_setup
*
* Sets ups FCoE adapters and corresponding mgmt information
*
* Results:
* 0 on Success
*
* Side effects:
* None
*----------------------------------------------------------------------
*/
int vmklnx_fcoe_host_setup(struct Scsi_Host *shost)
{
int status;
VMK_ASSERT(shost);
/*
* Create Mgmt Adapter Instance to our management
*/
if ((status = FcoeLinuxAttachMgmtAdapter(shost))) {
vmk_WarningMessage("Failed to attach FCoE attributes to VMKernel");
return status;
}
if ((status = fc_host_setup(shost))) {
vmk_WarningMessage("Failed to setup FCoE attributes");
FcoeLinuxReleaseMgmtAdapter(shost);
return status;
}
return 0;
}
/*
*----------------------------------------------------------------------
*
* fc_host_free
*
* Free's up resources allocated to the FC host
*
* Returns:
* 0 on Success
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
void
fc_host_free(struct Scsi_Host *shost)
{
struct fc_host_attrs *fc_host;
struct workqueue_struct *work_q;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
/*
* Free up the WQ
*/
if (fc_host->work_q) {
work_q = fc_host->work_q;
fc_host->work_q = NULL;
destroy_workqueue(work_q);
}
if (fc_host->devloss_work_q) {
work_q = fc_host->devloss_work_q;
fc_host->devloss_work_q = NULL;
destroy_workqueue(work_q);
}
return;
}
/*
*----------------------------------------------------------------------
*
* vmklnx_fc_host_free
*
* Frees up fc host information
*
* Results:
* None
*
* Side effects:
* None
*----------------------------------------------------------------------
*/
void
vmklnx_fc_host_free(struct Scsi_Host *shost)
{
VMK_ASSERT(shost);
fc_host_free(shost);
FcLinuxReleaseMgmtAdapter(shost);
return;
}
/*
*----------------------------------------------------------------------
*
* vmklnx_fcoe_host_free
*
* Frees up fcoe host information
*
* Results:
* None
*
* Side effects:
* None
*----------------------------------------------------------------------
*/
void
vmklnx_fcoe_host_free(struct Scsi_Host *shost)
{
VMK_ASSERT(shost);
fc_host_free(shost);
FcoeLinuxReleaseMgmtAdapter(shost);
return;
}
/**
* fc_remove_host - Called to terminate any fc_transport related elements
* for a scsi host
* @shost: Pointer to struct Scsi_Host
*
* This routine is expected to be called immediately preceeding the
* call from the driver to scsi_remove_host()
*
* ESX Deviation Notes:
* Removes vports along with rports
*
* RETURN VALUE:
* None
*/
/* _VMKLNX_CODECHECK_: fc_remove_host */
void
fc_remove_host(struct Scsi_Host *shost)
{
struct fc_vport *vport, *next_vport;
struct fc_rport *rport, *next_rport;
struct fc_host_attrs *fc_host;
unsigned long flags;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
VMKLNX_DEBUG(0, "for %s", shost->hostt->name);
atomic_set(&fc_host->vmklnx_flag, VMKLNX_FC_HOST_REMOVING);
spin_lock_irqsave(shost->host_lock, flags);
/* Remove any vports */
list_for_each_entry_safe(vport, next_vport,
&fc_host->vports, peers) {
fc_queue_work(shost, &vport->vport_delete_work);
}
/* Remove any remote ports */
list_for_each_entry_safe(rport, next_rport,
&fc_host->rports, peers) {
list_del(&rport->peers);
rport->port_state = FC_PORTSTATE_DELETED;
fc_queue_work(shost, &rport->rport_delete_work);
}
list_for_each_entry_safe(rport, next_rport,
&fc_host->rport_bindings, peers) {
list_del(&rport->peers);
rport->port_state = FC_PORTSTATE_DELETED;
fc_queue_work(shost, &rport->rport_delete_work);
}
spin_unlock_irqrestore(shost->host_lock, flags);
/*
* Flush all work items
*/
fc_flush_devloss(shost);
fc_flush_work(shost);
/* flush all scan work items */
scsi_flush_work(shost);
/*
* The WQ associated with this request will be removed during the
* scsi_host_dev_release call
*/
return;
}
EXPORT_SYMBOL(fc_remove_host);
/*
*----------------------------------------------------------------------
*
* fc_rport_create ---
* allocates and creates a remote FC port.
*
* Results:
* Pointer to new rport that is created
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
struct fc_rport *
fc_rport_create(struct Scsi_Host *shost, int channel,
struct fc_rport_identifiers *ids)
{
struct fc_internal *fci;
struct fc_host_attrs *fc_host;
struct fc_rport *rport;
struct device *dev;
unsigned long flags;
size_t size;
int error;
VMK_ASSERT(shost);
VMK_ASSERT(shost->transportt);
VMK_ASSERT(ids);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
fci = to_fc_internal(shost->transportt);
size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size);
rport = (struct fc_rport *) kzalloc(size, GFP_KERNEL);
if (unlikely(!rport)) {
VMKLNX_WARN("allocation failure");
return NULL;
}
VMKLNX_DEBUG(2, "Start");
rport->maxframe_size = -1;
rport->supported_classes = FC_COS_UNSPECIFIED;
rport->dev_loss_tmo = fc_dev_loss_tmo;
memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name));
memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name));
rport->port_id = ids->port_id;
rport->roles = ids->roles;
rport->port_state = FC_PORTSTATE_ONLINE;
if (fci->f->dd_fcrport_size) {
rport->dd_data = &rport[1];
}
rport->channel = channel;
rport->fast_io_fail_tmo = -1;
INIT_DELAYED_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport);
INIT_DELAYED_WORK(&rport->fail_io_work, fc_timeout_fail_rport_io);
INIT_WORK(&rport->scan_work, fc_scsi_scan_rport);
INIT_WORK(&rport->stgt_delete_work, fc_starget_delete);
INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete);
spin_lock_irqsave(shost->host_lock, flags);
rport->number = fc_host->next_rport_number++;
if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
rport->scsi_target_id = fc_host->next_target_id++;
} else {
rport->scsi_target_id = -1;
}
/*
* Add the rport to the list
*/
list_add_tail(&rport->peers, &fc_host->rports);
get_device(&shost->shost_gendev); /* for fc_host->rport list */
spin_unlock_irqrestore(shost->host_lock, flags);
/*
* Fill in references for the parents. This is used by scsi_alloc_target
*/
dev = &rport->dev;
device_initialize(dev);
dev->parent = get_device(&shost->shost_gendev); /* parent reference */
dev->dev_type = FC_RPORT_TYPE;
dev->release = fc_rport_dev_release;
sprintf(dev->bus_id, "rport-%d:%d-%d",
shost->host_no, channel, rport->number);
error = device_add(dev);
if (error) {
VMKLNX_WARN("FC Remote Port device_add failed");
spin_lock_irqsave(shost->host_lock, flags);
list_del(&rport->peers);
put_device(&shost->shost_gendev); /* for fc_host->rport list */
spin_unlock_irqrestore(shost->host_lock, flags);
put_device(dev->parent);
kfree(rport);
rport = NULL;
goto exit_rport_create;
}
if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
/* initiate a scan of the target */
rport->flags |= FC_RPORT_SCAN_PENDING;
vmk_AtomicInc64(&shost->pendingScanWorkQueueEntries);
scsi_queue_work(shost, &rport->scan_work);
}
exit_rport_create:
VMKLNX_DEBUG(2, "End");
return rport;
}
/**
* fc_remote_port_add - notifies the fc transport of the existence
* of a remote FC port
* @shost: scsi host the remote port is connected to
* @channel: Channel on shost port connected to
* @ids: The world wide names, fc address, and FC4 port
* roles for the remote port
*
* The LLDD calls this routine to notify the transport of the existence
* of a remote port. The LLDD provides the unique identifiers (wwpn,wwn)
* of the port, its FC address (port_id), and the FC4 roles that are
* active for the port.
*
* For ports that are FCP targets (aka scsi targets), the FC transport
* maintains consistent target id bindings on behalf of the LLDD.
* A consistent target id binding is an assignment of a target id to
* a remote port identifier, which persists while the scsi host is
* attached. The remote port can disappear, then later reappear, and
* its target id assignment remains the same. This allows for shifts
* in FC addressing (if binding by wwpn or wwnn) with no apparent
* changes to the scsi subsystem which is based on scsi host number and
* target id values. Bindings are only valid during the attachment of
* the scsi host. If the host detaches, then later reattaches, target
* id bindings may change. Whenever a remote port is allocated, a new
* fc_remote_port class device is created. This routine should not be
* called from interrupt context and assumes no locks are held on entry.
* The routine will search the list of remote ports it maintains
* internally on behalf of consistent target id mappings. If found, the
* remote port structure will be reused. Otherwise, a new remote port
* structure will be allocated.
*
* RETURN VALUE:
* Returns a remote port structure
*
**/
/* _VMKLNX_CODECHECK_: fc_remote_port_add */
struct fc_rport *
fc_remote_port_add(struct Scsi_Host *shost, int channel,
struct fc_rport_identifiers *ids)
{
struct fc_internal *fci;
struct fc_rport *rport;
unsigned long flags;
int match = 0;
struct fc_host_attrs *fc_host;
VMK_ASSERT(shost);
VMK_ASSERT(shost->transportt);
VMK_ASSERT(ids);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
if (atomic_read(&fc_host->vmklnx_flag) == VMKLNX_FC_HOST_REMOVING) {
VMKLNX_WARN("ERROR: FC host '%s' is being removed"
"can not add rports now", shost->hostt->name);
return NULL;
}
fci = to_fc_internal(shost->transportt);
/* ensure any stgt delete functions are done */
fc_flush_work(shost);
/*
* Search the list of "active" rports, for an rport that has been
* deleted, but we've held off the real delete while the target
* is in a "blocked" state.
*/
spin_lock_irqsave(shost->host_lock, flags);
list_for_each_entry(rport, &fc_host->rports, peers) {
if ((rport->port_state == FC_PORTSTATE_BLOCKED) &&
(rport->channel == channel)) {
switch (fc_host->tgtid_bind_type) {
case FC_TGTID_BIND_BY_WWPN:
case FC_TGTID_BIND_NONE:
if (rport->port_name == ids->port_name) {
match = 1;
}
break;
case FC_TGTID_BIND_BY_WWNN:
if (rport->node_name == ids->node_name) {
match = 1;
}
break;
case FC_TGTID_BIND_BY_ID:
if (rport->port_id == ids->port_id) {
match = 1;
}
break;
}
if (match) {
struct delayed_work *work = &rport->dev_loss_work;
memcpy(&rport->node_name, &ids->node_name,
sizeof(rport->node_name));
memcpy(&rport->port_name, &ids->port_name,
sizeof(rport->port_name));
rport->port_id = ids->port_id;
rport->port_state = FC_PORTSTATE_ONLINE;
rport->roles = ids->roles;
spin_unlock_irqrestore(shost->host_lock, flags);
if (fci->f->dd_fcrport_size) {
memset(rport->dd_data, 0, fci->f->dd_fcrport_size);
}
VMKLNX_DEBUG(2, "Active Port. Target Id %s:%d",
vmklnx_get_vmhba_name(shost),
rport->scsi_target_id);
/*
* If we were blocked, we were a target.
* If no longer a target, we leave the timer
* running in case the port changes roles
* prior to the timer expiring. If the timer
* fires, the target will be torn down.
*/
if (!(ids->roles & FC_RPORT_ROLE_FCP_TARGET)) {
return rport;
}
/* restart the target */
/*
* Stop the target timers first. Take no action
* on the del_timer failure as the state
* machine state change will validate the
* transaction.
*/
if (!cancel_delayed_work(&rport->fail_io_work)) {
fc_flush_devloss(shost);
}
if (!cancel_delayed_work(work)) {
fc_flush_devloss(shost);
}
spin_lock_irqsave(shost->host_lock, flags);
rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
/* initiate a scan of the target */
rport->flags |= FC_RPORT_SCAN_PENDING;
vmk_AtomicInc64(&shost->pendingScanWorkQueueEntries);
scsi_queue_work(shost, &rport->scan_work);
spin_unlock_irqrestore(shost->host_lock, flags);
scsi_target_unblock(&rport->dev);
return rport;
}
}
}
/* Search the bindings array */
if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) {
/* search for a matching consistent binding */
list_for_each_entry(rport, &fc_host->rport_bindings, peers) {
if (rport->channel != channel) {
continue;
}
VMKLNX_DEBUG(2, "In passive Queue. Target Id %s:%d",
vmklnx_get_vmhba_name(shost),
rport->scsi_target_id);
switch (fc_host->tgtid_bind_type) {
case FC_TGTID_BIND_BY_WWPN:
if (rport->port_name == ids->port_name) {
match = 1;
}
break;
case FC_TGTID_BIND_BY_WWNN:
if (rport->node_name == ids->node_name) {
match = 1;
}
break;
case FC_TGTID_BIND_BY_ID:
if (rport->port_id == ids->port_id) {
match = 1;
}
break;
case FC_TGTID_BIND_NONE: /* to keep compiler happy */
break;
}
if (match) {
list_move_tail(&rport->peers, &fc_host->rports);
break;
}
}
if (match) {
memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name));
memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name));
rport->port_id = ids->port_id;
rport->roles = ids->roles;
rport->port_state = FC_PORTSTATE_ONLINE;
if (fci->f->dd_fcrport_size) {
memset(rport->dd_data, 0, fci->f->dd_fcrport_size);
}
if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
/* initiate a scan of the target */
rport->flags |= FC_RPORT_SCAN_PENDING;
vmk_AtomicInc64(&shost->pendingScanWorkQueueEntries);
scsi_queue_work(shost, &rport->scan_work);
spin_unlock_irqrestore(shost->host_lock, flags);
scsi_target_unblock(&rport->dev);
} else {
spin_unlock_irqrestore(shost->host_lock, flags);
}
VMKLNX_DEBUG(2, "Passive Port");
return rport;
}
}
spin_unlock_irqrestore(shost->host_lock, flags);
/* No consistent binding found - create new remote port entry */
rport = fc_rport_create(shost, channel, ids);
vmk_ScsiAdapterEvent(((struct vmklnx_ScsiAdapter *)shost->adapter)->vmkAdapter,
VMK_SCSI_ADAPTER_EVENT_FC_NEW_TARGET);
return rport;
}
EXPORT_SYMBOL(fc_remote_port_add);
/**
* fc_remote_port_delete - notifies the fc transport that a remote
* port is no longer in existence
* @rport: The remote port that no longer exists
*
* The LLDD calls this routine to notify the transport that a remote
* port is no longer part of the topology. Although a port
* may no longer be part of the topology, it may persist in the remote
* ports displayed by the fc_host. This is done under 2 conditions. First,
* if the port was a scsi target, we delay its deletion by "blocking" it.
* This allows the port to temporarily disappear, then reappear without
* disrupting the SCSI device tree attached to it. During the "blocked"
* period the port will still exist.
* Second, if the port was a scsi target and disappears for longer than we
* expect, we'll delete the port and the tear down the SCSI device tree
* attached to it. However, we want to semi-persist the target id assigned
* to that port if it eventually does exist. The port structure will
* remain (although with minimal information) so that the target id
* bindings remails.
*
* If the remote port is not an FCP Target, it will be fully torn down
* and deallocated, including the fc_remote_port class device.
*
* If the remote port is an FCP Target, the port will be placed in a
* temporary blocked state. From the LLDD's perspective, the rport no
* longer exists. From the SCSI midlayer's perspective, the SCSI target
* exists, but all sdevs on it are blocked from further I/O. We can then
* expect the following two conditions. First, if the remote port does not
* return (signaled by a LLDD call to fc_remote_port_add())
* within the dev_loss_tmo timeout, then the scsi target is removed,
* thereby killing all outstanding i/o and removing the
* scsi devices attached ot it. The port structure will be marked Not
* Present and be partially cleared, leaving only enough information to
* recognize the remote port relative to the scsi target id binding if
* it later appears. The port will remain as long as there is a valid
* binding (e.g. until the user changes the binding type or unloads the
* scsi host with the binding).
*
* Second, if the remote port returns within the dev_loss_tmo value
* (and matches according to the target id binding type),
* the port structure will be reused. If it is no longer a SCSI target,
* the target will be torn down. If it continues to be a SCSI target,
* then the target will be unblocked (allowing i/o to be resumed),
* and a scan will be activated to ensure that all luns are detected.
*
* This function cannot be called from interrupt context and assumes no
* locks are held on entry.
*
* ESX Deviation Notes:
* The link timeout can be set by the driver in
* vmkAdapter->mgmtAdapter.t.fc->linkTimeout.
* The lesser of fast IO fail timeout of the rport and the
* link timeout is selected as the time period to wait before
* the rport is freed.
*
* RETURN VALUE:
* None
*
**/
/* _VMKLNX_CODECHECK_: fc_remote_port_delete */
void
fc_remote_port_delete(struct fc_rport *rport)
{
struct Scsi_Host *shost;
struct fc_internal *i;
int timeout;
unsigned long flags;
struct vmklnx_ScsiAdapter *vmklnx26ScsiAdapter;
vmk_ScsiAdapter *vmkAdapter;
struct fc_host_attrs *fc_host;
VMK_ASSERT(rport);
shost = rport_to_shost(rport);
VMK_ASSERT(shost);
VMK_ASSERT(shost->transportt);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
if (atomic_read(&fc_host->vmklnx_flag) == VMKLNX_FC_HOST_REMOVING) {
VMKLNX_WARN("ERROR: FC host '%s' is being removed"
"rports will be deleted as part of host removal",
shost->hostt->name);
return;
}
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
vmklnx26ScsiAdapter = (struct vmklnx_ScsiAdapter *) shost->adapter;
VMK_ASSERT(vmklnx26ScsiAdapter);
vmkAdapter = vmklnx26ScsiAdapter->vmkAdapter;
VMK_ASSERT(vmkAdapter);
VMK_ASSERT((vmkAdapter->mgmtAdapter.transport == VMK_STORAGE_ADAPTER_FC) ||
(vmkAdapter->mgmtAdapter.transport == VMK_STORAGE_ADAPTER_FCOE));
VMKLNX_DEBUG(2, "----");
/*
* No need to flush the fc_host work_q's, as all adds are synchronous.
*
* We do need to reclaim the rport scan work element, so eventually
* (in fc_rport_final_delete()) we'll flush the scsi host work_q if
* there's still a scan pending.
*/
spin_lock_irqsave(shost->host_lock, flags);
/* If no scsi target id mapping, delete it */
if (rport->scsi_target_id == -1) {
list_del(&rport->peers);
rport->port_state = FC_PORTSTATE_DELETED;
fc_queue_work(shost, &rport->rport_delete_work);
spin_unlock_irqrestore(shost->host_lock, flags);
VMKLNX_DEBUG(2, "Not a scsi target.. deleting----");
return;
}
rport->port_state = FC_PORTSTATE_BLOCKED;
rport->flags |= FC_RPORT_DEVLOSS_PENDING;
spin_unlock_irqrestore(shost->host_lock, flags);
scsi_target_block(&rport->dev);
/*
* If the user has set this value, use it. If not,
* use the value set by vmklinux or the FC driver
*/
if (unlikely(vmkAdapter->mgmtAdapter.transport == VMK_STORAGE_ADAPTER_FCOE)) {
timeout = vmkAdapter->mgmtAdapter.t.fcoe->fc.linkTimeout ?
vmkAdapter->mgmtAdapter.t.fcoe->fc.linkTimeout : rport->dev_loss_tmo;
} else {
timeout = vmkAdapter->mgmtAdapter.t.fc->linkTimeout ?
vmkAdapter->mgmtAdapter.t.fc->linkTimeout : rport->dev_loss_tmo;
}
/* see if we need to kill io faster than waiting for device loss */
if ((rport->fast_io_fail_tmo != -1) &&
(rport->fast_io_fail_tmo < timeout) && (i->f->terminate_rport_io))
fc_queue_devloss_work(shost, &rport->fail_io_work,
rport->fast_io_fail_tmo * HZ);
/* cap the length the devices can be blocked until they are deleted */
if (fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ) != 1) {
VMKLNX_DEBUG(2, "Failed to queue devloss----");
} else {
VMKLNX_DEBUG(2, "Link Timeout = %d, Target Id %s:%d",
timeout, vmklnx_get_vmhba_name(shost),
rport->scsi_target_id);
}
vmk_ScsiAdapterEvent(((struct vmklnx_ScsiAdapter *)shost->adapter)->vmkAdapter,
VMK_SCSI_ADAPTER_EVENT_FC_REMOVED_TARGET);
}
EXPORT_SYMBOL(fc_remote_port_delete);
/**
* fc_remote_port_rolechg - notifies the fc transport that the roles
* on a remote may have changed
* @rport: The remote port that changed
* @roles: Private (Transport-managed) Attribute
*
* The LLDD calls this routine to notify the transport that the roles
* on a remote port may have changed. The largest effect of this is
* if a port now becomes a FCP Target, it must be allocated a
* scsi target id. If the port is no longer a FCP target, any
* scsi target id value assigned to it will persist in case the
* role changes back to include FCP Target. No changes in the scsi
* midlayer will be invoked if the role changes (in the expectation
* that the role will be resumed. If it doesn't normal error processing
* will take place).
*
* Should not be called from interrupt context.
*
* Notes:
* This routine assumes no locks are held on entry
*
* RETURN VALUE:
* None
*
* ESX Deviation Notes:
* If the FC host is being removed, we do not change roles,
* but return immediately
**/
/* _VMKLNX_CODECHECK_: fc_remote_port_rolechg */
void
fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
{
struct Scsi_Host *shost;
struct fc_host_attrs *fc_host;
unsigned long flags;
int create = 0;
VMK_ASSERT(rport);
shost = rport_to_shost(rport);
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
if (atomic_read(&fc_host->vmklnx_flag) == VMKLNX_FC_HOST_REMOVING) {
VMKLNX_WARN("ERROR: FC host '%s' is being removed"
"can not role change now", shost->hostt->name);
return;
}
spin_lock_irqsave(shost->host_lock, flags);
if (roles & FC_RPORT_ROLE_FCP_TARGET) {
if (rport->scsi_target_id == -1) {
rport->scsi_target_id = fc_host->next_target_id++;
create = 1;
} else if (!(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
create = 1;
}
}
rport->roles = roles;
spin_unlock_irqrestore(shost->host_lock, flags);
if (create) {
/*
* There may have been a delete timer running on the
* port. Ensure that it is cancelled as we now know
* the port is an FCP Target.
* Note: we know the rport is exists and in an online
* state as the LLDD would not have had an rport
* reference to pass us.
*
* Take no action on the del_timer failure as the state
* machine state change will validate the
* transaction.
*/
if (!cancel_delayed_work(&rport->fail_io_work)) {
fc_flush_devloss(shost);
}
if (!cancel_delayed_work(&rport->dev_loss_work)) {
fc_flush_devloss(shost);
}
spin_lock_irqsave(shost->host_lock, flags);
rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
spin_unlock_irqrestore(shost->host_lock, flags);
/* ensure any stgt delete functions are done */
fc_flush_work(shost);
/* initiate a scan of the target */
spin_lock_irqsave(shost->host_lock, flags);
rport->flags |= FC_RPORT_SCAN_PENDING;
vmk_AtomicInc64(&shost->pendingScanWorkQueueEntries);
scsi_queue_work(shost, &rport->scan_work);
spin_unlock_irqrestore(shost->host_lock, flags);
scsi_target_unblock(&rport->dev);
}
}
EXPORT_SYMBOL(fc_remote_port_rolechg);
/*
*----------------------------------------------------------------------
*
* fc_timeout_deleted_rport - Timeout handler for a deleted remote port that
* was a SCSI target (thus was blocked), and failed
* to return in the alloted time.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void
fc_timeout_deleted_rport(struct work_struct *work)
{
struct fc_rport *rport;
struct Scsi_Host *shost;
struct fc_host_attrs *fc_host;
unsigned long flags;
rport = container_of(work, struct fc_rport, dev_loss_work.work);
shost = rport_to_shost(rport);
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
VMKLNX_DEBUG(2, "----");
spin_lock_irqsave(shost->host_lock, flags);
rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
/*
* If the port is ONLINE, then it came back. Validate it's still an
* FCP target. If not, tear down the scsi_target on it.
*/
if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
!(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
dev_printk(KERN_ERR, &rport->dev,
"blocked FC remote port time out: no longer"
" a FCP target, removing starget\n");
spin_unlock_irqrestore(shost->host_lock, flags);
scsi_target_unblock(&rport->dev);
fc_queue_work(shost, &rport->stgt_delete_work);
return;
}
if (rport->port_state != FC_PORTSTATE_BLOCKED) {
spin_unlock_irqrestore(shost->host_lock, flags);
dev_printk(KERN_ERR, &rport->dev,
"blocked FC remote port time out: leaving target alone\n");
return;
}
if (fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) {
list_del(&rport->peers);
rport->port_state = FC_PORTSTATE_DELETED;
dev_printk(KERN_ERR, &rport->dev,
"blocked FC remote port time out: removing target\n");
fc_queue_work(shost, &rport->rport_delete_work);
spin_unlock_irqrestore(shost->host_lock, flags);
return;
}
if (fc_remove_on_dev_loss) {
dev_printk(KERN_ERR, &rport->dev,
"blocked FC remote port time out: removing target and "
"saving binding\n");
} else {
dev_printk(KERN_ERR, &rport->dev,
"blocked FC remote port time out: saving binding\n");
}
list_move_tail(&rport->peers, &fc_host->rport_bindings);
/*
* Note: We do not remove or clear the hostdata area. This allows
* host-specific target data to persist along with the
* scsi_target_id. It's up to the host to manage it's hostdata area.
*/
/*
* Reinitialize port attributes that may change if the port comes back.
*/
rport->maxframe_size = -1;
rport->supported_classes = FC_COS_UNSPECIFIED;
rport->roles = FC_RPORT_ROLE_UNKNOWN;
rport->port_state = FC_PORTSTATE_NOTPRESENT;
/* remove the identifiers that aren't used in the consisting binding */
switch (fc_host->tgtid_bind_type) {
case FC_TGTID_BIND_BY_WWPN:
rport->node_name = -1;
rport->port_id = -1;
break;
case FC_TGTID_BIND_BY_WWNN:
rport->port_name = -1;
rport->port_id = -1;
break;
case FC_TGTID_BIND_BY_ID:
rport->node_name = -1;
rport->port_name = -1;
break;
case FC_TGTID_BIND_NONE: /* to keep compiler happy */
break;
}
/*
* As this only occurs if the remote port (scsi target)
* went away and didn't come back - we'll remove
* all attached scsi devices.
*/
spin_unlock_irqrestore(shost->host_lock, flags);
scsi_target_unblock(&rport->dev);
fc_queue_work(shost, &rport->stgt_delete_work);
}
/*
*----------------------------------------------------------------------
*
* fc_timeout_fail_rport_io - Timeout handler for a fast io failing on a
* disconnected SCSI target.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void
fc_timeout_fail_rport_io(struct work_struct *work)
{
struct fc_rport *rport;
struct Scsi_Host *shost;
struct fc_internal *i;
rport = container_of(work, struct fc_rport, fail_io_work.work);
shost = rport_to_shost(rport);
VMK_ASSERT(shost);
VMK_ASSERT(shost->transportt);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
VMKLNX_DEBUG(2, "----");
if (rport->port_state != FC_PORTSTATE_BLOCKED) {
return;
}
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost),
i->f->terminate_rport_io, rport);
}
/*
*----------------------------------------------------------------------
*
* fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void
fc_scsi_scan_rport(struct work_struct *work)
{
struct fc_rport *rport;
struct Scsi_Host *shost;
unsigned long flags;
rport = container_of(work, struct fc_rport, scan_work);
shost = rport_to_shost(rport);
VMK_ASSERT(shost);
if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
scsi_scan_target(&rport->dev, rport->channel,
rport->scsi_target_id, SCAN_WILD_CARD, 1);
}
spin_lock_irqsave(shost->host_lock, flags);
rport->flags &= ~FC_RPORT_SCAN_PENDING;
vmk_AtomicDec64(&shost->pendingScanWorkQueueEntries);
spin_unlock_irqrestore(shost->host_lock, flags);
}
/**
* scsi_is_fc_rport - Check if the scsi device is fc rport
* @dev: scsi device
*
* Check if the scsi device is fc rport
*
* RETURN VALUE:
* TRUE if the device is a fc rport, FALSE otherwise
*----------------------------------------------------------------------
*/
/* _VMKLNX_CODECHECK_: scsi_is_fc_rport */
int
scsi_is_fc_rport(const struct device *dev)
{
return dev->dev_type == FC_RPORT_TYPE;
}
EXPORT_SYMBOL(scsi_is_fc_rport);
/**
* fc_get_event_number - obtain the next sequential FC event number
*
* Returns the next sequential FC event number
*
* RETURN VALUE:
* The next sequential FC event number
*/
/* _VMKLNX_CODECHECK_: fc_get_event_number */
u32
fc_get_event_number(void)
{
return atomic_add_return(1, &fc_event_seq);
}
EXPORT_SYMBOL(fc_get_event_number);
/**
* fc_host_post_vendor_event - non-operational function
* @shost: ignored
* @event_number: ignored
* @data_len: ignored
* @data_buf: ignored
* @vendor_id: ignored
*
* This function is a non-operational function provided to help reduce
* kernel ifdefs. It is not supported in this release of ESX.
*
* ESX Deviation Notes:
* This function is a non-operational function provided to help reduce
* kernel ifdefs. It is not supported in this release of ESX.
*
* RETURN VALUE:
* This function does not return a value
*/
/* _VMKLNX_CODECHECK_: fc_host_post_vendor_event */
void
fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
u32 data_len, char * data_buf, u64 vendor_id)
{
VMK_ASSERT(shost);
VMKLNX_DEBUG(5, "Netlink is not supported in vmklinux "
"So no notifications were sent");
return;
}
EXPORT_SYMBOL(fc_host_post_vendor_event);
/**
* fc_host_post_event - non-operational function
* @shost: ignored
* @event_number: ignored
* @event_code: ignored
* @event_data: ignored
*
* This function is not implemented.
*
* This function is a non-operational function provided to help reduce
* kernel ifdefs. It is not supported in this release of ESX.
*
* ESX Deviation Notes:
* This function is a non-operational function provided to help reduce
* kernel ifdefs. It is not supported in this release of ESX.
*
* RETURN VALUE:
* This function does not return a value
*/
/* _VMKLNX_CODECHECK_: fc_host_post_event */
void
fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
enum fc_host_event_code event_code, u32 event_data)
{
VMK_ASSERT(shost);
VMKLNX_DEBUG(5, "Netlink is not supported in vmklinux "
"So no notifications were sent up [%x]", event_code);
return;
}
EXPORT_SYMBOL(fc_host_post_event);
/*
*----------------------------------------------------------------------
*
* fc_queue_work --
*
* Queue work to the fc_host workqueue.
*
* Results:
* 1 - work queued for execution
* 0 - work is already queued
* -EINVAL - work queue doesn't exist
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static int
fc_queue_work(struct Scsi_Host *shost, struct work_struct *work)
{
VMK_ASSERT(shost);
VMK_ASSERT(work);
if (unlikely(!fc_host_work_q(shost))) {
VMKLNX_WARN("ERROR: FC host '%s' attempted to queue work, "
"when no workqueue created.", shost->hostt->name);
return -EINVAL;
}
return queue_work(fc_host_work_q(shost), work);
}
/*
*----------------------------------------------------------------------
*
* fc_flush_work --
*
* Flush a fc_host's workqueue.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void
fc_flush_work(struct Scsi_Host *shost)
{
VMK_ASSERT(shost);
if (!fc_host_work_q(shost)) {
VMKLNX_WARN("ERROR: FC host '%s' attempted to flush work, "
"when no workqueue created.", shost->hostt->name);
return;
}
flush_workqueue(fc_host_work_q(shost));
}
/*
*----------------------------------------------------------------------
*
* fc_queue_devloss_work --
*
* Schedule work for the fc_host devloss workqueue.
*
* Results:
* 1 on success / 0 already queued / < 0 for error
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static int
fc_queue_devloss_work(struct Scsi_Host *shost, struct delayed_work *dwork,
unsigned long delay)
{
VMK_ASSERT(shost);
VMK_ASSERT(dwork);
if (unlikely(!fc_host_devloss_work_q(shost))) {
VMKLNX_WARN("ERROR: FC host '%s' attempted to queue work, "
"when no workqueue created.", shost->hostt->name);
return -EINVAL;
}
#if defined(VMX86_DEBUG)
if (delay != 0) {
/*
* Log the delay
*/
VMKLNX_DEBUG(2, "Delayed work = 0x%"VMK_FMT64"x", delay);
}
#endif /* defined(VMX86_DEBUG) */
return queue_delayed_work(fc_host_devloss_work_q(shost), dwork, delay);
}
/*
*----------------------------------------------------------------------
*
* fc_flush_devloss ---
*
* Flush a fc_host's devloss workqueue.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void
fc_flush_devloss(struct Scsi_Host *shost)
{
VMK_ASSERT(shost);
if (!fc_host_devloss_work_q(shost)) {
VMKLNX_WARN("ERROR: FC host '%s' attempted to flush work, "
"when no workqueue created.", shost->hostt->name);
return;
}
flush_workqueue(fc_host_devloss_work_q(shost));
}
/*
*----------------------------------------------------------------------
*
* fc_starget_delete ---
*
* Called to delete the scsi decendents of an rport (target and all sdevs)
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void
fc_starget_delete(struct work_struct *work)
{
struct fc_rport *rport;
struct Scsi_Host *shost;
unsigned long flags;
struct fc_internal *i;
struct fc_host_attrs *fc_host;
rport = container_of(work, struct fc_rport, stgt_delete_work);
shost = rport_to_shost(rport);
VMK_ASSERT(shost);
VMK_ASSERT(shost->transportt);
fc_host = shost_to_fc_host(shost);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
/*
* Involve the LLDD if possible. All io on the rport is to
* be terminated, either as part of the dev_loss_tmo callback
* processing, or via the terminate_rport_io function.
*/
if (i->f->dev_loss_tmo_callbk) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost),
i->f->dev_loss_tmo_callbk, rport);
} else if (i->f->terminate_rport_io) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost),
i->f->terminate_rport_io, rport);
}
spin_lock_irqsave(shost->host_lock, flags);
if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
spin_unlock_irqrestore(shost->host_lock, flags);
if (!cancel_delayed_work(&rport->fail_io_work)) {
fc_flush_devloss(shost);
}
if (!cancel_delayed_work(&rport->dev_loss_work)) {
fc_flush_devloss(shost);
}
spin_lock_irqsave(shost->host_lock, flags);
rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
}
spin_unlock_irqrestore(shost->host_lock, flags);
/*
* Try to remove the target when fc_host is in
* the process of being released
*/
if ((fc_remove_on_dev_loss) ||
(atomic_read(&fc_host->vmklnx_flag) == VMKLNX_FC_HOST_REMOVING)) {
scsi_remove_target(&rport->dev);
} else {
VMKLNX_DEBUG(2, "Marking the target offline");
vmklnx_scsi_target_offline(&rport->dev);
}
}
/*
*----------------------------------------------------------------------
*
* fc_rport_final_delete ---
* finish rport termination and delete it.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void
fc_rport_final_delete(struct work_struct *work)
{
struct fc_rport *rport;
struct Scsi_Host *shost;
struct fc_internal *i;
struct device *dev;
rport = container_of(work, struct fc_rport, rport_delete_work);
shost = rport_to_shost(rport);
VMK_ASSERT(shost);
VMK_ASSERT(shost->transportt);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
dev = &rport->dev;
/*
* if a scan is pending, flush the SCSI Host work_q so that
* that we can reclaim the rport scan work element.
*/
if (rport->flags & FC_RPORT_SCAN_PENDING) {
scsi_flush_work(shost);
}
/* Delete SCSI target and sdevs */
if (rport->scsi_target_id != -1) {
fc_starget_delete(&rport->stgt_delete_work);
} else if (i->f->dev_loss_tmo_callbk) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->dev_loss_tmo_callbk,
rport);
} else if (i->f->terminate_rport_io) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost), i->f->terminate_rport_io,
rport);
}
device_del(dev);
put_device(&shost->shost_gendev); /* for fc_host->rport list */
put_device(dev); /* for self-reference */
}
/*
* NPIV support code
*/
/**
* vmk_fc_vport_create - allocates and creates a FC virtual port.
* Allocates and creates the vport structure, calls the parent host
* to instantiate the vport, the completes w/ class and sysfs creation.
* shost - physical host to create vport on
* channel - unused
* pdev - parent device
* args - virtual port data passed in, wwn, etc.
*
* Notes:
* This routine assumes no locks are held on entry.
**/
int
vmk_fc_vport_create(struct Scsi_Host *shost,
int channel, struct device *pdev,
void *data)
{
struct fc_host_attrs *fc_host;
struct fc_internal *fci;
struct fc_vport *vport;
struct device *dev;
struct vmk_VportData *args;
unsigned long flags;
size_t size;
int error;
VMK_ASSERT(shost);
VMK_ASSERT(pdev);
args = (struct vmk_VportData *) data;
VMK_ASSERT(args);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
fci = to_fc_internal(shost->transportt);
VMK_ASSERT(fci);
if ( ! fci->f->vport_create) {
return -ENOENT;
}
size = (sizeof(struct fc_vport) + fci->f->dd_fcvport_size);
vport = (struct fc_vport *)kzalloc(size, GFP_KERNEL);
if (unlikely(!vport)) {
VMKLNX_DEBUG(2, "allocation failure");
return -ENOMEM;
}
vport->vport_state = FC_VPORT_UNKNOWN;
vport->vport_last_state = FC_VPORT_UNKNOWN;
vport->node_name = wwn_to_u64(args->node_name);
vport->port_name = wwn_to_u64(args->port_name);
// we are always an initiator for now
vport->roles = FC_PORT_ROLE_FCP_INITIATOR;
vport->vport_type = FC_PORTTYPE_NPIV;
if (fci->f->dd_fcvport_size) {
vport->dd_data = &vport[1];
}
vport->shost = shost;
vport->channel = channel;
vport->flags = FC_VPORT_CREATING;
if (args->options & VMK_SCSI_VPORT_TYPE_LEGACY) {
vport->flags |= FC_VPORT_LEGACY;
}
INIT_WORK(&vport->vport_delete_work, fc_vport_sched_delete);
spin_lock_irqsave(shost->host_lock, flags);
if (fc_host->npiv_vports_inuse >= fc_host->max_npiv_vports) {
spin_unlock_irqrestore(shost->host_lock, flags);
kfree(vport);
return -ENOSPC;
}
fc_host->npiv_vports_inuse++;
vport->number = fc_host->next_vport_number++;
list_add_tail(&vport->peers, &fc_host->vports);
get_device(&shost->shost_gendev); /* for fc_host->vport list */
spin_unlock_irqrestore(shost->host_lock, flags);
dev = &vport->dev;
device_initialize(dev); /* takes self reference */
dev->parent = get_device(pdev); /* takes parent reference */
dev->dev_type = FC_VPORT_TYPE;
dev->release = fc_vport_dev_release;
sprintf(dev->bus_id, "vport-%d:%d-%d",
shost->host_no, channel, vport->number);
error = device_add(dev);
if (error) {
VMKLNX_DEBUG(0, "FC Virtual Port device_add failed");
goto delete_vport;
}
/*
* call the driver to do the actual virtual port create
* this in turn will create a Scsi_Host struct to
* represent this vport
*/
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), error,
fci->f->vport_create, vport, FALSE);
if (error) {
VMKLNX_DEBUG(0, "FC Virtual Port LLDD Create failed");
goto delete_vport_all;
}
spin_lock_irqsave(shost->host_lock, flags);
vport->flags &= ~FC_VPORT_CREATING;
spin_unlock_irqrestore(shost->host_lock, flags);
VMKLNX_DEBUG(0, "%s created via shost%d channel %d", dev->bus_id,
shost->host_no, channel);
// need to return the vport shost pointer
args->vport_shost = vport->vhost;
vmk_ScsiAdapterEvent(((struct vmklnx_ScsiAdapter *)shost->adapter)->vmkAdapter,
VMK_SCSI_ADAPTER_EVENT_FC_NEW_VPORT);
return 0;
delete_vport_all:
device_del(dev);
delete_vport:
spin_lock_irqsave(shost->host_lock, flags);
list_del(&vport->peers);
put_device(&shost->shost_gendev); /* for fc_host->vport list */
fc_host->npiv_vports_inuse--;
spin_unlock_irqrestore(shost->host_lock, flags);
put_device(dev->parent);
kfree(vport);
return error;
}
int vmk_fc_vport_delete(struct Scsi_Host *shost)
{
struct fc_vport *vport;
VMK_ASSERT(shost);
if (shost->shost_gendev.parent->dev_type != FC_VPORT_TYPE) {
return -ENOENT;
}
vport = dev_to_vport(shost->shost_gendev.parent);
VMK_ASSERT(vport);
return (vmk_fc_vport_terminate(vport));
}
/**
* fc_vport_sched_delete - workq-based delete request for a vport
*
* @work: vport to be deleted.
**/
static void
fc_vport_sched_delete(struct work_struct *work)
{
struct fc_vport *vport;
int stat;
vport = container_of(work, struct fc_vport, vport_delete_work);
VMK_ASSERT(vport);
stat = vmk_fc_vport_terminate(vport);
if (stat) {
VMKLNX_DEBUG(0, "%s could not be deleted created via "
"shost%d channel %d - error %d",
vport->dev.bus_id, vport->shost->host_no,
vport->channel, stat);
}
}
/**
* Calls the LLDD vport_delete() function, then deallocates and removes
* the vport from the shost and object tree.
*
* Notes:
* This routine assumes no locks are held on entry.
**/
static int
vmk_fc_vport_terminate(struct fc_vport *vport)
{
struct Scsi_Host *shost;
struct fc_host_attrs *fc_host;
struct fc_internal *i;
struct device *dev;
unsigned long flags;
int stat;
VMK_ASSERT(vport);
shost = vport_to_shost(vport);
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
dev = &vport->dev;
VMK_ASSERT(dev);
spin_lock_irqsave(shost->host_lock, flags);
if (vport->flags & FC_VPORT_CREATING) {
spin_unlock_irqrestore(shost->host_lock, flags);
return -EBUSY;
}
if (vport->flags & (FC_VPORT_DEL)) {
spin_unlock_irqrestore(shost->host_lock, flags);
return -EALREADY;
}
vport->flags |= FC_VPORT_DELETING;
spin_unlock_irqrestore(shost->host_lock, flags);
if (i->f->vport_delete) {
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), stat,
i->f->vport_delete, vport);
} else {
stat = -ENOENT;
}
spin_lock_irqsave(shost->host_lock, flags);
vport->flags &= ~FC_VPORT_DELETING;
if (!stat) {
vport->flags |= FC_VPORT_DELETED;
list_del(&vport->peers);
fc_host->npiv_vports_inuse--;
put_device(&shost->shost_gendev); /* for fc_host->vport list */
}
spin_unlock_irqrestore(shost->host_lock, flags);
if (stat)
return stat;
device_del(dev);
/*
* Removing our self-reference should mean our
* release function gets called, which will drop the remaining
* parent reference and free the data structure.
*/
put_device(dev); /* for self-reference */
vmk_ScsiAdapterEvent(((struct vmklnx_ScsiAdapter *)shost->adapter)->vmkAdapter,
VMK_SCSI_ADAPTER_EVENT_FC_REMOVED_VPORT);
return 0; /* SUCCESS */
}
/*
* vmk_fc_vport_getinfo
*
*/
int
vmk_fc_vport_getinfo(struct Scsi_Host *shost, void *info)
{
struct vmk_VportInfo *pi;
struct fc_host_attrs *fc_host;
struct fc_vport *vport;
struct fc_internal *i;
VMK_ASSERT(shost);
if ((struct vmklnx_ScsiModule *)shost->transportt->module == NULL ||
((struct vmklnx_ScsiModule *)shost->transportt->module)->transportType !=
VMKLNX_SCSI_TRANSPORT_TYPE_FC ) {
VMKLNX_DEBUG(2, "vmk_fc_vport_getinfo: not supported: shost=%p", shost);
return -ENOENT;
}
i = to_fc_internal(shost->transportt);
VMK_ASSERT(i);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
if (fc_host->port_type == FC_PORTTYPE_UNKNOWN) {
if (i->f && i->f->get_host_port_type) {
VMKAPI_MODULE_CALL_VOID(SCSI_GET_MODULE_ID(shost),
i->f->get_host_port_type, shost);
}
/* If port type is still unknown, bail out */
if (fc_host->port_type == FC_PORTTYPE_UNKNOWN) {
VMKLNX_DEBUG(2, "FC port type is unknown shost=%p", shost);
return -ENOENT;
}
}
/*
* make sure this is not a vport before we check for vport capability
*/
if (i->f && (fc_host->port_type != FC_PORTTYPE_NPIV &&
(! i->f->vport_create))) {
VMKLNX_DEBUG(2, "vmk_fc_vport_getinfo: not supported2:"
" shost=%p, i=%p, f=%p", shost, i, i->f);
return -ENOENT;
}
VMK_ASSERT(info);
pi = (struct vmk_VportInfo *) info;
VMKLNX_DEBUG(2, "vmk_fc_vport_getinfo: shost=%p, info=%p", shost, info);
/*
* If this is not a physical Host, fill in something else
*/
if (fc_host->port_type == FC_PORTTYPE_NPIV) {
vport = dev_to_vport(&shost->shost_gendev);
VMK_ASSERT(vport);
pi->linktype = VMK_VPORT_TYPE_VIRTUAL;
pi->vports_max = VMK_VPORT_CNT_INVALID;
pi->vports_inuse = VMK_VPORT_CNT_INVALID;
pi->rpi_max = VMK_VPORT_CNT_INVALID;
pi->rpi_inuse = VMK_VPORT_CNT_INVALID;
goto check_state;
}
VMKLNX_DEBUG(2, "vmk_fc_vport_getinfo: physical port: shost=%p, info=%p",
shost, info);
/*
* must be a physical port
* just fill in the important blanks
*/
pi->vports_max = fc_host->max_npiv_vports;
/*
* PR 266660 - some drivers set max_npiv_vports
* to VMK_VPORT_CNT_INVALID from a u16.
* max_npiv_vports is a u32 and so is vports_max.
*/
if (pi->vports_max == 0xffff) {
VMKLNX_DEBUG(0, "vmk_fc_vport_getinfo: PR 266660: vports_max=%x",
pi->vports_max);
pi->vports_max = VMK_VPORT_CNT_INVALID;
}
pi->vports_inuse = fc_host->npiv_vports_inuse;
pi->linktype = VMK_VPORT_TYPE_PHYSICAL;
pi->fail_reason = VMK_VPORT_FAIL_UNKNOWN;
pi->prev_fail_reason = VMK_VPORT_FAIL_UNKNOWN;
u64_to_wwn(fc_host->node_name, pi->node_name);
u64_to_wwn(fc_host->port_name, pi->port_name);
/*
* check the state
*/
check_state:
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_OFFLINE:
case FC_PORTSTATE_NOTPRESENT:
case FC_PORTSTATE_BLOCKED:
pi->state = VMK_VPORT_STATE_OFFLINE;
break;
case FC_PORTSTATE_ONLINE:
pi->state = VMK_VPORT_STATE_ACTIVE;
break;
default:
pi->state = VMK_VPORT_STATE_FAILED;
break;
}
/*
* set the version we are supporting
*/
pi->api_version = VMK_VPORT_API_VERSION;
return 0;
}
/*
* vmk_fc_vport_suspend
* Suspend/Resume vport = Disable/Enable vport
*/
int
vmk_fc_vport_suspend(struct Scsi_Host *shost, int suspend)
{
struct fc_vport *vport;
int error;
struct fc_host_attrs *fc_host;
struct fc_internal *fci;
bool disable;
VMK_ASSERT(shost);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
fci = to_fc_internal(shost->transportt);
VMK_ASSERT(fci);
if (!fci->f->vport_disable) {
return -ENOENT;
}
if (shost->shost_gendev.parent->dev_type != FC_VPORT_TYPE) {
return -ENOENT;
}
vport = dev_to_vport(shost->shost_gendev.parent);
VMK_ASSERT(vport);
disable = (suspend != 0) ? TRUE : FALSE;
VMKAPI_MODULE_CALL(SCSI_GET_MODULE_ID(shost), error,
fci->f->vport_disable, vport, disable);
return error;
}
/*
* SAS transport functions
*/
/*
* SAS host attributes
*/
/**
*
* \globalfn vmklnx_sas_host_setup -- initialize sas_host_attrs
*
* \param shost pointer to a Scsi_Host structure
* \return 0 for SUCCESS; negative values if failed
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
*
* \sa None.
* \comments -
*
*/
int vmklnx_sas_host_setup(struct Scsi_Host *shost)
{
struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
if (sas_host) {
if ((sas_host->rphy_list.prev == NULL) ||
(sas_host->rphy_list.next == NULL)) {
/*
* sas_host_attrs has not been initialized yet.
*/
INIT_LIST_HEAD(&sas_host->rphy_list);
mutex_init(&sas_host->lock);
sas_host->next_target_id = 0;
INIT_LIST_HEAD(&sas_host->freed_rphy_list);
sas_host->next_expander_id = 0;
sas_host->next_port_id = 0;
/*
* Create Mgmt Adapter Instance to our management
*/
if (SasLinuxAttachMgmtAdapter(shost)) {
return -ENOMEM;
}
}
return 0;
} else {
return(-1);
}
}
/**
* sas_phy_free - free a SAS PHY
* @phy: SAS PHY to free
*
* Frees the specified SAS PHY.
*
*/
/* _VMKLNX_CODECHECK_: sas_phy_free */
void sas_phy_free(struct sas_phy *phy)
{
}
EXPORT_SYMBOL(sas_phy_free);
/**
* sas_phy_add - add a SAS to the device hierarchy
* @phy: a pointer to a sas_phy structure
*
* Adds a SAS to the device hierarchy.
*
* RETURN VALUE:
* 0 if success; otherwise -errno.
*/
/* _VMKLNX_CODECHECK_: sas_phy_add */
int sas_phy_add(struct sas_phy *phy)
{
int error;
error = device_add(&phy->dev);
return error;
}
EXPORT_SYMBOL(sas_phy_add);
/**
* sas_phy_alloc - allocate an intialize a SAS PHY structure
* @parent: parent device to connect sas phy structure to
* @number: a PHY index
*
* Allocates and intializes a SAS PHY structure. It will be added as a child in
* the device tree to the specified @parent. @parent must be a Scsi_Host or
* sas_rphy
*
*/
/* _VMKLNX_CODECHECK_: sas_phy_alloc */
struct sas_phy *sas_phy_alloc(struct device *parent, int number)
{
struct Scsi_Host *shost;
struct sas_phy *phy;
shost = dev_to_shost(parent);
VMK_ASSERT(shost);
phy = (struct sas_phy *)kzalloc(sizeof(struct sas_phy), GFP_KERNEL);
if (!phy)
return NULL;
device_initialize(&phy->dev);
phy->number = number;
phy->dev.parent = get_device(parent);
phy->dev.dev_type = SAS_PHY_DEVICE_TYPE;
phy->dev.release = sas_phy_release;
INIT_LIST_HEAD(&phy->port_siblings);
if (scsi_is_sas_expander_device(parent)) {
struct sas_rphy *rphy = dev_to_rphy(parent);
sprintf(phy->dev.bus_id, "phy-%d:%d:%d", shost->host_no,
rphy->scsi_target_id, number);
} else
sprintf(phy->dev.bus_id, "phy-%d:%d", shost->host_no, number);
return phy;
}
EXPORT_SYMBOL(sas_phy_alloc);
/**
* sas_rphy_free - free a SAS remote PHY
* @rphy: SAS remote PHY to free
*
* Frees the specified SAS remote PHY.
* This function must only be called on a remote PHY that has not sucessfully
* been added using sas_rphy_add().
*
* RETURN VALUE:
* None
*/
/* _VMKLNX_CODECHECK_: sas_rphy_free */
void sas_rphy_free(struct sas_rphy *rphy)
{
struct device *dev;
struct Scsi_Host *shost = NULL;
struct sas_host_attrs *sas_host = NULL;
VMK_ASSERT(rphy);
dev = &rphy->dev;
shost = dev_to_shost(rphy->dev.parent->parent);
VMK_ASSERT(shost);
sas_host = to_sas_host_attrs(shost);
VMK_ASSERT(sas_host);
mutex_lock(&sas_host->lock);
list_del(&rphy->list);
mutex_unlock(&sas_host->lock);
put_device(dev);
}
EXPORT_SYMBOL(sas_rphy_free);
/**
* sas_scsi_target_reparent - reparent the scsi_target to new rphy passed in
*/
static int
sas_scsi_target_reparent(struct device *dev, void *data)
{
struct scsi_target *stgt = to_scsi_target(dev);
struct sas_rphy *new_rphy = (struct sas_rphy *)data;
int error;
VMKLNX_DEBUG(5, "Entered for dev: %p stgt: %p shost:%p "
"new_rphy: %p", dev, stgt, dev_to_shost(dev), new_rphy);
if (dev && stgt) {
VMKLNX_DEBUG(5, "stgt: %p - refcount on "
"entry:%d parent:%p", stgt,
atomic_read(&stgt->dev.kref.refcount),
dev->parent);
/* reparent the scsi_target to the new rphy parent */
get_device(dev);
device_del(dev);
dev->parent = get_device(&new_rphy->dev);
error = device_add(dev);
if (error) {
VMKLNX_DEBUG(1, "stgt: %p - device_add to new rphy failed",
stgt);
}
scsi_target_unblock(&stgt->dev);
put_device(dev);
VMKLNX_DEBUG(5, "stgt: %p - refcount on "
"exit:%d parent:%p", stgt,
atomic_read(&stgt->dev.kref.refcount),
dev->parent);
}
return 0;
}
/**
* sas_assign_scsi_target_id - assign a scsi target id to the SAS device
*
* if previously removed dev
* reparent to new rphy and (re)assign old target id
* else
* assign next target id
*
* Returns 1 if a new id was assigned and 0 if none
*/
static int
sas_assign_scsi_target_id(struct sas_rphy *rphy,
struct sas_host_attrs *sas_host)
{
struct sas_rphy *t_rphy;
struct sas_port *parent;
struct Scsi_Host *shost;
VMKLNX_DEBUG(5, "Looking for sas_address 0x%llx rphy:%p",
rphy->identify.sas_address, rphy);
VMK_ASSERT(rphy);
parent = dev_to_sas_port(rphy->dev.parent);
VMK_ASSERT(parent);
shost = dev_to_shost(parent->dev.parent);
VMK_ASSERT(shost);
list_for_each_entry(t_rphy, &sas_host->freed_rphy_list, list) {
VMKLNX_DEBUG(5, "Examining sas_address 0x%llx "
"(matching with 0x%llx) t_rphy:%p rphy:%p",
t_rphy->identify.sas_address,
rphy->identify.sas_address, t_rphy, rphy);
if (t_rphy->identify.sas_address == rphy->identify.sas_address) {
/*
* The children of this rphy are scsi_target structs.
* Walk every child and reparent it to new rphy
*/
device_for_each_child_safe(&t_rphy->dev, rphy,
sas_scsi_target_reparent);
VMKLNX_DEBUG(5,
"Assigning target id %d for sas_address 0x%llx from "
"freed list; old rphy->scsi_target_id:0x%d; rphy:0x%p "
"t_rphy:0x%p", t_rphy->scsi_target_id,
rphy->identify.sas_address, rphy->scsi_target_id, rphy,
t_rphy);
/* Now assign the old target id to the new rphy */
rphy->scsi_target_id = t_rphy->scsi_target_id;
list_del(&t_rphy->list);
VMKLNX_DEBUG(5, "t_rphy: %p - refcount before "
"put_device: %d", t_rphy,
atomic_read(&t_rphy->dev.kref.refcount));
/* There is a new rphy now. The old one can now be released */
put_device(&t_rphy->dev);
return 0;
}
}
rphy->scsi_target_id = sas_host->next_target_id++;
VMKLNX_DEBUG(5, "Assigning target id %d for sas_address "
"0x%llx NOT from freed list",
rphy->scsi_target_id, rphy->identify.sas_address);
return 1;
}
/**
* sas_rphy_add - add a SAS remote PHY to the device hierachy
* @rphy: The remote PHY to be added
*
* Publishes a SAS remote PHY to the rest of the system.
* Assumes sas_host->lock is held as needed
*
* RETURN VALUE:
* 0 on success
* negative errno code on error
*/
/* _VMKLNX_CODECHECK_: sas_rphy_add */
int sas_rphy_add(struct sas_rphy *rphy)
{
struct sas_port *parent;
struct Scsi_Host *shost;
struct sas_host_attrs *sas_host;
struct sas_identify *identify;
int error;
VMK_ASSERT(rphy);
parent = dev_to_sas_port(rphy->dev.parent);
VMK_ASSERT(parent);
shost = dev_to_shost(parent->dev.parent);
VMK_ASSERT(shost);
sas_host = to_sas_host_attrs(shost);
identify = &rphy->identify;
if (parent->rphy)
return -ENXIO;
parent->rphy = rphy;
error = device_add(&rphy->dev);
if (error) {
VMKLNX_DEBUG(1, "rphy: %p device_add failed with %d",
rphy, error);
return error;
}
mutex_lock(&sas_host->lock);
list_add_tail(&rphy->list, &sas_host->rphy_list);
if (identify->device_type == SAS_END_DEVICE &&
(identify->target_port_protocols &
(SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA))) {
sas_assign_scsi_target_id(rphy, sas_host);
}
else if (identify->device_type == SAS_END_DEVICE)
rphy->scsi_target_id = -1;
mutex_unlock(&sas_host->lock);
if (identify->device_type == SAS_END_DEVICE &&
rphy->scsi_target_id != -1) {
scsi_scan_target(&rphy->dev, 0,
rphy->scsi_target_id, ~0, 1);
}
return 0;
}
EXPORT_SYMBOL(sas_rphy_add);
/**
* sas_rphy_delete - remove SAS remote PHY
* @rphy: SAS remote PHY to remove
*
* Removes the specified SAS remote PHY.
*
* RETURN VALUE:
* None
*/
/* _VMKLNX_CODECHECK_: sas_rphy_delete */
void sas_rphy_delete(struct sas_rphy *rphy)
{
struct device *dev = &rphy->dev;
struct sas_port *parent = dev_to_sas_port(dev->parent);
struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
if (NULL == sas_host) {
return;
}
switch (rphy->identify.device_type) {
case SAS_END_DEVICE:
break;
case SAS_EDGE_EXPANDER_DEVICE:
case SAS_FANOUT_EXPANDER_DEVICE:
break;
default:
break;
}
device_del(dev);
mutex_lock(&sas_host->lock);
list_del(&rphy->list);
list_add_tail(&rphy->list, &sas_host->freed_rphy_list);
vmklnx_scsi_target_offline(&rphy->dev);
VMKLNX_DEBUG(3, "rphy:%p - Added target id %d for "
"sas_address 0x%llx to freed list device_type:%d",
rphy, rphy->scsi_target_id, rphy->identify.sas_address,
rphy->identify.device_type);
mutex_unlock(&sas_host->lock);
parent->rphy = NULL;
}
EXPORT_SYMBOL(sas_rphy_delete);
static void sas_rphy_initialize(struct sas_rphy *rphy)
{
INIT_LIST_HEAD(&rphy->list);
}
/**
* sas_end_device_alloc - allocate a SAS rphy and connect to its parent device
* @parent: parent to connect SAS rphy port to
*
* Allocates a SAS remote PHY structure, connected to @parent
*
*/
/* _VMKLNX_CODECHECK_: sas_end_device_alloc */
struct sas_rphy *sas_end_device_alloc(struct sas_port *parent)
{
struct Scsi_Host *shost;
struct sas_end_device *rdev;
VMK_ASSERT(parent);
shost = dev_to_shost(&parent->dev);
VMK_ASSERT(shost);
rdev = (struct sas_end_device *)
kzalloc(sizeof(struct sas_end_device), GFP_KERNEL);
if (!rdev) {
return NULL;
}
device_initialize(&rdev->rphy.dev);
rdev->rphy.dev.parent = get_device(&parent->dev);
rdev->rphy.dev.dev_type = SAS_END_DEVICE_TYPE;
rdev->rphy.dev.release = sas_end_device_release;
if (scsi_is_sas_expander_device(parent->dev.parent)) {
struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent);
sprintf(rdev->rphy.dev.bus_id, "end_device-%d:%d:%d",
shost->host_no, rphy->scsi_target_id, parent->port_identifier);
} else
sprintf(rdev->rphy.dev.bus_id, "end_device-%d:%d",
shost->host_no, parent->port_identifier);
rdev->rphy.identify.device_type = SAS_END_DEVICE;
sas_rphy_initialize(&rdev->rphy);
return &rdev->rphy;
}
EXPORT_SYMBOL(sas_end_device_alloc);
/**
* sas_expander_alloc - allocate an rphy for an end device
* @parent: parent to connect SAS rphy to
* @type: device type
*
* Allocates a SAS remote PHY structure, connected to @parent and sets its type.
* Valid types are: SAS_EDGE_EXPANDER_DEVICE and SAS_FANOUT_EXPANDER_DEVICE
*
*/
/* _VMKLNX_CODECHECK_: sas_expander_alloc */
struct sas_rphy *sas_expander_alloc(struct sas_port *parent,
enum sas_device_type type)
{
struct Scsi_Host *shost;
struct sas_expander_device *rdev;
struct sas_host_attrs *sas_host;
VMK_ASSERT(parent);
VMK_ASSERT((type == SAS_EDGE_EXPANDER_DEVICE) ||
(type == SAS_FANOUT_EXPANDER_DEVICE));
shost = dev_to_shost(&parent->dev);
VMK_ASSERT(shost);
sas_host = to_sas_host_attrs(shost);
VMK_ASSERT(sas_host);
rdev = (struct sas_expander_device *)
kzalloc(sizeof(struct sas_expander_device), GFP_KERNEL);
if (!rdev) {
return NULL;
}
device_initialize(&rdev->rphy.dev);
rdev->rphy.dev.parent = get_device(&parent->dev);
rdev->rphy.dev.dev_type = SAS_EXPANDER_DEVICE_TYPE;
rdev->rphy.dev.release = sas_expander_release;
mutex_lock(&sas_host->lock);
rdev->rphy.scsi_target_id = sas_host->next_expander_id++;
mutex_unlock(&sas_host->lock);
sprintf(rdev->rphy.dev.bus_id, "expander-%d:%d",
shost->host_no, rdev->rphy.scsi_target_id);
rdev->rphy.identify.device_type = type;
sas_rphy_initialize(&rdev->rphy);
return &rdev->rphy;
}
EXPORT_SYMBOL(sas_expander_alloc);
/**
*
* \globalfn sas_is_sas_port -- check if it is a port device
*
* \param dev a pointer to a struct device
* \return 1 if it is a SAS remote PHY; 0 otherwise
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
* It uses device instead.
* \sa None.
* \comments -
*
*/
int scsi_is_sas_port(const struct device *dev)
{
if (dev) {
return(dev->dev_type == SAS_PORT_DEVICE_TYPE);
} else {
return(0);
}
}
/**
*
* \globalfn sas_is_sas_phy -- check if it is a phy device
*
* \param dev a pointer to a struct device
* \return 1 if it is a SAS PHY; 0 otherwise
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
* It uses device instead.
* \sa None.
* \comments -
*
*/
int scsi_is_sas_phy(const struct device *dev)
{
if (dev) {
return(dev->dev_type == SAS_PHY_DEVICE_TYPE);
} else {
return(0);
}
}
/**
* scsi_is_sas_rphy - check if it is a rphy device
* @dev: a pointer to struct device
*
* This function is used to identify if @dev is a SAS remote PHY.
*
* RETURN VALUE:
* Returns TRUE if @dev is a SAS remote PHY, FALSE otherwise.
*
*/
/* _VMKLNX_CODECHECK_: scsi_is_sas_rphy */
int scsi_is_sas_rphy(const struct device *dev)
{
if (dev) {
return(dev->dev_type == SAS_END_DEVICE_TYPE ||
dev->dev_type == SAS_EXPANDER_DEVICE_TYPE);
} else {
return(0);
}
}
EXPORT_SYMBOL(scsi_is_sas_rphy);
/**
*
* \globalfn sas_attach_transport -- Attach SAS transport
*
* \param scmd
* \return None
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
*
* \sa None.
* \comments
*
*/
/**
* sas_attach_transport - instantiate SAS transport template
* @ft: SAS transport class function template
*
*
*/
/* _VMKLNX_CODECHECK_: sas_attach_transport */
struct scsi_transport_template *
sas_attach_transport(struct sas_function_template *ft)
{
struct vmklnx_ScsiModule *vmklnx26ScsiModule;
struct sas_internal *i;
VMK_ASSERT(ft);
i = (struct sas_internal *) kzalloc(sizeof(struct sas_internal), GFP_KERNEL);
VMK_ASSERT(i);
if (unlikely(!i)) {
VMKLNX_WARN("Unable to allocate memory for spi_internal");
return NULL;
}
vmklnx26ScsiModule = vmklnx_alloc_scsimod(VMKLNX_SCSI_TRANSPORT_TYPE_SAS, i);
if (!vmklnx26ScsiModule) {
kfree(i);
return NULL;
}
i->t.module = (void *)vmklnx26ScsiModule;
i->t.host_size = sizeof(struct sas_host_attrs);
i->f = ft;
return &i->t;
}
EXPORT_SYMBOL(sas_attach_transport);
/**
*
* \globalfn sas_release_transport -- Release SAS transport
*
* \param scmd
* \return None
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
*
* \sa None.
* \comments
*
*/
/**
* sas_release_transport - Release SAS transport template instance
* @t: transport template instance
*
*/
/* _VMKLNX_CODECHECK_: sas_release_transport */
void sas_release_transport(struct scsi_transport_template *t)
{
struct sas_internal *i = to_sas_internal(t);
/*
* Free up the module structure
*/
kfree(t->module);
/*
* Free up the transport_internal structure
*/
kfree(i);
}
EXPORT_SYMBOL(sas_release_transport);
void sas_phy_delete(struct sas_phy *phy)
{
struct device *dev = &phy->dev;
if(NULL == phy) {
return;
}
device_del(dev);
put_device(dev);
return;
}
EXPORT_SYMBOL(sas_phy_delete);
static int do_sas_phy_delete(struct device *dev, void *data)
{
int pass = (int)(unsigned long)data;
if (pass == 0 && scsi_is_sas_port(dev))
sas_port_delete(dev_to_sas_port(dev));
else if (pass == 1 && scsi_is_sas_phy(dev))
sas_phy_delete(dev_to_phy(dev));
return 0;
}
/**
* sas_read_port_mode_page - Issue Mode Sense for Page 0x19 to specifed scsi_device
* @sdev: Pointer to SCSI device of type struct scsi_device
*
* Issues SCSI Mode Sense command for page 0x19 to the passed in scsi_device.
* Figures out the associated SAS end device and populates appropriate fields
* on success.
*
* RETURN VALUE:
* 0 on Sucess, non-zero otherwise
*
*/
/* _VMKLNX_CODECHECK_: sas_read_port_mode_page */
int sas_read_port_mode_page(struct scsi_device *sdev)
{
/* only need 8 bytes of data plus header (4 or 8) */
#define BUF_SIZE 64
unsigned char *buffer;
unsigned char *msdata;
struct sas_rphy *rphy;
struct sas_end_device *rdev;
struct scsi_mode_data mode_data;
int res, error;
VMK_ASSERT(sdev);
VMK_ASSERT(sdev->sdev_target);
rphy = target_to_rphy(sdev->sdev_target);
VMK_ASSERT(rphy);
VMK_ASSERT(rphy->identify.device_type == SAS_END_DEVICE);
rdev = rphy_to_end_device(rphy);
buffer = (unsigned char *) vmklnx_kzmalloc(vmklnxLowHeap, BUF_SIZE, GFP_KERNEL);
if (!buffer)
return -ENOMEM;
res = scsi_mode_sense(sdev, 1, 0x19, buffer, BUF_SIZE, 30*HZ, 3,
&mode_data, NULL);
error = -EINVAL;
if (!scsi_status_is_good(res))
goto out;
msdata = buffer + mode_data.header_length +
mode_data.block_descriptor_length;
if (msdata - buffer > BUF_SIZE - 8)
goto out;
error = 0;
rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0;
rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5];
rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7];
out:
vmklnx_kfree(vmklnxLowHeap, buffer);
return error;
}
EXPORT_SYMBOL(sas_read_port_mode_page);
/**
*
* \globalfn sas_remove_children -- tear down a device SAS data structure
*
* \param dev a pointer to device belonging to the SAS object
* \return void
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
*
* \sa None.
* \comments
* It must be called just before scsi_remove_host for SAS HBAs.
*
*/
void sas_remove_children(struct device *dev)
{
VMK_ASSERT(dev);
device_for_each_child(dev, (void *)0, do_sas_phy_delete);
device_for_each_child(dev, (void *)1, do_sas_phy_delete);
}
static int
sas_remove_scsi_target(struct device *dev, void *data)
{
struct scsi_target *stgt = to_scsi_target(dev);
VMKLNX_DEBUG(0, "Entered for dev: %p stgt: %p shost:%p "
"new_rphy: %p", dev, stgt, dev_to_shost(dev), data);
if (dev && stgt) {
scsi_remove_target(&stgt->dev);
VMKLNX_DEBUG(3, "Found and deleted target "
"(i.e stgt:%p &stgt->dev:%p", stgt, &stgt->dev);
}
return 0;
}
/**
* sas_remove_host - terminate any sas_transport related elements
* @shost: Pointer to struct Scsi_Host
*
* Terminates any sas_transport related elements for a scsi host.
* This routine is expected to be called immediately preceeding the call from
* the driver to scsi_remove_host().
*
* RETURN VALUE:
* None
*/
/* _VMKLNX_CODECHECK_: sas_remove_host */
void sas_remove_host(struct Scsi_Host *shost)
{
struct sas_host_attrs *sas_host;
struct sas_rphy *t_rphy, *t_rphy1;
VMKLNX_DEBUG(0, "shost:%p", shost);
sas_host = to_sas_host_attrs(shost);
list_for_each_entry_safe(t_rphy, t_rphy1, &sas_host->freed_rphy_list, list) {
VMKLNX_DEBUG(0, "shost:%p, processing t_rphy:%p", shost, t_rphy);
device_for_each_child(&t_rphy->dev, NULL, sas_remove_scsi_target);
sas_rphy_free(t_rphy);
}
sas_remove_children(&shost->shost_gendev);
}
EXPORT_SYMBOL(sas_remove_host);
/**
*
* \globalfn sas_port_alloc -- allocate and initialize a SAS port structure
*
* \param parent a pointer to the parent device
* \param port_id a port number
* \return a pointer to the allocated PHY structure; NULL if failed
* \par Include:
* scsi/scsi_transport_sas.h
* \par ESX Deviation Notes:
*
* \sa None.
* \comments -
*
*/
struct sas_port *sas_port_alloc(struct device *parent, int port_id)
{
struct Scsi_Host *shost = dev_to_shost(parent);
struct sas_port *port;
port = (struct sas_port *) kzalloc(sizeof(*port), GFP_KERNEL);
if (!port)
return NULL;
port->port_identifier = port_id;
device_initialize(&port->dev);
port->dev.parent = get_device(parent);
port->dev.dev_type = SAS_PORT_DEVICE_TYPE;
port->dev.release = sas_port_release;
mutex_init(&port->phy_list_mutex);
INIT_LIST_HEAD(&port->phy_list);
if (scsi_is_sas_expander_device(parent)) {
struct sas_rphy *rphy = dev_to_rphy(parent);
sprintf(port->dev.bus_id, "port-%d:%d:%d", shost->host_no,
rphy->scsi_target_id, port->port_identifier);
} else {
sprintf(port->dev.bus_id, "port-%d:%d", shost->host_no,
port->port_identifier);
}
return port;
}
/**
* sas_port_alloc_num - allocate and initialize a SAS port structure
* @parent: a pointer to the parent device
*
* Allocates a SAS port structure and a number to go with it. This interface is
* really for adapters where the port number has no meaning, so the sas class
* should manage them. It will be added to the device tree below the device
* specified by @parent which must be either a Scsi_Host or a
* sas_expander_device.
*
* RETURN VALUE:
* Returns a pointer to the allocated PHY structure; Returns NULL on error.
*
*/
/* _VMKLNX_CODECHECK_: sas_port_alloc_num */
struct sas_port *sas_port_alloc_num(struct device *parent)
{
int index;
struct Scsi_Host *shost;
struct sas_host_attrs *sas_host;
VMK_ASSERT(parent);
shost = dev_to_shost(parent);
VMK_ASSERT(shost);
sas_host = to_sas_host_attrs(shost);
VMK_ASSERT(sas_host);
/* FIXME: use idr for this eventually */
mutex_lock(&sas_host->lock);
if (scsi_is_sas_expander_device(parent)) {
struct sas_rphy *rphy = dev_to_rphy(parent);
struct sas_expander_device *exp = rphy_to_expander_device(rphy);
index = exp->next_port_id++;
} else
index = sas_host->next_port_id++;
mutex_unlock(&sas_host->lock);
return sas_port_alloc(parent, index);
}
EXPORT_SYMBOL(sas_port_alloc_num);
/**
* sas_port_mark_backlink - mark the sas port backlink
* @port: a pointer to struct sas_port
*
* Marks the port as a backlink.
*
* RETURN VALUE:
* This function does not return a value.
*
*/
/* _VMKLNX_CODECHECK_: sas_port_mark_backlink */
void sas_port_mark_backlink(struct sas_port *port)
{
struct device *parent;
VMK_ASSERT(port);
parent = port->dev.parent->parent->parent;
if (port->is_backlink)
return;
port->is_backlink = 1;
}
EXPORT_SYMBOL(sas_port_mark_backlink);
/**
* sas_port_add - Add a SAS port to the device hierarchy
* @port: Pointer to SAS port of type struct sas_port
*
* Add the passed in SAS port to the device hierarchy
*
* RETURN VALUE:
* 0 on success and non-zero on error
*
*/
/* _VMKLNX_CODECHECK_: sas_port_add */
int sas_port_add(struct sas_port *port)
{
int error;
/* No phys should be added until this is made visible */
BUG_ON(!list_empty(&port->phy_list));
error = device_add(&port->dev);
return error;
}
EXPORT_SYMBOL(sas_port_add);
/**
* sas_port_add_phy - Add a PHY to a SAS port structure
* @port: Pointer to SAS port of type struct sas_port
* @phy: Pointer to a PHY of type struct sas_phy
*
* Add the passed in PHY to the passed in SAS port.
* This API is usually called by SAS drivers that discover the SAS ports and
* want to associate the PHY with the SAS port.
*
* ESX Deviation Notes:
* No sysfs links are created on ESXi
*
*/
/* _VMKLNX_CODECHECK_: sas_port_add_phy */
void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy)
{
VMK_ASSERT(port);
VMK_ASSERT(phy);
mutex_lock(&port->phy_list_mutex);
if (unlikely(!list_empty(&phy->port_siblings))) {
/* make sure we're already on this port */
struct sas_phy *tmp;
list_for_each_entry(tmp, &port->phy_list, port_siblings)
if (tmp == phy)
break;
/* If this trips, you added a phy that was already
* part of a different port */
if (unlikely(tmp != phy)) {
dev_printk(KERN_ERR, &port->dev, "trying to add"
" phy %s fails: it's already part of another port\n",
phy->dev.bus_id);
VMK_ASSERT(FALSE);
}
} else {
list_add_tail(&phy->port_siblings, &port->phy_list);
port->num_phys++;
}
mutex_unlock(&port->phy_list_mutex);
}
EXPORT_SYMBOL(sas_port_add_phy);
/**
* sas_port_delete_phy - Remove a PHY from a SAS port
* @port: Pointer to a SAS port
* @phy: Pointer to the phy to be removed from the SAS port
*
* Removes the passed in PHY from the passed in SAS port.
* This operation is usually done as part of tearing down ports.
*
*/
/* _VMKLNX_CODECHECK_: sas_port_delete_phy */
void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy)
{
VMK_ASSERT(port);
VMK_ASSERT(phy);
mutex_lock(&port->phy_list_mutex);
list_del_init(&phy->port_siblings);
port->num_phys--;
mutex_unlock(&port->phy_list_mutex);
}
EXPORT_SYMBOL(sas_port_delete_phy);
/**
* sas_port_delete - Remove SAS port
* @port: Pointer to a SAS port (of type struct sas_port) to be removed
*
* Removes the specified SAS port.
* If any PHYs are found hanging from the passed in SAS port,
* those are cleaned up as well.
*
*/
/* _VMKLNX_CODECHECK_: sas_port_delete */
void sas_port_delete(struct sas_port *port)
{
struct device *dev;
struct sas_phy *phy, *tmp_phy;
VMK_ASSERT(port);
dev = &port->dev;
if (port->rphy) {
sas_rphy_delete(port->rphy);
port->rphy = NULL;
}
mutex_lock(&port->phy_list_mutex);
list_for_each_entry_safe(phy, tmp_phy, &port->phy_list,
port_siblings) {
list_del_init(&phy->port_siblings);
}
mutex_unlock(&port->phy_list_mutex);
if (port->is_backlink) {
port->is_backlink = 0;
}
device_del(dev);
put_device(dev);
}
EXPORT_SYMBOL(sas_port_delete);
/**
**********************************************************************
* \internalfn sas_find_rphy -- Find a matching rphy
*
* \param sh, id
* \return None
* \par Include:
* scsi/scsi_host.h
* \par ESX Deviation Notes:
* Needs
* \sa None.
**********************************************************************
*/
struct sas_rphy *
sas_find_rphy(struct Scsi_Host *sh, uint id)
{
struct sas_host_attrs *sas_host;
struct sas_rphy *rphy, *found_rphy = NULL;
VMK_ASSERT(sh);
sas_host = to_sas_host_attrs(sh);
VMK_ASSERT(sas_host);
/*
* Search for an existing target for this sdev.
*/
mutex_lock(&sas_host->lock);
list_for_each_entry(rphy, &sas_host->rphy_list, list) {
if (rphy->scsi_target_id == id) {
found_rphy = rphy;
break;
}
}
mutex_unlock(&sas_host->lock);
return found_rphy;
}
static void fc_rport_dev_release(struct device *dev)
{
struct fc_rport *rport = dev_to_rport(dev);
put_device(dev->parent);
kfree(rport);
}
static void fc_vport_dev_release(struct device *dev)
{
struct fc_vport *vport = dev_to_vport(dev);
put_device(dev->parent); /* release kobj parent */
kfree(vport);
}
static void sas_phy_release(struct device *dev)
{
struct sas_phy *phy = dev_to_phy(dev);
put_device(dev->parent);
kfree(phy);
}
static void sas_port_release(struct device *dev)
{
struct sas_port *port = dev_to_sas_port(dev);
put_device(dev->parent);
kfree(port);
}
static void sas_end_device_release(struct device *dev)
{
struct sas_rphy *rphy = dev_to_rphy(dev);
struct sas_end_device *edev = rphy_to_end_device(rphy);
put_device(dev->parent);
kfree(edev);
}
static void sas_expander_release(struct device *dev)
{
struct sas_rphy *rphy = dev_to_rphy(dev);
struct sas_expander_device *edev = rphy_to_expander_device(rphy);
put_device(dev->parent);
kfree(edev);
}
/**
* vmklnx_init_fcoe_attribs -
* @shost: Pointer to shost structure
* @netdevName: Pointer to CNA net_device name
* @vid: VLAN ID
* @fcoeControllerMac: FCOE Controller MAC address
* @vnportMac: VNPort MAC address
* @fcfMac: FCF MAC address
*
* Copies the given values to the Vmkernel storage management structure.
* The given MAC address pointers are permitted to be NULL, for which
* the corresponding management information will not be set.
*
* ESX Deviation Notes:
* This API is not present in Linux. This should be called immediately
* after FLOGI is completed.
*/
/* _VMKLNX_CODECHECK_: vmlnx_init_fcoe_attribs */
int
vmklnx_init_fcoe_attribs(struct Scsi_Host *shost,
char *netdevName,
unsigned short vid,
unsigned char *fcoeControllerMac,
unsigned char *vnportMac,
unsigned char *fcfMac)
{
struct fc_host_attrs *fc_host;
struct vmk_FcoeAdapterAttrs *attrs;
VMK_ASSERT(shost);
VMK_ASSERT(netdevName);
fc_host = shost_to_fc_host(shost);
VMK_ASSERT(fc_host);
attrs = (struct vmk_FcoeAdapterAttrs *) fc_host->cna_ops;
strncpy(attrs->vmnicName, netdevName, VMK_DEVICE_NAME_MAX_LENGTH);
attrs->vmnicName[VMK_DEVICE_NAME_MAX_LENGTH - 1] = '\0';
attrs->vlanId = vid;
#define COPY_MAC(dst, src) \
if (src) { \
memcpy(dst, src, VMK_MAX_ETHERNET_MAC_LENGTH); \
}
COPY_MAC(attrs->fcoeContlrMacAddr, fcoeControllerMac);
COPY_MAC(attrs->vnPortMacAddr, vnportMac);
COPY_MAC(attrs->fcfMacAddr, fcfMac);
#undef COPY_MAC
return 0;
}
EXPORT_SYMBOL(vmklnx_init_fcoe_attribs);
/*
*----------------------------------------------------------------------
*
* SCSILinux_InitTransport
*
* Entry point for SCSI Transport-specific initialization.
* Called as part of SCSILinux_Init in linux_scsi.c.
*
* Results:
* None.
*
* Side effects:
* Initializes SCSI Transport log.
*
*----------------------------------------------------------------------
*/
void
SCSILinux_InitTransport(void)
{
VMKLNX_CREATE_LOG();
}
/*
*----------------------------------------------------------------------
*
* SCSILinux_CleanupTransport
*
* Entry point for SCSI Transport-specific teardown.
* Called as part of SCSILinux_Cleanup in linux_scsi.c.
*
* Results:
* None.
*
* Side effects:
* Cleans up SCSI Transport log.
*
*----------------------------------------------------------------------
*/
void
SCSILinux_CleanupTransport(void)
{
VMKLNX_DESTROY_LOG();
}
|