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