summaryrefslogtreecommitdiffstats
path: root/drivers/net/wavelan.c
blob: 26eb3e758dc979e9b4df38ad37ee6be025569196 (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
/*
 * AT&T GIS (nee NCR) WaveLAN card:
 *	An Ethernet-like radio transceiver
 *	controlled by an Intel 82586 coprocessor.
 */

#include	<linux/config.h>

#if	defined(CONFIG_WAVELAN)
#if	defined(MODULE)
#include	<linux/module.h>
#include	<linux/version.h>
#endif	/* defined(MODULE) */

#include	<linux/kernel.h>
#include	<linux/sched.h>
#include	<linux/types.h>
#include	<linux/fcntl.h>
#include	<linux/interrupt.h>
#include	<linux/ptrace.h>
#include	<linux/ioport.h>
#include	<linux/in.h>
#include	<linux/string.h>
#include	<linux/delay.h>
#include	<asm/system.h>
#include	<asm/bitops.h>
#include	<asm/io.h>
#include	<asm/dma.h>
#include	<errno.h>
#include	<linux/netdevice.h>
#include	<linux/etherdevice.h>
#include	<linux/skbuff.h>
#include	<linux/malloc.h>
#include	<linux/timer.h>
#define	STRUCT_CHECK	1
#include	"i82586.h"
#include	"wavelan.h"

#ifndef WAVELAN_DEBUG
#define WAVELAN_DEBUG			0
#endif	/* WAVELAN_DEBUG */

#define	nels(a)				(sizeof(a) / sizeof(a[0]))

#define	WATCHDOG_JIFFIES		512	/* TODO: express in HZ. */

typedef struct device		device;
typedef struct enet_statistics	en_stats;
typedef struct net_local	net_local;
typedef struct timer_list	timer_list;

struct net_local
{
	en_stats	stats;
	unsigned int	tx_n_in_use;
	unsigned char	nwid[2];
	unsigned short	hacr;
	unsigned short	rx_head;
	unsigned short	rx_last;
	unsigned short	tx_first_free;
	unsigned short	tx_first_in_use;
	unsigned int	nresets;
	unsigned int	correct_nwid;
	unsigned int	wrong_nwid;
	unsigned int	promiscuous;
	timer_list	watchdog;
	device		*dev;
	net_local	*prev;
	net_local	*next;
};

extern int		wavelan_probe(device *);	/* See Space.c */

static char		*version	= "wavelan.c:v7 95/4/8\n";

/*
 * Entry point forward declarations.
 */
static int		wavelan_probe1(device *, unsigned short);
static int		wavelan_open(device *);
static int		wavelan_send_packet(struct sk_buff *, device *);
static void		wavelan_interrupt(int, struct pt_regs *);
static int		wavelan_close(device *);
static en_stats		*wavelan_get_stats(device *);
static void		wavelan_set_multicast_list(device *, int, void *);

/*
 * Other forward declarations.
 */
static void		wavelan_cu_show_one(device *, net_local *, int, unsigned short);
static void		wavelan_cu_start(device *);
static void		wavelan_ru_start(device *);
static void		wavelan_watchdog(unsigned long);
#if	0
static void		wavelan_psa_show(psa_t *);
static void		wavelan_mmc_show(unsigned short);
#endif	/* 0 */
static void		wavelan_scb_show(unsigned short);
static void		wavelan_ru_show(device *);
static void		wavelan_cu_show(device *);
static void		wavelan_dev_show(device *);
static void		wavelan_local_show(device *);

static unsigned int	wavelan_debug	= WAVELAN_DEBUG;
static net_local	*first_wavelan	= (net_local *)0;

static
unsigned long
wavelan_splhi(void)
{
	unsigned long	flags;

	save_flags(flags);
	cli();

	return flags;
}

static
void
wavelan_splx(unsigned long flags)
{
	restore_flags(flags);
}

static
unsigned short
hasr_read(unsigned short ioaddr)
{
	return inw(HASR(ioaddr));
}

static
void
hacr_write(unsigned short ioaddr, int hacr)
{
	outw(hacr, HACR(ioaddr));
}

static
void
hacr_write_slow(unsigned short ioaddr, int hacr)
{
	hacr_write(ioaddr, hacr);
	/* delay might only be needed sometimes */
	udelay(1000);
}

/*
 * Set the channel attention bit.
 */
static
void
set_chan_attn(unsigned short ioaddr, unsigned short current_hacr)
{
	hacr_write(ioaddr, current_hacr | HACR_CA);
}

/*
 * Reset, and then set host adaptor into default mode.
 */
static
void
wavelan_reset(unsigned short ioaddr)
{
	hacr_write_slow(ioaddr, HACR_RESET);
	hacr_write(ioaddr, HACR_DEFAULT);
}

static
void
wavelan_16_off(unsigned short ioaddr, unsigned short hacr)
{
	hacr &= ~HACR_16BITS;

	hacr_write(ioaddr, hacr);
}

static
void
wavelan_16_on(unsigned short ioaddr, unsigned short hacr)
{
	hacr |= HACR_16BITS;

	hacr_write(ioaddr, hacr);
}

static
void
wavelan_ints_off(device *dev)
{
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned long	x;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	x = wavelan_splhi();

	lp->hacr &= ~HACR_INTRON;
	hacr_write(ioaddr, lp->hacr);

	wavelan_splx(x);
}

static
void
wavelan_ints_on(device *dev)
{
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned long	x;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	x = wavelan_splhi();

	lp->hacr |= HACR_INTRON;
	hacr_write(ioaddr, lp->hacr);

	wavelan_splx(x);
}

/*
 * Read bytes from the PSA.
 */
static
void
psa_read(unsigned short ioaddr, unsigned short hacr, int o, unsigned char *b, int n)
{
	wavelan_16_off(ioaddr, hacr);

	while (n-- > 0)
	{
		outw(o, PIOR2(ioaddr));
		o++;
		*b++ = inb(PIOP2(ioaddr));
	}

	wavelan_16_on(ioaddr, hacr);
}

/*
 * Read bytes from the on-board RAM.
 */
static
void
obram_read(unsigned short ioaddr, unsigned short o, unsigned char *b, int n)
{
	n = (n + 1) / (sizeof(unsigned short) / sizeof(unsigned char));

	outw(o, PIOR1(ioaddr));

	insw(PIOP1(ioaddr), (unsigned short *)b, n);
}

/*
 * Write bytes to the on-board RAM.
 */
static
void
obram_write(unsigned short ioaddr, unsigned short o, unsigned char *b, int n)
{
	n = (n + 1) / (sizeof(unsigned short) / sizeof(unsigned char));

	outw(o, PIOR1(ioaddr));

	outsw(PIOP1(ioaddr), (unsigned short *)b, n);
}

/*
 * Read bytes from the MMC.
 */
static
void
mmc_read(unsigned short ioaddr, unsigned short o, unsigned char *b, int n)
{
	while (n-- > 0)
	{
		while (inw(HASR(ioaddr)) & HASR_MMC_BUSY)
			;

		outw(o << 1, MMCR(ioaddr));
		o++;

		while (inw(HASR(ioaddr)) & HASR_MMC_BUSY)
			;

		*b++ = (unsigned char)(inw(MMCR(ioaddr)) >> 8);
	}
}

/*
 * Write bytes to the MMC.
 */
static
void
mmc_write(unsigned short ioaddr, unsigned short o, unsigned char *b, int n)
{
	while (n-- > 0)
	{
		while (inw(HASR(ioaddr)) & HASR_MMC_BUSY)
			;

		outw((unsigned short)(((unsigned short)*b << 8) | (o << 1) | 1), MMCR(ioaddr));
		b++;
		o++;
	}
}

/*
 * Map values from the irq parameter register to irq numbers.
 */
static
int
wavelan_map_irq(unsigned short ioaddr, unsigned char irqval)
{
	int		irq;
	static int	irqvals[]	=
	{
		   0,    0,    0, 0x01,
		0x02, 0x04,    0, 0x08,
		   0,    0, 0x10, 0x20,
		0x40,    0,    0, 0x80,
	};

	for (irq = 0; irq < nels(irqvals); irq++)
	{
		if (irqvals[irq] == (int)irqval)
			return irq;
	}

	return -1;
}

/*
 * Initialize the Modem Management Controller.
 */
static
void
wavelan_mmc_init(device *dev, psa_t *psa)
{
	unsigned short	ioaddr;
	net_local	*lp;
	mmw_t		m;
	int		configured;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;
	memset(&m, 0x00, sizeof(m));

	/*
	 *	configured = psa->psa_conf_status & 1;
	 *
	 * For now we use the persistent PSA
	 * information as little as possible, thereby
	 * allowing us to return to the same known state
	 * during a hardware reset.
	 */
	configured = 0;
	
	/*
	 * Set default modem control parameters.
	 * See NCR document 407-0024326 Rev. A.
	 */
	m.mmw_jabber_enable = 0x01;
	m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
	m.mmw_ifs = 0x20;
	m.mmw_mod_delay = 0x04;
	m.mmw_jam_time = 0x38;

	m.mmw_encr_enable = 0;
	m.mmw_des_io_invert = 0;
	m.mmw_freeze = 0;
	m.mmw_decay_prm = 0;
	m.mmw_decay_updat_prm = 0;

	if (configured)
	{
		/*
		 * Use configuration defaults from parameter storage area.
		 */
		if (psa->psa_undefined & 1)
			m.mmw_loopt_sel = 0x00;
		else
			m.mmw_loopt_sel = MMW_LOOPT_SEL_UNDEFINED;

		m.mmw_thr_pre_set = psa->psa_thr_pre_set & 0x3F;
		m.mmw_quality_thr = psa->psa_quality_thr & 0x0F;
	}
	else
	{
		if (lp->promiscuous)
			m.mmw_loopt_sel = MMW_LOOPT_SEL_UNDEFINED;
		else
			m.mmw_loopt_sel = 0x00;

		/*
		 * 0x04 for AT,
		 * 0x01 for MCA.
		 */
		if (psa->psa_comp_number & 1)
			m.mmw_thr_pre_set = 0x01;
		else
			m.mmw_thr_pre_set = 0x04;

		m.mmw_quality_thr = 0x03;
	}

	m.mmw_netw_id_l = lp->nwid[1];
	m.mmw_netw_id_h = lp->nwid[0];

	mmc_write(ioaddr, 0, (unsigned char *)&m, sizeof(m));
}

static
void
wavelan_ack(device *dev)
{
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned short	scb_cs;
	int		i;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	obram_read(ioaddr, scboff(OFFSET_SCB, scb_status), (unsigned char *)&scb_cs, sizeof(scb_cs));
	scb_cs &= SCB_ST_INT;

	if (scb_cs == 0)
		return;

	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cs, sizeof(scb_cs));

	set_chan_attn(ioaddr, lp->hacr);

	for (i = 1000; i > 0; i--)
	{
		obram_read(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cs, sizeof(scb_cs));
		if (scb_cs == 0)
			break;

		udelay(1000);
	}

	if (i <= 0)
		printk("%s: wavelan_ack(): board not accepting command.\n", dev->name);
}

