2 * Linux ARCnet driver - device-independent routines
4 * Written 1997 by David Woodhouse.
5 * Written 1994-1999 by Avery Pennarun.
6 * Written 1999-2000 by Martin Mares <mj@suse.cz>.
7 * Derived from skeleton.c by Donald Becker.
9 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
10 * for sponsoring the further development of this driver.
12 * **********************
14 * The original copyright was as follows:
16 * skeleton.c Written 1993 by Donald Becker.
17 * Copyright 1993 United States Government as represented by the
18 * Director, National Security Agency. This software may only be used
19 * and distributed according to the terms of the GNU Public License as
20 * modified by SRC, incorporated herein by reference.
22 * **********************
24 * The change log is now in a file called ChangeLog in this directory.
27 * - Crynwr arcnet.com/arcether.com packet drivers.
28 * - arcnet.c v0.00 dated 1/1/94 and apparently by
29 * Donald Becker - it didn't work :)
30 * - skeleton.c v0.05 dated 11/16/93 by Donald Becker
31 * (from Linux Kernel 1.1.45)
32 * - RFC's 1201 and 1051 - re: TCP/IP over ARCnet
33 * - The official ARCnet COM9026 data sheets (!) thanks to
34 * Ken Cornetet <kcornete@nyx10.cs.du.edu>
35 * - The official ARCnet COM20020 data sheets.
36 * - Information on some more obscure ARCnet controller chips, thanks
37 * to the nice people at SMSC.
38 * - net/inet/eth.c (from kernel 1.1.50) for header-building info.
39 * - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
40 * - Textual information and more alternate source from Joachim Koenig
44 #define VERSION "arcnet: v3.93 BETA 2000/04/29 - by Avery Pennarun et al.\n"
46 #include <linux/module.h>
47 #include <linux/config.h>
48 #include <linux/types.h>
49 #include <linux/delay.h>
50 #include <linux/netdevice.h>
51 #include <linux/if_arp.h>
53 #include <linux/init.h>
54 #include <linux/arcdevice.h>
57 /* "do nothing" functions for protocol drivers */
58 static void null_rx(struct net_device *dev, int bufnum,
59 struct archdr *pkthdr, int length);
60 static int null_build_header(struct sk_buff *skb, unsigned short type,
62 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
63 int length, int bufnum);
67 * one ArcProto per possible proto ID. None of the elements of
68 * arc_proto_map are allowed to be NULL; they will get set to
69 * arc_proto_default instead. It also must not be NULL; if you would like
70 * to set it to NULL, set it to &arc_proto_null instead.
72 struct ArcProto *arc_proto_map[256], *arc_proto_default, *arc_bcast_proto;
74 struct ArcProto arc_proto_null =
84 /* Exported function prototypes */
85 int arcnet_debug = ARCNET_DEBUG;
87 EXPORT_SYMBOL(arc_proto_map);
88 EXPORT_SYMBOL(arc_proto_default);
89 EXPORT_SYMBOL(arc_bcast_proto);
90 EXPORT_SYMBOL(arc_proto_null);
91 EXPORT_SYMBOL(arcnet_unregister_proto);
92 EXPORT_SYMBOL(arcnet_debug);
93 EXPORT_SYMBOL(arcdev_setup);
94 EXPORT_SYMBOL(arcnet_interrupt);
96 /* Internal function prototypes */
97 static int arcnet_open(struct net_device *dev);
98 static int arcnet_close(struct net_device *dev);
99 static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev);
100 static void arcnet_timeout(struct net_device *dev);
101 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
102 unsigned short type, void *daddr, void *saddr,
104 static int arcnet_rebuild_header(struct sk_buff *skb);
105 static struct net_device_stats *arcnet_get_stats(struct net_device *dev);
106 static int go_tx(struct net_device *dev);
108 void __init arcnet_init(void)
110 static int arcnet_inited = 0;
120 printk("arcnet: ***\n"
121 "arcnet: * Read arcnet.txt for important release notes!\n"
123 "arcnet: * This is an ALPHA version! (Last stable release: v3.02) E-mail\n"
124 "arcnet: * me if you have any questions, comments, or bug reports.\n"
129 /* initialize the protocol map */
130 arc_proto_default = arc_bcast_proto = &arc_proto_null;
131 for (count = 0; count < 256; count++)
132 arc_proto_map[count] = arc_proto_default;
135 printk("arcnet: struct sizes: %d %d %d %d %d\n",
136 sizeof(struct arc_hardware), sizeof(struct arc_rfc1201),
137 sizeof(struct arc_rfc1051), sizeof(struct arc_eth_encap),
138 sizeof(struct archdr));
140 #ifdef CONFIG_ARCNET /* We're not built as a module */
141 printk("arcnet: Available protocols:");
142 #ifdef CONFIG_ARCNET_1201
144 arcnet_rfc1201_init();
146 #ifdef CONFIG_ARCNET_1051
148 arcnet_rfc1051_init();
150 #ifdef CONFIG_ARCNET_RAW
155 #ifdef CONFIG_ARCNET_COM90xx
164 static int debug = ARCNET_DEBUG;
165 MODULE_PARM(debug, "i");
167 int __init init_module(void)
169 arcnet_debug = debug;
174 void cleanup_module(void)
182 * Dump the contents of an sk_buff
184 #if ARCNET_DEBUG_MAX & D_SKB
185 void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc)
192 printk(KERN_DEBUG "%6s: skb dump (%s) follows:", dev->name, desc);
193 for (i = 0; i < skb->len; i++) {
195 printk("\n" KERN_DEBUG "[%04X] ", i);
196 printk("%02X ", ((u_char *) skb->data)[i]);
199 restore_flags(flags);
202 EXPORT_SYMBOL(arcnet_dump_skb);
207 * Dump the contents of an ARCnet buffer
209 #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
210 void arcnet_dump_packet(struct net_device *dev, int bufnum, char *desc)
212 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
215 static uint8_t buf[512];
220 lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
222 /* if the offset[0] byte is nonzero, this is a 256-byte packet */
223 length = (buf[2] ? 256 : 512);
225 printk(KERN_DEBUG "%6s: packet dump (%s) follows:", dev->name, desc);
226 for (i = 0; i < length; i++) {
228 printk("\n" KERN_DEBUG "[%04X] ", i);
229 printk("%02X ", buf[i]);
233 restore_flags(flags);
236 EXPORT_SYMBOL(arcnet_dump_packet);
241 * Unregister a protocol driver from the arc_proto_map. Protocol drivers
242 * are responsible for registering themselves, but the unregister routine
243 * is pretty generic so we'll do it here.
245 void arcnet_unregister_proto(struct ArcProto *proto)
249 if (arc_proto_default == proto)
250 arc_proto_default = &arc_proto_null;
251 if (arc_bcast_proto == proto)
252 arc_bcast_proto = arc_proto_default;
254 for (count = 0; count < 256; count++) {
255 if (arc_proto_map[count] == proto)
256 arc_proto_map[count] = arc_proto_default;
262 * Add a buffer to the queue. Only the interrupt handler is allowed to do
263 * this, unless interrupts are disabled.
265 * Note: we don't check for a full queue, since there aren't enough buffers
266 * to more than fill it.
268 static void release_arcbuf(struct net_device *dev, int bufnum)
270 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
273 lp->buf_queue[lp->first_free_buf++] = bufnum;
274 lp->first_free_buf %= 5;
277 BUGMSG(D_DURING, "release_arcbuf: freed #%d; buffer queue is now: ",
279 for (i = lp->next_buf; i != lp->first_free_buf; i = ++i % 5)
280 BUGMSG2(D_DURING, "#%d ", lp->buf_queue[i]);
281 BUGMSG2(D_DURING, "\n");
287 * Get a buffer from the queue. If this returns -1, there are no buffers
290 static int get_arcbuf(struct net_device *dev)
292 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
295 if (!atomic_dec_and_test(&lp->buf_lock)) /* already in this function */
296 BUGMSG(D_NORMAL, "get_arcbuf: overlap (%d)!\n", lp->buf_lock.counter);
297 else { /* we can continue */
298 if (lp->next_buf >= 5)
301 if (lp->next_buf == lp->first_free_buf)
302 BUGMSG(D_NORMAL, "get_arcbuf: BUG: no buffers are available??\n");
304 buf = lp->buf_queue[lp->next_buf++];
311 BUGMSG(D_DURING, "get_arcbuf: got #%d; buffer queue is now: ", buf);
312 for (i = lp->next_buf; i != lp->first_free_buf; i = ++i % 5)
313 BUGMSG2(D_DURING, "#%d ", lp->buf_queue[i]);
314 BUGMSG2(D_DURING, "\n");
317 atomic_inc(&lp->buf_lock);
322 static int choose_mtu(void)
324 int count, mtu = 65535;
326 /* choose the smallest MTU of all available encaps */
327 for (count = 0; count < 256; count++) {
328 if (arc_proto_map[count] != &arc_proto_null
329 && arc_proto_map[count]->mtu < mtu) {
330 mtu = arc_proto_map[count]->mtu;
334 return mtu == 65535 ? XMTU : mtu;
338 /* Setup a struct device for ARCnet. */
339 void arcdev_setup(struct net_device *dev)
341 dev->type = ARPHRD_ARCNET;
342 dev->hard_header_len = sizeof(struct archdr);
343 dev->mtu = choose_mtu();
346 dev->tx_queue_len = 30;
347 dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
348 dev->watchdog_timeo = TX_TIMEOUT;
350 /* New-style flags. */
351 dev->flags = IFF_BROADCAST;
354 * Put in this stuff here, so we don't have to export the symbols to
355 * the chipset drivers.
357 dev->open = arcnet_open;
358 dev->stop = arcnet_close;
359 dev->hard_start_xmit = arcnet_send_packet;
360 dev->tx_timeout = arcnet_timeout;
361 dev->get_stats = arcnet_get_stats;
362 dev->hard_header = arcnet_header;
363 dev->rebuild_header = arcnet_rebuild_header;
365 dev_init_buffers(dev);
370 * Open/initialize the board. This is called sometime after booting when
371 * the 'ifconfig' program is run.
373 * This routine should set everything up anew at each open, even registers
374 * that "should" only need to be set once at boot, so that there is
375 * non-reboot way to recover if something goes wrong.
377 static int arcnet_open(struct net_device *dev)
379 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
384 BUGMSG(D_PROTO, "protocol map (default is '%c'): ",
385 arc_proto_default->suffix);
386 for (count = 0; count < 256; count++)
387 BUGMSG2(D_PROTO, "%c", arc_proto_map[count]->suffix);
388 BUGMSG2(D_PROTO, "\n");
392 BUGMSG(D_INIT, "arcnet_open: resetting card.\n");
394 /* try to put the card in a defined state - if it fails the first
395 * time, actually reset it.
397 if (ARCRESET(0) && ARCRESET(1))
400 newmtu = choose_mtu();
401 if (newmtu < dev->mtu)
404 /* autodetect the encapsulation for each host. */
405 memset(lp->default_proto, 0, sizeof(lp->default_proto));
407 /* the broadcast address is special - use the 'bcast' protocol */
408 for (count = 0; count < 256; count++) {
409 if (arc_proto_map[count] == arc_bcast_proto) {
410 lp->default_proto[0] = count;
415 /* initialize buffers */
416 atomic_set(&lp->buf_lock, 1);
417 lp->next_buf = lp->first_free_buf = 0;
418 release_arcbuf(dev, 0);
419 release_arcbuf(dev, 1);
420 release_arcbuf(dev, 2);
421 release_arcbuf(dev, 3);
422 lp->cur_tx = lp->next_tx = -1;
425 lp->rfc1201.sequence = 1;
427 /* bring up the hardware driver */
430 if (dev->dev_addr[0] == 0)
431 BUGMSG(D_NORMAL, "WARNING! Station address 00 is reserved "
432 "for broadcasts!\n");
433 else if (dev->dev_addr[0] == 255)
434 BUGMSG(D_NORMAL, "WARNING! Station address FF may confuse "
435 "DOS networking programs!\n");
437 if (ASTATUS() & RESETflag)
438 ACOMMAND(CFLAGScmd | RESETclear);
440 /* make sure we're ready to receive IRQ's. */
442 udelay(1); /* give it time to set the mask before
443 * we reset it again. (may not even be
446 lp->intmask = NORXflag | RECONflag;
447 AINTMASK(lp->intmask);
449 netif_start_queue(dev);
455 /* The inverse routine to arcnet_open - shuts down the card. */
456 static int arcnet_close(struct net_device *dev)
458 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
460 netif_stop_queue(dev);
462 /* flush TX and disable RX */
464 ACOMMAND(NOTXcmd); /* stop transmit */
465 ACOMMAND(NORXcmd); /* disable receive */
468 /* shut down the card */
475 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
476 unsigned short type, void *daddr, void *saddr,
479 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
480 uint8_t _daddr, proto_num;
481 struct ArcProto *proto;
484 "create header from %d to %d; protocol %d (%Xh); size %u.\n",
485 saddr ? *(uint8_t *) saddr : -1,
486 daddr ? *(uint8_t *) daddr : -1,
490 BUGMSG(D_NORMAL, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
494 * if the dest addr isn't provided, we can't choose an encapsulation!
495 * Store the packet type (eg. ETH_P_IP) for now, and we'll push on a
496 * real header when we do rebuild_header.
499 *(uint16_t *) skb_push(skb, 2) = type;
500 if (skb->nh.raw - skb->mac.raw != 2)
501 BUGMSG(D_NORMAL, "arcnet_header: Yikes! diff (%d) is not 2!\n",
502 skb->nh.raw - skb->mac.raw);
503 return -2; /* return error -- can't transmit yet! */
505 /* otherwise, we can just add the header as usual. */
506 _daddr = *(uint8_t *) daddr;
507 proto_num = lp->default_proto[_daddr];
508 proto = arc_proto_map[proto_num];
509 BUGMSG(D_DURING, "building header for %02Xh using protocol '%c'\n",
510 proto_num, proto->suffix);
511 if (proto == &arc_proto_null && arc_bcast_proto != proto) {
512 BUGMSG(D_DURING, "actually, let's use '%c' instead.\n",
513 arc_bcast_proto->suffix);
514 proto = arc_bcast_proto;
516 return proto->build_header(skb, type, _daddr);
521 * Rebuild the ARCnet hard header. This is called after an ARP (or in the
522 * future other address resolution) has completed on this sk_buff. We now
523 * let ARP fill in the destination field.
525 static int arcnet_rebuild_header(struct sk_buff *skb)
527 struct net_device *dev = skb->dev;
528 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
529 int status = 0; /* default is failure */
533 if (skb->nh.raw - skb->mac.raw != 2) {
535 "rebuild_header: shouldn't be here! (hdrsize=%d)\n",
536 skb->nh.raw - skb->mac.raw);
539 type = *(uint16_t *) skb_pull(skb, 2);
541 if (type == ETH_P_IP) {
543 BUGMSG(D_DURING, "rebuild header for ethernet protocol %Xh\n", type);
544 status = arp_find(&daddr, skb) ? 1 : 0;
545 BUGMSG(D_DURING, " rebuilt: dest is %d; protocol %Xh\n",
550 "I don't understand ethernet protocol %Xh addresses!\n", type);
551 lp->stats.tx_errors++;
552 lp->stats.tx_aborted_errors++;
555 /* if we couldn't resolve the address... give up. */
559 /* add the _real_ header this time! */
560 arc_proto_map[lp->default_proto[daddr]]->build_header(skb, type, daddr);
562 return 1; /* success */
567 /* Called by the kernel in order to transmit a packet. */
568 static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev)
570 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
572 struct arc_rfc1201 *soft;
573 struct ArcProto *proto;
577 "transmit requested (status=%Xh, txbufs=%d/%d, len=%d)\n",
578 ASTATUS(), lp->cur_tx, lp->next_tx, skb->len);
580 pkt = (struct archdr *) skb->data;
581 soft = &pkt->soft.rfc1201;
582 proto = arc_proto_map[soft->proto];
584 BUGMSG(D_SKB_SIZE, "skb: transmitting %d bytes to %02X\n",
585 skb->len, pkt->hard.dest);
586 BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "tx");
588 /* fits in one packet? */
589 if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
590 BUGMSG(D_NORMAL, "fixme: packet too large: compensating badly!\n");
592 return 0; /* don't try again */
595 /* We're busy transmitting a packet... */
596 netif_stop_queue(dev);
600 txbuf = get_arcbuf(dev);
602 if (proto->prepare_tx(dev, pkt, skb->len, txbuf)) {
603 /* done right away */
604 lp->stats.tx_bytes += skb->len;
607 /* do it the 'split' way */
608 lp->outgoing.proto = proto;
609 lp->outgoing.skb = skb;
610 lp->outgoing.pkt = pkt;
612 if (!proto->continue_tx)
613 BUGMSG(D_NORMAL, "bug! prep_tx==0, but no continue_tx!\n");
614 else if (proto->continue_tx(dev, txbuf)) {
616 "bug! continue_tx finished the first time! "
617 "(proto='%c')\n", proto->suffix);
625 /* make sure we didn't ignore a TX IRQ while we were in here */
627 lp->intmask |= TXFREEflag;
628 AINTMASK(lp->intmask);
630 return 0; /* no need to try again */
635 * Actually start transmitting a packet that was loaded into a buffer
636 * by prepare_tx. This should _only_ be called by the interrupt handler.
638 static int go_tx(struct net_device *dev)
640 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
642 BUGMSG(D_DURING, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
643 ASTATUS(), lp->intmask, lp->next_tx, lp->cur_tx);
645 if (lp->cur_tx != -1 || lp->next_tx == -1)
648 BUGLVL(D_TX) arcnet_dump_packet(dev, lp->next_tx, "go_tx");
650 lp->cur_tx = lp->next_tx;
654 ACOMMAND(TXcmd | (lp->cur_tx << 3));
656 dev->trans_start = jiffies;
657 lp->stats.tx_packets++;
658 lp->lasttrans_dest = lp->lastload_dest;
659 lp->lastload_dest = 0;
660 lp->intmask |= TXFREEflag;
666 /* Called by the kernel when transmit times out */
667 static void arcnet_timeout(struct net_device *dev)
670 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
671 int status = ASTATUS();
677 if (status & TXFREEflag) { /* transmit _DID_ finish */
678 msg = " - missed IRQ?";
681 lp->stats.tx_aborted_errors++;
683 ACOMMAND(NOTXcmd | (lp->cur_tx << 3));
685 lp->stats.tx_errors++;
687 /* make sure we didn't miss a TX IRQ */
689 lp->intmask |= TXFREEflag;
690 AINTMASK(lp->intmask);
692 restore_flags(flags);
694 if (jiffies - lp->last_timeout > 10*HZ) {
695 BUGMSG(D_EXTRA, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
696 msg, status, lp->intmask, lp->lasttrans_dest);
697 lp->last_timeout = jiffies;
703 * The typical workload of the driver: Handle the network interface
704 * interrupts. Establish which device needs attention, and call the correct
705 * chipset interrupt handler.
707 void arcnet_interrupt(int irq, void *dev_id, struct pt_regs *regs)
709 struct net_device *dev = dev_id;
710 struct arcnet_local *lp;
711 int recbuf, status, didsomething, boguscount;
713 BUGMSG(D_DURING, "\n");
716 BUGMSG(D_DURING, "arcnet: irq %d for unknown device.\n", irq);
719 BUGMSG(D_DURING, "in arcnet_interrupt\n");
721 lp = (struct arcnet_local *) dev->priv;
723 BUGMSG(D_DURING, "arcnet: irq ignored due to missing lp.\n");
727 * RESET flag was enabled - if device is not running, we must clear it right
728 * away (but nothing else).
730 if (!netif_running(dev)) {
731 if (ASTATUS() & RESETflag)
732 ACOMMAND(CFLAGScmd | RESETclear);
737 BUGMSG(D_DURING, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
738 ASTATUS(), lp->intmask);
746 * RESET flag was enabled - card is resetting and if RX is
747 * disabled, it's NOT because we just got a packet.
749 * The card is in an undefined state. Clear it out and start over.
751 if (status & RESETflag) {
752 BUGMSG(D_NORMAL, "spurious reset (status=%Xh)\n", status);
756 /* get out of the interrupt handler! */
760 * RX is inhibited - we must have received something. Prepare to
761 * receive into the next buffer.
763 * We don't actually copy the received packet from the card until
764 * after the transmit handler runs (and possibly launches the next
765 * tx); this should improve latency slightly if we get both types
766 * of interrupts at once.
769 if (status & lp->intmask & NORXflag) {
771 BUGMSG(D_DURING, "Buffer #%d: receive irq (status=%Xh)\n",
774 lp->cur_rx = get_arcbuf(dev);
775 if (lp->cur_rx != -1) {
776 BUGMSG(D_DURING, "enabling receive to buffer #%d\n",
778 ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts);
782 /* a transmit finished, and we're interested in it. */
783 if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
784 lp->intmask &= ~TXFREEflag;
786 BUGMSG(D_DURING, "TX IRQ (stat=%Xh)\n", status);
788 if (lp->cur_tx != -1 && !(status & TXACKflag) && !lp->timed_out) {
789 if (lp->lasttrans_dest != 0) {
790 BUGMSG(D_EXTRA, "transmit was not acknowledged! "
791 "(status=%Xh, dest=%02Xh)\n",
792 status, lp->lasttrans_dest);
793 lp->stats.tx_errors++;
794 lp->stats.tx_carrier_errors++;
797 "broadcast was not acknowledged; that's normal "
798 "(status=%Xh, dest=%02Xh)\n",
799 status, lp->lasttrans_dest);
802 if (lp->cur_tx != -1)
803 release_arcbuf(dev, lp->cur_tx);
809 /* send another packet if there is one */
812 /* continue a split packet, if any */
813 if (lp->outgoing.proto && lp->outgoing.proto->continue_tx) {
814 int txbuf = get_arcbuf(dev);
816 if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
817 /* that was the last segment */
818 lp->stats.tx_bytes += lp->outgoing.skb->len;
819 dev_kfree_skb_irq(lp->outgoing.skb);
820 lp->outgoing.proto = NULL;
825 /* inform upper layers of idleness, if necessary */
826 if (lp->cur_tx == -1)
827 netif_wake_queue(dev);
829 /* now process the received packet, if any */
831 BUGLVL(D_RX) arcnet_dump_packet(dev, recbuf, "rx irq");
833 arcnet_rx(dev, recbuf);
834 release_arcbuf(dev, recbuf);
838 if (status & lp->intmask & RECONflag) {
839 ACOMMAND(CFLAGScmd | CONFIGclear);
840 lp->stats.tx_carrier_errors++;
842 BUGMSG(D_RECON, "Network reconfiguration detected (status=%Xh)\n",
845 /* is the RECON info empty or old? */
846 if (!lp->first_recon || !lp->last_recon ||
847 jiffies - lp->last_recon > HZ * 10) {
848 if (lp->network_down)
849 BUGMSG(D_NORMAL, "reconfiguration detected: cabling restored?\n");
850 lp->first_recon = lp->last_recon = jiffies;
851 lp->num_recons = lp->network_down = 0;
853 BUGMSG(D_DURING, "recon: clearing counters.\n");
854 } else { /* add to current RECON counter */
855 lp->last_recon = jiffies;
858 BUGMSG(D_DURING, "recon: counter=%d, time=%lds, net=%d\n",
860 (lp->last_recon - lp->first_recon) / HZ,
863 /* if network is marked up;
864 * and first_recon and last_recon are 60+ apart;
865 * and the average no. of recons counted is
866 * > RECON_THRESHOLD/min;
867 * then print a warning message.
869 if (!lp->network_down
870 && (lp->last_recon - lp->first_recon) <= HZ * 60
871 && lp->num_recons >= RECON_THRESHOLD) {
872 lp->network_down = 1;
873 BUGMSG(D_NORMAL, "many reconfigurations detected: cabling problem?\n");
874 } else if (!lp->network_down
875 && lp->last_recon - lp->first_recon > HZ * 60) {
876 /* reset counters if we've gone for over a minute. */
877 lp->first_recon = lp->last_recon;
881 } else if (lp->network_down && jiffies - lp->last_recon > HZ * 10) {
882 if (lp->network_down)
883 BUGMSG(D_NORMAL, "cabling restored?\n");
884 lp->first_recon = lp->last_recon = 0;
885 lp->num_recons = lp->network_down = 0;
887 BUGMSG(D_DURING, "not recon: clearing counters anyway.\n");
890 while (--boguscount && didsomething);
892 BUGMSG(D_DURING, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
893 ASTATUS(), boguscount);
894 BUGMSG(D_DURING, "\n");
899 AINTMASK(lp->intmask);
904 * This is a generic packet receiver that calls arcnet??_rx depending on the
907 void arcnet_rx(struct net_device *dev, int bufnum)
909 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
911 struct arc_rfc1201 *soft;
914 soft = &pkt.soft.rfc1201;
916 lp->hw.copy_from_card(dev, bufnum, 0, &pkt, sizeof(ARC_HDR_SIZE));
917 if (pkt.hard.offset[0]) {
918 ofs = pkt.hard.offset[0];
921 ofs = pkt.hard.offset[1];
925 /* get the full header, if possible */
926 if (sizeof(pkt.soft) < length)
927 lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft));
929 memset(&pkt.soft, 0, sizeof(pkt.soft));
930 lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
933 BUGMSG(D_DURING, "Buffer #%d: received packet from %02Xh to %02Xh "
935 bufnum, pkt.hard.source, pkt.hard.dest, length);
937 lp->stats.rx_packets++;
938 lp->stats.rx_bytes += length + ARC_HDR_SIZE;
940 /* call the right receiver for the protocol */
941 if (arc_proto_map[soft->proto] != &arc_proto_null) {
944 *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]],
945 *newp = arc_proto_map[soft->proto];
949 "got protocol %02Xh; encap for host %02Xh is now '%c'"
950 " (was '%c')\n", soft->proto, pkt.hard.source,
951 newp->suffix, oldp->suffix);
955 /* broadcasts will always be done with the last-used encap. */
956 lp->default_proto[0] = soft->proto;
958 /* in striking contrast, the following isn't a hack. */
959 lp->default_proto[pkt.hard.source] = soft->proto;
961 /* call the protocol-specific receiver. */
962 arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length);
968 * Get the current statistics. This may be called with the card open or
971 static struct net_device_stats *arcnet_get_stats(struct net_device *dev)
973 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
978 static void null_rx(struct net_device *dev, int bufnum,
979 struct archdr *pkthdr, int length)
982 "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
983 pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
987 static int null_build_header(struct sk_buff *skb, unsigned short type,
990 struct net_device *dev = skb->dev;
991 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
994 "tx: can't build header for encap %02Xh; load a protocol driver.\n",
995 lp->default_proto[daddr]);
1002 /* the "do nothing" prepare_tx function warns that there's nothing to do. */
1003 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
1004 int length, int bufnum)
1006 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
1007 struct arc_hardware newpkt;
1009 BUGMSG(D_PROTO, "tx: no encap for this host; load a protocol driver.\n");
1011 /* send a packet to myself -- will never get received, of course */
1012 newpkt.source = newpkt.dest = dev->dev_addr[0];
1014 /* only one byte of actual data (and it's random) */
1015 newpkt.offset[0] = 0xFF;
1017 lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
1019 return 1; /* done */