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 * driver probes: io: 0x360,0x300,0x320,0x340 / dma: 3,5,6,7
12 * This is an extension to the Linux operating system, and is covered by the
13 * same GNU General Public License that covers the Linux-kernel.
15 * comments/bugs/suggestions can be sent to:
17 * email: hippm@informatik.uni-tuebingen.de
20 * some things are from the 'ni6510-packet-driver for dos by Russ Nelson'
21 * and from the original drivers by D.Becker
24 * - on some PCI boards (including my own) the card/board/ISA-bridge has
25 * problems with bus master DMA. This results in lotsa overruns.
26 * It may help to '#define RCV_PARANOIA_CHECK' or try to #undef
27 * the XMT and RCV_VIA_SKB option .. this reduces driver performance.
28 * Or just play with your BIOS options to optimize ISA-DMA access.
29 * Maybe you also wanna play with the LOW_PERFORAMCE and MID_PERFORMANCE
30 * defines -> please report me your experience then
31 * - Harald reported for ASUS SP3G mainboards, that you should use
32 * the 'optimal settings' from the user's manual on page 3-12!
35 * thanx to Jason Sullivan for sending me a ni6510 card!
36 * lot of debug runs with ASUS SP3G Boards (Intel Saturn) by Harald Koenig
38 * simple performance test: (486DX-33/Ni6510-EB receives from 486DX4-100/Ni6510-EB)
39 * average: FTP -> 8384421 bytes received in 8.5 seconds
40 * (no RCV_VIA_SKB,no XMT_VIA_SKB,PARANOIA_CHECK,4 XMIT BUFS, 8 RCV_BUFFS)
41 * peak: FTP -> 8384421 bytes received in 7.5 seconds
42 * (RCV_VIA_SKB,XMT_VIA_SKB,no PARANOIA_CHECK,1(!) XMIT BUF, 16 RCV BUFFS)
46 * 99.Jun.8: added support for /proc/net/dev byte count for xosview (HK)
47 * 96.Sept.29: virt_to_bus stuff added for new memory modell
48 * 96.April.29: Added Harald Koenig's Patches (MH)
49 * 96.April.13: enhanced error handling .. more tests (MH)
50 * 96.April.5/6: a lot of performance tests. Got it stable now (hopefully) (MH)
51 * 96.April.1: (no joke ;) .. added EtherBlaster and Module support (MH)
52 * 96.Feb.19: fixed a few bugs .. cleanups .. tested for 1.3.66 (MH)
53 * hopefully no more 16MB limit
55 * 95.Nov.18: multicast tweaked (AC).
57 * 94.Aug.22: changes in xmit_intr (ack more than one xmitted-packet), ni65_send_packet (p->lock) (MH)
59 * 94.July.16: fixed bugs in recv_skb and skb-alloc stuff (MH)
62 #include <linux/kernel.h>
63 #include <linux/string.h>
64 #include <linux/errno.h>
65 #include <linux/ioport.h>
66 #include <linux/slab.h>
67 #include <linux/interrupt.h>
68 #include <linux/delay.h>
69 #include <linux/init.h>
70 #include <linux/netdevice.h>
71 #include <linux/etherdevice.h>
72 #include <linux/skbuff.h>
73 #include <linux/module.h>
74 #include <linux/bitops.h>
82 * the current setting allows an acceptable performance
83 * for 'RCV_PARANOIA_CHECK' read the 'known problems' part in
84 * the header of this file
85 * 'invert' the defines for max. performance. This may cause DMA problems
86 * on some boards (e.g on my ASUS SP3G)
90 #define RCV_PARANOIA_CHECK
92 #define MID_PERFORMANCE
94 #if defined( LOW_PERFORMANCE )
95 static int isa0
=7,isa1
=7,csr80
=0x0c10;
96 #elif defined( MID_PERFORMANCE )
97 static int isa0
=5,isa1
=5,csr80
=0x2810;
98 #else /* high performance */
99 static int isa0
=4,isa1
=4,csr80
=0x0017;
103 * a few card/vendor specific defines
105 #define NI65_ID0 0x00
106 #define NI65_ID1 0x55
107 #define NI65_EB_ID0 0x52
108 #define NI65_EB_ID1 0x44
109 #define NE2100_ID0 0x57
110 #define NE2100_ID1 0x57
112 #define PORT p->cmdr_addr
115 * buffer configuration
119 #define RMDNUMMASK 0x80000000
122 #define RMDNUMMASK 0x60000000 /* log2(RMDNUM)<<29 */
127 #define TMDNUMMASK 0x00000000
130 #define TMDNUMMASK 0x40000000 /* log2(TMDNUM)<<29 */
133 /* slightly oversized */
134 #define R_BUF_SIZE 1544
135 #define T_BUF_SIZE 1544
138 * lance register defines
140 #define L_DATAREG 0x00
141 #define L_ADDRREG 0x02
143 #define L_CONFIG 0x05
147 * to access the lance/am7990-regs, you have to write
148 * reg-number into L_ADDRREG, then you can access it using L_DATAREG
155 #define INIT_RING_BEFORE_START 0x1
156 #define FULL_RESET_ON_ERROR 0x2
159 #define writereg(val,reg) {outw(reg,PORT+L_ADDRREG);inw(PORT+L_ADDRREG); \
160 outw(val,PORT+L_DATAREG);inw(PORT+L_DATAREG);}
161 #define readreg(reg) (outw(reg,PORT+L_ADDRREG),inw(PORT+L_ADDRREG),\
164 #define writedatareg(val) {outw(val,PORT+L_DATAREG);inw(PORT+L_DATAREG);}
166 #define writedatareg(val) { writereg(val,CSR0); }
169 #define writereg(val,reg) {outw(reg,PORT+L_ADDRREG);outw(val,PORT+L_DATAREG);}
170 #define readreg(reg) (outw(reg,PORT+L_ADDRREG),inw(PORT+L_DATAREG))
171 #define writedatareg(val) { writereg(val,CSR0); }
174 static unsigned char ni_vendor
[] = { 0x02,0x07,0x01 };
177 unsigned char id0
,id1
;
182 unsigned char *vendor_id
;
184 unsigned long config
;
193 .vendor_id
= ni_vendor
,
194 .cardname
= "ni6510",
204 .vendor_id
= ni_vendor
,
205 .cardname
= "ni6510 EtherBlaster",
216 .cardname
= "generic NE2100",
224 struct rmd rmdhead
[RMDNUM
];
225 struct tmd tmdhead
[TMDNUM
];
226 struct init_block ib
;
230 struct sk_buff
*recv_skb
[RMDNUM
];
232 void *recvbounce
[RMDNUM
];
235 struct sk_buff
*tmd_skb
[TMDNUM
];
237 void *tmdbounce
[TMDNUM
];
239 int lock
,xmit_queued
;
245 spinlock_t ring_lock
;
248 static int ni65_probe1(struct net_device
*dev
,int);
249 static irqreturn_t
ni65_interrupt(int irq
, void * dev_id
);
250 static void ni65_recv_intr(struct net_device
*dev
,int);
251 static void ni65_xmit_intr(struct net_device
*dev
,int);
252 static int ni65_open(struct net_device
*dev
);
253 static int ni65_lance_reinit(struct net_device
*dev
);
254 static void ni65_init_lance(struct priv
*p
,unsigned char*,int,int);
255 static netdev_tx_t
ni65_send_packet(struct sk_buff
*skb
,
256 struct net_device
*dev
);
257 static void ni65_timeout(struct net_device
*dev
);
258 static int ni65_close(struct net_device
*dev
);
259 static int ni65_alloc_buffer(struct net_device
*dev
);
260 static void ni65_free_buffer(struct priv
*p
);
261 static void set_multicast_list(struct net_device
*dev
);
263 static int irqtab
[] __initdata
= { 9,12,15,5 }; /* irq config-translate */
264 static int dmatab
[] __initdata
= { 0,3,5,6,7 }; /* dma config-translate and autodetect */
266 static int debuglevel
= 1;
269 * set 'performance' registers .. we must STOP lance for that
271 static void ni65_set_performance(struct priv
*p
)
273 writereg(CSR0_STOP
| CSR0_CLRALL
,CSR0
); /* STOP */
275 if( !(cards
[p
->cardno
].config
& 0x02) )
278 outw(80,PORT
+L_ADDRREG
);
279 if(inw(PORT
+L_ADDRREG
) != 80)
282 writereg( (csr80
& 0x3fff) ,80); /* FIFO watermarks */
283 outw(0,PORT
+L_ADDRREG
);
284 outw((short)isa0
,PORT
+L_BUSIF
); /* write ISA 0: DMA_R : isa0 * 50ns */
285 outw(1,PORT
+L_ADDRREG
);
286 outw((short)isa1
,PORT
+L_BUSIF
); /* write ISA 1: DMA_W : isa1 * 50ns */
288 outw(CSR0
,PORT
+L_ADDRREG
); /* switch back to CSR0 */
292 * open interface (up)
294 static int ni65_open(struct net_device
*dev
)
296 struct priv
*p
= dev
->ml_priv
;
297 int irqval
= request_irq(dev
->irq
, ni65_interrupt
,0,
298 cards
[p
->cardno
].cardname
,dev
);
300 printk(KERN_ERR
"%s: unable to get IRQ %d (irqval=%d).\n",
301 dev
->name
,dev
->irq
, irqval
);
305 if(ni65_lance_reinit(dev
))
307 netif_start_queue(dev
);
312 free_irq(dev
->irq
,dev
);
318 * close interface (down)
320 static int ni65_close(struct net_device
*dev
)
322 struct priv
*p
= dev
->ml_priv
;
324 netif_stop_queue(dev
);
326 outw(inw(PORT
+L_RESET
),PORT
+L_RESET
); /* that's the hard way */
331 for(i
=0;i
<TMDNUM
;i
++)
334 dev_kfree_skb(p
->tmd_skb
[i
]);
335 p
->tmd_skb
[i
] = NULL
;
340 free_irq(dev
->irq
,dev
);
344 static void cleanup_card(struct net_device
*dev
)
346 struct priv
*p
= dev
->ml_priv
;
347 disable_dma(dev
->dma
);
349 release_region(dev
->base_addr
, cards
[p
->cardno
].total_size
);
353 /* set: io,irq,dma or set it when calling insmod */
359 * Probe The Card (not the lance-chip)
361 struct net_device
* __init
ni65_probe(int unit
)
363 struct net_device
*dev
= alloc_etherdev(0);
364 static const int ports
[] = { 0x360, 0x300, 0x320, 0x340, 0 };
369 return ERR_PTR(-ENOMEM
);
372 sprintf(dev
->name
, "eth%d", unit
);
373 netdev_boot_setup_check(dev
);
380 if (dev
->base_addr
> 0x1ff) { /* Check a single specified location. */
381 err
= ni65_probe1(dev
, dev
->base_addr
);
382 } else if (dev
->base_addr
> 0) { /* Don't probe at all. */
385 for (port
= ports
; *port
&& ni65_probe1(dev
, *port
); port
++)
393 err
= register_netdev(dev
);
404 static const struct net_device_ops ni65_netdev_ops
= {
405 .ndo_open
= ni65_open
,
406 .ndo_stop
= ni65_close
,
407 .ndo_start_xmit
= ni65_send_packet
,
408 .ndo_tx_timeout
= ni65_timeout
,
409 .ndo_set_rx_mode
= set_multicast_list
,
410 .ndo_change_mtu
= eth_change_mtu
,
411 .ndo_set_mac_address
= eth_mac_addr
,
412 .ndo_validate_addr
= eth_validate_addr
,
416 * this is the real card probe ..
418 static int __init
ni65_probe1(struct net_device
*dev
,int ioaddr
)
427 for(i
=0;i
<NUM_CARDS
;i
++) {
428 if(!request_region(ioaddr
, cards
[i
].total_size
, cards
[i
].cardname
))
430 if(cards
[i
].id_offset
>= 0) {
431 if(inb(ioaddr
+cards
[i
].id_offset
+0) != cards
[i
].id0
||
432 inb(ioaddr
+cards
[i
].id_offset
+1) != cards
[i
].id1
) {
433 release_region(ioaddr
, cards
[i
].total_size
);
437 if(cards
[i
].vendor_id
) {
439 if(inb(ioaddr
+cards
[i
].addr_offset
+j
) != cards
[i
].vendor_id
[j
]) {
440 release_region(ioaddr
, cards
[i
].total_size
);
450 dev
->dev_addr
[j
] = inb(ioaddr
+cards
[i
].addr_offset
+j
);
452 if( (j
=ni65_alloc_buffer(dev
)) < 0) {
453 release_region(ioaddr
, cards
[i
].total_size
);
457 p
->cmdr_addr
= ioaddr
+ cards
[i
].cmd_offset
;
459 spin_lock_init(&p
->ring_lock
);
461 printk(KERN_INFO
"%s: %s found at %#3x, ", dev
->name
, cards
[p
->cardno
].cardname
, ioaddr
);
463 outw(inw(PORT
+L_RESET
),PORT
+L_RESET
); /* first: reset the card */
464 if( (j
=readreg(CSR0
)) != 0x4) {
466 printk(KERN_ERR
"%s: Can't RESET card: %04x\n", dev
->name
, j
);
468 release_region(ioaddr
, cards
[p
->cardno
].total_size
);
472 outw(88,PORT
+L_ADDRREG
);
473 if(inw(PORT
+L_ADDRREG
) == 88) {
475 v
= inw(PORT
+L_DATAREG
);
477 outw(89,PORT
+L_ADDRREG
);
478 v
|= inw(PORT
+L_DATAREG
);
479 printk("Version %#08lx, ",v
);
480 p
->features
= INIT_RING_BEFORE_START
;
483 printk("ancient LANCE, ");
487 if(test_bit(0,&cards
[i
].config
)) {
488 dev
->irq
= irqtab
[(inw(ioaddr
+L_CONFIG
)>>2)&3];
489 dev
->dma
= dmatab
[inw(ioaddr
+L_CONFIG
)&3];
490 printk("IRQ %d (from card), DMA %d (from card).\n",dev
->irq
,dev
->dma
);
494 /* 'stuck test' from lance.c */
495 unsigned long dma_channels
=
496 ((inb(DMA1_STAT_REG
) >> 4) & 0x0f)
497 | (inb(DMA2_STAT_REG
) & 0xf0);
500 if(test_bit(dma
,&dma_channels
) || request_dma(dma
,"ni6510"))
503 flags
=claim_dma_lock();
505 set_dma_mode(dma
,DMA_MODE_CASCADE
);
507 release_dma_lock(flags
);
509 ni65_init_lance(p
,dev
->dev_addr
,0,0); /* trigger memory access */
511 flags
=claim_dma_lock();
514 release_dma_lock(flags
);
516 if(readreg(CSR0
) & CSR0_IDON
)
521 printk(KERN_ERR
"%s: Can't detect DMA channel!\n", dev
->name
);
523 release_region(ioaddr
, cards
[p
->cardno
].total_size
);
526 dev
->dma
= dmatab
[i
];
527 printk("DMA %d (autodetected), ",dev
->dma
);
530 printk("DMA %d (assigned), ",dev
->dma
);
534 unsigned long irq_mask
;
536 ni65_init_lance(p
,dev
->dev_addr
,0,0);
537 irq_mask
= probe_irq_on();
538 writereg(CSR0_INIT
|CSR0_INEA
,CSR0
); /* trigger interrupt */
540 dev
->irq
= probe_irq_off(irq_mask
);
543 printk("Failed to detect IRQ line!\n");
545 release_region(ioaddr
, cards
[p
->cardno
].total_size
);
548 printk("IRQ %d (autodetected).\n",dev
->irq
);
551 printk("IRQ %d (assigned).\n",dev
->irq
);
554 if(request_dma(dev
->dma
, cards
[p
->cardno
].cardname
) != 0)
556 printk(KERN_ERR
"%s: Can't request dma-channel %d\n",dev
->name
,(int) dev
->dma
);
558 release_region(ioaddr
, cards
[p
->cardno
].total_size
);
562 dev
->base_addr
= ioaddr
;
563 dev
->netdev_ops
= &ni65_netdev_ops
;
564 dev
->watchdog_timeo
= HZ
/2;
566 return 0; /* everything is OK */
570 * set lance register and trigger init
572 static void ni65_init_lance(struct priv
*p
,unsigned char *daddr
,int filter
,int mode
)
577 writereg(CSR0_CLRALL
|CSR0_STOP
,CSR0
);
580 p
->ib
.eaddr
[i
] = daddr
[i
];
583 p
->ib
.filter
[i
] = filter
;
586 p
->ib
.trp
= (u32
) isa_virt_to_bus(p
->tmdhead
) | TMDNUMMASK
;
587 p
->ib
.rrp
= (u32
) isa_virt_to_bus(p
->rmdhead
) | RMDNUMMASK
;
588 writereg(0,CSR3
); /* busmaster/no word-swap */
589 pib
= (u32
) isa_virt_to_bus(&p
->ib
);
590 writereg(pib
& 0xffff,CSR1
);
591 writereg(pib
>> 16,CSR2
);
593 writereg(CSR0_INIT
,CSR0
); /* this changes L_ADDRREG to CSR0 */
598 if(inw(PORT
+L_DATAREG
) & (CSR0_IDON
| CSR0_MERR
) )
599 break; /* init ok ? */
604 * allocate memory area and check the 16MB border
606 static void *ni65_alloc_mem(struct net_device
*dev
,char *what
,int size
,int type
)
608 struct sk_buff
*skb
=NULL
;
613 ret
= skb
= alloc_skb(2+16+size
,GFP_KERNEL
|GFP_DMA
);
615 printk(KERN_WARNING
"%s: unable to allocate %s memory.\n",dev
->name
,what
);
618 skb_reserve(skb
,2+16);
619 skb_put(skb
,R_BUF_SIZE
); /* grab the whole space .. (not necessary) */
623 ret
= ptr
= kmalloc(T_BUF_SIZE
,GFP_KERNEL
| GFP_DMA
);
625 printk(KERN_WARNING
"%s: unable to allocate %s memory.\n",dev
->name
,what
);
629 if( (u32
) virt_to_phys(ptr
+size
) > 0x1000000) {
630 printk(KERN_WARNING
"%s: unable to allocate %s memory in lower 16MB!\n",dev
->name
,what
);
641 * allocate all memory structures .. send/recv buffers etc ...
643 static int ni65_alloc_buffer(struct net_device
*dev
)
650 * we need 8-aligned memory ..
652 ptr
= ni65_alloc_mem(dev
,"BUFFER",sizeof(struct priv
)+8,0);
656 p
= dev
->ml_priv
= (struct priv
*) (((unsigned long) ptr
+ 7) & ~0x7);
657 memset((char *)p
, 0, sizeof(struct priv
));
660 for(i
=0;i
<TMDNUM
;i
++)
663 p
->tmd_skb
[i
] = NULL
;
665 p
->tmdbounce
[i
] = ni65_alloc_mem(dev
,"XMIT",T_BUF_SIZE
,0);
666 if(!p
->tmdbounce
[i
]) {
672 for(i
=0;i
<RMDNUM
;i
++)
675 p
->recv_skb
[i
] = ni65_alloc_mem(dev
,"RECV",R_BUF_SIZE
,1);
676 if(!p
->recv_skb
[i
]) {
681 p
->recvbounce
[i
] = ni65_alloc_mem(dev
,"RECV",R_BUF_SIZE
,0);
682 if(!p
->recvbounce
[i
]) {
689 return 0; /* everything is OK */
693 * free buffers and private struct
695 static void ni65_free_buffer(struct priv
*p
)
702 for(i
=0;i
<TMDNUM
;i
++) {
703 kfree(p
->tmdbounce
[i
]);
706 dev_kfree_skb(p
->tmd_skb
[i
]);
710 for(i
=0;i
<RMDNUM
;i
++)
714 dev_kfree_skb(p
->recv_skb
[i
]);
716 kfree(p
->recvbounce
[i
]);
724 * stop and (re)start lance .. e.g after an error
726 static void ni65_stop_start(struct net_device
*dev
,struct priv
*p
)
728 int csr0
= CSR0_INEA
;
730 writedatareg(CSR0_STOP
);
733 printk(KERN_DEBUG
"ni65_stop_start\n");
735 if(p
->features
& INIT_RING_BEFORE_START
) {
738 struct sk_buff
*skb_save
[TMDNUM
];
740 unsigned long buffer
[TMDNUM
];
745 if((p
->tmdhead
[p
->tmdlast
].u
.s
.status
& XMIT_OWN
))
747 p
->tmdlast
= (p
->tmdlast
+ 1) & (TMDNUM
-1);
748 if(p
->tmdlast
== p
->tmdnum
)
753 for(i
=0;i
<TMDNUM
;i
++) {
754 struct tmd
*tmdp
= p
->tmdhead
+ i
;
756 skb_save
[i
] = p
->tmd_skb
[i
];
758 buffer
[i
] = (u32
) isa_bus_to_virt(tmdp
->u
.buffer
);
759 blen
[i
] = tmdp
->blen
;
760 tmdp
->u
.s
.status
= 0x0;
763 for(i
=0;i
<RMDNUM
;i
++) {
764 struct rmd
*rmdp
= p
->rmdhead
+ i
;
765 rmdp
->u
.s
.status
= RCV_OWN
;
767 p
->tmdnum
= p
->xmit_queued
= 0;
768 writedatareg(CSR0_STRT
| csr0
);
770 for(i
=0;i
<TMDNUM
;i
++) {
771 int num
= (i
+ p
->tmdlast
) & (TMDNUM
-1);
772 p
->tmdhead
[i
].u
.buffer
= (u32
) isa_virt_to_bus((char *)buffer
[num
]); /* status is part of buffer field */
773 p
->tmdhead
[i
].blen
= blen
[num
];
774 if(p
->tmdhead
[i
].u
.s
.status
& XMIT_OWN
) {
775 p
->tmdnum
= (p
->tmdnum
+ 1) & (TMDNUM
-1);
777 writedatareg(CSR0_TDMD
| CSR0_INEA
| csr0
);
780 p
->tmd_skb
[i
] = skb_save
[num
];
783 p
->rmdnum
= p
->tmdlast
= 0;
785 if (p
->tmdnum
|| !p
->xmit_queued
)
786 netif_wake_queue(dev
);
787 dev
->trans_start
= jiffies
; /* prevent tx timeout */
790 writedatareg(CSR0_STRT
| csr0
);
794 * init lance (write init-values .. init-buffers) (open-helper)
796 static int ni65_lance_reinit(struct net_device
*dev
)
799 struct priv
*p
= dev
->ml_priv
;
805 flags
=claim_dma_lock();
806 disable_dma(dev
->dma
); /* I've never worked with dma, but we do it like the packetdriver */
807 set_dma_mode(dev
->dma
,DMA_MODE_CASCADE
);
808 enable_dma(dev
->dma
);
809 release_dma_lock(flags
);
811 outw(inw(PORT
+L_RESET
),PORT
+L_RESET
); /* first: reset the card */
812 if( (i
=readreg(CSR0
) ) != 0x4)
814 printk(KERN_ERR
"%s: can't RESET %s card: %04x\n",dev
->name
,
815 cards
[p
->cardno
].cardname
,(int) i
);
816 flags
=claim_dma_lock();
817 disable_dma(dev
->dma
);
818 release_dma_lock(flags
);
822 p
->rmdnum
= p
->tmdnum
= p
->tmdlast
= p
->tmdbouncenum
= 0;
823 for(i
=0;i
<TMDNUM
;i
++)
825 struct tmd
*tmdp
= p
->tmdhead
+ i
;
828 dev_kfree_skb(p
->tmd_skb
[i
]);
829 p
->tmd_skb
[i
] = NULL
;
832 tmdp
->u
.buffer
= 0x0;
833 tmdp
->u
.s
.status
= XMIT_START
| XMIT_END
;
834 tmdp
->blen
= tmdp
->status2
= 0;
837 for(i
=0;i
<RMDNUM
;i
++)
839 struct rmd
*rmdp
= p
->rmdhead
+ i
;
841 rmdp
->u
.buffer
= (u32
) isa_virt_to_bus(p
->recv_skb
[i
]->data
);
843 rmdp
->u
.buffer
= (u32
) isa_virt_to_bus(p
->recvbounce
[i
]);
845 rmdp
->blen
= -(R_BUF_SIZE
-8);
847 rmdp
->u
.s
.status
= RCV_OWN
;
850 if(dev
->flags
& IFF_PROMISC
)
851 ni65_init_lance(p
,dev
->dev_addr
,0x00,M_PROM
);
852 else if (netdev_mc_count(dev
) || dev
->flags
& IFF_ALLMULTI
)
853 ni65_init_lance(p
,dev
->dev_addr
,0xff,0x0);
855 ni65_init_lance(p
,dev
->dev_addr
,0x00,0x00);
858 * ni65_set_lance_mem() sets L_ADDRREG to CSR0
859 * NOW, WE WILL NEVER CHANGE THE L_ADDRREG, CSR0 IS ALWAYS SELECTED
862 if(inw(PORT
+L_DATAREG
) & CSR0_IDON
) {
863 ni65_set_performance(p
);
864 /* init OK: start lance , enable interrupts */
865 writedatareg(CSR0_CLRALL
| CSR0_INEA
| CSR0_STRT
);
868 printk(KERN_ERR
"%s: can't init lance, status: %04x\n",dev
->name
,(int) inw(PORT
+L_DATAREG
));
869 flags
=claim_dma_lock();
870 disable_dma(dev
->dma
);
871 release_dma_lock(flags
);
872 return 0; /* ->Error */
878 static irqreturn_t
ni65_interrupt(int irq
, void * dev_id
)
881 struct net_device
*dev
= dev_id
;
887 spin_lock(&p
->ring_lock
);
890 csr0
= inw(PORT
+L_DATAREG
);
893 writedatareg( (csr0
& CSR0_CLRALL
) ); /* ack interrupts, disable int. */
895 writedatareg( (csr0
& CSR0_CLRALL
) | CSR0_INEA
); /* ack interrupts, interrupts enabled */
898 if(!(csr0
& (CSR0_ERR
| CSR0_RINT
| CSR0_TINT
)))
901 if(csr0
& CSR0_RINT
) /* RECV-int? */
902 ni65_recv_intr(dev
,csr0
);
903 if(csr0
& CSR0_TINT
) /* XMIT-int? */
904 ni65_xmit_intr(dev
,csr0
);
909 printk(KERN_ERR
"%s: general error: %04x.\n",dev
->name
,csr0
);
911 dev
->stats
.tx_errors
++;
912 if(csr0
& CSR0_MISS
) {
914 for(i
=0;i
<RMDNUM
;i
++)
915 printk("%02x ",p
->rmdhead
[i
].u
.s
.status
);
917 dev
->stats
.rx_errors
++;
919 if(csr0
& CSR0_MERR
) {
921 printk(KERN_ERR
"%s: Ooops .. memory error: %04x.\n",dev
->name
,csr0
);
922 ni65_stop_start(dev
,p
);
927 #ifdef RCV_PARANOIA_CHECK
930 for(j
=0;j
<RMDNUM
;j
++)
933 for(i
=RMDNUM
-1;i
>0;i
--) {
934 num2
= (p
->rmdnum
+ i
) & (RMDNUM
-1);
935 if(!(p
->rmdhead
[num2
].u
.s
.status
& RCV_OWN
))
941 for(k
=0;k
<RMDNUM
;k
++) {
942 num1
= (p
->rmdnum
+ k
) & (RMDNUM
-1);
943 if(!(p
->rmdhead
[num1
].u
.s
.status
& RCV_OWN
))
953 for(k
=0;k
<RMDNUM
;k
++) {
954 sprintf(buf1
,"%02x ",(p
->rmdhead
[k
].u
.s
.status
)); /* & RCV_OWN) ); */
958 printk(KERN_ERR
"%s: Ooops, receive ring corrupted %2d %2d | %s\n",dev
->name
,p
->rmdnum
,i
,buf
);
962 ni65_recv_intr(dev
,csr0
);
963 if((p
->rmdhead
[num2
].u
.s
.status
& RCV_OWN
))
964 break; /* ok, we are 'in sync' again */
972 if( (csr0
& (CSR0_RXON
| CSR0_TXON
)) != (CSR0_RXON
| CSR0_TXON
) ) {
973 printk(KERN_DEBUG
"%s: RX or TX was offline -> restart\n",dev
->name
);
974 ni65_stop_start(dev
,p
);
977 writedatareg(CSR0_INEA
);
979 spin_unlock(&p
->ring_lock
);
984 * We have received an Xmit-Interrupt ..
985 * send a new packet if necessary
987 static void ni65_xmit_intr(struct net_device
*dev
,int csr0
)
989 struct priv
*p
= dev
->ml_priv
;
991 while(p
->xmit_queued
)
993 struct tmd
*tmdp
= p
->tmdhead
+ p
->tmdlast
;
994 int tmdstat
= tmdp
->u
.s
.status
;
996 if(tmdstat
& XMIT_OWN
)
999 if(tmdstat
& XMIT_ERR
)
1002 if(tmdp
->status2
& XMIT_TDRMASK
&& debuglevel
> 3)
1003 printk(KERN_ERR
"%s: tdr-problems (e.g. no resistor)\n",dev
->name
);
1005 /* checking some errors */
1006 if(tmdp
->status2
& XMIT_RTRY
)
1007 dev
->stats
.tx_aborted_errors
++;
1008 if(tmdp
->status2
& XMIT_LCAR
)
1009 dev
->stats
.tx_carrier_errors
++;
1010 if(tmdp
->status2
& (XMIT_BUFF
| XMIT_UFLO
)) {
1011 /* this stops the xmitter */
1012 dev
->stats
.tx_fifo_errors
++;
1014 printk(KERN_ERR
"%s: Xmit FIFO/BUFF error\n",dev
->name
);
1015 if(p
->features
& INIT_RING_BEFORE_START
) {
1016 tmdp
->u
.s
.status
= XMIT_OWN
| XMIT_START
| XMIT_END
; /* test: resend this frame */
1017 ni65_stop_start(dev
,p
);
1018 break; /* no more Xmit processing .. */
1021 ni65_stop_start(dev
,p
);
1024 printk(KERN_ERR
"%s: xmit-error: %04x %02x-%04x\n",dev
->name
,csr0
,(int) tmdstat
,(int) tmdp
->status2
);
1025 if(!(csr0
& CSR0_BABL
)) /* don't count errors twice */
1026 dev
->stats
.tx_errors
++;
1030 dev
->stats
.tx_bytes
-= (short)(tmdp
->blen
);
1031 dev
->stats
.tx_packets
++;
1035 if(p
->tmd_skb
[p
->tmdlast
]) {
1036 dev_kfree_skb_irq(p
->tmd_skb
[p
->tmdlast
]);
1037 p
->tmd_skb
[p
->tmdlast
] = NULL
;
1041 p
->tmdlast
= (p
->tmdlast
+ 1) & (TMDNUM
-1);
1042 if(p
->tmdlast
== p
->tmdnum
)
1045 netif_wake_queue(dev
);
1049 * We have received a packet
1051 static void ni65_recv_intr(struct net_device
*dev
,int csr0
)
1056 struct priv
*p
= dev
->ml_priv
;
1058 rmdp
= p
->rmdhead
+ p
->rmdnum
;
1059 while(!( (rmdstat
= rmdp
->u
.s
.status
) & RCV_OWN
))
1062 if( (rmdstat
& (RCV_START
| RCV_END
| RCV_ERR
)) != (RCV_START
| RCV_END
) ) /* error or oversized? */
1064 if(!(rmdstat
& RCV_ERR
)) {
1065 if(rmdstat
& RCV_START
)
1067 dev
->stats
.rx_length_errors
++;
1068 printk(KERN_ERR
"%s: recv, packet too long: %d\n",dev
->name
,rmdp
->mlen
& 0x0fff);
1073 printk(KERN_ERR
"%s: receive-error: %04x, lance-status: %04x/%04x\n",
1074 dev
->name
,(int) rmdstat
,csr0
,(int) inw(PORT
+L_DATAREG
) );
1075 if(rmdstat
& RCV_FRAM
)
1076 dev
->stats
.rx_frame_errors
++;
1077 if(rmdstat
& RCV_OFLO
)
1078 dev
->stats
.rx_over_errors
++;
1079 if(rmdstat
& RCV_CRC
)
1080 dev
->stats
.rx_crc_errors
++;
1081 if(rmdstat
& RCV_BUF_ERR
)
1082 dev
->stats
.rx_fifo_errors
++;
1084 if(!(csr0
& CSR0_MISS
)) /* don't count errors twice */
1085 dev
->stats
.rx_errors
++;
1087 else if( (len
= (rmdp
->mlen
& 0x0fff) - 4) >= 60)
1090 struct sk_buff
*skb
= alloc_skb(R_BUF_SIZE
+2+16,GFP_ATOMIC
);
1092 skb_reserve(skb
,16);
1094 struct sk_buff
*skb
= dev_alloc_skb(len
+2);
1100 if( (unsigned long) (skb
->data
+ R_BUF_SIZE
) > 0x1000000) {
1102 skb_copy_to_linear_data(skb
, (unsigned char *)(p
->recv_skb
[p
->rmdnum
]->data
),len
);
1105 struct sk_buff
*skb1
= p
->recv_skb
[p
->rmdnum
];
1106 skb_put(skb
,R_BUF_SIZE
);
1107 p
->recv_skb
[p
->rmdnum
] = skb
;
1108 rmdp
->u
.buffer
= (u32
) isa_virt_to_bus(skb
->data
);
1114 skb_copy_to_linear_data(skb
, (unsigned char *) p
->recvbounce
[p
->rmdnum
],len
);
1116 dev
->stats
.rx_packets
++;
1117 dev
->stats
.rx_bytes
+= len
;
1118 skb
->protocol
=eth_type_trans(skb
,dev
);
1123 printk(KERN_ERR
"%s: can't alloc new sk_buff\n",dev
->name
);
1124 dev
->stats
.rx_dropped
++;
1128 printk(KERN_INFO
"%s: received runt packet\n",dev
->name
);
1129 dev
->stats
.rx_errors
++;
1131 rmdp
->blen
= -(R_BUF_SIZE
-8);
1133 rmdp
->u
.s
.status
= RCV_OWN
; /* change owner */
1134 p
->rmdnum
= (p
->rmdnum
+ 1) & (RMDNUM
-1);
1135 rmdp
= p
->rmdhead
+ p
->rmdnum
;
1143 static void ni65_timeout(struct net_device
*dev
)
1146 struct priv
*p
= dev
->ml_priv
;
1148 printk(KERN_ERR
"%s: xmitter timed out, try to restart!\n",dev
->name
);
1149 for(i
=0;i
<TMDNUM
;i
++)
1150 printk("%02x ",p
->tmdhead
[i
].u
.s
.status
);
1152 ni65_lance_reinit(dev
);
1153 dev
->trans_start
= jiffies
; /* prevent tx timeout */
1154 netif_wake_queue(dev
);
1161 static netdev_tx_t
ni65_send_packet(struct sk_buff
*skb
,
1162 struct net_device
*dev
)
1164 struct priv
*p
= dev
->ml_priv
;
1166 netif_stop_queue(dev
);
1168 if (test_and_set_bit(0, (void*)&p
->lock
)) {
1169 printk(KERN_ERR
"%s: Queue was locked.\n", dev
->name
);
1170 return NETDEV_TX_BUSY
;
1174 short len
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
1176 unsigned long flags
;
1179 if( (unsigned long) (skb
->data
+ skb
->len
) > 0x1000000) {
1182 skb_copy_from_linear_data(skb
, p
->tmdbounce
[p
->tmdbouncenum
],
1183 skb
->len
> T_BUF_SIZE
? T_BUF_SIZE
:
1186 memset((char *)p
->tmdbounce
[p
->tmdbouncenum
]+skb
->len
, 0, len
-skb
->len
);
1187 dev_kfree_skb (skb
);
1189 spin_lock_irqsave(&p
->ring_lock
, flags
);
1190 tmdp
= p
->tmdhead
+ p
->tmdnum
;
1191 tmdp
->u
.buffer
= (u32
) isa_virt_to_bus(p
->tmdbounce
[p
->tmdbouncenum
]);
1192 p
->tmdbouncenum
= (p
->tmdbouncenum
+ 1) & (TMDNUM
- 1);
1197 spin_lock_irqsave(&p
->ring_lock
, flags
);
1199 tmdp
= p
->tmdhead
+ p
->tmdnum
;
1200 tmdp
->u
.buffer
= (u32
) isa_virt_to_bus(skb
->data
);
1201 p
->tmd_skb
[p
->tmdnum
] = skb
;
1206 tmdp
->u
.s
.status
= XMIT_OWN
| XMIT_START
| XMIT_END
;
1207 writedatareg(CSR0_TDMD
| CSR0_INEA
); /* enable xmit & interrupt */
1210 p
->tmdnum
= (p
->tmdnum
+ 1) & (TMDNUM
-1);
1212 if(p
->tmdnum
!= p
->tmdlast
)
1213 netif_wake_queue(dev
);
1217 spin_unlock_irqrestore(&p
->ring_lock
, flags
);
1220 return NETDEV_TX_OK
;
1223 static void set_multicast_list(struct net_device
*dev
)
1225 if(!ni65_lance_reinit(dev
))
1226 printk(KERN_ERR
"%s: Can't switch card into MC mode!\n",dev
->name
);
1227 netif_wake_queue(dev
);
1231 static struct net_device
*dev_ni65
;
1233 module_param(irq
, int, 0);
1234 module_param(io
, int, 0);
1235 module_param(dma
, int, 0);
1236 MODULE_PARM_DESC(irq
, "ni6510 IRQ number (ignored for some cards)");
1237 MODULE_PARM_DESC(io
, "ni6510 I/O base address");
1238 MODULE_PARM_DESC(dma
, "ni6510 ISA DMA channel (ignored for some cards)");
1240 int __init
init_module(void)
1242 dev_ni65
= ni65_probe(-1);
1243 return IS_ERR(dev_ni65
) ? PTR_ERR(dev_ni65
) : 0;
1246 void __exit
cleanup_module(void)
1248 unregister_netdev(dev_ni65
);
1249 cleanup_card(dev_ni65
);
1250 free_netdev(dev_ni65
);
1254 MODULE_LICENSE("GPL");