summaryrefslogtreecommitdiff
path: root/target/linux/ar7-2.4/patches/003-net_driver_cpmac.patch
blob: 3d6d1e523428c44a1c24ddf6707ef2a3579d8d43 (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
diff -urN linux.old/drivers/net/avalanche_cpmac/cpcommon_cpmac.c linux.dev/drivers/net/avalanche_cpmac/cpcommon_cpmac.c
--- linux.old/drivers/net/avalanche_cpmac/cpcommon_cpmac.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpcommon_cpmac.c	2005-07-12 02:48:41.996601000 +0200
@@ -0,0 +1,728 @@
+#ifndef _INC_CPCOMMON_C
+#define _INC_CPCOMMON_C
+
+#ifdef _CPHAL_CPMAC
+#include "cpremap_cpmac.c"
+#endif
+
+#ifdef _CPHAL_AAL5
+#include "cpremap_cpaal5.c"
+#endif
+
+#ifdef _CPHAL_CPSAR
+#include "cpremap_cpsar.c"
+#endif
+
+#ifdef _CPHAL_AAL2
+#include "cpremap_cpaal2.c"
+#endif
+
+/**
+@defgroup Common_Config_Params Common Configuration Parameters
+
+This section documents the configuration parameters that are valid across
+all CPHAL devices.
+@{
+*/
+/** This is the debug level.  The field is bit defined, such that the user
+should set to 1 all the bits corresponding to desired debug outputs.  The following 
+are the meanings for each debug bit:
+- bit0 (LSB): CPHAL Function Trace
+- b1 : OS Function call trace
+- b2 : Critical section entry/exit
+- b3 : Memory allocation/destruction
+- b4 : Detailed information in Rx path
+- b5 : Detailed information in Tx path
+- b6 : Extended error information
+- b7 : General info
+*/
+static const char pszDebug[]        = "debug";
+/** CPU Frequency. */
+/*static const char pszCpuFreq[]      = "CpuFreq";*/               /*MJH-030403*/
+/** Base address for the module. */
+static const char pszBase[]         = "base";
+/** Reset bit for the module. */
+static const char pszResetBit[]     = "reset_bit";
+/** Reset base address for the module. */
+static const char pszResetBase[]    = "ResetBase";
+/** Interrupt line for the module. */
+static const char pszIntLine[]      = "int_line";
+/** VLYNQ offset for the module.  Disregard if not using VLYNQ. */
+static const char pszOffset[]       = "offset";
+/** The OS may "Get" this parameter, which is a pointer
+    to a character string that indicates the version of CPHAL. */
+static const char pszVer[]          = "Version";
+/*@}*/
+
+/**
+@defgroup Common_Control_Params Common Keys for [os]Control()
+
+This section documents the keys used with the OS @c Control() interface that
+are required by CPHAL devices.
+
+@{
+*/
+/** Used to wait for an integer number of clock ticks, given as an integer
+    pointer in the @p Value parameter.  No actions are defined. */
+static const char pszSleep[]             = "Sleep";
+/** Requests the OS to flush it's IO buffers.  No actions are defined. */
+static const char pszSioFlush[]          = "SioFlush";
+/*@}*/
+
+static const char pszStateChange[]       = "StateChange";
+static const char pszStatus[]            = "Status";
+
+static const char pszGET[]               = "Get";
+static const char pszSET[]               = "Set";
+static const char pszCLEAR[]             = "Clear";
+static const char pszNULL[]              = "";
+static const char pszLocator[]           = "Locator";
+static const char pszOff[]               = "Off";
+static const char pszOn[]                = "On";
+static const char hcMaxFrags[]           = "MaxFrags";
+
+#ifdef _CPHAL_CPMAC
+
+/*  New method for string constants */
+const char hcClear[]  = "Clear";
+const char hcGet[]    = "Get";
+const char hcSet[]    = "Set";
+
+const char hcTick[]   = "Tick";
+
+static const CONTROL_KEY KeyCommon[] =
+   {
+     {""                   , enCommonStart},
+     {pszStatus            , enStatus},
+     {pszOff               , enOff},
+     {pszOn                , enOn},
+     {pszDebug             , enDebug},
+     {hcCpuFrequency       , enCpuFreq},                           /*MJH~030403*/
+     {""                   , enCommonEnd}
+   };
+#endif
+
+/**
+@defgroup Common_Statistics Statistics
+
+A broad array of module statistics is available.  Statistics values are accessed
+through the @c Control() interface of the CPHAL.  There are 5 different levels
+of statistics, each of which correspond to a unique set of data.  Furthermore,
+certain statistics data is indexed by using a channel number and Tx queue number.
+The following is a brief description of each statistics level, along with the
+indexes used for the level:
+
+- Level 0:  Hardware Statistics (index with channel)
+- Level 1:  CPHAL Software Statistics (channel, queue)
+- Level 2:  CPHAL Flags (channel, queue)
+- Level 3:  CPHAL Channel Configuration (channel)
+- Level 4:  CPHAL General Configuration (no index)
+
+The caller requests statistics information by providing a Key string to the
+@c Control() API in the following format: "Stats;[Level #];[Ch #];[Queue #]".
+The only valid Action parameter for statistics usage is "Get".
+
+Code Examples:
+@code
+unsigned int *StatsData;
+
+# Get Level 0 stats for Channel 1
+HalFunc->Control(OsDev->HalDev, "Stats;0;1", "Get", &StatsData);
+
+# Get Level 2 stats for Channel 0, Queue 0
+HalFunc->Control(OsDev->HalDev, "Stats;2;0;0", "Get", &StatsData);
+
+# Get Level 4 stats
+HalFunc->Control(OsDev->HalDev, "Stats;4", "Get", &StatsData);
+@endcode
+
+The information returned in the Value parameter of @c Control() is an
+array of pointers to strings.  The pointers are arranged in pairs.
+The first pointer is a pointer to a name string for a particular statistic.
+The next pointer is a pointer to a string containing the representation of
+the integer statistic value corresponding to the first pointer.  This is followed
+by another pair of pointers, and so on, until a NULL pointer is encountered.  The
+following is example code for processing the statistics data.  Note that the OS
+is responsible for freeing the memory passed back through the Value parameter of
+@c Control().
+
+@code
+unsigned int *StatsData;
+
+# Get Level 0 stats for Channel 1
+HalFunc->Control(OsDev->HalDev, "Stats;0;1", "Get", &StatsData);
+
+# output Statistics data
+PrintStats(StatsData);
+
+# the upper layer is responsible for freeing stats info
+free(&StatsPtr);
+
+...
+
+void PrintStats(unsigned int *StatsPtr)
+  {
+   while(*StatsPtr)
+     {
+      printf("%20s:",  (char *)*StatsPtr);
+      StatsPtr++;
+      printf("%11s\n", (char *)*StatsPtr);
+      StatsPtr++;
+     }
+   MySioFlush();
+  }
+@endcode
+
+Within each statistics level, there are several statistics defined.  The statistics that
+are common to every CPPI module are listed below.  In addition, each module may define
+extra statistics in each level, which will be documented within the module-specific
+documentation appendices.
+
+- Level 0 Statistics
+  - All level 0 statistics are module-specific.
+- Level 1 Statistics (CPHAL Software Statistics)
+  - DmaLenErrors: Incremented when the port DMA's more data than expected (per channel). (AAL5 Only)
+  - TxMisQCnt: Incremented when host queues a packet for transmission as the port finishes
+transmitting the previous last packet in the queue (per channel and queue).
+  - RxMisQCnt: Incremented when host queues adds buffers to a queue as the port finished the
+reception of the previous last packet in the queue (per channel).
+  - TxEOQCnt: Number of times the port has reached the end of the transmit queue (per channel and queue).
+  - RxEOQCnt: Number of times the port has reached the end of the receive queue (per channel).
+  - RxPacketsServiced: Number of received packets (per channel).
+  - TxPacketsServiced: Number of transmitted packets (per channel and queue).
+  - RxMaxServiced: Maximum number of packets that the CPHAL receive interrupt has serviced at a time (per channel).
+  - TxMaxServiced: Maximum number of packets that the CPHAL transmit interrupt has serviced at a time (per channel and queue).
+  - RxTotal: Total number of received packets, all channels.
+  - TxTotal: Total number of transmitted packets, all channels and queues.
+- Level 2 Statistics (CPHAL Flags)
+  - RcbPool: Pointer to receive descriptor pool (per channel).
+  - RxActQueueCount: Number of buffers currently available for receive (per channel).
+  - RxActQueueHead: Pointer to first buffer in receive queue (per channel).
+  - RxActQueueTail: Pointer to last buffer in receive queue (per channel).
+  - RxActive: 0 if inactive (no buffers available), or 1 if active (buffers available).
+  - RcbStart: Pointer to block of receive descriptors.
+  - RxTeardownPending: 1 if Rx teardown is pending but incomplete, 0 otherwise.
+  - TcbPool: Pointer to transmit descriptor pool (per channel and queue).
+  - TxActQueueCount: Number of buffers currently queued to be transmitted (per channel and queue).
+  - TxActQueueHead: Pointer to first buffer in transmit queue (per channel and queue).
+  - TxActQueueTail: Pointer to last buffer in transmit queue (per channel and queue).
+  - TxActive: 0 if inactive (no buffers to send), or 1 if active (buffers queued to send).
+  - TcbStart: Pointer to block of transmit descriptors.
+  - TxTeardownPending: 1 if Tx teardown is pending but incomplete, 0 otherwise.
+- Level 3 Statistics (CPHAL Channel Configuration)
+  - RxBufSize: Rx buffer size.
+  - RxBufferOffset: Rx buffer offset.
+  - RxNumBuffers: Number of Rx buffers.
+  - RxServiceMax: Maximum number of receive packets to service at a time.
+  - TxNumBuffers: Number of Tx buffer descriptors.
+  - TxNumQueues: Number of Tx queues to use.
+  - TxServiceMax: Maximum number of transmit packets to service at a time.
+- Level 4 Statistics (CPHAL General Configuration)
+  - Base Address: Base address of the module.
+  - Offset (VLYNQ): VLYNQ relative module offset.
+  - Interrupt Line: Interrupt number.
+  - Debug: Debug flag, 1 to enable debug.
+  - Inst: Instance number.
+*/
+
+/* 
+   Data Type 0 = int display
+   Data Type 1 = hex display
+   Data Type 2 = channel structure, int display
+   Data Type 3 = queue index and int display
+   Data Type 4 = queue index and hex display
+*/
+#if (defined(_CPHAL_AAL5) || defined(_CPHAL_CPMAC)) /* +GSG 030307 */
+static STATS_TABLE StatsTable0[] =
+  {
+#ifdef _CPHAL_AAL5
+   /* Name ,        Data Ptr,   Data Type */
+   {"Crc Errors",          0,          0},
+   {"Len Errors",          0,          0},
+   {"Abort Errors",        0,          0},
+   {"Starv Errors",        0,          0}
+#endif
+#ifdef _CPHAL_CPMAC
+   {"Rx Good Frames",      0,          0}
+#endif
+  };
+
+static STATS_TABLE StatsTable1[] =
+  {
+   /* Name ,        Data Ptr,   Data Type */
+   {"DmaLenErrors",        0,          0},
+   {"TxMisQCnt",           0,          3},
+   {"RxMisQCnt",           0,          0},
+   {"TxEOQCnt",            0,          3},
+   {"RxEOQCnt",            0,          0},
+   {"RxPacketsServiced",   0,          0},
+   {"TxPacketsServiced",   0,          3},
+   {"RxMaxServiced",       0,          0},
+   {"TxMaxServiced",       0,          3},
+   {"RxTotal",             0,          0},
+   {"TxTotal",             0,          0},
+  };
+
+static STATS_TABLE StatsTable2[] =
+  {
+   /* Name ,        Data Ptr,   Data Type */
+   {"RcbPool",             0,          1},
+   {"RxActQueueCount",     0,          0},
+   {"RxActQueueHead",      0,          1},
+   {"RxActQueueTail",      0,          1},
+   {"RxActive",            0,          0},
+   {"RcbStart",            0,          1},
+   {"RxTeardownPending",   0,          0},
+   {"TcbPool",             0,          4},
+   {"TxActQueueCount",     0,          3},
+   {"TxActQueueHead",      0,          4},
+   {"TxActQueueTail",      0,          4},
+   {"TxActive",            0,          3},
+   {"TcbStart",            0,          4},
+   {"TxTeardownPending",   0,          0}
+  };
+
+static STATS_TABLE StatsTable3[] =
+  {
+   /* Name ,        Data Ptr,   Data Type */
+   {"RxBufSize",           0,          2},
+   {"RxBufferOffset",      0,          2},
+   {"RxNumBuffers",        0,          2},
+   {"RxServiceMax",        0,          2},
+   {"TxNumBuffers",        0,          2},
+   {"TxNumQueues",         0,          2},
+   {"TxServiceMax",        0,          2},
+#ifdef _CPHAL_AAL5
+   {"CpcsUU",              0,          2},
+   {"Gfc",                 0,          2},
+   {"Clp",                 0,          2},
+   {"Pti",                 0,          2},
+   {"DaMask",              0,          2},
+   {"Priority",            0,          2},
+   {"PktType",             0,          2},
+   {"Vci",                 0,          2},
+   {"Vpi",                 0,          2},
+   {"CellRate",            0,          2},
+   {"QosType",             0,          2},
+   {"Mbs",                 0,          2},
+   {"Pcr",                 0,          2}
+#endif
+  };
+
+static STATS_TABLE StatsTable4[] =
+  {
+   {"Base Address",        0,          1},
+   {"Offset (VLYNQ)",      0,          0},
+   {"Interrupt Line",      0,          0},
+   {"Debug",               0,          0},
+   {"Instance",            0,          0},
+#ifdef _CPHAL_AAL5
+   {"UniNni",              0,          0}
+#endif
+  };
+
+static STATS_DB StatsDb[] =
+  {
+    {(sizeof(StatsTable0)/sizeof(STATS_TABLE)), StatsTable0},
+    {(sizeof(StatsTable1)/sizeof(STATS_TABLE)), StatsTable1},
+    {(sizeof(StatsTable2)/sizeof(STATS_TABLE)), StatsTable2},
+    {(sizeof(StatsTable3)/sizeof(STATS_TABLE)), StatsTable3},
+    {(sizeof(StatsTable4)/sizeof(STATS_TABLE)), StatsTable4}
+  };
+#endif /* +GSG 030307 */
+
+#ifdef _CPHAL_CPMAC /* +RC 3.02 */
+static void resetWait(HAL_DEVICE *HalDev)
+  {                                                                  /*+RC3.02*/
+  const int TickReset=64;
+  osfuncSleep((int*)&TickReset);
+  }                                                                  /*+RC3.02*/
+#endif /* +RC 3.02 */
+
+/* I only define the reset base function for the modules
+   that can perform a reset.  The AAL5 and AAL2 modules
+   do not perform a reset, that is done by the shared module
+   CPSAR */
+#if defined(_CPHAL_CPSAR) || defined(_CPHAL_CPMAC) || defined(_CPHAL_VDMAVT)
+/*
+ *  Determines the reset register address to be used for a particular device.
+ *  It will search the current device entry for Locator information.  If the
+ *  device is a root device, there will be no Locator information, and the
+ *  function will find and return the root reset register.  If a Locator value
+ *  is found, the function will search each VLYNQ device entry in the system
+ *  looking for a matching Locator.  Once it finds a VLYNQ device entry with
+ *  a matching Locator, it will extract the "ResetBase" parameter from that
+ *  VLYNQ device entry (thus every VLYNQ entry must have the ResetBase parameter).
+ *
+ *  @param  HalDev   CPHAL module instance. (set by xxxInitModule())
+ *  @param  ResetBase Pointer to integer address of reset register.
+ *
+ *  @return 0 OK, Non-zero not OK
+ */
+static int ResetBaseGet(HAL_DEVICE *HalDev, bit32u *ResetBase)
+  {
+   char *DeviceInfo = HalDev->DeviceInfo;
+   char *MyLocator, *NextLocator;
+   int Inst=1;
+   bit32u error_code;
+
+#ifdef __CPHAL_DEBUG
+   if (DBG(0))
+     {
+      dbgPrintf("[cpcommon]ResetBaseGet(HalDev:%08x, ResetBase:%08x)\n", (bit32u)HalDev, ResetBase);
+      osfuncSioFlush();
+     }
+#endif
+
+   error_code = HalDev->OsFunc->DeviceFindParmValue(DeviceInfo, "Locator", &MyLocator);
+   if (error_code)
+     {
+      /* if no Locator value, device is on the root, so get the "reset" device */
+      error_code = HalDev->OsFunc->DeviceFindInfo(0, "reset", &DeviceInfo);
+      if  (error_code)
+        {
+         return(EC_VAL_DEVICE_NOT_FOUND);
+        }
+
+      error_code = HalDev->OsFunc->DeviceFindParmUint(DeviceInfo, "base", ResetBase);
+      if (error_code)
+        {
+         return(EC_VAL_BASE_ADDR_NOT_FOUND);
+        }
+
+      *ResetBase = ((bit32u)PhysToVirtNoCache(*ResetBase));
+
+      /* found base address for root device, so we're done */
+      return (EC_NO_ERRORS);
+     }
+    else
+     {
+      /* we have a Locator value, so the device is remote */
+
+      /* Find a vlynq device with a matching locator value */
+      while ((HalDev->OsFunc->DeviceFindInfo(Inst, "vlynq", &DeviceInfo)) == EC_NO_ERRORS)
+        {
+         error_code = HalDev->OsFunc->DeviceFindParmValue(DeviceInfo, "Locator", &NextLocator);
+         if (error_code)
+           {
+            /* no Locator value for this VLYNQ, so move on */
+            continue;
+           }
+         if (HalDev->OsFunc->Strcmpi(MyLocator, NextLocator)==0)
+           {
+            /* we have found a VLYNQ with a matching Locator, so extract the ResetBase */
+            error_code = HalDev->OsFunc->DeviceFindParmUint(DeviceInfo, "ResetBase", ResetBase);
+            if (error_code)
+              {
+               return(EC_VAL_BASE_ADDR_NOT_FOUND);
+              }
+            *ResetBase = ((bit32u)PhysToVirtNoCache(*ResetBase));
+
+            /* found base address for root device, so we're done */
+            return (EC_NO_ERRORS);
+           }
+         Inst++;
+        } /* while */
+     } /* else */
+
+   return (EC_NO_ERRORS);
+  }
+#endif
+
+#ifndef _CPHAL_AAL2 /* + RC 3.02 */
+static bit32u ConfigGetCommon(HAL_DEVICE *HalDev)
+  {
+   bit32u ParmValue;
+   bit32 error_code;
+   char *DeviceInfo = HalDev->DeviceInfo;
+
+#ifdef __CPHAL_DEBUG
+   if (DBG(0))
+     {
+      dbgPrintf("[cpcommon]ConfigGetCommon(HalDev:%08x)\n", (bit32u)HalDev);
+      osfuncSioFlush();
+     }
+#endif
+
+   error_code = HalDev->OsFunc->DeviceFindParmUint(DeviceInfo, pszBase, &ParmValue);
+   if (error_code)
+     {
+      return(EC_FUNC_HAL_INIT|EC_VAL_BASE_ADDR_NOT_FOUND);
+     }
+   HalDev->dev_base = ((bit32u)PhysToVirtNoCache(ParmValue));
+
+#ifndef _CPHAL_AAL5
+#ifndef _CPHAL_AAL2
+   error_code = HalDev->OsFunc->DeviceFindParmUint(DeviceInfo, pszResetBit, &ParmValue);
+   if(error_code)
+     {
+      return(EC_FUNC_HAL_INIT|EC_VAL_RESET_BIT_NOT_FOUND);
+     }
+   HalDev->ResetBit = ParmValue;
+
+   /* Get reset base address */
+   error_code = ResetBaseGet(HalDev, &ParmValue);
+   if (error_code)
+     return(EC_FUNC_HAL_INIT|EC_VAL_RESET_BASE_NOT_FOUND);
+   HalDev->ResetBase = ParmValue;
+#endif
+#endif
+
+#ifndef _CPHAL_CPSAR
+   error_code = HalDev->OsFunc->DeviceFindParmUint(DeviceInfo, pszIntLine,&ParmValue);
+   if (error_code)
+     {
+      return(EC_FUNC_HAL_INIT|EC_VAL_INTERRUPT_NOT_FOUND);
+     }
+   HalDev->interrupt = ParmValue;
+#endif
+
+   /* only look for the offset if there is a Locator field, which indicates that
+      the module is a VLYNQ module */
+   error_code = HalDev->OsFunc->DeviceFindParmUint(DeviceInfo, pszLocator,&ParmValue);
+   if (!error_code)
+     {
+      error_code = HalDev->OsFunc->DeviceFindParmUint(DeviceInfo, pszOffset,&ParmValue);
+      if (error_code)
+        {
+         return(EC_FUNC_HAL_INIT|EC_VAL_OFFSET_NOT_FOUND);
+        }
+      HalDev->offset = ParmValue;
+     }
+    else
+      HalDev->offset = 0;
+
+   error_code = HalDev->OsFunc->DeviceFindParmUint(DeviceInfo, pszDebug, &ParmValue);
+   if (!error_code) HalDev->debug = ParmValue;
+
+   return (EC_NO_ERRORS);
+  }
+#endif /* +RC 3.02 */
+
+#ifdef _CPHAL_CPMAC /* +RC 3.02 */
+static void StatsInit(HAL_DEVICE *HalDev)                             /* +() RC3.02 */
+  {
+   /* even though these statistics may be for multiple channels and
+      queues, i need only configure the pointer to the beginning
+      of the array, and I can index from there if necessary */
+
+#ifdef _CPHAL_AAL5
+   StatsTable0[0].StatPtr  = &HalDev->Stats.CrcErrors[0];
+   StatsTable0[1].StatPtr  = &HalDev->Stats.LenErrors[0];
+   StatsTable0[2].StatPtr  = &HalDev->Stats.AbortErrors[0];
+   StatsTable0[3].StatPtr  = &HalDev->Stats.StarvErrors[0];
+
+   StatsTable1[0].StatPtr  = &HalDev->Stats.DmaLenErrors[0];
+   StatsTable1[1].StatPtr  = &HalDev->Stats.TxMisQCnt[0][0];
+   StatsTable1[2].StatPtr  = &HalDev->Stats.RxMisQCnt[0];
+   StatsTable1[3].StatPtr  = &HalDev->Stats.TxEOQCnt[0][0];
+   StatsTable1[4].StatPtr  = &HalDev->Stats.RxEOQCnt[0];
+   StatsTable1[5].StatPtr  = &HalDev->Stats.RxPacketsServiced[0];
+   StatsTable1[6].StatPtr  = &HalDev->Stats.TxPacketsServiced[0][0];
+   StatsTable1[7].StatPtr  = &HalDev->Stats.RxMaxServiced;
+   StatsTable1[8].StatPtr  = &HalDev->Stats.TxMaxServiced[0][0];
+   StatsTable1[9].StatPtr  = &HalDev->Stats.RxTotal;
+   StatsTable1[10].StatPtr = &HalDev->Stats.TxTotal;
+#endif
+
+#if (defined(_CPHAL_AAL5) || defined(_CPHAL_CPMAC))
+   StatsTable2[0].StatPtr  = (bit32u *)&HalDev->RcbPool[0];
+   StatsTable2[1].StatPtr  = &HalDev->RxActQueueCount[0];
+   StatsTable2[2].StatPtr  = (bit32u *)&HalDev->RxActQueueHead[0];
+   StatsTable2[3].StatPtr  = (bit32u *)&HalDev->RxActQueueTail[0];
+   StatsTable2[4].StatPtr  = &HalDev->RxActive[0];
+   StatsTable2[5].StatPtr  = (bit32u *)&HalDev->RcbStart[0];
+   StatsTable2[6].StatPtr  = &HalDev->RxTeardownPending[0];
+   StatsTable2[7].StatPtr  = (bit32u *)&HalDev->TcbPool[0][0];
+   StatsTable2[8].StatPtr  = &HalDev->TxActQueueCount[0][0];
+   StatsTable2[9].StatPtr  = (bit32u *)&HalDev->TxActQueueHead[0][0];
+   StatsTable2[10].StatPtr = (bit32u *)&HalDev->TxActQueueTail[0][0];
+   StatsTable2[11].StatPtr = &HalDev->TxActive[0][0];
+   StatsTable2[12].StatPtr = (bit32u *)&HalDev->TcbStart[0][0];
+   StatsTable2[13].StatPtr = &HalDev->TxTeardownPending[0];
+
+   StatsTable3[0].StatPtr  = &HalDev->ChData[0].RxBufSize;
+   StatsTable3[1].StatPtr  = &HalDev->ChData[0].RxBufferOffset;
+   StatsTable3[2].StatPtr  = &HalDev->ChData[0].RxNumBuffers;
+   StatsTable3[3].StatPtr  = &HalDev->ChData[0].RxServiceMax;
+   StatsTable3[4].StatPtr  = &HalDev->ChData[0].TxNumBuffers;
+   StatsTable3[5].StatPtr  = &HalDev->ChData[0].TxNumQueues;
+   StatsTable3[6].StatPtr  = &HalDev->ChData[0].TxServiceMax;
+#ifdef _CPHAL_AAL5
+   StatsTable3[7].StatPtr  = &HalDev->ChData[0].CpcsUU;
+   StatsTable3[8].StatPtr  = &HalDev->ChData[0].Gfc;
+   StatsTable3[9].StatPtr  = &HalDev->ChData[0].Clp;
+   StatsTable3[10].StatPtr = &HalDev->ChData[0].Pti;
+   StatsTable3[11].StatPtr = &HalDev->ChData[0].DaMask;
+   StatsTable3[12].StatPtr = &HalDev->ChData[0].Priority;
+   StatsTable3[13].StatPtr = &HalDev->ChData[0].PktType;
+   StatsTable3[14].StatPtr = &HalDev->ChData[0].Vci;
+   StatsTable3[15].StatPtr = &HalDev->ChData[0].Vpi;
+   StatsTable3[16].StatPtr = &HalDev->ChData[0].TxVc_CellRate;
+   StatsTable3[17].StatPtr = &HalDev->ChData[0].TxVc_QosType;
+   StatsTable3[18].StatPtr = &HalDev->ChData[0].TxVc_Mbs;
+   StatsTable3[19].StatPtr = &HalDev->ChData[0].TxVc_Pcr;
+#endif
+#endif
+
+   StatsTable4[0].StatPtr  = &HalDev->dev_base;
+   StatsTable4[1].StatPtr  = &HalDev->offset;
+   StatsTable4[2].StatPtr  = &HalDev->interrupt;
+   StatsTable4[3].StatPtr  = &HalDev->debug;
+   StatsTable4[4].StatPtr  = &HalDev->Inst;
+  }
+#endif /* +RC 3.02 */
+
+#ifndef _CPHAL_CPSAR /* +RC 3.02 */
+#ifndef _CPHAL_AAL2 /* +RC 3.02 */
+/*
+ *  Returns statistics information.
+ *
+ *  @param  HalDev   CPHAL module instance. (set by xxxInitModule())
+ *
+ *  @return 0
+ */
+static int StatsGet(HAL_DEVICE *HalDev, void **StatPtr, int Index, int Ch, int Queue)
+  {
+   int Size;
+   bit32u *AddrPtr;
+   char *DataPtr;
+   STATS_TABLE *StatsTable;
+   int i, NumberOfStats;
+
+#ifdef __CPHAL_DEBUG
+   if (DBG(0))
+     {
+      dbgPrintf("[cpcommon]StatsGet(HalDev:%08x, StatPtr:%08x)\n",
+                (bit32u)HalDev, (bit32u)StatPtr);
+      osfuncSioFlush();
+     }
+#endif
+
+   StatsTable = StatsDb[Index].StatTable;
+   NumberOfStats = StatsDb[Index].NumberOfStats;
+
+   Size = sizeof(bit32u)*((NumberOfStats*2)+1);
+   Size += (NumberOfStats*11);
+   *StatPtr = (bit32u *)HalDev->OsFunc->Malloc(Size);
+
+   AddrPtr = (bit32u *) *StatPtr;
+   DataPtr = (char *)AddrPtr;
+   DataPtr += sizeof(bit32u)*((NumberOfStats*2)+1);
+
+   for (i=0; i<NumberOfStats; i++)
+     {
+      *AddrPtr++ = (bit32u)StatsTable[i].StatName;
+      *AddrPtr++ = (bit32u)DataPtr;
+      if (&StatsTable[i].StatPtr[Ch] != 0)
+        {
+         switch(StatsTable[i].DataType)
+           {
+            case 0:
+              HalDev->OsFunc->Sprintf(DataPtr, "%d", (bit32u *)StatsTable[i].StatPtr[Ch]);
+              break;
+            case 1:
+              HalDev->OsFunc->Sprintf(DataPtr, "0x%x", (bit32u *)StatsTable[i].StatPtr[Ch]);
+              break;
+            case 2:
+              HalDev->OsFunc->Sprintf(DataPtr, "%d", *((bit32u *)StatsTable[i].StatPtr + (Ch * (sizeof(CHANNEL_INFO)/4))));
+              break;
+            case 3:
+              HalDev->OsFunc->Sprintf(DataPtr, "%d", *((bit32u *)StatsTable[i].StatPtr + (Ch*MAX_QUEUE)+Queue));
+              break;
+            case 4:
+              HalDev->OsFunc->Sprintf(DataPtr, "0x%x", *((bit32u *)StatsTable[i].StatPtr + (Ch*MAX_QUEUE)+Queue));
+              break;
+            default:
+              /* invalid data type, due to CPHAL programming error */
+              break;
+           }
+        }
+       else
+        {
+         /* invalid statistics pointer, probably was not initialized */
+        }
+      DataPtr += HalDev->OsFunc->Strlen(DataPtr) + 1;
+     }
+
+   *AddrPtr = (bit32u) 0;
+
+   return (EC_NO_ERRORS);
+  }
+#endif /* +RC 3.02 */
+#endif /* +RC 3.02 */
+
+#ifdef _CPHAL_CPMAC
+static void gpioFunctional(int base, int bit)
+  {                                                                  /*+RC3.02*/
+  bit32u GpioEnr = base + 0xC;
+  /*  To make functional, set to zero  */
+  *(volatile bit32u *)(GpioEnr) &= ~(1 << bit);                      /*+RC3.02*/
+  }                                                                  /*+RC3.02*/
+
+
+/*+RC3.02*/
+/* Common function, Checks to see if GPIO should be in functional mode */
+static void gpioCheck(HAL_DEVICE *HalDev, void *moduleDeviceInfo)
+  {                                                                  /*+RC3.02*/
+  int rc;
+  void *DeviceInfo;
+  char *pszMuxBits;
+  char pszMuxBit[20];
+  char *pszTmp;
+  char szMuxBit[20];
+  char *ptr;
+  int base;
+  int reset_bit;
+  int bit;
+  OS_FUNCTIONS *OsFunc = HalDev->OsFunc;
+
+  rc = OsFunc->DeviceFindParmValue(moduleDeviceInfo, "gpio_mux",&pszTmp);
+  if(rc) return;
+  /*  gpio entry found, get GPIO register info and make functional  */
+
+  /* temp copy until FinParmValue fixed */
+  ptr = &szMuxBit[0];
+  while ((*ptr++ = *pszTmp++));
+
+  pszMuxBits = &szMuxBit[0];
+
+  rc = OsFunc->DeviceFindInfo(0,"gpio",&DeviceInfo);
+  if(rc) return;
+
+  rc = OsFunc->DeviceFindParmUint(DeviceInfo, "base",&base);
+  if(rc) return;
+
+  rc = OsFunc->DeviceFindParmUint(DeviceInfo, "reset_bit",&reset_bit);
+  if(rc) return;
+
+  /* If GPIO still in reset, then exit  */
+  if((VOLATILE32(HalDev->ResetBase) & (1 << reset_bit)) == 0)
+    return;
+  /*  format for gpio_mux is  gpio_mux = <int>;<int>;<int>...*/
+  while (*pszMuxBits)
+    {
+    pszTmp = &pszMuxBit[0];
+    if(*pszMuxBits == ';') pszMuxBits++;
+    while ((*pszMuxBits != ';') && (*pszMuxBits != '\0'))
+      {
+      osfuncSioFlush();
+      /*If value not a number, skip */
+      if((*pszMuxBits < '0') || (*pszMuxBits > '9'))
+        pszMuxBits++;
+      else
+        *pszTmp++ = *pszMuxBits++;
+      }
+    *pszTmp = '\0';
+    bit = OsFunc->Strtoul(pszMuxBit, &pszTmp, 10);
+    gpioFunctional(base, bit);
+    resetWait(HalDev);  /* not sure if this is needed */
+    }
+  }                                                                  /*+RC3.02*/
+#endif  /* CPMAC  */
+
+#ifdef _CPHAL_AAL5
+const char hcSarFrequency[] = "SarFreq";
+#endif
+
+#endif  /* _INC  */
diff -urN linux.old/drivers/net/avalanche_cpmac/cpcommon_cpmac.h linux.dev/drivers/net/avalanche_cpmac/cpcommon_cpmac.h
--- linux.old/drivers/net/avalanche_cpmac/cpcommon_cpmac.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpcommon_cpmac.h	2005-07-12 02:48:41.996601000 +0200
@@ -0,0 +1,79 @@
+#ifndef _INC_CPCOMMON_H
+#define _INC_CPCOMMON_H
+
+#define VOLATILE32(addr)  (*(volatile bit32u *)(addr))
+#ifndef dbgPrintf
+#define dbgPrintf HalDev->OsFunc->Printf
+#endif
+
+#define ChannelUpdate(Field) if(HalChn->Field != 0xFFFFFFFF) HalDev->ChData[Ch].Field = HalChn->Field
+
+#define DBG(level)  (HalDev->debug & (1<<(level)))
+/*
+#define DBG0()      DBG(0)
+#define DBG1()      DBG(1)
+#define DBG2()      DBG(2)
+#define DBG3()      DBG(3)
+#define DBG4()      DBG(4)
+#define DBG5()      DBG(5)
+#define DBG6()      DBG(6)
+#define DBG7()      DBG(7)
+*/
+
+/*
+ *  List of defined actions for use with Control().
+ */
+typedef enum 
+  {
+   enGET=0,     /**< Get the value associated with a key */
+   enSET,       /**< Set the value associates with a key */
+   enCLEAR,     /**<Clear the value */ 
+   enNULL       /**< No data action, used to initiate a service or send a message */
+  }ACTION;
+
+/*
+ *  Enumerated hardware states.
+ */
+typedef enum
+  {
+   enConnected=1, enDevFound, enInitialized, enOpened
+  }DEVICE_STATE;
+
+typedef enum 
+  {
+   enCommonStart=0,
+   /* General  */
+   enOff, enOn, enDebug, 
+   /* Module General */
+   enCpuFreq, 
+   enStatus,
+   enCommonEnd
+   }COMMON_KEY;
+
+typedef struct
+  {
+   const char  *strKey;
+   int  enKey;
+  }CONTROL_KEY;
+
+typedef struct
+  {
+   char *StatName;
+   unsigned int *StatPtr;
+   int DataType; /* 0: int, 1: hex int, 2:channel data */
+  }STATS_TABLE;
+
+typedef struct
+  {
+   int NumberOfStats;
+   STATS_TABLE *StatTable;
+  }STATS_DB;
+
+#define osfuncSioFlush()    HalDev->OsFunc->Control(HalDev->OsDev,"SioFlush",pszNULL,0)
+#define osfuncSleep(Ticks)  HalDev->OsFunc->Control(HalDev->OsDev,pszSleep,pszNULL,Ticks)
+#define osfuncStateChange() HalDev->OsFunc->Control(HalDev->OsDev,pszStateChange,pszNULL,0)
+
+#define CHANNEL_NAMES {"Ch0","Ch1","Ch2","Ch3","Ch4","Ch5","Ch6","Ch7","Ch8","Ch9","Ch10","Ch11","Ch12","Ch13","Ch14","Ch15"}
+
+#endif
+
diff -urN linux.old/drivers/net/avalanche_cpmac/cpmac.c linux.dev/drivers/net/avalanche_cpmac/cpmac.c
--- linux.old/drivers/net/avalanche_cpmac/cpmac.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpmac.c	2005-07-22 01:03:12.609318544 +0200
@@ -0,0 +1,2504 @@
+/******************************************************************************
+ * FILE PURPOSE:    CPMAC Linux Network Device Driver Source
+ ******************************************************************************
+ * FILE NAME:       cpmac.c
+ *
+ * DESCRIPTION:     CPMAC Network Device Driver Source
+ *
+ * REVISION HISTORY:
+ *
+ * Date           Description                               Author
+ *-----------------------------------------------------------------------------
+ * 27 Nov 2002    Initial Creation                          Suraj S Iyer  
+ * 09 Jun 2003    Updates for GA                            Suraj S Iyer
+ * 30 Sep 2003    Updates for LED, Reset stats              Suraj S Iyer
+ * 
+ * (C) Copyright 2003, Texas Instruments, Inc
+ *******************************************************************************/
+#include <linux/kernel.h> 
+#include <linux/module.h> 
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/delay.h>     
+#include <linux/spinlock.h>
+#include <linux/proc_fs.h>
+#include <linux/ioport.h>
+#include <asm/io.h>
+
+#include <linux/skbuff.h>
+
+#include <asm/mips-boards/prom.h>
+#include <linux/string.h>
+#include <asm/uaccess.h>
+#include <linux/config.h>
+#include <asm/ar7/if_port.h>
+
+extern void build_psp_config(void);
+extern void psp_config_cleanup(void);
+
+#include "cpmacHalLx.h"
+#include "cpmac.h"
+
+static struct net_device *last_cpmac_device = NULL;
+static int    cpmac_devices_installed = 0;
+
+void xdump( u_char*  cp, int  length, char*  prefix );
+
+unsigned int  cpmac_cpu_freq = 0;
+
+char cpmac_version[] = "1.5";
+
+char l3_align_array[]            = {0x02, 0x01, 0x00, 0x03};
+#define L3_ALIGN(i)                l3_align_array[i]
+
+char add_for_4byte_align[]       = {0x04, 0x03, 0x02, 0x05};
+#define ADD_FOR_4BYTE_ALIGN(i)     add_for_4byte_align[i]
+
+
+#define TPID                       0x8100
+#define IS_802_1Q_FRAME(byte_ptr)  (*(unsigned short*)byte_ptr == TPID)
+#define TPID_START_OFFSET          12
+#define TCI_START_OFFSET           14
+#define TCI_LENGTH                 2
+#define TPID_LENGTH                2
+#define TPID_END_OFFSET            (TPID_START_OFFSET + TPID_LENGTH)
+#define TCI_END_OFFSET             (TCI_START_OFFSET  + TCI_LENGTH)
+#define IS_VALID_VLAN_ID(byte_ptr) ((*(unsigned short*)byte_ptr) && 0xfff != 0)
+#define MAX_CLASSES                8
+#define MAX_USER_PRIORITY          8
+#define CONTROL_802_1Q_SIZE        (TCI_LENGTH + TPID_LENGTH)
+
+unsigned char user_priority_to_traffic_class_map[MAX_CLASSES][MAX_USER_PRIORITY] = 
+{ 
+  {0, 0, 0, 1, 1, 1, 1, 2}, 
+  {0, 0, 0, 0, 0, 0, 0, 0}, 
+  {0, 0, 0, 0, 0, 0, 0, 1}, 
+  {0, 0, 0, 1, 1, 2, 2, 3}, 
+  {0, 1, 1, 2, 2, 3, 3, 4}, 
+  {0, 1, 1, 2, 3, 4, 4, 5}, 
+  {0, 1, 2, 3, 4, 5, 5, 6}, 
+  {0, 1, 2, 3, 4, 5, 6, 7}
+};
+
+#define GET_802_1P_CHAN(x,y) user_priority_to_traffic_class_map[x][(y & 0xe0)]
+
+#if defined(CONFIG_MIPS_SEAD2)
+unsigned long temp_base_address[2] = {0xa8610000, 0xa8612800};
+unsigned long temp_reset_value[2] = { 1<< 17,1<<21};
+#define RESET_REG_PRCR   (*(volatile unsigned int *)((0xa8611600 + 0x0)))
+#define VERSION(base)   (*(volatile unsigned int *)(((base)|0xa0000000) + 0x0))
+#endif
+
+MODULE_AUTHOR("Maintainer: Suraj S Iyer <ssiyer@ti.com>");
+MODULE_DESCRIPTION("Driver for TI CPMAC");
+
+static int cfg_link_speed = 0;
+MODULE_PARM(cfg_link_speed, "i");
+MODULE_PARM_DESC(cfg_link_speed, "Fixed speed of the Link: <100/10>");
+
+static char *cfg_link_mode = NULL;
+MODULE_PARM(cfg_link_mode, "1-3s");
+MODULE_PARM_DESC(cfg_link_mode, "Fixed mode of the Link: <fd/hd>");
+
+int cpmac_debug_mode = 0;
+MODULE_PARM(debug_mode, "i");
+MODULE_PARM_DESC(debug_mode, "Turn on the debug info: <0/1>. Default is 0 (off)");
+
+#define dbgPrint if (cpmac_debug_mode) printk
+#define errPrint printk
+
+static int g_cfg_start_link_params = CFG_START_LINK_SPEED;
+static int g_init_enable_flag      = 0;
+static int cfg_start_link_speed;
+static int cpmac_max_frame_size;
+
+static struct net_device *g_dev_array[2];
+static struct proc_dir_entry *gp_stats_file = NULL;
+
+//-----------------------------------------------------------------------------
+// Statistics related private functions.
+//----------------------------------------------------------------------------- 
+static int  cpmac_p_update_statistics(struct net_device *p_dev, char *buf, int limit, int *len);
+static int  cpmac_p_read_rfc2665_stats(char *buf, char **start, off_t offset, int count, int *eof, void *data);
+static int  cpmac_p_read_link(char *buf, char **start, off_t offset, int count, int *eof, void *data);
+static int  cpmac_p_read_stats(char* buf, char **start, off_t offset, int count, int *eof, void *data);
+static int  cpmac_p_write_stats (struct file *fp, const char * buf, unsigned long count, void * data);
+static int  cpmac_p_reset_statistics (struct net_device *p_dev);
+static int  cpmac_p_get_version(char *buf, char **start, off_t offset, int count, int *eof, void *data);
+
+static int  cpmac_p_detect_manual_cfg(int, char*, int);
+static int  cpmac_p_process_status_ind(CPMAC_PRIVATE_INFO_T *p_cpmac_priv);
+
+//-----------------------------------------------------------------------------
+// Timer related private functions.
+//-----------------------------------------------------------------------------
+static int  cpmac_p_timer_init(CPMAC_PRIVATE_INFO_T *p_cpmac_priv);
+// static int  cpmac_timer_cleanup(CPMAC_PRIVATE_INFO_T *p_cpmac_priv);
+static void cpmac_p_tick_timer_expiry(unsigned long p_cb_param);
+inline static int cpmac_p_start_timer(struct timer_list *p_timer, unsigned int delay_ticks);
+static int  cpmac_p_stop_timer(struct timer_list *p_timer);
+
+//------------------------------------------------------------------------------
+// Device configuration and setup related private functions.
+//------------------------------------------------------------------------------
+static int cpmac_p_probe_and_setup_device(CPMAC_PRIVATE_INFO_T *p_cpmac_priv, unsigned long *p_dev_flags);
+static int cpmac_p_setup_driver_params(CPMAC_PRIVATE_INFO_T *p_cpmac_priv);
+inline static int cpmac_p_rx_buf_setup(CPMAC_RX_CHAN_INFO_T *p_rx_chan);
+
+//-----------------------------------------------------------------------------
+// Net device related private functions.
+//-----------------------------------------------------------------------------
+static int  cpmac_dev_init(struct net_device *p_dev);
+static int  cpmac_dev_open( struct net_device *dev );
+static int  cpmac_dev_close(struct net_device *p_dev);
+static void cpmac_dev_mcast_set(struct net_device *p_dev);
+static int cpmac_dev_set_mac_addr(struct net_device *p_dev,void * addr);
+static int  cpmac_dev_tx( struct sk_buff *skb, struct net_device *p_dev);
+static struct net_device_stats *cpmac_dev_get_net_stats (struct net_device *dev);
+
+static int cpmac_p_dev_enable( struct net_device *p_dev);
+
+
+
+/* Max. Reserved headroom in front of each packet so that the headers can be added to
+ * a packet. Worst case scenario would be PPPoE + 2684 LLC Encapsulation + Ethernet
+ * header. */
+#define MAX_RESERVED_HEADROOM       20
+
+/* This is the MAX size of the static buffer for pure data. */
+#define MAX_SIZE_STATIC_BUFFER      1600
+
+typedef struct DRIVER_BUFFER
+{
+	/* Pointer to the allocated data buffer. This is the static data buffer 
+     * allocated for the TI-Cache. 60 bytes out of the below buffer are required
+     * by the SKB shared info. We always reserve at least MAX_RESERVED_HEADROOM bytes 
+     * so that the packets always have sufficient headroom. */
+	char					ptr_buffer[MAX_SIZE_STATIC_BUFFER + MAX_RESERVED_HEADROOM + 60];
+
+	/* List of the driver buffers. */
+	struct DRIVER_BUFFER*	ptr_next;
+}DRIVER_BUFFER;
+
+typedef struct DRIVER_BUFFER_MCB
+{
+	/* List of the driver buffers. */
+	DRIVER_BUFFER*	ptr_available_driver_buffers;
+
+    /* The number of available buffers. */
+    int                     num_available_buffers;
+}DRIVER_BUFFER_MCB;
+
+DRIVER_BUFFER_MCB	driver_mcb;
+int                 hybrid_mode = 0;
+
+static union {
+	struct sk_buff_head	list;
+	char			pad[SMP_CACHE_BYTES];
+} skb_head_pool[NR_CPUS];
+
+/**************************************************************************
+ * FUNCTION NAME : ti_release_skb
+ **************************************************************************
+ * DESCRIPTION   :
+ *  This function is called from the ti_alloc_skb when there were no more
+ *  data buffers available. The allocated SKB had to released back to the 
+ *  data pool. The reason why this function was moved from the fast path 
+ *  below was because '__skb_queue_head' is an inline function which adds
+ *  a large code chunk on the fast path.
+ *
+ * NOTES         :
+ *  This function is called with interrupts disabled. 
+ **************************************************************************/
+static void ti_release_skb (struct sk_buff_head* list, struct sk_buff* skb)
+{
+    __skb_queue_head(list, skb);
+    return;
+}
+
+/**************************************************************************
+ * FUNCTION NAME : ti_alloc_skb
+ **************************************************************************
+ * DESCRIPTION   :
+ *  The function is called to allocate memory from the static allocated 
+ *  TI-Cached memory pool.
+ *
+ * RETURNS       :
+ *      Allocated static memory buffer - Success
+ *      NULL                           - Error.
+ **************************************************************************/
+struct sk_buff *ti_alloc_skb(unsigned int size,int gfp_mask)
+{
+    register struct sk_buff*    skb;
+    unsigned long               flags;
+	struct sk_buff_head*        list;
+	DRIVER_BUFFER*	            ptr_node = NULL;
+
+    /* Critical Section Begin: Lock out interrupts. */
+    local_irq_save(flags);
+
+    /* Get the SKB Pool list associated with the processor and dequeue the head. */
+    list = &skb_head_pool[smp_processor_id()].list;
+    skb = __skb_dequeue(list);
+
+    /* Align the data size. */
+    size = SKB_DATA_ALIGN(size);
+
+    /* Did we get one. */
+    if (skb != NULL)
+    {
+        /* YES. Now get a data block from the head of statically allocated block. */
+        ptr_node = driver_mcb.ptr_available_driver_buffers;
+	    if (ptr_node != NULL)
+        {
+            /* YES. Got a data block. Advance the free list pointer to the next available buffer. */
+	        driver_mcb.ptr_available_driver_buffers = ptr_node->ptr_next;
+            ptr_node->ptr_next = NULL;
+
+            /* Decrement the number of available data buffers. */
+            driver_mcb.num_available_buffers = driver_mcb.num_available_buffers - 1;
+        }
+        else
+        {
+          /* NO. Was unable to get a data block. So put the SKB back on the free list. 
+           * This is slow path. */
+#ifdef DEBUG_SKB 
+           printk ("DEBUG: No Buffer memory available: Number of free buffer:%d.\n",
+                   driver_mcb.num_available_buffers);
+#endif
+           ti_release_skb (list, skb);
+        }
+    }
+
+    /* Critical Section End: Unlock interrupts. */
+    local_irq_restore(flags);
+
+    /* Did we get an SKB and data buffer. Proceed only if we were succesful in getting both else drop */
+    if (skb != NULL && ptr_node != NULL)
+    {
+       	/* XXX: does not include slab overhead */ 
+        skb->truesize = size + sizeof(struct sk_buff);
+ 
+        /* Load the data pointers. */
+     	skb->head = ptr_node->ptr_buffer;
+        skb->data = ptr_node->ptr_buffer + MAX_RESERVED_HEADROOM;
+	    skb->tail = ptr_node->ptr_buffer + MAX_RESERVED_HEADROOM;
+        skb->end  = ptr_node->ptr_buffer + size + MAX_RESERVED_HEADROOM;
+
+	    /* Set up other state */
+    	skb->len    = 0;
+    	skb->cloned = 0;
+        skb->data_len = 0;
+    
+        /* Mark the SKB indicating that the SKB is from the TI cache. */
+        skb->cb[45] = 1;
+
+    	atomic_set(&skb->users, 1); 
+    	atomic_set(&(skb_shinfo(skb)->dataref), 1);
+        skb_shinfo(skb)->nr_frags = 0;
+	    skb_shinfo(skb)->frag_list = NULL;
+        return skb;
+    }
+    else
+    {
+        /* Control comes here only when there is no statically allocated data buffers
+         * available. This case is handled using the mode selected
+         *
+         * 1. Hybrid Mode.
+         *  In that case lets jump to the old allocation code. This way we
+         *  can allocate a small number of data buffers upfront and the rest will hit
+         *  this portion of the code, which is slow path. Note the number of hits here
+         *  should be kept as low as possible to satisfy performance requirements. 
+         *
+         * 2. Pure Static Mode.
+         *  Return NULL the user should have tuned the number of static buffers for
+         *  worst case scenario. So return NULL and let the drivers handle the error. */
+        if (hybrid_mode == 1)
+        {
+            /* Hybrid Mode: Old allocation. */
+            return dev_alloc_skb(size);
+        }
+        else
+        {
+            /* Pure Static Mode: No buffers available. */
+            return NULL;
+        }
+    }
+}
+
+/**************************************************************************
+ * FUNCTION NAME : ti_skb_release_fragment
+ **************************************************************************
+ * DESCRIPTION   :
+ *  This function is called to release fragmented packets. This is NOT in 
+ *  the fast path and this function requires some work. 
+ **************************************************************************/
+static void ti_skb_release_fragment(struct sk_buff *skb)
+{
+    if (skb_shinfo(skb)->nr_frags)
+    {
+        /* PANKAJ TODO: This portion has not been tested. */
+	    int i;
+#ifdef DEBUG_SKB 
+        printk ("DEBUG: Releasing fragments in TI-Cached code.\n");
+#endif
+		for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
+		    printk ("DEBUG: Fragmented Page = 0x%p.\n", skb_shinfo(skb)->frags[i].page);
+    }
+
+    /* Check if there were any fragments present and if so clean all the SKB's. 
+     * This is required to recursivly clean the SKB's. */
+	if (skb_shinfo(skb)->frag_list)
+	    skb_drop_fraglist(skb);
+
+    return;
+}
+
+/**************************************************************************
+ * FUNCTION NAME : ti_skb_release_data
+ **************************************************************************
+ * DESCRIPTION   :
+ *  The function is called to release the SKB back into the TI-Cached static
+ *  memory pool. 
+ **************************************************************************/
+static void ti_skb_release_data(struct sk_buff *skb)
+{
+    DRIVER_BUFFER*	ptr_node;
+    unsigned long   flags;
+
+    /* The SKB data can be cleaned only if the packet has not been cloned and we
+     * are the only one holding a reference to the data. */
+	if (!skb->cloned || atomic_dec_and_test(&(skb_shinfo(skb)->dataref)))
+    {
+        /* Are there any fragments associated with the SKB ?*/
+		if ((skb_shinfo(skb)->nr_frags != 0) || (skb_shinfo(skb)->frag_list != NULL))
+        {
+            /* Slow Path: Try and clean up the fragments. */
+            ti_skb_release_fragment (skb);
+        }
+
+        /* Cleanup the SKB data memory. This is fast path. */
+        ptr_node = (DRIVER_BUFFER *)skb->head;
+
+        /* Critical Section: Lock out interrupts. */
+        local_irq_save(flags);
+
+        /* Add the data buffer to the list of available buffers. */
+        ptr_node->ptr_next = driver_mcb.ptr_available_driver_buffers;
+	    driver_mcb.ptr_available_driver_buffers = ptr_node;
+
+        /* Increment the number of available data buffers. */
+        driver_mcb.num_available_buffers = driver_mcb.num_available_buffers + 1;
+
+        /* Criticial Section: Unlock interrupts. */
+        local_irq_restore(flags);
+	}
+    return;
+}
+
+
+
+
+static unsigned char str2hexnum(unsigned char c)
+{
+        if(c >= '0' && c <= '9')
+                return c - '0';
+        if(c >= 'a' && c <= 'f')
+                return c - 'a' + 10;
+        if(c >= 'A' && c <= 'F')
+                return c - 'A' + 10;
+        return 0; 
+}
+
+static void str2eaddr(unsigned char *ea, unsigned char *str)
+{
+    int i;
+    unsigned char num;
+    for(i = 0; i < 6; i++) {
+        if((*str == '.') || (*str == ':'))
+            str++;
+        num = str2hexnum(*str++) << 4;
+        num |= (str2hexnum(*str++));
+        ea[i] = num;
+    }
+}
+
+//-----------------------------------------------------------------------------
+// Statistics related private functions.
+//-----------------------------------------------------------------------------
+static int cpmac_p_update_statistics(struct net_device *p_dev, char *buf, int limit, int *p_len)
+{
+    int                 ret_val   = -1;
+    unsigned long rx_hal_errors   = 0;
+    unsigned long rx_hal_discards = 0;
+    unsigned long tx_hal_errors   = 0;
+    unsigned long ifOutDiscards   = 0;
+    unsigned long ifInDiscards    = 0;
+    unsigned long ifOutErrors     = 0;
+    unsigned long ifInErrors      = 0;
+
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal    = p_cpmac_priv->drv_hal;
+    CPMAC_DEVICE_MIB_T   *p_device_mib = p_cpmac_priv->device_mib;
+    CPMAC_DRV_STATS_T    *p_stats      = p_cpmac_priv->stats;
+    CPMAC_DEVICE_MIB_T   local_mib;
+    CPMAC_DEVICE_MIB_T   *p_local_mib  = &local_mib;
+
+    struct net_device_stats *p_net_dev_stats = &p_cpmac_priv->net_dev_stats;
+
+    int                 len      = 0;
+    int  dev_mib_elem_count      = 0;
+
+    /* do not access the hardware if it is in the reset state. */
+    if(!test_bit(0, &p_cpmac_priv->set_to_close))
+    {
+        if(p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "StatsDump", "Get",
+ 			                 p_local_mib) != 0)
+        {
+            errPrint("The stats dump for %s is failing.\n", p_dev->name);
+            return(ret_val);
+        }
+
+        p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "StatsClear", "Set", NULL);
+
+        dev_mib_elem_count = sizeof(CPMAC_DEVICE_MIB_T)/sizeof(unsigned long);
+
+        /* Update the history of the stats. This takes care of any reset of the 
+         * device and stats that might have taken place during the life time of 
+         * the driver. 
+         */
+        while(dev_mib_elem_count--)
+        {
+            *((unsigned long*) p_device_mib + dev_mib_elem_count) += 
+            *((unsigned long*) p_local_mib  + dev_mib_elem_count); 
+        }
+    }
+
+    /* RFC2665, section 3.2.7, page 9 */
+    rx_hal_errors          = p_device_mib->ifInFragments       +
+	                     p_device_mib->ifInCRCErrors       +
+	                     p_device_mib->ifInAlignCodeErrors +
+	                     p_device_mib->ifInJabberFrames;
+
+    /* RFC2233 */
+    rx_hal_discards        = p_device_mib->ifRxDMAOverruns;
+
+    /* RFC2665, section 3.2.7, page 9 */
+    tx_hal_errors          = p_device_mib->ifExcessiveCollisionFrames +
+                             p_device_mib->ifLateCollisions           +
+                             p_device_mib->ifCarrierSenseErrors       +
+                             p_device_mib->ifOutUnderrun;
+
+    /* if not set, the short frames (< 64 bytes) are considered as errors */
+    if(!p_cpmac_priv->flags & IFF_PRIV_SHORT_FRAMES)
+        rx_hal_errors += p_device_mib->ifInUndersizedFrames;
+
+    /* if not set, the long frames ( > 1518) are considered as errors 
+     * RFC2665, section 3.2.7, page 9. */
+    if(!p_cpmac_priv->flags & IFF_PRIV_JUMBO_FRAMES)
+        rx_hal_errors += p_device_mib->ifInOversizedFrames;
+
+    /* if not in promiscous, then non addr matching frames are discarded */
+    /* CPMAC 2.0 Manual Section 2.8.1.14 */
+    if(!p_dev->flags & IFF_PROMISC)
+    {
+        ifInDiscards  +=  p_device_mib->ifInFilteredFrames;
+    }
+
+     /* total rx discards = hal discards + driver discards. */
+    ifInDiscards  = rx_hal_discards + p_net_dev_stats->rx_dropped;
+    ifInErrors    = rx_hal_errors;
+
+    ifOutErrors   = tx_hal_errors;
+    ifOutDiscards = p_net_dev_stats->tx_dropped;
+
+    /* Let us update the net device stats struct. To be updated in the later releases.*/
+    p_cpmac_priv->net_dev_stats.rx_errors  = ifInErrors;
+    p_cpmac_priv->net_dev_stats.collisions = p_device_mib->ifCollisionFrames;
+
+    if(buf == NULL || limit == 0)
+    {
+        return(0);
+    }
+
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %ld\n", "ifSpeed",                                 (long)p_cpmac_priv->link_speed);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "dot3StatsDuplexStatus",                   (long)p_cpmac_priv->link_mode);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifAdminStatus",                           (long)(p_dev->flags & IFF_UP ? 1:2));
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOperStatus",                            (long)(((p_dev->flags & IFF_UP) && netif_carrier_ok(p_dev)) ? 1:2));
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifLastChange",                            p_stats->start_tick);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInDiscards",                            ifInDiscards);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInErrors",                              ifInErrors);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOutDiscards",                           ifOutDiscards);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOutErrors",                             ifOutErrors);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInGoodFrames",                          p_device_mib->ifInGoodFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInBroadcasts",                          p_device_mib->ifInBroadcasts);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInMulticasts",                          p_device_mib->ifInMulticasts);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInPauseFrames",                         p_device_mib->ifInPauseFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInCRCErrors",                           p_device_mib->ifInCRCErrors);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInAlignCodeErrors",                     p_device_mib->ifInAlignCodeErrors);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInOversizedFrames",                     p_device_mib->ifInOversizedFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInJabberFrames",                        p_device_mib->ifInJabberFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInUndersizedFrames",                    p_device_mib->ifInUndersizedFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInFragments",                           p_device_mib->ifInFragments);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInFilteredFrames",                      p_device_mib->ifInFilteredFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInQosFilteredFrames",                   p_device_mib->ifInQosFilteredFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifInOctets",                              p_device_mib->ifInOctets);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOutGoodFrames",                         p_device_mib->ifOutGoodFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOutBroadcasts",                         p_device_mib->ifOutBroadcasts);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOutMulticasts",                         p_device_mib->ifOutMulticasts);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOutPauseFrames",                        p_device_mib->ifOutPauseFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifDeferredTransmissions",                 p_device_mib->ifDeferredTransmissions);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifCollisionFrames",                       p_device_mib->ifCollisionFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifSingleCollisionFrames",                 p_device_mib->ifSingleCollisionFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifMultipleCollisionFrames",               p_device_mib->ifMultipleCollisionFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifExcessiveCollisionFrames",              p_device_mib->ifExcessiveCollisionFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifLateCollisions",                        p_device_mib->ifLateCollisions);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOutUnderrun",                           p_device_mib->ifOutUnderrun);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifCarrierSenseErrors",                    p_device_mib->ifCarrierSenseErrors);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifOutOctets",                             p_device_mib->ifOutOctets);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "if64OctetFrames",                         p_device_mib->if64OctetFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "if65To127POctetFrames",                   p_device_mib->if65To127OctetFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "if128To255OctetFrames",                   p_device_mib->if128To255OctetFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "if256To511OctetFrames",                   p_device_mib->if256To511OctetFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "if512To1023OctetFrames",                  p_device_mib->if512To1023OctetFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "if1024ToUpOctetFrames",                   p_device_mib->if1024ToUPOctetFrames);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifNetOctets",                             p_device_mib->ifNetOctets);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifRxSofOverruns",                         p_device_mib->ifRxSofOverruns);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifRxMofOverruns",                         p_device_mib->ifRxMofOverruns);
+    if(len <= limit)
+        len+= sprintf(buf + len, "%-35s: %lu\n", "ifRxDMAOverruns",                         p_device_mib->ifRxDMAOverruns);
+
+    *p_len = len;
+
+    return(0);
+}
+
+
+static int cpmac_p_read_rfc2665_stats(char* buf, char **start, off_t offset, 
+		               int count, int *eof, void *data)
+{
+    int limit = count - 80;
+    int len   = 0;
+    struct net_device *p_dev = (struct net_device*)data;
+
+    cpmac_p_update_statistics(p_dev, buf, limit, &len);
+
+    *eof = 1;
+
+    return len;
+}
+
+static int cpmac_p_read_link(char *buf, char **start, off_t offset, int count, 
+                             int *eof, void *data)
+{
+    int len = 0;
+
+    struct net_device    *p_dev;
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv;
+    struct net_device    *cpmac_dev_list[cpmac_devices_installed];
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal;
+
+    int                  i;
+    int                  phy;            /* what phy are we using? */
+
+    len += sprintf(buf+len, "CPMAC devices = %d\n",cpmac_devices_installed);
+
+    p_dev        = last_cpmac_device;
+
+    /* Reverse the the device link list to list eth0,eth1...in correct order */
+    for(i=0; i< cpmac_devices_installed; i++)
+    {
+        cpmac_dev_list[cpmac_devices_installed -(i+1)] = p_dev;
+        p_cpmac_priv = p_dev->priv;
+        p_dev = p_cpmac_priv->next_device;
+    }
+
+    for(i=0; i< cpmac_devices_installed; i++)
+    {
+        p_dev        = cpmac_dev_list[i];
+        p_cpmac_priv = p_dev->priv;
+        p_drv_hal    = p_cpmac_priv->drv_hal;
+
+        /*  This prints them out from high to low because of how the devices are linked */
+        if(netif_carrier_ok(p_dev))
+        {
+            p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "PhyNum", "Get", &phy);
+
+
+            len += sprintf(buf+len,"eth%d: Link State: %s    Phy:0x%x, Speed = %s, Duplex = %s\n",
+                           p_cpmac_priv->instance_num, "UP", phy, 
+                           (p_cpmac_priv->link_speed == 100000000) ? "100":"10",
+                           (p_cpmac_priv->link_mode  == 2) ? "Half":"Full");
+
+        }
+        else
+            len += sprintf(buf+len,"eth%d: Link State: DOWN\n",p_cpmac_priv->instance_num);
+
+        p_dev = p_cpmac_priv->next_device;
+    }
+
+    return len;
+
+}
+
+static int cpmac_p_read_stats(char* buf, char **start, off_t offset, int count,
+                              int *eof, void *data)
+{
+    struct net_device *p_dev = last_cpmac_device;
+    int                len   = 0;
+    int                limit = count - 80;
+    int i;
+    struct net_device     *cpmac_dev_list[cpmac_devices_installed];
+    CPMAC_PRIVATE_INFO_T  *p_cpmac_priv;
+    CPMAC_DEVICE_MIB_T    *p_device_mib;
+
+    /* Reverse the the device link list to list eth0,eth1...in correct order */
+    for(i=0; i< cpmac_devices_installed; i++)
+    {
+        cpmac_dev_list[cpmac_devices_installed - (i+1)] = p_dev;
+        p_cpmac_priv = p_dev->priv;
+        p_dev = p_cpmac_priv->next_device;
+    }
+
+    for(i=0; i< cpmac_devices_installed; i++)
+    {
+        p_dev = cpmac_dev_list[i];
+
+        if(!p_dev)
+          goto proc_error;
+
+        /* Get Stats */
+        cpmac_p_update_statistics(p_dev, NULL, 0, NULL);
+
+        p_cpmac_priv = p_dev->priv;
+        p_device_mib = p_cpmac_priv->device_mib;
+
+        /* Transmit stats */
+        if(len<=limit)
+          len+= sprintf(buf+len, "\nCpmac %d, Address %lx\n",i+1, p_dev->base_addr);
+        if(len<=limit)
+          len+= sprintf(buf+len, " Transmit Stats\n");
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Tx Valid Bytes Sent        :%lu\n",p_device_mib->ifOutOctets);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Good Tx Frames (Hardware)  :%lu\n",p_device_mib->ifOutGoodFrames);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Good Tx Frames (Software)  :%lu\n",p_cpmac_priv->net_dev_stats.tx_packets);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Good Tx Broadcast Frames   :%lu\n",p_device_mib->ifOutBroadcasts);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Good Tx Multicast Frames   :%lu\n",p_device_mib->ifOutMulticasts);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Pause Frames Sent          :%lu\n",p_device_mib->ifOutPauseFrames);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Collisions                 :%lu\n",p_device_mib->ifCollisionFrames);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Tx Error Frames            :%lu\n",p_cpmac_priv->net_dev_stats.tx_errors);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Carrier Sense Errors       :%lu\n",p_device_mib->ifCarrierSenseErrors);
+        if(len<=limit)
+          len+= sprintf(buf+len, "\n");
+
+
+        /* Receive Stats */
+        if(len<=limit)
+          len+= sprintf(buf+len, "\nCpmac %d, Address %lx\n",i+1,p_dev->base_addr);
+        if(len<=limit)
+          len+= sprintf(buf+len, " Receive Stats\n");
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Rx Valid Bytes Received    :%lu\n",p_device_mib->ifInOctets);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Good Rx Frames (Hardware)  :%lu\n",p_device_mib->ifInGoodFrames);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Good Rx Frames (Software)  :%lu\n",p_cpmac_priv->net_dev_stats.rx_packets);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Good Rx Broadcast Frames   :%lu\n",p_device_mib->ifInBroadcasts);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Good Rx Multicast Frames   :%lu\n",p_device_mib->ifInMulticasts);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Pause Frames Received      :%lu\n",p_device_mib->ifInPauseFrames);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Rx CRC Errors              :%lu\n",p_device_mib->ifInCRCErrors);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Rx Align/Code Errors       :%lu\n",p_device_mib->ifInAlignCodeErrors);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Rx Jabbers                 :%lu\n",p_device_mib->ifInOversizedFrames);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Rx Filtered Frames         :%lu\n",p_device_mib->ifInFilteredFrames);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Rx Fragments               :%lu\n",p_device_mib->ifInFragments);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Rx Undersized Frames       :%lu\n",p_device_mib->ifInUndersizedFrames);
+        if(len<=limit)
+          len+= sprintf(buf+len, "   Rx Overruns                :%lu\n",p_device_mib->ifRxDMAOverruns);
+    }
+
+
+    return len;
+
+ proc_error:
+    *eof=1;
+    return len;
+}
+
+static int cpmac_p_write_stats (struct file *fp, const char * buf, unsigned long count, void * data)
+{
+	char local_buf[31];
+        int  ret_val = 0;
+
+	if(count > 30)
+	{
+		printk("Error : Buffer Overflow\n");
+		printk("Use \"echo 0 > cpmac_stat\" to reset the statistics\n");
+		return -EFAULT;
+	}
+
+	copy_from_user(local_buf,buf,count);
+	local_buf[count-1]='\0'; /* Ignoring last \n char */
+        ret_val = count;
+	
+	if(strcmp("0",local_buf)==0)
+	{
+            struct net_device *p_dev = last_cpmac_device;
+            int i;
+            struct net_device     *cpmac_dev_list[cpmac_devices_installed];
+            CPMAC_PRIVATE_INFO_T  *p_cpmac_priv;
+
+            /* Valid command */
+	    printk("Resetting statistics for CPMAC interface.\n");
+
+            /* Reverse the the device link list to list eth0,eth1...in correct order */
+            for(i=0; i< cpmac_devices_installed; i++)
+            {
+                cpmac_dev_list[cpmac_devices_installed - (i+1)] = p_dev;
+                p_cpmac_priv = p_dev->priv;
+                p_dev = p_cpmac_priv->next_device;
+            }
+
+            for(i=0; i< cpmac_devices_installed; i++)
+             {
+                p_dev = cpmac_dev_list[i];
+                if(!p_dev)
+                {
+                    ret_val = -EFAULT;
+                    break;
+                }
+
+                cpmac_p_reset_statistics(p_dev);
+            }
+	}
+	else
+	{
+		printk("Error: Unknown operation on cpmac statistics\n");
+		printk("Use \"echo 0 > cpmac_stats\" to reset the statistics\n");
+		return -EFAULT;
+	}
+	
+	return ret_val;
+}
+
+static int cpmac_p_reset_statistics(struct net_device *p_dev)
+{
+    int                       ret_val  = 0;
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal    = p_cpmac_priv->drv_hal;
+
+    memset(p_cpmac_priv->device_mib, 0, sizeof(CPMAC_DEVICE_MIB_T));
+    memset(p_cpmac_priv->stats, 0, sizeof(CPMAC_DRV_STATS_T));
+    memset(&p_cpmac_priv->net_dev_stats, 0, sizeof(struct net_device_stats));
+
+    p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "StatsClear", "Set", NULL);
+
+    return(ret_val);
+}
+
+static int cpmac_p_get_version(char* buf, char **start, off_t offset, int count,int *eof, void *data)
+{
+    int  len                           = 0;
+    int  limit                         = count - 80;
+    char *hal_version                  = NULL;
+    struct net_device *p_dev           = last_cpmac_device;
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal    = p_cpmac_priv->drv_hal;
+
+    p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "Version", "Get", &hal_version);
+
+    len += sprintf(buf+len, "Texas Instruments CPMAC driver version: %s\n", cpmac_version);
+
+    if(len <= limit && hal_version)
+        len += sprintf(buf+len, "Texas Instruments CPMAC HAL version: %s\n", hal_version);
+
+    return len;
+}
+
+static struct net_device_stats *cpmac_dev_get_net_stats (struct net_device *p_dev)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = (CPMAC_PRIVATE_INFO_T *) p_dev->priv;
+
+    cpmac_p_update_statistics(p_dev, NULL, 0, NULL);
+
+    return &p_cpmac_priv->net_dev_stats;
+}
+
+static int cpmac_p_detect_manual_cfg(int link_speed, char* link_mode, int debug)
+{
+    char *pSpeed = NULL;
+
+    if(debug == 1)
+    {
+        cpmac_debug_mode = 1;
+        dbgPrint("Enabled the debug print.\n");
+    }
+
+    if(!link_speed && !link_mode)
+    {
+        dbgPrint("No manual link params, defaulting to auto negotiation.\n");
+        return (0);
+    }
+
+    if(!link_speed || (link_speed != 10 && link_speed != 100))
+    {
+        dbgPrint("Invalid or No value of link speed specified, defaulting to auto speed.\n");
+        pSpeed = "auto";
+    }
+    else if(link_speed == 10)
+    {
+        g_cfg_start_link_params &= ~(_CPMDIO_100);
+        pSpeed = "10 Mbps";
+    }
+    else
+    {
+	g_cfg_start_link_params &= ~(_CPMDIO_10);
+        pSpeed = "100 Mbps";
+    }
+
+    if(!link_mode || (!strcmp(link_mode, "fd") && !strcmp(link_mode, "hd")))
+    {
+        dbgPrint("Invalid or No value of link mode specified, defaulting to auto mode.\n");
+    }
+    else if(!strcmp(link_mode, "hd"))
+    {
+        g_cfg_start_link_params &= ~(_CPMDIO_FD);
+    }
+    else
+    {
+        g_cfg_start_link_params &= ~(_CPMDIO_HD);
+    }
+
+    dbgPrint("Link is manually set to the speed of %s speed and %s mode.\n", 
+              pSpeed, link_mode ? link_mode : "auto");
+
+    return(0);
+}
+
+//------------------------------------------------------------------------------
+// Call back from the HAL.
+//------------------------------------------------------------------------------
+static int cpmac_p_process_status_ind(CPMAC_PRIVATE_INFO_T *p_cpmac_priv)
+{
+    struct net_device    *p_dev        = p_cpmac_priv->owner;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal    = p_cpmac_priv->drv_hal;
+    int status;
+
+    p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "Status", "Get", &status);
+
+    /* We do not reflect the real link status if in loopback.
+     * After all, we want the packets to reach the hardware so
+     * that Send() should work. */
+    if(p_dev->flags & IFF_LOOPBACK)
+    {
+        dbgPrint("Maintaining the link up loopback for %s.\n", p_dev->name);
+	netif_carrier_on(p_dev);
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//        avalanche_led_action(p_cpmac_priv->led_handle, CPMAC_LINK_ON);
+//#endif
+
+        return(0);
+    }
+
+    if(status & CPMAC_STATUS_ADAPTER_CHECK) /* ???? */
+    {
+        ; /* what to do ? */
+    }    
+    else if(status)
+    {
+        if(!netif_carrier_ok(p_dev))
+	{
+            netif_carrier_on(p_cpmac_priv->owner);
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//            avalanche_led_action(p_cpmac_priv->led_handle, CPMAC_LINK_ON);
+//#endif
+	    dbgPrint("Found the Link for the CPMAC instance %s.\n", p_dev->name);
+        }
+
+        if(netif_running(p_dev) & netif_queue_stopped(p_dev))
+        {
+            netif_wake_queue(p_dev);
+        }
+
+	p_cpmac_priv->link_speed = status & CPMAC_STATUS_LINK_SPEED ? 100000000:10000000;
+	p_cpmac_priv->link_mode  = status & CPMAC_STATUS_LINK_DUPLEX? 3:2;
+
+    }
+    else
+    {
+        if(netif_carrier_ok(p_dev))
+	{
+	    /* do we need to register synchronization issues with stats here. */
+	    p_cpmac_priv->link_speed        = 100000000;
+	    p_cpmac_priv->link_mode         = 1;
+
+	    netif_carrier_off(p_dev);
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//            avalanche_led_action(p_cpmac_priv->led_handle, CPMAC_LINK_OFF);
+//#endif
+
+	    dbgPrint("Lost the Link for the CPMAC for %s.\n", p_dev->name);
+	}
+
+        if(!netif_queue_stopped(p_dev))
+        {
+            netif_stop_queue(p_dev);     /* So that kernel does not keep on xmiting pkts. */
+        }
+    }
+
+    return(0);
+}
+
+//-----------------------------------------------------------------------------
+// Timer related private functions.
+//-----------------------------------------------------------------------------
+static int cpmac_p_timer_init(CPMAC_PRIVATE_INFO_T *p_cpmac_priv)
+{
+    struct timer_list *p_timer = p_cpmac_priv->timer;
+
+    init_timer(p_timer);
+    
+    p_timer                    = p_cpmac_priv->timer + TICK_TIMER;
+    p_timer->expires           = 0;
+    p_timer->data              = (unsigned long)p_cpmac_priv;
+    p_timer->function          = cpmac_p_tick_timer_expiry;
+
+    return(0);
+}
+
+#if 0
+static int cpmac_timer_cleanup(CPMAC_PRIVATE_INFO_T *p_cpmac_priv)
+{
+    struct timer_list *p_timer;
+
+    p_timer = p_cpmac_priv->timer + TICK_TIMER;
+   
+    /* use spin lock to establish synchronization with the dispatch */
+    if(p_timer->function) del_timer_sync(p_timer);
+    p_timer->function = NULL;
+
+    return (0);
+}
+#endif
+
+static int cpmac_p_start_timer(struct timer_list *p_timer, unsigned int delay_ticks)
+{
+    p_timer->expires        = jiffies + delay_ticks;
+
+    if(p_timer->function)
+    {
+        add_timer(p_timer);
+    }
+
+    return(0);
+} 
+
+static void cpmac_p_tick_timer_expiry(unsigned long p_cb_param)
+{
+    CPMAC_PRIVATE_INFO_T   *p_cpmac_priv = (CPMAC_PRIVATE_INFO_T*) p_cb_param;
+    CPMAC_DRV_HAL_INFO_T   *p_drv_hal    = p_cpmac_priv->drv_hal; 
+    struct timer_list       *p_timer     = p_cpmac_priv->timer + TICK_TIMER;
+
+    if(test_bit(0, &p_cpmac_priv->set_to_close))
+    {
+        return;
+    }
+
+    p_drv_hal->hal_funcs->Tick(p_drv_hal->hal_dev);
+  
+    cpmac_p_start_timer(p_timer, p_cpmac_priv->delay_ticks);
+}
+
+static int cpmac_p_stop_timer(struct timer_list *p_timer)
+{
+    /* Ideally we need to a set flag indicating not to start the timer again
+       before del_timer_sync() is called up. But here we assume that the 
+       caller has set the p_cpmac_priv->set_to_close (ok for now). */
+    del_timer_sync(p_timer);
+    
+    return(0);
+}
+
+//------------------------------------------------------------------------------
+// Device configuration and setup related private functions.
+//------------------------------------------------------------------------------
+static int cpmac_p_probe_and_setup_device(CPMAC_PRIVATE_INFO_T *p_cpmac_priv, 
+		                          unsigned long *p_dev_flags)
+{
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal   = p_cpmac_priv->drv_hal;
+    HAL_FUNCTIONS        *p_hal_funcs = p_drv_hal->hal_funcs;
+    HAL_DEVICE           *p_hal_dev   = p_drv_hal->hal_dev;
+    CPMAC_ABILITY_INFO_T *p_capability= p_cpmac_priv->ability_info;
+    unsigned int         val          = 0;
+    int                  channel      = 0;
+
+    p_cpmac_priv->flags                  = 0;
+
+    p_capability->promiscous             = CFG_PROMISCOUS;
+    p_capability->broadcast              = CFG_BROADCAST;
+    p_capability->multicast              = CFG_MULTICAST;
+    p_capability->all_multi              = CFG_ALL_MULTI;
+    p_capability->jumbo_frames           = CFG_JUMBO_FRAMES;
+    p_capability->short_frames           = CFG_SHORT_FRAMES;
+    p_capability->auto_negotiation       = CFG_AUTO_NEGOTIATION;
+    p_capability->link_speed             = cfg_start_link_speed;
+    p_capability->loop_back              = CFG_LOOP_BACK;
+    p_capability->tx_flow_control        = CFG_TX_FLOW_CNTL;
+    p_capability->rx_flow_control        = CFG_RX_FLOW_CNTL;
+    p_capability->tx_pacing              = CFG_TX_PACING;
+    p_capability->rx_pass_crc            = CFG_RX_PASS_CRC;
+    p_capability->qos_802_1q             = CFG_QOS_802_1Q;
+    p_capability->tx_num_chan            = CFG_TX_NUM_CHAN;
+
+    /* Lets probe the device for the configured capabilities (netdev specific).*/ 
+
+    /* Following are set in the set_multi_list, when indicated by the kernel 
+     * Promiscous and all multi.
+     */
+
+    if(p_capability->broadcast)
+    {
+        channel = 0;
+	val     = 1;
+        if((p_hal_funcs->Control(p_hal_dev, pszRX_BROAD_EN, pszSet, &val) == 0) && 
+           (p_hal_funcs->Control(p_hal_dev, pszRX_BROAD_CH, pszSet, &channel) == 0))
+	    *p_dev_flags |= IFF_BROADCAST;
+	else
+	    p_capability->broadcast = 0; /* no broadcast capabilities */
+    }
+
+    if(p_capability->multicast)
+    {
+        val     = 1;
+	channel = 0;
+	if((p_hal_funcs->Control(p_hal_dev, pszRX_MULT_EN, pszSet, &val) == 0) &&
+	   (p_hal_funcs->Control(p_hal_dev, pszRX_MULT_CH, pszSet, &channel) == 0))
+	    *p_dev_flags |= IFF_MULTICAST;
+	else
+	{
+	    p_capability->multicast = 0; 
+	    p_capability->all_multi = 0; /* no multicast, no all-multi. */
+	}
+    }
+
+    if(p_capability->loop_back)
+    {
+        ;  /* We do not put the device in loopback, if required use ioctl */
+    }
+    
+    /* Lets probe the device for the configured capabilities (Non net device specific).*/
+
+    if(p_capability->jumbo_frames)
+    {
+	val = 0;
+        if(p_hal_funcs->Control(p_hal_dev, pszRX_NO_CHAIN, pszSet, &val) == 0)
+            p_cpmac_priv->flags |= IFF_PRIV_JUMBO_FRAMES;
+	else
+	    p_capability->jumbo_frames = 0;
+    }
+
+    if(p_capability->short_frames)
+    {
+	val = 1;
+        if(p_hal_funcs->Control(p_hal_dev, pszRX_CSF_EN, pszSet, &val) == 0)
+            p_cpmac_priv->flags |= IFF_PRIV_SHORT_FRAMES;
+	else
+	    p_capability->short_frames = 0;
+    }            
+
+    val = g_cfg_start_link_params;
+
+#ifdef CONFIG_AR7_MDIX
+    if( avalanche_is_mdix_on_chip() )
+    {
+        val |= _CPMDIO_AUTOMDIX;
+    }
+#endif 
+
+    if(p_hal_funcs->Control(p_hal_dev,pszMdioConnect,pszSet, &val) !=0)
+    {
+        p_capability->link_speed = 0;
+    }
+    else
+    {
+	if(g_cfg_start_link_params & (_CPMDIO_100 | _CPMDIO_HD | _CPMDIO_FD | _CPMDIO_10))
+            p_cpmac_priv->flags |= IFF_PRIV_AUTOSPEED;
+	else if(g_cfg_start_link_params & (_CPMDIO_100 | _CPMDIO_HD))
+	    p_cpmac_priv->flags |= IFF_PRIV_LINK100_HD;
+	else if(g_cfg_start_link_params & (_CPMDIO_100 | _CPMDIO_FD))
+	    p_cpmac_priv->flags |= IFF_PRIV_LINK100_FD;
+	else if(g_cfg_start_link_params & (_CPMDIO_10 | _CPMDIO_HD))
+	    p_cpmac_priv->flags |= IFF_PRIV_LINK10_HD;
+	else if(g_cfg_start_link_params & (_CPMDIO_10 | _CPMDIO_FD))
+	    p_cpmac_priv->flags |= IFF_PRIV_LINK10_FD;
+	else
+	    ;
+    }
+
+    if(p_capability->tx_flow_control)
+    {
+	val = 1;
+        if(p_hal_funcs->Control(p_hal_dev,pszTX_FLOW_EN, pszSet, &val) ==0)
+            p_cpmac_priv->flags |= IFF_PRIV_TX_FLOW_CNTL;
+	else
+            p_capability->tx_flow_control = 0;
+    }
+
+    if(p_capability->rx_flow_control)
+    {
+	val = 1;
+        if(p_hal_funcs->Control(p_hal_dev, pszRX_FLOW_EN, pszSet, &val) ==0)
+	    p_cpmac_priv->flags |= IFF_PRIV_RX_FLOW_CNTL;
+	else
+            p_capability->rx_flow_control = 0;
+    }
+
+    if(p_capability->tx_pacing)
+    {
+	val = 1;
+        if(p_hal_funcs->Control(p_hal_dev, pszTX_PACE, pszSet, &val) ==0)
+            p_cpmac_priv->flags |= IFF_PRIV_TX_PACING;
+	else
+	    p_capability->tx_pacing = 0;
+    }
+
+    if(p_capability->rx_pass_crc)
+    {
+	val = 1;
+	if(p_hal_funcs->Control(p_hal_dev, pszRX_PASS_CRC, pszSet, &val) == 0)
+	    p_cpmac_priv->flags |= IFF_PRIV_RX_PASS_CRC;
+	else                                  
+            p_capability->rx_pass_crc = 0;
+    }
+
+    if(p_capability->qos_802_1q)
+    {
+	val  = 1;
+        if(p_hal_funcs->Control(p_hal_dev, pszRX_QOS_EN, pszSet, &val) == 0)
+            p_cpmac_priv->flags |= IFF_PRIV_8021Q_EN;
+	else
+	{
+	    p_capability->qos_802_1q = 0;
+	    p_capability->tx_num_chan= 1;
+        }
+    }
+
+    if(p_capability->tx_num_chan > 1)
+    {
+	int cfg_tx_num_chan = p_capability->tx_num_chan;
+        val = 0;
+#ifdef TEST
+	if(p_hal_funcs->Control(p_hal_dev, pszTX_NUM_CH, pszGet, &val) == 0)
+	    cfg_tx_num_chan = cfg_tx_num_chan > val ? val : cfg_tx_num_chan;
+	else 
+	    cfg_tx_num_chan = 1;
+#endif
+	p_capability->tx_num_chan = cfg_tx_num_chan;
+    }
+
+    return(0);
+}
+
+static int cpmac_p_setup_driver_params(CPMAC_PRIVATE_INFO_T *p_cpmac_priv)
+{
+   int i=0;
+   int threshold = CFG_TX_NUM_BUF_SERVICE;
+
+   char *tx_threshold_ptr = prom_getenv("threshold");
+   
+    CPMAC_TX_CHAN_INFO_T *p_tx_chan_info = p_cpmac_priv->tx_chan_info;
+    CPMAC_RX_CHAN_INFO_T *p_rx_chan_info = p_cpmac_priv->rx_chan_info;
+    CPMAC_ABILITY_INFO_T *p_capability   = p_cpmac_priv->ability_info;
+
+    /* Timer stuff */
+    p_cpmac_priv->timer_count      = 1; /* should be < or = the MAX TIMER */
+    p_cpmac_priv->timer_created    = 0;
+    p_cpmac_priv->timer_access_hal = 1;
+
+    for(i=0; i < MAX_TIMER; i++)
+        p_cpmac_priv->timer[i].function = NULL;
+
+    p_cpmac_priv->enable_802_1q  = p_capability->qos_802_1q;  
+
+    /* Tx channel related.*/
+    p_tx_chan_info->cfg_chan     = p_capability->tx_num_chan;
+    p_tx_chan_info->opened_chan  = 0;
+    
+    if(tx_threshold_ptr)
+       threshold = simple_strtol(tx_threshold_ptr, (char **)NULL, 10);
+    
+    if((threshold <= 0) && tx_threshold_ptr) /* If threshold set to 0 then Enable the TX interrupt */
+    {
+       threshold  = CFG_TX_NUM_BUF_SERVICE;
+       p_tx_chan_info->tx_int_disable = 0;
+       
+    }
+    else
+    {
+       p_tx_chan_info->tx_int_disable = CFG_TX_INT_DISABLE;
+    }
+
+    for(i=0; i < MAX_TX_CHAN; i++)
+    {
+       
+
+
+       p_tx_chan_info->chan[i].state         = CHAN_CLOSE; 
+       p_tx_chan_info->chan[i].num_BD        = CFG_TX_NUM_BUF_DESC;  
+       p_tx_chan_info->chan[i].buffer_size   = cpmac_max_frame_size;
+       p_tx_chan_info->chan[i].buffer_offset = CFG_TX_BUF_OFFSET;
+
+
+
+       p_tx_chan_info->chan[i].service_max   = threshold;
+    }
+    
+    if (p_tx_chan_info->tx_int_disable)
+       printk("Cpmac driver Disable TX complete interrupt setting threshold to %d.\n",threshold);
+    else
+       printk("Cpmac driver Enable TX complete interrupt\n");
+
+    
+    /* Assuming just one rx channel for now */
+    p_rx_chan_info->cfg_chan            = 1;
+    p_rx_chan_info->opened_chan         = 0;
+    p_rx_chan_info->chan->state         = CHAN_CLOSE;
+    p_rx_chan_info->chan->num_BD        = CFG_RX_NUM_BUF_DESC;
+    p_rx_chan_info->chan->buffer_size   = cpmac_max_frame_size;
+    p_rx_chan_info->chan->buffer_offset = CFG_RX_BUF_OFFSET;
+    p_rx_chan_info->chan->service_max   = CFG_RX_NUM_BUF_SERVICE;
+
+    /* Set as per RFC 2665 */
+    p_cpmac_priv->link_speed     = 100000000; 
+    p_cpmac_priv->link_mode      = 1;
+
+    p_cpmac_priv->loop_back      = 0;
+
+    return(0);
+}
+
+inline static int cpmac_p_rx_buf_setup(CPMAC_RX_CHAN_INFO_T *p_rx_chan)
+{
+    /* Number of ethernet packets & max pkt length */
+    p_rx_chan->chan->tot_buf_size  = p_rx_chan->chan->buffer_size   + 
+                                     2*(CONTROL_802_1Q_SIZE)        +
+	                             p_rx_chan->chan->buffer_offset +
+                                     ADD_FOR_4BYTE_ALIGN(p_rx_chan->chan->buffer_offset & 0x3);
+
+    p_rx_chan->chan->tot_reserve_bytes = CONTROL_802_1Q_SIZE + 
+                                         p_rx_chan->chan->buffer_offset +
+	                                 L3_ALIGN(p_rx_chan->chan->buffer_offset & 0x3);
+
+    return(0);
+}
+
+//-----------------------------------------------------------------------------
+// Net device related private functions.
+//-----------------------------------------------------------------------------
+
+/***************************************************************
+ *	cpmac_dev_init
+ *
+ *	Returns:
+ *		0 on success, error code otherwise.
+ *	Parms:
+ *		dev	The structure of the device to be
+ *			init'ed.
+ *
+ *	This function completes the initialization of the
+ *	device structure and driver.  It reserves the IO
+ *	addresses and assignes the device's methods.
+ *
+ *	
+ **************************************************************/
+
+static int cpmac_dev_init(struct net_device *p_dev)
+{
+    int retVal = -1;
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = p_dev->priv;
+    int instance_num                   = p_cpmac_priv->instance_num;
+    unsigned long net_flags = 0;
+    char *mac_name          = NULL;
+    char *mac_string        = NULL;
+
+    CPMAC_TX_CHAN_INFO_T *p_tx_chan_info;
+    CPMAC_RX_CHAN_INFO_T *p_rx_chan_info;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal;
+    int i;
+
+    int mem_size =    sizeof(CPMAC_DRV_HAL_INFO_T)
+		    + sizeof(CPMAC_TX_CHAN_INFO_T)
+		    + sizeof(CPMAC_RX_CHAN_INFO_T)
+		    + sizeof(CPMAC_ABILITY_INFO_T)
+                    + sizeof(CPMAC_DEVICE_MIB_T)
+                    + sizeof(CPMAC_DRV_STATS_T);
+
+
+#if defined(CONFIG_MIPS_SEAD2)
+    int prev_reset_val = RESET_REG_PRCR;
+    /* Bring the module out of reset */
+    RESET_REG_PRCR |= temp_reset_value[p_cpmac_priv->instance_num];     
+
+    /* Read the version id of the device to check if the device really exists */
+    if( VERSION(temp_base_address[p_cpmac_priv->instance_num]) == 0)
+    {
+        printk(" CPMAC:Device not found\n");
+	RESET_REG_PRCR = prev_reset_val;
+        return -ENODEV;
+    }
+
+    RESET_REG_PRCR = prev_reset_val;
+#endif
+
+
+    if((p_drv_hal = kmalloc(mem_size,  GFP_KERNEL)) == NULL)
+    {
+        errPrint("Failed to allocate memory; rewinding.\n");
+        return(-1);
+    }
+
+    memset(p_drv_hal, 0, mem_size);
+
+    /* build the cpmac private object */
+    p_cpmac_priv->drv_hal       = p_drv_hal;
+    p_cpmac_priv->tx_chan_info  = p_tx_chan_info
+                                = (CPMAC_TX_CHAN_INFO_T*)((char*)p_drv_hal 
+				  + sizeof(CPMAC_DRV_HAL_INFO_T));
+    p_cpmac_priv->rx_chan_info  = p_rx_chan_info 
+                                = (CPMAC_RX_CHAN_INFO_T*)((char *)p_tx_chan_info 
+				  + sizeof(CPMAC_TX_CHAN_INFO_T));
+    p_cpmac_priv->ability_info  = (CPMAC_ABILITY_INFO_T *)((char *)p_rx_chan_info 
+		                  + sizeof(CPMAC_RX_CHAN_INFO_T));
+    p_cpmac_priv->device_mib    = (CPMAC_DEVICE_MIB_T *)((char *)p_cpmac_priv->ability_info 
+	                          + sizeof(CPMAC_ABILITY_INFO_T));
+    p_cpmac_priv->stats         = (CPMAC_DRV_STATS_T *)((char *)p_cpmac_priv->device_mib   
+		                  + sizeof(CPMAC_DEVICE_MIB_T));
+
+    p_drv_hal->owner            = p_cpmac_priv;
+
+
+    switch(instance_num)
+    {
+
+        case 0:
+            mac_name="maca";
+
+            /* Also setting port information */
+            p_dev->if_port =  AVALANCHE_CPMAC_LOW_PORT_ID;            
+
+            break;
+
+        case 1:
+            mac_name="macb";
+
+            /* Also setting port information */
+            p_dev->if_port =  AVALANCHE_CPMAC_HIGH_PORT_ID;            
+
+            break;
+    }
+
+    if(mac_name)
+        mac_string=prom_getenv(mac_name);
+
+    if(!mac_string)
+    {
+        mac_string="08.00.28.32.06.02";
+        printk("Error getting mac from Boot enviroment for %s\n",p_dev->name);
+        printk("Using default mac address: %s\n",mac_string);
+        if(mac_name)
+        {
+            printk("Use Bootloader command:\n");
+            printk("    setenv %s xx.xx.xx.xx.xx.xx\n","<env_name>");
+            printk("to set mac address\n");
+        }
+    }
+
+    str2eaddr(p_cpmac_priv->mac_addr,mac_string);
+
+    for (i=0; i <= ETH_ALEN; i++)
+    {
+        /* This sets the hardware address */
+	p_dev->dev_addr[i] = p_cpmac_priv->mac_addr[i]; 
+    }
+
+    p_cpmac_priv->set_to_close          = 1;
+    p_cpmac_priv->non_data_irq_expected = 0;
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//    if((p_cpmac_priv->led_handle = avalanche_led_register("cpmac", instance_num)) == NULL)
+//   {
+//        errPrint("Could not allocate handle for CPMAC[%d] LED.\n", instance_num);
+//       goto cpmac_init_mod_error;
+//    }
+//#endif
+
+    if(cpmac_drv_init_module(p_drv_hal, p_dev, instance_num) != 0)
+    {
+        errPrint("Could not initialize the HAL for %s.\n", p_dev->name);
+        goto cpmac_init_mod_error;
+    } 
+
+    /* initialize the CPMAC device */
+    if (cpmac_drv_init(p_drv_hal) == -1)
+    {
+	errPrint("HAL init failed for %s.\n", p_dev->name);
+	goto cpmac_init_device_error;
+    }
+
+    if(cpmac_p_probe_and_setup_device(p_cpmac_priv, &net_flags) == -1)
+    {
+        errPrint("Failed to configure up %s.\n", p_dev->name);
+        goto cpmac_init_device_error;
+    }
+
+    if(cpmac_p_setup_driver_params(p_cpmac_priv) == -1)
+    {
+        errPrint("Failed to set driver parameters for %s.\n", p_dev->name);
+        goto cpmac_init_device_error;
+    }
+
+    cpmac_p_rx_buf_setup(p_rx_chan_info);
+
+    /* initialize the timers for the net device */
+    if(cpmac_p_timer_init(p_cpmac_priv) == -1)
+    {
+        errPrint("Failed to set timer(s) for %s.\n", p_dev->name);
+        goto cpmac_timer_init_error;
+    }
+
+    p_dev->addr_len           = 6;
+
+    p_dev->open               = &cpmac_dev_open;    /*  i.e. Start Device  */
+    p_dev->hard_start_xmit    = &cpmac_dev_tx;
+    p_dev->stop               = &cpmac_dev_close;
+    p_dev->get_stats          = &cpmac_dev_get_net_stats;
+
+    p_dev->set_multicast_list = &cpmac_dev_mcast_set;
+    p_dev->set_mac_address    = cpmac_dev_set_mac_addr;
+    /* Knocking off the default broadcast and multicast flags. Allowing the 
+       device configuration to control the flags. */
+    p_dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
+    p_dev->flags |= net_flags;
+
+    netif_carrier_off(p_dev);
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//    avalanche_led_action(p_cpmac_priv->led_handle, CPMAC_LINK_OFF);
+//#endif
+
+    /* Tasklet is initialized at the isr registeration time. */
+    p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "CpmacBase", "Get", &p_dev->base_addr);
+    p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "CpmacSize", "Get", &p_cpmac_priv->dev_size);
+
+    request_mem_region(p_dev->base_addr, p_cpmac_priv->dev_size, p_dev->name);
+
+    retVal = 0;
+
+    if(g_init_enable_flag)
+        cpmac_p_dev_enable(p_dev);
+
+    return(retVal);
+
+cpmac_timer_init_error:
+cpmac_init_device_error  :
+    cpmac_drv_cleanup(p_drv_hal);
+
+cpmac_init_mod_error:
+    kfree(p_drv_hal);
+
+    return (retVal);
+
+} /* cpmac_dev_init */
+
+
+/***************************************************************
+ *	cpmac_p_dev_enable
+ *
+ *	Returns:
+ *		0 on success, error code otherwise.
+ *	Parms:
+ *		dev	Structure of device to be opened.
+ *
+ *	This routine puts the driver and CPMAC adapter in a
+ *	state where it is ready to send and receive packets.
+ *	
+ *
+ **************************************************************/
+int cpmac_p_dev_enable( struct net_device *p_dev)
+{
+    int ret_val = 0;
+    int channel = 0;
+ 
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv   = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal      = p_cpmac_priv->drv_hal;
+    CPMAC_RX_CHAN_INFO_T *p_rx_chan_info = p_cpmac_priv->rx_chan_info;
+    int max_length                       = p_rx_chan_info->chan->tot_buf_size;
+
+    p_cpmac_priv->set_to_close = 0;
+
+    if((ret_val = cpmac_drv_start(p_drv_hal, p_cpmac_priv->tx_chan_info, 
+				  p_cpmac_priv->rx_chan_info, CHAN_SETUP))==-1)
+    {
+        errPrint("%s error: failed to start the device.\n", p_dev->name);
+        ret_val = -1;
+    }
+    else if(p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev,"RX_UNICAST_SET",  
+					  "Set", &channel)!=0)
+    {
+        errPrint("%s error: device chan 0 could not be enabled.\n", p_dev->name);	
+	ret_val = -1;
+    }
+    else if(p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, pszRX_MAXLEN, pszSet, &max_length) != 0)
+    {
+        errPrint(" CPMAC registers can't be written \n");
+        ret_val = -1;
+    }
+    else if(p_drv_hal->hal_funcs->Control(p_drv_hal->hal_dev, "TxIntDisable", "Set", 
+            &p_cpmac_priv->tx_chan_info->tx_int_disable) != 0)
+    {    
+        errPrint(" CPMAC registers can't be written \n");
+        ret_val = -1;
+    }
+    else
+    {
+        ; // Every thing went OK. 
+    }
+    
+    return(ret_val);
+} /* cpmac_dev_enable */
+
+
+static int cpmac_dev_open(struct net_device *p_dev)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv   = p_dev->priv;
+    CPMAC_ISR_INFO_T     *p_isr_cb_param = &p_cpmac_priv->cpmac_isr;
+
+    if(!g_init_enable_flag)
+        cpmac_p_dev_enable(p_dev);
+   
+    if(request_irq(p_isr_cb_param->intr, cpmac_hal_isr, SA_INTERRUPT, 
+                   "Cpmac Driver", p_isr_cb_param))
+    {
+        errPrint("Failed to register the irq %d for Cpmac %s.\n",
+                  p_isr_cb_param->intr, p_dev->name); 
+        return (-1);          
+    }
+    
+    netif_start_queue(p_dev);
+
+    MOD_INC_USE_COUNT;
+    p_cpmac_priv->stats->start_tick = jiffies;
+    dbgPrint("Started the network queue for %s.\n", p_dev->name);    
+    return(0);
+}
+
+/***************************************************************
+ *	cpmac_p_dev_disable
+ *  
+ * 	Returns:
+ *		An error code.
+ *	Parms:
+ *		dev	The device structure of the device to
+ *			close.
+ *
+ *	This function shuts down the adapter.  
+ *
+ **************************************************************/
+int cpmac_p_dev_disable(struct net_device *p_dev)
+{
+    int ret_val = 0;
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal    = p_cpmac_priv->drv_hal;
+
+    set_bit(0, &p_cpmac_priv->set_to_close);
+    set_bit(0, &p_cpmac_priv->non_data_irq_expected);
+   
+    /* The driver does not re-schedule the tasklet after kill is called. So, this 
+       should take care of the bug in the kernel. */
+    tasklet_kill(&p_cpmac_priv->cpmac_isr.tasklet);
+ 
+    if(cpmac_drv_stop(p_drv_hal, p_cpmac_priv->tx_chan_info,
+		      p_cpmac_priv->rx_chan_info, 
+		      CHAN_TEARDOWN | FREE_BUFFER | BLOCKING | COMPLETE) == -1)
+    {
+        ret_val = -1;
+    }
+    else
+    {
+        /* hope that the HAL closes down the tick timer.*/
+
+        dbgPrint("Device %s Closed.\n", p_dev->name);
+        p_cpmac_priv->stats->start_tick = jiffies;
+
+        p_cpmac_priv->link_speed        = 100000000;
+        p_cpmac_priv->link_mode         = 1;
+        netif_carrier_off(p_dev);
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//        avalanche_led_action(p_cpmac_priv->led_handle, CPMAC_LINK_OFF);
+//#endif
+
+        clear_bit(0, &p_cpmac_priv->non_data_irq_expected);
+
+    }
+    
+    return (ret_val);
+
+} /* cpmac_dev_close */
+
+
+/***************************************************************
+ *	cpmac_dev_close
+ *  
+ * 	Returns:
+ *		An error code.
+ *	Parms:
+ *		dev	The device structure of the device to
+ *			close.
+ *
+ *	This function shuts down the adapter.  
+ *
+ **************************************************************/
+static int cpmac_dev_close(struct net_device *p_dev)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv   = p_dev->priv;
+    CPMAC_ISR_INFO_T     *p_isr_cb_param = &p_cpmac_priv->cpmac_isr;
+
+    /* inform the upper layers. */
+    netif_stop_queue(p_dev);
+
+    if(!g_init_enable_flag)
+        cpmac_p_dev_disable(p_dev);
+    else
+        free_irq(p_isr_cb_param->intr, p_isr_cb_param);
+
+    MOD_DEC_USE_COUNT;
+
+    return(0);
+}
+
+static void cpmac_dev_mcast_set(struct net_device *p_dev)
+{
+    CPMAC_PRIVATE_INFO_T    *p_cpmac_priv = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T    *p_drv_hal    = p_cpmac_priv->drv_hal;
+    CPMAC_ABILITY_INFO_T    *p_capability = p_cpmac_priv->ability_info;
+    HAL_FUNCTIONS           *p_hal_funcs  = p_drv_hal->hal_funcs;
+    HAL_DEVICE              *p_hal_dev    = p_drv_hal->hal_dev;
+    int                     val           = 1;
+    int                     channel       = 0;
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)    
+//    if(netif_carrier_ok(p_dev))
+//      avalanche_led_action(p_cpmac_priv->led_handle, CPMAC_LINK_ON);
+//#endif
+
+    if(p_dev->flags & IFF_PROMISC)
+    {
+        if(p_capability->promiscous)
+        {       
+            /* multi mode in the HAL, check this */
+	    val = 0;
+	    p_hal_funcs->Control(p_hal_dev, pszRX_MULTI_ALL, "Clear", &val);
+
+	    val = 1;
+            /* set the promiscous mode in the HAL */
+            p_hal_funcs->Control(p_hal_dev, pszRX_CAF_EN, pszSet, &val);
+            p_hal_funcs->Control(p_hal_dev, pszRX_PROM_CH, pszSet, &channel);
+
+       	    dbgPrint("%s set in the Promisc mode.\n", p_dev->name);	
+	}
+        else
+        {
+	    errPrint("%s not configured for Promisc mode.\n", p_dev->name);
+        }
+    }
+    else if(p_dev->flags & IFF_ALLMULTI)
+    {
+        if(p_capability->all_multi)
+        {	
+	    val = 0;
+	    /* disable the promiscous mode in the HAL */
+	    p_hal_funcs->Control(p_hal_dev, pszRX_CAF_EN, "Clear", &val);
+
+	    val = 1;
+            /* set the all multi mode in the HAL */
+	    p_hal_funcs->Control(p_hal_dev, pszRX_MULTI_ALL, pszSet, &val);
+	    p_hal_funcs->Control(p_hal_dev, pszRX_MULT_CH, pszSet, &channel);
+
+            dbgPrint("%s has been set to the ALL_MULTI mode.\n", p_dev->name);
+        }
+        else
+        {
+	    errPrint("%s not configured for ALL MULTI mode.\n", p_dev->name);
+        }
+    }
+    else if(p_dev->mc_count)
+    {
+        if(p_capability->multicast)
+        {
+	    struct dev_mc_list *p_dmi = p_dev->mc_list;
+            int    count;
+
+            val = 0;
+            /* clear all the previous data, we are going to populate new ones.*/
+	    p_hal_funcs->Control(p_hal_dev, pszRX_MULTI_ALL, "Clear", &val);
+	    /* disable the promiscous mode in the HAL */
+	    p_hal_funcs->Control(p_hal_dev, pszRX_CAF_EN, pszSet, &val);
+
+	    for(count = 0; count < p_dev->mc_count; count++, p_dmi = p_dmi->next)
+	    {
+               p_hal_funcs->Control(p_hal_dev, "RX_MULTI_SINGLE", "Set", p_dmi->dmi_addr); 
+	    }
+
+            dbgPrint("%s configured for %d multicast addresses.\n", p_dev->name, p_dev->mc_count);
+        }
+        else
+        {
+	    errPrint("%s has not been configuted for multicast handling.\n", p_dev->name);
+        }
+    }
+    else
+    {
+       val = 0;
+       /* clear all the previous data, we are going to populate new ones.*/
+       p_hal_funcs->Control(p_hal_dev, pszRX_MULTI_ALL, "Clear", &val);
+       /* disable the promiscous mode in the HAL */
+       p_hal_funcs->Control(p_hal_dev, pszRX_CAF_EN, pszSet, &val);
+       dbgPrint("Dev set to  Unicast mode.\n");
+    }
+}
+
+static int cpmac_dev_set_mac_addr(struct net_device *p_dev,void * addr)
+{
+    CPMAC_PRIVATE_INFO_T    *p_cpmac_priv = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T    *p_drv_hal    = p_cpmac_priv->drv_hal;
+    HAL_FUNCTIONS           *p_hal_funcs  = p_drv_hal->hal_funcs;
+    HAL_DEVICE              *p_hal_dev    = p_drv_hal->hal_dev;
+    struct sockaddr *sa = addr;
+
+   memcpy(p_cpmac_priv->mac_addr,sa->sa_data,p_dev->addr_len);
+   memcpy(p_dev->dev_addr,sa->sa_data,p_dev->addr_len);
+   p_hal_funcs->Control(p_hal_dev, pszMacAddr, pszSet, p_cpmac_priv->mac_addr);   
+
+	return 0;
+
+}
+
+/* VLAN is handled by vlan/vconfig support. Here, we just check for the 
+ * 802.1q configuration of the device and en-queue the packet accordingly.
+ * We do not do any 802.1q processing here.
+ */
+static int cpmac_dev_tx( struct sk_buff *skb, struct net_device *p_dev)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv  = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal     = p_cpmac_priv->drv_hal;
+    int channel                         = 0;
+    int ret_val                         = 0;
+    FRAGLIST             send_frag_list[1];
+
+#ifdef CPMAC_8021Q_SUPPORT
+    if(skb->len < TCI_END_OFFSET)
+    {
+        /* Whee, frame shorter than 14 bytes !! We need to copy 
+	 * fragments to understand the frame. Too much work. 
+	 * Hmm, dump it. */
+
+        /* Free the buffer */
+	goto cpmac_dev_tx_drop_pkt;
+    }
+
+    /* 802.1p/q stuff */
+    if(IS_802_1Q_FRAME(skb->data + TPID_START_OFFSET)) 
+    {
+        /* IEEE 802.1q, section 8.8 and section 8.11.9 */
+        if(!p_cpmac_priv->enable_802_1q) 
+        {
+           /* free the buffer */
+           goto cpmac_dev_tx_drop_pkt;
+        }		
+
+        channel = GET_802_1P_CHAN(p_cpmac_priv->tx_chan_info->opened_chan,
+              		          skb->data[TCI_START_OFFSET]);
+
+    }
+    /* sending a non 802.1q frame, when configured for 802.1q: dump it.*/
+    else if(p_cpmac_priv->enable_802_1q)
+    {
+         /* free the buffer */
+	 goto cpmac_dev_tx_drop_pkt;
+    }
+    else
+    {
+        ;/* it is the good old non 802.1q */
+    }
+#endif
+
+    send_frag_list->len  = skb->len;
+    send_frag_list->data = skb->data;
+
+#ifdef CPMAC_TEST
+    xdump(skb->data, skb->len, "send");
+#endif
+
+    dma_cache_wback_inv((unsigned long)skb->data, skb->len);    
+
+    if(p_drv_hal->hal_funcs->Send(p_drv_hal->hal_dev, send_frag_list, 1, 
+			          skb->len, skb, channel) != 0)
+    {
+	/* code here to stop the queue, when allowing tx timeout, perhaps next release.*/
+        p_cpmac_priv->net_dev_stats.tx_errors++;  
+#ifndef TI_SLOW_PATH
+       /* Free the skb in case of Send return error */
+        dev_kfree_skb_any(skb);
+        p_cpmac_priv->net_dev_stats.tx_dropped++;
+        return 0;
+#endif
+        goto cpmac_dev_tx_drop_pkt; 
+    }
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//    avalanche_led_action(p_cpmac_priv->led_handle, CPMAC_TX_ACTIVITY);
+//#endif
+
+    return(ret_val);
+
+cpmac_dev_tx_drop_pkt:
+
+    p_cpmac_priv->net_dev_stats.tx_dropped++;
+    ret_val = -1;
+    return (ret_val);
+
+} /*cpmac_dev_tx */
+
+
+//------------------------------------------------------------------------------
+// Public functions : Called by outsiders to this file.
+//------------------------------------------------------------------------------
+
+
+void *cpmac_hal_malloc_buffer(unsigned int size, void* mem_base, unsigned int mem_range,
+	                      OS_SETUP *p_os_setup, HAL_RECEIVEINFO *HalReceiveInfo, 
+ 	                      OS_RECEIVEINFO **osReceiveInfo, OS_DEVICE *p_dev)
+{
+    CPMAC_RX_CHAN_INFO_T *p_rx_chan_info = (CPMAC_RX_CHAN_INFO_T *)p_os_setup;
+    int                  tot_buf_size    = p_rx_chan_info->chan->tot_buf_size;
+    int             tot_reserve_bytes    = p_rx_chan_info->chan->tot_reserve_bytes;
+    struct sk_buff  *p_skb;
+    void             *ret_ptr;
+
+    /* use TI SKB private pool */
+    p_skb = dev_alloc_skb(tot_buf_size);
+
+    if(p_skb == NULL)
+    {
+        errPrint("Failed to allocate skb for %s.\n", ((struct net_device*)p_dev)->name);
+        return (NULL);
+    }
+
+    p_skb->dev = p_dev;
+    skb_reserve(p_skb, tot_reserve_bytes);
+
+    *osReceiveInfo = p_skb;
+
+    ret_ptr = skb_put(p_skb, p_rx_chan_info->chan->buffer_size);
+
+    return(ret_ptr);
+}
+
+void cpmac_hal_isr(int irq, void *p_param, struct pt_regs *regs)
+{
+    CPMAC_ISR_INFO_T      *p_cb_param    = (CPMAC_ISR_INFO_T*) p_param;
+    CPMAC_DRV_HAL_INFO_T  *p_drv_hal     = p_cb_param->owner;
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv   = p_drv_hal->owner;
+    int                   pkts_to_handle = 0;
+
+    if(p_cpmac_priv->non_data_irq_expected)
+    {
+        p_cb_param->hal_isr(p_drv_hal->hal_dev, &pkts_to_handle);
+        p_drv_hal->hal_funcs->PacketProcessEnd(p_drv_hal->hal_dev);
+    }
+    else if(!p_cpmac_priv->set_to_close)
+        tasklet_schedule(&((CPMAC_ISR_INFO_T*) p_param)->tasklet);
+    else
+        ; // back off from doing anything more. We are closing down.
+}
+
+void cpmac_handle_tasklet(unsigned long data)
+{
+    CPMAC_ISR_INFO_T     *p_cb_param   = (CPMAC_ISR_INFO_T*) data;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal    = p_cb_param->owner;
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = p_drv_hal->owner;
+    int                  pkts_to_handle;
+
+    p_cb_param->hal_isr(p_drv_hal->hal_dev, &pkts_to_handle);
+
+    if(test_bit(0, &p_cpmac_priv->non_data_irq_expected) || !pkts_to_handle)
+        p_drv_hal->hal_funcs->PacketProcessEnd(p_drv_hal->hal_dev);
+    else if(!test_bit(0, &p_cpmac_priv->set_to_close))
+        tasklet_schedule(&p_cb_param->tasklet);
+    else
+        ; // Back off from processing packets we are closing down.
+}
+
+int cpmac_hal_control(OS_DEVICE *p_dev, const char *key, 
+	              const char *action, void *value)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = p_dev->priv;
+    int ret_val = -1;
+
+    if(key == NULL)
+    {
+        dbgPrint("Encountered NULL key.\n");
+	return (-1);
+    }
+
+    if(cpmac_ci_strcmp(key, "Sleep") == 0 && value != NULL)
+    {
+        unsigned int clocks_per_tick  = cpmac_cpu_freq/HZ;
+	unsigned int requested_clocks = *(unsigned int*)value;
+	unsigned int requested_ticks  = (requested_clocks + clocks_per_tick - 1)/clocks_per_tick;
+        mdelay(requested_ticks); 
+	ret_val = 0;
+    }
+    else if(cpmac_ci_strcmp(key, "StateChange") == 0)
+    {
+        ret_val = cpmac_p_process_status_ind(p_cpmac_priv);
+    }
+    else if(cpmac_ci_strcmp(key, "Tick") == 0 && action != NULL)
+    {
+	if(cpmac_ci_strcmp(action, "Set") == 0 && value != NULL)
+	{
+            if(*(unsigned int*)value == 0)
+            {
+                cpmac_p_stop_timer(p_cpmac_priv->timer + TICK_TIMER);
+                ret_val = 0;
+            }
+            else
+            {
+                unsigned int clocks_per_tick  = cpmac_cpu_freq/HZ;
+	        unsigned int requested_clocks = *(unsigned int*)value;
+	        unsigned int requested_ticks  = (requested_clocks + clocks_per_tick - 1)/clocks_per_tick;
+
+                p_cpmac_priv->delay_ticks =  requested_ticks; /* save it for re-triggering */
+	        ret_val = cpmac_p_start_timer(p_cpmac_priv->timer + TICK_TIMER, 
+		  	                      p_cpmac_priv->delay_ticks);
+            }
+	}
+        else if(cpmac_ci_strcmp(action, "Clear") == 0)
+        {
+            ret_val = cpmac_p_stop_timer(p_cpmac_priv->timer + TICK_TIMER);
+        }
+        else
+            ;
+    }
+    else if(cpmac_ci_strcmp(key, "MacAddr") == 0 && action != NULL)
+    {
+        if(cpmac_ci_strcmp(action, "Get") == 0 && value != NULL)
+	{
+            *(char **)value = p_cpmac_priv->mac_addr; 
+	    ret_val = 0;
+	}
+    }
+    else if(cpmac_ci_strcmp(key, "CpuFreq") == 0)
+    {
+       if(cpmac_ci_strcmp(action, "Get") == 0 && value != NULL)
+       {
+           *(unsigned int *)value = cpmac_cpu_freq;
+           dbgPrint("Cpu frequency for cpmacs is %u\n",cpmac_cpu_freq);
+           ret_val = 0;
+       }
+    }
+    else if(cpmac_ci_strcmp(key, "SioFlush") == 0)
+    {
+       ret_val = 0;
+       dbgPrint("\n"); 
+    }
+    else if(cpmac_ci_strcmp(key, "CpmacFrequency") == 0)
+    {
+        /* For Sangam cpmac clock is off the PBUS */
+        /* OS Needs to supply CORRECT frequency */
+        if(cpmac_ci_strcmp(action, "Get") == 0 && value != NULL)
+        {
+            *(unsigned int *)value = CONFIG_AR7_SYS * 1000 * 1000;
+            ret_val = 0;
+        }
+    }
+    /* For now, providing back the default values. */
+    else if(cpmac_ci_strcmp(key, "MdioClockFrequency") == 0)
+    {
+        if(cpmac_ci_strcmp(action, "Get") == 0 && value != NULL)
+        {
+            *(unsigned int *)value = 2200000;  /*DEFAULT */
+            ret_val = 0;
+        }
+    }
+    /* For now, providing back the default values. */
+    else if(cpmac_ci_strcmp(key, "MdioBusFrequency") == 0)
+    {
+        /* For Sangam MdioBusFreq is off the PBUS */
+        if(cpmac_ci_strcmp(action, "Get") == 0 && value != NULL)
+        {
+            *(unsigned int *)value = CONFIG_AR7_SYS * 1000 * 1000;
+            ret_val = 0;
+        }
+    }
+  
+#if 0 
+#if defined(CONFIG_AVALANCHE_AUTO_MDIX) 
+    /* supporting Mdio Mdix switching */
+    else if(cpmac_ci_strcmp(key, hcMdioMdixSwitch) == 0)
+    {
+        /* For Sangam Mdio-switching  action should be always "set"*/
+        if(cpmac_ci_strcmp(action, hcSet) == 0 && value != NULL )
+        {
+           unsigned  int mdix =  *((unsigned int *) value) ;
+
+           if(mdix)
+              avalanche_set_phy_into_mdix_mode();
+
+           else
+              avalanche_set_phy_into_mdi_mode();  
+  
+           ret_val = 0;
+        } 
+
+    }
+#endif
+#endif
+    else if(cpmac_ci_strcmp(key, hcMdioMdixSwitch) == 0)
+    {
+        /* For Sangam Mdio-switching  action should be always "set"*/
+        if(cpmac_ci_strcmp(action, hcSet) == 0 && value != NULL )
+        {
+           unsigned  int mdix =  *((unsigned int *) value) ;
+
+#ifdef CONFIG_AR7_MDIX
+	   avalanche_set_mdix_on_chip(0xa8610000 , mdix ? 1: 0);
+#endif
+  
+           ret_val = 0;
+        } 
+
+    }
+
+    return(ret_val);
+}
+
+
+int cpmac_hal_receive(OS_DEVICE *p_dev, FRAGLIST *fragList, 
+                             unsigned int fragCount,
+                             unsigned int packet_size, 
+                             HAL_RECEIVEINFO *hal_receive_info,
+                             unsigned int mode)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv  = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal     = p_cpmac_priv->drv_hal;
+    struct sk_buff       *p_skb         = fragList[0].OsInfo;
+    p_skb->len                          = fragList[0].len;    
+
+    /* invalidate the cache. */
+    dma_cache_inv((unsigned long)p_skb->data, fragList[0].len);    
+#ifdef CPMAC_TEST
+    xdump(p_skb->data, p_skb->len, "recv");
+#endif
+#ifdef CPMAC_8021Q_SUPPORT
+    /* 802.1q stuff, just does the basic checking here. */
+    if(!p_cpmac_priv->enable_802_1q      &&
+       p_skb->len > TCI_END_OFFSET       &&
+       IS_802_1Q_FRAME(p_skb->data + TPID_START_OFFSET))
+    {
+         goto cpmac_hal_recv_frame_mismatch;
+    }
+#endif
+    if(fragCount > 1) 	    
+    {	    
+       int     len;
+       struct sk_buff *p_temp_skb;
+       CPMAC_RX_CHAN_INFO_T *p_rx_chan_info = p_cpmac_priv->rx_chan_info;
+       int     count;
+       
+       dbgPrint("Recv: It is multifragment for %s.\n", p_dev->name);
+       
+       p_skb = dev_alloc_skb(packet_size + 
+          p_rx_chan_info->chan->tot_reserve_bytes); 
+       if(p_skb == NULL) 
+       {
+          p_cpmac_priv->net_dev_stats.rx_errors++;
+          goto cpmac_hal_recv_alloc_failed;
+       }
+       
+       p_skb->dev = p_dev;
+       skb_reserve(p_skb, p_rx_chan_info->chan->tot_reserve_bytes);
+       
+       for(count = 0; count < fragCount; count++)
+       {
+          p_temp_skb = fragList[count].OsInfo;
+          len        = fragList[count].len;
+          
+          dma_cache_inv((unsigned long)p_temp_skb->data, len);
+          
+          memcpy(skb_put(p_skb, len), p_temp_skb->data, len);
+          dev_kfree_skb_any(p_temp_skb);
+       }
+    }
+    
+
+#if defined(CONFIG_MIPS_AVALANCHE_MARVELL)                                                                                                   
+ /* Fetch the receiving port information from EGRESS TRAILOR Bytes*/         
+     p_dev->if_port = (unsigned char)p_skb->data[packet_size -(EGRESS_TRAILOR_LEN-1)] + AVALANCHE_MARVELL_BASE_PORT_ID;
+    skb_trim(p_skb, packet_size - EGRESS_TRAILOR_LEN);                                                                       
+#else                                                                                                                        
+    /* set length & tail */                                                                                                  
+    skb_trim(p_skb, packet_size);                                                                                            
+#endif 
+ 
+    p_skb->protocol = eth_type_trans(p_skb, p_dev);
+
+    netif_rx(p_skb);
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//    avalanche_led_action(p_cpmac_priv->led_handle, CPMAC_RX_ACTIVITY);	
+//#endif
+
+    p_cpmac_priv->net_dev_stats.rx_packets++;
+    p_cpmac_priv->net_dev_stats.rx_bytes += packet_size;
+
+    p_drv_hal->hal_funcs->RxReturn(hal_receive_info,1);
+
+    return(0);
+
+cpmac_hal_recv_alloc_failed:
+
+#ifdef CPMAC_8021Q_SUPPORT
+cpmac_hal_recv_frame_mismatch:
+#endif
+ 
+    fragCount--;
+
+    do
+    {
+        dev_kfree_skb_any(fragList[fragCount].OsInfo);
+    }
+    while(fragCount--);
+
+    p_cpmac_priv->net_dev_stats.rx_dropped++;
+
+    return(-1);
+} /*cpmac_receive*/
+
+
+void cpmac_hal_tear_down_complete(OS_DEVICE*a, int b, int ch)
+{
+    dbgPrint("what to do with this.\n");
+}
+
+
+int  cpmac_hal_send_complete(OS_SENDINFO *p_skb)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv = p_skb->dev->priv;
+
+    p_cpmac_priv->net_dev_stats.tx_packets++;
+    p_cpmac_priv->net_dev_stats.tx_bytes += p_skb->len;
+    
+    dev_kfree_skb_any(p_skb);
+
+    return(0);
+}
+
+
+int cpmac_reset(CPMAC_PRIVATE_INFO_T *p_cpmac_priv)
+{
+    // code here to reset the device/hal. Not now.
+
+   netif_wake_queue(p_cpmac_priv->owner);
+   return(0);
+}
+
+#ifdef CPMAC_TEST
+
+#define isprint(a) ((a >=' ')&&(a<= '~'))
+void xdump( u_char*  cp, int  length, char*  prefix )
+{
+    int col, count;
+    u_char prntBuf[120];
+    u_char*  pBuf = prntBuf;
+    count = 0;
+    while(count < length){
+        pBuf += sprintf( pBuf, "%s", prefix );
+        for(col = 0;count + col < length && col < 16; col++){
+            if (col != 0 && (col % 4) == 0)
+                pBuf += sprintf( pBuf, " " );
+            pBuf += sprintf( pBuf, "%02X ", cp[count + col] );
+        }
+        while(col++ < 16){      /* pad end of buffer with blanks */
+            if ((col % 4) == 0)
+                sprintf( pBuf, " " );
+            pBuf += sprintf( pBuf, "   " );
+        }
+        pBuf += sprintf( pBuf, "  " );
+        for(col = 0;count + col < length && col < 16; col++){
+            if (isprint((int)cp[count + col]))
+                pBuf += sprintf( pBuf, "%c", cp[count + col] );
+            else
+                pBuf += sprintf( pBuf, "." );
+                }
+        sprintf( pBuf, "\n" );
+        // SPrint(prntBuf);
+        printk(prntBuf);
+        count += col;
+        pBuf = prntBuf;
+    }
+
+}  /* close xdump(... */
+#endif
+
+
+static int __init cpmac_dev_probe(void)
+{
+    int     retVal         = 0;
+    int     unit;
+    int     instance_count = CONFIG_MIPS_CPMAC_PORTS;
+
+    //cpmac_cpu_freq = avalanche_clkc_get_freq(CLKC_MIPS);
+    cpmac_cpu_freq = CONFIG_AR7_CPU * 1000 * 1000;
+
+    build_psp_config();                       
+
+    for(unit = 0; unit < instance_count; unit++)
+    {
+        struct net_device	        *p_dev;
+        CPMAC_PRIVATE_INFO_T            *p_cpmac_priv;
+        size_t		                dev_size;
+	int                             failed;
+
+        dev_size =    sizeof(struct net_device) 
+	            + sizeof(CPMAC_PRIVATE_INFO_T);
+
+
+        if((p_dev = (struct net_device *) kmalloc(dev_size, GFP_KERNEL)) == NULL)
+        {
+            dbgPrint( "Could not allocate memory for device.\n" );
+            retVal = -ENOMEM;
+            break;
+        }            
+               
+        memset(p_dev, 0, dev_size );
+
+        p_dev->priv                 = p_cpmac_priv
+                                    = (CPMAC_PRIVATE_INFO_T*)(((char *) p_dev) + sizeof(struct net_device));
+        p_cpmac_priv->owner         = p_dev;
+	
+        ether_setup(p_dev); 
+
+	p_cpmac_priv->instance_num  = unit;
+        p_dev->init                 = cpmac_dev_init;
+
+        g_dev_array[p_cpmac_priv->instance_num] = p_dev;
+        
+#if defined CONFIG_MIPS_CPMAC_INIT_BUF_MALLOC
+        g_init_enable_flag = 1;
+        printk("Cpmac driver is allocating buffer memory at init time.\n");
+#endif
+
+	/* This section gives a default value by the number of PHY in order to
+	 * replace the default MACRO. */
+	{
+	    char *mac_port = prom_getenv("MAC_PORT"); /* Internal: 0, External: 1 */
+	    if(!mac_port || 0 == strcmp(mac_port, "1")) {
+		printk("Using the MAC with external PHY\n");
+		cfg_start_link_speed = _CPMDIO_NOPHY;
+		cpmac_max_frame_size = CPMAC_MAX_FRAME_SIZE + 4;
+	    }
+	    else {
+		printk("Using the MAC with internal PHY\n");
+		cfg_start_link_speed = CFG_START_LINK_SPEED;
+		cpmac_max_frame_size = CPMAC_MAX_FRAME_SIZE;
+	    }
+	    g_cfg_start_link_params = cfg_start_link_speed;
+	}
+
+        cpmac_p_detect_manual_cfg(cfg_link_speed, cfg_link_mode, cpmac_debug_mode);
+
+    	failed = register_netdev(p_dev);
+        if (failed)
+        {
+            dbgPrint("Could not register device for inst %d because of reason \
+                      code %d.\n", unit, failed);
+            retVal = -1;
+            kfree(p_dev);
+            break;
+        }           
+        else
+        {
+
+            char proc_name[100];
+            int  proc_category_name_len = 0;
+
+	    p_cpmac_priv->next_device = last_cpmac_device;
+            last_cpmac_device         = p_dev;
+
+    	    dbgPrint(" %s irq=%2d io=%04x\n",p_dev->name, (int) p_dev->irq,
+    	    	       (int) p_dev->base_addr);
+
+	    strcpy(proc_name, "avalanche/");
+            strcat(proc_name, p_dev->name);
+            proc_category_name_len = strlen(proc_name);
+
+            strcpy(proc_name + proc_category_name_len, "_rfc2665_stats");
+            create_proc_read_entry(proc_name,0,NULL,cpmac_p_read_rfc2665_stats, p_dev);
+
+    	}
+    }
+
+    if(retVal == 0)
+    {
+	/* To maintain backward compatibility with NSP. */
+        gp_stats_file = create_proc_entry("avalanche/cpmac_stats", 0644, NULL);
+        if(gp_stats_file)
+        {
+            gp_stats_file->read_proc  = cpmac_p_read_stats;
+            gp_stats_file->write_proc = cpmac_p_write_stats;
+        }
+	create_proc_read_entry("avalanche/cpmac_link", 0, NULL, cpmac_p_read_link, NULL);
+	create_proc_read_entry("avalanche/cpmac_ver", 0, NULL, cpmac_p_get_version, NULL);
+
+    }
+   
+    cpmac_devices_installed  = unit;
+    dbgPrint("Installed %d cpmac instances.\n", unit);
+    return ( (unit >= 0 ) ? 0 : -ENODEV );
+
+} /* init_module */
+
+
+/***************************************************************
+ *	cleanup_module
+ *
+ *	Returns:
+ *		Nothing
+ *	Parms:
+ *		None
+ *
+ *	Goes through the CpmacDevices list and frees the device
+ *	structs and memory associated with each device (lists
+ *	and buffers).  It also ureserves the IO port regions
+ *	associated with this device.
+ *
+ **************************************************************/
+
+void cpmac_exit(void)
+{
+    struct net_device       *p_dev;
+    CPMAC_PRIVATE_INFO_T    *p_cpmac_priv;
+
+    while (cpmac_devices_installed) 
+    {
+        char proc_name[100];
+        int  proc_category_name_len = 0;
+
+        p_dev = last_cpmac_device;
+        p_cpmac_priv = (CPMAC_PRIVATE_INFO_T *) p_dev->priv;
+
+    	dbgPrint("Unloading %s irq=%2d io=%04x\n",p_dev->name, (int) p_dev->irq, (int) p_dev->base_addr);
+
+        if(g_init_enable_flag)
+            cpmac_p_dev_disable(p_dev);
+      
+        cpmac_drv_cleanup(p_cpmac_priv->drv_hal);
+
+//#if defined (CONFIG_MIPS_AVALANCHE_LED)
+//        avalanche_led_unregister(p_cpmac_priv->led_handle);
+//#endif
+	strcpy(proc_name, "avalanche/");
+        strcat(proc_name, p_dev->name);
+        proc_category_name_len = strlen(proc_name);
+
+        strcpy(proc_name + proc_category_name_len, "_rfc2665_stats");
+        remove_proc_entry(proc_name, NULL);
+        
+        release_mem_region(p_dev->base_addr, p_cpmac_priv->dev_size);
+        unregister_netdev(p_dev);
+	last_cpmac_device = p_cpmac_priv->next_device;
+
+        kfree(p_cpmac_priv->drv_hal);
+        kfree(p_dev);
+     
+	cpmac_devices_installed--;
+    }
+
+    if(gp_stats_file)
+        remove_proc_entry("avalanche/cpmac_stats", NULL);
+
+    remove_proc_entry("avalanche/cpmac_link",  NULL);
+    remove_proc_entry("avalanche/cpmac_ver",   NULL);
+
+    psp_config_cleanup();
+}
+
+     
+module_init(cpmac_dev_probe);
+module_exit(cpmac_exit);
diff -urN linux.old/drivers/net/avalanche_cpmac/cpmac.h linux.dev/drivers/net/avalanche_cpmac/cpmac.h
--- linux.old/drivers/net/avalanche_cpmac/cpmac.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpmac.h	2005-07-12 02:48:42.043594000 +0200
@@ -0,0 +1,379 @@
+/******************************************************************************
+ * FILE PURPOSE:    CPMAC Linux Network Device Driver Header
+ ******************************************************************************
+ * FILE NAME:       cpmac.h
+ *
+ * DESCRIPTION:     CPMAC Network Device Driver Header
+ *
+ * REVISION HISTORY:
+ * Date            Name                   Details
+ *----------------------------------------------------------------------------- 
+ * 27 Nov 2002     Suraj S Iyer           Initial Create.
+ * 09 Jun 2003     Suraj S Iyer           Preparing for GA.
+ *
+ * (C) Copyright 2003, Texas Instruments, Inc
+ *******************************************************************************/
+
+#ifndef CPMAC_H
+#define CPMAC_H
+
+#include <linux/timer.h>
+#include <linux/netdevice.h>
+#include <asm/semaphore.h>
+#include <linux/ctype.h>
+#include <linux/interrupt.h>
+
+#include "cpmacHalLx.h"
+/*-----------------------------------------------------------------------------
+ * Config macros. Use these to config the driver.
+ *---------------------------------------------------------------------------*/
+#define CPMAC_MAX_FRAME_SIZE         1518
+
+#if defined(CONFIG_AR7WRD) || defined(CONFIG_AR7WI) || defined(CONFIG_AR7VWI)|| defined(CONFIG_AR7VW) 
+#define CFG_RX_NUM_BUF_DESC            64 
+#define CFG_RX_NUM_BUF_SERVICE         32 
+#else                                     
+#define CFG_RX_NUM_BUF_DESC            16 
+#define CFG_RX_NUM_BUF_SERVICE         8  
+#endif                                    
+
+#define CFG_RX_BUF_OFFSET              0
+
+#define CFG_TX_NUM_BUF_DESC            128
+#define CFG_TX_NUM_BUF_SERVICE         20 
+#define CFG_TX_BUF_OFFSET              0  /* Lets not change this. */
+#define CFG_TX_TIMEOUT                 2000 /* ticks*/
+#define CFG_TX_INT_DISABLE             1  /* Disable the Tx Complete interrupt */
+
+#define CFG_JUMBO_FRAMES               1
+#define CFG_SHORT_FRAMES               1
+#define CFG_PROMISCOUS                 1
+#define CFG_BROADCAST                  1
+#define CFG_MULTICAST                  1
+#define CFG_ALL_MULTI                  (1*(CFG_MULTICAST))
+#define CFG_AUTO_NEGOTIATION           1
+
+#if defined (CONFIG_MIPS_AVALANCHE_MARVELL)
+#define EGRESS_TRAILOR_LEN             4 
+#define CFG_START_LINK_SPEED           (_CPMDIO_NOPHY)
+#undef  CPMAC_MAX_FRAME_SIZE
+#define CPMAC_MAX_FRAME_SIZE          (1518 + EGRESS_TRAILOR_LEN)
+#else
+#define CFG_START_LINK_SPEED          (_CPMDIO_10 | _CPMDIO_100 | _CPMDIO_HD | _CPMDIO_FD) /* auto nego */
+#endif
+
+#define CFG_LOOP_BACK                  1
+#define CFG_TX_FLOW_CNTL               0
+#define CFG_RX_FLOW_CNTL               0
+#define CFG_TX_PACING                  0
+#define CFG_RX_PASS_CRC                0
+#define CFG_QOS_802_1Q                 0
+#define CFG_TX_NUM_CHAN                1
+
+
+/*-----------------------------------------------------------------------------
+ * Private macros.
+ *---------------------------------------------------------------------------*/
+#define MAX_TIMER               2
+#define TX_TIMER                0
+#define TICK_TIMER              0
+#define MAX_TX_CHAN             8
+
+#define CPMAC_LINK_OFF          0
+#define CPMAC_LINK_ON           1
+/*#define CPMAC_SPEED_100         2
+#define CPMAC_SPEED_10          3
+#define CPMAC_FULL_DPLX         4
+#define CPMAC_HALF_DPLX         5*/
+#define CPMAC_RX_ACTIVITY       2
+#define CPMAC_TX_ACTIVITY       3
+
+struct cpmac_timer_info;
+
+typedef int  (*CPMAC_HAL_ISR_FUNC_T)(HAL_DEVICE*, int*);
+typedef int  (*CPMAC_TIMEOUT_CB_T)(struct cpmac_timer_info*);
+
+typedef struct cpmac_ability_info
+{
+    int promiscous;
+    int broadcast;
+    int multicast;
+    int all_multi;
+    int loop_back;
+    int jumbo_frames;
+    int short_frames;
+    int auto_negotiation;
+    int tx_flow_control;
+    int rx_flow_control;
+    int tx_pacing;
+    int link_speed;
+    int rx_pass_crc;
+    int qos_802_1q;
+    int tx_num_chan;
+}
+CPMAC_ABILITY_INFO_T;
+
+#ifdef DEBUG
+typedef struct cpmac_timer_info
+{
+    void               *owner;
+    UINT32             delay_ticks;
+    WDOG_ID            timer_id;
+    UINT32             is_running;
+    UINT32             timer_set_at;
+    CPMAC_TIMEOUT_CB_T timeout_CB;
+} CPMAC_TIMER_INFO_T;
+
+typedef struct
+{
+    void               *owner;
+    unsigned int       num_cl_desc;
+    CL_DESC            *cl_desc_tbl;
+    M_CL_CONFIG        *m_cl_blk_config;
+    NET_POOL           *net_pool;
+    CL_POOL_ID         clPoolId;
+
+} CPMAC_NET_MEM_INFO_T;
+
+#endif
+
+typedef struct
+{
+    void                  *owner;
+    CPMAC_HAL_ISR_FUNC_T  hal_isr;
+    struct tasklet_struct tasklet;
+    int                   intr;
+
+} CPMAC_ISR_INFO_T;
+
+typedef struct cpmac_chan
+{
+   int num_BD;
+   int buffer_size;
+   int buffer_offset;
+   int service_max;
+   int state;
+   int tot_buf_size;
+   int tot_reserve_bytes;
+
+} CPMAC_CHAN_T;
+
+#define CHAN_CLOSE  0
+#define CHAN_OPENED 1
+
+typedef struct 
+{
+    int          cfg_chan;
+    int          dev_chan;
+    int          opened_chan;
+    CPMAC_CHAN_T chan[1];
+    int          enable_802_1q;
+
+} CPMAC_RX_CHAN_INFO_T;
+
+typedef struct
+{
+    int          cfg_chan;
+    int          dev_chan;
+    int          opened_chan;
+    int          tx_int_disable;
+    CPMAC_CHAN_T chan[MAX_TX_CHAN];
+   
+} CPMAC_TX_CHAN_INFO_T;
+
+
+
+typedef struct
+{
+   void                        *owner;
+   HAL_FUNCTIONS               *hal_funcs;
+   HAL_DEVICE                  *hal_dev;
+   OS_FUNCTIONS                *os_funcs; 
+//   SEM_ID                      chan_teardown_sem;
+   int                         non_data_irq_expected;
+} CPMAC_DRV_HAL_INFO_T;
+
+
+typedef struct
+{
+    unsigned long tx_discards;
+    unsigned long rx_discards;
+    unsigned long start_tick;
+
+} CPMAC_DRV_STATS_T;
+
+typedef struct 
+{
+    unsigned long   ifInGoodFrames;
+    unsigned long   ifInBroadcasts;
+    unsigned long   ifInMulticasts;
+    unsigned long   ifInPauseFrames;
+    unsigned long   ifInCRCErrors;
+    unsigned long   ifInAlignCodeErrors;
+    unsigned long   ifInOversizedFrames;
+    unsigned long   ifInJabberFrames;
+    unsigned long   ifInUndersizedFrames;
+    unsigned long   ifInFragments;
+    unsigned long   ifInFilteredFrames;
+    unsigned long   ifInQosFilteredFrames;
+    unsigned long   ifInOctets;
+    unsigned long   ifOutGoodFrames;
+    unsigned long   ifOutBroadcasts;
+    unsigned long   ifOutMulticasts;
+    unsigned long   ifOutPauseFrames;
+    unsigned long   ifDeferredTransmissions;
+    unsigned long   ifCollisionFrames;
+    unsigned long   ifSingleCollisionFrames;
+    unsigned long   ifMultipleCollisionFrames;
+    unsigned long   ifExcessiveCollisionFrames;
+    unsigned long   ifLateCollisions;
+    unsigned long   ifOutUnderrun;
+    unsigned long   ifCarrierSenseErrors;
+    unsigned long   ifOutOctets;
+    unsigned long   if64OctetFrames;
+    unsigned long   if65To127OctetFrames;
+    unsigned long   if128To255OctetFrames;
+    unsigned long   if256To511OctetFrames;
+    unsigned long   if512To1023OctetFrames;
+    unsigned long   if1024ToUPOctetFrames;
+    unsigned long   ifNetOctets;
+    unsigned long   ifRxSofOverruns;
+    unsigned long   ifRxMofOverruns;
+    unsigned long   ifRxDMAOverruns;
+
+} CPMAC_DEVICE_MIB_T;
+
+
+typedef struct
+{
+    void                         *owner;
+    int                          timer_count;
+    int                          timer_created;
+    struct timer_list            timer[1];
+    CPMAC_DRV_HAL_INFO_T         *drv_hal;
+    unsigned int                 num_of_intr;
+    CPMAC_ISR_INFO_T             cpmac_isr;
+    unsigned int                 link_speed;
+    unsigned int                 link_mode;
+    unsigned int                 enable_802_1q;
+    unsigned int                 timer_access_hal;
+    unsigned int                 loop_back;
+    CPMAC_RX_CHAN_INFO_T         *rx_chan_info;
+    CPMAC_TX_CHAN_INFO_T         *tx_chan_info;
+    CPMAC_ABILITY_INFO_T         *ability_info;
+    CPMAC_DEVICE_MIB_T           *device_mib;
+    CPMAC_DRV_STATS_T            *stats;
+    unsigned int                 flags;
+    unsigned int                 delay_ticks;
+    char                         mac_addr[6];
+    struct net_device_stats      net_dev_stats; 
+//    rwlock_t                     rw_lock;
+    int                          set_to_close;
+    struct net_device            *next_device;
+    unsigned int                 instance_num;
+    unsigned int                 non_data_irq_expected;
+    unsigned long                dev_size;
+    void*                        led_handle;
+} CPMAC_PRIVATE_INFO_T;
+
+
+/* Private flags */
+
+/* bit 0 to 31, bit 32 is used to indicate set or reset */
+
+#define IFF_PRIV_SHORT_FRAMES   0x00010000
+#define IFF_PRIV_JUMBO_FRAMES   0x00020000
+#define IFF_PRIV_AUTOSPEED      0x00080000
+#define IFF_PRIV_LINK10_HD      0x00100000
+#define IFF_PRIV_LINK10_FD      0x00200000
+#define IFF_PRIV_LINK100_HD     0x00400000
+#define IFF_PRIV_LINK100_FD     0x00800000
+#define IFF_PRIV_8021Q_EN       0x01000000
+#define IFF_PRIV_NUM_TX_CHAN    0x02000000
+#define IFF_PRIV_TX_FLOW_CNTL   0x04000000
+#define IFF_PRIV_RX_FLOW_CNTL   0x08000000
+#define IFF_PRIV_TX_PACING      0x10000000
+#define IFF_PRIV_RX_PASS_CRC    0x20000000
+
+#define PRIVCSFLAGS             0x200
+#define PRIVCGFLAGS             0x201
+
+
+#define BLOCKING      1
+#define CHAN_TEARDOWN 2
+#define CHAN_SETUP    4
+#define COMPLETE      8
+#define FREE_BUFFER   16
+
+
+static const char pszStats0[]            = "Stats0";
+static const char pszStats1[]            = "Stats1";
+static const char pszStats2[]            = "Stats2";
+static const char pszStats3[]            = "Stats3";
+static const char pszStats4[]            = "Stats4";
+static const char pszStatsDump[]         = "StatsDump";
+static const char pszStatsClear[]        = "StatsClear";
+static const char pszRX_PASS_CRC[]       = "RX_PASS_CRC";
+static const char pszRX_QOS_EN[]         = "RX_QOS_EN";
+static const char pszRX_NO_CHAIN[]       = "RX_NO_CHAIN";
+static const char pszRX_CMF_EN[]         = "RX_CMF_EN";
+static const char pszRX_CSF_EN[]         = "RX_CSF_EN";
+static const char pszRX_CEF_EN[]         = "RX_CEF_EN";
+static const char pszRX_CAF_EN[]         = "RX_CAF_EN";
+static const char pszRX_PROM_CH[]        = "RX_PROM_CH";
+static const char pszRX_BROAD_EN[]       = "RX_BROAD_EN";
+static const char pszRX_BROAD_CH[]       = "RX_BROAD_CH";
+static const char pszRX_MULT_EN[]        = "RX_MULT_EN";
+static const char pszRX_MULT_CH[]        = "RX_MULT_CH";
+static const char pszTX_PTYPE[]          = "TX_PTYPE";
+static const char pszTX_PACE[]           = "TX_PACE";
+static const char pszMII_EN[]            = "MII_EN";
+static const char pszTX_FLOW_EN[]        = "TX_FLOW_EN";
+static const char pszRX_FLOW_EN[]        = "RX_FLOW_EN";
+static const char pszRX_MAXLEN[]         = "RX_MAXLEN";
+static const char pszRX_FILTERLOWTHRESH[]   = "RX_FILTERLOWTHRESH";
+static const char pszRX0_FLOWTHRESH[]   = "RX0_FLOWTHRESH";
+static const char pszRX_UNICAST_SET[]    = "RX_UNICAST_SET";
+static const char pszRX_UNICAST_CLEAR[]  = "RX_UNICAST_CLEAR";
+static const char pszMdioConnect[]       = "MdioConnect";
+static const char pszMacAddr[]           = "MacAddr";
+static const char pszTick[]              = "Tick";
+static const char pszRX_MULTICAST[]      = "RX_MULTICAST";
+static const char pszRX_MULTI_ALL[]      = "RX_MULTI_ALL";
+static const char pszRX_MULTI_SINGLE[]   = "RX_MULTI_SINGLE";
+
+static const char pszSet[]               = "Set";
+static const char pszGet[]               = "Get";
+static const char pszClear[]             = "Clear";
+
+
+void *cpmac_hal_malloc_buffer(unsigned int size, void *MemBase, unsigned int MemRange,
+                              HAL_DEVICE *HalDev, HAL_RECEIVEINFO *HalReceiveInfo, 
+                              OS_RECEIVEINFO **OsReceiveInfo, OS_DEVICE *OsDev);
+
+void cpmac_hal_tear_down_complete(OS_DEVICE*, int, int);
+int  cpmac_hal_control(OS_DEVICE *p_END_obj, const char *key, 
+                   const char *action, void *value);
+int  cpmac_hal_receive(OS_DEVICE *p_END_obj, FRAGLIST *fragList, 
+               unsigned int FragCount, unsigned int pkt_len, 
+               HAL_RECEIVEINFO *halReceiveInfo, 
+               unsigned int mode);
+int  cpmac_hal_send_complete(OS_SENDINFO*);
+
+void  cpmac_hal_isr(int irq, void *p_param, struct pt_regs *p_cb_param);
+void  cpmac_handle_tasklet(unsigned long data);
+
+inline static int cpmac_ci_strcmp(const char *s1, const char *s2)
+{
+    while(*s1 && *s2)
+    {
+        if(tolower(*s1) != tolower(*s2))
+            break;
+        s1++;
+        s2++;
+    }
+
+    return(tolower(*s1) - tolower(*s2));
+}
+
+#endif
diff -urN linux.old/drivers/net/avalanche_cpmac/cpmacHalLx.c linux.dev/drivers/net/avalanche_cpmac/cpmacHalLx.c
--- linux.old/drivers/net/avalanche_cpmac/cpmacHalLx.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpmacHalLx.c	2005-07-12 02:48:42.044593000 +0200
@@ -0,0 +1,492 @@
+/******************************************************************************
+ * FILE PURPOSE:    CPMAC Net Driver HAL support Source
+ ******************************************************************************
+ * FILE NAME:       cpmacHalLx.c
+ *
+ * DESCRIPTION:     CPMAC Network Device Driver Source
+ *
+ * REVISION HISTORY:
+ *
+ * Date           Description                               Author
+ *-----------------------------------------------------------------------------
+ * 27 Nov 2002    Initial Creation                          Suraj S Iyer  
+ * 09 Jun 2003    Updates for GA                            Suraj S Iyer
+ * 18 Dec 2003    Updated for 5.7                           Suraj S Iyer
+ *
+ * (C) Copyright 2003, Texas Instruments, Inc
+ *******************************************************************************/
+#include <linux/kernel.h> 
+#include <linux/module.h> 
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/delay.h>     
+#include <linux/spinlock.h>
+#include <linux/proc_fs.h>
+#include <asm/io.h>
+#include <linux/string.h>
+
+#include <asm/ar7/avalanche_intc.h>
+
+#include "cpmacHalLx.h"
+#include "cpmac.h"
+
+/* PSP config headers */
+#include "psp_config_parse.h"
+#include "psp_config_mgr.h"
+
+/* debug */                                 
+extern int cpmac_debug_mode;
+#define dbgPrint if (cpmac_debug_mode) printk
+#define errPrint printk
+
+char CpmacSignature[] = "Cpmac driver";
+static unsigned long irq_flags = 0;
+OS_SETUP *p_os_setup = NULL;
+
+extern int avalanche_request_intr_pacing(int, unsigned int, unsigned int);
+extern int avalanche_free_intr_pacing(unsigned int blk_num);
+
+/*----------------------------------------------------------------------------
+ * Parameter extracting functionalities.
+ *--------------------------------------------------------------------------*/
+static int os_find_parm_u_int(void *info_ptr, const char *param, unsigned int *val)
+{
+    int ret_val = 0;
+
+    if((ret_val = psp_config_get_param_uint(info_ptr, param, val)) == -1)
+    {
+        dbgPrint("Error: could not locate the requested \"%s\" param.\n",param);
+        ret_val = -1;
+    }
+
+    return(ret_val);
+}
+
+static int os_find_parm_val(void *info_ptr, const char *param, void *val)
+{
+    int ret_val = 0;
+
+    if(psp_config_get_param_string(info_ptr, param, val) == -1)
+    {
+        dbgPrint("Error: could not locate the requested \"%s\" param.\n",param);
+        ret_val = -1;
+    }
+
+    return(ret_val);
+}
+
+static int os_find_device(int unit, const char *find_name, void *device_info)
+{
+    int ret_val = 0;
+
+    if(psp_config_get((char *)find_name, unit, device_info) == -1)
+    {
+        dbgPrint("Error: could not locate the requested \"%s\" param.\n", find_name);
+        ret_val = -1;
+    }
+
+    return(ret_val);
+}
+
+/*---------------------------------------------------------------------------
+ * Memory related OS abstraction.
+ *--------------------------------------------------------------------------*/
+void os_free(void *mem_ptr)
+{
+    kfree(mem_ptr);
+}
+
+void  os_free_buffer(OS_RECEIVEINFO *osReceiveInfo, void *mem_ptr)
+{
+    dev_kfree_skb_any(osReceiveInfo);
+}
+
+void  os_free_dev(void *mem_ptr)
+{
+    kfree(mem_ptr);
+}
+
+void os_free_dma_xfer(void *mem_ptr)
+{
+    kfree(mem_ptr);
+}
+
+static void *os_malloc(unsigned int size)
+{
+    return(kmalloc(size, GFP_KERNEL));
+}
+
+static void *os_malloc_dma_xfer(unsigned int size, 
+                                void         *mem_base, 
+                                unsigned int mem_range)
+{
+    return(kmalloc(size, GFP_KERNEL));
+}
+
+static void *os_malloc_dev(unsigned int size)
+{
+    return(kmalloc(size, GFP_KERNEL));
+}
+
+
+/*----------------------------------------------------------------------------
+ * CRITICAL SECTION ENABLING/DISABLING.
+ *--------------------------------------------------------------------------*/
+static void os_critical_on(void)
+{
+    save_and_cli(irq_flags);
+}
+
+static void os_critical_off(void)
+{
+    restore_flags(irq_flags);
+}
+
+/*----------------------------------------------------------------------------
+ * Cache related abstraction
+ *--------------------------------------------------------------------------*/
+static void os_cache_invalidate(void *mem_ptr, int size)
+{
+    dma_cache_inv((unsigned long)mem_ptr, size);
+}
+
+static void os_cache_writeback(void *mem_ptr, int size)
+{
+    dma_cache_wback_inv((unsigned long)mem_ptr, size);
+}
+
+/*-----------------------------------------------------------------------------
+ * Support functions.
+ *---------------------------------------------------------------------------*/
+
+static void  hal_drv_unregister_isr(OS_DEVICE *p_dev, int intr)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv   = p_dev->priv;
+    CPMAC_ISR_INFO_T     *p_isr_cb_param = &p_cpmac_priv->cpmac_isr;
+    intr                                 = LNXINTNUM(intr);
+
+    free_irq(p_isr_cb_param->intr, p_isr_cb_param);
+
+    dbgPrint("cpmac_hal_unregister called for the intr %d for unit %x and isr_cb_param %x.\n", 
+             intr, p_cpmac_priv->instance_num, (unsigned int )&p_cpmac_priv->cpmac_isr);
+}
+
+
+static void hal_drv_register_isr(OS_DEVICE *p_dev, 
+                                 CPMAC_HAL_ISR_FUNC_T hal_isr, int intr)
+{
+    CPMAC_PRIVATE_INFO_T *p_cpmac_priv   = p_dev->priv;
+    CPMAC_DRV_HAL_INFO_T *p_drv_hal      = p_cpmac_priv->drv_hal;
+    CPMAC_ISR_INFO_T     *p_isr_cb_param = &p_cpmac_priv->cpmac_isr;
+    intr                                 = LNXINTNUM(intr);
+       
+    dbgPrint("osRegister called for the intr %d for device %x and p_isr_cb_param %x.\n", 
+             intr, (bit32u)p_dev, (bit32u)p_isr_cb_param);
+
+    p_isr_cb_param->owner       = p_drv_hal;
+    p_isr_cb_param->hal_isr     = hal_isr;
+    p_isr_cb_param->intr        = intr;
+
+    tasklet_init(&p_isr_cb_param->tasklet, cpmac_handle_tasklet, (unsigned long)p_isr_cb_param);
+    dbgPrint("Success in registering irq %d for Cpmac unit# %d.\n", intr, p_cpmac_priv->instance_num); 
+}
+
+/*---------------------------------------------------------------------------
+ * FUNCTIONS called by the CPMAC Net Device.
+ *-------------------------------------------------------------------------*/
+static int load_os_funcs(OS_FUNCTIONS *os_func)
+{
+    dbgPrint("os_init_module: Start\n"); 
+    if( os_func == 0 )
+    {
+        return(sizeof(OS_FUNCTIONS));   
+    }
+
+    os_func->Control                    = cpmac_hal_control;
+    os_func->CriticalOn                 = os_critical_on;
+    os_func->CriticalOff                = os_critical_off;
+    os_func->DataCacheHitInvalidate     = os_cache_invalidate;
+    os_func->DataCacheHitWriteback      = os_cache_writeback;       
+    os_func->DeviceFindInfo     = os_find_device;
+    os_func->DeviceFindParmUint = os_find_parm_u_int;
+    os_func->DeviceFindParmValue= os_find_parm_val;
+    os_func->Free               = os_free;
+    os_func->FreeRxBuffer       = os_free_buffer;
+    os_func->FreeDev            = os_free_dev;
+    os_func->FreeDmaXfer        = os_free_dma_xfer;
+    os_func->IsrRegister        = hal_drv_register_isr;
+    os_func->IsrUnRegister      = hal_drv_unregister_isr;
+    os_func->Malloc             = os_malloc;
+    os_func->MallocDev          = os_malloc_dev;
+    os_func->MallocDmaXfer      = os_malloc_dma_xfer;
+    os_func->MallocRxBuffer     = cpmac_hal_malloc_buffer;
+    os_func->Memset             = memset;
+    os_func->Printf             = printk;
+    os_func->Receive            = cpmac_hal_receive;
+    os_func->SendComplete       = cpmac_hal_send_complete;
+    os_func->Strcmpi            = cpmac_ci_strcmp;
+    os_func->TeardownComplete   = cpmac_hal_tear_down_complete;
+    os_func->Strstr             = strstr;
+    os_func->Strtoul            = simple_strtol;
+    os_func->Sprintf            = sprintf;
+    os_func->Strlen             = strlen;
+
+    dbgPrint("os_init_module: Leave\n");             
+  
+    return(0);
+}
+
+
+int cpmac_drv_init(CPMAC_DRV_HAL_INFO_T *p_drv_hal)
+{
+    HAL_DEVICE       *p_hal_dev    = p_drv_hal->hal_dev;
+    HAL_FUNCTIONS    *p_hal_funcs  = p_drv_hal->hal_funcs;
+
+    return(p_hal_funcs->Init(p_hal_dev));
+}
+
+int cpmac_drv_cleanup(CPMAC_DRV_HAL_INFO_T *p_drv_hal)
+{
+    HAL_DEVICE       *p_hal_dev    = p_drv_hal->hal_dev;
+    HAL_FUNCTIONS    *p_hal_funcs  = p_drv_hal->hal_funcs;
+
+    int              ret_val       = p_hal_funcs->Shutdown(p_hal_dev);
+
+#if 0
+    if(ret_val == 0)
+        kfree(p_hal_funcs);
+    else
+        ret_val = -1;
+#endif
+
+    kfree(p_drv_hal->os_funcs); 
+    
+    return (ret_val); 
+}
+
+int cpmac_drv_tx_setup(HAL_FUNCTIONS        *p_hal_funcs,
+                       HAL_DEVICE           *p_hal_dev,
+                       CPMAC_TX_CHAN_INFO_T *p_tx_chan_info)
+{
+    int ret_val = 0;
+    int count   = 0;
+    CHANNEL_INFO chan_info;
+
+    /* Let's setup the TX Channels. */
+    for(count=0; count < p_tx_chan_info->cfg_chan; count++)
+    {
+        chan_info.Channel        = count;
+        chan_info.Direction      = DIRECTION_TX;       
+        chan_info.TxNumBuffers   = p_tx_chan_info->chan[count].num_BD;
+        chan_info.TxServiceMax   = p_tx_chan_info->chan[count].service_max;
+        chan_info.TxNumQueues    = 0;
+        
+        if((ret_val = p_hal_funcs->ChannelSetup(p_hal_dev, &chan_info,
+                                                NULL)) != 0)
+        {
+            errPrint("Error in opening channel %d for TX.\n", count);
+            ret_val = -1;
+            break;
+        }
+
+        p_tx_chan_info->opened_chan++;
+    }
+
+    return(ret_val);
+}
+
+int cpmac_drv_rx_setup(HAL_FUNCTIONS         *p_hal_funcs,
+                       HAL_DEVICE            *p_hal_dev,
+                       CPMAC_RX_CHAN_INFO_T  *p_rx_chan_info)
+{
+    int ret_val = 0;
+    CHANNEL_INFO chan_info;
+
+    chan_info.Channel       = 0;
+    chan_info.Direction     = DIRECTION_RX;
+    chan_info.RxBufSize     = p_rx_chan_info->chan[0].buffer_size;
+    chan_info.RxBufferOffset= p_rx_chan_info->chan[0].buffer_offset;
+    chan_info.RxNumBuffers  = p_rx_chan_info->chan[0].num_BD;
+    chan_info.RxServiceMax  = p_rx_chan_info->chan[0].service_max;
+
+    if(p_hal_funcs->ChannelSetup(p_hal_dev, &chan_info, p_rx_chan_info) != 0) 
+    {
+        errPrint("Error in opening channel %d for RX.\n", 0);
+        ret_val = -1;
+    }
+
+    return(ret_val);
+}
+
+int cpmac_drv_start(CPMAC_DRV_HAL_INFO_T *p_drv_hal,
+                    CPMAC_TX_CHAN_INFO_T *p_tx_chan_info,
+                    CPMAC_RX_CHAN_INFO_T *p_rx_chan_info,
+                    unsigned int         flags)
+{
+    int ret_val = 0;
+    HAL_FUNCTIONS *p_hal_funcs = p_drv_hal->hal_funcs;
+    HAL_DEVICE    *p_hal_dev   = p_drv_hal->hal_dev;
+
+    dbgPrint("It is in cpmac_drv_start for %x.\n", (unsigned int)p_drv_hal);
+
+    if(flags & CHAN_SETUP)
+    {
+        if(cpmac_drv_tx_setup(p_hal_funcs, p_hal_dev, 
+                  p_tx_chan_info)!=0)
+        {
+            errPrint("Failed to set up tx channel(s).\n");
+            ret_val = -1;
+        }
+        else if(cpmac_drv_rx_setup(p_hal_funcs, p_hal_dev,
+                                   p_rx_chan_info)!=0)
+        {
+            errPrint("Failed to set up rx channel.\n");
+            ret_val = -1;
+        }
+        else
+        {
+            ret_val = 0;
+        }
+    }
+
+    /* Error in setting up the Channels, quit. */
+    if((ret_val == 0) && (ret_val = p_hal_funcs->Open(p_hal_dev)) != 0)
+    {
+        errPrint("failed to open the HAL!!!.\n");
+        ret_val = -1;
+    }
+
+    return (ret_val);
+} /* cpmac_drv_start */
+
+
+
+int cpmac_drv_tx_teardown(HAL_FUNCTIONS        *p_hal_funcs,
+                          HAL_DEVICE           *p_hal_dev,
+                          CPMAC_TX_CHAN_INFO_T *p_tx_chan_info,
+                          unsigned int         flags)
+{
+    int ret_val = 0;
+    int count   = 0;
+
+    /* Let's setup the TX Channels. */
+    for(;  p_tx_chan_info->opened_chan > 0; 
+        p_tx_chan_info->opened_chan--, count++)
+    {
+        if(p_hal_funcs->ChannelTeardown(p_hal_dev, count, flags) != 0)
+        {
+            errPrint("Error in tearing down channel %d for TX.\n", count);
+            ret_val = -1;
+            break;
+        }
+    }
+
+    return(ret_val);
+}
+
+
+int cpmac_drv_rx_teardown(HAL_FUNCTIONS *p_hal_funcs,
+                  HAL_DEVICE    *p_hal_dev,
+              unsigned int  flags)
+{
+    int ret_val = 0;
+
+    if(p_hal_funcs->ChannelTeardown(p_hal_dev, 0, flags) != 0) 
+    {
+        errPrint("Error in tearing down channel %d for RX.\n", 0);
+        ret_val = -1;
+    }
+
+    return(ret_val);
+}
+
+int cpmac_drv_stop(CPMAC_DRV_HAL_INFO_T    *p_drv_hal,
+                   CPMAC_TX_CHAN_INFO_T    *p_tx_chan_info,
+                   CPMAC_RX_CHAN_INFO_T    *p_rx_chan_info,
+                   unsigned int flags)
+{
+    HAL_DEVICE       *p_hal_dev    = p_drv_hal->hal_dev;
+    HAL_FUNCTIONS    *p_hal_funcs  = p_drv_hal->hal_funcs;
+    int ret_val                    = 0;
+
+    if(flags & CHAN_TEARDOWN)
+    {
+        unsigned int chan_flags = 0;
+
+        if(flags & FREE_BUFFER) chan_flags |= 0x4; /* full tear down */
+        if(flags & BLOCKING)    chan_flags |= 0x8; /* blocking call  */
+
+        dbgPrint("The teardown flags are %d.\n", flags);
+        dbgPrint("The teardown chan flags are %d.\n", chan_flags);
+
+        if(cpmac_drv_tx_teardown(p_hal_funcs, p_hal_dev, 
+                                 p_tx_chan_info, chan_flags | 0x1) != 0)
+        {
+            ret_val = -1;
+            errPrint("The tx channel teardown failed.\n");
+        }
+        else if(cpmac_drv_rx_teardown(p_hal_funcs, p_hal_dev, chan_flags | 0x2) != 0)
+        {
+            ret_val = -1;
+            errPrint("The rx channel teardown failed.\n");
+        }
+        else
+        {
+            ;
+        }
+    }
+
+    if(ret_val == 0)
+    {
+        int close_flags = 1;
+
+        if(flags & FREE_BUFFER)  close_flags = 2;
+//        if(flags & COMPLETE)     close_flags = 3;
+
+        if(p_hal_funcs->Close(p_hal_dev, close_flags) != 0)
+        {
+            ret_val = -1;
+        }
+    }
+        
+    return(ret_val);
+}
+
+int cpmac_drv_init_module(CPMAC_DRV_HAL_INFO_T *p_drv_hal, OS_DEVICE *p_os_dev, int inst)
+{
+    int ret_val = -1;
+    int hal_func_size;
+
+    dbgPrint("Entering the CpmacInitModule for the inst %d \n", inst);
+
+    if((p_drv_hal->os_funcs = kmalloc(sizeof(OS_FUNCTIONS), GFP_KERNEL)) == NULL)
+    {
+        errPrint("Failed to allocate memory for OS_FUNCTIONS.\n");
+    }
+    else if(load_os_funcs(p_drv_hal->os_funcs) != 0)
+    {
+        errPrint("Failed to load OS funcs.\n");
+        os_free(p_drv_hal->os_funcs);
+    }
+    else if(halCpmacInitModule(&p_drv_hal->hal_dev, p_os_dev,
+                               &p_drv_hal->hal_funcs, p_drv_hal->os_funcs, 
+                               sizeof(*p_drv_hal->os_funcs),
+                               &hal_func_size, inst) != 0)
+    {
+        errPrint("halCpmacInitModule failed for inst %d \n", inst);
+        os_free(p_drv_hal->os_funcs);
+    }
+    else if(p_drv_hal->hal_funcs->Probe(p_drv_hal->hal_dev) != 0)
+    {
+        errPrint("halCpmacProbe failed for inst %d \n", inst);       
+        os_free(p_drv_hal->os_funcs);
+    }
+    else
+    {
+        /* every thing went well. */
+        ret_val = 0;
+    }  
+
+    return (ret_val);  
+}
diff -urN linux.old/drivers/net/avalanche_cpmac/cpmacHalLx.h linux.dev/drivers/net/avalanche_cpmac/cpmacHalLx.h
--- linux.old/drivers/net/avalanche_cpmac/cpmacHalLx.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpmacHalLx.h	2005-07-12 02:48:42.044593000 +0200
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * FILE PURPOSE:    CPMAC Linux Device Driver HAL support Header
+ ******************************************************************************
+ * FILE NAME:       cpmacHalVx.h
+ *
+ * DESCRIPTION:     CPMAC Linux Device Driver Header
+ *
+ * REVISION HISTORY:
+ *
+ * Date           Description                               Author
+ *-----------------------------------------------------------------------------
+ * 27 Nov 2002    Initial Creation                          Suraj S Iyer  
+ * 09 Jun 2003    Updates for GA                            Suraj S Iyer
+ * 
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+
+#ifndef __CPMAC_HAL_LX_H
+#define __CPMAC_HAL_LX_H
+
+
+typedef struct net_device         OS_DEVICE;
+typedef struct sk_buff            OS_RECEIVEINFO;
+typedef struct sk_buff            OS_SENDINFO;
+
+#ifdef DEBUG
+typedef void                      HAL_RECEIVEINFO;
+typedef void                      HAL_DEVICE;
+typedef void                      OS_SETUP;
+#endif
+
+#define OS_SETUP   void
+#define HAL_DEVICE void
+#define HAL_RECEIVEINFO void
+
+#define _CPHAL_CPMAC
+ 
+#include "cpswhal_cpmac.h"
+#include "cpmac.h"
+
+int cpmac_drv_start(CPMAC_DRV_HAL_INFO_T *, CPMAC_TX_CHAN_INFO_T*,
+                    CPMAC_RX_CHAN_INFO_T *, unsigned int);
+int cpmac_drv_cleanup(CPMAC_DRV_HAL_INFO_T *);
+int cpmac_drv_init(CPMAC_DRV_HAL_INFO_T*);
+int cpmac_drv_close(CPMAC_DRV_HAL_INFO_T*);
+int cpmac_drv_open(CPMAC_DRV_HAL_INFO_T*);
+int cpmac_drv_init_module(CPMAC_DRV_HAL_INFO_T*, OS_DEVICE*, int);
+int cpmac_drv_stop(CPMAC_DRV_HAL_INFO_T *p_drv_hal,CPMAC_TX_CHAN_INFO_T *p_tx_chan_info,
+                   CPMAC_RX_CHAN_INFO_T *p_rx_chan_info,unsigned int flags);
+
+#endif
diff -urN linux.old/drivers/net/avalanche_cpmac/cpmac_reg.h linux.dev/drivers/net/avalanche_cpmac/cpmac_reg.h
--- linux.old/drivers/net/avalanche_cpmac/cpmac_reg.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpmac_reg.h	2005-07-12 02:48:42.045593000 +0200
@@ -0,0 +1,406 @@
+/****************************************************************************
+        TNETD73xx Software Support
+        Copyright(c) 2000, Texas Instruments Incorporated. All Rights Reserved.
+
+        FILE: cpmac_reg.h   Register definitions for the CPMAC module
+
+         DESCRIPTION:
+                This include file contains register definitions for the
+                CPMAC module.
+
+         HISTORY:
+              15Nov00 BEGR Original version written
+              30May02 MICK Added bits for Int Vector
+              19Sep02 MICK Added INT_ACK per Channel
+              08Nov02 GDUN Updated to use base
+              12Nov02 MICK Incorporated into CPHAL 
+*****************************************************************************/
+#ifndef _INC_CPMAC_REG
+#define _INC_CPMAC_REG
+
+#ifndef MEM_PTR
+#define MEM_PTR volatile bit32u *
+#endif
+
+/***************************************************************************
+ *                                                                         
+ *         C P M A C  M E M O R Y  M A P 
+ *                                                                         
+ **************************************************************************/
+
+#define pCPMAC_TX_IDVER(base)                 ((MEM_PTR)(base+0x000))
+#define  CPMAC_TX_IDVER(base)                 (*pCPMAC_TX_IDVER(base))
+#define pCPMAC_TX_CONTROL(base)               ((MEM_PTR)(base+0x004))
+#define  CPMAC_TX_CONTROL(base)               (*pCPMAC_TX_CONTROL(base))
+#define pCPMAC_TX_TEARDOWN(base)              ((MEM_PTR)(base+0x008))
+#define  CPMAC_TX_TEARDOWN(base)              (*pCPMAC_TX_TEARDOWN(base))
+#define pCPMAC_RX_IDVER(base)                 ((MEM_PTR)(base+0x010))
+#define  CPMAC_RX_IDVER(base)                 (*pCPMAC_RX_IDVER(base))
+#define pCPMAC_RX_CONTROL(base)               ((MEM_PTR)(base+0x014))
+#define  CPMAC_RX_CONTROL(base)               (*pCPMAC_RX_CONTROL(base))
+#define pCPMAC_RX_TEARDOWN(base)              ((MEM_PTR)(base+0x018))
+#define  CPMAC_RX_TEARDOWN(base)              (*pCPMAC_RX_TEARDOWN(base))
+#define pCPMAC_RX_MBP_ENABLE(base)            ((MEM_PTR)(base+0x100))
+#define  CPMAC_RX_MBP_ENABLE(base)            (*pCPMAC_RX_MBP_ENABLE(base))
+#define pCPMAC_RX_UNICAST_SET(base)           ((MEM_PTR)(base+0x104))
+#define  CPMAC_RX_UNICAST_SET(base)           (*pCPMAC_RX_UNICAST_SET(base))
+#define pCPMAC_RX_UNICAST_CLEAR(base)         ((MEM_PTR)(base+0x108))
+#define  CPMAC_RX_UNICAST_CLEAR(base)         (*pCPMAC_RX_UNICAST_CLEAR(base))
+#define pCPMAC_RX_MAXLEN(base)                ((MEM_PTR)(base+0x10C))
+#define  CPMAC_RX_MAXLEN(base)                (*pCPMAC_RX_MAXLEN(base))
+#define pCPMAC_RX_BUFFER_OFFSET(base)         ((MEM_PTR)(base+0x110))
+#define  CPMAC_RX_BUFFER_OFFSET(base)         (*pCPMAC_RX_BUFFER_OFFSET(base))
+#define pCPMAC_RX_FILTERLOWTHRESH(base)       ((MEM_PTR)(base+0x114))
+#define  CPMAC_RX_FILTERLOWTHRESH(base)       (*pCPMAC_RX_FILTERLOWTHRESH(base))
+#define pCPMAC_RX0_FLOWTHRESH(base)           ((MEM_PTR)(base+0x120))
+#define  CPMAC_RX0_FLOWTHRESH(base)           (*pCPMAC_RX0_FLOWTHRESH(base))
+#define pCPMAC_RX1_FLOWTHRESH(base)           ((MEM_PTR)(base+0x124))
+#define  CPMAC_RX1_FLOWTHRESH(base)           (*pCPMAC_RX1_FLOWTHRESH(base))
+#define pCPMAC_RX2_FLOWTHRESH(base)           ((MEM_PTR)(base+0x128))
+#define  CPMAC_RX2_FLOWTHRESH(base)           (*pCPMAC_RX2_FLOWTHRESH(base))
+#define pCPMAC_RX3_FLOWTHRESH(base)           ((MEM_PTR)(base+0x12C))
+#define  CPMAC_RX3_FLOWTHRESH(base)           (*pCPMAC_RX3_FLOWTHRESH(base))
+#define pCPMAC_RX4_FLOWTHRESH(base)           ((MEM_PTR)(base+0x130))
+#define  CPMAC_RX4_FLOWTHRESH(base)           (*pCPMAC_RX4_FLOWTHRESH(base))
+#define pCPMAC_RX5_FLOWTHRESH(base)           ((MEM_PTR)(base+0x134))
+#define  CPMAC_RX5_FLOWTHRESH(base)           (*pCPMAC_RX5_FLOWTHRESH(base))
+#define pCPMAC_RX6_FLOWTHRESH(base)           ((MEM_PTR)(base+0x138))
+#define  CPMAC_RX6_FLOWTHRESH(base)           (*pCPMAC_RX6_FLOWTHRESH(base))
+#define pCPMAC_RX7_FLOWTHRESH(base)           ((MEM_PTR)(base+0x13C))
+#define  CPMAC_RX7_FLOWTHRESH(base)           (*pCPMAC_RX7_FLOWTHRESH(base))
+#define pCPMAC_RX0_FREEBUFFER(base)           ((MEM_PTR)(base+0x140))
+#define  CPMAC_RX0_FREEBUFFER(base)           (*pCPMAC_RX0_FREEBUFFER(base))
+#define pCPMAC_RX1_FREEBUFFER(base)           ((MEM_PTR)(base+0x144))
+#define  CPMAC_RX1_FREEBUFFER(base)           (*pCPMAC_RX1_FREEBUFFER(base))
+#define pCPMAC_RX2_FREEBUFFER(base)           ((MEM_PTR)(base+0x148))
+#define  CPMAC_RX2_FREEBUFFER(base)           (*pCPMAC_RX2_FREEBUFFER(base))
+#define pCPMAC_RX3_FREEBUFFER(base)           ((MEM_PTR)(base+0x14C))
+#define  CPMAC_RX3_FREEBUFFER(base)           (*pCPMAC_RX3_FREEBUFFER(base))
+#define pCPMAC_RX4_FREEBUFFER(base)           ((MEM_PTR)(base+0x150))
+#define  CPMAC_RX4_FREEBUFFER(base)           (*pCPMAC_RX4_FREEBUFFER(base))
+#define pCPMAC_RX5_FREEBUFFER(base)           ((MEM_PTR)(base+0x154))
+#define  CPMAC_RX5_FREEBUFFER(base)           (*pCPMAC_RX5_FREEBUFFER(base))
+#define pCPMAC_RX6_FREEBUFFER(base)           ((MEM_PTR)(base+0x158))
+#define  CPMAC_RX6_FREEBUFFER(base)           (*pCPMAC_RX6_FREEBUFFER(base))
+#define pCPMAC_RX7_FREEBUFFER(base)           ((MEM_PTR)(base+0x15C))
+#define  CPMAC_RX7_FREEBUFFER(base)           (*pCPMAC_RX7_FREEBUFFER(base))
+#define pCPMAC_MACCONTROL(base)               ((MEM_PTR)(base+0x160))
+#define  CPMAC_MACCONTROL(base)               (*pCPMAC_MACCONTROL(base))
+#define pCPMAC_MACSTATUS(base)                ((MEM_PTR)(base+0x164))
+#define  CPMAC_MACSTATUS(base)                (*pCPMAC_MACSTATUS(base))
+#define pCPMAC_EMCONTROL(base)                ((MEM_PTR)(base+0x168))
+#define  CPMAC_EMCONTROL(base)                (*pCPMAC_EMCONTROL(base))
+#define pCPMAC_TX_INTSTAT_RAW(base)           ((MEM_PTR)(base+0x170))
+#define  CPMAC_TX_INTSTAT_RAW(base)           (*pCPMAC_TX_INTSTAT_RAW(base))
+#define pCPMAC_TX_INTSTAT_MASKED(base)        ((MEM_PTR)(base+0x174))
+#define  CPMAC_TX_INTSTAT_MASKED(base)        (*pCPMAC_TX_INTSTAT_MASKED(base))
+#define pCPMAC_TX_INTMASK_SET(base)           ((MEM_PTR)(base+0x178))
+#define  CPMAC_TX_INTMASK_SET(base)           (*pCPMAC_TX_INTMASK_SET(base))
+#define pCPMAC_TX_INTMASK_CLEAR(base)         ((MEM_PTR)(base+0x17C))
+#define  CPMAC_TX_INTMASK_CLEAR(base)         (*pCPMAC_TX_INTMASK_CLEAR(base))
+#define pCPMAC_MAC_IN_VECTOR(base)            ((MEM_PTR)(base+0x180))
+#define  CPMAC_MAC_IN_VECTOR(base)            (*pCPMAC_MAC_IN_VECTOR(base))
+#define pCPMAC_MAC_EOI_VECTOR(base)           ((MEM_PTR)(base+0x184))
+#define  CPMAC_MAC_EOI_VECTOR(base)           (*pCPMAC_MAC_EOI_VECTOR(base))
+#define pCPMAC_RX_INTSTAT_RAW(base)           ((MEM_PTR)(base+0x190))
+#define  CPMAC_RX_INTSTAT_RAW(base)           (*pCPMAC_RX_INTSTAT_RAW(base))
+#define pCPMAC_RX_INTSTAT_MASKED(base)        ((MEM_PTR)(base+0x194))
+#define  CPMAC_RX_INTSTAT_MASKED(base)        (*pCPMAC_RX_INTSTAT_MASKED(base))
+#define pCPMAC_RX_INTMASK_SET(base)           ((MEM_PTR)(base+0x198))
+#define  CPMAC_RX_INTMASK_SET(base)           (*pCPMAC_RX_INTMASK_SET(base))
+#define pCPMAC_RX_INTMASK_CLEAR(base)         ((MEM_PTR)(base+0x19C))
+#define  CPMAC_RX_INTMASK_CLEAR(base)         (*pCPMAC_RX_INTMASK_CLEAR(base))
+#define pCPMAC_MAC_INTSTAT_RAW(base)          ((MEM_PTR)(base+0x1A0))
+#define  CPMAC_MAC_INTSTAT_RAW(base)          (*pCPMAC_MAC_INTSTAT_RAW(base))
+#define pCPMAC_MAC_INTSTAT_MASKED(base)       ((MEM_PTR)(base+0x1A4))
+#define  CPMAC_MAC_INTSTAT_MASKED(base)       (*pCPMAC_MAC_INTSTAT_MASKED(base))
+#define pCPMAC_MAC_INTMASK_SET(base)          ((MEM_PTR)(base+0x1A8))
+#define  CPMAC_MAC_INTMASK_SET(base)          (*pCPMAC_MAC_INTMASK_SET(base))
+#define pCPMAC_MAC_INTMASK_CLEAR(base)        ((MEM_PTR)(base+0x1AC))
+#define  CPMAC_MAC_INTMASK_CLEAR(base)        (*pCPMAC_MAC_INTMASK_CLEAR(base))
+#define pCPMAC_MACADDRLO_0(base)              ((MEM_PTR)(base+0x1B0))
+#define  CPMAC_MACADDRLO_0(base)              (*pCPMAC_MACADDRLO_0(base))
+#define pCPMAC_MACADDRLO_1(base)              ((MEM_PTR)(base+0x1B4))
+#define  CPMAC_MACADDRLO_1(base)              (*pCPMAC_MACADDRLO_1(base))
+#define pCPMAC_MACADDRLO_2(base)              ((MEM_PTR)(base+0x1B8))
+#define  CPMAC_MACADDRLO_2(base)              (*pCPMAC_MACADDRLO_2(base))
+#define pCPMAC_MACADDRLO_3(base)              ((MEM_PTR)(base+0x1BC))
+#define  CPMAC_MACADDRLO_3(base)              (*pCPMAC_MACADDRLO_3(base))
+#define pCPMAC_MACADDRLO_4(base)              ((MEM_PTR)(base+0x1C0))
+#define  CPMAC_MACADDRLO_4(base)              (*pCPMAC_MACADDRLO_4(base))
+#define pCPMAC_MACADDRLO_5(base)              ((MEM_PTR)(base+0x1C4))
+#define  CPMAC_MACADDRLO_5(base)              (*pCPMAC_MACADDRLO_5(base))
+#define pCPMAC_MACADDRLO_6(base)              ((MEM_PTR)(base+0x1C8))
+#define  CPMAC_MACADDRLO_6(base)              (*pCPMAC_MACADDRLO_6(base))
+#define pCPMAC_MACADDRLO_7(base)              ((MEM_PTR)(base+0x1CC))
+#define  CPMAC_MACADDRLO_7(base)              (*pCPMAC_MACADDRLO_7(base))
+#define pCPMAC_MACADDRMID(base)               ((MEM_PTR)(base+0x1D0))
+#define  CPMAC_MACADDRMID(base)               (*pCPMAC_MACADDRMID(base))
+#define pCPMAC_MACADDRHI(base)                ((MEM_PTR)(base+0x1D4))
+#define  CPMAC_MACADDRHI(base)                (*pCPMAC_MACADDRHI(base))
+#define pCPMAC_MACHASH1(base)                 ((MEM_PTR)(base+0x1D8))
+#define  CPMAC_MACHASH1(base)                 (*pCPMAC_MACHASH1(base))
+#define pCPMAC_MACHASH2(base)                 ((MEM_PTR)(base+0x1DC))
+#define  CPMAC_MACHASH2(base)                 (*pCPMAC_MACHASH2(base))
+#define pCPMAC_BOFFTEST(base)                 ((MEM_PTR)(base+0x1E0))
+#define  CPMAC_BOFFTEST(base)                 (*pCPMAC_BOFFTEST(base))
+#define pCPMAC_PACTEST(base)                  ((MEM_PTR)(base+0x1E4))
+#define  CPMAC_PACTEST(base)                  (*pCPMAC_PACTEST(base))
+#define pCPMAC_RXPAUSE(base)                  ((MEM_PTR)(base+0x1E8))
+#define  CPMAC_RXPAUSE(base)                  (*pCPMAC_RXPAUSE(base))
+#define pCPMAC_TXPAUSE(base)                  ((MEM_PTR)(base+0x1EC))
+#define  CPMAC_TXPAUSE(base)                  (*pCPMAC_TXPAUSE(base))
+/* STATISTICS */
+#define pCPMAC_RXGOODFRAMES(base)             ((MEM_PTR)(base+0x200))
+#define  CPMAC_RXGOODFRAMES(base)             (*pCPMAC_RXGOODFRAMES(base))
+#define pCPMAC_RXBROADCASTFRAMES(base)        ((MEM_PTR)(base+0x204))
+#define  CPMAC_RXBROADCASTFRAMES(base)        (*pCPMAC_RXBROADCASTFRAMES(base))
+#define pCPMAC_RXMULTICASTFRAMES(base)        ((MEM_PTR)(base+0x208))
+#define  CPMAC_RXMULTICASTFRAMES(base)        (*pCPMAC_RXMULTICASTFRAMES(base))
+#define pCPMAC_RXPAUSEFRAMES(base)            ((MEM_PTR)(base+0x20C))
+#define   CPMAC_RXPAUSEFRAMES(base)           (*pCPMAC_RXPAUSEFRAMES(base))
+#define pCPMAC_RXCRCERRORS(base)              ((MEM_PTR)(base+0x210))
+#define   CPMAC_RXCRCERRORS(base)             (*pCPMAC_RXCRCERRORS(base))
+#define pCPMAC_RXALIGNCODEERRORS(base)        ((MEM_PTR)(base+0x214))
+#define   CPMAC_RXALIGNCODEERRORS(base)       (*pCPMAC_RXALIGNCODEERRORS(base))
+#define pCPMAC_RXOVERSIZEDFRAMES(base)        ((MEM_PTR)(base+0x218))
+#define   CPMAC_RXOVERSIZEDFRAMES(base)       (*pCPMAC_RXOVERSIZEDFRAMES(base))
+#define pCPMAC_RXJABBERFRAMES(base)           ((MEM_PTR)(base+0x21C))
+#define  CPMAC_RXJABBERFRAMES(base)           (*pCPMAC_RXJABBERFRAMES(base))
+#define pCPMAC_RXUNDERSIZEDFRAMES(base)       ((MEM_PTR)(base+0x220))
+#define  CPMAC_RXUNDERSIZEDFRAMES(base)       (*pCPMAC_RXUNDERSIZEDFRAMES(base))
+#define pCPMAC_RXFRAGMENTS(base)              ((MEM_PTR)(base+0x224))
+#define  CPMAC_RXFRAGMENTS(base)              (*pCPMAC_RXFRAGMENTS(base))
+#define pCPMAC_RXFILTEREDFRAMES(base)         ((MEM_PTR)(base+0x228))
+#define  CPMAC_RXFILTEREDFRAMES(base)         (*pCPMAC_RXFILTEREDFRAMES(base))
+#define pCPMAC_RXQOSFILTEREDFRAMES(base)      ((MEM_PTR)(base+0x22C))
+#define  CPMAC_RXQOSFILTEREDFRAMES(base)      (*pCPMAC_RXQOSFILTEREDFRAMES(base))
+#define pCPMAC_RXOCTETS(base)                 ((MEM_PTR)(base+0x230))
+#define  CPMAC_RXOCTETS(base)                 (*pCPMAC_RXOCTETS(base))
+#define pCPMAC_TXGOODFRAMES(base)             ((MEM_PTR)(base+0x234))
+#define  CPMAC_TXGOODFRAMES(base)             (*pCPMAC_TXGOODFRAMES(base))
+#define pCPMAC_TXBROADCASTFRAMES(base)        ((MEM_PTR)(base+0x238))
+#define  CPMAC_TXBROADCASTFRAMES(base)        (*pCPMAC_TXBROADCASTFRAMES(base))
+#define pCPMAC_TXMULTICASTFRAMES(base)        ((MEM_PTR)(base+0x23C))
+#define  CPMAC_TXMULTICASTFRAMES(base)        (*pCPMAC_TXMULTICASTFRAMES(base))
+#define pCPMAC_TXPAUSEFRAMES(base)            ((MEM_PTR)(base+0x240))
+#define  CPMAC_TXPAUSEFRAMES(base)            (*pCPMAC_TXPAUSEFRAMES(base))
+#define pCPMAC_TXDEFERREDFRAMES(base)         ((MEM_PTR)(base+0x244))
+#define  CPMAC_TXDEFERREDFRAMES(base)         (*pCPMAC_TXDEFERREDFRAMES(base))
+#define pCPMAC_TXCOLLISIONFRAMES(base)        ((MEM_PTR)(base+0x248))
+#define  CPMAC_TXCOLLISIONFRAMES(base)        (*pCPMAC_TXCOLLISIONFRAMES(base))
+#define pCPMAC_TXSINGLECOLLFRAMES(base)       ((MEM_PTR)(base+0x24C))
+#define  CPMAC_TXSINGLECOLLFRAMES(base)       (*pCPMAC_TXSINGLECOLLFRAMES(base))
+#define pCPMAC_TXMULTCOLLFRAMES(base)         ((MEM_PTR)(base+0x250))
+#define  CPMAC_TXMULTCOLLFRAMES(base)         (*pCPMAC_TXMULTCOLLFRAMES(base))
+#define pCPMAC_TXEXCESSIVECOLLISIONS(base)    ((MEM_PTR)(base+0x254))
+#define  CPMAC_TXEXCESSIVECOLLISIONS(base)    (*pCPMAC_TXEXCESSIVECOLLISIONS(base))
+#define pCPMAC_TXLATECOLLISIONS(base)         ((MEM_PTR)(base+0x258))
+#define  CPMAC_TXLATECOLLISIONS(base)         (*pCPMAC_TXLATECOLLISIONS(base))
+#define pCPMAC_TXUNDERRUN(base)               ((MEM_PTR)(base+0x25C))
+#define  CPMAC_TXUNDERRUN(base)               (*pCPMAC_TXUNDERRUN(base))
+#define pCPMAC_TXCARRIERSENSEERRORS(base)     ((MEM_PTR)(base+0x260))
+#define  CPMAC_TXCARRIERSENSEERRORS(base)     (*pCPMAC_TXCARRIERSENSEERRORS(base))
+#define pCPMAC_TXOCTETS(base)                 ((MEM_PTR)(base+0x264))
+#define  CPMAC_TXOCTETS(base)                 (*pCPMAC_TXOCTETS(base))
+#define pCPMAC_64OCTETFRAMES(base)            ((MEM_PTR)(base+0x268))
+#define  CPMAC_64OCTETFRAMES(base)            (*pCPMAC_64OCTETFRAMES(base))
+#define pCPMAC_65T127OCTETFRAMES(base)        ((MEM_PTR)(base+0x26C))
+#define  CPMAC_65T127OCTETFRAMES(base)        (*pCPMAC_65T127OCTETFRAMES(base))
+#define pCPMAC_128T255OCTETFRAMES(base)       ((MEM_PTR)(base+0x270))
+#define  CPMAC_128T255OCTETFRAMES(base)       (*pCPMAC_128T255OCTETFRAMES(base))
+#define pCPMAC_256T511OCTETFRAMES(base)       ((MEM_PTR)(base+0x274))
+#define  CPMAC_256T511OCTETFRAMES(base)       (*pCPMAC_256T511OCTETFRAMES(base))
+#define pCPMAC_512T1023OCTETFRAMES(base)      ((MEM_PTR)(base+0x278))
+#define  CPMAC_512T1023OCTETFRAMES(base)      (*pCPMAC_512T1023OCTETFRAMES(base))
+#define pCPMAC_1024TUPOCTETFRAMES(base)       ((MEM_PTR)(base+0x27C))
+#define  CPMAC_1024TUPOCTETFRAMES(base)       (*pCPMAC_1024TUPOCTETFRAMES(base))
+#define pCPMAC_NETOCTETS(base)                ((MEM_PTR)(base+0x280))
+#define  CPMAC_NETOCTETS(base)                (*pCPMAC_NETOCTETS(base))
+#define pCPMAC_RXSOFOVERRUNS(base)            ((MEM_PTR)(base+0x284))
+#define  CPMAC_RXSOFOVERRUNS(base)            (*pCPMAC_RXSOFOVERRUNS(base))
+#define pCPMAC_RXMOFOVERRUNS(base)            ((MEM_PTR)(base+0x288))
+#define  CPMAC_RXMOFOVERRUNS(base)            (*pCPMAC_RXMOFOVERRUNS(base))
+#define pCPMAC_RXDMAOVERRUNS(base)            ((MEM_PTR)(base+0x28C))
+#define  CPMAC_RXDMAOVERRUNS(base)            (*pCPMAC_RXDMAOVERRUNS(base))
+
+#define  CPMAC_TX_HDP(base,ch)                (*(MEM_PTR)(base+0x600+(4*ch)))
+#define pCPMAC_TX0_HDP(base)                  ((MEM_PTR)(base+0x600))
+#define  CPMAC_TX0_HDP(base)                  (*pCPMAC_TX0_HDP(base))
+#define pCPMAC_TX1_HDP(base)                  ((MEM_PTR)(base+0x604))
+#define  CPMAC_TX1_HDP(base)                  (*pCPMAC_TX1_HDP(base))
+#define pCPMAC_TX2_HDP(base)                  ((MEM_PTR)(base+0x608))
+#define  CPMAC_TX2_HDP(base)                  (*pCPMAC_TX2_HDP(base))
+#define pCPMAC_TX3_HDP(base)                  ((MEM_PTR)(base+0x60C))
+#define  CPMAC_TX3_HDP(base)                  (*pCPMAC_TX3_HDP(base))
+#define pCPMAC_TX4_HDP(base)                  ((MEM_PTR)(base+0x610))
+#define  CPMAC_TX4_HDP(base)                  (*pCPMAC_TX4_HDP(base))
+#define pCPMAC_TX5_HDP(base)                  ((MEM_PTR)(base+0x614))
+#define  CPMAC_TX5_HDP(base)                  (*pCPMAC_TX5_HDP(base))
+#define pCPMAC_TX6_HDP(base)                  ((MEM_PTR)(base+0x618))
+#define  CPMAC_TX6_HDP(base)                  (*pCPMAC_TX6_HDP(base))
+#define pCPMAC_TX7_HDP(base)                  ((MEM_PTR)(base+0x61C))
+#define  CPMAC_TX7_HDP(base)                  (*pCPMAC_TX7_HDP(base))
+#define  CPMAC_RX_HDP(base,ch)                (*(MEM_PTR)(base+0x620+(4*ch)))
+#define pCPMAC_RX0_HDP(base)                  ((MEM_PTR)(base+0x620))
+#define  CPMAC_RX0_HDP(base)                  (*pCPMAC_RX0_HDP(base))
+#define pCPMAC_RX1_HDP(base)                  ((MEM_PTR)(base+0x624))
+#define  CPMAC_RX1_HDP(base)                  (*pCPMAC_RX1_HDP(base))
+#define pCPMAC_RX2_HDP(base)                  ((MEM_PTR)(base+0x628))
+#define  CPMAC_RX2_HDP(base)                  (*pCPMAC_RX2_HDP(base))
+#define pCPMAC_RX3_HDP(base)                  ((MEM_PTR)(base+0x62C))
+#define  CPMAC_RX3_HDP(base)                  (*pCPMAC_RX3_HDP(base))
+#define pCPMAC_RX4_HDP(base)                  ((MEM_PTR)(base+0x630))
+#define  CPMAC_RX4_HDP(base)                  (*pCPMAC_RX4_HDP(base))
+#define pCPMAC_RX5_HDP(base)                  ((MEM_PTR)(base+0x634))
+#define  CPMAC_RX5_HDP(base)                  (*pCPMAC_RX5_HDP(base))
+#define pCPMAC_RX6_HDP(base)                  ((MEM_PTR)(base+0x638))
+#define  CPMAC_RX6_HDP(base)                  (*pCPMAC_RX6_HDP(base))
+#define pCPMAC_RX7_HDP(base)                  ((MEM_PTR)(base+0x63C))
+#define  CPMAC_RX7_HDP(base)                  (*pCPMAC_RX7_HDP(base))
+
+
+#define CPMAC_TX_INT_ACK(base,ch)             (*(MEM_PTR)(base+0x640+(4*ch)))
+
+#define pCPMAC_TX0_INT_ACK(base)              ((MEM_PTR)(base+0x640))
+#define  CPMAC_TX0_INT_ACK(base)              (*pCPMAC_TX0_INT_ACK(base))
+#define pCPMAC_TX1_INT_ACK(base)              ((MEM_PTR)(base+0x644))
+#define  CPMAC_TX1_INT_ACK(base)              (*pCPMAC_TX1_INT_ACK(base))
+#define pCPMAC_TX2_INT_ACK(base)              ((MEM_PTR)(base+0x648))
+#define  CPMAC_TX2_INT_ACK(base)              (*pCPMAC_TX2_INT_ACK(base))
+#define pCPMAC_TX3_INT_ACK(base)              ((MEM_PTR)(base+0x64C))
+#define  CPMAC_TX3_INT_ACK(base)              (*pCPMAC_TX3_INT_ACK(base))
+#define pCPMAC_TX4_INT_ACK(base)              ((MEM_PTR)(base+0x650))
+#define  CPMAC_TX4_INT_ACK(base)              (*pCPMAC_TX4_INT_ACK(base))
+#define pCPMAC_TX5_INT_ACK(base)              ((MEM_PTR)(base+0x654))
+#define  CPMAC_TX5_INT_ACK(base)              (*pCPMAC_TX5_INT_ACK(base))
+#define pCPMAC_TX6_INT_ACK(base)              ((MEM_PTR)(base+0x658))
+#define  CPMAC_TX6_INT_ACK(base)              (*pCPMAC_TX6_INT_ACK(base))
+#define pCPMAC_TX7_INT_ACK(base)              ((MEM_PTR)(base+0x65C))
+#define  CPMAC_TX7_INT_ACK(base)              (*pCPMAC_TX7_INT_ACK(base))
+#define CPMAC_RX_INT_ACK(base,ch)             (*(MEM_PTR)(base+0x660+(4*ch)))
+         
+#define pCPMAC_RX0_INT_ACK(base)              ((MEM_PTR)(base+0x660))
+#define  CPMAC_RX0_INT_ACK(base)              (*pCPMAC_RX0_INT_ACK(base))
+#define pCPMAC_RX1_INT_ACK(base)              ((MEM_PTR)(base+0x664))
+#define  CPMAC_RX1_INT_ACK(base)              (*pCPMAC_RX1_INT_ACK(base))
+#define pCPMAC_RX2_INT_ACK(base)              ((MEM_PTR)(base+0x668))
+#define  CPMAC_RX2_INT_ACK(base)              (*pCPMAC_RX2_INT_ACK(base))
+#define pCPMAC_RX3_INT_ACK(base)              ((MEM_PTR)(base+0x66C))
+#define  CPMAC_RX3_INT_ACK(base)              (*pCPMAC_RX3_INT_ACK(base))
+#define pCPMAC_RX4_INT_ACK(base)              ((MEM_PTR)(base+0x670))
+#define  CPMAC_RX4_INT_ACK(base)              (*pCPMAC_RX4_INT_ACK(base))
+#define pCPMAC_RX5_INT_ACK(base)              ((MEM_PTR)(base+0x674))
+#define  CPMAC_RX5_INT_ACK(base)              (*pCPMAC_RX5_INT_ACK(base))
+#define pCPMAC_RX6_INT_ACK(base)              ((MEM_PTR)(base+0x678))
+#define  CPMAC_RX6_INT_ACK(base)              (*pCPMAC_RX6_INT_ACK(base))
+#define pCPMAC_RX7_INT_ACK(base)              ((MEM_PTR)(base+0x67C))
+#define  CPMAC_RX7_INT_ACK(base)              (*pCPMAC_RX7_INT_ACK(base))
+
+/****************************************************************************/
+/*                                                                          */
+/*         R E G I S T E R  B I T  D E F I N I T I O N S                    */
+/*                                                                          */
+/****************************************************************************/
+
+/* TX_CONTROL */
+
+#define TX_EN               (1 << 0)
+
+/* RX_CONTROL */
+
+#define RX_EN               (1 << 0)
+
+/* RX_MBP_ENABLE */
+
+#define RX_PASS_CRC         (1 << 30)
+#define RX_QOS_EN           (1 << 29)
+#define RX_NO_CHAIN         (1 << 28)
+
+#define RX_CMF_EN           (1 << 24)
+#define RX_CSF_EN           (1 << 23)
+#define RX_CEF_EN           (1 << 22)
+#define RX_CAF_EN           (1 << 21)
+
+#define RX_PROM_CH(n)       (n << 16)
+#define RX_PROM_CH_MASK     RX_PROM_CH(7)
+#define RX_PROM_CH_7        RX_PROM_CH(7)
+#define RX_PROM_CH_6        RX_PROM_CH(6)
+#define RX_PROM_CH_5        RX_PROM_CH(5)
+#define RX_PROM_CH_4        RX_PROM_CH(4)
+#define RX_PROM_CH_3        RX_PROM_CH(3)
+#define RX_PROM_CH_2        RX_PROM_CH(2)
+#define RX_PROM_CH_1        RX_PROM_CH(1)
+#define RX_PROM_CH_0        RX_PROM_CH(0)
+
+#define RX_BROAD_EN         (1 << 13)
+
+#define RX_BROAD_CH(n)       (n <<  8)
+#define RX_BROAD_CH_MASK     RX_BROAD_CH(7)
+#define RX_BROAD_CH_7        RX_BROAD_CH(7)
+#define RX_BROAD_CH_6        RX_BROAD_CH(6)
+#define RX_BROAD_CH_5        RX_BROAD_CH(5)
+#define RX_BROAD_CH_4        RX_BROAD_CH(4)
+#define RX_BROAD_CH_3        RX_BROAD_CH(3)
+#define RX_BROAD_CH_2        RX_BROAD_CH(2)
+#define RX_BROAD_CH_1        RX_BROAD_CH(1)
+#define RX_BROAD_CH_0        RX_BROAD_CH(0)
+
+#define RX_MULT_EN          (1 <<  5)
+
+#define RX_MULT_CH(n)       (n << 0)
+#define RX_MULT_CH_MASK     RX_MULT_CH(7)
+#define RX_MULT_CH_7        RX_MULT_CH(7)
+#define RX_MULT_CH_6        RX_MULT_CH(6)
+#define RX_MULT_CH_5        RX_MULT_CH(5)
+#define RX_MULT_CH_4        RX_MULT_CH(4)
+#define RX_MULT_CH_3        RX_MULT_CH(3)
+#define RX_MULT_CH_2        RX_MULT_CH(2)
+#define RX_MULT_CH_1        RX_MULT_CH(1)
+#define RX_MULT_CH_0        RX_MULT_CH(0)
+
+
+
+/* RX_UNICAST_SET */
+
+#define RX_CH7_EN        (1 <<  7)
+#define RX_CH6_EN        (1 <<  6)
+#define RX_CH5_EN        (1 <<  5)
+#define RX_CH4_EN        (1 <<  4)
+#define RX_CH3_EN        (1 <<  3)
+#define RX_CH2_EN        (1 <<  2)
+#define RX_CH1_EN        (1 <<  1)
+#define RX_CH0_EN        (1 <<  0)
+
+
+
+/*  MAC control */
+#define TX_PTYPE         (1 << 9)
+#define TX_PACE          (1 << 6)
+#define MII_EN           (1 << 5)
+#define TX_FLOW_EN       (1 << 4)
+#define RX_FLOW_EN       (1 << 3)
+#define MTEST            (1 << 2)
+#define CTRL_LOOPBACK    (1 << 1)
+#define FULLDUPLEX       (1 << 0)
+
+
+/* IntVec definitions  */
+#define MAC_IN_VECTOR_STATUS_INT   (1 << 19)
+#define MAC_IN_VECTOR_HOST_INT     (1 << 18)
+#define MAC_IN_VECTOR_RX_INT_OR    (1 << 17)
+#define MAC_IN_VECTOR_TX_INT_OR    (1 << 16)
+#define MAC_IN_VECTOR_RX_INT_VEC   (7 << 8)
+#define MAC_IN_VECTOR_TX_INT_VEC   (7)  
+
+
+/*  MacStatus */
+
+#define TX_HOST_ERR_CODE         (0xF << 20)
+#define TX_ERR_CH                (0x7 << 16)
+#define RX_HOST_ERR_CODE         (0xF << 12)
+#define RX_ERR_CH                (0x7 <<  8)
+#define RX_QOS_ACT               (1 << 2)
+#define RX_FLOW_ACT              (1 << 1)
+#define TX_FLOW_ACT              (1 << 0)
+#endif _INC_CPMAC_REG
diff -urN linux.old/drivers/net/avalanche_cpmac/cpmdio.c linux.dev/drivers/net/avalanche_cpmac/cpmdio.c
--- linux.old/drivers/net/avalanche_cpmac/cpmdio.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpmdio.c	2005-07-12 02:48:42.046593000 +0200
@@ -0,0 +1,960 @@
+/***************************************************************************
+**  TNETD53xx Software Support
+**  Copyright(c) 2002, Texas Instruments Incorporated. All Rights Reserved.
+**
+**  FILE: cpmdio.c
+**
+**  DESCRIPTION:
+**   MDIO Polling State Machine API. Functions will enable mii-Phy
+**   negotiation.
+**
+**  HISTORY:
+**    01Jan01 Denis, Bill      Original
+**      27Mar02 Michael Hanrahan (modified from emacmdio.c)
+**      07May02 Michael Hanrahan replaced clockwait for code delay
+**      10Jul02 Michael Hanrahan more debug, if fallback link is selected
+*****************************************************************************/
+#define __CPHAL_CPMDIO
+
+#include "mdio_reg.h"
+
+#ifdef _CPHAL_CPMAC
+#define mdioPrintf PhyDev->HalDev->OsFunc->Printf
+#else
+#define mdioPrintf printf
+#endif
+
+typedef struct _phy_device
+{
+   bit32u miibase;
+   bit32u inst;
+   bit32u PhyState;
+   bit32u MdixMask;
+   bit32u PhyMask;
+   bit32u MLinkMask;
+   bit32u PhyMode;
+#ifdef _CPHAL_CPMAC
+   HAL_DEVICE *HalDev;
+#endif
+} _PHY_DEVICE;
+
+static void   _mdioDelayEmulate(PHY_DEVICE *PhyDev, int ClockWait);
+static void   _mdioWaitForAccessComplete(PHY_DEVICE *PhyDev);
+static void   _mdioUserAccess(PHY_DEVICE *PhyDev, bit32u method, bit32u regadr, bit32u phyadr, bit32u data);
+static bit32u _mdioUserAccessRead(PHY_DEVICE *PhyDev, bit32u regadr, bit32u phyadr);
+static void   _mdioUserAccessWrite(PHY_DEVICE *PhyDev, bit32u regadr, bit32u phyadr, bit32u data);
+
+static void _mdioDisablePhy(PHY_DEVICE *PhyDev,bit32u PhyNum);
+static void _mdioPhyTimeOut(PHY_DEVICE *PhyDev);
+static void _mdioResetPhy(PHY_DEVICE *PhyDev,bit32u PhyNum);
+
+static void _mdioDumpPhy(PHY_DEVICE *PhyDev, bit32u p);
+static void _mdioDumpState(PHY_DEVICE *PhyDev);
+
+/* Auto Mdix */
+static void _mdioMdixDelay(PHY_DEVICE *PhyDev);
+static int  _mdioMdixSupported(PHY_DEVICE *PhyDev);
+
+static void _MdioDefaultState  (PHY_DEVICE *PhyDev);
+static void _MdioFindingState  (PHY_DEVICE *PhyDev);
+static void _MdioFoundState    (PHY_DEVICE *PhyDev);
+static void _MdioInitState     (PHY_DEVICE *PhyDev);
+static void _MdioLinkedState   (PHY_DEVICE *PhyDev);
+static void _MdioLinkWaitState (PHY_DEVICE *PhyDev);
+static void _MdioLoopbackState (PHY_DEVICE *PhyDev);
+static void _MdioNwayStartState(PHY_DEVICE *PhyDev);
+static void _MdioNwayWaitState (PHY_DEVICE *PhyDev);
+
+
+
+#ifndef TRUE
+#define TRUE (1==1)
+#endif
+
+#ifndef FALSE
+#define FALSE (1==2)
+#endif
+
+#define PHY_NOT_FOUND  0xFFFF    /*  Used in Phy Detection */
+
+/*PhyState breakout                                                          */
+
+#define PHY_DEV_OFFSET      (0)
+#define PHY_DEV_SIZE        (5)        /*  5 Bits used */
+#define PHY_DEV_MASK        (0x1f<<PHY_DEV_OFFSET)
+
+#define PHY_STATE_OFFSET    (PHY_DEV_SIZE+PHY_DEV_OFFSET)
+#define PHY_STATE_SIZE      (5)        /* 10 Bits used */
+#define PHY_STATE_MASK      (0x1f<<PHY_STATE_OFFSET)
+  #define INIT       (1<<PHY_STATE_OFFSET)
+  #define FINDING    (2<<PHY_STATE_OFFSET)
+  #define FOUND      (3<<PHY_STATE_OFFSET)
+  #define NWAY_START (4<<PHY_STATE_OFFSET)
+  #define NWAY_WAIT  (5<<PHY_STATE_OFFSET)
+  #define LINK_WAIT  (6<<PHY_STATE_OFFSET)
+  #define LINKED     (7<<PHY_STATE_OFFSET)
+  #define LOOPBACK   (8<<PHY_STATE_OFFSET)
+
+#define PHY_SPEED_OFFSET    (PHY_STATE_OFFSET+PHY_STATE_SIZE)
+#define PHY_SPEED_SIZE      (1)     /* 11 Bits used */
+#define PHY_SPEED_MASK      (1<<PHY_SPEED_OFFSET)
+
+#define PHY_DUPLEX_OFFSET   (PHY_SPEED_OFFSET+PHY_SPEED_SIZE)
+#define PHY_DUPLEX_SIZE     (1)     /* 12 Bits used */
+#define PHY_DUPLEX_MASK     (1<<PHY_DUPLEX_OFFSET)
+
+#define PHY_TIM_OFFSET      (PHY_DUPLEX_OFFSET+PHY_DUPLEX_SIZE)
+#define PHY_TIM_SIZE        (10)    /* 22 Bits used */
+#define PHY_TIM_MASK        (0x3ff<<PHY_TIM_OFFSET)
+  #define PHY_FIND_TO (  2<<PHY_TIM_OFFSET)
+  #define PHY_RECK_TO (200<<PHY_TIM_OFFSET)
+  #define PHY_LINK_TO (500<<PHY_TIM_OFFSET)
+  #define PHY_NWST_TO (500<<PHY_TIM_OFFSET)
+  #define PHY_NWDN_TO (800<<PHY_TIM_OFFSET)
+  #define PHY_MDIX_TO (274<<PHY_TIM_OFFSET) /* 2.74 Seconds <--Spec and empirical */
+
+#define PHY_SMODE_OFFSET    (PHY_TIM_OFFSET+PHY_TIM_SIZE)
+#define PHY_SMODE_SIZE      (5)     /* 27 Bits used */
+#define PHY_SMODE_MASK      (0x1f<<PHY_SMODE_OFFSET)
+  #define SMODE_AUTO   (0x10<<PHY_SMODE_OFFSET)
+  #define SMODE_FD100  (0x08<<PHY_SMODE_OFFSET)
+  #define SMODE_HD100  (0x04<<PHY_SMODE_OFFSET)
+  #define SMODE_FD10   (0x02<<PHY_SMODE_OFFSET)
+  #define SMODE_HD10   (0x01<<PHY_SMODE_OFFSET)
+  #define SMODE_ALL    (0x1f<<PHY_SMODE_OFFSET)
+
+#define PHY_CHNG_OFFSET    (PHY_SMODE_OFFSET+PHY_SMODE_SIZE)
+#define PHY_CHNG_SIZE      (1)     /* 28 Bits used */
+#define PHY_CHNG_MASK      (1<<PHY_CHNG_OFFSET)
+  #define PHY_CHANGE (1<<PHY_CHNG_OFFSET)
+
+#define PHY_TIMEDOUT_OFFSET    (PHY_CHNG_OFFSET+PHY_CHNG_SIZE)
+#define PHY_TIMEDOUT_SIZE      (1)     /*  29 Bits used */
+#define PHY_TIMEDOUT_MASK      (1<<PHY_TIMEDOUT_OFFSET)
+  #define PHY_MDIX_SWITCH  (1<<PHY_TIMEDOUT_OFFSET)
+
+#define PHY_MDIX_OFFSET    (PHY_TIMEDOUT_OFFSET+PHY_TIMEDOUT_SIZE)
+#define PHY_MDIX_SIZE      (1)     /*  30 Bits used */
+#define PHY_MDIX_MASK      (1<<PHY_MDIX_OFFSET)
+  #define PHY_MDIX     (1<<PHY_MDIX_OFFSET)
+
+static char *lstate[]={"NULL","INIT","FINDING","FOUND","NWAY_START","NWAY_WAIT","LINK_WAIT","LINKED", "LOOPBACK"};
+static int cpMacDebug;
+
+/*  Local MDIO Register Macros    */
+
+#define myMDIO_ALIVE           MDIO_ALIVE     (PhyDev->miibase)
+#define myMDIO_CONTROL         MDIO_CONTROL   (PhyDev->miibase)
+#define myMDIO_LINK            MDIO_LINK      (PhyDev->miibase)
+#define myMDIO_LINKINT         MDIO_LINKINT   (PhyDev->miibase)
+#define myMDIO_USERACCESS      MDIO_USERACCESS(PhyDev->miibase, PhyDev->inst)
+#define myMDIO_USERPHYSEL      MDIO_USERPHYSEL(PhyDev->miibase, PhyDev->inst)
+#define myMDIO_VER             MDIO_VER       (PhyDev->miibase)
+
+#ifndef VOLATILE32
+#define VOLATILE32(addr) (*((volatile bit32u *)(addr)))
+#endif
+
+/************************************
+***
+*** Delays at least ClockWait cylces
+*** before returning
+***
+**************************************/
+void _mdioDelayEmulate(PHY_DEVICE *PhyDev, int ClockWait)
+  {
+#ifdef _CPHAL_CPMAC                                                  /*+RC3.02*/
+  HAL_DEVICE *HalDev = PhyDev->HalDev;                               /*+RC3.02*/
+  osfuncSleep((int*)&ClockWait);                                     /*+RC3.02*/
+#else                                                                /*+RC3.02*/
+  volatile bit32u i=0;
+  while(ClockWait--)
+    {
+    i |= myMDIO_LINK; /*  MDIO register access to burn cycles */
+    }
+#endif
+  }
+
+void _mdioWaitForAccessComplete(PHY_DEVICE *PhyDev)
+  {
+  while((myMDIO_USERACCESS & MDIO_USERACCESS_GO)!=0)
+    {
+    }
+  }
+
+void _mdioUserAccess(PHY_DEVICE *PhyDev, bit32u method, bit32u regadr, bit32u phyadr, bit32u data)
+  {
+  bit32u  control;
+
+  control =  MDIO_USERACCESS_GO |
+             (method) |
+             (((regadr) << 21) & MDIO_USERACCESS_REGADR) |
+             (((phyadr) << 16) & MDIO_USERACCESS_PHYADR) |
+             ((data) & MDIO_USERACCESS_DATA);
+
+  myMDIO_USERACCESS = control;
+  }
+
+
+
+/************************************
+***
+*** Waits for MDIO_USERACCESS to be ready and reads data
+*** If 'WaitForData' set, waits for read to complete and returns Data,
+*** otherwise returns 0
+*** Note: 'data' is 16 bits but we use 32 bits
+***        to be consistent with rest of the code.
+***
+**************************************/
+bit32u _mdioUserAccessRead(PHY_DEVICE *PhyDev, bit32u regadr, bit32u phyadr)
+  {
+
+  _mdioWaitForAccessComplete(PhyDev);  /* Wait until UserAccess ready */
+  _mdioUserAccess(PhyDev, MDIO_USERACCESS_READ, regadr, phyadr, 0);
+  _mdioWaitForAccessComplete(PhyDev);  /* Wait for Read to complete */
+
+  return(myMDIO_USERACCESS & MDIO_USERACCESS_DATA);
+  }
+
+
+/************************************
+***
+*** Waits for MDIO_USERACCESS to be ready and writes data
+***
+**************************************/
+void _mdioUserAccessWrite(PHY_DEVICE *PhyDev, bit32u regadr, bit32u phyadr, bit32u data)
+  {
+  _mdioWaitForAccessComplete(PhyDev);  /* Wait until UserAccess ready */
+  _mdioUserAccess(PhyDev, MDIO_USERACCESS_WRITE, regadr, phyadr, data);
+  }
+
+void _mdioDumpPhyDetailed(PHY_DEVICE *PhyDev)
+{
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u  PhyNum;
+  int     RegData;
+
+  PhyNum=(*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET;
+
+  RegData = _mdioUserAccessRead(PhyDev, 0, PhyNum);
+  mdioPrintf("PhyControl: %04X, Lookback=%s, Speed=%s, Duplex=%s\n",
+    RegData,
+    RegData&PHY_LOOP?"On":"Off",
+    RegData&PHY_100?"100":"10",
+    RegData&PHY_FD?"Full":"Half");
+  RegData = _mdioUserAccessRead(PhyDev, 1, PhyNum);
+  mdioPrintf("PhyStatus: %04X, AutoNeg=%s, Link=%s\n",
+    RegData,
+    RegData&NWAY_COMPLETE?"Complete":"NotComplete",
+    RegData&PHY_LINKED?"Up":"Down");
+  RegData = _mdioUserAccessRead(PhyDev, 4, PhyNum);
+  mdioPrintf("PhyMyCapability: %04X, 100FD=%s, 100HD=%s, 10FD=%s, 10HD=%s\n",
+    RegData,
+    RegData&NWAY_FD100?"Yes":"No",
+    RegData&NWAY_HD100?"Yes":"No",
+    RegData&NWAY_FD10?"Yes":"No",
+    RegData&NWAY_HD10?"Yes":"No");
+
+  RegData = _mdioUserAccessRead(PhyDev, 5, PhyNum);
+  mdioPrintf("PhyPartnerCapability: %04X, 100FD=%s, 100HD=%s, 10FD=%s, 10HD=%s\n",
+    RegData,
+    RegData&NWAY_FD100?"Yes":"No",
+    RegData&NWAY_HD100?"Yes":"No",
+    RegData&NWAY_FD10?"Yes":"No",
+    RegData&NWAY_HD10?"Yes":"No");
+}
+void _mdioDumpPhy(PHY_DEVICE *PhyDev, bit32u p)
+  {
+  bit32u j,n,PhyAcks;
+  bit32u PhyRegAddr;
+  bit32u phy_num;
+  bit32u PhyMask  = PhyDev->PhyMask;
+
+  PhyAcks=myMDIO_ALIVE;
+  PhyAcks&=PhyMask;   /* Only interested in 'our' Phys */
+
+  for(phy_num=0,j=1;phy_num<32;phy_num++,j<<=1)
+    {
+    if (PhyAcks&j)
+      {
+      mdioPrintf("%2d%s:",phy_num,(phy_num==p)?">":" ");
+      for(PhyRegAddr=0;PhyRegAddr<6;PhyRegAddr++)
+        {
+        n = _mdioUserAccessRead(PhyDev, PhyRegAddr, phy_num);
+        mdioPrintf(" %04x",n&0x0ffff);
+        }
+      mdioPrintf("\n");
+      }
+    }
+  _mdioDumpPhyDetailed(PhyDev);
+  }
+
+void _mdioDumpState(PHY_DEVICE *PhyDev)
+  {
+  bit32u state    = PhyDev->PhyState;
+
+  if (!cpMacDebug) return;
+
+  mdioPrintf("Phy: %d, ",(state&PHY_DEV_MASK)>>PHY_DEV_OFFSET);
+  mdioPrintf("State: %d/%s, ",(state&PHY_STATE_MASK)>>PHY_STATE_OFFSET,lstate[(state&PHY_STATE_MASK)>>PHY_STATE_OFFSET]);
+  mdioPrintf("Speed: %d, ",(state&PHY_SPEED_MASK)>>PHY_SPEED_OFFSET);
+  mdioPrintf("Dup: %d, ",(state&PHY_DUPLEX_MASK)>>PHY_DUPLEX_OFFSET);
+  mdioPrintf("Tim: %d, ",(state&PHY_TIM_MASK)>>PHY_TIM_OFFSET);
+  mdioPrintf("SMode: %d, ",(state&PHY_SMODE_MASK)>>PHY_SMODE_OFFSET);
+  mdioPrintf("Chng: %d",(state&PHY_CHNG_MASK)>>PHY_CHNG_OFFSET);
+  mdioPrintf("\n");
+
+  if (((state&PHY_STATE_MASK)!=FINDING)&&((state&PHY_STATE_MASK)!=INIT))
+    _mdioDumpPhy(PhyDev, (state&PHY_DEV_MASK)>>PHY_DEV_OFFSET);
+  }
+
+
+void _mdioResetPhy(PHY_DEVICE *PhyDev,bit32u PhyNum)
+  {
+  bit16u PhyControlReg;
+
+  _mdioUserAccessWrite(PhyDev, PHY_CONTROL_REG, PhyNum, PHY_RESET);
+  if (cpMacDebug)
+    mdioPrintf("cpMacMdioPhYReset(%d)\n",PhyNum);
+
+  /* Read control register until Phy Reset is complete */
+  do
+   {
+    PhyControlReg = _mdioUserAccessRead(PhyDev, PHY_CONTROL_REG, PhyNum);
+   }
+   while (PhyControlReg & PHY_RESET); /* Wait for Reset to clear */
+  }
+
+void _mdioDisablePhy(PHY_DEVICE *PhyDev,bit32u PhyNum)
+  {
+  _mdioUserAccessWrite(PhyDev, PHY_CONTROL_REG, PhyNum, PHY_ISOLATE|PHY_PDOWN);
+
+  if (cpMacDebug)
+    mdioPrintf("cpMacMdioDisablePhy(%d)\n",PhyNum);
+
+  }
+
+void _MdioInitState(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u CurrentState;
+
+  CurrentState=*PhyState;
+  CurrentState=(CurrentState&~PHY_TIM_MASK)|(PHY_FIND_TO);
+  CurrentState=(CurrentState&~PHY_STATE_MASK)|(FINDING);
+  CurrentState=(CurrentState&~PHY_SPEED_MASK);
+  CurrentState=(CurrentState&~PHY_DUPLEX_MASK);
+  CurrentState|=PHY_CHANGE;
+
+  *PhyState=CurrentState;
+
+  }
+
+void _MdioFindingState(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u  PhyMask  = PhyDev->PhyMask;
+  bit32u  PhyNum,i,j,PhyAcks;
+
+
+  PhyNum=PHY_NOT_FOUND;
+
+  if (*PhyState&PHY_TIM_MASK)
+    {
+    *PhyState=(*PhyState&~PHY_TIM_MASK)|((*PhyState&PHY_TIM_MASK)-(1<<PHY_TIM_OFFSET));
+    }
+   else
+    {
+    PhyAcks=myMDIO_ALIVE;
+    PhyAcks&=PhyMask;   /* Only interested in 'our' Phys */
+
+    for(i=0,j=1;(i<32)&&((j&PhyAcks)==0);i++,j<<=1);
+
+    if ((PhyAcks)&&(i<32)) PhyNum=i;
+    if (PhyNum!=PHY_NOT_FOUND)
+      {
+      /*  Phy Found! */
+      *PhyState=(*PhyState&~PHY_DEV_MASK)|((PhyNum&PHY_DEV_MASK)<<PHY_DEV_OFFSET);
+      *PhyState=(*PhyState&~PHY_STATE_MASK)|(FOUND);
+      *PhyState|=PHY_CHANGE;
+      if (cpMacDebug)
+        mdioPrintf("cpMacMdioFindingState: PhyNum: %d\n",PhyNum);
+      }
+     else
+      {
+      if (cpMacDebug)
+        mdioPrintf("cpMacMdioFindingState: Timed Out looking for a Phy!\n");
+      *PhyState|=PHY_RECK_TO;  /* This state currently has no support?*/
+      }
+    }
+  }
+
+void _MdioFoundState(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState  = &PhyDev->PhyState;
+  bit32u  PhyMask   = PhyDev->PhyMask;
+  bit32u  MLinkMask = PhyDev->MLinkMask;
+  bit32u  PhyNum,PhyStatus,NWAYadvertise,m,phynum,i,j,PhyAcks;
+  bit32u  PhySel;
+
+  if ((*PhyState&PHY_SMODE_MASK)==0) return;
+
+  PhyNum=(*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET;
+
+  PhyAcks=myMDIO_ALIVE;
+  PhyAcks&=PhyMask;   /* Only interested in 'our' Phys */
+
+  /* Will now isolate all our Phys, except the one we have decided to use */
+  for(phynum=0,j=1;phynum<32;phynum++,j<<=1)
+    {
+    if (PhyAcks&j)
+      {
+        if (phynum!=PhyNum)  /* Do not disabled Found Phy */
+          _mdioDisablePhy(PhyDev,phynum);
+      }
+    }
+
+  /*  Reset the Phy and proceed with auto-negotiation */
+  _mdioResetPhy(PhyDev,PhyNum);
+
+  /* Now setup the MDIOUserPhySel register */
+
+  PhySel=PhyNum;  /* Set the phy address */
+
+  /*  Set the way Link will be Monitored */
+  /* Check the Link Selection Method */
+  if ((1 << PhyNum) & MLinkMask)
+    PhySel |= MDIO_USERPHYSEL_LINKSEL;
+
+  myMDIO_USERPHYSEL = PhySel;  /* update PHYSEL */
+
+  /* Get the Phy Status */
+  PhyStatus = _mdioUserAccessRead(PhyDev, PHY_STATUS_REG, PhyNum);
+
+
+#ifdef _CPHAL_CPMAC
+  /*  For Phy Internal loopback test, need to wait until Phy
+      found, then set Loopback */
+  if (PhyDev->HalDev->MdioConnect & _CPMDIO_LOOPBK)
+    {
+    /* Set Phy in Loopback */
+    _mdioUserAccessWrite(PhyDev, PHY_CONTROL_REG, PhyNum, PHY_LOOP|PHY_FD);
+    /* Do a read to ensure PHY_LOOP has completed */
+    _mdioUserAccessRead(PhyDev, PHY_STATUS_REG, PhyNum);
+    *PhyState=(*PhyState&~PHY_STATE_MASK)|(LOOPBACK);
+    *PhyState|=PHY_CHANGE;
+    return;
+    }
+#endif
+
+
+  if (cpMacDebug)
+    mdioPrintf("Enable Phy to negotiate external connection\n");
+
+  NWAYadvertise=NWAY_SEL;
+  if (*PhyState&SMODE_FD100) NWAYadvertise|=NWAY_FD100;
+  if (*PhyState&SMODE_HD100) NWAYadvertise|=NWAY_HD100;
+  if (*PhyState&SMODE_FD10)  NWAYadvertise|=NWAY_FD10;
+  if (*PhyState&SMODE_HD10)  NWAYadvertise|=NWAY_HD10;
+
+  *PhyState&=~(PHY_TIM_MASK|PHY_STATE_MASK);
+  if ((PhyStatus&NWAY_CAPABLE)&&(*PhyState&SMODE_AUTO))   /*NWAY Phy Detected*/
+    {
+    /*For NWAY compliant Phys                                                */
+
+    _mdioUserAccessWrite(PhyDev, NWAY_ADVERTIZE_REG, PhyNum, NWAYadvertise);
+
+    if (cpMacDebug)
+      {
+      mdioPrintf("NWAY Advertising: ");
+      if (NWAYadvertise&NWAY_FD100) mdioPrintf("FullDuplex-100 ");
+      if (NWAYadvertise&NWAY_HD100) mdioPrintf("HalfDuplex-100 ");
+      if (NWAYadvertise&NWAY_FD10)  mdioPrintf("FullDuplex-10 ");
+      if (NWAYadvertise&NWAY_HD10)  mdioPrintf("HalfDuplex-10 ");
+      mdioPrintf("\n");
+      }
+
+    _mdioUserAccessWrite(PhyDev, PHY_CONTROL_REG, PhyNum, AUTO_NEGOTIATE_EN);
+
+    _mdioUserAccessWrite(PhyDev, PHY_CONTROL_REG, PhyNum, AUTO_NEGOTIATE_EN|RENEGOTIATE);
+
+    *PhyState|=PHY_CHANGE|PHY_NWST_TO|NWAY_START;
+    }
+   else
+    {
+    *PhyState&=~SMODE_AUTO;   /*The Phy is not capable of auto negotiation!  */
+    m=NWAYadvertise;
+    for(j=0x8000,i=0;(i<16)&&((j&m)==0);i++,j>>=1);
+    m=j;
+    j=0;
+    if (m&(NWAY_FD100|NWAY_HD100))
+      {
+      j=PHY_100;
+      m&=(NWAY_FD100|NWAY_HD100);
+      }
+    if (m&(NWAY_FD100|NWAY_FD10))
+      j |= PHY_FD;
+    if (cpMacDebug)
+      mdioPrintf("Requested PHY mode %s Duplex %s Mbps\n",(j&PHY_FD)?"Full":"Half",(j&PHY_100)?"100":"10");
+    _mdioUserAccessWrite(PhyDev, PHY_CONTROL_REG, PhyNum, j);
+    *PhyState&=~PHY_SPEED_MASK;
+    if (j&PHY_100)
+      *PhyState|=(1<<PHY_SPEED_OFFSET);
+    *PhyState&=~PHY_DUPLEX_MASK;
+    if (j&PHY_FD)
+      *PhyState|=(1<<PHY_DUPLEX_OFFSET);
+    *PhyState|=PHY_CHANGE|PHY_LINK_TO|LINK_WAIT;
+    }
+     _mdioMdixDelay(PhyDev);  /* If AutoMdix add delay */
+  }
+
+void _MdioNwayStartState(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u PhyNum,PhyMode;
+
+  PhyNum=(*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET;
+
+  /*Wait for Negotiation to start                                            */
+
+  PhyMode=_mdioUserAccessRead(PhyDev, PHY_CONTROL_REG, PhyNum);
+
+  if((PhyMode&RENEGOTIATE)==0)
+    {
+    _mdioUserAccessRead(PhyDev, PHY_STATUS_REG, PhyNum); /*Flush pending latch bits*/
+    *PhyState&=~(PHY_STATE_MASK|PHY_TIM_MASK);
+    *PhyState|=PHY_CHANGE|NWAY_WAIT|PHY_NWDN_TO;
+    _mdioMdixDelay(PhyDev);  /* If AutoMdix add delay */
+    }
+   else
+    {
+    if (*PhyState&PHY_TIM_MASK)
+      *PhyState=(*PhyState&~PHY_TIM_MASK)|((*PhyState&PHY_TIM_MASK)-(1<<PHY_TIM_OFFSET));
+     else
+      _mdioPhyTimeOut(PhyDev);
+    }
+  }
+
+void _MdioNwayWaitState(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u  PhyNum,PhyStatus,NWAYadvertise,NWAYREadvertise,NegMode,i,j;
+
+  PhyNum=(*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET;
+
+  PhyStatus=_mdioUserAccessRead(PhyDev, PHY_STATUS_REG, PhyNum);
+
+  if (PhyStatus&NWAY_COMPLETE)
+    {
+    *PhyState|=PHY_CHANGE;
+    *PhyState&=~PHY_SPEED_MASK;
+    *PhyState&=~PHY_DUPLEX_MASK;
+
+    NWAYadvertise   =_mdioUserAccessRead(PhyDev, NWAY_ADVERTIZE_REG, PhyNum);
+    NWAYREadvertise =_mdioUserAccessRead(PhyDev, NWAY_REMADVERTISE_REG, PhyNum);
+
+    /* Negotiated mode is we and the remote have in common */
+    NegMode = NWAYadvertise & NWAYREadvertise;
+
+    if (cpMacDebug)
+      {
+       mdioPrintf("Phy: %d, ",(*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET);
+       mdioPrintf("NegMode %04X, NWAYadvertise %04X, NWAYREadvertise %04X\n",
+         NegMode,  NWAYadvertise, NWAYREadvertise);
+      }
+
+    /* Limit negotiation to fields below */
+    NegMode &= (NWAY_FD100|NWAY_HD100|NWAY_FD10|NWAY_HD10);
+
+    if (NegMode==0)
+      {
+      NegMode=(NWAY_HD100|NWAY_HD10)&NWAYadvertise; /*or 10 ?? who knows, Phy is not MII compliant*/
+      if(cpMacDebug)
+        {
+         mdioPrintf("Mdio:WARNING: Negotiation complete but NO agreement, default is HD\n");
+         _mdioDumpPhyDetailed(PhyDev);
+        } 
+      }
+    for(j=0x8000,i=0;(i<16)&&((j&NegMode)==0);i++,j>>=1);
+
+
+    NegMode=j;
+    if (cpMacDebug)
+      {
+      mdioPrintf("Negotiated connection: ");
+      if (NegMode&NWAY_FD100) mdioPrintf("FullDuplex 100 Mbs\n");
+      if (NegMode&NWAY_HD100) mdioPrintf("HalfDuplex 100 Mbs\n");
+      if (NegMode&NWAY_FD10) mdioPrintf("FullDuplex 10 Mbs\n");
+      if (NegMode&NWAY_HD10) mdioPrintf("HalfDuplex 10 Mbs\n");
+      }
+    if (NegMode!=0)
+      {
+      if (PhyStatus&PHY_LINKED)
+        *PhyState=(*PhyState&~PHY_STATE_MASK)|LINKED;
+       else
+        *PhyState=(*PhyState&~PHY_STATE_MASK)|LINK_WAIT;
+      if (NegMode&(NWAY_FD100|NWAY_HD100))
+        *PhyState=(*PhyState&~PHY_SPEED_MASK)|(1<<PHY_SPEED_OFFSET);
+      if (NegMode&(NWAY_FD100|NWAY_FD10))
+        *PhyState=(*PhyState&~PHY_DUPLEX_MASK)|(1<<PHY_DUPLEX_OFFSET);
+      }
+    }
+   else
+    {
+    if (*PhyState&PHY_TIM_MASK)
+      *PhyState=(*PhyState&~PHY_TIM_MASK)|((*PhyState&PHY_TIM_MASK)-(1<<PHY_TIM_OFFSET));
+     else
+      _mdioPhyTimeOut(PhyDev);
+    }
+  }
+
+void _MdioLinkWaitState(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u  PhyStatus;
+  bit32u  PhyNum;
+
+  PhyNum=(*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET;
+
+  PhyStatus=_mdioUserAccessRead(PhyDev, PHY_STATUS_REG, PhyNum);
+
+  if (PhyStatus&PHY_LINKED)
+    {
+    *PhyState=(*PhyState&~PHY_STATE_MASK)|LINKED;
+    *PhyState|=PHY_CHANGE;
+    }
+   else
+    {
+    if (*PhyState&PHY_TIM_MASK)
+      *PhyState=(*PhyState&~PHY_TIM_MASK)|((*PhyState&PHY_TIM_MASK)-(1<<PHY_TIM_OFFSET));
+     else
+      _mdioPhyTimeOut(PhyDev);
+    }
+  }
+
+void _mdioPhyTimeOut(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState;
+
+  if(_mdioMdixSupported(PhyDev) == 0)
+    return;  /* AutoMdix not supported */
+
+  PhyState = &PhyDev->PhyState;
+
+  /*  Indicate MDI/MDIX mode switch is needed */
+  *PhyState|=PHY_MDIX_SWITCH;
+
+  /* Toggle the MDIX mode indicatir */
+  if(*PhyState & PHY_MDIX)
+    *PhyState &= ~PHY_MDIX_MASK;       /* Current State is MDIX, set to MDI */
+  else
+    *PhyState |=  PHY_MDIX_MASK;      /* Current State is MDI, set to MDIX */
+
+  /* Reset state machine to FOUND */
+  *PhyState=(*PhyState&~PHY_STATE_MASK)|(FOUND);
+  }
+
+void _MdioLoopbackState(PHY_DEVICE *PhyDev)
+  {
+  return;
+  }
+
+void _MdioLinkedState(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u  PhyNum   = (*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET;
+
+  if (myMDIO_LINK&(1<<PhyNum)) return;  /* if still Linked, exit*/
+
+  /* Not Linked */
+  *PhyState&=~(PHY_STATE_MASK|PHY_TIM_MASK);
+  if (*PhyState&SMODE_AUTO)
+    *PhyState|=PHY_CHANGE|NWAY_WAIT|PHY_NWDN_TO;
+   else
+    *PhyState|=PHY_CHANGE|PHY_LINK_TO|LINK_WAIT;
+    
+  _mdioMdixDelay(PhyDev);  /* If AutoMdix add delay */
+  }
+
+void _MdioDefaultState(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  /*Awaiting a cpMacMdioInit call                                             */
+  *PhyState|=PHY_CHANGE;
+  }
+
+
+/*User Calls*********************************************************       */
+
+void cpMacMdioClose(PHY_DEVICE *PhyDev, int Full)
+  {
+  }
+
+
+int cpMacMdioInit(PHY_DEVICE *PhyDev, bit32u miibase, bit32u inst, bit32u PhyMask, bit32u MLinkMask, bit32u MdixMask, bit32u ResetReg, bit32u ResetBit, bit32u MdioBusFreq, bit32u MdioClockFreq, int verbose, void *Info)
+  {
+  bit32u HighestChannel;
+  bit32u ControlState;
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u clkdiv;                                                  /*MJH+030328*/
+
+  cpMacDebug=verbose;  
+ 
+  PhyDev->miibase   = miibase;
+  PhyDev->inst      = inst;
+  PhyDev->PhyMask   = PhyMask;
+  PhyDev->MLinkMask = MLinkMask;
+  PhyDev->MdixMask  = MdixMask;
+#ifdef _CPHAL_CPMAC
+  PhyDev->HalDev    = (HAL_DEVICE*) Info;
+#endif
+
+  *PhyState &= ~PHY_MDIX_MASK;   /* Set initial State to MDI */
+   
+  /* Check that the channel supplied is within range */
+  HighestChannel = (myMDIO_CONTROL & MDIO_CONTROL_HIGHEST_USER_CHANNEL) > 8;
+  if(inst > HighestChannel)
+    return(HighestChannel);
+
+  /*Setup MII MDIO access regs                                              */
+
+  /* Calculate the correct value for the mclkdiv */
+  /* See PITS #14 */
+  if (MdioClockFreq)                                              /*MJH+030402*/
+     clkdiv = (MdioBusFreq / MdioClockFreq) - 1;                  /*MJH+030402*/
+  else                                                            /*MJH+030402*/
+     clkdiv = 0xFF;                                               /*MJH+030402*/
+
+  ControlState  = MDIO_CONTROL_ENABLE;
+  ControlState |= (clkdiv & MDIO_CONTROL_CLKDIV);                 /*MJH+030328*/
+
+  /*
+      If mii is not out of reset or if the Control Register is not set correctly
+      then initalize
+  */
+  if( !(VOLATILE32(ResetReg) & (1 << ResetBit)) ||
+     ((myMDIO_CONTROL & (MDIO_CONTROL_CLKDIV | MDIO_CONTROL_ENABLE)) != ControlState) )/*GSG~030404*/
+    {
+    /*  MII not setup, Setup initial condition  */
+    VOLATILE32(ResetReg) &= ~(1 << ResetBit);
+    _mdioDelayEmulate(PhyDev, 64);
+    VOLATILE32(ResetReg) |= (1 << ResetBit);  /* take mii out of reset  */
+    _mdioDelayEmulate(PhyDev, 64);
+    myMDIO_CONTROL = ControlState;  /* Enable MDIO   */
+    }
+
+  *PhyState=INIT;
+
+  if (cpMacDebug)
+    mdioPrintf("cpMacMdioInit\n");
+  _mdioDumpState(PhyDev);
+  return(0);
+  }
+
+void cpMacMdioSetPhyMode(PHY_DEVICE *PhyDev,bit32u PhyMode)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u CurrentState;
+
+  PhyDev->PhyMode = PhyMode;   /* used for AUTOMIDX, planned to replace PhyState fields */
+
+  *PhyState&=~PHY_SMODE_MASK;
+
+  if (PhyMode&NWAY_AUTO)  *PhyState|=SMODE_AUTO;
+  if (PhyMode&NWAY_FD100) *PhyState|=SMODE_FD100;
+  if (PhyMode&NWAY_HD100) *PhyState|=SMODE_HD100;
+  if (PhyMode&NWAY_FD10)  *PhyState|=SMODE_FD10;
+  if (PhyMode&NWAY_HD10)  *PhyState|=SMODE_HD10;
+
+  CurrentState=*PhyState&PHY_STATE_MASK;
+  if ((CurrentState==NWAY_START)||
+      (CurrentState==NWAY_WAIT) ||
+      (CurrentState==LINK_WAIT) ||
+      (CurrentState==LINKED)      )
+    *PhyState=(*PhyState&~PHY_STATE_MASK)|FOUND|PHY_CHANGE;
+  if (cpMacDebug)
+    mdioPrintf("cpMacMdioSetPhyMode:%08X Auto:%d, FD10:%d, HD10:%d, FD100:%d, HD100:%d\n", PhyMode,
+     PhyMode&NWAY_AUTO, PhyMode&NWAY_FD10, PhyMode&NWAY_HD10, PhyMode&NWAY_FD100,
+     PhyMode&NWAY_HD100);
+  _mdioDumpState(PhyDev);
+  }
+
+/* cpMacMdioTic is called every 10 mili seconds to process Phy states         */
+
+int cpMacMdioTic(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u  CurrentState;
+
+  /*Act on current state of the Phy                                          */
+
+  CurrentState=*PhyState;
+  switch(CurrentState&PHY_STATE_MASK)
+    {
+    case INIT:       _MdioInitState(PhyDev);      break;
+    case FINDING:    _MdioFindingState(PhyDev);   break;
+    case FOUND:      _MdioFoundState(PhyDev);     break;
+    case NWAY_START: _MdioNwayStartState(PhyDev); break;
+    case NWAY_WAIT:  _MdioNwayWaitState(PhyDev);  break;
+    case LINK_WAIT:  _MdioLinkWaitState(PhyDev);  break;
+    case LINKED:     _MdioLinkedState(PhyDev);    break;
+    case LOOPBACK:   _MdioLoopbackState(PhyDev);  break;
+    default:         _MdioDefaultState(PhyDev);   break;
+    }
+
+  /*Dump state info if a change has been detected                            */
+
+  if ((CurrentState&~PHY_TIM_MASK)!=(*PhyState&~PHY_TIM_MASK))
+    _mdioDumpState(PhyDev);
+
+  /*  Check is MDI/MDIX mode switch is needed */
+  if(*PhyState & PHY_MDIX_SWITCH)
+    {
+    bit32u Mdix;
+
+    *PhyState &= ~PHY_MDIX_SWITCH;  /* Clear Mdix Flip indicator */
+
+    if(*PhyState & PHY_MDIX)
+      Mdix = 1;
+    else
+      Mdix = 0;
+    return(_MIIMDIO_MDIXFLIP|Mdix);
+    }
+
+  /*Return state change to user                                              */
+
+  if (*PhyState&PHY_CHNG_MASK)
+    {
+    *PhyState&=~PHY_CHNG_MASK;
+    return(1);
+    }
+   else
+    return(0);
+  }
+
+/* cpMacMdioGetDuplex is called to retrieve the Duplex info                   */
+
+int cpMacMdioGetDuplex(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  return((*PhyState&PHY_DUPLEX_MASK)?1:0);  /* return 0 or a 1  */
+  }
+
+/* cpMacMdioGetSpeed is called to retreive the Speed info                     */
+
+int cpMacMdioGetSpeed(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  return(*PhyState&PHY_SPEED_MASK);
+  }
+
+/* cpMacMdioGetPhyNum is called to retreive the Phy Device Adr info           */
+
+int cpMacMdioGetPhyNum(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  return((*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET);
+  }
+
+/* cpMacMdioGetLoopback is called to Determine if the LOOPBACK state has been reached*/
+
+int cpMacMdioGetLoopback(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  return((*PhyState&PHY_STATE_MASK)==LOOPBACK);
+  }
+/* cpMacMdioGetLinked is called to Determine if the LINKED state has been reached*/
+
+int cpMacMdioGetLinked(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  return((*PhyState&PHY_STATE_MASK)==LINKED);
+  }
+
+void cpMacMdioLinkChange(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u  PhyNum,PhyStatus;
+
+  PhyNum=(*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET;
+
+  if (cpMacMdioGetLinked(PhyDev))
+    {
+    PhyStatus=_mdioUserAccessRead(PhyDev, PHY_STATUS_REG, PhyNum);
+
+    if ((PhyStatus&PHY_LINKED)==0)
+      {
+      *PhyState&=~(PHY_TIM_MASK|PHY_STATE_MASK);
+      if (*PhyState&SMODE_AUTO)
+        {
+        _mdioUserAccessWrite(PhyDev, PHY_CONTROL_REG, PhyNum, AUTO_NEGOTIATE_EN|RENEGOTIATE);
+        *PhyState|=PHY_CHANGE|PHY_NWST_TO|NWAY_START;
+        }
+       else
+        {
+        *PhyState|=PHY_CHANGE|PHY_LINK_TO|LINK_WAIT;
+        }
+      }
+    }
+  }
+
+void cpMacMdioGetVer(bit32u miibase, bit32u *ModID,  bit32u *RevMaj,  bit32u *RevMin)
+  {
+  bit32u  Ver;
+
+  Ver = MDIO_VER(miibase);
+
+  *ModID  = (Ver & MDIO_VER_MODID) >> 16;
+  *RevMaj = (Ver & MDIO_VER_REVMAJ) >> 8;
+  *RevMin = (Ver & MDIO_VER_REVMIN);
+  }
+
+int cpMacMdioGetPhyDevSize(void)
+  {
+  return(sizeof(PHY_DEVICE));
+  }
+
+  /* returns 0 if current Phy has AutoMdix support, otherwise 0 */
+int _mdioMdixSupported(PHY_DEVICE *PhyDev)
+  {
+  bit32u *PhyState = &PhyDev->PhyState;
+  bit32u PhyNum;
+
+  if((PhyDev->PhyMode & NWAY_AUTOMDIX) == 0)
+    return(0);  /* AutoMdix not turned on */
+
+  PhyNum=(*PhyState&PHY_DEV_MASK)>>PHY_DEV_OFFSET;
+  if( ((1<<PhyNum) & PhyDev->MdixMask) == 0)
+    return(0);  /*  Phy does not support AutoMdix*/
+
+  return(1);
+  }
+
+/* If current Phy has AutoMdix support add Mdix Delay to the Timer State Value */
+void _mdioMdixDelay(PHY_DEVICE *PhyDev)
+  {
+  int Delay;
+  bit32u *PhyState = &PhyDev->PhyState;  
+#ifdef _CPHAL_CPMAC
+  HAL_DEVICE *HalDev = PhyDev->HalDev;
+#endif
+
+  if(_mdioMdixSupported(PhyDev) == 0)
+    return;  /* AutoMdix not supported */
+/* Currently only supported when used with the CPMAC */
+#ifdef _CPHAL_CPMAC
+  /* Get the Delay value in milli-seconds and convert to ten-milli second value */
+  Delay = cpmacRandomRange(HalDev, _AUTOMDIX_DELAY_MIN, _AUTOMDIX_DELAY_MAX);
+  Delay /= 10;
+
+  /*  Add AutoMidx Random Switch Delay to AutoMdix Link Delay */
+
+  Delay += (PHY_MDIX_TO>>PHY_TIM_OFFSET);
+
+  /* Change Timeout value to AutoMdix standard */
+  *PhyState &= ~(PHY_TIM_MASK);  /* Clear current Time out value */
+  *PhyState |=  (Delay<<PHY_TIM_OFFSET);     /* Set new value */
+#endif
+  }
+
+
diff -urN linux.old/drivers/net/avalanche_cpmac/cpmdio.h linux.dev/drivers/net/avalanche_cpmac/cpmdio.h
--- linux.old/drivers/net/avalanche_cpmac/cpmdio.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpmdio.h	2005-07-12 02:48:42.047593000 +0200
@@ -0,0 +1,73 @@
+/*****************************************************************************
+**      TNETD53xx Software Support
+**      Copyright(c) 2002, Texas Instruments Incorporated. All Rights Reserved.
+**
+**      FILE: cpmdio.h   User Include for MDIO API Access
+**
+**      DESCRIPTION:
+**              This include file contains definitions for the the MDIO API
+**
+**      HISTORY:
+**              27Mar02 Michael Hanrahan Original (modified from emacmdio.h)
+**              04Apr02 Michael Hanrahan Added Interrupt Support
+*****************************************************************************/
+#ifndef _INC_CPMDIO
+#define _INC_CPMDIO
+
+
+#ifndef __CPHAL_CPMDIO
+typedef void PHY_DEVICE;
+#endif
+
+
+/*Version Information */
+
+void cpMacMdioGetVer(bit32u miiBase, bit32u *ModID,  bit32u *RevMaj,  bit32u *RevMin);
+
+/*Called once at the begining of time                                        */
+
+int  cpMacMdioInit(PHY_DEVICE *PhyDev, bit32u miibase, bit32u inst, bit32u PhyMask, bit32u MLinkMask, bit32u MdixMask, bit32u ResetBase, bit32u ResetBit, bit32u MdioBusFreq, bit32u MdioClockFreq, int verbose, void *Info);
+int  cpMacMdioGetPhyDevSize(void);
+
+
+/*Called every 10 mili Seconds, returns TRUE if there has been a mode change */
+
+int cpMacMdioTic(PHY_DEVICE *PhyDev);
+
+/*Called to set Phy mode                                                     */
+
+void cpMacMdioSetPhyMode(PHY_DEVICE *PhyDev,bit32u PhyMode);
+
+/*Calls to retreive info after a mode change!                                */
+
+int  cpMacMdioGetDuplex(PHY_DEVICE *PhyDev);
+int  cpMacMdioGetSpeed(PHY_DEVICE *PhyDev);
+int  cpMacMdioGetPhyNum(PHY_DEVICE *PhyDev);
+int  cpMacMdioGetLinked(PHY_DEVICE *PhyDev);
+void cpMacMdioLinkChange(PHY_DEVICE *PhyDev);
+
+/*  Shot Down  */
+
+void cpMacMdioClose(PHY_DEVICE *PhyDev, int Full);
+
+
+/* Phy Mode Values  */
+#define NWAY_AUTOMDIX       (1<<16)
+#define NWAY_FD100          (1<<8)
+#define NWAY_HD100          (1<<7)
+#define NWAY_FD10           (1<<6)
+#define NWAY_HD10           (1<<5)
+#define NWAY_AUTO           (1<<0)
+
+/*
+ *
+ *    Tic() return values
+ *
+ */
+
+#define _MIIMDIO_MDIXFLIP (1<<28)
+
+#define _AUTOMDIX_DELAY_MIN  80  /* milli-seconds*/
+#define _AUTOMDIX_DELAY_MAX 200  /* milli-seconds*/
+
+#endif  /*  _INC_CPMDIO */
diff -urN linux.old/drivers/net/avalanche_cpmac/cppi_cpmac.c linux.dev/drivers/net/avalanche_cpmac/cppi_cpmac.c
--- linux.old/drivers/net/avalanche_cpmac/cppi_cpmac.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cppi_cpmac.c	2005-07-12 02:48:42.048593000 +0200
@@ -0,0 +1,1345 @@
+/*************************************************************************
+ *  TNETDxxxx Software Support
+ *  Copyright (c) 2002,2003 Texas Instruments Incorporated. All Rights Reserved.
+ *
+ *  FILE: cppi.c
+ *
+ *  DESCRIPTION:
+ *      This file contains shared code for all CPPI modules.
+ *
+ *  HISTORY:
+ *   7Aug02 Greg RC1.00  Original Version created.
+ *  27Sep02 Mick RC1.01  Merged for use by CPMAC/CPSAR
+ *  16Oct02 Mick RC1.02  Performance Tweaks (see cppihist.txt)
+ *  12Nov02 Mick RC1.02  Updated to use cpmac_reg.h
+ *  09Jan03 Mick RC3.01  Removed modification to RxBuffer ptr
+ *  28Mar03 Mick 1.03    RxReturn now returns error if Malloc Fails
+ *  10Apr03 Mick 1.03.02 Added Needs Buffer Support
+ *  11Jun03 Mick 1.06.02 halSend() errors corrected
+ *  23Aug04 Mick 1.07.08 cpmac only - Send: bypass threshold check if TxInts re-enabled
+ *
+ *  @author  Greg Guyotte
+ *  @version 1.00
+ *  @date    7-Aug-2002
+ *****************************************************************************/
+/* each CPPI module must modify this file, the rest of the
+                     code in cppi.c should be totally shared *//* Each CPPI module MUST properly define all constants shown below */
+
+/* CPPI registers */
+
+/* the following defines are not CPPI specific */
+
+static int TxInt(HAL_DEVICE *HalDev, int Ch, int Queue, int *MoreWork);                     
+
+static void FreeRx(HAL_DEVICE *HalDev, int Ch)
+  {
+   HAL_RCB *rcb_ptr;                                                /*+GSG 030303*/
+   int rcbSize = (sizeof(HAL_RCB)+0xf)&~0xf;                        /*+GSG 030303*/
+   int Num = HalDev->ChData[Ch].RxNumBuffers, i;                    /*+GSG 030303*/
+
+   /* Free Rx data buffers attached to descriptors, if necessary */
+   if (HalDev->RcbStart[Ch] != 0)                                   /*+GSG 030303*/
+     {                                                              /*+GSG 030303*/
+      for(i=0;i<Num;i++)                                            /*+GSG 030303*/
+        {                                                           /*+GSG 030303*/
+         rcb_ptr = (HAL_RCB *)(HalDev->RcbStart[Ch] + (i*rcbSize)); /*+GSG 030303*/
+
+         /* free the data buffer */
+         if (rcb_ptr->DatPtr != 0)
+       {
+
+        HalDev->OsFunc->FreeRxBuffer((void *)rcb_ptr->OsInfo, (void *)rcb_ptr->DatPtr);
+        rcb_ptr->OsInfo=0;                                        /*MJH+030522*/
+        rcb_ptr->DatPtr=0;                                        /*MJH+030522*/
+       }
+    }                                                           /*+GSG 030303*/
+     }                                                              /*+GSG 030303*/
+
+   /* free up all desciptors at once */
+   HalDev->OsFunc->FreeDmaXfer(HalDev->RcbStart[Ch]);
+
+   /* mark buffers as freed */
+   HalDev->RcbStart[Ch] = 0;
+  }
+
+static void FreeTx(HAL_DEVICE *HalDev, int Ch, int Queue)
+  {
+
+/*+GSG 030303*/
+
+   /* free all descriptors at once */
+   HalDev->OsFunc->FreeDmaXfer(HalDev->TcbStart[Ch][Queue]);
+
+   HalDev->TcbStart[Ch][Queue] = 0;
+  }
+
+/* return of 0 means that this code executed, -1 means the interrupt was not
+   a teardown interrupt */
+static int RxTeardownInt(HAL_DEVICE *HalDev, int Ch)
+  {
+   bit32u base = HalDev->dev_base;
+
+   /* check to see if the interrupt is a teardown interrupt */
+   if (((CPMAC_RX_INT_ACK( base , Ch ))  & TEARDOWN_VAL) == TEARDOWN_VAL)
+     {
+      /* finish channel teardown */
+
+      /* Free channel resources on a FULL teardown */
+      if (HalDev->RxTeardownPending[Ch] & FULL_TEARDOWN)
+        {
+         FreeRx(HalDev, Ch);
+        }
+
+      /* bug fix - clear Rx channel pointers on teardown */
+      HalDev->RcbPool[Ch] = 0;
+      HalDev->RxActQueueHead[Ch]  = 0;
+      HalDev->RxActQueueCount[Ch] = 0;
+      HalDev->RxActive[Ch] = FALSE;
+
+      /* write completion pointer */
+      (CPMAC_RX_INT_ACK( base , Ch ))  = TEARDOWN_VAL;
+
+      /* use direction bit as a teardown pending bit! May be able to
+         use only one teardown pending integer in HalDev */
+
+      HalDev->RxTeardownPending[Ch] &= ~RX_TEARDOWN;
+
+      HalDev->ChIsOpen[Ch][DIRECTION_RX] = 0;
+
+      HalDev->ChIsOpen[Ch][DIRECTION_RX] = 0;
+      CPMAC_RX_INTMASK_CLEAR(HalDev->dev_base) = (1<<Ch);
+      if ((HalDev->RxTeardownPending[Ch] & BLOCKING_TEARDOWN) == 0)
+    {
+
+     HalDev->OsFunc->TeardownComplete(HalDev->OsDev, Ch, DIRECTION_RX);
+    }
+      HalDev->RxTeardownPending[Ch] = 0;
+
+      return (EC_NO_ERRORS);
+     }
+   return (-1);
+  }
+
+/* return of 0 means that this code executed, -1 means the interrupt was not
+   a teardown interrupt.  Note: this code is always called with Queue == 0 (hi priority). */
+static int TxTeardownInt(HAL_DEVICE *HalDev, int Ch, int Queue)
+  {
+   bit32u base = HalDev->dev_base;
+   HAL_TCB *Last, *Curr, *First;                                    /*+GSG 030303*/
+   int i;
+
+   if (((CPMAC_TX_INT_ACK( base , Ch ))  & TEARDOWN_VAL) == TEARDOWN_VAL)
+     {
+      /* perform all actions for both queues (+GSG 040212) */
+      for (i=0; i<HalDev->ChData[Ch].TxNumQueues; i++)
+        {
+         /* return outstanding buffers to OS                             +RC3.02*/
+         Curr = HalDev->TxActQueueHead[Ch][i];                     /*+GSG 030303*/
+         First = Curr;                                                 /*+GSG 030303*/
+         while (Curr)                                                  /*+GSG 030303*/
+           {                                                           /*+GSG 030303*/
+            /* Pop TCB(s) for packet from the stack */                 /*+GSG 030303*/
+            Last = Curr->Eop;                                          /*+GSG 030303*/
+            HalDev->TxActQueueHead[Ch][i] = Last->Next;            /*+GSG 030303*/
+                                                                    /*+GSG 030303*/
+            /* return to OS */                                         /*+GSG 030303*/
+            HalDev->OsFunc->SendComplete(Curr->OsInfo);                /*+GSG 030303*/
+                                                                    /*+GSG 030303*/
+            /* Push Tcb(s) back onto the stack */                      /*+GSG 030303*/
+            Curr = Last->Next;                                         /*+GSG 030303*/
+            Last->Next = HalDev->TcbPool[Ch][i];                   /*+GSG 030303*/
+            HalDev->TcbPool[Ch][i] = First;                        /*+GSG 030303*/
+                                                                    /*+GSG 030303*/
+            /* set the first(SOP) pointer for the next packet */       /*+GSG 030303*/
+            First = Curr;                                              /*+GSG 030303*/
+           }                                                           /*+GSG 030303*/
+        }
+
+      /* finish channel teardown */
+
+      if (HalDev->TxTeardownPending[Ch] & FULL_TEARDOWN)
+        {
+         FreeTx(HalDev, Ch, 0);
+
+         if (HalDev->ChData[Ch].TxNumQueues == 2)
+           FreeTx(HalDev, Ch, 1);
+        } /* if FULL teardown */
+
+      /* perform all actions for both queues (+GSG 040212) */
+      for (i=0; i<HalDev->ChData[Ch].TxNumQueues; i++)
+        {
+         /* bug fix - clear Tx channel pointers on teardown */
+         HalDev->TcbPool[Ch][i] = 0;
+         HalDev->TxActQueueHead[Ch][i]  = 0;
+         HalDev->TxActQueueCount[Ch][i] = 0;
+         HalDev->TxActive[Ch][i]        = FALSE;
+        }
+
+      /* write completion pointer, only needed for the high priority queue */
+      (CPMAC_TX_INT_ACK( base , Ch ))  = TEARDOWN_VAL;
+
+      /* no longer pending teardown */
+      HalDev->TxTeardownPending[Ch] &= ~TX_TEARDOWN;
+
+      HalDev->ChIsOpen[Ch][DIRECTION_TX] = 0;
+
+      HalDev->ChIsOpen[Ch][DIRECTION_TX] = 0;
+      CPMAC_TX_INTMASK_CLEAR(HalDev->dev_base) = (1<<Ch);
+      if ((HalDev->TxTeardownPending[Ch] & BLOCKING_TEARDOWN) == 0)
+        {
+
+         HalDev->OsFunc->TeardownComplete(HalDev->OsDev, Ch, DIRECTION_TX);
+        }
+      HalDev->TxTeardownPending[Ch] = 0;
+
+      return (EC_NO_ERRORS);
+     }
+   return (-1);
+  }
+
+/* +GSG 030421 */
+static void AddToRxQueue(HAL_DEVICE *HalDev, HAL_RCB *FirstRcb, HAL_RCB *LastRcb, int FragCount, int Ch)
+  {
+   if (HalDev->RxActQueueHead[Ch]==0)
+     {
+
+      HalDev->RxActQueueHead[Ch]=FirstRcb;
+      HalDev->RxActQueueTail[Ch]=LastRcb;
+      if (!HalDev->RxActive[Ch])
+        {
+         /* write Rx Queue Head Descriptor Pointer */
+         ((CPMAC_RX_HDP(  HalDev->dev_base  ,  Ch  )) )  = VirtToPhys(FirstRcb) - HalDev->offset;
+         HalDev->RxActive[Ch]=TRUE;
+        }
+     }
+    else
+     {
+      register HAL_RCB *OldTailRcb;
+      register bit32u rmode;
+      
+      HalDev->OsFunc->CriticalOn();
+      OldTailRcb=HalDev->RxActQueueTail[Ch];
+      OldTailRcb->Next=(void *)FirstRcb;
+      OldTailRcb=VirtToVirtNoCache(OldTailRcb);
+      OldTailRcb->HNext=VirtToPhys(FirstRcb) - HalDev->offset;
+      HalDev->RxActQueueTail[Ch]=LastRcb;
+      rmode=OldTailRcb->mode;
+      if (rmode&CB_EOQ_BIT)
+        {
+        rmode&=~CB_EOQ_BIT;
+        ((CPMAC_RX_HDP(  HalDev->dev_base  ,  Ch  )) )  = VirtToPhys(FirstRcb) - HalDev->offset;
+        OldTailRcb->mode=rmode;
+        }   
+      HalDev->OsFunc->CriticalOff();
+     }
+  }
+
+/**
+ *  @ingroup CPHAL_Functions
+ *  This function is called to indicate to the CPHAL that the upper layer
+ *  software has finished processing the receive data (given to it by
+ *  osReceive()).  The CPHAL will then return the appropriate receive buffers
+ *  and buffer descriptors to the available pool.
+ *
+ *  @param   HalReceiveInfo   Start of receive buffer descriptor chain returned to
+ *                      CPHAL.
+ *  @param   StripFlag  Flag indicating whether the upper layer software has
+ *                      retained ownership of the receive data buffers.
+ *<BR>
+ * 'FALSE' means  that the CPHAL can reuse the receive data buffers.
+ *<BR>
+ * 'TRUE' : indicates the data buffers were retained by the OS
+ *<BR>
+ * NOTE:  If StripFlag is TRUE, it is the responsibility of the upper layer software to free the buffers when they are no longer needed.
+ *
+ *  @return EC_NO_ERRORS (ok). <BR>
+ *          Possible Error Codes:<BR>
+ *          @ref EC_VAL_INVALID_STATE "EC_VAL_INVALID_STATE"<BR>
+ *          @ref EC_VAL_RCB_NEEDS_BUFFER "EC_VAL_RCB_NEEDS_BUFFER"<BR>
+ *          @ref EC_VAL_RCB_DROPPED "EC_VAL_RCB_DROPPED"<BR>
+ */
+static int halRxReturn(HAL_RECEIVEINFO *HalReceiveInfo,
+            int StripFlag)
+  {
+   int Ch, i;
+   HAL_RCB *LastRcb;
+   HAL_DEVICE *HalDev;
+   int RcbSize;
+   int FragCount;
+
+   Ch = HalReceiveInfo->mode&0x0ff;
+   HalDev = (HAL_DEVICE *)HalReceiveInfo->Off_BLen;
+   FragCount = HalReceiveInfo->mode>>8;
+      
+   if (HalDev->State != enOpened)
+     return(EC_CPMAC |EC_FUNC_RXRETURN|EC_VAL_INVALID_STATE);
+
+   LastRcb=(HAL_RCB *)HalReceiveInfo->Eop;
+   LastRcb->HNext=0;
+   LastRcb->Next=0;
+   RcbSize = HalDev->ChData[Ch].RxBufSize;
+
+   if (FragCount>1)
+     {
+      LastRcb->Off_BLen=RcbSize;
+      LastRcb->mode=CB_OWNERSHIP_BIT;
+     }
+
+   HalReceiveInfo->Off_BLen=RcbSize;
+   HalReceiveInfo->mode=CB_OWNERSHIP_BIT;
+
+   /* If OS has kept the buffers for this packet, attempt to alloc new buffers */
+   if (StripFlag)
+     {
+      int rc=0;                                                      /*MJH+030417*/
+      int GoodCount=0;                                               /*GSG+030421*/       
+      HAL_RCB *TempRcb;
+      char *pBuf;
+      HAL_RCB *CurrHeadRcb = HalReceiveInfo, *LastGoodRcb=0;         /* +GSG 030421 */
+
+      TempRcb = HalReceiveInfo;
+      for (i=0; i<FragCount; i++)
+        {
+         if (TempRcb == 0)
+           {
+            dbgPrintf("Rx Return error while allocating new buffers\n");
+            dbgPrintf("Rcb = %08x, Rcb->Eop = %08x, FragCount = %d:%d\n",
+              (bit32u)HalReceiveInfo, (bit32u)HalReceiveInfo->Eop, FragCount,i);
+            osfuncSioFlush();
+
+            return(EC_CPPI|EC_FUNC_RXRETURN|EC_VAL_CORRUPT_RCB_CHAIN);
+           }
+
+         pBuf= (char *) HalDev->OsFunc->MallocRxBuffer(RcbSize,0,
+                             0xF,HalDev->ChData[Ch].OsSetup,
+                             (void *)TempRcb,
+                             (void *)&TempRcb->OsInfo,
+                             (void *) HalDev->OsDev);
+         if (!pBuf)
+           {
+            /* malloc failed, add this RCB to Needs Buffer List */
+            (HAL_RCB *)TempRcb->Eop = TempRcb;                                  /* GSG +030430 */
+            TempRcb->mode=1<<8|Ch;
+            TempRcb->Off_BLen=(bit32u)HalDev;
+            
+            if(HalDev->NeedsCount < MAX_NEEDS)                                  /* +MJH 030410 */
+              {                                                                 /* +MJH 030410 */
+               HalDev->Needs[HalDev->NeedsCount] = (HAL_RECEIVEINFO *) TempRcb; /* +MJH 030410 */
+               HalDev->NeedsCount++;                                            /* +MJH 030410 */
+               rc = (EC_CPPI|EC_FUNC_RXRETURN|EC_VAL_RCB_NEEDS_BUFFER);         /* ~MJH 030417 */
+              }                                                                 /* +MJH 030410 */
+             else                                                               /* +MJH 030410 */
+               rc = (EC_CPPI|EC_FUNC_RXRETURN|EC_VAL_RCB_DROPPED);              /* ~MJH 030417 */
+
+            /* requeue any previous RCB's that were ready to go before this one */
+            if (GoodCount > 0)                                                  /* +GSG 030421 */
+              {                                                                 /* +GSG 030421 */
+               LastGoodRcb->HNext=0;                                            /* +GSG 030430 */
+               LastGoodRcb->Next=0;                                             /* +GSG 030430 */
+               osfuncDataCacheHitWritebackAndInvalidate((void *)LastGoodRcb, 16);            /* +GSG 030430 */
+
+               AddToRxQueue(HalDev, CurrHeadRcb, LastGoodRcb, GoodCount, Ch);   /* +GSG 030421 */
+               GoodCount = 0;                                                   /* +GSG 030421 */
+              }                                                                 /* +GSG 030421 */
+
+            CurrHeadRcb = TempRcb->Next;                                        /* +GSG 030421 */
+           }
+          else                                                                  /* +GSG 030421 */
+           {                                                                    /* +GSG 030421 */
+            /* malloc succeeded, requeue the RCB to the hardware */
+            TempRcb->BufPtr=VirtToPhys(pBuf) - HalDev->offset;
+            TempRcb->DatPtr=pBuf;
+            /* Emerald fix 10/29 */
+            osfuncDataCacheHitWritebackAndInvalidate((void *)TempRcb, 16);
+
+            /* i store the last good RCB in case the malloc fails for the
+               next fragment.  This ensures that I can go ahead and return
+               a partial chain of RCB's to the hardware */
+            LastGoodRcb = TempRcb;                                              /* +GSG 030421 */
+            GoodCount++;                                                        /* +GSG 030421 */
+           }                                                                    /* +GSG 030421 */
+         TempRcb = TempRcb->Next;
+        } /*  end of Frag loop */
+      /* if there any good RCB's to requeue, do so here */
+      if (GoodCount > 0)                                                        /* +GSG 030421 */
+        {
+         AddToRxQueue(HalDev, CurrHeadRcb, LastGoodRcb, GoodCount, Ch);          /* +GSG 030421 */
+        }
+      return(rc);                                                               /* ~GSG 030421 */
+     }
+   else
+     {
+      /*  Not Stripping */
+      /* Emerald */
+      /* Write Back SOP and last RCB */
+      osfuncDataCacheHitWritebackAndInvalidate((void *)HalReceiveInfo, 16);
+
+      if (FragCount > 1)
+        {
+         osfuncDataCacheHitWritebackAndInvalidate((void *)LastRcb, 16);
+        }
+      /* if not stripping buffers, always add to queue */
+      AddToRxQueue(HalDev, HalReceiveInfo, LastRcb, FragCount, Ch); /*MJH~030520*/
+     }
+
+   return(EC_NO_ERRORS);
+  }
+
+/* +MJH 030410
+   Trys to liberate an RCB until liberation fails.
+   Note: If liberation fails then RxReturn will re-add the RCB to the
+         Needs list.
+*/
+static void NeedsCheck(HAL_DEVICE *HalDev)
+{
+    HAL_RECEIVEINFO* HalRcb;
+    int rc;
+    HalDev->OsFunc->CriticalOn();
+    while(HalDev->NeedsCount)
+      {
+      HalDev->NeedsCount--;
+      HalRcb = HalDev->Needs[HalDev->NeedsCount];
+      rc =  halRxReturn(HalRcb, 1);
+      /* short circuit if RxReturn starts to fail */
+      if (rc != 0)
+        break;
+      }
+    HalDev->OsFunc->CriticalOff();
+}
+
+/*
+ *  This function allocates transmit buffer descriptors (internal CPHAL function).
+ *  It creates a high priority transmit queue by default for a single Tx
+ *  channel.  If QoS is enabled for the given CPHAL device, this function
+ *  will also allocate a low priority transmit queue.
+ *
+ *  @param   HalDev   CPHAL module instance. (set by cphalInitModule())
+ *  @param   Ch       Channel number.
+ *
+ *  @return  0 OK, Non-Zero Not OK
+ */
+static int InitTcb(HAL_DEVICE *HalDev, int Ch)
+  {
+   int i, Num = HalDev->ChData[Ch].TxNumBuffers;
+   HAL_TCB *pTcb=0;
+   char *AllTcb;
+   int  tcbSize, Queue;
+   int SizeMalloc;
+
+   tcbSize = (sizeof(HAL_TCB)+0xf)&~0xf;
+   SizeMalloc = (tcbSize*Num)+0xf;
+
+   for (Queue=0; Queue < HalDev->ChData[Ch].TxNumQueues; Queue++)
+     {
+      if (HalDev->TcbStart[Ch][Queue] == 0)
+        {
+
+         /* malloc all TCBs at once */
+         AllTcb = (char *)HalDev->OsFunc->MallocDmaXfer(SizeMalloc,0,0xffffffff);
+         if (!AllTcb)
+           {
+            return(EC_CPPI|EC_FUNC_HAL_INIT|EC_VAL_TCB_MALLOC_FAILED);
+           }
+
+         HalDev->OsFunc->Memset(AllTcb, 0, SizeMalloc);
+
+         /* keep this address for freeing later */
+         HalDev->TcbStart[Ch][Queue] = AllTcb;
+        }
+       else
+        {
+         /* if the memory has already been allocated, simply reuse it! */
+         AllTcb = HalDev->TcbStart[Ch][Queue];
+        }
+
+      /* align to cache line */
+      AllTcb = (char *)(((bit32u)AllTcb + 0xf) &~ 0xf); /*PITS #143  MJH~030522*/
+
+      /* default High priority transmit queue */
+      HalDev->TcbPool[Ch][Queue]=0;
+      for(i=0;i<Num;i++)
+        {
+         /*pTcb=(HAL_TCB *) OsFunc->MallocDmaXfer(sizeof(HAL_TCB),0,0xffffffff); */
+         pTcb= (HAL_TCB *)(AllTcb + (i*tcbSize));
+         pTcb->mode=0;
+         pTcb->BufPtr=0;
+         pTcb->Next=HalDev->TcbPool[Ch][Queue];
+         pTcb->Off_BLen=0;
+         HalDev->TcbPool[Ch][Queue]=pTcb;
+        }
+      /*HalDev->TcbEnd = pTcb;*/
+     }
+
+   return(EC_NO_ERRORS);
+  }
+
+/*
+ *  This function allocates receive buffer descriptors (internal CPHAL function).
+ *  After allocation, the function 'queues' (gives to the hardware) the newly
+ *  created receive buffers to enable packet reception.
+ *
+ *  @param   HalDev   CPHAL module instance. (set by cphalInitModule())
+ *  @param   Ch    Channel number.
+ *
+ *  @return  0 OK, Non-Zero Not OK
+ */
+static int InitRcb(HAL_DEVICE *HalDev, int Ch)
+  {
+   int i, Num = HalDev->ChData[Ch].RxNumBuffers;
+   int Size = HalDev->ChData[Ch].RxBufSize;
+   HAL_RCB *pRcb;
+   char *pBuf;
+   char *AllRcb;
+   int  rcbSize;
+   int  DoMalloc = 0;
+   int SizeMalloc;
+   int MallocSize;
+
+   rcbSize = (sizeof(HAL_RCB)+0xf)&~0xf;
+   SizeMalloc = (rcbSize*Num)+0xf;
+
+   if (HalDev->RcbStart[Ch] == 0)
+     {
+      DoMalloc = 1;
+
+      /* malloc all RCBs at once */
+      AllRcb= (char *)HalDev->OsFunc->MallocDmaXfer(SizeMalloc,0,0xffffffff);
+      if (!AllRcb)
+        {
+         return(EC_CPPI|EC_FUNC_HAL_INIT|EC_VAL_RCB_MALLOC_FAILED);
+        }
+
+      HalDev->OsFunc->Memset(AllRcb, 0, SizeMalloc);
+
+      /* keep this address for freeing later */
+      HalDev->RcbStart[Ch] = AllRcb;
+     }
+    else
+     {
+      /* if the memory has already been allocated, simply reuse it! */
+      AllRcb = HalDev->RcbStart[Ch];
+     }
+
+   /* align to cache line */
+   AllRcb = (char *)(((bit32u)AllRcb + 0xf)&~0xf);  /*PITS #143  MJH~030522*/
+
+   HalDev->RcbPool[Ch]=0;
+   for(i=0;i<Num;i++)
+     {
+      pRcb = (HAL_RCB *)(AllRcb + (i*rcbSize));
+
+      if (DoMalloc == 1)
+        {
+
+         MallocSize = Size;                                       /*~3.01 */
+         pBuf= (char *) HalDev->OsFunc->MallocRxBuffer(MallocSize,0,0xF,HalDev->ChData[Ch].OsSetup, (void *)pRcb, (void *)&pRcb->OsInfo, (void *) HalDev->OsDev);
+         if(!pBuf)
+             {
+            return(EC_CPPI|EC_FUNC_HAL_INIT|EC_VAL_RX_BUFFER_MALLOC_FAILED);
+             }
+           /* -RC3.01 pBuf = (char *)(((bit32u)pBuf+0xF) & ~0xF); */
+         pRcb->BufPtr=VirtToPhys(pBuf) - HalDev->offset;
+         pRcb->DatPtr=pBuf;
+        }
+      pRcb->mode=(1<<8)|Ch; /* One Frag for Ch */
+      pRcb->Next=(void *)HalDev->RcbPool[Ch];
+      pRcb->Off_BLen=(bit32u)HalDev;
+      HalDev->RcbPool[Ch]=pRcb;
+     }
+
+   /* Give all of the Rx buffers to hardware */
+
+   while(HalDev->RcbPool[Ch])
+     {
+      pRcb=HalDev->RcbPool[Ch];
+      HalDev->RcbPool[Ch]=pRcb->Next;
+      pRcb->Eop=(void*)pRcb;
+      pRcb->mode=(1<<8)|Ch;
+      halRxReturn((HAL_RECEIVEINFO *)pRcb, 0);
+     }
+
+   return(EC_NO_ERRORS);
+  }
+
+/**
+ *  @ingroup CPHAL_Functions
+ *  This function transmits the data in FragList using available transmit
+ *  buffer descriptors.  More information on the use of the Mode parameter
+ *  is available in the module-specific appendices.  Note:  The OS should
+ *  not call Send() for a channel that has been requested to be torndown.
+ *
+ *  @param   HalDev      CPHAL module instance. (set by cphalInitModule())
+ *  @param   FragList    Fragment List structure.
+ *  @param   FragCount   Number of fragments in FragList.
+ *  @param   PacketSize  Number of bytes to transmit.
+ *  @param   OsSendInfo  OS Send Information structure. <BR>
+ *  @param   Mode        32-bit value with the following bit fields: <BR>
+ *                       31-16: Mode  (used for module specific data). <BR>
+ *                       15-08: Queue (transmit queue to send on). <BR>
+ *                       07-00: Channel (channel number to send on).
+ *
+ *  @return  EC_NO_ERRORS (ok). <BR>
+ *           Possible Error Codes:<BR>
+ *           @ref EC_VAL_INVALID_STATE "EC_VAL_INVALID_STATE"<BR>
+ *           @ref EC_VAL_NOT_LINKED "EC_VAL_NOT_LINKED"<BR>
+ *           @ref EC_VAL_INVALID_CH "EC_VAL_INVALID_CH"<BR>
+ *           @ref EC_VAL_OUT_OF_TCBS "EC_VAL_OUT_OF_TCBS"<BR>
+ *           @ref EC_VAL_NO_TCBS "EC_VAL_NO_TCBS"<BR>
+ */
+static int halSend(HAL_DEVICE *HalDev,FRAGLIST *FragList,
+                      int FragCount,int PacketSize, OS_SENDINFO *OsSendInfo,
+                      bit32u Mode)
+  {
+  HAL_TCB *tcb_ptr, *head;
+  int i;
+  int rc = EC_NO_ERRORS;
+  int Ch = Mode & 0xFF;
+  int Queue = (Mode>>8)&0xFF;
+  /*int DoThresholdCheck=1;  */ /* Used when TxIntDisable is set and TxInts are re-enabled */
+  
+  if (HalDev->State != enOpened)
+     return(EC_CPPI|EC_FUNC_SEND|EC_VAL_INVALID_STATE);
+
+  if (!HalDev->Linked)
+    {
+     rc = EC_CPPI|EC_FUNC_SEND|EC_VAL_NOT_LINKED;
+     return(rc);
+    }
+
+  if (HalDev->ChIsOpen[Ch][DIRECTION_TX] == 0)                    /*MJH~030611*/ /*PITS 148*/
+    return(EC_CPMAC |EC_FUNC_SEND|EC_VAL_INVALID_CH);              /*+GSG 030303*/
+
+  HalDev->OsFunc->CriticalOn();
+
+  /* Setup Tx mode and size */
+  if (PacketSize<60)
+    {
+     FragList[FragCount-1].len += (60 - PacketSize);              /*MJH~030506*//*PITS 132*/
+     PacketSize = 60;                                             /*MJH~030506*/
+    }
+  Mode &= CB_PASSCRC_BIT;
+
+  tcb_ptr = head = HalDev->TcbPool[Ch][Queue];
+
+  if (tcb_ptr)
+    {
+
+     Mode|=PacketSize|CB_SOF_BIT|CB_OWNERSHIP_BIT;
+
+     for (i=0; i<FragCount; i++)
+
+       {
+        /* Setup Tx mode and size */
+        tcb_ptr->Off_BLen = FragList[i].len;
+        
+        tcb_ptr->mode     = Mode;
+        tcb_ptr->BufPtr   = VirtToPhys((bit32 *)FragList[i].data) - HalDev->offset;
+        tcb_ptr->OsInfo = OsSendInfo;
+
+        if (i == (FragCount - 1))
+          {
+           /* last fragment */
+           tcb_ptr->mode |= CB_EOF_BIT;
+
+           /* since this is the last fragment, set the TcbPool pointer before
+              nulling out the Next pointers */
+
+           HalDev->TcbPool[Ch][Queue] = tcb_ptr->Next;
+
+           tcb_ptr->Next = 0;
+           tcb_ptr->HNext = 0;
+
+           /* In the Tx Interrupt handler, we will need to know which TCB is EOP,
+              so we can save that information in the SOP */
+           head->Eop = tcb_ptr;
+
+           /* Emerald fix 10/29 */
+       osfuncDataCacheHitWritebackAndInvalidate((void *)tcb_ptr, 16);
+
+          }
+         else
+          {
+           Mode=CB_OWNERSHIP_BIT;
+           tcb_ptr->HNext    = VirtToPhys((bit32 *)tcb_ptr->Next) - HalDev->offset;
+        
+           /* Emerald fix 10/29 */
+           osfuncDataCacheHitWritebackAndInvalidate((void *)tcb_ptr, 16);
+
+           tcb_ptr = tcb_ptr->Next;  /* what about the end of TCB list?? */
+
+           if (tcb_ptr == 0)
+             {
+              rc = EC_CPPI|EC_FUNC_SEND|EC_VAL_OUT_OF_TCBS;
+              goto ExitSend;
+             }
+          }
+       } /* for */
+
+     /* put it on the high priority queue */
+     if (HalDev->TxActQueueHead[Ch][Queue] == 0)
+       {
+        HalDev->TxActQueueHead[Ch][Queue]=head;
+        HalDev->TxActQueueTail[Ch][Queue]=tcb_ptr;
+/*+GSG 030303*//*+GSG 030303*/
+        if (!HalDev->TxActive[Ch][Queue])
+          {
+
+              bit32u base = HalDev->dev_base;
+              
+              /* write CPPI TX HDP */
+              (CPMAC_TX_HDP( base , Ch ))  = VirtToPhys(head)  - HalDev->offset;
+              HalDev->TxActive[Ch][Queue]=TRUE;
+
+          }
+       }
+      else
+       {
+	    register volatile HAL_TCB *pTailTcb;   
+        register bit32u tmode;
+        register bit32u pCurrentTcb;
+        
+        HalDev->TxActQueueTail[Ch][Queue]->Next=head;
+        /* Emerald fix 10/29 */
+        
+        pTailTcb=(HAL_TCB *)VirtToVirtNoCache(&HalDev->TxActQueueTail[Ch][Queue]->HNext);
+        pCurrentTcb=VirtToPhys(head)  - HalDev->offset;
+        pTailTcb->HNext=pCurrentTcb;
+        HalDev->TxActQueueTail[Ch][Queue]=tcb_ptr;
+/*+GSG 030303*/
+        tmode=pTailTcb->mode;  
+        if (tmode&CB_EOQ_BIT)
+          {
+           bit32u base = HalDev->dev_base;
+
+           tmode&=~CB_EOQ_BIT;
+           pTailTcb->mode=tmode;
+           ((CPMAC_TX_HDP( base , Ch )) )  = pCurrentTcb;
+          }
+
+        else
+          {
+           if(HalDev->TxIntDisable)
+             {
+              /*  Enable Interrupts, to ensure packet goes out on wire */
+              CPMAC_TX_INTMASK_SET(HalDev->dev_base) = (1<<Ch); 
+              halPacketProcessEnd(HalDev); /* Allow Interrupt to be seen at the OS */
+              /*DoThresholdCheck = 0; */       /* Disable Threshold Check */
+
+             }       
+          }
+
+       }
+     rc = EC_NO_ERRORS;
+     goto ExitSend;
+    } /* if (tcb_ptr) */
+   else
+    {
+     rc = EC_CPPI|EC_FUNC_SEND|EC_VAL_NO_TCBS;
+     goto ExitSend;
+    }
+ExitSend:
+
+/* 15 June 2004 - NSP Performance Update : If Tx Ints are disabled then process them here */
+/* 29 June 2004 - NSP Performance Update : Moved to end at request of BCIL */
+/* 23 Aug  2004 - NSP Performance Update : If Tx Ints are re-enabled do not do Threshold check */
+
+   if(HalDev->TxIntDisable /*&& DoThresholdCheck*/)
+   {
+      if(--HalDev->TxIntThreshold[Ch] <= 0)
+      {
+          int MoreWork;
+          TxInt(HalDev, Ch, 0, &MoreWork);
+          HalDev->TxIntThreshold[Ch] = HalDev->TxIntThresholdMaster[Ch];
+      }
+   }
+    HalDev->OsFunc->CriticalOff();
+
+   return(rc);
+  }
+
+/*
+ *  This function processes receive interrupts.  It traverses the receive
+ *  buffer queue, extracting the data and passing it to the upper layer software via
+ *  osReceive().  It handles all error conditions and fragments without valid data by
+ *  immediately returning the RCB's to the RCB pool.
+ *
+ *  @param   HalDev   CPHAL module instance. (set by cphalInitModule())
+ *  @param   Ch       Channel Number.
+ *  @param   MoreWork Flag that indicates that there is more work to do when set to 1.
+ *
+ *  @return  0 if OK, non-zero otherwise.
+ */
+static int RxInt(HAL_DEVICE *HalDev, int Ch, int *MoreWork)
+  {
+  HAL_RCB *CurrentRcb, *SopRcb, *EofRcb, *EopRcb;
+  bit32u RxBufStatus,PacketsServiced, RxPktLen = 0, RxSopStatus,
+    FrmFrags, TotalFrags, FrmLen;
+  int base = HalDev->dev_base, Ret;
+  OS_FUNCTIONS *OsFunc = HalDev->OsFunc;
+  int RxServiceMax = HalDev->ChData[Ch].RxServiceMax;
+  int FragIndex; /* +GSG 030508 */
+  
+  if(HalDev->NeedsCount) /* +MJH 030410 */
+    NeedsCheck(HalDev);  /* +MJH 030410 */
+
+  /* Handle case of teardown interrupt */
+  if (HalDev->RxTeardownPending[Ch] != 0)
+    {
+     Ret = RxTeardownInt(HalDev, Ch);
+     if (Ret == 0)
+       {                                                              /*+GSG 030303*/
+        *MoreWork = 0;
+        return (EC_NO_ERRORS);
+       }                                                              /*+GSG 030303*/
+    }
+
+  /* Examine first RCB on the software active queue */
+  CurrentRcb=HalDev->RxActQueueHead[Ch];
+  osfuncDataCacheHitInvalidate((void*)CurrentRcb, 16);
+  RxBufStatus=CurrentRcb->mode;
+  PacketsServiced=0;
+  
+  /* Process received packets until we find hardware owned descriptors
+     or until we hit RxServiceMax */
+  while((CurrentRcb)&&((RxBufStatus&CB_OWNERSHIP_BIT)==0)&&
+    (PacketsServiced<RxServiceMax)) /* ~GSG 030307 */
+    {
+
+     PacketsServiced++; /* ~GSG 030307 */
+     SopRcb=CurrentRcb;
+     RxSopStatus=RxBufStatus;
+     RxPktLen = RxSopStatus&CB_SIZE_MASK;
+    
+     FrmFrags=0;
+     TotalFrags=0;
+     FragIndex=0;
+     FrmLen=0;
+     EofRcb=0;
+
+/* +GSG 030508 *//* +GSG 030508 */
+
+     /* Loop through all fragments that comprise current packet.  Build
+        fraglist and exit when the end of the packet is reached, or the
+        end of the descriptor list is reached. */
+     do
+       {
+	    bit32u DmaLen;
+	   
+
+        DmaLen=CurrentRcb->Off_BLen;
+
+        FrmLen+=DmaLen;
+        TotalFrags++;
+        if (!EofRcb)
+          {
+           HalDev->fraglist[FragIndex].data=((char *)CurrentRcb->DatPtr);       /* ~GSG 030508 */
+
+           HalDev->fraglist[FragIndex].len=DmaLen;                              /* ~GSG 030508 */
+
+           /* GSG 12/9 */
+           HalDev->fraglist[FragIndex].OsInfo = CurrentRcb->OsInfo;             /* ~GSG 030508 */
+
+           /* Upper layer must do the data invalidate */ 
+
+           FrmFrags++;
+           FragIndex++;                                                         /* ~GSG 030508 */
+           if (FrmLen>=RxPktLen)
+             EofRcb=CurrentRcb;
+          }
+        EopRcb=CurrentRcb;
+        CurrentRcb=EopRcb->Next;
+        if (CurrentRcb)
+          {
+           osfuncDataCacheHitInvalidate((void*)CurrentRcb,16);
+          }
+       }while(((EopRcb->mode&CB_EOF_BIT)==0)&&(CurrentRcb));
+     
+     /* Write the completion pointer for interrupt acknowledgement*/
+     (CPMAC_RX_INT_ACK( base , Ch ))  = VirtToPhys(EopRcb) - HalDev->offset;
+
+     EopRcb->Next=0;
+
+     if (CurrentRcb == 0)
+       { 
+	    /* If we are out of RCB's we must not send this packet
+	       to the OS. */
+        int RcbSize = HalDev->ChData[Ch].RxBufSize;
+
+        if (TotalFrags>1)
+          {
+           EopRcb->Off_BLen=RcbSize;
+           EopRcb->mode=CB_OWNERSHIP_BIT;
+           osfuncDataCacheHitWritebackAndInvalidate((void *)EopRcb, 16);
+          }
+
+        SopRcb->Off_BLen=RcbSize;
+        SopRcb->mode=CB_OWNERSHIP_BIT;   
+        osfuncDataCacheHitWritebackAndInvalidate((void *)SopRcb, 16);
+      
+        ((CPMAC_RX_HDP( base , Ch )) )  = VirtToPhys(SopRcb);
+       }
+      else
+       { 
+	    /* Dequeue packet and send to OS */
+        int mode;
+
+        /* setup SopRcb for the packet */
+        SopRcb->Eop=(void*)EopRcb;
+
+        /* dequeue packet */
+        HalDev->RxActQueueHead[Ch]=CurrentRcb;
+        
+        if (EopRcb->mode&CB_EOQ_BIT)
+          {
+	       /* Next pointer is non-null and EOQ bit is set, which
+	          indicates misqueue packet in CPPI protocol. */
+
+           ((CPMAC_RX_HDP( base , Ch )) )  = EopRcb->HNext;
+          }
+        
+        mode = (SopRcb->mode & 0xFFFF0000) | Ch;
+
+        SopRcb->mode=(FrmFrags<<8)|Ch;
+        SopRcb->Off_BLen=(bit32u)HalDev;
+        
+        /* send packet up the higher layer driver */
+        OsFunc->Receive(HalDev->OsDev,HalDev->fraglist,FragIndex,RxPktLen,             /* ~GSG 030508 */
+                       (HAL_RECEIVEINFO *)SopRcb,mode);
+    
+        RxBufStatus=CurrentRcb->mode;          
+       }
+    } /* while loop */
+      
+  if ((CurrentRcb)&&((RxBufStatus&CB_OWNERSHIP_BIT)==0)) /*~GSG 030307*/
+    {
+     *MoreWork = 1;
+    }
+   else
+    {
+     *MoreWork = 0;
+    }
+
+  return (EC_NO_ERRORS);
+}
+
+/*
+ *  This function processes transmit interrupts.  It traverses the
+ *  transmit buffer queue, detecting sent data buffers and notifying the upper
+ *  layer software via osSendComplete().  (for SAR, i originally had this split
+ *  into two functions, one for each queue, but joined them on 8/8/02)
+ *
+ *  @param   HalDev   CPHAL module instance. (set by cphalInitModule())
+ *  @param   Queue    Queue number to service (always 0 for MAC, Choose 1 for SAR to service low priority queue)
+ *  @param   MoreWork Flag that indicates that there is more work to do when set to 1.
+ *
+ *  @return  0 if OK, non-zero otherwise.
+ */
+int TxInt(HAL_DEVICE *HalDev, int Ch, int Queue, int *MoreWork)
+  {
+  HAL_TCB *CurrentTcb,*LastTcbProcessed,*FirstTcbProcessed;
+  int PacketsServiced;
+  bit32u TxFrameStatus;
+  int base;
+  int TxServiceMax = HalDev->ChData[Ch].TxServiceMax;
+  OS_FUNCTIONS *OsFunc = HalDev->OsFunc;
+
+/*+GSG 030303*//*+GSG 030303*/
+
+  /* load the module base address */
+  base = HalDev->dev_base;
+  
+  /* Handle case of teardown interrupt.  This must be checked at
+     the top of the function rather than the bottom, because
+     the normal data processing can wipe out the completion
+     pointer which is used to determine teardown complete. */
+  if (HalDev->TxTeardownPending[Ch] != 0)
+    {
+	 int Ret;
+	 
+     Ret = TxTeardownInt(HalDev, Ch, Queue);
+     if (Ret == 0)
+       {                                                              /*+GSG 030303*/
+        *MoreWork = 0; /* bug fix 1/6 */                              /*+GSG 030303*/
+        return (EC_NO_ERRORS);
+       }                                                              /*+GSG 030303*/
+    }
+
+  OsFunc->CriticalOn(); /*  240904 */
+
+  CurrentTcb = HalDev->TxActQueueHead[Ch][Queue];
+  FirstTcbProcessed=CurrentTcb;
+
+  if (CurrentTcb==0)
+    {
+     /* I saw this error a couple of times when multi-channels were added */
+     dbgPrintf("[cppi TxInt()]TxH int with no TCB in queue!\n");
+     dbgPrintf("              Ch=%d, CurrentTcb = 0x%08x\n", Ch, (bit32u)CurrentTcb);
+     dbgPrintf("              HalDev = 0x%08x\n", (bit32u)HalDev);
+     osfuncSioFlush();
+     OsFunc->CriticalOff(); 
+     return(EC_CPPI|EC_FUNC_TXINT|EC_VAL_NULL_TCB);
+    }
+
+  osfuncDataCacheHitInvalidate((void *)CurrentTcb, 16);
+  TxFrameStatus=CurrentTcb->mode;
+  PacketsServiced=0;
+
+  /* should the ownership bit check be inside of the loop?? could make it a
+     while-do loop and take this check away */
+  if ((TxFrameStatus&CB_OWNERSHIP_BIT)==0)
+    {
+    do
+      {
+      /* Pop TCB(s) for packet from the stack */
+      LastTcbProcessed=CurrentTcb->Eop;
+
+      /* new location for acknowledge */
+      /* Write the completion pointer */
+      (CPMAC_TX_INT_ACK( base , Ch ))  = VirtToPhys(LastTcbProcessed) - HalDev->offset;
+
+      HalDev->TxActQueueHead[Ch][Queue] = LastTcbProcessed->Next;
+
+/*+GSG 030303*//*+GSG 030303*/
+
+      osfuncDataCacheHitInvalidate((void *)LastTcbProcessed, 16);
+
+      if (LastTcbProcessed->mode&CB_EOQ_BIT)
+        {
+         if (LastTcbProcessed->Next)
+           {
+            /* Misqueued packet */
+
+               (CPMAC_TX_HDP( base , Ch ))  = LastTcbProcessed->HNext;
+
+           }
+          else
+           {
+       /* Tx End of Queue */
+
+            HalDev->TxActive[Ch][Queue]=FALSE;
+           }
+        }
+
+      OsFunc->SendComplete(CurrentTcb->OsInfo);
+
+      /* Push Tcb(s) back onto the stack */
+      CurrentTcb = LastTcbProcessed->Next;
+
+      LastTcbProcessed->Next=HalDev->TcbPool[Ch][Queue];
+
+      HalDev->TcbPool[Ch][Queue]=FirstTcbProcessed;
+
+      PacketsServiced++;
+
+      TxFrameStatus=CB_OWNERSHIP_BIT;
+      /* set the first(SOP) pointer for the next packet */
+      FirstTcbProcessed = CurrentTcb;
+      if (CurrentTcb)
+        {
+         osfuncDataCacheHitInvalidate((void *)CurrentTcb, 16);
+         TxFrameStatus=CurrentTcb->mode;
+        }
+
+      }while(((TxFrameStatus&CB_OWNERSHIP_BIT)==0)
+             &&(PacketsServiced<TxServiceMax));
+
+    if (((TxFrameStatus&CB_OWNERSHIP_BIT)==0)
+             &&(PacketsServiced==TxServiceMax))
+      {
+       *MoreWork = 1;
+      }
+     else
+      {
+       *MoreWork = 0;
+      }
+    }
+    OsFunc->CriticalOff(); 
+
+  return(EC_NO_ERRORS);
+  }
+
+/**
+ *  @ingroup CPHAL_Functions
+ *  This function performs a teardown for the given channel.  The value of the
+ *  Mode parameter controls the operation of the function, as documented below.
+ *
+ *  Note: If bit 3 of Mode is set, this call is blocking, and will not return
+ *  until the teardown interrupt has occurred and been processed. While waiting
+ *  for a blocking teardown to complete, ChannelTeardown() will signal the OS
+ *  (via Control(.."Sleep"..)) to allow the OS to perform other tasks if
+ *  necessary.  If and only if bit 3 of Mode is clear, the CPHAL will call the
+ *  OS TeardownComplete() function to indicate that the teardown has completed.
+ *
+ *  @param   HalDev  CPHAL module instance. (set by xxxInitModule())
+ *  @param   Ch      Channel number.
+ *  @param   Mode    Bit 0 (LSB): Perform Tx teardown (if set).<BR>
+ *                   Bit 1: Perform Rx teardown (if set). <BR>
+ *                   Bit 2: If set, perform full teardown (free buffers/descriptors).
+ *                          If clear, perform partial teardown (keep buffers). <BR>
+ *                   Bit 3 (MSB): If set, call is blocking.
+ *                            If clear, call is non-blocking.
+ *
+ *  @return  EC_NO_ERRORS (ok). <BR>
+ *           Possible Error Codes:<BR>
+ *           @ref EC_VAL_INVALID_STATE "EC_VAL_INVALID_STATE"<BR>
+ *           @ref EC_VAL_INVALID_CH "EC_VAL_INVALID_CH"<BR>
+ *           @ref EC_VAL_TX_TEARDOWN_ALREADY_PEND "EC_VAL_TX_TEARDOWN_ALREADY_PEND"<BR>
+ *           @ref EC_VAL_RX_TEARDOWN_ALREADY_PEND "EC_VAL_RX_TEARDOWN_ALREADY_PEND"<BR>
+ *           @ref EC_VAL_TX_CH_ALREADY_TORNDOWN "EC_VAL_TX_CH_ALREADY_TORNDOWN"<BR>
+ *           @ref EC_VAL_RX_CH_ALREADY_TORNDOWN "EC_VAL_RX_CH_ALREADY_TORNDOWN"<BR>
+ *           @ref EC_VAL_TX_TEARDOWN_TIMEOUT "EC_VAL_TX_TEARDOWN_TIMEOUT"<BR>
+ *           @ref EC_VAL_RX_TEARDOWN_TIMEOUT "EC_VAL_RX_TEARDOWN_TIMEOUT"<BR>
+ *           @ref EC_VAL_LUT_NOT_READY "EC_VAL_LUT_NOT_READY"<BR>
+ */
+static int halChannelTeardown(HAL_DEVICE *HalDev, int Ch, bit32 Mode)
+  {
+   int DoTx, DoRx, Sleep=2048, timeout=0;                         /*MJH~030306*/
+   bit32u base = HalDev->dev_base;
+
+/* Set the module, used for error returns */
+
+   DoTx = (Mode & TX_TEARDOWN);
+   DoRx = (Mode & RX_TEARDOWN);
+
+   if (HalDev->State < enInitialized)
+     return(EC_CPMAC |EC_FUNC_CHTEARDOWN|EC_VAL_INVALID_STATE);
+
+   if ((Ch < 0) || (Ch > (MAX_CHAN-1) ))
+     {
+     return(EC_CPMAC |EC_FUNC_CHTEARDOWN|EC_VAL_INVALID_CH);
+     }
+
+   /* set teardown pending bits before performing the teardown, because they
+      will be used in the int handler (this is done for AAL5) */
+   if (DoTx)
+     {
+      if (HalDev->TxTeardownPending[Ch] != 0)
+        return(EC_CPMAC |EC_FUNC_CHTEARDOWN|EC_VAL_TX_TEARDOWN_ALREADY_PEND);
+
+      /* If a full teardown, this also means that the user must
+      setup all channels again to use them */
+      if (Mode & FULL_TEARDOWN)
+        HalDev->ChIsSetup[Ch][DIRECTION_TX] = 0;
+
+      if (HalDev->State < enOpened)
+        {
+         /* if the hardware has never been opened, the channel has never actually
+         been setup in the hardware, so I just need to reset the software flag
+         and leave */
+         HalDev->ChIsSetup[Ch][DIRECTION_TX] = 0;
+         return (EC_NO_ERRORS);
+    }
+       else
+    {
+         if (HalDev->ChIsOpen[Ch][DIRECTION_TX] == 0)
+       {
+            return(EC_CPMAC |EC_FUNC_CHTEARDOWN|EC_VAL_TX_CH_ALREADY_TORNDOWN);
+       }
+
+         /* set teardown flag */
+         HalDev->TxTeardownPending[Ch] = Mode;
+    }
+     }
+
+   if (DoRx)
+     {
+      if (HalDev->RxTeardownPending[Ch] != 0)
+        return(EC_CPMAC |EC_FUNC_CHTEARDOWN|EC_VAL_RX_TEARDOWN_ALREADY_PEND);
+
+      if (Mode & FULL_TEARDOWN)
+        HalDev->ChIsSetup[Ch][DIRECTION_RX] = 0;
+
+      if (HalDev->State < enOpened)
+        {
+         HalDev->ChIsSetup[Ch][DIRECTION_RX] = 0;
+         return (EC_NO_ERRORS);
+    }
+       else
+    {
+         if (HalDev->ChIsOpen[Ch][DIRECTION_RX] == 0)
+           return(EC_CPMAC |EC_FUNC_CHTEARDOWN|EC_VAL_RX_CH_ALREADY_TORNDOWN);
+
+         HalDev->RxTeardownPending[Ch] = Mode;
+    }
+     }
+
+   /* Perform Tx Teardown Duties */
+   if ((DoTx) && (HalDev->State == enOpened))
+     {
+      /* Request TX channel teardown */
+      (CPMAC_TX_TEARDOWN( base ))  = Ch;
+
+      /* wait until teardown has completed */
+      if (Mode & BLOCKING_TEARDOWN)
+        {
+     timeout = 0;
+         while (HalDev->ChIsOpen[Ch][DIRECTION_TX] == TRUE)
+       {
+            osfuncSleep(&Sleep);
+
+            timeout++;
+        if (timeout > 100000)
+          {
+               return(EC_CPMAC |EC_FUNC_CHTEARDOWN|EC_VAL_TX_TEARDOWN_TIMEOUT);
+          }
+       }
+    }
+     } /* if DoTx */
+
+   /* Perform Rx Teardown Duties */
+   if ((DoRx) && (HalDev->State == enOpened))
+     {
+
+      /* perform CPMAC specific RX channel teardown */
+      CPMAC_RX_TEARDOWN(base) = Ch;
+
+      if (Mode & BLOCKING_TEARDOWN)
+        {
+     timeout = 0;
+         while (HalDev->ChIsOpen[Ch][DIRECTION_RX] == TRUE)
+       {
+            osfuncSleep(&Sleep);
+
+            timeout++;
+        if (timeout > 100000)
+          {
+               return(EC_CPMAC |EC_FUNC_CHTEARDOWN|EC_VAL_RX_TEARDOWN_TIMEOUT);
+          }
+       }
+        }
+     } /* if DoRx */
+
+   return (EC_NO_ERRORS);
+  }
+
+/**
+ *  @ingroup CPHAL_Functions
+ *  This function closes the CPHAL module.  The module will be reset.
+ *  The Mode parameter should be used to determine the actions taken by
+ *  Close().
+ *
+ *  @param   HalDev   CPHAL module instance. (set by xxxInitModule())
+ *  @param   Mode     Indicates actions to take on close.  The following integer
+ *                    values are valid: <BR>
+ *                    1:  Does not free buffer resources, init parameters remain
+ *                        intact.  User can then call Open() without calling Init()
+ *                        to attempt to reset the device and bring it back to the
+ *                        last known state.<BR>
+ *                    2:  Frees the buffer resources, but keeps init parameters.  This
+ *                        option is a more aggressive means of attempting a device reset.
+ *                    3:  Frees the buffer resources, and clears all init parameters. <BR>
+ *                        At this point, the caller would have to call to completely
+ *                        reinitialize the device (Init()) before being able to call
+ *                        Open().  Use this mode if you are shutting down the module
+ *                        and do not plan to restart.
+ *
+ *  @return  EC_NO_ERRORS (ok).<BR>
+ *           Possible Error Codes:<BR>
+ *           @ref EC_VAL_INVALID_STATE "EC_VAL_INVALID_STATE"<BR>
+ *           Any error code from halChannelTeardown().<BR>
+ */
+static int halClose(HAL_DEVICE *HalDev, bit32 Mode)
+  {
+   int Ch, Inst, Ret;
+   OS_DEVICE *TmpOsDev;
+   OS_FUNCTIONS *TmpOsFunc;
+   HAL_FUNCTIONS *TmpHalFunc;
+   char *TmpDeviceInfo;
+
+   int Ticks;                                                     /*MJH~030306*/
+
+   /* Verify proper device state */
+   if (HalDev->State != enOpened)
+     return (EC_CPMAC  | EC_FUNC_CLOSE|EC_VAL_INVALID_STATE);
+
+   /* Teardown all open channels */
+   for (Ch = 0; Ch <= (MAX_CHAN-1) ; Ch++)
+     {
+      if (HalDev->ChIsOpen[Ch][DIRECTION_TX] == TRUE)
+        {
+         if (Mode == 1)
+           {
+            Ret = halChannelTeardown(HalDev, Ch, TX_TEARDOWN | PARTIAL_TEARDOWN | BLOCKING_TEARDOWN);
+            if (Ret) return (Ret);
+           }
+          else
+           {
+            Ret = halChannelTeardown(HalDev, Ch, TX_TEARDOWN | FULL_TEARDOWN | BLOCKING_TEARDOWN);
+            if (Ret) return (Ret);
+           }
+        }
+
+      if (HalDev->ChIsOpen[Ch][DIRECTION_RX] == TRUE)
+        {
+         if (Mode == 1)
+           {
+            Ret = halChannelTeardown(HalDev, Ch, RX_TEARDOWN | PARTIAL_TEARDOWN | BLOCKING_TEARDOWN);
+            if (Ret) return (Ret);
+           }
+          else
+           {
+            Ret = halChannelTeardown(HalDev, Ch, RX_TEARDOWN | FULL_TEARDOWN | BLOCKING_TEARDOWN);
+            if (Ret) return (Ret);
+           }
+        }
+     }
+
+   /* free fraglist in HalDev */
+   HalDev->OsFunc->Free(HalDev->fraglist);
+   HalDev->fraglist = 0;
+
+   /* unregister the interrupt */
+   HalDev->OsFunc->IsrUnRegister(HalDev->OsDev, HalDev->interrupt);
+
+   Ticks = 0;    /* Disable Tick Timer */                           /*MJH+030306*/
+   HalDev->OsFunc->Control(HalDev->OsDev, hcTick, hcClear, &Ticks); /*MJH+030306*/
+
+   /* Free the Phy Information Structure */
+   if(HalDev->PhyDev)
+   {
+      HalDev->OsFunc->Free(HalDev->PhyDev);                               /*MJH+030513*/
+      HalDev->PhyDev = 0;                                         /*MJH+030522*/
+   }
+
+   /* Perform CPMAC specific closing functions */
+   CPMAC_MACCONTROL(HalDev->dev_base) &= ~MII_EN;
+   CPMAC_TX_CONTROL(HalDev->dev_base) &= ~TX_EN;
+   CPMAC_RX_CONTROL(HalDev->dev_base) &= ~RX_EN;
+
+   /* put device back into reset */
+   (*(volatile bit32u *)(HalDev->ResetBase)) &=~ (1<<HalDev->ResetBit);
+   Ticks = 64;                                                    /*MJH~030306*/
+   osfuncSleep(&Ticks);
+
+   /* If mode is 3, than clear the HalDev and set next state to DevFound*/
+   if (Mode == 3)
+     {
+      /* I need to keep the HalDev parameters that were setup in InitModule */
+      TmpOsDev = HalDev->OsDev;
+      TmpOsFunc = HalDev->OsFunc;
+      TmpDeviceInfo = HalDev->DeviceInfo;
+
+      TmpHalFunc = HalDev->HalFuncPtr;
+      Inst = HalDev->Inst;
+
+      /* Clear HalDev */
+
+      HalDev->OsFunc->Memset(HalDev, 0, sizeof(HAL_DEVICE));
+
+      /* Restore key parameters */
+      HalDev->OsDev = TmpOsDev;
+      HalDev->OsFunc = TmpOsFunc;
+      HalDev->DeviceInfo = TmpDeviceInfo;
+
+      HalDev->HalFuncPtr = TmpHalFunc;
+      HalDev->Inst = Inst;
+
+      HalDev->State = enDevFound;
+     }
+    else
+     {
+      HalDev->State = enInitialized;
+     }
+
+   return(EC_NO_ERRORS);
+  }
diff -urN linux.old/drivers/net/avalanche_cpmac/cpremap_cpmac.c linux.dev/drivers/net/avalanche_cpmac/cpremap_cpmac.c
--- linux.old/drivers/net/avalanche_cpmac/cpremap_cpmac.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpremap_cpmac.c	2005-07-12 02:48:42.049593000 +0200
@@ -0,0 +1,28 @@
+#ifndef _INC_CPREMAP_C
+#define _INC_CPREMAP_C
+
+#ifdef __ADAM2
+static inline void osfuncDataCacheHitInvalidate(void *ptr, int Size)
+  {
+  asm(" cache  17, (%0)" : : "r" (ptr));
+  }
+
+static inline void osfuncDataCacheHitWriteback(void *ptr, int Size)
+  { 
+  asm(" cache  25, (%0)" : : "r" (ptr));
+  }
+  
+static inline void osfuncDataCacheHitWritebackAndInvalidate(void *ptr, int Size)
+  { 
+  asm(" cache  21, (%0)" : : "r" (ptr));
+  }
+
+#else
+
+#define osfuncDataCacheHitInvalidate(MemPtr, Size)               __asm__(" .set mips3; cache  17, (%0); .set mips0" : : "r" (MemPtr))
+#define osfuncDataCacheHitWritebackAndInvalidate(MemPtr, Size)   __asm__(" .set mips3; cache  21, (%0); .set mips0" : : "r" (MemPtr))
+#define osfuncDataCacheHitWriteback(MemPtr, Size)                __asm__(" .set mips3; cache  25, (%0); .set mips0" : : "r" (MemPtr))      
+            
+#endif
+
+#endif
diff -urN linux.old/drivers/net/avalanche_cpmac/cpswhal_cpmac.h linux.dev/drivers/net/avalanche_cpmac/cpswhal_cpmac.h
--- linux.old/drivers/net/avalanche_cpmac/cpswhal_cpmac.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/cpswhal_cpmac.h	2005-07-12 02:48:42.050593000 +0200
@@ -0,0 +1,632 @@
+/************************************************************************
+ *  TNETDxxxx Software Support
+ *  Copyright (c) 2002 Texas Instruments Incorporated. All Rights Reserved.
+ *
+ *  FILE: cphal.h
+ *
+ *  DESCRIPTION:
+ *      User include file, contains data definitions shared between the CPHAL
+ *      and the upper-layer software.
+ *
+ *  HISTORY:
+ *      Date      Modifier  Ver    Notes
+ *      28Feb02   Greg      1.00   Original
+ *      06Mar02   Greg      1.01   Documentation enhanced
+ *      18Jul02   Greg      1.02   Many updates (OAM additions, general reorg)
+ *      22Nov02   Mick      RC2    Additions from Denis' input on Control
+ *
+ *  author  Greg Guyotte
+ *  version 1.02
+ *  date    18-Jul-2002
+ *****************************************************************************/
+#ifndef _INC_CPHAL_H
+#define _INC_CPHAL_H
+
+#ifdef _CPHAL_CPMAC
+#include "ec_errors_cpmac.h"
+#endif
+
+#ifdef _CPHAL_AAL5
+#include "ec_errors_cpaal5.h"
+#endif
+
+#ifdef _CPHAL_CPSAR
+#include "ec_errors_cpsar.h"
+#endif
+
+#ifdef _CPHAL_AAL2
+#include "ec_errors_cpaal2.h"
+#endif
+
+#ifndef __ADAM2
+typedef char           bit8;
+typedef short          bit16;
+typedef int            bit32;
+
+typedef unsigned char  bit8u;
+typedef unsigned short bit16u;
+typedef unsigned int   bit32u;
+
+/*
+typedef char           INT8;
+typedef short          INT16;
+typedef int            INT32;
+typedef unsigned char  UINT8;
+typedef unsigned short UINT16;
+typedef unsigned int   UINT32;
+*/
+/*typedef unsigned int   size_t;*/
+#endif
+
+#ifdef _CPHAL
+
+#ifndef TRUE
+#define TRUE (1==1)
+#endif
+
+#ifndef FALSE
+#define FALSE (1==2)
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#endif
+
+#define        VirtToPhys(a)                 (((int)a)&~0xe0000000)
+#define        VirtToVirtNoCache(a)          ((void*)((VirtToPhys(a))|0xa0000000))
+#define        VirtToVirtCache(a)            ((void*)((VirtToPhys(a))|0x80000000))
+#define        PhysToVirtNoCache(a)          ((void*)(((int)a)|0xa0000000))
+#define        PhysToVirtCache(a)            ((void*)(((int)a)|0x80000000))
+/*
+#define        DataCacheHitInvalidate(a)     {__asm__(" cache  17, (%0)" :   : "r" (a));}
+#define        DataCacheHitWriteback(a)      {__asm__(" cache  25, (%0)" :   : "r" (a));}
+*/
+
+#define PARTIAL 1     /**< Used in @c Close() and @c ChannelTeardown() */
+#define FULL 2        /**< Used in @c Close() and @c ChannelTeardown() */
+
+/* Channel Teardown Defines */
+#define RX_TEARDOWN 2
+#define TX_TEARDOWN 1
+#define BLOCKING_TEARDOWN 8
+#define FULL_TEARDOWN 4
+#define PARTIAL_TEARDOWN 0
+
+#define MAX_DIR 2
+#define DIRECTION_TX 0
+#define DIRECTION_RX 1
+#define TX_CH 0
+#define RX_CH 1
+#define HAL_ERROR_DEVICE_NOT_FOUND    1
+#define HAL_ERROR_FAILED_MALLOC       2
+#define HAL_ERROR_OSFUNC_SIZE         3
+#define HAL_DEFAULT  0xFFFFFFFF
+#define VALID(val)    (val!=HAL_DEFAULT)
+
+/*
+ERROR REPORTING
+
+HAL Module Codes.  Each HAL module reporting an error code
+should OR the error code with the respective Module error code
+from the list below.
+*/
+#define EC_AAL5                                EC_HAL|EC_DEV_AAL5
+#define EC_AAL2                                EC_HAL|EC_DEV_AAL2
+#define EC_CPSAR                               EC_HAL|EC_DEV_CPSAR
+#define EC_CPMAC                               EC_HAL|EC_DEV_CPMAC
+#define EC_VDMA                                EC_HAL|EC_DEV_VDMA
+#define EC_VLYNQ                               EC_HAL|EC_DEV_VLYNQ
+#define EC_CPPI                                EC_HAL|EC_DEV_CPPI
+
+/*
+HAL Function Codes.  Each HAL module reporting an error code
+should OR the error code with one of the function codes from
+the list below.
+*/
+#define EC_FUNC_HAL_INIT                       EC_FUNC(1)
+#define EC_FUNC_CHSETUP                        EC_FUNC(2)
+#define EC_FUNC_CHTEARDOWN                     EC_FUNC(3)
+#define EC_FUNC_RXRETURN                       EC_FUNC(4)
+#define EC_FUNC_SEND                           EC_FUNC(5)
+#define EC_FUNC_RXINT                          EC_FUNC(6)
+#define EC_FUNC_TXINT                          EC_FUNC(7)
+#define EC_FUNC_AAL2_VDMA                      EC_FUNC(8)
+#define EC_FUNC_OPTIONS                        EC_FUNC(9)
+#define EC_FUNC_PROBE                          EC_FUNC(10)
+#define EC_FUNC_OPEN                           EC_FUNC(11)
+#define EC_FUNC_CONTROL                        EC_FUNC(12)
+#define EC_FUNC_DEVICE_INT                     EC_FUNC(13)
+#define EC_FUNC_STATUS                         EC_FUNC(14)
+#define EC_FUNC_TICK                           EC_FUNC(15)
+#define EC_FUNC_CLOSE                          EC_FUNC(16)
+#define EC_FUNC_SHUTDOWN                       EC_FUNC(17)
+#define EC_FUNC_DEVICE_INT_ALT                 EC_FUNC(18) /* +GSG 030306 */
+
+/*
+HAL Error Codes.  The list below defines every type of error
+used in all HAL modules. DO NOT CHANGE THESE VALUES!  Add new
+values in integer order to the bottom of the list.
+*/
+#define EC_VAL_PDSP_LOAD_FAIL                 EC_ERR(0x01)|EC_CRITICAL
+#define EC_VAL_FIRMWARE_TOO_LARGE             EC_ERR(0x02)|EC_CRITICAL
+#define EC_VAL_DEVICE_NOT_FOUND               EC_ERR(0x03)|EC_CRITICAL
+#define EC_VAL_BASE_ADDR_NOT_FOUND            EC_ERR(0x04)|EC_CRITICAL
+#define EC_VAL_RESET_BIT_NOT_FOUND            EC_ERR(0x05)|EC_CRITICAL
+#define EC_VAL_CH_INFO_NOT_FOUND              EC_ERR(0x06)
+#define EC_VAL_RX_STATE_RAM_NOT_CLEARED       EC_ERR(0x07)|EC_CRITICAL
+#define EC_VAL_TX_STATE_RAM_NOT_CLEARED       EC_ERR(0x08)|EC_CRITICAL
+#define EC_VAL_MALLOC_DEV_FAILED              EC_ERR(0x09)
+#define EC_VAL_OS_VERSION_NOT_SUPPORTED       EC_ERR(0x0A)|EC_CRITICAL
+#define EC_VAL_CPSAR_VERSION_NOT_SUPPORTED    EC_ERR(0x0B)|EC_CRITICAL
+#define EC_VAL_NULL_CPSAR_DEV                 EC_ERR(0x0C)|EC_CRITICAL
+
+#define EC_VAL_LUT_NOT_READY                  EC_ERR(0x0D)
+#define EC_VAL_INVALID_CH                     EC_ERR(0x0E)
+#define EC_VAL_NULL_CH_STRUCT                 EC_ERR(0x0F)
+#define EC_VAL_RX_TEARDOWN_ALREADY_PEND       EC_ERR(0x10)
+#define EC_VAL_TX_TEARDOWN_ALREADY_PEND       EC_ERR(0x11)
+#define EC_VAL_RX_CH_ALREADY_TORNDOWN         EC_ERR(0x12)
+#define EC_VAL_TX_CH_ALREADY_TORNDOWN         EC_ERR(0x13)
+#define EC_VAL_TX_TEARDOWN_TIMEOUT            EC_ERR(0x14)
+#define EC_VAL_RX_TEARDOWN_TIMEOUT            EC_ERR(0x15)
+#define EC_VAL_CH_ALREADY_TORNDOWN            EC_ERR(0x16)
+#define EC_VAL_VC_SETUP_NOT_READY             EC_ERR(0x17)
+#define EC_VAL_VC_TEARDOWN_NOT_READY          EC_ERR(0x18)
+#define EC_VAL_INVALID_VC                     EC_ERR(0x19)
+#define EC_VAL_INVALID_LC                     EC_ERR(0x20)
+#define EC_VAL_INVALID_VDMA_CH                EC_ERR(0x21)
+#define EC_VAL_INVALID_CID                    EC_ERR(0x22)
+#define EC_VAL_INVALID_UUI                    EC_ERR(0x23)
+#define EC_VAL_INVALID_UUI_DISCARD            EC_ERR(0x24)
+#define EC_VAL_CH_ALREADY_OPEN                EC_ERR(0x25)
+
+#define EC_VAL_RCB_MALLOC_FAILED              EC_ERR(0x26)
+#define EC_VAL_RX_BUFFER_MALLOC_FAILED        EC_ERR(0x27)
+#define EC_VAL_OUT_OF_TCBS                    EC_ERR(0x28)
+#define EC_VAL_NO_TCBS                        EC_ERR(0x29)
+#define EC_VAL_NULL_RCB                       EC_ERR(0x30)|EC_CRITICAL
+#define EC_VAL_SOP_ERROR                      EC_ERR(0x31)|EC_CRITICAL
+#define EC_VAL_EOP_ERROR                      EC_ERR(0x32)|EC_CRITICAL
+#define EC_VAL_NULL_TCB                       EC_ERR(0x33)|EC_CRITICAL
+#define EC_VAL_CORRUPT_RCB_CHAIN              EC_ERR(0x34)|EC_CRITICAL
+#define EC_VAL_TCB_MALLOC_FAILED              EC_ERR(0x35)
+
+#define EC_VAL_DISABLE_POLLING_FAILED         EC_ERR(0x36)
+#define EC_VAL_KEY_NOT_FOUND                  EC_ERR(0x37)
+#define EC_VAL_MALLOC_FAILED                  EC_ERR(0x38)
+#define EC_VAL_RESET_BASE_NOT_FOUND           EC_ERR(0x39)|EC_CRITICAL
+#define EC_VAL_INVALID_STATE                  EC_ERR(0x40)
+#define EC_VAL_NO_TXH_WORK_TO_DO              EC_ERR(0x41)
+#define EC_VAL_NO_TXL_WORK_TO_DO              EC_ERR(0x42)
+#define EC_VAL_NO_RX_WORK_TO_DO               EC_ERR(0x43)
+#define EC_VAL_NOT_LINKED                     EC_ERR(0x44)
+#define EC_VAL_INTERRUPT_NOT_FOUND            EC_ERR(0x45)
+#define EC_VAL_OFFSET_NOT_FOUND               EC_ERR(0x46)
+#define EC_VAL_MODULE_ALREADY_CLOSED          EC_ERR(0x47)
+#define EC_VAL_MODULE_ALREADY_SHUTDOWN        EC_ERR(0x48)
+#define EC_VAL_ACTION_NOT_FOUND               EC_ERR(0x49)
+#define EC_VAL_RX_CH_ALREADY_SETUP            EC_ERR(0x50)
+#define EC_VAL_TX_CH_ALREADY_SETUP            EC_ERR(0x51)
+#define EC_VAL_RX_CH_ALREADY_OPEN             EC_ERR(0x52)
+#define EC_VAL_TX_CH_ALREADY_OPEN             EC_ERR(0x53)
+#define EC_VAL_CH_ALREADY_SETUP               EC_ERR(0x54)
+#define EC_VAL_RCB_NEEDS_BUFFER               EC_ERR(0x55) /* +GSG 030410 */
+#define EC_VAL_RCB_DROPPED                    EC_ERR(0x56) /* +GSG 030410 */
+#define EC_VAL_INVALID_VALUE                  EC_ERR(0x57)
+
+/**
+@defgroup shared_data Shared Data Structures
+
+The data structures documented here are shared by all modules.
+*/
+
+/**
+ *  @ingroup shared_data
+ *  This is the fragment list structure.  Each fragment list entry contains a
+ *  length and a data buffer.
+ */
+typedef struct
+  {
+   bit32u   len;    /**< Length of the fragment in bytes (lower 16 bits are valid).  For SOP, upper 16 bits is the buffer offset. */
+   void     *data;  /**< Pointer to fragment data. */
+   void     *OsInfo; /**< Pointer to OS defined data. */
+  }FRAGLIST;
+
+#if defined (_CPHAL_CPMAC)
+#define CB_PASSCRC_BIT     (1<<26)
+
+/* CPMAC CPHAL STATUS */
+#define CPMAC_STATUS_LINK               (1 << 0)
+#define CPMAC_STATUS_LINK_DUPLEX        (1 << 1)  /* 0 - HD, 1 - FD */
+#define CPMAC_STATUS_LINK_SPEED         (1 << 2)  /* 0 - 10, 1 - 100 */
+
+/*   ADAPTER CHECK Codes */
+
+#define CPMAC_STATUS_ADAPTER_CHECK             (1 << 7)
+#define CPMAC_STATUS_HOST_ERR_DIRECTION        (1 << 8)
+#define CPMAC_STATUS_HOST_ERR_CODE             (0xF << 9)
+#define CPMAC_STATUS_HOST_ERR_CH               (0x7 << 13)
+
+#define _CPMDIO_DISABLE                 (1 << 0)
+#define _CPMDIO_HD                      (1 << 1)
+#define _CPMDIO_FD                      (1 << 2)
+#define _CPMDIO_10                      (1 << 3)
+#define _CPMDIO_100                     (1 << 4)
+#define _CPMDIO_NEG_OFF                 (1 << 5)
+#define _CPMDIO_LOOPBK                  (1 << 16)
+#define _CPMDIO_AUTOMDIX                (1 << 17)   /* Bit 16 and above not used by MII register */
+#define _CPMDIO_NOPHY                   (1 << 20)
+#endif
+
+/**
+ *  @ingroup shared_data
+ *  Channel specific configuration information.  This structure should be
+ *  populated by upper-layer software prior to calling @c ChannelSetup().  Any
+ *  configuration item that can be changed on a per channel basis should
+ *  be represented here.  Each module may define this structure with additional
+ *  module-specific members.
+ */
+typedef struct
+  {
+   int Channel;        /**< Channel number. */
+   int Direction;      /**< DIRECTION_RX(1) or DIRECTION_TX(0). */
+   OS_SETUP *OsSetup;  /**< OS defined information associated with this channel. */
+
+#if defined(_CPHAL_AAL5) || defined (_CPHAL_CPSAR) || defined (_CPHAL_CPMAC)
+   int RxBufSize;      /**< Size (in bytes) for each Rx buffer.*/
+   int RxBufferOffset; /**< Number of bytes to offset rx data from start of buffer (must be less than buffer size). */
+   int RxNumBuffers;   /**< The number of Rx buffer descriptors to allocate for Ch. */
+   int RxServiceMax;   /**< Maximum number of packets to service at one time. */
+
+   int TxNumBuffers;   /**< The number of Tx buffer descriptors to allocate for Ch. */
+   int TxNumQueues;    /**< Number of Tx queues for this channel (1-2). Choosing 2 enables a low priority SAR queue. */
+   int TxServiceMax;   /**< Maximum number of packets to service at one time. */
+#endif
+
+#if defined(_CPHAL_AAL5) || defined(_CPHAL_CPSAR)
+   int CpcsUU;      /**< The 2-byte CPCS UU and CPI information. */
+   int Gfc;         /**< Generic Flow Control. */
+   int Clp;         /**< Cell Loss Priority. */
+   int Pti;         /**< Payload Type Indication. */
+#endif
+
+#if defined(_CPHAL_AAL2) || defined(_CPHAL_AAL5) || defined(_CPHAL_CPSAR)
+   int DaMask;      /**< Specifies whether credit issuance is paused when Tx data not available. */
+   int Priority;    /**< Priority bin this channel will be scheduled within. */
+   int PktType;     /**< 0=AAL5,1=Null AAL,2=OAM,3=Transparent,4=AAL2. */
+   int Vci;         /**< Virtual Channel Identifier. */
+   int Vpi;         /**< Virtual Path Identifier. */
+   int FwdUnkVc;    /**< Enables forwarding of unknown VCI/VPI cells to host. 1=enable, 0=disable. */
+
+   /* Tx VC State */
+   int TxVc_CellRate;  /**< Tx rate, set as clock ticks between transmissions (SCR for VBR, CBR for CBR). */
+   int TxVc_QosType;   /**< 0=CBR,1=VBR,2=UBR,3=UBRmcr. */
+   int TxVc_Mbs;       /**< Min Burst Size in cells.*/
+   int TxVc_Pcr;       /**< Peak Cell Rate for VBR in clock ticks between transmissions. */
+
+   bit32 TxVc_AtmHeader; /**< ATM Header placed on firmware gen'd OAM cells for this Tx Ch (must be big endian with 0 PTI). */
+   int TxVc_OamTc;     /**< TC Path to transmit OAM cells for TX connection (0,1). */
+   int TxVc_VpOffset;  /**< Offset to the OAM VP state table. */
+   /* Rx VC State */
+   int RxVc_OamCh;     /**< Ch to terminate rx'd OAM cells to be forwarded to the host. */
+   int RxVc_OamToHost; /**< 0=do not pass, 1=pass. */
+   bit32 RxVc_AtmHeader; /**< ATM Header placed on firmware gen'd OAM cells for this Rx conn (must be big endian with 0 PTI). */
+   int RxVc_OamTc;     /**< TC Path to transmit OAM cells for RX connection (0,1). */
+   int RxVc_VpOffset;  /**< Offset to the OAM VP state table. */
+   /* Tx VP State */
+   int TxVp_OamTc;     /**< TC Path to transmit OAM cells for TX VP connection (0,1). */
+   bit32 TxVp_AtmHeader; /**< ATM Header placed on firmware gen'd VP OAM cells for this Tx VP conn (must be big endian with 0 VCI). */
+   /* Rx VP State  */
+   int RxVp_OamCh;     /**< Ch to terminate rx'd OAM cells to be forwarded to the host. */
+   int RxVp_OamToHost; /**< 0=do not pass, 1=pass. */
+   bit32 RxVp_AtmHeader; /**< ATM Header placed on firmware gen'd OAM cells for this Rx VP conn (must be big endian with 0 VCI). */
+   int RxVp_OamTc;     /**< TC Path to transmit OAM cells for RX VP connection (0,1). */
+   int RxVp_OamVcList; /**< Indicates all VC channels associated with this VP channel (one-hot encoded). */
+#endif
+
+
+#ifdef _CPHAL_VDMAVT
+   bit32u RemFifoAddr; /* Mirror mode only. */
+   bit32u FifoAddr;
+   bit32  PollInt;
+   bit32  FifoSize;
+   int    Ready;
+#endif
+
+  }CHANNEL_INFO;
+
+/*
+ *  This structure contains each statistic value gathered by the CPHAL.
+ *  Applications may access statistics data by using the @c StatsGet() routine.
+ */
+/* STATS */
+#if defined(_CPHAL_AAL2) || defined(_CPHAL_AAL5) || defined(_CPHAL_CPSAR)
+typedef struct
+  {
+   bit32u CrcErrors[16];
+   bit32u LenErrors[16];
+   bit32u DmaLenErrors[16];
+   bit32u AbortErrors[16];
+   bit32u StarvErrors[16];
+   bit32u TxMisQCnt[16][2];
+   bit32u RxMisQCnt[16];
+   bit32u RxEOQCnt[16];
+   bit32u TxEOQCnt[16][2];
+   bit32u RxPacketsServiced[16];
+   bit32u TxPacketsServiced[16][2];
+   bit32u RxMaxServiced;
+   bit32u TxMaxServiced[16][2];
+   bit32u RxTotal;
+   bit32u TxTotal;
+  } STAT_INFO;
+#endif
+
+/*
+ *  VDMA Channel specific configuration information
+ */
+#ifdef _CPHAL_AAL2
+typedef struct
+  {
+   int Ch;           /**< Channel Number */
+   int RemoteEndian; /**< Endianness of remote VDMA-VT device */
+   int CpsSwap;      /**< When 0, octet 0 in CPS pkt located in LS byte of 16-bit word sent to rem VDMA device.  When 1, in MS byte. */
+  }VdmaChInfo;
+#endif
+
+#ifndef _CPHAL
+  typedef void HAL_DEVICE;
+  typedef void HAL_PRIVATE;
+  typedef void HAL_RCB;
+  typedef void HAL_RECEIVEINFO;
+#endif
+
+/**
+ *  @ingroup shared_data
+ *  The HAL_FUNCTIONS struct defines the function pointers used by upper layer
+ *  software.  The upper layer software receives these pointers through the
+ *  call to xxxInitModule().
+ */
+typedef struct
+  {
+  int  (*ChannelSetup)    (HAL_DEVICE *HalDev, CHANNEL_INFO *Channel, OS_SETUP *OsSetup);
+  int  (*ChannelTeardown) (HAL_DEVICE *HalDev, int Channel, int Mode);
+  int  (*Close)           (HAL_DEVICE *HalDev, int Mode);
+  int  (*Control)         (HAL_DEVICE *HalDev, const char *Key, const char *Action, void *Value);
+  int  (*Init)            (HAL_DEVICE *HalDev);
+  int  (*Open)            (HAL_DEVICE *HalDev);
+  int  (*PacketProcessEnd) (HAL_DEVICE *HalDev);
+  int  (*Probe)           (HAL_DEVICE *HalDev);
+  int  (*RxReturn)        (HAL_RECEIVEINFO *HalReceiveInfo, int StripFlag);
+  int  (*Send)            (HAL_DEVICE *HalDev, FRAGLIST *FragList, int FragCount, int PacketSize, OS_SENDINFO *OsSendInfo, bit32u Mode);
+  int  (*Shutdown)        (HAL_DEVICE *HalDev);
+  int  (*Tick)            (HAL_DEVICE *HalDev);
+
+#ifdef _CPHAL_AAL5
+  int  (*Kick) (HAL_DEVICE *HalDev, int Queue);
+  void (*OamFuncConfig)   (HAL_DEVICE *HalDev, unsigned int OamConfig);
+  void (*OamLoopbackConfig)   (HAL_DEVICE *HalDev, unsigned int OamConfig, unsigned int *LLID, unsigned int CorrelationTag);
+  volatile bit32u* (*RegAccess)(HAL_DEVICE *HalDev, bit32u RegOffset);
+  STAT_INFO*  (*StatsGetOld)(HAL_DEVICE *HalDev);
+#endif
+  } HAL_FUNCTIONS;
+
+/**
+ *  @ingroup shared_data
+ *  The OS_FUNCTIONS struct defines the function pointers for all upper layer
+ *  functions accessible to the CPHAL.  The upper layer software is responsible
+ *  for providing the correct OS-specific implementations for the following
+ *  functions. It is populated by calling InitModule() (done by the CPHAL in
+ *  xxxInitModule().
+ */
+typedef struct
+  {
+  int   (*Control)(OS_DEVICE *OsDev, const char *Key, const char *Action, void *Value);
+  void  (*CriticalOn)(void);
+  void  (*CriticalOff)(void);
+  void  (*DataCacheHitInvalidate)(void *MemPtr, int Size);
+  void  (*DataCacheHitWriteback)(void *MemPtr, int Size);
+  int   (*DeviceFindInfo)(int Inst, const char *DeviceName, void *DeviceInfo);
+  int   (*DeviceFindParmUint)(void *DeviceInfo, const char *Parm, bit32u *Value);
+  int   (*DeviceFindParmValue)(void *DeviceInfo, const char *Parm, void *Value);
+  void  (*Free)(void *MemPtr);
+  void  (*FreeRxBuffer)(OS_RECEIVEINFO *OsReceiveInfo, void *MemPtr);
+  void  (*FreeDev)(void *MemPtr);
+  void  (*FreeDmaXfer)(void *MemPtr);
+  void  (*IsrRegister)(OS_DEVICE *OsDev, int (*halISR)(HAL_DEVICE*, int*), int InterruptBit);
+  void  (*IsrUnRegister)(OS_DEVICE *OsDev, int InterruptBit);
+  void* (*Malloc)(bit32u size);
+  void* (*MallocDev)(bit32u Size);
+  void* (*MallocDmaXfer)(bit32u size, void *MemBase, bit32u MemRange);
+  void* (*MallocRxBuffer)(bit32u size, void *MemBase, bit32u MemRange,
+                       OS_SETUP *OsSetup, HAL_RECEIVEINFO *HalReceiveInfo,
+                       OS_RECEIVEINFO **OsReceiveInfo, OS_DEVICE *OsDev);
+  void* (*Memset)(void *Dest, int C, bit32u N);
+  int   (*Printf)(const char *Format, ...);
+  int   (*Receive)(OS_DEVICE *OsDev,FRAGLIST *FragList,bit32u FragCount,
+                 bit32u PacketSize,HAL_RECEIVEINFO *HalReceiveInfo, bit32u Mode);
+  int   (*SendComplete)(OS_SENDINFO *OsSendInfo);
+  int   (*Sprintf)(char *S, const char *Format, ...);
+  int   (*Strcmpi)(const char *Str1, const char *Str2);
+  unsigned int (*Strlen)(const char *S);
+  char* (*Strstr)(const char *S1, const char *S2);
+  unsigned long  (*Strtoul)(const char *Str, char **Endptr, int Base);
+  void  (*TeardownComplete)(OS_DEVICE *OsDev, int Ch, int Direction);
+  } OS_FUNCTIONS;
+
+/************** MODULE SPECIFIC STUFF BELOW **************/
+
+#ifdef _CPHAL_CPMAC
+
+/*
+int halCpmacInitModule(HAL_DEVICE **HalDev, OS_DEVICE *OsDev, HAL_FUNCTIONS *HalFunc, int (*osBridgeInitModule)(OS_FUNCTIONS *), void* (*osMallocDev) (bit32u), int *Size, int inst);
+*/
+
+int halCpmacInitModule(HAL_DEVICE **HalDev,
+                 OS_DEVICE *OsDev,
+                 HAL_FUNCTIONS **HalFunc,
+                 OS_FUNCTIONS *OsFunc,
+                 int OsFuncSize,
+                 int *HalFuncSize,
+                 int Inst);
+#endif
+
+#ifdef _CPHAL_AAL5
+/*
+ *  @ingroup shared_data
+ *  The AAL5_FUNCTIONS struct defines the AAL5 function pointers used by upper layer
+ *  software.  The upper layer software receives these pointers through the
+ *  call to cphalInitModule().
+ */
+/*
+typedef struct
+  {
+  int  (*ChannelSetup)(HAL_DEVICE *HalDev, CHANNEL_INFO *HalCh, OS_SETUP *OsSetup);
+  int  (*ChannelTeardown)(HAL_DEVICE *HalDev, int Ch, int Mode);
+  int  (*Close)(HAL_DEVICE *HalDev, int Mode);
+  int  (*Init)(HAL_DEVICE *HalDev);
+  int  (*ModeChange)(HAL_DEVICE *HalDev, char *DeviceParms);
+  int  (*Open)(HAL_DEVICE *HalDev);
+  int  (*InfoGet)(HAL_DEVICE *HalDev, int Key, void *Value);
+  int  (*Probe)(HAL_DEVICE *HalDev);
+  int  (*RxReturn)(HAL_RECEIVEINFO *HalReceiveInfo, int StripFlag);
+  int  (*Send)(HAL_DEVICE *HalDev,FRAGLIST *FragList,int FragCount,
+                 int PacketSize,OS_SENDINFO *OsSendInfo,int Ch, int Queue,
+                 bit32u Mode);
+  int  (*StatsClear)(HAL_DEVICE *HalDev);
+  STAT_INFO*  (*StatsGet)(HAL_DEVICE *HalDev);
+  int  (*Status)(HAL_DEVICE *HalDev);
+  void (*Tick)(HAL_DEVICE *HalDev);
+  int  (*Kick)(HAL_DEVICE *HalDev, int Queue);
+  volatile bit32u* (*RegAccess)(HAL_DEVICE *HalDev, bit32u RegOffset);
+  } AAL5_FUNCTIONS;
+*/
+
+int cpaal5InitModule(HAL_DEVICE **HalDev,
+                 OS_DEVICE *OsDev,
+                 HAL_FUNCTIONS **HalFunc,
+                 OS_FUNCTIONS *OsFunc,
+                 int OsFuncSize,
+                 int *HalFuncSize,
+                 int Inst);
+#endif
+
+#ifdef _CPHAL_AAL2
+/**
+ *  @ingroup shared_data
+ *  The AAL2_FUNCTIONS struct defines the AAL2 function pointers used by upper layer
+ *  software.  The upper layer software receives these pointers through the
+ *  call to cphalInitModule().
+ */
+typedef struct
+  {
+  int  (*ChannelSetup)(HAL_DEVICE *HalDev, CHANNEL_INFO *HalCh, OS_SETUP *OsSetup);
+  int  (*ChannelTeardown)(HAL_DEVICE *HalDev, int Ch, int Mode);
+  int  (*Close)(HAL_DEVICE *HalDev, int Mode);
+  int  (*Init)(HAL_DEVICE *HalDev);
+  int  (*ModeChange)(HAL_DEVICE *HalDev, char *DeviceParms);
+  int  (*Open)(HAL_DEVICE *HalDev);
+  int  (*OptionsGet)(HAL_DEVICE *HalDev, char *Key, bit32u *Value);
+  int  (*Probe)(HAL_DEVICE *HalDev);
+
+  int  (*StatsClear)(HAL_DEVICE *HalDev);
+  STAT_INFO*  (*StatsGet)(HAL_DEVICE *HalDev);
+  int  (*Status)(HAL_DEVICE *HalDev);
+  void (*Tick)(HAL_DEVICE *HalDev);
+  int  (*Aal2UuiMappingSetup)(HAL_DEVICE *HalDev, int VC, int UUI,
+                                    int VdmaCh, int UUIDiscard);
+  int  (*Aal2RxMappingSetup)(HAL_DEVICE *HalDev, int VC, int CID,
+                                   int LC);
+  int  (*Aal2TxMappingSetup)(HAL_DEVICE *HalDev, int VC, int LC, int VdmaCh);
+  int  (*Aal2VdmaChSetup)(HAL_DEVICE *HalDev, bit32u RemVdmaVtAddr,
+                               VdmaChInfo *VdmaCh);
+  volatile bit32u* (*RegAccess)(HAL_DEVICE *HalDev, bit32u RegOffset);
+  int  (*Aal2ModeChange)(HAL_DEVICE *HalDev, int Vc, int RxCrossMode,
+                           int RxMultiMode, int TxMultiMode, int SchedMode,
+                           int TcCh);
+  void (*Aal2VdmaEnable)(HAL_DEVICE *HalDev, int Ch);
+  int  (*Aal2VdmaDisable)(HAL_DEVICE *HalDev, int Ch);
+  } AAL2_FUNCTIONS;
+
+int cpaal2InitModule(HAL_DEVICE **HalDev,
+                 OS_DEVICE *OsDev,
+                 AAL2_FUNCTIONS **HalFunc,
+                 OS_FUNCTIONS *OsFunc,
+                 int OsFuncSize,
+                 int *HalFuncSize,
+                 int Inst);
+#endif
+
+#ifdef _CPHAL_VDMAVT
+/**
+ *  @ingroup shared_data
+ *  The VDMA_FUNCTIONS struct defines the HAL function pointers used by upper layer
+ *  software.  The upper layer software receives these pointers through the
+ *  call to InitModule().
+ *
+ *  Note that this list is still under definition.
+ */
+typedef struct
+  {
+  bit32  (*Init)( HAL_DEVICE *VdmaVtDev);
+    /*  bit32  (*SetupTxFifo)(HAL_DEVICE *VdmaVtDev, bit32u LclRem,
+                  bit32u Addr, bit32u Size, bit32u PollInt);
+    bit32  (*SetupRxFifo)(HAL_DEVICE *VdmaVtDev, bit32u LclRem,
+                  bit32u Addr, bit32u Size, bit32u PollInt); */
+  bit32  (*Tx)(HAL_DEVICE *VdmaVtDev);
+  bit32  (*Rx)(HAL_DEVICE *VdmaVtDev);
+  bit32  (*SetRemoteChannel)(HAL_DEVICE *VdmaVtDev, bit32u RemAddr,
+                         bit32u RemDevID);
+  bit32  (*ClearRxInt)(HAL_DEVICE *VdmaVtDev);
+  bit32  (*ClearTxInt)(HAL_DEVICE *VdmaVtDev);
+  bit32  (*Open)(HAL_DEVICE *VdmaVtDev);
+  bit32  (*Close)(HAL_DEVICE *VdmaVtDev);
+  int    (*Control)         (HAL_DEVICE *HalDev, const char *Key, const char *Action, void *Value);
+  int    (*ChannelSetup)(HAL_DEVICE *VdmaVtDev, CHANNEL_INFO *HalCh, OS_SETUP *OsSetup);
+  int    (*ChannelTeardown)(HAL_DEVICE *VdmaVtDev, int Ch, int Mode);
+  int    (*Send)(HAL_DEVICE *VdmaVtDev,FRAGLIST *FragList,int FragCount,
+                 int PacketSize,OS_SENDINFO *OsSendInfo,bit32u Mode);
+  } VDMA_FUNCTIONS;
+
+int VdmaInitModule(HAL_DEVICE **VdmaVt,
+                 OS_DEVICE *OsDev,
+                 VDMA_FUNCTIONS **VdmaVtFunc,
+                 OS_FUNCTIONS *OsFunc,
+                 int OsFuncSize,
+                 int *HalFuncSize,
+                 int Inst);
+#endif
+
+/*
+extern int cphalInitModule(MODULE_TYPE ModuleType, HAL_DEVICE **HalDev, OS_DEVICE *OsDev, HAL_FUNCTIONS *HalFunc,
+                      int (*osInitModule)(OS_FUNCTIONS *), void* (*osMallocDev)(bit32u),
+                      int *Size, int Inst);
+*/
+
+
+#ifdef _CPHAL_AAL5
+extern const char hcSarFrequency[];
+#endif
+
+#ifdef _CPHAL_CPMAC
+/* following will be common, once 'utl' added */
+extern const char hcClear[];
+extern const char hcGet[];
+extern const char hcSet[];
+extern const char hcTick[];
+
+extern const char hcCpuFrequency[];
+extern const char hcCpmacFrequency[];
+extern const char hcMdioBusFrequency[];
+extern const char hcMdioClockFrequency[];
+extern const char hcCpmacBase[];
+extern const char hcPhyNum[];
+extern const char hcSize[];
+extern const char hcCpmacSize[];
+extern const char hcPhyAccess[];
+extern const char hcMdixMask[];
+extern const char hcMdioMdixSwitch[];
+#endif
+
+#endif  /*  end of _INC_    */
diff -urN linux.old/drivers/net/avalanche_cpmac/dox_cpmac.h linux.dev/drivers/net/avalanche_cpmac/dox_cpmac.h
--- linux.old/drivers/net/avalanche_cpmac/dox_cpmac.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/dox_cpmac.h	2005-07-12 02:48:42.050593000 +0200
@@ -0,0 +1,842 @@
+/*****************************************************************************
+ *  TNETDxxxx Software Support
+ *  Copyright (c) 2002,2003 Texas Instruments Incorporated. All Rights Reserved.
+ *
+ *  FILE:
+ *
+ *  DESCRIPTION:
+ *      This file contains documentation for the CPMAC
+ *
+ *  HISTORY:
+ *  @author Michael Hanrahan/Greg Guyotte
+ *  @version 1.00
+ *  @date    03-Dec-2002
+ *****************************************************************************/
+#ifndef _DOX_CPMAC_H
+#define _DOX_CPMAC_H
+/**
+@page CPMAC_Implementation_Details Version
+
+@copydoc CPMAC_Version
+*/
+
+/**
+@page cpmac_intro Introduction
+
+The CPMAC implementation will support 8 channels for transmit and 8 channel for
+receive.  Each of the 8 transmit channels has 1 queue associated with it.  It is
+recommended that only 1 channel is used for @c Receive() per processor.
+*/
+
+/**
+@page cpmac_details API Implementation Details
+@par osReceive
+@p Mode parameter
+- The Upper 16 bits of Mode match Word 3 of the Rx Buffer Descriptor
+
+@par halSend
+@p Mode parameter
+-  Bits 0-7 contain the Channel Number
+-  Bits 8-25 are reserved
+-  Bit  26 - if 0, the CRC will be calculated, if 1 the CRC will be Passed
+-  Bits 27-31 : reserved
+@section cpmac_keys Control Keys
+
+@par StateChange
+CPHAL calls the OS when a state change is detected.
+OS should check the CPMAC Status. See the Control Key 'Status' for more details.
+
+@par Status
+OS calls the CPHAL to obtain Status information. The Returned status is as follows
+
+@par MaxFrags
+The OS may "Set" or "Get" this value.  This defines the maximum
+number of fragments that can be received by the CPMAC Rx port.  The default
+value for CPMAC is 2.  This provides enough space to receive a maximum
+length packet (1,518 bytes) with the default buffer size of 1518 and any
+amount of RxBufferOffset.  If the buffer size is configured to be smaller,
+the OS *MUST* modify this parameter according to the following formula:
+((System Max packet length)/(RxBufSize)) + 1.  (The extra 1 fragment is to
+allow for RxBufferOffset)
+
+@code
+// Following defined in "cpswhal_cpmac.h"
+// CPMAC CPHAL STATUS
+#define CPMAC_STATUS_LINK               (1 << 0)
+#define CPMAC_STATUS_LINK_DUPLEX        (1 << 1)  // 0 - HD, 1 - FD
+#define CPMAC_STATUS_LINK_SPEED         (1 << 2)  // 0 - 10, 1 - 100
+
+// ADAPTER CHECK Codes
+#define CPMAC_STATUS_ADAPTER_CHECK             (1 << 7)
+#define CPMAC_STATUS_HOST_ERR_DIRECTION        (1 << 8)    // 0 - Tx, 1 - Rx
+#define CPMAC_STATUS_HOST_ERR_CODE             (0xF << 9)  See CPMAC Guide
+#define CPMAC_STATUS_HOST_ERR_CH               (0x7 << 13) See CPMAC Guide
+@endcode
+
+@code
+void osStateChange(OS_DEVICE *OsDev)
+  {
+  int status;
+  OsDev->HalFunc->Control(OsDev->HalDev, "Status", hcGet, &status);
+  if(status & CPMAC_STATUS_ADAPTER_CHECK)
+    {
+    printf("[osStateChange[%d]]  HAL notified OS of AdapterCheck (Link Status 0x%08X)\n", OsDev->port, status);
+    adaptercheck(OsDev->port);
+    }
+  else
+    {
+    printf("[osStateChange[%d]]  HAL notified OS of State Change (Link Status %s)\n", OsDev->port, (status & CPMAC_STATUS_LINK) ? "Up" : "Down");
+    if(status & CPMAC_STATUS_LINK)
+      {
+      printf("Speed %s, Duplex %s\n",
+      status & CPMAC_STATUS_LINK_SPEED ? "100" : "10",
+      status & CPMAC_STATUS_LINK_DUPLEX ? "FD" : "HD");
+      }
+    }
+@endcode
+
+@par Tick
+     The CPHAL calls the OS to set the interval for calling halTick()<BR>
+     Note: Predefined value hcTick now recommended for use.
+@code
+***  Example Code ***
+
+*** CPHAL code ***
+int Ticks;
+HalDev->OsFunc->Control(HalDev->OsDev, hcTick, hcSet, &Ticks);
+
+*** OS code ***
+  ..
+  if(osStrcmpi(pszKey, hcTick) == 0)
+  {
+    if(osStrcmpi(pszAction, hcSet) == 0)
+    {
+      // Enable the Tick Interval
+      if(*(unsigned int *) ParmValue)
+        printf("osTickSet: Interval = %d ticks\n", Interval);
+    }
+    else
+    if(osStrcmpi(pszAction, hcClear) == 0)
+    {
+        // Request disabling of the Tick Timer, ParmValue is ignored
+    }
+  }
+@endcode
+
+@par The following information can be obtained by the OS via 'Get'
+
+- StatsDump : OS supplies pointer to an 36 element unsigned int array
+CPHAL will populate the array with the current Statistics values.<BR>
+Note: all hcXXXX values are predefined and should be used by the OS.
+
+- hcPhyNum : Returns the PHY number.
+- hcCpmacBase : Returns the base-address of the CPMAC device
+- hcCpmacSize : Returns size of the CPMAC memory map
+
+
+@par Phy Register Communication
+
+halControl() is used to read and write the Phy Registers via the key hcPhyAccess
+
+Both reading and writing the Phy registers involve setting the Value parameter of halControl()
+<BR>
+Value is a 32-bit value with bits partioned as follows
+<BR>
+
+   0 -  4  Phy Number   <BR>
+   5 -  9  Phy Register <BR>
+  10 - 15  reserved     <BR>
+  16 - 31  Data  (write only)
+<BR>
+
+
+<B>Reading the Phy register</B>
+
+@code
+    bit32u Value;
+    bit32u RegAddr;
+    bit32u PhyNum;
+    bit32u PhyRegisterData;
+
+    //  Read Phy 31, register 20
+
+    PhyNum  = 31;
+    RegAddr = 20;
+
+    Value = (RegAddr << 5);
+    Value |= (PhyNum & 0x1F);
+
+    rc  = HalFunc->Control(HalDev, hcPhyAccess, hcGet, (bit32u *) &Value)
+    If(rc == 0)
+    {
+        // Value is overwriten with the value in Register 20 of Phy number 31.
+        PhyRegisterData = Value;
+    }
+@endcode
+
+<B>Writing the Phy register</B>
+@code
+    bit32u Value;
+    bit32u RegAddr;
+    bit32u PhyNum;
+    bit32u PhyRegisterData;
+
+    //  Reset Phy 23
+
+    PhyNum  = 23;
+    RegAddr = 0;
+    PhyRegisterData = 0x8000;  // Reset bit set
+
+    Value = (RegAddr << 5);
+    Value |= (PhyNum & 0x1F);
+    Value |= (PhyRegisterData << 16);
+
+    rc  = HalFunc->Control(HalDev, hcPhyAccess, hcSet, (bit32u *) &Value)
+
+    // Check is reset if done
+
+    PhyNum  = 23;
+    RegAddr = 0;
+
+    Value = (RegAddr << 5);
+    Value |= (PhyNum & 0x1F);
+
+    rc  = HalFunc->Control(HalDev, hcPhyAccess, hcGet, (bit32u *) &Value)
+
+    If(rc == 0)
+    {
+        // Value is overwriten with the value in Register 0 of Phy number 23.
+        PhyRegisterData = Value;
+        if((PhyRegisterData & 0x8000) == 0)
+           ResetIsComplete;
+    }
+
+@endcode
+<B>
+*** Example Showing turning values off/on ***
+<BR>
+</B>
+
+@code
+
+int On=1;
+int Off=0;
+   # Turn On loopback
+   OsDev->HalFunc->Control(OsDev->HalDev, "CTRL_LOOPBACK", hcSet, (int*) &On);
+
+   #  Turn off RX Flow
+   OsDev->HalFunc->Control(OsDev->HalDev, "RX_FLOW_EN", hcSet, (int*) &Off);
+@endcode
+
+@par CPMAC Configurable Parameters
+
+- RX_PASS_CRC        : See MBP_Enable description
+- RX_QOS_EN          : See MBP_Enable description
+- RX_NO_CHAIN        : See MBP_Enable description
+- RX_CMF_EN          : See MBP_Enable description
+- RX_CSF_EN          : See MBP_Enable description
+- RX_CEF_EN          : See MBP_Enable description
+- RX_CAF_EN          : See MBP_Enable description
+- RX_PROM_CH         : See MBP_Enable description
+- RX_BROAD_EN        : See MBP_Enable description
+- RX_BROAD_CH        : See MBP_Enable description
+- RX_MULT_EN         : See MBP_Enable description
+- RX_MULT_CH         : See MBP_Enable description
+
+- TX_PTYPE           : See MacControl description
+- TX_PACE            : See MacControl description
+- TX_FLOW_EN         : See MacControl description
+- RX_FLOW_EN         : See MacControl description
+- CTRL_LOOPBACK      : See MacControl description
+
+- RX_MAXLEN          : See CPMAC Guide
+- RX_FILTERLOWTHRESH : See CPMAC Guide
+- RX0_FLOWTHRESH     : See CPMAC Guide
+- RX_UNICAST_SET     : See CPMAC Guide
+- RX_UNICAST_CLEAR   : See CPMAC Guide
+
+@par Multicast Support
+- RX_MULTI_ALL       : When used with hcSet, sets all the Hash Bits. When used
+with hcClear clears all the Hash Bits.
+- RX_MULTI_SINGLE    : When used with hcSet, adds the Hashed Mac Address. When used
+with hcClear deletes the Hashed Mac Address.
+Note: Support will be added to keep track of Single additions and deletions.
+
+@code
+*** Example Code ***
+
+*** OS code ***
+  bit8u  MacAddress[6];
+  MacAddress[0] = 0x80;
+  MacAddress[1] = 0x12;
+  MacAddress[2] = 0x34;
+  MacAddress[3] = 0x56;
+  MacAddress[4] = 0x78;
+  MacAddress[5] = 0x78;
+  OsDev->HalFunc->Control(OsDev->HalDev, "RX_MULTI_SINGLE", hcSet, (bit8u*) &MacAddress);
+  OsDev->HalFunc->Control(OsDev->HalDev, "RX_MULTI_SINGLE", hcClear, (bit8u*) &MacAddress);
+  OsDev->HalFunc->Control(OsDev->HalDev, "RX_MULTI_ALL", hcSet, NULL);
+  OsDev->HalFunc->Control(OsDev->HalDev, "RX_MULTI_ALL", hcClear, NULL);
+@endcode
+@par MdioConnect Fields
+<BR>
+- "MdioConnect"     : The OS can set the Phy connection using this key. The default connection is Auto-Negotiation ON, All modes possible.
+
+
+- _CPMDIO_HD       <----- Allow Half Duplex, default is 1 (On)
+- _CPMDIO_FD       <----- Allow Full Duplex, default is 1 (On)
+- _CPMDIO_10       <----- Allow 10  Mbs, default is 1 (On)
+- _CPMDIO_100      <----- Allow 100 Mbs, default is 1 (On)
+- _CPMDIO_NEG_OFF  <----- Turn off Auto Negotiation, default is 0 (Auto Neg is on)
+- _CPMDIO_NOPHY    <----- Set for use with Marvel-type switch, default is 0 (Phy present)
+- _CPMDIO_AUTOMDIX  <---- Enables Auto Mdix (in conjunction with MdixMask), default is 1 (On)
+
+Note: When _CPMDIO_NOPHY is set, CPMAC will report being linked at 100/FD. Reported PhyNum will be 0xFFFFFFFF
+
+@par Setting CPMAC for use with a Marvel-type Switch
+@code
+     bit32u MdioConnect;
+
+     MdioConnect = _CPMDIO_NOPHY;
+     OsDev->HalFunc->Control(OsDev->HalDev, "MdioConnect", hcSet, (bit32u*) &MdioConnect);
+@endcode
+
+@par OS Support for MDIO
+@p The OS will need to supply the following values which the CPHAL will request via halControl()
+<BR>
+- MdioBusFrequency : The frequency of the BUS that MDIO is on (requested via hcMdioBusFrequency)
+<BR>
+- MdioClockFrequency : The desired Clock Frequency that MDIO qill operate at (requested via hcMdioClockFrequency)
+*/
+
+/**
+@page cpmac_conf DeviceFindxxx() Parameters
+
+These are some of the parameters that the CPMAC will request via the DeviceFindxxx() functions -
+<BR>
+- "Mlink"    : bit mask indicating what link status method Phy is using. Default is MDIO state machine (0x0)
+- "PhyMask"  : bit mask indicating PhyNums used by this CPMAC (e.g 0x8000000, PhyNum is 31)
+- "MdixMask" : bit mask indicating which Phys support AutoMdix. Default is 0x0 (None)
+<BR>
+@par Example cpmac definition from the options.conf for the Sangam VDB
+<BR>
+- cpmac( id=eth0, base=0xA8610000, size=0x800, reset_bit=17, int_line=19, PhyMask=0x80000000, MLink=0, MdixMask=0 )
+*/
+
+/**
+@page auto_mdix Auto Mdix Support
+
+Auto Mdix selection is controlled by two elements in the CPMAC. First the OS can turn Auto Midx On or Off by the use of the
+MdioConnect field, _CPMDIO_AUTOMDIX. This is defaulted ON.  For actual Auto Mdix operation the Phy must also be Auto Mdix capable.
+This is specified by the DeviceFindxxx() field, "MdixMask" (supplied as the variable hcMdixMask).
+If both these fields are set then the CPMDIO state machine will be enabled for Auto Mdix checking.
+If a switch to MDI or MDIX mode is needed, the CPMAC will signal this to the OS via Control() using
+the hcMdioMdixSwitch key.
+
+@par OS example for responding to a Mdix Switch Request
+<BR>
+@code
+if(osStrcmpi(pszKey, hcMdioMdixSwitch) == 0)  // See if key is Mdix Switch Request
+  {
+      if(osStrcmpi(pszAction, hcSet) == 0)   // Only respond to Set requests
+      {
+
+          bit32u Mdix;
+
+          Mdix = *(bit32u *) ParmValue;     // Extract requested Mode
+                                            // 0 : MDI
+                                            // 1 : MDIX
+          if(Mdix)
+            osSetPhyIntoMdixMode();         // Device specific logic
+          else
+            osSetPhyIntoMdiMode();          // Device specific logic
+          rc = 0;                           // Set return code as Successfull
+      }
+@endcode
+*/
+
+/**
+@page cpmac_stats CPMAC Specific Statistics
+
+Statistics level '0' contains all CPMAC specific statistics.
+
+
+*/
+
+/**
+@page Example_Driver_Code
+
+@section  example_intro Introduction
+This section provides an in-depth code example for driver implementations.  The code
+below illustrates the use of the CPMAC HAL, but is equally applicable to any CPHAL
+implementation. Note: the CPHAl constants hcGet, hcSet etc., are currently available for use with teh CPMAC module.
+Other modules should continue to use pszGET, etc. until these are made generally available.
+
+@par Pull Model Example
+
+@code
+
+#define _CPHAL_CPMAC
+
+typedef struct _os_device_s  OS_DEVICE;
+typedef struct _os_receive_s OS_RECEIVEINFO;
+typedef struct _os_send_s    OS_SENDINFO;
+typedef struct _os_setup_s   OS_SETUP;
+
+#include "cpswhal_cpmac.h"
+
+#define dbgPrintf printf
+
+typedef struct  _os_device_s
+{
+   HAL_DEVICE    *HalDev;
+   HAL_FUNCTIONS *HalFunc;
+   OS_FUNCTIONS  *OsFunc;
+   OS_SETUP      *OsSetup;
+   bit32u        Interrupt;
+   int           (*halIsr)(HAL_DEVICE  *HalDev, int*);
+   int           ModulePort;
+   int           Protocol;
+   int           LinkStatus;  // 0-> down, otherwise up
+}os_device_s;
+
+typedef struct  _os_receive_s
+{
+   HAL_RECEIVEINFO *HalReceiveInfo;
+   char   *ReceiveBuffer;
+   OS_DEVICE  *OsDev;
+}os_receive_s;
+
+typedef struct  _os_send_s
+{
+   OS_DEVICE  *OsDev;
+}os_send_s;
+
+typedef struct  _os_setup_s
+{
+   OS_DEVICE  *OsDev;
+}os_setup_s;
+
+
+
+void FlowForCphal(OS_DEVICE *OsDev)
+{
+  CHANNEL_INFO ChannelInfo;
+  int nChannels = 200;
+  int halFuncSize;
+  int rc;
+
+  //  Populate OsFunc structure
+  rc =  osInitModule(OsDev);
+
+  if(rc)
+  {
+    sprintf(bufTmp, "%s: return code from osInitModule:'0x%08X'", __FUNCTION__, rc);
+    errorout(bufTmp);
+  }
+
+
+  //  OS-Cphal handshake
+  rc = halCpmacInitModule(&OsDev->HalDev, OsDev, &OsDev->HalFunc, OsDev->OsFunc,
+                              sizeof(OS_FUNCTIONS), &halFuncSize, OsDev->ModulePort);
+
+  if(rc)
+  {
+    sprintf(bufTmp, "%s: return code from halCpmacInitModule:'0x%08X'", __FUNCTION__, rc);
+    errorout(bufTmp);
+  }
+
+  // See if hardware module exists
+  rc = OsDev->HalFunc->Probe(OsDev->HalDev);
+
+  if(rc)
+  {
+    sprintf(bufTmp, "%s: return code from Probe:'0x%08X'", __FUNCTION__, rc);
+    errorout(bufTmp);
+  }
+
+  // Initialize hardware module
+  rc = OsDev->HalFunc->Init(OsDev->HalDev);
+
+  if(rc)
+  {
+    sprintf(bufTmp, "%s: return code from Init:'0x%08X'", __FUNCTION__, rc);
+    errorout(bufTmp);
+  }
+
+  // Setup Channel Information (Tranmsit, channel 0)
+  ChannelInfo.Channel      = 0;
+  ChannelInfo.Direction    = DIRECTION_TX;
+  ChannelInfo.TxNumBuffers = nChannels;
+  ChannelInfo.TxNumQueues  = 1;
+  ChannelInfo.TxServiceMax = nChannels/3;
+
+  rc = OsDev->HalFunc->ChannelSetup(OsDev->HalDev, &ChannelInfo, OsDev->OsSetup);
+
+  // Setup Channel Information (Receive, channel 0)
+  ChannelInfo.Channel        = 0;
+  ChannelInfo.Direction      = DIRECTION_RX;
+  ChannelInfo.RxBufSize      = 1518;
+  ChannelInfo.RxBufferOffset = 0;
+  ChannelInfo.RxNumBuffers   = 2*nChannels;
+  ChannelInfo.RxServiceMax   = nChannels/3;
+
+  rc = OsDev->HalFunc->ChannelSetup(OsDev->HalDev, &ChannelInfo, OsDev->OsSetup);
+
+  // Open the hardware module
+  rc = OsDev->HalFunc->Open(OsDev->HalDev);
+
+  // Module now ready to Send/Receive data
+}
+
+
+int osInitModule(OS_FUNCTIONS **pOsFunc)
+  {
+   OS_FUNCTIONS *OsFunc;
+
+   OsFunc = (OS_FUNCTIONS *) malloc(sizeof(OS_FUNCTIONS));
+   if (!OsFunc)
+     return (-1);
+
+   *pOsFunc = OsFunc;
+
+   OsFunc->CriticalOff               = osCriticalOff;
+   OsFunc->CriticalOn                = osCriticalOn;
+   OsFunc->DataCacheHitInvalidate    = osDataCacheHitInvalidate;
+   OsFunc->DataCacheHitWriteback     = osDataCacheHitWriteback;
+   OsFunc->DeviceFindInfo            = osDeviceFindInfo;
+   OsFunc->DeviceFindParmUint        = osDeviceFindParmUint;
+   OsFunc->DeviceFindParmValue       = osDeviceFindParmValue;
+   OsFunc->Free                      = osFree;
+   OsFunc->FreeDev                   = osFreeDev;
+   OsFunc->FreeDmaXfer               = osFreeDmaXfer;
+   OsFunc->FreeRxBuffer              = osFreeRxBuffer;
+   OsFunc->IsrRegister               = osIsrRegister;
+   OsFunc->IsrUnRegister             = osIsrUnRegister;
+   OsFunc->Malloc                    = osMalloc;
+   OsFunc->MallocDev                 = osMallocDev;
+   OsFunc->MallocDmaXfer             = osMallocDmaXfer;
+   OsFunc->MallocRxBuffer            = osMallocRxBuffer;
+
+
+   OsFunc->Memset                    = memset;
+   OsFunc->Printf                    = printf;
+   OsFunc->Sprintf                   = sprintf;
+   OsFunc->Strcmpi                   = osStrcmpi;
+   OsFunc->Strlen                    = strlen;
+   OsFunc->Strstr                    = strstr;
+   OsFunc->Strtoul                   = strtoul;
+
+   OsFunc->Control                   = osControl;
+   OsFunc->Receive                   = osReceive;
+   OsFunc->SendComplete              = osSendComplete;
+   OsFunc->TeardownComplete          = osTearDownComplete;
+
+   return(0);
+  }
+
+
+int osReceive(OS_DEVICE *OsDev,FRAGLIST *Fraglist,bit32u FragCount,bit32u PacketSize,HAL_RECEIVEINFO *halInfo, bit32u mode)
+  {
+  OS_RECEIVEINFO *skb = (OS_RECEIVEINFO *)Fraglist[0].OsInfo;
+  dcache_i((char *)Fraglist->data, Fraglist->len);
+  OsDev->HalFunc->RxReturn(halInfo,0);
+  return(0);
+  }
+
+int osSendComplete(OS_SENDINFO *skb)
+  {
+  return(0);
+  }
+
+
+static void *osMallocRxBuffer(bit32u Size,void *MemBase, bit32u MemRange,
+                              OS_SETUP *OsSetup, HAL_RECEIVEINFO *HalReceiveInfo,
+                              OS_RECEIVEINFO **OsReceiveInfo, OS_DEVICE *OsDev )
+  {
+   void *HalBuffer;
+   OS_RECEIVEINFO *OsPriv;
+
+   HalBuffer=malloc(Size);
+   if (!HalBuffer)
+     {
+      return(0);
+     }
+
+   // Malloc the OS block
+   *OsReceiveInfo = malloc(sizeof(OS_RECEIVEINFO));
+   if (!*OsReceiveInfo)
+     {
+      free(HalBuffer);
+      return(0);
+     }
+
+   // Initialize the new buffer descriptor
+   OsPriv                 = *OsReceiveInfo;
+   OsPriv->OsDev          =  OsDev;
+   OsPriv->ReceiveBuffer  =  HalBuffer;
+   OsPriv->HalReceiveInfo =  HalReceiveInfo;
+
+   return(HalBuffer);
+  }
+
+
+void SendBuffer(OS_DEVICE *OsDev, char *Buffer, int Size)
+{
+  FRAGLIST Fraglist;
+  bit32u FragCount;
+
+  tcb_pending++;
+  Fraglist.len  = Size;
+  Fraglist.data = (unsigned *) Buffer;
+  FragCount     = 1;
+  mode          = 0;   //  Channel 0
+
+  dcache_wb(Fraglist.data, Fraglist.len);
+  OsDev->HalFunc->Send(OsDev->HalDev, &Fraglist, FragCount, Size, (OS_SENDINFO *) Buffer, mode);
+}
+
+
+void osStateChange(OS_DEVICE *OsDev)
+  {
+  int status;
+  int LinkStatus;
+  OsDev->HalFunc->Control(OsDev->HalDev, "Status", hcGet, &status);
+  if(status & CPMAC_STATUS_ADAPTER_CHECK)
+    {
+    //  Adapter Check, take appropiate action
+    }
+  else
+    {
+    LinkStatus = status & CPMAC_STATUS_LINK;
+    if(LinkStatus != OsDev->LinkStatus)
+      {
+      dbgPrintf("\n%s:Link %s for inst %d Speed %s, Duplex %s\n",
+                 __FUNCTION__,
+                 LinkStatus ? "up" : "down",
+                 OsDev->ModulePort,
+                 status & CPMAC_STATUS_LINK_SPEED ? "100" : "10",
+                 status & CPMAC_STATUS_LINK_DUPLEX ? "FD" : "HD");
+      OsDev->LinkStatus = LinkStatus;
+      }
+    }
+  }
+
+
+int osControl(OS_DEVICE *OsDev, const char *pszKey, const char* pszAction, void *ParmValue)
+  {
+  int rc=-1;
+
+  if (osStrcmpi(pszKey, hcCpuFrequency) == 0)
+   {
+   if(osStrcmpi(pszAction, hcGet) == 0)
+     {
+     *(bit32u*) ParmValue = cpufreq;
+     rc = 0;
+     }
+   }
+  if (osStrcmpi(pszKey, hcMdioBusFrequency) == 0)
+   {
+   if(osStrcmpi(pszAction, hcGet) == 0)
+     {
+     *(bit32u *)ParmValue = MdioBusFrequency;
+     rc = 0;
+     }
+   }
+if (osStrcmpi(pszKey, hcMdioClockFrequency) == 0)
+   {
+   if(osStrcmpi(pszAction, hcGet) == 0)
+     {
+     *(bit32u *)ParmValue = MdioClockFrequency;
+     rc = 0;
+     }
+   }
+
+  if (osStrcmpi(pszKey, hcTick) == 0)
+   {
+   if(osStrcmpi(pszAction, hcSet) == 0)
+     {
+       osTickSetInterval(OsDev, *(unsigned int *) ParmValue);
+       rc = 0;
+     }
+   else
+   if(osStrcmpi(pszAction, hcClear) == 0)
+     {
+       osTickDisable(OsDev);
+       rc = 0;
+     }
+   }
+
+  if (osStrcmpi(pszKey, "SioFlush") == 0)
+    {
+       MySioFlush();
+       rc = 0;
+    }
+
+  if (osStrcmpi(pszKey, "StateChange") == 0)
+    {
+       osStateChange(OsDev);
+       rc = 0;
+    }
+
+  if (osStrcmpi(pszKey, "Sleep") == 0)
+    {
+       osSleep(*(int *)ParmValue);
+       rc = 0;
+    }
+  return(rc);
+  }
+
+@endcode
+
+
+@par Push Model Example (Currently Eswitch ONLY)
+
+@code
+
+typedef struct _os_device_s  OS_DEVICE;
+typedef struct _os_receive_s OS_RECEIVEINFO;
+typedef struct _os_send_s    OS_SENDINFO;
+typedef struct _os_setup_s   OS_SETUP;
+
+#include "cpswhal.h"          //Get glogal HAL stuff
+#include "cpswhaleswitch.h"   //Get device specific hal stuff
+
+
+typedef struct  _os_device_s
+{
+   HAL_DEVICE    *HalDev;
+   HAL_FUNCTIONS *HalFunc;
+   OS_FUNCTIONS  *OsFunc;
+   OS_SETUP      *OsSetup;
+   bit32u        Interrupt;
+   int           (*halIsr)(HAL_DEVICE  *HalDev, int*);
+   int           ModulePort;
+   int           Protocol;
+   int           LinkStatus;  // 0-> down, otherwise up
+}os_device_s;
+
+typedef struct  _os_receive_s
+{
+   HAL_RECEIVEINFO *HalReceiveInfo;
+   char   *ReceiveBuffer;
+   OS_DEVICE  *OsDev;
+}os_receive_s;
+
+typedef struct  _os_send_s
+{
+   OS_DEVICE  *OsDev;
+}os_send_s;
+
+typedef struct  _os_setup_s
+{
+   OS_DEVICE  *OsDev;
+}os_setup_s;
+
+
+
+void FlowForCphal(OS_DEVICE *OsDev)
+{
+CHANNEL_INFO ChannelInfo;
+  int nChannels = 200;
+  int halFuncSize;
+  int rc;
+
+  //  Populate OsFunc structure
+  rc =  osInitModule(OsDev);
+
+  if(rc)
+  {
+    sprintf(bufTmp, "%s: return code from osInitModule:'0x%08X'", __FUNCTION__, rc);
+    errorout(bufTmp);
+  }
+
+
+  //  OS-Cphal handshake
+  rc = cpswHalEswitchInitModule(&OsDev->HalDev, OsDev, &OsDev->HalFunc, OsDev->OsFunc,
+                              sizeof(OS_FUNCTIONS), &halFuncSize, OsDev->ModulePort);
+
+  if(rc)
+  {
+    sprintf(bufTmp, "%s: return code from cpswHalEswitchInitModule:'0x%08X'", __FUNCTION__, rc);
+    errorout(bufTmp);
+  }
+
+
+  ChannelInfo.Channel      = 7;
+  ChannelInfo.Direction    = DIRECTION_RX;
+  ChanInfo.Receive = osReceiveSS;         //  Specify function to receive data for this channel
+
+  rc = OsDev->HalFunc->ChannelSetup(OsDev->HalDev, &ChannelInfo, OsDev->OsSetup);
+
+  MyConfig.debug=0;
+  MyConfig.CpuFrequency = CpuFreq;
+  MyConfig.EswitchFrequency = EswitchFreq;
+  MyConfig.ResetBase  = 0xa8611600;
+  MyConfig.MacAddress = MacAddr;
+
+  MyConfig.EswitchResetBit= 27;
+  MyConfig.Cpmac0ResetBit = 17;
+  MyConfig.Cpmac1ResetBit = 21;
+  MyConfig.MdioResetBit   = 22;
+  MyConfig.Phy0ResetBit   = 26;
+  MyConfig.Phy1ResetBit   = 28;
+  MyConfig.HdmaResetBit   = 13;
+  MyConfig.Cpmac0IntBit   = 19;
+  MyConfig.Cpmac1IntBit   = 33;
+  MyConfig.EswitchIntBit  = 27;
+  MyConfig.EswitchBase    = 0xa8640000;
+  MyConfig.EswitchBufferSize     = 64;
+  MyConfig.EswitchHostBufCount   = 0;
+  MyConfig.EswitchDefaultCamSize = 64;
+  MyConfig.EswitchOverFlowCount  = 200;
+  MyConfig.EswitchOverFlowSize   = 256;
+
+
+
+
+  rc=EswitchConfig(HalDev,HalFunc,&MyConfig);
+
+
+  // Open the hardware module
+  rc = OsDev->HalFunc->Open(OsDev->HalDev);
+
+  // Module now ready to Send/Receive data
+}
+
+
+int EswitchConfig(HAL_DEVICE *HalDev, HAL_FUNCTIONS *HalFunc, ESWITCH_CONFIG *Config)
+{
+  bit32u sts;
+  sts = 0;
+
+  sts |= cpswhalPushBin(hcdebug, Config->debug);
+  sts |= cpswhalPushBin(hcCpuFrequency     , Config->CpuFrequency );
+  sts |= cpswhalPushBin(hcEswitchFrequency , Config->EswitchFrequency );
+  sts |= cpswhalPushBin(hcResetBase        , Config->ResetBase  );
+  sts |= cpswhalPushBin(hcMacAddress       , Config->MacAddress );
+  sts |= cpswhalPushBin(hcEswitchResetBit, Config->EswitchResetBit);
+  sts |= cpswhalPushBin(hcCpmac0ResetBit , Config->Cpmac0ResetBit );
+  sts |= cpswhalPushBin(hcCpmac1ResetBit , Config->Cpmac1ResetBit );
+  sts |= cpswhalPushBin(hcMdioResetBit   , Config->MdioResetBit   );
+  sts |= cpswhalPushBin(hcPhy0ResetBit   , Config->Phy0ResetBit   );
+  sts |= cpswhalPushBin(hcPhy1ResetBit   , Config->Phy1ResetBit   );
+  sts |= cpswhalPushBin(hcHdmaResetBit   , Config->HdmaResetBit   );
+  sts |= cpswhalPushBin(hcCpmac0IntBit   , Config->Cpmac0IntBit   );
+  sts |= cpswhalPushBin(hcCpmac1IntBit   , Config->Cpmac1IntBit   );
+  sts |= cpswhalPushBin(hcEswitchIntBit  , Config->EswitchIntBit  );
+  sts |= cpswhalPushBin(hcEswitchBase           , Config->EswitchBase    );
+  sts |= cpswhalPushBin(hcEswitchBufferSize     , Config->EswitchBufferSize     );
+  sts |= cpswhalPushBin(hcEswitchHostBufCount   , Config->EswitchHostBufCount   );
+  sts |= cpswhalPushBin(hcEswitchDefaultCamSize , Config->EswitchDefaultCamSize );
+  sts |= cpswhalPushBin(hcEswitchOverFlowCount  , Config->EswitchOverFlowCount  );
+  sts |= cpswhalPushBin(hcEswitchOverFlowSize   , Config->EswitchOverFlowSize   );
+  return(sts);
+}
+
+
+
+@endcode
+*/
+
+#endif
diff -urN linux.old/drivers/net/avalanche_cpmac/ec_errors_cpmac.h linux.dev/drivers/net/avalanche_cpmac/ec_errors_cpmac.h
--- linux.old/drivers/net/avalanche_cpmac/ec_errors_cpmac.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/ec_errors_cpmac.h	2005-07-12 02:48:42.051592000 +0200
@@ -0,0 +1,118 @@
+/***************************************************************************
+ Copyright(c) 2001, Texas Instruments Incorporated. All Rights Reserved.
+
+ FILE:  ec_errors.h
+
+ DESCRIPTION:
+   This file contains definitions and function declarations for
+   error code support.
+
+ HISTORY:
+   14Dec00 MJH             Added masking to EC_CLASS etc macros
+   17Sep02 GSG             Added HAL support (new class&devices)
+   03Oct02 GSG             Removed C++ style comments
+***************************************************************************/
+#ifndef _INC_EC_ERRORS
+#define _INC_EC_ERRORS
+
+/*
+  31    - CRITICAL
+  30-28 - CLASS         (ie. DIAG, KERNEL, FLASH, etc)
+  27-24 - INSTANCE      (ie. 1, 2, 3, etc )
+  23-16 - DEVICE        (ie. EMAC, IIC, etc)
+  15-08 - FUNCTION      (ie. RX, TX, INIT, etc)
+  07-00 - ERROR CODE    (ie. NO_BASE, FILE_NOT_FOUND, etc )
+*/
+
+/*---------------------------------------------------------------------------
+  Useful defines for accessing fields within error code
+---------------------------------------------------------------------------*/
+#define CRITICAL_SHIFT    31
+#define CLASS_SHIFT       28
+#define INST_SHIFT        24
+#define DEVICE_SHIFT      16
+#define FUNCTION_SHIFT     8
+#define ERROR_CODE_SHIFT   0
+
+#define CRITICAL_MASK     1
+#define CLASS_MASK        0x07
+#define DEVICE_MASK       0xFF
+#define INST_MASK         0x0F
+#define FUNCTION_MASK     0xFF
+#define ERROR_CODE_MASK   0xFF
+
+#define EC_CLASS(val)     ((val&CLASS_MASK)      << CLASS_SHIFT)
+#define EC_DEVICE(val)    ((val&DEVICE_MASK)     << DEVICE_SHIFT)
+#define EC_INST(val)      ((val&INST_MASK)       << INST_SHIFT)
+#define EC_FUNC(val)      ((val&FUNCTION_MASK)   << FUNCTION_SHIFT)
+#define EC_ERR(val)       ((val&ERROR_CODE_MASK) << ERROR_CODE_SHIFT)
+
+/*---------------------------------------------------------------------------
+   Operation classes
+---------------------------------------------------------------------------*/
+#define EC_HAL              EC_CLASS(0)
+#define EC_DIAG             EC_CLASS(8)
+
+/*---------------------------------------------------------------------------
+   Device types
+---------------------------------------------------------------------------*/
+#define EC_DEV_EMAC         EC_DEVICE(1)
+#define EC_DEV_IIC          EC_DEVICE(2)
+#define EC_DEV_RESET        EC_DEVICE(3)
+#define EC_DEV_ATMSAR       EC_DEVICE(4)
+#define EC_DEV_MEM          EC_DEVICE(5)
+#define EC_DEV_DES          EC_DEVICE(6)
+#define EC_DEV_DMA          EC_DEVICE(7)
+#define EC_DEV_DSP          EC_DEVICE(8)
+#define EC_DEV_TMR          EC_DEVICE(9)
+#define EC_DEV_WDT          EC_DEVICE(10)
+#define EC_DEV_DCL          EC_DEVICE(11)
+#define EC_DEV_BBIF         EC_DEVICE(12)
+#define EC_DEV_PCI              EC_DEVICE(13)
+#define EC_DEV_XBUS         EC_DEVICE(14)
+#define EC_DEV_DSLIF            EC_DEVICE(15)
+#define EC_DEV_USB                      EC_DEVICE(16)
+#define EC_DEV_CLKC                     EC_DEVICE(17)
+#define EC_DEV_RAPTOR       EC_DEVICE(18)
+#define EC_DEV_DSPC                     EC_DEVICE(19)
+#define EC_DEV_INTC                     EC_DEVICE(20)
+#define EC_DEV_GPIO                     EC_DEVICE(21)
+#define EC_DEV_BIST                     EC_DEVICE(22)
+#define EC_DEV_HDLC                     EC_DEVICE(23)
+#define EC_DEV_UART                     EC_DEVICE(24)
+#define EC_DEV_VOIC                     EC_DEVICE(25)
+/* 9.17.02 (new HAL modules) */
+#define EC_DEV_CPSAR        EC_DEVICE(0x1A)
+#define EC_DEV_AAL5         EC_DEVICE(0x1B)
+#define EC_DEV_AAL2         EC_DEVICE(0x1C)
+#define EC_DEV_CPMAC        EC_DEVICE(0x1D)
+#define EC_DEV_VDMA         EC_DEVICE(0x1E)
+#define EC_DEV_VLYNQ        EC_DEVICE(0x1F)
+#define EC_DEV_CPPI         EC_DEVICE(0x20)
+#define EC_DEV_CPMDIO       EC_DEVICE(0x21)
+
+/*---------------------------------------------------------------------------
+   Function types
+---------------------------------------------------------------------------*/
+#define EC_FUNC_READ_CONF   EC_FUNC(1)
+#define EC_FUNC_INIT        EC_FUNC(2)
+
+/*---------------------------------------------------------------------------
+   Error codes
+---------------------------------------------------------------------------*/
+#define EC_CRITICAL         (1<<CRITICAL_SHIFT)
+#define EC_NO_ERRORS        0
+#define EC_VAL_NO_BASE      EC_ERR(1)
+#define EC_VAL_NO_RESET_BIT EC_ERR(2)
+#define EC_VAL_NO_RESET     EC_ERR(3)
+#define EC_VAL_BAD_BASE     EC_ERR(4)
+#define EC_VAL_MALLOCFAILED EC_ERR(5)
+#define EC_VAL_NO_RESETBASE EC_ERR(6)
+#define EC_DEVICE_NOT_FOUND EC_ERR(7)
+
+/*---------------------------------------------------------------------------
+   Function declarations
+---------------------------------------------------------------------------*/
+extern void ec_log_error( unsigned int );
+
+#endif /* _INC_EC_ERRORS */
diff -urN linux.old/drivers/net/avalanche_cpmac/hcpmac.c linux.dev/drivers/net/avalanche_cpmac/hcpmac.c
--- linux.old/drivers/net/avalanche_cpmac/hcpmac.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/hcpmac.c	2005-07-12 02:48:42.174574000 +0200
@@ -0,0 +1,1878 @@
+/******************************************************************************
+ *  TNETDxxxx Software Support
+ *  Copyright (c) 2002-2004 Texas Instruments Incorporated. All Rights Reserved.
+ *
+ *  FILE:
+ *
+ *  DESCRIPTION:
+ *      This file contains the code for the HAL EMAC Bridge Test
+ *
+ *  HISTORY:
+ *  xxXxx01 Denis            RC1.00  Original Version created.
+ *  22Jan02 Denis/Mick       RC1.01  Modified for HAL EMAC API
+ *  24Jan02 Denis/Mick       RC1.02  Speed Improvements
+ *  28Jan02 Denis/Mick       RC1.16  Made function calls pointers
+ *  28Jan02 Mick             RC1.18  Split into separate modules
+ *  29Jan02 Mick             RC1.19  Hal include file cleaned up
+ *  15Jul02 Michael Hanrahan RC1.20  Synch'd with Linux Version
+ *  23Sep02 Michael Hanrahan RC1.21  Added CPPI.C
+ *  16Oct02 Michael Hanrahan RC1.22  Added CAF etc to Options.Conf
+ *  09Jan03 Michael Hanrahan RC3.01  Fixed incorrect MDIO check
+ *  01Feb03 Michael Hanrahan RC3.02  Updated for GPIO/PBUSFREQ
+ *  29Mar03 Michael Hanrahan 1.03 Corrected  ChannelConfigGet
+ *  29Mar03 Michael Hanrahan 1.03 Removed user setting of TxNumQueues
+ *  23Aug04 Michael Hanrahan 1.7.8 Support for Setting Mac Address
+ *  @author Michael Hanrahan
+ *  @version 1.02
+ *  @date    24-Jan-2002
+ *****************************************************************************/
+#define _HAL_CPMAC
+#define _CPHAL_CPMAC
+#define _CPHAL
+#define __CPHAL_CPMDIO
+
+#include "dox_cpmac.h"  /*  Documentation information */
+
+/*  OS Data Structure definitions  */
+
+typedef void OS_PRIVATE;
+typedef void OS_DEVICE;
+typedef void OS_SENDINFO;
+typedef void OS_RECEIVEINFO;
+typedef void OS_SETUP;
+
+/*  HAL Data Structure definitions  */
+
+typedef struct _phy_device PHY_DEVICE;
+typedef struct hal_device  HAL_DEVICE;
+typedef struct hal_private HAL_PRIVATE;
+typedef struct hal_private HAL_RECEIVEINFO;
+
+#include "cpcommon_cpmac.h"
+#include "cpswhal_cpmac.h"
+#include "cpmdio.h"
+#include "hcpmac.h"
+#include "cpmac_reg.h"
+
+
+#define EC_MODULE
+
+/* MDIO Clock Frequency Default Value */
+
+/* Rcb/Tcb Constants */
+
+#define CB_SOF_BIT         (1<<31)
+#define CB_EOF_BIT         (1<<30)
+#define CB_SOF_AND_EOF_BIT (CB_SOF_BIT|CB_EOF_BIT)
+#define CB_OWNERSHIP_BIT   (1<<29)
+#define CB_EOQ_BIT         (1<<28)
+#define CB_SIZE_MASK       0x0000ffff
+#define RCB_ERRORS_MASK    0x03fe0000
+
+static char *channel_names[]   = CHANNEL_NAMES; /* GSG 11/22 (may change this implementation) */
+
+#define scFound(Module) if (HalDev->State != enDevFound)    return (Module|EC_FUNC_CHSETUP|EC_VAL_INVALID_STATE)
+#define scInit(Module)  if (HalDev->State <  enInitialized) return (Module|EC_FUNC_CHSETUP|EC_VAL_INVALID_STATE)
+#define scOpen(Module)  if (HalDev->State <  enOpened)      return (Module|EC_FUNC_CHSETUP|EC_VAL_INVALID_STATE)
+
+
+
+/********************************************************************
+**
+**  L O C A L  F U N C T I O N S
+**
+********************************************************************/
+static int halIsr(HAL_DEVICE *HalDev, int *MorePackets);
+static int cpmacRandom(HAL_DEVICE *HalDev);
+static int cpmacRandomRange(HAL_DEVICE *HalDev, int min, int max);
+static int halPacketProcessEnd(HAL_DEVICE *HalDev);
+
+#include "cpcommon_cpmac.c"                                                /*~RC3.02*/
+#include "cppi_cpmac.c"
+#include "cpmdio.c"                                                  /*~RC3.02*/
+
+static int MacAddressSave(HAL_DEVICE *HalDev, unsigned char *MacAddr)
+  {
+  int i;
+  int inst             = HalDev->inst;
+
+  HalDev->MacAddr = MacAddr;
+
+  if(HalDev->debug)
+    {
+    dbgPrintf("MacAddrSave[%d]: ", inst);
+    for (i=0;i<6;i++)
+       dbgPrintf("%X", HalDev->MacAddr[i]);
+    dbgPrintf("\n");
+    osfuncSioFlush();
+    }
+  return(EC_NO_ERRORS);
+  }
+static int MacAddressSet(HAL_DEVICE *HalDev)
+  {
+  unsigned char *macadr = &HalDev->MacAddr[0];
+  int base             = HalDev->dev_base;
+
+  scOpen(EC_CPMAC);
+  CPMAC_MACADDRLO_0(base) = macadr[5];
+  CPMAC_MACADDRMID(base)  = macadr[4];
+  CPMAC_MACADDRHI(base)   = (macadr[0])|(macadr[1]<<8)|(macadr[2]<<16)|(macadr[3]<<24);
+  if(HalDev->debug)
+    {
+     dbgPrintf("MacAddrSet: MacAddr(%d) %X %X %X\n", HalDev->inst, CPMAC_MACADDRLO_0(base),
+                                                     CPMAC_MACADDRMID(base),
+                                                     CPMAC_MACADDRHI(base));
+
+     dbgPrintf("Start MAC: %d\n",HalDev->dev_base);
+     osfuncSioFlush();
+    }
+  return(EC_NO_ERRORS);
+  }
+
+
+/*
+  Updates the MacHash registers
+*/
+static void MacHashSet(HAL_DEVICE *HalDev)
+  {
+  if(HalDev->State <  enOpened)
+    return;
+
+  CPMAC_MACHASH1(HalDev->dev_base) = HalDev->MacHash1;
+  CPMAC_MACHASH2(HalDev->dev_base) = HalDev->MacHash2;
+  if (DBG(11))
+    dbgPrintf("CPMAC[%X]: MacHash1 0x%08X, MacHash2 0x%08X\n", HalDev->dev_base, CPMAC_MACHASH1(HalDev->dev_base), CPMAC_MACHASH2(HalDev->dev_base));
+  }
+
+/*
+  Reads the MacControl register and updates
+  the changable bits. (See MACCONTROL_MASK)
+*/
+static void RxMBP_EnableSet(HAL_DEVICE *HalDev)
+  {
+   bit32u RxMbpEnable;
+   if(HalDev->State <  enOpened)
+     return;
+   RxMbpEnable  = CPMAC_RX_MBP_ENABLE(HalDev->dev_base);
+   RxMbpEnable &= ~RX_MBP_ENABLE_MASK; /* Clear out updatable bits */
+   RxMbpEnable |= HalDev->RxMbpEnable;
+   CPMAC_RX_MBP_ENABLE(HalDev->dev_base) = RxMbpEnable;
+  }
+/*
+  Reads the MacControl register and updates
+  the changable bits. (See MACCONTROL_MASK)
+*/
+static void MacControlSet(HAL_DEVICE *HalDev)
+  {
+   bit32u MacControl;
+   if(HalDev->State <  enOpened)
+     return;
+   MacControl  = CPMAC_MACCONTROL(HalDev->dev_base);
+   MacControl &= ~MACCONTROL_MASK; /* Clear out updatable bits */
+   MacControl |= HalDev->MacControl;
+   if(!(MacControl & MII_EN)) /* If Enable is not set just update register  */
+      CPMAC_MACCONTROL(HalDev->dev_base) = MacControl;
+   else
+     {
+     if(MacControl & CTRL_LOOPBACK)    /*  Loopback Set  */
+       {
+       /* mii_en is set and loopback is needed,
+          clear mii_en, set loopback, then set mii_en
+       */
+       MacControl &= ~MII_EN;  /* Clear MII_EN  */
+       CPMAC_MACCONTROL(HalDev->dev_base) = MacControl;
+       CPMAC_MACCONTROL(HalDev->dev_base) |= MII_EN; /* Set MII_EN  */
+       HalDev->Linked = 1; /* if in loopback the logically linked */
+       }
+     else  /* If Loopback not set just update */
+       {
+       CPMAC_MACCONTROL(HalDev->dev_base) = MacControl;
+       }
+     }
+    if(DBG(0))
+      dbgPrintf("[halMacControlSet]MacControl:%08X\n", CPMAC_MACCONTROL(HalDev->dev_base));
+  }
+static int UnicastSet(HAL_DEVICE *HalDev)
+  {
+  CPMAC_RX_UNICAST_SET(HalDev->dev_base)    = HalDev->RxUnicastSet;
+  CPMAC_RX_UNICAST_CLEAR(HalDev->dev_base)  = HalDev->RxUnicastClear;
+  return(EC_NO_ERRORS);
+  }
+
+  
+static bit32u HashGet(bit8u *Address)
+  {
+  bit32u hash;
+    bit8u  tmpval;
+    int    i;
+
+    hash = 0;
+    for( i=0; i<2; i++ )
+    {
+        tmpval = *Address++;
+        hash  ^= (tmpval>>2)^(tmpval<<4);
+        tmpval = *Address++;
+        hash  ^= (tmpval>>4)^(tmpval<<2);
+        tmpval = *Address++;
+        hash  ^= (tmpval>>6)^(tmpval);
+    }
+
+    return( hash & 0x3F );
+  }
+
+static void HashAdd(HAL_DEVICE *HalDev, bit8u *MacAddress)
+{
+  bit32u HashValue;
+  bit32u HashBit;
+
+  HashValue = HashGet(MacAddress);
+
+  if(HashValue < 32)
+    {
+    HashBit = (1 << HashValue);
+    HalDev->MacHash1 |= HashBit;
+    }
+    else
+    {
+    HashBit = (1 << (HashValue-32));
+    HalDev->MacHash2 |= HashBit;
+    }
+}
+
+static void HashDel(HAL_DEVICE *HalDev, bit8u *MacAddress)
+{
+  bit32u HashValue;
+  bit32u HashBit;
+
+  HashValue = HashGet(MacAddress);
+
+  if(HashValue < 32)
+    {
+    HashBit = (1 << HashValue);
+    HalDev->MacHash1 &= ~HashBit;
+    }
+    else
+    {
+    HashBit = (1 << (HashValue-32));
+    HalDev->MacHash2 &= ~HashBit;
+    }
+}
+
+/*  Replace with an array based on key, with a ptr to the code to do */
+/* e.g.  [enRX_PASS_CRC] = {Set, MBP_UPDATE() } */
+static void DuplexUpdate(HAL_DEVICE *HalDev)
+{
+  int base           = HalDev->dev_base;
+  PHY_DEVICE *PhyDev = HalDev->PhyDev;
+
+  if(HalDev->State <  enOpened)
+    return;
+
+   /* No Phy Condition */
+   if(HalDev->MdioConnect & _CPMDIO_NOPHY)                        /*MJH+030805*/
+   {
+       /*  No Phy condition, always linked */
+       HalDev->Linked     = 1;
+       HalDev->EmacSpeed  = 1;
+       HalDev->EmacDuplex = 1;
+       HalDev->PhyNum     = 0xFFFFFFFF;  /* No Phy Num */
+       CPMAC_MACCONTROL(base) |= FULLDUPLEX;                      /*MJH+030909*/
+       osfuncStateChange();
+       return;
+   }
+
+  if(HalDev->MacControl & CTRL_LOOPBACK)    /*  Loopback Set  */
+    {
+    HalDev->Linked = 1;
+    return;
+    }
+
+  if (HalDev->MdioConnect & _CPMDIO_LOOPBK)
+    {
+    HalDev->Linked = cpMacMdioGetLoopback(HalDev->PhyDev);
+    }
+  else
+    {
+    HalDev->Linked = cpMacMdioGetLinked(HalDev->PhyDev);
+    }
+  if (HalDev->Linked)
+    {
+     /*  Retreive Duplex and Speed and the Phy Number  */
+     if(HalDev->MdioConnect & _CPMDIO_LOOPBK)
+       HalDev->EmacDuplex = 1;
+     else
+       HalDev->EmacDuplex = cpMacMdioGetDuplex(PhyDev);
+     HalDev->EmacSpeed  = cpMacMdioGetSpeed(PhyDev);
+     HalDev->PhyNum     = cpMacMdioGetPhyNum(PhyDev);
+
+     if(HalDev->EmacDuplex)
+       CPMAC_MACCONTROL(base) |= FULLDUPLEX;
+     else
+       CPMAC_MACCONTROL(base) &= ~FULLDUPLEX;
+     if(HalDev->debug)
+        dbgPrintf("%d: Phy= %d, Speed=%s, Duplex=%s\n",HalDev->inst,HalDev->PhyNum,(HalDev->EmacSpeed)?"100":"10",(HalDev->EmacDuplex)?"Full":"Half");
+    }
+  if(HalDev->debug)
+     dbgPrintf("DuplexUpdate[%d]: MACCONTROL 0x%08X, %s\n", HalDev->inst, CPMAC_MACCONTROL(base),(HalDev->Linked)?"Linked":"Not Linked");
+}
+static void MdioSetPhyMode(HAL_DEVICE *HalDev)
+  {
+  unsigned int PhyMode;
+  /* Verify proper device state */
+  if (HalDev->State < enOpened)
+    return;
+
+  PhyMode = NWAY_AUTO|NWAY_FD100|NWAY_HD100|NWAY_FD10|NWAY_HD10;
+  if(DBG(0))
+    {
+    dbgPrintf("halSetPhyMode1: MdioConnect:%08X ,", HalDev->MdioConnect);
+    dbgPrintf("PhyMode:%08X Auto:%d, FD10:%d, HD10:%d, FD100:%d, HD100:%d\n", PhyMode,
+           PhyMode&NWAY_AUTO, PhyMode&NWAY_FD10, PhyMode&NWAY_HD10, PhyMode&NWAY_FD100,
+           PhyMode&NWAY_HD100);
+    }
+
+
+  if (  HalDev->MdioConnect & _CPMDIO_NEG_OFF)  /* ~RC3.01                */
+    PhyMode &= ~(NWAY_AUTO);                    /* Disable Auto Neg       */
+  if (!(HalDev->MdioConnect & _CPMDIO_HD))
+    PhyMode &= ~(NWAY_HD100|NWAY_HD10);         /* Cannot support HD      */
+  if (!(HalDev->MdioConnect & _CPMDIO_FD))
+    PhyMode &= ~(NWAY_FD100|NWAY_FD10);         /* Cannot support FD      */
+  if (!(HalDev->MdioConnect & _CPMDIO_10))
+    PhyMode &= ~(NWAY_HD10|NWAY_FD10);          /* Cannot support 10 Mbs  */
+  if (!(HalDev->MdioConnect & _CPMDIO_100))
+    PhyMode &= ~(NWAY_HD100|NWAY_FD100);        /* Cannot support 100 Mbs */
+
+  if(HalDev->MdioConnect & _CPMDIO_AUTOMDIX)   PhyMode |= NWAY_AUTOMDIX; /* Set AutoMdix */
+
+  if (HalDev->CpmacFrequency <= 50000000)
+    PhyMode &= ~(NWAY_FD100|NWAY_HD100); /* Cannot support 100 MBS */
+  if(DBG(7))
+    dbgPrintf("halNeg: PhyMode[0x%08X] %d\n", HalDev->dev_base, PhyMode);
+
+  if(DBG(0))
+    {
+    dbgPrintf("halSetPhyMode2: MdioConnect:%08X ,", HalDev->MdioConnect);
+    dbgPrintf("PhyMode:%08X Auto:%d, FD10:%d, HD10:%d, FD100:%d, HD100:%d\n", PhyMode,
+               PhyMode&NWAY_AUTO, PhyMode&NWAY_FD10, PhyMode&NWAY_HD10, PhyMode&NWAY_FD100,
+               PhyMode&NWAY_HD100);
+    }
+
+
+  cpMacMdioSetPhyMode(HalDev->PhyDev,PhyMode);
+  DuplexUpdate(HalDev);
+  }
+static int StatsClear(HAL_DEVICE *HalDev)
+{
+  int i;
+  MEM_PTR pStats;
+
+  scOpen(EC_CPMAC);
+
+  pStats = pCPMAC_RXGOODFRAMES(HalDev->dev_base);
+  for (i=0;i<STATS_MAX;i++)
+    {
+    *(MEM_PTR)(pStats) =  0xFFFFFFFF;
+    pStats++;
+    }
+
+  return(EC_NO_ERRORS);
+}
+static void StatsDump(HAL_DEVICE *HalDev, void *Value)
+ {
+ MEM_PTR ptrStats;
+ MEM_PTR ptrValue;
+ int i;
+ ptrStats = pCPMAC_RXGOODFRAMES(HalDev->dev_base);
+ ptrValue = (bit32u*) Value;
+ for (i=0; i<STATS_MAX; i++)
+  {
+     *ptrValue = *ptrStats;
+     if(DBG(4))
+      {
+      dbgPrintf("halStatsDump: Stat[%d:0x%08X] %d 0x%08X %d\n", i, ptrStats, *ptrStats, ptrValue, *ptrValue);
+      osfuncSioFlush();
+      }
+     ptrStats++;
+     ptrValue++;
+  }
+ }
+static void ConfigApply(HAL_DEVICE *HalDev)
+  {
+  CPMAC_RX_MAXLEN(HalDev->dev_base)          = HalDev->RxMaxLen;
+  CPMAC_RX_FILTERLOWTHRESH(HalDev->dev_base) = HalDev->RxFilterLowThresh;
+  CPMAC_RX0_FLOWTHRESH(HalDev->dev_base)     = HalDev->Rx0FlowThresh;
+  UnicastSet(HalDev);
+  MacAddressSet(HalDev);
+  RxMBP_EnableSet(HalDev);
+  MacHashSet(HalDev);
+  MacControlSet(HalDev);
+  if(DBG(0))
+     dbgPrintf("ValuesUpdate[%d]: MBP_ENABLE 0x%08X\n", HalDev->inst, CPMAC_RX_MBP_ENABLE(HalDev->dev_base));
+  }
+static int halStatus(HAL_DEVICE *HalDev)
+{
+   int status;
+
+    if(HalDev->State <  enOpened)
+      return (EC_CPMAC|EC_FUNC_STATUS|EC_VAL_INVALID_STATE);      /*MJH+030805*/
+
+   /* No Phy Condition */
+   if(HalDev->MdioConnect & _CPMDIO_NOPHY)                        /*MJH+030805*/
+   {
+       /*  No Phy condition, always linked */
+       status = HalDev->Linked;
+       status |= CPMAC_STATUS_LINK_DUPLEX;
+       status |= CPMAC_STATUS_LINK_SPEED;
+       return(status);
+   }
+
+
+   if (HalDev->HostErr)  /* Adapter Check  */
+    {
+    bit32u tmp;
+    status = CPMAC_STATUS_ADAPTER_CHECK;
+    if(HalDev->MacStatus & RX_HOST_ERR_CODE)
+      {
+      status |= CPMAC_STATUS_HOST_ERR_DIRECTION;
+      tmp     = (HalDev->MacStatus & RX_HOST_ERR_CODE) >> 12; /* Code */
+      status |= (tmp << 9); /* Code */
+      tmp     = (HalDev->MacStatus & RX_ERR_CH) >> 8; /* Channel */
+      status |= (tmp << 13);
+      }
+    else
+    if(HalDev->MacStatus & TX_HOST_ERR_CODE)
+      {
+      status |= CPMAC_STATUS_HOST_ERR_DIRECTION;
+      tmp     = (HalDev->MacStatus & TX_HOST_ERR_CODE) >> 20; /* Code */
+      status |= (tmp << 9); /* Code */
+      tmp     = (HalDev->MacStatus & TX_ERR_CH) >> 16; /* Channel */
+      status |= (tmp << 13);
+      }
+    }
+   else
+    {
+    status = HalDev->Linked;
+    if(status)
+      {
+      status = CPMAC_STATUS_LINK;
+      if(cpMacMdioGetDuplex(HalDev->PhyDev))
+        status |= CPMAC_STATUS_LINK_DUPLEX;
+      if(cpMacMdioGetSpeed(HalDev->PhyDev))
+        status |= CPMAC_STATUS_LINK_SPEED;
+      }
+    }
+   if(HalDev->debug)
+      dbgPrintf("[halStatus] Link Status is %d for 0x%X\n", status, HalDev->dev_base);
+   return(status);
+}
+static int InfoAccess(HAL_DEVICE *HalDev, int Key, int Action, void *ParmValue)
+  {
+  int rc = 0;
+  int Update=0;
+
+  switch (Key)
+  {
+    /********************************************************************/
+    /*                                                                  */
+    /*                      GENERAL                                     */
+    /*                                                                  */
+    /********************************************************************/
+
+    case enVersion :
+         if(Action==enGET)
+           {
+           *(const char **)ParmValue = pszVersion_CPMAC;
+           }
+    break;
+    case enDebug  :
+         if(Action==enSET)
+           {
+           HalDev->debug = *(unsigned int *)ParmValue;
+           }
+    break;
+
+    case enStatus      :
+         if(Action==enGET)
+           {
+           int status;
+           status = halStatus(HalDev);
+           *(int *)ParmValue = status;
+           }
+    break;
+    /********************************************************************/
+    /*                                                                  */
+    /*                      RX_MBP_ENABLE                               */
+    /*                                                                  */
+    /********************************************************************/
+
+    case enRX_PASS_CRC  :
+         if(Action==enSET)
+           {
+           UPDATE_RX_PASS_CRC(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_QOS_EN  :
+         if(Action==enSET)
+           {
+           UPDATE_RX_QOS_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_NO_CHAIN :
+         if(Action==enSET)
+           {
+           UPDATE_RX_NO_CHAIN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_CMF_EN :
+         if(Action==enSET)
+           {
+           UPDATE_RX_CMF_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_CSF_EN :
+         if(Action==enSET)
+           {
+           UPDATE_RX_CSF_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_CEF_EN :
+         if(Action==enSET)
+           {
+           UPDATE_RX_CEF_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_CAF_EN :
+         if(Action==enSET)
+           {
+           UPDATE_RX_CAF_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_PROM_CH :
+         if(Action==enSET)
+           {
+           UPDATE_RX_PROM_CH(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_BROAD_EN :
+         if(Action==enSET)
+           {
+           UPDATE_RX_BROAD_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_BROAD_CH :
+         if(Action==enSET)
+           {
+           UPDATE_RX_BROAD_CH(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_MULT_EN :
+         if(Action==enSET)
+           {
+           UPDATE_RX_MULT_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_MULT_CH :
+         if(Action==enSET)
+           {
+           UPDATE_RX_MULT_CH(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+
+    /********************************************************************/
+    /*                                                                  */
+    /*                      MAC_CONTROL                                 */
+    /*                                                                  */
+    /********************************************************************/
+
+    case enTX_PTYPE :
+         if(Action==enSET)
+           {
+           UPDATE_TX_PTYPE(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enTX_PACE :
+         if(Action==enSET)
+           {
+           UPDATE_TX_PACE(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enTX_FLOW_EN :
+         if(Action==enSET)
+           {
+           UPDATE_TX_FLOW_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_FLOW_EN :
+         if(Action==enSET)
+           {
+           UPDATE_RX_FLOW_EN(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+
+    case enCTRL_LOOPBACK :
+         if(Action==enSET)
+           {
+           UPDATE_CTRL_LOOPBACK(*(unsigned int *)ParmValue);
+           Update=1;
+           }
+    break;
+    /********************************************************************/
+    /*                                                                  */
+    /*                      RX_UNICAST_SET                              */
+    /*                                                                  */
+    /********************************************************************/
+
+    case enRX_UNICAST_SET :
+         if(Action==enSET)
+          {
+           HalDev->RxUnicastSet   |=  (1 << *(unsigned int *)ParmValue);
+           HalDev->RxUnicastClear &= ~(1 << *(unsigned int *)ParmValue);
+           Update=1;
+          }
+    break;
+    case enRX_UNICAST_CLEAR :
+         if(Action==enSET)
+          {
+          HalDev->RxUnicastClear |=  (1 << *(unsigned int *)ParmValue);
+          HalDev->RxUnicastSet   &= ~(1 << *(unsigned int *)ParmValue);
+          Update=1;
+          }
+    break;
+
+    case enRX_MAXLEN :
+         if(Action==enSET)
+           {
+           HalDev->RxMaxLen    =   *(unsigned int *)ParmValue;
+           Update=1;
+           }
+    break;
+
+    case enRX_FILTERLOWTHRESH :
+         if(Action==enSET)
+           {
+           HalDev->RxFilterLowThresh  =   *(unsigned int *)ParmValue;
+           Update=1;
+           }
+    break;
+    case enRX0_FLOWTHRESH :
+         if(Action==enSET)
+           {
+           HalDev->Rx0FlowThresh =   *(unsigned int *)ParmValue;
+           Update=1;
+           }
+    break;
+    /********************************************************************/
+    /*                                                                  */
+    /*                      RX_MULTICAST                                */
+    /*                                                                  */
+    /********************************************************************/
+
+    case enRX_MULTICAST :
+    break;
+    case enRX_MULTI_SINGLE :
+         if(DBG(11))
+          {
+           int tmpi;
+           bit8u *MacAddress;
+           MacAddress = (bit8u *) ParmValue;
+           dbgPrintf("CPMAC[%X]:  MacAddress '", HalDev->dev_base);
+           for (tmpi=0; tmpi<6; tmpi++)
+             dbgPrintf("%02X:", MacAddress[tmpi]);
+             dbgPrintf("\n");
+          }
+         if(Action==enCLEAR)
+           {
+           HashDel(HalDev, ParmValue);
+           Update=1;
+           }
+         else
+         if(Action==enSET)
+           {
+           HashAdd(HalDev, ParmValue);
+           Update=1;
+           }
+    break;
+    case enRX_MULTI_ALL :
+         if(Action==enCLEAR)
+           {
+           HalDev->MacHash1 = 0;
+           HalDev->MacHash2 = 0;
+           Update=1;
+           }
+         else
+         if(Action==enSET)
+           {
+           HalDev->MacHash1 = 0xFFFFFFFF;
+           HalDev->MacHash2 = 0xFFFFFFFF;
+           Update=1;
+           }
+    break;
+
+    /********************************************************************/
+    /*                                                                  */
+    /*                      MDIO                                        */
+    /*                                                                  */
+    /********************************************************************/
+
+    case enMdioConnect :
+         if(Action==enSET)
+           {
+           HalDev->MdioConnect = *(unsigned int *)ParmValue;
+           MdioSetPhyMode(HalDev);
+           }
+           if(Action==enGET)
+           {
+           *(unsigned int *)ParmValue = HalDev->MdioConnect;
+           }
+    break;
+
+
+    /********************************************************************/
+    /*                                                                  */
+    /*                      STATISTICS                                  */
+    /*                                                                  */
+    /********************************************************************/
+    case enStatsClear :
+           StatsClear(HalDev);
+    break;
+    case enStatsDump :
+         if(Action==enGET)
+           {
+           StatsDump(HalDev, ParmValue);
+           }
+    break;
+
+/*  Not implemented
+    case enStats1 :
+         if(Action==enGET)
+           {
+           StatsGet(HalDev, ParmValue, 1);
+           }
+    break;
+
+    case enStats2 :
+         if(Action==enGET)
+           {
+           StatsGet(HalDev, ParmValue, 2);
+           }
+    break;
+    case enStats3 :
+         if(Action==enGET)
+           {
+           StatsGet(HalDev, ParmValue, 3);
+           }
+    break;
+    case enStats4 :
+         if(Action==enGET)
+           {
+           StatsGet(HalDev, ParmValue, 4);
+           }
+    break;
+
+*/
+
+    default:
+    rc = EC_CPMAC|EC_FUNC_OPTIONS|EC_VAL_KEY_NOT_FOUND;
+    break;
+  }
+
+  /* Verify proper device state */
+  if (HalDev->State == enOpened)
+    switch (Update)
+      {
+      case 1 :
+           ConfigApply(HalDev);
+      break;
+      default:
+      break;
+      }
+
+  return (rc);
+  }
+static const char pszStats[]       = "Stats;";
+
+static int halControl(HAL_DEVICE *HalDev, const char *pszKey, const char *pszAction, void *Value)
+  {
+  int i;
+  int rc=0;
+  int Action;
+  int ActionFound;
+  int KeyFound;
+
+#ifdef __CPHAL_DEBUG
+  if (DBG(1))
+    {
+    dbgPrintf("\nhalControl-HalDev:%08X,Action:%s,Key:%s\n", (bit32u)HalDev, pszAction, pszKey);
+    }
+#endif
+
+  /* 23Aug04 - BCIL needs to set Mac Address  */
+  if(HalDev->OsFunc->Strcmpi(pszKey, pszMacAddr) == 0)
+    {
+    KeyFound=1;
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcSet) == 0)
+      {
+        unsigned char *MacAddr;  
+        MacAddr = (unsigned char *) Value;  
+        MacAddressSave(HalDev, MacAddr); 
+        MacAddressSet(HalDev);       
+        return(0);
+      }
+    else
+      {
+       return(-1);
+      }
+    }
+     
+  if(HalDev->OsFunc->Strcmpi(pszKey, hcLinked) == 0)
+    {
+    KeyFound=1;
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcSet) == 0)
+      {
+        HalDev->Linked = *(int *)Value;
+        return(0);
+      }
+    else
+      {
+       return(-1);
+      }
+    }
+  
+  if(HalDev->OsFunc->Strcmpi(pszKey, "TxIntDisable") == 0)
+    {
+    KeyFound=1;
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcSet) == 0)
+      {
+        HalDev->TxIntDisable = *(int *)Value;
+        if(HalDev->TxIntDisable && (HalDev->State == enOpened))
+          {
+              /* if Opened and need TxIntDisabled, clear Ints for Channel 0 */
+              CPMAC_TX_INTMASK_CLEAR(HalDev->dev_base) = 1;             
+          }        
+        return(0);
+      }
+    else
+      {
+       return(-1);
+      }
+    }
+
+  if(HalDev->OsFunc->Strcmpi(pszKey, hcPhyAccess) == 0)
+    {
+    bit32u RegAddr;
+    bit32u PhyNum;
+    bit32u Data;
+    bit32u ValueIn;
+
+    ValueIn = *(bit32u*) Value;
+
+    KeyFound=1;
+    /* Cannot access MII if not opended */
+
+    if(HalDev->State < enOpened)
+      return(-1);
+
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcGet) == 0)
+      {
+
+      PhyNum  = (ValueIn & 0x1F);        /* Phynum 0-32 */
+      RegAddr = (ValueIn >> 5) & 0xFF;   /* RegAddr in upper 11 bits */
+
+      *(bit32u*)Value = _mdioUserAccessRead(HalDev->PhyDev, RegAddr, PhyNum);
+
+      return(0);
+      } /* end of hcGet */
+
+
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcSet) == 0)
+      {
+      PhyNum  = (ValueIn & 0x1F);        /* Phynum 0-32 */
+      RegAddr = (ValueIn >> 5) & 0xFF;   /* RegAddr in upper 11 bits of lower 16 */
+
+      Data    = ValueIn >> 16;           /* Data store in upper 16 bits */
+
+      _mdioUserAccessWrite(HalDev->PhyDev, RegAddr, PhyNum, Data);
+      return(0);
+      }
+    } /*  End of hcPhyAccess */
+
+  if(HalDev->OsFunc->Strcmpi(pszKey, hcPhyNum) == 0)
+    {
+    KeyFound=1;
+    if(!HalDev->Linked)
+      return(-1);  /* if not linked the no Phy Connected */
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcGet) == 0)
+      {
+        *(int *)Value = HalDev->PhyNum;
+      return(0);
+      }
+    }
+
+  if(HalDev->OsFunc->Strcmpi(pszKey, hcCpmacSize) == 0)
+    {
+    KeyFound=1;
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcGet) == 0)
+      {
+        *(bit32u *)Value = HalDev->CpmacSize;
+      return(0);
+      }
+    }
+
+   if(HalDev->OsFunc->Strcmpi(pszKey, hcCpmacBase) == 0)
+    {
+    KeyFound=1;
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcGet) == 0)
+      {
+        *(int *)Value = HalDev->dev_base;
+      return(0);
+      }
+    }
+
+  if(HalDev->OsFunc->Strcmpi(pszKey, hcFullDuplex) == 0)
+    {
+    KeyFound=1;
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcSet) == 0)
+      {
+        UPDATE_FULLDUPLEX(*(unsigned int *)Value);
+        if(HalDev->State == enOpened)
+           ConfigApply(HalDev);
+      return(0);
+      }
+    else
+      return(-1);
+    }
+
+  if(HalDev->OsFunc->Strcmpi(pszKey, pszDebug) == 0)
+    {
+    KeyFound=1;
+    if(HalDev->OsFunc->Strcmpi(pszAction, hcSet) == 0)
+      {
+        ActionFound=1;
+        HalDev->debug = *(int *)Value;
+      }
+    }
+
+  if(HalDev->OsFunc->Strcmpi(pszKey, hcMaxFrags) == 0)
+    {
+     KeyFound=1;
+     if(HalDev->OsFunc->Strcmpi(pszAction, hcSet) == 0)
+       {
+        ActionFound=1;
+
+        if ((*(int *)Value) > 0)
+          HalDev->MaxFrags = *(int *)Value;
+         else
+          rc = (EC_AAL5|EC_FUNC_CONTROL|EC_VAL_INVALID_VALUE);
+      }
+
+     if (HalDev->OsFunc->Strcmpi(pszAction, hcGet) == 0)
+       {
+        ActionFound=1;
+
+        *(int *)Value = HalDev->MaxFrags;
+       }
+    }
+
+  if(HalDev->OsFunc->Strstr(pszKey, pszStats) != 0)
+    {
+     KeyFound=1;
+     if(HalDev->OsFunc->Strcmpi(pszAction, hcGet) == 0)
+         {
+       int Level;
+       int Ch;
+       char *TmpKey = (char *)pszKey;
+       ActionFound=1;
+       TmpKey += HalDev->OsFunc->Strlen(pszStats);
+       Level   = HalDev->OsFunc->Strtoul(TmpKey, &TmpKey, 10);
+       TmpKey++;
+       Ch      = HalDev->OsFunc->Strtoul(TmpKey, &TmpKey, 10);
+       TmpKey++;
+       osfuncSioFlush();
+#ifdef __CPHAL_DEBUG
+  if (DBG(1))
+    {
+    dbgPrintf("\nhalControl-HalDev:%08X, Level:%d, Ch:%d\n", (bit32u)HalDev, Level, Ch);
+    }
+#endif
+         StatsGet(HalDev, (void **)Value, Level, Ch, 0);
+       osfuncSioFlush();
+         }
+    }
+
+
+  if(HalDev->OsFunc->Strcmpi(pszAction, hcSet) == 0)
+    Action = enSET;
+  else
+  if(HalDev->OsFunc->Strcmpi(pszAction, hcClear) == 0)
+    Action = enCLEAR;
+  else
+  if(HalDev->OsFunc->Strcmpi(pszAction, hcGet) == 0)
+    Action = enGET;
+  else
+    Action = enNULL;
+
+
+
+  for(i=enCommonStart+1;i<enCommonEnd;i++)
+    {
+    if(HalDev->OsFunc->Strcmpi(KeyCommon[i].strKey, pszKey)==0)
+      {
+      rc = InfoAccess(HalDev, KeyCommon[i].enKey, Action, Value);
+      }
+    }
+  for(i=enCpmacStart+1;i<enCpmacEnd;i++)
+    {
+    if(HalDev->OsFunc->Strcmpi(KeyCpmac[i].strKey, pszKey)==0)
+      {
+      rc = InfoAccess(HalDev, KeyCpmac[i].enKey, Action, Value);
+      }
+    }
+/*
+  if (KeyFound == 0)
+    rc = (EC_MODULE|EC_FUNC_CONTROL|EC_VAL_KEY_NOT_FOUND);
+
+  if (ActionFound == 0)
+    rc = (EC_MODULE|EC_FUNC_CONTROL|EC_VAL_ACTION_NOT_FOUND);
+*/
+
+  return(rc);
+  }
+static bit32u ConfigGet(HAL_DEVICE *HalDev)
+  {
+  OS_FUNCTIONS *OsFunc = HalDev->OsFunc;
+  char *DeviceInfo     = HalDev->DeviceInfo;
+  int i                = HalDev->inst;
+  bit32u Value;
+  int Error;
+
+  /* get the configuration parameters common to all modules */
+  Error = ConfigGetCommon(HalDev);
+  if (Error) return (EC_CPMAC|Error);
+
+  if (HalDev->debug)
+    {
+      dbgPrintf("ConfigGet: haldev:0x%08X inst:%d base:0x%08X reset:%d\n", (bit32u) &HalDev, HalDev->inst, HalDev->dev_base, HalDev->ResetBit);
+      osfuncSioFlush();
+    }
+
+  Error = OsFunc->DeviceFindParmUint(DeviceInfo, pszMdioConnect,&Value); /*MJH+030805*/
+  if(!Error) HalDev->MdioConnect = Value;
+
+  Error = OsFunc->DeviceFindParmUint(DeviceInfo, "PhyMask",&Value);
+  if(!Error) HalDev->PhyMask = Value;
+
+  Error = OsFunc->DeviceFindParmUint(DeviceInfo, "MLink",&Value);
+  if(!Error) HalDev->MLinkMask = Value;
+
+  Error = OsFunc->DeviceFindParmUint(DeviceInfo, hcMdixMask, &Value);
+  if(!Error)
+    HalDev->MdixMask = Value;
+  else
+    HalDev->MdixMask = 0;
+
+  Error = OsFunc->DeviceFindParmUint(DeviceInfo, hcSize, &Value); /*MJH+030425*/
+  if(!Error) HalDev->CpmacSize = Value;
+
+  for(i=enCommonStart+1;i<enCommonEnd;i++)
+    {
+    Error = OsFunc->DeviceFindParmUint(DeviceInfo, KeyCommon[i].strKey, (bit32u*)&Value);
+    if(!Error)
+      {
+      InfoAccess(HalDev, KeyCommon[i].enKey, enSET, (bit32u*)&Value);
+      }
+    }
+  for(i=enCpmacStart+1;i<enCpmacEnd;i++)
+    {
+    Error = OsFunc->DeviceFindParmUint(DeviceInfo, KeyCpmac[i].strKey, (bit32u*)&Value);
+    if(!Error)
+      {
+      InfoAccess(HalDev, KeyCpmac[i].enKey, enSET, (bit32u*)&Value);
+      }
+    }
+   return (EC_NO_ERRORS);
+  }
+
+
+static void ConfigInit(HAL_DEVICE *HalDev)
+  {
+  if(HalDev->inst == 0)
+    {
+     HalDev->dev_base  = 0xA8610000;
+     HalDev->ResetBit  = 17;
+     HalDev->interrupt = 19;
+     HalDev->MLinkMask = 0;
+     HalDev->PhyMask   = 0xAAAAAAAA;
+    }
+  else
+    {
+     HalDev->dev_base  = 0xA8612800;
+     HalDev->ResetBit  = 21;
+     HalDev->interrupt = 33;                                         /*~RC3.02*/
+     HalDev->MLinkMask = 0;
+     HalDev->PhyMask   = 0x55555555;
+    }
+  HalDev->RxMaxLen    = 1518;
+  HalDev->MaxFrags    = 2;
+  HalDev->MdioConnect = _CPMDIO_HD|_CPMDIO_FD|_CPMDIO_10|_CPMDIO_100|_CPMDIO_AUTOMDIX;
+  HalDev->debug=0xFFFFFFFF;
+  HalDev->debug=0;
+  }
+/* Shuts down the EMAC device
+ *
+ *@param HalDev EMAC instance. This was returned by halOpen()
+ *@param mode Indicates actions to tak on close.
+ <br>
+ *PARTIAL - Disable EMAC
+ <br>
+ *FULL    - Disable EMAC and call OS to free all allocated memory
+ *
+ *@retval
+ *        0 OK
+ <br>
+ *        Non-Zero Not OK
+ *
+ */
+static int halInit( HAL_DEVICE *HalDev)
+  {
+   int rc;
+
+  /* Verify proper device state */
+  if (HalDev->State != enDevFound)
+    return(EC_CPMAC|EC_FUNC_HAL_INIT|EC_VAL_INVALID_STATE);
+
+  /* Configure HAL defaults */
+  ConfigInit(HalDev);
+
+  /* Retrieve HAL configuration parameters from data store */
+  rc = ConfigGet(HalDev);
+  if (rc) return (rc);
+
+  /* Updated 030403*/
+  rc = HalDev->OsFunc->Control(HalDev->OsDev, hcCpuFrequency, hcGet, &HalDev->CpuFrequency); /*MJH+030403*/
+  if(rc)
+    HalDev->CpuFrequency = 20000000;  /*20 Mhz default */         /*MJH+030403*/
+
+  rc = HalDev->OsFunc->Control(HalDev->OsDev, hcCpmacFrequency, hcGet, &HalDev->CpmacFrequency); /*MJH+030331*/
+  if(rc)
+    HalDev->CpmacFrequency = HalDev->CpuFrequency/2;               /*MJH~030404*/
+
+  rc = HalDev->OsFunc->Control(HalDev->OsDev, hcMdioBusFrequency,  hcGet, &HalDev->MdioBusFrequency);  /*MJH+030402*/
+  if(rc)
+    HalDev->MdioBusFrequency = HalDev->CpmacFrequency;
+
+  rc = HalDev->OsFunc->Control(HalDev->OsDev, hcMdioClockFrequency,  hcGet, &HalDev->MdioClockFrequency);  /*MJH+030402*/
+  if(rc)
+    HalDev->MdioClockFrequency = 2200000; /* 2.2 Mhz PITS #14 */
+
+
+  /* update device state */
+  HalDev->State = enInitialized;
+
+  /* initialize statistics */
+  StatsInit(HalDev);                                                  /* +RC3.02 */
+
+  /*                                                                  -RC3.02
+  StatsTable3[0].StatPtr  = &HalDev->ChData[0].RxBufSize;
+  StatsTable3[1].StatPtr  = &HalDev->ChData[0].RxBufferOffset;
+  StatsTable3[2].StatPtr  = &HalDev->ChData[0].RxNumBuffers;
+  StatsTable3[3].StatPtr  = &HalDev->ChData[0].RxServiceMax;
+  StatsTable3[4].StatPtr  = &HalDev->ChData[0].TxNumBuffers;
+  StatsTable3[5].StatPtr  = &HalDev->ChData[0].TxNumQueues;
+  StatsTable3[6].StatPtr  = &HalDev->ChData[0].TxServiceMax;
+  */
+
+  return(EC_NO_ERRORS);
+  }
+static int halProbe(HAL_DEVICE *HalDev)
+  {
+  int inst             = HalDev->inst;
+  OS_FUNCTIONS *OsFunc = HalDev->OsFunc;
+  int error_code;
+
+  if (HalDev->State != enConnected)
+     return (EC_CPMAC|EC_FUNC_PROBE|EC_VAL_INVALID_STATE);
+
+  if(HalDev->debug) dbgPrintf("halProbe: %d ",inst);
+
+  error_code = OsFunc->DeviceFindInfo(inst,"cpmac",&HalDev->DeviceInfo);
+
+  if(error_code)
+     return (EC_CPMAC|EC_FUNC_PROBE|EC_VAL_DEVICE_NOT_FOUND );
+
+  /* Set device state to DevFound */
+  HalDev->State = enDevFound;
+  return(EC_NO_ERRORS);
+  }
+static void ChannelConfigInit(HAL_DEVICE *HalDev, CHANNEL_INFO *HalChn)
+  {
+  int Ch        = HalChn->Channel;
+  int Direction = HalChn->Direction;
+  int nTxBuffers = 256;
+
+  if (Direction == DIRECTION_TX)
+    {
+    HalDev->ChData[Ch].TxNumBuffers   = nTxBuffers;
+    HalDev->ChData[Ch].TxNumQueues    = 1;
+    HalDev->ChData[Ch].TxServiceMax   = nTxBuffers/3;
+    HalDev->TxIntThreshold[Ch]        = HalDev->ChData[Ch].TxServiceMax;
+    HalDev->TxIntThresholdMaster[Ch]  = HalDev->TxIntThreshold[Ch];
+    }
+
+  if (Direction == DIRECTION_RX)
+    {
+    HalDev->ChData[Ch].RxNumBuffers   = nTxBuffers*2;
+    HalDev->ChData[Ch].RxBufferOffset = 0;
+    HalDev->ChData[Ch].RxBufSize      = 1518;
+    HalDev->ChData[Ch].RxServiceMax   = nTxBuffers/3; /*Not a typo*/
+    }
+  }
+static int ChannelConfigApply(HAL_DEVICE *HalDev, CHANNEL_INFO *HalChn)
+  {
+   int Ch        = HalChn->Channel;
+   int Direction = HalChn->Direction;
+
+   if (DBG(11))
+     {
+      dbgPrintf("halChannelConfigApply[%d:%d] haldev:0x%08X inst:%d base:0x%08X reset:%d\n", Ch, Direction, (bit32u) &HalDev, HalDev->inst, HalDev->dev_base, HalDev->ResetBit);
+      osfuncSioFlush();
+     }
+
+   if (Direction == DIRECTION_TX)
+   {
+     if (HalDev->ChIsOpen[Ch][Direction] == TRUE)
+     {
+      return(EC_CPMAC|EC_FUNC_CHSETUP|EC_VAL_TX_CH_ALREADY_OPEN);
+     }
+
+     /* Initialize Queue Data */
+     HalDev->TxActQueueHead[Ch][0]  = 0;
+     HalDev->TxActQueueCount[Ch][0] = 0;
+     HalDev->TxActive[Ch][0]        = FALSE;
+
+     /* Need to use a macro that takes channel as input */
+     CPMAC_TX0_HDP(HalDev->dev_base)=0;
+
+     /* Initialize buffer memory for the channel */
+     InitTcb(HalDev, Ch);
+
+     if(!HalDev->TxIntDisable)
+       CPMAC_TX_INTMASK_SET(HalDev->dev_base) = (1<<Ch); /* GSG 11/22 */
+   }
+   else
+   {
+     if (HalDev->ChIsOpen[Ch][Direction] == TRUE)
+     {
+      return(EC_CPMAC|EC_FUNC_CHSETUP|EC_VAL_RX_CH_ALREADY_OPEN);
+     }
+
+     /* Initialize Queue Data */
+     HalDev->RxActQueueHead[Ch]     = 0;
+     HalDev->RxActQueueCount[Ch]    = 0;
+
+     HalDev->RxActive[Ch]           = FALSE;
+
+     /* Need to use a macro that takes channel as input */
+     CPMAC_RX0_HDP(HalDev->dev_base)=0;
+
+     /* Initialize buffer memory for the channel */
+     InitRcb(HalDev, Ch);
+
+     CPMAC_RX_INTMASK_SET(HalDev->dev_base)  = (1<<Ch); /* GSG 11/22 */
+   }
+
+   HalDev->ChIsOpen[Ch][Direction] = TRUE; /* channel is open */
+
+   return (EC_NO_ERRORS);
+  }
+
+/* GSG 11/22
+ * Retrieves channel parameters from configuration file.  Any parameters
+ * which are not found are ignored, and the HAL default value will apply,
+ * unless a new value is given through the channel structure in the call
+ * to ChannelSetup.
+ */
+static int ChannelConfigGet(HAL_DEVICE *HalDev, CHANNEL_INFO *HalChn)
+  {
+  int Ch        = HalChn->Channel;
+  int Direction = HalChn->Direction;
+  OS_FUNCTIONS *OsFunc = HalDev->OsFunc;
+  unsigned int rc, Value;
+  void *ChInfo;
+
+   rc=OsFunc->DeviceFindParmValue(HalDev->DeviceInfo, channel_names[Ch], &ChInfo);
+   /*  Do not fail if Channel Info not available for RC2 */
+   if (rc) return(0);
+/*   if (rc) return(EC_CPMAC|EC_FUNC_CHSETUP|EC_VAL_CH_INFO_NOT_FOUND);*/
+
+   /* i don't care if a value is not found because they are optional */
+   if(Direction == DIRECTION_TX)
+     {
+     rc=OsFunc->DeviceFindParmUint(ChInfo, "TxNumBuffers", &Value);
+     if (!rc) HalDev->ChData[Ch].TxNumBuffers = Value;
+
+     /*rc=OsFunc->DeviceFindParmUint(ChInfo, "TxNumQueues", &Value);*/ /*MJH-030329*/
+     /*if (!rc) HalDev->ChData[Ch].TxNumQueues = Value;*/              /*MJH-030329*/
+
+     rc=OsFunc->DeviceFindParmUint(ChInfo, "TxServiceMax", &Value);
+     if (!rc) 
+       {
+         HalDev->ChData[Ch].TxServiceMax = Value;
+         HalDev->TxIntThreshold[Ch]      = HalDev->ChData[Ch].TxServiceMax;
+         HalDev->TxIntThresholdMaster[Ch]  = HalDev->TxIntThreshold[Ch];
+       }
+     }
+   if(Direction == DIRECTION_RX)
+     {
+     rc=OsFunc->DeviceFindParmUint(ChInfo, "RxNumBuffers", &Value);
+     if (!rc) HalDev->ChData[Ch].RxNumBuffers = Value;
+
+     rc=OsFunc->DeviceFindParmUint(ChInfo, "RxBufferOffset", &Value);
+     if (!rc) HalDev->ChData[Ch].RxBufferOffset = Value;
+
+     rc=OsFunc->DeviceFindParmUint(ChInfo, "RxBufSize", &Value);
+     if (!rc) HalDev->ChData[Ch].RxBufSize = Value;
+
+     rc=OsFunc->DeviceFindParmUint(ChInfo, "RxServiceMax", &Value);
+     if (!rc) HalDev->ChData[Ch].RxServiceMax = Value;
+     }
+   return (EC_NO_ERRORS);
+  }
+#define ChannelUpdate(Field) if(HalChn->Field != 0xFFFFFFFF) HalDev->ChData[Ch].Field = HalChn->Field
+
+static void ChannelConfigUpdate(HAL_DEVICE *HalDev, CHANNEL_INFO *HalChn)
+  {
+  int Ch        = HalChn->Channel;
+  int Direction = HalChn->Direction;
+#ifdef __CPHAL_DEBUG
+  if (DBG(1))
+    {
+    dbgPrintf("\nChnUpd-HalDev:%08X,Chn:%d:%d\n", (bit32u)HalDev, Ch, Direction); osfuncSioFlush();
+    }
+#endif
+  if (Direction == DIRECTION_TX)
+    {
+    ChannelUpdate(TxNumBuffers);
+    /*ChannelUpdate(TxNumQueues);*/                               /*MJH~030329*/
+    ChannelUpdate(TxServiceMax);
+    HalDev->TxIntThreshold[Ch]        = HalDev->ChData[Ch].TxServiceMax;
+    HalDev->TxIntThresholdMaster[Ch]  = HalDev->TxIntThreshold[Ch];
+    }
+  else
+  if (Direction == DIRECTION_RX)
+    {
+    ChannelUpdate(RxBufferOffset);
+    ChannelUpdate(RxBufSize);
+    ChannelUpdate(RxNumBuffers);
+    ChannelUpdate(RxServiceMax);
+#ifdef __CPHAL_DEBUG
+  if (DBG(1))
+    {
+    dbgPrintf("\nRxNumBuffers %d\n",HalChn->RxNumBuffers); osfuncSioFlush();
+    }
+#endif
+    }
+  }
+static int halChannelSetup(HAL_DEVICE *HalDev, CHANNEL_INFO *HalChn, OS_SETUP *OsSetup)
+  {
+  int Direction;
+  int Ch;
+  int rc;
+
+  /* Verify proper device state */
+  if (HalDev->State < enInitialized)
+    return (EC_CPMAC|EC_FUNC_CHSETUP|EC_VAL_INVALID_STATE);
+
+  /* We require the channel structure to be passed, even if it only contains
+     the channel number */
+  if (HalChn == NULL)
+    {
+     return(EC_CPMAC|EC_FUNC_CHSETUP|EC_VAL_NULL_CH_STRUCT);
+    }
+
+  Ch        = HalChn->Channel;
+  Direction = HalChn->Direction;
+
+  /* This should check on Maximum Channels for RX or TX,
+     they might be different Mick 021124 */
+  if ((Ch < 0) || (Ch > (MAX_CHAN-1)))
+    {
+     return(EC_CPMAC|EC_FUNC_CHSETUP|EC_VAL_INVALID_CH);
+    }
+
+  /* if channel is already open, this call is invalid */
+  if (HalDev->ChIsOpen[Ch][Direction] == TRUE)
+    {
+     return(EC_CPMAC|EC_FUNC_CHSETUP|EC_VAL_CH_ALREADY_OPEN);
+    }
+
+  /* channel is closed, but might be setup.  If so, reopen the hardware channel. */
+  if (HalDev->ChIsSetup[Ch][Direction] == FALSE)
+    {
+     /* Setup channel configuration */
+     HalDev->ChData[Ch].Channel = Ch;
+
+     /* Store OS_SETUP */
+     HalDev->ChData[Ch].OsSetup = OsSetup;
+
+     /*  Framework :
+         Set Default Values
+         Update with options.conf
+     Apply driver updates
+     */
+     ChannelConfigInit(HalDev, HalChn);
+     ChannelConfigGet(HalDev, HalChn);
+     ChannelConfigUpdate(HalDev, HalChn);
+
+     /* cppi.c needs to use Rx/TxServiceMax */
+     HalDev->BuffersServicedMax  = 169;  /* TEMP */
+
+     HalDev->ChIsSetup[Ch][Direction] = TRUE;
+    }
+
+  rc = EC_NO_ERRORS;
+
+  /* If the hardware has been opened (is out of reset), then configure the channel
+     in the hardware. NOTE: ChannelConfigApply calls the CPSAR ChannelSetup()! */
+  if (HalDev->State == enOpened)
+    {
+     rc = ChannelConfigApply(HalDev, HalChn);
+    }
+
+  return (rc);
+  }
+
+
+static int miiInfoGet(HAL_DEVICE *HalDev, bit32u *miiBaseAddress, bit32u *miiResetBit)
+  {
+  int rc;
+  void *DeviceInfo;
+  OS_FUNCTIONS *OsFunc = HalDev->OsFunc;
+
+  /*  Only one instance of cpmdio   */
+  rc = OsFunc->DeviceFindInfo(0,"cpmdio",&DeviceInfo);               /*~RC3.02*/
+
+  if(rc)
+     return (EC_DEV_CPMDIO|EC_FUNC_OPEN|EC_VAL_DEVICE_NOT_FOUND );
+
+  rc = OsFunc->DeviceFindParmUint(DeviceInfo, "base",miiBaseAddress);
+  if(rc)
+      rc=EC_DEV_CPMDIO|EC_FUNC_OPEN|EC_VAL_NO_BASE;
+
+  rc = OsFunc->DeviceFindParmUint(DeviceInfo, "reset_bit",miiResetBit);
+  if(rc)
+      rc=EC_DEV_CPMDIO|EC_FUNC_OPEN|EC_VAL_NO_BASE;
+
+
+  /* See if need to make mdio functional in GPIO */
+  gpioCheck(HalDev, DeviceInfo);
+
+  if(DBG(0))
+    dbgPrintf("miiBase: 0x%08X %u\n", *miiBaseAddress, *miiResetBit);
+  return(rc);
+  }
+static void ephyCheck(HAL_DEVICE *HalDev)
+  {                                                                  /*+RC3.02*/
+  int rc;
+  void *DeviceInfo;
+  int mii_phy;
+  int reset_bit;
+  OS_FUNCTIONS *OsFunc = HalDev->OsFunc;
+
+  rc = OsFunc->DeviceFindInfo(0,"ephy",&DeviceInfo);
+  if(rc) return;
+
+  rc = OsFunc->DeviceFindParmUint(DeviceInfo, "mii_phy",&mii_phy);
+  if(rc) return;
+
+  rc = OsFunc->DeviceFindParmUint(DeviceInfo, "reset_bit",&reset_bit);
+  if(rc) return;
+
+  if (HalDev->PhyMask & (1 << mii_phy))
+    {
+    *(volatile bit32u *)(HalDev->ResetBase) |=  (1 << reset_bit);                      /*+RC3.02*/
+    resetWait(HalDev);
+    }
+  }                                                                  /*+RC3.02*/
+static void AutoNegotiate(HAL_DEVICE *HalDev)
+  {
+  int size;
+  bit32u ModID,  RevMaj,  RevMin;
+  PHY_DEVICE *PhyDev;
+  bit32u miiBaseAddress;
+  bit32u miiResetBit;
+
+  /* Verify proper device state */
+  if (HalDev->State < enOpened)
+    return;
+
+  miiInfoGet(HalDev, &miiBaseAddress, &miiResetBit);
+
+  cpMacMdioGetVer(miiBaseAddress, &ModID,  &RevMaj,  &RevMin);
+  if(HalDev->debug)
+     dbgPrintf("Mdio Module Id %d, Version %d.%d\n", ModID,  RevMaj,  RevMin);
+
+  size = cpMacMdioGetPhyDevSize();
+  PhyDev = (PHY_DEVICE *) HalDev->OsFunc->Malloc( size );
+
+  HalDev->PhyDev = PhyDev;
+
+  ephyCheck(HalDev);
+
+  cpMacMdioInit( PhyDev, miiBaseAddress, HalDev->inst, HalDev->PhyMask, HalDev->MLinkMask, HalDev->MdixMask, HalDev->ResetBase, miiResetBit, HalDev->MdioBusFrequency, HalDev->MdioClockFrequency, HalDev->debug, HalDev); /*MJH~030402*/
+  MdioSetPhyMode(HalDev);
+
+  return;
+  }
+static int halOpen(HAL_DEVICE *HalDev)
+  {
+  unsigned char *MacAddr;
+  int i;
+  int j;
+  int rc, Ticks;
+
+  if (HalDev->debug)
+    {
+      dbgPrintf("halOpen: haldev:0x%08X inst:%d base:0x%08X reset:%d\n", (bit32u) &HalDev, HalDev->inst, HalDev->dev_base, HalDev->ResetBit);
+      osfuncSioFlush();
+    }
+
+   /* Verify proper device state */
+   if (HalDev->State < enInitialized)
+     return (EC_CPMAC|EC_FUNC_OPEN|EC_VAL_INVALID_STATE);
+
+
+  /* take CPMAC out of reset - GSG 11/20*/
+  if ((VOLATILE32(HalDev->ResetBase) & (1 << HalDev->ResetBit)) != 0)
+    {
+     /* perform normal close duties */
+     CPMAC_MACCONTROL(HalDev->dev_base) &= ~MII_EN;
+     CPMAC_TX_CONTROL(HalDev->dev_base) &= ~TX_EN;
+     CPMAC_RX_CONTROL(HalDev->dev_base) &= ~RX_EN;
+
+     /* disable interrupt masks */
+     CPMAC_TX_INTMASK_CLEAR(HalDev->dev_base) = 0xFF;
+     CPMAC_RX_INTMASK_CLEAR(HalDev->dev_base) = 0xFF;
+    }
+
+   /* take CPMAC out of reset */
+   *(volatile bit32u *)(HalDev->ResetBase) &= ~(1 << HalDev->ResetBit);
+   resetWait(HalDev);
+   *(volatile bit32u *)(HalDev->ResetBase) |=  (1 << HalDev->ResetBit);
+   resetWait(HalDev);
+
+  /* After Reset clear the Transmit and Receive DMA Head Descriptor Pointers */
+
+  CPMAC_TX0_HDP(HalDev->dev_base)=0;
+  CPMAC_TX1_HDP(HalDev->dev_base)=0;
+  CPMAC_TX2_HDP(HalDev->dev_base)=0;
+  CPMAC_TX3_HDP(HalDev->dev_base)=0;
+  CPMAC_TX4_HDP(HalDev->dev_base)=0;
+  CPMAC_TX5_HDP(HalDev->dev_base)=0;
+  CPMAC_TX6_HDP(HalDev->dev_base)=0;
+  CPMAC_TX7_HDP(HalDev->dev_base)=0;
+
+  /* Rx Init  */
+
+  CPMAC_RX0_HDP(HalDev->dev_base) = 0;
+  CPMAC_RX1_HDP(HalDev->dev_base) = 0;
+  CPMAC_RX2_HDP(HalDev->dev_base) = 0;
+  CPMAC_RX3_HDP(HalDev->dev_base) = 0;
+  CPMAC_RX4_HDP(HalDev->dev_base) = 0;
+  CPMAC_RX5_HDP(HalDev->dev_base) = 0;
+  CPMAC_RX6_HDP(HalDev->dev_base) = 0;
+  CPMAC_RX7_HDP(HalDev->dev_base) = 0;
+
+  CPMAC_RX_BUFFER_OFFSET(HalDev->dev_base) = 0;
+
+  /* Init Tx and Rx DMA */
+
+  CPMAC_TX_CONTROL(HalDev->dev_base) |= TX_EN;
+  CPMAC_RX_CONTROL(HalDev->dev_base) |= RX_EN;
+
+  CPMAC_MAC_INTMASK_SET(HalDev->dev_base) |=2; /* Enable Adaptercheck Ints */
+  HalDev->OsFunc->Control(HalDev->OsDev, pszMacAddr, hcGet, &MacAddr); /* GSG 11/22 */
+  MacAddressSave(HalDev, MacAddr);
+
+  HalDev->HostErr = 0;      /* Clear Adapter Check indicator */
+  HalDev->State = enOpened; /* Change device state */
+
+  /* Start MDIO Negotiation */
+  AutoNegotiate(HalDev);
+
+  /*  Enable the Os Timer  */
+  Ticks = HalDev->CpuFrequency / 100;  /*  10 milli-secs */       /*MJH~030402*/
+  HalDev->OsFunc->Control(HalDev->OsDev, pszTick, hcSet, &Ticks); /* GSG 11/22 */
+  HalDev->OsFunc->IsrRegister(HalDev->OsDev, halIsr, HalDev->interrupt);
+
+  /* GSG +030523 Malloc space for the Rx fraglist */
+  HalDev->fraglist = HalDev->OsFunc->Malloc(HalDev->MaxFrags * sizeof(FRAGLIST));
+
+  /* Any pre-open configuration */
+
+  /* For any channels that have been pre-initialized, set them up now */
+  /* Note : This loop should not use MAX_CHN, it should only
+            loop through Channels Setup, memory should not be reserved
+            until Channel is Setup
+  */
+  for(i=0; i<MAX_CHAN; i++) /* i loops through Channels */
+  for(j=0; j<2; j++)        /* j loops through DIRECTION values, 0 and 1  */
+    {
+     if(HalDev->ChIsSetup[i][j]==TRUE)   /* If the Channel and Direction have been Setup */
+       if(HalDev->ChIsOpen[i][j]==FALSE) /* but not opened, then Apply Values now */
+         {
+          CHANNEL_INFO HalChn;
+          HalChn.Channel   = i;
+          HalChn.Direction = j;
+          rc = ChannelConfigApply(HalDev, &HalChn);
+          if(rc != EC_NO_ERRORS)
+            return(rc);
+         }
+    }  /* End of looping through Channel/Direction */
+
+  ConfigApply(HalDev);  /* Apply Configuration Values to Device */
+  CPMAC_MACCONTROL(HalDev->dev_base) |= MII_EN;  /* MAC_EN */
+  if(DBG(0))
+     dbgPrintf("[halOpen]MacControl:%08X\n", CPMAC_MACCONTROL(HalDev->dev_base));
+  return(EC_NO_ERRORS);
+  }
+
+#define INT_PENDING (MAC_IN_VECTOR_TX_INT_OR | MAC_IN_VECTOR_RX_INT_OR | MAC_IN_VECTOR_HOST_INT)
+static int halShutdown(HAL_DEVICE *HalDev)
+  {
+   int Ch, Queue;                                                  /*GSG+030514*/
+
+   /* Verify proper device state */
+   if (HalDev->State == enOpened)
+     halClose(HalDev, 3); /* GSG ~030429 */
+
+   /* Buffer/descriptor resources may still need to be freed if a Close
+      Mode 1 was performed prior to Shutdown - clean up here */    /*GSG+030514*/
+   for (Ch=0; Ch<MAX_CHAN; Ch++)
+     {
+      if (HalDev->RcbStart[Ch] != 0)
+        FreeRx(HalDev,Ch);
+
+      for(Queue=0; Queue<MAX_QUEUE; Queue++)
+        {
+         if (HalDev->TcbStart[Ch][Queue] != 0)
+           FreeTx(HalDev,Ch,Queue);
+        }
+     }
+
+   /* free the HalFunc */
+   HalDev->OsFunc->Free(HalDev->HalFuncPtr);
+
+   /* free the HAL device */
+   HalDev->OsFunc->Free(HalDev);
+
+   return(EC_NO_ERRORS);
+  }
+int halIsr(HAL_DEVICE *HalDev, int *MorePackets)
+{
+  bit32u IntVec;
+  int Serviced;
+  int PacketsServiced=0;
+  int Channel;
+  int TxMorePackets=0;
+  int RxMorePackets=0;
+
+  /* Verify proper device state - important because a call prior to Open would
+      result in a lockup */
+  if (HalDev->State != enOpened)
+     return(EC_CPMAC|EC_FUNC_DEVICE_INT|EC_VAL_INVALID_STATE);
+
+  IntVec = CPMAC_MAC_IN_VECTOR(HalDev->dev_base);
+
+#ifdef __CPHAL_DEBUG
+  if (DBG(0))
+    {
+    dbgPrintf("\nhalIsr: inst %d, IntVec 0x%X\n", HalDev->inst, IntVec); osfuncSioFlush();/* GSG 11/22 */
+    }
+#endif
+
+  HalDev->IntVec = IntVec;
+  if (IntVec & MAC_IN_VECTOR_TX_INT_OR)
+   {
+     int TxServiceMax=0;  /* Compiler complains if not initialized */
+      
+     Channel = (IntVec & 0x7);
+     
+     if(HalDev->TxIntDisable)
+       {
+         CPMAC_TX_INTMASK_CLEAR(HalDev->dev_base) = (1<<Channel);  /* Disable Interrupt for Channel */           
+         TxServiceMax = HalDev->ChData[Channel].TxServiceMax;  
+         HalDev->ChData[Channel].TxServiceMax = 10000;             /* Need to service all packets in the Queue */
+       }      
+     
+     PacketsServiced |= TxInt(HalDev, Channel, 0, &TxMorePackets);
+     
+     if(HalDev->TxIntDisable)        
+          HalDev->ChData[Channel].TxServiceMax  = TxServiceMax;         
+    }
+  
+  if (IntVec & MAC_IN_VECTOR_RX_INT_OR)
+    {
+     Channel = (IntVec >> 8) & 0x7;
+     Serviced = RxInt(HalDev, Channel, &RxMorePackets);
+     PacketsServiced |= (Serviced<<16);
+    }
+
+  if (IntVec & MAC_IN_VECTOR_HOST_INT)
+    {
+    /* Adaptercheck */
+    HalDev->HostErr = 1;
+    HalDev->MacStatus = CPMAC_MACSTATUS(HalDev->dev_base);
+    osfuncStateChange();                                          /*MJH+030328*/
+    if(DBG(0))
+      {
+      dbgPrintf("Adaptercheck: %08x for base:%X\n",HalDev->MacStatus, (bit32u)HalDev->dev_base);
+      osfuncSioFlush();
+      }
+    }
+  *MorePackets = (TxMorePackets | RxMorePackets);
+  return (PacketsServiced);
+}
+
+int halPacketProcessEnd(HAL_DEVICE *HalDev)
+{
+  int base             = HalDev->dev_base;
+  CPMAC_MAC_EOI_VECTOR(base) = 0;
+  return(0);
+}
+
+
+
+static int PhyCheck(HAL_DEVICE *HalDev)
+  {
+      return(cpMacMdioTic(HalDev->PhyDev));
+  }
+static int halTick(HAL_DEVICE *HalDev)
+{
+    int TickChange;
+
+    if(HalDev->State <  enOpened)
+      return (EC_CPMAC|EC_FUNC_TICK|EC_VAL_INVALID_STATE);
+
+    /* if NO Phy no need to check Link */
+    if(HalDev->MdioConnect & _CPMDIO_NOPHY)
+      return(EC_NO_ERRORS);  /* No change in Phy State detected */
+
+    TickChange = PhyCheck(HalDev);
+    /* Phy State Change Detected */
+    if(TickChange == 1)
+    {
+        /*  MDIO indicated a change  */
+        DuplexUpdate(HalDev);
+        osfuncStateChange();
+        return(EC_NO_ERRORS);
+    }
+
+    /* if in AutoMdix mode, and Flip request received, inform OS */
+    if( (HalDev->MdioConnect & _CPMDIO_AUTOMDIX)  &&
+        (TickChange & _MIIMDIO_MDIXFLIP))
+    {
+       bit32u Mdix;
+       Mdix = TickChange & 0x1;   /*  Mdix mode stored in bit 0 */
+       HalDev->OsFunc->Control(HalDev->OsDev, hcMdioMdixSwitch, hcSet, &Mdix);
+       return(EC_NO_ERRORS);
+    }
+
+    return(EC_NO_ERRORS);
+}
+
+int halCpmacInitModule(HAL_DEVICE **pHalDev, OS_DEVICE *OsDev, HAL_FUNCTIONS **pHalFunc,
+                       OS_FUNCTIONS *OsFunc, int OsFuncSize,     int *HalFuncSize, int Inst)
+  {
+    HAL_DEVICE *HalDev;
+    HAL_FUNCTIONS *HalFunc;
+
+    if (OsFuncSize < sizeof(OS_FUNCTIONS))
+      return (EC_CPMAC|EC_FUNC_HAL_INIT|EC_VAL_OS_VERSION_NOT_SUPPORTED);
+
+    HalDev = (HAL_DEVICE *) OsFunc->MallocDev(sizeof(HAL_DEVICE));
+    if (!HalDev)
+      return (EC_CPMAC|EC_FUNC_HAL_INIT|EC_VAL_MALLOC_DEV_FAILED);
+
+    /* clear the HalDev area */
+    OsFunc->Memset(HalDev, 0, sizeof(HAL_DEVICE));
+
+    /* Initialize the size of hal functions */
+    *HalFuncSize = sizeof (HAL_FUNCTIONS);
+
+    HalFunc = (HAL_FUNCTIONS *) OsFunc->Malloc(sizeof(HAL_FUNCTIONS));
+    if (!HalFunc)
+      return (EC_CPMAC|EC_FUNC_HAL_INIT|EC_VAL_MALLOC_FAILED);
+
+    /* clear the function pointers */
+    OsFunc->Memset(HalFunc, 0, sizeof(HAL_FUNCTIONS));
+
+    HalDev->OsDev   = OsDev;
+    HalDev->OsOpen  = OsDev;
+    HalDev->inst    = Inst;
+    HalDev->OsFunc  = OsFunc;
+    HalDev->HalFunc = HalFunc;
+    /* Remove the following from cppi, replace with HalFunc */
+    HalDev->HalFuncPtr = HalFunc; /* GSG 11/20 changed name to match cppi */
+
+    /****************************************************************/
+    /*                 POPULATE HALFUNC                             */
+    /****************************************************************/
+    HalFunc->ChannelSetup     = halChannelSetup;
+    HalFunc->ChannelTeardown  = halChannelTeardown; /* GSG 11/20 */
+    HalFunc->Close            = halClose; /* GSG 11/20 */
+    HalFunc->Control          = halControl; /* GSG 11/22 */
+    HalFunc->Init             = halInit;
+    HalFunc->Open             = halOpen;
+    HalFunc->PacketProcessEnd = halPacketProcessEnd;
+    HalFunc->Probe            = halProbe;
+    HalFunc->RxReturn         = halRxReturn;
+    HalFunc->Send             = halSend;
+    HalFunc->Shutdown         = halShutdown;
+    HalFunc->Tick             = halTick;
+
+    /* HalFunc->Status        = halStatus;*/ /* GSG 11/22 */
+    /* pass the HalDev and HalFunc back to the caller */
+
+    *pHalDev  = HalDev;
+    *pHalFunc = HalFunc;
+
+    HalDev->State = enConnected;   /* Initialize the hardware state */
+
+    if (HalDev->debug) HalDev->OsFunc->Printf("halCpmacInitModule: Leave\n");
+    return(0);
+  }
+
+int cpmacRandomRange(HAL_DEVICE *HalDev, int min, int max)
+{
+    int iTmp;
+    iTmp  = cpmacRandom(HalDev);
+    iTmp %= ((max-min)+1);
+    iTmp += min;
+    return(iTmp);
+}
+
+int cpmacRandom(HAL_DEVICE *HalDev)
+{
+    int iTmp;
+    iTmp = CPMAC_BOFFTEST(HalDev->dev_base);
+    iTmp >>= 16;      /*  get rndnum field */
+    iTmp &= (0x3FF); /* field is 10 bits wide */
+    return(iTmp);
+}
diff -urN linux.old/drivers/net/avalanche_cpmac/hcpmac.h linux.dev/drivers/net/avalanche_cpmac/hcpmac.h
--- linux.old/drivers/net/avalanche_cpmac/hcpmac.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/hcpmac.h	2005-07-12 02:48:42.175574000 +0200
@@ -0,0 +1,383 @@
+/** @file***********************************************************************
+ *  TNETDxxxx Software Support
+ *  Copyright (c) 2002 Texas Instruments Incorporated. All Rights Reserved.
+ *
+ *  FILE:
+ *
+ *  DESCRIPTION:
+ *      This file contains definitions for the HAL EMAC API
+ *
+ *  HISTORY:
+ *  xxXxx01 Denis      1.00  Original Version created.
+ *  22Jan02 Denis/Mick 1.01  Modified for HAL EMAC API
+ *  24Jan02 Denis/Mick 1.02  Speed Improvements
+ *  28Jan02 Denis/Mick 1.16  Made function calls pointers
+ *  28Jan02 Mick       1.18  Split into separate modules
+ *  @author Michael Hanrahan
+ *  @version 1.02
+ *  @date    24-Jan-2002
+ *****************************************************************************/
+#ifndef _INC_HCPMAC
+#define _INC_HCPMAC
+
+/** \namespace CPMAC_Version
+This documents version 01.07.04 of the CPMAC CPHAL.
+*/
+const char *pszVersion_CPMAC="CPMAC 01.07.08 "__DATE__" "__TIME__;
+
+/* CHECK THESE LOCATIONS */
+#define TEARDOWN_VAL       0xfffffffc
+#define CB_OFFSET_MASK     0xFFFF0000
+
+
+#define MAX_CHAN 8
+#define MAX_QUEUE 1
+
+typedef struct
+  {
+  bit32 HNext;      /*< Hardware's pointer to next buffer descriptor  */
+  bit32 BufPtr;     /*< Pointer to the data buffer                    */
+  bit32 Off_BLen;   /*< Contains buffer offset and buffer length      */
+  bit32 mode;       /*< SOP, EOP, Ownership, EOQ, Teardown, Q Starv, Length */
+  void *Next;
+  void *OsInfo;
+  void *Eop;
+#ifdef __CPHAL_DEBUG
+  bit32 DbgSop;
+  bit32 DbgData;
+  bit32 DbgFraglist;
+#endif
+  }HAL_TCB;
+
+typedef volatile struct hal_private
+  {
+  bit32 HNext;      /*< Hardware's pointer to next buffer descriptor     */
+  bit32 BufPtr;     /*< Pointer to the data buffer                       */
+  bit32 Off_BLen;   /*< Contains buffer offset and buffer length         */
+  bit32 mode;       /*< SOP, EOP, Ownership, EOQ, Teardown Complete bits */
+  void *DatPtr;
+  void *Next;
+  void *OsInfo;
+  void *Eop;
+  }HAL_RCB;
+
+#define MAX_NEEDS 512                                             /*MJH+030409*/
+/*  HAL  */
+
+typedef struct hal_device
+  {
+  OS_DEVICE *OsDev;
+  OS_FUNCTIONS *OsFunc;
+    /*OS_SETUP *OsSetup;*/                                     /* -GSG 030508 */
+  int inst;
+  bit32u rxbufseq;
+
+
+  bit32 dev_base;
+  bit32  offset;
+
+  bit32u ResetBase; /* GSG 10/20 */
+  int ResetBit;
+  void *OsOpen;
+  bit32u IntVec;
+  PHY_DEVICE *PhyDev;
+  bit32u EmacDuplex;
+  bit32u EmacSpeed;
+  bit32u PhyNum;
+  bit32u MLinkMask;
+  bit32u PhyMask;
+  bit32u MdixMask;
+
+  bit32u Linked;
+  DEVICE_STATE State;
+  unsigned char *MacAddr;
+  HAL_FUNCTIONS *HalFuncPtr; /* GSG 11/20 changed name to match cppi */
+  HAL_FUNCTIONS *HalFunc;
+/*  unsigned int CpuFreq;*/                                       /*MJH-030402*/
+  unsigned int MdioConnect;
+  unsigned int HostErr;
+
+/************************************************************************/
+/*                                                                      */
+/*      R E G I S T E R S                                               */
+/*                                                                      */
+/************************************************************************/
+
+  bit32u RxMbpEnable;
+  bit32u RxUnicastSet;
+  bit32u RxUnicastClear;
+  bit32u RxMaxLen;
+  bit32u RxFilterLowThresh;
+  bit32u Rx0FlowThresh;
+  bit32u MacControl;
+  bit32u MacStatus;
+  bit32u MacHash1;
+  bit32u MacHash2;
+
+/************************************************************************/
+/*                                                                      */
+/*      O P T I O N S                                                   */
+/*                                                                      */
+/************************************************************************/
+
+  char *DeviceInfo;
+  bit32u interrupt;
+
+
+  bit32u RxPassCrc;
+  bit32u RxCaf;
+  bit32u RxCef;
+  bit32u RxBcast;
+  bit32u RxBcastCh;
+  HAL_RCB *RcbPool[MAX_CHAN];
+  bit32 RxActQueueCount[MAX_CHAN];
+  HAL_RCB *RxActQueueHead[MAX_CHAN];
+  HAL_RCB *RxActQueueTail[MAX_CHAN];
+  bit32 RxActive[MAX_CHAN];
+  HAL_TCB *TcbPool[MAX_CHAN][MAX_QUEUE];
+  bit32 TxActQueueCount[MAX_CHAN][MAX_QUEUE];
+  HAL_TCB *TxActQueueHead[MAX_CHAN][MAX_QUEUE];
+  HAL_TCB *TxActQueueTail[MAX_CHAN][MAX_QUEUE];
+  bit32 TxActive[MAX_CHAN][MAX_QUEUE];
+  bit32 TxTeardownPending[MAX_CHAN];
+  bit32 RxTeardownPending[MAX_CHAN];
+  bit32 ChIsOpen[MAX_CHAN][2];
+  bit32 ChIsSetup[MAX_CHAN][2];
+  FRAGLIST *fraglist;
+  char *TcbStart[MAX_CHAN][MAX_QUEUE];
+  char *RcbStart[MAX_CHAN];
+  bit32 RcbSize[MAX_CHAN];
+/*  STAT_INFO Stats;  */
+  bit32  Inst;
+  bit32u BuffersServicedMax;
+  CHANNEL_INFO ChData[MAX_CHAN];
+  bit32u MdioClockFrequency;                                      /*MJH+030402*/
+  bit32u MdioBusFrequency;                                        /*MJH+030402*/
+  bit32u CpuFrequency;                                            /*MJH+030402*/
+  bit32u CpmacFrequency;                                          /*MJH+030403*/
+  bit32u CpmacSize;                                               /*MJH+030425*/
+  int debug;
+  bit32u NeedsCount;                                              /*MJH+030409*/
+  HAL_RECEIVEINFO *Needs[MAX_NEEDS];                              /*MJH+030409*/
+  int MaxFrags;
+  int TxIntThreshold[MAX_CHAN];                   /* MJH 040621  NSP Performance Update */
+  int TxIntThresholdMaster[MAX_CHAN];             /* MJH 040827  NSP Performance Update */
+  int TxIntDisable;                     /* MJH 040621  NSP Performance Update */  
+  }HALDEVICE;
+
+#define STATS_MAX 36
+
+#define MACCONTROL_MASK    (TX_PTYPE|TX_PACE|TX_FLOW_EN|RX_FLOW_EN|CTRL_LOOPBACK)
+#define RX_MBP_ENABLE_MASK                                       \
+        (RX_PASS_CRC|RX_QOS_EN|RX_NO_CHAIN|                      \
+         RX_CMF_EN|RX_CSF_EN|RX_CEF_EN|RX_CAF_EN|RX_PROM_CH_MASK|     \
+         RX_BROAD_EN|RX_BROAD_CH_MASK|RX_MULT_EN|RX_MULT_CH_MASK)
+
+
+#define MBP_UPDATE(Mask, On)                      \
+         if(On)   HalDev->RxMbpEnable |=  Mask;   \
+         else     HalDev->RxMbpEnable &= ~Mask
+
+#define CONTROL_UPDATE(Mask, On)                  \
+         if(On)   HalDev->MacControl |=  Mask;    \
+         else     HalDev->MacControl &= ~Mask
+
+
+#define UPDATE_TX_PTYPE(Value)       CONTROL_UPDATE(TX_PTYPE,Value)
+#define UPDATE_TX_PACE(Value)        CONTROL_UPDATE(TX_PACE,Value)
+#define UPDATE_MII_EN(Value)         CONTROL_UPDATE(MII_EN,Value)
+#define UPDATE_TX_FLOW_EN(Value)     CONTROL_UPDATE(TX_FLOW_EN,Value)
+#define UPDATE_RX_FLOW_EN(Value)     CONTROL_UPDATE(RX_FLOW_EN,Value)
+#define UPDATE_CTRL_LOOPBACK(Value)  CONTROL_UPDATE(CTRL_LOOPBACK,Value)
+#define UPDATE_FULLDUPLEX(Value)     CONTROL_UPDATE(FULLDUPLEX,(Value))
+
+#define UPDATE_RX_PASS_CRC(Value)    MBP_UPDATE(RX_PASS_CRC,  Value)
+#define UPDATE_RX_QOS_EN(Value)      MBP_UPDATE(RX_QOS_EN,    Value)
+#define UPDATE_RX_NO_CHAIN(Value)    MBP_UPDATE(RX_NO_CHAIN,  Value)
+#define UPDATE_RX_CMF_EN(Value)      MBP_UPDATE(RX_CMF_EN,    Value)
+#define UPDATE_RX_CSF_EN(Value)      MBP_UPDATE(RX_CSF_EN,    Value)
+#define UPDATE_RX_CEF_EN(Value)      MBP_UPDATE(RX_CEF_EN,    Value)
+#define UPDATE_RX_CAF_EN(Value)      MBP_UPDATE(RX_CAF_EN,    Value)
+#define UPDATE_RX_BROAD_EN(Value)    MBP_UPDATE(RX_BROAD_EN,  Value)
+#define UPDATE_RX_MULT_EN(Value)     MBP_UPDATE(RX_MULT_EN,   Value)
+
+#define UPDATE_RX_PROM_CH(Value)                         \
+        HalDev->RxMbpEnable &=  ~RX_PROM_CH_MASK;        \
+        HalDev->RxMbpEnable |=   RX_PROM_CH(Value)
+
+#define UPDATE_RX_BROAD_CH(Value)                        \
+           HalDev->RxMbpEnable &=  ~RX_BROAD_CH_MASK;    \
+           HalDev->RxMbpEnable |=   RX_BROAD_CH(Value)
+
+#define UPDATE_RX_MULT_CH(Value)                         \
+           HalDev->RxMbpEnable &=  ~RX_MULT_CH_MASK;     \
+           HalDev->RxMbpEnable |=   RX_MULT_CH(Value)
+
+
+
+typedef enum
+  {
+   /*  CPMAC */
+    enCpmacStart=0,
+    enStats0,
+    enStats1,
+    enStats2,
+    enStats3,
+    enStats4,
+    enStatsDump,
+    enStatsClear,
+    enRX_PASS_CRC,
+    enRX_QOS_EN,
+    enRX_NO_CHAIN,
+    enRX_CMF_EN,
+    enRX_CSF_EN,
+    enRX_CEF_EN,
+    enRX_CAF_EN,
+    enRX_PROM_CH,
+    enRX_BROAD_EN,
+    enRX_BROAD_CH,
+    enRX_MULT_EN,
+    enRX_MULT_CH,
+
+    enTX_PTYPE,
+    enTX_PACE,
+    enMII_EN,
+    enTX_FLOW_EN,
+    enRX_FLOW_EN,
+    enCTRL_LOOPBACK,
+
+    enRX_MAXLEN,
+    enRX_FILTERLOWTHRESH,
+    enRX0_FLOWTHRESH,
+    enRX_UNICAST_SET,
+    enRX_UNICAST_CLEAR,
+    enMdioConnect,
+    enMAC_ADDR_GET,
+    enTick,
+    enRX_MULTICAST,
+    enRX_MULTI_ALL,
+    enRX_MULTI_SINGLE,
+    enVersion,
+    enCpmacEnd                                   /* Last entry */
+  }INFO_KEY_CPMAC;
+
+static const char pszVersion[]                 = "Version";
+static const char pszStats0[]                  = "Stats0";
+static const char pszStats1[]                  = "Stats1";
+static const char pszStats2[]                  = "Stats2";
+static const char pszStats3[]                  = "Stats3";
+static const char pszStats4[]                  = "Stats4";
+static const char pszStatsDump[]               = "StatsDump";
+static const char pszStatsClear[]              = "StatsClear";
+
+/********************************************************************
+**
+**  RX MBP ENABLE
+**
+********************************************************************/
+static const char pszRX_PASS_CRC[]             = "RX_PASS_CRC";
+static const char pszRX_QOS_EN[]               = "RX_QOS_EN";
+static const char pszRX_NO_CHAIN[]             = "RX_NO_CHAIN";
+static const char pszRX_CMF_EN[]               = "RX_CMF_EN";
+static const char pszRX_CSF_EN[]               = "RX_CSF_EN";
+static const char pszRX_CEF_EN[]               = "RX_CEF_EN";
+static const char pszRX_CAF_EN[]               = "RX_CAF_EN";
+static const char pszRX_PROM_CH[]              = "RX_PROM_CH";
+static const char pszRX_BROAD_EN[]             = "RX_BROAD_EN";
+static const char pszRX_BROAD_CH[]             = "RX_BROAD_CH";
+static const char pszRX_MULT_EN[]              = "RX_MULT_EN";
+static const char pszRX_MULT_CH[]              = "RX_MULT_CH";
+
+
+/********************************************************************
+**
+**  MAC CONTROL
+**
+********************************************************************/
+static const char pszTX_PTYPE[]                = "TX_PTYPE";
+static const char pszTX_PACE[]                 = "TX_PACE";
+static const char pszMII_EN[]                  = "MII_EN";
+static const char pszTX_FLOW_EN[]              = "TX_FLOW_EN";
+static const char pszRX_FLOW_EN[]              = "RX_FLOW_EN";
+static const char pszCTRL_LOOPBACK[]           = "CTRL_LOOPBACK";
+
+static const char pszRX_MAXLEN[]               = "RX_MAXLEN";
+static const char pszRX_FILTERLOWTHRESH[]      = "RX_FILTERLOWTHRESH";
+static const char pszRX0_FLOWTHRESH[]          = "RX0_FLOWTHRESH";
+static const char pszRX_UNICAST_SET[]          = "RX_UNICAST_SET";
+static const char pszRX_UNICAST_CLEAR[]        = "RX_UNICAST_CLEAR";
+static const char pszMdioConnect[]             = "MdioConnect";
+static const char pszMacAddr[]                 = "MacAddr";
+static const char pszTick[]                    = "Tick";
+
+/********************************************************************
+**
+**  MULTICAST
+**
+********************************************************************/
+
+static const char pszRX_MULTICAST[]            = "RX_MULTICAST";
+static const char pszRX_MULTI_ALL[]            = "RX_MULTI_ALL";
+static const char pszRX_MULTI_SINGLE[]         = "RX_MULTI_SINGLE";
+
+/*
+static const char* pszGFHN = "GFHN";
+*/
+
+static const CONTROL_KEY KeyCpmac[] =
+   {
+     {""                           , enCpmacStart},
+     {pszStats0                    , enStats0},
+     {pszStats1                    , enStats1},
+     {pszStats2                    , enStats2},
+     {pszStats3                    , enStats3},
+     {pszStats4                    , enStats4},
+     {pszStatsClear                , enStatsClear},
+     {pszStatsDump                 , enStatsDump},
+     {pszRX_PASS_CRC               , enRX_PASS_CRC},
+     {pszRX_QOS_EN                 , enRX_QOS_EN},
+     {pszRX_NO_CHAIN               , enRX_NO_CHAIN},
+     {pszRX_CMF_EN                 , enRX_CMF_EN},
+     {pszRX_CSF_EN                 , enRX_CSF_EN},
+     {pszRX_CEF_EN                 , enRX_CEF_EN},
+     {pszRX_CAF_EN                 , enRX_CAF_EN},
+     {pszRX_PROM_CH                , enRX_PROM_CH},
+     {pszRX_BROAD_EN               , enRX_BROAD_EN},
+     {pszRX_BROAD_CH               , enRX_BROAD_CH},
+     {pszRX_MULT_EN                , enRX_MULT_EN},
+     {pszRX_MULT_CH                , enRX_MULT_CH},
+
+     {pszTX_PTYPE                  , enTX_PTYPE},
+     {pszTX_PACE                   , enTX_PACE},
+     {pszMII_EN                    , enMII_EN},
+     {pszTX_FLOW_EN                , enTX_FLOW_EN},
+     {pszRX_FLOW_EN                , enRX_FLOW_EN},
+     {pszCTRL_LOOPBACK             , enCTRL_LOOPBACK},
+     {pszRX_MAXLEN                 , enRX_MAXLEN},
+     {pszRX_FILTERLOWTHRESH        , enRX_FILTERLOWTHRESH},
+     {pszRX0_FLOWTHRESH            , enRX0_FLOWTHRESH},
+     {pszRX_UNICAST_SET            , enRX_UNICAST_SET},
+     {pszRX_UNICAST_CLEAR          , enRX_UNICAST_CLEAR},
+     {pszMdioConnect               , enMdioConnect},
+     {pszRX_MULTICAST              , enRX_MULTICAST},
+     {pszRX_MULTI_ALL              , enRX_MULTI_ALL},
+     {pszRX_MULTI_SINGLE           , enRX_MULTI_SINGLE},
+     {pszTick                      , enTick},
+     {pszVersion                   , enVersion},
+     {""                           , enCpmacEnd}
+   };
+
+const char hcCpuFrequency[]       = "CpuFreq";
+const char hcCpmacFrequency[]     = "CpmacFrequency";
+const char hcMdioBusFrequency[]   = "MdioBusFrequency";
+const char hcMdioClockFrequency[] = "MdioClockFrequency";
+const char hcCpmacBase[]          = "CpmacBase";
+const char hcPhyNum[]             = "PhyNum";
+const char hcSize[]               = "size";
+const char hcCpmacSize[]          = "CpmacSize";
+const char hcPhyAccess[]          = "PhyAccess";
+const char hcLinked[]             = "Linked";
+const char hcFullDuplex[]         = "FullDuplex";
+const char hcMdixMask[]           = "MdixMask";
+const char hcMdioMdixSwitch[]     = "MdixSet";
+#endif
diff -urN linux.old/drivers/net/avalanche_cpmac/Makefile linux.dev/drivers/net/avalanche_cpmac/Makefile
--- linux.old/drivers/net/avalanche_cpmac/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/Makefile	2005-07-12 02:48:42.175574000 +0200
@@ -0,0 +1,26 @@
+# File: drivers/net/avalanche_cpmac/Makefile
+#
+# Makefile for the Linux network (CPMAC) device drivers.
+#
+
+O_TARGET := avalanche_cpmac.o
+
+
+list-multi := avalanche_cpmac.o
+obj-$(CONFIG_MIPS_AVALANCHE_CPMAC) := avalanche_cpmac.o
+
+avalanche_cpmac-objs += cpmac.o            cpmacHalLx.o       hcpmac.o \
+                        	      psp_config_build.o psp_config_mgr.o            \
+				      psp_config_parse.o psp_config_util.o
+
+
+include $(TOPDIR)/Rules.make
+
+
+avalanche_cpmac.o:        $(avalanche_cpmac-objs)
+	$(LD) -r -o $@ $(avalanche_cpmac-objs)
+
+
+
+clean:
+	rm -f core *.o *.a *.s
diff -urN linux.old/drivers/net/avalanche_cpmac/mdio_reg.h linux.dev/drivers/net/avalanche_cpmac/mdio_reg.h
--- linux.old/drivers/net/avalanche_cpmac/mdio_reg.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/mdio_reg.h	2005-07-12 02:48:42.176573000 +0200
@@ -0,0 +1,121 @@
+/****************************************************************************
+**      TNETD53xx Software Support
+**      Copyright(c) 2002, Texas Instruments Incorporated. All Rights Reserved.
+**
+**      FILE: mdio_reg.h   Register definitions for the VBUS MII module
+**
+**      DESCRIPTION:
+**              This include file contains register definitions for the
+**              VBUS MII module.
+**
+**      HISTORY:
+**              27Mar02 Michael Hanrahan Original (modified from emacmdio.h)
+**              01Apr02 Michael Hanrahan Modified to include all regs. in spec
+**              03Apr02 Michael Hanrahan Updated to Version 0.6 of spec
+**              05Apr02 Michael Hanrahan Moved Phy Mode values into here
+**              30Apr02 Michael Hanrahan Updated to Version 0.8 of spec
+**              30Apr02 Michael Hanrahan Updated to recommended format
+**              10May02 Michael Hanrahan Updated to Version 0.9 of spec
+*****************************************************************************/
+#ifndef _INC_MDIO_REG
+#define _INC_MDIO_REG
+
+/***************************************************************************
+**                                                                         
+**         M D I O  M E M O R Y  M A P 
+**                                                                         
+***************************************************************************/
+
+
+#define pMDIO_VER(base)                 ((volatile bit32u *)(base+0x00))
+#define pMDIO_CONTROL(base)             ((volatile bit32u *)(base+0x04))
+#define pMDIO_ALIVE(base)               ((volatile bit32u *)(base+0x08))
+#define pMDIO_LINK(base)                ((volatile bit32u *)(base+0x0C))
+#define pMDIO_LINKINTRAW(base)          ((volatile bit32u *)(base+0x10))
+#define pMDIO_LINKINTMASKED(base)       ((volatile bit32u *)(base+0x14))
+#define pMDIO_USERINTRAW(base)          ((volatile bit32u *)(base+0x20))
+#define pMDIO_USERINTMASKED(base)       ((volatile bit32u *)(base+0x24))
+#define pMDIO_USERINTMASKED_SET(base)   ((volatile bit32u *)(base+0x28))
+#define pMDIO_USERINTMASKED_CLR(base)   ((volatile bit32u *)(base+0x2C))
+#define pMDIO_USERACCESS(base, channel) ((volatile bit32u *)(base+(0x80+(channel*8))))
+#define pMDIO_USERPHYSEL(base, channel) ((volatile bit32u *)(base+(0x84+(channel*8))))
+
+
+/***************************************************************************
+**                                                                         
+**         M D I O  R E G I S T E R  A C C E S S  M A C R O S 
+**                                                                         
+***************************************************************************/
+
+
+#define MDIO_ALIVE(base)                    (*(pMDIO_ALIVE(base)))
+#define MDIO_CONTROL(base)                  (*(pMDIO_CONTROL(base)))
+#define         MDIO_CONTROL_IDLE                 (1 << 31)
+#define         MDIO_CONTROL_ENABLE               (1 << 30)
+#define         MDIO_CONTROL_PREAMBLE             (1 << 20)  
+#define         MDIO_CONTROL_FAULT                (1 << 19)
+#define         MDIO_CONTROL_FAULT_DETECT_ENABLE  (1 << 18)
+#define         MDIO_CONTROL_INT_TEST_ENABLE      (1 << 17)
+#define         MDIO_CONTROL_HIGHEST_USER_CHANNEL (0x1F << 8)
+#define         MDIO_CONTROL_CLKDIV               (0xFF)
+#define MDIO_LINK(base)                     (*(pMDIO_LINK(base)))
+#define MDIO_LINKINTRAW(base)               (*(pMDIO_LINKINTRAW(base)))
+#define MDIO_LINKINTMASKED(base)            (*(pMDIO_LINKINTMASKED(base)))
+#define MDIO_USERINTRAW(base)               (*(pMDIO_USERINTRAW(base)))
+#define MDIO_USERINTMASKED(base)            (*(pMDIO_USERINTMASKED(base)))
+#define MDIO_USERINTMASKED_CLR(base)        (*(pMDIO_USERINTMASKED_CLR(base)))
+#define MDIO_USERINTMASKED_SET(base)        (*(pMDIO_USERINTMASKED_SET(base)))
+#define MDIO_USERINTRAW(base)               (*(pMDIO_USERINTRAW(base)))
+#define MDIO_USERACCESS(base, channel)      (*(pMDIO_USERACCESS(base, channel)))
+#define         MDIO_USERACCESS_GO     (1 << 31)
+#define         MDIO_USERACCESS_WRITE  (1 << 30)
+#define         MDIO_USERACCESS_READ   (0 << 30)
+#define         MDIO_USERACCESS_ACK    (1 << 29)
+#define         MDIO_USERACCESS_REGADR (0x1F << 21)
+#define         MDIO_USERACCESS_PHYADR (0x1F << 16)
+#define         MDIO_USERACCESS_DATA   (0xFFFF)
+#define MDIO_USERPHYSEL(base, channel)      (*(pMDIO_USERPHYSEL(base, channel)))
+#define         MDIO_USERPHYSEL_LINKSEL         (1 << 7)
+#define         MDIO_USERPHYSEL_LINKINT_ENABLE  (1 << 6)
+#define         MDIO_USERPHYSEL_PHYADR_MON      (0x1F)
+#define MDIO_VER(base)                      (*(pMDIO_VER(base)))
+#define         MDIO_VER_MODID         (0xFFFF << 16)
+#define         MDIO_VER_REVMAJ        (0xFF   << 8)
+#define         MDIO_VER_REVMIN        (0xFF)
+
+
+
+
+/****************************************************************************/
+/*                                                                          */
+/*         P H Y   R E G I S T E R  D E F I N I T I O N S                   */
+/*                                                                          */
+/****************************************************************************/
+
+
+#define PHY_CONTROL_REG       0
+  #define PHY_RESET           (1<<15)
+  #define PHY_LOOP            (1<<14)
+  #define PHY_100             (1<<13)
+  #define AUTO_NEGOTIATE_EN   (1<<12)
+  #define PHY_PDOWN           (1<<11)
+  #define PHY_ISOLATE         (1<<10)
+  #define RENEGOTIATE         (1<<9)
+  #define PHY_FD              (1<<8)
+
+#define PHY_STATUS_REG        1
+  #define NWAY_COMPLETE       (1<<5)
+  #define NWAY_CAPABLE        (1<<3)
+  #define PHY_LINKED          (1<<2)
+
+#define NWAY_ADVERTIZE_REG    4
+#define NWAY_REMADVERTISE_REG 5
+  #define NWAY_FD100          (1<<8)
+  #define NWAY_HD100          (1<<7)
+  #define NWAY_FD10           (1<<6)
+  #define NWAY_HD10           (1<<5)
+  #define NWAY_SEL            (1<<0)
+  #define NWAY_AUTO           (1<<0)
+
+
+#endif _INC_MDIO_REG
diff -urN linux.old/drivers/net/avalanche_cpmac/psp_config_build.c linux.dev/drivers/net/avalanche_cpmac/psp_config_build.c
--- linux.old/drivers/net/avalanche_cpmac/psp_config_build.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/psp_config_build.c	2005-07-12 02:48:42.176573000 +0200
@@ -0,0 +1,335 @@
+/******************************************************************************
+ * FILE PURPOSE:    PSP Config Manager - Configuration Build Source
+ ******************************************************************************
+ * FILE NAME:       psp_config_build.c
+ *
+ * DESCRIPTION:     Configuration Build API Implementation
+ *
+ * REVISION HISTORY:
+ * 27 Nov 02 - PSP TII  
+ *
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+
+#ifdef INCLUDE_FFS
+#include "ffs.h"
+#endif /* INCLUDE_FFS */
+
+#include "psp_config_mgr.h"
+#include "psp_config_build.h"
+#include "psp_config_util.h"
+
+#define MAX_DEVICE_NAME_LEN     16
+#define MAX_DEVICE_STR_LEN      512
+
+#ifndef NULL
+#define NULL (char *)0
+#endif
+
+#include <asm/ar7/sangam.h>
+#include <linux/slab.h>
+#include <linux/config.h>
+
+
+#define os_malloc(size) kmalloc(size, GFP_KERNEL)
+
+int psp_run_enumerator(void)
+{
+    return(0);
+}
+
+#if defined (CONFIG_AVALANCHE_CPMAC_AUTO)
+
+static int auto_detect_cpmac_phy(void)
+{
+
+#define SELECT_INT_PHY_MAC 0
+#define SELECT_EXT_PHY_MAC 1
+
+    volatile unsigned long *reset_cntl = AVALANCHE_RESET_CONTROL_BASE, *mdio_cntl  = ((int)AVALANCHE_MDIO_BASE + 0x4);
+    unsigned int j= 0, detected_phy_map = 0, auto_select = SELECT_INT_PHY_MAC;
+                                                                                                                   
+    *reset_cntl |= (1 << AVALANCHE_MDIO_RESET_BIT) | (1 << AVALANCHE_LOW_CPMAC_RESET_BIT) | (1 << AVALANCHE_HIGH_CPMAC_RESET_BIT) | (1 << AVALANCHE_LOW_EPHY_RESET_BIT);                                 
+    *mdio_cntl   = (1 << 30) | ((CONFIG_AR7_SYS * 1000)/2200);                                              
+                                                                                                                   
+    for(j=0;j < 300000; j++) 
+    { 
+        if(j%100000) continue;
+
+        detected_phy_map = *(mdio_cntl + 1);
+        if(detected_phy_map) 
+        {
+            detected_phy_map &= ~AVALANCHE_LOW_CPMAC_PHY_MASK;
+                
+            if(detected_phy_map && !(detected_phy_map & (detected_phy_map - 1)))
+            {
+                auto_select = SELECT_EXT_PHY_MAC;
+                break;
+            }
+        } 
+    }
+
+    return(auto_select);
+
+}
+
+#endif
+
+
+#ifndef AVALANCHE_LOW_CPMAC_MDIX_MASK
+#define AVALANCHE_LOW_CPMAC_MDIX_MASK 0
+#endif
+
+void psp_load_default_static_cfg(void)
+{
+    char s2[100],  s3[100];
+    char s4[2000], s6[2000];
+    int threshold = 20;
+    char *tx_threshold_ptr = prom_getenv("threshold");
+    
+    if(tx_threshold_ptr)
+      threshold = simple_strtol(tx_threshold_ptr, (char **)NULL, 10);
+
+    /* Static configuration if options.conf not present */
+    sprintf(s3,"cpmdio(id=mii, base=%u, reset_bit=%d)", AVALANCHE_MDIO_BASE, 22);
+    sprintf(s2, "reset( id=[ResetRegister], base=%u)", AVALANCHE_RESET_CONTROL_BASE);
+
+    sprintf(s4, "cpmac(id=[cpmac], unit=0, base=%u, size=0x800, reset_bit=%d, PhyMask=%u, MdixMask=%u, MLink=0, int_line=%d, memory_offset=0, RX_CAF=1, RX_PASSCRC=0, RX_CEF=1, RX_BCAST=0, RX_BCASTCH=0, Ch0=[TxNumBuffers=256, TxNumQueues=1, TxServiceMax=%d, RxNumBuffers=256, RxBufferOffset=0, RxBufSize=1000, RxServiceMax=128], Ch1=[TxNumBuffers=256, TxNumQueues=1, TxServiceMax=%d, RxNumBuffers=256, RxBufferOffset=0, RxBufSize=1000, RxServiceMax=128], Ch2=[TxNumBuffers=256, TxNumQueues=1, TxServiceMax=%d, RxNumBuffers=256, RxBufferOffset=0, RxBufSize=1000, RxServiceMax=128])", AVALANCHE_LOW_CPMAC_BASE, AVALANCHE_LOW_CPMAC_RESET_BIT, AVALANCHE_LOW_CPMAC_PHY_MASK, AVALANCHE_LOW_CPMAC_MDIX_MASK, AVALANCHE_LOW_CPMAC_INT,threshold,threshold,threshold);
+
+    sprintf(s6, "cpmac(id=[cpmac], unit=1, base=%u, size=0x800, reset_bit=%d, PhyMask=%u, MLink=0, int_line=%d, memory_offset=0, RX_CAF=1, RX_PASSCRC=0, RX_CEF=1, RX_BCAST=0, RX_BCASTCH=0, Ch0=[TxNumBuffers=256, TxNumQueues=1, TxServiceMax=%d, RxNumBuffers=256, RxBufferOffset=0, RxBufSize=1000, RxServiceMax=128], Ch1=[TxNumBuffers=256, TxNumQueues=1, TxServiceMax=%d, RxNumBuffers=256, RxBufferOffset=0, RxBufSize=1000, RxServiceMax=128], Ch2=[TxNumBuffers=256, TxNumQueues=1, TxServiceMax=%d, RxNumBuffers=256, RxBufferOffset=0, RxBufSize=1000, RxServiceMax=128])", AVALANCHE_HIGH_CPMAC_BASE, AVALANCHE_HIGH_CPMAC_RESET_BIT, AVALANCHE_HIGH_CPMAC_PHY_MASK, AVALANCHE_HIGH_CPMAC_INT,threshold,threshold,threshold);
+
+    psp_config_add("reset", s2, psp_config_strlen(s2), en_compile);
+
+
+#if defined (CONFIG_AVALANCHE_LOW_CPMAC)
+
+    psp_config_add("cpmdio", s3, psp_config_strlen(s3), en_compile);
+    psp_config_add("cpmac", s4, psp_config_strlen(s4), en_compile);
+
+#endif
+
+
+#if defined (CONFIG_AVALANCHE_HIGH_CPMAC)
+
+    psp_config_add("cpmdio", s3, psp_config_strlen(s3), en_compile);
+    psp_config_add("cpmac", s6, psp_config_strlen(s6), en_compile);
+
+#endif
+
+#if defined (CONFIG_AVALANCHE_CPMAC_AUTO)
+    { 
+        char *phy_sel_ptr = prom_getenv("mac_phy_sel"); 
+        int   phy_sel = SELECT_EXT_PHY_MAC;
+        char *mac_port = prom_getenv("MAC_PORT"); /* Internal: 0, External: 1 */
+
+        if(phy_sel_ptr && (0 == strcmp(phy_sel_ptr, "int")))
+        {
+            phy_sel = SELECT_INT_PHY_MAC;
+        }
+
+        //if(phy_sel == auto_detect_cpmac_phy())
+        if(!mac_port || 0 == strcmp(mac_port, "1"))
+        {
+            printk("Using the MAC with external PHY\n");
+            psp_config_add("cpmdio", s3, psp_config_strlen(s3), en_compile);
+            psp_config_add("cpmac", s6, psp_config_strlen(s6), en_compile);
+        }
+        else
+        {
+            printk("Using the MAC with internal PHY\n");
+            psp_config_add("cpmdio", s3, psp_config_strlen(s3), en_compile);
+            psp_config_add("cpmac", s4, psp_config_strlen(s4), en_compile);
+        }
+    }
+                      
+#endif    
+
+}
+
+char* psp_conf_read_file(char *p_file_name)
+{
+#ifdef INCLUDE_FFS
+    
+    char        *p_file_data = NULL;
+    unsigned int file_size;
+    FFS_FILE    *p_file = NULL;
+
+    if(p_file_name == NULL)
+    {
+        return (NULL);
+    }
+
+    if(!(p_file = ffs_fopen(p_file_name, "r"))) 
+    {
+        return(NULL);
+    }
+
+    file_size = p_file->_AvailableBytes;
+
+    p_file_data = os_malloc(file_size + 1);
+    
+    if(ffs_fread(p_file_data, file_size, 1, p_file) == 0)
+    {
+        kfree(p_file_data);
+        return(NULL);
+    }
+
+    ffs_fclose(p_file);
+   
+    p_file_data[file_size] = '\0';
+
+    return(p_file_data);
+    
+#else /* NO FFS */
+    return(NULL);
+#endif /* INCLUDE_FFS */
+}
+
+int psp_conf_get_line(char *p_in_data, char **next_line)
+{
+    char *p       = p_in_data;
+
+    while(*p && *p++ != '\n')
+    {
+
+    } 
+   
+    *next_line = p;
+
+    return(p - 1 - p_in_data);
+}
+
+
+int psp_conf_is_data_line(char *line)
+{
+    int ret_val = 1;
+
+    if(*line == '\0' || *line == '\n' || *line == '#')
+        ret_val = 0;
+
+    return(ret_val);
+}
+
+int psp_conf_get_key_size(char *data)
+{
+    char *p = data;
+
+    while(*p && *p != '\n' && *p != '(' && *p != ' ')
+        p++;
+
+    return(p - data);
+}
+
+char* psp_conf_eat_white_spaces(char *p)
+{
+    while(*p && *p != '\n' && *p == ' ')
+        p++;
+
+    return (p);
+}
+
+int psp_build_from_opt_conf(void)
+{
+    char *data       = NULL;
+    char *data_hold  = NULL;
+    char *next_line  = NULL; 
+    int  line_size   = 0;
+
+    if((data = psp_conf_read_file("/etc/options.conf")) == NULL)
+        return(-1);
+
+    data_hold = data;
+
+    while((line_size=psp_conf_get_line(data, &next_line)) != -1)
+    {
+
+        char *name = NULL;
+        int  name_size; 
+ 
+    data = psp_conf_eat_white_spaces(data);
+
+        if(psp_conf_is_data_line(data))
+        {
+            data[line_size] = '\0';
+ 
+            name_size = psp_conf_get_key_size(data);
+           
+            if(name_size > 0) 
+            {
+                name = (char *) os_malloc(name_size + 1);
+                if(name == NULL) break;
+
+                psp_config_memcpy(name, data, name_size);
+                name[name_size] = '\0';
+
+                psp_config_add(name, data, line_size, en_opt_conf);
+            
+                kfree(name);
+            }
+
+            data[line_size] = '\n';
+        }
+
+        data = next_line;
+    }
+
+    kfree(data_hold);
+    return (0);
+}
+
+
+int psp_write_conf_file(char *p_write_file, char * dev_cfg_string)
+{
+#ifdef INCLUDE_FFS
+    int bytes_written=0;
+        FFS_FILE *file_ptr=NULL;    
+ 
+    /*
+     * NOTE: In current implementation of FFS in ADAM2 if the file exists beforehand, it
+     * can't be opened for write.
+     */
+        if(!(file_ptr=ffs_fopen(p_write_file, "w"))) {
+        return(-1);
+        }
+    
+    /* Write into the file "output.con" the character string */
+    /* write a \n before a writing a line */
+    if(!(bytes_written = ffs_fwrite("\n", 1, sizeof(char), file_ptr))) {
+        return (-1);
+    }
+    
+    if(!(bytes_written = ffs_fwrite(dev_cfg_string, psp_config_strlen(dev_cfg_string), sizeof(char), file_ptr))) {
+        return (-1);        
+    }
+    ffs_fclose(file_ptr);
+    return (bytes_written+1);
+#else /* NO FFS */
+    return(-1);
+#endif /* INCLUDE_FFS */
+}
+
+void build_psp_config(void)
+{
+
+    /* initialize the repository. */
+    psp_config_init();
+    
+#ifdef INCLUDE_FFS
+    ffs_init();
+#endif /* INCLUDE_FFS */
+
+    /* read the configuration from the options.conf to override default ones */
+    psp_build_from_opt_conf();
+
+    /* read the configuration which were not over ridden in options.conf */
+    psp_load_default_static_cfg();
+
+    /* let the vlynq be enumerated. Enumerator will add cfg info
+       of the discovered device instances to the repository.*/
+    psp_run_enumerator();
+
+    /* dump the repository*/
+    dump_device_cfg_pool();
+
+}
+
diff -urN linux.old/drivers/net/avalanche_cpmac/psp_config_build.h linux.dev/drivers/net/avalanche_cpmac/psp_config_build.h
--- linux.old/drivers/net/avalanche_cpmac/psp_config_build.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/psp_config_build.h	2005-07-12 02:48:42.176573000 +0200
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * FILE PURPOSE:    PSP Config Manager - Configuration Build Header
+ ******************************************************************************
+ * FILE NAME:       psp_config_build.h
+ *
+ * DESCRIPTION:     Configuration Build API's.
+ *
+ * REVISION HISTORY:
+ * 27 Nov 02 - PSP TII  
+ *
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+
+#ifndef __PSP_CONF_BUILD_H__
+#define __PSP_CONF_BUILD_H__
+
+/*------------------------------------------------------------------------------
+ * Name: psp_conf_read_file
+ *
+ * Parameters: 
+ *         in: p_file_name - the name of the file to read from.
+ *
+ * Description:
+ *     Reads the entire file in one shot. This function opens  the 
+ *     file, determines the size of the data to be read, allocates 
+ *     the required memory, NULL terminates the data and closes the
+ *     file.
+ *
+ *     It is responsibily of the callee to free the memory after it is
+ *     done with that data.
+ *    
+ *
+ * Returns:
+ *     A NULL pointer, if failed to read the data otherwise, a valid
+ *     pointer referring to the data read from the file.
+ *
+ * Example: 
+ *   
+ *     psp_conf_read_file("/etc/options.conf");
+ *---------------------------------------------------------------------------*/
+ char *psp_conf_read_file(char *p_file_name);
+
+ /*----------------------------------------------------------------------------
+  * Function : psp_conf_write_file
+  *
+  * Parameters:
+  *         in: p_file_name - the file to which data is to be written.
+  *         in: data        - the NULL terminated data string.
+  *
+  * Description:
+  *     Write the indicated data into the file. This function opens the file,
+  *     appends the data to end of the file, closes the file. 
+  *
+  * Returns:
+  *
+  *     The number of bytes on success. 
+  *     0 on failure.
+  *
+  * Example:
+  *
+  *     psp_conf_write_file("/etc/outcon.conf", data);
+  *--------------------------------------------------------------------------*/
+ int   psp_conf_write_file(char *p_file_name, char *data);
+
+ /*----------------------------------------------------------------------------
+  * Function: psp_conf_get_line
+  *
+  * Parameters:
+  *         in: data      - the data from which the line is to identified.
+  *        out: next_line - the pointer to start of the next line. 
+  *
+  * Description:
+  *     Expects the data to be '\n' separated segments and data is NULL 
+  *     terminated. Parses the given data for '\n' or '\0'. Provides a pointer
+  *     to the start of next line in the next_line. 
+  *
+  * Returns:
+  *     -1 on error.
+  *      0 or more to indicate the number of bytes in the line starting at 
+  *      data.
+  *--------------------------------------------------------------------------*/
+ int psp_get_conf_line(char *p_in_data, char **next_line);
+
+ /*----------------------------------------------------------------------------
+  * Function: psp_conf_is_data_line
+  *
+  * Parameters:
+  *         in: line - the array of bytes.
+  *
+  * Description:
+  *     Tests the first byte in the array for '\0' or '\n' or '#'. Lines 
+  *     starting with these characters are not considered data.
+  *
+  * Returns:
+  *     1 if the line has data.
+  *     0 otherwise.
+  *
+  *--------------------------------------------------------------------------*/
+ int psp_conf_is_data_line(char *line);
+
+ /*----------------------------------------------------------------------------
+  * Function: psp_conf_eat_white_spaces
+  *
+  * Parameters:
+  *         in: line - the array of bytes.
+  *
+  * Description:
+  *     Eats white spaces at the begining of the line while looking out for 
+  *     '\0' or '\n' or ' '.
+  * 
+  * Returns:
+  *     Pointer to the begining of the non white space character. 
+  *     NULL if '\0' or '\n' is found.
+  *
+  *--------------------------------------------------------------------------*/
+  char *psp_conf_eat_white_spaces(char *line);
+
+  /*---------------------------------------------------------------------------
+   * Function: psp_conf_get_key_size
+   *
+   * Parameters:
+   *         in: line - the array of bytes.
+   *
+   * Description:
+   *     Identifies the size of the 'key' in array formatted as 
+   *     key(id=[key1]....). This function also checks out for '\0' and '\n'.
+   *
+   * Returns:
+   *     On success, The number of bytes that forms the key. 
+   *     0 otherwise. 
+   *     
+   *-------------------------------------------------------------------------*/
+  int psp_conf_get_key_size(char *line);
+
+
+
+#endif /* __PSP_CONF_BUILD_H__ */
+
diff -urN linux.old/drivers/net/avalanche_cpmac/psp_config_mgr.c linux.dev/drivers/net/avalanche_cpmac/psp_config_mgr.c
--- linux.old/drivers/net/avalanche_cpmac/psp_config_mgr.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/psp_config_mgr.c	2005-07-12 02:48:42.177573000 +0200
@@ -0,0 +1,464 @@
+/******************************************************************************
+ * FILE PURPOSE:    PSP Config Manager Source
+ ******************************************************************************
+ * FILE NAME:       psp_config_mgr.c
+ *
+ * DESCRIPTION:
+ *
+ * Manages configuration information. The repository is managed on the basis of 
+ * <key, info> pair. It is possible to have multiple occurrence of the same key. 
+ * Multiple occurences of the same keys are referred to as 'instances'. 
+ * 'instances' are assigned in the order of configuration arrival. The first 
+ * config for a 'key' added to the repository would be treated as instance 0 and
+ * next config to arrive for the same key would be treated as instance '1' and 
+ * so on.
+ * 
+ * Info is retrieved from the repository based on the 'key' and 'instance' value.
+ *
+ * No assumption is made about the format of the information that is put in the 
+ * repository. The only requirement is that 'key' should be NULL terminated 
+ * string.
+ *
+ * REVISION HISTORY:
+ * 27 Nov 02 - PSP TII  
+ *
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+
+//#include <stdio.h>
+//#include <stdlib.h>
+#include "psp_config_mgr.h"
+#include "psp_config_util.h"
+
+#include <linux/slab.h>
+
+/*-----------------------------------------------------------
+  Implemented elsewhere
+ -----------------------------------------------------------*/
+extern int sys_read_options_conf(void);
+extern int sys_write_options_conf(char *cfg_info);
+extern int sys_load_default_static_cfg(void);
+extern int sys_run_enumerator(void);
+
+#define os_malloc(size) kmalloc(size, GFP_KERNEL)
+
+/*---------------------------------------------------------
+ * Data structures.
+ *--------------------------------------------------------*/
+struct device_cfg_data;
+
+typedef struct device_instance_cfg_data
+{
+    struct device_instance_cfg_data       *next;
+    char                                  locale[100];
+    unsigned int                          data_size;
+    char                                  *data;
+
+} DEV_INSTANCE_CFG_DATA_T;
+
+struct device_cfg_collection;
+
+typedef struct device_cfg_collection
+{
+    struct device_cfg_collection *next;
+    char                         *device_name;
+    CFG_TYPE_T                   cfg_type;
+    int                          count;
+    DEV_INSTANCE_CFG_DATA_T      *dev_inst_list_begin;
+    DEV_INSTANCE_CFG_DATA_T      *dev_inst_list_end;
+} DEVICE_CFG_T;
+
+
+typedef struct device_cfg_list
+{
+    DEVICE_CFG_T   *device_cfg_begin;
+    int            count;
+} DEVICE_CFG_LIST_T;
+
+/*-----------------------------------------------------------------------------
+ * Functions used locally with in the file.
+ *---------------------------------------------------------------------------*/
+static void p_init_device_cfg_list(void);
+static int  p_add_instance_cfg_data(DEVICE_CFG_T            *p_dev_cfg,
+                                    DEV_INSTANCE_CFG_DATA_T *p_dev_inst_data);
+static DEVICE_CFG_T* p_create_dev_cfg(char *device_name);
+static DEVICE_CFG_T* p_get_dev_cfg(char *device_name);
+static int p_set_device_cfg_type(DEVICE_CFG_T     *p_dev_cfg,
+                                 CFG_TYPE_T       cfg_type);
+
+/* PSP Config manager debug */                                 
+#define PSP_CFG_MGR_DEBUG 0
+
+#define dbgPrint if (PSP_CFG_MGR_DEBUG) printk
+
+/*-----------------------------------------------------------------------------
+ * The repository.
+ *---------------------------------------------------------------------------*/
+static DEVICE_CFG_LIST_T g_device_cfg_list;
+
+/*---------------------------------------------
+ * Initialize the device collection pool.
+ *--------------------------------------------*/ 
+void p_init_device_cfg_list(void)
+{
+    g_device_cfg_list.count = 0;
+    g_device_cfg_list.device_cfg_begin = NULL;
+}
+
+/*----------------------------------------------------------------------
+ * Add the device cfg into the device linked list.
+ *---------------------------------------------------------------------*/
+int p_add_dev_cfg_to_list(DEVICE_CFG_LIST_T *p_dev_list,
+                          DEVICE_CFG_T      *p_dev_cfg)
+{
+    if(p_dev_list->count != 0)
+        p_dev_cfg->next            = p_dev_list->device_cfg_begin;
+
+    p_dev_list->device_cfg_begin   = p_dev_cfg;
+
+    p_dev_list->count++;
+
+    return (0);
+}
+
+/*------------------------------------------------------------------
+ * Add the cfg data into the cfg data linked list of the collection.
+ *------------------------------------------------------------------*/
+int p_add_instance_cfg_data(DEVICE_CFG_T                 *p_dev_cfg,
+                            DEV_INSTANCE_CFG_DATA_T      *p_dev_inst_data)
+{
+    if(p_dev_cfg->count == 0)
+        p_dev_cfg->dev_inst_list_begin     = p_dev_inst_data;
+    else
+        p_dev_cfg->dev_inst_list_end->next = p_dev_inst_data;
+        
+    p_dev_cfg->dev_inst_list_end           = p_dev_inst_data;
+
+    p_dev_cfg->count++;
+    
+    return (0);
+}
+
+/*-----------------------------------------------------------------------------
+ * Create the device cfg.
+ *---------------------------------------------------------------------------*/
+DEVICE_CFG_T *p_create_dev_cfg(char *device_name)
+{
+    DEVICE_CFG_T *p_dev_cfg = NULL;
+
+    if((p_dev_cfg = os_malloc(sizeof(DEVICE_CFG_T))) == NULL)
+    {
+        dbgPrint("Failed to allocate memory for DEVICE_CFG_T.\n");
+    }
+    else if((p_dev_cfg->device_name = os_malloc(psp_config_strlen(device_name) + 1))==NULL)
+    {
+        dbgPrint("Failed to allocate memory for device name.\n");
+    }
+    else
+    {
+        psp_config_strcpy(p_dev_cfg->device_name, device_name);
+        p_dev_cfg->cfg_type = en_raw;
+        p_dev_cfg->count = 0;
+        p_dev_cfg->dev_inst_list_begin = NULL;
+        p_dev_cfg->dev_inst_list_end   = NULL;
+        p_dev_cfg->next                = NULL;
+    }
+
+    return(p_dev_cfg);
+}
+
+/*------------------------------------------------------------------------------
+ * Get the device cfg collection.
+ *-----------------------------------------------------------------------------*/
+DEVICE_CFG_T *p_get_dev_cfg(char *device_name)
+{
+    int count               = 0;
+    DEVICE_CFG_T *p_dev_cfg = g_device_cfg_list.device_cfg_begin;
+
+    for(count=0; count < g_device_cfg_list.count; count++)
+    {
+        if(psp_config_strcmp(device_name, p_dev_cfg->device_name) == 0)
+        {
+            break;
+        }
+
+        p_dev_cfg = p_dev_cfg->next;
+    }
+    
+    return(p_dev_cfg); 
+}
+
+/*-------------------------------------------------------------------------
+ * Gets the name for the static cfg type. Utility function. Debug purposes.
+ *-------------------------------------------------------------------------*/
+char *p_get_cfg_type_name_for_en(CFG_TYPE_T  cfg_type)
+{
+    static char raw_str      [] = "still raw";
+    static char compile_str  [] = "configured at compile time";
+    static char optconf_str  [] = "configured by options.conf";
+    static char vlynq_str    [] = "configured by VLYNQ";
+    static char no_static_str[] = "no static configuration";
+
+    if(cfg_type == en_raw)
+        return (raw_str);
+    else if(cfg_type == en_compile)
+        return (compile_str);
+    else if(cfg_type == en_opt_conf)
+        return (optconf_str);
+    else if(cfg_type == en_vlynq)
+        return (vlynq_str);
+    else
+        return (no_static_str);
+
+}
+
+/*-----------------------------------------------------------------------------
+ * Sets the static cfg status of the device collection.
+ *
+ * If the collection is en_virgin then, the collection is assigned to cfg_type.
+ * If the cfg_type is en_vlynq then, the old cfg_type is retained. 
+ * en_compile and en_opt_conf are mutually exclusive. One of these can be 
+ * accomodated.
+ *
+ *---------------------------------------------------------------------------*/
+int p_set_device_cfg_type(DEVICE_CFG_T    *p_dev_cfg,
+                          CFG_TYPE_T      cfg_type)
+{
+    int ret_val = 0;
+
+    if(p_dev_cfg->cfg_type == en_raw)
+        p_dev_cfg->cfg_type = cfg_type;
+    else if((cfg_type == en_vlynq) || (p_dev_cfg->cfg_type == cfg_type))
+        ;
+    else
+    {
+        dbgPrint("Device %s has been %s which overrides %s.\n",
+                  p_dev_cfg->device_name,
+                  p_get_cfg_type_name_for_en(p_dev_cfg->cfg_type),
+                  p_get_cfg_type_name_for_en(cfg_type));
+        ret_val = -1;
+    }
+
+    return(ret_val);
+}
+
+/*------------------------------------------------------------------------
+ * Add the config str into the repository. The cfg type indicates
+ * whether the device has been configured statically, from options.conf or
+ * by vlynq enumeration.
+ *------------------------------------------------------------------------*/
+int psp_config_add(char *key, void *p_cfg_str, unsigned int cfg_len, 
+                   CFG_TYPE_T cfg_type)
+{
+    int                     ret_val           = -1;
+    DEVICE_CFG_T            *p_dev_cfg        = NULL;
+    DEV_INSTANCE_CFG_DATA_T *p_dev_inst_data  = NULL;  
+
+    if(p_cfg_str == NULL || key == NULL)
+    {
+        dbgPrint("Null input pointer(s).\n");
+    }
+    /* check if there exist a dev_cfg for the given key, if not,
+       then create one and add it to the device list. */
+    else if(((p_dev_cfg = p_get_dev_cfg(key)) == NULL) &&
+            (((p_dev_cfg = p_create_dev_cfg(key)) == NULL) ||
+               p_add_dev_cfg_to_list(&g_device_cfg_list, p_dev_cfg) != 0))
+    {
+        dbgPrint("Failed to allocate mem or add dev cfg for %s.\n", key);
+    }
+    /* make sure that we can add this cfg type to the repository */
+    else if(p_set_device_cfg_type(p_dev_cfg, cfg_type) == -1)
+    {
+        dbgPrint("Ignoring \"%s\" for device \"%s\".\n",
+                  p_get_cfg_type_name_for_en(cfg_type),  
+                  p_dev_cfg->device_name); 
+    }
+    else if((p_dev_inst_data = os_malloc(sizeof(DEV_INSTANCE_CFG_DATA_T)))== NULL)
+    {
+        dbgPrint("Failed to allocate memory for DEV_INSTANCE_CFG_DATA_T.\n");
+    }
+    else if((p_dev_inst_data->data = os_malloc(cfg_len) + 1) == NULL)
+    {
+        dbgPrint("Failed to allocate memory for the config data.\n");
+    }
+    else
+    {
+        p_dev_inst_data->next = NULL;
+
+        if(cfg_type == en_opt_conf || cfg_type == en_compile)
+            psp_config_strcpy(p_dev_inst_data->locale, "dev on chip ");
+        else if(cfg_type == en_vlynq)
+            psp_config_strcpy(p_dev_inst_data->locale, "dev on vlynq");
+        else 
+            psp_config_strcpy(p_dev_inst_data->locale, "dev locale ?");
+
+        psp_config_memcpy(p_dev_inst_data->data, p_cfg_str, cfg_len);
+        p_dev_inst_data->data_size = cfg_len;
+        *(p_dev_inst_data->data + cfg_len) = '\0';
+
+        ret_val = p_add_instance_cfg_data(p_dev_cfg, p_dev_inst_data);
+    } 
+
+    return(ret_val);
+}
+
+/*-------------------------------------------------------------
+ * Get the total number of device instances in the repository
+ *------------------------------------------------------------*/
+int psp_config_get_num_keys(void)
+{
+    return(g_device_cfg_list.count);
+}
+
+
+/*--------------------------------------------------------------------
+ * Get the device configuration info from the repository.
+ *-------------------------------------------------------------------*/
+int psp_config_get(char *key, int instance, char **cfg_data_out)
+{
+    int ret_val             = -1;
+    DEVICE_CFG_T *p_dev_cfg = NULL;
+    *cfg_data_out           = NULL;
+
+    if(key == NULL && cfg_data_out == NULL)
+    {
+        dbgPrint("Key has a NULL value.\n");
+    }
+    else if((p_dev_cfg = p_get_dev_cfg(key)) == NULL)
+    {
+        dbgPrint("cfg information for %s could not be found.\n", key);
+    }
+    else if(p_dev_cfg->count)
+    {
+         DEV_INSTANCE_CFG_DATA_T *p_dev_inst_data = 
+                                  p_dev_cfg->dev_inst_list_begin;
+         int index = 0;
+         for(index = 0; 
+             index != instance && index < p_dev_cfg->count; 
+             index++)
+         {
+             p_dev_inst_data = p_dev_inst_data->next;
+         }
+
+         if(p_dev_inst_data != NULL && p_dev_inst_data->data != NULL)
+         {
+             *cfg_data_out = p_dev_inst_data->data;
+             ret_val = p_dev_inst_data->data_size;
+         }
+    }
+
+    return (ret_val);
+}
+
+/*----------------------------------------------------------------
+ * Returns the number of instances found in the repository for the
+ * specified key.
+ *---------------------------------------------------------------*/
+int psp_config_get_num_instances(char *key)
+{
+    int ret_val             = 0;
+    DEVICE_CFG_T *p_dev_cfg = NULL;
+
+    if(key == NULL)
+    {
+        dbgPrint("Key has a NULL value.\n");
+    }
+    else if((p_dev_cfg = p_get_dev_cfg(key)) == NULL)
+    {
+        dbgPrint("cfg information for %s could not be found.\n", key);
+    }
+    else
+    {
+        ret_val = p_dev_cfg->count;
+    }
+    
+    return (ret_val);
+}
+
+/*------------------------------------------------------------------
+ * Dump the configuration repository. 
+ * Caution: DO NOT USE THIS FOR ANY NON NBU specified config format.
+ *-----------------------------------------------------------------*/
+void psp_config_print(char *key)
+{
+    DEVICE_CFG_T *p_dev_cfg = NULL;
+
+    if(key == NULL)
+    {
+        dbgPrint("Key has a NULL value.\n");
+    }
+    else if((p_dev_cfg = p_get_dev_cfg(key)) == NULL)
+    {
+        dbgPrint("cfg information for %s could not be found.\n", key);
+    }
+    else if(p_dev_cfg && p_dev_cfg->count)
+    {
+        DEV_INSTANCE_CFG_DATA_T   *p_dev_inst_data;
+
+        p_dev_inst_data = p_dev_cfg->dev_inst_list_begin;
+
+        do
+        {
+            dbgPrint("%s : %s\n", p_dev_inst_data->locale, 
+                      p_dev_inst_data->data);
+            p_dev_inst_data = p_dev_inst_data->next;
+
+        } while(p_dev_inst_data);
+    }
+    else
+    {
+        dbgPrint("Nothing was found for %s.\n", key);
+    }
+}
+
+void dump_device_cfg_pool(void)
+{
+    DEVICE_CFG_T *p_dev_cfg = g_device_cfg_list.device_cfg_begin;
+    
+    if(p_dev_cfg != NULL && g_device_cfg_list.count)
+    {
+        int index=0;
+
+        for(index=0; index < g_device_cfg_list.count; index++)
+        {
+            psp_config_print(p_dev_cfg->device_name);
+            p_dev_cfg = p_dev_cfg->next;
+        }
+    }
+    else
+    {
+        dbgPrint("repository is empty.\n");
+    }
+}
+
+void psp_config_init(void)
+{
+    p_init_device_cfg_list();
+}
+
+void psp_config_cleanup()                                                       
+{                                                                               
+    int dev_count              = 0;                                             
+    int inst_count             = 0;                                             
+    DEVICE_CFG_T            *p = g_device_cfg_list.device_cfg_begin;            
+    DEV_INSTANCE_CFG_DATA_T *q = NULL;                                          
+                                                                                
+    for(dev_count = 0; dev_count < g_device_cfg_list.count; dev_count++)        
+    {                                                                           
+        DEVICE_CFG_T            *p_temp = NULL;                                 
+        if(p) q = p->dev_inst_list_begin;                                       
+                                                                                
+        for(inst_count = 0; inst_count < p->count && q != NULL; inst_count++)   
+        {                                                                       
+            DEV_INSTANCE_CFG_DATA_T *q_temp = q;                                
+            q_temp = q->next;                                                   
+            kfree(q->data);                                                     
+            kfree(q);                                                           
+            q = q_temp;                                                         
+        }                                                                       
+                                                                                
+        p_temp = p->next;                                                       
+        kfree(p);                                                               
+        p = p_temp;                                                             
+    }                                                                           
+}                                                                               
diff -urN linux.old/drivers/net/avalanche_cpmac/psp_config_mgr.h linux.dev/drivers/net/avalanche_cpmac/psp_config_mgr.h
--- linux.old/drivers/net/avalanche_cpmac/psp_config_mgr.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/psp_config_mgr.h	2005-07-12 02:48:42.177573000 +0200
@@ -0,0 +1,110 @@
+/******************************************************************************
+ * FILE PURPOSE:    PSP Config Manager Header
+ ******************************************************************************
+ * FILE NAME:       psp_config_mgr.h
+ *
+ * DESCRIPTION:     Storing and retrieving the configuration based on key
+ * A set of APIs to be used by one and sundry (including drivers and enumerator) to build
+ * and read cfg information of the devices for an avalanche SOC.
+ *
+ * This set of APIs isolates the configuration management from the world and provides simple
+ * access convinience.
+ *
+ * Device in this set refers to the peripherals that can be found on the SOC or on VLYNQ.
+ * The configuration is stored in the form of string and drivers can use these APIs to get
+ * a particular parameter value.
+ *
+ * The memory allocation for the pass back parameters is done by the caller.
+ *
+ * 0 is returned for SUCCESS or TRUE.
+ *  -1 is returned for FAILURE or FALSE.
+ *
+ * REVISION HISTORY:
+ * 27 Nov 02 - PSP TII  
+ *
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+ 
+#ifndef __PSP_CONFIG_MGR_H__
+#define __PSP_CONFIG_MGR_H__
+
+typedef enum cfg_type
+{
+    en_raw     = 0,
+    en_compile,
+    en_opt_conf,
+    en_vlynq
+} CFG_TYPE_T;
+
+/* Build psp configuration */
+void build_psp_config(void);
+ 
+/********************************************************
+ * Access Operations.
+ ********************************************************/
+
+/*------------------------------------------------------------------------- 
+   initializes the configuration repository. 
+ -------------------------------------------------------------------------*/
+void  psp_config_init(void);
+
+/*-------------------------------------------------------------------------- 
+   Adds the configuration information into the repository. 'key' is required 
+   to be NULL terminated string. 'cfg_ptr' points to the configuration data.
+   'cfg_len' is the length of the data pointed to by 'cfg_ptr' in bytes. 
+   'cfg_type' indicates the type of config information.
+
+   psp_config_mgr copies the 'cfg_len' bytes of data pointed to by 'cfg_ptr' 
+   into its internal repository. 
+
+   Returns: 0 on success, -1 on failure.
+  -------------------------------------------------------------------------*/
+int   psp_config_add(char *key, void *cfg_ptr, 
+                     unsigned int cfg_len, CFG_TYPE_T cfg_type);
+
+
+/* --------------------------------------------------------------------------
+   Passes back, in "*cfg_out_val" a pointer to the config data in the repository
+   for the specified 'key' and 'instance'. It returns the size of the config
+   info
+
+   psp_config_mgr passes back a pointer in '*cfg_out_val' which refers to 
+   some location in its internal repository. It is strongly recommended that 
+   if the user intends to modify the contents of the config info for reasons 
+   whatsoever, then, user should allocate memory of size returned by this 
+   routine and copy the contents from '*cfg_out_val'.
+  
+   Any, modification carried out on the repository would lead to un-expected
+   results.
+
+   Returns: 0 or more for the size of config info, -1 on error.
+  --------------------------------------------------------------------------*/ 
+int   psp_config_get(char *key, int instance, char **cfg_out_val);
+
+
+/*--------------------------------------------------------------------------
+   Get the number of keys that have been added in the repository so far.
+
+   Returns: 0 or more for the num of keys, -1 on error.
+  -------------------------------------------------------------------------*/
+int   psp_config_get_num_keys(void);
+
+
+/*--------------------------------------------------------------------------
+   Get the number of instances that are present in the repository for the 
+   given 'key'.
+
+   Returns: 0 or more for the num of instances, -1 on error.
+  -------------------------------------------------------------------------*/  
+int   psp_config_get_num_instances(char *key);
+
+
+/*--------------------------------------------------------------------------
+   Prints the config data for all instances associated with the specified 
+   'key'.
+  -------------------------------------------------------------------------*/
+void  psp_config_print(char *key);
+
+void  dump_device_cfg_pool(void);
+
+#endif /* __PSP_CONFIG_MGR_H__ */
diff -urN linux.old/drivers/net/avalanche_cpmac/psp_config_parse.c linux.dev/drivers/net/avalanche_cpmac/psp_config_parse.c
--- linux.old/drivers/net/avalanche_cpmac/psp_config_parse.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/psp_config_parse.c	2005-07-12 02:48:42.178573000 +0200
@@ -0,0 +1,362 @@
+/******************************************************************************
+ * FILE PURPOSE:    PSP Config Manager - Parse API Source
+ ******************************************************************************
+ * FILE NAME:       psp_config_parse.c
+ *
+ * DESCRIPTION:     These APIs should be used only for scanvenging parameters which 
+ *                  are stored in the following format.
+ *
+ *                  str[] = "module(id=[module], k1=v1, k2=[k3=v3, k4=v4], k5=v5)"
+ *
+ * REVISION HISTORY:
+ * 27 Nov 02 - PSP TII  
+ *
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+
+//#include <stdio.h>
+#include <linux/stddef.h>
+
+/*--------------------------------------------------
+ * MACROS.
+ *-------------------------------------------------*/
+#define my_isdigit(c) (c >= '0' && c <= '9')
+#define my_isoct(c)   (c >= '0' && c <= '7')  
+#define my_xtod(c)    ((c) <= '9' ? (c) - '0' : (c) - 'a' +  10)
+#define my_ifupper(c)    (c >= 'A' && c <= 'F')
+#define XTOD(c)       ((c) - 'A' + 10)
+#define my_ishex(c)   ((c >= 'a' && c <='f') || (c >= 'A' && c<='F') || my_isdigit(c) ) 
+
+/*---------------------------------------------------
+ * Local Functions.
+ *--------------------------------------------------*/
+static int p_get_substr_from_str(char *p_in_str, char begin_delimiter,
+                                 char end_delimiter, int pair_flag,
+                                 char **p_out_str);
+static int p_get_u_int_from_str(char *p_in_str, char begin_delimiter,
+                                char end_delimiter, unsigned long *out_val);
+
+/*---------------------------------------------------
+ * Return pointer to first instance of the char.
+ *--------------------------------------------------*/
+static char* psp_config_strchr(char *str, char chr)
+{
+    while(*str)
+    {
+        if(*str == chr)
+            break;
+        str++;    
+    }
+    
+    return((*str) ? str : NULL);
+}
+
+/*------------------------------------------------------------------------
+ * Convert the string upto delimiter to unsigned long.
+ *-----------------------------------------------------------------------*/
+unsigned long my_atoul(char *p, char end_delimiter, unsigned long *out_val)
+{
+    unsigned long n;
+    int c;
+ 
+    /* check the for null input */    
+    if (!p)
+        return -1;
+     
+    c = *p;    
+    
+    /* pass through the leading spaces */
+    if (!my_isdigit(c)) 
+    {
+        while ( c == ' ')
+            c = *++p;
+            
+    }
+    
+    if (c == '0')
+    {
+        if(*(p + 1) == 'x' || *(p+1) == 'X' ) 
+        {
+            /* string is in hex format */
+
+            p += 2; 
+            c = *p;
+            
+            if(my_ishex(c))
+            {
+               if(my_ifupper(c))
+                   n = XTOD(c);
+               else         
+                       n = my_xtod(c);
+            }
+            else
+                return -1; /* invalid hex string format */
+                
+            while ((c = *++p) && my_ishex(c)) 
+            {
+                n *= 16; 
+                if(my_ifupper(c))
+                   n += XTOD(c);
+                else         
+                       n += my_xtod(c);
+            }
+         }
+        else
+        {
+            /* string is in octal format */
+
+            if( my_isoct(c) )
+            n = c - '0';
+            else
+                return -1; /* invalid octal string format */
+ 
+            while ((c = *++p) && my_isoct(c)) 
+            {
+                n *= 8; 
+                n += c - '0'; 
+            }
+        } 
+         
+    }      
+    else 
+    {
+        /* string is in decimal format */
+ 
+        if( my_isdigit(c) )
+            n = c - '0';
+        else
+            return -1; /* invalid decimal string format */
+
+        while ((c = *++p) && my_isdigit(c)) 
+        {
+            n *= 10; 
+            n += c - '0'; 
+        }
+    }
+   
+    /* move through the trailing spaces */ 
+    while(*p == ' ')
+        p++;
+        
+    if(*p == end_delimiter)
+       {
+           *out_val = n;
+           return 0;
+       }   
+        
+    else
+        return -1; /* invalid string format */
+}
+
+/*---------------------------------------------------------------------------------
+ * Gets the substring de-limited by the 'begin_delimiter' and 'end_delimiter'.
+ * and returns the size of the substring. 
+ *
+ * Parses the NULL terminated p_in_str for a character array delimited by 
+ * begin_delimiter and end_delimiter, passes back the pointer to the character 
+ * array in ' *p_out_str '. The passed pointer ' *p_out_str ' should point to 
+ * the location next (byte) to the begin_delimiter. The function routine returns 
+ * the number of characters excluding the begin_delimiter and end_delimiter, 
+ * found in the array delimited by the said delimiters.
+ *
+ * If the pair_flag is set to 1, then, number of begin_delimiter and end_delimiter
+ * found in the parsing should match (equal) and this routine passes back the 
+ * pointer to the character array, starting at a location next (byte) to the 
+ * first begin_delimiter,  inclusive of all intermediate matching delimiter 
+ * characters found between outer delimiters. If the pair flag is set and if 
+ * begin_delimiter and end_delimiter happens to be same, then error (-1) is 
+ * returned.
+ * 
+ * Return: 0 or more to indicate the size of the substring, -1 on error.
+ *-------------------------------------------------------------------------------*/
+int p_get_substr_from_str(char *p_in_str, char begin_delimiter, 
+                          char end_delimiter, int pair_flag, 
+                          char **p_out_str) 
+{
+    int cnt,pos;
+
+    if(pair_flag  && begin_delimiter == end_delimiter)
+        return -1;
+    
+    if((p_in_str = psp_config_strchr(p_in_str, begin_delimiter)) == 0)
+        return -1; /* no start delimiter found */
+    
+    p_in_str++;      
+    *p_out_str = p_in_str;
+     
+    for(pos = 0,cnt =1; cnt && p_in_str[pos] ; pos++)
+    {
+        if(p_in_str[pos] == end_delimiter)
+        {
+            if(pair_flag == 0)
+                return pos;
+               
+            cnt--;                  
+        }             
+        else if(p_in_str[pos] == begin_delimiter)
+            cnt++;
+        else 
+            ; /* We do nothing */
+      
+    }
+    
+    if( cnt == 0)   
+        return pos - 1;
+    else
+        return -1; /* no corresponding end delimiter found */
+}
+
+/*--------------------------------------------------------------------------    
+ * Parses the NULL terminated p_in_str for unsigned long value delimited by 
+ * begin_delimiter and end_delimiter, passes back the found in ' *out_val '.  
+ * The function routine returns 0 on success and returns -1 on failure. 
+ * The first instance of the de-limiter should be accounted for the parsing.
+ *
+ * The base for unsigned value would 10, octal and hex. The value passed back 
+ * would be of the base 10. Spaces at the begining of the byte array are valid  
+ * and should be ingnored in the calculation of the value. Space character in 
+ * the middle of the byte array or any character other than the valid ones 
+ * (based on base type) should return error. The octal value begins with '0', 
+ * the hex value begins with "0x" or "0X", the base value can begin with 
+ * '1' to '9'.
+ * 
+ * Returns: 0 on success, -1 on failure.
+ *-------------------------------------------------------------------------*/
+int p_get_u_int_from_str(char *p_in_str, char begin_delimiter, 
+                         char end_delimiter, unsigned long *out_val) 
+{
+    char *start;
+    unsigned long num;
+    
+    num = p_get_substr_from_str(p_in_str, begin_delimiter, end_delimiter,
+                                0, &start);
+
+    if(num == (unsigned long)-1)
+        return -1;
+    
+    return my_atoul(start,end_delimiter,out_val);
+}
+
+/*--------------------------------------------------------------------------
+ * Finds the first occurrence of the substring p_find_str in the string
+ * p_in_str. 
+ *-------------------------------------------------------------------------*/
+char *my_strstr(char *p_in_str, const char *p_find_str)
+{
+    char *p = (char *)p_find_str;
+    char *ret = NULL;
+
+    while(*p_in_str)
+    {
+        if(!(*p))
+            return (ret);
+        else if(*p_in_str == *p)
+        {
+            if(!ret) ret = p_in_str;
+            p++;
+            p_in_str++;
+        }
+        else if(ret)
+        {
+            p = (char *)p_find_str;
+            p_in_str = ret + 1;
+            ret = NULL;
+        }
+        else
+            p_in_str++;
+    }
+
+    if(*p_in_str != *p) ret = NULL;
+
+    return (ret);
+
+}
+
+/*------------------------------------------------------------------------------
+ * Gets the value of the config param in the unsigned int format. The value is 
+ * stored in the following format in the string.
+ * str[] = "module(id=[module], k1=v1, k2=[k3=v3, k4=v4], k5=v5)"
+ *-----------------------------------------------------------------------------*/
+int psp_config_get_param_uint(char *p_in_str, const char *param, unsigned int *out_val)
+{
+    int   ret_val = -1;
+    char *p_strstr;
+
+    if(!p_in_str || !param || !out_val) 
+    {
+        ;
+    } 
+    else if((p_strstr = my_strstr(p_in_str, param)) == NULL)
+    {
+        ;
+    }
+    else if(p_get_u_int_from_str(p_strstr, '=', ',', (unsigned long *)out_val) == 0)
+    {
+        ret_val = 0;
+    }
+    else if(p_get_u_int_from_str(p_strstr, '=', ']', (unsigned long*)out_val) == 0)
+    {
+        ret_val = 0;
+    }
+    else if(p_get_u_int_from_str(p_strstr, '=', ')', (unsigned long*)out_val) == 0)
+    {
+        ret_val = 0;
+    }
+    else
+    {
+        /* we failed */
+    }
+
+    return (ret_val);
+}
+ 
+/*------------------------------------------------------------------------------
+ * Gets the value of the config param in the Non NULL terminated format. The value 
+ * is stored in the following format in the string. 
+ * str[] = "module(id=[module], k1=v1, k2=[k3=v3, k4=v4], k5=v5)"
+ *-----------------------------------------------------------------------------*/
+int psp_config_get_param_string(char *p_in_str, const char *param, char **out_val)
+{
+    int ret_val = -1;
+    char *p_strstr;
+
+    if(!p_in_str || !param || !(out_val))
+        ;
+    else if((p_strstr = my_strstr(p_in_str, param)) == NULL)
+    {
+        ;
+    }
+    else if((ret_val = p_get_substr_from_str(p_strstr, '[', ']', 1, out_val)) == -1)
+    {
+        ;
+    }
+    else
+    {
+        ; /* we got the value */
+    }   
+ 
+    return (ret_val); 
+} 
+
+#ifdef PSP_CONFIG_MGR_DEBUG_TEST
+main()
+{
+    unsigned long num =999;
+    int ret = 0;
+    char *val1 = NULL;
+    char val[30];
+    char str1[] = "cpmac(id=[cpmac], k0=[a1=[a2=[test], a3=2], k1=100, k2=[k3=300, k4=200], k7=722)";
+
+    psp_config_get_param_uint(str1, "k7", &num);
+    printf("%u.\n", num);    
+    ret = psp_config_get_param_string(str1, "a1", &val1); 
+    if(ret >= 0) { printf("%d.\n", ret); strncpy(val, val1, ret); val[ret] = '\0';}
+    
+    printf("val = \"%s\", and size = %d \n", val, ret);
+
+    if(val[ret]) ; else printf("jeee.\n");
+}
+#endif /* PSP_CONFIG_MGR_DEBUG_TEST */
+
+
+
diff -urN linux.old/drivers/net/avalanche_cpmac/psp_config_parse.h linux.dev/drivers/net/avalanche_cpmac/psp_config_parse.h
--- linux.old/drivers/net/avalanche_cpmac/psp_config_parse.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/psp_config_parse.h	2005-07-12 02:48:42.178573000 +0200
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * FILE PURPOSE:    PSP Config Manager - Parse API Header
+ ******************************************************************************
+ * FILE NAME:       psp_config_parse.h
+ *
+ * DESCRIPTION:     Parsing for params from string available in the NBU format.
+ *                  These APIs should be used only for scanvenging parameters which 
+ *                  are stored in the following format.
+ *                  
+ *                  str[] = "module(id=[module], k1=v1, k2=[k3=v3, k4=v4], k5=v5)"
+ *
+ * REVISION HISTORY:
+ * 27 Nov 02 - PSP TII  
+ *
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+
+#ifndef __PSP_CONFIG_PARSER_H__
+#define __PSP_CONFIG_PARSER_H__
+
+/*------------------------------------------------------------------
+ * These APIs should be used only for scanvenging parameters which 
+ * are stored in the following format.
+ *
+ * str[] = "module(id=[module], k1=v1, k2=[k3=v3, k4=v4], k5=v5)"
+ *-----------------------------------------------------------------*/
+int psp_config_get_param_uint(char *p_in_str, const char *param, 
+                              unsigned int *out_val);
+int psp_config_get_param_string(char *p_in_str, const char *param, 
+                                char **out_val);
+
+#endif /* __PSP_CONFIG_PARSER_H__ */
diff -urN linux.old/drivers/net/avalanche_cpmac/psp_config_util.c linux.dev/drivers/net/avalanche_cpmac/psp_config_util.c
--- linux.old/drivers/net/avalanche_cpmac/psp_config_util.c	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/psp_config_util.c	2005-07-12 02:48:42.178573000 +0200
@@ -0,0 +1,106 @@
+/******************************************************************************
+ * FILE PURPOSE:    PSP Config Manager - Utilities API Source
+ ******************************************************************************
+ * FILE NAME:       psp_config_util.c
+ *
+ * DESCRIPTION:     These APIs provide the standard "C" string interfaces. 
+ *                  Provided here to reduce dependencies on the standard libraries 
+ *                  and for cases where psp_config would required to run before 
+ *                  the whole system is loaded or outside the scope of the OS.
+ *
+ * REVISION HISTORY:
+ * 27 Nov 02 - PSP TII  
+ *
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+
+//#include <stdio.h>
+#include "psp_config_util.h"
+#include <linux/stddef.h>
+
+/*---------------------------------------------
+ * strlen.
+ *-------------------------------------------*/
+int psp_config_strlen(char *p)
+{
+    char *p_orig = p;
+    while(*p)
+        p++;
+    return(p - p_orig);
+}
+
+/*--------------------------------------------
+ * strcmp.
+ *-------------------------------------------*/
+int psp_config_strcmp(char *s1, char *s2)
+{
+    while(*s1 && *s2)
+    {
+        if(*s1 != *s2)
+            break;
+        s1++;
+        s2++;
+    }
+
+    return(*s1 - *s2);
+}
+
+/*--------------------------------------------
+ * strcpy.
+ *------------------------------------------*/
+char* psp_config_strcpy(char *dest, char *src)
+{
+    char *dest_orig = dest;
+
+    while(*src)
+    {
+        *dest++ = *src++;
+    }
+
+    *dest = '\0';
+
+    return(dest_orig);
+}
+
+/*----------------------------------------------
+ * psp_config_memcpy.
+ *--------------------------------------------*/
+void* psp_config_memcpy(void* dest, void* src, unsigned int n)
+{
+    void *dest_orig = dest;
+
+    while(n)
+    {
+        *(char *)dest++ = *(char *)src++;
+        n--;
+    }
+
+    return (dest_orig);
+}
+
+/*---------------------------------------------------
+ * Return pointer to first instance of the char.
+ *--------------------------------------------------*/
+char* psp_config_strchr(char *str, char chr)
+{
+    while(*str)
+    {
+        if(*str == chr)
+            break;
+        str++;    
+    }
+    
+    return((*str) ? str : NULL);
+}
+
+#ifdef PSP_CONFIG_MGR_DEBUG_TEST
+
+int main( )
+{
+    char s[] = "hello             ";
+    printf("%d.\n", psp_config_strlen("hello\n"));
+    printf("%d.\n", psp_config_strcmp("hells", "hellq"));
+    printf("%s %s.\n", psp_config_strcpy(s + 6, "test1"), s);
+}
+
+#endif /* PSP_CONFIG_MGR_DEBUG_TEST */
diff -urN linux.old/drivers/net/avalanche_cpmac/psp_config_util.h linux.dev/drivers/net/avalanche_cpmac/psp_config_util.h
--- linux.old/drivers/net/avalanche_cpmac/psp_config_util.h	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/psp_config_util.h	2005-07-12 02:48:42.179573000 +0200
@@ -0,0 +1,26 @@
+/******************************************************************************
+ * FILE PURPOSE:    PSP Config Manager - Utilities API Header
+ ******************************************************************************
+ * FILE NAME:       psp_config_util.h
+ *
+ * DESCRIPTION:     These APIs provide the standard "C" string interfaces. 
+ *                  Provided here to reduce dependencies on the standard libraries 
+ *                  and for cases where psp_config would required to run before 
+ *                  the whole system is loaded or outside the scope of the OS.
+ *
+ * REVISION HISTORY:
+ * 27 Nov 02 - PSP TII  
+ *
+ * (C) Copyright 2002, Texas Instruments, Inc
+ *******************************************************************************/
+ 
+#ifndef __PSP_CONFIG_UTIL_H__
+#define __PSP_CONFIG_UTIL_H__
+
+extern int   psp_config_strlen(char*);
+extern int   psp_config_strcmp(char*, char*);
+extern char* psp_config_strcpy(char*, char*);
+extern void* psp_config_memcpy(void*, void*, unsigned int n);
+extern char* psp_config_strchr(char*, char);
+
+#endif /* __PSP_CONFIG_UTIL_H__ */
diff -urN linux.old/drivers/net/avalanche_cpmac/readme.txt linux.dev/drivers/net/avalanche_cpmac/readme.txt
--- linux.old/drivers/net/avalanche_cpmac/readme.txt	1970-01-01 01:00:00.000000000 +0100
+++ linux.dev/drivers/net/avalanche_cpmac/readme.txt	2005-07-12 02:48:42.179573000 +0200
@@ -0,0 +1,545 @@
+23 August 2004      CPMAC 1.7.8 (NSP Performance Team Release)
+
+CC Labels: REL_20040823_HALdallas_cpmac_01.07.08
+
+New features:  Key "MacAddr" can now be used to set the Mac Address after Open. 
+
+ unsigned char MacAddr[6];
+
+  // Set Mac Address to "00.B0.D0.10.80.C1"     
+  MacAddr[0] = 0x00;
+  MacAddr[1] = 0xB0;
+  MacAddr[2] = 0xD0;
+  MacAddr[3] = 0x10;
+  MacAddr[4] = 0x80;
+  MacAddr[5] = 0xC1;
+      
+  HalFunc->Control(HalDev, "MacAddr", hcSet, &MacAddr);      
+
+Bug fixes: in Send(), Threshold is not checked if Tx Ints are re-enabled.
+
+Modules affected:  hcpmac.c, hcpmac.h, cppi_cpmac.c
+
+22 June 2004          CPMAC 1.7.6 (NSP Performance Team Release)
+
+CC Labels: REL_20040622_HALdallas_cpmac_01.07.06
+
+New features:  Key "TxIntDisable" used to disable Tx Interrupts. If it is set, then Tx Interrupts will be processed on Send() controlled by Tx ServiceMax Setting. 
+
+ int On = 1;
+ HalFunc->Control(HalDev, "TxIntDisable", "Set", &On);
+
+Bug fixes: NTR
+
+10 June 2004          CPMAC 1.7.5 (external release)
+
+CC Labels: REL_20040610_HALdallas_cpmac_01.07.05
+
+New features:  NTR
+
+Bug fixes: Fixed an issue with calculation for the multicast hash.
+
+27 May 2004          CPSAR 1.7.4, CPMAC 1.7.4 (external release)
+
+CC Labels: REL_20040527_HALdallas_cpsar_01.07.04
+           REL_20040527_HALdallas_cpmac_01.07.04
+
+New features:  NTR
+
+Bug fixes: A flaw was fixed in the critical sectioning of the CPPI file, affecting both
+           the MAC and the SAR releases.  This flaw was detected on Titan PSP 4.7 BFT2.
+
+05 May 2004          CPSAR 1.7.3, CPMAC 1.7.3 (external release)
+
+CC Labels: REL_20040505_HALdallas_cpsar_01.07.03
+                REL_20040505_HALdallas_cpmac_01.07.03
+
+New features:  NTR
+
+Bug fixes: 1) Firmware has been updated to fix a problem with Host OAM mode operation.  
+               2) Cache macros have been fixed.
+
+Notes:  This release contains all performance enhancements currently available for CPHAL 1.x.  
+
+19 April 2004          CPSAR 1.7.2, CPMAC 1.7.2 (external release)
+
+CC Labels: REL_20040419_HALdallas_cpsar_01.07.02
+                REL_20040419_HALdallas_cpmac_01.07.02
+
+New features:  NTR
+
+Bug fixes: Fixes merge problem in 1.7.1.
+
+Notes:  This is a branch release which contains only a subset of the performance improvements.
+            The remaining performance improvements are stiill being qualified at this time.
+
+1 April 2004          CPSAR 1.7.1, CPMAC 1.7.1 (external release)
+
+NOTICE: DO NOT USE 1.7.1.  It has a known problem (see 1.7.2 notes)
+
+CC Labels: REL_20040401_HALdallas_cpsar_01.07.01
+                REL_20040401_HALdallas_cpmac_01.07.01
+
+New features:  Performance improvement in CPPI layer, affecting both CPSAR and CPMAC.  
+
+Bug fixes: NTR
+
+17 Februrary 2004    CPSAR 1.7.0 (external release)
+
+CC Labels: REL_20040217_HALdallas_cpsar_01.07.00
+
+New features:  Added support for "TxFlush" feature.  This allows the upper
+               layer to flush all or part of a given Tx queue for a given
+               channel.  This is to be used during call setup for a voice
+               connection.
+
+30 January 2004      CPMAC 1.7.0 (external release)
+
+CC Labels: REL_20040130_HALdallas_cpmac_01.07.00
+
+Bug fixes:    CPMDIO - When in manual negotiate mode and linked, dropping link would move into NWAY state rather than manual state.
+              CPMDIO - Extraneous debug message corrected
+New features: CPMDIO - Support for AutoMdix usage added. 
+
+25 September 2003      CPSAR 1.6.6 (external release)
+
+CC Labels: REL_20030925_HALdallas_cpsar_01.06.06
+
+Bug fixes:   PDSP firmware has been updated to fix the OAM padding problem.  It previously
+             wrote pad bytes into a reserved field of the OAM cell.  There is a small
+             change to the CPSAR configuration code which corresponds to the PDSP spec
+             change.
+
+New features: NTR
+
+09 September 2003      CPMAC 1.6.6 (external release)
+
+CC Labels: REL_20030909_HALdallas_cpmac_01.06.06
+
+Bug fixes:   CPMAC : When _CPMDIO_NOPHY is set, Cpmac COntrol is set to Full Duplex
+             Bridge loopback test does not show a problem using 1.6.5 if packet rate is
+             below 50,000 pbs. Now testing with a 100% send from Ixia.
+
+New features: NTR
+
+05 August 2003         CPHAL 1.6.5 (external release)
+
+CC Labels: REL_20030805_HALdallas_cpmac_01.06.05
+
+Bug fixes: NTR
+
+New features:  CPMAC : Added support for CPMAC modules that do not have a Phy connected.
+               The CPMAC is informed of this by the MdioConnect option
+               _CPMDIO_NOPHY. This is the only driver change needed to
+               receive and transmit packets through the Marvel switch.
+               Note  In this mode Link status will reported linked at 100/FD to
+               PhyNum 0xFFFFFFFF.
+
+               ALL:  Cleaned up some Vlynq support logic.
+
+16 July 2003         CPSAR 1.6.3 (external release), no CPMAC release
+
+CC Labels: REL_20030716_HALdallas_cpsar_01.06.03
+
+Bug fixes: 1) Changed default value of CPCS_UU from 0x5aa5 to 0.  The old default value caused
+              problems with Cisco routers.
+
+New features:  NTR
+
+Known issues not addressed in this release: NTR.
+
+01 July 2003         CPHAL 1.6.2 (external release)
+
+CC Labels: REL_20030701_HALdallas_cpmac_01.06.02
+           REL_20030701_HALdallas_cpsar_01.06.02
+
+Bug fixes: 1) A previous firmware upgrade caused firmware OAM loopback cells to only work on every other
+              command.  This has been fixed in the new firmware version (0.47).
+           2) Problem with PTI values changing on transparent mode packets has been resolved.
+           3) Previously, successful firmware OAM loopback cells waited 5 seconds before notifying the
+              OS of success, rather that notifying immediately.  This has been resolved in firmware.
+           4) PITS #148 (MAC and SAR), #149 (MAC) have been fixed.
+
+New features: 1) AAL5 HAL now capable of receiving unknown VCI/VPI cells on a single transparent channel.
+                 See updated HAL document (AAL5 appendix) for implementation details.
+              2) AAL5 HAL now allows OS to modify the OAM loopback timeout window.  Previously, failed
+                 OAM loopback attempts timed out after a nominal 5 seconds (based on the SAR frequency
+                 provided by the OS).  Now, the default is 5 seconds, but the OS may change the
+                 value via halControl() to any integer number of milliseconds.  See updated HAL document
+                 (AAL5 appendix) for implementation details.
+              3) MAC (cpmdio): added loopback to Istate.  Used for debug.
+
+Known issues not addressed in this release: NTR.
+
+09 June 2003         CPSAR 1.6.1 (external release), CPMAC 1.6.1 (internal release - no functional change)
+
+Note: This is the same set of fixes being applied to 1.6.0 that were applied to 1.5.3.  The only difference
+      between 1.6.1 and 1.5.4 is that 1.6.1 has the TurboDSL fix.
+
+CC Labels: REL_20030609_HALdallas_cpmac_01.06.01
+           REL_20030609_HALdallas_cpsar_01.06.01
+
+Bug fixes: 1) Bug in OamLoopbackConfig fixed.
+           2) New firmware version (.43) to fix Westell issue of dropped downstream packets in
+              presence of OAM traffic when operating at or near line rate.
+
+New features: NTR.
+
+09 June 2003         CPSAR 1.5.4 (external release), CPMAC 1.5.4 (internal release - no functional change)
+
+Note:  This is a branch release from 1.5.3.  This does not contain anything from 1.6.0.  The CPMAC is
+only being labeled to keep the release flow consistent.
+
+CC Labels: REL_20030609_HALdallas_cpmac_01.05.04
+           REL_20030609_HALdallas_cpsar_01.05.04
+
+Bug fixes: 1) Bug in OamLoopbackConfig fixed.
+           2) New firmware version (.43) to fix Westell issue of dropped downstream packets in
+              presence of OAM traffic when operating at or near line rate.
+
+New features: NTR.
+
+30 May 2003         CPSAR 1.6.0 (external release), CPMAC 1.6.0 (internal release - no functional change)
+
+CC Labels: REL_20030530_HALdallas_cpmac_01.06.00
+           REL_20030530_HALdallas_cpsar_01.06.00
+
+Bug fixes: 1) TurboDSL issue has been fixed with a software workaround in TxInt.  This workaround
+              has been verified under Adam2 ONLY at this point.  Testing remains to be done on
+              Linux and VxWorks.
+
+New features: NTR.
+
+Known issues not addressed in this release: NTR.
+
+30 May 2003         CPSAR 1.5.3 (external release), CPMAC 1.5.3 (internal release - no functional change)
+
+CC Labels: REL_20030530_HALdallas_cpmac_01.05.03
+           REL_20030530_HALdallas_cpsar_01.05.03
+
+Bug fixes: NTR.
+
+New features: 1) AAL5 Send() has been modified to accept an ATM Header either in the first
+                 fragment by itself, or in the first fragment directly in front of payload data.
+                 The API() does not change.
+              2) Documentation updates throughout, reflected in latest version of CPHAL user's
+                 guide.
+              3) AAL5 MaxFrags default value is now 46.  This is based upon the default AAL5
+                 RxBufSize of 1518 (MaxFrags = (65568/1518) + 2).  IF THE OS CHOOSES A SMALLER
+                 RxBufSize, IT MUST INCREASE THE VALUE OF MaxFrags ACCORDINGLY.  This is done
+                 via halControl(), prior to Open().
+
+Known issues not addressed in this release:
+              1) The Linux SAR driver is seeing an issue in which it cannot
+                 reliably send traffic simultaneously on both the high and
+                 low priority queues of a single AAL5 channel. (TurboDSL)
+
+23 May 2003         CPHAL 1.5.2 (external release)
+
+CC Labels: REL_20030523_HALdallas_cpmac_01.05.02
+           REL_20030523_HALdallas_cpsar_01.05.02
+
+Bug fixes: 1) PITS #138: CPMAC flooding issue resolved.
+           2) PITS #142: OS may now set "MaxFrags" via Control().  This controls the
+              maximum number of fragments expected by the CPHAL.  The default value is 2 for
+              CPMAC and 1028 for AAL5.  If the OS chooses a RxBufSize that will cause more
+              fragments than the defaults, the OS must set "MaxFrags" to a correct value
+              ((maximum packet length / RxBufSize) + 2).
+           3) PITS #143: Fixed.
+           4) Firmware OAM bug fixed. (new firmware release in this version)
+
+New features: NTR.
+
+Known issues not addressed in this release:
+              1) The Linux SAR driver is seeing an issue in which it cannot
+                 reliably send traffic simultaneously on both the high and
+                 low priority queues of a single AAL5 channel. (TurboDSL)
+
+14 May 2003         CPHAL 1.5.1 (external release)
+
+CC Labels: REL_20030514_HALdallas_cpmac_01.05.01
+           REL_20030514_HALdallas_cpsar_01.05.01
+
+Bug fixes:    1) PITS 132 - (CPMAC) Frames < 60 bytes and split into
+                             multi-fragments.
+              2) BCIL MR PSP00000353 - (CPMAC) PhyDev not free'd on halClose()
+              3) PITS 113 - OsSetup bug in ChannelSetup fixed.
+              4) Fixed AAL5 to check return values of InitTcb/InitRcb.
+              5) Fixed Shutdown to properly free resources in the case of a Close
+                 mode 1 followed by Shutdown.  Previously, buffer and descriptor
+                 resources were left unfreed in this case.
+
+New features: 1) AAL5 Send() modified to be capable of accepting ATM header as first four
+                 bytes of first fragment.  This allows the OS to "override" the
+                 default ATM header which is constructed from preconfigured channel
+                 parameters.
+              2) AAL5 Receive() modified to be capable of passing the received ATM header (4 bytes, no HEC)
+                 in the first fragment (by itself).  It also passes up the OS an indication
+                 of what the received packet type was.  For Host OAM and transparent mode
+                 packets, the ATM header is passed in this manner, and for other types of packets
+                 (AAL5, NULL AAL) no ATM header is passed currently.
+
+Known issues not addressed in this release:
+              1) The Linux SAR driver is seeing an issue in which it cannot
+                 reliably send traffic simultaneously on both the high and
+                 low priority queues of a single AAL5 channel.
+
+30 April 2003         CPHAL 1.5.0 (external release)
+
+CC Labels: REL_20030430_HALdallas_cpmac_01.05.00
+           REL_20030430_HALdallas_cpsar_01.05.00
+
+Bug fixes:   1) Fixed AAL5 bug that rendered the low priority queue
+                unusable.
+             2) Fixed a bug in AAL5's Oam Rate calculations.
+             3) Fixed use of "DeviceCPID" key in AAL5's halControl().
+             4) Fixed RxReturn logic in HAL.  The HAL now can handle
+                failing MallocRxBuffer calls when multiple fragments
+                are being used.
+
+New features: 1) AAL5 Stats now available on a per queue basis.
+              2) AAL5 adds two new keys to halControl() for "Set" actions:
+                 RxVc_OamCh and RxVp_OamCh.
+              3) Shutdown() has been modified for both AAL5 and CPMAC to
+                 call Close() if the module is still in the Open state.
+              4) CPMAC adds the following access keys to halControl():
+                 hcPhyAccess,hcPhyNum,hcCpmacBase,hcSize,and hcCpmacSize.
+              5) CPHAL no longer requests an extra 15 bytes on data buffer
+                 mallocs.
+
+Known issues not addressed in this release:
+              1) The Linux SAR driver is seeing an issue in which it cannot
+                 reliably send traffic simultaneously on both the high and
+                 low priority queues of a single AAL5 channel.
+
+21 April 2003         CPHAL 1.4.1 (external release)
+
+CC Labels: REL_20030421_HALdallas_cpmac_01.04.01
+           REL_20030421_HALdallas_cpsar_01.04.01
+
+Bug fixes:   1) Fixed OAM logic in SAR portion of CPHAL.
+
+New features: 1) OAM loopback counters exposed through halControl.
+              2) Host OAM Send() can now use a single channel to send
+                 OAM cells on unlimited number of VP's/VC's.
+              3) CPHAL now requests "SarFreq" through osControl.
+              4) CPHAL now calculates all OAM function rates based on
+                 "SarFreq"; function OamRateConfig removed for API.
+              5) New OAM function OamLoopbackConfig, used for configuring
+                 loopback functions in firmware OAM mode.
+
+Known issues not addressed in this release:  Bug fix 1) in release 1.4
+             (see below) does not work properly for multiple fragments.
+
+10 April 2003         CPHAL 1.4 (external release)
+
+CC Labels: REL_20030410_HALdallas_cpmac_01.04.00
+           REL_20030410_HALdallas_cpsar_01.04.00
+
+This release is for SAR and MAC.
+
+  Bug fixes: 1) Implemented logic in HAL to re-request buffer mallocs
+                in the case of MallocRxBuffer failing.  The HAL now maintains
+                a NeedsBuffer queue of all RCB's that are without buffers.
+                On interrupts, or on Send(), the HAL checks to see if any
+                RCB's are on the queue, and if so, calls MallocRxBuffer
+                to attempt to get a new buffer and return the RCB to
+                circulation.
+             2) SAR now properly returns all error codes from halOpen and
+                halChannelSetup.
+
+  New features: NTR
+
+  Known issues not addressed in this release: NTR
+
+08 April 2003         CPHAL 1.3.1 (internal release - SAR only)
+
+  CC Labels: REL_20030408_HALdallas_cpsar_01.03.01
+
+  This is a SAR only release.  The current CPMAC release is still 1.3.
+
+  Bug fixes: 1) PDSP State RAM / Scratchpad RAM is now completely cleared after reset.
+                This resolves a stability issue.
+
+  New features: 1) OamMode is now a parameter in halControl().  Both "Set" and "Get"
+                   actions are available.  The value may be "0" (Host OAM), or "1"
+                   (Firmware OAM).
+
+  Known issues not addressed in this release:
+             1) Appropriate action for HAL in the case of MallocRxBuffer failing.  We
+                are investigating whether the HAL should implement a needs buffer
+                queue.
+
+04 April 2003         CPHAL 1.3 (external release)
+
+  CC Labels: REL_20030404_HALdallas_cpmac_01.03.00
+             REL_20030404_HALdallas_cpsar_01.03.00
+             REL_20030404_HALdallas_cpaal5_01.03.00
+             REL_20030404_HALdallas_cpaal2_01.03.00
+
+  This release requires no changes for the ethernet end driver.  The changes necessary
+  for the sar driver (firmware file name changes) have already been implemented.
+
+  Bug fixes: 1) RxReturn now returns an error if MallocRxBuffer fails.  On RxReturn error, the driver should
+                call RxReturn again at a later time (when the malloc may succeed) in order for the CPHAL
+                to maintain a full complement of Rx buffers.  We recommend holding off making this driver
+                change until we verify that this condition occurs.
+
+  New features: 1) Removed benign compiler warnings.
+                2) PITS 122: http://www.nbu.sc.ti.com/cgi-bin/pits/redisplay_archive?product=cphal_dev&report=122
+                3) Cpsar label (above) now is applied to everything
+                   beneath /cpsar.
+                4) PITS 14: http://www.nbu.sc.ti.com/cgi-bin/pits/redisplay_archive?product=cphal_dev&report=14
+                   Transferred to MR PSP 00000089.
+                5) PITS 120: http://www.nbu.sc.ti.com/cgi-bin/pits/redisplay_archive?product=cphal_dev&report=120
+
+  Known issues not addressed in this release:
+             1) PITS 102 (as relating to OamMode configuration):
+                http://www.nbu.sc.ti.com/cgi-bin/pits/redisplay_archive?product=cphal_dev&report=102
+                Future release will make OamMode configurable
+                through halControl(), not on per channel basis.
+
+20 March 2003         CPHAL 1.2.1 (internal release)
+
+  CC Labels: REL_20030320_HALdallas_cpmac_01.02.01
+             REL_20030320_HALdallas_cpsar_01.02.01
+             REL_20030320_HALdallas_cpaal5_01.02.01
+             REL_20030320_HALdallas_cpaal2_01.02.01
+
+  Bug fixes: 1. Fixed modification of buffer pointer following
+                MallocRxBuffer in cppi.c.
+             2. Removed extra firmware files from /cpsar.
+
+  New features: NTR.
+
+  Known issues not addressed in this release: NTR.
+
+07 March 2003         CPHAL 1.2 (external release)
+
+  CPMAC/CPSAR feature complete release.  SAR added
+  several features including full OAM support and various
+  other features and bug fixes to address PITS 99-106, and
+  114.  CPMAC cleaned up details raised by India PSP
+  team.
+
+29 January 2003       CPHAL RC 3.01a (external release)
+
+  Corrects non-static functions to be static in cppi.c.
+
+09 Janurary 2003      CPHAL RC 3.01 (external release)
+
+  PITS 88: Fixed MDIO re-connection problem (hcpmac.c)
+  PITS 90: Corrected Rx Buffer Pointer modification (cppi.c)
+
+  Corrected error in cpremap.c
+
+20 December 2002      CPHAL RC 3 (external release)
+
+  Statistics support via halControl().  See Appendix A of guide.
+  Fixed errors in ChannelTeardown/ChannelSetup CPHAL logic.
+  Added multicast support as requested.
+  Several new OS string functions added to OS_FUNCTIONS.
+  "DebugLevel" configuration parameter changed to "Debug".
+  "Stats0" changed to "StatsDump" for CPMAC.
+
+13 December 2002      CPHAL RC 2.03 (internal release)
+
+  Performance improvements.
+  More debug statements implemented (esp AAL5).
+  Updated makefile with "make debug" option.
+  Hbridge performance: [debug library] 15774 tps (53% line rate)
+                   [non-debug library] 13700 tps (46%)
+
+10 December 2002      CPHAL Release Candidate 2.02 (internal release)
+
+ Much of the configuration code internal to CPMAC and AAL5 has been made common.
+ [os]Receive API had been modified to remove OsReceiveInfo.  This information is now
+   available as third member of the FRAGLIST structure, on a per buffer basis.
+ Successfully tested multi-fragment support on CPMAC, using 32 byte buffers.
+ Code is now Emerald compliant - all buffer descriptors now aligned to cache-line
+   boundaries.
+
+2 December 2002      CPHAL Release Candidate 2.01
+
+ Updates to comments in hcpmac.c, cpmdio.c, hcpmac.h
+ Nested comment in hcpmac.c in RC2 can cause compile errors.
+
+25 November 2002      CPHAL Release Candidate 2
+
+Project Items not completed for RC2
+#6  Ship as Library -  Once under CC. Moved to RC3
+#8  Under Clearcase -  Moved to RC3
+#25 Emerald compliant - Moved to RC3
+#26 Statistics support - Moved to RC3 (some support in RC2)
+#36 Debug scheme implemented - Moved to RC3 (some support in RC2)
+
+8 November 2002       CPHAL Release Candidate 1
+
+Notes:
+
+Project Items not completed for RC1
+
+#8  Under Clearcase -  Clearcase server failure this week. Moved to RC2
+#6  Ship as Library -  Once under CC. Moved to RC2
+#13 Verify Datatypes. Moved to RC2
+#14 Review APIs.  Moved to RC2
+
+APIs under review for RC2
+
+halIsr()
+hslRxReturn()
+halSend()
+osSendComplete()
+osReceive()
+
+
+CPMAC Build Instructions
+
+Compile the file 'hcpmac.c'.
+
+
+AAL5 Build Instructions
+
+The AAL5 build is composed of the source files aal5sar.c and cpsar.c.
+Refer to the provided makefile for an example of compiling these files
+into a library.
+
+Example CPHAL Code
+
+CPMAC:
+
+Example CPMAC code is provided in the file hbridge.c.
+This program is provided simply as an example of using the CPHAL API.
+It is not intended to be compiled and executed in your environment.
+
+AAL5:
+
+Example AAL5 code is provided in the file loopback.c.  This program
+is provided simply as an example of using the CPHAL API.  It is not
+intended to be compiled and executed in your environment.
+
+
+Performance Baseline
+
+
+Cpmac
+
+RC1: hbridge.bin, running with IXIA cpahl_1.cfg.
+     This sends 64-byte packets from each Ixia port, with mac destination the other Ixia port.
+     MIPS core 4Kc.
+
+RC2: hbridge.bin, running with IXIA cpahl_1.cfg.
+     This sends 64-byte packets from each Ixia port, with mac destination the other Ixia port.
+     MIPS core 4Ke.
+     CPHAL now includes Emerald support, but this has been disabled by using 'cache -wt' to emulate 4Kc.
+
+RC3: hbridge.bin, running with IXIA cpahl_1.cfg.
+     This sends 64-byte packets from each Ixia port, with mac destination the other Ixia port.
+     MIPS core 4Ke.
+     Running as Emerald processor.
+
+Release  Total Receive Rate    Throughput Setting
+
+RC1             11300                 38%
+RC2              9524                 32%
+RC3             15190                 51%
diff -urN linux.old/drivers/net/Config.in linux.dev/drivers/net/Config.in
--- linux.old/drivers/net/Config.in	2005-07-12 03:20:45.726149872 +0200
+++ linux.dev/drivers/net/Config.in	2005-07-12 02:48:42.180573000 +0200
@@ -25,6 +25,24 @@
 comment 'Ethernet (10 or 100Mbit)'
 bool 'Ethernet (10 or 100Mbit)' CONFIG_NET_ETHERNET
 if [ "$CONFIG_NET_ETHERNET" = "y" ]; then
+   if [ "$CONFIG_MIPS_TITAN" = "y" -o "$CONFIG_AR7" = "y" ]; then
+        tristate '  Texas Instruments Avalanche CPMAC support' CONFIG_MIPS_AVALANCHE_CPMAC	
+   fi
+   if [ "$CONFIG_MIPS_AVALANCHE_CPMAC" != "n" ]; then
+     if [ "$CONFIG_AR7WRD" = "y" -o "$CONFIG_AR7VWI" = "y" -o "$CONFIG_AR7VW" = "y" ]; then
+	 define_bool  CONFIG_MIPS_CPMAC_INIT_BUF_MALLOC y
+         define_int CONFIG_MIPS_CPMAC_PORTS 1
+	 if [ "$CONFIG_MIPS_AVALANCHE_MARVELL" = "y" ]; then
+             define_bool CONFIG_AVALANCHE_LOW_CPMAC  n
+             define_bool CONFIG_AVALANCHE_HIGH_CPMAC y
+	 else
+             define_bool CONFIG_AVALANCHE_CPMAC_AUTO y
+             define_bool CONFIG_AVALANCHE_LOW_CPMAC n
+             define_bool CONFIG_AVALANCHE_HIGH_CPMAC n
+	fi
+     fi
+   fi
+
    if [ "$CONFIG_ARM" = "y" ]; then  
       dep_bool '  ARM EBSA110 AM79C961A support' CONFIG_ARM_AM79C961A $CONFIG_ARCH_EBSA110
       tristate '  Cirrus Logic CS8900A support' CONFIG_ARM_CIRRUS
diff -urN linux.old/drivers/net/Makefile linux.dev/drivers/net/Makefile
--- linux.old/drivers/net/Makefile	2005-07-12 03:20:45.726149872 +0200
+++ linux.dev/drivers/net/Makefile	2005-07-12 02:48:42.181573000 +0200
@@ -56,6 +56,16 @@
 subdir-$(CONFIG_BONDING) += bonding
 
 #
+# Texas Instruments AVALANCHE CPMAC  driver
+#
+
+subdir-$(CONFIG_MIPS_AVALANCHE_CPMAC) += avalanche_cpmac
+#obj-$(CONFIG_MIPS_AVALANCHE_CPMAC) += avalanche_cpmac/avalanche_cpmac.o
+ifeq ($(CONFIG_MIPS_AVALANCHE_CPMAC),y)
+  obj-y += avalanche_cpmac/avalanche_cpmac.o
+endif
+
+#
 # link order important here
 #
 obj-$(CONFIG_PLIP) += plip.o
--- linux.old/drivers/net/avalanche_cpmac/cpmac.c	2005-08-25 10:56:33.702931008 +0200
+++ linux.dev/drivers/net/avalanche_cpmac/cpmac.c	2005-08-25 11:08:45.027451520 +0200
@@ -2158,17 +2158,16 @@
     CPMAC_PRIVATE_INFO_T *p_cpmac_priv  = p_dev->priv;
     CPMAC_DRV_HAL_INFO_T *p_drv_hal     = p_cpmac_priv->drv_hal;
     struct sk_buff       *p_skb         = fragList[0].OsInfo;
-    p_skb->len                          = fragList[0].len;    
 
     /* invalidate the cache. */
     dma_cache_inv((unsigned long)p_skb->data, fragList[0].len);    
 #ifdef CPMAC_TEST
-    xdump(p_skb->data, p_skb->len, "recv");
+    xdump(p_skb->data, fragList[0].len, "recv");
 #endif
 #ifdef CPMAC_8021Q_SUPPORT
     /* 802.1q stuff, just does the basic checking here. */
     if(!p_cpmac_priv->enable_802_1q      &&
-       p_skb->len > TCI_END_OFFSET       &&
+       fragList[0].len > TCI_END_OFFSET       &&
        IS_802_1Q_FRAME(p_skb->data + TPID_START_OFFSET))
     {
          goto cpmac_hal_recv_frame_mismatch;