* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / net / com20020.c
blob0f3bd021030326a3bb3c9e3e70b9984812eb39ba
1 /* $Id: com20020.c,v 1.6 1997/11/09 11:04:58 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 arc20020_probe(struct net_device *dev);
62 static void arc20020_rx(struct net_device *dev,int recbuf);
63 static int arc20020_found(struct net_device *dev,int ioaddr,int airq);
64 static void arc20020_inthandler (struct net_device *dev);
65 static int arc20020_reset (struct net_device *dev, int reset_delay);
66 static void arc20020_setmask (struct net_device *dev, u_char mask);
67 static void arc20020_command (struct net_device *dev, u_char command);
68 static u_char arc20020_status (struct net_device *dev);
69 static void arc20020_en_dis_able_TX (struct net_device *dev, int enable);
70 static void arc20020_prepare_tx(struct net_device *dev,u_char *hdr,int hdrlen,
71 char *data,int length,int daddr,int exceptA, int offset);
72 static void arc20020_openclose(int open);
73 static void arc20020_set_mc_list(struct net_device *dev);
74 static u_char get_buffer_byte (struct net_device *dev, unsigned offset);
75 static void put_buffer_byte (struct net_device *dev, unsigned offset, u_char datum);
76 static void get_whole_buffer (struct net_device *dev, unsigned offset, unsigned length, char *dest);
77 static void put_whole_buffer (struct net_device *dev, unsigned offset, unsigned length, char *dest);
80 /* Module parameters */
82 #ifdef MODULE
83 static int node=0;
84 static int io=0x0; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
85 static int irq=0; /* or use the insmod io= irq= shmem= options */
86 static char *device; /* use eg. device="arc1" to change name */
87 static int timeout=3;
88 static int backplane=0;
89 static int clock=0;
91 MODULE_PARM(node,"i");
92 MODULE_PARM(io, "i");
93 MODULE_PARM(irq, "i");
94 MODULE_PARM(device, "s");
95 MODULE_PARM(timeout,"i");
96 MODULE_PARM(backplane,"i");
97 MODULE_PARM(clock,"i");
98 #else
99 void __init com20020_setup (char *str, int *ints);
100 extern struct net_device arcnet_devs[];
101 extern char arcnet_dev_names[][10];
102 extern int arcnet_num_devs;
103 #endif
106 /* Handy defines for ARCnet specific stuff */
108 static char *clockrates[]={"2.5 Mb/s","1.25Mb/s","625 Kb/s","312.5 Kb/s",
109 "156.25 Kb/s", "Reserved", "Reserved",
110 "Reserved"};
113 /* The number of low I/O ports used by the card. */
114 #define ARCNET_TOTAL_SIZE 9
116 #define _INTMASK (ioaddr+0) /* writable */
117 #define _STATUS (ioaddr+0) /* readable */
118 #define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
119 #define _CONFIG (ioaddr+6) /* Configuration register */
120 #define _DIAGSTAT (ioaddr+1) /* Diagnostic status register */
121 #define _MEMDATA (ioaddr+4) /* Data port for IO-mapped memory */
122 #define _ADDR_HI (ioaddr+2) /* Control registers for said */
123 #define _ADDR_LO (ioaddr+3)
125 #define RDDATAflag 0x80 /* Next access is a read/~write */
126 #define NEWNXTIDflag 0x02 /* ID to which token is passed has changed */
128 #define TXENflag 0x20 /* Enable TX (in CONFIG register) */
130 #define PROMISCflag 0x10 /* Enable RCV_ALL (in SETUP register) */
132 #define REGTENTID (lp->config &= ~3);
133 #define REGNID (lp->config = (lp->config&~2)|1);
134 #define REGSETUP (lp->config = (lp->config&~1)|2);
135 #define REGNXTID (lp->config |= 3);
137 #define ARCRESET { outb(lp->config | 0x80, _CONFIG); \
138 udelay(5); \
139 outb(lp->config , _CONFIG); \
141 #define ARCRESET0 { outb(0x18 | 0x80, _CONFIG); \
142 udelay(5); \
143 outb(0x18 , _CONFIG); \
146 #define ARCSTATUS inb(_STATUS)
147 #define ACOMMAND(cmd) outb((cmd),_COMMAND)
148 #define AINTMASK(msk) outb((msk),_INTMASK)
149 #define SETCONF outb((lp->config),_CONFIG)
152 /****************************************************************************
154 * IO-mapped operation routines *
156 ****************************************************************************/
158 u_char get_buffer_byte (struct net_device *dev, unsigned offset)
160 int ioaddr=dev->base_addr;
162 outb(offset >> 8 | RDDATAflag, _ADDR_HI);
163 outb(offset & 0xff, _ADDR_LO);
165 return inb(_MEMDATA);
168 void put_buffer_byte (struct net_device *dev, unsigned offset, u_char datum)
170 int ioaddr=dev->base_addr;
172 outb(offset >> 8, _ADDR_HI);
173 outb(offset & 0xff, _ADDR_LO);
175 outb(datum, _MEMDATA);
179 #undef ONE_AT_A_TIME_TX
180 #undef ONE_AT_A_TIME_RX
182 void get_whole_buffer (struct net_device *dev, unsigned offset, unsigned length, char *dest)
184 int ioaddr=dev->base_addr;
186 outb( (offset >> 8) | AUTOINCflag | RDDATAflag, _ADDR_HI);
187 outb( offset & 0xff, _ADDR_LO);
189 while (length--)
190 #ifdef ONE_AT_A_TIME_RX
191 *(dest++) = get_buffer_byte(dev,offset++);
192 #else
193 *(dest++) = inb (_MEMDATA);
194 #endif
197 void put_whole_buffer (struct net_device *dev, unsigned offset, unsigned length, char *dest)
199 int ioaddr=dev->base_addr;
201 outb( (offset >> 8) | AUTOINCflag, _ADDR_HI);
202 outb( offset & 0xff, _ADDR_LO);
204 while (length--)
205 #ifdef ONE_AT_A_TIME_TX
206 put_buffer_byte(dev,offset++,*(dest++));
207 #else
208 outb (*(dest++), _MEMDATA);
209 #endif
213 static const char *version =
214 "com20020.c: v3.00 97/11/09 Avery Pennarun <apenwarr@worldvisions.ca> et al.\n";
216 /****************************************************************************
218 * Probe and initialization *
220 ****************************************************************************/
223 /* We cannot probe for an IO mapped card either, although we can check that
224 * it's where we were told it was, and even autoirq
227 int __init arc20020_probe(struct net_device *dev)
229 int ioaddr=dev->base_addr,status,delayval;
230 unsigned long airqmask;
232 BUGLVL(D_NORMAL) printk(version);
234 if (ioaddr<0x200)
236 BUGMSG(D_NORMAL,"No autoprobe for IO mapped cards; you "
237 "must specify the base address!\n");
238 return -ENODEV;
241 if (check_region(ioaddr, ARCNET_TOTAL_SIZE))
243 BUGMSG(D_NORMAL,"IO region %xh-%xh already allocated.\n",
244 ioaddr,ioaddr+ARCNET_TOTAL_SIZE-1);
245 return -ENXIO;
248 if (ARCSTATUS == 0xFF)
250 BUGMSG(D_NORMAL,"IO address %x empty\n",ioaddr);
251 return -ENODEV;
254 ARCRESET0;
255 JIFFER(RESETtime);
257 status=ARCSTATUS;
259 if ((status & 0x99)
260 != (NORXflag|TXFREEflag|RESETflag))
262 BUGMSG(D_NORMAL,"Status invalid (%Xh).\n",status);
263 return -ENODEV;
266 BUGMSG(D_INIT_REASONS,"Status after reset: %X\n",status);
268 /* Enable TX */
269 outb(0x39,_CONFIG);
270 outb(inb(ioaddr+8),ioaddr+7);
272 ACOMMAND(CFLAGScmd|RESETclear|CONFIGclear);
274 BUGMSG(D_INIT_REASONS,"Status after reset acknowledged: %X\n",status);
276 /* Reset card. */
278 outb(0x98,_CONFIG);
279 udelay(5);
280 outb(0x18,_CONFIG);
282 /* Read first loc'n of memory */
284 outb(0 | RDDATAflag | AUTOINCflag ,_ADDR_HI);
285 outb(0,_ADDR_LO);
287 if ((status=inb(_MEMDATA)) != 0xd1)
289 BUGMSG(D_NORMAL,"Signature byte not found.\n");
290 return -ENODEV;
293 if (!dev->irq)
295 /* if we do this, we're sure to get an IRQ since the
296 * card has just reset and the NORXflag is on until
297 * we tell it to start receiving.
299 BUGMSG(D_INIT_REASONS, "intmask was %d:\n",inb(_INTMASK));
300 outb(0, _INTMASK);
301 airqmask = probe_irq_on();
302 outb(NORXflag,_INTMASK);
303 udelay(1);
304 outb(0,_INTMASK);
305 dev->irq = probe_irq_off(airqmask);
307 if (dev->irq<=0)
309 BUGMSG(D_INIT_REASONS,"Autoprobe IRQ failed first time\n");
310 airqmask = probe_irq_on();
311 outb(NORXflag,_INTMASK);
312 udelay(5);
313 outb(0,_INTMASK);
314 dev->irq = probe_irq_off(airqmask);
315 if (dev->irq<=0)
317 BUGMSG(D_NORMAL,"Autoprobe IRQ failed.\n");
318 return -ENODEV;
323 return arc20020_found(dev,dev->base_addr,dev->irq);
327 /* Set up the struct net_device associated with this card. Called after
328 * probing succeeds.
330 int __init arc20020_found(struct net_device *dev,int ioaddr,int airq)
332 struct arcnet_local *lp;
334 /* reserve the irq */
335 if (request_irq(airq,&arcnet_interrupt,0,"arcnet (COM20020)",dev))
337 BUGMSG(D_NORMAL,"Can't get IRQ %d!\n",airq);
338 return -ENODEV;
340 dev->irq=airq;
342 /* reserve the I/O region - guaranteed to work by check_region */
343 request_region(ioaddr,ARCNET_TOTAL_SIZE,"arcnet (COM20020)");
344 dev->base_addr=ioaddr;
346 dev->mem_start=dev->mem_end=dev->rmem_start=dev->rmem_end=(long)NULL;
348 /* Initialize the rest of the device structure. */
350 dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
351 if (dev->priv == NULL)
353 free_irq(airq,dev);
354 release_region(ioaddr,ARCNET_TOTAL_SIZE);
355 return -ENOMEM;
358 memset(dev->priv,0,sizeof(struct arcnet_local));
359 lp=(struct arcnet_local *)(dev->priv);
360 lp->card_type = ARC_20020;
361 lp->card_type_str = "COM 20020";
363 lp->arcnet_reset=arc20020_reset;
364 lp->asetmask=arc20020_setmask;
365 lp->astatus=arc20020_status;
366 lp->acommand=arc20020_command;
367 lp->en_dis_able_TX=arc20020_en_dis_able_TX;
368 lp->openclose_device=arc20020_openclose;
369 lp->prepare_tx=arc20020_prepare_tx;
370 lp->inthandler=arc20020_inthandler;
372 dev->set_multicast_list = arc20020_set_mc_list;
374 /* Fill in the fields of the device structure with generic
375 * values.
377 arcnet_setup(dev);
379 /* And now fill particular fields with arcnet values */
380 dev->mtu=1500; /* completely arbitrary - agrees with ether, though */
381 dev->hard_header_len=sizeof(struct ClientData);
382 lp->sequence=1;
383 lp->recbuf=0;
385 BUGMSG(D_DURING,"ClientData header size is %d.\n",
386 sizeof(struct ClientData));
387 BUGMSG(D_DURING,"HardHeader size is %d.\n",
388 sizeof(struct archdr));
390 /* get and check the station ID from offset 1 in shmem */
391 lp->timeout = dev->dev_addr[3] & 3; dev->dev_addr[3]=0;
392 lp->backplane =dev->dev_addr[1] & 1; dev->dev_addr[1]=0;
393 lp->setup = (dev->dev_addr[2] & 7) << 1; dev->dev_addr[2]=0;
395 if (dev->dev_addr[0])
396 lp->stationid=dev->dev_addr[0];
397 else
398 lp->stationid=inb(ioaddr+8); /* FIX ME - We should check that
399 this is valid before using it */
400 lp->config = 0x21 | (lp->timeout << 3) | (lp->backplane << 2);
401 /* Default 0x38 + register: Node ID */
402 SETCONF;
403 outb(lp->stationid, ioaddr+7);
405 REGSETUP;
406 SETCONF;
407 outb(lp->setup, ioaddr+7);
409 if (!lp->stationid)
410 BUGMSG(D_NORMAL,"WARNING! Station address 00 is reserved "
411 "for broadcasts!\n");
412 else if (lp->stationid==255)
413 BUGMSG(D_NORMAL,"WARNING! Station address FF may confuse "
414 "DOS networking programs!\n");
415 dev->dev_addr[0]=lp->stationid;
417 BUGMSG(D_NORMAL,"ARCnet COM20020: station %02Xh found at %03lXh, IRQ %d.\n",
418 lp->stationid, dev->base_addr,dev->irq);
420 if (lp->backplane)
421 BUGMSG (D_NORMAL, "Using backplane mode.\n");
423 if (lp->timeout != 3)
424 BUGMSG (D_NORMAL, "Using Extended Timeout value of %d.\n",lp->timeout);
425 if (lp->setup)
427 BUGMSG (D_NORMAL, "Using CKP %d - Data rate %s.\n",
428 lp->setup >>1,clockrates[lp->setup >> 1] );
430 return 0;
434 /****************************************************************************
436 * Utility routines *
438 ****************************************************************************/
440 /* Do a hardware reset on the card, and set up necessary registers.
442 * This should be called as little as possible, because it disrupts the
443 * token on the network (causes a RECON) and requires a significant delay.
445 * However, it does make sure the card is in a defined state.
447 int arc20020_reset(struct net_device *dev,int reset_delay)
449 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
450 short ioaddr=dev->base_addr;
451 int delayval,recbuf=lp->recbuf;
453 if (reset_delay==3)
455 ARCRESET;
456 return 0;
459 /* no IRQ's, please! */
460 lp->intmask=0;
461 SETMASK;
463 BUGMSG(D_INIT,"Resetting %s (status=%Xh)\n",
464 dev->name,ARCSTATUS);
466 lp->config = 0x20 | (lp->timeout<<3) | (lp->backplane<<2);
467 /* power-up defaults */
468 SETCONF;
470 if (reset_delay)
472 /* reset the card */
473 ARCRESET;
474 JIFFER(RESETtime);
477 ACOMMAND(CFLAGScmd|RESETclear); /* clear flags & end reset */
478 ACOMMAND(CFLAGScmd|CONFIGclear);
480 /* verify that the ARCnet signature byte is present */
482 if (get_buffer_byte(dev,0) != TESTvalue)
484 BUGMSG(D_NORMAL,"reset failed: TESTvalue not present.\n");
485 return 1;
488 /* clear out status variables */
489 recbuf=lp->recbuf=0;
490 lp->txbuf=2;
492 /* enable extended (512-byte) packets */
493 ACOMMAND(CONFIGcmd|EXTconf);
495 /* and enable receive of our first packet to the first buffer */
496 EnableReceiver();
498 /* re-enable interrupts */
499 lp->intmask|=NORXflag;
500 #ifdef DETECT_RECONFIGS
501 lp->intmask|=RECONflag;
502 #endif
503 SETMASK;
505 /* done! return success. */
506 return 0;
510 /* Set or clear the multicast filter for this adaptor.
511 * num_addrs == -1 Promiscuous mode, receive all packets
512 * num_addrs == 0 Normal mode, clear multicast list
513 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
514 * best-effort filtering.
515 * FIX ME - do multicast stuff, not just promiscuous.
517 static void
518 arc20020_set_mc_list(struct net_device *dev)
520 struct arcnet_local *lp=dev->priv;
521 int ioaddr=dev->base_addr;
523 if ((dev->flags & IFF_PROMISC) && (dev->flags & IFF_UP))
524 { /* Enable promiscuous mode */
525 if (!(lp->setup & PROMISCflag))
526 BUGMSG(D_NORMAL, "Setting promiscuous flag...\n");
527 REGSETUP;
528 SETCONF;
529 lp->setup|=PROMISCflag;
530 outb(lp->setup,ioaddr+7);
531 } else
532 /* Disable promiscuous mode, use normal mode */
534 if ((lp->setup & PROMISCflag))
535 BUGMSG(D_NORMAL, "Resetting promiscuous flag...\n");
536 REGSETUP;
537 SETCONF;
538 lp->setup &= ~PROMISCflag;
539 outb(lp->setup,ioaddr+7);
544 static void arc20020_openclose(int open)
546 if (open)
547 MOD_INC_USE_COUNT;
548 else
549 MOD_DEC_USE_COUNT;
553 static void arc20020_en_dis_able_TX(struct net_device *dev, int enable)
555 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
556 int ioaddr=dev->base_addr;
558 lp->config=enable?(lp->config | TXENflag):(lp->config & ~TXENflag);
559 SETCONF;
563 static void arc20020_setmask(struct net_device *dev, u_char mask)
565 short ioaddr=dev->base_addr;
567 AINTMASK(mask);
571 static u_char arc20020_status(struct net_device *dev)
573 short ioaddr=dev->base_addr;
575 return ARCSTATUS;
579 static void arc20020_command(struct net_device *dev, u_char cmd)
581 short ioaddr=dev->base_addr;
583 ACOMMAND(cmd);
587 /* The actual interrupt handler routine - handle various IRQ's generated
588 * by the card.
590 static void
591 arc20020_inthandler(struct net_device *dev)
593 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
594 int ioaddr=dev->base_addr, status, boguscount = 3, didsomething,
595 dstatus;
597 AINTMASK(0);
599 BUGMSG(D_DURING,"in arc20020_inthandler (status=%Xh, intmask=%Xh)\n",
600 ARCSTATUS,lp->intmask);
604 status = ARCSTATUS;
605 didsomething=0;
608 /* RESET flag was enabled - card is resetting and if RX
609 * is disabled, it's NOT because we just got a packet.
611 if (status & RESETflag)
613 BUGMSG(D_NORMAL,"spurious reset (status=%Xh)\n",
614 status);
615 arc20020_reset(dev,0);
617 /* all other flag values are just garbage */
618 break;
621 /* RX is inhibited - we must have received something. */
622 if (status & lp->intmask & NORXflag)
624 int recbuf=lp->recbuf=!lp->recbuf;
625 int oldaddr=0;
627 BUGMSG(D_DURING,"receive irq (status=%Xh)\n",
628 status);
630 /* enable receive of our next packet */
631 EnableReceiver();
633 if (lp->intx)
634 oldaddr=(inb(_ADDR_HI)<<8) | inb(_ADDR_LO);
636 /* Got a packet. */
637 arc20020_rx(dev,!recbuf);
639 if (lp->intx)
641 outb( (oldaddr >> 8), _ADDR_HI);
642 outb( oldaddr & 0xff, _ADDR_LO);
645 didsomething++;
648 /* it can only be an xmit-done irq if we're xmitting :) */
649 /*if (status&TXFREEflag && !lp->in_txhandler && lp->sending)*/
650 if (status & lp->intmask & TXFREEflag)
652 struct Outgoing *out=&(lp->outgoing);
653 int was_sending=lp->sending;
655 lp->intmask &= ~TXFREEflag;
657 lp->in_txhandler++;
658 if (was_sending) lp->sending--;
660 BUGMSG(D_DURING,"TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
661 status,out->numsegs,out->segnum,out->skb);
663 if (was_sending && !(status&TXACKflag))
665 if (lp->lasttrans_dest != 0)
667 BUGMSG(D_EXTRA,"transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
668 status,lp->lasttrans_dest);
669 lp->stats.tx_errors++;
670 lp->stats.tx_carrier_errors++;
672 else
674 BUGMSG(D_DURING,"broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
675 status,
676 lp->lasttrans_dest);
680 /* send packet if there is one */
681 arcnet_go_tx(dev,0);
682 didsomething++;
684 if (lp->intx)
686 BUGMSG(D_DURING,"TXDONE while intx! (status=%Xh, intx=%d)\n",
687 ARCSTATUS,lp->intx);
688 lp->in_txhandler--;
689 continue;
692 if (!lp->outgoing.skb)
694 BUGMSG(D_DURING,"TX IRQ done: no split to continue.\n");
696 /* inform upper layers */
697 if (!lp->txready) arcnet_tx_done(dev, lp);
698 lp->in_txhandler--;
699 continue;
702 /* if more than one segment, and not all segments
703 * are done, then continue xmit.
705 if (out->segnum<out->numsegs)
706 arcnetA_continue_tx(dev);
707 arcnet_go_tx(dev,0);
709 /* if segnum==numsegs, the transmission is finished;
710 * free the skb.
712 if (out->segnum>=out->numsegs)
714 /* transmit completed */
715 out->segnum++;
716 if (out->skb)
718 lp->stats.tx_bytes += out->skb->len;
719 dev_kfree_skb(out->skb);
721 out->skb=NULL;
723 /* inform upper layers */
724 if (!lp->txready) arcnet_tx_done(dev, lp);
726 didsomething++;
728 lp->in_txhandler--;
730 else if (lp->txready && !lp->sending && !lp->intx)
732 BUGMSG(D_NORMAL,"recovery from silent TX (status=%Xh)\n",
733 status);
734 arcnet_go_tx(dev,0);
735 didsomething++;
738 if ((dstatus=inb(_DIAGSTAT)) & NEWNXTIDflag)
740 REGNXTID;
741 SETCONF;
742 BUGMSG(D_EXTRA,"New NextID detected: %X\n",inb(ioaddr+7));
746 #ifdef DETECT_RECONFIGS
747 if (status & (lp->intmask) & RECONflag)
749 ACOMMAND(CFLAGScmd|CONFIGclear);
750 lp->stats.tx_carrier_errors++;
752 #ifdef SHOW_RECONFIGS
753 BUGMSG(D_NORMAL,"Network reconfiguration detected (status=%Xh, diag status=%Xh, config=%X)\n",
754 status,dstatus,lp->config);
755 #endif /* SHOW_RECONFIGS */
757 #ifdef RECON_THRESHOLD
758 /* is the RECON info empty or old? */
759 if (!lp->first_recon || !lp->last_recon ||
760 jiffies-lp->last_recon > HZ*10)
762 if (lp->network_down)
763 BUGMSG(D_NORMAL,"reconfiguration detected: cabling restored?\n");
764 lp->first_recon=lp->last_recon=jiffies;
765 lp->num_recons=lp->network_down=0;
767 BUGMSG(D_DURING,"recon: clearing counters.\n");
769 else /* add to current RECON counter */
771 lp->last_recon=jiffies;
772 lp->num_recons++;
774 BUGMSG(D_DURING,"recon: counter=%d, time=%lds, net=%d\n",
775 lp->num_recons,
776 (lp->last_recon-lp->first_recon)/HZ,
777 lp->network_down);
779 /* if network is marked up;
780 * and first_recon and last_recon are 60+ sec
781 * apart;
782 * and the average no. of recons counted is
783 * > RECON_THRESHOLD/min;
784 * then print a warning message.
786 if (!lp->network_down
787 && (lp->last_recon-lp->first_recon)<=HZ*60
788 && lp->num_recons >= RECON_THRESHOLD)
790 lp->network_down=1;
791 BUGMSG(D_NORMAL,"many reconfigurations detected: cabling problem?\n");
793 else if (!lp->network_down
794 && lp->last_recon-lp->first_recon > HZ*60)
796 /* reset counters if we've gone for
797 * over a minute.
799 lp->first_recon=lp->last_recon;
800 lp->num_recons=1;
804 else if (lp->network_down && jiffies-lp->last_recon > HZ*10)
806 if (lp->network_down)
807 BUGMSG(D_NORMAL,"cabling restored?\n");
808 lp->first_recon=lp->last_recon=0;
809 lp->num_recons=lp->network_down=0;
811 BUGMSG(D_DURING,"not recon: clearing counters anyway.\n");
812 #endif
814 #endif /* DETECT_RECONFIGS */
815 } while (--boguscount && didsomething);
817 BUGMSG(D_DURING,"net_interrupt complete (status=%Xh, count=%d)\n",
818 ARCSTATUS,boguscount);
819 BUGMSG(D_DURING,"\n");
821 SETMASK; /* put back interrupt mask */
826 /* A packet has arrived; grab it from the buffers and pass it to the generic
827 * arcnet_rx routing to deal with it.
830 static void
831 arc20020_rx(struct net_device *dev,int recbuf)
833 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
834 int ioaddr=dev->base_addr;
835 union ArcPacket packetbuf;
836 union ArcPacket *arcpacket=&packetbuf;
837 u_char *arcsoft;
838 short length,offset;
839 u_char daddr,saddr;
841 lp->stats.rx_packets++;
843 get_whole_buffer(dev,recbuf*512,4,(char *)arcpacket);
845 saddr=arcpacket->hardheader.source;
847 /* if source is 0, it's a "used" packet! */
848 if (saddr==0)
850 BUGMSG(D_NORMAL,"discarding old packet. (status=%Xh)\n",
851 ARCSTATUS);
852 lp->stats.rx_errors++;
853 return;
855 /* Set source address to zero to mark it as old */
857 put_buffer_byte(dev,recbuf*512,0);
859 arcpacket->hardheader.source=0;
861 daddr=arcpacket->hardheader.destination;
863 if (arcpacket->hardheader.offset1) /* Normal Packet */
865 offset=arcpacket->hardheader.offset1;
866 arcsoft=&arcpacket->raw[offset];
867 length=256-offset;
869 else /* ExtendedPacket or ExceptionPacket */
871 offset=arcpacket->hardheader.offset2;
872 arcsoft=&arcpacket->raw[offset];
873 length=512-offset;
876 get_whole_buffer(dev,recbuf*512+offset,length,(char *)arcpacket+offset);
878 arcnet_rx(lp, arcsoft, length, saddr, daddr);
880 BUGLVL(D_RX) arcnet_dump_packet(lp->adev,arcpacket->raw,length>240,"rx");
884 /* Given an skb, copy a packet into the ARCnet buffers for later transmission
885 * by arcnet_go_tx.
887 static void
888 arc20020_prepare_tx(struct net_device *dev,u_char *hdr,int hdrlen,
889 char *data,int length,int daddr,int exceptA, int offset)
891 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
893 lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate between 2 and 3 */
895 length+=hdrlen;
897 BUGMSG(D_TX,"arcnetAS_prep_tx: hdr:%ph, length:%d, data:%ph\n",
898 hdr,length,data);
900 put_buffer_byte(dev, lp->txbuf*512+1, daddr);
902 /* load packet into shared memory */
903 if (length<=MTU) /* Normal (256-byte) Packet */
904 put_buffer_byte(dev, lp->txbuf*512+2, offset=offset?offset:256-length);
906 else if (length>=MinTU || offset) /* Extended (512-byte) Packet */
908 put_buffer_byte(dev, lp->txbuf*512+2, 0);
909 put_buffer_byte(dev, lp->txbuf*512+3, offset=offset?offset:512-length);
911 else if (exceptA) /* RFC1201 Exception Packet */
913 put_buffer_byte(dev, lp->txbuf*512+2, 0);
914 put_buffer_byte(dev, lp->txbuf*512+3, offset=512-length-4);
916 /* exception-specific stuff - these four bytes
917 * make the packet long enough to fit in a 512-byte
918 * frame.
921 put_buffer_byte(dev, lp->txbuf*512+offset,hdr[0]);
922 put_whole_buffer(dev, lp->txbuf*512+offset+1,3,"\377\377\377");
923 offset+=4;
925 else /* "other" Exception packet */
927 /* RFC1051 - set 4 trailing bytes to 0 */
929 put_whole_buffer(dev,lp->txbuf*512+508,4,"\0\0\0\0");
931 /* now round up to MinTU */
932 put_buffer_byte(dev, lp->txbuf*512+2, 0);
933 put_buffer_byte(dev, lp->txbuf*512+3, offset=512-MinTU);
936 /* copy the packet into ARCnet shmem
937 * - the first bytes of ClientData header are skipped
940 put_whole_buffer(dev, 512*lp->txbuf+offset, hdrlen,(u_char *)hdr);
941 put_whole_buffer(dev, 512*lp->txbuf+offset+hdrlen,length-hdrlen,data);
943 BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
944 daddr,length);
946 lp->lastload_dest=daddr;
947 lp->txready=lp->txbuf; /* packet is ready for sending */
951 /****************************************************************************
953 * Kernel Loadable Module Support *
955 ****************************************************************************/
958 #ifdef MODULE
960 static struct net_device *cards[16]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
961 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
964 int init_module(void)
966 struct net_device *dev;
968 cards[0]=dev=(struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL);
969 if (!dev)
970 return -ENOMEM;
972 memset(dev, 0, sizeof(struct net_device));
974 dev->name=(char *)kmalloc(9, GFP_KERNEL);
975 if (!dev->name)
977 kfree(dev);
978 return -ENOMEM;
980 dev->init=arc20020_probe;
982 if (device)
983 strcpy(dev->name,device);
984 else arcnet_makename(dev->name);
986 if (node && node != 0xff)
987 dev->dev_addr[0]=node;
989 if (backplane) dev->dev_addr[1]=backplane?1:0;
990 if (clock) dev->dev_addr[2]=clock&7;
991 dev->dev_addr[3]=timeout&3;
993 dev->base_addr=io;
994 dev->irq=irq;
996 if (dev->irq==2) dev->irq=9;
998 if (register_netdev(dev) != 0)
999 return -EIO;
1001 /* Increase use count of arcnet.o */
1002 arcnet_use_count(1);
1004 return 0;
1007 void cleanup_module(void)
1009 struct net_device *dev=cards[0];
1010 int ioaddr=dev->base_addr;
1012 if (dev->start) (*dev->stop)(dev);
1014 /* Flush TX and disable RX */
1015 if (ioaddr)
1017 AINTMASK(0); /* disable IRQ's */
1018 ACOMMAND(NOTXcmd); /* stop transmit */
1019 ACOMMAND(NORXcmd); /* disable receive */
1022 if (dev->irq)
1024 free_irq(dev->irq,dev);
1027 if (dev->base_addr) release_region(dev->base_addr,ARCNET_TOTAL_SIZE);
1028 unregister_netdev(dev);
1029 kfree(dev->priv);
1030 dev->priv = NULL;
1032 /* Decrease use count of arcnet.o */
1033 arcnet_use_count(0);
1036 #else
1038 void __init com20020_setup (char *str, int *ints)
1040 struct net_device *dev;
1042 if (arcnet_num_devs == MAX_ARCNET_DEVS)
1044 printk("com20020: Too many ARCnet devices registered (max %d).\n",
1045 MAX_ARCNET_DEVS);
1046 return;
1049 dev=&arcnet_devs[arcnet_num_devs];
1051 if (ints[0] < 1)
1053 printk("com20020: You must give an IO address.\n");
1054 return;
1057 dev->dev_addr[3]=3;
1058 dev->init=arc20020_probe;
1060 switch(ints[0])
1062 case 7: /* ERROR */
1063 printk("com20020: Too many arguments.\n");
1065 case 6: /* Timeout */
1066 dev->dev_addr[3]=(u_char)ints[6];
1068 case 5: /* CKP value */
1069 dev->dev_addr[2]=(u_char)ints[5];
1071 case 4: /* Backplane flag */
1072 dev->dev_addr[1]=(u_char)ints[4];
1074 case 3: /* Node ID */
1075 dev->dev_addr[0]=(u_char)ints[3];
1077 case 2: /* IRQ */
1078 dev->irq=ints[2];
1080 case 1: /* IO address */
1081 dev->base_addr=ints[1];
1084 dev->name = (char *)&arcnet_dev_names[arcnet_num_devs];
1086 if (str)
1087 strncpy(dev->name, str, 9);
1089 arcnet_num_devs++;
1091 #endif /* MODULE */