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