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/arcdevice.h>
54 #include <linux/jiffies.h>
56 /* "do nothing" functions for protocol drivers */
57 static void null_rx(struct net_device *dev, int bufnum,
58 struct archdr *pkthdr, int length);
59 static int null_build_header(struct sk_buff *skb, struct net_device *dev,
60 unsigned short type, uint8_t daddr);
61 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
62 int length, int bufnum);
64 static void arcnet_rx(struct net_device *dev, int bufnum);
66 /* one ArcProto per possible proto ID. None of the elements of
67 * arc_proto_map are allowed to be NULL; they will get set to
68 * arc_proto_default instead. It also must not be NULL; if you would like
69 * to set it to NULL, set it to &arc_proto_null instead.
71 struct ArcProto *arc_proto_map[256], *arc_proto_default,
72 *arc_bcast_proto, *arc_raw_proto;
74 static struct ArcProto arc_proto_null = {
79 .build_header = null_build_header,
80 .prepare_tx = null_prepare_tx,
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_raw_proto);
92 EXPORT_SYMBOL(arcnet_unregister_proto);
93 EXPORT_SYMBOL(arcnet_debug);
94 EXPORT_SYMBOL(alloc_arcdev);
95 EXPORT_SYMBOL(arcnet_interrupt);
96 EXPORT_SYMBOL(arcnet_open);
97 EXPORT_SYMBOL(arcnet_close);
98 EXPORT_SYMBOL(arcnet_send_packet);
99 EXPORT_SYMBOL(arcnet_timeout);
101 /* Internal function prototypes */
102 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
103 unsigned short type, const void *daddr,
104 const void *saddr, unsigned len);
105 static int go_tx(struct net_device *dev);
107 static int debug = ARCNET_DEBUG;
108 module_param(debug, int, 0);
109 MODULE_LICENSE("GPL");
111 static int __init arcnet_init(void)
115 arcnet_debug = debug;
117 pr_info("arcnet loaded\n");
119 /* initialize the protocol map */
120 arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
121 for (count = 0; count < 256; count++)
122 arc_proto_map[count] = arc_proto_default;
124 if (BUGLVL(D_DURING))
125 pr_info("struct sizes: %Zd %Zd %Zd %Zd %Zd\n",
126 sizeof(struct arc_hardware),
127 sizeof(struct arc_rfc1201),
128 sizeof(struct arc_rfc1051),
129 sizeof(struct arc_eth_encap),
130 sizeof(struct archdr));
135 static void __exit arcnet_exit(void)
139 module_init(arcnet_init);
140 module_exit(arcnet_exit);
142 /* Dump the contents of an sk_buff */
143 #if ARCNET_DEBUG_MAX & D_SKB
144 void arcnet_dump_skb(struct net_device *dev,
145 struct sk_buff *skb, char *desc)
149 /* dump the packet */
150 snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc);
151 print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
152 16, 1, skb->data, skb->len, true);
155 EXPORT_SYMBOL(arcnet_dump_skb);
158 /* Dump the contents of an ARCnet buffer */
159 #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
160 static void arcnet_dump_packet(struct net_device *dev, int bufnum,
161 char *desc, int take_arcnet_lock)
163 struct arcnet_local *lp = netdev_priv(dev);
165 unsigned long flags = 0;
166 static uint8_t buf[512];
169 /* hw.copy_from_card expects IRQ context so take the IRQ lock
170 * to keep it single threaded
172 if (take_arcnet_lock)
173 spin_lock_irqsave(&lp->lock, flags);
175 lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
176 if (take_arcnet_lock)
177 spin_unlock_irqrestore(&lp->lock, flags);
179 /* if the offset[0] byte is nonzero, this is a 256-byte packet */
180 length = (buf[2] ? 256 : 512);
182 /* dump the packet */
183 snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc);
184 print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
185 16, 1, buf, length, true);
190 #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
194 /* Unregister a protocol driver from the arc_proto_map. Protocol drivers
195 * are responsible for registering themselves, but the unregister routine
196 * is pretty generic so we'll do it here.
198 void arcnet_unregister_proto(struct ArcProto *proto)
202 if (arc_proto_default == proto)
203 arc_proto_default = &arc_proto_null;
204 if (arc_bcast_proto == proto)
205 arc_bcast_proto = arc_proto_default;
206 if (arc_raw_proto == proto)
207 arc_raw_proto = arc_proto_default;
209 for (count = 0; count < 256; count++) {
210 if (arc_proto_map[count] == proto)
211 arc_proto_map[count] = arc_proto_default;
215 /* Add a buffer to the queue. Only the interrupt handler is allowed to do
216 * this, unless interrupts are disabled.
218 * Note: we don't check for a full queue, since there aren't enough buffers
219 * to more than fill it.
221 static void release_arcbuf(struct net_device *dev, int bufnum)
223 struct arcnet_local *lp = netdev_priv(dev);
226 lp->buf_queue[lp->first_free_buf++] = bufnum;
227 lp->first_free_buf %= 5;
229 if (BUGLVL(D_DURING)) {
230 arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
232 for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
233 arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
234 arc_cont(D_DURING, "\n");
238 /* Get a buffer from the queue.
239 * If this returns -1, there are no buffers available.
241 static int get_arcbuf(struct net_device *dev)
243 struct arcnet_local *lp = netdev_priv(dev);
246 if (!atomic_dec_and_test(&lp->buf_lock)) {
247 /* already in this function */
248 arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
249 lp->buf_lock.counter);
250 } else { /* we can continue */
251 if (lp->next_buf >= 5)
254 if (lp->next_buf == lp->first_free_buf) {
255 arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
257 buf = lp->buf_queue[lp->next_buf++];
262 if (BUGLVL(D_DURING)) {
263 arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
265 for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
266 arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
267 arc_cont(D_DURING, "\n");
270 atomic_inc(&lp->buf_lock);
274 static int choose_mtu(void)
276 int count, mtu = 65535;
278 /* choose the smallest MTU of all available encaps */
279 for (count = 0; count < 256; count++) {
280 if (arc_proto_map[count] != &arc_proto_null &&
281 arc_proto_map[count]->mtu < mtu) {
282 mtu = arc_proto_map[count]->mtu;
286 return mtu == 65535 ? XMTU : mtu;
289 static const struct header_ops arcnet_header_ops = {
290 .create = arcnet_header,
293 static const struct net_device_ops arcnet_netdev_ops = {
294 .ndo_open = arcnet_open,
295 .ndo_stop = arcnet_close,
296 .ndo_start_xmit = arcnet_send_packet,
297 .ndo_tx_timeout = arcnet_timeout,
300 /* Setup a struct device for ARCnet. */
301 static void arcdev_setup(struct net_device *dev)
303 dev->type = ARPHRD_ARCNET;
304 dev->netdev_ops = &arcnet_netdev_ops;
305 dev->header_ops = &arcnet_header_ops;
306 dev->hard_header_len = sizeof(struct archdr);
307 dev->mtu = choose_mtu();
309 dev->addr_len = ARCNET_ALEN;
310 dev->tx_queue_len = 100;
311 dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
312 dev->watchdog_timeo = TX_TIMEOUT;
314 /* New-style flags. */
315 dev->flags = IFF_BROADCAST;
318 struct net_device *alloc_arcdev(const char *name)
320 struct net_device *dev;
322 dev = alloc_netdev(sizeof(struct arcnet_local),
323 name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
326 struct arcnet_local *lp = netdev_priv(dev);
328 spin_lock_init(&lp->lock);
334 /* Open/initialize the board. This is called sometime after booting when
335 * the 'ifconfig' program is run.
337 * This routine should set everything up anew at each open, even registers
338 * that "should" only need to be set once at boot, so that there is
339 * non-reboot way to recover if something goes wrong.
341 int arcnet_open(struct net_device *dev)
343 struct arcnet_local *lp = netdev_priv(dev);
344 int count, newmtu, error;
346 arc_printk(D_INIT, dev, "opened.");
348 if (!try_module_get(lp->hw.owner))
351 if (BUGLVL(D_PROTO)) {
352 arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
353 arc_proto_default->suffix);
354 for (count = 0; count < 256; count++)
355 arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
356 arc_cont(D_PROTO, "\n");
359 arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
361 /* try to put the card in a defined state - if it fails the first
362 * time, actually reset it.
365 if (ARCRESET(0) && ARCRESET(1))
368 newmtu = choose_mtu();
369 if (newmtu < dev->mtu)
372 arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
374 /* autodetect the encapsulation for each host. */
375 memset(lp->default_proto, 0, sizeof(lp->default_proto));
377 /* the broadcast address is special - use the 'bcast' protocol */
378 for (count = 0; count < 256; count++) {
379 if (arc_proto_map[count] == arc_bcast_proto) {
380 lp->default_proto[0] = count;
385 /* initialize buffers */
386 atomic_set(&lp->buf_lock, 1);
388 lp->next_buf = lp->first_free_buf = 0;
389 release_arcbuf(dev, 0);
390 release_arcbuf(dev, 1);
391 release_arcbuf(dev, 2);
392 release_arcbuf(dev, 3);
393 lp->cur_tx = lp->next_tx = -1;
396 lp->rfc1201.sequence = 1;
398 /* bring up the hardware driver */
402 if (dev->dev_addr[0] == 0)
403 arc_printk(D_NORMAL, dev, "WARNING! Station address 00 is reserved for broadcasts!\n");
404 else if (dev->dev_addr[0] == 255)
405 arc_printk(D_NORMAL, dev, "WARNING! Station address FF may confuse DOS networking programs!\n");
407 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
408 if (ASTATUS() & RESETflag) {
409 arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
410 __FILE__, __LINE__, __func__);
411 ACOMMAND(CFLAGScmd | RESETclear);
414 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
415 /* make sure we're ready to receive IRQ's. */
417 udelay(1); /* give it time to set the mask before
418 * we reset it again. (may not even be
421 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
422 lp->intmask = NORXflag | RECONflag;
423 AINTMASK(lp->intmask);
424 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
426 netif_start_queue(dev);
431 module_put(lp->hw.owner);
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);
454 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
455 unsigned short type, const void *daddr,
456 const void *saddr, unsigned len)
458 const struct arcnet_local *lp = netdev_priv(dev);
459 uint8_t _daddr, proto_num;
460 struct ArcProto *proto;
462 arc_printk(D_DURING, dev,
463 "create header from %d to %d; protocol %d (%Xh); size %u.\n",
464 saddr ? *(uint8_t *)saddr : -1,
465 daddr ? *(uint8_t *)daddr : -1,
468 if (skb->len != 0 && len != skb->len)
469 arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
472 /* Type is host order - ? */
473 if (type == ETH_P_ARCNET) {
474 proto = arc_raw_proto;
475 arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
477 _daddr = daddr ? *(uint8_t *)daddr : 0;
479 /* if the dest addr isn't provided, we can't choose an
480 * encapsulation! Store the packet type (eg. ETH_P_IP)
481 * for now, and we'll push on a real header when we do
484 *(uint16_t *)skb_push(skb, 2) = type;
485 /* XXX: Why not use skb->mac_len? */
486 if (skb->network_header - skb->mac_header != 2)
487 arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! diff (%u) is not 2!\n",
488 skb->network_header - skb->mac_header);
489 return -2; /* return error -- can't transmit yet! */
491 /* otherwise, we can just add the header as usual. */
492 _daddr = *(uint8_t *)daddr;
493 proto_num = lp->default_proto[_daddr];
494 proto = arc_proto_map[proto_num];
495 arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
496 proto_num, proto->suffix);
497 if (proto == &arc_proto_null && arc_bcast_proto != proto) {
498 arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
499 arc_bcast_proto->suffix);
500 proto = arc_bcast_proto;
503 return proto->build_header(skb, dev, type, _daddr);
506 /* Called by the kernel in order to transmit a packet. */
507 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
508 struct net_device *dev)
510 struct arcnet_local *lp = netdev_priv(dev);
512 struct arc_rfc1201 *soft;
513 struct ArcProto *proto;
518 arc_printk(D_DURING, dev,
519 "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
520 ASTATUS(), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
522 pkt = (struct archdr *)skb->data;
523 soft = &pkt->soft.rfc1201;
524 proto = arc_proto_map[soft->proto];
526 arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
527 skb->len, pkt->hard.dest);
529 arcnet_dump_skb(dev, skb, "tx");
531 /* fits in one packet? */
532 if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
533 arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
535 return NETDEV_TX_OK; /* don't try again */
538 /* We're busy transmitting a packet... */
539 netif_stop_queue(dev);
541 spin_lock_irqsave(&lp->lock, flags);
543 if (lp->next_tx == -1)
544 txbuf = get_arcbuf(dev);
549 if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
551 /* done right away and we don't want to acknowledge
552 * the package later - forget about it now
554 dev->stats.tx_bytes += skb->len;
557 /* do it the 'split' way */
558 lp->outgoing.proto = proto;
559 lp->outgoing.skb = skb;
560 lp->outgoing.pkt = pkt;
564 if (proto->continue_tx &&
565 proto->continue_tx(dev, txbuf)) {
566 arc_printk(D_NORMAL, dev,
567 "bug! continue_tx finished the first time! (proto='%c')\n",
571 retval = NETDEV_TX_OK;
574 retval = NETDEV_TX_BUSY;
578 arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
579 __FILE__, __LINE__, __func__, ASTATUS());
580 /* make sure we didn't ignore a TX IRQ while we were in here */
583 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
584 lp->intmask |= TXFREEflag | EXCNAKflag;
585 AINTMASK(lp->intmask);
586 arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
587 __FILE__, __LINE__, __func__, ASTATUS());
589 spin_unlock_irqrestore(&lp->lock, flags);
593 return retval; /* no need to try again */
596 /* Actually start transmitting a packet that was loaded into a buffer
597 * by prepare_tx. This should _only_ be called by the interrupt handler.
599 static int go_tx(struct net_device *dev)
601 struct arcnet_local *lp = netdev_priv(dev);
603 arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
604 ASTATUS(), lp->intmask, lp->next_tx, lp->cur_tx);
606 if (lp->cur_tx != -1 || lp->next_tx == -1)
610 arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
612 lp->cur_tx = lp->next_tx;
616 ACOMMAND(TXcmd | (lp->cur_tx << 3));
618 dev->stats.tx_packets++;
619 lp->lasttrans_dest = lp->lastload_dest;
620 lp->lastload_dest = 0;
621 lp->excnak_pending = 0;
622 lp->intmask |= TXFREEflag | EXCNAKflag;
627 /* Called by the kernel when transmit times out */
628 void arcnet_timeout(struct net_device *dev)
631 struct arcnet_local *lp = netdev_priv(dev);
632 int status = ASTATUS();
635 spin_lock_irqsave(&lp->lock, flags);
636 if (status & TXFREEflag) { /* transmit _DID_ finish */
637 msg = " - missed IRQ?";
640 dev->stats.tx_aborted_errors++;
642 ACOMMAND(NOTXcmd | (lp->cur_tx << 3));
644 dev->stats.tx_errors++;
646 /* make sure we didn't miss a TX or a EXC NAK IRQ */
648 lp->intmask |= TXFREEflag | EXCNAKflag;
649 AINTMASK(lp->intmask);
651 spin_unlock_irqrestore(&lp->lock, flags);
653 if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
654 arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
655 msg, status, lp->intmask, lp->lasttrans_dest);
656 lp->last_timeout = jiffies;
659 if (lp->cur_tx == -1)
660 netif_wake_queue(dev);
663 /* The typical workload of the driver: Handle the network interface
664 * interrupts. Establish which device needs attention, and call the correct
665 * chipset interrupt handler.
667 irqreturn_t arcnet_interrupt(int irq, void *dev_id)
669 struct net_device *dev = dev_id;
670 struct arcnet_local *lp;
671 int recbuf, status, diagstatus, didsomething, boguscount;
672 int retval = IRQ_NONE;
674 arc_printk(D_DURING, dev, "\n");
676 arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
678 lp = netdev_priv(dev);
681 spin_lock(&lp->lock);
683 /* RESET flag was enabled - if device is not running, we must
684 * clear it right away (but nothing else).
686 if (!netif_running(dev)) {
687 if (ASTATUS() & RESETflag)
688 ACOMMAND(CFLAGScmd | RESETclear);
690 spin_unlock(&lp->lock);
694 arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
695 ASTATUS(), lp->intmask);
700 diagstatus = (status >> 8) & 0xFF;
702 arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
703 __FILE__, __LINE__, __func__, status);
706 /* RESET flag was enabled - card is resetting and if RX is
707 * disabled, it's NOT because we just got a packet.
709 * The card is in an undefined state.
710 * Clear it out and start over.
712 if (status & RESETflag) {
713 arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
718 /* get out of the interrupt handler! */
721 /* RX is inhibited - we must have received something.
722 * Prepare to receive into the next buffer.
724 * We don't actually copy the received packet from the card
725 * until after the transmit handler runs (and possibly
726 * launches the next tx); this should improve latency slightly
727 * if we get both types of interrupts at once.
730 if (status & lp->intmask & NORXflag) {
732 arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
735 lp->cur_rx = get_arcbuf(dev);
736 if (lp->cur_rx != -1) {
737 arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
739 ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts);
744 if ((diagstatus & EXCNAKflag)) {
745 arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
748 ACOMMAND(NOTXcmd); /* disable transmit */
749 lp->excnak_pending = 1;
751 ACOMMAND(EXCNAKclear);
752 lp->intmask &= ~(EXCNAKflag);
756 /* a transmit finished, and we're interested in it. */
757 if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
758 lp->intmask &= ~(TXFREEflag | EXCNAKflag);
760 arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n", status);
762 if (lp->cur_tx != -1 && !lp->timed_out) {
763 if (!(status & TXACKflag)) {
764 if (lp->lasttrans_dest != 0) {
765 arc_printk(D_EXTRA, dev,
766 "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
769 dev->stats.tx_errors++;
770 dev->stats.tx_carrier_errors++;
772 arc_printk(D_DURING, dev,
773 "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
779 if (lp->outgoing.proto &&
780 lp->outgoing.proto->ack_tx) {
783 if (status & TXACKflag)
785 else if (lp->excnak_pending)
791 ->ack_tx(dev, ackstatus);
794 if (lp->cur_tx != -1)
795 release_arcbuf(dev, lp->cur_tx);
801 /* send another packet if there is one */
804 /* continue a split packet, if any */
805 if (lp->outgoing.proto && lp->outgoing.proto->continue_tx) {
806 int txbuf = get_arcbuf(dev);
809 if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
810 /* that was the last segment */
811 dev->stats.tx_bytes += lp->outgoing.skb->len;
812 if (!lp->outgoing.proto->ack_tx) {
813 dev_kfree_skb_irq(lp->outgoing.skb);
814 lp->outgoing.proto = NULL;
820 /* inform upper layers of idleness, if necessary */
821 if (lp->cur_tx == -1)
822 netif_wake_queue(dev);
824 /* now process the received packet, if any */
827 arcnet_dump_packet(dev, recbuf, "rx irq", 0);
829 arcnet_rx(dev, recbuf);
830 release_arcbuf(dev, recbuf);
834 if (status & lp->intmask & RECONflag) {
835 ACOMMAND(CFLAGScmd | CONFIGclear);
836 dev->stats.tx_carrier_errors++;
838 arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
840 /* MYRECON bit is at bit 7 of diagstatus */
841 if (diagstatus & 0x80)
842 arc_printk(D_RECON, dev, "Put out that recon myself\n");
844 /* is the RECON info empty or old? */
845 if (!lp->first_recon || !lp->last_recon ||
846 time_after(jiffies, lp->last_recon + HZ * 10)) {
847 if (lp->network_down)
848 arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
849 lp->first_recon = lp->last_recon = jiffies;
850 lp->num_recons = lp->network_down = 0;
852 arc_printk(D_DURING, dev, "recon: clearing counters.\n");
853 } else { /* add to current RECON counter */
854 lp->last_recon = jiffies;
857 arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
859 (lp->last_recon - lp->first_recon) / HZ,
862 /* if network is marked up;
863 * and first_recon and last_recon are 60+ apart;
864 * and the average no. of recons counted is
865 * > RECON_THRESHOLD/min;
866 * then print a warning message.
868 if (!lp->network_down &&
869 (lp->last_recon - lp->first_recon) <= HZ * 60 &&
870 lp->num_recons >= RECON_THRESHOLD) {
871 lp->network_down = 1;
872 arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
873 } else if (!lp->network_down &&
874 lp->last_recon - lp->first_recon > HZ * 60) {
875 /* reset counters if we've gone for over a minute. */
876 lp->first_recon = lp->last_recon;
880 } else if (lp->network_down &&
881 time_after(jiffies, lp->last_recon + HZ * 10)) {
882 if (lp->network_down)
883 arc_printk(D_NORMAL, dev, "cabling restored?\n");
884 lp->first_recon = lp->last_recon = 0;
885 lp->num_recons = lp->network_down = 0;
887 arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
891 retval |= IRQ_HANDLED;
892 } while (--boguscount && didsomething);
894 arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
895 ASTATUS(), boguscount);
896 arc_printk(D_DURING, dev, "\n");
900 AINTMASK(lp->intmask);
902 spin_unlock(&lp->lock);
906 /* This is a generic packet receiver that calls arcnet??_rx depending on the
909 static void arcnet_rx(struct net_device *dev, int bufnum)
911 struct arcnet_local *lp = netdev_priv(dev);
913 struct arc_rfc1201 *soft;
916 soft = &pkt.soft.rfc1201;
918 lp->hw.copy_from_card(dev, bufnum, 0, &pkt, ARC_HDR_SIZE);
919 if (pkt.hard.offset[0]) {
920 ofs = pkt.hard.offset[0];
923 ofs = pkt.hard.offset[1];
927 /* get the full header, if possible */
928 if (sizeof(pkt.soft) <= length) {
929 lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft));
931 memset(&pkt.soft, 0, sizeof(pkt.soft));
932 lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
935 arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
936 bufnum, pkt.hard.source, pkt.hard.dest, length);
938 dev->stats.rx_packets++;
939 dev->stats.rx_bytes += length + ARC_HDR_SIZE;
941 /* call the right receiver for the protocol */
942 if (arc_proto_map[soft->proto]->is_ip) {
943 if (BUGLVL(D_PROTO)) {
945 *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]],
946 *newp = arc_proto_map[soft->proto];
949 arc_printk(D_PROTO, dev,
950 "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
951 soft->proto, pkt.hard.source,
952 newp->suffix, oldp->suffix);
956 /* broadcasts will always be done with the last-used encap. */
957 lp->default_proto[0] = soft->proto;
959 /* in striking contrast, the following isn't a hack. */
960 lp->default_proto[pkt.hard.source] = soft->proto;
962 /* call the protocol-specific receiver. */
963 arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length);
966 static void null_rx(struct net_device *dev, int bufnum,
967 struct archdr *pkthdr, int length)
969 arc_printk(D_PROTO, dev,
970 "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
971 pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
974 static int null_build_header(struct sk_buff *skb, struct net_device *dev,
975 unsigned short type, uint8_t daddr)
977 struct arcnet_local *lp = netdev_priv(dev);
979 arc_printk(D_PROTO, dev,
980 "tx: can't build header for encap %02Xh; load a protocol driver.\n",
981 lp->default_proto[daddr]);
987 /* the "do nothing" prepare_tx function warns that there's nothing to do. */
988 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
989 int length, int bufnum)
991 struct arcnet_local *lp = netdev_priv(dev);
992 struct arc_hardware newpkt;
994 arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
996 /* send a packet to myself -- will never get received, of course */
997 newpkt.source = newpkt.dest = dev->dev_addr[0];
999 /* only one byte of actual data (and it's random) */
1000 newpkt.offset[0] = 0xFF;
1002 lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
1004 return 1; /* done */