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 pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/module.h>
47 #include <linux/types.h>
48 #include <linux/delay.h>
49 #include <linux/netdevice.h>
50 #include <linux/if_arp.h>
52 #include <linux/init.h>
53 #include <linux/jiffies.h>
55 #include "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);
65 static void arcnet_rx(struct net_device *dev, 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];
73 EXPORT_SYMBOL(arc_proto_map);
75 struct ArcProto *arc_proto_default;
76 EXPORT_SYMBOL(arc_proto_default);
78 struct ArcProto *arc_bcast_proto;
79 EXPORT_SYMBOL(arc_bcast_proto);
81 struct ArcProto *arc_raw_proto;
82 EXPORT_SYMBOL(arc_raw_proto);
84 static struct ArcProto arc_proto_null = {
89 .build_header = null_build_header,
90 .prepare_tx = null_prepare_tx,
95 /* Exported function prototypes */
96 int arcnet_debug = ARCNET_DEBUG;
97 EXPORT_SYMBOL(arcnet_debug);
99 /* Internal function prototypes */
100 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
101 unsigned short type, const void *daddr,
102 const void *saddr, unsigned len);
103 static int go_tx(struct net_device *dev);
105 static int debug = ARCNET_DEBUG;
106 module_param(debug, int, 0);
107 MODULE_LICENSE("GPL");
109 static int __init arcnet_init(void)
113 arcnet_debug = debug;
115 pr_info("arcnet loaded\n");
117 /* initialize the protocol map */
118 arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
119 for (count = 0; count < 256; count++)
120 arc_proto_map[count] = arc_proto_default;
122 if (BUGLVL(D_DURING))
123 pr_info("struct sizes: %Zd %Zd %Zd %Zd %Zd\n",
124 sizeof(struct arc_hardware),
125 sizeof(struct arc_rfc1201),
126 sizeof(struct arc_rfc1051),
127 sizeof(struct arc_eth_encap),
128 sizeof(struct archdr));
133 static void __exit arcnet_exit(void)
137 module_init(arcnet_init);
138 module_exit(arcnet_exit);
140 /* Dump the contents of an sk_buff */
141 #if ARCNET_DEBUG_MAX & D_SKB
142 void arcnet_dump_skb(struct net_device *dev,
143 struct sk_buff *skb, char *desc)
147 /* dump the packet */
148 snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc);
149 print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
150 16, 1, skb->data, skb->len, true);
152 EXPORT_SYMBOL(arcnet_dump_skb);
155 /* Dump the contents of an ARCnet buffer */
156 #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
157 static void arcnet_dump_packet(struct net_device *dev, int bufnum,
158 char *desc, int take_arcnet_lock)
160 struct arcnet_local *lp = netdev_priv(dev);
162 unsigned long flags = 0;
163 static uint8_t buf[512];
166 /* hw.copy_from_card expects IRQ context so take the IRQ lock
167 * to keep it single threaded
169 if (take_arcnet_lock)
170 spin_lock_irqsave(&lp->lock, flags);
172 lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
173 if (take_arcnet_lock)
174 spin_unlock_irqrestore(&lp->lock, flags);
176 /* if the offset[0] byte is nonzero, this is a 256-byte packet */
177 length = (buf[2] ? 256 : 512);
179 /* dump the packet */
180 snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc);
181 print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
182 16, 1, buf, length, true);
187 #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
191 /* Unregister a protocol driver from the arc_proto_map. Protocol drivers
192 * are responsible for registering themselves, but the unregister routine
193 * is pretty generic so we'll do it here.
195 void arcnet_unregister_proto(struct ArcProto *proto)
199 if (arc_proto_default == proto)
200 arc_proto_default = &arc_proto_null;
201 if (arc_bcast_proto == proto)
202 arc_bcast_proto = arc_proto_default;
203 if (arc_raw_proto == proto)
204 arc_raw_proto = arc_proto_default;
206 for (count = 0; count < 256; count++) {
207 if (arc_proto_map[count] == proto)
208 arc_proto_map[count] = arc_proto_default;
211 EXPORT_SYMBOL(arcnet_unregister_proto);
213 /* Add a buffer to the queue. Only the interrupt handler is allowed to do
214 * this, unless interrupts are disabled.
216 * Note: we don't check for a full queue, since there aren't enough buffers
217 * to more than fill it.
219 static void release_arcbuf(struct net_device *dev, int bufnum)
221 struct arcnet_local *lp = netdev_priv(dev);
224 lp->buf_queue[lp->first_free_buf++] = bufnum;
225 lp->first_free_buf %= 5;
227 if (BUGLVL(D_DURING)) {
228 arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
230 for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
231 arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
232 arc_cont(D_DURING, "\n");
236 /* Get a buffer from the queue.
237 * If this returns -1, there are no buffers available.
239 static int get_arcbuf(struct net_device *dev)
241 struct arcnet_local *lp = netdev_priv(dev);
244 if (!atomic_dec_and_test(&lp->buf_lock)) {
245 /* already in this function */
246 arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
247 lp->buf_lock.counter);
248 } else { /* we can continue */
249 if (lp->next_buf >= 5)
252 if (lp->next_buf == lp->first_free_buf) {
253 arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
255 buf = lp->buf_queue[lp->next_buf++];
260 if (BUGLVL(D_DURING)) {
261 arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
263 for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
264 arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
265 arc_cont(D_DURING, "\n");
268 atomic_inc(&lp->buf_lock);
272 static int choose_mtu(void)
274 int count, mtu = 65535;
276 /* choose the smallest MTU of all available encaps */
277 for (count = 0; count < 256; count++) {
278 if (arc_proto_map[count] != &arc_proto_null &&
279 arc_proto_map[count]->mtu < mtu) {
280 mtu = arc_proto_map[count]->mtu;
284 return mtu == 65535 ? XMTU : mtu;
287 static const struct header_ops arcnet_header_ops = {
288 .create = arcnet_header,
291 static const struct net_device_ops arcnet_netdev_ops = {
292 .ndo_open = arcnet_open,
293 .ndo_stop = arcnet_close,
294 .ndo_start_xmit = arcnet_send_packet,
295 .ndo_tx_timeout = arcnet_timeout,
298 /* Setup a struct device for ARCnet. */
299 static void arcdev_setup(struct net_device *dev)
301 dev->type = ARPHRD_ARCNET;
302 dev->netdev_ops = &arcnet_netdev_ops;
303 dev->header_ops = &arcnet_header_ops;
304 dev->hard_header_len = sizeof(struct archdr);
305 dev->mtu = choose_mtu();
307 dev->addr_len = ARCNET_ALEN;
308 dev->tx_queue_len = 100;
309 dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
310 dev->watchdog_timeo = TX_TIMEOUT;
312 /* New-style flags. */
313 dev->flags = IFF_BROADCAST;
316 struct net_device *alloc_arcdev(const char *name)
318 struct net_device *dev;
320 dev = alloc_netdev(sizeof(struct arcnet_local),
321 name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
324 struct arcnet_local *lp = netdev_priv(dev);
326 spin_lock_init(&lp->lock);
331 EXPORT_SYMBOL(alloc_arcdev);
333 /* Open/initialize the board. This is called sometime after booting when
334 * the 'ifconfig' program is run.
336 * This routine should set everything up anew at each open, even registers
337 * that "should" only need to be set once at boot, so that there is
338 * non-reboot way to recover if something goes wrong.
340 int arcnet_open(struct net_device *dev)
342 struct arcnet_local *lp = netdev_priv(dev);
343 int count, newmtu, error;
345 arc_printk(D_INIT, dev, "opened.");
347 if (!try_module_get(lp->hw.owner))
350 if (BUGLVL(D_PROTO)) {
351 arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
352 arc_proto_default->suffix);
353 for (count = 0; count < 256; count++)
354 arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
355 arc_cont(D_PROTO, "\n");
358 arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
360 /* try to put the card in a defined state - if it fails the first
361 * time, actually reset it.
364 if (ARCRESET(0) && ARCRESET(1))
367 newmtu = choose_mtu();
368 if (newmtu < dev->mtu)
371 arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
373 /* autodetect the encapsulation for each host. */
374 memset(lp->default_proto, 0, sizeof(lp->default_proto));
376 /* the broadcast address is special - use the 'bcast' protocol */
377 for (count = 0; count < 256; count++) {
378 if (arc_proto_map[count] == arc_bcast_proto) {
379 lp->default_proto[0] = count;
384 /* initialize buffers */
385 atomic_set(&lp->buf_lock, 1);
387 lp->next_buf = lp->first_free_buf = 0;
388 release_arcbuf(dev, 0);
389 release_arcbuf(dev, 1);
390 release_arcbuf(dev, 2);
391 release_arcbuf(dev, 3);
392 lp->cur_tx = lp->next_tx = -1;
395 lp->rfc1201.sequence = 1;
397 /* bring up the hardware driver */
401 if (dev->dev_addr[0] == 0)
402 arc_printk(D_NORMAL, dev, "WARNING! Station address 00 is reserved for broadcasts!\n");
403 else if (dev->dev_addr[0] == 255)
404 arc_printk(D_NORMAL, dev, "WARNING! Station address FF may confuse DOS networking programs!\n");
406 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
407 if (ASTATUS() & RESETflag) {
408 arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
409 __FILE__, __LINE__, __func__);
410 ACOMMAND(CFLAGScmd | RESETclear);
413 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
414 /* make sure we're ready to receive IRQ's. */
416 udelay(1); /* give it time to set the mask before
417 * we reset it again. (may not even be
420 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
421 lp->intmask = NORXflag | RECONflag;
422 AINTMASK(lp->intmask);
423 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
425 netif_start_queue(dev);
430 module_put(lp->hw.owner);
433 EXPORT_SYMBOL(arcnet_open);
435 /* The inverse routine to arcnet_open - shuts down the card. */
436 int arcnet_close(struct net_device *dev)
438 struct arcnet_local *lp = netdev_priv(dev);
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);
453 EXPORT_SYMBOL(arcnet_close);
455 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
456 unsigned short type, const void *daddr,
457 const void *saddr, unsigned len)
459 const struct arcnet_local *lp = netdev_priv(dev);
460 uint8_t _daddr, proto_num;
461 struct ArcProto *proto;
463 arc_printk(D_DURING, dev,
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,
469 if (skb->len != 0 && len != skb->len)
470 arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
473 /* Type is host order - ? */
474 if (type == ETH_P_ARCNET) {
475 proto = arc_raw_proto;
476 arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
478 _daddr = daddr ? *(uint8_t *)daddr : 0;
480 /* if the dest addr isn't provided, we can't choose an
481 * encapsulation! Store the packet type (eg. ETH_P_IP)
482 * for now, and we'll push on a real header when we do
485 *(uint16_t *)skb_push(skb, 2) = type;
486 /* XXX: Why not use skb->mac_len? */
487 if (skb->network_header - skb->mac_header != 2)
488 arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! diff (%u) is not 2!\n",
489 skb->network_header - skb->mac_header);
490 return -2; /* return error -- can't transmit yet! */
492 /* otherwise, we can just add the header as usual. */
493 _daddr = *(uint8_t *)daddr;
494 proto_num = lp->default_proto[_daddr];
495 proto = arc_proto_map[proto_num];
496 arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
497 proto_num, proto->suffix);
498 if (proto == &arc_proto_null && arc_bcast_proto != proto) {
499 arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
500 arc_bcast_proto->suffix);
501 proto = arc_bcast_proto;
504 return proto->build_header(skb, dev, type, _daddr);
507 /* Called by the kernel in order to transmit a packet. */
508 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
509 struct net_device *dev)
511 struct arcnet_local *lp = netdev_priv(dev);
513 struct arc_rfc1201 *soft;
514 struct ArcProto *proto;
519 arc_printk(D_DURING, dev,
520 "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
521 ASTATUS(), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
523 pkt = (struct archdr *)skb->data;
524 soft = &pkt->soft.rfc1201;
525 proto = arc_proto_map[soft->proto];
527 arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
528 skb->len, pkt->hard.dest);
530 arcnet_dump_skb(dev, skb, "tx");
532 /* fits in one packet? */
533 if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
534 arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
536 return NETDEV_TX_OK; /* don't try again */
539 /* We're busy transmitting a packet... */
540 netif_stop_queue(dev);
542 spin_lock_irqsave(&lp->lock, flags);
544 if (lp->next_tx == -1)
545 txbuf = get_arcbuf(dev);
550 if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
552 /* done right away and we don't want to acknowledge
553 * the package later - forget about it now
555 dev->stats.tx_bytes += skb->len;
558 /* do it the 'split' way */
559 lp->outgoing.proto = proto;
560 lp->outgoing.skb = skb;
561 lp->outgoing.pkt = pkt;
565 if (proto->continue_tx &&
566 proto->continue_tx(dev, txbuf)) {
567 arc_printk(D_NORMAL, dev,
568 "bug! continue_tx finished the first time! (proto='%c')\n",
572 retval = NETDEV_TX_OK;
575 retval = NETDEV_TX_BUSY;
579 arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
580 __FILE__, __LINE__, __func__, ASTATUS());
581 /* make sure we didn't ignore a TX IRQ while we were in here */
584 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
585 lp->intmask |= TXFREEflag | EXCNAKflag;
586 AINTMASK(lp->intmask);
587 arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
588 __FILE__, __LINE__, __func__, ASTATUS());
590 spin_unlock_irqrestore(&lp->lock, flags);
594 return retval; /* no need to try again */
596 EXPORT_SYMBOL(arcnet_send_packet);
598 /* Actually start transmitting a packet that was loaded into a buffer
599 * by prepare_tx. This should _only_ be called by the interrupt handler.
601 static int go_tx(struct net_device *dev)
603 struct arcnet_local *lp = netdev_priv(dev);
605 arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
606 ASTATUS(), lp->intmask, lp->next_tx, lp->cur_tx);
608 if (lp->cur_tx != -1 || lp->next_tx == -1)
612 arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
614 lp->cur_tx = lp->next_tx;
618 ACOMMAND(TXcmd | (lp->cur_tx << 3));
620 dev->stats.tx_packets++;
621 lp->lasttrans_dest = lp->lastload_dest;
622 lp->lastload_dest = 0;
623 lp->excnak_pending = 0;
624 lp->intmask |= TXFREEflag | EXCNAKflag;
629 /* Called by the kernel when transmit times out */
630 void arcnet_timeout(struct net_device *dev)
633 struct arcnet_local *lp = netdev_priv(dev);
634 int status = ASTATUS();
637 spin_lock_irqsave(&lp->lock, flags);
638 if (status & TXFREEflag) { /* transmit _DID_ finish */
639 msg = " - missed IRQ?";
642 dev->stats.tx_aborted_errors++;
644 ACOMMAND(NOTXcmd | (lp->cur_tx << 3));
646 dev->stats.tx_errors++;
648 /* make sure we didn't miss a TX or a EXC NAK IRQ */
650 lp->intmask |= TXFREEflag | EXCNAKflag;
651 AINTMASK(lp->intmask);
653 spin_unlock_irqrestore(&lp->lock, flags);
655 if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
656 arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
657 msg, status, lp->intmask, lp->lasttrans_dest);
658 lp->last_timeout = jiffies;
661 if (lp->cur_tx == -1)
662 netif_wake_queue(dev);
664 EXPORT_SYMBOL(arcnet_timeout);
666 /* The typical workload of the driver: Handle the network interface
667 * interrupts. Establish which device needs attention, and call the correct
668 * chipset interrupt handler.
670 irqreturn_t arcnet_interrupt(int irq, void *dev_id)
672 struct net_device *dev = dev_id;
673 struct arcnet_local *lp;
674 int recbuf, status, diagstatus, didsomething, boguscount;
675 int retval = IRQ_NONE;
677 arc_printk(D_DURING, dev, "\n");
679 arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
681 lp = netdev_priv(dev);
684 spin_lock(&lp->lock);
686 /* RESET flag was enabled - if device is not running, we must
687 * clear it right away (but nothing else).
689 if (!netif_running(dev)) {
690 if (ASTATUS() & RESETflag)
691 ACOMMAND(CFLAGScmd | RESETclear);
693 spin_unlock(&lp->lock);
697 arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
698 ASTATUS(), lp->intmask);
703 diagstatus = (status >> 8) & 0xFF;
705 arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
706 __FILE__, __LINE__, __func__, status);
709 /* RESET flag was enabled - card is resetting and if RX is
710 * disabled, it's NOT because we just got a packet.
712 * The card is in an undefined state.
713 * Clear it out and start over.
715 if (status & RESETflag) {
716 arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
721 /* get out of the interrupt handler! */
724 /* RX is inhibited - we must have received something.
725 * Prepare to receive into the next buffer.
727 * We don't actually copy the received packet from the card
728 * until after the transmit handler runs (and possibly
729 * launches the next tx); this should improve latency slightly
730 * if we get both types of interrupts at once.
733 if (status & lp->intmask & NORXflag) {
735 arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
738 lp->cur_rx = get_arcbuf(dev);
739 if (lp->cur_rx != -1) {
740 arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
742 ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts);
747 if ((diagstatus & EXCNAKflag)) {
748 arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
751 ACOMMAND(NOTXcmd); /* disable transmit */
752 lp->excnak_pending = 1;
754 ACOMMAND(EXCNAKclear);
755 lp->intmask &= ~(EXCNAKflag);
759 /* a transmit finished, and we're interested in it. */
760 if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
761 lp->intmask &= ~(TXFREEflag | EXCNAKflag);
763 arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
766 if (lp->cur_tx != -1 && !lp->timed_out) {
767 if (!(status & TXACKflag)) {
768 if (lp->lasttrans_dest != 0) {
769 arc_printk(D_EXTRA, dev,
770 "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
773 dev->stats.tx_errors++;
774 dev->stats.tx_carrier_errors++;
776 arc_printk(D_DURING, dev,
777 "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
783 if (lp->outgoing.proto &&
784 lp->outgoing.proto->ack_tx) {
787 if (status & TXACKflag)
789 else if (lp->excnak_pending)
795 ->ack_tx(dev, ackstatus);
798 if (lp->cur_tx != -1)
799 release_arcbuf(dev, lp->cur_tx);
805 /* send another packet if there is one */
808 /* continue a split packet, if any */
809 if (lp->outgoing.proto &&
810 lp->outgoing.proto->continue_tx) {
811 int txbuf = get_arcbuf(dev);
814 if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
815 /* that was the last segment */
816 dev->stats.tx_bytes += lp->outgoing.skb->len;
817 if (!lp->outgoing.proto->ack_tx) {
818 dev_kfree_skb_irq(lp->outgoing.skb);
819 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 */
832 arcnet_dump_packet(dev, recbuf, "rx irq", 0);
834 arcnet_rx(dev, recbuf);
835 release_arcbuf(dev, recbuf);
839 if (status & lp->intmask & RECONflag) {
840 ACOMMAND(CFLAGScmd | CONFIGclear);
841 dev->stats.tx_carrier_errors++;
843 arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
845 /* MYRECON bit is at bit 7 of diagstatus */
846 if (diagstatus & 0x80)
847 arc_printk(D_RECON, dev, "Put out that recon myself\n");
849 /* is the RECON info empty or old? */
850 if (!lp->first_recon || !lp->last_recon ||
851 time_after(jiffies, lp->last_recon + HZ * 10)) {
852 if (lp->network_down)
853 arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
854 lp->first_recon = lp->last_recon = jiffies;
855 lp->num_recons = lp->network_down = 0;
857 arc_printk(D_DURING, dev, "recon: clearing counters.\n");
858 } else { /* add to current RECON counter */
859 lp->last_recon = jiffies;
862 arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
864 (lp->last_recon - lp->first_recon) / HZ,
867 /* if network is marked up;
868 * and first_recon and last_recon are 60+ apart;
869 * and the average no. of recons counted is
870 * > RECON_THRESHOLD/min;
871 * then print a warning message.
873 if (!lp->network_down &&
874 (lp->last_recon - lp->first_recon) <= HZ * 60 &&
875 lp->num_recons >= RECON_THRESHOLD) {
876 lp->network_down = 1;
877 arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
878 } else if (!lp->network_down &&
879 lp->last_recon - lp->first_recon > HZ * 60) {
880 /* reset counters if we've gone for
883 lp->first_recon = lp->last_recon;
887 } else if (lp->network_down &&
888 time_after(jiffies, lp->last_recon + HZ * 10)) {
889 if (lp->network_down)
890 arc_printk(D_NORMAL, dev, "cabling restored?\n");
891 lp->first_recon = lp->last_recon = 0;
892 lp->num_recons = lp->network_down = 0;
894 arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
898 retval |= IRQ_HANDLED;
899 } while (--boguscount && didsomething);
901 arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
902 ASTATUS(), boguscount);
903 arc_printk(D_DURING, dev, "\n");
907 AINTMASK(lp->intmask);
909 spin_unlock(&lp->lock);
912 EXPORT_SYMBOL(arcnet_interrupt);
914 /* This is a generic packet receiver that calls arcnet??_rx depending on the
917 static void arcnet_rx(struct net_device *dev, int bufnum)
919 struct arcnet_local *lp = netdev_priv(dev);
921 struct arc_rfc1201 *soft;
924 soft = &pkt.soft.rfc1201;
926 lp->hw.copy_from_card(dev, bufnum, 0, &pkt, ARC_HDR_SIZE);
927 if (pkt.hard.offset[0]) {
928 ofs = pkt.hard.offset[0];
931 ofs = pkt.hard.offset[1];
935 /* get the full header, if possible */
936 if (sizeof(pkt.soft) <= length) {
937 lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft));
939 memset(&pkt.soft, 0, sizeof(pkt.soft));
940 lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
943 arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
944 bufnum, pkt.hard.source, pkt.hard.dest, length);
946 dev->stats.rx_packets++;
947 dev->stats.rx_bytes += length + ARC_HDR_SIZE;
949 /* call the right receiver for the protocol */
950 if (arc_proto_map[soft->proto]->is_ip) {
951 if (BUGLVL(D_PROTO)) {
953 *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]],
954 *newp = arc_proto_map[soft->proto];
957 arc_printk(D_PROTO, dev,
958 "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
959 soft->proto, pkt.hard.source,
960 newp->suffix, oldp->suffix);
964 /* broadcasts will always be done with the last-used encap. */
965 lp->default_proto[0] = soft->proto;
967 /* in striking contrast, the following isn't a hack. */
968 lp->default_proto[pkt.hard.source] = soft->proto;
970 /* call the protocol-specific receiver. */
971 arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length);
974 static void null_rx(struct net_device *dev, int bufnum,
975 struct archdr *pkthdr, int length)
977 arc_printk(D_PROTO, dev,
978 "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
979 pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
982 static int null_build_header(struct sk_buff *skb, struct net_device *dev,
983 unsigned short type, uint8_t daddr)
985 struct arcnet_local *lp = netdev_priv(dev);
987 arc_printk(D_PROTO, dev,
988 "tx: can't build header for encap %02Xh; load a protocol driver.\n",
989 lp->default_proto[daddr]);
995 /* the "do nothing" prepare_tx function warns that there's nothing to do. */
996 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
997 int length, int bufnum)
999 struct arcnet_local *lp = netdev_priv(dev);
1000 struct arc_hardware newpkt;
1002 arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
1004 /* send a packet to myself -- will never get received, of course */
1005 newpkt.source = newpkt.dest = dev->dev_addr[0];
1007 /* only one byte of actual data (and it's random) */
1008 newpkt.offset[0] = 0xFF;
1010 lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
1012 return 1; /* done */