blob: 4781cd696dd1327354d150edd45c5fc0281fb476 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Linux ARCnet driver - COM90xx chipset (memory-mapped buffers)
Joe Perchescb334642015-05-05 10:05:47 -07003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000030#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/ioport.h>
32#include <linux/delay.h>
33#include <linux/netdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Joe Perches5e7ef912015-05-05 10:05:51 -070035#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/arcdevice.h>
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define VERSION "arcnet: COM90xx chipset support\n"
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/* Internal function declarations */
Al Virod0f6eca2005-12-02 03:54:44 -050055static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static void com90xx_command(struct net_device *dev, int command);
57static int com90xx_status(struct net_device *dev);
58static void com90xx_setmask(struct net_device *dev, int mask);
59static int com90xx_reset(struct net_device *dev, int really_reset);
60static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
61 void *buf, int count);
62static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset,
63 void *buf, int count);
64
65/* Known ARCnet cards */
66
67static struct net_device *cards[16];
68static int numcards;
69
70/* Handy defines for ARCnet specific stuff */
71
72/* The number of low I/O ports used by the card */
73#define ARCNET_TOTAL_SIZE 16
74
75/* Amount of I/O memory used by the card */
76#define BUFFER_SIZE (512)
Joe Perchescb334642015-05-05 10:05:47 -070077#define MIRROR_SIZE (BUFFER_SIZE * 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/* COM 9026 controller chip --> ARCnet register addresses */
Joe Perchescb334642015-05-05 10:05:47 -070080#define _INTMASK (ioaddr + 0) /* writable */
81#define _STATUS (ioaddr + 0) /* readable */
82#define _COMMAND (ioaddr + 1) /* writable, returns random vals on read (?) */
83#define _CONFIG (ioaddr + 2) /* Configuration register */
84#define _RESET (ioaddr + 8) /* software reset (on read) */
85#define _MEMDATA (ioaddr + 12) /* Data port for IO-mapped memory */
86#define _ADDR_HI (ioaddr + 15) /* Control registers for said */
87#define _ADDR_LO (ioaddr + 14)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#undef ASTATUS
90#undef ACOMMAND
91#undef AINTMASK
92
93#define ASTATUS() inb(_STATUS)
Joe Perchescb334642015-05-05 10:05:47 -070094#define ACOMMAND(cmd) outb((cmd), _COMMAND)
95#define AINTMASK(msk) outb((msk), _INTMASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static int com90xx_skip_probe __initdata = 0;
98
99/* Module parameters */
100
101static int io; /* use the insmod io= irq= shmem= options */
102static int irq;
103static int shmem;
104static char device[9]; /* use eg. device=arc1 to change name */
105
106module_param(io, int, 0);
107module_param(irq, int, 0);
108module_param(shmem, int, 0);
109module_param_string(device, device, sizeof(device), 0);
110
111static void __init com90xx_probe(void)
112{
113 int count, status, ioaddr, numprint, airq, openparen = 0;
114 unsigned long airqmask;
Joe Perches7f5e7602015-05-05 10:05:49 -0700115 int ports[(0x3f0 - 0x200) / 16 + 1] = { 0 };
Al Virod0f6eca2005-12-02 03:54:44 -0500116 unsigned long *shmems;
117 void __iomem **iomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 int numports, numshmems, *port;
119 u_long *p;
Al Virod0f6eca2005-12-02 03:54:44 -0500120 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 if (!io && !irq && !shmem && !*device && com90xx_skip_probe)
123 return;
124
Joe Perchescb334642015-05-05 10:05:47 -0700125 shmems = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(unsigned long),
Al Virod0f6eca2005-12-02 03:54:44 -0500126 GFP_KERNEL);
127 if (!shmems)
128 return;
Joe Perchescb334642015-05-05 10:05:47 -0700129 iomem = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(void __iomem *),
130 GFP_KERNEL);
Al Virod0f6eca2005-12-02 03:54:44 -0500131 if (!iomem) {
132 kfree(shmems);
133 return;
134 }
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 BUGLVL(D_NORMAL) printk(VERSION);
137
138 /* set up the arrays where we'll store the possible probe addresses */
139 numports = numshmems = 0;
140 if (io)
141 ports[numports++] = io;
142 else
143 for (count = 0x200; count <= 0x3f0; count += 16)
144 ports[numports++] = count;
145 if (shmem)
146 shmems[numshmems++] = shmem;
147 else
148 for (count = 0xA0000; count <= 0xFF800; count += 2048)
149 shmems[numshmems++] = count;
150
151 /* Stage 1: abandon any reserved ports, or ones with status==0xFF
152 * (empty), and reset any others by reading the reset port.
153 */
154 numprint = -1;
155 for (port = &ports[0]; port - ports < numports; port++) {
156 numprint++;
157 numprint %= 8;
158 if (!numprint) {
159 BUGMSG2(D_INIT, "\n");
160 BUGMSG2(D_INIT, "S1: ");
161 }
162 BUGMSG2(D_INIT, "%Xh ", *port);
163
164 ioaddr = *port;
165
166 if (!request_region(*port, ARCNET_TOTAL_SIZE, "arcnet (90xx)")) {
167 BUGMSG2(D_INIT_REASONS, "(request_region)\n");
168 BUGMSG2(D_INIT_REASONS, "S1: ");
169 BUGLVL(D_INIT_REASONS) numprint = 0;
170 *port-- = ports[--numports];
171 continue;
172 }
173 if (ASTATUS() == 0xFF) {
174 BUGMSG2(D_INIT_REASONS, "(empty)\n");
175 BUGMSG2(D_INIT_REASONS, "S1: ");
176 BUGLVL(D_INIT_REASONS) numprint = 0;
177 release_region(*port, ARCNET_TOTAL_SIZE);
178 *port-- = ports[--numports];
179 continue;
180 }
181 inb(_RESET); /* begin resetting card */
182
183 BUGMSG2(D_INIT_REASONS, "\n");
184 BUGMSG2(D_INIT_REASONS, "S1: ");
185 BUGLVL(D_INIT_REASONS) numprint = 0;
186 }
187 BUGMSG2(D_INIT, "\n");
188
189 if (!numports) {
190 BUGMSG2(D_NORMAL, "S1: No ARCnet cards found.\n");
Al Virod0f6eca2005-12-02 03:54:44 -0500191 kfree(shmems);
192 kfree(iomem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return;
194 }
195 /* Stage 2: we have now reset any possible ARCnet cards, so we can't
196 * do anything until they finish. If D_INIT, print the list of
197 * cards that are left.
198 */
199 numprint = -1;
200 for (port = &ports[0]; port < ports + numports; port++) {
201 numprint++;
202 numprint %= 8;
203 if (!numprint) {
204 BUGMSG2(D_INIT, "\n");
205 BUGMSG2(D_INIT, "S2: ");
206 }
207 BUGMSG2(D_INIT, "%Xh ", *port);
208 }
209 BUGMSG2(D_INIT, "\n");
210 mdelay(RESETtime);
211
212 /* Stage 3: abandon any shmem addresses that don't have the signature
213 * 0xD1 byte in the right place, or are read-only.
214 */
215 numprint = -1;
Al Virod0f6eca2005-12-02 03:54:44 -0500216 for (index = 0, p = &shmems[0]; index < numshmems; p++, index++) {
217 void __iomem *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 numprint++;
220 numprint %= 8;
221 if (!numprint) {
222 BUGMSG2(D_INIT, "\n");
223 BUGMSG2(D_INIT, "S3: ");
224 }
225 BUGMSG2(D_INIT, "%lXh ", *p);
226
Al Virod0f6eca2005-12-02 03:54:44 -0500227 if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 BUGMSG2(D_INIT_REASONS, "(request_mem_region)\n");
229 BUGMSG2(D_INIT_REASONS, "Stage 3: ");
230 BUGLVL(D_INIT_REASONS) numprint = 0;
Al Virod0f6eca2005-12-02 03:54:44 -0500231 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
Al Virod0f6eca2005-12-02 03:54:44 -0500233 base = ioremap(*p, MIRROR_SIZE);
234 if (!base) {
235 BUGMSG2(D_INIT_REASONS, "(ioremap)\n");
236 BUGMSG2(D_INIT_REASONS, "Stage 3: ");
237 BUGLVL(D_INIT_REASONS) numprint = 0;
238 goto out1;
239 }
240 if (readb(base) != TESTvalue) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 BUGMSG2(D_INIT_REASONS, "(%02Xh != %02Xh)\n",
Al Virod0f6eca2005-12-02 03:54:44 -0500242 readb(base), TESTvalue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 BUGMSG2(D_INIT_REASONS, "S3: ");
244 BUGLVL(D_INIT_REASONS) numprint = 0;
Al Virod0f6eca2005-12-02 03:54:44 -0500245 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247 /* By writing 0x42 to the TESTvalue location, we also make
248 * sure no "mirror" shmem areas show up - if they occur
249 * in another pass through this loop, they will be discarded
250 * because *cptr != TESTvalue.
251 */
Al Virod0f6eca2005-12-02 03:54:44 -0500252 writeb(0x42, base);
253 if (readb(base) != 0x42) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 BUGMSG2(D_INIT_REASONS, "(read only)\n");
255 BUGMSG2(D_INIT_REASONS, "S3: ");
Al Virod0f6eca2005-12-02 03:54:44 -0500256 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258 BUGMSG2(D_INIT_REASONS, "\n");
259 BUGMSG2(D_INIT_REASONS, "S3: ");
260 BUGLVL(D_INIT_REASONS) numprint = 0;
Al Virod0f6eca2005-12-02 03:54:44 -0500261 iomem[index] = base;
262 continue;
263 out2:
264 iounmap(base);
265 out1:
266 release_mem_region(*p, MIRROR_SIZE);
267 out:
268 *p-- = shmems[--numshmems];
269 index--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271 BUGMSG2(D_INIT, "\n");
272
273 if (!numshmems) {
274 BUGMSG2(D_NORMAL, "S3: No ARCnet cards found.\n");
275 for (port = &ports[0]; port < ports + numports; port++)
276 release_region(*port, ARCNET_TOTAL_SIZE);
Al Virod0f6eca2005-12-02 03:54:44 -0500277 kfree(shmems);
278 kfree(iomem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 return;
280 }
281 /* Stage 4: something of a dummy, to report the shmems that are
282 * still possible after stage 3.
283 */
284 numprint = -1;
285 for (p = &shmems[0]; p < shmems + numshmems; p++) {
286 numprint++;
287 numprint %= 8;
288 if (!numprint) {
289 BUGMSG2(D_INIT, "\n");
290 BUGMSG2(D_INIT, "S4: ");
291 }
292 BUGMSG2(D_INIT, "%lXh ", *p);
293 }
294 BUGMSG2(D_INIT, "\n");
295
296 /* Stage 5: for any ports that have the correct status, can disable
297 * the RESET flag, and (if no irq is given) generate an autoirq,
298 * register an ARCnet device.
299 *
300 * Currently, we can only register one device per probe, so quit
301 * after the first one is found.
302 */
303 numprint = -1;
304 for (port = &ports[0]; port < ports + numports; port++) {
305 int found = 0;
Joe Perches01a1d5a2015-05-05 10:05:48 -0700306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 numprint++;
308 numprint %= 8;
309 if (!numprint) {
310 BUGMSG2(D_INIT, "\n");
311 BUGMSG2(D_INIT, "S5: ");
312 }
313 BUGMSG2(D_INIT, "%Xh ", *port);
314
315 ioaddr = *port;
316 status = ASTATUS();
317
318 if ((status & 0x9D)
319 != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
320 BUGMSG2(D_INIT_REASONS, "(status=%Xh)\n", status);
321 BUGMSG2(D_INIT_REASONS, "S5: ");
322 BUGLVL(D_INIT_REASONS) numprint = 0;
323 release_region(*port, ARCNET_TOTAL_SIZE);
324 *port-- = ports[--numports];
325 continue;
326 }
327 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
328 status = ASTATUS();
329 if (status & RESETflag) {
330 BUGMSG2(D_INIT_REASONS, " (eternal reset, status=%Xh)\n",
331 status);
332 BUGMSG2(D_INIT_REASONS, "S5: ");
333 BUGLVL(D_INIT_REASONS) numprint = 0;
334 release_region(*port, ARCNET_TOTAL_SIZE);
335 *port-- = ports[--numports];
336 continue;
337 }
338 /* skip this completely if an IRQ was given, because maybe
339 * we're on a machine that locks during autoirq!
340 */
341 if (!irq) {
342 /* if we do this, we're sure to get an IRQ since the
343 * card has just reset and the NORXflag is on until
344 * we tell it to start receiving.
345 */
346 airqmask = probe_irq_on();
347 AINTMASK(NORXflag);
348 udelay(1);
349 AINTMASK(0);
350 airq = probe_irq_off(airqmask);
351
352 if (airq <= 0) {
353 BUGMSG2(D_INIT_REASONS, "(airq=%d)\n", airq);
354 BUGMSG2(D_INIT_REASONS, "S5: ");
355 BUGLVL(D_INIT_REASONS) numprint = 0;
356 release_region(*port, ARCNET_TOTAL_SIZE);
357 *port-- = ports[--numports];
358 continue;
359 }
360 } else {
361 airq = irq;
362 }
363
364 BUGMSG2(D_INIT, "(%d,", airq);
365 openparen = 1;
366
367 /* Everything seems okay. But which shmem, if any, puts
368 * back its signature byte when the card is reset?
369 *
370 * If there are multiple cards installed, there might be
371 * multiple shmems still in the list.
372 */
373#ifdef FAST_PROBE
374 if (numports > 1 || numshmems > 1) {
375 inb(_RESET);
376 mdelay(RESETtime);
377 } else {
378 /* just one shmem and port, assume they match */
Al Virod0f6eca2005-12-02 03:54:44 -0500379 writeb(TESTvalue, iomem[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
381#else
382 inb(_RESET);
383 mdelay(RESETtime);
384#endif
385
Al Virod0f6eca2005-12-02 03:54:44 -0500386 for (index = 0; index < numshmems; index++) {
387 u_long ptr = shmems[index];
388 void __iomem *base = iomem[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Al Virod0f6eca2005-12-02 03:54:44 -0500390 if (readb(base) == TESTvalue) { /* found one */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 BUGMSG2(D_INIT, "%lXh)\n", *p);
392 openparen = 0;
393
394 /* register the card */
Al Virod0f6eca2005-12-02 03:54:44 -0500395 if (com90xx_found(*port, airq, ptr, base) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 found = 1;
397 numprint = -1;
398
399 /* remove shmem from the list */
Al Virod0f6eca2005-12-02 03:54:44 -0500400 shmems[index] = shmems[--numshmems];
401 iomem[index] = iomem[numshmems];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 break; /* go to the next I/O port */
403 } else {
Al Virod0f6eca2005-12-02 03:54:44 -0500404 BUGMSG2(D_INIT_REASONS, "%Xh-", readb(base));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 }
406 }
407
408 if (openparen) {
409 BUGLVL(D_INIT) printk("no matching shmem)\n");
410 BUGLVL(D_INIT_REASONS) printk("S5: ");
411 BUGLVL(D_INIT_REASONS) numprint = 0;
412 }
413 if (!found)
414 release_region(*port, ARCNET_TOTAL_SIZE);
415 *port-- = ports[--numports];
416 }
417
418 BUGLVL(D_INIT_REASONS) printk("\n");
419
420 /* Now put back TESTvalue on all leftover shmems. */
Al Virod0f6eca2005-12-02 03:54:44 -0500421 for (index = 0; index < numshmems; index++) {
422 writeb(TESTvalue, iomem[index]);
423 iounmap(iomem[index]);
424 release_mem_region(shmems[index], MIRROR_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
Al Virod0f6eca2005-12-02 03:54:44 -0500426 kfree(shmems);
427 kfree(iomem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
Al Virod0f6eca2005-12-02 03:54:44 -0500430static int check_mirror(unsigned long addr, size_t size)
431{
432 void __iomem *p;
433 int res = -1;
434
435 if (!request_mem_region(addr, size, "arcnet (90xx)"))
436 return -1;
437
438 p = ioremap(addr, size);
439 if (p) {
440 if (readb(p) == TESTvalue)
441 res = 1;
442 else
443 res = 0;
444 iounmap(p);
445 }
446
447 release_mem_region(addr, size);
448 return res;
449}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451/* Set up the struct net_device associated with this card. Called after
452 * probing succeeds.
453 */
Al Virod0f6eca2005-12-02 03:54:44 -0500454static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 struct net_device *dev = NULL;
457 struct arcnet_local *lp;
458 u_long first_mirror, last_mirror;
459 int mirror_size;
460
461 /* allocate struct net_device */
462 dev = alloc_arcdev(device);
463 if (!dev) {
464 BUGMSG2(D_NORMAL, "com90xx: Can't allocate device!\n");
Al Virod0f6eca2005-12-02 03:54:44 -0500465 iounmap(p);
466 release_mem_region(shmem, MIRROR_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return -ENOMEM;
468 }
Wang Chen454d7c92008-11-12 23:37:49 -0800469 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 /* find the real shared memory start/end points, including mirrors */
471
472 /* guess the actual size of one "memory mirror" - the number of
473 * bytes between copies of the shared memory. On most cards, it's
474 * 2k (or there are no mirrors at all) but on some, it's 4k.
475 */
476 mirror_size = MIRROR_SIZE;
Al Virod0f6eca2005-12-02 03:54:44 -0500477 if (readb(p) == TESTvalue &&
478 check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
479 check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
480 mirror_size = 2 * MIRROR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Al Virod0f6eca2005-12-02 03:54:44 -0500482 first_mirror = shmem - mirror_size;
483 while (check_mirror(first_mirror, mirror_size) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 first_mirror -= mirror_size;
485 first_mirror += mirror_size;
486
Al Virod0f6eca2005-12-02 03:54:44 -0500487 last_mirror = shmem + mirror_size;
488 while (check_mirror(last_mirror, mirror_size) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 last_mirror += mirror_size;
490 last_mirror -= mirror_size;
491
492 dev->mem_start = first_mirror;
493 dev->mem_end = last_mirror + MIRROR_SIZE - 1;
494
Al Virod0f6eca2005-12-02 03:54:44 -0500495 iounmap(p);
496 release_mem_region(shmem, MIRROR_SIZE);
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if (!request_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1, "arcnet (90xx)"))
499 goto err_free_dev;
500
501 /* reserve the irq */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800502 if (request_irq(airq, arcnet_interrupt, 0, "arcnet (90xx)", dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", airq);
504 goto err_release_mem;
505 }
506 dev->irq = airq;
507
508 /* Initialize the rest of the device structure. */
509 lp->card_name = "COM90xx";
510 lp->hw.command = com90xx_command;
511 lp->hw.status = com90xx_status;
512 lp->hw.intmask = com90xx_setmask;
513 lp->hw.reset = com90xx_reset;
514 lp->hw.owner = THIS_MODULE;
515 lp->hw.copy_to_card = com90xx_copy_to_card;
516 lp->hw.copy_from_card = com90xx_copy_from_card;
517 lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1);
518 if (!lp->mem_start) {
519 BUGMSG(D_NORMAL, "Can't remap device memory!\n");
520 goto err_free_irq;
521 }
522
523 /* get and check the station ID from offset 1 in shmem */
524 dev->dev_addr[0] = readb(lp->mem_start + 1);
525
526 dev->base_addr = ioaddr;
527
Joe Perches3b4e5552015-05-05 10:05:50 -0700528 BUGMSG(D_NORMAL, "COM90xx station %02Xh found at %03lXh, IRQ %d, ShMem %lXh (%ld*%xh).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 dev->dev_addr[0],
530 dev->base_addr, dev->irq, dev->mem_start,
531 (dev->mem_end - dev->mem_start + 1) / mirror_size, mirror_size);
532
533 if (register_netdev(dev))
534 goto err_unmap;
535
536 cards[numcards++] = dev;
537 return 0;
538
539err_unmap:
540 iounmap(lp->mem_start);
541err_free_irq:
542 free_irq(dev->irq, dev);
543err_release_mem:
544 release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
545err_free_dev:
546 free_netdev(dev);
547 return -EIO;
548}
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550static void com90xx_command(struct net_device *dev, int cmd)
551{
552 short ioaddr = dev->base_addr;
553
554 ACOMMAND(cmd);
555}
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557static int com90xx_status(struct net_device *dev)
558{
559 short ioaddr = dev->base_addr;
560
561 return ASTATUS();
562}
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564static void com90xx_setmask(struct net_device *dev, int mask)
565{
566 short ioaddr = dev->base_addr;
567
568 AINTMASK(mask);
569}
570
Joe Perchesf2f0a162015-05-05 10:05:52 -0700571/* Do a hardware reset on the card, and set up necessary registers.
Joe Perchescb334642015-05-05 10:05:47 -0700572 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 * This should be called as little as possible, because it disrupts the
574 * token on the network (causes a RECON) and requires a significant delay.
575 *
576 * However, it does make sure the card is in a defined state.
577 */
Hannes Eder888432f2008-12-25 23:57:21 -0800578static int com90xx_reset(struct net_device *dev, int really_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Wang Chen454d7c92008-11-12 23:37:49 -0800580 struct arcnet_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 short ioaddr = dev->base_addr;
582
583 BUGMSG(D_INIT, "Resetting (status=%02Xh)\n", ASTATUS());
584
585 if (really_reset) {
586 /* reset the card */
587 inb(_RESET);
588 mdelay(RESETtime);
589 }
590 ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
591 ACOMMAND(CFLAGScmd | CONFIGclear);
592
593 /* don't do this until we verify that it doesn't hurt older cards! */
594 /* outb(inb(_CONFIG) | ENABLE16flag, _CONFIG); */
595
596 /* verify that the ARCnet signature byte is present */
597 if (readb(lp->mem_start) != TESTvalue) {
598 if (really_reset)
599 BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n");
600 return 1;
601 }
602 /* enable extended (512-byte) packets */
603 ACOMMAND(CONFIGcmd | EXTconf);
604
605 /* clean out all the memory to make debugging make more sense :) */
606 BUGLVL(D_DURING)
607 memset_io(lp->mem_start, 0x42, 2048);
608
609 /* done! return success. */
610 return 0;
611}
612
613static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
614 void *buf, int count)
615{
Wang Chen454d7c92008-11-12 23:37:49 -0800616 struct arcnet_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
Joe Perches01a1d5a2015-05-05 10:05:48 -0700618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 TIME("memcpy_toio", count, memcpy_toio(memaddr, buf, count));
620}
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622static void com90xx_copy_from_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;
Joe Perches01a1d5a2015-05-05 10:05:48 -0700627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 TIME("memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
629}
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631MODULE_LICENSE("GPL");
632
633static int __init com90xx_init(void)
634{
635 if (irq == 2)
636 irq = 9;
637 com90xx_probe();
638 if (!numcards)
639 return -EIO;
640 return 0;
641}
642
643static void __exit com90xx_exit(void)
644{
645 struct net_device *dev;
646 struct arcnet_local *lp;
647 int count;
648
649 for (count = 0; count < numcards; count++) {
650 dev = cards[count];
Wang Chen454d7c92008-11-12 23:37:49 -0800651 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 unregister_netdev(dev);
654 free_irq(dev->irq, dev);
655 iounmap(lp->mem_start);
656 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
657 release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
658 free_netdev(dev);
659 }
660}
661
662module_init(com90xx_init);
663module_exit(com90xx_exit);
664
665#ifndef MODULE
666static int __init com90xx_setup(char *s)
667{
668 int ints[8];
669
670 s = get_options(s, 8, ints);
671 if (!ints[0] && !*s) {
672 printk("com90xx: Disabled.\n");
673 return 1;
674 }
675
676 switch (ints[0]) {
677 default: /* ERROR */
678 printk("com90xx: Too many arguments.\n");
679 case 3: /* Mem address */
680 shmem = ints[3];
681 case 2: /* IRQ */
682 irq = ints[2];
683 case 1: /* IO address */
684 io = ints[1];
685 }
686
687 if (*s)
688 snprintf(device, sizeof(device), "%s", s);
689
690 return 1;
691}
692
693__setup("com90xx=", com90xx_setup);
694#endif