| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*	ni5010.c: A network driver for the MiCom-Interlan NI5010 ethercard. | 
|  | 2 | * | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 3 | *	Copyright 1996,1997,2006 Jan-Pascal van Best and Andreas Mohr. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * | 
|  | 5 | *	This software may be used and distributed according to the terms | 
|  | 6 | *	of the GNU General Public License, incorporated herein by reference. | 
|  | 7 | * | 
|  | 8 | * 	The authors may be reached as: | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 9 | *		janpascal@vanbest.org		andi@lisas.de | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * | 
|  | 11 | *	Sources: | 
|  | 12 | * 	 	Donald Becker's "skeleton.c" | 
|  | 13 | *  		Crynwr ni5010 packet driver | 
|  | 14 | * | 
|  | 15 | *	Changes: | 
|  | 16 | *		v0.0: First test version | 
|  | 17 | *		v0.1: First working version | 
|  | 18 | *		v0.2: | 
|  | 19 | *		v0.3->v0.90: Now demand setting io and irq when loading as module | 
|  | 20 | *	970430	v0.91: modified for Linux 2.1.14 | 
|  | 21 | *		v0.92: Implemented Andreas' (better) NI5010 probe | 
|  | 22 | *	970503	v0.93: Fixed auto-irq failure on warm reboot (JB) | 
|  | 23 | *	970623	v1.00: First kernel version (AM) | 
|  | 24 | *	970814	v1.01: Added detection of onboard receive buffer size (AM) | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 25 | *	060611	v1.02: slight cleanup: email addresses, driver modernization. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | *	Bugs: | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 27 | *		- not SMP-safe (no locking of I/O accesses) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | *		- Note that you have to patch ifconfig for the new /proc/net/dev | 
|  | 29 | *		format. It gives incorrect stats otherwise. | 
|  | 30 | * | 
|  | 31 | *	To do: | 
|  | 32 | *		Fix all bugs :-) | 
|  | 33 | *		Move some stuff to chipset_init() | 
|  | 34 | *		Handle xmt errors other than collisions | 
|  | 35 | *		Complete merge with Andreas' driver | 
|  | 36 | *		Implement ring buffers (Is this useful? You can't squeeze | 
|  | 37 | *			too many packet in a 2k buffer!) | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 38 | *		Implement DMA (Again, is this useful? Some docs say DMA is | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | *			slower than programmed I/O) | 
|  | 40 | * | 
|  | 41 | *	Compile with: | 
|  | 42 | *		gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ \ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 43 | *			-DMODULE -c ni5010.c | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * | 
|  | 45 | *	Insert with e.g.: | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 46 | *		insmod ni5010.ko io=0x300 irq=5 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | */ | 
|  | 48 |  | 
|  | 49 | #include <linux/module.h> | 
|  | 50 | #include <linux/kernel.h> | 
|  | 51 | #include <linux/string.h> | 
|  | 52 | #include <linux/errno.h> | 
|  | 53 | #include <linux/ioport.h> | 
|  | 54 | #include <linux/slab.h> | 
|  | 55 | #include <linux/interrupt.h> | 
|  | 56 | #include <linux/delay.h> | 
|  | 57 | #include <linux/init.h> | 
|  | 58 | #include <linux/bitops.h> | 
|  | 59 | #include <asm/io.h> | 
|  | 60 | #include <asm/dma.h> | 
|  | 61 |  | 
|  | 62 | #include <linux/netdevice.h> | 
|  | 63 | #include <linux/etherdevice.h> | 
|  | 64 | #include <linux/skbuff.h> | 
|  | 65 |  | 
|  | 66 | #include "ni5010.h" | 
|  | 67 |  | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 68 | static const char boardname[] = "NI5010"; | 
|  | 69 | static char version[] __initdata = | 
|  | 70 | "ni5010.c: v1.02 20060611 Jan-Pascal van Best and Andreas Mohr\n"; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 71 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* bufsize_rcv == 0 means autoprobing */ | 
|  | 73 | static unsigned int bufsize_rcv; | 
|  | 74 |  | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 75 | #define JUMPERED_INTERRUPTS	/* IRQ line jumpered on board */ | 
|  | 76 | #undef JUMPERED_DMA		/* No DMA used */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #undef FULL_IODETECT		/* Only detect in portlist */ | 
|  | 78 |  | 
|  | 79 | #ifndef FULL_IODETECT | 
|  | 80 | /* A zero-terminated list of I/O addresses to be probed. */ | 
|  | 81 | static unsigned int ports[] __initdata = | 
|  | 82 | { 0x300, 0x320, 0x340, 0x360, 0x380, 0x3a0, 0 }; | 
|  | 83 | #endif | 
|  | 84 |  | 
|  | 85 | /* Use 0 for production, 1 for verification, >2 for debug */ | 
|  | 86 | #ifndef NI5010_DEBUG | 
|  | 87 | #define NI5010_DEBUG 0 | 
|  | 88 | #endif | 
|  | 89 |  | 
|  | 90 | /* Information that needs to be kept for each board. */ | 
|  | 91 | struct ni5010_local { | 
|  | 92 | struct net_device_stats stats; | 
|  | 93 | int o_pkt_size; | 
|  | 94 | spinlock_t lock; | 
|  | 95 | }; | 
|  | 96 |  | 
|  | 97 | /* Index to functions, as function prototypes. */ | 
|  | 98 |  | 
|  | 99 | static int	ni5010_probe1(struct net_device *dev, int ioaddr); | 
|  | 100 | static int	ni5010_open(struct net_device *dev); | 
|  | 101 | static int	ni5010_send_packet(struct sk_buff *skb, struct net_device *dev); | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 102 | static irqreturn_t ni5010_interrupt(int irq, void *dev_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | static void	ni5010_rx(struct net_device *dev); | 
|  | 104 | static void	ni5010_timeout(struct net_device *dev); | 
|  | 105 | static int	ni5010_close(struct net_device *dev); | 
|  | 106 | static struct net_device_stats *ni5010_get_stats(struct net_device *dev); | 
|  | 107 | static void 	ni5010_set_multicast_list(struct net_device *dev); | 
|  | 108 | static void	reset_receiver(struct net_device *dev); | 
|  | 109 |  | 
|  | 110 | static int	process_xmt_interrupt(struct net_device *dev); | 
|  | 111 | #define tx_done(dev) 1 | 
|  | 112 | static void	hardware_send_packet(struct net_device *dev, char *buf, int length, int pad); | 
|  | 113 | static void 	chipset_init(struct net_device *dev, int startp); | 
|  | 114 | static void	dump_packet(void *buf, int len); | 
|  | 115 | static void 	ni5010_show_registers(struct net_device *dev); | 
|  | 116 |  | 
|  | 117 | static int io; | 
|  | 118 | static int irq; | 
|  | 119 |  | 
|  | 120 | struct net_device * __init ni5010_probe(int unit) | 
|  | 121 | { | 
|  | 122 | struct net_device *dev = alloc_etherdev(sizeof(struct ni5010_local)); | 
|  | 123 | int *port; | 
|  | 124 | int err = 0; | 
|  | 125 |  | 
|  | 126 | if (!dev) | 
|  | 127 | return ERR_PTR(-ENOMEM); | 
|  | 128 |  | 
|  | 129 | if (unit >= 0) { | 
|  | 130 | sprintf(dev->name, "eth%d", unit); | 
|  | 131 | netdev_boot_setup_check(dev); | 
|  | 132 | io = dev->base_addr; | 
|  | 133 | irq = dev->irq; | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | PRINTK2((KERN_DEBUG "%s: Entering ni5010_probe\n", dev->name)); | 
|  | 137 |  | 
|  | 138 | SET_MODULE_OWNER(dev); | 
|  | 139 |  | 
|  | 140 | if (io > 0x1ff)	{	/* Check a single specified location. */ | 
|  | 141 | err = ni5010_probe1(dev, io); | 
|  | 142 | } else if (io != 0) {	/* Don't probe at all. */ | 
|  | 143 | err = -ENXIO; | 
|  | 144 | } else { | 
|  | 145 | #ifdef FULL_IODETECT | 
|  | 146 | for (io=0x200; io<0x400 && ni5010_probe1(dev, io) ; io+=0x20) | 
|  | 147 | ; | 
|  | 148 | if (io == 0x400) | 
|  | 149 | err = -ENODEV; | 
|  | 150 |  | 
|  | 151 | #else | 
|  | 152 | for (port = ports; *port && ni5010_probe1(dev, *port); port++) | 
|  | 153 | ; | 
|  | 154 | if (!*port) | 
|  | 155 | err = -ENODEV; | 
|  | 156 | #endif	/* FULL_IODETECT */ | 
|  | 157 | } | 
|  | 158 | if (err) | 
|  | 159 | goto out; | 
|  | 160 | err = register_netdev(dev); | 
|  | 161 | if (err) | 
|  | 162 | goto out1; | 
|  | 163 | return dev; | 
|  | 164 | out1: | 
|  | 165 | release_region(dev->base_addr, NI5010_IO_EXTENT); | 
|  | 166 | out: | 
|  | 167 | free_netdev(dev); | 
|  | 168 | return ERR_PTR(err); | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 | static inline int rd_port(int ioaddr) | 
|  | 172 | { | 
|  | 173 | inb(IE_RBUF); | 
|  | 174 | return inb(IE_SAPROM); | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | static void __init trigger_irq(int ioaddr) | 
|  | 178 | { | 
|  | 179 | outb(0x00, EDLC_RESET);	/* Clear EDLC hold RESET state */ | 
|  | 180 | outb(0x00, IE_RESET);	/* Board reset */ | 
|  | 181 | outb(0x00, EDLC_XMASK);	/* Disable all Xmt interrupts */ | 
|  | 182 | outb(0x00, EDLC_RMASK); /* Disable all Rcv interrupt */ | 
|  | 183 | outb(0xff, EDLC_XCLR);	/* Clear all pending Xmt interrupts */ | 
|  | 184 | outb(0xff, EDLC_RCLR);	/* Clear all pending Rcv interrupts */ | 
|  | 185 | /* | 
|  | 186 | * Transmit packet mode: Ignore parity, Power xcvr, | 
|  | 187 | * 	Enable loopback | 
|  | 188 | */ | 
|  | 189 | outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE); | 
|  | 190 | outb(RMD_BROADCAST, EDLC_RMODE); /* Receive normal&broadcast */ | 
|  | 191 | outb(XM_ALL, EDLC_XMASK);	/* Enable all Xmt interrupts */ | 
|  | 192 | udelay(50);			/* FIXME: Necessary? */ | 
|  | 193 | outb(MM_EN_XMT|MM_MUX, IE_MMODE); /* Start transmission */ | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | /* | 
|  | 197 | *      This is the real probe routine.  Linux has a history of friendly device | 
|  | 198 | *      probes on the ISA bus.  A good device probes avoids doing writes, and | 
|  | 199 | *      verifies that the correct device exists and functions. | 
|  | 200 | */ | 
|  | 201 |  | 
|  | 202 | static int __init ni5010_probe1(struct net_device *dev, int ioaddr) | 
|  | 203 | { | 
|  | 204 | static unsigned version_printed; | 
|  | 205 | struct ni5010_local *lp; | 
|  | 206 | int i; | 
|  | 207 | unsigned int data = 0; | 
|  | 208 | int boguscount = 40; | 
|  | 209 | int err = -ENODEV; | 
|  | 210 |  | 
|  | 211 | dev->base_addr = ioaddr; | 
|  | 212 | dev->irq = irq; | 
|  | 213 |  | 
|  | 214 | if (!request_region(ioaddr, NI5010_IO_EXTENT, boardname)) | 
|  | 215 | return -EBUSY; | 
|  | 216 |  | 
|  | 217 | /* | 
|  | 218 | * This is no "official" probe method, I've rather tested which | 
|  | 219 | * probe works best with my seven NI5010 cards | 
|  | 220 | * (they have very different serial numbers) | 
|  | 221 | * Suggestions or failure reports are very, very welcome ! | 
|  | 222 | * But I think it is a relatively good probe method | 
|  | 223 | * since it doesn't use any "outb" | 
|  | 224 | * It should be nearly 100% reliable ! | 
|  | 225 | * well-known WARNING: this probe method (like many others) | 
|  | 226 | * will hang the system if a NE2000 card region is probed ! | 
|  | 227 | * | 
|  | 228 | *   - Andreas | 
|  | 229 | */ | 
|  | 230 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 231 | PRINTK2((KERN_DEBUG "%s: entering ni5010_probe1(%#3x)\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | dev->name, ioaddr)); | 
|  | 233 |  | 
|  | 234 | if (inb(ioaddr+0) == 0xff) | 
|  | 235 | goto out; | 
|  | 236 |  | 
|  | 237 | while ( (rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr) & | 
|  | 238 | rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr)) != 0xff) | 
|  | 239 | { | 
|  | 240 | if (boguscount-- == 0) | 
|  | 241 | goto out; | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | PRINTK2((KERN_DEBUG "%s: I/O #1 passed!\n", dev->name)); | 
|  | 245 |  | 
|  | 246 | for (i=0; i<32; i++) | 
|  | 247 | if ( (data = rd_port(ioaddr)) != 0xff) break; | 
|  | 248 | if (data==0xff) | 
|  | 249 | goto out; | 
|  | 250 |  | 
|  | 251 | PRINTK2((KERN_DEBUG "%s: I/O #2 passed!\n", dev->name)); | 
|  | 252 |  | 
|  | 253 | if ((data != SA_ADDR0) || (rd_port(ioaddr) != SA_ADDR1) || | 
|  | 254 | (rd_port(ioaddr) != SA_ADDR2)) | 
|  | 255 | goto out; | 
|  | 256 |  | 
|  | 257 | for (i=0; i<4; i++) | 
|  | 258 | rd_port(ioaddr); | 
|  | 259 |  | 
|  | 260 | if ( (rd_port(ioaddr) != NI5010_MAGICVAL1) || | 
|  | 261 | (rd_port(ioaddr) != NI5010_MAGICVAL2) ) | 
|  | 262 | goto out; | 
|  | 263 |  | 
|  | 264 | PRINTK2((KERN_DEBUG "%s: I/O #3 passed!\n", dev->name)); | 
|  | 265 |  | 
|  | 266 | if (NI5010_DEBUG && version_printed++ == 0) | 
|  | 267 | printk(KERN_INFO "%s", version); | 
|  | 268 |  | 
|  | 269 | printk("NI5010 ethercard probe at 0x%x: ", ioaddr); | 
|  | 270 |  | 
|  | 271 | dev->base_addr = ioaddr; | 
|  | 272 |  | 
|  | 273 | for (i=0; i<6; i++) { | 
|  | 274 | outw(i, IE_GP); | 
|  | 275 | printk("%2.2x ", dev->dev_addr[i] = inb(IE_SAPROM)); | 
|  | 276 | } | 
|  | 277 |  | 
|  | 278 | PRINTK2((KERN_DEBUG "%s: I/O #4 passed!\n", dev->name)); | 
|  | 279 |  | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 280 | #ifdef JUMPERED_INTERRUPTS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (dev->irq == 0xff) | 
|  | 282 | ; | 
|  | 283 | else if (dev->irq < 2) { | 
|  | 284 | unsigned long irq_mask; | 
|  | 285 |  | 
|  | 286 | PRINTK2((KERN_DEBUG "%s: I/O #5 passed!\n", dev->name)); | 
|  | 287 |  | 
|  | 288 | irq_mask = probe_irq_on(); | 
|  | 289 | trigger_irq(ioaddr); | 
|  | 290 | mdelay(20); | 
|  | 291 | dev->irq = probe_irq_off(irq_mask); | 
|  | 292 |  | 
|  | 293 | PRINTK2((KERN_DEBUG "%s: I/O #6 passed!\n", dev->name)); | 
|  | 294 |  | 
|  | 295 | if (dev->irq == 0) { | 
|  | 296 | err = -EAGAIN; | 
|  | 297 | printk(KERN_WARNING "%s: no IRQ found!\n", dev->name); | 
|  | 298 | goto out; | 
|  | 299 | } | 
|  | 300 | PRINTK2((KERN_DEBUG "%s: I/O #7 passed!\n", dev->name)); | 
|  | 301 | } else if (dev->irq == 2) { | 
|  | 302 | dev->irq = 9; | 
|  | 303 | } | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 304 | #endif	/* JUMPERED_INTERRUPTS */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | PRINTK2((KERN_DEBUG "%s: I/O #9 passed!\n", dev->name)); | 
|  | 306 |  | 
|  | 307 | /* DMA is not supported (yet?), so no use detecting it */ | 
|  | 308 | lp = netdev_priv(dev); | 
|  | 309 |  | 
|  | 310 | spin_lock_init(&lp->lock); | 
|  | 311 |  | 
|  | 312 | PRINTK2((KERN_DEBUG "%s: I/O #10 passed!\n", dev->name)); | 
|  | 313 |  | 
|  | 314 | /* get the size of the onboard receive buffer | 
|  | 315 | * higher addresses than bufsize are wrapped into real buffer | 
|  | 316 | * i.e. data for offs. 0x801 is written to 0x1 with a 2K onboard buffer | 
|  | 317 | */ | 
|  | 318 | if (!bufsize_rcv) { | 
|  | 319 | outb(1, IE_MMODE);      /* Put Rcv buffer on system bus */ | 
|  | 320 | outw(0, IE_GP);		/* Point GP at start of packet */ | 
|  | 321 | outb(0, IE_RBUF);	/* set buffer byte 0 to 0 */ | 
|  | 322 | for (i = 1; i < 0xff; i++) { | 
|  | 323 | outw(i << 8, IE_GP); /* Point GP at packet size to be tested */ | 
|  | 324 | outb(i, IE_RBUF); | 
|  | 325 | outw(0x0, IE_GP); /* Point GP at start of packet */ | 
|  | 326 | data = inb(IE_RBUF); | 
|  | 327 | if (data == i) break; | 
|  | 328 | } | 
|  | 329 | bufsize_rcv = i << 8; | 
|  | 330 | outw(0, IE_GP);		/* Point GP at start of packet */ | 
|  | 331 | outb(0, IE_RBUF);	/* set buffer byte 0 to 0 again */ | 
|  | 332 | } | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 333 | printk("-> bufsize rcv/xmt=%d/%d\n", bufsize_rcv, NI5010_BUFSIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | memset(dev->priv, 0, sizeof(struct ni5010_local)); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 335 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | dev->open		= ni5010_open; | 
|  | 337 | dev->stop		= ni5010_close; | 
|  | 338 | dev->hard_start_xmit	= ni5010_send_packet; | 
|  | 339 | dev->get_stats		= ni5010_get_stats; | 
|  | 340 | dev->set_multicast_list = ni5010_set_multicast_list; | 
|  | 341 | dev->tx_timeout		= ni5010_timeout; | 
|  | 342 | dev->watchdog_timeo	= HZ/20; | 
|  | 343 |  | 
|  | 344 | dev->flags &= ~IFF_MULTICAST;	/* Multicast doesn't work */ | 
|  | 345 |  | 
|  | 346 | /* Shut up the ni5010 */ | 
|  | 347 | outb(0, EDLC_RMASK);	/* Mask all receive interrupts */ | 
|  | 348 | outb(0, EDLC_XMASK);	/* Mask all xmit interrupts */ | 
|  | 349 | outb(0xff, EDLC_RCLR);	/* Kill all pending rcv interrupts */ | 
|  | 350 | outb(0xff, EDLC_XCLR); 	/* Kill all pending xmt interrupts */ | 
|  | 351 |  | 
|  | 352 | printk(KERN_INFO "%s: NI5010 found at 0x%x, using IRQ %d", dev->name, ioaddr, dev->irq); | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 353 | if (dev->dma) | 
|  | 354 | printk(" & DMA %d", dev->dma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | printk(".\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return 0; | 
|  | 357 | out: | 
|  | 358 | release_region(dev->base_addr, NI5010_IO_EXTENT); | 
|  | 359 | return err; | 
|  | 360 | } | 
|  | 361 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 362 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | * Open/initialize the board.  This is called (in the current kernel) | 
|  | 364 | * sometime after booting when the 'ifconfig' program is run. | 
|  | 365 | * | 
|  | 366 | * This routine should set everything up anew at each open, even | 
|  | 367 | * registers that "should" only need to be set once at boot, so that | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 368 | * there is a non-reboot way to recover if something goes wrong. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 370 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | static int ni5010_open(struct net_device *dev) | 
|  | 372 | { | 
|  | 373 | int ioaddr = dev->base_addr; | 
|  | 374 | int i; | 
|  | 375 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 376 | PRINTK2((KERN_DEBUG "%s: entering ni5010_open()\n", dev->name)); | 
|  | 377 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | if (request_irq(dev->irq, &ni5010_interrupt, 0, boardname, dev)) { | 
|  | 379 | printk(KERN_WARNING "%s: Cannot get irq %#2x\n", dev->name, dev->irq); | 
|  | 380 | return -EAGAIN; | 
|  | 381 | } | 
|  | 382 | PRINTK3((KERN_DEBUG "%s: passed open() #1\n", dev->name)); | 
|  | 383 | /* | 
|  | 384 | * Always allocate the DMA channel after the IRQ, | 
|  | 385 | * and clean up on failure. | 
|  | 386 | */ | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 387 | #ifdef JUMPERED_DMA | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | if (request_dma(dev->dma, cardname)) { | 
|  | 389 | printk(KERN_WARNING "%s: Cannot get dma %#2x\n", dev->name, dev->dma); | 
|  | 390 | free_irq(dev->irq, NULL); | 
|  | 391 | return -EAGAIN; | 
|  | 392 | } | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 393 | #endif	/* JUMPERED_DMA */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 |  | 
|  | 395 | PRINTK3((KERN_DEBUG "%s: passed open() #2\n", dev->name)); | 
|  | 396 | /* Reset the hardware here.  Don't forget to set the station address. */ | 
|  | 397 |  | 
|  | 398 | outb(RS_RESET, EDLC_RESET);	/* Hold up EDLC_RESET while configing board */ | 
|  | 399 | outb(0, IE_RESET);		/* Hardware reset of ni5010 board */ | 
|  | 400 | outb(XMD_LBC, EDLC_XMODE);	/* Only loopback xmits */ | 
|  | 401 |  | 
|  | 402 | PRINTK3((KERN_DEBUG "%s: passed open() #3\n", dev->name)); | 
|  | 403 | /* Set the station address */ | 
|  | 404 | for(i = 0;i < 6; i++) { | 
|  | 405 | outb(dev->dev_addr[i], EDLC_ADDR + i); | 
|  | 406 | } | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 407 |  | 
|  | 408 | PRINTK3((KERN_DEBUG "%s: Initialising ni5010\n", dev->name)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | outb(0, EDLC_XMASK);	/* No xmit interrupts for now */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 410 | outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /* Normal packet xmit mode */ | 
|  | 412 | outb(0xff, EDLC_XCLR);	/* Clear all pending xmit interrupts */ | 
|  | 413 | outb(RMD_BROADCAST, EDLC_RMODE); | 
|  | 414 | /* Receive broadcast and normal packets */ | 
|  | 415 | reset_receiver(dev);	/* Ready ni5010 for receiving packets */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 416 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | outb(0, EDLC_RESET);	/* Un-reset the ni5010 */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 418 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | netif_start_queue(dev); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 420 |  | 
|  | 421 | if (NI5010_DEBUG) ni5010_show_registers(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 |  | 
|  | 423 | PRINTK((KERN_DEBUG "%s: open successful\n", dev->name)); | 
|  | 424 | return 0; | 
|  | 425 | } | 
|  | 426 |  | 
|  | 427 | static void reset_receiver(struct net_device *dev) | 
|  | 428 | { | 
|  | 429 | int ioaddr = dev->base_addr; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 430 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | PRINTK3((KERN_DEBUG "%s: resetting receiver\n", dev->name)); | 
|  | 432 | outw(0, IE_GP);		/* Receive packet at start of buffer */ | 
|  | 433 | outb(0xff, EDLC_RCLR);	/* Clear all pending rcv interrupts */ | 
|  | 434 | outb(0, IE_MMODE);	/* Put EDLC to rcv buffer */ | 
|  | 435 | outb(MM_EN_RCV, IE_MMODE); /* Enable rcv */ | 
|  | 436 | outb(0xff, EDLC_RMASK);	/* Enable all rcv interrupts */ | 
|  | 437 | } | 
|  | 438 |  | 
|  | 439 | static void ni5010_timeout(struct net_device *dev) | 
|  | 440 | { | 
|  | 441 | printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name, | 
|  | 442 | tx_done(dev) ? "IRQ conflict" : "network cable problem"); | 
|  | 443 | /* Try to restart the adaptor. */ | 
|  | 444 | /* FIXME: Give it a real kick here */ | 
|  | 445 | chipset_init(dev, 1); | 
|  | 446 | dev->trans_start = jiffies; | 
|  | 447 | netif_wake_queue(dev); | 
|  | 448 | } | 
|  | 449 |  | 
|  | 450 | static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev) | 
|  | 451 | { | 
|  | 452 | int length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; | 
|  | 453 |  | 
|  | 454 | PRINTK2((KERN_DEBUG "%s: entering ni5010_send_packet\n", dev->name)); | 
|  | 455 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 456 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | * Block sending | 
|  | 458 | */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 459 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | netif_stop_queue(dev); | 
|  | 461 | hardware_send_packet(dev, (unsigned char *)skb->data, skb->len, length-skb->len); | 
|  | 462 | dev->trans_start = jiffies; | 
|  | 463 | dev_kfree_skb (skb); | 
|  | 464 | return 0; | 
|  | 465 | } | 
|  | 466 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 467 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | * The typical workload of the driver: | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 469 | * Handle the network interface interrupts. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 471 | static irqreturn_t ni5010_interrupt(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { | 
|  | 473 | struct net_device *dev = dev_id; | 
|  | 474 | struct ni5010_local *lp; | 
|  | 475 | int ioaddr, status; | 
|  | 476 | int xmit_was_error = 0; | 
|  | 477 |  | 
|  | 478 | PRINTK2((KERN_DEBUG "%s: entering ni5010_interrupt\n", dev->name)); | 
|  | 479 |  | 
|  | 480 | ioaddr = dev->base_addr; | 
|  | 481 | lp = netdev_priv(dev); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 482 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | spin_lock(&lp->lock); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 484 | status = inb(IE_ISTAT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | PRINTK3((KERN_DEBUG "%s: IE_ISTAT = %#02x\n", dev->name, status)); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 486 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | if ((status & IS_R_INT) == 0) ni5010_rx(dev); | 
|  | 488 |  | 
|  | 489 | if ((status & IS_X_INT) == 0) { | 
|  | 490 | xmit_was_error = process_xmt_interrupt(dev); | 
|  | 491 | } | 
|  | 492 |  | 
|  | 493 | if ((status & IS_DMA_INT) == 0) { | 
|  | 494 | PRINTK((KERN_DEBUG "%s: DMA complete (?)\n", dev->name)); | 
|  | 495 | outb(0, IE_DMA_RST); /* Reset DMA int */ | 
|  | 496 | } | 
|  | 497 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 498 | if (!xmit_was_error) | 
|  | 499 | reset_receiver(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | spin_unlock(&lp->lock); | 
|  | 501 | return IRQ_HANDLED; | 
|  | 502 | } | 
|  | 503 |  | 
|  | 504 |  | 
|  | 505 | static void dump_packet(void *buf, int len) | 
|  | 506 | { | 
|  | 507 | int i; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 508 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | printk(KERN_DEBUG "Packet length = %#4x\n", len); | 
|  | 510 | for (i = 0; i < len; i++){ | 
|  | 511 | if (i % 16 == 0) printk(KERN_DEBUG "%#4.4x", i); | 
|  | 512 | if (i % 2 == 0) printk(" "); | 
|  | 513 | printk("%2.2x", ((unsigned char *)buf)[i]); | 
|  | 514 | if (i % 16 == 15) printk("\n"); | 
|  | 515 | } | 
|  | 516 | printk("\n"); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 517 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | return; | 
|  | 519 | } | 
|  | 520 |  | 
|  | 521 | /* We have a good packet, get it out of the buffer. */ | 
|  | 522 | static void ni5010_rx(struct net_device *dev) | 
|  | 523 | { | 
|  | 524 | struct ni5010_local *lp = netdev_priv(dev); | 
|  | 525 | int ioaddr = dev->base_addr; | 
|  | 526 | unsigned char rcv_stat; | 
|  | 527 | struct sk_buff *skb; | 
|  | 528 | int i_pkt_size; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 529 |  | 
|  | 530 | PRINTK2((KERN_DEBUG "%s: entering ni5010_rx()\n", dev->name)); | 
|  | 531 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | rcv_stat = inb(EDLC_RSTAT); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 533 | PRINTK3((KERN_DEBUG "%s: EDLC_RSTAT = %#2x\n", dev->name, rcv_stat)); | 
|  | 534 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | if ( (rcv_stat & RS_VALID_BITS) != RS_PKT_OK) { | 
|  | 536 | PRINTK((KERN_INFO "%s: receive error.\n", dev->name)); | 
|  | 537 | lp->stats.rx_errors++; | 
|  | 538 | if (rcv_stat & RS_RUNT) lp->stats.rx_length_errors++; | 
|  | 539 | if (rcv_stat & RS_ALIGN) lp->stats.rx_frame_errors++; | 
|  | 540 | if (rcv_stat & RS_CRC_ERR) lp->stats.rx_crc_errors++; | 
|  | 541 | if (rcv_stat & RS_OFLW) lp->stats.rx_fifo_errors++; | 
|  | 542 | outb(0xff, EDLC_RCLR); /* Clear the interrupt */ | 
|  | 543 | return; | 
|  | 544 | } | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 545 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | outb(0xff, EDLC_RCLR);  /* Clear the interrupt */ | 
|  | 547 |  | 
|  | 548 | i_pkt_size = inw(IE_RCNT); | 
|  | 549 | if (i_pkt_size > ETH_FRAME_LEN || i_pkt_size < 10 ) { | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 550 | PRINTK((KERN_DEBUG "%s: Packet size error, packet size = %#4.4x\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | dev->name, i_pkt_size)); | 
|  | 552 | lp->stats.rx_errors++; | 
|  | 553 | lp->stats.rx_length_errors++; | 
|  | 554 | return; | 
|  | 555 | } | 
|  | 556 |  | 
|  | 557 | /* Malloc up new buffer. */ | 
|  | 558 | skb = dev_alloc_skb(i_pkt_size + 3); | 
|  | 559 | if (skb == NULL) { | 
|  | 560 | printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name); | 
|  | 561 | lp->stats.rx_dropped++; | 
|  | 562 | return; | 
|  | 563 | } | 
| 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 | skb->dev = dev; | 
|  | 566 | skb_reserve(skb, 2); | 
| 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 | /* Read packet into buffer */ | 
|  | 569 | outb(MM_MUX, IE_MMODE); /* Rcv buffer to system bus */ | 
|  | 570 | outw(0, IE_GP);	/* Seek to beginning of packet */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 571 | insb(IE_RBUF, skb_put(skb, i_pkt_size), i_pkt_size); | 
|  | 572 |  | 
|  | 573 | if (NI5010_DEBUG >= 4) | 
|  | 574 | dump_packet(skb->data, skb->len); | 
|  | 575 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | skb->protocol = eth_type_trans(skb,dev); | 
|  | 577 | netif_rx(skb); | 
|  | 578 | dev->last_rx = jiffies; | 
|  | 579 | lp->stats.rx_packets++; | 
|  | 580 | lp->stats.rx_bytes += i_pkt_size; | 
|  | 581 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 582 | PRINTK2((KERN_DEBUG "%s: Received packet, size=%#4.4x\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | dev->name, i_pkt_size)); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 584 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } | 
|  | 586 |  | 
|  | 587 | static int process_xmt_interrupt(struct net_device *dev) | 
|  | 588 | { | 
|  | 589 | struct ni5010_local *lp = netdev_priv(dev); | 
|  | 590 | int ioaddr = dev->base_addr; | 
|  | 591 | int xmit_stat; | 
|  | 592 |  | 
|  | 593 | PRINTK2((KERN_DEBUG "%s: entering process_xmt_interrupt\n", dev->name)); | 
|  | 594 |  | 
|  | 595 | xmit_stat = inb(EDLC_XSTAT); | 
|  | 596 | PRINTK3((KERN_DEBUG "%s: EDLC_XSTAT = %2.2x\n", dev->name, xmit_stat)); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 597 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | outb(0, EDLC_XMASK);	/* Disable xmit IRQ's */ | 
|  | 599 | outb(0xff, EDLC_XCLR);	/* Clear all pending xmit IRQ's */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 600 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | if (xmit_stat & XS_COLL){ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 602 | PRINTK((KERN_DEBUG "%s: collision detected, retransmitting\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | dev->name)); | 
|  | 604 | outw(NI5010_BUFSIZE - lp->o_pkt_size, IE_GP); | 
|  | 605 | /* outb(0, IE_MMODE); */ /* xmt buf on sysbus FIXME: needed ? */ | 
|  | 606 | outb(MM_EN_XMT | MM_MUX, IE_MMODE); | 
|  | 607 | outb(XM_ALL, EDLC_XMASK); /* Enable xmt IRQ's */ | 
|  | 608 | lp->stats.collisions++; | 
|  | 609 | return 1; | 
|  | 610 | } | 
|  | 611 |  | 
|  | 612 | /* FIXME: handle other xmt error conditions */ | 
|  | 613 |  | 
|  | 614 | lp->stats.tx_packets++; | 
|  | 615 | lp->stats.tx_bytes += lp->o_pkt_size; | 
|  | 616 | netif_wake_queue(dev); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 617 |  | 
|  | 618 | PRINTK2((KERN_DEBUG "%s: sent packet, size=%#4.4x\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | dev->name, lp->o_pkt_size)); | 
|  | 620 |  | 
|  | 621 | return 0; | 
|  | 622 | } | 
|  | 623 |  | 
|  | 624 | /* The inverse routine to ni5010_open(). */ | 
|  | 625 | static int ni5010_close(struct net_device *dev) | 
|  | 626 | { | 
|  | 627 | int ioaddr = dev->base_addr; | 
|  | 628 |  | 
|  | 629 | PRINTK2((KERN_DEBUG "%s: entering ni5010_close\n", dev->name)); | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 630 | #ifdef JUMPERED_INTERRUPTS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | free_irq(dev->irq, NULL); | 
|  | 632 | #endif | 
|  | 633 | /* Put card in held-RESET state */ | 
|  | 634 | outb(0, IE_MMODE); | 
|  | 635 | outb(RS_RESET, EDLC_RESET); | 
|  | 636 |  | 
|  | 637 | netif_stop_queue(dev); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 638 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | PRINTK((KERN_DEBUG "%s: %s closed down\n", dev->name, boardname)); | 
|  | 640 | return 0; | 
|  | 641 |  | 
|  | 642 | } | 
|  | 643 |  | 
|  | 644 | /* Get the current statistics.	This may be called with the card open or | 
|  | 645 | closed. */ | 
|  | 646 | static struct net_device_stats *ni5010_get_stats(struct net_device *dev) | 
|  | 647 | { | 
|  | 648 | struct ni5010_local *lp = netdev_priv(dev); | 
|  | 649 |  | 
|  | 650 | PRINTK2((KERN_DEBUG "%s: entering ni5010_get_stats\n", dev->name)); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 651 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | if (NI5010_DEBUG) ni5010_show_registers(dev); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 653 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | /* cli(); */ | 
|  | 655 | /* Update the statistics from the device registers. */ | 
|  | 656 | /* We do this in the interrupt handler */ | 
|  | 657 | /* sti(); */ | 
|  | 658 |  | 
|  | 659 | return &lp->stats; | 
|  | 660 | } | 
|  | 661 |  | 
|  | 662 | /* Set or clear the multicast filter for this adaptor. | 
|  | 663 | num_addrs == -1      Promiscuous mode, receive all packets | 
|  | 664 | num_addrs == 0       Normal mode, clear multicast list | 
|  | 665 | num_addrs > 0        Multicast mode, receive normal and MC packets, and do | 
|  | 666 | best-effort filtering. | 
|  | 667 | */ | 
|  | 668 | static void ni5010_set_multicast_list(struct net_device *dev) | 
|  | 669 | { | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 670 | short ioaddr = dev->base_addr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 |  | 
|  | 672 | PRINTK2((KERN_DEBUG "%s: entering set_multicast_list\n", dev->name)); | 
|  | 673 |  | 
|  | 674 | if (dev->flags&IFF_PROMISC || dev->flags&IFF_ALLMULTI) { | 
|  | 675 | dev->flags |= IFF_PROMISC; | 
|  | 676 | outb(RMD_PROMISC, EDLC_RMODE); /* Enable promiscuous mode */ | 
|  | 677 | PRINTK((KERN_DEBUG "%s: Entering promiscuous mode\n", dev->name)); | 
|  | 678 | } else if (dev->mc_list) { | 
|  | 679 | /* Sorry, multicast not supported */ | 
|  | 680 | PRINTK((KERN_DEBUG "%s: No multicast, entering broadcast mode\n", dev->name)); | 
|  | 681 | outb(RMD_BROADCAST, EDLC_RMODE); | 
|  | 682 | } else { | 
|  | 683 | PRINTK((KERN_DEBUG "%s: Entering broadcast mode\n", dev->name)); | 
|  | 684 | outb(RMD_BROADCAST, EDLC_RMODE);  /* Disable promiscuous mode, use normal mode */ | 
|  | 685 | } | 
|  | 686 | } | 
|  | 687 |  | 
|  | 688 | static void hardware_send_packet(struct net_device *dev, char *buf, int length, int pad) | 
|  | 689 | { | 
|  | 690 | struct ni5010_local *lp = netdev_priv(dev); | 
|  | 691 | int ioaddr = dev->base_addr; | 
|  | 692 | unsigned long flags; | 
|  | 693 | unsigned int buf_offs; | 
|  | 694 |  | 
|  | 695 | PRINTK2((KERN_DEBUG "%s: entering hardware_send_packet\n", dev->name)); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 696 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (length > ETH_FRAME_LEN) { | 
|  | 698 | PRINTK((KERN_WARNING "%s: packet too large, not possible\n", | 
|  | 699 | dev->name)); | 
|  | 700 | return; | 
|  | 701 | } | 
|  | 702 |  | 
|  | 703 | if (NI5010_DEBUG) ni5010_show_registers(dev); | 
|  | 704 |  | 
|  | 705 | if (inb(IE_ISTAT) & IS_EN_XMT) { | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 706 | PRINTK((KERN_WARNING "%s: sending packet while already transmitting, not possible\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | dev->name)); | 
|  | 708 | return; | 
|  | 709 | } | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 710 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | if (NI5010_DEBUG > 3) dump_packet(buf, length); | 
|  | 712 |  | 
|  | 713 | buf_offs = NI5010_BUFSIZE - length - pad; | 
|  | 714 |  | 
|  | 715 | spin_lock_irqsave(&lp->lock, flags); | 
|  | 716 | lp->o_pkt_size = length + pad; | 
|  | 717 |  | 
|  | 718 | outb(0, EDLC_RMASK);	/* Mask all receive interrupts */ | 
|  | 719 | outb(0, IE_MMODE);	/* Put Xmit buffer on system bus */ | 
|  | 720 | outb(0xff, EDLC_RCLR);	/* Clear out pending rcv interrupts */ | 
|  | 721 |  | 
|  | 722 | outw(buf_offs, IE_GP); /* Point GP at start of packet */ | 
|  | 723 | outsb(IE_XBUF, buf, length); /* Put data in buffer */ | 
|  | 724 | while(pad--) | 
|  | 725 | outb(0, IE_XBUF); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 726 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | outw(buf_offs, IE_GP); /* Rewrite where packet starts */ | 
|  | 728 |  | 
|  | 729 | /* should work without that outb() (Crynwr used it) */ | 
|  | 730 | /*outb(MM_MUX, IE_MMODE);*/ /* Xmt buffer to EDLC bus */ | 
|  | 731 | outb(MM_EN_XMT | MM_MUX, IE_MMODE); /* Begin transmission */ | 
|  | 732 | outb(XM_ALL, EDLC_XMASK); /* Cause interrupt after completion or fail */ | 
|  | 733 |  | 
|  | 734 | spin_unlock_irqrestore(&lp->lock, flags); | 
|  | 735 |  | 
|  | 736 | netif_wake_queue(dev); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 737 |  | 
|  | 738 | if (NI5010_DEBUG) ni5010_show_registers(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } | 
|  | 740 |  | 
|  | 741 | static void chipset_init(struct net_device *dev, int startp) | 
|  | 742 | { | 
|  | 743 | /* FIXME: Move some stuff here */ | 
|  | 744 | PRINTK3((KERN_DEBUG "%s: doing NOTHING in chipset_init\n", dev->name)); | 
|  | 745 | } | 
|  | 746 |  | 
|  | 747 | static void ni5010_show_registers(struct net_device *dev) | 
|  | 748 | { | 
|  | 749 | int ioaddr = dev->base_addr; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 750 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | PRINTK3((KERN_DEBUG "%s: XSTAT %#2.2x\n", dev->name, inb(EDLC_XSTAT))); | 
|  | 752 | PRINTK3((KERN_DEBUG "%s: XMASK %#2.2x\n", dev->name, inb(EDLC_XMASK))); | 
|  | 753 | PRINTK3((KERN_DEBUG "%s: RSTAT %#2.2x\n", dev->name, inb(EDLC_RSTAT))); | 
|  | 754 | PRINTK3((KERN_DEBUG "%s: RMASK %#2.2x\n", dev->name, inb(EDLC_RMASK))); | 
|  | 755 | PRINTK3((KERN_DEBUG "%s: RMODE %#2.2x\n", dev->name, inb(EDLC_RMODE))); | 
|  | 756 | PRINTK3((KERN_DEBUG "%s: XMODE %#2.2x\n", dev->name, inb(EDLC_XMODE))); | 
|  | 757 | PRINTK3((KERN_DEBUG "%s: ISTAT %#2.2x\n", dev->name, inb(IE_ISTAT))); | 
|  | 758 | } | 
|  | 759 |  | 
|  | 760 | #ifdef MODULE | 
|  | 761 | static struct net_device *dev_ni5010; | 
|  | 762 |  | 
| Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 763 | module_param(io, int, 0); | 
|  | 764 | module_param(irq, int, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | MODULE_PARM_DESC(io, "ni5010 I/O base address"); | 
|  | 766 | MODULE_PARM_DESC(irq, "ni5010 IRQ number"); | 
|  | 767 |  | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 768 | static int __init ni5010_init_module(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { | 
|  | 770 | PRINTK2((KERN_DEBUG "%s: entering init_module\n", boardname)); | 
|  | 771 | /* | 
|  | 772 | if(io <= 0 || irq == 0){ | 
|  | 773 | printk(KERN_WARNING "%s: Autoprobing not allowed for modules.\n", boardname); | 
|  | 774 | printk(KERN_WARNING "%s: Set symbols 'io' and 'irq'\n", boardname); | 
|  | 775 | return -EINVAL; | 
|  | 776 | } | 
|  | 777 | */ | 
|  | 778 | if (io <= 0){ | 
|  | 779 | printk(KERN_WARNING "%s: Autoprobing for modules is hazardous, trying anyway..\n", boardname); | 
|  | 780 | } | 
|  | 781 |  | 
|  | 782 | PRINTK2((KERN_DEBUG "%s: init_module irq=%#2x, io=%#3x\n", boardname, irq, io)); | 
|  | 783 | dev_ni5010 = ni5010_probe(-1); | 
|  | 784 | if (IS_ERR(dev_ni5010)) | 
|  | 785 | return PTR_ERR(dev_ni5010); | 
|  | 786 | return 0; | 
|  | 787 | } | 
|  | 788 |  | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 789 | static void __exit ni5010_cleanup_module(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | { | 
|  | 791 | PRINTK2((KERN_DEBUG "%s: entering cleanup_module\n", boardname)); | 
|  | 792 | unregister_netdev(dev_ni5010); | 
|  | 793 | release_region(dev_ni5010->base_addr, NI5010_IO_EXTENT); | 
|  | 794 | free_netdev(dev_ni5010); | 
|  | 795 | } | 
| Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 796 | module_init(ni5010_init_module); | 
|  | 797 | module_exit(ni5010_cleanup_module); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | #endif /* MODULE */ | 
|  | 799 | MODULE_LICENSE("GPL"); | 
|  | 800 |  | 
|  | 801 | /* | 
|  | 802 | * Local variables: | 
|  | 803 | *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c ni5010.c" | 
|  | 804 | *  version-control: t | 
|  | 805 | *  kept-new-versions: 5 | 
|  | 806 | *  tab-width: 4 | 
|  | 807 | * End: | 
|  | 808 | */ |