aboutsummaryrefslogtreecommitdiffstats
path: root/package/kernel/mac80211/patches/405-ath_regd_us.patch
Commit message (Expand)AuthorAgeFilesLines
* mac80211: update to 2014-10-08Felix Fietkau2014-10-181-0/+26
27'>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
/******************************************************************************/
/*                                                                            */
/* Broadcom BCM5700 Linux Network Driver, Copyright (c) 2000 - 2005 Broadcom  */
/* Corporation.                                                               */
/* All rights reserved.                                                       */
/*                                                                            */
/* This program is free software; you can redistribute it and/or modify       */
/* it under the terms of the GNU General Public License as published by       */
/* the Free Software Foundation, located in the file LICENSE.                 */
/*                                                                            */
/******************************************************************************/

/* $Id: b57um.c,v 1.32 2007/09/06 07:28:06 yogo Exp $ */

char bcm5700_driver[] = "bcm57xx";
char bcm5700_version[] = "8.3.14";
char bcm5700_date[] = "(11/2/05)";

#define B57UM
#include "mm.h"
#include "linux/mii.h" //@.@jack add it 2006/06/28.
#include "typedefs.h"
#include "osl.h"
#include "bcmdefs.h"
#include "bcmdevs.h"
#include "sbconfig.h"
#include "sbutils.h"
#include "hndgige.h"
#include "bcmrobo.h"
#include "robo_register.c"

#include "bcmendian.h"
#include "bcmnvram.h"
#include "proto/ethernet.h"
#include "proto/vlan.h"
#include "proto/bcmtcp.h"
#include "proto/bcmip.h"
#define	PKTDATA(osh, skb)		(((struct sk_buff*)(skb))->data)

/* this is needed to get good and stable performances */
#define EXTRA_HDR BCMEXTRAHDROOM

#define SIOCGREG_STATUS  0x8996          /* Read Switch register (for debug)*/
#define SIOCSREG_STATUS  0x8997          /* Write Switch register(for debug)*/

/* This structure is used in SIOCXREG_STATUS ioctl calls*/
struct reg_ioctl_data {
        u16             page_num;
        u16             addr_num;
        u16             len;
	u16		val_in[4];
	u16		val_out[4];
};

/* A few user-configurable values. */