/*
 * Set channel attention bit and busy wait until command has
 * completed, then acknowledge the command completion.
 */
static
int
wavelan_synchronous_cmd(device *dev, char *str)
{
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned short	scb_cmd;
	ach_t		cb;
	int		i;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO;
	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cmd, sizeof(scb_cmd));

	set_chan_attn(ioaddr, lp->hacr);

	for (i = 64; i > 0; i--)
	{
		obram_read(ioaddr, OFFSET_CU, (unsigned char *)&cb, sizeof(cb));
		if (cb.ac_status & AC_SFLD_C)
			break;

		udelay(1000);
	}

	if (i <= 0 || !(cb.ac_status & AC_SFLD_OK))
	{
		printk("%s: %s failed; status = 0x%x\n", dev->name, str, cb.ac_status);
		wavelan_scb_show(ioaddr);
		return -1;
	}

	wavelan_ack(dev);

	return 0;
}

static
int
wavelan_hardware_reset(device *dev)
{
	unsigned short	ioaddr;
	psa_t		psa;
	net_local	*lp;
	scp_t		scp;
	iscp_t		iscp;
	scb_t		scb;
	ach_t		cb;
	int		i;
	ac_cfg_t	cfg;
	ac_ias_t	ias;

	if (wavelan_debug > 0)
		printk("%s: ->wavelan_hardware_reset(dev=0x%x)\n", dev->name, (unsigned int)dev);

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	lp->nresets++;

	wavelan_reset(ioaddr);
	lp->hacr = HACR_DEFAULT;

	/*
	 * Clear the onboard RAM.
	 */
	{
		unsigned char	zeroes[512];

		memset(&zeroes[0], 0x00, sizeof(zeroes));

		for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
			obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
	}

	psa_read(ioaddr, lp->hacr, 0, (unsigned char *)&psa, sizeof(psa));

	wavelan_mmc_init(dev, &psa);

	/*
	 * Construct the command unit structures:
	 * scp, iscp, scb, cb.
	 */
	memset(&scp, 0x00, sizeof(scp));
	scp.scp_sysbus = SCP_SY_16BBUS;
	scp.scp_iscpl = OFFSET_ISCP;
	obram_write(ioaddr, OFFSET_SCP, (unsigned char *)&scp, sizeof(scp));

	memset(&iscp, 0x00, sizeof(iscp));
	iscp.iscp_busy = 1;
	iscp.iscp_offset = OFFSET_SCB;
	obram_write(ioaddr, OFFSET_ISCP, (unsigned char *)&iscp, sizeof(iscp));

	memset(&scb, 0x00, sizeof(scb));
	scb.scb_command = SCB_CMD_RESET;
	scb.scb_cbl_offset = OFFSET_CU;
	scb.scb_rfa_offset = OFFSET_RU;
	obram_write(ioaddr, OFFSET_SCB, (unsigned char *)&scb, sizeof(scb));

	set_chan_attn(ioaddr, lp->hacr);

	for (i = 1000; i > 0; i--)
	{
		obram_read(ioaddr, OFFSET_ISCP, (unsigned char *)&iscp, sizeof(iscp));

		if (iscp.iscp_busy == (unsigned short)0)
			break;

		udelay(1000);
	}

	if (i <= 0)
	{
		printk("%s: wavelan_hardware_reset(): iscp_busy timeout.\n", dev->name);
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_hardware_reset(): -1\n", dev->name);
		return -1;
	}

	for (i = 15; i > 0; i--)
	{
		obram_read(ioaddr, OFFSET_SCB, (unsigned char *)&scb, sizeof(scb));

		if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
			break;

		udelay(1000);
	}

	if (i <= 0)
	{
		printk("%s: wavelan_hardware_reset(): status: expected 0x%02x, got 0x%02x.\n", dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_hardware_reset(): -1\n", dev->name);
		return -1;
	}

	wavelan_ack(dev);

	memset(&cb, 0x00, sizeof(cb));
	cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
	cb.ac_link = OFFSET_CU;
	obram_write(ioaddr, OFFSET_CU, (unsigned char *)&cb, sizeof(cb));

	if (wavelan_synchronous_cmd(dev, "diag()") == -1)
	{
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_hardware_reset(): -1\n", dev->name);
		return -1;
	}

	obram_read(ioaddr, OFFSET_CU, (unsigned char *)&cb, sizeof(cb));
	if (cb.ac_status & AC_SFLD_FAIL)
	{
		printk("%s: wavelan_hardware_reset(): i82586 Self Test failed.\n", dev->name);
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_hardware_reset(): -1\n", dev->name);
		return -1;
	}

	memset(&cfg, 0x00, sizeof(cfg));

#if	0
	/*
	 * The default board configuration.
	 */
	cfg.fifolim_bytecnt 	= 0x080c;
	cfg.addrlen_mode  	= 0x2600;
	cfg.linprio_interframe	= 0x7820;	/* IFS=120, ACS=2 */
	cfg.slot_time      	= 0xf00c;	/* slottime=12    */
	cfg.hardware	     	= 0x0008;	/* tx even w/o CD */
	cfg.min_frame_len   	= 0x0040;
#endif	/* 0 */

	/*
	 * For Linux we invert AC_CFG_ALOC(..) so as to conform
	 * to the way that net packets reach us from above.
	 * (See also ac_tx_t.)
	 */
	cfg.cfg_byte_cnt = AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
	cfg.cfg_fifolim = AC_CFG_FIFOLIM(8);
 	cfg.cfg_byte8 = AC_CFG_SAV_BF(0) |
			AC_CFG_SRDY(0);
 	cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
			AC_CFG_ILPBCK(0) |
			AC_CFG_PRELEN(AC_CFG_PLEN_2) |
			AC_CFG_ALOC(1) |
			AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
	cfg.cfg_byte10 = AC_CFG_BOFMET(0) |
			AC_CFG_ACR(0) |
			AC_CFG_LINPRIO(0);
	cfg.cfg_ifs = 32;
	cfg.cfg_slotl = 0;
	cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) |
			AC_CFG_SLTTMHI(2);
	cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
			AC_CFG_BTSTF(0) |
			AC_CFG_CRC16(0) |
			AC_CFG_NCRC(0) |
			AC_CFG_TNCRS(1) |
			AC_CFG_MANCH(0) |
			AC_CFG_BCDIS(0) |
			AC_CFG_PRM(lp->promiscuous);
	cfg.cfg_byte15 = AC_CFG_ICDS(0) |
			AC_CFG_CDTF(0) |
			AC_CFG_ICSS(0) |
			AC_CFG_CSTF(0);
/*
	cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
*/
	cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);

	cfg.cfg_h.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_configure);
	cfg.cfg_h.ac_link = OFFSET_CU;
	obram_write(ioaddr, OFFSET_CU, (unsigned char *)&cfg, sizeof(cfg));

	if (wavelan_synchronous_cmd(dev, "reset()-configure") == -1)
	{
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_hardware_reset(): -1\n", dev->name);

		return -1;
	}

	memset(&ias, 0x00, sizeof(ias));
	ias.ias_h.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_ia_setup);
	ias.ias_h.ac_link = OFFSET_CU;
	memcpy(&ias.ias_addr[0], (unsigned char *)&dev->dev_addr[0], sizeof(ias.ias_addr));
	obram_write(ioaddr, OFFSET_CU, (unsigned char *)&ias, sizeof(ias));

	if (wavelan_synchronous_cmd(dev, "reset()-address") == -1)
	{
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_hardware_reset(): -1\n", dev->name);

		return -1;
	}

	wavelan_ints_on(dev);

	if (wavelan_debug > 4)
		wavelan_scb_show(ioaddr);

	wavelan_ru_start(dev);
	wavelan_cu_start(dev);

	if (wavelan_debug > 0)
		printk("%s: <-wavelan_hardware_reset(): 0\n", dev->name);

	return 0;
}

