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