Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux ARCnet driver - "RIM I" (entirely mem-mapped) cards |
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 1994-1999 by Avery Pennarun. |
| 5 | * Written 1999-2000 by Martin Mares <mj@ucw.cz>. |
| 6 | * Derived from skeleton.c by Donald Becker. |
| 7 | * |
| 8 | * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com) |
| 9 | * for sponsoring the further development of this driver. |
| 10 | * |
| 11 | * ********************** |
| 12 | * |
| 13 | * The original copyright of skeleton.c was as follows: |
| 14 | * |
| 15 | * skeleton.c Written 1993 by Donald Becker. |
| 16 | * Copyright 1993 United States Government as represented by the |
| 17 | * Director, National Security Agency. This software may only be used |
| 18 | * and distributed according to the terms of the GNU General Public License as |
| 19 | * modified by SRC, incorporated herein by reference. |
| 20 | * |
| 21 | * ********************** |
| 22 | * |
| 23 | * For more details, see drivers/net/arcnet.c |
| 24 | * |
| 25 | * ********************** |
| 26 | */ |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 27 | |
| 28 | #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/moduleparam.h> |
| 33 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/delay.h> |
| 35 | #include <linux/netdevice.h> |
Mike Rapoport | 57c8a66 | 2018-10-30 15:09:49 -0700 | [diff] [blame] | 36 | #include <linux/memblock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 38 | #include <linux/interrupt.h> |
Joe Perches | 5e7ef91 | 2015-05-05 10:05:51 -0700 | [diff] [blame] | 39 | #include <linux/io.h> |
Joe Perches | 26c6d28 | 2015-05-05 10:06:03 -0700 | [diff] [blame] | 40 | |
| 41 | #include "arcdevice.h" |
Joe Perches | 8e0f295 | 2015-05-05 10:06:13 -0700 | [diff] [blame] | 42 | #include "com9026.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 arcrimi_probe(struct net_device *dev); |
| 47 | static int arcrimi_found(struct net_device *dev); |
| 48 | static void arcrimi_command(struct net_device *dev, int command); |
| 49 | static int arcrimi_status(struct net_device *dev); |
| 50 | static void arcrimi_setmask(struct net_device *dev, int mask); |
| 51 | static int arcrimi_reset(struct net_device *dev, int really_reset); |
| 52 | static void arcrimi_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 arcrimi_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 | |
| 57 | /* Handy defines for ARCnet specific stuff */ |
| 58 | |
| 59 | /* Amount of I/O memory used by the card */ |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 60 | #define BUFFER_SIZE (512) |
| 61 | #define MIRROR_SIZE (BUFFER_SIZE * 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 63 | /* We cannot probe for a RIM I card; one reason is I don't know how to reset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * them. In fact, we can't even get their node ID automatically. So, we |
| 65 | * need to be passed a specific shmem address, IRQ, and node ID. |
| 66 | */ |
| 67 | static int __init arcrimi_probe(struct net_device *dev) |
| 68 | { |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 69 | if (BUGLVL(D_NORMAL)) { |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 70 | pr_info("%s\n", "RIM I (entirely mem-mapped) support"); |
| 71 | pr_info("E-mail me if you actually test the RIM I driver, please!\n"); |
| 72 | pr_info("Given: node %02Xh, shmem %lXh, irq %d\n", |
| 73 | dev->dev_addr[0], dev->mem_start, dev->irq); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 74 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | if (dev->mem_start <= 0 || dev->irq <= 0) { |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 77 | if (BUGLVL(D_NORMAL)) |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 78 | pr_err("No autoprobe for RIM I; you must specify the shmem and irq!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return -ENODEV; |
| 80 | } |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 81 | if (dev->dev_addr[0] == 0) { |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 82 | if (BUGLVL(D_NORMAL)) |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 83 | pr_err("You need to specify your card's station ID!\n"); |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 84 | return -ENODEV; |
| 85 | } |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 86 | /* Grab the memory region at mem_start for MIRROR_SIZE bytes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | * Later in arcrimi_found() the real size will be determined |
| 88 | * and this reserve will be released and the correct size |
| 89 | * will be taken. |
| 90 | */ |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 91 | if (!request_mem_region(dev->mem_start, MIRROR_SIZE, "arcnet (90xx)")) { |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 92 | if (BUGLVL(D_NORMAL)) |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 93 | pr_notice("Card memory already allocated\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return -ENODEV; |
| 95 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return arcrimi_found(dev); |
| 97 | } |
| 98 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 99 | static int check_mirror(unsigned long addr, size_t size) |
| 100 | { |
| 101 | void __iomem *p; |
| 102 | int res = -1; |
| 103 | |
| 104 | if (!request_mem_region(addr, size, "arcnet (90xx)")) |
| 105 | return -1; |
| 106 | |
| 107 | p = ioremap(addr, size); |
| 108 | if (p) { |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 109 | if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue) |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 110 | res = 1; |
| 111 | else |
| 112 | res = 0; |
| 113 | iounmap(p); |
| 114 | } |
| 115 | |
| 116 | release_mem_region(addr, size); |
| 117 | return res; |
| 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 120 | /* Set up the struct net_device associated with this card. |
| 121 | * Called after probing succeeds. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | */ |
| 123 | static int __init arcrimi_found(struct net_device *dev) |
| 124 | { |
| 125 | struct arcnet_local *lp; |
| 126 | unsigned long first_mirror, last_mirror, shmem; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 127 | void __iomem *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | int mirror_size; |
| 129 | int err; |
| 130 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 131 | p = ioremap(dev->mem_start, MIRROR_SIZE); |
| 132 | if (!p) { |
| 133 | release_mem_region(dev->mem_start, MIRROR_SIZE); |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 134 | arc_printk(D_NORMAL, dev, "Can't ioremap\n"); |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 135 | return -ENODEV; |
| 136 | } |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* reserve the irq */ |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 139 | if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (RIM I)", dev)) { |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 140 | iounmap(p); |
| 141 | release_mem_region(dev->mem_start, MIRROR_SIZE); |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 142 | 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] | 143 | return -ENODEV; |
| 144 | } |
| 145 | |
| 146 | shmem = dev->mem_start; |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 147 | arcnet_writeb(TESTvalue, p, COM9026_REG_W_INTMASK); |
| 148 | arcnet_writeb(TESTvalue, p, COM9026_REG_W_COMMAND); |
| 149 | /* actually the station/node ID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | /* find the real shared memory start/end points, including mirrors */ |
| 152 | |
| 153 | /* guess the actual size of one "memory mirror" - the number of |
| 154 | * bytes between copies of the shared memory. On most cards, it's |
| 155 | * 2k (or there are no mirrors at all) but on some, it's 4k. |
| 156 | */ |
| 157 | mirror_size = MIRROR_SIZE; |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 158 | if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue && |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 159 | check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 && |
| 160 | check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1) |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 161 | mirror_size = 2 * MIRROR_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 163 | first_mirror = shmem - mirror_size; |
| 164 | while (check_mirror(first_mirror, mirror_size) == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | first_mirror -= mirror_size; |
| 166 | first_mirror += mirror_size; |
| 167 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 168 | last_mirror = shmem + mirror_size; |
| 169 | while (check_mirror(last_mirror, mirror_size) == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | last_mirror += mirror_size; |
| 171 | last_mirror -= mirror_size; |
| 172 | |
| 173 | dev->mem_start = first_mirror; |
| 174 | dev->mem_end = last_mirror + MIRROR_SIZE - 1; |
| 175 | |
| 176 | /* initialize the rest of the device structure. */ |
| 177 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 178 | lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | lp->card_name = "RIM I"; |
| 180 | lp->hw.command = arcrimi_command; |
| 181 | lp->hw.status = arcrimi_status; |
| 182 | lp->hw.intmask = arcrimi_setmask; |
| 183 | lp->hw.reset = arcrimi_reset; |
| 184 | lp->hw.owner = THIS_MODULE; |
| 185 | lp->hw.copy_to_card = arcrimi_copy_to_card; |
| 186 | lp->hw.copy_from_card = arcrimi_copy_from_card; |
| 187 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 188 | /* re-reserve the memory region - arcrimi_probe() alloced this reqion |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | * but didn't know the real size. Free that region and then re-get |
| 190 | * with the correct size. There is a VERY slim chance this could |
| 191 | * fail. |
| 192 | */ |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 193 | iounmap(p); |
| 194 | release_mem_region(shmem, MIRROR_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if (!request_mem_region(dev->mem_start, |
| 196 | dev->mem_end - dev->mem_start + 1, |
| 197 | "arcnet (90xx)")) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 198 | arc_printk(D_NORMAL, dev, "Card memory already allocated\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | goto err_free_irq; |
| 200 | } |
| 201 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 202 | lp->mem_start = ioremap(dev->mem_start, |
| 203 | dev->mem_end - dev->mem_start + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | if (!lp->mem_start) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 205 | arc_printk(D_NORMAL, dev, "Can't remap device memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | goto err_release_mem; |
| 207 | } |
| 208 | |
| 209 | /* get and check the station ID from offset 1 in shmem */ |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 210 | dev->dev_addr[0] = arcnet_readb(lp->mem_start, COM9026_REG_R_STATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 212 | arc_printk(D_NORMAL, dev, "ARCnet RIM I: station %02Xh found at IRQ %d, ShMem %lXh (%ld*%d bytes)\n", |
| 213 | dev->dev_addr[0], |
| 214 | dev->irq, dev->mem_start, |
| 215 | (dev->mem_end - dev->mem_start + 1) / mirror_size, |
| 216 | mirror_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | err = register_netdev(dev); |
| 219 | if (err) |
| 220 | goto err_unmap; |
| 221 | |
| 222 | return 0; |
| 223 | |
| 224 | err_unmap: |
| 225 | iounmap(lp->mem_start); |
| 226 | err_release_mem: |
| 227 | release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1); |
| 228 | err_free_irq: |
| 229 | free_irq(dev->irq, dev); |
| 230 | return -EIO; |
| 231 | } |
| 232 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 233 | /* Do a hardware reset on the card, and set up necessary registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | * |
| 235 | * This should be called as little as possible, because it disrupts the |
| 236 | * token on the network (causes a RECON) and requires a significant delay. |
| 237 | * |
| 238 | * However, it does make sure the card is in a defined state. |
| 239 | */ |
| 240 | static int arcrimi_reset(struct net_device *dev, int really_reset) |
| 241 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 242 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | void __iomem *ioaddr = lp->mem_start + 0x800; |
| 244 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 245 | arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n", |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 246 | dev->name, arcnet_readb(ioaddr, COM9026_REG_R_STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | if (really_reset) { |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 249 | arcnet_writeb(TESTvalue, ioaddr, -0x800); /* fake reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | return 0; |
| 251 | } |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 252 | /* clear flags & end reset */ |
| 253 | arcnet_writeb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND); |
| 254 | arcnet_writeb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | /* enable extended (512-byte) packets */ |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 257 | arcnet_writeb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* done! return success. */ |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static void arcrimi_setmask(struct net_device *dev, int mask) |
| 264 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 265 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | void __iomem *ioaddr = lp->mem_start + 0x800; |
| 267 | |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 268 | arcnet_writeb(mask, ioaddr, COM9026_REG_W_INTMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static int arcrimi_status(struct net_device *dev) |
| 272 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 273 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | void __iomem *ioaddr = lp->mem_start + 0x800; |
| 275 | |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 276 | return arcnet_readb(ioaddr, COM9026_REG_R_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static void arcrimi_command(struct net_device *dev, int cmd) |
| 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 | void __iomem *ioaddr = lp->mem_start + 0x800; |
| 283 | |
Joe Perches | 4e2f9f1 | 2015-05-05 10:06:10 -0700 | [diff] [blame] | 284 | arcnet_writeb(cmd, ioaddr, COM9026_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset, |
| 288 | void *buf, int count) |
| 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 | void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 292 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 293 | TIME(dev, "memcpy_toio", count, memcpy_toio(memaddr, buf, count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 296 | static void arcrimi_copy_from_card(struct net_device *dev, int bufnum, |
| 297 | int offset, void *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 299 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 301 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 302 | TIME(dev, "memcpy_fromio", count, memcpy_fromio(buf, memaddr, count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static int node; |
| 306 | static int io; /* use the insmod io= irq= node= options */ |
| 307 | static int irq; |
| 308 | static char device[9]; /* use eg. device=arc1 to change name */ |
| 309 | |
| 310 | module_param(node, int, 0); |
| 311 | module_param(io, int, 0); |
| 312 | module_param(irq, int, 0); |
| 313 | module_param_string(device, device, sizeof(device), 0); |
| 314 | MODULE_LICENSE("GPL"); |
| 315 | |
| 316 | static struct net_device *my_dev; |
| 317 | |
| 318 | static int __init arc_rimi_init(void) |
| 319 | { |
| 320 | struct net_device *dev; |
| 321 | |
| 322 | dev = alloc_arcdev(device); |
| 323 | if (!dev) |
| 324 | return -ENOMEM; |
| 325 | |
| 326 | if (node && node != 0xff) |
| 327 | dev->dev_addr[0] = node; |
| 328 | |
| 329 | dev->mem_start = io; |
| 330 | dev->irq = irq; |
| 331 | if (dev->irq == 2) |
| 332 | dev->irq = 9; |
| 333 | |
| 334 | if (arcrimi_probe(dev)) { |
| 335 | free_netdev(dev); |
| 336 | return -EIO; |
| 337 | } |
| 338 | |
| 339 | my_dev = dev; |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static void __exit arc_rimi_exit(void) |
| 344 | { |
| 345 | struct net_device *dev = my_dev; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 346 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | unregister_netdev(dev); |
| 349 | iounmap(lp->mem_start); |
| 350 | release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1); |
| 351 | free_irq(dev->irq, dev); |
| 352 | free_netdev(dev); |
| 353 | } |
| 354 | |
| 355 | #ifndef MODULE |
| 356 | static int __init arcrimi_setup(char *s) |
| 357 | { |
| 358 | int ints[8]; |
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, 8, ints); |
| 361 | if (!ints[0]) |
| 362 | return 1; |
| 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"); |
Gustavo A. R. Silva | 26027f4 | 2019-07-29 06:15:50 -0500 | [diff] [blame] | 366 | /* Fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | case 3: /* Node ID */ |
| 368 | node = ints[3]; |
Gustavo A. R. Silva | 26027f4 | 2019-07-29 06:15:50 -0500 | [diff] [blame] | 369 | /* Fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | case 2: /* IRQ */ |
| 371 | irq = ints[2]; |
Gustavo A. R. Silva | 26027f4 | 2019-07-29 06:15:50 -0500 | [diff] [blame] | 372 | /* Fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | case 1: /* IO address */ |
| 374 | io = ints[1]; |
| 375 | } |
| 376 | if (*s) |
| 377 | snprintf(device, sizeof(device), "%s", s); |
| 378 | return 1; |
| 379 | } |
| 380 | __setup("arcrimi=", arcrimi_setup); |
| 381 | #endif /* MODULE */ |
| 382 | |
| 383 | module_init(arc_rimi_init) |
| 384 | module_exit(arc_rimi_exit) |