2 #include "../port/lib.h"
7 #include "../port/error.h"
8 #include "../port/netif.h"
11 #include "ether8390.h"
14 * Driver written for the 'Notebook Computer Ethernet LAN Adapter',
15 * a plug-in to the bus-slot on the rear of the Gateway NOMAD 425DXL
16 * laptop. The manual says NE2000 compatible.
17 * The interface appears to be pretty well described in the National
18 * Semiconductor Local Area Network Databook (1992) as one of the
19 * AT evaluation cards.
21 * The NE2000 is really just a DP8390[12] plus a data port
25 Data = 0x10, /* offset from I/O base of data port */
26 Reset = 0x1F, /* offset from I/O base of reset port */
29 typedef struct Ctlr Ctlr;
36 static Ctlr* ctlrhead;
37 static Ctlr* ctlrtail;
43 { "Realtek 8029", (0x8029<<16)|0x10EC, },
44 { "Winbond 89C940", (0x0940<<16)|0x1050, },
49 ne2000match(Ether* edev, int id)
56 * Any adapter matches if no edev->port is supplied,
57 * otherwise the ports must match.
59 for(ctlr = ctlrhead; ctlr != nil; ctlr = ctlr->next){
63 if(((p->did<<16)|p->vid) != id)
65 port = p->mem[0].bar & ~0x01;
66 if(edev->port != 0 && edev->port != port)
70 * It suffices to fill these in,
71 * the rest is gleaned from the card.
85 ne2000pnp(Ether* edev)
92 * Make a list of all ethernet controllers
93 * if not already done.
97 while(p = pcimatch(p, 0, 0)){
98 if(p->ccrb != 0x02 || p->ccru != 0)
100 ctlr = malloc(sizeof(Ctlr));
104 ctlrtail->next = ctlr;
112 * Is it a card with an unrecognised vid+did?
113 * Normally a search is made through all the found controllers
114 * for one which matches any of the known vid+did pairs.
115 * If a vid+did pair is specified a search is made for that
116 * specific controller only.
119 for(i = 0; i < edev->nopt; i++){
120 if(cistrncmp(edev->opt[i], "id=", 3) == 0)
121 id = strtol(&edev->opt[i][3], nil, 0);
125 ne2000match(edev, id);
126 else for(i = 0; ne2000pci[i].name; i++){
127 if(ne2000match(edev, ne2000pci[i].id) != nil)
133 ne2000reset(Ether* edev)
145 * Set up the software configuration.
146 * Use defaults for irq, mem and size
148 * Must have a port, no more default.
157 edev->size = 16*1024;
160 if(ioalloc(edev->port, 0x20, 0, "ne2000") < 0)
163 edev->ctlr = malloc(sizeof(Dp8390));
169 dp8390->data = port+Data;
171 dp8390->tstart = HOWMANY(edev->mem, Dp8390BufSz);
172 dp8390->pstart = dp8390->tstart + HOWMANY(sizeof(Etherpkt), Dp8390BufSz);
173 dp8390->pstop = dp8390->tstart + HOWMANY(edev->size, Dp8390BufSz);
176 for(i = 0; i < edev->nopt; i++){
177 if(strcmp(edev->opt[i], "nodummyrr"))
184 * Reset the board. This is done by doing a read
185 * followed by a write to the Reset address.
187 buf[0] = inb(port+Reset);
189 outb(port+Reset, buf[0]);
193 * Init the (possible) chip, then use the (possible)
194 * chip to read the (possible) PROM for ethernet address
196 * Could just look at the DP8390 command register after
197 * initialisation has been tried, but that wouldn't be
198 * enough, there are other ethernet boards which could
200 * Parallels has buf[0x0E] == 0x00 whereas real hardware
204 memset(buf, 0, sizeof(buf));
205 dp8390read(dp8390, buf, 0, sizeof(buf));
206 i = buf[0x0E] & 0xFF;
207 if((i != 0x00 && i != 0x57) || (buf[0x0F] & 0xFF) != 0x57){
214 * Stupid machine. Shorts were asked for,
215 * shorts were delivered, although the PROM is a byte array.
216 * Set the ethernet address.
218 memset(ea, 0, Eaddrlen);
219 if(memcmp(ea, edev->ea, Eaddrlen) == 0){
220 for(i = 0; i < sizeof(edev->ea); i++)
221 edev->ea[i] = buf[i];
231 addethercard("NE2000", ne2000reset);