Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Linux ARCnet driver - device-independent routines
0003  *
0004  * Written 1997 by David Woodhouse.
0005  * Written 1994-1999 by Avery Pennarun.
0006  * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
0007  * Derived from skeleton.c by Donald Becker.
0008  *
0009  * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
0010  *  for sponsoring the further development of this driver.
0011  *
0012  * **********************
0013  *
0014  * The original copyright was as follows:
0015  *
0016  * skeleton.c Written 1993 by Donald Becker.
0017  * Copyright 1993 United States Government as represented by the
0018  * Director, National Security Agency.  This software may only be used
0019  * and distributed according to the terms of the GNU General Public License as
0020  * modified by SRC, incorporated herein by reference.
0021  *
0022  * **********************
0023  *
0024  * The change log is now in a file called ChangeLog in this directory.
0025  *
0026  * Sources:
0027  *  - Crynwr arcnet.com/arcether.com packet drivers.
0028  *  - arcnet.c v0.00 dated 1/1/94 and apparently by
0029  *     Donald Becker - it didn't work :)
0030  *  - skeleton.c v0.05 dated 11/16/93 by Donald Becker
0031  *     (from Linux Kernel 1.1.45)
0032  *  - RFC's 1201 and 1051 - re: TCP/IP over ARCnet
0033  *  - The official ARCnet COM9026 data sheets (!) thanks to
0034  *     Ken Cornetet <kcornete@nyx10.cs.du.edu>
0035  *  - The official ARCnet COM20020 data sheets.
0036  *  - Information on some more obscure ARCnet controller chips, thanks
0037  *     to the nice people at SMSC.
0038  *  - net/inet/eth.c (from kernel 1.1.50) for header-building info.
0039  *  - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
0040  *  - Textual information and more alternate source from Joachim Koenig
0041  *     <jojo@repas.de>
0042  */
0043 
0044 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0045 
0046 #include <linux/module.h>
0047 #include <linux/types.h>
0048 #include <linux/delay.h>
0049 #include <linux/netdevice.h>
0050 #include <linux/if_arp.h>
0051 #include <net/arp.h>
0052 #include <linux/init.h>
0053 #include <linux/jiffies.h>
0054 #include <linux/errqueue.h>
0055 
0056 #include <linux/leds.h>
0057 
0058 #include "arcdevice.h"
0059 #include "com9026.h"
0060 
0061 /* "do nothing" functions for protocol drivers */
0062 static void null_rx(struct net_device *dev, int bufnum,
0063             struct archdr *pkthdr, int length);
0064 static int null_build_header(struct sk_buff *skb, struct net_device *dev,
0065                  unsigned short type, uint8_t daddr);
0066 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
0067                int length, int bufnum);
0068 
0069 static void arcnet_rx(struct net_device *dev, int bufnum);
0070 
0071 /* one ArcProto per possible proto ID.  None of the elements of
0072  * arc_proto_map are allowed to be NULL; they will get set to
0073  * arc_proto_default instead.  It also must not be NULL; if you would like
0074  * to set it to NULL, set it to &arc_proto_null instead.
0075  */
0076 struct ArcProto *arc_proto_map[256];
0077 EXPORT_SYMBOL(arc_proto_map);
0078 
0079 struct ArcProto *arc_proto_default;
0080 EXPORT_SYMBOL(arc_proto_default);
0081 
0082 struct ArcProto *arc_bcast_proto;
0083 EXPORT_SYMBOL(arc_bcast_proto);
0084 
0085 struct ArcProto *arc_raw_proto;
0086 EXPORT_SYMBOL(arc_raw_proto);
0087 
0088 static struct ArcProto arc_proto_null = {
0089     .suffix     = '?',
0090     .mtu        = XMTU,
0091     .is_ip          = 0,
0092     .rx     = null_rx,
0093     .build_header   = null_build_header,
0094     .prepare_tx = null_prepare_tx,
0095     .continue_tx    = NULL,
0096     .ack_tx         = NULL
0097 };
0098 
0099 /* Exported function prototypes */
0100 int arcnet_debug = ARCNET_DEBUG;
0101 EXPORT_SYMBOL(arcnet_debug);
0102 
0103 /* Internal function prototypes */
0104 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
0105              unsigned short type, const void *daddr,
0106              const void *saddr, unsigned len);
0107 static int go_tx(struct net_device *dev);
0108 
0109 static int debug = ARCNET_DEBUG;
0110 module_param(debug, int, 0);
0111 MODULE_LICENSE("GPL");
0112 
0113 static int __init arcnet_init(void)
0114 {
0115     int count;
0116 
0117     arcnet_debug = debug;
0118 
0119     pr_info("arcnet loaded\n");
0120 
0121     /* initialize the protocol map */
0122     arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
0123     for (count = 0; count < 256; count++)
0124         arc_proto_map[count] = arc_proto_default;
0125 
0126     if (BUGLVL(D_DURING))
0127         pr_info("struct sizes: %zd %zd %zd %zd %zd\n",
0128             sizeof(struct arc_hardware),
0129             sizeof(struct arc_rfc1201),
0130             sizeof(struct arc_rfc1051),
0131             sizeof(struct arc_eth_encap),
0132             sizeof(struct archdr));
0133 
0134     return 0;
0135 }
0136 
0137 static void __exit arcnet_exit(void)
0138 {
0139 }
0140 
0141 module_init(arcnet_init);
0142 module_exit(arcnet_exit);
0143 
0144 /* Dump the contents of an sk_buff */
0145 #if ARCNET_DEBUG_MAX & D_SKB
0146 void arcnet_dump_skb(struct net_device *dev,
0147              struct sk_buff *skb, char *desc)
0148 {
0149     char hdr[32];
0150 
0151     /* dump the packet */
0152     snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc);
0153     print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
0154                16, 1, skb->data, skb->len, true);
0155 }
0156 EXPORT_SYMBOL(arcnet_dump_skb);
0157 #endif
0158 
0159 /* Dump the contents of an ARCnet buffer */
0160 #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
0161 static void arcnet_dump_packet(struct net_device *dev, int bufnum,
0162                    char *desc, int take_arcnet_lock)
0163 {
0164     struct arcnet_local *lp = netdev_priv(dev);
0165     int i, length;
0166     unsigned long flags = 0;
0167     static uint8_t buf[512];
0168     char hdr[32];
0169 
0170     /* hw.copy_from_card expects IRQ context so take the IRQ lock
0171      * to keep it single threaded
0172      */
0173     if (take_arcnet_lock)
0174         spin_lock_irqsave(&lp->lock, flags);
0175 
0176     lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
0177     if (take_arcnet_lock)
0178         spin_unlock_irqrestore(&lp->lock, flags);
0179 
0180     /* if the offset[0] byte is nonzero, this is a 256-byte packet */
0181     length = (buf[2] ? 256 : 512);
0182 
0183     /* dump the packet */
0184     snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc);
0185     print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
0186                16, 1, buf, length, true);
0187 }
0188 
0189 #else
0190 
0191 #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
0192 
0193 #endif
0194 
0195 /* Trigger a LED event in response to a ARCNET device event */
0196 void arcnet_led_event(struct net_device *dev, enum arcnet_led_event event)
0197 {
0198     struct arcnet_local *lp = netdev_priv(dev);
0199     unsigned long led_delay = 350;
0200     unsigned long tx_delay = 50;
0201 
0202     switch (event) {
0203     case ARCNET_LED_EVENT_RECON:
0204         led_trigger_blink_oneshot(lp->recon_led_trig,
0205                       &led_delay, &led_delay, 0);
0206         break;
0207     case ARCNET_LED_EVENT_OPEN:
0208         led_trigger_event(lp->tx_led_trig, LED_OFF);
0209         led_trigger_event(lp->recon_led_trig, LED_OFF);
0210         break;
0211     case ARCNET_LED_EVENT_STOP:
0212         led_trigger_event(lp->tx_led_trig, LED_OFF);
0213         led_trigger_event(lp->recon_led_trig, LED_OFF);
0214         break;
0215     case ARCNET_LED_EVENT_TX:
0216         led_trigger_blink_oneshot(lp->tx_led_trig,
0217                       &tx_delay, &tx_delay, 0);
0218         break;
0219     }
0220 }
0221 EXPORT_SYMBOL_GPL(arcnet_led_event);
0222 
0223 static void arcnet_led_release(struct device *gendev, void *res)
0224 {
0225     struct arcnet_local *lp = netdev_priv(to_net_dev(gendev));
0226 
0227     led_trigger_unregister_simple(lp->tx_led_trig);
0228     led_trigger_unregister_simple(lp->recon_led_trig);
0229 }
0230 
0231 /* Register ARCNET LED triggers for a arcnet device
0232  *
0233  * This is normally called from a driver's probe function
0234  */
0235 void devm_arcnet_led_init(struct net_device *netdev, int index, int subid)
0236 {
0237     struct arcnet_local *lp = netdev_priv(netdev);
0238     void *res;
0239 
0240     res = devres_alloc(arcnet_led_release, 0, GFP_KERNEL);
0241     if (!res) {
0242         netdev_err(netdev, "cannot register LED triggers\n");
0243         return;
0244     }
0245 
0246     snprintf(lp->tx_led_trig_name, sizeof(lp->tx_led_trig_name),
0247          "arc%d-%d-tx", index, subid);
0248     snprintf(lp->recon_led_trig_name, sizeof(lp->recon_led_trig_name),
0249          "arc%d-%d-recon", index, subid);
0250 
0251     led_trigger_register_simple(lp->tx_led_trig_name,
0252                     &lp->tx_led_trig);
0253     led_trigger_register_simple(lp->recon_led_trig_name,
0254                     &lp->recon_led_trig);
0255 
0256     devres_add(&netdev->dev, res);
0257 }
0258 EXPORT_SYMBOL_GPL(devm_arcnet_led_init);
0259 
0260 /* Unregister a protocol driver from the arc_proto_map.  Protocol drivers
0261  * are responsible for registering themselves, but the unregister routine
0262  * is pretty generic so we'll do it here.
0263  */
0264 void arcnet_unregister_proto(struct ArcProto *proto)
0265 {
0266     int count;
0267 
0268     if (arc_proto_default == proto)
0269         arc_proto_default = &arc_proto_null;
0270     if (arc_bcast_proto == proto)
0271         arc_bcast_proto = arc_proto_default;
0272     if (arc_raw_proto == proto)
0273         arc_raw_proto = arc_proto_default;
0274 
0275     for (count = 0; count < 256; count++) {
0276         if (arc_proto_map[count] == proto)
0277             arc_proto_map[count] = arc_proto_default;
0278     }
0279 }
0280 EXPORT_SYMBOL(arcnet_unregister_proto);
0281 
0282 /* Add a buffer to the queue.  Only the interrupt handler is allowed to do
0283  * this, unless interrupts are disabled.
0284  *
0285  * Note: we don't check for a full queue, since there aren't enough buffers
0286  * to more than fill it.
0287  */
0288 static void release_arcbuf(struct net_device *dev, int bufnum)
0289 {
0290     struct arcnet_local *lp = netdev_priv(dev);
0291     int i;
0292 
0293     lp->buf_queue[lp->first_free_buf++] = bufnum;
0294     lp->first_free_buf %= 5;
0295 
0296     if (BUGLVL(D_DURING)) {
0297         arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
0298                bufnum);
0299         for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
0300             arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
0301         arc_cont(D_DURING, "\n");
0302     }
0303 }
0304 
0305 /* Get a buffer from the queue.
0306  * If this returns -1, there are no buffers available.
0307  */
0308 static int get_arcbuf(struct net_device *dev)
0309 {
0310     struct arcnet_local *lp = netdev_priv(dev);
0311     int buf = -1, i;
0312 
0313     if (!atomic_dec_and_test(&lp->buf_lock)) {
0314         /* already in this function */
0315         arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
0316                lp->buf_lock.counter);
0317     } else {            /* we can continue */
0318         if (lp->next_buf >= 5)
0319             lp->next_buf -= 5;
0320 
0321         if (lp->next_buf == lp->first_free_buf) {
0322             arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
0323         } else {
0324             buf = lp->buf_queue[lp->next_buf++];
0325             lp->next_buf %= 5;
0326         }
0327     }
0328 
0329     if (BUGLVL(D_DURING)) {
0330         arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
0331                buf);
0332         for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
0333             arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
0334         arc_cont(D_DURING, "\n");
0335     }
0336 
0337     atomic_inc(&lp->buf_lock);
0338     return buf;
0339 }
0340 
0341 static int choose_mtu(void)
0342 {
0343     int count, mtu = 65535;
0344 
0345     /* choose the smallest MTU of all available encaps */
0346     for (count = 0; count < 256; count++) {
0347         if (arc_proto_map[count] != &arc_proto_null &&
0348             arc_proto_map[count]->mtu < mtu) {
0349             mtu = arc_proto_map[count]->mtu;
0350         }
0351     }
0352 
0353     return mtu == 65535 ? XMTU : mtu;
0354 }
0355 
0356 static const struct header_ops arcnet_header_ops = {
0357     .create = arcnet_header,
0358 };
0359 
0360 static const struct net_device_ops arcnet_netdev_ops = {
0361     .ndo_open   = arcnet_open,
0362     .ndo_stop   = arcnet_close,
0363     .ndo_start_xmit = arcnet_send_packet,
0364     .ndo_tx_timeout = arcnet_timeout,
0365 };
0366 
0367 /* Setup a struct device for ARCnet. */
0368 static void arcdev_setup(struct net_device *dev)
0369 {
0370     dev->type = ARPHRD_ARCNET;
0371     dev->netdev_ops = &arcnet_netdev_ops;
0372     dev->header_ops = &arcnet_header_ops;
0373     dev->hard_header_len = sizeof(struct arc_hardware);
0374     dev->mtu = choose_mtu();
0375 
0376     dev->addr_len = ARCNET_ALEN;
0377     dev->tx_queue_len = 100;
0378     dev->broadcast[0] = 0x00;   /* for us, broadcasts are address 0 */
0379     dev->watchdog_timeo = TX_TIMEOUT;
0380 
0381     /* New-style flags. */
0382     dev->flags = IFF_BROADCAST;
0383 }
0384 
0385 static void arcnet_timer(struct timer_list *t)
0386 {
0387     struct arcnet_local *lp = from_timer(lp, t, timer);
0388     struct net_device *dev = lp->dev;
0389 
0390     spin_lock_irq(&lp->lock);
0391 
0392     if (!lp->reset_in_progress && !netif_carrier_ok(dev)) {
0393         netif_carrier_on(dev);
0394         netdev_info(dev, "link up\n");
0395     }
0396 
0397     spin_unlock_irq(&lp->lock);
0398 }
0399 
0400 static void reset_device_work(struct work_struct *work)
0401 {
0402     struct arcnet_local *lp;
0403     struct net_device *dev;
0404 
0405     lp = container_of(work, struct arcnet_local, reset_work);
0406     dev = lp->dev;
0407 
0408     /* Do not bring the network interface back up if an ifdown
0409      * was already done.
0410      */
0411     if (!netif_running(dev) || !lp->reset_in_progress)
0412         return;
0413 
0414     rtnl_lock();
0415 
0416     /* Do another check, in case of an ifdown that was triggered in
0417      * the small race window between the exit condition above and
0418      * acquiring RTNL.
0419      */
0420     if (!netif_running(dev) || !lp->reset_in_progress)
0421         goto out;
0422 
0423     dev_close(dev);
0424     dev_open(dev, NULL);
0425 
0426 out:
0427     rtnl_unlock();
0428 }
0429 
0430 static void arcnet_reply_tasklet(struct tasklet_struct *t)
0431 {
0432     struct arcnet_local *lp = from_tasklet(lp, t, reply_tasklet);
0433 
0434     struct sk_buff *ackskb, *skb;
0435     struct sock_exterr_skb *serr;
0436     struct sock *sk;
0437     int ret;
0438 
0439     local_irq_disable();
0440     skb = lp->outgoing.skb;
0441     if (!skb || !skb->sk) {
0442         local_irq_enable();
0443         return;
0444     }
0445 
0446     sock_hold(skb->sk);
0447     sk = skb->sk;
0448     ackskb = skb_clone_sk(skb);
0449     sock_put(skb->sk);
0450 
0451     if (!ackskb) {
0452         local_irq_enable();
0453         return;
0454     }
0455 
0456     serr = SKB_EXT_ERR(ackskb);
0457     memset(serr, 0, sizeof(*serr));
0458     serr->ee.ee_errno = ENOMSG;
0459     serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
0460     serr->ee.ee_data = skb_shinfo(skb)->tskey;
0461     serr->ee.ee_info = lp->reply_status;
0462 
0463     /* finally erasing outgoing skb */
0464     dev_kfree_skb(lp->outgoing.skb);
0465     lp->outgoing.skb = NULL;
0466 
0467     ackskb->dev = lp->dev;
0468 
0469     ret = sock_queue_err_skb(sk, ackskb);
0470     if (ret)
0471         kfree_skb(ackskb);
0472 
0473     local_irq_enable();
0474 };
0475 
0476 struct net_device *alloc_arcdev(const char *name)
0477 {
0478     struct net_device *dev;
0479 
0480     dev = alloc_netdev(sizeof(struct arcnet_local),
0481                name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
0482                arcdev_setup);
0483     if (dev) {
0484         struct arcnet_local *lp = netdev_priv(dev);
0485 
0486         lp->dev = dev;
0487         spin_lock_init(&lp->lock);
0488         timer_setup(&lp->timer, arcnet_timer, 0);
0489         INIT_WORK(&lp->reset_work, reset_device_work);
0490     }
0491 
0492     return dev;
0493 }
0494 EXPORT_SYMBOL(alloc_arcdev);
0495 
0496 void free_arcdev(struct net_device *dev)
0497 {
0498     struct arcnet_local *lp = netdev_priv(dev);
0499 
0500     /* Do not cancel this at ->ndo_close(), as the workqueue itself
0501      * indirectly calls the ifdown path through dev_close().
0502      */
0503     cancel_work_sync(&lp->reset_work);
0504     free_netdev(dev);
0505 }
0506 EXPORT_SYMBOL(free_arcdev);
0507 
0508 /* Open/initialize the board.  This is called sometime after booting when
0509  * the 'ifconfig' program is run.
0510  *
0511  * This routine should set everything up anew at each open, even registers
0512  * that "should" only need to be set once at boot, so that there is
0513  * non-reboot way to recover if something goes wrong.
0514  */
0515 int arcnet_open(struct net_device *dev)
0516 {
0517     struct arcnet_local *lp = netdev_priv(dev);
0518     int count, newmtu, error;
0519 
0520     arc_printk(D_INIT, dev, "opened.");
0521 
0522     if (!try_module_get(lp->hw.owner))
0523         return -ENODEV;
0524 
0525     if (BUGLVL(D_PROTO)) {
0526         arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
0527                arc_proto_default->suffix);
0528         for (count = 0; count < 256; count++)
0529             arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
0530         arc_cont(D_PROTO, "\n");
0531     }
0532 
0533     tasklet_setup(&lp->reply_tasklet, arcnet_reply_tasklet);
0534 
0535     arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
0536 
0537     /* try to put the card in a defined state - if it fails the first
0538      * time, actually reset it.
0539      */
0540     error = -ENODEV;
0541     if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1))
0542         goto out_module_put;
0543 
0544     newmtu = choose_mtu();
0545     if (newmtu < dev->mtu)
0546         dev->mtu = newmtu;
0547 
0548     arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
0549 
0550     /* autodetect the encapsulation for each host. */
0551     memset(lp->default_proto, 0, sizeof(lp->default_proto));
0552 
0553     /* the broadcast address is special - use the 'bcast' protocol */
0554     for (count = 0; count < 256; count++) {
0555         if (arc_proto_map[count] == arc_bcast_proto) {
0556             lp->default_proto[0] = count;
0557             break;
0558         }
0559     }
0560 
0561     /* initialize buffers */
0562     atomic_set(&lp->buf_lock, 1);
0563 
0564     lp->next_buf = lp->first_free_buf = 0;
0565     release_arcbuf(dev, 0);
0566     release_arcbuf(dev, 1);
0567     release_arcbuf(dev, 2);
0568     release_arcbuf(dev, 3);
0569     lp->cur_tx = lp->next_tx = -1;
0570     lp->cur_rx = -1;
0571 
0572     lp->rfc1201.sequence = 1;
0573 
0574     /* bring up the hardware driver */
0575     if (lp->hw.open)
0576         lp->hw.open(dev);
0577 
0578     if (dev->dev_addr[0] == 0)
0579         arc_printk(D_NORMAL, dev, "WARNING!  Station address 00 is reserved for broadcasts!\n");
0580     else if (dev->dev_addr[0] == 255)
0581         arc_printk(D_NORMAL, dev, "WARNING!  Station address FF may confuse DOS networking programs!\n");
0582 
0583     arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
0584     if (lp->hw.status(dev) & RESETflag) {
0585         arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
0586                __FILE__, __LINE__, __func__);
0587         lp->hw.command(dev, CFLAGScmd | RESETclear);
0588     }
0589 
0590     arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
0591     /* make sure we're ready to receive IRQ's. */
0592     lp->hw.intmask(dev, 0);
0593     udelay(1);      /* give it time to set the mask before
0594                  * we reset it again. (may not even be
0595                  * necessary)
0596                  */
0597     arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
0598     lp->intmask = NORXflag | RECONflag;
0599     lp->hw.intmask(dev, lp->intmask);
0600     arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
0601 
0602     netif_carrier_off(dev);
0603     netif_start_queue(dev);
0604     mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
0605 
0606     arcnet_led_event(dev, ARCNET_LED_EVENT_OPEN);
0607     return 0;
0608 
0609  out_module_put:
0610     module_put(lp->hw.owner);
0611     return error;
0612 }
0613 EXPORT_SYMBOL(arcnet_open);
0614 
0615 /* The inverse routine to arcnet_open - shuts down the card. */
0616 int arcnet_close(struct net_device *dev)
0617 {
0618     struct arcnet_local *lp = netdev_priv(dev);
0619 
0620     arcnet_led_event(dev, ARCNET_LED_EVENT_STOP);
0621     del_timer_sync(&lp->timer);
0622 
0623     netif_stop_queue(dev);
0624     netif_carrier_off(dev);
0625 
0626     tasklet_kill(&lp->reply_tasklet);
0627 
0628     /* flush TX and disable RX */
0629     lp->hw.intmask(dev, 0);
0630     lp->hw.command(dev, NOTXcmd);   /* stop transmit */
0631     lp->hw.command(dev, NORXcmd);   /* disable receive */
0632     mdelay(1);
0633 
0634     /* shut down the card */
0635     lp->hw.close(dev);
0636 
0637     /* reset counters */
0638     lp->reset_in_progress = 0;
0639 
0640     module_put(lp->hw.owner);
0641     return 0;
0642 }
0643 EXPORT_SYMBOL(arcnet_close);
0644 
0645 static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
0646              unsigned short type, const void *daddr,
0647              const void *saddr, unsigned len)
0648 {
0649     const struct arcnet_local *lp = netdev_priv(dev);
0650     uint8_t _daddr, proto_num;
0651     struct ArcProto *proto;
0652 
0653     arc_printk(D_DURING, dev,
0654            "create header from %d to %d; protocol %d (%Xh); size %u.\n",
0655            saddr ? *(uint8_t *)saddr : -1,
0656            daddr ? *(uint8_t *)daddr : -1,
0657            type, type, len);
0658 
0659     if (skb->len != 0 && len != skb->len)
0660         arc_printk(D_NORMAL, dev, "arcnet_header: Yikes!  skb->len(%d) != len(%d)!\n",
0661                skb->len, len);
0662 
0663     /* Type is host order - ? */
0664     if (type == ETH_P_ARCNET) {
0665         proto = arc_raw_proto;
0666         arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
0667                proto->suffix);
0668         _daddr = daddr ? *(uint8_t *)daddr : 0;
0669     } else if (!daddr) {
0670         /* if the dest addr isn't provided, we can't choose an
0671          * encapsulation!  Store the packet type (eg. ETH_P_IP)
0672          * for now, and we'll push on a real header when we do
0673          * rebuild_header.
0674          */
0675         *(uint16_t *)skb_push(skb, 2) = type;
0676         /* XXX: Why not use skb->mac_len? */
0677         if (skb->network_header - skb->mac_header != 2)
0678             arc_printk(D_NORMAL, dev, "arcnet_header: Yikes!  diff (%u) is not 2!\n",
0679                    skb->network_header - skb->mac_header);
0680         return -2;  /* return error -- can't transmit yet! */
0681     } else {
0682         /* otherwise, we can just add the header as usual. */
0683         _daddr = *(uint8_t *)daddr;
0684         proto_num = lp->default_proto[_daddr];
0685         proto = arc_proto_map[proto_num];
0686         arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
0687                proto_num, proto->suffix);
0688         if (proto == &arc_proto_null && arc_bcast_proto != proto) {
0689             arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
0690                    arc_bcast_proto->suffix);
0691             proto = arc_bcast_proto;
0692         }
0693     }
0694     return proto->build_header(skb, dev, type, _daddr);
0695 }
0696 
0697 /* Called by the kernel in order to transmit a packet. */
0698 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
0699                    struct net_device *dev)
0700 {
0701     struct arcnet_local *lp = netdev_priv(dev);
0702     struct archdr *pkt;
0703     struct arc_rfc1201 *soft;
0704     struct ArcProto *proto;
0705     int txbuf;
0706     unsigned long flags;
0707     int retval;
0708 
0709     arc_printk(D_DURING, dev,
0710            "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
0711            lp->hw.status(dev), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
0712 
0713     pkt = (struct archdr *)skb->data;
0714     soft = &pkt->soft.rfc1201;
0715     proto = arc_proto_map[soft->proto];
0716 
0717     arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
0718            skb->len, pkt->hard.dest);
0719     if (BUGLVL(D_SKB))
0720         arcnet_dump_skb(dev, skb, "tx");
0721 
0722     /* fits in one packet? */
0723     if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
0724         arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
0725         dev_kfree_skb(skb);
0726         return NETDEV_TX_OK;    /* don't try again */
0727     }
0728 
0729     /* We're busy transmitting a packet... */
0730     netif_stop_queue(dev);
0731 
0732     spin_lock_irqsave(&lp->lock, flags);
0733     lp->hw.intmask(dev, 0);
0734     if (lp->next_tx == -1)
0735         txbuf = get_arcbuf(dev);
0736     else
0737         txbuf = -1;
0738 
0739     if (txbuf != -1) {
0740         lp->outgoing.skb = skb;
0741         if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
0742             !proto->ack_tx) {
0743             /* done right away and we don't want to acknowledge
0744              *  the package later - forget about it now
0745              */
0746             dev->stats.tx_bytes += skb->len;
0747         } else {
0748             /* do it the 'split' way */
0749             lp->outgoing.proto = proto;
0750             lp->outgoing.skb = skb;
0751             lp->outgoing.pkt = pkt;
0752 
0753             if (proto->continue_tx &&
0754                 proto->continue_tx(dev, txbuf)) {
0755                 arc_printk(D_NORMAL, dev,
0756                        "bug! continue_tx finished the first time! (proto='%c')\n",
0757                        proto->suffix);
0758             }
0759         }
0760         retval = NETDEV_TX_OK;
0761         lp->next_tx = txbuf;
0762     } else {
0763         retval = NETDEV_TX_BUSY;
0764     }
0765 
0766     arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
0767            __FILE__, __LINE__, __func__, lp->hw.status(dev));
0768     /* make sure we didn't ignore a TX IRQ while we were in here */
0769     lp->hw.intmask(dev, 0);
0770 
0771     arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
0772     lp->intmask |= TXFREEflag | EXCNAKflag;
0773     lp->hw.intmask(dev, lp->intmask);
0774     arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
0775            __FILE__, __LINE__, __func__, lp->hw.status(dev));
0776 
0777     arcnet_led_event(dev, ARCNET_LED_EVENT_TX);
0778 
0779     spin_unlock_irqrestore(&lp->lock, flags);
0780     return retval;      /* no need to try again */
0781 }
0782 EXPORT_SYMBOL(arcnet_send_packet);
0783 
0784 /* Actually start transmitting a packet that was loaded into a buffer
0785  * by prepare_tx.  This should _only_ be called by the interrupt handler.
0786  */
0787 static int go_tx(struct net_device *dev)
0788 {
0789     struct arcnet_local *lp = netdev_priv(dev);
0790 
0791     arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
0792            lp->hw.status(dev), lp->intmask, lp->next_tx, lp->cur_tx);
0793 
0794     if (lp->cur_tx != -1 || lp->next_tx == -1)
0795         return 0;
0796 
0797     if (BUGLVL(D_TX))
0798         arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
0799 
0800     lp->cur_tx = lp->next_tx;
0801     lp->next_tx = -1;
0802 
0803     /* start sending */
0804     lp->hw.command(dev, TXcmd | (lp->cur_tx << 3));
0805 
0806     dev->stats.tx_packets++;
0807     lp->lasttrans_dest = lp->lastload_dest;
0808     lp->lastload_dest = 0;
0809     lp->excnak_pending = 0;
0810     lp->intmask |= TXFREEflag | EXCNAKflag;
0811 
0812     return 1;
0813 }
0814 
0815 /* Called by the kernel when transmit times out */
0816 void arcnet_timeout(struct net_device *dev, unsigned int txqueue)
0817 {
0818     unsigned long flags;
0819     struct arcnet_local *lp = netdev_priv(dev);
0820     int status = lp->hw.status(dev);
0821     char *msg;
0822 
0823     spin_lock_irqsave(&lp->lock, flags);
0824     if (status & TXFREEflag) {  /* transmit _DID_ finish */
0825         msg = " - missed IRQ?";
0826     } else {
0827         msg = "";
0828         dev->stats.tx_aborted_errors++;
0829         lp->timed_out = 1;
0830         lp->hw.command(dev, NOTXcmd | (lp->cur_tx << 3));
0831     }
0832     dev->stats.tx_errors++;
0833 
0834     /* make sure we didn't miss a TX or a EXC NAK IRQ */
0835     lp->hw.intmask(dev, 0);
0836     lp->intmask |= TXFREEflag | EXCNAKflag;
0837     lp->hw.intmask(dev, lp->intmask);
0838 
0839     spin_unlock_irqrestore(&lp->lock, flags);
0840 
0841     if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
0842         arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
0843                msg, status, lp->intmask, lp->lasttrans_dest);
0844         lp->last_timeout = jiffies;
0845     }
0846 
0847     if (lp->cur_tx == -1)
0848         netif_wake_queue(dev);
0849 }
0850 EXPORT_SYMBOL(arcnet_timeout);
0851 
0852 /* The typical workload of the driver: Handle the network interface
0853  * interrupts. Establish which device needs attention, and call the correct
0854  * chipset interrupt handler.
0855  */
0856 irqreturn_t arcnet_interrupt(int irq, void *dev_id)
0857 {
0858     struct net_device *dev = dev_id;
0859     struct arcnet_local *lp;
0860     int recbuf, status, diagstatus, didsomething, boguscount;
0861     unsigned long flags;
0862     int retval = IRQ_NONE;
0863 
0864     arc_printk(D_DURING, dev, "\n");
0865 
0866     arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
0867 
0868     lp = netdev_priv(dev);
0869     BUG_ON(!lp);
0870 
0871     spin_lock_irqsave(&lp->lock, flags);
0872 
0873     if (lp->reset_in_progress)
0874         goto out;
0875 
0876     /* RESET flag was enabled - if device is not running, we must
0877      * clear it right away (but nothing else).
0878      */
0879     if (!netif_running(dev)) {
0880         if (lp->hw.status(dev) & RESETflag)
0881             lp->hw.command(dev, CFLAGScmd | RESETclear);
0882         lp->hw.intmask(dev, 0);
0883         spin_unlock_irqrestore(&lp->lock, flags);
0884         return retval;
0885     }
0886 
0887     arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
0888            lp->hw.status(dev), lp->intmask);
0889 
0890     boguscount = 5;
0891     do {
0892         status = lp->hw.status(dev);
0893         diagstatus = (status >> 8) & 0xFF;
0894 
0895         arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
0896                __FILE__, __LINE__, __func__, status);
0897         didsomething = 0;
0898 
0899         /* RESET flag was enabled - card is resetting and if RX is
0900          * disabled, it's NOT because we just got a packet.
0901          *
0902          * The card is in an undefined state.
0903          * Clear it out and start over.
0904          */
0905         if (status & RESETflag) {
0906             arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
0907                    status);
0908 
0909             lp->reset_in_progress = 1;
0910             netif_stop_queue(dev);
0911             netif_carrier_off(dev);
0912             schedule_work(&lp->reset_work);
0913 
0914             /* get out of the interrupt handler! */
0915             goto out;
0916         }
0917         /* RX is inhibited - we must have received something.
0918          * Prepare to receive into the next buffer.
0919          *
0920          * We don't actually copy the received packet from the card
0921          * until after the transmit handler runs (and possibly
0922          * launches the next tx); this should improve latency slightly
0923          * if we get both types of interrupts at once.
0924          */
0925         recbuf = -1;
0926         if (status & lp->intmask & NORXflag) {
0927             recbuf = lp->cur_rx;
0928             arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
0929                    recbuf, status);
0930 
0931             lp->cur_rx = get_arcbuf(dev);
0932             if (lp->cur_rx != -1) {
0933                 arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
0934                        lp->cur_rx);
0935                 lp->hw.command(dev, RXcmd | (lp->cur_rx << 3) | RXbcasts);
0936             }
0937             didsomething++;
0938         }
0939 
0940         if ((diagstatus & EXCNAKflag)) {
0941             arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
0942                    diagstatus);
0943 
0944             lp->hw.command(dev, NOTXcmd);      /* disable transmit */
0945             lp->excnak_pending = 1;
0946 
0947             lp->hw.command(dev, EXCNAKclear);
0948             lp->intmask &= ~(EXCNAKflag);
0949             didsomething++;
0950         }
0951 
0952         /* a transmit finished, and we're interested in it. */
0953         if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
0954             int ackstatus;
0955             lp->intmask &= ~(TXFREEflag | EXCNAKflag);
0956 
0957             if (status & TXACKflag)
0958                 ackstatus = 2;
0959             else if (lp->excnak_pending)
0960                 ackstatus = 1;
0961             else
0962                 ackstatus = 0;
0963 
0964             arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
0965                    status);
0966 
0967             if (lp->cur_tx != -1 && !lp->timed_out) {
0968                 if (!(status & TXACKflag)) {
0969                     if (lp->lasttrans_dest != 0) {
0970                         arc_printk(D_EXTRA, dev,
0971                                "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
0972                                status,
0973                                lp->lasttrans_dest);
0974                         dev->stats.tx_errors++;
0975                         dev->stats.tx_carrier_errors++;
0976                     } else {
0977                         arc_printk(D_DURING, dev,
0978                                "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
0979                                status,
0980                                lp->lasttrans_dest);
0981                     }
0982                 }
0983 
0984                 if (lp->outgoing.proto &&
0985                     lp->outgoing.proto->ack_tx) {
0986                     lp->outgoing.proto
0987                         ->ack_tx(dev, ackstatus);
0988                 }
0989                 lp->reply_status = ackstatus;
0990                 tasklet_hi_schedule(&lp->reply_tasklet);
0991             }
0992             if (lp->cur_tx != -1)
0993                 release_arcbuf(dev, lp->cur_tx);
0994 
0995             lp->cur_tx = -1;
0996             lp->timed_out = 0;
0997             didsomething++;
0998 
0999             /* send another packet if there is one */
1000             go_tx(dev);
1001 
1002             /* continue a split packet, if any */
1003             if (lp->outgoing.proto &&
1004                 lp->outgoing.proto->continue_tx) {
1005                 int txbuf = get_arcbuf(dev);
1006 
1007                 if (txbuf != -1) {
1008                     if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
1009                         /* that was the last segment */
1010                         dev->stats.tx_bytes += lp->outgoing.skb->len;
1011                         if (!lp->outgoing.proto->ack_tx) {
1012                             dev_kfree_skb_irq(lp->outgoing.skb);
1013                             lp->outgoing.proto = NULL;
1014                         }
1015                     }
1016                     lp->next_tx = txbuf;
1017                 }
1018             }
1019             /* inform upper layers of idleness, if necessary */
1020             if (lp->cur_tx == -1)
1021                 netif_wake_queue(dev);
1022         }
1023         /* now process the received packet, if any */
1024         if (recbuf != -1) {
1025             if (BUGLVL(D_RX))
1026                 arcnet_dump_packet(dev, recbuf, "rx irq", 0);
1027 
1028             arcnet_rx(dev, recbuf);
1029             release_arcbuf(dev, recbuf);
1030 
1031             didsomething++;
1032         }
1033         if (status & lp->intmask & RECONflag) {
1034             lp->hw.command(dev, CFLAGScmd | CONFIGclear);
1035             dev->stats.tx_carrier_errors++;
1036 
1037             arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
1038                    status);
1039             if (netif_carrier_ok(dev)) {
1040                 netif_carrier_off(dev);
1041                 netdev_info(dev, "link down\n");
1042             }
1043             mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
1044 
1045             arcnet_led_event(dev, ARCNET_LED_EVENT_RECON);
1046             /* MYRECON bit is at bit 7 of diagstatus */
1047             if (diagstatus & 0x80)
1048                 arc_printk(D_RECON, dev, "Put out that recon myself\n");
1049 
1050             /* is the RECON info empty or old? */
1051             if (!lp->first_recon || !lp->last_recon ||
1052                 time_after(jiffies, lp->last_recon + HZ * 10)) {
1053                 if (lp->network_down)
1054                     arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
1055                 lp->first_recon = lp->last_recon = jiffies;
1056                 lp->num_recons = lp->network_down = 0;
1057 
1058                 arc_printk(D_DURING, dev, "recon: clearing counters.\n");
1059             } else {    /* add to current RECON counter */
1060                 lp->last_recon = jiffies;
1061                 lp->num_recons++;
1062 
1063                 arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
1064                        lp->num_recons,
1065                        (lp->last_recon - lp->first_recon) / HZ,
1066                        lp->network_down);
1067 
1068                 /* if network is marked up;
1069                  * and first_recon and last_recon are 60+ apart;
1070                  * and the average no. of recons counted is
1071                  *    > RECON_THRESHOLD/min;
1072                  * then print a warning message.
1073                  */
1074                 if (!lp->network_down &&
1075                     (lp->last_recon - lp->first_recon) <= HZ * 60 &&
1076                     lp->num_recons >= RECON_THRESHOLD) {
1077                     lp->network_down = 1;
1078                     arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
1079                 } else if (!lp->network_down &&
1080                        lp->last_recon - lp->first_recon > HZ * 60) {
1081                     /* reset counters if we've gone for
1082                      *  over a minute.
1083                      */
1084                     lp->first_recon = lp->last_recon;
1085                     lp->num_recons = 1;
1086                 }
1087             }
1088         } else if (lp->network_down &&
1089                time_after(jiffies, lp->last_recon + HZ * 10)) {
1090             if (lp->network_down)
1091                 arc_printk(D_NORMAL, dev, "cabling restored?\n");
1092             lp->first_recon = lp->last_recon = 0;
1093             lp->num_recons = lp->network_down = 0;
1094 
1095             arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
1096             netif_carrier_on(dev);
1097         }
1098 
1099         if (didsomething)
1100             retval |= IRQ_HANDLED;
1101     } while (--boguscount && didsomething);
1102 
1103     arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
1104            lp->hw.status(dev), boguscount);
1105     arc_printk(D_DURING, dev, "\n");
1106 
1107     lp->hw.intmask(dev, 0);
1108     udelay(1);
1109     lp->hw.intmask(dev, lp->intmask);
1110 
1111 out:
1112     spin_unlock_irqrestore(&lp->lock, flags);
1113     return retval;
1114 }
1115 EXPORT_SYMBOL(arcnet_interrupt);
1116 
1117 /* This is a generic packet receiver that calls arcnet??_rx depending on the
1118  * protocol ID found.
1119  */
1120 static void arcnet_rx(struct net_device *dev, int bufnum)
1121 {
1122     struct arcnet_local *lp = netdev_priv(dev);
1123     union {
1124         struct archdr pkt;
1125         char buf[512];
1126     } rxdata;
1127     struct arc_rfc1201 *soft;
1128     int length, ofs;
1129 
1130     soft = &rxdata.pkt.soft.rfc1201;
1131 
1132     lp->hw.copy_from_card(dev, bufnum, 0, &rxdata.pkt, ARC_HDR_SIZE);
1133     if (rxdata.pkt.hard.offset[0]) {
1134         ofs = rxdata.pkt.hard.offset[0];
1135         length = 256 - ofs;
1136     } else {
1137         ofs = rxdata.pkt.hard.offset[1];
1138         length = 512 - ofs;
1139     }
1140 
1141     /* get the full header, if possible */
1142     if (sizeof(rxdata.pkt.soft) <= length) {
1143         lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(rxdata.pkt.soft));
1144     } else {
1145         memset(&rxdata.pkt.soft, 0, sizeof(rxdata.pkt.soft));
1146         lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
1147     }
1148 
1149     arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
1150            bufnum, rxdata.pkt.hard.source, rxdata.pkt.hard.dest, length);
1151 
1152     dev->stats.rx_packets++;
1153     dev->stats.rx_bytes += length + ARC_HDR_SIZE;
1154 
1155     /* call the right receiver for the protocol */
1156     if (arc_proto_map[soft->proto]->is_ip) {
1157         if (BUGLVL(D_PROTO)) {
1158             struct ArcProto
1159             *oldp = arc_proto_map[lp->default_proto[rxdata.pkt.hard.source]],
1160             *newp = arc_proto_map[soft->proto];
1161 
1162             if (oldp != newp) {
1163                 arc_printk(D_PROTO, dev,
1164                        "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
1165                        soft->proto, rxdata.pkt.hard.source,
1166                        newp->suffix, oldp->suffix);
1167             }
1168         }
1169 
1170         /* broadcasts will always be done with the last-used encap. */
1171         lp->default_proto[0] = soft->proto;
1172 
1173         /* in striking contrast, the following isn't a hack. */
1174         lp->default_proto[rxdata.pkt.hard.source] = soft->proto;
1175     }
1176     /* call the protocol-specific receiver. */
1177     arc_proto_map[soft->proto]->rx(dev, bufnum, &rxdata.pkt, length);
1178 }
1179 
1180 static void null_rx(struct net_device *dev, int bufnum,
1181             struct archdr *pkthdr, int length)
1182 {
1183     arc_printk(D_PROTO, dev,
1184            "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
1185            pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
1186 }
1187 
1188 static int null_build_header(struct sk_buff *skb, struct net_device *dev,
1189                  unsigned short type, uint8_t daddr)
1190 {
1191     struct arcnet_local *lp = netdev_priv(dev);
1192 
1193     arc_printk(D_PROTO, dev,
1194            "tx: can't build header for encap %02Xh; load a protocol driver.\n",
1195            lp->default_proto[daddr]);
1196 
1197     /* always fails */
1198     return 0;
1199 }
1200 
1201 /* the "do nothing" prepare_tx function warns that there's nothing to do. */
1202 static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
1203                int length, int bufnum)
1204 {
1205     struct arcnet_local *lp = netdev_priv(dev);
1206     struct arc_hardware newpkt;
1207 
1208     arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
1209 
1210     /* send a packet to myself -- will never get received, of course */
1211     newpkt.source = newpkt.dest = dev->dev_addr[0];
1212 
1213     /* only one byte of actual data (and it's random) */
1214     newpkt.offset[0] = 0xFF;
1215 
1216     lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
1217 
1218     return 1;       /* done */
1219 }