2 * Linux ARCnet driver - COM90xx chipset (IO-mapped buffers)
4 * Written 1997 by David Woodhouse.
5 * Written 1994-1999 by Avery Pennarun.
6 * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
7 * Derived from skeleton.c by Donald Becker.
9 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
10 * for sponsoring the further development of this driver.
12 * **********************
14 * The original copyright of skeleton.c was as follows:
16 * skeleton.c Written 1993 by Donald Becker.
17 * Copyright 1993 United States Government as represented by the
18 * Director, National Security Agency. This software may only be used
19 * and distributed according to the terms of the GNU General Public License as
20 * modified by SRC, incorporated herein by reference.
22 * **********************
24 * For more details, see drivers/net/arcnet.c
26 * **********************
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/ioport.h>
32 #include <linux/delay.h>
33 #include <linux/netdevice.h>
34 #include <linux/bootmem.h>
35 #include <linux/init.h>
36 #include <linux/interrupt.h>
38 #include <linux/arcdevice.h>
40 #define VERSION "arcnet: COM90xx IO-mapped mode support (by David Woodhouse et el.)\n"
42 /* Internal function declarations */
44 static int com90io_found(struct net_device *dev);
45 static void com90io_command(struct net_device *dev, int command);
46 static int com90io_status(struct net_device *dev);
47 static void com90io_setmask(struct net_device *dev, int mask);
48 static int com90io_reset(struct net_device *dev, int really_reset);
49 static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
50 void *buf, int count);
51 static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset,
52 void *buf, int count);
54 /* Handy defines for ARCnet specific stuff */
56 /* The number of low I/O ports used by the card. */
57 #define ARCNET_TOTAL_SIZE 16
59 /* COM 9026 controller chip --> ARCnet register addresses */
60 #define _INTMASK (ioaddr + 0) /* writable */
61 #define _STATUS (ioaddr + 0) /* readable */
62 #define _COMMAND (ioaddr + 1) /* writable, returns random vals on read (?) */
63 #define _RESET (ioaddr + 8) /* software reset (on read) */
64 #define _MEMDATA (ioaddr + 12) /* Data port for IO-mapped memory */
65 #define _ADDR_HI (ioaddr + 15) /* Control registers for said */
66 #define _ADDR_LO (ioaddr + 14)
67 #define _CONFIG (ioaddr + 2) /* Configuration register */
73 #define ASTATUS() inb(_STATUS)
74 #define ACOMMAND(cmd) outb((cmd), _COMMAND)
75 #define AINTMASK(msk) outb((msk), _INTMASK)
76 #define SETCONF() outb((lp->config), _CONFIG)
78 /****************************************************************************
80 * IO-mapped operation routines *
82 ****************************************************************************/
84 #undef ONE_AT_A_TIME_TX
85 #undef ONE_AT_A_TIME_RX
87 static u_char get_buffer_byte(struct net_device *dev, unsigned offset)
89 int ioaddr = dev->base_addr;
91 outb(offset >> 8, _ADDR_HI);
92 outb(offset & 0xff, _ADDR_LO);
97 #ifdef ONE_AT_A_TIME_TX
98 static void put_buffer_byte(struct net_device *dev, unsigned offset, u_char datum)
100 int ioaddr = dev->base_addr;
102 outb(offset >> 8, _ADDR_HI);
103 outb(offset & 0xff, _ADDR_LO);
105 outb(datum, _MEMDATA);
110 static void get_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest)
112 int ioaddr = dev->base_addr;
114 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
115 outb(offset & 0xff, _ADDR_LO);
118 #ifdef ONE_AT_A_TIME_RX
119 *(dest++) = get_buffer_byte(dev, offset++);
121 *(dest++) = inb(_MEMDATA);
125 static void put_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest)
127 int ioaddr = dev->base_addr;
129 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
130 outb(offset & 0xff, _ADDR_LO);
133 #ifdef ONE_AT_A_TIME_TX
134 put_buffer_byte(dev, offset++, *(dest++));
136 outb(*(dest++), _MEMDATA);
140 /* We cannot probe for an IO mapped card either, although we can check that
141 * it's where we were told it was, and even autoirq
143 static int __init com90io_probe(struct net_device *dev)
145 int ioaddr = dev->base_addr, status;
146 unsigned long airqmask;
148 if (BUGLVL(D_NORMAL)) {
150 printk("E-mail me if you actually test this driver, please!\n");
154 BUGMSG(D_NORMAL, "No autoprobe for IO mapped cards; you must specify the base address!\n");
157 if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
158 BUGMSG(D_INIT_REASONS, "IO request_region %x-%x failed.\n",
159 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
162 if (ASTATUS() == 0xFF) {
163 BUGMSG(D_INIT_REASONS, "IO address %x empty\n", ioaddr);
171 if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
172 BUGMSG(D_INIT_REASONS, "Status invalid (%Xh).\n", status);
175 BUGMSG(D_INIT_REASONS, "Status after reset: %X\n", status);
177 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
179 BUGMSG(D_INIT_REASONS, "Status after reset acknowledged: %X\n", status);
183 if (status & RESETflag) {
184 BUGMSG(D_INIT_REASONS, "Eternal reset (status=%Xh)\n", status);
187 outb((0x16 | IOMAPflag) & ~ENABLE16flag, _CONFIG);
189 /* Read first loc'n of memory */
191 outb(AUTOINCflag, _ADDR_HI);
194 if ((status = inb(_MEMDATA)) != 0xd1) {
195 BUGMSG(D_INIT_REASONS, "Signature byte not found (%Xh instead).\n",
200 /* if we do this, we're sure to get an IRQ since the
201 * card has just reset and the NORXflag is on until
202 * we tell it to start receiving.
205 airqmask = probe_irq_on();
206 outb(NORXflag, _INTMASK);
209 dev->irq = probe_irq_off(airqmask);
211 if ((int)dev->irq <= 0) {
212 BUGMSG(D_INIT_REASONS, "Autoprobe IRQ failed\n");
216 release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */
217 return com90io_found(dev);
220 release_region(ioaddr, ARCNET_TOTAL_SIZE);
224 /* Set up the struct net_device associated with this card. Called after
227 static int __init com90io_found(struct net_device *dev)
229 struct arcnet_local *lp;
230 int ioaddr = dev->base_addr;
233 /* Reserve the irq */
234 if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (COM90xx-IO)", dev)) {
235 BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", dev->irq);
238 /* Reserve the I/O region */
239 if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE, "arcnet (COM90xx-IO)")) {
240 free_irq(dev->irq, dev);
244 lp = netdev_priv(dev);
245 lp->card_name = "COM90xx I/O";
246 lp->hw.command = com90io_command;
247 lp->hw.status = com90io_status;
248 lp->hw.intmask = com90io_setmask;
249 lp->hw.reset = com90io_reset;
250 lp->hw.owner = THIS_MODULE;
251 lp->hw.copy_to_card = com90io_copy_to_card;
252 lp->hw.copy_from_card = com90io_copy_from_card;
254 lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
257 /* get and check the station ID from offset 1 in shmem */
259 dev->dev_addr[0] = get_buffer_byte(dev, 1);
261 err = register_netdev(dev);
263 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
264 free_irq(dev->irq, dev);
265 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
269 BUGMSG(D_NORMAL, "COM90IO: station %02Xh found at %03lXh, IRQ %d.\n",
270 dev->dev_addr[0], dev->base_addr, dev->irq);
275 /* Do a hardware reset on the card, and set up necessary registers.
277 * This should be called as little as possible, because it disrupts the
278 * token on the network (causes a RECON) and requires a significant delay.
280 * However, it does make sure the card is in a defined state.
282 static int com90io_reset(struct net_device *dev, int really_reset)
284 struct arcnet_local *lp = netdev_priv(dev);
285 short ioaddr = dev->base_addr;
287 BUGMSG(D_INIT, "Resetting %s (status=%02Xh)\n", dev->name, ASTATUS());
294 /* Set the thing to IO-mapped, 8-bit mode */
295 lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
298 ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
299 ACOMMAND(CFLAGScmd | CONFIGclear);
301 /* verify that the ARCnet signature byte is present */
302 if (get_buffer_byte(dev, 0) != TESTvalue) {
303 BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n");
306 /* enable extended (512-byte) packets */
307 ACOMMAND(CONFIGcmd | EXTconf);
309 /* done! return success. */
313 static void com90io_command(struct net_device *dev, int cmd)
315 short ioaddr = dev->base_addr;
320 static int com90io_status(struct net_device *dev)
322 short ioaddr = dev->base_addr;
327 static void com90io_setmask(struct net_device *dev, int mask)
329 short ioaddr = dev->base_addr;
334 static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
335 void *buf, int count)
337 TIME("put_whole_buffer", count, put_whole_buffer(dev, bufnum * 512 + offset, count, buf));
340 static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset,
341 void *buf, int count)
343 TIME("get_whole_buffer", count, get_whole_buffer(dev, bufnum * 512 + offset, count, buf));
346 static int io; /* use the insmod io= irq= shmem= options */
348 static char device[9]; /* use eg. device=arc1 to change name */
350 module_param(io, int, 0);
351 module_param(irq, int, 0);
352 module_param_string(device, device, sizeof(device), 0);
353 MODULE_LICENSE("GPL");
356 static int __init com90io_setup(char *s)
360 s = get_options(s, 4, ints);
365 printk("com90io: Too many arguments.\n");
368 case 1: /* IO address */
372 snprintf(device, sizeof(device), "%s", s);
375 __setup("com90io=", com90io_setup);
378 static struct net_device *my_dev;
380 static int __init com90io_init(void)
382 struct net_device *dev;
385 dev = alloc_arcdev(device);
394 err = com90io_probe(dev);
405 static void __exit com90io_exit(void)
407 struct net_device *dev = my_dev;
408 int ioaddr = dev->base_addr;
410 unregister_netdev(dev);
412 /* Set the thing back to MMAP mode, in case the old driver is loaded later */
413 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
415 free_irq(dev->irq, dev);
416 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
420 module_init(com90io_init)
421 module_exit(com90io_exit)