arcnet: Convert arcnet_dump_skb macro to static inline
[deliverable/linux.git] / drivers / net / arcnet / com90io.c
CommitLineData
1da177e4
LT
1/*
2 * Linux ARCnet driver - COM90xx chipset (IO-mapped buffers)
cb334648 3 *
1da177e4
LT
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.
8 *
9 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
10 * for sponsoring the further development of this driver.
11 *
12 * **********************
13 *
14 * The original copyright of skeleton.c was as follows:
15 *
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.
21 *
22 * **********************
23 *
24 * For more details, see drivers/net/arcnet.c
25 *
26 * **********************
27 */
05a24b23
JP
28
29#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
30
1da177e4
LT
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/moduleparam.h>
34#include <linux/ioport.h>
1da177e4
LT
35#include <linux/delay.h>
36#include <linux/netdevice.h>
37#include <linux/bootmem.h>
38#include <linux/init.h>
a6b7a407 39#include <linux/interrupt.h>
5e7ef913 40#include <linux/io.h>
1da177e4
LT
41#include <linux/arcdevice.h>
42
1da177e4
LT
43/* Internal function declarations */
44
45static int com90io_found(struct net_device *dev);
46static void com90io_command(struct net_device *dev, int command);
47static int com90io_status(struct net_device *dev);
48static void com90io_setmask(struct net_device *dev, int mask);
49static int com90io_reset(struct net_device *dev, int really_reset);
50static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
51 void *buf, int count);
52static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset,
53 void *buf, int count);
54
1da177e4
LT
55/* Handy defines for ARCnet specific stuff */
56
57/* The number of low I/O ports used by the card. */
58#define ARCNET_TOTAL_SIZE 16
59
60/* COM 9026 controller chip --> ARCnet register addresses */
cb334648
JP
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 */
1da177e4
LT
69
70#undef ASTATUS
71#undef ACOMMAND
72#undef AINTMASK
73
74#define ASTATUS() inb(_STATUS)
cb334648
JP
75#define ACOMMAND(cmd) outb((cmd), _COMMAND)
76#define AINTMASK(msk) outb((msk), _INTMASK)
77#define SETCONF() outb((lp->config), _CONFIG)
1da177e4 78
1da177e4
LT
79/****************************************************************************
80 * *
81 * IO-mapped operation routines *
82 * *
83 ****************************************************************************/
84
85#undef ONE_AT_A_TIME_TX
86#undef ONE_AT_A_TIME_RX
87
88static u_char get_buffer_byte(struct net_device *dev, unsigned offset)
89{
90 int ioaddr = dev->base_addr;
91
92 outb(offset >> 8, _ADDR_HI);
93 outb(offset & 0xff, _ADDR_LO);
94
95 return inb(_MEMDATA);
96}
97
98#ifdef ONE_AT_A_TIME_TX
99static void put_buffer_byte(struct net_device *dev, unsigned offset, u_char datum)
100{
101 int ioaddr = dev->base_addr;
102
103 outb(offset >> 8, _ADDR_HI);
104 outb(offset & 0xff, _ADDR_LO);
105
106 outb(datum, _MEMDATA);
107}
108
109#endif
110
1da177e4
LT
111static void get_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest)
112{
113 int ioaddr = dev->base_addr;
114
115 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
116 outb(offset & 0xff, _ADDR_LO);
117
118 while (length--)
119#ifdef ONE_AT_A_TIME_RX
120 *(dest++) = get_buffer_byte(dev, offset++);
121#else
122 *(dest++) = inb(_MEMDATA);
123#endif
124}
125
126static void put_whole_buffer(struct net_device *dev, unsigned offset, unsigned length, char *dest)
127{
128 int ioaddr = dev->base_addr;
129
130 outb((offset >> 8) | AUTOINCflag, _ADDR_HI);
131 outb(offset & 0xff, _ADDR_LO);
132
133 while (length--)
134#ifdef ONE_AT_A_TIME_TX
135 put_buffer_byte(dev, offset++, *(dest++));
136#else
137 outb(*(dest++), _MEMDATA);
138#endif
139}
140
f2f0a16b 141/* We cannot probe for an IO mapped card either, although we can check that
1da177e4
LT
142 * it's where we were told it was, and even autoirq
143 */
144static int __init com90io_probe(struct net_device *dev)
145{
146 int ioaddr = dev->base_addr, status;
147 unsigned long airqmask;
148
72aeea48 149 if (BUGLVL(D_NORMAL)) {
05a24b23
JP
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");
72aeea48 152 }
1da177e4
LT
153
154 if (!ioaddr) {
a34c0932 155 arc_printk(D_NORMAL, dev, "No autoprobe for IO mapped cards; you must specify the base address!\n");
1da177e4
LT
156 return -ENODEV;
157 }
158 if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
a34c0932
JP
159 arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n",
160 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
1da177e4
LT
161 return -ENXIO;
162 }
163 if (ASTATUS() == 0xFF) {
a34c0932
JP
164 arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n",
165 ioaddr);
1da177e4
LT
166 goto err_out;
167 }
168 inb(_RESET);
169 mdelay(RESETtime);
170
171 status = ASTATUS();
172
173 if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
a34c0932
JP
174 arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n",
175 status);
1da177e4
LT
176 goto err_out;
177 }
a34c0932 178 arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status);
1da177e4
LT
179
180 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
181
a34c0932
JP
182 arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n",
183 status);
1da177e4
LT
184
185 status = ASTATUS();
186
187 if (status & RESETflag) {
a34c0932
JP
188 arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n",
189 status);
1da177e4
LT
190 goto err_out;
191 }
192 outb((0x16 | IOMAPflag) & ~ENABLE16flag, _CONFIG);
193
194 /* Read first loc'n of memory */
195
196 outb(AUTOINCflag, _ADDR_HI);
197 outb(0, _ADDR_LO);
198
97464edd
JP
199 status = inb(_MEMDATA);
200 if (status != 0xd1) {
a34c0932
JP
201 arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n",
202 status);
1da177e4
LT
203 goto err_out;
204 }
205 if (!dev->irq) {
f2f0a16b 206 /* if we do this, we're sure to get an IRQ since the
1da177e4
LT
207 * card has just reset and the NORXflag is on until
208 * we tell it to start receiving.
209 */
210
211 airqmask = probe_irq_on();
212 outb(NORXflag, _INTMASK);
213 udelay(1);
214 outb(0, _INTMASK);
215 dev->irq = probe_irq_off(airqmask);
216
0a6efc78 217 if ((int)dev->irq <= 0) {
a34c0932 218 arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n");
1da177e4
LT
219 goto err_out;
220 }
221 }
222 release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */
223 return com90io_found(dev);
224
225err_out:
226 release_region(ioaddr, ARCNET_TOTAL_SIZE);
227 return -ENODEV;
228}
229
1da177e4
LT
230/* Set up the struct net_device associated with this card. Called after
231 * probing succeeds.
232 */
233static int __init com90io_found(struct net_device *dev)
234{
235 struct arcnet_local *lp;
236 int ioaddr = dev->base_addr;
237 int err;
238
239 /* Reserve the irq */
a0607fd3 240 if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (COM90xx-IO)", dev)) {
a34c0932 241 arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
1da177e4
LT
242 return -ENODEV;
243 }
fb911ee8 244 /* Reserve the I/O region */
1da177e4
LT
245 if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE, "arcnet (COM90xx-IO)")) {
246 free_irq(dev->irq, dev);
247 return -EBUSY;
248 }
249
454d7c9b 250 lp = netdev_priv(dev);
1da177e4
LT
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;
259
260 lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
261 SETCONF();
262
263 /* get and check the station ID from offset 1 in shmem */
264
265 dev->dev_addr[0] = get_buffer_byte(dev, 1);
266
267 err = register_netdev(dev);
268 if (err) {
269 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
270 free_irq(dev->irq, dev);
271 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
272 return err;
273 }
274
a34c0932
JP
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);
1da177e4
LT
277
278 return 0;
279}
280
f2f0a16b 281/* Do a hardware reset on the card, and set up necessary registers.
1da177e4
LT
282 *
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.
285 *
286 * However, it does make sure the card is in a defined state.
287 */
288static int com90io_reset(struct net_device *dev, int really_reset)
289{
454d7c9b 290 struct arcnet_local *lp = netdev_priv(dev);
1da177e4
LT
291 short ioaddr = dev->base_addr;
292
a34c0932
JP
293 arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
294 dev->name, ASTATUS());
1da177e4
LT
295
296 if (really_reset) {
297 /* reset the card */
298 inb(_RESET);
299 mdelay(RESETtime);
300 }
301 /* Set the thing to IO-mapped, 8-bit mode */
302 lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
303 SETCONF();
304
305 ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
306 ACOMMAND(CFLAGScmd | CONFIGclear);
307
308 /* verify that the ARCnet signature byte is present */
309 if (get_buffer_byte(dev, 0) != TESTvalue) {
a34c0932 310 arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
1da177e4
LT
311 return 1;
312 }
313 /* enable extended (512-byte) packets */
314 ACOMMAND(CONFIGcmd | EXTconf);
315
316 /* done! return success. */
317 return 0;
318}
319
1da177e4
LT
320static void com90io_command(struct net_device *dev, int cmd)
321{
322 short ioaddr = dev->base_addr;
323
324 ACOMMAND(cmd);
325}
326
1da177e4
LT
327static int com90io_status(struct net_device *dev)
328{
329 short ioaddr = dev->base_addr;
330
331 return ASTATUS();
332}
333
1da177e4
LT
334static void com90io_setmask(struct net_device *dev, int mask)
335{
336 short ioaddr = dev->base_addr;
337
338 AINTMASK(mask);
339}
340
341static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
342 void *buf, int count)
343{
a34c0932
JP
344 TIME(dev, "put_whole_buffer", count,
345 put_whole_buffer(dev, bufnum * 512 + offset, count, buf));
1da177e4
LT
346}
347
1da177e4
LT
348static void com90io_copy_from_card(struct net_device *dev, int bufnum, int offset,
349 void *buf, int count)
350{
a34c0932
JP
351 TIME(dev, "get_whole_buffer", count,
352 get_whole_buffer(dev, bufnum * 512 + offset, count, buf));
1da177e4
LT
353}
354
355static int io; /* use the insmod io= irq= shmem= options */
356static int irq;
357static char device[9]; /* use eg. device=arc1 to change name */
358
359module_param(io, int, 0);
360module_param(irq, int, 0);
361module_param_string(device, device, sizeof(device), 0);
362MODULE_LICENSE("GPL");
363
364#ifndef MODULE
365static int __init com90io_setup(char *s)
366{
367 int ints[4];
01a1d5ac 368
1da177e4
LT
369 s = get_options(s, 4, ints);
370 if (!ints[0])
371 return 0;
372 switch (ints[0]) {
373 default: /* ERROR */
05a24b23 374 pr_err("Too many arguments\n");
1da177e4
LT
375 case 2: /* IRQ */
376 irq = ints[2];
377 case 1: /* IO address */
378 io = ints[1];
379 }
380 if (*s)
381 snprintf(device, sizeof(device), "%s", s);
382 return 1;
383}
384__setup("com90io=", com90io_setup);
385#endif
386
387static struct net_device *my_dev;
388
389static int __init com90io_init(void)
390{
391 struct net_device *dev;
392 int err;
393
394 dev = alloc_arcdev(device);
395 if (!dev)
396 return -ENOMEM;
397
1da177e4
LT
398 dev->base_addr = io;
399 dev->irq = irq;
400 if (dev->irq == 2)
401 dev->irq = 9;
402
403 err = com90io_probe(dev);
404
405 if (err) {
406 free_netdev(dev);
407 return err;
408 }
409
410 my_dev = dev;
411 return 0;
412}
413
414static void __exit com90io_exit(void)
415{
416 struct net_device *dev = my_dev;
417 int ioaddr = dev->base_addr;
418
419 unregister_netdev(dev);
420
421 /* Set the thing back to MMAP mode, in case the old driver is loaded later */
422 outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG);
423
424 free_irq(dev->irq, dev);
425 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
426 free_netdev(dev);
427}
428
429module_init(com90io_init)
430module_exit(com90io_exit)
This page took 0.882501 seconds and 5 git commands to generate.