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 * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ -DMODULE -c ni52.c
15 * insmod ni52.o io=0x360 irq=9 memstart=0xd0000 memend=0xd4000
17 * CAN YOU PLEASE REPORT ME YOUR PERFORMANCE EXPERIENCES !!.
19 * If you find a bug, please report me:
20 * The kernel panic output and any kmsg from the ni52 driver
21 * the ni5210-driver-version and the linux-kernel version
22 * how many shared memory (memsize) on the netcard,
23 * bootprom: yes/no, base_addr, mem_start
24 * maybe the ni5210-card revision and the i82586 version
26 * autoprobe for: base_addr: 0x300,0x280,0x360,0x320,0x340
27 * mem_start: 0xd0000,0xd2000,0xc8000,0xca000,0xd4000,0xd6000,
28 * 0xd8000,0xcc000,0xce000,0xda000,0xdc000
31 * skeleton.c from Donald Becker
33 * I have also done a look in the following sources: (mail me if you need them)
34 * crynwr-packet-driver by Russ Nelson
35 * Garret A. Wollman's (fourth) i82586-driver for BSD
36 * (before getting an i82596 (yes 596 not 586) manual, the existing drivers
37 * helped me a lot to understand this tricky chip.)
40 * The internal sysbus seems to be slow. So we often lose packets because of
41 * overruns while receiving from a fast remote host.
42 * This can slow down TCP connections. Maybe the newer ni5210 cards are
43 * better. My experience is, that if a machine sends with more than about
44 * 500-600K/s the fifo/sysbus overflows.
47 * On fast networks, it's a (very) good idea to have 16K shared memory. With
48 * 8K, we can store only 4 receive frames, so it can (easily) happen that a
49 * remote machine 'overruns' our system.
51 * Known i82586/card problems (I'm sure, there are many more!):
52 * Running the NOP-mode, the i82586 sometimes seems to forget to report
53 * every xmit-interrupt until we restart the CU.
54 * Another MAJOR bug is, that the RU sometimes seems to ignore the EL-Bit
55 * in the RBD-Struct which indicates an end of the RBD queue.
56 * Instead, the RU fetches another (randomly selected and
57 * usually used) RBD and begins to fill it. (Maybe, this happens only if
58 * the last buffer from the previous RFD fits exact into the queue and
59 * the next RFD can't fetch an initial RBD. Anyone knows more? )
61 * results from ftp performance tests with Linux 1.2.5
62 * send and receive about 350-400 KByte/s (peak up to 460 kbytes/s)
63 * sending in NOP-mode: peak performance up to 530K/s (but better don't
68 * 29.Sept.96: virt_to_bus changes for new memory scheme
69 * 19.Feb.96: more Mcast changes, module support (MH)
71 * 18.Nov.95: Mcast changes (AC).
73 * 23.April.95: fixed(?) receiving problems by configuring a RFD more
74 * than the number of RBD's. Can maybe cause other problems.
75 * 18.April.95: Added MODULE support (MH)
76 * 17.April.95: MC related changes in init586() and set_multicast_list().
77 * removed use of 'jiffies' in init586() (MH)
79 * 19.Sep.94: Added Multicast support (not tested yet) (MH)
81 * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.
82 * Now, every RFD has exact one RBD. (MH)
84 * 14.Sep.94: added promiscuous mode, a few cleanups (MH)
86 * 19.Aug.94: changed request_irq() parameter (MH)
88 * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH)
90 * 19.July.94: lotsa cleanups .. (MH)
92 * 17.July.94: some patches ... verified to run with 1.1.29 (MH)
94 * 4.July.94: patches for Linux 1.1.24 (MH)
96 * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
98 * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff,
101 * < 30.Sep.93: first versions
104 static int debuglevel
; /* debug-printk 0: off 1: a few 2: more */
105 static int automatic_resume
; /* experimental .. better should be zero */
106 static int rfdadd
; /* rfdadd=1 may be better for 8K MEM cards */
107 static int fifo
= 0x8; /* don't change */
109 #include <linux/module.h>
110 #include <linux/kernel.h>
111 #include <linux/string.h>
112 #include <linux/errno.h>
113 #include <linux/ioport.h>
114 #include <linux/slab.h>
115 #include <linux/interrupt.h>
116 #include <linux/delay.h>
117 #include <linux/init.h>
118 #include <linux/bitops.h>
121 #include <linux/netdevice.h>
122 #include <linux/etherdevice.h>
123 #include <linux/skbuff.h>
127 #define DRV_NAME "ni52"
129 #define DEBUG /* debug on */
130 #define SYSBUSVAL 1 /* 8 Bit */
132 #define ni_attn586() { outb(0, dev->base_addr + NI52_ATTENTION); }
133 #define ni_reset586() { outb(0, dev->base_addr + NI52_RESET); }
134 #define ni_disint() { outb(0, dev->base_addr + NI52_INTDIS); }
135 #define ni_enaint() { outb(0, dev->base_addr + NI52_INTENA); }
137 #define make32(ptr16) (p->memtop + (short) (ptr16))
138 #define make24(ptr32) ((char __iomem *)(ptr32)) - p->base
139 #define make16(ptr32) ((unsigned short) ((char __iomem *)(ptr32)\
142 /******************* how to calculate the buffers *****************************
144 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
145 * --------------- in a different (more stable?) mode. Only in this mode it's
146 * possible to configure the driver with 'NO_NOPCOMMANDS'
148 sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
149 sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
150 sizeof(rfd) = 24; sizeof(rbd) = 12;
151 sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
154 * if you don't know the driver, better do not change these values: */
156 #define RECV_BUFF_SIZE 1524 /* slightly oversized */
157 #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
158 #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
159 #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
160 #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
161 #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
163 /**************************************************************************/
166 #define NI52_TOTAL_SIZE 16
167 #define NI52_ADDR0 0x02
168 #define NI52_ADDR1 0x07
169 #define NI52_ADDR2 0x01
171 static int ni52_probe1(struct net_device
*dev
, int ioaddr
);
172 static irqreturn_t
ni52_interrupt(int irq
, void *dev_id
);
173 static int ni52_open(struct net_device
*dev
);
174 static int ni52_close(struct net_device
*dev
);
175 static int ni52_send_packet(struct sk_buff
*, struct net_device
*);
176 static struct net_device_stats
*ni52_get_stats(struct net_device
*dev
);
177 static void set_multicast_list(struct net_device
*dev
);
178 static void ni52_timeout(struct net_device
*dev
);
180 /* helper-functions */
181 static int init586(struct net_device
*dev
);
182 static int check586(struct net_device
*dev
, unsigned size
);
183 static void alloc586(struct net_device
*dev
);
184 static void startrecv586(struct net_device
*dev
);
185 static void __iomem
*alloc_rfa(struct net_device
*dev
, void __iomem
*ptr
);
186 static void ni52_rcv_int(struct net_device
*dev
);
187 static void ni52_xmt_int(struct net_device
*dev
);
188 static void ni52_rnr_int(struct net_device
*dev
);
191 struct net_device_stats stats
;
193 char __iomem
*mapped
;
194 char __iomem
*memtop
;
197 struct rfd_struct __iomem
*rfd_last
, *rfd_top
, *rfd_first
;
198 struct scp_struct __iomem
*scp
;
199 struct iscp_struct __iomem
*iscp
;
200 struct scb_struct __iomem
*scb
;
201 struct tbd_struct __iomem
*xmit_buffs
[NUM_XMIT_BUFFS
];
202 #if (NUM_XMIT_BUFFS == 1)
203 struct transmit_cmd_struct __iomem
*xmit_cmds
[2];
204 struct nop_cmd_struct __iomem
*nop_cmds
[2];
206 struct transmit_cmd_struct __iomem
*xmit_cmds
[NUM_XMIT_BUFFS
];
207 struct nop_cmd_struct __iomem
*nop_cmds
[NUM_XMIT_BUFFS
];
209 int nop_point
, num_recv_buffs
;
210 char __iomem
*xmit_cbuffs
[NUM_XMIT_BUFFS
];
211 int xmit_count
, xmit_last
;
214 /* wait for command with timeout: */
215 static void wait_for_scb_cmd(struct net_device
*dev
)
217 struct priv
*p
= dev
->priv
;
219 for (i
= 0; i
< 16384; i
++) {
220 if (readb(&p
->scb
->cmd_cuc
) == 0)
224 printk(KERN_ERR
"%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",
225 dev
->name
, readb(&p
->scb
->cmd_cuc
), readb(&p
->scb
->cus
));
234 static void wait_for_scb_cmd_ruc(struct net_device
*dev
)
236 struct priv
*p
= dev
->priv
;
238 for (i
= 0; i
< 16384; i
++) {
239 if (readb(&p
->scb
->cmd_ruc
) == 0)
243 printk(KERN_ERR
"%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",
244 dev
->name
, p
->scb
->cmd_ruc
, p
->scb
->rus
);
253 static void wait_for_stat_compl(void __iomem
*p
)
255 struct nop_cmd_struct __iomem
*addr
= p
;
257 for (i
= 0; i
< 32767; i
++) {
258 if (readw(&((addr
)->cmd_status
)) & STAT_COMPL
)
264 /**********************************************
267 static int ni52_close(struct net_device
*dev
)
269 free_irq(dev
->irq
, dev
);
270 ni_reset586(); /* the hard way to stop the receiver */
271 netif_stop_queue(dev
);
275 /**********************************************
278 static int ni52_open(struct net_device
*dev
)
288 ret
= request_irq(dev
->irq
, &ni52_interrupt
, 0, dev
->name
, dev
);
293 netif_start_queue(dev
);
294 return 0; /* most done by init */
297 /**********************************************
298 * Check to see if there's an 82586 out there.
300 static int check586(struct net_device
*dev
, unsigned size
)
302 unsigned long where
= dev
->mem_start
;
303 struct priv
*p
= dev
->priv
;
304 char __iomem
*iscp_addrs
[2];
307 p
->mapped
= (char __iomem
*)isa_bus_to_virt(where
);
308 p
->base
= p
->mapped
+ size
- 0x01000000;
309 p
->memtop
= p
->mapped
+ size
;
310 p
->scp
= (struct scp_struct __iomem
*)(p
->base
+ SCP_DEFAULT_ADDRESS
);
311 p
->scb
= (struct scb_struct __iomem
*) p
->mapped
;
312 memset_io(p
->scp
, 0, sizeof(struct scp_struct
));
313 for (i
= 0; i
< sizeof(struct scp_struct
); i
++)
314 /* memory was writeable? */
315 if (readb((char __iomem
*)p
->scp
+ i
))
317 writeb(SYSBUSVAL
, &p
->scp
->sysbus
); /* 1 = 8Bit-Bus, 0 = 16 Bit */
318 if (readb(&p
->scp
->sysbus
) != SYSBUSVAL
)
321 iscp_addrs
[0] = p
->mapped
;
322 iscp_addrs
[1] = (char __iomem
*)p
->scp
- sizeof(struct iscp_struct
);
324 for (i
= 0; i
< 2; i
++) {
325 p
->iscp
= (struct iscp_struct __iomem
*) iscp_addrs
[i
];
326 memset_io(p
->iscp
, 0, sizeof(struct iscp_struct
));
328 writel(make24(p
->iscp
), &p
->scp
->iscp
);
329 writeb(1, &p
->iscp
->busy
);
333 mdelay(32); /* wait a while... */
334 /* i82586 clears 'busy' after successful init */
335 if (readb(&p
->iscp
->busy
))
339 p
->iscp
= (struct iscp_struct __iomem
*)
340 ((char __iomem
*)p
->scp
- sizeof(struct iscp_struct
));
344 /******************************************************************
345 * set iscp at the right place, called by ni52_probe1 and open586.
347 static void alloc586(struct net_device
*dev
)
349 struct priv
*p
= (struct priv
*) dev
->priv
;
354 memset_io(p
->iscp
, 0, sizeof(struct iscp_struct
));
355 memset_io(p
->scp
, 0, sizeof(struct scp_struct
));
357 writel(make24(p
->iscp
), &p
->scp
->iscp
);
358 writeb(SYSBUSVAL
, &p
->scp
->sysbus
);
359 writew(make16(p
->scb
), &p
->iscp
->scb_offset
);
361 writeb(1, &p
->iscp
->busy
);
367 if (readb(&p
->iscp
->busy
))
368 printk(KERN_ERR
"%s: Init-Problems (alloc).\n", dev
->name
);
372 memset_io(p
->scb
, 0, sizeof(struct scb_struct
));
375 /* set: io,irq,memstart,memend or set it when calling insmod */
377 static int io
= 0x300;
378 static long memstart
; /* e.g 0xd0000 */
379 static long memend
; /* e.g 0xd4000 */
381 /**********************************************
382 * probe the ni5210-card
384 struct net_device
* __init
ni52_probe(int unit
)
386 struct net_device
*dev
= alloc_etherdev(sizeof(struct priv
));
387 static int ports
[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
392 return ERR_PTR(-ENOMEM
);
395 sprintf(dev
->name
, "eth%d", unit
);
396 netdev_boot_setup_check(dev
);
399 memstart
= dev
->mem_start
;
400 memend
= dev
->mem_end
;
403 if (io
> 0x1ff) { /* Check a single specified location. */
404 err
= ni52_probe1(dev
, io
);
405 } else if (io
> 0) { /* Don't probe at all. */
408 for (port
= ports
; *port
&& ni52_probe1(dev
, *port
) ; port
++)
413 for (io
= 0x200; io
< 0x400 && ni52_probe1(dev
, io
); io
+= 8)
423 err
= register_netdev(dev
);
428 release_region(dev
->base_addr
, NI52_TOTAL_SIZE
);
434 static int __init
ni52_probe1(struct net_device
*dev
, int ioaddr
)
437 struct priv
*priv
= dev
->priv
;
439 dev
->base_addr
= ioaddr
;
441 dev
->mem_start
= memstart
;
442 dev
->mem_end
= memend
;
444 spin_lock_init(&priv
->spinlock
);
446 if (!request_region(ioaddr
, NI52_TOTAL_SIZE
, DRV_NAME
))
449 if (!(inb(ioaddr
+NI52_MAGIC1
) == NI52_MAGICVAL1
) ||
450 !(inb(ioaddr
+NI52_MAGIC2
) == NI52_MAGICVAL2
)) {
455 for (i
= 0; i
< ETH_ALEN
; i
++)
456 dev
->dev_addr
[i
] = inb(dev
->base_addr
+i
);
458 if (dev
->dev_addr
[0] != NI52_ADDR0
|| dev
->dev_addr
[1] != NI52_ADDR1
459 || dev
->dev_addr
[2] != NI52_ADDR2
) {
464 printk(KERN_INFO
"%s: NI5210 found at %#3lx, ",
465 dev
->name
, dev
->base_addr
);
468 * check (or search) IO-Memory, 8K and 16K
471 size
= dev
->mem_end
- dev
->mem_start
;
472 if (size
!= 0x2000 && size
!= 0x4000) {
474 printk(KERN_ERR
"%s: Invalid memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n", dev
->name
, size
);
478 if (!check586(dev
, size
)) {
479 printk(KERN_ERR
"?memcheck, Can't find memory at 0x%lx with size %d!\n", dev
->mem_start
, size
);
484 if (dev
->mem_start
!= 0) {
485 /* no auto-mem-probe */
486 size
= 0x4000; /* check for 16K mem */
487 if (!check586(dev
, size
)) {
488 size
= 0x2000; /* check for 8K mem */
489 if (!check586(dev
, size
)) {
490 printk(KERN_ERR
"?memprobe, Can't find memory at 0x%lx!\n", dev
->mem_start
);
496 static const unsigned long memaddrs
[] = {
497 0xc8000, 0xca000, 0xcc000, 0xce000, 0xd0000, 0xd2000,
498 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0
502 printk(KERN_ERR
"?memprobe, Can't find io-memory!\n");
506 dev
->mem_start
= memaddrs
[i
];
507 size
= 0x2000; /* check for 8K mem */
508 if (check586(dev
, size
))
511 size
= 0x4000; /* check for 16K mem */
512 if (check586(dev
, size
))
517 /* set mem_end showed by 'ifconfig' */
518 dev
->mem_end
= dev
->mem_start
+ size
;
523 /* set number of receive-buffs according to memsize */
525 priv
->num_recv_buffs
= NUM_RECV_BUFFS_8
;
527 priv
->num_recv_buffs
= NUM_RECV_BUFFS_16
;
529 printk(KERN_DEBUG
"Memaddr: 0x%lx, Memsize: %d, ",
530 dev
->mem_start
, size
);
533 unsigned long irq_mask
;
535 irq_mask
= probe_irq_on();
540 dev
->irq
= probe_irq_off(irq_mask
);
542 printk("?autoirq, Failed to detect IRQ line!\n");
546 printk("IRQ %d (autodetected).\n", dev
->irq
);
550 printk("IRQ %d (assigned and not checked!).\n", dev
->irq
);
553 dev
->open
= ni52_open
;
554 dev
->stop
= ni52_close
;
555 dev
->get_stats
= ni52_get_stats
;
556 dev
->tx_timeout
= ni52_timeout
;
557 dev
->watchdog_timeo
= HZ
/20;
558 dev
->hard_start_xmit
= ni52_send_packet
;
559 dev
->set_multicast_list
= set_multicast_list
;
565 release_region(ioaddr
, NI52_TOTAL_SIZE
);
569 /**********************************************
570 * init the chip (ni52-interrupt should be disabled?!)
571 * needs a correct 'allocated' memory
574 static int init586(struct net_device
*dev
)
578 struct priv
*p
= (struct priv
*)dev
->priv
;
579 struct configure_cmd_struct __iomem
*cfg_cmd
;
580 struct iasetup_cmd_struct __iomem
*ias_cmd
;
581 struct tdr_cmd_struct __iomem
*tdr_cmd
;
582 struct mcsetup_cmd_struct __iomem
*mc_cmd
;
583 struct dev_mc_list
*dmi
= dev
->mc_list
;
584 int num_addrs
= dev
->mc_count
;
588 cfg_cmd
= ptr
; /* configure-command */
589 writew(0, &cfg_cmd
->cmd_status
);
590 writew(CMD_CONFIGURE
| CMD_LAST
, &cfg_cmd
->cmd_cmd
);
591 writew(0xFFFF, &cfg_cmd
->cmd_link
);
593 /* number of cfg bytes */
594 writeb(0x0a, &cfg_cmd
->byte_cnt
);
595 /* fifo-limit (8=tx:32/rx:64) */
596 writeb(fifo
, &cfg_cmd
->fifo
);
597 /* hold or discard bad recv frames (bit 7) */
598 writeb(0x40, &cfg_cmd
->sav_bf
);
599 /* addr_len |!src_insert |pre-len |loopback */
600 writeb(0x2e, &cfg_cmd
->adr_len
);
601 writeb(0x00, &cfg_cmd
->priority
);
602 writeb(0x60, &cfg_cmd
->ifs
);;
603 writeb(0x00, &cfg_cmd
->time_low
);
604 writeb(0xf2, &cfg_cmd
->time_high
);
605 writeb(0x00, &cfg_cmd
->promisc
);;
606 if (dev
->flags
& IFF_ALLMULTI
) {
607 int len
= ((char __iomem
*)p
->iscp
- (char __iomem
*)ptr
- 8) / 6;
608 if (num_addrs
> len
) {
609 printk(KERN_ERR
"%s: switching to promisc. mode\n",
611 dev
->flags
|= IFF_PROMISC
;
614 if (dev
->flags
& IFF_PROMISC
)
615 writeb(0x01, &cfg_cmd
->promisc
);
616 writeb(0x00, &cfg_cmd
->carr_coll
);
617 writew(make16(cfg_cmd
), &p
->scb
->cbl_offset
);
618 writew(0, &p
->scb
->cmd_ruc
);
620 writeb(CUC_START
, &p
->scb
->cmd_cuc
); /* cmd.-unit start */
623 wait_for_stat_compl(cfg_cmd
);
625 if ((readw(&cfg_cmd
->cmd_status
) & (STAT_OK
|STAT_COMPL
)) !=
626 (STAT_COMPL
|STAT_OK
)) {
627 printk(KERN_ERR
"%s: configure command failed: %x\n",
628 dev
->name
, readw(&cfg_cmd
->cmd_status
));
633 * individual address setup
638 writew(0, &ias_cmd
->cmd_status
);
639 writew(CMD_IASETUP
| CMD_LAST
, &ias_cmd
->cmd_cmd
);
640 writew(0xffff, &ias_cmd
->cmd_link
);
642 memcpy_toio(&ias_cmd
->iaddr
, (char *)dev
->dev_addr
, ETH_ALEN
);
644 writew(make16(ias_cmd
), &p
->scb
->cbl_offset
);
646 writeb(CUC_START
, &p
->scb
->cmd_cuc
); /* cmd.-unit start */
649 wait_for_stat_compl(ias_cmd
);
651 if ((readw(&ias_cmd
->cmd_status
) & (STAT_OK
|STAT_COMPL
)) !=
652 (STAT_OK
|STAT_COMPL
)) {
653 printk(KERN_ERR
"%s (ni52): individual address setup command failed: %04x\n", dev
->name
, readw(&ias_cmd
->cmd_status
));
658 * TDR, wire check .. e.g. no resistor e.t.c
663 writew(0, &tdr_cmd
->cmd_status
);
664 writew(CMD_TDR
| CMD_LAST
, &tdr_cmd
->cmd_cmd
);
665 writew(0xffff, &tdr_cmd
->cmd_link
);
666 writew(0, &tdr_cmd
->status
);
668 writew(make16(tdr_cmd
), &p
->scb
->cbl_offset
);
669 writeb(CUC_START
, &p
->scb
->cmd_cuc
); /* cmd.-unit start */
672 wait_for_stat_compl(tdr_cmd
);
674 if (!(readw(&tdr_cmd
->cmd_status
) & STAT_COMPL
))
675 printk(KERN_ERR
"%s: Problems while running the TDR.\n",
679 result
= readw(&tdr_cmd
->status
);
680 writeb(readb(&p
->scb
->cus
) & STAT_MASK
, &p
->scb
->cmd_cuc
);
681 ni_attn586(); /* ack the interrupts */
683 if (result
& TDR_LNK_OK
)
685 else if (result
& TDR_XCVR_PRB
)
686 printk(KERN_ERR
"%s: TDR: Transceiver problem. Check the cable(s)!\n",
688 else if (result
& TDR_ET_OPN
)
689 printk(KERN_ERR
"%s: TDR: No correct termination %d clocks away.\n",
690 dev
->name
, result
& TDR_TIMEMASK
);
691 else if (result
& TDR_ET_SRT
) {
692 /* time == 0 -> strange :-) */
693 if (result
& TDR_TIMEMASK
)
694 printk(KERN_ERR
"%s: TDR: Detected a short circuit %d clocks away.\n",
695 dev
->name
, result
& TDR_TIMEMASK
);
697 printk(KERN_ERR
"%s: TDR: Unknown status %04x\n",
704 if (num_addrs
&& !(dev
->flags
& IFF_PROMISC
)) {
706 writew(0, &mc_cmd
->cmd_status
);
707 writew(CMD_MCSETUP
| CMD_LAST
, &mc_cmd
->cmd_cmd
);
708 writew(0xffff, &mc_cmd
->cmd_link
);
709 writew(num_addrs
* 6, &mc_cmd
->mc_cnt
);
711 for (i
= 0; i
< num_addrs
; i
++, dmi
= dmi
->next
)
712 memcpy_toio(mc_cmd
->mc_list
[i
],
715 writew(make16(mc_cmd
), &p
->scb
->cbl_offset
);
716 writeb(CUC_START
, &p
->scb
->cmd_cuc
);
719 wait_for_stat_compl(mc_cmd
);
721 if ((readw(&mc_cmd
->cmd_status
) & (STAT_COMPL
|STAT_OK
))
722 != (STAT_COMPL
|STAT_OK
))
723 printk(KERN_ERR
"%s: Can't apply multicast-address-list.\n", dev
->name
);
727 * alloc nop/xmit-cmds
729 #if (NUM_XMIT_BUFFS == 1)
730 for (i
= 0; i
< 2; i
++) {
731 p
->nop_cmds
[i
] = ptr
;
732 writew(CMD_NOP
, &p
->nop_cmds
[i
]->cmd_cmd
);
733 writew(0, &p
->nop_cmds
[i
]->cmd_status
);
734 writew(make16(p
->nop_cmds
[i
]), &p
->nop_cmds
[i
]->cmd_link
);
735 ptr
= ptr
+ sizeof(struct nop_cmd_struct
);
738 for (i
= 0; i
< NUM_XMIT_BUFFS
; i
++) {
739 p
->nop_cmds
[i
] = ptr
;
740 writew(CMD_NOP
, &p
->nop_cmds
[i
]->cmd_cmd
);
741 writew(0, &p
->nop_cmds
[i
]->cmd_status
);
742 writew(make16(p
->nop_cmds
[i
]), &p
->nop_cmds
[i
]->cmd_link
);
743 ptr
= ptr
+ sizeof(struct nop_cmd_struct
);
747 ptr
= alloc_rfa(dev
, ptr
); /* init receive-frame-area */
750 * alloc xmit-buffs / init xmit_cmds
752 for (i
= 0; i
< NUM_XMIT_BUFFS
; i
++) {
753 /* Transmit cmd/buff 0 */
754 p
->xmit_cmds
[i
] = ptr
;
755 ptr
= ptr
+ sizeof(struct transmit_cmd_struct
);
756 p
->xmit_cbuffs
[i
] = ptr
; /* char-buffs */
757 ptr
= ptr
+ XMIT_BUFF_SIZE
;
758 p
->xmit_buffs
[i
] = ptr
; /* TBD */
759 ptr
= ptr
+ sizeof(struct tbd_struct
);
760 if ((void __iomem
*)ptr
> (void __iomem
*)p
->iscp
) {
761 printk(KERN_ERR
"%s: not enough shared-mem for your configuration!\n",
765 memset_io(p
->xmit_cmds
[i
], 0,
766 sizeof(struct transmit_cmd_struct
));
767 memset_io(p
->xmit_buffs
[i
], 0,
768 sizeof(struct tbd_struct
));
769 writew(make16(p
->nop_cmds
[(i
+1)%NUM_XMIT_BUFFS
]),
770 &p
->xmit_cmds
[i
]->cmd_link
);
771 writew(STAT_COMPL
, &p
->xmit_cmds
[i
]->cmd_status
);
772 writew(CMD_XMIT
|CMD_INT
, &p
->xmit_cmds
[i
]->cmd_cmd
);
773 writew(make16(p
->xmit_buffs
[i
]), &p
->xmit_cmds
[i
]->tbd_offset
);
774 writew(0xffff, &p
->xmit_buffs
[i
]->next
);
775 writel(make24(p
->xmit_cbuffs
[i
]), &p
->xmit_buffs
[i
]->buffer
);
780 #ifndef NO_NOPCOMMANDS
785 * 'start transmitter'
787 #ifndef NO_NOPCOMMANDS
788 writew(make16(p
->nop_cmds
[0]), &p
->scb
->cbl_offset
);
789 writeb(CUC_START
, &p
->scb
->cmd_cuc
);
791 wait_for_scb_cmd(dev
);
793 writew(make16(p
->xmit_cmds
[0]), &p
->xmit_cmds
[0]->cmd_link
);
794 writew(CMD_XMIT
| CMD_SUSPEND
| CMD_INT
, &p
->xmit_cmds
[0]->cmd_cmd
);
800 writeb(readb(&p
->scb
->cus
) & STAT_MASK
, &p
->scb
->cmd_cuc
);
809 /******************************************************
810 * This is a helper routine for ni52_rnr_int() and init586().
811 * It sets up the Receive Frame Area (RFA).
814 static void __iomem
*alloc_rfa(struct net_device
*dev
, void __iomem
*ptr
)
816 struct rfd_struct __iomem
*rfd
= ptr
;
817 struct rbd_struct __iomem
*rbd
;
819 struct priv
*p
= (struct priv
*) dev
->priv
;
822 sizeof(struct rfd_struct
) * (p
->num_recv_buffs
+ rfdadd
));
825 for (i
= 0; i
< (p
->num_recv_buffs
+ rfdadd
); i
++) {
826 writew(make16(rfd
+ (i
+1) % (p
->num_recv_buffs
+rfdadd
)),
828 writew(0xffff, &rfd
[i
].rbd_offset
);
831 writeb(RFD_SUSP
, &rfd
[p
->num_recv_buffs
-1+rfdadd
].last
);
833 ptr
= rfd
+ (p
->num_recv_buffs
+ rfdadd
);
836 ptr
= rbd
+ p
->num_recv_buffs
;
838 /* clr descriptors */
839 memset_io(rbd
, 0, sizeof(struct rbd_struct
) * (p
->num_recv_buffs
));
841 for (i
= 0; i
< p
->num_recv_buffs
; i
++) {
842 writew(make16(rbd
+ (i
+1) % p
->num_recv_buffs
), &rbd
[i
].next
);
843 writew(RECV_BUFF_SIZE
, &rbd
[i
].size
);
844 writel(make24(ptr
), &rbd
[i
].buffer
);
845 ptr
= ptr
+ RECV_BUFF_SIZE
;
847 p
->rfd_top
= p
->rfd_first
;
848 p
->rfd_last
= p
->rfd_first
+ (p
->num_recv_buffs
- 1 + rfdadd
);
850 writew(make16(p
->rfd_first
), &p
->scb
->rfa_offset
);
851 writew(make16(rbd
), &p
->rfd_first
->rbd_offset
);
857 /**************************************************
858 * Interrupt Handler ...
861 static irqreturn_t
ni52_interrupt(int irq
, void *dev_id
)
863 struct net_device
*dev
= dev_id
;
868 p
= (struct priv
*) dev
->priv
;
873 spin_lock(&p
->spinlock
);
875 wait_for_scb_cmd(dev
); /* wait for last command */
877 while ((stat
= readb(&p
->scb
->cus
) & STAT_MASK
)) {
878 writeb(stat
, &p
->scb
->cmd_cuc
);
881 if (stat
& STAT_FR
) /* received a frame */
884 if (stat
& STAT_RNR
) { /* RU went 'not ready' */
886 if (readb(&p
->scb
->rus
) & RU_SUSPEND
) {
887 /* special case: RU_SUSPEND */
888 wait_for_scb_cmd(dev
);
889 p
->scb
->cmd_ruc
= RUC_RESUME
;
891 wait_for_scb_cmd_ruc(dev
);
893 printk(KERN_ERR
"%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",
894 dev
->name
, stat
, readb(&p
->scb
->rus
));
899 /* Command with I-bit set complete */
903 #ifndef NO_NOPCOMMANDS
904 if (stat
& STAT_CNA
) { /* CU went 'not ready' */
905 if (netif_running(dev
))
906 printk(KERN_ERR
"%s: oops! CU has left active state. stat: %04x/%02x.\n",
907 dev
->name
, stat
, readb(&p
->scb
->cus
));
914 /* Wait for ack. (ni52_xmt_int can be faster than ack!!) */
915 wait_for_scb_cmd(dev
);
916 if (p
->scb
->cmd_cuc
) { /* timed out? */
917 printk(KERN_ERR
"%s: Acknowledge timed out.\n",
923 spin_unlock(&p
->spinlock
);
930 /*******************************************************
934 static void ni52_rcv_int(struct net_device
*dev
)
937 unsigned short totlen
;
939 struct rbd_struct __iomem
*rbd
;
940 struct priv
*p
= (struct priv
*)dev
->priv
;
945 for (; (status
= readb(&p
->rfd_top
->stat_high
)) & RFD_COMPL
;) {
946 rbd
= (struct rbd_struct __iomem
*) make32(p
->rfd_top
->rbd_offset
);
947 if (status
& RFD_OK
) { /* frame received without error? */
948 totlen
= readw(&rbd
->status
);
949 if (totlen
& RBD_LAST
) {
950 /* the first and the last buffer? */
951 totlen
&= RBD_MASK
; /* length of this frame */
952 writew(0x00, &rbd
->status
);
953 skb
= (struct sk_buff
*)dev_alloc_skb(totlen
+2);
956 skb_put(skb
, totlen
);
957 skb_copy_to_linear_data(skb
, p
->base
+ (unsigned long) rbd
->buffer
, totlen
);
958 skb
->protocol
= eth_type_trans(skb
, dev
);
960 dev
->last_rx
= jiffies
;
961 p
->stats
.rx_packets
++;
962 p
->stats
.rx_bytes
+= totlen
;
964 p
->stats
.rx_dropped
++;
967 /* free all RBD's until RBD_LAST is set */
969 while (!((rstat
= readw(&rbd
->status
)) & RBD_LAST
)) {
970 totlen
+= rstat
& RBD_MASK
;
972 printk(KERN_ERR
"%s: Whoops .. no end mark in RBD list\n", dev
->name
);
975 writew(0, &rbd
->status
);
976 rbd
= (struct rbd_struct __iomem
*) make32(readl(&rbd
->next
));
978 totlen
+= rstat
& RBD_MASK
;
979 writew(0, &rbd
->status
);
980 printk(KERN_ERR
"%s: received oversized frame! length: %d\n",
982 p
->stats
.rx_dropped
++;
984 } else {/* frame !(ok), only with 'save-bad-frames' */
985 printk(KERN_ERR
"%s: oops! rfd-error-status: %04x\n",
987 p
->stats
.rx_errors
++;
989 writeb(0, &p
->rfd_top
->stat_high
);
990 writeb(RFD_SUSP
, &p
->rfd_top
->last
); /* maybe exchange by RFD_LAST */
991 writew(0xffff, &p
->rfd_top
->rbd_offset
);
992 writeb(0, &p
->rfd_last
->last
); /* delete RFD_SUSP */
993 p
->rfd_last
= p
->rfd_top
;
994 p
->rfd_top
= (struct rfd_struct __iomem
*) make32(p
->rfd_top
->next
); /* step to next RFD */
995 writew(make16(p
->rfd_top
), &p
->scb
->rfa_offset
);
1001 if (automatic_resume
) {
1002 wait_for_scb_cmd(dev
);
1003 writeb(RUC_RESUME
, &p
->scb
->cmd_ruc
);
1005 wait_for_scb_cmd_ruc(dev
);
1011 for (i
= 0; i
< 1024; i
++) {
1012 if (p
->rfd_top
->status
)
1016 printk(KERN_ERR
"%s: RU hasn't fetched next RFD (not busy/complete)\n", dev
->name
);
1024 /**********************************************************
1025 * handle 'Receiver went not ready'.
1028 static void ni52_rnr_int(struct net_device
*dev
)
1030 struct priv
*p
= (struct priv
*) dev
->priv
;
1032 p
->stats
.rx_errors
++;
1034 wait_for_scb_cmd(dev
); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1035 writeb(RUC_ABORT
, &p
->scb
->cmd_ruc
); /* usually the RU is in the 'no resource'-state .. abort it now. */
1037 wait_for_scb_cmd_ruc(dev
); /* wait for accept cmd. */
1039 alloc_rfa(dev
, p
->rfd_first
);
1040 /* maybe add a check here, before restarting the RU */
1041 startrecv586(dev
); /* restart RU */
1043 printk(KERN_ERR
"%s: Receive-Unit restarted. Status: %04x\n", dev
->name
, p
->scb
->rus
);
1047 /**********************************************************
1048 * handle xmit - interrupt
1051 static void ni52_xmt_int(struct net_device
*dev
)
1054 struct priv
*p
= (struct priv
*) dev
->priv
;
1059 status
= readw(&p
->xmit_cmds
[p
->xmit_last
]->cmd_status
);
1060 if (!(status
& STAT_COMPL
))
1061 printk(KERN_ERR
"%s: strange .. xmit-int without a 'COMPLETE'\n", dev
->name
);
1063 if (status
& STAT_OK
) {
1064 p
->stats
.tx_packets
++;
1065 p
->stats
.collisions
+= (status
& TCMD_MAXCOLLMASK
);
1067 p
->stats
.tx_errors
++;
1068 if (status
& TCMD_LATECOLL
) {
1069 printk(KERN_ERR
"%s: late collision detected.\n",
1071 p
->stats
.collisions
++;
1072 } else if (status
& TCMD_NOCARRIER
) {
1073 p
->stats
.tx_carrier_errors
++;
1074 printk(KERN_ERR
"%s: no carrier detected.\n",
1076 } else if (status
& TCMD_LOSTCTS
)
1077 printk(KERN_ERR
"%s: loss of CTS detected.\n",
1079 else if (status
& TCMD_UNDERRUN
) {
1080 p
->stats
.tx_fifo_errors
++;
1081 printk(KERN_ERR
"%s: DMA underrun detected.\n",
1083 } else if (status
& TCMD_MAXCOLL
) {
1084 printk(KERN_ERR
"%s: Max. collisions exceeded.\n",
1086 p
->stats
.collisions
+= 16;
1089 #if (NUM_XMIT_BUFFS > 1)
1090 if ((++p
->xmit_last
) == NUM_XMIT_BUFFS
)
1093 netif_wake_queue(dev
);
1096 /***********************************************************
1097 * (re)start the receiver
1100 static void startrecv586(struct net_device
*dev
)
1102 struct priv
*p
= (struct priv
*) dev
->priv
;
1104 wait_for_scb_cmd(dev
);
1105 wait_for_scb_cmd_ruc(dev
);
1106 writew(make16(p
->rfd_first
), &p
->scb
->rfa_offset
);
1107 writeb(RUC_START
, &p
->scb
->cmd_ruc
);
1108 ni_attn586(); /* start cmd. */
1109 wait_for_scb_cmd_ruc(dev
);
1110 /* wait for accept cmd. (no timeout!!) */
1113 static void ni52_timeout(struct net_device
*dev
)
1115 struct priv
*p
= (struct priv
*) dev
->priv
;
1116 #ifndef NO_NOPCOMMANDS
1117 if (readb(&p
->scb
->cus
) & CU_ACTIVE
) { /* COMMAND-UNIT active? */
1118 netif_wake_queue(dev
);
1120 printk(KERN_ERR
"%s: strange ... timeout with CU active?!?\n",
1122 printk(KERN_ERR
"%s: X0: %04x N0: %04x N1: %04x %d\n",
1123 dev
->name
, (int)p
->xmit_cmds
[0]->cmd_status
,
1124 readw(&p
->nop_cmds
[0]->cmd_status
),
1125 readw(&p
->nop_cmds
[1]->cmd_status
),
1128 writeb(CUC_ABORT
, &p
->scb
->cmd_cuc
);
1130 wait_for_scb_cmd(dev
);
1131 writew(make16(p
->nop_cmds
[p
->nop_point
]), &p
->scb
->cbl_offset
);
1132 writeb(CUC_START
, &p
->scb
->cmd_cuc
);
1134 wait_for_scb_cmd(dev
);
1135 dev
->trans_start
= jiffies
;
1141 printk(KERN_ERR
"%s: xmitter timed out, try to restart! stat: %02x\n",
1142 dev
->name
, readb(&p
->scb
->cus
));
1143 printk(KERN_ERR
"%s: command-stats: %04x %04x\n",
1145 readw(&p
->xmit_cmds
[0]->cmd_status
),
1146 readw(&p
->xmit_cmds
[1]->cmd_status
));
1147 printk(KERN_ERR
"%s: check, whether you set the right interrupt number!\n",
1153 dev
->trans_start
= jiffies
;
1156 /******************************************************
1160 static int ni52_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1163 #ifndef NO_NOPCOMMANDS
1166 struct priv
*p
= (struct priv
*) dev
->priv
;
1168 if (skb
->len
> XMIT_BUFF_SIZE
) {
1169 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
);
1173 netif_stop_queue(dev
);
1175 skb_copy_from_linear_data(skb
, (char *)p
->xmit_cbuffs
[p
->xmit_count
],
1178 if (len
< ETH_ZLEN
) {
1180 memset((char *)p
->xmit_cbuffs
[p
->xmit_count
]+skb
->len
, 0,
1184 #if (NUM_XMIT_BUFFS == 1)
1185 # ifdef NO_NOPCOMMANDS
1188 if (p
->scb
->cus
& CU_ACTIVE
) {
1189 printk(KERN_ERR
"%s: Hmmm .. CU is still running and we wanna send a new packet.\n", dev
->name
);
1190 printk(KERN_ERR
"%s: stat: %04x %04x\n",
1191 dev
->name
, readb(&p
->scb
->cus
),
1192 readw(&p
->xmit_cmds
[0]->cmd_status
));
1195 writew(TBD_LAST
| len
, &p
->xmit_buffs
[0]->size
);;
1196 for (i
= 0; i
< 16; i
++) {
1197 writew(0, &p
->xmit_cmds
[0]->cmd_status
);
1198 wait_for_scb_cmd(dev
);
1199 if ((readb(&p
->scb
->cus
) & CU_STATUS
) == CU_SUSPEND
)
1200 writeb(CUC_RESUME
, &p
->scb
->cmd_cuc
);
1202 writew(make16(p
->xmit_cmds
[0]), &p
->scb
->cbl_offset
);
1203 writeb(CUC_START
, &p
->scb
->cmd_cuc
);
1206 dev
->trans_start
= jiffies
;
1209 wait_for_scb_cmd(dev
);
1210 /* test it, because CU sometimes doesn't start immediately */
1211 if (readb(&p
->scb
->cus
) & CU_ACTIVE
)
1213 if (readw(&p
->xmit_cmds
[0]->cmd_status
))
1216 printk(KERN_WARNING
"%s: Can't start transmit-command.\n", dev
->name
);
1219 next_nop
= (p
->nop_point
+ 1) & 0x1;
1220 writew(TBD_LAST
| len
, &p
->xmit_buffs
[0]->size
);
1221 writew(make16(p
->nop_cmds
[next_nop
]), &p
->xmit_cmds
[0]->cmd_link
);
1222 writew(make16(p
->nop_cmds
[next_nop
]),
1223 &p
->nop_cmds
[next_nop
]->cmd_link
);
1224 writew(0, &p
->xmit_cmds
[0]->cmd_status
);
1225 writew(0, &p
->nop_cmds
[next_nop
]->cmd_status
);
1227 writew(make16(p
->xmit_cmds
[0]), &p
->nop_cmds
[p
->nop_point
]->cmd_link
);
1228 dev
->trans_start
= jiffies
;
1229 p
->nop_point
= next_nop
;
1233 writew(TBD_LAST
| len
, &p
->xmit_buffs
[p
->xmit_count
]->size
);
1234 next_nop
= p
->xmit_count
+ 1
1235 if (next_nop
== NUM_XMIT_BUFFS
)
1237 writew(0, &p
->xmit_cmds
[p
->xmit_count
]->cmd_status
);
1238 /* linkpointer of xmit-command already points to next nop cmd */
1239 writew(make16(p
->nop_cmds
[next_nop
]),
1240 &p
->nop_cmds
[next_nop
]->cmd_link
);
1241 writew(0, &p
->nop_cmds
[next_nop
]->cmd_status
);
1242 writew(make16(p
->xmit_cmds
[p
->xmit_count
]),
1243 &p
->nop_cmds
[p
->xmit_count
]->cmd_link
);
1244 dev
->trans_start
= jiffies
;
1245 p
->xmit_count
= next_nop
;
1247 unsigned long flags
;
1248 spin_lock_irqsave(&p
->spinlock
);
1249 if (p
->xmit_count
!= p
->xmit_last
)
1250 netif_wake_queue(dev
);
1251 spin_unlock_irqrestore(&p
->spinlock
);
1258 /*******************************************
1259 * Someone wanna have the statistics
1262 static struct net_device_stats
*ni52_get_stats(struct net_device
*dev
)
1264 struct priv
*p
= (struct priv
*) dev
->priv
;
1265 unsigned short crc
, aln
, rsc
, ovrn
;
1267 /* Get error-statistics from the ni82586 */
1268 crc
= readw(&p
->scb
->crc_errs
);
1269 writew(0, &p
->scb
->crc_errs
);
1270 aln
= readw(&p
->scb
->aln_errs
);
1271 writew(0, &p
->scb
->aln_errs
);
1272 rsc
= readw(&p
->scb
->rsc_errs
);
1273 writew(0, &p
->scb
->rsc_errs
);
1274 ovrn
= readw(&p
->scb
->ovrn_errs
);
1275 writew(0, &p
->scb
->ovrn_errs
);
1277 p
->stats
.rx_crc_errors
+= crc
;
1278 p
->stats
.rx_fifo_errors
+= ovrn
;
1279 p
->stats
.rx_frame_errors
+= aln
;
1280 p
->stats
.rx_dropped
+= rsc
;
1285 /********************************************************
1289 static void set_multicast_list(struct net_device
*dev
)
1291 netif_stop_queue(dev
);
1297 netif_wake_queue(dev
);
1301 static struct net_device
*dev_ni52
;
1303 module_param(io
, int, 0);
1304 module_param(irq
, int, 0);
1305 module_param(memstart
, long, 0);
1306 module_param(memend
, long, 0);
1307 MODULE_PARM_DESC(io
, "NI5210 I/O base address,required");
1308 MODULE_PARM_DESC(irq
, "NI5210 IRQ number,required");
1309 MODULE_PARM_DESC(memstart
, "NI5210 memory base address,required");
1310 MODULE_PARM_DESC(memend
, "NI5210 memory end address,required");
1312 int __init
init_module(void)
1314 if (io
<= 0x0 || !memend
|| !memstart
|| irq
< 2) {
1315 printk(KERN_ERR
"ni52: Autoprobing not allowed for modules.\n");
1316 printk(KERN_ERR
"ni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
1319 dev_ni52
= ni52_probe(-1);
1320 if (IS_ERR(dev_ni52
))
1321 return PTR_ERR(dev_ni52
);
1325 void __exit
cleanup_module(void)
1327 unregister_netdev(dev_ni52
);
1328 release_region(dev_ni52
->base_addr
, NI52_TOTAL_SIZE
);
1329 free_netdev(dev_ni52
);
1333 MODULE_LICENSE("GPL");
1336 * END: linux/drivers/net/ni52.c