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 "etherif.h" 9 #include "ether8390.h" 10 11 /* 12 * Driver written for the 'Notebook Computer Ethernet LAN Adapter', 13 * a plug-in to the bus-slot on the rear of the Gateway NOMAD 425DXL 14 * laptop. The manual says NE2000 compatible. 15 * The interface appears to be pretty well described in the National 16 * Semiconductor Local Area Network Databook (1992) as one of the 17 * AT evaluation cards. 18 * 19 * The NE2000 is really just a DP8390[12] plus a data port 20 * and a reset port. 21 */ 22 enum { 23 Data = 0x10, /* offset from I/O base of data port */ 24 Reset = 0x1F, /* offset from I/O base of reset port */ 25 }; 26 27 int 28 ne2000reset(Ether* ether) 29 { 30 ushort buf[16]; 31 ulong port; 32 Dp8390 *ctlr; 33 int i; 34 uchar ea[Eaddrlen]; 35 36 /* 37 * Set up the software configuration. 38 * Use defaults for port, irq, mem and size 39 * if not specified. 40 */ 41 if(ether->port == 0) 42 ether->port = 0x300; 43 if(ether->irq == 0) 44 ether->irq = 2; 45 if(ether->mem == 0) 46 ether->mem = 0x4000; 47 if(ether->size == 0) 48 ether->size = 16*1024; 49 port = ether->port; 50 51 ether->ctlr = malloc(sizeof(Dp8390)); 52 ctlr = ether->ctlr; 53 ctlr->width = 2; 54 ctlr->ram = 0; 55 56 ctlr->port = port; 57 ctlr->data = port+Data; 58 59 ctlr->tstart = HOWMANY(ether->mem, Dp8390BufSz); 60 ctlr->pstart = ctlr->tstart + HOWMANY(sizeof(Etherpkt), Dp8390BufSz); 61 ctlr->pstop = ctlr->tstart + HOWMANY(ether->size, Dp8390BufSz); 62 63 ctlr->dummyrr = 1; 64 for(i = 0; i < ether->nopt; i++){ 65 if(strcmp(ether->opt[i], "nodummyrr")) 66 continue; 67 ctlr->dummyrr = 0; 68 break; 69 } 70 71 /* 72 * Reset the board. This is done by doing a read 73 * followed by a write to the Reset address. 74 */ 75 buf[0] = inb(port+Reset); 76 delay(2); 77 outb(port+Reset, buf[0]); 78 delay(2); 79 80 /* 81 * Init the (possible) chip, then use the (possible) 82 * chip to read the (possible) PROM for ethernet address 83 * and a marker byte. 84 * Could just look at the DP8390 command register after 85 * initialisation has been tried, but that wouldn't be 86 * enough, there are other ethernet boards which could 87 * match. 88 */ 89 dp8390reset(ether); 90 memset(buf, 0, sizeof(buf)); 91 dp8390read(ctlr, buf, 0, sizeof(buf)); 92 if((buf[0x0E] & 0xFF) != 0x57 || (buf[0x0F] & 0xFF) != 0x57){ 93 free(ether->ctlr); 94 return -1; 95 } 96 97 /* 98 * Stupid machine. Shorts were asked for, 99 * shorts were delivered, although the PROM is a byte array. 100 * Set the ethernet address. 101 */ 102 memset(ea, 0, Eaddrlen); 103 if(memcmp(ea, ether->ea, Eaddrlen) == 0){ 104 for(i = 0; i < sizeof(ether->ea); i++) 105 ether->ea[i] = buf[i]; 106 } 107 dp8390setea(ether); 108 109 return 0; 110 } 111