Loading...
1/*
2 * Linux ARCnet driver - COM90xx chipset (memory-mapped buffers)
3 *
4 * Written 1994-1999 by Avery Pennarun.
5 * Written 1999 by Martin Mares <mj@ucw.cz>.
6 * Derived from skeleton.c by Donald Becker.
7 *
8 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
9 * for sponsoring the further development of this driver.
10 *
11 * **********************
12 *
13 * The original copyright of skeleton.c was as follows:
14 *
15 * skeleton.c Written 1993 by Donald Becker.
16 * Copyright 1993 United States Government as represented by the
17 * Director, National Security Agency. This software may only be used
18 * and distributed according to the terms of the GNU General Public License as
19 * modified by SRC, incorporated herein by reference.
20 *
21 * **********************
22 *
23 * For more details, see drivers/net/arcnet.c
24 *
25 * **********************
26 */
27
28#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
29
30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/init.h>
33#include <linux/interrupt.h>
34#include <linux/ioport.h>
35#include <linux/delay.h>
36#include <linux/netdevice.h>
37#include <linux/slab.h>
38#include <linux/io.h>
39
40#include "arcdevice.h"
41#include "com9026.h"
42
43/* Define this to speed up the autoprobe by assuming if only one io port and
44 * shmem are left in the list at Stage 5, they must correspond to each
45 * other.
46 *
47 * This is undefined by default because it might not always be true, and the
48 * extra check makes the autoprobe even more careful. Speed demons can turn
49 * it on - I think it should be fine if you only have one ARCnet card
50 * installed.
51 *
52 * If no ARCnet cards are installed, this delay never happens anyway and thus
53 * the option has no effect.
54 */
55#undef FAST_PROBE
56
57/* Internal function declarations */
58static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *);
59static void com90xx_command(struct net_device *dev, int command);
60static int com90xx_status(struct net_device *dev);
61static void com90xx_setmask(struct net_device *dev, int mask);
62static int com90xx_reset(struct net_device *dev, int really_reset);
63static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
64 void *buf, int count);
65static void com90xx_copy_from_card(struct net_device *dev, int bufnum,
66 int offset, void *buf, int count);
67
68/* Known ARCnet cards */
69
70static struct net_device *cards[16];
71static int numcards;
72
73/* Handy defines for ARCnet specific stuff */
74
75/* The number of low I/O ports used by the card */
76#define ARCNET_TOTAL_SIZE 16
77
78/* Amount of I/O memory used by the card */
79#define BUFFER_SIZE (512)
80#define MIRROR_SIZE (BUFFER_SIZE * 4)
81
82static int com90xx_skip_probe __initdata = 0;
83
84/* Module parameters */
85
86static int io; /* use the insmod io= irq= shmem= options */
87static int irq;
88static int shmem;
89static char device[9]; /* use eg. device=arc1 to change name */
90
91module_param_hw(io, int, ioport, 0);
92module_param_hw(irq, int, irq, 0);
93module_param(shmem, int, 0);
94module_param_string(device, device, sizeof(device), 0);
95
96static void __init com90xx_probe(void)
97{
98 int count, status, ioaddr, numprint, airq, openparen = 0;
99 unsigned long airqmask;
100 int ports[(0x3f0 - 0x200) / 16 + 1] = { 0 };
101 unsigned long *shmems;
102 void __iomem **iomem;
103 int numports, numshmems, *port;
104 u_long *p;
105 int index;
106
107 if (!io && !irq && !shmem && !*device && com90xx_skip_probe)
108 return;
109
110 shmems = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(unsigned long),
111 GFP_KERNEL);
112 if (!shmems)
113 return;
114 iomem = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(void __iomem *),
115 GFP_KERNEL);
116 if (!iomem) {
117 kfree(shmems);
118 return;
119 }
120
121 if (BUGLVL(D_NORMAL))
122 pr_info("%s\n", "COM90xx chipset support");
123
124 /* set up the arrays where we'll store the possible probe addresses */
125 numports = numshmems = 0;
126 if (io)
127 ports[numports++] = io;
128 else
129 for (count = 0x200; count <= 0x3f0; count += 16)
130 ports[numports++] = count;
131 if (shmem)
132 shmems[numshmems++] = shmem;
133 else
134 for (count = 0xA0000; count <= 0xFF800; count += 2048)
135 shmems[numshmems++] = count;
136
137 /* Stage 1: abandon any reserved ports, or ones with status==0xFF
138 * (empty), and reset any others by reading the reset port.
139 */
140 numprint = -1;
141 for (port = &ports[0]; port - ports < numports; port++) {
142 numprint++;
143 numprint %= 8;
144 if (!numprint) {
145 arc_cont(D_INIT, "\n");
146 arc_cont(D_INIT, "S1: ");
147 }
148 arc_cont(D_INIT, "%Xh ", *port);
149
150 ioaddr = *port;
151
152 if (!request_region(*port, ARCNET_TOTAL_SIZE,
153 "arcnet (90xx)")) {
154 arc_cont(D_INIT_REASONS, "(request_region)\n");
155 arc_cont(D_INIT_REASONS, "S1: ");
156 if (BUGLVL(D_INIT_REASONS))
157 numprint = 0;
158 *port-- = ports[--numports];
159 continue;
160 }
161 if (arcnet_inb(ioaddr, COM9026_REG_R_STATUS) == 0xFF) {
162 arc_cont(D_INIT_REASONS, "(empty)\n");
163 arc_cont(D_INIT_REASONS, "S1: ");
164 if (BUGLVL(D_INIT_REASONS))
165 numprint = 0;
166 release_region(*port, ARCNET_TOTAL_SIZE);
167 *port-- = ports[--numports];
168 continue;
169 }
170 /* begin resetting card */
171 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
172
173 arc_cont(D_INIT_REASONS, "\n");
174 arc_cont(D_INIT_REASONS, "S1: ");
175 if (BUGLVL(D_INIT_REASONS))
176 numprint = 0;
177 }
178 arc_cont(D_INIT, "\n");
179
180 if (!numports) {
181 arc_cont(D_NORMAL, "S1: No ARCnet cards found.\n");
182 kfree(shmems);
183 kfree(iomem);
184 return;
185 }
186 /* Stage 2: we have now reset any possible ARCnet cards, so we can't
187 * do anything until they finish. If D_INIT, print the list of
188 * cards that are left.
189 */
190 numprint = -1;
191 for (port = &ports[0]; port < ports + numports; port++) {
192 numprint++;
193 numprint %= 8;
194 if (!numprint) {
195 arc_cont(D_INIT, "\n");
196 arc_cont(D_INIT, "S2: ");
197 }
198 arc_cont(D_INIT, "%Xh ", *port);
199 }
200 arc_cont(D_INIT, "\n");
201 mdelay(RESETtime);
202
203 /* Stage 3: abandon any shmem addresses that don't have the signature
204 * 0xD1 byte in the right place, or are read-only.
205 */
206 numprint = -1;
207 for (index = 0, p = &shmems[0]; index < numshmems; p++, index++) {
208 void __iomem *base;
209
210 numprint++;
211 numprint %= 8;
212 if (!numprint) {
213 arc_cont(D_INIT, "\n");
214 arc_cont(D_INIT, "S3: ");
215 }
216 arc_cont(D_INIT, "%lXh ", *p);
217
218 if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) {
219 arc_cont(D_INIT_REASONS, "(request_mem_region)\n");
220 arc_cont(D_INIT_REASONS, "Stage 3: ");
221 if (BUGLVL(D_INIT_REASONS))
222 numprint = 0;
223 goto out;
224 }
225 base = ioremap(*p, MIRROR_SIZE);
226 if (!base) {
227 arc_cont(D_INIT_REASONS, "(ioremap)\n");
228 arc_cont(D_INIT_REASONS, "Stage 3: ");
229 if (BUGLVL(D_INIT_REASONS))
230 numprint = 0;
231 goto out1;
232 }
233 if (arcnet_readb(base, COM9026_REG_R_STATUS) != TESTvalue) {
234 arc_cont(D_INIT_REASONS, "(%02Xh != %02Xh)\n",
235 arcnet_readb(base, COM9026_REG_R_STATUS),
236 TESTvalue);
237 arc_cont(D_INIT_REASONS, "S3: ");
238 if (BUGLVL(D_INIT_REASONS))
239 numprint = 0;
240 goto out2;
241 }
242 /* By writing 0x42 to the TESTvalue location, we also make
243 * sure no "mirror" shmem areas show up - if they occur
244 * in another pass through this loop, they will be discarded
245 * because *cptr != TESTvalue.
246 */
247 arcnet_writeb(0x42, base, COM9026_REG_W_INTMASK);
248 if (arcnet_readb(base, COM9026_REG_R_STATUS) != 0x42) {
249 arc_cont(D_INIT_REASONS, "(read only)\n");
250 arc_cont(D_INIT_REASONS, "S3: ");
251 goto out2;
252 }
253 arc_cont(D_INIT_REASONS, "\n");
254 arc_cont(D_INIT_REASONS, "S3: ");
255 if (BUGLVL(D_INIT_REASONS))
256 numprint = 0;
257 iomem[index] = base;
258 continue;
259 out2:
260 iounmap(base);
261 out1:
262 release_mem_region(*p, MIRROR_SIZE);
263 out:
264 *p-- = shmems[--numshmems];
265 index--;
266 }
267 arc_cont(D_INIT, "\n");
268
269 if (!numshmems) {
270 arc_cont(D_NORMAL, "S3: No ARCnet cards found.\n");
271 for (port = &ports[0]; port < ports + numports; port++)
272 release_region(*port, ARCNET_TOTAL_SIZE);
273 kfree(shmems);
274 kfree(iomem);
275 return;
276 }
277 /* Stage 4: something of a dummy, to report the shmems that are
278 * still possible after stage 3.
279 */
280 numprint = -1;
281 for (p = &shmems[0]; p < shmems + numshmems; p++) {
282 numprint++;
283 numprint %= 8;
284 if (!numprint) {
285 arc_cont(D_INIT, "\n");
286 arc_cont(D_INIT, "S4: ");
287 }
288 arc_cont(D_INIT, "%lXh ", *p);
289 }
290 arc_cont(D_INIT, "\n");
291
292 /* Stage 5: for any ports that have the correct status, can disable
293 * the RESET flag, and (if no irq is given) generate an autoirq,
294 * register an ARCnet device.
295 *
296 * Currently, we can only register one device per probe, so quit
297 * after the first one is found.
298 */
299 numprint = -1;
300 for (port = &ports[0]; port < ports + numports; port++) {
301 int found = 0;
302
303 numprint++;
304 numprint %= 8;
305 if (!numprint) {
306 arc_cont(D_INIT, "\n");
307 arc_cont(D_INIT, "S5: ");
308 }
309 arc_cont(D_INIT, "%Xh ", *port);
310
311 ioaddr = *port;
312 status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
313
314 if ((status & 0x9D)
315 != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
316 arc_cont(D_INIT_REASONS, "(status=%Xh)\n", status);
317 arc_cont(D_INIT_REASONS, "S5: ");
318 if (BUGLVL(D_INIT_REASONS))
319 numprint = 0;
320 release_region(*port, ARCNET_TOTAL_SIZE);
321 *port-- = ports[--numports];
322 continue;
323 }
324 arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
325 ioaddr, COM9026_REG_W_COMMAND);
326 status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
327 if (status & RESETflag) {
328 arc_cont(D_INIT_REASONS, " (eternal reset, status=%Xh)\n",
329 status);
330 arc_cont(D_INIT_REASONS, "S5: ");
331 if (BUGLVL(D_INIT_REASONS))
332 numprint = 0;
333 release_region(*port, ARCNET_TOTAL_SIZE);
334 *port-- = ports[--numports];
335 continue;
336 }
337 /* skip this completely if an IRQ was given, because maybe
338 * we're on a machine that locks during autoirq!
339 */
340 if (!irq) {
341 /* if we do this, we're sure to get an IRQ since the
342 * card has just reset and the NORXflag is on until
343 * we tell it to start receiving.
344 */
345 airqmask = probe_irq_on();
346 arcnet_outb(NORXflag, ioaddr, COM9026_REG_W_INTMASK);
347 udelay(1);
348 arcnet_outb(0, ioaddr, COM9026_REG_W_INTMASK);
349 airq = probe_irq_off(airqmask);
350
351 if (airq <= 0) {
352 arc_cont(D_INIT_REASONS, "(airq=%d)\n", airq);
353 arc_cont(D_INIT_REASONS, "S5: ");
354 if (BUGLVL(D_INIT_REASONS))
355 numprint = 0;
356 release_region(*port, ARCNET_TOTAL_SIZE);
357 *port-- = ports[--numports];
358 continue;
359 }
360 } else {
361 airq = irq;
362 }
363
364 arc_cont(D_INIT, "(%d,", airq);
365 openparen = 1;
366
367 /* Everything seems okay. But which shmem, if any, puts
368 * back its signature byte when the card is reset?
369 *
370 * If there are multiple cards installed, there might be
371 * multiple shmems still in the list.
372 */
373#ifdef FAST_PROBE
374 if (numports > 1 || numshmems > 1) {
375 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
376 mdelay(RESETtime);
377 } else {
378 /* just one shmem and port, assume they match */
379 arcnet_writeb(TESTvalue, iomem[0],
380 COM9026_REG_W_INTMASK);
381 }
382#else
383 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
384 mdelay(RESETtime);
385#endif
386
387 for (index = 0; index < numshmems; index++) {
388 u_long ptr = shmems[index];
389 void __iomem *base = iomem[index];
390
391 if (arcnet_readb(base, COM9026_REG_R_STATUS) == TESTvalue) { /* found one */
392 arc_cont(D_INIT, "%lXh)\n", *p);
393 openparen = 0;
394
395 /* register the card */
396 if (com90xx_found(*port, airq, ptr, base) == 0)
397 found = 1;
398 numprint = -1;
399
400 /* remove shmem from the list */
401 shmems[index] = shmems[--numshmems];
402 iomem[index] = iomem[numshmems];
403 break; /* go to the next I/O port */
404 } else {
405 arc_cont(D_INIT_REASONS, "%Xh-",
406 arcnet_readb(base, COM9026_REG_R_STATUS));
407 }
408 }
409
410 if (openparen) {
411 if (BUGLVL(D_INIT))
412 pr_cont("no matching shmem)\n");
413 if (BUGLVL(D_INIT_REASONS)) {
414 pr_cont("S5: ");
415 numprint = 0;
416 }
417 }
418 if (!found)
419 release_region(*port, ARCNET_TOTAL_SIZE);
420 *port-- = ports[--numports];
421 }
422
423 if (BUGLVL(D_INIT_REASONS))
424 pr_cont("\n");
425
426 /* Now put back TESTvalue on all leftover shmems. */
427 for (index = 0; index < numshmems; index++) {
428 arcnet_writeb(TESTvalue, iomem[index], COM9026_REG_W_INTMASK);
429 iounmap(iomem[index]);
430 release_mem_region(shmems[index], MIRROR_SIZE);
431 }
432 kfree(shmems);
433 kfree(iomem);
434}
435
436static int __init check_mirror(unsigned long addr, size_t size)
437{
438 void __iomem *p;
439 int res = -1;
440
441 if (!request_mem_region(addr, size, "arcnet (90xx)"))
442 return -1;
443
444 p = ioremap(addr, size);
445 if (p) {
446 if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue)
447 res = 1;
448 else
449 res = 0;
450 iounmap(p);
451 }
452
453 release_mem_region(addr, size);
454 return res;
455}
456
457/* Set up the struct net_device associated with this card. Called after
458 * probing succeeds.
459 */
460static int __init com90xx_found(int ioaddr, int airq, u_long shmem,
461 void __iomem *p)
462{
463 struct net_device *dev = NULL;
464 struct arcnet_local *lp;
465 u_long first_mirror, last_mirror;
466 int mirror_size;
467
468 /* allocate struct net_device */
469 dev = alloc_arcdev(device);
470 if (!dev) {
471 arc_cont(D_NORMAL, "com90xx: Can't allocate device!\n");
472 iounmap(p);
473 release_mem_region(shmem, MIRROR_SIZE);
474 return -ENOMEM;
475 }
476 lp = netdev_priv(dev);
477 /* find the real shared memory start/end points, including mirrors */
478
479 /* guess the actual size of one "memory mirror" - the number of
480 * bytes between copies of the shared memory. On most cards, it's
481 * 2k (or there are no mirrors at all) but on some, it's 4k.
482 */
483 mirror_size = MIRROR_SIZE;
484 if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue &&
485 check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
486 check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
487 mirror_size = 2 * MIRROR_SIZE;
488
489 first_mirror = shmem - mirror_size;
490 while (check_mirror(first_mirror, mirror_size) == 1)
491 first_mirror -= mirror_size;
492 first_mirror += mirror_size;
493
494 last_mirror = shmem + mirror_size;
495 while (check_mirror(last_mirror, mirror_size) == 1)
496 last_mirror += mirror_size;
497 last_mirror -= mirror_size;
498
499 dev->mem_start = first_mirror;
500 dev->mem_end = last_mirror + MIRROR_SIZE - 1;
501
502 iounmap(p);
503 release_mem_region(shmem, MIRROR_SIZE);
504
505 if (!request_mem_region(dev->mem_start,
506 dev->mem_end - dev->mem_start + 1,
507 "arcnet (90xx)"))
508 goto err_free_dev;
509
510 /* reserve the irq */
511 if (request_irq(airq, arcnet_interrupt, 0, "arcnet (90xx)", dev)) {
512 arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", airq);
513 goto err_release_mem;
514 }
515 dev->irq = airq;
516
517 /* Initialize the rest of the device structure. */
518 lp->card_name = "COM90xx";
519 lp->hw.command = com90xx_command;
520 lp->hw.status = com90xx_status;
521 lp->hw.intmask = com90xx_setmask;
522 lp->hw.reset = com90xx_reset;
523 lp->hw.owner = THIS_MODULE;
524 lp->hw.copy_to_card = com90xx_copy_to_card;
525 lp->hw.copy_from_card = com90xx_copy_from_card;
526 lp->mem_start = ioremap(dev->mem_start,
527 dev->mem_end - dev->mem_start + 1);
528 if (!lp->mem_start) {
529 arc_printk(D_NORMAL, dev, "Can't remap device memory!\n");
530 goto err_free_irq;
531 }
532
533 /* get and check the station ID from offset 1 in shmem */
534 arcnet_set_addr(dev, arcnet_readb(lp->mem_start,
535 COM9026_REG_R_STATION));
536
537 dev->base_addr = ioaddr;
538
539 arc_printk(D_NORMAL, dev, "COM90xx station %02Xh found at %03lXh, IRQ %d, ShMem %lXh (%ld*%xh).\n",
540 dev->dev_addr[0],
541 dev->base_addr, dev->irq, dev->mem_start,
542 (dev->mem_end - dev->mem_start + 1) / mirror_size,
543 mirror_size);
544
545 if (register_netdev(dev))
546 goto err_unmap;
547
548 cards[numcards++] = dev;
549 return 0;
550
551err_unmap:
552 iounmap(lp->mem_start);
553err_free_irq:
554 free_irq(dev->irq, dev);
555err_release_mem:
556 release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
557err_free_dev:
558 free_arcdev(dev);
559 return -EIO;
560}
561
562static void com90xx_command(struct net_device *dev, int cmd)
563{
564 short ioaddr = dev->base_addr;
565
566 arcnet_outb(cmd, ioaddr, COM9026_REG_W_COMMAND);
567}
568
569static int com90xx_status(struct net_device *dev)
570{
571 short ioaddr = dev->base_addr;
572
573 return arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
574}
575
576static void com90xx_setmask(struct net_device *dev, int mask)
577{
578 short ioaddr = dev->base_addr;
579
580 arcnet_outb(mask, ioaddr, COM9026_REG_W_INTMASK);
581}
582
583/* Do a hardware reset on the card, and set up necessary registers.
584 *
585 * This should be called as little as possible, because it disrupts the
586 * token on the network (causes a RECON) and requires a significant delay.
587 *
588 * However, it does make sure the card is in a defined state.
589 */
590static int com90xx_reset(struct net_device *dev, int really_reset)
591{
592 struct arcnet_local *lp = netdev_priv(dev);
593 short ioaddr = dev->base_addr;
594
595 arc_printk(D_INIT, dev, "Resetting (status=%02Xh)\n",
596 arcnet_inb(ioaddr, COM9026_REG_R_STATUS));
597
598 if (really_reset) {
599 /* reset the card */
600 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
601 mdelay(RESETtime);
602 }
603 /* clear flags & end reset */
604 arcnet_outb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND);
605 arcnet_outb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND);
606
607#if 0
608 /* don't do this until we verify that it doesn't hurt older cards! */
609 arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) | ENABLE16flag,
610 ioaddr, COM9026_REG_RW_CONFIG);
611#endif
612
613 /* verify that the ARCnet signature byte is present */
614 if (arcnet_readb(lp->mem_start, COM9026_REG_R_STATUS) != TESTvalue) {
615 if (really_reset)
616 arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
617 return 1;
618 }
619 /* enable extended (512-byte) packets */
620 arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
621
622 /* clean out all the memory to make debugging make more sense :) */
623 if (BUGLVL(D_DURING))
624 memset_io(lp->mem_start, 0x42, 2048);
625
626 /* done! return success. */
627 return 0;
628}
629
630static void com90xx_copy_to_card(struct net_device *dev, int bufnum,
631 int offset, void *buf, int count)
632{
633 struct arcnet_local *lp = netdev_priv(dev);
634 void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
635
636 TIME(dev, "memcpy_toio", count, memcpy_toio(memaddr, buf, count));
637}
638
639static void com90xx_copy_from_card(struct net_device *dev, int bufnum,
640 int offset, void *buf, int count)
641{
642 struct arcnet_local *lp = netdev_priv(dev);
643 void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
644
645 TIME(dev, "memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
646}
647
648MODULE_DESCRIPTION("ARCnet COM90xx normal chipset driver");
649MODULE_LICENSE("GPL");
650
651static int __init com90xx_init(void)
652{
653 if (irq == 2)
654 irq = 9;
655 com90xx_probe();
656 if (!numcards)
657 return -EIO;
658 return 0;
659}
660
661static void __exit com90xx_exit(void)
662{
663 struct net_device *dev;
664 struct arcnet_local *lp;
665 int count;
666
667 for (count = 0; count < numcards; count++) {
668 dev = cards[count];
669 lp = netdev_priv(dev);
670
671 unregister_netdev(dev);
672 free_irq(dev->irq, dev);
673 iounmap(lp->mem_start);
674 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
675 release_mem_region(dev->mem_start,
676 dev->mem_end - dev->mem_start + 1);
677 free_arcdev(dev);
678 }
679}
680
681module_init(com90xx_init);
682module_exit(com90xx_exit);
683
684#ifndef MODULE
685static int __init com90xx_setup(char *s)
686{
687 int ints[8];
688
689 s = get_options(s, 8, ints);
690 if (!ints[0] && !*s) {
691 pr_notice("Disabled\n");
692 return 1;
693 }
694
695 switch (ints[0]) {
696 default: /* ERROR */
697 pr_err("Too many arguments\n");
698 fallthrough;
699 case 3: /* Mem address */
700 shmem = ints[3];
701 fallthrough;
702 case 2: /* IRQ */
703 irq = ints[2];
704 fallthrough;
705 case 1: /* IO address */
706 io = ints[1];
707 }
708
709 if (*s)
710 snprintf(device, sizeof(device), "%s", s);
711
712 return 1;
713}
714
715__setup("com90xx=", com90xx_setup);
716#endif
1/*
2 * Linux ARCnet driver - COM90xx chipset (memory-mapped buffers)
3 *
4 * Written 1994-1999 by Avery Pennarun.
5 * Written 1999 by Martin Mares <mj@ucw.cz>.
6 * Derived from skeleton.c by Donald Becker.
7 *
8 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
9 * for sponsoring the further development of this driver.
10 *
11 * **********************
12 *
13 * The original copyright of skeleton.c was as follows:
14 *
15 * skeleton.c Written 1993 by Donald Becker.
16 * Copyright 1993 United States Government as represented by the
17 * Director, National Security Agency. This software may only be used
18 * and distributed according to the terms of the GNU General Public License as
19 * modified by SRC, incorporated herein by reference.
20 *
21 * **********************
22 *
23 * For more details, see drivers/net/arcnet.c
24 *
25 * **********************
26 */
27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/init.h>
30#include <linux/interrupt.h>
31#include <linux/ioport.h>
32#include <linux/delay.h>
33#include <linux/netdevice.h>
34#include <linux/slab.h>
35#include <asm/io.h>
36#include <linux/arcdevice.h>
37
38
39#define VERSION "arcnet: COM90xx chipset support\n"
40
41
42/* Define this to speed up the autoprobe by assuming if only one io port and
43 * shmem are left in the list at Stage 5, they must correspond to each
44 * other.
45 *
46 * This is undefined by default because it might not always be true, and the
47 * extra check makes the autoprobe even more careful. Speed demons can turn
48 * it on - I think it should be fine if you only have one ARCnet card
49 * installed.
50 *
51 * If no ARCnet cards are installed, this delay never happens anyway and thus
52 * the option has no effect.
53 */
54#undef FAST_PROBE
55
56
57/* Internal function declarations */
58static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *);
59static void com90xx_command(struct net_device *dev, int command);
60static int com90xx_status(struct net_device *dev);
61static void com90xx_setmask(struct net_device *dev, int mask);
62static int com90xx_reset(struct net_device *dev, int really_reset);
63static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
64 void *buf, int count);
65static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset,
66 void *buf, int count);
67
68/* Known ARCnet cards */
69
70static struct net_device *cards[16];
71static int numcards;
72
73/* Handy defines for ARCnet specific stuff */
74
75/* The number of low I/O ports used by the card */
76#define ARCNET_TOTAL_SIZE 16
77
78/* Amount of I/O memory used by the card */
79#define BUFFER_SIZE (512)
80#define MIRROR_SIZE (BUFFER_SIZE*4)
81
82/* COM 9026 controller chip --> ARCnet register addresses */
83#define _INTMASK (ioaddr+0) /* writable */
84#define _STATUS (ioaddr+0) /* readable */
85#define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
86#define _CONFIG (ioaddr+2) /* Configuration register */
87#define _RESET (ioaddr+8) /* software reset (on read) */
88#define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
89#define _ADDR_HI (ioaddr+15) /* Control registers for said */
90#define _ADDR_LO (ioaddr+14)
91
92#undef ASTATUS
93#undef ACOMMAND
94#undef AINTMASK
95
96#define ASTATUS() inb(_STATUS)
97#define ACOMMAND(cmd) outb((cmd),_COMMAND)
98#define AINTMASK(msk) outb((msk),_INTMASK)
99
100
101static int com90xx_skip_probe __initdata = 0;
102
103/* Module parameters */
104
105static int io; /* use the insmod io= irq= shmem= options */
106static int irq;
107static int shmem;
108static char device[9]; /* use eg. device=arc1 to change name */
109
110module_param(io, int, 0);
111module_param(irq, int, 0);
112module_param(shmem, int, 0);
113module_param_string(device, device, sizeof(device), 0);
114
115static void __init com90xx_probe(void)
116{
117 int count, status, ioaddr, numprint, airq, openparen = 0;
118 unsigned long airqmask;
119 int ports[(0x3f0 - 0x200) / 16 + 1] =
120 {0};
121 unsigned long *shmems;
122 void __iomem **iomem;
123 int numports, numshmems, *port;
124 u_long *p;
125 int index;
126
127 if (!io && !irq && !shmem && !*device && com90xx_skip_probe)
128 return;
129
130 shmems = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(unsigned long),
131 GFP_KERNEL);
132 if (!shmems)
133 return;
134 iomem = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(void __iomem *),
135 GFP_KERNEL);
136 if (!iomem) {
137 kfree(shmems);
138 return;
139 }
140
141 BUGLVL(D_NORMAL) printk(VERSION);
142
143 /* set up the arrays where we'll store the possible probe addresses */
144 numports = numshmems = 0;
145 if (io)
146 ports[numports++] = io;
147 else
148 for (count = 0x200; count <= 0x3f0; count += 16)
149 ports[numports++] = count;
150 if (shmem)
151 shmems[numshmems++] = shmem;
152 else
153 for (count = 0xA0000; count <= 0xFF800; count += 2048)
154 shmems[numshmems++] = count;
155
156 /* Stage 1: abandon any reserved ports, or ones with status==0xFF
157 * (empty), and reset any others by reading the reset port.
158 */
159 numprint = -1;
160 for (port = &ports[0]; port - ports < numports; port++) {
161 numprint++;
162 numprint %= 8;
163 if (!numprint) {
164 BUGMSG2(D_INIT, "\n");
165 BUGMSG2(D_INIT, "S1: ");
166 }
167 BUGMSG2(D_INIT, "%Xh ", *port);
168
169 ioaddr = *port;
170
171 if (!request_region(*port, ARCNET_TOTAL_SIZE, "arcnet (90xx)")) {
172 BUGMSG2(D_INIT_REASONS, "(request_region)\n");
173 BUGMSG2(D_INIT_REASONS, "S1: ");
174 BUGLVL(D_INIT_REASONS) numprint = 0;
175 *port-- = ports[--numports];
176 continue;
177 }
178 if (ASTATUS() == 0xFF) {
179 BUGMSG2(D_INIT_REASONS, "(empty)\n");
180 BUGMSG2(D_INIT_REASONS, "S1: ");
181 BUGLVL(D_INIT_REASONS) numprint = 0;
182 release_region(*port, ARCNET_TOTAL_SIZE);
183 *port-- = ports[--numports];
184 continue;
185 }
186 inb(_RESET); /* begin resetting card */
187
188 BUGMSG2(D_INIT_REASONS, "\n");
189 BUGMSG2(D_INIT_REASONS, "S1: ");
190 BUGLVL(D_INIT_REASONS) numprint = 0;
191 }
192 BUGMSG2(D_INIT, "\n");
193
194 if (!numports) {
195 BUGMSG2(D_NORMAL, "S1: No ARCnet cards found.\n");
196 kfree(shmems);
197 kfree(iomem);
198 return;
199 }
200 /* Stage 2: we have now reset any possible ARCnet cards, so we can't
201 * do anything until they finish. If D_INIT, print the list of
202 * cards that are left.
203 */
204 numprint = -1;
205 for (port = &ports[0]; port < ports + numports; port++) {
206 numprint++;
207 numprint %= 8;
208 if (!numprint) {
209 BUGMSG2(D_INIT, "\n");
210 BUGMSG2(D_INIT, "S2: ");
211 }
212 BUGMSG2(D_INIT, "%Xh ", *port);
213 }
214 BUGMSG2(D_INIT, "\n");
215 mdelay(RESETtime);
216
217 /* Stage 3: abandon any shmem addresses that don't have the signature
218 * 0xD1 byte in the right place, or are read-only.
219 */
220 numprint = -1;
221 for (index = 0, p = &shmems[0]; index < numshmems; p++, index++) {
222 void __iomem *base;
223
224 numprint++;
225 numprint %= 8;
226 if (!numprint) {
227 BUGMSG2(D_INIT, "\n");
228 BUGMSG2(D_INIT, "S3: ");
229 }
230 BUGMSG2(D_INIT, "%lXh ", *p);
231
232 if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) {
233 BUGMSG2(D_INIT_REASONS, "(request_mem_region)\n");
234 BUGMSG2(D_INIT_REASONS, "Stage 3: ");
235 BUGLVL(D_INIT_REASONS) numprint = 0;
236 goto out;
237 }
238 base = ioremap(*p, MIRROR_SIZE);
239 if (!base) {
240 BUGMSG2(D_INIT_REASONS, "(ioremap)\n");
241 BUGMSG2(D_INIT_REASONS, "Stage 3: ");
242 BUGLVL(D_INIT_REASONS) numprint = 0;
243 goto out1;
244 }
245 if (readb(base) != TESTvalue) {
246 BUGMSG2(D_INIT_REASONS, "(%02Xh != %02Xh)\n",
247 readb(base), TESTvalue);
248 BUGMSG2(D_INIT_REASONS, "S3: ");
249 BUGLVL(D_INIT_REASONS) numprint = 0;
250 goto out2;
251 }
252 /* By writing 0x42 to the TESTvalue location, we also make
253 * sure no "mirror" shmem areas show up - if they occur
254 * in another pass through this loop, they will be discarded
255 * because *cptr != TESTvalue.
256 */
257 writeb(0x42, base);
258 if (readb(base) != 0x42) {
259 BUGMSG2(D_INIT_REASONS, "(read only)\n");
260 BUGMSG2(D_INIT_REASONS, "S3: ");
261 goto out2;
262 }
263 BUGMSG2(D_INIT_REASONS, "\n");
264 BUGMSG2(D_INIT_REASONS, "S3: ");
265 BUGLVL(D_INIT_REASONS) numprint = 0;
266 iomem[index] = base;
267 continue;
268 out2:
269 iounmap(base);
270 out1:
271 release_mem_region(*p, MIRROR_SIZE);
272 out:
273 *p-- = shmems[--numshmems];
274 index--;
275 }
276 BUGMSG2(D_INIT, "\n");
277
278 if (!numshmems) {
279 BUGMSG2(D_NORMAL, "S3: No ARCnet cards found.\n");
280 for (port = &ports[0]; port < ports + numports; port++)
281 release_region(*port, ARCNET_TOTAL_SIZE);
282 kfree(shmems);
283 kfree(iomem);
284 return;
285 }
286 /* Stage 4: something of a dummy, to report the shmems that are
287 * still possible after stage 3.
288 */
289 numprint = -1;
290 for (p = &shmems[0]; p < shmems + numshmems; p++) {
291 numprint++;
292 numprint %= 8;
293 if (!numprint) {
294 BUGMSG2(D_INIT, "\n");
295 BUGMSG2(D_INIT, "S4: ");
296 }
297 BUGMSG2(D_INIT, "%lXh ", *p);
298 }
299 BUGMSG2(D_INIT, "\n");
300
301 /* Stage 5: for any ports that have the correct status, can disable
302 * the RESET flag, and (if no irq is given) generate an autoirq,
303 * register an ARCnet device.
304 *
305 * Currently, we can only register one device per probe, so quit
306 * after the first one is found.
307 */
308 numprint = -1;
309 for (port = &ports[0]; port < ports + numports; port++) {
310 int found = 0;
311 numprint++;
312 numprint %= 8;
313 if (!numprint) {
314 BUGMSG2(D_INIT, "\n");
315 BUGMSG2(D_INIT, "S5: ");
316 }
317 BUGMSG2(D_INIT, "%Xh ", *port);
318
319 ioaddr = *port;
320 status = ASTATUS();
321
322 if ((status & 0x9D)
323 != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
324 BUGMSG2(D_INIT_REASONS, "(status=%Xh)\n", status);
325 BUGMSG2(D_INIT_REASONS, "S5: ");
326 BUGLVL(D_INIT_REASONS) numprint = 0;
327 release_region(*port, ARCNET_TOTAL_SIZE);
328 *port-- = ports[--numports];
329 continue;
330 }
331 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
332 status = ASTATUS();
333 if (status & RESETflag) {
334 BUGMSG2(D_INIT_REASONS, " (eternal reset, status=%Xh)\n",
335 status);
336 BUGMSG2(D_INIT_REASONS, "S5: ");
337 BUGLVL(D_INIT_REASONS) numprint = 0;
338 release_region(*port, ARCNET_TOTAL_SIZE);
339 *port-- = ports[--numports];
340 continue;
341 }
342 /* skip this completely if an IRQ was given, because maybe
343 * we're on a machine that locks during autoirq!
344 */
345 if (!irq) {
346 /* if we do this, we're sure to get an IRQ since the
347 * card has just reset and the NORXflag is on until
348 * we tell it to start receiving.
349 */
350 airqmask = probe_irq_on();
351 AINTMASK(NORXflag);
352 udelay(1);
353 AINTMASK(0);
354 airq = probe_irq_off(airqmask);
355
356 if (airq <= 0) {
357 BUGMSG2(D_INIT_REASONS, "(airq=%d)\n", airq);
358 BUGMSG2(D_INIT_REASONS, "S5: ");
359 BUGLVL(D_INIT_REASONS) numprint = 0;
360 release_region(*port, ARCNET_TOTAL_SIZE);
361 *port-- = ports[--numports];
362 continue;
363 }
364 } else {
365 airq = irq;
366 }
367
368 BUGMSG2(D_INIT, "(%d,", airq);
369 openparen = 1;
370
371 /* Everything seems okay. But which shmem, if any, puts
372 * back its signature byte when the card is reset?
373 *
374 * If there are multiple cards installed, there might be
375 * multiple shmems still in the list.
376 */
377#ifdef FAST_PROBE
378 if (numports > 1 || numshmems > 1) {
379 inb(_RESET);
380 mdelay(RESETtime);
381 } else {
382 /* just one shmem and port, assume they match */
383 writeb(TESTvalue, iomem[0]);
384 }
385#else
386 inb(_RESET);
387 mdelay(RESETtime);
388#endif
389
390 for (index = 0; index < numshmems; index++) {
391 u_long ptr = shmems[index];
392 void __iomem *base = iomem[index];
393
394 if (readb(base) == TESTvalue) { /* found one */
395 BUGMSG2(D_INIT, "%lXh)\n", *p);
396 openparen = 0;
397
398 /* register the card */
399 if (com90xx_found(*port, airq, ptr, base) == 0)
400 found = 1;
401 numprint = -1;
402
403 /* remove shmem from the list */
404 shmems[index] = shmems[--numshmems];
405 iomem[index] = iomem[numshmems];
406 break; /* go to the next I/O port */
407 } else {
408 BUGMSG2(D_INIT_REASONS, "%Xh-", readb(base));
409 }
410 }
411
412 if (openparen) {
413 BUGLVL(D_INIT) printk("no matching shmem)\n");
414 BUGLVL(D_INIT_REASONS) printk("S5: ");
415 BUGLVL(D_INIT_REASONS) numprint = 0;
416 }
417 if (!found)
418 release_region(*port, ARCNET_TOTAL_SIZE);
419 *port-- = ports[--numports];
420 }
421
422 BUGLVL(D_INIT_REASONS) printk("\n");
423
424 /* Now put back TESTvalue on all leftover shmems. */
425 for (index = 0; index < numshmems; index++) {
426 writeb(TESTvalue, iomem[index]);
427 iounmap(iomem[index]);
428 release_mem_region(shmems[index], MIRROR_SIZE);
429 }
430 kfree(shmems);
431 kfree(iomem);
432}
433
434static int check_mirror(unsigned long addr, size_t size)
435{
436 void __iomem *p;
437 int res = -1;
438
439 if (!request_mem_region(addr, size, "arcnet (90xx)"))
440 return -1;
441
442 p = ioremap(addr, size);
443 if (p) {
444 if (readb(p) == TESTvalue)
445 res = 1;
446 else
447 res = 0;
448 iounmap(p);
449 }
450
451 release_mem_region(addr, size);
452 return res;
453}
454
455/* Set up the struct net_device associated with this card. Called after
456 * probing succeeds.
457 */
458static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *p)
459{
460 struct net_device *dev = NULL;
461 struct arcnet_local *lp;
462 u_long first_mirror, last_mirror;
463 int mirror_size;
464
465 /* allocate struct net_device */
466 dev = alloc_arcdev(device);
467 if (!dev) {
468 BUGMSG2(D_NORMAL, "com90xx: Can't allocate device!\n");
469 iounmap(p);
470 release_mem_region(shmem, MIRROR_SIZE);
471 return -ENOMEM;
472 }
473 lp = netdev_priv(dev);
474 /* find the real shared memory start/end points, including mirrors */
475
476 /* guess the actual size of one "memory mirror" - the number of
477 * bytes between copies of the shared memory. On most cards, it's
478 * 2k (or there are no mirrors at all) but on some, it's 4k.
479 */
480 mirror_size = MIRROR_SIZE;
481 if (readb(p) == TESTvalue &&
482 check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
483 check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
484 mirror_size = 2 * MIRROR_SIZE;
485
486 first_mirror = shmem - mirror_size;
487 while (check_mirror(first_mirror, mirror_size) == 1)
488 first_mirror -= mirror_size;
489 first_mirror += mirror_size;
490
491 last_mirror = shmem + mirror_size;
492 while (check_mirror(last_mirror, mirror_size) == 1)
493 last_mirror += mirror_size;
494 last_mirror -= mirror_size;
495
496 dev->mem_start = first_mirror;
497 dev->mem_end = last_mirror + MIRROR_SIZE - 1;
498
499 iounmap(p);
500 release_mem_region(shmem, MIRROR_SIZE);
501
502 if (!request_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1, "arcnet (90xx)"))
503 goto err_free_dev;
504
505 /* reserve the irq */
506 if (request_irq(airq, arcnet_interrupt, 0, "arcnet (90xx)", dev)) {
507 BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", airq);
508 goto err_release_mem;
509 }
510 dev->irq = airq;
511
512 /* Initialize the rest of the device structure. */
513 lp->card_name = "COM90xx";
514 lp->hw.command = com90xx_command;
515 lp->hw.status = com90xx_status;
516 lp->hw.intmask = com90xx_setmask;
517 lp->hw.reset = com90xx_reset;
518 lp->hw.owner = THIS_MODULE;
519 lp->hw.copy_to_card = com90xx_copy_to_card;
520 lp->hw.copy_from_card = com90xx_copy_from_card;
521 lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1);
522 if (!lp->mem_start) {
523 BUGMSG(D_NORMAL, "Can't remap device memory!\n");
524 goto err_free_irq;
525 }
526
527 /* get and check the station ID from offset 1 in shmem */
528 dev->dev_addr[0] = readb(lp->mem_start + 1);
529
530 dev->base_addr = ioaddr;
531
532 BUGMSG(D_NORMAL, "COM90xx station %02Xh found at %03lXh, IRQ %d, "
533 "ShMem %lXh (%ld*%xh).\n",
534 dev->dev_addr[0],
535 dev->base_addr, dev->irq, dev->mem_start,
536 (dev->mem_end - dev->mem_start + 1) / mirror_size, mirror_size);
537
538 if (register_netdev(dev))
539 goto err_unmap;
540
541 cards[numcards++] = dev;
542 return 0;
543
544err_unmap:
545 iounmap(lp->mem_start);
546err_free_irq:
547 free_irq(dev->irq, dev);
548err_release_mem:
549 release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
550err_free_dev:
551 free_netdev(dev);
552 return -EIO;
553}
554
555
556static void com90xx_command(struct net_device *dev, int cmd)
557{
558 short ioaddr = dev->base_addr;
559
560 ACOMMAND(cmd);
561}
562
563
564static int com90xx_status(struct net_device *dev)
565{
566 short ioaddr = dev->base_addr;
567
568 return ASTATUS();
569}
570
571
572static void com90xx_setmask(struct net_device *dev, int mask)
573{
574 short ioaddr = dev->base_addr;
575
576 AINTMASK(mask);
577}
578
579
580/*
581 * Do a hardware reset on the card, and set up necessary registers.
582 *
583 * This should be called as little as possible, because it disrupts the
584 * token on the network (causes a RECON) and requires a significant delay.
585 *
586 * However, it does make sure the card is in a defined state.
587 */
588static int com90xx_reset(struct net_device *dev, int really_reset)
589{
590 struct arcnet_local *lp = netdev_priv(dev);
591 short ioaddr = dev->base_addr;
592
593 BUGMSG(D_INIT, "Resetting (status=%02Xh)\n", ASTATUS());
594
595 if (really_reset) {
596 /* reset the card */
597 inb(_RESET);
598 mdelay(RESETtime);
599 }
600 ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
601 ACOMMAND(CFLAGScmd | CONFIGclear);
602
603 /* don't do this until we verify that it doesn't hurt older cards! */
604 /* outb(inb(_CONFIG) | ENABLE16flag, _CONFIG); */
605
606 /* verify that the ARCnet signature byte is present */
607 if (readb(lp->mem_start) != TESTvalue) {
608 if (really_reset)
609 BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n");
610 return 1;
611 }
612 /* enable extended (512-byte) packets */
613 ACOMMAND(CONFIGcmd | EXTconf);
614
615 /* clean out all the memory to make debugging make more sense :) */
616 BUGLVL(D_DURING)
617 memset_io(lp->mem_start, 0x42, 2048);
618
619 /* done! return success. */
620 return 0;
621}
622
623static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
624 void *buf, int count)
625{
626 struct arcnet_local *lp = netdev_priv(dev);
627 void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
628 TIME("memcpy_toio", count, memcpy_toio(memaddr, buf, count));
629}
630
631
632static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset,
633 void *buf, int count)
634{
635 struct arcnet_local *lp = netdev_priv(dev);
636 void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
637 TIME("memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
638}
639
640
641MODULE_LICENSE("GPL");
642
643static int __init com90xx_init(void)
644{
645 if (irq == 2)
646 irq = 9;
647 com90xx_probe();
648 if (!numcards)
649 return -EIO;
650 return 0;
651}
652
653static void __exit com90xx_exit(void)
654{
655 struct net_device *dev;
656 struct arcnet_local *lp;
657 int count;
658
659 for (count = 0; count < numcards; count++) {
660 dev = cards[count];
661 lp = netdev_priv(dev);
662
663 unregister_netdev(dev);
664 free_irq(dev->irq, dev);
665 iounmap(lp->mem_start);
666 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
667 release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
668 free_netdev(dev);
669 }
670}
671
672module_init(com90xx_init);
673module_exit(com90xx_exit);
674
675#ifndef MODULE
676static int __init com90xx_setup(char *s)
677{
678 int ints[8];
679
680 s = get_options(s, 8, ints);
681 if (!ints[0] && !*s) {
682 printk("com90xx: Disabled.\n");
683 return 1;
684 }
685
686 switch (ints[0]) {
687 default: /* ERROR */
688 printk("com90xx: Too many arguments.\n");
689 case 3: /* Mem address */
690 shmem = ints[3];
691 case 2: /* IRQ */
692 irq = ints[2];
693 case 1: /* IO address */
694 io = ints[1];
695 }
696
697 if (*s)
698 snprintf(device, sizeof(device), "%s", s);
699
700 return 1;
701}
702
703__setup("com90xx=", com90xx_setup);
704#endif