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.94 BETA 2007/02/08 - by Avery Pennarun et al.\n"
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 printk("arcnet loaded.\n");
120 if (BUGLVL(D_EXTRA)) {
121 printk("arcnet: ***\n"
122 "arcnet: * Read arcnet.txt for important release notes!\n"
124 "arcnet: * This is an ALPHA version! (Last stable release: v3.02) E-mail\n"
125 "arcnet: * me if you have any questions, comments, or bug reports.\n"
130 /* initialize the protocol map */
131 arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
132 for (count = 0; count < 256; count++)
133 arc_proto_map[count] = arc_proto_default;
135 if (BUGLVL(D_DURING))
136 printk("arcnet: struct sizes: %Zd %Zd %Zd %Zd %Zd\n",
137 sizeof(struct arc_hardware), sizeof(struct arc_rfc1201),
138 sizeof(struct arc_rfc1051), sizeof(struct arc_eth_encap),
139 sizeof(struct archdr));
144 static void __exit arcnet_exit(void)
148 module_init(arcnet_init);
149 module_exit(arcnet_exit);
151 /* Dump the contents of an sk_buff */
152 #if ARCNET_DEBUG_MAX & D_SKB
153 void arcnet_dump_skb(struct net_device *dev,
154 struct sk_buff *skb, char *desc)
158 /* dump the packet */
159 snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc);
160 print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
161 16, 1, skb->data, skb->len, true);
164 EXPORT_SYMBOL(arcnet_dump_skb);
167 /* Dump the contents of an ARCnet buffer */
168 #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
169 static void arcnet_dump_packet(struct net_device *dev, int bufnum,
170 char *desc, int take_arcnet_lock)
172 struct arcnet_local *lp = netdev_priv(dev);
174 unsigned long flags = 0;
175 static uint8_t buf[512];
178 /* hw.copy_from_card expects IRQ context so take the IRQ lock
179 * to keep it single threaded
181 if (take_arcnet_lock)
182 spin_lock_irqsave(&lp->lock, flags);
184 lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
185 if (take_arcnet_lock)
186 spin_unlock_irqrestore(&lp->lock, flags);
188 /* if the offset[0] byte is nonzero, this is a 256-byte packet */
189 length = (buf[2] ? 256 : 512);
191 /* dump the packet */
192 snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc);
193 print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
194 16, 1, buf, length, true);
199 #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
203 /* Unregister a protocol driver from the arc_proto_map. Protocol drivers
204 * are responsible for registering themselves, but the unregister routine
205 * is pretty generic so we'll do it here.
207 void arcnet_unregister_proto(struct ArcProto *proto)
211 if (arc_proto_default == proto)
212 arc_proto_default = &arc_proto_null;
213 if (arc_bcast_proto == proto)
214 arc_bcast_proto = arc_proto_default;
215 if (arc_raw_proto == proto)
216 arc_raw_proto = arc_proto_default;
218 for (count = 0; count < 256; count++) {
219 if (arc_proto_map[count] == proto)
220 arc_proto_map[count] = arc_proto_default;
224 /* Add a buffer to the queue. Only the interrupt handler is allowed to do
225 * this, unless interrupts are disabled.
227 * Note: we don't check for a full queue, since there aren't enough buffers
228 * to more than fill it.
230 static void release_arcbuf(struct net_device *dev, int bufnum)
232 struct arcnet_local *lp = netdev_priv(dev);
235 lp->buf_queue[lp->first_free_buf++] = bufnum;
236 lp->first_free_buf %= 5;
238 if (BUGLVL(D_DURING)) {
239 arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
241 for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
242 arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
243 arc_cont(D_DURING, "\n");
247 /* Get a buffer from the queue.
248 * If this returns -1, there are no buffers available.
250 static int get_arcbuf(struct net_device *dev)
252 struct arcnet_local *lp = netdev_priv(dev);
255 if (!atomic_dec_and_test(&lp->buf_lock)) {
256 /* already in this function */
257 arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
258 lp->buf_lock.counter);
259 } else { /* we can continue */
260 if (lp->next_buf >= 5)
263 if (lp->next_buf == lp->first_free_buf) {
264 arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
266 buf = lp->buf_queue[lp->next_buf++];
271 if (BUGLVL(D_DURING)) {
272 arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
274 for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
275 arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
276 arc_cont(D_DURING, "\n");
279 atomic_inc(&lp->buf_lock);
283 static int choose_mtu(void)
285 int count, mtu = 65535;
287 /* choose the smallest MTU of all available encaps */
288 for (count = 0; count < 256; count++) {
289 if (arc_proto_map[count] != &arc_proto_null &&
290 arc_proto_map[count]->mtu < mtu) {
291 mtu = arc_proto_map[count]->mtu;
295 return mtu == 65535 ? XMTU : mtu;
298 static const struct header_ops arcnet_header_ops = {
299 .create = arcnet_header,
302 static const struct net_device_ops arcnet_netdev_ops = {
303 .ndo_open = arcnet_open,
304 .ndo_stop = arcnet_close,
305 .ndo_start_xmit = arcnet_send_packet,
306 .ndo_tx_timeout = arcnet_timeout,
309 /* Setup a struct device for ARCnet. */
310 static void arcdev_setup(struct net_device *dev)
312 dev->type = ARPHRD_ARCNET;
313 dev->netdev_ops = &arcnet_netdev_ops;
314 dev->header_ops = &arcnet_header_ops;
315 dev->hard_header_len = sizeof(struct archdr);
316 dev->mtu = choose_mtu();
318 dev->addr_len = ARCNET_ALEN;
319 dev->tx_queue_len = 100;
320 dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
321 dev->watchdog_timeo = TX_TIMEOUT;
323 /* New-style flags. */
324 dev->flags = IFF_BROADCAST;
327 struct net_device *alloc_arcdev(const char *name)
329 struct net_device *dev;
331 dev = alloc_netdev(sizeof(struct arcnet_local),
332 name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
335 struct arcnet_local *lp = netdev_priv(dev);
337 spin_lock_init(&lp->lock);
343 /* Open/initialize the board. This is called sometime after booting when
344 * the 'ifconfig' program is run.
346 * This routine should set everything up anew at each open, even registers
347 * that "should" only need to be set once at boot, so that there is
348 * non-reboot way to recover if something goes wrong.
350 int arcnet_open(struct net_device *dev)
352 struct arcnet_local *lp = netdev_priv(dev);
353 int count, newmtu, error;
355 arc_printk(D_INIT, dev, "opened.");
357 if (!try_module_get(lp->hw.owner))
360 if (BUGLVL(D_PROTO)) {
361 arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
362 arc_proto_default->suffix);
363 for (count = 0; count < 256; count++)
364 arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
365 arc_cont(D_PROTO, "\n");
368 arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
370 /* try to put the card in a defined state - if it fails the first
371 * time, actually reset it.
374 if (ARCRESET(0) && ARCRESET(1))
377 newmtu = choose_mtu();
378 if (newmtu < dev->mtu)
381 arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
383 /* autodetect the encapsulation for each host. */
384 memset(lp->default_proto, 0, sizeof(lp->default_proto));
386 /* the broadcast address is special - use the 'bcast' protocol */
387 for (count = 0; count < 256; count++) {
388 if (arc_proto_map[count] == arc_bcast_proto) {
389 lp->default_proto[0] = count;
394 /* initialize buffers */
395 atomic_set(&lp->buf_lock, 1);
397 lp->next_buf = lp->first_free_buf = 0;
398 release_arcbuf(dev, 0);
399 release_arcbuf(dev, 1);
400 release_arcbuf(dev, 2);
401 release_arcbuf(dev, 3);
402 lp->cur_tx = lp->next_tx = -1;
405 lp->rfc1201.sequence = 1;
407 /* bring up the hardware driver */
411 if (dev->dev_addr[0] == 0)
412 arc_printk(D_NORMAL, dev, "WARNING! Station address 00 is reserved for broadcasts!\n");
413 else if (dev->dev_addr[0] == 255)
414 arc_printk(D_NORMAL, dev, "WARNING! Station address FF may confuse DOS networking programs!\n");
416 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
417 if (ASTATUS() & RESETflag) {
418 arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
419 __FILE__, __LINE__, __func__);
420 ACOMMAND(CFLAGScmd | RESETclear);
423 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
424 /* make sure we're ready to receive IRQ's. */
426 udelay(1); /* give it time to set the mask before
427 * we reset it again. (may not even be
430 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
431 lp->intmask = NORXflag | RECONflag;
432 AINTMASK(lp->intmask);
433 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
435 netif_start_queue(dev);
440 module_put(lp->hw.owner);
444 /* The inverse routine to arcnet_open - shuts down the card. */
445 int arcnet_close(struct net_device *dev)
447 struct arcnet_local *lp = netdev_priv(dev);
449 netif_stop_queue(dev);
451 /* flush TX and disable RX */
453 ACOMMAND(NOTXcmd); /* stop transmit */
454 ACOMMAND(NORXcmd); /* disable receive */
457 /* shut down the card */
459 module_put(lp->hw.owner);
463 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
464 unsigned short type, const void *daddr,
465 const void *saddr, unsigned len)
467 const struct arcnet_local *lp = netdev_priv(dev);
468 uint8_t _daddr, proto_num;
469 struct ArcProto *proto;
471 arc_printk(D_DURING, dev,
472 "create header from %d to %d; protocol %d (%Xh); size %u.\n",
473 saddr ? *(uint8_t *)saddr : -1,
474 daddr ? *(uint8_t *)daddr : -1,
477 if (skb->len != 0 && len != skb->len)
478 arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
481 /* Type is host order - ? */
482 if (type == ETH_P_ARCNET) {
483 proto = arc_raw_proto;
484 arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
486 _daddr = daddr ? *(uint8_t *)daddr : 0;
488 /* if the dest addr isn't provided, we can't choose an
489 * encapsulation! Store the packet type (eg. ETH_P_IP)
490 * for now, and we'll push on a real header when we do
493 *(uint16_t *)skb_push(skb, 2) = type;
494 /* XXX: Why not use skb->mac_len? */
495 if (skb->network_header - skb->mac_header != 2)
496 arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! diff (%u) is not 2!\n",
497 skb->network_header - skb->mac_header);
498 return -2; /* return error -- can't transmit yet! */
500 /* otherwise, we can just add the header as usual. */
501 _daddr = *(uint8_t *)daddr;
502 proto_num = lp->default_proto[_daddr];
503 proto = arc_proto_map[proto_num];
504 arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
505 proto_num, proto->suffix);
506 if (proto == &arc_proto_null && arc_bcast_proto != proto) {
507 arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
508 arc_bcast_proto->suffix);
509 proto = arc_bcast_proto;
512 return proto->build_header(skb, dev, type, _daddr);
515 /* Called by the kernel in order to transmit a packet. */
516 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
517 struct net_device *dev)
519 struct arcnet_local *lp = netdev_priv(dev);
521 struct arc_rfc1201 *soft;
522 struct ArcProto *proto;
527 arc_printk(D_DURING, dev,
528 "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
529 ASTATUS(), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
531 pkt = (struct archdr *)skb->data;
532 soft = &pkt->soft.rfc1201;
533 proto = arc_proto_map[soft->proto];
535 arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
536 skb->len, pkt->hard.dest);
538 arcnet_dump_skb(dev, skb, "tx");
540 /* fits in one packet? */
541 if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
542 arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
544 return NETDEV_TX_OK; /* don't try again */
547 /* We're busy transmitting a packet... */
548 netif_stop_queue(dev);
550 spin_lock_irqsave(&lp->lock, flags);
552 if (lp->next_tx == -1)
553 txbuf = get_arcbuf(dev);
558 if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
560 /* done right away and we don't want to acknowledge
561 * the package later - forget about it now
563 dev->stats.tx_bytes += skb->len;
566 /* do it the 'split' way */
567 lp->outgoing.proto = proto;
568 lp->outgoing.skb = skb;
569 lp->outgoing.pkt = pkt;
573 if (proto->continue_tx &&
574 proto->continue_tx(dev, txbuf)) {
575 arc_printk(D_NORMAL, dev,
576 "bug! continue_tx finished the first time! (proto='%c')\n",
580 retval = NETDEV_TX_OK;
583 retval = NETDEV_TX_BUSY;
587 arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
588 __FILE__, __LINE__, __func__, ASTATUS());
589 /* make sure we didn't ignore a TX IRQ while we were in here */
592 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
593 lp->intmask |= TXFREEflag | EXCNAKflag;
594 AINTMASK(lp->intmask);
595 arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
596 __FILE__, __LINE__, __func__, ASTATUS());
598 spin_unlock_irqrestore(&lp->lock, flags);
602 return retval; /* no need to try again */
605 /* Actually start transmitting a packet that was loaded into a buffer
606 * by prepare_tx. This should _only_ be called by the interrupt handler.
608 static int go_tx(struct net_device *dev)
610 struct arcnet_local *lp = netdev_priv(dev);
612 arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
613 ASTATUS(), lp->intmask, lp->next_tx, lp->cur_tx);
615 if (lp->cur_tx != -1 || lp->next_tx == -1)
619 arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
621 lp->cur_tx = lp->next_tx;
625 ACOMMAND(TXcmd | (lp->cur_tx << 3));
627 dev->stats.tx_packets++;
628 lp->lasttrans_dest = lp->lastload_dest;
629 lp->lastload_dest = 0;
630 lp->excnak_pending = 0;
631 lp->intmask |= TXFREEflag | EXCNAKflag;
636 /* Called by the kernel when transmit times out */
637 void arcnet_timeout(struct net_device *dev)
640 struct arcnet_local *lp = netdev_priv(dev);
641 int status = ASTATUS();
644 spin_lock_irqsave(&lp->lock, flags);
645 if (status & TXFREEflag) { /* transmit _DID_ finish */
646 msg = " - missed IRQ?";
649 dev->stats.tx_aborted_errors++;
651 ACOMMAND(NOTXcmd | (lp->cur_tx << 3));
653 dev->stats.tx_errors++;
655 /* make sure we didn't miss a TX or a EXC NAK IRQ */
657 lp->intmask |= TXFREEflag | EXCNAKflag;
658 AINTMASK(lp->intmask);
660 spin_unlock_irqrestore(&lp->lock, flags);
662 if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
663 arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
664 msg, status, lp->intmask, lp->lasttrans_dest);
665 lp->last_timeout = jiffies;
668 if (lp->cur_tx == -1)
669 netif_wake_queue(dev);
672 /* The typical workload of the driver: Handle the network interface
673 * interrupts. Establish which device needs attention, and call the correct
674 * chipset interrupt handler.
676 irqreturn_t arcnet_interrupt(int irq, void *dev_id)
678 struct net_device *dev = dev_id;
679 struct arcnet_local *lp;
680 int recbuf, status, diagstatus, didsomething, boguscount;
681 int retval = IRQ_NONE;
683 arc_printk(D_DURING, dev, "\n");
685 arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
687 lp = netdev_priv(dev);
690 spin_lock(&lp->lock);
692 /* RESET flag was enabled - if device is not running, we must
693 * clear it right away (but nothing else).
695 if (!netif_running(dev)) {
696 if (ASTATUS() & RESETflag)
697 ACOMMAND(CFLAGScmd | RESETclear);
699 spin_unlock(&lp->lock);
703 arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
704 ASTATUS(), lp->intmask);
709 diagstatus = (status >> 8) & 0xFF;
711 arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
712 __FILE__, __LINE__, __func__, status);
715 /* RESET flag was enabled - card is resetting and if RX is
716 * disabled, it's NOT because we just got a packet.
718 * The card is in an undefined state.
719 * Clear it out and start over.
721 if (status & RESETflag) {
722 arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
727 /* get out of the interrupt handler! */
730 /* RX is inhibited - we must have received something.
731 * Prepare to receive into the next buffer.
733 * We don't actually copy the received packet from the card
734 * until after the transmit handler runs (and possibly
735 * launches the next tx); this should improve latency slightly
736 * if we get both types of interrupts at once.
739 if (status & lp->intmask & NORXflag) {
741 arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
744 lp->cur_rx = get_arcbuf(dev);
745 if (lp->cur_rx != -1) {
746 arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
748 ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts);
753 if ((diagstatus & EXCNAKflag)) {
754 arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
757 ACOMMAND(NOTXcmd); /* disable transmit */
758 lp->excnak_pending = 1;
760 ACOMMAND(EXCNAKclear);
761 lp->intmask &= ~(EXCNAKflag);
765 /* a transmit finished, and we're interested in it. */
766 if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
767 lp->intmask &= ~(TXFREEflag | EXCNAKflag);
769 arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n", status);
771 if (lp->cur_tx != -1 && !lp->timed_out) {
772 if (!(status & TXACKflag)) {
773 if (lp->lasttrans_dest != 0) {
774 arc_printk(D_EXTRA, dev,
775 "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
778 dev->stats.tx_errors++;
779 dev->stats.tx_carrier_errors++;
781 arc_printk(D_DURING, dev,
782 "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
788 if (lp->outgoing.proto &&
789 lp->outgoing.proto->ack_tx) {
792 if (status & TXACKflag)
794 else if (lp->excnak_pending)
800 ->ack_tx(dev, ackstatus);
803 if (lp->cur_tx != -1)
804 release_arcbuf(dev, lp->cur_tx);
810 /* send another packet if there is one */
813 /* continue a split packet, if any */
814 if (lp->outgoing.proto && lp->outgoing.proto->continue_tx) {
815 int txbuf = get_arcbuf(dev);
818 if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
819 /* that was the last segment */
820 dev->stats.tx_bytes += lp->outgoing.skb->len;
821 if (!lp->outgoing.proto->ack_tx) {
822 dev_kfree_skb_irq(lp->outgoing.skb);
823 lp->outgoing.proto = NULL;
829 /* inform upper layers of idleness, if necessary */
830 if (lp->cur_tx == -1)
831 netif_wake_queue(dev);
833 /* now process the received packet, if any */
836 arcnet_dump_packet(dev, recbuf, "rx irq", 0);
838 arcnet_rx(dev, recbuf);
839 release_arcbuf(dev, recbuf);
843 if (status & lp->intmask & RECONflag) {
844 ACOMMAND(CFLAGScmd | CONFIGclear);
845 dev->stats.tx_carrier_errors++;
847 arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
849 /* MYRECON bit is at bit 7 of diagstatus */
850 if (diagstatus & 0x80)
851 arc_printk(D_RECON, dev, "Put out that recon myself\n");
853 /* is the RECON info empty or old? */
854 if (!lp->first_recon || !lp->last_recon ||
855 time_after(jiffies, lp->last_recon + HZ * 10)) {
856 if (lp->network_down)
857 arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
858 lp->first_recon = lp->last_recon = jiffies;
859 lp->num_recons = lp->network_down = 0;
861 arc_printk(D_DURING, dev, "recon: clearing counters.\n");
862 } else { /* add to current RECON counter */
863 lp->last_recon = jiffies;
866 arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
868 (lp->last_recon - lp->first_recon) / HZ,
871 /* if network is marked up;
872 * and first_recon and last_recon are 60+ apart;
873 * and the average no. of recons counted is
874 * > RECON_THRESHOLD/min;
875 * then print a warning message.
877 if (!lp->network_down &&
878 (lp->last_recon - lp->first_recon) <= HZ * 60 &&
879 lp->num_recons >= RECON_THRESHOLD) {
880 lp->network_down = 1;
881 arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
882 } else if (!lp->network_down &&
883 lp->last_recon - lp->first_recon > HZ * 60) {
884 /* reset counters if we've gone for over a minute. */
885 lp->first_recon = lp->last_recon;
889 } else if (lp->network_down &&
890 time_after(jiffies, lp->last_recon + HZ * 10)) {
891 if (lp->network_down)
892 arc_printk(D_NORMAL, dev, "cabling restored?\n");
893 lp->first_recon = lp->last_recon = 0;
894 lp->num_recons = lp->network_down = 0;
896 arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
900 retval |= IRQ_HANDLED;
901 } while (--boguscount && didsomething);
903 arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
904 ASTATUS(), boguscount);
905 arc_printk(D_DURING, dev, "\n");
909 AINTMASK(lp->intmask);
911 spin_unlock(&lp->lock);
915 /* This is a generic packet receiver that calls arcnet??_rx depending on the
918 static void arcnet_rx(struct net_device *dev, int bufnum)
920 struct arcnet_local *lp = netdev_priv(dev);
922 struct arc_rfc1201 *soft;
925 soft = &pkt.soft.rfc1201;
927 lp->hw.copy_from_card(dev, bufnum, 0, &pkt, ARC_HDR_SIZE);
928 if (pkt.hard.offset[0]) {
929 ofs = pkt.hard.offset[0];
932 ofs = pkt.hard.offset[1];
936 /* get the full header, if possible */
937 if (sizeof(pkt.soft) <= length) {
938 lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft));
940 memset(&pkt.soft, 0, sizeof(pkt.soft));
941 lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
944 arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
945 bufnum, pkt.hard.source, pkt.hard.dest, length);
947 dev->stats.rx_packets++;
948 dev->stats.rx_bytes += length + ARC_HDR_SIZE;
950 /* call the right receiver for the protocol */
951 if (arc_proto_map[soft->proto]->is_ip) {
952 if (BUGLVL(D_PROTO)) {
954 *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]],
955 *newp = arc_proto_map[soft->proto];
958 arc_printk(D_PROTO, dev,
959 "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
960 soft->proto, pkt.hard.source,
961 newp->suffix, oldp->suffix);
965 /* broadcasts will always be done with the last-used encap. */
966 lp->default_proto[0] = soft->proto;
968 /* in striking contrast, the following isn't a hack. */
969 lp->default_proto[pkt.hard.source] = soft->proto;
971 /* call the protocol-specific receiver. */
972 arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length);
975 static void null_rx(struct net_device *dev, int bufnum,
976 struct archdr *pkthdr, int length)
978 arc_printk(D_PROTO, dev,
979 "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
980 pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
983 static int null_build_header(struct sk_buff *skb, struct net_device *dev,
984 unsigned short type, uint8_t daddr)
986 struct arcnet_local *lp = netdev_priv(dev);
988 arc_printk(D_PROTO, dev,
989 "tx: can't build header for encap %02Xh; load a protocol driver.\n",
990 lp->default_proto[daddr]);
996 /* the "do nothing" prepare_tx function warns that there's nothing to do. */
997 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
998 int length, int bufnum)
1000 struct arcnet_local *lp = netdev_priv(dev);
1001 struct arc_hardware newpkt;
1003 arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
1005 /* send a packet to myself -- will never get received, of course */
1006 newpkt.source = newpkt.dest = dev->dev_addr[0];
1008 /* only one byte of actual data (and it's random) */
1009 newpkt.offset[0] = 0xFF;
1011 lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
1013 return 1; /* done */