arcnet: com90xx: Use arcnet_readb/writeb routines
[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
40 #include "arcdevice.h"
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 /* Internal function declarations */
57 static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *);
58 static void com90xx_command(struct net_device *dev, int command);
59 static int com90xx_status(struct net_device *dev);
60 static void com90xx_setmask(struct net_device *dev, int mask);
61 static int com90xx_reset(struct net_device *dev, int really_reset);
62 static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
63                                  void *buf, int count);
64 static void com90xx_copy_from_card(struct net_device *dev, int bufnum,
65                                    int offset, void *buf, int count);
66
67 /* Known ARCnet cards */
68
69 static struct net_device *cards[16];
70 static int numcards;
71
72 /* Handy defines for ARCnet specific stuff */
73
74 /* The number of low I/O ports used by the card */
75 #define ARCNET_TOTAL_SIZE       16
76
77 /* Amount of I/O memory used by the card */
78 #define BUFFER_SIZE (512)
79 #define MIRROR_SIZE (BUFFER_SIZE * 4)
80
81 /* COM 9026 controller chip --> ARCnet register addresses */
82 #define COM9026_REG_W_INTMASK   0       /* writable */
83 #define COM9026_REG_R_STATUS    0       /* readable */
84 #define COM9026_REG_W_COMMAND   1       /* writable, returns random vals on read (?) */
85 #define COM9026_REG_RW_CONFIG   2       /* Configuration register */
86 #define COM9026_REG_R_RESET     8       /* software reset (on read) */
87 #define COM9026_REG_RW_MEMDATA  12      /* Data port for IO-mapped memory */
88 #define COM9026_REG_W_ADDR_LO   14      /* Control registers for said */
89 #define COM9026_REG_W_ADDR_HI   15
90
91 #define COM9026_REG_R_STATION   1       /* Station ID */
92
93 static int com90xx_skip_probe __initdata = 0;
94
95 /* Module parameters */
96
97 static int io;                  /* use the insmod io= irq= shmem= options */
98 static int irq;
99 static int shmem;
100 static char device[9];          /* use eg. device=arc1 to change name */
101
102 module_param(io, int, 0);
103 module_param(irq, int, 0);
104 module_param(shmem, int, 0);
105 module_param_string(device, device, sizeof(device), 0);
106
107 static void __init com90xx_probe(void)
108 {
109         int count, status, ioaddr, numprint, airq, openparen = 0;
110         unsigned long airqmask;
111         int ports[(0x3f0 - 0x200) / 16 + 1] = { 0 };
112         unsigned long *shmems;
113         void __iomem **iomem;
114         int numports, numshmems, *port;
115         u_long *p;
116         int index;
117
118         if (!io && !irq && !shmem && !*device && com90xx_skip_probe)
119                 return;
120
121         shmems = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(unsigned long),
122                          GFP_KERNEL);
123         if (!shmems)
124                 return;
125         iomem = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(void __iomem *),
126                         GFP_KERNEL);
127         if (!iomem) {
128                 kfree(shmems);
129                 return;
130         }
131
132         if (BUGLVL(D_NORMAL))
133                 pr_info("%s\n", "COM90xx chipset support");
134
135         /* set up the arrays where we'll store the possible probe addresses */
136         numports = numshmems = 0;
137         if (io)
138                 ports[numports++] = io;
139         else
140                 for (count = 0x200; count <= 0x3f0; count += 16)
141                         ports[numports++] = count;
142         if (shmem)
143                 shmems[numshmems++] = shmem;
144         else
145                 for (count = 0xA0000; count <= 0xFF800; count += 2048)
146                         shmems[numshmems++] = count;
147
148         /* Stage 1: abandon any reserved ports, or ones with status==0xFF
149          * (empty), and reset any others by reading the reset port.
150          */
151         numprint = -1;
152         for (port = &ports[0]; port - ports < numports; port++) {
153                 numprint++;
154                 numprint %= 8;
155                 if (!numprint) {
156                         arc_cont(D_INIT, "\n");
157                         arc_cont(D_INIT, "S1: ");
158                 }
159                 arc_cont(D_INIT, "%Xh ", *port);
160
161                 ioaddr = *port;
162
163                 if (!request_region(*port, ARCNET_TOTAL_SIZE,
164                                     "arcnet (90xx)")) {
165                         arc_cont(D_INIT_REASONS, "(request_region)\n");
166                         arc_cont(D_INIT_REASONS, "S1: ");
167                         if (BUGLVL(D_INIT_REASONS))
168                                 numprint = 0;
169                         *port-- = ports[--numports];
170                         continue;
171                 }
172                 if (arcnet_inb(ioaddr, COM9026_REG_R_STATUS) == 0xFF) {
173                         arc_cont(D_INIT_REASONS, "(empty)\n");
174                         arc_cont(D_INIT_REASONS, "S1: ");
175                         if (BUGLVL(D_INIT_REASONS))
176                                 numprint = 0;
177                         release_region(*port, ARCNET_TOTAL_SIZE);
178                         *port-- = ports[--numports];
179                         continue;
180                 }
181                 /* begin resetting card */
182                 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
183
184                 arc_cont(D_INIT_REASONS, "\n");
185                 arc_cont(D_INIT_REASONS, "S1: ");
186                 if (BUGLVL(D_INIT_REASONS))
187                         numprint = 0;
188         }
189         arc_cont(D_INIT, "\n");
190
191         if (!numports) {
192                 arc_cont(D_NORMAL, "S1: No ARCnet cards found.\n");
193                 kfree(shmems);
194                 kfree(iomem);
195                 return;
196         }
197         /* Stage 2: we have now reset any possible ARCnet cards, so we can't
198          * do anything until they finish.  If D_INIT, print the list of
199          * cards that are left.
200          */
201         numprint = -1;
202         for (port = &ports[0]; port < ports + numports; port++) {
203                 numprint++;
204                 numprint %= 8;
205                 if (!numprint) {
206                         arc_cont(D_INIT, "\n");
207                         arc_cont(D_INIT, "S2: ");
208                 }
209                 arc_cont(D_INIT, "%Xh ", *port);
210         }
211         arc_cont(D_INIT, "\n");
212         mdelay(RESETtime);
213
214         /* Stage 3: abandon any shmem addresses that don't have the signature
215          * 0xD1 byte in the right place, or are read-only.
216          */
217         numprint = -1;
218         for (index = 0, p = &shmems[0]; index < numshmems; p++, index++) {
219                 void __iomem *base;
220
221                 numprint++;
222                 numprint %= 8;
223                 if (!numprint) {
224                         arc_cont(D_INIT, "\n");
225                         arc_cont(D_INIT, "S3: ");
226                 }
227                 arc_cont(D_INIT, "%lXh ", *p);
228
229                 if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) {
230                         arc_cont(D_INIT_REASONS, "(request_mem_region)\n");
231                         arc_cont(D_INIT_REASONS, "Stage 3: ");
232                         if (BUGLVL(D_INIT_REASONS))
233                                 numprint = 0;
234                         goto out;
235                 }
236                 base = ioremap(*p, MIRROR_SIZE);
237                 if (!base) {
238                         arc_cont(D_INIT_REASONS, "(ioremap)\n");
239                         arc_cont(D_INIT_REASONS, "Stage 3: ");
240                         if (BUGLVL(D_INIT_REASONS))
241                                 numprint = 0;
242                         goto out1;
243                 }
244                 if (arcnet_readb(base, COM9026_REG_R_STATUS) != TESTvalue) {
245                         arc_cont(D_INIT_REASONS, "(%02Xh != %02Xh)\n",
246                                  arcnet_readb(base, COM9026_REG_R_STATUS),
247                                  TESTvalue);
248                         arc_cont(D_INIT_REASONS, "S3: ");
249                         if (BUGLVL(D_INIT_REASONS))
250                                 numprint = 0;
251                         goto out2;
252                 }
253                 /* By writing 0x42 to the TESTvalue location, we also make
254                  * sure no "mirror" shmem areas show up - if they occur
255                  * in another pass through this loop, they will be discarded
256                  * because *cptr != TESTvalue.
257                  */
258                 arcnet_writeb(0x42, base, COM9026_REG_W_INTMASK);
259                 if (arcnet_readb(base, COM9026_REG_R_STATUS) != 0x42) {
260                         arc_cont(D_INIT_REASONS, "(read only)\n");
261                         arc_cont(D_INIT_REASONS, "S3: ");
262                         goto out2;
263                 }
264                 arc_cont(D_INIT_REASONS, "\n");
265                 arc_cont(D_INIT_REASONS, "S3: ");
266                 if (BUGLVL(D_INIT_REASONS))
267                         numprint = 0;
268                 iomem[index] = base;
269                 continue;
270         out2:
271                 iounmap(base);
272         out1:
273                 release_mem_region(*p, MIRROR_SIZE);
274         out:
275                 *p-- = shmems[--numshmems];
276                 index--;
277         }
278         arc_cont(D_INIT, "\n");
279
280         if (!numshmems) {
281                 arc_cont(D_NORMAL, "S3: No ARCnet cards found.\n");
282                 for (port = &ports[0]; port < ports + numports; port++)
283                         release_region(*port, ARCNET_TOTAL_SIZE);
284                 kfree(shmems);
285                 kfree(iomem);
286                 return;
287         }
288         /* Stage 4: something of a dummy, to report the shmems that are
289          * still possible after stage 3.
290          */
291         numprint = -1;
292         for (p = &shmems[0]; p < shmems + numshmems; p++) {
293                 numprint++;
294                 numprint %= 8;
295                 if (!numprint) {
296                         arc_cont(D_INIT, "\n");
297                         arc_cont(D_INIT, "S4: ");
298                 }
299                 arc_cont(D_INIT, "%lXh ", *p);
300         }
301         arc_cont(D_INIT, "\n");
302
303         /* Stage 5: for any ports that have the correct status, can disable
304          * the RESET flag, and (if no irq is given) generate an autoirq,
305          * register an ARCnet device.
306          *
307          * Currently, we can only register one device per probe, so quit
308          * after the first one is found.
309          */
310         numprint = -1;
311         for (port = &ports[0]; port < ports + numports; port++) {
312                 int found = 0;
313
314                 numprint++;
315                 numprint %= 8;
316                 if (!numprint) {
317                         arc_cont(D_INIT, "\n");
318                         arc_cont(D_INIT, "S5: ");
319                 }
320                 arc_cont(D_INIT, "%Xh ", *port);
321
322                 ioaddr = *port;
323                 status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
324
325                 if ((status & 0x9D)
326                     != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
327                         arc_cont(D_INIT_REASONS, "(status=%Xh)\n", status);
328                         arc_cont(D_INIT_REASONS, "S5: ");
329                         if (BUGLVL(D_INIT_REASONS))
330                                 numprint = 0;
331                         release_region(*port, ARCNET_TOTAL_SIZE);
332                         *port-- = ports[--numports];
333                         continue;
334                 }
335                 arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
336                             ioaddr, COM9026_REG_W_COMMAND);
337                 status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
338                 if (status & RESETflag) {
339                         arc_cont(D_INIT_REASONS, " (eternal reset, status=%Xh)\n",
340                                  status);
341                         arc_cont(D_INIT_REASONS, "S5: ");
342                         if (BUGLVL(D_INIT_REASONS))
343                                 numprint = 0;
344                         release_region(*port, ARCNET_TOTAL_SIZE);
345                         *port-- = ports[--numports];
346                         continue;
347                 }
348                 /* skip this completely if an IRQ was given, because maybe
349                  * we're on a machine that locks during autoirq!
350                  */
351                 if (!irq) {
352                         /* if we do this, we're sure to get an IRQ since the
353                          * card has just reset and the NORXflag is on until
354                          * we tell it to start receiving.
355                          */
356                         airqmask = probe_irq_on();
357                         arcnet_outb(NORXflag, ioaddr, COM9026_REG_W_INTMASK);
358                         udelay(1);
359                         arcnet_outb(0, ioaddr, COM9026_REG_W_INTMASK);
360                         airq = probe_irq_off(airqmask);
361
362                         if (airq <= 0) {
363                                 arc_cont(D_INIT_REASONS, "(airq=%d)\n", airq);
364                                 arc_cont(D_INIT_REASONS, "S5: ");
365                                 if (BUGLVL(D_INIT_REASONS))
366                                         numprint = 0;
367                                 release_region(*port, ARCNET_TOTAL_SIZE);
368                                 *port-- = ports[--numports];
369                                 continue;
370                         }
371                 } else {
372                         airq = irq;
373                 }
374
375                 arc_cont(D_INIT, "(%d,", airq);
376                 openparen = 1;
377
378                 /* Everything seems okay.  But which shmem, if any, puts
379                  * back its signature byte when the card is reset?
380                  *
381                  * If there are multiple cards installed, there might be
382                  * multiple shmems still in the list.
383                  */
384 #ifdef FAST_PROBE
385                 if (numports > 1 || numshmems > 1) {
386                         arcnet_inb(ioaddr, COM9026_REG_R_RESET);
387                         mdelay(RESETtime);
388                 } else {
389                         /* just one shmem and port, assume they match */
390                         arcnet_writeb(TESTvalue, iomem[0],
391                                       COM9026_REG_W_INTMASK);
392                 }
393 #else
394                 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
395                 mdelay(RESETtime);
396 #endif
397
398                 for (index = 0; index < numshmems; index++) {
399                         u_long ptr = shmems[index];
400                         void __iomem *base = iomem[index];
401
402                         if (arcnet_readb(base, COM9026_REG_R_STATUS) == TESTvalue) {    /* found one */
403                                 arc_cont(D_INIT, "%lXh)\n", *p);
404                                 openparen = 0;
405
406                                 /* register the card */
407                                 if (com90xx_found(*port, airq, ptr, base) == 0)
408                                         found = 1;
409                                 numprint = -1;
410
411                                 /* remove shmem from the list */
412                                 shmems[index] = shmems[--numshmems];
413                                 iomem[index] = iomem[numshmems];
414                                 break;  /* go to the next I/O port */
415                         } else {
416                                 arc_cont(D_INIT_REASONS, "%Xh-",
417                                          arcnet_readb(base, COM9026_REG_R_STATUS));
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                 arcnet_writeb(TESTvalue, iomem[index], COM9026_REG_W_INTMASK);
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 (arcnet_readb(p, COM9026_REG_R_STATUS) == 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 (arcnet_readb(p, COM9026_REG_R_STATUS) == 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] = arcnet_readb(lp->mem_start, COM9026_REG_R_STATION);
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         arcnet_outb(cmd, ioaddr, COM9026_REG_W_COMMAND);
577 }
578
579 static int com90xx_status(struct net_device *dev)
580 {
581         short ioaddr = dev->base_addr;
582
583         return arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
584 }
585
586 static void com90xx_setmask(struct net_device *dev, int mask)
587 {
588         short ioaddr = dev->base_addr;
589
590         arcnet_outb(mask, ioaddr, COM9026_REG_W_INTMASK);
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",
606                    arcnet_inb(ioaddr, COM9026_REG_R_STATUS));
607
608         if (really_reset) {
609                 /* reset the card */
610                 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
611                 mdelay(RESETtime);
612         }
613         /* clear flags & end reset */
614         arcnet_outb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND);
615         arcnet_outb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND);
616
617 #if 0
618         /* don't do this until we verify that it doesn't hurt older cards! */
619         arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) | ENABLE16flag,
620                     ioaddr, COM9026_REG_RW_CONFIG);
621 #endif
622
623         /* verify that the ARCnet signature byte is present */
624         if (arcnet_readb(lp->mem_start, COM9026_REG_R_STATUS) != TESTvalue) {
625                 if (really_reset)
626                         arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
627                 return 1;
628         }
629         /* enable extended (512-byte) packets */
630         arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
631
632         /* clean out all the memory to make debugging make more sense :) */
633         if (BUGLVL(D_DURING))
634                 memset_io(lp->mem_start, 0x42, 2048);
635
636         /* done!  return success. */
637         return 0;
638 }
639
640 static void com90xx_copy_to_card(struct net_device *dev, int bufnum,
641                                  int offset, void *buf, int count)
642 {
643         struct arcnet_local *lp = netdev_priv(dev);
644         void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
645
646         TIME(dev, "memcpy_toio", count, memcpy_toio(memaddr, buf, count));
647 }
648
649 static void com90xx_copy_from_card(struct net_device *dev, int bufnum,
650                                    int offset, void *buf, int count)
651 {
652         struct arcnet_local *lp = netdev_priv(dev);
653         void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
654
655         TIME(dev, "memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
656 }
657
658 MODULE_LICENSE("GPL");
659
660 static int __init com90xx_init(void)
661 {
662         if (irq == 2)
663                 irq = 9;
664         com90xx_probe();
665         if (!numcards)
666                 return -EIO;
667         return 0;
668 }
669
670 static void __exit com90xx_exit(void)
671 {
672         struct net_device *dev;
673         struct arcnet_local *lp;
674         int count;
675
676         for (count = 0; count < numcards; count++) {
677                 dev = cards[count];
678                 lp = netdev_priv(dev);
679
680                 unregister_netdev(dev);
681                 free_irq(dev->irq, dev);
682                 iounmap(lp->mem_start);
683                 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
684                 release_mem_region(dev->mem_start,
685                                    dev->mem_end - dev->mem_start + 1);
686                 free_netdev(dev);
687         }
688 }
689
690 module_init(com90xx_init);
691 module_exit(com90xx_exit);
692
693 #ifndef MODULE
694 static int __init com90xx_setup(char *s)
695 {
696         int ints[8];
697
698         s = get_options(s, 8, ints);
699         if (!ints[0] && !*s) {
700                 pr_notice("Disabled\n");
701                 return 1;
702         }
703
704         switch (ints[0]) {
705         default:                /* ERROR */
706                 pr_err("Too many arguments\n");
707         case 3:         /* Mem address */
708                 shmem = ints[3];
709         case 2:         /* IRQ */
710                 irq = ints[2];
711         case 1:         /* IO address */
712                 io = ints[1];
713         }
714
715         if (*s)
716                 snprintf(device, sizeof(device), "%s", s);
717
718         return 1;
719 }
720
721 __setup("com90xx=", com90xx_setup);
722 #endif