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@ucw.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 General 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, struct net_device *dev,
61 unsigned short type, uint8_t daddr);
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 =
79 .build_header = null_build_header,
80 .prepare_tx = null_prepare_tx,
83 static spinlock_t arcnet_lock = SPIN_LOCK_UNLOCKED;
85 /* Exported function prototypes */
86 int arcnet_debug = ARCNET_DEBUG;
88 EXPORT_SYMBOL(arc_proto_map);
89 EXPORT_SYMBOL(arc_proto_default);
90 EXPORT_SYMBOL(arc_bcast_proto);
91 EXPORT_SYMBOL(arc_proto_null);
92 EXPORT_SYMBOL(arcnet_unregister_proto);
93 EXPORT_SYMBOL(arcnet_debug);
94 EXPORT_SYMBOL(arcdev_setup);
95 EXPORT_SYMBOL(alloc_arcdev);
96 EXPORT_SYMBOL(arcnet_interrupt);
98 /* Internal function prototypes */
99 static int arcnet_open(struct net_device *dev);
100 static int arcnet_close(struct net_device *dev);
101 static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev);
102 static void arcnet_timeout(struct net_device *dev);
103 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
104 unsigned short type, void *daddr, void *saddr,
106 static int arcnet_rebuild_header(struct sk_buff *skb);
107 static struct net_device_stats *arcnet_get_stats(struct net_device *dev);
108 static int go_tx(struct net_device *dev);
110 static int debug = ARCNET_DEBUG;
111 MODULE_PARM(debug, "i");
112 MODULE_LICENSE("GPL");
114 static int __init arcnet_init(void)
118 arcnet_debug = debug;
124 printk("arcnet: ***\n"
125 "arcnet: * Read arcnet.txt for important release notes!\n"
127 "arcnet: * This is an ALPHA version! (Last stable release: v3.02) E-mail\n"
128 "arcnet: * me if you have any questions, comments, or bug reports.\n"
133 /* initialize the protocol map */
134 arc_proto_default = arc_bcast_proto = &arc_proto_null;
135 for (count = 0; count < 256; count++)
136 arc_proto_map[count] = arc_proto_default;
139 printk("arcnet: struct sizes: %Zd %Zd %Zd %Zd %Zd\n",
140 sizeof(struct arc_hardware), sizeof(struct arc_rfc1201),
141 sizeof(struct arc_rfc1051), sizeof(struct arc_eth_encap),
142 sizeof(struct archdr));
147 static void __exit arcnet_exit(void)
151 module_init(arcnet_init);
152 module_exit(arcnet_exit);
155 * Dump the contents of an sk_buff
157 #if ARCNET_DEBUG_MAX & D_SKB
158 void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc)
162 printk(KERN_DEBUG "%6s: skb dump (%s) follows:", dev->name, desc);
163 for (i = 0; i < skb->len; i++) {
165 printk("\n" KERN_DEBUG "[%04X] ", i);
166 printk("%02X ", ((u_char *) skb->data)[i]);
171 EXPORT_SYMBOL(arcnet_dump_skb);
176 * Dump the contents of an ARCnet buffer
178 #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
179 void arcnet_dump_packet(struct net_device *dev, int bufnum, char *desc)
181 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
184 static uint8_t buf[512];
186 /* hw.copy_from_card expects IRQ context so take the IRQ lock
187 to keep it single threaded */
188 spin_lock_irqsave(&arcnet_lock, flags);
189 lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
190 spin_unlock_irqrestore(&arcnet_lock, flags);
192 /* if the offset[0] byte is nonzero, this is a 256-byte packet */
193 length = (buf[2] ? 256 : 512);
195 printk(KERN_DEBUG "%6s: packet dump (%s) follows:", dev->name, desc);
196 for (i = 0; i < length; i++) {
198 printk("\n" KERN_DEBUG "[%04X] ", i);
199 printk("%02X ", buf[i]);
205 EXPORT_SYMBOL(arcnet_dump_packet);
210 * Unregister a protocol driver from the arc_proto_map. Protocol drivers
211 * are responsible for registering themselves, but the unregister routine
212 * is pretty generic so we'll do it here.
214 void arcnet_unregister_proto(struct ArcProto *proto)
218 if (arc_proto_default == proto)
219 arc_proto_default = &arc_proto_null;
220 if (arc_bcast_proto == proto)
221 arc_bcast_proto = arc_proto_default;
223 for (count = 0; count < 256; count++) {
224 if (arc_proto_map[count] == proto)
225 arc_proto_map[count] = arc_proto_default;
231 * Add a buffer to the queue. Only the interrupt handler is allowed to do
232 * this, unless interrupts are disabled.
234 * Note: we don't check for a full queue, since there aren't enough buffers
235 * to more than fill it.
237 static void release_arcbuf(struct net_device *dev, int bufnum)
239 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
242 lp->buf_queue[lp->first_free_buf++] = bufnum;
243 lp->first_free_buf %= 5;
246 BUGMSG(D_DURING, "release_arcbuf: freed #%d; buffer queue is now: ",
248 for (i = lp->next_buf; i != lp->first_free_buf; i = ++i % 5)
249 BUGMSG2(D_DURING, "#%d ", lp->buf_queue[i]);
250 BUGMSG2(D_DURING, "\n");
256 * Get a buffer from the queue. If this returns -1, there are no buffers
259 static int get_arcbuf(struct net_device *dev)
261 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
264 if (!atomic_dec_and_test(&lp->buf_lock)) /* already in this function */
265 BUGMSG(D_NORMAL, "get_arcbuf: overlap (%d)!\n", lp->buf_lock.counter);
266 else { /* we can continue */
267 if (lp->next_buf >= 5)
270 if (lp->next_buf == lp->first_free_buf)
271 BUGMSG(D_NORMAL, "get_arcbuf: BUG: no buffers are available??\n");
273 buf = lp->buf_queue[lp->next_buf++];
280 BUGMSG(D_DURING, "get_arcbuf: got #%d; buffer queue is now: ", buf);
281 for (i = lp->next_buf; i != lp->first_free_buf; i = ++i % 5)
282 BUGMSG2(D_DURING, "#%d ", lp->buf_queue[i]);
283 BUGMSG2(D_DURING, "\n");
286 atomic_inc(&lp->buf_lock);
291 static int choose_mtu(void)
293 int count, mtu = 65535;
295 /* choose the smallest MTU of all available encaps */
296 for (count = 0; count < 256; count++) {
297 if (arc_proto_map[count] != &arc_proto_null
298 && arc_proto_map[count]->mtu < mtu) {
299 mtu = arc_proto_map[count]->mtu;
303 return mtu == 65535 ? XMTU : mtu;
307 /* Setup a struct device for ARCnet. */
308 void arcdev_setup(struct net_device *dev)
310 dev->type = ARPHRD_ARCNET;
311 dev->hard_header_len = sizeof(struct archdr);
312 dev->mtu = choose_mtu();
314 dev->addr_len = ARCNET_ALEN;
315 dev->tx_queue_len = 30;
316 dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
317 dev->watchdog_timeo = TX_TIMEOUT;
319 /* New-style flags. */
320 dev->flags = IFF_BROADCAST;
323 * Put in this stuff here, so we don't have to export the symbols to
324 * the chipset drivers.
326 dev->open = arcnet_open;
327 dev->stop = arcnet_close;
328 dev->hard_start_xmit = arcnet_send_packet;
329 dev->tx_timeout = arcnet_timeout;
330 dev->get_stats = arcnet_get_stats;
331 dev->hard_header = arcnet_header;
332 dev->rebuild_header = arcnet_rebuild_header;
335 struct net_device *alloc_arcdev(char *name)
337 return alloc_netdev(sizeof(struct arcnet_local),
338 name && *name ? name : "arc%d", arcdev_setup);
342 * Open/initialize the board. This is called sometime after booting when
343 * the 'ifconfig' program is run.
345 * This routine should set everything up anew at each open, even registers
346 * that "should" only need to be set once at boot, so that there is
347 * non-reboot way to recover if something goes wrong.
349 static int arcnet_open(struct net_device *dev)
351 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
352 int count, newmtu, error;
354 if (!try_module_get(lp->hw.owner))
359 BUGMSG(D_PROTO, "protocol map (default is '%c'): ",
360 arc_proto_default->suffix);
361 for (count = 0; count < 256; count++)
362 BUGMSG2(D_PROTO, "%c", arc_proto_map[count]->suffix);
363 BUGMSG2(D_PROTO, "\n");
367 BUGMSG(D_INIT, "arcnet_open: resetting card.\n");
369 /* try to put the card in a defined state - if it fails the first
370 * time, actually reset it.
373 if (ARCRESET(0) && ARCRESET(1))
376 newmtu = choose_mtu();
377 if (newmtu < dev->mtu)
380 /* autodetect the encapsulation for each host. */
381 memset(lp->default_proto, 0, sizeof(lp->default_proto));
383 /* the broadcast address is special - use the 'bcast' protocol */
384 for (count = 0; count < 256; count++) {
385 if (arc_proto_map[count] == arc_bcast_proto) {
386 lp->default_proto[0] = count;
391 /* initialize buffers */
392 atomic_set(&lp->buf_lock, 1);
393 lp->next_buf = lp->first_free_buf = 0;
394 release_arcbuf(dev, 0);
395 release_arcbuf(dev, 1);
396 release_arcbuf(dev, 2);
397 release_arcbuf(dev, 3);
398 lp->cur_tx = lp->next_tx = -1;
401 lp->rfc1201.sequence = 1;
403 /* bring up the hardware driver */
406 if (dev->dev_addr[0] == 0)
407 BUGMSG(D_NORMAL, "WARNING! Station address 00 is reserved "
408 "for broadcasts!\n");
409 else if (dev->dev_addr[0] == 255)
410 BUGMSG(D_NORMAL, "WARNING! Station address FF may confuse "
411 "DOS networking programs!\n");
413 if (ASTATUS() & RESETflag)
414 ACOMMAND(CFLAGScmd | RESETclear);
416 /* make sure we're ready to receive IRQ's. */
418 udelay(1); /* give it time to set the mask before
419 * we reset it again. (may not even be
422 lp->intmask = NORXflag | RECONflag;
423 AINTMASK(lp->intmask);
425 netif_start_queue(dev);
430 module_put(lp->hw.owner);
435 /* The inverse routine to arcnet_open - shuts down the card. */
436 static int arcnet_close(struct net_device *dev)
438 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
440 netif_stop_queue(dev);
442 /* flush TX and disable RX */
444 ACOMMAND(NOTXcmd); /* stop transmit */
445 ACOMMAND(NORXcmd); /* disable receive */
448 /* shut down the card */
450 module_put(lp->hw.owner);
455 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
456 unsigned short type, void *daddr, void *saddr,
459 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
460 uint8_t _daddr, proto_num;
461 struct ArcProto *proto;
464 "create header from %d to %d; protocol %d (%Xh); size %u.\n",
465 saddr ? *(uint8_t *) saddr : -1,
466 daddr ? *(uint8_t *) daddr : -1,
470 BUGMSG(D_NORMAL, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
474 * if the dest addr isn't provided, we can't choose an encapsulation!
475 * Store the packet type (eg. ETH_P_IP) for now, and we'll push on a
476 * real header when we do rebuild_header.
479 *(uint16_t *) skb_push(skb, 2) = type;
480 if (skb->nh.raw - skb->mac.raw != 2)
481 BUGMSG(D_NORMAL, "arcnet_header: Yikes! diff (%d) is not 2!\n",
482 skb->nh.raw - skb->mac.raw);
483 return -2; /* return error -- can't transmit yet! */
485 /* otherwise, we can just add the header as usual. */
486 _daddr = *(uint8_t *) daddr;
487 proto_num = lp->default_proto[_daddr];
488 proto = arc_proto_map[proto_num];
489 BUGMSG(D_DURING, "building header for %02Xh using protocol '%c'\n",
490 proto_num, proto->suffix);
491 if (proto == &arc_proto_null && arc_bcast_proto != proto) {
492 BUGMSG(D_DURING, "actually, let's use '%c' instead.\n",
493 arc_bcast_proto->suffix);
494 proto = arc_bcast_proto;
496 return proto->build_header(skb, dev, type, _daddr);
501 * Rebuild the ARCnet hard header. This is called after an ARP (or in the
502 * future other address resolution) has completed on this sk_buff. We now
503 * let ARP fill in the destination field.
505 static int arcnet_rebuild_header(struct sk_buff *skb)
507 struct net_device *dev = skb->dev;
508 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
509 int status = 0; /* default is failure */
512 struct ArcProto *proto;
514 if (skb->nh.raw - skb->mac.raw != 2) {
516 "rebuild_header: shouldn't be here! (hdrsize=%d)\n",
517 skb->nh.raw - skb->mac.raw);
520 type = *(uint16_t *) skb_pull(skb, 2);
522 if (type == ETH_P_IP) {
524 BUGMSG(D_DURING, "rebuild header for ethernet protocol %Xh\n", type);
525 status = arp_find(&daddr, skb) ? 1 : 0;
526 BUGMSG(D_DURING, " rebuilt: dest is %d; protocol %Xh\n",
531 "I don't understand ethernet protocol %Xh addresses!\n", type);
532 lp->stats.tx_errors++;
533 lp->stats.tx_aborted_errors++;
536 /* if we couldn't resolve the address... give up. */
540 /* add the _real_ header this time! */
541 proto = arc_proto_map[lp->default_proto[daddr]];
542 proto->build_header(skb, dev, type, daddr);
544 return 1; /* success */
549 /* Called by the kernel in order to transmit a packet. */
550 static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev)
552 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
554 struct arc_rfc1201 *soft;
555 struct ArcProto *proto;
559 "transmit requested (status=%Xh, txbufs=%d/%d, len=%d)\n",
560 ASTATUS(), lp->cur_tx, lp->next_tx, skb->len);
562 pkt = (struct archdr *) skb->data;
563 soft = &pkt->soft.rfc1201;
564 proto = arc_proto_map[soft->proto];
566 BUGMSG(D_SKB_SIZE, "skb: transmitting %d bytes to %02X\n",
567 skb->len, pkt->hard.dest);
568 BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "tx");
570 /* fits in one packet? */
571 if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
572 BUGMSG(D_NORMAL, "fixme: packet too large: compensating badly!\n");
574 return 0; /* don't try again */
577 /* We're busy transmitting a packet... */
578 netif_stop_queue(dev);
582 txbuf = get_arcbuf(dev);
584 if (proto->prepare_tx(dev, pkt, skb->len, txbuf)) {
585 /* done right away */
586 lp->stats.tx_bytes += skb->len;
589 /* do it the 'split' way */
590 lp->outgoing.proto = proto;
591 lp->outgoing.skb = skb;
592 lp->outgoing.pkt = pkt;
594 if (!proto->continue_tx)
595 BUGMSG(D_NORMAL, "bug! prep_tx==0, but no continue_tx!\n");
596 else if (proto->continue_tx(dev, txbuf)) {
598 "bug! continue_tx finished the first time! "
599 "(proto='%c')\n", proto->suffix);
607 /* make sure we didn't ignore a TX IRQ while we were in here */
609 lp->intmask |= TXFREEflag;
610 AINTMASK(lp->intmask);
612 return 0; /* no need to try again */
617 * Actually start transmitting a packet that was loaded into a buffer
618 * by prepare_tx. This should _only_ be called by the interrupt handler.
620 static int go_tx(struct net_device *dev)
622 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
624 BUGMSG(D_DURING, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
625 ASTATUS(), lp->intmask, lp->next_tx, lp->cur_tx);
627 if (lp->cur_tx != -1 || lp->next_tx == -1)
630 BUGLVL(D_TX) arcnet_dump_packet(dev, lp->next_tx, "go_tx");
632 lp->cur_tx = lp->next_tx;
636 ACOMMAND(TXcmd | (lp->cur_tx << 3));
638 dev->trans_start = jiffies;
639 lp->stats.tx_packets++;
640 lp->lasttrans_dest = lp->lastload_dest;
641 lp->lastload_dest = 0;
642 lp->intmask |= TXFREEflag;
648 /* Called by the kernel when transmit times out */
649 static void arcnet_timeout(struct net_device *dev)
652 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
653 int status = ASTATUS();
656 spin_lock_irqsave(&arcnet_lock, flags);
657 if (status & TXFREEflag) { /* transmit _DID_ finish */
658 msg = " - missed IRQ?";
661 lp->stats.tx_aborted_errors++;
663 ACOMMAND(NOTXcmd | (lp->cur_tx << 3));
665 lp->stats.tx_errors++;
667 /* make sure we didn't miss a TX IRQ */
669 lp->intmask |= TXFREEflag;
670 AINTMASK(lp->intmask);
672 spin_unlock_irqrestore(&arcnet_lock, flags);
674 if (jiffies - lp->last_timeout > 10*HZ) {
675 BUGMSG(D_EXTRA, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
676 msg, status, lp->intmask, lp->lasttrans_dest);
677 lp->last_timeout = jiffies;
680 if (lp->cur_tx == -1)
681 netif_wake_queue(dev);
686 * The typical workload of the driver: Handle the network interface
687 * interrupts. Establish which device needs attention, and call the correct
688 * chipset interrupt handler.
690 irqreturn_t arcnet_interrupt(int irq, void *dev_id, struct pt_regs *regs)
692 struct net_device *dev = dev_id;
693 struct arcnet_local *lp;
694 int recbuf, status, didsomething, boguscount;
696 BUGMSG(D_DURING, "\n");
698 BUGMSG(D_DURING, "in arcnet_interrupt\n");
700 spin_lock(&arcnet_lock);
702 lp = (struct arcnet_local *) dev->priv;
707 * RESET flag was enabled - if device is not running, we must clear it right
708 * away (but nothing else).
710 if (!netif_running(dev)) {
711 if (ASTATUS() & RESETflag)
712 ACOMMAND(CFLAGScmd | RESETclear);
714 spin_unlock(&arcnet_lock);
718 BUGMSG(D_DURING, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
719 ASTATUS(), lp->intmask);
727 * RESET flag was enabled - card is resetting and if RX is
728 * disabled, it's NOT because we just got a packet.
730 * The card is in an undefined state. Clear it out and start over.
732 if (status & RESETflag) {
733 BUGMSG(D_NORMAL, "spurious reset (status=%Xh)\n", status);
737 /* get out of the interrupt handler! */
741 * RX is inhibited - we must have received something. Prepare to
742 * receive into the next buffer.
744 * We don't actually copy the received packet from the card until
745 * after the transmit handler runs (and possibly launches the next
746 * tx); this should improve latency slightly if we get both types
747 * of interrupts at once.
750 if (status & lp->intmask & NORXflag) {
752 BUGMSG(D_DURING, "Buffer #%d: receive irq (status=%Xh)\n",
755 lp->cur_rx = get_arcbuf(dev);
756 if (lp->cur_rx != -1) {
757 BUGMSG(D_DURING, "enabling receive to buffer #%d\n",
759 ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts);
763 /* a transmit finished, and we're interested in it. */
764 if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
765 lp->intmask &= ~TXFREEflag;
767 BUGMSG(D_DURING, "TX IRQ (stat=%Xh)\n", status);
769 if (lp->cur_tx != -1 && !(status & TXACKflag) && !lp->timed_out) {
770 if (lp->lasttrans_dest != 0) {
771 BUGMSG(D_EXTRA, "transmit was not acknowledged! "
772 "(status=%Xh, dest=%02Xh)\n",
773 status, lp->lasttrans_dest);
774 lp->stats.tx_errors++;
775 lp->stats.tx_carrier_errors++;
778 "broadcast was not acknowledged; that's normal "
779 "(status=%Xh, dest=%02Xh)\n",
780 status, lp->lasttrans_dest);
783 if (lp->cur_tx != -1)
784 release_arcbuf(dev, lp->cur_tx);
790 /* send another packet if there is one */
793 /* continue a split packet, if any */
794 if (lp->outgoing.proto && lp->outgoing.proto->continue_tx) {
795 int txbuf = get_arcbuf(dev);
797 if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
798 /* that was the last segment */
799 lp->stats.tx_bytes += lp->outgoing.skb->len;
800 dev_kfree_skb_irq(lp->outgoing.skb);
801 lp->outgoing.proto = NULL;
806 /* inform upper layers of idleness, if necessary */
807 if (lp->cur_tx == -1)
808 netif_wake_queue(dev);
810 /* now process the received packet, if any */
812 BUGLVL(D_RX) arcnet_dump_packet(dev, recbuf, "rx irq");
814 arcnet_rx(dev, recbuf);
815 release_arcbuf(dev, recbuf);
819 if (status & lp->intmask & RECONflag) {
820 ACOMMAND(CFLAGScmd | CONFIGclear);
821 lp->stats.tx_carrier_errors++;
823 BUGMSG(D_RECON, "Network reconfiguration detected (status=%Xh)\n",
826 /* is the RECON info empty or old? */
827 if (!lp->first_recon || !lp->last_recon ||
828 jiffies - lp->last_recon > HZ * 10) {
829 if (lp->network_down)
830 BUGMSG(D_NORMAL, "reconfiguration detected: cabling restored?\n");
831 lp->first_recon = lp->last_recon = jiffies;
832 lp->num_recons = lp->network_down = 0;
834 BUGMSG(D_DURING, "recon: clearing counters.\n");
835 } else { /* add to current RECON counter */
836 lp->last_recon = jiffies;
839 BUGMSG(D_DURING, "recon: counter=%d, time=%lds, net=%d\n",
841 (lp->last_recon - lp->first_recon) / HZ,
844 /* if network is marked up;
845 * and first_recon and last_recon are 60+ apart;
846 * and the average no. of recons counted is
847 * > RECON_THRESHOLD/min;
848 * then print a warning message.
850 if (!lp->network_down
851 && (lp->last_recon - lp->first_recon) <= HZ * 60
852 && lp->num_recons >= RECON_THRESHOLD) {
853 lp->network_down = 1;
854 BUGMSG(D_NORMAL, "many reconfigurations detected: cabling problem?\n");
855 } else if (!lp->network_down
856 && lp->last_recon - lp->first_recon > HZ * 60) {
857 /* reset counters if we've gone for over a minute. */
858 lp->first_recon = lp->last_recon;
862 } else if (lp->network_down && jiffies - lp->last_recon > HZ * 10) {
863 if (lp->network_down)
864 BUGMSG(D_NORMAL, "cabling restored?\n");
865 lp->first_recon = lp->last_recon = 0;
866 lp->num_recons = lp->network_down = 0;
868 BUGMSG(D_DURING, "not recon: clearing counters anyway.\n");
871 while (--boguscount && didsomething);
873 BUGMSG(D_DURING, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
874 ASTATUS(), boguscount);
875 BUGMSG(D_DURING, "\n");
880 AINTMASK(lp->intmask);
882 spin_unlock(&arcnet_lock);
883 return IRQ_RETVAL(didsomething);
888 * This is a generic packet receiver that calls arcnet??_rx depending on the
891 void arcnet_rx(struct net_device *dev, int bufnum)
893 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
895 struct arc_rfc1201 *soft;
898 soft = &pkt.soft.rfc1201;
900 lp->hw.copy_from_card(dev, bufnum, 0, &pkt, sizeof(ARC_HDR_SIZE));
901 if (pkt.hard.offset[0]) {
902 ofs = pkt.hard.offset[0];
905 ofs = pkt.hard.offset[1];
909 /* get the full header, if possible */
910 if (sizeof(pkt.soft) < length)
911 lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft));
913 memset(&pkt.soft, 0, sizeof(pkt.soft));
914 lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
917 BUGMSG(D_DURING, "Buffer #%d: received packet from %02Xh to %02Xh "
919 bufnum, pkt.hard.source, pkt.hard.dest, length);
921 lp->stats.rx_packets++;
922 lp->stats.rx_bytes += length + ARC_HDR_SIZE;
924 /* call the right receiver for the protocol */
925 if (arc_proto_map[soft->proto] != &arc_proto_null) {
928 *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]],
929 *newp = arc_proto_map[soft->proto];
933 "got protocol %02Xh; encap for host %02Xh is now '%c'"
934 " (was '%c')\n", soft->proto, pkt.hard.source,
935 newp->suffix, oldp->suffix);
939 /* broadcasts will always be done with the last-used encap. */
940 lp->default_proto[0] = soft->proto;
942 /* in striking contrast, the following isn't a hack. */
943 lp->default_proto[pkt.hard.source] = soft->proto;
945 /* call the protocol-specific receiver. */
946 arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length);
952 * Get the current statistics. This may be called with the card open or
955 static struct net_device_stats *arcnet_get_stats(struct net_device *dev)
957 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
962 static void null_rx(struct net_device *dev, int bufnum,
963 struct archdr *pkthdr, int length)
966 "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
967 pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
971 static int null_build_header(struct sk_buff *skb, struct net_device *dev,
972 unsigned short type, uint8_t daddr)
974 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
977 "tx: can't build header for encap %02Xh; load a protocol driver.\n",
978 lp->default_proto[daddr]);
985 /* the "do nothing" prepare_tx function warns that there's nothing to do. */
986 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
987 int length, int bufnum)
989 struct arcnet_local *lp = (struct arcnet_local *) dev->priv;
990 struct arc_hardware newpkt;
992 BUGMSG(D_PROTO, "tx: no encap for this host; load a protocol driver.\n");
994 /* send a packet to myself -- will never get received, of course */
995 newpkt.source = newpkt.dest = dev->dev_addr[0];
997 /* only one byte of actual data (and it's random) */
998 newpkt.offset[0] = 0xFF;
1000 lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
1002 return 1; /* done */