* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / net / ni5010.c
blob5df1c9ffac195dc8146146f172c307b302e714f7
1 /* ni5010.c: A network driver for the MiCom-Interlan NI5010 ethercard.
3 * Copyright 1996,1997 Jan-Pascal van Best and Andreas Mohr.
5 * This software may be used and distributed according to the terms
6 * of the GNU Public License, incorporated herein by reference.
8 * The authors may be reached as:
9 * jvbest@wi.leidenuniv.nl a.mohr@mailto.de
10 * or by snail mail as
11 * Jan-Pascal van Best Andreas Mohr
12 * Klikspaanweg 58-4 Stauferstr. 6
13 * 2324 LZ Leiden D-71272 Renningen
14 * The Netherlands Germany
16 * Sources:
17 * Donald Becker's "skeleton.c"
18 * Crynwr ni5010 packet driver
20 * Changes:
21 * v0.0: First test version
22 * v0.1: First working version
23 * v0.2:
24 * v0.3->v0.90: Now demand setting io and irq when loading as module
25 * 970430 v0.91: modified for Linux 2.1.14
26 * v0.92: Implemented Andreas' (better) NI5010 probe
27 * 970503 v0.93: Fixed auto-irq failure on warm reboot (JB)
28 * 970623 v1.00: First kernel version (AM)
29 * 970814 v1.01: Added detection of onboard receive buffer size (AM)
30 * Bugs:
31 * - None known...
32 * - Note that you have to patch ifconfig for the new /proc/net/dev
33 * format. It gives incorrect stats otherwise.
35 * To do:
36 * Fix all bugs :-)
37 * Move some stuff to chipset_init()
38 * Handle xmt errors other than collisions
39 * Complete merge with Andreas' driver
40 * Implement ring buffers (Is this useful? You can't squeeze
41 * too many packet in a 2k buffer!)
42 * Implement DMA (Again, is this useful? Some docs says DMA is
43 * slower than programmed I/O)
45 * Compile with:
46 * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ \
47 * -DMODULE -c ni5010.c
49 * Insert with e.g.:
50 * insmod ni5010.o io=0x300 irq=5
53 #include <linux/module.h>
54 #include <linux/kernel.h>
55 #include <linux/string.h>
56 #include <linux/errno.h>
57 #include <linux/ioport.h>
58 #include <linux/malloc.h>
59 #include <linux/interrupt.h>
60 #include <linux/delay.h>
61 #include <linux/init.h>
62 #include <asm/bitops.h>
63 #include <asm/io.h>
64 #include <asm/dma.h>
66 #include <linux/netdevice.h>
67 #include <linux/etherdevice.h>
68 #include <linux/skbuff.h>
70 #include "ni5010.h"
72 static const char *boardname = "NI5010";
73 static char *version =
74 "ni5010.c: v1.00 06/23/97 Jan-Pascal van Best and Andreas Mohr\n";
76 /* bufsize_rcv == 0 means autoprobing */
77 unsigned int bufsize_rcv = 0;
79 #define jumpered_interrupts /* IRQ line jumpered on board */
80 #undef jumpered_dma /* No DMA used */
81 #undef FULL_IODETECT /* Only detect in portlist */
83 #ifndef FULL_IODETECT
84 /* A zero-terminated list of I/O addresses to be probed. */
85 static unsigned int ni5010_portlist[] __initdata =
86 { 0x300, 0x320, 0x340, 0x360, 0x380, 0x3a0, 0 };
87 #endif
89 /* Use 0 for production, 1 for verification, >2 for debug */
90 #ifndef NI5010_DEBUG
91 #define NI5010_DEBUG 0
92 #endif
94 /* Information that needs to be kept for each board. */
95 struct ni5010_local {
96 struct net_device_stats stats;
97 int o_pkt_size;
98 int i_pkt_size;
101 /* Index to functions, as function prototypes. */
103 extern int ni5010_probe(struct net_device *dev);
104 static int ni5010_probe1(struct net_device *dev, int ioaddr);
105 static int ni5010_open(struct net_device *dev);
106 static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev);
107 static void ni5010_interrupt(int irq, void *dev_id, struct pt_regs *regs);
108 static void ni5010_rx(struct net_device *dev);
109 static int ni5010_close(struct net_device *dev);
110 static struct net_device_stats *ni5010_get_stats(struct net_device *dev);
111 static void ni5010_set_multicast_list(struct net_device *dev);
112 static void reset_receiver(struct net_device *dev);
114 static int process_xmt_interrupt(struct net_device *dev);
115 #define tx_done(dev) 1
116 extern void hardware_send_packet(struct net_device *dev, char *buf, int length);
117 extern void chipset_init(struct net_device *dev, int startp);
118 static void dump_packet(void *buf, int len);
119 static void show_registers(struct net_device *dev);
122 int __init ni5010_probe(struct net_device *dev)
124 int *port;
126 int base_addr = dev ? dev->base_addr : 0;
128 PRINTK2((KERN_DEBUG "%s: Entering ni5010_probe\n", dev->name));
130 if (base_addr > 0x1ff) /* Check a single specified location. */
131 return ni5010_probe1(dev, base_addr);
132 else if (base_addr != 0) /* Don't probe at all. */
133 return -ENXIO;
135 #ifdef FULL_IODETECT
136 for (int ioaddr=0x200; ioaddr<0x400; ioaddr+=0x20) {
137 if (check_region(ioaddr, NI5010_IO_EXTENT))
138 continue;
139 if (ni5010_probe1(dev, ioaddr) == 0)
140 return 0;
142 #else
143 for (port = ni5010_portlist; *port; port++) {
144 int ioaddr = *port;
145 if (check_region(ioaddr, NI5010_IO_EXTENT))
146 continue;
147 if (ni5010_probe1(dev, ioaddr) == 0)
148 return 0;
150 #endif /* FULL_IODETECT */
151 return -ENODEV;
154 static inline int rd_port(int ioaddr)
156 inb(IE_RBUF);
157 return inb(IE_SAPROM);
160 void __init trigger_irq(int ioaddr)
162 outb(0x00, EDLC_RESET); /* Clear EDLC hold RESET state */
163 outb(0x00, IE_RESET); /* Board reset */
164 outb(0x00, EDLC_XMASK); /* Disable all Xmt interrupts */
165 outb(0x00, EDLC_RMASK); /* Disable all Rcv interrupt */
166 outb(0xff, EDLC_XCLR); /* Clear all pending Xmt interrupts */
167 outb(0xff, EDLC_RCLR); /* Clear all pending Rcv interrupts */
169 * Transmit packet mode: Ignore parity, Power xcvr,
170 * Enable loopback
172 outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE);
173 outb(RMD_BROADCAST, EDLC_RMODE); /* Receive normal&broadcast */
174 outb(XM_ALL, EDLC_XMASK); /* Enable all Xmt interrupts */
175 udelay(50); /* FIXME: Necessary? */
176 outb(MM_EN_XMT|MM_MUX, IE_MMODE); /* Start transmission */
180 * This is the real probe routine. Linux has a history of friendly device
181 * probes on the ISA bus. A good device probes avoids doing writes, and
182 * verifies that the correct device exists and functions.
185 static int __init ni5010_probe1(struct net_device *dev, int ioaddr)
187 static unsigned version_printed = 0;
188 int i;
189 unsigned int data;
190 int boguscount = 40;
193 * This is no "official" probe method, I've rather tested which
194 * probe works best with my seven NI5010 cards
195 * (they have very different serial numbers)
196 * Suggestions or failure reports are very, very welcome !
197 * But I think it is a relatively good probe method
198 * since it doesn't use any "outb"
199 * It should be nearly 100% reliable !
200 * well-known WARNING: this probe method (like many others)
201 * will hang the system if a NE2000 card region is probed !
203 * - Andreas
206 PRINTK2((KERN_DEBUG "%s: entering ni5010_probe1(%#3x)\n",
207 dev->name, ioaddr));
209 if (inb(ioaddr+0) == 0xff) return -ENODEV;
211 while ( (rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr) &
212 rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr)) != 0xff)
214 if (boguscount-- == 0) return -ENODEV;
217 PRINTK2((KERN_DEBUG "%s: I/O #1 passed!\n", dev->name));
219 for (i=0; i<32; i++)
220 if ( (data = rd_port(ioaddr)) != 0xff) break;
221 if (data==0xff) return -ENODEV;
223 PRINTK2((KERN_DEBUG "%s: I/O #2 passed!\n", dev->name));
225 if ( (data == SA_ADDR0) &&
226 (rd_port(ioaddr) == SA_ADDR1) &&
227 (rd_port(ioaddr) == SA_ADDR2) ) {
228 for (i=0; i<4; i++) rd_port(ioaddr);
229 if ( (rd_port(ioaddr) != NI5010_MAGICVAL1) ||
230 (rd_port(ioaddr) != NI5010_MAGICVAL2) ) {
231 return -ENODEV;
233 } else return -ENODEV;
235 PRINTK2((KERN_DEBUG "%s: I/O #3 passed!\n", dev->name));
237 if (dev == NULL) {
238 dev = init_etherdev(0,0);
239 if (dev == NULL) {
240 printk(KERN_WARNING "%s: Failed to allocate device memory\n", boardname);
241 return -ENOMEM;
245 if (NI5010_DEBUG && version_printed++ == 0)
246 printk(KERN_INFO "%s", version);
248 printk("NI5010 ethercard probe at 0x%x: ", ioaddr);
250 dev->base_addr = ioaddr;
252 for (i=0; i<6; i++) {
253 outw(i, IE_GP);
254 printk("%2.2x ", dev->dev_addr[i] = inb(IE_SAPROM));
257 PRINTK2((KERN_DEBUG "%s: I/O #4 passed!\n", dev->name));
259 #ifdef jumpered_interrupts
260 if (dev->irq == 0xff)
262 else if (dev->irq < 2) {
263 PRINTK2((KERN_DEBUG "%s: I/O #5 passed!\n", dev->name));
265 autoirq_setup(0);
266 trigger_irq(ioaddr);
267 dev->irq = autoirq_report(2);
269 PRINTK2((KERN_DEBUG "%s: I/O #6 passed!\n", dev->name));
271 if (dev->irq == 0) {
272 printk(KERN_WARNING "%s: no IRQ found!\n", dev->name);
273 return -EAGAIN;
275 PRINTK2((KERN_DEBUG "%s: I/O #7 passed!\n", dev->name));
276 } else if (dev->irq == 2) {
277 dev->irq = 9;
279 #endif /* jumpered_irq */
280 PRINTK2((KERN_DEBUG "%s: I/O #9 passed!\n", dev->name));
282 /* DMA is not supported (yet?), so no use detecting it */
284 if (dev->priv == NULL) {
285 dev->priv = kmalloc(sizeof(struct ni5010_local), GFP_KERNEL|GFP_DMA);
286 if (dev->priv == NULL) {
287 printk(KERN_WARNING "%s: Failed to allocate private memory\n", dev->name);
288 return -ENOMEM;
292 PRINTK2((KERN_DEBUG "%s: I/O #10 passed!\n", dev->name));
294 /* get the size of the onboard receive buffer
295 * higher addresses than bufsize are wrapped into real buffer
296 * i.e. data for offs. 0x801 is written to 0x1 with a 2K onboard buffer
298 if (!bufsize_rcv) {
299 outb(1, IE_MMODE); /* Put Rcv buffer on system bus */
300 outw(0, IE_GP); /* Point GP at start of packet */
301 outb(0, IE_RBUF); /* set buffer byte 0 to 0 */
302 for (i = 1; i < 0xff; i++) {
303 outw(i << 8, IE_GP); /* Point GP at packet size to be tested */
304 outb(i, IE_RBUF);
305 outw(0x0, IE_GP); /* Point GP at start of packet */
306 data = inb(IE_RBUF);
307 if (data == i) break;
309 bufsize_rcv = i << 8;
310 outw(0, IE_GP); /* Point GP at start of packet */
311 outb(0, IE_RBUF); /* set buffer byte 0 to 0 again */
313 printk("// bufsize rcv/xmt=%d/%d\n", bufsize_rcv, NI5010_BUFSIZE);
314 memset(dev->priv, 0, sizeof(struct ni5010_local));
316 /* Grab the region so we can find another board if autoIRQ fails. */
317 request_region(ioaddr, NI5010_IO_EXTENT, boardname);
319 dev->open = ni5010_open;
320 dev->stop = ni5010_close;
321 dev->hard_start_xmit = ni5010_send_packet;
322 dev->get_stats = ni5010_get_stats;
323 dev->set_multicast_list = &ni5010_set_multicast_list;
325 /* Fill in the fields of the device structure with ethernet values. */
326 ether_setup(dev);
328 dev->tbusy = 0;
329 dev->interrupt = 0;
330 dev->start = 0;
332 dev->flags &= ~IFF_MULTICAST; /* Multicast doesn't work */
334 /* Shut up the ni5010 */
335 outb(0, EDLC_RMASK); /* Mask all receive interrupts */
336 outb(0, EDLC_XMASK); /* Mask all xmit interrupts */
337 outb(0xff, EDLC_RCLR); /* Kill all pending rcv interrupts */
338 outb(0xff, EDLC_XCLR); /* Kill all pending xmt interrupts */
340 printk(KERN_INFO "%s: NI5010 found at 0x%x, using IRQ %d", dev->name, ioaddr, dev->irq);
341 if (dev->dma) printk(" & DMA %d", dev->dma);
342 printk(".\n");
344 printk(KERN_INFO "Join the NI5010 driver development team!\n");
345 printk(KERN_INFO "Mail to a.mohr@mailto.de or jvbest@wi.leidenuniv.nl\n");
346 return 0;
350 * Open/initialize the board. This is called (in the current kernel)
351 * sometime after booting when the 'ifconfig' program is run.
353 * This routine should set everything up anew at each open, even
354 * registers that "should" only need to be set once at boot, so that
355 * there is non-reboot way to recover if something goes wrong.
358 static int ni5010_open(struct net_device *dev)
360 int ioaddr = dev->base_addr;
361 int i;
363 PRINTK2((KERN_DEBUG "%s: entering ni5010_open()\n", dev->name));
365 if (request_irq(dev->irq, &ni5010_interrupt, 0, boardname, dev)) {
366 printk(KERN_WARNING "%s: Cannot get irq %#2x\n", dev->name, dev->irq);
367 return -EAGAIN;
369 PRINTK3((KERN_DEBUG "%s: passed open() #1\n", dev->name));
371 * Always allocate the DMA channel after the IRQ,
372 * and clean up on failure.
374 #ifdef jumpered_dma
375 if (request_dma(dev->dma, cardname)) {
376 printk(KERN_WARNING "%s: Cannot get dma %#2x\n", dev->name, dev->dma);
377 free_irq(dev->irq, NULL);
378 return -EAGAIN;
380 #endif /* jumpered_dma */
382 PRINTK3((KERN_DEBUG "%s: passed open() #2\n", dev->name));
383 /* Reset the hardware here. Don't forget to set the station address. */
385 outb(RS_RESET, EDLC_RESET); /* Hold up EDLC_RESET while configing board */
386 outb(0, IE_RESET); /* Hardware reset of ni5010 board */
387 outb(XMD_LBC, EDLC_XMODE); /* Only loopback xmits */
389 PRINTK3((KERN_DEBUG "%s: passed open() #3\n", dev->name));
390 /* Set the station address */
391 for(i = 0;i < 6; i++) {
392 outb(dev->dev_addr[i], EDLC_ADDR + i);
395 PRINTK3((KERN_DEBUG "%s: Initialising ni5010\n", dev->name));
396 outb(0, EDLC_XMASK); /* No xmit interrupts for now */
397 outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE);
398 /* Normal packet xmit mode */
399 outb(0xff, EDLC_XCLR); /* Clear all pending xmit interrupts */
400 outb(RMD_BROADCAST, EDLC_RMODE);
401 /* Receive broadcast and normal packets */
402 reset_receiver(dev); /* Ready ni5010 for receiving packets */
404 outb(0, EDLC_RESET); /* Un-reset the ni5010 */
406 dev->tbusy = 0;
407 dev->interrupt = 0;
408 dev->start = 1;
410 if (NI5010_DEBUG) show_registers(dev);
412 MOD_INC_USE_COUNT;
413 PRINTK((KERN_DEBUG "%s: open successful\n", dev->name));
414 return 0;
417 static void reset_receiver(struct net_device *dev)
419 int ioaddr = dev->base_addr;
421 PRINTK3((KERN_DEBUG "%s: resetting receiver\n", dev->name));
422 outw(0, IE_GP); /* Receive packet at start of buffer */
423 outb(0xff, EDLC_RCLR); /* Clear all pending rcv interrupts */
424 outb(0, IE_MMODE); /* Put EDLC to rcv buffer */
425 outb(MM_EN_RCV, IE_MMODE); /* Enable rcv */
426 outb(0xff, EDLC_RMASK); /* Enable all rcv interrupts */
429 static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev)
431 PRINTK2((KERN_DEBUG "%s: entering ni5010_send_packet\n", dev->name));
432 if (dev->tbusy) {
434 * If we get here, some higher level has decided we are broken.
435 * There should really be a "kick me" function call instead.
437 int tickssofar = jiffies - dev->trans_start;
438 if (tickssofar < 5)
439 return 1;
440 printk("tbusy\n");
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->tbusy=0;
447 dev->trans_start = jiffies;
451 * Block a timer-based transmit from overlapping. This could better be
452 * done with atomic_swap(1, dev->tbusy), but test_and_set_bit() works as well.
454 if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
455 printk(KERN_WARNING "%s: Transmitter access conflict.\n", dev->name);
456 return 1;
457 } else {
458 int length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
460 hardware_send_packet(dev, (unsigned char *)skb->data, length);
461 dev->trans_start = jiffies;
463 dev_kfree_skb (skb);
465 return 0;
469 * The typical workload of the driver:
470 * Handle the network interface interrupts.
472 static void
473 ni5010_interrupt(int irq, void *dev_id, struct pt_regs *regs)
475 struct net_device *dev = dev_id;
476 struct ni5010_local *lp;
477 int ioaddr, status;
478 int xmit_was_error = 0;
480 if (dev == NULL || dev->irq != irq) {
481 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
482 boardname, irq);
483 return;
486 if (dev->interrupt) printk(KERN_WARNING "%s: Reentering IRQ-handler!\n", dev->name);
487 dev->interrupt = 1;
489 PRINTK2((KERN_DEBUG "%s: entering ni5010_interrupt\n", dev->name));
491 ioaddr = dev->base_addr;
492 lp = (struct ni5010_local *)dev->priv;
494 status = inb(IE_ISTAT);
495 PRINTK3((KERN_DEBUG "%s: IE_ISTAT = %#02x\n", dev->name, status));
497 if ((status & IS_R_INT) == 0) ni5010_rx(dev);
499 if ((status & IS_X_INT) == 0) {
500 xmit_was_error = process_xmt_interrupt(dev);
503 if ((status & IS_DMA_INT) == 0) {
504 PRINTK((KERN_DEBUG "%s: DMA complete (???)\n", dev->name));
505 outb(0, IE_DMA_RST); /* Reset DMA int */
508 if (!xmit_was_error)
509 reset_receiver(dev);
511 dev->interrupt = 0;
512 return;
516 static void dump_packet(void *buf, int len)
518 int i;
520 printk(KERN_DEBUG "Packet length = %#4x\n", len);
521 for (i = 0; i < len; i++){
522 if (i % 16 == 0) printk(KERN_DEBUG "%#4.4x", i);
523 if (i % 2 == 0) printk(" ");
524 printk("%2.2x", ((unsigned char *)buf)[i]);
525 if (i % 16 == 15) printk("\n");
527 printk("\n");
529 return;
532 /* We have a good packet, get it out of the buffer. */
533 static void
534 ni5010_rx(struct net_device *dev)
536 struct ni5010_local *lp = (struct ni5010_local *)dev->priv;
537 int ioaddr = dev->base_addr;
538 unsigned char rcv_stat;
539 struct sk_buff *skb;
541 PRINTK2((KERN_DEBUG "%s: entering ni5010_rx()\n", dev->name));
543 rcv_stat = inb(EDLC_RSTAT);
544 PRINTK3((KERN_DEBUG "%s: EDLC_RSTAT = %#2x\n", dev->name, rcv_stat));
546 if ( (rcv_stat & RS_VALID_BITS) != RS_PKT_OK) {
547 PRINTK((KERN_INFO "%s: receive error.\n", dev->name));
548 lp->stats.rx_errors++;
549 if (rcv_stat & RS_RUNT) lp->stats.rx_length_errors++;
550 if (rcv_stat & RS_ALIGN) lp->stats.rx_frame_errors++;
551 if (rcv_stat & RS_CRC_ERR) lp->stats.rx_crc_errors++;
552 if (rcv_stat & RS_OFLW) lp->stats.rx_fifo_errors++;
553 outb(0xff, EDLC_RCLR); /* Clear the interrupt */
554 return;
557 outb(0xff, EDLC_RCLR); /* Clear the interrupt */
559 lp->i_pkt_size = inw(IE_RCNT);
560 if (lp->i_pkt_size > ETH_FRAME_LEN || lp->i_pkt_size < 10 ) {
561 PRINTK((KERN_DEBUG "%s: Packet size error, packet size = %#4.4x\n",
562 dev->name, lp->i_pkt_size));
563 lp->stats.rx_errors++;
564 lp->stats.rx_length_errors++;
565 return;
568 /* Malloc up new buffer. */
569 skb = dev_alloc_skb(lp->i_pkt_size + 3);
570 if (skb == NULL) {
571 printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
572 lp->stats.rx_dropped++;
573 return;
576 skb->dev = dev;
577 skb_reserve(skb, 2);
579 /* Read packet into buffer */
580 outb(MM_MUX, IE_MMODE); /* Rcv buffer to system bus */
581 outw(0, IE_GP); /* Seek to beginning of packet */
582 insb(IE_RBUF, skb_put(skb, lp->i_pkt_size), lp->i_pkt_size);
584 if (NI5010_DEBUG >= 4)
585 dump_packet(skb->data, skb->len);
587 skb->protocol = eth_type_trans(skb,dev);
588 netif_rx(skb);
589 lp->stats.rx_packets++;
590 lp->stats.rx_bytes += lp->i_pkt_size;
592 PRINTK2((KERN_DEBUG "%s: Received packet, size=%#4.4x\n",
593 dev->name, lp->i_pkt_size));
597 static int process_xmt_interrupt(struct net_device *dev)
599 struct ni5010_local *lp = (struct ni5010_local *)dev->priv;
600 int ioaddr = dev->base_addr;
601 int xmit_stat;
603 PRINTK2((KERN_DEBUG "%s: entering process_xmt_interrupt\n", dev->name));
605 xmit_stat = inb(EDLC_XSTAT);
606 PRINTK3((KERN_DEBUG "%s: EDLC_XSTAT = %2.2x\n", dev->name, xmit_stat));
608 outb(0, EDLC_XMASK); /* Disable xmit IRQ's */
609 outb(0xff, EDLC_XCLR); /* Clear all pending xmit IRQ's */
611 if (xmit_stat & XS_COLL){
612 printk("ether collision\n"); /* FIXME: remove */
613 PRINTK((KERN_DEBUG "%s: collision detected, retransmitting\n",
614 dev->name));
615 outw(NI5010_BUFSIZE - lp->o_pkt_size, IE_GP);
616 /* outb(0, IE_MMODE); */ /* xmt buf on sysbus FIXME: needed ? */
617 outb(MM_EN_XMT | MM_MUX, IE_MMODE);
618 outb(XM_ALL, EDLC_XMASK); /* Enable xmt IRQ's */
619 lp->stats.collisions++;
620 return 1;
623 /* FIXME: handle other xmt error conditions */
625 lp->stats.tx_packets++;
626 lp->stats.tx_bytes += lp->o_pkt_size;
627 dev->tbusy = 0;
628 mark_bh(NET_BH); /* Inform upper layers. */
630 PRINTK2((KERN_DEBUG "%s: sent packet, size=%#4.4x\n",
631 dev->name, lp->o_pkt_size));
633 return 0;
636 /* The inverse routine to ni5010_open(). */
637 static int
638 ni5010_close(struct net_device *dev)
640 int ioaddr = dev->base_addr;
642 PRINTK2((KERN_DEBUG "%s: entering ni5010_close\n", dev->name));
643 #ifdef jumpered_interrupts
644 free_irq(dev->irq, NULL);
645 #endif
646 /* Put card in held-RESET state */
647 outb(0, IE_MMODE);
648 outb(RS_RESET, EDLC_RESET);
650 dev->tbusy = 1;
651 dev->start = 0;
653 MOD_DEC_USE_COUNT;
654 PRINTK((KERN_DEBUG "%s: %s closed down\n", dev->name, boardname));
655 return 0;
659 /* Get the current statistics. This may be called with the card open or
660 closed. */
661 static struct net_device_stats *
662 ni5010_get_stats(struct net_device *dev)
664 struct ni5010_local *lp = (struct ni5010_local *)dev->priv;
666 PRINTK2((KERN_DEBUG "%s: entering ni5010_get_stats\n", dev->name));
668 if (NI5010_DEBUG) show_registers(dev);
670 /* cli(); */
671 /* Update the statistics from the device registers. */
672 /* We do this in the interrupt handler */
673 /* sti(); */
675 return &lp->stats;
678 /* Set or clear the multicast filter for this adaptor.
679 num_addrs == -1 Promiscuous mode, receive all packets
680 num_addrs == 0 Normal mode, clear multicast list
681 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
682 best-effort filtering.
684 static void
685 ni5010_set_multicast_list(struct net_device *dev)
687 short ioaddr = dev->base_addr;
689 PRINTK2((KERN_DEBUG "%s: entering set_multicast_list\n", dev->name));
691 if (dev->flags&IFF_PROMISC || dev->flags&IFF_ALLMULTI) {
692 dev->flags |= IFF_PROMISC;
693 outb(RMD_PROMISC, EDLC_RMODE); /* Enable promiscuous mode */
694 PRINTK((KERN_DEBUG "%s: Entering promiscuous mode\n", dev->name));
695 } else if (dev->mc_list) {
696 /* Sorry, multicast not supported */
697 PRINTK((KERN_DEBUG "%s: No multicast, entering broadcast mode\n", dev->name));
698 outb(RMD_BROADCAST, EDLC_RMODE);
699 } else {
700 PRINTK((KERN_DEBUG "%s: Entering broadcast mode\n", dev->name));
701 outb(RMD_BROADCAST, EDLC_RMODE); /* Disable promiscuous mode, use normal mode */
705 extern void hardware_send_packet(struct net_device *dev, char *buf, int length)
707 struct ni5010_local *lp = (struct ni5010_local *)dev->priv;
708 int ioaddr = dev->base_addr;
709 unsigned long flags;
710 unsigned int buf_offs;
712 PRINTK2((KERN_DEBUG "%s: entering hardware_send_packet\n", dev->name));
714 if (length > ETH_FRAME_LEN) {
715 PRINTK((KERN_WARNING "%s: packet too large, not possible\n",
716 dev->name));
717 return;
720 if (NI5010_DEBUG) show_registers(dev);
722 if (inb(IE_ISTAT) & IS_EN_XMT) {
723 PRINTK((KERN_WARNING "%s: sending packet while already transmitting, not possible\n",
724 dev->name));
725 return;
728 if (NI5010_DEBUG > 3) dump_packet(buf, length);
730 buf_offs = NI5010_BUFSIZE - length;
731 lp->o_pkt_size = length;
733 save_flags(flags);
734 cli();
736 outb(0, EDLC_RMASK); /* Mask all receive interrupts */
737 outb(0, IE_MMODE); /* Put Xmit buffer on system bus */
738 outb(0xff, EDLC_RCLR); /* Clear out pending rcv interrupts */
740 outw(buf_offs, IE_GP); /* Point GP at start of packet */
741 outsb(IE_XBUF, buf, length); /* Put data in buffer */
742 outw(buf_offs, IE_GP); /* Rewrite where packet starts */
744 /* should work without that outb() (Crynwr used it) */
745 /*outb(MM_MUX, IE_MMODE);*/ /* Xmt buffer to EDLC bus */
746 outb(MM_EN_XMT | MM_MUX, IE_MMODE); /* Begin transmission */
747 outb(XM_ALL, EDLC_XMASK); /* Cause interrupt after completion or fail */
749 restore_flags(flags);
751 if (NI5010_DEBUG) show_registers(dev);
754 extern void chipset_init(struct net_device *dev, int startp)
756 /* FIXME: Move some stuff here */
757 PRINTK3((KERN_DEBUG "%s: doing NOTHING in chipset_init\n", dev->name));
760 static void show_registers(struct net_device *dev)
762 int ioaddr = dev->base_addr;
764 PRINTK3((KERN_DEBUG "%s: XSTAT %#2.2x\n", dev->name, inb(EDLC_XSTAT)));
765 PRINTK3((KERN_DEBUG "%s: XMASK %#2.2x\n", dev->name, inb(EDLC_XMASK)));
766 PRINTK3((KERN_DEBUG "%s: RSTAT %#2.2x\n", dev->name, inb(EDLC_RSTAT)));
767 PRINTK3((KERN_DEBUG "%s: RMASK %#2.2x\n", dev->name, inb(EDLC_RMASK)));
768 PRINTK3((KERN_DEBUG "%s: RMODE %#2.2x\n", dev->name, inb(EDLC_RMODE)));
769 PRINTK3((KERN_DEBUG "%s: XMODE %#2.2x\n", dev->name, inb(EDLC_XMODE)));
770 PRINTK3((KERN_DEBUG "%s: ISTAT %#2.2x\n", dev->name, inb(IE_ISTAT)));
773 #ifdef MODULE
774 static char devicename[9] = { 0, };
775 static struct net_device dev_ni5010 = {
776 devicename,
777 0, 0, 0, 0,
778 0, 0,
779 0, 0, 0, NULL, ni5010_probe };
781 int io = 0;
782 int irq = 0;
784 MODULE_PARM(io, "i");
785 MODULE_PARM(irq, "i");
787 int init_module(void)
789 int result;
791 PRINTK2((KERN_DEBUG "%s: entering init_module\n", boardname));
793 if(io <= 0 || irq == 0){
794 printk(KERN_WARNING "%s: Autoprobing not allowed for modules.\n", boardname);
795 printk(KERN_WARNING "%s: Set symbols 'io' and 'irq'\n", boardname);
796 return -EINVAL;
799 if (io <= 0){
800 printk(KERN_WARNING "%s: Autoprobing for modules is hazardous, trying anyway..\n", boardname);
803 PRINTK2((KERN_DEBUG "%s: init_module irq=%#2x, io=%#3x\n", boardname, irq, io));
804 dev_ni5010.irq=irq;
805 dev_ni5010.base_addr=io;
806 if ((result = register_netdev(&dev_ni5010)) != 0) {
807 PRINTK((KERN_WARNING "%s: register_netdev returned %d.\n",
808 boardname, result));
809 return -EIO;
811 return 0;
814 void
815 cleanup_module(void)
817 PRINTK2((KERN_DEBUG "%s: entering cleanup_module\n", boardname));
819 unregister_netdev(&dev_ni5010);
821 release_region(dev_ni5010.base_addr, NI5010_IO_EXTENT);
822 if (dev_ni5010.priv != NULL){
823 kfree(dev_ni5010.priv);
824 dev_ni5010.priv = NULL;
827 #endif /* MODULE */
830 * Local variables:
831 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c ni5010.c"
832 * version-control: t
833 * kept-new-versions: 5
834 * tab-width: 4
835 * End: