Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux ARCnet driver - COM90xx chipset (memory-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 1994-1999 by Avery Pennarun. |
| 5 | * Written 1999 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/module.h> |
| 31 | #include <linux/moduleparam.h> |
| 32 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 33 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/ioport.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/netdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Joe Perches | 5e7ef91 | 2015-05-05 10:05:51 -0700 | [diff] [blame] | 38 | #include <linux/io.h> |
Joe Perches | 26c6d28 | 2015-05-05 10:06:03 -0700 | [diff] [blame^] | 39 | |
| 40 | #include "arcdevice.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* Define this to speed up the autoprobe by assuming if only one io port and |
| 43 | * shmem are left in the list at Stage 5, they must correspond to each |
| 44 | * other. |
| 45 | * |
| 46 | * This is undefined by default because it might not always be true, and the |
| 47 | * extra check makes the autoprobe even more careful. Speed demons can turn |
| 48 | * it on - I think it should be fine if you only have one ARCnet card |
| 49 | * installed. |
| 50 | * |
| 51 | * If no ARCnet cards are installed, this delay never happens anyway and thus |
| 52 | * the option has no effect. |
| 53 | */ |
| 54 | #undef FAST_PROBE |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* Internal function declarations */ |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 57 | static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static void com90xx_command(struct net_device *dev, int command); |
| 59 | static int com90xx_status(struct net_device *dev); |
| 60 | static void com90xx_setmask(struct net_device *dev, int mask); |
| 61 | static int com90xx_reset(struct net_device *dev, int really_reset); |
| 62 | static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset, |
| 63 | void *buf, int count); |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 64 | static void com90xx_copy_from_card(struct net_device *dev, int bufnum, |
| 65 | int offset, void *buf, int count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | /* Known ARCnet cards */ |
| 68 | |
| 69 | static struct net_device *cards[16]; |
| 70 | static int numcards; |
| 71 | |
| 72 | /* Handy defines for ARCnet specific stuff */ |
| 73 | |
| 74 | /* The number of low I/O ports used by the card */ |
| 75 | #define ARCNET_TOTAL_SIZE 16 |
| 76 | |
| 77 | /* Amount of I/O memory used by the card */ |
| 78 | #define BUFFER_SIZE (512) |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 79 | #define MIRROR_SIZE (BUFFER_SIZE * 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* COM 9026 controller chip --> ARCnet register addresses */ |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 82 | #define _INTMASK (ioaddr + 0) /* writable */ |
| 83 | #define _STATUS (ioaddr + 0) /* readable */ |
| 84 | #define _COMMAND (ioaddr + 1) /* writable, returns random vals on read (?) */ |
| 85 | #define _CONFIG (ioaddr + 2) /* Configuration register */ |
| 86 | #define _RESET (ioaddr + 8) /* software reset (on read) */ |
| 87 | #define _MEMDATA (ioaddr + 12) /* Data port for IO-mapped memory */ |
| 88 | #define _ADDR_HI (ioaddr + 15) /* Control registers for said */ |
| 89 | #define _ADDR_LO (ioaddr + 14) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | #undef ASTATUS |
| 92 | #undef ACOMMAND |
| 93 | #undef AINTMASK |
| 94 | |
| 95 | #define ASTATUS() inb(_STATUS) |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 96 | #define ACOMMAND(cmd) outb((cmd), _COMMAND) |
| 97 | #define AINTMASK(msk) outb((msk), _INTMASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | static int com90xx_skip_probe __initdata = 0; |
| 100 | |
| 101 | /* Module parameters */ |
| 102 | |
| 103 | static int io; /* use the insmod io= irq= shmem= options */ |
| 104 | static int irq; |
| 105 | static int shmem; |
| 106 | static char device[9]; /* use eg. device=arc1 to change name */ |
| 107 | |
| 108 | module_param(io, int, 0); |
| 109 | module_param(irq, int, 0); |
| 110 | module_param(shmem, int, 0); |
| 111 | module_param_string(device, device, sizeof(device), 0); |
| 112 | |
| 113 | static void __init com90xx_probe(void) |
| 114 | { |
| 115 | int count, status, ioaddr, numprint, airq, openparen = 0; |
| 116 | unsigned long airqmask; |
Joe Perches | 7f5e760 | 2015-05-05 10:05:49 -0700 | [diff] [blame] | 117 | int ports[(0x3f0 - 0x200) / 16 + 1] = { 0 }; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 118 | unsigned long *shmems; |
| 119 | void __iomem **iomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | int numports, numshmems, *port; |
| 121 | u_long *p; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 122 | int index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | if (!io && !irq && !shmem && !*device && com90xx_skip_probe) |
| 125 | return; |
| 126 | |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 127 | shmems = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(unsigned long), |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 128 | GFP_KERNEL); |
| 129 | if (!shmems) |
| 130 | return; |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 131 | iomem = kzalloc(((0x100000 - 0xa0000) / 0x800) * sizeof(void __iomem *), |
| 132 | GFP_KERNEL); |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 133 | if (!iomem) { |
| 134 | kfree(shmems); |
| 135 | return; |
| 136 | } |
| 137 | |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 138 | if (BUGLVL(D_NORMAL)) |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 139 | pr_info("%s\n", "COM90xx chipset support"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | /* set up the arrays where we'll store the possible probe addresses */ |
| 142 | numports = numshmems = 0; |
| 143 | if (io) |
| 144 | ports[numports++] = io; |
| 145 | else |
| 146 | for (count = 0x200; count <= 0x3f0; count += 16) |
| 147 | ports[numports++] = count; |
| 148 | if (shmem) |
| 149 | shmems[numshmems++] = shmem; |
| 150 | else |
| 151 | for (count = 0xA0000; count <= 0xFF800; count += 2048) |
| 152 | shmems[numshmems++] = count; |
| 153 | |
| 154 | /* Stage 1: abandon any reserved ports, or ones with status==0xFF |
| 155 | * (empty), and reset any others by reading the reset port. |
| 156 | */ |
| 157 | numprint = -1; |
| 158 | for (port = &ports[0]; port - ports < numports; port++) { |
| 159 | numprint++; |
| 160 | numprint %= 8; |
| 161 | if (!numprint) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 162 | arc_cont(D_INIT, "\n"); |
| 163 | arc_cont(D_INIT, "S1: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 165 | arc_cont(D_INIT, "%Xh ", *port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | ioaddr = *port; |
| 168 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 169 | if (!request_region(*port, ARCNET_TOTAL_SIZE, |
| 170 | "arcnet (90xx)")) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 171 | arc_cont(D_INIT_REASONS, "(request_region)\n"); |
| 172 | arc_cont(D_INIT_REASONS, "S1: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 173 | if (BUGLVL(D_INIT_REASONS)) |
| 174 | numprint = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | *port-- = ports[--numports]; |
| 176 | continue; |
| 177 | } |
| 178 | if (ASTATUS() == 0xFF) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 179 | arc_cont(D_INIT_REASONS, "(empty)\n"); |
| 180 | arc_cont(D_INIT_REASONS, "S1: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 181 | if (BUGLVL(D_INIT_REASONS)) |
| 182 | numprint = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | release_region(*port, ARCNET_TOTAL_SIZE); |
| 184 | *port-- = ports[--numports]; |
| 185 | continue; |
| 186 | } |
| 187 | inb(_RESET); /* begin resetting card */ |
| 188 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 189 | arc_cont(D_INIT_REASONS, "\n"); |
| 190 | arc_cont(D_INIT_REASONS, "S1: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 191 | if (BUGLVL(D_INIT_REASONS)) |
| 192 | numprint = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 194 | arc_cont(D_INIT, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | if (!numports) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 197 | arc_cont(D_NORMAL, "S1: No ARCnet cards found.\n"); |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 198 | kfree(shmems); |
| 199 | kfree(iomem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | /* Stage 2: we have now reset any possible ARCnet cards, so we can't |
| 203 | * do anything until they finish. If D_INIT, print the list of |
| 204 | * cards that are left. |
| 205 | */ |
| 206 | numprint = -1; |
| 207 | for (port = &ports[0]; port < ports + numports; port++) { |
| 208 | numprint++; |
| 209 | numprint %= 8; |
| 210 | if (!numprint) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 211 | arc_cont(D_INIT, "\n"); |
| 212 | arc_cont(D_INIT, "S2: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 214 | arc_cont(D_INIT, "%Xh ", *port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 216 | arc_cont(D_INIT, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | mdelay(RESETtime); |
| 218 | |
| 219 | /* Stage 3: abandon any shmem addresses that don't have the signature |
| 220 | * 0xD1 byte in the right place, or are read-only. |
| 221 | */ |
| 222 | numprint = -1; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 223 | for (index = 0, p = &shmems[0]; index < numshmems; p++, index++) { |
| 224 | void __iomem *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | numprint++; |
| 227 | numprint %= 8; |
| 228 | if (!numprint) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 229 | arc_cont(D_INIT, "\n"); |
| 230 | arc_cont(D_INIT, "S3: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 232 | arc_cont(D_INIT, "%lXh ", *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 234 | if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 235 | arc_cont(D_INIT_REASONS, "(request_mem_region)\n"); |
| 236 | arc_cont(D_INIT_REASONS, "Stage 3: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 237 | if (BUGLVL(D_INIT_REASONS)) |
| 238 | numprint = 0; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 239 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 241 | base = ioremap(*p, MIRROR_SIZE); |
| 242 | if (!base) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 243 | arc_cont(D_INIT_REASONS, "(ioremap)\n"); |
| 244 | arc_cont(D_INIT_REASONS, "Stage 3: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 245 | if (BUGLVL(D_INIT_REASONS)) |
| 246 | numprint = 0; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 247 | goto out1; |
| 248 | } |
| 249 | if (readb(base) != TESTvalue) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 250 | arc_cont(D_INIT_REASONS, "(%02Xh != %02Xh)\n", |
| 251 | readb(base), TESTvalue); |
| 252 | arc_cont(D_INIT_REASONS, "S3: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 253 | if (BUGLVL(D_INIT_REASONS)) |
| 254 | numprint = 0; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 255 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | /* By writing 0x42 to the TESTvalue location, we also make |
| 258 | * sure no "mirror" shmem areas show up - if they occur |
| 259 | * in another pass through this loop, they will be discarded |
| 260 | * because *cptr != TESTvalue. |
| 261 | */ |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 262 | writeb(0x42, base); |
| 263 | if (readb(base) != 0x42) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 264 | arc_cont(D_INIT_REASONS, "(read only)\n"); |
| 265 | arc_cont(D_INIT_REASONS, "S3: "); |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 266 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 268 | arc_cont(D_INIT_REASONS, "\n"); |
| 269 | arc_cont(D_INIT_REASONS, "S3: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 270 | if (BUGLVL(D_INIT_REASONS)) |
| 271 | numprint = 0; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 272 | iomem[index] = base; |
| 273 | continue; |
| 274 | out2: |
| 275 | iounmap(base); |
| 276 | out1: |
| 277 | release_mem_region(*p, MIRROR_SIZE); |
| 278 | out: |
| 279 | *p-- = shmems[--numshmems]; |
| 280 | index--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 282 | arc_cont(D_INIT, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | if (!numshmems) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 285 | arc_cont(D_NORMAL, "S3: No ARCnet cards found.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | for (port = &ports[0]; port < ports + numports; port++) |
| 287 | release_region(*port, ARCNET_TOTAL_SIZE); |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 288 | kfree(shmems); |
| 289 | kfree(iomem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | return; |
| 291 | } |
| 292 | /* Stage 4: something of a dummy, to report the shmems that are |
| 293 | * still possible after stage 3. |
| 294 | */ |
| 295 | numprint = -1; |
| 296 | for (p = &shmems[0]; p < shmems + numshmems; p++) { |
| 297 | numprint++; |
| 298 | numprint %= 8; |
| 299 | if (!numprint) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 300 | arc_cont(D_INIT, "\n"); |
| 301 | arc_cont(D_INIT, "S4: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 303 | arc_cont(D_INIT, "%lXh ", *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 305 | arc_cont(D_INIT, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 307 | /* Stage 5: for any ports that have the correct status, can disable |
| 308 | * the RESET flag, and (if no irq is given) generate an autoirq, |
| 309 | * register an ARCnet device. |
| 310 | * |
| 311 | * Currently, we can only register one device per probe, so quit |
| 312 | * after the first one is found. |
| 313 | */ |
| 314 | numprint = -1; |
| 315 | for (port = &ports[0]; port < ports + numports; port++) { |
| 316 | int found = 0; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | numprint++; |
| 319 | numprint %= 8; |
| 320 | if (!numprint) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 321 | arc_cont(D_INIT, "\n"); |
| 322 | arc_cont(D_INIT, "S5: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 324 | arc_cont(D_INIT, "%Xh ", *port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | ioaddr = *port; |
| 327 | status = ASTATUS(); |
| 328 | |
| 329 | if ((status & 0x9D) |
| 330 | != (NORXflag | RECONflag | TXFREEflag | RESETflag)) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 331 | arc_cont(D_INIT_REASONS, "(status=%Xh)\n", status); |
| 332 | arc_cont(D_INIT_REASONS, "S5: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 333 | if (BUGLVL(D_INIT_REASONS)) |
| 334 | numprint = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | release_region(*port, ARCNET_TOTAL_SIZE); |
| 336 | *port-- = ports[--numports]; |
| 337 | continue; |
| 338 | } |
| 339 | ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear); |
| 340 | status = ASTATUS(); |
| 341 | if (status & RESETflag) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 342 | arc_cont(D_INIT_REASONS, " (eternal reset, status=%Xh)\n", |
| 343 | status); |
| 344 | arc_cont(D_INIT_REASONS, "S5: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 345 | if (BUGLVL(D_INIT_REASONS)) |
| 346 | numprint = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | release_region(*port, ARCNET_TOTAL_SIZE); |
| 348 | *port-- = ports[--numports]; |
| 349 | continue; |
| 350 | } |
| 351 | /* skip this completely if an IRQ was given, because maybe |
| 352 | * we're on a machine that locks during autoirq! |
| 353 | */ |
| 354 | if (!irq) { |
| 355 | /* if we do this, we're sure to get an IRQ since the |
| 356 | * card has just reset and the NORXflag is on until |
| 357 | * we tell it to start receiving. |
| 358 | */ |
| 359 | airqmask = probe_irq_on(); |
| 360 | AINTMASK(NORXflag); |
| 361 | udelay(1); |
| 362 | AINTMASK(0); |
| 363 | airq = probe_irq_off(airqmask); |
| 364 | |
| 365 | if (airq <= 0) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 366 | arc_cont(D_INIT_REASONS, "(airq=%d)\n", airq); |
| 367 | arc_cont(D_INIT_REASONS, "S5: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 368 | if (BUGLVL(D_INIT_REASONS)) |
| 369 | numprint = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | release_region(*port, ARCNET_TOTAL_SIZE); |
| 371 | *port-- = ports[--numports]; |
| 372 | continue; |
| 373 | } |
| 374 | } else { |
| 375 | airq = irq; |
| 376 | } |
| 377 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 378 | arc_cont(D_INIT, "(%d,", airq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | openparen = 1; |
| 380 | |
| 381 | /* Everything seems okay. But which shmem, if any, puts |
| 382 | * back its signature byte when the card is reset? |
| 383 | * |
| 384 | * If there are multiple cards installed, there might be |
| 385 | * multiple shmems still in the list. |
| 386 | */ |
| 387 | #ifdef FAST_PROBE |
| 388 | if (numports > 1 || numshmems > 1) { |
| 389 | inb(_RESET); |
| 390 | mdelay(RESETtime); |
| 391 | } else { |
| 392 | /* just one shmem and port, assume they match */ |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 393 | writeb(TESTvalue, iomem[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | #else |
| 396 | inb(_RESET); |
| 397 | mdelay(RESETtime); |
| 398 | #endif |
| 399 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 400 | for (index = 0; index < numshmems; index++) { |
| 401 | u_long ptr = shmems[index]; |
| 402 | void __iomem *base = iomem[index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 404 | if (readb(base) == TESTvalue) { /* found one */ |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 405 | arc_cont(D_INIT, "%lXh)\n", *p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | openparen = 0; |
| 407 | |
| 408 | /* register the card */ |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 409 | if (com90xx_found(*port, airq, ptr, base) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | found = 1; |
| 411 | numprint = -1; |
| 412 | |
| 413 | /* remove shmem from the list */ |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 414 | shmems[index] = shmems[--numshmems]; |
| 415 | iomem[index] = iomem[numshmems]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | break; /* go to the next I/O port */ |
| 417 | } else { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 418 | arc_cont(D_INIT_REASONS, "%Xh-", readb(base)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
| 422 | if (openparen) { |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 423 | if (BUGLVL(D_INIT)) |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 424 | pr_cont("no matching shmem)\n"); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 425 | if (BUGLVL(D_INIT_REASONS)) { |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 426 | pr_cont("S5: "); |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 427 | numprint = 0; |
| 428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | if (!found) |
| 431 | release_region(*port, ARCNET_TOTAL_SIZE); |
| 432 | *port-- = ports[--numports]; |
| 433 | } |
| 434 | |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 435 | if (BUGLVL(D_INIT_REASONS)) |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 436 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | /* Now put back TESTvalue on all leftover shmems. */ |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 439 | for (index = 0; index < numshmems; index++) { |
| 440 | writeb(TESTvalue, iomem[index]); |
| 441 | iounmap(iomem[index]); |
| 442 | release_mem_region(shmems[index], MIRROR_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 444 | kfree(shmems); |
| 445 | kfree(iomem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 448 | static int check_mirror(unsigned long addr, size_t size) |
| 449 | { |
| 450 | void __iomem *p; |
| 451 | int res = -1; |
| 452 | |
| 453 | if (!request_mem_region(addr, size, "arcnet (90xx)")) |
| 454 | return -1; |
| 455 | |
| 456 | p = ioremap(addr, size); |
| 457 | if (p) { |
| 458 | if (readb(p) == TESTvalue) |
| 459 | res = 1; |
| 460 | else |
| 461 | res = 0; |
| 462 | iounmap(p); |
| 463 | } |
| 464 | |
| 465 | release_mem_region(addr, size); |
| 466 | return res; |
| 467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
| 469 | /* Set up the struct net_device associated with this card. Called after |
| 470 | * probing succeeds. |
| 471 | */ |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 472 | static int __init com90xx_found(int ioaddr, int airq, u_long shmem, |
| 473 | void __iomem *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
| 475 | struct net_device *dev = NULL; |
| 476 | struct arcnet_local *lp; |
| 477 | u_long first_mirror, last_mirror; |
| 478 | int mirror_size; |
| 479 | |
| 480 | /* allocate struct net_device */ |
| 481 | dev = alloc_arcdev(device); |
| 482 | if (!dev) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 483 | arc_cont(D_NORMAL, "com90xx: Can't allocate device!\n"); |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 484 | iounmap(p); |
| 485 | release_mem_region(shmem, MIRROR_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | return -ENOMEM; |
| 487 | } |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 488 | lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* find the real shared memory start/end points, including mirrors */ |
| 490 | |
| 491 | /* guess the actual size of one "memory mirror" - the number of |
| 492 | * bytes between copies of the shared memory. On most cards, it's |
| 493 | * 2k (or there are no mirrors at all) but on some, it's 4k. |
| 494 | */ |
| 495 | mirror_size = MIRROR_SIZE; |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 496 | if (readb(p) == TESTvalue && |
| 497 | check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 && |
| 498 | check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1) |
| 499 | mirror_size = 2 * MIRROR_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 501 | first_mirror = shmem - mirror_size; |
| 502 | while (check_mirror(first_mirror, mirror_size) == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | first_mirror -= mirror_size; |
| 504 | first_mirror += mirror_size; |
| 505 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 506 | last_mirror = shmem + mirror_size; |
| 507 | while (check_mirror(last_mirror, mirror_size) == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | last_mirror += mirror_size; |
| 509 | last_mirror -= mirror_size; |
| 510 | |
| 511 | dev->mem_start = first_mirror; |
| 512 | dev->mem_end = last_mirror + MIRROR_SIZE - 1; |
| 513 | |
Al Viro | d0f6eca | 2005-12-02 03:54:44 -0500 | [diff] [blame] | 514 | iounmap(p); |
| 515 | release_mem_region(shmem, MIRROR_SIZE); |
| 516 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 517 | if (!request_mem_region(dev->mem_start, |
| 518 | dev->mem_end - dev->mem_start + 1, |
| 519 | "arcnet (90xx)")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | goto err_free_dev; |
| 521 | |
| 522 | /* reserve the irq */ |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 523 | if (request_irq(airq, arcnet_interrupt, 0, "arcnet (90xx)", dev)) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 524 | arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", airq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | goto err_release_mem; |
| 526 | } |
| 527 | dev->irq = airq; |
| 528 | |
| 529 | /* Initialize the rest of the device structure. */ |
| 530 | lp->card_name = "COM90xx"; |
| 531 | lp->hw.command = com90xx_command; |
| 532 | lp->hw.status = com90xx_status; |
| 533 | lp->hw.intmask = com90xx_setmask; |
| 534 | lp->hw.reset = com90xx_reset; |
| 535 | lp->hw.owner = THIS_MODULE; |
| 536 | lp->hw.copy_to_card = com90xx_copy_to_card; |
| 537 | lp->hw.copy_from_card = com90xx_copy_from_card; |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 538 | lp->mem_start = ioremap(dev->mem_start, |
| 539 | dev->mem_end - dev->mem_start + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | if (!lp->mem_start) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 541 | arc_printk(D_NORMAL, dev, "Can't remap device memory!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | goto err_free_irq; |
| 543 | } |
| 544 | |
| 545 | /* get and check the station ID from offset 1 in shmem */ |
| 546 | dev->dev_addr[0] = readb(lp->mem_start + 1); |
| 547 | |
| 548 | dev->base_addr = ioaddr; |
| 549 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 550 | arc_printk(D_NORMAL, dev, "COM90xx station %02Xh found at %03lXh, IRQ %d, ShMem %lXh (%ld*%xh).\n", |
| 551 | dev->dev_addr[0], |
| 552 | dev->base_addr, dev->irq, dev->mem_start, |
| 553 | (dev->mem_end - dev->mem_start + 1) / mirror_size, |
| 554 | mirror_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | if (register_netdev(dev)) |
| 557 | goto err_unmap; |
| 558 | |
| 559 | cards[numcards++] = dev; |
| 560 | return 0; |
| 561 | |
| 562 | err_unmap: |
| 563 | iounmap(lp->mem_start); |
| 564 | err_free_irq: |
| 565 | free_irq(dev->irq, dev); |
| 566 | err_release_mem: |
| 567 | release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1); |
| 568 | err_free_dev: |
| 569 | free_netdev(dev); |
| 570 | return -EIO; |
| 571 | } |
| 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | static void com90xx_command(struct net_device *dev, int cmd) |
| 574 | { |
| 575 | short ioaddr = dev->base_addr; |
| 576 | |
| 577 | ACOMMAND(cmd); |
| 578 | } |
| 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | static int com90xx_status(struct net_device *dev) |
| 581 | { |
| 582 | short ioaddr = dev->base_addr; |
| 583 | |
| 584 | return ASTATUS(); |
| 585 | } |
| 586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | static void com90xx_setmask(struct net_device *dev, int mask) |
| 588 | { |
| 589 | short ioaddr = dev->base_addr; |
| 590 | |
| 591 | AINTMASK(mask); |
| 592 | } |
| 593 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 594 | /* Do a hardware reset on the card, and set up necessary registers. |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 595 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | * This should be called as little as possible, because it disrupts the |
| 597 | * token on the network (causes a RECON) and requires a significant delay. |
| 598 | * |
| 599 | * However, it does make sure the card is in a defined state. |
| 600 | */ |
Hannes Eder | 888432f | 2008-12-25 23:57:21 -0800 | [diff] [blame] | 601 | static int com90xx_reset(struct net_device *dev, int really_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 603 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | short ioaddr = dev->base_addr; |
| 605 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 606 | arc_printk(D_INIT, dev, "Resetting (status=%02Xh)\n", ASTATUS()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | if (really_reset) { |
| 609 | /* reset the card */ |
| 610 | inb(_RESET); |
| 611 | mdelay(RESETtime); |
| 612 | } |
| 613 | ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */ |
| 614 | ACOMMAND(CFLAGScmd | CONFIGclear); |
| 615 | |
| 616 | /* don't do this until we verify that it doesn't hurt older cards! */ |
| 617 | /* outb(inb(_CONFIG) | ENABLE16flag, _CONFIG); */ |
| 618 | |
| 619 | /* verify that the ARCnet signature byte is present */ |
| 620 | if (readb(lp->mem_start) != TESTvalue) { |
| 621 | if (really_reset) |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 622 | arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return 1; |
| 624 | } |
| 625 | /* enable extended (512-byte) packets */ |
| 626 | ACOMMAND(CONFIGcmd | EXTconf); |
| 627 | |
| 628 | /* clean out all the memory to make debugging make more sense :) */ |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 629 | if (BUGLVL(D_DURING)) |
| 630 | memset_io(lp->mem_start, 0x42, 2048); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
| 632 | /* done! return success. */ |
| 633 | return 0; |
| 634 | } |
| 635 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 636 | static void com90xx_copy_to_card(struct net_device *dev, int bufnum, |
| 637 | int offset, void *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 639 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 641 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 642 | TIME(dev, "memcpy_toio", count, memcpy_toio(memaddr, buf, count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 645 | static void com90xx_copy_from_card(struct net_device *dev, int bufnum, |
| 646 | int offset, void *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 648 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 650 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 651 | TIME(dev, "memcpy_fromio", count, memcpy_fromio(buf, memaddr, count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | MODULE_LICENSE("GPL"); |
| 655 | |
| 656 | static int __init com90xx_init(void) |
| 657 | { |
| 658 | if (irq == 2) |
| 659 | irq = 9; |
| 660 | com90xx_probe(); |
| 661 | if (!numcards) |
| 662 | return -EIO; |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static void __exit com90xx_exit(void) |
| 667 | { |
| 668 | struct net_device *dev; |
| 669 | struct arcnet_local *lp; |
| 670 | int count; |
| 671 | |
| 672 | for (count = 0; count < numcards; count++) { |
| 673 | dev = cards[count]; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 674 | lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
| 676 | unregister_netdev(dev); |
| 677 | free_irq(dev->irq, dev); |
| 678 | iounmap(lp->mem_start); |
| 679 | release_region(dev->base_addr, ARCNET_TOTAL_SIZE); |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 680 | release_mem_region(dev->mem_start, |
| 681 | dev->mem_end - dev->mem_start + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | free_netdev(dev); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | module_init(com90xx_init); |
| 687 | module_exit(com90xx_exit); |
| 688 | |
| 689 | #ifndef MODULE |
| 690 | static int __init com90xx_setup(char *s) |
| 691 | { |
| 692 | int ints[8]; |
| 693 | |
| 694 | s = get_options(s, 8, ints); |
| 695 | if (!ints[0] && !*s) { |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 696 | pr_notice("Disabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | return 1; |
| 698 | } |
| 699 | |
| 700 | switch (ints[0]) { |
| 701 | default: /* ERROR */ |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 702 | pr_err("Too many arguments\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | case 3: /* Mem address */ |
| 704 | shmem = ints[3]; |
| 705 | case 2: /* IRQ */ |
| 706 | irq = ints[2]; |
| 707 | case 1: /* IO address */ |
| 708 | io = ints[1]; |
| 709 | } |
| 710 | |
| 711 | if (*s) |
| 712 | snprintf(device, sizeof(device), "%s", s); |
| 713 | |
| 714 | return 1; |
| 715 | } |
| 716 | |
| 717 | __setup("com90xx=", com90xx_setup); |
| 718 | #endif |