#if	STRUCT_CHECK == 1

static
char	*
wavelan_struct_check(void)
{
#define	SC(t,s,n)	if (sizeof(t) != s) return n
	SC(psa_t, PSA_SIZE, "psa_t");
	SC(mmw_t, MMW_SIZE, "mmw_t");
	SC(mmr_t, MMR_SIZE, "mmr_t");
	SC(ha_t, HA_SIZE, "ha_t");
#undef	SC

	return (char *)0;
}

#endif	/* STRUCT_CHECK == 1 */

/*
 * Check for a network adaptor of this type.
 * Return '0' iff one exists.
 * (There seem to be different interpretations of
 * the initial value of dev->base_addr.
 * We follow the example in drivers/net/ne.c.)
 */
int
wavelan_probe(device *dev)
{
	int			i;
	int			r;
	short			base_addr;
	static unsigned short	iobase[]	=
	{
#if	0
		Leave out 0x3C0 for now -- seems to clash
		with some video controllers.
		Leave out the others too -- we will always
		use 0x390 and leave 0x300 for the Ethernet device.
		0x300, 0x390, 0x3E0, 0x3C0,
#endif	/* 0 */
		0x390,
	};

	if (wavelan_debug > 0)
		printk("%s: ->wavelan_probe(dev=0x%x (base_addr=0x%x))\n", dev->name, (unsigned int)dev, (unsigned int)dev->base_addr);

#if	STRUCT_CHECK == 1
	if (wavelan_struct_check() != (char *)0)
	{
		printk("%s: structure/compiler botch: \"%s\"\n", dev->name, wavelan_struct_check());

		if (wavelan_debug > 0)
			printk("%s: <-wavelan_probe(): ENODEV\n", dev->name);

		return ENODEV;
	}
#endif	/* STRUCT_CHECK == 1 */

	base_addr = dev->base_addr;

	if (base_addr < 0)
	{
		/*
		 * Don't probe at all.
		 */
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_probe(): ENXIO\n", dev->name);
		return ENXIO;
	}

	if (base_addr > 0x100)
	{
		/*
		 * Check a single specified location.
		 */
		r = wavelan_probe1(dev, base_addr);
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_probe(): %d\n", dev->name, r);
		return r;
	}

	for (i = 0; i < nels(iobase); i++)
	{
		if (check_region(iobase[i], sizeof(ha_t)))
			continue;

		if (wavelan_probe1(dev, iobase[i]) == 0)
		{
			if (wavelan_debug > 0)
				printk("%s: <-wavelan_probe(): 0\n", dev->name);
			return 0;
		}
	}

	if (wavelan_debug > 0)
		printk("%s: <-wavelan_probe(): ENODEV\n", dev->name);

	return ENODEV;
}

static
int
wavelan_probe1(device *dev, unsigned short ioaddr)
{
	psa_t		psa;
	int		irq;
	int		i;
	net_local	*lp;

	if (wavelan_debug > 0)
		printk("%s: ->wavelan_probe1(dev=0x%x, ioaddr=0x%x)\n", dev->name, (unsigned int)dev, ioaddr);

	wavelan_reset(ioaddr);

	psa_read(ioaddr, HACR_DEFAULT, 0, (unsigned char *)&psa, sizeof(psa));

	/*
	 * Check the first three octets of the MAC address
	 * for the manufacturer's code.
	 */ 
	if
	(
		psa.psa_univ_mac_addr[0] != SA_ADDR0
		||
		psa.psa_univ_mac_addr[1] != SA_ADDR1
		||
		psa.psa_univ_mac_addr[2] != SA_ADDR2
	)
	{
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_probe1(): ENODEV\n", dev->name);
		return ENODEV;
	}

	printk("%s: WaveLAN at %#x,", dev->name, ioaddr);

	if ((irq = wavelan_map_irq(ioaddr, psa.psa_int_req_no)) == -1)
	{
		printk(" could not wavelan_map_irq(0x%x, %d).\n", ioaddr, psa.psa_int_req_no);
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_probe1(): EAGAIN\n", dev->name);
		return EAGAIN;
	}

	dev->irq = irq;

	request_region(ioaddr, sizeof(ha_t), "wavelan");
	dev->base_addr = ioaddr;

	/*
	 * Apparently the third numeric argument to LILO's
	 * `ether=' control line arrives here as `dev->mem_start'.
	 * If it is non-zero we use it instead of the PSA NWID.
	 */
	if (dev->mem_start != 0)
	{
		psa.psa_nwid[0] = (dev->mem_start >> 8) & 0xFF;
		psa.psa_nwid[1] = (dev->mem_start >> 0) & 0xFF;
	}

	dev->mem_start = 0x0000;
	dev->mem_end = 0x0000;
	dev->if_port = 0;

	memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);

	for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
		printk("%s%02x", (i == 0) ? " " : ":", dev->dev_addr[i]);

	printk(", IRQ %d", dev->irq);
	printk(", nwid 0x%02x%02x", psa.psa_nwid[0], psa.psa_nwid[1]);

	printk(", PC");
	switch (psa.psa_comp_number)
	{
	case PSA_COMP_PC_AT_915:
	case PSA_COMP_PC_AT_2400:
		printk("-AT");
		break;

	case PSA_COMP_PC_MC_915:
	case PSA_COMP_PC_MC_2400:
		printk("-MC");
		break;

	case PSA_COMP_PCMCIA_915:
		printk("MCIA");
		break;

	default:
		printk("???");
		break;
	}

	printk(", ");
	switch (psa.psa_subband)
	{
	case PSA_SUBBAND_915:
		printk("915");
		break;

	case PSA_SUBBAND_2425:
		printk("2425");
		break;

	case PSA_SUBBAND_2460:
		printk("2460");
		break;

	case PSA_SUBBAND_2484:
		printk("2484");
		break;

	case PSA_SUBBAND_2430_5:
		printk("2430.5");
		break;

	default:
		printk("???");
		break;
	}
	printk(" MHz");

	printk("\n");

	if (wavelan_debug > 0)
		printk(version);

	dev->priv = kmalloc(sizeof(net_local), GFP_KERNEL);
	memset(dev->priv, 0x00, sizeof(net_local));
	lp = (net_local *)dev->priv;

	if (first_wavelan == (net_local *)0)
	{
		first_wavelan = lp;
		lp->prev = lp;
		lp->next = lp;
	}
	else
	{
		lp->prev = first_wavelan->prev;
		lp->next = first_wavelan;
		first_wavelan->prev->next = lp;
		first_wavelan->prev = lp;
	}
	lp->dev = dev;

	lp->hacr = HACR_DEFAULT;

	lp->nwid[0] = psa.psa_nwid[0];
	lp->nwid[1] = psa.psa_nwid[1];

	lp->watchdog.function = wavelan_watchdog;
	lp->watchdog.data = (unsigned long)dev;

	dev->open = wavelan_open;
	dev->stop = wavelan_close;
	dev->hard_start_xmit = wavelan_send_packet;
	dev->get_stats = wavelan_get_stats;
	dev->set_multicast_list = &wavelan_set_multicast_list;

	/*
	 * Fill in the fields of the device structure
	 * with ethernet-generic values.
	 */
	ether_setup(dev);

	dev->mtu = WAVELAN_MTU;

	if (wavelan_debug > 0)
		printk("%s: <-wavelan_probe1(): 0\n", dev->name);

	return 0;
}

