Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | net-3-driver for the 3c523 Etherlink/MC card (i82586 Ethernet chip) |
| 3 | |
| 4 | |
| 5 | This is an extension to the Linux operating system, and is covered by the |
| 6 | same GNU General Public License that covers that work. |
| 7 | |
| 8 | Copyright 1995, 1996 by Chris Beauregard (cpbeaure@undergrad.math.uwaterloo.ca) |
| 9 | |
| 10 | This is basically Michael Hipp's ni52 driver, with a new probing |
| 11 | algorithm and some minor changes to the 82586 CA and reset routines. |
| 12 | Thanks a lot Michael for a really clean i82586 implementation! Unless |
| 13 | otherwise documented in ni52.c, any bugs are mine. |
| 14 | |
| 15 | Contrary to the Ethernet-HOWTO, this isn't based on the 3c507 driver in |
| 16 | any way. The ni52 is a lot easier to modify. |
| 17 | |
| 18 | sources: |
| 19 | ni52.c |
| 20 | |
| 21 | Crynwr packet driver collection was a great reference for my first |
| 22 | attempt at this sucker. The 3c507 driver also helped, until I noticed |
| 23 | that ni52.c was a lot nicer. |
| 24 | |
| 25 | EtherLink/MC: Micro Channel Ethernet Adapter Technical Reference |
| 26 | Manual, courtesy of 3Com CardFacts, documents the 3c523-specific |
| 27 | stuff. Information on CardFacts is found in the Ethernet HOWTO. |
| 28 | Also see <a href="http://www.3com.com/"> |
| 29 | |
| 30 | Microprocessor Communications Support Chips, T.J. Byers, ISBN |
| 31 | 0-444-01224-9, has a section on the i82586. It tells you just enough |
| 32 | to know that you really don't want to learn how to program the chip. |
| 33 | |
| 34 | The original device probe code was stolen from ps2esdi.c |
| 35 | |
| 36 | Known Problems: |
| 37 | Since most of the code was stolen from ni52.c, you'll run across the |
| 38 | same bugs in the 0.62 version of ni52.c, plus maybe a few because of |
| 39 | the 3c523 idiosynchacies. The 3c523 has 16K of RAM though, so there |
| 40 | shouldn't be the overrun problem that the 8K ni52 has. |
| 41 | |
| 42 | This driver is for a 16K adapter. It should work fine on the 64K |
| 43 | adapters, but it will only use one of the 4 banks of RAM. Modifying |
| 44 | this for the 64K version would require a lot of heinous bank |
| 45 | switching, which I'm sure not interested in doing. If you try to |
| 46 | implement a bank switching version, you'll basically have to remember |
| 47 | what bank is enabled and do a switch everytime you access a memory |
| 48 | location that's not current. You'll also have to remap pointers on |
| 49 | the driver side, because it only knows about 16K of the memory. |
| 50 | Anyone desperate or masochistic enough to try? |
| 51 | |
| 52 | It seems to be stable now when multiple transmit buffers are used. I |
| 53 | can't see any performance difference, but then I'm working on a 386SX. |
| 54 | |
| 55 | Multicast doesn't work. It doesn't even pretend to work. Don't use |
| 56 | it. Don't compile your kernel with multicast support. I don't know |
| 57 | why. |
| 58 | |
| 59 | Features: |
| 60 | This driver is useable as a loadable module. If you try to specify an |
| 61 | IRQ or a IO address (via insmod 3c523.o irq=xx io=0xyyy), it will |
| 62 | search the MCA slots until it finds a 3c523 with the specified |
| 63 | parameters. |
| 64 | |
| 65 | This driver does support multiple ethernet cards when used as a module |
| 66 | (up to MAX_3C523_CARDS, the default being 4) |
| 67 | |
| 68 | This has been tested with both BNC and TP versions, internal and |
| 69 | external transceivers. Haven't tested with the 64K version (that I |
| 70 | know of). |
| 71 | |
| 72 | History: |
| 73 | Jan 1st, 1996 |
| 74 | first public release |
| 75 | Feb 4th, 1996 |
| 76 | update to 1.3.59, incorporated multicast diffs from ni52.c |
| 77 | Feb 15th, 1996 |
| 78 | added shared irq support |
| 79 | Apr 1999 |
| 80 | added support for multiple cards when used as a module |
| 81 | added option to disable multicast as is causes problems |
| 82 | Ganesh Sittampalam <ganesh.sittampalam@magdalen.oxford.ac.uk> |
| 83 | Stuart Adamson <stuart.adamson@compsoc.net> |
| 84 | Nov 2001 |
| 85 | added support for ethtool (jgarzik) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | $Header: /fsys2/home/chrisb/linux-1.3.59-MCA/drivers/net/RCS/3c523.c,v 1.1 1996/02/05 01:53:46 chrisb Exp chrisb $ |
| 88 | */ |
| 89 | |
| 90 | #define DRV_NAME "3c523" |
| 91 | #define DRV_VERSION "17-Nov-2001" |
| 92 | |
| 93 | #include <linux/init.h> |
| 94 | #include <linux/netdevice.h> |
| 95 | #include <linux/etherdevice.h> |
| 96 | #include <linux/module.h> |
| 97 | #include <linux/kernel.h> |
| 98 | #include <linux/string.h> |
| 99 | #include <linux/errno.h> |
| 100 | #include <linux/ioport.h> |
| 101 | #include <linux/skbuff.h> |
| 102 | #include <linux/slab.h> |
| 103 | #include <linux/interrupt.h> |
| 104 | #include <linux/delay.h> |
| 105 | #include <linux/mca-legacy.h> |
| 106 | #include <linux/ethtool.h> |
| 107 | #include <linux/bitops.h> |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 108 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | #include <asm/uaccess.h> |
| 111 | #include <asm/processor.h> |
| 112 | #include <asm/io.h> |
| 113 | |
| 114 | #include "3c523.h" |
| 115 | |
| 116 | /*************************************************************************/ |
| 117 | #define DEBUG /* debug on */ |
| 118 | #define SYSBUSVAL 0 /* 1 = 8 Bit, 0 = 16 bit - 3c523 only does 16 bit */ |
| 119 | #undef ELMC_MULTICAST /* Disable multicast support as it is somewhat seriously broken at the moment */ |
| 120 | |
| 121 | #define make32(ptr16) (p->memtop + (short) (ptr16) ) |
| 122 | #define make24(ptr32) ((char *) (ptr32) - p->base) |
| 123 | #define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop )) |
| 124 | |
| 125 | /*************************************************************************/ |
| 126 | /* |
| 127 | Tables to which we can map values in the configuration registers. |
| 128 | */ |
| 129 | static int irq_table[] __initdata = { |
| 130 | 12, 7, 3, 9 |
| 131 | }; |
| 132 | |
| 133 | static int csr_table[] __initdata = { |
| 134 | 0x300, 0x1300, 0x2300, 0x3300 |
| 135 | }; |
| 136 | |
| 137 | static int shm_table[] __initdata = { |
| 138 | 0x0c0000, 0x0c8000, 0x0d0000, 0x0d8000 |
| 139 | }; |
| 140 | |
| 141 | /******************* how to calculate the buffers ***************************** |
| 142 | |
| 143 | |
| 144 | * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works |
| 145 | * --------------- in a different (more stable?) mode. Only in this mode it's |
| 146 | * possible to configure the driver with 'NO_NOPCOMMANDS' |
| 147 | |
| 148 | sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8; |
| 149 | sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT |
| 150 | sizeof(rfd) = 24; sizeof(rbd) = 12; |
| 151 | sizeof(tbd) = 8; sizeof(transmit_cmd) = 16; |
| 152 | sizeof(nop_cmd) = 8; |
| 153 | |
| 154 | * if you don't know the driver, better do not change this values: */ |
| 155 | |
| 156 | #define RECV_BUFF_SIZE 1524 /* slightly oversized */ |
| 157 | #define XMIT_BUFF_SIZE 1524 /* slightly oversized */ |
| 158 | #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */ |
| 159 | #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */ |
| 160 | #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */ |
| 161 | |
| 162 | #if (NUM_XMIT_BUFFS == 1) |
| 163 | #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */ |
| 164 | #endif |
| 165 | |
| 166 | /**************************************************************************/ |
| 167 | |
| 168 | #define DELAY(x) { mdelay(32 * x); } |
| 169 | |
| 170 | /* a much shorter delay: */ |
| 171 | #define DELAY_16(); { udelay(16) ; } |
| 172 | |
| 173 | /* wait for command with timeout: */ |
| 174 | #define WAIT_4_SCB_CMD() { int i; \ |
| 175 | for(i=0;i<1024;i++) { \ |
| 176 | if(!p->scb->cmd) break; \ |
| 177 | DELAY_16(); \ |
| 178 | if(i == 1023) { \ |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 179 | pr_warning("%s:%d: scb_cmd timed out .. resetting i82586\n",\ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | dev->name,__LINE__); \ |
| 181 | elmc_id_reset586(); } } } |
| 182 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 183 | static irqreturn_t elmc_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | static int elmc_open(struct net_device *dev); |
| 185 | static int elmc_close(struct net_device *dev); |
Stephen Hemminger | 27a1de9 | 2009-08-31 19:50:54 +0000 | [diff] [blame] | 186 | static netdev_tx_t elmc_send_packet(struct sk_buff *, struct net_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | static struct net_device_stats *elmc_get_stats(struct net_device *dev); |
| 188 | static void elmc_timeout(struct net_device *dev); |
| 189 | #ifdef ELMC_MULTICAST |
| 190 | static void set_multicast_list(struct net_device *dev); |
| 191 | #endif |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 192 | static const struct ethtool_ops netdev_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | /* helper-functions */ |
| 195 | static int init586(struct net_device *dev); |
| 196 | static int check586(struct net_device *dev, unsigned long where, unsigned size); |
| 197 | static void alloc586(struct net_device *dev); |
| 198 | static void startrecv586(struct net_device *dev); |
| 199 | static void *alloc_rfa(struct net_device *dev, void *ptr); |
| 200 | static void elmc_rcv_int(struct net_device *dev); |
| 201 | static void elmc_xmt_int(struct net_device *dev); |
| 202 | static void elmc_rnr_int(struct net_device *dev); |
| 203 | |
| 204 | struct priv { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | unsigned long base; |
| 206 | char *memtop; |
| 207 | unsigned long mapped_start; /* Start of ioremap */ |
| 208 | volatile struct rfd_struct *rfd_last, *rfd_top, *rfd_first; |
| 209 | volatile struct scp_struct *scp; /* volatile is important */ |
| 210 | volatile struct iscp_struct *iscp; /* volatile is important */ |
| 211 | volatile struct scb_struct *scb; /* volatile is important */ |
| 212 | volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS]; |
| 213 | #if (NUM_XMIT_BUFFS == 1) |
| 214 | volatile struct transmit_cmd_struct *xmit_cmds[2]; |
| 215 | volatile struct nop_cmd_struct *nop_cmds[2]; |
| 216 | #else |
| 217 | volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS]; |
| 218 | volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS]; |
| 219 | #endif |
| 220 | volatile int nop_point, num_recv_buffs; |
| 221 | volatile char *xmit_cbuffs[NUM_XMIT_BUFFS]; |
| 222 | volatile int xmit_count, xmit_last; |
| 223 | volatile int slot; |
| 224 | }; |
| 225 | |
| 226 | #define elmc_attn586() {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);} |
| 227 | #define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);} |
| 228 | |
| 229 | /* with interrupts disabled - this will clear the interrupt bit in the |
| 230 | 3c523 control register, and won't put it back. This effectively |
| 231 | disables interrupts on the card. */ |
| 232 | #define elmc_id_attn586() {elmc_do_attn586(dev->base_addr,0);} |
| 233 | #define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);} |
| 234 | |
| 235 | /*************************************************************************/ |
| 236 | /* |
| 237 | Do a Channel Attention on the 3c523. This is extremely board dependent. |
| 238 | */ |
| 239 | static void elmc_do_attn586(int ioaddr, int ints) |
| 240 | { |
| 241 | /* the 3c523 requires a minimum of 500 ns. The delays here might be |
| 242 | a little too large, and hence they may cut the performance of the |
| 243 | card slightly. If someone who knows a little more about Linux |
| 244 | timing would care to play with these, I'd appreciate it. */ |
| 245 | |
| 246 | /* this bit masking stuff is crap. I'd rather have separate |
| 247 | registers with strobe triggers for each of these functions. <sigh> |
| 248 | Ya take what ya got. */ |
| 249 | |
| 250 | outb(ELMC_CTRL_RST | 0x3 | ELMC_CTRL_CA | ints, ioaddr + ELMC_CTRL); |
| 251 | DELAY_16(); /* > 500 ns */ |
| 252 | outb(ELMC_CTRL_RST | 0x3 | ints, ioaddr + ELMC_CTRL); |
| 253 | } |
| 254 | |
| 255 | /*************************************************************************/ |
| 256 | /* |
| 257 | Reset the 82586 on the 3c523. Also very board dependent. |
| 258 | */ |
| 259 | static void elmc_do_reset586(int ioaddr, int ints) |
| 260 | { |
| 261 | /* toggle the RST bit low then high */ |
| 262 | outb(0x3 | ELMC_CTRL_LBK, ioaddr + ELMC_CTRL); |
| 263 | DELAY_16(); /* > 500 ns */ |
| 264 | outb(ELMC_CTRL_RST | ELMC_CTRL_LBK | 0x3, ioaddr + ELMC_CTRL); |
| 265 | |
| 266 | elmc_do_attn586(ioaddr, ints); |
| 267 | } |
| 268 | |
| 269 | /********************************************** |
| 270 | * close device |
| 271 | */ |
| 272 | |
| 273 | static int elmc_close(struct net_device *dev) |
| 274 | { |
| 275 | netif_stop_queue(dev); |
| 276 | elmc_id_reset586(); /* the hard way to stop the receiver */ |
| 277 | free_irq(dev->irq, dev); |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | /********************************************** |
| 282 | * open device |
| 283 | */ |
| 284 | |
| 285 | static int elmc_open(struct net_device *dev) |
| 286 | { |
| 287 | int ret; |
| 288 | |
| 289 | elmc_id_attn586(); /* disable interrupts */ |
| 290 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 291 | ret = request_irq(dev->irq, elmc_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | dev->name, dev); |
| 293 | if (ret) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 294 | pr_err("%s: couldn't get irq %d\n", dev->name, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | elmc_id_reset586(); |
| 296 | return ret; |
| 297 | } |
| 298 | alloc586(dev); |
| 299 | init586(dev); |
| 300 | startrecv586(dev); |
| 301 | netif_start_queue(dev); |
| 302 | return 0; /* most done by init */ |
| 303 | } |
| 304 | |
| 305 | /********************************************** |
| 306 | * Check to see if there's an 82586 out there. |
| 307 | */ |
| 308 | |
| 309 | static int __init check586(struct net_device *dev, unsigned long where, unsigned size) |
| 310 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 311 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | char *iscp_addrs[2]; |
| 313 | int i = 0; |
| 314 | |
| 315 | p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000; |
| 316 | p->memtop = isa_bus_to_virt((unsigned long)where) + size; |
| 317 | p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS); |
| 318 | memset((char *) p->scp, 0, sizeof(struct scp_struct)); |
| 319 | p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */ |
| 320 | |
| 321 | iscp_addrs[0] = isa_bus_to_virt((unsigned long)where); |
| 322 | iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct); |
| 323 | |
| 324 | for (i = 0; i < 2; i++) { |
| 325 | p->iscp = (struct iscp_struct *) iscp_addrs[i]; |
| 326 | memset((char *) p->iscp, 0, sizeof(struct iscp_struct)); |
| 327 | |
| 328 | p->scp->iscp = make24(p->iscp); |
| 329 | p->iscp->busy = 1; |
| 330 | |
| 331 | elmc_id_reset586(); |
| 332 | |
| 333 | /* reset586 does an implicit CA */ |
| 334 | |
| 335 | /* apparently, you sometimes have to kick the 82586 twice... */ |
| 336 | elmc_id_attn586(); |
| 337 | DELAY(1); |
| 338 | |
| 339 | if (p->iscp->busy) { /* i82586 clears 'busy' after successful init */ |
| 340 | return 0; |
| 341 | } |
| 342 | } |
| 343 | return 1; |
| 344 | } |
| 345 | |
| 346 | /****************************************************************** |
| 347 | * set iscp at the right place, called by elmc_probe and open586. |
| 348 | */ |
| 349 | |
Hannes Eder | dac499f | 2008-12-25 23:56:45 -0800 | [diff] [blame] | 350 | static void alloc586(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 352 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | elmc_id_reset586(); |
| 355 | DELAY(2); |
| 356 | |
| 357 | p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS); |
| 358 | p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start); |
| 359 | p->iscp = (struct iscp_struct *) ((char *) p->scp - sizeof(struct iscp_struct)); |
| 360 | |
| 361 | memset((char *) p->iscp, 0, sizeof(struct iscp_struct)); |
| 362 | memset((char *) p->scp, 0, sizeof(struct scp_struct)); |
| 363 | |
| 364 | p->scp->iscp = make24(p->iscp); |
| 365 | p->scp->sysbus = SYSBUSVAL; |
| 366 | p->iscp->scb_offset = make16(p->scb); |
| 367 | |
| 368 | p->iscp->busy = 1; |
| 369 | elmc_id_reset586(); |
| 370 | elmc_id_attn586(); |
| 371 | |
| 372 | DELAY(2); |
| 373 | |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 374 | if (p->iscp->busy) |
| 375 | pr_err("%s: Init-Problems (alloc).\n", dev->name); |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | memset((char *) p->scb, 0, sizeof(struct scb_struct)); |
| 378 | } |
| 379 | |
| 380 | /*****************************************************************/ |
| 381 | |
| 382 | static int elmc_getinfo(char *buf, int slot, void *d) |
| 383 | { |
| 384 | int len = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 385 | struct net_device *dev = d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | if (dev == NULL) |
| 388 | return len; |
| 389 | |
| 390 | len += sprintf(buf + len, "Revision: 0x%x\n", |
| 391 | inb(dev->base_addr + ELMC_REVISION) & 0xf); |
| 392 | len += sprintf(buf + len, "IRQ: %d\n", dev->irq); |
| 393 | len += sprintf(buf + len, "IO Address: %#lx-%#lx\n", dev->base_addr, |
| 394 | dev->base_addr + ELMC_IO_EXTENT); |
| 395 | len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start, |
| 396 | dev->mem_end - 1); |
| 397 | len += sprintf(buf + len, "Transceiver: %s\n", dev->if_port ? |
| 398 | "External" : "Internal"); |
| 399 | len += sprintf(buf + len, "Device: %s\n", dev->name); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 400 | len += sprintf(buf + len, "Hardware Address: %pM\n", |
| 401 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | return len; |
| 404 | } /* elmc_getinfo() */ |
| 405 | |
Stephen Hemminger | 90e64c6 | 2009-01-09 13:01:16 +0000 | [diff] [blame] | 406 | static const struct net_device_ops netdev_ops = { |
| 407 | .ndo_open = elmc_open, |
| 408 | .ndo_stop = elmc_close, |
| 409 | .ndo_get_stats = elmc_get_stats, |
| 410 | .ndo_start_xmit = elmc_send_packet, |
| 411 | .ndo_tx_timeout = elmc_timeout, |
| 412 | #ifdef ELMC_MULTICAST |
| 413 | .ndo_set_multicast_list = set_multicast_list, |
| 414 | #endif |
| 415 | .ndo_change_mtu = eth_change_mtu, |
| 416 | .ndo_set_mac_address = eth_mac_addr, |
| 417 | .ndo_validate_addr = eth_validate_addr, |
| 418 | }; |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | /*****************************************************************/ |
| 421 | |
| 422 | static int __init do_elmc_probe(struct net_device *dev) |
| 423 | { |
| 424 | static int slot; |
| 425 | int base_addr = dev->base_addr; |
| 426 | int irq = dev->irq; |
| 427 | u_char status = 0; |
| 428 | u_char revision = 0; |
| 429 | int i = 0; |
| 430 | unsigned int size = 0; |
| 431 | int retval; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 432 | struct priv *pr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (MCA_bus == 0) { |
| 435 | return -ENODEV; |
| 436 | } |
| 437 | /* search through the slots for the 3c523. */ |
| 438 | slot = mca_find_adapter(ELMC_MCA_ID, 0); |
| 439 | while (slot != -1) { |
| 440 | status = mca_read_stored_pos(slot, 2); |
| 441 | |
| 442 | dev->irq=irq_table[(status & ELMC_STATUS_IRQ_SELECT) >> 6]; |
| 443 | dev->base_addr=csr_table[(status & ELMC_STATUS_CSR_SELECT) >> 1]; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | /* |
| 446 | If we're trying to match a specified irq or IO address, |
| 447 | we'll reject a match unless it's what we're looking for. |
| 448 | Also reject it if the card is already in use. |
| 449 | */ |
| 450 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 451 | if ((irq && irq != dev->irq) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | (base_addr && base_addr != dev->base_addr)) { |
| 453 | slot = mca_find_adapter(ELMC_MCA_ID, slot + 1); |
| 454 | continue; |
| 455 | } |
| 456 | if (!request_region(dev->base_addr, ELMC_IO_EXTENT, DRV_NAME)) { |
| 457 | slot = mca_find_adapter(ELMC_MCA_ID, slot + 1); |
| 458 | continue; |
| 459 | } |
| 460 | |
| 461 | /* found what we're looking for... */ |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | /* we didn't find any 3c523 in the slots we checked for */ |
| 466 | if (slot == MCA_NOTFOUND) |
| 467 | return ((base_addr || irq) ? -ENXIO : -ENODEV); |
| 468 | |
| 469 | mca_set_adapter_name(slot, "3Com 3c523 Etherlink/MC"); |
| 470 | mca_set_adapter_procfn(slot, (MCA_ProcFn) elmc_getinfo, dev); |
| 471 | |
| 472 | /* if we get this far, adapter has been found - carry on */ |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 473 | pr_info("%s: 3c523 adapter found in slot %d\n", dev->name, slot + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | /* Now we extract configuration info from the card. |
| 476 | The 3c523 provides information in two of the POS registers, but |
| 477 | the second one is only needed if we want to tell the card what IRQ |
| 478 | to use. I suspect that whoever sets the thing up initially would |
| 479 | prefer we don't screw with those things. |
| 480 | |
| 481 | Note that we read the status info when we found the card... |
| 482 | |
| 483 | See 3c523.h for more details. |
| 484 | */ |
| 485 | |
| 486 | /* revision is stored in the first 4 bits of the revision register */ |
| 487 | revision = inb(dev->base_addr + ELMC_REVISION) & 0xf; |
| 488 | |
| 489 | /* according to docs, we read the interrupt and write it back to |
| 490 | the IRQ select register, since the POST might not configure the IRQ |
| 491 | properly. */ |
| 492 | switch (dev->irq) { |
| 493 | case 3: |
| 494 | mca_write_pos(slot, 3, 0x04); |
| 495 | break; |
| 496 | case 7: |
| 497 | mca_write_pos(slot, 3, 0x02); |
| 498 | break; |
| 499 | case 9: |
| 500 | mca_write_pos(slot, 3, 0x08); |
| 501 | break; |
| 502 | case 12: |
| 503 | mca_write_pos(slot, 3, 0x01); |
| 504 | break; |
| 505 | } |
| 506 | |
| 507 | memset(pr, 0, sizeof(struct priv)); |
| 508 | pr->slot = slot; |
| 509 | |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 510 | pr_info("%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev->name, (int) revision, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | dev->base_addr); |
| 512 | |
| 513 | /* Determine if we're using the on-board transceiver (i.e. coax) or |
| 514 | an external one. The information is pretty much useless, but I |
| 515 | guess it's worth brownie points. */ |
| 516 | dev->if_port = (status & ELMC_STATUS_DISABLE_THIN); |
| 517 | |
| 518 | /* The 3c523 has a 24K chunk of memory. The first 16K is the |
| 519 | shared memory, while the last 8K is for the EtherStart BIOS ROM. |
| 520 | Which we don't care much about here. We'll just tell Linux that |
| 521 | we're using 16K. MCA won't permit address space conflicts caused |
| 522 | by not mapping the other 8K. */ |
| 523 | dev->mem_start = shm_table[(status & ELMC_STATUS_MEMORY_SELECT) >> 3]; |
| 524 | |
| 525 | /* We're using MCA, so it's a given that the information about memory |
| 526 | size is correct. The Crynwr drivers do something like this. */ |
| 527 | |
| 528 | elmc_id_reset586(); /* seems like a good idea before checking it... */ |
| 529 | |
| 530 | size = 0x4000; /* check for 16K mem */ |
| 531 | if (!check586(dev, dev->mem_start, size)) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 532 | pr_err("%s: memprobe, Can't find memory at 0x%lx!\n", dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | dev->mem_start); |
| 534 | retval = -ENODEV; |
| 535 | goto err_out; |
| 536 | } |
| 537 | dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */ |
| 538 | |
| 539 | pr->memtop = isa_bus_to_virt(dev->mem_start) + size; |
| 540 | pr->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000; |
| 541 | alloc586(dev); |
| 542 | |
| 543 | elmc_id_reset586(); /* make sure it doesn't generate spurious ints */ |
| 544 | |
| 545 | /* set number of receive-buffs according to memsize */ |
| 546 | pr->num_recv_buffs = NUM_RECV_BUFFS_16; |
| 547 | |
| 548 | /* dump all the assorted information */ |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 549 | pr_info("%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->name, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 550 | dev->irq, dev->if_port ? "ex" : "in", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | dev->mem_start, dev->mem_end - 1); |
| 552 | |
| 553 | /* The hardware address for the 3c523 is stored in the first six |
| 554 | bytes of the IO address. */ |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 555 | for (i = 0; i < 6; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | dev->dev_addr[i] = inb(dev->base_addr + i); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 557 | |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 558 | pr_info("%s: hardware address %pM\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 559 | dev->name, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Stephen Hemminger | 90e64c6 | 2009-01-09 13:01:16 +0000 | [diff] [blame] | 561 | dev->netdev_ops = &netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | dev->watchdog_timeo = HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | dev->ethtool_ops = &netdev_ethtool_ops; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | /* note that we haven't actually requested the IRQ from the kernel. |
| 566 | That gets done in elmc_open(). I'm not sure that's such a good idea, |
| 567 | but it works, so I'll go with it. */ |
| 568 | |
| 569 | #ifndef ELMC_MULTICAST |
| 570 | dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */ |
| 571 | #endif |
| 572 | |
| b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 573 | retval = register_netdev(dev); |
| 574 | if (retval) |
| 575 | goto err_out; |
| 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return 0; |
| 578 | err_out: |
| 579 | mca_set_adapter_procfn(slot, NULL, NULL); |
| 580 | release_region(dev->base_addr, ELMC_IO_EXTENT); |
| 581 | return retval; |
| 582 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 583 | |
Ingo Molnar | 46a8494 | 2008-11-25 17:02:20 -0800 | [diff] [blame] | 584 | #ifdef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | static void cleanup_card(struct net_device *dev) |
| 586 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 587 | mca_set_adapter_procfn(((struct priv *)netdev_priv(dev))->slot, |
| 588 | NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | release_region(dev->base_addr, ELMC_IO_EXTENT); |
| 590 | } |
Ingo Molnar | 46a8494 | 2008-11-25 17:02:20 -0800 | [diff] [blame] | 591 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | struct net_device * __init elmc_probe(int unit) |
| 593 | { |
| 594 | struct net_device *dev = alloc_etherdev(sizeof(struct priv)); |
| 595 | int err; |
| 596 | |
| 597 | if (!dev) |
| 598 | return ERR_PTR(-ENOMEM); |
| 599 | |
| 600 | sprintf(dev->name, "eth%d", unit); |
| 601 | netdev_boot_setup_check(dev); |
| 602 | |
| 603 | err = do_elmc_probe(dev); |
| 604 | if (err) |
| 605 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | return dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | out: |
| 608 | free_netdev(dev); |
| 609 | return ERR_PTR(err); |
| 610 | } |
| 611 | #endif |
| 612 | |
| 613 | /********************************************** |
| 614 | * init the chip (elmc-interrupt should be disabled?!) |
| 615 | * needs a correct 'allocated' memory |
| 616 | */ |
| 617 | |
| 618 | static int init586(struct net_device *dev) |
| 619 | { |
| 620 | void *ptr; |
| 621 | unsigned long s; |
| 622 | int i, result = 0; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 623 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | volatile struct configure_cmd_struct *cfg_cmd; |
| 625 | volatile struct iasetup_cmd_struct *ias_cmd; |
| 626 | volatile struct tdr_cmd_struct *tdr_cmd; |
| 627 | volatile struct mcsetup_cmd_struct *mc_cmd; |
| 628 | struct dev_mc_list *dmi = dev->mc_list; |
| 629 | int num_addrs = dev->mc_count; |
| 630 | |
| 631 | ptr = (void *) ((char *) p->scb + sizeof(struct scb_struct)); |
| 632 | |
| 633 | cfg_cmd = (struct configure_cmd_struct *) ptr; /* configure-command */ |
| 634 | cfg_cmd->cmd_status = 0; |
| 635 | cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST; |
| 636 | cfg_cmd->cmd_link = 0xffff; |
| 637 | |
| 638 | cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */ |
| 639 | cfg_cmd->fifo = 0x08; /* fifo-limit (8=tx:32/rx:64) */ |
| 640 | cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */ |
| 641 | cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */ |
| 642 | cfg_cmd->priority = 0x00; |
| 643 | cfg_cmd->ifs = 0x60; |
| 644 | cfg_cmd->time_low = 0x00; |
| 645 | cfg_cmd->time_high = 0xf2; |
| 646 | cfg_cmd->promisc = 0; |
Wang Chen | c16d118 | 2008-07-22 13:13:12 +0800 | [diff] [blame] | 647 | if (dev->flags & (IFF_ALLMULTI | IFF_PROMISC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | cfg_cmd->promisc = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | cfg_cmd->carr_coll = 0x00; |
| 650 | |
| 651 | p->scb->cbl_offset = make16(cfg_cmd); |
| 652 | |
| 653 | p->scb->cmd = CUC_START; /* cmd.-unit start */ |
| 654 | elmc_id_attn586(); |
| 655 | |
| 656 | s = jiffies; /* warning: only active with interrupts on !! */ |
| 657 | while (!(cfg_cmd->cmd_status & STAT_COMPL)) { |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 658 | if (time_after(jiffies, s + 30*HZ/100)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | break; |
| 660 | } |
| 661 | |
| 662 | if ((cfg_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_COMPL | STAT_OK)) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 663 | pr_warning("%s (elmc): configure command failed: %x\n", dev->name, cfg_cmd->cmd_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | return 1; |
| 665 | } |
| 666 | /* |
| 667 | * individual address setup |
| 668 | */ |
| 669 | ias_cmd = (struct iasetup_cmd_struct *) ptr; |
| 670 | |
| 671 | ias_cmd->cmd_status = 0; |
| 672 | ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST; |
| 673 | ias_cmd->cmd_link = 0xffff; |
| 674 | |
| 675 | memcpy((char *) &ias_cmd->iaddr, (char *) dev->dev_addr, ETH_ALEN); |
| 676 | |
| 677 | p->scb->cbl_offset = make16(ias_cmd); |
| 678 | |
| 679 | p->scb->cmd = CUC_START; /* cmd.-unit start */ |
| 680 | elmc_id_attn586(); |
| 681 | |
| 682 | s = jiffies; |
| 683 | while (!(ias_cmd->cmd_status & STAT_COMPL)) { |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 684 | if (time_after(jiffies, s + 30*HZ/100)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | break; |
| 686 | } |
| 687 | |
| 688 | if ((ias_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_OK | STAT_COMPL)) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 689 | pr_warning("%s (elmc): individual address setup command failed: %04x\n", |
| 690 | dev->name, ias_cmd->cmd_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | return 1; |
| 692 | } |
| 693 | /* |
| 694 | * TDR, wire check .. e.g. no resistor e.t.c |
| 695 | */ |
| 696 | tdr_cmd = (struct tdr_cmd_struct *) ptr; |
| 697 | |
| 698 | tdr_cmd->cmd_status = 0; |
| 699 | tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST; |
| 700 | tdr_cmd->cmd_link = 0xffff; |
| 701 | tdr_cmd->status = 0; |
| 702 | |
| 703 | p->scb->cbl_offset = make16(tdr_cmd); |
| 704 | |
| 705 | p->scb->cmd = CUC_START; /* cmd.-unit start */ |
| 706 | elmc_attn586(); |
| 707 | |
| 708 | s = jiffies; |
| 709 | while (!(tdr_cmd->cmd_status & STAT_COMPL)) { |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 710 | if (time_after(jiffies, s + 30*HZ/100)) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 711 | pr_warning("%s: %d Problems while running the TDR.\n", dev->name, __LINE__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | result = 1; |
| 713 | break; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | if (!result) { |
| 718 | DELAY(2); /* wait for result */ |
| 719 | result = tdr_cmd->status; |
| 720 | |
| 721 | p->scb->cmd = p->scb->status & STAT_MASK; |
| 722 | elmc_id_attn586(); /* ack the interrupts */ |
| 723 | |
| 724 | if (result & TDR_LNK_OK) { |
| 725 | /* empty */ |
| 726 | } else if (result & TDR_XCVR_PRB) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 727 | pr_warning("%s: TDR: Transceiver problem!\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } else if (result & TDR_ET_OPN) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 729 | pr_warning("%s: TDR: No correct termination %d clocks away.\n", dev->name, result & TDR_TIMEMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } else if (result & TDR_ET_SRT) { |
| 731 | if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */ |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 732 | pr_warning("%s: TDR: Detected a short circuit %d clocks away.\n", dev->name, result & TDR_TIMEMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } else { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 734 | pr_warning("%s: TDR: Unknown status %04x\n", dev->name, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | /* |
| 738 | * ack interrupts |
| 739 | */ |
| 740 | p->scb->cmd = p->scb->status & STAT_MASK; |
| 741 | elmc_id_attn586(); |
| 742 | |
| 743 | /* |
| 744 | * alloc nop/xmit-cmds |
| 745 | */ |
| 746 | #if (NUM_XMIT_BUFFS == 1) |
| 747 | for (i = 0; i < 2; i++) { |
| 748 | p->nop_cmds[i] = (struct nop_cmd_struct *) ptr; |
| 749 | p->nop_cmds[i]->cmd_cmd = CMD_NOP; |
| 750 | p->nop_cmds[i]->cmd_status = 0; |
| 751 | p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); |
| 752 | ptr = (char *) ptr + sizeof(struct nop_cmd_struct); |
| 753 | } |
| 754 | p->xmit_cmds[0] = (struct transmit_cmd_struct *) ptr; /* transmit cmd/buff 0 */ |
| 755 | ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); |
| 756 | #else |
| 757 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
| 758 | p->nop_cmds[i] = (struct nop_cmd_struct *) ptr; |
| 759 | p->nop_cmds[i]->cmd_cmd = CMD_NOP; |
| 760 | p->nop_cmds[i]->cmd_status = 0; |
| 761 | p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); |
| 762 | ptr = (char *) ptr + sizeof(struct nop_cmd_struct); |
| 763 | p->xmit_cmds[i] = (struct transmit_cmd_struct *) ptr; /*transmit cmd/buff 0 */ |
| 764 | ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); |
| 765 | } |
| 766 | #endif |
| 767 | |
| 768 | ptr = alloc_rfa(dev, (void *) ptr); /* init receive-frame-area */ |
| 769 | |
| 770 | /* |
| 771 | * Multicast setup |
| 772 | */ |
| 773 | |
| 774 | if (dev->mc_count) { |
| 775 | /* I don't understand this: do we really need memory after the init? */ |
| 776 | int len = ((char *) p->iscp - (char *) ptr - 8) / 6; |
| 777 | if (len <= 0) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 778 | pr_err("%s: Ooooops, no memory for MC-Setup!\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } else { |
| 780 | if (len < num_addrs) { |
| 781 | num_addrs = len; |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 782 | pr_warning("%s: Sorry, can only apply %d MC-Address(es).\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | dev->name, num_addrs); |
| 784 | } |
| 785 | mc_cmd = (struct mcsetup_cmd_struct *) ptr; |
| 786 | mc_cmd->cmd_status = 0; |
| 787 | mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST; |
| 788 | mc_cmd->cmd_link = 0xffff; |
| 789 | mc_cmd->mc_cnt = num_addrs * 6; |
| 790 | for (i = 0; i < num_addrs; i++) { |
| 791 | memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr, 6); |
| 792 | dmi = dmi->next; |
| 793 | } |
| 794 | p->scb->cbl_offset = make16(mc_cmd); |
| 795 | p->scb->cmd = CUC_START; |
| 796 | elmc_id_attn586(); |
| 797 | s = jiffies; |
| 798 | while (!(mc_cmd->cmd_status & STAT_COMPL)) { |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 799 | if (time_after(jiffies, s + 30*HZ/100)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | break; |
| 801 | } |
| 802 | if (!(mc_cmd->cmd_status & STAT_COMPL)) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 803 | pr_warning("%s: Can't apply multicast-address-list.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | } |
| 807 | /* |
| 808 | * alloc xmit-buffs / init xmit_cmds |
| 809 | */ |
| 810 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { |
| 811 | p->xmit_cbuffs[i] = (char *) ptr; /* char-buffs */ |
| 812 | ptr = (char *) ptr + XMIT_BUFF_SIZE; |
| 813 | p->xmit_buffs[i] = (struct tbd_struct *) ptr; /* TBD */ |
| 814 | ptr = (char *) ptr + sizeof(struct tbd_struct); |
| 815 | if ((void *) ptr > (void *) p->iscp) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 816 | pr_err("%s: not enough shared-mem for your configuration!\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return 1; |
| 818 | } |
| 819 | memset((char *) (p->xmit_cmds[i]), 0, sizeof(struct transmit_cmd_struct)); |
| 820 | memset((char *) (p->xmit_buffs[i]), 0, sizeof(struct tbd_struct)); |
| 821 | p->xmit_cmds[i]->cmd_status = STAT_COMPL; |
| 822 | p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT; |
| 823 | p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i])); |
| 824 | p->xmit_buffs[i]->next = 0xffff; |
| 825 | p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i])); |
| 826 | } |
| 827 | |
| 828 | p->xmit_count = 0; |
| 829 | p->xmit_last = 0; |
| 830 | #ifndef NO_NOPCOMMANDS |
| 831 | p->nop_point = 0; |
| 832 | #endif |
| 833 | |
| 834 | /* |
| 835 | * 'start transmitter' (nop-loop) |
| 836 | */ |
| 837 | #ifndef NO_NOPCOMMANDS |
| 838 | p->scb->cbl_offset = make16(p->nop_cmds[0]); |
| 839 | p->scb->cmd = CUC_START; |
| 840 | elmc_id_attn586(); |
| 841 | WAIT_4_SCB_CMD(); |
| 842 | #else |
| 843 | p->xmit_cmds[0]->cmd_link = 0xffff; |
| 844 | p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_LAST | CMD_INT; |
| 845 | #endif |
| 846 | |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | /****************************************************** |
| 851 | * This is a helper routine for elmc_rnr_int() and init586(). |
| 852 | * It sets up the Receive Frame Area (RFA). |
| 853 | */ |
| 854 | |
| 855 | static void *alloc_rfa(struct net_device *dev, void *ptr) |
| 856 | { |
| 857 | volatile struct rfd_struct *rfd = (struct rfd_struct *) ptr; |
| 858 | volatile struct rbd_struct *rbd; |
| 859 | int i; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 860 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
| 862 | memset((char *) rfd, 0, sizeof(struct rfd_struct) * p->num_recv_buffs); |
| 863 | p->rfd_first = rfd; |
| 864 | |
| 865 | for (i = 0; i < p->num_recv_buffs; i++) { |
| 866 | rfd[i].next = make16(rfd + (i + 1) % p->num_recv_buffs); |
| 867 | } |
| 868 | rfd[p->num_recv_buffs - 1].last = RFD_SUSP; /* RU suspend */ |
| 869 | |
| 870 | ptr = (void *) (rfd + p->num_recv_buffs); |
| 871 | |
| 872 | rbd = (struct rbd_struct *) ptr; |
| 873 | ptr = (void *) (rbd + p->num_recv_buffs); |
| 874 | |
| 875 | /* clr descriptors */ |
| 876 | memset((char *) rbd, 0, sizeof(struct rbd_struct) * p->num_recv_buffs); |
| 877 | |
| 878 | for (i = 0; i < p->num_recv_buffs; i++) { |
| 879 | rbd[i].next = make16((rbd + (i + 1) % p->num_recv_buffs)); |
| 880 | rbd[i].size = RECV_BUFF_SIZE; |
| 881 | rbd[i].buffer = make24(ptr); |
| 882 | ptr = (char *) ptr + RECV_BUFF_SIZE; |
| 883 | } |
| 884 | |
| 885 | p->rfd_top = p->rfd_first; |
| 886 | p->rfd_last = p->rfd_first + p->num_recv_buffs - 1; |
| 887 | |
| 888 | p->scb->rfa_offset = make16(p->rfd_first); |
| 889 | p->rfd_first->rbd_offset = make16(rbd); |
| 890 | |
| 891 | return ptr; |
| 892 | } |
| 893 | |
| 894 | |
| 895 | /************************************************** |
| 896 | * Interrupt Handler ... |
| 897 | */ |
| 898 | |
| 899 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 900 | elmc_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | { |
Jeff Garzik | c31f28e | 2006-10-06 14:56:04 -0400 | [diff] [blame] | 902 | struct net_device *dev = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | unsigned short stat; |
| 904 | struct priv *p; |
| 905 | |
Jeff Garzik | c31f28e | 2006-10-06 14:56:04 -0400 | [diff] [blame] | 906 | if (!netif_running(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | /* The 3c523 has this habit of generating interrupts during the |
| 908 | reset. I'm not sure if the ni52 has this same problem, but it's |
| 909 | really annoying if we haven't finished initializing it. I was |
| 910 | hoping all the elmc_id_* commands would disable this, but I |
| 911 | might have missed a few. */ |
| 912 | |
| 913 | elmc_id_attn586(); /* ack inter. and disable any more */ |
| 914 | return IRQ_HANDLED; |
| 915 | } else if (!(ELMC_CTRL_INT & inb(dev->base_addr + ELMC_CTRL))) { |
| 916 | /* wasn't this device */ |
| 917 | return IRQ_NONE; |
| 918 | } |
| 919 | /* reading ELMC_CTRL also clears the INT bit. */ |
| 920 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 921 | p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 923 | while ((stat = p->scb->status & STAT_MASK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
| 925 | p->scb->cmd = stat; |
| 926 | elmc_attn586(); /* ack inter. */ |
| 927 | |
| 928 | if (stat & STAT_CX) { |
| 929 | /* command with I-bit set complete */ |
| 930 | elmc_xmt_int(dev); |
| 931 | } |
| 932 | if (stat & STAT_FR) { |
| 933 | /* received a frame */ |
| 934 | elmc_rcv_int(dev); |
| 935 | } |
| 936 | #ifndef NO_NOPCOMMANDS |
| 937 | if (stat & STAT_CNA) { |
| 938 | /* CU went 'not ready' */ |
| 939 | if (netif_running(dev)) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 940 | pr_warning("%s: oops! CU has left active state. stat: %04x/%04x.\n", |
| 941 | dev->name, (int) stat, (int) p->scb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | #endif |
| 945 | |
| 946 | if (stat & STAT_RNR) { |
| 947 | /* RU went 'not ready' */ |
| 948 | |
| 949 | if (p->scb->status & RU_SUSPEND) { |
| 950 | /* special case: RU_SUSPEND */ |
| 951 | |
| 952 | WAIT_4_SCB_CMD(); |
| 953 | p->scb->cmd = RUC_RESUME; |
| 954 | elmc_attn586(); |
| 955 | } else { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 956 | pr_warning("%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n", |
| 957 | dev->name, (int) stat, (int) p->scb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | elmc_rnr_int(dev); |
| 959 | } |
| 960 | } |
| 961 | WAIT_4_SCB_CMD(); /* wait for ack. (elmc_xmt_int can be faster than ack!!) */ |
| 962 | if (p->scb->cmd) { /* timed out? */ |
| 963 | break; |
| 964 | } |
| 965 | } |
| 966 | return IRQ_HANDLED; |
| 967 | } |
| 968 | |
| 969 | /******************************************************* |
| 970 | * receive-interrupt |
| 971 | */ |
| 972 | |
| 973 | static void elmc_rcv_int(struct net_device *dev) |
| 974 | { |
| 975 | int status; |
| 976 | unsigned short totlen; |
| 977 | struct sk_buff *skb; |
| 978 | struct rbd_struct *rbd; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 979 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
| 981 | for (; (status = p->rfd_top->status) & STAT_COMPL;) { |
| 982 | rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); |
| 983 | |
| 984 | if (status & STAT_OK) { /* frame received without error? */ |
| 985 | if ((totlen = rbd->status) & RBD_LAST) { /* the first and the last buffer? */ |
| 986 | totlen &= RBD_MASK; /* length of this frame */ |
| 987 | rbd->status = 0; |
| 988 | skb = (struct sk_buff *) dev_alloc_skb(totlen + 2); |
| 989 | if (skb != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | skb_reserve(skb, 2); /* 16 byte alignment */ |
| 991 | skb_put(skb,totlen); |
David S. Miller | 8c7b7fa | 2007-07-10 22:08:12 -0700 | [diff] [blame] | 992 | skb_copy_to_linear_data(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | skb->protocol = eth_type_trans(skb, dev); |
| 994 | netif_rx(skb); |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 995 | dev->stats.rx_packets++; |
| 996 | dev->stats.rx_bytes += totlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } else { |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 998 | dev->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | } |
| 1000 | } else { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1001 | pr_warning("%s: received oversized frame.\n", dev->name); |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1002 | dev->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | } else { /* frame !(ok), only with 'save-bad-frames' */ |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1005 | pr_warning("%s: oops! rfd-error-status: %04x\n", dev->name, status); |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1006 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | } |
| 1008 | p->rfd_top->status = 0; |
| 1009 | p->rfd_top->last = RFD_SUSP; |
| 1010 | p->rfd_last->last = 0; /* delete RU_SUSP */ |
| 1011 | p->rfd_last = p->rfd_top; |
| 1012 | p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */ |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | /********************************************************** |
| 1017 | * handle 'Receiver went not ready'. |
| 1018 | */ |
| 1019 | |
| 1020 | static void elmc_rnr_int(struct net_device *dev) |
| 1021 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1022 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1024 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
| 1026 | WAIT_4_SCB_CMD(); /* wait for the last cmd */ |
| 1027 | p->scb->cmd = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */ |
| 1028 | elmc_attn586(); |
| 1029 | WAIT_4_SCB_CMD(); /* wait for accept cmd. */ |
| 1030 | |
| 1031 | alloc_rfa(dev, (char *) p->rfd_first); |
| 1032 | startrecv586(dev); /* restart RU */ |
| 1033 | |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1034 | pr_warning("%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
| 1036 | } |
| 1037 | |
| 1038 | /********************************************************** |
| 1039 | * handle xmit - interrupt |
| 1040 | */ |
| 1041 | |
| 1042 | static void elmc_xmt_int(struct net_device *dev) |
| 1043 | { |
| 1044 | int status; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1045 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | |
| 1047 | status = p->xmit_cmds[p->xmit_last]->cmd_status; |
| 1048 | if (!(status & STAT_COMPL)) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1049 | pr_warning("%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | } |
| 1051 | if (status & STAT_OK) { |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1052 | dev->stats.tx_packets++; |
| 1053 | dev->stats.collisions += (status & TCMD_MAXCOLLMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | } else { |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1055 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | if (status & TCMD_LATECOLL) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1057 | pr_warning("%s: late collision detected.\n", dev->name); |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1058 | dev->stats.collisions++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } else if (status & TCMD_NOCARRIER) { |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1060 | dev->stats.tx_carrier_errors++; |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1061 | pr_warning("%s: no carrier detected.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | } else if (status & TCMD_LOSTCTS) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1063 | pr_warning("%s: loss of CTS detected.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | } else if (status & TCMD_UNDERRUN) { |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1065 | dev->stats.tx_fifo_errors++; |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1066 | pr_warning("%s: DMA underrun detected.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | } else if (status & TCMD_MAXCOLL) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1068 | pr_warning("%s: Max. collisions exceeded.\n", dev->name); |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1069 | dev->stats.collisions += 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | #if (NUM_XMIT_BUFFS != 1) |
| 1074 | if ((++p->xmit_last) == NUM_XMIT_BUFFS) { |
| 1075 | p->xmit_last = 0; |
| 1076 | } |
| 1077 | #endif |
| 1078 | |
| 1079 | netif_wake_queue(dev); |
| 1080 | } |
| 1081 | |
| 1082 | /*********************************************************** |
| 1083 | * (re)start the receiver |
| 1084 | */ |
| 1085 | |
| 1086 | static void startrecv586(struct net_device *dev) |
| 1087 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1088 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
| 1090 | p->scb->rfa_offset = make16(p->rfd_first); |
| 1091 | p->scb->cmd = RUC_START; |
| 1092 | elmc_attn586(); /* start cmd. */ |
| 1093 | WAIT_4_SCB_CMD(); /* wait for accept cmd. (no timeout!!) */ |
| 1094 | } |
| 1095 | |
| 1096 | /****************************************************** |
| 1097 | * timeout |
| 1098 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | static void elmc_timeout(struct net_device *dev) |
| 1101 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1102 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | /* COMMAND-UNIT active? */ |
| 1104 | if (p->scb->status & CU_ACTIVE) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1105 | pr_debug("%s: strange ... timeout with CU active?!?\n", dev->name); |
| 1106 | pr_debug("%s: X0: %04x N0: %04x N1: %04x %d\n", dev->name, |
| 1107 | (int)p->xmit_cmds[0]->cmd_status, |
| 1108 | (int)p->nop_cmds[0]->cmd_status, |
| 1109 | (int)p->nop_cmds[1]->cmd_status, (int)p->nop_point); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | p->scb->cmd = CUC_ABORT; |
| 1111 | elmc_attn586(); |
| 1112 | WAIT_4_SCB_CMD(); |
| 1113 | p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]); |
| 1114 | p->scb->cmd = CUC_START; |
| 1115 | elmc_attn586(); |
| 1116 | WAIT_4_SCB_CMD(); |
| 1117 | netif_wake_queue(dev); |
| 1118 | } else { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1119 | pr_debug("%s: xmitter timed out, try to restart! stat: %04x\n", |
| 1120 | dev->name, p->scb->status); |
| 1121 | pr_debug("%s: command-stats: %04x %04x\n", dev->name, |
| 1122 | p->xmit_cmds[0]->cmd_status, p->xmit_cmds[1]->cmd_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | elmc_close(dev); |
| 1124 | elmc_open(dev); |
| 1125 | } |
| 1126 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | /****************************************************** |
| 1129 | * send frame |
| 1130 | */ |
| 1131 | |
Stephen Hemminger | 27a1de9 | 2009-08-31 19:50:54 +0000 | [diff] [blame] | 1132 | static netdev_tx_t elmc_send_packet(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | { |
| 1134 | int len; |
| 1135 | int i; |
| 1136 | #ifndef NO_NOPCOMMANDS |
| 1137 | int next_nop; |
| 1138 | #endif |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1139 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
| 1141 | netif_stop_queue(dev); |
| 1142 | |
| 1143 | len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | if (len != skb->len) |
| 1146 | memset((char *) p->xmit_cbuffs[p->xmit_count], 0, ETH_ZLEN); |
David S. Miller | 3dbad80 | 2007-03-29 19:16:03 -0700 | [diff] [blame] | 1147 | skb_copy_from_linear_data(skb, (char *) p->xmit_cbuffs[p->xmit_count], skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
| 1149 | #if (NUM_XMIT_BUFFS == 1) |
| 1150 | #ifdef NO_NOPCOMMANDS |
| 1151 | p->xmit_buffs[0]->size = TBD_LAST | len; |
| 1152 | for (i = 0; i < 16; i++) { |
| 1153 | p->scb->cbl_offset = make16(p->xmit_cmds[0]); |
| 1154 | p->scb->cmd = CUC_START; |
| 1155 | p->xmit_cmds[0]->cmd_status = 0; |
| 1156 | elmc_attn586(); |
| 1157 | dev->trans_start = jiffies; |
| 1158 | if (!i) { |
| 1159 | dev_kfree_skb(skb); |
| 1160 | } |
| 1161 | WAIT_4_SCB_CMD(); |
| 1162 | if ((p->scb->status & CU_ACTIVE)) { /* test it, because CU sometimes doesn't start immediately */ |
| 1163 | break; |
| 1164 | } |
| 1165 | if (p->xmit_cmds[0]->cmd_status) { |
| 1166 | break; |
| 1167 | } |
| 1168 | if (i == 15) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1169 | pr_warning("%s: Can't start transmit-command.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | #else |
| 1173 | next_nop = (p->nop_point + 1) & 0x1; |
| 1174 | p->xmit_buffs[0]->size = TBD_LAST | len; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link |
| 1177 | = make16((p->nop_cmds[next_nop])); |
| 1178 | p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0; |
| 1179 | |
| 1180 | p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0])); |
| 1181 | dev->trans_start = jiffies; |
| 1182 | p->nop_point = next_nop; |
| 1183 | dev_kfree_skb(skb); |
| 1184 | #endif |
| 1185 | #else |
| 1186 | p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len; |
| 1187 | if ((next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS) { |
| 1188 | next_nop = 0; |
| 1189 | } |
| 1190 | p->xmit_cmds[p->xmit_count]->cmd_status = 0; |
| 1191 | p->xmit_cmds[p->xmit_count]->cmd_link = p->nop_cmds[next_nop]->cmd_link |
| 1192 | = make16((p->nop_cmds[next_nop])); |
| 1193 | p->nop_cmds[next_nop]->cmd_status = 0; |
| 1194 | p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count])); |
| 1195 | dev->trans_start = jiffies; |
| 1196 | p->xmit_count = next_nop; |
| 1197 | if (p->xmit_count != p->xmit_last) |
| 1198 | netif_wake_queue(dev); |
| 1199 | dev_kfree_skb(skb); |
| 1200 | #endif |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1201 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /******************************************* |
| 1205 | * Someone wanna have the statistics |
| 1206 | */ |
| 1207 | |
| 1208 | static struct net_device_stats *elmc_get_stats(struct net_device *dev) |
| 1209 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1210 | struct priv *p = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | unsigned short crc, aln, rsc, ovrn; |
| 1212 | |
| 1213 | crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */ |
| 1214 | p->scb->crc_errs -= crc; |
| 1215 | aln = p->scb->aln_errs; |
| 1216 | p->scb->aln_errs -= aln; |
| 1217 | rsc = p->scb->rsc_errs; |
| 1218 | p->scb->rsc_errs -= rsc; |
| 1219 | ovrn = p->scb->ovrn_errs; |
| 1220 | p->scb->ovrn_errs -= ovrn; |
| 1221 | |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1222 | dev->stats.rx_crc_errors += crc; |
| 1223 | dev->stats.rx_fifo_errors += ovrn; |
| 1224 | dev->stats.rx_frame_errors += aln; |
| 1225 | dev->stats.rx_dropped += rsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | |
Paulius Zaleckas | aa50911 | 2008-04-29 11:58:42 +0300 | [diff] [blame] | 1227 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | /******************************************************** |
| 1231 | * Set MC list .. |
| 1232 | */ |
| 1233 | |
| 1234 | #ifdef ELMC_MULTICAST |
| 1235 | static void set_multicast_list(struct net_device *dev) |
| 1236 | { |
| 1237 | if (!dev->start) { |
| 1238 | /* without a running interface, promiscuous doesn't work */ |
| 1239 | return; |
| 1240 | } |
| 1241 | dev->start = 0; |
| 1242 | alloc586(dev); |
| 1243 | init586(dev); |
| 1244 | startrecv586(dev); |
| 1245 | dev->start = 1; |
| 1246 | } |
| 1247 | #endif |
| 1248 | |
| 1249 | static void netdev_get_drvinfo(struct net_device *dev, |
| 1250 | struct ethtool_drvinfo *info) |
| 1251 | { |
| 1252 | strcpy(info->driver, DRV_NAME); |
| 1253 | strcpy(info->version, DRV_VERSION); |
| 1254 | sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr); |
| 1255 | } |
| 1256 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1257 | static const struct ethtool_ops netdev_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | .get_drvinfo = netdev_get_drvinfo, |
| 1259 | }; |
| 1260 | |
| 1261 | #ifdef MODULE |
| 1262 | |
| 1263 | /* Increase if needed ;) */ |
| 1264 | #define MAX_3C523_CARDS 4 |
| 1265 | |
| 1266 | static struct net_device *dev_elmc[MAX_3C523_CARDS]; |
| 1267 | static int irq[MAX_3C523_CARDS]; |
| 1268 | static int io[MAX_3C523_CARDS]; |
| 1269 | module_param_array(irq, int, NULL, 0); |
| 1270 | module_param_array(io, int, NULL, 0); |
| 1271 | MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)"); |
| 1272 | MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)"); |
Randy Dunlap | 7b24017 | 2005-06-13 12:31:53 -0700 | [diff] [blame] | 1273 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
Randy Dunlap | 96e672c | 2006-06-10 13:33:48 -0700 | [diff] [blame] | 1275 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | { |
| 1277 | int this_dev,found = 0; |
| 1278 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1279 | /* Loop until we either can't find any more cards, or we have MAX_3C523_CARDS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | for(this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) { |
| 1281 | struct net_device *dev = alloc_etherdev(sizeof(struct priv)); |
| 1282 | if (!dev) |
| 1283 | break; |
| 1284 | dev->irq=irq[this_dev]; |
| 1285 | dev->base_addr=io[this_dev]; |
| 1286 | if (do_elmc_probe(dev) == 0) { |
| b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 1287 | dev_elmc[this_dev] = dev; |
| 1288 | found++; |
| 1289 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | } |
| 1291 | free_netdev(dev); |
| 1292 | if (io[this_dev]==0) |
| 1293 | break; |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1294 | pr_warning("3c523.c: No 3c523 card found at io=%#x\n",io[this_dev]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | if(found==0) { |
Alexander Beregalov | 39738e1 | 2009-05-26 12:35:26 +0000 | [diff] [blame] | 1298 | if (io[0]==0) |
| 1299 | pr_notice("3c523.c: No 3c523 cards found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | return -ENXIO; |
| 1301 | } else return 0; |
| 1302 | } |
| 1303 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 1304 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | { |
| 1306 | int this_dev; |
| 1307 | for (this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) { |
| 1308 | struct net_device *dev = dev_elmc[this_dev]; |
| 1309 | if (dev) { |
| 1310 | unregister_netdev(dev); |
| 1311 | cleanup_card(dev); |
| 1312 | free_netdev(dev); |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | #endif /* MODULE */ |