#define MAX_UNITS 16
/* Used to pass the full-duplex flag, etc. */
static int line_speed[MAX_UNITS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static int auto_speed[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
static int full_duplex[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
static int rx_flow_control[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
static int tx_flow_control[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
static int auto_flow_control[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
static int mtu[MAX_UNITS] = {1500,1500,1500,1500,1500,1500,1500,1500,1500,1500,1500,1500,1500,1500,1500,1500};	/* Jumbo MTU for interfaces. */
#endif
static int tx_checksum[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
static int rx_checksum[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
static int scatter_gather[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
static int activate_gpio = -1;

#define TX_DESC_CNT DEFAULT_TX_PACKET_DESC_COUNT
static unsigned int tx_pkt_desc_cnt[MAX_UNITS] =
	{TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,
	TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,
	TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT,
	TX_DESC_CNT};

#define RX_DESC_CNT DEFAULT_STD_RCV_DESC_COUNT
static unsigned int rx_std_desc_cnt[MAX_UNITS] =
	{RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,
	RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,
	RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,
	RX_DESC_CNT };

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
#define JBO_DESC_CNT DEFAULT_JUMBO_RCV_DESC_COUNT
static unsigned int rx_jumbo_desc_cnt[MAX_UNITS] =
	{JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,
	JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,
	JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,JBO_DESC_CNT,
	JBO_DESC_CNT };
#endif

#ifdef BCM_INT_COAL
#ifdef BCM_NAPI_RXPOLL
static unsigned int adaptive_coalesce[MAX_UNITS] =
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
#else
static unsigned int adaptive_coalesce[MAX_UNITS] =
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
#endif

#define RX_COAL_TK DEFAULT_RX_COALESCING_TICKS
static unsigned int rx_coalesce_ticks[MAX_UNITS] =
	{RX_COAL_TK,RX_COAL_TK,RX_COAL_TK,RX_COAL_TK,RX_COAL_TK,
	RX_COAL_TK, RX_COAL_TK,RX_COAL_TK,RX_COAL_TK,RX_COAL_TK,
	RX_COAL_TK,RX_COAL_TK, RX_COAL_TK,RX_COAL_TK,RX_COAL_TK,
	RX_COAL_TK};

#define RX_COAL_FM DEFAULT_RX_MAX_COALESCED_FRAMES
static unsigned int rx_max_coalesce_frames[MAX_UNITS] =
	{RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,
	RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,
	RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,RX_COAL_FM,
	RX_COAL_FM};

#define TX_COAL_TK DEFAULT_TX_COALESCING_TICKS
static unsigned int tx_coalesce_ticks[MAX_UNITS] =
	{TX_COAL_TK,TX_COAL_TK,TX_COAL_TK,TX_COAL_TK,TX_COAL_TK,
	TX_COAL_TK, TX_COAL_TK,TX_COAL_TK,TX_COAL_TK,TX_COAL_TK,
	TX_COAL_TK,TX_COAL_TK, TX_COAL_TK,TX_COAL_TK,TX_COAL_TK,
	TX_COAL_TK};

#define TX_COAL_FM DEFAULT_TX_MAX_COALESCED_FRAMES
static unsigned int tx_max_coalesce_frames[MAX_UNITS] =
	{TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,
	TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,
	TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,TX_COAL_FM,
	TX_COAL_FM};

#define ST_COAL_TK DEFAULT_STATS_COALESCING_TICKS
static unsigned int stats_coalesce_ticks[MAX_UNITS] =
	{ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,
	ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,
	ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,ST_COAL_TK,
	ST_COAL_TK,};

#endif
#ifdef BCM_WOL
static int enable_wol[MAX_UNITS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
#endif
#ifdef BCM_TSO
static int enable_tso[MAX_UNITS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
#endif
#ifdef BCM_NIC_SEND_BD
static int nic_tx_bd[MAX_UNITS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
#endif
#ifdef BCM_ASF
static int vlan_tag_mode[MAX_UNITS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
#endif
static int delay_link[MAX_UNITS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static int disable_d3hot[MAX_UNITS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)
static int disable_msi[MAX_UNITS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static int bcm_msi_chipset_bug = 0;
#endif

#define BCM_TIMER_GRANULARITY  (1000000 / HZ)

/* Hack to hook the data path to the BCM WL dirver */
#ifdef BCM_WL_EMULATOR
#include "bcmnvram.h"
#include "wl_bcm57emu.h" 
#ifdef SKB_MANAGER
int skb_old_alloc = 0;
#endif
#endif /* BCM_WL_EMULATOR */

/* Operational parameters that usually are not changed. */
/* Time in jiffies before concluding the transmitter is hung. */
#define TX_TIMEOUT  (2*HZ)

#if (LINUX_VERSION_CODE < 0x02030d)
#define pci_resource_start(dev, bar)	(dev->base_address[bar] & PCI_BASE_ADDRESS_MEM_MASK)
#elif (LINUX_VERSION_CODE < 0x02032b)
#define pci_resource_start(dev, bar)	(dev->resource[bar] & PCI_BASE_ADDRESS_MEM_MASK)
#endif

#if (LINUX_VERSION_CODE < 0x02032b)
#define dev_kfree_skb_irq(skb)  dev_kfree_skb(skb)
#define netif_wake_queue(dev)	clear_bit(0, &dev->tbusy); mark_bh(NET_BH)
#define netif_stop_queue(dev)	set_bit(0, &dev->tbusy)

static inline void netif_start_queue(struct net_device *dev)
{
	dev->tbusy = 0;
	dev->interrupt = 0;
	dev->start = 1;
}

#define netif_queue_stopped(dev)	dev->tbusy
#define netif_running(dev)		dev->start

static inline void tasklet_schedule(struct tasklet_struct *tasklet)
{
	queue_task(tasklet, &tq_immediate);
	mark_bh(IMMEDIATE_BH);
}

static inline void tasklet_init(struct tasklet_struct *tasklet,
				void (*func)(unsigned long),
				unsigned long data)
{
		tasklet->next = NULL;
		tasklet->sync = 0;
		tasklet->routine = (void (*)(void *))func;
		tasklet->data = (void *)data;
}

#define tasklet_kill(tasklet)

#endif

#if (LINUX_VERSION_CODE < 0x020300)
struct pci_device_id {
	unsigned int vendor, device;		/* Vendor and device ID or PCI_ANY_ID */
	unsigned int subvendor, subdevice;	/* Subsystem ID's or PCI_ANY_ID */
	unsigned int class, class_mask;		/* (class,subclass,prog-if) triplet */
	unsigned long driver_data;		/* Data private to the driver */
};

#define PCI_ANY_ID		0

#define pci_set_drvdata(pdev, dev)
#define pci_get_drvdata(pdev) 0

#define pci_enable_device(pdev) 0

#define __devinit		__init
#define __devinitdata		__initdata
#define __devexit

#define SET_MODULE_OWNER(dev)
#define MODULE_DEVICE_TABLE(pci, pci_tbl)

#endif

#if (LINUX_VERSION_CODE < 0x020411)
#ifndef __devexit_p
#define __devexit_p(x)	x
#endif
#endif

#ifndef MODULE_LICENSE
#define MODULE_LICENSE(license)
#endif

#ifndef IRQ_RETVAL
typedef void irqreturn_t;
#define IRQ_RETVAL(x)
#endif

#if (LINUX_VERSION_CODE < 0x02032a)
static inline void *pci_alloc_consistent(struct pci_dev *pdev, size_t size,
					 dma_addr_t *dma_handle)
{
	void *virt_ptr;

	/* Maximum in slab.c */
	if (size > 131072)
		return 0;

	virt_ptr = kmalloc(size, GFP_KERNEL);
	*dma_handle = virt_to_bus(virt_ptr);
	return virt_ptr;
}
#define pci_free_consistent(dev, size, ptr, dma_ptr)	kfree(ptr)

#endif /*#if (LINUX_VERSION_CODE < 0x02032a) */


#if (LINUX_VERSION_CODE < 0x02040d)

#if (LINUX_VERSION_CODE >= 0x020409) && defined(RED_HAT_LINUX_KERNEL)

#define BCM_32BIT_DMA_MASK ((u64) 0x00000000ffffffffULL)
#define BCM_64BIT_DMA_MASK ((u64) 0xffffffffffffffffULL)

#else
/* pci_set_dma_mask is using dma_addr_t */

#define BCM_32BIT_DMA_MASK ((dma_addr_t) 0xffffffff)
#define BCM_64BIT_DMA_MASK ((dma_addr_t) 0xffffffff)

#endif

#else /* (LINUX_VERSION_CODE < 0x02040d) */

#define BCM_32BIT_DMA_MASK ((u64) 0x00000000ffffffffULL)
#define BCM_64BIT_DMA_MASK ((u64) 0xffffffffffffffffULL)
#endif

#if (LINUX_VERSION_CODE < 0x020329)
#define pci_set_dma_mask(pdev, mask) (0)
#else
#if (LINUX_VERSION_CODE < 0x020403)
int
pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask)
{
    if(! pci_dma_supported(dev, mask))
        return -EIO;

    dev->dma_mask = mask;

    return 0;
}
#endif
#endif

#if (LINUX_VERSION_CODE < 0x020547)
#define pci_set_consistent_dma_mask(pdev, mask) (0)
#endif

#if (LINUX_VERSION_CODE < 0x020402)
#define pci_request_regions(pdev, name) (0)
#define pci_release_regions(pdev)
#endif

#if !defined(spin_is_locked)
#define spin_is_locked(lock)    (test_bit(0,(lock)))
#endif

#define BCM5700_LOCK(pUmDevice, flags)					\
	if ((pUmDevice)->do_global_lock) {				\
		spin_lock_irqsave(&(pUmDevice)->global_lock, flags);	\
	}

#define BCM5700_UNLOCK(pUmDevice, flags)				\
	if ((pUmDevice)->do_global_lock) {				\
		spin_unlock_irqrestore(&(pUmDevice)->global_lock, flags);\
	}

inline void
bcm5700_intr_lock(PUM_DEVICE_BLOCK pUmDevice)
{
	if (pUmDevice->do_global_lock) {
		spin_lock(&pUmDevice->global_lock);
	}
}

inline void
bcm5700_intr_unlock(PUM_DEVICE_BLOCK pUmDevice)
{
	if (pUmDevice->do_global_lock) {
		spin_unlock(&pUmDevice->global_lock);
	}
}

void
bcm5700_intr_off(PUM_DEVICE_BLOCK pUmDevice)
{
	atomic_inc(&pUmDevice->intr_sem);
	LM_DisableInterrupt(&pUmDevice->lm_dev);
#if (LINUX_VERSION_CODE >= 0x2051c)
	synchronize_irq(pUmDevice->dev->irq);
#else
	synchronize_irq();
#endif
	LM_DisableInterrupt(&pUmDevice->lm_dev);
}

void
bcm5700_intr_on(PUM_DEVICE_BLOCK pUmDevice)
{
	if (atomic_dec_and_test(&pUmDevice->intr_sem)) {
		LM_EnableInterrupt(&pUmDevice->lm_dev);
	}
}


int MM_Packet_Desc_Size = sizeof(UM_PACKET);

#if defined(MODULE)
MODULE_AUTHOR("Michael Chan <mchan at broadcom dot com> and Gary Zambrano <zambrano at broadcom dot com>");
MODULE_DESCRIPTION("BCM5700 Driver");
MODULE_LICENSE("GPL");

#if (LINUX_VERSION_CODE < 0x020605)

MODULE_PARM(debug, "i");
MODULE_PARM(msglevel, "i");
MODULE_PARM(activate_gpio, "0-15i");
MODULE_PARM(line_speed, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(auto_speed, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(rx_flow_control, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(tx_flow_control, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(auto_flow_control, "1-" __MODULE_STRING(MAX_UNITS) "i");
#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
MODULE_PARM(mtu, "1-" __MODULE_STRING(MAX_UNITS) "i");
#endif
MODULE_PARM(tx_checksum, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(rx_checksum, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(scatter_gather, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(tx_pkt_desc_cnt, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(rx_std_desc_cnt, "1-" __MODULE_STRING(MAX_UNITS) "i");
#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
MODULE_PARM(rx_jumbo_desc_cnt, "1-" __MODULE_STRING(MAX_UNITS) "i");
#endif
#ifdef BCM_INT_COAL
MODULE_PARM(adaptive_coalesce, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(rx_coalesce_ticks, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(rx_max_coalesce_frames, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(tx_coalesce_ticks, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(tx_max_coalesce_frames, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(stats_coalesce_ticks, "1-" __MODULE_STRING(MAX_UNITS) "i");
#endif
#ifdef BCM_WOL
MODULE_PARM(enable_wol, "1-" __MODULE_STRING(MAX_UNITS) "i");
#endif
#ifdef BCM_TSO
MODULE_PARM(enable_tso, "1-" __MODULE_STRING(MAX_UNITS) "i");
#endif
#ifdef BCM_NIC_SEND_BD
MODULE_PARM(nic_tx_bd, "1-" __MODULE_STRING(MAX_UNITS) "i");
#endif
#ifdef BCM_ASF
MODULE_PARM(vlan_tag_mode, "1-" __MODULE_STRING(MAX_UNITS) "i");
#endif
MODULE_PARM(delay_link, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(disable_d3hot, "1-" __MODULE_STRING(MAX_UNITS) "i");

#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)
MODULE_PARM(disable_msi, "1-" __MODULE_STRING(MAX_UNITS) "i");
#endif

#else /* parms*/

#if (LINUX_VERSION_CODE >= 0x020605) && (LINUX_VERSION_CODE < 0x02060a)

static int var;

#define numvar var

#endif

#if (LINUX_VERSION_CODE >= 0x2060a)

#define numvar NULL

#endif

module_param_array(line_speed, int, numvar, 0);
module_param_array(auto_speed, int, numvar, 0);
module_param_array(full_duplex, int, numvar, 0);
module_param_array(rx_flow_control, int, numvar, 0);
module_param_array(tx_flow_control, int, numvar, 0);
module_param_array(auto_flow_control, int, numvar, 0);
#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
module_param_array(mtu, int, numvar, 0);
#endif
module_param_array(tx_checksum, int, numvar, 0);
module_param_array(rx_checksum, int, numvar, 0);
module_param_array(scatter_gather, int, numvar, 0);
module_param_array(tx_pkt_desc_cnt, int, numvar, 0);
module_param_array(rx_std_desc_cnt, int, numvar, 0);
#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
module_param_array(rx_jumbo_desc_cnt, int, numvar, 0);
#endif
#ifdef BCM_INT_COAL
module_param_array(adaptive_coalesce, int, numvar, 0);
module_param_array(rx_coalesce_ticks, int, numvar, 0);
module_param_array(rx_max_coalesce_frames, int, numvar, 0);
module_param_array(tx_coalesce_ticks, int, numvar, 0);
module_param_array(tx_max_coalesce_frames, int, numvar, 0);
module_param_array(stats_coalesce_ticks, int, numvar, 0);
#endif
#ifdef BCM_WOL
module_param_array(enable_wol, int, numvar, 0);
#endif
#ifdef BCM_TSO
module_param_array(enable_tso, int, numvar, 0);
#endif
#ifdef BCM_NIC_SEND_BD
module_param_array(nic_tx_bd, int, numvar, 0);
#endif
#ifdef BCM_ASF
module_param_array(vlan_tag_mode, int, numvar, 0);
#endif
module_param_array(delay_link, int, numvar, 0);
module_param_array(disable_d3hot, int, numvar, 0);

#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)
module_param_array(disable_msi, int, numvar, 0);
#endif


#endif /* params */


#endif

#define RUN_AT(x) (jiffies + (x))

char kernel_version[] = UTS_RELEASE;

#define PCI_SUPPORT_VER2

#if !defined(CAP_NET_ADMIN)
#define capable(CAP_XXX) (suser())
#endif

#define tigon3_debug debug
#if TIGON3_DEBUG
static int tigon3_debug = TIGON3_DEBUG;
#else
static int tigon3_debug = 0;
#endif
static int msglevel = 0xdeadbeef;
int b57_msg_level;

int bcm5700_open(struct net_device *dev);
STATIC void bcm5700_timer(unsigned long data);
STATIC void bcm5700_stats_timer(unsigned long data);
STATIC void bcm5700_reset(struct net_device *dev);
STATIC int bcm5700_start_xmit(struct sk_buff *skb, struct net_device *dev);
STATIC irqreturn_t bcm5700_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
#ifdef BCM_TASKLET
STATIC void bcm5700_tasklet(unsigned long data);
#endif
STATIC int bcm5700_close(struct net_device *dev);
STATIC struct net_device_stats *bcm5700_get_stats(struct net_device *dev);
STATIC int bcm5700_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
STATIC void bcm5700_do_rx_mode(struct net_device *dev);
STATIC void bcm5700_set_rx_mode(struct net_device *dev);
STATIC int bcm5700_set_mac_addr(struct net_device *dev, void *p);
#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
STATIC int bcm5700_change_mtu(struct net_device *dev, int new_mtu);
#endif
#ifdef BCM_NAPI_RXPOLL
STATIC int bcm5700_poll(struct net_device *dev, int *budget);
#endif
STATIC int replenish_rx_buffers(PUM_DEVICE_BLOCK pUmDevice, int max);
STATIC int bcm5700_freemem(struct net_device *dev);
#ifdef BCM_INT_COAL
#ifndef BCM_NAPI_RXPOLL
STATIC int bcm5700_adapt_coalesce(PUM_DEVICE_BLOCK pUmDevice);
#endif
#endif
STATIC void bcm5700_set_vlan_mode(UM_DEVICE_BLOCK *pUmDevice);
STATIC int bcm5700_init_counters(PUM_DEVICE_BLOCK pUmDevice);
#ifdef BCM_VLAN
STATIC void bcm5700_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp);
STATIC void bcm5700_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid);
#endif
void bcm5700_shutdown(UM_DEVICE_BLOCK *pUmDevice);
void bcm5700_free_remaining_rx_bufs(UM_DEVICE_BLOCK *pUmDevice);
void bcm5700_validate_param_range(UM_DEVICE_BLOCK *pUmDevice, int *param,
	char *param_name, int min, int max, int deflt);

static int bcm5700_notify_reboot(struct notifier_block *this, unsigned long event, void *unused);
static struct notifier_block bcm5700_reboot_notifier = {
	bcm5700_notify_reboot,
	NULL,
	0
};

#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
STATIC void poll_bcm5700(struct net_device *dev);
#endif

/* A list of all installed bcm5700 devices. */
static struct net_device *root_tigon3_dev = NULL;

#if defined(CONFIG_SPARC64) || defined(CONFIG_X86_64) ||defined(CONFIG_PPC64)

#endif

typedef enum {
	BCM5700A6 = 0,
	BCM5700T6,
	BCM5700A9,
	BCM5700T9,
	BCM5700,
	BCM5701A5,
	BCM5701T1,
	BCM5701T8,
	BCM5701A7,
	BCM5701A10,
	BCM5701A12,
	BCM5701,
	BCM5702,
	BCM5703,
	BCM5703A31,
	BCM5703ARBUCKLE,
	TC996T,
	TC996ST,
	TC996SSX,
	TC996SX,
	TC996BT,
	TC997T,
	TC997SX,
	TC1000T,
	TC1000BT,
	TC940BR01,
	TC942BR01,
	TC998T,
	TC998SX,
	TC999T,
	NC6770,
	NC1020,
	NC150T,
	NC7760,
	NC7761,
	NC7770,
	NC7771,
	NC7780,
	NC7781,
	NC7772,
	NC7782,
	NC7783,
	NC320T,
	NC320I,
	NC325I,
	NC324I,
	NC326I,
	BCM5704CIOBE,
	BCM5704,
	BCM5704S,
	BCM5705,
	BCM5705M,
	BCM5705F,
	BCM5901,
	BCM5782,
	BCM5788,
	BCM5789,
	BCM5750,
	BCM5750M,
	BCM5720,
	BCM5751,
	BCM5751M,
	BCM5751F,
	BCM5721,
	BCM5753,
	BCM5753M,
	BCM5753F,
	BCM5781,
	BCM5752,
	BCM5752M,
	BCM5714,
	BCM5780,
	BCM5780S,
	BCM5715,
	BCM4785,
	BCM5903M,
	UNK5788
} board_t;


/* indexed by board_t, above */
static struct {
	char *name;
} board_info[] __devinitdata = {
	{ "Broadcom BCM5700 1000Base-T" },
	{ "Broadcom BCM5700 1000Base-SX" },
	{ "Broadcom BCM5700 1000Base-SX" },
	{ "Broadcom BCM5700 1000Base-T" },
	{ "Broadcom BCM5700" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-SX" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701" },
	{ "Broadcom BCM5702 1000Base-T" },
	{ "Broadcom BCM5703 1000Base-T" },
	{ "Broadcom BCM5703 1000Base-SX" },
	{ "Broadcom B5703 1000Base-SX" },
	{ "3Com 3C996 10/100/1000 Server NIC" },
	{ "3Com 3C996 10/100/1000 Server NIC" },
	{ "3Com 3C996 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C996 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C996B Gigabit Server NIC" },
	{ "3Com 3C997 Gigabit Server NIC" },
	{ "3Com 3C997 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C1000 Gigabit NIC" },
	{ "3Com 3C1000B-T 10/100/1000 PCI" },
	{ "3Com 3C940 Gigabit LOM (21X21)" },
	{ "3Com 3C942 Gigabit LOM (31X31)" },
	{ "3Com 3C998-T Dual Port 10/100/1000 PCI-X Server NIC" },
	{ "3Com 3C998-SX Dual Port 1000-SX PCI-X Server NIC" },
	{ "3Com 3C999-T Quad Port 10/100/1000 PCI-X Server NIC" },
	{ "HP NC6770 Gigabit Server Adapter" },
	{ "NC1020 HP ProLiant Gigabit Server Adapter 32 PCI" },
	{ "HP ProLiant NC 150T PCI 4-port Gigabit Combo Switch Adapter" },
	{ "HP NC7760 Gigabit Server Adapter" },
	{ "HP NC7761 Gigabit Server Adapter" },
	{ "HP NC7770 Gigabit Server Adapter" },
	{ "HP NC7771 Gigabit Server Adapter" },
	{ "HP NC7780 Gigabit Server Adapter" },
	{ "HP NC7781 Gigabit Server Adapter" },
	{ "HP NC7772 Gigabit Server Adapter" },
	{ "HP NC7782 Gigabit Server Adapter" },
	{ "HP NC7783 Gigabit Server Adapter" },
	{ "HP ProLiant NC 320T PCI Express Gigabit Server Adapter" },
	{ "HP ProLiant NC 320i PCI Express Gigabit Server Adapter" },
	{ "HP NC325i Integrated Dual Port PCI Express Gigabit Server Adapter" },
	{ "HP NC324i Integrated Dual Port PCI Express Gigabit Server Adapter" },
	{ "HP NC326i Integrated Dual Port PCI Express Gigabit Server Adapter" },
	{ "Broadcom BCM5704 CIOB-E 1000Base-T" },
	{ "Broadcom BCM5704 1000Base-T" },
	{ "Broadcom BCM5704 1000Base-SX" },
	{ "Broadcom BCM5705 1000Base-T" },
	{ "Broadcom BCM5705M 1000Base-T" },
	{ "Broadcom 570x 10/100 Integrated Controller" },
	{ "Broadcom BCM5901 100Base-TX" },
	{ "Broadcom NetXtreme Gigabit Ethernet for hp" },
	{ "Broadcom BCM5788 NetLink 1000Base-T" },
	{ "Broadcom BCM5789 NetLink 1000Base-T PCI Express" },
	{ "Broadcom BCM5750 1000Base-T PCI" },
	{ "Broadcom BCM5750M 1000Base-T PCI" },
	{ "Broadcom BCM5720 1000Base-T PCI" },
	{ "Broadcom BCM5751 1000Base-T PCI Express" },
	{ "Broadcom BCM5751M 1000Base-T PCI Express" },
	{ "Broadcom BCM5751F 100Base-TX PCI Express" },
	{ "Broadcom BCM5721 1000Base-T PCI Express" },
	{ "Broadcom BCM5753 1000Base-T PCI Express" },
	{ "Broadcom BCM5753M 1000Base-T PCI Express" },
	{ "Broadcom BCM5753F 100Base-TX PCI Express" },
	{ "Broadcom BCM5781 NetLink 1000Base-T PCI Express" },
	{ "Broadcom BCM5752 1000Base-T PCI Express" },
	{ "Broadcom BCM5752M 1000Base-T PCI Express" },
	{ "Broadcom BCM5714 1000Base-T " },
	{ "Broadcom BCM5780 1000Base-T" },
	{ "Broadcom BCM5780S 1000Base-SX" },
	{ "Broadcom BCM5715 1000Base-T " },
	{ "Broadcom BCM4785 10/100/1000 Integrated Controller" },
	{ "Broadcom BCM5903M Gigabit Ethernet " },
	{ "Unknown BCM5788 Gigabit Ethernet " },
	{ 0 }
	};

static struct pci_device_id bcm5700_pci_tbl[] __devinitdata = {
	{0x14e4, 0x1644, 0x14e4, 0x1644, 0, 0, BCM5700A6 },
	{0x14e4, 0x1644, 0x14e4, 0x2, 0, 0, BCM5700T6 },
	{0x14e4, 0x1644, 0x14e4, 0x3, 0, 0, BCM5700A9 },
	{0x14e4, 0x1644, 0x14e4, 0x4, 0, 0, BCM5700T9 },
	{0x14e4, 0x1644, 0x1028, 0xd1, 0, 0, BCM5700 },
	{0x14e4, 0x1644, 0x1028, 0x0106, 0, 0, BCM5700 },
	{0x14e4, 0x1644, 0x1028, 0x0109, 0, 0, BCM5700 },
	{0x14e4, 0x1644, 0x1028, 0x010a, 0, 0, BCM5700 },
	{0x14e4, 0x1644, 0x10b7, 0x1000, 0, 0, TC996T },
	{0x14e4, 0x1644, 0x10b7, 0x1001, 0, 0, TC996ST },
	{0x14e4, 0x1644, 0x10b7, 0x1002, 0, 0, TC996SSX },
	{0x14e4, 0x1644, 0x10b7, 0x1003, 0, 0, TC997T },
	{0x14e4, 0x1644, 0x10b7, 0x1005, 0, 0, TC997SX },
	{0x14e4, 0x1644, 0x10b7, 0x1008, 0, 0, TC942BR01 },
	{0x14e4, 0x1644, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5700 },
	{0x14e4, 0x1645, 0x14e4, 1, 0, 0, BCM5701A5 },
	{0x14e4, 0x1645, 0x14e4, 5, 0, 0, BCM5701T1 },
	{0x14e4, 0x1645, 0x14e4, 6, 0, 0, BCM5701T8 },
	{0x14e4, 0x1645, 0x14e4, 7, 0, 0, BCM5701A7 },
	{0x14e4, 0x1645, 0x14e4, 8, 0, 0, BCM5701A10 },
	{0x14e4, 0x1645, 0x14e4, 0x8008, 0, 0, BCM5701A12 },
	{0x14e4, 0x1645, 0x0e11, 0xc1, 0, 0, NC6770 },
	{0x14e4, 0x1645, 0x0e11, 0x7c, 0, 0, NC7770 },
	{0x14e4, 0x1645, 0x0e11, 0x85, 0, 0, NC7780 },
	{0x14e4, 0x1645, 0x1028, 0x0121, 0, 0, BCM5701 },
	{0x14e4, 0x1645, 0x10b7, 0x1004, 0, 0, TC996SX },
	{0x14e4, 0x1645, 0x10b7, 0x1006, 0, 0, TC996BT },
	{0x14e4, 0x1645, 0x10b7, 0x1007, 0, 0, TC1000T },
	{0x14e4, 0x1645, 0x10b7, 0x1008, 0, 0, TC940BR01 },
	{0x14e4, 0x1645, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5701 },
	{0x14e4, 0x1646, 0x14e4, 0x8009, 0, 0, BCM5702 },
	{0x14e4, 0x1646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702 },
	{0x14e4, 0x16a6, 0x14e4, 0x8009, 0, 0, BCM5702 },
	{0x14e4, 0x16a6, 0x14e4, 0x000c, 0, 0, BCM5702 },
	{0x14e4, 0x16a6, 0x0e11, 0xbb, 0, 0, NC7760 },
	{0x14e4, 0x16a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702 },
	{0x14e4, 0x16c6, 0x10b7, 0x1100, 0, 0, TC1000BT },
	{0x14e4, 0x16c6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702 },
	{0x14e4, 0x1647, 0x14e4, 0x0009, 0, 0, BCM5703 },
	{0x14e4, 0x1647, 0x14e4, 0x000a, 0, 0, BCM5703A31 },
	{0x14e4, 0x1647, 0x14e4, 0x000b, 0, 0, BCM5703 },
	{0x14e4, 0x1647, 0x14e4, 0x800a, 0, 0, BCM5703 },
	{0x14e4, 0x1647, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703 },
	{0x14e4, 0x16a7, 0x14e4, 0x0009, 0, 0, BCM5703 },
	{0x14e4, 0x16a7, 0x14e4, 0x000a, 0, 0, BCM5703A31 },
	{0x14e4, 0x16a7, 0x14e4, 0x000b, 0, 0, BCM5703 },
	{0x14e4, 0x16a7, 0x14e4, 0x800a, 0, 0, BCM5703 },
	{0x14e4, 0x16a7, 0x0e11, 0xca, 0, 0, NC7771 },
	{0x14e4, 0x16a7, 0x0e11, 0xcb, 0, 0, NC7781 },
	{0x14e4, 0x16a7, 0x1014, 0x0281, 0, 0, BCM5703ARBUCKLE },
	{0x14e4, 0x16a7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703 },
	{0x14e4, 0x16c7, 0x14e4, 0x000a, 0, 0, BCM5703A31 },
	{0x14e4, 0x16c7, 0x0e11, 0xca, 0, 0, NC7771 },
	{0x14e4, 0x16c7, 0x0e11, 0xcb, 0, 0, NC7781 },
	{0x14e4, 0x16c7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703 },
	{0x14e4, 0x1648, 0x0e11, 0xcf, 0, 0, NC7772 },
	{0x14e4, 0x1648, 0x0e11, 0xd0, 0, 0, NC7782 },
	{0x14e4, 0x1648, 0x0e11, 0xd1, 0, 0, NC7783 },
	{0x14e4, 0x1648, 0x10b7, 0x2000, 0, 0, TC998T },
	{0x14e4, 0x1648, 0x10b7, 0x3000, 0, 0, TC999T },
	{0x14e4, 0x1648, 0x1166, 0x1648, 0, 0, BCM5704CIOBE },
	{0x14e4, 0x1648, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5704 },
	{0x14e4, 0x1649, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5704S },
	{0x14e4, 0x16a8, 0x14e4, 0x16a8, 0, 0, BCM5704S },
	{0x14e4, 0x16a8, 0x10b7, 0x2001, 0, 0, TC998SX },
	{0x14e4, 0x16a8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5704S },
	{0x14e4, 0x1653, 0x0e11, 0x00e3, 0, 0, NC7761 },
	{0x14e4, 0x1653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5705 },
	{0x14e4, 0x1654, 0x0e11, 0x00e3, 0, 0, NC7761 },
	{0x14e4, 0x1654, 0x103c, 0x3100, 0, 0, NC1020 },
	{0x14e4, 0x1654, 0x103c, 0x3226, 0, 0, NC150T },
	{0x14e4, 0x1654, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5705 },
	{0x14e4, 0x165d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5705M },
	{0x14e4, 0x165e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5705M },
	{0x14e4, 0x166e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5705F },
	{0x14e4, 0x1696, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5782 },
	{0x14e4, 0x169c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5788 },
	{0x14e4, 0x169d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5789 },
	{0x14e4, 0x170d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5901 },
	{0x14e4, 0x170e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5901 },
	{0x14e4, 0x1676, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5750 },
	{0x14e4, 0x167c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5750M },
	{0x14e4, 0x1677, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5751 },
	{0x14e4, 0x167d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5751M },
	{0x14e4, 0x167e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5751F },
	{0x14e4, 0x1658, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5720 },
	{0x14e4, 0x1659, 0x103c, 0x7031, 0, 0, NC320T },
	{0x14e4, 0x1659, 0x103c, 0x7032, 0, 0, NC320T },
	{0x14e4, 0x166a, 0x103c, 0x7035, 0, 0, NC325I },
	{0x14e4, 0x166b, 0x103c, 0x7036, 0, 0, NC325I },
	{0x14e4, 0x1668, 0x103c, 0x7039, 0, 0, NC324I },
	{0x14e4, 0x1669, 0x103c, 0x703a, 0, 0, NC324I },
	{0x14e4, 0x1678, 0x103c, 0x703e, 0, 0, NC326I },
	{0x14e4, 0x1679, 0x103c, 0x703c, 0, 0, NC326I },
	{0x14e4, 0x1659, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5721 },
	{0x14e4, 0x16f7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5753 },
	{0x14e4, 0x16fd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5753M },
	{0x14e4, 0x16fe, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5753F },
	{0x14e4, 0x16dd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5781 },
	{0x14e4, 0x1600, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5752 },
	{0x14e4, 0x1601, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5752M },
	{0x14e4, 0x1668, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5714 },
	{0x14e4, 0x166a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5780 },
	{0x14e4, 0x166b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5780S },
	{0x14e4, 0x1678, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5715 },
	{0x14e4, 0x471f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM4785 },
	{0x14e4, 0x16ff, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5903M },
	{0x173b, 0x03ed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, UNK5788 },
	{0,}
	};

MODULE_DEVICE_TABLE(pci, bcm5700_pci_tbl);

#if (LINUX_VERSION_CODE >= 0x2060a)
	static struct pci_device_id pci_AMD762id[]={
		{ PCI_DEVICE(PCI_VENDOR_ID_AMD,
			PCI_DEVICE_ID_AMD_FE_GATE_700C) },
		{ }
	};
#endif

static int sbgige = -1;

/*******************************************************************************
 *******************************************************************************
*/

int get_csum_flag(LM_UINT32 ChipRevId)
{
        return NETIF_F_IP_CSUM;
}

/*******************************************************************************
 *******************************************************************************

   This function returns true if the device passed to it is attached to an
   ICH-ICH4. If the chip is not attached to an ICH, or is attached to an ICH5
   or newer, it returns false.

   This function determines which bridge it is attached to by scaning the pci
   bus looking for bridge chips (hdr_type=1). When a bridge chip is detected,
   the bridge's subordinate's secondary bus number is compared with this
   devices bus number. If they match, then the device is attached to this
   bridge. The bridge's device id is compared to a list of known device ids for
   ICH-ICH4. Since many older ICH's (ICH2-ICH7) share the same device id, the
   chip revision must also be checked to determine if the chip is older than an
   ICH5.

   To scan the bus, one of two functions is used depending on the kernel
   version. For 2.4 kernels, the pci_find_device function is used. This
   function has been depricated in the 2.6 kernel and replaced with the
   fucntion pci_get_device. The macro walk_pci_bus determines which function to
   use when the driver is built.
*/

#if (LINUX_VERSION_CODE >= 0x2060a)
#define walk_pci_bus(d)		while ((d = pci_get_device( \
					PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)

#define unwalk_pci_bus(d)	pci_dev_put(d)

#else
#define walk_pci_bus(d)		while ((d = pci_find_device( \
					PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
#define unwalk_pci_bus(d)

#endif

#define ICH5_CHIP_VERSION	0xc0

static struct pci_device_id pci_ICHtable[] = {
	{0x8086, 0x2418}, /* PCI_DEVICE_ID_INTEL_82801AA_8  */
	{0x8086, 0x2428}, /* PCI_DEVICE_ID_INTEL_82801AB_8  */
	{0x8086, 0x244e}, /* PCI_DEVICE_ID_INTEL_82801BA_6  */
	{0x8086, 0x2448}, /* PCI_DEVICE_ID_INTEL_82801BA_11 */
	{0, 0}
};

int attached_to_ICH4_or_older( struct pci_dev *pdev)
{
	struct pci_dev *tmp_pdev = NULL;
	struct pci_device_id *ich_table;
	u8 chip_rev;

	walk_pci_bus (tmp_pdev) {
		if ((tmp_pdev->hdr_type == 1) &&
		   (tmp_pdev->subordinate != NULL) &&
		   (tmp_pdev->subordinate->secondary == pdev->bus->number)) {

			ich_table = pci_ICHtable;

			while (ich_table->vendor) {
				if ((ich_table->vendor == tmp_pdev->vendor) &&
				    (ich_table->device == tmp_pdev->device)) {

					pci_read_config_byte( tmp_pdev,
						PCI_REVISION_ID, &chip_rev);

					if (chip_rev < ICH5_CHIP_VERSION) {
						unwalk_pci_bus( tmp_pdev);
						return 1;
					}
				}
				ich_table++;
			}
		}
	}
	return 0;
}

static void robo_set_power_mode(void *h)
{
	//int status = 0;
	int i;
	//uint8 mode8;
	//uint16 mode16;
	uint32 flags = 0, temp32 = 0,val32 = 0, savephyaddr = 0;
	PUM_DEVICE_BLOCK pudev = (PUM_DEVICE_BLOCK)h;
	PLM_DEVICE_BLOCK pdev = &pudev->lm_dev;

	/*Brcm,Alex,2006.7.20. Adding Phy power mode setting*/
	BCM5700_PHY_LOCK(pudev, flags);
	savephyaddr = pdev->PhyAddr;

	for(i = 0; i < 8; i++)
	{
		pdev->PhyAddr = i;
		temp32 = 0x2007;
		LM_WritePhy(pdev, 0x18, temp32);
		LM_ReadPhy(pdev, 0x18, &val32);
//		printk(KERN_DEBUG "Alex: port = %x, read value =%x\n",i, val32);
		temp32 = 0xc042;
		LM_WritePhy(pdev, 0x18, temp32);
		/*Read back*/
		temp32 = 0x2007;
		val32 = 0;
		LM_WritePhy(pdev, 0x18, temp32);
		LM_ReadPhy(pdev, 0x18, &val32);
//		printk(KERN_ERR "Alex: read back value =%x\n",val32);
	}

	pdev->PhyAddr = savephyaddr;
	BCM5700_PHY_UNLOCK(pudev, flags);

	/*end of Brcm,Alex,2006.7.20. Adding Phy power mode setting*/

}

static int
__devinit bcm5700_init_board(struct pci_dev *pdev, struct net_device **dev_out, int board_idx)
{
	struct net_device *dev;
	PUM_DEVICE_BLOCK pUmDevice;
	PLM_DEVICE_BLOCK pDevice;
	bool rgmii = FALSE;
	sb_t *sbh = NULL;
	int rc;

	*dev_out = NULL;

	/* dev zeroed in init_etherdev */
#if (LINUX_VERSION_CODE >= 0x20600)
	dev = alloc_etherdev(sizeof(*pUmDevice));
#else
	dev = init_etherdev(NULL, sizeof(*pUmDevice));
#endif
	if (dev == NULL) {
		printk(KERN_ERR "%s: unable to alloc new ethernet\n", bcm5700_driver);
		return -ENOMEM;
	}
	SET_MODULE_OWNER(dev);
#if (LINUX_VERSION_CODE >= 0x20600)
	SET_NETDEV_DEV(dev, &pdev->dev);
#endif
	pUmDevice = (PUM_DEVICE_BLOCK) dev->priv;

	/* enable device (incl. PCI PM wakeup), and bus-mastering */
	rc = pci_enable_device(pdev);
	if (rc)
		goto err_out;

	/* init core specific stuff */
	if (pdev->device == T3_PCI_DEVICE_ID(T3_PCI_ID_BCM471F)) {
		sbh = sb_kattach(SB_OSH);
		sb_gige_init(sbh, ++sbgige, &rgmii);
	}

	rc = pci_request_regions(pdev, bcm5700_driver);
	if (rc) {
		if (!sbh)
			goto err_out;
		printk(KERN_INFO "bcm5700_init_board: pci_request_regions returned error %d\n"
				 "This may be because the region is already requested by"
				 " the SMBus driver. Ignore the PCI error messages.\n", rc);
	}

	pci_set_master(pdev);

	if (pci_set_dma_mask(pdev, BCM_64BIT_DMA_MASK) == 0) {
		pUmDevice->using_dac = 1;
		if (pci_set_consistent_dma_mask(pdev, BCM_64BIT_DMA_MASK) != 0) {
			printk(KERN_ERR "pci_set_consistent_dma_mask failed\n");
			pci_release_regions(pdev);
			goto err_out;
		}
	} else if (pci_set_dma_mask(pdev, BCM_32BIT_DMA_MASK) == 0) {
		pUmDevice->using_dac = 0;
	} else {
		printk(KERN_ERR "System does not support DMA\n");
		pci_release_regions(pdev);
		goto err_out;
	}

	pUmDevice->dev = dev;
	pUmDevice->pdev = pdev;
	pUmDevice->mem_list_num = 0;
	pUmDevice->next_module = root_tigon3_dev;
	pUmDevice->index = board_idx;
	pUmDevice->sbh = (void *)sbh;
	root_tigon3_dev = dev;

	spin_lock_init(&pUmDevice->global_lock);

	spin_lock_init(&pUmDevice->undi_lock);

	spin_lock_init(&pUmDevice->phy_lock);

	pDevice = &pUmDevice->lm_dev;
	pDevice->Flags = 0;
	pDevice->FunctNum = PCI_FUNC(pUmDevice->pdev->devfn);
	pUmDevice->boardflags = getintvar(NULL, "boardflags");
	if (sbh) {
		if (pUmDevice->boardflags & BFL_ENETROBO)
			pDevice->Flags |= ROBO_SWITCH_FLAG;
		pDevice->Flags |= rgmii ? RGMII_MODE_FLAG : 0;
		if (sb_chip(sbh) == BCM4785_CHIP_ID && sb_chiprev(sbh) < 2)
			pDevice->Flags |= ONE_DMA_AT_ONCE_FLAG;
		pDevice->Flags |= SB_CORE_FLAG;
		if (sb_chip(sbh) == BCM4785_CHIP_ID)
			pDevice->Flags |= FLUSH_POSTED_WRITE_FLAG;
	}

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
	if (board_idx < MAX_UNITS) {
		bcm5700_validate_param_range(pUmDevice, &mtu[board_idx], "mtu", 1500, 9000, 1500);
		dev->mtu = mtu[board_idx];
	}
#endif

	if (attached_to_ICH4_or_older(pdev)) {
		pDevice->Flags |= UNDI_FIX_FLAG;
	}

#if (LINUX_VERSION_CODE >= 0x2060a)
	if (pci_dev_present(pci_AMD762id)) {
		pDevice->Flags |= FLUSH_POSTED_WRITE_FLAG;
		pDevice->Flags &= ~NIC_SEND_BD_FLAG;
	}
#else
	if (pci_find_device(0x1022, 0x700c, NULL)) {
		/* AMD762 writes I/O out of order */
		/* Setting bit 1 in 762's register 0x4C still doesn't work */
		/* in all cases */
		pDevice->Flags |= FLUSH_POSTED_WRITE_FLAG;
		pDevice->Flags &= ~NIC_SEND_BD_FLAG;
	}
#endif
	if (LM_GetAdapterInfo(pDevice) != LM_STATUS_SUCCESS) {
		rc = -ENODEV;
		goto err_out_unmap;
	}

	if (pDevice->Flags & ROBO_SWITCH_FLAG) {
		robo_info_t	*robo;

		if ((robo = bcm_robo_attach(sbh, pDevice, dev->name, NULL,
		                            robo_miird, robo_miiwr)) == NULL) {
			B57_ERR(("robo_setup: failed to attach robo switch \n"));
			goto robo_fail;
		}

		if (bcm_robo_enable_device(robo)) {
			B57_ERR(("robo_setup: failed to enable robo switch \n"));
robo_fail:
			bcm_robo_detach(robo);
			rc = -ENODEV;
			goto err_out_unmap;
		}

		/* 5397 power mode setting */
		robo_set_power_mode(robo->h);

		pUmDevice->robo = (void *)robo;
	}

	if ((pDevice->Flags & JUMBO_CAPABLE_FLAG) == 0) {
		if (dev->mtu > 1500) {
			dev->mtu = 1500;
			printk(KERN_WARNING
			       "%s-%d: Jumbo mtu sizes not supported, using mtu=1500\n",
			       bcm5700_driver, pUmDevice->index);
		}
	}

	pUmDevice->do_global_lock = 0;
	if (T3_ASIC_REV(pUmDevice->lm_dev.ChipRevId) == T3_ASIC_REV_5700) {
		/* The 5700 chip works best without interleaved register */
		/* accesses on certain machines. */
		pUmDevice->do_global_lock = 1;
	}

	if ((T3_ASIC_REV(pUmDevice->lm_dev.ChipRevId) == T3_ASIC_REV_5701) &&
		((pDevice->PciState & T3_PCI_STATE_NOT_PCI_X_BUS) == 0)) {

		pUmDevice->rx_buf_align = 0;
	} else {
		pUmDevice->rx_buf_align = 2;
	}
	dev->mem_start = pci_resource_start(pdev, 0);
	dev->mem_end = dev->mem_start + sizeof(T3_STD_MEM_MAP);
	dev->irq = pdev->irq;

	*dev_out = dev;
	return 0;

err_out_unmap:
	pci_release_regions(pdev);
	bcm5700_freemem(dev);

err_out:
#if (LINUX_VERSION_CODE < 0x020600)
	unregister_netdev(dev);
	kfree(dev);
#else
	free_netdev(dev);
#endif
	return rc;
}

static int __devinit
bcm5700_print_ver(void)
{
	printk(KERN_INFO "Broadcom Gigabit Ethernet Driver %s ",
		bcm5700_driver);
	printk("ver. %s %s\n", bcm5700_version, bcm5700_date);
	return 0;
}

static int __devinit
bcm5700_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
{
	struct net_device *dev = NULL;
	PUM_DEVICE_BLOCK pUmDevice;
	PLM_DEVICE_BLOCK pDevice;
	int i;
	static int board_idx = -1;
	static int printed_version = 0;
	struct pci_dev *pci_dev;

	board_idx++;

	if (!printed_version) {
		bcm5700_print_ver();
		printed_version = 1;
	}

	i = bcm5700_init_board(pdev, &dev, board_idx);
	if (i < 0) {
		return i;
	}

	if (dev == NULL)
		return -ENOMEM;

#ifdef BCM_IOCTL32
	if (atomic_read(&bcm5700_load_count) == 0) {
		register_ioctl32_conversion(SIOCNICE, bcm5700_ioctl32);
	}
	atomic_inc(&bcm5700_load_count);
#endif
	dev->open = bcm5700_open;
	dev->hard_start_xmit = bcm5700_start_xmit;
	dev->stop = bcm5700_close;
	dev->get_stats = bcm5700_get_stats;
	dev->set_multicast_list = bcm5700_set_rx_mode;
	dev->do_ioctl = bcm5700_ioctl;
	dev->set_mac_address = &bcm5700_set_mac_addr;
#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
	dev->change_mtu = &bcm5700_change_mtu;
#endif
#if (LINUX_VERSION_CODE >= 0x20400)
	dev->tx_timeout = bcm5700_reset;
	dev->watchdog_timeo = TX_TIMEOUT;
#endif
#ifdef BCM_VLAN
	dev->vlan_rx_register = &bcm5700_vlan_rx_register;
	dev->vlan_rx_kill_vid = &bcm5700_vlan_rx_kill_vid;
#endif
#ifdef BCM_NAPI_RXPOLL
	dev->poll = bcm5700_poll;
	dev->weight = 64;
#endif

	pUmDevice = (PUM_DEVICE_BLOCK) dev->priv;
	pDevice = (PLM_DEVICE_BLOCK) pUmDevice;

	dev->base_addr = pci_resource_start(pdev, 0);
	dev->irq = pdev->irq;
#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
	dev->poll_controller = poll_bcm5700;
#endif

#if (LINUX_VERSION_CODE >= 0x20600)
	if ((i = register_netdev(dev))) {
		printk(KERN_ERR "%s: Cannot register net device\n",
			bcm5700_driver);
		if (pUmDevice->lm_dev.pMappedMemBase)
			iounmap(pUmDevice->lm_dev.pMappedMemBase);
		pci_release_regions(pdev);
		bcm5700_freemem(dev);
		free_netdev(dev);
		return i;
	}
#endif


	pci_set_drvdata(pdev, dev);

	memcpy(dev->dev_addr, pDevice->NodeAddress, 6);
	pUmDevice->name = board_info[ent->driver_data].name,
	printk(KERN_INFO "%s: %s found at mem %lx, IRQ %d, ",
		dev->name, pUmDevice->name, dev->base_addr,
		dev->irq);
	printk("node addr ");
	for (i = 0; i < 6; i++) {
		printk("%2.2x", dev->dev_addr[i]);
	}
	printk("\n");

	printk(KERN_INFO "%s: ", dev->name);
	if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5400_PHY_ID)
		printk("Broadcom BCM5400 Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID)
		printk("Broadcom BCM5401 Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5411_PHY_ID)
		printk("Broadcom BCM5411 Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5461_PHY_ID)
		printk("Broadcom BCM5461 Copper ");
	else if (((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5701_PHY_ID) &&
		!(pDevice->TbiFlags & ENABLE_TBI_FLAG)) {
		printk("Broadcom BCM5701 Integrated Copper ");
	}
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5703_PHY_ID) {
		printk("Broadcom BCM5703 Integrated ");
		if (pDevice->TbiFlags & ENABLE_TBI_FLAG)
			printk("SerDes ");
		else
			printk("Copper ");
	}
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5704_PHY_ID) {
		printk("Broadcom BCM5704 Integrated ");
		if (pDevice->TbiFlags & ENABLE_TBI_FLAG)
			printk("SerDes ");
		else
			printk("Copper ");
	}
        else if (pDevice->PhyFlags & PHY_IS_FIBER){
            if(( pDevice->PhyId & PHY_ID_MASK ) == PHY_BCM5780_PHY_ID)
                printk("Broadcom BCM5780S Integrated Serdes ");

        }        
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5705_PHY_ID)
		printk("Broadcom BCM5705 Integrated Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5750_PHY_ID)
		printk("Broadcom BCM5750 Integrated Copper ");

        else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5714_PHY_ID)
                printk("Broadcom BCM5714 Integrated Copper ");
        else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5780_PHY_ID)
                printk("Broadcom BCM5780 Integrated Copper ");

	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5752_PHY_ID)
		printk("Broadcom BCM5752 Integrated Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM8002_PHY_ID)
		printk("Broadcom BCM8002 SerDes ");
	else if (pDevice->TbiFlags & ENABLE_TBI_FLAG) {
		if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5703) {
			printk("Broadcom BCM5703 Integrated SerDes ");
		}
		else if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5704) {
			printk("Broadcom BCM5704 Integrated SerDes ");
		}
		else {
			printk("Agilent HDMP-1636 SerDes ");
		}
	}
	else {
		printk("Unknown ");
	}
	printk("transceiver found\n");

#if (LINUX_VERSION_CODE >= 0x20400)
	if (scatter_gather[board_idx]) {
		dev->features |= NETIF_F_SG;
		if (pUmDevice->using_dac && !(pDevice->Flags & BCM5788_FLAG))
			dev->features |= NETIF_F_HIGHDMA;
	}
	if ((pDevice->TaskOffloadCap & LM_TASK_OFFLOAD_TX_TCP_CHECKSUM) &&
		tx_checksum[board_idx]) {

		dev->features |= get_csum_flag( pDevice->ChipRevId);
	}
#ifdef BCM_VLAN
	dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
#endif
#ifdef BCM_TSO
	/* On 5714/15/80 chips, Jumbo Frames and TSO cannot both be enabled at
	   the same time. Since only one of these features can be enable at a
           time, we'll enable only Jumbo Frames and disable TSO when the user
	   tries to enable both.
	*/
	dev->features &= ~NETIF_F_TSO;

	if ((pDevice->TaskToOffload & LM_TASK_OFFLOAD_TCP_SEGMENTATION) &&
	    (enable_tso[board_idx])) {
		if (T3_ASIC_5714_FAMILY(pDevice->ChipRevId) &&
		   (dev->mtu > 1500)) {
			printk(KERN_ALERT "%s: Jumbo Frames and TSO cannot simultaneously be enabled. Jumbo Frames enabled. TSO disabled.\n", dev->name);
		} else {
			dev->features |= NETIF_F_TSO;
		}
	}
#endif
	printk(KERN_INFO "%s: Scatter-gather %s, 64-bit DMA %s, Tx Checksum %s, ",
			dev->name,
			(char *) ((dev->features & NETIF_F_SG) ? "ON" : "OFF"),
			(char *) ((dev->features & NETIF_F_HIGHDMA) ? "ON" : "OFF"),
			(char *) ((dev->features & get_csum_flag( pDevice->ChipRevId)) ? "ON" : "OFF"));
#endif
	if ((pDevice->ChipRevId != T3_CHIP_ID_5700_B0) &&
		rx_checksum[board_idx])
		printk("Rx Checksum ON");
	else
		printk("Rx Checksum OFF");
#ifdef BCM_VLAN
	printk(", 802.1Q VLAN ON");
#endif
#ifdef BCM_TSO
	if (dev->features & NETIF_F_TSO) {
		printk(", TSO ON");
	}
	else
#endif
#ifdef BCM_NAPI_RXPOLL
	printk(", NAPI ON");
#endif
	printk("\n");

	register_reboot_notifier(&bcm5700_reboot_notifier);
#ifdef BCM_TASKLET
	tasklet_init(&pUmDevice->tasklet, bcm5700_tasklet,
		(unsigned long) pUmDevice);
#endif
	if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5704) {
		if ((REG_RD(pDevice, PciCfg.DualMacCtrl) &
			T3_DUAL_MAC_CH_CTRL_MASK) == 3) {

printk(KERN_WARNING "%s: Device is configured for Hardware Based Teaming which is not supported with this operating system. Please consult the user diagnostic guide to disable Turbo Teaming.\n", dev->name);
		}
	}

#if (LINUX_VERSION_CODE > 0x20605)

	if ((pci_dev = pci_get_device(0x1022, 0x700c, NULL)))
#else
	if ((pci_dev = pci_find_device(0x1022, 0x700c, NULL)))
#endif
	{
		u32 val;

		/* Found AMD 762 North bridge */
		pci_read_config_dword(pci_dev, 0x4c, &val);
		if ((val & 0x02) == 0) {
			pci_write_config_dword(pci_dev, 0x4c, val | 0x02);
			printk(KERN_INFO "%s: Setting AMD762 Northbridge to enable PCI ordering compliance\n", bcm5700_driver);
		}
	}

#if (LINUX_VERSION_CODE > 0x20605)

	pci_dev_put(pci_dev);

#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)

	if ((pci_dev = pci_get_device(0x1066, 0x0017, NULL))) {
		bcm_msi_chipset_bug = 1;
	}
	pci_dev_put(pci_dev);
#endif
#endif

	return 0;
}


static void __devexit
bcm5700_remove_one (struct pci_dev *pdev)
{
	struct net_device *dev = pci_get_drvdata (pdev);
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;

#ifdef BCM_IOCTL32
	atomic_dec(&bcm5700_load_count);
	if (atomic_read(&bcm5700_load_count) == 0)
		unregister_ioctl32_conversion(SIOCNICE);
#endif
	unregister_netdev(dev);

	if (pUmDevice->lm_dev.pMappedMemBase)
		iounmap(pUmDevice->lm_dev.pMappedMemBase);

	pci_release_regions(pdev);

#if (LINUX_VERSION_CODE < 0x020600)
	kfree(dev);
#else
	free_netdev(dev);
#endif

	pci_set_drvdata(pdev, NULL);

}

int b57_test_intr(UM_DEVICE_BLOCK *pUmDevice);
 
#ifdef BCM_WL_EMULATOR
/* new transmit callback  */ 
static int bcm5700emu_start_xmit(struct sk_buff *skb, struct net_device *dev);
/* keep track of the 2 gige devices */ 
static PLM_DEVICE_BLOCK pDev1;
static PLM_DEVICE_BLOCK pDev2;

static void 
bcm5700emu_open(struct net_device *dev)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;       
	static int instance = 0;
	static char *wlemu_if = NULL;
	char *wlemu_mode = NULL;
	//int wlemu_idx = 0;
	static int rx_enable = 0;
	static int tx_enable = 0;
	
	/* which interface is the emulator ? */
	if(instance == 0) {
		wlemu_if = nvram_get("wlemu_if");
		/* do we emulate rx, tx or both  */
		wlemu_mode = nvram_get("wlemu_mode");
		if(wlemu_mode) {
			if (!strcmp(wlemu_mode,"rx"))
			{
				rx_enable = 1;
			} 
			else if (!strcmp(wlemu_mode,"tx"))
			{
				
				tx_enable = 1;
				
			}
			else if (!strcmp(wlemu_mode,"rx_tx"))
			{
				
				rx_enable = 1;
				tx_enable = 1;
			}
		}
	}
	
	instance++;

	/* The context is used for accessing the OSL for emulating devices */
	pDevice->wlc = NULL;
	
	/* determines if this device is an emulator */
	pDevice->wl_emulate_rx = 0;
	pDevice->wl_emulate_tx = 0;

	if(wlemu_if && !strcmp(dev->name,wlemu_if))
	{
		/* create an emulator context. */
		pDevice->wlc = (void *)wlcemu_wlccreate((void *)dev);
		B57_INFO(("Using %s for wl emulation \n", dev->name));
		if(rx_enable)
		{
			B57_INFO(("Enabling wl RX emulation \n"));
			pDevice->wl_emulate_rx = 1;
		}
		/* re-direct transmit callback to emulator */
		if(tx_enable)
		{
			pDevice->wl_emulate_tx = 1;
			dev->hard_start_xmit = bcm5700emu_start_xmit;
			B57_INFO(("Enabling wl TX emulation \n"));
		}  
	}
	/* for debug access to configured devices only */
	if(instance == 1)
		pDev1 = pDevice;
	else if (instance == 2)
		pDev2 = pDevice;	
}	

/* Public API to get current emulation info */
int bcm5700emu_get_info(char *buf)
{
	int len = 0;
	PLM_DEVICE_BLOCK p;
	
	/* look for an emulating device */
	if(pDev1->wlc) {
		p = pDev1;
		len += sprintf(buf+len,"emulation device : eth0\n");
	}
	else if (pDev2->wlc) {
		p = pDev2;
		len += sprintf(buf+len,"emulation device : eth1\n");
	}
	else {
		len += sprintf(buf+len,"emulation not activated\n");
		return len;
	}
	if(p->wl_emulate_rx)
		len += sprintf(buf+len,"RX emulation enabled\n");
	else 
		len += sprintf(buf+len,"RX emulation disabled\n");
	if(p->wl_emulate_tx)
		len += sprintf(buf+len,"TX emulation enabled\n");
	else 
		len += sprintf(buf+len,"TX emulation disabled\n");
	return len;
	
} 


/* Public API to access the bcm5700_start_xmit callback */

int 
bcm5700emu_forward_xmit(struct sk_buff *skb, struct net_device *dev)
{
  return bcm5700_start_xmit(skb, dev);
}


/* hook to kernel txmit callback */
STATIC int
bcm5700emu_start_xmit(struct sk_buff *skb, struct net_device *dev)
{

  PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
  PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
  return wlcemu_start_xmit(skb,pDevice->wlc);
}	
	 
#endif /* BCM_WL_EMULATOR */
 
int
bcm5700_open(struct net_device *dev)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	int rc;

	if (pUmDevice->suspended){
            return -EAGAIN;
        }

#ifdef BCM_WL_EMULATOR
	bcm5700emu_open(dev);
#endif

	/* delay for 6 seconds */
	pUmDevice->delayed_link_ind = (6 * HZ) / pUmDevice->timer_interval;

#ifdef BCM_INT_COAL
#ifndef BCM_NAPI_RXPOLL
	pUmDevice->adaptive_expiry = HZ / pUmDevice->timer_interval;
#endif
#endif

#ifdef INCLUDE_TBI_SUPPORT
	if ((pDevice->TbiFlags & ENABLE_TBI_FLAG) &&
		(pDevice->TbiFlags & TBI_POLLING_FLAGS)) {
		pUmDevice->poll_tbi_interval = HZ / pUmDevice->timer_interval;
		if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5703) {
			pUmDevice->poll_tbi_interval /= 4;
		}
		pUmDevice->poll_tbi_expiry = pUmDevice->poll_tbi_interval;
	}
#endif
	/* set this timer for 2 seconds */
	pUmDevice->asf_heartbeat = (2 * HZ) / pUmDevice->timer_interval;

#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)


	if ( (  (T3_ASIC_IS_575X_PLUS(pDevice->ChipRevId) ) &&
		(T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5714_A0 ) &&
		(T3_CHIP_REV(pDevice->ChipRevId) != T3_CHIP_REV_5750_AX ) &&
		(T3_CHIP_REV(pDevice->ChipRevId) != T3_CHIP_REV_5750_BX ) ) &&
		!bcm_msi_chipset_bug	){

		if (disable_msi[pUmDevice->index]==1){
			/* do nothing-it's not turned on */
		}else{
			pDevice->Flags |= USING_MSI_FLAG;

                        REG_WR(pDevice, Msi.Mode,  2 );

			rc = pci_enable_msi(pUmDevice->pdev);

			if(rc!=0){
				pDevice->Flags &= ~ USING_MSI_FLAG;
                        	REG_WR(pDevice, Msi.Mode,  1 );
			}
		}
	}


#endif

	if ((rc= request_irq(pUmDevice->pdev->irq, &bcm5700_interrupt, SA_SHIRQ, dev->name, dev)))
	{

#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)

		if(pDevice->Flags & USING_MSI_FLAG)  {

			pci_disable_msi(pUmDevice->pdev);
			pDevice->Flags &= ~USING_MSI_FLAG;
                       	REG_WR(pDevice, Msi.Mode,  1 );

		}
#endif
		return rc;
	}

	pUmDevice->opened = 1;
	if (LM_InitializeAdapter(pDevice) != LM_STATUS_SUCCESS) {
		pUmDevice->opened = 0;
		free_irq(dev->irq, dev);
		bcm5700_freemem(dev);
		return -EAGAIN;
	}

	bcm5700_set_vlan_mode(pUmDevice);
	bcm5700_init_counters(pUmDevice);

	if (pDevice->Flags & UNDI_FIX_FLAG) {
		printk(KERN_INFO "%s: Using indirect register access\n", dev->name);
	}

	if (memcmp(dev->dev_addr, pDevice->NodeAddress, 6))
	{
		/* Do not use invalid eth addrs: any multicast & all zeros */
		if( is_valid_ether_addr(dev->dev_addr) ){
			LM_SetMacAddress(pDevice, dev->dev_addr);
		}
		else
		{
			printk(KERN_INFO "%s: Invalid administered node address\n",dev->name);
			memcpy(dev->dev_addr, pDevice->NodeAddress, 6);
		}
	}

	if (tigon3_debug > 1)
		printk(KERN_DEBUG "%s: tigon3_open() irq %d.\n", dev->name, dev->irq);

	QQ_InitQueue(&pUmDevice->rx_out_of_buf_q.Container,
        MAX_RX_PACKET_DESC_COUNT);


#if (LINUX_VERSION_CODE < 0x020300)
	MOD_INC_USE_COUNT;
#endif

	atomic_set(&pUmDevice->intr_sem, 0);

	LM_EnableInterrupt(pDevice);

#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)

	if (pDevice->Flags & USING_MSI_FLAG){

		/* int test to check support on older machines */
		if (b57_test_intr(pUmDevice) != 1) {

			LM_DisableInterrupt(pDevice);
			free_irq(pUmDevice->pdev->irq, dev);
			pci_disable_msi(pUmDevice->pdev);
                        REG_WR(pDevice, Msi.Mode,  1 );
			pDevice->Flags &= ~USING_MSI_FLAG;

			rc = LM_ResetAdapter(pDevice);
printk(KERN_ALERT " The MSI support in this system is not functional.\n");

			if (rc == LM_STATUS_SUCCESS)
				rc = 0;
			else
				rc = -ENODEV;

			if(rc == 0){
				rc = request_irq(pUmDevice->pdev->irq, &bcm5700_interrupt,
					    SA_SHIRQ, dev->name, dev);
			}

			if(rc){
				LM_Halt(pDevice);
				bcm5700_freemem(dev);
				pUmDevice->opened = 0;
				return rc;
			}


			pDevice->InitDone = TRUE;
			atomic_set(&pUmDevice->intr_sem, 0);
			LM_EnableInterrupt(pDevice);
		}
	}
#endif

	init_timer(&pUmDevice->timer);
	pUmDevice->timer.expires = RUN_AT(pUmDevice->timer_interval);
	pUmDevice->timer.data = (unsigned long)dev;
	pUmDevice->timer.function = &bcm5700_timer;
	add_timer(&pUmDevice->timer);

	if (T3_ASIC_IS_5705_BEYOND(pDevice->ChipRevId)) {
		init_timer(&pUmDevice->statstimer);
		pUmDevice->statstimer.expires = RUN_AT(pUmDevice->statstimer_interval);
		pUmDevice->statstimer.data = (unsigned long)dev;
		pUmDevice->statstimer.function = &bcm5700_stats_timer;
		add_timer(&pUmDevice->statstimer);
	}

	if(pDevice->Flags & USING_MSI_FLAG)
		printk(KERN_INFO "%s: Using Message Signaled Interrupt (MSI)  \n", dev->name);
	else
		printk(KERN_INFO "%s: Using PCI INTX interrupt \n", dev->name);

	netif_start_queue(dev);

	return 0;
}


STATIC void
bcm5700_stats_timer(unsigned long data)
{
	struct net_device *dev = (struct net_device *)data;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	unsigned long flags = 0;

	if (!pUmDevice->opened)
		return;

	if (!atomic_read(&pUmDevice->intr_sem) &&
	    !pUmDevice->suspended              &&
	   (pDevice->LinkStatus == LM_STATUS_LINK_ACTIVE)) {
		BCM5700_LOCK(pUmDevice, flags);
		LM_GetStats(pDevice);
		BCM5700_UNLOCK(pUmDevice, flags);
	}

	pUmDevice->statstimer.expires = RUN_AT(pUmDevice->statstimer_interval);

	add_timer(&pUmDevice->statstimer);
}


STATIC void
bcm5700_timer(unsigned long data)
{
	struct net_device *dev = (struct net_device *)data;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	unsigned long flags = 0;
	LM_UINT32 value32;

	if (!pUmDevice->opened)
		return;

	/* BCM4785: Flush posted writes from GbE to host memory. */
	if (pDevice->Flags & FLUSH_POSTED_WRITE_FLAG)
		REG_RD(pDevice, HostCoalesce.Mode);

	if (atomic_read(&pUmDevice->intr_sem) || pUmDevice->suspended) {
		pUmDevice->timer.expires = RUN_AT(pUmDevice->timer_interval);
		add_timer(&pUmDevice->timer);
		return;
	}

#ifdef INCLUDE_TBI_SUPPORT
	if ((pDevice->TbiFlags & TBI_POLLING_FLAGS) &&
		(--pUmDevice->poll_tbi_expiry <= 0)) {

		BCM5700_PHY_LOCK(pUmDevice, flags);
		value32 = REG_RD(pDevice, MacCtrl.Status);
		if (((pDevice->LinkStatus == LM_STATUS_LINK_ACTIVE) &&
			((value32 & (MAC_STATUS_LINK_STATE_CHANGED |
				MAC_STATUS_CFG_CHANGED)) ||
			!(value32 & MAC_STATUS_PCS_SYNCED)))
			||
			((pDevice->LinkStatus != LM_STATUS_LINK_ACTIVE) &&
			(value32 & (MAC_STATUS_PCS_SYNCED |
				MAC_STATUS_SIGNAL_DETECTED))))
		{
			LM_SetupPhy(pDevice);
		}
		BCM5700_PHY_UNLOCK(pUmDevice, flags);
		pUmDevice->poll_tbi_expiry = pUmDevice->poll_tbi_interval;

        }
#endif

	if (pUmDevice->delayed_link_ind > 0) {
		if (pUmDevice->delayed_link_ind == 1)
			MM_IndicateStatus(pDevice, pDevice->LinkStatus);
		else
			pUmDevice->delayed_link_ind--;
	}

	if (pUmDevice->crc_counter_expiry > 0)
		pUmDevice->crc_counter_expiry--;

	if (!pUmDevice->interrupt) {
		if (!(pDevice->Flags & USE_TAGGED_STATUS_FLAG)) {
			BCM5700_LOCK(pUmDevice, flags);
			if (pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) {
				/* This will generate an interrupt */
				REG_WR(pDevice, Grc.LocalCtrl,
					pDevice->GrcLocalCtrl |
					GRC_MISC_LOCAL_CTRL_SET_INT);
			}
			else {
				REG_WR(pDevice, HostCoalesce.Mode,
					pDevice->CoalesceMode |
					HOST_COALESCE_ENABLE |
					HOST_COALESCE_NOW);
			}
			if (!(REG_RD(pDevice, DmaWrite.Mode) &
				DMA_WRITE_MODE_ENABLE)) {
				BCM5700_UNLOCK(pUmDevice, flags);
				bcm5700_reset(dev);
			}
			else {
				BCM5700_UNLOCK(pUmDevice, flags);
			}
			if (pUmDevice->tx_queued) {
				pUmDevice->tx_queued = 0;
				netif_wake_queue(dev);
			}
		}
#if (LINUX_VERSION_CODE < 0x02032b)
		if ((QQ_GetEntryCnt(&pDevice->TxPacketFreeQ.Container) !=
			pDevice->TxPacketDescCnt) &&
			((jiffies - dev->trans_start) > TX_TIMEOUT)) {

			printk(KERN_WARNING "%s: Tx hung\n", dev->name);
			bcm5700_reset(dev);
		}
#endif
	}
#ifdef BCM_INT_COAL
#ifndef BCM_NAPI_RXPOLL
	if (pUmDevice->adaptive_coalesce) {
		pUmDevice->adaptive_expiry--;
		if (pUmDevice->adaptive_expiry == 0) {
			pUmDevice->adaptive_expiry = HZ /
				pUmDevice->timer_interval;
			bcm5700_adapt_coalesce(pUmDevice);
		}
	}
#endif
#endif
	if (QQ_GetEntryCnt(&pUmDevice->rx_out_of_buf_q.Container) >
		(unsigned int) pUmDevice->rx_buf_repl_panic_thresh) {
		/* Generate interrupt and let isr allocate buffers */
		REG_WR(pDevice, HostCoalesce.Mode, pDevice->CoalesceMode |
			HOST_COALESCE_ENABLE | HOST_COALESCE_NOW);
	}

#ifdef BCM_ASF
	if (pDevice->AsfFlags & ASF_ENABLED) {
		pUmDevice->asf_heartbeat--;
		if (pUmDevice->asf_heartbeat == 0) {
			if( (pDevice->Flags & UNDI_FIX_FLAG) || 
			    (pDevice->Flags & ENABLE_PCIX_FIX_FLAG)) {
				MEM_WR_OFFSET(pDevice, T3_CMD_MAILBOX,
					T3_CMD_NICDRV_ALIVE2);
				MEM_WR_OFFSET(pDevice, T3_CMD_LENGTH_MAILBOX,
					4);
				MEM_WR_OFFSET(pDevice, T3_CMD_DATA_MAILBOX, 5);
			} else {
				LM_RegWr(pDevice, 
					 (T3_NIC_MBUF_POOL_ADDR + 
					  T3_CMD_MAILBOX), 
					 T3_CMD_NICDRV_ALIVE2, 1);
				LM_RegWr(pDevice, 
					 (T3_NIC_MBUF_POOL_ADDR + 
					  T3_CMD_LENGTH_MAILBOX),4,1);
				LM_RegWr(pDevice, 
					 (T3_NIC_MBUF_POOL_ADDR + 
					  T3_CMD_DATA_MAILBOX),5,1);
 			}

			value32 = REG_RD(pDevice, Grc.RxCpuEvent);
			REG_WR(pDevice, Grc.RxCpuEvent, value32 | BIT_14);
			pUmDevice->asf_heartbeat = (2 * HZ) /
				pUmDevice->timer_interval;
		}
	}
#endif

	if (pDevice->PhyFlags & PHY_IS_FIBER){
		BCM5700_PHY_LOCK(pUmDevice, flags);
		LM_5714_FamFiberCheckLink(pDevice);
		BCM5700_PHY_UNLOCK(pUmDevice, flags);
	}

	pUmDevice->timer.expires = RUN_AT(pUmDevice->timer_interval);
	add_timer(&pUmDevice->timer);
}

STATIC int
bcm5700_init_counters(PUM_DEVICE_BLOCK pUmDevice)
{
#ifdef BCM_INT_COAL
#ifndef BCM_NAPI_RXPOLL
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;

	pUmDevice->rx_curr_coalesce_frames = pDevice->RxMaxCoalescedFrames;
	pUmDevice->rx_curr_coalesce_ticks = pDevice->RxCoalescingTicks;
	pUmDevice->tx_curr_coalesce_frames = pDevice->TxMaxCoalescedFrames;
	pUmDevice->rx_last_cnt = 0;
	pUmDevice->tx_last_cnt = 0;
#endif
#endif
	pUmDevice->phy_crc_count = 0;
#if TIGON3_DEBUG
	pUmDevice->tx_zc_count = 0;
	pUmDevice->tx_chksum_count = 0;
	pUmDevice->tx_himem_count = 0;
	pUmDevice->rx_good_chksum_count = 0;
	pUmDevice->rx_bad_chksum_count = 0;
#endif
#ifdef BCM_TSO
	pUmDevice->tso_pkt_count = 0;
#endif
	return 0;
}

#ifdef BCM_INT_COAL
#ifndef BCM_NAPI_RXPOLL
STATIC int
bcm5700_do_adapt_coalesce(PUM_DEVICE_BLOCK pUmDevice,
	int rx_frames, int rx_ticks, int tx_frames, int rx_frames_intr)
{
	unsigned long flags = 0;
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;

	if (pUmDevice->do_global_lock) {
		if (spin_is_locked(&pUmDevice->global_lock))
			return 0;
		spin_lock_irqsave(&pUmDevice->global_lock, flags);
	}
	pUmDevice->rx_curr_coalesce_frames = rx_frames;
	pUmDevice->rx_curr_coalesce_ticks = rx_ticks;
	pUmDevice->tx_curr_coalesce_frames = tx_frames;
	pUmDevice->rx_curr_coalesce_frames_intr = rx_frames_intr;
	REG_WR(pDevice, HostCoalesce.RxMaxCoalescedFrames, rx_frames);

	REG_WR(pDevice, HostCoalesce.RxCoalescingTicks, rx_ticks);

	REG_WR(pDevice, HostCoalesce.TxMaxCoalescedFrames, tx_frames);

	REG_WR(pDevice, HostCoalesce.RxMaxCoalescedFramesDuringInt,
		rx_frames_intr);

	BCM5700_UNLOCK(pUmDevice, flags);
	return 0;
}

STATIC int
bcm5700_adapt_coalesce(PUM_DEVICE_BLOCK pUmDevice)
{
	PLM_DEVICE_BLOCK pDevice = &pUmDevice->lm_dev;
	uint rx_curr_cnt, tx_curr_cnt, rx_delta, tx_delta, total_delta;

	rx_curr_cnt = pDevice->pStatsBlkVirt->ifHCInUcastPkts.Low;
	tx_curr_cnt = pDevice->pStatsBlkVirt->ifHCOutUcastPkts.Low;
	if ((rx_curr_cnt <= pUmDevice->rx_last_cnt) ||
		(tx_curr_cnt < pUmDevice->tx_last_cnt)) {

		/* skip if there is counter rollover */
		pUmDevice->rx_last_cnt = rx_curr_cnt;
		pUmDevice->tx_last_cnt = tx_curr_cnt;
		return 0;
	}

	rx_delta = rx_curr_cnt - pUmDevice->rx_last_cnt;
	tx_delta = tx_curr_cnt - pUmDevice->tx_last_cnt;
	total_delta = (((rx_delta + rx_delta) + tx_delta) / 3) << 1;

	pUmDevice->rx_last_cnt = rx_curr_cnt;
	pUmDevice->tx_last_cnt = tx_curr_cnt;

	if (total_delta < ADAPTIVE_LO_PKT_THRESH) {
		if (pUmDevice->rx_curr_coalesce_frames !=
			ADAPTIVE_LO_RX_MAX_COALESCED_FRAMES) {

			bcm5700_do_adapt_coalesce(pUmDevice,
				ADAPTIVE_LO_RX_MAX_COALESCED_FRAMES,
				ADAPTIVE_LO_RX_COALESCING_TICKS,
				ADAPTIVE_LO_TX_MAX_COALESCED_FRAMES,
				ADAPTIVE_LO_RX_MAX_COALESCED_FRAMES_DURING_INT);
		}
	}
	else if (total_delta < ADAPTIVE_HI_PKT_THRESH) {
		if (pUmDevice->rx_curr_coalesce_frames !=
			DEFAULT_RX_MAX_COALESCED_FRAMES) {

			bcm5700_do_adapt_coalesce(pUmDevice,
				DEFAULT_RX_MAX_COALESCED_FRAMES,
				DEFAULT_RX_COALESCING_TICKS,
				DEFAULT_TX_MAX_COALESCED_FRAMES,
				DEFAULT_RX_MAX_COALESCED_FRAMES_DURING_INT);
		}
	}
	else {
		if (pUmDevice->rx_curr_coalesce_frames !=
			ADAPTIVE_HI_RX_MAX_COALESCED_FRAMES) {

			bcm5700_do_adapt_coalesce(pUmDevice,
				ADAPTIVE_HI_RX_MAX_COALESCED_FRAMES,
				ADAPTIVE_HI_RX_COALESCING_TICKS,
				ADAPTIVE_HI_TX_MAX_COALESCED_FRAMES,
				ADAPTIVE_HI_RX_MAX_COALESCED_FRAMES_DURING_INT);
		}
	}
	return 0;
}
#endif
#endif

STATIC void
bcm5700_reset(struct net_device *dev)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	unsigned long flags;

#ifdef BCM_TSO

	if( (dev->features & NETIF_F_TSO) &&
		(pUmDevice->tx_full) )	   {

		dev->features &= ~NETIF_F_TSO;
	}
#endif

	netif_stop_queue(dev);
	bcm5700_intr_off(pUmDevice);
	BCM5700_PHY_LOCK(pUmDevice, flags);
	LM_ResetAdapter(pDevice);
	pDevice->InitDone = TRUE;
	bcm5700_do_rx_mode(dev);
	bcm5700_set_vlan_mode(pUmDevice);
	bcm5700_init_counters(pUmDevice);
	if (memcmp(dev->dev_addr, pDevice->NodeAddress, 6)) {
		LM_SetMacAddress(pDevice, dev->dev_addr);
	}
	BCM5700_PHY_UNLOCK(pUmDevice, flags);
	atomic_set(&pUmDevice->intr_sem, 1);
	bcm5700_intr_on(pUmDevice);
	netif_wake_queue(dev);
}

STATIC void
bcm5700_set_vlan_mode(UM_DEVICE_BLOCK *pUmDevice)
{
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;
	LM_UINT32 ReceiveMask = pDevice->ReceiveMask;
	int vlan_tag_mode = pUmDevice->vlan_tag_mode;

	if (vlan_tag_mode == VLAN_TAG_MODE_AUTO_STRIP) {
	        if (pDevice->AsfFlags & ASF_ENABLED) {
			vlan_tag_mode = VLAN_TAG_MODE_FORCED_STRIP;
		}
		else {
			vlan_tag_mode = VLAN_TAG_MODE_NORMAL_STRIP;
		}
	}
	if (vlan_tag_mode == VLAN_TAG_MODE_NORMAL_STRIP) {
		ReceiveMask |= LM_KEEP_VLAN_TAG;
#ifdef BCM_VLAN
		if (pUmDevice->vlgrp)
			ReceiveMask &= ~LM_KEEP_VLAN_TAG;
#endif
	}
	else if (vlan_tag_mode == VLAN_TAG_MODE_FORCED_STRIP) {
		ReceiveMask &= ~LM_KEEP_VLAN_TAG;
	}
	if (ReceiveMask != pDevice->ReceiveMask)
	{
		LM_SetReceiveMask(pDevice, ReceiveMask);
	}
}

static void
bcm5700_poll_wait(UM_DEVICE_BLOCK *pUmDevice)
{
#ifdef BCM_NAPI_RXPOLL
	while (pUmDevice->lm_dev.RxPoll) {
		current->state = TASK_INTERRUPTIBLE;
		schedule_timeout(1);
	}
#endif
}


#ifdef BCM_VLAN
STATIC void
bcm5700_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) dev->priv;

	bcm5700_intr_off(pUmDevice);
	bcm5700_poll_wait(pUmDevice);
	pUmDevice->vlgrp = vlgrp;
	bcm5700_set_vlan_mode(pUmDevice);
	bcm5700_intr_on(pUmDevice);
}

STATIC void
bcm5700_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) dev->priv;

	bcm5700_intr_off(pUmDevice);
	bcm5700_poll_wait(pUmDevice);
	if (pUmDevice->vlgrp) {
		pUmDevice->vlgrp->vlan_devices[vid] = NULL;
	}
	bcm5700_intr_on(pUmDevice);
}
#endif

STATIC int
bcm5700_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	PLM_PACKET pPacket;
	PUM_PACKET pUmPacket;
	unsigned long flags = 0;
	int frag_no;
#ifdef BCM_TSO
	LM_UINT32 mss = 0 ;
	uint16_t ip_tcp_len, tcp_opt_len, tcp_seg_flags;
#endif

	if ((pDevice->LinkStatus == LM_STATUS_LINK_DOWN) ||
		!pDevice->InitDone || pUmDevice->suspended)
	{
		dev_kfree_skb(skb);
		return 0;
	}

#if (LINUX_VERSION_CODE < 0x02032b)
	if (test_and_set_bit(0, &dev->tbusy)) {
	    return 1;
	}
#endif

	if (pUmDevice->do_global_lock && pUmDevice->interrupt) {
		netif_stop_queue(dev);
		pUmDevice->tx_queued = 1;
		if (!pUmDevice->interrupt) {
			netif_wake_queue(dev);
			pUmDevice->tx_queued = 0;
		}
	    return 1;
	}

	pPacket = (PLM_PACKET)
		QQ_PopHead(&pDevice->TxPacketFreeQ.Container);
	if (pPacket == 0) {
		netif_stop_queue(dev);
		pUmDevice->tx_full = 1;
		if (QQ_GetEntryCnt(&pDevice->TxPacketFreeQ.Container)) {
			netif_wake_queue(dev);
			pUmDevice->tx_full = 0;
		}
	    return 1;
	}
	pUmPacket = (PUM_PACKET) pPacket;
	pUmPacket->skbuff = skb;
	pUmDevice->stats.tx_bytes += skb->len; 

	if (skb->ip_summed == CHECKSUM_HW) {
		pPacket->Flags = SND_BD_FLAG_TCP_UDP_CKSUM;
#if TIGON3_DEBUG
		pUmDevice->tx_chksum_count++;
#endif
	}
	else {
		pPacket->Flags = 0;
	}
#if MAX_SKB_FRAGS
	frag_no = skb_shinfo(skb)->nr_frags;
#else
	frag_no = 0;
#endif
	if (atomic_read(&pDevice->SendBdLeft) < (frag_no + 1)) {
		netif_stop_queue(dev);
		pUmDevice->tx_full = 1;
		QQ_PushHead(&pDevice->TxPacketFreeQ.Container, pPacket);
		if (atomic_read(&pDevice->SendBdLeft) >= (frag_no + 1)) {
			netif_wake_queue(dev);
			pUmDevice->tx_full = 0;
		}
		return 1;
	}

	pPacket->u.Tx.FragCount = frag_no + 1;
#if TIGON3_DEBUG
	if (pPacket->u.Tx.FragCount > 1)
		pUmDevice->tx_zc_count++;
#endif

#ifdef BCM_VLAN
	if (pUmDevice->vlgrp && vlan_tx_tag_present(skb)) {
		pPacket->VlanTag = vlan_tx_tag_get(skb);
		pPacket->Flags |= SND_BD_FLAG_VLAN_TAG;
	}
#endif

#ifdef BCM_TSO
	if ((mss = (LM_UINT32) skb_shinfo(skb)->tso_size) &&
		(skb->len > pDevice->TxMtu)) {

#if (LINUX_VERSION_CODE >= 0x02060c)

		if (skb_header_cloned(skb) &&
			pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {

			dev_kfree_skb(skb);
			return 0;
		}
#endif
		pUmDevice->tso_pkt_count++;

		pPacket->Flags |= SND_BD_FLAG_CPU_PRE_DMA |
			SND_BD_FLAG_CPU_POST_DMA;

		tcp_opt_len = 0;
		if (skb->h.th->doff > 5) {
			tcp_opt_len = (skb->h.th->doff - 5) << 2;
		}
		ip_tcp_len = (skb->nh.iph->ihl << 2) + sizeof(struct tcphdr);
		skb->nh.iph->check = 0;

		if ( T3_ASIC_IS_575X_PLUS(pDevice->ChipRevId) ){
			skb->h.th->check = 0;
			pPacket->Flags &= ~SND_BD_FLAG_TCP_UDP_CKSUM;
		}
		else {
			skb->h.th->check = ~csum_tcpudp_magic(
				skb->nh.iph->saddr, skb->nh.iph->daddr,
				0, IPPROTO_TCP, 0);
		}

		skb->nh.iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
		tcp_seg_flags = 0;

		if (tcp_opt_len || (skb->nh.iph->ihl > 5)) {
			if ( T3_ASIC_IS_5705_BEYOND(pDevice->ChipRevId) ){
				tcp_seg_flags =
					((skb->nh.iph->ihl - 5) +
					(tcp_opt_len >> 2)) << 11;
			}
			else {
				pPacket->Flags |=
					((skb->nh.iph->ihl - 5) +
					(tcp_opt_len >> 2)) << 12;
			}
		}
		pPacket->u.Tx.MaxSegmentSize = mss | tcp_seg_flags;
	}
	else
	{
		pPacket->u.Tx.MaxSegmentSize = 0;
	}
#endif
	BCM5700_LOCK(pUmDevice, flags);
	LM_SendPacket(pDevice, pPacket);
	BCM5700_UNLOCK(pUmDevice, flags);

#if (LINUX_VERSION_CODE < 0x02032b)
	netif_wake_queue(dev);
#endif
	dev->trans_start = jiffies;


	return 0;
}

#ifdef BCM_NAPI_RXPOLL
STATIC int
bcm5700_poll(struct net_device *dev, int *budget)
{
	int orig_budget = *budget;
	int work_done;
	UM_DEVICE_BLOCK *pUmDevice = (UM_DEVICE_BLOCK *) dev->priv;
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;
	unsigned long flags = 0;
	LM_UINT32 tag;

	if (orig_budget > dev->quota)
		orig_budget = dev->quota;

	BCM5700_LOCK(pUmDevice, flags);
	/* BCM4785: Flush posted writes from GbE to host memory. */
	if (pDevice->Flags & FLUSH_POSTED_WRITE_FLAG)
		REG_RD(pDevice, HostCoalesce.Mode);
	work_done = LM_ServiceRxPoll(pDevice, orig_budget);
	*budget -= work_done;
	dev->quota -= work_done;

	if (QQ_GetEntryCnt(&pUmDevice->rx_out_of_buf_q.Container)) {
		replenish_rx_buffers(pUmDevice, 0);
	}
	BCM5700_UNLOCK(pUmDevice, flags);
	if (work_done) {
		MM_IndicateRxPackets(pDevice);
		BCM5700_LOCK(pUmDevice, flags);
		LM_QueueRxPackets(pDevice);
		BCM5700_UNLOCK(pUmDevice, flags);
	}
	if ((work_done < orig_budget) || atomic_read(&pUmDevice->intr_sem) ||
		pUmDevice->suspended) {

		netif_rx_complete(dev);
		BCM5700_LOCK(pUmDevice, flags);
		REG_WR(pDevice, Grc.Mode, pDevice->GrcMode);
		pDevice->RxPoll = FALSE;
		if (pDevice->RxPoll) {
			BCM5700_UNLOCK(pUmDevice, flags);
			return 0;
		}
		/* Take care of possible missed rx interrupts */
		REG_RD_BACK(pDevice, Grc.Mode);	/* flush the register write */
		tag = pDevice->pStatusBlkVirt->StatusTag;
		if ((pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) ||
			(pDevice->pStatusBlkVirt->Idx[0].RcvProdIdx !=
			pDevice->RcvRetConIdx)) {

			REG_WR(pDevice, HostCoalesce.Mode,
				pDevice->CoalesceMode | HOST_COALESCE_ENABLE |
				HOST_COALESCE_NOW);
		}
		/* If a new status block is pending in the WDMA state machine */
		/* before the register write to enable the rx interrupt,      */
		/* the new status block may DMA with no interrupt. In this    */
		/* scenario, the tag read above will be older than the tag in */
		/* the pending status block and writing the older tag will    */
		/* cause interrupt to be generated.                           */
		else if (pDevice->Flags & USE_TAGGED_STATUS_FLAG) {
			MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low,
				tag << 24);
			/* Make sure we service tx in case some tx interrupts */
			/* are cleared */
			if (atomic_read(&pDevice->SendBdLeft) <
				(T3_SEND_RCB_ENTRY_COUNT / 2)) {
				REG_WR(pDevice, HostCoalesce.Mode,
					pDevice->CoalesceMode |
					HOST_COALESCE_ENABLE |
					HOST_COALESCE_NOW);
			}
		}
		BCM5700_UNLOCK(pUmDevice, flags);
		return 0;
	}
	return 1;
}
#endif /* BCM_NAPI_RXPOLL */

STATIC irqreturn_t
bcm5700_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
{
	struct net_device *dev = (struct net_device *)dev_instance;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	LM_UINT32 oldtag, newtag;
	int i, max_intr_loop;
#ifdef BCM_TASKLET
	int repl_buf_count;
#endif
	unsigned int handled = 1;

	if (!pDevice->InitDone) {
		handled = 0;
		return IRQ_RETVAL(handled);
	}

	bcm5700_intr_lock(pUmDevice);
	if (atomic_read(&pUmDevice->intr_sem)) {
		MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 1);
		bcm5700_intr_unlock(pUmDevice);
		handled = 0;
		return IRQ_RETVAL(handled);
	}

	if (test_and_set_bit(0, (void*)&pUmDevice->interrupt)) {
		printk(KERN_ERR "%s: Duplicate entry of the interrupt handler\n",
			dev->name);
		bcm5700_intr_unlock(pUmDevice);
		handled = 0;
		return IRQ_RETVAL(handled);
	}

	/* BCM4785: Flush posted writes from GbE to host memory. */
	if (pDevice->Flags & FLUSH_POSTED_WRITE_FLAG)
		REG_RD(pDevice, HostCoalesce.Mode);

	if ((pDevice->Flags & USING_MSI_FLAG) ||
		(pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) ||
		!(REG_RD(pDevice,PciCfg.PciState) & T3_PCI_STATE_INTERRUPT_NOT_ACTIVE) )
	{

		if (pUmDevice->intr_test) {
			if (!(REG_RD(pDevice, PciCfg.PciState) &
					T3_PCI_STATE_INTERRUPT_NOT_ACTIVE) ||
						pDevice->Flags & USING_MSI_FLAG ) {
				pUmDevice->intr_test_result = 1;
			}
			pUmDevice->intr_test = 0;
		}

#ifdef BCM_NAPI_RXPOLL
		max_intr_loop = 1;
#else
		max_intr_loop = 50;
#endif
		if (pDevice->Flags & USE_TAGGED_STATUS_FLAG) {
			MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 1);
			oldtag = pDevice->pStatusBlkVirt->StatusTag;

			for (i = 0; ; i++) {
				pDevice->pStatusBlkVirt->Status &= ~STATUS_BLOCK_UPDATED;

				LM_ServiceInterrupts(pDevice);
				/* BCM4785: Flush GbE posted writes to host memory. */
				if (pDevice->Flags & FLUSH_POSTED_WRITE_FLAG)
					MB_REG_RD(pDevice, Mailbox.Interrupt[0].Low);
				newtag = pDevice->pStatusBlkVirt->StatusTag;
				if ((newtag == oldtag) || (i > max_intr_loop)) {
					MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, oldtag << 24);
					pDevice->LastTag = oldtag;
					if (pDevice->Flags & UNDI_FIX_FLAG) {
						REG_WR(pDevice, Grc.LocalCtrl,
						pDevice->GrcLocalCtrl | 0x2);
					}
					break;
				}
				oldtag = newtag;
			}
		}
		else
		{
			i = 0;
			do {
				uint dummy;

				MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 1);
				pDevice->pStatusBlkVirt->Status &= ~STATUS_BLOCK_UPDATED;
				LM_ServiceInterrupts(pDevice);
				MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 0);
				dummy = MB_REG_RD(pDevice, Mailbox.Interrupt[0].Low);
				i++;
			}
			while ((pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) &&
				(i < max_intr_loop));

			if (pDevice->Flags & UNDI_FIX_FLAG) {
				REG_WR(pDevice, Grc.LocalCtrl,
				pDevice->GrcLocalCtrl | 0x2);
			}
		}
	}
	else
	{
		/* not my interrupt */
		handled = 0;
	}

#ifdef BCM_TASKLET
	repl_buf_count = QQ_GetEntryCnt(&pUmDevice->rx_out_of_buf_q.Container);
	if (((repl_buf_count > pUmDevice->rx_buf_repl_panic_thresh) ||
		pDevice->QueueAgain) &&
		(!test_and_set_bit(0, &pUmDevice->tasklet_busy))) {

		replenish_rx_buffers(pUmDevice, pUmDevice->rx_buf_repl_isr_limit);
		clear_bit(0, (void*)&pUmDevice->tasklet_busy);
	}
	else if ((repl_buf_count > pUmDevice->rx_buf_repl_thresh) &&
		!pUmDevice->tasklet_pending) {

		pUmDevice->tasklet_pending = 1;
		tasklet_schedule(&pUmDevice->tasklet);
	}
#else
#ifdef BCM_NAPI_RXPOLL
	if (!pDevice->RxPoll &&
		QQ_GetEntryCnt(&pUmDevice->rx_out_of_buf_q.Container)) {
		pDevice->RxPoll = 1;
		MM_ScheduleRxPoll(pDevice);
	}
#else
	if (QQ_GetEntryCnt(&pUmDevice->rx_out_of_buf_q.Container)) {
		replenish_rx_buffers(pUmDevice, 0);
	}

	if (QQ_GetEntryCnt(&pDevice->RxPacketFreeQ.Container) ||
		pDevice->QueueAgain) {

		LM_QueueRxPackets(pDevice);
	}
#endif
#endif

	clear_bit(0, (void*)&pUmDevice->interrupt);
	bcm5700_intr_unlock(pUmDevice);
	if (pUmDevice->tx_queued) {
		pUmDevice->tx_queued = 0;
		netif_wake_queue(dev);
	}
	return IRQ_RETVAL(handled);
}


#ifdef BCM_TASKLET
STATIC void
bcm5700_tasklet(unsigned long data)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)data;
	unsigned long flags = 0;

	/* RH 7.2 Beta 3 tasklets are reentrant */
	if (test_and_set_bit(0, &pUmDevice->tasklet_busy)) {
		pUmDevice->tasklet_pending = 0;
		return;
	}

	pUmDevice->tasklet_pending = 0;
	if (pUmDevice->opened && !pUmDevice->suspended) {
		BCM5700_LOCK(pUmDevice, flags);
		replenish_rx_buffers(pUmDevice, 0);
		BCM5700_UNLOCK(pUmDevice, flags);
	}

	clear_bit(0, &pUmDevice->tasklet_busy);
}
#endif

STATIC int
bcm5700_close(struct net_device *dev)
{

	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;

#if (LINUX_VERSION_CODE < 0x02032b)
	dev->start = 0;
#endif
	netif_stop_queue(dev);
	pUmDevice->opened = 0;

#ifdef BCM_ASF
	if( !(pDevice->AsfFlags & ASF_ENABLED) )
#endif
#ifdef BCM_WOL
		if( enable_wol[pUmDevice->index] == 0 )
#endif
			B57_INFO(("%s: %s NIC Link is DOWN\n", bcm5700_driver, dev->name));

	if (tigon3_debug > 1)
		printk(KERN_DEBUG "%s: Shutting down Tigon3\n",
			   dev->name);

	LM_MulticastClear(pDevice);
	bcm5700_shutdown(pUmDevice);

	if (T3_ASIC_IS_5705_BEYOND(pDevice->ChipRevId)) {
		del_timer_sync(&pUmDevice->statstimer);
	}

	del_timer_sync(&pUmDevice->timer);

	free_irq(pUmDevice->pdev->irq, dev);

#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)

	if(pDevice->Flags & USING_MSI_FLAG) {
		pci_disable_msi(pUmDevice->pdev);
                REG_WR(pDevice, Msi.Mode,  1 );
		pDevice->Flags &= ~USING_MSI_FLAG;
	}

#endif


#if (LINUX_VERSION_CODE < 0x020300)
	MOD_DEC_USE_COUNT;
#endif
	{
	/* BCM4785: Don't go to low-power state because it will power down the smbus block. */
	if (!(pDevice->Flags & SB_CORE_FLAG))
		LM_SetPowerState(pDevice, LM_POWER_STATE_D3);
	}

	bcm5700_freemem(dev);

	QQ_InitQueue(&pDevice->RxPacketFreeQ.Container,
        		MAX_RX_PACKET_DESC_COUNT);

	return 0;
}

STATIC int
bcm5700_freemem(struct net_device *dev)
{
	int i;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	LM_DEVICE_BLOCK	 *pDevice = &pUmDevice->lm_dev;

	for (i = 0; i < pUmDevice->mem_list_num; i++) {
		if (pUmDevice->mem_size_list[i] == 0) {
			kfree(pUmDevice->mem_list[i]);
		}
		else {
			pci_free_consistent(pUmDevice->pdev,
				(size_t) pUmDevice->mem_size_list[i],
				pUmDevice->mem_list[i],
				pUmDevice->dma_list[i]);
		}
	}

	pDevice->pStatusBlkVirt = 0;
	pDevice->pStatsBlkVirt  = 0;
	pUmDevice->mem_list_num = 0;

	return 0;
}

uint64_t
bcm5700_crc_count(PUM_DEVICE_BLOCK pUmDevice)
{
	PLM_DEVICE_BLOCK pDevice = &pUmDevice->lm_dev;
	LM_UINT32 Value32;
	PT3_STATS_BLOCK pStats = (PT3_STATS_BLOCK) pDevice->pStatsBlkVirt;
	unsigned long flags;

	if ((T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
		T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701) &&
		!(pDevice->TbiFlags & ENABLE_TBI_FLAG)) {

		if (!pUmDevice->opened || !pDevice->InitDone)
		{

			return 0;
		}

		/* regulate MDIO access during run time */
		if (pUmDevice->crc_counter_expiry > 0)
			return pUmDevice->phy_crc_count;

		pUmDevice->crc_counter_expiry = (5 * HZ) /
			pUmDevice->timer_interval;

		BCM5700_PHY_LOCK(pUmDevice, flags);
		LM_ReadPhy(pDevice, 0x1e, &Value32);
		if ((Value32 & 0x8000) == 0)
			LM_WritePhy(pDevice, 0x1e, Value32 | 0x8000);
		LM_ReadPhy(pDevice, 0x14, &Value32);
		BCM5700_PHY_UNLOCK(pUmDevice, flags);
		/* Sometimes data on the MDIO bus can be corrupted */
		if (Value32 != 0xffff)
			pUmDevice->phy_crc_count += Value32;
		return pUmDevice->phy_crc_count;
	}
	else if (pStats == 0) {
		return 0;
	}
	else {
		return (MM_GETSTATS64(pStats->dot3StatsFCSErrors));
	}
}

uint64_t
bcm5700_rx_err_count(UM_DEVICE_BLOCK *pUmDevice)
{
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;
	T3_STATS_BLOCK *pStats = (T3_STATS_BLOCK *) pDevice->pStatsBlkVirt;

	if (pStats == 0)
		return 0;
	return (bcm5700_crc_count(pUmDevice) +
		MM_GETSTATS64(pStats->dot3StatsAlignmentErrors) +
		MM_GETSTATS64(pStats->etherStatsUndersizePkts) +
		MM_GETSTATS64(pStats->etherStatsFragments) +
		MM_GETSTATS64(pStats->dot3StatsFramesTooLong) +
		MM_GETSTATS64(pStats->etherStatsJabbers));
}

STATIC struct net_device_stats *
bcm5700_get_stats(struct net_device *dev)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	PT3_STATS_BLOCK pStats = (PT3_STATS_BLOCK) pDevice->pStatsBlkVirt;
	struct net_device_stats *p_netstats = &pUmDevice->stats;

	if (pStats == 0)
		return p_netstats;

	/* Get stats from LM */
	p_netstats->rx_packets =
		MM_GETSTATS(pStats->ifHCInUcastPkts) +
		MM_GETSTATS(pStats->ifHCInMulticastPkts) +
		MM_GETSTATS(pStats->ifHCInBroadcastPkts);
	p_netstats->tx_packets =
		MM_GETSTATS(pStats->ifHCOutUcastPkts) +
		MM_GETSTATS(pStats->ifHCOutMulticastPkts) +
		MM_GETSTATS(pStats->ifHCOutBroadcastPkts);
	/* There counters seem to be innacurate. Use byte number accumulation 
	   instead.
	   p_netstats->rx_bytes = MM_GETSTATS(pStats->ifHCInOctets);
	   p_netstats->tx_bytes = MM_GETSTATS(pStats->ifHCOutOctets);
	*/
	p_netstats->tx_errors =
		MM_GETSTATS(pStats->dot3StatsInternalMacTransmitErrors) +
		MM_GETSTATS(pStats->dot3StatsCarrierSenseErrors) +
		MM_GETSTATS(pStats->ifOutDiscards) +
		MM_GETSTATS(pStats->ifOutErrors);
	p_netstats->multicast = MM_GETSTATS(pStats->ifHCInMulticastPkts);
	p_netstats->collisions = MM_GETSTATS(pStats->etherStatsCollisions);
	p_netstats->rx_length_errors =
		MM_GETSTATS(pStats->dot3StatsFramesTooLong) +
		MM_GETSTATS(pStats->etherStatsUndersizePkts);
	p_netstats->rx_over_errors = MM_GETSTATS(pStats->nicNoMoreRxBDs);
	p_netstats->rx_frame_errors =
		MM_GETSTATS(pStats->dot3StatsAlignmentErrors);
	p_netstats->rx_crc_errors = (unsigned long)
		bcm5700_crc_count(pUmDevice);
	p_netstats->rx_errors = (unsigned long)
		bcm5700_rx_err_count(pUmDevice);

	p_netstats->tx_aborted_errors = MM_GETSTATS(pStats->ifOutDiscards);
	p_netstats->tx_carrier_errors =
		MM_GETSTATS(pStats->dot3StatsCarrierSenseErrors);

	return p_netstats;
}

void
b57_suspend_chip(UM_DEVICE_BLOCK *pUmDevice)
{
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;

	if (pUmDevice->opened) {
		bcm5700_intr_off(pUmDevice);
		netif_carrier_off(pUmDevice->dev);
		netif_stop_queue(pUmDevice->dev);
#ifdef BCM_TASKLET
		tasklet_kill(&pUmDevice->tasklet);
#endif
		bcm5700_poll_wait(pUmDevice);
	}
	pUmDevice->suspended = 1;
	LM_ShutdownChip(pDevice, LM_SUSPEND_RESET);
}

void
b57_resume_chip(UM_DEVICE_BLOCK *pUmDevice)
{
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;

	if (pUmDevice->suspended) {
		pUmDevice->suspended = 0;
		if (pUmDevice->opened) {
			bcm5700_reset(pUmDevice->dev);
		}
		else {
			LM_ShutdownChip(pDevice, LM_SHUTDOWN_RESET);
		}
	}
}

/* Returns 0 on failure, 1 on success */
int
b57_test_intr(UM_DEVICE_BLOCK *pUmDevice)
{
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;
	int j;

	if (!pUmDevice->opened)
		return 0;
	pUmDevice->intr_test_result = 0;
	pUmDevice->intr_test = 1;

	REG_WR(pDevice, HostCoalesce.Mode,
		pDevice->CoalesceMode | HOST_COALESCE_ENABLE |
		HOST_COALESCE_NOW);

	for (j = 0; j < 10; j++) {
		if (pUmDevice->intr_test_result){
			break;
		}

		REG_WR(pDevice, HostCoalesce.Mode,
		pDevice->CoalesceMode | HOST_COALESCE_ENABLE |
		HOST_COALESCE_NOW);

		MM_Sleep(pDevice, 1);
	}

	return pUmDevice->intr_test_result;

}

#ifdef SIOCETHTOOL

#ifdef ETHTOOL_GSTRINGS

#define ETH_NUM_STATS 30
#define RX_CRC_IDX 5
#define RX_MAC_ERR_IDX 14

struct {
	char string[ETH_GSTRING_LEN];
} bcm5700_stats_str_arr[ETH_NUM_STATS] = {
	{ "rx_unicast_packets" },
	{ "rx_multicast_packets" },
	{ "rx_broadcast_packets" },
	{ "rx_bytes" },
	{ "rx_fragments" },
	{ "rx_crc_errors" },	/* this needs to be calculated */
	{ "rx_align_errors" },
	{ "rx_xon_frames" },
	{ "rx_xoff_frames" },
	{ "rx_long_frames" },
	{ "rx_short_frames" },
	{ "rx_jabber" },
	{ "rx_discards" },
	{ "rx_errors" },
	{ "rx_mac_errors" },	/* this needs to be calculated */
	{ "tx_unicast_packets" },
	{ "tx_multicast_packets" },
	{ "tx_broadcast_packets" },
	{ "tx_bytes" },
	{ "tx_deferred" },
	{ "tx_single_collisions" },
	{ "tx_multi_collisions" },
	{ "tx_total_collisions" },
	{ "tx_excess_collisions" },
	{ "tx_late_collisions" },
	{ "tx_xon_frames" },
	{ "tx_xoff_frames" },
	{ "tx_internal_mac_errors" },
	{ "tx_carrier_errors" },
	{ "tx_errors" },
};

#define STATS_OFFSET(offset_name) ((OFFSETOF(T3_STATS_BLOCK, offset_name)) / sizeof(uint64_t))

#ifdef __BIG_ENDIAN
#define SWAP_DWORD_64(x) (x)
#else
#define SWAP_DWORD_64(x) ((x << 32) | (x >> 32))
#endif

unsigned long bcm5700_stats_offset_arr[ETH_NUM_STATS] = {
	STATS_OFFSET(ifHCInUcastPkts),
	STATS_OFFSET(ifHCInMulticastPkts),
	STATS_OFFSET(ifHCInBroadcastPkts),
	STATS_OFFSET(ifHCInOctets),
	STATS_OFFSET(etherStatsFragments),
	0,
	STATS_OFFSET(dot3StatsAlignmentErrors),
	STATS_OFFSET(xonPauseFramesReceived),
	STATS_OFFSET(xoffPauseFramesReceived),
	STATS_OFFSET(dot3StatsFramesTooLong),
	STATS_OFFSET(etherStatsUndersizePkts),
	STATS_OFFSET(etherStatsJabbers),
	STATS_OFFSET(ifInDiscards),
	STATS_OFFSET(ifInErrors),
	0,
	STATS_OFFSET(ifHCOutUcastPkts),
	STATS_OFFSET(ifHCOutMulticastPkts),
	STATS_OFFSET(ifHCOutBroadcastPkts),
	STATS_OFFSET(ifHCOutOctets),
	STATS_OFFSET(dot3StatsDeferredTransmissions),
	STATS_OFFSET(dot3StatsSingleCollisionFrames),
	STATS_OFFSET(dot3StatsMultipleCollisionFrames),
	STATS_OFFSET(etherStatsCollisions),
	STATS_OFFSET(dot3StatsExcessiveCollisions),
	STATS_OFFSET(dot3StatsLateCollisions),
	STATS_OFFSET(outXonSent),
	STATS_OFFSET(outXoffSent),
	STATS_OFFSET(dot3StatsInternalMacTransmitErrors),
	STATS_OFFSET(dot3StatsCarrierSenseErrors),
	STATS_OFFSET(ifOutErrors),
};

#endif /* ETHTOOL_GSTRINGS */


#ifdef ETHTOOL_GREGS
#if (LINUX_VERSION_CODE >= 0x02040f)
static void
bcm5700_get_reg_blk(UM_DEVICE_BLOCK *pUmDevice, u32 **buf, u32 start, u32 end,
		int reserved)
{
	u32 offset;
	LM_DEVICE_BLOCK *pDevice = &pUmDevice->lm_dev;

	if (reserved) {
		memset(*buf, 0, end - start);
		*buf = *buf + (end - start)/4;
		return;
	}
	for (offset = start; offset < end; offset+=4, *buf = *buf + 1) {
		if (T3_ASIC_IS_5705_BEYOND(pDevice->ChipRevId)){
			if (((offset >= 0x3400) && (offset < 0x3c00)) ||
				((offset >= 0x5400) && (offset < 0x5800)) ||
				((offset >= 0x6400) && (offset < 0x6800))) {
				**buf = 0;
				continue;
			}
		}
		**buf = REG_RD_OFFSET(pDevice, offset);
	}
}
#endif
#endif

static int netdev_ethtool_ioctl(struct net_device *dev, void *useraddr)
{
	struct ethtool_cmd ethcmd;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;

	if (mm_copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
		return -EFAULT;

        switch (ethcmd.cmd) {
#ifdef ETHTOOL_GDRVINFO
        case ETHTOOL_GDRVINFO: {
		struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};

		strcpy(info.driver,  bcm5700_driver);
#ifdef INCLUDE_5701_AX_FIX
		if(pDevice->ChipRevId == T3_CHIP_ID_5701_A0) {
			extern int t3FwReleaseMajor;
			extern int t3FwReleaseMinor;
			extern int t3FwReleaseFix;

			sprintf(info.fw_version, "%i.%i.%i",
				t3FwReleaseMajor, t3FwReleaseMinor,
				t3FwReleaseFix);
		}
#endif
		strcpy(info.fw_version, pDevice->BootCodeVer);
		strcpy(info.version, bcm5700_version);
#if (LINUX_VERSION_CODE <= 0x020422)
		strcpy(info.bus_info, pUmDevice->pdev->slot_name);
#else
		strcpy(info.bus_info, pci_name(pUmDevice->pdev));
#endif



#ifdef ETHTOOL_GEEPROM
		BCM_EEDUMP_LEN(&info, pDevice->NvramSize);
#endif
#ifdef ETHTOOL_GREGS
		/* dump everything, including holes in the register space */
		info.regdump_len = 0x6c00;
#endif
#ifdef ETHTOOL_GSTATS
		info.n_stats = ETH_NUM_STATS;
#endif
		if (mm_copy_to_user(useraddr, &info, sizeof(info)))
			return -EFAULT;
		return 0;
	}
#endif
        case ETHTOOL_GSET: {
		if ((pDevice->TbiFlags & ENABLE_TBI_FLAG)||
			(pDevice->PhyFlags & PHY_IS_FIBER)) {
			ethcmd.supported =
				(SUPPORTED_1000baseT_Full |
				SUPPORTED_Autoneg);
			ethcmd.supported |= SUPPORTED_FIBRE;
			ethcmd.port = PORT_FIBRE;
		} else {
			ethcmd.supported =
				(SUPPORTED_10baseT_Half |
				SUPPORTED_10baseT_Full |
				SUPPORTED_100baseT_Half |
				SUPPORTED_100baseT_Full |
				SUPPORTED_1000baseT_Half |
				SUPPORTED_1000baseT_Full |
				SUPPORTED_Autoneg);
			ethcmd.supported |= SUPPORTED_TP;
			ethcmd.port = PORT_TP;
		}

		ethcmd.transceiver = XCVR_INTERNAL;
		ethcmd.phy_address = 0;

		if (pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS)
			ethcmd.speed = SPEED_1000;
		else if (pDevice->LineSpeed == LM_LINE_SPEED_100MBPS)
			ethcmd.speed = SPEED_100;
		else if (pDevice->LineSpeed == LM_LINE_SPEED_10MBPS)
			ethcmd.speed = SPEED_10;
		else
			ethcmd.speed = 0;

		if (pDevice->DuplexMode == LM_DUPLEX_MODE_FULL)
			ethcmd.duplex = DUPLEX_FULL;
		else
			ethcmd.duplex = DUPLEX_HALF;

		if (pDevice->DisableAutoNeg == FALSE) {
			ethcmd.autoneg = AUTONEG_ENABLE;
			ethcmd.advertising = ADVERTISED_Autoneg;
			if ((pDevice->TbiFlags & ENABLE_TBI_FLAG) ||
				(pDevice->PhyFlags & PHY_IS_FIBER)) {
				ethcmd.advertising |=
					ADVERTISED_1000baseT_Full |
					ADVERTISED_FIBRE;
			}
			else {
				ethcmd.advertising |=
					ADVERTISED_TP;
				if (pDevice->advertising &
					PHY_AN_AD_10BASET_HALF) {

					ethcmd.advertising |=
						ADVERTISED_10baseT_Half;
				}
				if (pDevice->advertising &
					PHY_AN_AD_10BASET_FULL) {

					ethcmd.advertising |=
						ADVERTISED_10baseT_Full;
				}
				if (pDevice->advertising &
					PHY_AN_AD_100BASETX_HALF) {

					ethcmd.advertising |=
						ADVERTISED_100baseT_Half;
				}
				if (pDevice->advertising &
					PHY_AN_AD_100BASETX_FULL) {

					ethcmd.advertising |=
						ADVERTISED_100baseT_Full;
				}
				if (pDevice->advertising1000 &
					BCM540X_AN_AD_1000BASET_HALF) {

					ethcmd.advertising |=
						ADVERTISED_1000baseT_Half;
				}
				if (pDevice->advertising1000 &
					BCM540X_AN_AD_1000BASET_FULL) {

					ethcmd.advertising |=
						ADVERTISED_1000baseT_Full;
				}
			}
		}
		else {
			ethcmd.autoneg = AUTONEG_DISABLE;
			ethcmd.advertising = 0;
		}

		ethcmd.maxtxpkt = pDevice->TxMaxCoalescedFrames;
		ethcmd.maxrxpkt = pDevice->RxMaxCoalescedFrames;

		if(mm_copy_to_user(useraddr, &ethcmd, sizeof(ethcmd)))
			return -EFAULT;
		return 0;
	}
	case ETHTOOL_SSET: {
		unsigned long flags;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (ethcmd.autoneg == AUTONEG_ENABLE) {
			pDevice->RequestedLineSpeed = LM_LINE_SPEED_AUTO;
			pDevice->RequestedDuplexMode = LM_DUPLEX_MODE_UNKNOWN;
			pDevice->DisableAutoNeg = FALSE;
		}
		else {
			if (ethcmd.speed == SPEED_1000 &&
				pDevice->PhyFlags & PHY_NO_GIGABIT)
					return -EINVAL;

			if (ethcmd.speed == SPEED_1000 &&
			    (pDevice->TbiFlags & ENABLE_TBI_FLAG ||
			     pDevice->PhyFlags & PHY_IS_FIBER ) ) {

				pDevice->RequestedLineSpeed =
					LM_LINE_SPEED_1000MBPS;

				pDevice->RequestedDuplexMode =
					LM_DUPLEX_MODE_FULL;
			}
			else if (ethcmd.speed == SPEED_100 &&
			        !(pDevice->TbiFlags & ENABLE_TBI_FLAG) &&
			     	!(pDevice->PhyFlags & PHY_IS_FIBER)) {

				pDevice->RequestedLineSpeed =
					LM_LINE_SPEED_100MBPS;
			}
			else if (ethcmd.speed == SPEED_10  &&
			        !(pDevice->TbiFlags & ENABLE_TBI_FLAG) &&
			     	!(pDevice->PhyFlags & PHY_IS_FIBER)) {

                                pDevice->RequestedLineSpeed =
					LM_LINE_SPEED_10MBPS;
			}
			else {
				return -EINVAL;
			}

			pDevice->DisableAutoNeg = TRUE;
			if (ethcmd.duplex == DUPLEX_FULL) {
				pDevice->RequestedDuplexMode =
					LM_DUPLEX_MODE_FULL;
			}
			else {
				if (!(pDevice->TbiFlags & ENABLE_TBI_FLAG) &&
			     	    !(pDevice->PhyFlags & PHY_IS_FIBER)  ) {

					pDevice->RequestedDuplexMode =
							LM_DUPLEX_MODE_HALF;
				}
			}
		}
		if (netif_running(dev)) {
			BCM5700_PHY_LOCK(pUmDevice, flags);
			LM_SetupPhy(pDevice);
			BCM5700_PHY_UNLOCK(pUmDevice, flags);
		}
		return 0;
	}
#ifdef ETHTOOL_GWOL
#ifdef BCM_WOL
	case ETHTOOL_GWOL: {
		struct ethtool_wolinfo wol = {ETHTOOL_GWOL};

		if (((pDevice->TbiFlags & ENABLE_TBI_FLAG) &&
			!(pDevice->Flags & FIBER_WOL_CAPABLE_FLAG)) ||
			(pDevice->Flags & DISABLE_D3HOT_FLAG)) {
			wol.supported = 0;
			wol.wolopts = 0;
		}
		else {
			wol.supported = WAKE_MAGIC;
			if (pDevice->WakeUpMode == LM_WAKE_UP_MODE_MAGIC_PACKET)
			{
				wol.wolopts = WAKE_MAGIC;
			}
			else {
				wol.wolopts = 0;
			}
		}
		if (mm_copy_to_user(useraddr, &wol, sizeof(wol)))
			return -EFAULT;
		return 0;
	}
	case ETHTOOL_SWOL: {
		struct ethtool_wolinfo wol;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (mm_copy_from_user(&wol, useraddr, sizeof(wol)))
			return -EFAULT;
		if ((((pDevice->TbiFlags & ENABLE_TBI_FLAG) &&
			!(pDevice->Flags & FIBER_WOL_CAPABLE_FLAG)) ||
			(pDevice->Flags & DISABLE_D3HOT_FLAG)) &&
			wol.wolopts) {
			return -EINVAL;
		}

		if ((wol.wolopts & ~WAKE_MAGIC) != 0) {
			return -EINVAL;
		}
		if (wol.wolopts & WAKE_MAGIC) {
			pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_MAGIC_PACKET;
			pDevice->WakeUpMode = LM_WAKE_UP_MODE_MAGIC_PACKET;
		}
		else {
			pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_NONE;
			pDevice->WakeUpMode = LM_WAKE_UP_MODE_NONE;
		}
		return 0;
        }
#endif
#endif
#ifdef ETHTOOL_GLINK
	case ETHTOOL_GLINK: {
		struct ethtool_value edata = {ETHTOOL_GLINK};

		/* ifup only waits for 5 seconds for link up */
		/* NIC may take more than 5 seconds to establish link */
		if ((pUmDevice->delayed_link_ind > 0) &&
			delay_link[pUmDevice->index])
			return -EOPNOTSUPP;

		if (pDevice->LinkStatus == LM_STATUS_LINK_ACTIVE) {
			edata.data =  1;
		}
		else {
			edata.data =  0;
		}
		if (mm_copy_to_user(useraddr, &edata, sizeof(edata)))
			return -EFAULT;
		return 0;
	}
#endif
#ifdef ETHTOOL_NWAY_RST
	case ETHTOOL_NWAY_RST: {
		LM_UINT32 phyctrl;
		unsigned long flags;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (pDevice->DisableAutoNeg) {
			return -EINVAL;
		}
		if (!netif_running(dev))
			return -EAGAIN;
		BCM5700_PHY_LOCK(pUmDevice, flags);
		if (pDevice->TbiFlags & ENABLE_TBI_FLAG) { 
			pDevice->RequestedLineSpeed = LM_LINE_SPEED_1000MBPS;
			pDevice->DisableAutoNeg = TRUE;
			LM_SetupPhy(pDevice);

			pDevice->RequestedLineSpeed = LM_LINE_SPEED_AUTO;
			pDevice->DisableAutoNeg = FALSE;
			LM_SetupPhy(pDevice);
		}
		else {
			if ((T3_ASIC_REV(pDevice->ChipRevId) ==
					T3_ASIC_REV_5703) ||
				(T3_ASIC_REV(pDevice->ChipRevId) ==
					T3_ASIC_REV_5704) ||
				(T3_ASIC_REV(pDevice->ChipRevId) ==
					T3_ASIC_REV_5705))
			{
				LM_ResetPhy(pDevice);
				LM_SetupPhy(pDevice);
			}
			pDevice->PhyFlags &= ~PHY_FIBER_FALLBACK;
			LM_ReadPhy(pDevice, PHY_CTRL_REG, &phyctrl);
			LM_WritePhy(pDevice, PHY_CTRL_REG, phyctrl |
				PHY_CTRL_AUTO_NEG_ENABLE |
				PHY_CTRL_RESTART_AUTO_NEG);
		}
		BCM5700_PHY_UNLOCK(pUmDevice, flags);
		return 0;
	}
#endif
#ifdef ETHTOOL_GEEPROM
	case ETHTOOL_GEEPROM: {
		struct ethtool_eeprom eeprom;
		LM_UINT32 *buf = 0;
		LM_UINT32 buf1[64/4];
		int i, j, offset, len;

		if (mm_copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
			return -EFAULT;

		if (eeprom.offset >= pDevice->NvramSize)
			return -EFAULT;

		/* maximum data limited */
		/* to read more, call again with a different offset */
		if (eeprom.len > 0x800) {
			eeprom.len = 0x800;
			if (mm_copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
				return -EFAULT;
		}

		if (eeprom.len > 64) {
			buf = kmalloc(eeprom.len, GFP_KERNEL);
			if (!buf)
				return -ENOMEM;
		}
		else {
			buf = buf1;
		}
		useraddr += offsetof(struct ethtool_eeprom, data);

		offset = eeprom.offset;
		len = eeprom.len;
		if (offset & 3) {
			offset &= 0xfffffffc;
			len += (offset & 3);
		}
		len = (len + 3) & 0xfffffffc;
		for (i = 0, j = 0; j < len; i++, j += 4) {
			if (LM_NvramRead(pDevice, offset + j, buf + i) !=
				LM_STATUS_SUCCESS) {
				break;
			}
		}
		if (j >= len) {
			buf += (eeprom.offset & 3);
			i = mm_copy_to_user(useraddr, buf, eeprom.len);
		}
		if (eeprom.len > 64) {
			kfree(buf);
		}
		if ((j < len) || i)
			return -EFAULT;
		return 0;
	}
	case ETHTOOL_SEEPROM: {
		struct ethtool_eeprom eeprom;
		LM_UINT32 buf[64/4];
		int i, offset, len;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (mm_copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
			return -EFAULT;

		if ((eeprom.offset & 3) || (eeprom.len & 3) ||
			(eeprom.offset >= pDevice->NvramSize)) {
			return -EFAULT;
		}

		if ((eeprom.offset + eeprom.len) >= pDevice->NvramSize) {
			eeprom.len = pDevice->NvramSize - eeprom.offset;
		}

		useraddr += offsetof(struct ethtool_eeprom, data);

		len = eeprom.len;
		offset = eeprom.offset;
		for (; len > 0; ) {
			if (len < 64)
				i = len;
			else
				i = 64;
			if (mm_copy_from_user(&buf, useraddr, i))
				return -EFAULT;

			bcm5700_intr_off(pUmDevice);
			/* Prevent race condition on Grc.Mode register */
			bcm5700_poll_wait(pUmDevice);

			if (LM_NvramWriteBlock(pDevice, offset, buf, i/4) !=
				LM_STATUS_SUCCESS) {
				bcm5700_intr_on(pUmDevice);
				return -EFAULT;
			}
			bcm5700_intr_on(pUmDevice);
			len -= i;
			offset += i;
			useraddr += i;
		}
		return 0;
	}
#endif
#ifdef ETHTOOL_GREGS
#if (LINUX_VERSION_CODE >= 0x02040f)
	case ETHTOOL_GREGS: {
		struct ethtool_regs eregs;
		LM_UINT32 *buf, *buf1;
		unsigned int i;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (pDevice->Flags & UNDI_FIX_FLAG)
			return -EOPNOTSUPP;
		if (mm_copy_from_user(&eregs, useraddr, sizeof(eregs)))
			return -EFAULT;
		if (eregs.len > 0x6c00)
			eregs.len = 0x6c00;
		eregs.version = 0x0;
		if (mm_copy_to_user(useraddr, &eregs, sizeof(eregs)))
			return -EFAULT;
		buf = buf1 = kmalloc(eregs.len, GFP_KERNEL);
		if (!buf)
			return -ENOMEM;
		bcm5700_get_reg_blk(pUmDevice, &buf, 0,      0xb0,   0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0xb0,   0x200,  1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x200,  0x8f0,  0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x8f0,  0xc00,  1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0xc00,  0xce0,  0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0xce0,  0x1000, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x1000, 0x1004, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x1004, 0x1400, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x1400, 0x1480, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x1480, 0x1800, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x1800, 0x1848, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x1848, 0x1c00, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x1c00, 0x1c04, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x1c04, 0x2000, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x2000, 0x225c, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x225c, 0x2400, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x2400, 0x24c4, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x24c4, 0x2800, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x2800, 0x2804, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x2804, 0x2c00, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x2c00, 0x2c20, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x2c20, 0x3000, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x3000, 0x3014, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x3014, 0x3400, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x3400, 0x3408, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x3408, 0x3800, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x3800, 0x3808, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x3808, 0x3c00, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x3c00, 0x3d00, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x3d00, 0x4000, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x4000, 0x4010, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x4010, 0x4400, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x4400, 0x4458, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x4458, 0x4800, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x4800, 0x4808, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x4808, 0x4c00, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x4c00, 0x4c08, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x4c08, 0x5000, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x5000, 0x5050, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x5050, 0x5400, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x5400, 0x5450, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x5450, 0x5800, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x5800, 0x5a10, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x5a10, 0x6000, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x6000, 0x600c, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x600c, 0x6400, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x6400, 0x6404, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x6404, 0x6800, 1);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x6800, 0x6848, 0);
		bcm5700_get_reg_blk(pUmDevice, &buf, 0x6848, 0x6c00, 1);

		i = mm_copy_to_user(useraddr + sizeof(eregs), buf1, eregs.len);
		kfree(buf1);
		if (i)
			return -EFAULT;
		return 0;
	}
#endif
#endif
#ifdef ETHTOOL_GPAUSEPARAM
	case ETHTOOL_GPAUSEPARAM: {
		struct ethtool_pauseparam epause = { ETHTOOL_GPAUSEPARAM };

		if (!pDevice->DisableAutoNeg) {
			epause.autoneg = (pDevice->FlowControlCap &
				LM_FLOW_CONTROL_AUTO_PAUSE) != 0;
		}
		else {
			epause.autoneg = 0;
		}
		epause.rx_pause =
			(pDevice->FlowControl &
			LM_FLOW_CONTROL_RECEIVE_PAUSE) != 0;
		epause.tx_pause =
			(pDevice->FlowControl &
			LM_FLOW_CONTROL_TRANSMIT_PAUSE) != 0;
		if (mm_copy_to_user(useraddr, &epause, sizeof(epause)))
			return -EFAULT;

		return 0;
	}
	case ETHTOOL_SPAUSEPARAM: {
		struct ethtool_pauseparam epause;
		unsigned long flags;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (mm_copy_from_user(&epause, useraddr, sizeof(epause)))
			return -EFAULT;
		pDevice->FlowControlCap = 0;
		if (epause.autoneg && !pDevice->DisableAutoNeg) {
			pDevice->FlowControlCap |= LM_FLOW_CONTROL_AUTO_PAUSE;
		}
		if (epause.rx_pause)  {
			pDevice->FlowControlCap |=
				LM_FLOW_CONTROL_RECEIVE_PAUSE;
		}
		if (epause.tx_pause)  {
			pDevice->FlowControlCap |=
				LM_FLOW_CONTROL_TRANSMIT_PAUSE;
		}
		if (netif_running(dev)) {
			BCM5700_PHY_LOCK(pUmDevice, flags);
			LM_SetupPhy(pDevice);
			BCM5700_PHY_UNLOCK(pUmDevice, flags);
		}

		return 0;
	}
#endif
#ifdef ETHTOOL_GRXCSUM
	case ETHTOOL_GRXCSUM: {
		struct ethtool_value edata = { ETHTOOL_GRXCSUM };

		edata.data =
			(pDevice->TaskToOffload &
			LM_TASK_OFFLOAD_RX_TCP_CHECKSUM) != 0;
		if (mm_copy_to_user(useraddr, &edata, sizeof(edata)))
			return -EFAULT;

		return 0;
	}
	case ETHTOOL_SRXCSUM: {
		struct ethtool_value edata;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (mm_copy_from_user(&edata, useraddr, sizeof(edata)))
			return -EFAULT;
		if (edata.data) {
			if (!(pDevice->TaskOffloadCap &
				LM_TASK_OFFLOAD_TX_TCP_CHECKSUM)) {

				return -EINVAL;
			}
			pDevice->TaskToOffload |=
				LM_TASK_OFFLOAD_RX_TCP_CHECKSUM |
				LM_TASK_OFFLOAD_RX_UDP_CHECKSUM;
		}
		else {
			pDevice->TaskToOffload &=
				~(LM_TASK_OFFLOAD_RX_TCP_CHECKSUM |
				LM_TASK_OFFLOAD_RX_UDP_CHECKSUM);
		}
		return 0;
	}
	case ETHTOOL_GTXCSUM: {
		struct ethtool_value edata = { ETHTOOL_GTXCSUM };

		edata.data =
			(dev->features & get_csum_flag( pDevice->ChipRevId)) != 0;
		if (mm_copy_to_user(useraddr, &edata, sizeof(edata)))
			return -EFAULT;

		return 0;
	}
	case ETHTOOL_STXCSUM: {
		struct ethtool_value edata;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (mm_copy_from_user(&edata, useraddr, sizeof(edata)))
			return -EFAULT;
		if (edata.data) {
			if (!(pDevice->TaskOffloadCap &
				LM_TASK_OFFLOAD_TX_TCP_CHECKSUM)) {

				return -EINVAL;
			}
			dev->features |= get_csum_flag( pDevice->ChipRevId);
			pDevice->TaskToOffload |=
				LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
				LM_TASK_OFFLOAD_TX_UDP_CHECKSUM;
		}
		else {
			dev->features &= ~get_csum_flag( pDevice->ChipRevId);
			pDevice->TaskToOffload &=
				~(LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
				LM_TASK_OFFLOAD_TX_UDP_CHECKSUM);
		}
		return 0;
	}
	case ETHTOOL_GSG: {
		struct ethtool_value edata = { ETHTOOL_GSG };

		edata.data =
			(dev->features & NETIF_F_SG) != 0;
		if (mm_copy_to_user(useraddr, &edata, sizeof(edata)))
			return -EFAULT;
		return 0;
	}
	case ETHTOOL_SSG: {
		struct ethtool_value edata;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (mm_copy_from_user(&edata, useraddr, sizeof(edata)))
			return -EFAULT;
		if (edata.data) {
			dev->features |= NETIF_F_SG;
		}
		else {
			dev->features &= ~NETIF_F_SG;
		}
		return 0;
	}
#endif
#ifdef ETHTOOL_GRINGPARAM
	case ETHTOOL_GRINGPARAM: {
		struct ethtool_ringparam ering = { ETHTOOL_GRINGPARAM };

		ering.rx_max_pending = T3_STD_RCV_RCB_ENTRY_COUNT - 1;
		ering.rx_pending = pDevice->RxStdDescCnt;
		ering.rx_mini_max_pending = 0;
		ering.rx_mini_pending = 0;
#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
		ering.rx_jumbo_max_pending = T3_JUMBO_RCV_RCB_ENTRY_COUNT - 1;
		ering.rx_jumbo_pending = pDevice->RxJumboDescCnt;
#else
		ering.rx_jumbo_max_pending = 0;
		ering.rx_jumbo_pending = 0;
#endif
		ering.tx_max_pending = MAX_TX_PACKET_DESC_COUNT - 1;
		ering.tx_pending = pDevice->TxPacketDescCnt;
		if (mm_copy_to_user(useraddr, &ering, sizeof(ering)))
			return -EFAULT;
		return 0;
	}
#endif
#ifdef ETHTOOL_PHYS_ID
	case ETHTOOL_PHYS_ID: {
		struct ethtool_value edata;

		if(!capable(CAP_NET_ADMIN))
			return -EPERM;
		if (mm_copy_from_user(&edata, useraddr, sizeof(edata)))
			return -EFAULT;
		if (LM_BlinkLED(pDevice, edata.data) == LM_STATUS_SUCCESS)
			return 0;
		return -EINTR;
	}
#endif
#ifdef ETHTOOL_GSTRINGS
	case ETHTOOL_GSTRINGS: {
		struct ethtool_gstrings egstr = { ETHTOOL_GSTRINGS };

		if (mm_copy_from_user(&egstr, useraddr, sizeof(egstr)))
			return -EFAULT;
		switch(egstr.string_set) {
#ifdef ETHTOOL_GSTATS
		case ETH_SS_STATS:
			egstr.len = ETH_NUM_STATS;
			if (mm_copy_to_user(useraddr, &egstr, sizeof(egstr)))
				return -EFAULT;
			if (mm_copy_to_user(useraddr + sizeof(egstr),
				bcm5700_stats_str_arr,
				sizeof(bcm5700_stats_str_arr)))
				return -EFAULT;
			return 0;
#endif
		default:
			return -EOPNOTSUPP;
		}
		}
#endif
#ifdef ETHTOOL_GSTATS
	case ETHTOOL_GSTATS: {
		struct ethtool_stats estats = { ETHTOOL_GSTATS };
		uint64_t stats[ETH_NUM_STATS];
		int i;
		uint64_t *pStats =
			(uint64_t *) pDevice->pStatsBlkVirt;

		estats.n_stats = ETH_NUM_STATS;
		if (pStats == 0) {
			memset(stats, 0, sizeof(stats));
		}
		else {

			for (i = 0; i < ETH_NUM_STATS; i++) {
				if (bcm5700_stats_offset_arr[i] != 0) {
					stats[i] = SWAP_DWORD_64(*(pStats +
						bcm5700_stats_offset_arr[i]));
				}
				else if (i == RX_CRC_IDX) {
					stats[i] =
						bcm5700_crc_count(pUmDevice);
				}
				else if (i == RX_MAC_ERR_IDX) {
					stats[i] =
						bcm5700_rx_err_count(pUmDevice);
				}
			}
		}
		if (mm_copy_to_user(useraddr, &estats, sizeof(estats))) {
			return -EFAULT;
		}
		if (mm_copy_to_user(useraddr + sizeof(estats), &stats,
			sizeof(stats))) {
			return -EFAULT;
		}
		return 0;
	}
#endif
#ifdef ETHTOOL_GTSO
	case ETHTOOL_GTSO: {
		struct ethtool_value edata = { ETHTOOL_GTSO };

#ifdef BCM_TSO
		edata.data =
			(dev->features & NETIF_F_TSO) != 0;
#else
		edata.data = 0;
#endif
		if (mm_copy_to_user(useraddr, &edata, sizeof(edata)))
			return -EFAULT;
		return 0;
	}
#endif
#ifdef ETHTOOL_STSO
	case ETHTOOL_STSO: {
#ifdef BCM_TSO
		struct ethtool_value edata;

		if (!capable(CAP_NET_ADMIN))
			return -EPERM;

		if (mm_copy_from_user(&edata, useraddr, sizeof(edata)))
			return -EFAULT;

		if (!(pDevice->TaskToOffload &
			LM_TASK_OFFLOAD_TCP_SEGMENTATION)) {
			return -EINVAL;
		}

		dev->features &= ~NETIF_F_TSO;

		if (edata.data) {
			if (T3_ASIC_5714_FAMILY(pDevice->ChipRevId) &&
			   (dev->mtu > 1500)) {
				printk(KERN_ALERT "%s: Jumbo Frames and TSO cannot simultaneously be enabled. Jumbo Frames enabled. TSO disabled.\n", dev->name);
			return -EINVAL;
			} else {
				dev->features |= NETIF_F_TSO;
			}
	        }
		return 0;
#else
		return -EINVAL;
#endif
	}
#endif
	}

	return -EOPNOTSUPP;
}
#endif /* #ifdef SIOCETHTOOL */

#if (LINUX_VERSION_CODE >= 0x20400) && (LINUX_VERSION_CODE < 0x20600)
#include <linux/iobuf.h>
#endif

/* Provide ioctl() calls to examine the MII xcvr state. */
STATIC int bcm5700_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	u16 *data = (u16 *)&rq->ifr_data;
	u32 value = 0;
	u16 page_num =0, addr_num =0, len =0;
	unsigned long flags;

	switch(cmd) {
	case SIOCGREG_STATUS: //Get register
	{
		struct reg_ioctl_data *rdata =(struct reg_ioctl_data *)rq->ifr_data;
                robo_info_t *robo = (robo_info_t *)pUmDevice->robo;
		page_num = rdata->page_num;
		addr_num = rdata->addr_num;
		len = rdata->len;
                printk("b57um SIOCGREG_STATUS cmd page[0x%x]addr[0x%x]len[%d].\n",page_num,addr_num,len);
		if (len == 6)
		{
			ReadDataFromRegister(robo,page_num,addr_num,len,(void *)&rdata->val_out);
			printk("val[0x%04x-0x%04x-0x%04x].\n",rdata->val_out[0],rdata->val_out[1],rdata->val_out[2]);
		}
		else if (len == 8)
		{
			ReadDataFromRegister(robo,page_num,addr_num,len,(void *)&rdata->val_out);
                        printk("val[0x%04x%04x-0x%04x%04x].\n",rdata->val_out[0],rdata->val_out[1],
				rdata->val_out[2],rdata->val_out[3]);
		}
		else if (len == 4) 
		{
			ReadDataFromRegister(robo,page_num,addr_num,len,(void *)&rdata->val_out);
                        printk("val[0x%04x%04x].\n",rdata->val_out[0],rdata->val_out[1]);
		}
		else 
		{
                        ReadDataFromRegister(robo,page_num,addr_num,len,(void *)&rdata->val_out);
                        printk("val[0x%04x].\n",rdata->val_out[0]);

		}
                if (mm_copy_to_user(rq->ifr_data, rdata, sizeof(struct reg_ioctl_data)))
		{
			printk("Fail mm_copy_to_user.\n");
                        return -EFAULT;
		}
                return 0;
	}
	break;
	case SIOCSREG_STATUS://Set register
	{
                struct reg_ioctl_data * wdata =(struct reg_ioctl_data *)rq->ifr_data;
		len = wdata->len;
		page_num = wdata->page_num;
		addr_num = wdata->addr_num;
                robo_info_t *robo = (robo_info_t *)pUmDevice->robo;
                if (len == 6)
                {
                        WriteDataToRegister(robo,page_num,addr_num,len,(void *)&wdata->val_in);
                        //printk("val[0x%04x-0x%04x-0x%04x].\n",val48[0],val48[1],val48[2]);
                }
                else if (len == 8)
                {
                        WriteDataToRegister(robo,page_num,addr_num,len,(void *)&wdata->val_in);
                        //printk("val[0x%04x-0x%04x-0x%04x-0x%04x].\n",val64[0],val64[1],val64[2],val64[3]);
                }
                else if (len == 4)
                {
                        WriteDataToRegister(robo,page_num,addr_num,len,(void *)&wdata->val_in);
                        //printk("val[0x%08x].\n",value);
                }
		else
		{
                        WriteDataToRegister(robo,page_num,addr_num,len,(void *)&wdata->val_in);
                        //printk("len[%d] val[0x%04x].\n",len,val16);
		}

                return 0;
	}
	break;
#ifdef SIOCGMIIPHY
	case SIOCGMIIPHY:		/* Get the address of the PHY in use. */

		data[0] = pDevice->PhyAddr;
		return 0;
#endif

#ifdef SIOCGMIIREG
	case SIOCGMIIREG:		/* Read the specified MII register. */
	{
		uint32 savephyaddr = 0;

		if (pDevice->TbiFlags & ENABLE_TBI_FLAG)
			return -EOPNOTSUPP;

		/* ifup only waits for 5 seconds for link up */
		/* NIC may take more than 5 seconds to establish link */
		if ((pUmDevice->delayed_link_ind > 0) &&
			delay_link[pUmDevice->index]) {
			return -EAGAIN;
		}

		BCM5700_PHY_LOCK(pUmDevice, flags);
		if (data[0] != 0xffff) {
			savephyaddr = pDevice->PhyAddr;
			pDevice->PhyAddr = data[0];
		}
		LM_ReadPhy(pDevice, data[1] & 0x1f, (LM_UINT32 *)&value);
		if (data[0] != 0xffff)
			pDevice->PhyAddr = savephyaddr;
		BCM5700_PHY_UNLOCK(pUmDevice, flags);
		data[3] = value & 0xffff;
		return 0;
	}
#endif

#ifdef SIOCSMIIREG
	case SIOCSMIIREG:		/* Write the specified MII register */
	{
		uint32 savephyaddr = 0;

		if (!capable(CAP_NET_ADMIN))
			return -EPERM;

		if (pDevice->TbiFlags & ENABLE_TBI_FLAG)
			return -EOPNOTSUPP;

		BCM5700_PHY_LOCK(pUmDevice, flags);
		if (data[0] != 0xffff) {
			savephyaddr = pDevice->PhyAddr;
			pDevice->PhyAddr = data[0];
		}
		LM_WritePhy(pDevice, data[1] & 0x1f, data[2]);
		if (data[0] != 0xffff)
			pDevice->PhyAddr = savephyaddr;
		BCM5700_PHY_UNLOCK(pUmDevice, flags);
		data[3] = 0;
		return 0;
	}
#endif

#ifdef SIOCETHTOOL
	case SIOCETHTOOL:
		return netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
#endif
	default:
		return -EOPNOTSUPP;
	}
	return -EOPNOTSUPP;
}

STATIC void bcm5700_do_rx_mode(struct net_device *dev)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	int i;
	struct dev_mc_list *mclist;

	LM_MulticastClear(pDevice);
	for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
			 i++, mclist = mclist->next) {
		LM_MulticastAdd(pDevice, (PLM_UINT8) &mclist->dmi_addr);
	}
	if (dev->flags & IFF_ALLMULTI) {
		if (!(pDevice->ReceiveMask & LM_ACCEPT_ALL_MULTICAST)) {
			LM_SetReceiveMask(pDevice,
				pDevice->ReceiveMask | LM_ACCEPT_ALL_MULTICAST);
		}
	}
	else if (pDevice->ReceiveMask & LM_ACCEPT_ALL_MULTICAST) {
		LM_SetReceiveMask(pDevice,
			pDevice->ReceiveMask & ~LM_ACCEPT_ALL_MULTICAST);
	}
	if (dev->flags & IFF_PROMISC) {
		if (!(pDevice->ReceiveMask & LM_PROMISCUOUS_MODE)) {
			LM_SetReceiveMask(pDevice,
				pDevice->ReceiveMask | LM_PROMISCUOUS_MODE);
		}
	}
	else if (pDevice->ReceiveMask & LM_PROMISCUOUS_MODE) {
		LM_SetReceiveMask(pDevice,
			pDevice->ReceiveMask & ~LM_PROMISCUOUS_MODE);
	}

}

STATIC void bcm5700_set_rx_mode(struct net_device *dev)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) pUmDevice;
	int i;
	struct dev_mc_list *mclist;
	unsigned long flags;

	BCM5700_PHY_LOCK(pUmDevice, flags);

	LM_MulticastClear(pDevice);
	for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
			 i++, mclist = mclist->next) {
		LM_MulticastAdd(pDevice, (PLM_UINT8) &mclist->dmi_addr);
	}
	if (dev->flags & IFF_ALLMULTI) {
		if (!(pDevice->ReceiveMask & LM_ACCEPT_ALL_MULTICAST)) {
			LM_SetReceiveMask(pDevice,
				pDevice->ReceiveMask | LM_ACCEPT_ALL_MULTICAST);
		}
	}
	else if (pDevice->ReceiveMask & LM_ACCEPT_ALL_MULTICAST) {
		LM_SetReceiveMask(pDevice,
			pDevice->ReceiveMask & ~LM_ACCEPT_ALL_MULTICAST);
	}
	if (dev->flags & IFF_PROMISC) {
		if (!(pDevice->ReceiveMask & LM_PROMISCUOUS_MODE)) {
			LM_SetReceiveMask(pDevice,
				pDevice->ReceiveMask | LM_PROMISCUOUS_MODE);
		}
	}
	else if (pDevice->ReceiveMask & LM_PROMISCUOUS_MODE) {
		LM_SetReceiveMask(pDevice,
			pDevice->ReceiveMask & ~LM_PROMISCUOUS_MODE);
	}

	BCM5700_PHY_UNLOCK(pUmDevice, flags);
}

