e8c15016bb8e7e48f6b1ea6a1f430be940a7f9bb
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/delay.h>
32 #include <linux/netdevice.h>
33 #include <linux/bootmem.h>
34 #include <linux/init.h>
35 #include <linux/interrupt.h>
37 #include <linux/arcdevice.h>
39 #define VERSION "arcnet: RIM I (entirely mem-mapped) support\n"
41 /* Internal function declarations */
43 static int arcrimi_probe(struct net_device
*dev
);
44 static int arcrimi_found(struct net_device
*dev
);
45 static void arcrimi_command(struct net_device
*dev
, int command
);
46 static int arcrimi_status(struct net_device
*dev
);
47 static void arcrimi_setmask(struct net_device
*dev
, int mask
);
48 static int arcrimi_reset(struct net_device
*dev
, int really_reset
);
49 static void arcrimi_copy_to_card(struct net_device
*dev
, int bufnum
, int offset
,
50 void *buf
, int count
);
51 static void arcrimi_copy_from_card(struct net_device
*dev
, int bufnum
, int offset
,
52 void *buf
, int count
);
54 /* Handy defines for ARCnet specific stuff */
56 /* Amount of I/O memory used by the card */
57 #define BUFFER_SIZE (512)
58 #define MIRROR_SIZE (BUFFER_SIZE * 4)
60 /* COM 9026 controller chip --> ARCnet register addresses */
61 #define _INTMASK (ioaddr + 0) /* writable */
62 #define _STATUS (ioaddr + 0) /* readable */
63 #define _COMMAND (ioaddr + 1) /* writable, returns random vals on read (?) */
64 #define _RESET (ioaddr + 8) /* software reset (on read) */
65 #define _MEMDATA (ioaddr + 12) /* Data port for IO-mapped memory */
66 #define _ADDR_HI (ioaddr + 15) /* Control registers for said */
67 #define _ADDR_LO (ioaddr + 14)
68 #define _CONFIG (ioaddr + 2) /* Configuration register */
74 #define ASTATUS() readb(_STATUS)
75 #define ACOMMAND(cmd) writeb((cmd), _COMMAND)
76 #define AINTMASK(msk) writeb((msk), _INTMASK)
77 #define SETCONF() writeb(lp->config, _CONFIG)
80 * We cannot probe for a RIM I card; one reason is I don't know how to reset
81 * them. In fact, we can't even get their node ID automatically. So, we
82 * need to be passed a specific shmem address, IRQ, and node ID.
84 static int __init
arcrimi_probe(struct net_device
*dev
)
86 BUGLVL(D_NORMAL
) printk(VERSION
);
87 BUGLVL(D_NORMAL
) printk("E-mail me if you actually test the RIM I driver, please!\n");
89 BUGLVL(D_NORMAL
) printk("Given: node %02Xh, shmem %lXh, irq %d\n",
90 dev
->dev_addr
[0], dev
->mem_start
, dev
->irq
);
92 if (dev
->mem_start
<= 0 || dev
->irq
<= 0) {
93 BUGLVL(D_NORMAL
) printk("No autoprobe for RIM I; you "
94 "must specify the shmem and irq!\n");
97 if (dev
->dev_addr
[0] == 0) {
98 BUGLVL(D_NORMAL
) printk("You need to specify your card's station "
103 * Grab the memory region at mem_start for MIRROR_SIZE bytes.
104 * Later in arcrimi_found() the real size will be determined
105 * and this reserve will be released and the correct size
108 if (!request_mem_region(dev
->mem_start
, MIRROR_SIZE
, "arcnet (90xx)")) {
109 BUGLVL(D_NORMAL
) printk("Card memory already allocated\n");
112 return arcrimi_found(dev
);
115 static int check_mirror(unsigned long addr
, size_t size
)
120 if (!request_mem_region(addr
, size
, "arcnet (90xx)"))
123 p
= ioremap(addr
, size
);
125 if (readb(p
) == TESTvalue
)
132 release_mem_region(addr
, size
);
137 * Set up the struct net_device associated with this card. Called after
140 static int __init
arcrimi_found(struct net_device
*dev
)
142 struct arcnet_local
*lp
;
143 unsigned long first_mirror
, last_mirror
, shmem
;
148 p
= ioremap(dev
->mem_start
, MIRROR_SIZE
);
150 release_mem_region(dev
->mem_start
, MIRROR_SIZE
);
151 BUGMSG(D_NORMAL
, "Can't ioremap\n");
155 /* reserve the irq */
156 if (request_irq(dev
->irq
, arcnet_interrupt
, 0, "arcnet (RIM I)", dev
)) {
158 release_mem_region(dev
->mem_start
, MIRROR_SIZE
);
159 BUGMSG(D_NORMAL
, "Can't get IRQ %d!\n", dev
->irq
);
163 shmem
= dev
->mem_start
;
164 writeb(TESTvalue
, p
);
165 writeb(dev
->dev_addr
[0], p
+ 1); /* actually the node ID */
167 /* find the real shared memory start/end points, including mirrors */
169 /* guess the actual size of one "memory mirror" - the number of
170 * bytes between copies of the shared memory. On most cards, it's
171 * 2k (or there are no mirrors at all) but on some, it's 4k.
173 mirror_size
= MIRROR_SIZE
;
174 if (readb(p
) == TESTvalue
&&
175 check_mirror(shmem
- MIRROR_SIZE
, MIRROR_SIZE
) == 0 &&
176 check_mirror(shmem
- 2 * MIRROR_SIZE
, MIRROR_SIZE
) == 1)
177 mirror_size
= 2 * MIRROR_SIZE
;
179 first_mirror
= shmem
- mirror_size
;
180 while (check_mirror(first_mirror
, mirror_size
) == 1)
181 first_mirror
-= mirror_size
;
182 first_mirror
+= mirror_size
;
184 last_mirror
= shmem
+ mirror_size
;
185 while (check_mirror(last_mirror
, mirror_size
) == 1)
186 last_mirror
+= mirror_size
;
187 last_mirror
-= mirror_size
;
189 dev
->mem_start
= first_mirror
;
190 dev
->mem_end
= last_mirror
+ MIRROR_SIZE
- 1;
192 /* initialize the rest of the device structure. */
194 lp
= netdev_priv(dev
);
195 lp
->card_name
= "RIM I";
196 lp
->hw
.command
= arcrimi_command
;
197 lp
->hw
.status
= arcrimi_status
;
198 lp
->hw
.intmask
= arcrimi_setmask
;
199 lp
->hw
.reset
= arcrimi_reset
;
200 lp
->hw
.owner
= THIS_MODULE
;
201 lp
->hw
.copy_to_card
= arcrimi_copy_to_card
;
202 lp
->hw
.copy_from_card
= arcrimi_copy_from_card
;
205 * re-reserve the memory region - arcrimi_probe() alloced this reqion
206 * but didn't know the real size. Free that region and then re-get
207 * with the correct size. There is a VERY slim chance this could
211 release_mem_region(shmem
, MIRROR_SIZE
);
212 if (!request_mem_region(dev
->mem_start
,
213 dev
->mem_end
- dev
->mem_start
+ 1,
215 BUGMSG(D_NORMAL
, "Card memory already allocated\n");
219 lp
->mem_start
= ioremap(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
220 if (!lp
->mem_start
) {
221 BUGMSG(D_NORMAL
, "Can't remap device memory!\n");
222 goto err_release_mem
;
225 /* get and check the station ID from offset 1 in shmem */
226 dev
->dev_addr
[0] = readb(lp
->mem_start
+ 1);
228 BUGMSG(D_NORMAL
, "ARCnet RIM I: station %02Xh found at IRQ %d, "
229 "ShMem %lXh (%ld*%d bytes).\n",
231 dev
->irq
, dev
->mem_start
,
232 (dev
->mem_end
- dev
->mem_start
+ 1) / mirror_size
, mirror_size
);
234 err
= register_netdev(dev
);
241 iounmap(lp
->mem_start
);
243 release_mem_region(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
245 free_irq(dev
->irq
, dev
);
250 * Do a hardware reset on the card, and set up necessary registers.
252 * This should be called as little as possible, because it disrupts the
253 * token on the network (causes a RECON) and requires a significant delay.
255 * However, it does make sure the card is in a defined state.
257 static int arcrimi_reset(struct net_device
*dev
, int really_reset
)
259 struct arcnet_local
*lp
= netdev_priv(dev
);
260 void __iomem
*ioaddr
= lp
->mem_start
+ 0x800;
262 BUGMSG(D_INIT
, "Resetting %s (status=%02Xh)\n", dev
->name
, ASTATUS());
265 writeb(TESTvalue
, ioaddr
- 0x800); /* fake reset */
268 ACOMMAND(CFLAGScmd
| RESETclear
); /* clear flags & end reset */
269 ACOMMAND(CFLAGScmd
| CONFIGclear
);
271 /* enable extended (512-byte) packets */
272 ACOMMAND(CONFIGcmd
| EXTconf
);
274 /* done! return success. */
278 static void arcrimi_setmask(struct net_device
*dev
, int mask
)
280 struct arcnet_local
*lp
= netdev_priv(dev
);
281 void __iomem
*ioaddr
= lp
->mem_start
+ 0x800;
286 static int arcrimi_status(struct net_device
*dev
)
288 struct arcnet_local
*lp
= netdev_priv(dev
);
289 void __iomem
*ioaddr
= lp
->mem_start
+ 0x800;
294 static void arcrimi_command(struct net_device
*dev
, int cmd
)
296 struct arcnet_local
*lp
= netdev_priv(dev
);
297 void __iomem
*ioaddr
= lp
->mem_start
+ 0x800;
302 static void arcrimi_copy_to_card(struct net_device
*dev
, int bufnum
, int offset
,
303 void *buf
, int count
)
305 struct arcnet_local
*lp
= netdev_priv(dev
);
306 void __iomem
*memaddr
= lp
->mem_start
+ 0x800 + bufnum
* 512 + offset
;
308 TIME("memcpy_toio", count
, memcpy_toio(memaddr
, buf
, count
));
311 static void arcrimi_copy_from_card(struct net_device
*dev
, int bufnum
, int offset
,
312 void *buf
, int count
)
314 struct arcnet_local
*lp
= netdev_priv(dev
);
315 void __iomem
*memaddr
= lp
->mem_start
+ 0x800 + bufnum
* 512 + offset
;
317 TIME("memcpy_fromio", count
, memcpy_fromio(buf
, memaddr
, count
));
321 static int io
; /* use the insmod io= irq= node= options */
323 static char device
[9]; /* use eg. device=arc1 to change name */
325 module_param(node
, int, 0);
326 module_param(io
, int, 0);
327 module_param(irq
, int, 0);
328 module_param_string(device
, device
, sizeof(device
), 0);
329 MODULE_LICENSE("GPL");
331 static struct net_device
*my_dev
;
333 static int __init
arc_rimi_init(void)
335 struct net_device
*dev
;
337 dev
= alloc_arcdev(device
);
341 if (node
&& node
!= 0xff)
342 dev
->dev_addr
[0] = node
;
349 if (arcrimi_probe(dev
)) {
358 static void __exit
arc_rimi_exit(void)
360 struct net_device
*dev
= my_dev
;
361 struct arcnet_local
*lp
= netdev_priv(dev
);
363 unregister_netdev(dev
);
364 iounmap(lp
->mem_start
);
365 release_mem_region(dev
->mem_start
, dev
->mem_end
- dev
->mem_start
+ 1);
366 free_irq(dev
->irq
, dev
);
371 static int __init
arcrimi_setup(char *s
)
375 s
= get_options(s
, 8, ints
);
380 printk("arcrimi: Too many arguments.\n");
381 case 3: /* Node ID */
385 case 1: /* IO address */
389 snprintf(device
, sizeof(device
), "%s", s
);
392 __setup("arcrimi=", arcrimi_setup
);
395 module_init(arc_rimi_init
)
396 module_exit(arc_rimi_exit
)
This page took 0.038931 seconds and 4 git commands to generate.