| 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) { \ | 
|  | 179 | printk(KERN_WARNING "%s:%d: scb_cmd timed out .. resetting i82586\n",\ | 
|  | 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); | 
|  | 186 | static int elmc_send_packet(struct sk_buff *, struct net_device *); | 
|  | 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 { | 
|  | 205 | struct net_device_stats stats; | 
|  | 206 | unsigned long base; | 
|  | 207 | char *memtop; | 
|  | 208 | unsigned long mapped_start;		/* Start of ioremap */ | 
|  | 209 | volatile struct rfd_struct *rfd_last, *rfd_top, *rfd_first; | 
|  | 210 | volatile struct scp_struct *scp;	/* volatile is important */ | 
|  | 211 | volatile struct iscp_struct *iscp;	/* volatile is important */ | 
|  | 212 | volatile struct scb_struct *scb;	/* volatile is important */ | 
|  | 213 | volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS]; | 
|  | 214 | #if (NUM_XMIT_BUFFS == 1) | 
|  | 215 | volatile struct transmit_cmd_struct *xmit_cmds[2]; | 
|  | 216 | volatile struct nop_cmd_struct *nop_cmds[2]; | 
|  | 217 | #else | 
|  | 218 | volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS]; | 
|  | 219 | volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS]; | 
|  | 220 | #endif | 
|  | 221 | volatile int nop_point, num_recv_buffs; | 
|  | 222 | volatile char *xmit_cbuffs[NUM_XMIT_BUFFS]; | 
|  | 223 | volatile int xmit_count, xmit_last; | 
|  | 224 | volatile int slot; | 
|  | 225 | }; | 
|  | 226 |  | 
|  | 227 | #define elmc_attn586()  {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);} | 
|  | 228 | #define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);} | 
|  | 229 |  | 
|  | 230 | /* with interrupts disabled - this will clear the interrupt bit in the | 
|  | 231 | 3c523 control register, and won't put it back.  This effectively | 
|  | 232 | disables interrupts on the card. */ | 
|  | 233 | #define elmc_id_attn586()  {elmc_do_attn586(dev->base_addr,0);} | 
|  | 234 | #define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);} | 
|  | 235 |  | 
|  | 236 | /*************************************************************************/ | 
|  | 237 | /* | 
|  | 238 | Do a Channel Attention on the 3c523.  This is extremely board dependent. | 
|  | 239 | */ | 
|  | 240 | static void elmc_do_attn586(int ioaddr, int ints) | 
|  | 241 | { | 
|  | 242 | /* the 3c523 requires a minimum of 500 ns.  The delays here might be | 
|  | 243 | a little too large, and hence they may cut the performance of the | 
|  | 244 | card slightly.  If someone who knows a little more about Linux | 
|  | 245 | timing would care to play with these, I'd appreciate it. */ | 
|  | 246 |  | 
|  | 247 | /* this bit masking stuff is crap.  I'd rather have separate | 
|  | 248 | registers with strobe triggers for each of these functions.  <sigh> | 
|  | 249 | Ya take what ya got. */ | 
|  | 250 |  | 
|  | 251 | outb(ELMC_CTRL_RST | 0x3 | ELMC_CTRL_CA | ints, ioaddr + ELMC_CTRL); | 
|  | 252 | DELAY_16();		/* > 500 ns */ | 
|  | 253 | outb(ELMC_CTRL_RST | 0x3 | ints, ioaddr + ELMC_CTRL); | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | /*************************************************************************/ | 
|  | 257 | /* | 
|  | 258 | Reset the 82586 on the 3c523.  Also very board dependent. | 
|  | 259 | */ | 
|  | 260 | static void elmc_do_reset586(int ioaddr, int ints) | 
|  | 261 | { | 
|  | 262 | /* toggle the RST bit low then high */ | 
|  | 263 | outb(0x3 | ELMC_CTRL_LBK, ioaddr + ELMC_CTRL); | 
|  | 264 | DELAY_16();		/* > 500 ns */ | 
|  | 265 | outb(ELMC_CTRL_RST | ELMC_CTRL_LBK | 0x3, ioaddr + ELMC_CTRL); | 
|  | 266 |  | 
|  | 267 | elmc_do_attn586(ioaddr, ints); | 
|  | 268 | } | 
|  | 269 |  | 
|  | 270 | /********************************************** | 
|  | 271 | * close device | 
|  | 272 | */ | 
|  | 273 |  | 
|  | 274 | static int elmc_close(struct net_device *dev) | 
|  | 275 | { | 
|  | 276 | netif_stop_queue(dev); | 
|  | 277 | elmc_id_reset586();	/* the hard way to stop the receiver */ | 
|  | 278 | free_irq(dev->irq, dev); | 
|  | 279 | return 0; | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 | /********************************************** | 
|  | 283 | * open device | 
|  | 284 | */ | 
|  | 285 |  | 
|  | 286 | static int elmc_open(struct net_device *dev) | 
|  | 287 | { | 
|  | 288 | int ret; | 
|  | 289 |  | 
|  | 290 | elmc_id_attn586();	/* disable interrupts */ | 
|  | 291 |  | 
| Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 292 | ret = request_irq(dev->irq, &elmc_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | dev->name, dev); | 
|  | 294 | if (ret) { | 
|  | 295 | printk(KERN_ERR "%s: couldn't get irq %d\n", dev->name, dev->irq); | 
|  | 296 | elmc_id_reset586(); | 
|  | 297 | return ret; | 
|  | 298 | } | 
|  | 299 | alloc586(dev); | 
|  | 300 | init586(dev); | 
|  | 301 | startrecv586(dev); | 
|  | 302 | netif_start_queue(dev); | 
|  | 303 | return 0;		/* most done by init */ | 
|  | 304 | } | 
|  | 305 |  | 
|  | 306 | /********************************************** | 
|  | 307 | * Check to see if there's an 82586 out there. | 
|  | 308 | */ | 
|  | 309 |  | 
|  | 310 | static int __init check586(struct net_device *dev, unsigned long where, unsigned size) | 
|  | 311 | { | 
|  | 312 | struct priv *p = (struct priv *) dev->priv; | 
|  | 313 | char *iscp_addrs[2]; | 
|  | 314 | int i = 0; | 
|  | 315 |  | 
|  | 316 | p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000; | 
|  | 317 | p->memtop = isa_bus_to_virt((unsigned long)where) + size; | 
|  | 318 | p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS); | 
|  | 319 | memset((char *) p->scp, 0, sizeof(struct scp_struct)); | 
|  | 320 | p->scp->sysbus = SYSBUSVAL;	/* 1 = 8Bit-Bus, 0 = 16 Bit */ | 
|  | 321 |  | 
|  | 322 | iscp_addrs[0] = isa_bus_to_virt((unsigned long)where); | 
|  | 323 | iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct); | 
|  | 324 |  | 
|  | 325 | for (i = 0; i < 2; i++) { | 
|  | 326 | p->iscp = (struct iscp_struct *) iscp_addrs[i]; | 
|  | 327 | memset((char *) p->iscp, 0, sizeof(struct iscp_struct)); | 
|  | 328 |  | 
|  | 329 | p->scp->iscp = make24(p->iscp); | 
|  | 330 | p->iscp->busy = 1; | 
|  | 331 |  | 
|  | 332 | elmc_id_reset586(); | 
|  | 333 |  | 
|  | 334 | /* reset586 does an implicit CA */ | 
|  | 335 |  | 
|  | 336 | /* apparently, you sometimes have to kick the 82586 twice... */ | 
|  | 337 | elmc_id_attn586(); | 
|  | 338 | DELAY(1); | 
|  | 339 |  | 
|  | 340 | if (p->iscp->busy) {	/* i82586 clears 'busy' after successful init */ | 
|  | 341 | return 0; | 
|  | 342 | } | 
|  | 343 | } | 
|  | 344 | return 1; | 
|  | 345 | } | 
|  | 346 |  | 
|  | 347 | /****************************************************************** | 
|  | 348 | * set iscp at the right place, called by elmc_probe and open586. | 
|  | 349 | */ | 
|  | 350 |  | 
|  | 351 | void alloc586(struct net_device *dev) | 
|  | 352 | { | 
|  | 353 | struct priv *p = (struct priv *) dev->priv; | 
|  | 354 |  | 
|  | 355 | elmc_id_reset586(); | 
|  | 356 | DELAY(2); | 
|  | 357 |  | 
|  | 358 | p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS); | 
|  | 359 | p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start); | 
|  | 360 | p->iscp = (struct iscp_struct *) ((char *) p->scp - sizeof(struct iscp_struct)); | 
|  | 361 |  | 
|  | 362 | memset((char *) p->iscp, 0, sizeof(struct iscp_struct)); | 
|  | 363 | memset((char *) p->scp, 0, sizeof(struct scp_struct)); | 
|  | 364 |  | 
|  | 365 | p->scp->iscp = make24(p->iscp); | 
|  | 366 | p->scp->sysbus = SYSBUSVAL; | 
|  | 367 | p->iscp->scb_offset = make16(p->scb); | 
|  | 368 |  | 
|  | 369 | p->iscp->busy = 1; | 
|  | 370 | elmc_id_reset586(); | 
|  | 371 | elmc_id_attn586(); | 
|  | 372 |  | 
|  | 373 | DELAY(2); | 
|  | 374 |  | 
|  | 375 | if (p->iscp->busy) { | 
|  | 376 | printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name); | 
|  | 377 | } | 
|  | 378 | memset((char *) p->scb, 0, sizeof(struct scb_struct)); | 
|  | 379 | } | 
|  | 380 |  | 
|  | 381 | /*****************************************************************/ | 
|  | 382 |  | 
|  | 383 | static int elmc_getinfo(char *buf, int slot, void *d) | 
|  | 384 | { | 
|  | 385 | int len = 0; | 
|  | 386 | struct net_device *dev = (struct net_device *) d; | 
|  | 387 | int i; | 
|  | 388 |  | 
|  | 389 | if (dev == NULL) | 
|  | 390 | return len; | 
|  | 391 |  | 
|  | 392 | len += sprintf(buf + len, "Revision: 0x%x\n", | 
|  | 393 | inb(dev->base_addr + ELMC_REVISION) & 0xf); | 
|  | 394 | len += sprintf(buf + len, "IRQ: %d\n", dev->irq); | 
|  | 395 | len += sprintf(buf + len, "IO Address: %#lx-%#lx\n", dev->base_addr, | 
|  | 396 | dev->base_addr + ELMC_IO_EXTENT); | 
|  | 397 | len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start, | 
|  | 398 | dev->mem_end - 1); | 
|  | 399 | len += sprintf(buf + len, "Transceiver: %s\n", dev->if_port ? | 
|  | 400 | "External" : "Internal"); | 
|  | 401 | len += sprintf(buf + len, "Device: %s\n", dev->name); | 
|  | 402 | len += sprintf(buf + len, "Hardware Address:"); | 
|  | 403 | for (i = 0; i < 6; i++) { | 
|  | 404 | len += sprintf(buf + len, " %02x", dev->dev_addr[i]); | 
|  | 405 | } | 
|  | 406 | buf[len++] = '\n'; | 
|  | 407 | buf[len] = 0; | 
|  | 408 |  | 
|  | 409 | return len; | 
|  | 410 | }				/* elmc_getinfo() */ | 
|  | 411 |  | 
|  | 412 | /*****************************************************************/ | 
|  | 413 |  | 
|  | 414 | static int __init do_elmc_probe(struct net_device *dev) | 
|  | 415 | { | 
|  | 416 | static int slot; | 
|  | 417 | int base_addr = dev->base_addr; | 
|  | 418 | int irq = dev->irq; | 
|  | 419 | u_char status = 0; | 
|  | 420 | u_char revision = 0; | 
|  | 421 | int i = 0; | 
|  | 422 | unsigned int size = 0; | 
|  | 423 | int retval; | 
|  | 424 | struct priv *pr = dev->priv; | 
|  | 425 |  | 
|  | 426 | SET_MODULE_OWNER(dev); | 
|  | 427 | if (MCA_bus == 0) { | 
|  | 428 | return -ENODEV; | 
|  | 429 | } | 
|  | 430 | /* search through the slots for the 3c523. */ | 
|  | 431 | slot = mca_find_adapter(ELMC_MCA_ID, 0); | 
|  | 432 | while (slot != -1) { | 
|  | 433 | status = mca_read_stored_pos(slot, 2); | 
|  | 434 |  | 
|  | 435 | dev->irq=irq_table[(status & ELMC_STATUS_IRQ_SELECT) >> 6]; | 
|  | 436 | dev->base_addr=csr_table[(status & ELMC_STATUS_CSR_SELECT) >> 1]; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 437 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | /* | 
|  | 439 | If we're trying to match a specified irq or IO address, | 
|  | 440 | we'll reject a match unless it's what we're looking for. | 
|  | 441 | Also reject it if the card is already in use. | 
|  | 442 | */ | 
|  | 443 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 444 | if ((irq && irq != dev->irq) || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | (base_addr && base_addr != dev->base_addr)) { | 
|  | 446 | slot = mca_find_adapter(ELMC_MCA_ID, slot + 1); | 
|  | 447 | continue; | 
|  | 448 | } | 
|  | 449 | if (!request_region(dev->base_addr, ELMC_IO_EXTENT, DRV_NAME)) { | 
|  | 450 | slot = mca_find_adapter(ELMC_MCA_ID, slot + 1); | 
|  | 451 | continue; | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | /* found what we're looking for... */ | 
|  | 455 | break; | 
|  | 456 | } | 
|  | 457 |  | 
|  | 458 | /* we didn't find any 3c523 in the slots we checked for */ | 
|  | 459 | if (slot == MCA_NOTFOUND) | 
|  | 460 | return ((base_addr || irq) ? -ENXIO : -ENODEV); | 
|  | 461 |  | 
|  | 462 | mca_set_adapter_name(slot, "3Com 3c523 Etherlink/MC"); | 
|  | 463 | mca_set_adapter_procfn(slot, (MCA_ProcFn) elmc_getinfo, dev); | 
|  | 464 |  | 
|  | 465 | /* if we get this far, adapter has been found - carry on */ | 
|  | 466 | printk(KERN_INFO "%s: 3c523 adapter found in slot %d\n", dev->name, slot + 1); | 
|  | 467 |  | 
|  | 468 | /* Now we extract configuration info from the card. | 
|  | 469 | The 3c523 provides information in two of the POS registers, but | 
|  | 470 | the second one is only needed if we want to tell the card what IRQ | 
|  | 471 | to use.  I suspect that whoever sets the thing up initially would | 
|  | 472 | prefer we don't screw with those things. | 
|  | 473 |  | 
|  | 474 | Note that we read the status info when we found the card... | 
|  | 475 |  | 
|  | 476 | See 3c523.h for more details. | 
|  | 477 | */ | 
|  | 478 |  | 
|  | 479 | /* revision is stored in the first 4 bits of the revision register */ | 
|  | 480 | revision = inb(dev->base_addr + ELMC_REVISION) & 0xf; | 
|  | 481 |  | 
|  | 482 | /* according to docs, we read the interrupt and write it back to | 
|  | 483 | the IRQ select register, since the POST might not configure the IRQ | 
|  | 484 | properly. */ | 
|  | 485 | switch (dev->irq) { | 
|  | 486 | case 3: | 
|  | 487 | mca_write_pos(slot, 3, 0x04); | 
|  | 488 | break; | 
|  | 489 | case 7: | 
|  | 490 | mca_write_pos(slot, 3, 0x02); | 
|  | 491 | break; | 
|  | 492 | case 9: | 
|  | 493 | mca_write_pos(slot, 3, 0x08); | 
|  | 494 | break; | 
|  | 495 | case 12: | 
|  | 496 | mca_write_pos(slot, 3, 0x01); | 
|  | 497 | break; | 
|  | 498 | } | 
|  | 499 |  | 
|  | 500 | memset(pr, 0, sizeof(struct priv)); | 
|  | 501 | pr->slot = slot; | 
|  | 502 |  | 
|  | 503 | printk(KERN_INFO "%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev->name, (int) revision, | 
|  | 504 | dev->base_addr); | 
|  | 505 |  | 
|  | 506 | /* Determine if we're using the on-board transceiver (i.e. coax) or | 
|  | 507 | an external one.  The information is pretty much useless, but I | 
|  | 508 | guess it's worth brownie points. */ | 
|  | 509 | dev->if_port = (status & ELMC_STATUS_DISABLE_THIN); | 
|  | 510 |  | 
|  | 511 | /* The 3c523 has a 24K chunk of memory.  The first 16K is the | 
|  | 512 | shared memory, while the last 8K is for the EtherStart BIOS ROM. | 
|  | 513 | Which we don't care much about here.  We'll just tell Linux that | 
|  | 514 | we're using 16K.  MCA won't permit address space conflicts caused | 
|  | 515 | by not mapping the other 8K. */ | 
|  | 516 | dev->mem_start = shm_table[(status & ELMC_STATUS_MEMORY_SELECT) >> 3]; | 
|  | 517 |  | 
|  | 518 | /* We're using MCA, so it's a given that the information about memory | 
|  | 519 | size is correct.  The Crynwr drivers do something like this. */ | 
|  | 520 |  | 
|  | 521 | elmc_id_reset586();	/* seems like a good idea before checking it... */ | 
|  | 522 |  | 
|  | 523 | size = 0x4000;		/* check for 16K mem */ | 
|  | 524 | if (!check586(dev, dev->mem_start, size)) { | 
|  | 525 | printk(KERN_ERR "%s: memprobe, Can't find memory at 0x%lx!\n", dev->name, | 
|  | 526 | dev->mem_start); | 
|  | 527 | retval = -ENODEV; | 
|  | 528 | goto err_out; | 
|  | 529 | } | 
|  | 530 | dev->mem_end = dev->mem_start + size;	/* set mem_end showed by 'ifconfig' */ | 
|  | 531 |  | 
|  | 532 | pr->memtop = isa_bus_to_virt(dev->mem_start) + size; | 
|  | 533 | pr->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000; | 
|  | 534 | alloc586(dev); | 
|  | 535 |  | 
|  | 536 | elmc_id_reset586();	/* make sure it doesn't generate spurious ints */ | 
|  | 537 |  | 
|  | 538 | /* set number of receive-buffs according to memsize */ | 
|  | 539 | pr->num_recv_buffs = NUM_RECV_BUFFS_16; | 
|  | 540 |  | 
|  | 541 | /* dump all the assorted information */ | 
|  | 542 | printk(KERN_INFO "%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->name, | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 543 | dev->irq, dev->if_port ? "ex" : "in", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | dev->mem_start, dev->mem_end - 1); | 
|  | 545 |  | 
|  | 546 | /* The hardware address for the 3c523 is stored in the first six | 
|  | 547 | bytes of the IO address. */ | 
|  | 548 | printk(KERN_INFO "%s: hardware address ", dev->name); | 
|  | 549 | for (i = 0; i < 6; i++) { | 
|  | 550 | dev->dev_addr[i] = inb(dev->base_addr + i); | 
|  | 551 | printk(" %02x", dev->dev_addr[i]); | 
|  | 552 | } | 
|  | 553 | printk("\n"); | 
|  | 554 |  | 
|  | 555 | dev->open = &elmc_open; | 
|  | 556 | dev->stop = &elmc_close; | 
|  | 557 | dev->get_stats = &elmc_get_stats; | 
|  | 558 | dev->hard_start_xmit = &elmc_send_packet; | 
|  | 559 | dev->tx_timeout = &elmc_timeout; | 
|  | 560 | dev->watchdog_timeo = HZ; | 
|  | 561 | #ifdef ELMC_MULTICAST | 
|  | 562 | dev->set_multicast_list = &set_multicast_list; | 
|  | 563 | #else | 
|  | 564 | dev->set_multicast_list = NULL; | 
|  | 565 | #endif | 
|  | 566 | dev->ethtool_ops = &netdev_ethtool_ops; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 567 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* note that we haven't actually requested the IRQ from the kernel. | 
|  | 569 | That gets done in elmc_open().  I'm not sure that's such a good idea, | 
|  | 570 | but it works, so I'll go with it. */ | 
|  | 571 |  | 
|  | 572 | #ifndef ELMC_MULTICAST | 
|  | 573 | dev->flags&=~IFF_MULTICAST;     /* Multicast doesn't work */ | 
|  | 574 | #endif | 
|  | 575 |  | 
|  | b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 576 | retval = register_netdev(dev); | 
|  | 577 | if (retval) | 
|  | 578 | goto err_out; | 
|  | 579 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | return 0; | 
|  | 581 | err_out: | 
|  | 582 | mca_set_adapter_procfn(slot, NULL, NULL); | 
|  | 583 | release_region(dev->base_addr, ELMC_IO_EXTENT); | 
|  | 584 | return retval; | 
|  | 585 | } | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 586 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | static void cleanup_card(struct net_device *dev) | 
|  | 588 | { | 
|  | 589 | mca_set_adapter_procfn(((struct priv *) (dev->priv))->slot, NULL, NULL); | 
|  | 590 | release_region(dev->base_addr, ELMC_IO_EXTENT); | 
|  | 591 | } | 
|  | 592 |  | 
|  | 593 | #ifndef MODULE | 
|  | 594 | struct net_device * __init elmc_probe(int unit) | 
|  | 595 | { | 
|  | 596 | struct net_device *dev = alloc_etherdev(sizeof(struct priv)); | 
|  | 597 | int err; | 
|  | 598 |  | 
|  | 599 | if (!dev) | 
|  | 600 | return ERR_PTR(-ENOMEM); | 
|  | 601 |  | 
|  | 602 | sprintf(dev->name, "eth%d", unit); | 
|  | 603 | netdev_boot_setup_check(dev); | 
|  | 604 |  | 
|  | 605 | err = do_elmc_probe(dev); | 
|  | 606 | if (err) | 
|  | 607 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | return dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | out: | 
|  | 610 | free_netdev(dev); | 
|  | 611 | return ERR_PTR(err); | 
|  | 612 | } | 
|  | 613 | #endif | 
|  | 614 |  | 
|  | 615 | /********************************************** | 
|  | 616 | * init the chip (elmc-interrupt should be disabled?!) | 
|  | 617 | * needs a correct 'allocated' memory | 
|  | 618 | */ | 
|  | 619 |  | 
|  | 620 | static int init586(struct net_device *dev) | 
|  | 621 | { | 
|  | 622 | void *ptr; | 
|  | 623 | unsigned long s; | 
|  | 624 | int i, result = 0; | 
|  | 625 | struct priv *p = (struct priv *) dev->priv; | 
|  | 626 | volatile struct configure_cmd_struct *cfg_cmd; | 
|  | 627 | volatile struct iasetup_cmd_struct *ias_cmd; | 
|  | 628 | volatile struct tdr_cmd_struct *tdr_cmd; | 
|  | 629 | volatile struct mcsetup_cmd_struct *mc_cmd; | 
|  | 630 | struct dev_mc_list *dmi = dev->mc_list; | 
|  | 631 | int num_addrs = dev->mc_count; | 
|  | 632 |  | 
|  | 633 | ptr = (void *) ((char *) p->scb + sizeof(struct scb_struct)); | 
|  | 634 |  | 
|  | 635 | cfg_cmd = (struct configure_cmd_struct *) ptr;	/* configure-command */ | 
|  | 636 | cfg_cmd->cmd_status = 0; | 
|  | 637 | cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST; | 
|  | 638 | cfg_cmd->cmd_link = 0xffff; | 
|  | 639 |  | 
|  | 640 | cfg_cmd->byte_cnt = 0x0a;	/* number of cfg bytes */ | 
|  | 641 | cfg_cmd->fifo = 0x08;	/* fifo-limit (8=tx:32/rx:64) */ | 
|  | 642 | cfg_cmd->sav_bf = 0x40;	/* hold or discard bad recv frames (bit 7) */ | 
|  | 643 | cfg_cmd->adr_len = 0x2e;	/* addr_len |!src_insert |pre-len |loopback */ | 
|  | 644 | cfg_cmd->priority = 0x00; | 
|  | 645 | cfg_cmd->ifs = 0x60; | 
|  | 646 | cfg_cmd->time_low = 0x00; | 
|  | 647 | cfg_cmd->time_high = 0xf2; | 
|  | 648 | cfg_cmd->promisc = 0; | 
|  | 649 | if (dev->flags & (IFF_ALLMULTI | IFF_PROMISC)) { | 
|  | 650 | cfg_cmd->promisc = 1; | 
|  | 651 | dev->flags |= IFF_PROMISC; | 
|  | 652 | } | 
|  | 653 | cfg_cmd->carr_coll = 0x00; | 
|  | 654 |  | 
|  | 655 | p->scb->cbl_offset = make16(cfg_cmd); | 
|  | 656 |  | 
|  | 657 | p->scb->cmd = CUC_START;	/* cmd.-unit start */ | 
|  | 658 | elmc_id_attn586(); | 
|  | 659 |  | 
|  | 660 | s = jiffies;		/* warning: only active with interrupts on !! */ | 
|  | 661 | while (!(cfg_cmd->cmd_status & STAT_COMPL)) { | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 662 | if (time_after(jiffies, s + 30*HZ/100)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | break; | 
|  | 664 | } | 
|  | 665 |  | 
|  | 666 | if ((cfg_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_COMPL | STAT_OK)) { | 
|  | 667 | printk(KERN_WARNING "%s (elmc): configure command failed: %x\n", dev->name, cfg_cmd->cmd_status); | 
|  | 668 | return 1; | 
|  | 669 | } | 
|  | 670 | /* | 
|  | 671 | * individual address setup | 
|  | 672 | */ | 
|  | 673 | ias_cmd = (struct iasetup_cmd_struct *) ptr; | 
|  | 674 |  | 
|  | 675 | ias_cmd->cmd_status = 0; | 
|  | 676 | ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST; | 
|  | 677 | ias_cmd->cmd_link = 0xffff; | 
|  | 678 |  | 
|  | 679 | memcpy((char *) &ias_cmd->iaddr, (char *) dev->dev_addr, ETH_ALEN); | 
|  | 680 |  | 
|  | 681 | p->scb->cbl_offset = make16(ias_cmd); | 
|  | 682 |  | 
|  | 683 | p->scb->cmd = CUC_START;	/* cmd.-unit start */ | 
|  | 684 | elmc_id_attn586(); | 
|  | 685 |  | 
|  | 686 | s = jiffies; | 
|  | 687 | while (!(ias_cmd->cmd_status & STAT_COMPL)) { | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 688 | if (time_after(jiffies, s + 30*HZ/100)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | break; | 
|  | 690 | } | 
|  | 691 |  | 
|  | 692 | if ((ias_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_OK | STAT_COMPL)) { | 
|  | 693 | printk(KERN_WARNING "%s (elmc): individual address setup command failed: %04x\n", dev->name, ias_cmd->cmd_status); | 
|  | 694 | return 1; | 
|  | 695 | } | 
|  | 696 | /* | 
|  | 697 | * TDR, wire check .. e.g. no resistor e.t.c | 
|  | 698 | */ | 
|  | 699 | tdr_cmd = (struct tdr_cmd_struct *) ptr; | 
|  | 700 |  | 
|  | 701 | tdr_cmd->cmd_status = 0; | 
|  | 702 | tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST; | 
|  | 703 | tdr_cmd->cmd_link = 0xffff; | 
|  | 704 | tdr_cmd->status = 0; | 
|  | 705 |  | 
|  | 706 | p->scb->cbl_offset = make16(tdr_cmd); | 
|  | 707 |  | 
|  | 708 | p->scb->cmd = CUC_START;	/* cmd.-unit start */ | 
|  | 709 | elmc_attn586(); | 
|  | 710 |  | 
|  | 711 | s = jiffies; | 
|  | 712 | while (!(tdr_cmd->cmd_status & STAT_COMPL)) { | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 713 | if (time_after(jiffies, s + 30*HZ/100)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | printk(KERN_WARNING "%s: %d Problems while running the TDR.\n", dev->name, __LINE__); | 
|  | 715 | result = 1; | 
|  | 716 | break; | 
|  | 717 | } | 
|  | 718 | } | 
|  | 719 |  | 
|  | 720 | if (!result) { | 
|  | 721 | DELAY(2);	/* wait for result */ | 
|  | 722 | result = tdr_cmd->status; | 
|  | 723 |  | 
|  | 724 | p->scb->cmd = p->scb->status & STAT_MASK; | 
|  | 725 | elmc_id_attn586();	/* ack the interrupts */ | 
|  | 726 |  | 
|  | 727 | if (result & TDR_LNK_OK) { | 
|  | 728 | /* empty */ | 
|  | 729 | } else if (result & TDR_XCVR_PRB) { | 
|  | 730 | printk(KERN_WARNING "%s: TDR: Transceiver problem!\n", dev->name); | 
|  | 731 | } else if (result & TDR_ET_OPN) { | 
|  | 732 | printk(KERN_WARNING "%s: TDR: No correct termination %d clocks away.\n", dev->name, result & TDR_TIMEMASK); | 
|  | 733 | } else if (result & TDR_ET_SRT) { | 
|  | 734 | if (result & TDR_TIMEMASK)	/* time == 0 -> strange :-) */ | 
|  | 735 | printk(KERN_WARNING "%s: TDR: Detected a short circuit %d clocks away.\n", dev->name, result & TDR_TIMEMASK); | 
|  | 736 | } else { | 
|  | 737 | printk(KERN_WARNING "%s: TDR: Unknown status %04x\n", dev->name, result); | 
|  | 738 | } | 
|  | 739 | } | 
|  | 740 | /* | 
|  | 741 | * ack interrupts | 
|  | 742 | */ | 
|  | 743 | p->scb->cmd = p->scb->status & STAT_MASK; | 
|  | 744 | elmc_id_attn586(); | 
|  | 745 |  | 
|  | 746 | /* | 
|  | 747 | * alloc nop/xmit-cmds | 
|  | 748 | */ | 
|  | 749 | #if (NUM_XMIT_BUFFS == 1) | 
|  | 750 | for (i = 0; i < 2; i++) { | 
|  | 751 | p->nop_cmds[i] = (struct nop_cmd_struct *) ptr; | 
|  | 752 | p->nop_cmds[i]->cmd_cmd = CMD_NOP; | 
|  | 753 | p->nop_cmds[i]->cmd_status = 0; | 
|  | 754 | p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); | 
|  | 755 | ptr = (char *) ptr + sizeof(struct nop_cmd_struct); | 
|  | 756 | } | 
|  | 757 | p->xmit_cmds[0] = (struct transmit_cmd_struct *) ptr;	/* transmit cmd/buff 0 */ | 
|  | 758 | ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); | 
|  | 759 | #else | 
|  | 760 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { | 
|  | 761 | p->nop_cmds[i] = (struct nop_cmd_struct *) ptr; | 
|  | 762 | p->nop_cmds[i]->cmd_cmd = CMD_NOP; | 
|  | 763 | p->nop_cmds[i]->cmd_status = 0; | 
|  | 764 | p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); | 
|  | 765 | ptr = (char *) ptr + sizeof(struct nop_cmd_struct); | 
|  | 766 | p->xmit_cmds[i] = (struct transmit_cmd_struct *) ptr;	/*transmit cmd/buff 0 */ | 
|  | 767 | ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); | 
|  | 768 | } | 
|  | 769 | #endif | 
|  | 770 |  | 
|  | 771 | ptr = alloc_rfa(dev, (void *) ptr);	/* init receive-frame-area */ | 
|  | 772 |  | 
|  | 773 | /* | 
|  | 774 | * Multicast setup | 
|  | 775 | */ | 
|  | 776 |  | 
|  | 777 | if (dev->mc_count) { | 
|  | 778 | /* I don't understand this: do we really need memory after the init? */ | 
|  | 779 | int len = ((char *) p->iscp - (char *) ptr - 8) / 6; | 
|  | 780 | if (len <= 0) { | 
|  | 781 | printk(KERN_ERR "%s: Ooooops, no memory for MC-Setup!\n", dev->name); | 
|  | 782 | } else { | 
|  | 783 | if (len < num_addrs) { | 
|  | 784 | num_addrs = len; | 
|  | 785 | printk(KERN_WARNING "%s: Sorry, can only apply %d MC-Address(es).\n", | 
|  | 786 | dev->name, num_addrs); | 
|  | 787 | } | 
|  | 788 | mc_cmd = (struct mcsetup_cmd_struct *) ptr; | 
|  | 789 | mc_cmd->cmd_status = 0; | 
|  | 790 | mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST; | 
|  | 791 | mc_cmd->cmd_link = 0xffff; | 
|  | 792 | mc_cmd->mc_cnt = num_addrs * 6; | 
|  | 793 | for (i = 0; i < num_addrs; i++) { | 
|  | 794 | memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr, 6); | 
|  | 795 | dmi = dmi->next; | 
|  | 796 | } | 
|  | 797 | p->scb->cbl_offset = make16(mc_cmd); | 
|  | 798 | p->scb->cmd = CUC_START; | 
|  | 799 | elmc_id_attn586(); | 
|  | 800 | s = jiffies; | 
|  | 801 | while (!(mc_cmd->cmd_status & STAT_COMPL)) { | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 802 | if (time_after(jiffies, s + 30*HZ/100)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | break; | 
|  | 804 | } | 
|  | 805 | if (!(mc_cmd->cmd_status & STAT_COMPL)) { | 
|  | 806 | printk(KERN_WARNING "%s: Can't apply multicast-address-list.\n", dev->name); | 
|  | 807 | } | 
|  | 808 | } | 
|  | 809 | } | 
|  | 810 | /* | 
|  | 811 | * alloc xmit-buffs / init xmit_cmds | 
|  | 812 | */ | 
|  | 813 | for (i = 0; i < NUM_XMIT_BUFFS; i++) { | 
|  | 814 | p->xmit_cbuffs[i] = (char *) ptr;	/* char-buffs */ | 
|  | 815 | ptr = (char *) ptr + XMIT_BUFF_SIZE; | 
|  | 816 | p->xmit_buffs[i] = (struct tbd_struct *) ptr;	/* TBD */ | 
|  | 817 | ptr = (char *) ptr + sizeof(struct tbd_struct); | 
|  | 818 | if ((void *) ptr > (void *) p->iscp) { | 
|  | 819 | printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", dev->name); | 
|  | 820 | return 1; | 
|  | 821 | } | 
|  | 822 | memset((char *) (p->xmit_cmds[i]), 0, sizeof(struct transmit_cmd_struct)); | 
|  | 823 | memset((char *) (p->xmit_buffs[i]), 0, sizeof(struct tbd_struct)); | 
|  | 824 | p->xmit_cmds[i]->cmd_status = STAT_COMPL; | 
|  | 825 | p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT; | 
|  | 826 | p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i])); | 
|  | 827 | p->xmit_buffs[i]->next = 0xffff; | 
|  | 828 | p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i])); | 
|  | 829 | } | 
|  | 830 |  | 
|  | 831 | p->xmit_count = 0; | 
|  | 832 | p->xmit_last = 0; | 
|  | 833 | #ifndef NO_NOPCOMMANDS | 
|  | 834 | p->nop_point = 0; | 
|  | 835 | #endif | 
|  | 836 |  | 
|  | 837 | /* | 
|  | 838 | * 'start transmitter' (nop-loop) | 
|  | 839 | */ | 
|  | 840 | #ifndef NO_NOPCOMMANDS | 
|  | 841 | p->scb->cbl_offset = make16(p->nop_cmds[0]); | 
|  | 842 | p->scb->cmd = CUC_START; | 
|  | 843 | elmc_id_attn586(); | 
|  | 844 | WAIT_4_SCB_CMD(); | 
|  | 845 | #else | 
|  | 846 | p->xmit_cmds[0]->cmd_link = 0xffff; | 
|  | 847 | p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_LAST | CMD_INT; | 
|  | 848 | #endif | 
|  | 849 |  | 
|  | 850 | return 0; | 
|  | 851 | } | 
|  | 852 |  | 
|  | 853 | /****************************************************** | 
|  | 854 | * This is a helper routine for elmc_rnr_int() and init586(). | 
|  | 855 | * It sets up the Receive Frame Area (RFA). | 
|  | 856 | */ | 
|  | 857 |  | 
|  | 858 | static void *alloc_rfa(struct net_device *dev, void *ptr) | 
|  | 859 | { | 
|  | 860 | volatile struct rfd_struct *rfd = (struct rfd_struct *) ptr; | 
|  | 861 | volatile struct rbd_struct *rbd; | 
|  | 862 | int i; | 
|  | 863 | struct priv *p = (struct priv *) dev->priv; | 
|  | 864 |  | 
|  | 865 | memset((char *) rfd, 0, sizeof(struct rfd_struct) * p->num_recv_buffs); | 
|  | 866 | p->rfd_first = rfd; | 
|  | 867 |  | 
|  | 868 | for (i = 0; i < p->num_recv_buffs; i++) { | 
|  | 869 | rfd[i].next = make16(rfd + (i + 1) % p->num_recv_buffs); | 
|  | 870 | } | 
|  | 871 | rfd[p->num_recv_buffs - 1].last = RFD_SUSP;	/* RU suspend */ | 
|  | 872 |  | 
|  | 873 | ptr = (void *) (rfd + p->num_recv_buffs); | 
|  | 874 |  | 
|  | 875 | rbd = (struct rbd_struct *) ptr; | 
|  | 876 | ptr = (void *) (rbd + p->num_recv_buffs); | 
|  | 877 |  | 
|  | 878 | /* clr descriptors */ | 
|  | 879 | memset((char *) rbd, 0, sizeof(struct rbd_struct) * p->num_recv_buffs); | 
|  | 880 |  | 
|  | 881 | for (i = 0; i < p->num_recv_buffs; i++) { | 
|  | 882 | rbd[i].next = make16((rbd + (i + 1) % p->num_recv_buffs)); | 
|  | 883 | rbd[i].size = RECV_BUFF_SIZE; | 
|  | 884 | rbd[i].buffer = make24(ptr); | 
|  | 885 | ptr = (char *) ptr + RECV_BUFF_SIZE; | 
|  | 886 | } | 
|  | 887 |  | 
|  | 888 | p->rfd_top = p->rfd_first; | 
|  | 889 | p->rfd_last = p->rfd_first + p->num_recv_buffs - 1; | 
|  | 890 |  | 
|  | 891 | p->scb->rfa_offset = make16(p->rfd_first); | 
|  | 892 | p->rfd_first->rbd_offset = make16(rbd); | 
|  | 893 |  | 
|  | 894 | return ptr; | 
|  | 895 | } | 
|  | 896 |  | 
|  | 897 |  | 
|  | 898 | /************************************************** | 
|  | 899 | * Interrupt Handler ... | 
|  | 900 | */ | 
|  | 901 |  | 
|  | 902 | static irqreturn_t | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 903 | elmc_interrupt(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { | 
| Jeff Garzik | c31f28e | 2006-10-06 14:56:04 -0400 | [diff] [blame] | 905 | struct net_device *dev = dev_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | unsigned short stat; | 
|  | 907 | struct priv *p; | 
|  | 908 |  | 
| Jeff Garzik | c31f28e | 2006-10-06 14:56:04 -0400 | [diff] [blame] | 909 | if (!netif_running(dev)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | /* The 3c523 has this habit of generating interrupts during the | 
|  | 911 | reset.  I'm not sure if the ni52 has this same problem, but it's | 
|  | 912 | really annoying if we haven't finished initializing it.  I was | 
|  | 913 | hoping all the elmc_id_* commands would disable this, but I | 
|  | 914 | might have missed a few. */ | 
|  | 915 |  | 
|  | 916 | elmc_id_attn586();	/* ack inter. and disable any more */ | 
|  | 917 | return IRQ_HANDLED; | 
|  | 918 | } else if (!(ELMC_CTRL_INT & inb(dev->base_addr + ELMC_CTRL))) { | 
|  | 919 | /* wasn't this device */ | 
|  | 920 | return IRQ_NONE; | 
|  | 921 | } | 
|  | 922 | /* reading ELMC_CTRL also clears the INT bit. */ | 
|  | 923 |  | 
|  | 924 | p = (struct priv *) dev->priv; | 
|  | 925 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 926 | while ((stat = p->scb->status & STAT_MASK)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | { | 
|  | 928 | p->scb->cmd = stat; | 
|  | 929 | elmc_attn586();	/* ack inter. */ | 
|  | 930 |  | 
|  | 931 | if (stat & STAT_CX) { | 
|  | 932 | /* command with I-bit set complete */ | 
|  | 933 | elmc_xmt_int(dev); | 
|  | 934 | } | 
|  | 935 | if (stat & STAT_FR) { | 
|  | 936 | /* received a frame */ | 
|  | 937 | elmc_rcv_int(dev); | 
|  | 938 | } | 
|  | 939 | #ifndef NO_NOPCOMMANDS | 
|  | 940 | if (stat & STAT_CNA) { | 
|  | 941 | /* CU went 'not ready' */ | 
|  | 942 | if (netif_running(dev)) { | 
|  | 943 | printk(KERN_WARNING "%s: oops! CU has left active state. stat: %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status); | 
|  | 944 | } | 
|  | 945 | } | 
|  | 946 | #endif | 
|  | 947 |  | 
|  | 948 | if (stat & STAT_RNR) { | 
|  | 949 | /* RU went 'not ready' */ | 
|  | 950 |  | 
|  | 951 | if (p->scb->status & RU_SUSPEND) { | 
|  | 952 | /* special case: RU_SUSPEND */ | 
|  | 953 |  | 
|  | 954 | WAIT_4_SCB_CMD(); | 
|  | 955 | p->scb->cmd = RUC_RESUME; | 
|  | 956 | elmc_attn586(); | 
|  | 957 | } else { | 
|  | 958 | printk(KERN_WARNING "%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status); | 
|  | 959 | elmc_rnr_int(dev); | 
|  | 960 | } | 
|  | 961 | } | 
|  | 962 | WAIT_4_SCB_CMD();	/* wait for ack. (elmc_xmt_int can be faster than ack!!) */ | 
|  | 963 | if (p->scb->cmd) {	/* timed out? */ | 
|  | 964 | break; | 
|  | 965 | } | 
|  | 966 | } | 
|  | 967 | return IRQ_HANDLED; | 
|  | 968 | } | 
|  | 969 |  | 
|  | 970 | /******************************************************* | 
|  | 971 | * receive-interrupt | 
|  | 972 | */ | 
|  | 973 |  | 
|  | 974 | static void elmc_rcv_int(struct net_device *dev) | 
|  | 975 | { | 
|  | 976 | int status; | 
|  | 977 | unsigned short totlen; | 
|  | 978 | struct sk_buff *skb; | 
|  | 979 | struct rbd_struct *rbd; | 
|  | 980 | struct priv *p = (struct priv *) dev->priv; | 
|  | 981 |  | 
|  | 982 | for (; (status = p->rfd_top->status) & STAT_COMPL;) { | 
|  | 983 | rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); | 
|  | 984 |  | 
|  | 985 | if (status & STAT_OK) {		/* frame received without error? */ | 
|  | 986 | if ((totlen = rbd->status) & RBD_LAST) {	/* the first and the last buffer? */ | 
|  | 987 | totlen &= RBD_MASK;	/* length of this frame */ | 
|  | 988 | rbd->status = 0; | 
|  | 989 | skb = (struct sk_buff *) dev_alloc_skb(totlen + 2); | 
|  | 990 | if (skb != NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | skb_reserve(skb, 2);	/* 16 byte alignment */ | 
|  | 992 | skb_put(skb,totlen); | 
| David S. Miller | 8c7b7fa | 2007-07-10 22:08:12 -0700 | [diff] [blame] | 993 | 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] | 994 | skb->protocol = eth_type_trans(skb, dev); | 
|  | 995 | netif_rx(skb); | 
|  | 996 | dev->last_rx = jiffies; | 
|  | 997 | p->stats.rx_packets++; | 
|  | 998 | p->stats.rx_bytes += totlen; | 
|  | 999 | } else { | 
|  | 1000 | p->stats.rx_dropped++; | 
|  | 1001 | } | 
|  | 1002 | } else { | 
|  | 1003 | printk(KERN_WARNING "%s: received oversized frame.\n", dev->name); | 
|  | 1004 | p->stats.rx_dropped++; | 
|  | 1005 | } | 
|  | 1006 | } else {	/* frame !(ok), only with 'save-bad-frames' */ | 
|  | 1007 | printk(KERN_WARNING "%s: oops! rfd-error-status: %04x\n", dev->name, status); | 
|  | 1008 | p->stats.rx_errors++; | 
|  | 1009 | } | 
|  | 1010 | p->rfd_top->status = 0; | 
|  | 1011 | p->rfd_top->last = RFD_SUSP; | 
|  | 1012 | p->rfd_last->last = 0;	/* delete RU_SUSP  */ | 
|  | 1013 | p->rfd_last = p->rfd_top; | 
|  | 1014 | p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next);	/* step to next RFD */ | 
|  | 1015 | } | 
|  | 1016 | } | 
|  | 1017 |  | 
|  | 1018 | /********************************************************** | 
|  | 1019 | * handle 'Receiver went not ready'. | 
|  | 1020 | */ | 
|  | 1021 |  | 
|  | 1022 | static void elmc_rnr_int(struct net_device *dev) | 
|  | 1023 | { | 
|  | 1024 | struct priv *p = (struct priv *) dev->priv; | 
|  | 1025 |  | 
|  | 1026 | p->stats.rx_errors++; | 
|  | 1027 |  | 
|  | 1028 | WAIT_4_SCB_CMD();	/* wait for the last cmd */ | 
|  | 1029 | p->scb->cmd = RUC_ABORT;	/* usually the RU is in the 'no resource'-state .. abort it now. */ | 
|  | 1030 | elmc_attn586(); | 
|  | 1031 | WAIT_4_SCB_CMD();	/* wait for accept cmd. */ | 
|  | 1032 |  | 
|  | 1033 | alloc_rfa(dev, (char *) p->rfd_first); | 
|  | 1034 | startrecv586(dev);	/* restart RU */ | 
|  | 1035 |  | 
|  | 1036 | printk(KERN_WARNING "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->status); | 
|  | 1037 |  | 
|  | 1038 | } | 
|  | 1039 |  | 
|  | 1040 | /********************************************************** | 
|  | 1041 | * handle xmit - interrupt | 
|  | 1042 | */ | 
|  | 1043 |  | 
|  | 1044 | static void elmc_xmt_int(struct net_device *dev) | 
|  | 1045 | { | 
|  | 1046 | int status; | 
|  | 1047 | struct priv *p = (struct priv *) dev->priv; | 
|  | 1048 |  | 
|  | 1049 | status = p->xmit_cmds[p->xmit_last]->cmd_status; | 
|  | 1050 | if (!(status & STAT_COMPL)) { | 
|  | 1051 | printk(KERN_WARNING "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name); | 
|  | 1052 | } | 
|  | 1053 | if (status & STAT_OK) { | 
|  | 1054 | p->stats.tx_packets++; | 
|  | 1055 | p->stats.collisions += (status & TCMD_MAXCOLLMASK); | 
|  | 1056 | } else { | 
|  | 1057 | p->stats.tx_errors++; | 
|  | 1058 | if (status & TCMD_LATECOLL) { | 
|  | 1059 | printk(KERN_WARNING "%s: late collision detected.\n", dev->name); | 
|  | 1060 | p->stats.collisions++; | 
|  | 1061 | } else if (status & TCMD_NOCARRIER) { | 
|  | 1062 | p->stats.tx_carrier_errors++; | 
|  | 1063 | printk(KERN_WARNING "%s: no carrier detected.\n", dev->name); | 
|  | 1064 | } else if (status & TCMD_LOSTCTS) { | 
|  | 1065 | printk(KERN_WARNING "%s: loss of CTS detected.\n", dev->name); | 
|  | 1066 | } else if (status & TCMD_UNDERRUN) { | 
|  | 1067 | p->stats.tx_fifo_errors++; | 
|  | 1068 | printk(KERN_WARNING "%s: DMA underrun detected.\n", dev->name); | 
|  | 1069 | } else if (status & TCMD_MAXCOLL) { | 
|  | 1070 | printk(KERN_WARNING "%s: Max. collisions exceeded.\n", dev->name); | 
|  | 1071 | p->stats.collisions += 16; | 
|  | 1072 | } | 
|  | 1073 | } | 
|  | 1074 |  | 
|  | 1075 | #if (NUM_XMIT_BUFFS != 1) | 
|  | 1076 | if ((++p->xmit_last) == NUM_XMIT_BUFFS) { | 
|  | 1077 | p->xmit_last = 0; | 
|  | 1078 | } | 
|  | 1079 | #endif | 
|  | 1080 |  | 
|  | 1081 | netif_wake_queue(dev); | 
|  | 1082 | } | 
|  | 1083 |  | 
|  | 1084 | /*********************************************************** | 
|  | 1085 | * (re)start the receiver | 
|  | 1086 | */ | 
|  | 1087 |  | 
|  | 1088 | static void startrecv586(struct net_device *dev) | 
|  | 1089 | { | 
|  | 1090 | struct priv *p = (struct priv *) dev->priv; | 
|  | 1091 |  | 
|  | 1092 | p->scb->rfa_offset = make16(p->rfd_first); | 
|  | 1093 | p->scb->cmd = RUC_START; | 
|  | 1094 | elmc_attn586();		/* start cmd. */ | 
|  | 1095 | WAIT_4_SCB_CMD();	/* wait for accept cmd. (no timeout!!) */ | 
|  | 1096 | } | 
|  | 1097 |  | 
|  | 1098 | /****************************************************** | 
|  | 1099 | * timeout | 
|  | 1100 | */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1101 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | static void elmc_timeout(struct net_device *dev) | 
|  | 1103 | { | 
|  | 1104 | struct priv *p = (struct priv *) dev->priv; | 
|  | 1105 | /* COMMAND-UNIT active? */ | 
|  | 1106 | if (p->scb->status & CU_ACTIVE) { | 
|  | 1107 | #ifdef DEBUG | 
|  | 1108 | printk("%s: strange ... timeout with CU active?!?\n", dev->name); | 
|  | 1109 | printk("%s: X0: %04x N0: %04x N1: %04x %d\n", dev->name, (int) p->xmit_cmds[0]->cmd_status, (int) p->nop_cmds[0]->cmd_status, (int) p->nop_cmds[1]->cmd_status, (int) p->nop_point); | 
|  | 1110 | #endif | 
|  | 1111 | p->scb->cmd = CUC_ABORT; | 
|  | 1112 | elmc_attn586(); | 
|  | 1113 | WAIT_4_SCB_CMD(); | 
|  | 1114 | p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]); | 
|  | 1115 | p->scb->cmd = CUC_START; | 
|  | 1116 | elmc_attn586(); | 
|  | 1117 | WAIT_4_SCB_CMD(); | 
|  | 1118 | netif_wake_queue(dev); | 
|  | 1119 | } else { | 
|  | 1120 | #ifdef DEBUG | 
|  | 1121 | printk("%s: xmitter timed out, try to restart! stat: %04x\n", dev->name, p->scb->status); | 
|  | 1122 | printk("%s: command-stats: %04x %04x\n", dev->name, p->xmit_cmds[0]->cmd_status, p->xmit_cmds[1]->cmd_status); | 
|  | 1123 | #endif | 
|  | 1124 | elmc_close(dev); | 
|  | 1125 | elmc_open(dev); | 
|  | 1126 | } | 
|  | 1127 | } | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1128 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | /****************************************************** | 
|  | 1130 | * send frame | 
|  | 1131 | */ | 
|  | 1132 |  | 
|  | 1133 | static int elmc_send_packet(struct sk_buff *skb, struct net_device *dev) | 
|  | 1134 | { | 
|  | 1135 | int len; | 
|  | 1136 | int i; | 
|  | 1137 | #ifndef NO_NOPCOMMANDS | 
|  | 1138 | int next_nop; | 
|  | 1139 | #endif | 
|  | 1140 | struct priv *p = (struct priv *) dev->priv; | 
|  | 1141 |  | 
|  | 1142 | netif_stop_queue(dev); | 
|  | 1143 |  | 
|  | 1144 | len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1145 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | if (len != skb->len) | 
|  | 1147 | memset((char *) p->xmit_cbuffs[p->xmit_count], 0, ETH_ZLEN); | 
| David S. Miller | 3dbad80 | 2007-03-29 19:16:03 -0700 | [diff] [blame] | 1148 | 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] | 1149 |  | 
|  | 1150 | #if (NUM_XMIT_BUFFS == 1) | 
|  | 1151 | #ifdef NO_NOPCOMMANDS | 
|  | 1152 | p->xmit_buffs[0]->size = TBD_LAST | len; | 
|  | 1153 | for (i = 0; i < 16; i++) { | 
|  | 1154 | p->scb->cbl_offset = make16(p->xmit_cmds[0]); | 
|  | 1155 | p->scb->cmd = CUC_START; | 
|  | 1156 | p->xmit_cmds[0]->cmd_status = 0; | 
|  | 1157 | elmc_attn586(); | 
|  | 1158 | dev->trans_start = jiffies; | 
|  | 1159 | if (!i) { | 
|  | 1160 | dev_kfree_skb(skb); | 
|  | 1161 | } | 
|  | 1162 | WAIT_4_SCB_CMD(); | 
|  | 1163 | if ((p->scb->status & CU_ACTIVE)) {	/* test it, because CU sometimes doesn't start immediately */ | 
|  | 1164 | break; | 
|  | 1165 | } | 
|  | 1166 | if (p->xmit_cmds[0]->cmd_status) { | 
|  | 1167 | break; | 
|  | 1168 | } | 
|  | 1169 | if (i == 15) { | 
|  | 1170 | printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name); | 
|  | 1171 | } | 
|  | 1172 | } | 
|  | 1173 | #else | 
|  | 1174 | next_nop = (p->nop_point + 1) & 0x1; | 
|  | 1175 | p->xmit_buffs[0]->size = TBD_LAST | len; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1176 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link | 
|  | 1178 | = make16((p->nop_cmds[next_nop])); | 
|  | 1179 | p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0; | 
|  | 1180 |  | 
|  | 1181 | p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0])); | 
|  | 1182 | dev->trans_start = jiffies; | 
|  | 1183 | p->nop_point = next_nop; | 
|  | 1184 | dev_kfree_skb(skb); | 
|  | 1185 | #endif | 
|  | 1186 | #else | 
|  | 1187 | p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len; | 
|  | 1188 | if ((next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS) { | 
|  | 1189 | next_nop = 0; | 
|  | 1190 | } | 
|  | 1191 | p->xmit_cmds[p->xmit_count]->cmd_status = 0; | 
|  | 1192 | p->xmit_cmds[p->xmit_count]->cmd_link = p->nop_cmds[next_nop]->cmd_link | 
|  | 1193 | = make16((p->nop_cmds[next_nop])); | 
|  | 1194 | p->nop_cmds[next_nop]->cmd_status = 0; | 
|  | 1195 | p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count])); | 
|  | 1196 | dev->trans_start = jiffies; | 
|  | 1197 | p->xmit_count = next_nop; | 
|  | 1198 | if (p->xmit_count != p->xmit_last) | 
|  | 1199 | netif_wake_queue(dev); | 
|  | 1200 | dev_kfree_skb(skb); | 
|  | 1201 | #endif | 
|  | 1202 | return 0; | 
|  | 1203 | } | 
|  | 1204 |  | 
|  | 1205 | /******************************************* | 
|  | 1206 | * Someone wanna have the statistics | 
|  | 1207 | */ | 
|  | 1208 |  | 
|  | 1209 | static struct net_device_stats *elmc_get_stats(struct net_device *dev) | 
|  | 1210 | { | 
|  | 1211 | struct priv *p = (struct priv *) dev->priv; | 
|  | 1212 | unsigned short crc, aln, rsc, ovrn; | 
|  | 1213 |  | 
|  | 1214 | crc = p->scb->crc_errs;	/* get error-statistic from the ni82586 */ | 
|  | 1215 | p->scb->crc_errs -= crc; | 
|  | 1216 | aln = p->scb->aln_errs; | 
|  | 1217 | p->scb->aln_errs -= aln; | 
|  | 1218 | rsc = p->scb->rsc_errs; | 
|  | 1219 | p->scb->rsc_errs -= rsc; | 
|  | 1220 | ovrn = p->scb->ovrn_errs; | 
|  | 1221 | p->scb->ovrn_errs -= ovrn; | 
|  | 1222 |  | 
|  | 1223 | p->stats.rx_crc_errors += crc; | 
|  | 1224 | p->stats.rx_fifo_errors += ovrn; | 
|  | 1225 | p->stats.rx_frame_errors += aln; | 
|  | 1226 | p->stats.rx_dropped += rsc; | 
|  | 1227 |  | 
|  | 1228 | return &p->stats; | 
|  | 1229 | } | 
|  | 1230 |  | 
|  | 1231 | /******************************************************** | 
|  | 1232 | * Set MC list .. | 
|  | 1233 | */ | 
|  | 1234 |  | 
|  | 1235 | #ifdef ELMC_MULTICAST | 
|  | 1236 | static void set_multicast_list(struct net_device *dev) | 
|  | 1237 | { | 
|  | 1238 | if (!dev->start) { | 
|  | 1239 | /* without a running interface, promiscuous doesn't work */ | 
|  | 1240 | return; | 
|  | 1241 | } | 
|  | 1242 | dev->start = 0; | 
|  | 1243 | alloc586(dev); | 
|  | 1244 | init586(dev); | 
|  | 1245 | startrecv586(dev); | 
|  | 1246 | dev->start = 1; | 
|  | 1247 | } | 
|  | 1248 | #endif | 
|  | 1249 |  | 
|  | 1250 | static void netdev_get_drvinfo(struct net_device *dev, | 
|  | 1251 | struct ethtool_drvinfo *info) | 
|  | 1252 | { | 
|  | 1253 | strcpy(info->driver, DRV_NAME); | 
|  | 1254 | strcpy(info->version, DRV_VERSION); | 
|  | 1255 | sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr); | 
|  | 1256 | } | 
|  | 1257 |  | 
| Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1258 | static const struct ethtool_ops netdev_ethtool_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | .get_drvinfo		= netdev_get_drvinfo, | 
|  | 1260 | }; | 
|  | 1261 |  | 
|  | 1262 | #ifdef MODULE | 
|  | 1263 |  | 
|  | 1264 | /* Increase if needed ;) */ | 
|  | 1265 | #define MAX_3C523_CARDS 4 | 
|  | 1266 |  | 
|  | 1267 | static struct net_device *dev_elmc[MAX_3C523_CARDS]; | 
|  | 1268 | static int irq[MAX_3C523_CARDS]; | 
|  | 1269 | static int io[MAX_3C523_CARDS]; | 
|  | 1270 | module_param_array(irq, int, NULL, 0); | 
|  | 1271 | module_param_array(io, int, NULL, 0); | 
|  | 1272 | MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)"); | 
|  | 1273 | MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)"); | 
| Randy Dunlap | 7b24017 | 2005-06-13 12:31:53 -0700 | [diff] [blame] | 1274 | MODULE_LICENSE("GPL"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 |  | 
| Randy Dunlap | 96e672c | 2006-06-10 13:33:48 -0700 | [diff] [blame] | 1276 | int __init init_module(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | { | 
|  | 1278 | int this_dev,found = 0; | 
|  | 1279 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1280 | /* 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] | 1281 | for(this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) { | 
|  | 1282 | struct net_device *dev = alloc_etherdev(sizeof(struct priv)); | 
|  | 1283 | if (!dev) | 
|  | 1284 | break; | 
|  | 1285 | dev->irq=irq[this_dev]; | 
|  | 1286 | dev->base_addr=io[this_dev]; | 
|  | 1287 | if (do_elmc_probe(dev) == 0) { | 
|  | b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 1288 | dev_elmc[this_dev] = dev; | 
|  | 1289 | found++; | 
|  | 1290 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | } | 
|  | 1292 | free_netdev(dev); | 
|  | 1293 | if (io[this_dev]==0) | 
|  | 1294 | break; | 
|  | 1295 | printk(KERN_WARNING "3c523.c: No 3c523 card found at io=%#x\n",io[this_dev]); | 
|  | 1296 | } | 
|  | 1297 |  | 
|  | 1298 | if(found==0) { | 
|  | 1299 | if(io[0]==0) printk(KERN_NOTICE "3c523.c: No 3c523 cards found\n"); | 
|  | 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 */ |