/*
 * Set the hardware MAC address.
 */
STATIC int bcm5700_set_mac_addr(struct net_device *dev, void *p)
{
	struct sockaddr *addr=p;
	PLM_DEVICE_BLOCK pDevice = (PLM_DEVICE_BLOCK) dev->priv;
	UM_DEVICE_BLOCK *pUmDevice = (UM_DEVICE_BLOCK *) pDevice;

	if(is_valid_ether_addr(addr->sa_data)){

	    memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
	    if (pUmDevice->opened)
	        LM_SetMacAddress(pDevice, dev->dev_addr);
			bcm_robo_set_macaddr(pUmDevice->robo, dev->dev_addr);
            return 0;
        }
	return -EINVAL;
}

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
STATIC int bcm5700_change_mtu(struct net_device *dev, int new_mtu)
{
	int pkt_size = new_mtu + ETHERNET_PACKET_HEADER_SIZE;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)dev->priv;
	PLM_DEVICE_BLOCK pDevice = &pUmDevice->lm_dev;
	unsigned long flags;
	int reinit = 0;

	if ((pkt_size < MIN_ETHERNET_PACKET_SIZE_NO_CRC) ||
		(pkt_size > MAX_ETHERNET_JUMBO_PACKET_SIZE_NO_CRC)) {

		return -EINVAL;
	}
	if ( !(pDevice->Flags & JUMBO_CAPABLE_FLAG)    &&
		(pkt_size > MAX_ETHERNET_PACKET_SIZE_NO_CRC) ) {

		return -EINVAL;
	}
	if (pUmDevice->suspended)
		return -EAGAIN;

	if (pUmDevice->opened && (new_mtu != dev->mtu) &&
		(pDevice->Flags & JUMBO_CAPABLE_FLAG)) {
		reinit = 1;
	}

	BCM5700_PHY_LOCK(pUmDevice, flags);
	if (reinit) {
		netif_stop_queue(dev);
		bcm5700_shutdown(pUmDevice);
		bcm5700_freemem(dev);
	}

	dev->mtu = new_mtu;
	if (pkt_size < MAX_ETHERNET_PACKET_SIZE_NO_CRC) {
		pDevice->RxMtu = pDevice->TxMtu =
			MAX_ETHERNET_PACKET_SIZE_NO_CRC;
	}
	else {
		pDevice->RxMtu = pDevice->TxMtu = pkt_size;
	}

	if (dev->mtu <= 1514)  {
		pDevice->RxJumboDescCnt = 0;
	}
	else if (pDevice->Flags & JUMBO_CAPABLE_FLAG){
		pDevice->RxJumboDescCnt =
			rx_jumbo_desc_cnt[pUmDevice->index];
	}
	pDevice->RxPacketDescCnt = pDevice->RxJumboDescCnt +
		pDevice->RxStdDescCnt;

	pDevice->RxJumboBufferSize = (pDevice->RxMtu + 8 /* CRC + VLAN */ +
		COMMON_CACHE_LINE_SIZE-1) & ~COMMON_CACHE_LINE_MASK;