/*
 * Construct the fd and rbd structures.
 * Start the receive unit.
 */
static
void
wavelan_ru_start(device *dev)
{
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned short	scb_cs;
	fd_t		fd;
	rbd_t		rbd;
	unsigned short	rx;
	unsigned short	rx_next;
	int		i;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	obram_read(ioaddr, scboff(OFFSET_SCB, scb_status), (unsigned char *)&scb_cs, sizeof(scb_cs));
	if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
		return;

	lp->rx_head = OFFSET_RU;

	for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next)
	{
		rx_next = (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;

		fd.fd_status = 0;
		fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
		fd.fd_link_offset = rx_next;
		fd.fd_rbd_offset = rx + sizeof(fd);
		obram_write(ioaddr, rx, (unsigned char *)&fd, sizeof(fd));

		rbd.rbd_status = 0;
		rbd.rbd_next_rbd_offset = I82586NULL;
		rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
		rbd.rbd_bufh = 0;
		rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
		obram_write(ioaddr, rx + sizeof(fd), (unsigned char *)&rbd, sizeof(rbd));

		lp->rx_last = rx;
	}

	obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset), (unsigned char *)&lp->rx_head, sizeof(lp->rx_head));

	scb_cs = SCB_CMD_RUC_GO;
	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cs, sizeof(scb_cs));

	set_chan_attn(ioaddr, lp->hacr);

	for (i = 1000; i > 0; i--)
	{
		obram_read(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cs, sizeof(scb_cs));
		if (scb_cs == 0)
			break;

		udelay(1000);
	}

	if (i <= 0)
		printk("%s: wavelan_ru_start(): board not accepting command.\n", dev->name);
}

/*
 * Initialise the transmit blocks.
 * Start the command unit executing the NOP
 * self-loop of the first transmit block.
 */
static
void
wavelan_cu_start(device *dev)
{
	unsigned short	ioaddr;
	net_local	*lp;
	int		i;
	unsigned short	txblock;
	unsigned short	first_nop;
	unsigned short	scb_cs;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	lp->tx_first_free = OFFSET_CU;
	lp->tx_first_in_use = I82586NULL;

	for
	(
		i = 0, txblock = OFFSET_CU;
		i < NTXBLOCKS;
		i++, txblock += TXBLOCKZ
	)
	{
		ac_tx_t		tx;
		ac_nop_t	nop;
		tbd_t		tbd;
		unsigned short	tx_addr;
		unsigned short	nop_addr;
		unsigned short	tbd_addr;
		unsigned short	buf_addr;

		tx_addr = txblock;
		nop_addr = tx_addr + sizeof(tx);
		tbd_addr = nop_addr + sizeof(nop);
		buf_addr = tbd_addr + sizeof(tbd);

		tx.tx_h.ac_status = 0;
		tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
		tx.tx_h.ac_link = nop_addr;
		tx.tx_tbd_offset = tbd_addr;
		obram_write(ioaddr, tx_addr, (unsigned char *)&tx, sizeof(tx));

		nop.nop_h.ac_status = 0;
		nop.nop_h.ac_command = acmd_nop;
		nop.nop_h.ac_link = nop_addr;
		obram_write(ioaddr, nop_addr, (unsigned char *)&nop, sizeof(nop));

		tbd.tbd_status = TBD_STATUS_EOF;
		tbd.tbd_next_bd_offset = I82586NULL;
		tbd.tbd_bufl = buf_addr;
		tbd.tbd_bufh = 0;
		obram_write(ioaddr, tbd_addr, (unsigned char *)&tbd, sizeof(tbd));
	}

	first_nop = OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
	obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset), (unsigned char *)&first_nop, sizeof(first_nop));

	scb_cs = SCB_CMD_CUC_GO;
	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cs, sizeof(scb_cs));

	set_chan_attn(ioaddr, lp->hacr);

	for (i = 1000; i > 0; i--)
	{
		obram_read(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cs, sizeof(scb_cs));
		if (scb_cs == 0)
			break;

		udelay(1000);
	}

	if (i <= 0)
		printk("%s: wavelan_cu_start(): board not accepting command.\n", dev->name);

	lp->tx_n_in_use = 0;
	dev->tbusy = 0;
}

static
int
wavelan_open(device *dev)
{
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned long	x;
	int		r;

	if (wavelan_debug > 0)
		printk("%s: ->wavelan_open(dev=0x%x)\n", dev->name, (unsigned int)dev);

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	if (dev->irq == 0)
	{
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_open(): -ENXIO\n", dev->name);
		return -ENXIO;
	}

	if
	(
		irq2dev_map[dev->irq] != (device *)0
		/* This is always true, but avoid the false IRQ. */
		||
		(irq2dev_map[dev->irq] = dev) == (device *)0
		||
		request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN") != 0
	)
	{
		irq2dev_map[dev->irq] = (device *)0;
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_open(): -EAGAIN\n", dev->name);
		return -EAGAIN;
	}

	x = wavelan_splhi();
	if ((r = wavelan_hardware_reset(dev)) != -1)
	{
		dev->interrupt = 0;
		dev->start = 1;
	}
	wavelan_splx(x);

	if (r == -1)
	{
		free_irq(dev->irq);
		irq2dev_map[dev->irq] = (device *)0;
		if (wavelan_debug > 0)
			printk("%s: <-wavelan_open(): -EAGAIN(2)\n", dev->name);
		return -EAGAIN;
	}

#if	defined(MODULE)
	MOD_INC_USE_COUNT;
#endif	/* defined(MODULE) */

	if (wavelan_debug > 0)
		printk("%s: <-wavelan_open(): 0\n", dev->name);

	return 0;
}

static
void
hardware_send_packet(device *dev, void *buf, short length)
{
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned short	txblock;
	unsigned short	txpred;
	unsigned short	tx_addr;
	unsigned short	nop_addr;
	unsigned short	tbd_addr;
	unsigned short	buf_addr;
	ac_tx_t		tx;
	ac_nop_t	nop;
	tbd_t		tbd;
	unsigned long	x;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	x = wavelan_splhi();

	txblock = lp->tx_first_free;
	txpred = txblock - TXBLOCKZ;
	if (txpred < OFFSET_CU)
		txpred += NTXBLOCKS * TXBLOCKZ;
	lp->tx_first_free += TXBLOCKZ;
	if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
		lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;

/*
if (lp->tx_n_in_use > 0)
	printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
*/

	lp->tx_n_in_use++;

	tx_addr = txblock;
	nop_addr = tx_addr + sizeof(tx);
	tbd_addr = nop_addr + sizeof(nop);
	buf_addr = tbd_addr + sizeof(tbd);

	/*
	 * Transmit command.
	 */
	tx.tx_h.ac_status = 0;
	obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status), (unsigned char *)&tx.tx_h.ac_status, sizeof(tx.tx_h.ac_status));

	/*
	 * NOP command.
	 */
	nop.nop_h.ac_status = 0;
	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status), (unsigned char *)&nop.nop_h.ac_status, sizeof(nop.nop_h.ac_status));
	nop.nop_h.ac_link = nop_addr;
	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link), (unsigned char *)&nop.nop_h.ac_link, sizeof(nop.nop_h.ac_link));

	/*
	 * Transmit buffer descriptor. 
	 */
	tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & length);
	tbd.tbd_next_bd_offset = I82586NULL;
	tbd.tbd_bufl = buf_addr;
	tbd.tbd_bufh = 0;
	obram_write(ioaddr, tbd_addr, (unsigned char *)&tbd, sizeof(tbd));

	/*
	 * Data.
	 */
	obram_write(ioaddr, buf_addr, buf, length);

	/*
	 * Overwrite the predecessor NOP link
	 * so that it points to this txblock.
	 */
	nop_addr = txpred + sizeof(tx);
	nop.nop_h.ac_status = 0;
	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status), (unsigned char *)&nop.nop_h.ac_status, sizeof(nop.nop_h.ac_status));
	nop.nop_h.ac_link = txblock;
	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link), (unsigned char *)&nop.nop_h.ac_link, sizeof(nop.nop_h.ac_link));

	if (lp->tx_first_in_use == I82586NULL)
		lp->tx_first_in_use = txblock;

	if (lp->tx_n_in_use < NTXBLOCKS - 1)
		dev->tbusy = 0;

	dev->trans_start = jiffies;

	if (lp->watchdog.next == (timer_list *)0)
		wavelan_watchdog((unsigned long)dev);

	wavelan_splx(x);

	if (wavelan_debug > 4)
	{
		unsigned char	*a;

		a = (unsigned char *)buf;

		printk
		(
			"%s: tx: dest %02x:%02x:%02x:%02x:%02x:%02x, length %d, tbd.tbd_bufl 0x%x.\n",
			dev->name,
			a[0], a[1], a[2], a[3], a[4], a[5],
			length,
			buf_addr
		);
	}
}

