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 * **********************
29 #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/moduleparam.h>
34 #include <linux/ioport.h>
35 #include <linux/delay.h>
36 #include <linux/netdevice.h>
37 #include <linux/bootmem.h>
38 #include <linux/init.h>
39 #include <linux/interrupt.h>
41 #include <linux/arcdevice.h>
43 /* Internal function declarations */
45 static int com90io_found(struct net_device *dev);
46 static void com90io_command(struct net_device *dev, int command);
47 static int com90io_status(struct net_device *dev);
48 static void com90io_setmask(struct net_device *dev, int mask);
49 static int com90io_reset(struct net_device *dev, int really_reset);
50 static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
51 void *buf, int count);
52 static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset,
53 void *buf, int count);
55 /* Handy defines for ARCnet specific stuff */
57 /* The number of low I/O ports used by the card. */
58 #define ARCNET_TOTAL_SIZE 16
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() inb(_STATUS)
75 #define ACOMMAND(cmd) outb((cmd), _COMMAND)
76 #define AINTMASK(msk) outb((msk), _INTMASK)
77 #define SETCONF() outb((lp->config), _CONFIG)
79 /****************************************************************************
81 * IO-mapped operation routines *
83 ****************************************************************************/
85 #undef ONE_AT_A_TIME_TX
86 #undef ONE_AT_A_TIME_RX
88 static u_char get_buffer_byte(struct net_device *dev, unsigned offset)
90 int ioaddr = dev->base_addr;
92 outb(offset >> 8, _ADDR_HI);
93 outb(offset & 0xff, _ADDR_LO);
98 #ifdef ONE_AT_A_TIME_TX
99 static void put_buffer_byte(struct net_device *dev, unsigned offset, u_char datum)
101 int ioaddr = dev->base_addr;
103 outb(offset >> 8, _ADDR_HI);
104 outb(offset & 0xff, _ADDR_LO);
106 outb(datum, _MEMDATA);
111 static void get_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest)
113 int ioaddr = dev->base_addr;
115 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
116 outb(offset & 0xff, _ADDR_LO);
119 #ifdef ONE_AT_A_TIME_RX
120 *(dest++) = get_buffer_byte(dev, offset++);
122 *(dest++) = inb(_MEMDATA);
126 static void put_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest)
128 int ioaddr = dev->base_addr;
130 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
131 outb(offset & 0xff, _ADDR_LO);
134 #ifdef ONE_AT_A_TIME_TX
135 put_buffer_byte(dev, offset++, *(dest++));
137 outb(*(dest++), _MEMDATA);
141 /* We cannot probe for an IO mapped card either, although we can check that
142 * it's where we were told it was, and even autoirq
144 static int __init com90io_probe(struct net_device *dev)
146 int ioaddr = dev->base_addr, status;
147 unsigned long airqmask;
149 if (BUGLVL(D_NORMAL)) {
150 pr_info("%s\n", "COM90xx IO-mapped mode support (by David Woodhouse et el.)");
151 pr_info("E-mail me if you actually test this driver, please!\n");
155 arc_printk(D_NORMAL, dev, "No autoprobe for IO mapped cards; you must specify the base address!\n");
158 if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
159 arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n",
160 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
163 if (ASTATUS() == 0xFF) {
164 arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n",
173 if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
174 arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n",
178 arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status);
180 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
182 arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n",
187 if (status & RESETflag) {
188 arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n",
192 outb((0x16 | IOMAPflag) & ~ENABLE16flag, _CONFIG);
194 /* Read first loc'n of memory */
196 outb(AUTOINCflag, _ADDR_HI);
199 status = inb(_MEMDATA);
200 if (status != 0xd1) {
201 arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n",
206 /* if we do this, we're sure to get an IRQ since the
207 * card has just reset and the NORXflag is on until
208 * we tell it to start receiving.
211 airqmask = probe_irq_on();
212 outb(NORXflag, _INTMASK);
215 dev->irq = probe_irq_off(airqmask);
217 if ((int)dev->irq <= 0) {
218 arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n");
222 release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */
223 return com90io_found(dev);
226 release_region(ioaddr, ARCNET_TOTAL_SIZE);
230 /* Set up the struct net_device associated with this card. Called after
233 static int __init com90io_found(struct net_device *dev)
235 struct arcnet_local *lp;
236 int ioaddr = dev->base_addr;
239 /* Reserve the irq */
240 if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (COM90xx-IO)", dev)) {
241 arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
244 /* Reserve the I/O region */
245 if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE, "arcnet (COM90xx-IO)")) {
246 free_irq(dev->irq, dev);
250 lp = netdev_priv(dev);
251 lp->card_name = "COM90xx I/O";
252 lp->hw.command = com90io_command;
253 lp->hw.status = com90io_status;
254 lp->hw.intmask = com90io_setmask;
255 lp->hw.reset = com90io_reset;
256 lp->hw.owner = THIS_MODULE;
257 lp->hw.copy_to_card = com90io_copy_to_card;
258 lp->hw.copy_from_card = com90io_copy_from_card;
260 lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
263 /* get and check the station ID from offset 1 in shmem */
265 dev->dev_addr[0] = get_buffer_byte(dev, 1);
267 err = register_netdev(dev);
269 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
270 free_irq(dev->irq, dev);
271 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
275 arc_printk(D_NORMAL, dev, "COM90IO: station %02Xh found at %03lXh, IRQ %d.\n",
276 dev->dev_addr[0], dev->base_addr, dev->irq);
281 /* Do a hardware reset on the card, and set up necessary registers.
283 * This should be called as little as possible, because it disrupts the
284 * token on the network (causes a RECON) and requires a significant delay.
286 * However, it does make sure the card is in a defined state.
288 static int com90io_reset(struct net_device *dev, int really_reset)
290 struct arcnet_local *lp = netdev_priv(dev);
291 short ioaddr = dev->base_addr;
293 arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
294 dev->name, ASTATUS());
301 /* Set the thing to IO-mapped, 8-bit mode */
302 lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
305 ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
306 ACOMMAND(CFLAGScmd | CONFIGclear);
308 /* verify that the ARCnet signature byte is present */
309 if (get_buffer_byte(dev, 0) != TESTvalue) {
310 arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
313 /* enable extended (512-byte) packets */
314 ACOMMAND(CONFIGcmd | EXTconf);
316 /* done! return success. */
320 static void com90io_command(struct net_device *dev, int cmd)
322 short ioaddr = dev->base_addr;
327 static int com90io_status(struct net_device *dev)
329 short ioaddr = dev->base_addr;
334 static void com90io_setmask(struct net_device *dev, int mask)
336 short ioaddr = dev->base_addr;
341 static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
342 void *buf, int count)
344 TIME(dev, "put_whole_buffer", count,
345 put_whole_buffer(dev, bufnum * 512 + offset, count, buf));
348 static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset,
349 void *buf, int count)
351 TIME(dev, "get_whole_buffer", count,
352 get_whole_buffer(dev, bufnum * 512 + offset, count, buf));
355 static int io; /* use the insmod io= irq= shmem= options */
357 static char device[9]; /* use eg. device=arc1 to change name */
359 module_param(io, int, 0);
360 module_param(irq, int, 0);
361 module_param_string(device, device, sizeof(device), 0);
362 MODULE_LICENSE("GPL");
365 static int __init com90io_setup(char *s)
369 s = get_options(s, 4, ints);
374 pr_err("Too many arguments\n");
377 case 1: /* IO address */
381 snprintf(device, sizeof(device), "%s", s);
384 __setup("com90io=", com90io_setup);
387 static struct net_device *my_dev;
389 static int __init com90io_init(void)
391 struct net_device *dev;
394 dev = alloc_arcdev(device);
403 err = com90io_probe(dev);
414 static void __exit com90io_exit(void)
416 struct net_device *dev = my_dev;
417 int ioaddr = dev->base_addr;
419 unregister_netdev(dev);
421 /* Set the thing back to MMAP mode, in case the old driver is loaded later */
422 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
424 free_irq(dev->irq, dev);
425 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
429 module_init(com90io_init)
430 module_exit(com90io_exit)