#ifdef BCM_TSO
	if (T3_ASIC_5714_FAMILY(pDevice->ChipRevId) &&
	   (dev->mtu > 1514) ) {
		if (dev->features & NETIF_F_TSO) {
			dev->features &= ~NETIF_F_TSO;
			printk(KERN_ALERT "%s: TSO previously enabled. Jumbo Frames and TSO cannot simultaneously be enabled. Jumbo Frames enabled. TSO disabled.\n", dev->name);
		}
	}
#endif

	if (reinit) {
		LM_InitializeAdapter(pDevice);
		bcm5700_do_rx_mode(dev);
		bcm5700_set_vlan_mode(pUmDevice);
		bcm5700_init_counters(pUmDevice);
		if (memcmp(dev->dev_addr, pDevice->NodeAddress, 6)) {
			LM_SetMacAddress(pDevice, dev->dev_addr);
		}
		netif_start_queue(dev);
		bcm5700_intr_on(pUmDevice);
	}
	BCM5700_PHY_UNLOCK(pUmDevice, flags);

	return 0;
}
#endif


#if (LINUX_VERSION_CODE < 0x020300)
int
bcm5700_probe(struct net_device *dev)
{
	int cards_found = 0;
	struct pci_dev *pdev = NULL;
	struct pci_device_id *pci_tbl;
	u16 ssvid, ssid;

	if ( ! pci_present())
		return -ENODEV;

	pci_tbl = bcm5700_pci_tbl;
	while ((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pdev))) {
		int idx;

		pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &ssvid);
		pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &ssid);
		for (idx = 0; pci_tbl[idx].vendor; idx++) {
			if ((pci_tbl[idx].vendor == PCI_ANY_ID ||
				pci_tbl[idx].vendor == pdev->vendor) &&
				(pci_tbl[idx].device == PCI_ANY_ID ||
				pci_tbl[idx].device == pdev->device) &&
				(pci_tbl[idx].subvendor == PCI_ANY_ID ||
				pci_tbl[idx].subvendor == ssvid) &&
				(pci_tbl[idx].subdevice == PCI_ANY_ID ||
				pci_tbl[idx].subdevice == ssid))
			{

				break;
			}
		}
		if (pci_tbl[idx].vendor == 0)
			continue;


		if (bcm5700_init_one(pdev, &pci_tbl[idx]) == 0)
			cards_found++;
	}

	return cards_found ? 0 : -ENODEV;
}

