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,
53 int offset, 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,
102 int ioaddr = dev->base_addr;
104 outb(offset >> 8, _ADDR_HI);
105 outb(offset & 0xff, _ADDR_LO);
107 outb(datum, _MEMDATA);
112 static void get_whole_buffer(struct net_device *dev, unsigned offset,
113 unsigned length, char *dest)
115 int ioaddr = dev->base_addr;
117 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
118 outb(offset & 0xff, _ADDR_LO);
121 #ifdef ONE_AT_A_TIME_RX
122 *(dest++) = get_buffer_byte(dev, offset++);
124 *(dest++) = inb(_MEMDATA);
128 static void put_whole_buffer(struct net_device *dev, unsigned offset,
129 unsigned length, char *dest)
131 int ioaddr = dev->base_addr;
133 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
134 outb(offset & 0xff, _ADDR_LO);
137 #ifdef ONE_AT_A_TIME_TX
138 put_buffer_byte(dev, offset++, *(dest++));
140 outb(*(dest++), _MEMDATA);
144 /* We cannot probe for an IO mapped card either, although we can check that
145 * it's where we were told it was, and even autoirq
147 static int __init com90io_probe(struct net_device *dev)
149 int ioaddr = dev->base_addr, status;
150 unsigned long airqmask;
152 if (BUGLVL(D_NORMAL)) {
153 pr_info("%s\n", "COM90xx IO-mapped mode support (by David Woodhouse et el.)");
154 pr_info("E-mail me if you actually test this driver, please!\n");
158 arc_printk(D_NORMAL, dev, "No autoprobe for IO mapped cards; you must specify the base address!\n");
161 if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
162 arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n",
163 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
166 if (ASTATUS() == 0xFF) {
167 arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n",
176 if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
177 arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n",
181 arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status);
183 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
185 arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n",
190 if (status & RESETflag) {
191 arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n",
195 outb((0x16 | IOMAPflag) & ~ENABLE16flag, _CONFIG);
197 /* Read first loc'n of memory */
199 outb(AUTOINCflag, _ADDR_HI);
202 status = inb(_MEMDATA);
203 if (status != 0xd1) {
204 arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n",
209 /* if we do this, we're sure to get an IRQ since the
210 * card has just reset and the NORXflag is on until
211 * we tell it to start receiving.
214 airqmask = probe_irq_on();
215 outb(NORXflag, _INTMASK);
218 dev->irq = probe_irq_off(airqmask);
220 if ((int)dev->irq <= 0) {
221 arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n");
225 release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */
226 return com90io_found(dev);
229 release_region(ioaddr, ARCNET_TOTAL_SIZE);
233 /* Set up the struct net_device associated with this card. Called after
236 static int __init com90io_found(struct net_device *dev)
238 struct arcnet_local *lp;
239 int ioaddr = dev->base_addr;
242 /* Reserve the irq */
243 if (request_irq(dev->irq, arcnet_interrupt, 0,
244 "arcnet (COM90xx-IO)", dev)) {
245 arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
248 /* Reserve the I/O region */
249 if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE,
250 "arcnet (COM90xx-IO)")) {
251 free_irq(dev->irq, dev);
255 lp = netdev_priv(dev);
256 lp->card_name = "COM90xx I/O";
257 lp->hw.command = com90io_command;
258 lp->hw.status = com90io_status;
259 lp->hw.intmask = com90io_setmask;
260 lp->hw.reset = com90io_reset;
261 lp->hw.owner = THIS_MODULE;
262 lp->hw.copy_to_card = com90io_copy_to_card;
263 lp->hw.copy_from_card = com90io_copy_from_card;
265 lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
268 /* get and check the station ID from offset 1 in shmem */
270 dev->dev_addr[0] = get_buffer_byte(dev, 1);
272 err = register_netdev(dev);
274 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
275 free_irq(dev->irq, dev);
276 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
280 arc_printk(D_NORMAL, dev, "COM90IO: station %02Xh found at %03lXh, IRQ %d.\n",
281 dev->dev_addr[0], dev->base_addr, dev->irq);
286 /* Do a hardware reset on the card, and set up necessary registers.
288 * This should be called as little as possible, because it disrupts the
289 * token on the network (causes a RECON) and requires a significant delay.
291 * However, it does make sure the card is in a defined state.
293 static int com90io_reset(struct net_device *dev, int really_reset)
295 struct arcnet_local *lp = netdev_priv(dev);
296 short ioaddr = dev->base_addr;
298 arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
299 dev->name, ASTATUS());
306 /* Set the thing to IO-mapped, 8-bit mode */
307 lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
310 ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
311 ACOMMAND(CFLAGScmd | CONFIGclear);
313 /* verify that the ARCnet signature byte is present */
314 if (get_buffer_byte(dev, 0) != TESTvalue) {
315 arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
318 /* enable extended (512-byte) packets */
319 ACOMMAND(CONFIGcmd | EXTconf);
321 /* done! return success. */
325 static void com90io_command(struct net_device *dev, int cmd)
327 short ioaddr = dev->base_addr;
332 static int com90io_status(struct net_device *dev)
334 short ioaddr = dev->base_addr;
339 static void com90io_setmask(struct net_device *dev, int mask)
341 short ioaddr = dev->base_addr;
346 static void com90io_copy_to_card(struct net_device *dev, int bufnum,
347 int offset, void *buf, int count)
349 TIME(dev, "put_whole_buffer", count,
350 put_whole_buffer(dev, bufnum * 512 + offset, count, buf));
353 static void com90io_copy_from_card(struct net_device *dev, int bufnum,
354 int offset, void *buf, int count)
356 TIME(dev, "get_whole_buffer", count,
357 get_whole_buffer(dev, bufnum * 512 + offset, count, buf));
360 static int io; /* use the insmod io= irq= shmem= options */
362 static char device[9]; /* use eg. device=arc1 to change name */
364 module_param(io, int, 0);
365 module_param(irq, int, 0);
366 module_param_string(device, device, sizeof(device), 0);
367 MODULE_LICENSE("GPL");
370 static int __init com90io_setup(char *s)
374 s = get_options(s, 4, ints);
379 pr_err("Too many arguments\n");
382 case 1: /* IO address */
386 snprintf(device, sizeof(device), "%s", s);
389 __setup("com90io=", com90io_setup);
392 static struct net_device *my_dev;
394 static int __init com90io_init(void)
396 struct net_device *dev;
399 dev = alloc_arcdev(device);
408 err = com90io_probe(dev);
419 static void __exit com90io_exit(void)
421 struct net_device *dev = my_dev;
422 int ioaddr = dev->base_addr;
424 unregister_netdev(dev);
426 /* In case the old driver is loaded later,
427 * set the thing back to MMAP mode
429 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
431 free_irq(dev->irq, dev);
432 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
436 module_init(com90io_init)
437 module_exit(com90io_exit)