blob: deefa51b8c31b652cdbbc1509dfcb6d006f0d915 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 es3210.c
3
4 Linux driver for Racal-Interlan ES3210 EISA Network Adapter
5
6 Copyright (C) 1996, Paul Gortmaker.
7
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
10
11 Information and Code Sources:
12
13 1) The existing myriad of Linux 8390 drivers written by Donald Becker.
14
15 2) Once again Russ Nelson's asm packet driver provided additional info.
16
17 3) Info for getting IRQ and sh-mem gleaned from the EISA cfg files.
18 Too bad it doesn't work -- see below.
19
20 The ES3210 is an EISA shared memory NS8390 implementation. Note
21 that all memory copies to/from the board must be 32bit transfers.
22 Which rules out using eth_io_copy_and_sum() in this driver.
23
24 Apparently there are two slightly different revisions of the
25 card, since there are two distinct EISA cfg files (!rii0101.cfg
26 and !rii0102.cfg) One has media select in the cfg file and the
27 other doesn't. Hopefully this will work with either.
28
29 That is about all I can tell you about it, having never actually
30 even seen one of these cards. :) Try http://www.interlan.com
31 if you want more info.
32
33 Thanks go to Mark Salazar for testing v0.02 of this driver.
34
35 Bugs, to-fix, etc:
36
37 1) The EISA cfg ports that are *supposed* to have the IRQ and shared
38 mem values just read 0xff all the time. Hrrmpf. Apparently the
39 same happens with the packet driver as the code for reading
40 these registers is disabled there. In the meantime, boot with:
41 ether=<IRQ>,0,0x<shared_mem_addr>,eth0 to override the IRQ and
42 shared memory detection. (The i/o port detection is okay.)
43
44 2) Module support currently untested. Probably works though.
45
46*/
47
48static const char version[] =
49 "es3210.c: Driver revision v0.03, 14/09/96\n";
50
51#include <linux/module.h>
52#include <linux/eisa.h>
53#include <linux/kernel.h>
54#include <linux/errno.h>
55#include <linux/string.h>
56#include <linux/init.h>
57#include <linux/netdevice.h>
58#include <linux/etherdevice.h>
59
60#include <asm/io.h>
61#include <asm/system.h>
62
63#include "8390.h"
64
65static int es_probe1(struct net_device *dev, int ioaddr);
66
67static int es_open(struct net_device *dev);
68static int es_close(struct net_device *dev);
69
70static void es_reset_8390(struct net_device *dev);
71
72static void es_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
73static void es_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
74static void es_block_output(struct net_device *dev, int count, const unsigned char *buf, int start_page);
75
76#define ES_START_PG 0x00 /* First page of TX buffer */
77#define ES_STOP_PG 0x40 /* Last page +1 of RX ring */
78
79#define ES_IO_EXTENT 0x37 /* The cfg file says 0xc90 -> 0xcc7 */
80#define ES_ID_PORT 0xc80 /* Same for all EISA cards */
81#define ES_SA_PROM 0xc90 /* Start of e'net addr. */
82#define ES_RESET_PORT 0xc84 /* From the packet driver source */
83#define ES_NIC_OFFSET 0xca0 /* Hello, the 8390 is *here* */
84
85#define ES_ADDR0 0x02 /* 3 byte vendor prefix */
86#define ES_ADDR1 0x07
87#define ES_ADDR2 0x01
88
89/*
90 * Two card revisions. EISA ID's are always rev. minor, rev. major,, and
91 * then the three vendor letters stored in 5 bits each, with an "a" = 1.
92 * For eg: "rii" = 10010 01001 01001 = 0x4929, which is how the EISA
93 * config utility determines automagically what config file(s) to use.
94 */
95#define ES_EISA_ID1 0x01012949 /* !rii0101.cfg */
96#define ES_EISA_ID2 0x02012949 /* !rii0102.cfg */
97
98#define ES_CFG1 0xcc0 /* IOPORT(1) --> IOPORT(6) in cfg file */
99#define ES_CFG2 0xcc1
100#define ES_CFG3 0xcc2
101#define ES_CFG4 0xcc3
102#define ES_CFG5 0xcc4
103#define ES_CFG6 0xc84 /* NB: 0xc84 is also "reset" port. */
104
105/*
106 * You can OR any of the following bits together and assign it
107 * to ES_DEBUG to get verbose driver info during operation.
108 * Some of these don't do anything yet.
109 */
110
111#define ES_D_PROBE 0x01
112#define ES_D_RX_PKT 0x02
113#define ES_D_TX_PKT 0x04
114#define ED_D_IRQ 0x08
115
116#define ES_DEBUG 0
117
118static unsigned char lo_irq_map[] __initdata = {3, 4, 5, 6, 7, 9, 10};
119static unsigned char hi_irq_map[] __initdata = {11, 12, 0, 14, 0, 0, 0, 15};
120
121/*
122 * Probe for the card. The best way is to read the EISA ID if it
123 * is known. Then we check the prefix of the station address
124 * PROM for a match against the Racal-Interlan assigned value.
125 */
126
127static int __init do_es_probe(struct net_device *dev)
128{
129 unsigned short ioaddr = dev->base_addr;
130 int irq = dev->irq;
131 int mem_start = dev->mem_start;
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 if (ioaddr > 0x1ff) /* Check a single specified location. */
134 return es_probe1(dev, ioaddr);
135 else if (ioaddr > 0) /* Don't probe at all. */
136 return -ENXIO;
137
138 if (!EISA_bus) {
139#if ES_DEBUG & ES_D_PROBE
140 printk("es3210.c: Not EISA bus. Not probing high ports.\n");
141#endif
142 return -ENXIO;
143 }
144
145 /* EISA spec allows for up to 16 slots, but 8 is typical. */
146 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
147 if (es_probe1(dev, ioaddr) == 0)
148 return 0;
149 dev->irq = irq;
150 dev->mem_start = mem_start;
151 }
152
153 return -ENODEV;
154}
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#ifndef MODULE
157struct net_device * __init es_probe(int unit)
158{
159 struct net_device *dev = alloc_ei_netdev();
160 int err;
161
162 if (!dev)
163 return ERR_PTR(-ENOMEM);
164
165 sprintf(dev->name, "eth%d", unit);
166 netdev_boot_setup_check(dev);
167
168 err = do_es_probe(dev);
169 if (err)
170 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172out:
173 free_netdev(dev);
174 return ERR_PTR(err);
175}
176#endif
177
178static int __init es_probe1(struct net_device *dev, int ioaddr)
179{
180 int i, retval;
181 unsigned long eisa_id;
Joe Perches0795af52007-10-03 17:59:30 -0700182 DECLARE_MAC_BUF(mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 if (!request_region(ioaddr + ES_SA_PROM, ES_IO_EXTENT, "es3210"))
185 return -ENODEV;
186
187#if ES_DEBUG & ES_D_PROBE
188 printk("es3210.c: probe at %#x, ID %#8x\n", ioaddr, inl(ioaddr + ES_ID_PORT));
189 printk("es3210.c: config regs: %#x %#x %#x %#x %#x %#x\n",
190 inb(ioaddr + ES_CFG1), inb(ioaddr + ES_CFG2), inb(ioaddr + ES_CFG3),
191 inb(ioaddr + ES_CFG4), inb(ioaddr + ES_CFG5), inb(ioaddr + ES_CFG6));
192#endif
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/* Check the EISA ID of the card. */
195 eisa_id = inl(ioaddr + ES_ID_PORT);
196 if ((eisa_id != ES_EISA_ID1) && (eisa_id != ES_EISA_ID2)) {
197 retval = -ENODEV;
198 goto out;
199 }
200
Joe Perches0795af52007-10-03 17:59:30 -0700201 for (i = 0; i < ETHER_ADDR_LEN ; i++)
202 dev->dev_addr[i] = inb(ioaddr + ES_SA_PROM + i);
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204/* Check the Racal vendor ID as well. */
Joe Perches0795af52007-10-03 17:59:30 -0700205 if (dev->dev_addr[0] != ES_ADDR0 ||
206 dev->dev_addr[1] != ES_ADDR1 ||
207 dev->dev_addr[2] != ES_ADDR2) {
208 printk("es3210.c: card not found %s (invalid_prefix).\n",
209 print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 retval = -ENODEV;
211 goto out;
212 }
213
Joe Perches0795af52007-10-03 17:59:30 -0700214 printk("es3210.c: ES3210 rev. %ld at %#x, node %s",
215 eisa_id>>24, ioaddr, print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 /* Snarf the interrupt now. */
218 if (dev->irq == 0) {
219 unsigned char hi_irq = inb(ioaddr + ES_CFG2) & 0x07;
220 unsigned char lo_irq = inb(ioaddr + ES_CFG1) & 0xfe;
221
222 if (hi_irq != 0) {
223 dev->irq = hi_irq_map[hi_irq - 1];
224 } else {
225 int i = 0;
226 while (lo_irq > (1<<i)) i++;
227 dev->irq = lo_irq_map[i];
228 }
229 printk(" using IRQ %d", dev->irq);
230#if ES_DEBUG & ES_D_PROBE
231 printk("es3210.c: hi_irq %#x, lo_irq %#x, dev->irq = %d\n",
232 hi_irq, lo_irq, dev->irq);
233#endif
234 } else {
235 if (dev->irq == 2)
236 dev->irq = 9; /* Doh! */
237 printk(" assigning IRQ %d", dev->irq);
238 }
239
240 if (request_irq(dev->irq, ei_interrupt, 0, "es3210", dev)) {
241 printk (" unable to get IRQ %d.\n", dev->irq);
242 retval = -EAGAIN;
243 goto out;
244 }
245
246 if (dev->mem_start == 0) {
247 unsigned char mem_enabled = inb(ioaddr + ES_CFG2) & 0xc0;
248 unsigned char mem_bits = inb(ioaddr + ES_CFG3) & 0x07;
249
250 if (mem_enabled != 0x80) {
251 printk(" shared mem disabled - giving up\n");
252 retval = -ENXIO;
253 goto out1;
254 }
255 dev->mem_start = 0xC0000 + mem_bits*0x4000;
256 printk(" using ");
257 } else {
258 printk(" assigning ");
259 }
260
261 ei_status.mem = ioremap(dev->mem_start, (ES_STOP_PG - ES_START_PG)*256);
262 if (!ei_status.mem) {
263 printk("ioremap failed - giving up\n");
264 retval = -ENXIO;
265 goto out1;
266 }
267
268 dev->mem_end = dev->mem_start + (ES_STOP_PG - ES_START_PG)*256;
269
270 printk("mem %#lx-%#lx\n", dev->mem_start, dev->mem_end-1);
271
272#if ES_DEBUG & ES_D_PROBE
273 if (inb(ioaddr + ES_CFG5))
274 printk("es3210: Warning - DMA channel enabled, but not used here.\n");
275#endif
276 /* Note, point at the 8390, and not the card... */
277 dev->base_addr = ioaddr + ES_NIC_OFFSET;
278
279 ei_status.name = "ES3210";
280 ei_status.tx_start_page = ES_START_PG;
281 ei_status.rx_start_page = ES_START_PG + TX_PAGES;
282 ei_status.stop_page = ES_STOP_PG;
283 ei_status.word16 = 1;
284
285 if (ei_debug > 0)
286 printk(version);
287
288 ei_status.reset_8390 = &es_reset_8390;
289 ei_status.block_input = &es_block_input;
290 ei_status.block_output = &es_block_output;
291 ei_status.get_8390_hdr = &es_get_8390_hdr;
292
293 dev->open = &es_open;
294 dev->stop = &es_close;
295#ifdef CONFIG_NET_POLL_CONTROLLER
296 dev->poll_controller = ei_poll;
297#endif
298 NS8390_init(dev, 0);
b1fc5502005-05-12 20:11:55 -0400299
300 retval = register_netdev(dev);
301 if (retval)
302 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 return 0;
304out1:
305 free_irq(dev->irq, dev);
306out:
307 release_region(ioaddr + ES_SA_PROM, ES_IO_EXTENT);
308 return retval;
309}
310
311/*
312 * Reset as per the packet driver method. Judging by the EISA cfg
313 * file, this just toggles the "Board Enable" bits (bit 2 and 0).
314 */
315
316static void es_reset_8390(struct net_device *dev)
317{
318 unsigned short ioaddr = dev->base_addr;
319 unsigned long end;
320
321 outb(0x04, ioaddr + ES_RESET_PORT);
322 if (ei_debug > 1) printk("%s: resetting the ES3210...", dev->name);
323
324 end = jiffies + 2*HZ/100;
325 while ((signed)(end - jiffies) > 0) continue;
326
327 ei_status.txing = 0;
328 outb(0x01, ioaddr + ES_RESET_PORT);
329 if (ei_debug > 1) printk("reset done\n");
330
331 return;
332}
333
334/*
335 * Note: In the following three functions is the implicit assumption
336 * that the associated memcpy will only use "rep; movsl" as long as
337 * we keep the counts as some multiple of doublewords. This is a
338 * requirement of the hardware, and also prevents us from using
339 * eth_io_copy_and_sum() since we can't guarantee it will limit
340 * itself to doubleword access.
341 */
342
343/*
344 * Grab the 8390 specific header. Similar to the block_input routine, but
345 * we don't need to be concerned with ring wrap as the header will be at
346 * the start of a page, so we optimize accordingly. (A single doubleword.)
347 */
348
349static void
350es_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
351{
352 void __iomem *hdr_start = ei_status.mem + ((ring_page - ES_START_PG)<<8);
353 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
354 hdr->count = (hdr->count + 3) & ~3; /* Round up allocation. */
355}
356
357/*
358 * Block input and output are easy on shared memory ethercards, the only
359 * complication is when the ring buffer wraps. The count will already
360 * be rounded up to a doubleword value via es_get_8390_hdr() above.
361 */
362
363static void es_block_input(struct net_device *dev, int count, struct sk_buff *skb,
364 int ring_offset)
365{
366 void __iomem *xfer_start = ei_status.mem + ring_offset - ES_START_PG*256;
367
368 if (ring_offset + count > ES_STOP_PG*256) {
369 /* Packet wraps over end of ring buffer. */
370 int semi_count = ES_STOP_PG*256 - ring_offset;
371 memcpy_fromio(skb->data, xfer_start, semi_count);
372 count -= semi_count;
373 memcpy_fromio(skb->data + semi_count, ei_status.mem, count);
374 } else {
375 /* Packet is in one chunk. */
Al Viro4ec03112007-02-09 16:38:30 +0000376 memcpy_fromio(skb->data, xfer_start, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378}
379
380static void es_block_output(struct net_device *dev, int count,
381 const unsigned char *buf, int start_page)
382{
383 void __iomem *shmem = ei_status.mem + ((start_page - ES_START_PG)<<8);
384
385 count = (count + 3) & ~3; /* Round up to doubleword */
386 memcpy_toio(shmem, buf, count);
387}
388
389static int es_open(struct net_device *dev)
390{
391 ei_open(dev);
392 return 0;
393}
394
395static int es_close(struct net_device *dev)
396{
397
398 if (ei_debug > 1)
399 printk("%s: Shutting down ethercard.\n", dev->name);
400
401 ei_close(dev);
402 return 0;
403}
404
405#ifdef MODULE
406#define MAX_ES_CARDS 4 /* Max number of ES3210 cards per module */
407#define NAMELEN 8 /* # of chars for storing dev->name */
408static struct net_device *dev_es3210[MAX_ES_CARDS];
409static int io[MAX_ES_CARDS];
410static int irq[MAX_ES_CARDS];
411static int mem[MAX_ES_CARDS];
412
413module_param_array(io, int, NULL, 0);
414module_param_array(irq, int, NULL, 0);
415module_param_array(mem, int, NULL, 0);
416MODULE_PARM_DESC(io, "I/O base address(es)");
417MODULE_PARM_DESC(irq, "IRQ number(s)");
418MODULE_PARM_DESC(mem, "memory base address(es)");
419MODULE_DESCRIPTION("Racal-Interlan ES3210 EISA ethernet driver");
420MODULE_LICENSE("GPL");
421
Andrew Morton5757f5c2006-08-14 23:00:02 -0700422int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
424 struct net_device *dev;
425 int this_dev, found = 0;
426
427 for (this_dev = 0; this_dev < MAX_ES_CARDS; this_dev++) {
428 if (io[this_dev] == 0 && this_dev != 0)
429 break;
430 dev = alloc_ei_netdev();
431 if (!dev)
432 break;
433 dev->irq = irq[this_dev];
434 dev->base_addr = io[this_dev];
435 dev->mem_start = mem[this_dev];
436 if (do_es_probe(dev) == 0) {
b1fc5502005-05-12 20:11:55 -0400437 dev_es3210[found++] = dev;
438 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
440 free_netdev(dev);
441 printk(KERN_WARNING "es3210.c: No es3210 card found (i/o = 0x%x).\n", io[this_dev]);
442 break;
443 }
444 if (found)
445 return 0;
446 return -ENXIO;
447}
448
Denis Vlasenko64916f12006-01-05 22:45:47 -0800449static void cleanup_card(struct net_device *dev)
450{
451 free_irq(dev->irq, dev);
452 release_region(dev->base_addr, ES_IO_EXTENT);
453 iounmap(ei_status.mem);
454}
455
Al Viroafc8eb42006-06-14 18:50:53 -0400456void __exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457cleanup_module(void)
458{
459 int this_dev;
460
461 for (this_dev = 0; this_dev < MAX_ES_CARDS; this_dev++) {
462 struct net_device *dev = dev_es3210[this_dev];
463 if (dev) {
464 unregister_netdev(dev);
465 cleanup_card(dev);
466 free_netdev(dev);
467 }
468 }
469}
470#endif /* MODULE */
471