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