2 #include "../port/lib.h"
7 #include "../port/error.h"
8 #include "../port/netif.h"
9 #include "../port/etherif.h"
11 #include "ether8390.h"
14 * Western Digital/Standard Microsystems Corporation cards (WD80[01]3).
15 * Also handles 8216 cards (Elite Ultra).
16 * Configuration code based on that provided by SMC a long time ago.
18 enum { /* 83C584 Bus Interface Controller */
19 Msr = 0x00, /* Memory Select Register */
20 Icr = 0x01, /* Interface Configuration Register */
21 Iar = 0x02, /* I/O Address Register */
22 Bio = 0x03, /* BIOS ROM Address Register */
23 Ear = 0x03, /* EEROM Address Register (shared with Bio) */
24 Irr = 0x04, /* Interrupt Request Register */
25 Hcr = 0x04, /* 8216 hardware control */
26 Laar = 0x05, /* LA Address Register */
27 Ijr = 0x06, /* Initialisation Jumpers */
28 Gp2 = 0x07, /* General Purpose Data Register */
29 Lar = 0x08, /* LAN Address Registers */
30 Id = 0x0E, /* Card ID byte */
31 Cksum = 0x0F, /* Checksum */
35 Rst = 0x80, /* software reset */
36 Menb = 0x40, /* memory enable */
40 Bit16 = 0x01, /* 16-bit bus */
41 Other = 0x02, /* other register access */
43 Msz = 0x08, /* SRAM size */
44 Rla = 0x10, /* recall LAN address */
45 Rx7 = 0x20, /* recall all but I/O and LAN address */
46 Rio = 0x40, /* recall I/O address from EEROM */
47 Sto = 0x80, /* non-volatile EEROM store */
51 ZeroWS16 = 0x20, /* zero wait states for 16-bit ops */
52 L16en = 0x40, /* enable 16-bit LAN operation */
53 M16en = 0x80, /* enable 16-bit memory access */
57 Ienable = 0x01, /* 8216 interrupt enable */
61 * Mapping from configuration bits to interrupt level.
63 static int irq8003[8] = {
64 9, 3, 5, 7, 10, 11, 15, 4,
67 static int irq8216[8] = {
68 0, 9, 3, 5, 7, 10, 11, 15,
72 reset8003(Ether* ether, uchar ea[Eaddrlen], uchar ic[8])
81 * Check for old, dumb 8003E, which doesn't have an interface
82 * chip. Only Msr exists out of the 1st eight registers, reads
83 * of the others just alias the 2nd eight registers, the LAN
84 * address ROM. Can check Icr, Irr and Laar against the ethernet
85 * address read above and if they match it's an 8003E (or an
86 * 8003EBT, 8003S, 8003SH or 8003WT, doesn't matter), in which
87 * case the default irq gets used.
89 if(memcmp(&ea[1], &ic[1], 5) == 0){
90 memset(ic, 0, sizeof(ic));
91 ic[Msr] = (ether->mem>>13) & 0x3F;
95 * As a final sanity check for the 8013EBT, which doesn't have
96 * the 83C584 interface chip, but has 2 real registers, write Gp2
97 * and if it reads back the same, it's not an 8013EBT.
100 inb(port+Msr); /* wiggle bus */
101 if(inb(port+Gp2) != 0xAA){
102 memset(ic, 0, sizeof(ic));
103 ic[Msr] = (ether->mem>>13) & 0x3F;
106 ether->irq = irq8003[((ic[Irr]>>5) & 0x3)|(ic[Icr] & 0x4)];
109 * Check if 16-bit card.
110 * If Bit16 is read/write, then it's an 8-bit card.
111 * If Bit16 is set, it's in a 16-bit slot.
113 outb(port+Icr, ic[Icr]^Bit16);
114 inb(port+Msr); /* wiggle bus */
115 if((inb(port+Icr) & Bit16) == (ic[Icr] & Bit16)){
119 outb(port+Icr, ic[Icr]);
121 if(ctlr->width == 2 && (inb(port+Icr) & Bit16) == 0)
125 ether->mem = (ic[Msr] & 0x3F)<<13;
127 ether->mem |= (ic[Laar] & 0x1F)<<19;
129 ether->mem |= 0x80000;
132 ether->size = 32*1024;
137 * Enable interface RAM, set interface width.
139 outb(port+Msr, ic[Msr]|Menb);
141 outb(port+Laar, ic[Laar]|L16en|M16en|ZeroWS16);
145 reset8216(Ether* ether, uchar[8])
157 * Switch to the alternate register set and retrieve the memory
158 * and irq information.
161 outb(port+Hcr, 0x80|hcr);
162 addr = inb(port+0x0B) & 0xFF;
163 irq = inb(port+0x0D);
166 ether->mem = 0xC0000+((((addr>>2) & 0x30)|(addr & 0x0F))<<13);
167 ether->size = 8192*(1<<((addr>>4) & 0x03));
168 ether->irq = irq8216[((irq>>4) & 0x04)|((irq>>2) & 0x03)];
171 * Enable interface RAM, set interface width, and enable interrupts.
173 x = inb(port+Msr) & ~Rst;
174 outb(port+Msr, Menb|x);
176 outb(port+Laar, M16en|x);
177 outb(port+Ijr, Ienable);
181 * Get configuration parameters, enable memory.
182 * There are opportunities here for buckets of code, try to resist.
188 uchar ea[Eaddrlen], ic[8], id, nullea[Eaddrlen], sum;
193 * Set up the software configuration.
194 * Use defaults for port, irq, mem and size if not specified.
195 * Defaults are set for the dumb 8003E which can't be
203 ether->mem = 0xD0000;
205 ether->size = 8*1024;
206 if(ioalloc(ether->port, 0x20, 0, "wd8003") < 0)
210 * Look for the interface. Read the LAN address ROM
211 * and validate the checksum - the sum of all 8 bytes
213 * At the same time, get the (possible) interface chip
214 * registers, they'll be used later to check for aliasing.
218 for(i = 0; i < sizeof(ea); i++){
219 ea[i] = inb(port+Lar+i);
225 sum += inb(port+Cksum);
231 ctlr = malloc(sizeof(Dp8390));
233 print("ether8003: can't allocate memory\n");
240 if((id & 0xFE) == 0x2A)
241 reset8216(ether, ic);
243 reset8003(ether, ea, ic);
246 * Set the DP8390 ring addresses.
248 ctlr->port = port+0x10;
250 ctlr->pstart = HOWMANY(sizeof(Etherpkt), Dp8390BufSz);
251 ctlr->pstop = HOWMANY(ether->size, Dp8390BufSz);
254 * Finally, init the 8390, set the ethernet address
255 * and claim the memory used.
258 memset(nullea, 0, Eaddrlen);
259 if(memcmp(nullea, ether->ea, Eaddrlen) == 0){
260 for(i = 0; i < sizeof(ether->ea); i++)
261 ether->ea[i] = ea[i];
265 if(umballoc(ether->mem, ether->size, 0) == -1)
266 print("ether8003: warning - 0x%luX unavailable\n", ether->mem);
274 addethercard("WD8003", reset);