blob: f3b46f71e293d9ac7bb39dda6bd0a2937a1452cd [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/io.h>
35#include <linux/arcdevice.h>
36
37
38#define VERSION "arcnet: COM90xx chipset support\n"
39
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
56/* Internal function declarations */
Al Virod0f6eca2005-12-02 03:54:44 -050057static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058static void com90xx_command(struct net_device *dev, int command);
59static int com90xx_status(struct net_device *dev);
60static void com90xx_setmask(struct net_device *dev, int mask);
61static int com90xx_reset(struct net_device *dev, int really_reset);
62static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
63 void *buf, int count);
64static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset,
65 void *buf, int count);
66
67/* Known ARCnet cards */
68
69static struct net_device *cards[16];
70static 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 _INTMASK (ioaddr+0) /* writable */
83#define _STATUS (ioaddr+0) /* readable */
84#define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
85#define _CONFIG (ioaddr+2) /* Configuration register */
86#define _RESET (ioaddr+8) /* software reset (on read) */
87#define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
88#define _ADDR_HI (ioaddr+15) /* Control registers for said */
89#define _ADDR_LO (ioaddr+14)
90
91#undef ASTATUS
92#undef ACOMMAND
93#undef AINTMASK
94
95#define ASTATUS() inb(_STATUS)
96#define ACOMMAND(cmd) outb((cmd),_COMMAND)
97#define AINTMASK(msk) outb((msk),_INTMASK)
98
99
100static int com90xx_skip_probe __initdata = 0;
101
102/* Module parameters */
103
104static int io; /* use the insmod io= irq= shmem= options */
105static int irq;
106static int shmem;
107static char device[9]; /* use eg. device=arc1 to change name */
108
109module_param(io, int, 0);
110module_param(irq, int, 0);
111module_param(shmem, int, 0);
112module_param_string(device, device, sizeof(device), 0);
113
114static void __init com90xx_probe(void)
115{
116 int count, status, ioaddr, numprint, airq, openparen = 0;
117 unsigned long airqmask;
118 int ports[(0x3f0 - 0x200) / 16 + 1] =
119 {0};
Al Virod0f6eca2005-12-02 03:54:44 -0500120 unsigned long *shmems;
121 void __iomem **iomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 int numports, numshmems, *port;
123 u_long *p;
Al Virod0f6eca2005-12-02 03:54:44 -0500124 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 if (!io && !irq && !shmem && !*device && com90xx_skip_probe)
127 return;
128
Andrew Morton15901dc2006-04-01 00:49:35 -0800129 shmems = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(unsigned long),
Al Virod0f6eca2005-12-02 03:54:44 -0500130 GFP_KERNEL);
131 if (!shmems)
132 return;
Andrew Morton15901dc2006-04-01 00:49:35 -0800133 iomem = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(void __iomem *),
Al Virod0f6eca2005-12-02 03:54:44 -0500134 GFP_KERNEL);
135 if (!iomem) {
136 kfree(shmems);
137 return;
138 }
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 BUGLVL(D_NORMAL) printk(VERSION);
141
142 /* set up the arrays where we'll store the possible probe addresses */
143 numports = numshmems = 0;
144 if (io)
145 ports[numports++] = io;
146 else
147 for (count = 0x200; count <= 0x3f0; count += 16)
148 ports[numports++] = count;
149 if (shmem)
150 shmems[numshmems++] = shmem;
151 else
152 for (count = 0xA0000; count <= 0xFF800; count += 2048)
153 shmems[numshmems++] = count;
154
155 /* Stage 1: abandon any reserved ports, or ones with status==0xFF
156 * (empty), and reset any others by reading the reset port.
157 */
158 numprint = -1;
159 for (port = &ports[0]; port - ports < numports; port++) {
160 numprint++;
161 numprint %= 8;
162 if (!numprint) {
163 BUGMSG2(D_INIT, "\n");
164 BUGMSG2(D_INIT, "S1: ");
165 }
166 BUGMSG2(D_INIT, "%Xh ", *port);
167
168 ioaddr = *port;
169
170 if (!request_region(*port, ARCNET_TOTAL_SIZE, "arcnet (90xx)")) {
171 BUGMSG2(D_INIT_REASONS, "(request_region)\n");
172 BUGMSG2(D_INIT_REASONS, "S1: ");
173 BUGLVL(D_INIT_REASONS) numprint = 0;
174 *port-- = ports[--numports];
175 continue;
176 }
177 if (ASTATUS() == 0xFF) {
178 BUGMSG2(D_INIT_REASONS, "(empty)\n");
179 BUGMSG2(D_INIT_REASONS, "S1: ");
180 BUGLVL(D_INIT_REASONS) numprint = 0;
181 release_region(*port, ARCNET_TOTAL_SIZE);
182 *port-- = ports[--numports];
183 continue;
184 }
185 inb(_RESET); /* begin resetting card */
186
187 BUGMSG2(D_INIT_REASONS, "\n");
188 BUGMSG2(D_INIT_REASONS, "S1: ");
189 BUGLVL(D_INIT_REASONS) numprint = 0;
190 }
191 BUGMSG2(D_INIT, "\n");
192
193 if (!numports) {
194 BUGMSG2(D_NORMAL, "S1: No ARCnet cards found.\n");
Al Virod0f6eca2005-12-02 03:54:44 -0500195 kfree(shmems);
196 kfree(iomem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 return;
198 }
199 /* Stage 2: we have now reset any possible ARCnet cards, so we can't
200 * do anything until they finish. If D_INIT, print the list of
201 * cards that are left.
202 */
203 numprint = -1;
204 for (port = &ports[0]; port < ports + numports; port++) {
205 numprint++;
206 numprint %= 8;
207 if (!numprint) {
208 BUGMSG2(D_INIT, "\n");
209 BUGMSG2(D_INIT, "S2: ");
210 }
211 BUGMSG2(D_INIT, "%Xh ", *port);
212 }
213 BUGMSG2(D_INIT, "\n");
214 mdelay(RESETtime);
215
216 /* Stage 3: abandon any shmem addresses that don't have the signature
217 * 0xD1 byte in the right place, or are read-only.
218 */
219 numprint = -1;
Al Virod0f6eca2005-12-02 03:54:44 -0500220 for (index = 0, p = &shmems[0]; index < numshmems; p++, index++) {
221 void __iomem *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 numprint++;
224 numprint %= 8;
225 if (!numprint) {
226 BUGMSG2(D_INIT, "\n");
227 BUGMSG2(D_INIT, "S3: ");
228 }
229 BUGMSG2(D_INIT, "%lXh ", *p);
230
Al Virod0f6eca2005-12-02 03:54:44 -0500231 if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 BUGMSG2(D_INIT_REASONS, "(request_mem_region)\n");
233 BUGMSG2(D_INIT_REASONS, "Stage 3: ");
234 BUGLVL(D_INIT_REASONS) numprint = 0;
Al Virod0f6eca2005-12-02 03:54:44 -0500235 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
Al Virod0f6eca2005-12-02 03:54:44 -0500237 base = ioremap(*p, MIRROR_SIZE);
238 if (!base) {
239 BUGMSG2(D_INIT_REASONS, "(ioremap)\n");
240 BUGMSG2(D_INIT_REASONS, "Stage 3: ");
241 BUGLVL(D_INIT_REASONS) numprint = 0;
242 goto out1;
243 }
244 if (readb(base) != TESTvalue) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 BUGMSG2(D_INIT_REASONS, "(%02Xh != %02Xh)\n",
Al Virod0f6eca2005-12-02 03:54:44 -0500246 readb(base), TESTvalue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 BUGMSG2(D_INIT_REASONS, "S3: ");
248 BUGLVL(D_INIT_REASONS) numprint = 0;
Al Virod0f6eca2005-12-02 03:54:44 -0500249 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251 /* By writing 0x42 to the TESTvalue location, we also make
252 * sure no "mirror" shmem areas show up - if they occur
253 * in another pass through this loop, they will be discarded
254 * because *cptr != TESTvalue.
255 */
Al Virod0f6eca2005-12-02 03:54:44 -0500256 writeb(0x42, base);
257 if (readb(base) != 0x42) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 BUGMSG2(D_INIT_REASONS, "(read only)\n");
259 BUGMSG2(D_INIT_REASONS, "S3: ");
Al Virod0f6eca2005-12-02 03:54:44 -0500260 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
262 BUGMSG2(D_INIT_REASONS, "\n");
263 BUGMSG2(D_INIT_REASONS, "S3: ");
264 BUGLVL(D_INIT_REASONS) numprint = 0;
Al Virod0f6eca2005-12-02 03:54:44 -0500265 iomem[index] = base;
266 continue;
267 out2:
268 iounmap(base);
269 out1:
270 release_mem_region(*p, MIRROR_SIZE);
271 out:
272 *p-- = shmems[--numshmems];
273 index--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
275 BUGMSG2(D_INIT, "\n");
276
277 if (!numshmems) {
278 BUGMSG2(D_NORMAL, "S3: No ARCnet cards found.\n");
279 for (port = &ports[0]; port < ports + numports; port++)
280 release_region(*port, ARCNET_TOTAL_SIZE);
Al Virod0f6eca2005-12-02 03:54:44 -0500281 kfree(shmems);
282 kfree(iomem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return;
284 }
285 /* Stage 4: something of a dummy, to report the shmems that are
286 * still possible after stage 3.
287 */
288 numprint = -1;
289 for (p = &shmems[0]; p < shmems + numshmems; p++) {
290 numprint++;
291 numprint %= 8;
292 if (!numprint) {
293 BUGMSG2(D_INIT, "\n");
294 BUGMSG2(D_INIT, "S4: ");
295 }
296 BUGMSG2(D_INIT, "%lXh ", *p);
297 }
298 BUGMSG2(D_INIT, "\n");
299
300 /* Stage 5: for any ports that have the correct status, can disable
301 * the RESET flag, and (if no irq is given) generate an autoirq,
302 * register an ARCnet device.
303 *
304 * Currently, we can only register one device per probe, so quit
305 * after the first one is found.
306 */
307 numprint = -1;
308 for (port = &ports[0]; port < ports + numports; port++) {
309 int found = 0;
310 numprint++;
311 numprint %= 8;
312 if (!numprint) {
313 BUGMSG2(D_INIT, "\n");
314 BUGMSG2(D_INIT, "S5: ");
315 }
316 BUGMSG2(D_INIT, "%Xh ", *port);
317
318 ioaddr = *port;
319 status = ASTATUS();
320
321 if ((status & 0x9D)
322 != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
323 BUGMSG2(D_INIT_REASONS, "(status=%Xh)\n", status);
324 BUGMSG2(D_INIT_REASONS, "S5: ");
325 BUGLVL(D_INIT_REASONS) numprint = 0;
326 release_region(*port, ARCNET_TOTAL_SIZE);
327 *port-- = ports[--numports];
328 continue;
329 }
330 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
331 status = ASTATUS();
332 if (status & RESETflag) {
333 BUGMSG2(D_INIT_REASONS, " (eternal reset, status=%Xh)\n",
334 status);
335 BUGMSG2(D_INIT_REASONS, "S5: ");
336 BUGLVL(D_INIT_REASONS) numprint = 0;
337 release_region(*port, ARCNET_TOTAL_SIZE);
338 *port-- = ports[--numports];
339 continue;
340 }
341 /* skip this completely if an IRQ was given, because maybe
342 * we're on a machine that locks during autoirq!
343 */
344 if (!irq) {
345 /* if we do this, we're sure to get an IRQ since the
346 * card has just reset and the NORXflag is on until
347 * we tell it to start receiving.
348 */
349 airqmask = probe_irq_on();
350 AINTMASK(NORXflag);
351 udelay(1);
352 AINTMASK(0);
353 airq = probe_irq_off(airqmask);
354
355 if (airq <= 0) {
356 BUGMSG2(D_INIT_REASONS, "(airq=%d)\n", airq);
357 BUGMSG2(D_INIT_REASONS, "S5: ");
358 BUGLVL(D_INIT_REASONS) numprint = 0;
359 release_region(*port, ARCNET_TOTAL_SIZE);
360 *port-- = ports[--numports];
361 continue;
362 }
363 } else {
364 airq = irq;
365 }
366
367 BUGMSG2(D_INIT, "(%d,", airq);
368 openparen = 1;
369
370 /* Everything seems okay. But which shmem, if any, puts
371 * back its signature byte when the card is reset?
372 *
373 * If there are multiple cards installed, there might be
374 * multiple shmems still in the list.
375 */
376#ifdef FAST_PROBE
377 if (numports > 1 || numshmems > 1) {
378 inb(_RESET);
379 mdelay(RESETtime);
380 } else {
381 /* just one shmem and port, assume they match */
Al Virod0f6eca2005-12-02 03:54:44 -0500382 writeb(TESTvalue, iomem[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
384#else
385 inb(_RESET);
386 mdelay(RESETtime);
387#endif
388
Al Virod0f6eca2005-12-02 03:54:44 -0500389 for (index = 0; index < numshmems; index++) {
390 u_long ptr = shmems[index];
391 void __iomem *base = iomem[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Al Virod0f6eca2005-12-02 03:54:44 -0500393 if (readb(base) == TESTvalue) { /* found one */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 BUGMSG2(D_INIT, "%lXh)\n", *p);
395 openparen = 0;
396
397 /* register the card */
Al Virod0f6eca2005-12-02 03:54:44 -0500398 if (com90xx_found(*port, airq, ptr, base) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 found = 1;
400 numprint = -1;
401
402 /* remove shmem from the list */
Al Virod0f6eca2005-12-02 03:54:44 -0500403 shmems[index] = shmems[--numshmems];
404 iomem[index] = iomem[numshmems];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 break; /* go to the next I/O port */
406 } else {
Al Virod0f6eca2005-12-02 03:54:44 -0500407 BUGMSG2(D_INIT_REASONS, "%Xh-", readb(base));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 }
409 }
410
411 if (openparen) {
412 BUGLVL(D_INIT) printk("no matching shmem)\n");
413 BUGLVL(D_INIT_REASONS) printk("S5: ");
414 BUGLVL(D_INIT_REASONS) numprint = 0;
415 }
416 if (!found)
417 release_region(*port, ARCNET_TOTAL_SIZE);
418 *port-- = ports[--numports];
419 }
420
421 BUGLVL(D_INIT_REASONS) printk("\n");
422
423 /* Now put back TESTvalue on all leftover shmems. */
Al Virod0f6eca2005-12-02 03:54:44 -0500424 for (index = 0; index < numshmems; index++) {
425 writeb(TESTvalue, iomem[index]);
426 iounmap(iomem[index]);
427 release_mem_region(shmems[index], MIRROR_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
Al Virod0f6eca2005-12-02 03:54:44 -0500429 kfree(shmems);
430 kfree(iomem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Al Virod0f6eca2005-12-02 03:54:44 -0500433static int check_mirror(unsigned long addr, size_t size)
434{
435 void __iomem *p;
436 int res = -1;
437
438 if (!request_mem_region(addr, size, "arcnet (90xx)"))
439 return -1;
440
441 p = ioremap(addr, size);
442 if (p) {
443 if (readb(p) == TESTvalue)
444 res = 1;
445 else
446 res = 0;
447 iounmap(p);
448 }
449
450 release_mem_region(addr, size);
451 return res;
452}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454/* Set up the struct net_device associated with this card. Called after
455 * probing succeeds.
456 */
Al Virod0f6eca2005-12-02 03:54:44 -0500457static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
459 struct net_device *dev = NULL;
460 struct arcnet_local *lp;
461 u_long first_mirror, last_mirror;
462 int mirror_size;
463
464 /* allocate struct net_device */
465 dev = alloc_arcdev(device);
466 if (!dev) {
467 BUGMSG2(D_NORMAL, "com90xx: Can't allocate device!\n");
Al Virod0f6eca2005-12-02 03:54:44 -0500468 iounmap(p);
469 release_mem_region(shmem, MIRROR_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return -ENOMEM;
471 }
Wang Chen454d7c92008-11-12 23:37:49 -0800472 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 /* find the real shared memory start/end points, including mirrors */
474
475 /* guess the actual size of one "memory mirror" - the number of
476 * bytes between copies of the shared memory. On most cards, it's
477 * 2k (or there are no mirrors at all) but on some, it's 4k.
478 */
479 mirror_size = MIRROR_SIZE;
Al Virod0f6eca2005-12-02 03:54:44 -0500480 if (readb(p) == TESTvalue &&
481 check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
482 check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
483 mirror_size = 2 * MIRROR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Al Virod0f6eca2005-12-02 03:54:44 -0500485 first_mirror = shmem - mirror_size;
486 while (check_mirror(first_mirror, mirror_size) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 first_mirror -= mirror_size;
488 first_mirror += mirror_size;
489
Al Virod0f6eca2005-12-02 03:54:44 -0500490 last_mirror = shmem + mirror_size;
491 while (check_mirror(last_mirror, mirror_size) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 last_mirror += mirror_size;
493 last_mirror -= mirror_size;
494
495 dev->mem_start = first_mirror;
496 dev->mem_end = last_mirror + MIRROR_SIZE - 1;
497
Al Virod0f6eca2005-12-02 03:54:44 -0500498 iounmap(p);
499 release_mem_region(shmem, MIRROR_SIZE);
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 if (!request_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1, "arcnet (90xx)"))
502 goto err_free_dev;
503
504 /* reserve the irq */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800505 if (request_irq(airq, arcnet_interrupt, 0, "arcnet (90xx)", dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", airq);
507 goto err_release_mem;
508 }
509 dev->irq = airq;
510
511 /* Initialize the rest of the device structure. */
512 lp->card_name = "COM90xx";
513 lp->hw.command = com90xx_command;
514 lp->hw.status = com90xx_status;
515 lp->hw.intmask = com90xx_setmask;
516 lp->hw.reset = com90xx_reset;
517 lp->hw.owner = THIS_MODULE;
518 lp->hw.copy_to_card = com90xx_copy_to_card;
519 lp->hw.copy_from_card = com90xx_copy_from_card;
520 lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1);
521 if (!lp->mem_start) {
522 BUGMSG(D_NORMAL, "Can't remap device memory!\n");
523 goto err_free_irq;
524 }
525
526 /* get and check the station ID from offset 1 in shmem */
527 dev->dev_addr[0] = readb(lp->mem_start + 1);
528
529 dev->base_addr = ioaddr;
530
531 BUGMSG(D_NORMAL, "COM90xx station %02Xh found at %03lXh, IRQ %d, "
532 "ShMem %lXh (%ld*%xh).\n",
533 dev->dev_addr[0],
534 dev->base_addr, dev->irq, dev->mem_start,
535 (dev->mem_end - dev->mem_start + 1) / mirror_size, mirror_size);
536
537 if (register_netdev(dev))
538 goto err_unmap;
539
540 cards[numcards++] = dev;
541 return 0;
542
543err_unmap:
544 iounmap(lp->mem_start);
545err_free_irq:
546 free_irq(dev->irq, dev);
547err_release_mem:
548 release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
549err_free_dev:
550 free_netdev(dev);
551 return -EIO;
552}
553
554
555static void com90xx_command(struct net_device *dev, int cmd)
556{
557 short ioaddr = dev->base_addr;
558
559 ACOMMAND(cmd);
560}
561
562
563static int com90xx_status(struct net_device *dev)
564{
565 short ioaddr = dev->base_addr;
566
567 return ASTATUS();
568}
569
570
571static void com90xx_setmask(struct net_device *dev, int mask)
572{
573 short ioaddr = dev->base_addr;
574
575 AINTMASK(mask);
576}
577
578
579/*
580 * Do a hardware reset on the card, and set up necessary registers.
581 *
582 * This should be called as little as possible, because it disrupts the
583 * token on the network (causes a RECON) and requires a significant delay.
584 *
585 * However, it does make sure the card is in a defined state.
586 */
Hannes Eder888432f2008-12-25 23:57:21 -0800587static int com90xx_reset(struct net_device *dev, int really_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588{
Wang Chen454d7c92008-11-12 23:37:49 -0800589 struct arcnet_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 short ioaddr = dev->base_addr;
591
592 BUGMSG(D_INIT, "Resetting (status=%02Xh)\n", ASTATUS());
593
594 if (really_reset) {
595 /* reset the card */
596 inb(_RESET);
597 mdelay(RESETtime);
598 }
599 ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
600 ACOMMAND(CFLAGScmd | CONFIGclear);
601
602 /* don't do this until we verify that it doesn't hurt older cards! */
603 /* outb(inb(_CONFIG) | ENABLE16flag, _CONFIG); */
604
605 /* verify that the ARCnet signature byte is present */
606 if (readb(lp->mem_start) != TESTvalue) {
607 if (really_reset)
608 BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n");
609 return 1;
610 }
611 /* enable extended (512-byte) packets */
612 ACOMMAND(CONFIGcmd | EXTconf);
613
614 /* clean out all the memory to make debugging make more sense :) */
615 BUGLVL(D_DURING)
616 memset_io(lp->mem_start, 0x42, 2048);
617
618 /* done! return success. */
619 return 0;
620}
621
622static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
623 void *buf, int count)
624{
Wang Chen454d7c92008-11-12 23:37:49 -0800625 struct arcnet_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
627 TIME("memcpy_toio", count, memcpy_toio(memaddr, buf, count));
628}
629
630
631static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset,
632 void *buf, int count)
633{
Wang Chen454d7c92008-11-12 23:37:49 -0800634 struct arcnet_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
636 TIME("memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
637}
638
639
640MODULE_LICENSE("GPL");
641
642static int __init com90xx_init(void)
643{
644 if (irq == 2)
645 irq = 9;
646 com90xx_probe();
647 if (!numcards)
648 return -EIO;
649 return 0;
650}
651
652static void __exit com90xx_exit(void)
653{
654 struct net_device *dev;
655 struct arcnet_local *lp;
656 int count;
657
658 for (count = 0; count < numcards; count++) {
659 dev = cards[count];
Wang Chen454d7c92008-11-12 23:37:49 -0800660 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 unregister_netdev(dev);
663 free_irq(dev->irq, dev);
664 iounmap(lp->mem_start);
665 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
666 release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
667 free_netdev(dev);
668 }
669}
670
671module_init(com90xx_init);
672module_exit(com90xx_exit);
673
674#ifndef MODULE
675static int __init com90xx_setup(char *s)
676{
677 int ints[8];
678
679 s = get_options(s, 8, ints);
680 if (!ints[0] && !*s) {
681 printk("com90xx: Disabled.\n");
682 return 1;
683 }
684
685 switch (ints[0]) {
686 default: /* ERROR */
687 printk("com90xx: Too many arguments.\n");
688 case 3: /* Mem address */
689 shmem = ints[3];
690 case 2: /* IRQ */
691 irq = ints[2];
692 case 1: /* IO address */
693 io = ints[1];
694 }
695
696 if (*s)
697 snprintf(device, sizeof(device), "%s", s);
698
699 return 1;
700}
701
702__setup("com90xx=", com90xx_setup);
703#endif