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 | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 80 | static u_char get_buffer_byte(struct net_device *dev, unsigned offset) |
| 81 | { |
| 82 | int ioaddr = dev->base_addr; |
| 83 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 84 | arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI); |
| 85 | arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 87 | return arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | #ifdef ONE_AT_A_TIME_TX |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 91 | static void put_buffer_byte(struct net_device *dev, unsigned offset, |
| 92 | u_char datum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
| 94 | int ioaddr = dev->base_addr; |
| 95 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 96 | arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI); |
| 97 | arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 99 | arcnet_outb(datum, ioaddr, COM9026_REG_RW_MEMDATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | #endif |
| 103 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 104 | static void get_whole_buffer(struct net_device *dev, unsigned offset, |
| 105 | unsigned length, char *dest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | int ioaddr = dev->base_addr; |
| 108 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 109 | arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI); |
| 110 | arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | while (length--) |
| 113 | #ifdef ONE_AT_A_TIME_RX |
| 114 | *(dest++) = get_buffer_byte(dev, offset++); |
| 115 | #else |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 116 | *(dest++) = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #endif |
| 118 | } |
| 119 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 120 | static void put_whole_buffer(struct net_device *dev, unsigned offset, |
| 121 | unsigned length, char *dest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | int ioaddr = dev->base_addr; |
| 124 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 125 | arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI); |
| 126 | arcnet_outb(offset & 0xff, ioaddr,COM9026_REG_W_ADDR_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | while (length--) |
| 129 | #ifdef ONE_AT_A_TIME_TX |
| 130 | put_buffer_byte(dev, offset++, *(dest++)); |
| 131 | #else |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 132 | arcnet_outb(*(dest++), ioaddr, COM9026_REG_RW_MEMDATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #endif |
| 134 | } |
| 135 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 136 | /* 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] | 137 | * it's where we were told it was, and even autoirq |
| 138 | */ |
| 139 | static int __init com90io_probe(struct net_device *dev) |
| 140 | { |
| 141 | int ioaddr = dev->base_addr, status; |
| 142 | unsigned long airqmask; |
| 143 | |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 144 | if (BUGLVL(D_NORMAL)) { |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 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"); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 147 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | if (!ioaddr) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 150 | 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] | 151 | return -ENODEV; |
| 152 | } |
| 153 | if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 154 | arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n", |
| 155 | ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | return -ENXIO; |
| 157 | } |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 158 | if (arcnet_inb(ioaddr, COM9026_REG_R_STATUS) == 0xFF) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 159 | arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n", |
| 160 | ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | goto err_out; |
| 162 | } |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 163 | arcnet_inb(ioaddr, COM9026_REG_R_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | mdelay(RESETtime); |
| 165 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 166 | status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 169 | arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n", |
| 170 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | goto err_out; |
| 172 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 173 | arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 175 | arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear, |
| 176 | ioaddr, COM9026_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 178 | arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n", |
| 179 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 181 | status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | if (status & RESETflag) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 184 | arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n", |
| 185 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | goto err_out; |
| 187 | } |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 188 | arcnet_outb((0x16 | IOMAPflag) & ~ENABLE16flag, |
| 189 | ioaddr, COM9026_REG_RW_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | /* Read first loc'n of memory */ |
| 192 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 193 | arcnet_outb(AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI); |
| 194 | arcnet_outb(0, ioaddr, COM9026_REG_W_ADDR_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 196 | status = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA); |
Joe Perches | 97464ed | 2015-05-05 10:05:59 -0700 | [diff] [blame] | 197 | if (status != 0xd1) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 198 | arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n", |
| 199 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | goto err_out; |
| 201 | } |
| 202 | if (!dev->irq) { |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 203 | /* 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] | 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(); |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 209 | arcnet_outb(NORXflag, ioaddr, COM9026_REG_W_INTMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | udelay(1); |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 211 | arcnet_outb(0, ioaddr, COM9026_REG_W_INTMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | dev->irq = probe_irq_off(airqmask); |
| 213 | |
Dan Carpenter | 0a6efc7 | 2010-07-17 07:21:28 +0000 | [diff] [blame] | 214 | if ((int)dev->irq <= 0) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 215 | arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | goto err_out; |
| 217 | } |
| 218 | } |
| 219 | release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */ |
| 220 | return com90io_found(dev); |
| 221 | |
| 222 | err_out: |
| 223 | release_region(ioaddr, ARCNET_TOTAL_SIZE); |
| 224 | return -ENODEV; |
| 225 | } |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* Set up the struct net_device associated with this card. Called after |
| 228 | * probing succeeds. |
| 229 | */ |
| 230 | static 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 */ |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 237 | if (request_irq(dev->irq, arcnet_interrupt, 0, |
| 238 | "arcnet (COM90xx-IO)", dev)) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 239 | 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] | 240 | return -ENODEV; |
| 241 | } |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 242 | /* Reserve the I/O region */ |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 243 | if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE, |
| 244 | "arcnet (COM90xx-IO)")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | free_irq(dev->irq, dev); |
| 246 | return -EBUSY; |
| 247 | } |
| 248 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 249 | lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 260 | arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) { |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 268 | arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag, |
| 269 | ioaddr, COM9026_REG_RW_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | free_irq(dev->irq, dev); |
| 271 | release_region(dev->base_addr, ARCNET_TOTAL_SIZE); |
| 272 | return err; |
| 273 | } |
| 274 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 281 | /* Do a hardware reset on the card, and set up necessary registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
| 288 | static int com90io_reset(struct net_device *dev, int really_reset) |
| 289 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 290 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | short ioaddr = dev->base_addr; |
| 292 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 293 | arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n", |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 294 | dev->name, arcnet_inb(ioaddr, COM9026_REG_R_STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | if (really_reset) { |
| 297 | /* reset the card */ |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 298 | arcnet_inb(ioaddr, COM9026_REG_R_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | mdelay(RESETtime); |
| 300 | } |
| 301 | /* Set the thing to IO-mapped, 8-bit mode */ |
| 302 | lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag; |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 303 | arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* verify that the ARCnet signature byte is present */ |
| 310 | if (get_buffer_byte(dev, 0) != TESTvalue) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 311 | arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | return 1; |
| 313 | } |
| 314 | /* enable extended (512-byte) packets */ |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 315 | arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /* done! return success. */ |
| 317 | return 0; |
| 318 | } |
| 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | static void com90io_command(struct net_device *dev, int cmd) |
| 321 | { |
| 322 | short ioaddr = dev->base_addr; |
| 323 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 324 | arcnet_outb(cmd, ioaddr, COM9026_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | static int com90io_status(struct net_device *dev) |
| 328 | { |
| 329 | short ioaddr = dev->base_addr; |
| 330 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 331 | return arcnet_inb(ioaddr, COM9026_REG_R_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | static void com90io_setmask(struct net_device *dev, int mask) |
| 335 | { |
| 336 | short ioaddr = dev->base_addr; |
| 337 | |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 338 | arcnet_outb(mask, ioaddr, COM9026_REG_W_INTMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 341 | static void com90io_copy_to_card(struct net_device *dev, int bufnum, |
| 342 | int offset, void *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 344 | TIME(dev, "put_whole_buffer", count, |
| 345 | put_whole_buffer(dev, bufnum * 512 + offset, count, buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 348 | static void com90io_copy_from_card(struct net_device *dev, int bufnum, |
| 349 | int offset, void *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 351 | TIME(dev, "get_whole_buffer", count, |
| 352 | get_whole_buffer(dev, bufnum * 512 + offset, count, buf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static int io; /* use the insmod io= irq= shmem= options */ |
| 356 | static int irq; |
| 357 | static char device[9]; /* use eg. device=arc1 to change name */ |
| 358 | |
| 359 | module_param(io, int, 0); |
| 360 | module_param(irq, int, 0); |
| 361 | module_param_string(device, device, sizeof(device), 0); |
| 362 | MODULE_LICENSE("GPL"); |
| 363 | |
| 364 | #ifndef MODULE |
| 365 | static int __init com90io_setup(char *s) |
| 366 | { |
| 367 | int ints[4]; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | s = get_options(s, 4, ints); |
| 370 | if (!ints[0]) |
| 371 | return 0; |
| 372 | switch (ints[0]) { |
| 373 | default: /* ERROR */ |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 374 | pr_err("Too many arguments\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 387 | static struct net_device *my_dev; |
| 388 | |
| 389 | static 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 414 | static 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 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 421 | /* In case the old driver is loaded later, |
| 422 | * set the thing back to MMAP mode |
| 423 | */ |
Joe Perches | f0b9c27 | 2015-05-05 10:06:07 -0700 | [diff] [blame^] | 424 | arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag, |
| 425 | ioaddr, COM9026_REG_RW_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | free_irq(dev->irq, dev); |
| 428 | release_region(dev->base_addr, ARCNET_TOTAL_SIZE); |
| 429 | free_netdev(dev); |
| 430 | } |
| 431 | |
| 432 | module_init(com90io_init) |
| 433 | module_exit(com90io_exit) |