* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / net / com90io.c
blob8c12c632508b21f14657d03c0fcf2c12f4d99e5a
1 /* $Id: com90io.c,v 1.6 1997/11/09 11:04:59 mj Exp $
3 Written 1997 by David Woodhouse <dwmw2@cam.ac.uk>
5 Derived from the original arcnet.c,
6 Written 1994-1996 by Avery Pennarun,
7 which was in turn derived from skeleton.c by Donald Becker.
9 **********************
11 The original copyright of skeleton.c was as follows:
13 skeleton.c Written 1993 by Donald Becker.
14 Copyright 1993 United States Government as represented by the
15 Director, National Security Agency. This software may only be used
16 and distributed according to the terms of the GNU Public License as
17 modified by SRC, incorporated herein by reference.
19 **********************
21 For more details, see drivers/net/arcnet.c
23 **********************
27 #include <linux/module.h>
28 #include <linux/version.h>
30 #include <linux/kernel.h>
31 #include <linux/sched.h>
32 #include <linux/types.h>
33 #include <linux/fcntl.h>
34 #include <linux/interrupt.h>
35 #include <linux/ptrace.h>
36 #include <linux/ioport.h>
37 #include <linux/in.h>
38 #include <linux/malloc.h>
39 #include <linux/string.h>
40 #include <linux/timer.h>
41 #include <linux/errno.h>
42 #include <linux/delay.h>
43 #include <linux/netdevice.h>
44 #include <linux/if_arp.h>
45 #include <linux/etherdevice.h>
46 #include <linux/skbuff.h>
47 #include <linux/init.h>
48 #include <linux/if_arcnet.h>
49 #include <linux/arcdevice.h>
51 #include <asm/system.h>
52 #include <asm/bitops.h>
53 #include <asm/io.h>
54 #include <asm/dma.h>
56 #include <net/arp.h>
59 /* Internal function declarations */
61 static int arc90io_probe(struct net_device *dev);
62 static void arc90io_rx(struct net_device *dev,int recbuf);
63 static int arc90io_found(struct net_device *dev,int ioaddr,int airq);
64 static void arc90io_inthandler (struct net_device *dev);
65 static int arc90io_reset (struct net_device *dev, int reset_delay);
66 static void arc90io_setmask (struct net_device *dev, u_char mask);
67 static void arc90io_command (struct net_device *dev, u_char command);
68 static u_char arc90io_status (struct net_device *dev);
69 static void arc90io_prepare_tx(struct net_device *dev,u_char *hdr,int hdrlen,
70 char *data,int length,int daddr,int exceptA, int offset);
71 static void arc90io_openclose(int open);
73 static u_char get_buffer_byte (struct net_device *dev, unsigned offset);
74 static void put_buffer_byte (struct net_device *dev, unsigned offset, u_char datum);
75 static void get_whole_buffer (struct net_device *dev, unsigned offset, unsigned length, char *dest);
76 static void put_whole_buffer (struct net_device *dev, unsigned offset, unsigned length, char *dest);
79 /* Module parameters */
81 #ifdef MODULE
82 static int io=0x0; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
83 static int irq=0; /* or use the insmod io= irq= shmem= options */
84 static char *device; /* use eg. device="arc1" to change name */
86 MODULE_PARM(io, "i");
87 MODULE_PARM(irq, "i");
88 MODULE_PARM(device, "s");
89 #else
90 void __init com90io_setup (char *str, int *ints);
91 extern struct net_device arcnet_devs[];
92 extern char arcnet_dev_names[][10];
93 extern int arcnet_num_devs;
94 #endif
97 /* Handy defines for ARCnet specific stuff */
99 /* The number of low I/O ports used by the card. */
100 #define ARCNET_TOTAL_SIZE 16
102 /* COM 9026 controller chip --> ARCnet register addresses */
103 #define _INTMASK (ioaddr+0) /* writable */
104 #define _STATUS (ioaddr+0) /* readable */
105 #define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
106 #define _RESET (ioaddr+8) /* software reset (on read) */
107 #define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
108 #define _ADDR_HI (ioaddr+15) /* Control registers for said */
109 #define _ADDR_LO (ioaddr+14)
110 #define _CONFIG (ioaddr+2) /* Configuration register */
112 #define ARCSTATUS inb(_STATUS)
113 #define ACOMMAND(cmd) outb((cmd),_COMMAND)
114 #define AINTMASK(msk) outb((msk),_INTMASK)
116 #define ARCRESET inb(_RESET)
118 #define SETCONF outb((lp->config),_CONFIG)
121 /****************************************************************************
123 * IO-mapped operation routines *
125 ****************************************************************************/
127 u_char get_buffer_byte (struct net_device *dev, unsigned offset)
129 int ioaddr=dev->base_addr;
131 outb(offset >> 8, _ADDR_HI);
132 outb(offset & 0xff, _ADDR_LO);
134 return inb(_MEMDATA);
137 void put_buffer_byte (struct net_device *dev, unsigned offset, u_char datum)
139 int ioaddr=dev->base_addr;
141 outb(offset >> 8, _ADDR_HI);
142 outb(offset & 0xff, _ADDR_LO);
144 outb(datum, _MEMDATA);
148 #undef ONE_AT_A_TIME_TX
149 #undef ONE_AT_A_TIME_RX
151 void get_whole_buffer (struct net_device *dev, unsigned offset, unsigned length, char *dest)
153 int ioaddr=dev->base_addr;
155 outb( (offset >> 8) | AUTOINCflag, _ADDR_HI);
156 outb( offset & 0xff, _ADDR_LO);
158 while (length--)
159 #ifdef ONE_AT_A_TIME_RX
160 *(dest++) = get_buffer_byte(dev,offset++);
161 #else
162 *(dest++) = inb (_MEMDATA);
163 #endif
166 void put_whole_buffer (struct net_device *dev, unsigned offset, unsigned length, char *dest)
168 int ioaddr=dev->base_addr;
170 outb( (offset >> 8) | AUTOINCflag, _ADDR_HI);
171 outb( offset & 0xff, _ADDR_LO);
173 while (length--)
174 #ifdef ONE_AT_A_TIME_TX
175 put_buffer_byte(dev,offset++,*(dest++));
176 #else
177 outb (*(dest++), _MEMDATA);
178 #endif
182 static const char *version =
183 "com90io.c: v3.00 97/11/09 Avery Pennarun <apenwarr@worldvisions.ca> et al.\n";
186 /****************************************************************************
188 * Probe and initialization *
190 ****************************************************************************/
192 /* We cannot probe for an IO mapped card either, although we can check that
193 * it's where we were told it was, and even autoirq
196 int __init arc90io_probe(struct net_device *dev)
198 int ioaddr=dev->base_addr,status,delayval;
199 unsigned long airqmask;
201 BUGLVL(D_NORMAL) printk(version);
203 if (ioaddr<0x200)
205 BUGMSG(D_NORMAL,"No autoprobe for IO mapped cards; you "
206 "must specify the base address!\n");
207 return -ENODEV;
210 if (check_region(ioaddr, ARCNET_TOTAL_SIZE))
212 BUGMSG(D_INIT_REASONS,"IO check_region %x-%x failed.\n",
213 ioaddr,ioaddr+ARCNET_TOTAL_SIZE-1);
214 return -ENXIO;
217 if (ARCSTATUS == 0xFF)
219 BUGMSG(D_INIT_REASONS,"IO address %x empty\n",ioaddr);
220 return -ENODEV;
223 ARCRESET;
224 JIFFER(RESETtime);
226 status=ARCSTATUS;
228 if ((status & 0x9D)
229 != (NORXflag|RECONflag|TXFREEflag|RESETflag))
231 BUGMSG(D_INIT_REASONS,"Status invalid (%Xh).\n",status);
232 return -ENODEV;
235 BUGMSG(D_INIT_REASONS,"Status after reset: %X\n",status);
237 ACOMMAND(CFLAGScmd|RESETclear|CONFIGclear);
239 BUGMSG(D_INIT_REASONS,"Status after reset acknowledged: %X\n",status);
241 status=ARCSTATUS;
243 if (status & RESETflag)
245 BUGMSG(D_INIT_REASONS,"Eternal reset (status=%Xh)\n",status);
246 return -ENODEV;
249 outb((0x16 | IOMAPflag) &~ENABLE16flag, _CONFIG);
251 /* Read first loc'n of memory */
253 outb(AUTOINCflag ,_ADDR_HI);
254 outb(0,_ADDR_LO);
256 if ((status=inb(_MEMDATA)) != 0xd1)
258 BUGMSG(D_INIT_REASONS,"Signature byte not found"
259 " (%Xh instead).\n", status);
260 return -ENODEV;
263 if (!dev->irq)
265 /* if we do this, we're sure to get an IRQ since the
266 * card has just reset and the NORXflag is on until
267 * we tell it to start receiving.
270 airqmask = probe_irq_on();
271 outb(NORXflag,_INTMASK);
272 udelay(1);
273 outb(0,_INTMASK);
274 dev->irq = probe_irq_off(airqmask);
276 if (dev->irq<=0)
278 BUGMSG(D_INIT_REASONS,"Autoprobe IRQ failed\n");
279 return -ENODEV;
283 return arc90io_found(dev,dev->base_addr,dev->irq);
287 /* Set up the struct net_device associated with this card. Called after
288 * probing succeeds.
290 int __init arc90io_found(struct net_device *dev,int ioaddr,int airq)
292 struct arcnet_local *lp;
294 /* reserve the irq */
295 if (request_irq(airq,&arcnet_interrupt,0,"arcnet (COM90xx-IO)",dev))
297 BUGMSG(D_NORMAL,"Can't get IRQ %d!\n",airq);
298 return -ENODEV;
300 dev->irq=airq;
302 /* reserve the I/O region - guaranteed to work by check_region */
303 request_region(ioaddr,ARCNET_TOTAL_SIZE,"arcnet (COM90xx-IO)");
304 dev->base_addr=ioaddr;
306 dev->mem_start=dev->mem_end=dev->rmem_start=dev->rmem_end=(long)NULL;
308 /* Initialize the rest of the device structure. */
310 dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
311 if (dev->priv == NULL)
313 free_irq(airq,dev);
314 release_region(ioaddr,ARCNET_TOTAL_SIZE);
315 return -ENOMEM;
318 memset(dev->priv,0,sizeof(struct arcnet_local));
319 lp=(struct arcnet_local *)(dev->priv);
320 lp->card_type = ARC_90xx_IO;
321 lp->card_type_str = "COM 90xx (IO)";
323 lp->arcnet_reset=arc90io_reset;
324 lp->asetmask=arc90io_setmask;
325 lp->astatus=arc90io_status;
326 lp->acommand=arc90io_command;
327 lp->openclose_device=arc90io_openclose;
328 lp->prepare_tx=arc90io_prepare_tx;
329 lp->inthandler=arc90io_inthandler;
331 /* Fill in the fields of the device structure with generic
332 * values.
334 arcnet_setup(dev);
336 /* And now fill particular fields with arcnet values */
337 dev->mtu=1500; /* completely arbitrary - agrees with ether, though */
338 dev->hard_header_len=sizeof(struct ClientData);
339 lp->sequence=1;
340 lp->recbuf=0;
342 BUGMSG(D_DURING,"ClientData header size is %d.\n",
343 sizeof(struct ClientData));
344 BUGMSG(D_DURING,"HardHeader size is %d.\n",
345 sizeof(struct archdr));
347 lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
348 SETCONF;
350 /* get and check the station ID from offset 1 in shmem */
352 lp->stationid = get_buffer_byte(dev,1);
354 if (!lp->stationid)
355 BUGMSG(D_NORMAL,"WARNING! Station address 00 is reserved "
356 "for broadcasts!\n");
357 else if (lp->stationid==255)
358 BUGMSG(D_NORMAL,"WARNING! Station address FF may confuse "
359 "DOS networking programs!\n");
360 dev->dev_addr[0]=lp->stationid;
362 BUGMSG(D_NORMAL,"ARCnet COM90xx in IO-mapped mode: "
363 "station %02Xh found at %03lXh, IRQ %d.\n",
364 lp->stationid,
365 dev->base_addr,dev->irq);
367 return 0;
371 /****************************************************************************
373 * Utility routines *
375 ****************************************************************************/
377 /* Do a hardware reset on the card, and set up necessary registers.
379 * This should be called as little as possible, because it disrupts the
380 * token on the network (causes a RECON) and requires a significant delay.
382 * However, it does make sure the card is in a defined state.
384 int arc90io_reset(struct net_device *dev,int reset_delay)
386 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
387 short ioaddr=dev->base_addr;
388 int delayval,recbuf=lp->recbuf;
390 if (reset_delay==3)
392 ARCRESET;
393 return 0;
396 /* no IRQ's, please! */
397 lp->intmask=0;
398 SETMASK;
400 BUGMSG(D_INIT,"Resetting %s (status=%Xh)\n",
401 dev->name,ARCSTATUS);
403 /* Set the thing to IO-mapped, 8-bit mode */
404 lp->config = (0x1C|IOMAPflag) & ~ENABLE16flag;
405 SETCONF;
407 if (reset_delay)
409 /* reset the card */
410 ARCRESET;
411 JIFFER(RESETtime);
414 ACOMMAND(CFLAGScmd|RESETclear); /* clear flags & end reset */
415 ACOMMAND(CFLAGScmd|CONFIGclear);
417 /* verify that the ARCnet signature byte is present */
419 if (get_buffer_byte(dev,0) != TESTvalue)
421 BUGMSG(D_NORMAL,"reset failed: TESTvalue not present.\n");
422 return 1;
425 /* clear out status variables */
426 recbuf=lp->recbuf=0;
427 lp->txbuf=2;
429 /* enable extended (512-byte) packets */
430 ACOMMAND(CONFIGcmd|EXTconf);
432 /* and enable receive of our first packet to the first buffer */
433 EnableReceiver();
435 /* re-enable interrupts */
436 lp->intmask|=NORXflag;
437 #ifdef DETECT_RECONFIGS
438 lp->intmask|=RECONflag;
439 #endif
440 SETMASK;
442 /* done! return success. */
443 return 0;
447 static void arc90io_openclose(int open)
449 if (open)
450 MOD_INC_USE_COUNT;
451 else
452 MOD_DEC_USE_COUNT;
456 static void arc90io_setmask(struct net_device *dev, u_char mask)
458 short ioaddr=dev->base_addr;
460 AINTMASK(mask);
463 static u_char arc90io_status(struct net_device *dev)
465 short ioaddr=dev->base_addr;
467 return ARCSTATUS;
470 static void arc90io_command(struct net_device *dev, u_char cmd)
472 short ioaddr=dev->base_addr;
474 ACOMMAND(cmd);
478 /* The actual interrupt handler routine - handle various IRQ's generated
479 * by the card.
481 static void
482 arc90io_inthandler(struct net_device *dev)
484 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
485 int ioaddr=dev->base_addr, status, boguscount = 3, didsomething;
487 AINTMASK(0);
489 BUGMSG(D_DURING,"in arc90io_inthandler (status=%Xh, intmask=%Xh)\n",
490 ARCSTATUS,lp->intmask);
494 status = ARCSTATUS;
495 didsomething=0;
497 /* RESET flag was enabled - card is resetting and if RX
498 * is disabled, it's NOT because we just got a packet.
500 if (status & RESETflag)
502 BUGMSG(D_NORMAL,"spurious reset (status=%Xh)\n",
503 status);
504 arc90io_reset(dev,0);
506 /* all other flag values are just garbage */
507 break;
510 /* RX is inhibited - we must have received something. */
511 if (status & lp->intmask & NORXflag)
513 int recbuf=lp->recbuf=!lp->recbuf;
514 int oldaddr=0;
516 BUGMSG(D_DURING,"receive irq (status=%Xh)\n",
517 status);
519 /* enable receive of our next packet */
520 EnableReceiver();
522 if (lp->intx)
523 oldaddr=(inb(_ADDR_HI)<<8) | inb(_ADDR_LO);
526 /* Got a packet. */
527 arc90io_rx(dev,!recbuf);
530 if (lp->intx)
532 outb( (oldaddr >> 8), _ADDR_HI);
533 outb( oldaddr & 0xff, _ADDR_LO);
536 didsomething++;
539 /* it can only be an xmit-done irq if we're xmitting :) */
540 /*if (status&TXFREEflag && !lp->in_txhandler && lp->sending)*/
541 if (status & lp->intmask & TXFREEflag)
543 struct Outgoing *out=&(lp->outgoing);
544 int was_sending=lp->sending;
546 lp->intmask &= ~TXFREEflag;
548 lp->in_txhandler++;
549 if (was_sending) lp->sending--;
551 BUGMSG(D_DURING,"TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
552 status,out->numsegs,out->segnum,out->skb);
554 if (was_sending && !(status&TXACKflag))
556 if (lp->lasttrans_dest != 0)
558 BUGMSG(D_EXTRA,"transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
559 status,lp->lasttrans_dest);
560 lp->stats.tx_errors++;
561 lp->stats.tx_carrier_errors++;
563 else
565 BUGMSG(D_DURING,"broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
566 status,
567 lp->lasttrans_dest);
571 /* send packet if there is one */
572 arcnet_go_tx(dev,0);
573 didsomething++;
575 if (lp->intx)
577 BUGMSG(D_DURING,"TXDONE while intx! (status=%Xh, intx=%d)\n",
578 ARCSTATUS,lp->intx);
579 lp->in_txhandler--;
580 continue;
583 if (!lp->outgoing.skb)
585 BUGMSG(D_DURING,"TX IRQ done: no split to continue.\n");
587 /* inform upper layers */
588 if (!lp->txready) arcnet_tx_done(dev, lp);
589 lp->in_txhandler--;
590 continue;
593 /* if more than one segment, and not all segments
594 * are done, then continue xmit.
596 if (out->segnum<out->numsegs)
597 arcnetA_continue_tx(dev);
598 arcnet_go_tx(dev,0);
600 /* if segnum==numsegs, the transmission is finished;
601 * free the skb.
603 if (out->segnum>=out->numsegs)
605 /* transmit completed */
606 out->segnum++;
607 if (out->skb)
609 lp->stats.tx_bytes += out->skb->len;
610 dev_kfree_skb(out->skb);
612 out->skb=NULL;
614 /* inform upper layers */
615 if (!lp->txready) arcnet_tx_done(dev, lp);
617 didsomething++;
619 lp->in_txhandler--;
621 else if (lp->txready && !lp->sending && !lp->intx)
623 BUGMSG(D_NORMAL,"recovery from silent TX (status=%Xh)\n",
624 status);
625 arcnet_go_tx(dev,0);
626 didsomething++;
629 #ifdef DETECT_RECONFIGS
630 if (status & (lp->intmask) & RECONflag)
632 ACOMMAND(CFLAGScmd|CONFIGclear);
633 lp->stats.tx_carrier_errors++;
635 #ifdef SHOW_RECONFIGS
636 BUGMSG(D_NORMAL,"Network reconfiguration detected"
637 " (status=%Xh, config=%X)\n",
638 status,lp->config);
639 #endif /* SHOW_RECONFIGS */
641 #ifdef RECON_THRESHOLD
642 /* is the RECON info empty or old? */
643 if (!lp->first_recon || !lp->last_recon ||
644 jiffies-lp->last_recon > HZ*10)
646 if (lp->network_down)
647 BUGMSG(D_NORMAL,"reconfiguration detected: cabling restored?\n");
648 lp->first_recon=lp->last_recon=jiffies;
649 lp->num_recons=lp->network_down=0;
651 BUGMSG(D_DURING,"recon: clearing counters.\n");
653 else /* add to current RECON counter */
655 lp->last_recon=jiffies;
656 lp->num_recons++;
658 BUGMSG(D_DURING,"recon: counter=%d, time=%lds, net=%d\n",
659 lp->num_recons,
660 (lp->last_recon-lp->first_recon)/HZ,
661 lp->network_down);
663 /* if network is marked up;
664 * and first_recon and last_recon are 60+ sec
665 * apart;
666 * and the average no. of recons counted is
667 * > RECON_THRESHOLD/min;
668 * then print a warning message.
670 if (!lp->network_down
671 && (lp->last_recon-lp->first_recon)<=HZ*60
672 && lp->num_recons >= RECON_THRESHOLD)
674 lp->network_down=1;
675 BUGMSG(D_NORMAL,"many reconfigurations detected: cabling problem?\n");
677 else if (!lp->network_down
678 && lp->last_recon-lp->first_recon > HZ*60)
680 /* reset counters if we've gone for
681 * over a minute.
683 lp->first_recon=lp->last_recon;
684 lp->num_recons=1;
688 else if (lp->network_down && jiffies-lp->last_recon > HZ*10)
690 if (lp->network_down)
691 BUGMSG(D_NORMAL,"cabling restored?\n");
692 lp->first_recon=lp->last_recon=0;
693 lp->num_recons=lp->network_down=0;
695 BUGMSG(D_DURING,"not recon: clearing counters anyway.\n");
696 #endif
698 #endif /* DETECT_RECONFIGS */
699 } while (--boguscount && didsomething);
701 BUGMSG(D_DURING,"net_interrupt complete (status=%Xh, count=%d)\n",
702 ARCSTATUS,boguscount);
703 BUGMSG(D_DURING,"\n");
705 SETMASK; /* put back interrupt mask */
709 /* A packet has arrived; grab it from the buffers and pass it to the generic
710 * arcnet_rx routing to deal with it.
713 static void
714 arc90io_rx(struct net_device *dev,int recbuf)
716 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
717 int ioaddr=dev->base_addr;
718 union ArcPacket packetbuf;
719 union ArcPacket *arcpacket=&packetbuf;
720 u_char *arcsoft;
721 short length,offset;
722 u_char daddr,saddr;
724 lp->stats.rx_packets++;
726 get_whole_buffer(dev,recbuf*512,4,(char *)arcpacket);
728 saddr=arcpacket->hardheader.source;
730 /* if source is 0, it's a "used" packet! */
731 if (saddr==0)
733 BUGMSG(D_NORMAL,"discarding old packet. (status=%Xh)\n",
734 ARCSTATUS);
735 lp->stats.rx_errors++;
736 return;
738 /* Set source address to zero to mark it as old */
740 put_buffer_byte(dev,recbuf*512,0);
742 arcpacket->hardheader.source=0;
744 daddr=arcpacket->hardheader.destination;
746 if (arcpacket->hardheader.offset1) /* Normal Packet */
748 offset=arcpacket->hardheader.offset1;
749 arcsoft=&arcpacket->raw[offset];
750 length=256-offset;
752 else /* ExtendedPacket or ExceptionPacket */
754 offset=arcpacket->hardheader.offset2;
755 arcsoft=&arcpacket->raw[offset];
756 length=512-offset;
759 get_whole_buffer(dev,recbuf*512+offset,length,(char *)arcpacket+offset);
761 arcnet_rx(lp, arcsoft, length, saddr, daddr);
763 BUGLVL(D_RX) arcnet_dump_packet(lp->adev,arcpacket->raw,length>240,"rx");
767 /* Given an skb, copy a packet into the ARCnet buffers for later transmission
768 * by arcnet_go_tx.
770 static void
771 arc90io_prepare_tx(struct net_device *dev,u_char *hdr,int hdrlen,
772 char *data,int length,int daddr,int exceptA, int offset)
774 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
776 lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate between 2 and 3 */
778 length+=hdrlen;
780 BUGMSG(D_TX,"arcnetAS_prep_tx: hdr:%ph, length:%d, data:%ph\n",
781 hdr,length,data);
783 put_buffer_byte(dev, lp->txbuf*512+1, daddr);
785 /* load packet into shared memory */
786 if (length<=MTU) /* Normal (256-byte) Packet */
787 put_buffer_byte(dev, lp->txbuf*512+2, offset=offset?offset:256-length);
789 else if (length>=MinTU || offset) /* Extended (512-byte) Packet */
791 put_buffer_byte(dev, lp->txbuf*512+2, 0);
792 put_buffer_byte(dev, lp->txbuf*512+3, offset=offset?offset:512-length);
794 else if (exceptA) /* RFC1201 Exception Packet */
796 put_buffer_byte(dev, lp->txbuf*512+2, 0);
797 put_buffer_byte(dev, lp->txbuf*512+3, offset=512-length-4);
799 /* exception-specific stuff - these four bytes
800 * make the packet long enough to fit in a 512-byte
801 * frame.
804 put_buffer_byte(dev, lp->txbuf*512+offset,hdr[0]);
805 put_whole_buffer(dev, lp->txbuf*512+offset+1,3,"\377\377\377");
806 offset+=4;
808 else /* "other" Exception packet */
810 /* RFC1051 - set 4 trailing bytes to 0 */
812 put_whole_buffer(dev,lp->txbuf*512+508,4,"\0\0\0\0");
814 /* now round up to MinTU */
815 put_buffer_byte(dev, lp->txbuf*512+2, 0);
816 put_buffer_byte(dev, lp->txbuf*512+3, offset=512-MinTU);
819 /* copy the packet into ARCnet shmem
820 * - the first bytes of ClientData header are skipped
823 put_whole_buffer(dev, 512*lp->txbuf+offset, hdrlen,(u_char *)hdr);
824 put_whole_buffer(dev, 512*lp->txbuf+offset+hdrlen,length-hdrlen,data);
826 BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
827 daddr,length);
829 lp->lastload_dest=daddr;
830 lp->txready=lp->txbuf; /* packet is ready for sending */
834 /****************************************************************************
836 * Kernel Loadable Module Support *
838 ****************************************************************************/
841 #ifdef MODULE
843 static struct net_device *cards[16]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
844 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
847 int init_module(void)
849 struct net_device *dev=cards[0];
851 cards[0]=dev=(struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL);
852 if (!dev)
853 return -ENOMEM;
855 memset(dev, 0, sizeof(struct net_device));
857 dev->name=(char *)kmalloc(9, GFP_KERNEL);
858 if (!dev->name)
860 kfree(dev);
861 return -ENOMEM;
863 dev->init=arc90io_probe;
865 if (device)
866 strcpy(dev->name,device);
867 else arcnet_makename(dev->name);
869 dev->base_addr=io;
870 dev->irq=irq;
872 if (dev->irq==2) dev->irq=9;
874 if (register_netdev(dev) != 0)
875 return -EIO;
877 /* Increase use count of arcnet.o */
878 arcnet_use_count(1);
879 return 0;
882 void cleanup_module(void)
884 struct net_device *dev=cards[0];
885 int ioaddr=dev->base_addr;
887 if (dev->start) (*dev->stop)(dev);
889 /* Flush TX and disable RX */
890 if (ioaddr)
892 AINTMASK(0); /* disable IRQ's */
893 ACOMMAND(NOTXcmd); /* stop transmit */
894 ACOMMAND(NORXcmd); /* disable receive */
896 /* Set the thing back to MMAP mode, in case the old
897 driver is loaded later */
898 outb( (inb(_CONFIG)&~IOMAPflag),_CONFIG);
901 if (dev->irq)
903 free_irq(dev->irq,dev);
906 if (dev->base_addr) release_region(dev->base_addr,ARCNET_TOTAL_SIZE);
907 unregister_netdev(dev);
908 kfree(dev->priv);
909 dev->priv = NULL;
911 /* Decrease use count of arcnet.o */
912 arcnet_use_count(0);
915 #else
917 void __init com90io_setup (char *str, int *ints)
919 struct net_device *dev;
921 if (arcnet_num_devs == MAX_ARCNET_DEVS)
923 printk("com90xx IO-MAP: Too many ARCnet devices registered (max %d).\n",
924 MAX_ARCNET_DEVS);
925 return;
928 dev=&arcnet_devs[arcnet_num_devs];
930 if (ints[0] < 1)
932 printk("com90xx IO-MAP: You must give an IO address.\n");
933 return;
936 dev->init=arc90io_probe;
938 switch(ints[0])
940 case 3: /* ERROR */
941 printk("com90xx IO-MAP: Too many arguments.\n");
943 case 2: /* IRQ */
944 dev->irq=ints[2];
946 case 1: /* IO address */
947 dev->base_addr=ints[1];
950 dev->name = (char *)&arcnet_dev_names[arcnet_num_devs];
952 if (str)
953 strncpy(dev->name, str, 9);
955 arcnet_num_devs++;
958 #endif /* MODULE */