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 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/sched.h>
66 #include <linux/string.h>
67 #include <linux/ptrace.h>
68 #include <linux/errno.h>
69 #include <linux/ioport.h>
70 #include <linux/malloc.h>
71 #include <linux/interrupt.h>
72 #include <linux/delay.h>
73 #include <linux/init.h>
74 #include <asm/bitops.h>
78 #include <linux/netdevice.h>
79 #include <linux/etherdevice.h>
80 #include <linux/skbuff.h>
82 #include <linux/version.h>
83 #include <linux/module.h>
88 * the current setting allows an acceptable performance
89 * for 'RCV_PARANOIA_CHECK' read the 'known problems' part in
90 * the header of this file
91 * 'invert' the defines for max. performance. This may cause DMA problems
92 * on some boards (e.g on my ASUS SP3G)
96 #define RCV_PARANOIA_CHECK
98 #define MID_PERFORMANCE
100 #if defined( LOW_PERFORMANCE )
101 static int isa0
=7,isa1
=7,csr80
=0x0c10;
102 #elif defined( MID_PERFORMANCE )
103 static int isa0
=5,isa1
=5,csr80
=0x2810;
104 #else /* high performance */
105 static int isa0
=4,isa1
=4,csr80
=0x0017;
109 * a few card/vendor specific defines
111 #define NI65_ID0 0x00
112 #define NI65_ID1 0x55
113 #define NI65_EB_ID0 0x52
114 #define NI65_EB_ID1 0x44
115 #define NE2100_ID0 0x57
116 #define NE2100_ID1 0x57
118 #define PORT p->cmdr_addr
121 * buffer configuration
125 #define RMDNUMMASK 0x80000000
128 #define RMDNUMMASK 0x60000000 /* log2(RMDNUM)<<29 */
133 #define TMDNUMMASK 0x00000000
136 #define TMDNUMMASK 0x40000000 /* log2(TMDNUM)<<29 */
139 /* slightly oversized */
140 #define R_BUF_SIZE 1544
141 #define T_BUF_SIZE 1544
144 * lance register defines
146 #define L_DATAREG 0x00
147 #define L_ADDRREG 0x02
149 #define L_CONFIG 0x05
153 * to access the lance/am7990-regs, you have to write
154 * reg-number into L_ADDRREG, then you can access it using L_DATAREG
161 #define INIT_RING_BEFORE_START 0x1
162 #define FULL_RESET_ON_ERROR 0x2
165 #define writereg(val,reg) {outw(reg,PORT+L_ADDRREG);inw(PORT+L_ADDRREG); \
166 outw(val,PORT+L_DATAREG);inw(PORT+L_DATAREG);}
167 #define readreg(reg) (outw(reg,PORT+L_ADDRREG),inw(PORT+L_ADDRREG),\
170 #define writedatareg(val) {outw(val,PORT+L_DATAREG);inw(PORT+L_DATAREG);}
172 #define writedatareg(val) { writereg(val,CSR0); }
175 #define writereg(val,reg) {outw(reg,PORT+L_ADDRREG);outw(val,PORT+L_DATAREG);}
176 #define readreg(reg) (outw(reg,PORT+L_ADDRREG),inw(PORT+L_DATAREG))
177 #define writedatareg(val) { writereg(val,CSR0); }
180 static unsigned char ni_vendor
[] = { 0x02,0x07,0x01 };
183 unsigned char id0
,id1
;
188 unsigned char *vendor_id
;
190 unsigned char config
;
192 { NI65_ID0
,NI65_ID1
,0x0e,0x10,0x0,0x8,ni_vendor
,"ni6510", 0x1 } ,
193 { NI65_EB_ID0
,NI65_EB_ID1
,0x0e,0x18,0x10,0x0,ni_vendor
,"ni6510 EtherBlaster", 0x2 } ,
194 { NE2100_ID0
,NE2100_ID1
,0x0e,0x18,0x10,0x0,NULL
,"generic NE2100", 0x0 }
200 struct rmd rmdhead
[RMDNUM
];
201 struct tmd tmdhead
[TMDNUM
];
202 struct init_block ib
;
206 struct sk_buff
*recv_skb
[RMDNUM
];
208 void *recvbounce
[RMDNUM
];
211 struct sk_buff
*tmd_skb
[TMDNUM
];
213 void *tmdbounce
[TMDNUM
];
215 int lock
,xmit_queued
;
216 struct net_device_stats stats
;
223 static int ni65_probe1(struct net_device
*dev
,int);
224 static void ni65_interrupt(int irq
, void * dev_id
, struct pt_regs
*regs
);
225 static void ni65_recv_intr(struct net_device
*dev
,int);
226 static void ni65_xmit_intr(struct net_device
*dev
,int);
227 static int ni65_open(struct net_device
*dev
);
228 static int ni65_lance_reinit(struct net_device
*dev
);
229 static void ni65_init_lance(struct priv
*p
,unsigned char*,int,int);
230 static int ni65_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
231 static int ni65_close(struct net_device
*dev
);
232 static int ni65_alloc_buffer(struct net_device
*dev
);
233 static void ni65_free_buffer(struct priv
*p
);
234 static struct net_device_stats
*ni65_get_stats(struct net_device
*);
235 static void set_multicast_list(struct net_device
*dev
);
237 static int irqtab
[] __initdata
= { 9,12,15,5 }; /* irq config-translate */
238 static int dmatab
[] __initdata
= { 0,3,5,6,7 }; /* dma config-translate and autodetect */
240 static int debuglevel
= 1;
243 * set 'performance' registers .. we must STOP lance for that
245 static void ni65_set_performance(struct priv
*p
)
247 writereg(CSR0_STOP
| CSR0_CLRALL
,CSR0
); /* STOP */
249 if( !(cards
[p
->cardno
].config
& 0x02) )
252 outw(80,PORT
+L_ADDRREG
);
253 if(inw(PORT
+L_ADDRREG
) != 80)
256 writereg( (csr80
& 0x3fff) ,80); /* FIFO watermarks */
257 outw(0,PORT
+L_ADDRREG
);
258 outw((short)isa0
,PORT
+L_BUSIF
); /* write ISA 0: DMA_R : isa0 * 50ns */
259 outw(1,PORT
+L_ADDRREG
);
260 outw((short)isa1
,PORT
+L_BUSIF
); /* write ISA 1: DMA_W : isa1 * 50ns */
262 outw(CSR0
,PORT
+L_ADDRREG
); /* switch back to CSR0 */
266 * open interface (up)
268 static int ni65_open(struct net_device
*dev
)
270 struct priv
*p
= (struct priv
*) dev
->priv
;
271 int irqval
= request_irq(dev
->irq
, &ni65_interrupt
,0,
272 cards
[p
->cardno
].cardname
,dev
);
274 printk ("%s: unable to get IRQ %d (irqval=%d).\n",
275 dev
->name
,dev
->irq
, irqval
);
279 if(ni65_lance_reinit(dev
))
289 free_irq(dev
->irq
,dev
);
296 * close interface (down)
298 static int ni65_close(struct net_device
*dev
)
300 struct priv
*p
= (struct priv
*) dev
->priv
;
302 outw(inw(PORT
+L_RESET
),PORT
+L_RESET
); /* that's the hard way */
307 for(i
=0;i
<TMDNUM
;i
++)
310 dev_kfree_skb(p
->tmd_skb
[i
]);
311 p
->tmd_skb
[i
] = NULL
;
316 free_irq(dev
->irq
,dev
);
324 * Probe The Card (not the lance-chip)
329 int __init
ni65_probe(struct net_device
*dev
)
332 static int ports
[] = {0x360,0x300,0x320,0x340, 0};
334 if (dev
->base_addr
> 0x1ff) /* Check a single specified location. */
335 return ni65_probe1(dev
, dev
->base_addr
);
336 else if (dev
->base_addr
> 0) /* Don't probe at all. */
339 for (port
= ports
; *port
; port
++)
341 if (ni65_probe1(dev
, *port
) == 0)
349 * this is the real card probe ..
351 static int __init
ni65_probe1(struct net_device
*dev
,int ioaddr
)
357 for(i
=0;i
<NUM_CARDS
;i
++) {
358 if(check_region(ioaddr
, cards
[i
].total_size
))
360 if(cards
[i
].id_offset
>= 0) {
361 if(inb(ioaddr
+cards
[i
].id_offset
+0) != cards
[i
].id0
||
362 inb(ioaddr
+cards
[i
].id_offset
+1) != cards
[i
].id1
) {
366 if(cards
[i
].vendor_id
) {
368 if(inb(ioaddr
+cards
[i
].addr_offset
+j
) != cards
[i
].vendor_id
[j
])
377 dev
->dev_addr
[j
] = inb(ioaddr
+cards
[i
].addr_offset
+j
);
379 if( (j
=ni65_alloc_buffer(dev
)) < 0)
381 p
= (struct priv
*) dev
->priv
;
382 p
->cmdr_addr
= ioaddr
+ cards
[i
].cmd_offset
;
385 printk("%s: %s found at %#3x, ", dev
->name
, cards
[p
->cardno
].cardname
, ioaddr
);
387 outw(inw(PORT
+L_RESET
),PORT
+L_RESET
); /* first: reset the card */
388 if( (j
=readreg(CSR0
)) != 0x4) {
389 printk(KERN_ERR
"can't RESET card: %04x\n",j
);
394 outw(88,PORT
+L_ADDRREG
);
395 if(inw(PORT
+L_ADDRREG
) == 88) {
397 v
= inw(PORT
+L_DATAREG
);
399 outw(89,PORT
+L_ADDRREG
);
400 v
|= inw(PORT
+L_DATAREG
);
401 printk("Version %#08lx, ",v
);
402 p
->features
= INIT_RING_BEFORE_START
;
405 printk("ancient LANCE, ");
409 if(test_bit(0,&cards
[i
].config
)) {
410 dev
->irq
= irqtab
[(inw(ioaddr
+L_CONFIG
)>>2)&3];
411 dev
->dma
= dmatab
[inw(ioaddr
+L_CONFIG
)&3];
412 printk("IRQ %d (from card), DMA %d (from card).\n",dev
->irq
,dev
->dma
);
416 /* 'stuck test' from lance.c */
417 int dma_channels
= ((inb(DMA1_STAT_REG
) >> 4) & 0x0f) | (inb(DMA2_STAT_REG
) & 0xf0);
420 if(test_bit(dma
,&dma_channels
) || request_dma(dma
,"ni6510"))
423 flags
=claim_dma_lock();
425 set_dma_mode(dma
,DMA_MODE_CASCADE
);
427 release_dma_lock(flags
);
429 ni65_init_lance(p
,dev
->dev_addr
,0,0); /* trigger memory access */
431 flags
=claim_dma_lock();
434 release_dma_lock(flags
);
436 if(readreg(CSR0
) & CSR0_IDON
)
440 printk("Can't detect DMA channel!\n");
444 dev
->dma
= dmatab
[i
];
445 printk("DMA %d (autodetected), ",dev
->dma
);
448 printk("DMA %d (assigned), ",dev
->dma
);
452 ni65_init_lance(p
,dev
->dev_addr
,0,0);
454 writereg(CSR0_INIT
|CSR0_INEA
,CSR0
); /* trigger interrupt */
456 if(!(dev
->irq
= autoirq_report(2)))
458 printk("Failed to detect IRQ line!\n");
462 printk("IRQ %d (autodetected).\n",dev
->irq
);
465 printk("IRQ %d (assigned).\n",dev
->irq
);
468 if(request_dma(dev
->dma
, cards
[p
->cardno
].cardname
) != 0)
470 printk("%s: Can't request dma-channel %d\n",dev
->name
,(int) dev
->dma
);
476 * Grab the region so we can find another board.
478 request_region(ioaddr
,cards
[p
->cardno
].total_size
,cards
[p
->cardno
].cardname
);
480 dev
->base_addr
= ioaddr
;
482 dev
->open
= ni65_open
;
483 dev
->stop
= ni65_close
;
484 dev
->hard_start_xmit
= ni65_send_packet
;
485 dev
->get_stats
= ni65_get_stats
;
486 dev
->set_multicast_list
= set_multicast_list
;
494 return 0; /* everything is OK */
498 * set lance register and trigger init
500 static void ni65_init_lance(struct priv
*p
,unsigned char *daddr
,int filter
,int mode
)
505 writereg(CSR0_CLRALL
|CSR0_STOP
,CSR0
);
508 p
->ib
.eaddr
[i
] = daddr
[i
];
511 p
->ib
.filter
[i
] = filter
;
514 p
->ib
.trp
= (u32
) virt_to_bus(p
->tmdhead
) | TMDNUMMASK
;
515 p
->ib
.rrp
= (u32
) virt_to_bus(p
->rmdhead
) | RMDNUMMASK
;
516 writereg(0,CSR3
); /* busmaster/no word-swap */
517 pib
= (u32
) virt_to_bus(&p
->ib
);
518 writereg(pib
& 0xffff,CSR1
);
519 writereg(pib
>> 16,CSR2
);
521 writereg(CSR0_INIT
,CSR0
); /* this changes L_ADDRREG to CSR0 */
526 if(inw(PORT
+L_DATAREG
) & (CSR0_IDON
| CSR0_MERR
) )
527 break; /* init ok ? */
532 * allocate memory area and check the 16MB border
534 static void *ni65_alloc_mem(struct net_device
*dev
,char *what
,int size
,int type
)
536 struct sk_buff
*skb
=NULL
;
541 ret
= skb
= alloc_skb(2+16+size
,GFP_KERNEL
|GFP_DMA
);
543 printk("%s: unable to allocate %s memory.\n",dev
->name
,what
);
547 skb_reserve(skb
,2+16);
548 skb_put(skb
,R_BUF_SIZE
); /* grab the whole space .. (not necessary) */
552 ret
= ptr
= kmalloc(T_BUF_SIZE
,GFP_KERNEL
| GFP_DMA
);
554 printk("%s: unable to allocate %s memory.\n",dev
->name
,what
);
558 if( (u32
) virt_to_bus(ptr
+size
) > 0x1000000) {
559 printk("%s: unable to allocate %s memory in lower 16MB!\n",dev
->name
,what
);
570 * allocate all memory structures .. send/recv buffers etc ...
572 static int ni65_alloc_buffer(struct net_device
*dev
)
579 * we need 8-aligned memory ..
581 ptr
= ni65_alloc_mem(dev
,"BUFFER",sizeof(struct priv
)+8,0);
585 p
= dev
->priv
= (struct priv
*) (((unsigned long) ptr
+ 7) & ~0x7);
586 memset((char *) dev
->priv
,0,sizeof(struct priv
));
589 for(i
=0;i
<TMDNUM
;i
++)
592 p
->tmd_skb
[i
] = NULL
;
594 p
->tmdbounce
[i
] = ni65_alloc_mem(dev
,"XMIT",T_BUF_SIZE
,0);
595 if(!p
->tmdbounce
[i
]) {
601 for(i
=0;i
<RMDNUM
;i
++)
604 p
->recv_skb
[i
] = ni65_alloc_mem(dev
,"RECV",R_BUF_SIZE
,1);
605 if(!p
->recv_skb
[i
]) {
610 p
->recvbounce
[i
] = ni65_alloc_mem(dev
,"RECV",R_BUF_SIZE
,0);
611 if(!p
->recvbounce
[i
]) {
618 return 0; /* everything is OK */
622 * free buffers and private struct
624 static void ni65_free_buffer(struct priv
*p
)
631 for(i
=0;i
<TMDNUM
;i
++) {
633 kfree(p
->tmdbounce
[i
]);
636 dev_kfree_skb(p
->tmd_skb
[i
]);
640 for(i
=0;i
<RMDNUM
;i
++)
644 dev_kfree_skb(p
->recv_skb
[i
]);
647 kfree(p
->recvbounce
[i
]);
656 * stop and (re)start lance .. e.g after an error
658 static void ni65_stop_start(struct net_device
*dev
,struct priv
*p
)
660 int csr0
= CSR0_INEA
;
662 writedatareg(CSR0_STOP
);
665 printk("ni65_stop_start\n");
667 if(p
->features
& INIT_RING_BEFORE_START
) {
670 struct sk_buff
*skb_save
[TMDNUM
];
672 unsigned long buffer
[TMDNUM
];
677 if((p
->tmdhead
[p
->tmdlast
].u
.s
.status
& XMIT_OWN
))
679 p
->tmdlast
= (p
->tmdlast
+ 1) & (TMDNUM
-1);
680 if(p
->tmdlast
== p
->tmdnum
)
685 for(i
=0;i
<TMDNUM
;i
++) {
686 struct tmd
*tmdp
= p
->tmdhead
+ i
;
688 skb_save
[i
] = p
->tmd_skb
[i
];
690 buffer
[i
] = (u32
) bus_to_virt(tmdp
->u
.buffer
);
691 blen
[i
] = tmdp
->blen
;
692 tmdp
->u
.s
.status
= 0x0;
695 for(i
=0;i
<RMDNUM
;i
++) {
696 struct rmd
*rmdp
= p
->rmdhead
+ i
;
697 rmdp
->u
.s
.status
= RCV_OWN
;
699 p
->tmdnum
= p
->xmit_queued
= 0;
700 writedatareg(CSR0_STRT
| csr0
);
702 for(i
=0;i
<TMDNUM
;i
++) {
703 int num
= (i
+ p
->tmdlast
) & (TMDNUM
-1);
704 p
->tmdhead
[i
].u
.buffer
= (u32
) virt_to_bus((char *)buffer
[num
]); /* status is part of buffer field */
705 p
->tmdhead
[i
].blen
= blen
[num
];
706 if(p
->tmdhead
[i
].u
.s
.status
& XMIT_OWN
) {
707 p
->tmdnum
= (p
->tmdnum
+ 1) & (TMDNUM
-1);
709 writedatareg(CSR0_TDMD
| CSR0_INEA
| csr0
);
712 p
->tmd_skb
[i
] = skb_save
[num
];
715 p
->rmdnum
= p
->tmdlast
= 0;
717 dev
->tbusy
= (p
->tmdnum
|| !p
->xmit_queued
) ? 0 : 1;
718 dev
->trans_start
= jiffies
;
721 writedatareg(CSR0_STRT
| csr0
);
725 * init lance (write init-values .. init-buffers) (open-helper)
727 static int ni65_lance_reinit(struct net_device
*dev
)
730 struct priv
*p
= (struct priv
*) dev
->priv
;
736 flags
=claim_dma_lock();
737 disable_dma(dev
->dma
); /* I've never worked with dma, but we do it like the packetdriver */
738 set_dma_mode(dev
->dma
,DMA_MODE_CASCADE
);
739 enable_dma(dev
->dma
);
740 release_dma_lock(flags
);
742 outw(inw(PORT
+L_RESET
),PORT
+L_RESET
); /* first: reset the card */
743 if( (i
=readreg(CSR0
) ) != 0x4)
745 printk(KERN_ERR
"%s: can't RESET %s card: %04x\n",dev
->name
,
746 cards
[p
->cardno
].cardname
,(int) i
);
747 flags
=claim_dma_lock();
748 disable_dma(dev
->dma
);
749 release_dma_lock(flags
);
753 p
->rmdnum
= p
->tmdnum
= p
->tmdlast
= p
->tmdbouncenum
= 0;
754 for(i
=0;i
<TMDNUM
;i
++)
756 struct tmd
*tmdp
= p
->tmdhead
+ i
;
759 dev_kfree_skb(p
->tmd_skb
[i
]);
760 p
->tmd_skb
[i
] = NULL
;
763 tmdp
->u
.buffer
= 0x0;
764 tmdp
->u
.s
.status
= XMIT_START
| XMIT_END
;
765 tmdp
->blen
= tmdp
->status2
= 0;
768 for(i
=0;i
<RMDNUM
;i
++)
770 struct rmd
*rmdp
= p
->rmdhead
+ i
;
772 rmdp
->u
.buffer
= (u32
) virt_to_bus(p
->recv_skb
[i
]->data
);
774 rmdp
->u
.buffer
= (u32
) virt_to_bus(p
->recvbounce
[i
]);
776 rmdp
->blen
= -(R_BUF_SIZE
-8);
778 rmdp
->u
.s
.status
= RCV_OWN
;
781 if(dev
->flags
& IFF_PROMISC
)
782 ni65_init_lance(p
,dev
->dev_addr
,0x00,M_PROM
);
783 else if(dev
->mc_count
|| dev
->flags
& IFF_ALLMULTI
)
784 ni65_init_lance(p
,dev
->dev_addr
,0xff,0x0);
786 ni65_init_lance(p
,dev
->dev_addr
,0x00,0x00);
789 * ni65_set_lance_mem() sets L_ADDRREG to CSR0
790 * NOW, WE WILL NEVER CHANGE THE L_ADDRREG, CSR0 IS ALWAYS SELECTED
793 if(inw(PORT
+L_DATAREG
) & CSR0_IDON
) {
794 ni65_set_performance(p
);
795 /* init OK: start lance , enable interrupts */
796 writedatareg(CSR0_CLRALL
| CSR0_INEA
| CSR0_STRT
);
799 printk(KERN_ERR
"%s: can't init lance, status: %04x\n",dev
->name
,(int) inw(PORT
+L_DATAREG
));
800 flags
=claim_dma_lock();
801 disable_dma(dev
->dma
);
802 release_dma_lock(flags
);
803 return 0; /* ->Error */
809 static void ni65_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
812 struct net_device
*dev
= dev_id
;
817 printk (KERN_ERR
"ni65_interrupt(): irq %d for unknown device.\n", irq
);
821 if(test_and_set_bit(0,(int *) &dev
->interrupt
)) {
822 printk("ni65: oops .. interrupt while proceeding interrupt\n");
825 p
= (struct priv
*) dev
->priv
;
828 csr0
= inw(PORT
+L_DATAREG
);
831 writedatareg( (csr0
& CSR0_CLRALL
) ); /* ack interrupts, disable int. */
833 writedatareg( (csr0
& CSR0_CLRALL
) | CSR0_INEA
); /* ack interrupts, interrupts enabled */
836 if(!(csr0
& (CSR0_ERR
| CSR0_RINT
| CSR0_TINT
)))
839 if(csr0
& CSR0_RINT
) /* RECV-int? */
840 ni65_recv_intr(dev
,csr0
);
841 if(csr0
& CSR0_TINT
) /* XMIT-int? */
842 ni65_xmit_intr(dev
,csr0
);
846 struct priv
*p
= (struct priv
*) dev
->priv
;
848 printk("%s: general error: %04x.\n",dev
->name
,csr0
);
850 p
->stats
.tx_errors
++;
851 if(csr0
& CSR0_MISS
) {
853 for(i
=0;i
<RMDNUM
;i
++)
854 printk("%02x ",p
->rmdhead
[i
].u
.s
.status
);
856 p
->stats
.rx_errors
++;
858 if(csr0
& CSR0_MERR
) {
860 printk("%s: Ooops .. memory error: %04x.\n",dev
->name
,csr0
);
861 ni65_stop_start(dev
,p
);
866 #ifdef RCV_PARANOIA_CHECK
869 for(j
=0;j
<RMDNUM
;j
++)
871 struct priv
*p
= (struct priv
*) dev
->priv
;
873 for(i
=RMDNUM
-1;i
>0;i
--) {
874 num2
= (p
->rmdnum
+ i
) & (RMDNUM
-1);
875 if(!(p
->rmdhead
[num2
].u
.s
.status
& RCV_OWN
))
880 for(k
=0;k
<RMDNUM
;k
++) {
881 num1
= (p
->rmdnum
+ k
) & (RMDNUM
-1);
882 if(!(p
->rmdhead
[num1
].u
.s
.status
& RCV_OWN
))
893 for(k
=0;k
<RMDNUM
;k
++) {
894 sprintf(buf1
,"%02x ",(p
->rmdhead
[k
].u
.s
.status
)); /* & RCV_OWN) ); */
898 printk(KERN_ERR
"%s: Ooops, receive ring corrupted %2d %2d | %s\n",dev
->name
,p
->rmdnum
,i
,buf
);
902 ni65_recv_intr(dev
,csr0
);
903 if((p
->rmdhead
[num2
].u
.s
.status
& RCV_OWN
))
904 break; /* ok, we are 'in sync' again */
912 if( (csr0
& (CSR0_RXON
| CSR0_TXON
)) != (CSR0_RXON
| CSR0_TXON
) ) {
913 printk("%s: RX or TX was offline -> restart\n",dev
->name
);
914 ni65_stop_start(dev
,p
);
917 writedatareg(CSR0_INEA
);
925 * We have received an Xmit-Interrupt ..
926 * send a new packet if necessary
928 static void ni65_xmit_intr(struct net_device
*dev
,int csr0
)
930 struct priv
*p
= (struct priv
*) dev
->priv
;
932 while(p
->xmit_queued
)
934 struct tmd
*tmdp
= p
->tmdhead
+ p
->tmdlast
;
935 int tmdstat
= tmdp
->u
.s
.status
;
937 if(tmdstat
& XMIT_OWN
)
940 if(tmdstat
& XMIT_ERR
)
943 if(tmdp
->status2
& XMIT_TDRMASK
&& debuglevel
> 3)
944 printk(KERN_ERR
"%s: tdr-problems (e.g. no resistor)\n",dev
->name
);
946 /* checking some errors */
947 if(tmdp
->status2
& XMIT_RTRY
)
948 p
->stats
.tx_aborted_errors
++;
949 if(tmdp
->status2
& XMIT_LCAR
)
950 p
->stats
.tx_carrier_errors
++;
951 if(tmdp
->status2
& (XMIT_BUFF
| XMIT_UFLO
)) {
952 /* this stops the xmitter */
953 p
->stats
.tx_fifo_errors
++;
955 printk(KERN_ERR
"%s: Xmit FIFO/BUFF error\n",dev
->name
);
956 if(p
->features
& INIT_RING_BEFORE_START
) {
957 tmdp
->u
.s
.status
= XMIT_OWN
| XMIT_START
| XMIT_END
; /* test: resend this frame */
958 ni65_stop_start(dev
,p
);
959 break; /* no more Xmit processing .. */
962 ni65_stop_start(dev
,p
);
965 printk(KERN_ERR
"%s: xmit-error: %04x %02x-%04x\n",dev
->name
,csr0
,(int) tmdstat
,(int) tmdp
->status2
);
966 if(!(csr0
& CSR0_BABL
)) /* don't count errors twice */
967 p
->stats
.tx_errors
++;
971 p
->stats
.tx_bytes
-= (short)(tmdp
->blen
);
972 p
->stats
.tx_packets
++;
976 if(p
->tmd_skb
[p
->tmdlast
]) {
977 dev_kfree_skb(p
->tmd_skb
[p
->tmdlast
]);
978 p
->tmd_skb
[p
->tmdlast
] = NULL
;
982 p
->tmdlast
= (p
->tmdlast
+ 1) & (TMDNUM
-1);
983 if(p
->tmdlast
== p
->tmdnum
)
991 * We have received a packet
993 static void ni65_recv_intr(struct net_device
*dev
,int csr0
)
998 struct priv
*p
= (struct priv
*) dev
->priv
;
1000 rmdp
= p
->rmdhead
+ p
->rmdnum
;
1001 while(!( (rmdstat
= rmdp
->u
.s
.status
) & RCV_OWN
))
1004 if( (rmdstat
& (RCV_START
| RCV_END
| RCV_ERR
)) != (RCV_START
| RCV_END
) ) /* error or oversized? */
1006 if(!(rmdstat
& RCV_ERR
)) {
1007 if(rmdstat
& RCV_START
)
1009 p
->stats
.rx_length_errors
++;
1010 printk(KERN_ERR
"%s: recv, packet too long: %d\n",dev
->name
,rmdp
->mlen
& 0x0fff);
1015 printk(KERN_ERR
"%s: receive-error: %04x, lance-status: %04x/%04x\n",
1016 dev
->name
,(int) rmdstat
,csr0
,(int) inw(PORT
+L_DATAREG
) );
1017 if(rmdstat
& RCV_FRAM
)
1018 p
->stats
.rx_frame_errors
++;
1019 if(rmdstat
& RCV_OFLO
)
1020 p
->stats
.rx_over_errors
++;
1021 if(rmdstat
& RCV_CRC
)
1022 p
->stats
.rx_crc_errors
++;
1023 if(rmdstat
& RCV_BUF_ERR
)
1024 p
->stats
.rx_fifo_errors
++;
1026 if(!(csr0
& CSR0_MISS
)) /* don't count errors twice */
1027 p
->stats
.rx_errors
++;
1029 else if( (len
= (rmdp
->mlen
& 0x0fff) - 4) >= 60)
1032 struct sk_buff
*skb
= alloc_skb(R_BUF_SIZE
+2+16,GFP_ATOMIC
);
1034 skb_reserve(skb
,16);
1036 struct sk_buff
*skb
= dev_alloc_skb(len
+2);
1043 if( (unsigned long) (skb
->data
+ R_BUF_SIZE
) > 0x1000000) {
1045 eth_copy_and_sum(skb
, (unsigned char *)(p
->recv_skb
[p
->rmdnum
]->data
),len
,0);
1048 struct sk_buff
*skb1
= p
->recv_skb
[p
->rmdnum
];
1049 skb_put(skb
,R_BUF_SIZE
);
1050 p
->recv_skb
[p
->rmdnum
] = skb
;
1051 rmdp
->u
.buffer
= (u32
) virt_to_bus(skb
->data
);
1057 eth_copy_and_sum(skb
, (unsigned char *) p
->recvbounce
[p
->rmdnum
],len
,0);
1059 p
->stats
.rx_packets
++;
1060 p
->stats
.rx_bytes
+= len
;
1061 skb
->protocol
=eth_type_trans(skb
,dev
);
1066 printk(KERN_ERR
"%s: can't alloc new sk_buff\n",dev
->name
);
1067 p
->stats
.rx_dropped
++;
1071 printk(KERN_INFO
"%s: received runt packet\n",dev
->name
);
1072 p
->stats
.rx_errors
++;
1074 rmdp
->blen
= -(R_BUF_SIZE
-8);
1076 rmdp
->u
.s
.status
= RCV_OWN
; /* change owner */
1077 p
->rmdnum
= (p
->rmdnum
+ 1) & (RMDNUM
-1);
1078 rmdp
= p
->rmdhead
+ p
->rmdnum
;
1085 static int ni65_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1087 struct priv
*p
= (struct priv
*) dev
->priv
;
1091 int tickssofar
= jiffies
- dev
->trans_start
;
1092 if (tickssofar
< 50)
1095 printk(KERN_ERR
"%s: xmitter timed out, try to restart!\n",dev
->name
);
1098 for(i
=0;i
<TMDNUM
;i
++)
1099 printk("%02x ",p
->tmdhead
[i
].u
.s
.status
);
1102 ni65_lance_reinit(dev
);
1104 dev
->trans_start
= jiffies
;
1107 if (test_and_set_bit(0, (void*)&dev
->tbusy
) != 0) {
1108 printk(KERN_ERR
"%s: Transmitter access conflict.\n", dev
->name
);
1111 if (test_and_set_bit(0, (void*)&p
->lock
)) {
1112 printk(KERN_ERR
"%s: Queue was locked.\n", dev
->name
);
1117 short len
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
1122 if( (unsigned long) (skb
->data
+ skb
->len
) > 0x1000000) {
1125 memcpy((char *) p
->tmdbounce
[p
->tmdbouncenum
] ,(char *)skb
->data
,
1126 (skb
->len
> T_BUF_SIZE
) ? T_BUF_SIZE
: skb
->len
);
1127 dev_kfree_skb (skb
);
1132 tmdp
= p
->tmdhead
+ p
->tmdnum
;
1133 tmdp
->u
.buffer
= (u32
) virt_to_bus(p
->tmdbounce
[p
->tmdbouncenum
]);
1134 p
->tmdbouncenum
= (p
->tmdbouncenum
+ 1) & (TMDNUM
- 1);
1142 tmdp
= p
->tmdhead
+ p
->tmdnum
;
1143 tmdp
->u
.buffer
= (u32
) virt_to_bus(skb
->data
);
1144 p
->tmd_skb
[p
->tmdnum
] = skb
;
1149 tmdp
->u
.s
.status
= XMIT_OWN
| XMIT_START
| XMIT_END
;
1150 writedatareg(CSR0_TDMD
| CSR0_INEA
); /* enable xmit & interrupt */
1153 p
->tmdnum
= (p
->tmdnum
+ 1) & (TMDNUM
-1);
1155 dev
->tbusy
= (p
->tmdnum
== p
->tmdlast
) ? 1 : 0;
1157 dev
->trans_start
= jiffies
;
1159 restore_flags(flags
);
1165 static struct net_device_stats
*ni65_get_stats(struct net_device
*dev
)
1170 struct priv
*p
= (struct priv
*) dev
->priv
;
1171 for(i
=0;i
<RMDNUM
;i
++)
1173 struct rmd
*rmdp
= p
->rmdhead
+ ((p
->rmdnum
+ i
) & (RMDNUM
-1));
1174 printk("%02x ",rmdp
->u
.s
.status
);
1179 return &((struct priv
*) dev
->priv
)->stats
;
1182 static void set_multicast_list(struct net_device
*dev
)
1184 if(!ni65_lance_reinit(dev
))
1185 printk(KERN_ERR
"%s: Can't switch card into MC mode!\n",dev
->name
);
1190 static char devicename
[9] = { 0, };
1192 static struct net_device dev_ni65
= {
1193 devicename
, /* "ni6510": device name inserted by net_init.c */
1195 0x360, 9, /* I/O address, IRQ */
1196 0, 0, 0, NULL
, ni65_probe
};
1198 /* set: io,irq,dma or set it when calling insmod */
1203 MODULE_PARM(irq
, "i");
1204 MODULE_PARM(io
, "i");
1205 MODULE_PARM(dma
, "i");
1207 int init_module(void)
1211 dev_ni65
.base_addr
= io
;
1212 if (register_netdev(&dev_ni65
) != 0)
1217 void cleanup_module(void)
1220 p
= (struct priv
*) dev_ni65
.priv
;
1222 printk("Ooops .. no private struct\n");
1225 disable_dma(dev_ni65
.dma
);
1226 free_dma(dev_ni65
.dma
);
1227 unregister_netdev(&dev_ni65
);
1228 release_region(dev_ni65
.base_addr
,cards
[p
->cardno
].total_size
);
1229 ni65_free_buffer(p
);
1230 dev_ni65
.priv
= NULL
;