1 /* e2100.c: A Cabletron E2100 series ethernet driver for linux. */ 2 /* 3 Written 1993-1994 by Donald Becker. 4
5 Copyright 1994 by Donald Becker. 6 Copyright 1993 United States Government as represented by the 7 Director, National Security Agency. This software may be used and 8 distributed according to the terms of the GNU Public License, 9 incorporated herein by reference. 10
11 This is a driver for the Cabletron E2100 series ethercards. 12
13 The Author may be reached as becker@cesdis.gsfc.nasa.gov, or 14 C/O Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771 15
16 The E2100 series ethercard is a fairly generic shared memory 8390 17 implementation. The only unusual aspect is the way the shared memory 18 registers are set: first you do an inb() in what is normally the 19 station address region, and the low three bits of next outb() *address* 20 is used as the write value for that register. Either someone wasn't 21 too used to dem bit en bites, or they were trying to obfuscate the 22 programming interface. 23
24 There is an additional complication when setting the window on the packet 25 buffer. You must first do a read into the packet buffer region with the 26 low 8 address bits the address setting the page for the start of the packet 27 buffer window, and then do the above operation. See mem_on() for details. 28
29 One bug on the chip is that even a hard reset won't disable the memory 30 window, usually resulting in a hung machine if mem_off() isn't called. 31 If this happens, you must power down the machine for about 30 seconds. 32 */ 33
34 staticchar *version =
35 "e2100.c:v1.01 7/21/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
36
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/errno.h>
40 #include <linux/string.h>
41 #include <asm/io.h>
42 #include <asm/system.h>
43 #include <linux/ioport.h>
44
45 #include <linux/netdevice.h>
46 #include "8390.h"
47
48 staticinte21_probe_list[] = {0x300, 0x280, 0x380, 0x220, 0};
49
50 /* Offsets from the base_addr. 51 Read from the ASIC register, and the low three bits of the next outb() 52 address is used to set the corresponding register. */ 53 #define E21_NIC_OFFSET 0 /* Offset to the 8390 NIC. */ 54 #defineE21_ASIC 0x10
55 #defineE21_MEM_ENABLE 0x10
56 #defineE21_MEM_ON 0x05 /* Enable memory in 16 bit mode. */ 57 #define E21_MEM_ON_8 0x07 /* Enable memory in 8 bit mode. */ 58 #defineE21_MEM_BASE 0x11
59 #defineE21_IRQ_LOW 0x12 /* The low three bits of the IRQ number. */ 60 #defineE21_IRQ_HIGH 0x14 /* The high IRQ bit and media select ... */ 61 #defineE21_MEDIA 0x14 /* (alias). */ 62 #defineE21_ALT_IFPORT 0x02 /* Set to use the other (BNC,AUI) port. */ 63 #define E21_BIG_MEM 0x04 /* Use a bigger (64K) buffer (we don't) */ 64 #defineE21_SAPROM 0x10 /* Offset to station address data. */ 65 #defineE21_IO_EXTENT 0x20
66
67 externinlinevoidmem_on(shortport, volatilechar *mem_base,
/* */ 68 unsignedcharstart_page )
69 { 70 /* This is a little weird: set the shared memory window by doing a 71 read. The low address bits specify the starting page. */ 72 mem_base[start_page];
73 inb(port + E21_MEM_ENABLE);
74 outb(E21_MEM_ON, port + E21_MEM_ENABLE + E21_MEM_ON);
75 } 76
77 externinlinevoidmem_off(shortport)
/* */ 78 { 79 inb(port + E21_MEM_ENABLE);
80 outb(0x00, port + E21_MEM_ENABLE);
81 } 82
83 /* In other drivers I put the TX pages first, but the E2100 window circuitry 84 is designed to have a 4K Tx region last. The windowing circuitry wraps the 85 window at 0x2fff->0x0000 so that the packets at e.g. 0x2f00 in the RX ring 86 appear contiguously in the window. */ 87 #defineE21_RX_START_PG 0x00 /* First page of RX buffer */ 88 #defineE21_RX_STOP_PG 0x30 /* Last page +1 of RX ring */ 89 #define E21_BIG_RX_STOP_PG 0xF0 /* Last page +1 of RX ring */ 90 #defineE21_TX_START_PGE21_RX_STOP_PG/* First page of TX buffer */ 91
92 inte2100_probe(structdevice *dev);
93 inte21_probe1(structdevice *dev, intioaddr);
94
95 staticinte21_open(structdevice *dev);
96 staticvoide21_reset_8390(structdevice *dev);
97 staticinte21_block_input(structdevice *dev, intcount,
98 char *buf, intring_offset);
99 staticvoide21_block_output(structdevice *dev, intcount,
100 constunsignedchar *buf, conststart_page);
101 staticinte21_close(structdevice *dev);
102
103
104 /* Probe for the E2100 series ethercards. These cards have an 8390 at the 105 base address and the station address at both offset 0x10 and 0x18. I read 106 the station address from offset 0x18 to avoid the dataport of NE2000 107 ethercards, and look for Ctron's unique ID (first three octets of the 108 station address). 109 */ 110
111 inte2100_probe(structdevice *dev)
/* */ 112 { 113 int *port;
114 intbase_addr = dev->base_addr;
115
116 if (base_addr > 0x1ff) /* Check a single specified location. */ 117 returne21_probe1(dev, base_addr);
118 elseif (base_addr != 0) /* Don't probe at all. */ 119 returnENXIO;
120
121 for (port = e21_probe_list; *port; port++) { 122 if (check_region(*port, E21_IO_EXTENT))
123 continue;
124 if (e21_probe1(dev, *port) == 0)
125 return 0;
126 } 127
128 returnENODEV;
129 } 130
131 inte21_probe1(structdevice *dev, intioaddr)
/* */ 132 { 133 inti, status;
134 unsignedchar *station_addr = dev->dev_addr;
135
136 /* First check the station address for the Ctron prefix. */ 137 if (inb(ioaddr + E21_SAPROM + 0) != 0x00
138 || inb(ioaddr + E21_SAPROM + 1) != 0x00
139 || inb(ioaddr + E21_SAPROM + 2) != 0x1d)
140 returnENODEV;
141
142 /* Verify by making certain that there is a 8390 at there. */ 143 outb(E8390_NODMA + E8390_STOP, ioaddr);
144 SLOW_DOWN_IO;
145 status = inb(ioaddr);
146 if (status != 0x21 && status != 0x23)
147 returnENODEV;
148
149 /* Grab the region so we can find a different board if IRQ select fails. */ 150 request_region(ioaddr, E21_IO_EXTENT,"e2100");
151
152 /* Read the station address PROM. */ 153 for (i = 0; i < 6; i++)
154 station_addr[i] = inb(ioaddr + E21_SAPROM + i);
155
156 inb(ioaddr + E21_MEDIA); /* Point to media selection. */ 157 outb(0, ioaddr + E21_ASIC); /* and disable the secondary interface. */ 158
159 printk("%s: E21** at %#3x,", dev->name, ioaddr);
160 for (i = 0; i < 6; i++)
161 printk(" %02X", station_addr[i]);
162
163 if (dev->irq < 2) { 164 intirqlist[] = {15,11,10,12,5,9,3,4}, i;
165 for (i = 0; i < 8; i++)
166 if (request_irq (irqlist[i], NULL, 0, "bogus") != -EBUSY) { 167 dev->irq = irqlist[i];
168 break;
169 } 170 if (i >= 8) { 171 printk(" unable to get IRQ %d.\n", dev->irq);
172 returnEAGAIN;
173 } 174 }elseif (dev->irq == 2) /* Fixup luser bogosity: IRQ2 is really IRQ9 */ 175 dev->irq = 9;
176
177 /* The 8390 is at the base address. */ 178 dev->base_addr = ioaddr;
179
180 ethdev_init(dev);
181
182 ei_status.name = "E2100";
183 ei_status.word16 = 1;
184 ei_status.tx_start_page = E21_TX_START_PG;
185 ei_status.rx_start_page = E21_RX_START_PG;
186 ei_status.stop_page = E21_RX_STOP_PG;
187 ei_status.saved_irq = dev->irq;
188
189 /* Check the media port used. The port can be passed in on the 190 low mem_end bits. */ 191 if (dev->mem_end & 15)
192 dev->if_port = dev->mem_end & 7;
193 else{ 194 dev->if_port = 0;
195 inb(ioaddr + E21_MEDIA); /* Turn automatic media detection on. */ 196 for(i = 0; i < 6; i++)
197 if (station_addr[i] != inb(ioaddr + E21_SAPROM + 8 + i)) { 198 dev->if_port = 1;
199 break;
200 } 201 } 202
203 /* Never map in the E21 shared memory unless you are actively using it. 204 Also, the shared memory has effective only one setting -- spread all 205 over the 128K region! */ 206 if (dev->mem_start == 0)
207 dev->mem_start = 0xd0000;
208
209 #ifdef notdef
210 /* These values are unused. The E2100 has a 2K window into the packet 211 buffer. The window can be set to start on any page boundary. */ 212 dev->rmem_start = dev->mem_start + TX_PAGES*256;
213 dev->mem_end = dev->rmem_end = dev->mem_start + 2*1024;
214 #endif 215
216 printk(", IRQ %d, %s media, memory @ %#lx.\n", dev->irq,
217 dev->if_port ? "secondary" : "primary", dev->mem_start);
218
219 if (ei_debug > 0)
220 printk(version);
221
222 ei_status.reset_8390 = &e21_reset_8390;
223 ei_status.block_input = &e21_block_input;
224 ei_status.block_output = &e21_block_output;
225 dev->open = &e21_open;
226 dev->stop = &e21_close;
227 NS8390_init(dev, 0);
228
229 return 0;
230 } 231
232 staticint 233 e21_open(structdevice *dev)
/* */ 234 { 235 shortioaddr = dev->base_addr;
236
237 if (request_irq(dev->irq, ei_interrupt, 0, "e2100")) { 238 returnEBUSY;
239 } 240 irq2dev_map[dev->irq] = dev;
241
242 /* Set the interrupt line and memory base on the hardware. */ 243 inb(ioaddr + E21_IRQ_LOW);
244 outb(0, ioaddr + E21_ASIC + (dev->irq & 7));
245 inb(ioaddr + E21_IRQ_HIGH); /* High IRQ bit, and if_port. */ 246 outb(0, ioaddr + E21_ASIC + (dev->irq > 7 ? 1:0)
247 + (dev->if_port ? E21_ALT_IFPORT : 0));
248 inb(ioaddr + E21_MEM_BASE);
249 outb(0, ioaddr + E21_ASIC + ((dev->mem_start >> 17) & 7));
250
251 returnei_open(dev);
252 } 253
254 staticvoid 255 e21_reset_8390(structdevice *dev)
/* */ 256 { 257 shortioaddr = dev->base_addr;
258
259 outb(0x01, ioaddr);
260 if (ei_debug > 1) printk("resetting the E2180x3 t=%ld...", jiffies);
261 ei_status.txing = 0;
262
263 /* Set up the ASIC registers, just in case something changed them. */ 264
265 if (ei_debug > 1) printk("reset done\n");
266 return;
267 } 268
269 /* Block input and output are easy on shared memory ethercards. 270 The E21xx makes block_input() especially easy by wrapping the top 271 ring buffer to the bottom automatically. */ 272 staticint 273 e21_block_input(structdevice *dev, intcount, char *buf, intring_offset)
/* */ 274 { 275 shortioaddr = dev->base_addr;
276 char *shared_mem = (char *)dev->mem_start;
277 intstart_page = (ring_offset>>8);
278
279 mem_on(ioaddr, shared_mem, start_page);
280
281 /* We'll always get a 4 byte header read first. */ 282 if (count == 4)
283 ((int*)buf)[0] = ((int*)shared_mem)[0];
284 else 285 memcpy(buf, shared_mem + (ring_offset & 0xff), count);
286
287 /* Turn off memory access: we would need to reprogram the window anyway. */ 288 mem_off(ioaddr);
289
290 return 0;
291 } 292
293 staticvoid 294 e21_block_output(structdevice *dev, intcount, constunsignedchar *buf,
/* */ 295 intstart_page)
296 { 297 shortioaddr = dev->base_addr;
298 volatilechar *shared_mem = (char *)dev->mem_start;
299
300 /* Set the shared memory window start by doing a read, with the low address 301 bits specifying the starting page. */ 302 *(shared_mem + start_page);
303 mem_on(ioaddr, shared_mem, start_page);
304
305 memcpy((char*)shared_mem, buf, count);
306 mem_off(ioaddr);
307 } 308
309 staticint 310 e21_close(structdevice *dev)
/* */ 311 { 312 shortioaddr = dev->base_addr;
313
314 if (ei_debug > 1)
315 printk("%s: Shutting down ethercard.\n", dev->name);
316
317 free_irq(dev->irq);
318 dev->irq = ei_status.saved_irq;
319
320 /* Shut off the interrupt line and secondary interface. */ 321 inb(ioaddr + E21_IRQ_LOW);
322 outb(0, ioaddr + E21_ASIC);
323 inb(ioaddr + E21_IRQ_HIGH); /* High IRQ bit, and if_port. */ 324 outb(0, ioaddr + E21_ASIC);
325
326 irq2dev_map[dev->irq] = NULL;
327
328 NS8390_init(dev, 0);
329
330 /* Double-check that the memory has been turned off, because really 331 really bad things happen if it isn't. */ 332 mem_off(ioaddr);
333
334 return 0;
335 } 336
337 #ifdefHAVE_DEVLIST 338 structnetdev_entry e21_drv =
339 {"e21", e21_probe1, E21_IO_EXTENT, e21_probe_list};
340 #endif 341
342
343 /* 344 * Local variables: 345 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c e2100.c" 346 * version-control: t 347 * tab-width: 4 348 * kept-new-versions: 5 349 * End: 350 */