]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/arcnet/com90io.c
arcnet: Remove function pointer macro indirections
[mirror_ubuntu-artful-kernel.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>
26c6d281
JP
41
42#include "arcdevice.h"
1da177e4 43
1da177e4
LT
44/* Internal function declarations */
45
46static int com90io_found(struct net_device *dev);
47static void com90io_command(struct net_device *dev, int command);
48static int com90io_status(struct net_device *dev);
49static void com90io_setmask(struct net_device *dev, int mask);
50static int com90io_reset(struct net_device *dev, int really_reset);
51static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
52 void *buf, int count);
d6d7d3ed
JP
53static void com90io_copy_from_card(struct net_device *dev, int bufnum,
54 int offset, void *buf, int count);
1da177e4 55
1da177e4
LT
56/* Handy defines for ARCnet specific stuff */
57
58/* The number of low I/O ports used by the card. */
59#define ARCNET_TOTAL_SIZE 16
60
61/* COM 9026 controller chip --> ARCnet register addresses */
f0b9c27c
JP
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
1da177e4 70
1da177e4
LT
71/****************************************************************************
72 * *
73 * IO-mapped operation routines *
74 * *
75 ****************************************************************************/
76
77#undef ONE_AT_A_TIME_TX
78#undef ONE_AT_A_TIME_RX
79
80static u_char get_buffer_byte(struct net_device *dev, unsigned offset)
81{
82 int ioaddr = dev->base_addr;
83
f0b9c27c
JP
84 arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI);
85 arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
1da177e4 86
f0b9c27c 87 return arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
1da177e4
LT
88}
89
90#ifdef ONE_AT_A_TIME_TX
d6d7d3ed
JP
91static void put_buffer_byte(struct net_device *dev, unsigned offset,
92 u_char datum)
1da177e4
LT
93{
94 int ioaddr = dev->base_addr;
95
f0b9c27c
JP
96 arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI);
97 arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
1da177e4 98
f0b9c27c 99 arcnet_outb(datum, ioaddr, COM9026_REG_RW_MEMDATA);
1da177e4
LT
100}
101
102#endif
103
d6d7d3ed
JP
104static void get_whole_buffer(struct net_device *dev, unsigned offset,
105 unsigned length, char *dest)
1da177e4
LT
106{
107 int ioaddr = dev->base_addr;
108
f0b9c27c
JP
109 arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
110 arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
1da177e4
LT
111
112 while (length--)
113#ifdef ONE_AT_A_TIME_RX
114 *(dest++) = get_buffer_byte(dev, offset++);
115#else
f0b9c27c 116 *(dest++) = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
1da177e4
LT
117#endif
118}
119
d6d7d3ed
JP
120static void put_whole_buffer(struct net_device *dev, unsigned offset,
121 unsigned length, char *dest)
1da177e4
LT
122{
123 int ioaddr = dev->base_addr;
124
f0b9c27c
JP
125 arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
126 arcnet_outb(offset & 0xff, ioaddr,COM9026_REG_W_ADDR_LO);
1da177e4
LT
127
128 while (length--)
129#ifdef ONE_AT_A_TIME_TX
130 put_buffer_byte(dev, offset++, *(dest++));
131#else
f0b9c27c 132 arcnet_outb(*(dest++), ioaddr, COM9026_REG_RW_MEMDATA);
1da177e4
LT
133#endif
134}
135
f2f0a16b 136/* We cannot probe for an IO mapped card either, although we can check that
1da177e4
LT
137 * it's where we were told it was, and even autoirq
138 */
139static int __init com90io_probe(struct net_device *dev)
140{
141 int ioaddr = dev->base_addr, status;
142 unsigned long airqmask;
143
72aeea48 144 if (BUGLVL(D_NORMAL)) {
05a24b23
JP
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");
72aeea48 147 }
1da177e4
LT
148
149 if (!ioaddr) {
a34c0932 150 arc_printk(D_NORMAL, dev, "No autoprobe for IO mapped cards; you must specify the base address!\n");
1da177e4
LT
151 return -ENODEV;
152 }
153 if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
a34c0932
JP
154 arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n",
155 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
1da177e4
LT
156 return -ENXIO;
157 }
f0b9c27c 158 if (arcnet_inb(ioaddr, COM9026_REG_R_STATUS) == 0xFF) {
a34c0932
JP
159 arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n",
160 ioaddr);
1da177e4
LT
161 goto err_out;
162 }
f0b9c27c 163 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
1da177e4
LT
164 mdelay(RESETtime);
165
f0b9c27c 166 status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
1da177e4
LT
167
168 if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
a34c0932
JP
169 arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n",
170 status);
1da177e4
LT
171 goto err_out;
172 }
a34c0932 173 arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status);
1da177e4 174
f0b9c27c
JP
175 arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
176 ioaddr, COM9026_REG_W_COMMAND);
1da177e4 177
a34c0932
JP
178 arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n",
179 status);
1da177e4 180
f0b9c27c 181 status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
1da177e4
LT
182
183 if (status & RESETflag) {
a34c0932
JP
184 arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n",
185 status);
1da177e4
LT
186 goto err_out;
187 }
f0b9c27c
JP
188 arcnet_outb((0x16 | IOMAPflag) & ~ENABLE16flag,
189 ioaddr, COM9026_REG_RW_CONFIG);
1da177e4
LT
190
191 /* Read first loc'n of memory */
192
f0b9c27c
JP
193 arcnet_outb(AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
194 arcnet_outb(0, ioaddr, COM9026_REG_W_ADDR_LO);
1da177e4 195
f0b9c27c 196 status = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
97464edd 197 if (status != 0xd1) {
a34c0932
JP
198 arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n",
199 status);
1da177e4
LT
200 goto err_out;
201 }
202 if (!dev->irq) {
f2f0a16b 203 /* if we do this, we're sure to get an IRQ since the
1da177e4
LT
204 * card has just reset and the NORXflag is on until
205 * we tell it to start receiving.
206 */
207
208 airqmask = probe_irq_on();
f0b9c27c 209 arcnet_outb(NORXflag, ioaddr, COM9026_REG_W_INTMASK);
1da177e4 210 udelay(1);
f0b9c27c 211 arcnet_outb(0, ioaddr, COM9026_REG_W_INTMASK);
1da177e4
LT
212 dev->irq = probe_irq_off(airqmask);
213
0a6efc78 214 if ((int)dev->irq <= 0) {
a34c0932 215 arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n");
1da177e4
LT
216 goto err_out;
217 }
218 }
219 release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */
220 return com90io_found(dev);
221
222err_out:
223 release_region(ioaddr, ARCNET_TOTAL_SIZE);
224 return -ENODEV;
225}
226
1da177e4
LT
227/* Set up the struct net_device associated with this card. Called after
228 * probing succeeds.
229 */
230static int __init com90io_found(struct net_device *dev)
231{
232 struct arcnet_local *lp;
233 int ioaddr = dev->base_addr;
234 int err;
235
236 /* Reserve the irq */
d6d7d3ed
JP
237 if (request_irq(dev->irq, arcnet_interrupt, 0,
238 "arcnet (COM90xx-IO)", dev)) {
a34c0932 239 arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
1da177e4
LT
240 return -ENODEV;
241 }
fb911ee8 242 /* Reserve the I/O region */
d6d7d3ed
JP
243 if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE,
244 "arcnet (COM90xx-IO)")) {
1da177e4
LT
245 free_irq(dev->irq, dev);
246 return -EBUSY;
247 }
248
454d7c9b 249 lp = netdev_priv(dev);
1da177e4
LT
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;
258
259 lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
f0b9c27c 260 arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG);
1da177e4
LT
261
262 /* get and check the station ID from offset 1 in shmem */
263
264 dev->dev_addr[0] = get_buffer_byte(dev, 1);
265
266 err = register_netdev(dev);
267 if (err) {
f0b9c27c
JP
268 arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag,
269 ioaddr, COM9026_REG_RW_CONFIG);
1da177e4
LT
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 293 arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
f0b9c27c 294 dev->name, arcnet_inb(ioaddr, COM9026_REG_R_STATUS));
1da177e4
LT
295
296 if (really_reset) {
297 /* reset the card */
f0b9c27c 298 arcnet_inb(ioaddr, COM9026_REG_R_RESET);
1da177e4
LT
299 mdelay(RESETtime);
300 }
301 /* Set the thing to IO-mapped, 8-bit mode */
302 lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
f0b9c27c 303 arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG);
1da177e4 304
f0b9c27c
JP
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);
1da177e4
LT
308
309 /* verify that the ARCnet signature byte is present */
310 if (get_buffer_byte(dev, 0) != TESTvalue) {
a34c0932 311 arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
1da177e4
LT
312 return 1;
313 }
314 /* enable extended (512-byte) packets */
f0b9c27c 315 arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
1da177e4
LT
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
f0b9c27c 324 arcnet_outb(cmd, ioaddr, COM9026_REG_W_COMMAND);
1da177e4
LT
325}
326
1da177e4
LT
327static int com90io_status(struct net_device *dev)
328{
329 short ioaddr = dev->base_addr;
330
f0b9c27c 331 return arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
1da177e4
LT
332}
333
1da177e4
LT
334static void com90io_setmask(struct net_device *dev, int mask)
335{
336 short ioaddr = dev->base_addr;
337
f0b9c27c 338 arcnet_outb(mask, ioaddr, COM9026_REG_W_INTMASK);
1da177e4
LT
339}
340
d6d7d3ed
JP
341static void com90io_copy_to_card(struct net_device *dev, int bufnum,
342 int offset, void *buf, int count)
1da177e4 343{
a34c0932
JP
344 TIME(dev, "put_whole_buffer", count,
345 put_whole_buffer(dev, bufnum * 512 + offset, count, buf));
1da177e4
LT
346}
347
d6d7d3ed
JP
348static void com90io_copy_from_card(struct net_device *dev, int bufnum,
349 int offset, void *buf, int count)
1da177e4 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
d6d7d3ed
JP
421 /* In case the old driver is loaded later,
422 * set the thing back to MMAP mode
423 */
f0b9c27c
JP
424 arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag,
425 ioaddr, COM9026_REG_RW_CONFIG);
1da177e4
LT
426
427 free_irq(dev->irq, dev);
428 release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
429 free_netdev(dev);
430}
431
432module_init(com90io_init)
433module_exit(com90io_exit)