[XFRM]: skb_cow_data() does not set proper owner for new skbs.
[linux-2.6/verdex.git] / drivers / net / arcnet / com90io.c
blob52c77cbe8c62cf8e104d3639b3ac047737e8d5aa
1 /*
2 * Linux ARCnet driver - COM90xx chipset (IO-mapped buffers)
3 *
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/slab.h>
33 #include <linux/delay.h>
34 #include <linux/netdevice.h>
35 #include <linux/bootmem.h>
36 #include <linux/init.h>
37 #include <asm/io.h>
38 #include <linux/arcdevice.h>
41 #define VERSION "arcnet: COM90xx IO-mapped mode support (by David Woodhouse et el.)\n"
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, int offset,
54 void *buf, int count);
57 /* Handy defines for ARCnet specific stuff */
59 /* The number of low I/O ports used by the card. */
60 #define ARCNET_TOTAL_SIZE 16
62 /* COM 9026 controller chip --> ARCnet register addresses */
63 #define _INTMASK (ioaddr+0) /* writable */
64 #define _STATUS (ioaddr+0) /* readable */
65 #define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
66 #define _RESET (ioaddr+8) /* software reset (on read) */
67 #define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
68 #define _ADDR_HI (ioaddr+15) /* Control registers for said */
69 #define _ADDR_LO (ioaddr+14)
70 #define _CONFIG (ioaddr+2) /* Configuration register */
72 #undef ASTATUS
73 #undef ACOMMAND
74 #undef AINTMASK
76 #define ASTATUS() inb(_STATUS)
77 #define ACOMMAND(cmd) outb((cmd),_COMMAND)
78 #define AINTMASK(msk) outb((msk),_INTMASK)
79 #define SETCONF() outb((lp->config),_CONFIG)
82 /****************************************************************************
83 * *
84 * IO-mapped operation routines *
85 * *
86 ****************************************************************************/
88 #undef ONE_AT_A_TIME_TX
89 #undef ONE_AT_A_TIME_RX
91 static u_char get_buffer_byte(struct net_device *dev, unsigned offset)
93 int ioaddr = dev->base_addr;
95 outb(offset >> 8, _ADDR_HI);
96 outb(offset & 0xff, _ADDR_LO);
98 return inb(_MEMDATA);
101 #ifdef ONE_AT_A_TIME_TX
102 static void put_buffer_byte(struct net_device *dev, unsigned offset, u_char datum)
104 int ioaddr = dev->base_addr;
106 outb(offset >> 8, _ADDR_HI);
107 outb(offset & 0xff, _ADDR_LO);
109 outb(datum, _MEMDATA);
112 #endif
115 static void get_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest)
117 int ioaddr = dev->base_addr;
119 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
120 outb(offset & 0xff, _ADDR_LO);
122 while (length--)
123 #ifdef ONE_AT_A_TIME_RX
124 *(dest++) = get_buffer_byte(dev, offset++);
125 #else
126 *(dest++) = inb(_MEMDATA);
127 #endif
130 static void put_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest)
132 int ioaddr = dev->base_addr;
134 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
135 outb(offset & 0xff, _ADDR_LO);
137 while (length--)
138 #ifdef ONE_AT_A_TIME_TX
139 put_buffer_byte(dev, offset++, *(dest++));
140 #else
141 outb(*(dest++), _MEMDATA);
142 #endif
146 * We cannot probe for an IO mapped card either, although we can check that
147 * it's where we were told it was, and even autoirq
149 static int __init com90io_probe(struct net_device *dev)
151 int ioaddr = dev->base_addr, status;
152 unsigned long airqmask;
154 BUGLVL(D_NORMAL) printk(VERSION);
155 BUGLVL(D_NORMAL) printk("E-mail me if you actually test this driver, please!\n");
157 if (!ioaddr) {
158 BUGMSG(D_NORMAL, "No autoprobe for IO mapped cards; you "
159 "must specify the base address!\n");
160 return -ENODEV;
162 if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
163 BUGMSG(D_INIT_REASONS, "IO check_region %x-%x failed.\n",
164 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
165 return -ENXIO;
167 if (ASTATUS() == 0xFF) {
168 BUGMSG(D_INIT_REASONS, "IO address %x empty\n", ioaddr);
169 goto err_out;
171 inb(_RESET);
172 mdelay(RESETtime);
174 status = ASTATUS();
176 if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
177 BUGMSG(D_INIT_REASONS, "Status invalid (%Xh).\n", status);
178 goto err_out;
180 BUGMSG(D_INIT_REASONS, "Status after reset: %X\n", status);
182 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
184 BUGMSG(D_INIT_REASONS, "Status after reset acknowledged: %X\n", status);
186 status = ASTATUS();
188 if (status & RESETflag) {
189 BUGMSG(D_INIT_REASONS, "Eternal reset (status=%Xh)\n", status);
190 goto err_out;
192 outb((0x16 | IOMAPflag) & ~ENABLE16flag, _CONFIG);
194 /* Read first loc'n of memory */
196 outb(AUTOINCflag, _ADDR_HI);
197 outb(0, _ADDR_LO);
199 if ((status = inb(_MEMDATA)) != 0xd1) {
200 BUGMSG(D_INIT_REASONS, "Signature byte not found"
201 " (%Xh instead).\n", status);
202 goto err_out;
204 if (!dev->irq) {
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);
213 udelay(1);
214 outb(0, _INTMASK);
215 dev->irq = probe_irq_off(airqmask);
217 if (dev->irq <= 0) {
218 BUGMSG(D_INIT_REASONS, "Autoprobe IRQ failed\n");
219 goto err_out;
222 release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */
223 return com90io_found(dev);
225 err_out:
226 release_region(ioaddr, ARCNET_TOTAL_SIZE);
227 return -ENODEV;
231 /* Set up the struct net_device associated with this card. Called after
232 * probing succeeds.
234 static int __init com90io_found(struct net_device *dev)
236 struct arcnet_local *lp;
237 int ioaddr = dev->base_addr;
238 int err;
240 /* Reserve the irq */
241 if (request_irq(dev->irq, &arcnet_interrupt, 0, "arcnet (COM90xx-IO)", dev)) {
242 BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", dev->irq);
243 return -ENODEV;
245 /* Reserve the I/O region - guaranteed to work by check_region */
246 if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE, "arcnet (COM90xx-IO)")) {
247 free_irq(dev->irq, dev);
248 return -EBUSY;
251 lp = dev->priv;
252 lp->card_name = "COM90xx I/O";
253 lp->hw.command = com90io_command;
254 lp->hw.status = com90io_status;
255 lp->hw.intmask = com90io_setmask;
256 lp->hw.reset = com90io_reset;
257 lp->hw.owner = THIS_MODULE;
258 lp->hw.copy_to_card = com90io_copy_to_card;
259 lp->hw.copy_from_card = com90io_copy_from_card;
261 lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
262 SETCONF();
264 /* get and check the station ID from offset 1 in shmem */
266 dev->dev_addr[0] = get_buffer_byte(dev, 1);
268 err = register_netdev(dev);
269 if (err) {
270 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
271 free_irq(dev->irq, dev);
272 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
273 return err;
276 BUGMSG(D_NORMAL, "COM90IO: station %02Xh found at %03lXh, IRQ %d.\n",
277 dev->dev_addr[0], dev->base_addr, dev->irq);
279 return 0;
284 * Do a hardware reset on the card, and set up necessary registers.
286 * This should be called as little as possible, because it disrupts the
287 * token on the network (causes a RECON) and requires a significant delay.
289 * However, it does make sure the card is in a defined state.
291 static int com90io_reset(struct net_device *dev, int really_reset)
293 struct arcnet_local *lp = dev->priv;
294 short ioaddr = dev->base_addr;
296 BUGMSG(D_INIT, "Resetting %s (status=%02Xh)\n", dev->name, ASTATUS());
298 if (really_reset) {
299 /* reset the card */
300 inb(_RESET);
301 mdelay(RESETtime);
303 /* Set the thing to IO-mapped, 8-bit mode */
304 lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
305 SETCONF();
307 ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
308 ACOMMAND(CFLAGScmd | CONFIGclear);
310 /* verify that the ARCnet signature byte is present */
311 if (get_buffer_byte(dev, 0) != TESTvalue) {
312 BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n");
313 return 1;
315 /* enable extended (512-byte) packets */
316 ACOMMAND(CONFIGcmd | EXTconf);
318 /* done! return success. */
319 return 0;
323 static void com90io_command(struct net_device *dev, int cmd)
325 short ioaddr = dev->base_addr;
327 ACOMMAND(cmd);
331 static int com90io_status(struct net_device *dev)
333 short ioaddr = dev->base_addr;
335 return ASTATUS();
339 static void com90io_setmask(struct net_device *dev, int mask)
341 short ioaddr = dev->base_addr;
343 AINTMASK(mask);
346 static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
347 void *buf, int count)
349 TIME("put_whole_buffer", count, put_whole_buffer(dev, bufnum * 512 + offset, count, buf));
353 static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset,
354 void *buf, int count)
356 TIME("get_whole_buffer", count, get_whole_buffer(dev, bufnum * 512 + offset, count, buf));
359 static int io; /* use the insmod io= irq= shmem= options */
360 static int irq;
361 static char device[9]; /* use eg. device=arc1 to change name */
363 module_param(io, int, 0);
364 module_param(irq, int, 0);
365 module_param_string(device, device, sizeof(device), 0);
366 MODULE_LICENSE("GPL");
368 #ifndef MODULE
369 static int __init com90io_setup(char *s)
371 int ints[4];
372 s = get_options(s, 4, ints);
373 if (!ints[0])
374 return 0;
375 switch (ints[0]) {
376 default: /* ERROR */
377 printk("com90io: Too many arguments.\n");
378 case 2: /* IRQ */
379 irq = ints[2];
380 case 1: /* IO address */
381 io = ints[1];
383 if (*s)
384 snprintf(device, sizeof(device), "%s", s);
385 return 1;
387 __setup("com90io=", com90io_setup);
388 #endif
390 static struct net_device *my_dev;
392 static int __init com90io_init(void)
394 struct net_device *dev;
395 int err;
397 dev = alloc_arcdev(device);
398 if (!dev)
399 return -ENOMEM;
401 SET_MODULE_OWNER(dev);
403 dev->base_addr = io;
404 dev->irq = irq;
405 if (dev->irq == 2)
406 dev->irq = 9;
408 err = com90io_probe(dev);
410 if (err) {
411 free_netdev(dev);
412 return err;
415 my_dev = dev;
416 return 0;
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 /* Set the thing back to MMAP mode, in case the old driver is loaded later */
427 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
429 free_irq(dev->irq, dev);
430 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
431 free_netdev(dev);
434 module_init(com90io_init)
435 module_exit(com90io_exit)