Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux ARCnet driver - COM90xx chipset (IO-mapped buffers) |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 28 | |
| 29 | #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/kernel.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/moduleparam.h> |
| 34 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/delay.h> |
| 36 | #include <linux/netdevice.h> |
| 37 | #include <linux/bootmem.h> |
| 38 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 39 | #include <linux/interrupt.h> |
Joe Perches | 5e7ef91 | 2015-05-05 10:05:51 -0700 | [diff] [blame] | 40 | #include <linux/io.h> |
Joe Perches | 26c6d28 | 2015-05-05 10:06:03 -0700 | [diff] [blame] | 41 | |
| 42 | #include "arcdevice.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* Internal function declarations */ |
| 45 | |
| 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); |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 53 | static void com90io_copy_from_card(struct net_device *dev, int bufnum, |
| 54 | int offset, void *buf, int count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 62 | #define _INTMASK (ioaddr + 0) /* writable */ |
| 63 | #define _STATUS (ioaddr + 0) /* readable */ |
| 64 | #define _COMMAND (ioaddr + 1) /* writable, returns random vals on read (?) */ |
| 65 | #define _RESET (ioaddr + 8) /* software reset (on read) */ |
| 66 | #define _MEMDATA (ioaddr + 12) /* Data port for IO-mapped memory */ |
| 67 | #define _ADDR_HI (ioaddr + 15) /* Control registers for said */ |
| 68 | #define _ADDR_LO (ioaddr + 14) |
| 69 | #define _CONFIG (ioaddr + 2) /* Configuration register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | #undef ASTATUS |
| 72 | #undef ACOMMAND |
| 73 | #undef AINTMASK |
| 74 | |
| 75 | #define ASTATUS() inb(_STATUS) |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 76 | #define ACOMMAND(cmd) outb((cmd), _COMMAND) |
| 77 | #define AINTMASK(msk) outb((msk), _INTMASK) |
| 78 | #define SETCONF() outb((lp->config), _CONFIG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /**************************************************************************** |
| 81 | * * |
| 82 | * IO-mapped operation routines * |
| 83 | * * |
| 84 | ****************************************************************************/ |
| 85 | |
| 86 | #undef ONE_AT_A_TIME_TX |
| 87 | #undef ONE_AT_A_TIME_RX |
| 88 | |
| 89 | static u_char get_buffer_byte(struct net_device *dev, unsigned offset) |
| 90 | { |
| 91 | int ioaddr = dev->base_addr; |
| 92 | |
| 93 | outb(offset >> 8, _ADDR_HI); |
| 94 | outb(offset & 0xff, _ADDR_LO); |
| 95 | |
| 96 | return inb(_MEMDATA); |
| 97 | } |
| 98 | |
| 99 | #ifdef ONE_AT_A_TIME_TX |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 100 | static void put_buffer_byte(struct net_device *dev, unsigned offset, |
| 101 | u_char datum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | int ioaddr = dev->base_addr; |
| 104 | |
| 105 | outb(offset >> 8, _ADDR_HI); |
| 106 | outb(offset & 0xff, _ADDR_LO); |
| 107 | |
| 108 | outb(datum, _MEMDATA); |
| 109 | } |
| 110 | |
| 111 | #endif |
| 112 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 113 | static void get_whole_buffer(struct net_device *dev, unsigned offset, |
| 114 | unsigned length, char *dest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | int ioaddr = dev->base_addr; |
| 117 | |
| 118 | outb((offset >> 8) | AUTOINCflag, _ADDR_HI); |
| 119 | outb(offset & 0xff, _ADDR_LO); |
| 120 | |
| 121 | while (length--) |
| 122 | #ifdef ONE_AT_A_TIME_RX |
| 123 | *(dest++) = get_buffer_byte(dev, offset++); |
| 124 | #else |
| 125 | *(dest++) = inb(_MEMDATA); |
| 126 | #endif |
| 127 | } |
| 128 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 129 | static void put_whole_buffer(struct net_device *dev, unsigned offset, |
| 130 | unsigned length, char *dest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
| 132 | int ioaddr = dev->base_addr; |
| 133 | |
| 134 | outb((offset >> 8) | AUTOINCflag, _ADDR_HI); |
| 135 | outb(offset & 0xff, _ADDR_LO); |
| 136 | |
| 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 |
| 143 | } |
| 144 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 145 | /* We cannot probe for an IO mapped card either, although we can check that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | * it's where we were told it was, and even autoirq |
| 147 | */ |
| 148 | static int __init com90io_probe(struct net_device *dev) |
| 149 | { |
| 150 | int ioaddr = dev->base_addr, status; |
| 151 | unsigned long airqmask; |
| 152 | |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 153 | if (BUGLVL(D_NORMAL)) { |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 154 | pr_info("%s\n", "COM90xx IO-mapped mode support (by David Woodhouse et el.)"); |
| 155 | pr_info("E-mail me if you actually test this driver, please!\n"); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | if (!ioaddr) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 159 | arc_printk(D_NORMAL, dev, "No autoprobe for IO mapped cards; you must specify the base address!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | return -ENODEV; |
| 161 | } |
| 162 | if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 163 | arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n", |
| 164 | ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | return -ENXIO; |
| 166 | } |
| 167 | if (ASTATUS() == 0xFF) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 168 | arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n", |
| 169 | ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | goto err_out; |
| 171 | } |
| 172 | inb(_RESET); |
| 173 | mdelay(RESETtime); |
| 174 | |
| 175 | status = ASTATUS(); |
| 176 | |
| 177 | if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 178 | arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n", |
| 179 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | goto err_out; |
| 181 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 182 | arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear); |
| 185 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 186 | arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n", |
| 187 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | status = ASTATUS(); |
| 190 | |
| 191 | if (status & RESETflag) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 192 | arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n", |
| 193 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | goto err_out; |
| 195 | } |
| 196 | outb((0x16 | IOMAPflag) & ~ENABLE16flag, _CONFIG); |
| 197 | |
| 198 | /* Read first loc'n of memory */ |
| 199 | |
| 200 | outb(AUTOINCflag, _ADDR_HI); |
| 201 | outb(0, _ADDR_LO); |
| 202 | |
Joe Perches | 97464ed | 2015-05-05 10:05:59 -0700 | [diff] [blame] | 203 | status = inb(_MEMDATA); |
| 204 | if (status != 0xd1) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 205 | arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n", |
| 206 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | goto err_out; |
| 208 | } |
| 209 | if (!dev->irq) { |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 210 | /* if we do this, we're sure to get an IRQ since the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | * card has just reset and the NORXflag is on until |
| 212 | * we tell it to start receiving. |
| 213 | */ |
| 214 | |
| 215 | airqmask = probe_irq_on(); |
| 216 | outb(NORXflag, _INTMASK); |
| 217 | udelay(1); |
| 218 | outb(0, _INTMASK); |
| 219 | dev->irq = probe_irq_off(airqmask); |
| 220 | |
Dan Carpenter | 0a6efc7 | 2010-07-17 07:21:28 +0000 | [diff] [blame] | 221 | if ((int)dev->irq <= 0) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 222 | arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | goto err_out; |
| 224 | } |
| 225 | } |
| 226 | release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */ |
| 227 | return com90io_found(dev); |
| 228 | |
| 229 | err_out: |
| 230 | release_region(ioaddr, ARCNET_TOTAL_SIZE); |
| 231 | return -ENODEV; |
| 232 | } |
| 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | /* Set up the struct net_device associated with this card. Called after |
| 235 | * probing succeeds. |
| 236 | */ |
| 237 | static int __init com90io_found(struct net_device *dev) |
| 238 | { |
| 239 | struct arcnet_local *lp; |
| 240 | int ioaddr = dev->base_addr; |
| 241 | int err; |
| 242 | |
| 243 | /* Reserve the irq */ |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 244 | if (request_irq(dev->irq, arcnet_interrupt, 0, |
| 245 | "arcnet (COM90xx-IO)", dev)) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 246 | arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return -ENODEV; |
| 248 | } |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 249 | /* Reserve the I/O region */ |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 250 | if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE, |
| 251 | "arcnet (COM90xx-IO)")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | free_irq(dev->irq, dev); |
| 253 | return -EBUSY; |
| 254 | } |
| 255 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 256 | lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | lp->card_name = "COM90xx I/O"; |
| 258 | lp->hw.command = com90io_command; |
| 259 | lp->hw.status = com90io_status; |
| 260 | lp->hw.intmask = com90io_setmask; |
| 261 | lp->hw.reset = com90io_reset; |
| 262 | lp->hw.owner = THIS_MODULE; |
| 263 | lp->hw.copy_to_card = com90io_copy_to_card; |
| 264 | lp->hw.copy_from_card = com90io_copy_from_card; |
| 265 | |
| 266 | lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag; |
| 267 | SETCONF(); |
| 268 | |
| 269 | /* get and check the station ID from offset 1 in shmem */ |
| 270 | |
| 271 | dev->dev_addr[0] = get_buffer_byte(dev, 1); |
| 272 | |
| 273 | err = register_netdev(dev); |
| 274 | if (err) { |
| 275 | outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG); |
| 276 | free_irq(dev->irq, dev); |
| 277 | release_region(dev->base_addr, ARCNET_TOTAL_SIZE); |
| 278 | return err; |
| 279 | } |
| 280 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 281 | arc_printk(D_NORMAL, dev, "COM90IO: station %02Xh found at %03lXh, IRQ %d.\n", |
| 282 | dev->dev_addr[0], dev->base_addr, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 287 | /* Do a hardware reset on the card, and set up necessary registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | * |
| 289 | * This should be called as little as possible, because it disrupts the |
| 290 | * token on the network (causes a RECON) and requires a significant delay. |
| 291 | * |
| 292 | * However, it does make sure the card is in a defined state. |
| 293 | */ |
| 294 | static int com90io_reset(struct net_device *dev, int really_reset) |
| 295 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 296 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | short ioaddr = dev->base_addr; |
| 298 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 299 | arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n", |
| 300 | dev->name, ASTATUS()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | if (really_reset) { |
| 303 | /* reset the card */ |
| 304 | inb(_RESET); |
| 305 | mdelay(RESETtime); |
| 306 | } |
| 307 | /* Set the thing to IO-mapped, 8-bit mode */ |
| 308 | lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag; |
| 309 | SETCONF(); |
| 310 | |
| 311 | ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */ |
| 312 | ACOMMAND(CFLAGScmd | CONFIGclear); |
| 313 | |
| 314 | /* verify that the ARCnet signature byte is present */ |
| 315 | if (get_buffer_byte(dev, 0) != TESTvalue) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 316 | arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return 1; |
| 318 | } |
| 319 | /* enable extended (512-byte) packets */ |
| 320 | ACOMMAND(CONFIGcmd | EXTconf); |
| 321 | |
| 322 | /* done! return success. */ |
| 323 | return 0; |
| 324 | } |
| 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | static void com90io_command(struct net_device *dev, int cmd) |
| 327 | { |
| 328 | short ioaddr = dev->base_addr; |
| 329 | |
| 330 | ACOMMAND(cmd); |
| 331 | } |
| 332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | static int com90io_status(struct net_device *dev) |
| 334 | { |
| 335 | short ioaddr = dev->base_addr; |
| 336 | |
| 337 | return ASTATUS(); |
| 338 | } |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | static void com90io_setmask(struct net_device *dev, int mask) |
| 341 | { |
| 342 | short ioaddr = dev->base_addr; |
| 343 | |
| 344 | AINTMASK(mask); |
| 345 | } |
| 346 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 347 | static void com90io_copy_to_card(struct net_device *dev, int bufnum, |
| 348 | int offset, void *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 350 | TIME(dev, "put_whole_buffer", count, |
| 351 | put_whole_buffer(dev, bufnum * 512 + offset, count, buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 354 | static void com90io_copy_from_card(struct net_device *dev, int bufnum, |
| 355 | int offset, void *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 357 | TIME(dev, "get_whole_buffer", count, |
| 358 | get_whole_buffer(dev, bufnum * 512 + offset, count, buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static int io; /* use the insmod io= irq= shmem= options */ |
| 362 | static int irq; |
| 363 | static char device[9]; /* use eg. device=arc1 to change name */ |
| 364 | |
| 365 | module_param(io, int, 0); |
| 366 | module_param(irq, int, 0); |
| 367 | module_param_string(device, device, sizeof(device), 0); |
| 368 | MODULE_LICENSE("GPL"); |
| 369 | |
| 370 | #ifndef MODULE |
| 371 | static int __init com90io_setup(char *s) |
| 372 | { |
| 373 | int ints[4]; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | s = get_options(s, 4, ints); |
| 376 | if (!ints[0]) |
| 377 | return 0; |
| 378 | switch (ints[0]) { |
| 379 | default: /* ERROR */ |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 380 | pr_err("Too many arguments\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | case 2: /* IRQ */ |
| 382 | irq = ints[2]; |
| 383 | case 1: /* IO address */ |
| 384 | io = ints[1]; |
| 385 | } |
| 386 | if (*s) |
| 387 | snprintf(device, sizeof(device), "%s", s); |
| 388 | return 1; |
| 389 | } |
| 390 | __setup("com90io=", com90io_setup); |
| 391 | #endif |
| 392 | |
| 393 | static struct net_device *my_dev; |
| 394 | |
| 395 | static int __init com90io_init(void) |
| 396 | { |
| 397 | struct net_device *dev; |
| 398 | int err; |
| 399 | |
| 400 | dev = alloc_arcdev(device); |
| 401 | if (!dev) |
| 402 | return -ENOMEM; |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | dev->base_addr = io; |
| 405 | dev->irq = irq; |
| 406 | if (dev->irq == 2) |
| 407 | dev->irq = 9; |
| 408 | |
| 409 | err = com90io_probe(dev); |
| 410 | |
| 411 | if (err) { |
| 412 | free_netdev(dev); |
| 413 | return err; |
| 414 | } |
| 415 | |
| 416 | my_dev = dev; |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static void __exit com90io_exit(void) |
| 421 | { |
| 422 | struct net_device *dev = my_dev; |
| 423 | int ioaddr = dev->base_addr; |
| 424 | |
| 425 | unregister_netdev(dev); |
| 426 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 427 | /* In case the old driver is loaded later, |
| 428 | * set the thing back to MMAP mode |
| 429 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | outb((inb(_CONFIG) & ~IOMAPflag), _CONFIG); |
| 431 | |
| 432 | free_irq(dev->irq, dev); |
| 433 | release_region(dev->base_addr, ARCNET_TOTAL_SIZE); |
| 434 | free_netdev(dev); |
| 435 | } |
| 436 | |
| 437 | module_init(com90io_init) |
| 438 | module_exit(com90io_exit) |