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 { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | int o_pkt_size; |
| 93 | spinlock_t lock; |
| 94 | }; |
| 95 | |
| 96 | /* Index to functions, as function prototypes. */ |
| 97 | |
| 98 | static int ni5010_probe1(struct net_device *dev, int ioaddr); |
| 99 | static int ni5010_open(struct net_device *dev); |
| 100 | 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] | 101 | static irqreturn_t ni5010_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | static void ni5010_rx(struct net_device *dev); |
| 103 | static void ni5010_timeout(struct net_device *dev); |
| 104 | static int ni5010_close(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | static void ni5010_set_multicast_list(struct net_device *dev); |
| 106 | static void reset_receiver(struct net_device *dev); |
| 107 | |
| 108 | static int process_xmt_interrupt(struct net_device *dev); |
| 109 | #define tx_done(dev) 1 |
| 110 | static void hardware_send_packet(struct net_device *dev, char *buf, int length, int pad); |
| 111 | static void chipset_init(struct net_device *dev, int startp); |
| 112 | static void dump_packet(void *buf, int len); |
| 113 | static void ni5010_show_registers(struct net_device *dev); |
| 114 | |
| 115 | static int io; |
| 116 | static int irq; |
| 117 | |
| 118 | struct net_device * __init ni5010_probe(int unit) |
| 119 | { |
| 120 | struct net_device *dev = alloc_etherdev(sizeof(struct ni5010_local)); |
| 121 | int *port; |
| 122 | int err = 0; |
| 123 | |
| 124 | if (!dev) |
| 125 | return ERR_PTR(-ENOMEM); |
| 126 | |
| 127 | if (unit >= 0) { |
| 128 | sprintf(dev->name, "eth%d", unit); |
| 129 | netdev_boot_setup_check(dev); |
| 130 | io = dev->base_addr; |
| 131 | irq = dev->irq; |
| 132 | } |
| 133 | |
| 134 | PRINTK2((KERN_DEBUG "%s: Entering ni5010_probe\n", dev->name)); |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | if (io > 0x1ff) { /* Check a single specified location. */ |
| 137 | err = ni5010_probe1(dev, io); |
| 138 | } else if (io != 0) { /* Don't probe at all. */ |
| 139 | err = -ENXIO; |
| 140 | } else { |
| 141 | #ifdef FULL_IODETECT |
| 142 | for (io=0x200; io<0x400 && ni5010_probe1(dev, io) ; io+=0x20) |
| 143 | ; |
| 144 | if (io == 0x400) |
| 145 | err = -ENODEV; |
| 146 | |
| 147 | #else |
| 148 | for (port = ports; *port && ni5010_probe1(dev, *port); port++) |
| 149 | ; |
| 150 | if (!*port) |
| 151 | err = -ENODEV; |
| 152 | #endif /* FULL_IODETECT */ |
| 153 | } |
| 154 | if (err) |
| 155 | goto out; |
| 156 | err = register_netdev(dev); |
| 157 | if (err) |
| 158 | goto out1; |
| 159 | return dev; |
| 160 | out1: |
| 161 | release_region(dev->base_addr, NI5010_IO_EXTENT); |
| 162 | out: |
| 163 | free_netdev(dev); |
| 164 | return ERR_PTR(err); |
| 165 | } |
| 166 | |
| 167 | static inline int rd_port(int ioaddr) |
| 168 | { |
| 169 | inb(IE_RBUF); |
| 170 | return inb(IE_SAPROM); |
| 171 | } |
| 172 | |
| 173 | static void __init trigger_irq(int ioaddr) |
| 174 | { |
| 175 | outb(0x00, EDLC_RESET); /* Clear EDLC hold RESET state */ |
| 176 | outb(0x00, IE_RESET); /* Board reset */ |
| 177 | outb(0x00, EDLC_XMASK); /* Disable all Xmt interrupts */ |
| 178 | outb(0x00, EDLC_RMASK); /* Disable all Rcv interrupt */ |
| 179 | outb(0xff, EDLC_XCLR); /* Clear all pending Xmt interrupts */ |
| 180 | outb(0xff, EDLC_RCLR); /* Clear all pending Rcv interrupts */ |
| 181 | /* |
| 182 | * Transmit packet mode: Ignore parity, Power xcvr, |
| 183 | * Enable loopback |
| 184 | */ |
| 185 | outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE); |
| 186 | outb(RMD_BROADCAST, EDLC_RMODE); /* Receive normal&broadcast */ |
| 187 | outb(XM_ALL, EDLC_XMASK); /* Enable all Xmt interrupts */ |
| 188 | udelay(50); /* FIXME: Necessary? */ |
| 189 | outb(MM_EN_XMT|MM_MUX, IE_MMODE); /* Start transmission */ |
| 190 | } |
| 191 | |
Alexander Beregalov | 79f1bc0 | 2009-03-28 23:37:27 -0700 | [diff] [blame] | 192 | static const struct net_device_ops ni5010_netdev_ops = { |
| 193 | .ndo_open = ni5010_open, |
| 194 | .ndo_stop = ni5010_close, |
| 195 | .ndo_start_xmit = ni5010_send_packet, |
| 196 | .ndo_set_multicast_list = ni5010_set_multicast_list, |
| 197 | .ndo_tx_timeout = ni5010_timeout, |
| 198 | .ndo_validate_addr = eth_validate_addr, |
| 199 | .ndo_set_mac_address = eth_mac_addr, |
| 200 | .ndo_change_mtu = eth_change_mtu, |
| 201 | }; |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /* |
| 204 | * This is the real probe routine. Linux has a history of friendly device |
| 205 | * probes on the ISA bus. A good device probes avoids doing writes, and |
| 206 | * verifies that the correct device exists and functions. |
| 207 | */ |
| 208 | |
| 209 | static int __init ni5010_probe1(struct net_device *dev, int ioaddr) |
| 210 | { |
| 211 | static unsigned version_printed; |
| 212 | struct ni5010_local *lp; |
| 213 | int i; |
| 214 | unsigned int data = 0; |
| 215 | int boguscount = 40; |
| 216 | int err = -ENODEV; |
| 217 | |
| 218 | dev->base_addr = ioaddr; |
| 219 | dev->irq = irq; |
| 220 | |
| 221 | if (!request_region(ioaddr, NI5010_IO_EXTENT, boardname)) |
| 222 | return -EBUSY; |
| 223 | |
| 224 | /* |
| 225 | * This is no "official" probe method, I've rather tested which |
| 226 | * probe works best with my seven NI5010 cards |
| 227 | * (they have very different serial numbers) |
| 228 | * Suggestions or failure reports are very, very welcome ! |
| 229 | * But I think it is a relatively good probe method |
| 230 | * since it doesn't use any "outb" |
| 231 | * It should be nearly 100% reliable ! |
| 232 | * well-known WARNING: this probe method (like many others) |
| 233 | * will hang the system if a NE2000 card region is probed ! |
| 234 | * |
| 235 | * - Andreas |
| 236 | */ |
| 237 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 238 | PRINTK2((KERN_DEBUG "%s: entering ni5010_probe1(%#3x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | dev->name, ioaddr)); |
| 240 | |
| 241 | if (inb(ioaddr+0) == 0xff) |
| 242 | goto out; |
| 243 | |
| 244 | while ( (rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr) & |
| 245 | rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr)) != 0xff) |
| 246 | { |
| 247 | if (boguscount-- == 0) |
| 248 | goto out; |
| 249 | } |
| 250 | |
| 251 | PRINTK2((KERN_DEBUG "%s: I/O #1 passed!\n", dev->name)); |
| 252 | |
| 253 | for (i=0; i<32; i++) |
| 254 | if ( (data = rd_port(ioaddr)) != 0xff) break; |
| 255 | if (data==0xff) |
| 256 | goto out; |
| 257 | |
| 258 | PRINTK2((KERN_DEBUG "%s: I/O #2 passed!\n", dev->name)); |
| 259 | |
| 260 | if ((data != SA_ADDR0) || (rd_port(ioaddr) != SA_ADDR1) || |
| 261 | (rd_port(ioaddr) != SA_ADDR2)) |
| 262 | goto out; |
| 263 | |
| 264 | for (i=0; i<4; i++) |
| 265 | rd_port(ioaddr); |
| 266 | |
| 267 | if ( (rd_port(ioaddr) != NI5010_MAGICVAL1) || |
| 268 | (rd_port(ioaddr) != NI5010_MAGICVAL2) ) |
| 269 | goto out; |
| 270 | |
| 271 | PRINTK2((KERN_DEBUG "%s: I/O #3 passed!\n", dev->name)); |
| 272 | |
| 273 | if (NI5010_DEBUG && version_printed++ == 0) |
| 274 | printk(KERN_INFO "%s", version); |
| 275 | |
| 276 | printk("NI5010 ethercard probe at 0x%x: ", ioaddr); |
| 277 | |
| 278 | dev->base_addr = ioaddr; |
| 279 | |
| 280 | for (i=0; i<6; i++) { |
| 281 | outw(i, IE_GP); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 282 | dev->dev_addr[i] = inb(IE_SAPROM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 284 | printk("%pM ", dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | PRINTK2((KERN_DEBUG "%s: I/O #4 passed!\n", dev->name)); |
| 287 | |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 288 | #ifdef JUMPERED_INTERRUPTS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (dev->irq == 0xff) |
| 290 | ; |
| 291 | else if (dev->irq < 2) { |
| 292 | unsigned long irq_mask; |
| 293 | |
| 294 | PRINTK2((KERN_DEBUG "%s: I/O #5 passed!\n", dev->name)); |
| 295 | |
| 296 | irq_mask = probe_irq_on(); |
| 297 | trigger_irq(ioaddr); |
| 298 | mdelay(20); |
| 299 | dev->irq = probe_irq_off(irq_mask); |
| 300 | |
| 301 | PRINTK2((KERN_DEBUG "%s: I/O #6 passed!\n", dev->name)); |
| 302 | |
| 303 | if (dev->irq == 0) { |
| 304 | err = -EAGAIN; |
| 305 | printk(KERN_WARNING "%s: no IRQ found!\n", dev->name); |
| 306 | goto out; |
| 307 | } |
| 308 | PRINTK2((KERN_DEBUG "%s: I/O #7 passed!\n", dev->name)); |
| 309 | } else if (dev->irq == 2) { |
| 310 | dev->irq = 9; |
| 311 | } |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 312 | #endif /* JUMPERED_INTERRUPTS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | PRINTK2((KERN_DEBUG "%s: I/O #9 passed!\n", dev->name)); |
| 314 | |
| 315 | /* DMA is not supported (yet?), so no use detecting it */ |
| 316 | lp = netdev_priv(dev); |
| 317 | |
| 318 | spin_lock_init(&lp->lock); |
| 319 | |
| 320 | PRINTK2((KERN_DEBUG "%s: I/O #10 passed!\n", dev->name)); |
| 321 | |
| 322 | /* get the size of the onboard receive buffer |
| 323 | * higher addresses than bufsize are wrapped into real buffer |
| 324 | * i.e. data for offs. 0x801 is written to 0x1 with a 2K onboard buffer |
| 325 | */ |
| 326 | if (!bufsize_rcv) { |
| 327 | outb(1, IE_MMODE); /* Put Rcv buffer on system bus */ |
| 328 | outw(0, IE_GP); /* Point GP at start of packet */ |
| 329 | outb(0, IE_RBUF); /* set buffer byte 0 to 0 */ |
| 330 | for (i = 1; i < 0xff; i++) { |
| 331 | outw(i << 8, IE_GP); /* Point GP at packet size to be tested */ |
| 332 | outb(i, IE_RBUF); |
| 333 | outw(0x0, IE_GP); /* Point GP at start of packet */ |
| 334 | data = inb(IE_RBUF); |
| 335 | if (data == i) break; |
| 336 | } |
| 337 | bufsize_rcv = i << 8; |
| 338 | outw(0, IE_GP); /* Point GP at start of packet */ |
| 339 | outb(0, IE_RBUF); /* set buffer byte 0 to 0 again */ |
| 340 | } |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 341 | printk("-> bufsize rcv/xmt=%d/%d\n", bufsize_rcv, NI5010_BUFSIZE); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 342 | |
Alexander Beregalov | 79f1bc0 | 2009-03-28 23:37:27 -0700 | [diff] [blame] | 343 | dev->netdev_ops = &ni5010_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | dev->watchdog_timeo = HZ/20; |
| 345 | |
| 346 | dev->flags &= ~IFF_MULTICAST; /* Multicast doesn't work */ |
| 347 | |
| 348 | /* Shut up the ni5010 */ |
| 349 | outb(0, EDLC_RMASK); /* Mask all receive interrupts */ |
| 350 | outb(0, EDLC_XMASK); /* Mask all xmit interrupts */ |
| 351 | outb(0xff, EDLC_RCLR); /* Kill all pending rcv interrupts */ |
| 352 | outb(0xff, EDLC_XCLR); /* Kill all pending xmt interrupts */ |
| 353 | |
| 354 | 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] | 355 | if (dev->dma) |
| 356 | printk(" & DMA %d", dev->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | printk(".\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | return 0; |
| 359 | out: |
| 360 | release_region(dev->base_addr, NI5010_IO_EXTENT); |
| 361 | return err; |
| 362 | } |
| 363 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 364 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | * Open/initialize the board. This is called (in the current kernel) |
| 366 | * sometime after booting when the 'ifconfig' program is run. |
| 367 | * |
| 368 | * This routine should set everything up anew at each open, even |
| 369 | * 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] | 370 | * there is a non-reboot way to recover if something goes wrong. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | static int ni5010_open(struct net_device *dev) |
| 374 | { |
| 375 | int ioaddr = dev->base_addr; |
| 376 | int i; |
| 377 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 378 | PRINTK2((KERN_DEBUG "%s: entering ni5010_open()\n", dev->name)); |
| 379 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 380 | if (request_irq(dev->irq, ni5010_interrupt, 0, boardname, dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | printk(KERN_WARNING "%s: Cannot get irq %#2x\n", dev->name, dev->irq); |
| 382 | return -EAGAIN; |
| 383 | } |
| 384 | PRINTK3((KERN_DEBUG "%s: passed open() #1\n", dev->name)); |
| 385 | /* |
| 386 | * Always allocate the DMA channel after the IRQ, |
| 387 | * and clean up on failure. |
| 388 | */ |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 389 | #ifdef JUMPERED_DMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | if (request_dma(dev->dma, cardname)) { |
| 391 | printk(KERN_WARNING "%s: Cannot get dma %#2x\n", dev->name, dev->dma); |
| 392 | free_irq(dev->irq, NULL); |
| 393 | return -EAGAIN; |
| 394 | } |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 395 | #endif /* JUMPERED_DMA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | PRINTK3((KERN_DEBUG "%s: passed open() #2\n", dev->name)); |
| 398 | /* Reset the hardware here. Don't forget to set the station address. */ |
| 399 | |
| 400 | outb(RS_RESET, EDLC_RESET); /* Hold up EDLC_RESET while configing board */ |
| 401 | outb(0, IE_RESET); /* Hardware reset of ni5010 board */ |
| 402 | outb(XMD_LBC, EDLC_XMODE); /* Only loopback xmits */ |
| 403 | |
| 404 | PRINTK3((KERN_DEBUG "%s: passed open() #3\n", dev->name)); |
| 405 | /* Set the station address */ |
| 406 | for(i = 0;i < 6; i++) { |
| 407 | outb(dev->dev_addr[i], EDLC_ADDR + i); |
| 408 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 409 | |
| 410 | PRINTK3((KERN_DEBUG "%s: Initialising ni5010\n", dev->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | outb(0, EDLC_XMASK); /* No xmit interrupts for now */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 412 | outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | /* Normal packet xmit mode */ |
| 414 | outb(0xff, EDLC_XCLR); /* Clear all pending xmit interrupts */ |
| 415 | outb(RMD_BROADCAST, EDLC_RMODE); |
| 416 | /* Receive broadcast and normal packets */ |
| 417 | reset_receiver(dev); /* Ready ni5010 for receiving packets */ |
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 | outb(0, EDLC_RESET); /* Un-reset the ni5010 */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | netif_start_queue(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 422 | |
| 423 | if (NI5010_DEBUG) ni5010_show_registers(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
| 425 | PRINTK((KERN_DEBUG "%s: open successful\n", dev->name)); |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static void reset_receiver(struct net_device *dev) |
| 430 | { |
| 431 | int ioaddr = dev->base_addr; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | PRINTK3((KERN_DEBUG "%s: resetting receiver\n", dev->name)); |
| 434 | outw(0, IE_GP); /* Receive packet at start of buffer */ |
| 435 | outb(0xff, EDLC_RCLR); /* Clear all pending rcv interrupts */ |
| 436 | outb(0, IE_MMODE); /* Put EDLC to rcv buffer */ |
| 437 | outb(MM_EN_RCV, IE_MMODE); /* Enable rcv */ |
| 438 | outb(0xff, EDLC_RMASK); /* Enable all rcv interrupts */ |
| 439 | } |
| 440 | |
| 441 | static void ni5010_timeout(struct net_device *dev) |
| 442 | { |
| 443 | printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name, |
| 444 | tx_done(dev) ? "IRQ conflict" : "network cable problem"); |
| 445 | /* Try to restart the adaptor. */ |
| 446 | /* FIXME: Give it a real kick here */ |
| 447 | chipset_init(dev, 1); |
| 448 | dev->trans_start = jiffies; |
| 449 | netif_wake_queue(dev); |
| 450 | } |
| 451 | |
| 452 | static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 453 | { |
| 454 | int length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; |
| 455 | |
| 456 | PRINTK2((KERN_DEBUG "%s: entering ni5010_send_packet\n", dev->name)); |
| 457 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 458 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | * Block sending |
| 460 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | netif_stop_queue(dev); |
| 463 | hardware_send_packet(dev, (unsigned char *)skb->data, skb->len, length-skb->len); |
| 464 | dev->trans_start = jiffies; |
| 465 | dev_kfree_skb (skb); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 466 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 469 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | * The typical workload of the driver: |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 471 | * Handle the network interface interrupts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 473 | static irqreturn_t ni5010_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
| 475 | struct net_device *dev = dev_id; |
| 476 | struct ni5010_local *lp; |
| 477 | int ioaddr, status; |
| 478 | int xmit_was_error = 0; |
| 479 | |
| 480 | PRINTK2((KERN_DEBUG "%s: entering ni5010_interrupt\n", dev->name)); |
| 481 | |
| 482 | ioaddr = dev->base_addr; |
| 483 | lp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | spin_lock(&lp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 486 | status = inb(IE_ISTAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | PRINTK3((KERN_DEBUG "%s: IE_ISTAT = %#02x\n", dev->name, status)); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | if ((status & IS_R_INT) == 0) ni5010_rx(dev); |
| 490 | |
| 491 | if ((status & IS_X_INT) == 0) { |
| 492 | xmit_was_error = process_xmt_interrupt(dev); |
| 493 | } |
| 494 | |
| 495 | if ((status & IS_DMA_INT) == 0) { |
| 496 | PRINTK((KERN_DEBUG "%s: DMA complete (?)\n", dev->name)); |
| 497 | outb(0, IE_DMA_RST); /* Reset DMA int */ |
| 498 | } |
| 499 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 500 | if (!xmit_was_error) |
| 501 | reset_receiver(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | spin_unlock(&lp->lock); |
| 503 | return IRQ_HANDLED; |
| 504 | } |
| 505 | |
| 506 | |
| 507 | static void dump_packet(void *buf, int len) |
| 508 | { |
| 509 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | printk(KERN_DEBUG "Packet length = %#4x\n", len); |
| 512 | for (i = 0; i < len; i++){ |
| 513 | if (i % 16 == 0) printk(KERN_DEBUG "%#4.4x", i); |
| 514 | if (i % 2 == 0) printk(" "); |
| 515 | printk("%2.2x", ((unsigned char *)buf)[i]); |
| 516 | if (i % 16 == 15) printk("\n"); |
| 517 | } |
| 518 | printk("\n"); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | return; |
| 521 | } |
| 522 | |
| 523 | /* We have a good packet, get it out of the buffer. */ |
| 524 | static void ni5010_rx(struct net_device *dev) |
| 525 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | int ioaddr = dev->base_addr; |
| 527 | unsigned char rcv_stat; |
| 528 | struct sk_buff *skb; |
| 529 | int i_pkt_size; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 530 | |
| 531 | PRINTK2((KERN_DEBUG "%s: entering ni5010_rx()\n", dev->name)); |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | rcv_stat = inb(EDLC_RSTAT); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 534 | PRINTK3((KERN_DEBUG "%s: EDLC_RSTAT = %#2x\n", dev->name, rcv_stat)); |
| 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | if ( (rcv_stat & RS_VALID_BITS) != RS_PKT_OK) { |
| 537 | PRINTK((KERN_INFO "%s: receive error.\n", dev->name)); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 538 | dev->stats.rx_errors++; |
| 539 | if (rcv_stat & RS_RUNT) dev->stats.rx_length_errors++; |
| 540 | if (rcv_stat & RS_ALIGN) dev->stats.rx_frame_errors++; |
| 541 | if (rcv_stat & RS_CRC_ERR) dev->stats.rx_crc_errors++; |
| 542 | if (rcv_stat & RS_OFLW) dev->stats.rx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | outb(0xff, EDLC_RCLR); /* Clear the interrupt */ |
| 544 | return; |
| 545 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | outb(0xff, EDLC_RCLR); /* Clear the interrupt */ |
| 548 | |
| 549 | i_pkt_size = inw(IE_RCNT); |
| 550 | if (i_pkt_size > ETH_FRAME_LEN || i_pkt_size < 10 ) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 551 | PRINTK((KERN_DEBUG "%s: Packet size error, packet size = %#4.4x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | dev->name, i_pkt_size)); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 553 | dev->stats.rx_errors++; |
| 554 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | return; |
| 556 | } |
| 557 | |
| 558 | /* Malloc up new buffer. */ |
| 559 | skb = dev_alloc_skb(i_pkt_size + 3); |
| 560 | if (skb == NULL) { |
| 561 | printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 562 | dev->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return; |
| 564 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 578 | dev->stats.rx_packets++; |
| 579 | dev->stats.rx_bytes += i_pkt_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 581 | PRINTK2((KERN_DEBUG "%s: Received packet, size=%#4.4x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | dev->name, i_pkt_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | static int process_xmt_interrupt(struct net_device *dev) |
| 586 | { |
| 587 | struct ni5010_local *lp = netdev_priv(dev); |
| 588 | int ioaddr = dev->base_addr; |
| 589 | int xmit_stat; |
| 590 | |
| 591 | PRINTK2((KERN_DEBUG "%s: entering process_xmt_interrupt\n", dev->name)); |
| 592 | |
| 593 | xmit_stat = inb(EDLC_XSTAT); |
| 594 | 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] | 595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | outb(0, EDLC_XMASK); /* Disable xmit IRQ's */ |
| 597 | outb(0xff, EDLC_XCLR); /* Clear all pending xmit IRQ's */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | if (xmit_stat & XS_COLL){ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 600 | PRINTK((KERN_DEBUG "%s: collision detected, retransmitting\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | dev->name)); |
| 602 | outw(NI5010_BUFSIZE - lp->o_pkt_size, IE_GP); |
| 603 | /* outb(0, IE_MMODE); */ /* xmt buf on sysbus FIXME: needed ? */ |
| 604 | outb(MM_EN_XMT | MM_MUX, IE_MMODE); |
| 605 | outb(XM_ALL, EDLC_XMASK); /* Enable xmt IRQ's */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 606 | dev->stats.collisions++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | return 1; |
| 608 | } |
| 609 | |
| 610 | /* FIXME: handle other xmt error conditions */ |
| 611 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 612 | dev->stats.tx_packets++; |
| 613 | dev->stats.tx_bytes += lp->o_pkt_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | netif_wake_queue(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 615 | |
| 616 | PRINTK2((KERN_DEBUG "%s: sent packet, size=%#4.4x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | dev->name, lp->o_pkt_size)); |
| 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | /* The inverse routine to ni5010_open(). */ |
| 623 | static int ni5010_close(struct net_device *dev) |
| 624 | { |
| 625 | int ioaddr = dev->base_addr; |
| 626 | |
| 627 | PRINTK2((KERN_DEBUG "%s: entering ni5010_close\n", dev->name)); |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 628 | #ifdef JUMPERED_INTERRUPTS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | free_irq(dev->irq, NULL); |
| 630 | #endif |
| 631 | /* Put card in held-RESET state */ |
| 632 | outb(0, IE_MMODE); |
| 633 | outb(RS_RESET, EDLC_RESET); |
| 634 | |
| 635 | netif_stop_queue(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | PRINTK((KERN_DEBUG "%s: %s closed down\n", dev->name, boardname)); |
| 638 | return 0; |
| 639 | |
| 640 | } |
| 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | /* Set or clear the multicast filter for this adaptor. |
| 643 | num_addrs == -1 Promiscuous mode, receive all packets |
| 644 | num_addrs == 0 Normal mode, clear multicast list |
| 645 | num_addrs > 0 Multicast mode, receive normal and MC packets, and do |
| 646 | best-effort filtering. |
| 647 | */ |
| 648 | static void ni5010_set_multicast_list(struct net_device *dev) |
| 649 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 650 | short ioaddr = dev->base_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
| 652 | PRINTK2((KERN_DEBUG "%s: entering set_multicast_list\n", dev->name)); |
| 653 | |
Jiri Pirko | f9dcbcc | 2010-02-23 09:19:49 +0000 | [diff] [blame] | 654 | if (dev->flags & IFF_PROMISC || dev->flags & IFF_ALLMULTI || |
| 655 | !netdev_mc_empty(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | outb(RMD_PROMISC, EDLC_RMODE); /* Enable promiscuous mode */ |
| 657 | PRINTK((KERN_DEBUG "%s: Entering promiscuous mode\n", dev->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } else { |
| 659 | PRINTK((KERN_DEBUG "%s: Entering broadcast mode\n", dev->name)); |
| 660 | outb(RMD_BROADCAST, EDLC_RMODE); /* Disable promiscuous mode, use normal mode */ |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | static void hardware_send_packet(struct net_device *dev, char *buf, int length, int pad) |
| 665 | { |
| 666 | struct ni5010_local *lp = netdev_priv(dev); |
| 667 | int ioaddr = dev->base_addr; |
| 668 | unsigned long flags; |
| 669 | unsigned int buf_offs; |
| 670 | |
| 671 | PRINTK2((KERN_DEBUG "%s: entering hardware_send_packet\n", dev->name)); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | if (length > ETH_FRAME_LEN) { |
| 674 | PRINTK((KERN_WARNING "%s: packet too large, not possible\n", |
| 675 | dev->name)); |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | if (NI5010_DEBUG) ni5010_show_registers(dev); |
| 680 | |
| 681 | if (inb(IE_ISTAT) & IS_EN_XMT) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 682 | PRINTK((KERN_WARNING "%s: sending packet while already transmitting, not possible\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | dev->name)); |
| 684 | return; |
| 685 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | if (NI5010_DEBUG > 3) dump_packet(buf, length); |
| 688 | |
| 689 | buf_offs = NI5010_BUFSIZE - length - pad; |
| 690 | |
| 691 | spin_lock_irqsave(&lp->lock, flags); |
| 692 | lp->o_pkt_size = length + pad; |
| 693 | |
| 694 | outb(0, EDLC_RMASK); /* Mask all receive interrupts */ |
| 695 | outb(0, IE_MMODE); /* Put Xmit buffer on system bus */ |
| 696 | outb(0xff, EDLC_RCLR); /* Clear out pending rcv interrupts */ |
| 697 | |
| 698 | outw(buf_offs, IE_GP); /* Point GP at start of packet */ |
| 699 | outsb(IE_XBUF, buf, length); /* Put data in buffer */ |
| 700 | while(pad--) |
| 701 | outb(0, IE_XBUF); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | outw(buf_offs, IE_GP); /* Rewrite where packet starts */ |
| 704 | |
| 705 | /* should work without that outb() (Crynwr used it) */ |
| 706 | /*outb(MM_MUX, IE_MMODE);*/ /* Xmt buffer to EDLC bus */ |
| 707 | outb(MM_EN_XMT | MM_MUX, IE_MMODE); /* Begin transmission */ |
| 708 | outb(XM_ALL, EDLC_XMASK); /* Cause interrupt after completion or fail */ |
| 709 | |
| 710 | spin_unlock_irqrestore(&lp->lock, flags); |
| 711 | |
| 712 | netif_wake_queue(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 713 | |
| 714 | if (NI5010_DEBUG) ni5010_show_registers(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static void chipset_init(struct net_device *dev, int startp) |
| 718 | { |
| 719 | /* FIXME: Move some stuff here */ |
| 720 | PRINTK3((KERN_DEBUG "%s: doing NOTHING in chipset_init\n", dev->name)); |
| 721 | } |
| 722 | |
| 723 | static void ni5010_show_registers(struct net_device *dev) |
| 724 | { |
| 725 | int ioaddr = dev->base_addr; |
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 | PRINTK3((KERN_DEBUG "%s: XSTAT %#2.2x\n", dev->name, inb(EDLC_XSTAT))); |
| 728 | PRINTK3((KERN_DEBUG "%s: XMASK %#2.2x\n", dev->name, inb(EDLC_XMASK))); |
| 729 | PRINTK3((KERN_DEBUG "%s: RSTAT %#2.2x\n", dev->name, inb(EDLC_RSTAT))); |
| 730 | PRINTK3((KERN_DEBUG "%s: RMASK %#2.2x\n", dev->name, inb(EDLC_RMASK))); |
| 731 | PRINTK3((KERN_DEBUG "%s: RMODE %#2.2x\n", dev->name, inb(EDLC_RMODE))); |
| 732 | PRINTK3((KERN_DEBUG "%s: XMODE %#2.2x\n", dev->name, inb(EDLC_XMODE))); |
| 733 | PRINTK3((KERN_DEBUG "%s: ISTAT %#2.2x\n", dev->name, inb(IE_ISTAT))); |
| 734 | } |
| 735 | |
| 736 | #ifdef MODULE |
| 737 | static struct net_device *dev_ni5010; |
| 738 | |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 739 | module_param(io, int, 0); |
| 740 | module_param(irq, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | MODULE_PARM_DESC(io, "ni5010 I/O base address"); |
| 742 | MODULE_PARM_DESC(irq, "ni5010 IRQ number"); |
| 743 | |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 744 | static int __init ni5010_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | { |
| 746 | PRINTK2((KERN_DEBUG "%s: entering init_module\n", boardname)); |
| 747 | /* |
| 748 | if(io <= 0 || irq == 0){ |
| 749 | printk(KERN_WARNING "%s: Autoprobing not allowed for modules.\n", boardname); |
| 750 | printk(KERN_WARNING "%s: Set symbols 'io' and 'irq'\n", boardname); |
| 751 | return -EINVAL; |
| 752 | } |
| 753 | */ |
| 754 | if (io <= 0){ |
| 755 | printk(KERN_WARNING "%s: Autoprobing for modules is hazardous, trying anyway..\n", boardname); |
| 756 | } |
| 757 | |
| 758 | PRINTK2((KERN_DEBUG "%s: init_module irq=%#2x, io=%#3x\n", boardname, irq, io)); |
| 759 | dev_ni5010 = ni5010_probe(-1); |
| 760 | if (IS_ERR(dev_ni5010)) |
| 761 | return PTR_ERR(dev_ni5010); |
| 762 | return 0; |
| 763 | } |
| 764 | |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 765 | static void __exit ni5010_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | { |
| 767 | PRINTK2((KERN_DEBUG "%s: entering cleanup_module\n", boardname)); |
| 768 | unregister_netdev(dev_ni5010); |
| 769 | release_region(dev_ni5010->base_addr, NI5010_IO_EXTENT); |
| 770 | free_netdev(dev_ni5010); |
| 771 | } |
Andreas Mohr | 5b552b1 | 2006-06-30 02:25:07 -0700 | [diff] [blame] | 772 | module_init(ni5010_init_module); |
| 773 | module_exit(ni5010_cleanup_module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | #endif /* MODULE */ |
| 775 | MODULE_LICENSE("GPL"); |