#ifdef MODULE
int init_module(void)
{
	return bcm5700_probe(NULL);
}

void cleanup_module(void)
{
	struct net_device *next_dev;
	PUM_DEVICE_BLOCK pUmDevice;

	/* No need to check MOD_IN_USE, as sys_delete_module() checks. */
	while (root_tigon3_dev) {
		pUmDevice = (PUM_DEVICE_BLOCK)root_tigon3_dev->priv;
		next_dev = pUmDevice->next_module;
		unregister_netdev(root_tigon3_dev);
		if (pUmDevice->lm_dev.pMappedMemBase)
			iounmap(pUmDevice->lm_dev.pMappedMemBase);
#if (LINUX_VERSION_CODE < 0x020600)
		kfree(root_tigon3_dev);
#else
		free_netdev(root_tigon3_dev);
#endif
		root_tigon3_dev = next_dev;
	}
#ifdef BCM_IOCTL32
	unregister_ioctl32_conversion(SIOCNICE);
#endif
}

#endif  /* MODULE */
#else	/* LINUX_VERSION_CODE < 0x020300 */

#if (LINUX_VERSION_CODE >= 0x020406)
static int bcm5700_suspend (struct pci_dev *pdev, u32 state)
#else
static void bcm5700_suspend (struct pci_dev *pdev)
#endif
{
	struct net_device *dev = (struct net_device *) pci_get_drvdata(pdev);
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) dev->priv;
	PLM_DEVICE_BLOCK pDevice = &pUmDevice->lm_dev;

	if (!netif_running(dev))
