27 #include <linux/module.h>
33 #include <linux/netdevice.h>
34 #include <linux/slab.h>
39 #define VERSION "arcnet: COM90xx chipset support\n"
58 static int com90xx_found(
int ioaddr,
int airq,
u_long shmem,
void __iomem *);
62 static int com90xx_reset(
struct net_device *
dev,
int really_reset);
76 #define ARCNET_TOTAL_SIZE 16
79 #define BUFFER_SIZE (512)
80 #define MIRROR_SIZE (BUFFER_SIZE*4)
83 #define _INTMASK (ioaddr+0)
84 #define _STATUS (ioaddr+0)
85 #define _COMMAND (ioaddr+1)
86 #define _CONFIG (ioaddr+2)
87 #define _RESET (ioaddr+8)
88 #define _MEMDATA (ioaddr+12)
89 #define _ADDR_HI (ioaddr+15)
90 #define _ADDR_LO (ioaddr+14)
96 #define ASTATUS() inb(_STATUS)
97 #define ACOMMAND(cmd) outb((cmd),_COMMAND)
98 #define AINTMASK(msk) outb((msk),_INTMASK)
115 static void __init com90xx_probe(
void)
117 int count,
status, ioaddr, numprint, airq, openparen = 0;
118 unsigned long airqmask;
119 int ports[(0x3f0 - 0x200) / 16 + 1] =
121 unsigned long *shmems;
123 int numports, numshmems, *
port;
127 if (!
io && !
irq && !shmem && !*
device && com90xx_skip_probe)
130 shmems = kzalloc(((0x100000-0xa0000) / 0x800) *
sizeof(
unsigned long),
134 iomem = kzalloc(((0x100000-0xa0000) / 0x800) *
sizeof(
void __iomem *),
144 numports = numshmems = 0;
146 ports[numports++] =
io;
148 for (count = 0x200; count <= 0x3f0; count += 16)
149 ports[numports++] = count;
151 shmems[numshmems++] = shmem;
153 for (count = 0xA0000; count <= 0xFF800; count += 2048)
154 shmems[numshmems++] = count;
160 for (port = &ports[0]; port - ports < numports; port++) {
167 BUGMSG2(
D_INIT,
"%Xh ", *port);
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];
179 BUGMSG2(D_INIT_REASONS,
"(empty)\n");
180 BUGMSG2(D_INIT_REASONS,
"S1: ");
181 BUGLVL(D_INIT_REASONS) numprint = 0;
183 *port-- = ports[--numports];
188 BUGMSG2(D_INIT_REASONS, "\
n");
189 BUGMSG2(D_INIT_REASONS, "
S1: ");
190 BUGLVL(D_INIT_REASONS) numprint = 0;
195 BUGMSG2(D_NORMAL,
"S1: No ARCnet cards found.\n");
205 for (port = &ports[0]; port < ports + numports; port++) {
212 BUGMSG2(
D_INIT,
"%Xh ", *port);
221 for (index = 0, p = &shmems[0]; index < numshmems; p++, index++) {
230 BUGMSG2(
D_INIT,
"%lXh ", *p);
233 BUGMSG2(D_INIT_REASONS,
"(request_mem_region)\n");
234 BUGMSG2(D_INIT_REASONS,
"Stage 3: ");
235 BUGLVL(D_INIT_REASONS) numprint = 0;
240 BUGMSG2(D_INIT_REASONS,
"(ioremap)\n");
241 BUGMSG2(D_INIT_REASONS,
"Stage 3: ");
242 BUGLVL(D_INIT_REASONS) numprint = 0;
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;
259 BUGMSG2(D_INIT_REASONS,
"(read only)\n");
260 BUGMSG2(D_INIT_REASONS,
"S3: ");
263 BUGMSG2(D_INIT_REASONS,
"\n");
264 BUGMSG2(D_INIT_REASONS,
"S3: ");
265 BUGLVL(D_INIT_REASONS) numprint = 0;
273 *p-- = shmems[--numshmems];
279 BUGMSG2(D_NORMAL,
"S3: No ARCnet cards found.\n");
280 for (port = &ports[0]; port < ports + numports; port++)
290 for (p = &shmems[0]; p < shmems + numshmems; p++) {
294 BUGMSG2(D_INIT,
"\n");
295 BUGMSG2(D_INIT,
"S4: ");
297 BUGMSG2(D_INIT,
"%lXh ", *p);
299 BUGMSG2(D_INIT,
"\n");
309 for (port = &ports[0]; port < ports + numports; port++) {
314 BUGMSG2(D_INIT,
"\n");
315 BUGMSG2(D_INIT,
"S5: ");
317 BUGMSG2(D_INIT,
"%Xh ", *port);
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;
328 *port-- = ports[--numports];
331 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
333 if (status & RESETflag) {
334 BUGMSG2(D_INIT_REASONS,
" (eternal reset, status=%Xh)\n",
336 BUGMSG2(D_INIT_REASONS,
"S5: ");
337 BUGLVL(D_INIT_REASONS) numprint = 0;
339 *port-- = ports[--numports];
357 BUGMSG2(D_INIT_REASONS,
"(airq=%d)\n", airq);
358 BUGMSG2(D_INIT_REASONS,
"S5: ");
359 BUGLVL(D_INIT_REASONS) numprint = 0;
361 *port-- = ports[--numports];
368 BUGMSG2(D_INIT,
"(%d,", airq);
378 if (numports > 1 || numshmems > 1) {
383 writeb(TESTvalue, iomem[0]);
390 for (index = 0; index < numshmems; index++) {
394 if (
readb(base) == TESTvalue) {
395 BUGMSG2(D_INIT,
"%lXh)\n", *p);
399 if (com90xx_found(*port, airq, ptr, base) == 0)
404 shmems[
index] = shmems[--numshmems];
405 iomem[
index] = iomem[numshmems];
408 BUGMSG2(D_INIT_REASONS,
"%Xh-",
readb(base));
413 BUGLVL(D_INIT)
printk("
no matching shmem)\n");
414 BUGLVL(D_INIT_REASONS)
printk("
S5: ");
415 BUGLVL(D_INIT_REASONS) numprint = 0;
419 *port-- = ports[--numports];
422 BUGLVL(D_INIT_REASONS)
printk("\n");
425 for (index = 0; index < numshmems; index++) {
426 writeb(TESTvalue, iomem[index]);
434 static int check_mirror(
unsigned long addr,
size_t size)
444 if (
readb(p) == TESTvalue)
461 struct arcnet_local *
lp;
462 u_long first_mirror, last_mirror;
468 BUGMSG2(D_NORMAL,
"com90xx: Can't allocate device!\n");
473 lp = netdev_priv(dev);
481 if (
readb(p) == TESTvalue &&
482 check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
483 check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
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;
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;
497 dev->
mem_end = last_mirror + MIRROR_SIZE - 1;
507 BUGMSG(D_NORMAL,
"Can't get IRQ %d!\n", airq);
508 goto err_release_mem;
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;
519 lp->hw.copy_to_card = com90xx_copy_to_card;
520 lp->hw.copy_from_card = com90xx_copy_from_card;
522 if (!lp->mem_start) {
523 BUGMSG(D_NORMAL,
"Can't remap device memory!\n");
532 BUGMSG(D_NORMAL,
"COM90xx station %02Xh found at %03lXh, IRQ %d, "
533 "ShMem %lXh (%ld*%xh).\n",
541 cards[numcards++] =
dev;
564 static int com90xx_status(
struct net_device *dev)
588 static int com90xx_reset(
struct net_device *dev,
int really_reset)
590 struct arcnet_local *lp = netdev_priv(dev);
593 BUGMSG(D_INIT,
"Resetting (status=%02Xh)\n",
ASTATUS());
607 if (
readb(lp->mem_start) != TESTvalue) {
609 BUGMSG(D_NORMAL,
"reset failed: TESTvalue not present.\n");
624 void *
buf,
int count)
626 struct arcnet_local *lp = netdev_priv(dev);
632 static void com90xx_copy_from_card(
struct net_device *dev,
int bufnum,
int offset,
633 void *buf,
int count)
635 struct arcnet_local *lp = netdev_priv(dev);
636 void __iomem *memaddr = lp->mem_start + bufnum * 512 +
offset;
643 static int __init com90xx_init(
void)
653 static void __exit com90xx_exit(
void)
656 struct arcnet_local *lp;
659 for (count = 0; count < numcards; count++) {
661 lp = netdev_priv(dev);
676 static int __init com90xx_setup(
char *
s)
681 if (!ints[0] && !*s) {
682 printk(
"com90xx: Disabled.\n");
688 printk(
"com90xx: Too many arguments.\n");
703 __setup(
"com90xx=", com90xx_setup);