static
int
wavelan_send_packet(struct sk_buff *skb, device *dev)
{
	unsigned short	ioaddr;

	ioaddr = dev->base_addr;

	if (dev->tbusy)
	{
		/*
		 * If we get here, some higher level
		 * has decided we are broken.
		 */
		int	tickssofar;

		tickssofar = jiffies - dev->trans_start;

		/*
		 * But for the moment, we will rely on wavelan_watchdog()
		 * instead as it allows finer control over exactly when we
		 * make the determination of failure.
		 *
		if (tickssofar < 5)
		 */
			return 1;

		wavelan_scb_show(ioaddr);
		wavelan_ru_show(dev);
		wavelan_cu_show(dev);
		wavelan_dev_show(dev);
		wavelan_local_show(dev);

		printk("%s: transmit timed out -- resetting board.\n", dev->name);

		(void)wavelan_hardware_reset(dev);
	}

	/*
	 * If some higher layer thinks we've missed
	 * a tx-done interrupt we are passed NULL.
	 * Caution: dev_tint() handles the cli()/sti() itself.
	 */
	if (skb == (struct sk_buff *)0)
	{
		dev_tint(dev);
		return 0;
	}

	/*
	 * Block a timer-based transmit from overlapping.
	 */
	if (set_bit(0, (void *)&dev->tbusy) == 0)
	{
		short		length;
		unsigned char	*buf;

		length = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
		buf = skb->data;

		hardware_send_packet(dev, buf, length);
	}
	else
		printk("%s: Transmitter access conflict.\n", dev->name);

	dev_kfree_skb(skb, FREE_WRITE);

	return 0;
}

#if	0
static
int
addrcmp(unsigned char *a0, unsigned char *a1)
{
	int	i;

	for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
	{
		if (a0[i] != a1[i])
			return a0[i] - a1[i];
	}

	return 0;
}
#endif	/* 0 */

/*
 * Transfer as many packets as we can
 * from the device RAM.
 * Called by the interrupt handler.
 */
