2 * Linux ARCnet driver - COM90xx chipset (memory-mapped buffers)
4 * Written 1994-1999 by Avery Pennarun.
5 * Written 1999 by Martin Mares <mj@ucw.cz>.
6 * Derived from skeleton.c by Donald Becker.
8 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
9 * for sponsoring the further development of this driver.
11 * **********************
13 * The original copyright of skeleton.c was as follows:
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.
21 * **********************
23 * For more details, see drivers/net/arcnet.c
25 * **********************
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/init.h>
30 #include <linux/ioport.h>
31 #include <linux/delay.h>
32 #include <linux/netdevice.h>
34 #include <linux/arcdevice.h>
37 #define VERSION "arcnet: COM90xx chipset support\n"
40 /* Define this to speed up the autoprobe by assuming if only one io port and
41 * shmem are left in the list at Stage 5, they must correspond to each
44 * This is undefined by default because it might not always be true, and the
45 * extra check makes the autoprobe even more careful. Speed demons can turn
46 * it on - I think it should be fine if you only have one ARCnet card
49 * If no ARCnet cards are installed, this delay never happens anyway and thus
50 * the option has no effect.
55 /* Internal function declarations */
56 static int com90xx_found(int ioaddr
, int airq
, u_long shmem
);
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
, int offset
,
64 void *buf
, int count
);
66 /* Known ARCnet cards */
68 static struct net_device
*cards
[16];
71 /* Handy defines for ARCnet specific stuff */
73 /* The number of low I/O ports used by the card */
74 #define ARCNET_TOTAL_SIZE 16
76 /* Amount of I/O memory used by the card */
77 #define BUFFER_SIZE (512)
78 #define MIRROR_SIZE (BUFFER_SIZE*4)
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)
94 #define ASTATUS() inb(_STATUS)
95 #define ACOMMAND(cmd) outb((cmd),_COMMAND)
96 #define AINTMASK(msk) outb((msk),_INTMASK)
99 static int com90xx_skip_probe __initdata
= 0;
101 /* Module parameters */
103 static int io
; /* use the insmod io= irq= shmem= options */
106 static char device
[9]; /* use eg. device=arc1 to change name */
108 module_param(io
, int, 0);
109 module_param(irq
, int, 0);
110 module_param(shmem
, int, 0);
111 module_param_string(device
, device
, sizeof(device
), 0);
113 static void __init
com90xx_probe(void)
115 int count
, status
, ioaddr
, numprint
, airq
, openparen
= 0;
116 unsigned long airqmask
;
117 int ports
[(0x3f0 - 0x200) / 16 + 1] =
119 u_long shmems
[(0xFF800 - 0xA0000) / 2048 + 1] =
121 int numports
, numshmems
, *port
;
124 if (!io
&& !irq
&& !shmem
&& !*device
&& com90xx_skip_probe
)
127 BUGLVL(D_NORMAL
) printk(VERSION
);
129 /* set up the arrays where we'll store the possible probe addresses */
130 numports
= numshmems
= 0;
132 ports
[numports
++] = io
;
134 for (count
= 0x200; count
<= 0x3f0; count
+= 16)
135 ports
[numports
++] = count
;
137 shmems
[numshmems
++] = shmem
;
139 for (count
= 0xA0000; count
<= 0xFF800; count
+= 2048)
140 shmems
[numshmems
++] = count
;
142 /* Stage 1: abandon any reserved ports, or ones with status==0xFF
143 * (empty), and reset any others by reading the reset port.
146 for (port
= &ports
[0]; port
- ports
< numports
; port
++) {
150 BUGMSG2(D_INIT
, "\n");
151 BUGMSG2(D_INIT
, "S1: ");
153 BUGMSG2(D_INIT
, "%Xh ", *port
);
157 if (!request_region(*port
, ARCNET_TOTAL_SIZE
, "arcnet (90xx)")) {
158 BUGMSG2(D_INIT_REASONS
, "(request_region)\n");
159 BUGMSG2(D_INIT_REASONS
, "S1: ");
160 BUGLVL(D_INIT_REASONS
) numprint
= 0;
161 *port
-- = ports
[--numports
];
164 if (ASTATUS() == 0xFF) {
165 BUGMSG2(D_INIT_REASONS
, "(empty)\n");
166 BUGMSG2(D_INIT_REASONS
, "S1: ");
167 BUGLVL(D_INIT_REASONS
) numprint
= 0;
168 release_region(*port
, ARCNET_TOTAL_SIZE
);
169 *port
-- = ports
[--numports
];
172 inb(_RESET
); /* begin resetting card */
174 BUGMSG2(D_INIT_REASONS
, "\n");
175 BUGMSG2(D_INIT_REASONS
, "S1: ");
176 BUGLVL(D_INIT_REASONS
) numprint
= 0;
178 BUGMSG2(D_INIT
, "\n");
181 BUGMSG2(D_NORMAL
, "S1: No ARCnet cards found.\n");
184 /* Stage 2: we have now reset any possible ARCnet cards, so we can't
185 * do anything until they finish. If D_INIT, print the list of
186 * cards that are left.
189 for (port
= &ports
[0]; port
< ports
+ numports
; port
++) {
193 BUGMSG2(D_INIT
, "\n");
194 BUGMSG2(D_INIT
, "S2: ");
196 BUGMSG2(D_INIT
, "%Xh ", *port
);
198 BUGMSG2(D_INIT
, "\n");
201 /* Stage 3: abandon any shmem addresses that don't have the signature
202 * 0xD1 byte in the right place, or are read-only.
205 for (p
= &shmems
[0]; p
< shmems
+ numshmems
; p
++) {
211 BUGMSG2(D_INIT
, "\n");
212 BUGMSG2(D_INIT
, "S3: ");
214 BUGMSG2(D_INIT
, "%lXh ", *p
);
216 if (!request_mem_region(*p
, BUFFER_SIZE
, "arcnet (90xx)")) {
217 BUGMSG2(D_INIT_REASONS
, "(request_mem_region)\n");
218 BUGMSG2(D_INIT_REASONS
, "Stage 3: ");
219 BUGLVL(D_INIT_REASONS
) numprint
= 0;
220 *p
-- = shmems
[--numshmems
];
223 if (isa_readb(ptr
) != TESTvalue
) {
224 BUGMSG2(D_INIT_REASONS
, "(%02Xh != %02Xh)\n",
225 isa_readb(ptr
), TESTvalue
);
226 BUGMSG2(D_INIT_REASONS
, "S3: ");
227 BUGLVL(D_INIT_REASONS
) numprint
= 0;
228 release_mem_region(*p
, BUFFER_SIZE
);
229 *p
-- = shmems
[--numshmems
];
232 /* By writing 0x42 to the TESTvalue location, we also make
233 * sure no "mirror" shmem areas show up - if they occur
234 * in another pass through this loop, they will be discarded
235 * because *cptr != TESTvalue.
237 isa_writeb(0x42, ptr
);
238 if (isa_readb(ptr
) != 0x42) {
239 BUGMSG2(D_INIT_REASONS
, "(read only)\n");
240 BUGMSG2(D_INIT_REASONS
, "S3: ");
241 release_mem_region(*p
, BUFFER_SIZE
);
242 *p
-- = shmems
[--numshmems
];
245 BUGMSG2(D_INIT_REASONS
, "\n");
246 BUGMSG2(D_INIT_REASONS
, "S3: ");
247 BUGLVL(D_INIT_REASONS
) numprint
= 0;
249 BUGMSG2(D_INIT
, "\n");
252 BUGMSG2(D_NORMAL
, "S3: No ARCnet cards found.\n");
253 for (port
= &ports
[0]; port
< ports
+ numports
; port
++)
254 release_region(*port
, ARCNET_TOTAL_SIZE
);
257 /* Stage 4: something of a dummy, to report the shmems that are
258 * still possible after stage 3.
261 for (p
= &shmems
[0]; p
< shmems
+ numshmems
; p
++) {
265 BUGMSG2(D_INIT
, "\n");
266 BUGMSG2(D_INIT
, "S4: ");
268 BUGMSG2(D_INIT
, "%lXh ", *p
);
270 BUGMSG2(D_INIT
, "\n");
272 /* Stage 5: for any ports that have the correct status, can disable
273 * the RESET flag, and (if no irq is given) generate an autoirq,
274 * register an ARCnet device.
276 * Currently, we can only register one device per probe, so quit
277 * after the first one is found.
280 for (port
= &ports
[0]; port
< ports
+ numports
; port
++) {
285 BUGMSG2(D_INIT
, "\n");
286 BUGMSG2(D_INIT
, "S5: ");
288 BUGMSG2(D_INIT
, "%Xh ", *port
);
294 != (NORXflag
| RECONflag
| TXFREEflag
| RESETflag
)) {
295 BUGMSG2(D_INIT_REASONS
, "(status=%Xh)\n", status
);
296 BUGMSG2(D_INIT_REASONS
, "S5: ");
297 BUGLVL(D_INIT_REASONS
) numprint
= 0;
298 release_region(*port
, ARCNET_TOTAL_SIZE
);
299 *port
-- = ports
[--numports
];
302 ACOMMAND(CFLAGScmd
| RESETclear
| CONFIGclear
);
304 if (status
& RESETflag
) {
305 BUGMSG2(D_INIT_REASONS
, " (eternal reset, status=%Xh)\n",
307 BUGMSG2(D_INIT_REASONS
, "S5: ");
308 BUGLVL(D_INIT_REASONS
) numprint
= 0;
309 release_region(*port
, ARCNET_TOTAL_SIZE
);
310 *port
-- = ports
[--numports
];
313 /* skip this completely if an IRQ was given, because maybe
314 * we're on a machine that locks during autoirq!
317 /* if we do this, we're sure to get an IRQ since the
318 * card has just reset and the NORXflag is on until
319 * we tell it to start receiving.
321 airqmask
= probe_irq_on();
325 airq
= probe_irq_off(airqmask
);
328 BUGMSG2(D_INIT_REASONS
, "(airq=%d)\n", airq
);
329 BUGMSG2(D_INIT_REASONS
, "S5: ");
330 BUGLVL(D_INIT_REASONS
) numprint
= 0;
331 release_region(*port
, ARCNET_TOTAL_SIZE
);
332 *port
-- = ports
[--numports
];
339 BUGMSG2(D_INIT
, "(%d,", airq
);
342 /* Everything seems okay. But which shmem, if any, puts
343 * back its signature byte when the card is reset?
345 * If there are multiple cards installed, there might be
346 * multiple shmems still in the list.
349 if (numports
> 1 || numshmems
> 1) {
353 /* just one shmem and port, assume they match */
354 isa_writeb(TESTvalue
, shmems
[0]);
361 for (p
= &shmems
[0]; p
< shmems
+ numshmems
; p
++) {
364 if (isa_readb(ptr
) == TESTvalue
) { /* found one */
365 BUGMSG2(D_INIT
, "%lXh)\n", *p
);
368 /* register the card */
369 if (com90xx_found(*port
, airq
, *p
) == 0)
373 /* remove shmem from the list */
374 *p
= shmems
[--numshmems
];
375 break; /* go to the next I/O port */
377 BUGMSG2(D_INIT_REASONS
, "%Xh-", isa_readb(ptr
));
382 BUGLVL(D_INIT
) printk("no matching shmem)\n");
383 BUGLVL(D_INIT_REASONS
) printk("S5: ");
384 BUGLVL(D_INIT_REASONS
) numprint
= 0;
387 release_region(*port
, ARCNET_TOTAL_SIZE
);
388 *port
-- = ports
[--numports
];
391 BUGLVL(D_INIT_REASONS
) printk("\n");
393 /* Now put back TESTvalue on all leftover shmems. */
394 for (p
= &shmems
[0]; p
< shmems
+ numshmems
; p
++) {
395 isa_writeb(TESTvalue
, *p
);
396 release_mem_region(*p
, BUFFER_SIZE
);
401 /* Set up the struct net_device associated with this card. Called after
404 static int __init
com90xx_found(int ioaddr
, int airq
, u_long shmem
)
406 struct net_device
*dev
= NULL
;
407 struct arcnet_local
*lp
;
408 u_long first_mirror
, last_mirror
;
411 /* allocate struct net_device */
412 dev
= alloc_arcdev(device
);
414 BUGMSG2(D_NORMAL
, "com90xx: Can't allocate device!\n");
415 release_mem_region(shmem
, BUFFER_SIZE
);
419 /* find the real shared memory start/end points, including mirrors */
421 /* guess the actual size of one "memory mirror" - the number of
422 * bytes between copies of the shared memory. On most cards, it's
423 * 2k (or there are no mirrors at all) but on some, it's 4k.
425 mirror_size
= MIRROR_SIZE
;
426 if (isa_readb(shmem
) == TESTvalue
427 && isa_readb(shmem
- mirror_size
) != TESTvalue
428 && isa_readb(shmem
- 2 * mirror_size
) == TESTvalue
)
431 first_mirror
= last_mirror
= shmem
;
432 while (isa_readb(first_mirror
) == TESTvalue
)
433 first_mirror
-= mirror_size
;
434 first_mirror
+= mirror_size
;
436 while (isa_readb(last_mirror
) == TESTvalue
)
437 last_mirror
+= mirror_size
;
438 last_mirror
-= mirror_size
;
440 dev
->mem_start
= first_mirror
;
441 dev
->mem_end
= last_mirror
+ MIRROR_SIZE
- 1;
443 release_mem_region(shmem
, BUFFER_SIZE
);
444 if (!request_mem_region(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1, "arcnet (90xx)"))
447 /* reserve the irq */
448 if (request_irq(airq
, &arcnet_interrupt
, 0, "arcnet (90xx)", dev
)) {
449 BUGMSG(D_NORMAL
, "Can't get IRQ %d!\n", airq
);
450 goto err_release_mem
;
454 /* Initialize the rest of the device structure. */
455 lp
->card_name
= "COM90xx";
456 lp
->hw
.command
= com90xx_command
;
457 lp
->hw
.status
= com90xx_status
;
458 lp
->hw
.intmask
= com90xx_setmask
;
459 lp
->hw
.reset
= com90xx_reset
;
460 lp
->hw
.owner
= THIS_MODULE
;
461 lp
->hw
.copy_to_card
= com90xx_copy_to_card
;
462 lp
->hw
.copy_from_card
= com90xx_copy_from_card
;
463 lp
->mem_start
= ioremap(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
464 if (!lp
->mem_start
) {
465 BUGMSG(D_NORMAL
, "Can't remap device memory!\n");
469 /* get and check the station ID from offset 1 in shmem */
470 dev
->dev_addr
[0] = readb(lp
->mem_start
+ 1);
472 dev
->base_addr
= ioaddr
;
474 BUGMSG(D_NORMAL
, "COM90xx station %02Xh found at %03lXh, IRQ %d, "
475 "ShMem %lXh (%ld*%xh).\n",
477 dev
->base_addr
, dev
->irq
, dev
->mem_start
,
478 (dev
->mem_end
- dev
->mem_start
+ 1) / mirror_size
, mirror_size
);
480 if (register_netdev(dev
))
483 cards
[numcards
++] = dev
;
487 iounmap(lp
->mem_start
);
489 free_irq(dev
->irq
, dev
);
491 release_mem_region(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
498 static void com90xx_command(struct net_device
*dev
, int cmd
)
500 short ioaddr
= dev
->base_addr
;
506 static int com90xx_status(struct net_device
*dev
)
508 short ioaddr
= dev
->base_addr
;
514 static void com90xx_setmask(struct net_device
*dev
, int mask
)
516 short ioaddr
= dev
->base_addr
;
523 * Do a hardware reset on the card, and set up necessary registers.
525 * This should be called as little as possible, because it disrupts the
526 * token on the network (causes a RECON) and requires a significant delay.
528 * However, it does make sure the card is in a defined state.
530 int com90xx_reset(struct net_device
*dev
, int really_reset
)
532 struct arcnet_local
*lp
= dev
->priv
;
533 short ioaddr
= dev
->base_addr
;
535 BUGMSG(D_INIT
, "Resetting (status=%02Xh)\n", ASTATUS());
542 ACOMMAND(CFLAGScmd
| RESETclear
); /* clear flags & end reset */
543 ACOMMAND(CFLAGScmd
| CONFIGclear
);
545 /* don't do this until we verify that it doesn't hurt older cards! */
546 /* outb(inb(_CONFIG) | ENABLE16flag, _CONFIG); */
548 /* verify that the ARCnet signature byte is present */
549 if (readb(lp
->mem_start
) != TESTvalue
) {
551 BUGMSG(D_NORMAL
, "reset failed: TESTvalue not present.\n");
554 /* enable extended (512-byte) packets */
555 ACOMMAND(CONFIGcmd
| EXTconf
);
557 /* clean out all the memory to make debugging make more sense :) */
559 memset_io(lp
->mem_start
, 0x42, 2048);
561 /* done! return success. */
565 static void com90xx_copy_to_card(struct net_device
*dev
, int bufnum
, int offset
,
566 void *buf
, int count
)
568 struct arcnet_local
*lp
= dev
->priv
;
569 void __iomem
*memaddr
= lp
->mem_start
+ bufnum
* 512 + offset
;
570 TIME("memcpy_toio", count
, memcpy_toio(memaddr
, buf
, count
));
574 static void com90xx_copy_from_card(struct net_device
*dev
, int bufnum
, int offset
,
575 void *buf
, int count
)
577 struct arcnet_local
*lp
= dev
->priv
;
578 void __iomem
*memaddr
= lp
->mem_start
+ bufnum
* 512 + offset
;
579 TIME("memcpy_fromio", count
, memcpy_fromio(buf
, memaddr
, count
));
583 MODULE_LICENSE("GPL");
585 static int __init
com90xx_init(void)
595 static void __exit
com90xx_exit(void)
597 struct net_device
*dev
;
598 struct arcnet_local
*lp
;
601 for (count
= 0; count
< numcards
; count
++) {
605 unregister_netdev(dev
);
606 free_irq(dev
->irq
, dev
);
607 iounmap(lp
->mem_start
);
608 release_region(dev
->base_addr
, ARCNET_TOTAL_SIZE
);
609 release_mem_region(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
614 module_init(com90xx_init
);
615 module_exit(com90xx_exit
);
618 static int __init
com90xx_setup(char *s
)
622 s
= get_options(s
, 8, ints
);
623 if (!ints
[0] && !*s
) {
624 printk("com90xx: Disabled.\n");
630 printk("com90xx: Too many arguments.\n");
631 case 3: /* Mem address */
635 case 1: /* IO address */
640 snprintf(device
, sizeof(device
), "%s", s
);
645 __setup("com90xx=", com90xx_setup
);