2 * Linux ARCnet driver - "RIM I" (entirely mem-mapped) cards
4 * Written 1994-1999 by Avery Pennarun.
5 * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
6 * Derived from skeleton.c by Donald Becker.
8 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
9 * for sponsoring the further development of this driver.
11 * **********************
13 * The original copyright of skeleton.c was as follows:
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.
21 * **********************
23 * For more details, see drivers/net/arcnet.c
25 * **********************
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/moduleparam.h>
30 #include <linux/ioport.h>
31 #include <linux/slab.h>
32 #include <linux/delay.h>
33 #include <linux/netdevice.h>
34 #include <linux/bootmem.h>
35 #include <linux/init.h>
37 #include <linux/arcdevice.h>
40 #define VERSION "arcnet: RIM I (entirely mem-mapped) support\n"
43 /* Internal function declarations */
45 static int arcrimi_probe(struct net_device
*dev
);
46 static int arcrimi_found(struct net_device
*dev
);
47 static void arcrimi_command(struct net_device
*dev
, int command
);
48 static int arcrimi_status(struct net_device
*dev
);
49 static void arcrimi_setmask(struct net_device
*dev
, int mask
);
50 static int arcrimi_reset(struct net_device
*dev
, int really_reset
);
51 static void arcrimi_copy_to_card(struct net_device
*dev
, int bufnum
, int offset
,
52 void *buf
, int count
);
53 static void arcrimi_copy_from_card(struct net_device
*dev
, int bufnum
, int offset
,
54 void *buf
, int count
);
56 /* Handy defines for ARCnet specific stuff */
58 /* Amount of I/O memory used by the card */
59 #define BUFFER_SIZE (512)
60 #define MIRROR_SIZE (BUFFER_SIZE*4)
62 /* COM 9026 controller chip --> ARCnet register addresses */
63 #define _INTMASK (ioaddr+0) /* writable */
64 #define _STATUS (ioaddr+0) /* readable */
65 #define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
66 #define _RESET (ioaddr+8) /* software reset (on read) */
67 #define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
68 #define _ADDR_HI (ioaddr+15) /* Control registers for said */
69 #define _ADDR_LO (ioaddr+14)
70 #define _CONFIG (ioaddr+2) /* Configuration register */
76 #define ASTATUS() readb(_STATUS)
77 #define ACOMMAND(cmd) writeb((cmd),_COMMAND)
78 #define AINTMASK(msk) writeb((msk),_INTMASK)
79 #define SETCONF() writeb(lp->config,_CONFIG)
83 * We cannot probe for a RIM I card; one reason is I don't know how to reset
84 * them. In fact, we can't even get their node ID automatically. So, we
85 * need to be passed a specific shmem address, IRQ, and node ID.
87 static int __init
arcrimi_probe(struct net_device
*dev
)
89 BUGLVL(D_NORMAL
) printk(VERSION
);
90 BUGLVL(D_NORMAL
) printk("E-mail me if you actually test the RIM I driver, please!\n");
92 BUGMSG(D_NORMAL
, "Given: node %02Xh, shmem %lXh, irq %d\n",
93 dev
->dev_addr
[0], dev
->mem_start
, dev
->irq
);
95 if (dev
->mem_start
<= 0 || dev
->irq
<= 0) {
96 BUGMSG(D_NORMAL
, "No autoprobe for RIM I; you "
97 "must specify the shmem and irq!\n");
101 * Grab the memory region at mem_start for BUFFER_SIZE bytes.
102 * Later in arcrimi_found() the real size will be determined
103 * and this reserve will be released and the correct size
106 if (!request_mem_region(dev
->mem_start
, BUFFER_SIZE
, "arcnet (90xx)")) {
107 BUGMSG(D_NORMAL
, "Card memory already allocated\n");
110 if (dev
->dev_addr
[0] == 0) {
111 release_mem_region(dev
->mem_start
, BUFFER_SIZE
);
112 BUGMSG(D_NORMAL
, "You need to specify your card's station "
116 return arcrimi_found(dev
);
121 * Set up the struct net_device associated with this card. Called after
124 static int __init
arcrimi_found(struct net_device
*dev
)
126 struct arcnet_local
*lp
;
127 unsigned long first_mirror
, last_mirror
, shmem
;
131 /* reserve the irq */
132 if (request_irq(dev
->irq
, &arcnet_interrupt
, 0, "arcnet (RIM I)", dev
)) {
133 release_mem_region(dev
->mem_start
, BUFFER_SIZE
);
134 BUGMSG(D_NORMAL
, "Can't get IRQ %d!\n", dev
->irq
);
138 shmem
= dev
->mem_start
;
139 isa_writeb(TESTvalue
, shmem
);
140 isa_writeb(dev
->dev_addr
[0], shmem
+ 1); /* actually the node ID */
142 /* find the real shared memory start/end points, including mirrors */
144 /* guess the actual size of one "memory mirror" - the number of
145 * bytes between copies of the shared memory. On most cards, it's
146 * 2k (or there are no mirrors at all) but on some, it's 4k.
148 mirror_size
= MIRROR_SIZE
;
149 if (isa_readb(shmem
) == TESTvalue
150 && isa_readb(shmem
- mirror_size
) != TESTvalue
151 && isa_readb(shmem
- 2 * mirror_size
) == TESTvalue
)
154 first_mirror
= last_mirror
= shmem
;
155 while (isa_readb(first_mirror
) == TESTvalue
)
156 first_mirror
-= mirror_size
;
157 first_mirror
+= mirror_size
;
159 while (isa_readb(last_mirror
) == TESTvalue
)
160 last_mirror
+= mirror_size
;
161 last_mirror
-= mirror_size
;
163 dev
->mem_start
= first_mirror
;
164 dev
->mem_end
= last_mirror
+ MIRROR_SIZE
- 1;
166 /* initialize the rest of the device structure. */
169 lp
->card_name
= "RIM I";
170 lp
->hw
.command
= arcrimi_command
;
171 lp
->hw
.status
= arcrimi_status
;
172 lp
->hw
.intmask
= arcrimi_setmask
;
173 lp
->hw
.reset
= arcrimi_reset
;
174 lp
->hw
.owner
= THIS_MODULE
;
175 lp
->hw
.copy_to_card
= arcrimi_copy_to_card
;
176 lp
->hw
.copy_from_card
= arcrimi_copy_from_card
;
179 * re-reserve the memory region - arcrimi_probe() alloced this reqion
180 * but didn't know the real size. Free that region and then re-get
181 * with the correct size. There is a VERY slim chance this could
184 release_mem_region(shmem
, BUFFER_SIZE
);
185 if (!request_mem_region(dev
->mem_start
,
186 dev
->mem_end
- dev
->mem_start
+ 1,
188 BUGMSG(D_NORMAL
, "Card memory already allocated\n");
192 lp
->mem_start
= ioremap(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
193 if (!lp
->mem_start
) {
194 BUGMSG(D_NORMAL
, "Can't remap device memory!\n");
195 goto err_release_mem
;
198 /* get and check the station ID from offset 1 in shmem */
199 dev
->dev_addr
[0] = readb(lp
->mem_start
+ 1);
201 BUGMSG(D_NORMAL
, "ARCnet RIM I: station %02Xh found at IRQ %d, "
202 "ShMem %lXh (%ld*%d bytes).\n",
204 dev
->irq
, dev
->mem_start
,
205 (dev
->mem_end
- dev
->mem_start
+ 1) / mirror_size
, mirror_size
);
207 err
= register_netdev(dev
);
214 iounmap(lp
->mem_start
);
216 release_mem_region(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
218 free_irq(dev
->irq
, dev
);
224 * Do a hardware reset on the card, and set up necessary registers.
226 * This should be called as little as possible, because it disrupts the
227 * token on the network (causes a RECON) and requires a significant delay.
229 * However, it does make sure the card is in a defined state.
231 static int arcrimi_reset(struct net_device
*dev
, int really_reset
)
233 struct arcnet_local
*lp
= dev
->priv
;
234 void __iomem
*ioaddr
= lp
->mem_start
+ 0x800;
236 BUGMSG(D_INIT
, "Resetting %s (status=%02Xh)\n", dev
->name
, ASTATUS());
239 writeb(TESTvalue
, ioaddr
- 0x800); /* fake reset */
242 ACOMMAND(CFLAGScmd
| RESETclear
); /* clear flags & end reset */
243 ACOMMAND(CFLAGScmd
| CONFIGclear
);
245 /* enable extended (512-byte) packets */
246 ACOMMAND(CONFIGcmd
| EXTconf
);
248 /* done! return success. */
252 static void arcrimi_setmask(struct net_device
*dev
, int mask
)
254 struct arcnet_local
*lp
= dev
->priv
;
255 void __iomem
*ioaddr
= lp
->mem_start
+ 0x800;
260 static int arcrimi_status(struct net_device
*dev
)
262 struct arcnet_local
*lp
= dev
->priv
;
263 void __iomem
*ioaddr
= lp
->mem_start
+ 0x800;
268 static void arcrimi_command(struct net_device
*dev
, int cmd
)
270 struct arcnet_local
*lp
= dev
->priv
;
271 void __iomem
*ioaddr
= lp
->mem_start
+ 0x800;
276 static void arcrimi_copy_to_card(struct net_device
*dev
, int bufnum
, int offset
,
277 void *buf
, int count
)
279 struct arcnet_local
*lp
= dev
->priv
;
280 void __iomem
*memaddr
= lp
->mem_start
+ 0x800 + bufnum
* 512 + offset
;
281 TIME("memcpy_toio", count
, memcpy_toio(memaddr
, buf
, count
));
285 static void arcrimi_copy_from_card(struct net_device
*dev
, int bufnum
, int offset
,
286 void *buf
, int count
)
288 struct arcnet_local
*lp
= dev
->priv
;
289 void __iomem
*memaddr
= lp
->mem_start
+ 0x800 + bufnum
* 512 + offset
;
290 TIME("memcpy_fromio", count
, memcpy_fromio(buf
, memaddr
, count
));
294 static int io
; /* use the insmod io= irq= node= options */
296 static char device
[9]; /* use eg. device=arc1 to change name */
298 module_param(node
, int, 0);
299 module_param(io
, int, 0);
300 module_param(irq
, int, 0);
301 module_param_string(device
, device
, sizeof(device
), 0);
302 MODULE_LICENSE("GPL");
304 static struct net_device
*my_dev
;
306 static int __init
arc_rimi_init(void)
308 struct net_device
*dev
;
310 dev
= alloc_arcdev(device
);
314 if (node
&& node
!= 0xff)
315 dev
->dev_addr
[0] = node
;
322 if (arcrimi_probe(dev
)) {
331 static void __exit
arc_rimi_exit(void)
333 struct net_device
*dev
= my_dev
;
334 struct arcnet_local
*lp
= dev
->priv
;
336 unregister_netdev(dev
);
337 iounmap(lp
->mem_start
);
338 release_mem_region(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
339 free_irq(dev
->irq
, dev
);
344 static int __init
arcrimi_setup(char *s
)
347 s
= get_options(s
, 8, ints
);
352 printk("arcrimi: Too many arguments.\n");
353 case 3: /* Node ID */
357 case 1: /* IO address */
361 snprintf(device
, sizeof(device
), "%s", s
);
364 __setup("arcrimi=", arcrimi_setup
);
367 module_init(arc_rimi_init
)
368 module_exit(arc_rimi_exit
)