static
void
wavelan_receive(device *dev)
{
	unsigned short	ioaddr;
	net_local	*lp;
	int		nreaped;

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;
	nreaped = 0;

	for (;;)
	{
		fd_t		fd;
		rbd_t		rbd;
		ushort		pkt_len;
		int		sksize;
		struct sk_buff	*skb;

		obram_read(ioaddr, lp->rx_head, (unsigned char *)&fd, sizeof(fd));

		if ((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
			break;

		nreaped++;

		if
		(
			(fd.fd_status & (FD_STATUS_B | FD_STATUS_OK))
			!=
			(FD_STATUS_B | FD_STATUS_OK)
		)
		{
			/*
			 * Not sure about this one -- it does not seem
			 * to be an error so we will keep quiet about it.
			if ((fd.fd_status & FD_STATUS_B) != FD_STATUS_B)
				printk("%s: frame not consumed by RU.\n", dev->name);
			 */

			if ((fd.fd_status & FD_STATUS_OK) != FD_STATUS_OK)
				printk("%s: frame not received successfully.\n", dev->name);
		}

		if ((fd.fd_status & (FD_STATUS_S6 | FD_STATUS_S7 | FD_STATUS_S8 | FD_STATUS_S9 | FD_STATUS_S10 | FD_STATUS_S11)) != 0)
		{
			lp->stats.rx_errors++;

			if ((fd.fd_status & FD_STATUS_S6) != 0)
				printk("%s: no EOF flag.\n", dev->name);

			if ((fd.fd_status & FD_STATUS_S7) != 0)
			{
				lp->stats.rx_length_errors++;
				printk("%s: frame too short.\n", dev->name);
			}

			if ((fd.fd_status & FD_STATUS_S8) != 0)
			{
				lp->stats.rx_over_errors++;
				printk("%s: rx DMA overrun.\n", dev->name);
			}

			if ((fd.fd_status & FD_STATUS_S9) != 0)
			{
				lp->stats.rx_fifo_errors++;
				printk("%s: ran out of resources.\n", dev->name);
			}

			if ((fd.fd_status & FD_STATUS_S10) != 0)
			{
				lp->stats.rx_frame_errors++;
				printk("%s: alignment error.\n", dev->name);
			}

			if ((fd.fd_status & FD_STATUS_S11) != 0)
			{
				lp->stats.rx_crc_errors++;
				printk("%s: CRC error.\n", dev->name);
			}
		}

		if (fd.fd_rbd_offset == I82586NULL)
			printk("%s: frame has no data.\n", dev->name);
		else
		{
			obram_read(ioaddr, fd.fd_rbd_offset, (unsigned char *)&rbd, sizeof(rbd));

			if ((rbd.rbd_status & RBD_STATUS_EOF) != RBD_STATUS_EOF)
				printk("%s: missing EOF flag.\n", dev->name);

			if ((rbd.rbd_status & RBD_STATUS_F) != RBD_STATUS_F)
				printk("%s: missing F flag.\n", dev->name);

			pkt_len = rbd.rbd_status & RBD_STATUS_ACNT;

#if	0
			{
				unsigned char		addr[WAVELAN_ADDR_SIZE];
				int			i;
				static unsigned char	toweraddr[WAVELAN_ADDR_SIZE]	=
				{
					0x08, 0x00, 0x0e, 0x20, 0x3e, 0xd3,
				};

				obram_read(ioaddr, rbd.rbd_bufl + sizeof(addr), &addr[0], sizeof(addr));
				if
				(
					/*
					addrcmp(&addr[0], &dev->dev_addr[0]) != 0
					&&
					*/
					addrcmp(&addr[0], toweraddr) != 0
				)
				{
					printk("%s: foreign MAC source addr=", dev->name);
					for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
						printk("%s%02x", (i == 0) ? "" : ":", addr[i]);
					printk("\n");
				}
			}
#endif	/* 0 */

			if (wavelan_debug > 5)
			{
				unsigned char	addr[WAVELAN_ADDR_SIZE];
				unsigned short	ltype;
				int		i;

#if	0
				printk("%s: fd_dest=", dev->name);
				for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
					printk("%s%02x", (i == 0) ? "" : ":", fd.fd_dest[i]);
				printk("\n");

				printk("%s: fd_src=", dev->name);
				for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
					printk("%s%02x", (i == 0) ? "" : ":", fd.fd_src[i]);
				printk("\n");
				printk("%s: fd_length=%d\n", dev->name, fd.fd_length);
#endif	/* 0 */

				obram_read(ioaddr, rbd.rbd_bufl, &addr[0], sizeof(addr));
				printk("%s: dest=", dev->name);
				for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
					printk("%s%02x", (i == 0) ? "" : ":", addr[i]);
				printk("\n");

				obram_read(ioaddr, rbd.rbd_bufl + sizeof(addr), &addr[0], sizeof(addr));
				printk("%s: src=", dev->name);
				for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
					printk("%s%02x", (i == 0) ? "" : ":", addr[i]);
				printk("\n");

				obram_read(ioaddr, rbd.rbd_bufl + sizeof(addr) * 2, (unsigned char *)&ltype, sizeof(ltype));
				printk("%s: ntohs(length/type)=0x%04x\n", dev->name, ntohs(ltype));
			}

			sksize = pkt_len;

			if ((skb = alloc_skb(sksize, GFP_ATOMIC)) == (struct sk_buff *)0)
			{
				printk("%s: could not alloc_skb(%d, GFP_ATOMIC).\n", dev->name, sksize);
				lp->stats.rx_dropped++;
			}
			else
			{
				skb->len = pkt_len;
				skb->dev = dev;

				obram_read(ioaddr, rbd.rbd_bufl, skb->data, pkt_len);

				if (wavelan_debug > 5)
				{
					int	i;
					int	maxi;

					printk("%s: pkt_len=%d, data=\"", dev->name, pkt_len);

					if ((maxi = pkt_len) > 16)
						maxi = 16;
				
					for (i = 0; i < maxi; i++)
					{
						unsigned char	c;

						c = skb->data[i];
						if (c >= ' ' && c <= '~')
							printk(" %c", skb->data[i]);
						else
							printk("%02x", skb->data[i]);
					}

					if (maxi < pkt_len)
						printk("..");
				
					printk("\"\n\n");
				}
			
				skb->protocol=eth_type_trans(skb,dev);
				netif_rx(skb);

				lp->stats.rx_packets++;
			}
		}

		fd.fd_status = 0;
		obram_write(ioaddr, fdoff(lp->rx_head, fd_status), (unsigned char *)&fd.fd_status, sizeof(fd.fd_status));

		fd.fd_command = FD_COMMAND_EL;
		obram_write(ioaddr, fdoff(lp->rx_head, fd_command), (unsigned char *)&fd.fd_command, sizeof(fd.fd_command));

		fd.fd_command = 0;
		obram_write(ioaddr, fdoff(lp->rx_last, fd_command), (unsigned char *)&fd.fd_command, sizeof(fd.fd_command));

		lp->rx_last = lp->rx_head;
		lp->rx_head = fd.fd_link_offset;
	}

/*
	if (nreaped > 1)
		printk("r%d", nreaped);
*/
}

/*
 * Command completion interrupt.
 * Reclaim as many freed tx buffers as we can.
 */
static
int
wavelan_complete(device *dev, unsigned short ioaddr, net_local *lp)
{
	int	nreaped;

	nreaped = 0;

	for (;;)
	{
		unsigned short	tx_status;

		if (lp->tx_first_in_use == I82586NULL)
			break;

		obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status), (unsigned char *)&tx_status, sizeof(tx_status));

		if ((tx_status & AC_SFLD_C) == 0)
			break;

		nreaped++;

		--lp->tx_n_in_use;

/*
if (lp->tx_n_in_use > 0)
	printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
*/

		if (lp->tx_n_in_use <= 0)
			lp->tx_first_in_use = I82586NULL;
		else
		{
			lp->tx_first_in_use += TXBLOCKZ;
			if (lp->tx_first_in_use >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
				lp->tx_first_in_use -= NTXBLOCKS * TXBLOCKZ;
		}

		if (tx_status & AC_SFLD_OK)
		{
			int	ncollisions;

			lp->stats.tx_packets++;
			ncollisions = tx_status & AC_SFLD_MAXCOL;
			lp->stats.collisions += ncollisions;
			/*
			if (ncollisions > 0)
				printk("%s: tx completed after %d collisions.\n", dev->name, ncollisions);
			*/
		}
		else
		{
			lp->stats.tx_errors++;
			if (tx_status & AC_SFLD_S10)
			{
				lp->stats.tx_carrier_errors++;
				if (wavelan_debug > 0)
					printk("%s:     tx error: no CS.\n", dev->name);
			}
			if (tx_status & AC_SFLD_S9)
			{
				lp->stats.tx_carrier_errors++;
				printk("%s:     tx error: lost CTS.\n", dev->name);
			}
			if (tx_status & AC_SFLD_S8)
			{
				lp->stats.tx_fifo_errors++;
				printk("%s:     tx error: slow DMA.\n", dev->name);
			}
			if (tx_status & AC_SFLD_S6)
			{
				lp->stats.tx_heartbeat_errors++;
				if (wavelan_debug > 0)
					printk("%s:     tx error: heart beat.\n", dev->name);
			}
			if (tx_status & AC_SFLD_S5)
			{
				lp->stats.tx_aborted_errors++;
				if (wavelan_debug > 0)
					printk("%s:     tx error: too many collisions.\n", dev->name);
			}
		}

		if (wavelan_debug > 5)
			printk("%s:     tx completed, tx_status 0x%04x.\n", dev->name, tx_status);
	}

/*
	if (nreaped > 1)
		printk("c%d", nreaped);
*/

	/*
	 * Inform upper layers.
	 */
	if (lp->tx_n_in_use < NTXBLOCKS - 1)
	{
		dev->tbusy = 0;
		mark_bh(NET_BH);
	}

	return nreaped;
}

static
void
wavelan_watchdog(unsigned long a)
{
	device		*dev;
	net_local	*lp;
	unsigned short	ioaddr;
	unsigned long	x;
	unsigned int	nreaped;

	x = wavelan_splhi();

	dev = (device *)a;
	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	if (lp->tx_n_in_use <= 0)
	{
		wavelan_splx(x);
		return;
	}

	lp->watchdog.expires = WATCHDOG_JIFFIES;
	add_timer(&lp->watchdog);

	if (jiffies - dev->trans_start < WATCHDOG_JIFFIES)
	{
		wavelan_splx(x);
		return;
	}

	nreaped = wavelan_complete(dev, ioaddr, lp);

	printk("%s: warning: wavelan_watchdog(): %d reaped, %d remain.\n", dev->name, nreaped, lp->tx_n_in_use);
	/*
	wavelan_scb_show(ioaddr);
	wavelan_ru_show(dev);
	wavelan_cu_show(dev);
	wavelan_dev_show(dev);
	wavelan_local_show(dev);
	*/

	wavelan_splx(x);
}

static
void
wavelan_interrupt(int irq, struct pt_regs *regs)
{
	device		*dev;
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned short	hasr;
	unsigned short	status;
	unsigned short	ack_cmd;

	if ((dev = (device *)(irq2dev_map[irq])) == (device *)0)
	{
		printk("wavelan_interrupt(): irq %d for unknown device.\n", irq);
		return;
	}

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	dev->interrupt = 1;

	if ((hasr = hasr_read(ioaddr)) & HASR_MMC_INTR)
	{
		unsigned char	dce_status;

		/*
		 * Interrupt from the modem management controller.
		 * This will clear it -- ignored for now.
		 */
		mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status, sizeof(dce_status));
		if (wavelan_debug > 0)
			printk("%s: warning: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n", dev->name, dce_status);
	}

	if ((hasr & HASR_82586_INTR) == 0)
	{
		dev->interrupt = 0;
		if (wavelan_debug > 0)
			printk("%s: warning: wavelan_interrupt() but (hasr & HASR_82586_INTR) == 0.\n", dev->name);
		return;
	}

	obram_read(ioaddr, scboff(OFFSET_SCB, scb_status), (unsigned char *)&status, sizeof(status));

	/*
	 * Acknowledge the interrupt(s).
	 */
	ack_cmd = status & SCB_ST_INT;

	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&ack_cmd, sizeof(ack_cmd));

	set_chan_attn(ioaddr, lp->hacr);

	if (wavelan_debug > 5)
		printk("%s: interrupt, status 0x%04x.\n", dev->name, status);

	if ((status & SCB_ST_CX) == SCB_ST_CX)
	{
		/*
		 * Command completed.
		 */
		if (wavelan_debug > 5)
			printk("%s: command completed.\n", dev->name);
		(void)wavelan_complete(dev, ioaddr, lp);
	}

	if ((status & SCB_ST_FR) == SCB_ST_FR)
	{
		/*
		 * Frame received.
		 */
		if (wavelan_debug > 5)
			printk("%s: received packet.\n", dev->name);
		wavelan_receive(dev);
	}

	if
	(
		(status & SCB_ST_CNA) == SCB_ST_CNA
		||
		(((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) && dev->start)
	)
	{
		printk("%s: warning: CU inactive -- restarting.\n", dev->name);

		(void)wavelan_hardware_reset(dev);
	}

	if
	(
		(status & SCB_ST_RNR) == SCB_ST_RNR
		||
		(((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) && dev->start)
	)
	{
		printk("%s: warning: RU not ready -- restarting.\n", dev->name);

		(void)wavelan_hardware_reset(dev);
	}

	dev->interrupt = 0;
}

static
int
wavelan_close(device *dev)
{
	unsigned short	ioaddr;
	net_local	*lp;
	unsigned short	scb_cmd;

	if (wavelan_debug > 0)
		printk("%s: ->wavelan_close(dev=0x%x)\n", dev->name, (unsigned int)dev);

	ioaddr = dev->base_addr;
	lp = (net_local *)dev->priv;

	dev->tbusy = 1;
	dev->start = 0;

	/*
	 * Flush the Tx and disable Rx.
	 */
	scb_cmd = (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC & SCB_CMD_RUC_SUS);
	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command), (unsigned char *)&scb_cmd, sizeof(scb_cmd));
	set_chan_attn(ioaddr, lp->hacr);

	wavelan_ints_off(dev);

	free_irq(dev->irq);
	irq2dev_map[dev->irq] = (device *)0;

	/*
	 * Release the ioport-region.
	 */
	release_region(ioaddr, sizeof(ha_t));

#if	defined(MODULE)
	MOD_DEC_USE_COUNT;
#endif	/* defined(MODULE) */

	if (wavelan_debug > 0)
		printk("%s: <-wavelan_close(): 0\n", dev->name);

	return 0;
}

/*
 * Get the current statistics.
 * This may be called with the card open or closed.
 */
static
en_stats	*
wavelan_get_stats(device *dev)
{
	net_local	*lp;

	lp = (net_local *)dev->priv;

	return &lp->stats;
}

