Import 2.1.36
[davej-history.git] / drivers / net / ni52.c
blob746037adfe09922f2037ee27766375e6ce1380ae
1 /*
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 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 (Michael.Hipp@student.uni-tuebingen.de)
9 * [feel free to mail ....]
11 * when using as module: (no autoprobing!)
12 * compile with:
13 * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ -DMODULE -c ni52.c
14 * run with e.g:
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
30 * sources:
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 helped
37 * me a lot to understand this tricky chip.)
39 * Known Problems:
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 better.
43 * my experience is, that if a machine sends with more then about 500-600K/s
44 * the fifo/sysbus overflows.
46 * IMPORTANT NOTE:
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 remote
49 * 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 run this mode)
67 * 29.Sept.96: virt_to_bus changes for new memory scheme
68 * 19.Feb.96: more Mcast changes, module support (MH)
70 * 18.Nov.95: Mcast changes (AC).
72 * 23.April.95: fixed(?) receiving problems by configuring a RFD more
73 * than the number of RBD's. Can maybe cause other problems.
74 * 18.April.95: Added MODULE support (MH)
75 * 17.April.95: MC related changes in init586() and set_multicast_list().
76 * removed use of 'jiffies' in init586() (MH)
78 * 19.Sep.94: Added Multicast support (not tested yet) (MH)
80 * 18.Sep.94: Workaround for 'EL-Bug'. Removed flexible RBD-handling.
81 * Now, every RFD has exact one RBD. (MH)
83 * 14.Sep.94: added promiscuous mode, a few cleanups (MH)
85 * 19.Aug.94: changed request_irq() parameter (MH)
87 * 20.July.94: removed cleanup bugs, removed a 16K-mem-probe-bug (MH)
89 * 19.July.94: lotsa cleanups .. (MH)
91 * 17.July.94: some patches ... verified to run with 1.1.29 (MH)
93 * 4.July.94: patches for Linux 1.1.24 (MH)
95 * 26.March.94: patches for Linux 1.0 and iomem-auto-probe (MH)
97 * 30.Sep.93: Added nop-chain .. driver now runs with only one Xmit-Buff, too (MH)
99 * < 30.Sep.93: first versions
102 static int debuglevel = 0; /* debug-printk 0: off 1: a few 2: more */
103 static int automatic_resume = 0; /* experimental .. better should be zero */
104 static int rfdadd = 0; /* rfdadd=1 may be better for 8K MEM cards */
105 static int fifo=0x8; /* don't change */
107 /* #define REALLY_SLOW_IO */
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/malloc.h>
115 #include <linux/interrupt.h>
116 #include <linux/delay.h>
117 #include <linux/init.h>
118 #include <asm/bitops.h>
119 #include <asm/io.h>
121 #include <linux/netdevice.h>
122 #include <linux/etherdevice.h>
123 #include <linux/skbuff.h>
125 #include "ni52.h"
127 #define DEBUG /* debug on */
128 #define SYSBUSVAL 1 /* 8 Bit */
130 #define ni_attn586() {outb(0,dev->base_addr+NI52_ATTENTION);}
131 #define ni_reset586() {outb(0,dev->base_addr+NI52_RESET);}
132 #define ni_disint() {outb(0,dev->base_addr+NI52_INTDIS);}
133 #define ni_enaint() {outb(0,dev->base_addr+NI52_INTENA);}
135 #define make32(ptr16) (p->memtop + (short) (ptr16) )
136 #define make24(ptr32) ( ((char *) (ptr32)) - p->base)
137 #define make16(ptr32) ((unsigned short) ((unsigned long)(ptr32) - (unsigned long) p->memtop ))
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;
149 sizeof(nop_cmd) = 8;
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 /**************************************************************************/
162 /* different DELAYs */
163 #define DELAY(x) __delay((loops_per_sec>>5)*(x));
164 #define DELAY_16(); { __delay( (loops_per_sec>>16)+1 ); }
165 #define DELAY_18(); { __delay( (loops_per_sec>>18)+1 ); }
167 /* wait for command with timeout: */
168 #define WAIT_4_SCB_CMD() \
169 { int i; \
170 for(i=0;i<16384;i++) { \
171 if(!p->scb->cmd_cuc) break; \
172 DELAY_18(); \
173 if(i == 16383) { \
174 printk("%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_cuc,p->scb->cus); \
175 if(!p->reseted) { p->reseted = 1; ni_reset586(); } } } }
177 #define WAIT_4_SCB_CMD_RUC() { int i; \
178 for(i=0;i<16384;i++) { \
179 if(!p->scb->cmd_ruc) break; \
180 DELAY_18(); \
181 if(i == 16383) { \
182 printk("%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_ruc,p->scb->rus); \
183 if(!p->reseted) { p->reseted = 1; ni_reset586(); } } } }
185 #define WAIT_4_STAT_COMPL(addr) { int i; \
186 for(i=0;i<32767;i++) { \
187 if((addr)->cmd_status & STAT_COMPL) break; \
188 DELAY_16(); DELAY_16(); } }
190 #define NI52_TOTAL_SIZE 16
191 #define NI52_ADDR0 0x02
192 #define NI52_ADDR1 0x07
193 #define NI52_ADDR2 0x01
195 static int ni52_probe1(struct device *dev,int ioaddr);
196 static void ni52_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr);
197 static int ni52_open(struct device *dev);
198 static int ni52_close(struct device *dev);
199 static int ni52_send_packet(struct sk_buff *,struct device *);
200 static struct net_device_stats *ni52_get_stats(struct device *dev);
201 static void set_multicast_list(struct device *dev);
202 #if 0
203 static void ni52_dump(struct device *,void *);
204 #endif
206 /* helper-functions */
207 static int init586(struct device *dev);
208 static int check586(struct device *dev,char *where,unsigned size);
209 static void alloc586(struct device *dev);
210 static void startrecv586(struct device *dev);
211 static void *alloc_rfa(struct device *dev,void *ptr);
212 static void ni52_rcv_int(struct device *dev);
213 static void ni52_xmt_int(struct device *dev);
214 static void ni52_rnr_int(struct device *dev);
216 struct priv
218 struct net_device_stats stats;
219 unsigned long base;
220 char *memtop;
221 int lock,reseted;
222 volatile struct rfd_struct *rfd_last,*rfd_top,*rfd_first;
223 volatile struct scp_struct *scp; /* volatile is important */
224 volatile struct iscp_struct *iscp; /* volatile is important */
225 volatile struct scb_struct *scb; /* volatile is important */
226 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
227 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
228 #if (NUM_XMIT_BUFFS == 1)
229 volatile struct nop_cmd_struct *nop_cmds[2];
230 #else
231 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
232 #endif
233 volatile int nop_point,num_recv_buffs;
234 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
235 volatile int xmit_count,xmit_last;
238 /**********************************************
239 * close device
241 static int ni52_close(struct device *dev)
243 free_irq(dev->irq, NULL);
244 irq2dev_map[dev->irq] = NULL;
246 ni_reset586(); /* the hard way to stop the receiver */
248 dev->start = 0;
249 dev->tbusy = 0;
251 MOD_DEC_USE_COUNT;
253 return 0;
256 /**********************************************
257 * open device
259 static int ni52_open(struct device *dev)
261 ni_disint();
262 alloc586(dev);
263 init586(dev);
264 startrecv586(dev);
265 ni_enaint();
267 if(request_irq(dev->irq, &ni52_interrupt,0,"ni5210",NULL))
269 ni_reset586();
270 return -EAGAIN;
272 irq2dev_map[dev->irq] = dev;
274 dev->interrupt = 0;
275 dev->tbusy = 0;
276 dev->start = 1;
278 MOD_INC_USE_COUNT;
280 return 0; /* most done by init */
283 /**********************************************
284 * Check to see if there's an 82586 out there.
286 static int check586(struct device *dev,char *where,unsigned size)
288 struct priv pb;
289 struct priv *p = /* (struct priv *) dev->priv*/ &pb;
290 char *iscp_addrs[2];
291 int i;
293 p->base = (unsigned long) bus_to_virt((unsigned long)where) + size - 0x01000000;
294 p->memtop = bus_to_virt((unsigned long)where) + size;
295 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
296 memset((char *)p->scp,0, sizeof(struct scp_struct));
297 for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */
298 if(((char *)p->scp)[i])
299 return 0;
300 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
301 if(p->scp->sysbus != SYSBUSVAL)
302 return 0;
304 iscp_addrs[0] = bus_to_virt((unsigned long)where);
305 iscp_addrs[1]= (char *) p->scp - sizeof(struct iscp_struct);
307 for(i=0;i<2;i++)
309 p->iscp = (struct iscp_struct *) iscp_addrs[i];
310 memset((char *)p->iscp,0, sizeof(struct iscp_struct));
312 p->scp->iscp = make24(p->iscp);
313 p->iscp->busy = 1;
315 ni_reset586();
316 ni_attn586();
317 DELAY(1); /* wait a while... */
319 if(p->iscp->busy) /* i82586 clears 'busy' after successful init */
320 return 0;
322 return 1;
325 /******************************************************************
326 * set iscp at the right place, called by ni52_probe1 and open586.
328 void alloc586(struct device *dev)
330 struct priv *p = (struct priv *) dev->priv;
332 ni_reset586();
333 DELAY(1);
335 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
336 p->scb = (struct scb_struct *) bus_to_virt(dev->mem_start);
337 p->iscp = (struct iscp_struct *) ((char *)p->scp - sizeof(struct iscp_struct));
339 memset((char *) p->iscp,0,sizeof(struct iscp_struct));
340 memset((char *) p->scp ,0,sizeof(struct scp_struct));
342 p->scp->iscp = make24(p->iscp);
343 p->scp->sysbus = SYSBUSVAL;
344 p->iscp->scb_offset = make16(p->scb);
346 p->iscp->busy = 1;
347 ni_reset586();
348 ni_attn586();
350 DELAY(1);
352 if(p->iscp->busy)
353 printk("%s: Init-Problems (alloc).\n",dev->name);
355 p->reseted = 0;
357 memset((char *)p->scb,0,sizeof(struct scb_struct));
360 /**********************************************
361 * probe the ni5210-card
363 __initfunc(int ni52_probe(struct device *dev))
365 #ifndef MODULE
366 int *port;
367 static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
368 #endif
369 int base_addr = dev->base_addr;
371 if (base_addr > 0x1ff) /* Check a single specified location. */
372 if( (inb(base_addr+NI52_MAGIC1) == NI52_MAGICVAL1) &&
373 (inb(base_addr+NI52_MAGIC2) == NI52_MAGICVAL2))
374 return ni52_probe1(dev, base_addr);
375 else if (base_addr > 0) /* Don't probe at all. */
376 return ENXIO;
378 #ifdef MODULE
379 printk("%s: no autoprobing allowed for modules.\n",dev->name);
380 #else
381 for (port = ports; *port; port++) {
382 int ioaddr = *port;
383 if (check_region(ioaddr, NI52_TOTAL_SIZE))
384 continue;
385 if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
386 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2))
387 continue;
389 dev->base_addr = ioaddr;
390 if (ni52_probe1(dev, ioaddr) == 0)
391 return 0;
394 #ifdef FULL_IO_PROBE
395 for(dev->base_addr=0x200;dev->base_addr<0x400;dev->base_addr+=8)
397 int ioaddr = dev->base_addr;
398 if (check_region(ioaddr, NI52_TOTAL_SIZE))
399 continue;
400 if( !(inb(ioaddr+NI52_MAGIC1) == NI52_MAGICVAL1) ||
401 !(inb(ioaddr+NI52_MAGIC2) == NI52_MAGICVAL2))
402 continue;
403 if (ni52_probe1(dev, ioaddr) == 0)
404 return 0;
406 #endif
408 #endif
410 dev->base_addr = base_addr;
411 return ENODEV;
414 __initfunc(static int ni52_probe1(struct device *dev,int ioaddr))
416 int i,size;
418 for(i=0;i<ETH_ALEN;i++)
419 dev->dev_addr[i] = inb(dev->base_addr+i);
421 if(dev->dev_addr[0] != NI52_ADDR0 || dev->dev_addr[1] != NI52_ADDR1
422 || dev->dev_addr[2] != NI52_ADDR2)
423 return ENODEV;
425 printk("%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr);
427 request_region(ioaddr,NI52_TOTAL_SIZE,"ni5210");
430 * check (or search) IO-Memory, 8K and 16K
432 #ifdef MODULE
433 size = dev->mem_end - dev->mem_start;
434 if(size != 0x2000 && size != 0x4000)
436 printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 bytes.\n",dev->name,size);
437 return ENODEV;
439 if(!check586(dev,(char *) dev->mem_start,size))
441 printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size);
442 return ENODEV;
444 #else
445 if(dev->mem_start != 0) /* no auto-mem-probe */
447 size = 0x4000; /* check for 16K mem */
448 if(!check586(dev,(char *) dev->mem_start,size)) {
449 size = 0x2000; /* check for 8K mem */
450 if(!check586(dev,(char *) dev->mem_start,size)) {
451 printk("?memprobe, Can't find memory at 0x%lx!\n",dev->mem_start);
452 return ENODEV;
456 else
458 static long memaddrs[] = { 0xc8000,0xca000,0xcc000,0xce000,0xd0000,0xd2000,
459 0xd4000,0xd6000,0xd8000,0xda000,0xdc000, 0 };
460 for(i=0;;i++)
462 if(!memaddrs[i]) {
463 printk("?memprobe, Can't find io-memory!\n");
464 return ENODEV;
466 dev->mem_start = memaddrs[i];
467 size = 0x2000; /* check for 8K mem */
468 if(check586(dev,(char *)dev->mem_start,size)) /* 8K-check */
469 break;
470 size = 0x4000; /* check for 16K mem */
471 if(check586(dev,(char *)dev->mem_start,size)) /* 16K-check */
472 break;
475 dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
476 #endif
478 dev->priv = (void *) kmalloc(sizeof(struct priv),GFP_KERNEL);
479 if(dev->priv == NULL)
481 printk("%s: Ooops .. can't allocate private driver memory.\n",dev->name);
482 return -ENOMEM;
484 /* warning: we don't free it on errors */
485 memset((char *) dev->priv,0,sizeof(struct priv));
487 ((struct priv *) (dev->priv))->memtop = bus_to_virt(dev->mem_start) + size;
488 ((struct priv *) (dev->priv))->base = (unsigned long) bus_to_virt(dev->mem_start) + size - 0x01000000;
489 alloc586(dev);
491 /* set number of receive-buffs according to memsize */
492 if(size == 0x2000)
493 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_8;
494 else
495 ((struct priv *) dev->priv)->num_recv_buffs = NUM_RECV_BUFFS_16;
497 printk("Memaddr: 0x%lx, Memsize: %d, ",dev->mem_start,size);
499 if(dev->irq < 2)
501 autoirq_setup(0);
502 ni_reset586();
503 ni_attn586();
504 if(!(dev->irq = autoirq_report(2)))
506 printk("?autoirq, Failed to detect IRQ line!\n");
507 return 1;
509 printk("IRQ %d (autodetected).\n",dev->irq);
511 else {
512 if(dev->irq == 2)
513 dev->irq = 9;
514 printk("IRQ %d (assigned and not checked!).\n",dev->irq);
517 dev->open = &ni52_open;
518 dev->stop = &ni52_close;
519 dev->get_stats = &ni52_get_stats;
520 dev->hard_start_xmit = &ni52_send_packet;
521 dev->set_multicast_list = &set_multicast_list;
523 dev->if_port = 0;
525 ether_setup(dev);
527 dev->tbusy = 0;
528 dev->interrupt = 0;
529 dev->start = 0;
531 return 0;
534 /**********************************************
535 * init the chip (ni52-interrupt should be disabled?!)
536 * needs a correct 'allocated' memory
539 static int init586(struct device *dev)
541 void *ptr;
542 int i,result=0;
543 struct priv *p = (struct priv *) dev->priv;
544 volatile struct configure_cmd_struct *cfg_cmd;
545 volatile struct iasetup_cmd_struct *ias_cmd;
546 volatile struct tdr_cmd_struct *tdr_cmd;
547 volatile struct mcsetup_cmd_struct *mc_cmd;
548 struct dev_mc_list *dmi=dev->mc_list;
549 int num_addrs=dev->mc_count;
551 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
553 cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */
554 cfg_cmd->cmd_status = 0;
555 cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
556 cfg_cmd->cmd_link = 0xffff;
558 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
559 cfg_cmd->fifo = fifo; /* fifo-limit (8=tx:32/rx:64) */
560 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
561 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
562 cfg_cmd->priority = 0x00;
563 cfg_cmd->ifs = 0x60;
564 cfg_cmd->time_low = 0x00;
565 cfg_cmd->time_high = 0xf2;
566 cfg_cmd->promisc = 0;
567 if(dev->flags & IFF_ALLMULTI) {
568 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
569 if(num_addrs > len) {
570 printk("%s: switching to promisc. mode\n",dev->name);
571 dev->flags|=IFF_PROMISC;
574 if(dev->flags&IFF_PROMISC)
576 cfg_cmd->promisc=1;
577 dev->flags|=IFF_PROMISC;
579 cfg_cmd->carr_coll = 0x00;
581 p->scb->cbl_offset = make16(cfg_cmd);
582 p->scb->cmd_ruc = 0;
584 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
585 ni_attn586();
587 WAIT_4_STAT_COMPL(cfg_cmd);
589 if((cfg_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK))
591 printk("%s: configure command failed: %x\n",dev->name,cfg_cmd->cmd_status);
592 return 1;
596 * individual address setup
599 ias_cmd = (struct iasetup_cmd_struct *)ptr;
601 ias_cmd->cmd_status = 0;
602 ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST;
603 ias_cmd->cmd_link = 0xffff;
605 memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN);
607 p->scb->cbl_offset = make16(ias_cmd);
609 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
610 ni_attn586();
612 WAIT_4_STAT_COMPL(ias_cmd);
614 if((ias_cmd->cmd_status & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) {
615 printk("%s (ni52): individual address setup command failed: %04x\n",dev->name,ias_cmd->cmd_status);
616 return 1;
620 * TDR, wire check .. e.g. no resistor e.t.c
623 tdr_cmd = (struct tdr_cmd_struct *)ptr;
625 tdr_cmd->cmd_status = 0;
626 tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
627 tdr_cmd->cmd_link = 0xffff;
628 tdr_cmd->status = 0;
630 p->scb->cbl_offset = make16(tdr_cmd);
631 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
632 ni_attn586();
634 WAIT_4_STAT_COMPL(tdr_cmd);
636 if(!(tdr_cmd->cmd_status & STAT_COMPL))
638 printk("%s: Problems while running the TDR.\n",dev->name);
640 else
642 DELAY_16(); /* wait for result */
643 result = tdr_cmd->status;
645 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
646 ni_attn586(); /* ack the interrupts */
648 if(result & TDR_LNK_OK)
650 else if(result & TDR_XCVR_PRB)
651 printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name);
652 else if(result & TDR_ET_OPN)
653 printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
654 else if(result & TDR_ET_SRT)
656 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
657 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
659 else
660 printk("%s: TDR: Unknown status %04x\n",dev->name,result);
664 * Multicast setup
666 if(num_addrs && !(dev->flags & IFF_PROMISC) )
668 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
669 mc_cmd->cmd_status = 0;
670 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
671 mc_cmd->cmd_link = 0xffff;
672 mc_cmd->mc_cnt = num_addrs * 6;
674 for(i=0;i<num_addrs;i++,dmi=dmi->next)
675 memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr,6);
677 p->scb->cbl_offset = make16(mc_cmd);
678 p->scb->cmd_cuc = CUC_START;
679 ni_attn586();
681 WAIT_4_STAT_COMPL(mc_cmd);
683 if( (mc_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
684 printk("%s: Can't apply multicast-address-list.\n",dev->name);
688 * alloc nop/xmit-cmds
690 #if (NUM_XMIT_BUFFS == 1)
691 for(i=0;i<2;i++)
693 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
694 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
695 p->nop_cmds[i]->cmd_status = 0;
696 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
697 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
699 #else
700 for(i=0;i<NUM_XMIT_BUFFS;i++)
702 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
703 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
704 p->nop_cmds[i]->cmd_status = 0;
705 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
706 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
708 #endif
710 ptr = alloc_rfa(dev,(void *)ptr); /* init receive-frame-area */
713 * alloc xmit-buffs / init xmit_cmds
715 for(i=0;i<NUM_XMIT_BUFFS;i++)
717 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/
718 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
719 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */
720 ptr = (char *) ptr + XMIT_BUFF_SIZE;
721 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */
722 ptr = (char *) ptr + sizeof(struct tbd_struct);
723 if((void *)ptr > (void *)p->iscp)
725 printk("%s: not enough shared-mem for your configuration!\n",dev->name);
726 return 1;
728 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct));
729 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct));
730 p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]);
731 p->xmit_cmds[i]->cmd_status = STAT_COMPL;
732 p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
733 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
734 p->xmit_buffs[i]->next = 0xffff;
735 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
738 p->xmit_count = 0;
739 p->xmit_last = 0;
740 #ifndef NO_NOPCOMMANDS
741 p->nop_point = 0;
742 #endif
745 * 'start transmitter'
747 #ifndef NO_NOPCOMMANDS
748 p->scb->cbl_offset = make16(p->nop_cmds[0]);
749 p->scb->cmd_cuc = CUC_START;
750 ni_attn586();
751 WAIT_4_SCB_CMD();
752 #else
753 p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]);
754 p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_SUSPEND | CMD_INT;
755 #endif
758 * ack. interrupts
760 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
761 ni_attn586();
762 DELAY_16();
764 ni_enaint();
766 return 0;
769 /******************************************************
770 * This is a helper routine for ni52_rnr_int() and init586().
771 * It sets up the Receive Frame Area (RFA).
774 static void *alloc_rfa(struct device *dev,void *ptr)
776 volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr;
777 volatile struct rbd_struct *rbd;
778 int i;
779 struct priv *p = (struct priv *) dev->priv;
781 memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd));
782 p->rfd_first = rfd;
784 for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) {
785 rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) );
786 rfd[i].rbd_offset = 0xffff;
788 rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP; /* RU suspend */
790 ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) );
792 rbd = (struct rbd_struct *) ptr;
793 ptr = (void *) (rbd + p->num_recv_buffs);
795 /* clr descriptors */
796 memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs));
798 for(i=0;i<p->num_recv_buffs;i++)
800 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs));
801 rbd[i].size = RECV_BUFF_SIZE;
802 rbd[i].buffer = make24(ptr);
803 ptr = (char *) ptr + RECV_BUFF_SIZE;
806 p->rfd_top = p->rfd_first;
807 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
809 p->scb->rfa_offset = make16(p->rfd_first);
810 p->rfd_first->rbd_offset = make16(rbd);
812 return ptr;
816 /**************************************************
817 * Interrupt Handler ...
820 static void ni52_interrupt(int irq,void *dev_id,struct pt_regs *reg_ptr)
822 struct device *dev = (struct device *) irq2dev_map[irq];
823 unsigned short stat;
824 int cnt=0;
825 struct priv *p;
827 if (!dev) {
828 printk ("ni5210-interrupt: irq %d for unknown device.\n",irq);
829 return;
831 p = (struct priv *) dev->priv;
833 if(debuglevel > 1)
834 printk("I");
836 dev->interrupt = 1;
838 WAIT_4_SCB_CMD(); /* wait for last command */
840 while((stat=p->scb->cus & STAT_MASK))
842 p->scb->cmd_cuc = stat;
843 ni_attn586();
845 if(stat & STAT_FR) /* received a frame */
846 ni52_rcv_int(dev);
848 if(stat & STAT_RNR) /* RU went 'not ready' */
850 printk("(R)");
851 if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */
853 WAIT_4_SCB_CMD();
854 p->scb->cmd_ruc = RUC_RESUME;
855 ni_attn586();
856 WAIT_4_SCB_CMD_RUC();
858 else
860 printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus);
861 ni52_rnr_int(dev);
865 if(stat & STAT_CX) /* command with I-bit set complete */
866 ni52_xmt_int(dev);
868 #ifndef NO_NOPCOMMANDS
869 if(stat & STAT_CNA) /* CU went 'not ready' */
871 if(dev->start)
872 printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus);
874 #endif
876 if(debuglevel > 1)
877 printk("%d",cnt++);
879 WAIT_4_SCB_CMD(); /* wait for ack. (ni52_xmt_int can be faster than ack!!) */
880 if(p->scb->cmd_cuc) /* timed out? */
882 printk("%s: Acknowledge timed out.\n",dev->name);
883 ni_disint();
884 break;
888 if(debuglevel > 1)
889 printk("i");
891 dev->interrupt = 0;
894 /*******************************************************
895 * receive-interrupt
898 static void ni52_rcv_int(struct device *dev)
900 int status,cnt=0;
901 unsigned short totlen;
902 struct sk_buff *skb;
903 struct rbd_struct *rbd;
904 struct priv *p = (struct priv *) dev->priv;
906 if(debuglevel > 0)
907 printk("R");
909 for(;(status = p->rfd_top->stat_high) & RFD_COMPL;)
911 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
913 if(status & RFD_OK) /* frame received without error? */
915 if( (totlen = rbd->status) & RBD_LAST) /* the first and the last buffer? */
917 totlen &= RBD_MASK; /* length of this frame */
918 rbd->status = 0;
919 skb = (struct sk_buff *) dev_alloc_skb(totlen+2);
920 if(skb != NULL)
922 skb->dev = dev;
923 skb_reserve(skb,2);
924 skb_put(skb,totlen);
925 eth_copy_and_sum(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen,0);
926 skb->protocol=eth_type_trans(skb,dev);
927 netif_rx(skb);
928 p->stats.rx_packets++;
930 else
931 p->stats.rx_dropped++;
933 else
935 int rstat;
936 /* free all RBD's until RBD_LAST is set */
937 totlen = 0;
938 while(!((rstat=rbd->status) & RBD_LAST))
940 totlen += rstat & RBD_MASK;
941 if(!rstat)
943 printk("%s: Whoops .. no end mark in RBD list\n",dev->name);
944 break;
946 rbd->status = 0;
947 rbd = (struct rbd_struct *) make32(rbd->next);
949 totlen += rstat & RBD_MASK;
950 rbd->status = 0;
951 printk("%s: received oversized frame! length: %d\n",dev->name,totlen);
952 p->stats.rx_dropped++;
955 else /* frame !(ok), only with 'save-bad-frames' */
957 printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
958 p->stats.rx_errors++;
960 p->rfd_top->stat_high = 0;
961 p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */
962 p->rfd_top->rbd_offset = 0xffff;
963 p->rfd_last->last = 0; /* delete RFD_SUSP */
964 p->rfd_last = p->rfd_top;
965 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
966 p->scb->rfa_offset = make16(p->rfd_top);
968 if(debuglevel > 0)
969 printk("%d",cnt++);
972 if(automatic_resume)
974 WAIT_4_SCB_CMD();
975 p->scb->cmd_ruc = RUC_RESUME;
976 ni_attn586();
977 WAIT_4_SCB_CMD_RUC();
980 #ifdef WAIT_4_BUSY
982 int i;
983 for(i=0;i<1024;i++)
985 if(p->rfd_top->status)
986 break;
987 DELAY_16();
988 if(i == 1023)
989 printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name);
992 #endif
994 #ifdef 0
995 if(!at_least_one)
997 int i;
998 volatile struct rfd_struct *rfds=p->rfd_top;
999 volatile struct rbd_struct *rbds;
1000 printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least);
1001 for(i=0;i< (p->num_recv_buffs+4);i++)
1003 rbds = (struct rbd_struct *) make32(rfds->rbd_offset);
1004 printk("%04x:%04x ",rfds->status,rbds->status);
1005 rfds = (struct rfd_struct *) make32(rfds->next);
1007 printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status);
1008 printk("\nerrs: %04x %04x rus: %02x, cus: %02x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->rus,(int)p->scb->cus);
1010 old_at_least = at_least_one;
1011 #endif
1013 if(debuglevel > 0)
1014 printk("r");
1017 /**********************************************************
1018 * handle 'Receiver went not ready'.
1021 static void ni52_rnr_int(struct device *dev)
1023 struct priv *p = (struct priv *) dev->priv;
1025 p->stats.rx_errors++;
1027 WAIT_4_SCB_CMD(); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
1028 p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
1029 ni_attn586();
1030 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. */
1032 alloc_rfa(dev,(char *)p->rfd_first);
1033 /* maybe add a check here, before restarting the RU */
1034 startrecv586(dev); /* restart RU */
1036 printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus);
1040 /**********************************************************
1041 * handle xmit - interrupt
1044 static void ni52_xmt_int(struct device *dev)
1046 int status;
1047 struct priv *p = (struct priv *) dev->priv;
1049 if(debuglevel > 0)
1050 printk("X");
1052 status = p->xmit_cmds[p->xmit_last]->cmd_status;
1053 if(!(status & STAT_COMPL))
1054 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name);
1056 if(status & STAT_OK)
1058 p->stats.tx_packets++;
1059 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
1061 else
1063 p->stats.tx_errors++;
1064 if(status & TCMD_LATECOLL) {
1065 printk("%s: late collision detected.\n",dev->name);
1066 p->stats.collisions++;
1068 else if(status & TCMD_NOCARRIER) {
1069 p->stats.tx_carrier_errors++;
1070 printk("%s: no carrier detected.\n",dev->name);
1072 else if(status & TCMD_LOSTCTS)
1073 printk("%s: loss of CTS detected.\n",dev->name);
1074 else if(status & TCMD_UNDERRUN) {
1075 p->stats.tx_fifo_errors++;
1076 printk("%s: DMA underrun detected.\n",dev->name);
1078 else if(status & TCMD_MAXCOLL) {
1079 printk("%s: Max. collisions exceeded.\n",dev->name);
1080 p->stats.collisions += 16;
1084 #if (NUM_XMIT_BUFFS > 1)
1085 if( (++p->xmit_last) == NUM_XMIT_BUFFS)
1086 p->xmit_last = 0;
1087 #endif
1089 dev->tbusy = 0;
1090 mark_bh(NET_BH);
1093 /***********************************************************
1094 * (re)start the receiver
1097 static void startrecv586(struct device *dev)
1099 struct priv *p = (struct priv *) dev->priv;
1101 WAIT_4_SCB_CMD();
1102 WAIT_4_SCB_CMD_RUC();
1103 p->scb->rfa_offset = make16(p->rfd_first);
1104 p->scb->cmd_ruc = RUC_START;
1105 ni_attn586(); /* start cmd. */
1106 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. (no timeout!!) */
1109 /******************************************************
1110 * send frame
1113 static int ni52_send_packet(struct sk_buff *skb, struct device *dev)
1115 int len,i;
1116 #ifndef NO_NOPCOMMANDS
1117 int next_nop;
1118 #endif
1119 struct priv *p = (struct priv *) dev->priv;
1121 if(dev->tbusy)
1123 int tickssofar = jiffies - dev->trans_start;
1124 if (tickssofar < 5)
1125 return 1;
1127 #ifndef NO_NOPCOMMANDS
1128 if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */
1130 dev->tbusy = 0;
1131 #ifdef DEBUG
1132 printk("%s: strange ... timeout with CU active?!?\n",dev->name);
1133 printk("%s: X0: %04x N0: %04x N1: %04x %d\n",dev->name,(int)p->xmit_cmds[0]->cmd_status,(int)p->nop_cmds[0]->cmd_status,(int)p->nop_cmds[1]->cmd_status,(int)p->nop_point);
1134 #endif
1135 p->scb->cmd_cuc = CUC_ABORT;
1136 ni_attn586();
1137 WAIT_4_SCB_CMD();
1138 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
1139 p->scb->cmd_cuc = CUC_START;
1140 ni_attn586();
1141 WAIT_4_SCB_CMD();
1142 dev->trans_start = jiffies;
1143 return 0;
1145 else
1146 #endif
1148 #ifdef DEBUG
1149 printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus);
1150 printk("%s: command-stats: %04x %04x\n",dev->name,p->xmit_cmds[0]->cmd_status,p->xmit_cmds[1]->cmd_status);
1151 printk("%s: check, whether you set the right interrupt number!\n",dev->name);
1152 #endif
1153 ni52_close(dev);
1154 ni52_open(dev);
1156 dev->trans_start = jiffies;
1157 return 0;
1160 if(skb == NULL)
1162 dev_tint(dev);
1163 return 0;
1166 if (skb->len <= 0)
1167 return 0;
1168 if(skb->len > XMIT_BUFF_SIZE)
1170 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
1171 return 0;
1174 if (set_bit(0, (void*)&dev->tbusy)) {
1175 printk("%s: Transmitter access conflict.\n", dev->name);
1176 return 1;
1178 #if(NUM_XMIT_BUFFS > 1)
1179 else if(set_bit(0,(void *) &p->lock)) {
1180 printk("%s: Queue was locked\n",dev->name);
1181 return 1;
1183 #endif
1184 else
1186 memcpy((char *)p->xmit_cbuffs[p->xmit_count],(char *)(skb->data),skb->len);
1187 len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
1189 #if (NUM_XMIT_BUFFS == 1)
1190 # ifdef NO_NOPCOMMANDS
1192 #ifdef DEBUG
1193 if(p->scb->cus & CU_ACTIVE)
1195 printk("%s: Hmmm .. CU is still running and we wanna send a new packet.\n",dev->name);
1196 printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,p->xmit_cmds[0]->cmd_status);
1198 #endif
1200 p->xmit_buffs[0]->size = TBD_LAST | len;
1201 for(i=0;i<16;i++)
1203 p->xmit_cmds[0]->cmd_status = 0;
1204 WAIT_4_SCB_CMD();
1205 if( (p->scb->cus & CU_STATUS) == CU_SUSPEND)
1206 p->scb->cmd_cuc = CUC_RESUME;
1207 else
1209 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1210 p->scb->cmd_cuc = CUC_START;
1213 ni_attn586();
1214 dev->trans_start = jiffies;
1215 if(!i)
1216 dev_kfree_skb(skb,FREE_WRITE);
1217 WAIT_4_SCB_CMD();
1218 if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */
1219 break;
1220 if(p->xmit_cmds[0]->cmd_status)
1221 break;
1222 if(i==15)
1223 printk("%s: Can't start transmit-command.\n",dev->name);
1225 # else
1226 next_nop = (p->nop_point + 1) & 0x1;
1227 p->xmit_buffs[0]->size = TBD_LAST | len;
1229 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1230 = make16((p->nop_cmds[next_nop]));
1231 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1233 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1234 dev->trans_start = jiffies;
1235 p->nop_point = next_nop;
1236 dev_kfree_skb(skb,FREE_WRITE);
1237 # endif
1238 #else
1239 p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
1240 if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS )
1241 next_nop = 0;
1243 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1244 /* linkpointer of xmit-command already points to next nop cmd */
1245 p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop]));
1246 p->nop_cmds[next_nop]->cmd_status = 0;
1248 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
1249 dev->trans_start = jiffies;
1250 p->xmit_count = next_nop;
1253 long flags;
1254 save_flags(flags);
1255 cli();
1256 if(p->xmit_count != p->xmit_last)
1257 dev->tbusy = 0;
1258 p->lock = 0;
1259 restore_flags(flags);
1261 dev_kfree_skb(skb,FREE_WRITE);
1262 #endif
1264 return 0;
1267 /*******************************************
1268 * Someone wanna have the statistics
1271 static struct net_device_stats *ni52_get_stats(struct device *dev)
1273 struct priv *p = (struct priv *) dev->priv;
1274 unsigned short crc,aln,rsc,ovrn;
1276 crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */
1277 p->scb->crc_errs = 0;
1278 aln = p->scb->aln_errs;
1279 p->scb->aln_errs = 0;
1280 rsc = p->scb->rsc_errs;
1281 p->scb->rsc_errs = 0;
1282 ovrn = p->scb->ovrn_errs;
1283 p->scb->ovrn_errs = 0;
1285 p->stats.rx_crc_errors += crc;
1286 p->stats.rx_fifo_errors += ovrn;
1287 p->stats.rx_frame_errors += aln;
1288 p->stats.rx_dropped += rsc;
1290 return &p->stats;
1293 /********************************************************
1294 * Set MC list ..
1296 static void set_multicast_list(struct device *dev)
1298 if(!dev->start)
1300 printk("%s: Can't apply promiscuous/multicastmode to a not running interface.\n",dev->name);
1301 return;
1304 dev->start = 0;
1306 ni_disint();
1307 alloc586(dev);
1308 init586(dev);
1309 startrecv586(dev);
1310 ni_enaint();
1312 dev->start = 1;
1315 #ifdef MODULE
1316 static struct device dev_ni52 = {
1317 " ", /* "ni5210": device name inserted by net_init.c */
1318 0, 0, 0, 0,
1319 0x300, 9, /* I/O address, IRQ */
1320 0, 0, 0, NULL, ni52_probe };
1322 /* set: io,irq,memstart,memend or set it when calling insmod */
1323 int irq=9;
1324 int io=0x300;
1325 long memstart=0; /* e.g 0xd0000 */
1326 long memend=0; /* e.g 0xd4000 */
1328 MODULE_PARM(io, "i");
1329 MODULE_PARM(irq, "i");
1330 MODULE_PARM(memstart, "l");
1331 MODULE_PARM(memend, "l");
1333 int init_module(void)
1335 if(io <= 0x0 || !memend || !memstart || irq < 2) {
1336 printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
1337 return -ENODEV;
1339 dev_ni52.irq = irq;
1340 dev_ni52.base_addr = io;
1341 dev_ni52.mem_end = memend;
1342 dev_ni52.mem_start = memstart;
1343 if (register_netdev(&dev_ni52) != 0)
1344 return -EIO;
1345 return 0;
1348 void cleanup_module(void)
1350 release_region(dev_ni52.base_addr, NI52_TOTAL_SIZE);
1351 kfree(dev_ni52.priv);
1352 dev_ni52.priv = NULL;
1353 unregister_netdev(&dev_ni52);
1355 #endif /* MODULE */
1357 #if 0
1359 * DUMP .. we expect a not running CMD unit and enough space
1361 void ni52_dump(struct device *dev,void *ptr)
1363 struct priv *p = (struct priv *) dev->priv;
1364 struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr;
1365 int i;
1367 p->scb->cmd_cuc = CUC_ABORT;
1368 ni_attn586();
1369 WAIT_4_SCB_CMD();
1370 WAIT_4_SCB_CMD_RUC();
1372 dump_cmd->cmd_status = 0;
1373 dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST;
1374 dump_cmd->dump_offset = make16((dump_cmd + 1));
1375 dump_cmd->cmd_link = 0xffff;
1377 p->scb->cbl_offset = make16(dump_cmd);
1378 p->scb->cmd_cuc = CUC_START;
1379 ni_attn586();
1380 WAIT_4_STAT_COMPL(dump_cmd);
1382 if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
1383 printk("%s: Can't get dump information.\n",dev->name);
1385 for(i=0;i<170;i++) {
1386 printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]);
1387 if(i % 24 == 23)
1388 printk("\n");
1390 printk("\n");
1392 #endif
1395 * END: linux/drivers/net/ni52.c