#if (LINUX_VERSION_CODE >= 0x020406)
		return 0;
#else
		return;
#endif

	netif_device_detach (dev);
	bcm5700_shutdown(pUmDevice);

	LM_SetPowerState(pDevice, LM_POWER_STATE_D3);

/*	pci_power_off(pdev, -1);*/
#if (LINUX_VERSION_CODE >= 0x020406)
	return 0;
#endif
}


#if (LINUX_VERSION_CODE >= 0x020406)
static int bcm5700_resume(struct pci_dev *pdev)
#else
static void bcm5700_resume(struct pci_dev *pdev)
#endif
{
	struct net_device *dev = (struct net_device *) pci_get_drvdata(pdev);
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) dev->priv;
	PLM_DEVICE_BLOCK pDevice = &pUmDevice->lm_dev;

	if (!netif_running(dev))
#if (LINUX_VERSION_CODE >= 0x020406)
		return 0;
#else
		return;
#endif
/*	pci_power_on(pdev);*/
	netif_device_attach(dev);
	LM_SetPowerState(pDevice, LM_POWER_STATE_D0);
	MM_InitializeUmPackets(pDevice);
	bcm5700_reset(dev);
#if (LINUX_VERSION_CODE >= 0x020406)
	return 0;
#endif
}


static struct pci_driver bcm5700_pci_driver = {
	name:		bcm5700_driver,
	id_table:	bcm5700_pci_tbl,
	probe:		bcm5700_init_one,
	remove:		__devexit_p(bcm5700_remove_one),
	suspend:	bcm5700_suspend,
	resume:		bcm5700_resume,
};

static int
bcm5700_notify_reboot(struct notifier_block *this, unsigned long event, void *unused)
{
	switch (event) {
	case SYS_HALT:
	case SYS_POWER_OFF:
	case SYS_RESTART:
		break;
	default:
		return NOTIFY_DONE;
	}

	B57_INFO(("bcm5700 reboot notification\n"));
	pci_unregister_driver(&bcm5700_pci_driver);
	return NOTIFY_DONE;
}

static int __init bcm5700_init_module (void)
{
	int pin = 1 << 2;

	if (nvram_match("disabled_5397", "1") || (activate_gpio != -1)) {
		if ( activate_gpio != -1 ) pin = activate_gpio;
		printk("5397 switch GPIO-Reset (pin %d)\n", pin);
		sb_t *gpio_sbh;
		if (!(gpio_sbh = sb_kattach(SB_OSH))) return -ENODEV;
		sb_gpiosetcore(gpio_sbh);
//		sb_gpioreserve(gpio_sbh, 0x4, GPIO_HI_PRIORITY);
		sb_gpioouten(gpio_sbh, 0x4, 0x4, GPIO_HI_PRIORITY);
		sb_gpioout(gpio_sbh, 0x4, 0x4, GPIO_HI_PRIORITY);
		sb_detach(gpio_sbh);
	}

	if (msglevel != 0xdeadbeef) {
		b57_msg_level = msglevel;
		printf("%s: msglevel set to 0x%x\n", __FUNCTION__, b57_msg_level);
	} else
		b57_msg_level = B57_ERR_VAL;

	return pci_module_init(&bcm5700_pci_driver);
}

static void __exit bcm5700_cleanup_module (void)
{
	unregister_reboot_notifier(&bcm5700_reboot_notifier);
	pci_unregister_driver(&bcm5700_pci_driver);
}

module_init(bcm5700_init_module);
module_exit(bcm5700_cleanup_module);
#endif

/*
 * Middle Module
 *
 */


#ifdef BCM_NAPI_RXPOLL
LM_STATUS
MM_ScheduleRxPoll(LM_DEVICE_BLOCK *pDevice)
{
	struct net_device *dev = ((UM_DEVICE_BLOCK *) pDevice)->dev;

	if (netif_rx_schedule_prep(dev)) {
		__netif_rx_schedule(dev);
		return LM_STATUS_SUCCESS;
	}
	return LM_STATUS_FAILURE;
}
#endif

