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
|
/*
* Copyright (c) 2007 Kontron Canada, Inc. All Rights Reserved.
*
* Base on code from
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <ipmitool/ipmi_ekanalyzer.h>
#include <ipmitool/log.h>
#include <ipmitool/helper.h>
#include <ipmitool/ipmi_strings.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define NO_MORE_INFO_FIELD 0xc1
#define TYPE_CODE 0xc0 /*Language code*/
/*
* CONSTANT
*/
const int ERROR_STATUS = -1;
const int OK_STATUS = 0;
const char * STAR_LINE_LIMITER =
"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*";
const char * EQUAL_LINE_LIMITER =
"=================================================================";
const int SIZE_OF_FILE_TYPE = 3;
const unsigned char AMC_MODULE = 0x80;
const int PICMG_ID_OFFSET = 3;
const unsigned int COMPARE_CANDIDATE = 2;
/* In AMC.0 or PICMG 3.0 specification offset start from 0 with 3 bytes of
* Mfg.ID, 1 byte of Picmg record Id, and
* 1 byte of format version, so the data offset start from 5
*/
const int START_DATA_OFFSET = 5;
const int LOWER_OEM_TYPE = 0xf0;
const int UPPER_OEM_TYPE = 0xfe;
const unsigned char DISABLE_PORT = 0x1f;
const struct valstr ipmi_ekanalyzer_module_type[] = {
{ ON_CARRIER_FRU_FILE, "On-Carrier Device" },
{ A1_AMC_FRU_FILE, "AMC slot A1" },
{ A2_AMC_FRU_FILE, "AMC slot A2" },
{ A3_AMC_FRU_FILE, "AMC slot A3" },
{ A4_AMC_FRU_FILE, "AMC slot A4" },
{ B1_AMC_FRU_FILE, "AMC slot B1" },
{ B2_AMC_FRU_FILE, "AMC slot B2" },
{ B3_AMC_FRU_FILE, "AMC slot B3" },
{ B4_AMC_FRU_FILE, "AMC slot B4" },
{ RTM_FRU_FILE, "RTM" }, /*This is OEM specific module*/
{ CONFIG_FILE, "Configuration file" },
{ SHELF_MANAGER_FRU_FILE, "Shelf Manager" },
{ 0xffff , NULL },
};
const struct valstr ipmi_ekanalyzer_IPMBL_addr[] = {
{ 0x72, "AMC slot A1" },
{ 0x74, "AMC slot A2" },
{ 0x76, "AMC slot A3" },
{ 0x78, "AMC slot A4" },
{ 0x7a, "AMC slot B1" },
{ 0x7c, "AMC slot B2" },
{ 0x7e, "AMC slot B3" },
{ 0x80, "AMC slot B4" },
{ 0x90, "RTM"}, /*This is OEM specific module*/
{ 0xffff , NULL },
};
const struct valstr ipmi_ekanalyzer_link_type[] = {
{ 0x00, "Reserved" },
{ 0x01, "Reserved" },
{ 0x02, "AMC.1 PCI Express" },
{ 0x03, "AMC.1 PCI Express Advanced Switching" },
{ 0x04, "AMC.1 PCI Express Advanced Switching" },
{ 0x05, "AMC.2 Ethernet" },
{ 0x06, "AMC.4 Serial RapidIO" },
{ 0x07, "AMC.3 Storage" },
/*This is OEM specific module*/
{ 0xf0, "OEM Type 0"},
{ 0xf1, "OEM Type 1"},
{ 0xf2, "OEM Type 2"},
{ 0xf3, "OEM Type 3"},
{ 0xf4, "OEM Type 4"},
{ 0xf5, "OEM Type 5"},
{ 0xf6, "OEM Type 6"},
{ 0xf7, "OEM Type 7"},
{ 0xf8, "OEM Type 8"},
{ 0xf9, "OEM Type 9"},
{ 0xfa, "OEM Type 10"},
{ 0xfb, "OEM Type 11"},
{ 0xfc, "OEM Type 12"},
{ 0xfd, "OEM Type 13"},
{ 0xfe, "OEM Type 14"},
{ 0xff , "Reserved" },
};
/*Reference: AMC.1 specification*/
const struct valstr ipmi_ekanalyzer_extension_PCIE[] = {
{ 0x00, "Gen 1 capable - non SSC" },
{ 0x01, "Gen 1 capable - SSC" },
{ 0x02, "Gen 2 capable - non SSC" },
{ 0x03, "Gen 3 capable - SSC" },
{ 0x0f, "Reserved"},
};
/*Reference: AMC.2 specification*/
const struct valstr ipmi_ekanalyzer_extension_ETHERNET[] = {
{ 0x00, "1000BASE-BX (SerDES Gigabit) Ethernet link" },
{ 0x01, "10GBASE-BX4 10 Gigabit Ethernet link" },
};
/*Reference: AMC.3 specification*/
const struct valstr ipmi_ekanalyzer_extension_STORAGE[] = {
{ 0x00, "Fibre Channel (FC)" },
{ 0x01, "Serial ATA (SATA)" },
{ 0x02, "Serial Attached SCSI (SAS/SATA)" },
};
const struct valstr ipmi_ekanalyzer_asym_PCIE[] = {
{ 0x00, "exact match"},
{ 0x01, "provides a Primary PCI Express Port" },
{ 0x02, "provides a Secondary PCI Express Port" },
};
const struct valstr ipmi_ekanalyzer_asym_STORAGE[] = {
{ 0x00, "FC or SAS interface {exact match}" },
{ 0x01, "SATA Server interface" },
{ 0x02, "SATA Client interface" },
{ 0x03, "Reserved" },
};
const struct valstr ipmi_ekanalyzer_picmg_record_id[] = {
{ 0x04, "Backplane Point to Point Connectivity Record" },
{ 0x10, "Address Table Record" },
{ 0x11, "Shelf Power Distribution Record" },
{ 0x12, "Shelf Activation and Power Management Record" },
{ 0x13, "Shelf Manager IP Connection Record" },
{ 0x14, "Board Point to Point Connectivity Record" },
{ 0x15, "Radial IPMB-0 Link Mapping Record" },
{ 0x16, "Module Current Requirements Record" },
{ 0x17, "Carrier Activation and Power Management Record" },
{ 0x18, "Carrier Point-to-Point Connectivity Record" },
{ 0x19, "AdvancedMC Point-to-Point Connectivity Record" },
{ 0x1a, "Carrier Information Table" },
{ 0x1b, "Shelf Fan Geography Record" },
{ 0x2c, "Carrier Clock Point-to-Point Connectivity Record" },
{ 0x2d, "Clock Configuration Record" },
};
extern int verbose;
struct ipmi_ek_multi_header {
struct fru_multirec_header header;
unsigned char * data;
struct ipmi_ek_multi_header * prev;
struct ipmi_ek_multi_header * next;
};
struct ipmi_ek_amc_p2p_connectivity_record{
unsigned char guid_count;
struct fru_picmgext_guid * oem_guid;
unsigned char rsc_id;
unsigned char ch_count;
struct fru_picmgext_amc_channel_desc_record * ch_desc;
unsigned char link_desc_count;
struct fru_picmgext_amc_link_desc_record * link_desc;
int * matching_result; /*For link descriptor comparision*/
};
/*****************************************************************************
* Function prototype
******************************************************************************/
/****************************************************************************
* command Functions
*****************************************************************************/
static int ipmi_ekanalyzer_print( int argc, char * opt,
char ** filename, int * file_type );
static tboolean ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
char ** filename, int * file_type );
/****************************************************************************
* Linked list Functions
*****************************************************************************/
static void ipmi_ek_add_record2list( struct ipmi_ek_multi_header ** record,
struct ipmi_ek_multi_header ** list_head,
struct ipmi_ek_multi_header ** list_last );
static void ipmi_ek_display_record( struct ipmi_ek_multi_header * record,
struct ipmi_ek_multi_header * list_head,
struct ipmi_ek_multi_header * list_last );
static void ipmi_ek_remove_record_from_list(
struct ipmi_ek_multi_header * record,
struct ipmi_ek_multi_header ** list_head,
struct ipmi_ek_multi_header ** list_last );
static int ipmi_ekanalyzer_fru_file2structure( char * filename,
struct ipmi_ek_multi_header ** list_head,
struct ipmi_ek_multi_header ** list_record,
struct ipmi_ek_multi_header ** list_last );
/****************************************************************************
* Ekeying match Functions
*****************************************************************************/
static int ipmi_ek_matching_process( int * file_type, int index1, int index2,
struct ipmi_ek_multi_header ** list_head,
struct ipmi_ek_multi_header ** list_last, char * opt,
struct ipmi_ek_multi_header * pphysical );
static int ipmi_ek_get_resource_descriptor( int port_count, int index,
struct fru_picmgext_carrier_p2p_descriptor * port_desc,
struct ipmi_ek_multi_header * record );
static int ipmi_ek_create_amc_p2p_record( struct ipmi_ek_multi_header * record,
struct ipmi_ek_amc_p2p_connectivity_record * amc_record );
static int ipmi_ek_compare_link( struct ipmi_ek_multi_header * physic_record,
struct ipmi_ek_amc_p2p_connectivity_record record1,
struct ipmi_ek_amc_p2p_connectivity_record record2,
char * opt, int file_type1, int file_type2 );
static tboolean ipmi_ek_compare_channel_descriptor(
struct fru_picmgext_amc_channel_desc_record ch_desc1,
struct fru_picmgext_amc_channel_desc_record ch_desc2,
struct fru_picmgext_carrier_p2p_descriptor * port_desc,
int index_port, unsigned char rsc_id );
static int ipmi_ek_compare_link_descriptor(
struct ipmi_ek_amc_p2p_connectivity_record record1, int index1,
struct ipmi_ek_amc_p2p_connectivity_record record2, int index2 );
static int ipmi_ek_compare_asym( unsigned char asym[COMPARE_CANDIDATE] );
static int ipmi_ek_compare_number_of_enable_port(
struct fru_picmgext_amc_link_desc_record link_desc[COMPARE_CANDIDATE] );
static int ipmi_ek_check_physical_connectivity(
struct ipmi_ek_amc_p2p_connectivity_record record1, int index1,
struct ipmi_ek_amc_p2p_connectivity_record record2, int index2,
struct ipmi_ek_multi_header * record,
int filetype1, int filetype2, char * option );
/****************************************************************************
* Display Functions
*****************************************************************************/
static int ipmi_ek_display_fru_header( char * filename );
static int ipmi_ek_display_fru_header_detail(char * filename);
static int ipmi_ek_display_chassis_info_area(FILE * input_file, long offset);
static size_t ipmi_ek_display_board_info_area( FILE * input_file,
char * board_type, unsigned int * board_length );
static int ipmi_ek_display_product_info_area(FILE * input_file, long offset);
static tboolean ipmi_ek_display_link_descriptor( int file_type,
unsigned char rsc_id, char * str,
struct fru_picmgext_amc_link_desc_record link_desc );
static void ipmi_ek_display_oem_guid(
struct ipmi_ek_amc_p2p_connectivity_record amc_record1 );
static int ipmi_ek_display_carrier_connectivity(
struct ipmi_ek_multi_header * record );
static int ipmi_ek_display_power( int argc, char * opt,
char ** filename, int * file_type );
static void ipmi_ek_display_current_descriptor(
struct fru_picmgext_carrier_activation_record car,
struct fru_picmgext_activation_record * cur_desc, char * filename );
static void ipmi_ek_display_backplane_p2p_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_address_table_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_shelf_power_distribution_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_shelf_activation_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_shelf_ip_connection_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_shelf_fan_geography_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_board_p2p_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_radial_ipmb0_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_amc_current_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_amc_activation_record (
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_amc_p2p_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_amc_carrier_info_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_clock_carrier_p2p_record(
struct ipmi_ek_multi_header * record );
static void ipmi_ek_display_clock_config_record(
struct ipmi_ek_multi_header * record );
/**************************************************************************
*
* Function name: ipmi_ekanalyzer_usage
*
* Description : Print the usage (help menu) of ekeying analyzer tool
*
* Restriction : None
*
* Input : None
*
* Output : None
*
* Global : None
*
* Return : None
*
***************************************************************************/
static void
ipmi_ekanalyzer_usage(void)
{
lprintf(LOG_NOTICE,
"Ekeying analyzer tool version 1.00");
lprintf(LOG_NOTICE,
"ekanalyzer Commands:");
lprintf(LOG_NOTICE,
" print [carrier | power | all] <oc=filename1> <b1=filename2>...");
lprintf(LOG_NOTICE,
" frushow <b2=filename>");
lprintf(LOG_NOTICE,
" summary [match | unmatch | all] <oc=filename1> <b1=filename2>...");
}
/**************************************************************************
*
* Function name: ipmi_ek_get_file_type
*
* Description: this function takes an argument, then xtract the file type and
* convert into module type (on carrier, AMC,...) value.
*
*
* Restriction: None
*
* Input: argument: strings contain the type and the name of the file
* together
*
* Output: None
*
* Global: None
*
* Return: Return value of module type: On carrier FRU file, A1 FRUM file...
* if the file type is invalid, it return -1. See structure
* ipmi_ekanalyzer_module_type for a list of valid type.
***************************************************************************/
static int
ipmi_ek_get_file_type(char *argument)
{
int filetype = ERROR_STATUS;
if (strlen(argument) <= MIN_ARGUMENT) {
return filetype;
}
if (strncmp(argument, "oc=", SIZE_OF_FILE_TYPE) == 0) {
filetype = ON_CARRIER_FRU_FILE;
} else if (strncmp(argument, "a1=", SIZE_OF_FILE_TYPE) == 0) {
filetype = A1_AMC_FRU_FILE;
} else if (strncmp(argument, "a2=", SIZE_OF_FILE_TYPE) == 0) {
filetype = A2_AMC_FRU_FILE;
} else if (strncmp(argument, "a3=", SIZE_OF_FILE_TYPE) == 0) {
filetype = A3_AMC_FRU_FILE;
} else if (strncmp(argument, "a4=", SIZE_OF_FILE_TYPE) == 0) {
filetype = A4_AMC_FRU_FILE;
} else if (strncmp(argument, "b1=", SIZE_OF_FILE_TYPE) == 0) {
filetype = B1_AMC_FRU_FILE;
} else if (strncmp(argument, "b2=", SIZE_OF_FILE_TYPE) == 0) {
filetype = B2_AMC_FRU_FILE;
} else if (strncmp(argument, "b3=", SIZE_OF_FILE_TYPE) == 0) {
filetype = B3_AMC_FRU_FILE;
} else if (strncmp(argument, "b4=", SIZE_OF_FILE_TYPE) == 0) {
filetype = B4_AMC_FRU_FILE;
} else if (strncmp(argument, "rt=", SIZE_OF_FILE_TYPE) == 0) {
filetype = RTM_FRU_FILE;
} else if (strncmp(argument, "rc=", SIZE_OF_FILE_TYPE) == 0) {
filetype = CONFIG_FILE;
} else if (strncmp(argument, "sm=", SIZE_OF_FILE_TYPE) == 0) {
filetype = SHELF_MANAGER_FRU_FILE;
} else {
filetype = ERROR_STATUS;
}
return filetype;
}
/**************************************************************************
*
* Function name: ipmi_ekanalyzer_main
*
* Description: Main program of ekeying analyzer. It calls the appropriate
* function according to the command received.
*
* Restriction: None
*
* Input: ipmi_intf * intf: ?
* int argc : number of argument received
* int ** argv: argument strings
*
* Output: None
*
* Global: None
*
* Return: OK_STATUS as succes or ERROR_STATUS as error
*
***************************************************************************/
int
ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
{
int rc = ERROR_STATUS;
int file_type[MAX_FILE_NUMBER];
char *filename[MAX_FILE_NUMBER];
unsigned int argument_offset = 0;
unsigned int type_offset = 0;
/* list des multi record */
struct ipmi_ek_multi_header *list_head = NULL;
struct ipmi_ek_multi_header *list_record = NULL;
struct ipmi_ek_multi_header *list_last = NULL;
if (argc == 0) {
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_ekanalyzer_usage();
return (-1);
} else if ((argc - 1) > MAX_FILE_NUMBER) {
lprintf(LOG_ERR, "Too too many parameters given.");
return (-1);
}
if (strcmp(argv[argument_offset], "help") == 0) {
ipmi_ekanalyzer_usage();
return 0;
} else if ((strcmp(argv[argument_offset], "frushow") == 0)
&& (argc > (MIN_ARGUMENT-1))) {
for (type_offset = 0; type_offset < (argc-1); type_offset++ ) {
argument_offset++;
file_type[type_offset] = ipmi_ek_get_file_type(argv[argument_offset]);
if (file_type[type_offset] == ERROR_STATUS
|| file_type[type_offset] == CONFIG_FILE) {
lprintf(LOG_ERR, "Invalid file type!");
lprintf(LOG_ERR, " ekanalyzer frushow <xx=frufile> ...");
return (-1);
}
/* because of strlen doesn't count '\0',
* we need to add 1 byte for this character
* to filename size
*/
filename[type_offset] = malloc(strlen(argv[argument_offset])
+ 1 - SIZE_OF_FILE_TYPE);
if (filename[type_offset] == NULL) {
lprintf(LOG_ERR, "malloc failure");
return (-1);
}
strcpy(filename[type_offset],
&argv[argument_offset][SIZE_OF_FILE_TYPE]);
printf("Start converting file '%s'...\n",
filename[type_offset]);
/* Display FRU header offset */
rc = ipmi_ek_display_fru_header (filename[type_offset]);
if (rc != ERROR_STATUS) {
/* Display FRU header info in detail record */
rc = ipmi_ek_display_fru_header_detail(filename[type_offset]);
/* Convert from binary data into multi record structure */
rc = ipmi_ekanalyzer_fru_file2structure (filename[type_offset],
&list_head, &list_record, &list_last );
ipmi_ek_display_record(list_record, list_head, list_last);
/* Remove record of list */
while (list_head != NULL) {
ipmi_ek_remove_record_from_list(list_head,
&list_head,&list_last );
if (verbose > 1) {
printf("record has been removed!\n");
}
}
}
free(filename[type_offset]);
filename[type_offset] = NULL;
}
} else if ((strcmp(argv[argument_offset], "print") == 0)
|| (strcmp(argv[argument_offset], "summary") == 0)) {
/* Display help text for corresponding command
* if not enough parameters were given.
*/
char * option;
/* index=1 indicates start position of first file
* name in command line
*/
int index = 1;
int filename_size=0;
if (argc < MIN_ARGUMENT) {
lprintf(LOG_ERR, "Not enough parameters given.");
if (strcmp(argv[argument_offset], "print") == 0) {
lprintf(LOG_ERR,
" ekanalyzer print [carrier/power/all]"
" <xx=frufile> <xx=frufile> [xx=frufile]");
} else {
lprintf(LOG_ERR,
" ekanalyzer summary [match/ unmatch/ all]"
" <xx=frufile> <xx=frufile> [xx=frufile]");
}
return ERROR_STATUS;
}
argument_offset++;
if ((strcmp(argv[argument_offset], "carrier") == 0)
|| (strcmp(argv[argument_offset], "power") == 0)
|| (strcmp(argv[argument_offset], "all") == 0)) {
option = argv[argument_offset];
index ++;
argc--;
} else if ((strcmp(argv[argument_offset], "match") == 0)
|| ( strcmp(argv[argument_offset], "unmatch") == 0)) {
option = argv[argument_offset];
index ++;
argc--;
} else if ( strncmp(&argv[argument_offset][2], "=", 1) == 0) {
/* since the command line must receive xx=filename,
* so the position of "=" sign is 2
*/
option = "default";
/* Since there is no option from user, the first argument
* becomes first file type
*/
index = 1; /* index of argument */
} else {
option = "invalid";
printf("Invalid option '%s'\n", argv[argument_offset]);
argument_offset--;
if (strcmp(argv[0], "print") == 0) {
lprintf (LOG_ERR,
" ekanalyzer print [carrier/power/all]"
" <xx=frufile> <xx=frufile> [xx=frufile]");
} else {
lprintf (LOG_ERR,
" ekanalyzer summary [match/ unmatch/ all]"
" <xx=frufile> <xx=frufile> [xx=frufile]");
}
rc = ERROR_STATUS;
}
if (strcmp(option, "invalid") != 0) {
int i=0;
for (i = 0; i < (argc-1); i++) {
file_type[i] = ipmi_ek_get_file_type (argv[index]);
if (file_type[i] == ERROR_STATUS) {
/* display the first 2 charactors (file type) of argument */
lprintf(LOG_ERR, "Invalid file type: %c%c\n",
argv[index][0],
argv[index][1]);
ipmi_ekanalyzer_usage();
rc = ERROR_STATUS;
break;
}
/* size is equal to string size minus 3 bytes of file type plus
* 1 byte of '\0' since the strlen doesn't count the '\0'
*/
filename_size = strlen(argv[index]) - SIZE_OF_FILE_TYPE + 1;
if (filename_size > 0) {
filename[i] = malloc( filename_size );
if (filename[i] != NULL) {
strcpy(filename[i], &argv[index][SIZE_OF_FILE_TYPE]);
} else {
lprintf(LOG_ERR, "ipmitool: malloc failure");
rc = ERROR_STATUS;
break;
}
}
rc = OK_STATUS;
index++;
}
if (rc != ERROR_STATUS) {
if (verbose > 0) {
for (i = 0; i < (argc-1); i++) {
printf ("Type: %s, ",
val2str(file_type[i],
ipmi_ekanalyzer_module_type));
printf("file name: %s\n", filename[i]);
}
}
if (strcmp(argv[0], "print") == 0) {
rc = ipmi_ekanalyzer_print((argc-1),
option, filename, file_type);
} else {
rc = ipmi_ekanalyzer_ekeying_match((argc-1),
option, filename, file_type);
}
for (i = 0; i < (argc-1); i++) {
if (filename[i] != NULL) {
free(filename[i]);
filename[i] = NULL;
}
}
} /* End of ERROR_STATUS */
} /* End of comparison of invalid option */
} else {
lprintf(LOG_ERR, "Invalid ekanalyzer command: %s", argv[0]);
ipmi_ekanalyzer_usage();
rc = ERROR_STATUS;
}
return rc;
}
/**************************************************************************
*
* Function name: ipmi_ekanalyzer_print
*
* Description: this function will display the topology, power or both
* information together according to the option that it received.
*
* Restriction: None
*
* Input: int argc: number of the argument received
* char* opt: option string that will tell what to display
* char** filename: strings that contained filename of FRU data binary file
* int* file_type: a pointer that contain file type (on carrier file,
* a1 file, b1 file...). See structure
* ipmi_ekanalyzer_module_type for a list of valid type
*
* Output: None
*
* Global: None
*
* Return: return 0 as success and -1 as error.
*
***************************************************************************/
static int
ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type)
{
int return_value = OK_STATUS;
/* Display carrier topology */
if ((strcmp(opt, "carrier") == 0) || (strcmp(opt, "default") == 0)) {
tboolean found_flag = FALSE;
int index = 0;
int index_name[argc];
int list = 0;
/* list of multi record */
struct ipmi_ek_multi_header *list_head[argc];
struct ipmi_ek_multi_header *list_record[argc];
struct ipmi_ek_multi_header *list_last[argc];
for (list=0; list < argc; list++) {
list_head[list] = NULL;
list_record[list] = NULL;
list_last[list] = NULL;
}
/* reset list count */
list = 0;
for (index = 0; index < argc; index++) {
if (file_type[index] != ON_CARRIER_FRU_FILE) {
continue;
}
index_name[list] = index;
return_value = ipmi_ekanalyzer_fru_file2structure(filename[index],
&list_head[list],
&list_record[list],
&list_last[list]);
list++;
found_flag = TRUE;
}
if (!found_flag) {
printf("No carrier file has been found\n");
return_value = ERROR_STATUS;
} else {
int i = 0;
for (i = 0; i < argc; i++) {
/* this is a flag to advoid displaying
* the same data multiple time
*/
tboolean first_data = TRUE;
for (list_record[i] = list_head[i];
list_record[i] != NULL;
list_record[i] = list_record[i]->next) {
if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_P2P) {
if (first_data) {
printf("%s\n", STAR_LINE_LIMITER);
printf("From Carrier file: %s\n", filename[index_name[i]]);
first_data = FALSE;
}
return_value = ipmi_ek_display_carrier_connectivity(list_record[i]);
} else if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_INFO) {
/*See AMC.0 specification Table3-3 for mor detail*/
#define COUNT_OFFSET 6
if (first_data) {
printf("From Carrier file: %s\n", filename[index_name[i]]);
first_data = FALSE;
}
printf(" Number of AMC bays supported by Carrier: %d\n",
list_record[i]->data[COUNT_OFFSET]);
}
}
}
/*Destroy the list of record*/
for (i = 0; i < argc; i++) {
while (list_head[i] != NULL) {
ipmi_ek_remove_record_from_list(list_head[i],
&list_head[i], &list_last[i]);
}
/* display deleted result when we
* reach the last record
*/
if ((i == (list-1)) && verbose) {
printf("Record list has been removed successfully\n");
}
}
}
} else if (strcmp(opt, "power") == 0) {
printf("Print power information\n");
return_value = ipmi_ek_display_power(argc, opt, filename, file_type);
} else if (strcmp(opt, "all") == 0) {
printf("Print all information\n");
return_value = ipmi_ek_display_power(argc, opt, filename, file_type);
} else {
lprintf(LOG_ERR, "Invalid option %s", opt);
return_value = ERROR_STATUS;
}
return return_value;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_carrier_connectivity
*
* Description: Display the topology between a Carrier and all AMC modules by
* using carrier p2p connectivity record
*
* Restriction: Ref: AMC.0 Specification: Table 3-13 and Table 3-14
*
* Input: struct ipmi_ek_multi_header* record: a pointer to the carrier p2p
* connectivity record.
*
* Output: None
*
* Global: None
*
* Return: return 0 on success and -1 if the record doesn't exist.
*
***************************************************************************/
static int
ipmi_ek_display_carrier_connectivity(struct ipmi_ek_multi_header *record)
{
int offset = START_DATA_OFFSET;
struct fru_picmgext_carrier_p2p_record rsc_desc;
struct fru_picmgext_carrier_p2p_descriptor *port_desc;
if (record == NULL) {
lprintf(LOG_ERR, "P2P connectivity record is invalid\n");
return ERROR_STATUS;
}
if (verbose > 1) {
int k = 0;
printf("Binary data of Carrier p2p connectivity"\
" record starting from mfg id\n");
for (k = 0; k < (record->header.len); k++) {
printf("%02x ", record->data[k]);
}
printf("\n");
}
while (offset <= (record->header.len - START_DATA_OFFSET)) {
rsc_desc.resource_id = record->data[offset++];
rsc_desc.p2p_count = record->data[offset++];
if (verbose > 0) {
printf("resource id= %02x port count= %d\n",
rsc_desc.resource_id, rsc_desc.p2p_count);
}
/* check if it is an AMC Module */
if ((rsc_desc.resource_id & AMC_MODULE) == AMC_MODULE) {
/* check if it is an RTM module */
if (rsc_desc.resource_id == AMC_MODULE) {
printf(" %s topology:\n",
val2str(RTM_IPMB_L,
ipmi_ekanalyzer_IPMBL_addr));
} else {
/* The last four bits of resource ID
* represent site number (mask = 0x0f)
*/
printf(" %s topology:\n",
val2str((rsc_desc.resource_id & 0x0f),
ipmi_ekanalyzer_module_type));
}
} else {
printf(" On Carrier Device ID %d topology: \n",
(rsc_desc.resource_id & 0x0f));
}
while (rsc_desc.p2p_count > 0) {
unsigned char data[3];
# ifndef WORDS_BIGENDIAN
data[0] = record->data[offset + 0];
data[1] = record->data[offset + 1];
data[2] = record->data[offset + 2];
# else
data[0] = record->data[offset + 2];
data[1] = record->data[offset + 1];
data[2] = record->data[offset + 0];
# endif
port_desc = (struct fru_picmgext_carrier_p2p_descriptor*)data;
offset += sizeof(struct fru_picmgext_carrier_p2p_descriptor);
if ((port_desc->remote_resource_id & AMC_MODULE) == AMC_MODULE) {
printf("\tPort %d =====> %s, Port %d\n",
port_desc->local_port,
val2str((port_desc->remote_resource_id & 0x0f),
ipmi_ekanalyzer_module_type),
port_desc->remote_port);
} else {
printf("\tPort %d =====> On Carrier Device ID %d, Port %d\n",
port_desc->local_port,
(port_desc->remote_resource_id & 0x0f),
port_desc->remote_port);
}
rsc_desc.p2p_count--;
}
}
return OK_STATUS;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_power
*
* Description: Display the power management of the Carrier and AMC module by
* using current management record. If the display option equal to all,
* it will display power and carrier topology together.
*
* Restriction: Reference: AMC.0 Specification, Table 3-11
*
* Input: int argc: number of the argument received
* char* opt: option string that will tell what to display
* char** filename: strings that contained filename of FRU data binary file
* int* file_type: a pointer that contain file type (on carrier file,
* a1 file, b1 file...)
*
* Output: None
*
* Global: None
*
* Return: return 0 on success and -1 if the record doesn't exist.
*
***************************************************************************/
static int
ipmi_ek_display_power( int argc, char * opt, char ** filename, int * file_type )
{
int num_file=0;
int return_value = ERROR_STATUS;
int index = 0;
/*list des multi record*/
struct ipmi_ek_multi_header * list_head[argc];
struct ipmi_ek_multi_header * list_record[argc];
struct ipmi_ek_multi_header * list_last[argc];
for ( num_file = 0; num_file < argc; num_file++ ){
list_head[num_file] = NULL;
list_record[num_file] = NULL;
list_last[num_file] = NULL;
}
for ( num_file = 0; num_file < argc; num_file++ ){
tboolean is_first_data = TRUE;
if ( file_type[num_file] == CONFIG_FILE ){
num_file++;
}
if ( is_first_data ){
printf("%s\n", STAR_LINE_LIMITER);
printf("\nFrom %s file '%s'\n",
val2str( file_type[num_file], ipmi_ekanalyzer_module_type),
filename[num_file]);
is_first_data = FALSE;
}
return_value = ipmi_ekanalyzer_fru_file2structure( filename[num_file],
&list_head[num_file], &list_record[num_file], &list_last[num_file]);
if ( list_head[num_file] != NULL ){
for ( list_record[num_file] = list_head[num_file];
list_record[num_file] != NULL;
list_record[num_file] = list_record[num_file]->next
){
if ( ( strcmp(opt, "all") == 0 )
&& ( file_type[num_file] == ON_CARRIER_FRU_FILE )
){
if ( list_record[num_file]->data[PICMG_ID_OFFSET]
==
FRU_AMC_CARRIER_P2P
){
return_value = ipmi_ek_display_carrier_connectivity(
list_record[num_file] );
}
else if ( list_record[num_file]->data[PICMG_ID_OFFSET]
==
FRU_AMC_CARRIER_INFO
){
/*Ref: See AMC.0 Specification Table 3-3: Carrier Information
* Table about offset value
*/
printf( " Number of AMC bays supported by Carrier: %d\n",
list_record[num_file]->data[START_DATA_OFFSET+1] );
}
}
/*Ref: AMC.0 Specification: Table 3-11
* Carrier Activation and Current Management Record
*/
if ( list_record[num_file]->data[PICMG_ID_OFFSET]
==
FRU_AMC_ACTIVATION
){
int index_data = START_DATA_OFFSET;
struct fru_picmgext_carrier_activation_record car;
struct fru_picmgext_activation_record * cur_desc;
memcpy ( &car, &list_record[num_file]->data[index_data],
sizeof (struct fru_picmgext_carrier_activation_record) );
index_data +=
sizeof (struct fru_picmgext_carrier_activation_record);
cur_desc = malloc (car.module_activation_record_count * \
sizeof (struct fru_picmgext_activation_record) );
for(index=0; index<car.module_activation_record_count; index++){
memcpy( &cur_desc[index],
&list_record[num_file]->data[index_data],
sizeof (struct fru_picmgext_activation_record) );
index_data += sizeof (struct fru_picmgext_activation_record);
}
/*Display the current*/
ipmi_ek_display_current_descriptor( car,
cur_desc, filename[num_file] );
free(cur_desc);
cur_desc = NULL;
}
/*Ref: AMC.0 specification, Table 3-10: Module Current Requirement*/
else if ( list_record[num_file]->data[PICMG_ID_OFFSET]
== FRU_AMC_CURRENT
){
float power_in_watt = 0;
float current_in_amp = 0;
printf(" %s power required (Current Draw): ",
val2str ( file_type[num_file], ipmi_ekanalyzer_module_type) );
current_in_amp =
list_record[num_file]->data[START_DATA_OFFSET]*0.1;
power_in_watt = current_in_amp * AMC_VOLTAGE;
printf("%.2f Watts (%.2f Amps)\n",power_in_watt, current_in_amp);
}
}
return_value = OK_STATUS;
/*Destroy the list of record*/
for ( index = 0; index < argc; index++ ){
while ( list_head[index] != NULL ){
ipmi_ek_remove_record_from_list ( list_head[index],
&list_head[index],&list_last[index] );
}
if ( verbose > 1 )
printf("Record list has been removed successfully\n");
}
}
}
printf("%s\n", STAR_LINE_LIMITER);
return return_value;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_current_descriptor
*
* Description: Display the current descriptor under format xx Watts (xx Amps)
*
* Restriction: None
*
* Input: struct fru_picmgext_carrier_activation_record car: contain binary data
* of carrier activation record
* struct fru_picmgext_activation_record * cur_desc: contain current
* descriptor
* char* filename: strings that contained filename of FRU data binary file
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_current_descriptor(
struct fru_picmgext_carrier_activation_record car,
struct fru_picmgext_activation_record *cur_desc,
char *filename)
{
int index = 0;
float power_in_watt = 0.0;
float current_in_amp = 0.0;
for (index = 0; index < car.module_activation_record_count; index++) {
/* See AMC.0 specification, Table 3-12 for
* detail about calculation
*/
current_in_amp = (float)cur_desc[index].max_module_curr * 0.1;
power_in_watt = (float)current_in_amp * AMC_VOLTAGE;
printf(" Carrier AMC power available on %s:\n",
val2str( cur_desc[index].ibmb_addr,
ipmi_ekanalyzer_IPMBL_addr));
printf("\t- Local IPMB Address \t: %02x\n",
cur_desc[index].ibmb_addr);
printf("\t- Maximum module Current\t: %.2f Watts (%.2f Amps)\n",
power_in_watt, current_in_amp);
}
/* Display total power on Carrier */
current_in_amp = (float)car.max_internal_curr * 0.1;
power_in_watt = (float)current_in_amp * AMC_VOLTAGE;
printf(" Carrier AMC total power available for all bays from file '%s':",
filename);
printf(" %.2f Watts (%.2f Amps)\n", power_in_watt, current_in_amp);
}
/**************************************************************************
*
* Function name: ipmi_ekanalyzer_ekeying_match
*
* Description: Check for possible Ekeying match between two FRU files
*
* Restriction: None
*
* Input: argc: number of the argument received
* opt: string that contains display option received from user.
* filename: strings that contained filename of FRU data binary file
* file_type: a pointer that contain file type (on carrier file,
* a1 file, b1 file...)
*
* Output: None
*
* Global: None
*
* Return: return TRUE on success and FALSE if the record doesn't exist.
*
***************************************************************************/
static tboolean
ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
char ** filename, int * file_type )
{
tboolean return_value = FALSE;
if ( (strcmp(opt, "carrier") == 0 ) || (strcmp(opt, "power") == 0) ){
lprintf(LOG_ERR, " ekanalyzer summary [match/ unmatch/ all]"\
" <xx=frufile> <xx=frufile> [xx=frufile]");
return_value = ERROR_STATUS;
}
else{
int num_file=0;
tboolean amc_file = FALSE; /*used to indicate the present of AMC file*/
tboolean oc_file = FALSE; /*used to indicate the present of Carrier file*/
/*Check for possible ekeying match between files*/
for ( num_file=0; num_file < argc; num_file++ ){
if ( ( file_type[num_file] == ON_CARRIER_FRU_FILE )
|| ( file_type[num_file] == CONFIG_FILE )
|| ( file_type[num_file] == SHELF_MANAGER_FRU_FILE )
){
amc_file = FALSE;
}
else { /*there is an amc file*/
amc_file = TRUE;
break;
}
}
if ( amc_file == FALSE ){
printf("\nNo AMC FRU file is provided --->" \
" No possible ekeying match!\n");
return_value = ERROR_STATUS;
}
else{
/*If no carrier file is provided, return error*/
for ( num_file=0; num_file < argc; num_file++ ){
if ( (file_type[num_file] == ON_CARRIER_FRU_FILE )
|| ( file_type[num_file] == CONFIG_FILE )
|| ( file_type[num_file] == SHELF_MANAGER_FRU_FILE )
){
oc_file = TRUE;
break;
}
}
if ( !oc_file ){
printf("\nNo Carrier FRU file is provided" \
" ---> No possible ekeying match!\n");
return_value = ERROR_STATUS;
}
else{
/*list des multi record*/
struct ipmi_ek_multi_header * list_head[argc];
struct ipmi_ek_multi_header * list_record[argc];
struct ipmi_ek_multi_header * list_last[argc];
struct ipmi_ek_multi_header * pcarrier_p2p;
int list = 0;
int match_pair = 0;
/*Create an empty list*/
for ( list=0; list<argc; list++ ){
list_head[list] = NULL;
list_record[list] = NULL;
list_last[list] = NULL;
}
list=0;
for ( num_file=0; num_file < argc; num_file++ ){
if (file_type[num_file] != CONFIG_FILE){
return_value = ipmi_ekanalyzer_fru_file2structure(
filename[num_file], &list_head[num_file],
&list_record[num_file], &list_last[num_file]);
}
}
/*Get Carrier p2p connectivity record for physical check*/
for (num_file=0; num_file < argc; num_file++){
if (file_type[num_file] == ON_CARRIER_FRU_FILE ){
for ( pcarrier_p2p=list_head[num_file];
pcarrier_p2p != NULL ;
pcarrier_p2p = pcarrier_p2p->next
){
if ( pcarrier_p2p->data[PICMG_ID_OFFSET]
== FRU_AMC_CARRIER_P2P
){
break;
}
}
break;
}
}
/*Determine the match making pair*/
while ( match_pair < argc ){
for ( num_file = (match_pair+1); num_file<argc; num_file++ ){
if ( ( file_type[match_pair] != CONFIG_FILE )
&& ( file_type[num_file] != CONFIG_FILE )
){
if ( ( file_type[match_pair] != ON_CARRIER_FRU_FILE )
|| ( file_type[num_file] != ON_CARRIER_FRU_FILE )
){
printf("%s vs %s\n",
val2str(file_type[match_pair],
ipmi_ekanalyzer_module_type),
val2str(file_type[num_file],
ipmi_ekanalyzer_module_type));
/*Ekeying match between 2 files*/
if (verbose>0){
printf("Start matching process\n");
}
return_value = ipmi_ek_matching_process( file_type,
match_pair, num_file, list_head,
list_last, opt, pcarrier_p2p);
}
}
}
match_pair ++;
}
for( num_file=0; num_file < argc; num_file++ ){
if (list_head[num_file] != NULL ){
ipmi_ek_remove_record_from_list( list_head[num_file],
&list_record[num_file], &list_last[num_file]);
}
if ( ( num_file == argc-1 ) && verbose )
printf("Record list has been removed successfully\n");
}
return_value = OK_STATUS;
}
}
}
return return_value;
}
/**************************************************************************
*
* Function name: ipmi_ek_matching_process
*
* Description: This function process the OEM check, Physical Connectivity check,
* and Link Descriptor comparison to do Ekeying match
*
* Restriction: None
*
* Input: file_type: a pointer that contain file type (on carrier file,
* a1 file, b1 file...)
* index1: position of the first record in the list of the record
* index2: position of the second record in the list of the record
* ipmi_ek_multi_header ** list_head: pointer to the header of a
* linked list that contain FRU multi record
* ipmi_ek_multi_header ** list_last: pointer to the tale of a
* linked list that contain FRU multi record
* opt: string that contain display option such as "match", "unmatch", or
* "all".
* pphysical: a pointer that contain a carrier p2p connectivity record
* to perform physical check
*
* Output: None
*
* Global: None
*
* Return: return OK_STATUS on success and ERROR_STATUS if the record doesn't
* exist.
*
***************************************************************************/
static int ipmi_ek_matching_process( int * file_type, int index1, int index2,
struct ipmi_ek_multi_header ** list_head,
struct ipmi_ek_multi_header ** list_last, char * opt,
struct ipmi_ek_multi_header * pphysical )
{
int result = ERROR_STATUS;
struct ipmi_ek_multi_header * record;
int num_amc_record1 = 0;/*Number of AMC records in the first module*/
int num_amc_record2 = 0;/*Number of AMC records in the second module*/
/* Comparison between an On-Carrier and an AMC*/
if ( file_type[index2] == ON_CARRIER_FRU_FILE ){
int index_temp = 0;
index_temp = index1;
index1 = index2; /*index1 indicate on carrier*/
index2 = index_temp; /*index2 indcate an AMC*/
}
/*Calculate record size for Carrier file*/
for ( record=list_head[index1]; record != NULL;record = record->next ){
if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
num_amc_record2++;
}
}
/*Calculate record size for amc file*/
for ( record=list_head[index2]; record != NULL;record = record->next){
if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
num_amc_record1++;
}
}
if ( (num_amc_record1 > 0) && (num_amc_record2 > 0) ){
int index_record1 = 0;
int index_record2 = 0;
/* Multi records of AMC module */
struct ipmi_ek_amc_p2p_connectivity_record * amc_record1 = NULL;
/* Multi records of Carrier or an AMC module */
struct ipmi_ek_amc_p2p_connectivity_record * amc_record2 = NULL;
amc_record1 = malloc ( num_amc_record1 * \
sizeof(struct ipmi_ek_amc_p2p_connectivity_record));
amc_record2 = malloc ( num_amc_record2 * \
sizeof(struct ipmi_ek_amc_p2p_connectivity_record));
for (record=list_head[index2]; record != NULL;record = record->next){
if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
result = ipmi_ek_create_amc_p2p_record( record,
&amc_record1[index_record1] );
if (result != ERROR_STATUS){
struct ipmi_ek_multi_header * current_record = NULL;
for ( current_record=list_head[index1];
current_record != NULL ;
current_record = current_record->next
){
if ( current_record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
result = ipmi_ek_create_amc_p2p_record( current_record,
&amc_record2[index_record2] );
if ( result != ERROR_STATUS ){
if ( result == OK_STATUS ){
/*Compare Link descriptor*/
result = ipmi_ek_compare_link ( pphysical,
amc_record1[index_record1],
amc_record2[index_record2],
opt, file_type[index1], file_type[index2]);
}
index_record2++;
}
} /*end of FRU_AMC_P2P */
} /* end of for loop */
index_record1++;
}
}
}
free(amc_record1) ;
amc_record1 = NULL;
free(amc_record2) ;
amc_record2 = NULL;
}
else{
printf("No amc record is found!\n");
}
return result;
}
/**************************************************************************
*
* Function name: ipmi_ek_check_physical_connectivity
*
* Description: This function check for point to point connectivity between
* two modules by comparing each enable port in link descriptor
* with local and remote ports of port descriptor in
* carrier point-to-point connectivity record according to the
* corresponding file type ( a1, b1, b2...).
*
* Restriction: In order to perform physical check connectivity, it needs to
* compare between 2 AMC Modules, so the use of index ( 1 and 2 )
* can facilitate the comparison in this case.
*
* Input: record1: is an AMC p2p record for an AMC module
* record2 is an AMC p2p record for an On-Carrier record or an AMC module
* char* opt: option string that will tell if a matching result, unmatched
* result or all the results will be displayed.
* file_type1: indicates type of the first module
* file_type2: indicates type of the second module
*
* Output: None
*
* Global: None
*
* Return: return OK_STATUS if both link are matched, otherwise
* return ERROR_STATUS
*
***************************************************************************/
static int
ipmi_ek_check_physical_connectivity(
struct ipmi_ek_amc_p2p_connectivity_record record1, int index1,
struct ipmi_ek_amc_p2p_connectivity_record record2, int index2,
struct ipmi_ek_multi_header * record,
int filetype1, int filetype2, char * option )
{
int return_status = OK_STATUS;
if ( record == NULL ){
printf("NO Carrier p2p connectivity !\n");
return_status = ERROR_STATUS;
}
else{
#define INVALID_AMC_SITE_NUMBER -1
int index = START_DATA_OFFSET;
int amc_site = INVALID_AMC_SITE_NUMBER;
struct fru_picmgext_carrier_p2p_record rsc_desc;
struct fru_picmgext_carrier_p2p_descriptor * port_desc = NULL;
/* Get the physical connectivity record */
while ( index < record->header.len ) {
rsc_desc.resource_id = record->data[index++];
rsc_desc.p2p_count = record->data[index++];
/* carrier p2p record starts with on-carrier device */
if ( (rsc_desc.resource_id == record1.rsc_id)
||
(rsc_desc.resource_id == record2.rsc_id)
){
if (rsc_desc.p2p_count <= 0){
printf("No p2p count\n");
return_status = ERROR_STATUS;
}
else{
port_desc = malloc ( rsc_desc.p2p_count *
sizeof(struct fru_picmgext_carrier_p2p_descriptor) );
index = ipmi_ek_get_resource_descriptor( rsc_desc.p2p_count,
index, port_desc, record );
amc_site = INVALID_AMC_SITE_NUMBER;
break;
}
}
else{ /* carrier p2p record starts with AMC module */
if (rsc_desc.resource_id == AMC_MODULE){
if (filetype1 != ON_CARRIER_FRU_FILE){
amc_site = filetype1;
}
else{
amc_site = filetype2;
}
}
else{
amc_site = rsc_desc.resource_id & 0x0f;
}
if ( amc_site > 0 ){
if ( (amc_site == filetype1) || (amc_site == filetype2) ){
port_desc = malloc ( rsc_desc.p2p_count *
sizeof(struct fru_picmgext_carrier_p2p_descriptor) );
index = ipmi_ek_get_resource_descriptor( rsc_desc.p2p_count,
index, port_desc, record );
break;
}
}
else{
return_status = ERROR_STATUS;
}
}
/*If the record doesn't contain the same AMC site number in command
* line, go to the next record
*/
index += ( sizeof(struct fru_picmgext_carrier_p2p_descriptor) *
rsc_desc.p2p_count );
}
if ( (port_desc != NULL) && (return_status != ERROR_STATUS) ){
int j=0;
for ( j = 0; j < rsc_desc.p2p_count; j++ ){
/* Compare only enable channel descriptor */
if ( record1.ch_desc[index1].lane0port != DISABLE_PORT ){
/* matching result from channel descriptor comparison */
tboolean match_lane = FALSE;
match_lane = ipmi_ek_compare_channel_descriptor (
record1.ch_desc[index1], record2.ch_desc[index2],
port_desc, j, rsc_desc.resource_id );
if ( match_lane ){
if ( filetype1 != ON_CARRIER_FRU_FILE ){
if ( (
(filetype1 == (rsc_desc.resource_id & 0x0f))
&&
(filetype2 ==(port_desc[j].remote_resource_id &0x0f))
)
||
(
(filetype2 == (rsc_desc.resource_id & 0x0f))
&&
(filetype1 ==(port_desc[j].remote_resource_id &0x0f))
)
){
if ( ! (strcmp(option, "unmatch") == 0) ){
printf("%s port %d ==> %s port %d\n",
val2str(filetype2, ipmi_ekanalyzer_module_type),
record1.ch_desc[index1].lane0port,
val2str(filetype1, ipmi_ekanalyzer_module_type),
record2.ch_desc[index2].lane0port);
}
return_status = OK_STATUS;
break;
}
else{
if (verbose == LOG_DEBUG){
printf("No point 2 point connectivity\n");
}
return_status = ERROR_STATUS;
}
}
else{
if ( (record2.rsc_id == (rsc_desc.resource_id) )
&&
(filetype2 == (port_desc[j].remote_resource_id & 0x0f))
){
if ( ! (strcmp(option, "unmatch") == 0) ){
printf("%s port %d ==> %s port %d\n",
val2str(filetype2, ipmi_ekanalyzer_module_type),
record1.ch_desc[index1].lane0port,
val2str(filetype1, ipmi_ekanalyzer_module_type),
record2.ch_desc[index2].lane0port);
}
return_status = OK_STATUS;
break;
}
else if ( (filetype2 == (rsc_desc.resource_id & 0x0f) )
&&
(record2.rsc_id == (port_desc[j].remote_resource_id))
){
if ( ! (strcmp(option, "unmatch") == 0) ){
printf("%s port %d ==> %s %x port %d\n",
val2str(filetype2, ipmi_ekanalyzer_module_type),
record1.ch_desc[index1].lane0port,
val2str(filetype1, ipmi_ekanalyzer_module_type),
record2.rsc_id,record2.ch_desc[index2].lane0port);
}
return_status = OK_STATUS;
break;
}
else{
if (verbose == LOG_DEBUG){
printf("No point 2 point connectivity\n");
}
return_status = ERROR_STATUS;
}
}
}
else{
if (verbose == LOG_DEBUG){
printf("No point 2 point connectivity\n");
}
return_status = ERROR_STATUS;
}
}
else{ /*If the link is disable, the result is always true*/
return_status = OK_STATUS;
}
}
}
else{
if (verbose == LOG_WARN){
printf("Invalid Carrier p2p connectivity record\n");
}
return_status = ERROR_STATUS;
}
if (port_desc != NULL){
free(port_desc);
port_desc = NULL;
}
}
return return_status;
}
/**************************************************************************
*
* Function name: ipmi_ek_compare_link
*
* Description: This function compares link grouping id of each
* amc p2p connectiviy record
*
* Restriction: None
*
* Input: record1: is an AMC p2p record for an AMC module
* record2 is an AMC p2p record for an On-Carrier record or an AMC module
* char* opt: option string that will tell if a matching result, unmatched
* result or all the results will be displayed.
* file_type1: indicates type of the first module
* file_type2: indicates type of the second module
*
* Output: None
*
* Global: None
*
* Return: return 0 if both link are matched, otherwise return -1
*
***************************************************************************/
static int
ipmi_ek_compare_link( struct ipmi_ek_multi_header * physic_record,
struct ipmi_ek_amc_p2p_connectivity_record record1,
struct ipmi_ek_amc_p2p_connectivity_record record2, char * opt,
int file_type1, int file_type2 )
{
int result = ERROR_STATUS;
int index1 = 0; /*index for AMC module*/
int index2 = 0; /*index for On-carrier type*/
record1.matching_result = malloc ( record1.link_desc_count * sizeof(int) );
record2.matching_result = malloc ( record2.link_desc_count * sizeof(int) );
/*Initialize all the matching_result to false*/
for( index2 = 0; index2 < record2.link_desc_count; index2++ ){
record2.matching_result[index2] = FALSE;
}
for( index1 = 0; index1 < record1.link_desc_count; index1++ ){
for( index2 = 0; index2 < record2.link_desc_count; index2++ ){
if( record1.link_desc[index1].group_id == 0 ){
if( record2.link_desc[index2].group_id == 0 ){
result = ipmi_ek_compare_link_descriptor(
record1, index1, record2, index2 );
if ( result == OK_STATUS ){
/*Calculate the index for Channel descriptor in function of
* link designator channel ID
*/
/*first channel_id in the AMC Link descriptor of record1*/
static int flag_first_link1;
int index_ch_desc1; /*index of channel descriptor */
/*first channel_id in the AMC Link descriptor of record2*/
static int flag_first_link2;
int index_ch_desc2; /*index of channel descriptor*/
if (index1==0){ /*this indicate the first link is encounter*/
flag_first_link1 = record1.link_desc[index1].channel_id;
}
index_ch_desc1 = record1.link_desc[index1].channel_id -
flag_first_link1;
if (index2==0){
flag_first_link2 = record2.link_desc[index2].channel_id;
}
index_ch_desc2 = record2.link_desc[index2].channel_id -
flag_first_link2;
/*Check for physical connectivity for each link*/
result = ipmi_ek_check_physical_connectivity ( record1,
index_ch_desc1, record2, index_ch_desc2,
physic_record, file_type1, file_type2, opt );
if ( result == OK_STATUS ){
/*Display the result if option = match or all*/
if ( (strcmp( opt, "match" ) == 0)
|| (strcmp( opt, "all" ) == 0)
|| (strcmp( opt, "default" ) == 0)
){
tboolean isOEMtype = FALSE;
printf(" Matching Result\n");
isOEMtype = ipmi_ek_display_link_descriptor( file_type1,
record2.rsc_id,
"From", record2.link_desc[index2]);
if (isOEMtype){
ipmi_ek_display_oem_guid (record2);
}
isOEMtype = ipmi_ek_display_link_descriptor( file_type2,
record1.rsc_id,
"To", record1.link_desc[index1] );
if (isOEMtype){
ipmi_ek_display_oem_guid (record1);
}
printf(" %s\n", STAR_LINE_LIMITER);
}
record2.matching_result[index2] = TRUE;
record1.matching_result[index1] = TRUE;
/*quit the fist loop since the match is found*/
index2 = record2.link_desc_count;
}
}
}
}
else { /*Link Grouping ID is non zero, Compare all link descriptor
* that has non-zero link grouping id together
*/
if (record2.link_desc[index2].group_id != 0 ){
result = ipmi_ek_compare_link_descriptor(
record1, index1, record2, index2 );
if ( result == OK_STATUS ){
/*Calculate the index for Channel descriptor in function of
* link designator channel ID
*/
/*first channel_id in the AMC Link descriptor of record1*/
static int flag_first_link1;
int index_ch_desc1; /*index of channel descriptor */
/*first channel_id in the AMC Link descriptor of record2*/
static int flag_first_link2;
int index_ch_desc2; /*index of channel descriptor*/
if (index1==0){ /*this indicate the first link is encounter*/
flag_first_link1 = record1.link_desc[index1].channel_id;
}
index_ch_desc1 = record1.link_desc[index1].channel_id -
flag_first_link1;
if (index2==0){
flag_first_link2 = record2.link_desc[index2].channel_id;
}
index_ch_desc2 = record2.link_desc[index2].channel_id -
flag_first_link2;
/*Check for physical connectivity for each link*/
result = ipmi_ek_check_physical_connectivity (
record1, index_ch_desc1, record2, index_ch_desc2,
physic_record, file_type1, file_type2, opt );
if ( result == OK_STATUS ){
if ( (strcmp( opt, "match" ) == 0)
|| (strcmp( opt, "all" ) == 0)
|| (strcmp( opt, "default" ) == 0)
){
tboolean isOEMtype = FALSE;
printf(" Matching Result\n");
isOEMtype = ipmi_ek_display_link_descriptor( file_type1,
record2.rsc_id,
"From", record2.link_desc[index2] );
if ( isOEMtype ){
ipmi_ek_display_oem_guid (record2);
}
isOEMtype = ipmi_ek_display_link_descriptor( file_type2,
record1.rsc_id,
"To", record1.link_desc[index1] );
if (isOEMtype){
ipmi_ek_display_oem_guid (record1);
}
printf(" %s\n", STAR_LINE_LIMITER);
}
record2.matching_result[index2] = TRUE;
record1.matching_result[index1] = TRUE;
/*leave the fist loop since the match is found*/
index2 = record2.link_desc_count;
}
}
}
}
}
}
if ( (strcmp(opt, "unmatch") == 0) || (strcmp(opt, "all") == 0) ){
int isOEMtype = FALSE;
printf(" Unmatching result\n");
for (index1 = 0; index1 < record1.link_desc_count; index1++){
isOEMtype = ipmi_ek_display_link_descriptor( file_type2,
record1.rsc_id, "", record1.link_desc[index1] );
if ( isOEMtype ){
ipmi_ek_display_oem_guid (record1);
}
printf(" %s\n", STAR_LINE_LIMITER);
}
for ( index2 = 0; index2 < record2.link_desc_count; index2++){
if ( !record2.matching_result[index2] ){
isOEMtype = ipmi_ek_display_link_descriptor( file_type1,
record2.rsc_id, "", record2.link_desc[index2] );
if ( isOEMtype ){
ipmi_ek_display_oem_guid (record2);
}
printf(" %s\n", STAR_LINE_LIMITER);
}
}
}
free(record1.matching_result);
record1.matching_result = NULL;
free(record2.matching_result);
record2.matching_result = NULL;
return result;
}
/**************************************************************************
*
* Function name: ipmi_ek_compare_channel_descriptor
*
* Description: This function compares 2 channel descriptors of 2 AMC
* point-to-point connectivity records with port descriptor of
* carrier point-to-point connectivity record. The comparison is
* made between each enable port only.
*
* Restriction: Reference: AMC.0 specification:
* - Table 3-14 for port descriptor
* - Table 3-17 for channel descriptor
*
* Input: ch_desc1: first channel descriptor
* ch_desc2: second channel descriptor
* port_desc: a pointer that contain a list of port descriptor
* index_port: index of the port descriptor
* rsc_id: resource id that represents as local resource id in the
* resource descriptor table.
*
* Output: None
*
* Global: None
*
* Return: return TRUE if both channel descriptor are matched,
* or FALSE otherwise
*
***************************************************************************/
static tboolean
ipmi_ek_compare_channel_descriptor(
struct fru_picmgext_amc_channel_desc_record ch_desc1,
struct fru_picmgext_amc_channel_desc_record ch_desc2,
struct fru_picmgext_carrier_p2p_descriptor * port_desc,
int index_port, unsigned char rsc_id )
{
tboolean match_lane = FALSE;
/* carrier p2p record start with AMC_MODULE as local port */
if ( (rsc_id & AMC_MODULE) == AMC_MODULE ){
if ( (ch_desc1.lane0port == port_desc[index_port].local_port)
&&
(ch_desc2.lane0port == port_desc[index_port].remote_port)
){
/*check if the port is enable*/
if (ch_desc1.lane1port != DISABLE_PORT){
index_port ++;
if ( (ch_desc1.lane1port == port_desc[index_port].local_port)
&&
(ch_desc2.lane1port == port_desc[index_port].remote_port)
){
if (ch_desc1.lane2port != DISABLE_PORT){
index_port++;
if ( (ch_desc1.lane2port == port_desc[index_port].local_port)
&&
(ch_desc2.lane2port == port_desc[index_port].remote_port)
){
if (ch_desc1.lane3port != DISABLE_PORT){
index_port++;
if ( (ch_desc1.lane3port ==
port_desc[index_port].local_port)
&&
(ch_desc2.lane3port ==
port_desc[index_port].remote_port)
){
match_lane = TRUE;
}
}
else{
match_lane = TRUE;
}
} /* end of if lane2port */
}
else{
match_lane = TRUE;
}
} /* end of if lane1port */
}
else{ /*if the port is disable, the compare result is always true*/
match_lane = TRUE;
}
}/* end of if lane0port */
}
/* carrier p2p record start with Carrier as local port */
else{
if ( (ch_desc1.lane0port == port_desc[index_port].remote_port)
&&
(ch_desc2.lane0port == port_desc[index_port].local_port)
){
if (ch_desc1.lane1port != DISABLE_PORT){
index_port ++;
if ( (ch_desc1.lane1port == port_desc[index_port].remote_port)
&&
(ch_desc2.lane1port == port_desc[index_port].local_port)
){
if (ch_desc1.lane2port != DISABLE_PORT){
index_port++;
if ( (ch_desc1.lane2port == port_desc[index_port].remote_port)
&&
(ch_desc2.lane2port == port_desc[index_port].local_port)
){
if (ch_desc1.lane3port != DISABLE_PORT){
index_port++;
if ( (ch_desc1.lane3port ==
port_desc[index_port].remote_port)
&&
(ch_desc2.lane3port ==
port_desc[index_port].local_port)
){
match_lane = TRUE;
}
}
else{
match_lane = TRUE;
}
} /* end of if lane2port */
}
else{
match_lane = TRUE;
}
} /* end of if lane1port */
}
else{
match_lane = TRUE;
}
} /* end of if lane0port */
}
return match_lane;
}
/**************************************************************************
*
* Function name: ipmi_ek_compare_link_descriptor
*
* Description: This function compares 2 link descriptors of 2
* amc p2p connectiviy record
*
* Restriction: None
*
* Input: record1: AMC p2p connectivity record of the 1rst AMC or Carrier Module
* index1: index of AMC link descriptor in 1rst record
* record2: AMC p2p connectivity record of the 2nd AMC or Carrier Module
* index1: index of AMC link descriptor in 2nd record
*
* Output: None
*
* Global: None
*
* Return: return OK_STATUS if both link are matched,
* otherwise return ERROR_STATUS
*
***************************************************************************/
static int
ipmi_ek_compare_link_descriptor(
struct ipmi_ek_amc_p2p_connectivity_record record1,
int index1,
struct ipmi_ek_amc_p2p_connectivity_record record2,
int index2)
{
int result = ERROR_STATUS;
if (record1.link_desc[index1].type != record2.link_desc[index2].type) {
return ERROR_STATUS;
}
/* if it is an OEM type, we compare the OEM GUID */
if ((record1.link_desc[index1].type >= LOWER_OEM_TYPE)
&& (record1.link_desc[index1].type <= UPPER_OEM_TYPE)) {
if ((record1.guid_count == 0) && (record2.guid_count == 0)) {
/*there is no GUID for comparison, so the result is always OK*/
result = OK_STATUS;
} else {
int i = 0;
int j = 0;
for (i = 0; i < record1.guid_count; i++) {
for (j = 0; j < record2.guid_count; j++) {
if (memcmp(&record1.oem_guid[i],
&record2.oem_guid[j],
SIZE_OF_GUID) == 0) {
result = OK_STATUS;
break;
}
}
}
}
} else {
result = OK_STATUS;
}
if (result != OK_STATUS) {
return result;
}
if (record1.link_desc[index1].type_ext == record2.link_desc[index2].type_ext) {
unsigned char asym[COMPARE_CANDIDATE];
int offset = 0;
asym[offset++] = record1.link_desc[index1].asym_match;
asym[offset] = record2.link_desc[index2].asym_match;
result = ipmi_ek_compare_asym (asym);
if (result == OK_STATUS){
struct fru_picmgext_amc_link_desc_record link[COMPARE_CANDIDATE];
int index = 0;
link[index++] = record1.link_desc[index1];
link[index] = record2.link_desc[index2];
result = ipmi_ek_compare_number_of_enable_port(link);
} else {
result = ERROR_STATUS;
}
} else {
result = ERROR_STATUS;
}
return result;
}
/**************************************************************************
*
* Function name: ipmi_ek_compare_asym
*
* Description: This function compares 2 asymetric match of 2
* amc link descriptors
*
* Restriction: None
*
* Input: asym[COMPARE_CANDIDATE]: Contain 2 asymetric match for comparison
*
* Output: None
*
* Global: None
*
* Return: return 0 if both asym. match are matched, otherwise return -1
*
***************************************************************************/
static int
ipmi_ek_compare_asym(unsigned char asym[COMPARE_CANDIDATE])
{
int return_value = ERROR_STATUS;
int first_index = 0;
int second_index = 1;
if ((asym[first_index] == 0) && (asym[second_index] == 0)) {
return_value = OK_STATUS;
} else if ((asym[first_index] & asym[second_index]) == 0) {
return_value = OK_STATUS;
} else {
return_value = ERROR_STATUS;
}
return return_value;
}
/**************************************************************************
*
* Function name: ipmi_ek_compare_link_descriptor
*
* Description: This function compare number of enble port of Link designator
*
* Restriction: None
*
* Input: link_designator1: first link designator
* link_designator2: second link designator
*
* Output: None
*
* Global: None
*
* Return: return 0 if both link are matched, otherwise return -1
*
***************************************************************************/
static int
ipmi_ek_compare_number_of_enable_port(
struct fru_picmgext_amc_link_desc_record link_desc[COMPARE_CANDIDATE])
{
int amc_port_count = 0;
int carrier_port_count = 0;
int return_value = ERROR_STATUS;
int index = 0;
if (link_desc[index].port_flag_0) {
/*bit 0 indicates port 0*/
amc_port_count++;
}
if (link_desc[index].port_flag_1) {
/*bit 1 indicates port 1*/
amc_port_count++;
}
if (link_desc[index].port_flag_2) {
/*bit 2 indicates port 2*/
amc_port_count++;
}
if (link_desc[index++].port_flag_3) {
/*bit 3 indicates port 3*/
amc_port_count++;
}
/* 2nd link designator */
if (link_desc[index].port_flag_0) {
/*bit 0 indicates port 0*/
carrier_port_count++;
}
if (link_desc[index].port_flag_1) {
/*bit 1 indicates port 1*/
carrier_port_count++;
}
if (link_desc[index].port_flag_2) {
/*bit 2 indicates port 2*/
carrier_port_count++;
}
if (link_desc[index].port_flag_3) {
/*bit 3 indicates port 3*/
carrier_port_count++;
}
if (carrier_port_count == amc_port_count) {
return_value = OK_STATUS;
} else {
return_value = ERROR_STATUS;
}
return return_value;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_link_descriptor
*
* Description: Display the link descriptor of an AMC p2p connectivity record
*
* Restriction: See AMC.0 or PICMG 3.0 specification for detail about bit masks
*
* Input: file_type: module type.
* rsc_id: resource id
* char* str: indicates if it is a source (its value= "From") or a
* destination (its value = "To"). ( it is set to "" if it is not
* a source nor destination
* link_desc: AMC link descriptor
* asym: asymetric match
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static tboolean
ipmi_ek_display_link_descriptor(int file_type, unsigned char rsc_id,
char *str,
struct fru_picmgext_amc_link_desc_record link_desc)
{
tboolean isOEMtype = FALSE;
if (file_type == ON_CARRIER_FRU_FILE) {
printf(" - %s On-Carrier Device ID %d\n", str,
(rsc_id & 0x0f));
} else {
printf(" - %s %s\n", str, val2str(file_type,
ipmi_ekanalyzer_module_type));
}
printf(" - Channel ID %d || ", link_desc.channel_id);
printf("%s", link_desc.port_flag_0 ? "Lane 0: enable" : "");
printf("%s", link_desc.port_flag_1 ? ", Lane 1: enable" : "");
printf("%s", link_desc.port_flag_2 ? ", Lane 2: enable" : "");
printf("%s", link_desc.port_flag_3 ? ", Lane 3: enable" : "");
printf("\n");
printf(" - Link Type: %s \n", val2str(link_desc.type,
ipmi_ekanalyzer_link_type));
switch (link_desc.type) {
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE:
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1:
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2:
printf(" - Link Type extension: %s\n",
val2str(link_desc.type_ext,
ipmi_ekanalyzer_extension_PCIE));
printf(" - Link Group ID: %d || ", link_desc.group_id);
printf("Link Asym. Match: %d - %s\n",
link_desc.asym_match,
val2str(link_desc.asym_match,
ipmi_ekanalyzer_asym_PCIE));
break;
case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET:
printf(" - Link Type extension: %s\n",
val2str(link_desc.type_ext,
ipmi_ekanalyzer_extension_ETHERNET));
printf(" - Link Group ID: %d || ", link_desc.group_id);
printf("Link Asym. Match: %d - %s\n",
link_desc.asym_match,
val2str(link_desc.asym_match,
ipmi_ekanalyzer_asym_PCIE));
break;
case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE:
printf(" - Link Type extension: %s\n",
val2str(link_desc.type_ext,
ipmi_ekanalyzer_extension_STORAGE));
printf(" - Link Group ID: %d || ",
link_desc.group_id);
printf("Link Asym. Match: %d - %s\n",
link_desc.asym_match,
val2str(link_desc.asym_match,
ipmi_ekanalyzer_asym_STORAGE));
break;
default:
printf(" - Link Type extension: %i\n",
link_desc.type_ext);
printf(" - Link Group ID: %d || ",
link_desc.group_id);
printf("Link Asym. Match: %i\n",
link_desc.asym_match);
break;
}
/* return as OEM type if link type indicates OEM */
if ((link_desc.type >= LOWER_OEM_TYPE)
&& (link_desc.type <= UPPER_OEM_TYPE)) {
isOEMtype = TRUE;
}
return isOEMtype;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_oem_guid
*
* Description: Display the oem guid of an AMC p2p connectivity record
*
* Restriction: None
*
* Input: amc_record: AMC p2p connectivity record
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_oem_guid(struct ipmi_ek_amc_p2p_connectivity_record amc_record)
{
int index_oem = 0;
int index = 0;
if (amc_record.guid_count == 0) {
printf("\tThere is no OEM GUID for this module\n");
}
for (index_oem = 0; index_oem < amc_record.guid_count; index_oem++) {
printf(" - GUID: ");
for (index = 0; index < SIZE_OF_GUID; index++) {
printf("%02x",
amc_record.oem_guid[index_oem].guid[index]);
/* For a better look: putting a "-" after displaying
* four bytes of GUID
*/
if (!(index % 4)){
printf("-");
}
}
printf("\n");
}
}
/**************************************************************************
*
* Function name: ipmi_ek_create_amc_p2p_record
*
* Description: this function create an AMC point 2 point connectivity record
* that contain link descriptor, channel descriptor, oem guid
*
* Restriction: Reference: AMC.0 Specification Table 3-16
*
* Input: record: a pointer to FRU multi record
*
* Output: amc_record: a pointer to the created AMC p2p record
*
* Global: None
*
* Return: Return OK_STATUS on success, or ERROR_STATUS if no record has been
* created.
*
***************************************************************************/
static int
ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record,
struct ipmi_ek_amc_p2p_connectivity_record *amc_record)
{
int index_data = START_DATA_OFFSET;
int return_status = OK_STATUS;
amc_record->guid_count = record->data[index_data++];
if (amc_record->guid_count > 0) {
int index_oem = 0;
amc_record->oem_guid = malloc(amc_record->guid_count * \
sizeof(struct fru_picmgext_guid));
if (amc_record->oem_guid == NULL) {
return ERROR_STATUS;
}
for (index_oem = 0; index_oem < amc_record->guid_count;
index_oem++) {
memcpy(&amc_record->oem_guid[index_oem].guid,
&record->data[index_data],
SIZE_OF_GUID);
index_data += (int)SIZE_OF_GUID;
}
amc_record->rsc_id = record->data[index_data++];
amc_record->ch_count = record->data[index_data++];
/* Calculate link descriptor count */
amc_record->link_desc_count = ((record->header.len) - 8 -
(SIZE_OF_GUID*amc_record->guid_count) -
(FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
amc_record->ch_count)) / 5 ;
} else {
amc_record->rsc_id = record->data[index_data++];
amc_record->ch_count = record->data[index_data++];
/* Calculate link descriptor count see spec AMC.0 for detail */
amc_record->link_desc_count = ((record->header.len) - 8 -
(FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
amc_record->ch_count)) / 5;
}
if (amc_record->ch_count > 0) {
int ch_index = 0;
amc_record->ch_desc = malloc((amc_record->ch_count) * \
sizeof(struct fru_picmgext_amc_channel_desc_record));
if (amc_record->ch_desc == NULL) {
return ERROR_STATUS;
}
for (ch_index = 0; ch_index < amc_record->ch_count;
ch_index++) {
unsigned int data;
struct fru_picmgext_amc_channel_desc_record *src, *dst;
data = record->data[index_data] |
(record->data[index_data + 1] << 8) |
(record->data[index_data + 2] << 16);
src = (struct fru_picmgext_amc_channel_desc_record *)&data;
dst = (struct fru_picmgext_amc_channel_desc_record *)
&amc_record->ch_desc[ch_index];
dst->lane0port = src->lane0port;
dst->lane1port = src->lane1port;
dst->lane2port = src->lane2port;
dst->lane3port = src->lane3port;
index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
}
}
if (amc_record->link_desc_count > 0) {
int i=0;
amc_record->link_desc = malloc(amc_record->link_desc_count * \
sizeof(struct fru_picmgext_amc_link_desc_record));
if (amc_record->link_desc == NULL) {
return ERROR_STATUS;
}
for (i = 0; i< amc_record->link_desc_count; i++) {
unsigned int data[2];
struct fru_picmgext_amc_link_desc_record *src, *dst;
data[0] = record->data[index_data] |
(record->data[index_data + 1] << 8) |
(record->data[index_data + 2] << 16) |
(record->data[index_data + 3] << 24);
data[1] = record->data[index_data + 4];
src = (struct fru_picmgext_amc_link_desc_record*)&data;
dst = (struct fru_picmgext_amc_link_desc_record*)
&amc_record->link_desc[i];
dst->channel_id = src->channel_id;
dst->port_flag_0 = src->port_flag_0;
dst->port_flag_1 = src->port_flag_1;
dst->port_flag_2 = src->port_flag_2;
dst->port_flag_3 = src->port_flag_3;
dst->type = src->type;
dst->type_ext = src->type_ext;
dst->group_id = src->group_id;
dst->asym_match = src->asym_match;
index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE;
}
} else {
return_status = ERROR_STATUS;
}
return return_status;
}
/**************************************************************************
*
* Function name: ipmi_ek_get_resource_descriptor
*
* Description: this function create the resource descriptor of Carrier p2p
* connectivity record.
*
* Restriction: None
*
* Input: port_count: number of port count
* index: index to the position of data start offset
* record: a pointer to FRU multi record
*
* Output: port_desc: a pointer to the created resource descriptor
*
* Global: None
*
* Return: Return index that indicates the current position of data in record.
*
***************************************************************************/
static int
ipmi_ek_get_resource_descriptor(int port_count, int index,
struct fru_picmgext_carrier_p2p_descriptor *port_desc,
struct ipmi_ek_multi_header *record)
{
int num_port = 0;
while (num_port < port_count) {
memcpy(&port_desc[num_port], &record->data[index],
sizeof (struct fru_picmgext_carrier_p2p_descriptor));
index += sizeof (struct fru_picmgext_carrier_p2p_descriptor);
num_port++;
}
return index;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_fru_header
*
* Description: this function display FRU header offset from a FRU binary file
*
* Restriction: Reference: IPMI Platform Management FRU Information Storage
* Definition V1.0, Section 8
*
* Input: filename: name of FRU binary file
*
* Output: None
*
* Global: None
*
* Return: Return OK_STATUS on sucess, ERROR_STATUS on error
*
***************************************************************************/
static int
ipmi_ek_display_fru_header(char *filename)
{
FILE *input_file;
struct fru_header header;
int ret = 0;
input_file = fopen(filename, "r");
if (input_file == NULL) {
lprintf(LOG_ERR, "File '%s' not found.", filename);
return (ERROR_STATUS);
}
ret = fread(&header, sizeof (struct fru_header), 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Failed to read FRU header!");
fclose(input_file);
return (ERROR_STATUS);
}
printf("%s\n", EQUAL_LINE_LIMITER);
printf("FRU Header Info\n");
printf("%s\n", EQUAL_LINE_LIMITER);
printf("Format Version :0x%02x %s\n",
(header.version & 0x0f),
((header.version & 0x0f) == 1) ? "" : "{unsupported}");
printf("Internal Use Offset :0x%02x\n", header.offset.internal);
printf("Chassis Info Offset :0x%02x\n", header.offset.chassis);
printf("Board Info Offset :0x%02x\n", header.offset.board);
printf("Product Info Offset :0x%02x\n", header.offset.product);
printf("MultiRecord Offset :0x%02x\n", header.offset.multi);
printf("Common header Checksum :0x%02x\n", header.checksum);
fclose(input_file);
return OK_STATUS;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_fru_header_detail
*
* Description: this function display detail FRU header information
* from a FRU binary file.
*
* Restriction: Reference: IPMI Platform Management FRU Information Storage
* Definition V1.0, Section 8
*
* Input: filename: name of FRU binary file
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static int
ipmi_ek_display_fru_header_detail(char *filename)
{
# define FACTOR_OFFSET 8
# define SIZE_MFG_DATE 3
FILE *input_file;
size_t file_offset = 0;
struct fru_header header;
time_t tval;
int ret = 0;
unsigned char data = 0;
unsigned char lan_code = 0;
unsigned char mfg_date[SIZE_MFG_DATE];
unsigned int board_length = 0;
input_file = fopen(filename, "r");
if (input_file == NULL) {
lprintf(LOG_ERR, "File '%s' not found.", filename);
return (-1);
}
/* The offset in each fru is in multiple of 8 bytes
* See IPMI Platform Management FRU Information Storage Definition
* for detail
*/
ret = fread(&header, sizeof(struct fru_header), 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Failed to read FRU header!");
fclose(input_file);
return (-1);
}
/*** Display FRU Internal Use Info ***/
if (header.offset.internal != 0) {
unsigned char format_version;
unsigned long len = 0;
printf("%s\n", EQUAL_LINE_LIMITER);
printf("FRU Internal Use Info\n");
printf("%s\n", EQUAL_LINE_LIMITER);
ret = fread(&format_version, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid format version!");
fclose(input_file);
return (-1);
}
printf("Format Version: %d\n", (format_version & 0x0f));
if (header.offset.chassis > 0) {
len = (header.offset.chassis * FACTOR_OFFSET)
- (header.offset.internal * FACTOR_OFFSET);
} else {
len = (header.offset.board * FACTOR_OFFSET)
- (header.offset.internal * FACTOR_OFFSET);
}
printf("Length: %ld\n", len);
printf("Data dump:\n");
while ((len > 0) && (!feof(input_file))) {
unsigned char data;
ret = fread(&data, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid data!");
fclose(input_file);
return (-1);
}
printf("0x%02x ", data);
len--;
}
printf("\n");
}
/*** Chassis Info Area ***/
if (header.offset.chassis != 0) {
long offset = 0;
offset = header.offset.chassis * FACTOR_OFFSET;
ret = ipmi_ek_display_chassis_info_area(input_file, offset);
}
/*** Display FRU Board Info Area ***/
while (1) {
if (header.offset.board == 0) {
break;
}
ret = fseek(input_file,
(header.offset.board * FACTOR_OFFSET),
SEEK_SET);
if (feof(input_file)) {
break;
}
file_offset = ftell(input_file);
printf("%s\n", EQUAL_LINE_LIMITER);
printf("FRU Board Info Area\n");
printf("%s\n", EQUAL_LINE_LIMITER);
ret = fread(&data, 1, 1, input_file); /* Format version */
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid FRU Format Version!");
fclose(input_file);
return (-1);
}
printf("Format Version: %d\n", (data & 0x0f));
if (feof(input_file)) {
break;
}
ret = fread(&data, 1, 1, input_file); /* Board Area Length */
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Board Area Length!");
fclose(input_file);
return (-1);
}
board_length = (data * FACTOR_OFFSET);
printf("Area Length: %d\n", board_length);
/* Decrease the length of board area by 1 byte of format version
* and 1 byte for area length itself. the rest of this length will
* be used to check for additional custom mfg. byte
*/
board_length -= 2;
if (feof(input_file)) {
break;
}
ret = fread(&lan_code, 1, 1, input_file); /* Language Code */
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Language Code in input");
fclose(input_file);
return (-1);
}
printf("Language Code: %d\n", lan_code);
board_length--;
/* Board Mfg Date */
if (feof(input_file)) {
break;
}
ret = fread(mfg_date, SIZE_MFG_DATE, 1, input_file);
if (ret != 1) {
lprintf(LOG_ERR, "Invalid Board Data.");
fclose(input_file);
return (-1);
}
tval = ((mfg_date[2] << 16) + (mfg_date[1] << 8)
+ (mfg_date[0]));
tval = tval * 60;
tval = tval + secs_from_1970_1996;
printf("Board Mfg Date: %ld, %s", tval,
asctime(localtime(&tval)));
board_length -= SIZE_MFG_DATE;
/* Board Mfg */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Board Manufacture Data", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Board Product */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Board Product Name", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Board Serial */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Board Serial Number", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Board Part */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Board Part Number", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
/* FRU file ID */
file_offset = ipmi_ek_display_board_info_area(
input_file, "FRU File ID", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Additional Custom Mfg. */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Custom", &board_length);
break;
}
/* Product Info Area */
if (header.offset.product && (!feof(input_file))) {
long offset = 0;
offset = header.offset.product * FACTOR_OFFSET;
ret = ipmi_ek_display_product_info_area(input_file,
offset);
}
fclose(input_file);
return 0;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_chassis_info_area
*
* Description: this function displays detail format of product info area record
* into humain readable text format
*
* Restriction: Reference: IPMI Platform Management FRU Information Storage
* Definition V1.0, Section 10
*
* Input: input_file: pointer to file stream
* offset: start offset of chassis info area
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static int
ipmi_ek_display_chassis_info_area(FILE *input_file, long offset)
{
size_t file_offset;
int ret = 0;
unsigned char data = 0;
unsigned char ch_len = 0;
unsigned char ch_type = 0;
unsigned int len;
if (input_file == NULL) {
lprintf(LOG_ERR, "No file stream to read.");
return (-1);
}
printf("%s\n", EQUAL_LINE_LIMITER);
printf("Chassis Info Area\n");
printf("%s\n", EQUAL_LINE_LIMITER);
ret = fseek(input_file, offset, SEEK_SET);
if (feof(input_file)) {
lprintf(LOG_ERR, "Invalid Chassis Info Area!");
return (-1);
}
ret = fread(&data, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Version Number!");
return (-1);
}
printf("Format Version Number: %d\n", (data & 0x0f));
ret = fread(&ch_len, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid length!");
return (-1);
}
/* len is in factor of 8 bytes */
len = ch_len * 8;
printf("Area Length: %d\n", len);
len -= 2;
if (feof(input_file)) {
return (-1);
}
/* Chassis Type*/
ret = fread(&ch_type, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Chassis Type!");
return (-1);
}
printf("Chassis Type: %d\n", ch_type);
len--;
/* Chassis Part Number*/
file_offset = ipmi_ek_display_board_info_area(input_file,
"Chassis Part Number", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Chassis Serial */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Chassis Serial Number", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Custom product info area */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Custom", &len);
return 0;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_board_info_area
*
* Description: this function displays board info area depending on board type
* that pass in argument. Board type can be:
* Manufacturer, Serial, Product or Part...
*
* Restriction: IPMI Platform Management FRU Information Storage
* Definition V1.0, Section 11
*
* Input: input_file: pointer to file stream
* board_type: a string that contain board type
* board_length: length of info area
*
* Output: None
*
* Global: None
*
* Return: the current position of input_file
*
***************************************************************************/
static size_t
ipmi_ek_display_board_info_area(FILE *input_file, char *board_type,
unsigned int *board_length)
{
size_t file_offset;
int ret = 0;
unsigned char len = 0;
unsigned int size_board = 0;
if (input_file == NULL || board_type == NULL
|| board_length == NULL) {
return (size_t)(-1);
}
file_offset = ftell(input_file);
/* Board length*/
ret = fread(&len, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Length!");
goto out;
}
(*board_length)--;
/* Bit 5:0 of Board Mfg type represent legnth */
size_board = (len & 0x3f);
if (size_board == 0) {
printf("%s: None\n", board_type);
goto out;
}
if (strncmp(board_type, "Custom", 6 ) != 0) {
unsigned char *data;
unsigned int i = 0;
data = malloc(size_board);
if (data == NULL) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (size_t)(-1);
}
ret = fread(data, size_board, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid board type size!");
free(data);
data = NULL;
goto out;
}
printf("%s type: 0x%02x\n", board_type, len);
printf("%s: ", board_type);
for (i = 0; i < size_board; i++) {
if ((len & TYPE_CODE) == TYPE_CODE) {
printf("%c", data[i]);
} else {
/* other than language code (binary, BCD,
* ASCII 6 bit...) is not supported
*/
printf("%02x", data[i]);
}
}
printf("\n");
free(data);
data = NULL;
(*board_length) -= size_board;
goto out;
}
while (!feof(input_file)) {
if (len == NO_MORE_INFO_FIELD) {
unsigned char padding;
unsigned char checksum = 0;
/* take the rest of data in the area minus 1 byte of
* checksum
*/
printf("Additional Custom Mfg. length: 0x%02x\n", len);
padding = (*board_length) - 1;
if ((padding > 0) && (!feof(input_file))) {
printf("Unused space: %d (bytes)\n", padding);
fseek(input_file, padding, SEEK_CUR);
}
ret = fread(&checksum, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Checksum!");
goto out;
}
printf("Checksum: 0x%02x\n", checksum);
goto out;
}
printf("Additional Custom Mfg. length: 0x%02x\n", len);
if ((size_board > 0) && (size_board < (*board_length))) {
unsigned char * additional_data = NULL;
unsigned int i = 0;
additional_data = malloc(size_board);
if (additional_data == NULL) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (size_t)(-1);
}
ret = fread(additional_data, size_board, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Additional Data!");
if (additional_data != NULL) {
free(additional_data);
additional_data = NULL;
}
goto out;
}
printf("Additional Custom Mfg. Data: %02x",
additional_data[0]);
for (i = 1; i < size_board; i++) {
printf("-%02x", additional_data[i]);
}
printf("\n");
free(additional_data);
additional_data = NULL;
(*board_length) -= size_board;
}
else {
printf("No Additional Custom Mfg. %d\n", *board_length);
goto out;
}
}
out:
file_offset = ftell(input_file);
return file_offset;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_product_info_area
*
* Description: this function displays detail format of product info area record
* into humain readable text format
*
* Restriction: Reference: IPMI Platform Management FRU Information Storage
* Definition V1.0, Section 12
*
* Input: input_file: pointer to file stream
* offset: start offset of product info area
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static int
ipmi_ek_display_product_info_area(FILE *input_file, long offset)
{
size_t file_offset;
int ret = 0;
unsigned char ch_len = 0;
unsigned char data = 0;
unsigned int len = 0;
if (input_file == NULL) {
lprintf(LOG_ERR, "No file stream to read.");
return (-1);
}
file_offset = ftell(input_file);
printf("%s\n", EQUAL_LINE_LIMITER);
printf("Product Info Area\n");
printf("%s\n", EQUAL_LINE_LIMITER);
ret = fseek(input_file, offset, SEEK_SET);
if (feof(input_file)) {
lprintf(LOG_ERR, "Invalid Product Info Area!");
return (-1);
}
ret = fread(&data, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Data!");
return (-1);
}
printf("Format Version Number: %d\n", (data & 0x0f));
if (feof(input_file)) {
return (-1);
}
/* Have to read this into a char or else
* it ends up byte swapped on big endian machines */
ret = fread(&ch_len, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Length!");
return (-1);
}
/* length is in factor of 8 bytes */
len = ch_len * 8;
printf("Area Length: %d\n", len);
len -= 2; /* -1 byte of format version and -1 byte itself */
ret = fread(&data, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Length!");
return (-1);
}
printf("Language Code: %d\n", data);
len--;
/* Product Mfg */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Product Manufacture Data", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Product Name */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Product Name", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Product Part */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Product Part/Model Number", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Product Version */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Product Version", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Product Serial */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Product Serial Number", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Product Asset Tag */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Asset Tag", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* FRU file ID */
file_offset = ipmi_ek_display_board_info_area(input_file,
"FRU File ID", &len);
ret = fseek(input_file, file_offset, SEEK_SET);
/* Custom product info area */
file_offset = ipmi_ek_display_board_info_area(input_file,
"Custom", &len);
return 0;
}
/**************************************************************************
*
* Function name: ipmi_ek_display_record
*
* Description: this function displays FRU multi record information.
*
* Restriction: None
*
* Input: record: a pointer to current record
* list_head: a pointer to header of the list
* list_last: a pointer to tale of the list
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_record(struct ipmi_ek_multi_header *record,
struct ipmi_ek_multi_header *list_head,
struct ipmi_ek_multi_header *list_last)
{
if (list_head == NULL) {
printf("***empty list***\n");
return;
}
printf("%s\n", EQUAL_LINE_LIMITER);
printf("FRU Multi Info area\n");
printf("%s\n", EQUAL_LINE_LIMITER);
for (record = list_head; record != NULL; record = record->next) {
printf("Record Type ID: 0x%02x\n", record->header.type);
printf("Record Format version: 0x%02x\n",
record->header.format);
if (record->header.len <= PICMG_ID_OFFSET) {
continue;
}
/* In picmg3.0 specification, picmg record
* id lower than 4 or greater than 0x2d
* isn't supported
*/
#define PICMG_ID_LOWER_LIMIT 0x04
#define PICMG_ID_UPPER_LIMIT 0x2d
unsigned char picmg_id;
picmg_id = record->data[PICMG_ID_OFFSET];
printf("Manufacturer ID: %02x%02x%02x h\n",
record->data[2], record->data[1],
record->data[0]);
if ((picmg_id < PICMG_ID_LOWER_LIMIT)
|| (picmg_id > PICMG_ID_UPPER_LIMIT)) {
printf("Picmg record ID: Unsupported {0x%02x}\n", picmg_id);
} else {
printf("Picmg record ID: %s {0x%02x}\n",
val2str(picmg_id, ipmi_ekanalyzer_picmg_record_id),
picmg_id);
}
switch (picmg_id) {
case FRU_PICMG_BACKPLANE_P2P: /*0x04*/
ipmi_ek_display_backplane_p2p_record (record);
break;
case FRU_PICMG_ADDRESS_TABLE: /*0x10*/
ipmi_ek_display_address_table_record (record);
break;
case FRU_PICMG_SHELF_POWER_DIST: /*0x11*/
ipmi_ek_display_shelf_power_distribution_record (record);
break;
case FRU_PICMG_SHELF_ACTIVATION: /*/0x12*/
ipmi_ek_display_shelf_activation_record (record);
break;
case FRU_PICMG_SHMC_IP_CONN: /*0x13*/
ipmi_ek_display_shelf_ip_connection_record (record);
break;
case FRU_PICMG_BOARD_P2P: /*0x14*/
ipmi_ek_display_board_p2p_record (record);
break;
case FRU_RADIAL_IPMB0_LINK_MAPPING: /*0x15*/
ipmi_ek_display_radial_ipmb0_record (record);
break;
case FRU_AMC_CURRENT: /*0x16*/
ipmi_ek_display_amc_current_record (record);
break;
case FRU_AMC_ACTIVATION: /*0x17*/
ipmi_ek_display_amc_activation_record (record);
break;
case FRU_AMC_CARRIER_P2P: /*0x18*/
ipmi_ek_display_carrier_connectivity (record);
break;
case FRU_AMC_P2P: /*0x19*/
ipmi_ek_display_amc_p2p_record (record);
break;
case FRU_AMC_CARRIER_INFO: /*0x1a*/
ipmi_ek_display_amc_carrier_info_record (record);
break;
case FRU_PICMG_CLK_CARRIER_P2P: /*0x2c*/
ipmi_ek_display_clock_carrier_p2p_record (record);
break;
case FRU_PICMG_CLK_CONFIG: /*0x2d*/
ipmi_ek_display_clock_config_record (record);
break;
default:
if (verbose > 0) {
int i;
printf("%02x %02x %02x %02x %02x ",
record->header.type,
record->header.format,
record->header.len,
record->header.record_checksum,
record->header.header_checksum);
for (i = 0; i < record->header.len; i++) {
printf("%02x ", record->data[i]);
}
printf("\n");
}
break;
}
printf("%s\n", STAR_LINE_LIMITER);
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_backplane_p2p_record
*
* Description: this function displays backplane p2p record.
*
* Restriction: Reference: PICMG 3.0 Specification Table 3-40
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_backplane_p2p_record(struct ipmi_ek_multi_header *record)
{
uint8_t index;
int offset = START_DATA_OFFSET;
struct fru_picmgext_slot_desc *slot_d =
(struct fru_picmgext_slot_desc*)&record->data[offset];
offset += sizeof(struct fru_picmgext_slot_desc);
while (offset <= record->header.len) {
printf(" Channel Type: ");
switch (slot_d->chan_type) {
case 0x00:
case 0x07:
printf("PICMG 2.9\n");
break;
case 0x08:
printf("Single Port Fabric IF\n");
break;
case 0x09:
printf("Double Port Fabric IF\n");
break;
case 0x0a:
printf("Full Channel Fabric IF\n");
break;
case 0x0b:
printf("Base IF\n");
break;
case 0x0c:
printf("Update Channel IF\n");
break;
default:
printf("Unknown IF\n");
break;
}
printf(" Slot Address: %02x\n", slot_d->slot_addr);
printf(" Channel Count: %i\n", slot_d->chn_count);
for (index = 0; index < (slot_d->chn_count); index++) {
struct fru_picmgext_chn_desc *d =
(struct fru_picmgext_chn_desc *)&record->data[offset];
if (verbose) {
printf("\t"
"Chn: %02x --> "
"Chn: %02x in "
"Slot: %02x\n",
d->local_chn,
d->remote_chn,
d->remote_slot);
}
offset += sizeof(struct fru_picmgext_chn_desc);
}
slot_d = (struct fru_picmgext_slot_desc*)&record->data[offset];
offset += sizeof(struct fru_picmgext_slot_desc);
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_address_table_record
*
* Description: this function displays address table record.
*
* Restriction: Reference: PICMG 3.0 Specification Table 3-6
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_address_table_record(struct ipmi_ek_multi_header *record)
{
#define SIZE_SHELF_ADDRESS_BYTE 20
unsigned char entries = 0;
unsigned char i;
int offset = START_DATA_OFFSET;
printf(" Type/Len: 0x%02x\n", record->data[offset++]);
printf(" Shelf Addr: ");
for (i = 0; i < SIZE_SHELF_ADDRESS_BYTE; i++) {
printf("0x%02x ", record->data[offset++]);
}
printf("\n");
entries = record->data[offset++];
printf(" Addr Table Entries count: 0x%02x\n", entries);
for (i = 0; i < entries; i++) {
printf("\tHWAddr: 0x%02x - SiteNum: 0x%02x - SiteType: 0x%02x \n",
record->data[offset+0],
record->data[offset+1],
record->data[offset+2]);
offset += 3;
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_shelf_power_distribution_record
*
* Description: this function displays shelf power distribution record.
*
* Restriction: Reference: PICMG 3.0 Specification Table 3-70
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_shelf_power_distribution_record(
struct ipmi_ek_multi_header *record)
{
int offset = START_DATA_OFFSET;
unsigned char i;
unsigned char j;
unsigned char feeds = 0;
feeds = record->data[offset++];
printf(" Number of Power Feeds: 0x%02x\n", feeds);
for (i = 0; i < feeds; i++) {
unsigned char entries;
unsigned long max_ext = 0;
unsigned long max_int = 0;
max_ext = record->data[offset+0]
| (record->data[offset+1] << 8);
printf(" Max External Available Current: %ld Amps\n",
(max_ext * 10));
offset += 2;
max_int = record->data[offset+0]
| (record->data[offset+1] << 8);
printf(" Max Internal Current:\t %ld Amps\n",
(max_int * 10));
offset += 2;
printf(" Min Expected Operating Voltage: %d Volts\n",
(record->data[offset++] / 2));
entries = record->data[offset++];
printf(" Feed to FRU count: 0x%02x\n", entries);
for (j = 0; j < entries; j++) {
printf("\tHW: 0x%02x", record->data[offset++]);
printf("\tFRU ID: 0x%02x\n", record->data[offset++]);
}
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_shelf_activation_record
*
* Description: this function displays shelf activation record.
*
* Restriction: Reference: PICMG 3.0 Specification Table 3-73
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_shelf_activation_record(struct ipmi_ek_multi_header *record)
{
unsigned char count = 0;
int offset = START_DATA_OFFSET;
printf(" Allowance for FRU Act Readiness: 0x%02x\n",
record->data[offset++]);
count = record->data[offset++];
printf(" FRU activation and Power Desc Cnt: 0x%02x\n", count);
while (count > 0) {
printf(" FRU activation and Power descriptor:\n");
printf("\tHardware Address:\t\t0x%02x\n",
record->data[offset++]);
printf("\tFRU Device ID:\t\t\t0x%02x\n",
record->data[offset++]);
printf("\tMax FRU Power Capability:\t0x%04x Watts\n",
(record->data[offset+0]
| (record->data[offset+1]<<8)));
offset += 2;
printf("\tConfiguration parameter:\t0x%02x\n",
record->data[offset++]);
count --;
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_shelf_ip_connection_record
*
* Description: this function displays shelf ip connection record.
*
* Restriction: Fix me: Don't test yet
* Reference: PICMG 3.0 Specification Table 3-31
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_shelf_ip_connection_record(struct ipmi_ek_multi_header *record)
{
int ioffset = START_DATA_OFFSET;
if (ioffset > record->header.len) {
printf(" Shelf Manager IP Address: %d.%d.%d.%d\n",
record->data[ioffset+0],
record->data[ioffset+1],
record->data[ioffset+2],
record->data[ioffset+3]);
ioffset += 4;
}
if (ioffset > record->header.len) {
printf(" Default Gateway Address: %d.%d.%d.%d\n",
record->data[ioffset+0],
record->data[ioffset+1],
record->data[ioffset+2],
record->data[ioffset+3]);
ioffset += 4;
}
if (ioffset > record->header.len) {
printf(" Subnet Mask: %d.%d.%d.%d\n",
record->data[ioffset+0],
record->data[ioffset+1],
record->data[ioffset+2],
record->data[ioffset+3]);
ioffset += 4;
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_shelf_fan_geography_record
*
* Description: this function displays shelf fan geography record.
*
* Restriction: Fix me: Don't test yet
* Reference: PICMG 3.0 Specification Table 3-75
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_shelf_fan_geography_record(struct ipmi_ek_multi_header *record)
{
int ioffset = START_DATA_OFFSET;
unsigned char fan_count = 0;
fan_count = record->data[ioffset];
ioffset++;
printf(" Fan-to-FRU Entry Count: 0x%02x\n", fan_count);
while ((fan_count > 0) && (ioffset <= record->header.len)) {
printf(" Fan-to-FRU Mapping Entry: {%2x%2x%2x%2x}\n",
record->data[ioffset],
record->data[ioffset+1],
record->data[ioffset+2],
record->data[ioffset+3]);
printf(" Hardware Address: 0x%02x\n",
record->data[ioffset++]);
printf(" FRU device ID: 0x%02x\n",
record->data[ioffset++]);
printf(" Site Number: 0x%02x\n",
record->data[ioffset++]);
printf(" Site Type: 0x%02x\n",
record->data[ioffset++]);
fan_count --;
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_board_p2p_record
*
* Description: this function displays board pont-to-point record.
*
* Restriction: Reference: PICMG 3.0 Specification Table 3-44
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_board_p2p_record(struct ipmi_ek_multi_header *record)
{
unsigned char guid_count;
int offset = START_DATA_OFFSET;
int i = 0;
guid_count = record->data[offset++];
printf(" GUID count: %2d\n", guid_count);
for (i = 0 ; i < guid_count; i++) {
int j;
printf("\tGUID: ");
for (j = 0; j < sizeof(struct fru_picmgext_guid); j++) {
printf("%02x", record->data[offset+j]);
}
printf("\n");
offset += sizeof(struct fru_picmgext_guid);
}
for (offset = offset;
offset < record->header.len;
offset += sizeof(struct fru_picmgext_link_desc)) {
/* to solve little endian/big endian problem */
unsigned long data;
struct fru_picmgext_link_desc * d;
data = (record->data[offset+0])
| (record->data[offset+1] << 8)\
| (record->data[offset+2] << 16)\
| (record->data[offset+3] << 24);
d = (struct fru_picmgext_link_desc *)&data;
printf(" Link Descriptor\n");
printf("\tLink Grouping ID:\t0x%02x\n", d->grouping);
printf("\tLink Type Extension:\t0x%02x - ", d->ext);
if (d->type == FRU_PICMGEXT_LINK_TYPE_BASE) {
switch (d->ext) {
case 0:
printf("10/100/1000BASE-T Link (four-pair)\n");
break;
case 1:
printf("ShMC Cross-connect (two-pair)\n");
break;
default:
printf("Unknown\n");
break;
}
} else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET) {
switch (d->ext) {
case 0:
printf("Fixed 1000Base-BX\n");
break;
case 1:
printf("Fixed 10GBASE-BX4 [XAUI]\n");
break;
case 2:
printf("FC-PI\n");
break;
default:
printf("Unknown\n");
break;
}
} else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND) {
printf("Unknown\n");
} else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR) {
printf("Unknown\n");
} else if (d->type == FRU_PICMGEXT_LINK_TYPE_PCIE) {
printf("Unknown\n");
} else {
printf("Unknown\n");
}
printf("\tLink Type:\t\t0x%02x - ", d->type);
if (d->type == 0 || d->type == 0xff) {
printf("Reserved\n");
} else if (d->type >= 0x06 && d->type <= 0xef) {
printf("Reserved\n");
} else if (d->type >= LOWER_OEM_TYPE && d->type <= UPPER_OEM_TYPE) {
printf("OEM GUID Definition\n");
} else {
switch (d->type){
case FRU_PICMGEXT_LINK_TYPE_BASE:
printf("PICMG 3.0 Base Interface 10/100/1000\n");
break;
case FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET:
printf("PICMG 3.1 Ethernet Fabric Interface\n");
break;
case FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND:
printf("PICMG 3.2 Infiniband Fabric Interface\n");
break;
case FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR:
printf("PICMG 3.3 Star Fabric Interface\n");
break;
case FRU_PICMGEXT_LINK_TYPE_PCIE:
printf("PICMG 3.4 PCI Express Fabric Interface\n");
break;
default:
printf("Invalid\n");
break;
}
}
printf("\tLink Designator: \n");
printf("\t Port 0 Flag: %s\n",
(d->desig_port & 0x01) ? "enable" : "disable");
printf("\t Port 1 Flag: %s\n",
(d->desig_port & 0x02) ? "enable" : "disable");
printf("\t Port 2 Flag: %s\n",
(d->desig_port & 0x04) ? "enable" : "disable");
printf("\t Port 3 Flag: %s\n",
(d->desig_port & 0x08) ? "enable" : "disable");
printf("\t Interface: 0x%02x - ", d->desig_if);
switch (d->desig_if) {
case FRU_PICMGEXT_DESIGN_IF_BASE:
printf("Base Interface\n");
break;
case FRU_PICMGEXT_DESIGN_IF_FABRIC:
printf("Fabric Interface\n");
break;
case FRU_PICMGEXT_DESIGN_IF_UPDATE_CHANNEL:
printf("Update Channel\n");
break;
case FRU_PICMGEXT_DESIGN_IF_RESERVED:
printf("Reserved\n");
break;
default:
printf("Invalid");
break;
}
printf("\t Channel Number: 0x%02x\n",
d->desig_channel);
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_radial_ipmb0_record
*
* Description: this function displays radial IPMB-0 record.
*
* Restriction: Fix me: Don't test yet
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_radial_ipmb0_record(struct ipmi_ek_multi_header *record)
{
#define SIZE_OF_CONNECTOR_DEFINER 3; /*bytes*/
int offset = START_DATA_OFFSET;
/* Ref: PICMG 3.0 Specification Revision 2.0, Table 3-59 */
printf(" IPMB-0 Connector Definer: ");
#ifndef WORDS_BIGENDIAN
printf("%02x %02x %02x h\n", record->data[offset],
record->data[offset+1], record->data[offset+2]);
#else
printf("%02x %02x %02x h\n", record->data[offset+2],
record->data[offset+1], record->data[offset]);
#endif
/* 3 bytes of connector definer was used */
offset += SIZE_OF_CONNECTOR_DEFINER;
printf(" IPMB-0 Connector version ID: ");
#ifndef WORDS_BIGENDIAN
printf("%02x %02x h\n", record->data[offset],
record->data[offset+1]);
#else
printf("%02x %02x h\n", record->data[offset+1],
record->data[offset]);
#endif
offset += 2;
printf(" IPMB-0 Hub Descriptor Count: 0x%02x",
record->data[offset++]);
if (record->data[offset] < 1) {
return;
}
for (offset = offset; offset < record->header.len;) {
unsigned char entry_count = 0;
printf(" IPMB-0 Hub Descriptor\n");
printf("\tHardware Address: 0x%02x\n",
record->data[offset++]);
printf("\tHub Info {0x%02x}: ", record->data[offset]);
/* Bit mask specified in Table 3-59
* of PICMG 3.0 Specification
*/
if ((record->data[offset] & 0x01) == 0x01) {
printf("IPMB-A only\n");
} else if ((record->data[offset] & 0x02) == 0x02) {
printf("IPMB-B only\n");
} else if ((record->data[offset] & 0x03) == 0x03) {
printf("IPMB-A and IPMB-B\n");
} else {
printf("Reserved.\n");
}
offset ++;
entry_count = record->data[offset++];
printf("\tAddress Entry count: 0x%02x", entry_count);
while (entry_count > 0) {
printf("\t Hardware Address: 0x%02x\n",
record->data[offset++]);
printf("\t IPMB-0 Link Entry: 0x%02x\n",
record->data[offset++]);
entry_count --;
}
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_amc_current_record
*
* Description: this function displays AMC current record.
*
* Restriction: None
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_amc_current_record(struct ipmi_ek_multi_header *record)
{
unsigned char current;
current = record->data[START_DATA_OFFSET];
printf(" Current draw: %.1f A @ 12V => %.2f Watt\n",
(float)current / 10.0,
((float)current / 10.0) * 12.0);
printf("\n");
}
/**************************************************************************
*
* Function name: ipmi_ek_display_amc_activation_record
*
* Description: this function displays carrier activation and current management
* record.
*
* Restriction: Reference: AMC.0 Specification Table 3-11 and Table 3-12
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_amc_activation_record(struct ipmi_ek_multi_header *record)
{
uint16_t max_current;
int offset = START_DATA_OFFSET;
max_current = record->data[offset];
max_current |= record->data[++offset] << 8;
printf(" Maximum Internal Current(@12V): %.2f A [ %.2f Watt ]\n",
(float) max_current / 10,
(float) max_current / 10 * 12);
printf(" Module Activation Readiness: %i sec.\n",
record->data[++offset]);
printf(" Descriptor Count: %i\n", record->data[++offset]);
for (++offset; (offset < record->header.len); offset += 3) {
struct fru_picmgext_activation_record *a =
(struct fru_picmgext_activation_record *)&record->data[offset];
printf("\tIPMB-Address:\t\t0x%x\n", a->ibmb_addr);
printf("\tMax. Module Current:\t%.2f A\n",
(float)a->max_module_curr / 10);
printf("\n");
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_amc_p2p_record
*
* Description: this function display amc p2p connectivity record in humain
* readable text format
*
* Restriction: Reference: AMC.0 Specification Table 3-16
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_amc_p2p_record(struct ipmi_ek_multi_header *record)
{
int index_data = START_DATA_OFFSET;
int oem_count = 0;
int ch_count = 0;
int index=0;
oem_count = record->data[index_data++];
printf("OEM GUID count: %02x\n", oem_count);
if (oem_count > 0) {
while (oem_count > 0) {
printf("OEM GUID: ");
for (index = 1; index <= SIZE_OF_GUID; index++) {
printf("%02x", record->data[index_data++]);
/* For a better look, display a "-" character
* after each 5 bytes of OEM GUID
*/
if (!(index % 5)) {
printf("-");
}
}
printf("\n");
oem_count--;
}
}
if ((record->data[index_data] & AMC_MODULE) == AMC_MODULE) {
printf("AMC module connection\n");
} else {
printf("On-Carrier Device %02x h\n",
(record->data[index_data] & 0x0f));
}
index_data ++;
ch_count = record->data[index_data++];
printf("AMC Channel Descriptor count: %02x h\n", ch_count);
if (ch_count > 0) {
for (index = 0; index < ch_count; index++) {
unsigned int data;
struct fru_picmgext_amc_channel_desc_record *ch_desc;
printf(" AMC Channel Descriptor {%02x%02x%02x}\n",
record->data[index_data+2],
record->data[index_data+1],
record->data[index_data]);
data = record->data[index_data]
| (record->data[index_data + 1] << 8)
| (record->data[index_data + 2] << 16);
ch_desc = (struct fru_picmgext_amc_channel_desc_record *)&data;
printf(" Lane 0 Port: %d\n", ch_desc->lane0port);
printf(" Lane 1 Port: %d\n", ch_desc->lane1port);
printf(" Lane 2 Port: %d\n", ch_desc->lane2port);
printf(" Lane 3 Port: %d\n\n", ch_desc->lane3port);
index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
}
}
while (index_data < record->header.len) {
/* Warning: This code doesn't work with gcc version
* between 4.0 and 4.3
*/
unsigned int data[2];
struct fru_picmgext_amc_link_desc_record *link_desc;
data[0] = record->data[index_data]
| (record->data[index_data + 1] << 8)
| (record->data[index_data + 2] << 16)
| (record->data[index_data + 3] << 24);
data[1] = record->data[index_data + 4];
link_desc = (struct fru_picmgext_amc_link_desc_record *)&data[0];
printf(" AMC Link Descriptor:\n");
printf("\t- Link Type: %s \n",
val2str(link_desc->type, ipmi_ekanalyzer_link_type));
switch (link_desc->type) {
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE:
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1:
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2:
printf("\t- Link Type extension: %s\n",
val2str(link_desc->type_ext,
ipmi_ekanalyzer_extension_PCIE));
printf("\t- Link Group ID: %d\n ",
link_desc->group_id);
printf("\t- Link Asym. Match: %d - %s\n",
link_desc->asym_match,
val2str(link_desc->asym_match,
ipmi_ekanalyzer_asym_PCIE));
break;
case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET:
printf("\t- Link Type extension: %s\n",
val2str (link_desc->type_ext,
ipmi_ekanalyzer_extension_ETHERNET));
printf("\t- Link Group ID: %d \n",
link_desc->group_id);
printf("\t- Link Asym. Match: %d - %s\n",
link_desc->asym_match,
val2str(link_desc->asym_match,
ipmi_ekanalyzer_asym_PCIE));
break;
case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE:
printf("\t- Link Type extension: %s\n",
val2str (link_desc->type_ext,
ipmi_ekanalyzer_extension_STORAGE));
printf("\t- Link Group ID: %d \n",
link_desc->group_id);
printf("\t- Link Asym. Match: %d - %s\n",
link_desc->asym_match,
val2str(link_desc->asym_match,
ipmi_ekanalyzer_asym_STORAGE));
break;
default:
printf("\t- Link Type extension: %i (Unknown)\n",
link_desc->type_ext);
printf("\t- Link Group ID: %d \n",
link_desc->group_id);
printf("\t- Link Asym. Match: %i\n",
link_desc->asym_match);
break;
}
printf("\t- AMC Link Designator:\n");
printf("\t Channel ID: %i\n", link_desc->channel_id);
printf("\t\t Lane 0: %s\n",
(link_desc->port_flag_0) ? "enable" : "disable");
printf("\t\t Lane 1: %s\n",
(link_desc->port_flag_1) ? "enable" : "disable");
printf("\t\t Lane 2: %s\n",
(link_desc->port_flag_2) ? "enable" : "disable");
printf("\t\t Lane 3: %s\n",
(link_desc->port_flag_3) ? "enable" : "disable");
index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE;
}
}
/**************************************************************************
*
* Function name: ipmi_ek_display_amc_carrier_info_record
*
* Description: this function displays Carrier information table.
*
* Restriction: Reference: AMC.0 Specification Table 3-3
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: START_DATA_OFFSET
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_amc_carrier_info_record(struct ipmi_ek_multi_header *record)
{
unsigned char extVersion;
unsigned char siteCount;
int offset = START_DATA_OFFSET;
extVersion = record->data[offset++];
siteCount = record->data[offset++];
printf(" AMC.0 extension version: R%d.%d\n",
(extVersion >> 0) & 0x0F,
(extVersion >> 4) & 0x0F);
printf(" Carrier Sie Number Count: %d\n", siteCount);
while (siteCount > 0) {
printf("\tSite ID (%d): %s \n", record->data[offset],
val2str(record->data[offset], ipmi_ekanalyzer_module_type));
offset++;
siteCount--;
}
printf("\n");
}
/**************************************************************************
*
* Function name: ipmi_ek_display_clock_carrier_p2p_record
*
* Description: this function displays Carrier clock point-to-pont
* connectivity record.
*
* Restriction: the following code is copy from ipmi_fru.c with modification in
* reference to AMC.0 Specification Table 3-29
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_display_clock_carrier_p2p_record(struct ipmi_ek_multi_header *record)
{
unsigned char desc_count;
int i;
int j;
int offset = START_DATA_OFFSET;
desc_count = record->data[offset++];
for(i = 0; i < desc_count; i++) {
unsigned char resource_id;
unsigned char channel_count;
resource_id = record->data[offset++];
channel_count = record->data[offset++];
printf(" Clock Resource ID: 0x%02x\n", resource_id);
printf(" Type: ");
if ((resource_id & 0xC0) >> 6 == 0) {
printf("On-Carrier-Device\n");
} else if ((resource_id & 0xC0) >> 6 == 1) {
printf("AMC slot\n");
} else if ((resource_id & 0xC0) >> 6 == 2) {
printf("Backplane\n");
} else{
printf("reserved\n");
}
printf(" Channel Count: 0x%02x\n", channel_count);
for (j = 0; j < channel_count; j++) {
unsigned char loc_channel;
unsigned char rem_channel;
unsigned char rem_resource;
loc_channel = record->data[offset++];
rem_channel = record->data[offset++];
rem_resource = record->data[offset++];
printf("\tCLK-ID: 0x%02x ---> ", loc_channel);
printf(" remote CLKID: 0x%02x ", rem_channel);
if ((rem_resource & 0xC0) >> 6 == 0) {
printf("[ Carrier-Dev");
} else if ((rem_resource & 0xC0) >> 6 == 1) {
printf("[ AMC slot ");
} else if ((rem_resource & 0xC0) >> 6 == 2) {
printf("[ Backplane ");
} else {
printf("reserved ");
}
printf(" 0x%02x ]\n", rem_resource & 0xF);
}
}
printf("\n");
}
/**************************************************************************
*
* Function name: ipmi_ek_display_clock_config_record
*
* Description: this function displays clock configuration record.
*
* Restriction: the following codes are copy from ipmi_fru.c with modification
* in reference to AMC.0 Specification Table 3-35 and Table 3-36
*
* Input: record: a pointer to current record to be displayed
*
* Output: None
*
* Global: START_DATA_OFFSET
*
* Return: None
*
***************************************************************************/
void
ipmi_ek_display_clock_config_record(struct ipmi_ek_multi_header *record)
{
unsigned char resource_id;
unsigned char descr_count;
int i;
int offset = START_DATA_OFFSET;
resource_id = record->data[offset++];
descr_count = record->data[offset++];
printf(" Clock Resource ID: 0x%02x\n", resource_id);
printf(" Clock Configuration Descriptor Count: 0x%02x\n", descr_count);
for (i = 0; i < descr_count; i++) {
int j = 0;
unsigned char channel_id;
unsigned char control;
unsigned char indirect_cnt;
unsigned char direct_cnt;
channel_id = record->data[offset++];
control = record->data[offset++];
printf("\tCLK-ID: 0x%02x - ", channel_id);
printf("CTRL 0x%02x [ %12s ]\n", control,
((control & 0x1) == 0) ? "Carrier IPMC" : "Application");
indirect_cnt = record->data[offset++];
direct_cnt = record->data[offset++];
printf("\t Count: Indirect 0x%02x / Direct 0x%02x\n",
indirect_cnt,
direct_cnt);
/* indirect desc */
for (j = 0; j < indirect_cnt; j++) {
unsigned char feature;
unsigned char dep_chn_id;
feature = record->data[offset++];
dep_chn_id = record->data[offset++];
printf("\t\tFeature: 0x%02x [%8s] - ",
feature,
(feature & 0x1) == 1 ? "Source" : "Receiver");
printf(" Dep. CLK-ID: 0x%02x\n", dep_chn_id);
}
/* direct desc */
for (j = 0; j < direct_cnt; j++) {
unsigned char feature;
unsigned char family;
unsigned char accuracy;
unsigned long freq;
unsigned long min_freq;
unsigned long max_freq;
feature = record->data[offset++];
family = record->data[offset++];
accuracy = record->data[offset++];
freq = (record->data[offset+0] << 0)
| (record->data[offset+1] << 8)
| (record->data[offset+2] << 16)
| (record->data[offset+3] << 24);
offset += 4;
min_freq = (record->data[offset+0] << 0)
| (record->data[offset+1] << 8)
| (record->data[offset+2] << 16)
| (record->data[offset+3] << 24);
offset += 4;
max_freq = (record->data[offset+0] << 0)
| (record->data[offset+1] << 8)
| (record->data[offset+2] << 16)
| (record->data[offset+3] << 24);
offset += 4;
printf("\t- Feature: 0x%02x - PLL: %x / Asym: %s\n",
feature,
(feature > 1) & 1,
(feature & 1) ? "Source" : "Receiver");
printf("\tFamily: 0x%02x - AccLVL: 0x%02x\n",
family, accuracy);
printf("\tFRQ: %-9ld - min: %-9ld - max: %-9ld\n",
freq, min_freq, max_freq);
}
printf("\n");
}
}
/**************************************************************************
*
* Function name: ipmi_ekanalyzer_fru_file2structure
*
* Description: this function convert a FRU binary file into a linked list of
* FRU multi record
*
* Restriction: None
*
* Input/Ouput: filename1: name of the file that contain FRU binary data
* record: a pointer to current record
* list_head: a pointer to header of the list
* list_last: a pointer to tale of the list
*
* Global: None
*
* Return: return -1 as Error status, and 0 as Ok status
*
***************************************************************************/
static int
ipmi_ekanalyzer_fru_file2structure(char *filename,
struct ipmi_ek_multi_header **list_head,
struct ipmi_ek_multi_header **list_record,
struct ipmi_ek_multi_header **list_last)
{
FILE *input_file;
unsigned char data;
unsigned char last_record = 0;
unsigned int multi_offset = 0;
int record_count = 0;
int ret = 0;
input_file = fopen(filename, "r");
if (input_file == NULL) {
lprintf(LOG_ERR, "File: '%s' is not found", filename);
return ERROR_STATUS;
}
fseek(input_file, START_DATA_OFFSET, SEEK_SET);
data = 0;
ret = fread(&data, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Offset!");
fclose(input_file);
return ERROR_STATUS;
}
if (data == 0) {
lprintf(LOG_ERR, "There is no multi record in the file '%s'",
filename);
fclose(input_file);
return ERROR_STATUS;
}
/* the offset value is in multiple of 8 bytes. */
multi_offset = data * 8;
lprintf(LOG_DEBUG, "start multi offset = 0x%02x",
multi_offset);
fseek(input_file, multi_offset, SEEK_SET);
while (!feof(input_file)) {
*list_record = malloc(sizeof(struct ipmi_ek_multi_header));
if (*list_record == NULL) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return ERROR_STATUS;
}
ret = fread(&(*list_record)->header, START_DATA_OFFSET, 1,
input_file);
if ((ret != 1) || ferror(input_file)) {
free(*list_record);
*list_record = NULL;
fclose(input_file);
lprintf(LOG_ERR, "Invalid Header!");
return ERROR_STATUS;
}
if ((*list_record)->header.len == 0) {
record_count++;
continue;
}
(*list_record)->data = malloc((*list_record)->header.len);
if ((*list_record)->data == NULL) {
lprintf(LOG_ERR, "Failed to allocation memory size %d\n",
(*list_record)->header.len);
record_count++;
continue;
}
ret = fread((*list_record)->data, ((*list_record)->header.len),
1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Record Data!");
fclose(input_file);
return ERROR_STATUS;
}
if (verbose > 0)
printf("Record %d has length = %02x\n", record_count,
(*list_record)->header.len);
if (verbose > 1) {
int i;
printf("Type: %02x", (*list_record)->header.type);
for (i = 0; i < ((*list_record)->header.len); i++) {
if (!(i % 8)) {
printf("\n0x%02x: ", i);
}
printf("%02x ",
(*list_record)->data[i]);
}
printf("\n\n");
}
ipmi_ek_add_record2list(list_record, list_head, list_last);
/* mask the 8th bits to see if it is the last record */
last_record = ((*list_record)->header.format) & 0x80;
if (last_record) {
break;
}
record_count++;
}
fclose(input_file);
return OK_STATUS;
}
/**************************************************************************
*
* Function name: ipmi_ek_add_record2list
*
* Description: this function adds a sigle FRU multi record to a linked list of
* FRU multi record.
*
* Restriction: None
*
* Input/Output: record: a pointer to current record
* list_head: a pointer to header of the list
* list_last: a pointer to tale of the list
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_add_record2list(struct ipmi_ek_multi_header **record,
struct ipmi_ek_multi_header **list_head,
struct ipmi_ek_multi_header **list_last)
{
if (*list_head == NULL) {
*list_head = *record;
(*record)->prev = NULL;
if (verbose > 2) {
printf("Adding first record to list\n");
}
} else {
(*list_last)->next = *record;
(*record)->prev = *list_last;
if (verbose > 2) {
printf("Add 1 record to list\n");
}
}
*list_last = *record;
(*record)->next = NULL;
}
/**************************************************************************
*
* Function name: ipmi_ek_remove_record_from_list
*
* Description: this function removes a sigle FRU multi record from a linked
* list of FRU multi record.
*
* Restriction: None
*
* Input/Output: record: a pointer to record to be deleted
* list_head: a pointer to header of the list
* list_last: a pointer to tale of the list
*
* Global: None
*
* Return: None
*
***************************************************************************/
static void
ipmi_ek_remove_record_from_list(struct ipmi_ek_multi_header *record,
struct ipmi_ek_multi_header **list_head,
struct ipmi_ek_multi_header **list_last)
{
if (record->prev == NULL) {
*list_head = record->next;
} else {
record->prev->next = record->next;
}
if (record->next == NULL) {
(*list_last) = record->prev;
} else {
record->next->prev = record->prev;
}
free(record);
record = NULL;
}
|