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