2 * ni6510 (am7990 'lance' chip) driver for Linux-net-3
3 * BETAcode v0.71 (96/09/29) for 2.0.0 (or later)
4 * copyrights (c) 1994,1995,1996 by M.Hipp
6 * This driver can handle the old ni6510 board and the newer ni6510
7 * EtherBlaster. (probably it also works with every full NE2100
10 * To compile as module, type:
11 * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ -DMODULE -c ni65.c
12 * driver probes: io: 0x360,0x300,0x320,0x340 / dma: 3,5,6,7
14 * This is an extension to the Linux operating system, and is covered by the
15 * same GNU General Public License that covers the Linux-kernel.
17 * comments/bugs/suggestions can be sent to:
19 * email: hippm@informatik.uni-tuebingen.de
22 * some things are from the 'ni6510-packet-driver for dos by Russ Nelson'
23 * and from the original drivers by D.Becker
26 * - on some PCI boards (including my own) the card/board/ISA-bridge has
27 * problems with bus master DMA. This results in lotsa overruns.
28 * It may help to '#define RCV_PARANOIA_CHECK' or try to #undef
29 * the XMT and RCV_VIA_SKB option .. this reduces driver performance.
30 * Or just play with your BIOS options to optimize ISA-DMA access.
31 * Maybe you also wanna play with the LOW_PERFORAMCE and MID_PERFORMANCE
32 * defines -> please report me your experience then
33 * - Harald reported for ASUS SP3G mainboards, that you should use
34 * the 'optimal settings' from the user's manual on page 3-12!
37 * thanx to Jason Sullivan for sending me a ni6510 card!
38 * lot of debug runs with ASUS SP3G Boards (Intel Saturn) by Harald Koenig
40 * simple performance test: (486DX-33/Ni6510-EB receives from 486DX4-100/Ni6510-EB)
41 * average: FTP -> 8384421 bytes received in 8.5 seconds
42 * (no RCV_VIA_SKB,no XMT_VIA_SKB,PARANOIA_CHECK,4 XMIT BUFS, 8 RCV_BUFFS)
43 * peak: FTP -> 8384421 bytes received in 7.5 seconds
44 * (RCV_VIA_SKB,XMT_VIA_SKB,no PARANOIA_CHECK,1(!) XMIT BUF, 16 RCV BUFFS)
48 * 99.Jun.8: added support for /proc/net/dev byte count for xosview (HK)
49 * 96.Sept.29: virt_to_bus stuff added for new memory modell
50 * 96.April.29: Added Harald Koenig's Patches (MH)
51 * 96.April.13: enhanced error handling .. more tests (MH)
52 * 96.April.5/6: a lot of performance tests. Got it stable now (hopefully) (MH)
53 * 96.April.1: (no joke ;) .. added EtherBlaster and Module support (MH)
54 * 96.Feb.19: fixed a few bugs .. cleanups .. tested for 1.3.66 (MH)
55 * hopefully no more 16MB limit
57 * 95.Nov.18: multicast tweaked (AC).
59 * 94.Aug.22: changes in xmit_intr (ack more than one xmitted-packet), ni65_send_packet (p->lock) (MH)
61 * 94.July.16: fixed bugs in recv_skb and skb-alloc stuff (MH)
64 #include <linux/kernel.h>
65 #include <linux/string.h>
66 #include <linux/errno.h>
67 #include <linux/ioport.h>
68 #include <linux/slab.h>
69 #include <linux/interrupt.h>
70 #include <linux/delay.h>
71 #include <linux/init.h>
72 #include <linux/netdevice.h>
73 #include <linux/etherdevice.h>
74 #include <linux/skbuff.h>
75 #include <linux/module.h>
76 #include <linux/bitops.h>
84 * the current setting allows an acceptable performance
85 * for 'RCV_PARANOIA_CHECK' read the 'known problems' part in
86 * the header of this file
87 * 'invert' the defines for max. performance. This may cause DMA problems
88 * on some boards (e.g on my ASUS SP3G)
92 #define RCV_PARANOIA_CHECK
94 #define MID_PERFORMANCE
96 #if defined( LOW_PERFORMANCE )
97 static int isa0=7,isa1=7,csr80=0x0c10;
98 #elif defined( MID_PERFORMANCE )
99 static int isa0=5,isa1=5,csr80=0x2810;
100 #else /* high performance */
101 static int isa0=4,isa1=4,csr80=0x0017;
105 * a few card/vendor specific defines
107 #define NI65_ID0 0x00
108 #define NI65_ID1 0x55
109 #define NI65_EB_ID0 0x52
110 #define NI65_EB_ID1 0x44
111 #define NE2100_ID0 0x57
112 #define NE2100_ID1 0x57
114 #define PORT p->cmdr_addr
117 * buffer configuration
121 #define RMDNUMMASK 0x80000000
124 #define RMDNUMMASK 0x60000000 /* log2(RMDNUM)<<29 */
129 #define TMDNUMMASK 0x00000000
132 #define TMDNUMMASK 0x40000000 /* log2(TMDNUM)<<29 */
135 /* slightly oversized */
136 #define R_BUF_SIZE 1544
137 #define T_BUF_SIZE 1544
140 * lance register defines
142 #define L_DATAREG 0x00
143 #define L_ADDRREG 0x02
145 #define L_CONFIG 0x05
149 * to access the lance/am7990-regs, you have to write
150 * reg-number into L_ADDRREG, then you can access it using L_DATAREG
157 #define INIT_RING_BEFORE_START 0x1
158 #define FULL_RESET_ON_ERROR 0x2
161 #define writereg(val,reg) {outw(reg,PORT+L_ADDRREG);inw(PORT+L_ADDRREG); \
162 outw(val,PORT+L_DATAREG);inw(PORT+L_DATAREG);}
163 #define readreg(reg) (outw(reg,PORT+L_ADDRREG),inw(PORT+L_ADDRREG),\
166 #define writedatareg(val) {outw(val,PORT+L_DATAREG);inw(PORT+L_DATAREG);}
168 #define writedatareg(val) { writereg(val,CSR0); }
171 #define writereg(val,reg) {outw(reg,PORT+L_ADDRREG);outw(val,PORT+L_DATAREG);}
172 #define readreg(reg) (outw(reg,PORT+L_ADDRREG),inw(PORT+L_DATAREG))
173 #define writedatareg(val) { writereg(val,CSR0); }
176 static unsigned char ni_vendor[] = { 0x02,0x07,0x01 };
179 unsigned char id0,id1;
184 unsigned char *vendor_id;
186 unsigned long config;
195 .vendor_id = ni_vendor,
196 .cardname = "ni6510",
206 .vendor_id = ni_vendor,
207 .cardname = "ni6510 EtherBlaster",
218 .cardname = "generic NE2100",
226 struct rmd rmdhead[RMDNUM];
227 struct tmd tmdhead[TMDNUM];
228 struct init_block ib;
232 struct sk_buff *recv_skb[RMDNUM];
234 void *recvbounce[RMDNUM];
237 struct sk_buff *tmd_skb[TMDNUM];
239 void *tmdbounce[TMDNUM];
241 int lock,xmit_queued;
242 struct net_device_stats stats;
247 spinlock_t ring_lock;
250 static int ni65_probe1(struct net_device *dev,int);
251 static irqreturn_t ni65_interrupt(int irq, void * dev_id);
252 static void ni65_recv_intr(struct net_device *dev,int);
253 static void ni65_xmit_intr(struct net_device *dev,int);
254 static int ni65_open(struct net_device *dev);
255 static int ni65_lance_reinit(struct net_device *dev);
256 static void ni65_init_lance(struct priv *p,unsigned char*,int,int);
257 static int ni65_send_packet(struct sk_buff *skb, struct net_device *dev);
258 static void ni65_timeout(struct net_device *dev);
259 static int ni65_close(struct net_device *dev);
260 static int ni65_alloc_buffer(struct net_device *dev);
261 static void ni65_free_buffer(struct priv *p);
262 static struct net_device_stats *ni65_get_stats(struct net_device *);
263 static void set_multicast_list(struct net_device *dev);
265 static int irqtab[] __initdata = { 9,12,15,5 }; /* irq config-translate */
266 static int dmatab[] __initdata = { 0,3,5,6,7 }; /* dma config-translate and autodetect */
268 static int debuglevel = 1;
271 * set 'performance' registers .. we must STOP lance for that
273 static void ni65_set_performance(struct priv *p)
275 writereg(CSR0_STOP | CSR0_CLRALL,CSR0); /* STOP */
277 if( !(cards[p->cardno].config & 0x02) )
280 outw(80,PORT+L_ADDRREG);
281 if(inw(PORT+L_ADDRREG) != 80)
284 writereg( (csr80 & 0x3fff) ,80); /* FIFO watermarks */
285 outw(0,PORT+L_ADDRREG);
286 outw((short)isa0,PORT+L_BUSIF); /* write ISA 0: DMA_R : isa0 * 50ns */
287 outw(1,PORT+L_ADDRREG);
288 outw((short)isa1,PORT+L_BUSIF); /* write ISA 1: DMA_W : isa1 * 50ns */
290 outw(CSR0,PORT+L_ADDRREG); /* switch back to CSR0 */
294 * open interface (up)
296 static int ni65_open(struct net_device *dev)
298 struct priv *p = (struct priv *) dev->priv;
299 int irqval = request_irq(dev->irq, &ni65_interrupt,0,
300 cards[p->cardno].cardname,dev);
302 printk(KERN_ERR "%s: unable to get IRQ %d (irqval=%d).\n",
303 dev->name,dev->irq, irqval);
307 if(ni65_lance_reinit(dev))
309 netif_start_queue(dev);
314 free_irq(dev->irq,dev);
320 * close interface (down)
322 static int ni65_close(struct net_device *dev)
324 struct priv *p = (struct priv *) dev->priv;
326 netif_stop_queue(dev);
328 outw(inw(PORT+L_RESET),PORT+L_RESET); /* that's the hard way */
333 for(i=0;i<TMDNUM;i++)
336 dev_kfree_skb(p->tmd_skb[i]);
337 p->tmd_skb[i] = NULL;
342 free_irq(dev->irq,dev);
346 static void cleanup_card(struct net_device *dev)
348 struct priv *p = (struct priv *) dev->priv;
349 disable_dma(dev->dma);
351 release_region(dev->base_addr, cards[p->cardno].total_size);
355 /* set: io,irq,dma or set it when calling insmod */
361 * Probe The Card (not the lance-chip)
363 struct net_device * __init ni65_probe(int unit)
365 struct net_device *dev = alloc_etherdev(0);
366 static int ports[] = {0x360,0x300,0x320,0x340, 0};
371 return ERR_PTR(-ENOMEM);
374 sprintf(dev->name, "eth%d", unit);
375 netdev_boot_setup_check(dev);
382 if (dev->base_addr > 0x1ff) { /* Check a single specified location. */
383 err = ni65_probe1(dev, dev->base_addr);
384 } else if (dev->base_addr > 0) { /* Don't probe at all. */
387 for (port = ports; *port && ni65_probe1(dev, *port); port++)
395 err = register_netdev(dev);
407 * this is the real card probe ..
409 static int __init ni65_probe1(struct net_device *dev,int ioaddr)
418 for(i=0;i<NUM_CARDS;i++) {
419 if(!request_region(ioaddr, cards[i].total_size, cards[i].cardname))
421 if(cards[i].id_offset >= 0) {
422 if(inb(ioaddr+cards[i].id_offset+0) != cards[i].id0 ||
423 inb(ioaddr+cards[i].id_offset+1) != cards[i].id1) {
424 release_region(ioaddr, cards[i].total_size);
428 if(cards[i].vendor_id) {
430 if(inb(ioaddr+cards[i].addr_offset+j) != cards[i].vendor_id[j]) {
431 release_region(ioaddr, cards[i].total_size);
441 dev->dev_addr[j] = inb(ioaddr+cards[i].addr_offset+j);
443 if( (j=ni65_alloc_buffer(dev)) < 0) {
444 release_region(ioaddr, cards[i].total_size);
447 p = (struct priv *) dev->priv;
448 p->cmdr_addr = ioaddr + cards[i].cmd_offset;
450 spin_lock_init(&p->ring_lock);
452 printk(KERN_INFO "%s: %s found at %#3x, ", dev->name, cards[p->cardno].cardname , ioaddr);
454 outw(inw(PORT+L_RESET),PORT+L_RESET); /* first: reset the card */
455 if( (j=readreg(CSR0)) != 0x4) {
457 printk(KERN_ERR "%s: Can't RESET card: %04x\n", dev->name, j);
459 release_region(ioaddr, cards[p->cardno].total_size);
463 outw(88,PORT+L_ADDRREG);
464 if(inw(PORT+L_ADDRREG) == 88) {
466 v = inw(PORT+L_DATAREG);
468 outw(89,PORT+L_ADDRREG);
469 v |= inw(PORT+L_DATAREG);
470 printk("Version %#08lx, ",v);
471 p->features = INIT_RING_BEFORE_START;
474 printk("ancient LANCE, ");
478 if(test_bit(0,&cards[i].config)) {
479 dev->irq = irqtab[(inw(ioaddr+L_CONFIG)>>2)&3];
480 dev->dma = dmatab[inw(ioaddr+L_CONFIG)&3];
481 printk("IRQ %d (from card), DMA %d (from card).\n",dev->irq,dev->dma);
485 /* 'stuck test' from lance.c */
486 long dma_channels = ((inb(DMA1_STAT_REG) >> 4) & 0x0f) |
487 (inb(DMA2_STAT_REG) & 0xf0);
490 if(test_bit(dma,&dma_channels) || request_dma(dma,"ni6510"))
493 flags=claim_dma_lock();
495 set_dma_mode(dma,DMA_MODE_CASCADE);
497 release_dma_lock(flags);
499 ni65_init_lance(p,dev->dev_addr,0,0); /* trigger memory access */
501 flags=claim_dma_lock();
504 release_dma_lock(flags);
506 if(readreg(CSR0) & CSR0_IDON)
511 printk(KERN_ERR "%s: Can't detect DMA channel!\n", dev->name);
513 release_region(ioaddr, cards[p->cardno].total_size);
516 dev->dma = dmatab[i];
517 printk("DMA %d (autodetected), ",dev->dma);
520 printk("DMA %d (assigned), ",dev->dma);
524 unsigned long irq_mask;
526 ni65_init_lance(p,dev->dev_addr,0,0);
527 irq_mask = probe_irq_on();
528 writereg(CSR0_INIT|CSR0_INEA,CSR0); /* trigger interrupt */
530 dev->irq = probe_irq_off(irq_mask);
533 printk("Failed to detect IRQ line!\n");
535 release_region(ioaddr, cards[p->cardno].total_size);
538 printk("IRQ %d (autodetected).\n",dev->irq);
541 printk("IRQ %d (assigned).\n",dev->irq);
544 if(request_dma(dev->dma, cards[p->cardno].cardname ) != 0)
546 printk(KERN_ERR "%s: Can't request dma-channel %d\n",dev->name,(int) dev->dma);
548 release_region(ioaddr, cards[p->cardno].total_size);
552 dev->base_addr = ioaddr;
553 dev->open = ni65_open;
554 dev->stop = ni65_close;
555 dev->hard_start_xmit = ni65_send_packet;
556 dev->tx_timeout = ni65_timeout;
557 dev->watchdog_timeo = HZ/2;
558 dev->get_stats = ni65_get_stats;
559 dev->set_multicast_list = set_multicast_list;
560 return 0; /* everything is OK */
564 * set lance register and trigger init
566 static void ni65_init_lance(struct priv *p,unsigned char *daddr,int filter,int mode)
571 writereg(CSR0_CLRALL|CSR0_STOP,CSR0);
574 p->ib.eaddr[i] = daddr[i];
577 p->ib.filter[i] = filter;
580 p->ib.trp = (u32) isa_virt_to_bus(p->tmdhead) | TMDNUMMASK;
581 p->ib.rrp = (u32) isa_virt_to_bus(p->rmdhead) | RMDNUMMASK;
582 writereg(0,CSR3); /* busmaster/no word-swap */
583 pib = (u32) isa_virt_to_bus(&p->ib);
584 writereg(pib & 0xffff,CSR1);
585 writereg(pib >> 16,CSR2);
587 writereg(CSR0_INIT,CSR0); /* this changes L_ADDRREG to CSR0 */
592 if(inw(PORT+L_DATAREG) & (CSR0_IDON | CSR0_MERR) )
593 break; /* init ok ? */
598 * allocate memory area and check the 16MB border
600 static void *ni65_alloc_mem(struct net_device *dev,char *what,int size,int type)
602 struct sk_buff *skb=NULL;
607 ret = skb = alloc_skb(2+16+size,GFP_KERNEL|GFP_DMA);
609 printk(KERN_WARNING "%s: unable to allocate %s memory.\n",dev->name,what);
612 skb_reserve(skb,2+16);
613 skb_put(skb,R_BUF_SIZE); /* grab the whole space .. (not necessary) */
617 ret = ptr = kmalloc(T_BUF_SIZE,GFP_KERNEL | GFP_DMA);
619 printk(KERN_WARNING "%s: unable to allocate %s memory.\n",dev->name,what);
623 if( (u32) virt_to_phys(ptr+size) > 0x1000000) {
624 printk(KERN_WARNING "%s: unable to allocate %s memory in lower 16MB!\n",dev->name,what);
635 * allocate all memory structures .. send/recv buffers etc ...
637 static int ni65_alloc_buffer(struct net_device *dev)
644 * we need 8-aligned memory ..
646 ptr = ni65_alloc_mem(dev,"BUFFER",sizeof(struct priv)+8,0);
650 p = dev->priv = (struct priv *) (((unsigned long) ptr + 7) & ~0x7);
651 memset((char *) dev->priv,0,sizeof(struct priv));
654 for(i=0;i<TMDNUM;i++)
657 p->tmd_skb[i] = NULL;
659 p->tmdbounce[i] = ni65_alloc_mem(dev,"XMIT",T_BUF_SIZE,0);
660 if(!p->tmdbounce[i]) {
666 for(i=0;i<RMDNUM;i++)
669 p->recv_skb[i] = ni65_alloc_mem(dev,"RECV",R_BUF_SIZE,1);
670 if(!p->recv_skb[i]) {
675 p->recvbounce[i] = ni65_alloc_mem(dev,"RECV",R_BUF_SIZE,0);
676 if(!p->recvbounce[i]) {
683 return 0; /* everything is OK */
687 * free buffers and private struct
689 static void ni65_free_buffer(struct priv *p)
696 for(i=0;i<TMDNUM;i++) {
697 kfree(p->tmdbounce[i]);
700 dev_kfree_skb(p->tmd_skb[i]);
704 for(i=0;i<RMDNUM;i++)
708 dev_kfree_skb(p->recv_skb[i]);
710 kfree(p->recvbounce[i]);
718 * stop and (re)start lance .. e.g after an error
720 static void ni65_stop_start(struct net_device *dev,struct priv *p)
722 int csr0 = CSR0_INEA;
724 writedatareg(CSR0_STOP);
727 printk(KERN_DEBUG "ni65_stop_start\n");
729 if(p->features & INIT_RING_BEFORE_START) {
732 struct sk_buff *skb_save[TMDNUM];
734 unsigned long buffer[TMDNUM];
739 if((p->tmdhead[p->tmdlast].u.s.status & XMIT_OWN))
741 p->tmdlast = (p->tmdlast + 1) & (TMDNUM-1);
742 if(p->tmdlast == p->tmdnum)
747 for(i=0;i<TMDNUM;i++) {
748 struct tmd *tmdp = p->tmdhead + i;
750 skb_save[i] = p->tmd_skb[i];
752 buffer[i] = (u32) isa_bus_to_virt(tmdp->u.buffer);
753 blen[i] = tmdp->blen;
754 tmdp->u.s.status = 0x0;
757 for(i=0;i<RMDNUM;i++) {
758 struct rmd *rmdp = p->rmdhead + i;
759 rmdp->u.s.status = RCV_OWN;
761 p->tmdnum = p->xmit_queued = 0;
762 writedatareg(CSR0_STRT | csr0);
764 for(i=0;i<TMDNUM;i++) {
765 int num = (i + p->tmdlast) & (TMDNUM-1);
766 p->tmdhead[i].u.buffer = (u32) isa_virt_to_bus((char *)buffer[num]); /* status is part of buffer field */
767 p->tmdhead[i].blen = blen[num];
768 if(p->tmdhead[i].u.s.status & XMIT_OWN) {
769 p->tmdnum = (p->tmdnum + 1) & (TMDNUM-1);
771 writedatareg(CSR0_TDMD | CSR0_INEA | csr0);
774 p->tmd_skb[i] = skb_save[num];
777 p->rmdnum = p->tmdlast = 0;
779 if (p->tmdnum || !p->xmit_queued)
780 netif_wake_queue(dev);
781 dev->trans_start = jiffies;
784 writedatareg(CSR0_STRT | csr0);
788 * init lance (write init-values .. init-buffers) (open-helper)
790 static int ni65_lance_reinit(struct net_device *dev)
793 struct priv *p = (struct priv *) dev->priv;
799 flags=claim_dma_lock();
800 disable_dma(dev->dma); /* I've never worked with dma, but we do it like the packetdriver */
801 set_dma_mode(dev->dma,DMA_MODE_CASCADE);
802 enable_dma(dev->dma);
803 release_dma_lock(flags);
805 outw(inw(PORT+L_RESET),PORT+L_RESET); /* first: reset the card */
806 if( (i=readreg(CSR0) ) != 0x4)
808 printk(KERN_ERR "%s: can't RESET %s card: %04x\n",dev->name,
809 cards[p->cardno].cardname,(int) i);
810 flags=claim_dma_lock();
811 disable_dma(dev->dma);
812 release_dma_lock(flags);
816 p->rmdnum = p->tmdnum = p->tmdlast = p->tmdbouncenum = 0;
817 for(i=0;i<TMDNUM;i++)
819 struct tmd *tmdp = p->tmdhead + i;
822 dev_kfree_skb(p->tmd_skb[i]);
823 p->tmd_skb[i] = NULL;
826 tmdp->u.buffer = 0x0;
827 tmdp->u.s.status = XMIT_START | XMIT_END;
828 tmdp->blen = tmdp->status2 = 0;
831 for(i=0;i<RMDNUM;i++)
833 struct rmd *rmdp = p->rmdhead + i;
835 rmdp->u.buffer = (u32) isa_virt_to_bus(p->recv_skb[i]->data);
837 rmdp->u.buffer = (u32) isa_virt_to_bus(p->recvbounce[i]);
839 rmdp->blen = -(R_BUF_SIZE-8);
841 rmdp->u.s.status = RCV_OWN;
844 if(dev->flags & IFF_PROMISC)
845 ni65_init_lance(p,dev->dev_addr,0x00,M_PROM);
846 else if(dev->mc_count || dev->flags & IFF_ALLMULTI)
847 ni65_init_lance(p,dev->dev_addr,0xff,0x0);
849 ni65_init_lance(p,dev->dev_addr,0x00,0x00);
852 * ni65_set_lance_mem() sets L_ADDRREG to CSR0
853 * NOW, WE WILL NEVER CHANGE THE L_ADDRREG, CSR0 IS ALWAYS SELECTED
856 if(inw(PORT+L_DATAREG) & CSR0_IDON) {
857 ni65_set_performance(p);
858 /* init OK: start lance , enable interrupts */
859 writedatareg(CSR0_CLRALL | CSR0_INEA | CSR0_STRT);
862 printk(KERN_ERR "%s: can't init lance, status: %04x\n",dev->name,(int) inw(PORT+L_DATAREG));
863 flags=claim_dma_lock();
864 disable_dma(dev->dma);
865 release_dma_lock(flags);
866 return 0; /* ->Error */
872 static irqreturn_t ni65_interrupt(int irq, void * dev_id)
875 struct net_device *dev = dev_id;
879 p = (struct priv *) dev->priv;
881 spin_lock(&p->ring_lock);
884 csr0 = inw(PORT+L_DATAREG);
887 writedatareg( (csr0 & CSR0_CLRALL) ); /* ack interrupts, disable int. */
889 writedatareg( (csr0 & CSR0_CLRALL) | CSR0_INEA ); /* ack interrupts, interrupts enabled */
892 if(!(csr0 & (CSR0_ERR | CSR0_RINT | CSR0_TINT)))
895 if(csr0 & CSR0_RINT) /* RECV-int? */
896 ni65_recv_intr(dev,csr0);
897 if(csr0 & CSR0_TINT) /* XMIT-int? */
898 ni65_xmit_intr(dev,csr0);
902 struct priv *p = (struct priv *) dev->priv;
904 printk(KERN_ERR "%s: general error: %04x.\n",dev->name,csr0);
906 p->stats.tx_errors++;
907 if(csr0 & CSR0_MISS) {
909 for(i=0;i<RMDNUM;i++)
910 printk("%02x ",p->rmdhead[i].u.s.status);
912 p->stats.rx_errors++;
914 if(csr0 & CSR0_MERR) {
916 printk(KERN_ERR "%s: Ooops .. memory error: %04x.\n",dev->name,csr0);
917 ni65_stop_start(dev,p);
922 #ifdef RCV_PARANOIA_CHECK
925 for(j=0;j<RMDNUM;j++)
927 struct priv *p = (struct priv *) dev->priv;
929 for(i=RMDNUM-1;i>0;i--) {
930 num2 = (p->rmdnum + i) & (RMDNUM-1);
931 if(!(p->rmdhead[num2].u.s.status & RCV_OWN))
936 for(k=0;k<RMDNUM;k++) {
937 num1 = (p->rmdnum + k) & (RMDNUM-1);
938 if(!(p->rmdhead[num1].u.s.status & RCV_OWN))
949 for(k=0;k<RMDNUM;k++) {
950 sprintf(buf1,"%02x ",(p->rmdhead[k].u.s.status)); /* & RCV_OWN) ); */
954 printk(KERN_ERR "%s: Ooops, receive ring corrupted %2d %2d | %s\n",dev->name,p->rmdnum,i,buf);
958 ni65_recv_intr(dev,csr0);
959 if((p->rmdhead[num2].u.s.status & RCV_OWN))
960 break; /* ok, we are 'in sync' again */
968 if( (csr0 & (CSR0_RXON | CSR0_TXON)) != (CSR0_RXON | CSR0_TXON) ) {
969 printk(KERN_DEBUG "%s: RX or TX was offline -> restart\n",dev->name);
970 ni65_stop_start(dev,p);
973 writedatareg(CSR0_INEA);
975 spin_unlock(&p->ring_lock);
980 * We have received an Xmit-Interrupt ..
981 * send a new packet if necessary
983 static void ni65_xmit_intr(struct net_device *dev,int csr0)
985 struct priv *p = (struct priv *) dev->priv;
987 while(p->xmit_queued)
989 struct tmd *tmdp = p->tmdhead + p->tmdlast;
990 int tmdstat = tmdp->u.s.status;
992 if(tmdstat & XMIT_OWN)
995 if(tmdstat & XMIT_ERR)
998 if(tmdp->status2 & XMIT_TDRMASK && debuglevel > 3)
999 printk(KERN_ERR "%s: tdr-problems (e.g. no resistor)\n",dev->name);
1001 /* checking some errors */
1002 if(tmdp->status2 & XMIT_RTRY)
1003 p->stats.tx_aborted_errors++;
1004 if(tmdp->status2 & XMIT_LCAR)
1005 p->stats.tx_carrier_errors++;
1006 if(tmdp->status2 & (XMIT_BUFF | XMIT_UFLO )) {
1007 /* this stops the xmitter */
1008 p->stats.tx_fifo_errors++;
1010 printk(KERN_ERR "%s: Xmit FIFO/BUFF error\n",dev->name);
1011 if(p->features & INIT_RING_BEFORE_START) {
1012 tmdp->u.s.status = XMIT_OWN | XMIT_START | XMIT_END; /* test: resend this frame */
1013 ni65_stop_start(dev,p);
1014 break; /* no more Xmit processing .. */
1017 ni65_stop_start(dev,p);
1020 printk(KERN_ERR "%s: xmit-error: %04x %02x-%04x\n",dev->name,csr0,(int) tmdstat,(int) tmdp->status2);
1021 if(!(csr0 & CSR0_BABL)) /* don't count errors twice */
1022 p->stats.tx_errors++;
1026 p->stats.tx_bytes -= (short)(tmdp->blen);
1027 p->stats.tx_packets++;
1031 if(p->tmd_skb[p->tmdlast]) {
1032 dev_kfree_skb_irq(p->tmd_skb[p->tmdlast]);
1033 p->tmd_skb[p->tmdlast] = NULL;
1037 p->tmdlast = (p->tmdlast + 1) & (TMDNUM-1);
1038 if(p->tmdlast == p->tmdnum)
1041 netif_wake_queue(dev);
1045 * We have received a packet
1047 static void ni65_recv_intr(struct net_device *dev,int csr0)
1052 struct priv *p = (struct priv *) dev->priv;
1054 rmdp = p->rmdhead + p->rmdnum;
1055 while(!( (rmdstat = rmdp->u.s.status) & RCV_OWN))
1058 if( (rmdstat & (RCV_START | RCV_END | RCV_ERR)) != (RCV_START | RCV_END) ) /* error or oversized? */
1060 if(!(rmdstat & RCV_ERR)) {
1061 if(rmdstat & RCV_START)
1063 p->stats.rx_length_errors++;
1064 printk(KERN_ERR "%s: recv, packet too long: %d\n",dev->name,rmdp->mlen & 0x0fff);
1069 printk(KERN_ERR "%s: receive-error: %04x, lance-status: %04x/%04x\n",
1070 dev->name,(int) rmdstat,csr0,(int) inw(PORT+L_DATAREG) );
1071 if(rmdstat & RCV_FRAM)
1072 p->stats.rx_frame_errors++;
1073 if(rmdstat & RCV_OFLO)
1074 p->stats.rx_over_errors++;
1075 if(rmdstat & RCV_CRC)
1076 p->stats.rx_crc_errors++;
1077 if(rmdstat & RCV_BUF_ERR)
1078 p->stats.rx_fifo_errors++;
1080 if(!(csr0 & CSR0_MISS)) /* don't count errors twice */
1081 p->stats.rx_errors++;
1083 else if( (len = (rmdp->mlen & 0x0fff) - 4) >= 60)
1086 struct sk_buff *skb = alloc_skb(R_BUF_SIZE+2+16,GFP_ATOMIC);
1088 skb_reserve(skb,16);
1090 struct sk_buff *skb = dev_alloc_skb(len+2);
1096 if( (unsigned long) (skb->data + R_BUF_SIZE) > 0x1000000) {
1098 skb_copy_to_linear_data(skb, (unsigned char *)(p->recv_skb[p->rmdnum]->data),len);
1101 struct sk_buff *skb1 = p->recv_skb[p->rmdnum];
1102 skb_put(skb,R_BUF_SIZE);
1103 p->recv_skb[p->rmdnum] = skb;
1104 rmdp->u.buffer = (u32) isa_virt_to_bus(skb->data);
1110 skb_copy_to_linear_data(skb, (unsigned char *) p->recvbounce[p->rmdnum],len);
1112 p->stats.rx_packets++;
1113 p->stats.rx_bytes += len;
1114 skb->protocol=eth_type_trans(skb,dev);
1116 dev->last_rx = jiffies;
1120 printk(KERN_ERR "%s: can't alloc new sk_buff\n",dev->name);
1121 p->stats.rx_dropped++;
1125 printk(KERN_INFO "%s: received runt packet\n",dev->name);
1126 p->stats.rx_errors++;
1128 rmdp->blen = -(R_BUF_SIZE-8);
1130 rmdp->u.s.status = RCV_OWN; /* change owner */
1131 p->rmdnum = (p->rmdnum + 1) & (RMDNUM-1);
1132 rmdp = p->rmdhead + p->rmdnum;
1140 static void ni65_timeout(struct net_device *dev)
1143 struct priv *p = (struct priv *) dev->priv;
1145 printk(KERN_ERR "%s: xmitter timed out, try to restart!\n",dev->name);
1146 for(i=0;i<TMDNUM;i++)
1147 printk("%02x ",p->tmdhead[i].u.s.status);
1149 ni65_lance_reinit(dev);
1150 dev->trans_start = jiffies;
1151 netif_wake_queue(dev);
1158 static int ni65_send_packet(struct sk_buff *skb, struct net_device *dev)
1160 struct priv *p = (struct priv *) dev->priv;
1162 netif_stop_queue(dev);
1164 if (test_and_set_bit(0, (void*)&p->lock)) {
1165 printk(KERN_ERR "%s: Queue was locked.\n", dev->name);
1170 short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1172 unsigned long flags;
1175 if( (unsigned long) (skb->data + skb->len) > 0x1000000) {
1178 skb_copy_from_linear_data(skb, p->tmdbounce[p->tmdbouncenum],
1179 skb->len > T_BUF_SIZE ? T_BUF_SIZE :
1182 memset((char *)p->tmdbounce[p->tmdbouncenum]+skb->len, 0, len-skb->len);
1183 dev_kfree_skb (skb);
1185 spin_lock_irqsave(&p->ring_lock, flags);
1186 tmdp = p->tmdhead + p->tmdnum;
1187 tmdp->u.buffer = (u32) isa_virt_to_bus(p->tmdbounce[p->tmdbouncenum]);
1188 p->tmdbouncenum = (p->tmdbouncenum + 1) & (TMDNUM - 1);
1193 spin_lock_irqsave(&p->ring_lock, flags);
1195 tmdp = p->tmdhead + p->tmdnum;
1196 tmdp->u.buffer = (u32) isa_virt_to_bus(skb->data);
1197 p->tmd_skb[p->tmdnum] = skb;
1202 tmdp->u.s.status = XMIT_OWN | XMIT_START | XMIT_END;
1203 writedatareg(CSR0_TDMD | CSR0_INEA); /* enable xmit & interrupt */
1206 p->tmdnum = (p->tmdnum + 1) & (TMDNUM-1);
1208 if(p->tmdnum != p->tmdlast)
1209 netif_wake_queue(dev);
1212 dev->trans_start = jiffies;
1214 spin_unlock_irqrestore(&p->ring_lock, flags);
1220 static struct net_device_stats *ni65_get_stats(struct net_device *dev)
1225 struct priv *p = (struct priv *) dev->priv;
1226 for(i=0;i<RMDNUM;i++)
1228 struct rmd *rmdp = p->rmdhead + ((p->rmdnum + i) & (RMDNUM-1));
1229 printk("%02x ",rmdp->u.s.status);
1234 return &((struct priv *) dev->priv)->stats;
1237 static void set_multicast_list(struct net_device *dev)
1239 if(!ni65_lance_reinit(dev))
1240 printk(KERN_ERR "%s: Can't switch card into MC mode!\n",dev->name);
1241 netif_wake_queue(dev);
1245 static struct net_device *dev_ni65;
1247 module_param(irq, int, 0);
1248 module_param(io, int, 0);
1249 module_param(dma, int, 0);
1250 MODULE_PARM_DESC(irq, "ni6510 IRQ number (ignored for some cards)");
1251 MODULE_PARM_DESC(io, "ni6510 I/O base address");
1252 MODULE_PARM_DESC(dma, "ni6510 ISA DMA channel (ignored for some cards)");
1254 int __init init_module(void)
1256 dev_ni65 = ni65_probe(-1);
1257 return IS_ERR(dev_ni65) ? PTR_ERR(dev_ni65) : 0;
1260 void __exit cleanup_module(void)
1262 unregister_netdev(dev_ni65);
1263 cleanup_card(dev_ni65);
1264 free_netdev(dev_ni65);
1268 MODULE_LICENSE("GPL");