summaryrefslogtreecommitdiff
path: root/target/linux/storm/patches/1002-gmac.patch
blob: 99e710bb748ecc3c51304804644b25d6e0c8945a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
--- /dev/null
+++ b/drivers/net/sl2312_emac.c
@@ -0,0 +1,4604 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/compiler.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
+#include <linux/delay.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/completion.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/semaphore.h>
+#include <asm/arch-sl2312/irqs.h>
+#include <asm/arch/it8712.h>
+#include <asm/arch/sl2312.h>
+#include <linux/mtd/kvctl.h>
+#include <linux/sysctl_storlink.h>
+
+#define BIG_ENDIAN  	0
+
+#define GMAC_DEBUG      0
+
+#define GMAC_PHY_IF     2
+
+/* define PHY address */
+#define HPHY_ADDR   0x01
+#define GPHY_ADDR   0x02
+
+#define CONFIG_ADM_6999 1
+/* define chip information */
+#define DRV_NAME			"SL2312"
+#define DRV_VERSION			"0.1.1"
+#define SL2312_DRIVER_NAME  DRV_NAME " Fast Ethernet driver " DRV_VERSION
+
+/* define TX/RX descriptor parameter */
+#define MAX_ETH_FRAME_SIZE	1920
+#define TX_BUF_SIZE			MAX_ETH_FRAME_SIZE
+#define TX_DESC_NUM			128
+#define TX_BUF_TOT_LEN		(TX_BUF_SIZE * TX_DESC_NUM)
+#define RX_BUF_SIZE			MAX_ETH_FRAME_SIZE
+#define RX_DESC_NUM			256
+#define RX_BUF_TOT_LEN		(RX_BUF_SIZE * RX_DESC_NUM)
+#define MAX_ISR_WORK        20
+
+unsigned int int_status = 0;
+
+/* define GMAC base address */
+#define GMAC_PHYSICAL_BASE_ADDR	    (SL2312_GMAC_BASE)
+#define GMAC_BASE_ADDR			    (IO_ADDRESS(GMAC_PHYSICAL_BASE_ADDR))
+#define GMAC_GLOBAL_BASE_ADDR       (IO_ADDRESS(SL2312_GLOBAL_BASE))
+
+#define GMAC0_BASE                  (IO_ADDRESS(SL2312_GMAC0_BASE))
+#define GMAC1_BASE                  (IO_ADDRESS(SL2312_GMAC1_BASE))
+
+/* memory management utility */
+#define DMA_MALLOC(size,handle)		pci_alloc_consistent(NULL,size,handle)
+#define DMA_MFREE(mem,size,handle)	pci_free_consistent(NULL,size,mem,handle)
+
+//#define gmac_read_reg(offset)       (readl(GMAC_BASE_ADDR + offset))
+//#define gmac_write_reg(offset,data,mask)  writel( (gmac_read_reg(offset)&~mask) |(data&mask),(GMAC_BASE_ADDR+offset))
+
+/* define owner bit */
+#define CPU		0
+#define DMA		1
+
+#define ACTIVE      1
+#define NONACTIVE   0
+
+#define CONFIG_SL_NAPI
+
+#ifndef CONFIG_SL2312_MPAGE
+#define CONFIG_SL2312_MPAGE
+#endif
+
+#ifdef CONFIG_SL2312_MPAGE
+#include <linux/skbuff.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#endif
+
+#ifndef CONFIG_TXINT_DISABLE
+//#define CONFIG_TXINT_DISABLE
+#endif
+
+enum phy_state
+{
+    LINK_DOWN   = 0,
+    LINK_UP     = 1
+};
+
+
+/* transmit timeout value */
+#define TX_TIMEOUT  (6*HZ)
+
+/***************************************/
+/* the offset address of GMAC register */
+/***************************************/
+enum GMAC_REGISTER {
+	GMAC_STA_ADD0 	= 0x0000,
+	GMAC_STA_ADD1	= 0x0004,
+	GMAC_STA_ADD2	= 0x0008,
+	GMAC_RX_FLTR	= 0x000c,
+	GMAC_MCAST_FIL0 = 0x0010,
+	GMAC_MCAST_FIL1 = 0x0014,
+	GMAC_CONFIG0	= 0x0018,
+	GMAC_CONFIG1	= 0x001c,
+	GMAC_CONFIG2	= 0x0020,
+	GMAC_BNCR		= 0x0024,
+	GMAC_RBNR		= 0x0028,
+	GMAC_STATUS		= 0x002c,
+	GMAC_IN_DISCARDS= 0x0030,
+	GMAC_IN_ERRORS  = 0x0034,
+	GMAC_IN_MCAST   = 0x0038,
+	GMAC_IN_BCAST   = 0x003c,
+	GMAC_IN_MAC1    = 0x0040,
+	GMAC_IN_MAC2    = 0x0044
+};
+
+/*******************************************/
+/* the offset address of GMAC DMA register */
+/*******************************************/
+enum GMAC_DMA_REGISTER {
+	GMAC_DMA_DEVICE_ID		= 0xff00,
+	GMAC_DMA_STATUS			= 0xff04,
+	GMAC_TXDMA_CTRL 	 	= 0xff08,
+	GMAC_TXDMA_FIRST_DESC 	= 0xff0c,
+	GMAC_TXDMA_CURR_DESC	= 0xff10,
+	GMAC_RXDMA_CTRL			= 0xff14,
+	GMAC_RXDMA_FIRST_DESC	= 0xff18,
+	GMAC_RXDMA_CURR_DESC	= 0xff1c,
+};
+
+/*******************************************/
+/* the register structure of GMAC          */
+/*******************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_0004
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int sta_add2_l16	: 16;	/* station MAC address2 bits 15 to 0 */
+		unsigned int sta_add1_h16	: 16;	/* station MAC address1 bits 47 to 32 */
+#else
+		unsigned int sta_add1_h16	: 16;	/* station MAC address1 bits 47 to 32 */
+		unsigned int sta_add2_l16	: 16;	/* station MAC address2 bits 15 to 0 */
+#endif
+	} bits;
+} GMAC_STA_ADD1_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_000c
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int 				: 27;
+		unsigned int error			:  1;	/* enable receive of all error frames */
+		unsigned int promiscuous	:  1;   /* enable receive of all frames */
+		unsigned int broadcast		:  1;	/* enable receive of broadcast frames */
+		unsigned int multicast		:  1;	/* enable receive of multicast frames that pass multicast filter */
+		unsigned int unicast		:  1;	/* enable receive of unicast frames that are sent to STA address */
+#else
+		unsigned int unicast		:  1;	/* enable receive of unicast frames that are sent to STA address */
+		unsigned int multicast		:  1;	/* enable receive of multicast frames that pass multicast filter */
+		unsigned int broadcast		:  1;	/* enable receive of broadcast frames */
+		unsigned int promiscuous	:  1;   /* enable receive of all frames */
+		unsigned int error			:  1;	/* enable receive of all error frames */
+		unsigned int 				: 27;
+#endif
+	} bits;
+} GMAC_RX_FLTR_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_0018
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int : 10;
+		unsigned int inv_rx_clk     : 1;	/* Inverse RX Clock */
+		unsigned int rising_latch   : 1;
+        unsigned int rx_tag_remove  :  1;   /* Remove Rx VLAN tag */
+        unsigned int ipv6_tss_rx_en :  1;   /* IPv6 TSS RX enable */
+        unsigned int ipv4_tss_rx_en :  1;   /* IPv4 TSS RX enable */
+        unsigned int rgmii_en       :  1;   /* RGMII in-band status enable */
+		unsigned int tx_fc_en		:  1;	/* TX flow control enable */
+		unsigned int rx_fc_en		:  1;	/* RX flow control enable */
+		unsigned int sim_test		:  1;	/* speed up timers in simulation */
+		unsigned int dis_col		:  1;	/* disable 16 collisions abort function */
+		unsigned int dis_bkoff		:  1;	/* disable back-off function */
+		unsigned int max_len		:  3;	/* maximum receive frame length allowed */
+		unsigned int adj_ifg		:  4;	/* adjust IFG from 96+/-56 */
+        unsigned int                :  1;   /* reserved */
+		unsigned int loop_back		:  1;	/* transmit data loopback enable */
+		unsigned int dis_rx			:  1;	/* disable receive */
+		unsigned int dis_tx			:  1;	/* disable transmit */
+#else
+		unsigned int dis_tx			:  1;	/* disable transmit */
+		unsigned int dis_rx			:  1;	/* disable receive */
+		unsigned int loop_back		:  1;	/* transmit data loopback enable */
+        unsigned int                :  1;   /* reserved */
+		unsigned int adj_ifg		:  4;	/* adjust IFG from 96+/-56 */
+		unsigned int max_len		:  3;	/* maximum receive frame length allowed */
+		unsigned int dis_bkoff		:  1;	/* disable back-off function */
+		unsigned int dis_col		:  1;	/* disable 16 collisions abort function */
+		unsigned int sim_test		:  1;	/* speed up timers in simulation */
+		unsigned int rx_fc_en		:  1;	/* RX flow control enable */
+		unsigned int tx_fc_en		:  1;	/* TX flow control enable */
+        unsigned int rgmii_en       :  1;   /* RGMII in-band status enable */
+        unsigned int ipv4_tss_rx_en :  1;   /* IPv4 TSS RX enable */
+        unsigned int ipv6_tss_rx_en :  1;   /* IPv6 TSS RX enable */
+        unsigned int rx_tag_remove  :  1;   /* Remove Rx VLAN tag */
+		unsigned int rising_latch   :  1;
+		unsigned int inv_rx_clk : 1;	/* Inverse RX Clock */
+		unsigned int : 10;
+#endif
+	} bits;
+} GMAC_CONFIG0_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_001c
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int 				: 28;
+		unsigned int buf_size		:  4; 	/* per packet buffer size */
+#else
+		unsigned int buf_size		:  4; 	/* per packet buffer size */
+		unsigned int 				: 28;
+#endif
+	} bits;
+} GMAC_CONFIG1_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_0020
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int rel_threshold	: 16;	/* flow control release threshold */
+		unsigned int set_threshold	: 16; 	/* flow control set threshold */
+#else
+		unsigned int set_threshold	: 16; 	/* flow control set threshold */
+		unsigned int rel_threshold	: 16;	/* flow control release threshold */
+#endif
+	} bits;
+} GMAC_CONFIG2_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_0024
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int 				: 16;
+		unsigned int buf_num		: 16; 	/* return buffer number from software */
+#else
+		unsigned int buf_num		: 16; 	/* return buffer number from software */
+		unsigned int 				: 16;
+#endif
+	} bits;
+} GMAC_BNCR_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_0028
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int				: 16;
+		unsigned int buf_remain		: 16;	/* remaining buffer number */
+#else
+		unsigned int buf_remain		: 16;	/* remaining buffer number */
+		unsigned int				: 16;
+#endif
+	} bits;
+} GMAC_RBNR_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_002c
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int 				: 25;
+		unsigned int mii_rmii		:  2;   /* PHY interface type */
+		unsigned int phy_mode		:  1;	/* PHY interface mode in 10M-bps */
+		unsigned int duplex			:  1;	/* duplex mode */
+		unsigned int speed			:  2;	/* link speed(00->2.5M 01->25M 10->125M) */
+		unsigned int link			:  1;	/* link status */
+#else
+		unsigned int link			:  1;	/* link status */
+		unsigned int speed			:  2;	/* link speed(00->2.5M 01->25M 10->125M) */
+		unsigned int duplex			:  1;	/* duplex mode */
+		unsigned int phy_mode		:  1;	/* PHY interface mode in 10M-bps */
+		unsigned int mii_rmii		:  2;   /* PHY interface type */
+		unsigned int 				: 25;
+#endif
+	} bits;
+} GMAC_STATUS_T;
+
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_009
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int 				: 10;
+		unsigned int tx_fail		:  1; 	/* Tx fail interrupt */
+		unsigned int cnt_full		:  1;	/* MIB counters half full interrupt */
+		unsigned int rx_pause_on	:  1;	/* received pause on frame interrupt */
+		unsigned int tx_pause_on	:  1;	/* transmit pause on frame interrupt */
+		unsigned int rx_pause_off   :  1;	/* received pause off frame interrupt */
+		unsigned int tx_pause_off	:  1;	/* received pause off frame interrupt */
+		unsigned int rx_overrun		:  1;   /* GMAC Rx FIFO overrun interrupt */
+		unsigned int tx_underrun	:  1;	/* GMAC Tx FIFO underrun interrupt */
+		unsigned int				:  6;
+		unsigned int m_tx_fail 		:  1;	/* Tx fail interrupt mask */
+		unsigned int m_cnt_full		:  1;	/* MIB counters half full interrupt mask */
+		unsigned int m_rx_pause_on	:  1;	/* received pause on frame interrupt mask */
+		unsigned int m_tx_pause_on  :  1;	/* transmit pause on frame interrupt mask */
+		unsigned int m_rx_pause_off :  1;	/* received pause off frame interrupt mask */
+		unsigned int m_tx_pause_off	:  1;	/* received pause off frame interrupt mask */
+		unsigned int m_rx_overrun	:  1;   /* GMAC Rx FIFO overrun interrupt mask */
+		unsigned int m_tx_underrun	:  1;	/* GMAC Tx FIFO underrun interrupt mask */
+#else
+		unsigned int m_tx_underrun	:  1;	/* GMAC Tx FIFO underrun interrupt mask */
+		unsigned int m_rx_overrun	:  1;   /* GMAC Rx FIFO overrun interrupt mask */
+		unsigned int m_tx_pause_off	:  1;	/* received pause off frame interrupt mask */
+		unsigned int m_rx_pause_off :  1;	/* received pause off frame interrupt mask */
+		unsigned int m_tx_pause_on  :  1;	/* transmit pause on frame interrupt mask */
+		unsigned int m_rx_pause_on	:  1;	/* received pause on frame interrupt mask */
+		unsigned int m_cnt_full		:  1;	/* MIB counters half full interrupt mask */
+		unsigned int m_tx_fail 		:  1;	/* Tx fail interrupt mask */
+		unsigned int				:  6;
+		unsigned int tx_underrun	:  1;	/* GMAC Tx FIFO underrun interrupt */
+		unsigned int rx_overrun		:  1;   /* GMAC Rx FIFO overrun interrupt */
+		unsigned int tx_pause_off	:  1;	/* received pause off frame interrupt */
+		unsigned int rx_pause_off   :  1;	/* received pause off frame interrupt */
+		unsigned int tx_pause_on	:  1;	/* transmit pause on frame interrupt */
+		unsigned int rx_pause_on	:  1;	/* received pause on frame interrupt */
+		unsigned int cnt_full		:  1;	/* MIB counters half full interrupt */
+		unsigned int tx_fail		:  1; 	/* Tx fail interrupt */
+		unsigned int 				: 10;
+#endif
+	} bits;
+} GMAC_INT_MASK_T;
+
+
+/*******************************************/
+/* the register structure of GMAC DMA      */
+/*******************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit2_ff00
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int                :  7;   /* reserved */
+		unsigned int s_ahb_err		:  1;	/* Slave AHB bus error */
+		unsigned int tx_err_code    :  4;   /* TxDMA error code */
+		unsigned int rx_err_code  	:  4;   /* RxDMA error code */
+		unsigned int device_id		: 12;
+		unsigned int revision_id	:  4;
+#else
+		unsigned int revision_id	:  4;
+		unsigned int device_id		: 12;
+		unsigned int rx_err_code  	:  4;   /* RxDMA error code */
+		unsigned int tx_err_code    :  4;   /* TxDMA error code */
+		unsigned int s_ahb_err		:  1;	/* Slave AHB bus error */
+		unsigned int                :  7;   /* reserved */
+#endif
+	} bits;
+} GMAC_DMA_DEVICE_ID_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit2_ff04
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int ts_finish		:  1;	/* finished tx interrupt */
+		unsigned int ts_derr		:  1;   /* AHB Bus Error while tx */
+		unsigned int ts_perr		:  1;   /* Tx Descriptor protocol error */
+		unsigned int ts_eodi		:  1;	/* TxDMA end of descriptor interrupt */
+		unsigned int ts_eofi		:  1;   /* TxDMA end of frame interrupt */
+		unsigned int rs_finish		:  1;   /* finished rx interrupt */
+		unsigned int rs_derr		:  1;   /* AHB Bus Error while rx */
+		unsigned int rs_perr		:  1;   /* Rx Descriptor protocol error */
+		unsigned int rs_eodi		:  1;	/* RxDMA end of descriptor interrupt */
+		unsigned int rs_eofi		:  1;	/* RxDMA end of frame interrupt */
+		unsigned int        		:  1; 	/* Tx fail interrupt */
+		unsigned int cnt_full		:  1;	/* MIB counters half full interrupt */
+		unsigned int rx_pause_on	:  1;	/* received pause on frame interrupt */
+		unsigned int tx_pause_on	:  1;	/* transmit pause on frame interrupt */
+		unsigned int rx_pause_off   :  1;	/* received pause off frame interrupt */
+		unsigned int tx_pause_off	:  1;	/* received pause off frame interrupt */
+		unsigned int rx_overrun		:  1;   /* GMAC Rx FIFO overrun interrupt */
+		unsigned int link_change	:  1;	/* GMAC link changed Interrupt for RGMII mode */
+		unsigned int        		:  1;
+		unsigned int            	:  1;
+		unsigned int 				:  3;
+		unsigned int loop_back		:  1;	/* loopback TxDMA to RxDMA */
+		unsigned int        		:  1;	/* Tx fail interrupt mask */
+		unsigned int m_cnt_full		:  1;	/* MIB counters half full interrupt mask */
+		unsigned int m_rx_pause_on	:  1;	/* received pause on frame interrupt mask */
+		unsigned int m_tx_pause_on  :  1;	/* transmit pause on frame interrupt mask */
+		unsigned int m_rx_pause_off :  1;	/* received pause off frame interrupt mask */
+		unsigned int m_tx_pause_off	:  1;	/* received pause off frame interrupt mask */
+		unsigned int m_rx_overrun	:  1;   /* GMAC Rx FIFO overrun interrupt mask */
+		unsigned int m_link_change	:  1;	/* GMAC link changed Interrupt mask for RGMII mode */
+#else
+		unsigned int m_link_change	:  1;	/* GMAC link changed Interrupt mask for RGMII mode */
+		unsigned int m_rx_overrun	:  1;   /* GMAC Rx FIFO overrun interrupt mask */
+		unsigned int m_tx_pause_off	:  1;	/* received pause off frame interrupt mask */
+		unsigned int m_rx_pause_off :  1;	/* received pause off frame interrupt mask */
+		unsigned int m_tx_pause_on  :  1;	/* transmit pause on frame interrupt mask */
+		unsigned int m_rx_pause_on	:  1;	/* received pause on frame interrupt mask */
+		unsigned int m_cnt_full		:  1;	/* MIB counters half full interrupt mask */
+		unsigned int         		:  1;	/* Tx fail interrupt mask */
+		unsigned int loop_back		:  1;	/* loopback TxDMA to RxDMA */
+		unsigned int 				:  3;
+		unsigned int            	:  1;
+		unsigned int        		:  1;
+		unsigned int link_change	:  1;	/* GMAC link changed Interrupt for RGMII mode */
+		unsigned int rx_overrun		:  1;   /* GMAC Rx FIFO overrun interrupt */
+		unsigned int tx_pause_off	:  1;	/* received pause off frame interrupt */
+		unsigned int rx_pause_off   :  1;	/* received pause off frame interrupt */
+		unsigned int tx_pause_on	:  1;	/* transmit pause on frame interrupt */
+		unsigned int rx_pause_on	:  1;	/* received pause on frame interrupt */
+		unsigned int cnt_full		:  1;	/* MIB counters half full interrupt */
+		unsigned int        		:  1; 	/* Tx fail interrupt */
+		unsigned int rs_eofi		:  1;	/* RxDMA end of frame interrupt */
+		unsigned int rs_eodi		:  1;	/* RxDMA end of descriptor interrupt */
+		unsigned int rs_perr		:  1;   /* Rx Descriptor protocol error */
+		unsigned int rs_derr		:  1;   /* AHB Bus Error while rx */
+		unsigned int rs_finish		:  1;   /* finished rx interrupt */
+		unsigned int ts_eofi		:  1;   /* TxDMA end of frame interrupt */
+		unsigned int ts_eodi		:  1;	/* TxDMA end of descriptor interrupt */
+		unsigned int ts_perr		:  1;   /* Tx Descriptor protocol error */
+		unsigned int ts_derr		:  1;   /* AHB Bus Error while tx */
+		unsigned int ts_finish		:  1;	/* finished tx interrupt */
+#endif
+	} bits;
+} GMAC_DMA_STATUS_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit2_ff08
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int td_start		:  1;	/* Start DMA transfer */
+		unsigned int td_continue	:  1;   /* Continue DMA operation */
+		unsigned int td_chain_mode	:  1;	/* Descriptor Chain Mode;1-Descriptor Chain mode, 0-Direct DMA mode*/
+		unsigned int 				:  1;
+		unsigned int td_prot		:  4;	/* TxDMA protection control */
+		unsigned int td_burst_size  :  2;	/* TxDMA max burst size for every AHB request */
+		unsigned int td_bus		    :  2;	/* peripheral bus width;0x->8 bits,10->16 bits,11->32 bits */
+		unsigned int td_endian		:  1;	/* AHB Endian. 0-little endian; 1-big endian */
+		unsigned int td_finish_en   :  1;	/* DMA Finish Event Interrupt Enable;1-enable;0-mask */
+		unsigned int td_fail_en 	:  1;	/* DMA Fail Interrupt Enable;1-enable;0-mask */
+		unsigned int td_perr_en 	:  1;	/* Protocol Failure Interrupt Enable;1-enable;0-mask */
+		unsigned int td_eod_en  	:  1;	/* End of Descriptor interrupt Enable;1-enable;0-mask */
+		unsigned int td_eof_en      :  1;   /* End of frame interrupt Enable;1-enable;0-mask */
+		unsigned int 				: 14;
+#else
+		unsigned int 				: 14;
+		unsigned int td_eof_en      :  1;   /* End of frame interrupt Enable;1-enable;0-mask */
+		unsigned int td_eod_en  	:  1;	/* End of Descriptor interrupt Enable;1-enable;0-mask */
+		unsigned int td_perr_en 	:  1;	/* Protocol Failure Interrupt Enable;1-enable;0-mask */
+		unsigned int td_fail_en 	:  1;	/* DMA Fail Interrupt Enable;1-enable;0-mask */
+		unsigned int td_finish_en   :  1;	/* DMA Finish Event Interrupt Enable;1-enable;0-mask */
+		unsigned int td_endian		:  1;	/* AHB Endian. 0-little endian; 1-big endian */
+		unsigned int td_bus		    :  2;	/* peripheral bus width;0x->8 bits,10->16 bits,11->32 bits */
+		unsigned int td_burst_size  :  2;	/* TxDMA max burst size for every AHB request */
+		unsigned int td_prot		:  4;	/* TxDMA protection control */
+		unsigned int 				:  1;
+		unsigned int td_chain_mode	:  1;	/* Descriptor Chain Mode;1-Descriptor Chain mode, 0-Direct DMA mode*/
+		unsigned int td_continue	:  1;   /* Continue DMA operation */
+		unsigned int td_start		:  1;	/* Start DMA transfer */
+#endif
+	} bits;
+} GMAC_TXDMA_CTRL_T;
+
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit2_ff0c
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int td_first_des_ptr	: 28;/* first descriptor address */
+		unsigned int td_busy			:  1;/* 1-TxDMA busy; 0-TxDMA idle */
+		unsigned int 					:  3;
+#else
+		unsigned int 					:  3;
+		unsigned int td_busy			:  1;/* 1-TxDMA busy; 0-TxDMA idle */
+		unsigned int td_first_des_ptr	: 28;/* first descriptor address */
+#endif
+	} bits;
+} GMAC_TXDMA_FIRST_DESC_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit2_ff10
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int ndar			: 28;	/* next descriptor address */
+		unsigned int eofie			:  1;	/* end of frame interrupt enable */
+		unsigned int    			:  1;
+		unsigned int sof_eof		:  2;
+#else
+		unsigned int sof_eof		:  2;
+		unsigned int    			:  1;
+		unsigned int eofie			:  1;	/* end of frame interrupt enable */
+		unsigned int ndar			: 28;	/* next descriptor address */
+#endif
+	} bits;
+} GMAC_TXDMA_CURR_DESC_T;
+
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit2_ff14
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int rd_start		:  1;	/* Start DMA transfer */
+		unsigned int rd_continue	:  1;   /* Continue DMA operation */
+		unsigned int rd_chain_mode	:  1;	/* Descriptor Chain Mode;1-Descriptor Chain mode, 0-Direct DMA mode*/
+		unsigned int 				:  1;
+		unsigned int rd_prot		:  4;	/* DMA protection control */
+		unsigned int rd_burst_size  :  2;	/* DMA max burst size for every AHB request */
+		unsigned int rd_bus		    :  2;	/* peripheral bus width;0x->8 bits,10->16 bits,11->32 bits */
+		unsigned int rd_endian		:  1;	/* AHB Endian. 0-little endian; 1-big endian */
+		unsigned int rd_finish_en   :  1;	/* DMA Finish Event Interrupt Enable;1-enable;0-mask */
+		unsigned int rd_fail_en  	:  1;	/* DMA Fail Interrupt Enable;1-enable;0-mask */
+		unsigned int rd_perr_en 	:  1;	/* Protocol Failure Interrupt Enable;1-enable;0-mask */
+		unsigned int rd_eod_en  	:  1;	/* End of Descriptor interrupt Enable;1-enable;0-mask */
+		unsigned int rd_eof_en      :  1;   /* End of frame interrupt Enable;1-enable;0-mask */
+		unsigned int 				: 14;
+#else
+		unsigned int 				: 14;
+		unsigned int rd_eof_en      :  1;   /* End of frame interrupt Enable;1-enable;0-mask */
+		unsigned int rd_eod_en  	:  1;	/* End of Descriptor interrupt Enable;1-enable;0-mask */
+		unsigned int rd_perr_en 	:  1;	/* Protocol Failure Interrupt Enable;1-enable;0-mask */
+		unsigned int rd_fail_en  	:  1;	/* DMA Fail Interrupt Enable;1-enable;0-mask */
+		unsigned int rd_finish_en   :  1;	/* DMA Finish Event Interrupt Enable;1-enable;0-mask */
+		unsigned int rd_endian		:  1;	/* AHB Endian. 0-little endian; 1-big endian */
+		unsigned int rd_bus		    :  2;	/* peripheral bus width;0x->8 bits,10->16 bits,11->32 bits */
+		unsigned int rd_burst_size  :  2;	/* DMA max burst size for every AHB request */
+		unsigned int rd_prot		:  4;	/* DMA protection control */
+		unsigned int 				:  1;
+		unsigned int rd_chain_mode	:  1;	/* Descriptor Chain Mode;1-Descriptor Chain mode, 0-Direct DMA mode*/
+		unsigned int rd_continue	:  1;   /* Continue DMA operation */
+		unsigned int rd_start		:  1;	/* Start DMA transfer */
+#endif
+	} bits;
+} GMAC_RXDMA_CTRL_T;
+
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit2_ff18
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int rd_first_des_ptr	: 28;/* first descriptor address */
+		unsigned int rd_busy			:  1;/* 1-RxDMA busy; 0-RxDMA idle */
+		unsigned int 					:  3;
+#else
+		unsigned int 					:  3;
+		unsigned int rd_busy			:  1;/* 1-RxDMA busy; 0-RxDMA idle */
+		unsigned int rd_first_des_ptr	: 28;/* first descriptor address */
+#endif
+	} bits;
+} GMAC_RXDMA_FIRST_DESC_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit2_ff1c
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int ndar			: 28;	/* next descriptor address */
+		unsigned int eofie			:  1;	/* end of frame interrupt enable */
+		unsigned int    			:  1;
+		unsigned int sof_eof		:  2;
+#else
+		unsigned int sof_eof		:  2;
+		unsigned int    			:  1;
+		unsigned int eofie			:  1;	/* end of frame interrupt enable */
+		unsigned int ndar			: 28;	/* next descriptor address */
+#endif
+	} bits;
+} GMAC_RXDMA_CURR_DESC_T;
+
+
+/********************************************/
+/*          Descriptor Format               */
+/********************************************/
+
+typedef struct descriptor_t
+{
+	union frame_control_t
+	{
+		unsigned int bits32;
+		struct bits_0000
+		{
+#if (BIG_ENDIAN==1)
+			unsigned int own 		: 1;	/* owner bit. 0-CPU, 1-DMA */
+			unsigned int derr		: 1;	/* data error during processing this descriptor */
+			unsigned int perr		: 1;	/* protocol error during processing this descriptor */
+			unsigned int csum_state : 3;	/* checksum error status */
+			unsigned int vlan_tag   : 1;    /* 802.1q vlan tag packet */
+			unsigned int frame_state: 3;    /* reference Rx Status1 */
+			unsigned int desc_count : 6;	/* number of descriptors used for the current frame */
+			unsigned int buffer_size:16;	/* transfer buffer size associated with current description*/
+#else
+			unsigned int buffer_size:16;	/* transfer buffer size associated with current description*/
+			unsigned int desc_count : 6;	/* number of descriptors used for the current frame */
+			unsigned int frame_state: 3;    /* reference Rx Status1 */
+			unsigned int vlan_tag   : 1;    /* 802.1q vlan tag packet */
+			unsigned int csum_state : 3;	/* checksum error status */
+			unsigned int perr		: 1;	/* protocol error during processing this descriptor */
+			unsigned int derr		: 1;	/* data error during processing this descriptor */
+			unsigned int own 		: 1;	/* owner bit. 0-CPU, 1-DMA */
+#endif
+		} bits_rx;
+
+		struct bits_0001
+		{
+#if (BIG_ENDIAN==1)
+			unsigned int own 		: 1;	/* owner bit. 0-CPU, 1-DMA */
+			unsigned int derr		: 1;	/* data error during processing this descriptor */
+			unsigned int perr		: 1;	/* protocol error during processing this descriptor */
+			unsigned int            : 6;
+			unsigned int success_tx : 1;    /* successful transmitted */
+			unsigned int desc_count : 6;	/* number of descriptors used for the current frame */
+			unsigned int buffer_size:16;	/* transfer buffer size associated with current description*/
+#else
+			unsigned int buffer_size:16;	/* transfer buffer size associated with current description*/
+			unsigned int desc_count : 6;	/* number of descriptors used for the current frame */
+			unsigned int success_tx : 1;    /* successful transmitted */
+			unsigned int            : 6;
+			unsigned int perr		: 1;	/* protocol error during processing this descriptor */
+			unsigned int derr		: 1;	/* data error during processing this descriptor */
+			unsigned int own 		: 1;	/* owner bit. 0-CPU, 1-DMA */
+#endif
+        } bits_tx_in;
+
+		struct bits_0002
+		{
+#if (BIG_ENDIAN==1)
+			unsigned int own 		: 1;	/* owner bit. 0-CPU, 1-DMA */
+			unsigned int derr		: 1;	/* data error during processing this descriptor */
+			unsigned int perr		: 1;	/* protocol error during processing this descriptor */
+			unsigned int            : 2;
+			unsigned int udp_csum_en: 1;    /* TSS UDP checksum enable */
+			unsigned int tcp_csum_en: 1;    /* TSS TCP checksum enable */
+			unsigned int ipv6_tx_en : 1;    /* TSS IPv6 TX enable */
+			unsigned int ip_csum_en : 1;    /* TSS IPv4 IP Header checksum enable */
+			unsigned int vlan_enable: 1;    /* VLAN TIC insertion enable */
+			unsigned int desc_count : 6;	/* number of descriptors used for the current frame */
+			unsigned int buffer_size:16;	/* transfer buffer size associated with current description*/
+#else
+			unsigned int buffer_size:16;	/* transfer buffer size associated with current description*/
+			unsigned int desc_count : 6;	/* number of descriptors used for the current frame */
+			unsigned int vlan_enable: 1;    /* VLAN TIC insertion enable */
+			unsigned int ip_csum_en : 1;    /* TSS IPv4 IP Header checksum enable */
+			unsigned int ipv6_tx_en : 1;    /* TSS IPv6 TX enable */
+			unsigned int tcp_csum_en: 1;    /* TSS TCP checksum enable */
+			unsigned int udp_csum_en: 1;    /* TSS UDP checksum enable */
+			unsigned int            : 2;
+			unsigned int perr		: 1;	/* protocol error during processing this descriptor */
+			unsigned int derr		: 1;	/* data error during processing this descriptor */
+			unsigned int own 		: 1;	/* owner bit. 0-CPU, 1-DMA */
+#endif
+        } bits_tx_out;
+
+	} frame_ctrl;
+
+	union flag_status_t
+	{
+		unsigned int bits32;
+		struct bits_0004
+		{
+#if (BIG_ENDIAN==1)
+            unsigned int priority   : 3;    /* user priority extracted from receiving frame*/
+            unsigned int cfi        : 1;	/* cfi extracted from receiving frame*/
+			unsigned int vlan_id    :12;	/* VLAN ID extracted from receiving frame */
+			unsigned int frame_count:16;	/* received frame byte count,include CRC,not include VLAN TIC */
+#else
+			unsigned int frame_count:16;	/* received frame byte count,include CRC,not include VLAN TIC */
+			unsigned int vlan_id    :12;	/* VLAN ID extracted from receiving frame */
+            unsigned int cfi        : 1;	/* cfi extracted from receiving frame*/
+            unsigned int priority   : 3;    /* user priority extracted from receiving frame*/
+#endif
+		} bits_rx_status;
+
+		struct bits_0005
+		{
+#if (BIG_ENDIAN==1)
+            unsigned int priority   : 3;    /* user priority to transmit*/
+            unsigned int cfi        : 1;	/* cfi to transmit*/
+			unsigned int vlan_id    :12;	/* VLAN ID to transmit */
+			unsigned int frame_count:16;    /* total tx frame byte count */
+#else
+			unsigned int frame_count:16;    /* total tx frame byte count */
+			unsigned int vlan_id    :12;	/* VLAN ID to transmit */
+            unsigned int cfi        : 1;	/* cfi to transmit*/
+            unsigned int priority   : 3;    /* user priority to transmit*/
+#endif
+		} bits_tx_flag;
+	} flag_status;
+
+	unsigned int buf_adr;	/* data buffer address */
+
+	union next_desc_t
+	{
+		unsigned int next_descriptor;
+		struct bits_000c
+		{
+#if (BIG_ENDIAN==1)
+			unsigned int ndar		:28;	/* next descriptor address */
+			unsigned int eofie		: 1;	/* end of frame interrupt enable */
+			unsigned int    		: 1;
+			unsigned int sof_eof	: 2;	/* 00-the linking descriptor   01-the last descriptor of a frame*/
+			                                /* 10-the first descriptor of a frame    11-only one descriptor for a frame*/
+#else
+			unsigned int sof_eof	: 2;	/* 00-the linking descriptor   01-the last descriptor of a frame*/
+			                                /* 10-the first descriptor of a frame    11-only one descriptor for a frame*/
+			unsigned int    		: 1;
+			unsigned int eofie		: 1;	/* end of frame interrupt enable */
+			unsigned int ndar		:28;	/* next descriptor address */
+#endif
+		} bits;
+	} next_desc;
+} GMAC_DESCRIPTOR_T;
+
+typedef struct gmac_conf {
+	struct net_device *dev;
+	int portmap;
+	int vid;
+	int flag;     /* 1: active  0: non-active */
+} sys_gmac_conf;
+
+struct gmac_private {
+	unsigned char       *tx_bufs;	/* Tx bounce buffer region. */
+	unsigned char       *rx_bufs;
+	GMAC_DESCRIPTOR_T	*tx_desc;	/* point to virtual TX descriptor address*/
+	GMAC_DESCRIPTOR_T	*rx_desc;	/* point to virtual RX descriptor address*/
+	GMAC_DESCRIPTOR_T	*tx_cur_desc;	/* point to current TX descriptor */
+	GMAC_DESCRIPTOR_T	*rx_cur_desc;	/* point to current RX descriptor */
+	GMAC_DESCRIPTOR_T   *tx_finished_desc;
+	GMAC_DESCRIPTOR_T   *rx_finished_desc;
+	unsigned long       cur_tx;
+	unsigned int        cur_rx;	/* Index into the Rx buffer of next Rx pkt. */
+	unsigned int        tx_flag;
+	unsigned long       dirty_tx;
+	unsigned char       *tx_buf[TX_DESC_NUM];	/* Tx bounce buffers */
+	dma_addr_t          tx_desc_dma; /* physical TX descriptor address */
+	dma_addr_t          rx_desc_dma;	/* physical RX descriptor address */
+	dma_addr_t          tx_bufs_dma; /* physical TX descriptor address */
+	dma_addr_t          rx_bufs_dma; /* physical RX descriptor address */
+    struct net_device_stats  stats;
+	pid_t               thr_pid;
+	wait_queue_head_t   thr_wait;
+	struct completion   thr_exited;
+    spinlock_t          lock;
+    int                 time_to_die;
+	unsigned int		tx_desc_hdr[GMAC_PHY_IF];	/* the descriptor which sw can fill */
+	unsigned int		tx_desc_tail[GMAC_PHY_IF];	/* the descriptor which is not cleaned yet */
+};
+
+
+struct reg_ioctl_data {
+    unsigned int    reg_addr;   /* the register address */
+    unsigned int    val_in;     /* data write to the register */
+    unsigned int    val_out;    /* data read from the register */
+};
+
+#ifdef CONFIG_SL2312_MPAGE
+typedef struct tx_data_t {
+	int	freeable; // 1 when it's skb. it can be freed in tx interrupt handler
+	struct sk_buff*	skb; // skb
+	int	desc_in_use; // 1 when the desc is in use. 0 when desc is available.
+	long end_seq; // to find out packets are in seq.
+	// so this value is the seq of next packet.
+} tx_data;
+#endif
+
+/*************************************************************
+ *         Global Variable
+ *************************************************************/
+struct semaphore        sem_gmac;   /* semaphore for share pins issue */
+
+/*************************************************************
+ *        Static Global Variable
+ *************************************************************/
+// static unsigned int     MAC_BASE_ADDR = GMAC0_BASE;
+static unsigned int     gmac_base_addr[GMAC_PHY_IF] = {GMAC0_BASE,GMAC1_BASE};
+static unsigned int     gmac_irq[GMAC_PHY_IF] = {IRQ_GMAC0,IRQ_GMAC1};
+static struct net_device *gmac_dev[GMAC_PHY_IF];
+
+static unsigned int     FLAG_SWITCH=0;	/* if 1-->switch chip presented. if 0-->switch chip unpresented */
+static unsigned int     flow_control_enable[GMAC_PHY_IF] = {1,1};
+static unsigned int     pre_phy_status[GMAC_PHY_IF] = {LINK_DOWN,LINK_DOWN};
+static unsigned int     tx_desc_virtual_base[GMAC_PHY_IF];
+static unsigned int     rx_desc_virtual_base[GMAC_PHY_IF];
+static unsigned int     full_duplex = 1;
+static unsigned int     speed = 1;
+#ifdef CONFIG_SL2312_MPAGE
+static tx_data		    tx_skb[GMAC_PHY_IF][TX_DESC_NUM];
+#else
+static struct sk_buff   *tx_skb[GMAC_PHY_IF][TX_DESC_NUM];
+#endif
+static struct sk_buff   *rx_skb[GMAC_PHY_IF][RX_DESC_NUM];
+static unsigned int     tx_desc_start_adr[GMAC_PHY_IF];
+static unsigned int     rx_desc_start_adr[GMAC_PHY_IF];
+static unsigned char    eth0_mac[6]= {0x00,0x50,0xc2,0x2b,0xd3,0x25};
+static unsigned char    eth1_mac[6]= {0x00,0x50,0xc2,0x2b,0xdf,0xfe};
+static unsigned int     next_tick = 3 * HZ;
+
+static unsigned int     phy_addr[GMAC_PHY_IF] = {0x01,0x02};  /* define PHY address */
+
+DECLARE_WAIT_QUEUE_HEAD(gmac_queue);
+//static 	wait_queue_t    wait;
+
+struct gmac_conf VLAN_conf[] = {
+#ifdef CONFIG_ADM_6999
+	{ (struct net_device *)0,0x7F,1 },
+	{ (struct net_device *)0,0x80,2 }
+#endif
+#ifdef CONFIG_ADM_6996
+	{ (struct net_device *)0,0x0F,1 },
+	{ (struct net_device *)0,0x10,2 }
+#endif
+};
+
+#define NUM_VLAN_IF	(sizeof(VLAN_conf)/sizeof(struct gmac_conf))
+
+
+/************************************************/
+/*            GMAC function declare             */
+/************************************************/
+
+unsigned int mii_read(unsigned char phyad,unsigned char regad);
+void mii_write(unsigned char phyad,unsigned char regad,unsigned int value);
+static void gmac_set_phy_status(struct net_device *dev);
+static void gmac_get_phy_status(struct net_device *dev);
+static int gmac_phy_thread (void *data);
+static int gmac_set_mac_address(struct net_device *dev, void *addr);
+static void gmac_tx_timeout(struct net_device *dev);
+static void gmac_tx_packet_complete(struct net_device *dev);
+static int gmac_start_xmit(struct sk_buff *skb, struct net_device *dev);
+static void gmac_set_rx_mode(struct net_device *dev);
+static void gmac_rx_packet(struct net_device *dev);
+static int gmac_open (struct net_device *dev);
+static int gmac_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
+
+static unsigned int gmac_get_dev_index(struct net_device *dev);
+static unsigned int gmac_select_interface(struct net_device *dev);
+
+#ifdef CONFIG_SL2312_MPAGE
+int printk_all(int dev_index, struct gmac_private* tp);
+#endif
+
+/****************************************/
+/*	SPI Function Declare		*/
+/****************************************/
+void SPI_write(unsigned char addr,unsigned int value);
+unsigned int SPI_read(unsigned char table,unsigned char addr);
+void SPI_write_bit(char bit_EEDO);
+unsigned int SPI_read_bit(void);
+void SPI_default(void);
+void SPI_reset(unsigned char rstype,unsigned char port_cnt);
+void SPI_pre_st(void);
+void SPI_CS_enable(unsigned char enable);
+void SPI_Set_VLAN(unsigned char LAN,unsigned int port_mask);
+void SPI_Set_tag(unsigned int port,unsigned tag);
+void SPI_Set_PVID(unsigned int PVID,unsigned int port_mask);
+unsigned int SPI_Get_PVID(unsigned int port);
+void SPI_mac_lock(unsigned int port, unsigned char lock);
+void SPI_get_port_state(unsigned int port);
+void SPI_port_enable(unsigned int port,unsigned char enable);
+unsigned int SPI_get_identifier(void);
+void SPI_get_status(unsigned int port);
+
+/****************************************/
+/*	VLAN Function Declare		        */
+/****************************************/
+int getVLANfromdev (struct net_device *dev );
+struct net_device * getdevfromVLAN( int VID);
+
+
+
+/************************************************/
+/*                 function body                */
+/************************************************/
+#if 0
+void hw_memcpy(void *to,const void *from,unsigned long n)
+{
+    writel(from,SL2312_DRAM_CTRL_BASE+0x20);  /* set source address */
+    writel(to,SL2312_DRAM_CTRL_BASE+0x24);    /* set destination address */
+    writel(n,SL2312_DRAM_CTRL_BASE+0x28);     /* set byte count */
+    writel(0x00000001,SL2312_DRAM_CTRL_BASE+0x2c);
+    while (readl(SL2312_DRAM_CTRL_BASE+0x2c));
+}
+#endif
+
+static unsigned int gmac_read_reg(unsigned int addr)
+{
+    unsigned int    reg_val;
+//    unsigned int    flags;
+//    spinlock_t     lock;
+
+//    spin_lock_irqsave(&lock, flags);
+    reg_val = readl(addr);	// Gary Chen
+//	spin_unlock_irqrestore(&lock, flags);
+	return (reg_val);
+}
+
+static void gmac_write_reg(unsigned int addr,unsigned int data,unsigned int bit_mask)
+{
+	unsigned int    reg_val;
+    //unsigned int    *addr;
+//    unsigned int    flags;
+//    spinlock_t     lock;
+
+//    spin_lock_irqsave(&lock, flags);
+	reg_val = ( gmac_read_reg(addr) & (~bit_mask) ) | (data & bit_mask);
+    writel(reg_val,addr);
+//	spin_unlock_irqrestore(&lock, flags);
+	return;
+}
+
+
+static void gmac_sw_reset(struct net_device *dev)
+{
+    unsigned int    index;
+    unsigned int    reg_val;
+
+    index = gmac_get_dev_index(dev);
+    if (index==0)
+        reg_val = readl(GMAC_GLOBAL_BASE_ADDR+0x0c) | 0x00000020;   /* GMAC0 S/W reset */
+    else
+        reg_val = readl(GMAC_GLOBAL_BASE_ADDR+0x0c) | 0x00000040;   /* GMAC1 S/W reset */
+
+    writel(reg_val,GMAC_GLOBAL_BASE_ADDR+0x0c);
+    return;
+}
+
+static void gmac_get_mac_address(void)
+{
+#ifdef CONFIG_MTD
+	extern int get_vlaninfo(vlaninfo* vlan);
+    static vlaninfo    vlan[2];
+
+    if (get_vlaninfo(&vlan[0]))
+    {
+        memcpy(eth0_mac,vlan[0].mac,6);
+        VLAN_conf[0].vid = vlan[0].vlanid;
+        VLAN_conf[0].portmap = vlan[0].vlanmap;
+        memcpy(eth1_mac,vlan[1].mac,6);
+        VLAN_conf[1].vid = vlan[1].vlanid;
+        VLAN_conf[1].portmap = vlan[1].vlanmap;
+    }
+#else
+    unsigned int reg_val;
+
+    reg_val = readl(IO_ADDRESS(SL2312_SECURITY_BASE)+0xac);
+    eth0_mac[4] = (reg_val & 0xff00) >> 8;
+    eth0_mac[5] = reg_val & 0x00ff;
+    reg_val = readl(IO_ADDRESS(SL2312_SECURITY_BASE)+0xac);
+    eth1_mac[4] = (reg_val & 0xff00) >> 8;
+    eth1_mac[5] = reg_val & 0x00ff;
+#endif
+    return;
+}
+
+static unsigned int gmac_get_dev_index(struct net_device *dev)
+{
+    unsigned int    i;
+
+    /* get device index number */
+    for (i=0;i<GMAC_PHY_IF;i++)
+    {
+        if (gmac_dev[i]==dev)
+        {
+            return(i);
+        }
+    }
+    return (0xff);
+}
+
+static unsigned int gmac_select_interface(struct net_device *dev)
+{
+    unsigned int    index;
+
+    index = gmac_get_dev_index(dev);
+    // MAC_BASE_ADDR = gmac_base_addr[index];	// Gary Chen
+    return (index);
+}
+
+
+static void gmac_dump_register(struct net_device *dev)
+{
+#if 0
+    unsigned int   i,val,index;
+
+    index = gmac_select_interface(dev);
+
+    printk("========== GMAC%d ==========\n",index);
+    for (i=0;i<=0x7c;i=i+4)
+    {
+        val = gmac_read_reg(gmac_base_addr[index] + i);
+        printk("offset = %08x   value = %08x\n",i,val);
+    }
+    for (i=0xff00;i<=0xff7c;i=i+4)
+    {
+        val = gmac_read_reg(gmac_base_addr[index] + i);
+        printk("offset = %08x   value = %08x\n",i,val);
+    }
+#endif
+}
+
+static int gmac_init_chip(struct net_device *dev)
+{
+	GMAC_RBNR_T		rbnr_val,rbnr_mask;
+	GMAC_CONFIG2_T	config2_val;
+	GMAC_CONFIG0_T	config0,config0_mask;
+	GMAC_CONFIG1_T	config1;
+	struct sockaddr sock;
+	unsigned int    status;
+	unsigned int    phy_mode;
+	unsigned int    index;
+
+    index = gmac_get_dev_index(dev);
+
+    /* set GMAC RMII mode */
+    if (index==0)
+        phy_mode = 0;   /* 0->MII 1->GMII 2->RGMII(10/100) 3->RGMII(1000) */
+    else
+        phy_mode = 2;   /* 0->MII 1->GMII 2->RGMII(10/100) 3->RGMII(1000) */
+
+    /* set PHY operation mode */
+    status = (phy_mode<<5) | 0x11 | (full_duplex<<3) | (speed<<1);
+    gmac_write_reg(gmac_base_addr[index] + GMAC_STATUS,status ,0x0000007f);
+
+	/* set station MAC address1 and address2 */
+	if (index==0)
+	    memcpy(&sock.sa_data[0],&eth0_mac[0],6);
+    else
+	    memcpy(&sock.sa_data[0],&eth1_mac[0],6);
+    gmac_set_mac_address(dev,(void *)&sock);
+
+    /* set RX_FLTR register to receive all multicast packet */
+    gmac_write_reg(gmac_base_addr[index] + GMAC_RX_FLTR,0x0000001F,0x0000001f);
+    //gmac_write_reg(gmac_base_addr[index] + GMAC_RX_FLTR,0x00000007,0x0000001f);
+
+	/* set per packet buffer size */
+	config1.bits32 = 0;
+    config1.bits.buf_size = 11; /* buffer size = 2048-byte */
+    gmac_write_reg(gmac_base_addr[index] + GMAC_CONFIG1,config1.bits32,0x0000000f);
+
+	/* set flow control threshold */
+	config2_val.bits32 = 0;
+	config2_val.bits.set_threshold = RX_DESC_NUM/4;
+	config2_val.bits.rel_threshold = RX_DESC_NUM*3/4;
+	gmac_write_reg(gmac_base_addr[index] + GMAC_CONFIG2,config2_val.bits32,0xffffffff);
+
+	/* init remaining buffer number register */
+	rbnr_val.bits32 = 0;
+	rbnr_val.bits.buf_remain = RX_DESC_NUM;
+	rbnr_mask.bits32 = 0;
+	rbnr_mask.bits.buf_remain = 0xffff;
+	gmac_write_reg(gmac_base_addr[index] + GMAC_RBNR,rbnr_val.bits32,rbnr_mask.bits32);
+
+    /* disable TX/RX and disable internal loop back */
+    config0.bits32 = 0;
+    config0_mask.bits32 = 0;
+    config0.bits.max_len = 2;
+    if (flow_control_enable[index]==1)
+    {
+        config0.bits.tx_fc_en = 1; /* enable tx flow control */
+        config0.bits.rx_fc_en = 1; /* enable rx flow control */
+        printk("Enable MAC Flow Control...\n");
+    }
+    else
+    {
+        config0.bits.tx_fc_en = 0; /* disable tx flow control */
+        config0.bits.rx_fc_en = 0; /* disable rx flow control */
+        printk("Disable MAC Flow Control...\n");
+    }
+    config0.bits.dis_rx = 1;  /* disable rx */
+    config0.bits.dis_tx = 1;  /* disable tx */
+    config0.bits.loop_back = 0; /* enable/disable GMAC loopback */
+	config0.bits.inv_rx_clk = 0;
+	config0.bits.rising_latch = 1;
+	config0.bits.ipv4_tss_rx_en = 1;  /* enable H/W to check ip checksum */
+	config0.bits.ipv6_tss_rx_en = 1;  /* enable H/W to check ip checksum */
+
+    config0_mask.bits.max_len = 7;
+    config0_mask.bits.tx_fc_en = 1;
+    config0_mask.bits.rx_fc_en = 1;
+    config0_mask.bits.dis_rx = 1;
+    config0_mask.bits.dis_tx = 1;
+    config0_mask.bits.loop_back = 1;
+    config0_mask.bits.inv_rx_clk = 1;
+	config0_mask.bits.rising_latch = 1;
+	config0_mask.bits.ipv4_tss_rx_en = 1;
+	config0_mask.bits.ipv6_tss_rx_en = 1;
+    gmac_write_reg(gmac_base_addr[index] + GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+
+	return (0);
+}
+
+static void gmac_enable_tx_rx(struct net_device *dev)
+{
+	GMAC_CONFIG0_T	config0,config0_mask;
+	int				dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+    /* enable TX/RX */
+    config0.bits32 = 0;
+    config0_mask.bits32 = 0;
+    config0.bits.dis_rx = 0;  /* enable rx */
+    config0.bits.dis_tx = 0;  /* enable tx */
+    config0_mask.bits.dis_rx = 1;
+    config0_mask.bits.dis_tx = 1;
+    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+}
+
+static void gmac_disable_tx_rx(struct net_device *dev)
+{
+	GMAC_CONFIG0_T	config0,config0_mask;
+	int				dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+    /* enable TX/RX */
+    config0.bits32 = 0;
+    config0_mask.bits32 = 0;
+    config0.bits.dis_rx = 1;  /* disable rx */
+    config0.bits.dis_tx = 1;  /* disable tx */
+    config0_mask.bits.dis_rx = 1;
+    config0_mask.bits.dis_tx = 1;
+    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+}
+
+#ifdef CONFIG_SL_NAPI
+static int gmac_rx_poll_ga(struct net_device *dev, int *budget)
+{
+	struct gmac_private *tp = dev->priv;
+	struct sk_buff 		*skb;
+    GMAC_RXDMA_CTRL_T       rxdma_ctrl,rxdma_ctrl_mask;
+	GMAC_RXDMA_FIRST_DESC_T	rxdma_busy;
+    GMAC_DESCRIPTOR_T   *rx_desc;
+	unsigned int 		pkt_size;
+	unsigned int        desc_count;
+    unsigned int        vid;
+//    unsigned int        priority;
+	unsigned int        own;
+	unsigned int        good_frame = 0;
+	unsigned int        index;
+	unsigned int        dev_index;
+	int                 work = 0;
+	int                 work_done = 0;
+	int                 quota = min(dev->quota, *budget);
+
+    dev_index = gmac_select_interface(dev);
+
+	for (;;)
+	{
+        own = tp->rx_cur_desc->frame_ctrl.bits32 >> 31;
+        if (own == CPU) /* check owner bit */
+        {
+	        rx_desc = tp->rx_cur_desc;
+#if (GMAC_DEBUG==1)
+	        /* check error interrupt */
+	        if ( (rx_desc->frame_ctrl.bits_rx.derr==1)||(rx_desc->frame_ctrl.bits_rx.perr==1) )
+	        {
+    	        printk("%s::Rx Descriptor Processing Error !!!\n",__func__);
+    	    }
+#endif
+    	    /* get frame information from the first descriptor of the frame */
+	        pkt_size = rx_desc->flag_status.bits_rx_status.frame_count - 4;  /*total byte count in a frame*/
+#if (GMAC_DEBUG==1)
+            priority = rx_desc->flag_status.bits_rx_status.priority;    /* 802.1p priority */
+#endif
+            vid = rx_desc->flag_status.bits_rx_status.vlan_id;          /* 802.1q vlan id */
+            if (vid == 0)
+            {
+                vid = 1;    /* default vlan */
+            }
+	        desc_count = rx_desc->frame_ctrl.bits_rx.desc_count; /* get descriptor count per frame */
+
+    		if (rx_desc->frame_ctrl.bits_rx.frame_state == 0x000) /* good frame */
+    		{
+    			tp->stats.rx_bytes += pkt_size;
+    			tp->stats.rx_packets++;
+    			good_frame = 1;
+    		}
+    		else
+    		{
+    			tp->stats.rx_errors++;
+    			good_frame = 0;
+    			printk("RX status: 0x%x\n",rx_desc->frame_ctrl.bits_rx.frame_state);
+    		}
+    	}
+    	else
+    	{
+    	    work_done = 1;
+    	    break;  /* Rx process is completed */
+    	}
+
+        if (good_frame == 1)
+        {
+            /* get rx skb buffer index */
+            index = ((unsigned int)tp->rx_cur_desc - rx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+            if (rx_skb[dev_index][index])
+            {
+                skb_reserve (rx_skb[dev_index][index], 2);	/* 16 byte align the IP fields. */
+                rx_skb[dev_index][index]->dev = dev;
+                rx_skb[dev_index][index]->ip_summed = CHECKSUM_UNNECESSARY;
+ 			    skb_put(rx_skb[dev_index][index],pkt_size);
+ 			    rx_skb[dev_index][index]->protocol = eth_type_trans(rx_skb[dev_index][index],dev); /* set skb protocol */
+ 			    netif_rx(rx_skb[dev_index][index]);  /* socket rx */
+ 			    dev->last_rx = jiffies;
+
+ 			    /* allocate rx skb buffer */
+                if ( (skb = dev_alloc_skb(RX_BUF_SIZE))==NULL)  /* allocate socket buffer */
+                {
+                    printk("%s::skb buffer allocation fail !\n",__func__);
+                }
+                rx_skb[dev_index][index] = skb;
+                tp->rx_cur_desc->buf_adr = (unsigned int)__pa(skb->data) | 0x02;    /* insert two bytes in the beginning of rx data */
+            }
+            else
+            {
+                printk("%s::rx skb index error !\n",__func__);
+            }
+        }
+
+	    tp->rx_cur_desc->frame_ctrl.bits_rx.own = DMA; /* release rx descriptor to DMA */
+        /* point to next rx descriptor */
+        tp->rx_cur_desc = (GMAC_DESCRIPTOR_T *)((tp->rx_cur_desc->next_desc.next_descriptor & 0xfffffff0)+rx_desc_virtual_base[dev_index]);
+
+        /* release buffer to Remaining Buffer Number Register */
+        if (flow_control_enable[dev_index] ==1)
+        {
+//            gmac_write_reg(gmac_base_addr[dev_index] + GMAC_BNCR,desc_count,0x0000ffff);
+            writel(desc_count,(unsigned int *)(gmac_base_addr[dev_index] + GMAC_BNCR));
+        }
+
+		if (work++ >= quota )
+		{
+			break;
+		}
+    }
+
+    /* if RX DMA process is stoped , restart it */
+	rxdma_busy.bits.rd_first_des_ptr = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_FIRST_DESC);
+	if (rxdma_busy.bits.rd_busy == 0)
+	{
+	    rxdma_ctrl.bits32 = 0;
+    	rxdma_ctrl.bits.rd_start = 1;    /* start RX DMA transfer */
+	    rxdma_ctrl.bits.rd_continue = 1; /* continue RX DMA operation */
+	    rxdma_ctrl_mask.bits32 = 0;
+    	rxdma_ctrl_mask.bits.rd_start = 1;
+	    rxdma_ctrl_mask.bits.rd_continue = 1;
+	    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,rxdma_ctrl.bits32,rxdma_ctrl_mask.bits32);
+    }
+
+	dev->quota -= work;
+	*budget -= work;
+	if (work_done==1)
+	{
+	    /* Receive descriptor is empty now */
+        netif_rx_complete(dev);
+        /* enable receive interrupt */
+        gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,0x0007c000,0x0007c000);   /* enable rx interrupt */
+        return 0;
+    }
+    else
+    {
+        return -1;
+    }
+}
+
+static int gmac_rx_poll_gb(struct net_device *dev, int *budget)
+{
+	struct gmac_private *tp = dev->priv;
+	struct sk_buff 		*skb;
+    GMAC_RXDMA_CTRL_T       rxdma_ctrl,rxdma_ctrl_mask;
+	GMAC_RXDMA_FIRST_DESC_T	rxdma_busy;
+    GMAC_DESCRIPTOR_T   *rx_desc;
+	unsigned int 		pkt_size;
+	unsigned int        desc_count;
+    unsigned int        vid;
+//    unsigned int        priority;
+	unsigned int        own;
+	unsigned int        good_frame = 0;
+	unsigned int        index;
+	unsigned int        dev_index;
+	int                 work = 0;
+	int                 work_done = 0;
+	int                 quota = min(dev->quota, *budget);
+
+    dev_index = gmac_select_interface(dev);
+
+	for (;;)
+	{
+        own = tp->rx_cur_desc->frame_ctrl.bits32 >> 31;
+        if (own == CPU) /* check owner bit */
+        {
+	        rx_desc = tp->rx_cur_desc;
+#if (GMAC_DEBUG==1)
+	        /* check error interrupt */
+	        if ( (rx_desc->frame_ctrl.bits_rx.derr==1)||(rx_desc->frame_ctrl.bits_rx.perr==1) )
+	        {
+    	        printk("%s::Rx Descriptor Processing Error !!!\n",__func__);
+    	    }
+#endif
+    	    /* get frame information from the first descriptor of the frame */
+	        pkt_size = rx_desc->flag_status.bits_rx_status.frame_count - 4;  /*total byte count in a frame*/
+#if (GMAC_DEBUG==1)
+            priority = rx_desc->flag_status.bits_rx_status.priority;    /* 802.1p priority */
+#endif
+            vid = rx_desc->flag_status.bits_rx_status.vlan_id;          /* 802.1q vlan id */
+            if (vid == 0)
+            {
+                vid = 1;    /* default vlan */
+            }
+	        desc_count = rx_desc->frame_ctrl.bits_rx.desc_count; /* get descriptor count per frame */
+
+    		if (rx_desc->frame_ctrl.bits_rx.frame_state == 0x000) /* good frame */
+    		{
+    			tp->stats.rx_bytes += pkt_size;
+    			tp->stats.rx_packets++;
+    			good_frame = 1;
+    		}
+    		else
+    		{
+    			tp->stats.rx_errors++;
+    			good_frame = 0;
+    			printk("RX status: 0x%x\n",rx_desc->frame_ctrl.bits_rx.frame_state);
+    		}
+    	}
+    	else
+    	{
+    	    work_done = 1;
+    	    break;  /* Rx process is completed */
+    	}
+
+        if (good_frame == 1)
+        {
+            /* get rx skb buffer index */
+            index = ((unsigned int)tp->rx_cur_desc - rx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+            if (rx_skb[dev_index][index])
+            {
+                skb_reserve (rx_skb[dev_index][index], 2);	/* 16 byte align the IP fields. */
+                rx_skb[dev_index][index]->dev = dev;
+                rx_skb[dev_index][index]->ip_summed = CHECKSUM_UNNECESSARY;
+ 			    skb_put(rx_skb[dev_index][index],pkt_size);
+ 			    rx_skb[dev_index][index]->protocol = eth_type_trans(rx_skb[dev_index][index],dev); /* set skb protocol */
+ 			    netif_rx(rx_skb[dev_index][index]);  /* socket rx */
+ 			    dev->last_rx = jiffies;
+
+ 			    /* allocate rx skb buffer */
+                if ( (skb = dev_alloc_skb(RX_BUF_SIZE))==NULL)  /* allocate socket buffer */
+                {
+                    printk("%s::skb buffer allocation fail !\n",__func__);
+                }
+                rx_skb[dev_index][index] = skb;
+                tp->rx_cur_desc->buf_adr = (unsigned int)__pa(skb->data) | 0x02;    /* insert two bytes in the beginning of rx data */
+            }
+            else
+            {
+                printk("%s::rx skb index error !\n",__func__);
+            }
+        }
+
+	    tp->rx_cur_desc->frame_ctrl.bits_rx.own = DMA; /* release rx descriptor to DMA */
+        /* point to next rx descriptor */
+        tp->rx_cur_desc = (GMAC_DESCRIPTOR_T *)((tp->rx_cur_desc->next_desc.next_descriptor & 0xfffffff0)+rx_desc_virtual_base[dev_index]);
+
+        /* release buffer to Remaining Buffer Number Register */
+        if (flow_control_enable[dev_index] ==1)
+        {
+//            gmac_write_reg(gmac_base_addr[dev_index] + GMAC_BNCR,desc_count,0x0000ffff);
+            writel(desc_count,(unsigned int *)(gmac_base_addr[dev_index] + GMAC_BNCR));
+        }
+
+		if (work++ >= quota )
+		{
+			break;
+		}
+    }
+
+    /* if RX DMA process is stoped , restart it */
+	rxdma_busy.bits.rd_first_des_ptr = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_FIRST_DESC);
+	if (rxdma_busy.bits.rd_busy == 0)
+	{
+	    rxdma_ctrl.bits32 = 0;
+    	rxdma_ctrl.bits.rd_start = 1;    /* start RX DMA transfer */
+	    rxdma_ctrl.bits.rd_continue = 1; /* continue RX DMA operation */
+	    rxdma_ctrl_mask.bits32 = 0;
+    	rxdma_ctrl_mask.bits.rd_start = 1;
+	    rxdma_ctrl_mask.bits.rd_continue = 1;
+	    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,rxdma_ctrl.bits32,rxdma_ctrl_mask.bits32);
+    }
+
+	dev->quota -= work;
+	*budget -= work;
+	if (work_done==1)
+	{
+	    /* Receive descriptor is empty now */
+        netif_rx_complete(dev);
+        /* enable receive interrupt */
+        gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,0x0007c000,0x0007c000);   /* enable rx interrupt */
+        return 0;
+    }
+    else
+    {
+        return -1;
+    }
+}
+
+#endif
+
+static void gmac_rx_packet(struct net_device *dev)
+{
+	struct gmac_private *tp = dev->priv;
+	struct sk_buff 		*skb;
+    GMAC_RXDMA_CTRL_T       rxdma_ctrl,rxdma_ctrl_mask;
+	GMAC_RXDMA_FIRST_DESC_T	rxdma_busy;
+    GMAC_DESCRIPTOR_T   *rx_desc;
+	unsigned int 		pkt_size;
+	unsigned int        desc_count;
+    unsigned int        vid;
+//    unsigned int        priority;
+	unsigned int        own;
+	unsigned int        good_frame = 0;
+	unsigned int        i,index;
+	unsigned int        dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+	for (i=0;i<256;i++)
+	{
+        own = tp->rx_cur_desc->frame_ctrl.bits32 >> 31;
+        if (own == CPU) /* check owner bit */
+        {
+	        rx_desc = tp->rx_cur_desc;
+#if (GMAC_DEBUG==1)
+	        /* check error interrupt */
+	        if ( (rx_desc->frame_ctrl.bits_rx.derr==1)||(rx_desc->frame_ctrl.bits_rx.perr==1) )
+	        {
+    	        printk("%s::Rx Descriptor Processing Error !!!\n",__func__);
+    	    }
+#endif
+    	    /* get frame information from the first descriptor of the frame */
+	        pkt_size = rx_desc->flag_status.bits_rx_status.frame_count - 4;  /*total byte count in a frame*/
+#if (GMAC_DEBUG==1)
+            priority = rx_desc->flag_status.bits_rx_status.priority;    /* 802.1p priority */
+#endif
+            vid = rx_desc->flag_status.bits_rx_status.vlan_id;          /* 802.1q vlan id */
+            if (vid == 0)
+            {
+                vid = 1;    /* default vlan */
+            }
+	        desc_count = rx_desc->frame_ctrl.bits_rx.desc_count; /* get descriptor count per frame */
+
+    		if (rx_desc->frame_ctrl.bits_rx.frame_state == 0x000) /* good frame */
+    		{
+    			tp->stats.rx_bytes += pkt_size;
+    			tp->stats.rx_packets++;
+    			good_frame = 1;
+    		}
+    		else
+    		{
+    			tp->stats.rx_errors++;
+    			good_frame = 0;
+    			printk("RX status: 0x%x\n",rx_desc->frame_ctrl.bits_rx.frame_state);
+    		}
+    	}
+    	else
+    	{
+    	    break;  /* Rx process is completed */
+    	}
+
+        if (good_frame == 1)
+        {
+            /* get rx skb buffer index */
+            index = ((unsigned int)tp->rx_cur_desc - rx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+            if (rx_skb[dev_index][index])
+            {
+                skb_reserve (rx_skb[dev_index][index], 2);	/* 16 byte align the IP fields. */
+                rx_skb[dev_index][index]->dev = dev;
+                rx_skb[dev_index][index]->ip_summed = CHECKSUM_UNNECESSARY;
+ 			    skb_put(rx_skb[dev_index][index],pkt_size);
+ 			    rx_skb[dev_index][index]->protocol = eth_type_trans(rx_skb[dev_index][index],dev); /* set skb protocol */
+ 			    netif_rx(rx_skb[dev_index][index]);  /* socket rx */
+ 			    dev->last_rx = jiffies;
+
+ 			    /* allocate rx skb buffer */
+                if ( (skb = dev_alloc_skb(RX_BUF_SIZE))==NULL)  /* allocate socket buffer */
+                {
+                    printk("%s::skb buffer allocation fail !\n",__func__);
+                }
+                rx_skb[dev_index][index] = skb;
+                tp->rx_cur_desc->buf_adr = (unsigned int)__pa(skb->data) | 0x02;    /* insert two bytes in the beginning of rx data */
+            }
+            else
+            {
+                printk("%s::rx skb index error !\n",__func__);
+            }
+        }
+
+	    tp->rx_cur_desc->frame_ctrl.bits_rx.own = DMA; /* release rx descriptor to DMA */
+        /* point to next rx descriptor */
+        tp->rx_cur_desc = (GMAC_DESCRIPTOR_T *)((tp->rx_cur_desc->next_desc.next_descriptor & 0xfffffff0)+rx_desc_virtual_base[dev_index]);
+
+        /* release buffer to Remaining Buffer Number Register */
+        if (flow_control_enable[dev_index] ==1)
+        {
+            gmac_write_reg(gmac_base_addr[dev_index] + GMAC_BNCR,desc_count,0x0000ffff);
+        }
+    }
+
+    /* if RX DMA process is stoped , restart it */
+	rxdma_busy.bits.rd_first_des_ptr = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_FIRST_DESC);
+	if (rxdma_busy.bits.rd_busy == 0)
+	{
+	    rxdma_ctrl.bits32 = 0;
+    	rxdma_ctrl.bits.rd_start = 1;    /* start RX DMA transfer */
+	    rxdma_ctrl.bits.rd_continue = 1; /* continue RX DMA operation */
+	    rxdma_ctrl_mask.bits32 = 0;
+    	rxdma_ctrl_mask.bits.rd_start = 1;
+	    rxdma_ctrl_mask.bits.rd_continue = 1;
+	    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,rxdma_ctrl.bits32,rxdma_ctrl_mask.bits32);
+    }
+}
+
+#ifdef CONFIG_SL2312_MPAGE
+static inline void free_tx_buf(int dev_index, int desc_index)
+{
+	if (tx_skb[dev_index][desc_index].freeable &&
+	    tx_skb[dev_index][desc_index].skb) {
+		struct sk_buff* skb = tx_skb[dev_index][desc_index].skb;
+		//printk("free_skb %x, len %d\n", skb, skb->len);
+#ifdef CONFIG_TXINT_DISABLE
+		dev_kfree_skb(skb);
+#else
+		dev_kfree_skb_irq(skb);
+#endif
+		tx_skb[dev_index][desc_index].skb = 0;
+	}
+}
+
+#ifdef CONFIG_TXINT_DISABLE
+static void gmac_tx_packet_complete(struct net_device *dev)
+{
+	struct gmac_private     *tp = dev->priv;
+    GMAC_DESCRIPTOR_T	    *tx_hw_complete_desc, *next_desc;
+    unsigned int desc_cnt=0;
+    unsigned int i,index,dev_index;
+    unsigned int tx_current_descriptor = 0;
+	// int own_dma = 0;
+
+    dev_index = gmac_select_interface(dev);
+
+	index = ((unsigned int)tp->tx_finished_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+	if (tx_skb[dev_index][index].desc_in_use && tp->tx_finished_desc->frame_ctrl.bits_tx_in.own == CPU) {
+		free_tx_buf(dev_index, index);
+		tx_skb[dev_index][index].desc_in_use = 0;
+	}
+	next_desc = (GMAC_DESCRIPTOR_T*)((tp->tx_finished_desc->next_desc.next_descriptor & 0xfffffff0) + tx_desc_virtual_base[dev_index]);
+
+	for (;;) {
+		tx_hw_complete_desc = (GMAC_DESCRIPTOR_T *)((gmac_read_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CURR_DESC) & 0xfffffff0)+ tx_desc_virtual_base[dev_index]);
+		if (next_desc == tx_hw_complete_desc)
+			break;
+		if (next_desc->frame_ctrl.bits_tx_in.own == CPU) {
+			if (next_desc->frame_ctrl.bits_tx_in.success_tx == 1) {
+				tp->stats.tx_bytes += next_desc->flag_status.bits_tx_flag.frame_count;
+				tp->stats.tx_packets ++;
+			} else {
+				tp->stats.tx_errors++;
+			}
+			desc_cnt = next_desc->frame_ctrl.bits_tx_in.desc_count;
+			for (i=1; i<desc_cnt; i++) {
+				/* get tx skb buffer index */
+				index = ((unsigned int)next_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+				next_desc->frame_ctrl.bits_tx_in.own = CPU;
+				free_tx_buf(dev_index, index);
+				tx_skb[dev_index][index].desc_in_use = 0;
+				tp->tx_desc_tail[dev_index] = (tp->tx_desc_tail[dev_index] +1) & (TX_DESC_NUM-1);
+				/* release Tx descriptor to CPU */
+				next_desc = (GMAC_DESCRIPTOR_T *)((next_desc->next_desc.next_descriptor & 0xfffffff0)+tx_desc_virtual_base[dev_index]);
+			}
+			/* get tx skb buffer index */
+			index = ((unsigned int)next_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+			/* free skb buffer */
+			next_desc->frame_ctrl.bits_tx_in.own = CPU;
+			free_tx_buf(dev_index, index);
+			tx_skb[dev_index][index].desc_in_use = 0;
+			tp->tx_desc_tail[dev_index] = (tp->tx_desc_tail[dev_index] +1) & (TX_DESC_NUM-1);
+			tp->tx_finished_desc = next_desc;
+//			printk("finish tx_desc index %d\n", index);
+			next_desc = (GMAC_DESCRIPTOR_T *)((next_desc->next_desc.next_descriptor & 0xfffffff0)+tx_desc_virtual_base[dev_index]);
+		}
+		else
+			break;
+	}
+	if (netif_queue_stopped(dev))
+	{
+		netif_wake_queue(dev);
+	}
+
+}
+#else
+static void gmac_tx_packet_complete(struct net_device *dev)
+{
+	struct gmac_private     *tp = dev->priv;
+	GMAC_DESCRIPTOR_T	    *tx_hw_complete_desc;
+	unsigned int desc_cnt=0;
+	unsigned int i,index,dev_index;
+	unsigned int tx_current_descriptor = 0;
+	// int own_dma = 0;
+
+	dev_index = gmac_select_interface(dev);
+
+	index = ((unsigned int)tp->tx_finished_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+
+	/* check tx status and accumulate tx statistics */
+	for (;;)
+	{
+
+        for (i=0;i<1000;i++)
+        {
+            tx_current_descriptor = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CURR_DESC);
+            if ( ((tx_current_descriptor & 0x00000003)==0x00000003) ||  /* only one descriptor */
+                 ((tx_current_descriptor & 0x00000003)==0x00000001) )   /* the last descriptor */
+            {
+                break;
+            }
+            udelay(1);
+        }
+        if (i==1000)
+        {
+//            gmac_dump_register(dev);
+//            printk("%s: tx current descriptor = %x \n",__func__,tx_current_descriptor);
+//            printk_all(dev_index, tp);
+            continue;
+        }
+
+	    /* get tx H/W completed descriptor virtual address */
+    	tx_hw_complete_desc = (GMAC_DESCRIPTOR_T *)((tx_current_descriptor & 0xfffffff0)+ tx_desc_virtual_base[dev_index]);
+//    	tx_hw_complete_desc = (GMAC_DESCRIPTOR_T *)((gmac_read_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CURR_DESC) & 0xfffffff0)+ tx_desc_virtual_base[dev_index]);
+	    if (tp->tx_finished_desc == tx_hw_complete_desc ) // ||
+		    //tx_skb[dev_index][index].desc_in_use )   /* complete tx processing */
+		{
+			break;
+		}
+
+        for (;;)
+        {
+    		if (tp->tx_finished_desc->frame_ctrl.bits_tx_in.own == CPU)
+    		{
+    #if (GMAC_DEBUG==1)
+    			if ( (tp->tx_finished_desc->frame_ctrl.bits_tx_in.derr) ||
+    			   (tp->tx_finished_desc->frame_ctrl.bits_tx_in.perr) )
+    			{
+    				printk("%s::Descriptor Processing Error !!!\n",__func__);
+    			}
+    #endif
+    			if (tp->tx_finished_desc->frame_ctrl.bits_tx_in.success_tx == 1)
+    			{
+    				tp->stats.tx_bytes += tp->tx_finished_desc->flag_status.bits_tx_flag.frame_count;
+    				tp->stats.tx_packets ++;
+    			}
+    			else
+    			{
+    				tp->stats.tx_errors++;
+    			}
+    			desc_cnt = tp->tx_finished_desc->frame_ctrl.bits_tx_in.desc_count;
+    			for (i=1; i<desc_cnt; i++)  /* multi-descriptor in one packet */
+    			{
+    				/* get tx skb buffer index */
+    				index = ((unsigned int)tp->tx_finished_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+    				tp->tx_finished_desc->frame_ctrl.bits_tx_in.own = CPU;
+    				free_tx_buf(dev_index, index);
+    				tx_skb[dev_index][index].desc_in_use = 0;
+    				/* release Tx descriptor to CPU */
+    				tp->tx_finished_desc = (GMAC_DESCRIPTOR_T *)((tp->tx_finished_desc->next_desc.next_descriptor & 0xfffffff0)+tx_desc_virtual_base[dev_index]);
+    			}
+    			/* get tx skb buffer index */
+    			index = ((unsigned int)tp->tx_finished_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+    			/* free skb buffer */
+    			tp->tx_finished_desc->frame_ctrl.bits_tx_in.own = CPU;
+    			free_tx_buf(dev_index, index);
+    			tx_skb[dev_index][index].desc_in_use = 0;
+    			tp->tx_finished_desc = (GMAC_DESCRIPTOR_T *)((tp->tx_finished_desc->next_desc.next_descriptor & 0xfffffff0)+tx_desc_virtual_base[dev_index]);
+
+        	    if (tp->tx_finished_desc == tx_hw_complete_desc )
+        		{
+        			break;
+        		}
+            }
+    		else
+    		{
+    			break;
+       		}
+		}
+	}
+
+	if (netif_queue_stopped(dev))
+	{
+		netif_wake_queue(dev);
+	}
+
+}
+#endif
+#else
+
+static void gmac_tx_packet_complete(struct net_device *dev)
+{
+	struct gmac_private     *tp = dev->priv;
+    GMAC_DESCRIPTOR_T	    *tx_hw_complete_desc;
+    unsigned int desc_cnt=0;
+    unsigned int i,index,dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+	/* get tx H/W completed descriptor virtual address */
+	tx_hw_complete_desc = (GMAC_DESCRIPTOR_T *)((gmac_read_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CURR_DESC) & 0xfffffff0)+ tx_desc_virtual_base[dev_index]);
+	/* check tx status and accumulate tx statistics */
+    for (;;)
+    {
+        if (tp->tx_finished_desc == tx_hw_complete_desc)   /* complete tx processing */
+        {
+            break;
+        }
+    	if (tp->tx_finished_desc->frame_ctrl.bits_tx_in.own == CPU)
+    	{
+#if (GMAC_DEBUG==1)
+    	    if ( (tp->tx_finished_desc->frame_ctrl.bits_tx_in.derr) ||
+    	         (tp->tx_finished_desc->frame_ctrl.bits_tx_in.perr) )
+    	    {
+    	        printk("%s::Descriptor Processing Error !!!\n",__func__);
+    	    }
+#endif
+            if (tp->tx_finished_desc->frame_ctrl.bits_tx_in.success_tx == 1)
+            {
+                tp->stats.tx_bytes += tp->tx_finished_desc->flag_status.bits_tx_flag.frame_count;
+                tp->stats.tx_packets ++;
+            }
+            else
+            {
+                tp->stats.tx_errors++;
+            }
+            desc_cnt = tp->tx_finished_desc->frame_ctrl.bits_tx_in.desc_count;
+        	for (i=1; i<desc_cnt; i++)  /* multi-descriptor in one packet */
+        	{
+                /* get tx skb buffer index */
+                index = ((unsigned int)tp->tx_finished_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+                /* free skb buffer */
+                if (tx_skb[dev_index][index])
+                {
+		            dev_kfree_skb_irq(tx_skb[dev_index][index]);
+		        }
+        	    /* release Tx descriptor to CPU */
+                tp->tx_finished_desc = (GMAC_DESCRIPTOR_T *)((tp->tx_finished_desc->next_desc.next_descriptor & 0xfffffff0)+tx_desc_virtual_base[dev_index]);
+                tp->tx_finished_desc->frame_ctrl.bits_tx_in.own = CPU;
+         	}
+            /* get tx skb buffer index */
+            index = ((unsigned int)tp->tx_finished_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+            /* free skb buffer */
+            if (tx_skb[dev_index][index])
+            {
+	            dev_kfree_skb_irq(tx_skb[dev_index][index]);
+	        }
+            tp->tx_finished_desc = (GMAC_DESCRIPTOR_T *)((tp->tx_finished_desc->next_desc.next_descriptor & 0xfffffff0)+tx_desc_virtual_base[dev_index]);
+     	}
+    }
+
+	if (netif_queue_stopped(dev))
+	{
+	    netif_wake_queue(dev);
+	}
+
+}
+
+
+#endif
+
+#if 0
+static void gmac_weird_interrupt(struct net_device *dev)
+{
+    gmac_dump_register(dev);
+}
+#endif
+
+/* The interrupt handler does all of the Rx thread work and cleans up
+   after the Tx thread. */
+static irqreturn_t gmac_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
+{
+	struct net_device       *dev = (struct net_device *)dev_instance;
+	GMAC_RXDMA_FIRST_DESC_T	rxdma_busy;
+//	GMAC_TXDMA_FIRST_DESC_T	txdma_busy;
+//    GMAC_TXDMA_CTRL_T       txdma_ctrl,txdma_ctrl_mask;
+    GMAC_RXDMA_CTRL_T       rxdma_ctrl,rxdma_ctrl_mask;
+	GMAC_DMA_STATUS_T	    status;
+    unsigned int            i,dev_index;
+	int                     handled = 0;
+
+    dev_index = gmac_select_interface(dev);
+
+	handled = 1;
+
+#ifdef CONFIG_SL_NAPI
+	disable_irq(gmac_irq[dev_index]);   /* disable GMAC interrupt */
+
+    status.bits32 = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_DMA_STATUS);	 /* read DMA status */
+    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_DMA_STATUS,status.bits32,status.bits32);    /* clear DMA status */
+
+    if (status.bits.rx_overrun == 1)
+    {
+		printk("%s::RX Overrun !!!%d\n",__func__,gmac_read_reg(gmac_base_addr[dev_index] + GMAC_RBNR));
+         gmac_dump_register(dev);
+        /* if RX DMA process is stoped , restart it */
+        rxdma_busy.bits32 = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_FIRST_DESC) ;
+        if (rxdma_busy.bits.rd_busy == 0)
+        {
+            /* restart Rx DMA process */
+	        rxdma_ctrl.bits32 = 0;
+	        rxdma_ctrl.bits.rd_start = 1;    /* start RX DMA transfer */
+            rxdma_ctrl.bits.rd_continue = 1; /* continue RX DMA operation */
+            rxdma_ctrl_mask.bits32 = 0;
+	        rxdma_ctrl_mask.bits.rd_start = 1;
+            rxdma_ctrl_mask.bits.rd_continue = 1;
+            gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,rxdma_ctrl.bits32,rxdma_ctrl_mask.bits32);
+        }
+    }
+
+    /* process rx packet */
+   	if (netif_running(dev) && ((status.bits.rs_eofi==1)||(status.bits.rs_finish==1)))
+   	{
+        if (likely(netif_rx_schedule_prep(dev)))
+        {
+            gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,0,0x0007c000);   /* disable rx interrupt */
+            __netif_rx_schedule(dev);
+        }
+    }
+#ifndef CONFIG_TXINT_DISABLE
+    /* process tx packet */
+	if (netif_running(dev) && ((status.bits.ts_eofi==1)||(status.bits.ts_finish==1)))
+	{
+		gmac_tx_packet_complete(dev);
+	}
+#endif
+
+	enable_irq(gmac_irq[dev_index]);    /* enable GMAC interrupt */
+    return IRQ_RETVAL(handled);
+#endif
+
+   /* disable GMAC interrupt */
+	disable_irq(gmac_irq[dev_index]);
+    for (i=0;i<MAX_ISR_WORK;i++)
+    {
+        /* read DMA status */
+	    status.bits32 = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_DMA_STATUS);
+int_status = status.bits32;
+	    /* clear DMA status */
+        gmac_write_reg(gmac_base_addr[dev_index] + GMAC_DMA_STATUS,status.bits32,status.bits32);
+
+        if ((status.bits32 & 0xffffc000)==0)
+        {
+            break;
+        }
+
+	    if (status.bits.rx_overrun == 1)
+	    {
+			printk("%s::RX Overrun !!!%d\n",__func__,gmac_read_reg(gmac_base_addr[dev_index] + GMAC_RBNR));
+           	gmac_dump_register(dev);
+            /* if RX DMA process is stoped , restart it */
+	        rxdma_busy.bits32 = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_FIRST_DESC) ;
+	        if (rxdma_busy.bits.rd_busy == 0)
+	        {
+	            /* restart Rx DMA process */
+    	        rxdma_ctrl.bits32 = 0;
+    	        rxdma_ctrl.bits.rd_start = 1;    /* start RX DMA transfer */
+	            rxdma_ctrl.bits.rd_continue = 1; /* continue RX DMA operation */
+	            rxdma_ctrl_mask.bits32 = 0;
+    	        rxdma_ctrl_mask.bits.rd_start = 1;
+	            rxdma_ctrl_mask.bits.rd_continue = 1;
+	            gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,rxdma_ctrl.bits32,rxdma_ctrl_mask.bits32);
+            }
+	    }
+
+        /* receive rx interrupt */
+    	if (netif_running(dev) && ((status.bits.rs_eofi==1)||(status.bits.rs_finish==1)))
+    	{
+    		gmac_rx_packet(dev);
+//    		gmac_tx_packet_complete(dev);
+        }
+
+        /* receive tx interrupt */
+    	// if (netif_running(dev) && (status.bits.ts_finish==1))
+#ifndef CONFIG_TXINT_DISABLE
+    	if (netif_running(dev) && ((status.bits.ts_eofi==1)||
+			   (status.bits.ts_finish==1)))
+    	{
+    		gmac_tx_packet_complete(dev);
+    	}
+#endif
+    	/* check uncommon events */
+/*        if ((status.bits32 & 0x632fc000)!=0)
+        {
+            printk("%s::DMA Status = %08x \n",__func__,status.bits32);
+            gmac_weird_interrupt(dev);
+        }
+*/
+	}
+
+    /* enable GMAC interrupt */
+	enable_irq(gmac_irq[dev_index]);
+	//printk("gmac_interrupt complete!\n\n");
+	return IRQ_RETVAL(handled);
+}
+
+static void gmac_hw_start(struct net_device *dev)
+{
+	struct gmac_private     *tp = dev->priv;
+	GMAC_TXDMA_CURR_DESC_T	tx_desc;
+	GMAC_RXDMA_CURR_DESC_T	rx_desc;
+    GMAC_TXDMA_CTRL_T       txdma_ctrl,txdma_ctrl_mask;
+    GMAC_RXDMA_CTRL_T       rxdma_ctrl,rxdma_ctrl_mask;
+	GMAC_DMA_STATUS_T       dma_status,dma_status_mask;
+	int						dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+	/* program TxDMA Current Descriptor Address register for first descriptor */
+	tx_desc.bits32 = (unsigned int)(tp->tx_desc_dma);
+	tx_desc.bits.eofie = 1;
+	tx_desc.bits.sof_eof = 0x03;
+	gmac_write_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CURR_DESC,tx_desc.bits32,0xffffffff);
+	gmac_write_reg(gmac_base_addr[dev_index] + 0xff2c,tx_desc.bits32,0xffffffff);   /* tx next descriptor address */
+
+	/* program RxDMA Current Descriptor Address register for first descriptor */
+	rx_desc.bits32 = (unsigned int)(tp->rx_desc_dma);
+	rx_desc.bits.eofie = 1;
+	rx_desc.bits.sof_eof = 0x03;
+	gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CURR_DESC,rx_desc.bits32,0xffffffff);
+	gmac_write_reg(gmac_base_addr[dev_index] + 0xff3c,rx_desc.bits32,0xffffffff);   /* rx next descriptor address */
+
+	/* enable GMAC interrupt & disable loopback */
+	dma_status.bits32 = 0;
+	dma_status.bits.loop_back = 0;  /* disable DMA loop-back mode */
+//	dma_status.bits.m_tx_fail = 1;
+	dma_status.bits.m_cnt_full = 1;
+	dma_status.bits.m_rx_pause_on = 1;
+	dma_status.bits.m_tx_pause_on = 1;
+	dma_status.bits.m_rx_pause_off = 1;
+	dma_status.bits.m_tx_pause_off = 1;
+	dma_status.bits.m_rx_overrun = 1;
+	dma_status.bits.m_link_change = 1;
+	dma_status_mask.bits32 = 0;
+	dma_status_mask.bits.loop_back = 1;
+//	dma_status_mask.bits.m_tx_fail = 1;
+	dma_status_mask.bits.m_cnt_full = 1;
+	dma_status_mask.bits.m_rx_pause_on = 1;
+	dma_status_mask.bits.m_tx_pause_on = 1;
+	dma_status_mask.bits.m_rx_pause_off = 1;
+	dma_status_mask.bits.m_tx_pause_off = 1;
+	dma_status_mask.bits.m_rx_overrun = 1;
+	dma_status_mask.bits.m_link_change = 1;
+	gmac_write_reg(gmac_base_addr[dev_index] + GMAC_DMA_STATUS,dma_status.bits32,dma_status_mask.bits32);
+
+    /* program tx dma control register */
+	txdma_ctrl.bits32 = 0;
+	txdma_ctrl.bits.td_start = 0;    /* start TX DMA transfer */
+	txdma_ctrl.bits.td_continue = 0; /* continue Tx DMA operation */
+	txdma_ctrl.bits.td_chain_mode = 1;  /* chain mode */
+	txdma_ctrl.bits.td_prot = 0;
+	txdma_ctrl.bits.td_burst_size = 2;  /* DMA burst size for every AHB request */
+	txdma_ctrl.bits.td_bus = 2;         /* peripheral bus width */
+	txdma_ctrl.bits.td_endian = 0;      /* little endian */
+#ifdef CONFIG_TXINT_DISABLE
+	txdma_ctrl.bits.td_finish_en = 0;   /* DMA finish event interrupt disable */
+#else
+	txdma_ctrl.bits.td_finish_en = 1;   /* DMA finish event interrupt enable */
+#endif
+	txdma_ctrl.bits.td_fail_en = 1;     /* DMA fail interrupt enable */
+	txdma_ctrl.bits.td_perr_en = 1;     /* protocol failure interrupt enable */
+	txdma_ctrl.bits.td_eod_en = 0;      /* disable Tx End of Descriptor Interrupt */
+	//txdma_ctrl.bits.td_eod_en = 0;      /* disable Tx End of Descriptor Interrupt */
+#ifdef CONFIG_TXINT_DISABLE
+	txdma_ctrl.bits.td_eof_en = 0;      /* end of frame interrupt disable */
+#else
+	txdma_ctrl.bits.td_eof_en = 1;      /* end of frame interrupt enable */
+#endif
+	txdma_ctrl_mask.bits32 = 0;
+	txdma_ctrl_mask.bits.td_start = 1;
+	txdma_ctrl_mask.bits.td_continue = 1;
+	txdma_ctrl_mask.bits.td_chain_mode = 1;
+	txdma_ctrl_mask.bits.td_prot = 15;
+	txdma_ctrl_mask.bits.td_burst_size = 3;
+	txdma_ctrl_mask.bits.td_bus = 3;
+	txdma_ctrl_mask.bits.td_endian = 1;
+	txdma_ctrl_mask.bits.td_finish_en = 1;
+	txdma_ctrl_mask.bits.td_fail_en = 1;
+	txdma_ctrl_mask.bits.td_perr_en = 1;
+	txdma_ctrl_mask.bits.td_eod_en = 1;
+	//txdma_ctrl_mask.bits.td_eod_en = 1;
+	txdma_ctrl_mask.bits.td_eof_en = 1;
+	gmac_write_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CTRL,txdma_ctrl.bits32,txdma_ctrl_mask.bits32);
+
+    /* program rx dma control register */
+	rxdma_ctrl.bits32 = 0;
+	rxdma_ctrl.bits.rd_start = 1;    /* start RX DMA transfer */
+	rxdma_ctrl.bits.rd_continue = 1; /* continue RX DMA operation */
+	rxdma_ctrl.bits.rd_chain_mode = 1;  /* chain mode */
+	rxdma_ctrl.bits.rd_prot = 0;
+	rxdma_ctrl.bits.rd_burst_size = 2;  /* DMA burst size for every AHB request */
+	rxdma_ctrl.bits.rd_bus = 2;         /* peripheral bus width */
+	rxdma_ctrl.bits.rd_endian = 0;      /* little endian */
+	rxdma_ctrl.bits.rd_finish_en = 1;   /* DMA finish event interrupt enable */
+	rxdma_ctrl.bits.rd_fail_en = 1;     /* DMA fail interrupt enable */
+	rxdma_ctrl.bits.rd_perr_en = 1;     /* protocol failure interrupt enable */
+	rxdma_ctrl.bits.rd_eod_en = 0;      /* disable Rx End of Descriptor Interrupt */
+	rxdma_ctrl.bits.rd_eof_en = 1;      /* end of frame interrupt enable */
+	rxdma_ctrl_mask.bits32 = 0;
+	rxdma_ctrl_mask.bits.rd_start = 1;
+	rxdma_ctrl_mask.bits.rd_continue = 1;
+	rxdma_ctrl_mask.bits.rd_chain_mode = 1;
+	rxdma_ctrl_mask.bits.rd_prot = 15;
+	rxdma_ctrl_mask.bits.rd_burst_size = 3;
+	rxdma_ctrl_mask.bits.rd_bus = 3;
+	rxdma_ctrl_mask.bits.rd_endian = 1;
+	rxdma_ctrl_mask.bits.rd_finish_en = 1;
+	rxdma_ctrl_mask.bits.rd_fail_en = 1;
+	rxdma_ctrl_mask.bits.rd_perr_en = 1;
+	rxdma_ctrl_mask.bits.rd_eod_en = 1;
+	rxdma_ctrl_mask.bits.rd_eof_en = 1;
+	gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,rxdma_ctrl.bits32,rxdma_ctrl_mask.bits32);
+    return;
+}
+
+static void gmac_hw_stop(struct net_device *dev)
+{
+    GMAC_TXDMA_CTRL_T       txdma_ctrl,txdma_ctrl_mask;
+    GMAC_RXDMA_CTRL_T       rxdma_ctrl,rxdma_ctrl_mask;
+	int 					dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+    /* program tx dma control register */
+	txdma_ctrl.bits32 = 0;
+	txdma_ctrl.bits.td_start = 0;
+	txdma_ctrl.bits.td_continue = 0;
+	txdma_ctrl_mask.bits32 = 0;
+	txdma_ctrl_mask.bits.td_start = 1;
+	txdma_ctrl_mask.bits.td_continue = 1;
+	gmac_write_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CTRL,txdma_ctrl.bits32,txdma_ctrl_mask.bits32);
+    /* program rx dma control register */
+	rxdma_ctrl.bits32 = 0;
+	rxdma_ctrl.bits.rd_start = 0;    /* stop RX DMA transfer */
+	rxdma_ctrl.bits.rd_continue = 0; /* stop continue RX DMA operation */
+	rxdma_ctrl_mask.bits32 = 0;
+	rxdma_ctrl_mask.bits.rd_start = 1;
+	rxdma_ctrl_mask.bits.rd_continue = 1;
+	gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RXDMA_CTRL,rxdma_ctrl.bits32,rxdma_ctrl_mask.bits32);
+}
+
+static int gmac_init_desc_buf(struct net_device *dev)
+{
+	struct gmac_private *tp = dev->priv;
+	struct sk_buff 		*skb;
+	dma_addr_t          tx_first_desc_dma=0;
+	dma_addr_t          rx_first_desc_dma=0;
+	dma_addr_t          rx_first_buf_dma=0;
+	unsigned int        i,index;
+
+    printk("Descriptor buffer init......\n");
+
+    /* get device index number */
+    index = gmac_get_dev_index(dev);
+#ifdef CONFIG_SL2312_MPAGE
+	for (i=0; i<TX_DESC_NUM; i++) {
+		tx_skb[index][i].freeable = 0;
+		tx_skb[index][i].skb = 0;
+		tx_skb[index][i].desc_in_use = 0;
+		tx_skb[index][i].end_seq = 0;
+	}
+#else
+    for (i=0;i<TX_DESC_NUM;i++)
+    {
+        tx_skb[index][i] = NULL;
+    }
+#endif
+    for (i=0;i<RX_DESC_NUM;i++)
+    {
+        rx_skb[index][i] = NULL;
+    }
+
+	/* allocates TX/RX descriptors */
+	tp->tx_desc = DMA_MALLOC(TX_DESC_NUM*sizeof(GMAC_DESCRIPTOR_T),(dma_addr_t *)&tp->tx_desc_dma);
+    tx_desc_virtual_base[index] = (unsigned int)tp->tx_desc - (unsigned int)tp->tx_desc_dma;
+    memset(tp->tx_desc,0x00,TX_DESC_NUM*sizeof(GMAC_DESCRIPTOR_T));
+	tp->rx_desc = DMA_MALLOC(RX_DESC_NUM*sizeof(GMAC_DESCRIPTOR_T),(dma_addr_t *)&tp->rx_desc_dma);
+    rx_desc_virtual_base[index] = (unsigned int)tp->rx_desc - (unsigned int)tp->rx_desc_dma;
+    memset(tp->rx_desc,0x00,RX_DESC_NUM*sizeof(GMAC_DESCRIPTOR_T));
+    tx_desc_start_adr[index] = (unsigned int)tp->tx_desc;   /* for tx skb index calculation */
+    rx_desc_start_adr[index] = (unsigned int)tp->rx_desc;   /* for rx skb index calculation */
+    printk("tx_desc = %08x\n",(unsigned int)tp->tx_desc);
+    printk("rx_desc = %08x\n",(unsigned int)tp->rx_desc);
+	printk("tx_desc_dma = %08x\n",tp->tx_desc_dma);
+	printk("rx_desc_dma = %08x\n",tp->rx_desc_dma);
+
+	if (tp->tx_desc==0x00 || tp->rx_desc==0x00)
+	{
+		free_irq(dev->irq, dev);
+
+		if (tp->tx_desc)
+			DMA_MFREE(tp->tx_desc, TX_DESC_NUM*sizeof(GMAC_DESCRIPTOR_T),tp->tx_desc_dma);
+		if (tp->rx_desc)
+			DMA_MFREE(tp->rx_desc, RX_DESC_NUM*sizeof(GMAC_DESCRIPTOR_T),tp->rx_desc_dma);
+		return -ENOMEM;
+	}
+
+	/* TX descriptors initial */
+	tp->tx_cur_desc = tp->tx_desc;  /* virtual address */
+	tp->tx_finished_desc = tp->tx_desc; /* virtual address */
+	tx_first_desc_dma = tp->tx_desc_dma; /* physical address */
+	for (i = 1; i < TX_DESC_NUM; i++)
+	{
+		tp->tx_desc->frame_ctrl.bits_tx_out.own = CPU; /* set owner to CPU */
+		tp->tx_desc->frame_ctrl.bits_tx_out.buffer_size = TX_BUF_SIZE;  /* set tx buffer size for descriptor */
+		tp->tx_desc_dma = tp->tx_desc_dma + sizeof(GMAC_DESCRIPTOR_T); /* next tx descriptor DMA address */
+		tp->tx_desc->next_desc.next_descriptor = tp->tx_desc_dma | 0x0000000b;
+		tp->tx_desc = &tp->tx_desc[1] ; /* next tx descriptor virtual address */
+	}
+	/* the last descriptor will point back to first descriptor */
+	tp->tx_desc->frame_ctrl.bits_tx_out.own = CPU;
+	tp->tx_desc->frame_ctrl.bits_tx_out.buffer_size = TX_BUF_SIZE;
+	tp->tx_desc->next_desc.next_descriptor = tx_first_desc_dma | 0x0000000b;
+	tp->tx_desc = tp->tx_cur_desc;
+	tp->tx_desc_dma = tx_first_desc_dma;
+
+	/* RX descriptors initial */
+	tp->rx_cur_desc = tp->rx_desc;  /* virtual address */
+	rx_first_desc_dma = tp->rx_desc_dma; /* physical address */
+	for (i = 1; i < RX_DESC_NUM; i++)
+	{
+        if ( (skb = dev_alloc_skb(RX_BUF_SIZE))==NULL)  /* allocate socket buffer */
+        {
+            printk("%s::skb buffer allocation fail !\n",__func__);
+        }
+        rx_skb[index][i-1] = skb;
+        tp->rx_desc->buf_adr = (unsigned int)__pa(skb->data) | 0x02;    /* insert two bytes in the beginning of rx data */
+		tp->rx_desc->frame_ctrl.bits_rx.own = DMA;  /* set owner bit to DMA */
+		tp->rx_desc->frame_ctrl.bits_rx.buffer_size = RX_BUF_SIZE; /* set rx buffer size for descriptor */
+		tp->rx_bufs_dma = tp->rx_bufs_dma + RX_BUF_SIZE;    /* point to next buffer address */
+		tp->rx_desc_dma = tp->rx_desc_dma + sizeof(GMAC_DESCRIPTOR_T); /* next rx descriptor DMA address */
+		tp->rx_desc->next_desc.next_descriptor = tp->rx_desc_dma | 0x0000000b;
+		tp->rx_desc = &tp->rx_desc[1]; /* next rx descriptor virtual address */
+	}
+	/* the last descriptor will point back to first descriptor */
+    if ( (skb = dev_alloc_skb(RX_BUF_SIZE))==NULL)  /* allocate socket buffer */
+    {
+        printk("%s::skb buffer allocation fail !\n",__func__);
+    }
+    rx_skb[index][i-1] = skb;
+    tp->rx_desc->buf_adr = (unsigned int)__pa(skb->data) | 0x02;    /* insert two bytes in the beginning of rx data */
+	tp->rx_desc->frame_ctrl.bits_rx.own = DMA;
+	tp->rx_desc->frame_ctrl.bits_rx.buffer_size = RX_BUF_SIZE;
+	tp->rx_desc->next_desc.next_descriptor = rx_first_desc_dma | 0x0000000b;
+	tp->rx_desc = tp->rx_cur_desc;
+	tp->rx_desc_dma = rx_first_desc_dma;
+	tp->rx_bufs_dma = rx_first_buf_dma;
+
+	for (i=0; i<GMAC_PHY_IF; i++) {
+		tp->tx_desc_hdr[i] = 0;
+		tp->tx_desc_tail[i] = 0;
+	}
+	return (0);
+}
+
+static int gmac_clear_counter (struct net_device *dev)
+{
+	struct gmac_private *tp = dev->priv;
+	unsigned int    dev_index;
+
+    dev_index = gmac_select_interface(dev);
+//	tp = gmac_dev[index]->priv;
+    /* clear counter */
+    gmac_read_reg(gmac_base_addr[dev_index] + GMAC_IN_DISCARDS);
+    gmac_read_reg(gmac_base_addr[dev_index] + GMAC_IN_ERRORS);
+    tp->stats.tx_bytes = 0;
+    tp->stats.tx_packets = 0;
+	tp->stats.tx_errors = 0;
+    tp->stats.rx_bytes = 0;
+	tp->stats.rx_packets = 0;
+	tp->stats.rx_errors = 0;
+    tp->stats.rx_dropped = 0;
+	return (0);
+}
+
+static int gmac_open (struct net_device *dev)
+{
+	struct gmac_private     *tp = dev->priv;
+	int    retval;
+
+    gmac_select_interface(dev);
+
+	/* chip reset */
+	gmac_sw_reset(dev);
+
+    /* allocates tx/rx descriptor and buffer memory */
+    gmac_init_desc_buf(dev);
+
+    /* get mac address from FLASH */
+    gmac_get_mac_address();
+
+    /* set PHY register to start autonegition process */
+    gmac_set_phy_status(dev);
+
+	/* GMAC initialization */
+	if (gmac_init_chip(dev))
+	{
+		printk (KERN_ERR "GMAC init fail\n");
+	}
+
+    /* start DMA process */
+	gmac_hw_start(dev);
+
+    /* enable tx/rx register */
+    gmac_enable_tx_rx(dev);
+
+    /* clear statistic counter */
+    gmac_clear_counter(dev);
+
+   	netif_start_queue (dev);
+
+    /* hook ISR */
+	retval = request_irq (dev->irq, gmac_interrupt, SA_INTERRUPT, dev->name, dev);
+	if (retval)
+		return retval;
+
+	if(!FLAG_SWITCH)
+	{
+    	init_waitqueue_head (&tp->thr_wait);
+    	init_completion(&tp->thr_exited);
+
+    	tp->time_to_die = 0;
+    	tp->thr_pid = kernel_thread (gmac_phy_thread, dev, CLONE_FS | CLONE_FILES);
+    	if (tp->thr_pid < 0)
+    	{
+    		printk (KERN_WARNING "%s: unable to start kernel thread\n",dev->name);
+    	}
+    }
+	return (0);
+}
+
+static int gmac_close(struct net_device *dev)
+{
+    struct gmac_private *tp = dev->priv;
+    unsigned int        i,dev_index;
+    unsigned int        ret;
+
+    dev_index = gmac_get_dev_index(dev);
+
+    /* stop tx/rx packet */
+    gmac_disable_tx_rx(dev);
+
+    /* stop the chip's Tx and Rx DMA processes */
+	gmac_hw_stop(dev);
+
+    netif_stop_queue(dev);
+
+    /* disable interrupts by clearing the interrupt mask */
+    synchronize_irq();
+    free_irq(dev->irq,dev);
+
+	DMA_MFREE(tp->tx_desc, TX_DESC_NUM*sizeof(GMAC_DESCRIPTOR_T),(unsigned int)tp->tx_desc_dma);
+	DMA_MFREE(tp->rx_desc, RX_DESC_NUM*sizeof(GMAC_DESCRIPTOR_T),(unsigned int)tp->rx_desc_dma);
+
+#ifdef CONFIG_SL2312_MPAGE
+//	kfree(tx_skb);
+#endif
+
+    for (i=0;i<RX_DESC_NUM;i++)
+    {
+        if (rx_skb[dev_index][i])
+        {
+            dev_kfree_skb(rx_skb[dev_index][i]);
+        }
+    }
+	if(!FLAG_SWITCH)
+	{
+    	if (tp->thr_pid >= 0)
+    	{
+		    tp->time_to_die = 1;
+    		wmb();
+    		ret = kill_proc (tp->thr_pid, SIGTERM, 1);
+    		if (ret)
+    		{
+    			printk (KERN_ERR "%s: unable to signal thread\n", dev->name);
+    			return ret;
+    		}
+//    		wait_for_completion (&tp->thr_exited);
+    	}
+    }
+
+    return (0);
+}
+
+#ifdef CONFIG_SL2312_MPAGE
+int printk_all(int dev_index, struct gmac_private* tp)
+{
+	int i=0;
+    unsigned int tx_current_descriptor = 0;
+    int hw_index;
+    int fi;
+    GMAC_DESCRIPTOR_T* tmp_desc;
+
+	GMAC_DESCRIPTOR_T* cur_desc=tp->tx_cur_desc;
+	fi = ((unsigned int)cur_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+	printk("tmp_desc %x, id %d\n", (int)cur_desc, fi);
+
+	tmp_desc = (GMAC_DESCRIPTOR_T*)((gmac_read_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CURR_DESC) & 0xfffffff0) + tx_desc_virtual_base[dev_index]);
+	hw_index = ((unsigned int)tmp_desc - tx_desc_start_adr[dev_index])/ sizeof(GMAC_DESCRIPTOR_T);
+	printk("hd_desc %x, ind %d, fin desc %x\n",(int)tmp_desc, hw_index, (int)tp->tx_finished_desc);
+
+	for (i=0; i<TX_DESC_NUM; i++) {
+		printk("**id %4d, hw_index %4d ==> ", fi, hw_index);
+		printk("fc %8x ", tmp_desc->frame_ctrl.bits32);
+		printk("fs %8x ", tmp_desc->flag_status.bits32);
+		printk("fb %8x ", tmp_desc->buf_adr);
+		printk("fd %8x\n",  tmp_desc->next_desc.next_descriptor);
+	  	tmp_desc = (GMAC_DESCRIPTOR_T*)((tmp_desc->next_desc.next_descriptor & 0xfffffff0) + tx_desc_virtual_base[dev_index]);
+		fi = ((unsigned int)tmp_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+	}
+    tx_current_descriptor = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CURR_DESC);
+    printk("%s: tx current descriptor = %x \n",__func__,tx_current_descriptor);
+    printk("%s: interrupt status = %x \n",__func__,int_status);
+    return 0;
+}
+
+int cleanup_desc(int dev_index, struct gmac_private* tp)
+{
+	int i=0;
+	int index = ((unsigned int)tp->tx_cur_desc - tx_desc_start_adr[dev_index])/sizeof(GMAC_DESCRIPTOR_T);
+	GMAC_DESCRIPTOR_T* fill_desc = tp->tx_cur_desc;
+
+	for (i=0; i< TX_DESC_NUM; i++)
+	{
+		fill_desc->frame_ctrl.bits_tx_out.own = CPU;
+		fill_desc->frame_ctrl.bits_tx_out.buffer_size = TX_BUF_SIZE;
+		tx_skb[dev_index][index].desc_in_use = 0;
+		free_tx_buf(dev_index, index);
+		printk("cleanup di %d\n", index);
+		fill_desc = (GMAC_DESCRIPTOR_T*)((fill_desc->next_desc.next_descriptor & 0xfffffff0) + tx_desc_virtual_base[dev_index]);
+		index++;
+		if (index > TX_DESC_NUM)
+			index = 0;
+	}
+	return 1;
+}
+
+size_t get_available_tx_desc(struct net_device* dev, int dev_index)
+{
+	struct gmac_private *tp = dev->priv;
+	unsigned int desc_hdr = tp->tx_desc_hdr[dev_index];
+	unsigned int desc_tail = tp->tx_desc_tail[dev_index];
+	int available_desc_num = (TX_DESC_NUM - desc_hdr + desc_tail) & (TX_DESC_NUM-1);
+	if (!available_desc_num) {
+		if (tx_skb[dev_index][desc_hdr].desc_in_use)
+			return 0;
+		else
+			return TX_DESC_NUM;
+	}
+	return available_desc_num;
+}
+
+int check_free_tx_desc(int dev_index, int n, GMAC_DESCRIPTOR_T* desc)
+{
+	int i,index;
+	GMAC_DESCRIPTOR_T* tmp_desc = desc;
+
+	if (n > TX_DESC_NUM)
+		return 0;
+
+	index = ((unsigned int)tmp_desc - tx_desc_start_adr[dev_index])/sizeof(GMAC_DESCRIPTOR_T);
+	for (i=0; i<n; i++)
+	{
+		if (tx_skb[dev_index][index].desc_in_use)
+		{
+			printk("sw desc %d is in use\n", index);
+			/* cleanup all the descriptors to check if DMA still running */
+			return 0;
+		}
+		index++;
+		if (index == TX_DESC_NUM)
+			index = 0;
+	}
+	return 1;
+}
+
+#define TCPHDRLEN(tcp_hdr)  ((ntohs(*((__u16 *)tcp_hdr + 6)) >> 12) & 0x000F)
+
+inline int fill_in_desc(int dev_index, GMAC_DESCRIPTOR_T *desc, char* data, int len, int total_len, int sof, int freeable, int ownership, struct sk_buff* skb)
+{
+	int index = ((unsigned int)desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+
+	if (desc->frame_ctrl.bits_tx_in.own == CPU)
+	{
+		tx_skb[dev_index][index].freeable = freeable;
+		if ((sof & 0x01) && skb) {
+			tx_skb[dev_index][index].skb = skb;
+		}
+		else
+			tx_skb[dev_index][index].skb = 0;
+
+		if (sof != 2)
+			tx_skb[dev_index][index].desc_in_use = 1;
+		else
+			tx_skb[dev_index][index].desc_in_use = 0;
+
+		consistent_sync(data, len, PCI_DMA_TODEVICE);
+		desc->buf_adr = (unsigned int)__pa(data);
+		desc->frame_ctrl.bits_tx_out.buffer_size = len;
+		desc->flag_status.bits_tx_flag.frame_count = total_len;
+		desc->next_desc.bits.eofie = 1;
+		desc->next_desc.bits.sof_eof = sof;
+		desc->frame_ctrl.bits_tx_out.vlan_enable = 0;
+		desc->frame_ctrl.bits_tx_out.ip_csum_en = 1;     /* TSS IPv4 IP header checksum enable */
+		desc->frame_ctrl.bits_tx_out.ipv6_tx_en = 1;    /* TSS IPv6 tx enable */
+		desc->frame_ctrl.bits_tx_out.tcp_csum_en = 1;    /* TSS TCP checksum enable */
+		desc->frame_ctrl.bits_tx_out.udp_csum_en = 1;    /* TSS UDP checksum enable */
+        wmb();
+		desc->frame_ctrl.bits_tx_out.own = ownership;
+//		consistent_sync(desc, sizeof(GMAC_DESCRIPTOR_T), PCI_DMA_TODEVICE);
+	}
+	return 0;
+}
+#endif
+
+static int gmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+	struct gmac_private     *tp = dev->priv;
+	GMAC_TXDMA_CTRL_T		tx_ctrl,tx_ctrl_mask;
+	GMAC_TXDMA_FIRST_DESC_T	txdma_busy;
+	unsigned int            len = skb->len;
+	unsigned int            dev_index;
+	static unsigned int     pcount = 0;
+#ifdef CONFIG_SL2312_MPAGE
+    GMAC_DESCRIPTOR_T *fill_desc;
+	int snd_pages = skb_shinfo(skb)->nr_frags;  /* get number of descriptor */
+	int desc_needed = 1; // for jumbo packet, one descriptor is enough.
+	int header_len = skb->len;
+    struct iphdr	*ip_hdr;
+    struct tcphdr	*tcp_hdr;
+    int             tcp_hdr_len;
+    int             data_len;
+    int             prv_index;
+    long            seq_num;
+    int             first_desc_index;
+    int             ownership, freeable;
+    int             eof;
+	int             i=0;
+#endif
+#ifdef CONFIG_TXINT_DISABLE
+	int				available_desc_cnt = 0;
+#endif
+
+    dev_index = gmac_select_interface(dev);
+
+#ifdef CONFIG_TXINT_DISABLE
+	available_desc_cnt = get_available_tx_desc(dev, dev_index);
+
+	if (available_desc_cnt < (TX_DESC_NUM >> 2)) {
+		gmac_tx_packet_complete(dev);
+	}
+#endif
+
+#ifdef CONFIG_SL2312_MPAGE
+
+	fill_desc = tp->tx_cur_desc;
+	if(!fill_desc) {
+		printk("cur_desc is NULL!\n");
+		return -1;
+	}
+
+	if (storlink_ctl.recvfile==2)
+	{
+	    printk("snd_pages=%d skb->len=%d\n",snd_pages,skb->len);
+	}
+
+	if (snd_pages)
+		desc_needed += snd_pages;   /* decriptors needed for this large packet */
+
+	if (!check_free_tx_desc(dev_index, desc_needed, fill_desc)) {
+		printk("no available desc!\n");
+        gmac_dump_register(dev);
+		printk_all(dev_index, tp);
+		tp->stats.tx_dropped++;
+		if (pcount++ > 10)
+		{
+		    for (;;);
+		}
+		return -1;
+	}
+
+	first_desc_index = ((unsigned int)fill_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+
+	/* check if the tcp packet is in order*/
+	ip_hdr = (struct iphdr*) &(skb->data[14]);
+	tcp_hdr = (struct tcphdr*) &(skb->data[14+ip_hdr->ihl * 4]);
+	tcp_hdr_len = TCPHDRLEN(tcp_hdr) * 4;
+	data_len = skb->len - 14 - ip_hdr->ihl *4 - tcp_hdr_len;
+
+	prv_index = first_desc_index-1;
+	if (prv_index <0)
+	    prv_index += TX_DESC_NUM;
+	seq_num = ntohl(tcp_hdr->seq);
+
+	if (snd_pages)
+	{
+		// calculate header length
+		// check fragment total length and header len = skb len - frag len
+		// or parse the header.
+		for (i=0; i<snd_pages; i++) {
+			skb_frag_t* frag = &skb_shinfo(skb)->frags[i];
+			header_len -= frag->size;
+		}
+		ownership = CPU;
+		freeable = 0;
+		/* fill header into first descriptor */
+		fill_in_desc(dev_index, fill_desc, skb->data, header_len, len, 2, freeable, ownership, 0);
+		fill_desc = (GMAC_DESCRIPTOR_T*)((fill_desc->next_desc.next_descriptor & 0xfffffff0) + tx_desc_virtual_base[dev_index]);
+		tx_skb[dev_index][first_desc_index].end_seq = seq_num + data_len;
+
+		eof = 0;
+		ownership = DMA;
+		for (i=0; i<snd_pages; i++)
+		{
+			skb_frag_t* frag = &skb_shinfo(skb)->frags[i];
+			int start_pos = frag->page_offset;
+			char* data_buf = page_address(frag->page);
+			int data_size = frag->size;
+			int cur_index;
+
+			if (i == snd_pages-1)
+			{
+				eof=1;
+				freeable = 1;
+			}
+			fill_in_desc(dev_index, fill_desc, data_buf+(start_pos), data_size,
+			             len, eof, freeable, ownership, skb);
+			cur_index = ((unsigned int)fill_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+
+			fill_desc = (GMAC_DESCRIPTOR_T*)((fill_desc->next_desc.next_descriptor & 0xfffffff0) + tx_desc_virtual_base[dev_index]);
+		}
+		/* pass the ownership of the first descriptor to hardware */
+//	    disable_irq(gmac_irq[dev_index]);
+		tx_skb[dev_index][first_desc_index].desc_in_use = 1;
+        wmb();
+		tp->tx_cur_desc->frame_ctrl.bits_tx_out.own = DMA;
+//		consistent_sync(tp->tx_cur_desc, sizeof(GMAC_DESCRIPTOR_T), PCI_DMA_TODEVICE);
+		tp->tx_cur_desc = fill_desc;
+		dev->trans_start = jiffies;
+//	    enable_irq(gmac_irq[dev_index]);
+	}
+	else if ( tp->tx_cur_desc->frame_ctrl.bits_tx_out.own == CPU )
+	{
+//		tx_skb[dev_index][first_desc_index].end_seq = seq_num + data_len;
+//	    disable_irq(gmac_irq[dev_index]);
+		fill_in_desc(dev_index, tp->tx_cur_desc, skb->data, skb->len, skb->len, 3, 1, DMA, skb);
+//	    enable_irq(gmac_irq[dev_index]);
+		//consistent_sync(tp->tx_cur_desc, sizeof(GMAC_DESCRIPTOR_T), PCI_DMA_TODEVICE);
+		tp->tx_cur_desc = (GMAC_DESCRIPTOR_T*)((tp->tx_cur_desc->next_desc.next_descriptor & 0xfffffff0) + tx_desc_virtual_base[dev_index]);
+		dev->trans_start = jiffies;
+	}
+	else
+	{
+		printk("gmac tx drop!\n");
+		tp->stats.tx_dropped++;
+		return -1;
+	}
+
+#ifdef CONFIG_TXINT_DISABLE
+	tp->tx_desc_hdr[dev_index] = (tp->tx_desc_hdr[dev_index] + desc_needed) & (TX_DESC_NUM-1);
+#endif
+
+#else
+    if ((tp->tx_cur_desc->frame_ctrl.bits_tx_out.own == CPU) && (len < TX_BUF_SIZE))
+	{
+        index = ((unsigned int)tp->tx_cur_desc - tx_desc_start_adr[dev_index]) / sizeof(GMAC_DESCRIPTOR_T);
+        tx_skb[dev_index][index] = skb;
+        consistent_sync(skb->data,skb->len,PCI_DMA_TODEVICE);
+        tp->tx_cur_desc->buf_adr = (unsigned int)__pa(skb->data);
+    	tp->tx_cur_desc->flag_status.bits_tx_flag.frame_count = len;    /* total frame byte count */
+    	tp->tx_cur_desc->next_desc.bits.sof_eof = 0x03;                 /*only one descriptor*/
+		tp->tx_cur_desc->frame_ctrl.bits_tx_out.buffer_size = len;      /* descriptor byte count */
+        tp->tx_cur_desc->frame_ctrl.bits_tx_out.vlan_enable = 0;
+        tp->tx_cur_desc->frame_ctrl.bits_tx_out.ip_csum_en = 0;     /* TSS IPv4 IP header checksum enable */
+        tp->tx_cur_desc->frame_ctrl.bits_tx_out.ipv6_tx_en = 0 ;    /* TSS IPv6 tx enable */
+        tp->tx_cur_desc->frame_ctrl.bits_tx_out.tcp_csum_en = 0;    /* TSS TCP checksum enable */
+        tp->tx_cur_desc->frame_ctrl.bits_tx_out.udp_csum_en = 0;    /* TSS UDP checksum enable */
+        wmb();
+    	tp->tx_cur_desc->frame_ctrl.bits_tx_out.own = DMA;	        /* set owner bit */
+    	tp->tx_cur_desc = (GMAC_DESCRIPTOR_T *)((tp->tx_cur_desc->next_desc.next_descriptor & 0xfffffff0)+tx_desc_virtual_base[dev_index]);
+    	dev->trans_start = jiffies;
+	}
+	else
+	{
+	 	/* no free tx descriptor */
+		dev_kfree_skb(skb);
+	    netif_stop_queue(dev);
+		tp->stats.tx_dropped++;
+		return (-1);
+	}
+#endif
+ 	/* if TX DMA process is stoped , restart it */
+	txdma_busy.bits32 = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_FIRST_DESC);
+	if (txdma_busy.bits.td_busy == 0)
+	{
+		/* restart DMA process */
+		tx_ctrl.bits32 = 0;
+		tx_ctrl.bits.td_start = 1;
+		tx_ctrl.bits.td_continue = 1;
+		tx_ctrl_mask.bits32 = 0;
+		tx_ctrl_mask.bits.td_start = 1;
+		tx_ctrl_mask.bits.td_continue = 1;
+		gmac_write_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CTRL,tx_ctrl.bits32,tx_ctrl_mask.bits32);
+	}
+	return (0);
+}
+
+
+struct net_device_stats * gmac_get_stats(struct net_device *dev)
+{
+    struct gmac_private *tp = dev->priv;
+    unsigned long       flags;
+    unsigned int        pkt_drop;
+    unsigned int        pkt_error;
+    unsigned int        dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+//	if (storlink_ctl.recvfile==3)
+//	{
+//        printk("GMAC_GLOBAL_BASE_ADDR=%x\n", readl(GMAC_GLOBAL_BASE_ADDR+0x30));
+//        gmac_dump_register(dev);
+//        printk_all(0, dev);
+//    }
+
+    if (netif_running(dev))
+    {
+        /* read H/W counter */
+        spin_lock_irqsave(&tp->lock,flags);
+        pkt_drop = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_IN_DISCARDS);
+        pkt_error = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_IN_ERRORS);
+        tp->stats.rx_dropped = tp->stats.rx_dropped + pkt_drop;
+        tp->stats.rx_errors = tp->stats.rx_errors + pkt_error;
+        spin_unlock_irqrestore(&tp->lock,flags);
+    }
+    return &tp->stats;
+}
+
+static unsigned const ethernet_polynomial = 0x04c11db7U;
+static inline u32 ether_crc (int length, unsigned char *data)
+{
+	int crc = -1;
+	unsigned int i;
+	unsigned int crc_val=0;
+
+	while (--length >= 0) {
+		unsigned char current_octet = *data++;
+		int bit;
+		for (bit = 0; bit < 8; bit++, current_octet >>= 1)
+			crc = (crc << 1) ^ ((crc < 0) ^ (current_octet & 1) ?
+			     ethernet_polynomial : 0);
+	}
+	crc = ~crc;
+	for (i=0;i<32;i++)
+	{
+		crc_val = crc_val + (((crc << i) & 0x80000000) >> (31-i));
+	}
+	return crc_val;
+}
+
+static void gmac_set_rx_mode(struct net_device *dev)
+{
+    GMAC_RX_FLTR_T      filter;
+	unsigned int        mc_filter[2];	/* Multicast hash filter */
+    int                 bit_nr;
+	unsigned int        i, dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+//    printk("%s : dev->flags = %x \n",__func__,dev->flags);
+//    dev->flags |= IFF_ALLMULTI;  /* temp */
+    filter.bits32 = 0;
+    filter.bits.error = 0;
+	if (dev->flags & IFF_PROMISC)
+	{
+	    filter.bits.error = 1;
+        filter.bits.promiscuous = 1;
+        filter.bits.broadcast = 1;
+        filter.bits.multicast = 1;
+        filter.bits.unicast = 1;
+		mc_filter[1] = mc_filter[0] = 0xffffffff;
+	}
+	else if (dev->flags & IFF_ALLMULTI)
+	{
+        filter.bits.promiscuous = 1;
+        filter.bits.broadcast = 1;
+        filter.bits.multicast = 1;
+        filter.bits.unicast = 1;
+		mc_filter[1] = mc_filter[0] = 0xffffffff;
+	}
+	else
+	{
+		struct dev_mc_list *mclist;
+
+        filter.bits.promiscuous = 1;
+        filter.bits.broadcast = 1;
+        filter.bits.multicast = 1;
+        filter.bits.unicast = 1;
+		mc_filter[1] = mc_filter[0] = 0;
+		for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;i++, mclist = mclist->next)
+		{
+            bit_nr = ether_crc(ETH_ALEN,mclist->dmi_addr) & 0x0000003f;
+            if (bit_nr < 32)
+            {
+                mc_filter[0] = mc_filter[0] | (1<<bit_nr);
+            }
+            else
+            {
+                mc_filter[1] = mc_filter[1] | (1<<(bit_nr-32));
+            }
+		}
+	}
+    filter.bits32 = 0x1f;
+    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_RX_FLTR,filter.bits32,0xffffffff);
+
+    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_MCAST_FIL0,mc_filter[0],0xffffffff);
+    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_MCAST_FIL1,mc_filter[1],0xffffffff);
+    return;
+}
+
+static int gmac_set_mac_address(struct net_device *dev, void *addr)
+{
+	struct sockaddr *sock;
+	unsigned int    reg_val;
+	unsigned int    dev_index;
+    unsigned int    i;
+
+    dev_index = gmac_select_interface(dev);
+
+	sock = (struct sockaddr *) addr;
+	for (i = 0; i < 6; i++)
+	{
+		dev->dev_addr[i] = sock->sa_data[i];
+	}
+
+    reg_val = dev->dev_addr[0] + (dev->dev_addr[1]<<8) + (dev->dev_addr[2]<<16) + (dev->dev_addr[3]<<24);
+    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_STA_ADD0,reg_val,0xffffffff);
+    reg_val = dev->dev_addr[4] + (dev->dev_addr[5]<<8) ;
+    gmac_write_reg(gmac_base_addr[dev_index] + GMAC_STA_ADD1,reg_val,0x0000ffff);
+    memcpy(&eth0_mac[0],&dev->dev_addr[0],6);
+    printk("Storlink %s address = ",dev->name);
+    printk("%02x",dev->dev_addr[0]);
+    printk("%02x",dev->dev_addr[1]);
+    printk("%02x",dev->dev_addr[2]);
+    printk("%02x",dev->dev_addr[3]);
+    printk("%02x",dev->dev_addr[4]);
+    printk("%02x\n",dev->dev_addr[5]);
+
+    return (0);
+}
+
+static void gmac_tx_timeout(struct net_device *dev)
+{
+	GMAC_TXDMA_CTRL_T	        tx_ctrl,tx_ctrl_mask;
+    GMAC_TXDMA_FIRST_DESC_T     txdma_busy;
+    int							dev_index;
+
+    dev_index = gmac_select_interface(dev);
+
+    /* if TX DMA process is stoped , restart it */
+	txdma_busy.bits32 = gmac_read_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_FIRST_DESC);
+	if (txdma_busy.bits.td_busy == 0)
+	{
+		/* restart DMA process */
+		tx_ctrl.bits32 = 0;
+		tx_ctrl.bits.td_start = 1;
+		tx_ctrl.bits.td_continue = 1;
+		tx_ctrl_mask.bits32 = 0;
+		tx_ctrl_mask.bits.td_start = 1;
+		tx_ctrl_mask.bits.td_continue = 1;
+		gmac_write_reg(gmac_base_addr[dev_index] + GMAC_TXDMA_CTRL,tx_ctrl.bits32,tx_ctrl_mask.bits32);
+	}
+	netif_wake_queue(dev);
+    return;
+}
+
+static int gmac_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+{
+	int rc = 0;
+    unsigned char *hwa = rq->ifr_ifru.ifru_hwaddr.sa_data;
+
+	if (!netif_running(dev))
+	{
+	    printk("Before changing the H/W address,please down the device.\n");
+		return -EINVAL;
+    }
+
+	switch (cmd) {
+	case SIOCETHTOOL:
+        break;
+
+    case SIOCSIFHWADDR:
+        gmac_set_mac_address(dev,hwa);
+        break;
+
+	case SIOCGMIIPHY:	/* Get the address of the PHY in use. */
+	case SIOCDEVPRIVATE:	/* binary compat, remove in 2.5 */
+        break;
+
+	case SIOCGMIIREG:	/* Read the specified MII register. */
+	case SIOCDEVPRIVATE+1:
+		break;
+
+	case SIOCSMIIREG:	/* Write the specified MII register */
+	case SIOCDEVPRIVATE+2:
+		break;
+
+	default:
+		rc = -EOPNOTSUPP;
+		break;
+	}
+
+	return rc;
+}
+
+static void gmac_cleanup_module(void)
+{
+    int i;
+
+    for (i=0;i<GMAC_PHY_IF;i++)
+    {
+        unregister_netdev(gmac_dev[i]);
+    }
+	return ;
+}
+
+static int __init gmac_init_module(void)
+{
+	struct gmac_private *tp;
+	struct net_device *dev[GMAC_PHY_IF];
+	unsigned int i;
+
+#ifdef MODULE
+	printk (KERN_INFO RTL8139_DRIVER_NAME "\n");
+#endif
+//	init_waitqueue_entry(&wait, current);
+
+	printk("GMAC Init......\n");
+	for(i = 0; i<GMAC_PHY_IF; i++)
+	{
+		dev[i] = alloc_etherdev(sizeof(struct gmac_private));
+		if (dev[i] == NULL)
+		{
+			printk (KERN_ERR "Can't allocate ethernet device #%d .\n",i);
+			return -ENOMEM;
+		}
+        gmac_dev[i] = dev[i];
+
+		SET_MODULE_OWNER(dev[i]);
+
+		tp = dev[i]->priv;
+
+		dev[i]->base_addr = gmac_base_addr[i];
+		dev[i]->irq = gmac_irq[i];
+	    dev[i]->open = gmac_open;
+	    dev[i]->stop = gmac_close;
+		dev[i]->hard_start_xmit = gmac_start_xmit;
+		dev[i]->get_stats = gmac_get_stats;
+		dev[i]->set_multicast_list = gmac_set_rx_mode;
+		dev[i]->set_mac_address = gmac_set_mac_address;
+		dev[i]->do_ioctl = gmac_netdev_ioctl;
+		dev[i]->tx_timeout = gmac_tx_timeout;
+		dev[i]->watchdog_timeo = TX_TIMEOUT;
+		dev[i]->features |= NETIF_F_SG|NETIF_F_HW_CSUM|NETIF_F_TSO;
+#ifdef CONFIG_SL_NAPI
+        printk("NAPI driver is enabled.\n");
+        if (i==0)
+        {
+	        dev[i]->poll = gmac_rx_poll_ga;
+	        dev[i]->weight = 64;
+	    }
+	    else
+	    {
+	        dev[i]->poll = gmac_rx_poll_gb;
+	        dev[i]->weight = 64;
+	    }
+#endif
+
+		if (register_netdev(dev[i]))
+		{
+			gmac_cleanup_module();
+			return(-1);
+		}
+	}
+
+#ifdef CONFIG_SL3516_ASIC
+{
+    unsigned int    val;
+
+    /* set GMAC global register */
+    val = readl(GMAC_GLOBAL_BASE_ADDR+0x10);
+    val = val | 0x005a0000;
+    writel(val,GMAC_GLOBAL_BASE_ADDR+0x10);
+    writel(0x07f007f0,GMAC_GLOBAL_BASE_ADDR+0x1c);
+    writel(0x77770000,GMAC_GLOBAL_BASE_ADDR+0x20);
+    writel(0x77770000,GMAC_GLOBAL_BASE_ADDR+0x24);
+	val = readl(GMAC_GLOBAL_BASE_ADDR+0x04);
+	if((val&(1<<20))==0){           // GMAC1 enable
+ 		val = readl(GMAC_GLOBAL_BASE_ADDR+0x30);
+		val = (val & 0xe7ffffff) | 0x08000000;
+		writel(val,GMAC_GLOBAL_BASE_ADDR+0x30);
+	}
+
+}
+#endif
+
+//	printk("%s: dev0=%x  dev1=%x \n",__func__,dev[0],dev[1]);
+//	FLAG_SWITCH = 0 ;
+//	FLAG_SWITCH = SPI_get_identifier();
+//	if(FLAG_SWITCH)
+//	{
+//		printk("Configure ADM699X...\n");
+//		SPI_default();	//Add by jason for ADM699X configuration
+//	}
+	return (0);
+}
+
+
+module_init(gmac_init_module);
+module_exit(gmac_cleanup_module);
+
+static int gmac_phy_thread (void *data)
+{
+	struct net_device   *dev = data;
+	struct gmac_private *tp = dev->priv;
+	unsigned long       timeout;
+
+    daemonize("%s", dev->name);
+	allow_signal(SIGTERM);
+//	reparent_to_init();
+//	spin_lock_irq(&current->sigmask_lock);
+//	sigemptyset(&current->blocked);
+//	recalc_sigpending(current);
+//	spin_unlock_irq(&current->sigmask_lock);
+//	strncpy (current->comm, dev->name, sizeof(current->comm) - 1);
+//	current->comm[sizeof(current->comm) - 1] = '\0';
+
+	while (1)
+	{
+	    timeout = next_tick;
+		do
+		{
+			timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout);
+		} while (!signal_pending (current) && (timeout > 0));
+
+		if (signal_pending (current))
+		{
+//			spin_lock_irq(&current->sigmask_lock);
+			flush_signals(current);
+//			spin_unlock_irq(&current->sigmask_lock);
+		}
+
+		if (tp->time_to_die)
+			break;
+
+//        printk("%s : Polling PHY Status...%x\n",__func__,dev);
+		rtnl_lock ();
+        gmac_get_phy_status(dev);
+		rtnl_unlock ();
+	}
+	complete_and_exit (&tp->thr_exited, 0);
+}
+
+static void gmac_set_phy_status(struct net_device *dev)
+{
+    GMAC_STATUS_T   status;
+    unsigned int    reg_val;
+    unsigned int    i = 0;
+    unsigned int    index;
+
+    if (FLAG_SWITCH==1)
+    {
+        return; /* GMAC connects to a switch chip, not PHY */
+    }
+
+    index = gmac_get_dev_index(dev);
+
+    if (index == 0)
+    {
+//    	mii_write(phy_addr[index],0x04,0x0461); /* advertisement 10M full duplex, pause capable on */
+//    	mii_write(phy_addr[index],0x04,0x0421); /* advertisement 10M half duplex, pause capable on */
+    	mii_write(phy_addr[index],0x04,0x05e1); /* advertisement 100M full duplex, pause capable on */
+//    	mii_write(phy_addr[index],0x04,0x04a1); /* advertisement 100M half duplex, pause capable on */
+#ifdef CONFIG_SL3516_ASIC
+    	mii_write(phy_addr[index],0x09,0x0300); /* advertisement 1000M full duplex, pause capable on */
+//    	mii_write(phy_addr[index],0x09,0x0000); /* advertisement 1000M full duplex, pause capable on */
+#endif
+    }
+    else
+    {
+//    	mii_write(phy_addr[index],0x04,0x0461); /* advertisement 10M full duplex, pause capable on */
+//    	mii_write(phy_addr[index],0x04,0x0421); /* advertisement 10M half duplex, pause capable on */
+    	mii_write(phy_addr[index],0x04,0x05e1); /* advertisement 100M full duplex, pause capable on */
+//    	mii_write(phy_addr[index],0x04,0x04a1); /* advertisement 100M half duplex, pause capable on */
+#ifdef CONFIG_SL3516_ASIC
+//    	mii_write(phy_addr[index],0x09,0x0000); /* advertisement no 1000M */
+    	mii_write(phy_addr[index],0x09,0x0300); /* advertisement 1000M full duplex, pause capable on */
+#endif
+	}
+
+    mii_write(phy_addr[index],0x00,0x1200); /* Enable and Restart Auto-Negotiation */
+    mii_write(phy_addr[index],0x18,0x0041); /* Enable Active led */
+    while (((reg_val=mii_read(phy_addr[index],0x01)) & 0x00000004)!=0x04)
+    {
+        i++;
+        if (i > 30)
+        {
+            break;
+        }
+	msleep(100);
+    }
+    if (i>30)
+    {
+        pre_phy_status[index] = LINK_DOWN;
+		clear_bit(__LINK_STATE_START, &dev->state);
+        netif_stop_queue(dev);
+        storlink_ctl.link = 0;
+        printk("Link Down (%04x) ",reg_val);
+    }
+    else
+    {
+        pre_phy_status[index] = LINK_UP;
+		set_bit(__LINK_STATE_START, &dev->state);
+        netif_wake_queue(dev);
+        storlink_ctl.link = 1;
+        printk("Link Up (%04x) ",reg_val);
+    }
+
+    status.bits32 = 0;
+    reg_val = mii_read(phy_addr[index],10);
+    printk("reg_val0 = %x \n",reg_val);
+    if ((reg_val & 0x0800) == 0x0800)
+    {
+        status.bits.duplex = 1;
+        status.bits.speed = 2;
+        printk(" 1000M/Full \n");
+    }
+    else if ((reg_val & 0x0400) == 0x0400)
+    {
+        status.bits.duplex = 0;
+        status.bits.speed = 2;
+        printk(" 1000M/Half \n");
+    }
+    else
+    {
+        reg_val = (mii_read(phy_addr[index],0x05) & 0x05E0) >> 5;
+        printk("reg_val1 = %x \n",reg_val);
+        if ((reg_val & 0x08)==0x08) /* 100M full duplex */
+        {
+                status.bits.duplex = 1;
+                status.bits.speed = 1;
+                printk(" 100M/Full \n");
+        }
+        else if ((reg_val & 0x04)==0x04) /* 100M half duplex */
+        {
+                status.bits.duplex = 0;
+                status.bits.speed = 1;
+                printk(" 100M/Half \n");
+        }
+        else if ((reg_val & 0x02)==0x02) /* 10M full duplex */
+        {
+                status.bits.duplex = 1;
+                status.bits.speed = 0;
+                printk(" 10M/Full \n");
+        }
+        else if ((reg_val & 0x01)==0x01) /* 10M half duplex */
+        {
+                status.bits.duplex = 0;
+                status.bits.speed = 0;
+                printk(" 100M/Half \n");
+        }
+    }
+
+    reg_val = (mii_read(phy_addr[index],0x05) & 0x05E0) >> 5;
+    if ((reg_val & 0x20)==0x20)
+    {
+        flow_control_enable[index] = 1;
+        printk("Flow Control Enable. \n");
+    }
+    else
+    {
+        flow_control_enable[index] = 0;
+        printk("Flow Control Disable. \n");
+    }
+    full_duplex = status.bits.duplex;
+    speed = status.bits.speed;
+}
+
+static void gmac_get_phy_status(struct net_device *dev)
+{
+	GMAC_CONFIG0_T	config0,config0_mask;
+    GMAC_STATUS_T   status;
+    unsigned int    reg_val;
+    unsigned int    index;
+
+    index = gmac_select_interface(dev);
+
+    status.bits32 = 0;
+    status.bits.phy_mode = 1;
+
+#ifdef CONFIG_SL3516_ASIC
+    status.bits.mii_rmii = 2;   /* default value for ASIC version */
+//    status.bits.speed = 1;
+#else
+    if (index==0)
+        status.bits.mii_rmii = 0;
+    else
+        status.bits.mii_rmii = 2;
+#endif
+
+    /* read PHY status register */
+    reg_val = mii_read(phy_addr[index],0x01);
+    if ((reg_val & 0x0024) == 0x0024) /* link is established and auto_negotiate process completed */
+    {
+        /* read PHY Auto-Negotiation Link Partner Ability Register */
+        reg_val = mii_read(phy_addr[index],10);
+        if ((reg_val & 0x0800) == 0x0800)
+        {
+            status.bits.mii_rmii = 3;  /* RGMII 1000Mbps mode */
+            status.bits.duplex = 1;
+            status.bits.speed = 2;
+        }
+        else if ((reg_val & 0x0400) == 0x0400)
+        {
+            status.bits.mii_rmii = 3;  /* RGMII 1000Mbps mode */
+            status.bits.duplex = 0;
+            status.bits.speed = 2;
+        }
+        else
+        {
+            reg_val = (mii_read(phy_addr[index],0x05) & 0x05E0) >> 5;
+            if ((reg_val & 0x08)==0x08) /* 100M full duplex */
+            {
+                    status.bits.mii_rmii = 2;  /* RGMII 10/100Mbps mode */
+                    status.bits.duplex = 1;
+                    status.bits.speed = 1;
+            }
+            else if ((reg_val & 0x04)==0x04) /* 100M half duplex */
+            {
+                    status.bits.mii_rmii = 2;  /* RGMII 10/100Mbps mode */
+                    status.bits.duplex = 0;
+                    status.bits.speed = 1;
+            }
+            else if ((reg_val & 0x02)==0x02) /* 10M full duplex */
+            {
+                    status.bits.mii_rmii = 2;  /* RGMII 10/100Mbps mode */
+                    status.bits.duplex = 1;
+                    status.bits.speed = 0;
+            }
+            else if ((reg_val & 0x01)==0x01) /* 10M half duplex */
+            {
+                    status.bits.mii_rmii = 2;  /* RGMII 10/100Mbps mode */
+                    status.bits.duplex = 0;
+                    status.bits.speed = 0;
+            }
+        }
+        status.bits.link = LINK_UP; /* link up */
+        netif_wake_queue(dev);
+
+        reg_val = (mii_read(phy_addr[index],0x05) & 0x05E0) >> 5;
+        if ((reg_val & 0x20)==0x20)
+        {
+            if (flow_control_enable[index] == 0)
+            {
+                config0.bits32 = 0;
+                config0_mask.bits32 = 0;
+                config0.bits.tx_fc_en = 1; /* enable tx flow control */
+                config0.bits.rx_fc_en = 1; /* enable rx flow control */
+                config0_mask.bits.tx_fc_en = 1;
+                config0_mask.bits.rx_fc_en = 1;
+                gmac_write_reg(gmac_base_addr[index] + GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+//                printk("eth%d Flow Control Enable. \n",index);
+            }
+            flow_control_enable[index] = 1;
+        }
+        else
+        {
+            if (flow_control_enable[index] == 1)
+            {
+                config0.bits32 = 0;
+                config0_mask.bits32 = 0;
+                config0.bits.tx_fc_en = 0; /* disable tx flow control */
+                config0.bits.rx_fc_en = 0; /* disable rx flow control */
+                config0_mask.bits.tx_fc_en = 1;
+                config0_mask.bits.rx_fc_en = 1;
+                gmac_write_reg(gmac_base_addr[index] + GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+//                printk("eth%d Flow Control Disable. \n",index);
+            }
+            flow_control_enable[index] = 0;
+        }
+
+        if (pre_phy_status[index] == LINK_DOWN)
+        {
+            gmac_enable_tx_rx(dev);
+            pre_phy_status[index] = LINK_UP;
+			set_bit(__LINK_STATE_START, &dev->state);
+			storlink_ctl.link = 1;
+//			printk("eth%d Link Up ...\n",index);
+        }
+    }
+    else
+    {
+        status.bits.link = LINK_DOWN; /* link down */
+        netif_stop_queue(dev);
+        flow_control_enable[index] = 0;
+        storlink_ctl.link = 0;
+        if (pre_phy_status[index] == LINK_UP)
+        {
+            gmac_disable_tx_rx(dev);
+            pre_phy_status[index] = LINK_DOWN;
+			clear_bit(__LINK_STATE_START, &dev->state);
+//			printk("eth%d Link Down ...\n",index);
+    	}
+
+    }
+
+    reg_val = gmac_read_reg(gmac_base_addr[index] + GMAC_STATUS);
+    if (reg_val != status.bits32)
+    {
+        gmac_write_reg(gmac_base_addr[index] + GMAC_STATUS,status.bits32,0x0000007f);
+    }
+}
+
+/***************************************/
+/* define GPIO module base address     */
+/***************************************/
+#define GPIO_BASE_ADDR  (IO_ADDRESS(SL2312_GPIO_BASE))
+
+/* define GPIO pin for MDC/MDIO */
+
+// for gemini ASIC
+#ifdef CONFIG_SL3516_ASIC
+#define H_MDC_PIN           22
+#define H_MDIO_PIN          21
+#define G_MDC_PIN           22
+#define G_MDIO_PIN          21
+#else
+#define H_MDC_PIN           3
+#define H_MDIO_PIN          2
+#define G_MDC_PIN           0
+#define G_MDIO_PIN          1
+#endif
+
+//#define GPIO_MDC             0x80000000
+//#define GPIO_MDIO            0x00400000
+
+static unsigned int GPIO_MDC = 0;
+static unsigned int GPIO_MDIO = 0;
+static unsigned int GPIO_MDC_PIN = 0;
+static unsigned int GPIO_MDIO_PIN = 0;
+
+// For PHY test definition!!
+#define LPC_EECK		0x02
+#define LPC_EDIO		0x04
+#define LPC_GPIO_SET		3
+#define LPC_BASE_ADDR		IO_ADDRESS(IT8712_IO_BASE)
+#define inb_gpio(x)		inb(LPC_BASE_ADDR + IT8712_GPIO_BASE + x)
+#define outb_gpio(x, y)		outb(y, LPC_BASE_ADDR + IT8712_GPIO_BASE + x)
+
+enum GPIO_REG
+{
+    GPIO_DATA_OUT   = 0x00,
+    GPIO_DATA_IN    = 0x04,
+    GPIO_PIN_DIR    = 0x08,
+    GPIO_BY_PASS    = 0x0c,
+    GPIO_DATA_SET   = 0x10,
+    GPIO_DATA_CLEAR = 0x14,
+};
+/***********************/
+/*    MDC : GPIO[31]   */
+/*    MDIO: GPIO[22]   */
+/***********************/
+
+/***************************************************
+* All the commands should have the frame structure:
+*<PRE><ST><OP><PHYAD><REGAD><TA><DATA><IDLE>
+****************************************************/
+
+/*****************************************************************
+* Inject a bit to NWay register through CSR9_MDC,MDIO
+*******************************************************************/
+void mii_serial_write(char bit_MDO) // write data into mii PHY
+{
+#if 0 //def CONFIG_SL2312_LPC_IT8712
+	unsigned char iomode,status;
+
+	iomode = LPCGetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET);
+	iomode |= (LPC_EECK|LPC_EDIO) ;				// Set EECK,EDIO,EECS output
+	LPCSetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET, iomode);
+
+	if(bit_MDO)
+	{
+		status = inb_gpio( LPC_GPIO_SET);
+		status |= LPC_EDIO ;		//EDIO high
+		outb_gpio(LPC_GPIO_SET, status);
+	}
+	else
+	{
+		status = inb_gpio( LPC_GPIO_SET);
+		status &= ~(LPC_EDIO) ;		//EDIO low
+		outb_gpio(LPC_GPIO_SET, status);
+	}
+
+	status |= LPC_EECK ;		//EECK high
+	outb_gpio(LPC_GPIO_SET, status);
+
+	status &= ~(LPC_EECK) ;		//EECK low
+	outb_gpio(LPC_GPIO_SET, status);
+
+#else
+    unsigned int addr;
+    unsigned int value;
+
+    addr = GPIO_BASE_ADDR + GPIO_PIN_DIR;
+    value = readl(addr) | GPIO_MDC | GPIO_MDIO; /* set MDC/MDIO Pin to output */
+    writel(value,addr);
+    if(bit_MDO)
+    {
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+        writel(GPIO_MDIO,addr); /* set MDIO to 1 */
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+        writel(GPIO_MDC,addr); /* set MDC to 1 */
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+        writel(GPIO_MDC,addr); /* set MDC to 0 */
+    }
+    else
+    {
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+        writel(GPIO_MDIO,addr); /* set MDIO to 0 */
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+        writel(GPIO_MDC,addr); /* set MDC to 1 */
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+        writel(GPIO_MDC,addr); /* set MDC to 0 */
+    }
+
+#endif
+}
+
+/**********************************************************************
+* read a bit from NWay register through CSR9_MDC,MDIO
+***********************************************************************/
+unsigned int mii_serial_read(void) // read data from mii PHY
+{
+#if 0 //def CONFIG_SL2312_LPC_IT8712
+  	unsigned char iomode,status;
+	unsigned int value ;
+
+	iomode = LPCGetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET);
+	iomode &= ~(LPC_EDIO) ;		// Set EDIO input
+	iomode |= (LPC_EECK) ;		// Set EECK,EECS output
+	LPCSetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET, iomode);
+
+	status = inb_gpio( LPC_GPIO_SET);
+	status |= LPC_EECK ;		//EECK high
+	outb_gpio(LPC_GPIO_SET, status);
+
+	status &= ~(LPC_EECK) ;		//EECK low
+	outb_gpio(LPC_GPIO_SET, status);
+
+	value = inb_gpio( LPC_GPIO_SET);
+
+	value = value>>2 ;
+	value &= 0x01;
+
+	return value ;
+
+#else
+    unsigned int *addr;
+    unsigned int value;
+
+    addr = (unsigned int *)(GPIO_BASE_ADDR + GPIO_PIN_DIR);
+    value = readl(addr) & ~GPIO_MDIO; //0xffbfffff;   /* set MDC to output and MDIO to input */
+    writel(value,addr);
+
+    addr = (unsigned int *)(GPIO_BASE_ADDR + GPIO_DATA_SET);
+    writel(GPIO_MDC,addr); /* set MDC to 1 */
+    addr = (unsigned int *)(GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+    writel(GPIO_MDC,addr); /* set MDC to 0 */
+
+    addr = (unsigned int *)(GPIO_BASE_ADDR + GPIO_DATA_IN);
+    value = readl(addr);
+    value = (value & (1<<GPIO_MDIO_PIN)) >> GPIO_MDIO_PIN;
+    return(value);
+
+#endif
+}
+
+/***************************************
+* preamble + ST
+***************************************/
+void mii_pre_st(void)
+{
+    unsigned char i;
+
+    for(i=0;i<32;i++) // PREAMBLE
+        mii_serial_write(1);
+    mii_serial_write(0); // ST
+    mii_serial_write(1);
+}
+
+
+/******************************************
+* Read MII register
+* phyad -> physical address
+* regad -> register address
+***************************************** */
+unsigned int mii_read(unsigned char phyad,unsigned char regad)
+{
+    unsigned int i,value;
+    unsigned int bit;
+
+    if (phyad == GPHY_ADDR)
+    {
+        GPIO_MDC_PIN = G_MDC_PIN;   /* assigned MDC pin for giga PHY */
+        GPIO_MDIO_PIN = G_MDIO_PIN; /* assigned MDIO pin for giga PHY */
+    }
+    else
+    {
+        GPIO_MDC_PIN = H_MDC_PIN;   /* assigned MDC pin for 10/100 PHY */
+        GPIO_MDIO_PIN = H_MDIO_PIN; /* assigned MDIO pin for 10/100 PHY */
+    }
+    GPIO_MDC = (1<<GPIO_MDC_PIN);
+    GPIO_MDIO = (1<<GPIO_MDIO_PIN);
+
+    mii_pre_st(); // PRE+ST
+    mii_serial_write(1); // OP
+    mii_serial_write(0);
+
+    for (i=0;i<5;i++) { // PHYAD
+        bit= ((phyad>>(4-i)) & 0x01) ? 1 :0 ;
+        mii_serial_write(bit);
+    }
+
+    for (i=0;i<5;i++) { // REGAD
+        bit= ((regad>>(4-i)) & 0x01) ? 1 :0 ;
+        mii_serial_write(bit);
+    }
+
+    mii_serial_read(); // TA_Z
+//    if((bit=mii_serial_read()) !=0 ) // TA_0
+//    {
+//        return(0);
+//    }
+    value=0;
+    for (i=0;i<16;i++) { // READ DATA
+        bit=mii_serial_read();
+        value += (bit<<(15-i)) ;
+    }
+
+    mii_serial_write(0); // dumy clock
+    mii_serial_write(0); // dumy clock
+//printk("%s: phy_addr=%x reg_addr=%x value=%x \n",__func__,phyad,regad,value);
+    return(value);
+}
+
+/******************************************
+* Write MII register
+* phyad -> physical address
+* regad -> register address
+* value -> value to be write
+***************************************** */
+void mii_write(unsigned char phyad,unsigned char regad,unsigned int value)
+{
+    unsigned int i;
+    char bit;
+
+printk("%s: phy_addr=%x reg_addr=%x value=%x \n",__func__,phyad,regad,value);
+    if (phyad == GPHY_ADDR)
+    {
+        GPIO_MDC_PIN = G_MDC_PIN;   /* assigned MDC pin for giga PHY */
+        GPIO_MDIO_PIN = G_MDIO_PIN; /* assigned MDIO pin for giga PHY */
+    }
+    else
+    {
+        GPIO_MDC_PIN = H_MDC_PIN;   /* assigned MDC pin for 10/100 PHY */
+        GPIO_MDIO_PIN = H_MDIO_PIN; /* assigned MDIO pin for 10/100 PHY */
+    }
+    GPIO_MDC = (1<<GPIO_MDC_PIN);
+    GPIO_MDIO = (1<<GPIO_MDIO_PIN);
+
+    mii_pre_st(); // PRE+ST
+    mii_serial_write(0); // OP
+    mii_serial_write(1);
+    for (i=0;i<5;i++) { // PHYAD
+        bit= ((phyad>>(4-i)) & 0x01) ? 1 :0 ;
+        mii_serial_write(bit);
+    }
+
+    for (i=0;i<5;i++) { // REGAD
+        bit= ((regad>>(4-i)) & 0x01) ? 1 :0 ;
+        mii_serial_write(bit);
+    }
+    mii_serial_write(1); // TA_1
+    mii_serial_write(0); // TA_0
+
+    for (i=0;i<16;i++) { // OUT DATA
+        bit= ((value>>(15-i)) & 0x01) ? 1 : 0 ;
+        mii_serial_write(bit);
+    }
+    mii_serial_write(0); // dumy clock
+    mii_serial_write(0); // dumy clock
+}
+
+
+
+
+
+
+
+
+
+/*				NOTES
+ *   The instruction set of the 93C66/56/46/26/06 chips are as follows:
+ *
+ *               Start  OP	    *
+ *     Function   Bit  Code  Address**  Data     Description
+ *     -------------------------------------------------------------------
+ *     READ        1    10   A7 - A0             Reads data stored in memory,
+ *                                               starting at specified address
+ *     EWEN        1    00   11XXXXXX            Write enable must precede
+ *                                               all programming modes
+ *     ERASE       1    11   A7 - A0             Erase register A7A6A5A4A3A2A1A0
+ *     WRITE       1    01   A7 - A0   D15 - D0  Writes register
+ *     ERAL        1    00   10XXXXXX            Erase all registers
+ *     WRAL        1    00   01XXXXXX  D15 - D0  Writes to all registers
+ *     EWDS        1    00   00XXXXXX            Disables all programming
+ *                                               instructions
+ *    *Note: A value of X for address is a don't care condition.
+ *    **Note: There are 8 address bits for the 93C56/66 chips unlike
+ *	      the 93C46/26/06 chips which have 6 address bits.
+ *
+ *   The 93Cx6 has a four wire interface: clock, chip select, data in, and
+ *   data out.While the ADM6996 uning three interface: clock, chip select,and data line.
+ *   The input and output are the same pin. ADM6996 can only recognize the write cmd.
+ *   In order to perform above functions, you need
+ *   1. to enable the chip select .
+ *   2. send one clock of dummy clock
+ *   3. send start bit and opcode
+ *   4. send 8 bits address and 16 bits data
+ *   5. to disable the chip select.
+ *							Jason Lee 2003/07/30
+ */
+
+/***************************************/
+/* define GPIO module base address     */
+/***************************************/
+#define GPIO_EECS	     0x00400000		/*   EECS: GPIO[22]   */
+//#define GPIO_MOSI	     0x20000000         /*   EEDO: GPIO[29]   send to 6996*/
+#define GPIO_MISO	     0x40000000         /*   EEDI: GPIO[30]   receive from 6996*/
+#define GPIO_EECK	     0x80000000         /*   EECK: GPIO[31]   */
+
+#define ADM_EECS		0x01
+#define ADM_EECK		0x02
+#define ADM_EDIO		0x04
+/*************************************************************
+* SPI protocol for ADM6996 control
+**************************************************************/
+#define SPI_OP_LEN	     0x03		// the length of start bit and opcode
+#define SPI_OPWRITE	     0X05		// write
+#define SPI_OPREAD	     0X06		// read
+#define SPI_OPERASE	     0X07		// erase
+#define SPI_OPWTEN	     0X04		// write enable
+#define SPI_OPWTDIS	     0X04		// write disable
+#define SPI_OPERSALL	     0X04		// erase all
+#define SPI_OPWTALL	     0X04		// write all
+
+#define SPI_ADD_LEN	     8			// bits of Address
+#define SPI_DAT_LEN	     16			// bits of Data
+#define ADM6996_PORT_NO	     6			// the port number of ADM6996
+#define ADM6999_PORT_NO	     9			// the port number of ADM6999
+#ifdef CONFIG_ADM_6996
+	#define ADM699X_PORT_NO		ADM6996_PORT_NO
+#endif
+#ifdef CONFIG_ADM_6999
+	#define ADM699X_PORT_NO		ADM6999_PORT_NO
+#endif
+#define LPC_GPIO_SET		3
+#define LPC_BASE_ADDR			IO_ADDRESS(IT8712_IO_BASE)
+
+extern int it8712_exist;
+
+#define inb_gpio(x)			inb(LPC_BASE_ADDR + IT8712_GPIO_BASE + x)
+#define outb_gpio(x, y)		outb(y, LPC_BASE_ADDR + IT8712_GPIO_BASE + x)
+
+/****************************************/
+/*	Function Declare		*/
+/****************************************/
+/*
+void SPI_write(unsigned char addr,unsigned int value);
+unsigned int SPI_read(unsigned char table,unsigned char addr);
+void SPI_write_bit(char bit_EEDO);
+unsigned int SPI_read_bit(void);
+void SPI_default(void);
+void SPI_reset(unsigned char rstype,unsigned char port_cnt);
+void SPI_pre_st(void);
+void SPI_CS_enable(unsigned char enable);
+void SPI_Set_VLAN(unsigned char LAN,unsigned int port_mask);
+void SPI_Set_tag(unsigned int port,unsigned tag);
+void SPI_Set_PVID(unsigned int PVID,unsigned int port_mask);
+void SPI_mac_lock(unsigned int port, unsigned char lock);
+void SPI_get_port_state(unsigned int port);
+void SPI_port_enable(unsigned int port,unsigned char enable);
+
+void SPI_get_status(unsigned int port);
+*/
+
+struct PORT_CONFIG
+{
+	unsigned char auto_negotiation;	// 0:Disable	1:Enable
+	unsigned char speed;		// 0:10M	1:100M
+	unsigned char duplex;		// 0:Half	1:Full duplex
+	unsigned char Tag;		// 0:Untag	1:Tag
+	unsigned char port_disable;	// 0:port enable	1:disable
+	unsigned char pvid;		// port VLAN ID 0001
+	unsigned char mdix;		// Crossover judgement. 0:Disable 1:Enable
+	unsigned char mac_lock;		// MAC address Lock 0:Disable 1:Enable
+};
+
+struct PORT_STATUS
+{
+	unsigned char link;		// 0:not link	1:link established
+	unsigned char speed;		// 0:10M	1:100M
+	unsigned char duplex;		// 0:Half	1:Full duplex
+	unsigned char flow_ctl;		// 0:flow control disable 1:enable
+	unsigned char mac_lock;		// MAC address Lock 0:Disable 1:Enable
+	unsigned char port_disable;	// 0:port enable	1:disable
+
+	// Serial Management
+	unsigned long rx_pac_count;		//receive packet count
+	unsigned long rx_pac_byte;		//receive packet byte count
+	unsigned long tx_pac_count;		//transmit packet count
+	unsigned long tx_pac_byte;		//transmit packet byte count
+	unsigned long collision_count;		//error count
+	unsigned long error_count ;
+
+	unsigned long rx_pac_count_overflow;		//overflow flag
+	unsigned long rx_pac_byte_overflow;
+	unsigned long tx_pac_count_overflow;
+	unsigned long tx_pac_byte_overflow;
+	unsigned long collision_count_overflow;
+	unsigned long error_count_overflow;
+};
+
+struct PORT_CONFIG port_config[ADM699X_PORT_NO];	// 0~3:LAN , 4:WAN , 5:MII
+static struct PORT_STATUS port_state[ADM699X_PORT_NO];
+
+/******************************************
+* SPI_write
+* addr -> Write Address
+* value -> value to be write
+***************************************** */
+void SPI_write(unsigned char addr,unsigned int value)
+{
+	int     i;
+	char    bit;
+#ifdef CONFIG_IT8712_GPIO
+	char    status;
+#else
+    int     ad1;
+#endif
+
+#ifdef CONFIG_IT8712_GPIO
+	status = inb_gpio(LPC_GPIO_SET);
+	status &= ~(ADM_EDIO) ;		//EDIO low
+	outb_gpio(LPC_GPIO_SET, status);
+#else
+   	ad1 = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+	writel(GPIO_MISO,ad1); /* set MISO to 0 */
+#endif
+	SPI_CS_enable(1);
+
+	SPI_write_bit(0);       //dummy clock
+
+	//send write command (0x05)
+	for(i=SPI_OP_LEN-1;i>=0;i--)
+	{
+		bit = (SPI_OPWRITE>>i)& 0x01;
+		SPI_write_bit(bit);
+	}
+	// send 8 bits address (MSB first, LSB last)
+	for(i=SPI_ADD_LEN-1;i>=0;i--)
+	{
+		bit = (addr>>i)& 0x01;
+		SPI_write_bit(bit);
+	}
+	// send 16 bits data (MSB first, LSB last)
+	for(i=SPI_DAT_LEN-1;i>=0;i--)
+	{
+		bit = (value>>i)& 0x01;
+		SPI_write_bit(bit);
+	}
+
+	SPI_CS_enable(0);	// CS low
+
+	for(i=0;i<0xFFF;i++) ;
+#ifdef CONFIG_IT8712_GPIO
+	status = inb_gpio(LPC_GPIO_SET);
+	status &= ~(ADM_EDIO) ;		//EDIO low
+	outb_gpio(LPC_GPIO_SET, status);
+#else
+   	ad1 = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+	writel(GPIO_MISO,ad1); /* set MISO to 0 */
+#endif
+}
+
+
+/************************************
+* SPI_write_bit
+* bit_EEDO -> 1 or 0 to be written
+************************************/
+void SPI_write_bit(char bit_EEDO)
+{
+#ifdef CONFIG_IT8712_GPIO
+	unsigned char iomode,status;
+
+	iomode = LPCGetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET);
+	iomode |= (ADM_EECK|ADM_EDIO|ADM_EECS) ;				// Set EECK,EDIO,EECS output
+	LPCSetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET, iomode);
+
+	if(bit_EEDO)
+	{
+		status = inb_gpio( LPC_GPIO_SET);
+		status |= ADM_EDIO ;		//EDIO high
+		outb_gpio(LPC_GPIO_SET, status);
+	}
+	else
+	{
+		status = inb_gpio( LPC_GPIO_SET);
+		status &= ~(ADM_EDIO) ;		//EDIO low
+		outb_gpio(LPC_GPIO_SET, status);
+	}
+
+	status |= ADM_EECK ;		//EECK high
+	outb_gpio(LPC_GPIO_SET, status);
+
+	status &= ~(ADM_EECK) ;		//EECK low
+	outb_gpio(LPC_GPIO_SET, status);
+
+#else
+	unsigned int addr;
+	unsigned int value;
+
+	addr = (GPIO_BASE_ADDR + GPIO_PIN_DIR);
+	value = readl(addr) |GPIO_EECK |GPIO_MISO ;   /* set EECK/MISO Pin to output */
+	writel(value,addr);
+	if(bit_EEDO)
+	{
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+		writel(GPIO_MISO,addr); /* set MISO to 1 */
+		writel(GPIO_EECK,addr); /* set EECK to 1 */
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+		writel(GPIO_EECK,addr); /* set EECK to 0 */
+	}
+	else
+	{
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+		writel(GPIO_MISO,addr); /* set MISO to 0 */
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+		writel(GPIO_EECK,addr); /* set EECK to 1 */
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+		writel(GPIO_EECK,addr); /* set EECK to 0 */
+	}
+
+	return ;
+#endif
+}
+
+/**********************************************************************
+* read a bit from ADM6996 register
+***********************************************************************/
+unsigned int SPI_read_bit(void) // read data from
+{
+#ifdef CONFIG_IT8712_GPIO
+	unsigned char iomode,status;
+	unsigned int value ;
+
+	iomode = LPCGetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET);
+	iomode &= ~(ADM_EDIO) ;		// Set EDIO input
+	iomode |= (ADM_EECS|ADM_EECK) ;		// Set EECK,EECS output
+	LPCSetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET, iomode);
+
+	status = inb_gpio( LPC_GPIO_SET);
+	status |= ADM_EECK ;		//EECK high
+	outb_gpio(LPC_GPIO_SET, status);
+
+	status &= ~(ADM_EECK) ;		//EECK low
+	outb_gpio(LPC_GPIO_SET, status);
+
+	value = inb_gpio( LPC_GPIO_SET);
+
+	value = value>>2 ;
+	value &= 0x01;
+
+	return value ;
+#else
+	unsigned int addr;
+	unsigned int value;
+
+	addr = (GPIO_BASE_ADDR + GPIO_PIN_DIR);
+	value = readl(addr) & (~GPIO_MISO);   // set EECK to output and MISO to input
+	writel(value,addr);
+
+	addr =(GPIO_BASE_ADDR + GPIO_DATA_SET);
+	writel(GPIO_EECK,addr); // set EECK to 1
+	addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+	writel(GPIO_EECK,addr); // set EECK to 0
+
+	addr = (GPIO_BASE_ADDR + GPIO_DATA_IN);
+	value = readl(addr) ;
+	value = value >> 30;
+	return value ;
+#endif
+}
+
+/******************************************
+* SPI_default
+* EEPROM content default value
+*******************************************/
+void SPI_default(void)
+{
+	int i;
+#ifdef CONFIG_ADM_6999
+	SPI_write(0x11,0xFF30);
+	for(i=1;i<8;i++)
+		SPI_write(i,0x840F);
+
+	SPI_write(0x08,0x880F);			//port 8 Untag, PVID=2
+	SPI_write(0x09,0x881D);			//port 9 Tag, PVID=2 ,10M
+	SPI_write(0x14,0x017F);			//Group 0~6,8 as VLAN 1
+	SPI_write(0x15,0x0180);			//Group 7,8 as VLAN 2
+#endif
+
+#ifdef CONFIG_ADM_6996
+	SPI_write(0x11,0xFF30);
+	SPI_write(0x01,0x840F);			//port 0~3 Untag ,PVID=1 ,100M ,duplex
+	SPI_write(0x03,0x840F);
+	SPI_write(0x05,0x840F);
+	SPI_write(0x07,0x840F);
+	SPI_write(0x08,0x880F);			//port 4 Untag, PVID=2
+	SPI_write(0x09,0x881D);			//port 5 Tag, PVID=2 ,10M
+	SPI_write(0x14,0x0155);			//Group 0~3,5 as VLAN 1
+	SPI_write(0x15,0x0180);			//Group 4,5 as VLAN 2
+
+#endif
+
+	for(i=0x16;i<=0x22;i++)
+		SPI_write((unsigned char)i,0x0000);		// clean VLAN¡@map 3~15
+
+	for (i=0;i<NUM_VLAN_IF;i++) 				// Set VLAN ID map 1,2
+		SPI_Set_PVID( VLAN_conf[i].vid,  VLAN_conf[i].portmap);
+
+	for(i=0;i<ADM699X_PORT_NO;i++)				// reset count
+		SPI_reset(0,i);
+}
+
+/*************************************************
+* SPI_reset
+* rstype -> reset type
+*	    0:reset all count for 'port_cnt' port
+*	    1:reset specified count 'port_cnt'
+* port_cnt   ->  port number or counter index
+***************************************************/
+void SPI_reset(unsigned char rstype,unsigned char port_cnt)
+{
+
+	int i;
+#ifdef CONFIG_IT8712_GPIO
+    char status;
+#else
+	int ad1;
+#endif
+	char bit;
+
+#ifdef CONFIG_IT8712_GPIO
+	status = inb_gpio(LPC_GPIO_SET);
+	status &= ~(ADM_EDIO) ;		//EDIO low
+	outb_gpio(LPC_GPIO_SET, status);
+#else
+   	ad1 = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+	writel(GPIO_MISO,ad1); /* set MISO to 0 */
+#endif
+
+	SPI_CS_enable(0);	// CS low
+
+	SPI_pre_st(); // PRE+ST
+	SPI_write_bit(0); // OP
+	SPI_write_bit(1);
+
+	SPI_write_bit(1);		// Table select, must be 1 -> reset Counter
+
+	SPI_write_bit(0);		// Device Address
+	SPI_write_bit(0);
+
+	rstype &= 0x01;
+	SPI_write_bit(rstype);		// Reset type 0:clear dedicate port's all counters 1:clear dedicate counter
+
+	for (i=5;i>=0;i--) 		// port or cnt index
+	{
+		bit = port_cnt >> i ;
+		bit &= 0x01 ;
+		SPI_write_bit(bit);
+	}
+
+	SPI_write_bit(0); 		// dumy clock
+	SPI_write_bit(0); 		// dumy clock
+
+#ifdef CONFIG_IT8712_GPIO
+	status = inb_gpio(LPC_GPIO_SET);
+	status &= ~(ADM_EDIO) ;		//EDIO low
+	outb_gpio(LPC_GPIO_SET, status);
+#else
+   	ad1 = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+	writel(GPIO_MISO,ad1); /* set MISO to 0 */
+#endif
+}
+
+/*****************************************************
+* SPI_pre_st
+* preambler: 32 bits '1'   start bit: '01'
+*****************************************************/
+void SPI_pre_st(void)
+{
+	int i;
+
+	for(i=0;i<32;i++) // PREAMBLE
+		SPI_write_bit(1);
+	SPI_write_bit(0); // ST
+	SPI_write_bit(1);
+}
+
+
+/***********************************************************
+* SPI_CS_enable
+* before access ,you have to enable Chip Select. (pull high)
+* When fisish, you should pull low !!
+*************************************************************/
+void SPI_CS_enable(unsigned char enable)
+{
+#ifdef CONFIG_IT8712_GPIO
+
+	unsigned char iomode,status;
+
+	iomode = LPCGetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET);
+	iomode |= (ADM_EECK|ADM_EDIO|ADM_EECS) ;				// Set EECK,EDIO,EECS output
+	LPCSetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET, iomode);
+
+
+	status = inb_gpio( LPC_GPIO_SET);
+	if(enable)
+		status |= ADM_EECS ;		//EECS high
+	else
+		status &= ~(ADM_EECS) ;	//EECS low
+
+	outb_gpio(LPC_GPIO_SET, status);
+
+
+	status |= ADM_EECK ;		//EECK high
+	outb_gpio(LPC_GPIO_SET, status);
+
+	status &= ~(ADM_EECK) ;		//EECK low
+	outb_gpio(LPC_GPIO_SET, status);
+
+#else
+	unsigned int addr,value;
+
+	addr = (GPIO_BASE_ADDR + GPIO_PIN_DIR);
+	value = readl(addr) |GPIO_EECS |GPIO_EECK;   /* set EECS/EECK Pin to output */
+	writel(value,addr);
+
+	if(enable)
+	{
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+		writel(GPIO_EECS,addr); /* set EECS to 1 */
+
+	}
+	else
+	{
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+		writel(GPIO_EECS,addr); /* set EECS to 0 */
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+		writel(GPIO_EECK,addr); /* set EECK to 1 */	// at least one clock after CS low
+		addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+		writel(GPIO_EECK,addr); /* set EECK to 0 */
+	}
+#endif
+}
+
+/*********************************************************
+* SPI_Set_VLAN: group ports as VLAN
+* LAN  -> VLAN number : 0~16
+* port_mask -> ports which would group as LAN
+* 	       ex. 0x03 = 0000 0011
+*			port 0 and port 1
+*********************************************************/
+void SPI_Set_VLAN(unsigned char LAN,unsigned int port_mask)
+{
+	unsigned int i,value=0;
+	unsigned reg_add = 0x13 + LAN ;
+
+	for(i=0;i<ADM6996_PORT_NO;i++)
+	{	if(port_mask&0x01)
+		{
+			switch(i)
+			{
+				case 0: value|=0x0001;	break;	//port0:bit[0]
+				case 1: value|=0x0004;	break;  //port1:bit[2]
+				case 2: value|=0x0010;	break;  //port2:bit[4]
+				case 3: value|=0x0040;	break;  //port3:bit[6]
+				case 4: value|=0x0080;	break;  //port4:bit[7]
+				case 5: value|=0x0100;	break;  //port5:bit[8]
+			}
+		}
+		port_mask >>= 1;
+	}
+
+	SPI_write(reg_add,value);
+}
+
+
+/*******************************************
+* SPI_Set_tag
+* port -> port number to set tag or untag
+* tag  -> 0/set untag,  1/set tag
+* In general, tag is for MII port. LAN and
+* WAN port is configed as untag!!
+********************************************/
+void SPI_Set_tag(unsigned int port,unsigned tag)
+{
+	unsigned int regadd,value;
+
+	// mapping port's register !! (0,1,2,3,4,5) ==> (1,3,5,7,8,9)
+	if(port<=3)
+		regadd=2*port+1;
+	else if(port==4) regadd = 8 ;
+	else regadd = 9 ;
+
+
+	value = SPI_read(0,regadd);		//read original setting
+
+	if(tag)
+		value |= 0x0010 ;		// set tag
+	else
+		value &= 0xFFEF ;		// set untag
+
+	SPI_write(regadd,value);		// write back!!
+}
+
+/************************************************
+* SPI_Set_PVID
+* PVID -> PVID number :
+* port_mask -> ports which would group as LAN
+* 	       ex. 0x0F = 0000 1111 ==> port 0~3
+************************************************/
+void SPI_Set_PVID(unsigned int PVID,unsigned int port_mask)
+{
+	unsigned int i,value=0;
+
+	PVID &= 0x000F ;
+
+	for(i=0;i<ADM699X_PORT_NO;i++)
+	{	if(port_mask&0x01)
+		{
+#ifdef CONFIG_ADM_6996
+			switch(i)
+			{
+				case 0:
+					value = SPI_read(0,0x01);	// read original value
+					value &= 0xC3FF ;			//set PVIC column as 0 first
+					value |= PVID << 10 ;		//Set PVID column as PVID
+					SPI_write(0x01,value);		//write back
+					break;
+				case 1:
+					value = SPI_read(0,0x03);
+					value &= 0xC3FF ;
+					value |= PVID << 10 ;
+					SPI_write(0x03,value);
+					break;
+				case 2:
+					value = SPI_read(0,0x05);
+					value &= 0xC3FF ;
+					value |= PVID << 10 ;
+					SPI_write(0x05,value);
+					break;
+				case 3:
+					value = SPI_read(0,0x07);
+					value &= 0xC3FF ;
+					value |= PVID << 10 ;
+					SPI_write(0x07,value);
+					break;
+				case 4:
+					value = SPI_read(0,0x08);
+					value &= 0xC3FF ;
+					value |= PVID << 10 ;
+					SPI_write(0x08,value);
+					break;
+				case 5:
+					value = SPI_read(0,0x09);
+					value &= 0xC3FF ;
+					value |= PVID << 10 ;
+					SPI_write(0x09,value);
+					break;
+			}
+#endif
+#ifdef CONFIG_ADM_6999
+			value = SPI_read(0,(unsigned char)i+1);
+			value &= 0xC3FF ;
+			value |= PVID << 10 ;
+			SPI_write((unsigned char)i+1,value);
+#endif
+		}
+		port_mask >>= 1;
+	}
+}
+
+
+/************************************************
+* SPI_get_PVID
+* port -> which ports to VID
+************************************************/
+unsigned int SPI_Get_PVID(unsigned int port)
+{
+	unsigned int value=0;
+
+	if (port>=ADM6996_PORT_NO)
+		return 0;
+
+	switch(port)
+	{
+		case 0:
+			value = SPI_read(0,0x01);	// read original value
+			value &= 0x3C00 ;		// get VID
+			value = value >> 10 ;		// Shift
+			break;
+		case 1:
+			value = SPI_read(0,0x03);
+			value &= 0x3C00 ;
+			value = value >> 10 ;
+			break;
+		case 2:
+			value = SPI_read(0,0x05);
+			value &= 0x3C00 ;
+			value = value >> 10 ;
+			break;
+		case 3:
+			value = SPI_read(0,0x07);
+			value &= 0x3C00 ;
+			value = value >> 10 ;
+			break;
+		case 4:
+			value = SPI_read(0,0x08);
+			value &= 0x3C00 ;
+			value = value >> 10 ;
+			break;
+		case 5:
+			value = SPI_read(0,0x09);
+			value &= 0x3C00 ;
+			value = value >> 10 ;
+			break;
+	}
+	return value ;
+}
+
+
+/**********************************************
+* SPI_mac_clone
+* port -> the port which will lock or unlock
+* lock -> 0/the port will be unlock
+*	  1/the port will be locked
+**********************************************/
+void SPI_mac_lock(unsigned int port, unsigned char lock)
+{
+	unsigned int i,value=0;
+
+	value = SPI_read(0,0x12);		// read original
+
+	for(i=0;i<ADM6996_PORT_NO;i++)
+	{	if(lock)				// lock port
+		{
+			switch(port)
+			{
+				case 0: value|=0x0001;	break;	//port0:bit[0]
+				case 1: value|=0x0004;	break;	//port1:bit[2]
+				case 2: value|=0x0010;	break;	//port2:bit[4]
+				case 3: value|=0x0040;	break;	//port3:bit[6]
+				case 4: value|=0x0080;	break;	//port4:bit[7]
+				case 5: value|=0x0100;	break;	//port5:bit[8]
+			}
+		}
+		else
+		{
+			switch(i)			// unlock port
+			{
+				case 0: value&=0xFFFE;	break;
+				case 1: value&=0xFFFB;	break;
+				case 2: value&=0xFFEF;	break;
+				case 3: value&=0xFFBF;	break;
+				case 4: value&=0xFF7F;	break;
+				case 5: value&=0xFEFF;	break;
+			}
+		}
+	}
+
+	SPI_write(0x12,value);
+}
+
+
+/***************************************************
+* SPI_learn_pause
+* pause = 01-80-c2-00-00-01
+* DA=distination address
+* forward -> 0: if DA == pause then drop and stop mac learning
+*	     1: if DA == pause ,then forward it
+***************************************************/
+void SPI_pause_cmd_forward(unsigned char forward)
+{
+	unsigned int value=0;
+
+	value = SPI_read(0,0x2C);		// read original setting
+	if(forward)
+		value |= 0x2000;		// set bit[13] '1'
+	else
+		value &= 0xDFFF;		// set bit[13] '0'
+
+	SPI_write(0x2C,value);
+
+}
+
+
+/************************************************
+* SPI_read
+* table -> which table to be read: 1/count  0/EEPROM
+* addr  -> Address to be read
+* return : Value of the register
+*************************************************/
+unsigned int SPI_read(unsigned char table,unsigned char addr)
+{
+	int i ;
+	unsigned int value=0;
+	unsigned int bit;
+#ifdef CONFIG_IT8712_GPIO
+	unsigned char status;
+#else
+    unsigned int ad1;
+#endif
+
+#ifdef CONFIG_IT8712_GPIO
+	status = inb_gpio(LPC_GPIO_SET);
+	status &= ~(ADM_EDIO) ;		//EDIO low
+	outb_gpio(LPC_GPIO_SET, status);
+#else
+   	ad1 = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+	writel(GPIO_MISO,ad1); /* set MISO to 0 */
+#endif
+
+	SPI_CS_enable(0);
+
+	SPI_pre_st(); // PRE+ST
+	SPI_write_bit(1); // OPCODE '10' for read
+	SPI_write_bit(0);
+
+	(table==1) ? SPI_write_bit(1) : SPI_write_bit(0) ;	// table select
+
+	SPI_write_bit(0);		// Device Address
+	SPI_write_bit(0);
+
+
+	// send 7 bits address to be read
+	for (i=6;i>=0;i--) {
+		bit= ((addr>>i) & 0x01) ? 1 :0 ;
+		SPI_write_bit(bit);
+	}
+
+
+	// turn around
+	SPI_read_bit(); // TA_Z
+
+	value=0;
+	for (i=31;i>=0;i--) { // READ DATA
+		bit=SPI_read_bit();
+		value |= bit << i ;
+	}
+
+	SPI_read_bit(); // dumy clock
+	SPI_read_bit(); // dumy clock
+
+	if(!table)					// EEPROM, only fetch 16 bits data
+	{
+	    if(addr&0x01)				// odd number content (register,register-1)
+		    value >>= 16 ;			// so we remove the rear 16bits
+	    else					// even number content (register+1,register),
+		    value &= 0x0000FFFF ;		// so we keep the rear 16 bits
+	}
+
+
+	SPI_CS_enable(0);
+
+#ifdef CONFIG_IT8712_GPIO
+	status = inb_gpio(LPC_GPIO_SET);
+	status &= ~(ADM_EDIO) ;		//EDIO low
+	outb_gpio(LPC_GPIO_SET, status);
+#else
+   	ad1 = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+	writel(GPIO_MISO,ad1); /* set MISO to 0 */
+#endif
+
+	return(value);
+
+}
+
+
+
+/**************************************************
+* SPI_port_en
+* port -> Number of port to config
+* enable -> 1/ enable this port
+*	    0/ disable this port
+**************************************************/
+void SPI_port_enable(unsigned int port,unsigned char enable)
+{
+	unsigned int reg_val ;
+	unsigned char reg_add ;
+
+	if(port<=3)
+		reg_add=2*port+1;
+	else if(port==4) reg_add = 8 ;
+	else reg_add = 9 ;
+
+	reg_val = SPI_read(0,reg_add);
+	if(enable)
+	{
+		reg_val &= 0xFFDF ;
+		SPI_write(reg_add,reg_val);
+	}
+	else
+	{
+		reg_val |= 0x0020 ;
+		SPI_write(reg_add,reg_val);
+	}
+}
+
+/********************************************************
+* get port status
+* port -> specify the port number to get configuration
+*********************************************************/
+void SPI_get_status(unsigned int port)
+{
+/*	unsigned int reg_val,add_offset[6];
+	struct PORT_STATUS *status;
+	status = &port_state[port];
+
+	if(port>(ADM6996_PORT_NO-1))
+		return ;
+
+	// Link estabilish , speed, deplex, flow control ?
+	if(port < 5 )
+	{
+		reg_val = SPI_read(1, 1) ;
+		if(port < 4)
+			reg_val >>= port*8 ;
+		else
+			reg_val >>=28 ;
+		status->link = reg_val & 0x00000001 ;
+		status->speed = reg_val  & 0x00000002 ;
+		status->duplex = reg_val & 0x00000004 ;
+		status->flow_ctl = reg_val & 0x00000008 ;
+	}
+	else if(port ==5 )
+	{
+		reg_val = SPI_read(1, 2) ;
+		status->link = reg_val & 0x00000001 ;
+		status->speed = reg_val  & 0x00000002 ;
+		status->duplex = reg_val & 0x00000008 ;
+		status->flow_ctl = reg_val & 0x00000010 ;
+	}
+
+	//   Mac Lock ?
+	reg_val = SPI_read(0,0x12);
+	switch(port)
+	{
+		case 0:	status->mac_lock = reg_val & 0x00000001;
+		case 1:	status->mac_lock = reg_val & 0x00000004;
+		case 2:	status->mac_lock = reg_val & 0x00000010;
+		case 3:	status->mac_lock = reg_val & 0x00000040;
+		case 4:	status->mac_lock = reg_val & 0x00000080;
+		case 5:	status->mac_lock = reg_val & 0x00000100;
+	}
+
+	// port enable ?
+	add_offset[0] = 0x01 ;		add_offset[1] = 0x03 ;
+	add_offset[2] = 0x05 ;		add_offset[3] = 0x07 ;
+	add_offset[4] = 0x08 ;		add_offset[5] = 0x09 ;
+	reg_val = SPI_read(0,add_offset[port]);
+	status->port_disable = reg_val & 0x0020;
+
+
+	//  Packet Count ...
+	add_offset[0] = 0x04 ;		add_offset[1] = 0x06 ;
+	add_offset[2] = 0x08 ;		add_offset[3] = 0x0a ;
+	add_offset[4] = 0x0b ;		add_offset[5] = 0x0c ;
+
+	reg_val = SPI_read(1,add_offset[port]);
+	status->rx_pac_count = reg_val ;
+	reg_val = SPI_read(1,add_offset[port]+9);
+	status->rx_pac_byte = reg_val ;
+	reg_val = SPI_read(1,add_offset[port]+18);
+	status->tx_pac_count = reg_val ;
+	reg_val = SPI_read(1,add_offset[port]+27);
+	status->tx_pac_byte = reg_val ;
+	reg_val = SPI_read(1,add_offset[port]+36);
+	status->collision_count = reg_val ;
+	reg_val = SPI_read(1,add_offset[port]+45);
+	status->error_count = reg_val ;
+	reg_val = SPI_read(1, 0x3A);
+	switch(port)
+	{
+		case 0:	status->rx_pac_count_overflow = reg_val & 0x00000001;
+			status->rx_pac_byte_overflow = reg_val & 0x00000200 ;
+		case 1:	status->rx_pac_count_overflow = reg_val & 0x00000004;
+			status->rx_pac_byte_overflow = reg_val & 0x00000800 ;
+		case 2:	status->rx_pac_count_overflow = reg_val & 0x00000010;
+			status->rx_pac_byte_overflow = reg_val & 0x00002000 ;
+		case 3:	status->rx_pac_count_overflow = reg_val & 0x00000040;;
+			status->rx_pac_byte_overflow = reg_val & 0x00008000 ;
+		case 4:	status->rx_pac_count_overflow = reg_val & 0x00000080;
+			status->rx_pac_byte_overflow = reg_val & 0x00010000 ;
+		case 5:	status->rx_pac_count_overflow = reg_val & 0x00000100;
+			status->rx_pac_byte_overflow = reg_val & 0x00020000 ;
+	}
+
+	reg_val = SPI_read(1, 0x3B);
+	switch(port)
+	{
+		case 0:	status->tx_pac_count_overflow = reg_val & 0x00000001;
+			status->tx_pac_byte_overflow  = reg_val & 0x00000200 ;
+		case 1:	status->tx_pac_count_overflow  = reg_val & 0x00000004;
+			status->tx_pac_byte_overflow  = reg_val & 0x00000800 ;
+		case 2:	status->tx_pac_count_overflow  = reg_val & 0x00000010;
+			status->tx_pac_byte_overflow  = reg_val & 0x00002000 ;
+		case 3:	status->tx_pac_count_overflow  = reg_val & 0x00000040;;
+			status->tx_pac_byte_overflow  = reg_val & 0x00008000 ;
+		case 4:	status->tx_pac_count_overflow  = reg_val & 0x00000080;
+			status->tx_pac_byte_overflow  = reg_val & 0x00010000 ;
+		case 5:	status->tx_pac_count_overflow  = reg_val & 0x00000100;
+			status->tx_pac_byte_overflow  = reg_val & 0x00020000 ;
+	}
+*/
+
+	unsigned int reg_val;
+	struct PORT_STATUS *status;
+	status = &port_state[port];
+
+	if(port>=ADM6999_PORT_NO)
+		return ;
+
+	// Link estabilish , speed, deplex, flow control ?
+	if(port < ADM6999_PORT_NO-1 )
+	{
+		reg_val = SPI_read(1, 0x01) ;
+		reg_val = reg_val >> port*4 ;
+		status->link = reg_val & 0x00000001 ;
+		status->speed = reg_val  & 0x00000002 ;
+		status->duplex = reg_val & 0x00000004 ;
+		status->flow_ctl = reg_val & 0x00000008 ;
+	}
+	else if(port == (ADM6999_PORT_NO-1) )
+	{
+		reg_val = SPI_read(1, 0x02) ;
+		status->link = reg_val & 0x00000001 ;
+		status->speed = reg_val  & 0x00000002 ;
+		status->duplex = reg_val & 0x00000008 ;
+		status->flow_ctl = reg_val & 0x00000010 ;
+	}
+
+	// Mac Lock ?
+	reg_val = SPI_read(0,0x12);
+	reg_val = reg_val >> port ;
+	reg_val = reg_val & 0x01 ;
+	status->mac_lock = reg_val ? 0x01:0x00 ;
+
+	// port enable ?
+	reg_val = SPI_read(0,(unsigned char)port+1);
+	status->port_disable = reg_val & 0x0020;
+
+	//  Packet Count ...
+	reg_val = SPI_read(1,(unsigned char)port+0x04);
+	status->rx_pac_count = reg_val ;
+	reg_val = SPI_read(1,(unsigned char)port+0x0D);
+	status->rx_pac_byte = reg_val ;
+	reg_val = SPI_read(1,(unsigned char)port+0x16);
+	status->tx_pac_count = reg_val ;
+	reg_val = SPI_read(1,(unsigned char)port+0x1F);
+	status->tx_pac_byte = reg_val ;
+	reg_val = SPI_read(1,(unsigned char)port+0x28);
+	status->collision_count = reg_val ;
+	reg_val = SPI_read(1,(unsigned char)port+0x31);
+	status->error_count = reg_val ;
+	reg_val = SPI_read(1, 0x3A);
+	reg_val = reg_val >> port ;
+	status->rx_pac_count_overflow = reg_val & 0x00000001;
+	reg_val = reg_val >> 0x09 ;
+	status->rx_pac_byte_overflow = reg_val & 0x00000001 ;
+
+	reg_val = SPI_read(1, 0x3B);
+	reg_val = reg_val >> port ;
+	status->tx_pac_count_overflow = reg_val & 0x00000001;
+	reg_val = reg_val >> 0x09 ;
+	status->tx_pac_byte_overflow  = reg_val & 0x00000001 ;
+
+	reg_val = SPI_read(1, 0x3C);
+	reg_val = reg_val >> port ;
+	status->collision_count_overflow = reg_val & 0x00000001;
+	reg_val = reg_val >> 0x09 ;
+	status->error_count_overflow  = reg_val & 0x00000001 ;
+
+}
+
+unsigned int SPI_get_identifier(void)
+{
+	unsigned int flag=0;
+
+#ifdef CONFIG_IT8712_GPIO
+
+	if (!it8712_exist) {
+		return -ENODEV;
+	}
+	printk("it8712_gpio init\n");
+
+	/* initialize registers */
+	// switch all multi-function pins to GPIO
+	LPCSetConfig(LDN_GPIO, 0x28, 0xff);
+
+	// set simple I/O base address
+	LPCSetConfig(LDN_GPIO, 0x62, IT8712_GPIO_BASE >> 8);
+	LPCSetConfig(LDN_GPIO, 0x63, (unsigned char) IT8712_GPIO_BASE >> 8);
+
+	// select GPIO to simple I/O
+	LPCSetConfig(LDN_GPIO, 0xc3, 0xff);
+
+	// enable internal pull-up
+	LPCSetConfig(LDN_GPIO, 0xbb, 0xff);
+
+#endif
+
+	flag = SPI_read(1,0x00);
+	printk("Get ADM identifier %6x\n",flag);
+	if ((flag & 0xFFFF0) == 0x21120) {
+		printk("ADM699X Found\n");
+		return 1;
+	}
+	else {
+		printk("ADM699X not Found\n");
+		return 0;
+	}
+}
+
--- /dev/null
+++ b/drivers/net/sl351x_crc16.c
@@ -0,0 +1,93 @@
+/****************************************************************************
+* Name			: sl351x_crc16.c
+* Description	:
+*		Implement CRC16
+*		refer to RFC1662
+* History
+*
+*	Date		Writer		Description
+*	-----------	-----------	-------------------------------------------------
+*	09/14/2005	Gary Chen	Create
+*
+****************************************************************************/
+
+#define INITFCS16		0xffff  /* Initial FCS value */
+#define GOODFCS16		0xf0b8  /* Good final FCS value */
+#define SWAP_WORD(x)	(unsigned short)((((unsigned short)x & 0x00FF) << 8) |	\
+										 (((unsigned short)x & 0xFF00) >> 8))
+
+/*----------------------------------------------------------------------
+* 	x**0 + x**5 + x**12 + x**16
+*----------------------------------------------------------------------*/
+static const unsigned short crc16_tbl[256] = {
+      0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
+      0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
+      0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
+      0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
+      0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
+      0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
+      0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
+      0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
+      0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
+      0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
+      0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
+      0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
+      0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
+      0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
+      0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
+      0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
+      0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
+      0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
+      0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
+      0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
+      0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
+      0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
+      0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
+      0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
+      0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
+      0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
+      0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
+      0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
+      0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
+      0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
+      0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
+      0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
+};
+
+/*----------------------------------------------------------------------
+* hash_crc16
+*----------------------------------------------------------------------*/
+unsigned short hash_crc16(unsigned short crc, unsigned char *datap, unsigned long len)
+{
+    while (len--)
+    {
+        crc = (crc >> 8) ^ crc16_tbl[(crc ^ (*datap++)) & 0xff];
+    }
+
+    return (crc);
+
+}
+
+/*----------------------------------------------------------------------
+* hash_check_crc16
+*----------------------------------------------------------------------*/
+unsigned long hash_check_crc16(unsigned char *datap, unsigned long len)
+{
+    unsigned short crc;
+
+    crc = hash_crc16(INITFCS16, datap, len );
+    return (crc == GOODFCS16) ?  0 : 1;
+}
+
+/*----------------------------------------------------------------------
+* hash_gen_crc16
+*----------------------------------------------------------------------*/
+unsigned short hash_gen_crc16(unsigned char *datap, unsigned long len)
+{
+    unsigned short crc;
+
+    crc = hash_crc16(INITFCS16, datap, len);
+    crc ^= 0xffff;
+
+    return(SWAP_WORD(crc));
+}
--- /dev/null
+++ b/drivers/net/sl351x_gmac.c
@@ -0,0 +1,5622 @@
+/**************************************************************************
+* Copyright 2006 StorLink Semiconductors, Inc.  All rights reserved.
+*--------------------------------------------------------------------------
+* Name			: sl351x_gmac.c
+* Description	:
+*		Ethernet device driver for Storlink SL351x FPGA
+*
+* History
+*
+*	Date		Writer		Description
+*	-----------	-----------	-------------------------------------------------
+*	08/22/2005	Gary Chen	Create and implement
+*   27/10/2005  CH Hsu      Porting to Linux
+*
+****************************************************************************/
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/mm.h>
+#include <linux/compiler.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
+#include <linux/delay.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/completion.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/semaphore.h>
+#include <asm/arch/irqs.h>
+#include <asm/arch/it8712.h>
+#include <linux/mtd/kvctl.h>
+#include <linux/skbuff.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
+
+#include <linux/mtd/kvctl.h>
+
+#define	 MIDWAY
+#define	 SL_LEPUS
+#define VITESSE_G5SWITCH	1
+
+#ifndef CONFIG_SL351x_RXTOE
+//#define CONFIG_SL351x_RXTOE	1
+#endif
+#undef CONFIG_SL351x_RXTOE
+
+#include <asm/arch/sl2312.h>
+#include <asm/arch/sl351x_gmac.h>
+#include <asm/arch/sl351x_hash_cfg.h>
+#include <asm/arch/sl351x_nat_cfg.h>
+
+#ifdef CONFIG_SL351x_SYSCTL
+#include <linux/sysctl_storlink.h>
+#endif
+
+#ifdef CONFIG_SL351x_RXTOE
+#include <asm/arch/sl351x_toe.h>
+#include <net/tcp.h>
+#include <linux/tcp.h>
+#include <linux/ip.h>
+#endif
+
+// #define SL351x_TEST_WORKAROUND
+#ifdef CONFIG_SL351x_NAT
+#define CONFIG_SL_NAPI					1
+#endif
+#define GMAX_TX_INTR_DISABLED			1
+#define DO_HW_CHKSUM					1
+#define ENABLE_TSO						1
+#define GMAC_USE_TXQ0					1
+// #define NAT_WORKAROUND_BY_RESET_GMAC	1
+// #define HW_RXBUF_BY_KMALLOC			1
+//#define _DUMP_TX_TCP_CONTENT	1
+#define	br_if_ioctl						1
+#define GMAC_LEN_1_2_ISSUE				1
+
+#define GMAC_EXISTED_FLAG			0x5566abcd
+#define CONFIG_MAC_NUM				GMAC_NUM
+#define GMAC0_BASE					TOE_GMAC0_BASE
+#define GMAC1_BASE					TOE_GMAC1_BASE
+#define PAUSE_SET_HW_FREEQ			(TOE_HW_FREEQ_DESC_NUM / 2)
+#define PAUSE_REL_HW_FREEQ			((TOE_HW_FREEQ_DESC_NUM / 2) + 10)
+#define DEFAULT_RXQ_MAX_CNT			256
+#ifdef	L2_jumbo_frame
+#define TCPHDRLEN(tcp_hdr)  ((ntohs(*((__u16 *)tcp_hdr + 6)) >> 12) & 0x000F)
+#endif
+
+/* define chip information */
+#define DRV_NAME					"SL351x"
+#define DRV_VERSION					"0.1.4"
+#define SL351x_DRIVER_NAME  		DRV_NAME " Giga Ethernet driver " DRV_VERSION
+
+#define toe_gmac_enable_interrupt(irq)	enable_irq(irq)
+#define toe_gmac_disable_interrupt(irq)	disable_irq(irq)
+
+#ifdef SL351x_GMAC_WORKAROUND
+#define GMAC_SHORT_FRAME_THRESHOLD		10
+static struct timer_list gmac_workround_timer_obj;
+void sl351x_poll_gmac_hanged_status(u32 data);
+#ifdef CONFIG_SL351x_NAT
+//#define IxscriptMate_1518				1
+	void sl351x_nat_workaround_init(void);
+	#ifndef NAT_WORKAROUND_BY_RESET_GMAC
+		static void sl351x_nat_workaround_handler(void);
+	#endif
+#endif
+#endif
+
+#ifdef GMAC_LEN_1_2_ISSUE
+	#define _DEBUG_PREFETCH_NUM	256
+static	int	_debug_prefetch_cnt;
+static	char _debug_prefetch_buf[_DEBUG_PREFETCH_NUM][4] __attribute__((aligned(4)));
+#endif
+/*************************************************************
+ *         Global Variable
+ *************************************************************/
+static int	gmac_initialized = 0;
+TOE_INFO_T toe_private_data;
+//static int		do_again = 0;
+spinlock_t gmac_fq_lock;
+unsigned int FLAG_SWITCH;
+
+static unsigned int     	next_tick = 3 * HZ;
+static unsigned char    	eth_mac[CONFIG_MAC_NUM][6]= {{0x00,0x11,0x11,0x87,0x87,0x87}, {0x00,0x22,0x22,0xab,0xab,0xab}};
+
+#undef CONFIG_SL351x_RXTOE
+extern NAT_CFG_T nat_cfg;
+
+/************************************************/
+/*                 function declare             */
+/************************************************/
+static int gmac_set_mac_address(struct net_device *dev, void *addr);
+static unsigned int gmac_get_phy_vendor(int phy_addr);
+static void gmac_set_phy_status(struct net_device *dev);
+void gmac_get_phy_status(struct net_device *dev);
+static int gmac_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
+static void gmac_tx_timeout(struct net_device *dev);
+static int gmac_phy_thread (void *data);
+struct net_device_stats * gmac_get_stats(struct net_device *dev);
+static int gmac_start_xmit(struct sk_buff *skb, struct net_device *dev);
+static void gmac_set_rx_mode(struct net_device *dev);
+static irqreturn_t toe_gmac_interrupt (int irq, void *dev_instance);
+static void toe_gmac_handle_default_rxq(struct net_device *dev, GMAC_INFO_T *tp);
+unsigned int mii_read(unsigned char phyad,unsigned char regad);
+void mii_write(unsigned char phyad,unsigned char regad,unsigned int value);
+void mac_init_drv(void);
+
+static void toe_init_free_queue(void);
+static void toe_init_swtx_queue(void);
+static void toe_init_default_queue(void);
+#ifdef CONFIG_SL351x_RXTOE
+static void toe_init_interrupt_queue(void);
+#endif
+static void toe_init_interrupt_config(void);
+static void toe_gmac_sw_reset(void);
+static int toe_gmac_init_chip(struct net_device *dev);
+static void toe_gmac_enable_tx_rx(struct net_device* dev);
+static void toe_gmac_disable_tx_rx(struct net_device *dev);
+static void toe_gmac_hw_start(struct net_device *dev);
+static void toe_gmac_hw_stop(struct net_device *dev);
+static int toe_gmac_clear_counter(struct net_device *dev);
+static void toe_init_gmac(struct net_device *dev);
+static  void toe_gmac_tx_complete(GMAC_INFO_T *tp, unsigned int tx_qid, struct net_device *dev, int interrupt);
+#ifdef CONFIG_SL_NAPI
+static int gmac_rx_poll(struct net_device *dev, int *budget);
+// static void toe_gmac_disable_rx(struct net_device *dev);
+// static void toe_gmac_enable_rx(struct net_device *dev);
+#endif
+
+u32 mac_read_dma_reg(int mac, unsigned int offset);
+void mac_write_dma_reg(int mac, unsigned int offset, u32 data);
+void mac_stop_txdma(struct net_device *dev);
+void mac_get_sw_tx_weight(struct net_device *dev, char *weight);
+void mac_set_sw_tx_weight(struct net_device *dev, char *weight);
+void mac_get_hw_tx_weight(struct net_device *dev, char *weight);
+void mac_set_hw_tx_weight(struct net_device *dev, char *weight);
+static inline void toe_gmac_fill_free_q(void);
+
+#ifdef VITESSE_G5SWITCH
+extern int Get_Set_port_status(void);
+extern int SPI_default(void);
+extern unsigned int SPI_get_identifier(void);
+void gmac_get_switch_status(struct net_device *dev);
+unsigned int Giga_switch=0;
+unsigned int switch_port_no=0;
+unsigned int ever_dwon=0;
+#endif
+
+/************************************************/
+/*            GMAC function declare             */
+/************************************************/
+static int gmac_open (struct net_device *dev);
+static int gmac_close (struct net_device *dev);
+static void gmac_cleanup_module(void);
+static void gmac_get_mac_address(void);
+
+#ifdef CONFIG_SL351x_NAT
+static void toe_init_hwtx_queue(void);
+extern void sl351x_nat_init(void);
+extern void sl351x_nat_input(struct sk_buff *skb, int port, void *l3off, void *l4off);
+extern int sl351x_nat_output(struct sk_buff *skb, int port);
+extern int sl351x_nat_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
+#endif
+
+#ifdef CONFIG_SL351x_RXTOE
+extern void set_toeq_hdr(struct toe_conn* connection, TOE_INFO_T* toe, struct net_device *dev);
+extern void sl351x_toe_init(void);
+extern void toe_gmac_handle_toeq(struct net_device *dev, GMAC_INFO_T* tp, __u32 status);
+extern struct toe_conn* init_toeq(int ipver, void* iph, struct tcphdr* tcp_hdr, TOE_INFO_T* toe, unsigned char* l2hdr);
+#endif
+
+int mac_set_rule_reg(int mac, int rule, int enabled, u32 reg0, u32 reg1, u32 reg2);
+void mac_set_rule_enable_bit(int mac, int rule, int data);
+int mac_set_rule_action(int mac, int rule, int data);
+int mac_get_MRxCRx(int mac, int rule, int ctrlreg);
+void mac_set_MRxCRx(int mac, int rule, int ctrlreg, u32 data);
+
+/*----------------------------------------------------------------------
+*	Ethernet Driver init
+*----------------------------------------------------------------------*/
+
+static int __init gmac_init_module(void)
+{
+	GMAC_INFO_T 		*tp;
+	struct net_device	*dev;
+	int 		i,j;
+	unsigned int	chip_id;
+//	unsigned int chip_version;
+
+#ifdef CONFIG_SL3516_ASIC
+{
+    unsigned int    val;
+    /* set GMAC global register */
+    val = readl(GMAC_GLOBAL_BASE_ADDR+0x10);
+    val = val | 0x005f0000;
+    writel(val,GMAC_GLOBAL_BASE_ADDR+0x10);
+//    writel(0xb737b737,GMAC_GLOBAL_BASE_ADDR+0x1c); //For Socket Board
+    writel(0x77777777,GMAC_GLOBAL_BASE_ADDR+0x20);
+//    writel(0xa737b747,GMAC_GLOBAL_BASE_ADDR+0x1c);//For Mounting Board
+
+	//debug_Aaron
+    //writel(0xa7f0a7f0,GMAC_GLOBAL_BASE_ADDR+0x1c);//For Mounting Board
+    writel(0xa7f0b7f0,GMAC_GLOBAL_BASE_ADDR+0x1c);//For Mounting Board
+
+    writel(0x77777777,GMAC_GLOBAL_BASE_ADDR+0x24);
+	writel(0x09200030,GMAC_GLOBAL_BASE_ADDR+0x2C);
+	val = readl(GMAC_GLOBAL_BASE_ADDR+0x04);
+	if((val&(1<<20))==0){           // GMAC1 enable
+ 		val = readl(GMAC_GLOBAL_BASE_ADDR+0x30);
+		val = (val & 0xe7ffffff) | 0x08000000;
+		writel(val,GMAC_GLOBAL_BASE_ADDR+0x30);
+	}
+}
+#endif
+
+#ifdef VITESSE_G5SWITCH
+	Giga_switch = SPI_get_identifier();
+	if(Giga_switch)
+		switch_port_no = SPI_default();
+#endif
+
+	chip_id = readl(GMAC_GLOBAL_BASE_ADDR+0x0);
+	if (chip_id == 0x3512C1)
+	{
+		writel(0x5787a5f0,GMAC_GLOBAL_BASE_ADDR+0x1c);//For 3512 Switch Board
+		writel(0x55557777,GMAC_GLOBAL_BASE_ADDR+0x20);//For 3512 Switch Board
+	}
+//#endif
+
+	mac_init_drv();
+
+	printk (KERN_INFO SL351x_DRIVER_NAME " built at %s %s\n", __DATE__, __TIME__);
+
+//	init_waitqueue_entry(&wait, current);
+
+	// printk("GMAC Init......\n");
+
+	i = 0;
+	for(j = 0; i<CONFIG_MAC_NUM; j++)
+	{
+		i=j;
+		if(Giga_switch){		// if gswitch present, swap eth0/1
+			if(j==0)
+				i=1;
+			else if(j==1)
+				i=0;
+		}
+
+		tp = (GMAC_INFO_T *)&toe_private_data.gmac[i];
+		tp->dev = NULL;
+		if (tp->existed != GMAC_EXISTED_FLAG) continue;
+
+		dev = alloc_etherdev(0);
+		if (dev == NULL)
+		{
+			printk (KERN_ERR "Can't allocate ethernet device #%d .\n",i);
+			return -ENOMEM;
+		}
+
+		dev->priv=tp;
+		tp->dev = dev;
+
+		SET_MODULE_OWNER(dev);
+
+		// spin_lock_init(&tp->lock);
+		spin_lock_init(&gmac_fq_lock);
+		dev->base_addr = tp->base_addr;
+		dev->irq = tp->irq;
+	    dev->open = gmac_open;
+	    dev->stop = gmac_close;
+		dev->hard_start_xmit = gmac_start_xmit;
+		dev->get_stats = gmac_get_stats;
+		dev->set_multicast_list = gmac_set_rx_mode;
+		dev->set_mac_address = gmac_set_mac_address;
+		dev->do_ioctl = gmac_netdev_ioctl;
+		dev->tx_timeout = gmac_tx_timeout;
+		dev->watchdog_timeo = GMAC_DEV_TX_TIMEOUT;
+#ifdef	L2_jumbo_frame
+		dev->mtu = 2018; //2002  ,2018
+#endif
+		if (tp->port_id == 0)
+			dev->tx_queue_len = TOE_GMAC0_SWTXQ_DESC_NUM;
+		else
+			dev->tx_queue_len = TOE_GMAC1_SWTXQ_DESC_NUM;
+
+#ifdef DO_HW_CHKSUM
+		dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM;
+#ifdef ENABLE_TSO
+		dev->features |= NETIF_F_TSO;
+#endif
+#endif
+#ifdef CONFIG_SL_NAPI
+        dev->poll = gmac_rx_poll;
+        dev->weight = 64;
+#endif
+
+		if (register_netdev(dev))
+		{
+			gmac_cleanup_module();
+			return(-1);
+		}
+	}
+
+
+//	FLAG_SWITCH = 0 ;
+//	FLAG_SWITCH = SPI_get_identifier();
+//	if(FLAG_SWITCH)
+//	{
+//		printk("Configure ADM699X...\n");
+//		SPI_default();	//Add by jason for ADM699X configuration
+//	}
+	return (0);
+}
+
+/*----------------------------------------------------------------------
+*	gmac_cleanup_module
+*----------------------------------------------------------------------*/
+
+static void gmac_cleanup_module(void)
+{
+    int i;
+
+#ifdef SL351x_GMAC_WORKAROUND
+	del_timer(&gmac_workround_timer_obj);
+#endif
+
+    for (i=0;i<CONFIG_MAC_NUM;i++)
+    {
+    	if (toe_private_data.gmac[i].dev)
+    	{
+        	unregister_netdev(toe_private_data.gmac[i].dev);
+        	toe_private_data.gmac[i].dev = NULL;
+        }
+    }
+	return ;
+}
+
+module_init(gmac_init_module);
+module_exit(gmac_cleanup_module);
+
+
+/*----------------------------------------------------------------------
+*	gmac_read_reg
+*----------------------------------------------------------------------*/
+static inline unsigned int gmac_read_reg(unsigned int base, unsigned int offset)
+//static unsigned int gmac_read_reg(unsigned int base, unsigned int offset)
+{
+    volatile unsigned int reg_val;
+
+    reg_val = readl(base + offset);
+	return (reg_val);
+}
+
+/*----------------------------------------------------------------------
+*	gmac_write_reg
+*----------------------------------------------------------------------*/
+static inline void gmac_write_reg(unsigned int base, unsigned int offset,unsigned int data,unsigned int bit_mask)
+//static void gmac_write_reg(unsigned int base, unsigned int offset,unsigned int data,unsigned int bit_mask)
+{
+	volatile unsigned int reg_val;
+    unsigned int *addr;
+
+	reg_val = ( gmac_read_reg(base, offset) & (~bit_mask) ) | (data & bit_mask);
+	addr = (unsigned int *)(base + offset);
+    writel(reg_val,addr);
+	return;
+}
+
+/*----------------------------------------------------------------------
+*	mac_init_drv
+*----------------------------------------------------------------------*/
+void mac_init_drv(void)
+{
+	TOE_INFO_T			*toe;
+	int					i;
+	QUEUE_THRESHOLD_T	threshold;
+	u32					*destp;
+	unsigned int		chip_id,chip_version;
+
+	chip_id = readl(GMAC_GLOBAL_BASE_ADDR+0x0);
+	chip_version = chip_id & 0x1 ;
+
+	if (!gmac_initialized)
+	{
+		gmac_initialized = 1;
+
+		// clear non TOE Queue Header Area
+		destp = (u32 *)TOE_NONTOE_QUE_HDR_BASE;
+		for (; destp < (u32 *)NONTOE_Q_HDR_AREA_END; destp++)
+			*destp = 0x00;
+
+		// clear TOE Queue Header Area
+		destp = (u32 *)TOE_TOE_QUE_HDR_BASE;
+		for (; destp < (u32 *)TOE_Q_HDR_AREA_END; destp++)
+			*destp = 0x00;
+
+		// init private data
+		toe = (TOE_INFO_T *)&toe_private_data;
+		memset((void *)toe, 0, sizeof(TOE_INFO_T));
+		toe->gmac[0].base_addr = GMAC0_BASE;
+		toe->gmac[1].base_addr = GMAC1_BASE;
+		toe->gmac[0].dma_base_addr = TOE_GMAC0_DMA_BASE;
+		toe->gmac[1].dma_base_addr = TOE_GMAC1_DMA_BASE;
+        toe->gmac[0].auto_nego_cfg = 1;
+        toe->gmac[1].auto_nego_cfg = 1;
+#ifdef CONFIG_SL3516_ASIC
+        toe->gmac[0].speed_cfg = GMAC_SPEED_1000;
+        toe->gmac[1].speed_cfg = GMAC_SPEED_1000;
+#else
+		toe->gmac[0].speed_cfg = GMAC_SPEED_100;
+        toe->gmac[1].speed_cfg = GMAC_SPEED_100;
+#endif
+        toe->gmac[0].full_duplex_cfg = 1;
+        toe->gmac[1].full_duplex_cfg = 1;
+#ifdef CONFIG_SL3516_ASIC
+        toe->gmac[0].phy_mode = GMAC_PHY_RGMII_1000;
+        toe->gmac[1].phy_mode = GMAC_PHY_RGMII_1000;
+#else
+		toe->gmac[0].phy_mode = GMAC_PHY_RGMII_100;
+        toe->gmac[1].phy_mode = GMAC_PHY_RGMII_100;
+#endif
+        toe->gmac[0].port_id = GMAC_PORT0;
+        toe->gmac[1].port_id = GMAC_PORT1;
+        toe->gmac[0].phy_addr = 0x1;
+        toe->gmac[1].phy_addr = 2;
+//      toe->gmac[0].irq = SL2312_INTERRUPT_GMAC0;
+		toe->gmac[0].irq =1;
+//      toe->gmac[1].irq = SL2312_INTERRUPT_GMAC1;
+		toe->gmac[1].irq =2;
+        toe->gmac[0].mac_addr1 = &eth_mac[0][0];
+        toe->gmac[1].mac_addr1 = &eth_mac[1][0];
+
+		for (i=0; i<CONFIG_MAC_NUM; i++)
+		{
+			unsigned int data, phy_vendor;
+			gmac_write_reg(toe->gmac[i].base_addr, GMAC_STA_ADD2, 0x55aa55aa, 0xffffffff);
+			data = gmac_read_reg(toe->gmac[i].base_addr, GMAC_STA_ADD2);
+			if (data == 0x55aa55aa)
+			{
+#ifdef VITESSE_G5SWITCH
+				if(Giga_switch && (i==1)){
+					toe->gmac[i].existed = GMAC_EXISTED_FLAG;
+					break;
+				}
+#endif
+				phy_vendor = gmac_get_phy_vendor(toe->gmac[i].phy_addr);
+				if (phy_vendor != 0 && phy_vendor != 0xffffffff)
+					toe->gmac[i].existed = GMAC_EXISTED_FLAG;
+			}
+		}
+
+		// Write GLOBAL_QUEUE_THRESHOLD_REG
+		threshold.bits32 = 0;
+		threshold.bits.swfq_empty = (TOE_SW_FREEQ_DESC_NUM > 256) ? 255 :
+		                                        TOE_SW_FREEQ_DESC_NUM/2;
+		threshold.bits.hwfq_empty = (TOE_HW_FREEQ_DESC_NUM > 256) ? 256/4 :
+		                                        TOE_HW_FREEQ_DESC_NUM/4;
+		threshold.bits.toe_class = (TOE_TOE_DESC_NUM > 256) ? 256/4 :
+		                                        TOE_TOE_DESC_NUM/4;
+		threshold.bits.intrq = (TOE_INTR_DESC_NUM > 256) ? 256/4 :
+		                                        TOE_INTR_DESC_NUM/4;
+		writel(threshold.bits32, TOE_GLOBAL_BASE + GLOBAL_QUEUE_THRESHOLD_REG);
+
+		FLAG_SWITCH = 0;
+		toe_gmac_sw_reset();
+		toe_init_free_queue();
+		toe_init_swtx_queue();
+#ifdef CONFIG_SL351x_NAT
+		toe_init_hwtx_queue();
+#endif
+		toe_init_default_queue();
+#ifdef CONFIG_SL351x_RXTOE
+		toe_init_interrupt_queue();
+#endif
+		toe_init_interrupt_config();
+
+#if defined(CONFIG_SL351x_NAT) || defined(CONFIG_SL351x_RXTOE)
+		sl351x_hash_init();
+#else
+	{
+		volatile u32 *dp1, *dp2, dword;
+
+		dp1 = (volatile u32 *) TOE_V_BIT_BASE;
+		dp2 = (volatile u32 *) TOE_A_BIT_BASE;
+
+		for (i=0; i<HASH_TOTAL_ENTRIES/32; i++)
+		{
+			*dp1++ = 0;
+			dword = *dp2++;	// read-clear
+		}
+	}
+#endif
+	}
+
+#ifdef SL351x_GMAC_WORKAROUND
+#ifdef CONFIG_SL351x_NAT
+	sl351x_nat_workaround_init();
+#endif
+	init_timer(&gmac_workround_timer_obj);
+	if (chip_version == 1)
+	{
+		gmac_workround_timer_obj.expires = jiffies * 50;
+	}
+	else
+	{
+		gmac_workround_timer_obj.expires = jiffies + 2;
+	}
+	gmac_workround_timer_obj.data = (unsigned long)&gmac_workround_timer_obj;
+	gmac_workround_timer_obj.function = (void *)&sl351x_poll_gmac_hanged_status;
+	add_timer(&gmac_workround_timer_obj);
+#endif
+}
+
+/*----------------------------------------------------------------------
+*	toe_init_free_queue
+*	(1) Initialize the Free Queue Descriptor Base Address & size
+*		Register: TOE_GLOBAL_BASE + 0x0004
+*	(2) Initialize DMA Read/Write pointer for
+*		SW Free Queue and HW Free Queue
+*	(3)	Initialize DMA Descriptors for
+*		SW Free Queue and HW Free Queue,
+*----------------------------------------------------------------------*/
+static void toe_init_free_queue(void)
+{
+	int 				i;
+	TOE_INFO_T			*toe;
+	DMA_RWPTR_T			rwptr_reg;
+//	unsigned int 		rwptr_addr;
+	unsigned int		desc_buf;
+	GMAC_RXDESC_T		*sw_desc_ptr;
+	struct sk_buff 		*skb;
+#ifdef CONFIG_SL351x_NAT
+	GMAC_RXDESC_T		*desc_ptr;
+	unsigned int		buf_ptr;
+#endif
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	desc_buf = (unsigned int)DMA_MALLOC((TOE_SW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T)),
+						(dma_addr_t *)&toe->sw_freeq_desc_base_dma) ;
+	sw_desc_ptr = (GMAC_RXDESC_T *)desc_buf;
+	if (!desc_buf)
+	{
+		printk("%s::DMA_MALLOC fail !\n",__func__);
+		return;
+	}
+	memset((void *)desc_buf, 0, TOE_SW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T));
+
+	// DMA Queue Base & Size
+	writel((toe->sw_freeq_desc_base_dma & DMA_Q_BASE_MASK) | TOE_SW_FREEQ_DESC_POWER,
+			TOE_GLOBAL_BASE + GLOBAL_SW_FREEQ_BASE_SIZE_REG);
+
+	// init descriptor base
+	toe->swfq_desc_base = desc_buf;
+
+	// SW Free Queue Read/Write Pointer
+	rwptr_reg.bits.wptr = TOE_SW_FREEQ_DESC_NUM - 1;
+	rwptr_reg.bits.rptr = 0;
+	toe->fq_rx_rwptr.bits32 = rwptr_reg.bits32;
+	writel(rwptr_reg.bits32, TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+
+	// SW Free Queue Descriptors
+	for (i=0; i<TOE_SW_FREEQ_DESC_NUM; i++)
+	{
+		sw_desc_ptr->word0.bits.buffer_size = SW_RX_BUF_SIZE;
+		sw_desc_ptr->word1.bits.sw_id = i;	// used to locate skb
+		if ( (skb = dev_alloc_skb(SW_RX_BUF_SIZE))==NULL)  /* allocate socket buffer */
+		{
+			printk("%s::skb buffer allocation fail !\n",__func__); while(1);
+		}
+		REG32(skb->data) = (unsigned int)skb;
+		skb_reserve(skb, SKB_RESERVE_BYTES);
+		// toe->rx_skb[i] = skb;
+		sw_desc_ptr->word2.buf_adr = (unsigned int)__pa(skb->data);
+//   		consistent_sync((unsigned int)desc_ptr, sizeof(GMAC_RXDESC_T), PCI_DMA_TODEVICE);
+   		sw_desc_ptr++;
+	}
+
+#ifdef CONFIG_SL351x_NAT
+	if (sizeof(skb->cb) < 64)
+	{
+			printk("==> %s:: sk structure is incorrect -->Change to cb[64] !\n",__func__); while(1);
+	}
+	// init hardware free queues
+	desc_buf = (unsigned int)DMA_MALLOC((TOE_HW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T)),
+						(dma_addr_t *)&toe->hw_freeq_desc_base_dma) ;
+	desc_ptr = (GMAC_RXDESC_T *)desc_buf;
+	if (!desc_buf)
+	{
+		printk("%s::DMA_MALLOC fail !\n",__func__);
+		return;
+	}
+	memset((void *)desc_buf, 0, TOE_HW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T));
+
+	// DMA Queue Base & Size
+	writel((toe->hw_freeq_desc_base_dma & DMA_Q_BASE_MASK) | TOE_HW_FREEQ_DESC_POWER,
+			TOE_GLOBAL_BASE + GLOBAL_HW_FREEQ_BASE_SIZE_REG);
+
+	// init descriptor base
+	toe->hwfq_desc_base = desc_buf;
+
+	// HW Free Queue Read/Write Pointer
+	rwptr_reg.bits.wptr = TOE_HW_FREEQ_DESC_NUM - 1;
+	rwptr_reg.bits.rptr = 0;
+	writel(rwptr_reg.bits32, TOE_GLOBAL_BASE + GLOBAL_HWFQ_RWPTR_REG);
+#ifndef HW_RXBUF_BY_KMALLOC
+	buf_ptr = (unsigned int)DMA_MALLOC(TOE_HW_FREEQ_DESC_NUM * HW_RX_BUF_SIZE,
+						(dma_addr_t *)&toe->hwfq_buf_base_dma);
+#else
+	buf_ptr = (unsigned int)kmalloc(TOE_HW_FREEQ_DESC_NUM * HW_RX_BUF_SIZE, GFP_KERNEL);
+	toe->hwfq_buf_base_dma = __pa(buf_ptr);
+#endif
+	if (!buf_ptr)
+	{
+		printk("===> %s::Failed to allocate HW TxQ Buffers!\n",__func__);
+		while(1);	// could not be happened, if happened, adjust the buffer descriptor number
+		return;
+	}
+
+	toe->hwfq_buf_base = buf_ptr;
+	toe->hwfq_buf_end_dma = toe->hwfq_buf_base_dma + (TOE_HW_FREEQ_DESC_NUM * HW_RX_BUF_SIZE);
+	buf_ptr = (unsigned int)toe->hwfq_buf_base_dma;
+	for (i=0; i<TOE_HW_FREEQ_DESC_NUM; i++)
+	{
+		desc_ptr->word0.bits.buffer_size = HW_RX_BUF_SIZE;
+		desc_ptr->word1.bits.sw_id = i;
+		desc_ptr->word2.buf_adr = (unsigned int)buf_ptr;
+//   		consistent_sync((unsigned int)desc_ptr, sizeof(GMAC_RXDESC_T), PCI_DMA_TODEVICE);
+   		// consistent_sync((unsigned int)buf_ptr, HW_RX_BUF_SIZE, PCI_DMA_TODEVICE);
+   		desc_ptr++;
+   		buf_ptr += HW_RX_BUF_SIZE;
+	}
+#else
+	// DMA Queue Base & Size
+	writel((0) | TOE_SW_FREEQ_DESC_POWER,
+			TOE_GLOBAL_BASE + GLOBAL_HW_FREEQ_BASE_SIZE_REG);
+	rwptr_reg.bits.wptr = TOE_HW_FREEQ_DESC_NUM - 1;
+	rwptr_reg.bits.rptr = 0;
+	writel(rwptr_reg.bits32, TOE_GLOBAL_BASE + GLOBAL_HWFQ_RWPTR_REG);
+
+#endif
+}
+/*----------------------------------------------------------------------
+*	toe_init_swtx_queue
+*	(2) Initialize the GMAC 0/1 SW TXQ Queue Descriptor Base Address & sizeup
+*		GMAC_SW_TX_QUEUE_BASE_REG(0x0050)
+*	(2) Initialize DMA Read/Write pointer for
+*		GMAC 0/1 SW TX Q0-5
+*----------------------------------------------------------------------*/
+static void toe_init_swtx_queue(void)
+{
+	int 				i;
+	TOE_INFO_T			*toe;
+	DMA_RWPTR_T			rwptr_reg;
+	unsigned int 		rwptr_addr;
+	unsigned int		desc_buf;
+
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+
+	// GMAC-0, SW-TXQ
+	// The GMAC-0 and GMAC-0 maybe have different descriptor number
+	// so, not use for instruction
+	desc_buf = (unsigned int)DMA_MALLOC((TOE_GMAC0_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T)),
+						(dma_addr_t *)&toe->gmac[0].swtxq_desc_base_dma) ;
+	toe->gmac[0].swtxq_desc_base = desc_buf;
+	if (!desc_buf)
+	{
+		printk("%s::DMA_MALLOC fail !\n",__func__);
+		return	;
+	}
+	memset((void *)desc_buf, 0,	TOE_GMAC0_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T));
+	writel((toe->gmac[0].swtxq_desc_base_dma & DMA_Q_BASE_MASK) | TOE_GMAC0_SWTXQ_DESC_POWER,
+			TOE_GMAC0_DMA_BASE+ GMAC_SW_TX_QUEUE_BASE_REG);
+
+	// GMAC0 SW TX Q0-Q5
+	rwptr_reg.bits.wptr = 0;
+	rwptr_reg.bits.rptr = 0;
+	rwptr_addr = TOE_GMAC0_DMA_BASE + GMAC_SW_TX_QUEUE0_PTR_REG;
+	for (i=0; i<TOE_SW_TXQ_NUM; i++)
+	{
+		toe->gmac[0].swtxq[i].rwptr_reg = rwptr_addr;
+		toe->gmac[0].swtxq[i].desc_base = desc_buf;
+		toe->gmac[0].swtxq[i].total_desc_num = TOE_GMAC0_SWTXQ_DESC_NUM;
+		desc_buf += TOE_GMAC0_SWTXQ_DESC_NUM * sizeof(GMAC_TXDESC_T);
+		writel(rwptr_reg.bits32, rwptr_addr);
+		rwptr_addr+=4;
+	}
+
+	// GMAC-1, SW-TXQ
+	desc_buf = (unsigned int)DMA_MALLOC((TOE_GMAC1_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T)),
+						(dma_addr_t *)&toe->gmac[1].swtxq_desc_base_dma) ;
+	toe->gmac[1].swtxq_desc_base = desc_buf;
+	if (!desc_buf)
+	{
+		printk("%s::DMA_MALLOC fail !\n",__func__);
+		return	;
+	}
+	memset((void *)desc_buf, 0,	TOE_GMAC1_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T));
+	writel((toe->gmac[1].swtxq_desc_base_dma & DMA_Q_BASE_MASK) | TOE_GMAC1_SWTXQ_DESC_POWER,
+			TOE_GMAC1_DMA_BASE+ GMAC_SW_TX_QUEUE_BASE_REG);
+
+
+	// GMAC1 SW TX Q0-Q5
+	rwptr_reg.bits.wptr = 0;
+	rwptr_reg.bits.rptr = 0;
+	rwptr_addr = TOE_GMAC1_DMA_BASE + GMAC_SW_TX_QUEUE0_PTR_REG;
+	for (i=0; i<TOE_SW_TXQ_NUM; i++)
+	{
+		toe->gmac[1].swtxq[i].rwptr_reg = rwptr_addr;
+		toe->gmac[1].swtxq[i].desc_base = desc_buf;
+		toe->gmac[1].swtxq[i].total_desc_num = TOE_GMAC1_SWTXQ_DESC_NUM;
+		desc_buf += TOE_GMAC1_SWTXQ_DESC_NUM * sizeof(GMAC_TXDESC_T);
+		writel(rwptr_reg.bits32, rwptr_addr);
+		rwptr_addr+=4;
+	}
+}
+
+/*----------------------------------------------------------------------
+*	toe_init_hwtx_queue
+*	(2) Initialize the GMAC 0/1 HW TXQ Queue Descriptor Base Address & size
+*		GMAC_HW_TX_QUEUE_BASE_REG(0x0054)
+*	(2) Initialize DMA Read/Write pointer for
+*		GMAC 0/1 HW TX Q0-5
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static void toe_init_hwtx_queue(void)
+{
+	int 				i;
+	TOE_INFO_T			*toe;
+	DMA_RWPTR_T			rwptr_reg;
+	unsigned int 		rwptr_addr;
+	unsigned int		desc_buf;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	// GMAC-0, HW-TXQ
+	// The GMAC-0 and GMAC-0 maybe have different descriptor number
+	// so, not use for instruction
+	desc_buf = (unsigned int)DMA_MALLOC((TOE_GMAC0_HWTXQ_DESC_NUM * TOE_HW_TXQ_NUM * sizeof(GMAC_TXDESC_T)),
+						(dma_addr_t *)&toe->gmac[0].hwtxq_desc_base_dma) ;
+	toe->gmac[0].hwtxq_desc_base = desc_buf;
+	if (!desc_buf)
+	{
+		printk("%s::DMA_MALLOC fail !\n",__func__);
+		return	;
+	}
+	memset((void *)desc_buf, 0,	TOE_GMAC0_HWTXQ_DESC_NUM * TOE_HW_TXQ_NUM * sizeof(GMAC_TXDESC_T));
+	writel((toe->gmac[0].hwtxq_desc_base_dma & DMA_Q_BASE_MASK) | TOE_GMAC0_HWTXQ_DESC_POWER,
+			TOE_GMAC0_DMA_BASE+ GMAC_HW_TX_QUEUE_BASE_REG);
+
+	// GMAC0 HW TX Q0-Q5
+	rwptr_reg.bits.wptr = 0;
+	rwptr_reg.bits.rptr = 0;
+	rwptr_addr = TOE_GMAC0_DMA_BASE + GMAC_HW_TX_QUEUE0_PTR_REG;
+	for (i=0; i<TOE_HW_TXQ_NUM; i++)
+	{
+		toe->gmac[0].hwtxq[i].desc_base = desc_buf;
+		desc_buf += TOE_GMAC0_HWTXQ_DESC_NUM * sizeof(GMAC_TXDESC_T);
+		writel(rwptr_reg.bits32, rwptr_addr);
+		rwptr_addr+=4;
+	}
+
+	// GMAC-1, HW-TXQ
+	desc_buf = (unsigned int)DMA_MALLOC((TOE_GMAC1_HWTXQ_DESC_NUM * TOE_HW_TXQ_NUM * sizeof(GMAC_TXDESC_T)),
+						(dma_addr_t *)&toe->gmac[1].hwtxq_desc_base_dma) ;
+	toe->gmac[1].hwtxq_desc_base = desc_buf;
+	if (!desc_buf)
+	{
+		printk("%s::DMA_MALLOC fail !\n",__func__);
+		return	;
+	}
+	memset((void *)desc_buf, 0,	TOE_GMAC1_HWTXQ_DESC_NUM * TOE_HW_TXQ_NUM * sizeof(GMAC_TXDESC_T));
+	writel((toe->gmac[1].hwtxq_desc_base_dma & DMA_Q_BASE_MASK) | TOE_GMAC1_HWTXQ_DESC_POWER,
+			TOE_GMAC1_DMA_BASE+ GMAC_HW_TX_QUEUE_BASE_REG);
+
+	// GMAC1 HW TX Q0-Q5
+	rwptr_reg.bits.wptr = 0;
+	rwptr_reg.bits.rptr = 0;
+	rwptr_addr = TOE_GMAC1_DMA_BASE + GMAC_HW_TX_QUEUE0_PTR_REG;
+	for (i=0; i<TOE_HW_TXQ_NUM; i++)
+	{
+		toe->gmac[1].hwtxq[i].desc_base = desc_buf;
+		desc_buf += TOE_GMAC1_HWTXQ_DESC_NUM * sizeof(GMAC_TXDESC_T);
+		writel(rwptr_reg.bits32, rwptr_addr);
+		rwptr_addr+=4;
+	}
+}
+#endif
+
+/*----------------------------------------------------------------------
+*	toe_init_default_queue
+*	(1) Initialize the default 0/1 Queue Header
+*		Register: TOE_DEFAULT_Q0_HDR_BASE (0x60002000)
+*				  TOE_DEFAULT_Q1_HDR_BASE (0x60002008)
+*	(2)	Initialize Descriptors of Default Queue 0/1
+*----------------------------------------------------------------------*/
+static void toe_init_default_queue(void)
+{
+	TOE_INFO_T				*toe;
+	volatile NONTOE_QHDR_T	*qhdr;
+	GMAC_RXDESC_T			*desc_ptr;
+	DMA_SKB_SIZE_T			skb_size;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	desc_ptr = (GMAC_RXDESC_T *)DMA_MALLOC((TOE_DEFAULT_Q0_DESC_NUM * sizeof(GMAC_RXDESC_T)),
+											(dma_addr_t *)&toe->gmac[0].default_desc_base_dma);
+	if (!desc_ptr)
+	{
+		printk("%s::DMA_MALLOC fail !\n",__func__);
+		return	;
+	}
+	memset((void *)desc_ptr, 0, TOE_DEFAULT_Q0_DESC_NUM * sizeof(GMAC_RXDESC_T));
+	toe->gmac[0].default_desc_base = (unsigned int)desc_ptr;
+	toe->gmac[0].default_desc_num = TOE_DEFAULT_Q0_DESC_NUM;
+	qhdr = (volatile NONTOE_QHDR_T *)TOE_DEFAULT_Q0_HDR_BASE;
+	qhdr->word0.base_size = ((unsigned int)toe->gmac[0].default_desc_base_dma & NONTOE_QHDR0_BASE_MASK) | TOE_DEFAULT_Q0_DESC_POWER;
+	qhdr->word1.bits32 = 0;
+	toe->gmac[0].rx_rwptr.bits32 = 0;
+	toe->gmac[0].default_qhdr = (NONTOE_QHDR_T *)qhdr;
+	desc_ptr = (GMAC_RXDESC_T *)DMA_MALLOC((TOE_DEFAULT_Q1_DESC_NUM * sizeof(GMAC_RXDESC_T)),
+											(dma_addr_t *)&toe->gmac[1].default_desc_base_dma);
+	if (!desc_ptr)
+	{
+		printk("%s::DMA_MALLOC fail !\n",__func__);
+		return	;
+	}
+	memset((void *)desc_ptr, 0, TOE_DEFAULT_Q1_DESC_NUM * sizeof(GMAC_RXDESC_T));
+	toe->gmac[1].default_desc_base = (unsigned int)desc_ptr;
+	toe->gmac[1].default_desc_num = TOE_DEFAULT_Q1_DESC_NUM;
+	qhdr = (volatile NONTOE_QHDR_T *)TOE_DEFAULT_Q1_HDR_BASE;
+	qhdr->word0.base_size = ((unsigned int)toe->gmac[1].default_desc_base_dma & NONTOE_QHDR0_BASE_MASK) | TOE_DEFAULT_Q1_DESC_POWER;
+	qhdr->word1.bits32 = 0;
+	toe->gmac[1].rx_rwptr.bits32 = 0;
+	toe->gmac[1].default_qhdr = (NONTOE_QHDR_T *)qhdr;
+
+	skb_size.bits.hw_skb_size = HW_RX_BUF_SIZE;
+	skb_size.bits.sw_skb_size = SW_RX_BUF_SIZE;
+	writel(skb_size.bits32, TOE_GLOBAL_BASE + GLOBAL_DMA_SKB_SIZE_REG);
+}
+
+/*----------------------------------------------------------------------
+*	toe_init_interrupt_queue
+*	(1) Initialize the Interrupt Queue Header
+*		Register: TOE_INTR_Q_HDR_BASE (0x60002080)
+*	(2)	Initialize Descriptors of Interrupt Queues
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_RXTOE
+static void toe_init_interrupt_queue(void)
+{
+	TOE_INFO_T				*toe;
+	volatile NONTOE_QHDR_T	*qhdr;
+	INTR_QHDR_T				*desc_ptr;
+	// unsigned int			desc_buf_addr;
+	int						i;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	desc_ptr = (INTR_QHDR_T *)DMA_MALLOC((TOE_INTR_QUEUE_NUM * TOE_INTR_DESC_NUM * sizeof(INTR_QHDR_T)),
+											(dma_addr_t *)&toe->intr_desc_base_dma);
+	if (!desc_ptr)
+	{
+		printk("%s::DMA_MALLOC interrupt queue fail !\n",__func__);
+		return	;
+	}
+	/*
+	desc_buf_addr = (unsigned int)DMA_MALLOC((TOE_INTR_DESC_NUM * sizeof(TOE_QHDR_T)),
+												(dma_addr_t *)&toe->intr_buf_base_dma);
+	if (!desc_buf_addr)
+	{
+		printk("%s::DMA_MALLOC interrupt desc fail !\n",__func__);
+		return	;
+	}*/
+	printk("#### %s::Intr Q desc %x\n", __func__, (u32)desc_ptr);
+
+	memset((void *)desc_ptr, 0, TOE_INTR_QUEUE_NUM * TOE_INTR_DESC_NUM * sizeof(INTR_QHDR_T));
+//	memset((void *)desc_buf_addr, 0, TOE_INTR_DESC_NUM * sizeof(TOE_QHDR_T));
+	toe->intr_desc_base = (unsigned int)desc_ptr;
+	toe->intr_desc_num = TOE_INTR_DESC_NUM;
+
+	qhdr = (volatile NONTOE_QHDR_T *)TOE_INTR_Q_HDR_BASE;
+//	intrq = (INTRQ_INFO_T*) &toe->intrq[0];
+	for (i=0; i<TOE_INTR_QUEUE_NUM; i++, qhdr++)
+	{
+		qhdr->word0.base_size = ((unsigned int)toe->intr_desc_base_dma & NONTOE_QHDR0_BASE_MASK) | TOE_INTR_DESC_POWER;
+		qhdr->word1.bits32 = 0;
+		desc_ptr += TOE_INTR_DESC_NUM;
+	}
+}
+
+#endif
+
+/*----------------------------------------------------------------------
+*	toe_init_interrupt_config
+*	Interrupt Select Registers are used to map interrupt to int0 or int1
+*	Int0 and int1 are wired to CPU 0/1 GMAC 0/1
+* 	Interrupt Device Inteface data are used to pass device info to
+*		upper device deiver or store status/statistics
+*	ISR handler
+*		(1) If status bit ON but masked, the prinf error message (bug issue)
+*		(2) If select bits are for me, handle it, else skip to let
+*			the other ISR handles it.
+*  Notes:
+*		GMACx init routine (for eCOS) or open routine (for Linux)
+*       enable the interrupt bits only which are selected for him.
+*
+*	Default Setting:
+*		GMAC0 intr bits ------>	int0 ----> eth0
+*		GMAC1 intr bits ------> int1 ----> eth1
+*		TOE intr -------------> int0 ----> eth0
+*		Classification Intr --> int0 ----> eth0
+*		Default Q0 -----------> int0 ----> eth0
+*		Default Q1 -----------> int1 ----> eth1
+*----------------------------------------------------------------------*/
+static void toe_init_interrupt_config(void)
+{
+	// clear all status bits
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_0_REG);
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_1_REG);
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_2_REG);
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_3_REG);
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_4_REG);
+
+	// Init select registers
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_0_REG);
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_1_REG);
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_2_REG);
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_3_REG);
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_4_REG);
+
+	// disable all interrupt
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_0_REG);
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_1_REG);
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_2_REG);
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_3_REG);
+	writel(0, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_4_REG);
+}
+
+/*----------------------------------------------------------------------
+*	toe_init_gmac
+*----------------------------------------------------------------------*/
+static void toe_init_gmac(struct net_device *dev)
+{
+	GMAC_INFO_T		*tp = dev->priv;
+	TOE_INFO_T		*toe;
+	u32 			data;
+
+	if (!gmac_initialized)
+		return ;
+
+	if (!tp->existed)
+		return;
+
+	tp->dev = dev;
+	tp->flow_control_enable = 1;
+	tp->pre_phy_status = LINK_DOWN;
+	tp->full_duplex_status = tp->full_duplex_cfg;
+	tp->speed_status = tp->speed_status;
+
+#if 0
+   /* get mac address from FLASH */
+    gmac_get_mac_address();
+#endif
+
+    /* set PHY register to start autonegition process */
+    gmac_set_phy_status(dev);
+
+	/* GMAC initialization */
+	if ( toe_gmac_init_chip(dev) )
+	{
+		printk ("GMAC %d init fail\n", tp->port_id);
+	}
+
+    /* clear statistic counter */
+    toe_gmac_clear_counter(dev);
+
+	memset((void *)&tp->ifStatics, 0, sizeof(struct net_device_stats));
+
+	/* -----------------------------------------------------------
+	Enable GMAC interrupt & disable loopback
+	Notes:
+		GMACx init routine (for eCOS) or open routine (for Linux)
+		enable the interrupt bits only which are selected for him.
+	--------------------------------------------------------------*/
+	toe = (TOE_INFO_T *)&toe_private_data;
+
+	// Enable Interrupt Bits
+	if (tp->port_id == 0)
+	{
+		tp->intr0_selected =	GMAC0_TXDERR_INT_BIT	 | GMAC0_TXPERR_INT_BIT		|
+	                         	GMAC0_RXDERR_INT_BIT	 | GMAC0_RXPERR_INT_BIT		|
+	                            GMAC0_SWTQ05_FIN_INT_BIT | GMAC0_SWTQ05_EOF_INT_BIT |
+	                            GMAC0_SWTQ04_FIN_INT_BIT | GMAC0_SWTQ04_EOF_INT_BIT |
+	                            GMAC0_SWTQ03_FIN_INT_BIT | GMAC0_SWTQ03_EOF_INT_BIT |
+	                            GMAC0_SWTQ02_FIN_INT_BIT | GMAC0_SWTQ02_EOF_INT_BIT |
+	                            GMAC0_SWTQ01_FIN_INT_BIT | GMAC0_SWTQ01_EOF_INT_BIT |
+	                            GMAC0_SWTQ00_FIN_INT_BIT | GMAC0_SWTQ00_EOF_INT_BIT;
+
+#ifdef GMAX_TX_INTR_DISABLED
+	    tp->intr0_enabled =		0;
+#else
+	    tp->intr0_enabled =		GMAC0_SWTQ00_FIN_INT_BIT | GMAC0_SWTQ00_EOF_INT_BIT;
+#endif
+
+	    tp->intr1_selected =	TOE_IQ_ALL_BITS			 | TOE_CLASS_RX_INT_BITS	|
+	    						GMAC0_HWTQ03_EOF_INT_BIT | GMAC0_HWTQ02_EOF_INT_BIT |
+	    						GMAC0_HWTQ01_EOF_INT_BIT | GMAC0_HWTQ00_EOF_INT_BIT |
+	    						DEFAULT_Q0_INT_BIT;
+	    tp->intr1_enabled = 	DEFAULT_Q0_INT_BIT | TOE_IQ_ALL_BITS;
+	    tp->intr2_selected = 	0xffffffff;	 // TOE Queue 32-63 FUUL Intr
+	    tp->intr2_enabled = 	0xffffffff;
+	    tp->intr3_selected = 	0xffffffff;	 // TOE Queue 0-31 FUUL Intr
+	    tp->intr3_enabled = 	0xffffffff;
+	    tp->intr4_selected = 	GMAC0_INT_BITS | CLASS_RX_FULL_INT_BITS |
+	    						HWFQ_EMPTY_INT_BIT | SWFQ_EMPTY_INT_BIT;
+	    tp->intr4_enabled = 	GMAC0_INT_BITS | SWFQ_EMPTY_INT_BIT;
+
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_0_REG) & ~tp->intr0_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_0_REG);
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_1_REG) & ~tp->intr1_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_1_REG);
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_2_REG) & ~tp->intr2_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_2_REG);
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_3_REG) & ~tp->intr3_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_3_REG);
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_4_REG) & ~tp->intr4_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_4_REG);
+	}
+	else
+	{
+		tp->intr0_selected =	GMAC1_TXDERR_INT_BIT	 | GMAC1_TXPERR_INT_BIT		|
+	                         	GMAC1_RXDERR_INT_BIT	 | GMAC1_RXPERR_INT_BIT		|
+	                            GMAC1_SWTQ15_FIN_INT_BIT | GMAC1_SWTQ15_EOF_INT_BIT |
+	                            GMAC1_SWTQ14_FIN_INT_BIT | GMAC1_SWTQ14_EOF_INT_BIT |
+	                            GMAC1_SWTQ13_FIN_INT_BIT | GMAC1_SWTQ13_EOF_INT_BIT |
+	                            GMAC1_SWTQ12_FIN_INT_BIT | GMAC1_SWTQ12_EOF_INT_BIT |
+	                            GMAC1_SWTQ11_FIN_INT_BIT | GMAC1_SWTQ11_EOF_INT_BIT |
+	                            GMAC1_SWTQ10_FIN_INT_BIT | GMAC1_SWTQ10_EOF_INT_BIT;
+#ifdef GMAX_TX_INTR_DISABLED
+	    tp->intr0_enabled =		0;
+#else
+	    tp->intr0_enabled =		GMAC1_SWTQ10_FIN_INT_BIT | GMAC1_SWTQ10_EOF_INT_BIT;
+#endif
+
+	    tp->intr1_selected =	DEFAULT_Q1_INT_BIT;
+	    tp->intr1_enabled = 	DEFAULT_Q1_INT_BIT | TOE_IQ_ALL_BITS;
+	    tp->intr2_selected = 	0;	 // TOE Queue 32-63 FUUL Intr
+	    tp->intr2_enabled = 	0;
+	    tp->intr3_selected = 	0;	 // TOE Queue 0-31 FUUL Intr
+	    tp->intr3_enabled = 	0;
+	    tp->intr4_selected = 	GMAC1_INT_BITS;
+	    tp->intr4_enabled = 	GMAC1_INT_BITS;
+
+	    if (toe->gmac[0].existed != GMAC_EXISTED_FLAG)
+	    {
+	    	tp->intr1_selected	|= 	TOE_IQ_ALL_BITS | TOE_CLASS_RX_INT_BITS	|
+	    						  	GMAC0_HWTQ03_EOF_INT_BIT | GMAC0_HWTQ02_EOF_INT_BIT |
+	    						  	GMAC0_HWTQ01_EOF_INT_BIT | GMAC0_HWTQ00_EOF_INT_BIT;
+	    	tp->intr1_enabled	|= 	TOE_IQ_ALL_BITS;
+	    	tp->intr2_selected	|= 	0xffffffff;	 // TOE Queue 32-63 FUUL Intr
+	    	tp->intr2_enabled	|= 	0xffffffff;
+	    	tp->intr3_selected	|= 	0xffffffff;	 // TOE Queue 0-31 FUUL Intr
+	    	tp->intr3_enabled	|= 	0xffffffff;
+	    	tp->intr4_selected 	|= 	CLASS_RX_FULL_INT_BITS |
+	    							HWFQ_EMPTY_INT_BIT | SWFQ_EMPTY_INT_BIT;
+	    	tp->intr4_enabled	|= 	SWFQ_EMPTY_INT_BIT;
+		}
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_0_REG) | tp->intr0_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_0_REG);
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_1_REG) | tp->intr1_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_1_REG);
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_2_REG) | tp->intr2_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_2_REG);
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_3_REG) | tp->intr3_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_3_REG);
+	    data = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_4_REG) | tp->intr4_selected;
+	    writel(data, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_SELECT_4_REG);
+	}
+
+	// enable only selected bits
+	gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_ENABLE_0_REG,
+					tp->intr0_enabled, tp->intr0_selected);
+	gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_ENABLE_1_REG,
+					tp->intr1_enabled, tp->intr1_selected);
+	gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_ENABLE_2_REG,
+					tp->intr2_enabled, tp->intr2_selected);
+	gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_ENABLE_3_REG,
+					tp->intr3_enabled, tp->intr3_selected);
+	gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_ENABLE_4_REG,
+					tp->intr4_enabled, tp->intr4_selected);
+
+    /* start DMA process */
+	toe_gmac_hw_start(dev);
+
+    /* enable tx/rx register */
+    toe_gmac_enable_tx_rx(dev);
+
+//	toe_gmac_enable_interrupt(tp->irq);
+
+    return ;
+}
+
+
+/*----------------------------------------------------------------------
+* toe_gmac_sw_reset
+*----------------------------------------------------------------------*/
+static void toe_gmac_sw_reset(void)
+{
+	unsigned int	reg_val;
+	reg_val = readl(GMAC_GLOBAL_BASE_ADDR+GLOBAL_RESET_REG) | 0x00000060;   /* GMAC0 S/W reset */
+    writel(reg_val,GMAC_GLOBAL_BASE_ADDR+GLOBAL_RESET_REG);
+    udelay(100);
+    return;
+}
+
+/*----------------------------------------------------------------------
+*	toe_gmac_init_chip
+*----------------------------------------------------------------------*/
+static int toe_gmac_init_chip(struct net_device *dev)
+{
+	GMAC_INFO_T 	*tp = dev->priv;
+	GMAC_CONFIG2_T	config2_val;
+	GMAC_CONFIG0_T	config0,config0_mask;
+	GMAC_CONFIG1_T	config1;
+	#ifdef CONFIG_SL351x_NAT
+	GMAC_CONFIG3_T	config3_val;
+	#endif
+	GMAC_TX_WCR0_T	hw_weigh;
+	GMAC_TX_WCR1_T	sw_weigh;
+//	GMAC_HASH_ENABLE_REG0_T hash_ctrl;
+//
+#if 0 /* mac address will be set in late_initcall */
+	struct sockaddr sock;
+	// GMAC_AHB_WEIGHT_T	ahb_weight, ahb_weight_mask;
+
+
+	/* set station MAC address1 and address2 */
+	memcpy(&sock.sa_data[0],&eth_mac[tp->port_id][0],6);
+	gmac_set_mac_address(dev,(void *)&sock);
+#endif
+
+	/* set RX_FLTR register to receive all multicast packet */
+	gmac_write_reg(tp->base_addr, GMAC_RX_FLTR, 0x00000007,0x0000001f);
+	//    gmac_write_reg(tp->base_addr, GMAC_RX_FLTR, 0x00000007,0x0000001f);
+	//gmac_write_reg(tp->base_addr, GMAC_RX_FLTR,0x00000007,0x0000001f);
+
+	/* set per packet buffer size */
+	//	config1.bits32 = 0x002004;	//next version
+	/* set flow control threshold */
+	config1.bits32 = 0;
+	config1.bits.set_threshold = 32 / 2;
+	config1.bits.rel_threshold = 32 / 4 * 3;
+	gmac_write_reg(tp->base_addr, GMAC_CONFIG1, config1.bits32, 0xffffffff);
+
+	/* set flow control threshold */
+	config2_val.bits32 = 0;
+	config2_val.bits.set_threshold = TOE_SW_FREEQ_DESC_NUM/2;
+	config2_val.bits.rel_threshold = TOE_SW_FREEQ_DESC_NUM*3/4;
+	gmac_write_reg(tp->base_addr, GMAC_CONFIG2, config2_val.bits32,0xffffffff);
+
+	#ifdef CONFIG_SL351x_NAT
+	/* set HW free queue flow control threshold */
+	config3_val.bits32 = 0;
+	config3_val.bits.set_threshold = PAUSE_SET_HW_FREEQ;
+	config3_val.bits.rel_threshold = PAUSE_REL_HW_FREEQ;
+	gmac_write_reg(tp->base_addr, GMAC_CONFIG3, config3_val.bits32,0xffffffff);
+	#endif
+	/* set_mcast_filter mask*/
+	//	gmac_write_reg(tp->base_addr,GMAC_MCAST_FIL0,0x0,0xffffffff);
+	//  gmac_write_reg(tp->base_addr,GMAC_MCAST_FIL1,0x0,0xffffffff);
+
+	/* disable TX/RX and disable internal loop back */
+	config0.bits32 = 0;
+	config0_mask.bits32 = 0;
+
+	//debug_Aaron
+#ifdef	L2_jumbo_frame
+	config0.bits.max_len = 5;
+#else
+	config0.bits.max_len = 2;
+#endif
+
+	if (tp->flow_control_enable==1)
+	{
+		config0.bits.tx_fc_en = 1; /* enable tx flow control */
+		config0.bits.rx_fc_en = 1; /* enable rx flow control */
+		printk("Enable MAC Flow Control...\n");
+	}
+	else
+	{
+		config0.bits.tx_fc_en = 0; /* disable tx flow control */
+		config0.bits.rx_fc_en = 0; /* disable rx flow control */
+		printk("Disable MAC Flow Control...\n");
+	}
+	config0.bits.dis_rx = 1;  /* disable rx */
+	config0.bits.dis_tx = 1;  /* disable tx */
+	config0.bits.loop_back = 0; /* enable/disable GMAC loopback */
+	config0.bits.rx_err_detect = 1;
+	config0.bits.rgmii_en = 0;
+	config0.bits.rgmm_edge = 1;
+	config0.bits.rxc_inv = 0;
+	config0.bits.ipv4_rx_chksum = 1;  /* enable H/W to check ip checksum */
+	config0.bits.ipv6_rx_chksum = 1;  /* enable H/W to check ip checksum */
+	config0.bits.port0_chk_hwq = 1;	// GaryChen 3/24/2006 2:26PM
+	config0.bits.port1_chk_hwq = 1;	// GaryChen 3/24/2006 2:26PM
+	config0.bits.port0_chk_toeq = 1;
+	config0.bits.port1_chk_toeq = 1;
+	config0.bits.port0_chk_classq = 1;
+	config0.bits.port1_chk_classq = 1;
+
+	config0_mask.bits.max_len = 7;
+	config0_mask.bits.tx_fc_en = 1;
+	config0_mask.bits.rx_fc_en = 1;
+	config0_mask.bits.dis_rx = 1;
+	config0_mask.bits.dis_tx = 1;
+	config0_mask.bits.loop_back = 1;
+	config0_mask.bits.rgmii_en = 1;
+	config0_mask.bits.rgmm_edge = 1;
+	config0_mask.bits.rxc_inv = 1;
+	config0_mask.bits.ipv4_rx_chksum = 1;
+	config0_mask.bits.ipv6_rx_chksum = 1;
+	config0_mask.bits.port0_chk_hwq = 1;
+	config0_mask.bits.port1_chk_hwq = 1;
+	config0_mask.bits.port0_chk_toeq = 1;
+	config0_mask.bits.port1_chk_toeq = 1;
+	config0_mask.bits.port0_chk_classq = 1;
+	config0_mask.bits.port1_chk_classq = 1;
+	config0_mask.bits.rx_err_detect = 1;
+
+	#if 0
+	config0.bits.dis_rx = 1;  /* disable rx */
+	config0.bits.dis_tx = 1;  /* disable tx */
+	config0.bits.loop_back = 0; /* enable/disable GMAC loopback */
+	config0.bits.txc_inv = 0;
+	config0.bits.rgmii_en = 0;
+	config0.bits.rgmm_edge = 1;
+	config0.bits.rxc_inv = 1;
+	config0.bits.ipv4_tss_rx_en = 1;  /* enable H/W to check ip checksum */
+	config0.bits.ipv6_tss_rx_en = 1;  /* enable H/W to check ip checksum */
+
+	config0_mask.bits.max_len = 3;
+	config0_mask.bits.tx_fc_en = 1;
+	config0_mask.bits.rx_fc_en = 1;
+	config0_mask.bits.dis_rx = 1;
+	config0_mask.bits.dis_tx = 1;
+	config0_mask.bits.loop_back = 1;
+	config0_mask.bits.rgmii_en = 1;
+	config0_mask.bits.rgmm_edge = 1;
+	config0_mask.bits.txc_inv = 1;
+	config0_mask.bits.rxc_inv = 1;
+	config0_mask.bits.ipv4_tss_rx_en = 1;
+	config0_mask.bits.ipv6_tss_rx_en = 1;
+	#endif
+
+	gmac_write_reg(tp->base_addr, GMAC_CONFIG0, config0.bits32,config0_mask.bits32);
+
+	#if 1
+	hw_weigh.bits32 = 0;
+	hw_weigh.bits.hw_tq3 = 1;
+	hw_weigh.bits.hw_tq2 = 1;
+	hw_weigh.bits.hw_tq1 = 1;
+	hw_weigh.bits.hw_tq0 = 1;
+	gmac_write_reg(tp->dma_base_addr, GMAC_TX_WEIGHTING_CTRL_0_REG, hw_weigh.bits32, 0xffffffff);
+
+	sw_weigh.bits32 = 0;
+	sw_weigh.bits.sw_tq5 = 1;
+	sw_weigh.bits.sw_tq4 = 1;
+	sw_weigh.bits.sw_tq3 = 1;
+	sw_weigh.bits.sw_tq2 = 1;
+	sw_weigh.bits.sw_tq1 = 1;
+	sw_weigh.bits.sw_tq0 = 1;
+	gmac_write_reg(tp->dma_base_addr, GMAC_TX_WEIGHTING_CTRL_1_REG, sw_weigh.bits32, 0xffffffff);
+	#endif
+
+	#if 0
+	ahb_weight.bits32 = 0;
+	ahb_weight_mask.bits32 = 0;
+	ahb_weight.bits.rx_weight = 1;
+	ahb_weight.bits.tx_weight = 1;
+	ahb_weight.bits.hash_weight = 1;
+	ahb_weight.bits.pre_req = 0x1f;
+	ahb_weight.bits.tqDV_threshold = 0;
+	ahb_weight_mask.bits.rx_weight = 0x1f;
+	ahb_weight_mask.bits.tx_weight = 0x1f;
+	ahb_weight_mask.bits.hash_weight = 0x1f;
+	ahb_weight_mask.bits.pre_req = 0x1f;
+	ahb_weight_mask.bits.tqDV_threshold = 0x1f;
+	gmac_write_reg(tp->dma_base_addr, GMAC_AHB_WEIGHT_REG, ahb_weight.bits32, ahb_weight_mask.bits32);
+	#endif
+
+	#if defined(CONFIG_SL351x_NAT) || defined(CONFIG_SL351x_RXTOE)
+	gmac_write_reg(tp->dma_base_addr, GMAC_SPR0, IPPROTO_TCP, 0xffffffff);
+	#endif
+	#ifdef CONFIG_SL351x_NAT
+	gmac_write_reg(tp->dma_base_addr, GMAC_SPR1, IPPROTO_UDP, 0xffffffff);
+	gmac_write_reg(tp->dma_base_addr, GMAC_SPR2, IPPROTO_GRE, 0xffffffff);
+	gmac_write_reg(tp->dma_base_addr, GMAC_SPR3, 0xff, 0xffffffff);
+	gmac_write_reg(tp->dma_base_addr, GMAC_SPR4, 0xff, 0xffffffff);
+	gmac_write_reg(tp->dma_base_addr, GMAC_SPR5, 0xff, 0xffffffff);
+	gmac_write_reg(tp->dma_base_addr, GMAC_SPR6, 0xff, 0xffffffff);
+	gmac_write_reg(tp->dma_base_addr, GMAC_SPR7, 0xff, 0xffffffff);
+
+	sl351x_nat_init();
+	#endif
+
+	#ifdef CONFIG_SL351x_RXTOE
+	/* setup matching rule to TOE */
+	sl351x_toe_init();
+	#endif
+
+	// for A1 ASIC version
+//	hash_ctrl.bits32 = 0;
+//	hash_ctrl.bits.timing = 6;
+//	gmac_write_reg(tp->dma_base_addr, GMAC_HASH_ENGINE_REG0, hash_ctrl.bits32, 0xffffffff);
+
+	return (0);
+}
+
+/*----------------------------------------------------------------------
+*	toe_gmac_enable_tx_rx
+*----------------------------------------------------------------------*/
+static void toe_gmac_enable_tx_rx(struct net_device *dev)
+{
+	GMAC_INFO_T		*tp = dev->priv;
+	GMAC_CONFIG0_T	config0,config0_mask;
+
+    /* enable TX/RX */
+    config0.bits32 = 0;
+    config0_mask.bits32 = 0;
+    config0.bits.dis_rx = 0;  /* enable rx */
+    config0.bits.dis_tx = 0;  /* enable tx */
+    config0_mask.bits.dis_rx = 1;
+    config0_mask.bits.dis_tx = 1;
+    gmac_write_reg(tp->base_addr, GMAC_CONFIG0, config0.bits32,config0_mask.bits32);
+}
+/*----------------------------------------------------------------------
+*	toe_gmac_disable_rx
+*----------------------------------------------------------------------*/
+#if 0
+static void toe_gmac_disable_rx(struct net_device *dev)
+{
+	GMAC_INFO_T		*tp = dev->priv;
+	GMAC_CONFIG0_T	config0,config0_mask;
+
+    /* enable TX/RX */
+    config0.bits32 = 0;
+    config0_mask.bits32 = 0;
+    config0.bits.dis_rx = 1;  /* disable rx */
+//    config0.bits.dis_tx = 1;  /* disable tx */
+    config0_mask.bits.dis_rx = 1;
+//     config0_mask.bits.dis_tx = 1;
+    gmac_write_reg(tp->base_addr, GMAC_CONFIG0, config0.bits32,config0_mask.bits32);
+}
+#endif
+/*----------------------------------------------------------------------
+*	toe_gmac_enable_rx
+*----------------------------------------------------------------------*/
+#if 0
+static void toe_gmac_enable_rx(struct net_device *dev)
+{
+	GMAC_INFO_T		*tp = dev->priv;
+	GMAC_CONFIG0_T	config0,config0_mask;
+
+    /* enable TX/RX */
+    config0.bits32 = 0;
+    config0_mask.bits32 = 0;
+    config0.bits.dis_rx = 0;  /* enable rx */
+//    config0.bits.dis_tx = 0;  /* enable tx */
+    config0_mask.bits.dis_rx = 1;
+//    config0_mask.bits.dis_tx = 1;
+    gmac_write_reg(tp->base_addr, GMAC_CONFIG0, config0.bits32,config0_mask.bits32);
+}
+#endif
+/*----------------------------------------------------------------------
+*	toe_gmac_disable_tx_rx
+*----------------------------------------------------------------------*/
+static void toe_gmac_disable_tx_rx(struct net_device *dev)
+{
+	GMAC_INFO_T		*tp = dev->priv;
+	GMAC_CONFIG0_T	config0,config0_mask;
+
+    /* enable TX/RX */
+    config0.bits32 = 0;
+    config0_mask.bits32 = 0;
+    config0.bits.dis_rx = 1;  /* disable rx */
+    config0.bits.dis_tx = 1;  /* disable tx */
+    config0_mask.bits.dis_rx = 1;
+    config0_mask.bits.dis_tx = 1;
+    gmac_write_reg(tp->base_addr, GMAC_CONFIG0, config0.bits32,config0_mask.bits32);
+}
+
+/*----------------------------------------------------------------------
+*	toe_gmac_hw_start
+*----------------------------------------------------------------------*/
+static void toe_gmac_hw_start(struct net_device *dev)
+{
+	GMAC_INFO_T				*tp = (GMAC_INFO_T *)dev->priv;
+	GMAC_DMA_CTRL_T			dma_ctrl, dma_ctrl_mask;
+
+
+    /* program dma control register */
+	dma_ctrl.bits32 = 0;
+	dma_ctrl.bits.rd_enable = 1;
+	dma_ctrl.bits.td_enable = 1;
+	dma_ctrl.bits.loopback = 0;
+	dma_ctrl.bits.drop_small_ack = 0;
+	dma_ctrl.bits.rd_prot = 0;
+	dma_ctrl.bits.rd_burst_size = 3;
+	dma_ctrl.bits.rd_insert_bytes = RX_INSERT_BYTES;
+	dma_ctrl.bits.rd_bus = 3;
+	dma_ctrl.bits.td_prot = 0;
+	dma_ctrl.bits.td_burst_size = 3;
+	dma_ctrl.bits.td_bus = 3;
+
+	dma_ctrl_mask.bits32 = 0;
+	dma_ctrl_mask.bits.rd_enable = 1;
+	dma_ctrl_mask.bits.td_enable = 1;
+	dma_ctrl_mask.bits.loopback = 1;
+	dma_ctrl_mask.bits.drop_small_ack = 1;
+	dma_ctrl_mask.bits.rd_prot = 3;
+	dma_ctrl_mask.bits.rd_burst_size = 3;
+	dma_ctrl_mask.bits.rd_insert_bytes = 3;
+	dma_ctrl_mask.bits.rd_bus = 3;
+	dma_ctrl_mask.bits.td_prot = 0x0f;
+	dma_ctrl_mask.bits.td_burst_size = 3;
+	dma_ctrl_mask.bits.td_bus = 3;
+
+	gmac_write_reg(tp->dma_base_addr, GMAC_DMA_CTRL_REG, dma_ctrl.bits32, dma_ctrl_mask.bits32);
+
+    return;
+}
+
+/*----------------------------------------------------------------------
+*	toe_gmac_hw_stop
+*----------------------------------------------------------------------*/
+static void toe_gmac_hw_stop(struct net_device *dev)
+{
+	GMAC_INFO_T			*tp = (GMAC_INFO_T *)dev->priv;
+	GMAC_DMA_CTRL_T		dma_ctrl, dma_ctrl_mask;
+
+    /* program dma control register */
+	dma_ctrl.bits32 = 0;
+	dma_ctrl.bits.rd_enable = 0;
+	dma_ctrl.bits.td_enable = 0;
+
+	dma_ctrl_mask.bits32 = 0;
+	dma_ctrl_mask.bits.rd_enable = 1;
+	dma_ctrl_mask.bits.td_enable = 1;
+
+	gmac_write_reg(tp->dma_base_addr, GMAC_DMA_CTRL_REG, dma_ctrl.bits32, dma_ctrl_mask.bits32);
+}
+
+/*----------------------------------------------------------------------
+*	toe_gmac_clear_counter
+*----------------------------------------------------------------------*/
+static int toe_gmac_clear_counter (struct net_device *dev)
+{
+	GMAC_INFO_T	*tp = (GMAC_INFO_T *)dev->priv;
+
+    /* clear counter */
+    gmac_read_reg(tp->base_addr, GMAC_IN_DISCARDS);
+    gmac_read_reg(tp->base_addr, GMAC_IN_ERRORS);
+    gmac_read_reg(tp->base_addr, GMAC_IN_MCAST);
+    gmac_read_reg(tp->base_addr, GMAC_IN_BCAST);
+    gmac_read_reg(tp->base_addr, GMAC_IN_MAC1);
+    gmac_read_reg(tp->base_addr, GMAC_IN_MAC2);
+		tp->ifStatics.tx_bytes = 0;
+		tp->ifStatics.tx_packets = 0;
+		tp->ifStatics.tx_errors = 0;
+		tp->ifStatics.rx_bytes = 0;
+		tp->ifStatics.rx_packets = 0;
+		tp->ifStatics.rx_errors = 0;
+		tp->ifStatics.rx_dropped = 0;
+	return (0);
+}
+
+
+/*----------------------------------------------------------------------
+*	toe_gmac_tx_complete
+*----------------------------------------------------------------------*/
+static  void toe_gmac_tx_complete(GMAC_INFO_T *tp, unsigned int tx_qid,
+   										struct net_device *dev, int interrupt)
+{
+	volatile GMAC_TXDESC_T	*curr_desc;
+	GMAC_TXDESC_0_T			word0;
+	GMAC_TXDESC_1_T			word1;
+	unsigned int			desc_count;
+//	struct net_device_stats *isPtr = (struct net_device_stats *)&tp->ifStatics;
+	GMAC_SWTXQ_T			*swtxq;
+	DMA_RWPTR_T				rwptr;
+
+	/* get tx H/W completed descriptor virtual address */
+	/* check tx status and accumulate tx statistics */
+	swtxq = &tp->swtxq[tx_qid];
+	swtxq->intr_cnt++;
+	for (;;)
+	{
+		rwptr.bits32 = readl(swtxq->rwptr_reg);
+		if (rwptr.bits.rptr == swtxq->finished_idx)
+			break;
+    	curr_desc = (volatile GMAC_TXDESC_T *)swtxq->desc_base + swtxq->finished_idx;
+//   		consistent_sync((void *)curr_desc, sizeof(GMAC_TXDESC_T), PCI_DMA_FROMDEVICE);
+		word0.bits32 = curr_desc->word0.bits32;
+		word1.bits32 = curr_desc->word1.bits32;
+
+		if (word0.bits.status_tx_ok)
+		{
+			tp->ifStatics.tx_bytes += word1.bits.byte_count;
+			desc_count = word0.bits.desc_count;
+			if (desc_count==0)
+			{
+				printk("%s::Desc 0x%x = 0x%x, desc_count=%d\n",__func__, (u32)curr_desc, word0.bits32, desc_count);
+				while(1);
+			}
+			while (--desc_count)
+			{
+				word0.bits.status_tx_ok = 0;
+				curr_desc->word0.bits32 = word0.bits32;
+				swtxq->finished_idx = RWPTR_ADVANCE_ONE(swtxq->finished_idx, swtxq->total_desc_num);
+				curr_desc = (GMAC_TXDESC_T *)swtxq->desc_base + swtxq->finished_idx;
+				word0.bits32 = curr_desc->word0.bits32;
+#ifdef _DUMP_TX_TCP_CONTENT
+				if (curr_desc->word0.bits.buffer_size < 16)
+				{
+					int a;
+					char *datap;
+					printk("\t Tx Finished Desc 0x%x Len %d Addr 0x%08x: ", (u32)curr_desc, curr_desc->word0.bits.buffer_size, curr_desc->word2.buf_adr);
+					datap = (char *)__va(curr_desc->word2.buf_adr);
+					for (a=0; a<8 && a<curr_desc->word0.bits.buffer_size; a++, datap++)
+					{
+						printk("0x%02x ", *datap);
+					}
+					printk("\n");
+				}
+#endif
+			}
+
+			word0.bits.status_tx_ok = 0;
+			if (swtxq->tx_skb[swtxq->finished_idx])
+			{
+				if (interrupt)
+					dev_kfree_skb_irq(swtxq->tx_skb[swtxq->finished_idx]);
+				else
+					dev_kfree_skb(swtxq->tx_skb[swtxq->finished_idx]);
+				swtxq->tx_skb[swtxq->finished_idx] = NULL;
+			}
+			curr_desc->word0.bits32 = word0.bits32;
+  			swtxq->curr_finished_desc = (GMAC_TXDESC_T *)curr_desc;
+ 			swtxq->total_finished++;
+  			tp->ifStatics.tx_packets++;
+			swtxq->finished_idx = RWPTR_ADVANCE_ONE(swtxq->finished_idx, swtxq->total_desc_num);
+		}
+		else
+		{
+			// tp->ifStatics.tx_errors++;
+			// printk("%s::Tx Descriptor is !!!\n",__func__);
+			// wait ready by breaking
+			break;
+		}
+	}
+
+	if (netif_queue_stopped(dev))
+	{
+		netif_wake_queue(dev);
+	}
+}
+
+/*----------------------------------------------------------------------
+*	gmac_start_xmit
+*----------------------------------------------------------------------*/
+static int gmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+	GMAC_INFO_T 			*tp= dev->priv;
+//	static unsigned int     pcount = 0;
+//	unsigned int			tx_qid;
+    DMA_RWPTR_T				rwptr;
+	volatile GMAC_TXDESC_T	*curr_desc;
+	int 					snd_pages = skb_shinfo(skb)->nr_frags + 1;  /* get number of descriptor */
+	int 					frag_id = 0;
+	int 					len, total_len = skb->len;
+	struct net_device_stats *isPtr;
+	unsigned int			free_desc;
+	GMAC_SWTXQ_T			*swtxq;
+	register unsigned long	word0, word1, word2, word3;
+	unsigned short			wptr, rptr;
+#ifdef	L2_jumbo_frame
+	int header_len = skb->len;
+	struct iphdr	*ip_hdr;
+    struct tcphdr	*tcp_hdr;
+    int             tcp_hdr_len;
+    unsigned char 	*ptr;
+    int             data_len,a;
+    unsigned int    val;
+#endif
+
+#ifdef GMAC_LEN_1_2_ISSUE
+	int						total_pages;
+	total_pages = snd_pages;
+#endif
+
+	isPtr = (struct net_device_stats *)&tp->ifStatics;
+#if 1
+	if (skb->len >= 0x10000)
+	{
+//		spin_unlock(&tp->tx_mutex);
+		isPtr->tx_dropped++;
+		printk("%s::[GMAC %d] skb->len %d >= 64K\n", __func__, tp->port_id, skb->len);
+		netif_stop_queue(dev);
+		return 1;
+    }
+#endif
+
+#if 0
+	if (storlink_ctl.recvfile==2)
+	{
+	    printk("snd_pages=%d skb->len=%d\n",snd_pages,skb->len);
+	}
+#endif
+
+#ifdef GMAC_USE_TXQ0
+	#define tx_qid 	0
+#endif
+
+	swtxq = &tp->swtxq[tx_qid];
+
+//	spin_lock(&tp->tx_mutex);
+    rwptr.bits32 = readl(swtxq->rwptr_reg);
+	wptr = rwptr.bits.wptr;
+	rptr = rwptr.bits.rptr;
+
+	// check finished desc or empty BD
+	// cannot check by read ptr of RW PTR register,
+	// because the HW complete to send but the SW may NOT handle it
+#ifndef	GMAX_TX_INTR_DISABLED
+	if (wptr >= swtxq->finished_idx)
+		free_desc = swtxq->total_desc_num - wptr - 1 + swtxq->finished_idx;
+	else
+		free_desc = swtxq->finished_idx - wptr - 1;
+
+	if (free_desc < snd_pages)
+	{
+//		spin_unlock(&tp->tx_mutex);
+		isPtr->tx_dropped++;
+//		printk("GMAC %d No available descriptor!\n", tp->port_id);
+		netif_stop_queue(dev);
+		return 1;
+    }
+#else
+	toe_gmac_tx_complete(tp, tx_qid, dev, 0);
+
+	if (wptr >= swtxq->finished_idx)
+		free_desc = swtxq->total_desc_num - wptr - 1 + swtxq->finished_idx;
+	else
+		free_desc = swtxq->finished_idx - wptr - 1;
+	if (free_desc < snd_pages)
+	{
+//		spin_unlock(&tp->tx_mutex);
+		isPtr->tx_dropped++;
+//		printk("GMAC %d No available descriptor!\n", tp->port_id);
+		netif_stop_queue(dev);
+		return 1;
+    }
+
+#if 0
+	printk("1: free_desc=%d, wptr=%d, finished_idx=%d\n", free_desc, wptr, swtxq->finished_idx);
+	if ((free_desc < (snd_pages << 2)) ||
+	    (free_desc < (swtxq->total_desc_num >> 2)))
+	{
+		printk("2: free_desc = %d\n", free_desc);
+		toe_gmac_tx_complete(tp, tx_qid, dev, 0);
+		rwptr.bits32 = readl(swtxq->rwptr_reg);
+		wptr = rwptr.bits.wptr;
+		if (wptr>= swtxq->finished_idx)
+			free_desc = swtxq->total_desc_num - wptr -1 + swtxq->finished_idx;
+		else
+			free_desc = swtxq->finished_idx - wptr - 1;
+	}
+#endif
+#endif
+
+#ifdef	L2_jumbo_frame
+//		data_len = skb->len - 14 - ip_hdr->ihl *4 - tcp_hdr_len;
+//		if ((skb->nh.iph->protocol == __constant_htons(ETH_P_IP)) && ((skb->nh.iph->protocol & 0x00ff)  == IPPROTO_TCP))
+//		if (skb->nh.iph->protocol == 0x006 && (skb->nh.iph->protocol == __constant_htons(ETH_P_IP)))
+		if (((skb->nh.iph->protocol & 0x00ff)  == IPPROTO_TCP))
+		{
+				ip_hdr = (struct iphdr*)(skb->nh.iph);
+				tcp_hdr = (struct tcphdr*)(skb->h.th);
+				tcp_hdr_len = TCPHDRLEN(tcp_hdr) * 4;
+				tcp_hdr_len = TCPHDRLEN(tcp_hdr) * 4;
+
+				if ((skb->h.th->syn) && (tcp_hdr_len > 20))
+				{
+					ptr = (unsigned char *)(tcp_hdr+1);
+					if ((ptr[0] == 0x02) && (ptr[1] == 0x04) && (ptr[2] == 0x07) && (ptr[3] == 0xba)) // 0x07 aa=2016-54=1962  ,0x07ba=2032-54=1978
+					{
+						ptr[2]=0x20;	//23
+						ptr[3]=0x00;   	//00
+						printk("-----> Change MSS to 8K \n" );
+					}
+				}
+		}
+//		if ((ip_hdr->protocol & 0x00ff) != IPPROTO_TCP)
+//		if ((tcp_hdr_len > 20) && (skb->h.th->syn))
+#endif
+
+
+#if 0
+	if (snd_pages > 1)
+		printk("-----> snd_pages=%d\n", snd_pages);
+	if (total_len > 1514)
+	{
+		printk("-----> total_len=%d\n", total_len);
+	}
+#endif
+
+    while (snd_pages)
+    {
+    	char *pkt_datap;
+
+    	curr_desc = (GMAC_TXDESC_T *)swtxq->desc_base + wptr;
+//		consistent_sync((void *)curr_desc, sizeof(GMAC_TXDESC_T), PCI_DMA_FROMDEVICE);
+#if 0
+//#if (GMAC_DEBUG==1)
+    	// if curr_desc->word2.buf_adr !=0 means that the ISR does NOT handle it
+    	// if (curr_desc->word2.buf_adr)
+    	if (swtxq->tx_skb[wptr])
+    	{
+    		printk("Error! Stop due to TX descriptor's buffer is not freed!\n");
+    		while(1);
+    		dev_kfree_skb(swtxq->tx_skb[wptr]);
+    		swtxq->tx_skb[wptr] = NULL;
+		}
+#endif
+
+		if (frag_id == 0)
+		{
+#if 0
+			int i;
+			pkt_datap = skb->data;
+			len = total_len;
+			for (i=0; i<skb_shinfo(skb)->nr_frags; i++)
+			{
+				skb_frag_t* frag = &skb_shinfo(skb)->frags[i];
+				len -= frag->size;
+			}
+#else
+			pkt_datap = skb->data;
+			len = total_len - skb->data_len;
+#endif
+		}
+		else
+		{
+			skb_frag_t* frag = &skb_shinfo(skb)->frags[frag_id-1];
+			pkt_datap = page_address(frag->page) + frag->page_offset;
+			len = frag->size;
+			if (len > total_len)
+			{
+				printk("===> Fatal Error! Send Frag size %d > Total Size %d!!!!!\n",
+					len, total_len);
+			}
+		}
+
+		/* set TX descriptor */
+		/* copy packet to descriptor buffer address */
+		// curr_desc->word0.bits32 = len;    /* total frame byte count */
+		word0 = len;
+#ifdef	L2_jumbo_frame
+		word3 = (dev->mtu+14) | EOFIE_BIT;  //2016 ,2032
+#else
+		word3 = 1514 | EOFIE_BIT;
+#endif
+
+#ifdef DO_HW_CHKSUM
+#ifdef	L2_jumbo_frame
+		if (total_len >= (dev->mtu+14) && (skb->nh.iph->protocol == 0x011) && skb->nh.iph && (skb->nh.iph->frag_off & __constant_htons(0x3fff)))
+#else
+		if (total_len <= 1514 && ip_hdr(skb) && (ip_hdr(skb)->frag_off & __constant_htons(0x3fff)))
+#endif
+			word1  = total_len |
+					TSS_IP_CHKSUM_BIT  |
+					TSS_IPV6_ENABLE_BIT |
+					TSS_MTU_ENABLE_BIT;
+		else
+			word1 = total_len |
+					TSS_UDP_CHKSUM_BIT |
+					TSS_TCP_CHKSUM_BIT |
+					TSS_IP_CHKSUM_BIT  |
+					TSS_IPV6_ENABLE_BIT |
+					TSS_MTU_ENABLE_BIT;
+#else
+		word1 = total_len | TSS_MTU_ENABLE_BIT;
+#endif
+		word2 = (unsigned long)__pa(pkt_datap);
+
+		if (frag_id == 0)
+		{
+			word3 |= SOF_BIT;	// SOF
+		}
+
+		if (snd_pages == 1)
+		{
+			word3 |= EOF_BIT;	// EOF
+			swtxq->tx_skb[wptr] = skb;
+#ifdef CONFIG_SL351x_NAT
+			if (nat_cfg.enabled && sl351x_nat_output(skb, tp->port_id))
+				word1 |= TSS_IP_FIXED_LEN_BIT;
+#endif
+		}
+		else
+			swtxq->tx_skb[wptr] = NULL;
+		// word1 |= TSS_IP_FIXED_LEN_BIT;
+#if 1
+#ifdef CONFIG_SL351x_RXTOE
+		// check if this frame has the mission to enable toe hash entry..
+		// if rx_max_pktsize ==0, do not enable RXTOE
+		if (TCP_SKB_CB(skb)->connection && storlink_ctl.rx_max_pktsize) {
+			set_toeq_hdr(TCP_SKB_CB(skb)->connection, &toe_private_data, dev);
+		}
+#endif
+#endif
+#ifdef _DUMP_TX_TCP_CONTENT
+		if (len < 16 && frag_id && skb->h.th && (skb->h.th->source == __constant_htons(445) || skb->h.th->source == __constant_htons(139)))
+		{
+			int a;
+			char *datap;
+			printk("Tx Desc 0x%x Frag %d Len %d [IP-ID 0x%x] 0x%08x: ", (u32)curr_desc, frag_id, len, htons(skb->nh.iph->id), (u32)pkt_datap);
+			datap = (char *)pkt_datap;
+			for (a=0; a<8 && a<len; a++, datap++)
+			{
+				printk("0x%02x ", *datap);
+			}
+			printk("\n");
+		}
+#endif
+
+#ifdef GMAC_LEN_1_2_ISSUE
+		if ((total_pages!=snd_pages) && (len == 1 || len == 2 ) && ((u32)pkt_datap & 0x03))
+		{
+			memcpy((void *)&_debug_prefetch_buf[_debug_prefetch_cnt][0], pkt_datap, len);
+			pkt_datap = (char *)&_debug_prefetch_buf[_debug_prefetch_cnt][0];
+			word2 = (unsigned long)__pa(pkt_datap);
+			_debug_prefetch_cnt++;
+			if (_debug_prefetch_cnt >= _DEBUG_PREFETCH_NUM)
+				_debug_prefetch_cnt = 0;
+		}
+#endif
+
+		consistent_sync((void *)pkt_datap, len, PCI_DMA_TODEVICE);
+		wmb();
+		curr_desc->word0.bits32 = word0;
+		curr_desc->word1.bits32 = word1;
+		curr_desc->word2.bits32 = word2;
+		curr_desc->word3.bits32 = word3;
+		swtxq->curr_tx_desc = (GMAC_TXDESC_T *)curr_desc;
+//		consistent_sync((void *)curr_desc, sizeof(GMAC_TXDESC_T), PCI_DMA_TODEVICE);
+#ifdef _DUMP_TX_TCP_CONTENT
+		if (len < 16 && frag_id && skb->h.th && (skb->h.th->source == __constant_htons(445) || skb->h.th->source == __constant_htons(139)))
+		{
+			int a;
+			char *datap;
+			printk("\t 0x%08x: ", (u32)pkt_datap);
+			datap = (char *)pkt_datap;
+			for (a=0; a<8 && a<len; a++, datap++)
+			{
+				printk("0x%02x ", *datap);
+			}
+			printk("\n");
+		}
+#endif
+		free_desc--;
+		wmb();
+		wptr = RWPTR_ADVANCE_ONE(wptr, swtxq->total_desc_num);
+		frag_id++;
+		snd_pages--;
+	}
+
+    swtxq->total_sent++;
+	SET_WPTR(swtxq->rwptr_reg, wptr);
+	dev->trans_start = jiffies;
+
+
+	// printk("MAC %d Qid %d rwptr = 0x%x, curr_desc=0x%x\n", skb->tx_port_id, tx_qid, rwptr.bits32, curr_desc);
+//#ifdef	GMAX_TX_INTR_DISABLED
+//		toe_gmac_tx_complete(tp, tx_qid, dev, 0);
+//#endif
+	return (0);
+}
+
+/*----------------------------------------------------------------------
+* gmac_set_mac_address
+*----------------------------------------------------------------------*/
+
+static int gmac_set_mac_address(struct net_device *dev, void *addr)
+{
+	GMAC_INFO_T		*tp= dev->priv;
+	struct sockaddr *sock;
+	unsigned int    reg_val;
+    unsigned int    i;
+
+	sock = (struct sockaddr *) addr;
+	for (i = 0; i < 6; i++)
+	{
+		dev->dev_addr[i] = sock->sa_data[i];
+	}
+
+    reg_val = dev->dev_addr[0] + (dev->dev_addr[1]<<8) + (dev->dev_addr[2]<<16) + (dev->dev_addr[3]<<24);
+    gmac_write_reg(tp->base_addr,GMAC_STA_ADD0,reg_val,0xffffffff);
+    reg_val = dev->dev_addr[4] + (dev->dev_addr[5]<<8);
+    gmac_write_reg(tp->base_addr,GMAC_STA_ADD1,reg_val,0x0000ffff);
+	memcpy(&eth_mac[tp->port_id][0],&dev->dev_addr[0],6);
+
+    printk("Storlink %s address = ",dev->name);
+    printk("%02x",dev->dev_addr[0]);
+    printk("%02x",dev->dev_addr[1]);
+    printk("%02x",dev->dev_addr[2]);
+    printk("%02x",dev->dev_addr[3]);
+    printk("%02x",dev->dev_addr[4]);
+    printk("%02x\n",dev->dev_addr[5]);
+
+    return (0);
+}
+
+/*----------------------------------------------------------------------
+* gmac_get_mac_address
+*	get mac address from FLASH
+*----------------------------------------------------------------------*/
+static void gmac_get_mac_address(void)
+{
+#ifdef CONFIG_MTD
+	extern int get_vlaninfo(vlaninfo* vlan);
+    static vlaninfo    vlan[2];
+
+    if (get_vlaninfo(&vlan[0]))
+    {
+        memcpy((void *)&eth_mac[0][0],vlan[0].mac,6);
+        // VLAN_conf[0].vid = vlan[0].vlanid;
+        // VLAN_conf[0].portmap = vlan[0].vlanmap;
+        memcpy((void *)&eth_mac[1][0],vlan[1].mac,6);
+        // VLAN_conf[1].vid = vlan[1].vlanid;
+        // VLAN_conf[1].portmap = vlan[1].vlanmap;
+    }
+#else
+    unsigned int reg_val;
+
+    reg_val = readl(IO_ADDRESS(TOE_GMAC0_BASE)+0xac);
+    eth_mac[0][4] = (reg_val & 0xff00) >> 8;
+    eth_mac[0][5] = reg_val & 0x00ff;
+    reg_val = readl(IO_ADDRESS(SL2312_SECURITY_BASE)+0xac);
+    eth_mac[1][4] = (reg_val & 0xff00) >> 8;
+    eth_mac[1][5] = reg_val & 0x00ff;
+#endif
+    return;
+}
+
+
+/*----------------------------------------------------------------------
+* mac_stop_txdma
+*----------------------------------------------------------------------*/
+void mac_stop_txdma(struct net_device *dev)
+{
+	GMAC_INFO_T				*tp = (GMAC_INFO_T *)dev->priv;
+	GMAC_DMA_CTRL_T			dma_ctrl, dma_ctrl_mask;
+	GMAC_TXDMA_FIRST_DESC_T	txdma_busy;
+
+	// wait idle
+	do
+	{
+		txdma_busy.bits32 = gmac_read_reg(tp->dma_base_addr, GMAC_DMA_TX_FIRST_DESC_REG);
+	} while (txdma_busy.bits.td_busy);
+
+    /* program dma control register */
+	dma_ctrl.bits32 = 0;
+	dma_ctrl.bits.rd_enable = 0;
+	dma_ctrl.bits.td_enable = 0;
+
+	dma_ctrl_mask.bits32 = 0;
+	dma_ctrl_mask.bits.rd_enable = 1;
+	dma_ctrl_mask.bits.td_enable = 1;
+
+	gmac_write_reg(tp->dma_base_addr, GMAC_DMA_CTRL_REG, dma_ctrl.bits32, dma_ctrl_mask.bits32);
+}
+
+/*----------------------------------------------------------------------
+* mac_start_txdma
+*----------------------------------------------------------------------*/
+void mac_start_txdma(struct net_device *dev)
+{
+	GMAC_INFO_T			*tp = (GMAC_INFO_T *)dev->priv;
+	GMAC_DMA_CTRL_T		dma_ctrl, dma_ctrl_mask;
+
+    /* program dma control register */
+	dma_ctrl.bits32 = 0;
+	dma_ctrl.bits.rd_enable = 1;
+	dma_ctrl.bits.td_enable = 1;
+
+	dma_ctrl_mask.bits32 = 0;
+	dma_ctrl_mask.bits.rd_enable = 1;
+	dma_ctrl_mask.bits.td_enable = 1;
+
+	gmac_write_reg(tp->dma_base_addr, GMAC_DMA_CTRL_REG, dma_ctrl.bits32, dma_ctrl_mask.bits32);
+}
+
+
+/*----------------------------------------------------------------------
+* gmac_get_stats
+*----------------------------------------------------------------------*/
+
+struct net_device_stats * gmac_get_stats(struct net_device *dev)
+{
+    GMAC_INFO_T *tp = (GMAC_INFO_T *)dev->priv;
+    // unsigned int        flags;
+    unsigned int        pkt_drop;
+    unsigned int        pkt_error;
+
+    if (netif_running(dev))
+    {
+        /* read H/W counter */
+        // spin_lock_irqsave(&tp->lock,flags);
+        pkt_drop = gmac_read_reg(tp->base_addr,GMAC_IN_DISCARDS);
+        pkt_error = gmac_read_reg(tp->base_addr,GMAC_IN_ERRORS);
+        tp->ifStatics.rx_dropped = tp->ifStatics.rx_dropped + pkt_drop;
+        tp->ifStatics.rx_errors = tp->ifStatics.rx_errors + pkt_error;
+        // spin_unlock_irqrestore(&tp->lock,flags);
+    }
+    return &tp->ifStatics;
+}
+
+
+
+/*----------------------------------------------------------------------
+* mac_get_sw_tx_weight
+*----------------------------------------------------------------------*/
+void mac_get_sw_tx_weight(struct net_device *dev, char *weight)
+{
+	GMAC_TX_WCR1_T	sw_weigh;
+    GMAC_INFO_T		*tp = (GMAC_INFO_T *)dev->priv;
+
+	sw_weigh.bits32 = gmac_read_reg(tp->dma_base_addr, GMAC_TX_WEIGHTING_CTRL_1_REG);
+
+	weight[0] = sw_weigh.bits.sw_tq0;
+   	weight[1] = sw_weigh.bits.sw_tq1;
+   	weight[2] = sw_weigh.bits.sw_tq2;
+   	weight[3] = sw_weigh.bits.sw_tq3;
+   	weight[4] = sw_weigh.bits.sw_tq4;
+   	weight[5] = sw_weigh.bits.sw_tq5;
+}
+
+/*----------------------------------------------------------------------
+* mac_set_sw_tx_weight
+*----------------------------------------------------------------------*/
+void mac_set_sw_tx_weight(struct net_device *dev, char *weight)
+{
+	GMAC_TX_WCR1_T	sw_weigh;
+    GMAC_INFO_T		*tp = (GMAC_INFO_T *)dev->priv;
+
+	sw_weigh.bits32 = 0;
+	sw_weigh.bits.sw_tq0 = weight[0];
+   	sw_weigh.bits.sw_tq1 = weight[1];
+   	sw_weigh.bits.sw_tq2 = weight[2];
+   	sw_weigh.bits.sw_tq3 = weight[3];
+   	sw_weigh.bits.sw_tq4 = weight[4];
+   	sw_weigh.bits.sw_tq5 = weight[5];
+
+	gmac_write_reg(tp->dma_base_addr, GMAC_TX_WEIGHTING_CTRL_1_REG, sw_weigh.bits32, 0xffffffff);
+}
+
+/*----------------------------------------------------------------------
+* mac_get_hw_tx_weight
+*----------------------------------------------------------------------*/
+void mac_get_hw_tx_weight(struct net_device *dev, char *weight)
+{
+	GMAC_TX_WCR0_T	hw_weigh;
+    GMAC_INFO_T		*tp = (GMAC_INFO_T *)dev->priv;
+
+	hw_weigh.bits32 = gmac_read_reg(tp->dma_base_addr, GMAC_TX_WEIGHTING_CTRL_0_REG);
+
+	weight[0] = hw_weigh.bits.hw_tq0;
+   	weight[1] = hw_weigh.bits.hw_tq1;
+   	weight[2] = hw_weigh.bits.hw_tq2;
+   	weight[3] = hw_weigh.bits.hw_tq3;
+}
+
+/*----------------------------------------------------------------------
+* mac_set_hw_tx_weight
+*----------------------------------------------------------------------*/
+void mac_set_hw_tx_weight(struct net_device *dev, char *weight)
+{
+	GMAC_TX_WCR0_T	hw_weigh;
+    GMAC_INFO_T		*tp = (GMAC_INFO_T *)dev->priv;
+
+	hw_weigh.bits32 = 0;
+	hw_weigh.bits.hw_tq0 = weight[0];
+   	hw_weigh.bits.hw_tq1 = weight[1];
+   	hw_weigh.bits.hw_tq2 = weight[2];
+   	hw_weigh.bits.hw_tq3 = weight[3];
+
+	gmac_write_reg(tp->dma_base_addr, GMAC_TX_WEIGHTING_CTRL_0_REG, hw_weigh.bits32, 0xffffffff);
+}
+
+/*----------------------------------------------------------------------
+* mac_start_tx_dma
+*----------------------------------------------------------------------*/
+int mac_start_tx_dma(int mac)
+{
+	GMAC_DMA_CTRL_T dma_ctrl, dma_ctrl_mask;
+
+	dma_ctrl.bits32 = 0;
+	dma_ctrl.bits.td_enable = 1;
+
+	dma_ctrl_mask.bits32 = 0;
+	dma_ctrl_mask.bits.td_enable = 1;
+
+	if (mac == 0)
+    	gmac_write_reg(TOE_GMAC0_DMA_BASE, GMAC_DMA_CTRL_REG, dma_ctrl.bits32, dma_ctrl_mask.bits32);
+	else
+    	gmac_write_reg(TOE_GMAC1_DMA_BASE, GMAC_DMA_CTRL_REG, dma_ctrl.bits32, dma_ctrl_mask.bits32);
+	return	1;
+}
+
+/*----------------------------------------------------------------------
+* mac_stop_tx_dma
+*----------------------------------------------------------------------*/
+int mac_stop_tx_dma(int mac)
+{
+	GMAC_DMA_CTRL_T dma_ctrl, dma_ctrl_mask;
+
+	dma_ctrl.bits32 = 0;
+	dma_ctrl.bits.td_enable = 0;
+
+	dma_ctrl_mask.bits32 = 0;
+	dma_ctrl_mask.bits.td_enable = 1;
+
+	if (mac == 0)
+    	gmac_write_reg(TOE_GMAC0_DMA_BASE, GMAC_DMA_CTRL_REG, dma_ctrl.bits32, dma_ctrl_mask.bits32);
+	else
+    	gmac_write_reg(TOE_GMAC1_DMA_BASE, GMAC_DMA_CTRL_REG, dma_ctrl.bits32, dma_ctrl_mask.bits32);
+	return	1;
+}
+
+/*----------------------------------------------------------------------
+* mac_read_reg(int mac, unsigned int offset)
+*----------------------------------------------------------------------*/
+unsigned int mac_read_reg(int mac, unsigned int offset)
+{
+	switch (mac)
+	{
+		case 0:
+			return gmac_read_reg(TOE_GMAC0_BASE, offset);
+		case 1:
+			return gmac_read_reg(TOE_GMAC1_BASE, offset);
+		default:
+			return 0;
+	}
+}
+
+/*----------------------------------------------------------------------
+* mac_write_reg
+*----------------------------------------------------------------------*/
+void mac_write_reg(int mac, unsigned int offset, unsigned data)
+{
+	switch (mac)
+	{
+		case 0:
+			gmac_write_reg(GMAC0_BASE, offset, data, 0xffffffff);
+			break;
+		case 1:
+			gmac_write_reg(GMAC1_BASE, offset, data, 0xffffffff);
+			break;
+	}
+}
+
+/*----------------------------------------------------------------------
+* mac_read_dma_reg(int mac, unsigned int offset)
+*----------------------------------------------------------------------*/
+u32 mac_read_dma_reg(int mac, unsigned int offset)
+{
+	switch (mac)
+	{
+		case 0:
+			return gmac_read_reg(TOE_GMAC0_DMA_BASE, offset);
+		case 1:
+			return gmac_read_reg(TOE_GMAC1_DMA_BASE, offset);
+		default:
+			return 0;
+	}
+}
+
+/*----------------------------------------------------------------------
+* mac_write_dma_reg
+*----------------------------------------------------------------------*/
+void mac_write_dma_reg(int mac, unsigned int offset, u32 data)
+{
+	switch (mac)
+	{
+		case 0:
+			gmac_write_reg(TOE_GMAC0_DMA_BASE, offset, data, 0xffffffff);
+			break;
+		case 1:
+			gmac_write_reg(TOE_GMAC1_DMA_BASE, offset, data, 0xffffffff);
+			break;
+	}
+}
+
+/*----------------------------------------------------------------------
+* ether_crc
+*----------------------------------------------------------------------*/
+static unsigned const ethernet_polynomial = 0x04c11db7U;
+static unsigned int ether_crc (int length, unsigned char *data)
+{
+	int crc = -1;
+	unsigned int i;
+	unsigned int crc_val=0;
+
+	while (--length >= 0) {
+		unsigned char current_octet = *data++;
+		int bit;
+		for (bit = 0; bit < 8; bit++, current_octet >>= 1)
+			crc = (crc << 1) ^ ((crc < 0) ^ (current_octet & 1) ?
+			     ethernet_polynomial : 0);
+	}
+	crc = ~crc;
+	for (i=0;i<32;i++)
+	{
+		crc_val = crc_val + (((crc << i) & 0x80000000) >> (31-i));
+	}
+	return crc_val;
+}
+
+
+
+/*----------------------------------------------------------------------
+* mac_set_rx_mode
+*----------------------------------------------------------------------*/
+void mac_set_rx_mode(int pid, unsigned int data)
+{
+	unsigned int	base;
+
+	base = (pid == 0) ? GMAC0_BASE : GMAC1_BASE;
+
+    gmac_write_reg(base, GMAC_RX_FLTR, data, 0x0000001f);
+    return;
+}
+
+
+/*----------------------------------------------------------------------
+* gmac_open
+*----------------------------------------------------------------------*/
+
+static int gmac_open (struct net_device *dev)
+{
+	GMAC_INFO_T  *tp = (GMAC_INFO_T *)dev->priv;
+	int    					retval;
+	TOE_INFO_T				*toe;
+	toe = (TOE_INFO_T *)&toe_private_data;
+
+    /* hook ISR */
+	retval = request_irq (dev->irq, toe_gmac_interrupt, IRQF_DISABLED, dev->name, dev);
+	if (retval)
+		return retval;
+
+	toe_init_gmac(dev);
+
+	if(!FLAG_SWITCH)
+	{
+    	init_waitqueue_head (&tp->thr_wait);
+    	init_completion(&tp->thr_exited);
+
+    	tp->time_to_die = 0;
+    	tp->thr_pid = kernel_thread (gmac_phy_thread, dev, CLONE_FS | CLONE_FILES);
+    	if (tp->thr_pid < 0)
+    	{
+    		printk (KERN_WARNING "%s: unable to start kernel thread\n",dev->name);
+    	}
+    }
+
+	tp->operation = 1;
+
+   	netif_start_queue (dev);
+
+	return (0);
+}
+
+/*----------------------------------------------------------------------
+* gmac_close
+*----------------------------------------------------------------------*/
+static int gmac_close(struct net_device *dev)
+{
+    TOE_INFO_T			*toe;
+// 	GMAC_RXDESC_T		*sw_desc_ptr,*desc_ptr;
+// 	unsigned int		buf_ptr;
+	GMAC_INFO_T 	*tp = dev->priv;
+	unsigned int		ret;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+
+	tp->operation = 0;
+
+    netif_stop_queue(dev);
+    mdelay(20);
+
+    /* stop tx/rx packet */
+    toe_gmac_disable_tx_rx(dev);
+    mdelay(20);
+
+    /* stop the chip's Tx and Rx DMA processes */
+	toe_gmac_hw_stop(dev);
+
+	toe_gmac_disable_interrupt(tp->irq);
+
+    /* disable interrupts by clearing the interrupt mask */
+    synchronize_irq();
+    free_irq(dev->irq,dev);
+
+//	DMA_MFREE(sw_desc_ptr, (TOE_SW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T),(dma_addr_t *)&toe->sw_freeq_desc_base_dma);
+//	DMA_MFREE(desc_ptr, TOE_HW_FREEQ_DESC_NUM * sizeof(GMAC_RXDESC_T),(dma_addr_t *)&toe->hw_freeq_desc_base_dma);
+//	DMA_MFREE(buf_ptr, TOE_HW_FREEQ_DESC_NUM) * HW_RX_BUF_SIZE),(dma_addr_t *)&toe->hwfq_buf_base_dma);
+//	DMA_MFREE(toe->gmac[0].swtxq_desc_base , TOE_GMAC0_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T),(dma_addr_t *)&toe->gmac[0].swtxq_desc_base_dma);
+//	DMA_MFREE(toe->gmac[1].swtxq_desc_base , TOE_GMAC0_SWTXQ_DESC_NUM * TOE_SW_TXQ_NUM * sizeof(GMAC_TXDESC_T),(dma_addr_t *)&toe->gmac[1].swtxq_desc_base_dma);
+//	DMA_MFREE(toe->gmac[0].hwtxq_desc_base_dma , TOE_GMAC0_HWTXQ_DESC_NUM * TOE_HW_TXQ_NUM * sizeof(GMAC_TXDESC_T),(dma_addr_t *)&toe->gmac[0].hwtxq_desc_base_dma);
+//	DMA_MFREE(toe->gmac[1].hwtxq_desc_base_dma , TOE_GMAC0_SWTXQ_DESC_NUM * TOE_HW_TXQ_NUM * sizeof(GMAC_TXDESC_T),(dma_addr_t *)&toe->gmac[1].hwtxq_desc_base_dma);
+//	DMA_MFREE(toe->gmac[0].default_desc_base_dma ,TOE_DEFAULT_Q0_DESC_NUM * sizeof(GMAC_TXDESC_T),(dma_addr_t *)&toe->gmac[0].default_desc_base_dma);
+//	DMA_MFREE(toe->gmac[1].default_desc_base_dma , TOE_DEFAULT_Q0_DESC_NUM * sizeof(GMAC_TXDESC_T),(dma_addr_t *)&toe->gmac[1].default_desc_base_dma);
+//	DMA_MFREE(toe->intr_desc_base_dma , TOE_INTR_QUEUE_NUM * TOE_INTR_DESC_NUM * sizeof(GMAC_RXDESC_T),(dma_addr_t *)&toe->intr_desc_base_dma);
+//	DMA_MFREE(toe->intr_buf_base_dma , TOE_INTR_DESC_NUM * sizeof(TOE_QHDR_T),(dma_addr_t *)&toe->intr_buf_base_dma);
+
+	if(!FLAG_SWITCH)
+	{
+    	if (tp->thr_pid >= 0)
+    	{
+		    tp->time_to_die = 1;
+    		wmb();
+    		ret = kill_proc (tp->thr_pid, SIGTERM, 1);
+    		if (ret)
+    		{
+    			printk (KERN_ERR "%s: unable to signal thread\n", dev->name);
+    			return ret;
+    		}
+//    		wait_for_completion (&tp->thr_exited);
+    	}
+    }
+
+    return (0);
+}
+
+/*----------------------------------------------------------------------
+* toe_gmac_fill_free_q
+* allocate buffers for free queue.
+*----------------------------------------------------------------------*/
+static inline void toe_gmac_fill_free_q(void)
+{
+	struct sk_buff	*skb;
+	volatile DMA_RWPTR_T	fq_rwptr;
+	volatile GMAC_RXDESC_T	*fq_desc;
+	unsigned long	flags;
+	// unsigned short max_cnt=TOE_SW_FREEQ_DESC_NUM>>1;
+
+	fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+	spin_lock_irqsave(&gmac_fq_lock, flags);
+	//while ((max_cnt--) && (unsigned short)RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr,
+	//				TOE_SW_FREEQ_DESC_NUM) != fq_rwptr.bits.rptr) {
+	while ((unsigned short)RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr,
+					TOE_SW_FREEQ_DESC_NUM) != fq_rwptr.bits.rptr) {
+		if ((skb = dev_alloc_skb(SW_RX_BUF_SIZE)) == NULL) {
+			printk("%s::skb allocation fail!\n", __func__);
+			//while(1);
+			break;
+		}
+		REG32(skb->data) = (unsigned int)skb;
+		skb_reserve(skb, SKB_RESERVE_BYTES);
+		// fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+		fq_rwptr.bits.wptr = RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr,
+			TOE_SW_FREEQ_DESC_NUM);
+		fq_desc = (GMAC_RXDESC_T*)toe_private_data.swfq_desc_base+fq_rwptr.bits.wptr;
+		fq_desc->word2.buf_adr = (unsigned int)__pa(skb->data);
+		SET_WPTR(TOE_GLOBAL_BASE+GLOBAL_SWFQ_RWPTR_REG, fq_rwptr.bits.wptr);
+		toe_private_data.fq_rx_rwptr.bits32 = fq_rwptr.bits32;
+	}
+	spin_unlock_irqrestore(&gmac_fq_lock, flags);
+}
+// EXPORT_SYMBOL(toe_gmac_fill_free_q);
+
+/*----------------------------------------------------------------------
+* toe_gmac_interrupt
+*----------------------------------------------------------------------*/
+static irqreturn_t toe_gmac_interrupt (int irq, void *dev_instance)
+{
+	struct net_device   *dev = (struct net_device *)dev_instance;
+	TOE_INFO_T			*toe;
+	GMAC_INFO_T 		*tp = (GMAC_INFO_T *)dev->priv;
+	unsigned int		status0;
+	unsigned int		status1;
+	unsigned int		status2;
+	unsigned int		status3;
+	unsigned int		status4;
+
+//	struct net_device_stats *isPtr = (struct net_device_stats *)&tp->ifStatics;
+	toe = (TOE_INFO_T *)&toe_private_data;
+//	handle NAPI
+#ifdef CONFIG_SL_NAPI
+if (storlink_ctl.pauseoff == 1)
+{
+/* disable GMAC interrupt */
+    //toe_gmac_disable_interrupt(tp->irq);
+
+//	isPtr->interrupts++;
+	/* read Interrupt status */
+	status0 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_0_REG);
+	status1 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_1_REG);
+	status2 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_2_REG);
+	status3 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_3_REG);
+	status4 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_4_REG);
+	// prompt warning if status bit ON but not enabled
+#if 0
+	if (status0 & ~tp->intr0_enabled)
+		printk("Intr 0 Status error. status = 0x%X, enable = 0x%X\n",
+				status0, tp->intr0_enabled);
+	if (status1 & ~tp->intr1_enabled)
+		printk("Intr 1 Status error. status = 0x%X, enable = 0x%X\n",
+				status1, tp->intr1_enabled);
+	if (status2 & ~tp->intr2_enabled)
+		printk("Intr 2 Status error. status = 0x%X, enable = 0x%X\n",
+				status2, tp->intr2_enabled);
+	if (status3 & ~tp->intr3_enabled)
+		printk("Intr 3 Status error. status = 0x%X, enable = 0x%X\n",
+				status3, tp->intr3_enabled);
+	if (status4 & ~tp->intr4_enabled)
+		printk("Intr 4 Status error. status = 0x%X, enable = 0x%X\n",
+				status4, tp->intr4_enabled);
+#endif
+
+	if (status0)
+		writel(status0 & tp->intr0_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_0_REG);
+	if (status1)
+		writel(status1 & tp->intr1_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_1_REG);
+	if (status2)
+		writel(status2 & tp->intr2_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_2_REG);
+	if (status3)
+		writel(status3 & tp->intr3_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_3_REG);
+	if (status4)
+		writel(status4 & tp->intr4_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_4_REG);
+#if 0
+	/* handle freeq interrupt first */
+	if (status4 & tp->intr4_enabled) {
+		if ((status4 & SWFQ_EMPTY_INT_BIT) && (tp->intr4_enabled & SWFQ_EMPTY_INT_BIT))
+		{
+			// unsigned long data = REG32(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+			//gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_ENABLE_4_REG,
+			//	tp->intr4_enabled & ~SWFQ_EMPTY_INT_BIT, SWFQ_EMPTY_INT_BIT);
+
+			if (toe->gmac[0].dev && netif_running(toe->gmac[0].dev))
+				toe_gmac_handle_default_rxq(toe->gmac[0].dev,&toe->gmac[0]);
+			if (toe->gmac[1].dev && netif_running(toe->gmac[1].dev))
+				toe_gmac_handle_default_rxq(toe->gmac[1].dev,&toe->gmac[1]);
+			printk("\nfreeq int\n");
+			toe_gmac_fill_free_q();
+			tp->sw_fq_empty_cnt++;
+
+		}
+	}
+#endif
+	// Interrupt Status 1
+	if (status1 & tp->intr1_enabled)
+	{
+		#define G1_INTR0_BITS	(GMAC1_HWTQ13_EOF_INT_BIT | GMAC1_HWTQ12_EOF_INT_BIT | GMAC1_HWTQ11_EOF_INT_BIT | GMAC1_HWTQ10_EOF_INT_BIT)
+		#define G0_INTR0_BITS	(GMAC0_HWTQ03_EOF_INT_BIT | GMAC0_HWTQ02_EOF_INT_BIT | GMAC0_HWTQ01_EOF_INT_BIT | GMAC0_HWTQ00_EOF_INT_BIT)
+		// Handle GMAC 0/1 HW Tx queue 0-3 EOF events
+		// Only count
+		// TOE, Classification, and default queues interrupts are handled by ISR
+		// because they should pass packets to upper layer
+		if (tp->port_id == 0)
+		{
+			if (netif_running(dev) && (status1 & G0_INTR0_BITS) && (tp->intr1_enabled & G0_INTR0_BITS))
+			{
+				if (status1 & GMAC0_HWTQ03_EOF_INT_BIT)
+					tp->hwtxq[3].eof_cnt++;
+				if (status1 & GMAC0_HWTQ02_EOF_INT_BIT)
+					tp->hwtxq[2].eof_cnt++;
+				if (status1 & GMAC0_HWTQ01_EOF_INT_BIT)
+					tp->hwtxq[1].eof_cnt++;
+				if (status1 & GMAC0_HWTQ00_EOF_INT_BIT)
+					tp->hwtxq[0].eof_cnt++;
+			}
+				if (netif_running(dev) && (status1 & DEFAULT_Q0_INT_BIT) && (tp->intr1_enabled & DEFAULT_Q0_INT_BIT))
+				{
+					if (likely(netif_rx_schedule_prep(dev)))
+        			{
+        				unsigned int data32;
+        				// disable GMAC-0 rx interrupt
+        				// class-Q & TOE-Q are implemented in future
+        				//data32 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_1_REG);
+        				//data32 &= ~DEFAULT_Q0_INT_BIT;
+						//writel(data32, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_1_REG);
+						//printk("\%s: DEFAULT_Q0_INT_BIT===================>>>>>>>>>>>>\n",__func__);
+						writel(0x0, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_ENABLE_1_REG);
+						//tp->total_q_cnt_napi=0;
+						//rx_time = jiffies;
+						//rx_old_bytes = isPtr->rx_bytes;
+            			__netif_rx_schedule(dev);
+        			}
+			}
+		}
+		else if (tp->port_id == 1)
+		{
+			if (netif_running(dev) && (status1 & G1_INTR0_BITS) && (tp->intr1_enabled & G1_INTR0_BITS))
+			{
+				if (status1 & GMAC1_HWTQ13_EOF_INT_BIT)
+					tp->hwtxq[3].eof_cnt++;
+				if (status1 & GMAC1_HWTQ12_EOF_INT_BIT)
+					tp->hwtxq[2].eof_cnt++;
+				if (status1 & GMAC1_HWTQ11_EOF_INT_BIT)
+					tp->hwtxq[1].eof_cnt++;
+				if (status1 & GMAC1_HWTQ10_EOF_INT_BIT)
+					tp->hwtxq[0].eof_cnt++;
+			}
+
+			if (netif_running(dev) && (status1 & DEFAULT_Q1_INT_BIT) && (tp->intr1_enabled & DEFAULT_Q1_INT_BIT))
+			{
+				if (likely(netif_rx_schedule_prep(dev)))
+        		{
+        			unsigned int data32;
+         			// disable GMAC-0 rx interrupt
+        			// class-Q & TOE-Q are implemented in future
+        			//data32 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_1_REG);
+        			//data32 &= ~DEFAULT_Q1_INT_BIT;
+					//writel(data32, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_1_REG);
+					//printk("\%s: 1111111111--->DEFAULT_Q1_INT_BIT===================>>>>>>>>>>>>\n",__func__);
+					writel(0x0, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_ENABLE_1_REG);
+					//tp->total_q_cnt_napi=0;
+					//rx_time = jiffies;
+					//rx_old_bytes = isPtr->rx_bytes;
+           			__netif_rx_schedule(dev);
+        		}
+			}
+		}
+	}
+
+	// Interrupt Status 0
+	if (status0 & tp->intr0_enabled)
+	{
+		#define ERR_INTR_BITS	(GMAC0_TXDERR_INT_BIT | GMAC0_TXPERR_INT_BIT |	\
+								 GMAC1_TXDERR_INT_BIT | GMAC1_TXPERR_INT_BIT |	\
+								 GMAC0_RXDERR_INT_BIT | GMAC0_RXPERR_INT_BIT |	\
+								 GMAC1_RXDERR_INT_BIT | GMAC1_RXPERR_INT_BIT)
+
+		if (status0 &  ERR_INTR_BITS)
+		{
+			if ((status0 & GMAC0_TXDERR_INT_BIT) && (tp->intr0_enabled & GMAC0_TXDERR_INT_BIT))
+			{
+				tp->txDerr_cnt[0]++;
+				printk("GMAC0 TX AHB Bus Error!\n");
+			}
+			if ((status0 & GMAC0_TXPERR_INT_BIT) && (tp->intr0_enabled & GMAC0_TXPERR_INT_BIT))
+			{
+				tp->txPerr_cnt[0]++;
+				printk("GMAC0 Tx Descriptor Protocol Error!\n");
+			}
+			if ((status0 & GMAC1_TXDERR_INT_BIT) && (tp->intr0_enabled & GMAC1_TXDERR_INT_BIT))
+			{
+				tp->txDerr_cnt[1]++;
+				printk("GMAC1 Tx AHB Bus Error!\n");
+			}
+			if ((status0 & GMAC1_TXPERR_INT_BIT) && (tp->intr0_enabled & GMAC1_TXPERR_INT_BIT))
+			{
+				tp->txPerr_cnt[1]++;
+				printk("GMAC1 Tx Descriptor Protocol Error!\n");
+			}
+
+			if ((status0 & GMAC0_RXDERR_INT_BIT) && (tp->intr0_enabled & GMAC0_RXDERR_INT_BIT))
+			{
+				tp->RxDerr_cnt[0]++;
+				printk("GMAC0 Rx AHB Bus Error!\n");
+			}
+			if ((status0 & GMAC0_RXPERR_INT_BIT) && (tp->intr0_enabled & GMAC0_RXPERR_INT_BIT))
+			{
+				tp->RxPerr_cnt[0]++;
+				printk("GMAC0 Rx Descriptor Protocol Error!\n");
+			}
+			if ((status0 & GMAC1_RXDERR_INT_BIT) && (tp->intr0_enabled & GMAC1_RXDERR_INT_BIT))
+			{
+				tp->RxDerr_cnt[1]++;
+				printk("GMAC1 Rx AHB Bus Error!\n");
+			}
+			if ((status0 & GMAC1_RXPERR_INT_BIT) && (tp->intr0_enabled & GMAC1_RXPERR_INT_BIT))
+			{
+				tp->RxPerr_cnt[1]++;
+				printk("GMAC1 Rx Descriptor Protocol Error!\n");
+			}
+		}
+
+#ifndef	GMAX_TX_INTR_DISABLED
+		if (tp->port_id == 1 &&	netif_running(dev) &&
+			(((status0 & GMAC1_SWTQ10_FIN_INT_BIT) && (tp->intr0_enabled & GMAC1_SWTQ10_FIN_INT_BIT))
+			||
+			((status0 & GMAC1_SWTQ10_EOF_INT_BIT) && (tp->intr0_enabled & GMAC1_SWTQ10_EOF_INT_BIT))))
+		{
+			toe_gmac_tx_complete(&toe_private_data.gmac[1], 0, dev, 1);
+		}
+
+		if (tp->port_id == 0 &&	netif_running(dev) &&
+			(((status0 & GMAC0_SWTQ00_FIN_INT_BIT) && (tp->intr0_enabled & GMAC0_SWTQ00_FIN_INT_BIT))
+			||
+			((status0 & GMAC0_SWTQ00_EOF_INT_BIT) && (tp->intr0_enabled & GMAC0_SWTQ00_EOF_INT_BIT))))
+		{
+			toe_gmac_tx_complete(&toe_private_data.gmac[0], 0, dev, 1);
+		}
+#endif
+	}
+	// Interrupt Status 4
+	if (status4 & tp->intr4_enabled)
+	{
+		#define G1_INTR4_BITS		(0xff000000)
+		#define G0_INTR4_BITS		(0x00ff0000)
+
+		if (tp->port_id == 0)
+		{
+			if ((status4 & G0_INTR4_BITS) && (tp->intr4_enabled & G0_INTR4_BITS))
+			{
+				if (status4 & GMAC0_RESERVED_INT_BIT)
+					printk("GMAC0_RESERVED_INT_BIT is ON\n");
+				if (status4 & GMAC0_MIB_INT_BIT)
+					tp->mib_full_cnt++;
+				if (status4 & GMAC0_RX_PAUSE_ON_INT_BIT)
+					tp->rx_pause_on_cnt++;
+				if (status4 & GMAC0_TX_PAUSE_ON_INT_BIT)
+					tp->tx_pause_on_cnt++;
+				if (status4 & GMAC0_RX_PAUSE_OFF_INT_BIT)
+					tp->rx_pause_off_cnt++;
+				if (status4 & GMAC0_TX_PAUSE_OFF_INT_BIT)
+					tp->rx_pause_off_cnt++;
+				if (status4 & GMAC0_RX_OVERRUN_INT_BIT)
+					tp->rx_overrun_cnt++;
+				if (status4 & GMAC0_STATUS_CHANGE_INT_BIT)
+					tp->status_changed_cnt++;
+			}
+		}
+		else if (tp->port_id == 1)
+		{
+			if ((status4 & G1_INTR4_BITS) && (tp->intr4_enabled & G1_INTR4_BITS))
+			{
+				if (status4 & GMAC1_RESERVED_INT_BIT)
+					printk("GMAC1_RESERVED_INT_BIT is ON\n");
+				if (status4 & GMAC1_MIB_INT_BIT)
+					tp->mib_full_cnt++;
+				if (status4 & GMAC1_RX_PAUSE_ON_INT_BIT)
+				{
+					printk("Gmac pause on\n");
+					tp->rx_pause_on_cnt++;
+				}
+				if (status4 & GMAC1_TX_PAUSE_ON_INT_BIT)
+				{
+					printk("Gmac pause on\n");
+					tp->tx_pause_on_cnt++;
+				}
+				if (status4 & GMAC1_RX_PAUSE_OFF_INT_BIT)
+				{
+					printk("Gmac pause off\n");
+					tp->rx_pause_off_cnt++;
+				}
+				if (status4 & GMAC1_TX_PAUSE_OFF_INT_BIT)
+				{
+					printk("Gmac pause off\n");
+					tp->rx_pause_off_cnt++;
+				}
+				if (status4 & GMAC1_RX_OVERRUN_INT_BIT)
+				{
+					//printk("Gmac Rx Overrun \n");
+					tp->rx_overrun_cnt++;
+				}
+				if (status4 & GMAC1_STATUS_CHANGE_INT_BIT)
+					tp->status_changed_cnt++;
+			}
+		}
+	}
+
+	//toe_gmac_enable_interrupt(tp->irq);
+#ifdef IxscriptMate_1518
+	if (storlink_ctl.pauseoff == 1)
+	{
+		GMAC_CONFIG0_T config0;
+		config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+		config0.bits.dis_rx = 0;
+		writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+		config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+		config0.bits.dis_rx = 0;
+		writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+	}
+#endif
+//	 enable_irq(gmac_irq[dev_index]);
+	//printk("gmac_interrupt complete!\n\n");
+//	return IRQ_RETVAL(handled);
+	return	IRQ_RETVAL(1);
+}
+else
+{
+#endif	//endif NAPI
+
+
+	/* disable GMAC interrupt */
+    toe_gmac_disable_interrupt(tp->irq);
+
+//	isPtr->interrupts++;
+	/* read Interrupt status */
+	status0 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_0_REG);
+	status1 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_1_REG);
+	status2 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_2_REG);
+	status3 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_3_REG);
+	status4 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_4_REG);
+	// prompt warning if status bit ON but not enabled
+#if 0
+	if (status0 & ~tp->intr0_enabled)
+		printk("Intr 0 Status error. status = 0x%X, enable = 0x%X\n",
+				status0, tp->intr0_enabled);
+	if (status1 & ~tp->intr1_enabled)
+		printk("Intr 1 Status error. status = 0x%X, enable = 0x%X\n",
+				status1, tp->intr1_enabled);
+	if (status2 & ~tp->intr2_enabled)
+		printk("Intr 2 Status error. status = 0x%X, enable = 0x%X\n",
+				status2, tp->intr2_enabled);
+	if (status3 & ~tp->intr3_enabled)
+		printk("Intr 3 Status error. status = 0x%X, enable = 0x%X\n",
+				status3, tp->intr3_enabled);
+	if (status4 & ~tp->intr4_enabled)
+		printk("Intr 4 Status error. status = 0x%X, enable = 0x%X\n",
+				status4, tp->intr4_enabled);
+#endif
+#define	INTERRUPT_SELECT			1
+	if (status0)
+		writel(status0 & tp->intr0_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_0_REG);
+	if (status1)
+		writel(status1 & tp->intr1_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_1_REG);
+	if (status2)
+		writel(status2 & tp->intr2_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_2_REG);
+	if (status3)
+		writel(status3 & tp->intr3_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_3_REG);
+	if (status4)
+		writel(status4 & tp->intr4_enabled, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_STATUS_4_REG);
+
+	/* handle freeq interrupt first */
+	if (status4 & tp->intr4_enabled) {
+		if ((status4 & SWFQ_EMPTY_INT_BIT) && (tp->intr4_enabled & SWFQ_EMPTY_INT_BIT))
+		{
+			// unsigned long data = REG32(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+			//gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_ENABLE_4_REG,
+			//	tp->intr4_enabled & ~SWFQ_EMPTY_INT_BIT, SWFQ_EMPTY_INT_BIT);
+
+			//gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_STATUS_4_REG,
+			//	SWFQ_EMPTY_INT_BIT, SWFQ_EMPTY_INT_BIT);
+			if (toe->gmac[0].dev && netif_running(toe->gmac[0].dev))
+				toe_gmac_handle_default_rxq(toe->gmac[0].dev,&toe->gmac[0]);
+			if (toe->gmac[1].dev && netif_running(toe->gmac[1].dev))
+				toe_gmac_handle_default_rxq(toe->gmac[1].dev,&toe->gmac[1]);
+			printk("\nfreeq int\n");
+			toe_gmac_fill_free_q();
+			tp->sw_fq_empty_cnt++;
+
+			gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_STATUS_4_REG, status4,
+				SWFQ_EMPTY_INT_BIT);
+		}
+	}
+
+	// Interrupt Status 1
+	if (status1 & tp->intr1_enabled)
+	{
+		#define G1_INTR0_BITS	(GMAC1_HWTQ13_EOF_INT_BIT | GMAC1_HWTQ12_EOF_INT_BIT | GMAC1_HWTQ11_EOF_INT_BIT | GMAC1_HWTQ10_EOF_INT_BIT)
+		#define G0_INTR0_BITS	(GMAC0_HWTQ03_EOF_INT_BIT | GMAC0_HWTQ02_EOF_INT_BIT | GMAC0_HWTQ01_EOF_INT_BIT | GMAC0_HWTQ00_EOF_INT_BIT)
+		// Handle GMAC 0/1 HW Tx queue 0-3 EOF events
+		// Only count
+		// TOE, Classification, and default queues interrupts are handled by ISR
+		// because they should pass packets to upper layer
+		if (tp->port_id == 0)
+		{
+#ifndef	INTERRUPT_SELECT
+			if (netif_running(dev) && (status1 & G0_INTR0_BITS) && (tp->intr1_enabled & G0_INTR0_BITS))
+			{
+				if (status1 & GMAC0_HWTQ03_EOF_INT_BIT)
+					tp->hwtxq[3].eof_cnt++;
+				if (status1 & GMAC0_HWTQ02_EOF_INT_BIT)
+					tp->hwtxq[2].eof_cnt++;
+				if (status1 & GMAC0_HWTQ01_EOF_INT_BIT)
+					tp->hwtxq[1].eof_cnt++;
+				if (status1 & GMAC0_HWTQ00_EOF_INT_BIT)
+					tp->hwtxq[0].eof_cnt++;
+#endif	//INTERRUPT_SELECT
+#ifndef	INTERRUPT_SELECT
+			}
+#endif	//INTERRUPT_SELECT
+			if (netif_running(dev) && (status1 & DEFAULT_Q0_INT_BIT) && (tp->intr1_enabled & DEFAULT_Q0_INT_BIT))
+			{
+				tp->default_q_intr_cnt++;
+				toe_gmac_handle_default_rxq(dev, tp);
+			}
+#ifdef CONFIG_SL351x_RXTOE
+			if (netif_running(dev) && (status1 & TOE_IQ_ALL_BITS) &&
+			    (tp->intr1_enabled & TOE_IQ_ALL_BITS)) {
+				//printk("status %x, bits %x, slct %x\n", status1, TOE_IQ_ALL_BITS, tp->intr1_selected);
+				toe_gmac_handle_toeq(dev, tp, status1);
+				//toe_gmac_handle_toeq(dev, toe, tp, status1);
+			}
+#endif
+		}
+		else if (tp->port_id == 1)
+		{
+#ifndef	INTERRUPT_SELECT
+			if (netif_running(dev) && (status1 & G1_INTR0_BITS) && (tp->intr1_enabled & G1_INTR0_BITS))
+			{
+				if (status1 & GMAC1_HWTQ13_EOF_INT_BIT)
+					tp->hwtxq[3].eof_cnt++;
+				if (status1 & GMAC1_HWTQ12_EOF_INT_BIT)
+					tp->hwtxq[2].eof_cnt++;
+				if (status1 & GMAC1_HWTQ11_EOF_INT_BIT)
+					tp->hwtxq[1].eof_cnt++;
+				if (status1 & GMAC1_HWTQ10_EOF_INT_BIT)
+					tp->hwtxq[0].eof_cnt++;
+#endif	//INTERRUPT_SELECT
+#ifndef	INTERRUPT_SELECT
+			}
+#endif	//INTERRUPT_SELECT
+			if (netif_running(dev) && (status1 & DEFAULT_Q1_INT_BIT) && (tp->intr1_enabled & DEFAULT_Q1_INT_BIT))
+			{
+				tp->default_q_intr_cnt++;
+				toe_gmac_handle_default_rxq(dev, tp);
+			}
+#ifdef CONFIG_SL351x_RXTOE
+			if (netif_running(dev) && (status1 & TOE_IQ_ALL_BITS) &&
+			    (tp->intr1_enabled & TOE_IQ_ALL_BITS)) {
+				//printk("status %x, bits %x, slct %x\n", status1, TOE_IQ_ALL_BITS, tp->intr1_selected);
+				toe_gmac_handle_toeq(dev, tp, status1);
+				//toe_gmac_handle_toeq(dev, toe, tp, status1);
+			}
+#endif
+		}
+	}
+
+
+	// Interrupt Status 0
+	if (status0 & tp->intr0_enabled)
+	{
+
+		#define ERR_INTR_BITS	(GMAC0_TXDERR_INT_BIT | GMAC0_TXPERR_INT_BIT |	\
+								 GMAC1_TXDERR_INT_BIT | GMAC1_TXPERR_INT_BIT |	\
+								 GMAC0_RXDERR_INT_BIT | GMAC0_RXPERR_INT_BIT |	\
+								 GMAC1_RXDERR_INT_BIT | GMAC1_RXPERR_INT_BIT)
+#ifndef	INTERRUPT_SELECT
+		if (status0 &  ERR_INTR_BITS)
+		{
+			if ((status0 & GMAC0_TXDERR_INT_BIT) && (tp->intr0_enabled & GMAC0_TXDERR_INT_BIT))
+			{
+				tp->txDerr_cnt[0]++;
+				printk("GMAC0 TX AHB Bus Error!\n");
+			}
+			if ((status0 & GMAC0_TXPERR_INT_BIT) && (tp->intr0_enabled & GMAC0_TXPERR_INT_BIT))
+			{
+				tp->txPerr_cnt[0]++;
+				printk("GMAC0 Tx Descriptor Protocol Error!\n");
+			}
+			if ((status0 & GMAC1_TXDERR_INT_BIT) && (tp->intr0_enabled & GMAC1_TXDERR_INT_BIT))
+			{
+				tp->txDerr_cnt[1]++;
+				printk("GMAC1 Tx AHB Bus Error!\n");
+			}
+			if ((status0 & GMAC1_TXPERR_INT_BIT) && (tp->intr0_enabled & GMAC1_TXPERR_INT_BIT))
+			{
+				tp->txPerr_cnt[1]++;
+				printk("GMAC1 Tx Descriptor Protocol Error!\n");
+			}
+
+			if ((status0 & GMAC0_RXDERR_INT_BIT) && (tp->intr0_enabled & GMAC0_RXDERR_INT_BIT))
+			{
+				tp->RxDerr_cnt[0]++;
+				printk("GMAC0 Rx AHB Bus Error!\n");
+			}
+			if ((status0 & GMAC0_RXPERR_INT_BIT) && (tp->intr0_enabled & GMAC0_RXPERR_INT_BIT))
+			{
+				tp->RxPerr_cnt[0]++;
+				printk("GMAC0 Rx Descriptor Protocol Error!\n");
+			}
+			if ((status0 & GMAC1_RXDERR_INT_BIT) && (tp->intr0_enabled & GMAC1_RXDERR_INT_BIT))
+			{
+				tp->RxDerr_cnt[1]++;
+				printk("GMAC1 Rx AHB Bus Error!\n");
+			}
+			if ((status0 & GMAC1_RXPERR_INT_BIT) && (tp->intr0_enabled & GMAC1_RXPERR_INT_BIT))
+			{
+				tp->RxPerr_cnt[1]++;
+				printk("GMAC1 Rx Descriptor Protocol Error!\n");
+			}
+		}
+#endif	//INTERRUPT_SELECT
+#ifndef	GMAX_TX_INTR_DISABLED
+		if (tp->port_id == 1 &&	netif_running(dev) &&
+			(((status0 & GMAC1_SWTQ10_FIN_INT_BIT) && (tp->intr0_enabled & GMAC1_SWTQ10_FIN_INT_BIT))
+			||
+			((status0 & GMAC1_SWTQ10_EOF_INT_BIT) && (tp->intr0_enabled & GMAC1_SWTQ10_EOF_INT_BIT))))
+		{
+			toe_gmac_tx_complete(&toe_private_data.gmac[1], 0, dev, 1);
+		}
+
+		if (tp->port_id == 0 &&	netif_running(dev) &&
+			(((status0 & GMAC0_SWTQ00_FIN_INT_BIT) && (tp->intr0_enabled & GMAC0_SWTQ00_FIN_INT_BIT))
+			||
+			((status0 & GMAC0_SWTQ00_EOF_INT_BIT) && (tp->intr0_enabled & GMAC0_SWTQ00_EOF_INT_BIT))))
+		{
+			toe_gmac_tx_complete(&toe_private_data.gmac[0], 0, dev, 1);
+		}
+#endif
+		// clear enabled status bits
+	}
+	// Interrupt Status 4
+#ifndef	INTERRUPT_SELECT
+	if (status4 & tp->intr4_enabled)
+	{
+		#define G1_INTR4_BITS		(0xff000000)
+		#define G0_INTR4_BITS		(0x00ff0000)
+
+		if (tp->port_id == 0)
+		{
+			if ((status4 & G0_INTR4_BITS) && (tp->intr4_enabled & G0_INTR4_BITS))
+			{
+				if (status4 & GMAC0_RESERVED_INT_BIT)
+					printk("GMAC0_RESERVED_INT_BIT is ON\n");
+				if (status4 & GMAC0_MIB_INT_BIT)
+					tp->mib_full_cnt++;
+				if (status4 & GMAC0_RX_PAUSE_ON_INT_BIT)
+					tp->rx_pause_on_cnt++;
+				if (status4 & GMAC0_TX_PAUSE_ON_INT_BIT)
+					tp->tx_pause_on_cnt++;
+				if (status4 & GMAC0_RX_PAUSE_OFF_INT_BIT)
+					tp->rx_pause_off_cnt++;
+				if (status4 & GMAC0_TX_PAUSE_OFF_INT_BIT)
+					tp->rx_pause_off_cnt++;
+				if (status4 & GMAC0_RX_OVERRUN_INT_BIT)
+					tp->rx_overrun_cnt++;
+				if (status4 & GMAC0_STATUS_CHANGE_INT_BIT)
+					tp->status_changed_cnt++;
+			}
+		}
+		else if (tp->port_id == 1)
+		{
+			if ((status4 & G1_INTR4_BITS) && (tp->intr4_enabled & G1_INTR4_BITS))
+			{
+				if (status4 & GMAC1_RESERVED_INT_BIT)
+					printk("GMAC1_RESERVED_INT_BIT is ON\n");
+				if (status4 & GMAC1_MIB_INT_BIT)
+					tp->mib_full_cnt++;
+				if (status4 & GMAC1_RX_PAUSE_ON_INT_BIT)
+				{
+					//printk("Gmac pause on\n");
+					tp->rx_pause_on_cnt++;
+				}
+				if (status4 & GMAC1_TX_PAUSE_ON_INT_BIT)
+				{
+					//printk("Gmac pause on\n");
+					tp->tx_pause_on_cnt++;
+				}
+				if (status4 & GMAC1_RX_PAUSE_OFF_INT_BIT)
+				{
+					//printk("Gmac pause off\n");
+					tp->rx_pause_off_cnt++;
+				}
+				if (status4 & GMAC1_TX_PAUSE_OFF_INT_BIT)
+				{
+					//printk("Gmac pause off\n");
+					tp->rx_pause_off_cnt++;
+				}
+				if (status4 & GMAC1_RX_OVERRUN_INT_BIT)
+				{
+					//printk("Gmac Rx Overrun \n");
+					tp->rx_overrun_cnt++;
+				}
+				if (status4 & GMAC1_STATUS_CHANGE_INT_BIT)
+					tp->status_changed_cnt++;
+			}
+		}
+#if 0
+		if ((status4 & SWFQ_EMPTY_INT_BIT) && (tp->intr4_enabled & SWFQ_EMPTY_INT_BIT))
+		{
+			// unsigned long data = REG32(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+//			mac_stop_rxdma(tp->sc);
+			gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_ENABLE_4_REG,
+				tp->intr4_enabled & ~SWFQ_EMPTY_INT_BIT, SWFQ_EMPTY_INT_BIT);
+
+			gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_STATUS_4_REG,
+				SWFQ_EMPTY_INT_BIT, SWFQ_EMPTY_INT_BIT);
+			toe_gmac_fill_free_q();
+			tp->sw_fq_empty_cnt++;
+
+			gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_STATUS_4_REG, status4,
+				SWFQ_EMPTY_INT_BIT);
+//#if 0
+/*			if (netif_running(dev))
+				toe_gmac_handle_default_rxq(dev, tp);
+			printk("SWFQ_EMPTY_INT_BIT is ON!\n");	// should not be happened */
+//#endif
+		}
+#endif
+	}
+#endif	//INTERRUPT_SELECT
+	toe_gmac_enable_interrupt(tp->irq);
+//enable gmac rx function when do RFC 2544
+#ifdef IxscriptMate_1518
+	if (storlink_ctl.pauseoff == 1)
+	{
+		GMAC_CONFIG0_T config0;
+		config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+		config0.bits.dis_rx = 0;
+		writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+		config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+		config0.bits.dis_rx = 0;
+		writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+	}
+#endif
+	//printk("gmac_interrupt complete!\n\n");
+//	return IRQ_RETVAL(handled);
+	return	IRQ_RETVAL(1);
+#ifdef CONFIG_SL_NAPI
+}
+#endif
+}
+
+/*----------------------------------------------------------------------
+*	toe_gmac_handle_default_rxq
+*	(1) Get rx Buffer for default Rx queue
+*	(2) notify or call upper-routine to handle it
+*	(3) get a new buffer and insert it into SW free queue
+*	(4) Note: The SW free queue Read-Write Pointer should be locked when accessing
+*----------------------------------------------------------------------*/
+//static inline void toe_gmac_handle_default_rxq(struct net_device *dev, GMAC_INFO_T *tp)
+static void toe_gmac_handle_default_rxq(struct net_device *dev, GMAC_INFO_T *tp)
+{
+	TOE_INFO_T			*toe;
+    GMAC_RXDESC_T   	*curr_desc;
+	struct sk_buff 		*skb;
+    DMA_RWPTR_T			rwptr;
+	unsigned int 		pkt_size;
+	int					max_cnt;
+	unsigned int        desc_count;
+	unsigned int        good_frame, chksum_status, rx_status;
+	struct net_device_stats *isPtr = (struct net_device_stats *)&tp->ifStatics;
+
+//when do ixia RFC 2544 test and packet size is select 1518 bytes,disable gmace rx function immediately after one interrupt come in.
+#ifdef IxscriptMate_1518
+	if (storlink_ctl.pauseoff == 1)
+	{
+		GMAC_CONFIG0_T config0;
+		config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+		config0.bits.dis_rx = 1;
+		writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+		config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+		config0.bits.dis_rx = 1;
+		writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+	}
+#endif
+	rwptr.bits32 = readl(&tp->default_qhdr->word1);
+#if 0
+	if (rwptr.bits.rptr != tp->rx_rwptr.bits.rptr)
+	{
+		mac_stop_txdma((struct net_device *)tp->dev);
+		printk("Default Queue HW RD ptr (0x%x) != SW RD Ptr (0x%x)\n",
+				rwptr.bits32, tp->rx_rwptr.bits.rptr);
+		while(1);
+	}
+#endif
+	toe = (TOE_INFO_T *)&toe_private_data;
+	max_cnt = DEFAULT_RXQ_MAX_CNT;
+	while ((--max_cnt) && rwptr.bits.rptr != rwptr.bits.wptr)
+//	while (rwptr.bits.rptr != rwptr.bits.wptr)
+	{
+//if packet size is not 1518 for RFC 2544,enable gmac rx function.The other packet size have RX workaround.
+#ifdef IxscriptMate_1518
+    	if (storlink_ctl.pauseoff == 1)
+		{
+			if (pkt_size != 1514)
+			{
+						GMAC_CONFIG0_T config0;
+						config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+						config0.bits.dis_rx = 0;
+						writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+						config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+						config0.bits.dis_rx = 0;
+						writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+			}
+		}
+#endif
+    	curr_desc = (GMAC_RXDESC_T *)tp->default_desc_base + rwptr.bits.rptr;
+//		consistent_sync(curr_desc, sizeof(GMAC_RXDESC_T), PCI_DMA_FROMDEVICE);
+		tp->default_q_cnt++;
+    	tp->rx_curr_desc = (unsigned int)curr_desc;
+    	rx_status = curr_desc->word0.bits.status;
+    	chksum_status = curr_desc->word0.bits.chksum_status;
+    	tp->rx_status_cnt[rx_status]++;
+    	tp->rx_chksum_cnt[chksum_status]++;
+        pkt_size = curr_desc->word1.bits.byte_count;  /*total byte count in a frame*/
+		desc_count = curr_desc->word0.bits.desc_count; /* get descriptor count per frame */
+		good_frame=1;
+		if ((curr_desc->word0.bits32 & (GMAC_RXDESC_0_T_derr | GMAC_RXDESC_0_T_perr))
+			|| (pkt_size < 60)
+		    || (chksum_status & 0x4)
+			|| rx_status)
+		{
+			good_frame = 0;
+			if (curr_desc->word0.bits32 & GMAC_RXDESC_0_T_derr)
+				printk("%s::derr (GMAC-%d)!!!\n", __func__, tp->port_id);
+			if (curr_desc->word0.bits32 & GMAC_RXDESC_0_T_perr)
+				printk("%s::perr (GMAC-%d)!!!\n", __func__, tp->port_id);
+			if (rx_status)
+			{
+				if (rx_status == 4 || rx_status == 7)
+					isPtr->rx_crc_errors++;
+//				printk("%s::Status=%d (GMAC-%d)!!!\n", __func__, rx_status, tp->port_id);
+			}
+#ifdef SL351x_GMAC_WORKAROUND
+			else if (pkt_size < 60)
+			{
+				if (tp->short_frames_cnt < GMAC_SHORT_FRAME_THRESHOLD)
+					tp->short_frames_cnt++;
+				if (tp->short_frames_cnt >= GMAC_SHORT_FRAME_THRESHOLD)
+				{
+					GMAC_CONFIG0_T config0;
+					config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+					config0.bits.dis_rx = 1;
+					writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+					config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+					config0.bits.dis_rx = 1;
+					writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+				}
+			}
+#endif
+//			if (chksum_status)
+//				printk("%s::Checksum Status=%d (GMAC-%d)!!!\n", __func__, chksum_status, tp->port_id);
+			skb = (struct sk_buff *)(REG32(__va(curr_desc->word2.buf_adr) - SKB_RESERVE_BYTES));
+			dev_kfree_skb_irq(skb);
+		}
+		if (good_frame)
+		{
+			if (curr_desc->word0.bits.drop)
+				printk("%s::Drop (GMAC-%d)!!!\n", __func__, tp->port_id);
+//			if (chksum_status)
+//				printk("%s::Checksum Status=%d (GMAC-%d)!!!\n", __func__, chksum_status, tp->port_id);
+
+	    	/* get frame information from the first descriptor of the frame */
+#ifdef SL351x_GMAC_WORKAROUND
+			if (tp->short_frames_cnt >= GMAC_SHORT_FRAME_THRESHOLD)
+			{
+				GMAC_CONFIG0_T config0;
+				config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+				config0.bits.dis_rx = 0;
+				writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+				config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+				config0.bits.dis_rx = 0;
+				writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+			}
+			tp->short_frames_cnt = 0;
+#endif
+			isPtr->rx_packets++;
+			skb = (struct sk_buff *)(REG32(__va(curr_desc->word2.buf_adr - SKB_RESERVE_BYTES)));
+			if (!skb)
+			{
+				printk("Fatal Error!!skb==NULL\n");
+				goto next_rx;
+			}
+			tp->curr_rx_skb = skb;
+			// consistent_sync((void *)__va(curr_desc->word2.buf_adr), pkt_size, PCI_DMA_FROMDEVICE);
+
+	//		curr_desc->word2.buf_adr = 0;
+
+			skb_reserve (skb, RX_INSERT_BYTES);	/* 16 byte align the IP fields. */
+			skb_put(skb, pkt_size);
+			skb->dev = dev;
+			if (chksum_status == RX_CHKSUM_IP_UDP_TCP_OK)
+			{
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+#ifdef CONFIG_SL351x_NAT
+				if (nat_cfg.enabled && curr_desc->word3.bits.l3_offset && curr_desc->word3.bits.l4_offset)
+				{
+					struct iphdr	*ip_hdr;
+					ip_hdr = (struct iphdr *)&(skb->data[curr_desc->word3.bits.l3_offset]);
+					sl351x_nat_input(skb,
+									tp->port_id,
+									(void *)curr_desc->word3.bits.l3_offset,
+								  	(void *)curr_desc->word3.bits.l4_offset);
+				}
+#endif
+				skb->protocol = eth_type_trans(skb,dev); /* set skb protocol */
+#if 0
+#ifdef CONFIG_SL351x_RXTOE
+				if (storlink_ctl.rx_max_pktsize) {
+					struct iphdr	*ip_hdr;
+					struct tcphdr	*tcp_hdr;
+					int ip_hdrlen;
+
+ 					ip_hdr = (struct iphdr*)&(skb->data[0]);
+					if ((skb->protocol == __constant_htons(ETH_P_IP)) &&
+					   ((ip_hdr->protocol & 0x00ff) == IPPROTO_TCP)) {
+						ip_hdrlen = ip_hdr->ihl << 2;
+						tcp_hdr = (struct tcphdr*)&(skb->data[ip_hdrlen]);
+						if (tcp_hdr->syn) {
+							struct toe_conn* connection = init_toeq(ip_hdr->version,
+									ip_hdr, tcp_hdr, toe, &(skb->data[0]) - 14);
+							TCP_SKB_CB(skb)->connection = connection;
+							//	hash_dump_entry(TCP_SKB_CB(skb)->connection->hash_entry_index);
+							//		printk("%s::skb data %x, conn %x, mode %x\n",
+							//			__func__, skb->data, connection, connection->mode);
+						}
+					}
+				}
+#endif
+#endif
+			}
+			else if (chksum_status == RX_CHKSUM_IP_OK_ONLY)
+			{
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+#ifdef CONFIG_SL351x_NAT
+				if (nat_cfg.enabled && curr_desc->word3.bits.l3_offset && curr_desc->word3.bits.l4_offset)
+				{
+					struct iphdr		*ip_hdr;
+					//struct tcphdr		*tcp_hdr;
+					ip_hdr = (struct iphdr *)&(skb->data[curr_desc->word3.bits.l3_offset]);
+					//tcp_hdr = (struct tcphdr *)&(skb->data[curr_desc->word3.bits.l4_offset]);
+					if (ip_hdr->protocol == IPPROTO_UDP)
+					{
+						sl351x_nat_input(skb,
+										tp->port_id,
+										(void *)curr_desc->word3.bits.l3_offset,
+								  		(void *)curr_desc->word3.bits.l4_offset);
+					}
+					else if (ip_hdr->protocol == IPPROTO_GRE)
+					{
+						sl351x_nat_input(skb,
+									tp->port_id,
+									(void *)curr_desc->word3.bits.l3_offset,
+								  	(void *)curr_desc->word3.bits.l4_offset);
+					}
+				}
+#endif
+				skb->protocol = eth_type_trans(skb,dev); /* set skb protocol */
+			}
+			else
+			{
+				skb->protocol = eth_type_trans(skb,dev); /* set skb protocol */
+			}
+
+			netif_rx(skb);  /* socket rx */
+			dev->last_rx = jiffies;
+
+			isPtr->rx_bytes += pkt_size;
+
+        }
+
+next_rx:
+		// advance one for Rx default Q 0/1
+		rwptr.bits.rptr = RWPTR_ADVANCE_ONE(rwptr.bits.rptr, tp->default_desc_num);
+		SET_RPTR(&tp->default_qhdr->word1, rwptr.bits.rptr);
+     	tp->rx_rwptr.bits32 = rwptr.bits32;
+
+		toe_gmac_fill_free_q();
+	}
+}
+
+/*----------------------------------------------------------------------
+* gmac_get_phy_vendor
+*----------------------------------------------------------------------*/
+static unsigned int gmac_get_phy_vendor(int phy_addr)
+{
+    unsigned int	reg_val;
+    reg_val=(mii_read(phy_addr,0x02) << 16) + mii_read(phy_addr,0x03);
+    return reg_val;
+}
+
+/*----------------------------------------------------------------------
+* gmac_set_phy_status
+*----------------------------------------------------------------------*/
+void gmac_set_phy_status(struct net_device *dev)
+{
+	GMAC_INFO_T *tp = dev->priv;
+	GMAC_STATUS_T   status;
+	unsigned int    reg_val, ability,wan_port_id;
+	unsigned int    i = 0;
+
+#ifdef VITESSE_G5SWITCH
+	if((tp->port_id == GMAC_PORT1)&&(Giga_switch==1)){
+#if 0
+		rcv_mask = SPI_read(2,0,0x10);			// Receive mask
+		rcv_mask |= 0x4F;
+		for(i=0;i<4;i++){
+			reg_val = BIT(26)|(i<<21)|(10<<16);
+			SPI_write(3,0,1,reg_val);
+			msleep(10);
+			reg_val = SPI_read(3,0,2);
+			if(reg_val & 0x0c00){
+				printk("Port%d:Giga mode\n",i);
+				SPI_write(1,i,0x00,0x300701B1);
+				SPI_write(1,i,0x00,0x10070181);
+				switch_pre_link[i]=LINK_UP;
+				switch_pre_speed[i]=GMAC_SPEED_1000;
+			}
+			else{
+				reg_val = BIT(26)|(i<<21)|(5<<16);
+				SPI_write(3,0,1,reg_val);
+				msleep(10);
+				ability = (reg_val = SPI_read(3,0,2)&0x5e0) >>5;
+				if ((ability & 0x0C)) /* 100M full duplex */
+				{
+					SPI_write(1,i,0x00,0x30050472);
+					SPI_write(1,i,0x00,0x10050442);
+					printk("Port%d:100M\n",i);
+					switch_pre_link[i]=LINK_UP;
+				switch_pre_speed[i]=GMAC_SPEED_100;
+				}
+				else if((ability & 0x03)) /* 10M full duplex */
+				{
+					SPI_write(1,i,0x00,0x30050473);
+					SPI_write(1,i,0x00,0x10050443);
+					printk("Port%d:10M\n",i);
+					switch_pre_link[i]=LINK_UP;
+					switch_pre_speed[i]=GMAC_SPEED_10;
+				}
+				else{
+					SPI_write(1,i,0x00,BIT(16));			// disable RX
+					SPI_write(5,0,0x0E,BIT(i));			// dicard packet
+					while((SPI_read(5,0,0x0C)&BIT(i))==0)		// wait to be empty
+						msleep(1);
+
+					SPI_write(1,i,0x00,0x20000030);			// PORT_RST
+					switch_pre_link[i]=LINK_DOWN;
+					switch_pre_speed[i]=GMAC_SPEED_10;
+					rcv_mask &= ~BIT(i);
+					SPI_write(2,0,0x10,rcv_mask);			// Disable Receive
+				}
+			}
+		}
+#endif
+		gmac_get_switch_status(dev);
+		gmac_write_reg(tp->base_addr, GMAC_STATUS, 0x7d, 0x0000007f);
+//		SPI_write(2,0,0x10,rcv_mask);			// Enable Receive
+		return ;
+	}
+#endif
+
+	reg_val = gmac_get_phy_vendor(tp->phy_addr);
+	printk("GMAC-%d Addr %d Vendor ID: 0x%08x\n", tp->port_id, tp->phy_addr, reg_val);
+
+	switch (tp->phy_mode)
+	{
+		case GMAC_PHY_GMII:
+		mii_write(tp->phy_addr,0x04,0x05e1); /* advertisement 100M full duplex, pause capable on */
+		#ifdef CONFIG_SL3516_ASIC
+		mii_write(tp->phy_addr,0x09,0x0300); /* advertise 1000M full/half duplex */
+		#else
+		mii_write(tp->phy_addr,0x09,0x0000); /* advertise no 1000M full/half duplex */
+		#endif
+		break;
+		case GMAC_PHY_RGMII_100:
+		mii_write(tp->phy_addr,0x04,0x05e1); /* advertisement 100M full duplex, pause capable on */
+		mii_write(tp->phy_addr,0x09,0x0000); /* advertise no 1000M */
+		break;
+		case GMAC_PHY_RGMII_1000:
+		mii_write(tp->phy_addr,0x04,0x05e1); /* advertisement 100M full duplex, pause capable on */
+		#ifdef CONFIG_SL3516_ASIC
+		mii_write(tp->phy_addr,0x09,0x0300); /* advertise 1000M full/half duplex */
+		#else
+		mii_write(tp->phy_addr,0x09,0x0000); /* advertise no 1000M full/half duplex */
+		#endif
+		break;
+		case GMAC_PHY_MII:
+		default:
+		mii_write(tp->phy_addr,0x04,0x05e1); /* advertisement 100M full duplex, pause capable on */
+		mii_write(tp->phy_addr,0x09,0x0000); /* advertise no 1000M */
+		break;
+	}
+
+	mii_write(tp->phy_addr,0x18,0x0041);	// Phy active led
+	if (tp->auto_nego_cfg)
+	{
+		reg_val = 0x1200 | (1 << 15);
+		mii_write(tp->phy_addr,0x00,reg_val); /* Enable and Restart Auto-Negotiation */
+		mdelay(500);
+		reg_val &= ~(1 << 15);
+		mii_write(tp->phy_addr, 0x00, reg_val);
+	}
+	else
+	{
+		reg_val = 0;
+		reg_val |= (tp->full_duplex_cfg) ? (1 << 8) : 0;
+		reg_val |= (tp->speed_cfg == GMAC_SPEED_1000) ? (1 << 6) : 0;
+		reg_val |= (tp->speed_cfg == GMAC_SPEED_100) ? (1 << 13) : 0;
+		mii_write(tp->phy_addr, 0x00, reg_val);
+		mdelay(100);
+
+		reg_val |= (1 << 15);	// Reset PHY;
+		mii_write(tp->phy_addr, 0x00, reg_val);
+	}
+
+	status.bits32 = 0;
+	/* set PHY operation mode */
+	status.bits.mii_rmii = tp->phy_mode;
+	status.bits.reserved = 1;
+	mdelay(100);
+	while (((reg_val=mii_read(tp->phy_addr,0x01)) & 0x00000004)!=0x04)
+	{
+		msleep(100);
+		i++;
+		if (i > 30)
+		break;
+	}
+	if (i>30)
+	{
+		tp->pre_phy_status = LINK_DOWN;
+		status.bits.link = LINK_DOWN;
+		//		clear_bit(__LINK_STATE_START, &dev->state);
+		printk("Link Down (0x%04x) ", reg_val);
+		if(Giga_switch == 1)
+		{
+				wan_port_id = 1;
+#ifdef CONFIG_SL351x_SYSCTL
+				storlink_ctl.link[ wan_port_id] = 0;
+#endif
+		}
+		else
+		{
+#ifdef CONFIG_SL351x_SYSCTL
+				storlink_ctl.link[ tp->port_id] = 0;
+#endif
+		}
+	}
+	else
+	{
+		tp->pre_phy_status = LINK_UP;
+		status.bits.link = LINK_UP;
+		//		set_bit(__LINK_STATE_START, &dev->state);
+		printk("Link Up (0x%04x) ",reg_val);
+		if(Giga_switch == 1)
+		{
+				wan_port_id = 1;
+#ifdef CONFIG_SL351x_SYSCTL
+				storlink_ctl.link[ wan_port_id] = 1;
+#endif
+		}
+		else
+		{
+#ifdef CONFIG_SL351x_SYSCTL
+				storlink_ctl.link[ tp->port_id] = 1;
+#endif
+		}
+	}
+	//    value = mii_read(PHY_ADDR,0x05);
+
+	ability = (mii_read(tp->phy_addr,0x05) & 0x05E0) >> 5;
+
+	//#ifdef CONFIG_SL3516_ASIC
+	reg_val = mii_read(tp->phy_addr,10);
+	printk("MII REG 10 = 0x%x\n",reg_val);
+
+	if ((reg_val & 0x0800) == 0x0800)
+	{
+		status.bits.duplex = 1;
+		status.bits.speed = 2;
+		if (status.bits.mii_rmii == GMAC_PHY_RGMII_100)
+		status.bits.mii_rmii = GMAC_PHY_RGMII_1000;
+
+		printk(" 1000M/Full \n");
+	}
+	else if ((reg_val & 0x0400) == 0x0400)
+	{
+		status.bits.duplex = 0;
+		status.bits.speed = 2;
+		if (status.bits.mii_rmii == GMAC_PHY_RGMII_100)
+		status.bits.mii_rmii = GMAC_PHY_RGMII_1000;
+
+		printk(" 1000M/Half \n");
+	}
+	//#endif
+	else
+	{
+		#ifdef CONFIG_SL3516_ASIC
+		if (status.bits.mii_rmii == GMAC_PHY_RGMII_1000)
+		status.bits.mii_rmii = GMAC_PHY_RGMII_100;
+		#endif
+		printk("MII REG 5 (bit 5:15) = 0x%x\n", ability);
+		if ((ability & 0x08)==0x08) /* 100M full duplex */
+		{
+			status.bits.duplex = 1;
+			status.bits.speed = 1;
+			printk(" 100M/Full\n");
+
+		}
+		else if ((ability & 0x04)==0x04) /* 100M half duplex */
+		{
+			status.bits.duplex = 0;
+			status.bits.speed = 1;
+			printk(" 100M/Half\n");
+
+		}
+		else if ((ability & 0x02)==0x02) /* 10M full duplex */
+		{
+			status.bits.duplex = 1;
+			status.bits.speed = 0;
+			printk(" 10M/Full\n");
+
+		}
+		else if ((ability & 0x01)==0x01) /* 10M half duplex */
+		{
+			status.bits.duplex = 0;
+			status.bits.speed = 0;
+			printk(" 10M/Half\n");
+
+		}
+	}
+	if ((ability & 0x20)==0x20)
+	{
+		tp->flow_control_enable = 1;
+		printk("Flow Control Enable.\n");
+	}
+	else
+	{
+		tp->flow_control_enable = 0;
+		printk("Flow Control Disable.\n");
+	}
+	tp->full_duplex_status = status.bits.duplex;
+	tp->speed_status = status.bits.speed;
+	if (!tp->auto_nego_cfg)
+	{
+		status.bits.duplex = tp->full_duplex_cfg;
+		status.bits.speed = tp->speed_cfg;
+	}
+	toe_gmac_disable_tx_rx(dev);
+	mdelay(10);
+	gmac_write_reg(tp->base_addr, GMAC_STATUS, status.bits32, 0x0000007f);
+	toe_gmac_enable_tx_rx(dev);
+}
+
+/*----------------------------------------------------------------------
+* gmac_phy_thread
+*----------------------------------------------------------------------*/
+static int gmac_phy_thread (void *data)
+{
+	struct net_device   *dev = data;
+	GMAC_INFO_T *tp = dev->priv;
+	unsigned long       timeout;
+
+    daemonize("%s", dev->name);
+	allow_signal(SIGTERM);
+//	reparent_to_init();
+//	spin_lock_irq(&current->sigmask_lock);
+//	sigemptyset(&current->blocked);
+//	recalc_sigpending(current);
+//	spin_unlock_irq(&current->sigmask_lock);
+//	strncpy (current->comm, dev->name, sizeof(current->comm) - 1);
+//	current->comm[sizeof(current->comm) - 1] = '\0';
+
+	while (1)
+	{
+	    timeout = next_tick;
+		do
+		{
+			timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout);
+		} while (!signal_pending (current) && (timeout > 0));
+
+		if (signal_pending (current))
+		{
+//			spin_lock_irq(&current->sigmask_lock);
+			flush_signals(current);
+//			spin_unlock_irq(&current->sigmask_lock);
+		}
+
+		if (tp->time_to_die)
+			break;
+
+		// printk("%s : Polling MAC %d PHY Status...\n",__func__, tp->port_id);
+		rtnl_lock ();
+		if (tp->auto_nego_cfg){
+#ifdef VITESSE_G5SWITCH
+        		if((tp->port_id == GMAC_PORT1)&&(Giga_switch==1))
+	        		gmac_get_switch_status(dev);
+        		else
+#endif
+        			gmac_get_phy_status(dev); //temp remove
+        	}
+		rtnl_unlock ();
+	}
+	complete_and_exit (&tp->thr_exited, 0);
+}
+
+/*----------------------------------------------------------------------
+* gmac_get_switch_status
+*----------------------------------------------------------------------*/
+#ifdef VITESSE_G5SWITCH
+void gmac_get_switch_status(struct net_device *dev)
+{
+	GMAC_INFO_T *tp = dev->priv;
+	GMAC_CONFIG0_T	config0,config0_mask;
+	unsigned int	switch_port_id;
+	int get_link=0;
+
+	get_link = Get_Set_port_status();
+	if(get_link){				// link
+		if(ever_dwon){
+			ever_dwon = 0;
+			toe_gmac_enable_tx_rx(dev);
+			netif_wake_queue(dev);
+			set_bit(__LINK_STATE_START, &dev->state);
+		}
+	}
+	else{					// all down
+		//printk("All link down\n");
+		ever_dwon=1;
+		netif_stop_queue(dev);
+		toe_gmac_disable_tx_rx(dev);
+		clear_bit(__LINK_STATE_START, &dev->state);
+	}
+
+	if ( tp->port_id == 1 )
+		switch_port_id = 0;
+#ifdef CONFIG_SL351x_SYSCTL
+	if (get_link)
+	{
+		storlink_ctl.link[switch_port_id] = 1;
+	}
+	else
+	{
+		storlink_ctl.link[switch_port_id] = 0;
+	}
+	if (storlink_ctl.pauseoff == 1)
+		{
+			if (tp->flow_control_enable == 1)
+			{
+				config0.bits32 = 0;
+				config0_mask.bits32 = 0;
+				config0.bits.tx_fc_en = 0; /* disable tx flow control */
+				config0.bits.rx_fc_en = 0; /* disable rx flow control */
+				config0_mask.bits.tx_fc_en = 1;
+				config0_mask.bits.rx_fc_en = 1;
+				gmac_write_reg(tp->base_addr, GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+				printk("Disable SWITCH Flow Control...\n");
+			}
+				tp->flow_control_enable = 0;
+		}
+		else
+#endif
+		{
+			if (tp->flow_control_enable == 0)
+			{
+				config0.bits32 = 0;
+				config0_mask.bits32 = 0;
+				config0.bits.tx_fc_en = 1; /* enable tx flow control */
+				config0.bits.rx_fc_en = 1; /* enable rx flow control */
+				config0_mask.bits.tx_fc_en = 1;
+				config0_mask.bits.rx_fc_en = 1;
+				gmac_write_reg(tp->base_addr, GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+				printk("Enable SWITCH Flow Control...\n");
+			}
+			tp->flow_control_enable = 1;
+		}
+	return ;
+
+}
+#endif
+
+/*----------------------------------------------------------------------
+* gmac_get_phy_status
+*----------------------------------------------------------------------*/
+void gmac_get_phy_status(struct net_device *dev)
+{
+	GMAC_INFO_T *tp = dev->priv;
+	GMAC_CONFIG0_T	config0,config0_mask;
+	GMAC_STATUS_T   status, old_status;
+	unsigned int    reg_val,ability,wan_port_id;
+
+	old_status.bits32 = status.bits32 = gmac_read_reg(tp->base_addr, GMAC_STATUS);
+
+
+	/* read PHY status register */
+	reg_val = mii_read(tp->phy_addr,0x01);
+	if ((reg_val & 0x0024) == 0x0024) /* link is established and auto_negotiate process completed */
+	{
+		ability = (mii_read(tp->phy_addr,0x05) & 0x05E0) >> 5;
+		/* read PHY Auto-Negotiation Link Partner Ability Register */
+		#ifdef CONFIG_SL3516_ASIC
+		reg_val = mii_read(tp->phy_addr,10);
+		if ((reg_val & 0x0800) == 0x0800)
+		{
+			status.bits.duplex = 1;
+			status.bits.speed = 2;
+			if (status.bits.mii_rmii == GMAC_PHY_RGMII_100)
+			status.bits.mii_rmii = GMAC_PHY_RGMII_1000;
+		}
+		else if ((reg_val & 0x0400) == 0x0400)
+		{
+			status.bits.duplex = 0;
+			status.bits.speed = 2;
+			if (status.bits.mii_rmii == GMAC_PHY_RGMII_100)
+			status.bits.mii_rmii = GMAC_PHY_RGMII_1000;
+		}
+		else
+		#endif
+		{
+			#ifdef CONFIG_SL3516_ASIC
+			if (status.bits.mii_rmii == GMAC_PHY_RGMII_1000)
+			status.bits.mii_rmii = GMAC_PHY_RGMII_100;
+			#endif
+			if ((ability & 0x08)==0x08) /* 100M full duplex */
+			{
+				status.bits.duplex = 1;
+				status.bits.speed = 1;
+			}
+			else if ((ability & 0x04)==0x04) /* 100M half duplex */
+			{
+				status.bits.duplex = 0;
+				status.bits.speed = 1;
+			}
+			else if ((ability & 0x02)==0x02) /* 10M full duplex */
+			{
+				status.bits.duplex = 1;
+				status.bits.speed = 0;
+			}
+			else if ((ability & 0x01)==0x01) /* 10M half duplex */
+			{
+				status.bits.duplex = 0;
+				status.bits.speed = 0;
+			}
+		}
+		status.bits.link = LINK_UP; /* link up */
+		if(Giga_switch==1)
+		{
+				wan_port_id = 1;
+#ifdef CONFIG_SL351x_SYSCTL
+				storlink_ctl.link[ wan_port_id] = 1;
+		}
+		else
+		{
+				storlink_ctl.link[ tp->port_id] = 1;
+#endif
+		}
+		if ((ability & 0x20)==0x20)
+		{
+			if (tp->flow_control_enable == 0)
+			{
+				config0.bits32 = 0;
+				config0_mask.bits32 = 0;
+				config0.bits.tx_fc_en = 1; /* enable tx flow control */
+				config0.bits.rx_fc_en = 1; /* enable rx flow control */
+				config0_mask.bits.tx_fc_en = 1;
+				config0_mask.bits.rx_fc_en = 1;
+				gmac_write_reg(tp->base_addr, GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+				printk("GMAC-%d Flow Control Enable.\n", tp->port_id);
+			}
+			tp->flow_control_enable = 1;
+		}
+		else
+		{
+			if (tp->flow_control_enable == 1)
+			{
+				config0.bits32 = 0;
+				config0_mask.bits32 = 0;
+				config0.bits.tx_fc_en = 0; /* disable tx flow control */
+				config0.bits.rx_fc_en = 0; /* disable rx flow control */
+				config0_mask.bits.tx_fc_en = 1;
+				config0_mask.bits.rx_fc_en = 1;
+				gmac_write_reg(tp->base_addr, GMAC_CONFIG0,config0.bits32,config0_mask.bits32);
+				printk("GMAC-%d Flow Control Disable.\n", tp->port_id);
+			}
+			tp->flow_control_enable = 0;
+		}
+
+		if (tp->pre_phy_status == LINK_DOWN)
+		{
+			printk("GMAC-%d LINK_UP......\n",tp->port_id);
+			tp->pre_phy_status = LINK_UP;
+		}
+	}
+	else
+	{
+		status.bits.link = LINK_DOWN; /* link down */
+		if(Giga_switch == 1)
+		{
+				wan_port_id = 1;
+#ifdef CONFIG_SL351x_SYSCTL
+				storlink_ctl.link[ wan_port_id] = 0;
+		}
+		else
+		{
+				storlink_ctl.link[ tp->port_id] = 0;
+#endif
+		}
+		if (tp->pre_phy_status == LINK_UP)
+		{
+			printk("GMAC-%d LINK_Down......\n",tp->port_id);
+			tp->pre_phy_status = LINK_DOWN;
+		}
+	}
+
+	tp->full_duplex_status = status.bits.duplex;
+	tp->speed_status = status.bits.speed;
+	if (!tp->auto_nego_cfg)
+	{
+		status.bits.duplex = tp->full_duplex_cfg;
+		status.bits.speed = tp->speed_cfg;
+	}
+
+	if (old_status.bits32 != status.bits32)
+	{
+		netif_stop_queue(dev);
+		toe_gmac_disable_tx_rx(dev);
+		clear_bit(__LINK_STATE_START, &dev->state);
+		printk("GMAC-%d Change Status Bits 0x%x-->0x%x\n",tp->port_id, old_status.bits32, status.bits32);
+		mdelay(10); // let GMAC consume packet
+		gmac_write_reg(tp->base_addr, GMAC_STATUS, status.bits32, 0x0000007f);
+		if (status.bits.link == LINK_UP)
+		{
+			toe_gmac_enable_tx_rx(dev);
+			netif_wake_queue(dev);
+			set_bit(__LINK_STATE_START, &dev->state);
+		}
+	}
+}
+
+/***************************************/
+/* define GPIO module base address     */
+/***************************************/
+#define GPIO_BASE_ADDR  (IO_ADDRESS(SL2312_GPIO_BASE))
+#define GPIO_BASE_ADDR1  (IO_ADDRESS(SL2312_GPIO_BASE1))
+
+/* define GPIO pin for MDC/MDIO */
+#ifdef CONFIG_SL3516_ASIC
+#define H_MDC_PIN           22
+#define H_MDIO_PIN          21
+#define G_MDC_PIN           22
+#define G_MDIO_PIN          21
+#else
+#define H_MDC_PIN           3
+#define H_MDIO_PIN          2
+#define G_MDC_PIN           0
+#define G_MDIO_PIN          1
+#endif
+
+//#define GPIO_MDC             0x80000000
+//#define GPIO_MDIO            0x00400000
+
+static unsigned int GPIO_MDC = 0;
+static unsigned int GPIO_MDIO = 0;
+static unsigned int GPIO_MDC_PIN = 0;
+static unsigned int GPIO_MDIO_PIN = 0;
+
+// For PHY test definition!!
+#define LPC_EECK		0x02
+#define LPC_EDIO		0x04
+#define LPC_GPIO_SET		3
+#define LPC_BASE_ADDR		IO_ADDRESS(IT8712_IO_BASE)
+#define inb_gpio(x)		inb(LPC_BASE_ADDR + IT8712_GPIO_BASE + x)
+#define outb_gpio(x, y)		outb(y, LPC_BASE_ADDR + IT8712_GPIO_BASE + x)
+
+enum GPIO_REG
+{
+    GPIO_DATA_OUT   = 0x00,
+    GPIO_DATA_IN    = 0x04,
+    GPIO_PIN_DIR    = 0x08,
+    GPIO_BY_PASS    = 0x0c,
+    GPIO_DATA_SET   = 0x10,
+    GPIO_DATA_CLEAR = 0x14,
+};
+/***********************/
+/*    MDC : GPIO[31]   */
+/*    MDIO: GPIO[22]   */
+/***********************/
+
+/***************************************************
+* All the commands should have the frame structure:
+*<PRE><ST><OP><PHYAD><REGAD><TA><DATA><IDLE>
+****************************************************/
+
+/*****************************************************************
+* Inject a bit to NWay register through CSR9_MDC,MDIO
+*******************************************************************/
+void mii_serial_write(char bit_MDO) // write data into mii PHY
+{
+#ifdef CONFIG_SL2312_LPC_IT8712
+	unsigned char iomode,status;
+
+	iomode = LPCGetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET);
+	iomode |= (LPC_EECK|LPC_EDIO) ;				// Set EECK,EDIO,EECS output
+	LPCSetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET, iomode);
+
+	if(bit_MDO)
+	{
+		status = inb_gpio( LPC_GPIO_SET);
+		status |= LPC_EDIO ;		//EDIO high
+		outb_gpio(LPC_GPIO_SET, status);
+	}
+	else
+	{
+		status = inb_gpio( LPC_GPIO_SET);
+		status &= ~(LPC_EDIO) ;		//EDIO low
+		outb_gpio(LPC_GPIO_SET, status);
+	}
+
+	status |= LPC_EECK ;		//EECK high
+	outb_gpio(LPC_GPIO_SET, status);
+
+	status &= ~(LPC_EECK) ;		//EECK low
+	outb_gpio(LPC_GPIO_SET, status);
+
+#else
+    unsigned int addr;
+    unsigned int value;
+
+    addr = GPIO_BASE_ADDR + GPIO_PIN_DIR;
+    value = readl(addr) | GPIO_MDC | GPIO_MDIO; /* set MDC/MDIO Pin to output */
+    writel(value,addr);
+    if(bit_MDO)
+    {
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+        writel(GPIO_MDIO,addr); /* set MDIO to 1 */
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+        writel(GPIO_MDC,addr); /* set MDC to 1 */
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+        writel(GPIO_MDC,addr); /* set MDC to 0 */
+    }
+    else
+    {
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+        writel(GPIO_MDIO,addr); /* set MDIO to 0 */
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_SET);
+        writel(GPIO_MDC,addr); /* set MDC to 1 */
+        addr = (GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+        writel(GPIO_MDC,addr); /* set MDC to 0 */
+    }
+
+#endif
+}
+
+/**********************************************************************
+* read a bit from NWay register through CSR9_MDC,MDIO
+***********************************************************************/
+unsigned int mii_serial_read(void) // read data from mii PHY
+{
+#ifdef CONFIG_SL2312_LPC_IT8712
+  	unsigned char iomode,status;
+	unsigned int value ;
+
+	iomode = LPCGetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET);
+	iomode &= ~(LPC_EDIO) ;		// Set EDIO input
+	iomode |= (LPC_EECK) ;		// Set EECK,EECS output
+	LPCSetConfig(LDN_GPIO, 0xc8 + LPC_GPIO_SET, iomode);
+
+	status = inb_gpio( LPC_GPIO_SET);
+	status |= LPC_EECK ;		//EECK high
+	outb_gpio(LPC_GPIO_SET, status);
+
+	status &= ~(LPC_EECK) ;		//EECK low
+	outb_gpio(LPC_GPIO_SET, status);
+
+	value = inb_gpio( LPC_GPIO_SET);
+
+	value = value>>2 ;
+	value &= 0x01;
+
+	return value ;
+
+#else
+    unsigned int *addr;
+    unsigned int value;
+
+    addr = (unsigned int *)(GPIO_BASE_ADDR + GPIO_PIN_DIR);
+    value = readl(addr) & ~GPIO_MDIO; //0xffbfffff;   /* set MDC to output and MDIO to input */
+    writel(value,addr);
+
+    addr = (unsigned int *)(GPIO_BASE_ADDR + GPIO_DATA_SET);
+    writel(GPIO_MDC,addr); /* set MDC to 1 */
+    addr = (unsigned int *)(GPIO_BASE_ADDR + GPIO_DATA_CLEAR);
+    writel(GPIO_MDC,addr); /* set MDC to 0 */
+
+    addr = (unsigned int *)(GPIO_BASE_ADDR + GPIO_DATA_IN);
+    value = readl(addr);
+    value = (value & (1<<GPIO_MDIO_PIN)) >> GPIO_MDIO_PIN;
+    return(value);
+
+#endif
+}
+
+/***************************************
+* preamble + ST
+***************************************/
+void mii_pre_st(void)
+{
+    unsigned char i;
+
+    for(i=0;i<32;i++) // PREAMBLE
+        mii_serial_write(1);
+    mii_serial_write(0); // ST
+    mii_serial_write(1);
+}
+
+
+/******************************************
+* Read MII register
+* phyad -> physical address
+* regad -> register address
+***************************************** */
+unsigned int mii_read(unsigned char phyad,unsigned char regad)
+{
+    unsigned int i,value;
+    unsigned int bit;
+
+    if (phyad == GPHY_ADDR)
+    {
+        GPIO_MDC_PIN = G_MDC_PIN;   /* assigned MDC pin for giga PHY */
+        GPIO_MDIO_PIN = G_MDIO_PIN; /* assigned MDIO pin for giga PHY */
+    }
+    else
+    {
+        GPIO_MDC_PIN = H_MDC_PIN;   /* assigned MDC pin for 10/100 PHY */
+        GPIO_MDIO_PIN = H_MDIO_PIN; /* assigned MDIO pin for 10/100 PHY */
+    }
+    GPIO_MDC = (1<<GPIO_MDC_PIN);
+    GPIO_MDIO = (1<<GPIO_MDIO_PIN);
+
+    mii_pre_st(); // PRE+ST
+    mii_serial_write(1); // OP
+    mii_serial_write(0);
+
+    for (i=0;i<5;i++) { // PHYAD
+        bit= ((phyad>>(4-i)) & 0x01) ? 1 :0 ;
+        mii_serial_write(bit);
+    }
+
+    for (i=0;i<5;i++) { // REGAD
+        bit= ((regad>>(4-i)) & 0x01) ? 1 :0 ;
+        mii_serial_write(bit);
+    }
+
+    mii_serial_read(); // TA_Z
+//    if((bit=mii_serial_read()) !=0 ) // TA_0
+//    {
+//        return(0);
+//    }
+    value=0;
+    for (i=0;i<16;i++) { // READ DATA
+        bit=mii_serial_read();
+        value += (bit<<(15-i)) ;
+    }
+
+    mii_serial_write(0); // dumy clock
+    mii_serial_write(0); // dumy clock
+
+	//printk("%s: phy_addr=0x%x reg_addr=0x%x value=0x%x \n",__func__,phyad,regad,value);
+    return(value);
+}
+
+/******************************************
+* Write MII register
+* phyad -> physical address
+* regad -> register address
+* value -> value to be write
+***************************************** */
+void mii_write(unsigned char phyad,unsigned char regad,unsigned int value)
+{
+    unsigned int i;
+    char bit;
+
+	printk("%s: phy_addr=0x%x reg_addr=0x%x value=0x%x \n",__func__,phyad,regad,value);
+    if (phyad == GPHY_ADDR)
+    {
+        GPIO_MDC_PIN = G_MDC_PIN;   /* assigned MDC pin for giga PHY */
+        GPIO_MDIO_PIN = G_MDIO_PIN; /* assigned MDIO pin for giga PHY */
+    }
+    else
+    {
+        GPIO_MDC_PIN = H_MDC_PIN;   /* assigned MDC pin for 10/100 PHY */
+        GPIO_MDIO_PIN = H_MDIO_PIN; /* assigned MDIO pin for 10/100 PHY */
+    }
+    GPIO_MDC = (1<<GPIO_MDC_PIN);
+    GPIO_MDIO = (1<<GPIO_MDIO_PIN);
+
+    mii_pre_st(); // PRE+ST
+    mii_serial_write(0); // OP
+    mii_serial_write(1);
+    for (i=0;i<5;i++) { // PHYAD
+        bit= ((phyad>>(4-i)) & 0x01) ? 1 :0 ;
+        mii_serial_write(bit);
+    }
+
+    for (i=0;i<5;i++) { // REGAD
+        bit= ((regad>>(4-i)) & 0x01) ? 1 :0 ;
+        mii_serial_write(bit);
+    }
+    mii_serial_write(1); // TA_1
+    mii_serial_write(0); // TA_0
+
+    for (i=0;i<16;i++) { // OUT DATA
+        bit= ((value>>(15-i)) & 0x01) ? 1 : 0 ;
+        mii_serial_write(bit);
+    }
+    mii_serial_write(0); // dumy clock
+    mii_serial_write(0); // dumy clock
+}
+
+/*----------------------------------------------------------------------
+* gmac_set_rx_mode
+*----------------------------------------------------------------------*/
+static void gmac_set_rx_mode(struct net_device *dev)
+{
+    GMAC_RX_FLTR_T      filter;
+	unsigned int        mc_filter[2];	/* Multicast hash filter */
+    int                 bit_nr;
+	unsigned int        i;
+	GMAC_INFO_T 		*tp = dev->priv;
+
+//    printk("%s : dev->flags = %x \n",__func__,dev->flags);
+//    dev->flags |= IFF_ALLMULTI;  /* temp */
+    filter.bits32 = 0;
+    filter.bits.error = 0;
+	if (dev->flags & IFF_PROMISC)
+	{
+	    filter.bits.error = 1;
+        filter.bits.promiscuous = 1;
+        filter.bits.broadcast = 1;
+        filter.bits.multicast = 1;
+        filter.bits.unicast = 1;
+		mc_filter[1] = mc_filter[0] = 0xffffffff;
+	}
+	else if (dev->flags & IFF_ALLMULTI)
+	{
+//        filter.bits.promiscuous = 1;
+        filter.bits.broadcast = 1;
+        filter.bits.multicast = 1;
+        filter.bits.unicast = 1;
+		mc_filter[1] = mc_filter[0] = 0xffffffff;
+	}
+	else
+	{
+		struct dev_mc_list *mclist;
+
+//        filter.bits.promiscuous = 1;
+        filter.bits.broadcast = 1;
+        filter.bits.multicast = 1;
+        filter.bits.unicast = 1;
+		mc_filter[1] = mc_filter[0] = 0;
+		for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;i++, mclist = mclist->next)
+		{
+            bit_nr = ether_crc(ETH_ALEN,mclist->dmi_addr) & 0x0000003f;
+            if (bit_nr < 32)
+            {
+                mc_filter[0] = mc_filter[0] | (1<<bit_nr);
+            }
+            else
+            {
+                mc_filter[1] = mc_filter[1] | (1<<(bit_nr-32));
+            }
+		}
+	}
+    gmac_write_reg(tp->base_addr,GMAC_RX_FLTR,filter.bits32,0xffffffff);  //chech base address!!!
+    gmac_write_reg(tp->base_addr,GMAC_MCAST_FIL0,mc_filter[0],0xffffffff);
+    gmac_write_reg(tp->base_addr,GMAC_MCAST_FIL1,mc_filter[1],0xffffffff);
+    return;
+}
+
+#ifdef CONFIG_SL_NAPI
+/*----------------------------------------------------------------------
+* gmac_rx_poll
+*----------------------------------------------------------------------*/
+static int gmac_rx_poll(struct net_device *dev, int *budget)
+{
+	TOE_INFO_T			*toe;
+    GMAC_RXDESC_T   	*curr_desc;
+	struct sk_buff 		*skb;
+    DMA_RWPTR_T			rwptr;
+	unsigned int 		pkt_size;
+	unsigned int        desc_count;
+	unsigned int        good_frame, chksum_status, rx_status;
+	int                 rx_pkts_num = 0;
+	int                 quota = min(dev->quota, *budget);
+	GMAC_INFO_T			*tp = (GMAC_INFO_T *)dev->priv;
+	unsigned int		status4;
+	volatile DMA_RWPTR_T	fq_rwptr;
+	int					max_cnt = TOE_SW_FREEQ_DESC_NUM;//TOE_SW_FREEQ_DESC_NUM = 64
+	//unsigned long		rx_old_bytes;
+	struct net_device_stats *isPtr = (struct net_device_stats *)&tp->ifStatics;
+	//unsigned long long	rx_time;
+
+
+
+#if 1
+	if (do_again)
+	{
+			toe_gmac_fill_free_q();
+			status4 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_4_REG);
+			fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+			//printk("\n%s:: do_again toe_gmac_fill_free_q =======>status4=0x%x =====fq_rwptr =0x%8x======>JKJKJKJKJKJKJKJKJ \n", __func__,status4,fq_rwptr.bits32);
+			if (fq_rwptr.bits.wptr != fq_rwptr.bits.rptr)
+			{
+						//status4 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_4_REG);
+						do_again =0;
+						//netif_rx_complete(dev);
+						gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_STATUS_4_REG, status4,	0x1);
+						fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+						rwptr.bits32 = readl(&tp->default_qhdr->word1);
+			}
+			else
+				return 1;
+	}
+#endif
+	rwptr.bits32 = readl(&tp->default_qhdr->word1);
+#if 0
+	if (rwptr.bits.rptr != tp->rx_rwptr.bits.rptr)
+	{
+		mac_stop_txdma((struct net_device *)tp->dev);
+		printk("Default Queue HW RD ptr (0x%x) != SW RD Ptr (0x%x)\n",
+				rwptr.bits32, tp->rx_rwptr.bits.rptr);
+		while(1);
+	}
+#endif
+	toe = (TOE_INFO_T *)&toe_private_data;
+
+	fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+	//printk("%s:---Before-------------->Default Queue HW RW ptr (0x%8x),   fq_rwptr =0x%8x \n",__func__,rwptr.bits32,fq_rwptr.bits32 );
+	//printk("%s:---Before while   rx_pkts_num=%d------rx_finished_idx=0x%x------->Default_Q [rwptr.bits.rptr(SW)=0x%x,   rwptr.bits.wptr(HW) = 0x%x ]---->Free_Q(SW_HW) = 0x%8x \n",__func__,rx_pkts_num,rx_finished_idx,rwptr.bits.rptr,rwptr.bits.wptr,fq_rwptr.bits32 );
+//	while ((--max_cnt) && (rwptr.bits.rptr != rwptr.bits.wptr) && (rx_pkts_num < quota))
+
+	while ((rwptr.bits.rptr != rwptr.bits.wptr) && (rx_pkts_num < quota))
+	{
+
+    	curr_desc = (GMAC_RXDESC_T *)tp->default_desc_base + rwptr.bits.rptr;
+		tp->default_q_cnt++;
+    	tp->rx_curr_desc = (unsigned int)curr_desc;
+    	rx_status = curr_desc->word0.bits.status;
+    	chksum_status = curr_desc->word0.bits.chksum_status;
+    	tp->rx_status_cnt[rx_status]++;
+    	tp->rx_chksum_cnt[chksum_status]++;
+        pkt_size = curr_desc->word1.bits.byte_count;  /*total byte count in a frame*/
+		desc_count = curr_desc->word0.bits.desc_count; /* get descriptor count per frame */
+		good_frame=1;
+		if ((curr_desc->word0.bits32 & (GMAC_RXDESC_0_T_derr | GMAC_RXDESC_0_T_perr))
+			|| (pkt_size < 60)
+		    || (chksum_status & 0x4)
+		    || rx_status )
+//			|| rx_status || (rwptr.bits.rptr > rwptr.bits.wptr ))
+		{
+			good_frame = 0;
+			if (curr_desc->word0.bits32 & GMAC_RXDESC_0_T_derr)
+				printk("%s::derr (GMAC-%d)!!!\n", __func__, tp->port_id);
+			if (curr_desc->word0.bits32 & GMAC_RXDESC_0_T_perr)
+				printk("%s::perr (GMAC-%d)!!!\n", __func__, tp->port_id);
+			if (rx_status)
+			{
+				if (rx_status == 4 || rx_status == 7)
+					isPtr->rx_crc_errors++;
+//				printk("%s::Status=%d (GMAC-%d)!!!\n", __func__, rx_status, tp->port_id);
+			}
+#ifdef SL351x_GMAC_WORKAROUND
+			else if (pkt_size < 60)
+			{
+				if (tp->short_frames_cnt < GMAC_SHORT_FRAME_THRESHOLD)
+					tp->short_frames_cnt++;
+				if (tp->short_frames_cnt >= GMAC_SHORT_FRAME_THRESHOLD)
+				{
+					GMAC_CONFIG0_T config0;
+					config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+					config0.bits.dis_rx = 1;
+					writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+					config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+					config0.bits.dis_rx = 1;
+					writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+				}
+			}
+#endif
+//			if (chksum_status)
+//				printk("%s::Checksum Status=%d (GMAC-%d)!!!\n", __func__, chksum_status, tp->port_id);
+			skb = (struct sk_buff *)(REG32(__va(curr_desc->word2.buf_adr) - SKB_RESERVE_BYTES));
+			dev_kfree_skb_irq(skb);
+		}
+		if (good_frame)
+		{
+			if (curr_desc->word0.bits.drop)
+				printk("%s::Drop (GMAC-%d)!!!\n", __func__, tp->port_id);
+//			if (chksum_status)
+//				printk("%s::Checksum Status=%d (GMAC-%d)!!!\n", __func__, chksum_status, tp->port_id);
+
+#ifdef SL351x_GMAC_WORKAROUND
+			if (tp->short_frames_cnt >= GMAC_SHORT_FRAME_THRESHOLD)
+			{
+				GMAC_CONFIG0_T config0;
+				config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+				config0.bits.dis_rx = 0;
+				writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+				config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+				config0.bits.dis_rx = 0;
+				writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+			}
+			tp->short_frames_cnt = 0;
+#endif
+	    	/* get frame information from the first descriptor of the frame */
+			isPtr->rx_packets++;
+			//consistent_sync((void *)__va(curr_desc->word2.buf_adr), pkt_size, PCI_DMA_FROMDEVICE);
+			skb = (struct sk_buff *)(REG32(__va(curr_desc->word2.buf_adr) - SKB_RESERVE_BYTES));
+			tp->curr_rx_skb = skb;
+	//		curr_desc->word2.buf_adr = 0;
+
+		    //skb_reserve (skb, SKB_RESERVE_BYTES);
+			skb_reserve (skb, RX_INSERT_BYTES);	/* 2 byte align the IP fields. */
+			//if ((skb->tail+pkt_size) > skb->end )
+			//printk("%s::------------->Here skb->len=%d,pkt_size= %d,skb->head=0x%x,skb->tail= 0x%x, skb->end= 0x%x\n", __func__, skb->len, pkt_size,skb->head,skb->tail,skb->end);
+			skb_put(skb, pkt_size);
+
+
+			skb->dev = dev;
+			if (chksum_status == RX_CHKSUM_IP_UDP_TCP_OK)
+			{
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+#ifdef CONFIG_SL351x_NAT
+				if (nat_cfg.enabled && curr_desc->word3.bits.l3_offset && curr_desc->word3.bits.l4_offset)
+				{
+					struct iphdr	*ip_hdr;
+					ip_hdr = (struct iphdr *)&(skb->data[curr_desc->word3.bits.l3_offset]);
+					sl351x_nat_input(skb,
+									tp->port_id,
+									(void *)curr_desc->word3.bits.l3_offset,
+								  	(void *)curr_desc->word3.bits.l4_offset);
+				}
+#endif
+				skb->protocol = eth_type_trans(skb,dev); /* set skb protocol */
+#if 0
+#ifdef CONFIG_SL351x_RXTOE
+				if (storlink_ctl.rx_max_pktsize) {
+					struct iphdr	*ip_hdr;
+					struct tcphdr	*tcp_hdr;
+					int ip_hdrlen;
+
+ 					ip_hdr = (struct iphdr*)&(skb->data[0]);
+					if ((skb->protocol == __constant_htons(ETH_P_IP)) &&
+					   ((ip_hdr->protocol & 0x00ff) == IPPROTO_TCP)) {
+						ip_hdrlen = ip_hdr->ihl << 2;
+						tcp_hdr = (struct tcphdr*)&(skb->data[ip_hdrlen]);
+						if (tcp_hdr->syn) {
+							struct toe_conn* connection = init_toeq(ip_hdr->version,
+									ip_hdr, tcp_hdr, toe, &(skb->data[0]) - 14);
+							TCP_SKB_CB(skb)->connection = connection;
+							//	hash_dump_entry(TCP_SKB_CB(skb)->connection->hash_entry_index);
+							//		printk("%s::skb data %x, conn %x, mode %x\n",
+							//			__func__, skb->data, connection, connection->mode);
+						}
+					}
+				}
+#endif
+#endif
+			}
+			else if (chksum_status == RX_CHKSUM_IP_OK_ONLY)
+			{
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+#ifdef CONFIG_SL351x_NAT
+				if (nat_cfg.enabled && curr_desc->word3.bits.l3_offset && curr_desc->word3.bits.l4_offset)
+				{
+					struct iphdr	*ip_hdr;
+					ip_hdr = (struct iphdr *)&(skb->data[curr_desc->word3.bits.l3_offset]);
+					if (ip_hdr->protocol == IPPROTO_UDP)
+					{
+						sl351x_nat_input(skb,
+										tp->port_id,
+										(void *)curr_desc->word3.bits.l3_offset,
+								  		(void *)curr_desc->word3.bits.l4_offset);
+					}
+					else if (ip_hdr->protocol == IPPROTO_GRE)
+					{
+						sl351x_nat_input(skb,
+									tp->port_id,
+									(void *)curr_desc->word3.bits.l3_offset,
+								  	(void *)curr_desc->word3.bits.l4_offset);
+					}
+				}
+#endif
+				skb->protocol = eth_type_trans(skb,dev); /* set skb protocol */
+			}
+			else
+			{
+				skb->protocol = eth_type_trans(skb,dev); /* set skb protocol */
+			}
+			//netif_rx(skb);  /* socket rx */
+			netif_receive_skb(skb); //For NAPI
+			dev->last_rx = jiffies;
+
+			isPtr->rx_bytes += pkt_size;
+			//printk("------------------->isPtr->rx_bytes = %d\n",isPtr->rx_bytes);
+
+
+        }
+		// advance one for Rx default Q 0/1
+		rwptr.bits.rptr = RWPTR_ADVANCE_ONE(rwptr.bits.rptr, tp->default_desc_num);
+		SET_RPTR(&tp->default_qhdr->word1, rwptr.bits.rptr);
+     	tp->rx_rwptr.bits32 = rwptr.bits32;
+		rx_pkts_num++;
+		//rwptr.bits32 = readl(&tp->default_qhdr->word1);//try read default_qhdr again
+		//fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+		//printk("%s:---Loop  -------->rx_pkts_num=%d------------>Default Queue HW RW ptr = (0x%8x),   fq_rwptr =0x%8x \n",__func__,rx_pkts_num,rwptr.bits32,fq_rwptr.bits32 );
+#if 0
+		if ((status4 & 0x1) == 0)
+		{
+			//if (!((dev->last_rx <= (rx_time + 2)) &&  (isPtr->rx_bytes > (rx_old_bytes + 1000000 ))))
+			if (tp->total_q_cnt_napi < 1024)
+			{
+				tp->total_q_cnt_napi++;
+				toe_gmac_fill_free_q();  //for iperf test disable
+			}
+			//else
+				//printk("%s:---isPtr->rx_bytes =%u , rx_old_bytes =%u\n",__func__,isPtr->rx_bytes,rx_old_bytes );
+
+		}
+#endif
+		//rwptr.bits.rptr = RWPTR_ADVANCE_ONE(rwptr.bits.rptr, tp->default_desc_num);
+		//printk("%s:---Loop  -------->rx_pkts_num=%d----rwptr.bits.rptr=0x%x-------->Default Queue HW RW ptr = (0x%8x),   fq_rwptr =0x%8x \n",__func__,rx_pkts_num,rwptr.bits.rptr,rwptr.bits32,fq_rwptr.bits32 );
+		//printk("%s:---Loop  rx_pkts_num=%d------rwptr.bits.rptr=0x%x------->Default_Q [rwptr.bits.rptr(SW)=0x%x,   rwptr.bits.wptr(HW) = 0x%x ]---->Free_Q(SW_HW) = 0x%8x \n",__func__,rx_pkts_num,rwptr.bits.rptr,rwptr.bits.rptr,rwptr.bits.wptr,fq_rwptr.bits32 );
+	}
+	// advance one for Rx default Q 0/1
+
+		//rwptr.bits.rptr = RWPTR_ADVANCE_ONE(rwptr.bits.rptr, tp->default_desc_num);
+		//SET_RPTR(&tp->default_qhdr->word1, rwptr.bits.rptr);
+     	//tp->rx_rwptr.bits32 = rwptr.bits32;
+     	//rwptr.bits.rptr = rwptr.bits.rptr;
+
+	dev->quota -= rx_pkts_num;
+	*budget -= rx_pkts_num;
+
+	status4 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_4_REG);//try read SWFQ empty again
+	//fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+	rwptr.bits32 = readl(&tp->default_qhdr->word1); //try read default_qhdr again
+	//printk("%s:---After    rx_pkts_num=%d------rwptr.bits.rptr=0x%x------->Default_Q [rwptr.bits.rptr(SW)=0x%x,   rwptr.bits.wptr(HW) = 0x%x ]---->Free_Q(SW_HW) = 0x%8x \n",__func__,rx_pkts_num,rwptr.bits.rptr,rwptr.bits.rptr,rwptr.bits.wptr,fq_rwptr.bits32 );
+//	if (rwptr.bits.rptr > rwptr.bits.wptr )
+//			{
+				//toe_gmac_disable_rx(dev);
+				//wait_event_interruptible_timeout(freeq_wait,
+					//(rx_pkts_num == 100), CMTP_INTEROP_TIMEOUT);
+				//printk("\n%s:: return 22222=======> rx_pkts_num =%d,   rwptr.bits.rptr=%d,   rwptr.bits.wptr = %d ====---------=======>JKJKJKJKJK\n",
+					//__func__,rx_pkts_num,rwptr.bits.rptr,rwptr.bits.wptr);
+//				return 1;
+//			}
+
+	if (rwptr.bits.rptr == rwptr.bits.wptr)
+	{
+		unsigned int data32;
+			//printk("%s:---[rwptr.bits.rptr == rwptr.bits.wptr]   rx_pkts_num=%d------rwptr.bits.rptr=0x%x------->Default_Q [rwptr.bits.rptr(SW)=0x%x,   rwptr.bits.wptr(HW) = 0x%x ]---->Free_Q(SW_HW) = 0x%8x \n",__func__,rx_pkts_num,rwptr.bits.rptr,rwptr.bits.rptr,rwptr.bits.wptr,fq_rwptr.bits32 );
+
+	    /* Receive descriptor is empty now */
+#if 1
+     if (status4 & 0x1)
+   			{
+   				do_again =1;
+   				//writel(0x40400000, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_ENABLE_4_REG); //disable SWFQ empty interrupt
+   				//toe_gmac_disable_interrupt(tp->irq);
+   				tp->sw_fq_empty_cnt++;
+   				//toe_gmac_disable_rx(dev);
+   				writel(0x07960202, TOE_GMAC0_BASE+GMAC_CONFIG0);
+				writel(0x07960202, TOE_GMAC1_BASE+GMAC_CONFIG0);
+   				//printk("\n%s ::  freeq int-----tp->sw_fq_empty_cnt  =%d---------====================----------------->\n",__func__,tp->sw_fq_empty_cnt);
+   				//while ((fq_rwptr.bits.wptr >= (fq_rwptr.bits.rptr+256)) || (fq_rwptr.bits.wptr <= (fq_rwptr.bits.rptr+256)))
+   				//{
+   					//gmac_write_reg(TOE_GLOBAL_BASE, GLOBAL_INTERRUPT_STATUS_4_REG, status4,
+					//0x1);
+				//printk("\n%s::fq_rwptr.wrptr = %x =======> ===========>here \n", __func__,fq_rwptr.bits32);
+				//if ((status4 & 0x1) == 0)
+					//break;
+				 return 1;
+				//}
+
+			}
+#endif
+        //toe_gmac_fill_free_q();
+        netif_rx_complete(dev);
+        // enable GMAC-0 rx interrupt
+        // class-Q & TOE-Q are implemented in future
+        //data32 = readl(TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_1_REG);
+        //if (tp->port_id == 0)
+        	//data32 |= DEFAULT_Q0_INT_BIT;
+        //else
+        	//data32 |= DEFAULT_Q1_INT_BIT;
+        //writel(data32, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_ENABLE_1_REG);
+		writel(0x3, TOE_GLOBAL_BASE+GLOBAL_INTERRUPT_ENABLE_1_REG);
+		//printk("\n%s::netif_rx_complete-->  rx_pkts_num =%d,   rwptr.bits.rptr=0x%x,   rwptr.bits.wptr = 0x%x ====---------=======>JKJKJKJKJK\n",
+		//__func__,rx_pkts_num,rwptr.bits.rptr,rwptr.bits.wptr);
+        writel(0x07960200, TOE_GMAC0_BASE+GMAC_CONFIG0);
+		writel(0x07960200, TOE_GMAC1_BASE+GMAC_CONFIG0);
+        return 0;
+    }
+    else
+    {
+        //printk("\n%s:: return 1 -->status4= 0x%x,rx_pkts_num =%d,   rwptr.bits.rptr=0x%x,   rwptr.bits.wptr = 0x%x  ======> \n", __func__,status4,rx_pkts_num,rwptr.bits.rptr,rwptr.bits.wptr);
+        return 1;
+    }
+}
+#endif
+
+/*----------------------------------------------------------------------
+* gmac_tx_timeout
+*----------------------------------------------------------------------*/
+void gmac_tx_timeout(struct net_device *dev)
+{
+	GMAC_INFO_T				*tp = (GMAC_INFO_T *)dev->priv;
+
+#ifdef CONFIG_SL351x_SYSCTL
+	if (tp->operation && storlink_ctl.link[tp->port_id])
+#else
+	if (tp->operation)
+#endif
+	{
+		netif_wake_queue(dev);
+	}
+}
+
+
+
+/*----------------------------------------------------------------------
+* mac_set_rule_reg
+*----------------------------------------------------------------------*/
+int mac_set_rule_reg(int mac, int rule, int enabled, u32 reg0, u32 reg1, u32 reg2)
+{
+	int		total_key_dwords;
+
+	total_key_dwords = 1;
+
+	if (reg0 & MR_L2_BIT)
+	{
+		if (reg0 & MR_DA_BIT) total_key_dwords += 2;
+		if (reg0 & MR_SA_BIT) total_key_dwords += 2;
+		if ((reg0 & MR_DA_BIT) && ( reg0 & MR_SA_BIT)) total_key_dwords--;
+		if (reg0 & (MR_PPPOE_BIT | MR_VLAN_BIT)) total_key_dwords++;
+	}
+	if (reg0 & MR_L3_BIT)
+	{
+		if (reg0 & (MR_IP_HDR_LEN_BIT | MR_TOS_TRAFFIC_BIT | MR_SPR_BITS))
+			total_key_dwords++;
+		if (reg0 & MR_FLOW_LABLE_BIT) total_key_dwords++;
+		if ((reg0 & MR_IP_VER_BIT) == 0) // IPv4
+		{
+			if (reg1 & 0xff000000) total_key_dwords += 1;
+			if (reg1 & 0x00ff0000) total_key_dwords += 1;
+		}
+		else
+		{
+			if (reg1 & 0xff000000) total_key_dwords += 4;
+			if (reg1 & 0x00ff0000) total_key_dwords += 4;
+		}
+	}
+	if (reg0 & MR_L4_BIT)
+	{
+		if (reg1 & 0x0000f000) total_key_dwords += 1;
+		if (reg1 & 0x00000f00) total_key_dwords += 1;
+		if (reg1 & 0x000000f0) total_key_dwords += 1;
+		if (reg1 & 0x0000000f) total_key_dwords += 1;
+		if (reg2 & 0xf0000000) total_key_dwords += 1;
+		if (reg2 & 0x0f000000) total_key_dwords += 1;
+	}
+	if (reg0 & MR_L7_BIT)
+	{
+		if (reg2 & 0x00f00000) total_key_dwords += 1;
+		if (reg2 & 0x000f0000) total_key_dwords += 1;
+		if (reg2 & 0x0000f000) total_key_dwords += 1;
+		if (reg2 & 0x00000f00) total_key_dwords += 1;
+		if (reg2 & 0x000000f0) total_key_dwords += 1;
+		if (reg2 & 0x0000000f) total_key_dwords += 1;
+	}
+
+	if (total_key_dwords > HASH_MAX_KEY_DWORD)
+		return -1;
+
+	if (total_key_dwords == 0 && enabled)
+		return -2;
+
+	mac_set_rule_enable_bit(mac, rule, 0);
+	if (enabled)
+	{
+		mac_set_MRxCRx(mac, rule, 0, reg0);
+		mac_set_MRxCRx(mac, rule, 1, reg1);
+		mac_set_MRxCRx(mac, rule, 2, reg2);
+		mac_set_rule_action(mac, rule, total_key_dwords);
+		mac_set_rule_enable_bit(mac, rule, enabled);
+	}
+	else
+	{
+		mac_set_rule_action(mac, rule, 0);
+	}
+	return total_key_dwords;
+}
+
+/*----------------------------------------------------------------------
+* mac_get_rule_enable_bit
+*----------------------------------------------------------------------*/
+int mac_get_rule_enable_bit(int mac, int rule)
+{
+	switch (rule)
+	{
+		case 0: return ((mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG0) >> 15) & 1);
+		case 1: return ((mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG0) >> 31) & 1);
+		case 2: return ((mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG1) >> 15) & 1);
+		case 3: return ((mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG1) >> 31) & 1);
+		default: return 0;
+	}
+}
+
+/*----------------------------------------------------------------------
+* mac_set_rule_enable_bit
+*----------------------------------------------------------------------*/
+void mac_set_rule_enable_bit(int mac, int rule, int data)
+{
+	u32 reg;
+
+	if (data & ~1)
+		return;
+
+	switch (rule)
+	{
+		case 0:
+			reg = (mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG0) & ~(1<<15)) | (data << 15);
+			mac_write_dma_reg(mac, GMAC_HASH_ENGINE_REG0, reg);
+			break;
+		case 1:
+			reg = (mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG0) & ~(1<<31)) | (data << 31);
+			mac_write_dma_reg(mac, GMAC_HASH_ENGINE_REG0, reg);
+			break;
+		case 2:
+			reg = (mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG1) & ~(1<<15)) | (data << 15);
+			mac_write_dma_reg(mac, GMAC_HASH_ENGINE_REG1, reg);
+			break;
+		case 3:
+			reg = (mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG1) & ~(1<<31)) | (data << 31);
+			mac_write_dma_reg(mac, GMAC_HASH_ENGINE_REG1, reg);
+	}
+}
+
+/*----------------------------------------------------------------------
+* mac_set_rule_action
+*----------------------------------------------------------------------*/
+int mac_set_rule_action(int mac, int rule, int data)
+{
+	u32 reg;
+
+	if (data > 32)
+		return -1;
+
+	if (data)
+		data = (data << 6) | (data + HASH_ACTION_DWORDS);
+	switch (rule)
+	{
+		case 0:
+			reg = (mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG0) & ~(0x7ff));
+			mac_write_dma_reg(mac, GMAC_HASH_ENGINE_REG0, reg | data);
+			break;
+		case 1:
+			reg = (mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG0) & ~(0x7ff<<16));
+			mac_write_dma_reg(mac, GMAC_HASH_ENGINE_REG0, reg | (data << 16));
+			break;
+		case 2:
+			reg = (mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG1) & ~(0x7ff));
+			mac_write_dma_reg(mac, GMAC_HASH_ENGINE_REG1,  reg | data);
+			break;
+		case 3:
+			reg = (mac_read_dma_reg(mac, GMAC_HASH_ENGINE_REG1) & ~(0x7ff<<16));
+			mac_write_dma_reg(mac, GMAC_HASH_ENGINE_REG1, reg | (data << 16));
+			break;
+		default:
+			return -1;
+	}
+
+	return 0;
+}
+/*----------------------------------------------------------------------
+* mac_get_MRxCRx
+*----------------------------------------------------------------------*/
+int mac_get_MRxCRx(int mac, int rule, int ctrlreg)
+{
+	int reg;
+
+	switch (rule)
+	{
+		case 0: reg = GMAC_MR0CR0 + ctrlreg * 4; break;
+		case 1: reg = GMAC_MR1CR0 + ctrlreg * 4; break;
+		case 2: reg = GMAC_MR2CR0 + ctrlreg * 4; break;
+		case 3: reg = GMAC_MR3CR0 + ctrlreg * 4; break;
+		default: return 0;
+	}
+	return mac_read_dma_reg(mac, reg);
+}
+
+/*----------------------------------------------------------------------
+* mac_set_MRxCRx
+*----------------------------------------------------------------------*/
+void mac_set_MRxCRx(int mac, int rule, int ctrlreg, u32 data)
+{
+	int reg;
+
+	switch (rule)
+	{
+		case 0: reg = GMAC_MR0CR0 + ctrlreg * 4; break;
+		case 1: reg = GMAC_MR1CR0 + ctrlreg * 4; break;
+		case 2: reg = GMAC_MR2CR0 + ctrlreg * 4; break;
+		case 3: reg = GMAC_MR3CR0 + ctrlreg * 4; break;
+		default: return;
+	}
+	mac_write_dma_reg(mac, reg, data);
+}
+
+/*----------------------------------------------------------------------
+* mac_set_rule_priority
+*----------------------------------------------------------------------*/
+void mac_set_rule_priority(int mac, int p0, int p1, int p2, int p3)
+{
+	int 			i;
+	GMAC_MRxCR0_T	reg[4];
+
+	for (i=0; i<4; i++)
+		reg[i].bits32 = mac_get_MRxCRx(mac, i, 0);
+
+	reg[0].bits.priority = p0;
+	reg[1].bits.priority = p1;
+	reg[2].bits.priority = p2;
+	reg[3].bits.priority = p3;
+
+	for (i=0; i<4; i++)
+		mac_set_MRxCRx(mac, i, 0, reg[i].bits32);
+}
+
+/*----------------------------------------------------------------------
+* gmac_netdev_ioctl
+*----------------------------------------------------------------------*/
+static int gmac_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+{
+	int 				rc = 0;
+    unsigned char		*hwa = rq->ifr_ifru.ifru_hwaddr.sa_data;
+
+#ifdef br_if_ioctl
+    struct 				ethtool_cmd ecmd; 	//br_if.c will call this ioctl
+	GMAC_INFO_T 		*tp = dev->priv;
+#endif
+
+#ifdef 	CONFIG_SL351x_NAT
+	if (cmd == SIOCDEVPRIVATE)
+		return sl351x_nat_ioctl(dev, rq, cmd);
+#endif
+
+	switch (cmd) {
+	case SIOCETHTOOL:
+#ifdef br_if_ioctl  	//br_if.c will call this ioctl
+		if (!netif_running(dev))
+		{
+			printk("Before changing the H/W address,please down the device.\n");
+			return -EINVAL;
+		}
+		memset((void *) &ecmd, 0, sizeof (ecmd));
+           	    ecmd.supported =
+                	SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII |
+                    SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
+                    SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full;
+         		    ecmd.port = PORT_TP;
+            	    ecmd.transceiver = XCVR_EXTERNAL;
+            	    ecmd.phy_address = tp->phy_addr;
+            	    switch (tp->speed_status)
+            	    {
+            	    case GMAC_SPEED_10: ecmd.speed = SPEED_10; break;
+             	    case GMAC_SPEED_100: ecmd.speed = SPEED_100; break;
+            	    case GMAC_SPEED_1000: ecmd.speed = SPEED_1000; break;
+            	    default: ecmd.speed = SPEED_10; break;
+            	   }
+            	    ecmd.duplex = tp->full_duplex_status ? DUPLEX_FULL : DUPLEX_HALF;
+            	    ecmd.advertising = ADVERTISED_TP;
+            	    ecmd.advertising |= ADVERTISED_Autoneg;
+           	    ecmd.autoneg = AUTONEG_ENABLE;
+                    if (copy_to_user(rq->ifr_data, &ecmd, sizeof (ecmd)))
+                  	return -EFAULT;
+#endif
+
+        break;
+
+    case SIOCSIFHWADDR:
+		if (!netif_running(dev))
+		{
+			printk("Before changing the H/W address,please down the device.\n");
+			return -EINVAL;
+		}
+        gmac_set_mac_address(dev,hwa);
+        break;
+
+	case SIOCGMIIPHY:	/* Get the address of the PHY in use. */
+        break;
+
+	case SIOCGMIIREG:	/* Read the specified MII register. */
+		break;
+
+	case SIOCSMIIREG:	/* Write the specified MII register */
+		break;
+
+	default:
+		rc = -EOPNOTSUPP;
+		break;
+	}
+
+	return rc;
+}
+
+#ifdef SL351x_GMAC_WORKAROUND
+
+#define GMAC_TX_STATE_OFFSET	0x60
+#define GMAC_RX_STATE_OFFSET	0x64
+#define GMAC_POLL_HANGED_NUM	200
+#define GMAC_RX_HANGED_STATE	0x4b2000
+#define GMAC_RX_HANGED_MASK		0xdff000
+#define GMAC_TX_HANGED_STATE	0x34012
+#define GMAC_TX_HANGED_MASK		0xfffff
+#define TOE_GLOBAL_REG_SIZE		(0x78/sizeof(u32))
+#define TOE_DMA_REG_SIZE		(0xd0/sizeof(u32))
+#define TOE_GMAC_REG_SIZE		(0x30/sizeof(u32))
+#define GMAC0_RX_HANG_BIT		(1 << 0)
+#define GMAC0_TX_HANG_BIT		(1 << 1)
+#define GMAC1_RX_HANG_BIT		(1 << 2)
+#define GMAC1_TX_HANG_BIT		(1 << 3)
+
+int		gmac_in_do_workaround;
+#if 0
+int		debug_cnt, poll_max_cnt;
+#endif
+u32		gmac_workaround_cnt[4];
+u32		toe_global_reg[TOE_GLOBAL_REG_SIZE];
+u32		toe_dma_reg[GMAC_NUM][TOE_DMA_REG_SIZE];
+u32		toe_gmac_reg[GMAC_NUM][TOE_GMAC_REG_SIZE];
+u32		gmac_short_frame_workaround_cnt[2];
+
+static void sl351x_gmac_release_buffers(void);
+static void sl351x_gmac_release_swtx_q(void);
+static void sl351x_gmac_release_rx_q(void);
+#ifdef _TOEQ_CLASSQ_READY_
+static void sl351x_gmac_release_class_q(void);
+static void sl351x_gmac_release_toe_q(void);
+static void sl351x_gmac_release_intr_q(void);
+#endif
+static void sl351x_gmac_release_sw_free_q(void);
+static void sl351x_gmac_release_hw_free_q(void);
+#ifdef CONFIG_SL351x_NAT
+static int get_free_desc_cnt(unsigned long rwptr, int total);
+static void sl351x_gmac_release_hwtx_q(void);
+u32     sl351x_nat_workaround_cnt;
+#endif
+void sl351x_gmac_save_reg(void);
+void sl351x_gmac_restore_reg(void);
+
+
+/*----------------------------------------------------------------------
+* 	sl351x_poll_gmac_hanged_status
+* 	- Called by timer routine, period 10ms
+*	- If (state != 0 && state == prev state && )
+*----------------------------------------------------------------------*/
+void sl351x_poll_gmac_hanged_status(u32 data)
+{
+	int 			i;
+	u32 			state;
+	TOE_INFO_T		*toe;
+	GMAC_INFO_T		*tp;
+	u32				hanged_state;
+	// int				old_operation[GMAC_NUM];
+#ifdef CONFIG_SL351x_NAT
+	u32				hw_free_cnt;
+#endif
+
+	if (gmac_in_do_workaround)
+		return;
+
+	gmac_in_do_workaround = 1;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	hanged_state = 0;
+
+#ifdef SL351x_TEST_WORKAROUND
+	if (toe->gmac[0].operation || toe->gmac[1].operation)
+	{
+		debug_cnt++;
+		if (debug_cnt == (30 * HZ))
+		{
+			debug_cnt = 0;
+			hanged_state = GMAC0_RX_HANG_BIT;
+			goto do_workaround;
+		}
+	}
+#endif
+	if (toe->gmac[0].operation)
+		hanged_state |= GMAC0_RX_HANG_BIT | GMAC0_TX_HANG_BIT;
+
+#if (GMAC_NUM > 1)
+	if (toe->gmac[1].operation)
+		hanged_state |= GMAC1_RX_HANG_BIT | GMAC1_TX_HANG_BIT;
+#endif
+
+	for (i=0; i<GMAC_POLL_HANGED_NUM; i++)
+	{
+		if (hanged_state & GMAC0_RX_HANG_BIT)
+		{
+			state = readl(TOE_GMAC0_BASE + GMAC_RX_STATE_OFFSET) & GMAC_RX_HANGED_MASK;
+			if (state != GMAC_RX_HANGED_STATE)
+				hanged_state &= ~GMAC0_RX_HANG_BIT;
+		}
+		if (hanged_state & GMAC0_TX_HANG_BIT)
+		{
+			state = readl(TOE_GMAC0_BASE + GMAC_TX_STATE_OFFSET) & GMAC_TX_HANGED_MASK;
+			if (state != GMAC_TX_HANGED_STATE)
+				hanged_state &= ~GMAC0_TX_HANG_BIT;
+		}
+#if (GMAC_NUM > 1)
+		if (hanged_state & GMAC1_RX_HANG_BIT)
+		{
+			state = readl(TOE_GMAC1_BASE + GMAC_RX_STATE_OFFSET) & GMAC_RX_HANGED_MASK;
+			if (state != GMAC_RX_HANGED_STATE)
+				hanged_state &= ~GMAC1_RX_HANG_BIT;
+		}
+		if (hanged_state & GMAC1_TX_HANG_BIT)
+		{
+			state = readl(TOE_GMAC1_BASE + GMAC_TX_STATE_OFFSET) & GMAC_TX_HANGED_MASK;
+			if (state != GMAC_TX_HANGED_STATE)
+				hanged_state &= ~GMAC1_TX_HANG_BIT;
+		}
+#endif
+		if (!hanged_state)
+		{
+#if 0
+			if (i < poll_max_cnt)
+				poll_max_cnt = i;
+#endif
+			if (toe->gmac[0].short_frames_cnt >= GMAC_SHORT_FRAME_THRESHOLD)
+			{
+				gmac_short_frame_workaround_cnt[0]++;
+				toe->gmac[0].short_frames_cnt = 0;
+				goto do_workaround;
+			}
+#if (GMAC_NUM > 1)
+			if (toe->gmac[1].short_frames_cnt >= GMAC_SHORT_FRAME_THRESHOLD)
+			{
+				gmac_short_frame_workaround_cnt[1]++;
+				toe->gmac[1].short_frames_cnt = 0;
+				goto do_workaround;
+			}
+#endif
+
+#ifdef CONFIG_SL351x_NAT
+			hw_free_cnt = readl(TOE_GLOBAL_BASE + GLOBAL_HWFQ_RWPTR_REG);
+			hw_free_cnt = get_free_desc_cnt(hw_free_cnt, TOE_HW_FREEQ_DESC_NUM);
+#ifdef NAT_WORKAROUND_BY_RESET_GMAC
+			if (readl(TOE_GLOBAL_BASE + 0x4084) && (hw_free_cnt <= PAUSE_SET_HW_FREEQ))
+			{
+				sl351x_nat_workaround_cnt++;
+				goto do_workaround;
+			}
+#else
+			if (readl(TOE_GLOBAL_BASE + 0x4084) && (hw_free_cnt <= (PAUSE_SET_HW_FREEQ*2)))
+			{
+				sl351x_nat_workaround_cnt++;
+				sl351x_nat_workaround_handler();
+			}
+#endif
+#endif
+			gmac_in_do_workaround = 0;
+			add_timer(&gmac_workround_timer_obj);
+			return;
+		}
+	}
+
+do_workaround:
+
+	gmac_initialized = 0;
+	if (hanged_state)
+	{
+		if (hanged_state & GMAC0_RX_HANG_BIT) gmac_workaround_cnt[0]++;
+		if (hanged_state & GMAC0_TX_HANG_BIT) gmac_workaround_cnt[1]++;
+		if (hanged_state & GMAC1_RX_HANG_BIT) gmac_workaround_cnt[2]++;
+		if (hanged_state & GMAC1_TX_HANG_BIT) gmac_workaround_cnt[3]++;
+	}
+
+	for (i=0; i<GMAC_NUM; i++)
+	{
+		tp=(GMAC_INFO_T *)&toe->gmac[i];
+		// old_operation[i] = tp->operation;
+		if (tp->operation)
+		{
+			netif_stop_queue(tp->dev);
+			clear_bit(__LINK_STATE_START, &tp->dev->state);
+			toe_gmac_disable_interrupt(tp->irq);
+			toe_gmac_disable_tx_rx(tp->dev);
+			toe_gmac_hw_stop(tp->dev);
+		}
+	}
+
+	// clear all status bits
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_0_REG);
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_1_REG);
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_2_REG);
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_3_REG);
+	writel(0xffffffff, TOE_GLOBAL_BASE + GLOBAL_INTERRUPT_STATUS_4_REG);
+
+#if 0
+	if ((hanged_state & GMAC0_RX_HANG_BIT) &&
+		(readl(TOE_GMAC0_DMA_BASE + 0xdc) & 0xf0))
+	{
+		struct sk_buff *skb;
+		unsigned int buf;
+		buf = readl(TOE_GMAC0_DMA_BASE + 0x68) & ~3;
+#ifdef CONFIG_SL351x_NAT
+		if (buf < toe->hwfq_buf_base_dma || buf > toe->hwfq_buf_end_dma)
+#endif
+		{
+			skb = (struct sk_buff *)(REG32(buf - SKB_RESERVE_BYTES));
+			printk("GMAC-0 free a loss SKB 0x%x\n", (u32)skb);
+			dev_kfree_skb(skb);
+		}
+	}
+	if ((hanged_state & GMAC1_RX_HANG_BIT)  &&
+		(readl(TOE_GMAC1_DMA_BASE + 0xdc) & 0xf0))
+	{
+		struct sk_buff *skb;
+		unsigned int buf;
+		buf = readl(TOE_GMAC1_DMA_BASE + 0x68) & ~3;
+#ifdef CONFIG_SL351x_NAT
+		if (buf < toe->hwfq_buf_base_dma || buf > toe->hwfq_buf_end_dma)
+#endif
+		{
+			skb = (struct sk_buff *)(REG32(buf - SKB_RESERVE_BYTES));
+			printk("GMAC-1 free a loss SKB 0x%x\n", (u32)skb);
+			dev_kfree_skb(skb);
+		}
+	}
+#endif
+
+	sl351x_gmac_release_buffers();
+	sl351x_gmac_save_reg();
+	toe_gmac_sw_reset();
+	sl351x_gmac_restore_reg();
+
+	if (toe->gmac[0].default_qhdr->word1.bits32)
+	{
+		// printk("===> toe->gmac[0].default_qhdr->word1 = 0x%x\n", toe->gmac[0].default_qhdr->word1);
+		sl351x_gmac_release_rx_q();
+		writel(0, &toe->gmac[0].default_qhdr->word1);
+	}
+	if (toe->gmac[1].default_qhdr->word1.bits32)
+	{
+		// printk("===> toe->gmac[1].default_qhdr->word1 = 0x%x\n", toe->gmac[1].default_qhdr->word1);
+		sl351x_gmac_release_rx_q();
+		writel(0, &toe->gmac[1].default_qhdr->word1);
+	}
+
+	gmac_initialized = 1;
+
+#ifdef 	CONFIG_SL351x_NAT
+	writel(0, TOE_GLOBAL_BASE + 0x4084);
+#endif
+
+	for (i=0; i<GMAC_NUM; i++)
+	{
+		tp=(GMAC_INFO_T *)&toe->gmac[i];
+ 		if (tp->operation)
+ 		{
+			toe_gmac_enable_interrupt(tp->irq);
+			toe_gmac_hw_start(tp->dev);
+			toe_gmac_enable_tx_rx(tp->dev);
+			netif_wake_queue(tp->dev);
+			set_bit(__LINK_STATE_START, &tp->dev->state);
+		}
+	}
+
+	gmac_in_do_workaround = 0;
+	add_timer(&gmac_workround_timer_obj);
+}
+
+/*----------------------------------------------------------------------
+*	get_free_desc_cnt
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static int get_free_desc_cnt(unsigned long rwptr, int total)
+{
+	unsigned short wptr = rwptr & 0xffff;
+	unsigned short rptr = rwptr >> 16;
+
+	if (wptr >= rptr)
+		return (total - wptr + rptr);
+	else
+		return (rptr - wptr);
+}
+#endif
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_buffers
+*----------------------------------------------------------------------*/
+static void sl351x_gmac_release_buffers(void)
+{
+	// Free buffers & Descriptors in all SW Tx Queues
+	sl351x_gmac_release_swtx_q();
+
+	// Free buffers in Default Rx Queues
+	sl351x_gmac_release_rx_q();
+
+#ifdef _TOEQ_CLASSQ_READY_
+	// Free buffers in Classification Queues
+	sl351x_gmac_release_class_q();
+
+	// Free buffers in TOE Queues
+	sl351x_gmac_release_toe_q();
+
+	// Free buffers in Interrupt Queues
+	sl351x_gmac_release_intr_q();
+#endif
+
+	// Free buffers & descriptors in SW free queue
+	sl351x_gmac_release_sw_free_q();
+
+	// Free buffers & descriptors in HW free queue
+	sl351x_gmac_release_hw_free_q();
+
+#ifdef CONFIG_SL351x_NAT
+	// Free buffers & descriptors in HW free queue
+	sl351x_gmac_release_hwtx_q();
+#endif
+}
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_swtx_q
+*----------------------------------------------------------------------*/
+static void sl351x_gmac_release_swtx_q(void)
+{
+	int				i, j;
+	GMAC_TXDESC_T	*curr_desc;
+	unsigned int	desc_count;
+	TOE_INFO_T		*toe;
+	GMAC_INFO_T		*tp;
+	GMAC_SWTXQ_T	*swtxq;
+	DMA_RWPTR_T		rwptr;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	tp = (GMAC_INFO_T *)&toe->gmac[0];
+	for (i=0; i<GMAC_NUM; i++, tp++)
+	{
+		if (!tp->existed) continue;
+		swtxq = (GMAC_SWTXQ_T *)&tp->swtxq[0];
+		for (j=0; j<TOE_SW_TXQ_NUM; j++, swtxq++)
+		{
+			for (;;)
+			{
+				rwptr.bits32 = readl(swtxq->rwptr_reg);
+				if (rwptr.bits.rptr == swtxq->finished_idx)
+				break;
+				curr_desc = (GMAC_TXDESC_T *)swtxq->desc_base + swtxq->finished_idx;
+				// if (curr_desc->word0.bits.status_tx_ok)
+				{
+					desc_count = curr_desc->word0.bits.desc_count;
+					while (--desc_count)
+					{
+						curr_desc->word0.bits.status_tx_ok = 0;
+						swtxq->finished_idx = RWPTR_ADVANCE_ONE(swtxq->finished_idx, swtxq->total_desc_num);
+						curr_desc = (GMAC_TXDESC_T *)swtxq->desc_base + swtxq->finished_idx;
+					}
+
+					curr_desc->word0.bits.status_tx_ok = 0;
+					if (swtxq->tx_skb[swtxq->finished_idx])
+					{
+						dev_kfree_skb_irq(swtxq->tx_skb[swtxq->finished_idx]);
+						swtxq->tx_skb[swtxq->finished_idx] = NULL;
+					}
+				}
+				swtxq->finished_idx = RWPTR_ADVANCE_ONE(swtxq->finished_idx, swtxq->total_desc_num);
+			}
+			writel(0, swtxq->rwptr_reg);
+			swtxq->finished_idx = 0;
+		}
+	}
+
+}
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_rx_q
+*----------------------------------------------------------------------*/
+static void sl351x_gmac_release_rx_q(void)
+{
+	int				i;
+	TOE_INFO_T		*toe;
+	GMAC_INFO_T		*tp;
+	DMA_RWPTR_T		rwptr;
+	volatile GMAC_RXDESC_T	*curr_desc;
+	struct sk_buff			*skb;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	tp = (GMAC_INFO_T *)&toe->gmac[0];
+	for (i=0; i<GMAC_NUM; i++, tp++)
+	{
+		if (!tp->existed) continue;
+		rwptr.bits32 = readl(&tp->default_qhdr->word1);
+		while (rwptr.bits.rptr != rwptr.bits.wptr)
+		{
+			curr_desc = (GMAC_RXDESC_T *)tp->default_desc_base + rwptr.bits.rptr;
+			skb = (struct sk_buff *)(REG32(__va(curr_desc->word2.buf_adr) - SKB_RESERVE_BYTES));
+			dev_kfree_skb_irq(skb);
+			rwptr.bits.rptr = RWPTR_ADVANCE_ONE(rwptr.bits.rptr, tp->default_desc_num);
+			SET_RPTR(&tp->default_qhdr->word1, rwptr.bits.rptr);
+			rwptr.bits32 = readl(&tp->default_qhdr->word1);
+		}  // while
+		writel(0, &tp->default_qhdr->word1);
+		tp->rx_rwptr.bits32 = 0;
+	} // for
+
+}
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_class_q
+*----------------------------------------------------------------------*/
+#ifdef _TOEQ_CLASSQ_READY_
+static void sl351x_gmac_release_class_q(void)
+{
+	int				i;
+	TOE_INFO_T		*toe;
+	CLASSQ_INFO_T	*classq;
+	DMA_RWPTR_T		rwptr;
+	volatile GMAC_RXDESC_T	*curr_desc;
+	struct sk_buff			*skb;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	classq = (CLASSQ_INFO_T *)&toe->classq[0];
+	for (i=0; i<TOE_CLASS_QUEUE_NUM; i++, classq++)
+	{
+		rwptr.bits32 = readl(&classq->qhdr->word1);
+		while (rwptr.bits.rptr != rwptr.bits.wptr)
+		{
+			curr_desc = (GMAC_RXDESC_T *)classq->desc_base + rwptr.bits.rptr;
+			skb = (struct sk_buff *)(REG32(__va(curr_desc->word2.buf_adr) - SKB_RESERVE_BYTES));
+			dev_kfree_skb_irq(skb);
+			rwptr.bits.rptr = RWPTR_ADVANCE_ONE(rwptr.bits.rptr, classq->desc_num);
+			SET_RPTR(&classq->qhdr->word1, rwptr.bits.rptr);
+			rwptr.bits32 = readl(&classq->qhdr->word1);
+		}  // while
+		writel(0, &classq->qhdr->word1);
+		classq->rwptr.bits32 = 0;
+	} // for
+
+}
+#endif
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_toe_q
+*----------------------------------------------------------------------*/
+#ifdef _TOEQ_CLASSQ_READY_
+static void sl351x_gmac_release_toe_q(void)
+{
+	int				i;
+	TOE_INFO_T		*toe;
+	TOEQ_INFO_T		*toeq_info;
+	TOE_QHDR_T		*toe_qhdr;
+	DMA_RWPTR_T		rwptr;
+	volatile GMAC_RXDESC_T	*curr_desc;
+	unsigned int	rptr, wptr;
+	GMAC_RXDESC_T	*toe_curr_desc;
+	struct sk_buff			*skb;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	toe_qhdr = (TOE_QHDR_T *)TOE_TOE_QUE_HDR_BASE;
+	for (i=0; i<TOE_TOE_QUEUE_NUM; i++, toe_qhdr++)
+	{
+		toeq_info = (TOEQ_INFO_T *)&toe->toeq[i];
+		wptr = toe_qhdr->word1.bits.wptr;
+		rptr = toe_qhdr->word1.bits.rptr;
+		while (rptr != wptr)
+		{
+			toe_curr_desc = (GMAC_RXDESC_T *)toeq_info->desc_base + rptr;
+			skb = (struct sk_buff *)(REG32(__va(toe_curr_desc->word2.buf_adr) - SKB_RESERVE_BYTES));
+			dev_kfree_skb_irq(skb);
+			rptr = RWPTR_ADVANCE_ONE(rptr, toeq_info->desc_num);
+			SET_RPTR(&toe_qhdr->word1.bits32, rptr);
+			wptr = toe_qhdr->word1.bits.wptr;
+			rptr = toe_qhdr->word1.bits.rptr;
+		}
+		toe_qhdr->word1.bits32 = 0;
+		toeq_info->rwptr.bits32 = 0;
+	}
+}
+#endif
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_intr_q
+*----------------------------------------------------------------------*/
+#ifdef _TOEQ_CLASSQ_READY_
+static void sl351x_gmac_release_intr_q(void)
+{
+}
+#endif
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_sw_free_q
+*----------------------------------------------------------------------*/
+static void sl351x_gmac_release_sw_free_q(void)
+{
+	TOE_INFO_T				*toe;
+	volatile DMA_RWPTR_T	fq_rwptr;
+	volatile GMAC_RXDESC_T	*fq_desc;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+
+	while ((unsigned short)RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr, TOE_SW_FREEQ_DESC_NUM) != fq_rwptr.bits.rptr)
+	{
+		struct sk_buff *skb;
+		if ((skb = dev_alloc_skb(SW_RX_BUF_SIZE))==NULL)  /* allocate socket buffer */
+		{
+			printk("%s::skb buffer allocation fail !\n",__func__); while(1);
+		}
+		// *(unsigned int *)(skb->data) = (unsigned int)skb;
+		REG32(skb->data) = (unsigned long)skb;
+		skb_reserve(skb, SKB_RESERVE_BYTES);
+
+		fq_rwptr.bits.wptr = RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr, TOE_SW_FREEQ_DESC_NUM);
+		fq_desc = (volatile GMAC_RXDESC_T *)toe->swfq_desc_base + fq_rwptr.bits.wptr;
+		fq_desc->word2.buf_adr = (unsigned int)__pa(skb->data);
+		SET_WPTR(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG, fq_rwptr.bits.wptr);
+		fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+	}
+
+	toe->fq_rx_rwptr.bits.wptr = TOE_SW_FREEQ_DESC_NUM - 1;
+	toe->fq_rx_rwptr.bits.rptr = 0;
+	writel(toe->fq_rx_rwptr.bits32, TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+
+}
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_hw_free_q
+*----------------------------------------------------------------------*/
+static void sl351x_gmac_release_hw_free_q(void)
+{
+	DMA_RWPTR_T			rwptr_reg;
+
+#ifdef CONFIG_SL351x_NAT
+	int					i;
+	TOE_INFO_T			*toe;
+	GMAC_RXDESC_T		*desc_ptr;
+	unsigned int		buf_ptr;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+	desc_ptr = (GMAC_RXDESC_T *)toe->hwfq_desc_base;
+	buf_ptr = (unsigned int)toe->hwfq_buf_base_dma;
+	for (i=0; i<TOE_HW_FREEQ_DESC_NUM; i++)
+	{
+		desc_ptr->word0.bits.buffer_size = HW_RX_BUF_SIZE;
+		desc_ptr->word1.bits.sw_id = i;
+		desc_ptr->word2.buf_adr = (unsigned int)buf_ptr;
+   		desc_ptr++;
+   		buf_ptr += HW_RX_BUF_SIZE;
+	}
+#endif
+	rwptr_reg.bits.wptr = TOE_HW_FREEQ_DESC_NUM - 1;
+	rwptr_reg.bits.rptr = 0;
+	writel(rwptr_reg.bits32, TOE_GLOBAL_BASE + GLOBAL_HWFQ_RWPTR_REG);
+}
+
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_release_hw_free_q
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static void sl351x_gmac_release_hwtx_q(void)
+{
+	int				i;
+	unsigned int	rwptr_addr;
+
+	rwptr_addr = TOE_GMAC0_DMA_BASE + GMAC_HW_TX_QUEUE0_PTR_REG;
+	for (i=0; i<TOE_HW_TXQ_NUM; i++)
+	{
+		writel(0, rwptr_addr);
+		rwptr_addr+=4;
+	}
+	rwptr_addr = TOE_GMAC1_DMA_BASE + GMAC_HW_TX_QUEUE0_PTR_REG;
+	for (i=0; i<TOE_HW_TXQ_NUM; i++)
+	{
+		writel(0, rwptr_addr);
+		rwptr_addr+=4;
+	}
+}
+#endif
+
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_save_reg
+*----------------------------------------------------------------------*/
+void sl351x_gmac_save_reg(void)
+{
+	int	i;
+	volatile u32	*destp;
+	unsigned int	srce_addr;
+
+	srce_addr = TOE_GLOBAL_BASE;
+	destp = (volatile u32 *)toe_global_reg;
+	for (i=0; i<TOE_GLOBAL_REG_SIZE; i++, destp++, srce_addr+=4)
+		*destp = readl(srce_addr);
+
+	srce_addr = TOE_GMAC0_DMA_BASE;
+	destp = (volatile u32 *)&toe_dma_reg[0][0];
+	for (i=0; i<TOE_DMA_REG_SIZE; i++, destp++, srce_addr+=4)
+	{
+		if (srce_addr ==  (TOE_GMAC0_DMA_BASE+0x38))
+			srce_addr = (TOE_GMAC0_DMA_BASE+0x50);
+		if (srce_addr ==  (TOE_GMAC0_DMA_BASE+0x58))
+			srce_addr = (TOE_GMAC0_DMA_BASE+0x70);
+
+		*destp = readl(srce_addr);
+	}
+	srce_addr = TOE_GMAC1_DMA_BASE;
+	destp = (volatile u32 *)&toe_dma_reg[1][0];
+	for (i=0; i<TOE_DMA_REG_SIZE; i++, destp++, srce_addr+=4)
+	{
+		if (srce_addr ==  (TOE_GMAC0_DMA_BASE+0x38))
+			srce_addr = (TOE_GMAC0_DMA_BASE+0x50);
+		if (srce_addr ==  (TOE_GMAC0_DMA_BASE+0x58))
+			srce_addr = (TOE_GMAC0_DMA_BASE+0x70);
+
+		*destp = readl(srce_addr);
+	}
+
+	srce_addr = TOE_GMAC0_BASE;
+	destp = (volatile u32 *)&toe_gmac_reg[0][0];
+	for (i=0; i<TOE_GMAC_REG_SIZE; i++, destp++, srce_addr+=4)
+		*destp = readl(srce_addr);
+
+	srce_addr = TOE_GMAC1_BASE;
+	destp = (volatile u32 *)&toe_gmac_reg[1][0];
+	for (i=0; i<TOE_GMAC_REG_SIZE; i++, destp++, srce_addr+=4)
+		*destp = readl(srce_addr);
+}
+
+/*----------------------------------------------------------------------
+* 	sl351x_gmac_restore_reg
+*----------------------------------------------------------------------*/
+void sl351x_gmac_restore_reg(void)
+{
+	int	i;
+	volatile u32	*srcep;
+	unsigned int	dest_addr;
+
+	srcep = (volatile u32 *)&toe_dma_reg[0][0];
+	dest_addr = TOE_GMAC0_DMA_BASE;
+	for (i=0; i<TOE_DMA_REG_SIZE; i++, dest_addr+=4, srcep++)
+	{
+		if (dest_addr == (TOE_GMAC0_DMA_BASE+0x38))
+			dest_addr = (TOE_GMAC0_DMA_BASE+0x50);
+		if (dest_addr == (TOE_GMAC0_DMA_BASE+0x58))
+			dest_addr = (TOE_GMAC0_DMA_BASE+0x70);
+
+		writel(*srcep, dest_addr);
+		// gmac_write_reg(dest_addr, 0, *srcep, 0xffffffff);
+	}
+	srcep = (volatile u32 *)&toe_dma_reg[1][0];
+	dest_addr = TOE_GMAC1_DMA_BASE;
+	for (i=0; i<TOE_DMA_REG_SIZE; i++, dest_addr+=4, srcep++)
+	{
+		if (dest_addr == (TOE_GMAC0_DMA_BASE+0x38))
+			dest_addr = (TOE_GMAC0_DMA_BASE+0x50);
+		if (dest_addr == (TOE_GMAC0_DMA_BASE+0x58))
+			dest_addr = (TOE_GMAC0_DMA_BASE+0x70);
+
+		writel(*srcep, dest_addr);
+		// gmac_write_reg(dest_addr, 0, *srcep, 0xffffffff);
+	}
+
+	srcep = (volatile u32 *)&toe_gmac_reg[0][0];
+	dest_addr = TOE_GMAC0_BASE;
+	for (i=0; i<TOE_GMAC_REG_SIZE; i++, dest_addr+=4, srcep++)
+		writel(*srcep, dest_addr);
+
+	srcep = (volatile u32 *)&toe_gmac_reg[1][0];
+	dest_addr = TOE_GMAC1_BASE;
+	for (i=0; i<TOE_GMAC_REG_SIZE; i++, dest_addr+=4, srcep++)
+		writel(*srcep, dest_addr);
+
+	srcep = (volatile u32 *)toe_global_reg;
+	dest_addr = TOE_GLOBAL_BASE;
+	for (i=0; i<TOE_GLOBAL_REG_SIZE; i++, dest_addr+=4, srcep++)
+		writel(*srcep, dest_addr);
+
+}
+
+#ifdef CONFIG_SL351x_NAT
+/*----------------------------------------------------------------------
+* 	sl351x_nat_workaround_init
+*----------------------------------------------------------------------*/
+#define NAT_WORAROUND_DESC_POWER	(6)
+#define NAT_WORAROUND_DESC_NUM		(2 << NAT_WORAROUND_DESC_POWER)
+dma_addr_t sl351x_nat_workaround_desc_dma;
+void sl351x_nat_workaround_init(void)
+{
+	unsigned int	desc_buf;
+
+	desc_buf = (unsigned int)DMA_MALLOC((NAT_WORAROUND_DESC_NUM * sizeof(GMAC_RXDESC_T)),
+						(dma_addr_t *)&sl351x_nat_workaround_desc_dma) ;
+	memset((void *)desc_buf, 0, NAT_WORAROUND_DESC_NUM * sizeof(GMAC_RXDESC_T));
+
+	// DMA Queue Base & Size
+	writel((sl351x_nat_workaround_desc_dma & DMA_Q_BASE_MASK) | NAT_WORAROUND_DESC_POWER,
+			TOE_GLOBAL_BASE + 0x4080);
+	writel(0, TOE_GLOBAL_BASE + 0x4084);
+}
+
+/*----------------------------------------------------------------------
+* 	sl351x_nat_workaround_handler
+*----------------------------------------------------------------------*/
+#ifndef NAT_WORKAROUND_BY_RESET_GMAC
+static void sl351x_nat_workaround_handler(void)
+{
+	int					i;
+	DMA_RWPTR_T			rwptr;
+	GMAC_RXDESC_T		*desc_ptr;
+	unsigned int		buf_ptr;
+	TOE_INFO_T			*toe;
+	GMAC_CONFIG0_T		config0;
+	unsigned int		rwptr_addr;
+
+	toe = (TOE_INFO_T *)&toe_private_data;
+
+	// disable Rx of GMAC-0 & 1
+	config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+	config0.bits.dis_rx = 1;
+	writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+	config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+	config0.bits.dis_rx = 1;
+	writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+
+	// wait GMAC-0 HW Tx finished
+	rwptr_addr = TOE_GMAC0_DMA_BASE + GMAC_HW_TX_QUEUE0_PTR_REG;
+	for (i=0; i<TOE_HW_TXQ_NUM; i++)
+	{
+		rwptr.bits32 = readl(rwptr_addr);
+		if (rwptr.bits.rptr != rwptr.bits.wptr)
+			return;	// wait the HW to send packets and release buffers
+		rwptr_addr+=4;
+	}
+	rwptr_addr = TOE_GMAC1_DMA_BASE + GMAC_HW_TX_QUEUE0_PTR_REG;
+	for (i=0; i<TOE_HW_TXQ_NUM; i++)
+	{
+		rwptr.bits32 = readl(rwptr_addr);
+		if (rwptr.bits.rptr != rwptr.bits.wptr)
+			return;	// wait the HW to send packets and release buffers
+		rwptr_addr+=4;
+	}
+
+	// printk("sl351x_nat_workaround_handler %d\n", sl351x_nat_workaround_cnt);
+	desc_ptr = (GMAC_RXDESC_T *)toe->hwfq_desc_base;
+	buf_ptr = (unsigned int)toe->hwfq_buf_base_dma;
+	for (i=0; i<TOE_HW_FREEQ_DESC_NUM; i++)
+	{
+		desc_ptr->word0.bits.buffer_size = HW_RX_BUF_SIZE;
+		desc_ptr->word1.bits.sw_id = i;
+		desc_ptr->word2.buf_adr = (unsigned int)buf_ptr;
+		desc_ptr++;
+		buf_ptr += HW_RX_BUF_SIZE;
+	}
+	rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_HWFQ_RWPTR_REG);
+	rwptr.bits.wptr = RWPTR_RECEDE_ONE(rwptr.bits.rptr, TOE_HW_FREEQ_DESC_NUM);
+	writel(rwptr.bits32, TOE_GLOBAL_BASE + GLOBAL_HWFQ_RWPTR_REG);
+	writel(0, TOE_GLOBAL_BASE + 0x4084);
+
+	// Enable Rx of GMAC-0 & 1
+	config0.bits32 = readl(TOE_GMAC0_BASE+GMAC_CONFIG0);
+	config0.bits.dis_rx = 0;
+	writel(config0.bits32, TOE_GMAC0_BASE+GMAC_CONFIG0);
+	config0.bits32 = readl(TOE_GMAC1_BASE+GMAC_CONFIG0);
+	config0.bits.dis_rx = 0;
+	writel(config0.bits32, TOE_GMAC1_BASE+GMAC_CONFIG0);
+}
+#endif
+#endif // CONFIG_SL351x_NAT
+
+#endif // SL351x_GMAC_WORKAROUND
+
+/* get the mac addresses from flash
+ *can't do this in module_init because mtd driver is initialized after ethernet
+ */
+static __init int sl351x_mac_address_init(void)
+{
+	GMAC_INFO_T		*tp;
+	struct sockaddr sock;
+	int i;
+
+	/* get mac address from FLASH */
+	gmac_get_mac_address();
+
+	for (i = 0; i < GMAC_NUM; i++) {
+		tp = (GMAC_INFO_T *)&toe_private_data.gmac[i];
+		memcpy(&sock.sa_data[0],&eth_mac[tp->port_id][0],6);
+		gmac_set_mac_address(tp->dev,(void *)&sock);
+	}
+
+        return 0;
+}
+late_initcall(sl351x_mac_address_init);
+
+
--- /dev/null
+++ b/drivers/net/sl351x_hash.c
@@ -0,0 +1,713 @@
+/**************************************************************************
+* Copyright 2006 StorLink Semiconductors, Inc.  All rights reserved.
+*--------------------------------------------------------------------------
+* Name			: sl351x_hash.c
+* Description	:
+*		Handle Storlink SL351x Hash Functions
+*
+* History
+*
+*	Date		Writer		Description
+*----------------------------------------------------------------------------
+*	03/13/2006	Gary Chen	Create and implement
+*
+****************************************************************************/
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/compiler.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
+#include <linux/delay.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/completion.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/semaphore.h>
+#include <asm/arch/irqs.h>
+#include <asm/arch/it8712.h>
+#include <linux/mtd/kvctl.h>
+#include <linux/skbuff.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/list.h>
+#define	 MIDWAY
+#define	 SL_LEPUS
+
+#include <asm/arch/sl2312.h>
+#include <asm/arch/sl351x_gmac.h>
+#include <asm/arch/sl351x_hash_cfg.h>
+
+#ifndef RXTOE_DEBUG
+#define RXTOE_DEBUG
+#endif
+#undef RXTOE_DEBUG
+
+/*----------------------------------------------------------------------
+* Definition
+*----------------------------------------------------------------------*/
+#define	hash_printf				printk
+
+#define HASH_TIMER_PERIOD		(30)	// seconds
+#define HASH_ILLEGAL_INDEX		0xffff
+
+/*----------------------------------------------------------------------
+* Variables
+*----------------------------------------------------------------------*/
+u32					hash_nat_owner_bits[HASH_TOTAL_ENTRIES/32];
+char 				hash_tables[HASH_TOTAL_ENTRIES][HASH_MAX_BYTES] __attribute__ ((aligned(16)));
+static struct timer_list hash_timer_obj;
+LIST_HEAD(hash_timeout_list);
+
+/*----------------------------------------------------------------------
+* Functions
+*----------------------------------------------------------------------*/
+void dm_long(u32 location, int length);
+static void hash_timer_func(u32 data);
+
+/*----------------------------------------------------------------------
+* hash_init
+*----------------------------------------------------------------------*/
+void sl351x_hash_init(void)
+{
+	int i;
+	volatile u32 *dp1, *dp2, dword;
+
+	dp1 = (volatile u32 *) TOE_V_BIT_BASE;
+	dp2 = (volatile u32 *) TOE_A_BIT_BASE;
+
+	for (i=0; i<HASH_TOTAL_ENTRIES/32; i++)
+	{
+		*dp1++ = 0;
+		dword = *dp2++;	// read-clear
+	}
+	memset((void *)&hash_nat_owner_bits, 0, sizeof(hash_nat_owner_bits));
+	memset((void *)&hash_tables, 0, sizeof(hash_tables));
+
+	init_timer(&hash_timer_obj);
+	hash_timer_obj.expires = jiffies + (HASH_TIMER_PERIOD * HZ);
+	hash_timer_obj.data = (unsigned long)&hash_timer_obj;
+	hash_timer_obj.function = (void *)&hash_timer_func;
+	add_timer(&hash_timer_obj);
+
+#if (HASH_MAX_BYTES == 128)
+	writel((unsigned long)__pa(&hash_tables) | 3,	// 32 words
+			TOE_GLOBAL_BASE + GLOBAL_HASH_TABLE_BASE_REG);
+#elif (HASH_MAX_BYTES == 64)
+	writel((unsigned long)__pa(&hash_tables) | 2,	// 16 words
+			TOE_GLOBAL_BASE + GLOBAL_HASH_TABLE_BASE_REG);
+#else
+	#error Incorrect setting for HASH_MAX_BYTES
+#endif
+
+}
+/*----------------------------------------------------------------------
+* hash_add_entry
+*----------------------------------------------------------------------*/
+int hash_add_entry(HASH_ENTRY_T *entry)
+{
+	int	rc;
+	u32	key[HASH_MAX_DWORDS];
+	rc = hash_build_keys((u32 *)&key, entry);
+	if (rc < 0)
+		return -1;
+	hash_write_entry(entry, (unsigned char*) &key[0]);
+//	hash_set_valid_flag(entry->index, 1);
+//	printk("Dump hash key!\n");
+//	dump_hash_key(entry);
+	return entry->index;
+}
+
+/*----------------------------------------------------------------------
+* hash_set_valid_flag
+*----------------------------------------------------------------------*/
+void hash_set_valid_flag(int index, int valid)
+{
+	register u32 reg32;
+
+	reg32 = TOE_V_BIT_BASE + (index/32) * 4;
+
+	if (valid)
+	{
+		writel(readl(reg32) | (1 << (index%32)), reg32);
+	}
+	else
+	{
+		writel(readl(reg32) & ~(1 << (index%32)), reg32);
+	}
+}
+
+/*----------------------------------------------------------------------
+* hash_set_nat_owner_flag
+*----------------------------------------------------------------------*/
+void hash_set_nat_owner_flag(int index, int valid)
+{
+	if (valid)
+	{
+		hash_nat_owner_bits[index/32] |= (1 << (index % 32));
+	}
+	else
+	{
+		hash_nat_owner_bits[index/32] &= ~(1 << (index % 32));
+	}
+}
+
+
+/*----------------------------------------------------------------------
+* hash_build_keys
+*----------------------------------------------------------------------*/
+int hash_build_keys(u32 *destp, HASH_ENTRY_T *entry)
+{
+	u32 	data;
+	unsigned char 	*cp;
+	int				i, j;
+	unsigned short 	index;
+	int 			total;
+
+	memset((void *)destp, 0, HASH_MAX_BYTES);
+	cp = (unsigned char *)destp;
+
+	if (entry->key_present.port || entry->key_present.Ethertype)
+	{
+		HASH_PUSH_WORD(cp, entry->key.Ethertype);		// word 0
+		HASH_PUSH_BYTE(cp, entry->key.port);			// Byte 2
+		HASH_PUSH_BYTE(cp, 0);							// Byte 3
+	}
+	else
+	{
+		HASH_PUSH_DWORD(cp, 0);
+	}
+
+	if (entry->key_present.da || entry->key_present.sa)
+	{
+		unsigned char mac[4];
+		if (entry->key_present.da)
+		{
+			for (i=0; i<4; i++)
+				HASH_PUSH_BYTE(cp, entry->key.da[i]);
+		}
+		mac[0] = (entry->key_present.da) ? entry->key.da[4] : 0;
+		mac[1] = (entry->key_present.da) ? entry->key.da[5] : 0;
+		mac[2] = (entry->key_present.sa) ? entry->key.sa[0] : 0;
+		mac[3] = (entry->key_present.sa) ? entry->key.sa[1] : 0;
+		data = mac[0] + (mac[1]<<8) + (mac[2]<<16) + (mac[3]<<24);
+		HASH_PUSH_DWORD(cp, data);
+		if (entry->key_present.sa)
+		{
+			for (i=2; i<6; i++)
+				HASH_PUSH_BYTE(cp, entry->key.sa[i]);
+		}
+	}
+
+	if (entry->key_present.pppoe_sid || entry->key_present.vlan_id)
+	{
+		HASH_PUSH_WORD(cp, entry->key.vlan_id);		// low word
+		HASH_PUSH_WORD(cp, entry->key.pppoe_sid);	// high word
+	}
+	if (entry->key_present.ipv4_hdrlen || entry->key_present.ip_tos || entry->key_present.ip_protocol)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.ip_protocol);		// Byte 0
+		HASH_PUSH_BYTE(cp, entry->key.ip_tos);			// Byte 1
+		HASH_PUSH_BYTE(cp, entry->key.ipv4_hdrlen);		// Byte 2
+		HASH_PUSH_BYTE(cp, 0);							// Byte 3
+	}
+
+	if (entry->key_present.ipv6_flow_label)
+	{
+		HASH_PUSH_DWORD(cp, entry->key.ipv6_flow_label);	// low word
+	}
+	if (entry->key_present.sip)
+	{
+		// input (entry->key.sip[i]) is network-oriented
+		// output (hash key) is host-oriented
+		for (i=3; i>=0; i--)
+			HASH_PUSH_BYTE(cp, entry->key.sip[i]);
+		if (entry->key.ipv6)
+		{
+			for (i=4; i<16; i+=4)
+			{
+				for (j=i+3; j>=i; j--)
+					HASH_PUSH_BYTE(cp, entry->key.sip[j]);
+			}
+		}
+	}
+	if (entry->key_present.dip)
+	{
+		// input (entry->key.sip[i]) is network-oriented
+		// output (hash key) is host-oriented
+		for (i=3; i>=0; i--)
+			HASH_PUSH_BYTE(cp, entry->key.dip[i]);
+		if (entry->key.ipv6)
+		{
+			for (i=4; i<16; i+=4)
+			{
+				for (j=i+3; j>=i; j--)
+					HASH_PUSH_BYTE(cp, entry->key.dip[j]);
+			}
+		}
+	}
+
+	if (entry->key_present.l4_bytes_0_3)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[0]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[1]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[2]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[3]);
+	}
+	if (entry->key_present.l4_bytes_4_7)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[4]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[5]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[6]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[7]);
+	}
+	if (entry->key_present.l4_bytes_8_11)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[8]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[9]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[10]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[11]);
+	}
+	if (entry->key_present.l4_bytes_12_15)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[12]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[13]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[14]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[15]);
+	}
+	if (entry->key_present.l4_bytes_16_19)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[16]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[17]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[18]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[19]);
+	}
+	if (entry->key_present.l4_bytes_20_23)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[20]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[21]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[22]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[23]);
+	}
+	if (entry->key_present.l7_bytes_0_3)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[0]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[1]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[2]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[3]);
+	}
+	if (entry->key_present.l7_bytes_4_7)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[4]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[5]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[6]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[7]);
+	}
+	if (entry->key_present.l7_bytes_8_11)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[8]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[9]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[10]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[11]);
+	}
+	if (entry->key_present.l7_bytes_12_15)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[12]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[13]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[14]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[15]);
+	}
+	if (entry->key_present.l7_bytes_16_19)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[16]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[17]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[18]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[19]);
+	}
+	if (entry->key_present.l7_bytes_20_23)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[20]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[21]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[22]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[23]);
+	}
+
+	// get hash index
+	total = (u32)((u32)cp - (u32)destp) / (sizeof(u32));
+
+	if (total > HASH_MAX_KEY_DWORD)
+	{
+		//hash_printf("Total key words (%d) is too large (> %d)!\n",
+		//				total, HASH_MAX_KEY_DWORD);
+		return -1;
+	}
+
+	if (entry->key_present.port || entry->key_present.Ethertype)
+		index = hash_gen_crc16((unsigned char *)destp, total * 4);
+	else
+	{
+		if (total == 1)
+		{
+			hash_printf("No key is assigned!\n");
+			return -1;
+		}
+
+		index = hash_gen_crc16((unsigned char *)(destp+1), (total-1) * 4);
+	}
+
+	entry->index = index & HASH_BITS_MASK;
+
+	//hash_printf("Total key words = %d, Hash Index= %d\n",
+	//				total, entry->index);
+
+	cp = (unsigned char *)destp;
+	cp+=3;
+	HASH_PUSH_BYTE(cp, entry->rule);	// rule
+
+	entry->total_dwords = total;
+
+	return total;
+}
+
+/*----------------------------------------------------------------------
+* hash_build_nat_keys
+*----------------------------------------------------------------------*/
+void hash_build_nat_keys(u32 *destp, HASH_ENTRY_T *entry)
+{
+	unsigned char 	*cp;
+	int				i;
+	unsigned short 	index;
+	int 			total;
+
+	memset((void *)destp, 0, HASH_MAX_BYTES);
+
+	cp = (unsigned char *)destp + 2;
+	HASH_PUSH_BYTE(cp, entry->key.port);
+	cp++;
+
+	if (entry->key_present.pppoe_sid || entry->key_present.vlan_id)
+	{
+		HASH_PUSH_WORD(cp, entry->key.vlan_id);		// low word
+		HASH_PUSH_WORD(cp, entry->key.pppoe_sid);	// high word
+	}
+
+	HASH_PUSH_BYTE(cp, entry->key.ip_protocol);
+	cp+=3;
+
+	// input (entry->key.sip[i]) is network-oriented
+	// output (hash key) is host-oriented
+	for (i=3; i>=0; i--)
+		HASH_PUSH_BYTE(cp, entry->key.sip[i]);
+
+	// input (entry->key.sip[i]) is network-oriented
+	// output (hash key) is host-oriented
+	for (i=3; i>=0; i--)
+		HASH_PUSH_BYTE(cp, entry->key.dip[i]);
+
+	HASH_PUSH_BYTE(cp, entry->key.l4_bytes[0]);
+	HASH_PUSH_BYTE(cp, entry->key.l4_bytes[1]);
+	HASH_PUSH_BYTE(cp, entry->key.l4_bytes[2]);
+	HASH_PUSH_BYTE(cp, entry->key.l4_bytes[3]);
+
+	// get hash index
+	total = (u32)((u32)cp - (u32)destp) / (sizeof(u32));
+
+	index = hash_gen_crc16((unsigned char *)destp, total * 4);
+	entry->index = index & ((1 << HASH_BITS) - 1);
+
+	cp = (unsigned char *)destp;
+	cp+=3;
+	HASH_PUSH_BYTE(cp, entry->rule);	// rule
+
+	entry->total_dwords = total;
+}
+
+/*----------------------------------------------------------------------
+* hash_build_toe_keys
+*----------------------------------------------------------------------*/
+int hash_build_toe_keys(u32 *destp, HASH_ENTRY_T *entry)
+{
+	unsigned long	data;
+	unsigned char	*cp;
+	unsigned short	index;
+	int	i;
+	int total;
+	//printk("%s\n", __func__);
+	memset((void*)destp, 0, HASH_MAX_BYTES);
+	cp = (unsigned char*)destp;
+
+	if(entry->key_present.port || entry->key_present.Ethertype) {
+		data = (entry->key.port << 16) + entry->key.Ethertype;
+		HASH_PUSH_DWORD(cp, data);
+	} else
+		HASH_PUSH_DWORD(cp, 0);
+
+	if (entry->key_present.da || entry->key_present.sa) {
+		unsigned char	mac[4];
+		if (entry->key_present.da) {
+			data = (entry->key.da[0]) + (entry->key.da[1] << 8) +
+				   (entry->key.da[2] << 16) + (entry->key.da[3] <<24);
+			HASH_PUSH_DWORD(cp, data);
+		}
+		mac[0] = (entry->key_present.da) ? entry->key.da[4] : 0;
+		mac[1] = (entry->key_present.da) ? entry->key.da[5] : 0;
+		mac[2] = (entry->key_present.sa) ? entry->key.sa[0] : 0;
+		mac[3] = (entry->key_present.sa) ? entry->key.sa[1] : 0;
+		data = mac[0] + (mac[1]<<8) + (mac[2]<<16) + (mac[3]<<24);
+		HASH_PUSH_DWORD(cp, data);
+		if (entry->key_present.sa) {
+			data = (entry->key.sa[2]) + (entry->key.sa[3] << 8) +
+				   (entry->key.sa[4] << 16) + (entry->key.sa[5] <<24);
+			HASH_PUSH_DWORD(cp, data);
+		}
+	}
+
+	if (entry->key_present.ip_protocol) {
+		unsigned char ip_protocol;
+		ip_protocol = entry->key.ip_protocol;
+		data = ip_protocol;
+		HASH_PUSH_DWORD(cp, data);
+	}
+
+	if (entry->key_present.ipv6_flow_label) {
+		unsigned long flow_label;
+		flow_label  = entry->key.ipv6_flow_label;
+		data = flow_label & 0xfffff;
+		HASH_PUSH_DWORD(cp, data);
+	}
+
+	if (entry->key_present.sip)	{
+		{
+			data = IPIV(entry->key.sip[0], entry->key.sip[1],
+					entry->key.sip[2], entry->key.sip[3]);
+			HASH_PUSH_DWORD(cp, data);
+			if (entry->key.ipv6) {
+				for (i=4; i<16; i+=4) {
+					data = IPIV(entry->key.sip[i+0], entry->key.sip[i+1],
+							entry->key.sip[i+2], entry->key.sip[i+3]);
+					HASH_PUSH_DWORD(cp, data);
+				}
+			}
+		}
+	}
+
+	if (entry->key_present.dip)	{
+		{
+			data = IPIV(entry->key.dip[0], entry->key.dip[1],
+						entry->key.dip[2], entry->key.dip[3]);
+			HASH_PUSH_DWORD(cp, data);
+			if (entry->key.ipv6) {
+				for (i=4; i<16; i+=4) {
+					data = IPIV(entry->key.dip[i+0], entry->key.dip[i+1],
+								entry->key.dip[i+2], entry->key.dip[i+3]);
+					HASH_PUSH_DWORD(cp, data);
+				}
+			}
+		}
+	}
+	if (entry->key_present.l4_bytes_0_3)
+	{
+		unsigned char *datap;
+		datap = &entry->key.l4_bytes[0];
+		data = 	datap[0] + 	(datap[1] << 8) + (datap[2] << 16) + (datap[3] << 24);
+		HASH_PUSH_DWORD(cp, data);
+	}
+	if (entry->key_present.l7_bytes_0_3)
+	{
+		unsigned char *datap;
+		datap = &entry->key.l7_bytes[0];
+		data = 	datap[0] + 	(datap[1] << 8) + (datap[2] << 16) + (datap[3] << 24);
+		HASH_PUSH_DWORD(cp, data);
+	}
+	if (entry->key_present.l7_bytes_4_7)
+	{
+		unsigned char *datap;
+		datap = &entry->key.l7_bytes[4];
+		data = 	datap[0] + 	(datap[1] << 8) + (datap[2] << 16) + (datap[3] << 24);
+		HASH_PUSH_DWORD(cp, data);
+	}
+
+	total = (unsigned long)((unsigned long)cp - (unsigned long)destp) / (sizeof(u32));
+	if (total > HASH_MAX_KEY_DWORD) {
+		//printf("Total key words (%d) is too large (> %d)!\n",
+		//		total, HASH_MAX_KEY_DWORD);
+		return -1;
+	}
+	index = hash_gen_crc16((unsigned char*)(destp + 1), (total-1)*4);
+	entry->index = index & ((1 << HASH_BITS)-1);
+
+	cp = (unsigned char*) destp;
+	cp += 3;
+	HASH_PUSH_BYTE(cp, entry->rule);
+	entry->total_dwords = total;
+	return total;
+}
+
+/*----------------------------------------------------------------------
+* hash_add_toe_entry
+*----------------------------------------------------------------------*/
+int hash_add_toe_entry(HASH_ENTRY_T *entry)
+{
+	int	rc;
+	u32	key[HASH_MAX_DWORDS];
+
+	rc = hash_build_toe_keys((u32 *)&key, entry);
+	if (rc < 0)
+		return -1;
+	hash_write_entry(entry, (unsigned char*) &key[0]);
+	//hash_dump_entry(entry->index);
+//	hash_set_valid_flag(entry->index, 1);
+//	printk("Dump hash key!\n");
+//	dump_hash_key(entry);
+	return entry->index;
+}
+
+
+/*----------------------------------------------------------------------
+* hash_write_entry
+*----------------------------------------------------------------------*/
+int hash_write_entry(HASH_ENTRY_T *entry, unsigned char *key)
+{
+	int		i;
+	u32		*srcep, *destp, *destp2;
+
+	srcep = (u32 *)key;
+	destp2 = destp = (u32 *)&hash_tables[entry->index][0];
+
+	for (i=0; i<(entry->total_dwords); i++, srcep++, destp++)
+		*destp = *srcep;
+
+	srcep = (u32 *)&entry->action;
+	*destp++ = *srcep;
+
+	srcep = (u32 *)&entry->param;
+	for (i=0; i<(sizeof(ENTRY_PARAM_T)/sizeof(*destp)); i++, srcep++, destp++)
+		*destp = *srcep;
+
+	memset(destp, 0, (HASH_MAX_DWORDS-entry->total_dwords-HASH_ACTION_DWORDS) * sizeof(u32));
+
+	consistent_sync(destp2, (entry->total_dwords+HASH_ACTION_DWORDS) * 4, PCI_DMA_TODEVICE);
+	return 0;
+}
+
+/*----------------------------------------------------------------------
+* hash_timer_func
+*----------------------------------------------------------------------*/
+static void hash_timer_func(u32 data)
+{
+	int					i, j, idx;
+	volatile u32		*own_p, *valid_p;
+	u32					own_bits, a_bits;
+	int					period = HASH_TIMER_PERIOD;
+
+	valid_p = (volatile u32 *)TOE_V_BIT_BASE;
+	own_p = (volatile u32 *)hash_nat_owner_bits;
+	for (i=0, idx=0; i<(HASH_TOTAL_ENTRIES/32); i++, own_p++, valid_p++, idx+=32)
+	{
+		a_bits = readl(TOE_A_BIT_BASE + (i*4));
+		own_bits = *own_p;
+		if (own_bits)
+		{
+			for (j=0; own_bits && j<32; j++)
+			{
+				if (own_bits & 1)
+				{
+					short *counter_p, *interval_p;
+					NAT_HASH_ENTRY_T	*nat_entry;
+					GRE_HASH_ENTRY_T	*gre_entry;
+					nat_entry = (NAT_HASH_ENTRY_T *)hash_get_entry(idx+j);
+					gre_entry = (GRE_HASH_ENTRY_T *)nat_entry;
+					if (nat_entry->key.ip_protocol == IPPROTO_GRE)
+					{
+						counter_p = (short *)&gre_entry->tmo.counter;
+						interval_p = (short *)&gre_entry->tmo.interval;
+					}
+					else
+					{
+						counter_p = (short *)&nat_entry->tmo.counter;
+						interval_p = (short *)&nat_entry->tmo.interval;
+					}
+					if (a_bits & 1)
+					{
+						*counter_p = *interval_p;
+					}
+					else
+					{
+						*counter_p -= HASH_TIMER_PERIOD;
+						if (*counter_p <= 0)
+						{
+							*valid_p &= ~(1 << j);		// invalidate it
+							*own_p &= ~(1 << j);		// release ownership for NAT
+							*counter_p = 0;
+							// hash_printf("%lu %s: Clear hash index: %d\n", jiffies/HZ, __func__, i*32+j);
+						}
+						else if (period > *counter_p)
+						{
+							period = *counter_p;
+						}
+					}
+				}
+				a_bits >>= 1;
+				own_bits >>=1;
+			}
+		}
+	}
+
+	hash_timer_obj.expires = jiffies + (period * HZ);
+	add_timer((struct timer_list *)data);
+}
+
+/*----------------------------------------------------------------------
+* dm_long
+*----------------------------------------------------------------------*/
+void dm_long(u32 location, int length)
+{
+	u32		*start_p, *curr_p, *end_p;
+	u32		*datap, data;
+	int		i;
+
+	//if (length > 1024)
+	//	length = 1024;
+
+	start_p = (u32 *)location;
+	end_p = (u32 *)location + length;
+	curr_p = (u32 *)((u32)location & 0xfffffff0);
+	datap = (u32 *)location;
+	while (curr_p < end_p)
+	{
+		hash_printf("0x%08x: ",(u32)curr_p & 0xfffffff0);
+		for (i=0; i<4; i++)
+		{
+			if (curr_p < start_p || curr_p >= end_p)
+               hash_printf("         ");
+			else
+			{
+				data = *datap;
+				hash_printf("%08X ", data);
+			}
+			if (i==1)
+              hash_printf("- ");
+
+			curr_p++;
+			datap++;
+		}
+        hash_printf("\n");
+	}
+}
+
+/*----------------------------------------------------------------------
+* hash_dump_entry
+*----------------------------------------------------------------------*/
+void hash_dump_entry(int index)
+{
+	hash_printf("Hash Index %d:\n", index);
+	dm_long((u32)&hash_tables[index][0], HASH_MAX_DWORDS);
+}
+
+
--- /dev/null
+++ b/drivers/net/sl351x_nat.c
@@ -0,0 +1,1736 @@
+/****************************************************************************
+* Copyright 2006 StorLink Semiconductors, Inc.  All rights reserved.
+*----------------------------------------------------------------------------
+* Name			: sl351x_nat.c
+* Description	:
+*		Handle Storlink SL351x NAT Functions
+*
+*
+* Packet Flow:
+*
+*            (xmit)+<--- SW NAT -->+(xmit)
+*                  |       ^^      |
+*                  |       ||      |
+*                  |       ||      |
+*   Client <---> GMAC-x  HW-NAT  GMAC-y  <---> Server
+*
+*
+* History
+*
+*	Date		Writer		Description
+*----------------------------------------------------------------------------
+*	03/13/2006	Gary Chen	Create and implement
+*
+*
+****************************************************************************/
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/compiler.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
+#include <linux/delay.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/completion.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/semaphore.h>
+#include <asm/arch/irqs.h>
+#include <asm/arch/it8712.h>
+#include <linux/mtd/kvctl.h>
+#include <linux/skbuff.h>
+#include <linux/if_ether.h>
+#include <linux/if_pppox.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
+#include <linux/ppp_defs.h>
+
+#define	 MIDWAY
+#define	 SL_LEPUS
+
+#include <asm/arch/sl2312.h>
+#include <asm/arch/sl351x_gmac.h>
+#include <asm/arch/sl351x_hash_cfg.h>
+#include <asm/arch/sl351x_nat_cfg.h>
+#ifdef CONFIG_NETFILTER
+// #include <linux/netfilter/nf_conntrack.h>
+#include <linux/netfilter/nf_conntrack_tcp.h>
+#endif
+
+//#define NAT_DEBUG_MSG		1
+#define _NOT_CHECK_SIP_DIP
+//#define	SL351x_NAT_TEST_BY_SMARTBITS		1	// Initialize 32 hash entries and test by SmartBITS
+#define VITESSE_G5SWITCH	1
+
+#ifdef CONFIG_SL351x_NAT
+
+/*----------------------------------------------------------------------
+* Definition
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL3516_ASIC
+#define CONFIG_SL351x_NAT_TCP_UDP
+#define CONFIG_SL351x_NAT_GRE
+#define CONFIG_SL351x_TCP_UDP_RULE_ID	0
+#define CONFIG_SL351x_GRE_RULE_ID		1
+#else
+#define CONFIG_SL351x_NAT_TCP_UDP
+//#define CONFIG_SL351x_NAT_GRE
+#define CONFIG_SL351x_TCP_UDP_RULE_ID	0
+#define CONFIG_SL351x_GRE_RULE_ID		0
+#endif
+
+#define	nat_printf					printk
+#define NAT_FTP_CTRL_PORT 			(21)	// TCP
+#define NAT_H323_PORT				(1720)	// TCP
+#define NAT_T120_PORT				(1503)	// TCP
+#define NAT_PPTP_PORT				(1723)	// TCP
+#define NAT_TFTP_PORT 				(69)	// UDP
+#define NAT_DNS_PORT 				(53)	// UDP
+#define NAT_NTP_PORT				(123)	// UDP
+#define NAT_RAS_PORT				(1719)	// UDP
+#define NAT_BOOTP67_PORT			(67)	// UDP
+#define NAT_BOOTP68_PORT			(68)	// UDP
+
+#define NAT_TCP_PORT_MAX			64
+#define NAT_UDP_PORT_MAX			64
+
+#define GRE_PROTOCOL				(0x880b)
+#define GRE_PROTOCOL_SWAP			__constant_htons(0x880b)
+
+#ifdef VITESSE_G5SWITCH
+extern int Giga_switch;
+#endif
+
+typedef struct
+{
+	u16		flags_ver;
+	u16		protocol;
+	u16		payload_length;
+	u16		call_id;
+	u32		seq;
+	u32		ack;
+} GRE_PKTHDR_T;
+
+/*----------------------------------------------------------------------
+* NAT Configuration
+*
+* Note: Any change for network setting, the NAT configuration should
+*       be changed also.
+*	cfg->lan_port	0 if GMAC-0, 1: if GMAC-1
+*	cfg->wan_port	0 if GMAC-0, 1: if GMAC-1
+*	cfg->lan_ipaddr, cfg->lan_gateway, cfg->lan_netmask
+*	cfg->wan_ipaddr, cfg->wan_gateway, cfg->wan_netmask
+*
+*----------------------------------------------------------------------*/
+NAT_CFG_T 		nat_cfg;
+static int		nat_initialized;
+u32 			nat_collision;
+
+#ifdef CONFIG_SL351x_NAT_TCP_UDP
+static u16		fixed_tcp_port_list[]={NAT_FTP_CTRL_PORT,
+							   			NAT_H323_PORT,
+							   			// NAT_T120_PORT,
+							   			NAT_PPTP_PORT,
+										0};
+static u16		fixed_udp_port_list[]={NAT_DNS_PORT,
+									  	NAT_NTP_PORT,
+									  	NAT_TFTP_PORT,
+										NAT_RAS_PORT,
+									  	NAT_BOOTP67_PORT,
+									  	NAT_BOOTP68_PORT,
+									   	0};
+#endif
+
+// #define _HAVE_DYNAMIC_PORT_LIST
+#ifdef _HAVE_DYNAMIC_PORT_LIST
+static u16		dynamic_tcp_port_list[NAT_TCP_PORT_MAX+1];
+static u16		dynamic_udp_port_list[NAT_UDP_PORT_MAX+1]};
+#endif
+
+/*----------------------------------------------------------------------
+* Functions
+*----------------------------------------------------------------------*/
+int sl351x_nat_tcp_udp_output(struct sk_buff *skb, int port);
+int sl351x_nat_udp_output(struct sk_buff *skb, int port);
+int sl351x_nat_gre_output(struct sk_buff *skb, int port);
+
+extern int mac_set_rule_reg(int mac, int rule, int enabled, u32 reg0, u32 reg1, u32 reg2);
+extern void hash_dump_entry(int index);
+extern void mac_get_hw_tx_weight(struct net_device *dev, char *weight);
+extern void mac_set_hw_tx_weight(struct net_device *dev, char *weight);
+
+#ifdef SL351x_NAT_TEST_BY_SMARTBITS
+static void nat_init_test_entry(void);
+#endif
+/*----------------------------------------------------------------------
+* sl351x_nat_init
+*	initialize a NAT matching rule
+*	Called by SL351x Driver
+*		key		: port, protocol, Sip, Dip, Sport, Dport
+*		Action	: Srce Q: HW Free Queue,
+*				  Dest Q: HW TxQ
+*				  Change DA
+*				  Change SA
+*                 Change Sip or Dip
+*    			  Change Sport or Dport
+*----------------------------------------------------------------------*/
+void sl351x_nat_init(void)
+{
+	int					rc;
+	GMAC_MRxCR0_T		mrxcr0;
+	GMAC_MRxCR1_T		mrxcr1;
+	GMAC_MRxCR2_T		mrxcr2;
+	NAT_CFG_T			*cfg;
+
+	if (nat_initialized)
+		return;
+
+	nat_initialized = 1;
+
+	if ((sizeof(NAT_HASH_ENTRY_T) > HASH_MAX_BYTES) ||
+		(sizeof(GRE_HASH_ENTRY_T) > HASH_MAX_BYTES))
+	{
+		nat_printf("NAT_HASH_ENTRY_T structure Size is too larger!\n");
+		while(1);
+	}
+
+	cfg = (NAT_CFG_T *)&nat_cfg;
+	memset((void *)cfg, 0, sizeof(NAT_CFG_T));
+#ifdef _HAVE_DYNAMIC_PORT_LIST
+	memset((void *)dynamic_tcp_port_list, 0, sizeof(dynamic_tcp_port_list));
+	memset((void *)dynamic_udp_port_list, 0, sizeof(dynamic_udp_port_list));
+#endif
+
+#ifdef VITESSE_G5SWITCH
+	if(Giga_switch)
+	{
+		cfg->enabled			= 1;
+		cfg->tcp_udp_rule_id 	= CONFIG_SL351x_TCP_UDP_RULE_ID;
+		cfg->gre_rule_id 		= CONFIG_SL351x_GRE_RULE_ID;
+		cfg->lan_port			= 1;
+		cfg->wan_port			= 0;
+		cfg->default_hw_txq 	= 3;
+		cfg->tcp_tmo_interval 	= 60;
+		cfg->udp_tmo_interval 	= 180;
+		cfg->gre_tmo_interval 	= 60;
+	}
+	else
+	{
+		cfg->enabled			= 1;
+		cfg->tcp_udp_rule_id 	= CONFIG_SL351x_TCP_UDP_RULE_ID;
+		cfg->gre_rule_id 		= CONFIG_SL351x_GRE_RULE_ID;
+		cfg->lan_port			= 0;
+		cfg->wan_port			= 1;
+		cfg->default_hw_txq 	= 3;
+		cfg->tcp_tmo_interval 	= 60;
+		cfg->udp_tmo_interval 	= 180;
+		cfg->gre_tmo_interval 	= 60;
+
+	}
+#endif
+
+#if 1	//	debug purpose
+	cfg->ipcfg[0].total				= 1;
+	cfg->ipcfg[0].entry[0].ipaddr	= IPIV(192,168,2,92);
+	cfg->ipcfg[0].entry[0].netmask	= IPIV(255,255,255,0);
+	cfg->ipcfg[1].total				= 1;
+	cfg->ipcfg[1].entry[0].ipaddr	= IPIV(192,168,1,200);
+	cfg->ipcfg[1].entry[0].netmask	= IPIV(255,255,255,0);
+#endif
+
+#if 1
+	cfg->xport.total = 0;
+#else
+	cfg->xport.total = 4;
+
+	// H.323/H.225 Call setup
+	cfg->xport.entry[0].protocol = IPPROTO_TCP;
+	cfg->xport.entry[0].sport_start = 0;
+	cfg->xport.entry[0].sport_end = 0;
+	cfg->xport.entry[0].dport_start = 1720;
+	cfg->xport.entry[0].dport_end = 1720;
+	cfg->xport.entry[1].protocol = IPPROTO_TCP;
+	cfg->xport.entry[1].sport_start = 1720;
+	cfg->xport.entry[1].sport_end = 1720;
+	cfg->xport.entry[1].dport_start = 0;
+	cfg->xport.entry[1].dport_end = 0;
+
+	// RAS Setup
+	cfg->xport.entry[2].protocol = IPPROTO_UDP;
+	cfg->xport.entry[2].sport_start = 0;
+	cfg->xport.entry[2].sport_end = 0;
+	cfg->xport.entry[2].dport_start = 1719;
+	cfg->xport.entry[2].dport_end = 1719;
+	cfg->xport.entry[3].protocol = IPPROTO_UDP;
+	cfg->xport.entry[3].sport_start = 1719;
+	cfg->xport.entry[3].sport_end = 1719;
+	cfg->xport.entry[3].dport_start = 0;
+	cfg->xport.entry[3].dport_end = 0;
+#endif
+
+#ifdef CONFIG_SL351x_NAT_TCP_UDP
+	mrxcr0.bits32 = 0;
+	mrxcr1.bits32 = 0;
+	mrxcr2.bits32 = 0;
+	mrxcr0.bits.port = 1;
+	mrxcr0.bits.l3 = 1;
+	mrxcr0.bits.l4 = 1;
+	mrxcr1.bits.sip = 1;
+	mrxcr1.bits.dip = 1;
+	mrxcr1.bits.l4_byte0_15 = 0x0f;	// Byte 0-3
+	mrxcr0.bits.sprx = 3;
+
+	rc = mac_set_rule_reg(cfg->lan_port, cfg->tcp_udp_rule_id, 1, mrxcr0.bits32, mrxcr1.bits32, mrxcr2.bits32);
+	if (rc < 0)
+	{
+		nat_printf("NAT Failed to set MAC-%d Rule %d!\n", cfg->lan_port, cfg->tcp_udp_rule_id);
+	}
+
+	if (cfg->lan_port != cfg->wan_port)
+	{
+		rc = mac_set_rule_reg(cfg->wan_port, cfg->tcp_udp_rule_id, 1, mrxcr0.bits32, mrxcr1.bits32, mrxcr2.bits32);
+		if (rc < 0)
+		{
+			nat_printf("NAT Failed to set MAC-%d Rule %d!\n", cfg->wan_port, cfg->tcp_udp_rule_id);
+		}
+	}
+#endif
+
+#ifdef CONFIG_SL351x_NAT_GRE
+	mrxcr0.bits32 = 0;
+	mrxcr1.bits32 = 0;
+	mrxcr2.bits32 = 0;
+	mrxcr0.bits.port = 1;
+	mrxcr0.bits.l3 = 1;
+	mrxcr0.bits.l4 = 1;
+	mrxcr1.bits.sip = 1;
+	mrxcr1.bits.dip = 1;
+	mrxcr1.bits.l4_byte0_15 = 0xcc;	// Byte 2, 3, 6, 7
+	mrxcr0.bits.sprx = 4;			// see GMAC driver about SPR
+
+	rc = mac_set_rule_reg(cfg->lan_port, cfg->gre_rule_id, 1, mrxcr0.bits32, mrxcr1.bits32, mrxcr2.bits32);
+	if (rc < 0)
+	{
+		nat_printf("NAT Failed to set MAC-%d Rule %d!\n", cfg->lan_port, cfg->gre_rule_id);
+	}
+
+	if (cfg->lan_port != cfg->wan_port)
+	{
+		rc = mac_set_rule_reg(cfg->wan_port, cfg->gre_rule_id, 1, mrxcr0.bits32, mrxcr1.bits32, mrxcr2.bits32);
+		if (rc < 0)
+		{
+			nat_printf("NAT Failed to set MAC-%d Rule %d!\n", cfg->wan_port, cfg->gre_rule_id);
+		}
+	}
+#endif
+
+#ifdef SL351x_NAT_TEST_BY_SMARTBITS
+	nat_init_test_entry();
+#endif
+}
+
+/*----------------------------------------------------------------------
+* nat_build_keys
+*	Note: To call this routine, the key->rule_id MUST be zero
+*----------------------------------------------------------------------*/
+static inline int nat_build_keys(NAT_KEY_T *key)
+{
+	return hash_gen_crc16((unsigned char *)key, NAT_KEY_SIZE) & HASH_BITS_MASK;
+}
+
+/*----------------------------------------------------------------------
+* gre_build_keys
+*	Note: To call this routine, the key->rule_id MUST be zero
+*----------------------------------------------------------------------*/
+static inline int gre_build_keys(GRE_KEY_T *key)
+{
+	return hash_gen_crc16((unsigned char *)key, GRE_KEY_SIZE) & HASH_BITS_MASK;
+}
+
+/*----------------------------------------------------------------------
+* nat_write_hash_entry
+*----------------------------------------------------------------------*/
+static inline int nat_write_hash_entry(int index, void *hash_entry)
+{
+	int		i;
+	u32		*srcep, *destp, *destp2;
+
+	srcep = (u32 *)hash_entry;
+	destp = destp2 = (u32 *)&hash_tables[index][0];
+
+	for (i=0; i<(NAT_HASH_ENTRY_SIZE/sizeof(u32)); i++)
+		*destp++ = *srcep++;
+
+	consistent_sync(destp2, NAT_HASH_ENTRY_SIZE, PCI_DMA_TODEVICE);
+	return 0;
+}
+
+/*----------------------------------------------------------------------
+* gre_write_hash_entry
+*----------------------------------------------------------------------*/
+static inline int gre_write_hash_entry(int index, void *hash_entry)
+{
+	int		i;
+	u32		*srcep, *destp, *destp2;
+
+	srcep = (u32 *)hash_entry;
+	destp = destp2 = (u32 *)&hash_tables[index][0];
+
+	for (i=0; i<(GRE_HASH_ENTRY_SIZE/sizeof(u32)); i++)
+		*destp++ = *srcep++;
+
+	consistent_sync(destp2, GRE_HASH_ENTRY_SIZE, PCI_DMA_TODEVICE);
+	return 0;
+}
+
+/*----------------------------------------------------------------------
+* sl351x_nat_find_ipcfg
+*	return NULL if not found
+*----------------------------------------------------------------------*/
+static NAT_IP_ENTRY_T *sl351x_nat_find_ipcfg(u32 ipaddr, int port)
+{
+	int				i;
+	NAT_IP_ENTRY_T	*ipcfg;
+
+	ipcfg = (NAT_IP_ENTRY_T *)&nat_cfg.ipcfg[port].entry[0];
+	for (i=0; i<nat_cfg.ipcfg[port].total; i++, ipcfg++)
+	{
+		if (ipaddr == ipcfg->ipaddr)
+		{
+			return ipcfg;
+		}
+	}
+	return NULL;
+}
+
+/*----------------------------------------------------------------------
+* sl351x_nat_assign_qid
+*----------------------------------------------------------------------*/
+static int sl351x_nat_assign_qid(u8 proto, u32 sip, u32 dip, u16 sport, u16 dport)
+{
+	int 				i, total, qid;
+	NAT_WRULE_ENTRY_T	*entry;
+
+	for (qid = 0; qid<CONFIG_NAT_TXQ_NUM; qid++)
+	{
+		if (qid == nat_cfg.default_hw_txq)
+			continue;
+
+		entry = (NAT_WRULE_ENTRY_T *)&nat_cfg.wrule[qid].entry[0];
+		total = nat_cfg.wrule[qid].total;
+		for (i=0; i<total; i++, entry++)
+		{
+			if (!entry->protocol || entry->protocol==proto)
+			{
+				//if (!entry->sip_start && !entry->dip_start && !entry->sport_start && !entry->dport_start)
+				//	continue; // UI take care
+				if (entry->sip_start && !((sip >= entry->sip_start) &&
+									   (sip <= entry->sip_end)))
+					continue;
+				if (entry->dip_start && !((dip >= entry->dip_start) &&
+									   (dip <= entry->dip_end)))
+					continue;
+				if (entry->sport_start && !((sport >= entry->sport_start) &&
+									   (sport <= entry->sport_end)))
+					continue;
+				if (entry->dport_start && !((dport >= entry->dport_start)
+					 			       && (dport <= entry->dport_end)))
+					continue;
+				return qid;
+			}
+		}
+	}
+	return nat_cfg.default_hw_txq;
+}
+
+/*----------------------------------------------------------------------
+* sl351x_nat_input
+*	Handle NAT input frames
+*	Called by SL351x Driver - Handle Default Rx Queue
+*	Notes: The caller must make sure that the l3off & l4offset should not be zero.
+*	SL351x NAT Frames should meet the following conditions:
+*	1. TCP or UDP frame
+*	2. Cannot be special ALGs ports which TCP/UDP data is updated
+*	3. LAN-IN Frames:
+*		Source IP is in the LAN subnet and Destination is not in the LAN subnet
+*	4. WAN-IN Frames
+*		Destination IP is in the WAN port IP
+*
+*	Example Ports
+*	1. TCP/UDP data is updated
+*		(a) FTP Control Packet
+*		(b) VoIP Packets
+*		(c) etc. (add in future)
+*	2. UDP Low packet rate, not worth
+*		(b) TFTP Destination Port is 69
+*		(b) DNS  53
+*		(c) NTP  123
+*		(d) etc. (add in future)
+*----------------------------------------------------------------------*/
+void sl351x_nat_input(struct sk_buff *skb, int port, void *l3off, void *l4off)
+{
+	int 				i, found;
+	u32					sip, dip;
+	u16					sport, dport;
+	struct ethhdr		*ether_hdr;
+	struct iphdr		*ip_hdr;
+	struct tcphdr		*tcp_hdr;
+	struct pppoe_hdr	*pppoe_hdr;
+	NAT_CB_T			*nat_cb;
+	u8					proto, pppoe_frame=0;
+	NAT_CFG_T			*cfg;
+	u16					ppp_proto;
+	NAT_IP_ENTRY_T		*ipcfg;
+	NAT_XPORT_ENTRY_T	*xentry;
+	GRE_PKTHDR_T		*gre_hdr;
+#ifdef CONFIG_SL351x_NAT_TCP_UDP
+	u16 				*port_ptr;
+#endif
+
+	cfg = (NAT_CFG_T *)&nat_cfg;
+	if (!cfg->enabled || !cfg->ipcfg[port].total)
+		return;
+
+	ip_hdr = (struct iphdr *)&(skb->data[(u32)l3off]);
+	proto = ip_hdr->protocol;
+
+	tcp_hdr = (struct tcphdr *)&(skb->data[(u32)l4off]);
+	gre_hdr = (GRE_PKTHDR_T *)tcp_hdr;
+	sport = ntohs(tcp_hdr->source);
+	dport = ntohs(tcp_hdr->dest);
+
+	sip = ntohl(ip_hdr->saddr);
+	dip = ntohl(ip_hdr->daddr);
+
+	if (dip == IPIV(255,255,255,255))
+		return;
+
+	if (port == cfg->lan_port)
+	{
+		ipcfg = (NAT_IP_ENTRY_T *)&cfg->ipcfg[port].entry[0];
+		for (i=0, found=0; i<cfg->ipcfg[port].total; i++, ipcfg++)
+		{
+			u32 subnet = ipcfg->ipaddr & ipcfg->netmask;
+			if (((sip & ipcfg->netmask) == subnet) &&
+				((dip & ipcfg->netmask) != subnet))
+			{
+				found = 1;
+				break;
+			}
+		}
+		if (!found)
+			return;
+	}
+	else
+	{
+#ifndef _NOT_CHECK_SIP_DIP	// enable it if know and get the wan ip address
+		if (!sl351x_nat_find_ipcfg(dip, port))
+		{
+			printk("WAN->LAN Incorrect Dip %d.%d.%d.%d\n", HIPQUAD(dip));
+			return;
+		}
+#endif
+		ether_hdr = (struct ethhdr *)skb->data;
+		pppoe_hdr = (struct pppoe_hdr *)(ether_hdr + 1);
+		ppp_proto = *(u16 *)&pppoe_hdr->tag[0];
+		if (ether_hdr->h_proto == __constant_htons(ETH_P_PPP_SES)	// 0x8864
+			&& ppp_proto == __constant_htons(PPP_IP) )				// 0x21
+		{
+			pppoe_frame = 1;
+		}
+	}
+
+#ifdef CONFIG_SL351x_NAT_TCP_UDP
+	if (proto == IPPROTO_TCP)
+	{
+#ifdef	NAT_DEBUG_MSG
+		nat_printf("From   GMAC-%d: 0x%-4X TCP %d.%d.%d.%d [%d] --> %d.%d.%d.%d [%d]",
+				port, ntohs(ip_hdr->id),
+				NIPQUAD(ip_hdr->saddr), sport,
+				NIPQUAD(ip_hdr->daddr), dport);
+		if (tcp_flag_word(tcp_hdr) & TCP_FLAG_SYN) nat_printf(" SYN");
+		if (tcp_flag_word(tcp_hdr) & TCP_FLAG_FIN) nat_printf(" FIN");
+		if (tcp_flag_word(tcp_hdr) & TCP_FLAG_RST) nat_printf(" RST");
+		if (tcp_flag_word(tcp_hdr) & TCP_FLAG_ACK) nat_printf(" ACK");
+		nat_printf("\n");
+#endif
+		// if (tcp_flag_word(tcp_hdr) & (TCP_FLAG_SYN | TCP_FLAG_FIN | TCP_FLAG_RST))
+		if (tcp_flag_word(tcp_hdr) & (TCP_FLAG_SYN))
+		{
+			return;
+		}
+		port_ptr = fixed_tcp_port_list;
+		for (i=0; *port_ptr; i++, port_ptr++)
+		{
+			if (sport == *port_ptr || dport == *port_ptr)
+				return;
+		}
+#ifdef _HAVE_DYNAMIC_PORT_LIST
+		port_ptr = dynamic_tcp_port_list;
+		for (i=0; *port_ptr; i++, port_ptr++)
+		{
+			if (sport == *port_ptr || dport == *port_ptr)
+				return;
+		}
+#endif
+	}
+	else if (proto == IPPROTO_UDP)
+	{
+#ifdef	NAT_DEBUG_MSG
+		nat_printf("From   GMAC-%d: 0x%-4X UDP %d.%d.%d.%d [%d] --> %d.%d.%d.%d [%d]",
+				port, ntohs(ip_hdr->id),
+				NIPQUAD(ip_hdr->saddr), sport,
+				NIPQUAD(ip_hdr->daddr), dport);
+		nat_printf("\n");
+#endif
+		port_ptr = fixed_udp_port_list;
+		for (i=0; *port_ptr; i++, port_ptr++)
+		{
+			if (sport == *port_ptr || dport == *port_ptr)
+				return;
+		}
+#ifdef _HAVE_DYNAMIC_PORT_LIST
+		port_ptr = dynamic_udp_port_list;
+		for (i=0; *port_ptr; i++, port_ptr++)
+		{
+			if (sport == *port_ptr || dport == *port_ptr)
+				return;
+		}
+#endif
+	}
+	else
+#endif	// CONFIG_SL351x_NAT_TCP_UDP
+#ifdef CONFIG_SL351x_NAT_GRE
+	if (proto == IPPROTO_GRE)
+	{
+		if (gre_hdr->protocol != GRE_PROTOCOL_SWAP)
+			return;
+#ifdef	NAT_DEBUG_MSG
+		nat_printf("From   GMAC-%d: 0x%-4X GRE %d.%d.%d.%d [%d] --> %d.%d.%d.%d",
+				port, ntohs(ip_hdr->id),
+				NIPQUAD(ip_hdr->saddr), ntohs(gre_hdr->call_id),
+				NIPQUAD(ip_hdr->daddr));
+		nat_printf("\n");
+#endif
+	}
+	else
+#endif
+		return;
+
+
+	// check xport list
+	xentry = (NAT_XPORT_ENTRY_T *)&cfg->xport.entry[0];
+	for (i=0; i<cfg->xport.total; i++, xentry++)
+	{
+		if (!xentry->protocol || xentry->protocol == proto)
+		{
+			//if (!xentry->sport_start && !xentry->dport_start) // UI take care
+			//	continue;
+			if (xentry->sport_start && !((sport >= xentry->sport_start) &&
+									   (sport <= xentry->sport_end)))
+				continue;
+			if (xentry->dport_start && !((dport >= xentry->dport_start)
+					 			       && (dport <= xentry->dport_end)))
+				continue;
+			return;
+		}
+	}
+
+	nat_cb = NAT_SKB_CB(skb);
+	if (((u32)nat_cb & 3))
+	{
+		nat_printf("%s ERROR! nat_cb is not alignment!!!!!!\n", __func__);
+		return;
+	}
+	nat_cb->tag = NAT_CB_TAG;
+	memcpy(nat_cb->sa, skb->data+6, 6);
+	nat_cb->sip = ip_hdr->saddr;
+	nat_cb->dip = ip_hdr->daddr;
+	if (proto == IPPROTO_GRE)
+	{
+		nat_cb->sport = gre_hdr->protocol;
+		nat_cb->dport = gre_hdr->call_id;
+	}
+	else
+	{
+		nat_cb->sport = tcp_hdr->source;
+		nat_cb->dport = tcp_hdr->dest;
+	}
+	nat_cb->pppoe_frame = pppoe_frame;
+}
+
+/*----------------------------------------------------------------------
+* sl351x_nat_output
+*	Handle NAT output frames
+*	Called by SL351x Driver - Transmit
+*
+*	1. If not SL351x NAT frames, return FALSE
+*	2. LAN-to-WAN frames
+*		(1) Sip must be WAN IP
+*	3. If TCP SY/RST/FIN frame, return
+*	4. Build the hash key and get the hash index
+*	5. If V-Bit is ON, return.
+*	6. Write hash entry and validate it
+*
+*----------------------------------------------------------------------*/
+int sl351x_nat_output(struct sk_buff *skb, int port)
+{
+	struct iphdr		*ip_hdr;
+	u8					proto;
+	NAT_CB_T			*nat_cb;
+
+	nat_cb = NAT_SKB_CB(skb);
+	if (nat_cb->tag != NAT_CB_TAG)
+		return 0;
+
+	if (((u32)nat_cb & 3))
+	{
+		nat_printf("%s ERROR! nat_cb is not alignment!!!!!!\n", __func__);
+		return 0;
+	}
+	ip_hdr = (struct iphdr *)skb->h.ipiph;
+	proto = ip_hdr->protocol;
+
+	switch (proto)
+	{
+		case IPPROTO_TCP:
+		case IPPROTO_UDP:
+			return sl351x_nat_tcp_udp_output(skb, port);
+		case IPPROTO_GRE:
+			return sl351x_nat_gre_output(skb, port);
+	}
+	return 0;
+}
+
+/*----------------------------------------------------------------------
+* sl351x_nat_tcp_udp_output
+*	Handle NAT TCP/UDP output frames
+*----------------------------------------------------------------------*/
+int sl351x_nat_tcp_udp_output(struct sk_buff *skb, int port)
+{
+	u32					sip, dip;
+	struct ethhdr		*ether_hdr;
+	struct iphdr		*ip_hdr;
+	struct tcphdr		*tcp_hdr;
+	struct pppoe_hdr	*pppoe_hdr;
+	NAT_CB_T			*nat_cb;
+	NAT_CFG_T			*cfg;
+	u8					proto;
+	u16					sport, dport, ppp_proto;
+	u32					hash_data[HASH_MAX_DWORDS];
+	NAT_HASH_ENTRY_T	*hash_entry;
+	int					hash_index;
+	struct ip_conntrack *nat_ip_conntrack;
+	enum ip_conntrack_info ctinfo;
+
+	nat_cb = NAT_SKB_CB(skb);
+	cfg = (NAT_CFG_T *)&nat_cfg;
+
+	ether_hdr = (struct ethhdr *)skb->data;
+	ip_hdr = (struct iphdr *)skb->h.ipiph;
+	tcp_hdr = (struct tcphdr *)((u32)ip_hdr + (ip_hdr->ihl<<2));
+	sip = ntohl(ip_hdr->saddr);
+	dip = ntohl(ip_hdr->daddr);
+	proto = ip_hdr->protocol;
+	sport = ntohs(tcp_hdr->source);
+	dport = ntohs(tcp_hdr->dest);
+
+#ifdef	NAT_DEBUG_MSG
+	{
+		nat_printf("To   GMAC-%d: 0x%-4X [%d] %d.%d.%d.%d [%d] --> %d.%d.%d.%d [%d]",
+				port, ntohs(ip_hdr->id), proto,
+				NIPQUAD(ip_hdr->saddr), sport,
+				NIPQUAD(ip_hdr->daddr), dport);
+		if (proto == IPPROTO_TCP)
+		{
+			if (tcp_flag_word(tcp_hdr) & TCP_FLAG_SYN) nat_printf(" SYN");
+			if (tcp_flag_word(tcp_hdr) & TCP_FLAG_FIN) nat_printf(" FIN");
+			if (tcp_flag_word(tcp_hdr) & TCP_FLAG_RST) nat_printf(" RST");
+			if (tcp_flag_word(tcp_hdr) & TCP_FLAG_ACK) nat_printf(" ACK");
+		}
+		nat_printf("\n");
+	}
+#endif
+	nat_ip_conntrack = ip_conntrack_get(skb, &ctinfo);
+	if (!nat_ip_conntrack)
+	{
+		nat_printf("IP conntrack info is not found!\n");
+		return 0;
+	}
+	// nat_printf("nat_ip_conntrack = 0x%x, status=0x%lx, ctinfo=%d\n", (u32)nat_ip_conntrack, nat_ip_conntrack->status, ctinfo);
+	// if (nat_ip_conntrack->master || nat_ip_conntrack->helper)
+	if (nat_ip_conntrack->helper)
+	{
+		nat_printf("Sport=%d Dport=%d master=0x%x, helper=0x%x\n", sport, dport, (u32)nat_ip_conntrack->master, (u32)nat_ip_conntrack->helper);
+		return 0;
+	}
+
+	//if (proto == IPPROTO_TCP && !(nat_ip_conntrack->status & IPS_ASSURED))
+	//	return 0;
+
+#ifdef	NAT_DEBUG_MSG
+	nat_printf("nat_ip_conntrack=0x%x, nat_cb->state=%d\n", (u32)nat_ip_conntrack, nat_cb->state);
+	nat_printf("lan2wan_hash_index=%d,  wan2lan_hash_index=%d\n", nat_ip_conntrack->lan2wan_hash_index, nat_ip_conntrack->wan2lan_hash_index);
+	nat_printf("lan2wan_collision=%d, wan2lan_collision=%d\n", nat_ip_conntrack->lan2wan_collision, nat_ip_conntrack->wan2lan_collision);
+#endif
+	if (proto == IPPROTO_TCP)
+	{
+		if (nat_cb->state >= TCP_CONNTRACK_FIN_WAIT && nat_cb->state <= TCP_CONNTRACK_CLOSE)
+		{
+			if 	(nat_ip_conntrack->lan2wan_hash_index)
+			{
+#ifdef	NAT_DEBUG_MSG
+				nat_printf("Invalidate LAN->WAN hash entry %d\n", nat_ip_conntrack->lan2wan_hash_index - 1);
+#endif
+				hash_nat_disable_owner(nat_ip_conntrack->lan2wan_hash_index - 1);
+				hash_invalidate_entry(nat_ip_conntrack->lan2wan_hash_index - 1);
+				nat_ip_conntrack->lan2wan_hash_index = 0;
+			}
+			if 	(nat_ip_conntrack->wan2lan_hash_index)
+			{
+#ifdef	NAT_DEBUG_MSG
+				nat_printf("Invalidate WAN->LAN hash entry %d\n", nat_ip_conntrack->wan2lan_hash_index - 1);
+#endif
+				hash_nat_disable_owner(nat_ip_conntrack->wan2lan_hash_index - 1);
+				hash_invalidate_entry(nat_ip_conntrack->wan2lan_hash_index - 1);
+				nat_ip_conntrack->wan2lan_hash_index = 0;
+			}
+			return 0;
+
+		}
+		else if (nat_cb->state != TCP_CONNTRACK_ESTABLISHED)
+		{
+			return 0;
+		}
+	}
+	if (proto == IPPROTO_TCP && (tcp_flag_word(tcp_hdr) & (TCP_FLAG_SYN | TCP_FLAG_FIN | TCP_FLAG_RST)))
+	// if (proto == IPPROTO_TCP &&  (tcp_flag_word(tcp_hdr) & (TCP_FLAG_SYN)))
+		return 0;
+
+	hash_entry = (NAT_HASH_ENTRY_T *)&hash_data;
+	if (port == cfg->wan_port)	// LAN-to-WAN
+	{
+		if (nat_ip_conntrack->lan2wan_hash_index || nat_ip_conntrack->lan2wan_collision)
+			return 0;
+#ifndef _NOT_CHECK_SIP_DIP	// enable it if know and get the wan ip address
+		if (!sl351x_nat_find_ipcfg(sip, port))
+		{
+			printk("LAN->WAN Incorrect Sip %d.%d.%d.%d\n", HIPQUAD(sip));
+			return 0;
+		}
+#endif
+		// Note: unused fields (including rule_id) MUST be zero
+		hash_entry->key.Ethertype 	= 0;
+		hash_entry->key.port_id 	= cfg->lan_port;
+		hash_entry->key.rule_id 	= 0;
+		hash_entry->key.ip_protocol = proto;
+		hash_entry->key.reserved1 	= 0;
+		hash_entry->key.reserved2 	= 0;
+		hash_entry->key.sip 		= ntohl(nat_cb->sip);
+		hash_entry->key.dip 		= ntohl(nat_cb->dip);
+		hash_entry->key.sport 		= nat_cb->sport;
+		hash_entry->key.dport 		= nat_cb->dport;
+
+		hash_index = nat_build_keys(&hash_entry->key);
+
+#ifdef NAT_DEBUG_LAN_HASH_TIMEOUT
+		if (hash_get_nat_owner_flag(hash_index))
+			return 0;
+#endif
+		if (hash_get_valid_flag(hash_index))
+		{
+			nat_ip_conntrack->lan2wan_collision = 1;
+			nat_collision++;
+#if 0
+			if (proto == IPPROTO_TCP && (tcp_flag_word(tcp_hdr) & (TCP_FLAG_FIN | TCP_FLAG_RST)))
+			{
+				if (memcmp((void *)&hash_entry->key, hash_get_entry(hash_index), sizeof(NAT_KEY_T)) == 0)
+				{
+   					hash_nat_disable_owner(hash_index);
+ 					hash_invalidate_entry(hash_index); // Must last one, else HW Tx fast SW
+ 					// nat_printf("Invalidate nat hash entry %d\n", hash_index);
+ 				}
+			}
+#endif
+			return 0;
+		}
+
+		// write hash entry
+		hash_entry->key.rule_id = cfg->tcp_udp_rule_id;
+		memcpy(hash_entry->param.da, skb->data, 6);
+		memcpy(hash_entry->param.sa, skb->data+6, 6);
+		hash_entry->param.Sip = sip;
+		hash_entry->param.Dip = dip;
+		hash_entry->param.Sport = sport;
+		hash_entry->param.Dport = dport;
+		hash_entry->param.vlan = 0;
+		hash_entry->param.sw_id = 0;
+		hash_entry->param.mtu = 0;
+		// check PPPoE
+		pppoe_hdr = (struct pppoe_hdr *)(ether_hdr + 1);
+		ppp_proto = *(u16 *)&pppoe_hdr->tag[0];
+		if (ether_hdr->h_proto == __constant_htons(ETH_P_PPP_SES)	// 0x8864
+			&& ppp_proto == __constant_htons(PPP_IP) )				// 0x21
+		{
+			hash_entry->action.dword = NAT_PPPOE_LAN2WAN_ACTIONS;
+			hash_entry->param.pppoe = htons(pppoe_hdr->sid);
+		}
+		else
+		{
+			hash_entry->action.dword = NAT_LAN2WAN_ACTIONS;
+			hash_entry->param.pppoe = 0;
+		}
+		hash_entry->action.bits.dest_qid = sl351x_nat_assign_qid(proto, sip, dip, sport, dport);
+		hash_entry->action.bits.dest_qid +=	(cfg->wan_port==0) ? TOE_GMAC0_HW_TXQ0_QID : TOE_GMAC1_HW_TXQ0_QID;
+		hash_entry->tmo.counter = hash_entry->tmo.interval =
+						(proto == IPPROTO_TCP) ? cfg->tcp_tmo_interval : cfg->udp_tmo_interval;
+		nat_write_hash_entry(hash_index, hash_entry);
+		// nat_printf("%lu Validate a LAN hash entry %d\n", jiffies/HZ, hash_index);
+		// hash_dump_entry(hash_index);
+		hash_nat_enable_owner(hash_index);
+		hash_validate_entry(hash_index); // Must last one, else HW Tx fast than SW
+ 		nat_ip_conntrack->lan2wan_hash_index = hash_index + 1;
+ 		nat_ip_conntrack->hw_nat |= 1;
+		return 0;
+	}
+	else // WAN-to-LAN
+	{
+		if (nat_ip_conntrack->wan2lan_hash_index || nat_ip_conntrack->wan2lan_collision)
+			return 0;
+
+		// Note: unused fields (including rule_id) MUST be zero
+		hash_entry->key.Ethertype 	= 0;
+		hash_entry->key.port_id 	= cfg->wan_port;
+		hash_entry->key.rule_id 	= 0;
+		hash_entry->key.ip_protocol = proto;
+		hash_entry->key.reserved1 	= 0;
+		hash_entry->key.reserved2 	= 0;
+		hash_entry->key.sip 		= ntohl(nat_cb->sip);
+		hash_entry->key.dip 		= ntohl(nat_cb->dip);
+		hash_entry->key.sport 		= nat_cb->sport;
+		hash_entry->key.dport 		= nat_cb->dport;
+
+		hash_index = nat_build_keys(&hash_entry->key);
+
+#ifdef NAT_DEBUG_WAN_HASH_TIMEOUT
+		if (hash_get_nat_owner_flag(hash_index))
+			return 0;
+#endif
+		if (hash_get_valid_flag(hash_index))
+		{
+			nat_ip_conntrack->wan2lan_collision = 1;
+			nat_collision++;
+#if 0
+			if (proto == IPPROTO_TCP && (tcp_flag_word(tcp_hdr) & (TCP_FLAG_FIN | TCP_FLAG_RST)))
+			{
+				if (memcmp((void *)&hash_entry->key, hash_get_entry(hash_index), sizeof(NAT_KEY_T)) == 0)
+				{
+   					hash_nat_disable_owner(hash_index);
+ 					hash_invalidate_entry(hash_index); // Must last one, else HW Tx fast SW
+  					// nat_printf("Invalidate nat hash entry %d\n", hash_index);
+				}
+			}
+#endif
+			return 0;
+		}
+
+		// write hash entry
+		hash_entry->key.rule_id = cfg->tcp_udp_rule_id;
+		memcpy(hash_entry->param.da, skb->data, 6);
+		memcpy(hash_entry->param.sa, skb->data+6, 6);
+		hash_entry->param.Sip = sip;
+		hash_entry->param.Dip = dip;
+		hash_entry->param.Sport = sport;
+		hash_entry->param.Dport = dport;
+		hash_entry->param.vlan = 0;
+		hash_entry->param.pppoe = 0;
+		hash_entry->param.sw_id = 0;
+		hash_entry->param.mtu = 0;
+		hash_entry->action.dword = (nat_cb->pppoe_frame) ? NAT_PPPOE_WAN2LAN_ACTIONS : NAT_WAN2LAN_ACTIONS;
+		hash_entry->action.bits.dest_qid = sl351x_nat_assign_qid(proto, sip, dip, sport, dport);
+		hash_entry->action.bits.dest_qid += (cfg->lan_port==0) ? TOE_GMAC0_HW_TXQ0_QID : TOE_GMAC1_HW_TXQ0_QID;;
+		hash_entry->tmo.counter = hash_entry->tmo.interval =
+						(proto == IPPROTO_TCP) ? cfg->tcp_tmo_interval : cfg->udp_tmo_interval;
+		nat_write_hash_entry(hash_index, hash_entry);
+
+		// nat_printf("%lu Validate a WAN hash entry %d\n", jiffies/HZ, hash_index);
+		// hash_dump_entry(hash_index);
+   		hash_nat_enable_owner(hash_index);
+ 		hash_validate_entry(hash_index); // Must last one, else HW Tx fast SW
+ 		nat_ip_conntrack->wan2lan_hash_index = hash_index + 1;
+ 		nat_ip_conntrack->hw_nat |= 2;
+		return 0;
+	}
+	return 0;
+}
+
+/*----------------------------------------------------------------------
+* sl351x_nat_gre_output
+*	Handle NAT GRE output frames
+*----------------------------------------------------------------------*/
+int sl351x_nat_gre_output(struct sk_buff *skb, int port)
+{
+	u32					sip, dip;
+	struct ethhdr		*ether_hdr;
+	struct iphdr		*ip_hdr;
+	struct pppoe_hdr	*pppoe_hdr;
+	GRE_PKTHDR_T		*gre_hdr;
+	NAT_CB_T			*nat_cb;
+	NAT_CFG_T			*cfg;
+	u16					ppp_proto;
+	u32					hash_data[HASH_MAX_DWORDS];
+	GRE_HASH_ENTRY_T	*hash_entry;
+	int					hash_index;
+	struct ip_conntrack *nat_ip_conntrack;
+	enum ip_conntrack_info ctinfo;
+
+	nat_cb = NAT_SKB_CB(skb);
+	cfg = (NAT_CFG_T *)&nat_cfg;
+
+	ether_hdr = (struct ethhdr *)skb->data;
+	ip_hdr = (struct iphdr *)skb->h.ipiph;
+	gre_hdr = (GRE_PKTHDR_T *)((u32)ip_hdr + (ip_hdr->ihl<<2));
+	sip = ntohl(ip_hdr->saddr);
+	dip = ntohl(ip_hdr->daddr);
+
+#ifdef	NAT_DEBUG_MSG
+	{
+		nat_printf("To   GMAC-%d: 0x%-4X GRE %d.%d.%d.%d [%d] --> %d.%d.%d.%d",
+				port, ntohs(ip_hdr->id),
+				NIPQUAD(ip_hdr->saddr), ntohs(gre_hdr->call_id),
+				NIPQUAD(ip_hdr->daddr));
+		nat_printf("\n");
+	}
+#endif
+	nat_ip_conntrack = ip_conntrack_get(skb, &ctinfo);
+	if (nat_ip_conntrack)
+	{
+		// if (nat_ip_conntrack->master || nat_ip_conntrack->helper)
+		if (nat_ip_conntrack->helper)
+		{
+			nat_printf("GRE Call-ID=%d, master=0x%x, helper=0x%x\n", ntohs(gre_hdr->call_id), (u32)nat_ip_conntrack->master, (u32)nat_ip_conntrack->helper);
+			return 0;
+		}
+		if (!(nat_ip_conntrack->status & IPS_ASSURED))
+			return 0;
+	}
+
+	hash_entry = (GRE_HASH_ENTRY_T *)&hash_data;
+	if (port == cfg->wan_port)	// LAN-to-WAN
+	{
+#ifdef _NOT_CHECK_SIP_DIP	// enable it if know and get the wan ip address
+		if (!sl351x_nat_find_ipcfg(sip, port))
+		{
+			printk("LAN->WAN Incorrect Sip %d.%d.%d.%d\n", HIPQUAD(sip));
+			return 0;
+		}
+#endif
+		// Note: unused fields (including rule_id) MUST be zero
+		hash_entry->key.Ethertype 	= 0;
+		hash_entry->key.port_id 	= cfg->lan_port;
+		hash_entry->key.rule_id 	= 0;
+		hash_entry->key.ip_protocol = IPPROTO_GRE;
+		hash_entry->key.reserved1 	= 0;
+		hash_entry->key.reserved2 	= 0;
+		hash_entry->key.reserved3 	= 0;
+		hash_entry->key.reserved4 	= 0;
+		hash_entry->key.sip 		= ntohl(nat_cb->sip);
+		hash_entry->key.dip 		= ntohl(nat_cb->dip);
+		hash_entry->key.protocol	= nat_cb->sport;
+		hash_entry->key.call_id 	= nat_cb->dport;
+
+		hash_index = gre_build_keys(&hash_entry->key);
+
+#ifdef NAT_DEBUG_LAN_HASH_TIMEOUT
+		if (hash_get_nat_owner_flag(hash_index))
+			return 0;
+#endif
+		if (hash_get_valid_flag(hash_index))
+		{
+			return 0;
+		}
+
+		// write hash entry
+		hash_entry->key.rule_id = cfg->gre_rule_id;
+		memcpy(hash_entry->param.da, skb->data, 6);
+		memcpy(hash_entry->param.sa, skb->data+6, 6);
+		hash_entry->param.Sip = sip;
+		hash_entry->param.Dip = dip;
+		hash_entry->param.Sport = 0;
+		hash_entry->param.Dport = ntohs(gre_hdr->call_id);
+		hash_entry->param.vlan = 0;
+		hash_entry->param.sw_id = 0;
+		hash_entry->param.mtu = 0;
+		// check PPPoE
+		pppoe_hdr = (struct pppoe_hdr *)(ether_hdr + 1);
+		ppp_proto = *(u16 *)&pppoe_hdr->tag[0];
+		if (ether_hdr->h_proto == __constant_htons(ETH_P_PPP_SES)	// 0x8864
+			&& ppp_proto == __constant_htons(PPP_IP) )				// 0x21
+		{
+			hash_entry->action.dword = NAT_PPPOE_PPTP_LAN2WAN_ACTIONS;
+			hash_entry->param.pppoe = htons(pppoe_hdr->sid);
+		}
+		else
+		{
+			hash_entry->action.dword = NAT_PPTP_LAN2WAN_ACTIONS;
+			hash_entry->param.pppoe = 0;
+		}
+		hash_entry->action.bits.dest_qid = sl351x_nat_assign_qid(IPPROTO_GRE, sip, dip, 0, ntohs(gre_hdr->call_id));
+		hash_entry->action.bits.dest_qid +=	(cfg->wan_port==0) ? TOE_GMAC0_HW_TXQ0_QID : TOE_GMAC1_HW_TXQ0_QID;
+		hash_entry->tmo.counter = hash_entry->tmo.interval = cfg->gre_tmo_interval;
+		gre_write_hash_entry(hash_index, hash_entry);
+		// nat_printf("%lu Validate a LAN hash entry %d\n", jiffies/HZ, hash_index);
+		// hash_dump_entry(hash_index);
+		hash_nat_enable_owner(hash_index);
+		hash_validate_entry(hash_index); // Must last one, else HW Tx fast than SW
+		return 0;
+	}
+	else // WAN-to-LAN
+	{
+		// Note: unused fields (including rule_id) MUST be zero
+		hash_entry->key.Ethertype 	= 0;
+		hash_entry->key.port_id 	= cfg->wan_port;
+		hash_entry->key.rule_id 	= 0;
+		hash_entry->key.ip_protocol = IPPROTO_GRE;
+		hash_entry->key.reserved1 	= 0;
+		hash_entry->key.reserved2 	= 0;
+		hash_entry->key.reserved3 	= 0;
+		hash_entry->key.reserved4 	= 0;
+		hash_entry->key.sip 		= ntohl(nat_cb->sip);
+		hash_entry->key.dip 		= ntohl(nat_cb->dip);
+		hash_entry->key.protocol	= nat_cb->sport;
+		hash_entry->key.call_id		= nat_cb->dport;
+
+		hash_index = gre_build_keys(&hash_entry->key);
+
+#ifdef NAT_DEBUG_WAN_HASH_TIMEOUT
+		if (hash_get_nat_owner_flag(hash_index))
+			return 0;
+#endif
+		if (hash_get_valid_flag(hash_index))
+		{
+			return 0;
+		}
+
+		// write hash entry
+		hash_entry->key.rule_id = cfg->gre_rule_id;
+		memcpy(hash_entry->param.da, skb->data, 6);
+		memcpy(hash_entry->param.sa, skb->data+6, 6);
+		hash_entry->param.Sip = sip;
+		hash_entry->param.Dip = dip;
+		hash_entry->param.Sport = 0;
+		hash_entry->param.Dport = ntohs(gre_hdr->call_id);
+		hash_entry->param.vlan = 0;
+		hash_entry->param.pppoe = 0;
+		hash_entry->param.sw_id = 0;
+		hash_entry->param.mtu = 0;
+		hash_entry->action.dword = (nat_cb->pppoe_frame) ? NAT_PPPOE_PPTP_WAN2LAN_ACTIONS : NAT_PPTP_WAN2LAN_ACTIONS;
+		hash_entry->action.bits.dest_qid = sl351x_nat_assign_qid(IPPROTO_GRE, sip, dip, 0, ntohs(gre_hdr->call_id));
+		hash_entry->action.bits.dest_qid += (cfg->lan_port==0) ? TOE_GMAC0_HW_TXQ0_QID : TOE_GMAC1_HW_TXQ0_QID;;
+		hash_entry->tmo.counter = hash_entry->tmo.interval = cfg->gre_tmo_interval;
+		gre_write_hash_entry(hash_index, hash_entry);
+
+		// nat_printf("%lu Validate a WAN hash entry %d\n", jiffies/HZ, hash_index);
+		// hash_dump_entry(hash_index);
+   		hash_nat_enable_owner(hash_index);
+ 		hash_validate_entry(hash_index); // Must last one, else HW Tx fast SW
+		return 0;
+	}
+	return 0;
+}
+
+
+#ifdef _HAVE_DYNAMIC_PORT_LIST
+/*----------------------------------------------------------------------
+* sl_nat_add_port
+*----------------------------------------------------------------------*/
+void sl_nat_add_port(u8 protocol, u16 port)
+{
+	int 	i;
+	u16		*port_ptr;
+
+	if (protocol == IPPROTO_TCP)
+		port_ptr = dynamic_tcp_port_list;
+	else if (protocol == IPPROTO_UDP)
+		port_ptr = dynamic_udp_port_list;
+	else
+		return;
+
+	for (i=0; *port_ptr; i++)
+	{
+		if (port == *port_ptr)
+			return;
+		port_ptr++;
+	}
+	port_ptr++;
+	*port_ptr = port;
+}
+
+/*----------------------------------------------------------------------
+* sl_nat_remove_port
+*----------------------------------------------------------------------*/
+void sl_nat_remove_port(u8 protocol, u16 port)
+{
+	int 	i, j;
+	u16		*port_ptr, *next;
+
+	if (protocol == IPPROTO_TCP)
+		port_ptr = dynamic_tcp_port_list;
+	else if (protocol == IPPROTO_UDP)
+		port_ptr = dynamic_udp_port_list;
+	else
+		return;
+
+	for (i=0; *port_ptr; i++, port_ptr++)
+	{
+		if (port == *port_ptr)
+		{
+			port_next = port_ptr + 1;
+			for (j=i+1; *port_next; i++, j++)
+				*port_ptr++ = *port_next++;
+			*port_ptr = 0;
+			return;
+		}
+	}
+}
+#endif
+
+/*----------------------------------------------------------------------
+* sl351x_nat_ioctl
+*----------------------------------------------------------------------*/
+int sl351x_nat_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+{
+	GMAC_INFO_T 		*tp = (GMAC_INFO_T *)dev->priv;
+	int 				i, j, port_id;
+    NATCMD_HDR_T		nat_hdr;
+    NAT_REQ_E			ctrl;
+	unsigned char		*req_datap;
+	NAT_IP_ENTRY_T		*ipcfg;
+	NAT_XPORT_ENTRY_T	*xport_entry;
+	NAT_WRULE_ENTRY_T	*wrule_entry;
+	unsigned int		qid;
+
+	if (copy_from_user((void *)&nat_hdr, rq->ifr_data, sizeof(nat_hdr)))
+		return -EFAULT;
+	req_datap = (unsigned char *)rq->ifr_data + sizeof(nat_hdr);
+	port_id = tp->port_id;
+	switch (nat_hdr.cmd) {
+	case NATSSTATUS:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_STATUS_T))
+			return -EPERM;
+		if (copy_from_user((void *)&ctrl.status, req_datap, sizeof(ctrl.status)))
+			return -EFAULT;
+		if (ctrl.status.enable != 0 && ctrl.status.enable != 1)
+			return -EPERM;
+		// sl351x_nat_set_enabled_flag(ctrl.status.enable);
+		if (nat_cfg.enabled && (ctrl.status.enable == 0))
+		{
+			for (i=0; i<HASH_TOTAL_ENTRIES; i++)
+			{
+				if (hash_get_nat_owner_flag(i))
+				{
+					hash_nat_disable_owner(i);
+					hash_invalidate_entry(i);
+				}
+			}
+		}
+		nat_cfg.enabled = ctrl.status.enable;
+		break;
+	case NATGSTATUS:
+		if (nat_hdr.len != sizeof(NAT_STATUS_T))
+			return -EPERM;
+		ctrl.status.enable = nat_cfg.enabled;
+		if (copy_to_user(req_datap, (void *)&ctrl.status, sizeof(ctrl.status)))
+			return -EFAULT;
+		break;
+	case NATSETPORT:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_PORTCFG_T))
+			return -EPERM;
+		if (copy_from_user((void *)&ctrl.portcfg, req_datap, sizeof(ctrl.portcfg)))
+			return -EFAULT;
+		if (ctrl.portcfg.portmap == 0)
+			nat_cfg.lan_port = port_id;
+		else if (ctrl.portcfg.portmap == 1)
+			nat_cfg.wan_port = port_id;
+		else
+			return -EPERM;
+		break;
+	case NATGETPORT:
+		if (nat_hdr.len != sizeof(NAT_PORTCFG_T))
+			return -EPERM;
+		if (nat_cfg.lan_port == port_id)
+			ctrl.portcfg.portmap = 0;
+		else if (nat_cfg.wan_port == port_id)
+			ctrl.portcfg.portmap = 1;
+		else
+			return -EPERM;
+		if (copy_to_user(req_datap, (void *)&ctrl.portcfg, sizeof(ctrl.portcfg)))
+			return -EFAULT;
+		break;
+	case NATADDIP:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_IPCFG_T))
+			return -EPERM;
+		i = nat_cfg.ipcfg[port_id].total;
+		if (i >= CONFIG_NAT_MAX_IP_NUM)
+			return -E2BIG;
+		if (copy_from_user((void *)&nat_cfg.ipcfg[port_id].entry[i], req_datap, sizeof(NAT_IPCFG_T)))
+			return -EFAULT;
+		nat_cfg.ipcfg[port_id].total++;
+		break;
+	case NATDELIP:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_IPCFG_T))
+			return -EPERM;
+		if (copy_from_user((void *)&ctrl.ipcfg, req_datap, sizeof(ctrl.ipcfg)))
+			return -EFAULT;
+		ipcfg = (NAT_IP_ENTRY_T *)&nat_cfg.ipcfg[port_id].entry[0];
+		for (i=0; i<nat_cfg.ipcfg[port_id].total; i++, ipcfg++)
+		{
+			if (ipcfg->ipaddr == ctrl.ipcfg.entry.ipaddr)
+			{
+				NAT_IP_ENTRY_T *ipcfg_next;
+				ipcfg_next = ipcfg + 1;
+				for (j=i+1; j < nat_cfg.ipcfg[port_id].total; i++, j++)
+				{
+					memcpy((void *)ipcfg, (void *)ipcfg_next, sizeof(NAT_IP_ENTRY_T));
+					ipcfg++;
+					ipcfg_next++;
+				}
+				ipcfg->ipaddr = 0;
+				ipcfg->netmask = 0;
+				nat_cfg.ipcfg[port_id].total--;
+				return 0;
+			}
+		}
+		return -ENOENT;
+	case NATGETIP:
+		if (nat_hdr.len != sizeof(NAT_IPCFG_ALL_T))
+			return -EPERM;
+		if (copy_to_user(req_datap, (void *)&nat_cfg.ipcfg[port_id], sizeof(NAT_IPCFG_ALL_T)))
+			return -EFAULT;
+		break;
+	case NATAXPORT:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_XPORT_T))
+			return -EPERM;
+		i = nat_cfg.xport.total;
+		if (i >= CONFIG_NAT_MAX_XPORT)
+			return -E2BIG;
+		if (copy_from_user((void *)&nat_cfg.xport.entry[i], req_datap, sizeof(NAT_XPORT_T)))
+			return -EFAULT;
+		nat_cfg.xport.total++;
+		break;
+	case NATDXPORT:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_XPORT_T))
+			return -EPERM;
+		if (copy_from_user((void *)&ctrl.xport, req_datap, sizeof(NAT_XPORT_T)))
+			return -EFAULT;
+		xport_entry = (NAT_XPORT_ENTRY_T *)&nat_cfg.xport.entry[0];
+		for (i=0; i<nat_cfg.xport.total; i++, xport_entry++)
+		{
+			if (memcmp((void *)xport_entry, (void *)&ctrl.xport, sizeof(NAT_XPORT_ENTRY_T)) == 0)
+			{
+				NAT_XPORT_ENTRY_T *xport_next;
+				xport_next = xport_entry + 1;
+				for (j=i+1; j < nat_cfg.xport.total; i++, j++)
+				{
+					memcpy((void *)xport_entry, (void *)xport_next, sizeof(NAT_XPORT_ENTRY_T));
+					xport_entry++;
+					xport_next++;
+				}
+				memset((void *)xport_entry, 0, sizeof(NAT_XPORT_ENTRY_T));
+				nat_cfg.xport.total--;
+				return 0;
+			}
+		}
+		return -ENOENT;
+	case NATGXPORT:
+		if (nat_hdr.len != sizeof(NAT_XPORT_ALL_T))
+			return -EPERM;
+		if (copy_to_user(req_datap, (void *)&nat_cfg.xport, sizeof(NAT_XPORT_ALL_T)))
+			return -EFAULT;
+		break;
+	case NATSWEIGHT:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_WEIGHT_T))
+			return -EPERM;
+		if (copy_from_user((void *)&nat_cfg.weight, req_datap, sizeof(NAT_WEIGHT_T)))
+			return -EFAULT;
+		mac_set_hw_tx_weight(dev, (char *)&nat_cfg.weight);
+		break;
+	case NATGWEIGHT:
+		if (nat_hdr.len != sizeof(NAT_WEIGHT_T))
+			return -EPERM;
+		mac_get_hw_tx_weight(dev, (char *)&nat_cfg.weight);
+		if (copy_to_user(req_datap, (void *)&nat_cfg.weight, sizeof(NAT_WEIGHT_T)))
+			return -EFAULT;
+		break;
+	case NATAWRULE:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_WRULE_T))
+			return -EPERM;
+		if (copy_from_user((void *)&qid, req_datap, sizeof(qid)))
+			return -EFAULT;
+		if (qid > CONFIG_NAT_TXQ_NUM)
+			return -EPERM;
+		i = nat_cfg.wrule[qid].total;
+		if (i >= CONFIG_NAT_MAX_WRULE)
+			return -E2BIG;
+		if (copy_from_user((void *)&nat_cfg.wrule[qid].entry[i], req_datap+sizeof(qid), sizeof(NAT_WRULE_T)))
+			return -EFAULT;
+		nat_cfg.wrule[qid].total++;
+		break;
+	case NATDWRULE:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_WRULE_T))
+			return -EPERM;
+		if (copy_from_user((void *)&ctrl.wrule, req_datap, sizeof(NAT_WRULE_T)))
+			return -EFAULT;
+		qid = ctrl.wrule.qid;
+		if (qid >= CONFIG_NAT_TXQ_NUM)
+			return -EPERM;
+		wrule_entry = (NAT_WRULE_ENTRY_T *)&nat_cfg.wrule[qid].entry[0];
+		for (i=0; i<nat_cfg.wrule[qid].total; i++, wrule_entry++)
+		{
+			if (memcmp((void *)wrule_entry, (void *)&ctrl.wrule.entry, sizeof(NAT_WRULE_ENTRY_T)) == 0)
+			{
+				NAT_WRULE_ENTRY_T *wrule_next;
+				wrule_next = wrule_entry + 1;
+				for (j=i+1; j < nat_cfg.wrule[qid].total; i++, j++)
+				{
+					memcpy((void *)wrule_entry, (void *)wrule_next, sizeof(NAT_WRULE_ENTRY_T));
+					wrule_entry++;
+					wrule_next++;
+				}
+				memset((void *)wrule_entry, 0, sizeof(NAT_WRULE_ENTRY_T));
+				nat_cfg.wrule[qid].total--;
+				return 0;
+			}
+		}
+		return -ENOENT;
+	case NATGWRULE:
+		if (nat_hdr.len != sizeof(NAT_WRULE_ALL_T))
+			return -EPERM;
+		if (copy_from_user((void *)&qid, req_datap, sizeof(qid)))
+			return -EFAULT;
+		if (qid >= CONFIG_NAT_TXQ_NUM)
+			return -EPERM;
+		if (copy_to_user(req_datap, (void *)&nat_cfg.wrule[qid], sizeof(NAT_WRULE_ALL_T)))
+			return -EFAULT;
+		break;
+	case NATSDEFQ:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_QUEUE_T))
+			return -EPERM;
+		if (copy_from_user((void *)&nat_cfg.default_hw_txq, req_datap, sizeof(u32)))
+			return -EFAULT;
+		break;
+	case NATGDEFQ:
+		if (nat_hdr.len != sizeof(NAT_QUEUE_T))
+			return -EPERM;
+		if (copy_to_user(req_datap, (void *)&nat_cfg.default_hw_txq, sizeof(u32)))
+			return -EFAULT;
+	case NATRMIPCFG:
+		nat_cfg.ipcfg[port_id].total = 0;
+		break;
+	case NATTESTENTRY:
+		if (!capable(CAP_NET_ADMIN))
+			return -EPERM;
+		if (nat_hdr.len != sizeof(NAT_TESTENTRY_T))
+			return -EPERM;
+		if (copy_from_user((void *)&ctrl.init_entry, req_datap, sizeof(ctrl.init_entry)))
+			return -EFAULT;
+		if (ctrl.init_entry.init_enable != 0 && ctrl.init_entry.init_enable != 1)
+			return -EPERM;
+		nat_cfg.init_enabled = ctrl.init_entry.init_enable;
+		break;
+
+	default:
+		return -EPERM;
+	}
+
+	return 0;
+}
+
+/*----------------------------------------------------------------------
+* 	nat_init_test_entry
+*	Initialize NAT test hash entries
+*
+*	SmartBits P1  -----> Lepus GMAC 0 --------------+
+*													|
+*													|
+*             P3  <----- Lepus GMAC 1 -- HW TxQ0 <--+
+*									  -- HW TxQ1 <--+
+*									  -- HW TxQ2 <--+
+*									  -- HW TxQ3 <--+
+*
+*	SmartBits P1  <----- Lepus GMAC 0 -- HW TxQ0 <--+
+*									  -- HW TxQ1 <--+
+*                                     -- HW TxQ2 <--+
+*									  -- HW TxQ3 <--+
+*													|
+*													|
+*             P3  -----> Lepus GMAC 1 --------------+
+*
+*   LAN GMAC0 <--------------------------------------------> GMAC1 WAN
+*	192.168.[x].[y]:50 --> 168.95.[x].[y]:80 ---TXQ[y-1]---> 192.168.2.254:200[y] --> 168.95.[x].[y]:80
+*	192.168.[x].[y]:50 <-- 168.95.[x].[y]:80 <--TXQ[y-1]---- 192.168.2.254:200[y] <-- 168.95.[x].[y]:80
+*   where:
+*		[x] : Packet Type
+*		[y] : Tx Queue, 1 for TxQ0, 2 for TxQ1, 3 for TxQ2, 4 for TxQ3,
+*
+*
+* Packet Type:
+* 1. TCP Frames <---> TCP Frames
+*   LAN GMAC0 <--------------------------------> GMAC1 WAN
+*	192.168.1.1:50 --> 168.95.1.1:80 ---TXQ0---> 192.168.2.254:2001 --> 168.95.1.1:80
+*	192.168.1.1:50 <-- 168.95.1.1:80 <--TXQ0---- 192.168.2.254:2001 <-- 168.95.1.1:80
+*
+*	192.168.1.2:50 --> 168.95.1.2:80 ---TXQ1---> 192.168.2.254:2002 --> 168.95.1.2:80
+*	192.168.1.2:50 <-- 168.95.1.2:80 <--TXQ1---- 192.168.2.254:2002 <-- 168.95.1.2:80
+*
+*	192.168.1.3:50 --> 168.95.1.3:80 ---TXQ2---> 192.168.2.254:2003 --> 168.95.1.3:80
+*	192.168.1.3:50 <-- 168.95.1.3:80 <--TXQ2---- 192.168.2.254:2003 <-- 168.95.1.3:80
+*
+*	192.168.1.4:50 --> 168.95.1.4:80 ---TXQ3---> 192.168.2.254:2004 --> 168.95.1.4:80
+*	192.168.1.4:50 <-- 168.95.1.4:80 <--TXQ3---- 192.168.2.254:2004 <-- 168.95.1.4:80
+*
+* 2 TCP Frames <----> PPPoE + TCP Frames
+*   LAN GMAC0 <--------------------------------> GMAC1 WAN
+*	192.168.2.1:50 --> 168.95.2.1:80 ---TXQ0---> 192.168.2.254:2001 --> 168.95.2.1:80
+*	192.168.2.1:50 <-- 168.95.2.1:80 <--TXQ0---- 192.168.2.254:2001 <-- 168.95.2.1:80
+*
+*	192.168.2.2:50 --> 168.95.2.2:80 ---TXQ1---> 192.168.2.254:2002 --> 168.95.2.2:80
+*	192.168.2.2:50 <-- 168.95.2.2:80 <--TXQ1---- 192.168.2.254:2002 <-- 168.95.2.2:80
+*
+*	192.168.2.3:50 --> 168.95.2.3:80 ---TXQ2---> 192.168.2.254:2003 --> 168.95.2.3:80
+*	192.168.2.3:50 <-- 168.95.2.3:80 <--TXQ2---- 192.168.2.254:2003 <-- 168.95.2.3:80
+*
+*	192.168.2.4:50 --> 168.95.2.4:80 ---TXQ3---> 192.168.2.254:2004 --> 168.95.2.4:80
+*	192.168.2.4:50 <-- 168.95.2.4:80 <--TXQ3---- 192.168.2.254:2004 <-- 168.95.2.4:80
+*
+* 3 TCP Frames <----> VLAN + PPPoE + TCP Frames
+*   LAN GMAC0 <--------------------------------> GMAC1 WAN
+*	192.168.3.1:50 --> 168.95.3.1:80 ---TXQ0---> 192.168.2.254:2001 --> 168.95.3.1:80
+*	192.168.3.1:50 <-- 168.95.3.1:80 <--TXQ0---- 192.168.2.254:2001 <-- 168.95.3.1:80
+*
+*	192.168.3.2:50 --> 168.95.3.2:80 ---TXQ1---> 192.168.2.254:2002 --> 168.95.3.2:80
+*	192.168.3.2:50 <-- 168.95.3.2:80 <--TXQ1---- 192.168.2.254:2002 <-- 168.95.3.2:80
+*
+*	192.168.3.3:50 --> 168.95.3.3:80 ---TXQ2---> 192.168.2.254:2003 --> 168.95.3.3:80
+*	192.168.3.3:50 <-- 168.95.3.3:80 <--TXQ2---- 192.168.2.254:2003 <-- 168.95.3.3:80
+*
+*	192.168.3.4:50 --> 168.95.3.4:80 ---TXQ3---> 192.168.2.254:2004 --> 168.95.3.4:80
+*	192.168.3.4:50 <-- 168.95.3.4:80 <--TXQ3---- 192.168.2.254:2004 <-- 168.95.3.4:80
+*
+* 4 VLAN-A + TCP Frames <----> VLAN-B + PPPoE + TCP Frames
+*   LAN GMAC0 <--------------------------------> GMAC1 WAN
+*	192.168.4.1:50 --> 168.95.4.1:80 ---TXQ0---> 192.168.2.254:2001 --> 168.95.4.1:80
+*	192.168.4.1:50 <-- 168.95.4.1:80 <--TXQ0---- 192.168.2.254:2001 <-- 168.95.4.1:80
+*
+*	192.168.4.2:50 --> 168.95.4.2:80 ---TXQ1---> 192.168.2.254:2002 --> 168.95.4.2:80
+*	192.168.4.2:50 <-- 168.95.4.2:80 <--TXQ1---- 192.168.2.254:2002 <-- 168.95.4.2:80
+*
+*	192.168.4.3:50 --> 168.95.4.3:80 ---TXQ2---> 192.168.2.254:2003 --> 168.95.4.3:80
+*	192.168.4.3:50 <-- 168.95.4.3:80 <--TXQ2---- 192.168.2.254:2003 <-- 168.95.4.3:80
+*
+*	192.168.4.4:50 --> 168.95.4.4:80 ---TXQ3---> 192.168.2.254:2004 --> 168.95.4.4:80
+*	192.168.4.4:50 <-- 168.95.4.4:80 <--TXQ3---- 192.168.2.254:2004 <-- 168.95.4.4:80
+*
+*
+*
+*----------------------------------------------------------------------*/
+#ifdef SL351x_NAT_TEST_BY_SMARTBITS
+#define 	NAT_IPIV(a,b,c,d)			((a<<24)+(b<<16)+(c<<8)+d)
+#define     NAT_TEST_CLIENT_IP 			NAT_IPIV(192,168,1,1)
+#define     NAT_TEST_SERVER_IP 			NAT_IPIV(168,95,1,1)
+#define		NAT_TEST_LAN_IP				NAT_IPIV(192,168,1,254)
+#define		NAT_TEST_WAN_IP				NAT_IPIV(192,168,2,254)
+#define     NAT_TEST_MAP_PORT_BASE		2001
+#define     NAT_TEST_SPORT				50
+#define     NAT_TEST_DPORT				80
+#define     NAT_TEST_PROTOCOL			6
+u8			nat_test_lan_target_da[6]={0x00,0x11,0x22,0x33,0x44,0x55};
+u8			nat_test_wan_target_da[6]={0x00,0xaa,0xbb,0xcc,0xdd,0xee};
+u8			nat_test_lan_my_da[6]={0x00,0x11,0x11,0x11,0x11,0x11};
+u8			nat_test_wan_my_da[6]={0x00,0x22,0x22,0x22,0x22,0x22};
+static void nat_init_test_entry(void)
+{
+	int 				i, j ;
+	NAT_HASH_ENTRY_T	*hash_entry;
+	u32					sip, dip;
+	u32					hash_data[HASH_MAX_DWORDS];
+	NAT_CFG_T			*cfg;
+	int					hash_index;
+
+	cfg = (NAT_CFG_T *)&nat_cfg;
+	hash_entry = (NAT_HASH_ENTRY_T *)&hash_data;
+	hash_entry->key.Ethertype 	= 0;
+	hash_entry->key.rule_id 	= 0;
+	hash_entry->key.ip_protocol = IPPROTO_TCP;
+	hash_entry->key.reserved1 	= 0;
+	hash_entry->key.reserved2 	= 0;
+	// hash_entry->key.sip 		= NAT_TEST_CLIENT_IP;
+	// hash_entry->key.dip 		= NAT_TEST_SERVER_IP;
+	hash_entry->key.sport 		= htons(NAT_TEST_SPORT);
+	hash_entry->key.dport 		= htons(NAT_TEST_DPORT);
+	hash_entry->key.rule_id = cfg->tcp_udp_rule_id;
+	hash_entry->action.dword = NAT_LAN2WAN_ACTIONS;
+
+	sip = NAT_TEST_CLIENT_IP;
+	dip = NAT_TEST_SERVER_IP;
+
+	// Init TCP <------> TCP hash entries
+	// LAN --> WAN
+	// (1) TCP --> TCP
+	// (2) TCP --> PPPoE + TCP
+	// (3) TCP --> VLAN-B + PPPoE + TCP
+	// (4) TCP + VLAN-A --> VLAN-B + PPPoE + TCP
+	memcpy(hash_entry->param.da, nat_test_wan_target_da, 6);
+	memcpy(hash_entry->param.sa, nat_test_wan_my_da, 6);
+	hash_entry->key.port_id = cfg->lan_port;
+	for (i=0; i<TOE_HW_TXQ_NUM; i++)
+	{
+		if (i < 2)
+		{
+			hash_entry->action.bits.dest_qid = i+2;
+		}
+		else
+		{
+			hash_entry->action.bits.dest_qid = i;
+		}
+		hash_entry->action.bits.dest_qid += (cfg->wan_port==0) ? TOE_GMAC0_HW_TXQ0_QID : TOE_GMAC1_HW_TXQ0_QID;
+		hash_entry->param.Sport = NAT_TEST_MAP_PORT_BASE+i;
+		hash_entry->param.Dport = NAT_TEST_DPORT;
+		for (j=0; j<4; j++)
+		{
+			hash_entry->key.sip = sip + i + j*0x100;
+			hash_entry->key.dip = dip + i + j*0x100;
+			hash_entry->param.Dip = hash_entry->key.dip;
+			hash_entry->param.Sip = NAT_TEST_WAN_IP;
+			switch (j)
+			{
+			case 0:
+				hash_entry->action.bits.pppoe = 0;
+				hash_entry->param.pppoe = 0;
+				hash_entry->action.bits.vlan = 0;
+				hash_entry->param.vlan = 0;
+				break;
+			case 1:
+				hash_entry->action.bits.pppoe = 1;
+				hash_entry->param.pppoe = i+1;
+				hash_entry->action.bits.vlan = 0;
+				hash_entry->param.vlan = 0;
+				break;
+			case 2:
+				hash_entry->action.bits.pppoe = 1;
+				hash_entry->param.pppoe = i+1;
+				hash_entry->action.bits.vlan = 1;
+				hash_entry->param.vlan = i+10;
+				break;
+			case 3:
+				hash_entry->action.bits.pppoe = 1;
+				hash_entry->param.pppoe = i+1;
+				hash_entry->action.bits.vlan = 1;
+				hash_entry->param.vlan = i+10;
+				break;
+			}
+			hash_entry->tmo.counter = hash_entry->tmo.interval = 0x7fff;
+			hash_index = nat_build_keys(&hash_entry->key);
+			nat_write_hash_entry(hash_index, hash_entry);
+			hash_nat_enable_owner(hash_index);
+			hash_validate_entry(hash_index); // Must last one, else HW Tx fast than SW
+		}
+	}
+
+
+	// WAN --> LAN
+	hash_entry->key.port_id 	= cfg->wan_port;
+	hash_entry->key.sport 		= htons(NAT_TEST_DPORT);
+	hash_entry->key.dport 		= htons(NAT_TEST_DPORT);
+	hash_entry->key.rule_id		= cfg->tcp_udp_rule_id;
+	hash_entry->action.dword	= NAT_WAN2LAN_ACTIONS;
+	hash_entry->key.sport		= htons(NAT_TEST_DPORT);
+	memcpy(hash_entry->param.da, nat_test_lan_target_da, 6);
+	memcpy(hash_entry->param.sa, nat_test_lan_my_da, 6);
+	for (i=0; i<TOE_HW_TXQ_NUM; i++)
+	{
+		hash_entry->key.dport = htons(NAT_TEST_MAP_PORT_BASE + i);
+		if (i < 2)
+		{
+			hash_entry->action.bits.dest_qid = i+2;
+		}
+		else
+		{
+			hash_entry->action.bits.dest_qid = i;
+		}
+		hash_entry->action.bits.dest_qid += (cfg->lan_port==0) ? TOE_GMAC0_HW_TXQ0_QID : TOE_GMAC1_HW_TXQ0_QID;
+		hash_entry->param.Dport = NAT_TEST_SPORT;
+		hash_entry->param.Sport = NAT_TEST_DPORT;
+		hash_entry->param.da[5] = i;
+		for (j=0; j<4; j++)
+		{
+			hash_entry->key.sip = (dip + i + j*0x100);
+			hash_entry->key.dip = (NAT_TEST_WAN_IP);
+			hash_entry->param.Sip = hash_entry->key.sip;
+			hash_entry->param.Dip = sip + i + j*0x100;
+			switch (j)
+			{
+			case 0:
+				hash_entry->action.bits.pppoe = 0;
+				hash_entry->param.pppoe = 0;
+				hash_entry->action.bits.vlan = 0;
+				hash_entry->param.vlan = 0;
+				break;
+			case 1:
+				hash_entry->action.bits.pppoe = 2;
+				hash_entry->param.pppoe = i+1;
+				hash_entry->action.bits.vlan = 0;
+				hash_entry->param.vlan = 0;
+				break;
+			case 2:
+				hash_entry->action.bits.pppoe = 2;
+				hash_entry->param.pppoe = i+1;
+				hash_entry->action.bits.vlan = 2;
+				hash_entry->param.vlan = i+5;
+				break;
+			case 3:
+				hash_entry->action.bits.pppoe = 1;
+				hash_entry->param.pppoe = i+1;
+				hash_entry->action.bits.vlan = 1;
+				hash_entry->param.vlan = i+5;
+				break;
+			}
+			hash_entry->tmo.counter = hash_entry->tmo.interval = 0x7fff;
+			hash_index = nat_build_keys(&hash_entry->key);
+			nat_write_hash_entry(hash_index, hash_entry);
+			hash_nat_enable_owner(hash_index);
+			hash_validate_entry(hash_index); // Must last one, else HW Tx fast than SW
+		}
+	}
+}
+#endif	// SL351x_NAT_TEST_BY_SMARTBITS
+
+#endif // CONFIG_SL351x_NAT
+
--- /dev/null
+++ b/drivers/net/sl351x_proc.c
@@ -0,0 +1,578 @@
+/****************************************************************************
+* Copyright 2006 Storlink Corp.  All rights reserved.
+*----------------------------------------------------------------------------
+* Name			: sl351x_proc.c
+* Description	:
+*		Handle Proc Routines for Storlink SL351x Platform
+*
+* History
+*
+*	Date		Writer		Description
+*----------------------------------------------------------------------------
+*	04/13/2006	Gary Chen	Create and implement
+*
+*
+****************************************************************************/
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/compiler.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
+#include <linux/delay.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/completion.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/semaphore.h>
+#include <asm/arch/irqs.h>
+#include <asm/arch/it8712.h>
+#include <linux/mtd/kvctl.h>
+#include <linux/skbuff.h>
+#include <linux/if_ether.h>
+#include <linux/if_pppox.h>
+#include <linux/in.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/ppp_defs.h>
+#ifdef CONFIG_NETFILTER
+// #include <linux/netfilter_ipv4/ip_conntrack.h>
+#endif
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/percpu.h>
+#ifdef CONFIG_SYSCTL
+#include <linux/sysctl.h>
+#endif
+
+#define	 MIDWAY
+#define	 SL_LEPUS
+
+// #define PROC_DEBUG_MSG	1
+
+#include <asm/arch/sl2312.h>
+#include <asm/arch/sl351x_gmac.h>
+#include <asm/arch/sl351x_hash_cfg.h>
+#include <asm/arch/sl351x_nat_cfg.h>
+#include <asm/arch/sl351x_toe.h>
+
+#ifdef CONFIG_PROC_FS
+/*----------------------------------------------------------------------
+* Definition
+*----------------------------------------------------------------------*/
+#define	proc_printf					printk
+#define SL351x_GMAC_PROC_NAME		"sl351x_gmac"
+#define SL351x_NAT_PROC_NAME		"sl351x_nat"
+#define SL351x_TOE_PROC_NAME		"sl351x_toe"
+
+/*----------------------------------------------------------------------
+* Function Definition
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static int nat_ct_open(struct inode *inode, struct file *file);
+static void *nat_ct_seq_start(struct seq_file *s, loff_t *pos);
+static void nat_ct_seq_stop(struct seq_file *s, void *v);
+static void *nat_ct_seq_next(struct seq_file *s, void *v, loff_t *pos);
+static int nat_ct_seq_show(struct seq_file *s, void *v);
+#endif
+
+#ifdef CONFIG_SL351x_RXTOE
+static int toe_ct_open(struct inode *inode, struct file *file);
+static void *toe_ct_seq_start(struct seq_file *s, loff_t *pos);
+static void toe_ct_seq_stop(struct seq_file *s, void *v);
+static void *toe_ct_seq_next(struct seq_file *s, void *v, loff_t *pos);
+static int toe_ct_seq_show(struct seq_file *s, void *v);
+extern int sl351x_get_toe_conn_flag(int index);
+extern struct toe_conn * sl351x_get_toe_conn_info(int index);
+#endif
+
+static int gmac_ct_open(struct inode *inode, struct file *file);
+static void *gmac_ct_seq_start(struct seq_file *s, loff_t *pos);
+static void gmac_ct_seq_stop(struct seq_file *s, void *v);
+static void *gmac_ct_seq_next(struct seq_file *s, void *v, loff_t *pos);
+static int gmac_ct_seq_show(struct seq_file *s, void *v);
+
+
+/*----------------------------------------------------------------------
+* Data
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SYSCTL
+// static struct ctl_table_header *nat_ct_sysctl_header;
+#endif
+
+#ifdef CONFIG_SL351x_NAT
+static struct seq_operations nat_ct_seq_ops = {
+	.start = nat_ct_seq_start,
+	.next  = nat_ct_seq_next,
+	.stop  = nat_ct_seq_stop,
+	.show  = nat_ct_seq_show
+};
+
+static struct file_operations nat_file_ops= {
+	.owner   = THIS_MODULE,
+	.open    = nat_ct_open,
+	.read    = seq_read,
+	.llseek  = seq_lseek,
+	.release = seq_release
+};
+#endif // CONFIG_SL351x_NAT
+
+#ifdef CONFIG_SL351x_RXTOE
+static struct seq_operations toe_ct_seq_ops = {
+	.start = toe_ct_seq_start,
+	.next  = toe_ct_seq_next,
+	.stop  = toe_ct_seq_stop,
+	.show  = toe_ct_seq_show
+};
+
+static struct file_operations toe_file_ops= {
+	.owner   = THIS_MODULE,
+	.open    = toe_ct_open,
+	.read    = seq_read,
+	.llseek  = seq_lseek,
+	.release = seq_release
+};
+#endif
+
+static struct seq_operations gmac_ct_seq_ops = {
+	.start = gmac_ct_seq_start,
+	.next  = gmac_ct_seq_next,
+	.stop  = gmac_ct_seq_stop,
+	.show  = gmac_ct_seq_show
+};
+
+static struct file_operations gmac_file_ops= {
+	.owner   = THIS_MODULE,
+	.open    = gmac_ct_open,
+	.read    = seq_read,
+	.llseek  = seq_lseek,
+	.release = seq_release
+};
+
+#ifdef SL351x_GMAC_WORKAROUND
+extern u32 gmac_workaround_cnt[4];
+extern u32 gmac_short_frame_workaround_cnt[2];
+#ifdef CONFIG_SL351x_NAT
+	extern u32 sl351x_nat_workaround_cnt;
+#endif
+#endif
+/*----------------------------------------------------------------------
+* nat_ct_open
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static int nat_ct_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &nat_ct_seq_ops);
+}
+#endif // CONFIG_SL351x_NAT
+/*----------------------------------------------------------------------
+* nat_ct_seq_start
+* find the first
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static void *nat_ct_seq_start(struct seq_file *s, loff_t *pos)
+{
+	int i;
+
+	// proc_printf("%s: *pos=%d\n", __func__, (int)*pos);
+	for (i=*pos; i<HASH_TOTAL_ENTRIES; i++)
+	{
+		if (hash_get_nat_owner_flag(i))
+		{
+			*pos = i;
+			return (void *)(i+1);
+		}
+	}
+	return NULL;
+}
+#endif // CONFIG_SL351x_NAT
+/*----------------------------------------------------------------------
+* nat_ct_seq_stop
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static void nat_ct_seq_stop(struct seq_file *s, void *v)
+{
+}
+#endif // CONFIG_SL351x_NAT
+/*----------------------------------------------------------------------
+* nat_ct_seq_next
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static void *nat_ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	int i;
+
+	// proc_printf("%s: *pos=%d\n", __func__, (int)*pos);
+	(*pos)++;
+	for (i=*pos; i<HASH_TOTAL_ENTRIES; i++)
+	{
+		if (hash_get_nat_owner_flag(i))
+		{
+			*pos = i;
+			return (void *)(i+1);
+		}
+	}
+	return NULL;
+}
+#endif // CONFIG_SL351x_NAT
+/*----------------------------------------------------------------------
+* nat_ct_seq_show
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_NAT
+static int nat_ct_seq_show(struct seq_file *s, void *v)
+{
+	int 				idx;
+	NAT_HASH_ENTRY_T	*nat_entry;
+	GRE_HASH_ENTRY_T	*gre_entry;
+
+	idx = (int)v;
+	if (idx<=0 || idx >HASH_TOTAL_ENTRIES)
+		return -ENOSPC;
+
+	idx--;
+	nat_entry = (NAT_HASH_ENTRY_T *)&hash_tables[idx];
+	gre_entry = (GRE_HASH_ENTRY_T *)nat_entry;
+	if (nat_entry->key.ip_protocol == IPPROTO_GRE)
+	{
+		if (seq_printf(s, "%4d: KEY MAC-%d [%d] %u.%u.%u.%u [%u]-->%u.%u.%u.%u\n",
+					idx, gre_entry->key.port_id, gre_entry->key.ip_protocol,
+					HIPQUAD(gre_entry->key.sip), ntohs(gre_entry->key.call_id),
+					HIPQUAD(gre_entry->key.dip)))
+			return -ENOSPC;
+		if (seq_printf(s, "      PARAMETER: %u.%u.%u.%u -->%u.%u.%u.%u [%u] Timeout:%ds\n",
+					HIPQUAD(gre_entry->param.Sip),
+					HIPQUAD(gre_entry->param.Dip), gre_entry->param.Dport,
+					gre_entry->tmo.counter))
+			return -ENOSPC;
+	}
+	else
+	{
+		if (seq_printf(s, "%4d: KEY MAC-%d [%d] %u.%u.%u.%u [%u]-->%u.%u.%u.%u [%u]\n",
+					idx, nat_entry->key.port_id, nat_entry->key.ip_protocol,
+					HIPQUAD(nat_entry->key.sip), ntohs(nat_entry->key.sport),
+					HIPQUAD(nat_entry->key.dip), ntohs(nat_entry->key.dport)))
+			return -ENOSPC;
+		if (seq_printf(s, "      PARAMETER: %u.%u.%u.%u [%u]-->%u.%u.%u.%u [%u] Timeout:%ds\n",
+					HIPQUAD(nat_entry->param.Sip), nat_entry->param.Sport,
+					HIPQUAD(nat_entry->param.Dip), nat_entry->param.Dport,
+					nat_entry->tmo.counter))
+			return -ENOSPC;
+	}
+	return 0;
+}
+#endif // CONFIG_SL351x_NAT
+
+/*----------------------------------------------------------------------
+* toe_ct_open
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_RXTOE
+static int toe_ct_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &toe_ct_seq_ops);
+}
+#endif
+/*----------------------------------------------------------------------
+* toe_ct_seq_start
+* find the first
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_RXTOE
+static void *toe_ct_seq_start(struct seq_file *s, loff_t *pos)
+{
+	int i;
+
+	// proc_printf("%s: *pos=%d\n", __func__, (int)*pos);
+	for (i=*pos; i<TOE_TOE_QUEUE_NUM; i++)
+	{
+		if (sl351x_get_toe_conn_flag(i))
+		{
+			*pos = i;
+			return (void *)(i+1);
+		}
+	}
+	return NULL;
+}
+#endif
+/*----------------------------------------------------------------------
+* toe_ct_seq_stop
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_RXTOE
+static void toe_ct_seq_stop(struct seq_file *s, void *v)
+{
+}
+#endif
+/*----------------------------------------------------------------------
+* toe_ct_seq_next
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_RXTOE
+static void *toe_ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	int i;
+
+	// proc_printf("%s: *pos=%d\n", __func__, (int)*pos);
+	(*pos)++;
+	for (i=*pos; i<TOE_TOE_QUEUE_NUM; i++)
+	{
+		if (sl351x_get_toe_conn_flag(i))
+		{
+			*pos = i;
+			return (void *)(i+1);
+		}
+	}
+	return NULL;
+}
+#endif
+/*----------------------------------------------------------------------
+* toe_ct_seq_show
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_SL351x_RXTOE
+static int toe_ct_seq_show(struct seq_file *s, void *v)
+{
+	int 				idx;
+	struct toe_conn		*toe_entry;
+
+	idx = (int)v;
+	if (idx<=0 || idx >TOE_TOE_QUEUE_NUM)
+		return -ENOSPC;
+
+	idx--;
+	toe_entry = (struct toe_conn *)sl351x_get_toe_conn_info(idx);
+	if (!toe_entry)
+		return -ENOSPC;
+
+	if (seq_printf(s, "%4d: Qid %d MAC-%d TCP %u.%u.%u.%u [%u]-->%u.%u.%u.%u [%u]\n",
+				idx, toe_entry->qid, toe_entry->gmac->port_id,
+				NIPQUAD(toe_entry->saddr[0]), ntohs(toe_entry->source),
+				NIPQUAD(toe_entry->daddr[0]), ntohs(toe_entry->dest)))
+			return -ENOSPC;
+	return 0;
+}
+#endif
+/*----------------------------------------------------------------------
+* gmac_ct_open
+*----------------------------------------------------------------------*/
+static int gmac_ct_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &gmac_ct_seq_ops);
+}
+
+/*----------------------------------------------------------------------
+* gmac_ct_seq_start
+* find the first
+*----------------------------------------------------------------------*/
+static void *gmac_ct_seq_start(struct seq_file *s, loff_t *pos)
+{
+	int i;
+	i = (int)*pos + 1;;
+
+	if (i > 9)
+		return NULL;
+	else
+		return (void *)i;
+}
+
+/*----------------------------------------------------------------------
+* gmac_ct_seq_stop
+*----------------------------------------------------------------------*/
+static void gmac_ct_seq_stop(struct seq_file *s, void *v)
+{
+}
+
+/*----------------------------------------------------------------------
+* gmac_ct_seq_next
+*----------------------------------------------------------------------*/
+static void *gmac_ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	int i;
+
+	// proc_printf("%s: *pos=%d\n", __func__, (int)*pos);
+
+	(*pos)++;
+	i = (int)*pos + 1;;
+
+	if (i > 9)
+		return NULL;
+	else
+		return (void *)i;
+}
+
+/*----------------------------------------------------------------------
+* seq_dm_long
+*----------------------------------------------------------------------*/
+static void seq_dm_long(struct seq_file *s, u32 location, int length)
+{
+	u32		*start_p, *curr_p, *end_p;
+	u32		*datap, data;
+	int		i;
+
+	//if (length > 1024)
+	//	length = 1024;
+
+	start_p = (u32 *)location;
+	end_p = (u32 *)location + length;
+	curr_p = (u32 *)((u32)location & 0xfffffff0);
+	datap = (u32 *)location;
+	while (curr_p < end_p)
+	{
+		cond_resched();
+		seq_printf(s, "0x%08x: ",(u32)curr_p & 0xfffffff0);
+		for (i=0; i<4; i++)
+		{
+			if (curr_p < start_p || curr_p >= end_p)
+               seq_printf(s, "         ");
+			else
+			{
+				data = *datap;
+				seq_printf(s, "%08X ", data);
+			}
+			if (i==1)
+              seq_printf(s, "- ");
+
+			curr_p++;
+			datap++;
+		}
+        seq_printf(s, "\n");
+	}
+}
+
+/*----------------------------------------------------------------------
+* gmac_ct_seq_show
+*----------------------------------------------------------------------*/
+static int gmac_ct_seq_show(struct seq_file *s, void *v)
+{
+	switch ((int)v)
+	{
+		case 1:
+			seq_printf(s, "\nGMAC Global Registers\n");
+			seq_dm_long(s, TOE_GLOBAL_BASE, 32);
+			break;
+		case 2:
+			seq_printf(s, "\nGMAC Non-TOE Queue Header\n");
+			seq_dm_long(s, TOE_NONTOE_QUE_HDR_BASE, 12);
+			break;
+		case 3:
+			seq_printf(s, "\nGMAC TOE Queue Header\n");
+			seq_dm_long(s, TOE_TOE_QUE_HDR_BASE, 12);
+			break;
+		case 4:
+			seq_printf(s, "\nGMAC-0 DMA Registers\n");
+			seq_dm_long(s, TOE_GMAC0_DMA_BASE, 52);
+			break;
+		case 5:
+			seq_printf(s, "\nGMAC-0 Registers\n");
+			seq_dm_long(s, TOE_GMAC0_BASE, 32);
+			break;
+		case 6:
+			seq_printf(s, "\nGMAC-1 DMA Registers\n");
+			seq_dm_long(s, TOE_GMAC1_DMA_BASE, 52);
+			break;
+		case 7:
+			seq_printf(s, "\nGMAC-1 Registers\n");
+			seq_dm_long(s, TOE_GMAC1_BASE, 32);
+			break;
+		case 8:
+			seq_printf(s, "\nGLOBAL Registers\n");
+			seq_dm_long(s, GMAC_GLOBAL_BASE_ADDR, 16);
+			break;
+		case 9:
+#ifdef SL351x_GMAC_WORKAROUND
+			seq_printf(s, "\nGMAC-0 Rx/Tx/Short Workaround: %u, %u, %u\n", gmac_workaround_cnt[0], gmac_workaround_cnt[1], gmac_short_frame_workaround_cnt[0]);
+			seq_printf(s, "GMAC-1 Rx/Tx/Short Workaround: %u, %u, %u\n", gmac_workaround_cnt[2], gmac_workaround_cnt[3], gmac_short_frame_workaround_cnt[1]);
+#ifdef CONFIG_SL351x_NAT
+			seq_printf(s, "NAT Workaround: %u\n", sl351x_nat_workaround_cnt);
+#endif
+#endif
+			break;
+		default:
+			return -ENOSPC;
+	}
+	return 0;
+}
+
+/*----------------------------------------------------------------------
+* init
+*----------------------------------------------------------------------*/
+static int __init init(void)
+{
+	struct proc_dir_entry *proc_gmac=NULL;
+
+#ifdef CONFIG_SL351x_NAT
+	struct proc_dir_entry *proc_nat=NULL;
+#endif
+
+#ifdef CONFIG_SL351x_RXTOE
+	struct proc_dir_entry *proc_toe=NULL;
+#endif
+
+#ifdef CONFIG_SYSCTL
+	// nat_ct_sysctl_header = NULL;
+#endif
+	proc_gmac = proc_net_fops_create(SL351x_GMAC_PROC_NAME, 0440, &gmac_file_ops);
+	if (!proc_gmac) goto init_bad;
+
+#ifdef CONFIG_SL351x_NAT
+	proc_nat = proc_net_fops_create(SL351x_NAT_PROC_NAME, 0440, &nat_file_ops);
+	if (!proc_nat) goto init_bad;
+#endif // CONFIG_SL351x_NAT
+
+#ifdef CONFIG_SL351x_RXTOE
+	proc_toe = proc_net_fops_create(SL351x_TOE_PROC_NAME, 0440, &toe_file_ops);
+	if (!proc_toe) goto init_bad;
+#endif
+
+#ifdef CONFIG_SYSCTL
+	// nat_ct_sysctl_header = register_sysctl_table(nat_ct_net_table, 0);
+	// if (!nat_ct_sysctl_header) goto init_bad;
+#endif
+
+	return 0;
+
+init_bad:
+	if (proc_gmac) proc_net_remove(SL351x_GMAC_PROC_NAME);
+
+#ifdef CONFIG_SL351x_NAT
+	if (proc_nat) proc_net_remove(SL351x_NAT_PROC_NAME);
+#endif
+
+#ifdef CONFIG_SL351x_RXTOE
+	if (proc_toe) proc_net_remove(SL351x_NAT_PROC_NAME);
+#endif
+
+#ifdef CONFIG_SYSCTL
+	// if (nat_ct_sysctl_header) unregister_sysctl_table(nat_ct_sysctl_header);
+#endif
+	proc_printf("SL351x NAT Proc: can't create proc or register sysctl.\n");
+	return -ENOMEM;
+}
+
+/*----------------------------------------------------------------------
+* fini
+*----------------------------------------------------------------------*/
+static void __exit fini(void)
+{
+	proc_net_remove(SL351x_GMAC_PROC_NAME);
+
+#ifdef CONFIG_SL351x_NAT
+	proc_net_remove(SL351x_NAT_PROC_NAME);
+#endif
+
+#ifdef CONFIG_SL351x_RXTOE
+	proc_net_remove(SL351x_TOE_PROC_NAME);
+#endif
+
+#ifdef CONFIG_SYSCTL
+	// unregister_sysctl_table(nat_ct_sysctl_header);
+#endif
+}
+
+/*----------------------------------------------------------------------
+* module
+*----------------------------------------------------------------------*/
+module_init(init);
+module_exit(fini);
+
+#endif	// CONFIG_PROC_FS
--- /dev/null
+++ b/drivers/net/sl351x_toe.c
@@ -0,0 +1,1083 @@
+/**************************************************************************
+* Copyright 2006 StorLink Semiconductors, Inc.  All rights reserved.
+*--------------------------------------------------------------------------
+* Name			: sl351x_toe.c
+* Description	:
+*		Provide TOE routines for SL351x
+*
+* History
+*
+*	Date		Writer		Description
+*----------------------------------------------------------------------------
+*				Xiaochong
+*
+****************************************************************************/
+
+#include <linux/pci.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/tcp.h>
+#include <linux/slab.h>
+#include <linux/etherdevice.h>
+#include <asm/io.h>
+#include <linux/sysctl_storlink.h>
+#include <net/tcp.h>
+#include <linux/if_ether.h>
+#include <asm/arch/sl351x_gmac.h>
+#include <asm/arch/sl351x_toe.h>
+#include <asm/arch/sl351x_hash_cfg.h>
+#include <asm/arch/sl351x_nat_cfg.h>
+
+static int in_toe_isr;
+static int toe_initialized=0;
+
+static struct toe_conn	toe_connections[TOE_TOE_QUEUE_NUM];
+EXPORT_SYMBOL(toe_connections);
+static __u32 toe_connection_bits[TOE_TOE_QUEUE_NUM/32] __attribute__ ((aligned(16)));
+struct sk_buff* gen_pure_ack(struct toe_conn* connection, TOE_QHDR_T* toe_qhdr, INTR_QHDR_T *intr_curr_desc);
+
+extern struct storlink_sysctl	storlink_ctl;
+extern TOE_INFO_T toe_private_data;
+extern spinlock_t gmac_fq_lock;
+extern void mac_write_dma_reg(int mac, unsigned int offset, u32 data);
+extern int mac_set_rule_reg(int mac, int rule, int enabled, u32 reg0, u32 reg1, u32 reg2);
+extern int hash_add_toe_entry(HASH_ENTRY_T *entry);
+extern void toe_gmac_fill_free_q(void);
+
+#define _DEBUG_SKB_		1
+#ifdef _DEBUG_SKB_
+/*---------------------------------------------------------------------------
+ * _debug_skb
+ *-------------------------------------------------------------------------*/
+static inline void _debug_skb(struct sk_buff *skb, GMAC_RXDESC_T *toe_curr_desc, u32 data)
+{
+	if ((u32)skb < 0x1000)
+	{
+		printk("%s skb=%x\n", __func__, (u32)skb);
+		while(1);
+	}
+	REG32(__va(toe_curr_desc->word2.buf_adr)-SKB_RESERVE_BYTES) = data;
+}
+#else
+#define _debug_skb(x, y, z)
+#endif
+
+/*---------------------------------------------------------------------------
+ * get_connection_seq_num
+ *-------------------------------------------------------------------------*/
+u32 get_connection_seq_num(unsigned short qid)
+{
+	TOE_QHDR_T	*toe_qhdr;
+
+	toe_qhdr = (TOE_QHDR_T*)TOE_TOE_QUE_HDR_BASE;
+	toe_qhdr += qid;
+	return (u32)toe_qhdr->word3.seq_num;
+}
+EXPORT_SYMBOL(get_connection_seq_num);
+
+/*---------------------------------------------------------------------------
+ * get_connection_ack_num
+ *-------------------------------------------------------------------------*/
+u32 get_connection_ack_num(unsigned short qid)
+{
+	TOE_QHDR_T	*toe_qhdr;
+
+	toe_qhdr = (TOE_QHDR_T*)TOE_TOE_QUE_HDR_BASE;
+	toe_qhdr += qid;
+	return (u32)toe_qhdr->word4.ack_num;
+}
+EXPORT_SYMBOL(get_connection_ack_num);
+
+/*---------------------------------------------------------------------------
+ * dump_toe_qhdr
+ *-------------------------------------------------------------------------*/
+void dump_toe_qhdr(TOE_QHDR_T *toe_qhdr)
+{
+	printk("TOE w1 %x, w2 %x, w3 %x\n", toe_qhdr->word1.bits32,
+		toe_qhdr->word2.bits32, toe_qhdr->word3.bits32);
+	printk("w4 %x, w5 %x, w6 %x\n", toe_qhdr->word4.bits32,
+		toe_qhdr->word5.bits32, toe_qhdr->word6.bits32);
+}
+
+/*---------------------------------------------------------------------------
+ * dump_intrq_desc
+ *-------------------------------------------------------------------------*/
+void dump_intrq_desc(INTR_QHDR_T *intr_curr_desc)
+{
+	printk("INTR w0 %x, w1 %x, seq %x\n", intr_curr_desc->word0.bits32,
+		intr_curr_desc->word1.bits32, intr_curr_desc->word2.bits32);
+	printk("ack %x, w4 %x\n", intr_curr_desc->word3.bits32,
+		intr_curr_desc->word4.bits32);
+}
+
+/*---------------------------------------------------------------------------
+ * This routine will initialize a TOE matching rule
+ * called by SL351x GMAC driver.
+ *-------------------------------------------------------------------------*/
+void sl351x_toe_init(void)
+{
+	GMAC_MRxCR0_T	mrxcr0;
+	GMAC_MRxCR1_T	mrxcr1;
+	GMAC_MRxCR2_T	mrxcr2;
+	int	rule, rc;
+
+	if (toe_initialized)
+		return;
+
+	toe_initialized = 1;
+
+#ifndef CONFIG_SL351x_NAT
+	mrxcr0.bits32 = 0;
+	mrxcr1.bits32 = 0;
+	mrxcr2.bits32 = 0;
+	mrxcr0.bits.l3 = 1;
+	mrxcr0.bits.l4 = 1;
+	mrxcr1.bits.sip = 1;
+	mrxcr1.bits.dip = 1;
+	mrxcr1.bits.l4_byte0_15 = 0x0f;
+	mrxcr0.bits.sprx = 1;
+	rule = 0;
+	rc = mac_set_rule_reg(0, rule, 1, mrxcr0.bits32, mrxcr1.bits32,
+						mrxcr2.bits32);
+	if (rc<0) {
+		printk("%s::Set MAC 0 rule fail!\n", __func__);
+	}
+	rc = mac_set_rule_reg(1, rule, 1, mrxcr0.bits32, mrxcr1.bits32,
+	     					mrxcr2.bits32);
+	if (rc<0) {
+		printk("%s::Set MAC 1 rule fail!\n", __func__);
+	}
+#endif // CONFIG_SL351x_NAT
+}
+
+/*---------------------------------------------------------------------------
+ * dump_intrq_desc
+ * assign an interrupt queue number to a give tcp queue
+ *-------------------------------------------------------------------------*/
+int get_interrupt_queue_id(int tcp_qid)
+{
+	return (int)(tcp_qid & 0x0003);
+}
+
+/*---------------------------------------------------------------------------
+ * reset_connection_index
+ * reset the connection bit by given index
+ *-------------------------------------------------------------------------*/
+void reset_connection_index(__u8 index)
+{
+	__u32 mask = ~(0xffffffff & (1<< (index&0x1f)));
+	toe_connection_bits[index>>5] = toe_connection_bits[index>>5] & mask;
+}
+
+/*---------------------------------------------------------------------------
+ * update_timer
+ *-------------------------------------------------------------------------*/
+void update_timer(struct toe_conn* connection)
+{
+//	if (time_before(jiffies, connection->last_rx_jiffies+3))
+//	if ((jiffies + 0xffffffff - connection->last_rx_jiffies) & 0x3)
+//	if (connection->last_rx_jiffies > jiffies)
+//		printk("%s::jif %g, last_rx_jif %g\n", __func__, jiffies, connection->last_rx_jiffies);
+/*	if ((long)(jiffies + 2)< 3) { // overflow...
+		printk("%s::jiffies %x\n", __func__, jiffies);
+	} */
+//	if ((long)(jiffies - connection->last_rx_jiffies)< 2)
+//		return;
+	connection->last_rx_jiffies = jiffies;
+	// gary chen mod_timer(&connection->rx_timer, jiffies+2);
+	connection->rx_timer.expires = jiffies + 2;
+	add_timer(&connection->rx_timer);
+//	printk("%s::nt %x, lj %x\n", __func__, (jiffies+2), connection->last_rx_jiffies);
+}
+
+/*---------------------------------------------------------------------------
+ * gen_pure_ack
+ *-------------------------------------------------------------------------*/
+struct sk_buff* gen_pure_ack(struct toe_conn* connection, TOE_QHDR_T* toe_qhdr,
+INTR_QHDR_T *intr_curr_desc)
+{
+	struct sk_buff	*skb;
+	struct iphdr	*ip_hdr;
+	struct tcphdr	*tcp_hdr;
+	struct ethhdr	*eth_hdr;
+
+	if ((skb= dev_alloc_skb(RX_BUF_SIZE))==NULL) {
+		printk("%s::alloc pure ack fail!\n", __func__);
+		return NULL;
+	}
+	skb_reserve(skb, RX_INSERT_BYTES);
+	memset(skb->data, 0, 60);
+
+	eth_hdr = (struct ethhdr*)&(skb->data[0]);
+	memcpy(eth_hdr, &connection->l2_hdr, sizeof(struct ethhdr));
+
+	ip_hdr = (struct iphdr*)&(skb->data[14]);
+	ip_hdr->version = connection->ip_ver;
+	ip_hdr->ihl = 20>>2;
+	ip_hdr->tot_len = ntohs(40);
+	ip_hdr->frag_off = htons(IP_DF);
+	ip_hdr->ttl = 128;
+	ip_hdr->protocol = 0x06;
+	ip_hdr->saddr = connection->saddr[0];
+	ip_hdr->daddr = connection->daddr[0];
+//	printk("%s ip sa %x, da %x\n",
+//		__func__, ntohl(ip_hdr->saddr), ntohl(ip_hdr->daddr));
+
+	tcp_hdr = (struct tcphdr*)&(skb->data[34]);
+	tcp_hdr->source = connection->source;
+	tcp_hdr->dest = connection->dest;
+	if (intr_curr_desc) {
+		tcp_hdr->seq = htonl(intr_curr_desc->word2.seq_num);
+		tcp_hdr->ack_seq = htonl(intr_curr_desc->word3.ack_num);
+		tcp_hdr->window = htons(intr_curr_desc->word0.bits.win_size);
+	} else {
+		tcp_hdr->seq = htonl(toe_qhdr->word3.seq_num);
+		tcp_hdr->ack_seq = htonl(toe_qhdr->word4.ack_num);
+		tcp_hdr->window = htons(toe_qhdr->word6.bits.WinSize);
+	}
+	tcp_hdr->ack = 1;
+	tcp_hdr->doff = 20 >> 2;
+#if 0
+	if (!intr_curr_desc) {
+		unsigned char byte;
+		for (i=0; i<20; i++) {
+			byte = skb->data[34+i];
+			printk("%x ", byte);
+		}
+		printk("\n");
+	}
+#endif
+	TCP_SKB_CB(skb)->connection = connection;
+	return skb;
+}
+
+/*---------------------------------------------------------------------------
+ * connection_rx_timer
+ *-------------------------------------------------------------------------*/
+void connection_rx_timer(unsigned long *data)
+{
+	struct toe_conn	*connection = (struct toe_conn*)data;
+	unsigned int	tcp_qid, toeq_wptr;
+	unsigned int	pkt_size, desc_count;
+	struct sk_buff	*skb;
+	GMAC_RXDESC_T	*toe_curr_desc;
+	TOE_QHDR_T	*toe_qhdr;
+	struct net_device	*dev;
+	unsigned long	conn_flags;
+	DMA_RWPTR_T		toeq_rwptr;
+	unsigned short	timeout_descs;
+
+	if (in_toe_isr)
+		printk("%s::in_toe_isr=%d!\n", __func__, in_toe_isr);
+
+	if (connection) {
+		/* should we disable gmac interrupt first? */
+		if (!connection->gmac)
+			printk("%s::conn gmac %x!\n", __func__, (u32)connection->gmac);
+		local_irq_save(conn_flags);
+		if (!spin_trylock(&connection->conn_lock)) {
+			local_irq_restore(conn_flags);
+			// timer should be updated by the toeq isr. So no need to update here.
+			printk("%s::conn_lock is held by ISR!\n", __func__);
+			return;
+		}
+		disable_irq(connection->gmac->irq);
+
+		/* disable hash entry and get toeq desc. */
+		hash_set_valid_flag(connection->hash_entry_index, 0);
+		do{} while(0);	/* wait until HW finish */
+
+		dev = connection->dev;
+		if (!dev)
+			printk("%s::conn dev NULL!\n", __func__);
+		tcp_qid = connection->qid;
+		toe_qhdr = (TOE_QHDR_T *)(TOE_TOE_QUE_HDR_BASE +
+		              tcp_qid * sizeof(TOE_QHDR_T));
+		toeq_rwptr.bits32 = readl(&toe_qhdr->word1);
+		toeq_wptr = toe_qhdr->word1.bits.wptr;
+		timeout_descs = toeq_wptr - toeq_rwptr.bits.rptr;
+
+		if (toeq_rwptr.bits.rptr == toeq_wptr) {
+			if (toe_qhdr->word5.bits32) {
+				// shall we check toe_qhdr->word2.bits?
+				skb = gen_pure_ack(connection, toe_qhdr, (INTR_QHDR_T *)NULL);
+				skb_put(skb, 54);
+				skb->dev = connection->dev;
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+				skb->protocol = eth_type_trans(skb, connection->dev);
+				netif_rx(skb);
+				connection->dev->last_rx = jiffies;
+			}
+		} else {
+			while (toeq_rwptr.bits.rptr != toeq_rwptr.bits.wptr) {
+				/* we just simply send those packets to tcp? */
+				toe_curr_desc = (GMAC_RXDESC_T*)(toe_private_data.toe_desc_base[tcp_qid]
+					+ toeq_rwptr.bits.rptr * sizeof(GMAC_RXDESC_T));
+				connection->curr_desc = toe_curr_desc;
+				if (toe_curr_desc->word3.bits.ctrl_flag) {
+					printk("%s::ctrl flag! %x, conn rptr %d, to %d, jif %x, conn_jif %x\n",
+						__func__, toe_curr_desc->word3.bits32,
+						connection->toeq_rwptr.bits.rptr, timeout_descs,
+						(u32)jiffies, (u32)connection->last_rx_jiffies);
+				}
+				desc_count = toe_curr_desc->word0.bits.desc_count;
+				pkt_size = toe_curr_desc->word1.bits.byte_count;
+				consistent_sync((void*)__va(toe_curr_desc->word2.buf_adr), pkt_size,
+					PCI_DMA_FROMDEVICE);
+				skb = (struct sk_buff*)(REG32(__va(toe_curr_desc->word2.buf_adr)-
+					SKB_RESERVE_BYTES));
+				_debug_skb(skb, (GMAC_RXDESC_T *)toe_curr_desc, 0x02);
+				connection->curr_rx_skb = skb;
+				skb_reserve(skb, RX_INSERT_BYTES);
+				skb_put(skb, pkt_size);
+				skb->dev = dev;
+				skb->protocol = eth_type_trans(skb, dev);
+				{
+					struct iphdr* ip_hdr = (struct iphdr*)&(skb->data[0]);
+					if (toe_curr_desc->word3.bits.ctrl_flag)
+						printk("%s::ip id %x\n", __func__, ntohs(ip_hdr->id));
+				}
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+
+				netif_rx(skb);
+				dev->last_rx = jiffies;
+#if 0
+				if ((skb = dev_alloc_skb(RX_BUF_SIZE)) == NULL) {
+					printk("%s::alloc buf fail!\n", __func__);
+				}
+				*(unsigned int*)(skb->data) = (unsigned int)skb;
+				connection->curr_rx_skb = skb;
+				skb_reserve(skb, SKB_RESERVE_BYTES);
+				spin_lock_irqsave(&connection->gmac->rx_mutex, flags);
+				fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+				if (toe_private_data.fq_rx_rwptr.bits.wptr != fq_rwptr.bits.wptr) {
+					mac_stop_txdma((struct net_device*)connection->dev);
+					spin_unlock_irqrestore(&connection->gmac->rx_mutex, flags);
+					while(1);
+				}
+				fq_desc = (GMAC_RXDESC_T*)toe_private_data.swfq_desc_base + fq_rwptr.bits.wptr;
+				fq_desc->word2.buf_adr = (unsigned int)__pa(skb->data);
+				fq_rwptr.bits.wptr = RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr, TOE_SW_FREEQ_DESC_NUM);
+				SET_WPTR(TOE_GLOBAL_BASE+GLOBAL_SWFQ_RWPTR_REG, fq_rwptr.bits.wptr);
+				toe_private_data.fq_rx_rwptr.bits32 = fq_rwptr.bits32;
+				spin_unlock_irqrestore(&connection->gmac->rx_mutex, flags);
+#endif
+//				spin_lock_irqsave(&connection->gmac->rx_mutex, flags);
+				toeq_rwptr.bits.rptr = RWPTR_ADVANCE_ONE(toeq_rwptr.bits.rptr, TOE_TOE_DESC_NUM);
+				SET_RPTR(&toe_qhdr->word1, toeq_rwptr.bits.rptr);
+//				spin_unlock_irqrestore(&connection->gmac->rx_mutex, flags);
+				connection->toeq_rwptr.bits32 = toeq_rwptr.bits32;
+			}
+			toeq_rwptr.bits32 = readl(&toe_qhdr->word1);
+//			toe_gmac_fill_free_q();
+		}
+		connection->last_rx_jiffies = jiffies;
+		if (connection->status != TCP_CONN_CLOSED)
+			mod_timer(&connection->rx_timer, jiffies+2);
+		if (connection->status != TCP_CONN_ESTABLISHED)
+			printk("%s::conn status %x\n", __func__, connection->status);
+		hash_set_valid_flag(connection->hash_entry_index, 1);
+		enable_irq(connection->gmac->irq);
+		// Gary Chen spin_unlock_irqrestore(&connection->conn_lock, conn_flags);
+	}
+}
+
+/*---------------------------------------------------------------------------
+ * free_toeq_descs
+ *-------------------------------------------------------------------------*/
+void free_toeq_descs(int qid, TOE_INFO_T *toe)
+{
+	void	*desc_ptr;
+
+	desc_ptr = (void*)toe->toe_desc_base[qid];
+	pci_free_consistent(NULL, TOE_TOE_DESC_NUM*sizeof(GMAC_RXDESC_T), desc_ptr,
+	   (dma_addr_t)toe->toe_desc_base_dma[qid]);
+	toe->toe_desc_base[qid] = 0;
+}
+
+/*---------------------------------------------------------------------------
+ * set_toeq_hdr
+ *-------------------------------------------------------------------------*/
+void set_toeq_hdr(struct toe_conn*	connection, TOE_INFO_T* toe, struct net_device *dev)
+{
+	volatile TOE_QHDR_T	*toe_qhdr;
+	volatile unsigned int	toeq_wptr; // toeq_rptr
+	volatile GMAC_RXDESC_T	*toe_curr_desc;
+	struct sk_buff	*skb;
+	unsigned int	pkt_size;
+	DMA_RWPTR_T	toeq_rwptr;
+
+	if (connection->status == TCP_CONN_CLOSING) {
+		connection->status = TCP_CONN_CLOSED;
+		hash_set_valid_flag(connection->hash_entry_index, 0);
+		// remove timer first.
+		// del_timer_sync(&(connection->rx_timer));
+		// check if any queued frames last time.
+		toe_qhdr = (volatile TOE_QHDR_T*)TOE_TOE_QUE_HDR_BASE;
+		toe_qhdr += connection->qid;
+		toeq_rwptr.bits32 = readl(&toe_qhdr->word1);
+
+		//toeq_rptr = toe_qhdr->word1.bits.rptr;
+		toeq_wptr = toe_qhdr->word1.bits.wptr;
+		while (toeq_rwptr.bits.rptr != toeq_wptr) {
+			printk("%s::pending frames in TOE Queue before closing!\n", __func__);
+			toe_curr_desc = (GMAC_RXDESC_T*)(toe->toe_desc_base[connection->qid] +
+				toe_qhdr->word1.bits.rptr*sizeof(GMAC_RXDESC_T));
+			connection->curr_desc = (GMAC_RXDESC_T *)toe_curr_desc;
+			pkt_size = toe_curr_desc->word1.bits.byte_count;
+			consistent_sync((void*)__va(toe_curr_desc->word2.buf_adr), pkt_size,
+				PCI_DMA_FROMDEVICE);
+			skb = (struct sk_buff*)(REG32(__va(toe_curr_desc->word2.buf_adr) -
+				SKB_RESERVE_BYTES));
+			_debug_skb(skb, (GMAC_RXDESC_T *)toe_curr_desc, 0x03);
+			connection->curr_rx_skb = skb;
+			skb_reserve(skb, RX_INSERT_BYTES);
+			skb_put(skb, pkt_size);
+			skb->dev = connection->dev;
+			skb->protocol = eth_type_trans(skb, connection->dev);
+			skb->ip_summed = CHECKSUM_UNNECESSARY;
+			netif_rx(skb);
+			connection->dev->last_rx = jiffies;
+
+			toeq_rwptr.bits.rptr = RWPTR_ADVANCE_ONE(toeq_rwptr.bits.rptr, TOE_TOE_DESC_NUM);
+			SET_RPTR(&toe_qhdr->word1, toeq_rwptr.bits.rptr);
+		}
+		free_toeq_descs(connection->qid, toe);
+		// shall we re-fill free queue?
+
+		reset_connection_index(connection->qid);
+		//memset(connection, 0, sizeof(struct toe_conn));
+		printk(" del timer and close connection %x, qid %d\n", (u32)connection, connection->qid);
+		return;
+	}
+	/* enable or setup toe queue header */
+	if (connection->status == TCP_CONN_CONNECTING && storlink_ctl.rx_max_pktsize) {
+		volatile TOE_QHDR_T	*qhdr;
+		int iq_id;
+		connection->status = TCP_CONN_ESTABLISHED;
+		qhdr = (volatile TOE_QHDR_T*)((unsigned int)TOE_TOE_QUE_HDR_BASE +
+		               connection->qid * sizeof(TOE_QHDR_T));
+
+		iq_id = get_interrupt_queue_id(connection->qid);
+		connection->dev = dev;
+		connection->gmac = dev->priv;
+		connection->toeq_rwptr.bits32 = 0;
+
+//		qhdr->word6.bits.iq_num = iq_id;
+		qhdr->word6.bits.MaxPktSize = (connection->max_pktsize)>>2; // in word.
+		qhdr->word7.bits.AckThreshold = connection->ack_threshold;
+		qhdr->word7.bits.SeqThreshold = connection->seq_threshold;
+
+		// init timer.
+#if 1
+		init_timer(&connection->rx_timer);
+		connection->rx_timer.expires = jiffies + 5;
+		connection->rx_timer.data = (unsigned long)connection;
+		connection->rx_timer.function = (void *)&connection_rx_timer;
+		add_timer(&connection->rx_timer);
+		connection->last_rx_jiffies = jiffies;
+		printk("init_timer %x\n", (u32)jiffies);
+#endif
+		hash_set_valid_flag(connection->hash_entry_index, 1);
+		return;
+	} else {
+		printk("%s::conn status %x, rx_pktsize %d\n",
+			__func__, connection->status, storlink_ctl.rx_max_pktsize);
+	}
+}
+
+/*---------------------------------------------------------------------------
+ * get_connection_index
+ * get_connection_index will find an available index for the connection,
+ * when allocate a new connection is needed.
+ * we find available Qid from AV bits and write to hash_table, so that when RxTOE
+ * packet is received, sw_id from ToeQ descriptor is also the Qid of conneciton Q.
+ *-------------------------------------------------------------------------*/
+int get_connection_index(void)
+{
+	int i=0, j=0, index=-1;
+	__u32	connection_bits;
+
+	for (i = 0; i< TOE_TOE_QUEUE_NUM/32; i++) {
+		connection_bits = ~(toe_connection_bits[i]);
+		if (connection_bits == 0)
+			// all 32 bits are used.
+			continue;
+
+		for (j=0; j<32; j++) {
+			if (connection_bits & 0x01) {
+				index = i*32 + j;
+				return index;
+			}
+			connection_bits = connection_bits >> 1;
+		}
+	}
+	return index;
+}
+
+/*---------------------------------------------------------------------------
+ * set_toe_connection
+ *-------------------------------------------------------------------------*/
+void set_toe_connection(int index, int val)
+{
+	if (val) {
+		toe_connection_bits[index/32] |= (1<<(index%32));
+	} else {
+		toe_connection_bits[index/32] &= (~(1<<(index%32)));
+	}
+}
+
+/*---------------------------------------------------------------------------
+ * sl351x_get_toe_conn_flag
+ *-------------------------------------------------------------------------*/
+int sl351x_get_toe_conn_flag(int index)
+{
+	if (index < TOE_TOE_QUEUE_NUM)
+		return (toe_connection_bits[index/32] & (1 << (index %32)));
+	else
+		return 0;
+}
+
+/*---------------------------------------------------------------------------
+ * sl351x_get_toe_conn_info
+ *-------------------------------------------------------------------------*/
+struct toe_conn * sl351x_get_toe_conn_info(int index)
+{
+	if (index < TOE_TOE_QUEUE_NUM)
+		return (struct toe_conn *)&toe_connections[index];
+	else
+		return NULL;
+}
+
+/*---------------------------------------------------------------------------
+ * create_sw_toe_connection
+ *-------------------------------------------------------------------------*/
+struct toe_conn* create_sw_toe_connection(int qid, int ip_ver, void* ip_hdr,
+	struct tcphdr* tcp_hdr)
+{
+	struct toe_conn*	connection =  &(toe_connections[qid]);
+
+	connection->ip_ver = (__u8)ip_ver;
+	connection->qid = (__u8)qid;
+	connection->source = (__u16)tcp_hdr->source;
+	connection->dest = (__u16)tcp_hdr->dest;
+	if (ip_ver == 4) {
+		struct iphdr* iph = (struct iphdr*) ip_hdr;
+		connection->saddr[0] = (__u32)iph->saddr;
+		connection->daddr[0] = (__u32)iph->daddr;
+//		printk("%s::saddr %x, daddr %x\n", __func__,
+//			ntohl(connection->saddr[0]), ntohl(connection->daddr[0]));
+	} else if (ip_ver == 6) {
+		struct ipv6hdr *iph = (struct ipv6hdr*)ip_hdr;
+		int i=0;
+		for (i=0; i<4; i++) {
+			connection->saddr[i] = (__u32)iph->saddr.in6_u.u6_addr32[i];
+			connection->daddr[i] = (__u32)iph->daddr.in6_u.u6_addr32[i];
+		}
+	}
+	connection->status = TCP_CONN_CREATION;
+	return connection;
+}
+
+/*---------------------------------------------------------------------------
+ * fill_toeq_buf
+ *-------------------------------------------------------------------------*/
+int fill_toeq_buf(int index, TOE_INFO_T* toe)
+{
+	volatile TOE_QHDR_T	*qhdr;
+	//struct toe_conn* connection;
+	GMAC_RXDESC_T	*desc_ptr;
+
+	if (!toe->toe_desc_base[index]) {
+		// first time. init.
+		desc_ptr = (GMAC_RXDESC_T*)(pci_alloc_consistent(NULL, TOE_TOE_DESC_NUM
+		            *sizeof(GMAC_RXDESC_T), (dma_addr_t*)&toe->toe_desc_base_dma[index]));
+
+		toe->toe_desc_num = TOE_TOE_DESC_NUM;
+		toe->toe_desc_base[index] = (unsigned int)desc_ptr;
+	}
+	qhdr = (volatile TOE_QHDR_T*)((unsigned int)TOE_TOE_QUE_HDR_BASE +
+									index*sizeof(TOE_QHDR_T));
+	//connection = (struct toe_conn*)&(toe_connections[index]);
+
+	qhdr->word0.base_size = ((unsigned int)toe->toe_desc_base_dma[index]&TOE_QHDR0_BASE_MASK)
+					| TOE_TOE_DESC_POWER;
+	qhdr->word1.bits32 = 0;
+	qhdr->word2.bits32 = 0;
+	qhdr->word3.bits32 = 0;
+	qhdr->word4.bits32 = 0;
+	qhdr->word5.bits32 = 0;
+	return 1;
+}
+
+/*---------------------------------------------------------------------------
+ * create_toe_hash_entry_smb
+ * add SMB header in hash entry.
+ *-------------------------------------------------------------------------*/
+int create_toe_hash_entry_smb(int ip_ver, void* ip_hdr, struct tcphdr* tcp_hdr,
+	int sw_id)
+{
+	HASH_ENTRY_T	hash_entry, *entry;
+	int	hash_entry_index;
+	int i;
+
+	entry = (HASH_ENTRY_T*)&hash_entry;
+	memset((void*)entry, 0, sizeof(HASH_ENTRY_T));
+	entry->rule = 0;
+
+	/* enable fields of hash key */
+	entry->key_present.ip_protocol = 1;
+	entry->key_present.sip = 1;
+	entry->key_present.dip = 1;
+	entry->key_present.l4_bytes_0_3 = 1;	// src port and dest port
+	entry->key_present.l7_bytes_0_3 = 0;	// do we need to enable NETBIOS? how?
+	entry->key_present.l7_bytes_4_7 = 1;	// "SMB" header
+
+	/* hash key */
+	entry->key.ip_protocol = IPPROTO_TCP;
+	if (ip_ver == 4) {
+		struct iphdr *iph = (struct iphdr*)ip_hdr;
+		memcpy(entry->key.sip, &iph->saddr, 4);
+		memcpy(entry->key.dip, &iph->daddr, 4);
+	} else if (ip_ver == 6) {
+		struct ipv6hdr *iph = (struct ipv6hdr*)ip_hdr;
+		for (i=0; i<4; i++) {
+			memcpy(&(entry->key.sip[i*4]), &(iph->saddr.in6_u.u6_addr32[i]), 4);
+			memcpy(&(entry->key.dip[i*4]), &(iph->daddr.in6_u.u6_addr32[i]), 4);
+		}
+	}
+	*(__u16*)&entry->key.l4_bytes[0] = tcp_hdr->source;
+	*(__u16*)&entry->key.l4_bytes[2] = tcp_hdr->dest;
+
+	entry->key.l7_bytes[4] = 0xff;
+	entry->key.l7_bytes[5] = 0x53;
+	entry->key.l7_bytes[6] = 0x4d;
+	entry->key.l7_bytes[7] = 0x42;
+
+	/* action of hash entry match */
+	entry->action.sw_id = 1;
+	entry->action.dest_qid = (__u8)TOE_TOE_QID(sw_id);
+	entry->action.srce_qid = 0;
+	hash_entry_index = hash_add_toe_entry(entry);
+
+	return hash_entry_index;
+}
+
+// best performance of tcp streaming.
+/*---------------------------------------------------------------------------
+ * create_toe_hash_entry_smb
+ * add SMB header in hash entry.
+ *-------------------------------------------------------------------------*/
+int create_toe_hash_entry_ftp(int ip_ver, void* ip_hdr, struct tcphdr* tcphdr)
+{
+	return 0;
+}
+
+// is hash entry for nfs needed?
+
+/*
+ * Create a TOE hash entry by given ip addresses and tcp port numbers.
+ * hash entry index will be saved in sw connection.
+ */
+/*---------------------------------------------------------------------------
+ * create_toe_hash_entry
+ *-------------------------------------------------------------------------*/
+int create_toe_hash_entry(int ip_ver, void* ip_hdr, struct tcphdr* tcp_hdr, int sw_id)
+{
+	HASH_ENTRY_T	hash_entry, *entry;
+//	unsigned long	hash_key[HASH_MAX_DWORDS];
+	int	hash_entry_index;
+
+	entry = (HASH_ENTRY_T*) &hash_entry;
+	memset((void*)entry, 0, sizeof(HASH_ENTRY_T));
+	entry->rule = 0;
+	/* enable fields of hash key */
+	entry->key_present.ip_protocol = 1;
+	entry->key_present.sip = 1;
+	entry->key_present.dip = 1;
+	entry->key_present.l4_bytes_0_3 = 1;	// src port and dest port
+
+	/* hash key */
+	entry->key.ip_protocol = IPPROTO_TCP;
+	if (ip_ver == 4) {
+		// key of ipv4
+		struct iphdr* iph = (struct iphdr*)ip_hdr;
+		memcpy(entry->key.sip, &iph->saddr, 4);
+		memcpy(entry->key.dip, &iph->daddr, 4);
+	} else if (ip_ver == 6) {
+		// key of ipv6
+		int i=0;
+		struct ipv6hdr *iph = (struct ipv6hdr*)ip_hdr;
+		for (i=0; i<4; i++) {
+			memcpy(&(entry->key.sip[i*4]), &(iph->saddr.in6_u.u6_addr32[i]), 4);
+			memcpy(&(entry->key.dip[i*4]), &(iph->daddr.in6_u.u6_addr32[i]), 4);
+		}
+	}
+	*(__u16*)&entry->key.l4_bytes[0] = tcp_hdr->source;
+	*(__u16*)&entry->key.l4_bytes[2] = tcp_hdr->dest;
+	// is it necessary to write ip version to hash key?
+
+	/* action of hash entry match */
+	entry->action.sw_id = 1;
+	entry->action.dest_qid = (__u8)TOE_TOE_QID(sw_id);
+	entry->action.srce_qid = 0;	// 0 for SW FreeQ. 1 for HW FreeQ.
+	hash_entry_index = hash_add_toe_entry(entry);
+//	printk("\n%s. sw_id %d, hash_entry index %x\n",
+//		__func__, TOE_TOE_QID(sw_id), hash_entry_index);
+	return hash_entry_index;
+}
+
+/*---------------------------------------------------------------------------
+ * init_toeq
+ * 1. Reserve a TOE Queue id first, to get the sw toe_connection.
+ * 2. Setup the hash entry with given iphdr and tcphdr, save hash entry index
+ *    in sw toe_connection.
+ * 3. Prepare sw toe_connection and allocate buffers.
+ * 4. Validate hash entry.
+ *-------------------------------------------------------------------------*/
+struct toe_conn* init_toeq(int ipver, void* iph, struct tcphdr* tcp_hdr,
+	TOE_INFO_T* toe, unsigned char* l2hdr)
+{
+//	printk("\t*** %s, ipver %d\n", __func__, ipver);
+	int qid=-1;
+	struct toe_conn* connection;
+	int hash_entry_index;
+	// int i=0;
+	unsigned short	dest_port = ntohs(tcp_hdr->dest);
+
+	if (dest_port == 445) {
+		printk("%s::SMB/CIFS connection\n", __func__);
+	} else if (dest_port == 20) {
+		printk("%s::ftp-data connection\n", __func__);
+	} else if (dest_port == 2049) {
+		printk("%s::nfs daemon connection\n", __func__);
+	}
+	qid = get_connection_index();
+	if (qid<0)
+		return 0;	// setup toeq failure
+	set_toe_connection(qid, 1); // reserve this sw toeq.
+
+	//connection = (struct toe_conn*)&(toe_connections[qid]);
+	hash_entry_index = create_toe_hash_entry(ipver, iph, tcp_hdr, qid);
+	if (hash_entry_index <0) {
+		printk("%s::release toe hash entry!\n", __func__);
+		set_toe_connection(qid, 0); // release this sw toeq.
+		return 0;
+	}
+	connection = create_sw_toe_connection(qid, ipver, iph, tcp_hdr);
+	connection->hash_entry_index = (__u16) hash_entry_index;
+
+	fill_toeq_buf(qid, toe);
+	memcpy(&connection->l2_hdr, l2hdr, sizeof(struct ethhdr));
+	spin_lock_init(&connection->conn_lock);
+
+	return connection;
+}
+
+#if 0
+/*----------------------------------------------------------------------
+*   toe_init_toe_queue
+*   (1) Initialize the TOE Queue Header
+*       Register: TOE_TOE_QUE_HDR_BASE (0x60003000)
+*   (2) Initialize Descriptors of TOE Queues
+*----------------------------------------------------------------------*/
+void toe_init_toe_queue(TOE_INFO_T* toe)
+{
+}
+EXPORT_SYMBOL(toe_init_toe_queue);
+#endif
+
+/*---------------------------------------------------------------------------
+ * dump_jumbo_skb
+ *-------------------------------------------------------------------------*/
+void dump_jumbo_skb(struct jumbo_frame *jumbo_skb)
+{
+	if (jumbo_skb->skb0) {
+//		printk("%s. jumbo skb %x, len %d\n",
+//			__func__, jumbo_skb->skb0->data, jumbo_skb->skb0->len);
+		netif_rx(jumbo_skb->skb0);
+	}
+	jumbo_skb->skb0 = 0;
+	jumbo_skb->tail = 0;
+	jumbo_skb->iphdr0 = 0;
+	jumbo_skb->tcphdr0 = 0;
+}
+
+/* ---------------------------------------------------------------------
+ * Append skb to skb0. skb0 is the jumbo frame that will be passed to
+ * kernel tcp.
+ * --------------------------------------------------------------------*/
+void rx_append_skb(struct jumbo_frame *jumbo_skb, struct sk_buff* skb, int payload_len)
+{
+	struct iphdr* iphdr0 = (struct iphdr*)&(skb->data[0]);
+	int ip_hdrlen = iphdr0->ihl << 2;
+	struct tcphdr* tcphdr0 = (struct tcphdr*)&(skb->data[ip_hdrlen]);
+
+	if (!jumbo_skb->skb0) {
+		// head of the jumbo frame.
+		jumbo_skb->skb0 = skb;
+		jumbo_skb->tail = 0;
+		jumbo_skb->iphdr0 = iphdr0;
+		jumbo_skb->tcphdr0 = tcphdr0;
+	} else {
+		if (!jumbo_skb->tail)
+			skb_shinfo(jumbo_skb->skb0)->frag_list = skb;
+		else
+			(jumbo_skb->tail)->next = skb;
+		jumbo_skb->tail = skb;
+
+		// do we need to change truesize as well?
+		jumbo_skb->skb0->len += payload_len;
+		jumbo_skb->skb0->data_len += payload_len;
+
+		jumbo_skb->iphdr0->tot_len = htons(ntohs(jumbo_skb->iphdr0->tot_len)+payload_len);
+		jumbo_skb->tcphdr0->ack_seq = tcphdr0->ack_seq;
+		jumbo_skb->tcphdr0->window = tcphdr0->window;
+
+		skb->len += payload_len;
+		skb->data_len = 0;
+		skb->data += ntohs(iphdr0->tot_len) - payload_len;
+	}
+}
+
+/*----------------------------------------------------------------------
+* toe_gmac_handle_toeq
+* (1) read interrupt Queue to get TOE Q.
+* (2) get packet fro TOE Q and send to upper layer handler.
+* (3) allocate new buffers and put to TOE Q. Intr Q buffer is recycled.
+*----------------------------------------------------------------------*/
+void toe_gmac_handle_toeq(struct net_device *dev, GMAC_INFO_T* tp, __u32 status)
+{
+	//volatile INTRQ_INFO_T	*intrq_info;
+	//TOEQ_INFO_T		*toeq_info;
+	volatile NONTOE_QHDR_T	*intr_qhdr;
+	volatile TOE_QHDR_T		*toe_qhdr;
+	volatile INTR_QHDR_T	*intr_curr_desc;
+	TOE_INFO_T	*toe = &toe_private_data;
+
+	volatile GMAC_RXDESC_T	*toe_curr_desc; // , *fq_desc;// *tmp_desc;
+	volatile DMA_RWPTR_T	intr_rwptr, toeq_rwptr;  // fq_rwptr;
+
+	unsigned int 	pkt_size, desc_count, tcp_qid;
+	volatile unsigned int	toeq_wptr;
+	struct toe_conn*		connection;
+	int		i, frag_id = 0;
+	// unsigned long	toeq_flags;
+	struct jumbo_frame	jumbo_skb;
+	struct sk_buff	*skb;
+	__u32	interrupt_status;
+
+	in_toe_isr++;
+
+	interrupt_status = status >> 24;
+	// get interrupt queue header
+	intr_qhdr = (volatile NONTOE_QHDR_T*)TOE_INTR_Q_HDR_BASE;
+	memset(&jumbo_skb, 0, sizeof(struct jumbo_frame));
+
+	for (i=0; i<TOE_INTR_QUEUE_NUM; i++, intr_qhdr++) {
+		if (!(interrupt_status & 0x0001)) {
+			// no interrupt of this IntQ
+			interrupt_status = interrupt_status >> 1;
+			continue;
+		}
+		interrupt_status = interrupt_status >> 1;
+		intr_rwptr.bits32 = readl(&intr_qhdr->word1);
+
+		while ( intr_rwptr.bits.rptr != intr_rwptr.bits.wptr) {
+			int max_pktsize = 1;
+			// get interrupt queue descriptor.
+			intr_curr_desc = (INTR_QHDR_T*)toe->intr_desc_base +
+				i* TOE_INTR_DESC_NUM + intr_rwptr.bits.rptr;
+//			printk("%s::int %x\n", __func__, intr_curr_desc->word1.bits32);
+			// get toeq id
+			tcp_qid = (u8)intr_curr_desc->word1.bits.tcp_qid - (u8)TOE_TOE_QID(0);
+			// get toeq queue header
+			toe_qhdr = (volatile TOE_QHDR_T*) TOE_TOE_QUE_HDR_BASE;
+			toe_qhdr += tcp_qid;
+			connection = &toe_connections[tcp_qid];
+			del_timer(&connection->rx_timer);
+			// Gary Chen spin_lock_irqsave(&connection->conn_lock, toeq_flags);
+			// handling interrupts of this TOE Q.
+			if (intr_curr_desc->word1.bits.ctl || intr_curr_desc->word1.bits.osq ||
+				intr_curr_desc->word1.bits.abn)
+				max_pktsize = 0;
+			if (!max_pktsize || intr_curr_desc->word1.bits.TotalPktSize) {
+				desc_count=0;
+				// wptr in intl queue is where this TOE interrupt should stop.
+				toeq_rwptr.bits32 = readl(&toe_qhdr->word1);
+				toeq_wptr = intr_curr_desc->word0.bits.wptr;
+				if (connection->toeq_rwptr.bits.rptr != toeq_rwptr.bits.rptr)
+					printk("conn rptr %d, hw rptr %d\n",
+						connection->toeq_rwptr.bits.rptr, toeq_rwptr.bits.rptr);
+
+				if (intr_curr_desc->word1.bits.ctl &&
+					(toeq_rwptr.bits.rptr == toeq_wptr)) {
+					printk("\nctrl frame, but not in TOE queue! conn rptr %d, hw wptr %d\n",
+						connection->toeq_rwptr.bits.rptr, toeq_wptr);
+//					dump_toe_qhdr(toe_qhdr);
+//					dump_intrq_desc(intr_curr_desc);
+				}
+				// while (toeq_rwptr.bits.rptr != intr_curr_desc->word0.bits.wptr) {
+				while (toe_qhdr->word1.bits.rptr != intr_curr_desc->word0.bits.wptr) {
+					frag_id++;
+					toe_curr_desc = (volatile GMAC_RXDESC_T *)(toe->toe_desc_base[tcp_qid]
+						+ toe_qhdr->word1.bits.rptr *sizeof(GMAC_RXDESC_T));
+					connection->curr_desc = (GMAC_RXDESC_T *)toe_curr_desc;
+					desc_count = toe_curr_desc->word0.bits.desc_count;
+					pkt_size = toe_curr_desc->word1.bits.byte_count;
+					consistent_sync((void*)__va(toe_curr_desc->word2.buf_adr), pkt_size,
+						PCI_DMA_FROMDEVICE);
+					skb = (struct sk_buff*)(REG32(__va(toe_curr_desc->word2.buf_adr)-
+						SKB_RESERVE_BYTES));
+					_debug_skb(skb, (GMAC_RXDESC_T *)toe_curr_desc, 0x01);
+					connection->curr_rx_skb = skb;
+					skb_reserve(skb, RX_INSERT_BYTES);
+					if ((skb->len + pkt_size) > (1514+16))
+					{
+						printk("skb->len=%d, pkt_size=%d\n",skb->len, pkt_size);
+						while(1);
+					}
+
+					skb_put(skb, pkt_size);
+					skb->dev = dev;
+					skb->protocol = eth_type_trans(skb, dev);
+					skb->ip_summed = CHECKSUM_UNNECESSARY;
+
+					if (toe_curr_desc->word3.bits32 & 0x1b000000)
+						dump_jumbo_skb(&jumbo_skb);
+
+					rx_append_skb(&jumbo_skb, skb, pkt_size-toe_curr_desc->word3.bits.l7_offset);
+//					spin_lock_irqsave(&gmac_fq_lock, flags);
+					toeq_rwptr.bits.rptr = RWPTR_ADVANCE_ONE(toeq_rwptr.bits.rptr, TOE_TOE_DESC_NUM);
+					SET_RPTR(&toe_qhdr->word1, toeq_rwptr.bits.rptr);
+//					spin_unlock_irqrestore(&gmac_fq_lock, flags);
+					if (storlink_ctl.fqint_threshold)
+						continue;
+#if 0
+//#if (HANDLE_FREEQ_METHOD == HANDLE_FREEQ_INDIVIDUAL)
+					if ((skb = dev_alloc_skb(RX_BUF_SIZE)) == NULL) {
+						printk("%s::toe queue alloc buffer ", __func__);
+					}
+					*(unsigned int*)(skb->data) = (unsigned int)skb;
+					connection->curr_rx_skb = skb;
+					skb_reserve(skb, SKB_RESERVE_BYTES);
+
+					spin_lock_irqsave(&gmac_fq_lock, flags);
+					fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+					if (toe->fq_rx_rwptr.bits.wptr != fq_rwptr.bits.wptr) {
+						printk("%s::fq_rx_rwptr %x\n", __func__, toe->fq_rx_rwptr.bits32);
+						mac_stop_txdma((struct net_device*) tp->dev);
+						spin_unlock_irqrestore(&gmac_fq_lock, flags);
+						while(1);
+					}
+					fq_desc = (GMAC_RXDESC_T*)toe->swfq_desc_base + fq_rwptr.bits.wptr;
+					fq_desc->word2.buf_adr = (unsigned int)__pa(skb->data);
+
+					fq_rwptr.bits.wptr = RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr, TOE_SW_FREEQ_DESC_NUM);
+					SET_WPTR(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG, fq_rwptr.bits.wptr);
+					toe->fq_rx_rwptr.bits32 = fq_rwptr.bits32;
+					spin_unlock_irqrestore(&gmac_fq_lock, flags);
+#endif
+				} // end of this multi-desc.
+				dump_jumbo_skb(&jumbo_skb);
+				dev->last_rx = jiffies;
+				connection->toeq_rwptr.bits32 = toeq_rwptr.bits32;
+			} else if (intr_curr_desc->word1.bits.sat) {
+				toeq_rwptr.bits32 = readl(&toe_qhdr->word1);
+				toeq_wptr = intr_curr_desc->word0.bits.wptr;
+				if (connection->toeq_rwptr.bits.rptr != toeq_rwptr.bits.rptr)
+					printk("SAT. conn rptr %d, hw rptr %d\n",
+						connection->toeq_rwptr.bits.rptr, toeq_rwptr.bits.rptr);
+/*
+					printk("%s::SAT int!, ackcnt %x, seqcnt %x, rptr %d, wptr %d, ack %x, qhack %x\n",
+ 						__func__, intr_curr_desc->word4.bits.AckCnt, intr_curr_desc->word4.bits.SeqCnt,
+						toeq_rptr, toeq_wptr, intr_curr_desc->word3.ack_num, toe_qhdr->word4.ack_num);*/
+				/* pure ack */
+				if (toeq_rwptr.bits.rptr == toeq_wptr) {
+					if (intr_curr_desc->word4.bits32) {
+						skb = gen_pure_ack(connection, (TOE_QHDR_T *)toe_qhdr, (INTR_QHDR_T *)intr_curr_desc);
+						skb_put(skb, 60);
+						skb->dev = connection->dev;
+						skb->ip_summed = CHECKSUM_UNNECESSARY;
+						skb->protocol = eth_type_trans(skb, connection->dev);
+						netif_rx(skb);
+					} else
+						printk("%s::SAT Interrupt!. But cnt is 0!\n", __func__);
+				} else {
+					// while (toeq_rwptr.bits.rptr != toeq_wptr) {
+					while (toe_qhdr->word1.bits.rptr != intr_curr_desc->word0.bits.wptr) {
+						toe_curr_desc = (volatile GMAC_RXDESC_T*)(toe->toe_desc_base[tcp_qid]
+							+ toe_qhdr->word1.bits.rptr * sizeof(GMAC_RXDESC_T));
+						connection->curr_desc = (GMAC_RXDESC_T *)toe_curr_desc;
+						desc_count = toe_curr_desc->word0.bits.desc_count;
+						pkt_size = toe_curr_desc->word1.bits.byte_count;
+						consistent_sync((void*)__va(toe_curr_desc->word2.buf_adr), pkt_size,
+							PCI_DMA_FROMDEVICE);
+						// if ( ((toeq_rwptr.bits.rptr +1)&(TOE_TOE_DESC_NUM-1)) == toeq_wptr) {
+						if ( RWPTR_ADVANCE_ONE(toe_qhdr->word1.bits.rptr, TOE_TOE_DESC_NUM) == toeq_wptr) {
+							skb = (struct sk_buff*)(REG32(__va(toe_curr_desc->word2.buf_adr) -
+								SKB_RESERVE_BYTES));
+							_debug_skb(skb, (GMAC_RXDESC_T *)toe_curr_desc, 0x04);
+							connection->curr_rx_skb = skb;
+							skb_reserve(skb, RX_INSERT_BYTES);
+							skb_put(skb, pkt_size);
+							skb->dev = dev;
+							skb->protocol = eth_type_trans(skb, dev);
+							skb->ip_summed = CHECKSUM_UNNECESSARY;
+							// printk("toeq_rptr %d, wptr %d\n", toeq_rptr, toeq_wptr);
+							netif_rx(skb);
+							dev->last_rx = jiffies;
+/*
+							if ((skb = dev_alloc_skb(RX_BUF_SIZE)) == NULL) {
+
+							}
+							*(unsigned int*)(skb->data) = (unsigned int) skb;
+							skb_reserve(skb, SKB_RESERVE_BYTES); */
+						} else {
+							// reuse this skb, append to free queue..
+							skb = (struct sk_buff*)(REG32(__va(toe_curr_desc->word2.buf_adr)-
+								SKB_RESERVE_BYTES));
+							_debug_skb(skb, (GMAC_RXDESC_T *)toe_curr_desc, 0x05);
+							connection->curr_rx_skb = skb;
+							dev_kfree_skb_irq(skb);
+						}
+#if 0
+						spin_lock_irqsave(&gmac_fq_lock, flags);
+						fq_rwptr.bits32 = readl(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG);
+/*						if (toe->fq_rx_rwptr.bits.wptr != fq_rwptr.bits.wptr) {
+							printk("%s::fq_rx_rwptr %x\n", __func__, toe->fq_rx_rwptr.bits32);
+							mac_stop_txdma((struct net_device*) tp->dev);
+							spin_unlock_irqrestore(&gmac_fq_lock, flags);
+							while(1);
+						} */
+						fq_desc = (GMAC_RXDESC_T*)toe->swfq_desc_base + fq_rwptr.bits.wptr;
+						fq_desc->word2.buf_adr = (unsigned int)__pa(skb->data);
+
+						fq_rwptr.bits.wptr = RWPTR_ADVANCE_ONE(fq_rwptr.bits.wptr, TOE_SW_FREEQ_DESC_NUM);
+						SET_WPTR(TOE_GLOBAL_BASE + GLOBAL_SWFQ_RWPTR_REG, fq_rwptr.bits.wptr);
+						toe->fq_rx_rwptr.bits32 = fq_rwptr.bits32;
+	//					spin_unlock_irqrestore(&gmac_fq_lock, flags);
+#endif
+//						spin_lock_irqsave(&gmac_fq_lock, flags);
+						toeq_rwptr.bits.rptr = RWPTR_ADVANCE_ONE(toeq_rwptr.bits.rptr, TOE_TOE_DESC_NUM);
+						SET_RPTR(&toe_qhdr->word1, toeq_rwptr.bits.rptr);
+//						spin_unlock_irqrestore(&gmac_fq_lock, flags);
+					}
+				} // end of ACK with options.
+				connection->toeq_rwptr.bits32 = toeq_rwptr.bits32;
+				// Gary Chen spin_unlock_irqrestore(&connection->conn_lock, toeq_flags);
+//				}
+			};
+			update_timer(connection);
+			// any protection against interrupt queue header?
+			intr_rwptr.bits.rptr = RWPTR_ADVANCE_ONE(intr_rwptr.bits.rptr, TOE_INTR_DESC_NUM);
+			SET_RPTR(&intr_qhdr->word1, intr_rwptr.bits.rptr);
+			intr_rwptr.bits32 = readl(&intr_qhdr->word1);
+			toe_gmac_fill_free_q();
+		} // end of this interrupt Queue processing.
+	} // end of all interrupt Queues.
+
+	in_toe_isr = 0;
+}
+
+
--- /dev/null
+++ b/drivers/net/sl_lepus_hash.c
@@ -0,0 +1,553 @@
+/**************************************************************************
+* Copyright 2006 StorLink Semiconductors, Inc.  All rights reserved.
+*--------------------------------------------------------------------------
+* Name			: sl_lepus_hash.c
+* Description	:
+*		Handle Storlink Lepus Hash Functions
+*
+* History
+*
+*	Date		Writer		Description
+*----------------------------------------------------------------------------
+*	03/13/2006	Gary Chen	Create and implement
+*
+****************************************************************************/
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/compiler.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
+#include <linux/delay.h>
+#include <linux/ethtool.h>
+#include <linux/mii.h>
+#include <linux/completion.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/semaphore.h>
+#include <asm/arch/irqs.h>
+#include <asm/arch/it8712.h>
+#include <linux/mtd/kvctl.h>
+#include <linux/skbuff.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/list.h>
+#define	 MIDWAY
+#define	 SL_LEPUS
+
+#include <asm/arch/sl2312.h>
+#include <asm/arch/sl_lepus_gmac.h>
+#include <asm/arch/sl_hash_cfg.h>
+
+#ifndef RXTOE_DEBUG
+#define RXTOE_DEBUG
+#endif
+#undef RXTOE_DEBUG
+
+/*----------------------------------------------------------------------
+* Definition
+*----------------------------------------------------------------------*/
+#define	hash_printf				printk
+
+#define HASH_TIMER_PERIOD		(60*HZ)	// seconds
+#define HASH_ILLEGAL_INDEX		0xffff
+
+/*----------------------------------------------------------------------
+* Variables
+*----------------------------------------------------------------------*/
+u32					hash_activate_bits[HASH_TOTAL_ENTRIES/32];
+u32					hash_nat_owner_bits[HASH_TOTAL_ENTRIES/32];
+char 				hash_tables[HASH_TOTAL_ENTRIES][HASH_MAX_BYTES] __attribute__ ((aligned(16)));
+static struct timer_list hash_timer_obj;
+LIST_HEAD(hash_timeout_list);
+
+/*----------------------------------------------------------------------
+* Functions
+*----------------------------------------------------------------------*/
+void dm_long(u32 location, int length);
+static void hash_timer_func(u32 data);
+
+/*----------------------------------------------------------------------
+* hash_init
+*----------------------------------------------------------------------*/
+void hash_init(void)
+{
+	int i;
+	volatile u32 *dp1, *dp2, dword;
+
+	dp1 = (volatile u32 *) TOE_V_BIT_BASE;
+	dp2 = (volatile u32 *) TOE_A_BIT_BASE;
+
+	for (i=0; i<HASH_TOTAL_ENTRIES/32; i++)
+	{
+		*dp1++ = 0;
+		dword = *dp2++;	// read-clear
+	}
+	memset((void *)&hash_nat_owner_bits, 0, sizeof(hash_nat_owner_bits));
+	memset((void *)&hash_tables, 0, sizeof(hash_tables));
+
+	init_timer(&hash_timer_obj);
+	hash_timer_obj.expires = jiffies + HASH_TIMER_PERIOD;
+	hash_timer_obj.data = (unsigned long)&hash_timer_obj;
+	hash_timer_obj.function = (void *)&hash_timer_func;
+	add_timer(&hash_timer_obj);
+
+#if (HASH_MAX_BYTES == 128)
+	writel((unsigned long)__pa(&hash_tables) | 3,	// 32 words
+			TOE_GLOBAL_BASE + GLOBAL_HASH_TABLE_BASE_REG);
+#elif (HASH_MAX_BYTES == 64)
+	writel((unsigned long)__pa(&hash_tables) | 2,	// 16 words
+			TOE_GLOBAL_BASE + GLOBAL_HASH_TABLE_BASE_REG);
+#else
+	#error Incorrect setting for HASH_MAX_BYTES
+#endif
+
+}
+/*----------------------------------------------------------------------
+* hash_add_entry
+*----------------------------------------------------------------------*/
+int hash_add_entry(HASH_ENTRY_T *entry)
+{
+	int	rc;
+	u32	key[HASH_MAX_DWORDS];
+	rc = hash_build_keys((u32 *)&key, entry);
+	if (rc < 0)
+		return -1;
+	hash_write_entry(entry, (unsigned char*) &key[0]);
+//	hash_set_valid_flag(entry->index, 1);
+//	printk("Dump hash key!\n");
+//	dump_hash_key(entry);
+	return entry->index;
+}
+
+/*----------------------------------------------------------------------
+* hash_set_valid_flag
+*----------------------------------------------------------------------*/
+void hash_set_valid_flag(int index, int valid)
+{
+	register u32 reg32;
+
+	reg32 = TOE_V_BIT_BASE + (index/32) * 4;
+
+	if (valid)
+	{
+		writel(readl(reg32) | (1 << (index%32)), reg32);
+	}
+	else
+	{
+		writel(readl(reg32) & ~(1 << (index%32)), reg32);
+	}
+}
+
+/*----------------------------------------------------------------------
+* hash_set_nat_owner_flag
+*----------------------------------------------------------------------*/
+void hash_set_nat_owner_flag(int index, int valid)
+{
+	if (valid)
+	{
+		hash_nat_owner_bits[index/32] |= (1 << (index % 32));
+	}
+	else
+	{
+		hash_nat_owner_bits[index/32] &= ~(1 << (index % 32));
+	}
+}
+
+
+/*----------------------------------------------------------------------
+* hash_build_keys
+*----------------------------------------------------------------------*/
+int hash_build_keys(u32 *destp, HASH_ENTRY_T *entry)
+{
+	u32 	data;
+	unsigned char 	*cp;
+	int				i, j;
+	unsigned short 	index;
+	int 			total;
+
+	memset((void *)destp, 0, HASH_MAX_BYTES);
+	cp = (unsigned char *)destp;
+
+	if (entry->key_present.port || entry->key_present.Ethertype)
+	{
+		HASH_PUSH_WORD(cp, entry->key.Ethertype);		// word 0
+		HASH_PUSH_BYTE(cp, entry->key.port);			// Byte 2
+		HASH_PUSH_BYTE(cp, 0);							// Byte 3
+	}
+	else
+	{
+		HASH_PUSH_DWORD(cp, 0);
+	}
+
+	if (entry->key_present.da || entry->key_present.sa)
+	{
+		unsigned char mac[4];
+		if (entry->key_present.da)
+		{
+			for (i=0; i<4; i++)
+				HASH_PUSH_BYTE(cp, entry->key.da[i]);
+		}
+		mac[0] = (entry->key_present.da) ? entry->key.da[4] : 0;
+		mac[1] = (entry->key_present.da) ? entry->key.da[5] : 0;
+		mac[2] = (entry->key_present.sa) ? entry->key.sa[0] : 0;
+		mac[3] = (entry->key_present.sa) ? entry->key.sa[1] : 0;
+		data = mac[0] + (mac[1]<<8) + (mac[2]<<16) + (mac[3]<<24);
+		HASH_PUSH_DWORD(cp, data);
+		if (entry->key_present.sa)
+		{
+			for (i=2; i<6; i++)
+				HASH_PUSH_BYTE(cp, entry->key.sa[i]);
+		}
+	}
+
+	if (entry->key_present.pppoe_sid || entry->key_present.vlan_id)
+	{
+		HASH_PUSH_WORD(cp, entry->key.vlan_id);		// low word
+		HASH_PUSH_WORD(cp, entry->key.pppoe_sid);	// high word
+	}
+	if (entry->key_present.ipv4_hdrlen || entry->key_present.ip_tos || entry->key_present.ip_protocol)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.ip_protocol);		// Byte 0
+		HASH_PUSH_BYTE(cp, entry->key.ip_tos);			// Byte 1
+		HASH_PUSH_BYTE(cp, entry->key.ipv4_hdrlen);		// Byte 2
+		HASH_PUSH_BYTE(cp, 0);							// Byte 3
+	}
+
+	if (entry->key_present.ipv6_flow_label)
+	{
+		HASH_PUSH_DWORD(cp, entry->key.ipv6_flow_label);	// low word
+	}
+	if (entry->key_present.sip)
+	{
+		// input (entry->key.sip[i]) is network-oriented
+		// output (hash key) is host-oriented
+		for (i=3; i>=0; i--)
+			HASH_PUSH_BYTE(cp, entry->key.sip[i]);
+		if (entry->key.ipv6)
+		{
+			for (i=4; i<16; i+=4)
+			{
+				for (j=i+3; j>=i; j--)
+					HASH_PUSH_BYTE(cp, entry->key.sip[j]);
+			}
+		}
+	}
+	if (entry->key_present.dip)
+	{
+		// input (entry->key.sip[i]) is network-oriented
+		// output (hash key) is host-oriented
+		for (i=3; i>=0; i--)
+			HASH_PUSH_BYTE(cp, entry->key.dip[i]);
+		if (entry->key.ipv6)
+		{
+			for (i=4; i<16; i+=4)
+			{
+				for (j=i+3; j>=i; j--)
+					HASH_PUSH_BYTE(cp, entry->key.dip[j]);
+			}
+		}
+	}
+
+	if (entry->key_present.l4_bytes_0_3)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[0]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[1]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[2]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[3]);
+	}
+	if (entry->key_present.l4_bytes_4_7)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[4]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[5]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[6]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[7]);
+	}
+	if (entry->key_present.l4_bytes_8_11)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[8]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[9]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[10]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[11]);
+	}
+	if (entry->key_present.l4_bytes_12_15)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[12]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[13]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[14]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[15]);
+	}
+	if (entry->key_present.l4_bytes_16_19)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[16]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[17]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[18]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[19]);
+	}
+	if (entry->key_present.l4_bytes_20_23)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[20]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[21]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[22]);
+		HASH_PUSH_BYTE(cp, entry->key.l4_bytes[23]);
+	}
+	if (entry->key_present.l7_bytes_0_3)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[0]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[1]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[2]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[3]);
+	}
+	if (entry->key_present.l7_bytes_4_7)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[4]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[5]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[6]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[7]);
+	}
+	if (entry->key_present.l7_bytes_8_11)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[8]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[9]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[10]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[11]);
+	}
+	if (entry->key_present.l7_bytes_12_15)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[12]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[13]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[14]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[15]);
+	}
+	if (entry->key_present.l7_bytes_16_19)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[16]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[17]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[18]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[19]);
+	}
+	if (entry->key_present.l7_bytes_20_23)
+	{
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[20]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[21]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[22]);
+		HASH_PUSH_BYTE(cp, entry->key.l7_bytes[23]);
+	}
+
+	// get hash index
+	total = (u32)((u32)cp - (u32)destp) / (sizeof(u32));
+
+	if (total > HASH_MAX_KEY_DWORD)
+	{
+		//hash_printf("Total key words (%d) is too large (> %d)!\n",
+		//				total, HASH_MAX_KEY_DWORD);
+		return -1;
+	}
+
+	if (entry->key_present.port || entry->key_present.Ethertype)
+		index = hash_gen_crc16((unsigned char *)destp, total * 4);
+	else
+	{
+		if (total == 1)
+		{
+			hash_printf("No key is assigned!\n");
+			return -1;
+		}
+
+		index = hash_gen_crc16((unsigned char *)(destp+1), (total-1) * 4);
+	}
+
+	entry->index = index & HASH_BITS_MASK;
+
+	//hash_printf("Total key words = %d, Hash Index= %d\n",
+	//				total, entry->index);
+
+	cp = (unsigned char *)destp;
+	cp+=3;
+	HASH_PUSH_BYTE(cp, entry->rule);	// rule
+
+	entry->total_dwords = total;
+
+	return total;
+}
+
+/*----------------------------------------------------------------------
+* hash_build_nat_keys
+*----------------------------------------------------------------------*/
+void hash_build_nat_keys(u32 *destp, HASH_ENTRY_T *entry)
+{
+	unsigned char 	*cp;
+	int				i;
+	unsigned short 	index;
+	int 			total;
+
+	memset((void *)destp, 0, HASH_MAX_BYTES);
+
+	cp = (unsigned char *)destp + 2;
+	HASH_PUSH_BYTE(cp, entry->key.port);
+	cp++;
+
+	if (entry->key_present.pppoe_sid || entry->key_present.vlan_id)
+	{
+		HASH_PUSH_WORD(cp, entry->key.vlan_id);		// low word
+		HASH_PUSH_WORD(cp, entry->key.pppoe_sid);	// high word
+	}
+
+	HASH_PUSH_BYTE(cp, entry->key.ip_protocol);
+	cp+=3;
+
+	// input (entry->key.sip[i]) is network-oriented
+	// output (hash key) is host-oriented
+	for (i=3; i>=0; i--)
+		HASH_PUSH_BYTE(cp, entry->key.sip[i]);
+
+	// input (entry->key.sip[i]) is network-oriented
+	// output (hash key) is host-oriented
+	for (i=3; i>=0; i--)
+		HASH_PUSH_BYTE(cp, entry->key.dip[i]);
+
+	HASH_PUSH_BYTE(cp, entry->key.l4_bytes[0]);
+	HASH_PUSH_BYTE(cp, entry->key.l4_bytes[1]);
+	HASH_PUSH_BYTE(cp, entry->key.l4_bytes[2]);
+	HASH_PUSH_BYTE(cp, entry->key.l4_bytes[3]);
+
+	// get hash index
+	total = (u32)((u32)cp - (u32)destp) / (sizeof(u32));
+
+	index = hash_gen_crc16((unsigned char *)destp, total * 4);
+	entry->index = index & ((1 << HASH_BITS) - 1);
+
+	cp = (unsigned char *)destp;
+	cp+=3;
+	HASH_PUSH_BYTE(cp, entry->rule);	// rule
+
+	entry->total_dwords = total;
+}
+
+
+/*----------------------------------------------------------------------
+* hash_write_entry
+*----------------------------------------------------------------------*/
+int hash_write_entry(HASH_ENTRY_T *entry, unsigned char *key)
+{
+	int		i;
+	u32		*srcep, *destp, *destp2;
+
+	srcep = (u32 *)key;
+	destp2 = destp = (u32 *)&hash_tables[entry->index][0];
+
+	for (i=0; i<(entry->total_dwords); i++, srcep++, destp++)
+		*destp = *srcep;
+
+	srcep = (u32 *)&entry->action;
+	*destp++ = *srcep;
+
+	srcep = (u32 *)&entry->param;
+	for (i=0; i<(sizeof(ENTRY_PARAM_T)/sizeof(*destp)); i++, srcep++, destp++)
+		*destp = *srcep;
+
+	memset(destp, 0, (HASH_MAX_DWORDS-entry->total_dwords-HASH_ACTION_DWORDS) * sizeof(u32));
+
+	consistent_sync(destp2, (entry->total_dwords+HASH_ACTION_DWORDS) * 4, PCI_DMA_TODEVICE);
+	return 0;
+}
+
+/*----------------------------------------------------------------------
+* hash_timer_func
+*----------------------------------------------------------------------*/
+static void hash_timer_func(u32 data)
+{
+	int				i, j;
+	volatile u32	*active_p, *own_p, *valid_p;
+	u32				a_bits, own_bits;
+
+	valid_p = (volatile u32 *)TOE_V_BIT_BASE;
+	active_p = (volatile u32 *)hash_activate_bits;
+	own_p = (volatile u32 *)hash_nat_owner_bits;
+	for (i=0; i<(HASH_TOTAL_ENTRIES/32); i++, own_p++, active_p++, valid_p++)
+	{
+		*active_p |= readl(TOE_A_BIT_BASE + (i*4));
+		a_bits = *active_p;
+		own_bits = *own_p;
+		if (own_bits)
+		{
+#ifndef DEBUG_NAT_MIXED_HW_SW_TX
+			a_bits = own_bits & ~a_bits;
+#else
+			a_bits = own_bits & a_bits;
+#endif
+			for (j=0; a_bits && j<32; j++)
+			{
+				if (a_bits & 1)
+				{
+					*valid_p &= ~(1 << j);		// invalidate it
+#if !(defined(NAT_DEBUG_LAN_HASH_TIMEOUT) || defined(NAT_DEBUG_WAN_HASH_TIMEOUT))
+					*own_p &= ~(1 << j);		// release ownership for NAT
+#endif
+// #ifdef DEBUG_NAT_MIXED_HW_SW_TX
+#if 0
+					hash_printf("%lu %s: Clear hash index: %d\n", jiffies/HZ, __func__, i*32+j);
+#endif
+				}
+				a_bits >>= 1;
+			}
+			*active_p &= ~own_bits;		// deactivate it for next polling
+		}
+	}
+
+	hash_timer_obj.expires = jiffies + HASH_TIMER_PERIOD;
+	add_timer((struct timer_list *)data);
+}
+
+/*----------------------------------------------------------------------
+* dm_long
+*----------------------------------------------------------------------*/
+void dm_long(u32 location, int length)
+{
+	u32		*start_p, *curr_p, *end_p;
+	u32		*datap, data;
+	int		i;
+
+	//if (length > 1024)
+	//	length = 1024;
+
+	start_p = (u32 *)location;
+	end_p = (u32 *)location + length;
+	curr_p = (u32 *)((u32)location & 0xfffffff0);
+	datap = (u32 *)location;
+	while (curr_p < end_p)
+	{
+		hash_printf("0x%08x: ",(u32)curr_p & 0xfffffff0);
+		for (i=0; i<4; i++)
+		{
+			if (curr_p < start_p || curr_p >= end_p)
+               hash_printf("         ");
+			else
+			{
+				data = *datap;
+				hash_printf("%08X ", data);
+			}
+			if (i==1)
+              hash_printf("- ");
+
+			curr_p++;
+			datap++;
+		}
+        hash_printf("\n");
+	}
+}
+
+/*----------------------------------------------------------------------
+* hash_dump_entry
+*----------------------------------------------------------------------*/
+void hash_dump_entry(int index)
+{
+	hash_printf("Hash Index %d:\n", index);
+	dm_long((u32)&hash_tables[index][0], HASH_MAX_DWORDS);
+}
+
+
--- /dev/null
+++ b/drivers/net/sl_switch.c
@@ -0,0 +1,650 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+
+#define GMAC_GLOBAL_BASE_ADDR       (IO_ADDRESS(SL2312_GLOBAL_BASE))
+#define GPIO_BASE_ADDR1  (IO_ADDRESS(SL2312_GPIO_BASE1))
+enum GPIO_REG
+{
+    GPIO_DATA_OUT   = 0x00,
+    GPIO_DATA_IN    = 0x04,
+    GPIO_PIN_DIR    = 0x08,
+    GPIO_BY_PASS    = 0x0c,
+    GPIO_DATA_SET   = 0x10,
+    GPIO_DATA_CLEAR = 0x14,
+};
+
+#define GMAC_SPEED_10			0
+#define GMAC_SPEED_100			1
+#define GMAC_SPEED_1000			2
+
+enum phy_state
+{
+    LINK_DOWN   = 0,
+    LINK_UP     = 1
+};
+
+#ifndef BIT
+#define BIT(x)						(1 << (x))
+#endif
+
+//int Get_Set_port_status();
+unsigned int SPI_read_bit(void);
+void SPI_write_bit(char bit_EEDO);
+void SPI_write(unsigned char block,unsigned char subblock,unsigned char addr,unsigned int value);
+unsigned int SPI_read(unsigned char block,unsigned char subblock,unsigned char addr);
+int SPI_default(void);
+void SPI_CS_enable(unsigned char enable);
+unsigned int SPI_get_identifier(void);
+void phy_write(unsigned char port_no,unsigned char reg,unsigned int val);
+unsigned int phy_read(unsigned char port_no,unsigned char reg);
+void phy_write_masked(unsigned char port_no,unsigned char reg,unsigned int val,unsigned int mask);
+void init_seq_7385(unsigned char port_no) ;
+void phy_receiver_init (unsigned char port_no);
+
+#define PORT_NO		4
+int switch_pre_speed[PORT_NO]={0,0,0,0};
+int switch_pre_link[PORT_NO]={0,0,0,0};
+
+
+
+
+
+/*				NOTES
+ *   The Protocol of the SPI are as follows:
+ *
+ *     		   Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
+ *	byte0     |   Block id  | r/w | sub-block        |
+ *	byte1     |		Address			 |
+ *	byte2	  |		Data			 |
+ *	byte3	  |		Data			 |
+ *	byte4	  |		Data			 |
+ *	byte5	  |		Data			 |
+ */
+
+
+
+
+/***************************************/
+/* define GPIO module base address     */
+/***************************************/
+#define GPIO_EECS	     0x80000000		/*   EECS: GPIO[22]   */
+#define GPIO_MOSI	     0x20000000         /*   EEDO: GPIO[29]   send to 6996*/
+#define GPIO_MISO	     0x40000000         /*   EEDI: GPIO[30]   receive from 6996*/
+#define GPIO_EECK	     0x10000000         /*   EECK: GPIO[31]   */
+
+/*************************************************************
+* SPI protocol for ADM6996 control
+**************************************************************/
+#define SPI_OP_LEN	     0x08		// the length of start bit and opcode
+#define SPI_OPWRITE	     0X05		// write
+#define SPI_OPREAD	     0X06		// read
+#define SPI_OPERASE	     0X07		// erase
+#define SPI_OPWTEN	     0X04		// write enable
+#define SPI_OPWTDIS	     0X04		// write disable
+#define SPI_OPERSALL	     0X04		// erase all
+#define SPI_OPWTALL	     0X04		// write all
+
+#define SPI_ADD_LEN	     8			// bits of Address
+#define SPI_DAT_LEN	     32			// bits of Data
+
+
+/****************************************/
+/*	Function Declare		*/
+/****************************************/
+
+//unsigned int SPI_read_bit(void);
+//void SPI_write_bit(char bit_EEDO);
+//unsigned int SPI_read_bit(void);
+/******************************************
+* SPI_write
+* addr -> Write Address
+* value -> value to be write
+***************************************** */
+void phy_receiver_init (unsigned char port_no)
+{
+    phy_write(port_no,31,0x2a30);
+    phy_write_masked(port_no, 12, 0x0200, 0x0300);
+    phy_write(port_no,31,0);
+}
+
+void phy_write(unsigned char port_no,unsigned char reg,unsigned int val)
+{
+	unsigned int cmd;
+
+	cmd = (port_no<<21)|(reg<<16)|val;
+	SPI_write(3,0,1,cmd);
+}
+
+unsigned int phy_read(unsigned char port_no,unsigned char reg)
+{
+	unsigned int cmd,reg_val;
+
+	cmd = BIT(26)|(port_no<<21)|(reg<<16);
+	SPI_write(3,0,1,cmd);
+	msleep(2);
+	reg_val = SPI_read(3,0,2);
+	return reg_val;
+}
+
+void phy_write_masked(unsigned char port_no,unsigned char reg,unsigned int val,unsigned int mask)
+{
+	unsigned int cmd,reg_val;
+
+	cmd = BIT(26)|(port_no<<21)|(reg<<16);	// Read reg_val
+	SPI_write(3,0,1,cmd);
+	mdelay(2);
+	reg_val = SPI_read(3,0,2);
+	reg_val &= ~mask;			// Clear masked bit
+	reg_val |= (val&mask) ;			// set masked bit ,if true
+	cmd = (port_no<<21)|(reg<<16)|reg_val;
+	SPI_write(3,0,1,cmd);
+}
+
+void init_seq_7385(unsigned char port_no)
+{
+	unsigned char rev;
+
+	phy_write(port_no, 31, 0x2a30);
+	phy_write_masked(port_no, 8, 0x0200, 0x0200);
+	phy_write(port_no, 31, 0x52b5);
+	phy_write(port_no, 16, 0xb68a);
+	phy_write_masked(port_no, 18, 0x0003, 0xff07);
+	phy_write_masked(port_no, 17, 0x00a2, 0x00ff);
+	phy_write(port_no, 16, 0x968a);
+	phy_write(port_no, 31, 0x2a30);
+	phy_write_masked(port_no, 8, 0x0000, 0x0200);
+	phy_write(port_no, 31, 0x0000); /* Read revision */
+	rev = phy_read(port_no, 3) & 0x000f;
+	if (rev == 0)
+	{
+		phy_write(port_no, 31, 0x2a30);
+		phy_write_masked(port_no, 8, 0x0200, 0x0200);
+		phy_write(port_no, 31, 0x52b5);
+		phy_write(port_no, 18, 0x0000);
+		phy_write(port_no, 17, 0x0689);
+		phy_write(port_no, 16, 0x8f92);
+		phy_write(port_no, 31, 0x52B5);
+		phy_write(port_no, 18, 0x0000);
+		phy_write(port_no, 17, 0x0E35);
+		phy_write(port_no, 16, 0x9786);
+		phy_write(port_no, 31, 0x2a30);
+		phy_write_masked(port_no, 8, 0x0000, 0x0200);
+		phy_write(port_no, 23, 0xFF80);
+		phy_write(port_no, 23, 0x0000);
+	}
+	phy_write(port_no, 31, 0x0000);
+	phy_write(port_no, 18, 0x0048);
+	if (rev == 0)
+	{
+		phy_write(port_no, 31, 0x2a30);
+		phy_write(port_no, 20, 0x6600);
+		phy_write(port_no, 31, 0x0000);
+		phy_write(port_no, 24, 0xa24e);
+	}
+	else
+	{
+		phy_write(port_no, 31, 0x2a30);
+		phy_write_masked(port_no, 22, 0x0240, 0x0fc0);
+		phy_write_masked(port_no, 20, 0x4000, 0x6000);
+		phy_write(port_no, 31, 1);
+		phy_write_masked(port_no, 20, 0x6000, 0xe000);
+		phy_write(port_no, 31, 0x0000);
+	}
+}
+
+int Get_Set_port_status()
+{
+	unsigned int    reg_val,ability,rcv_mask,mac_config;
+	int is_link=0;
+	int i;
+
+ 	rcv_mask = SPI_read(2,0,0x10);			// Receive mask
+
+	for(i=0;i<4;i++){
+		reg_val = phy_read(i,1);
+		if ((reg_val & 0x0024) == 0x0024) /* link is established and auto_negotiate process completed */
+		{
+			is_link=1;
+			if(switch_pre_link[i]==LINK_DOWN){		// Link Down ==> Link up
+
+				rcv_mask |= BIT(i);			// Enable receive
+
+				reg_val = phy_read(i,10);
+				if(reg_val & 0x0c00){
+					printk("Port%d:Giga mode\n",i);
+//					SPI_write(1,i,0x00,0x300701B1);
+					mac_config = 0x00060004|(6<<6);
+
+					SPI_write(1,i,0x00,((mac_config & 0xfffffff8) | 1) | 0x20000030);	// reset port
+					mac_config |= (( BIT(i) << 19) | 0x08000000);
+					SPI_write(1,i,0x00,mac_config);
+					SPI_write(1,i,0x04,0x000300ff);		// flow control
+
+					reg_val = SPI_read(5,0,0x12);
+					reg_val &= ~BIT(i);
+					SPI_write(5,0,0x12,reg_val);
+
+					reg_val = SPI_read(1,i,0x00);
+					reg_val |= 0x10010000;
+					SPI_write(1,i,0x00,reg_val);
+//					SPI_write(1,i,0x00,0x10070181);
+					switch_pre_link[i]=LINK_UP;
+					switch_pre_speed[i]=GMAC_SPEED_1000;
+				}
+				else{
+					reg_val = phy_read(i,5);
+					ability = (reg_val&0x5e0) >>5;
+					if ((ability & 0x0C)) /* 100M */
+					{
+//						SPI_write(1,i,0x00,0x30050472);
+						if((ability&0x08)==0) 		// Half
+							mac_config = 0x00040004 |(17<<6);
+						else				// Full
+							mac_config = 0x00040004 |(17<<6);
+
+						SPI_write(1,i,0x00,((mac_config & 0xfffffff8) | 1) | 0x20000030);	// reset port
+						mac_config |= (( BIT(i) << 19) | 0x08000000);
+						SPI_write(1,i,0x00,mac_config);
+						SPI_write(1,i,0x04,0x000300ff);		// flow control
+
+						reg_val = SPI_read(5,0,0x12);
+						reg_val &= ~BIT(i);
+						SPI_write(5,0,0x12,reg_val);
+
+						reg_val = SPI_read(1,i,0x00);
+						reg_val &= ~0x08000000;
+						reg_val |= 0x10010000;
+						SPI_write(1,i,0x00,reg_val);
+//						SPI_write(1,i,0x00,0x10050442);
+						printk("Port%d:100M\n",i);
+						switch_pre_link[i]=LINK_UP;
+						switch_pre_speed[i]=GMAC_SPEED_100;
+					}
+					else if((ability & 0x03)) /* 10M */
+					{
+//						SPI_write(1,i,0x00,0x30050473);
+						if((ability&0x2)==0)		// Half
+							mac_config = 0x00040004 |(17<<6);
+						else				// Full
+							mac_config = 0x00040004 |(17<<6);
+
+						SPI_write(1,i,0x00,((mac_config & 0xfffffff8) | 1) | 0x20000030);	// reset port
+						mac_config |= (( BIT(i) << 19) | 0x08000000);
+						SPI_write(1,i,0x00,mac_config);
+						SPI_write(1,i,0x04,0x000300ff);		// flow control
+
+						reg_val = SPI_read(5,0,0x12);
+						reg_val &= ~BIT(i);
+						SPI_write(5,0,0x12,reg_val);
+
+						reg_val = SPI_read(1,i,0x00);
+						reg_val &= ~0x08000000;
+						reg_val |= 0x10010000;
+						SPI_write(1,i,0x00,reg_val);
+//						SPI_write(1,i,0x00,0x10050443);
+						printk("Port%d:10M\n",i);
+						switch_pre_link[i]=LINK_UP;
+						switch_pre_speed[i]=GMAC_SPEED_10;
+					}
+					else{
+						SPI_write(1,i,0x00,0x20000030);
+						printk("Port%d:Unknown mode\n",i);
+						switch_pre_link[i]=LINK_DOWN;
+						switch_pre_speed[i]=GMAC_SPEED_10;
+					}
+				}
+			}
+			else{						// Link up ==> Link UP
+
+			}
+		}
+		else{							// Link Down
+			if(switch_pre_link[i]==LINK_UP){
+				printk("Port%d:Link Down\n",i);
+				//phy_receiver_init(i);
+				reg_val = SPI_read(1,i,0);
+				reg_val &= ~BIT(16);
+				SPI_write(1,i,0x00,reg_val);			// disable RX
+				SPI_write(5,0,0x0E,BIT(i));			// dicard packet
+				while((SPI_read(5,0,0x0C)&BIT(i))==0)		// wait to be empty
+					msleep(1);
+				SPI_write(1,i,0x00,0x20000030);			// PORT_RST
+				SPI_write(5,0,0x0E,SPI_read(5,0,0x0E) & ~BIT(i));// accept packet
+
+				reg_val = SPI_read(5,0,0x12);
+				reg_val |= BIT(i);
+				SPI_write(5,0,0x12,reg_val);
+			}
+			switch_pre_link[i]=LINK_DOWN;
+			rcv_mask &= ~BIT(i);			// disable receive
+		}
+	}
+
+	SPI_write(2,0,0x10,rcv_mask);			// Receive mask
+	return is_link;
+
+}
+EXPORT_SYMBOL(Get_Set_port_status);
+
+void SPI_write(unsigned char block,unsigned char subblock,unsigned char addr,unsigned int value)
+{
+	int     i;
+	char    bit;
+	unsigned int data;
+
+	SPI_CS_enable(1);
+
+	data = (block<<5) | 0x10 | subblock;
+
+	//send write command
+	for(i=SPI_OP_LEN-1;i>=0;i--)
+	{
+		bit = (data>>i)& 0x01;
+		SPI_write_bit(bit);
+	}
+
+	// send 8 bits address (MSB first, LSB last)
+	for(i=SPI_ADD_LEN-1;i>=0;i--)
+	{
+		bit = (addr>>i)& 0x01;
+		SPI_write_bit(bit);
+	}
+	// send 32 bits data (MSB first, LSB last)
+	for(i=SPI_DAT_LEN-1;i>=0;i--)
+	{
+		bit = (value>>i)& 0x01;
+		SPI_write_bit(bit);
+	}
+
+	SPI_CS_enable(0);	// CS low
+
+}
+
+
+/************************************
+* SPI_write_bit
+* bit_EEDO -> 1 or 0 to be written
+************************************/
+void SPI_write_bit(char bit_EEDO)
+{
+	unsigned int addr;
+	unsigned int value;
+
+	addr = (GPIO_BASE_ADDR1 + GPIO_PIN_DIR);
+	value = readl(addr) |GPIO_EECK |GPIO_MOSI ;   /* set EECK/MISO Pin to output */
+	writel(value,addr);
+	if(bit_EEDO)
+	{
+		addr = (GPIO_BASE_ADDR1 + GPIO_DATA_SET);
+		writel(GPIO_MOSI,addr); /* set MISO to 1 */
+
+	}
+	else
+	{
+		addr = (GPIO_BASE_ADDR1 + GPIO_DATA_CLEAR);
+		writel(GPIO_MOSI,addr); /* set MISO to 0 */
+	}
+	addr = (GPIO_BASE_ADDR1 + GPIO_DATA_SET);
+	writel(GPIO_EECK,addr); /* set EECK to 1 */
+	addr = (GPIO_BASE_ADDR1 + GPIO_DATA_CLEAR);
+	writel(GPIO_EECK,addr); /* set EECK to 0 */
+
+	//return ;
+}
+
+/**********************************************************************
+* read a bit from ADM6996 register
+***********************************************************************/
+unsigned int SPI_read_bit(void) // read data from
+{
+	unsigned int addr;
+	unsigned int value;
+
+	addr = (GPIO_BASE_ADDR1 + GPIO_PIN_DIR);
+	value = readl(addr) & (~GPIO_MISO);   // set EECK to output and MISO to input
+	writel(value,addr);
+
+	addr =(GPIO_BASE_ADDR1 + GPIO_DATA_SET);
+	writel(GPIO_EECK,addr); // set EECK to 1
+
+
+	addr = (GPIO_BASE_ADDR1 + GPIO_DATA_IN);
+	value = readl(addr) ;
+
+	addr = (GPIO_BASE_ADDR1 + GPIO_DATA_CLEAR);
+	writel(GPIO_EECK,addr); // set EECK to 0
+
+
+	value = value >> 30;
+	return value ;
+}
+
+/******************************************
+* SPI_default
+* EEPROM content default value
+*******************************************/
+int SPI_default(void)
+{
+	int i;
+	unsigned reg_val,cmd;
+
+#if 0
+	SPI_write(7,0,0x1C,0x01);				// map code space to 0
+
+	reg_val = SPI_read(7,0,0x10);
+	reg_val |= 0x0146;
+	reg_val &= ~0x0001;
+	SPI_write(7,0,0x10,reg_val);				// reset iCPU and enable ext_access
+	SPI_write(7,0,0x11,0x0000);				// start address
+	for(i=0;i<sizeof(vts_img);i++){
+		SPI_write(7,0,0x12,vts_img[i]);			// fill in ROM data
+	}
+	reg_val |= BIT(0)|BIT(3);
+	SPI_write(7,0,0x10,reg_val);				// release iCPU
+	SPI_write(7,0,0x10,SPI_read(7,0,0x10)&~BIT(7));				// release iCPU
+	return ;
+#endif
+
+
+	for(i=0;i<15;i++){
+		if(i!=6 && i!=7)
+			SPI_write(3,2,0,0x1010400+i);		// Initial memory
+		mdelay(1);
+	}
+
+	mdelay(30);
+
+	SPI_write(2,0,0xB0,0x05);			// Clear MAC table
+	SPI_write(2,0,0xD0,0x03);			// Clear VLAN
+
+	//for(i=0;i<5;i++)
+	SPI_write(1,6,0x19,0x2C);			// Double Data rate
+
+	for(i=0;i<4;i++){
+		SPI_write(1,i,0x00,0x30050472);		// MAC configure
+		SPI_write(1,i,0x00,0x10050442);		// MAC configure
+		SPI_write(1,i,0x10,0x5F4);		// Max length
+		SPI_write(1,i,0x04,0x00030000);		// Flow control
+		SPI_write(1,i,0xDF,0x00000001);		// Flow control
+		SPI_write(1,i,0x08,0x000050c2);		// Flow control mac high
+		SPI_write(1,i,0x0C,0x002b00f1);		// Flow control mac low
+		SPI_write(1,i,0x6E,BIT(3));		// forward pause frame
+	}
+	SPI_write(1,i,0x00,0x20000030);			// set port 4 as reset
+
+	SPI_write(1,6,0x00,0x300701B1);			// MAC configure
+	SPI_write(1,6,0x00,0x10070181);			// MAC configure
+	SPI_write(1,6,0x10,0x5F4);			// Max length
+	SPI_write(1,6,0x04,0x00030000);		// Flow control
+	SPI_write(1,6,0xDF,0x00000002);		// Flow control
+	SPI_write(1,6,0x08,0x000050c2);		// Flow control mac high
+	SPI_write(1,6,0x0C,0x002b00f1);		// Flow control mac low
+	SPI_write(1,6,0x6E,BIT(3));		// forward pause frame
+
+
+	//SPI_write(7,0,0x05,0x31);			// MII delay for loader
+	//SPI_write(7,0,0x05,0x01);			// MII delay for kernel
+	SPI_write(7,0,0x05,0x33);
+
+	SPI_write(2,0,0x10,0x4F);			// Receive mask
+
+	mdelay(50);
+
+	SPI_write(7,0,0x14,0x02);			// Release Reset
+
+	mdelay(3);
+
+	for(i=0;i<4;i++){
+		init_seq_7385(i);
+		phy_receiver_init(i);
+		cmd = BIT(26)|(i<<21)|(0x1B<<16);	// Config LED
+		SPI_write(3,0,1,cmd);
+		mdelay(10);
+		reg_val = SPI_read(3,0,2);
+		reg_val &= 0xFF00;
+		reg_val |= 0x61;
+		cmd = (i<<21)|(0x1B<<16)|reg_val;
+		SPI_write(3,0,1,cmd);
+
+		cmd = BIT(26)|(i<<21)|(0x04<<16);	// Pause enable
+		SPI_write(3,0,1,cmd);
+		mdelay(10);
+		reg_val = SPI_read(3,0,2);
+		reg_val |= BIT(10)|BIT(11);
+		cmd = (i<<21)|(0x04<<16)|reg_val;
+		SPI_write(3,0,1,cmd);
+
+		cmd = BIT(26)|(i<<21)|(0x0<<16);	// collision test and re-negotiation
+		SPI_write(3,0,1,cmd);
+		mdelay(10);
+		reg_val = SPI_read(3,0,2);
+		reg_val |= BIT(7)|BIT(8)|BIT(9);
+		cmd = (i<<21)|(0x0<<16)|reg_val;
+		SPI_write(3,0,1,cmd);
+	}
+	init_seq_7385(i);
+	writel(0x5787a7f0,GMAC_GLOBAL_BASE_ADDR+0x1c);//For switch timing
+	return 4;		// return port_no
+}
+EXPORT_SYMBOL(SPI_default);
+
+/***********************************************************
+* SPI_CS_enable
+* before access ,you have to enable Chip Select. (pull high)
+* When fisish, you should pull low !!
+*************************************************************/
+void SPI_CS_enable(unsigned char enable)
+{
+
+	unsigned int addr,value;
+
+	addr = (GPIO_BASE_ADDR1 + GPIO_PIN_DIR);
+	value = readl(addr) |GPIO_EECS |GPIO_EECK;   /* set EECS/EECK Pin to output */
+	writel(value,addr);
+
+	if(enable)
+	{
+		addr = (GPIO_BASE_ADDR1 + GPIO_DATA_CLEAR);
+		writel(GPIO_EECK,addr); /* set EECK to 0 */	// pull low clk first
+		addr = (GPIO_BASE_ADDR1 + GPIO_DATA_CLEAR);
+		writel(GPIO_EECS,addr); /* set EECS to 0 */
+
+	}
+	else
+	{
+		addr = (GPIO_BASE_ADDR1 + GPIO_DATA_SET);
+		writel(GPIO_EECK,addr); /* set EECK to 1 */	// pull high clk before disable
+		writel(GPIO_EECS,addr); /* set EECS to 1 */
+	}
+}
+
+
+/************************************************
+* SPI_read
+* table -> which table to be read: 1/count  0/EEPROM
+* addr  -> Address to be read
+* return : Value of the register
+*************************************************/
+unsigned int SPI_read(unsigned char block,unsigned char subblock,unsigned char addr)
+{
+	int     i;
+	char    bit;
+	unsigned int data,value=0;
+
+	SPI_CS_enable(1);
+
+	data = (block<<5) | subblock;
+
+	//send write command
+	for(i=SPI_OP_LEN-1;i>=0;i--)
+	{
+		bit = (data>>i)& 0x01;
+		SPI_write_bit(bit);
+	}
+
+	// send 8 bits address (MSB first, LSB last)
+	for(i=SPI_ADD_LEN-1;i>=0;i--)
+	{
+		bit = (addr>>i)& 0x01;
+		SPI_write_bit(bit);
+	}
+
+	// dummy read for chip ready
+	for(i=0;i<8;i++)
+		SPI_read_bit();
+
+
+	// read 32 bits data (MSB first, LSB last)
+	for(i=SPI_DAT_LEN-1;i>=0;i--)
+	{
+		bit = SPI_read_bit();
+		value |= bit<<i;
+	}
+
+	SPI_CS_enable(0);	// CS low
+	return(value);
+
+}
+
+void pull_low_gpio(unsigned int val)
+{
+
+	unsigned int addr,value;
+
+	addr = (GPIO_BASE_ADDR1 + GPIO_DATA_CLEAR);
+	writel(val,addr); /* set pin low to save power*/
+
+	addr = (GPIO_BASE_ADDR1 + GPIO_PIN_DIR);
+	value = readl(addr) & ~ val;   /* set Pin to input */
+	writel(value,addr);
+
+//	value = readl(GMAC_GLOBAL_BASE_ADDR+0x0C);	// reset GPIO1 module(self clear)
+//	value |= BIT(21);
+//	writel(value,GMAC_GLOBAL_BASE_ADDR+0x0C);
+}
+
+unsigned int SPI_get_identifier(void)
+{
+	unsigned int flag=0;
+
+	SPI_write(7,0,0x01,0x01);
+	flag = SPI_read(7,0,0x18);  // chip id
+	if((flag & 0x0ffff000)==0x07385000){
+		printk("Get VSC-switch ID 0x%08x\n",flag);
+		//Giga_switch = 1;;
+		return 1;
+	}
+	else{
+		printk("VSC-switch not found\n");
+		//Giga_switch = 0;
+		pull_low_gpio(GPIO_EECK|GPIO_MOSI|GPIO_MISO|GPIO_EECS); // reduce power consume
+		return 0;
+	}
+}
+EXPORT_SYMBOL(SPI_get_identifier);
+
--- /dev/null
+++ b/include/asm-arm/arch-sl2312/sl351x_gmac.h
@@ -0,0 +1,2223 @@
+/****************************************************************************
+* Copyright 2006 StorLink Semiconductors, Inc.  All rights reserved.
+*--------------------------------------------------------------------------
+* Name			: sl351x_gmac.h
+* Description	:
+*		Define for device driver of Storlink SL351x network Engine
+*
+* Historych
+*
+*	Date		Writer		Description
+*	-----------	-----------	-------------------------------------------------
+*	08/22/2005	Gary Chen	Create and implement
+*
+****************************************************************************/
+#ifndef _GMAC_SL351x_H
+#define _GMAC_SL351x_H
+#include <linux/skbuff.h>
+
+#define SL351x_GMAC_WORKAROUND		1
+
+#undef BIG_ENDIAN
+#define BIG_ENDIAN  				0
+#define GMAC_DEBUG      			1
+#define GMAC_NUM					2
+//#define	L2_jumbo_frame				1
+
+#define _PACKED_					__attribute__ ((aligned(1), packed))
+
+#ifndef BIT
+#define BIT(x)						(1 << (x))
+#endif
+
+#define REG32(addr)     			(*(volatile unsigned long  * const)(addr))
+
+#define DMA_MALLOC(size,handle)		pci_alloc_consistent(NULL,size,handle)
+#define DMA_MFREE(mem,size,handle)	pci_free_consistent(NULL,size,mem,handle)
+
+// Define frame size
+#define ETHER_ADDR_LEN				6
+#define GMAC_MAX_ETH_FRAME_SIZE		1514
+#define GMAC_TX_BUF_SIZE			((GMAC_MAX_ETH_FRAME_SIZE + 31) & (~31))
+#define MAX_ISR_WORK        		20
+
+#ifdef	L2_jumbo_frame
+#define SW_RX_BUF_SIZE				9234	// 2048 ,9234
+#else
+#define SW_RX_BUF_SIZE				1536	// 2048
+#endif
+
+#define HW_RX_BUF_SIZE				1536	// 2048
+
+#define GMAC_DEV_TX_TIMEOUT  		(10*HZ)			//add by CH
+#define	SKB_RESERVE_BYTES			16
+
+/**********************************************************************
+ * Base Register
+ **********************************************************************/
+#define TOE_BASE					(IO_ADDRESS(SL2312_TOE_BASE))
+#define GMAC_GLOBAL_BASE_ADDR       (IO_ADDRESS(SL2312_GLOBAL_BASE))
+
+#define TOE_GLOBAL_BASE				(TOE_BASE + 0x0000)
+#define TOE_NONTOE_QUE_HDR_BASE		(TOE_BASE + 0x2000)
+#define TOE_TOE_QUE_HDR_BASE		(TOE_BASE + 0x3000)
+#define TOE_V_BIT_BASE				(TOE_BASE + 0x4000)
+#define TOE_A_BIT_BASE				(TOE_BASE + 0x6000)
+#define TOE_GMAC0_DMA_BASE			(TOE_BASE + 0x8000)
+#define TOE_GMAC0_BASE				(TOE_BASE + 0xA000)
+#define TOE_GMAC1_DMA_BASE			(TOE_BASE + 0xC000)
+#define TOE_GMAC1_BASE				(TOE_BASE + 0xE000)
+
+/**********************************************************************
+ * Queue ID
+ **********************************************************************/
+#define TOE_SW_FREE_QID				0x00
+#define TOE_HW_FREE_QID				0x01
+#define TOE_GMAC0_SW_TXQ0_QID		0x02
+#define TOE_GMAC0_SW_TXQ1_QID		0x03
+#define TOE_GMAC0_SW_TXQ2_QID		0x04
+#define TOE_GMAC0_SW_TXQ3_QID		0x05
+#define TOE_GMAC0_SW_TXQ4_QID		0x06
+#define TOE_GMAC0_SW_TXQ5_QID		0x07
+#define TOE_GMAC0_HW_TXQ0_QID		0x08
+#define TOE_GMAC0_HW_TXQ1_QID		0x09
+#define TOE_GMAC0_HW_TXQ2_QID		0x0A
+#define TOE_GMAC0_HW_TXQ3_QID		0x0B
+#define TOE_GMAC1_SW_TXQ0_QID		0x12
+#define TOE_GMAC1_SW_TXQ1_QID		0x13
+#define TOE_GMAC1_SW_TXQ2_QID		0x14
+#define TOE_GMAC1_SW_TXQ3_QID		0x15
+#define TOE_GMAC1_SW_TXQ4_QID		0x16
+#define TOE_GMAC1_SW_TXQ5_QID		0x17
+#define TOE_GMAC1_HW_TXQ0_QID		0x18
+#define TOE_GMAC1_HW_TXQ1_QID		0x19
+#define TOE_GMAC1_HW_TXQ2_QID		0x1A
+#define TOE_GMAC1_HW_TXQ3_QID		0x1B
+#define TOE_GMAC0_DEFAULT_QID		0x20
+#define TOE_GMAC1_DEFAULT_QID		0x21
+#define TOE_CLASSIFICATION_QID(x)	(0x22 + x)	// 0x22 ~ 0x2F
+#define TOE_TOE_QID(x)				(0x40 + x)	// 0x40 ~ 0x7F
+
+/**********************************************************************
+ * TOE DMA Queue Number should be 2^n, n = 6...12
+ * TOE DMA Queues are the following queue types:
+ *		SW Free Queue, HW Free Queue,
+ *		GMAC 0/1 SW TX Q0-5, and GMAC 0/1 HW TX Q0-5
+ * They have same descriptor numbers.
+ * The base address and descriptor number are configured at
+ * DMA Queues Descriptor Ring Base Address/Size Register (offset 0x0004)
+ **********************************************************************/
+#define TOE_SW_FREEQ_DESC_POWER		10
+#define TOE_SW_FREEQ_DESC_NUM		(1<<TOE_SW_FREEQ_DESC_POWER)
+#define TOE_HW_FREEQ_DESC_POWER		8
+#define TOE_HW_FREEQ_DESC_NUM		(1<<TOE_HW_FREEQ_DESC_POWER)
+#define TOE_GMAC0_SWTXQ_DESC_POWER	8
+#define TOE_GMAC0_SWTXQ_DESC_NUM	(1<<TOE_GMAC0_SWTXQ_DESC_POWER)
+#define TOE_GMAC0_HWTXQ_DESC_POWER	8
+#define TOE_GMAC0_HWTXQ_DESC_NUM	(1<<TOE_GMAC0_HWTXQ_DESC_POWER)
+#define TOE_GMAC1_SWTXQ_DESC_POWER	8
+#define TOE_GMAC1_SWTXQ_DESC_NUM	(1<<TOE_GMAC1_SWTXQ_DESC_POWER)
+#define TOE_GMAC1_HWTXQ_DESC_POWER	8
+#define TOE_GMAC1_HWTXQ_DESC_NUM	(1<<TOE_GMAC1_HWTXQ_DESC_POWER)
+#define TOE_DEFAULT_Q0_DESC_POWER	8
+#define TOE_DEFAULT_Q0_DESC_NUM		(1<<TOE_DEFAULT_Q0_DESC_POWER)
+#define TOE_DEFAULT_Q1_DESC_POWER	8
+#define TOE_DEFAULT_Q1_DESC_NUM		(1<<TOE_DEFAULT_Q1_DESC_POWER)
+#define TOE_TOE_DESC_POWER			8
+#define TOE_TOE_DESC_NUM			(1<<TOE_TOE_DESC_POWER)
+#define TOE_CLASS_DESC_POWER		8
+#define TOE_CLASS_DESC_NUM			(1<<TOE_CLASS_DESC_POWER)
+#define TOE_INTR_DESC_POWER			8
+#define TOE_INTR_DESC_NUM			(1<<TOE_INTR_DESC_POWER)
+
+#define TOE_TOE_QUEUE_MAX			64
+#define TOE_TOE_QUEUE_NUM			64
+#define TOE_CLASS_QUEUE_MAX			14
+#define TOE_CLASS_QUEUE_NUM			14
+#define TOE_INTR_QUEUE_MAX			4
+#define TOE_INTR_QUEUE_NUM			4
+#define TOE_SW_TXQ_MAX				6
+#define TOE_SW_TXQ_NUM				1
+#define TOE_HW_TXQ_MAX				4
+#define TOE_HW_TXQ_NUM				4
+#define _max(x,y)					((x>y) ? x :y)
+#define TX_DESC_NUM					_max(TOE_GMAC0_SWTXQ_DESC_NUM, TOE_GMAC1_SWTXQ_DESC_NUM)
+
+#define RWPTR_ADVANCE_ONE(x, max)	((x == (max -1)) ? 0 : x+1)
+#define RWPTR_RECEDE_ONE(x, max)	((x == 0) ? (max -1) : x-1)
+#define SET_WPTR(addr, data)		(*(volatile u16 * const)((u32)(addr)+2) = (u16)data)
+#define SET_RPTR(addr, data)		(*(volatile u16 * const)((u32)(addr)) = (u16)data)
+
+/**********************************************************************
+ * Global registers
+ * #define TOE_GLOBAL_BASE			(TOE_BASE + 0x0000)
+ * Base 0x60000000
+ **********************************************************************/
+#define GLOBAL_TOE_VERSION_REG			0x0000
+#define GLOBAL_SW_FREEQ_BASE_SIZE_REG	0x0004
+#define GLOBAL_HW_FREEQ_BASE_SIZE_REG	0x0008
+#define GLOBAL_DMA_SKB_SIZE_REG			0x0010
+#define GLOBAL_SWFQ_RWPTR_REG			0x0014
+#define GLOBAL_HWFQ_RWPTR_REG			0x0018
+#define GLOBAL_INTERRUPT_STATUS_0_REG	0x0020
+#define GLOBAL_INTERRUPT_ENABLE_0_REG	0x0024
+#define GLOBAL_INTERRUPT_SELECT_0_REG	0x0028
+#define GLOBAL_INTERRUPT_STATUS_1_REG	0x0030
+#define GLOBAL_INTERRUPT_ENABLE_1_REG	0x0034
+#define GLOBAL_INTERRUPT_SELECT_1_REG	0x0038
+#define GLOBAL_INTERRUPT_STATUS_2_REG	0x0040
+#define GLOBAL_INTERRUPT_ENABLE_2_REG	0x0044
+#define GLOBAL_INTERRUPT_SELECT_2_REG	0x0048
+#define GLOBAL_INTERRUPT_STATUS_3_REG	0x0050
+#define GLOBAL_INTERRUPT_ENABLE_3_REG	0x0054
+#define GLOBAL_INTERRUPT_SELECT_3_REG	0x0058
+#define GLOBAL_INTERRUPT_STATUS_4_REG	0x0060
+#define GLOBAL_INTERRUPT_ENABLE_4_REG	0x0064
+#define GLOBAL_INTERRUPT_SELECT_4_REG	0x0068
+#define GLOBAL_HASH_TABLE_BASE_REG		0x006C
+#define GLOBAL_QUEUE_THRESHOLD_REG		0x0070
+
+/**********************************************************************
+ * GMAC 0/1 DMA/TOE register
+ * #define TOE_GMAC0_DMA_BASE		(TOE_BASE + 0x8000)
+ * #define TOE_GMAC1_DMA_BASE		(TOE_BASE + 0xC000)
+ * Base 0x60008000 or 0x6000C000
+ **********************************************************************/
+#define GMAC_DMA_CTRL_REG				0x0000
+#define GMAC_TX_WEIGHTING_CTRL_0_REG	0x0004
+#define GMAC_TX_WEIGHTING_CTRL_1_REG	0x0008
+#define GMAC_SW_TX_QUEUE0_PTR_REG		0x000C
+#define GMAC_SW_TX_QUEUE1_PTR_REG		0x0010
+#define GMAC_SW_TX_QUEUE2_PTR_REG		0x0014
+#define GMAC_SW_TX_QUEUE3_PTR_REG		0x0018
+#define GMAC_SW_TX_QUEUE4_PTR_REG		0x001C
+#define GMAC_SW_TX_QUEUE5_PTR_REG		0x0020
+#define GMAC_HW_TX_QUEUE0_PTR_REG		0x0024
+#define GMAC_HW_TX_QUEUE1_PTR_REG		0x0028
+#define GMAC_HW_TX_QUEUE2_PTR_REG		0x002C
+#define GMAC_HW_TX_QUEUE3_PTR_REG		0x0030
+#define GMAC_DMA_TX_FIRST_DESC_REG		0x0038
+#define GMAC_DMA_TX_CURR_DESC_REG		0x003C
+#define GMAC_DMA_TX_DESC_WORD0_REG		0x0040
+#define GMAC_DMA_TX_DESC_WORD1_REG		0x0044
+#define GMAC_DMA_TX_DESC_WORD2_REG		0x0048
+#define GMAC_DMA_TX_DESC_WORD3_REG		0x004C
+#define GMAC_SW_TX_QUEUE_BASE_REG		0x0050
+#define GMAC_HW_TX_QUEUE_BASE_REG		0x0054
+#define GMAC_DMA_RX_FIRST_DESC_REG		0x0058
+#define GMAC_DMA_RX_CURR_DESC_REG		0x005C
+#define GMAC_DMA_RX_DESC_WORD0_REG		0x0060
+#define GMAC_DMA_RX_DESC_WORD1_REG		0x0064
+#define GMAC_DMA_RX_DESC_WORD2_REG		0x0068
+#define GMAC_DMA_RX_DESC_WORD3_REG		0x006C
+#define GMAC_HASH_ENGINE_REG0			0x0070
+#define GMAC_HASH_ENGINE_REG1			0x0074
+#define GMAC_MR0CR0						0x0078 	// matching rule 0 Control register 0
+#define GMAC_MR0CR1						0x007C	// matching rule 0 Control register 1
+#define GMAC_MR0CR2						0x0080	// matching rule 0 Control register 2
+#define GMAC_MR1CR0						0x0084	// matching rule 1 Control register 0
+#define GMAC_MR1CR1						0x0088	// matching rule 1 Control register 1
+#define GMAC_MR1CR2						0x008C	// matching rule 1 Control register 2
+#define GMAC_MR2CR0						0x0090	// matching rule 2 Control register 0
+#define GMAC_MR2CR1						0x0094	// matching rule 2 Control register 1
+#define GMAC_MR2CR2						0x0098	// matching rule 2 Control register 2
+#define GMAC_MR3CR0						0x009C	// matching rule 3 Control register 0
+#define GMAC_MR3CR1						0x00A0	// matching rule 3 Control register 1
+#define GMAC_MR3CR2						0x00A4	// matching rule 3 Control register 2
+#define GMAC_SPR0						0x00A8	// Support Protocol Regsister 0
+#define GMAC_SPR1						0x00AC	// Support Protocol Regsister 1
+#define GMAC_SPR2						0x00B0	// Support Protocol Regsister 2
+#define GMAC_SPR3						0x00B4	// Support Protocol Regsister 3
+#define GMAC_SPR4						0x00B8	// Support Protocol Regsister 4
+#define GMAC_SPR5						0x00BC	// Support Protocol Regsister 5
+#define GMAC_SPR6						0x00C0	// Support Protocol Regsister 6
+#define GMAC_SPR7						0x00C4	// Support Protocol Regsister 7
+#define GMAC_AHB_WEIGHT_REG				0x00C8	// GMAC Hash/Rx/Tx AHB Weighting register
+
+/**********************************************************************
+ * TOE GMAC 0/1 register
+ * #define TOE_GMAC0_BASE				(TOE_BASE + 0xA000)
+ * #define TOE_GMAC1_BASE				(TOE_BASE + 0xE000)
+ * Base 0x6000A000 or 0x6000E000
+ **********************************************************************/
+enum GMAC_REGISTER {
+	GMAC_STA_ADD0 	= 0x0000,
+	GMAC_STA_ADD1	= 0x0004,
+	GMAC_STA_ADD2	= 0x0008,
+	GMAC_RX_FLTR	= 0x000c,
+	GMAC_MCAST_FIL0 = 0x0010,
+	GMAC_MCAST_FIL1 = 0x0014,
+	GMAC_CONFIG0	= 0x0018,
+	GMAC_CONFIG1	= 0x001c,
+	GMAC_CONFIG2	= 0x0020,
+	GMAC_CONFIG3	= 0x0024,
+	GMAC_RESERVED	= 0x0028,
+	GMAC_STATUS		= 0x002c,
+	GMAC_IN_DISCARDS= 0x0030,
+	GMAC_IN_ERRORS  = 0x0034,
+	GMAC_IN_MCAST   = 0x0038,
+	GMAC_IN_BCAST   = 0x003c,
+	GMAC_IN_MAC1    = 0x0040,	// for STA 1 MAC Address
+	GMAC_IN_MAC2    = 0x0044	// for STA 2 MAC Address
+};
+/**********************************************************************
+ * TOE version Register (offset 0x0000)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int reserved		: 15;	// bit 31:17
+		unsigned int v_bit_mode		: 1;	// bit 16		1: 128-entry
+		unsigned int device_id		: 12;	// bit 15:4 	Device ID
+		unsigned int revision_id	: 4;	// bit  3:0 	Revision ID
+#else
+		unsigned int revision_id	: 4;	// bit  3:0 	Revision ID
+		unsigned int device_id		: 12;	// bit 15:4 	Device ID
+		unsigned int v_bit_mode		: 1;	// bit 16		1: 128-entry
+		unsigned int reserved		: 15;	// bit 31:17
+#endif
+	} bits;
+} TOE_VERSION_T;
+
+
+/**********************************************************************
+ * DMA Queues description Ring Base Address/Size Register (offset 0x0004)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	unsigned int base_size;
+} DMA_Q_BASE_SIZE_T;
+#define DMA_Q_BASE_MASK 	(~0x0f)
+
+/**********************************************************************
+ * DMA SKB Buffer register (offset 0x0008)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_0008
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int hw_skb_size	: 16;	// bit 31:16	HW Free poll SKB Size
+		unsigned int sw_skb_size	: 16;	// bit 15:0 	SW Free poll SKB Size
+#else
+		unsigned int sw_skb_size	: 16;	// bit 15:0 	SW Free poll SKB Size
+		unsigned int hw_skb_size	: 16;	// bit 31:16	HW Free poll SKB Size
+#endif
+	} bits;
+} DMA_SKB_SIZE_T;
+
+/**********************************************************************
+ * DMA SW Free Queue Read/Write Pointer Register (offset 0x000C)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_000c
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int wptr			: 16;	// bit 31:16 	Write Ptr, RW
+		unsigned int rptr			: 16;	// bit 15:0		Read Ptr, RO
+#else
+		unsigned int rptr			: 16;	// bit 15:0		Read Ptr, RO
+		unsigned int wptr			: 16;	// bit 31:16 	Write Ptr, RW
+#endif
+	} bits;
+} DMA_RWPTR_T;
+
+/**********************************************************************
+ * DMA HW Free Queue Read/Write Pointer Register (offset 0x0010)
+ **********************************************************************/
+// see DMA_RWPTR_T structure
+
+/**********************************************************************
+ * Interrupt Status Register 0 	(offset 0x0020)
+ * Interrupt Mask Register 0 	(offset 0x0024)
+ * Interrupt Select Register 0 	(offset 0x0028)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_0020
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int txDerr1		: 1;	// bit 31	GMAC1 AHB Bus Error while Tx
+		unsigned int txPerr1		: 1;	// bit 30	GMAC1 Tx Descriptor Protocol Error
+		unsigned int txDerr0		: 1;	// bit 29	GMAC0 AHB Bus Error while Tx
+		unsigned int txPerr0		: 1;	// bit 28	GMAC0 Tx Descriptor Protocol Error
+		unsigned int rxDerr1		: 1;	// bit 27	GMAC1 AHB Bus Error while Rx
+		unsigned int rxPerr1		: 1;	// bit 26	GMAC1 Rx Descriptor Protocol Error
+		unsigned int rxDerr0		: 1;	// bit 25	GMAC0 AHB Bus Error while Rx
+		unsigned int rxPerr0		: 1;	// bit 24	GMAC0 Rx Descriptor Protocol Error
+		unsigned int swtq15_fin		: 1;	// bit 23	GMAC1 SW Tx Queue 5 Finish Interrupt
+		unsigned int swtq14_fin		: 1;	// bit 22	GMAC1 SW Tx Queue 4 Finish Interrupt
+		unsigned int swtq13_fin		: 1;	// bit 21	GMAC1 SW Tx Queue 3 Finish Interrupt
+		unsigned int swtq12_fin		: 1;	// bit 20	GMAC1 SW Tx Queue 2 Finish Interrupt
+		unsigned int swtq11_fin		: 1;	// bit 19	GMAC1 SW Tx Queue 1 Finish Interrupt
+		unsigned int swtq10_fin		: 1;	// bit 18	GMAC1 SW Tx Queue 0 Finish Interrupt
+		unsigned int swtq05_fin		: 1;	// bit 17	GMAC0 SW Tx Queue 5 Finish Interrupt
+		unsigned int swtq04_fin		: 1;	// bit 16	GMAC0 SW Tx Queue 4 Finish Interrupt
+		unsigned int swtq03_fin		: 1;	// bit 15	GMAC0 SW Tx Queue 3 Finish Interrupt
+		unsigned int swtq02_fin		: 1;	// bit 14	GMAC0 SW Tx Queue 2 Finish Interrupt
+		unsigned int swtq01_fin		: 1;	// bit 13	GMAC0 SW Tx Queue 1 Finish Interrupt
+		unsigned int swtq00_fin		: 1;	// bit 12	GMAC0 SW Tx Queue 0 Finish Interrupt
+		unsigned int swtq15_eof		: 1;	// bit 11	GMAC1 SW Tx Queue 5 EOF Interrupt
+		unsigned int swtq14_eof		: 1;	// bit 10	GMAC1 SW Tx Queue 4 EOF Interrupt
+		unsigned int swtq13_eof		: 1;	// bit 9	GMAC1 SW Tx Queue 3 EOF Interrupt
+		unsigned int swtq12_eof		: 1;	// bit 8	GMAC1 SW Tx Queue 2 EOF Interrupt
+		unsigned int swtq11_eof		: 1;	// bit 7	GMAC1 SW Tx Queue 1 EOF Interrupt
+		unsigned int swtq10_eof		: 1;	// bit 6	GMAC1 SW Tx Queue 0 EOF Interrupt
+		unsigned int swtq05_eof		: 1;	// bit 5	GMAC0 SW Tx Queue 5 EOF Interrupt
+		unsigned int swtq04_eof		: 1;	// bit 4	GMAC0 SW Tx Queue 4 EOF Interrupt
+		unsigned int swtq03_eof		: 1;	// bit 3	GMAC0 SW Tx Queue 3 EOF Interrupt
+		unsigned int swtq02_eof		: 1;	// bit 2	GMAC0 SW Tx Queue 2 EOF Interrupt
+		unsigned int swtq01_eof		: 1;	// bit 1	GMAC0 SW Tx Queue 1 EOF Interrupt
+		unsigned int swtq00_eof		: 1;	// bit 0	GMAC0 SW Tx Queue 0 EOF Interrupt
+#else
+		unsigned int swtq00_eof		: 1;	// bit 0	GMAC0 SW Tx Queue 0 EOF Interrupt
+		unsigned int swtq01_eof		: 1;	// bit 1	GMAC0 SW Tx Queue 1 EOF Interrupt
+		unsigned int swtq02_eof		: 1;	// bit 2	GMAC0 SW Tx Queue 2 EOF Interrupt
+		unsigned int swtq03_eof		: 1;	// bit 3	GMAC0 SW Tx Queue 3 EOF Interrupt
+		unsigned int swtq04_eof		: 1;	// bit 4	GMAC0 SW Tx Queue 4 EOF Interrupt
+		unsigned int swtq05_eof		: 1;	// bit 5	GMAC0 SW Tx Queue 5 EOF Interrupt
+		unsigned int swtq10_eof		: 1;	// bit 6	GMAC1 SW Tx Queue 0 EOF Interrupt
+		unsigned int swtq11_eof		: 1;	// bit 7	GMAC1 SW Tx Queue 1 EOF Interrupt
+		unsigned int swtq12_eof		: 1;	// bit 8	GMAC1 SW Tx Queue 2 EOF Interrupt
+		unsigned int swtq13_eof		: 1;	// bit 9	GMAC1 SW Tx Queue 3 EOF Interrupt
+		unsigned int swtq14_eof		: 1;	// bit 10	GMAC1 SW Tx Queue 4 EOF Interrupt
+		unsigned int swtq15_eof		: 1;	// bit 11	GMAC1 SW Tx Queue 5 EOF Interrupt
+		unsigned int swtq00_fin		: 1;	// bit 12	GMAC0 SW Tx Queue 0 Finish Interrupt
+		unsigned int swtq01_fin		: 1;	// bit 13	GMAC0 SW Tx Queue 1 Finish Interrupt
+		unsigned int swtq02_fin		: 1;	// bit 14	GMAC0 SW Tx Queue 2 Finish Interrupt
+		unsigned int swtq03_fin		: 1;	// bit 15	GMAC0 SW Tx Queue 3 Finish Interrupt
+		unsigned int swtq04_fin		: 1;	// bit 16	GMAC0 SW Tx Queue 4 Finish Interrupt
+		unsigned int swtq05_fin		: 1;	// bit 17	GMAC0 SW Tx Queue 5 Finish Interrupt
+		unsigned int swtq10_fin		: 1;	// bit 18	GMAC1 SW Tx Queue 0 Finish Interrupt
+		unsigned int swtq11_fin		: 1;	// bit 19	GMAC1 SW Tx Queue 1 Finish Interrupt
+		unsigned int swtq12_fin		: 1;	// bit 20	GMAC1 SW Tx Queue 2 Finish Interrupt
+		unsigned int swtq13_fin		: 1;	// bit 21	GMAC1 SW Tx Queue 3 Finish Interrupt
+		unsigned int swtq14_fin		: 1;	// bit 22	GMAC1 SW Tx Queue 4 Finish Interrupt
+		unsigned int swtq15_fin		: 1;	// bit 23	GMAC1 SW Tx Queue 5 Finish Interrupt
+		unsigned int rxPerr0		: 1;	// bit 24	GMAC0 Rx Descriptor Protocol Error
+		unsigned int rxDerr0		: 1;	// bit 25	GMAC0 AHB Bus Error while Rx
+		unsigned int rxPerr1		: 1;	// bit 26	GMAC1 Rx Descriptor Protocol Error
+		unsigned int rxDerr1		: 1;	// bit 27	GMAC1 AHB Bus Error while Rx
+		unsigned int txPerr0		: 1;	// bit 28	GMAC0 Tx Descriptor Protocol Error
+		unsigned int txDerr0		: 1;	// bit 29	GMAC0 AHB Bus Error while Tx
+		unsigned int txPerr1		: 1;	// bit 30	GMAC1 Tx Descriptor Protocol Error
+		unsigned int txDerr1		: 1;	// bit 31	GMAC1 AHB Bus Error while Tx
+#endif
+	} bits;
+} INTR_REG0_T;
+
+#define GMAC1_TXDERR_INT_BIT		BIT(31)
+#define GMAC1_TXPERR_INT_BIT		BIT(30)
+#define GMAC0_TXDERR_INT_BIT		BIT(29)
+#define GMAC0_TXPERR_INT_BIT		BIT(28)
+#define GMAC1_RXDERR_INT_BIT		BIT(27)
+#define GMAC1_RXPERR_INT_BIT		BIT(26)
+#define GMAC0_RXDERR_INT_BIT		BIT(25)
+#define GMAC0_RXPERR_INT_BIT		BIT(24)
+#define GMAC1_SWTQ15_FIN_INT_BIT	BIT(23)
+#define GMAC1_SWTQ14_FIN_INT_BIT	BIT(22)
+#define GMAC1_SWTQ13_FIN_INT_BIT	BIT(21)
+#define GMAC1_SWTQ12_FIN_INT_BIT	BIT(20)
+#define GMAC1_SWTQ11_FIN_INT_BIT	BIT(19)
+#define GMAC1_SWTQ10_FIN_INT_BIT	BIT(18)
+#define GMAC0_SWTQ05_FIN_INT_BIT	BIT(17)
+#define GMAC0_SWTQ04_FIN_INT_BIT	BIT(16)
+#define GMAC0_SWTQ03_FIN_INT_BIT	BIT(15)
+#define GMAC0_SWTQ02_FIN_INT_BIT	BIT(14)
+#define GMAC0_SWTQ01_FIN_INT_BIT	BIT(13)
+#define GMAC0_SWTQ00_FIN_INT_BIT	BIT(12)
+#define GMAC1_SWTQ15_EOF_INT_BIT	BIT(11)
+#define GMAC1_SWTQ14_EOF_INT_BIT	BIT(10)
+#define GMAC1_SWTQ13_EOF_INT_BIT	BIT(9)
+#define GMAC1_SWTQ12_EOF_INT_BIT	BIT(8)
+#define GMAC1_SWTQ11_EOF_INT_BIT	BIT(7)
+#define GMAC1_SWTQ10_EOF_INT_BIT	BIT(6)
+#define GMAC0_SWTQ05_EOF_INT_BIT	BIT(5)
+#define GMAC0_SWTQ04_EOF_INT_BIT	BIT(4)
+#define GMAC0_SWTQ03_EOF_INT_BIT	BIT(3)
+#define GMAC0_SWTQ02_EOF_INT_BIT	BIT(2)
+#define GMAC0_SWTQ01_EOF_INT_BIT	BIT(1)
+#define GMAC0_SWTQ00_EOF_INT_BIT	BIT(0)
+
+
+/**********************************************************************
+ * Interrupt Status Register 1 	(offset 0x0030)
+ * Interrupt Mask Register 1 	(offset 0x0034)
+ * Interrupt Select Register 1 	(offset 0x0038)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_0030
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int toe_iq3_full	: 1;	// bit 31	TOE Interrupt Queue 3 Full Interrupt
+		unsigned int toe_iq2_full	: 1;	// bit 30	TOE Interrupt Queue 2 Full Interrupt
+		unsigned int toe_iq1_full	: 1;	// bit 29	TOE Interrupt Queue 1 Full Interrupt
+		unsigned int toe_iq0_full	: 1;	// bit 28	TOE Interrupt Queue 0 Full Interrupt
+		unsigned int toe_iq3_intr	: 1;	// bit 27	TOE Interrupt Queue 3 with Interrupts
+		unsigned int toe_iq2_intr	: 1;	// bit 26	TOE Interrupt Queue 2 with Interrupts
+		unsigned int toe_iq1_intr	: 1;	// bit 25	TOE Interrupt Queue 1 with Interrupts
+		unsigned int toe_iq0_intr	: 1;	// bit 24	TOE Interrupt Queue 0 with Interrupts
+		unsigned int hwtq13_eof		: 1;	// bit 23	GMAC1 HW Tx Queue3 EOF Interrupt
+		unsigned int hwtq12_eof		: 1;	// bit 22	GMAC1 HW Tx Queue2 EOF Interrupt
+		unsigned int hwtq11_eof		: 1;	// bit 21	GMAC1 HW Tx Queue1 EOF Interrupt
+		unsigned int hwtq10_eof		: 1;	// bit 20	GMAC1 HW Tx Queue0 EOF Interrupt
+		unsigned int hwtq03_eof		: 1;	// bit 19	GMAC0 HW Tx Queue3 EOF Interrupt
+		unsigned int hwtq02_eof		: 1;	// bit 18	GMAC0 HW Tx Queue2 EOF Interrupt
+		unsigned int hwtq01_eof		: 1;	// bit 17	GMAC0 HW Tx Queue1 EOF Interrupt
+		unsigned int hwtq00_eof		: 1;	// bit 16	GMAC0 HW Tx Queue0 EOF Interrupt
+		unsigned int class_rx		: 14;	// bit 15:2	Classification Queue Rx Interrupt
+		unsigned int default_q1_eof	: 1;	// bit 1	Default Queue 1 EOF Interrupt
+		unsigned int default_q0_eof	: 1;	// bit 0	Default Queue 0 EOF Interrupt
+#else
+		unsigned int default_q0_eof	: 1;	// bit 0	Default Queue 0 EOF Interrupt
+		unsigned int default_q1_eof	: 1;	// bit 1	Default Queue 1 EOF Interrupt
+		unsigned int class_rx		: 14;	// bit 15:2	Classification Queue Rx Interrupt
+		unsigned int hwtq00_eof		: 1;	// bit 16	GMAC0 HW Tx Queue0 EOF Interrupt
+		unsigned int hwtq01_eof		: 1;	// bit 17	GMAC0 HW Tx Queue1 EOF Interrupt
+		unsigned int hwtq02_eof		: 1;	// bit 18	GMAC0 HW Tx Queue2 EOF Interrupt
+		unsigned int hwtq03_eof		: 1;	// bit 19	GMAC0 HW Tx Queue3 EOF Interrupt
+		unsigned int hwtq10_eof		: 1;	// bit 20	GMAC1 HW Tx Queue0 EOF Interrupt
+		unsigned int hwtq11_eof		: 1;	// bit 21	GMAC1 HW Tx Queue1 EOF Interrupt
+		unsigned int hwtq12_eof		: 1;	// bit 22	GMAC1 HW Tx Queue2 EOF Interrupt
+		unsigned int hwtq13_eof		: 1;	// bit 23	GMAC1 HW Tx Queue3 EOF Interrupt
+		unsigned int toe_iq0_intr	: 1;	// bit 24	TOE Interrupt Queue 0 with Interrupts
+		unsigned int toe_iq1_intr	: 1;	// bit 25	TOE Interrupt Queue 1 with Interrupts
+		unsigned int toe_iq2_intr	: 1;	// bit 26	TOE Interrupt Queue 2 with Interrupts
+		unsigned int toe_iq3_intr	: 1;	// bit 27	TOE Interrupt Queue 3 with Interrupts
+		unsigned int toe_iq0_full	: 1;	// bit 28	TOE Interrupt Queue 0 Full Interrupt
+		unsigned int toe_iq1_full	: 1;	// bit 29	TOE Interrupt Queue 1 Full Interrupt
+		unsigned int toe_iq2_full	: 1;	// bit 30	TOE Interrupt Queue 2 Full Interrupt
+		unsigned int toe_iq3_full	: 1;	// bit 31	TOE Interrupt Queue 3 Full Interrupt
+#endif
+	} bits;
+} INTR_REG1_T;
+
+#define TOE_IQ3_FULL_INT_BIT		BIT(31)
+#define TOE_IQ2_FULL_INT_BIT		BIT(30)
+#define TOE_IQ1_FULL_INT_BIT		BIT(29)
+#define TOE_IQ0_FULL_INT_BIT		BIT(28)
+#define TOE_IQ3_INT_BIT				BIT(27)
+#define TOE_IQ2_INT_BIT				BIT(26)
+#define TOE_IQ1_INT_BIT				BIT(25)
+#define TOE_IQ0_INT_BIT				BIT(24)
+#define GMAC1_HWTQ13_EOF_INT_BIT	BIT(23)
+#define GMAC1_HWTQ12_EOF_INT_BIT	BIT(22)
+#define GMAC1_HWTQ11_EOF_INT_BIT	BIT(21)
+#define GMAC1_HWTQ10_EOF_INT_BIT	BIT(20)
+#define GMAC0_HWTQ03_EOF_INT_BIT	BIT(19)
+#define GMAC0_HWTQ02_EOF_INT_BIT	BIT(18)
+#define GMAC0_HWTQ01_EOF_INT_BIT	BIT(17)
+#define GMAC0_HWTQ00_EOF_INT_BIT	BIT(16)
+#define CLASS_RX_INT_BIT(x)			BIT((x+2))
+#define DEFAULT_Q1_INT_BIT			BIT(1)
+#define DEFAULT_Q0_INT_BIT			BIT(0)
+
+#define TOE_IQ_INT_BITS				(TOE_IQ0_INT_BIT | TOE_IQ1_INT_BIT | \
+		               	 			TOE_IQ2_INT_BIT | TOE_IQ3_INT_BIT)
+#define	TOE_IQ_FULL_BITS			(TOE_IQ0_FULL_INT_BIT | TOE_IQ1_FULL_INT_BIT | \
+		                	 		TOE_IQ2_FULL_INT_BIT | TOE_IQ3_FULL_INT_BIT)
+#define	TOE_IQ_ALL_BITS				(TOE_IQ_INT_BITS | TOE_IQ_FULL_BITS)
+#define TOE_CLASS_RX_INT_BITS		0xfffc
+
+/**********************************************************************
+ * Interrupt Status Register 2 	(offset 0x0040)
+ * Interrupt Mask Register 2 	(offset 0x0044)
+ * Interrupt Select Register 2 	(offset 0x0048)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_0040
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int toe_q31_full	: 1;	// bit 31	TOE Queue 31 Full Interrupt
+		unsigned int toe_q30_full	: 1;	// bit 30	TOE Queue 30 Full Interrupt
+		unsigned int toe_q29_full	: 1;	// bit 29	TOE Queue 29 Full Interrupt
+		unsigned int toe_q28_full	: 1;	// bit 28	TOE Queue 28 Full Interrupt
+		unsigned int toe_q27_full	: 1;	// bit 27	TOE Queue 27 Full Interrupt
+		unsigned int toe_q26_full	: 1;	// bit 26	TOE Queue 26 Full Interrupt
+		unsigned int toe_q25_full	: 1;	// bit 25	TOE Queue 25 Full Interrupt
+		unsigned int toe_q24_full	: 1;	// bit 24	TOE Queue 24 Full Interrupt
+		unsigned int toe_q23_full	: 1;	// bit 23	TOE Queue 23 Full Interrupt
+		unsigned int toe_q22_full	: 1;	// bit 22	TOE Queue 22 Full Interrupt
+		unsigned int toe_q21_full	: 1;	// bit 21	TOE Queue 21 Full Interrupt
+		unsigned int toe_q20_full	: 1;	// bit 20	TOE Queue 20 Full Interrupt
+		unsigned int toe_q19_full	: 1;	// bit 19	TOE Queue 19 Full Interrupt
+		unsigned int toe_q18_full	: 1;	// bit 18	TOE Queue 18 Full Interrupt
+		unsigned int toe_q17_full	: 1;	// bit 17	TOE Queue 17 Full Interrupt
+		unsigned int toe_q16_full	: 1;	// bit 16	TOE Queue 16 Full Interrupt
+		unsigned int toe_q15_full	: 1;	// bit 15	TOE Queue 15 Full Interrupt
+		unsigned int toe_q14_full	: 1;	// bit 14	TOE Queue 14 Full Interrupt
+		unsigned int toe_q13_full	: 1;	// bit 13	TOE Queue 13 Full Interrupt
+		unsigned int toe_q12_full	: 1;	// bit 12	TOE Queue 12 Full Interrupt
+		unsigned int toe_q11_full	: 1;	// bit 11	TOE Queue 11 Full Interrupt
+		unsigned int toe_q10_full	: 1;	// bit 10	TOE Queue 10 Full Interrupt
+		unsigned int toe_q9_full	: 1;	// bit 9	TOE Queue 9 Full Interrupt
+		unsigned int toe_q8_full	: 1;	// bit 8	TOE Queue 8 Full Interrupt
+		unsigned int toe_q7_full	: 1;	// bit 7	TOE Queue 7 Full Interrupt
+		unsigned int toe_q6_full	: 1;	// bit 6	TOE Queue 6 Full Interrupt
+		unsigned int toe_q5_full	: 1;	// bit 5	TOE Queue 5 Full Interrupt
+		unsigned int toe_q4_full	: 1;	// bit 4	TOE Queue 4 Full Interrupt
+		unsigned int toe_q3_full	: 1;	// bit 3	TOE Queue 3 Full Interrupt
+		unsigned int toe_q2_full	: 1;	// bit 2	TOE Queue 2 Full Interrupt
+		unsigned int toe_q1_full	: 1;	// bit 1	TOE Queue 1 Full Interrupt
+		unsigned int toe_q0_full	: 1;	// bit 0	TOE Queue 0 Full Interrupt
+#else
+		unsigned int toe_q0_full	: 1;	// bit 0	TOE Queue 0 Full Interrupt
+		unsigned int toe_q1_full	: 1;	// bit 1	TOE Queue 1 Full Interrupt
+		unsigned int toe_q2_full	: 1;	// bit 2	TOE Queue 2 Full Interrupt
+		unsigned int toe_q3_full	: 1;	// bit 3	TOE Queue 3 Full Interrupt
+		unsigned int toe_q4_full	: 1;	// bit 4	TOE Queue 4 Full Interrupt
+		unsigned int toe_q5_full	: 1;	// bit 5	TOE Queue 5 Full Interrupt
+		unsigned int toe_q6_full	: 1;	// bit 6	TOE Queue 6 Full Interrupt
+		unsigned int toe_q7_full	: 1;	// bit 7	TOE Queue 7 Full Interrupt
+		unsigned int toe_q8_full	: 1;	// bit 8	TOE Queue 8 Full Interrupt
+		unsigned int toe_q9_full	: 1;	// bit 9	TOE Queue 9 Full Interrupt
+		unsigned int toe_q10_full	: 1;	// bit 10	TOE Queue 10 Full Interrupt
+		unsigned int toe_q11_full	: 1;	// bit 11	TOE Queue 11 Full Interrupt
+		unsigned int toe_q12_full	: 1;	// bit 12	TOE Queue 12 Full Interrupt
+		unsigned int toe_q13_full	: 1;	// bit 13	TOE Queue 13 Full Interrupt
+		unsigned int toe_q14_full	: 1;	// bit 14	TOE Queue 14 Full Interrupt
+		unsigned int toe_q15_full	: 1;	// bit 15	TOE Queue 15 Full Interrupt
+		unsigned int toe_q16_full	: 1;	// bit 16	TOE Queue 16 Full Interrupt
+		unsigned int toe_q17_full	: 1;	// bit 17	TOE Queue 17 Full Interrupt
+		unsigned int toe_q18_full	: 1;	// bit 18	TOE Queue 18 Full Interrupt
+		unsigned int toe_q19_full	: 1;	// bit 19	TOE Queue 19 Full Interrupt
+		unsigned int toe_q20_full	: 1;	// bit 20	TOE Queue 20 Full Interrupt
+		unsigned int toe_q21_full	: 1;	// bit 21	TOE Queue 21 Full Interrupt
+		unsigned int toe_q22_full	: 1;	// bit 22	TOE Queue 22 Full Interrupt
+		unsigned int toe_q23_full	: 1;	// bit 23	TOE Queue 23 Full Interrupt
+		unsigned int toe_q24_full	: 1;	// bit 24	TOE Queue 24 Full Interrupt
+		unsigned int toe_q25_full	: 1;	// bit 25	TOE Queue 25 Full Interrupt
+		unsigned int toe_q26_full	: 1;	// bit 26	TOE Queue 26 Full Interrupt
+		unsigned int toe_q27_full	: 1;	// bit 27	TOE Queue 27 Full Interrupt
+		unsigned int toe_q28_full	: 1;	// bit 28	TOE Queue 28 Full Interrupt
+		unsigned int toe_q29_full	: 1;	// bit 29	TOE Queue 29 Full Interrupt
+		unsigned int toe_q30_full	: 1;	// bit 30	TOE Queue 30 Full Interrupt
+		unsigned int toe_q31_full	: 1;	// bit 31	TOE Queue 31 Full Interrupt
+#endif
+	} bits;
+} INTR_REG2_T;
+
+#define TOE_QL_FULL_INT_BIT(x)		BIT(x)
+
+/**********************************************************************
+ * Interrupt Status Register 3 	(offset 0x0050)
+ * Interrupt Mask Register 3 	(offset 0x0054)
+ * Interrupt Select Register 3 	(offset 0x0058)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_0050
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int toe_q63_full	: 1;	// bit 63	TOE Queue 63 Full Interrupt
+		unsigned int toe_q62_full	: 1;	// bit 62	TOE Queue 62 Full Interrupt
+		unsigned int toe_q61_full	: 1;	// bit 61	TOE Queue 61 Full Interrupt
+		unsigned int toe_q60_full	: 1;	// bit 60	TOE Queue 60 Full Interrupt
+		unsigned int toe_q59_full	: 1;	// bit 59	TOE Queue 59 Full Interrupt
+		unsigned int toe_q58_full	: 1;	// bit 58	TOE Queue 58 Full Interrupt
+		unsigned int toe_q57_full	: 1;	// bit 57	TOE Queue 57 Full Interrupt
+		unsigned int toe_q56_full	: 1;	// bit 56	TOE Queue 56 Full Interrupt
+		unsigned int toe_q55_full	: 1;	// bit 55	TOE Queue 55 Full Interrupt
+		unsigned int toe_q54_full	: 1;	// bit 54	TOE Queue 54 Full Interrupt
+		unsigned int toe_q53_full	: 1;	// bit 53	TOE Queue 53 Full Interrupt
+		unsigned int toe_q52_full	: 1;	// bit 52	TOE Queue 52 Full Interrupt
+		unsigned int toe_q51_full	: 1;	// bit 51	TOE Queue 51 Full Interrupt
+		unsigned int toe_q50_full	: 1;	// bit 50	TOE Queue 50 Full Interrupt
+		unsigned int toe_q49_full	: 1;	// bit 49	TOE Queue 49 Full Interrupt
+		unsigned int toe_q48_full	: 1;	// bit 48	TOE Queue 48 Full Interrupt
+		unsigned int toe_q47_full	: 1;	// bit 47	TOE Queue 47 Full Interrupt
+		unsigned int toe_q46_full	: 1;	// bit 46	TOE Queue 46 Full Interrupt
+		unsigned int toe_q45_full	: 1;	// bit 45	TOE Queue 45 Full Interrupt
+		unsigned int toe_q44_full	: 1;	// bit 44	TOE Queue 44 Full Interrupt
+		unsigned int toe_q43_full	: 1;	// bit 43	TOE Queue 43 Full Interrupt
+		unsigned int toe_q42_full	: 1;	// bit 42	TOE Queue 42 Full Interrupt
+		unsigned int toe_q41_full	: 1;	// bit 41	TOE Queue 41 Full Interrupt
+		unsigned int toe_q40_full	: 1;	// bit 40	TOE Queue 40 Full Interrupt
+		unsigned int toe_q39_full	: 1;	// bit 39 	TOE Queue 39 Full Interrupt
+		unsigned int toe_q38_full	: 1;	// bit 38	TOE Queue 38 Full Interrupt
+		unsigned int toe_q37_full	: 1;	// bit 37	TOE Queue 37 Full Interrupt
+		unsigned int toe_q36_full	: 1;	// bit 36	TOE Queue 36 Full Interrupt
+		unsigned int toe_q35_full	: 1;	// bit 35	TOE Queue 35 Full Interrupt
+		unsigned int toe_q34_full	: 1;	// bit 34	TOE Queue 34 Full Interrupt
+		unsigned int toe_q33_full	: 1;	// bit 33	TOE Queue 33 Full Interrupt
+		unsigned int toe_q32_full	: 1;	// bit 32	TOE Queue 32 Full Interrupt
+#else
+		unsigned int toe_q32_full	: 1;	// bit 32	TOE Queue 32 Full Interrupt
+		unsigned int toe_q33_full	: 1;	// bit 33	TOE Queue 33 Full Interrupt
+		unsigned int toe_q34_full	: 1;	// bit 34	TOE Queue 34 Full Interrupt
+		unsigned int toe_q35_full	: 1;	// bit 35	TOE Queue 35 Full Interrupt
+		unsigned int toe_q36_full	: 1;	// bit 36	TOE Queue 36 Full Interrupt
+		unsigned int toe_q37_full	: 1;	// bit 37	TOE Queue 37 Full Interrupt
+		unsigned int toe_q38_full	: 1;	// bit 38	TOE Queue 38 Full Interrupt
+		unsigned int toe_q39_full	: 1;	// bit 39	TOE Queue 39 Full Interrupt
+		unsigned int toe_q40_full	: 1;	// bit 40	TOE Queue 40 Full Interrupt
+		unsigned int toe_q41_full	: 1;	// bit 41	TOE Queue 41 Full Interrupt
+		unsigned int toe_q42_full	: 1;	// bit 42	TOE Queue 42 Full Interrupt
+		unsigned int toe_q43_full	: 1;	// bit 43	TOE Queue 43 Full Interrupt
+		unsigned int toe_q44_full	: 1;	// bit 44	TOE Queue 44 Full Interrupt
+		unsigned int toe_q45_full	: 1;	// bit 45	TOE Queue 45 Full Interrupt
+		unsigned int toe_q46_full	: 1;	// bit 46	TOE Queue 46 Full Interrupt
+		unsigned int toe_q47_full	: 1;	// bit 47	TOE Queue 47 Full Interrupt
+		unsigned int toe_q48_full	: 1;	// bit 48	TOE Queue 48 Full Interrupt
+		unsigned int toe_q49_full	: 1;	// bit 49	TOE Queue 49 Full Interrupt
+		unsigned int toe_q50_full	: 1;	// bit 50	TOE Queue 50 Full Interrupt
+		unsigned int toe_q51_full	: 1;	// bit 51	TOE Queue 51 Full Interrupt
+		unsigned int toe_q52_full	: 1;	// bit 52	TOE Queue 52 Full Interrupt
+		unsigned int toe_q53_full	: 1;	// bit 53	TOE Queue 53 Full Interrupt
+		unsigned int toe_q54_full	: 1;	// bit 54	TOE Queue 54 Full Interrupt
+		unsigned int toe_q55_full	: 1;	// bit 55	TOE Queue 55 Full Interrupt
+		unsigned int toe_q56_full	: 1;	// bit 56	TOE Queue 56 Full Interrupt
+		unsigned int toe_q57_full	: 1;	// bit 57	TOE Queue 57 Full Interrupt
+		unsigned int toe_q58_full	: 1;	// bit 58	TOE Queue 58 Full Interrupt
+		unsigned int toe_q59_full	: 1;	// bit 59	TOE Queue 59 Full Interrupt
+		unsigned int toe_q60_full	: 1;	// bit 60	TOE Queue 60 Full Interrupt
+		unsigned int toe_q61_full	: 1;	// bit 61	TOE Queue 61 Full Interrupt
+		unsigned int toe_q62_full	: 1;	// bit 62	TOE Queue 62 Full Interrupt
+		unsigned int toe_q63_full	: 1;	// bit 63	TOE Queue 63 Full Interrupt
+#endif
+	} bits;
+} INTR_REG3_T;
+
+#define TOE_QH_FULL_INT_BIT(x)		BIT(x-32)
+
+/**********************************************************************
+ * Interrupt Status Register 4 	(offset 0x0060)
+ * Interrupt Mask Register 4 	(offset 0x0064)
+ * Interrupt Select Register 4 	(offset 0x0068)
+ **********************************************************************/
+typedef union
+{
+	unsigned char byte;
+	struct bit_0060
+	{
+#if (BIG_ENDIAN==1)
+		unsigned char reserved		: 1;	//
+		unsigned char cnt_full 		: 1;	// MIB counters half full interrupt
+		unsigned char rx_pause_on	: 1;	// received pause on frame interrupt
+		unsigned char tx_pause_on	: 1;	// transmit pause on frame interrupt
+		unsigned char rx_pause_off  : 1;	// received pause off frame interrupt
+		unsigned char tx_pause_off	: 1;	// received pause off frame interrupt
+		unsigned char rx_overrun	: 1;    // GMAC Rx FIFO overrun interrupt
+		unsigned char status_changed: 1;	// Status Changed Intr for RGMII Mode
+#else
+		unsigned char status_changed: 1;	// Status Changed Intr for RGMII Mode
+		unsigned char rx_overrun	: 1;   // GMAC Rx FIFO overrun interrupt
+		unsigned char tx_pause_off	: 1;	// received pause off frame interrupt
+		unsigned char rx_pause_off  : 1;	// received pause off frame interrupt
+		unsigned char tx_pause_on	: 1;	// transmit pause on frame interrupt
+		unsigned char rx_pause_on	: 1;	// received pause on frame interrupt
+		unsigned char cnt_full 		: 1;	// MIB counters half full interrupt
+		unsigned char reserved		: 1;	//
+#endif
+	} _PACKED_ bits;
+} _PACKED_ GMAC_INTR_T;
+
+typedef union
+{
+	unsigned int bits32;
+	struct bit_0060_2
+	{
+#if (BIG_ENDIAN==1)
+		GMAC_INTR_T		gmac1;
+		GMAC_INTR_T		gmac0;
+		unsigned int	class_qf_int: 14;	// bit 15:2 Classification Rx Queue13-0 Full Intr.
+		unsigned int    hwfq_empty	: 1;	// bit 1	Hardware Free Queue Empty Intr.
+		unsigned int    swfq_empty	: 1;	// bit 0	Software Free Queue Empty Intr.
+#else
+#endif
+		unsigned int    swfq_empty	: 1;	// bit 0	Software Free Queue Empty Intr.
+		unsigned int    hwfq_empty	: 1;	// bit 1	Hardware Free Queue Empty Intr.
+		unsigned int	class_qf_int: 14;	// bit 15:2 Classification Rx Queue13-0 Full Intr.
+		GMAC_INTR_T		gmac0;
+		GMAC_INTR_T		gmac1;
+	} bits;
+} INTR_REG4_T;
+
+#define GMAC1_RESERVED_INT_BIT		BIT(31)
+#define GMAC1_MIB_INT_BIT			BIT(30)
+#define GMAC1_RX_PAUSE_ON_INT_BIT	BIT(29)
+#define GMAC1_TX_PAUSE_ON_INT_BIT	BIT(28)
+#define GMAC1_RX_PAUSE_OFF_INT_BIT	BIT(27)
+#define GMAC1_TX_PAUSE_OFF_INT_BIT	BIT(26)
+#define GMAC1_RX_OVERRUN_INT_BIT	BIT(25)
+#define GMAC1_STATUS_CHANGE_INT_BIT	BIT(24)
+#define GMAC0_RESERVED_INT_BIT		BIT(23)
+#define GMAC0_MIB_INT_BIT			BIT(22)
+#define GMAC0_RX_PAUSE_ON_INT_BIT	BIT(21)
+#define GMAC0_TX_PAUSE_ON_INT_BIT	BIT(20)
+#define GMAC0_RX_PAUSE_OFF_INT_BIT	BIT(19)
+#define GMAC0_TX_PAUSE_OFF_INT_BIT	BIT(18)
+#define GMAC0_RX_OVERRUN_INT_BIT	BIT(17)
+#define GMAC0_STATUS_CHANGE_INT_BIT	BIT(16)
+#define CLASS_RX_FULL_INT_BIT(x)	BIT((x+2))
+#define HWFQ_EMPTY_INT_BIT			BIT(1)
+#define SWFQ_EMPTY_INT_BIT			BIT(0)
+
+#if 1
+#define GMAC0_INT_BITS				(GMAC0_MIB_INT_BIT)
+#define GMAC1_INT_BITS				(GMAC1_MIB_INT_BIT)
+#else
+#define GMAC0_INT_BITS				(GMAC0_RESERVED_INT_BIT | GMAC0_MIB_INT_BIT | \
+									 GMAC0_RX_PAUSE_ON_INT_BIT | GMAC0_TX_PAUSE_ON_INT_BIT |	\
+									 GMAC0_RX_PAUSE_OFF_INT_BIT | GMAC0_TX_PAUSE_OFF_INT_BIT | 	\
+									 GMAC0_RX_OVERRUN_INT_BIT | GMAC0_STATUS_CHANGE_INT_BIT)
+#define GMAC1_INT_BITS				(GMAC1_RESERVED_INT_BIT | GMAC1_MIB_INT_BIT | \
+									 GMAC1_RX_PAUSE_ON_INT_BIT | GMAC1_TX_PAUSE_ON_INT_BIT |	\
+									 GMAC1_RX_PAUSE_OFF_INT_BIT | GMAC1_TX_PAUSE_OFF_INT_BIT | 	\
+									 GMAC1_RX_OVERRUN_INT_BIT | GMAC1_STATUS_CHANGE_INT_BIT)
+#endif
+
+#define CLASS_RX_FULL_INT_BITS		0xfffc
+
+/**********************************************************************
+ * GLOBAL_QUEUE_THRESHOLD_REG 	(offset 0x0070)
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_0070_2
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	toe_class	: 8;	// 31:24
+		unsigned int	intrq		: 8;	// 23:16
+		unsigned int    hwfq_empty	: 8;	// 15:8		Hardware Free Queue Empty Threshold
+		unsigned int    swfq_empty	: 8;	//  7:0  	Software Free Queue Empty Threshold
+#else
+#endif
+		unsigned int    swfq_empty	: 8;	//  7:0  	Software Free Queue Empty Threshold
+		unsigned int    hwfq_empty	: 8;	// 15:8		Hardware Free Queue Empty Threshold
+		unsigned int	intrq		: 8;	// 23:16
+		unsigned int	toe_class	: 8;	// 31:24
+	} bits;
+} QUEUE_THRESHOLD_T;
+
+
+/**********************************************************************
+ * GMAC DMA Control Register
+ * GMAC0 offset 0x8000
+ * GMAC1 offset 0xC000
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8000
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int    rd_enable		: 1;	// bit 31	Rx DMA Enable
+		unsigned int    td_enable		: 1;	// bit 30	Tx DMA Enable
+		unsigned int    loopback		: 1;	// bit 29	Loopback TxDMA to RxDMA
+		unsigned int    drop_small_ack	: 1;	// bit 28	1: Drop, 0: Accept
+		unsigned int	reserved		: 10;	// bit 27:18
+		unsigned int	rd_insert_bytes	: 2;	// bit 17:16
+		unsigned int	rd_prot			: 4;	// bit 15:12 DMA Protection Control
+		unsigned int	rd_burst_size	: 2;	// bit 11:10 DMA max burst size for every AHB request
+		unsigned int	rd_bus		    : 2;	// bit 9:8 	Peripheral Bus Width
+		unsigned int	td_prot			: 4;	// bit 7:4  TxDMA protection control
+		unsigned int	td_burst_size	: 2;	// bit 3:2	TxDMA max burst size for every AHB request
+		unsigned int	td_bus		    : 2;	// bit 1:0  Peripheral Bus Width
+#else
+		unsigned int	td_bus		    : 2;	// bit 1:0  Peripheral Bus Width
+		unsigned int	td_burst_size	: 2;	// bit 3:2	TxDMA max burst size for every AHB request
+		unsigned int	td_prot			: 4;	// bit 7:4  TxDMA protection control
+		unsigned int	rd_bus		    : 2;	// bit 9:8 	Peripheral Bus Width
+		unsigned int	rd_burst_size	: 2;	// bit 11:10 DMA max burst size for every AHB request
+		unsigned int	rd_prot			: 4;	// bit 15:12 DMA Protection Control
+		unsigned int	rd_insert_bytes	: 2;	// bit 17:16
+		unsigned int	reserved		: 10;	// bit 27:18
+		unsigned int    drop_small_ack	: 1;	// bit 28	1: Drop, 0: Accept
+		unsigned int    loopback		: 1;	// bit 29	Loopback TxDMA to RxDMA
+		unsigned int    td_enable		: 1;	// bit 30	Tx DMA Enable
+		unsigned int    rd_enable		: 1;	// bit 31	Rx DMA Enable
+#endif
+	} bits;
+} GMAC_DMA_CTRL_T;
+
+/**********************************************************************
+ * GMAC Tx Weighting Control Register 0
+ * GMAC0 offset 0x8004
+ * GMAC1 offset 0xC004
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8004
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int    reserved		: 8;	// bit 31:24
+		unsigned int    hw_tq3			: 6;	// bit 23:18	HW TX Queue 0
+		unsigned int    hw_tq2			: 6;	// bit 17:12	HW TX Queue 1
+		unsigned int    hw_tq1			: 6;	// bit 11:6		HW TX Queue 2
+		unsigned int    hw_tq0			: 6;	// bit 5:0		HW TX Queue 3
+#else
+		unsigned int    hw_tq0			: 6;	// bit 5:0		HW TX Queue 3
+		unsigned int    hw_tq1			: 6;	// bit 11:6		HW TX Queue 2
+		unsigned int    hw_tq2			: 6;	// bit 17:12	HW TX Queue 1
+		unsigned int    hw_tq3			: 6;	// bit 23:18	HW TX Queue 0
+		unsigned int    reserved		: 8;	// bit 31:24
+#endif
+	} bits;
+} GMAC_TX_WCR0_T;	// Weighting Control Register 0
+
+/**********************************************************************
+ * GMAC Tx Weighting Control Register 1
+ * GMAC0 offset 0x8008
+ * GMAC1 offset 0xC008
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8008
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int    reserved		: 2;	// bit 31:30
+		unsigned int    sw_tq5			: 5;	// bit 29:25	SW TX Queue 5
+		unsigned int    sw_tq4			: 5;	// bit 24:20	SW TX Queue 4
+		unsigned int    sw_tq3			: 5;	// bit 19:15	SW TX Queue 3
+		unsigned int    sw_tq2			: 5;	// bit 14:10	SW TX Queue 2
+		unsigned int    sw_tq1			: 5;	// bit 9:5		SW TX Queue 1
+		unsigned int    sw_tq0			: 5;	// bit 4:0		SW TX Queue 0
+#else
+		unsigned int    sw_tq0			: 5;	// bit 4:0		SW TX Queue 0
+		unsigned int    sw_tq1			: 5;	// bit 9:5		SW TX Queue 1
+		unsigned int    sw_tq2			: 5;	// bit 14:10	SW TX Queue 2
+		unsigned int    sw_tq3			: 5;	// bit 19:15	SW TX Queue 3
+		unsigned int    sw_tq4			: 5;	// bit 24:20	SW TX Queue 4
+		unsigned int    sw_tq5			: 5;	// bit 29:25	SW TX Queue 5
+		unsigned int    reserved		: 2;	// bit 31:30
+#endif
+	} bits;
+} GMAC_TX_WCR1_T;	// Weighting Control Register 1
+
+/**********************************************************************
+ * Queue Read/Write Pointer
+ * GMAC SW TX Queue 0~5 Read/Write Pointer register
+ * GMAC0 offset 0x800C ~ 0x8020
+ * GMAC1 offset 0xC00C ~ 0xC020
+ * GMAC HW TX Queue 0~3 Read/Write Pointer register
+ * GMAC0 offset 0x8024 ~ 0x8030
+ * GMAC1 offset 0xC024 ~ 0xC030
+ **********************************************************************/
+// see DMA_RWPTR_T structure
+
+/**********************************************************************
+ * GMAC DMA Tx First Description Address Register
+ * GMAC0 offset 0x8038
+ * GMAC1 offset 0xC038
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8038
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int td_first_des_ptr	: 28;	// bit 31:4	first descriptor address
+		unsigned int td_busy			:  1;	// bit 3	1: TxDMA busy; 0: TxDMA idle
+		unsigned int reserved			:  3;
+#else
+		unsigned int reserved			:  3;
+		unsigned int td_busy			:  1;	// bit 3	1: TxDMA busy; 0: TxDMA idle
+		unsigned int td_first_des_ptr	: 28;	// bit 31:4	first descriptor address
+#endif
+	} bits;
+} GMAC_TXDMA_FIRST_DESC_T;
+
+/**********************************************************************
+ * GMAC DMA Tx Current Description Address Register
+ * GMAC0 offset 0x803C
+ * GMAC1 offset 0xC03C
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_803C
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int td_curr_desc_ptr	: 28;	// bit 31:4	current descriptor address
+		unsigned int reserved			:  4;
+#else
+		unsigned int reserved			:  4;
+		unsigned int td_curr_desc_ptr	: 28;	// bit 31:4	current descriptor address
+#endif
+	} bits;
+} GMAC_TXDMA_CURR_DESC_T;
+
+/**********************************************************************
+ * GMAC DMA Tx Description Word 0 Register
+ * GMAC0 offset 0x8040
+ * GMAC1 offset 0xC040
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8040
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int reserved		: 1;	// bit 31
+		unsigned int derr			: 1;	// bit 30	 data error during processing this descriptor
+		unsigned int perr			: 1;	// bit 29	 protocol error during processing this descriptor
+		unsigned int status_rvd		: 6;	// bit 28:23 Tx Status, Reserved bits
+		unsigned int status_tx_ok	: 1;	// bit 22    Tx Status, 1: Successful 0: Failed
+		unsigned int desc_count 	: 6;	// bit 21:16 number of descriptors used for the current frame
+		unsigned int buffer_size 	: 16;	// bit 15:0  Transfer size
+#else
+		unsigned int buffer_size 	: 16;	// bit 15:0  Transfer size
+		unsigned int desc_count 	: 6;	// bit 21:16 number of descriptors used for the current frame
+		unsigned int status_tx_ok	: 1;	// bit 22    Tx Status, 1: Successful 0: Failed
+		unsigned int status_rvd		: 6;	// bit 28:23 Tx Status, Reserved bits
+		unsigned int perr			: 1;	// bit 29	 protocol error during processing this descriptor
+		unsigned int derr			: 1;	// bit 30	 data error during processing this descriptor
+		unsigned int reserved		: 1;	// bit 31
+#endif
+	} bits;
+} GMAC_TXDESC_0_T;
+
+/**********************************************************************
+ * GMAC DMA Tx Description Word 1 Register
+ * GMAC0 offset 0x8044
+ * GMAC1 offset 0xC044
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct txdesc_word1
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	reserved	: 9;	// bit 31:23 	Tx Flag, Reserved
+		unsigned int	ip_fixed_len: 1;	// bit 22
+		unsigned int	bypass_tss	: 1;	// bit 21
+		unsigned int	udp_chksum	: 1;	// bit 20		UDP Checksum Enable
+		unsigned int	tcp_chksum	: 1;	// bit 19		TCP Checksum Enable
+		unsigned int	ipv6_enable	: 1;	// bit 18		IPV6 Tx Enable
+		unsigned int	ip_chksum	: 1;	// bit 17		IPV4 Header Checksum Enable
+		unsigned int	mtu_enable	: 1;	// bit 16		TSS segmentation use MTU setting
+		unsigned int	byte_count	: 16;	// bit 15: 0	Tx Frame Byte Count
+#else
+		unsigned int	byte_count	: 16;	// bit 15: 0	Tx Frame Byte Count
+		unsigned int	mtu_enable	: 1;	// bit 16		TSS segmentation use MTU setting
+		unsigned int	ip_chksum	: 1;	// bit 17		IPV4 Header Checksum Enable
+		unsigned int	ipv6_enable	: 1;	// bit 18		IPV6 Tx Enable
+		unsigned int	tcp_chksum	: 1;	// bit 19		TCP Checksum Enable
+		unsigned int	udp_chksum	: 1;	// bit 20		UDP Checksum Enable
+		unsigned int	bypass_tss	: 1;	// bit 21
+		unsigned int	ip_fixed_len: 1;	// bit 22
+		unsigned int	reserved	: 9;	// bit 31:23 	Tx Flag, Reserved
+#endif
+	} bits;
+} GMAC_TXDESC_1_T;
+
+#define TSS_IP_FIXED_LEN_BIT	BIT(22)
+#define TSS_UDP_CHKSUM_BIT		BIT(20)
+#define TSS_TCP_CHKSUM_BIT		BIT(19)
+#define TSS_IPV6_ENABLE_BIT		BIT(18)
+#define TSS_IP_CHKSUM_BIT		BIT(17)
+#define TSS_MTU_ENABLE_BIT		BIT(16)
+
+/**********************************************************************
+ * GMAC DMA Tx Description Word 2 Register
+ * GMAC0 offset 0x8048
+ * GMAC1 offset 0xC048
+ **********************************************************************/
+typedef union
+{
+	unsigned int	bits32;
+	unsigned int 	buf_adr;
+} GMAC_TXDESC_2_T;
+
+/**********************************************************************
+ * GMAC DMA Tx Description Word 3 Register
+ * GMAC0 offset 0x804C
+ * GMAC1 offset 0xC04C
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct txdesc_word3
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	sof_eof		: 2;	// bit 31:30 	11: only one, 10: first, 01: last, 00: linking
+		unsigned int	eofie		: 1;	// bit 29		End of frame interrupt enable
+		unsigned int	reserved	: 18;	// bit 28:11
+		unsigned int	mtu_size	: 11;	// bit 10: 0	Tx Frame Byte Count
+#else
+		unsigned int	mtu_size	: 11;	// bit 10: 0	Tx Frame Byte Count
+		unsigned int	reserved	: 18;	// bit 28:11
+		unsigned int	eofie		: 1;	// bit 29		End of frame interrupt enable
+		unsigned int	sof_eof		: 2;	// bit 31:30 	11: only one, 10: first, 01: last, 00: linking
+#endif
+	} bits;
+} GMAC_TXDESC_3_T;
+#define SOF_EOF_BIT_MASK	0x3fffffff
+#define SOF_BIT				0x80000000
+#define EOF_BIT				0x40000000
+#define EOFIE_BIT			BIT(29)
+#define MTU_SIZE_BIT_MASK	0x7ff
+
+/**********************************************************************
+ * GMAC Tx Descriptor
+ **********************************************************************/
+typedef struct
+{
+	GMAC_TXDESC_0_T	word0;
+	GMAC_TXDESC_1_T	word1;
+	GMAC_TXDESC_2_T	word2;
+	GMAC_TXDESC_3_T	word3;
+} GMAC_TXDESC_T;
+
+
+/**********************************************************************
+ * GMAC DMA Rx First Description Address Register
+ * GMAC0 offset 0x8058
+ * GMAC1 offset 0xC058
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8058
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int rd_first_des_ptr	: 28;	// bit 31:4 first descriptor address
+		unsigned int rd_busy			:  1;	// bit 3	1-RxDMA busy; 0-RxDMA idle
+		unsigned int reserved			:  3;	// bit 2:0
+#else
+		unsigned int reserved			:  3;	// bit 2:0
+		unsigned int rd_busy			:  1;	// bit 3	1-RxDMA busy; 0-RxDMA idle
+		unsigned int rd_first_des_ptr	: 28;	// bit 31:4 first descriptor address
+#endif
+	} bits;
+} GMAC_RXDMA_FIRST_DESC_T;
+
+/**********************************************************************
+ * GMAC DMA Rx Current Description Address Register
+ * GMAC0 offset 0x805C
+ * GMAC1 offset 0xC05C
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_805C
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int rd_curr_des_ptr	: 28;	// bit 31:4 current descriptor address
+		unsigned int reserved			:  4;	// bit 3:0
+#else
+		unsigned int reserved			:  4;	// bit 3:0
+		unsigned int rd_curr_des_ptr	: 28;	// bit 31:4 current descriptor address
+#endif
+	} bits;
+} GMAC_RXDMA_CURR_DESC_T;
+
+/**********************************************************************
+ * GMAC DMA Rx Description Word 0 Register
+ * GMAC0 offset 0x8060
+ * GMAC1 offset 0xC060
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8060
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int drop			: 1;	// bit 31	 TOE/CIS Queue Full dropped packet to default queue
+		unsigned int derr			: 1;	// bit 30	 data error during processing this descriptor
+		unsigned int perr			: 1;	// bit 29	 protocol error during processing this descriptor
+		unsigned int chksum_status	: 3;	// bit 28:26 Check Sum Status
+		unsigned int status			: 4;	// bit 24:22 Status of rx frame
+		unsigned int desc_count 	: 6;	// bit 21:16 number of descriptors used for the current frame
+		unsigned int buffer_size 	: 16;	// bit 15:0  number of descriptors used for the current frame
+#else
+		unsigned int buffer_size 	: 16;	// bit 15:0  number of descriptors used for the current frame
+		unsigned int desc_count 	: 6;	// bit 21:16 number of descriptors used for the current frame
+		unsigned int status			: 4;	// bit 24:22 Status of rx frame
+		unsigned int chksum_status	: 3;	// bit 28:26 Check Sum Status
+		unsigned int perr			: 1;	// bit 29	 protocol error during processing this descriptor
+		unsigned int derr			: 1;	// bit 30	 data error during processing this descriptor
+		unsigned int drop			: 1;	// bit 31	 TOE/CIS Queue Full dropped packet to default queue
+#endif
+	} bits;
+} GMAC_RXDESC_0_T;
+
+#define		GMAC_RXDESC_0_T_derr				BIT(30)
+#define		GMAC_RXDESC_0_T_perr				BIT(29)
+#define		GMAC_RXDESC_0_T_chksum_status(x)	BIT((x+26))
+#define		GMAC_RXDESC_0_T_status(x)			BIT((x+22))
+#define		GMAC_RXDESC_0_T_desc_count(x)		BIT((x+16))
+
+#define	RX_CHKSUM_IP_UDP_TCP_OK			0
+#define	RX_CHKSUM_IP_OK_ONLY			1
+#define	RX_CHKSUM_NONE					2
+#define	RX_CHKSUM_IP_ERR_UNKNOWN		4
+#define	RX_CHKSUM_IP_ERR				5
+#define	RX_CHKSUM_TCP_UDP_ERR			6
+#define RX_CHKSUM_NUM					8
+
+#define RX_STATUS_GOOD_FRAME			0
+#define RX_STATUS_TOO_LONG_GOOD_CRC		1
+#define RX_STATUS_RUNT_FRAME			2
+#define RX_STATUS_SFD_NOT_FOUND			3
+#define RX_STATUS_CRC_ERROR				4
+#define RX_STATUS_TOO_LONG_BAD_CRC		5
+#define RX_STATUS_ALIGNMENT_ERROR		6
+#define RX_STATUS_TOO_LONG_BAD_ALIGN	7
+#define RX_STATUS_RX_ERR				8
+#define RX_STATUS_DA_FILTERED			9
+#define RX_STATUS_BUFFER_FULL			10
+#define RX_STATUS_NUM					16
+
+
+/**********************************************************************
+ * GMAC DMA Rx Description Word 1 Register
+ * GMAC0 offset 0x8064
+ * GMAC1 offset 0xC064
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct rxdesc_word1
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	sw_id		: 16;	// bit 31:16	Software ID
+		unsigned int	byte_count	: 16;	// bit 15: 0	Rx Frame Byte Count
+#else
+		unsigned int	byte_count	: 16;	// bit 15: 0	Rx Frame Byte Count
+		unsigned int	sw_id		: 16;	// bit 31:16	Software ID
+#endif
+	} bits;
+} GMAC_RXDESC_1_T;
+
+/**********************************************************************
+ * GMAC DMA Rx Description Word 2 Register
+ * GMAC0 offset 0x8068
+ * GMAC1 offset 0xC068
+ **********************************************************************/
+typedef union
+{
+	unsigned int	bits32;
+	unsigned int	buf_adr;
+} GMAC_RXDESC_2_T;
+
+#define RX_INSERT_NONE		0
+#define RX_INSERT_1_BYTE	1
+#define RX_INSERT_2_BYTE	2
+#define RX_INSERT_3_BYTE	3
+
+#define RX_INSERT_BYTES		RX_INSERT_2_BYTE
+/**********************************************************************
+ * GMAC DMA Rx Description Word 3 Register
+ * GMAC0 offset 0x806C
+ * GMAC1 offset 0xC06C
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct rxdesc_word3
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	sof_eof		: 2;	// bit 31:30 	11: only one, 10: first, 01: last, 00: linking
+		unsigned int	eofie		: 1;	// bit 29		End of frame interrupt enable
+		unsigned int	ctrl_flag	: 1;	// bit 28 		Control Flag is present
+		unsigned int	out_of_seq	: 1;	// bit 27		Out of Sequence packet
+		unsigned int	option		: 1;	// bit 26		IPV4 option or IPV6 extension header
+		unsigned int	abnormal	: 1;	// bit 25		abnormal case found
+		unsigned int	dup_ack		: 1;	// bit 24		Duplicated ACK detected
+		unsigned int	l7_offset	: 8;	// bit 23: 16	L7 data offset
+		unsigned int	l4_offset	: 8;	// bit 15: 8	L4 data offset
+		unsigned int	l3_offset	: 8;	// bit 7: 0		L3 data offset
+#else
+		unsigned int	l3_offset	: 8;	// bit 7: 0		L3 data offset
+		unsigned int	l4_offset	: 8;	// bit 15: 8	L4 data offset
+		unsigned int	l7_offset	: 8;	// bit 23: 16	L7 data offset
+		unsigned int	dup_ack		: 1;	// bit 24		Duplicated ACK detected
+		unsigned int	abnormal	: 1;	// bit 25		abnormal case found
+		unsigned int	option		: 1;	// bit 26		IPV4 option or IPV6 extension header
+		unsigned int	out_of_seq	: 1;	// bit 27		Out of Sequence packet
+		unsigned int	ctrl_flag	: 1;	// bit 28 		Control Flag is present
+		unsigned int	eofie		: 1;	// bit 29		End of frame interrupt enable
+		unsigned int	sof_eof		: 2;	// bit 31:30 	11: only one, 10: first, 01: last, 00: linking
+#endif
+	} bits;
+} GMAC_RXDESC_3_T;
+
+/**********************************************************************
+ * GMAC Rx Descriptor
+ **********************************************************************/
+typedef struct
+{
+	GMAC_RXDESC_0_T	word0;
+	GMAC_RXDESC_1_T	word1;
+	GMAC_RXDESC_2_T	word2;
+	GMAC_RXDESC_3_T	word3;
+} GMAC_RXDESC_T;
+
+/**********************************************************************
+ * GMAC Hash Engine Enable/Action Register 0 Offset Register
+ * GMAC0 offset 0x8070
+ * GMAC1 offset 0xC070
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8070
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	mr1en		: 1;	// bit 31		Enable Matching Rule 1
+		unsigned int	reserved1	: 1;	// bit 30
+		unsigned int	timing		: 3;	// bit 29:27
+		unsigned int	mr1_action	: 5;	// bit 26:22	Matching Rule 1 action offset
+		unsigned int	mr1hel		: 6;	// bit 21:16	match rule 1 hash entry size
+		unsigned int	mr0en		: 1;	// bit 15		Enable Matching Rule 0
+		unsigned int	reserved0	: 4;	// bit 14:11
+		unsigned int	mr0_action	: 5;	// bit 10:6		Matching Rule 0 action offset
+		unsigned int	mr0hel		: 6;	// bit 5:0		match rule 0 hash entry size
+#else
+		unsigned int	mr0hel		: 6;	// bit 5:0		match rule 0 hash entry size
+		unsigned int	mr0_action	: 5;	// bit 10:6		Matching Rule 0 action offset
+		unsigned int	reserved0	: 4;	// bit 14:11
+		unsigned int	mr0en		: 1;	// bit 15		Enable Matching Rule 0
+		unsigned int	mr1hel		: 6;	// bit 21:16	match rule 1 hash entry size
+		unsigned int	mr1_action	: 5;	// bit 26:22	Matching Rule 1 action offset
+		unsigned int	timing		: 3;	// bit 29:27
+		unsigned int	reserved1	: 1;	// bit 30
+		unsigned int	mr1en		: 1;	// bit 31		Enable Matching Rule 1
+#endif
+	} bits;
+} GMAC_HASH_ENABLE_REG0_T;
+
+/**********************************************************************
+ * GMAC Hash Engine Enable/Action Register 1 Offset Register
+ * GMAC0 offset 0x8074
+ * GMAC1 offset 0xC074
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8074
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	mr3en		: 1;	// bit 31		Enable Matching Rule 3
+		unsigned int	reserved3	: 4;	// bit 30:27
+		unsigned int	mr3_action	: 5;	// bit 26:22	Matching Rule 3 action offset
+		unsigned int	mr3hel		: 6;	// bit 21:16	match rule 3 hash entry size
+		unsigned int	mr2en		: 1;	// bit 15		Enable Matching Rule 2
+		unsigned int	reserved2	: 4;	// bit 14:11
+		unsigned int	mr2_action	: 5;	// bit 10:6		Matching Rule 2 action offset
+		unsigned int	mr2hel		: 6;	// bit 5:0		match rule 2 hash entry size
+#else
+		unsigned int	mr2hel		: 6;	// bit 5:0		match rule 2 hash entry size
+		unsigned int	mr2_action	: 5;	// bit 10:6		Matching Rule 2 action offset
+		unsigned int	reserved2	: 4;	// bit 14:11
+		unsigned int	mr2en		: 1;	// bit 15		Enable Matching Rule 2
+		unsigned int	mr3hel		: 6;	// bit 21:16	match rule 3 hash entry size
+		unsigned int	mr3_action	: 5;	// bit 26:22	Matching Rule 3 action offset
+		unsigned int	reserved1	: 4;	// bit 30:27
+		unsigned int	mr3en		: 1;	// bit 31		Enable Matching Rule 3
+#endif
+	} bits;
+} GMAC_HASH_ENABLE_REG1_T;
+
+
+/**********************************************************************
+ * GMAC Matching Rule Control Register 0
+ * GMAC0 offset 0x8078
+ * GMAC1 offset 0xC078
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_8078
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	l2			: 1;	// bit 31		L2 matching enable
+		unsigned int	l3			: 1;	// bit 30		L3 matching enable
+		unsigned int	l4			: 1;	// bit 29		L4 matching enable
+		unsigned int	l7			: 1;	// bit 28		L7 matching enable
+		unsigned int	port		: 1;	// bit 27		PORT ID matching enable
+		unsigned int	priority	: 3;	// bit 26:24	priority if multi-rules matched
+		unsigned int	da			: 1;	// bit 23		MAC DA enable
+		unsigned int	sa			: 1;	// bit 22		MAC SA enable
+		unsigned int	ether_type	: 1;	// bit 21		Ethernet type enable
+		unsigned int	vlan		: 1;	// bit 20		VLAN ID enable
+		unsigned int	pppoe		: 1;	// bit 19		PPPoE Session ID enable
+		unsigned int	reserved1	: 3;	// bit 18:16
+		unsigned int	ip_version	: 1;	// bit 15		0: IPV4, 1: IPV6
+		unsigned int	ip_hdr_len	: 1;	// bit 14		IPV4 Header length
+		unsigned int	flow_lable	: 1;	// bit 13		IPV6 Flow label
+		unsigned int	tos_traffic	: 1;	// bit 12		IPV4 TOS or IPV6 Traffice Class
+		unsigned int	reserved2	: 4;	// bit 11:8
+		unsigned int	sprx		: 8;	// bit 7:0		Support Protocol Register 7:0
+#else
+		unsigned int	sprx		: 8;	// bit 7:0		Support Protocol Register 7:0
+		unsigned int	reserved2	: 4;	// bit 11:8
+		unsigned int	tos_traffic	: 1;	// bit 12		IPV4 TOS or IPV6 Traffice Class
+		unsigned int	flow_lable	: 1;	// bit 13		IPV6 Flow label
+		unsigned int	ip_hdr_len	: 1;	// bit 14		IPV4 Header length
+		unsigned int	ip_version	: 1;	// bit 15		0: IPV4, 1: IPV6
+		unsigned int	reserved1	: 3;	// bit 18:16
+		unsigned int	pppoe		: 1;	// bit 19		PPPoE Session ID enable
+		unsigned int	vlan		: 1;	// bit 20		VLAN ID enable
+		unsigned int	ether_type	: 1;	// bit 21		Ethernet type enable
+		unsigned int	sa			: 1;	// bit 22		MAC SA enable
+		unsigned int	da			: 1;	// bit 23		MAC DA enable
+		unsigned int	priority	: 3;	// bit 26:24	priority if multi-rules matched
+		unsigned int	port		: 1;	// bit 27		PORT ID matching enable
+		unsigned int	l7			: 1;	// bit 28		L7 matching enable
+		unsigned int	l4			: 1;	// bit 29		L4 matching enable
+		unsigned int	l3			: 1;	// bit 30		L3 matching enable
+		unsigned int	l2			: 1;	// bit 31		L2 matching enable
+#endif
+	} bits;
+} GMAC_MRxCR0_T;
+
+#define MR_L2_BIT			BIT(31)
+#define MR_L3_BIT			BIT(30)
+#define MR_L4_BIT			BIT(29)
+#define MR_L7_BIT			BIT(28)
+#define MR_PORT_BIT			BIT(27)
+#define MR_PRIORITY_BIT		BIT(26)
+#define MR_DA_BIT			BIT(23)
+#define MR_SA_BIT			BIT(22)
+#define MR_ETHER_TYPE_BIT	BIT(21)
+#define MR_VLAN_BIT			BIT(20)
+#define MR_PPPOE_BIT		BIT(19)
+#define MR_IP_VER_BIT		BIT(15)
+#define MR_IP_HDR_LEN_BIT	BIT(14)
+#define MR_FLOW_LABLE_BIT	BIT(13)
+#define MR_TOS_TRAFFIC_BIT	BIT(12)
+#define MR_SPR_BIT(x)		BIT(x)
+#define MR_SPR_BITS		0xff
+
+/**********************************************************************
+ * GMAC Matching Rule Control Register 1
+ * GMAC0 offset 0x807C
+ * GMAC1 offset 0xC07C
+ **********************************************************************/
+ typedef union
+{
+	unsigned int bits32;
+	struct bit_807C
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int	sip			: 1;	// bit 31		Srce IP
+		unsigned int	sip_netmask	: 7;	// bit 30:24	Srce IP net mask, number of mask bits
+		unsigned int	dip			: 1;	// bit 23		Dest IP
+		unsigned int	dip_netmask	: 7;	// bit 22:16	Dest IP net mask, number of mask bits
+		unsigned int    l4_byte0_15	: 16;	// bit 15: 0
+#else
+		unsigned int    l4_byte0_15	: 16;	// bit 15: 0
+		unsigned int	dip_netmask	: 7;	// bit 22:16	Dest IP net mask, number of mask bits
+		unsigned int	dip			: 1;	// bit 23		Dest IP
+		unsigned int	sip_netmask	: 7;	// bit 30:24	Srce IP net mask, number of mask bits
+		unsigned int	sip			: 1;	// bit 31		Srce IP
+#endif
+	} bits;
+} GMAC_MRxCR1_T;
+
+/**********************************************************************
+ * GMAC Matching Rule Control Register 2
+ * GMAC0 offset 0x8080
+ * GMAC1 offset 0xC080
+ **********************************************************************/
+ typedef union
+{
+	unsigned int bits32;
+	struct bit_8080
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int    l4_byte16_24: 8;	// bit 31: 24
+		unsigned int    l7_byte0_23	: 24;	// bit 23:0
+#else
+		unsigned int    l7_byte0_23	: 24;	// bit 23:0
+		unsigned int    l4_byte16_24: 8;	// bit 31: 24
+#endif
+	} bits;
+} GMAC_MRxCR2_T;
+
+
+/**********************************************************************
+ * GMAC Support registers
+ * GMAC0 offset 0x80A8
+ * GMAC1 offset 0xC0A8
+ **********************************************************************/
+ typedef union
+{
+	unsigned int bits32;
+	struct bit_80A8
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int    reserved: 21;	// bit 31:11
+		unsigned int    swap	: 3;	// bit 10:8		Swap
+		unsigned int    protocol: 8;	// bit 7:0		Supported protocol
+#else
+		unsigned int    protocol: 8;	// bit 7:0		Supported protocol
+		unsigned int    swap	: 3;	// bit 10:8		Swap
+		unsigned int    reserved: 21;	// bit 31:11
+#endif
+	} bits;
+} GMAC_SPR_T;
+
+/**********************************************************************
+ * GMAC_AHB_WEIGHT registers
+ * GMAC0 offset 0x80C8
+ * GMAC1 offset 0xC0C8
+ **********************************************************************/
+ typedef union
+{
+	unsigned int bits32;
+	struct bit_80C8
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int    reserved		: 7;	// 31:25
+		unsigned int    tqDV_threshold	: 5;	// 24:20 DMA TqCtrl to Start tqDV FIFO Threshold
+		unsigned int    pre_req			: 5;	// 19:15 Rx Data Pre Request FIFO Threshold
+		unsigned int    tx_weight		: 5;	// 14:10
+		unsigned int    rx_weight		: 5;	// 9:5
+		unsigned int    hash_weight		: 5;	// 4:0
+#else
+		unsigned int    hash_weight		: 5;	// 4:0
+		unsigned int    rx_weight		: 5;	// 9:5
+		unsigned int    tx_weight		: 5;	// 14:10
+		unsigned int    pre_req			: 5;	// 19:15 Rx Data Pre Request FIFO Threshold
+		unsigned int    tqDV_threshold	: 5;	// 24:20 DMA TqCtrl to Start tqDV FIFO Threshold
+		unsigned int    reserved		: 7;	// 31:25
+#endif
+	} bits;
+} GMAC_AHB_WEIGHT_T;
+/**********************************************************************
+ * the register structure of GMAC
+ **********************************************************************/
+
+/**********************************************************************
+ * GMAC RX FLTR
+ * GMAC0 Offset 0xA00C
+ * GMAC1 Offset 0xE00C
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_000c
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int 				: 27;
+		unsigned int error			:  1;	/* enable receive of all error frames */
+		unsigned int promiscuous	:  1;   /* enable receive of all frames */
+		unsigned int broadcast		:  1;	/* enable receive of broadcast frames */
+		unsigned int multicast		:  1;	/* enable receive of multicast frames that pass multicast filter */
+		unsigned int unicast		:  1;	/* enable receive of unicast frames that are sent to STA address */
+#else
+		unsigned int unicast		:  1;	/* enable receive of unicast frames that are sent to STA address */
+		unsigned int multicast		:  1;	/* enable receive of multicast frames that pass multicast filter */
+		unsigned int broadcast		:  1;	/* enable receive of broadcast frames */
+		unsigned int promiscuous	:  1;   /* enable receive of all frames */
+		unsigned int error			:  1;	/* enable receive of all error frames */
+		unsigned int 				: 27;
+#endif
+	} bits;
+} GMAC_RX_FLTR_T;
+
+/**********************************************************************
+ * GMAC Configuration 0
+ * GMAC0 Offset 0xA018
+ * GMAC1 Offset 0xE018
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_0018
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int reserved		:  2;	// 31
+		unsigned int port1_chk_classq :  1;	// 29
+		unsigned int port0_chk_classq :  1;	// 28
+		unsigned int port1_chk_toeq	:  1;	// 27
+		unsigned int port0_chk_toeq	:  1;	// 26
+		unsigned int port1_chk_hwq	:  1;	// 25
+		unsigned int port0_chk_hwq	:  1;	// 24
+		unsigned int rx_err_detect  :  1;	// 23
+		unsigned int ipv6_exthdr_order: 1;	// 22
+		unsigned int rxc_inv		:  1;	// 21
+		unsigned int rgmm_edge		:  1;	// 20
+        unsigned int rx_tag_remove  :  1;   /* 19: Remove Rx VLAN tag */
+        unsigned int ipv6_rx_chksum :  1;   /* 18: IPv6 RX Checksum enable */
+        unsigned int ipv4_rx_chksum :  1;   /* 17: IPv4 RX Checksum enable */
+        unsigned int rgmii_en       :  1;   /* 16: RGMII in-band status enable */
+		unsigned int tx_fc_en		:  1;	/* 15: TX flow control enable */
+		unsigned int rx_fc_en		:  1;	/* 14: RX flow control enable */
+		unsigned int sim_test		:  1;	/* 13: speed up timers in simulation */
+		unsigned int dis_col		:  1;	/* 12: disable 16 collisions abort function */
+		unsigned int dis_bkoff		:  1;	/* 11: disable back-off function */
+		unsigned int max_len		:  3;	/* 8-10 maximum receive frame length allowed */
+		unsigned int adj_ifg		:  4;	/* 4-7: adjust IFG from 96+/-56 */
+        unsigned int flow_ctrl      :  1;   /* 3: flow control also trigged by Rx queues */
+		unsigned int loop_back		:  1;	/* 2: transmit data loopback enable */
+		unsigned int dis_rx			:  1;	/* 1: disable receive */
+		unsigned int dis_tx			:  1;	/* 0: disable transmit */
+#else
+		unsigned int dis_tx			:  1;	/* 0: disable transmit */
+		unsigned int dis_rx			:  1;	/* 1: disable receive */
+		unsigned int loop_back		:  1;	/* 2: transmit data loopback enable */
+        unsigned int flow_ctrl      :  1;   /* 3: flow control also trigged by Rx queues */
+		unsigned int adj_ifg		:  4;	/* 4-7: adjust IFG from 96+/-56 */
+		unsigned int max_len		:  3;	/* 8-10 maximum receive frame length allowed */
+		unsigned int dis_bkoff		:  1;	/* 11: disable back-off function */
+		unsigned int dis_col		:  1;	/* 12: disable 16 collisions abort function */
+		unsigned int sim_test		:  1;	/* 13: speed up timers in simulation */
+		unsigned int rx_fc_en		:  1;	/* 14: RX flow control enable */
+		unsigned int tx_fc_en		:  1;	/* 15: TX flow control enable */
+        unsigned int rgmii_en       :  1;   /* 16: RGMII in-band status enable */
+        unsigned int ipv4_rx_chksum :  1;   /* 17: IPv4 RX Checksum enable */
+        unsigned int ipv6_rx_chksum :  1;   /* 18: IPv6 RX Checksum enable */
+        unsigned int rx_tag_remove  :  1;   /* 19: Remove Rx VLAN tag */
+		unsigned int rgmm_edge		:  1;	// 20
+		unsigned int rxc_inv		:  1;	// 21
+		unsigned int ipv6_exthdr_order: 1;	// 22
+		unsigned int rx_err_detect  :  1;	// 23
+		unsigned int port0_chk_hwq	:  1;	// 24
+		unsigned int port1_chk_hwq	:  1;	// 25
+		unsigned int port0_chk_toeq	:  1;	// 26
+		unsigned int port1_chk_toeq	:  1;	// 27
+		unsigned int port0_chk_classq :  1;	// 28
+		unsigned int port1_chk_classq :  1;	// 29
+		unsigned int reserved		:  2;	// 31
+#endif
+	} bits;
+} GMAC_CONFIG0_T;
+
+/**********************************************************************
+ * GMAC Configuration 1
+ * GMAC0 Offset 0xA01C
+ * GMAC1 Offset 0xE01C
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_001c
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int reserved		: 16;
+		unsigned int rel_threshold	: 8;	/* flow control release threshold */
+		unsigned int set_threshold	: 8; 	/* flow control set threshold */
+#else
+		unsigned int set_threshold	: 8; 	/* flow control set threshold */
+		unsigned int rel_threshold	: 8;	/* flow control release threshold */
+		unsigned int reserved		: 16;
+#endif
+	} bits;
+} GMAC_CONFIG1_T;
+
+#define GMAC_FLOWCTRL_SET_MAX		32
+#define GMAC_FLOWCTRL_SET_MIN		0
+#define GMAC_FLOWCTRL_RELEASE_MAX	32
+#define GMAC_FLOWCTRL_RELEASE_MIN	0
+
+/**********************************************************************
+ * GMAC Configuration 2
+ * GMAC0 Offset 0xA020
+ * GMAC1 Offset 0xE020
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_0020
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int rel_threshold	: 16;	/* flow control release threshold */
+		unsigned int set_threshold	: 16; 	/* flow control set threshold */
+#else
+		unsigned int set_threshold	: 16; 	/* flow control set threshold */
+		unsigned int rel_threshold	: 16;	/* flow control release threshold */
+#endif
+	} bits;
+} GMAC_CONFIG2_T;
+
+/**********************************************************************
+ * GMAC Configuration 3
+ * GMAC0 Offset 0xA024
+ * GMAC1 Offset 0xE024
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_0024
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int rel_threshold	: 16;	/* flow control release threshold */
+		unsigned int set_threshold	: 16; 	/* flow control set threshold */
+#else
+		unsigned int set_threshold	: 16; 	/* flow control set threshold */
+		unsigned int rel_threshold	: 16;	/* flow control release threshold */
+#endif
+	} bits;
+} GMAC_CONFIG3_T;
+
+
+/**********************************************************************
+ * GMAC STATUS
+ * GMAC0 Offset 0xA02C
+ * GMAC1 Offset 0xE02C
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit1_002c
+	{
+#if (BIG_ENDIAN==1)
+		unsigned int 				: 25;
+		unsigned int mii_rmii		:  2;   /* PHY interface type */
+		unsigned int reserved		:  1;
+		unsigned int duplex			:  1;	/* duplex mode */
+		unsigned int speed			:  2;	/* link speed(00->2.5M 01->25M 10->125M) */
+		unsigned int link			:  1;	/* link status */
+#else
+		unsigned int link			:  1;	/* link status */
+		unsigned int speed			:  2;	/* link speed(00->2.5M 01->25M 10->125M) */
+		unsigned int duplex			:  1;	/* duplex mode */
+		unsigned int reserved		:  1;
+		unsigned int mii_rmii		:  2;   /* PHY interface type */
+		unsigned int 				: 25;
+#endif
+	} bits;
+} GMAC_STATUS_T;
+
+#define GMAC_SPEED_10			0
+#define GMAC_SPEED_100			1
+#define GMAC_SPEED_1000			2
+
+#define GMAC_PHY_MII			0
+#define GMAC_PHY_GMII			1
+#define GMAC_PHY_RGMII_100		2
+#define GMAC_PHY_RGMII_1000		3
+
+/**********************************************************************
+ * Queue Header
+ *	(1) TOE Queue Header
+ *	(2) Non-TOE Queue Header
+ *	(3) Interrupt Queue Header
+ *
+ * memory Layout
+ *	TOE Queue Header
+ *	 0x60003000 +---------------------------+ 0x0000
+ *				|     TOE Queue 0 Header	|
+ *				|         8 * 4 Bytes	    |
+ *				+---------------------------+ 0x0020
+ *				|     TOE Queue 1 Header  	|
+ *				|         8 * 4 Bytes		|
+ *				+---------------------------+ 0x0040
+ *				|   	......  			|
+ *				|      						|
+ *				+---------------------------+
+ *
+ *	Non TOE Queue Header
+ *	 0x60002000 +---------------------------+ 0x0000
+ *				|   Default Queue 0 Header  |
+ *				|         2 * 4 Bytes		|
+ *				+---------------------------+ 0x0008
+ *				|   Default Queue 1 Header	|
+ *				|         2 * 4 Bytes		|
+ *				+---------------------------+ 0x0010
+ *				|   Classification Queue 0	|
+ *				|      	  2 * 4 Bytes		|
+ *				+---------------------------+
+ *				|   Classification Queue 1	|
+ *				|      	  2 * 4 Bytes		|
+ *				+---------------------------+ (n * 8 + 0x10)
+ *				|   		...				|
+ *				|      	  2 * 4 Bytes		|
+ *				+---------------------------+ (13 * 8 + 0x10)
+ *				|   Classification Queue 13	|
+ *				|      	  2 * 4 Bytes		|
+ *				+---------------------------+ 0x80
+ * 				|      Interrupt Queue 0	|
+ *				|      	  2 * 4 Bytes		|
+ *				+---------------------------+
+ * 				|      Interrupt Queue 1	|
+ *				|      	  2 * 4 Bytes		|
+ *				+---------------------------+
+ * 				|      Interrupt Queue 2	|
+ *				|      	  2 * 4 Bytes		|
+ *				+---------------------------+
+ * 				|      Interrupt Queue 3	|
+ *				|      	  2 * 4 Bytes		|
+ *				+---------------------------+
+ *
+ **********************************************************************/
+#define TOE_QUEUE_HDR_ADDR(n)		(TOE_TOE_QUE_HDR_BASE + n * 32)
+#define TOE_Q_HDR_AREA_END			(TOE_QUEUE_HDR_ADDR(TOE_TOE_QUEUE_MAX+1))
+#define TOE_DEFAULT_Q0_HDR_BASE		(TOE_NONTOE_QUE_HDR_BASE + 0x00)
+#define TOE_DEFAULT_Q1_HDR_BASE		(TOE_NONTOE_QUE_HDR_BASE + 0x08)
+#define TOE_CLASS_Q_HDR_BASE		(TOE_NONTOE_QUE_HDR_BASE + 0x10)
+#define TOE_INTR_Q_HDR_BASE			(TOE_NONTOE_QUE_HDR_BASE + 0x80)
+#define INTERRUPT_QUEUE_HDR_ADDR(n)	(TOE_INTR_Q_HDR_BASE + n * 8)
+#define NONTOE_Q_HDR_AREA_END		(INTERRUPT_QUEUE_HDR_ADDR(TOE_INTR_QUEUE_MAX+1))
+/**********************************************************************
+ * TOE Queue Header Word 0
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	unsigned int base_size;
+} TOE_QHDR0_T;
+
+#define TOE_QHDR0_BASE_MASK 	(~0x0f)
+
+/**********************************************************************
+ * TOE Queue Header Word 1
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_qhdr1
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int wptr			: 16;	// bit 31:16
+		unsigned int rptr			: 16;	// bit 15:0
+#else
+		unsigned int rptr			: 16;	// bit 15:0
+		unsigned int wptr			: 16;	// bit 31:16
+#endif
+	} bits;
+} TOE_QHDR1_T;
+
+/**********************************************************************
+ * TOE Queue Header Word 2
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_qhdr2
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int usd			: 1;	// bit 31		0: if no data assembled yet
+		unsigned int ctl			: 1;	// bit 30		1: have control flag bits (except ack)
+		unsigned int osq			: 1;	// bit 29		1: out of sequence
+		unsigned int sat			: 1;	// bit 28		1: SeqCnt > SeqThreshold, or AckCnt > AckThreshold
+		unsigned int ip_opt			: 1;	// bit 27		1: have IPV4 option or IPV6 Extension header
+		unsigned int tcp_opt		: 1;	// bit 26		1: Have TCP option
+		unsigned int abn			: 1;	// bit 25		1: Abnormal case Found
+		unsigned int dack			: 1;	// bit 24		1: Duplicated ACK
+		unsigned int reserved		: 7;	// bit 23:17
+		unsigned int TotalPktSize	: 17;	// bit 16: 0	Total packet size
+#else
+		unsigned int TotalPktSize	: 17;	// bit 16: 0	Total packet size
+		unsigned int reserved		: 7;	// bit 23:17
+		unsigned int dack			: 1;	// bit 24		1: Duplicated ACK
+		unsigned int abn			: 1;	// bit 25		1: Abnormal case Found
+		unsigned int tcp_opt		: 1;	// bit 26		1: Have TCP option
+		unsigned int ip_opt			: 1;	// bit 27		1: have IPV4 option or IPV6 Extension header
+		unsigned int sat			: 1;	// bit 28		1: SeqCnt > SeqThreshold, or AckCnt > AckThreshold
+		unsigned int osq			: 1;	// bit 29		1: out of sequence
+		unsigned int ctl			: 1;	// bit 30		1: have control flag bits (except ack)
+		unsigned int usd			: 1;	// bit 31		0: if no data assembled yet
+#endif
+	} bits;
+} TOE_QHDR2_T;
+
+/**********************************************************************
+ * TOE Queue Header Word 3
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	unsigned int seq_num;
+} TOE_QHDR3_T;
+
+/**********************************************************************
+ * TOE Queue Header Word 4
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	unsigned int ack_num;
+} TOE_QHDR4_T;
+
+/**********************************************************************
+ * TOE Queue Header Word 5
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_qhdr5
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int SeqCnt		: 16;	// bit 31:16
+		unsigned int AckCnt		: 16;	// bit 15:0
+#else
+		unsigned int AckCnt		: 16;	// bit 15:0
+		unsigned int SeqCnt		: 16;	// bit 31:16
+#endif
+	} bits;
+} TOE_QHDR5_T;
+
+/**********************************************************************
+ * TOE Queue Header Word 6
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_qhdr6
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int MaxPktSize	: 14;	// bit 31:18
+		unsigned int iq_num		: 2;	// bit 17:16
+		unsigned int WinSize	: 16;	// bit 15:0
+#else
+		unsigned int WinSize	: 16;	// bit 15:0
+		unsigned int iq_num		: 2;	// bit 17:16
+		unsigned int MaxPktSize	: 14;	// bit 31:18
+#endif
+	} bits;
+} TOE_QHDR6_T;
+
+/**********************************************************************
+ * TOE Queue Header Word 7
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_qhdr7
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int SeqThreshold	: 16;	// bit 31:16
+		unsigned int AckThreshold	: 16;	// bit 15:0
+#else
+		unsigned int AckThreshold	: 16;	// bit 15:0
+		unsigned int SeqThreshold	: 16;	// bit 31:16
+#endif
+	} bits;
+} TOE_QHDR7_T;
+
+/**********************************************************************
+ * TOE Queue Header
+ **********************************************************************/
+typedef struct
+{
+	TOE_QHDR0_T		word0;
+	TOE_QHDR1_T		word1;
+	TOE_QHDR2_T		word2;
+	TOE_QHDR3_T		word3;
+	TOE_QHDR4_T		word4;
+	TOE_QHDR5_T		word5;
+	TOE_QHDR6_T		word6;
+	TOE_QHDR7_T		word7;
+} TOE_QHDR_T;
+
+/**********************************************************************
+ * NONTOE Queue Header Word 0
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	unsigned int base_size;
+} NONTOE_QHDR0_T;
+
+#define NONTOE_QHDR0_BASE_MASK 	(~0x0f)
+
+/**********************************************************************
+ * NONTOE Queue Header Word 1
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_nonqhdr1
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int wptr			: 16;	// bit 31:16
+		unsigned int rptr			: 16;	// bit 15:0
+#else
+		unsigned int rptr			: 16;	// bit 15:0
+		unsigned int wptr			: 16;	// bit 31:16
+#endif
+	} bits;
+} NONTOE_QHDR1_T;
+
+/**********************************************************************
+ * Non-TOE Queue Header
+ **********************************************************************/
+typedef struct
+{
+	NONTOE_QHDR0_T		word0;
+	NONTOE_QHDR1_T		word1;
+} NONTOE_QHDR_T;
+
+/**********************************************************************
+ * Interrupt Queue Header Word 0
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_intrqhdr0
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int wptr		: 16;	// bit 31:16	Write Pointer where hw stopped
+		unsigned int win_size	: 16;	// bit 15:0 	Descriptor Ring Size
+#else
+		unsigned int win_size	: 16;	// bit 15:0 	Descriptor Ring Size
+		unsigned int wptr		: 16;	// bit 31:16	Write Pointer where hw stopped
+#endif
+	} bits;
+} INTR_QHDR0_T;
+
+/**********************************************************************
+ * Interrupt Queue Header Word 1
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_intrqhdr1
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int ctl			: 1;	// bit 31		1: have control flag bits (except ack)
+		unsigned int osq			: 1;	// bit 30		1: out of sequence
+		unsigned int sat			: 1;	// bit 29		1: SeqCnt > SeqThreshold, or AckCnt > AckThreshold
+		unsigned int ip_opt			: 1;	// bit 28		1: have IPV4 option or IPV6 Extension header
+		unsigned int tcp_opt		: 1;	// bit 27		1: Have TCP option
+		unsigned int abn			: 1;	// bit 26		1: Abnormal case Found
+		unsigned int dack			: 1;	// bit 25		1: Duplicated ACK
+		unsigned int tcp_qid		: 8;	// bit 24:17	TCP Queue ID
+		unsigned int TotalPktSize	: 17;	// bit 16: 0	Total packet size
+#else
+		unsigned int TotalPktSize	: 17;	// bit 16: 0	Total packet size
+		unsigned int tcp_qid		: 8;	// bit 24:17	TCP Queue ID
+		unsigned int dack			: 1;	// bit 25		1: Duplicated ACK
+		unsigned int abn			: 1;	// bit 26		1: Abnormal case Found
+		unsigned int tcp_opt		: 1;	// bit 27		1: Have TCP option
+		unsigned int ip_opt			: 1;	// bit 28		1: have IPV4 option or IPV6 Extension header
+		unsigned int sat			: 1;	// bit 29		1: SeqCnt > SeqThreshold, or AckCnt > AckThreshold
+		unsigned int osq			: 1;	// bit 30		1: out of sequence
+		unsigned int ctl			: 1;	// bit 31		1: have control flag bits (except ack)
+#endif
+	} bits;
+} INTR_QHDR1_T;
+
+/**********************************************************************
+ * Interrupt Queue Header Word 2
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	unsigned int seq_num;
+} INTR_QHDR2_T;
+
+/**********************************************************************
+ * Interrupt Queue Header Word 3
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	unsigned int ack_num;
+} INTR_QHDR3_T;
+
+/**********************************************************************
+ * Interrupt Queue Header Word 4
+ **********************************************************************/
+typedef union
+{
+	unsigned int bits32;
+	struct bit_intrqhdr4
+	{
+#if (BIG_ENDIAN==1)
+
+		unsigned int SeqCnt		: 16;	// bit 31:16	Seq# change since last seq# intr.
+		unsigned int AckCnt		: 16;	// bit 15:0     Ack# change since last ack# intr.
+#else
+		unsigned int AckCnt		: 16;	// bit 15:0		Ack# change since last ack# intr.
+		unsigned int SeqCnt		: 16;	// bit 31:16	Seq# change since last seq# intr.
+#endif
+	} bits;
+} INTR_QHDR4_T;
+
+/**********************************************************************
+ * Interrupt Queue Header
+ **********************************************************************/
+typedef struct
+{
+	INTR_QHDR0_T		word0;
+	INTR_QHDR1_T		word1;
+	INTR_QHDR2_T		word2;
+	INTR_QHDR3_T		word3;
+	INTR_QHDR4_T		word4;
+	unsigned int		word5;
+	unsigned int		word6;
+	unsigned int		word7;
+} INTR_QHDR_T;
+
+/**********************************************************************
+ * GMAC Conf
+ **********************************************************************/
+typedef struct gmac_conf {
+	struct net_device *dev;
+	int portmap;
+	int vid;
+	int flag;     /* 1: active  0: non-active */
+} sys_gmac_conf;
+
+/**********************************************************************
+ * GMAC private data
+ **********************************************************************/
+typedef struct {
+	unsigned int		rwptr_reg;
+	unsigned int		desc_base;
+	unsigned int		total_desc_num;
+	unsigned short		finished_idx;
+	GMAC_TXDESC_T		*curr_tx_desc;
+	GMAC_TXDESC_T		*curr_finished_desc;
+	struct sk_buff		*tx_skb[TX_DESC_NUM];
+	unsigned long		total_sent;
+	unsigned long		total_finished;
+	unsigned long		intr_cnt;
+} GMAC_SWTXQ_T;
+
+typedef struct {
+	unsigned int		desc_base;
+	unsigned long 		eof_cnt;
+} GMAC_HWTXQ_T;
+
+typedef struct gmac_private{
+	struct net_device	*dev;
+	unsigned int		existed;
+	unsigned int		port_id;	// 0 or 1
+	unsigned int		base_addr;
+	unsigned int		dma_base_addr;
+	unsigned char		*mac_addr1;
+	unsigned char		*mac_addr2;
+	unsigned int		swtxq_desc_base;
+	unsigned int		hwtxq_desc_base;
+	GMAC_SWTXQ_T		swtxq[TOE_SW_TXQ_NUM];
+	GMAC_HWTXQ_T		hwtxq[TOE_HW_TXQ_NUM];
+	NONTOE_QHDR_T		*default_qhdr;
+	unsigned int		default_desc_base;
+	unsigned int		default_desc_num;
+	unsigned int		rx_curr_desc;
+	DMA_RWPTR_T			rx_rwptr;
+	struct sk_buff		*curr_rx_skb;
+	dma_addr_t			default_desc_base_dma;
+	dma_addr_t			swtxq_desc_base_dma;
+	dma_addr_t			hwtxq_desc_base_dma;
+	unsigned int		irq;
+	unsigned int		flow_control_enable	;
+	unsigned int		pre_phy_status;
+	unsigned int		full_duplex_cfg;
+	unsigned int		speed_cfg;
+	unsigned int		auto_nego_cfg;
+	unsigned int		full_duplex_status;
+	unsigned int		speed_status;
+	unsigned int		phy_mode;	/* 0->MII 1->GMII 2->RGMII(10/100) 3->RGMII(1000) */
+	unsigned int		phy_addr;
+	unsigned int		intr0_enabled;	// 1: enabled
+	unsigned int		intr1_enabled;	// 1: enabled
+	unsigned int		intr2_enabled;	// 1: enabled
+	unsigned int		intr3_enabled;	// 1: enabled
+	unsigned int		intr4_enabled;	// 1: enabled
+//	unsigned int		intr4_enabled_1;	// 1: enabled
+	unsigned int		intr0_selected;	// 1: selected
+	unsigned int		intr1_selected;	// 1: selected
+	unsigned int		intr2_selected;	// 1: selected
+	unsigned int		intr3_selected;	// 1: selected
+	unsigned int		intr4_selected;	// 1: selected
+	// void 				(*gmac_rcv_handler)(struct sk_buff *, int);
+	struct net_device_stats ifStatics;
+	unsigned long		txDerr_cnt[GMAC_NUM];
+	unsigned long		txPerr_cnt[GMAC_NUM];
+	unsigned long		RxDerr_cnt[GMAC_NUM];
+	unsigned long		RxPerr_cnt[GMAC_NUM];
+	unsigned int		isr_rx_cnt;
+	unsigned int		isr_tx_cnt;
+	unsigned long		rx_discard;
+	unsigned long		rx_error;
+	unsigned long		rx_mcast;
+	unsigned long		rx_bcast;
+	unsigned long		rx_status_cnt[8];
+	unsigned long		rx_chksum_cnt[8];
+	unsigned long		rx_sta1_ucast;	// for STA 1 MAC Address
+	unsigned long		rx_sta2_ucast;	// for STA 2 MAC Address
+	unsigned long		mib_full_cnt;
+	unsigned long		rx_pause_on_cnt;
+	unsigned long		tx_pause_on_cnt;
+	unsigned long		rx_pause_off_cnt;
+	unsigned long		tx_pause_off_cnt;
+	unsigned long		rx_overrun_cnt;
+	unsigned long		status_changed_cnt;
+	unsigned long		default_q_cnt;
+	unsigned long		hw_fq_empty_cnt;
+	unsigned long		sw_fq_empty_cnt;
+	unsigned long		default_q_intr_cnt;
+	pid_t               thr_pid;
+	wait_queue_head_t   thr_wait;
+	struct completion   thr_exited;
+    spinlock_t          lock;
+    int                 time_to_die;
+    int					operation;
+#ifdef SL351x_GMAC_WORKAROUND
+    unsigned long		short_frames_cnt;
+#endif
+}GMAC_INFO_T ;
+
+typedef struct toe_private {
+	unsigned int	swfq_desc_base;
+	unsigned int	hwfq_desc_base;
+	unsigned int	hwfq_buf_base;
+//	unsigned int	toe_desc_base[TOE_TOE_QUEUE_NUM];
+//	unsigned int	toe_desc_num;
+//	unsigned int	class_desc_base;
+//	unsigned int	class_desc_num;
+//	unsigned int	intr_desc_base;
+//	unsigned int	intr_desc_num;
+//	unsigned int	intr_buf_base;
+	DMA_RWPTR_T		fq_rx_rwptr;
+	GMAC_INFO_T		gmac[GMAC_NUM];
+	dma_addr_t		sw_freeq_desc_base_dma;
+	dma_addr_t		hw_freeq_desc_base_dma;
+	dma_addr_t		hwfq_buf_base_dma;
+	dma_addr_t		hwfq_buf_end_dma;
+//	dma_addr_t		toe_desc_base_dma[TOE_TOE_QUEUE_NUM];
+//	dma_addr_t		class_desc_base_dma;
+//	dma_addr_t		intr_desc_base_dma;
+//	dma_addr_t		intr_buf_base_dma;
+//	unsigned long	toe_iq_intr_full_cnt[TOE_INTR_QUEUE_NUM];
+//	unsigned long	toe_iq_intr_cnt[TOE_INTR_QUEUE_NUM];
+//	unsigned long	toe_q_intr_full_cnt[TOE_TOE_QUEUE_NUM];
+//	unsigned long	class_q_intr_full_cnt[TOE_CLASS_QUEUE_NUM];
+//	unsigned long	class_q_intr_cnt[TOE_CLASS_QUEUE_NUM];
+} TOE_INFO_T;
+
+extern TOE_INFO_T toe_private_data;
+
+#define GMAC_PORT0	0
+#define GMAC_PORT1	1
+/**********************************************************************
+ * PHY Definition
+ **********************************************************************/
+#define HPHY_ADDR   			0x01
+#define GPHY_ADDR   			0x02
+
+enum phy_state
+{
+    LINK_DOWN   = 0,
+    LINK_UP     = 1
+};
+
+/* transmit timeout value */
+
+#endif //_GMAC_SL351x_H
--- /dev/null
+++ b/include/asm-arm/arch-sl2312/sl351x_hash_cfg.h
@@ -0,0 +1,365 @@
+/*-----------------------------------------------------------------------------------
+*	sl351x_hash_cfg.h
+*
+*	Description:
+*	
+*	History:
+*
+*	9/14/2005	Gary Chen	Create
+*
+*-------------------------------------------------------------------------------------*/
+#ifndef _SL351x_HASH_CFG_H_
+#define _SL351x_HASH_CFG_H_	1
+
+// #define NAT_DEBUG_MSG	1
+// #define DEBUG_NAT_MIXED_HW_SW_TX	1
+#ifdef DEBUG_NAT_MIXED_HW_SW_TX
+	// #define NAT_DEBUG_LAN_HASH_TIMEOUT	1
+	// #define NAT_DEBUG_WAN_HASH_TIMEOUT	1
+#endif
+
+#define IPIV(a,b,c,d)		((a<<24)+(b<<16)+(c<<8)+d)
+#define	IPIV1(a)			((a>>24)&0xff)
+#define	IPIV2(a)			((a>>16)&0xff)
+#define IPIV3(a)			((a>>8)&0xff)
+#define IPIV4(a)			((a)&0xff)
+
+#define HASH_MAX_BYTES			64	// 128
+#define HASH_ACTION_DWORDS		9
+#define HASH_MAX_DWORDS			(HASH_MAX_BYTES / sizeof(u32))
+#define HASH_MAX_KEY_DWORD		(HASH_MAX_DWORDS - HASH_ACTION_DWORDS)
+#define HASH_INIT_KEY			0x534C4F52
+#define HASH_BITS				12	// 12 : Normal, 7: Simulation
+#define HASH_TOTAL_ENTRIES		(1 << HASH_BITS)
+#define HASH_MAX_ENTRIES		(1 << 12)
+#define HASH_TOE_ENTRIES		(HASH_TOTAL_ENTRIES >> 5)
+#define HASH_BITS_MASK			((1 << HASH_BITS) - 1)
+
+#define hash_lock(lock)			// spin_lock_bh(lock)
+#define hash_unlock(lock)		// spin_unlock_bh(lock)
+
+/*----------------------------------------------------------------------
+ *  special macro
+ ----------------------------------------------------------------------*/
+#define HASH_PUSH_WORD(cp, data)	{*cp++ = (((u16)(data))     ) & 0xff; 	\
+							 		*cp++ = (((u16)(data)) >> 8) & 0xff;} 
+#define HASH_PUSH_DWORD(cp, data)	{*cp++ = (u8)(((u32)(data))      ) & 0xff;	\
+							  		*cp++ = (u8)(((u32)(data)) >>  8) & 0xff;	\
+							  		*cp++ = (u8)(((u32)(data)) >> 16) & 0xff;	\
+							  		*cp++ = (u8)(((u32)(data)) >> 24) & 0xff;}
+#define HASH_PUSH_BYTE(cp, data)	{*cp++ = ((u8)(data)) & 0xff;}
+
+/*----------------------------------------------------------------------
+ *  key
+ ----------------------------------------------------------------------*/
+typedef struct {
+	u8		port;
+	u16		Ethertype;
+	u8		da[6];
+	u8		sa[6];
+	u16		pppoe_sid;	
+	u16		vlan_id;	
+	u8		ipv4_hdrlen;	
+	u8		ip_tos;	
+	u8		ip_protocol;	
+	u32		ipv6_flow_label;
+	u8		sip[16];
+	u8		dip[16];
+	//__u32			sip[4];
+	//__u32			dip[4];
+	u8		l4_bytes[24];
+	u8		l7_bytes[24];
+	u8		ipv6;	// 1: IPv6, 0: IPV4
+} ENTRY_KEY_T;
+
+/*----------------------------------------------------------------------
+ *  key for NAT
+ *	Note: packed
+ ----------------------------------------------------------------------*/
+typedef struct {
+	u16		Ethertype;		// not used
+	u8		port_id;
+	u8		rule_id;
+	u8		ip_protocol;
+	u8		reserved1;		// ip_tos, not used
+	u16		reserved2;		// not used
+	u32		sip;
+	u32		dip;
+	u16		sport;
+	u16		dport;
+} NAT_KEY_T;
+
+#define NAT_KEY_DWORD_SIZE	(sizeof(NAT_KEY_T)/sizeof(u32))
+#define NAT_KEY_SIZE		(sizeof(NAT_KEY_T))
+
+/*----------------------------------------------------------------------
+ *  key for NAT
+ *	Note: packed
+ ----------------------------------------------------------------------*/
+typedef struct {
+	u16		Ethertype;		// not used
+	u8		port_id;
+	u8		rule_id;
+	u8		ip_protocol;
+	u8		reserved1;		// ip_tos, not used
+	u16		reserved2;		// not used
+	u32		sip;
+	u32		dip;
+	u16		reserved3;
+	u16		protocol;
+	u16		reserved4;
+	u16		call_id;
+} GRE_KEY_T;
+
+#define GRE_KEY_DWORD_SIZE	(sizeof(GRE_KEY_T)/sizeof(u32))
+#define GRE_KEY_SIZE		(sizeof(GRE_KEY_T))
+/*----------------------------------------------------------------------
+ *  key present or not
+ ----------------------------------------------------------------------*/
+typedef struct {
+	u32		port			: 1;
+	u32		Ethertype		: 1;
+	u32		da				: 1;
+	u32		sa				: 1;
+	u32		pppoe_sid		: 1;	
+	u32		vlan_id			: 1;	
+	u32		ipv4_hdrlen		: 1;	
+	u32		ip_tos			: 1;
+	u32		ip_protocol		: 1;	
+	u32		ipv6_flow_label	: 1;
+	u32		sip				: 1;
+	u32		dip				: 1;
+	u32		l4_bytes_0_3	: 1;
+	u32		l4_bytes_4_7	: 1;
+	u32		l4_bytes_8_11	: 1;
+	u32		l4_bytes_12_15	: 1;
+	u32		l4_bytes_16_19	: 1;
+	u32		l4_bytes_20_23	: 1;
+	u32		l7_bytes_0_3	: 1;
+	u32		l7_bytes_4_7	: 1;
+	u32		l7_bytes_8_11	: 1;
+	u32		l7_bytes_12_15	: 1;
+	u32		l7_bytes_16_19	: 1;
+	u32		l7_bytes_20_23	: 1;
+	u32		reserved		: 8;
+} KEY_FIELD_T;
+
+/*----------------------------------------------------------------------
+ *  action
+ ----------------------------------------------------------------------*/
+typedef struct {
+	u32		reserved0	: 5;	// bit 0:4
+	u32		pppoe		: 2;	// bit 5:6
+	u32		vlan		: 2;	// bit 7:8
+	u32		sa			: 1;	// bit 9
+	u32		da			: 1;	// bit 10
+	u32		Dport		: 1;	// bit 11
+	u32		Sport		: 1;	// bit 12
+	u32		Dip			: 1;	// bit 13
+	u32		Sip			: 1;	// bit 14
+	u32		sw_id		: 1;	// bit 15
+	u32		frag		: 1;	// bit 16
+	u32		option		: 1;	// bit 17
+	u32		ttl_0		: 1;	// bit 18
+	u32		ttl_1		: 1;	// bit 19
+	u32		mtu			: 1;	// bit 20
+	u32		exception	: 1;	// bit 21
+	u32		srce_qid	: 1;	// bit 22
+	u32		discard		: 1;	// bit 23
+	u32		dest_qid	: 8;	// bit 24:31
+} ENTRY_ACTION_T;
+
+#define ACTION_DISCARD_BIT		BIT(23)
+#define ACTION_SRCE_QID_BIT		BIT(22)
+#define ACTION_EXCEPTION_BIT	BIT(21)
+#define ACTION_MTU_BIT			BIT(20)
+#define ACTION_TTL_1_BIT		BIT(19)
+#define ACTION_TTL_0_BIT		BIT(18)
+#define ACTION_IP_OPTION		BIT(17)
+#define ACTION_FRAG_BIT			BIT(16)
+#define ACTION_SWID_BIT			BIT(15)
+#define ACTION_SIP_BIT			BIT(14)
+#define ACTION_DIP_BIT			BIT(13)
+#define ACTION_SPORT_BIT		BIT(12)
+#define ACTION_DPORT_BIT		BIT(11)
+#define ACTION_DA_BIT			BIT(10)
+#define ACTION_SA_BIT			BIT(9)
+#define ACTION_VLAN_DEL_BIT		BIT(8)
+#define ACTION_VLAN_INS_BIT		BIT(7)
+#define ACTION_PPPOE_DEL_BIT	BIT(6)
+#define ACTION_PPPOE_INS_BIT	BIT(5)
+#define ACTION_L4_THIRD_BIT		BIT(4)
+#define ACTION_L4_FOURTH_BIT	BIT(3)
+
+#define NAT_ACTION_BITS			(ACTION_SRCE_QID_BIT  | ACTION_EXCEPTION_BIT |	\
+								ACTION_TTL_1_BIT | ACTION_TTL_0_BIT | 			\
+								ACTION_IP_OPTION | ACTION_FRAG_BIT |			\
+								ACTION_DA_BIT | ACTION_SA_BIT)
+#define NAT_LAN2WAN_ACTIONS		(NAT_ACTION_BITS | ACTION_SIP_BIT | ACTION_SPORT_BIT)
+#define NAT_WAN2LAN_ACTIONS		(NAT_ACTION_BITS | ACTION_DIP_BIT | ACTION_DPORT_BIT)
+#define NAT_PPPOE_LAN2WAN_ACTIONS	(NAT_LAN2WAN_ACTIONS | ACTION_PPPOE_INS_BIT)
+#define NAT_PPPOE_WAN2LAN_ACTIONS	(NAT_WAN2LAN_ACTIONS | ACTION_PPPOE_DEL_BIT)
+#define NAT_PPTP_LAN2WAN_ACTIONS	(NAT_ACTION_BITS | ACTION_SIP_BIT | ACTION_L4_FOURTH_BIT)
+#define NAT_PPTP_WAN2LAN_ACTIONS	(NAT_ACTION_BITS | ACTION_DIP_BIT | ACTION_L4_FOURTH_BIT)
+#define NAT_PPPOE_PPTP_LAN2WAN_ACTIONS	(NAT_PPTP_LAN2WAN_ACTIONS | ACTION_PPPOE_INS_BIT)
+#define NAT_PPPOE_PPTP_WAN2LAN_ACTIONS	(NAT_PPTP_WAN2LAN_ACTIONS | ACTION_PPPOE_DEL_BIT)
+								
+/*----------------------------------------------------------------------
+ *  parameter
+ ----------------------------------------------------------------------*/
+typedef struct {
+	u8		da[6];
+	u8		sa[6];
+	u16		vlan;	
+	u16  	pppoe;	
+	u32		Sip;
+	u32		Dip;
+	u16  	Sport;	
+	u16  	Dport;	
+	u16  	sw_id;	
+	u16  	mtu;	
+} ENTRY_PARAM_T;
+
+/*----------------------------------------------------------------------
+ *  Hash Entry
+ ----------------------------------------------------------------------*/
+typedef struct {
+	char			rule;
+	ENTRY_KEY_T		key;
+	KEY_FIELD_T		key_present;
+	ENTRY_ACTION_T	action;
+	ENTRY_PARAM_T	param;
+	int				index;
+	int				total_dwords;
+} HASH_ENTRY_T;
+
+/*----------------------------------------------------------------------
+ *  NAT Hash Entry
+ ----------------------------------------------------------------------*/
+typedef struct {
+	short	counter;
+	short	interval;
+} HASH_TIMEOUT_T;
+
+/*----------------------------------------------------------------------
+ *  NAT Hash Entry for TCP/UDP protocol
+ ----------------------------------------------------------------------*/
+typedef struct {
+	NAT_KEY_T			key;
+	union {
+		u32				dword;
+		ENTRY_ACTION_T	bits;
+	} action;
+	ENTRY_PARAM_T		param;
+	HASH_TIMEOUT_T		tmo;	// used by software only, to use memory space efficiently
+} NAT_HASH_ENTRY_T;
+
+#define NAT_HASH_ENTRY_SIZE		(sizeof(NAT_HASH_ENTRY_T))
+
+/*----------------------------------------------------------------------
+ *  GRE Hash Entry for PPTP/GRE protocol
+ ----------------------------------------------------------------------*/
+typedef struct {
+	GRE_KEY_T			key;
+	union {
+		u32				dword;
+		ENTRY_ACTION_T	bits;
+	} action;
+	ENTRY_PARAM_T		param;
+	HASH_TIMEOUT_T		tmo;	// used by software only, to use memory space efficiently
+} GRE_HASH_ENTRY_T;
+
+#define GRE_HASH_ENTRY_SIZE		(sizeof(GRE_HASH_ENTRY_T))
+
+/*----------------------------------------------------------------------
+ *  External Variables
+ ----------------------------------------------------------------------*/
+extern char				hash_tables[HASH_TOTAL_ENTRIES][HASH_MAX_BYTES] __attribute__ ((aligned(16)));
+extern u32				hash_nat_owner_bits[HASH_TOTAL_ENTRIES/32];
+/*----------------------------------------------------------------------
+* hash_get_valid_flag
+*----------------------------------------------------------------------*/
+static inline int hash_get_valid_flag(int index)
+{
+	volatile u32 *hash_valid_bits_ptr = (volatile u32 *)TOE_V_BIT_BASE;
+
+#ifdef SL351x_GMAC_WORKAROUND
+	if (index >= (0x80 * 8) && index < (0x8c * 8))
+		return 1;
+#endif	
+	return (hash_valid_bits_ptr[index/32] & (1 << (index %32)));
+}
+
+/*----------------------------------------------------------------------
+* hash_get_nat_owner_flag
+*----------------------------------------------------------------------*/
+static inline int hash_get_nat_owner_flag(int index)
+{
+	return (hash_nat_owner_bits[index/32] & (1 << (index %32)));
+}
+
+/*----------------------------------------------------------------------
+* hash_validate_entry
+*----------------------------------------------------------------------*/
+static inline void hash_validate_entry(int index)
+{
+	volatile u32	*hash_valid_bits_ptr = (volatile u32 *)TOE_V_BIT_BASE;
+	register int	ptr = index/32, bits = 1 << (index %32);
+	
+	hash_valid_bits_ptr[ptr] |= bits;
+}
+
+/*----------------------------------------------------------------------
+* hash_invalidate_entry
+*----------------------------------------------------------------------*/
+static inline void hash_invalidate_entry(int index)
+{
+	volatile u32 *hash_valid_bits_ptr = (volatile u32 *)TOE_V_BIT_BASE;
+	register int	ptr = index/32, bits = 1 << (index %32);
+	
+	hash_valid_bits_ptr[ptr] &= ~(bits);
+}
+
+/*----------------------------------------------------------------------
+* hash_nat_enable_owner
+*----------------------------------------------------------------------*/
+static inline void hash_nat_enable_owner(int index)
+{
+	hash_nat_owner_bits[index/32] |= (1 << (index % 32));
+}
+
+/*----------------------------------------------------------------------
+* hash_nat_disable_owner
+*----------------------------------------------------------------------*/
+static inline void hash_nat_disable_owner(int index)
+{
+	hash_nat_owner_bits[index/32] &= ~(1 << (index % 32));
+}
+
+/*----------------------------------------------------------------------
+* hash_get_entry
+*----------------------------------------------------------------------*/
+static inline void *hash_get_entry(int index)
+{
+	return (void*) &hash_tables[index][0];
+}
+
+/*----------------------------------------------------------------------
+* Functions
+*----------------------------------------------------------------------*/
+extern int hash_add_entry(HASH_ENTRY_T *entry);
+extern void sl351x_hash_init(void);
+extern void hash_set_valid_flag(int index, int valid);
+extern void hash_set_nat_owner_flag(int index, int valid);
+extern void *hash_get_entry(int index);
+extern int hash_build_keys(u32 *destp, HASH_ENTRY_T *entry);
+extern void hash_build_nat_keys(u32 *destp, HASH_ENTRY_T *entry);
+extern int hash_write_entry(HASH_ENTRY_T *entry, u8 *key);
+extern int hash_add_entry(HASH_ENTRY_T *entry);
+extern	u16 hash_crc16(u16 crc, u8 *datap, u32 len);
+extern	u16 hash_gen_crc16(u8 *datap, u32 len);
+
+#endif // _SL351x_HASH_CFG_H_
+
+
+
--- /dev/null
+++ b/include/asm-arm/arch-sl2312/sl351x_nat_cfg.h
@@ -0,0 +1,211 @@
+/**************************************************************************
+* Copyright 2006 StorLink Semiconductors, Inc.  All rights reserved.                
+*--------------------------------------------------------------------------
+*	sl_nat_cfg.h
+*
+*	Description:
+*		- Define the Device Control Commands for NAT Configuration
+*	
+*	History:
+*
+*	4/28/2006	Gary Chen	Create
+*
+*-----------------------------------------------------------------------------*/
+#ifndef _SL351x_NAT_CFG_H_
+#define _SL351x_NAT_CFG_H_	1
+
+/*----------------------------------------------------------------------
+* Confiuration
+*----------------------------------------------------------------------*/
+#ifdef CONFIG_NETFILTER
+#define CONFIG_SL351x_NAT			1
+#undef CONFIG_SL351x_NAT
+#undef CONFIG_SL351x_SYSCTL
+#endif
+#define CONFIG_NAT_MAX_IP_NUM		4	// per device (eth0 or eth1)
+#define CONFIG_NAT_MAX_XPORT		64
+#define CONFIG_NAT_MAX_WRULE		16	// per Queue
+#define CONFIG_NAT_TXQ_NUM			4
+/*----------------------------------------------------------------------
+* Command set
+*----------------------------------------------------------------------*/
+#define SIOCDEVSL351x	SIOCDEVPRIVATE	// 0x89F0
+#define NATSSTATUS		0
+#define NATGSTATUS		1
+#define NATSETPORT		2
+#define NATGETPORT		3
+#define NATADDIP		4
+#define NATDELIP		5
+#define NATGETIP		6
+#define NATAXPORT		7
+#define NATDXPORT		8
+#define NATGXPORT		9
+#define NATSWEIGHT		10
+#define NATGWEIGHT		11
+#define NATAWRULE		12
+#define NATDWRULE		13
+#define NATGWRULE		14
+#define NATSDEFQ		15
+#define NATGDEFQ		16
+#define NATRMIPCFG		17		// remove IP config
+#define NATTESTENTRY	18
+#define NATSETMEM		19
+#define NATSHOWMEM		20
+/*----------------------------------------------------------------------
+* Command Structure
+*----------------------------------------------------------------------*/
+// Common Header
+typedef struct {
+	unsigned short		cmd;	// command ID
+	unsigned short		len;	// data length, excluding this header
+} NATCMD_HDR_T;
+
+// NATSSTATUS & NATGSTATUS commands
+typedef struct {
+	unsigned char		enable;
+} NAT_STATUS_T;	
+
+// NATSETPORT & NATGETPORT commands
+typedef struct {
+	unsigned char		portmap;
+} NAT_PORTCFG_T;
+
+typedef struct {
+	unsigned int		ipaddr;
+	unsigned int		netmask;
+} NAT_IP_ENTRY_T;
+
+// NATADDIP & NATDELIP commands
+typedef struct {
+	NAT_IP_ENTRY_T	entry;
+} NAT_IPCFG_T;
+
+// NATGETIP command
+typedef struct {
+	unsigned int	total;
+	NAT_IP_ENTRY_T	entry[CONFIG_NAT_MAX_IP_NUM];
+} NAT_IPCFG_ALL_T;
+
+typedef struct {
+	unsigned int		protocol;
+	unsigned short		sport_start;
+	unsigned short		sport_end;
+	unsigned short		dport_start;
+	unsigned short		dport_end;
+} NAT_XPORT_ENTRY_T;
+
+// NATAXPORT & NATDXPORT Commands
+typedef struct {
+	NAT_XPORT_ENTRY_T	entry;
+} NAT_XPORT_T;
+
+// NATGXPORT Command
+typedef struct {
+	unsigned int		total;
+	NAT_XPORT_ENTRY_T	entry[CONFIG_NAT_MAX_XPORT];
+} NAT_XPORT_ALL_T;
+
+// NATSWEIGHT & NATGWEIGHT Commands
+typedef struct {
+	unsigned char		weight[CONFIG_NAT_TXQ_NUM];
+} NAT_WEIGHT_T;
+
+typedef struct {
+	unsigned int		protocol;
+	unsigned int		sip_start;
+	unsigned int		sip_end;
+	unsigned int		dip_start;
+	unsigned int		dip_end;
+	unsigned short		sport_start;
+	unsigned short		sport_end;
+	unsigned short		dport_start;
+	unsigned short		dport_end;
+} NAT_WRULE_ENTRY_T;	
+
+// NATAWRULE & NATDWRULE Commands
+typedef struct {
+	unsigned int		qid;
+	NAT_WRULE_ENTRY_T	entry;
+} NAT_WRULE_T;
+
+// NATGWRULE Command
+typedef struct {
+	unsigned int		total;
+	NAT_WRULE_ENTRY_T	entry[CONFIG_NAT_MAX_WRULE];
+} NAT_WRULE_ALL_T;
+
+// NATSDEFQ & NATGDEFQ commands
+typedef struct {
+	unsigned int		qid;
+} NAT_QUEUE_T;	
+
+// NATTESTENTRY 
+typedef struct {
+	u_int16_t		cmd;	// command ID
+	u_int16_t		len;	// data length, excluding this header
+	u_int8_t		init_enable;
+} NAT_TESTENTRY_T;	
+	
+typedef union
+{
+	NAT_STATUS_T		status;
+	NAT_PORTCFG_T		portcfg;
+	NAT_IPCFG_T			ipcfg;
+	NAT_XPORT_T			xport;
+	NAT_WEIGHT_T		weight;
+	NAT_WRULE_T			wrule;
+	NAT_QUEUE_T			queue;
+	NAT_TESTENTRY_T init_entry;
+} NAT_REQ_E;
+	
+/*----------------------------------------------------------------------
+* NAT Configuration
+*	- Used by driver only
+*----------------------------------------------------------------------*/
+typedef struct {
+	unsigned int		enabled;
+	unsigned int		init_enabled;
+	unsigned int		tcp_udp_rule_id;
+	unsigned int		gre_rule_id;
+	unsigned int		lan_port;
+	unsigned int		wan_port;
+	unsigned int		default_hw_txq;
+	short				tcp_tmo_interval;
+	short				udp_tmo_interval;
+	short				gre_tmo_interval;
+	NAT_IPCFG_ALL_T		ipcfg[2];	// LAN/WAN port
+	NAT_XPORT_ALL_T		xport;
+	NAT_WEIGHT_T		weight;
+	NAT_WRULE_ALL_T		wrule[CONFIG_NAT_TXQ_NUM];
+} NAT_CFG_T;
+
+/*----------------------------------------------------------------------
+* NAT Control Block
+*	- Used by driver only
+*	- Stores LAN-IN or WAN-IN information
+*	- WAN-OUT and LAN-OUT driver use them to build up a hash entry
+*	- NOTES: To update this data structure, MUST take care of alignment issue
+*   -		 MUST make sure that the size of skbuff structure must 
+*            be larger than (40 + sizof(NAT_CB_T))
+*----------------------------------------------------------------------*/
+typedef struct {
+	unsigned short		tag;
+	unsigned char		sa[6];
+	unsigned int		sip;
+	unsigned int		dip;
+	unsigned short		sport;
+	unsigned short		dport;
+	unsigned char		pppoe_frame;
+	unsigned char		state;			// same to enum tcp_conntrack
+	unsigned char		reserved[2];
+} NAT_CB_T;
+
+#define NAT_CB_TAG		0x4C53	// "SL"
+#define NAT_CB_SIZE		sizeof(NAT_CB_T)
+// #define NAT_SKB_CB(skb)	(NAT_CB_T *)(((unsigned int)&((skb)->cb[40]) + 3) & ~3)  // for align 4
+#define NAT_SKB_CB(skb)	(NAT_CB_T *)&((skb)->cb[40])  // for align 4
+
+#endif // _SL351x_NAT_CFG_H_
+
+
+
--- /dev/null
+++ b/include/asm-arm/arch-sl2312/sl351x_toe.h
@@ -0,0 +1,88 @@
+/**************************************************************************
+* Copyright 2006 StorLink Semiconductors, Inc.  All rights reserved.
+*--------------------------------------------------------------------------
+* Name			: sl351x_toe.h
+* Description	:
+*		Define for TOE driver of Storlink SL351x
+*
+* History
+*
+*	Date		Writer		Description
+*----------------------------------------------------------------------------
+*				Xiaochong	Create
+*
+****************************************************************************/
+#ifndef __SL351x_TOE_H
+#define __SL351x_TOE_H	1
+#include <net/sock.h>
+#include <asm/arch/sl351x_gmac.h>
+#include <linux/timer.h>
+#include <linux/netdevice.h>
+#include <linux/ip.h>
+#include <linux/if_ether.h>
+/*
+ * TOE_CONN_T is data structure of tcp connection info, used at both
+ * device layer and kernel tcp layer
+ * skb is the jumbo frame
+ */
+
+struct toe_conn{
+	__u8	qid;		// connection qid 0~63.
+	__u8	ip_ver;		// 0: not used; 4: ipv4; 6: ipv6.
+	/* hash key of the connection */
+	__u16	source;
+	__u16	dest;
+	__u32	saddr[4];
+	__u32	daddr[4];
+
+	__u32	seq;
+	__u32	ack_seq;
+
+	/* these fields are used to set TOE QHDR */
+	__u32	ack_threshold;
+	__u32	seq_threshold;
+	__u16	max_pktsize;
+
+	/* used by sw toe, accumulated ack_seq of ack frames */
+	__u16	ack_cnt;
+	/* used by sw toe, accumulated data frames held at driver */
+	__u16	cur_pktsize;
+
+	__u8	status;
+#define	TCP_CONN_UNDEFINE		0X00
+#define	TCP_CONN_CREATION		0X01
+#define	TCP_CONN_CONNECTING		0X02
+#define	TCP_CONN_ESTABLISHED	0X04
+#define	TCP_CONN_RESET			0X08	// this is used for out-of-order
+                      			    	// or congestion window is small
+#define	TCP_CONN_CLOSING		0X10
+#define	TCP_CONN_CLOSED			0x11
+
+	__u16	hash_entry_index;	/* associated hash entry */
+
+	// one timer per connection. Otherwise all connections should be scanned
+	// in a timeout interrupt, and timeout interrupt is triggered no matter
+	// a connection is actually timeout or not.
+	struct timer_list	rx_timer;
+	unsigned long		last_rx_jiffies;
+	GMAC_INFO_T			*gmac;
+	struct net_device	*dev;
+
+	//	for generating pure ack frame.
+	struct ethhdr		l2_hdr;
+	struct iphdr		l3_hdr;
+
+	spinlock_t			conn_lock;
+	DMA_RWPTR_T			toeq_rwptr;
+	GMAC_RXDESC_T		*curr_desc;
+	struct sk_buff		*curr_rx_skb;
+};
+
+struct jumbo_frame {
+	struct sk_buff	*skb0;		// the head of jumbo frame
+	struct sk_buff	*tail;		// the tail of jumbo frame
+	struct iphdr	*iphdr0;	// the ip hdr of skb0.
+	struct tcphdr	*tcphdr0;	// the tcp hdr of skb0.
+};
+
+#endif // __SL351x_TOE_H
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2131,6 +2131,42 @@
 
 	  The safe and default value for this is N.
 
+config NET_GMAC
+	tristate "Storlink Gigabit Ethernet support"
+	depends on ARCH_SL2312
+	help
+	  This driver supports Storlink dual Gigabit Ethernet.
+
+config NET_SL2312
+	tristate "Storlink Gigabit Ethernet support"
+	depends on NET_GMAC
+	help
+	  This driver supports Storlink dual Gigabit Ethernet.
+
+config NET_SL351X
+	tristate "Storlink Lepus Gigabit Ethernet support"
+	depends on NET_GMAC
+	help
+	  This driver supports Storlink TOE and NAT dual Gigabit Ethernet.
+
+config SL2312_TSO
+	bool "Tx Segmentation Enable"
+	depends on NET_GMAC
+	help
+	  TBD
+
+config SL2312_MPAGE
+	bool "Tx Multipage Enable"
+	depends on NET_GMAC
+	help
+	  TBD
+
+config SL2312_RECVFILE
+	bool "Rx Multipage Enable"
+	depends on NET_GMAC
+	help
+	  TBD
+
 config DL2K
 	tristate "D-Link DL2000-based Gigabit Ethernet support"
 	depends on PCI
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -236,4 +236,8 @@
 
 obj-$(CONFIG_FS_ENET) += fs_enet/
 
-obj-$(CONFIG_NETXEN_NIC) += netxen/
+
+obj-$(CONFIG_NET_SL351X)+= sl351x_gmac.o sl351x_nat.o sl351x_hash.o sl351x_crc16.o sl351x_proc.o sl_switch.o
+obj-$(CONFIG_NET_SL2312)+= sl2312_emac.o
+
+