static
void
wavelan_set_multicast_list(device *dev, int num_addrs, void *addrs)
{
	net_local	*lp;
	unsigned long	x;

	if (wavelan_debug > 0)
		printk("%s: ->wavelan_set_multicast_list(dev=0x%x, num_addrs=%d, addrs=0x%x)\n", dev->name, (unsigned int)dev, num_addrs, (unsigned int)addrs);

	lp = (net_local *)dev->priv;

	switch (num_addrs)
	{
	case -1:
		/*
		 * Promiscuous mode: receive all packets.
		 */
		lp->promiscuous = 1;
		x = wavelan_splhi();
		(void)wavelan_hardware_reset(dev);
		wavelan_splx(x);
		break;

	case 0:
		/*
		 * Normal mode: disable promiscuous mode,
		 * clear multicast list.
		 */
		lp->promiscuous = 0;
		x = wavelan_splhi();
		(void)wavelan_hardware_reset(dev);
		wavelan_splx(x);
		break;

	default:
		/*
		 * Multicast mode: receive normal and
		 * multicast packets and do best-effort filtering.
		 */
		break;
	}

	if (wavelan_debug > 0)
		printk("%s: <-wavelan_set_multicast_list()\n", dev->name);
}

/*
 * Extra WaveLAN-specific device data.
 * "cat /proc/net/wavelan" -- see fs/proc/net.c.
 */
