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>
42 #include "arcdevice.h"
44 /* Internal function declarations */
46 static int com90io_found(struct net_device *dev);
47 static void com90io_command(struct net_device *dev, int command);
48 static int com90io_status(struct net_device *dev);
49 static void com90io_setmask(struct net_device *dev, int mask);
50 static int com90io_reset(struct net_device *dev, int really_reset);
51 static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
52 void *buf, int count);
53 static void com90io_copy_from_card(struct net_device *dev, int bufnum,
54 int offset, void *buf, int count);
56 /* Handy defines for ARCnet specific stuff */
58 /* The number of low I/O ports used by the card. */
59 #define ARCNET_TOTAL_SIZE 16
61 /* COM 9026 controller chip --> ARCnet register addresses */
62 #define COM9026_REG_W_INTMASK 0 /* writable */
63 #define COM9026_REG_R_STATUS 0 /* readable */
64 #define COM9026_REG_W_COMMAND 1 /* writable, returns random vals on read (?) */
65 #define COM9026_REG_RW_CONFIG 2 /* Configuration register */
66 #define COM9026_REG_R_RESET 8 /* software reset (on read) */
67 #define COM9026_REG_RW_MEMDATA 12 /* Data port for IO-mapped memory */
68 #define COM9026_REG_W_ADDR_LO 14 /* Control registers for said */
69 #define COM9026_REG_W_ADDR_HI 15
71 /****************************************************************************
73 * IO-mapped operation routines *
75 ****************************************************************************/
77 #undef ONE_AT_A_TIME_TX
78 #undef ONE_AT_A_TIME_RX
80 static u_char get_buffer_byte(struct net_device *dev, unsigned offset)
82 int ioaddr = dev->base_addr;
84 arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI);
85 arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
87 return arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
90 #ifdef ONE_AT_A_TIME_TX
91 static void put_buffer_byte(struct net_device *dev, unsigned offset,
94 int ioaddr = dev->base_addr;
96 arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI);
97 arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
99 arcnet_outb(datum, ioaddr, COM9026_REG_RW_MEMDATA);
104 static void get_whole_buffer(struct net_device *dev, unsigned offset,
105 unsigned length, char *dest)
107 int ioaddr = dev->base_addr;
109 arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
110 arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
113 #ifdef ONE_AT_A_TIME_RX
114 *(dest++) = get_buffer_byte(dev, offset++);
116 *(dest++) = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
120 static void put_whole_buffer(struct net_device *dev, unsigned offset,
121 unsigned length, char *dest)
123 int ioaddr = dev->base_addr;
125 arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
126 arcnet_outb(offset & 0xff, ioaddr,COM9026_REG_W_ADDR_LO);
129 #ifdef ONE_AT_A_TIME_TX
130 put_buffer_byte(dev, offset++, *(dest++));
132 arcnet_outb(*(dest++), ioaddr, COM9026_REG_RW_MEMDATA);
136 /* We cannot probe for an IO mapped card either, although we can check that
137 * it's where we were told it was, and even autoirq
139 static int __init com90io_probe(struct net_device *dev)
141 int ioaddr = dev->base_addr, status;
142 unsigned long airqmask;
144 if (BUGLVL(D_NORMAL)) {
145 pr_info("%s\n", "COM90xx IO-mapped mode support (by David Woodhouse et el.)");
146 pr_info("E-mail me if you actually test this driver, please!\n");
150 arc_printk(D_NORMAL, dev, "No autoprobe for IO mapped cards; you must specify the base address!\n");
153 if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
154 arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n",
155 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
158 if (arcnet_inb(ioaddr, COM9026_REG_R_STATUS) == 0xFF) {
159 arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n",
163 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
166 status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
168 if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
169 arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n",
173 arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status);
175 arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
176 ioaddr, COM9026_REG_W_COMMAND);
178 arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n",
181 status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
183 if (status & RESETflag) {
184 arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n",
188 arcnet_outb((0x16 | IOMAPflag) & ~ENABLE16flag,
189 ioaddr, COM9026_REG_RW_CONFIG);
191 /* Read first loc'n of memory */
193 arcnet_outb(AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
194 arcnet_outb(0, ioaddr, COM9026_REG_W_ADDR_LO);
196 status = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
197 if (status != 0xd1) {
198 arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n",
203 /* if we do this, we're sure to get an IRQ since the
204 * card has just reset and the NORXflag is on until
205 * we tell it to start receiving.
208 airqmask = probe_irq_on();
209 arcnet_outb(NORXflag, ioaddr, COM9026_REG_W_INTMASK);
211 arcnet_outb(0, ioaddr, COM9026_REG_W_INTMASK);
212 dev->irq = probe_irq_off(airqmask);
214 if ((int)dev->irq <= 0) {
215 arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n");
219 release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */
220 return com90io_found(dev);
223 release_region(ioaddr, ARCNET_TOTAL_SIZE);
227 /* Set up the struct net_device associated with this card. Called after
230 static int __init com90io_found(struct net_device *dev)
232 struct arcnet_local *lp;
233 int ioaddr = dev->base_addr;
236 /* Reserve the irq */
237 if (request_irq(dev->irq, arcnet_interrupt, 0,
238 "arcnet (COM90xx-IO)", dev)) {
239 arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
242 /* Reserve the I/O region */
243 if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE,
244 "arcnet (COM90xx-IO)")) {
245 free_irq(dev->irq, dev);
249 lp = netdev_priv(dev);
250 lp->card_name = "COM90xx I/O";
251 lp->hw.command = com90io_command;
252 lp->hw.status = com90io_status;
253 lp->hw.intmask = com90io_setmask;
254 lp->hw.reset = com90io_reset;
255 lp->hw.owner = THIS_MODULE;
256 lp->hw.copy_to_card = com90io_copy_to_card;
257 lp->hw.copy_from_card = com90io_copy_from_card;
259 lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
260 arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG);
262 /* get and check the station ID from offset 1 in shmem */
264 dev->dev_addr[0] = get_buffer_byte(dev, 1);
266 err = register_netdev(dev);
268 arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag,
269 ioaddr, COM9026_REG_RW_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, arcnet_inb(ioaddr, COM9026_REG_R_STATUS));
298 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
301 /* Set the thing to IO-mapped, 8-bit mode */
302 lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
303 arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG);
305 arcnet_outb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND);
306 /* clear flags & end reset */
307 arcnet_outb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND);
309 /* verify that the ARCnet signature byte is present */
310 if (get_buffer_byte(dev, 0) != TESTvalue) {
311 arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
314 /* enable extended (512-byte) packets */
315 arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
316 /* done! return success. */
320 static void com90io_command(struct net_device *dev, int cmd)
322 short ioaddr = dev->base_addr;
324 arcnet_outb(cmd, ioaddr, COM9026_REG_W_COMMAND);
327 static int com90io_status(struct net_device *dev)
329 short ioaddr = dev->base_addr;
331 return arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
334 static void com90io_setmask(struct net_device *dev, int mask)
336 short ioaddr = dev->base_addr;
338 arcnet_outb(mask, ioaddr, COM9026_REG_W_INTMASK);
341 static void com90io_copy_to_card(struct net_device *dev, int bufnum,
342 int offset, 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,
349 int offset, 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 /* In case the old driver is loaded later,
422 * set the thing back to MMAP mode
424 arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag,
425 ioaddr, COM9026_REG_RW_CONFIG);
427 free_irq(dev->irq, dev);
428 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
432 module_init(com90io_init)
433 module_exit(com90io_exit)