2 * net-3-driver for the NI5210 card (i82586 Ethernet chip)
4 * This is an extension to the Linux operating system, and is covered by the
5 * same GNU General Public License that covers that work.
7 * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later)
8 * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de)
9 * [feel free to mail ....]
11 * when using as module: (no autoprobing!)
13 * insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000
15 * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!.
17 * If you find a bug, please report me:
18 * The kernel panic output and any kmsg from the ni52 driver
19 * the ni5210-driver-version and the linux-kernel version
20 * how many shared memory (memsize) on the netcard,
21 * bootprom: yes/no, base_addr, mem_start
22 * maybe the ni5210-card revision and the i82586 version
24 * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340
25 * mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000,
26 * 0xd8000,0xcc000,0xce000,0xda000,0xdc000
29 * skeleton.c from Donald Becker
31 * I have also done a look in the following sources: (mail me if you need them)
32 * crynwr-packet-driver by Russ Nelson
33 * Garret A. Wollman's (fourth) i82586-driver for BSD
34 * (before getting an i82596 (yes 596 not 586) manual, the existing drivers
35 * helped me a lot to understand this tricky chip.)
38 * The internal sysbus seems to be slow. So we often lose packets because of
39 * overruns while receiving from a fast remote host.
40 * This can slow down TCP connections. Maybe the newer ni5210 cards are
41 * better. My experience is, that if a machine sends with more than about
42 * 500-600K/s the fifo/sysbus overflows.
45 * On fast networks, it's a (very) good idea to have 16K shared memory. With
46 * 8K, we can store only 4 receive frames, so it can (easily) happen that a
47 * remote machine 'overruns' our system.
49 * Known i82586/card problems (I'm sure, there are many more!):
50 * Running the NOP-mode, the i82586 sometimes seems to forget to report
51 * every xmit-interrupt until we restart the CU.
52 * Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit
53 * in the RBD-Struct which indicates an end of the RBD queue.
54 * Instead, the RU fetches another (randomly selected and
55 * usually used) RBD and begins to fill it. (Maybe, this happens only if
56 * the last buffer from the previous RFD fits exact into the queue and
57 * the next RFD can't fetch an initial RBD. Anyone knows more? )
59 * results from ftp performance tests with Linux 1.2.5
60 * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s)
61 * sending in NOP-mode: peak performance up to 530K/s (but better don't
66 * 29.Sept.96: virt_to_bus changes for new memory scheme
67 * 19.Feb.96: more Mcast changes, module support (MH)
69 * 18.Nov.95: Mcast changes (AC).
71 * 23.April.95: fixed(?) receiving problems by configuring a RFD more
72 * than the number of RBD's. Can maybe cause other problems.
73 * 18.April.95: Added MODULE support (MH)
74 * 17.April.95: MC related changes in init586() and set_multicast_list().
75 * removed use of 'jiffies' in init586() (MH)
77 * 19.Sep.94: Added Multicast support (not tested yet) (MH)
79 * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.
80 * Now, every RFD has exact one RBD. (MH)
82 * 14.Sep.94: added promiscuous mode, a few cleanups (MH)
84 * 19.Aug.94: changed request_irq() parameter (MH)
86 * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH)
88 * 19.July.94: lotsa cleanups .. (MH)
90 * 17.July.94: some patches ... verified to run with 1.1.29 (MH)
92 * 4.July.94: patches for Linux 1.1.24 (MH)
94 * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
96 * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff,
99 * < 30.Sep.93: first versions
102 static int debuglevel
; /* debug-printk 0: off 1: a few 2: more */
103 static int automatic_resume
; /* experimental .. better should be zero */
104 static int rfdadd
; /* rfdadd=1 may be better for 8K MEM cards */
105 static int fifo
= 0x8; /* don't change */
107 #include <linux/module.h>
108 #include <linux/kernel.h>
109 #include <linux/string.h>
110 #include <linux/errno.h>
111 #include <linux/ioport.h>
112 #include <linux/interrupt.h>
113 #include <linux/delay.h>
114 #include <linux/init.h>
115 #include <linux/bitops.h>
118 #include <linux/netdevice.h>
119 #include <linux/etherdevice.h>
120 #include <linux/skbuff.h>
124 #define DRV_NAME "ni52"
126 #define DEBUG /* debug on */
127 #define SYSBUSVAL 1 /* 8 Bit */
129 #define ni_attn586() { outb(0, dev->base_addr + NI52_ATTENTION); }
130 #define ni_reset586() { outb(0, dev->base_addr + NI52_RESET); }
131 #define ni_disint() { outb(0, dev->base_addr + NI52_INTDIS); }
132 #define ni_enaint() { outb(0, dev->base_addr + NI52_INTENA); }
134 #define make32(ptr16) ((void __iomem *)(p->memtop + (short) (ptr16)))
135 #define make24(ptr32) ((char __iomem *)(ptr32)) - p->base
136 #define make16(ptr32) ((unsigned short) ((char __iomem *)(ptr32)\
139 /******************* how to calculate the buffers *****************************
141 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
142 * --------------- in a different (more stable?) mode. Only in this mode it's
143 * possible to configure the driver with 'NO_NOPCOMMANDS'
145 sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
146 sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
147 sizeof(rfd) = 24; sizeof(rbd) = 12;
148 sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
151 * if you don't know the driver, better do not change these values: */
153 #define RECV_BUFF_SIZE 1524 /* slightly oversized */
154 #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
155 #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
156 #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
157 #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
158 #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
160 /**************************************************************************/
163 #define NI52_TOTAL_SIZE 16
164 #define NI52_ADDR0 0x02
165 #define NI52_ADDR1 0x07
166 #define NI52_ADDR2 0x01
168 static int ni52_probe1(struct net_device
*dev
, int ioaddr
);
169 static irqreturn_t
ni52_interrupt(int irq
, void *dev_id
);
170 static int ni52_open(struct net_device
*dev
);
171 static int ni52_close(struct net_device
*dev
);
172 static netdev_tx_t
ni52_send_packet(struct sk_buff
*, struct net_device
*);
173 static struct net_device_stats
*ni52_get_stats(struct net_device
*dev
);
174 static void set_multicast_list(struct net_device
*dev
);
175 static void ni52_timeout(struct net_device
*dev
);
177 /* helper-functions */
178 static int init586(struct net_device
*dev
);
179 static int check586(struct net_device
*dev
, unsigned size
);
180 static void alloc586(struct net_device
*dev
);
181 static void startrecv586(struct net_device
*dev
);
182 static void __iomem
*alloc_rfa(struct net_device
*dev
, void __iomem
*ptr
);
183 static void ni52_rcv_int(struct net_device
*dev
);
184 static void ni52_xmt_int(struct net_device
*dev
);
185 static void ni52_rnr_int(struct net_device
*dev
);
188 struct net_device_stats stats
;
190 char __iomem
*mapped
;
191 char __iomem
*memtop
;
194 struct rfd_struct __iomem
*rfd_last
, *rfd_top
, *rfd_first
;
195 struct scp_struct __iomem
*scp
;
196 struct iscp_struct __iomem
*iscp
;
197 struct scb_struct __iomem
*scb
;
198 struct tbd_struct __iomem
*xmit_buffs
[NUM_XMIT_BUFFS
];
199 #if (NUM_XMIT_BUFFS == 1)
200 struct transmit_cmd_struct __iomem
*xmit_cmds
[2];
201 struct nop_cmd_struct __iomem
*nop_cmds
[2];
203 struct transmit_cmd_struct __iomem
*xmit_cmds
[NUM_XMIT_BUFFS
];
204 struct nop_cmd_struct __iomem
*nop_cmds
[NUM_XMIT_BUFFS
];
206 int nop_point
, num_recv_buffs
;
207 char __iomem
*xmit_cbuffs
[NUM_XMIT_BUFFS
];
208 int xmit_count
, xmit_last
;
211 /* wait for command with timeout: */
212 static void wait_for_scb_cmd(struct net_device
*dev
)
214 struct priv
*p
= netdev_priv(dev
);
216 for (i
= 0; i
< 16384; i
++) {
217 if (readb(&p
->scb
->cmd_cuc
) == 0)
221 printk(KERN_ERR
"%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",
222 dev
->name
, readb(&p
->scb
->cmd_cuc
), readb(&p
->scb
->cus
));
231 static void wait_for_scb_cmd_ruc(struct net_device
*dev
)
233 struct priv
*p
= netdev_priv(dev
);
235 for (i
= 0; i
< 16384; i
++) {
236 if (readb(&p
->scb
->cmd_ruc
) == 0)
240 printk(KERN_ERR
"%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",
241 dev
->name
, readb(&p
->scb
->cmd_ruc
),
242 readb(&p
->scb
->rus
));
251 static void wait_for_stat_compl(void __iomem
*p
)
253 struct nop_cmd_struct __iomem
*addr
= p
;
255 for (i
= 0; i
< 32767; i
++) {
256 if (readw(&((addr
)->cmd_status
)) & STAT_COMPL
)
262 /**********************************************
265 static int ni52_close(struct net_device
*dev
)
267 free_irq(dev
->irq
, dev
);
268 ni_reset586(); /* the hard way to stop the receiver */
269 netif_stop_queue(dev
);
273 /**********************************************
276 static int ni52_open(struct net_device
*dev
)
286 ret
= request_irq(dev
->irq
, ni52_interrupt
, 0, dev
->name
, dev
);
291 netif_start_queue(dev
);
292 return 0; /* most done by init */
295 static int check_iscp(struct net_device
*dev
, void __iomem
*addr
)
297 struct iscp_struct __iomem
*iscp
= addr
;
298 struct priv
*p
= netdev_priv(dev
);
299 memset_io(iscp
, 0, sizeof(struct iscp_struct
));
301 writel(make24(iscp
), &p
->scp
->iscp
);
302 writeb(1, &iscp
->busy
);
306 mdelay(32); /* wait a while... */
307 /* i82586 clears 'busy' after successful init */
308 if (readb(&iscp
->busy
))
313 /**********************************************
314 * Check to see if there's an 82586 out there.
316 static int check586(struct net_device
*dev
, unsigned size
)
318 struct priv
*p
= netdev_priv(dev
);
321 p
->mapped
= ioremap(dev
->mem_start
, size
);
325 p
->base
= p
->mapped
+ size
- 0x01000000;
326 p
->memtop
= p
->mapped
+ size
;
327 p
->scp
= (struct scp_struct __iomem
*)(p
->base
+ SCP_DEFAULT_ADDRESS
);
328 p
->scb
= (struct scb_struct __iomem
*) p
->mapped
;
329 p
->iscp
= (struct iscp_struct __iomem
*)p
->scp
- 1;
330 memset_io(p
->scp
, 0, sizeof(struct scp_struct
));
331 for (i
= 0; i
< sizeof(struct scp_struct
); i
++)
332 /* memory was writeable? */
333 if (readb((char __iomem
*)p
->scp
+ i
))
335 writeb(SYSBUSVAL
, &p
->scp
->sysbus
); /* 1 = 8Bit-Bus, 0 = 16 Bit */
336 if (readb(&p
->scp
->sysbus
) != SYSBUSVAL
)
339 if (!check_iscp(dev
, p
->mapped
))
341 if (!check_iscp(dev
, p
->iscp
))
349 /******************************************************************
350 * set iscp at the right place, called by ni52_probe1 and open586.
352 static void alloc586(struct net_device
*dev
)
354 struct priv
*p
= netdev_priv(dev
);
359 memset_io(p
->iscp
, 0, sizeof(struct iscp_struct
));
360 memset_io(p
->scp
, 0, sizeof(struct scp_struct
));
362 writel(make24(p
->iscp
), &p
->scp
->iscp
);
363 writeb(SYSBUSVAL
, &p
->scp
->sysbus
);
364 writew(make16(p
->scb
), &p
->iscp
->scb_offset
);
366 writeb(1, &p
->iscp
->busy
);
372 if (readb(&p
->iscp
->busy
))
373 printk(KERN_ERR
"%s: Init-Problems (alloc).\n", dev
->name
);
377 memset_io(p
->scb
, 0, sizeof(struct scb_struct
));
380 /* set: io,irq,memstart,memend or set it when calling insmod */
382 static int io
= 0x300;
383 static long memstart
; /* e.g 0xd0000 */
384 static long memend
; /* e.g 0xd4000 */
386 /**********************************************
387 * probe the ni5210-card
389 struct net_device
* __init
ni52_probe(int unit
)
391 struct net_device
*dev
= alloc_etherdev(sizeof(struct priv
));
392 static int ports
[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
398 return ERR_PTR(-ENOMEM
);
400 p
= netdev_priv(dev
);
403 sprintf(dev
->name
, "eth%d", unit
);
404 netdev_boot_setup_check(dev
);
407 memstart
= dev
->mem_start
;
408 memend
= dev
->mem_end
;
411 if (io
> 0x1ff) { /* Check a single specified location. */
412 err
= ni52_probe1(dev
, io
);
413 } else if (io
> 0) { /* Don't probe at all. */
416 for (port
= ports
; *port
&& ni52_probe1(dev
, *port
) ; port
++)
421 for (io
= 0x200; io
< 0x400 && ni52_probe1(dev
, io
); io
+= 8)
431 err
= register_netdev(dev
);
437 release_region(dev
->base_addr
, NI52_TOTAL_SIZE
);
443 static const struct net_device_ops ni52_netdev_ops
= {
444 .ndo_open
= ni52_open
,
445 .ndo_stop
= ni52_close
,
446 .ndo_get_stats
= ni52_get_stats
,
447 .ndo_tx_timeout
= ni52_timeout
,
448 .ndo_start_xmit
= ni52_send_packet
,
449 .ndo_set_multicast_list
= set_multicast_list
,
450 .ndo_change_mtu
= eth_change_mtu
,
451 .ndo_set_mac_address
= eth_mac_addr
,
452 .ndo_validate_addr
= eth_validate_addr
,
455 static int __init
ni52_probe1(struct net_device
*dev
, int ioaddr
)
458 struct priv
*priv
= netdev_priv(dev
);
460 dev
->base_addr
= ioaddr
;
462 dev
->mem_start
= memstart
;
463 dev
->mem_end
= memend
;
465 spin_lock_init(&priv
->spinlock
);
467 if (!request_region(ioaddr
, NI52_TOTAL_SIZE
, DRV_NAME
))
470 if (!(inb(ioaddr
+NI52_MAGIC1
) == NI52_MAGICVAL1
) ||
471 !(inb(ioaddr
+NI52_MAGIC2
) == NI52_MAGICVAL2
)) {
476 for (i
= 0; i
< ETH_ALEN
; i
++)
477 dev
->dev_addr
[i
] = inb(dev
->base_addr
+i
);
479 if (dev
->dev_addr
[0] != NI52_ADDR0
|| dev
->dev_addr
[1] != NI52_ADDR1
||
480 dev
->dev_addr
[2] != NI52_ADDR2
) {
485 printk(KERN_INFO
"%s: NI5210 found at %#3lx, ",
486 dev
->name
, dev
->base_addr
);
489 * check (or search) IO-Memory, 8K and 16K
492 size
= dev
->mem_end
- dev
->mem_start
;
493 if (size
!= 0x2000 && size
!= 0x4000) {
495 printk(KERN_ERR
"%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev
->name
, size
);
499 if (!check586(dev
, size
)) {
500 printk(KERN_ERR
"?memcheck, Can't find memory at 0x%lx with size %d!\n", dev
->mem_start
, size
);
505 if (dev
->mem_start
!= 0) {
506 /* no auto-mem-probe */
507 size
= 0x4000; /* check for 16K mem */
508 if (!check586(dev
, size
)) {
509 size
= 0x2000; /* check for 8K mem */
510 if (!check586(dev
, size
)) {
511 printk(KERN_ERR
"?memprobe, Can't find memory at 0x%lx!\n", dev
->mem_start
);
517 static const unsigned long memaddrs
[] = {
518 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
519 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
523 printk(KERN_ERR
"?memprobe, Can't find io-memory!\n");
527 dev
->mem_start
= memaddrs
[i
];
528 size
= 0x2000; /* check for 8K mem */
529 if (check586(dev
, size
))
532 size
= 0x4000; /* check for 16K mem */
533 if (check586(dev
, size
))
538 /* set mem_end showed by 'ifconfig' */
539 dev
->mem_end
= dev
->mem_start
+ size
;
544 /* set number of receive-buffs according to memsize */
546 priv
->num_recv_buffs
= NUM_RECV_BUFFS_8
;
548 priv
->num_recv_buffs
= NUM_RECV_BUFFS_16
;
550 printk(KERN_DEBUG
"Memaddr: 0x%lx, Memsize: %d, ",
551 dev
->mem_start
, size
);
554 unsigned long irq_mask
;
556 irq_mask
= probe_irq_on();
561 dev
->irq
= probe_irq_off(irq_mask
);
563 printk("?autoirq, Failed to detect IRQ line!\n");
565 iounmap(priv
->mapped
);
568 printk("IRQ %d (autodetected).\n", dev
->irq
);
572 printk("IRQ %d (assigned and not checked!).\n", dev
->irq
);
575 dev
->netdev_ops
= &ni52_netdev_ops
;
576 dev
->watchdog_timeo
= HZ
/20;
580 release_region(ioaddr
, NI52_TOTAL_SIZE
);
584 /**********************************************
585 * init the chip (ni52-interrupt should be disabled?!)
586 * needs a correct 'allocated' memory
589 static int init586(struct net_device
*dev
)
593 struct priv
*p
= netdev_priv(dev
);
594 struct configure_cmd_struct __iomem
*cfg_cmd
;
595 struct iasetup_cmd_struct __iomem
*ias_cmd
;
596 struct tdr_cmd_struct __iomem
*tdr_cmd
;
597 struct mcsetup_cmd_struct __iomem
*mc_cmd
;
598 struct dev_mc_list
*dmi
;
599 int num_addrs
= netdev_mc_count(dev
);
603 cfg_cmd
= ptr
; /* configure-command */
604 writew(0, &cfg_cmd
->cmd_status
);
605 writew(CMD_CONFIGURE
| CMD_LAST
, &cfg_cmd
->cmd_cmd
);
606 writew(0xFFFF, &cfg_cmd
->cmd_link
);
608 /* number of cfg bytes */
609 writeb(0x0a, &cfg_cmd
->byte_cnt
);
610 /* fifo-limit (8=tx:32/rx:64) */
611 writeb(fifo
, &cfg_cmd
->fifo
);
612 /* hold or discard bad recv frames (bit 7) */
613 writeb(0x40, &cfg_cmd
->sav_bf
);
614 /* addr_len |!src_insert |pre-len |loopback */
615 writeb(0x2e, &cfg_cmd
->adr_len
);
616 writeb(0x00, &cfg_cmd
->priority
);
617 writeb(0x60, &cfg_cmd
->ifs
);
618 writeb(0x00, &cfg_cmd
->time_low
);
619 writeb(0xf2, &cfg_cmd
->time_high
);
620 writeb(0x00, &cfg_cmd
->promisc
);
621 if (dev
->flags
& IFF_ALLMULTI
) {
622 int len
= ((char __iomem
*)p
->iscp
- (char __iomem
*)ptr
- 8) / 6;
623 if (num_addrs
> len
) {
624 printk(KERN_ERR
"%s: switching to promisc. mode\n",
626 writeb(0x01, &cfg_cmd
->promisc
);
629 if (dev
->flags
& IFF_PROMISC
)
630 writeb(0x01, &cfg_cmd
->promisc
);
631 writeb(0x00, &cfg_cmd
->carr_coll
);
632 writew(make16(cfg_cmd
), &p
->scb
->cbl_offset
);
633 writeb(0, &p
->scb
->cmd_ruc
);
635 writeb(CUC_START
, &p
->scb
->cmd_cuc
); /* cmd.-unit start */
638 wait_for_stat_compl(cfg_cmd
);
640 if ((readw(&cfg_cmd
->cmd_status
) & (STAT_OK
|STAT_COMPL
)) !=
641 (STAT_COMPL
|STAT_OK
)) {
642 printk(KERN_ERR
"%s: configure command failed: %x\n",
643 dev
->name
, readw(&cfg_cmd
->cmd_status
));
648 * individual address setup
653 writew(0, &ias_cmd
->cmd_status
);
654 writew(CMD_IASETUP
| CMD_LAST
, &ias_cmd
->cmd_cmd
);
655 writew(0xffff, &ias_cmd
->cmd_link
);
657 memcpy_toio(&ias_cmd
->iaddr
, (char *)dev
->dev_addr
, ETH_ALEN
);
659 writew(make16(ias_cmd
), &p
->scb
->cbl_offset
);
661 writeb(CUC_START
, &p
->scb
->cmd_cuc
); /* cmd.-unit start */
664 wait_for_stat_compl(ias_cmd
);
666 if ((readw(&ias_cmd
->cmd_status
) & (STAT_OK
|STAT_COMPL
)) !=
667 (STAT_OK
|STAT_COMPL
)) {
668 printk(KERN_ERR
"%s (ni52): individual address setup command failed: %04x\n", dev
->name
, readw(&ias_cmd
->cmd_status
));
673 * TDR, wire check .. e.g. no resistor e.t.c
678 writew(0, &tdr_cmd
->cmd_status
);
679 writew(CMD_TDR
| CMD_LAST
, &tdr_cmd
->cmd_cmd
);
680 writew(0xffff, &tdr_cmd
->cmd_link
);
681 writew(0, &tdr_cmd
->status
);
683 writew(make16(tdr_cmd
), &p
->scb
->cbl_offset
);
684 writeb(CUC_START
, &p
->scb
->cmd_cuc
); /* cmd.-unit start */
687 wait_for_stat_compl(tdr_cmd
);
689 if (!(readw(&tdr_cmd
->cmd_status
) & STAT_COMPL
))
690 printk(KERN_ERR
"%s: Problems while running the TDR.\n",
694 result
= readw(&tdr_cmd
->status
);
695 writeb(readb(&p
->scb
->cus
) & STAT_MASK
, &p
->scb
->cmd_cuc
);
696 ni_attn586(); /* ack the interrupts */
698 if (result
& TDR_LNK_OK
)
700 else if (result
& TDR_XCVR_PRB
)
701 printk(KERN_ERR
"%s: TDR: Transceiver problem. Check the cable(s)!\n",
703 else if (result
& TDR_ET_OPN
)
704 printk(KERN_ERR
"%s: TDR: No correct termination %d clocks away.\n",
705 dev
->name
, result
& TDR_TIMEMASK
);
706 else if (result
& TDR_ET_SRT
) {
707 /* time == 0 -> strange :-) */
708 if (result
& TDR_TIMEMASK
)
709 printk(KERN_ERR
"%s: TDR: Detected a short circuit %d clocks away.\n",
710 dev
->name
, result
& TDR_TIMEMASK
);
712 printk(KERN_ERR
"%s: TDR: Unknown status %04x\n",
719 if (num_addrs
&& !(dev
->flags
& IFF_PROMISC
)) {
721 writew(0, &mc_cmd
->cmd_status
);
722 writew(CMD_MCSETUP
| CMD_LAST
, &mc_cmd
->cmd_cmd
);
723 writew(0xffff, &mc_cmd
->cmd_link
);
724 writew(num_addrs
* 6, &mc_cmd
->mc_cnt
);
727 netdev_for_each_mc_addr(dmi
, dev
)
728 memcpy_toio(mc_cmd
->mc_list
[i
++], dmi
->dmi_addr
, 6);
730 writew(make16(mc_cmd
), &p
->scb
->cbl_offset
);
731 writeb(CUC_START
, &p
->scb
->cmd_cuc
);
734 wait_for_stat_compl(mc_cmd
);
736 if ((readw(&mc_cmd
->cmd_status
) & (STAT_COMPL
|STAT_OK
))
737 != (STAT_COMPL
|STAT_OK
))
738 printk(KERN_ERR
"%s: Can't apply multicast-address-list.\n", dev
->name
);
742 * alloc nop/xmit-cmds
744 #if (NUM_XMIT_BUFFS == 1)
745 for (i
= 0; i
< 2; i
++) {
746 p
->nop_cmds
[i
] = ptr
;
747 writew(CMD_NOP
, &p
->nop_cmds
[i
]->cmd_cmd
);
748 writew(0, &p
->nop_cmds
[i
]->cmd_status
);
749 writew(make16(p
->nop_cmds
[i
]), &p
->nop_cmds
[i
]->cmd_link
);
750 ptr
= ptr
+ sizeof(struct nop_cmd_struct
);
753 for (i
= 0; i
< NUM_XMIT_BUFFS
; i
++) {
754 p
->nop_cmds
[i
] = ptr
;
755 writew(CMD_NOP
, &p
->nop_cmds
[i
]->cmd_cmd
);
756 writew(0, &p
->nop_cmds
[i
]->cmd_status
);
757 writew(make16(p
->nop_cmds
[i
]), &p
->nop_cmds
[i
]->cmd_link
);
758 ptr
= ptr
+ sizeof(struct nop_cmd_struct
);
762 ptr
= alloc_rfa(dev
, ptr
); /* init receive-frame-area */
765 * alloc xmit-buffs / init xmit_cmds
767 for (i
= 0; i
< NUM_XMIT_BUFFS
; i
++) {
768 /* Transmit cmd/buff 0 */
769 p
->xmit_cmds
[i
] = ptr
;
770 ptr
= ptr
+ sizeof(struct transmit_cmd_struct
);
771 p
->xmit_cbuffs
[i
] = ptr
; /* char-buffs */
772 ptr
= ptr
+ XMIT_BUFF_SIZE
;
773 p
->xmit_buffs
[i
] = ptr
; /* TBD */
774 ptr
= ptr
+ sizeof(struct tbd_struct
);
775 if ((void __iomem
*)ptr
> (void __iomem
*)p
->iscp
) {
776 printk(KERN_ERR
"%s: not enough shared-mem for your configuration!\n",
780 memset_io(p
->xmit_cmds
[i
], 0,
781 sizeof(struct transmit_cmd_struct
));
782 memset_io(p
->xmit_buffs
[i
], 0,
783 sizeof(struct tbd_struct
));
784 writew(make16(p
->nop_cmds
[(i
+1)%NUM_XMIT_BUFFS
]),
785 &p
->xmit_cmds
[i
]->cmd_link
);
786 writew(STAT_COMPL
, &p
->xmit_cmds
[i
]->cmd_status
);
787 writew(CMD_XMIT
|CMD_INT
, &p
->xmit_cmds
[i
]->cmd_cmd
);
788 writew(make16(p
->xmit_buffs
[i
]), &p
->xmit_cmds
[i
]->tbd_offset
);
789 writew(0xffff, &p
->xmit_buffs
[i
]->next
);
790 writel(make24(p
->xmit_cbuffs
[i
]), &p
->xmit_buffs
[i
]->buffer
);
795 #ifndef NO_NOPCOMMANDS
800 * 'start transmitter'
802 #ifndef NO_NOPCOMMANDS
803 writew(make16(p
->nop_cmds
[0]), &p
->scb
->cbl_offset
);
804 writeb(CUC_START
, &p
->scb
->cmd_cuc
);
806 wait_for_scb_cmd(dev
);
808 writew(make16(p
->xmit_cmds
[0]), &p
->xmit_cmds
[0]->cmd_link
);
809 writew(CMD_XMIT
| CMD_SUSPEND
| CMD_INT
, &p
->xmit_cmds
[0]->cmd_cmd
);
815 writeb(readb(&p
->scb
->cus
) & STAT_MASK
, &p
->scb
->cmd_cuc
);
824 /******************************************************
825 * This is a helper routine for ni52_rnr_int() and init586().
826 * It sets up the Receive Frame Area (RFA).
829 static void __iomem
*alloc_rfa(struct net_device
*dev
, void __iomem
*ptr
)
831 struct rfd_struct __iomem
*rfd
= ptr
;
832 struct rbd_struct __iomem
*rbd
;
834 struct priv
*p
= netdev_priv(dev
);
837 sizeof(struct rfd_struct
) * (p
->num_recv_buffs
+ rfdadd
));
840 for (i
= 0; i
< (p
->num_recv_buffs
+ rfdadd
); i
++) {
841 writew(make16(rfd
+ (i
+1) % (p
->num_recv_buffs
+rfdadd
)),
843 writew(0xffff, &rfd
[i
].rbd_offset
);
846 writeb(RFD_SUSP
, &rfd
[p
->num_recv_buffs
-1+rfdadd
].last
);
848 ptr
= rfd
+ (p
->num_recv_buffs
+ rfdadd
);
851 ptr
= rbd
+ p
->num_recv_buffs
;
853 /* clr descriptors */
854 memset_io(rbd
, 0, sizeof(struct rbd_struct
) * (p
->num_recv_buffs
));
856 for (i
= 0; i
< p
->num_recv_buffs
; i
++) {
857 writew(make16(rbd
+ (i
+1) % p
->num_recv_buffs
), &rbd
[i
].next
);
858 writew(RECV_BUFF_SIZE
, &rbd
[i
].size
);
859 writel(make24(ptr
), &rbd
[i
].buffer
);
860 ptr
= ptr
+ RECV_BUFF_SIZE
;
862 p
->rfd_top
= p
->rfd_first
;
863 p
->rfd_last
= p
->rfd_first
+ (p
->num_recv_buffs
- 1 + rfdadd
);
865 writew(make16(p
->rfd_first
), &p
->scb
->rfa_offset
);
866 writew(make16(rbd
), &p
->rfd_first
->rbd_offset
);
872 /**************************************************
873 * Interrupt Handler ...
876 static irqreturn_t
ni52_interrupt(int irq
, void *dev_id
)
878 struct net_device
*dev
= dev_id
;
883 p
= netdev_priv(dev
);
888 spin_lock(&p
->spinlock
);
890 wait_for_scb_cmd(dev
); /* wait for last command */
892 while ((stat
= readb(&p
->scb
->cus
) & STAT_MASK
)) {
893 writeb(stat
, &p
->scb
->cmd_cuc
);
896 if (stat
& STAT_FR
) /* received a frame */
899 if (stat
& STAT_RNR
) { /* RU went 'not ready' */
901 if (readb(&p
->scb
->rus
) & RU_SUSPEND
) {
902 /* special case: RU_SUSPEND */
903 wait_for_scb_cmd(dev
);
904 writeb(RUC_RESUME
, &p
->scb
->cmd_ruc
);
906 wait_for_scb_cmd_ruc(dev
);
908 printk(KERN_ERR
"%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
909 dev
->name
, stat
, readb(&p
->scb
->rus
));
914 /* Command with I-bit set complete */
918 #ifndef NO_NOPCOMMANDS
919 if (stat
& STAT_CNA
) { /* CU went 'not ready' */
920 if (netif_running(dev
))
921 printk(KERN_ERR
"%s: oops! CU has left active state. stat: %04x/%02x.\n",
922 dev
->name
, stat
, readb(&p
->scb
->cus
));
929 /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
930 wait_for_scb_cmd(dev
);
931 if (readb(&p
->scb
->cmd_cuc
)) { /* timed out? */
932 printk(KERN_ERR
"%s: Acknowledge timed out.\n",
938 spin_unlock(&p
->spinlock
);
945 /*******************************************************
949 static void ni52_rcv_int(struct net_device
*dev
)
952 unsigned short totlen
;
954 struct rbd_struct __iomem
*rbd
;
955 struct priv
*p
= netdev_priv(dev
);
960 for (; (status
= readb(&p
->rfd_top
->stat_high
)) & RFD_COMPL
;) {
961 rbd
= make32(readw(&p
->rfd_top
->rbd_offset
));
962 if (status
& RFD_OK
) { /* frame received without error? */
963 totlen
= readw(&rbd
->status
);
964 if (totlen
& RBD_LAST
) {
965 /* the first and the last buffer? */
966 totlen
&= RBD_MASK
; /* length of this frame */
967 writew(0x00, &rbd
->status
);
968 skb
= (struct sk_buff
*)dev_alloc_skb(totlen
+2);
971 skb_put(skb
, totlen
);
972 memcpy_fromio(skb
->data
, p
->base
+ readl(&rbd
->buffer
), totlen
);
973 skb
->protocol
= eth_type_trans(skb
, dev
);
975 p
->stats
.rx_packets
++;
976 p
->stats
.rx_bytes
+= totlen
;
978 p
->stats
.rx_dropped
++;
981 /* free all RBD's until RBD_LAST is set */
983 while (!((rstat
= readw(&rbd
->status
)) & RBD_LAST
)) {
984 totlen
+= rstat
& RBD_MASK
;
986 printk(KERN_ERR
"%s: Whoops .. no end mark in RBD list\n", dev
->name
);
989 writew(0, &rbd
->status
);
990 rbd
= make32(readw(&rbd
->next
));
992 totlen
+= rstat
& RBD_MASK
;
993 writew(0, &rbd
->status
);
994 printk(KERN_ERR
"%s: received oversized frame! length: %d\n",
996 p
->stats
.rx_dropped
++;
998 } else {/* frame !(ok), only with 'save-bad-frames' */
999 printk(KERN_ERR
"%s: oops! rfd-error-status: %04x\n",
1001 p
->stats
.rx_errors
++;
1003 writeb(0, &p
->rfd_top
->stat_high
);
1004 writeb(RFD_SUSP
, &p
->rfd_top
->last
); /* maybe exchange by RFD_LAST */
1005 writew(0xffff, &p
->rfd_top
->rbd_offset
);
1006 writeb(0, &p
->rfd_last
->last
); /* delete RFD_SUSP */
1007 p
->rfd_last
= p
->rfd_top
;
1008 p
->rfd_top
= make32(readw(&p
->rfd_top
->next
)); /* step to next RFD */
1009 writew(make16(p
->rfd_top
), &p
->scb
->rfa_offset
);
1012 printk("%d", cnt
++);
1015 if (automatic_resume
) {
1016 wait_for_scb_cmd(dev
);
1017 writeb(RUC_RESUME
, &p
->scb
->cmd_ruc
);
1019 wait_for_scb_cmd_ruc(dev
);
1025 for (i
= 0; i
< 1024; i
++) {
1026 if (p
->rfd_top
->status
)
1030 printk(KERN_ERR
"%s: RU hasn't fetched next RFD (not busy/complete)\n", dev
->name
);
1038 /**********************************************************
1039 * handle 'Receiver went not ready'.
1042 static void ni52_rnr_int(struct net_device
*dev
)
1044 struct priv
*p
= netdev_priv(dev
);
1046 p
->stats
.rx_errors
++;
1048 wait_for_scb_cmd(dev
); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1049 writeb(RUC_ABORT
, &p
->scb
->cmd_ruc
); /* usually the RU is in the 'no resource'-state .. abort it now. */
1051 wait_for_scb_cmd_ruc(dev
); /* wait for accept cmd. */
1053 alloc_rfa(dev
, p
->rfd_first
);
1054 /* maybe add a check here, before restarting the RU */
1055 startrecv586(dev
); /* restart RU */
1057 printk(KERN_ERR
"%s: Receive-Unit restarted. Status: %04x\n",
1058 dev
->name
, readb(&p
->scb
->rus
));
1062 /**********************************************************
1063 * handle xmit - interrupt
1066 static void ni52_xmt_int(struct net_device
*dev
)
1069 struct priv
*p
= netdev_priv(dev
);
1074 status
= readw(&p
->xmit_cmds
[p
->xmit_last
]->cmd_status
);
1075 if (!(status
& STAT_COMPL
))
1076 printk(KERN_ERR
"%s: strange .. xmit-int without a 'COMPLETE'\n", dev
->name
);
1078 if (status
& STAT_OK
) {
1079 p
->stats
.tx_packets
++;
1080 p
->stats
.collisions
+= (status
& TCMD_MAXCOLLMASK
);
1082 p
->stats
.tx_errors
++;
1083 if (status
& TCMD_LATECOLL
) {
1084 printk(KERN_ERR
"%s: late collision detected.\n",
1086 p
->stats
.collisions
++;
1087 } else if (status
& TCMD_NOCARRIER
) {
1088 p
->stats
.tx_carrier_errors
++;
1089 printk(KERN_ERR
"%s: no carrier detected.\n",
1091 } else if (status
& TCMD_LOSTCTS
)
1092 printk(KERN_ERR
"%s: loss of CTS detected.\n",
1094 else if (status
& TCMD_UNDERRUN
) {
1095 p
->stats
.tx_fifo_errors
++;
1096 printk(KERN_ERR
"%s: DMA underrun detected.\n",
1098 } else if (status
& TCMD_MAXCOLL
) {
1099 printk(KERN_ERR
"%s: Max. collisions exceeded.\n",
1101 p
->stats
.collisions
+= 16;
1104 #if (NUM_XMIT_BUFFS > 1)
1105 if ((++p
->xmit_last
) == NUM_XMIT_BUFFS
)
1108 netif_wake_queue(dev
);
1111 /***********************************************************
1112 * (re)start the receiver
1115 static void startrecv586(struct net_device
*dev
)
1117 struct priv
*p
= netdev_priv(dev
);
1119 wait_for_scb_cmd(dev
);
1120 wait_for_scb_cmd_ruc(dev
);
1121 writew(make16(p
->rfd_first
), &p
->scb
->rfa_offset
);
1122 writeb(RUC_START
, &p
->scb
->cmd_ruc
);
1123 ni_attn586(); /* start cmd. */
1124 wait_for_scb_cmd_ruc(dev
);
1125 /* wait for accept cmd. (no timeout!!) */
1128 static void ni52_timeout(struct net_device
*dev
)
1130 struct priv
*p
= netdev_priv(dev
);
1131 #ifndef NO_NOPCOMMANDS
1132 if (readb(&p
->scb
->cus
) & CU_ACTIVE
) { /* COMMAND-UNIT active? */
1133 netif_wake_queue(dev
);
1135 printk(KERN_ERR
"%s: strange ... timeout with CU active?!?\n",
1137 printk(KERN_ERR
"%s: X0: %04x N0: %04x N1: %04x %d\n",
1138 dev
->name
, (int)p
->xmit_cmds
[0]->cmd_status
,
1139 readw(&p
->nop_cmds
[0]->cmd_status
),
1140 readw(&p
->nop_cmds
[1]->cmd_status
),
1143 writeb(CUC_ABORT
, &p
->scb
->cmd_cuc
);
1145 wait_for_scb_cmd(dev
);
1146 writew(make16(p
->nop_cmds
[p
->nop_point
]), &p
->scb
->cbl_offset
);
1147 writeb(CUC_START
, &p
->scb
->cmd_cuc
);
1149 wait_for_scb_cmd(dev
);
1150 dev
->trans_start
= jiffies
;
1156 printk(KERN_ERR
"%s: xmitter timed out, try to restart! stat: %02x\n",
1157 dev
->name
, readb(&p
->scb
->cus
));
1158 printk(KERN_ERR
"%s: command-stats: %04x %04x\n",
1160 readw(&p
->xmit_cmds
[0]->cmd_status
),
1161 readw(&p
->xmit_cmds
[1]->cmd_status
));
1162 printk(KERN_ERR
"%s: check, whether you set the right interrupt number!\n",
1168 dev
->trans_start
= jiffies
;
1171 /******************************************************
1175 static netdev_tx_t
ni52_send_packet(struct sk_buff
*skb
,
1176 struct net_device
*dev
)
1179 #ifndef NO_NOPCOMMANDS
1182 struct priv
*p
= netdev_priv(dev
);
1184 if (skb
->len
> XMIT_BUFF_SIZE
) {
1185 printk(KERN_ERR
"%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n", dev
->name
, XMIT_BUFF_SIZE
, skb
->len
);
1186 return NETDEV_TX_OK
;
1189 netif_stop_queue(dev
);
1191 memcpy_toio(p
->xmit_cbuffs
[p
->xmit_count
], skb
->data
, skb
->len
);
1193 if (len
< ETH_ZLEN
) {
1195 memset_io(p
->xmit_cbuffs
[p
->xmit_count
]+skb
->len
, 0,
1199 #if (NUM_XMIT_BUFFS == 1)
1200 # ifdef NO_NOPCOMMANDS
1203 if (readb(&p
->scb
->cus
) & CU_ACTIVE
) {
1204 printk(KERN_ERR
"%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev
->name
);
1205 printk(KERN_ERR
"%s: stat: %04x %04x\n",
1206 dev
->name
, readb(&p
->scb
->cus
),
1207 readw(&p
->xmit_cmds
[0]->cmd_status
));
1210 writew(TBD_LAST
| len
, &p
->xmit_buffs
[0]->size
);
1211 for (i
= 0; i
< 16; i
++) {
1212 writew(0, &p
->xmit_cmds
[0]->cmd_status
);
1213 wait_for_scb_cmd(dev
);
1214 if ((readb(&p
->scb
->cus
) & CU_STATUS
) == CU_SUSPEND
)
1215 writeb(CUC_RESUME
, &p
->scb
->cmd_cuc
);
1217 writew(make16(p
->xmit_cmds
[0]), &p
->scb
->cbl_offset
);
1218 writeb(CUC_START
, &p
->scb
->cmd_cuc
);
1221 dev
->trans_start
= jiffies
;
1224 wait_for_scb_cmd(dev
);
1225 /* test it, because CU sometimes doesn't start immediately */
1226 if (readb(&p
->scb
->cus
) & CU_ACTIVE
)
1228 if (readw(&p
->xmit_cmds
[0]->cmd_status
))
1231 printk(KERN_WARNING
"%s: Can't start transmit-command.\n", dev
->name
);
1234 next_nop
= (p
->nop_point
+ 1) & 0x1;
1235 writew(TBD_LAST
| len
, &p
->xmit_buffs
[0]->size
);
1236 writew(make16(p
->nop_cmds
[next_nop
]), &p
->xmit_cmds
[0]->cmd_link
);
1237 writew(make16(p
->nop_cmds
[next_nop
]),
1238 &p
->nop_cmds
[next_nop
]->cmd_link
);
1239 writew(0, &p
->xmit_cmds
[0]->cmd_status
);
1240 writew(0, &p
->nop_cmds
[next_nop
]->cmd_status
);
1242 writew(make16(p
->xmit_cmds
[0]), &p
->nop_cmds
[p
->nop_point
]->cmd_link
);
1243 dev
->trans_start
= jiffies
;
1244 p
->nop_point
= next_nop
;
1248 writew(TBD_LAST
| len
, &p
->xmit_buffs
[p
->xmit_count
]->size
);
1249 next_nop
= p
->xmit_count
+ 1
1250 if (next_nop
== NUM_XMIT_BUFFS
)
1252 writew(0, &p
->xmit_cmds
[p
->xmit_count
]->cmd_status
);
1253 /* linkpointer of xmit-command already points to next nop cmd */
1254 writew(make16(p
->nop_cmds
[next_nop
]),
1255 &p
->nop_cmds
[next_nop
]->cmd_link
);
1256 writew(0, &p
->nop_cmds
[next_nop
]->cmd_status
);
1257 writew(make16(p
->xmit_cmds
[p
->xmit_count
]),
1258 &p
->nop_cmds
[p
->xmit_count
]->cmd_link
);
1259 dev
->trans_start
= jiffies
;
1260 p
->xmit_count
= next_nop
;
1262 unsigned long flags
;
1263 spin_lock_irqsave(&p
->spinlock
);
1264 if (p
->xmit_count
!= p
->xmit_last
)
1265 netif_wake_queue(dev
);
1266 spin_unlock_irqrestore(&p
->spinlock
);
1270 return NETDEV_TX_OK
;
1273 /*******************************************
1274 * Someone wanna have the statistics
1277 static struct net_device_stats
*ni52_get_stats(struct net_device
*dev
)
1279 struct priv
*p
= netdev_priv(dev
);
1280 unsigned short crc
, aln
, rsc
, ovrn
;
1282 /* Get error-statistics from the ni82586 */
1283 crc
= readw(&p
->scb
->crc_errs
);
1284 writew(0, &p
->scb
->crc_errs
);
1285 aln
= readw(&p
->scb
->aln_errs
);
1286 writew(0, &p
->scb
->aln_errs
);
1287 rsc
= readw(&p
->scb
->rsc_errs
);
1288 writew(0, &p
->scb
->rsc_errs
);
1289 ovrn
= readw(&p
->scb
->ovrn_errs
);
1290 writew(0, &p
->scb
->ovrn_errs
);
1292 p
->stats
.rx_crc_errors
+= crc
;
1293 p
->stats
.rx_fifo_errors
+= ovrn
;
1294 p
->stats
.rx_frame_errors
+= aln
;
1295 p
->stats
.rx_dropped
+= rsc
;
1300 /********************************************************
1304 static void set_multicast_list(struct net_device
*dev
)
1306 netif_stop_queue(dev
);
1312 netif_wake_queue(dev
);
1316 static struct net_device
*dev_ni52
;
1318 module_param(io
, int, 0);
1319 module_param(irq
, int, 0);
1320 module_param(memstart
, long, 0);
1321 module_param(memend
, long, 0);
1322 MODULE_PARM_DESC(io
, "NI5210 I/O base address,required");
1323 MODULE_PARM_DESC(irq
, "NI5210 IRQ number,required");
1324 MODULE_PARM_DESC(memstart
, "NI5210 memory base address,required");
1325 MODULE_PARM_DESC(memend
, "NI5210 memory end address,required");
1327 int __init
init_module(void)
1329 if (io
<= 0x0 || !memend
|| !memstart
|| irq
< 2) {
1330 printk(KERN_ERR
"ni52: Autoprobing not allowed for modules.\n");
1331 printk(KERN_ERR
"ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
1334 dev_ni52
= ni52_probe(-1);
1335 if (IS_ERR(dev_ni52
))
1336 return PTR_ERR(dev_ni52
);
1340 void __exit
cleanup_module(void)
1342 struct priv
*p
= netdev_priv(dev_ni52
);
1343 unregister_netdev(dev_ni52
);
1345 release_region(dev_ni52
->base_addr
, NI52_TOTAL_SIZE
);
1346 free_netdev(dev_ni52
);
1350 MODULE_LICENSE("GPL");