static
int
sprintf_stats(char *buffer, device *dev)
{
	net_local	*lp;
	unsigned char	v;
	mmr_t		m;

	lp = (net_local *)dev->priv;

	if (lp == (net_local *)0)
		return sprintf(buffer, "%6s: No statistics available.\n", dev->name);

	v = (unsigned char)1;
	mmc_write(dev->base_addr, mmwoff(0, mmw_freeze), &v, sizeof(v));

	mmc_read(dev->base_addr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, sizeof(m.mmr_dce_status));
	mmc_read(dev->base_addr, mmroff(0, mmr_correct_nwid_h), &m.mmr_correct_nwid_h, sizeof(m.mmr_correct_nwid_h));
	mmc_read(dev->base_addr, mmroff(0, mmr_correct_nwid_l), &m.mmr_correct_nwid_l, sizeof(m.mmr_correct_nwid_l));
	mmc_read(dev->base_addr, mmroff(0, mmr_wrong_nwid_h), &m.mmr_wrong_nwid_h, sizeof(m.mmr_wrong_nwid_h));
	mmc_read(dev->base_addr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, sizeof(m.mmr_wrong_nwid_l));
	mmc_read(dev->base_addr, mmroff(0, mmr_signal_lvl), &m.mmr_signal_lvl, sizeof(m.mmr_signal_lvl));
	mmc_read(dev->base_addr, mmroff(0, mmr_silence_lvl), &m.mmr_silence_lvl, sizeof(m.mmr_silence_lvl));
	mmc_read(dev->base_addr, mmroff(0, mmr_sgnl_qual), &m.mmr_sgnl_qual, sizeof(m.mmr_sgnl_qual));

	v = (unsigned char)0;
	mmc_write(dev->base_addr, mmwoff(0, mmw_freeze), &v, sizeof(v));

	lp->correct_nwid += (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l;
	lp->wrong_nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;

	return sprintf
	(
		buffer,
		"%6s:   %02x %08x %08x   %02x   %02x   %02x   %02x    %u\n",
		dev->name,
		m.mmr_dce_status,
		lp->correct_nwid,
		lp->wrong_nwid,
		m.mmr_signal_lvl,
		m.mmr_silence_lvl,
		m.mmr_sgnl_qual,
		lp->tx_n_in_use,
		lp->nresets
	);
}

int
wavelan_get_info(char *buffer, char **start, off_t offset, int length)
{
	int		len;
	off_t		begin;
	off_t		pos;
	int		size;
	unsigned long	x;

	len = 0;
	begin = 0;
	pos = 0;

	size = sprintf(buffer, "%s", "Iface |  dce    +nwid    -nwid  lvl slnc qual ntxq nrst\n");

	pos += size;
	len += size;
	
	x = wavelan_splhi();

	if (first_wavelan != (net_local *)0)
	{
		net_local	*lp;

		lp = first_wavelan;
		do
		{
			size = sprintf_stats(buffer + len, lp->dev);

			len += size;
			pos = begin + len;
					
			if (pos < offset)
			{
				len = 0;
				begin = pos;
			}

			if (pos > offset + length)
				break;
		}
			while ((lp = lp->next) != first_wavelan);
	}

	wavelan_splx(x);

	*start = buffer + (offset - begin);	/* Start of wanted data */
	len -= (offset - begin);		/* Start slop */
	if (len > length)
		len = length;			/* Ending slop */

	return len;
}

#if	defined(MODULE)
char			kernel_version[]	= UTS_RELEASE;
static struct device	dev_wavelan		=
{
	"       " /* "wavelan" */,
	0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, wavelan_probe
};

int
init_module(void)
{
	if (register_netdev(&dev_wavelan) != 0)
		return -EIO;
	return 0;
}

void
cleanup_module(void)
{
	if (MOD_IN_USE)
		printk("wavelan: device busy, remove delayed\n");
	else
	{
		unregister_netdev(&dev_wavelan);
		kfree_s(dev_wavelan.priv, sizeof(struct net_local));
		dev_wavelan.priv = NULL;
	}
}
#endif	/* defined(MODULE) */

static
void
wavelan_cu_show_one(device *dev, net_local *lp, int i, unsigned short p)
{
	unsigned short	ioaddr;
	ac_tx_t		actx;

	ioaddr = dev->base_addr;

	printk("%d: 0x%x:", i, p);

	obram_read(ioaddr, p, (unsigned char *)&actx, sizeof(actx));
	printk(" status=0x%x,", actx.tx_h.ac_status);
	printk(" command=0x%x,", actx.tx_h.ac_command);

/*
	{
		tbd_t	tbd;

		obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
		printk(" tbd_status=0x%x,", tbd.tbd_status);
	}
*/

	printk("|");
}

#if	0
static
void
wavelan_psa_show(psa_t *p)
{
	printk("psa:");

	printk("psa_io_base_addr_1: 0x%02x,", p->psa_io_base_addr_1);
	printk("psa_io_base_addr_2: 0x%02x,", p->psa_io_base_addr_2);
	printk("psa_io_base_addr_3: 0x%02x,", p->psa_io_base_addr_3);
	printk("psa_io_base_addr_4: 0x%02x,", p->psa_io_base_addr_4);
	printk("psa_rem_boot_addr_1: 0x%02x,", p->psa_rem_boot_addr_1);
	printk("psa_rem_boot_addr_2: 0x%02x,", p->psa_rem_boot_addr_2);
	printk("psa_rem_boot_addr_3: 0x%02x,", p->psa_rem_boot_addr_3);
	printk("psa_holi_params: 0x%02x,", p->psa_holi_params);
	printk("psa_int_req_no: %d,", p->psa_int_req_no);
	printk
	(
		"psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x,",
		p->psa_univ_mac_addr[0],
		p->psa_univ_mac_addr[1],
		p->psa_univ_mac_addr[2],
		p->psa_univ_mac_addr[3],
		p->psa_univ_mac_addr[4],
		p->psa_univ_mac_addr[5]
	);
	printk
	(
		"psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x,",
		p->psa_local_mac_addr[0],
		p->psa_local_mac_addr[1],
		p->psa_local_mac_addr[2],
		p->psa_local_mac_addr[3],
		p->psa_local_mac_addr[4],
		p->psa_local_mac_addr[5]
	);
	printk("psa_univ_local_sel: %d,", p->psa_univ_local_sel);
	printk("psa_comp_number: %d,", p->psa_comp_number);
	printk("psa_thr_pre_set: 0x%02x,", p->psa_thr_pre_set);
	printk("psa_feature_select/decay_prm: 0x%02x,", p->psa_feature_select);
	printk("psa_subband/decay_update_prm: %d,", p->psa_subband);
	printk("psa_quality_thr: 0x%02x,", p->psa_quality_thr);
	printk("psa_mod_delay: 0x%02x,", p->psa_mod_delay);
	printk("psa_nwid: 0x%02x%02x,", p->psa_nwid[0], p->psa_nwid[1]);
	printk("psa_undefined: %d,", p->psa_undefined);
	printk("psa_encryption_select: %d,", p->psa_encryption_select);
	printk
	(
		"psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x,",
		p->psa_encryption_key[0],
		p->psa_encryption_key[1],
		p->psa_encryption_key[2],
		p->psa_encryption_key[3],
		p->psa_encryption_key[4],
		p->psa_encryption_key[5],
		p->psa_encryption_key[6],
		p->psa_encryption_key[7]
	);
	printk("psa_databus_width: %d,", p->psa_databus_width);
	printk("psa_call_code/auto_squelch: 0x%02x,", p->psa_call_code);
	printk("psa_no_of_retries: %d,", p->psa_no_of_retries);
	printk("psa_acr: %d,", p->psa_acr);
	printk("psa_dump_count: %d,", p->psa_dump_count);
	printk("psa_nwid_prefix: 0x%02x,", p->psa_nwid_prefix);
	printk("psa_conf_status: %d,", p->psa_conf_status);
	printk("psa_crc: 0x%02x%02x,", p->psa_crc[0], p->psa_crc[1]);
	printk("psa_crc_status: 0x%02x,", p->psa_crc_status);

	printk("\n");
}

static
void
wavelan_mmc_show(unsigned short ioaddr)
{
	mmr_t	m;

	mmc_read(ioaddr, 0, (unsigned char *)&m, sizeof(m));

	printk("mmr:");
	printk(" des_status: 0x%x", m.mmr_des_status);
	printk(" des_avail: 0x%x", m.mmr_des_avail);
	printk(" des_io_invert: 0x%x", m.mmr_des_io_invert);
	printk
	(
		" dce_status: 0x%x[%s%s%s%s]",
		m.mmr_dce_status & 0x0F,
		(m.mmr_dce_status & MMR_DCE_STATUS_ENERG_DET) ? "energy detected," : "",
		(m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ? "loop test indicated," : "",
		(m.mmr_dce_status & MMR_DCE_STATUS_XMTITR_IND) ? "transmitter on," : "",
		(m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ? "jabber timer expired," : ""
	);
	printk(" correct_nwid: %d", m.mmr_correct_nwid_h << 8 | m.mmr_correct_nwid_l);
	printk(" wrong_nwid: %d", (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
	printk(" thr_pre_set: 0x%x", m.mmr_thr_pre_set);
	printk(" signal_lvl: %d", m.mmr_signal_lvl);
	printk(" silence_lvl: %d", m.mmr_silence_lvl);
	printk(" sgnl_qual: 0x%x", m.mmr_sgnl_qual);
	printk(" netw_id_l: %x", m.mmr_netw_id_l);

	printk("\n");
}
#endif	/* 0 */

static
void
wavelan_scb_show(unsigned short ioaddr)
{
	scb_t	scb;

	obram_read(ioaddr, OFFSET_SCB, (unsigned char *)&scb, sizeof(scb));   

	printk("scb:");

	printk(" status:");
	printk
	(
		" stat 0x%x[%s%s%s%s]",
		(scb.scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA | SCB_ST_RNR)) >> 12,
		(scb.scb_status & SCB_ST_CX) ? "cmd completion interrupt," : "",
		(scb.scb_status & SCB_ST_FR) ? "frame received," : "",
		(scb.scb_status & SCB_ST_CNA) ? "cmd unit not active," : "",
		(scb.scb_status & SCB_ST_RNR) ? "rcv unit not ready," : ""
	);
	printk
	(
		" cus 0x%x[%s%s%s]",
		(scb.scb_status & SCB_ST_CUS) >> 8,
		((scb.scb_status & SCB_ST_CUS) == SCB_ST_CUS_IDLE) ? "idle" : "",
		((scb.scb_status & SCB_ST_CUS) == SCB_ST_CUS_SUSP) ? "suspended" : "",
		((scb.scb_status & SCB_ST_CUS) == SCB_ST_CUS_ACTV) ? "active" : ""
	);
	printk
	(
		" rus 0x%x[%s%s%s%s]",
		(scb.scb_status & SCB_ST_RUS) >> 4,
		((scb.scb_status & SCB_ST_RUS) == SCB_ST_RUS_IDLE) ? "idle" : "",
		((scb.scb_status & SCB_ST_RUS) == SCB_ST_RUS_SUSP) ? "suspended" : "",
		((scb.scb_status & SCB_ST_RUS) == SCB_ST_RUS_NRES) ? "no resources" : "",
		((scb.scb_status & SCB_ST_RUS) == SCB_ST_RUS_RDY) ? "ready" : ""
	);

	printk(" command:");
	printk
	(
		" ack 0x%x[%s%s%s%s]",
		(scb.scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR | SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12,
		(scb.scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "",
		(scb.scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "",
		(scb.scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "",
		(scb.scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : ""
	);
	printk
	(
		" cuc 0x%x[%s%s%s%s%s]",
		(scb.scb_command & SCB_CMD_CUC) >> 8,
		((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_NOP) ? "nop" : "",
		((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_GO) ? "start cbl_offset" : "",
		((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_RES) ? "resume execution" : "",
		((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_SUS) ? "suspend execution" : "",
		((scb.scb_command & SCB_CMD_CUC) == SCB_CMD_CUC_ABT) ? "abort execution" : ""
	);
	printk
	(
		" ruc 0x%x[%s%s%s%s%s]",
		(scb.scb_command & SCB_CMD_RUC) >> 4,
		((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_NOP) ? "nop" : "",
		((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_GO) ? "start rfa_offset" : "",
		((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_RES) ? "resume reception" : "",
		((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_SUS) ? "suspend reception" : "",
		((scb.scb_command & SCB_CMD_RUC) == SCB_CMD_RUC_ABT) ? "abort reception" : ""
	);

	printk(" cbl_offset 0x%x", scb.scb_cbl_offset);
	printk(" rfa_offset 0x%x", scb.scb_rfa_offset);

	printk(" crcerrs %d", scb.scb_crcerrs);
	printk(" alnerrs %d", scb.scb_alnerrs);
	printk(" rscerrs %d", scb.scb_rscerrs);
	printk(" ovrnerrs %d", scb.scb_ovrnerrs);

	printk("\n");
}

static
void
wavelan_ru_show(device *dev)
{
	net_local	*lp;

	lp = (net_local *)dev->priv;

	printk("ru:");
	/*
	 * Not implemented yet...
	 */
	printk("\n");
}

static
void
wavelan_cu_show(device *dev)
{
	net_local	*lp;
	unsigned int	i;
	unsigned short	p;

	lp = (net_local *)dev->priv;

	printk("cu:");
	printk("\n");

	for (i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++)
	{
		wavelan_cu_show_one(dev, lp, i, p);

		p += TXBLOCKZ;
		if (p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
			p -= NTXBLOCKS * TXBLOCKZ;
	}
}

static
void
wavelan_dev_show(device *dev)
{
	printk("dev:");
	printk(" start=%d,", dev->start);
	printk(" tbusy=%d,", dev->tbusy);
	printk(" interrupt=%d,", dev->interrupt);
	printk(" trans_start=%ld,", dev->trans_start);
	printk(" flags=0x%x,", dev->flags);
	printk("\n");
}

static
void
wavelan_local_show(device *dev)
{
	net_local	*lp;

	lp = (net_local *)dev->priv;

	printk("local:");
	printk(" tx_n_in_use=%d,", lp->tx_n_in_use);
	printk(" hacr=0x%x,", lp->hacr);
	printk(" rx_head=0x%x,", lp->rx_head);
	printk(" rx_last=0x%x,", lp->rx_last);
	printk(" tx_first_free=0x%x,", lp->tx_first_free);
	printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use);
	printk("\n");
}

/*
 * This software may only be used and distributed
 * according to the terms of the GNU Public License.
 *
 * This software was developed as a component of the
 * Linux operating system.
 * It is based on other device drivers and information
 * either written or supplied by:
 *	Ajay Bakre (bakre@paul.rutgers.edu),
 *	Donald Becker (becker@cesdis.gsfc.nasa.gov),
 *	Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
 *	Anders Klemets (klemets@it.kth.se),
 *	Vladimir V. Kolpakov (w@stier.koenig.ru),
 *	Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
 *	Pauline Middelink (middelin@polyware.iaf.nl),
 *	Robert Morris (rtm@das.harvard.edu),
 *	Girish Welling (welling@paul.rutgers.edu),
 *
 * Thanks go also to:
 *	James Ashton (jaa101@syseng.anu.edu.au),
 *	Alan Cox (iialan@iiit.swan.ac.uk),
 *	Allan Creighton (allanc@cs.usyd.edu.au),
 *	Matthew Geier (matthew@cs.usyd.edu.au),
 *	Remo di Giovanni (remo@cs.usyd.edu.au),
 *	Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
 *	Vipul Gupta (vgupta@cs.binghamton.edu),
 *	Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
 *	Tim Nicholson (tim@cs.usyd.edu.au),
 *	Ian Parkin (ian@cs.usyd.edu.au),
 *	John Rosenberg (johnr@cs.usyd.edu.au),
 *	George Rossi (george@phm.gov.au),
 *	Arthur Scott (arthur@cs.usyd.edu.au),
 *	Peter Storey,
 * for their assistance and advice.
 *
 * Please send bug reports, updates, comments to:
 *
 * Bruce Janson                                    Email:  bruce@cs.usyd.edu.au
 * Basser Department of Computer Science           Phone:  +61-2-351-3423
 * University of Sydney, N.S.W., 2006, AUSTRALIA   Fax:    +61-2-351-3838
 */
#endif	/* defined(CONFIG_WAVELAN) */