Import 2.3.18pre1
[davej-history.git] / drivers / net / arc-rimi.c
blobf9f4348913b016d3a2d9f6570ecd7e2fbcd1c750
1 /* $Id: arc-rimi.c,v 1.5 1997/11/09 11:04:57 mj Exp $
3 Derived from the original arcnet.c,
4 Written 1994-1996 by Avery Pennarun,
5 which was in turn derived from skeleton.c by Donald Becker.
7 **********************
9 The original copyright of skeleton.c was as follows:
11 skeleton.c Written 1993 by Donald Becker.
12 Copyright 1993 United States Government as represented by the
13 Director, National Security Agency. This software may only be used
14 and distributed according to the terms of the GNU Public License as
15 modified by SRC, incorporated herein by reference.
17 **********************
19 For more details, see drivers/net/arcnet.c
21 **********************
25 #include <linux/module.h>
26 #include <linux/version.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/types.h>
31 #include <linux/fcntl.h>
32 #include <linux/interrupt.h>
33 #include <linux/ptrace.h>
34 #include <linux/ioport.h>
35 #include <linux/in.h>
36 #include <linux/malloc.h>
37 #include <linux/string.h>
38 #include <linux/timer.h>
39 #include <linux/errno.h>
40 #include <linux/delay.h>
41 #include <linux/netdevice.h>
42 #include <linux/if_arp.h>
43 #include <linux/etherdevice.h>
44 #include <linux/skbuff.h>
45 #include <linux/init.h>
46 #include <linux/if_arcnet.h>
47 #include <linux/arcdevice.h>
49 #include <asm/system.h>
50 #include <asm/bitops.h>
51 #include <asm/io.h>
52 #include <asm/dma.h>
54 #include <net/arp.h>
56 /**************************************************************************/
58 /* On a fast computer, the buffer copy from memory to the ARCnet card during
59 * a transmit can hog the bus just a little too long. SLOW_XMIT_COPY
60 * replaces the fast memcpy() with a slower for() loop that seems to solve
61 * my problems with ftape.
63 * Probably a better solution would be to use memcpy_toio (more portable
64 * anyway) and modify that routine to support REALLY_SLOW_IO-style
65 * defines; ARCnet probably is not the only driver that can screw up an
66 * ftape DMA transfer.
68 * Turn this on if you have timing-sensitive DMA (ie. a tape drive) and
69 * would like to sacrifice a little bit of network speed to reduce tape
70 * write retries or some related problem.
72 #undef SLOW_XMIT_COPY
75 /* Internal function declarations */
77 static int arcrimi_probe(struct net_device *dev);
78 static void arcrimi_rx(struct net_device *dev,int recbuf);
79 static int arcrimi_found(struct net_device *dev,int ioaddr,int airq,u_long shmem);
80 static void arcrimi_inthandler (struct net_device *dev);
81 static int arcrimi_reset (struct net_device *dev, int reset_delay);
82 static void arcrimi_setmask (struct net_device *dev, u_char mask);
83 static void arcrimi_command (struct net_device *dev, u_char command);
84 static u_char arcrimi_status (struct net_device *dev);
85 static void arcrimi_prepare_tx(struct net_device *dev,u_char *hdr,int hdrlen,
86 char *data,int length,int daddr,int exceptA, int offset);
87 static void arcrimi_openclose(int open);
90 /* Module parameters */
92 #ifdef MODULE
93 static int shmem=0x0; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
94 static int irq=0; /* or use the insmod io= irq= shmem= options */
95 static char *device; /* use eg. device="arc1" to change name */
96 static int node=0; /* you must specify the node ID for RIM I cards */
98 MODULE_PARM(shmem, "i");
99 MODULE_PARM(irq, "i");
100 MODULE_PARM(device, "s");
101 MODULE_PARM (node, "i");
102 #else
103 void __init arcrimi_setup (char *str, int *ints);
104 extern struct net_device arcnet_devs[];
105 extern char arcnet_dev_names[][10];
106 extern int arcnet_num_devs;
107 #endif
109 /* Handy defines for ARCnet specific stuff */
111 /* COM 9026 controller chip --> ARCnet register addresses */
112 #define _INTMASK (ioaddr+0) /* writable */
113 #define _STATUS (ioaddr+0) /* readable */
114 #define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
115 #define _RESET (ioaddr+8) /* software reset (on read) */
116 #define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
117 #define _ADDR_HI (ioaddr+15) /* Control registers for said */
118 #define _ADDR_LO (ioaddr+14)
119 #define _CONFIG (ioaddr+2) /* Configuration register */
121 #define RDDATAflag 0x00 /* Next access is a read/~write */
123 #define ARCSTATUS readb(_STATUS)
124 #define ACOMMAND(cmd) writeb((cmd),_COMMAND)
125 #define ARCRESET writeb(TESTvalue,ioaddr-0x800) /* fake reset */
126 #define AINTMASK(msk) writeb((msk),_INTMASK)
127 #define SETCONF writeb(lp->config,_CONFIG)
129 static const char *version =
130 "arc-rimi.c: v3.00 97/11/09 Avery Pennarun <apenwarr@worldvisions.ca> et al.\n";
132 /****************************************************************************
134 * Probe and initialization *
136 ****************************************************************************/
139 /* We cannot probe for a RIM I card; one reason is I don't know how to reset
140 * them. In fact, we can't even get their node ID automatically. So, we
141 * need to be passed a specific shmem address, IRQ, and node ID.
143 int __init arcrimi_probe(struct net_device *dev)
145 BUGLVL(D_NORMAL) printk(version);
146 BUGMSG(D_NORMAL,"Given: node %02Xh, shmem %lXh, irq %d\n",
147 dev->dev_addr[0],dev->mem_start,dev->irq);
149 if (dev->mem_start<=0 || dev->irq<=0)
151 BUGMSG(D_NORMAL,"No autoprobe for RIM I; you "
152 "must specify the shmem and irq!\n");
153 return -ENODEV;
156 if (dev->dev_addr[0]==0)
158 BUGMSG(D_NORMAL,"You need to specify your card's station "
159 "ID!\n");
160 return -ENODEV;
163 return arcrimi_found(dev,dev->dev_addr[0],dev->irq,dev->mem_start);
167 /* Set up the struct net_device associated with this card. Called after
168 * probing succeeds.
170 int __init arcrimi_found(struct net_device *dev,int node,int airq, u_long shmem)
172 struct arcnet_local *lp;
173 u_long first_mirror,last_mirror;
174 int mirror_size;
176 /* reserve the irq */
177 if (request_irq(airq,&arcnet_interrupt,0,"arcnet (RIM I)",dev))
179 BUGMSG(D_NORMAL,"Can't get IRQ %d!\n",airq);
180 return -ENODEV;
182 dev->irq=airq;
184 dev->base_addr=0;
185 writeb(TESTvalue,shmem);
186 writeb(node,shmem+1); /* actually the node ID */
188 /* find the real shared memory start/end points, including mirrors */
189 #define BUFFER_SIZE (512)
190 #define MIRROR_SIZE (BUFFER_SIZE*4)
192 /* guess the actual size of one "memory mirror" - the number of
193 * bytes between copies of the shared memory. On most cards, it's
194 * 2k (or there are no mirrors at all) but on some, it's 4k.
196 mirror_size=MIRROR_SIZE;
197 if (readb(shmem)==TESTvalue
198 && readb(shmem-mirror_size)!=TESTvalue
199 && readb(shmem-2*mirror_size)==TESTvalue)
200 mirror_size*=2;
202 first_mirror=last_mirror=shmem;
203 while (readb(first_mirror)==TESTvalue) first_mirror-=mirror_size;
204 first_mirror+=mirror_size;
206 while (readb(last_mirror)==TESTvalue) last_mirror+=mirror_size;
207 last_mirror-=mirror_size;
209 dev->mem_start=first_mirror;
210 dev->mem_end=last_mirror+MIRROR_SIZE-1;
211 dev->rmem_start=dev->mem_start+BUFFER_SIZE*0;
212 dev->rmem_end=dev->mem_start+BUFFER_SIZE*2-1;
214 /* Initialize the rest of the device structure. */
216 dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
217 if (dev->priv == NULL)
219 free_irq(airq,dev);
220 return -ENOMEM;
222 memset(dev->priv,0,sizeof(struct arcnet_local));
223 lp=(struct arcnet_local *)(dev->priv);
224 lp->card_type = ARC_RIM_I;
225 lp->card_type_str = "RIM I";
226 lp->arcnet_reset=arcrimi_reset;
227 lp->asetmask=arcrimi_setmask;
228 lp->astatus=arcrimi_status;
229 lp->acommand=arcrimi_command;
230 lp->openclose_device=arcrimi_openclose;
231 lp->prepare_tx=arcrimi_prepare_tx;
232 lp->inthandler=arcrimi_inthandler;
234 /* Fill in the fields of the device structure with generic
235 * values.
237 arcnet_setup(dev);
239 /* And now fill particular fields with arcnet values */
240 dev->mtu=1500; /* completely arbitrary - agrees with ether, though */
241 dev->hard_header_len=sizeof(struct ClientData);
242 lp->sequence=1;
243 lp->recbuf=0;
245 BUGMSG(D_DURING,"ClientData header size is %d.\n",
246 sizeof(struct ClientData));
247 BUGMSG(D_DURING,"HardHeader size is %d.\n",
248 sizeof(struct archdr));
250 /* get and check the station ID from offset 1 in shmem */
251 lp->stationid = readb(first_mirror+1);
253 if (lp->stationid==0)
254 BUGMSG(D_NORMAL,"WARNING! Station address 00 is reserved "
255 "for broadcasts!\n");
256 else if (lp->stationid==255)
257 BUGMSG(D_NORMAL,"WARNING! Station address FF may confuse "
258 "DOS networking programs!\n");
259 dev->dev_addr[0]=lp->stationid;
261 BUGMSG(D_NORMAL,"ARCnet RIM I: station %02Xh found at IRQ %d, "
262 "ShMem %lXh (%ld*%d bytes).\n",
263 lp->stationid,
264 dev->irq, dev->mem_start,
265 (dev->mem_end-dev->mem_start+1)/mirror_size,mirror_size);
267 return 0;
271 /* Do a hardware reset on the card, and set up necessary registers.
273 * This should be called as little as possible, because it disrupts the
274 * token on the network (causes a RECON) and requires a significant delay.
276 * However, it does make sure the card is in a defined state.
278 int arcrimi_reset(struct net_device *dev,int reset_delay)
280 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
281 short ioaddr=dev->mem_start + 0x800;
282 int recbuf=lp->recbuf;
284 if (reset_delay==3)
286 ARCRESET;
287 return 0;
290 /* no IRQ's, please! */
291 lp->intmask=0;
292 SETMASK;
294 BUGMSG(D_INIT,"Resetting %s (status=%Xh)\n",
295 dev->name,ARCSTATUS);
297 ACOMMAND(CFLAGScmd|RESETclear); /* clear flags & end reset */
298 ACOMMAND(CFLAGScmd|CONFIGclear);
300 /* clear out status variables */
301 recbuf=lp->recbuf=0;
302 lp->txbuf=2;
304 /* enable extended (512-byte) packets */
305 ACOMMAND(CONFIGcmd|EXTconf);
307 #ifndef SLOW_XMIT_COPY
308 /* clean out all the memory to make debugging make more sense :) */
309 BUGLVL(D_DURING)
310 memset_io(dev->mem_start,0x42,2048);
311 #endif
313 /* and enable receive of our first packet to the first buffer */
314 EnableReceiver();
316 /* re-enable interrupts */
317 lp->intmask|=NORXflag;
318 #ifdef DETECT_RECONFIGS
319 lp->intmask|=RECONflag;
320 #endif
321 SETMASK;
323 /* done! return success. */
324 return 0;
328 static void arcrimi_openclose(int open)
330 if (open)
331 MOD_INC_USE_COUNT;
332 else
333 MOD_DEC_USE_COUNT;
336 static void arcrimi_setmask(struct net_device *dev, u_char mask)
338 int ioaddr=dev->mem_start+0x800;
340 AINTMASK(mask);
343 static u_char arcrimi_status(struct net_device *dev)
345 int ioaddr=dev->mem_start+0x800;
347 return ARCSTATUS;
350 static void arcrimi_command(struct net_device *dev, u_char cmd)
352 int ioaddr=dev->mem_start+0x800;
354 ACOMMAND(cmd);
358 /* The actual interrupt handler routine - handle various IRQ's generated
359 * by the card.
361 static void
362 arcrimi_inthandler(struct net_device *dev)
364 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
365 int ioaddr=dev->mem_start+0x800, status, boguscount = 3, didsomething;
367 AINTMASK(0);
369 BUGMSG(D_DURING,"in arcrimi_inthandler (status=%Xh, intmask=%Xh)\n",
370 ARCSTATUS,lp->intmask);
374 status = ARCSTATUS;
375 didsomething=0;
377 /* RESET flag was enabled - card is resetting and if RX
378 * is disabled, it's NOT because we just got a packet.
380 if (status & RESETflag)
382 BUGMSG(D_NORMAL,"spurious reset (status=%Xh)\n",
383 status);
384 arcrimi_reset(dev,0);
386 /* all other flag values are just garbage */
387 break;
390 /* RX is inhibited - we must have received something. */
391 if (status & lp->intmask & NORXflag)
393 int recbuf=lp->recbuf=!lp->recbuf;
395 BUGMSG(D_DURING,"receive irq (status=%Xh)\n",
396 status);
398 /* enable receive of our next packet */
399 EnableReceiver();
401 /* Got a packet. */
402 arcrimi_rx(dev,!recbuf);
404 didsomething++;
407 /* it can only be an xmit-done irq if we're xmitting :) */
408 /*if (status&TXFREEflag && !lp->in_txhandler && lp->sending)*/
409 if (status & lp->intmask & TXFREEflag)
411 struct Outgoing *out=&(lp->outgoing);
412 int was_sending=lp->sending;
414 lp->intmask &= ~TXFREEflag;
416 lp->in_txhandler++;
417 if (was_sending) lp->sending--;
419 BUGMSG(D_DURING,"TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
420 status,out->numsegs,out->segnum,out->skb);
422 if (was_sending && !(status&TXACKflag))
424 if (lp->lasttrans_dest != 0)
426 BUGMSG(D_EXTRA,"transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
427 status,lp->lasttrans_dest);
428 lp->stats.tx_errors++;
429 lp->stats.tx_carrier_errors++;
431 else
433 BUGMSG(D_DURING,"broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
434 status,
435 lp->lasttrans_dest);
439 /* send packet if there is one */
440 arcnet_go_tx(dev,0);
441 didsomething++;
443 if (lp->intx)
445 BUGMSG(D_DURING,"TXDONE while intx! (status=%Xh, intx=%d)\n",
446 ARCSTATUS,lp->intx);
447 lp->in_txhandler--;
448 continue;
451 if (!lp->outgoing.skb)
453 BUGMSG(D_DURING,"TX IRQ done: no split to continue.\n");
455 /* inform upper layers */
456 if (!lp->txready) arcnet_tx_done(dev, lp);
457 lp->in_txhandler--;
458 continue;
461 /* if more than one segment, and not all segments
462 * are done, then continue xmit.
464 if (out->segnum<out->numsegs)
465 arcnetA_continue_tx(dev);
466 arcnet_go_tx(dev,0);
468 /* if segnum==numsegs, the transmission is finished;
469 * free the skb.
471 if (out->segnum>=out->numsegs)
473 /* transmit completed */
474 out->segnum++;
475 if (out->skb)
477 lp->stats.tx_bytes += out->skb->len;
478 dev_kfree_skb(out->skb);
480 out->skb=NULL;
482 /* inform upper layers */
483 if (!lp->txready) arcnet_tx_done(dev, lp);
485 didsomething++;
487 lp->in_txhandler--;
489 else if (lp->txready && !lp->sending && !lp->intx)
491 BUGMSG(D_NORMAL,"recovery from silent TX (status=%Xh)\n",
492 status);
493 arcnet_go_tx(dev,0);
494 didsomething++;
497 #ifdef DETECT_RECONFIGS
498 if (status & (lp->intmask) & RECONflag)
500 ACOMMAND(CFLAGScmd|CONFIGclear);
501 lp->stats.tx_carrier_errors++;
503 #ifdef SHOW_RECONFIGS
504 BUGMSG(D_NORMAL,"Network reconfiguration detected (status=%Xh)\n",
505 status);
506 #endif /* SHOW_RECONFIGS */
508 #ifdef RECON_THRESHOLD
509 /* is the RECON info empty or old? */
510 if (!lp->first_recon || !lp->last_recon ||
511 jiffies-lp->last_recon > HZ*10)
513 if (lp->network_down)
514 BUGMSG(D_NORMAL,"reconfiguration detected: cabling restored?\n");
515 lp->first_recon=lp->last_recon=jiffies;
516 lp->num_recons=lp->network_down=0;
518 BUGMSG(D_DURING,"recon: clearing counters.\n");
520 else /* add to current RECON counter */
522 lp->last_recon=jiffies;
523 lp->num_recons++;
525 BUGMSG(D_DURING,"recon: counter=%d, time=%lds, net=%d\n",
526 lp->num_recons,
527 (lp->last_recon-lp->first_recon)/HZ,
528 lp->network_down);
530 /* if network is marked up;
531 * and first_recon and last_recon are 60+ sec
532 * apart;
533 * and the average no. of recons counted is
534 * > RECON_THRESHOLD/min;
535 * then print a warning message.
537 if (!lp->network_down
538 && (lp->last_recon-lp->first_recon)<=HZ*60
539 && lp->num_recons >= RECON_THRESHOLD)
541 lp->network_down=1;
542 BUGMSG(D_NORMAL,"many reconfigurations detected: cabling problem?\n");
544 else if (!lp->network_down
545 && lp->last_recon-lp->first_recon > HZ*60)
547 /* reset counters if we've gone for
548 * over a minute.
550 lp->first_recon=lp->last_recon;
551 lp->num_recons=1;
555 else if (lp->network_down && jiffies-lp->last_recon > HZ*10)
557 if (lp->network_down)
558 BUGMSG(D_NORMAL,"cabling restored?\n");
559 lp->first_recon=lp->last_recon=0;
560 lp->num_recons=lp->network_down=0;
562 BUGMSG(D_DURING,"not recon: clearing counters anyway.\n");
563 #endif
565 #endif /* DETECT_RECONFIGS */
566 } while (--boguscount && didsomething);
568 BUGMSG(D_DURING,"net_interrupt complete (status=%Xh, count=%d)\n",
569 ARCSTATUS,boguscount);
570 BUGMSG(D_DURING,"\n");
572 SETMASK; /* put back interrupt mask */
576 /* A packet has arrived; grab it from the buffers and pass it to the generic
577 * arcnet_rx routing to deal with it.
580 static void
581 arcrimi_rx(struct net_device *dev,int recbuf)
583 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
584 int ioaddr=dev->mem_start+0x800;
585 union ArcPacket *arcpacket=
586 (union ArcPacket *)phys_to_virt(dev->mem_start+recbuf*512);
587 u_char *arcsoft;
588 short length,offset;
589 u_char daddr,saddr;
591 lp->stats.rx_packets++;
593 saddr=arcpacket->hardheader.source;
595 /* if source is 0, it's a "used" packet! */
596 if (saddr==0)
598 BUGMSG(D_NORMAL,"discarding old packet. (status=%Xh)\n",
599 ARCSTATUS);
600 lp->stats.rx_errors++;
601 return;
603 /* Set source address to zero to mark it as old */
605 arcpacket->hardheader.source=0;
607 daddr=arcpacket->hardheader.destination;
609 if (arcpacket->hardheader.offset1) /* Normal Packet */
611 offset=arcpacket->hardheader.offset1;
612 arcsoft=&arcpacket->raw[offset];
613 length=256-offset;
615 else /* ExtendedPacket or ExceptionPacket */
617 offset=arcpacket->hardheader.offset2;
618 arcsoft=&arcpacket->raw[offset];
620 length=512-offset;
623 arcnet_rx(lp, arcsoft, length, saddr, daddr);
625 BUGLVL(D_RX) arcnet_dump_packet(lp->adev,arcpacket->raw,length>240,"rx");
627 #ifndef SLOW_XMIT_COPY
628 /* clean out the page to make debugging make more sense :) */
629 BUGLVL(D_DURING)
630 memset((void *)arcpacket->raw,0x42,512);
631 #endif
635 /* Given an skb, copy a packet into the ARCnet buffers for later transmission
636 * by arcnet_go_tx.
638 static void
639 arcrimi_prepare_tx(struct net_device *dev,u_char *hdr,int hdrlen,
640 char *data,int length,int daddr,int exceptA, int offset)
642 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
643 union ArcPacket *arcpacket =
644 (union ArcPacket *)phys_to_virt(dev->mem_start+512*(lp->txbuf^1));
646 #ifdef SLOW_XMIT_COPY
647 char *iptr,*iend,*optr;
648 #endif
650 lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate between 2 and 3 */
652 length+=hdrlen;
654 BUGMSG(D_TX,"arcnetAS_prep_tx: hdr:%ph, length:%d, data:%ph\n",
655 hdr,length,data);
657 #ifndef SLOW_XMIT_COPY
658 /* clean out the page to make debugging make more sense :) */
659 BUGLVL(D_DURING)
660 memset_io(dev->mem_start+lp->txbuf*512,0x42,512);
661 #endif
663 arcpacket->hardheader.destination=daddr;
665 /* load packet into shared memory */
666 if (length<=MTU) /* Normal (256-byte) Packet */
667 arcpacket->hardheader.offset1=offset=offset?offset:256-length;
669 else if (length>=MinTU || offset) /* Extended (512-byte) Packet */
671 arcpacket->hardheader.offset1=0;
672 arcpacket->hardheader.offset2=offset=offset?offset:512-length;
674 else if (exceptA) /* RFC1201 Exception Packet */
676 arcpacket->hardheader.offset1=0;
677 arcpacket->hardheader.offset2=offset=512-length-4;
679 /* exception-specific stuff - these four bytes
680 * make the packet long enough to fit in a 512-byte
681 * frame.
684 arcpacket->raw[offset+0]=hdr[0];
685 arcpacket->raw[offset+1]=0xFF; /* FF flag */
686 arcpacket->raw[offset+2]=0xFF; /* FF padding */
687 arcpacket->raw[offset+3]=0xFF; /* FF padding */
688 offset+=4;
690 else /* "other" Exception packet */
692 /* RFC1051 - set 4 trailing bytes to 0 */
693 memset(&arcpacket->raw[508],0,4);
695 /* now round up to MinTU */
696 arcpacket->hardheader.offset1=0;
697 arcpacket->hardheader.offset2=offset=512-MinTU;
701 /* copy the packet into ARCnet shmem
702 * - the first bytes of ClientData header are skipped
705 memcpy((u_char*)arcpacket+offset, (u_char*)hdr,hdrlen);
706 #ifdef SLOW_XMIT_COPY
707 for (iptr=data,iend=iptr+length-hdrlen,optr=(char *)arcpacket+offset+hdrlen;
708 iptr<iend; iptr++,optr++)
710 *optr=*iptr;
711 /*udelay(5);*/
713 #else
714 memcpy((u_char*)arcpacket+offset+hdrlen, data,length-hdrlen);
715 #endif
717 BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
718 daddr,length);
720 BUGLVL(D_TX) arcnet_dump_packet(dev,arcpacket->raw,length>MTU,"tx");
722 lp->lastload_dest=daddr;
723 lp->txready=lp->txbuf; /* packet is ready for sending */
727 /****************************************************************************
729 * Kernel Loadable Module Support *
731 ****************************************************************************/
734 #ifdef MODULE
736 static char devicename[9] = "";
737 static struct net_device thiscard = {
738 devicename, /* device name is inserted by linux/drivers/net/net_init.c */
739 0, 0, 0, 0,
740 0, 0, /* I/O address, IRQ */
741 0, 0, 0, NULL, arcrimi_probe
745 int init_module(void)
747 struct net_device *dev=&thiscard;
748 if (device)
749 strcpy(dev->name,device);
750 else arcnet_makename(dev->name);
752 if (node && node != 0xff)
753 dev->dev_addr[0]=node;
755 dev->irq=irq;
756 if (dev->irq==2) dev->irq=9;
758 if (shmem)
760 dev->mem_start=shmem;
761 dev->mem_end=thiscard.mem_start+512*4-1;
762 dev->rmem_start=thiscard.mem_start+512*0;
763 dev->rmem_end=thiscard.mem_start+512*2-1;
766 if (register_netdev(dev) != 0)
767 return -EIO;
768 arcnet_use_count(1);
769 return 0;
772 void cleanup_module(void)
774 struct net_device *dev=&thiscard;
775 int ioaddr=dev->mem_start;
777 if (dev->start) (*dev->stop)(dev);
779 /* Flush TX and disable RX */
780 if (ioaddr)
782 AINTMASK(0); /* disable IRQ's */
783 ACOMMAND(NOTXcmd); /* stop transmit */
784 ACOMMAND(NORXcmd); /* disable receive */
787 if (dev->irq)
789 free_irq(dev->irq,dev);
792 unregister_netdev(dev);
793 kfree(dev->priv);
794 dev->priv = NULL;
795 arcnet_use_count(0);
798 #else
800 void __init arcrimi_setup (char *str, int *ints)
802 struct net_device *dev;
804 if (arcnet_num_devs == MAX_ARCNET_DEVS)
806 printk("ARCnet RIM I: Too many ARCnet devices registered (max %d).\n",
807 MAX_ARCNET_DEVS);
808 return;
811 dev=&arcnet_devs[arcnet_num_devs];
813 if (ints[0] < 3)
815 printk("ARCnet RIM I: You must give address, IRQ and node ID.\n");
816 return;
819 dev->init=arcrimi_probe;
821 switch(ints[0])
823 case 4: /* ERROR */
824 printk("ARCnet RIM I: Too many arguments.\n");
826 case 3: /* Node ID */
827 dev->dev_addr[0]=(u_char)ints[3];
829 case 2: /* IRQ */
830 dev->irq=ints[2];
832 case 1: /* Mem address */
833 dev->mem_start=ints[1];
836 dev->name = (char *)&arcnet_dev_names[arcnet_num_devs];
838 if (str)
839 strncpy(dev->name, str, 9);
841 arcnet_num_devs++;
844 #endif /* MODULE */