|
|
1.1 root 1: #include "u.h"
2: #include "lib.h"
3: #include "mem.h"
4: #include "dat.h"
5: #include "fns.h"
6: #include "io.h"
7:
8: #include "ether.h"
9:
10: /*
11: * Driver written for the 'Notebook Computer Ethernet LAN Adapter',
12: * a plug-in to the bus-slot on the rear of the Gateway NOMAD 425DXL
13: * laptop. The manual says NE2000 compatible.
14: * The interface appears to be pretty well described in the National
15: * Semiconductor Local Area Network Databook (1992) as one of the
16: * AT evaluation cards.
17: *
18: * The NE2000 is really just a DP8390[12] plus a data port
19: * and a reset port.
20: */
21: enum {
22: Data = 0x10, /* offset from I/O base of data port */
23: Reset = 0x18, /* offset from I/O base of reset port */
24: };
25:
26: int
27: ne2000reset(Ctlr *ctlr)
28: {
29: ushort buf[16];
30: int i;
31:
32: /*
33: * Set up the software configuration.
34: * Use defaults for port, irq, mem and size
35: * if not specified.
36: */
37: if(ctlr->card.port == 0)
38: ctlr->card.port = 0x300;
39: if(ctlr->card.irq == 0)
40: ctlr->card.irq = 2;
41: if(ctlr->card.mem == 0)
42: ctlr->card.mem = 0x4000;
43: if(ctlr->card.size == 0)
44: ctlr->card.size = 16*1024;
45:
46: ctlr->card.reset = ne2000reset;
47: ctlr->card.attach = dp8390attach;
48: ctlr->card.read = dp8390read;
49: ctlr->card.write = dp8390write;
50: ctlr->card.receive = dp8390receive;
51: ctlr->card.transmit = dp8390transmit;
52: ctlr->card.intr = dp8390intr;
53: ctlr->card.overflow = dp8390overflow;
54:
55: ctlr->card.bit16 = 1;
56: ctlr->card.dp8390 = ctlr->card.port;
57: ctlr->card.data = ctlr->card.port+Data;
58:
59: ctlr->card.tstart = HOWMANY(ctlr->card.mem, Dp8390BufSz);
60: ctlr->card.pstart = ctlr->card.tstart + HOWMANY(sizeof(Etherpkt), Dp8390BufSz);
61: ctlr->card.pstop = ctlr->card.tstart + HOWMANY(ctlr->card.size, Dp8390BufSz);
62:
63: /*
64: * Reset the board. This is done by doing a read
65: * followed by a write to the Reset address.
66: */
67: buf[0] = inb(ctlr->card.port+Reset);
68: delay(2);
69: outb(ctlr->card.port+Reset, buf[0]);
70:
71: /*
72: * Init the (possible) chip, then use the (possible)
73: * chip to read the (possible) PROM for ethernet address
74: * and a marker byte.
75: * We could just look at the DP8390 command register after
76: * initialisation has been tried, but that wouldn't be
77: * enough, there are other ethernet boards which could
78: * match.
79: */
80: dp8390reset(ctlr);
81: memset(buf, 0, sizeof(buf));
82: dp8390read(ctlr, buf, 0, sizeof(buf));
83: if((buf[0x0E] & 0xFF) != 0x57 || (buf[0x0F] & 0xFF) != 0x57)
84: return -1;
85:
86: /*
87: * Stupid machine. We asked for shorts, we got shorts,
88: * although the PROM is a byte array.
89: * Now we can set the ethernet address.
90: */
91: if((ctlr->card.ea[0]|ctlr->card.ea[1]|ctlr->card.ea[2]|ctlr->card.ea[3]|ctlr->card.ea[4]|ctlr->card.ea[5]) == 0){
92: for(i = 0; i < sizeof(ctlr->card.ea); i++)
93: ctlr->card.ea[i] = buf[i];
94: }
95: dp8390setea(ctlr);
96:
97: return 0;
98: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.