LM_STATUS
MM_ReadConfig16(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset,
	LM_UINT16 *pValue16)
{
	UM_DEVICE_BLOCK *pUmDevice;

	pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
	pci_read_config_word(pUmDevice->pdev, Offset, (u16 *) pValue16);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_ReadConfig32(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset,
	LM_UINT32 *pValue32)
{
	UM_DEVICE_BLOCK *pUmDevice;

	pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
	pci_read_config_dword(pUmDevice->pdev, Offset, (u32 *) pValue32);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_WriteConfig16(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset,
	LM_UINT16 Value16)
{
	UM_DEVICE_BLOCK *pUmDevice;

	pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
	pci_write_config_word(pUmDevice->pdev, Offset, Value16);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_WriteConfig32(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset,
	LM_UINT32 Value32)
{
	UM_DEVICE_BLOCK *pUmDevice;

	pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
	pci_write_config_dword(pUmDevice->pdev, Offset, Value32);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_AllocateSharedMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
	PLM_VOID *pMemoryBlockVirt, PLM_PHYSICAL_ADDRESS pMemoryBlockPhy,
	LM_BOOL Cached)
{
	PLM_VOID pvirt;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	dma_addr_t mapping;

	pvirt = pci_alloc_consistent(pUmDevice->pdev, BlockSize,
					       &mapping);
	if (!pvirt) {
		return LM_STATUS_FAILURE;
	}
	pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
	pUmDevice->dma_list[pUmDevice->mem_list_num] = mapping;
	pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = BlockSize;
	memset(pvirt, 0, BlockSize);
	*pMemoryBlockVirt = (PLM_VOID) pvirt;
	MM_SetAddr(pMemoryBlockPhy, mapping);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_AllocateMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
	PLM_VOID *pMemoryBlockVirt)
{
	PLM_VOID pvirt;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;


	/* Maximum in slab.c */
	if (BlockSize > 131072) {
		goto MM_Alloc_error;
	}

	pvirt = kmalloc(BlockSize, GFP_ATOMIC);
	if (!pvirt) {
		goto MM_Alloc_error;
	}
	pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
	pUmDevice->dma_list[pUmDevice->mem_list_num] = 0;
	pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = 0;
	/* mem_size_list[i] == 0 indicates that the memory should be freed */
	/* using kfree */
	memset(pvirt, 0, BlockSize);
	*pMemoryBlockVirt = pvirt;
	return LM_STATUS_SUCCESS;

MM_Alloc_error:
	printk(KERN_WARNING "%s: Memory allocation failed - buffer parameters may be set too high\n", pUmDevice->dev->name);
	return LM_STATUS_FAILURE;
}

LM_STATUS
MM_MapMemBase(PLM_DEVICE_BLOCK pDevice)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;

	pDevice->pMappedMemBase = ioremap_nocache(
		pci_resource_start(pUmDevice->pdev, 0), sizeof(T3_STD_MEM_MAP));
	if (pDevice->pMappedMemBase == 0)
		return LM_STATUS_FAILURE;

	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_InitializeUmPackets(PLM_DEVICE_BLOCK pDevice)
{
	unsigned int i;
	struct sk_buff *skb;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	PUM_PACKET pUmPacket;
	PLM_PACKET pPacket;

	for (i = 0; i < pDevice->RxPacketDescCnt; i++) {
		pPacket = QQ_PopHead(&pDevice->RxPacketFreeQ.Container);
		pUmPacket = (PUM_PACKET) pPacket;
		if (pPacket == 0) {
			printk(KERN_DEBUG "Bad RxPacketFreeQ\n");
		}
		if (pUmPacket->skbuff == 0) {
#ifdef BCM_WL_EMULATOR
			skb = (struct sk_buff *)wlcemu_pktget(pDevice->wlc,pPacket->u.Rx.RxBufferSize + 2);
#else
			skb = dev_alloc_skb(pPacket->u.Rx.RxBufferSize + 2 + EXTRA_HDR);
#endif
			if (skb == 0) {
				pUmPacket->skbuff = 0;
				QQ_PushTail(
					&pUmDevice->rx_out_of_buf_q.Container,
					pPacket);
				continue;
			}
			pUmPacket->skbuff = skb;
			skb->dev = pUmDevice->dev;
#ifndef BCM_WL_EMULATOR
			skb_reserve(skb, EXTRA_HDR - pUmDevice->rx_buf_align);
#endif
		}
		QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
	}
	if (T3_ASIC_REV(pUmDevice->lm_dev.ChipRevId) == T3_ASIC_REV_5700) {
		/* reallocate buffers in the ISR */
		pUmDevice->rx_buf_repl_thresh = 0;
		pUmDevice->rx_buf_repl_panic_thresh = 0;
		pUmDevice->rx_buf_repl_isr_limit = 0;
	}
	else {
		pUmDevice->rx_buf_repl_thresh = pDevice->RxPacketDescCnt / 8;
		pUmDevice->rx_buf_repl_panic_thresh =
			pDevice->RxPacketDescCnt  * 7 / 8;

		/* This limits the time spent in the ISR when the receiver */
		/* is in a steady state of being overrun. */
		pUmDevice->rx_buf_repl_isr_limit = pDevice->RxPacketDescCnt / 8;

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
		if (pDevice->RxJumboDescCnt != 0) {
			if (pUmDevice->rx_buf_repl_thresh >=
				pDevice->RxJumboDescCnt) {

				pUmDevice->rx_buf_repl_thresh =
				pUmDevice->rx_buf_repl_panic_thresh =
					pDevice->RxJumboDescCnt - 1;
			}
			if (pUmDevice->rx_buf_repl_thresh >=
				pDevice->RxStdDescCnt) {

				pUmDevice->rx_buf_repl_thresh =
				pUmDevice->rx_buf_repl_panic_thresh =
					pDevice->RxStdDescCnt - 1;
			}
		}
#endif
	}
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_GetConfig(PLM_DEVICE_BLOCK pDevice)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	int index = pUmDevice->index;
	struct net_device *dev = pUmDevice->dev;

	if (index >= MAX_UNITS)
		return LM_STATUS_SUCCESS;

#if LINUX_KERNEL_VERSION < 0x0020609

	bcm5700_validate_param_range(pUmDevice, &auto_speed[index], "auto_speed",
		0, 1, 1);
	if (auto_speed[index] == 0)
		pDevice->DisableAutoNeg = TRUE;
	else
		pDevice->DisableAutoNeg = FALSE;

	if (line_speed[index] == 0) {
		pDevice->RequestedLineSpeed = LM_LINE_SPEED_AUTO;
		pDevice->DisableAutoNeg = FALSE;
	}
	else {
		bcm5700_validate_param_range(pUmDevice, &full_duplex[index],
			"full_duplex", 0, 1, 1);
		if (full_duplex[index]) {
			pDevice->RequestedDuplexMode = LM_DUPLEX_MODE_FULL;
		}
		else {
			pDevice->RequestedDuplexMode = LM_DUPLEX_MODE_HALF;
		}

		if (line_speed[index] == 1000) {
			pDevice->RequestedLineSpeed = LM_LINE_SPEED_1000MBPS;
			if (pDevice->PhyFlags & PHY_NO_GIGABIT) {
				pDevice->RequestedLineSpeed =
					LM_LINE_SPEED_100MBPS;
				printk(KERN_WARNING "%s-%d: Invalid line_speed parameter (1000), using 100\n", bcm5700_driver, index);
			}
			else {
				if ((pDevice->TbiFlags & ENABLE_TBI_FLAG) &&
					!full_duplex[index]) {
					printk(KERN_WARNING "%s-%d: Invalid full_duplex parameter (0) for fiber, using 1\n", bcm5700_driver, index);
					pDevice->RequestedDuplexMode =
						LM_DUPLEX_MODE_FULL;
				}

				if (!(pDevice->TbiFlags & ENABLE_TBI_FLAG) &&
					!auto_speed[index] && !(pDevice->PhyFlags & PHY_IS_FIBER) ) {
					printk(KERN_WARNING "%s-%d: Invalid auto_speed parameter (0) for copper, using 1\n", bcm5700_driver, index);
					pDevice->DisableAutoNeg = FALSE;
				}
			}
		}
		else if ((pDevice->TbiFlags & ENABLE_TBI_FLAG) ||
                         (pDevice->PhyFlags & PHY_IS_FIBER)){
			 pDevice->RequestedLineSpeed = LM_LINE_SPEED_AUTO;
			 pDevice->RequestedDuplexMode = LM_DUPLEX_MODE_FULL;
			 pDevice->DisableAutoNeg = FALSE;
			 printk(KERN_WARNING "%s-%d: Invalid line_speed parameter (%d), using auto\n", bcm5700_driver, index, line_speed[index]);
		}
		else if (line_speed[index] == 100) {

                        pDevice->RequestedLineSpeed = LM_LINE_SPEED_100MBPS;
		}
		else if (line_speed[index] == 10) {

			pDevice->RequestedLineSpeed = LM_LINE_SPEED_10MBPS;
		}
		else {
			pDevice->RequestedLineSpeed = LM_LINE_SPEED_AUTO;
			pDevice->DisableAutoNeg = FALSE;
			printk(KERN_WARNING "%s-%d: Invalid line_speed parameter (%d), using 0\n", bcm5700_driver, index, line_speed[index]);
		}

	}

#endif /* LINUX_KERNEL_VERSION */

	/* This is an unmanageable switch nic and will have link problems if
	   not set to auto
	*/
	if(pDevice->SubsystemVendorId==0x103c && pDevice->SubsystemId==0x3226)
	{
	    if(pDevice->RequestedLineSpeed != LM_LINE_SPEED_AUTO)
	    {
		printk(KERN_WARNING "%s-%d: Invalid line_speed parameter (%d), using 0\n",
			bcm5700_driver, index, line_speed[index]);
	    }
	    pDevice->RequestedLineSpeed = LM_LINE_SPEED_AUTO;
	    pDevice->DisableAutoNeg = FALSE;
	}

#if LINUX_KERNEL_VERSION < 0x0020609

	pDevice->FlowControlCap = 0;
	bcm5700_validate_param_range(pUmDevice, &rx_flow_control[index],
		"rx_flow_control", 0, 1, 0);
	if (rx_flow_control[index] != 0) {
		pDevice->FlowControlCap |= LM_FLOW_CONTROL_RECEIVE_PAUSE;
	}
	bcm5700_validate_param_range(pUmDevice, &tx_flow_control[index],
		"tx_flow_control", 0, 1, 0);
	if (tx_flow_control[index] != 0) {
		pDevice->FlowControlCap |= LM_FLOW_CONTROL_TRANSMIT_PAUSE;
	}
	bcm5700_validate_param_range(pUmDevice, &auto_flow_control[index],
		"auto_flow_control", 0, 1, 0);
	if (auto_flow_control[index] != 0) {
		if (pDevice->DisableAutoNeg == FALSE) {

			pDevice->FlowControlCap |= LM_FLOW_CONTROL_AUTO_PAUSE;
			if ((tx_flow_control[index] == 0) &&
				(rx_flow_control[index] == 0)) {

				pDevice->FlowControlCap |=
					LM_FLOW_CONTROL_TRANSMIT_PAUSE |
					LM_FLOW_CONTROL_RECEIVE_PAUSE;
			}
		}
	}

	if (dev->mtu > 1500) {
#ifdef BCM_TSO
		if (T3_ASIC_5714_FAMILY(pDevice->ChipRevId) &&
		   (dev->features & NETIF_F_TSO)) {
				dev->features &= ~NETIF_F_TSO;
				printk(KERN_ALERT "%s: TSO previously enabled. Jumbo Frames and TSO cannot simultaneously be enabled. Jumbo Frames enabled. TSO disabled.\n", dev->name);
		}
#endif
		pDevice->RxMtu = dev->mtu + 14;
	}

	if ((T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5700) &&
		!(pDevice->Flags & BCM5788_FLAG)) {
		pDevice->Flags |= USE_TAGGED_STATUS_FLAG;
		pUmDevice->timer_interval = HZ;
		if ((T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5703) &&
			(pDevice->TbiFlags & ENABLE_TBI_FLAG)) {
			pUmDevice->timer_interval = HZ/4;
		}
	}
	else {
		pUmDevice->timer_interval = HZ/10;
	}

	bcm5700_validate_param_range(pUmDevice, &tx_pkt_desc_cnt[index],
		"tx_pkt_desc_cnt", 1, MAX_TX_PACKET_DESC_COUNT-1, TX_DESC_CNT);
	pDevice->TxPacketDescCnt = tx_pkt_desc_cnt[index];
	bcm5700_validate_param_range(pUmDevice, &rx_std_desc_cnt[index],
		"rx_std_desc_cnt", 1, T3_STD_RCV_RCB_ENTRY_COUNT-1,
		RX_DESC_CNT);
	pDevice->RxStdDescCnt = rx_std_desc_cnt[index];

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
	bcm5700_validate_param_range(pUmDevice, &rx_jumbo_desc_cnt[index],
		"rx_jumbo_desc_cnt", 1, T3_JUMBO_RCV_RCB_ENTRY_COUNT-1,
		JBO_DESC_CNT);

	if (mtu[index] <= 1514)
		pDevice->RxJumboDescCnt = 0;
	else if(!T3_ASIC_IS_5705_BEYOND(pDevice->ChipRevId)){
		pDevice->RxJumboDescCnt = rx_jumbo_desc_cnt[index];
        }
#endif

#ifdef BCM_INT_COAL
	bcm5700_validate_param_range(pUmDevice, &adaptive_coalesce[index],
		"adaptive_coalesce", 0, 1, 1);
#ifdef BCM_NAPI_RXPOLL
	if (adaptive_coalesce[index]) {
		printk(KERN_WARNING "%s-%d: adaptive_coalesce not used in NAPI mode\n", bcm5700_driver, index);
		adaptive_coalesce[index] = 0;

	}
#endif
	pUmDevice->adaptive_coalesce = adaptive_coalesce[index];
	if (!pUmDevice->adaptive_coalesce) {
		bcm5700_validate_param_range(pUmDevice,
			&rx_coalesce_ticks[index], "rx_coalesce_ticks", 0,
			MAX_RX_COALESCING_TICKS, RX_COAL_TK);
		if ((rx_coalesce_ticks[index] == 0) &&
			(rx_max_coalesce_frames[index] == 0)) {

			printk(KERN_WARNING "%s-%d: Conflicting rx_coalesce_ticks (0) and rx_max_coalesce_frames (0) parameters, using %d and %d respectively\n",
				bcm5700_driver, index, RX_COAL_TK, RX_COAL_FM);

			rx_coalesce_ticks[index] = RX_COAL_TK;
			rx_max_coalesce_frames[index] = RX_COAL_FM;
		}
		pDevice->RxCoalescingTicks = pUmDevice->rx_curr_coalesce_ticks =
			rx_coalesce_ticks[index];
#ifdef BCM_NAPI_RXPOLL
		pDevice->RxCoalescingTicksDuringInt = rx_coalesce_ticks[index];
#endif

		bcm5700_validate_param_range(pUmDevice,
			&rx_max_coalesce_frames[index],
			"rx_max_coalesce_frames", 0,
			MAX_RX_MAX_COALESCED_FRAMES, RX_COAL_FM);

		pDevice->RxMaxCoalescedFrames =
			pUmDevice->rx_curr_coalesce_frames =
			rx_max_coalesce_frames[index];
#ifdef BCM_NAPI_RXPOLL
		pDevice->RxMaxCoalescedFramesDuringInt =
			rx_max_coalesce_frames[index];
#endif

		bcm5700_validate_param_range(pUmDevice,
			&tx_coalesce_ticks[index], "tx_coalesce_ticks", 0,
			MAX_TX_COALESCING_TICKS, TX_COAL_TK);
		if ((tx_coalesce_ticks[index] == 0) &&
			(tx_max_coalesce_frames[index] == 0)) {

			printk(KERN_WARNING "%s-%d: Conflicting tx_coalesce_ticks (0) and tx_max_coalesce_frames (0) parameters, using %d and %d respectively\n",
				bcm5700_driver, index, TX_COAL_TK, TX_COAL_FM);

			tx_coalesce_ticks[index] = TX_COAL_TK;
			tx_max_coalesce_frames[index] = TX_COAL_FM;
		}
		pDevice->TxCoalescingTicks = tx_coalesce_ticks[index];
		bcm5700_validate_param_range(pUmDevice,
			&tx_max_coalesce_frames[index],
			"tx_max_coalesce_frames", 0,
			MAX_TX_MAX_COALESCED_FRAMES, TX_COAL_FM);
		pDevice->TxMaxCoalescedFrames = tx_max_coalesce_frames[index];
		pUmDevice->tx_curr_coalesce_frames =
			pDevice->TxMaxCoalescedFrames;

		bcm5700_validate_param_range(pUmDevice,
			&stats_coalesce_ticks[index], "stats_coalesce_ticks",
			0, MAX_STATS_COALESCING_TICKS, ST_COAL_TK);
		if (adaptive_coalesce[index]) {
			printk(KERN_WARNING "%s-%d: Invalid stats_coalesce_ticks parameter set with with adaptive_coalesce parameter. Using adaptive_coalesce.\n", bcm5700_driver, index);
		}else{
			if ((stats_coalesce_ticks[index] > 0) &&
				(stats_coalesce_ticks[index] < 100)) {
				printk(KERN_WARNING "%s-%d: Invalid stats_coalesce_ticks parameter (%u), using 100\n", bcm5700_driver, index, (unsigned int) stats_coalesce_ticks[index]);
				stats_coalesce_ticks[index] = 100;
				pDevice->StatsCoalescingTicks = stats_coalesce_ticks[index];
				pDevice->StatsCoalescingTicks = stats_coalesce_ticks[index];
			}
		}
	}
	else {
		pUmDevice->rx_curr_coalesce_frames = RX_COAL_FM;
		pUmDevice->rx_curr_coalesce_ticks = RX_COAL_TK;
		pUmDevice->tx_curr_coalesce_frames = TX_COAL_FM;
	}
#endif

	if (T3_ASIC_IS_5705_BEYOND(pDevice->ChipRevId)) {
		unsigned int tmpvar;

		tmpvar = pDevice->StatsCoalescingTicks / BCM_TIMER_GRANULARITY;

		/*
		 * If the result is zero, the request is too demanding.
		 */
		if (tmpvar == 0) {
			tmpvar = 1;
		}

		pDevice->StatsCoalescingTicks = tmpvar * BCM_TIMER_GRANULARITY;

		pUmDevice->statstimer_interval = tmpvar;
	}

#ifdef BCM_WOL
	bcm5700_validate_param_range(pUmDevice, &enable_wol[index],
		"enable_wol", 0, 1, 0);
	if (enable_wol[index]) {
		pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_MAGIC_PACKET;
		pDevice->WakeUpMode = LM_WAKE_UP_MODE_MAGIC_PACKET;
	}
#endif
#ifdef INCLUDE_TBI_SUPPORT
	if (pDevice->TbiFlags & ENABLE_TBI_FLAG) {
		if ((T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5704) ||
			(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5703)) {
			/* just poll since we have hardware autoneg. in 5704 */
			pDevice->TbiFlags |= TBI_PURE_POLLING_FLAG;
		}
		else {
			pDevice->TbiFlags |= TBI_POLLING_INTR_FLAG;
		}
	}
#endif
	bcm5700_validate_param_range(pUmDevice, &scatter_gather[index],
		"scatter_gather", 0, 1, 1);
	bcm5700_validate_param_range(pUmDevice, &tx_checksum[index],
		"tx_checksum", 0, 1, 1);
	bcm5700_validate_param_range(pUmDevice, &rx_checksum[index],
		"rx_checksum", 0, 1, 1);
	if (!(pDevice->TaskOffloadCap & LM_TASK_OFFLOAD_TX_TCP_CHECKSUM)) {
		if (tx_checksum[index] || rx_checksum[index]) {

			pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;
			printk(KERN_WARNING "%s-%d: Checksum offload not available on this NIC\n", bcm5700_driver, index);
		}
	}
	else {
		if (rx_checksum[index]) {
			pDevice->TaskToOffload |=
				LM_TASK_OFFLOAD_RX_TCP_CHECKSUM |
				LM_TASK_OFFLOAD_RX_UDP_CHECKSUM;
		}
		if (tx_checksum[index]) {
			pDevice->TaskToOffload |=
				LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
				LM_TASK_OFFLOAD_TX_UDP_CHECKSUM;
			pDevice->Flags |= NO_TX_PSEUDO_HDR_CSUM_FLAG;
		}
	}
#ifdef BCM_TSO
	bcm5700_validate_param_range(pUmDevice, &enable_tso[index],
		"enable_tso", 0, 1, 1);

	/* Always enable TSO firmware if supported */
	/* This way we can turn it on or off on the fly */
	if (pDevice->TaskOffloadCap & LM_TASK_OFFLOAD_TCP_SEGMENTATION)
	{
		pDevice->TaskToOffload |=
			LM_TASK_OFFLOAD_TCP_SEGMENTATION;
	}
	if (enable_tso[index] &&
		!(pDevice->TaskToOffload & LM_TASK_OFFLOAD_TCP_SEGMENTATION))
	{
		printk(KERN_WARNING "%s-%d: TSO not available on this NIC\n", bcm5700_driver, index);
	}
#endif
#ifdef BCM_ASF
	bcm5700_validate_param_range(pUmDevice, &vlan_tag_mode[index],
		"vlan_strip_mode", 0, 2, 0);
	pUmDevice->vlan_tag_mode = vlan_tag_mode[index];
#else
	pUmDevice->vlan_tag_mode = VLAN_TAG_MODE_NORMAL_STRIP;
#endif

#endif /* LINUX_KERNEL_VERSION */

#ifdef BCM_NIC_SEND_BD
	bcm5700_validate_param_range(pUmDevice, &nic_tx_bd[index], "nic_tx_bd",
		0, 1, 0);
	if (nic_tx_bd[index])
		pDevice->Flags |= NIC_SEND_BD_FLAG;
	if ((pDevice->Flags & ENABLE_PCIX_FIX_FLAG) ||
		(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5705)) {
		if (pDevice->Flags & NIC_SEND_BD_FLAG) {
			pDevice->Flags &= ~NIC_SEND_BD_FLAG;
			printk(KERN_WARNING "%s-%d: Nic Send BDs not available on this NIC or not possible on this system\n", bcm5700_driver, index);
		}
	}
#endif
#if defined(CONFIG_PCI_MSI) || defined(CONFIG_PCI_USE_VECTOR)
	bcm5700_validate_param_range(pUmDevice, &disable_msi[pUmDevice->index],
		"disable_msi", 0, 1, 0);
#endif

	bcm5700_validate_param_range(pUmDevice, &delay_link[index],
		"delay_link", 0, 1, 0);

	bcm5700_validate_param_range(pUmDevice, &disable_d3hot[index],
		"disable_d3hot", 0, 1, 0);
	if (disable_d3hot[index]) {

#ifdef BCM_WOL
		if (enable_wol[index]) {
			pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_NONE;
			pDevice->WakeUpMode = LM_WAKE_UP_MODE_NONE;
			printk(KERN_WARNING "%s-%d: Wake-On-Lan disabled because D3Hot is disabled\n", bcm5700_driver, index);
		}
#endif
		pDevice->Flags |= DISABLE_D3HOT_FLAG;
	}

    return LM_STATUS_SUCCESS;
}

/* From include/proto/ethernet.h */
#define ETHER_TYPE_8021Q	0x8100		/* 802.1Q */

/* From include/proto/vlan.h */
#define VLAN_PRI_MASK		7	/* 3 bits of priority */
#define VLAN_PRI_SHIFT		13

/* Replace the priority in a vlan tag */
#define	UPD_VLANTAG_PRIO(tag, prio) do { \
	tag &= ~(VLAN_PRI_MASK << VLAN_PRI_SHIFT); \
	tag |= prio << VLAN_PRI_SHIFT; \
} while (0)

/* Takes an Ethernet frame and sets out-of-bound PKTPRIO.
 * Also updates the inplace vlan tag if requested.
 * For debugging, it returns an indication of what it did.
 */
#define	PKTPRIO_VDSCP	0x100		/* DSCP prio found after VLAN tag */
#define	PKTPRIO_VLAN	0x200		/* VLAN prio found */
#define	PKTPRIO_UPD	0x400		/* DSCP used to update VLAN prio */
#define	PKTPRIO_DSCP	0x800		/* DSCP prio found */
#define	PKTSETPRIO(skb, x)		(((struct sk_buff*)(skb))->priority = (x))
static uint
pktsetprio(void *pkt, bool update_vtag)
{
	struct ether_header *eh;
	struct ethervlan_header *evh;
	uint8 *pktdata;
	int priority = 0;
	int rc = 0;

	pktdata = (uint8 *) PKTDATA(NULL, pkt);
	ASSERT(ISALIGNED((uintptr)pktdata, sizeof(uint16)));

	eh = (struct ether_header *) pktdata;

	if (ntoh16(eh->ether_type) == ETHER_TYPE_8021Q) {
		uint16 vlan_tag;
		int vlan_prio, dscp_prio = 0;

		evh = (struct ethervlan_header *)eh;

		vlan_tag = ntoh16(evh->vlan_tag);
		vlan_prio = (int) (vlan_tag >> VLAN_PRI_SHIFT) & VLAN_PRI_MASK;

		if (ntoh16(evh->ether_type) == ETHER_TYPE_IP) {
			uint8 *ip_body = pktdata + sizeof(struct ethervlan_header);
			uint8 tos_tc = IP_TOS(ip_body);
			dscp_prio = (int)(tos_tc >> IPV4_TOS_PREC_SHIFT);
			if ((IP_VER(ip_body) == IP_VER_4) && (IPV4_PROT(ip_body) == IP_PROT_TCP)) {
				int ip_len;
				int src_port;
				bool src_port_exc;
				uint8 *tcp_hdr;

				ip_len = IPV4_PAYLOAD_LEN(ip_body);
				tcp_hdr = IPV4_NO_OPTIONS_PAYLOAD(ip_body);
				src_port = TCP_SRC_PORT(tcp_hdr);
				src_port_exc = (src_port == 10110) || (src_port == 10120) ||
					(src_port == 10130) || (src_port == 10140);

				if ((ip_len == 40) && src_port_exc && TCP_IS_ACK(tcp_hdr)) {
					dscp_prio = 7;
				}
			}
		}

		/* DSCP priority gets precedence over 802.1P (vlan tag) */
		if (dscp_prio != 0) {
			priority = dscp_prio;
			rc |= PKTPRIO_VDSCP;
		} else {
			priority = vlan_prio;
			rc |= PKTPRIO_VLAN;
		}
		/* 
		 * If the DSCP priority is not the same as the VLAN priority,
		 * then overwrite the priority field in the vlan tag, with the
		 * DSCP priority value. This is required for Linux APs because
		 * the VLAN driver on Linux, overwrites the skb->priority field
		 * with the priority value in the vlan tag
		 */
		if (update_vtag && (priority != vlan_prio)) {
			vlan_tag &= ~(VLAN_PRI_MASK << VLAN_PRI_SHIFT);
			vlan_tag |= (uint16)priority << VLAN_PRI_SHIFT;
			evh->vlan_tag = hton16(vlan_tag);
			rc |= PKTPRIO_UPD;
		}
	} else if (ntoh16(eh->ether_type) == ETHER_TYPE_IP) {
		uint8 *ip_body = pktdata + sizeof(struct ether_header);
		uint8 tos_tc = IP_TOS(ip_body);
		priority = (int)(tos_tc >> IPV4_TOS_PREC_SHIFT);
		rc |= PKTPRIO_DSCP;
		if ((IP_VER(ip_body) == IP_VER_4) && (IPV4_PROT(ip_body) == IP_PROT_TCP)) {
			int ip_len;
			int src_port;
			bool src_port_exc;
			uint8 *tcp_hdr;

			ip_len = IPV4_PAYLOAD_LEN(ip_body);
			tcp_hdr = IPV4_NO_OPTIONS_PAYLOAD(ip_body);
			src_port = TCP_SRC_PORT(tcp_hdr);
			src_port_exc = (src_port == 10110) || (src_port == 10120) ||
				(src_port == 10130) || (src_port == 10140);

			if ((ip_len == 40) && src_port_exc && TCP_IS_ACK(tcp_hdr)) {
				priority = 7;
			}
		}
	}

	ASSERT(priority >= 0 && priority <= MAXPRIO);
	PKTSETPRIO(pkt, priority);
	return (rc | priority);
}

LM_STATUS
MM_IndicateRxPackets(PLM_DEVICE_BLOCK pDevice)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	PLM_PACKET pPacket;
	PUM_PACKET pUmPacket;
	struct sk_buff *skb;
	int size;
	int vlan_tag_size = 0;
	uint16 dscp_prio;

	if (pDevice->ReceiveMask & LM_KEEP_VLAN_TAG)
		vlan_tag_size = 4;

	while (1) {
		pPacket = (PLM_PACKET)
			QQ_PopHead(&pDevice->RxPacketReceivedQ.Container);
		if (pPacket == 0)
			break;
		pUmPacket = (PUM_PACKET) pPacket;
#if !defined(NO_PCI_UNMAP)
		pci_unmap_single(pUmDevice->pdev,
				pci_unmap_addr(pUmPacket, map[0]),
				pPacket->u.Rx.RxBufferSize,
				PCI_DMA_FROMDEVICE);
#endif
		if ((pPacket->PacketStatus != LM_STATUS_SUCCESS) ||
			((size = pPacket->PacketSize) >
			(pDevice->RxMtu + vlan_tag_size))) {

			/* reuse skb */
#ifdef BCM_TASKLET
			QQ_PushTail(&pUmDevice->rx_out_of_buf_q.Container, pPacket);
#else
			QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
#endif
			pUmDevice->rx_misc_errors++;
			continue;
		}
		skb = pUmPacket->skbuff;
		skb_put(skb, size);
		skb->pkt_type = 0;
		/* Extract priority from payload and put it in skb->priority */
		dscp_prio = 0;
		if (pUmDevice->qos) {
			uint rc;

			rc = pktsetprio(skb, TRUE);
			if (rc & (PKTPRIO_VDSCP | PKTPRIO_DSCP))
				dscp_prio = rc & VLAN_PRI_MASK;
			if (rc != 0)
				B57_INFO(("pktsetprio returned 0x%x, skb->priority: %d\n",
				          rc, skb->priority));
		}
		skb->protocol = eth_type_trans(skb, skb->dev);
		if (size > pDevice->RxMtu) {
			/* Make sure we have a valid VLAN tag */
			if (htons(skb->protocol) != ETHER_TYPE_8021Q) {
				dev_kfree_skb_irq(skb);
				pUmDevice->rx_misc_errors++;
				goto drop_rx;
			}
		}

		pUmDevice->stats.rx_bytes += skb->len;

		if ((pPacket->Flags & RCV_BD_FLAG_TCP_UDP_CHKSUM_FIELD) &&
			(pDevice->TaskToOffload &
				LM_TASK_OFFLOAD_RX_TCP_CHECKSUM)) {
			if (pPacket->u.Rx.TcpUdpChecksum == 0xffff) {

				skb->ip_summed = CHECKSUM_UNNECESSARY;
#if TIGON3_DEBUG
				pUmDevice->rx_good_chksum_count++;
#endif
			}
			else {
				skb->ip_summed = CHECKSUM_NONE;
				pUmDevice->rx_bad_chksum_count++;
			}
		}
		else {
			skb->ip_summed = CHECKSUM_NONE;
		}
		{
#ifdef BCM_VLAN
			if (pUmDevice->vlgrp &&
				(pPacket->Flags & RCV_BD_FLAG_VLAN_TAG)) {
				/* Override vlan priority with dscp priority */
				if (dscp_prio)
					UPD_VLANTAG_PRIO(pPacket->VlanTag, dscp_prio);
#ifdef BCM_NAPI_RXPOLL
				vlan_hwaccel_receive_skb(skb, pUmDevice->vlgrp,
					pPacket->VlanTag);
#else
				vlan_hwaccel_rx(skb, pUmDevice->vlgrp,
					pPacket->VlanTag);
#endif
			} else
#endif
			{
#ifdef BCM_WL_EMULATOR
				if(pDevice->wl_emulate_rx) {
					/* bcmstats("emu recv %d %d"); */
					wlcemu_receive_skb(pDevice->wlc, skb);
					/* bcmstats("emu recv end %d %d"); */
				}
				else 
#endif /* BCM_WL_EMULATOR  */
				{
#ifdef BCM_NAPI_RXPOLL
				netif_receive_skb(skb);
#else
				netif_rx(skb);
#endif
				}
			}
		}
		pUmDevice->dev->last_rx = jiffies;

drop_rx:
#ifdef BCM_TASKLET
		pUmPacket->skbuff = 0;
		QQ_PushTail(&pUmDevice->rx_out_of_buf_q.Container, pPacket);
#else
#ifdef BCM_WL_EMULATOR
		skb = (struct sk_buff *)wlcemu_pktget(pDevice->wlc,pPacket->u.Rx.RxBufferSize + 2);
#else
		skb = dev_alloc_skb(pPacket->u.Rx.RxBufferSize + 2 + EXTRA_HDR);
#endif /* BCM_WL_EMULATOR  */
		if (skb == 0) {
			pUmPacket->skbuff = 0;
			QQ_PushTail(&pUmDevice->rx_out_of_buf_q.Container, pPacket);
		}
		else {
			pUmPacket->skbuff = skb;
			skb->dev = pUmDevice->dev;
#ifndef BCM_WL_EMULATOR
			skb_reserve(skb, EXTRA_HDR - pUmDevice->rx_buf_align);
#endif
			QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
		}
#endif
	}
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_CoalesceTxBuffer(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
	PUM_PACKET pUmPacket = (PUM_PACKET) pPacket;
	struct sk_buff *skb = pUmPacket->skbuff;
	struct sk_buff *nskb;
#if !defined(NO_PCI_UNMAP)
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;

	pci_unmap_single(pUmDevice->pdev,
			pci_unmap_addr(pUmPacket, map[0]),