1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730
|
/*
* ethtool.c: Linux ethernet device configuration tool.
*
* Copyright (C) 1998 David S. Miller (davem@dm.cobaltmicro.com)
* Portions Copyright 2001 Sun Microsystems
* Kernel 2.4 update Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
* Wake-on-LAN,natsemi,misc support by Tim Hockin <thockin@sun.com>
* Portions Copyright 2002 Intel
* Portions Copyright (C) Sun Microsystems 2008
* do_test support by Eli Kupermann <eli.kupermann@intel.com>
* ETHTOOL_PHYS_ID support by Chris Leech <christopher.leech@intel.com>
* e1000 support by Scott Feldman <scott.feldman@intel.com>
* e100 support by Wen Tao <wen-hwa.tao@intel.com>
* ixgb support by Nicholas Nunley <Nicholas.d.nunley@intel.com>
* amd8111e support by Reeja John <reeja.john@amd.com>
* long arguments by Andi Kleen.
* SMSC LAN911x support by Steve Glendinning <steve.glendinning@smsc.com>
* Rx Network Flow Control configuration support <santwona.behera@sun.com>
* Various features by Ben Hutchings <bhutchings@solarflare.com>;
* Copyright 2009, 2010 Solarflare Communications
* MDI-X set support by Jesse Brandeburg <jesse.brandeburg@intel.com>
* Copyright 2012 Intel Corporation
* vmxnet3 support by Shrikrishna Khare <skhare@vmware.com>
* Various features by Ben Hutchings <ben@decadent.org.uk>;
* Copyright 2008-2010, 2013-2016 Ben Hutchings
* QSFP+/QSFP28 DOM support by Vidya Sagar Ravipati <vidya@cumulusnetworks.com>
*
* TODO:
* * show settings for all devices
*/
#include "internal.h"
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <errno.h>
#include <sys/utsname.h>
#include <limits.h>
#include <ctype.h>
#include <inttypes.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/ioctl.h>
#include <linux/sockios.h>
#include <linux/netlink.h>
#include "common.h"
#include "netlink/extapi.h"
#ifndef MAX_ADDR_LEN
#define MAX_ADDR_LEN 32
#endif
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
static void exit_bad_args(void) __attribute__((noreturn));
static void exit_bad_args(void)
{
fprintf(stderr,
"ethtool: bad command line argument(s)\n"
"For more information run ethtool -h\n");
exit(1);
}
static void exit_bad_args_info(const char *info) __attribute__((noreturn));
static void exit_bad_args_info(const char *info)
{
fprintf(stderr,
"ethtool: bad command line argument(s)\n"
"%s\n"
"For more information run ethtool -h\n",
info);
exit(1);
}
static void exit_nlonly_param(const char *name) __attribute__((noreturn));
static void exit_nlonly_param(const char *name)
{
fprintf(stderr,
"ethtool: parameter '%s' can be used only with netlink\n",
name);
exit(1);
}
typedef enum {
CMDL_NONE,
CMDL_BOOL,
CMDL_S32,
CMDL_U8,
CMDL_U16,
CMDL_U32,
CMDL_U64,
CMDL_BE16,
CMDL_IP4,
CMDL_STR,
CMDL_FLAG,
CMDL_MAC,
} cmdline_type_t;
struct cmdline_info {
const char *name;
cmdline_type_t type;
/* Points to int (BOOL), s32, u16, u32 (U32/FLAG/IP4), u64,
* char * (STR) or u8[6] (MAC). For FLAG, the value accumulates
* all flags to be set. */
void *wanted_val;
void *ioctl_val;
/* For FLAG, the flag value to be set/cleared */
u32 flag_val;
/* For FLAG, points to u32 and accumulates all flags seen.
* For anything else, points to int and is set if the option is
* seen. */
void *seen_val;
};
struct feature_def {
char name[ETH_GSTRING_LEN];
int off_flag_index; /* index in off_flag_def; negative if none match */
};
struct feature_defs {
size_t n_features;
/* Number of features each offload flag is associated with */
unsigned int off_flag_matched[OFF_FLAG_DEF_SIZE];
/* Name and offload flag index for each feature */
struct feature_def def[0];
};
#define FEATURE_BITS_TO_BLOCKS(n_bits) DIV_ROUND_UP(n_bits, 32U)
#define FEATURE_WORD(blocks, index, field) ((blocks)[(index) / 32U].field)
#define FEATURE_FIELD_FLAG(index) (1U << (index) % 32U)
#define FEATURE_BIT_SET(blocks, index, field) \
(FEATURE_WORD(blocks, index, field) |= FEATURE_FIELD_FLAG(index))
#define FEATURE_BIT_CLEAR(blocks, index, field) \
(FEATURE_WORD(blocks, index, filed) &= ~FEATURE_FIELD_FLAG(index))
#define FEATURE_BIT_IS_SET(blocks, index, field) \
(FEATURE_WORD(blocks, index, field) & FEATURE_FIELD_FLAG(index))
static long long
get_int_range(char *str, int base, long long min, long long max)
{
long long v;
char *endp;
if (!str)
exit_bad_args();
errno = 0;
v = strtoll(str, &endp, base);
if (errno || *endp || v < min || v > max)
exit_bad_args();
return v;
}
static unsigned long long
get_uint_range(char *str, int base, unsigned long long max)
{
unsigned long long v;
char *endp;
if (!str)
exit_bad_args();
errno = 0;
v = strtoull(str, &endp, base);
if (errno || *endp || v > max)
exit_bad_args();
return v;
}
static int get_int(char *str, int base)
{
return get_int_range(str, base, INT_MIN, INT_MAX);
}
static u32 get_u32(char *str, int base)
{
return get_uint_range(str, base, 0xffffffff);
}
static void get_mac_addr(char *src, unsigned char *dest)
{
int count;
int i;
int buf[ETH_ALEN];
count = sscanf(src, "%2x:%2x:%2x:%2x:%2x:%2x",
&buf[0], &buf[1], &buf[2], &buf[3], &buf[4], &buf[5]);
if (count != ETH_ALEN)
exit_bad_args();
for (i = 0; i < count; i++)
dest[i] = buf[i];
}
static int parse_hex_u32_bitmap(const char *s,
unsigned int nbits, u32 *result)
{
const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32);
size_t slen = strlen(s);
size_t i;
/* ignore optional '0x' prefix */
if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) {
slen -= 2;
s += 2;
}
if (slen > 8 * nwords) /* up to 2 digits per byte */
return -1;
memset(result, 0, 4 * nwords);
for (i = 0; i < slen; ++i) {
const unsigned int shift = (slen - 1 - i) * 4;
u32 *dest = &result[shift / 32];
u32 nibble;
if ('a' <= s[i] && s[i] <= 'f')
nibble = 0xa + (s[i] - 'a');
else if ('A' <= s[i] && s[i] <= 'F')
nibble = 0xa + (s[i] - 'A');
else if ('0' <= s[i] && s[i] <= '9')
nibble = (s[i] - '0');
else
return -1;
*dest |= (nibble << (shift % 32));
}
return 0;
}
static void parse_generic_cmdline(struct cmd_context *ctx,
int *changed,
struct cmdline_info *info,
unsigned int n_info)
{
unsigned int argc = ctx->argc;
char **argp = ctx->argp;
unsigned int i, idx;
int found;
for (i = 0; i < argc; i++) {
found = 0;
for (idx = 0; idx < n_info; idx++) {
if (!strcmp(info[idx].name, argp[i])) {
found = 1;
*changed = 1;
if (info[idx].type != CMDL_FLAG &&
info[idx].seen_val)
*(int *)info[idx].seen_val = 1;
i += 1;
if (i >= argc)
exit_bad_args();
switch (info[idx].type) {
case CMDL_BOOL: {
int *p = info[idx].wanted_val;
if (!strcmp(argp[i], "on"))
*p = 1;
else if (!strcmp(argp[i], "off"))
*p = 0;
else
exit_bad_args();
break;
}
case CMDL_S32: {
s32 *p = info[idx].wanted_val;
*p = get_int_range(argp[i], 0,
-0x80000000LL,
0x7fffffff);
break;
}
case CMDL_U8: {
u8 *p = info[idx].wanted_val;
*p = get_uint_range(argp[i], 0, 0xff);
break;
}
case CMDL_U16: {
u16 *p = info[idx].wanted_val;
*p = get_uint_range(argp[i], 0, 0xffff);
break;
}
case CMDL_U32: {
u32 *p = info[idx].wanted_val;
*p = get_uint_range(argp[i], 0,
0xffffffff);
break;
}
case CMDL_U64: {
u64 *p = info[idx].wanted_val;
*p = get_uint_range(
argp[i], 0,
0xffffffffffffffffLL);
break;
}
case CMDL_BE16: {
u16 *p = info[idx].wanted_val;
*p = cpu_to_be16(
get_uint_range(argp[i], 0,
0xffff));
break;
}
case CMDL_IP4: {
u32 *p = info[idx].wanted_val;
struct in_addr in;
if (!inet_pton(AF_INET, argp[i], &in))
exit_bad_args();
*p = in.s_addr;
break;
}
case CMDL_MAC:
get_mac_addr(argp[i],
info[idx].wanted_val);
break;
case CMDL_FLAG: {
u32 *p;
p = info[idx].seen_val;
*p |= info[idx].flag_val;
if (!strcmp(argp[i], "on")) {
p = info[idx].wanted_val;
*p |= info[idx].flag_val;
} else if (strcmp(argp[i], "off")) {
exit_bad_args();
}
break;
}
case CMDL_STR: {
char **s = info[idx].wanted_val;
*s = strdup(argp[i]);
break;
}
default:
exit_bad_args();
}
break;
}
}
if (!found)
exit_bad_args();
}
}
static void flag_to_cmdline_info(const char *name, u32 value,
u32 *wanted, u32 *mask,
struct cmdline_info *cli)
{
memset(cli, 0, sizeof(*cli));
cli->name = name;
cli->type = CMDL_FLAG;
cli->flag_val = value;
cli->wanted_val = wanted;
cli->seen_val = mask;
}
static int rxflow_str_to_type(const char *str)
{
int flow_type = 0;
if (!strcmp(str, "tcp4"))
flow_type = TCP_V4_FLOW;
else if (!strcmp(str, "udp4"))
flow_type = UDP_V4_FLOW;
else if (!strcmp(str, "ah4") || !strcmp(str, "esp4"))
flow_type = AH_ESP_V4_FLOW;
else if (!strcmp(str, "sctp4"))
flow_type = SCTP_V4_FLOW;
else if (!strcmp(str, "gtpc4"))
flow_type = GTPC_V4_FLOW;
else if (!strcmp(str, "gtpc4t"))
flow_type = GTPC_TEID_V4_FLOW;
else if (!strcmp(str, "gtpu4"))
flow_type = GTPU_V4_FLOW;
else if (!strcmp(str, "gtpu4e"))
flow_type = GTPU_EH_V4_FLOW;
else if (!strcmp(str, "gtpu4u"))
flow_type = GTPU_UL_V4_FLOW;
else if (!strcmp(str, "gtpu4d"))
flow_type = GTPU_DL_V4_FLOW;
else if (!strcmp(str, "tcp6"))
flow_type = TCP_V6_FLOW;
else if (!strcmp(str, "udp6"))
flow_type = UDP_V6_FLOW;
else if (!strcmp(str, "ah6") || !strcmp(str, "esp6"))
flow_type = AH_ESP_V6_FLOW;
else if (!strcmp(str, "sctp6"))
flow_type = SCTP_V6_FLOW;
else if (!strcmp(str, "ether"))
flow_type = ETHER_FLOW;
else if (!strcmp(str, "gtpc6"))
flow_type = GTPC_V6_FLOW;
else if (!strcmp(str, "gtpc6t"))
flow_type = GTPC_TEID_V6_FLOW;
else if (!strcmp(str, "gtpu6"))
flow_type = GTPU_V6_FLOW;
else if (!strcmp(str, "gtpu6e"))
flow_type = GTPU_EH_V6_FLOW;
else if (!strcmp(str, "gtpu6u"))
flow_type = GTPU_UL_V6_FLOW;
else if (!strcmp(str, "gtpu6d"))
flow_type = GTPU_DL_V6_FLOW;
return flow_type;
}
static int do_version(struct cmd_context *ctx __maybe_unused)
{
fprintf(stdout,
PACKAGE " version " VERSION
#ifndef ETHTOOL_ENABLE_PRETTY_DUMP
" (pretty dumps disabled)"
#endif
"\n");
return 0;
}
/* link mode routines */
static ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes);
static ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags);
static void init_global_link_mode_masks(void)
{
static const enum ethtool_link_mode_bit_indices
all_advertised_modes_bits[] = {
ETHTOOL_LINK_MODE_10baseT_Half_BIT,
ETHTOOL_LINK_MODE_10baseT_Full_BIT,
ETHTOOL_LINK_MODE_100baseT_Half_BIT,
ETHTOOL_LINK_MODE_100baseT_Full_BIT,
ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_10000baseR_FEC_BIT,
ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT,
ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT,
ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
ETHTOOL_LINK_MODE_10000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT,
ETHTOOL_LINK_MODE_10000baseER_Full_BIT,
ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
ETHTOOL_LINK_MODE_50000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseDR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT,
ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT,
ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_100baseT1_Full_BIT,
ETHTOOL_LINK_MODE_1000baseT1_Full_BIT,
ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT,
ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT,
ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT,
ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT,
ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT,
ETHTOOL_LINK_MODE_100000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseLR_ER_FR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseDR_Full_BIT,
ETHTOOL_LINK_MODE_200000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseSR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseLR2_ER2_FR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseDR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseCR2_Full_BIT,
ETHTOOL_LINK_MODE_400000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_400000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_400000baseLR4_ER4_FR4_Full_BIT,
ETHTOOL_LINK_MODE_400000baseDR4_Full_BIT,
ETHTOOL_LINK_MODE_400000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_100baseFX_Half_BIT,
ETHTOOL_LINK_MODE_100baseFX_Full_BIT,
ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
ETHTOOL_LINK_MODE_800000baseCR8_Full_BIT,
ETHTOOL_LINK_MODE_800000baseKR8_Full_BIT,
ETHTOOL_LINK_MODE_800000baseDR8_Full_BIT,
ETHTOOL_LINK_MODE_800000baseDR8_2_Full_BIT,
ETHTOOL_LINK_MODE_800000baseSR8_Full_BIT,
ETHTOOL_LINK_MODE_800000baseVR8_Full_BIT,
ETHTOOL_LINK_MODE_10baseT1S_Full_BIT,
ETHTOOL_LINK_MODE_10baseT1S_Half_BIT,
ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT,
ETHTOOL_LINK_MODE_10baseT1BRR_Full_BIT,
ETHTOOL_LINK_MODE_200000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_200000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_200000baseDR_Full_BIT,
ETHTOOL_LINK_MODE_200000baseDR_2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_200000baseVR_Full_BIT,
ETHTOOL_LINK_MODE_400000baseCR2_Full_BIT,
ETHTOOL_LINK_MODE_400000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_400000baseDR2_Full_BIT,
ETHTOOL_LINK_MODE_400000baseDR2_2_Full_BIT,
ETHTOOL_LINK_MODE_400000baseSR2_Full_BIT,
ETHTOOL_LINK_MODE_400000baseVR2_Full_BIT,
ETHTOOL_LINK_MODE_800000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_800000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_800000baseDR4_Full_BIT,
ETHTOOL_LINK_MODE_800000baseDR4_2_Full_BIT,
ETHTOOL_LINK_MODE_800000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_800000baseVR4_Full_BIT,
};
static const enum ethtool_link_mode_bit_indices
additional_advertised_flags_bits[] = {
ETHTOOL_LINK_MODE_Autoneg_BIT,
ETHTOOL_LINK_MODE_TP_BIT,
ETHTOOL_LINK_MODE_AUI_BIT,
ETHTOOL_LINK_MODE_MII_BIT,
ETHTOOL_LINK_MODE_FIBRE_BIT,
ETHTOOL_LINK_MODE_BNC_BIT,
ETHTOOL_LINK_MODE_Pause_BIT,
ETHTOOL_LINK_MODE_Asym_Pause_BIT,
ETHTOOL_LINK_MODE_Backplane_BIT,
ETHTOOL_LINK_MODE_FEC_NONE_BIT,
ETHTOOL_LINK_MODE_FEC_RS_BIT,
ETHTOOL_LINK_MODE_FEC_BASER_BIT,
ETHTOOL_LINK_MODE_FEC_LLRS_BIT,
};
unsigned int i;
ethtool_link_mode_zero(all_advertised_modes);
ethtool_link_mode_zero(all_advertised_flags);
for (i = 0; i < ARRAY_SIZE(all_advertised_modes_bits); ++i) {
ethtool_link_mode_set_bit(all_advertised_modes_bits[i],
all_advertised_modes);
ethtool_link_mode_set_bit(all_advertised_modes_bits[i],
all_advertised_flags);
}
for (i = 0; i < ARRAY_SIZE(additional_advertised_flags_bits); ++i) {
ethtool_link_mode_set_bit(
additional_advertised_flags_bits[i],
all_advertised_flags);
}
}
static void dump_link_caps(const char *prefix, const char *an_prefix,
const u32 *mask, int link_mode_only);
static void dump_supported(const struct ethtool_link_usettings *link_usettings)
{
fprintf(stdout, " Supported ports: [ ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_TP_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "TP ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_AUI_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "AUI ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_BNC_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "BNC ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_MII_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "MII ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_FIBRE_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "FIBRE ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Backplane_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "Backplane ");
fprintf(stdout, "]\n");
dump_link_caps("Supported", "Supports",
link_usettings->link_modes.supported, 0);
}
/* Print link capability flags (supported, advertised or lp_advertised).
* Assumes that the corresponding SUPPORTED and ADVERTISED flags are equal.
*/
static void dump_link_caps(const char *prefix, const char *an_prefix,
const u32 *mask, int link_mode_only)
{
static const struct {
int same_line; /* print on same line as previous */
unsigned int bit_index;
const char *name;
} mode_defs[] = {
{ 0, ETHTOOL_LINK_MODE_10baseT_Half_BIT,
"10baseT/Half" },
{ 1, ETHTOOL_LINK_MODE_10baseT_Full_BIT,
"10baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_100baseT_Half_BIT,
"100baseT/Half" },
{ 1, ETHTOOL_LINK_MODE_100baseT_Full_BIT,
"100baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
"1000baseT/Half" },
{ 1, ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
"1000baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
"10000baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
"2500baseX/Full" },
{ 0, ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
"1000baseKX/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
"10000baseKX4/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
"10000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseR_FEC_BIT,
"10000baseR_FEC" },
{ 0, ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT,
"20000baseMLD2/Full" },
{ 0, ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
"20000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
"40000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
"40000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
"40000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
"40000baseLR4/Full" },
{ 0, ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT,
"56000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT,
"56000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT,
"56000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT,
"56000baseLR4/Full" },
{ 0, ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
"25000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
"25000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
"25000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
"50000baseCR2/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
"50000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
"100000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
"100000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
"100000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
"100000baseLR4_ER4/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
"50000baseSR2/Full" },
{ 0, ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
"1000baseX/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseCR_Full_BIT,
"10000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
"10000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
"10000baseLR/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT,
"10000baseLRM/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseER_Full_BIT,
"10000baseER/Full" },
{ 0, ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
"2500baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
"5000baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseKR_Full_BIT,
"50000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseSR_Full_BIT,
"50000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseCR_Full_BIT,
"50000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT,
"50000baseLR_ER_FR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseDR_Full_BIT,
"50000baseDR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT,
"100000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT,
"100000baseSR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT,
"100000baseCR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT,
"100000baseLR2_ER2_FR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT,
"100000baseDR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT,
"200000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT,
"200000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT,
"200000baseLR4_ER4_FR4/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT,
"200000baseDR4/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT,
"200000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100baseT1_Full_BIT,
"100baseT1/Full" },
{ 0, ETHTOOL_LINK_MODE_1000baseT1_Full_BIT,
"1000baseT1/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT,
"400000baseKR8/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT,
"400000baseSR8/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT,
"400000baseLR8_ER8_FR8/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT,
"400000baseDR8/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT,
"400000baseCR8/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseKR_Full_BIT,
"100000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseSR_Full_BIT,
"100000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseLR_ER_FR_Full_BIT,
"100000baseLR_ER_FR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseDR_Full_BIT,
"100000baseDR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseCR_Full_BIT,
"100000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseKR2_Full_BIT,
"200000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseSR2_Full_BIT,
"200000baseSR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseLR2_ER2_FR2_Full_BIT,
"200000baseLR2_ER2_FR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseDR2_Full_BIT,
"200000baseDR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseCR2_Full_BIT,
"200000baseCR2/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseKR4_Full_BIT,
"400000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseSR4_Full_BIT,
"400000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseLR4_ER4_FR4_Full_BIT,
"400000baseLR4_ER4_FR4/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseDR4_Full_BIT,
"400000baseDR4/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseCR4_Full_BIT,
"400000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100baseFX_Half_BIT,
"100baseFX/Half" },
{ 1, ETHTOOL_LINK_MODE_100baseFX_Full_BIT,
"100baseFX/Full" },
{ 0, ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
"10baseT1L/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseCR8_Full_BIT,
"800000baseCR8/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseKR8_Full_BIT,
"800000baseKR8/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseDR8_Full_BIT,
"800000baseDR8/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseDR8_2_Full_BIT,
"800000baseDR8_2/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseSR8_Full_BIT,
"800000baseSR8/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseVR8_Full_BIT,
"800000baseVR8/Full" },
{ 0, ETHTOOL_LINK_MODE_10baseT1S_Full_BIT,
"10baseT1S/Full" },
{ 1, ETHTOOL_LINK_MODE_10baseT1S_Half_BIT,
"10baseT1S/Half" },
{ 0, ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT,
"10baseT1S/Half" },
{ 0, ETHTOOL_LINK_MODE_10baseT1BRR_Full_BIT,
"10baseT1BRR/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseCR_Full_BIT,
"200000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseKR_Full_BIT,
"200000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseDR_Full_BIT,
"200000baseDR/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseDR_2_Full_BIT,
"200000baseDR_2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseSR_Full_BIT,
"200000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseVR_Full_BIT,
"200000baseVR/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseCR2_Full_BIT,
"400000baseCR2/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseKR2_Full_BIT,
"400000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseDR2_Full_BIT,
"400000baseDR2/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseDR2_2_Full_BIT,
"400000baseDR2_2/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseSR2_Full_BIT,
"400000baseSR2/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseVR2_Full_BIT,
"400000baseVR2/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseCR4_Full_BIT,
"800000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseKR4_Full_BIT,
"800000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseDR4_Full_BIT,
"800000baseDR4/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseDR4_2_Full_BIT,
"800000baseDR4_2/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseSR4_Full_BIT,
"800000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseVR4_Full_BIT,
"800000baseVR4/Full" },
};
int indent;
int did1, new_line_pend;
int fecreported = 0;
unsigned int i;
/* Indent just like the separate functions used to */
indent = strlen(prefix) + 14;
if (indent < 24)
indent = 24;
fprintf(stdout, " %s link modes:%*s", prefix,
indent - (int)strlen(prefix) - 12, "");
did1 = 0;
new_line_pend = 0;
for (i = 0; i < ARRAY_SIZE(mode_defs); i++) {
if (did1 && !mode_defs[i].same_line)
new_line_pend = 1;
if (ethtool_link_mode_test_bit(mode_defs[i].bit_index,
mask)) {
if (new_line_pend) {
fprintf(stdout, "\n");
fprintf(stdout, " %*s", indent, "");
new_line_pend = 0;
}
did1++;
fprintf(stdout, "%s ", mode_defs[i].name);
}
}
if (did1 == 0)
fprintf(stdout, "Not reported");
fprintf(stdout, "\n");
if (!link_mode_only) {
fprintf(stdout, " %s pause frame use: ", prefix);
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Pause_BIT, mask)) {
fprintf(stdout, "Symmetric");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Asym_Pause_BIT, mask))
fprintf(stdout, " Receive-only");
fprintf(stdout, "\n");
} else {
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Asym_Pause_BIT, mask))
fprintf(stdout, "Transmit-only\n");
else
fprintf(stdout, "No\n");
}
fprintf(stdout, " %s auto-negotiation: ", an_prefix);
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Autoneg_BIT, mask))
fprintf(stdout, "Yes\n");
else
fprintf(stdout, "No\n");
fprintf(stdout, " %s FEC modes:", prefix);
if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_NONE_BIT,
mask)) {
fprintf(stdout, " None");
fecreported = 1;
}
if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_BASER_BIT,
mask)) {
fprintf(stdout, " BaseR");
fecreported = 1;
}
if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_RS_BIT,
mask)) {
fprintf(stdout, " RS");
fecreported = 1;
}
if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_LLRS_BIT,
mask)) {
fprintf(stdout, " LLRS");
fecreported = 1;
}
if (!fecreported)
fprintf(stdout, " Not reported");
fprintf(stdout, "\n");
}
}
static int
dump_link_usettings(const struct ethtool_link_usettings *link_usettings)
{
dump_supported(link_usettings);
dump_link_caps("Advertised", "Advertised",
link_usettings->link_modes.advertising, 0);
if (!ethtool_link_mode_is_empty(
link_usettings->link_modes.lp_advertising))
dump_link_caps("Link partner advertised",
"Link partner advertised",
link_usettings->link_modes.lp_advertising, 0);
fprintf(stdout, " Speed: ");
if (link_usettings->base.speed == 0
|| link_usettings->base.speed == (u16)(-1)
|| link_usettings->base.speed == (u32)(-1))
fprintf(stdout, "Unknown!\n");
else
fprintf(stdout, "%uMb/s\n", link_usettings->base.speed);
fprintf(stdout, " Duplex: ");
switch (link_usettings->base.duplex) {
case DUPLEX_HALF:
fprintf(stdout, "Half\n");
break;
case DUPLEX_FULL:
fprintf(stdout, "Full\n");
break;
default:
fprintf(stdout, "Unknown! (%i)\n", link_usettings->base.duplex);
break;
};
fprintf(stdout, " Port: ");
switch (link_usettings->base.port) {
case PORT_TP:
fprintf(stdout, "Twisted Pair\n");
break;
case PORT_AUI:
fprintf(stdout, "AUI\n");
break;
case PORT_BNC:
fprintf(stdout, "BNC\n");
break;
case PORT_MII:
fprintf(stdout, "MII\n");
break;
case PORT_FIBRE:
fprintf(stdout, "FIBRE\n");
break;
case PORT_DA:
fprintf(stdout, "Direct Attach Copper\n");
break;
case PORT_NONE:
fprintf(stdout, "None\n");
break;
case PORT_OTHER:
fprintf(stdout, "Other\n");
break;
default:
fprintf(stdout, "Unknown! (%i)\n", link_usettings->base.port);
break;
};
fprintf(stdout, " PHYAD: %d\n", link_usettings->base.phy_address);
fprintf(stdout, " Transceiver: ");
switch (link_usettings->deprecated.transceiver) {
case XCVR_INTERNAL:
fprintf(stdout, "internal\n");
break;
case XCVR_EXTERNAL:
fprintf(stdout, "external\n");
break;
default:
fprintf(stdout, "Unknown!\n");
break;
};
fprintf(stdout, " Auto-negotiation: %s\n",
(link_usettings->base.autoneg == AUTONEG_DISABLE) ?
"off" : "on");
if (link_usettings->base.port == PORT_TP)
dump_mdix(link_usettings->base.eth_tp_mdix,
link_usettings->base.eth_tp_mdix_ctrl);
return 0;
}
static int dump_drvinfo(struct ethtool_drvinfo *info)
{
fprintf(stdout,
"driver: %.*s\n"
"version: %.*s\n"
"firmware-version: %.*s\n"
"expansion-rom-version: %.*s\n"
"bus-info: %.*s\n"
"supports-statistics: %s\n"
"supports-test: %s\n"
"supports-eeprom-access: %s\n"
"supports-register-dump: %s\n"
"supports-priv-flags: %s\n",
(int)sizeof(info->driver), info->driver,
(int)sizeof(info->version), info->version,
(int)sizeof(info->fw_version), info->fw_version,
(int)sizeof(info->erom_version), info->erom_version,
(int)sizeof(info->bus_info), info->bus_info,
info->n_stats ? "yes" : "no",
info->testinfo_len ? "yes" : "no",
info->eedump_len ? "yes" : "no",
info->regdump_len ? "yes" : "no",
info->n_priv_flags ? "yes" : "no");
return 0;
}
static int parse_wolopts(char *optstr, u32 *data)
{
*data = 0;
while (*optstr) {
switch (*optstr) {
case 'p':
*data |= WAKE_PHY;
break;
case 'u':
*data |= WAKE_UCAST;
break;
case 'm':
*data |= WAKE_MCAST;
break;
case 'b':
*data |= WAKE_BCAST;
break;
case 'a':
*data |= WAKE_ARP;
break;
case 'g':
*data |= WAKE_MAGIC;
break;
case 's':
*data |= WAKE_MAGICSECURE;
break;
case 'f':
*data |= WAKE_FILTER;
break;
case 'd':
*data = 0;
break;
default:
return -1;
}
optstr++;
}
return 0;
}
static int parse_rxfhashopts(char *optstr, u32 *data)
{
*data = 0;
while (*optstr) {
switch (*optstr) {
case 'm':
*data |= RXH_L2DA;
break;
case 'v':
*data |= RXH_VLAN;
break;
case 't':
*data |= RXH_L3_PROTO;
break;
case 's':
*data |= RXH_IP_SRC;
break;
case 'd':
*data |= RXH_IP_DST;
break;
case 'f':
*data |= RXH_L4_B_0_1;
break;
case 'n':
*data |= RXH_L4_B_2_3;
break;
case 'e':
*data |= RXH_GTP_TEID;
break;
case 'r':
*data |= RXH_DISCARD;
break;
default:
return -1;
}
optstr++;
}
return 0;
}
static char *unparse_rxfhashopts(u64 opts)
{
static char buf[300];
memset(buf, 0, sizeof(buf));
if (opts) {
if (opts & RXH_L2DA)
strcat(buf, "L2DA\n");
if (opts & RXH_VLAN)
strcat(buf, "VLAN tag\n");
if (opts & RXH_L3_PROTO)
strcat(buf, "L3 proto\n");
if (opts & RXH_IP_SRC)
strcat(buf, "IP SA\n");
if (opts & RXH_IP_DST)
strcat(buf, "IP DA\n");
if (opts & RXH_L4_B_0_1)
strcat(buf, "L4 bytes 0 & 1 [TCP/UDP src port]\n");
if (opts & RXH_L4_B_2_3)
strcat(buf, "L4 bytes 2 & 3 [TCP/UDP dst port]\n");
if (opts & RXH_GTP_TEID)
strcat(buf, "GTP TEID\n");
} else {
sprintf(buf, "None");
}
return buf;
}
static int convert_string_to_hashkey(char *rss_hkey, u32 key_size,
const char *rss_hkey_string)
{
u32 i = 0;
int hex_byte, len;
do {
if (i > (key_size - 1)) {
fprintf(stderr,
"Key is too long for device (%u > %u)\n",
i + 1, key_size);
goto err;
}
if (sscanf(rss_hkey_string, "%2x%n", &hex_byte, &len) < 1 ||
len != 2) {
fprintf(stderr, "Invalid RSS hash key format\n");
goto err;
}
rss_hkey[i++] = hex_byte;
rss_hkey_string += 2;
if (*rss_hkey_string == ':') {
rss_hkey_string++;
} else if (*rss_hkey_string != '\0') {
fprintf(stderr, "Invalid RSS hash key format\n");
goto err;
}
} while (*rss_hkey_string);
if (i != key_size) {
fprintf(stderr, "Key is too short for device (%u < %u)\n",
i, key_size);
goto err;
}
return 0;
err:
return 2;
}
static int parse_hkey(char **rss_hkey, u32 key_size,
const char *rss_hkey_string)
{
if (!key_size) {
fprintf(stderr,
"Cannot set RX flow hash configuration:\n"
" Hash key setting not supported\n");
return 1;
}
*rss_hkey = malloc(key_size);
if (!(*rss_hkey)) {
perror("Cannot allocate memory for RSS hash key");
return 1;
}
if (convert_string_to_hashkey(*rss_hkey, key_size,
rss_hkey_string)) {
free(*rss_hkey);
*rss_hkey = NULL;
return 2;
}
return 0;
}
#ifdef ETHTOOL_ENABLE_PRETTY_DUMP
static const struct {
const char *name;
int (*func)(struct ethtool_drvinfo *info, struct ethtool_regs *regs);
} driver_list[] = {
{ "8139cp", realtek_dump_regs },
{ "8139too", realtek_dump_regs },
{ "r8169", realtek_dump_regs },
{ "de2104x", de2104x_dump_regs },
{ "e1000", e1000_dump_regs },
{ "e1000e", e1000_dump_regs },
{ "igb", igb_dump_regs },
{ "ixgb", ixgb_dump_regs },
{ "ixgbe", ixgbe_dump_regs },
{ "ixgbevf", ixgbevf_dump_regs },
{ "natsemi", natsemi_dump_regs },
{ "e100", e100_dump_regs },
{ "amd8111e", amd8111e_dump_regs },
{ "pcnet32", pcnet32_dump_regs },
{ "fec_8xx", fec_8xx_dump_regs },
{ "ibm_emac", ibm_emac_dump_regs },
{ "tg3", tg3_dump_regs },
{ "skge", skge_dump_regs },
{ "sky2", sky2_dump_regs },
{ "vioc", vioc_dump_regs },
{ "smsc911x", smsc911x_dump_regs },
{ "at76c50x-usb", at76c50x_usb_dump_regs },
{ "sfc", sfc_dump_regs },
{ "st_mac100", st_mac100_dump_regs },
{ "st_gmac", st_gmac_dump_regs },
{ "et131x", et131x_dump_regs },
{ "altera_tse", altera_tse_dump_regs },
{ "vmxnet3", vmxnet3_dump_regs },
{ "fjes", fjes_dump_regs },
{ "lan78xx", lan78xx_dump_regs },
{ "dsa", dsa_dump_regs },
{ "fec", fec_dump_regs },
{ "igc", igc_dump_regs },
{ "bnxt_en", bnxt_dump_regs },
{ "cpsw-switch", cpsw_dump_regs },
{ "lan743x", lan743x_dump_regs },
{ "fsl_enetc", fsl_enetc_dump_regs },
{ "fsl_enetc_vf", fsl_enetc_dump_regs },
{ "hns3", hns3_dump_regs },
{ "fbnic", fbnic_dump_regs },
{ "hibmcge", hibmcge_dump_regs },
};
#endif
void dump_hex(FILE *file, const u8 *data, int len, int offset)
{
int i;
fprintf(file, "Offset\t\tValues\n");
fprintf(file, "------\t\t------");
for (i = 0; i < len; i++) {
if (i % 16 == 0)
fprintf(file, "\n0x%04x:\t\t", i + offset);
fprintf(file, "%02x ", data[i]);
}
fprintf(file, "\n");
}
static int dump_regs(int gregs_dump_raw, int gregs_dump_hex,
struct ethtool_drvinfo *info, struct ethtool_regs *regs)
{
if (gregs_dump_raw) {
fwrite(regs->data, regs->len, 1, stdout);
goto nested;
}
#ifdef ETHTOOL_ENABLE_PRETTY_DUMP
if (!gregs_dump_hex) {
unsigned int i;
for (i = 0; i < ARRAY_SIZE(driver_list); i++)
if (!strncmp(driver_list[i].name, info->driver,
ETHTOOL_BUSINFO_LEN)) {
if (driver_list[i].func(info, regs) == 0)
goto nested;
/* This version (or some other
* variation in the dump format) is
* not handled; fall back to hex
*/
break;
}
}
#endif
dump_hex(stdout, regs->data, regs->len, 0);
nested:
/* Recurse dump if some drvinfo and regs structures are nested */
if (info->regdump_len > regs->len + sizeof(*info) + sizeof(*regs)) {
info = (struct ethtool_drvinfo *)(®s->data[0] + regs->len);
regs = (struct ethtool_regs *)(®s->data[0] + regs->len + sizeof(*info));
return dump_regs(gregs_dump_raw, gregs_dump_hex, info, regs);
}
return 0;
}
static int dump_eeprom(int geeprom_dump_raw,
struct ethtool_drvinfo *info __maybe_unused,
struct ethtool_eeprom *ee)
{
if (geeprom_dump_raw) {
fwrite(ee->data, 1, ee->len, stdout);
return 0;
}
#ifdef ETHTOOL_ENABLE_PRETTY_DUMP
if (!strncmp("natsemi", info->driver, ETHTOOL_BUSINFO_LEN)) {
return natsemi_dump_eeprom(info, ee);
} else if (!strncmp("tg3", info->driver, ETHTOOL_BUSINFO_LEN)) {
return tg3_dump_eeprom(info, ee);
}
#endif
dump_hex(stdout, ee->data, ee->len, ee->offset);
return 0;
}
static int dump_test(struct ethtool_test *test,
struct ethtool_gstrings *strings)
{
unsigned int i;
int rc;
rc = test->flags & ETH_TEST_FL_FAILED;
fprintf(stdout, "The test result is %s\n", rc ? "FAIL" : "PASS");
if (test->flags & ETH_TEST_FL_EXTERNAL_LB)
fprintf(stdout, "External loopback test was %sexecuted\n",
(test->flags & ETH_TEST_FL_EXTERNAL_LB_DONE) ?
"" : "not ");
if (strings->len)
fprintf(stdout, "The test extra info:\n");
for (i = 0; i < strings->len; i++) {
fprintf(stdout, "%s\t %d\n",
(char *)(strings->data + i * ETH_GSTRING_LEN),
(u32) test->data[i]);
}
fprintf(stdout, "\n");
return rc;
}
static int dump_pause(const struct ethtool_pauseparam *epause,
u32 advertising, u32 lp_advertising)
{
fprintf(stdout,
"Autonegotiate: %s\n"
"RX: %s\n"
"TX: %s\n",
epause->autoneg ? "on" : "off",
epause->rx_pause ? "on" : "off",
epause->tx_pause ? "on" : "off");
if (lp_advertising) {
int an_rx = 0, an_tx = 0;
/* Work out negotiated pause frame usage per
* IEEE 802.3-2005 table 28B-3.
*/
if (advertising & lp_advertising & ADVERTISED_Pause) {
an_tx = 1;
an_rx = 1;
} else if (advertising & lp_advertising &
ADVERTISED_Asym_Pause) {
if (advertising & ADVERTISED_Pause)
an_rx = 1;
else if (lp_advertising & ADVERTISED_Pause)
an_tx = 1;
}
fprintf(stdout,
"RX negotiated: %s\n"
"TX negotiated: %s\n",
an_rx ? "on" : "off",
an_tx ? "on" : "off");
}
fprintf(stdout, "\n");
return 0;
}
static int dump_ring(const struct ethtool_ringparam *ering)
{
fprintf(stdout,
"Pre-set maximums:\n"
"RX: %u\n"
"RX Mini: %u\n"
"RX Jumbo: %u\n"
"TX: %u\n",
ering->rx_max_pending,
ering->rx_mini_max_pending,
ering->rx_jumbo_max_pending,
ering->tx_max_pending);
fprintf(stdout,
"Current hardware settings:\n"
"RX: %u\n"
"RX Mini: %u\n"
"RX Jumbo: %u\n"
"TX: %u\n",
ering->rx_pending,
ering->rx_mini_pending,
ering->rx_jumbo_pending,
ering->tx_pending);
fprintf(stdout, "\n");
return 0;
}
static int dump_channels(const struct ethtool_channels *echannels)
{
fprintf(stdout,
"Pre-set maximums:\n"
"RX: %u\n"
"TX: %u\n"
"Other: %u\n"
"Combined: %u\n",
echannels->max_rx, echannels->max_tx,
echannels->max_other,
echannels->max_combined);
fprintf(stdout,
"Current hardware settings:\n"
"RX: %u\n"
"TX: %u\n"
"Other: %u\n"
"Combined: %u\n",
echannels->rx_count, echannels->tx_count,
echannels->other_count,
echannels->combined_count);
fprintf(stdout, "\n");
return 0;
}
static int dump_coalesce(const struct ethtool_coalesce *ecoal)
{
fprintf(stdout, "Adaptive RX: %s TX: %s\n",
ecoal->use_adaptive_rx_coalesce ? "on" : "off",
ecoal->use_adaptive_tx_coalesce ? "on" : "off");
fprintf(stdout,
"stats-block-usecs: %u\n"
"sample-interval: %u\n"
"pkt-rate-low: %u\n"
"pkt-rate-high: %u\n"
"\n"
"rx-usecs: %u\n"
"rx-frames: %u\n"
"rx-usecs-irq: %u\n"
"rx-frames-irq: %u\n"
"\n"
"tx-usecs: %u\n"
"tx-frames: %u\n"
"tx-usecs-irq: %u\n"
"tx-frames-irq: %u\n"
"\n"
"rx-usecs-low: %u\n"
"rx-frames-low: %u\n"
"tx-usecs-low: %u\n"
"tx-frames-low: %u\n"
"\n"
"rx-usecs-high: %u\n"
"rx-frames-high: %u\n"
"tx-usecs-high: %u\n"
"tx-frames-high: %u\n"
"\n",
ecoal->stats_block_coalesce_usecs,
ecoal->rate_sample_interval,
ecoal->pkt_rate_low,
ecoal->pkt_rate_high,
ecoal->rx_coalesce_usecs,
ecoal->rx_max_coalesced_frames,
ecoal->rx_coalesce_usecs_irq,
ecoal->rx_max_coalesced_frames_irq,
ecoal->tx_coalesce_usecs,
ecoal->tx_max_coalesced_frames,
ecoal->tx_coalesce_usecs_irq,
ecoal->tx_max_coalesced_frames_irq,
ecoal->rx_coalesce_usecs_low,
ecoal->rx_max_coalesced_frames_low,
ecoal->tx_coalesce_usecs_low,
ecoal->tx_max_coalesced_frames_low,
ecoal->rx_coalesce_usecs_high,
ecoal->rx_max_coalesced_frames_high,
ecoal->tx_coalesce_usecs_high,
ecoal->tx_max_coalesced_frames_high);
return 0;
}
void dump_per_queue_coalesce(struct ethtool_per_queue_op *per_queue_opt,
__u32 *queue_mask, int n_queues)
{
struct ethtool_coalesce *ecoal;
int i, idx = 0;
ecoal = (struct ethtool_coalesce *)(per_queue_opt + 1);
for (i = 0; i < __KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32); i++) {
int queue = i * 32;
__u32 mask = queue_mask[i];
while (mask > 0) {
if (mask & 0x1) {
fprintf(stdout, "Queue: %d\n", queue);
dump_coalesce(ecoal + idx);
idx++;
}
mask = mask >> 1;
queue++;
}
if (idx == n_queues)
break;
}
}
struct feature_state {
u32 off_flags;
struct ethtool_gfeatures features;
};
static void dump_one_feature(const char *indent, const char *name,
const struct feature_state *state,
const struct feature_state *ref_state,
u32 index)
{
if (ref_state &&
!(FEATURE_BIT_IS_SET(state->features.features, index, active) ^
FEATURE_BIT_IS_SET(ref_state->features.features, index, active)))
return;
printf("%s%s: %s%s\n",
indent, name,
FEATURE_BIT_IS_SET(state->features.features, index, active) ?
"on" : "off",
(!FEATURE_BIT_IS_SET(state->features.features, index, available)
|| FEATURE_BIT_IS_SET(state->features.features, index,
never_changed))
? " [fixed]"
: (FEATURE_BIT_IS_SET(state->features.features, index, requested)
^ FEATURE_BIT_IS_SET(state->features.features, index, active))
? (FEATURE_BIT_IS_SET(state->features.features, index, requested)
? " [requested on]" : " [requested off]")
: "");
}
static unsigned int linux_version_code(void)
{
struct utsname utsname;
unsigned version, patchlevel, sublevel = 0;
if (uname(&utsname))
return -1;
if (sscanf(utsname.release, "%u.%u.%u", &version, &patchlevel, &sublevel) < 2)
return -1;
return KERNEL_VERSION(version, patchlevel, sublevel);
}
static void dump_features(const struct feature_defs *defs,
const struct feature_state *state,
const struct feature_state *ref_state)
{
unsigned int kernel_ver = linux_version_code();
unsigned int i, j;
int indent;
u32 value;
for (i = 0; i < OFF_FLAG_DEF_SIZE; i++) {
/* Don't show features whose state is unknown on this
* kernel version
*/
if (defs->off_flag_matched[i] == 0 &&
((off_flag_def[i].get_cmd == 0 &&
kernel_ver < off_flag_def[i].min_kernel_ver) ||
(off_flag_def[i].get_cmd == ETHTOOL_GUFO &&
kernel_ver >= KERNEL_VERSION(4, 14, 0))))
continue;
value = off_flag_def[i].value;
/* If this offload flag matches exactly one generic
* feature then it's redundant to show the flag and
* feature states separately. Otherwise, show the
* flag state first.
*/
if (defs->off_flag_matched[i] != 1 &&
(!ref_state ||
(state->off_flags ^ ref_state->off_flags) & value)) {
printf("%s: %s\n",
off_flag_def[i].long_name,
(state->off_flags & value) ? "on" : "off");
indent = 1;
} else {
indent = 0;
}
/* Show matching features */
for (j = 0; j < defs->n_features; j++) {
if (defs->def[j].off_flag_index != (int)i)
continue;
if (defs->off_flag_matched[i] != 1)
/* Show all matching feature states */
dump_one_feature(indent ? "\t" : "",
defs->def[j].name,
state, ref_state, j);
else
/* Show full state with the old flag name */
dump_one_feature("", off_flag_def[i].long_name,
state, ref_state, j);
}
}
/* Show all unmatched features that have non-null names */
for (j = 0; j < defs->n_features; j++)
if (defs->def[j].off_flag_index < 0 && defs->def[j].name[0])
dump_one_feature("", defs->def[j].name,
state, ref_state, j);
}
static int dump_rxfhash(int fhash, u64 val)
{
switch (fhash & ~FLOW_RSS) {
case TCP_V4_FLOW:
fprintf(stdout, "TCP over IPV4 flows");
break;
case UDP_V4_FLOW:
fprintf(stdout, "UDP over IPV4 flows");
break;
case SCTP_V4_FLOW:
fprintf(stdout, "SCTP over IPV4 flows");
break;
case GTPC_V4_FLOW:
fprintf(stdout, "GTP-C over IPV4 flows");
break;
case GTPC_TEID_V4_FLOW:
fprintf(stdout, "GTP-C (include TEID) over IPV4 flows");
break;
case GTPU_V4_FLOW:
fprintf(stdout, "GTP-U over IPV4 flows");
break;
case GTPU_EH_V4_FLOW:
fprintf(stdout, "GTP-U and Extension Header over IPV4 flows");
break;
case GTPU_UL_V4_FLOW:
fprintf(stdout, "GTP-U PSC Uplink over IPV4 flows");
break;
case GTPU_DL_V4_FLOW:
fprintf(stdout, "GTP-U PSC Downlink over IPV4 flows");
break;
case AH_ESP_V4_FLOW:
case AH_V4_FLOW:
case ESP_V4_FLOW:
fprintf(stdout, "IPSEC AH/ESP over IPV4 flows");
break;
case TCP_V6_FLOW:
fprintf(stdout, "TCP over IPV6 flows");
break;
case UDP_V6_FLOW:
fprintf(stdout, "UDP over IPV6 flows");
break;
case SCTP_V6_FLOW:
fprintf(stdout, "SCTP over IPV6 flows");
break;
case GTPC_V6_FLOW:
fprintf(stdout, "GTP-C over IPV6 flows");
break;
case GTPC_TEID_V6_FLOW:
fprintf(stdout, "GTP-C (include TEID) over IPV6 flows");
break;
case GTPU_V6_FLOW:
fprintf(stdout, "GTP-U over IPV6 flows");
break;
case GTPU_EH_V6_FLOW:
fprintf(stdout, "GTP-U and Extension Header over IPV6 flows");
break;
case GTPU_UL_V6_FLOW:
fprintf(stdout, "GTP-U PSC Uplink over IPV6 flows");
break;
case GTPU_DL_V6_FLOW:
fprintf(stdout, "GTP-U PSC Downlink over IPV6 flows");
break;
case AH_ESP_V6_FLOW:
case AH_V6_FLOW:
case ESP_V6_FLOW:
fprintf(stdout, "IPSEC AH/ESP over IPV6 flows");
break;
default:
break;
}
if (val & RXH_DISCARD) {
fprintf(stdout, " - All matching flows discarded on RX\n");
return 0;
}
fprintf(stdout, " use these fields for computing Hash flow key:\n");
fprintf(stdout, "%s\n", unparse_rxfhashopts(val));
return 0;
}
static void dump_eeecmd(struct ethtool_eee *ep)
{
ETHTOOL_DECLARE_LINK_MODE_MASK(link_mode);
fprintf(stdout, " EEE status: ");
if (!ep->supported) {
fprintf(stdout, "not supported\n");
return;
} else if (!ep->eee_enabled) {
fprintf(stdout, "disabled\n");
} else {
fprintf(stdout, "enabled - ");
if (ep->eee_active)
fprintf(stdout, "active\n");
else
fprintf(stdout, "inactive\n");
}
fprintf(stdout, " Tx LPI:");
if (ep->tx_lpi_enabled)
fprintf(stdout, " %d (us)\n", ep->tx_lpi_timer);
else
fprintf(stdout, " disabled\n");
ethtool_link_mode_zero(link_mode);
link_mode[0] = ep->supported;
dump_link_caps("Supported EEE", "", link_mode, 1);
link_mode[0] = ep->advertised;
dump_link_caps("Advertised EEE", "", link_mode, 1);
link_mode[0] = ep->lp_advertised;
dump_link_caps("Link partner advertised EEE", "", link_mode, 1);
}
static void dump_fec(u32 fec)
{
if (fec & ETHTOOL_FEC_NONE)
fprintf(stdout, " None");
if (fec & ETHTOOL_FEC_AUTO)
fprintf(stdout, " Auto");
if (fec & ETHTOOL_FEC_OFF)
fprintf(stdout, " Off");
if (fec & ETHTOOL_FEC_BASER)
fprintf(stdout, " BaseR");
if (fec & ETHTOOL_FEC_RS)
fprintf(stdout, " RS");
if (fec & ETHTOOL_FEC_LLRS)
fprintf(stdout, " LLRS");
}
#define N_SOTS 7
static char *so_timestamping_labels[N_SOTS] = {
"hardware-transmit (SOF_TIMESTAMPING_TX_HARDWARE)",
"software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)",
"hardware-receive (SOF_TIMESTAMPING_RX_HARDWARE)",
"software-receive (SOF_TIMESTAMPING_RX_SOFTWARE)",
"software-system-clock (SOF_TIMESTAMPING_SOFTWARE)",
"hardware-legacy-clock (SOF_TIMESTAMPING_SYS_HARDWARE)",
"hardware-raw-clock (SOF_TIMESTAMPING_RAW_HARDWARE)",
};
#define N_TX_TYPES (HWTSTAMP_TX_ONESTEP_SYNC + 1)
static char *tx_type_labels[N_TX_TYPES] = {
"off (HWTSTAMP_TX_OFF)",
"on (HWTSTAMP_TX_ON)",
"one-step-sync (HWTSTAMP_TX_ONESTEP_SYNC)",
};
#define N_RX_FILTERS (HWTSTAMP_FILTER_NTP_ALL + 1)
static char *rx_filter_labels[N_RX_FILTERS] = {
"none (HWTSTAMP_FILTER_NONE)",
"all (HWTSTAMP_FILTER_ALL)",
"some (HWTSTAMP_FILTER_SOME)",
"ptpv1-l4-event (HWTSTAMP_FILTER_PTP_V1_L4_EVENT)",
"ptpv1-l4-sync (HWTSTAMP_FILTER_PTP_V1_L4_SYNC)",
"ptpv1-l4-delay-req (HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ)",
"ptpv2-l4-event (HWTSTAMP_FILTER_PTP_V2_L4_EVENT)",
"ptpv2-l4-sync (HWTSTAMP_FILTER_PTP_V2_L4_SYNC)",
"ptpv2-l4-delay-req (HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ)",
"ptpv2-l2-event (HWTSTAMP_FILTER_PTP_V2_L2_EVENT)",
"ptpv2-l2-sync (HWTSTAMP_FILTER_PTP_V2_L2_SYNC)",
"ptpv2-l2-delay-req (HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ)",
"ptpv2-event (HWTSTAMP_FILTER_PTP_V2_EVENT)",
"ptpv2-sync (HWTSTAMP_FILTER_PTP_V2_SYNC)",
"ptpv2-delay-req (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ)",
"ntp-all (HWTSTAMP_FILTER_NTP_ALL)",
};
static int dump_tsinfo(const struct ethtool_ts_info *info)
{
int i;
fprintf(stdout, "Capabilities:\n");
for (i = 0; i < N_SOTS; i++) {
if (info->so_timestamping & (1 << i))
fprintf(stdout, "\t%s\n", so_timestamping_labels[i]);
}
fprintf(stdout, "PTP Hardware Clock: ");
if (info->phc_index < 0)
fprintf(stdout, "none\n");
else
fprintf(stdout, "%d\n", info->phc_index);
fprintf(stdout, "Hardware Transmit Timestamp Modes:");
if (!info->tx_types)
fprintf(stdout, " none\n");
else
fprintf(stdout, "\n");
for (i = 0; i < N_TX_TYPES; i++) {
if (info->tx_types & (1 << i))
fprintf(stdout, "\t%s\n", tx_type_labels[i]);
}
fprintf(stdout, "Hardware Receive Filter Modes:");
if (!info->rx_filters)
fprintf(stdout, " none\n");
else
fprintf(stdout, "\n");
for (i = 0; i < N_RX_FILTERS; i++) {
if (info->rx_filters & (1 << i))
fprintf(stdout, "\t%s\n", rx_filter_labels[i]);
}
return 0;
}
static struct ethtool_gstrings *
get_stringset(struct cmd_context *ctx, enum ethtool_stringset set_id,
ptrdiff_t drvinfo_offset, int null_terminate)
{
struct {
struct ethtool_sset_info hdr;
u32 buf[1];
} sset_info;
struct ethtool_drvinfo drvinfo;
u32 len, i;
struct ethtool_gstrings *strings;
sset_info.hdr.cmd = ETHTOOL_GSSET_INFO;
sset_info.hdr.reserved = 0;
sset_info.hdr.sset_mask = 1ULL << set_id;
if (send_ioctl(ctx, &sset_info) == 0) {
const u32 *sset_lengths = sset_info.hdr.data;
len = sset_info.hdr.sset_mask ? sset_lengths[0] : 0;
} else if (errno == EOPNOTSUPP && drvinfo_offset != 0) {
/* Fallback for old kernel versions */
drvinfo.cmd = ETHTOOL_GDRVINFO;
if (send_ioctl(ctx, &drvinfo))
return NULL;
len = *(u32 *)((char *)&drvinfo + drvinfo_offset);
} else {
return NULL;
}
strings = calloc(1, sizeof(*strings) + len * ETH_GSTRING_LEN);
if (!strings)
return NULL;
strings->cmd = ETHTOOL_GSTRINGS;
strings->string_set = set_id;
strings->len = len;
if (len != 0 && send_ioctl(ctx, strings)) {
free(strings);
return NULL;
}
if (null_terminate)
for (i = 0; i < len; i++)
strings->data[(i + 1) * ETH_GSTRING_LEN - 1] = 0;
return strings;
}
static struct feature_defs *get_feature_defs(struct cmd_context *ctx)
{
struct ethtool_gstrings *names;
struct feature_defs *defs;
unsigned int i, j;
u32 n_features;
names = get_stringset(ctx, ETH_SS_FEATURES, 0, 1);
if (names) {
n_features = names->len;
} else if (errno == EOPNOTSUPP || errno == EINVAL) {
/* Kernel doesn't support named features; not an error */
n_features = 0;
} else if (errno == EPERM) {
/* Kernel bug: ETHTOOL_GSSET_INFO was privileged.
* Work around it. */
n_features = 0;
} else {
return NULL;
}
defs = malloc(sizeof(*defs) + sizeof(defs->def[0]) * n_features);
if (!defs) {
free(names);
return NULL;
}
defs->n_features = n_features;
memset(defs->off_flag_matched, 0, sizeof(defs->off_flag_matched));
/* Copy out feature names and find those associated with legacy flags */
for (i = 0; i < defs->n_features; i++) {
memcpy(defs->def[i].name, names->data + i * ETH_GSTRING_LEN,
ETH_GSTRING_LEN);
defs->def[i].off_flag_index = -1;
for (j = 0;
j < OFF_FLAG_DEF_SIZE &&
defs->def[i].off_flag_index < 0;
j++) {
const char *pattern =
off_flag_def[j].kernel_name;
const char *name = defs->def[i].name;
for (;;) {
if (*pattern == '*') {
/* There is only one wildcard; so
* switch to a suffix comparison */
size_t pattern_len =
strlen(pattern + 1);
size_t name_len = strlen(name);
if (name_len < pattern_len)
break; /* name is too short */
name += name_len - pattern_len;
++pattern;
} else if (*pattern != *name) {
break; /* mismatch */
} else if (*pattern == 0) {
defs->def[i].off_flag_index = j;
defs->off_flag_matched[j]++;
break;
} else {
++name;
++pattern;
}
}
}
}
free(names);
return defs;
}
static int do_gdrv(struct cmd_context *ctx)
{
int err;
struct ethtool_drvinfo drvinfo;
if (ctx->argc != 0)
exit_bad_args();
drvinfo.cmd = ETHTOOL_GDRVINFO;
err = send_ioctl(ctx, &drvinfo);
if (err < 0) {
perror("Cannot get driver information");
return 71;
}
return dump_drvinfo(&drvinfo);
}
static int do_gpause(struct cmd_context *ctx)
{
struct ethtool_pauseparam epause;
struct ethtool_cmd ecmd;
int err;
if (ctx->argc != 0)
exit_bad_args();
fprintf(stdout, "Pause parameters for %s:\n", ctx->devname);
epause.cmd = ETHTOOL_GPAUSEPARAM;
err = send_ioctl(ctx, &epause);
if (err) {
perror("Cannot get device pause settings");
return 76;
}
if (epause.autoneg) {
ecmd.cmd = ETHTOOL_GSET;
err = send_ioctl(ctx, &ecmd);
if (err) {
perror("Cannot get device settings");
return 1;
}
dump_pause(&epause, ecmd.advertising, ecmd.lp_advertising);
} else {
dump_pause(&epause, 0, 0);
}
return 0;
}
static void do_generic_set1(struct cmdline_info *info, int *changed_out)
{
int wanted, *v1, *v2;
v1 = info->wanted_val;
wanted = *v1;
if (wanted < 0)
return;
v2 = info->ioctl_val;
if (wanted == *v2) {
fprintf(stderr, "%s unmodified, ignoring\n", info->name);
} else {
*v2 = wanted;
*changed_out = 1;
}
}
static void do_generic_set(struct cmdline_info *info,
unsigned int n_info,
int *changed_out)
{
unsigned int i;
for (i = 0; i < n_info; i++)
do_generic_set1(&info[i], changed_out);
}
static int do_spause(struct cmd_context *ctx)
{
struct ethtool_pauseparam epause;
int gpause_changed = 0;
int pause_autoneg_wanted = -1;
int pause_rx_wanted = -1;
int pause_tx_wanted = -1;
struct cmdline_info cmdline_pause[] = {
{
.name = "autoneg",
.type = CMDL_BOOL,
.wanted_val = &pause_autoneg_wanted,
.ioctl_val = &epause.autoneg,
},
{
.name = "rx",
.type = CMDL_BOOL,
.wanted_val = &pause_rx_wanted,
.ioctl_val = &epause.rx_pause,
},
{
.name = "tx",
.type = CMDL_BOOL,
.wanted_val = &pause_tx_wanted,
.ioctl_val = &epause.tx_pause,
},
};
int err, changed = 0;
parse_generic_cmdline(ctx, &gpause_changed,
cmdline_pause, ARRAY_SIZE(cmdline_pause));
epause.cmd = ETHTOOL_GPAUSEPARAM;
err = send_ioctl(ctx, &epause);
if (err) {
perror("Cannot get device pause settings");
return 77;
}
do_generic_set(cmdline_pause, ARRAY_SIZE(cmdline_pause), &changed);
if (!changed) {
fprintf(stderr, "no pause parameters changed, aborting\n");
return 78;
}
epause.cmd = ETHTOOL_SPAUSEPARAM;
err = send_ioctl(ctx, &epause);
if (err) {
perror("Cannot set device pause parameters");
return 79;
}
return 0;
}
static int do_sring(struct cmd_context *ctx)
{
struct ethtool_ringparam ering;
int gring_changed = 0;
s32 ring_rx_wanted = -1;
s32 ring_rx_mini_wanted = -1;
s32 ring_rx_jumbo_wanted = -1;
s32 ring_tx_wanted = -1;
struct cmdline_info cmdline_ring[] = {
{
.name = "rx",
.type = CMDL_S32,
.wanted_val = &ring_rx_wanted,
.ioctl_val = &ering.rx_pending,
},
{
.name = "rx-mini",
.type = CMDL_S32,
.wanted_val = &ring_rx_mini_wanted,
.ioctl_val = &ering.rx_mini_pending,
},
{
.name = "rx-jumbo",
.type = CMDL_S32,
.wanted_val = &ring_rx_jumbo_wanted,
.ioctl_val = &ering.rx_jumbo_pending,
},
{
.name = "tx",
.type = CMDL_S32,
.wanted_val = &ring_tx_wanted,
.ioctl_val = &ering.tx_pending,
},
};
int err, changed = 0;
parse_generic_cmdline(ctx, &gring_changed,
cmdline_ring, ARRAY_SIZE(cmdline_ring));
ering.cmd = ETHTOOL_GRINGPARAM;
err = send_ioctl(ctx, &ering);
if (err) {
perror("Cannot get device ring settings");
return 76;
}
do_generic_set(cmdline_ring, ARRAY_SIZE(cmdline_ring), &changed);
if (!changed) {
fprintf(stderr, "no ring parameters changed, aborting\n");
return 80;
}
ering.cmd = ETHTOOL_SRINGPARAM;
err = send_ioctl(ctx, &ering);
if (err) {
perror("Cannot set device ring parameters");
return 81;
}
return 0;
}
static int do_gring(struct cmd_context *ctx)
{
struct ethtool_ringparam ering;
int err;
if (ctx->argc != 0)
exit_bad_args();
fprintf(stdout, "Ring parameters for %s:\n", ctx->devname);
ering.cmd = ETHTOOL_GRINGPARAM;
err = send_ioctl(ctx, &ering);
if (err == 0) {
err = dump_ring(&ering);
if (err)
return err;
} else {
perror("Cannot get device ring settings");
return 76;
}
return 0;
}
static int do_schannels(struct cmd_context *ctx)
{
struct ethtool_channels echannels;
int gchannels_changed;
s32 channels_rx_wanted = -1;
s32 channels_tx_wanted = -1;
s32 channels_other_wanted = -1;
s32 channels_combined_wanted = -1;
struct cmdline_info cmdline_channels[] = {
{
.name = "rx",
.type = CMDL_S32,
.wanted_val = &channels_rx_wanted,
.ioctl_val = &echannels.rx_count,
},
{
.name = "tx",
.type = CMDL_S32,
.wanted_val = &channels_tx_wanted,
.ioctl_val = &echannels.tx_count,
},
{
.name = "other",
.type = CMDL_S32,
.wanted_val = &channels_other_wanted,
.ioctl_val = &echannels.other_count,
},
{
.name = "combined",
.type = CMDL_S32,
.wanted_val = &channels_combined_wanted,
.ioctl_val = &echannels.combined_count,
},
};
int err, changed = 0;
parse_generic_cmdline(ctx, &gchannels_changed,
cmdline_channels, ARRAY_SIZE(cmdline_channels));
echannels.cmd = ETHTOOL_GCHANNELS;
err = send_ioctl(ctx, &echannels);
if (err) {
perror("Cannot get device channel parameters");
return 1;
}
do_generic_set(cmdline_channels, ARRAY_SIZE(cmdline_channels),
&changed);
if (!changed) {
fprintf(stderr, "no channel parameters changed.\n");
fprintf(stderr, "current values: rx %u tx %u other %u"
" combined %u\n", echannels.rx_count,
echannels.tx_count, echannels.other_count,
echannels.combined_count);
return 0;
}
echannels.cmd = ETHTOOL_SCHANNELS;
err = send_ioctl(ctx, &echannels);
if (err) {
perror("Cannot set device channel parameters");
return 1;
}
return 0;
}
static int do_gchannels(struct cmd_context *ctx)
{
struct ethtool_channels echannels;
int err;
if (ctx->argc != 0)
exit_bad_args();
fprintf(stdout, "Channel parameters for %s:\n", ctx->devname);
echannels.cmd = ETHTOOL_GCHANNELS;
err = send_ioctl(ctx, &echannels);
if (err == 0) {
err = dump_channels(&echannels);
if (err)
return err;
} else {
perror("Cannot get device channel parameters");
return 1;
}
return 0;
}
static int do_gcoalesce(struct cmd_context *ctx)
{
struct ethtool_coalesce ecoal = {};
int err;
if (ctx->argc != 0)
exit_bad_args();
fprintf(stdout, "Coalesce parameters for %s:\n", ctx->devname);
ecoal.cmd = ETHTOOL_GCOALESCE;
err = send_ioctl(ctx, &ecoal);
if (err == 0) {
err = dump_coalesce(&ecoal);
if (err)
return err;
} else {
perror("Cannot get device coalesce settings");
return 82;
}
return 0;
}
#define DECLARE_COALESCE_OPTION_VARS() \
s32 coal_stats_wanted = -1; \
int coal_adaptive_rx_wanted = -1; \
int coal_adaptive_tx_wanted = -1; \
s32 coal_sample_rate_wanted = -1; \
s32 coal_pkt_rate_low_wanted = -1; \
s32 coal_pkt_rate_high_wanted = -1; \
s32 coal_rx_usec_wanted = -1; \
s32 coal_rx_frames_wanted = -1; \
s32 coal_rx_usec_irq_wanted = -1; \
s32 coal_rx_frames_irq_wanted = -1; \
s32 coal_tx_usec_wanted = -1; \
s32 coal_tx_frames_wanted = -1; \
s32 coal_tx_usec_irq_wanted = -1; \
s32 coal_tx_frames_irq_wanted = -1; \
s32 coal_rx_usec_low_wanted = -1; \
s32 coal_rx_frames_low_wanted = -1; \
s32 coal_tx_usec_low_wanted = -1; \
s32 coal_tx_frames_low_wanted = -1; \
s32 coal_rx_usec_high_wanted = -1; \
s32 coal_rx_frames_high_wanted = -1; \
s32 coal_tx_usec_high_wanted = -1; \
s32 coal_tx_frames_high_wanted = -1
#define COALESCE_CMDLINE_INFO(__ecoal) \
{ \
{ \
.name = "adaptive-rx", \
.type = CMDL_BOOL, \
.wanted_val = &coal_adaptive_rx_wanted, \
.ioctl_val = &__ecoal.use_adaptive_rx_coalesce, \
}, \
{ \
.name = "adaptive-tx", \
.type = CMDL_BOOL, \
.wanted_val = &coal_adaptive_tx_wanted, \
.ioctl_val = &__ecoal.use_adaptive_tx_coalesce, \
}, \
{ \
.name = "sample-interval", \
.type = CMDL_S32, \
.wanted_val = &coal_sample_rate_wanted, \
.ioctl_val = &__ecoal.rate_sample_interval, \
}, \
{ \
.name = "stats-block-usecs", \
.type = CMDL_S32, \
.wanted_val = &coal_stats_wanted, \
.ioctl_val = &__ecoal.stats_block_coalesce_usecs, \
}, \
{ \
.name = "pkt-rate-low", \
.type = CMDL_S32, \
.wanted_val = &coal_pkt_rate_low_wanted, \
.ioctl_val = &__ecoal.pkt_rate_low, \
}, \
{ \
.name = "pkt-rate-high", \
.type = CMDL_S32, \
.wanted_val = &coal_pkt_rate_high_wanted, \
.ioctl_val = &__ecoal.pkt_rate_high, \
}, \
{ \
.name = "rx-usecs", \
.type = CMDL_S32, \
.wanted_val = &coal_rx_usec_wanted, \
.ioctl_val = &__ecoal.rx_coalesce_usecs, \
}, \
{ \
.name = "rx-frames", \
.type = CMDL_S32, \
.wanted_val = &coal_rx_frames_wanted, \
.ioctl_val = &__ecoal.rx_max_coalesced_frames, \
}, \
{ \
.name = "rx-usecs-irq", \
.type = CMDL_S32, \
.wanted_val = &coal_rx_usec_irq_wanted, \
.ioctl_val = &__ecoal.rx_coalesce_usecs_irq, \
}, \
{ \
.name = "rx-frames-irq", \
.type = CMDL_S32, \
.wanted_val = &coal_rx_frames_irq_wanted, \
.ioctl_val = &__ecoal.rx_max_coalesced_frames_irq, \
}, \
{ \
.name = "tx-usecs", \
.type = CMDL_S32, \
.wanted_val = &coal_tx_usec_wanted, \
.ioctl_val = &__ecoal.tx_coalesce_usecs, \
}, \
{ \
.name = "tx-frames", \
.type = CMDL_S32, \
.wanted_val = &coal_tx_frames_wanted, \
.ioctl_val = &__ecoal.tx_max_coalesced_frames, \
}, \
{ \
.name = "tx-usecs-irq", \
.type = CMDL_S32, \
.wanted_val = &coal_tx_usec_irq_wanted, \
.ioctl_val = &__ecoal.tx_coalesce_usecs_irq, \
}, \
{ \
.name = "tx-frames-irq", \
.type = CMDL_S32, \
.wanted_val = &coal_tx_frames_irq_wanted, \
.ioctl_val = &__ecoal.tx_max_coalesced_frames_irq, \
}, \
{ \
.name = "rx-usecs-low", \
.type = CMDL_S32, \
.wanted_val = &coal_rx_usec_low_wanted, \
.ioctl_val = &__ecoal.rx_coalesce_usecs_low, \
}, \
{ \
.name = "rx-frames-low", \
.type = CMDL_S32, \
.wanted_val = &coal_rx_frames_low_wanted, \
.ioctl_val = &__ecoal.rx_max_coalesced_frames_low, \
}, \
{ \
.name = "tx-usecs-low", \
.type = CMDL_S32, \
.wanted_val = &coal_tx_usec_low_wanted, \
.ioctl_val = &__ecoal.tx_coalesce_usecs_low, \
}, \
{ \
.name = "tx-frames-low", \
.type = CMDL_S32, \
.wanted_val = &coal_tx_frames_low_wanted, \
.ioctl_val = &__ecoal.tx_max_coalesced_frames_low, \
}, \
{ \
.name = "rx-usecs-high", \
.type = CMDL_S32, \
.wanted_val = &coal_rx_usec_high_wanted, \
.ioctl_val = &__ecoal.rx_coalesce_usecs_high, \
}, \
{ \
.name = "rx-frames-high", \
.type = CMDL_S32, \
.wanted_val = &coal_rx_frames_high_wanted, \
.ioctl_val = &__ecoal.rx_max_coalesced_frames_high,\
}, \
{ \
.name = "tx-usecs-high", \
.type = CMDL_S32, \
.wanted_val = &coal_tx_usec_high_wanted, \
.ioctl_val = &__ecoal.tx_coalesce_usecs_high, \
}, \
{ \
.name = "tx-frames-high", \
.type = CMDL_S32, \
.wanted_val = &coal_tx_frames_high_wanted, \
.ioctl_val = &__ecoal.tx_max_coalesced_frames_high,\
}, \
}
static int do_scoalesce(struct cmd_context *ctx)
{
struct ethtool_coalesce ecoal;
int gcoalesce_changed = 0;
DECLARE_COALESCE_OPTION_VARS();
struct cmdline_info cmdline_coalesce[] = COALESCE_CMDLINE_INFO(ecoal);
int err, changed = 0;
parse_generic_cmdline(ctx, &gcoalesce_changed,
cmdline_coalesce, ARRAY_SIZE(cmdline_coalesce));
ecoal.cmd = ETHTOOL_GCOALESCE;
err = send_ioctl(ctx, &ecoal);
if (err) {
perror("Cannot get device coalesce settings");
return 76;
}
do_generic_set(cmdline_coalesce, ARRAY_SIZE(cmdline_coalesce),
&changed);
if (!changed) {
fprintf(stderr, "no coalesce parameters changed, aborting\n");
return 80;
}
ecoal.cmd = ETHTOOL_SCOALESCE;
err = send_ioctl(ctx, &ecoal);
if (err) {
perror("Cannot set device coalesce parameters");
return 81;
}
return 0;
}
static struct feature_state *
get_features(struct cmd_context *ctx, const struct feature_defs *defs)
{
struct feature_state *state;
struct ethtool_value eval;
int err, allfail = 1;
u32 value;
int i;
state = malloc(sizeof(*state) +
FEATURE_BITS_TO_BLOCKS(defs->n_features) *
sizeof(state->features.features[0]));
if (!state)
return NULL;
state->off_flags = 0;
for (i = 0; i < OFF_FLAG_DEF_SIZE; i++) {
value = off_flag_def[i].value;
if (!off_flag_def[i].get_cmd)
continue;
eval.cmd = off_flag_def[i].get_cmd;
err = send_ioctl(ctx, &eval);
if (err) {
if (errno == EOPNOTSUPP &&
off_flag_def[i].get_cmd == ETHTOOL_GUFO)
continue;
fprintf(stderr,
"Cannot get device %s settings: %m\n",
off_flag_def[i].long_name);
} else {
if (eval.data)
state->off_flags |= value;
allfail = 0;
}
}
eval.cmd = ETHTOOL_GFLAGS;
err = send_ioctl(ctx, &eval);
if (err) {
perror("Cannot get device flags");
} else {
state->off_flags |= eval.data & ETH_FLAG_EXT_MASK;
allfail = 0;
}
if (defs->n_features) {
state->features.cmd = ETHTOOL_GFEATURES;
state->features.size = FEATURE_BITS_TO_BLOCKS(defs->n_features);
err = send_ioctl(ctx, &state->features);
if (err)
perror("Cannot get device generic features");
else
allfail = 0;
}
if (allfail) {
free(state);
return NULL;
}
return state;
}
static int do_gfeatures(struct cmd_context *ctx)
{
struct feature_defs *defs;
struct feature_state *features;
if (ctx->argc != 0)
exit_bad_args();
defs = get_feature_defs(ctx);
if (!defs) {
perror("Cannot get device feature names");
return 1;
}
fprintf(stdout, "Features for %s:\n", ctx->devname);
features = get_features(ctx, defs);
if (!features) {
fprintf(stdout, "no feature info available\n");
free(defs);
return 1;
}
dump_features(defs, features, NULL);
free(features);
free(defs);
return 0;
}
static int do_sfeatures(struct cmd_context *ctx)
{
struct feature_defs *defs;
int any_changed = 0, any_mismatch = 0;
u32 off_flags_wanted = 0;
u32 off_flags_mask = 0;
struct ethtool_sfeatures *efeatures = NULL;
struct feature_state *old_state = NULL;
struct feature_state *new_state = NULL;
struct cmdline_info *cmdline_features;
struct ethtool_value eval;
unsigned int i, j;
int err, rc;
defs = get_feature_defs(ctx);
if (!defs) {
perror("Cannot get device feature names");
return 1;
}
if (defs->n_features) {
efeatures = malloc(sizeof(*efeatures) +
FEATURE_BITS_TO_BLOCKS(defs->n_features) *
sizeof(efeatures->features[0]));
if (!efeatures) {
perror("Cannot parse arguments");
rc = 1;
goto err;
}
efeatures->cmd = ETHTOOL_SFEATURES;
efeatures->size = FEATURE_BITS_TO_BLOCKS(defs->n_features);
memset(efeatures->features, 0,
FEATURE_BITS_TO_BLOCKS(defs->n_features) *
sizeof(efeatures->features[0]));
}
/* Generate cmdline_info for legacy flags and kernel-named
* features, and parse our arguments.
*/
cmdline_features = calloc(2 * OFF_FLAG_DEF_SIZE + defs->n_features,
sizeof(cmdline_features[0]));
if (!cmdline_features) {
perror("Cannot parse arguments");
rc = 1;
goto err;
}
j = 0;
for (i = 0; i < OFF_FLAG_DEF_SIZE; i++) {
flag_to_cmdline_info(off_flag_def[i].short_name,
off_flag_def[i].value,
&off_flags_wanted, &off_flags_mask,
&cmdline_features[j++]);
flag_to_cmdline_info(off_flag_def[i].long_name,
off_flag_def[i].value,
&off_flags_wanted, &off_flags_mask,
&cmdline_features[j++]);
}
for (i = 0; i < defs->n_features; i++)
flag_to_cmdline_info(
defs->def[i].name, FEATURE_FIELD_FLAG(i),
&FEATURE_WORD(efeatures->features, i, requested),
&FEATURE_WORD(efeatures->features, i, valid),
&cmdline_features[j++]);
parse_generic_cmdline(ctx, &any_changed, cmdline_features,
2 * OFF_FLAG_DEF_SIZE + defs->n_features);
free(cmdline_features);
if (!any_changed) {
fprintf(stdout, "no features changed\n");
rc = 0;
goto err;
}
old_state = get_features(ctx, defs);
if (!old_state) {
rc = 1;
goto err;
}
if (efeatures) {
/* For each offload that the user specified, update any
* related features that the user did not specify and that
* are not fixed. Warn if all related features are fixed.
*/
for (i = 0; i < OFF_FLAG_DEF_SIZE; i++) {
int fixed = 1;
if (!(off_flags_mask & off_flag_def[i].value))
continue;
for (j = 0; j < defs->n_features; j++) {
if (defs->def[j].off_flag_index != (int)i ||
!FEATURE_BIT_IS_SET(
old_state->features.features,
j, available) ||
FEATURE_BIT_IS_SET(
old_state->features.features,
j, never_changed))
continue;
fixed = 0;
if (!FEATURE_BIT_IS_SET(efeatures->features,
j, valid)) {
FEATURE_BIT_SET(efeatures->features,
j, valid);
if (off_flags_wanted &
off_flag_def[i].value)
FEATURE_BIT_SET(
efeatures->features,
j, requested);
}
}
if (fixed)
fprintf(stderr, "Cannot change %s\n",
off_flag_def[i].long_name);
}
err = send_ioctl(ctx, efeatures);
if (err < 0) {
perror("Cannot set device feature settings");
rc = 1;
goto err;
}
} else {
for (i = 0; i < OFF_FLAG_DEF_SIZE; i++) {
if (!off_flag_def[i].set_cmd)
continue;
if (off_flags_mask & off_flag_def[i].value) {
eval.cmd = off_flag_def[i].set_cmd;
eval.data = !!(off_flags_wanted &
off_flag_def[i].value);
err = send_ioctl(ctx, &eval);
if (err) {
fprintf(stderr,
"Cannot set device %s settings: %m\n",
off_flag_def[i].long_name);
rc = 1;
goto err;
}
}
}
if (off_flags_mask & ETH_FLAG_EXT_MASK) {
eval.cmd = ETHTOOL_SFLAGS;
eval.data = (old_state->off_flags & ~off_flags_mask &
ETH_FLAG_EXT_MASK);
eval.data |= off_flags_wanted & ETH_FLAG_EXT_MASK;
err = send_ioctl(ctx, &eval);
if (err) {
perror("Cannot set device flag settings");
rc = 92;
goto err;
}
}
}
/* Compare new state with requested state */
new_state = get_features(ctx, defs);
if (!new_state) {
rc = 1;
goto err;
}
any_changed = new_state->off_flags != old_state->off_flags;
any_mismatch = (new_state->off_flags !=
((old_state->off_flags & ~off_flags_mask) |
off_flags_wanted));
for (i = 0; i < FEATURE_BITS_TO_BLOCKS(defs->n_features); i++) {
if (new_state->features.features[i].active !=
old_state->features.features[i].active)
any_changed = 1;
if (new_state->features.features[i].active !=
((old_state->features.features[i].active &
~efeatures->features[i].valid) |
efeatures->features[i].requested))
any_mismatch = 1;
}
if (any_mismatch) {
if (!any_changed) {
fprintf(stderr,
"Could not change any device features\n");
rc = 1;
goto err;
}
printf("Actual changes:\n");
dump_features(defs, new_state, old_state);
}
rc = 0;
err:
free(new_state);
free(old_state);
free(defs);
free(efeatures);
return rc;
}
static struct ethtool_link_usettings *
do_ioctl_glinksettings(struct cmd_context *ctx)
{
int err;
struct {
struct ethtool_link_settings req;
__u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
} ecmd;
struct ethtool_link_usettings *link_usettings;
unsigned int u32_offs;
/* Handshake with kernel to determine number of words for link
* mode bitmaps. When requested number of bitmap words is not
* the one expected by kernel, the latter returns the integer
* opposite of what it is expecting. We request length 0 below
* (aka. invalid bitmap length) to get this info.
*/
memset(&ecmd, 0, sizeof(ecmd));
ecmd.req.cmd = ETHTOOL_GLINKSETTINGS;
err = send_ioctl(ctx, &ecmd);
if (err < 0)
return NULL;
/* see above: we expect a strictly negative value from kernel.
*/
if (ecmd.req.link_mode_masks_nwords >= 0
|| ecmd.req.cmd != ETHTOOL_GLINKSETTINGS)
return NULL;
/* got the real ecmd.req.link_mode_masks_nwords,
* now send the real request
*/
ecmd.req.cmd = ETHTOOL_GLINKSETTINGS;
ecmd.req.link_mode_masks_nwords = -ecmd.req.link_mode_masks_nwords;
err = send_ioctl(ctx, &ecmd);
if (err < 0)
return NULL;
if (ecmd.req.link_mode_masks_nwords <= 0
|| ecmd.req.cmd != ETHTOOL_GLINKSETTINGS)
return NULL;
/* Convert to usettings struct */
link_usettings = calloc(1, sizeof(*link_usettings));
if (link_usettings == NULL)
return NULL;
memcpy(&link_usettings->base, &ecmd.req, sizeof(link_usettings->base));
link_usettings->deprecated.transceiver = ecmd.req.transceiver;
/* copy link mode bitmaps */
u32_offs = 0;
memcpy(link_usettings->link_modes.supported,
&ecmd.link_mode_data[u32_offs],
4 * ecmd.req.link_mode_masks_nwords);
u32_offs += ecmd.req.link_mode_masks_nwords;
memcpy(link_usettings->link_modes.advertising,
&ecmd.link_mode_data[u32_offs],
4 * ecmd.req.link_mode_masks_nwords);
u32_offs += ecmd.req.link_mode_masks_nwords;
memcpy(link_usettings->link_modes.lp_advertising,
&ecmd.link_mode_data[u32_offs],
4 * ecmd.req.link_mode_masks_nwords);
return link_usettings;
}
static int
do_ioctl_slinksettings(struct cmd_context *ctx,
const struct ethtool_link_usettings *link_usettings)
{
struct {
struct ethtool_link_settings req;
__u32 link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
} ecmd;
unsigned int u32_offs;
/* refuse to send ETHTOOL_SLINKSETTINGS ioctl if
* link_usettings was retrieved with ETHTOOL_GSET
*/
if (link_usettings->base.cmd != ETHTOOL_GLINKSETTINGS)
return -1;
/* refuse to send ETHTOOL_SLINKSETTINGS ioctl if deprecated fields
* were set
*/
if (link_usettings->deprecated.transceiver)
return -1;
if (link_usettings->base.link_mode_masks_nwords <= 0)
return -1;
memcpy(&ecmd.req, &link_usettings->base, sizeof(ecmd.req));
ecmd.req.cmd = ETHTOOL_SLINKSETTINGS;
/* copy link mode bitmaps */
u32_offs = 0;
memcpy(&ecmd.link_mode_data[u32_offs],
link_usettings->link_modes.supported,
4 * ecmd.req.link_mode_masks_nwords);
u32_offs += ecmd.req.link_mode_masks_nwords;
memcpy(&ecmd.link_mode_data[u32_offs],
link_usettings->link_modes.advertising,
4 * ecmd.req.link_mode_masks_nwords);
u32_offs += ecmd.req.link_mode_masks_nwords;
memcpy(&ecmd.link_mode_data[u32_offs],
link_usettings->link_modes.lp_advertising,
4 * ecmd.req.link_mode_masks_nwords);
return send_ioctl(ctx, &ecmd);
}
static struct ethtool_link_usettings *
do_ioctl_gset(struct cmd_context *ctx)
{
int err;
struct ethtool_cmd ecmd;
struct ethtool_link_usettings *link_usettings;
memset(&ecmd, 0, sizeof(ecmd));
ecmd.cmd = ETHTOOL_GSET;
err = send_ioctl(ctx, &ecmd);
if (err < 0)
return NULL;
link_usettings = calloc(1, sizeof(*link_usettings));
if (link_usettings == NULL)
return NULL;
/* remember that ETHTOOL_GSET was used */
link_usettings->base.cmd = ETHTOOL_GSET;
link_usettings->base.link_mode_masks_nwords = 1;
link_usettings->link_modes.supported[0] = ecmd.supported;
link_usettings->link_modes.advertising[0] = ecmd.advertising;
link_usettings->link_modes.lp_advertising[0] = ecmd.lp_advertising;
link_usettings->base.speed = ethtool_cmd_speed(&ecmd);
link_usettings->base.duplex = ecmd.duplex;
link_usettings->base.port = ecmd.port;
link_usettings->base.phy_address = ecmd.phy_address;
link_usettings->deprecated.transceiver = ecmd.transceiver;
link_usettings->base.autoneg = ecmd.autoneg;
link_usettings->base.mdio_support = ecmd.mdio_support;
/* ignored (fully deprecated): maxrxpkt, maxtxpkt */
link_usettings->base.eth_tp_mdix = ecmd.eth_tp_mdix;
link_usettings->base.eth_tp_mdix_ctrl = ecmd.eth_tp_mdix_ctrl;
return link_usettings;
}
static bool ethtool_link_mode_is_backward_compatible(const u32 *mask)
{
unsigned int i;
for (i = 1; i < ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32; ++i)
if (mask[i])
return false;
return true;
}
static int
do_ioctl_sset(struct cmd_context *ctx,
const struct ethtool_link_usettings *link_usettings)
{
struct ethtool_cmd ecmd;
/* refuse to send ETHTOOL_SSET ioctl if link_usettings was
* retrieved with ETHTOOL_GLINKSETTINGS
*/
if (link_usettings->base.cmd != ETHTOOL_GSET)
return -1;
if (link_usettings->base.link_mode_masks_nwords <= 0)
return -1;
/* refuse to sset if any bit > 31 is set */
if (!ethtool_link_mode_is_backward_compatible(
link_usettings->link_modes.supported))
return -1;
if (!ethtool_link_mode_is_backward_compatible(
link_usettings->link_modes.advertising))
return -1;
if (!ethtool_link_mode_is_backward_compatible(
link_usettings->link_modes.lp_advertising))
return -1;
memset(&ecmd, 0, sizeof(ecmd));
ecmd.cmd = ETHTOOL_SSET;
ecmd.supported = link_usettings->link_modes.supported[0];
ecmd.advertising = link_usettings->link_modes.advertising[0];
ecmd.lp_advertising = link_usettings->link_modes.lp_advertising[0];
ethtool_cmd_speed_set(&ecmd, link_usettings->base.speed);
ecmd.duplex = link_usettings->base.duplex;
ecmd.port = link_usettings->base.port;
ecmd.phy_address = link_usettings->base.phy_address;
ecmd.transceiver = link_usettings->deprecated.transceiver;
ecmd.autoneg = link_usettings->base.autoneg;
ecmd.mdio_support = link_usettings->base.mdio_support;
/* ignored (fully deprecated): maxrxpkt, maxtxpkt */
ecmd.eth_tp_mdix = link_usettings->base.eth_tp_mdix;
ecmd.eth_tp_mdix_ctrl = link_usettings->base.eth_tp_mdix_ctrl;
return send_ioctl(ctx, &ecmd);
}
static int do_gset(struct cmd_context *ctx)
{
int err;
struct ethtool_link_usettings *link_usettings;
struct ethtool_wolinfo wolinfo;
struct ethtool_value edata;
int allfail = 1;
if (ctx->argc != 0)
exit_bad_args();
fprintf(stdout, "Settings for %s:\n", ctx->devname);
link_usettings = do_ioctl_glinksettings(ctx);
if (link_usettings == NULL)
link_usettings = do_ioctl_gset(ctx);
if (link_usettings != NULL) {
err = dump_link_usettings(link_usettings);
free(link_usettings);
if (err)
return err;
allfail = 0;
} else if (errno != EOPNOTSUPP) {
perror("Cannot get device settings");
}
wolinfo.cmd = ETHTOOL_GWOL;
err = send_ioctl(ctx, &wolinfo);
if (err == 0) {
err = dump_wol(&wolinfo);
if (err)
return err;
allfail = 0;
} else if (errno != EOPNOTSUPP) {
perror("Cannot get wake-on-lan settings");
}
edata.cmd = ETHTOOL_GMSGLVL;
err = send_ioctl(ctx, &edata);
if (err == 0) {
fprintf(stdout, " Current message level: 0x%08x (%d)\n"
" ",
edata.data, edata.data);
print_flags(flags_msglvl, n_flags_msglvl, edata.data);
fprintf(stdout, "\n");
allfail = 0;
} else if (errno != EOPNOTSUPP) {
perror("Cannot get message level");
}
edata.cmd = ETHTOOL_GLINK;
err = send_ioctl(ctx, &edata);
if (err == 0) {
fprintf(stdout, " Link detected: %s\n",
edata.data ? "yes":"no");
allfail = 0;
} else if (errno != EOPNOTSUPP) {
perror("Cannot get link status");
}
if (allfail) {
fprintf(stdout, "No data available\n");
return 75;
}
return 0;
}
static int do_sset(struct cmd_context *ctx)
{
int speed_wanted = -1;
int duplex_wanted = -1;
int port_wanted = -1;
int mdix_wanted = -1;
int autoneg_wanted = -1;
int phyad_wanted = -1;
int xcvr_wanted = -1;
u32 *full_advertising_wanted = NULL;
u32 *advertising_wanted = NULL;
ETHTOOL_DECLARE_LINK_MODE_MASK(mask_full_advertising_wanted);
ETHTOOL_DECLARE_LINK_MODE_MASK(mask_advertising_wanted);
int gset_changed = 0; /* did anything in GSET change? */
u32 wol_wanted = 0;
int wol_change = 0;
u8 sopass_wanted[SOPASS_MAX];
int sopass_change = 0;
int gwol_changed = 0; /* did anything in GWOL change? */
int msglvl_changed = 0;
u32 msglvl_wanted = 0;
u32 msglvl_mask = 0;
struct cmdline_info cmdline_msglvl[n_flags_msglvl];
unsigned int argc = ctx->argc;
char **argp = ctx->argp;
unsigned int i;
int err = 0;
for (i = 0; i < n_flags_msglvl; i++)
flag_to_cmdline_info(flags_msglvl[i].name,
flags_msglvl[i].value,
&msglvl_wanted, &msglvl_mask,
&cmdline_msglvl[i]);
for (i = 0; i < argc; i++) {
if (!strcmp(argp[i], "speed")) {
gset_changed = 1;
i += 1;
if (i >= argc)
exit_bad_args();
speed_wanted = get_int(argp[i], 10);
} else if (!strcmp(argp[i], "duplex")) {
gset_changed = 1;
i += 1;
if (i >= argc)
exit_bad_args();
if (!strcmp(argp[i], "half"))
duplex_wanted = DUPLEX_HALF;
else if (!strcmp(argp[i], "full"))
duplex_wanted = DUPLEX_FULL;
else
exit_bad_args();
} else if (!strcmp(argp[i], "port")) {
gset_changed = 1;
i += 1;
if (i >= argc)
exit_bad_args();
if (!strcmp(argp[i], "tp"))
port_wanted = PORT_TP;
else if (!strcmp(argp[i], "aui"))
port_wanted = PORT_AUI;
else if (!strcmp(argp[i], "bnc"))
port_wanted = PORT_BNC;
else if (!strcmp(argp[i], "mii"))
port_wanted = PORT_MII;
else if (!strcmp(argp[i], "fibre"))
port_wanted = PORT_FIBRE;
else
exit_bad_args();
} else if (!strcmp(argp[i], "mdix")) {
gset_changed = 1;
i += 1;
if (i >= argc)
exit_bad_args();
if (!strcmp(argp[i], "auto"))
mdix_wanted = ETH_TP_MDI_AUTO;
else if (!strcmp(argp[i], "on"))
mdix_wanted = ETH_TP_MDI_X;
else if (!strcmp(argp[i], "off"))
mdix_wanted = ETH_TP_MDI;
else
exit_bad_args();
} else if (!strcmp(argp[i], "autoneg")) {
i += 1;
if (i >= argc)
exit_bad_args();
if (!strcmp(argp[i], "on")) {
gset_changed = 1;
autoneg_wanted = AUTONEG_ENABLE;
} else if (!strcmp(argp[i], "off")) {
gset_changed = 1;
autoneg_wanted = AUTONEG_DISABLE;
} else {
exit_bad_args();
}
} else if (!strcmp(argp[i], "advertise")) {
gset_changed = 1;
i += 1;
if (i >= argc)
exit_bad_args();
if (parse_hex_u32_bitmap(
argp[i],
ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NBITS,
mask_full_advertising_wanted))
exit_bad_args();
full_advertising_wanted = mask_full_advertising_wanted;
} else if (!strcmp(argp[i], "phyad")) {
gset_changed = 1;
i += 1;
if (i >= argc)
exit_bad_args();
phyad_wanted = get_int(argp[i], 0);
} else if (!strcmp(argp[i], "xcvr")) {
gset_changed = 1;
i += 1;
if (i >= argc)
exit_bad_args();
if (!strcmp(argp[i], "internal"))
xcvr_wanted = XCVR_INTERNAL;
else if (!strcmp(argp[i], "external"))
xcvr_wanted = XCVR_EXTERNAL;
else
exit_bad_args();
} else if (!strcmp(argp[i], "wol")) {
gwol_changed = 1;
i++;
if (i >= argc)
exit_bad_args();
if (parse_wolopts(argp[i], &wol_wanted) < 0)
exit_bad_args();
wol_change = 1;
} else if (!strcmp(argp[i], "sopass")) {
gwol_changed = 1;
i++;
if (i >= argc)
exit_bad_args();
get_mac_addr(argp[i], sopass_wanted);
sopass_change = 1;
} else if (!strcmp(argp[i], "msglvl")) {
i++;
if (i >= argc)
exit_bad_args();
if (isdigit((unsigned char)argp[i][0])) {
msglvl_changed = 1;
msglvl_mask = ~0;
msglvl_wanted =
get_uint_range(argp[i], 0,
0xffffffff);
} else {
ctx->argc -= i;
ctx->argp += i;
parse_generic_cmdline(
ctx, &msglvl_changed,
cmdline_msglvl,
ARRAY_SIZE(cmdline_msglvl));
break;
}
} else if (!strcmp(argp[i], "master-slave")) {
exit_nlonly_param(argp[i]);
} else {
exit_bad_args();
}
}
if (full_advertising_wanted == NULL) {
/* User didn't supply a full advertisement bitfield:
* construct one from the specified speed and duplex.
*/
int adv_bit = -1;
if (speed_wanted == SPEED_10 && duplex_wanted == DUPLEX_HALF)
adv_bit = ETHTOOL_LINK_MODE_10baseT_Half_BIT;
else if (speed_wanted == SPEED_10 &&
duplex_wanted == DUPLEX_FULL)
adv_bit = ETHTOOL_LINK_MODE_10baseT_Full_BIT;
else if (speed_wanted == SPEED_100 &&
duplex_wanted == DUPLEX_HALF)
adv_bit = ETHTOOL_LINK_MODE_100baseT_Half_BIT;
else if (speed_wanted == SPEED_100 &&
duplex_wanted == DUPLEX_FULL)
adv_bit = ETHTOOL_LINK_MODE_100baseT_Full_BIT;
else if (speed_wanted == SPEED_1000 &&
duplex_wanted == DUPLEX_HALF)
adv_bit = ETHTOOL_LINK_MODE_1000baseT_Half_BIT;
else if (speed_wanted == SPEED_1000 &&
duplex_wanted == DUPLEX_FULL)
adv_bit = ETHTOOL_LINK_MODE_1000baseT_Full_BIT;
else if (speed_wanted == SPEED_2500 &&
duplex_wanted == DUPLEX_FULL)
adv_bit = ETHTOOL_LINK_MODE_2500baseX_Full_BIT;
else if (speed_wanted == SPEED_10000 &&
duplex_wanted == DUPLEX_FULL)
adv_bit = ETHTOOL_LINK_MODE_10000baseT_Full_BIT;
if (adv_bit >= 0) {
advertising_wanted = mask_advertising_wanted;
ethtool_link_mode_zero(advertising_wanted);
ethtool_link_mode_set_bit(
adv_bit, advertising_wanted);
}
/* otherwise: auto negotiate without forcing,
* all supported speed will be assigned below
*/
}
if (gset_changed) {
struct ethtool_link_usettings *link_usettings;
link_usettings = do_ioctl_glinksettings(ctx);
if (link_usettings == NULL)
link_usettings = do_ioctl_gset(ctx);
else
memset(&link_usettings->deprecated, 0,
sizeof(link_usettings->deprecated));
if (link_usettings == NULL) {
perror("Cannot get current device settings");
err = -1;
} else {
/* Change everything the user specified. */
if (speed_wanted != -1)
link_usettings->base.speed = speed_wanted;
if (duplex_wanted != -1)
link_usettings->base.duplex = duplex_wanted;
if (port_wanted != -1)
link_usettings->base.port = port_wanted;
if (mdix_wanted != -1) {
/* check driver supports MDI-X */
if (link_usettings->base.eth_tp_mdix_ctrl
!= ETH_TP_MDI_INVALID)
link_usettings->base.eth_tp_mdix_ctrl
= mdix_wanted;
else
fprintf(stderr,
"setting MDI not supported\n");
}
if (autoneg_wanted != -1)
link_usettings->base.autoneg = autoneg_wanted;
if (phyad_wanted != -1)
link_usettings->base.phy_address = phyad_wanted;
if (xcvr_wanted != -1)
link_usettings->deprecated.transceiver
= xcvr_wanted;
/* XXX If the user specified speed or duplex
* then we should mask the advertised modes
* accordingly. For now, warn that we aren't
* doing that.
*/
if ((speed_wanted != -1 || duplex_wanted != -1) &&
link_usettings->base.autoneg &&
advertising_wanted == NULL) {
fprintf(stderr, "Cannot advertise");
if (speed_wanted >= 0)
fprintf(stderr, " speed %d",
speed_wanted);
if (duplex_wanted >= 0)
fprintf(stderr, " duplex %s",
duplex_wanted ?
"full" : "half");
fprintf(stderr, "\n");
}
if (autoneg_wanted == AUTONEG_ENABLE &&
advertising_wanted == NULL &&
full_advertising_wanted == NULL) {
unsigned int i;
/* Auto negotiation enabled, but with
* unspecified speed and duplex: enable all
* supported speeds and duplexes.
*/
ethtool_link_mode_for_each_u32(i) {
u32 sup = link_usettings->link_modes.supported[i];
u32 *adv = link_usettings->link_modes.advertising + i;
*adv = ((*adv & ~all_advertised_modes[i])
| (sup & all_advertised_modes[i]));
}
/* If driver supports unknown flags, we cannot
* be sure that we enable all link modes.
*/
ethtool_link_mode_for_each_u32(i) {
u32 sup = link_usettings->link_modes.supported[i];
if ((sup & all_advertised_flags[i]) != sup) {
fprintf(stderr, "Driver supports one or more unknown flags\n");
break;
}
}
} else if (advertising_wanted != NULL) {
unsigned int i;
/* Enable all requested modes */
ethtool_link_mode_for_each_u32(i) {
u32 *adv = link_usettings->link_modes.advertising + i;
*adv = ((*adv & ~all_advertised_modes[i])
| advertising_wanted[i]);
}
} else if (full_advertising_wanted != NULL) {
ethtool_link_mode_copy(
link_usettings->link_modes.advertising,
full_advertising_wanted);
}
/* Try to perform the update. */
if (link_usettings->base.cmd == ETHTOOL_GLINKSETTINGS)
err = do_ioctl_slinksettings(ctx,
link_usettings);
else
err = do_ioctl_sset(ctx, link_usettings);
free(link_usettings);
if (err < 0)
perror("Cannot set new settings");
}
if (err < 0) {
if (speed_wanted != -1)
fprintf(stderr, " not setting speed\n");
if (duplex_wanted != -1)
fprintf(stderr, " not setting duplex\n");
if (port_wanted != -1)
fprintf(stderr, " not setting port\n");
if (autoneg_wanted != -1)
fprintf(stderr, " not setting autoneg\n");
if (phyad_wanted != -1)
fprintf(stderr, " not setting phy_address\n");
if (xcvr_wanted != -1)
fprintf(stderr, " not setting transceiver\n");
if (mdix_wanted != -1)
fprintf(stderr, " not setting mdix\n");
}
}
if (gwol_changed) {
struct ethtool_wolinfo wol;
wol.cmd = ETHTOOL_GWOL;
err = send_ioctl(ctx, &wol);
if (err < 0) {
perror("Cannot get current wake-on-lan settings");
} else {
/* Change everything the user specified. */
if (wol_change)
wol.wolopts = wol_wanted;
if (sopass_change) {
int i;
for (i = 0; i < SOPASS_MAX; i++)
wol.sopass[i] = sopass_wanted[i];
}
/* Try to perform the update. */
wol.cmd = ETHTOOL_SWOL;
err = send_ioctl(ctx, &wol);
if (err < 0)
perror("Cannot set new wake-on-lan settings");
}
if (err < 0) {
if (wol_change)
fprintf(stderr, " not setting wol\n");
if (sopass_change)
fprintf(stderr, " not setting sopass\n");
}
}
if (msglvl_changed) {
struct ethtool_value edata;
edata.cmd = ETHTOOL_GMSGLVL;
err = send_ioctl(ctx, &edata);
if (err < 0) {
perror("Cannot get msglvl");
} else {
edata.cmd = ETHTOOL_SMSGLVL;
edata.data = ((edata.data & ~msglvl_mask) |
msglvl_wanted);
err = send_ioctl(ctx, &edata);
if (err < 0)
perror("Cannot set new msglvl");
}
}
return 0;
}
static int do_gregs(struct cmd_context *ctx)
{
int gregs_changed = 0;
int gregs_dump_raw = 0;
int gregs_dump_hex = 0;
char *gregs_dump_file = NULL;
struct cmdline_info cmdline_gregs[] = {
{
.name = "raw",
.type = CMDL_BOOL,
.wanted_val = &gregs_dump_raw,
},
{
.name = "hex",
.type = CMDL_BOOL,
.wanted_val = &gregs_dump_hex,
},
{
.name = "file",
.type = CMDL_STR,
.wanted_val = &gregs_dump_file,
},
};
int err;
struct ethtool_drvinfo drvinfo;
struct ethtool_regs *regs;
parse_generic_cmdline(ctx, &gregs_changed,
cmdline_gregs, ARRAY_SIZE(cmdline_gregs));
drvinfo.cmd = ETHTOOL_GDRVINFO;
err = send_ioctl(ctx, &drvinfo);
if (err < 0) {
perror("Cannot get driver information");
return 72;
}
regs = calloc(1, sizeof(*regs)+drvinfo.regdump_len);
if (!regs) {
perror("Cannot allocate memory for register dump");
return 73;
}
regs->cmd = ETHTOOL_GREGS;
regs->len = drvinfo.regdump_len;
err = send_ioctl(ctx, regs);
if (err < 0) {
perror("Cannot get register dump");
free(regs);
return 74;
}
if (!gregs_dump_raw && gregs_dump_file != NULL) {
/* overwrite reg values from file dump */
FILE *f = fopen(gregs_dump_file, "r");
struct ethtool_regs *nregs;
struct stat st;
size_t nread;
if (!f || fstat(fileno(f), &st) < 0) {
fprintf(stderr, "Can't open '%s': %s\n",
gregs_dump_file, strerror(errno));
if (f)
fclose(f);
free(regs);
return 75;
}
nregs = realloc(regs, sizeof(*regs) + st.st_size);
if (!nregs) {
perror("Cannot allocate memory for register dump");
free(regs); /* was not freed by realloc */
return 73;
}
regs = nregs;
regs->len = st.st_size;
nread = fread(regs->data, regs->len, 1, f);
fclose(f);
if (nread != 1) {
free(regs);
return 75;
}
}
if (dump_regs(gregs_dump_raw, gregs_dump_hex,
&drvinfo, regs) < 0) {
fprintf(stderr, "Cannot dump registers\n");
free(regs);
return 75;
}
free(regs);
return 0;
}
static int do_nway_rst(struct cmd_context *ctx)
{
struct ethtool_value edata;
int err;
if (ctx->argc != 0)
exit_bad_args();
edata.cmd = ETHTOOL_NWAY_RST;
err = send_ioctl(ctx, &edata);
if (err < 0)
perror("Cannot restart autonegotiation");
return err;
}
static int do_geeprom(struct cmd_context *ctx)
{
int geeprom_changed = 0;
int geeprom_dump_raw = 0;
u32 geeprom_offset = 0;
u32 geeprom_length = 0;
int geeprom_length_seen = 0;
struct cmdline_info cmdline_geeprom[] = {
{
.name = "offset",
.type = CMDL_U32,
.wanted_val = &geeprom_offset,
},
{
.name = "length",
.type = CMDL_U32,
.wanted_val = &geeprom_length,
.seen_val = &geeprom_length_seen,
},
{
.name = "raw",
.type = CMDL_BOOL,
.wanted_val = &geeprom_dump_raw,
},
};
int err;
struct ethtool_drvinfo drvinfo;
struct ethtool_eeprom *eeprom;
parse_generic_cmdline(ctx, &geeprom_changed,
cmdline_geeprom, ARRAY_SIZE(cmdline_geeprom));
drvinfo.cmd = ETHTOOL_GDRVINFO;
err = send_ioctl(ctx, &drvinfo);
if (err < 0) {
perror("Cannot get driver information");
return 74;
}
if (!geeprom_length_seen)
geeprom_length = drvinfo.eedump_len;
if (drvinfo.eedump_len < geeprom_offset + geeprom_length)
geeprom_length = drvinfo.eedump_len - geeprom_offset;
eeprom = calloc(1, sizeof(*eeprom)+geeprom_length);
if (!eeprom) {
perror("Cannot allocate memory for EEPROM data");
return 75;
}
eeprom->cmd = ETHTOOL_GEEPROM;
eeprom->len = geeprom_length;
eeprom->offset = geeprom_offset;
err = send_ioctl(ctx, eeprom);
if (err < 0) {
perror("Cannot get EEPROM data");
free(eeprom);
return 74;
}
err = dump_eeprom(geeprom_dump_raw, &drvinfo, eeprom);
free(eeprom);
return err;
}
static int do_seeprom(struct cmd_context *ctx)
{
int seeprom_changed = 0;
u32 seeprom_magic = 0;
u32 seeprom_length = 0;
u32 seeprom_offset = 0;
u8 seeprom_value = 0;
int seeprom_length_seen = 0;
int seeprom_value_seen = 0;
struct cmdline_info cmdline_seeprom[] = {
{
.name = "magic",
.type = CMDL_U32,
.wanted_val = &seeprom_magic,
},
{
.name = "offset",
.type = CMDL_U32,
.wanted_val = &seeprom_offset,
},
{
.name = "length",
.type = CMDL_U32,
.wanted_val = &seeprom_length,
.seen_val = &seeprom_length_seen,
},
{
.name = "value",
.type = CMDL_U8,
.wanted_val = &seeprom_value,
.seen_val = &seeprom_value_seen,
},
};
int err;
struct ethtool_drvinfo drvinfo;
struct ethtool_eeprom *eeprom;
parse_generic_cmdline(ctx, &seeprom_changed,
cmdline_seeprom, ARRAY_SIZE(cmdline_seeprom));
drvinfo.cmd = ETHTOOL_GDRVINFO;
err = send_ioctl(ctx, &drvinfo);
if (err < 0) {
perror("Cannot get driver information");
return 74;
}
if (seeprom_value_seen && !seeprom_length_seen)
seeprom_length = 1;
else if (!seeprom_length_seen)
seeprom_length = drvinfo.eedump_len;
if (seeprom_value_seen && (seeprom_length != 1)) {
fprintf(stderr, "value requires length 1\n");
return 1;
}
if (drvinfo.eedump_len < seeprom_offset + seeprom_length) {
fprintf(stderr, "offset & length out of bounds\n");
return 1;
}
eeprom = calloc(1, sizeof(*eeprom)+seeprom_length);
if (!eeprom) {
perror("Cannot allocate memory for EEPROM data");
return 75;
}
eeprom->cmd = ETHTOOL_SEEPROM;
eeprom->len = seeprom_length;
eeprom->offset = seeprom_offset;
eeprom->magic = seeprom_magic;
eeprom->data[0] = seeprom_value;
/* Multi-byte write: read input from stdin */
if (!seeprom_value_seen) {
if (fread(eeprom->data, eeprom->len, 1, stdin) != 1) {
fprintf(stderr, "not enough data from stdin\n");
free(eeprom);
return 75;
}
if ((fgetc(stdin) != EOF) || !feof(stdin)) {
fprintf(stderr, "too much data from stdin\n");
free(eeprom);
return 75;
}
}
err = send_ioctl(ctx, eeprom);
if (err < 0) {
perror("Cannot set EEPROM data");
err = 87;
}
free(eeprom);
return err;
}
static int do_test(struct cmd_context *ctx)
{
enum {
ONLINE = 0,
OFFLINE,
EXTERNAL_LB,
} test_type;
int err;
struct ethtool_test *test;
struct ethtool_gstrings *strings;
if (ctx->argc > 1)
exit_bad_args();
if (ctx->argc == 1) {
if (!strcmp(ctx->argp[0], "online"))
test_type = ONLINE;
else if (!strcmp(*ctx->argp, "offline"))
test_type = OFFLINE;
else if (!strcmp(*ctx->argp, "external_lb"))
test_type = EXTERNAL_LB;
else
exit_bad_args();
} else {
test_type = OFFLINE;
}
strings = get_stringset(ctx, ETH_SS_TEST,
offsetof(struct ethtool_drvinfo, testinfo_len),
1);
if (!strings) {
perror("Cannot get strings");
return 74;
}
test = calloc(1, sizeof(*test) + strings->len * sizeof(u64));
if (!test) {
perror("Cannot allocate memory for test info");
free(strings);
return 73;
}
memset(test->data, 0, strings->len * sizeof(u64));
test->cmd = ETHTOOL_TEST;
test->len = strings->len;
if (test_type == EXTERNAL_LB)
test->flags = (ETH_TEST_FL_OFFLINE | ETH_TEST_FL_EXTERNAL_LB);
else if (test_type == OFFLINE)
test->flags = ETH_TEST_FL_OFFLINE;
else
test->flags = 0;
err = send_ioctl(ctx, test);
if (err < 0) {
perror("Cannot test");
free(test);
free(strings);
return 74;
}
err = dump_test(test, strings);
free(test);
free(strings);
return err;
}
static int do_phys_id(struct cmd_context *ctx)
{
int err;
struct ethtool_value edata;
int phys_id_time;
if (ctx->argc > 1)
exit_bad_args();
if (ctx->argc == 1)
phys_id_time = get_int(*ctx->argp, 0);
else
phys_id_time = 0;
edata.cmd = ETHTOOL_PHYS_ID;
edata.data = phys_id_time;
err = send_ioctl(ctx, &edata);
if (err < 0)
perror("Cannot identify NIC");
return err;
}
static int do_gstats(struct cmd_context *ctx, int cmd, int stringset,
const char *name)
{
struct ethtool_gstrings *strings;
struct ethtool_stats *stats;
unsigned int n_stats, sz_stats, i;
int err;
if (ctx->argc != 0)
exit_bad_args();
strings = get_stringset(ctx, stringset,
offsetof(struct ethtool_drvinfo, n_stats),
0);
if (!strings) {
perror("Cannot get stats strings information");
return 96;
}
n_stats = strings->len;
if (n_stats < 1) {
fprintf(stderr, "no stats available\n");
free(strings);
return 94;
}
sz_stats = n_stats * sizeof(u64);
stats = calloc(1, sz_stats + sizeof(struct ethtool_stats));
if (!stats) {
fprintf(stderr, "no memory available\n");
free(strings);
return 95;
}
stats->cmd = cmd;
stats->n_stats = n_stats;
err = send_ioctl(ctx, stats);
if (err < 0) {
perror("Cannot get stats information");
free(strings);
free(stats);
return 97;
}
/* todo - pretty-print the strings per-driver */
fprintf(stdout, "%s statistics:\n", name);
for (i = 0; i < n_stats; i++) {
fprintf(stdout, " %.*s: %llu\n",
ETH_GSTRING_LEN,
&strings->data[i * ETH_GSTRING_LEN],
stats->data[i]);
}
free(strings);
free(stats);
return 0;
}
static int do_gnicstats(struct cmd_context *ctx)
{
return do_gstats(ctx, ETHTOOL_GSTATS, ETH_SS_STATS, "NIC");
}
static int do_gphystats(struct cmd_context *ctx)
{
return do_gstats(ctx, ETHTOOL_GPHYSTATS, ETH_SS_PHY_STATS, "PHY");
}
static int do_srxntuple(struct cmd_context *ctx,
struct ethtool_rx_flow_spec *rx_rule_fs);
static int do_srxclass(struct cmd_context *ctx)
{
int err;
if (ctx->argc < 2)
exit_bad_args();
if (!strcmp(ctx->argp[0], "rx-flow-hash")) {
int rx_fhash_set;
u32 rx_fhash_val;
struct ethtool_rxnfc nfccmd;
bool flow_rss = false;
if (ctx->argc == 5) {
if (strcmp(ctx->argp[3], "context"))
exit_bad_args();
flow_rss = true;
nfccmd.rss_context = get_u32(ctx->argp[4], 0);
} else if (ctx->argc != 3) {
exit_bad_args();
}
rx_fhash_set = rxflow_str_to_type(ctx->argp[1]);
if (!rx_fhash_set)
exit_bad_args();
if (parse_rxfhashopts(ctx->argp[2], &rx_fhash_val) < 0)
exit_bad_args();
nfccmd.cmd = ETHTOOL_SRXFH;
nfccmd.flow_type = rx_fhash_set;
nfccmd.data = rx_fhash_val;
if (flow_rss)
nfccmd.flow_type |= FLOW_RSS;
err = send_ioctl(ctx, &nfccmd);
if (err < 0) {
perror("Cannot change RX network flow hashing options");
return 1;
}
} else if (!strcmp(ctx->argp[0], "flow-type")) {
struct ethtool_rx_flow_spec rx_rule_fs;
__u32 rss_context = 0;
ctx->argc--;
ctx->argp++;
if (rxclass_parse_ruleopts(ctx, &rx_rule_fs, &rss_context) < 0)
exit_bad_args();
/* attempt to add rule via N-tuple specifier */
err = do_srxntuple(ctx, &rx_rule_fs);
if (!err)
return 0;
/* attempt to add rule via network flow classifier */
err = rxclass_rule_ins(ctx, &rx_rule_fs, rss_context);
if (err < 0) {
fprintf(stderr, "Cannot insert"
" classification rule\n");
return 1;
}
} else if (!strcmp(ctx->argp[0], "delete")) {
int rx_class_rule_del =
get_uint_range(ctx->argp[1], 0, INT_MAX);
err = rxclass_rule_del(ctx, rx_class_rule_del);
if (err < 0) {
fprintf(stderr, "Cannot delete"
" classification rule\n");
return 1;
}
} else {
exit_bad_args();
}
return 0;
}
static int do_grxclass(struct cmd_context *ctx)
{
struct ethtool_rxnfc nfccmd;
int err;
if (ctx->argc > 0 && !strcmp(ctx->argp[0], "rx-flow-hash")) {
int rx_fhash_get;
bool flow_rss = false;
if (ctx->argc == 4) {
if (strcmp(ctx->argp[2], "context"))
exit_bad_args();
flow_rss = true;
nfccmd.rss_context = get_u32(ctx->argp[3], 0);
} else if (ctx->argc != 2) {
exit_bad_args();
}
rx_fhash_get = rxflow_str_to_type(ctx->argp[1]);
if (!rx_fhash_get)
exit_bad_args();
nfccmd.cmd = ETHTOOL_GRXFH;
nfccmd.flow_type = rx_fhash_get;
if (flow_rss)
nfccmd.flow_type |= FLOW_RSS;
err = send_ioctl(ctx, &nfccmd);
if (err < 0) {
perror("Cannot get RX network flow hashing options");
} else {
if (flow_rss)
fprintf(stdout, "For RSS context %u:\n",
nfccmd.rss_context);
dump_rxfhash(rx_fhash_get, nfccmd.data);
}
} else if (ctx->argc == 2 && !strcmp(ctx->argp[0], "rule")) {
int rx_class_rule_get =
get_uint_range(ctx->argp[1], 0, INT_MAX);
err = rxclass_rule_get(ctx, rx_class_rule_get);
if (err < 0)
fprintf(stderr, "Cannot get RX classification rule\n");
} else if (ctx->argc == 0) {
nfccmd.cmd = ETHTOOL_GRXRINGS;
err = send_ioctl(ctx, &nfccmd);
if (err < 0)
perror("Cannot get RX rings");
else
fprintf(stdout, "%d RX rings available\n",
(int)nfccmd.data);
err = rxclass_rule_getall(ctx);
if (err < 0)
fprintf(stderr, "RX classification rule retrieval failed\n");
} else {
exit_bad_args();
}
return err ? 1 : 0;
}
static int do_grxfhindir(struct cmd_context *ctx,
struct ethtool_rxnfc *ring_count)
{
struct ethtool_rxfh_indir indir_head;
struct ethtool_rxfh_indir *indir;
int err;
indir_head.cmd = ETHTOOL_GRXFHINDIR;
indir_head.size = 0;
err = send_ioctl(ctx, &indir_head);
if (err < 0) {
perror("Cannot get RX flow hash indirection table size");
return 1;
}
indir = malloc(sizeof(*indir) +
indir_head.size * sizeof(*indir->ring_index));
if (!indir) {
perror("Cannot allocate memory for indirection table");
return 1;
}
indir->cmd = ETHTOOL_GRXFHINDIR;
indir->size = indir_head.size;
err = send_ioctl(ctx, indir);
if (err < 0) {
perror("Cannot get RX flow hash indirection table");
free(indir);
return 1;
}
print_indir_table(ctx, ring_count->data, indir->size,
indir->ring_index);
free(indir);
return 0;
}
static int do_grxfh(struct cmd_context *ctx)
{
struct ethtool_gstrings *hfuncs = NULL;
struct ethtool_rxfh rss_head = {0};
struct ethtool_rxnfc ring_count;
struct ethtool_rxfh *rss;
u32 rss_context = 0;
u32 i, indir_bytes;
unsigned int arg_num = 0;
u8 *hkey;
int err;
while (arg_num < ctx->argc) {
if (!strcmp(ctx->argp[arg_num], "context")) {
++arg_num;
rss_context = get_int_range(ctx->argp[arg_num], 0, 1,
ETH_RXFH_CONTEXT_ALLOC - 1);
++arg_num;
} else {
exit_bad_args();
}
}
ring_count.cmd = ETHTOOL_GRXRINGS;
err = send_ioctl(ctx, &ring_count);
if (err < 0) {
perror("Cannot get RX ring count");
return 1;
}
rss_head.cmd = ETHTOOL_GRSSH;
rss_head.rss_context = rss_context;
err = send_ioctl(ctx, &rss_head);
if (err < 0 && errno == EOPNOTSUPP && !rss_context) {
return do_grxfhindir(ctx, &ring_count);
} else if (err < 0) {
perror("Cannot get RX flow hash indir size and/or key size");
return 1;
}
rss = calloc(1, sizeof(*rss) +
rss_head.indir_size * sizeof(rss_head.rss_config[0]) +
rss_head.key_size);
if (!rss) {
perror("Cannot allocate memory for RX flow hash config");
return 1;
}
rss->cmd = ETHTOOL_GRSSH;
rss->rss_context = rss_context;
rss->indir_size = rss_head.indir_size;
rss->key_size = rss_head.key_size;
err = send_ioctl(ctx, rss);
if (err < 0) {
perror("Cannot get RX flow hash configuration");
free(rss);
return 1;
}
print_indir_table(ctx, ring_count.data, rss->indir_size,
rss->rss_config);
indir_bytes = rss->indir_size * sizeof(rss->rss_config[0]);
hkey = ((u8 *)rss->rss_config + indir_bytes);
print_rss_hkey(hkey, rss->key_size);
printf("RSS hash function:\n");
if (!rss->hfunc) {
printf(" Operation not supported\n");
goto out;
}
hfuncs = get_stringset(ctx, ETH_SS_RSS_HASH_FUNCS, 0, 1);
if (!hfuncs) {
perror("Cannot get hash functions names");
free(rss);
return 1;
}
for (i = 0; i < hfuncs->len; i++) {
printf(" %s: %s\n",
(const char *)hfuncs->data + i * ETH_GSTRING_LEN,
(rss->hfunc & (1 << i)) ? "on" : "off");
rss->hfunc &= ~(1 << i);
}
if (rss->hfunc)
printf(" Unknown hash function: 0x%x\n", rss->hfunc);
printf("RSS input transformation:\n");
printf(" symmetric-xor: %s\n",
(rss->input_xfrm & RXH_XFRM_SYM_XOR) ? "on" : "off");
rss->input_xfrm &= ~RXH_XFRM_SYM_XOR;
printf(" symmetric-or-xor: %s\n",
(rss->input_xfrm & RXH_XFRM_SYM_OR_XOR) ? "on" : "off");
rss->input_xfrm &= ~RXH_XFRM_SYM_OR_XOR;
if (rss->input_xfrm)
printf(" Unknown bits in RSS input transformation: 0x%x\n",
rss->input_xfrm);
out:
free(hfuncs);
free(rss);
return 0;
}
static int fill_indir_table(u32 *indir_size, u32 *indir, int rxfhindir_default,
int rxfhindir_start, int rxfhindir_equal,
char **rxfhindir_weight, u32 num_weights)
{
u32 i;
if (rxfhindir_equal) {
for (i = 0; i < *indir_size; i++)
indir[i] = rxfhindir_start + (i % rxfhindir_equal);
} else if (rxfhindir_weight) {
u32 j, weight, sum = 0, partial = 0;
for (j = 0; j < num_weights; j++) {
weight = get_u32(rxfhindir_weight[j], 0);
sum += weight;
}
if (sum == 0) {
fprintf(stderr,
"At least one weight must be non-zero\n");
return 2;
}
if (sum > *indir_size) {
fprintf(stderr,
"Total weight exceeds the size of the "
"indirection table\n");
return 2;
}
j = -1;
for (i = 0; i < *indir_size; i++) {
while (i >= (*indir_size) * partial / sum) {
j += 1;
weight = get_u32(rxfhindir_weight[j], 0);
partial += weight;
}
indir[i] = rxfhindir_start + j;
}
} else if (rxfhindir_default) {
/* "*indir_size == 0" ==> reset indir to default */
*indir_size = 0;
} else {
*indir_size = ETH_RXFH_INDIR_NO_CHANGE;
}
return 0;
}
static int do_srxfhindir(struct cmd_context *ctx, int rxfhindir_default,
int rxfhindir_start, int rxfhindir_equal,
char **rxfhindir_weight, u32 num_weights)
{
struct ethtool_rxfh_indir indir_head;
struct ethtool_rxfh_indir *indir;
int err;
indir_head.cmd = ETHTOOL_GRXFHINDIR;
indir_head.size = 0;
err = send_ioctl(ctx, &indir_head);
if (err < 0) {
perror("Cannot get RX flow hash indirection table size");
return 1;
}
indir = malloc(sizeof(*indir) +
indir_head.size * sizeof(*indir->ring_index));
if (!indir) {
perror("Cannot allocate memory for indirection table");
return 1;
}
indir->cmd = ETHTOOL_SRXFHINDIR;
indir->size = indir_head.size;
if (fill_indir_table(&indir->size, indir->ring_index,
rxfhindir_default, rxfhindir_start,
rxfhindir_equal, rxfhindir_weight, num_weights)) {
free(indir);
return 1;
}
err = send_ioctl(ctx, indir);
if (err < 0) {
perror("Cannot set RX flow hash indirection table");
free(indir);
return 1;
}
free(indir);
return 0;
}
static int do_srxfh(struct cmd_context *ctx)
{
struct ethtool_rxfh rss_head = {0};
struct ethtool_rxfh *rss = NULL;
struct ethtool_rxnfc ring_count;
int rxfhindir_equal = 0, rxfhindir_default = 0, rxfhindir_start = 0;
struct ethtool_gstrings *hfuncs = NULL;
char **rxfhindir_weight = NULL;
char *rxfhindir_key = NULL;
char *req_hfunc_name = NULL;
char *hfunc_name = NULL;
char *hkey = NULL;
int err = 0;
unsigned int i;
u32 arg_num = 0, indir_bytes = 0;
u32 req_hfunc = 0;
u32 entry_size = sizeof(rss_head.rss_config[0]);
u32 req_input_xfrm = RXH_XFRM_NO_CHANGE;
u32 num_weights = 0;
u32 rss_context = 0;
int delete = 0;
if (ctx->argc < 1)
exit_bad_args();
while (arg_num < ctx->argc) {
if (!strcmp(ctx->argp[arg_num], "equal")) {
++arg_num;
rxfhindir_equal = get_int_range(ctx->argp[arg_num],
0, 1, INT_MAX);
++arg_num;
} else if (!strcmp(ctx->argp[arg_num], "start")) {
++arg_num;
rxfhindir_start = get_int_range(ctx->argp[arg_num],
0, 0, INT_MAX);
++arg_num;
} else if (!strcmp(ctx->argp[arg_num], "weight")) {
++arg_num;
rxfhindir_weight = ctx->argp + arg_num;
while (arg_num < ctx->argc &&
isdigit((unsigned char)ctx->argp[arg_num][0])) {
++arg_num;
++num_weights;
}
if (!num_weights)
exit_bad_args();
} else if (!strcmp(ctx->argp[arg_num], "hkey")) {
++arg_num;
rxfhindir_key = ctx->argp[arg_num];
if (!rxfhindir_key)
exit_bad_args();
++arg_num;
} else if (!strcmp(ctx->argp[arg_num], "default")) {
++arg_num;
rxfhindir_default = 1;
} else if (!strcmp(ctx->argp[arg_num], "hfunc")) {
++arg_num;
req_hfunc_name = ctx->argp[arg_num];
if (!req_hfunc_name)
exit_bad_args();
++arg_num;
} else if (!strcmp(ctx->argp[arg_num], "xfrm")) {
++arg_num;
if (!ctx->argp[arg_num])
exit_bad_args();
if (!strcmp(ctx->argp[arg_num], "symmetric-xor"))
req_input_xfrm = RXH_XFRM_SYM_XOR;
else if (!strcmp(ctx->argp[arg_num], "symmetric-or-xor"))
req_input_xfrm = RXH_XFRM_SYM_OR_XOR;
else if (!strcmp(ctx->argp[arg_num], "none"))
req_input_xfrm = 0;
else
exit_bad_args();
++arg_num;
} else if (!strcmp(ctx->argp[arg_num], "context")) {
++arg_num;
if (!ctx->argp[arg_num])
exit_bad_args();
if(!strcmp(ctx->argp[arg_num], "new"))
rss_context = ETH_RXFH_CONTEXT_ALLOC;
else
rss_context = get_int_range(
ctx->argp[arg_num], 0, 1,
ETH_RXFH_CONTEXT_ALLOC - 1);
++arg_num;
} else if (!strcmp(ctx->argp[arg_num], "delete")) {
++arg_num;
delete = 1;
} else {
exit_bad_args();
}
}
if (rxfhindir_equal && rxfhindir_weight) {
fprintf(stderr,
"Equal and weight options are mutually exclusive\n");
return 1;
}
if (rxfhindir_equal && rxfhindir_default) {
fprintf(stderr,
"Equal and default options are mutually exclusive\n");
return 1;
}
if (rxfhindir_weight && rxfhindir_default) {
fprintf(stderr,
"Weight and default options are mutually exclusive\n");
return 1;
}
if (rxfhindir_start && rxfhindir_default) {
fprintf(stderr,
"Start and default options are mutually exclusive\n");
return 1;
}
if (rxfhindir_start && !(rxfhindir_equal || rxfhindir_weight)) {
fprintf(stderr,
"Start must be used with equal or weight options\n");
return 1;
}
if (rxfhindir_default && rss_context) {
fprintf(stderr,
"Default and context options are mutually exclusive\n");
return 1;
}
if (delete && !rss_context) {
fprintf(stderr, "Delete option requires context option\n");
return 1;
}
if (delete && rxfhindir_weight) {
fprintf(stderr,
"Delete and weight options are mutually exclusive\n");
return 1;
}
if (delete && rxfhindir_equal) {
fprintf(stderr,
"Delete and equal options are mutually exclusive\n");
return 1;
}
if (delete && rxfhindir_default) {
fprintf(stderr,
"Delete and default options are mutually exclusive\n");
return 1;
}
if (delete && rxfhindir_key) {
fprintf(stderr,
"Delete and hkey options are mutually exclusive\n");
return 1;
}
ring_count.cmd = ETHTOOL_GRXRINGS;
err = send_ioctl(ctx, &ring_count);
if (err < 0) {
perror("Cannot get RX ring count");
return 1;
}
rss_head.cmd = ETHTOOL_GRSSH;
err = send_ioctl(ctx, &rss_head);
if (err < 0 && errno == EOPNOTSUPP && !rxfhindir_key &&
!req_hfunc_name && !rss_context) {
return do_srxfhindir(ctx, rxfhindir_default, rxfhindir_start,
rxfhindir_equal, rxfhindir_weight,
num_weights);
} else if (err < 0) {
perror("Cannot get RX flow hash indir size and key size");
return 1;
}
if (rxfhindir_key) {
err = parse_hkey(&hkey, rss_head.key_size,
rxfhindir_key);
if (err)
return err;
}
if (rxfhindir_equal || rxfhindir_weight)
indir_bytes = rss_head.indir_size * entry_size;
if (rss_head.hfunc && req_hfunc_name) {
hfuncs = get_stringset(ctx, ETH_SS_RSS_HASH_FUNCS, 0, 1);
if (!hfuncs) {
perror("Cannot get hash functions names");
err = 1;
goto free;
}
for (i = 0; i < hfuncs->len && !req_hfunc ; i++) {
hfunc_name = (char *)(hfuncs->data +
i * ETH_GSTRING_LEN);
if (!strncmp(hfunc_name, req_hfunc_name,
ETH_GSTRING_LEN))
req_hfunc = (u32)1 << i;
}
if (!req_hfunc) {
fprintf(stderr,
"Unknown hash function: %s\n", req_hfunc_name);
err = 1;
goto free;
}
}
rss = calloc(1, sizeof(*rss) + indir_bytes + rss_head.key_size);
if (!rss) {
perror("Cannot allocate memory for RX flow hash config");
err = 1;
goto free;
}
rss->cmd = ETHTOOL_SRSSH;
rss->rss_context = rss_context;
rss->hfunc = req_hfunc;
rss->input_xfrm = req_input_xfrm;
if (delete) {
rss->indir_size = rss->key_size = 0;
} else {
rss->indir_size = rss_head.indir_size;
rss->key_size = rss_head.key_size;
if (fill_indir_table(&rss->indir_size, rss->rss_config,
rxfhindir_default, rxfhindir_start,
rxfhindir_equal, rxfhindir_weight,
num_weights)) {
err = 1;
goto free;
}
}
if (hkey)
memcpy((char *)rss->rss_config + indir_bytes,
hkey, rss->key_size);
else
rss->key_size = 0;
err = send_ioctl(ctx, rss);
if (err < 0) {
perror("Cannot set RX flow hash configuration");
err = 1;
} else if (rss_context == ETH_RXFH_CONTEXT_ALLOC) {
printf("New RSS context is %d\n", rss->rss_context);
}
free:
free(hkey);
free(rss);
free(hfuncs);
return err;
}
static int do_flash(struct cmd_context *ctx)
{
char *flash_file;
int flash_region;
struct ethtool_flash efl;
int err;
if (ctx->argc < 1 || ctx->argc > 2)
exit_bad_args();
flash_file = ctx->argp[0];
if (ctx->argc == 2) {
flash_region = strtol(ctx->argp[1], NULL, 0);
if (flash_region < 0)
exit_bad_args();
} else {
flash_region = -1;
}
if (strlen(flash_file) > ETHTOOL_FLASH_MAX_FILENAME - 1) {
fprintf(stdout, "Filename too long\n");
return 99;
}
efl.cmd = ETHTOOL_FLASHDEV;
strcpy(efl.data, flash_file);
if (flash_region < 0)
efl.region = ETHTOOL_FLASH_ALL_REGIONS;
else
efl.region = flash_region;
err = send_ioctl(ctx, &efl);
if (err < 0)
perror("Flashing failed");
return err;
}
static int do_permaddr(struct cmd_context *ctx)
{
unsigned int i;
int err;
struct ethtool_perm_addr *epaddr;
epaddr = malloc(sizeof(struct ethtool_perm_addr) + MAX_ADDR_LEN);
if (!epaddr) {
perror("Cannot allocate memory for operation");
return 1;
}
epaddr->cmd = ETHTOOL_GPERMADDR;
epaddr->size = MAX_ADDR_LEN;
err = send_ioctl(ctx, epaddr);
if (err < 0)
perror("Cannot read permanent address");
else {
printf("Permanent address:");
for (i = 0; i < epaddr->size; i++)
printf("%c%02x", (i == 0) ? ' ' : ':',
epaddr->data[i]);
printf("\n");
}
free(epaddr);
return err;
}
static bool flow_type_is_ntuple_supported(__u32 flow_type)
{
switch (flow_type) {
case TCP_V4_FLOW:
case UDP_V4_FLOW:
case SCTP_V4_FLOW:
case AH_V4_FLOW:
case ESP_V4_FLOW:
case IPV4_USER_FLOW:
case ETHER_FLOW:
return true;
default:
return false;
}
}
static int flow_spec_to_ntuple(struct ethtool_rx_flow_spec *fsp,
struct ethtool_rx_ntuple_flow_spec *ntuple)
{
size_t i;
/* verify location is not specified */
if (fsp->location != RX_CLS_LOC_ANY)
return -1;
/* destination MAC address in L3/L4 rules is not supported by ntuple */
if (fsp->flow_type & FLOW_MAC_EXT)
return -1;
/* verify ring cookie can transfer to action */
if (fsp->ring_cookie > INT_MAX && fsp->ring_cookie < (u64)(-2))
return -1;
/* verify only one field is setting data field */
if ((fsp->flow_type & FLOW_EXT) &&
(fsp->m_ext.data[0] || fsp->m_ext.data[1]) &&
fsp->m_ext.vlan_etype)
return -1;
/* IPv6 flow types are not supported by ntuple */
if (!flow_type_is_ntuple_supported(fsp->flow_type & ~FLOW_EXT))
return -1;
/* Set entire ntuple to ~0 to guarantee all masks are set */
memset(ntuple, ~0, sizeof(*ntuple));
/* set non-filter values */
ntuple->flow_type = fsp->flow_type;
ntuple->action = fsp->ring_cookie;
/*
* Copy over header union, they are identical in layout however
* the ntuple union contains additional padding on the end
*/
memcpy(&ntuple->h_u, &fsp->h_u, sizeof(fsp->h_u));
/*
* The same rule mentioned above applies to the mask union. However,
* in addition we need to invert the mask bits to match the ntuple
* mask which is 1 for masked, versus 0 for masked as seen in nfc.
*/
memcpy(&ntuple->m_u, &fsp->m_u, sizeof(fsp->m_u));
for (i = 0; i < sizeof(fsp->m_u); i++)
ntuple->m_u.hdata[i] ^= 0xFF;
/* copy extended fields */
if (fsp->flow_type & FLOW_EXT) {
ntuple->vlan_tag =
ntohs(fsp->h_ext.vlan_tci);
ntuple->vlan_tag_mask =
~ntohs(fsp->m_ext.vlan_tci);
if (fsp->m_ext.vlan_etype) {
/*
* vlan_etype and user data are mutually exclusive
* in ntuple configuration as they occupy the same
* space.
*/
if (fsp->m_ext.data[0] || fsp->m_ext.data[1])
return -1;
ntuple->data =
ntohl(fsp->h_ext.vlan_etype);
ntuple->data_mask =
~(u64)ntohl(fsp->m_ext.vlan_etype);
} else {
ntuple->data =
(u64)ntohl(fsp->h_ext.data[0]) << 32;
ntuple->data |=
(u64)ntohl(fsp->h_ext.data[1]);
ntuple->data_mask =
(u64)ntohl(~fsp->m_ext.data[0]) << 32;
ntuple->data_mask |=
(u64)ntohl(~fsp->m_ext.data[1]);
}
}
/* Mask out the extended bit, because ntuple does not know it! */
ntuple->flow_type &= ~FLOW_EXT;
return 0;
}
static int do_srxntuple(struct cmd_context *ctx,
struct ethtool_rx_flow_spec *rx_rule_fs)
{
struct ethtool_rx_ntuple ntuplecmd;
struct ethtool_value eval;
int err;
/* attempt to convert the flow classifier to an ntuple classifier */
err = flow_spec_to_ntuple(rx_rule_fs, &ntuplecmd.fs);
if (err)
return -1;
/*
* Check to see if the flag is set for N-tuple, this allows
* us to avoid the possible EINVAL response for the N-tuple
* flag not being set on the device
*/
eval.cmd = ETHTOOL_GFLAGS;
err = send_ioctl(ctx, &eval);
if (err || !(eval.data & ETH_FLAG_NTUPLE))
return -1;
/* send rule via N-tuple */
ntuplecmd.cmd = ETHTOOL_SRXNTUPLE;
err = send_ioctl(ctx, &ntuplecmd);
/*
* Display error only if response is something other than op not
* supported. It is possible that the interface uses the network
* flow classifier interface instead of N-tuple.
*/
if (err < 0) {
if (errno != EOPNOTSUPP)
perror("Cannot add new rule via N-tuple");
return -1;
}
return 0;
}
static int do_writefwdump(struct ethtool_dump *dump, const char *dump_file)
{
int err = 0;
FILE *f;
size_t bytes;
f = fopen(dump_file, "wb+");
if (!f) {
fprintf(stderr, "Can't open file %s: %s\n",
dump_file, strerror(errno));
return 1;
}
bytes = fwrite(dump->data, 1, dump->len, f);
if (bytes != dump->len) {
fprintf(stderr, "Can not write all of dump data\n");
err = 1;
}
if (fclose(f)) {
fprintf(stderr, "Can't close file %s: %s\n",
dump_file, strerror(errno));
err = 1;
}
return err;
}
static int do_getfwdump(struct cmd_context *ctx)
{
u32 dump_flag;
char *dump_file;
int err;
struct ethtool_dump edata;
struct ethtool_dump *data;
if (ctx->argc == 2 && !strcmp(ctx->argp[0], "data")) {
dump_flag = ETHTOOL_GET_DUMP_DATA;
dump_file = ctx->argp[1];
} else if (ctx->argc == 0) {
dump_flag = 0;
dump_file = NULL;
} else {
exit_bad_args();
}
edata.cmd = ETHTOOL_GET_DUMP_FLAG;
err = send_ioctl(ctx, &edata);
if (err < 0) {
perror("Can not get dump level");
return 1;
}
if (dump_flag != ETHTOOL_GET_DUMP_DATA) {
fprintf(stdout, "flag: %u, version: %u, length: %u\n",
edata.flag, edata.version, edata.len);
return 0;
}
data = calloc(1, offsetof(struct ethtool_dump, data) + edata.len);
if (!data) {
perror("Can not allocate enough memory");
return 1;
}
data->cmd = ETHTOOL_GET_DUMP_DATA;
data->len = edata.len;
err = send_ioctl(ctx, data);
if (err < 0) {
perror("Can not get dump data");
err = 1;
goto free;
}
err = do_writefwdump(data, dump_file);
free:
free(data);
return err;
}
static int do_setfwdump(struct cmd_context *ctx)
{
u32 dump_flag;
int err;
struct ethtool_dump dump;
if (ctx->argc != 1)
exit_bad_args();
dump_flag = get_u32(ctx->argp[0], 0);
dump.cmd = ETHTOOL_SET_DUMP;
dump.flag = dump_flag;
err = send_ioctl(ctx, &dump);
if (err < 0) {
perror("Can not set dump level");
return 1;
}
return 0;
}
static int do_gprivflags(struct cmd_context *ctx)
{
struct ethtool_gstrings *strings;
struct ethtool_value flags;
unsigned int i;
int max_len = 0, cur_len, rc;
if (ctx->argc != 0)
exit_bad_args();
strings = get_stringset(ctx, ETH_SS_PRIV_FLAGS,
offsetof(struct ethtool_drvinfo, n_priv_flags),
1);
if (!strings) {
perror("Cannot get private flag names");
return 1;
}
if (strings->len == 0) {
fprintf(stderr, "No private flags defined\n");
rc = 1;
goto err;
}
if (strings->len > 32) {
/* ETHTOOL_GPFLAGS can only cover 32 flags */
fprintf(stderr, "Only showing first 32 private flags\n");
strings->len = 32;
}
flags.cmd = ETHTOOL_GPFLAGS;
if (send_ioctl(ctx, &flags)) {
perror("Cannot get private flags");
rc = 1;
goto err;
}
/* Find longest string and align all strings accordingly */
for (i = 0; i < strings->len; i++) {
cur_len = strlen((const char *)strings->data +
i * ETH_GSTRING_LEN);
if (cur_len > max_len)
max_len = cur_len;
}
printf("Private flags for %s:\n", ctx->devname);
for (i = 0; i < strings->len; i++)
printf("%-*s: %s\n",
max_len,
(const char *)strings->data + i * ETH_GSTRING_LEN,
(flags.data & (1U << i)) ? "on" : "off");
rc = 0;
err:
free(strings);
return rc;
}
static int do_sprivflags(struct cmd_context *ctx)
{
struct ethtool_gstrings *strings;
struct cmdline_info *cmdline;
struct ethtool_value flags;
u32 wanted_flags = 0, seen_flags = 0;
int any_changed, rc;
unsigned int i;
strings = get_stringset(ctx, ETH_SS_PRIV_FLAGS,
offsetof(struct ethtool_drvinfo, n_priv_flags),
1);
if (!strings) {
perror("Cannot get private flag names");
return 1;
}
if (strings->len == 0) {
fprintf(stderr, "No private flags defined\n");
rc = 1;
goto err;
}
if (strings->len > 32) {
/* ETHTOOL_{G,S}PFLAGS can only cover 32 flags */
fprintf(stderr, "Only setting first 32 private flags\n");
strings->len = 32;
}
cmdline = calloc(strings->len, sizeof(*cmdline));
if (!cmdline) {
perror("Cannot parse arguments");
rc = 1;
goto err;
}
for (i = 0; i < strings->len; i++) {
cmdline[i].name = ((const char *)strings->data +
i * ETH_GSTRING_LEN);
cmdline[i].type = CMDL_FLAG;
cmdline[i].wanted_val = &wanted_flags;
cmdline[i].flag_val = 1U << i;
cmdline[i].seen_val = &seen_flags;
}
parse_generic_cmdline(ctx, &any_changed, cmdline, strings->len);
free(cmdline);
flags.cmd = ETHTOOL_GPFLAGS;
if (send_ioctl(ctx, &flags)) {
perror("Cannot get private flags");
rc = 1;
goto err;
}
flags.cmd = ETHTOOL_SPFLAGS;
flags.data = (flags.data & ~seen_flags) | wanted_flags;
if (send_ioctl(ctx, &flags)) {
perror("Cannot set private flags");
rc = 1;
goto err;
}
rc = 0;
err:
free(strings);
return rc;
}
static int do_tsinfo(struct cmd_context *ctx)
{
struct ethtool_ts_info info;
if (ctx->argc != 0)
exit_bad_args();
fprintf(stdout, "Time stamping parameters for %s:\n", ctx->devname);
info.cmd = ETHTOOL_GET_TS_INFO;
if (send_ioctl(ctx, &info)) {
perror("Cannot get device time stamping settings");
return -1;
}
dump_tsinfo(&info);
return 0;
}
static int do_getmodule(struct cmd_context *ctx)
{
struct ethtool_modinfo modinfo;
struct ethtool_eeprom *eeprom;
u32 geeprom_offset = 0;
u32 geeprom_length = 0;
int geeprom_changed = 0;
int geeprom_dump_raw = 0;
int geeprom_dump_hex = 0;
int geeprom_length_seen = 0;
int err;
struct cmdline_info cmdline_geeprom[] = {
{
.name = "offset",
.type = CMDL_U32,
.wanted_val = &geeprom_offset,
},
{
.name = "length",
.type = CMDL_U32,
.wanted_val = &geeprom_length,
.seen_val = &geeprom_length_seen,
},
{
.name = "raw",
.type = CMDL_BOOL,
.wanted_val = &geeprom_dump_raw,
},
{
.name = "hex",
.type = CMDL_BOOL,
.wanted_val = &geeprom_dump_hex,
},
};
parse_generic_cmdline(ctx, &geeprom_changed,
cmdline_geeprom, ARRAY_SIZE(cmdline_geeprom));
if (geeprom_dump_raw && geeprom_dump_hex) {
printf("Hex and raw dump cannot be specified together\n");
return 1;
}
modinfo.cmd = ETHTOOL_GMODULEINFO;
err = send_ioctl(ctx, &modinfo);
if (err < 0) {
perror("Cannot get module EEPROM information");
return 1;
}
if (!geeprom_length_seen)
geeprom_length = modinfo.eeprom_len;
if (modinfo.eeprom_len < geeprom_offset + geeprom_length)
geeprom_length = modinfo.eeprom_len - geeprom_offset;
eeprom = calloc(1, sizeof(*eeprom)+geeprom_length);
if (!eeprom) {
perror("Cannot allocate memory for Module EEPROM data");
return 1;
}
eeprom->cmd = ETHTOOL_GMODULEEEPROM;
eeprom->len = geeprom_length;
eeprom->offset = geeprom_offset;
err = send_ioctl(ctx, eeprom);
if (err < 0) {
int saved_errno = errno;
perror("Cannot get Module EEPROM data");
if (saved_errno == ENODEV || saved_errno == EIO ||
saved_errno == ENXIO)
fprintf(stderr, "SFP module not in cage?\n");
free(eeprom);
return 1;
}
/*
* SFF-8079 EEPROM layout contains the memory available at A0 address on
* the PHY EEPROM.
* SFF-8472 defines a virtual extension of the EEPROM, where the
* microcontroller on the SFP/SFP+ generates a page at the A2 address,
* which contains data relative to optical diagnostics.
* The current kernel implementation returns a blob, which contains:
* - ETH_MODULE_SFF_8079 => The A0 page only.
* - ETH_MODULE_SFF_8472 => The A0 and A2 page concatenated.
*/
if (geeprom_dump_raw) {
fwrite(eeprom->data, 1, eeprom->len, stdout);
} else {
if (eeprom->offset != 0 ||
(eeprom->len != modinfo.eeprom_len)) {
geeprom_dump_hex = 1;
} else if (!geeprom_dump_hex) {
new_json_obj(ctx->json);
open_json_object(NULL);
switch (modinfo.type) {
#ifdef ETHTOOL_ENABLE_PRETTY_DUMP
case ETH_MODULE_SFF_8079:
sff8079_show_all_ioctl(eeprom->data);
break;
case ETH_MODULE_SFF_8472:
sff8079_show_all_ioctl(eeprom->data);
sff8472_show_all(eeprom->data);
break;
case ETH_MODULE_SFF_8436:
case ETH_MODULE_SFF_8636:
sff8636_show_all_ioctl(eeprom->data,
modinfo.eeprom_len);
break;
#endif
default:
geeprom_dump_hex = 1;
break;
}
close_json_object();
delete_json_obj();
}
if (geeprom_dump_hex)
dump_hex(stdout, eeprom->data,
eeprom->len, eeprom->offset);
}
free(eeprom);
return 0;
}
static int do_geee(struct cmd_context *ctx)
{
struct ethtool_eee eeecmd;
if (ctx->argc != 0)
exit_bad_args();
eeecmd.cmd = ETHTOOL_GEEE;
if (send_ioctl(ctx, &eeecmd)) {
perror("Cannot get EEE settings");
return 1;
}
fprintf(stdout, "EEE Settings for %s:\n", ctx->devname);
dump_eeecmd(&eeecmd);
return 0;
}
static int do_seee(struct cmd_context *ctx)
{
int adv_c = -1, lpi_c = -1, lpi_time_c = -1, eee_c = -1;
int change = -1, change2 = 0;
struct ethtool_eee eeecmd;
struct cmdline_info cmdline_eee[] = {
{
.name = "advertise",
.type = CMDL_U32,
.wanted_val = &adv_c,
.ioctl_val = &eeecmd.advertised,
},
{
.name = "tx-lpi",
.type = CMDL_BOOL,
.wanted_val = &lpi_c,
.ioctl_val = &eeecmd.tx_lpi_enabled,
},
{
.name = "tx-timer",
.type = CMDL_U32,
.wanted_val = &lpi_time_c,
.ioctl_val = &eeecmd.tx_lpi_timer,
},
{
.name = "eee",
.type = CMDL_BOOL,
.wanted_val = &eee_c,
.ioctl_val = &eeecmd.eee_enabled,
},
};
if (ctx->argc == 0)
exit_bad_args();
parse_generic_cmdline(ctx, &change, cmdline_eee,
ARRAY_SIZE(cmdline_eee));
eeecmd.cmd = ETHTOOL_GEEE;
if (send_ioctl(ctx, &eeecmd)) {
perror("Cannot get EEE settings");
return 1;
}
do_generic_set(cmdline_eee, ARRAY_SIZE(cmdline_eee), &change2);
if (change2) {
eeecmd.cmd = ETHTOOL_SEEE;
if (send_ioctl(ctx, &eeecmd)) {
perror("Cannot set EEE settings");
return 1;
}
}
return 0;
}
/* copy of net/ethtool/common.c */
char
tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
[ETHTOOL_ID_UNSPEC] = "Unspec",
[ETHTOOL_RX_COPYBREAK] = "rx-copybreak",
[ETHTOOL_TX_COPYBREAK] = "tx-copybreak",
[ETHTOOL_TX_COPYBREAK_BUF_SIZE] = "tx-buf-size",
[ETHTOOL_PFC_PREVENTION_TOUT] = "pfc-prevention-tout",
};
union ethtool_tunable_info_val {
uint8_t u8;
uint16_t u16;
uint32_t u32;
uint64_t u64;
int8_t s8;
int16_t s16;
int32_t s32;
int64_t s64;
};
struct ethtool_tunable_info {
enum tunable_id t_id;
enum tunable_type_id t_type_id;
size_t size;
cmdline_type_t type;
union ethtool_tunable_info_val wanted;
int seen;
};
static struct ethtool_tunable_info tunables_info[] = {
{ .t_id = ETHTOOL_RX_COPYBREAK,
.t_type_id = ETHTOOL_TUNABLE_U32,
.size = sizeof(u32),
.type = CMDL_U32,
},
{ .t_id = ETHTOOL_TX_COPYBREAK,
.t_type_id = ETHTOOL_TUNABLE_U32,
.size = sizeof(u32),
.type = CMDL_U32,
},
{ .t_id = ETHTOOL_PFC_PREVENTION_TOUT,
.t_type_id = ETHTOOL_TUNABLE_U16,
.size = sizeof(u16),
.type = CMDL_U16,
},
{ .t_id = ETHTOOL_TX_COPYBREAK_BUF_SIZE,
.t_type_id = ETHTOOL_TUNABLE_U32,
.size = sizeof(u32),
.type = CMDL_U32,
},
};
#define TUNABLES_INFO_SIZE ARRAY_SIZE(tunables_info)
static int do_stunable(struct cmd_context *ctx)
{
struct cmdline_info cmdline_tunable[TUNABLES_INFO_SIZE];
struct ethtool_tunable_info *tinfo = tunables_info;
int changed = 0;
unsigned int i;
for (i = 0; i < TUNABLES_INFO_SIZE; i++) {
cmdline_tunable[i].name = tunable_strings[tinfo[i].t_id];
cmdline_tunable[i].type = tinfo[i].type;
cmdline_tunable[i].wanted_val = &tinfo[i].wanted;
cmdline_tunable[i].seen_val = &tinfo[i].seen;
}
parse_generic_cmdline(ctx, &changed, cmdline_tunable, TUNABLES_INFO_SIZE);
if (!changed)
exit_bad_args();
for (i = 0; i < TUNABLES_INFO_SIZE; i++) {
struct ethtool_tunable *tuna;
size_t size;
int ret;
if (!tinfo[i].seen)
continue;
size = sizeof(*tuna) + tinfo[i].size;
tuna = calloc(1, size);
if (!tuna) {
perror(tunable_strings[tinfo[i].t_id]);
return 1;
}
tuna->cmd = ETHTOOL_STUNABLE;
tuna->id = tinfo[i].t_id;
tuna->type_id = tinfo[i].t_type_id;
tuna->len = tinfo[i].size;
memcpy(tuna->data, &tinfo[i].wanted, tuna->len);
ret = send_ioctl(ctx, tuna);
if (ret) {
perror(tunable_strings[tuna->id]);
free(tuna);
return ret;
}
free(tuna);
}
return 0;
}
static void print_tunable(struct ethtool_tunable *tuna)
{
char *name = tunable_strings[tuna->id];
union ethtool_tunable_info_val *val;
val = (union ethtool_tunable_info_val *)tuna->data;
switch (tuna->type_id) {
case ETHTOOL_TUNABLE_U8:
fprintf(stdout, "%s: %" PRIu8 "\n", name, val->u8);
break;
case ETHTOOL_TUNABLE_U16:
fprintf(stdout, "%s: %" PRIu16 "\n", name, val->u16);
break;
case ETHTOOL_TUNABLE_U32:
fprintf(stdout, "%s: %" PRIu32 "\n", name, val->u32);
break;
case ETHTOOL_TUNABLE_U64:
fprintf(stdout, "%s: %" PRIu64 "\n", name, val->u64);
break;
case ETHTOOL_TUNABLE_S8:
fprintf(stdout, "%s: %" PRId8 "\n", name, val->s8);
break;
case ETHTOOL_TUNABLE_S16:
fprintf(stdout, "%s: %" PRId16 "\n", name, val->s16);
break;
case ETHTOOL_TUNABLE_S32:
fprintf(stdout, "%s: %" PRId32 "\n", name, val->s32);
break;
case ETHTOOL_TUNABLE_S64:
fprintf(stdout, "%s: %" PRId64 "\n", name, val->s64);
break;
default:
fprintf(stdout, "%s: Unknown format\n", name);
}
}
static int do_gtunable(struct cmd_context *ctx)
{
struct ethtool_tunable_info *tinfo = tunables_info;
char **argp = ctx->argp;
unsigned int argc = ctx->argc;
unsigned int i, j;
if (argc < 1)
exit_bad_args();
for (i = 0; i < argc; i++) {
int valid = 0;
for (j = 0; j < TUNABLES_INFO_SIZE; j++) {
char *ts = tunable_strings[tinfo[j].t_id];
struct ethtool_tunable *tuna;
int ret;
if (strcmp(argp[i], ts))
continue;
valid = 1;
tuna = calloc(1, sizeof(*tuna) + tinfo[j].size);
if (!tuna) {
perror(ts);
return 1;
}
tuna->cmd = ETHTOOL_GTUNABLE;
tuna->id = tinfo[j].t_id;
tuna->type_id = tinfo[j].t_type_id;
tuna->len = tinfo[j].size;
ret = send_ioctl(ctx, tuna);
if (ret) {
fprintf(stderr, "%s: Cannot get tunable\n", ts);
free(tuna);
return ret;
}
print_tunable(tuna);
free(tuna);
}
if (!valid)
exit_bad_args();
}
return 0;
}
static int do_get_phy_tunable(struct cmd_context *ctx)
{
unsigned int argc = ctx->argc;
char **argp = ctx->argp;
if (argc < 1)
exit_bad_args();
if (!strcmp(argp[0], "downshift")) {
struct {
struct ethtool_tunable ds;
u8 count;
} cont;
cont.ds.cmd = ETHTOOL_PHY_GTUNABLE;
cont.ds.id = ETHTOOL_PHY_DOWNSHIFT;
cont.ds.type_id = ETHTOOL_TUNABLE_U8;
cont.ds.len = 1;
if (send_ioctl(ctx, &cont.ds) < 0) {
perror("Cannot Get PHY downshift count");
return 87;
}
if (cont.count)
fprintf(stdout, "Downshift count: %d\n", cont.count);
else
fprintf(stdout, "Downshift disabled\n");
} else if (!strcmp(argp[0], "fast-link-down")) {
struct {
struct ethtool_tunable fld;
u8 msecs;
} cont;
cont.fld.cmd = ETHTOOL_PHY_GTUNABLE;
cont.fld.id = ETHTOOL_PHY_FAST_LINK_DOWN;
cont.fld.type_id = ETHTOOL_TUNABLE_U8;
cont.fld.len = 1;
if (send_ioctl(ctx, &cont.fld) < 0) {
perror("Cannot Get PHY Fast Link Down value");
return 87;
}
if (cont.msecs == ETHTOOL_PHY_FAST_LINK_DOWN_ON)
fprintf(stdout, "Fast Link Down enabled\n");
else if (cont.msecs == ETHTOOL_PHY_FAST_LINK_DOWN_OFF)
fprintf(stdout, "Fast Link Down disabled\n");
else
fprintf(stdout, "Fast Link Down enabled, %d msecs\n",
cont.msecs);
} else if (!strcmp(argp[0], "energy-detect-power-down")) {
struct {
struct ethtool_tunable ds;
u16 msecs;
} cont;
cont.ds.cmd = ETHTOOL_PHY_GTUNABLE;
cont.ds.id = ETHTOOL_PHY_EDPD;
cont.ds.type_id = ETHTOOL_TUNABLE_U16;
cont.ds.len = 2;
if (send_ioctl(ctx, &cont.ds) < 0) {
perror("Cannot Get PHY Energy Detect Power Down value");
return 87;
}
if (cont.msecs == ETHTOOL_PHY_EDPD_DISABLE)
fprintf(stdout, "Energy Detect Power Down: disabled\n");
else if (cont.msecs == ETHTOOL_PHY_EDPD_NO_TX)
fprintf(stdout,
"Energy Detect Power Down: enabled, TX disabled\n");
else
fprintf(stdout,
"Energy Detect Power Down: enabled, TX %u msecs\n",
cont.msecs);
} else {
exit_bad_args();
}
return 0;
}
static __u32 parse_reset(char *val, __u32 bitset, char *arg, __u32 *data)
{
__u32 bitval = 0;
int i;
/* Check for component match */
for (i = 0; val[i] != '\0'; i++)
if (arg[i] != val[i])
return 0;
/* Check if component has -shared specified or not */
if (arg[i] == '\0')
bitval = bitset;
else if (!strcmp(arg+i, "-shared"))
bitval = bitset << ETH_RESET_SHARED_SHIFT;
if (bitval) {
*data |= bitval;
return 1;
}
return 0;
}
static int do_reset(struct cmd_context *ctx)
{
struct ethtool_value resetinfo;
__u32 data;
unsigned int argc = ctx->argc;
char **argp = ctx->argp;
unsigned int i;
if (argc == 0)
exit_bad_args();
data = 0;
for (i = 0; i < argc; i++) {
if (!strcmp(argp[i], "flags")) {
__u32 flags;
i++;
if (i >= argc)
exit_bad_args();
flags = strtoul(argp[i], NULL, 0);
if (flags == 0)
exit_bad_args();
else
data |= flags;
} else if (parse_reset("mgmt", ETH_RESET_MGMT,
argp[i], &data)) {
} else if (parse_reset("irq", ETH_RESET_IRQ,
argp[i], &data)) {
} else if (parse_reset("dma", ETH_RESET_DMA,
argp[i], &data)) {
} else if (parse_reset("filter", ETH_RESET_FILTER,
argp[i], &data)) {
} else if (parse_reset("offload", ETH_RESET_OFFLOAD,
argp[i], &data)) {
} else if (parse_reset("mac", ETH_RESET_MAC,
argp[i], &data)) {
} else if (parse_reset("phy", ETH_RESET_PHY,
argp[i], &data)) {
} else if (parse_reset("ram", ETH_RESET_RAM,
argp[i], &data)) {
} else if (parse_reset("ap", ETH_RESET_AP,
argp[i], &data)) {
} else if (!strcmp(argp[i], "dedicated")) {
data |= ETH_RESET_DEDICATED;
} else if (!strcmp(argp[i], "all")) {
data |= ETH_RESET_ALL;
} else {
exit_bad_args();
}
}
resetinfo.cmd = ETHTOOL_RESET;
resetinfo.data = data;
fprintf(stdout, "ETHTOOL_RESET 0x%x\n", resetinfo.data);
if (send_ioctl(ctx, &resetinfo)) {
perror("Cannot issue ETHTOOL_RESET");
return 1;
}
fprintf(stdout, "Components reset: 0x%x\n", data & ~resetinfo.data);
if (resetinfo.data)
fprintf(stdout, "Components not reset: 0x%x\n", resetinfo.data);
return 0;
}
static int parse_named_bool(struct cmd_context *ctx, const char *name, u8 *on)
{
if (ctx->argc < 2)
return 0;
if (strcmp(*ctx->argp, name))
return 0;
if (!strcmp(*(ctx->argp + 1), "on")) {
*on = 1;
} else if (!strcmp(*(ctx->argp + 1), "off")) {
*on = 0;
} else {
fprintf(stderr, "Invalid boolean\n");
exit_bad_args();
}
ctx->argc -= 2;
ctx->argp += 2;
return 1;
}
static int parse_named_uint(struct cmd_context *ctx,
const char *name,
unsigned long long *val,
unsigned long long max)
{
if (ctx->argc < 2)
return 0;
if (strcmp(*ctx->argp, name))
return 0;
*val = get_uint_range(*(ctx->argp + 1), 0, max);
ctx->argc -= 2;
ctx->argp += 2;
return 1;
}
static int parse_named_u8(struct cmd_context *ctx, const char *name, u8 *val)
{
unsigned long long val1;
int ret;
ret = parse_named_uint(ctx, name, &val1, 0xff);
if (ret)
*val = val1;
return ret;
}
static int parse_named_u16(struct cmd_context *ctx, const char *name, u16 *val)
{
unsigned long long val1;
int ret;
ret = parse_named_uint(ctx, name, &val1, 0xffff);
if (ret)
*val = val1;
return ret;
}
static int do_set_phy_tunable(struct cmd_context *ctx)
{
int err = 0;
u8 ds_cnt = DOWNSHIFT_DEV_DEFAULT_COUNT;
u8 ds_changed = 0, ds_has_cnt = 0, ds_enable = 0;
u8 fld_changed = 0, fld_enable = 0;
u8 fld_msecs = ETHTOOL_PHY_FAST_LINK_DOWN_ON;
u8 edpd_changed = 0, edpd_enable = 0;
u16 edpd_tx_interval = ETHTOOL_PHY_EDPD_DFLT_TX_MSECS;
/* Parse arguments */
if (parse_named_bool(ctx, "downshift", &ds_enable)) {
ds_changed = 1;
ds_has_cnt = parse_named_u8(ctx, "count", &ds_cnt);
} else if (parse_named_bool(ctx, "fast-link-down", &fld_enable)) {
fld_changed = 1;
if (fld_enable)
parse_named_u8(ctx, "msecs", &fld_msecs);
} else if (parse_named_bool(ctx, "energy-detect-power-down",
&edpd_enable)) {
edpd_changed = 1;
if (edpd_enable)
parse_named_u16(ctx, "msecs", &edpd_tx_interval);
} else {
exit_bad_args();
}
/* Validate parameters */
if (ds_changed) {
if (!ds_enable && ds_has_cnt) {
fprintf(stderr, "'count' may not be set when downshift "
"is off.\n");
exit_bad_args();
}
if (ds_enable && ds_has_cnt && ds_cnt == 0) {
fprintf(stderr, "'count' may not be zero.\n");
exit_bad_args();
}
if (!ds_enable)
ds_cnt = DOWNSHIFT_DEV_DISABLE;
} else if (fld_changed) {
if (!fld_enable)
fld_msecs = ETHTOOL_PHY_FAST_LINK_DOWN_OFF;
else if (fld_msecs == ETHTOOL_PHY_FAST_LINK_DOWN_OFF)
exit_bad_args();
} else if (edpd_changed) {
if (!edpd_enable)
edpd_tx_interval = ETHTOOL_PHY_EDPD_DISABLE;
else if (edpd_tx_interval == 0)
edpd_tx_interval = ETHTOOL_PHY_EDPD_NO_TX;
else if (edpd_tx_interval > ETHTOOL_PHY_EDPD_NO_TX) {
fprintf(stderr, "'msecs' max value is %d.\n",
(ETHTOOL_PHY_EDPD_NO_TX - 1));
exit_bad_args();
}
}
/* Do it */
if (ds_changed) {
struct {
struct ethtool_tunable ds;
u8 count;
} cont;
cont.ds.cmd = ETHTOOL_PHY_STUNABLE;
cont.ds.id = ETHTOOL_PHY_DOWNSHIFT;
cont.ds.type_id = ETHTOOL_TUNABLE_U8;
cont.ds.len = 1;
cont.count = ds_cnt;
err = send_ioctl(ctx, &cont.ds);
if (err < 0) {
perror("Cannot Set PHY downshift count");
err = 87;
}
} else if (fld_changed) {
struct {
struct ethtool_tunable fld;
u8 msecs;
} cont;
cont.fld.cmd = ETHTOOL_PHY_STUNABLE;
cont.fld.id = ETHTOOL_PHY_FAST_LINK_DOWN;
cont.fld.type_id = ETHTOOL_TUNABLE_U8;
cont.fld.len = 1;
cont.msecs = fld_msecs;
err = send_ioctl(ctx, &cont.fld);
if (err < 0) {
perror("Cannot Set PHY Fast Link Down value");
err = 87;
}
} else if (edpd_changed) {
struct {
struct ethtool_tunable fld;
u16 msecs;
} cont;
cont.fld.cmd = ETHTOOL_PHY_STUNABLE;
cont.fld.id = ETHTOOL_PHY_EDPD;
cont.fld.type_id = ETHTOOL_TUNABLE_U16;
cont.fld.len = 2;
cont.msecs = edpd_tx_interval;
err = send_ioctl(ctx, &cont.fld);
if (err < 0) {
perror("Cannot Set PHY Energy Detect Power Down");
err = 87;
}
}
return err;
}
static int fecmode_str_to_type(const char *str)
{
if (!strcasecmp(str, "auto"))
return ETHTOOL_FEC_AUTO;
if (!strcasecmp(str, "off"))
return ETHTOOL_FEC_OFF;
if (!strcasecmp(str, "rs"))
return ETHTOOL_FEC_RS;
if (!strcasecmp(str, "baser"))
return ETHTOOL_FEC_BASER;
if (!strcasecmp(str, "llrs"))
return ETHTOOL_FEC_LLRS;
return 0;
}
static int do_gfec(struct cmd_context *ctx)
{
struct ethtool_fecparam feccmd = { 0 };
int rv;
if (ctx->argc != 0)
exit_bad_args();
feccmd.cmd = ETHTOOL_GFECPARAM;
rv = send_ioctl(ctx, &feccmd);
if (rv != 0) {
perror("Cannot get FEC settings");
return rv;
}
fprintf(stdout, "FEC parameters for %s:\n", ctx->devname);
fprintf(stdout, "Supported/Configured FEC encodings:");
dump_fec(feccmd.fec);
fprintf(stdout, "\n");
fprintf(stdout, "Active FEC encoding:");
dump_fec(feccmd.active_fec);
fprintf(stdout, "\n");
return 0;
}
static int do_sfec(struct cmd_context *ctx)
{
enum { ARG_NONE, ARG_ENCODING } state = ARG_NONE;
struct ethtool_fecparam feccmd;
int fecmode = 0, newmode;
unsigned int i;
int rv;
for (i = 0; i < ctx->argc; i++) {
if (!strcmp(ctx->argp[i], "encoding")) {
state = ARG_ENCODING;
continue;
}
if (state == ARG_ENCODING) {
newmode = fecmode_str_to_type(ctx->argp[i]);
if (!newmode)
exit_bad_args();
fecmode |= newmode;
continue;
}
exit_bad_args();
}
if (!fecmode)
exit_bad_args();
feccmd.cmd = ETHTOOL_SFECPARAM;
feccmd.fec = fecmode;
rv = send_ioctl(ctx, &feccmd);
if (rv != 0) {
perror("Cannot set FEC settings");
return rv;
}
return 0;
}
static int do_perqueue(struct cmd_context *ctx);
#ifndef TEST_ETHTOOL
int send_ioctl(struct cmd_context *ctx, void *cmd)
{
ctx->ifr.ifr_data = cmd;
return ioctl(ctx->fd, SIOCETHTOOL, &ctx->ifr);
}
#endif
static int show_usage(struct cmd_context *ctx);
struct option {
const char *opts;
bool no_dev;
bool json;
bool targets_phy;
int (*func)(struct cmd_context *);
nl_chk_t nlchk;
nl_func_t nlfunc;
const char *help;
const char *xhelp;
};
static const struct option args[] = {
{
/* "default" entry when no switch is used */
.opts = "",
.json = true,
.func = do_gset,
.nlfunc = nl_gset,
.help = "Display standard information about device",
},
{
.opts = "-s|--change",
.func = do_sset,
.nlfunc = nl_sset,
.help = "Change generic options",
.xhelp = " [ speed %d ]\n"
" [ lanes %d ]\n"
" [ duplex half|full ]\n"
" [ port tp|aui|bnc|mii|fibre|da ]\n"
" [ mdix auto|on|off ]\n"
" [ autoneg on|off ]\n"
" [ advertise %x[/%x] | mode on|off ... [--] ]\n"
" [ phyad %d ]\n"
" [ xcvr internal|external ]\n"
" [ wol %d[/%d] | p|u|m|b|a|g|s|f|d... ]\n"
" [ sopass %x:%x:%x:%x:%x:%x ]\n"
" [ msglvl %d[/%d] | type on|off ... [--] ]\n"
" [ master-slave preferred-master|preferred-slave|forced-master|forced-slave ]\n"
},
{
.opts = "-a|--show-pause",
.json = true,
.func = do_gpause,
.nlfunc = nl_gpause,
.help = "Show pause options",
.xhelp = " [ --src aggregate | emac | pmac ]\n"
},
{
.opts = "-A|--pause",
.func = do_spause,
.nlfunc = nl_spause,
.help = "Set pause options",
.xhelp = " [ autoneg on|off ]\n"
" [ rx on|off ]\n"
" [ tx on|off ]\n"
},
{
.opts = "-c|--show-coalesce",
.json = true,
.func = do_gcoalesce,
.nlfunc = nl_gcoalesce,
.help = "Show coalesce options"
},
{
.opts = "-C|--coalesce",
.func = do_scoalesce,
.nlfunc = nl_scoalesce,
.help = "Set coalesce options",
.xhelp = " [adaptive-rx on|off]\n"
" [adaptive-tx on|off]\n"
" [rx-usecs N]\n"
" [rx-frames N]\n"
" [rx-usecs-irq N]\n"
" [rx-frames-irq N]\n"
" [tx-usecs N]\n"
" [tx-frames N]\n"
" [tx-usecs-irq N]\n"
" [tx-frames-irq N]\n"
" [stats-block-usecs N]\n"
" [pkt-rate-low N]\n"
" [rx-usecs-low N]\n"
" [rx-frames-low N]\n"
" [tx-usecs-low N]\n"
" [tx-frames-low N]\n"
" [pkt-rate-high N]\n"
" [rx-usecs-high N]\n"
" [rx-frames-high N]\n"
" [tx-usecs-high N]\n"
" [tx-frames-high N]\n"
" [sample-interval N]\n"
" [cqe-mode-rx on|off]\n"
" [cqe-mode-tx on|off]\n"
" [tx-aggr-max-bytes N]\n"
" [tx-aggr-max-frames N]\n"
" [tx-aggr-time-usecs N]\n"
},
{
.opts = "-g|--show-ring",
.json = true,
.func = do_gring,
.nlfunc = nl_gring,
.help = "Query RX/TX ring parameters"
},
{
.opts = "-G|--set-ring",
.func = do_sring,
.nlfunc = nl_sring,
.help = "Set RX/TX ring parameters",
.xhelp = " [ rx N ]\n"
" [ rx-mini N ]\n"
" [ rx-jumbo N ]\n"
" [ tx N ]\n"
" [ rx-buf-len N ]\n"
" [ tcp-data-split auto|on|off ]\n"
" [ cqe-size N ]\n"
" [ tx-push on|off ]\n"
" [ rx-push on|off ]\n"
" [ tx-push-buf-len N]\n"
" [ hds-thresh N ]\n"
},
{
.opts = "-k|--show-features|--show-offload",
.json = true,
.func = do_gfeatures,
.nlfunc = nl_gfeatures,
.help = "Get state of protocol offload and other features"
},
{
.opts = "-K|--features|--offload",
.func = do_sfeatures,
.nlfunc = nl_sfeatures,
.help = "Set protocol offload and other features",
.xhelp = " FEATURE on|off ...\n"
},
{
.opts = "-i|--driver",
.func = do_gdrv,
.help = "Show driver information"
},
{
.opts = "-d|--register-dump",
.func = do_gregs,
.help = "Do a register dump",
.xhelp = " [ raw on|off ]\n"
" [ file FILENAME ]\n"
},
{
.opts = "-e|--eeprom-dump",
.func = do_geeprom,
.help = "Do a EEPROM dump",
.xhelp = " [ raw on|off ]\n"
" [ offset N ]\n"
" [ length N ]\n"
},
{
.opts = "-E|--change-eeprom",
.func = do_seeprom,
.help = "Change bytes in device EEPROM",
.xhelp = " [ magic N ]\n"
" [ offset N ]\n"
" [ length N ]\n"
" [ value N ]\n"
},
{
.opts = "-r|--negotiate",
.func = do_nway_rst,
.help = "Restart N-WAY negotiation"
},
{
.opts = "-p|--identify",
.func = do_phys_id,
.help = "Show visible port identification (e.g. blinking)",
.xhelp = " [ TIME-IN-SECONDS ]\n"
},
{
.opts = "-t|--test",
.func = do_test,
.help = "Execute adapter self test",
.xhelp = " [ online | offline | external_lb ]\n"
},
{
.opts = "-S|--statistics",
.json = true,
.func = do_gnicstats,
.nlchk = nl_gstats_chk,
.nlfunc = nl_gstats,
.help = "Show adapter statistics",
.xhelp = " [ --all-groups | --groups [eth-phy] [eth-mac] [eth-ctrl] [rmon] ]\n"
" [ --src aggregate | emac | pmac ]\n"
},
{
.opts = "--phy-statistics",
.func = do_gphystats,
.help = "Show phy statistics"
},
{
.opts = "-n|-u|--show-nfc|--show-ntuple",
.func = do_grxclass,
.help = "Show Rx network flow classification options or rules",
.xhelp = " [ rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|"
"gtpc4|gtpc4t|gtpu4|gtpu4e|gtpu4u|gtpu4d|tcp6|udp6|ah6|esp6|sctp6|"
"gtpc6|gtpc6t|gtpu6|gtpu6e|gtpu6u|gtpu6d [context %d] |\n"
" rule %d ]\n"
},
{
.opts = "-N|-U|--config-nfc|--config-ntuple",
.func = do_srxclass,
.help = "Configure Rx network flow classification options or rules",
.xhelp = " rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|"
"gtpc4|gtpc4t|gtpu4|gtpu4e|gtpu4u|gtpu4d|tcp6|udp6|ah6|esp6|sctp6"
"|gtpc6|gtpc6t|gtpu6|gtpu6e|gtpu6u|gtpu6d m|v|t|s|d|f|n|r|e... [context %d] |\n"
" flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4|"
"ip6|tcp6|udp6|ah6|esp6|sctp6\n"
" [ src %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n"
" [ dst %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n"
" [ proto %d [m %x] ]\n"
" [ src-ip IP-ADDRESS [m IP-ADDRESS] ]\n"
" [ dst-ip IP-ADDRESS [m IP-ADDRESS] ]\n"
" [ tos %d [m %x] ]\n"
" [ tclass %d [m %x] ]\n"
" [ l4proto %d [m %x] ]\n"
" [ src-port %d [m %x] ]\n"
" [ dst-port %d [m %x] ]\n"
" [ spi %d [m %x] ]\n"
" [ vlan-etype %x [m %x] ]\n"
" [ vlan %x [m %x] ]\n"
" [ user-def %x [m %x] ]\n"
" [ dst-mac %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n"
" [ action %d ] | [ vf %d queue %d ]\n"
" [ context %d ]\n"
" [ loc %d ] |\n"
" delete %d\n"
},
{
.opts = "-T|--show-time-stamping",
.func = do_tsinfo,
.nlfunc = nl_tsinfo,
.help = "Show time stamping capabilities",
.xhelp = " [ index N qualifier precise|approx ]\n"
},
{
.opts = "--get-hwtimestamp-cfg",
.nlfunc = nl_gtsconfig,
.help = "Get selected hardware time stamping"
},
{
.opts = "--set-hwtimestamp-cfg",
.nlfunc = nl_stsconfig,
.help = "Select hardware time stamping",
.xhelp = " [ index N qualifier precise|approx ]\n"
},
{
.opts = "-x|--show-rxfh-indir|--show-rxfh",
.json = true,
.func = do_grxfh,
.nlfunc = nl_grss,
.help = "Show Rx flow hash indirection table and/or RSS hash key",
.xhelp = " [ context %d ]\n"
},
{
.opts = "-X|--set-rxfh-indir|--rxfh",
.func = do_srxfh,
.help = "Set Rx flow hash indirection table and/or RSS hash key",
.xhelp = " [ context %d|new ]\n"
" [ equal N | weight W0 W1 ... | default ]\n"
" [ hkey %x:%x:%x:%x:%x:.... ]\n"
" [ hfunc FUNC ]\n"
" [ xfrm symmetric-xor | symmetric-or-xor | none ]\n"
" [ delete ]\n"
},
{
.opts = "-f|--flash",
.func = do_flash,
.help = "Flash firmware image from the specified file to a region on the device",
.xhelp = " FILENAME [ REGION-NUMBER-TO-FLASH ]\n"
},
{
.opts = "-P|--show-permaddr",
.func = do_permaddr,
.nlfunc = nl_permaddr,
.help = "Show permanent hardware address"
},
{
.opts = "-w|--get-dump",
.func = do_getfwdump,
.help = "Get dump flag, data",
.xhelp = " [ data FILENAME ]\n"
},
{
.opts = "-W|--set-dump",
.func = do_setfwdump,
.help = "Set dump flag of the device",
.xhelp = " N\n"
},
{
.opts = "-l|--show-channels",
.json = true,
.func = do_gchannels,
.nlfunc = nl_gchannels,
.help = "Query Channels"
},
{
.opts = "-L|--set-channels",
.func = do_schannels,
.nlfunc = nl_schannels,
.help = "Set Channels",
.xhelp = " [ rx N ]\n"
" [ tx N ]\n"
" [ other N ]\n"
" [ combined N ]\n"
},
{
.opts = "--show-priv-flags",
.func = do_gprivflags,
.nlfunc = nl_gprivflags,
.help = "Query private flags"
},
{
.opts = "--set-priv-flags",
.func = do_sprivflags,
.nlfunc = nl_sprivflags,
.help = "Set private flags",
.xhelp = " FLAG on|off ...\n"
},
{
.opts = "-m|--dump-module-eeprom|--module-info",
.json = true,
.func = do_getmodule,
.nlfunc = nl_getmodule,
.help = "Query/Decode Module EEPROM information and optical diagnostics if available",
.xhelp = " [ raw on|off ]\n"
" [ hex on|off ]\n"
" [ offset N ]\n"
" [ length N ]\n"
" [ page N ]\n"
" [ bank N ]\n"
" [ i2c N ]\n"
},
{
.opts = "--show-eee",
.json = true,
.func = do_geee,
.nlfunc = nl_geee,
.help = "Show EEE settings",
},
{
.opts = "--set-eee",
.func = do_seee,
.nlfunc = nl_seee,
.help = "Set EEE settings",
.xhelp = " [ eee on|off ]\n"
" [ advertise %x ]\n"
" [ tx-lpi on|off ]\n"
" [ tx-timer %d ]\n"
},
{
.opts = "--set-phy-tunable",
.func = do_set_phy_tunable,
.help = "Set PHY tunable",
.xhelp = " [ downshift on|off [count N] ]\n"
" [ fast-link-down on|off [msecs N] ]\n"
" [ energy-detect-power-down on|off [msecs N] ]\n"
},
{
.opts = "--get-phy-tunable",
.func = do_get_phy_tunable,
.help = "Get PHY tunable",
.xhelp = " [ downshift ]\n"
" [ fast-link-down ]\n"
" [ energy-detect-power-down ]\n"
},
{
.opts = "--get-tunable",
.func = do_gtunable,
.help = "Get tunable",
.xhelp = " [ rx-copybreak ]\n"
" [ tx-copybreak ]\n"
" [ tx-buf-size ]\n"
" [ pfc-prevention-tout ]\n"
},
{
.opts = "--set-tunable",
.func = do_stunable,
.help = "Set tunable",
.xhelp = " [ rx-copybreak N ]\n"
" [ tx-copybreak N ]\n"
" [ tx-buf-size N ]\n"
" [ pfc-prevention-tout N ]\n"
},
{
.opts = "--reset",
.func = do_reset,
.help = "Reset components",
.xhelp = " [ flags %x ]\n"
" [ mgmt ]\n"
" [ mgmt-shared ]\n"
" [ irq ]\n"
" [ irq-shared ]\n"
" [ dma ]\n"
" [ dma-shared ]\n"
" [ filter ]\n"
" [ filter-shared ]\n"
" [ offload ]\n"
" [ offload-shared ]\n"
" [ mac ]\n"
" [ mac-shared ]\n"
" [ phy ]\n"
" [ phy-shared ]\n"
" [ ram ]\n"
" [ ram-shared ]\n"
" [ ap ]\n"
" [ ap-shared ]\n"
" [ dedicated ]\n"
" [ all ]\n"
},
{
.opts = "--show-fec",
.json = true,
.func = do_gfec,
.nlfunc = nl_gfec,
.help = "Show FEC settings",
},
{
.opts = "--set-fec",
.func = do_sfec,
.nlfunc = nl_sfec,
.help = "Set FEC settings",
.xhelp = " [ encoding auto|off|rs|baser|llrs [...] ]\n"
},
{
.opts = "-Q|--per-queue",
.func = do_perqueue,
.help = "Apply per-queue command. ",
.xhelp = "The supported sub commands include --show-coalesce, --coalesce"
" [queue_mask %x] SUB_COMMAND\n",
},
{
.opts = "--cable-test",
.targets_phy = true,
.json = true,
.nlfunc = nl_cable_test,
.help = "Perform a cable test",
},
{
.opts = "--cable-test-tdr",
.targets_phy = true,
.json = true,
.nlfunc = nl_cable_test_tdr,
.help = "Print cable test time domain reflectrometery data",
.xhelp = " [ first N ]\n"
" [ last N ]\n"
" [ step N ]\n"
" [ pair N ]\n"
},
{
.opts = "--show-tunnels",
.nlfunc = nl_gtunnels,
.help = "Show NIC tunnel offload information",
},
{
.opts = "--show-module",
.json = true,
.nlfunc = nl_gmodule,
.help = "Show transceiver module settings",
},
{
.opts = "--set-module",
.nlfunc = nl_smodule,
.help = "Set transceiver module settings",
.xhelp = " [ power-mode-policy high|auto ]\n"
},
{
.opts = "--get-plca-cfg",
.targets_phy = true,
.nlfunc = nl_plca_get_cfg,
.help = "Get PLCA configuration",
},
{
.opts = "--set-plca-cfg",
.targets_phy = true,
.nlfunc = nl_plca_set_cfg,
.help = "Set PLCA configuration",
.xhelp = " [ enable on|off ]\n"
" [ node-id N ]\n"
" [ node-cnt N ]\n"
" [ to-tmr N ]\n"
" [ burst-cnt N ]\n"
" [ burst-tmr N ]\n"
},
{
.opts = "--get-plca-status",
.targets_phy = true,
.nlfunc = nl_plca_get_status,
.help = "Get PLCA status information",
},
{
.opts = "--show-mm",
.json = true,
.nlfunc = nl_get_mm,
.help = "Show MAC merge layer state",
},
{
.opts = "--set-mm",
.nlfunc = nl_set_mm,
.help = "Set MAC merge layer parameters",
" [ verify-enabled on|off ]\n"
" [ verify-time N ]\n"
" [ tx-enabled on|off ]\n"
" [ pmac-enabled on|off ]\n"
" [ tx-min-frag-size 60-252 ]\n"
},
{
.opts = "--show-pse",
.targets_phy = true,
.json = true,
.nlfunc = nl_gpse,
.help = "Show settings for Power Sourcing Equipment",
},
{
.opts = "--set-pse",
.targets_phy = true,
.nlfunc = nl_spse,
.help = "Set Power Sourcing Equipment settings",
.xhelp = " [ podl-pse-admin-control enable|disable ]\n"
" [ c33-pse-admin-control enable|disable ]\n"
" [ c33-pse-avail-pw-limit N ]\n"
},
{
.opts = "--flash-module-firmware",
.nlfunc = nl_flash_module_fw,
.help = "Flash transceiver module firmware",
.xhelp = " file FILE\n"
" [ pass PASS ]\n"
},
{
.opts = "--show-phys",
.nlfunc = nl_get_phy,
.help = "List PHYs"
},
{
.opts = "-h|--help",
.no_dev = true,
.func = show_usage,
.help = "Show this help"
},
{
.opts = "--version",
.no_dev = true,
.func = do_version,
.help = "Show version number"
},
{}
};
static int show_usage(struct cmd_context *ctx __maybe_unused)
{
int i;
/* ethtool -h */
fprintf(stdout, PACKAGE " version " VERSION "\n");
fprintf(stdout, "Usage:\n");
for (i = 0; args[i].opts; i++) {
fputs(" ethtool [ FLAGS ] ", stdout);
fprintf(stdout, "%s%s %s\t%s\n",
args[i].targets_phy ? "[ --phy PHY ] " : "",
args[i].opts,
args[i].no_dev ? "\t" : "DEVNAME",
args[i].help);
if (args[i].xhelp)
fputs(args[i].xhelp, stdout);
}
nl_monitor_usage();
fprintf(stdout, "\n");
fprintf(stdout, "FLAGS:\n");
fprintf(stdout, " --debug MASK turn on debugging messages\n");
fprintf(stdout, " -j|--json enable JSON output format (not supported by all commands)\n");
fprintf(stdout, " -I|--include-statistics request device statistics related to the command (not supported by all commands)\n");
return 0;
}
static int find_option(char *arg)
{
const char *opt;
size_t len;
int k;
for (k = 1; args[k].opts; k++) {
opt = args[k].opts;
for (;;) {
len = strcspn(opt, "|");
if (strncmp(arg, opt, len) == 0 && arg[len] == 0)
return k;
if (opt[len] == 0)
break;
opt += len + 1;
}
}
return -1;
}
#define MAX(x, y) (x > y ? x : y)
static int find_max_num_queues(struct cmd_context *ctx)
{
struct ethtool_channels echannels;
echannels.cmd = ETHTOOL_GCHANNELS;
if (send_ioctl(ctx, &echannels))
return -1;
return MAX(echannels.rx_count, echannels.tx_count) +
echannels.combined_count;
}
static struct ethtool_per_queue_op *
get_per_queue_coalesce(struct cmd_context *ctx, __u32 *queue_mask, int n_queues)
{
struct ethtool_per_queue_op *per_queue_opt;
per_queue_opt = malloc(sizeof(*per_queue_opt) + n_queues *
sizeof(struct ethtool_coalesce));
if (!per_queue_opt)
return NULL;
memcpy(per_queue_opt->queue_mask, queue_mask,
__KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32) * sizeof(__u32));
per_queue_opt->cmd = ETHTOOL_PERQUEUE;
per_queue_opt->sub_command = ETHTOOL_GCOALESCE;
if (send_ioctl(ctx, per_queue_opt)) {
free(per_queue_opt);
perror("Cannot get device per queue parameters");
return NULL;
}
return per_queue_opt;
}
static void set_per_queue_coalesce(struct cmd_context *ctx,
struct ethtool_per_queue_op *per_queue_opt,
int n_queues)
{
struct ethtool_coalesce ecoal;
DECLARE_COALESCE_OPTION_VARS();
struct cmdline_info cmdline_coalesce[] = COALESCE_CMDLINE_INFO(ecoal);
__u32 *queue_mask = per_queue_opt->queue_mask;
struct ethtool_coalesce *ecoal_q;
int gcoalesce_changed = 0;
int i, idx = 0;
parse_generic_cmdline(ctx, &gcoalesce_changed,
cmdline_coalesce, ARRAY_SIZE(cmdline_coalesce));
ecoal_q = (struct ethtool_coalesce *)(per_queue_opt + 1);
for (i = 0; i < __KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32); i++) {
int queue = i * 32;
__u32 mask = queue_mask[i];
while (mask > 0) {
if (mask & 0x1) {
int changed = 0;
memcpy(&ecoal, ecoal_q + idx,
sizeof(struct ethtool_coalesce));
do_generic_set(cmdline_coalesce,
ARRAY_SIZE(cmdline_coalesce),
&changed);
if (!changed)
fprintf(stderr,
"Queue %d, no coalesce parameters changed\n",
queue);
memcpy(ecoal_q + idx, &ecoal,
sizeof(struct ethtool_coalesce));
idx++;
}
mask = mask >> 1;
queue++;
}
if (idx == n_queues)
break;
}
per_queue_opt->cmd = ETHTOOL_PERQUEUE;
per_queue_opt->sub_command = ETHTOOL_SCOALESCE;
if (send_ioctl(ctx, per_queue_opt))
perror("Cannot set device per queue parameters");
}
static int do_perqueue(struct cmd_context *ctx)
{
struct ethtool_per_queue_op *per_queue_opt;
__u32 queue_mask[__KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32)] = {0};
int i, n_queues = 0;
if (ctx->argc == 0)
exit_bad_args();
/*
* The sub commands will be applied to
* all queues if no queue_mask set
*/
if (strncmp(*ctx->argp, "queue_mask", 11)) {
n_queues = find_max_num_queues(ctx);
if (n_queues < 0) {
perror("Cannot get number of queues");
return -EFAULT;
} else if (n_queues > MAX_NUM_QUEUE) {
n_queues = MAX_NUM_QUEUE;
}
for (i = 0; i < n_queues / 32; i++)
queue_mask[i] = ~0;
if (n_queues % 32)
queue_mask[i] = (1 << (n_queues - i * 32)) - 1;
fprintf(stdout,
"The sub commands will be applied to all %d queues\n",
n_queues);
} else {
if (ctx->argc <= 2)
exit_bad_args();
ctx->argc--;
ctx->argp++;
if (parse_hex_u32_bitmap(*ctx->argp, MAX_NUM_QUEUE,
queue_mask)) {
fprintf(stdout, "Invalid queue mask\n");
return -1;
}
for (i = 0; i < __KERNEL_DIV_ROUND_UP(MAX_NUM_QUEUE, 32); i++) {
__u32 mask = queue_mask[i];
while (mask > 0) {
if (mask & 0x1)
n_queues++;
mask = mask >> 1;
}
}
ctx->argc--;
ctx->argp++;
}
i = find_option(ctx->argp[0]);
if (i < 0)
exit_bad_args();
if (strstr(args[i].opts, "--show-coalesce") != NULL) {
per_queue_opt = get_per_queue_coalesce(ctx, queue_mask,
n_queues);
if (per_queue_opt == NULL) {
perror("Cannot get device per queue parameters");
return -EFAULT;
}
dump_per_queue_coalesce(per_queue_opt, queue_mask, n_queues);
free(per_queue_opt);
} else if (strstr(args[i].opts, "--coalesce") != NULL) {
ctx->argc--;
ctx->argp++;
per_queue_opt = get_per_queue_coalesce(ctx, queue_mask,
n_queues);
if (per_queue_opt == NULL) {
perror("Cannot get device per queue parameters");
return -EFAULT;
}
set_per_queue_coalesce(ctx, per_queue_opt, n_queues);
free(per_queue_opt);
} else {
perror("The subcommand is not supported yet");
return -EOPNOTSUPP;
}
return 0;
}
int ioctl_init(struct cmd_context *ctx, bool no_dev)
{
if (no_dev) {
ctx->fd = -1;
return 0;
}
if (strlen(ctx->devname) >= IFNAMSIZ) {
fprintf(stderr, "Device name longer than %u characters\n",
IFNAMSIZ - 1);
exit_bad_args();
}
/* Setup our control structures. */
memset(&ctx->ifr, 0, sizeof(ctx->ifr));
strcpy(ctx->ifr.ifr_name, ctx->devname);
/* Open control socket. */
ctx->fd = socket(AF_INET, SOCK_DGRAM, 0);
if (ctx->fd < 0)
ctx->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (ctx->fd < 0) {
perror("Cannot get control socket");
return 70;
}
return 0;
}
int main(int argc, char **argp)
{
struct cmd_context ctx = {};
int ret;
int k;
init_global_link_mode_masks();
if (argc < 2)
exit_bad_args();
/* Skip command name */
argp++;
argc--;
while (true) {
if (*argp && !strcmp(*argp, "--debug")) {
char *eptr;
if (argc < 2)
exit_bad_args();
ctx.debug = strtoul(argp[1], &eptr, 0);
if (!argp[1][0] || *eptr)
exit_bad_args();
argp += 2;
argc -= 2;
continue;
}
if (*argp && !strcmp(*argp, "--disable-netlink")) {
ctx.nl_disable = true;
argp += 1;
argc -= 1;
continue;
}
if (*argp && (!strcmp(*argp, "--json") ||
!strcmp(*argp, "-j"))) {
ctx.json = true;
argp += 1;
argc -= 1;
continue;
}
if (*argp && (!strcmp(*argp, "--include-statistics") ||
!strcmp(*argp, "-I"))) {
ctx.show_stats = true;
argp += 1;
argc -= 1;
continue;
}
if (*argp && !strcmp(*argp, "--phy")) {
char *eptr;
if (argc < 2)
exit_bad_args_info("--phy parameters expects a phy index");
ctx.phy_index = strtoul(argp[1], &eptr, 0);
if (!argp[1][0] || *eptr)
exit_bad_args_info("invalid phy index");
argp += 2;
argc -= 2;
continue;
}
break;
}
if (*argp && !strcmp(*argp, "--monitor")) {
ctx.argp = ++argp;
ctx.argc = --argc;
ret = nl_monitor(&ctx);
return ret ? 1 : 0;
}
/* First argument must be either a valid option or a device
* name to get settings for (which we don't expect to begin
* with '-').
*/
if (!*argp)
exit_bad_args();
k = find_option(*argp);
if (k > 0) {
argp++;
argc--;
} else {
if ((*argp)[0] == '-')
exit_bad_args();
k = 0;
}
if (!args[k].no_dev) {
ctx.devname = *argp++;
argc--;
if (!ctx.devname)
exit_bad_args();
}
if (ctx.json && !args[k].json)
exit_bad_args_info("JSON output not available for this subcommand");
if (!args[k].targets_phy && ctx.phy_index)
exit_bad_args_info("Unexpected --phy parameter");
ctx.argc = argc;
ctx.argp = argp;
netlink_run_handler(&ctx, args[k].nlchk, args[k].nlfunc, !args[k].func);
if (ctx.json) /* no IOCTL command supports JSON output */
exit_nlonly_param("--json");
ret = ioctl_init(&ctx, args[k].no_dev);
if (ret)
return ret;
return args[k].func(&ctx);
}
|