11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Linux ARCnet driver - device-independent routines 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Written 1997 by David Woodhouse. 51da177e4SLinus Torvalds * Written 1994-1999 by Avery Pennarun. 61da177e4SLinus Torvalds * Written 1999-2000 by Martin Mares <mj@ucw.cz>. 71da177e4SLinus Torvalds * Derived from skeleton.c by Donald Becker. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com) 101da177e4SLinus Torvalds * for sponsoring the further development of this driver. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * ********************** 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * The original copyright was as follows: 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * skeleton.c Written 1993 by Donald Becker. 171da177e4SLinus Torvalds * Copyright 1993 United States Government as represented by the 181da177e4SLinus Torvalds * Director, National Security Agency. This software may only be used 191da177e4SLinus Torvalds * and distributed according to the terms of the GNU General Public License as 201da177e4SLinus Torvalds * modified by SRC, incorporated herein by reference. 211da177e4SLinus Torvalds * 221da177e4SLinus Torvalds * ********************** 231da177e4SLinus Torvalds * 241da177e4SLinus Torvalds * The change log is now in a file called ChangeLog in this directory. 251da177e4SLinus Torvalds * 261da177e4SLinus Torvalds * Sources: 271da177e4SLinus Torvalds * - Crynwr arcnet.com/arcether.com packet drivers. 281da177e4SLinus Torvalds * - arcnet.c v0.00 dated 1/1/94 and apparently by 291da177e4SLinus Torvalds * Donald Becker - it didn't work :) 301da177e4SLinus Torvalds * - skeleton.c v0.05 dated 11/16/93 by Donald Becker 311da177e4SLinus Torvalds * (from Linux Kernel 1.1.45) 321da177e4SLinus Torvalds * - RFC's 1201 and 1051 - re: TCP/IP over ARCnet 331da177e4SLinus Torvalds * - The official ARCnet COM9026 data sheets (!) thanks to 341da177e4SLinus Torvalds * Ken Cornetet <kcornete@nyx10.cs.du.edu> 351da177e4SLinus Torvalds * - The official ARCnet COM20020 data sheets. 361da177e4SLinus Torvalds * - Information on some more obscure ARCnet controller chips, thanks 371da177e4SLinus Torvalds * to the nice people at SMSC. 381da177e4SLinus Torvalds * - net/inet/eth.c (from kernel 1.1.50) for header-building info. 391da177e4SLinus Torvalds * - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su> 401da177e4SLinus Torvalds * - Textual information and more alternate source from Joachim Koenig 411da177e4SLinus Torvalds * <jojo@repas.de> 421da177e4SLinus Torvalds */ 431da177e4SLinus Torvalds 4452edc17fSJeff Morrow #define VERSION "arcnet: v3.94 BETA 2007/02/08 - by Avery Pennarun et al.\n" 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds #include <linux/module.h> 471da177e4SLinus Torvalds #include <linux/types.h> 481da177e4SLinus Torvalds #include <linux/delay.h> 491da177e4SLinus Torvalds #include <linux/netdevice.h> 501da177e4SLinus Torvalds #include <linux/if_arp.h> 511da177e4SLinus Torvalds #include <net/arp.h> 521da177e4SLinus Torvalds #include <linux/init.h> 531da177e4SLinus Torvalds #include <linux/arcdevice.h> 54ff5688aeSMarcelo Feitoza Parisi #include <linux/jiffies.h> 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /* "do nothing" functions for protocol drivers */ 571da177e4SLinus Torvalds static void null_rx(struct net_device *dev, int bufnum, 581da177e4SLinus Torvalds struct archdr *pkthdr, int length); 591da177e4SLinus Torvalds static int null_build_header(struct sk_buff *skb, struct net_device *dev, 601da177e4SLinus Torvalds unsigned short type, uint8_t daddr); 611da177e4SLinus Torvalds static int null_prepare_tx(struct net_device *dev, struct archdr *pkt, 621da177e4SLinus Torvalds int length, int bufnum); 631da177e4SLinus Torvalds 64f03aa2d8SAdrian Bunk static void arcnet_rx(struct net_device *dev, int bufnum); 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds /* 671da177e4SLinus Torvalds * one ArcProto per possible proto ID. None of the elements of 681da177e4SLinus Torvalds * arc_proto_map are allowed to be NULL; they will get set to 691da177e4SLinus Torvalds * arc_proto_default instead. It also must not be NULL; if you would like 701da177e4SLinus Torvalds * to set it to NULL, set it to &arc_proto_null instead. 711da177e4SLinus Torvalds */ 721da177e4SLinus Torvalds struct ArcProto *arc_proto_map[256], *arc_proto_default, 731da177e4SLinus Torvalds *arc_bcast_proto, *arc_raw_proto; 741da177e4SLinus Torvalds 75f03aa2d8SAdrian Bunk static struct ArcProto arc_proto_null = 761da177e4SLinus Torvalds { 771da177e4SLinus Torvalds .suffix = '?', 781da177e4SLinus Torvalds .mtu = XMTU, 791da177e4SLinus Torvalds .is_ip = 0, 801da177e4SLinus Torvalds .rx = null_rx, 811da177e4SLinus Torvalds .build_header = null_build_header, 821da177e4SLinus Torvalds .prepare_tx = null_prepare_tx, 831da177e4SLinus Torvalds .continue_tx = NULL, 841da177e4SLinus Torvalds .ack_tx = NULL 851da177e4SLinus Torvalds }; 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds /* Exported function prototypes */ 881da177e4SLinus Torvalds int arcnet_debug = ARCNET_DEBUG; 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds EXPORT_SYMBOL(arc_proto_map); 911da177e4SLinus Torvalds EXPORT_SYMBOL(arc_proto_default); 921da177e4SLinus Torvalds EXPORT_SYMBOL(arc_bcast_proto); 931da177e4SLinus Torvalds EXPORT_SYMBOL(arc_raw_proto); 941da177e4SLinus Torvalds EXPORT_SYMBOL(arcnet_unregister_proto); 951da177e4SLinus Torvalds EXPORT_SYMBOL(arcnet_debug); 961da177e4SLinus Torvalds EXPORT_SYMBOL(alloc_arcdev); 971da177e4SLinus Torvalds EXPORT_SYMBOL(arcnet_interrupt); 98bca5b893SStephen Hemminger EXPORT_SYMBOL(arcnet_open); 99bca5b893SStephen Hemminger EXPORT_SYMBOL(arcnet_close); 100bca5b893SStephen Hemminger EXPORT_SYMBOL(arcnet_send_packet); 101bca5b893SStephen Hemminger EXPORT_SYMBOL(arcnet_timeout); 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds /* Internal function prototypes */ 1041da177e4SLinus Torvalds static int arcnet_header(struct sk_buff *skb, struct net_device *dev, 1053b04dddeSStephen Hemminger unsigned short type, const void *daddr, 1063b04dddeSStephen Hemminger const void *saddr, unsigned len); 1071da177e4SLinus Torvalds static int arcnet_rebuild_header(struct sk_buff *skb); 1081da177e4SLinus Torvalds static int go_tx(struct net_device *dev); 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds static int debug = ARCNET_DEBUG; 1111da177e4SLinus Torvalds module_param(debug, int, 0); 1121da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds static int __init arcnet_init(void) 1151da177e4SLinus Torvalds { 1161da177e4SLinus Torvalds int count; 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds arcnet_debug = debug; 1191da177e4SLinus Torvalds 120f03aa2d8SAdrian Bunk printk("arcnet loaded.\n"); 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds #ifdef ALPHA_WARNING 1231da177e4SLinus Torvalds BUGLVL(D_EXTRA) { 1241da177e4SLinus Torvalds printk("arcnet: ***\n" 1251da177e4SLinus Torvalds "arcnet: * Read arcnet.txt for important release notes!\n" 1261da177e4SLinus Torvalds "arcnet: *\n" 1271da177e4SLinus Torvalds "arcnet: * This is an ALPHA version! (Last stable release: v3.02) E-mail\n" 1281da177e4SLinus Torvalds "arcnet: * me if you have any questions, comments, or bug reports.\n" 1291da177e4SLinus Torvalds "arcnet: ***\n"); 1301da177e4SLinus Torvalds } 1311da177e4SLinus Torvalds #endif 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds /* initialize the protocol map */ 1341da177e4SLinus Torvalds arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null; 1351da177e4SLinus Torvalds for (count = 0; count < 256; count++) 1361da177e4SLinus Torvalds arc_proto_map[count] = arc_proto_default; 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds BUGLVL(D_DURING) 1391da177e4SLinus Torvalds printk("arcnet: struct sizes: %Zd %Zd %Zd %Zd %Zd\n", 1401da177e4SLinus Torvalds sizeof(struct arc_hardware), sizeof(struct arc_rfc1201), 1411da177e4SLinus Torvalds sizeof(struct arc_rfc1051), sizeof(struct arc_eth_encap), 1421da177e4SLinus Torvalds sizeof(struct archdr)); 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds return 0; 1451da177e4SLinus Torvalds } 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds static void __exit arcnet_exit(void) 1481da177e4SLinus Torvalds { 1491da177e4SLinus Torvalds } 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds module_init(arcnet_init); 1521da177e4SLinus Torvalds module_exit(arcnet_exit); 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds /* 1551da177e4SLinus Torvalds * Dump the contents of an sk_buff 1561da177e4SLinus Torvalds */ 1571da177e4SLinus Torvalds #if ARCNET_DEBUG_MAX & D_SKB 1581da177e4SLinus Torvalds void arcnet_dump_skb(struct net_device *dev, 1591da177e4SLinus Torvalds struct sk_buff *skb, char *desc) 1601da177e4SLinus Torvalds { 161ad361c98SJoe Perches char hdr[32]; 1621da177e4SLinus Torvalds 163ad361c98SJoe Perches /* dump the packet */ 164ad361c98SJoe Perches snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc); 165ad361c98SJoe Perches print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET, 166ad361c98SJoe Perches 16, 1, skb->data, skb->len, true); 1671da177e4SLinus Torvalds } 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds EXPORT_SYMBOL(arcnet_dump_skb); 1701da177e4SLinus Torvalds #endif 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds /* 1741da177e4SLinus Torvalds * Dump the contents of an ARCnet buffer 1751da177e4SLinus Torvalds */ 1761da177e4SLinus Torvalds #if (ARCNET_DEBUG_MAX & (D_RX | D_TX)) 177f03aa2d8SAdrian Bunk static void arcnet_dump_packet(struct net_device *dev, int bufnum, 178f03aa2d8SAdrian Bunk char *desc, int take_arcnet_lock) 1791da177e4SLinus Torvalds { 180454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 1811da177e4SLinus Torvalds int i, length; 1821da177e4SLinus Torvalds unsigned long flags = 0; 1831da177e4SLinus Torvalds static uint8_t buf[512]; 184ad361c98SJoe Perches char hdr[32]; 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds /* hw.copy_from_card expects IRQ context so take the IRQ lock 1871da177e4SLinus Torvalds to keep it single threaded */ 1881da177e4SLinus Torvalds if(take_arcnet_lock) 1891da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags); 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds lp->hw.copy_from_card(dev, bufnum, 0, buf, 512); 1921da177e4SLinus Torvalds if(take_arcnet_lock) 1931da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags); 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds /* if the offset[0] byte is nonzero, this is a 256-byte packet */ 1961da177e4SLinus Torvalds length = (buf[2] ? 256 : 512); 1971da177e4SLinus Torvalds 198ad361c98SJoe Perches /* dump the packet */ 199ad361c98SJoe Perches snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc); 200ad361c98SJoe Perches print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET, 201ad361c98SJoe Perches 16, 1, buf, length, true); 2021da177e4SLinus Torvalds } 2031da177e4SLinus Torvalds 204f03aa2d8SAdrian Bunk #else 205f03aa2d8SAdrian Bunk 206f03aa2d8SAdrian Bunk #define arcnet_dump_packet(dev, bufnum, desc,take_arcnet_lock) do { } while (0) 207f03aa2d8SAdrian Bunk 2081da177e4SLinus Torvalds #endif 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds /* 2121da177e4SLinus Torvalds * Unregister a protocol driver from the arc_proto_map. Protocol drivers 2131da177e4SLinus Torvalds * are responsible for registering themselves, but the unregister routine 2141da177e4SLinus Torvalds * is pretty generic so we'll do it here. 2151da177e4SLinus Torvalds */ 2161da177e4SLinus Torvalds void arcnet_unregister_proto(struct ArcProto *proto) 2171da177e4SLinus Torvalds { 2181da177e4SLinus Torvalds int count; 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds if (arc_proto_default == proto) 2211da177e4SLinus Torvalds arc_proto_default = &arc_proto_null; 2221da177e4SLinus Torvalds if (arc_bcast_proto == proto) 2231da177e4SLinus Torvalds arc_bcast_proto = arc_proto_default; 2241da177e4SLinus Torvalds if (arc_raw_proto == proto) 2251da177e4SLinus Torvalds arc_raw_proto = arc_proto_default; 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds for (count = 0; count < 256; count++) { 2281da177e4SLinus Torvalds if (arc_proto_map[count] == proto) 2291da177e4SLinus Torvalds arc_proto_map[count] = arc_proto_default; 2301da177e4SLinus Torvalds } 2311da177e4SLinus Torvalds } 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds /* 2351da177e4SLinus Torvalds * Add a buffer to the queue. Only the interrupt handler is allowed to do 2361da177e4SLinus Torvalds * this, unless interrupts are disabled. 2371da177e4SLinus Torvalds * 2381da177e4SLinus Torvalds * Note: we don't check for a full queue, since there aren't enough buffers 2391da177e4SLinus Torvalds * to more than fill it. 2401da177e4SLinus Torvalds */ 2411da177e4SLinus Torvalds static void release_arcbuf(struct net_device *dev, int bufnum) 2421da177e4SLinus Torvalds { 243454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 2441da177e4SLinus Torvalds int i; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds lp->buf_queue[lp->first_free_buf++] = bufnum; 2471da177e4SLinus Torvalds lp->first_free_buf %= 5; 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds BUGLVL(D_DURING) { 2501da177e4SLinus Torvalds BUGMSG(D_DURING, "release_arcbuf: freed #%d; buffer queue is now: ", 2511da177e4SLinus Torvalds bufnum); 2521da177e4SLinus Torvalds for (i = lp->next_buf; i != lp->first_free_buf; i = (i+1) % 5) 2531da177e4SLinus Torvalds BUGMSG2(D_DURING, "#%d ", lp->buf_queue[i]); 2541da177e4SLinus Torvalds BUGMSG2(D_DURING, "\n"); 2551da177e4SLinus Torvalds } 2561da177e4SLinus Torvalds } 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds /* 2601da177e4SLinus Torvalds * Get a buffer from the queue. If this returns -1, there are no buffers 2611da177e4SLinus Torvalds * available. 2621da177e4SLinus Torvalds */ 2631da177e4SLinus Torvalds static int get_arcbuf(struct net_device *dev) 2641da177e4SLinus Torvalds { 265454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 2661da177e4SLinus Torvalds int buf = -1, i; 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds if (!atomic_dec_and_test(&lp->buf_lock)) { 2691da177e4SLinus Torvalds /* already in this function */ 2701da177e4SLinus Torvalds BUGMSG(D_NORMAL, "get_arcbuf: overlap (%d)!\n", 2711da177e4SLinus Torvalds lp->buf_lock.counter); 2721da177e4SLinus Torvalds } 2731da177e4SLinus Torvalds else { /* we can continue */ 2741da177e4SLinus Torvalds if (lp->next_buf >= 5) 2751da177e4SLinus Torvalds lp->next_buf -= 5; 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds if (lp->next_buf == lp->first_free_buf) 2781da177e4SLinus Torvalds BUGMSG(D_NORMAL, "get_arcbuf: BUG: no buffers are available??\n"); 2791da177e4SLinus Torvalds else { 2801da177e4SLinus Torvalds buf = lp->buf_queue[lp->next_buf++]; 2811da177e4SLinus Torvalds lp->next_buf %= 5; 2821da177e4SLinus Torvalds } 2831da177e4SLinus Torvalds } 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds BUGLVL(D_DURING) { 2871da177e4SLinus Torvalds BUGMSG(D_DURING, "get_arcbuf: got #%d; buffer queue is now: ", buf); 2881da177e4SLinus Torvalds for (i = lp->next_buf; i != lp->first_free_buf; i = (i+1) % 5) 2891da177e4SLinus Torvalds BUGMSG2(D_DURING, "#%d ", lp->buf_queue[i]); 2901da177e4SLinus Torvalds BUGMSG2(D_DURING, "\n"); 2911da177e4SLinus Torvalds } 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds atomic_inc(&lp->buf_lock); 2941da177e4SLinus Torvalds return buf; 2951da177e4SLinus Torvalds } 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds static int choose_mtu(void) 2991da177e4SLinus Torvalds { 3001da177e4SLinus Torvalds int count, mtu = 65535; 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds /* choose the smallest MTU of all available encaps */ 3031da177e4SLinus Torvalds for (count = 0; count < 256; count++) { 3048e95a202SJoe Perches if (arc_proto_map[count] != &arc_proto_null && 3058e95a202SJoe Perches arc_proto_map[count]->mtu < mtu) { 3061da177e4SLinus Torvalds mtu = arc_proto_map[count]->mtu; 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds } 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds return mtu == 65535 ? XMTU : mtu; 3111da177e4SLinus Torvalds } 3121da177e4SLinus Torvalds 3133b04dddeSStephen Hemminger static const struct header_ops arcnet_header_ops = { 3143b04dddeSStephen Hemminger .create = arcnet_header, 3153b04dddeSStephen Hemminger .rebuild = arcnet_rebuild_header, 3163b04dddeSStephen Hemminger }; 3173b04dddeSStephen Hemminger 318bca5b893SStephen Hemminger static const struct net_device_ops arcnet_netdev_ops = { 319bca5b893SStephen Hemminger .ndo_open = arcnet_open, 320bca5b893SStephen Hemminger .ndo_stop = arcnet_close, 321bca5b893SStephen Hemminger .ndo_start_xmit = arcnet_send_packet, 322bca5b893SStephen Hemminger .ndo_tx_timeout = arcnet_timeout, 323bca5b893SStephen Hemminger }; 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds /* Setup a struct device for ARCnet. */ 3261da177e4SLinus Torvalds static void arcdev_setup(struct net_device *dev) 3271da177e4SLinus Torvalds { 3281da177e4SLinus Torvalds dev->type = ARPHRD_ARCNET; 329bca5b893SStephen Hemminger dev->netdev_ops = &arcnet_netdev_ops; 3303b04dddeSStephen Hemminger dev->header_ops = &arcnet_header_ops; 3311da177e4SLinus Torvalds dev->hard_header_len = sizeof(struct archdr); 3321da177e4SLinus Torvalds dev->mtu = choose_mtu(); 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds dev->addr_len = ARCNET_ALEN; 3351da177e4SLinus Torvalds dev->tx_queue_len = 100; 3361da177e4SLinus Torvalds dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */ 3371da177e4SLinus Torvalds dev->watchdog_timeo = TX_TIMEOUT; 3381da177e4SLinus Torvalds 3391da177e4SLinus Torvalds /* New-style flags. */ 3401da177e4SLinus Torvalds dev->flags = IFF_BROADCAST; 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds } 3431da177e4SLinus Torvalds 344bca5b893SStephen Hemminger struct net_device *alloc_arcdev(const char *name) 3451da177e4SLinus Torvalds { 3461da177e4SLinus Torvalds struct net_device *dev; 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds dev = alloc_netdev(sizeof(struct arcnet_local), 3491da177e4SLinus Torvalds name && *name ? name : "arc%d", arcdev_setup); 3501da177e4SLinus Torvalds if(dev) { 351454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 3521da177e4SLinus Torvalds spin_lock_init(&lp->lock); 3531da177e4SLinus Torvalds } 3541da177e4SLinus Torvalds 3551da177e4SLinus Torvalds return dev; 3561da177e4SLinus Torvalds } 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds /* 3591da177e4SLinus Torvalds * Open/initialize the board. This is called sometime after booting when 3601da177e4SLinus Torvalds * the 'ifconfig' program is run. 3611da177e4SLinus Torvalds * 3621da177e4SLinus Torvalds * This routine should set everything up anew at each open, even registers 3631da177e4SLinus Torvalds * that "should" only need to be set once at boot, so that there is 3641da177e4SLinus Torvalds * non-reboot way to recover if something goes wrong. 3651da177e4SLinus Torvalds */ 366bca5b893SStephen Hemminger int arcnet_open(struct net_device *dev) 3671da177e4SLinus Torvalds { 368454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 3691da177e4SLinus Torvalds int count, newmtu, error; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds BUGMSG(D_INIT,"opened."); 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds if (!try_module_get(lp->hw.owner)) 3741da177e4SLinus Torvalds return -ENODEV; 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds BUGLVL(D_PROTO) { 3771da177e4SLinus Torvalds BUGMSG(D_PROTO, "protocol map (default is '%c'): ", 3781da177e4SLinus Torvalds arc_proto_default->suffix); 3791da177e4SLinus Torvalds for (count = 0; count < 256; count++) 3801da177e4SLinus Torvalds BUGMSG2(D_PROTO, "%c", arc_proto_map[count]->suffix); 3811da177e4SLinus Torvalds BUGMSG2(D_PROTO, "\n"); 3821da177e4SLinus Torvalds } 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds BUGMSG(D_INIT, "arcnet_open: resetting card.\n"); 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds /* try to put the card in a defined state - if it fails the first 3881da177e4SLinus Torvalds * time, actually reset it. 3891da177e4SLinus Torvalds */ 3901da177e4SLinus Torvalds error = -ENODEV; 3911da177e4SLinus Torvalds if (ARCRESET(0) && ARCRESET(1)) 3921da177e4SLinus Torvalds goto out_module_put; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds newmtu = choose_mtu(); 3951da177e4SLinus Torvalds if (newmtu < dev->mtu) 3961da177e4SLinus Torvalds dev->mtu = newmtu; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds BUGMSG(D_INIT, "arcnet_open: mtu: %d.\n", dev->mtu); 3991da177e4SLinus Torvalds 4001da177e4SLinus Torvalds /* autodetect the encapsulation for each host. */ 4011da177e4SLinus Torvalds memset(lp->default_proto, 0, sizeof(lp->default_proto)); 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds /* the broadcast address is special - use the 'bcast' protocol */ 4041da177e4SLinus Torvalds for (count = 0; count < 256; count++) { 4051da177e4SLinus Torvalds if (arc_proto_map[count] == arc_bcast_proto) { 4061da177e4SLinus Torvalds lp->default_proto[0] = count; 4071da177e4SLinus Torvalds break; 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds } 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds /* initialize buffers */ 4121da177e4SLinus Torvalds atomic_set(&lp->buf_lock, 1); 4131da177e4SLinus Torvalds 4141da177e4SLinus Torvalds lp->next_buf = lp->first_free_buf = 0; 4151da177e4SLinus Torvalds release_arcbuf(dev, 0); 4161da177e4SLinus Torvalds release_arcbuf(dev, 1); 4171da177e4SLinus Torvalds release_arcbuf(dev, 2); 4181da177e4SLinus Torvalds release_arcbuf(dev, 3); 4191da177e4SLinus Torvalds lp->cur_tx = lp->next_tx = -1; 4201da177e4SLinus Torvalds lp->cur_rx = -1; 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds lp->rfc1201.sequence = 1; 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds /* bring up the hardware driver */ 4251da177e4SLinus Torvalds if (lp->hw.open) 4261da177e4SLinus Torvalds lp->hw.open(dev); 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds if (dev->dev_addr[0] == 0) 4291da177e4SLinus Torvalds BUGMSG(D_NORMAL, "WARNING! Station address 00 is reserved " 4301da177e4SLinus Torvalds "for broadcasts!\n"); 4311da177e4SLinus Torvalds else if (dev->dev_addr[0] == 255) 4321da177e4SLinus Torvalds BUGMSG(D_NORMAL, "WARNING! Station address FF may confuse " 4331da177e4SLinus Torvalds "DOS networking programs!\n"); 4341da177e4SLinus Torvalds 435b39d66a8SHarvey Harrison BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); 4361da177e4SLinus Torvalds if (ASTATUS() & RESETflag) { 437b39d66a8SHarvey Harrison BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); 4381da177e4SLinus Torvalds ACOMMAND(CFLAGScmd | RESETclear); 4391da177e4SLinus Torvalds } 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds 442b39d66a8SHarvey Harrison BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); 4431da177e4SLinus Torvalds /* make sure we're ready to receive IRQ's. */ 4441da177e4SLinus Torvalds AINTMASK(0); 4451da177e4SLinus Torvalds udelay(1); /* give it time to set the mask before 4461da177e4SLinus Torvalds * we reset it again. (may not even be 4471da177e4SLinus Torvalds * necessary) 4481da177e4SLinus Torvalds */ 449b39d66a8SHarvey Harrison BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); 4501da177e4SLinus Torvalds lp->intmask = NORXflag | RECONflag; 4511da177e4SLinus Torvalds AINTMASK(lp->intmask); 452b39d66a8SHarvey Harrison BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds netif_start_queue(dev); 4551da177e4SLinus Torvalds 4561da177e4SLinus Torvalds return 0; 4571da177e4SLinus Torvalds 4581da177e4SLinus Torvalds out_module_put: 4591da177e4SLinus Torvalds module_put(lp->hw.owner); 4601da177e4SLinus Torvalds return error; 4611da177e4SLinus Torvalds } 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds /* The inverse routine to arcnet_open - shuts down the card. */ 465bca5b893SStephen Hemminger int arcnet_close(struct net_device *dev) 4661da177e4SLinus Torvalds { 467454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 4681da177e4SLinus Torvalds 4691da177e4SLinus Torvalds netif_stop_queue(dev); 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds /* flush TX and disable RX */ 4721da177e4SLinus Torvalds AINTMASK(0); 4731da177e4SLinus Torvalds ACOMMAND(NOTXcmd); /* stop transmit */ 4741da177e4SLinus Torvalds ACOMMAND(NORXcmd); /* disable receive */ 4751da177e4SLinus Torvalds mdelay(1); 4761da177e4SLinus Torvalds 4771da177e4SLinus Torvalds /* shut down the card */ 4781da177e4SLinus Torvalds lp->hw.close(dev); 4791da177e4SLinus Torvalds module_put(lp->hw.owner); 4801da177e4SLinus Torvalds return 0; 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds static int arcnet_header(struct sk_buff *skb, struct net_device *dev, 4853b04dddeSStephen Hemminger unsigned short type, const void *daddr, 4863b04dddeSStephen Hemminger const void *saddr, unsigned len) 4871da177e4SLinus Torvalds { 4883b04dddeSStephen Hemminger const struct arcnet_local *lp = netdev_priv(dev); 4891da177e4SLinus Torvalds uint8_t _daddr, proto_num; 4901da177e4SLinus Torvalds struct ArcProto *proto; 4911da177e4SLinus Torvalds 4921da177e4SLinus Torvalds BUGMSG(D_DURING, 4931da177e4SLinus Torvalds "create header from %d to %d; protocol %d (%Xh); size %u.\n", 4941da177e4SLinus Torvalds saddr ? *(uint8_t *) saddr : -1, 4951da177e4SLinus Torvalds daddr ? *(uint8_t *) daddr : -1, 4961da177e4SLinus Torvalds type, type, len); 4971da177e4SLinus Torvalds 4981da177e4SLinus Torvalds if (skb->len!=0 && len != skb->len) 4991da177e4SLinus Torvalds BUGMSG(D_NORMAL, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n", 5001da177e4SLinus Torvalds skb->len, len); 5011da177e4SLinus Torvalds 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds /* Type is host order - ? */ 5041da177e4SLinus Torvalds if(type == ETH_P_ARCNET) { 5051da177e4SLinus Torvalds proto = arc_raw_proto; 5061da177e4SLinus Torvalds BUGMSG(D_DEBUG, "arc_raw_proto used. proto='%c'\n",proto->suffix); 5071da177e4SLinus Torvalds _daddr = daddr ? *(uint8_t *) daddr : 0; 5081da177e4SLinus Torvalds } 5091da177e4SLinus Torvalds else if (!daddr) { 5101da177e4SLinus Torvalds /* 5111da177e4SLinus Torvalds * if the dest addr isn't provided, we can't choose an encapsulation! 5121da177e4SLinus Torvalds * Store the packet type (eg. ETH_P_IP) for now, and we'll push on a 5131da177e4SLinus Torvalds * real header when we do rebuild_header. 5141da177e4SLinus Torvalds */ 5151da177e4SLinus Torvalds *(uint16_t *) skb_push(skb, 2) = type; 516b0e380b1SArnaldo Carvalho de Melo /* 517b0e380b1SArnaldo Carvalho de Melo * XXX: Why not use skb->mac_len? 518b0e380b1SArnaldo Carvalho de Melo */ 519b0e380b1SArnaldo Carvalho de Melo if (skb->network_header - skb->mac_header != 2) 5201da177e4SLinus Torvalds BUGMSG(D_NORMAL, "arcnet_header: Yikes! diff (%d) is not 2!\n", 521b0e380b1SArnaldo Carvalho de Melo (int)(skb->network_header - skb->mac_header)); 5221da177e4SLinus Torvalds return -2; /* return error -- can't transmit yet! */ 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds else { 5251da177e4SLinus Torvalds /* otherwise, we can just add the header as usual. */ 5261da177e4SLinus Torvalds _daddr = *(uint8_t *) daddr; 5271da177e4SLinus Torvalds proto_num = lp->default_proto[_daddr]; 5281da177e4SLinus Torvalds proto = arc_proto_map[proto_num]; 5291da177e4SLinus Torvalds BUGMSG(D_DURING, "building header for %02Xh using protocol '%c'\n", 5301da177e4SLinus Torvalds proto_num, proto->suffix); 5311da177e4SLinus Torvalds if (proto == &arc_proto_null && arc_bcast_proto != proto) { 5321da177e4SLinus Torvalds BUGMSG(D_DURING, "actually, let's use '%c' instead.\n", 5331da177e4SLinus Torvalds arc_bcast_proto->suffix); 5341da177e4SLinus Torvalds proto = arc_bcast_proto; 5351da177e4SLinus Torvalds } 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds return proto->build_header(skb, dev, type, _daddr); 5381da177e4SLinus Torvalds } 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds /* 5421da177e4SLinus Torvalds * Rebuild the ARCnet hard header. This is called after an ARP (or in the 5431da177e4SLinus Torvalds * future other address resolution) has completed on this sk_buff. We now 5441da177e4SLinus Torvalds * let ARP fill in the destination field. 5451da177e4SLinus Torvalds */ 5461da177e4SLinus Torvalds static int arcnet_rebuild_header(struct sk_buff *skb) 5471da177e4SLinus Torvalds { 5481da177e4SLinus Torvalds struct net_device *dev = skb->dev; 549454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 5501da177e4SLinus Torvalds int status = 0; /* default is failure */ 5511da177e4SLinus Torvalds unsigned short type; 5521da177e4SLinus Torvalds uint8_t daddr=0; 5531da177e4SLinus Torvalds struct ArcProto *proto; 554b0e380b1SArnaldo Carvalho de Melo /* 555b0e380b1SArnaldo Carvalho de Melo * XXX: Why not use skb->mac_len? 556b0e380b1SArnaldo Carvalho de Melo */ 557b0e380b1SArnaldo Carvalho de Melo if (skb->network_header - skb->mac_header != 2) { 5581da177e4SLinus Torvalds BUGMSG(D_NORMAL, 5591da177e4SLinus Torvalds "rebuild_header: shouldn't be here! (hdrsize=%d)\n", 560b0e380b1SArnaldo Carvalho de Melo (int)(skb->network_header - skb->mac_header)); 5611da177e4SLinus Torvalds return 0; 5621da177e4SLinus Torvalds } 5631da177e4SLinus Torvalds type = *(uint16_t *) skb_pull(skb, 2); 5641da177e4SLinus Torvalds BUGMSG(D_DURING, "rebuild header for protocol %Xh\n", type); 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds if (type == ETH_P_IP) { 5671da177e4SLinus Torvalds #ifdef CONFIG_INET 5681da177e4SLinus Torvalds BUGMSG(D_DURING, "rebuild header for ethernet protocol %Xh\n", type); 5691da177e4SLinus Torvalds status = arp_find(&daddr, skb) ? 1 : 0; 5701da177e4SLinus Torvalds BUGMSG(D_DURING, " rebuilt: dest is %d; protocol %Xh\n", 5711da177e4SLinus Torvalds daddr, type); 5721da177e4SLinus Torvalds #endif 5731da177e4SLinus Torvalds } else { 5741da177e4SLinus Torvalds BUGMSG(D_NORMAL, 5751da177e4SLinus Torvalds "I don't understand ethernet protocol %Xh addresses!\n", type); 5765803c512SStephen Hemminger dev->stats.tx_errors++; 5775803c512SStephen Hemminger dev->stats.tx_aborted_errors++; 5781da177e4SLinus Torvalds } 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds /* if we couldn't resolve the address... give up. */ 5811da177e4SLinus Torvalds if (!status) 5821da177e4SLinus Torvalds return 0; 5831da177e4SLinus Torvalds 5841da177e4SLinus Torvalds /* add the _real_ header this time! */ 5851da177e4SLinus Torvalds proto = arc_proto_map[lp->default_proto[daddr]]; 5861da177e4SLinus Torvalds proto->build_header(skb, dev, type, daddr); 5871da177e4SLinus Torvalds 5881da177e4SLinus Torvalds return 1; /* success */ 5891da177e4SLinus Torvalds } 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds 5921da177e4SLinus Torvalds 5931da177e4SLinus Torvalds /* Called by the kernel in order to transmit a packet. */ 59461357325SStephen Hemminger netdev_tx_t arcnet_send_packet(struct sk_buff *skb, 59561357325SStephen Hemminger struct net_device *dev) 5961da177e4SLinus Torvalds { 597454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 5981da177e4SLinus Torvalds struct archdr *pkt; 5991da177e4SLinus Torvalds struct arc_rfc1201 *soft; 6001da177e4SLinus Torvalds struct ArcProto *proto; 6011da177e4SLinus Torvalds int txbuf; 6021da177e4SLinus Torvalds unsigned long flags; 603c6bb15a0SPieter Dejaeghere int freeskb, retval; 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds BUGMSG(D_DURING, 6061da177e4SLinus Torvalds "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n", 6071da177e4SLinus Torvalds ASTATUS(), lp->cur_tx, lp->next_tx, skb->len,skb->protocol); 6081da177e4SLinus Torvalds 6091da177e4SLinus Torvalds pkt = (struct archdr *) skb->data; 6101da177e4SLinus Torvalds soft = &pkt->soft.rfc1201; 6111da177e4SLinus Torvalds proto = arc_proto_map[soft->proto]; 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds BUGMSG(D_SKB_SIZE, "skb: transmitting %d bytes to %02X\n", 6141da177e4SLinus Torvalds skb->len, pkt->hard.dest); 6151da177e4SLinus Torvalds BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "tx"); 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds /* fits in one packet? */ 6181da177e4SLinus Torvalds if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) { 6191da177e4SLinus Torvalds BUGMSG(D_NORMAL, "fixme: packet too large: compensating badly!\n"); 6201da177e4SLinus Torvalds dev_kfree_skb(skb); 621c6bb15a0SPieter Dejaeghere return NETDEV_TX_OK; /* don't try again */ 6221da177e4SLinus Torvalds } 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds /* We're busy transmitting a packet... */ 6251da177e4SLinus Torvalds netif_stop_queue(dev); 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags); 6281da177e4SLinus Torvalds AINTMASK(0); 629c6bb15a0SPieter Dejaeghere if(lp->next_tx == -1) 6301da177e4SLinus Torvalds txbuf = get_arcbuf(dev); 631c6bb15a0SPieter Dejaeghere else { 632c6bb15a0SPieter Dejaeghere txbuf = -1; 633c6bb15a0SPieter Dejaeghere } 6341da177e4SLinus Torvalds if (txbuf != -1) { 6351da177e4SLinus Torvalds if (proto->prepare_tx(dev, pkt, skb->len, txbuf) && 6361da177e4SLinus Torvalds !proto->ack_tx) { 6371da177e4SLinus Torvalds /* done right away and we don't want to acknowledge 6381da177e4SLinus Torvalds the package later - forget about it now */ 6395803c512SStephen Hemminger dev->stats.tx_bytes += skb->len; 6401da177e4SLinus Torvalds freeskb = 1; 6411da177e4SLinus Torvalds } else { 6421da177e4SLinus Torvalds /* do it the 'split' way */ 6431da177e4SLinus Torvalds lp->outgoing.proto = proto; 6441da177e4SLinus Torvalds lp->outgoing.skb = skb; 6451da177e4SLinus Torvalds lp->outgoing.pkt = pkt; 6461da177e4SLinus Torvalds 647c6bb15a0SPieter Dejaeghere freeskb = 0; 648c6bb15a0SPieter Dejaeghere 6491da177e4SLinus Torvalds if (proto->continue_tx && 6501da177e4SLinus Torvalds proto->continue_tx(dev, txbuf)) { 6511da177e4SLinus Torvalds BUGMSG(D_NORMAL, 6521da177e4SLinus Torvalds "bug! continue_tx finished the first time! " 6531da177e4SLinus Torvalds "(proto='%c')\n", proto->suffix); 6541da177e4SLinus Torvalds } 6551da177e4SLinus Torvalds } 656c6bb15a0SPieter Dejaeghere retval = NETDEV_TX_OK; 6571da177e4SLinus Torvalds lp->next_tx = txbuf; 6581da177e4SLinus Torvalds } else { 659c6bb15a0SPieter Dejaeghere retval = NETDEV_TX_BUSY; 660c6bb15a0SPieter Dejaeghere freeskb = 0; 6611da177e4SLinus Torvalds } 6621da177e4SLinus Torvalds 663b39d66a8SHarvey Harrison BUGMSG(D_DEBUG, "%s: %d: %s, status: %x\n",__FILE__,__LINE__,__func__,ASTATUS()); 6641da177e4SLinus Torvalds /* make sure we didn't ignore a TX IRQ while we were in here */ 6651da177e4SLinus Torvalds AINTMASK(0); 6661da177e4SLinus Torvalds 667b39d66a8SHarvey Harrison BUGMSG(D_DEBUG, "%s: %d: %s\n",__FILE__,__LINE__,__func__); 6681da177e4SLinus Torvalds lp->intmask |= TXFREEflag|EXCNAKflag; 6691da177e4SLinus Torvalds AINTMASK(lp->intmask); 670b39d66a8SHarvey Harrison BUGMSG(D_DEBUG, "%s: %d: %s, status: %x\n",__FILE__,__LINE__,__func__,ASTATUS()); 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags); 6731da177e4SLinus Torvalds if (freeskb) { 6741da177e4SLinus Torvalds dev_kfree_skb(skb); 6751da177e4SLinus Torvalds } 676c6bb15a0SPieter Dejaeghere return retval; /* no need to try again */ 6771da177e4SLinus Torvalds } 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds 6801da177e4SLinus Torvalds /* 6811da177e4SLinus Torvalds * Actually start transmitting a packet that was loaded into a buffer 6821da177e4SLinus Torvalds * by prepare_tx. This should _only_ be called by the interrupt handler. 6831da177e4SLinus Torvalds */ 6841da177e4SLinus Torvalds static int go_tx(struct net_device *dev) 6851da177e4SLinus Torvalds { 686454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds BUGMSG(D_DURING, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n", 6891da177e4SLinus Torvalds ASTATUS(), lp->intmask, lp->next_tx, lp->cur_tx); 6901da177e4SLinus Torvalds 6911da177e4SLinus Torvalds if (lp->cur_tx != -1 || lp->next_tx == -1) 6921da177e4SLinus Torvalds return 0; 6931da177e4SLinus Torvalds 6941da177e4SLinus Torvalds BUGLVL(D_TX) arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0); 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds lp->cur_tx = lp->next_tx; 6971da177e4SLinus Torvalds lp->next_tx = -1; 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds /* start sending */ 7001da177e4SLinus Torvalds ACOMMAND(TXcmd | (lp->cur_tx << 3)); 7011da177e4SLinus Torvalds 7025803c512SStephen Hemminger dev->stats.tx_packets++; 7031da177e4SLinus Torvalds lp->lasttrans_dest = lp->lastload_dest; 7041da177e4SLinus Torvalds lp->lastload_dest = 0; 7051da177e4SLinus Torvalds lp->excnak_pending = 0; 7061da177e4SLinus Torvalds lp->intmask |= TXFREEflag|EXCNAKflag; 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds return 1; 7091da177e4SLinus Torvalds } 7101da177e4SLinus Torvalds 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds /* Called by the kernel when transmit times out */ 713bca5b893SStephen Hemminger void arcnet_timeout(struct net_device *dev) 7141da177e4SLinus Torvalds { 7151da177e4SLinus Torvalds unsigned long flags; 716454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 7171da177e4SLinus Torvalds int status = ASTATUS(); 7181da177e4SLinus Torvalds char *msg; 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags); 7211da177e4SLinus Torvalds if (status & TXFREEflag) { /* transmit _DID_ finish */ 7221da177e4SLinus Torvalds msg = " - missed IRQ?"; 7231da177e4SLinus Torvalds } else { 7241da177e4SLinus Torvalds msg = ""; 7255803c512SStephen Hemminger dev->stats.tx_aborted_errors++; 7261da177e4SLinus Torvalds lp->timed_out = 1; 7271da177e4SLinus Torvalds ACOMMAND(NOTXcmd | (lp->cur_tx << 3)); 7281da177e4SLinus Torvalds } 7295803c512SStephen Hemminger dev->stats.tx_errors++; 7301da177e4SLinus Torvalds 7311da177e4SLinus Torvalds /* make sure we didn't miss a TX or a EXC NAK IRQ */ 7321da177e4SLinus Torvalds AINTMASK(0); 7331da177e4SLinus Torvalds lp->intmask |= TXFREEflag|EXCNAKflag; 7341da177e4SLinus Torvalds AINTMASK(lp->intmask); 7351da177e4SLinus Torvalds 7361da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags); 7371da177e4SLinus Torvalds 738ff5688aeSMarcelo Feitoza Parisi if (time_after(jiffies, lp->last_timeout + 10*HZ)) { 7391da177e4SLinus Torvalds BUGMSG(D_EXTRA, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n", 7401da177e4SLinus Torvalds msg, status, lp->intmask, lp->lasttrans_dest); 7411da177e4SLinus Torvalds lp->last_timeout = jiffies; 7421da177e4SLinus Torvalds } 7431da177e4SLinus Torvalds 7441da177e4SLinus Torvalds if (lp->cur_tx == -1) 7451da177e4SLinus Torvalds netif_wake_queue(dev); 7461da177e4SLinus Torvalds } 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds /* 7501da177e4SLinus Torvalds * The typical workload of the driver: Handle the network interface 7511da177e4SLinus Torvalds * interrupts. Establish which device needs attention, and call the correct 7521da177e4SLinus Torvalds * chipset interrupt handler. 7531da177e4SLinus Torvalds */ 7547d12e780SDavid Howells irqreturn_t arcnet_interrupt(int irq, void *dev_id) 7551da177e4SLinus Torvalds { 7561da177e4SLinus Torvalds struct net_device *dev = dev_id; 7571da177e4SLinus Torvalds struct arcnet_local *lp; 7581da177e4SLinus Torvalds int recbuf, status, diagstatus, didsomething, boguscount; 7591da177e4SLinus Torvalds int retval = IRQ_NONE; 7601da177e4SLinus Torvalds 7611da177e4SLinus Torvalds BUGMSG(D_DURING, "\n"); 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds BUGMSG(D_DURING, "in arcnet_interrupt\n"); 7641da177e4SLinus Torvalds 765454d7c9bSWang Chen lp = netdev_priv(dev); 7665d9428deSEric Sesterhenn BUG_ON(!lp); 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds spin_lock(&lp->lock); 7691da177e4SLinus Torvalds 7701da177e4SLinus Torvalds /* 7711da177e4SLinus Torvalds * RESET flag was enabled - if device is not running, we must clear it right 7721da177e4SLinus Torvalds * away (but nothing else). 7731da177e4SLinus Torvalds */ 7741da177e4SLinus Torvalds if (!netif_running(dev)) { 7751da177e4SLinus Torvalds if (ASTATUS() & RESETflag) 7761da177e4SLinus Torvalds ACOMMAND(CFLAGScmd | RESETclear); 7771da177e4SLinus Torvalds AINTMASK(0); 7781da177e4SLinus Torvalds spin_unlock(&lp->lock); 7791da177e4SLinus Torvalds return IRQ_HANDLED; 7801da177e4SLinus Torvalds } 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds BUGMSG(D_DURING, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n", 7831da177e4SLinus Torvalds ASTATUS(), lp->intmask); 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds boguscount = 5; 7861da177e4SLinus Torvalds do { 7871da177e4SLinus Torvalds status = ASTATUS(); 7881da177e4SLinus Torvalds diagstatus = (status >> 8) & 0xFF; 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds BUGMSG(D_DEBUG, "%s: %d: %s: status=%x\n", 791b39d66a8SHarvey Harrison __FILE__,__LINE__,__func__,status); 7921da177e4SLinus Torvalds didsomething = 0; 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds /* 7951da177e4SLinus Torvalds * RESET flag was enabled - card is resetting and if RX is 7961da177e4SLinus Torvalds * disabled, it's NOT because we just got a packet. 7971da177e4SLinus Torvalds * 7981da177e4SLinus Torvalds * The card is in an undefined state. Clear it out and start over. 7991da177e4SLinus Torvalds */ 8001da177e4SLinus Torvalds if (status & RESETflag) { 8011da177e4SLinus Torvalds BUGMSG(D_NORMAL, "spurious reset (status=%Xh)\n", status); 8021da177e4SLinus Torvalds arcnet_close(dev); 8031da177e4SLinus Torvalds arcnet_open(dev); 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds /* get out of the interrupt handler! */ 8061da177e4SLinus Torvalds break; 8071da177e4SLinus Torvalds } 8081da177e4SLinus Torvalds /* 8091da177e4SLinus Torvalds * RX is inhibited - we must have received something. Prepare to 8101da177e4SLinus Torvalds * receive into the next buffer. 8111da177e4SLinus Torvalds * 8121da177e4SLinus Torvalds * We don't actually copy the received packet from the card until 8131da177e4SLinus Torvalds * after the transmit handler runs (and possibly launches the next 8141da177e4SLinus Torvalds * tx); this should improve latency slightly if we get both types 8151da177e4SLinus Torvalds * of interrupts at once. 8161da177e4SLinus Torvalds */ 8171da177e4SLinus Torvalds recbuf = -1; 8181da177e4SLinus Torvalds if (status & lp->intmask & NORXflag) { 8191da177e4SLinus Torvalds recbuf = lp->cur_rx; 8201da177e4SLinus Torvalds BUGMSG(D_DURING, "Buffer #%d: receive irq (status=%Xh)\n", 8211da177e4SLinus Torvalds recbuf, status); 8221da177e4SLinus Torvalds 8231da177e4SLinus Torvalds lp->cur_rx = get_arcbuf(dev); 8241da177e4SLinus Torvalds if (lp->cur_rx != -1) { 8251da177e4SLinus Torvalds BUGMSG(D_DURING, "enabling receive to buffer #%d\n", 8261da177e4SLinus Torvalds lp->cur_rx); 8271da177e4SLinus Torvalds ACOMMAND(RXcmd | (lp->cur_rx << 3) | RXbcasts); 8281da177e4SLinus Torvalds } 8291da177e4SLinus Torvalds didsomething++; 8301da177e4SLinus Torvalds } 8311da177e4SLinus Torvalds 8321da177e4SLinus Torvalds if((diagstatus & EXCNAKflag)) { 8331da177e4SLinus Torvalds BUGMSG(D_DURING, "EXCNAK IRQ (diagstat=%Xh)\n", 8341da177e4SLinus Torvalds diagstatus); 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds ACOMMAND(NOTXcmd); /* disable transmit */ 8371da177e4SLinus Torvalds lp->excnak_pending = 1; 8381da177e4SLinus Torvalds 8391da177e4SLinus Torvalds ACOMMAND(EXCNAKclear); 8401da177e4SLinus Torvalds lp->intmask &= ~(EXCNAKflag); 8411da177e4SLinus Torvalds didsomething++; 8421da177e4SLinus Torvalds } 8431da177e4SLinus Torvalds 8441da177e4SLinus Torvalds 8451da177e4SLinus Torvalds /* a transmit finished, and we're interested in it. */ 8461da177e4SLinus Torvalds if ((status & lp->intmask & TXFREEflag) || lp->timed_out) { 8471da177e4SLinus Torvalds lp->intmask &= ~(TXFREEflag|EXCNAKflag); 8481da177e4SLinus Torvalds 8491da177e4SLinus Torvalds BUGMSG(D_DURING, "TX IRQ (stat=%Xh)\n", status); 8501da177e4SLinus Torvalds 8511da177e4SLinus Torvalds if (lp->cur_tx != -1 && !lp->timed_out) { 8521da177e4SLinus Torvalds if(!(status & TXACKflag)) { 8531da177e4SLinus Torvalds if (lp->lasttrans_dest != 0) { 8541da177e4SLinus Torvalds BUGMSG(D_EXTRA, 8551da177e4SLinus Torvalds "transmit was not acknowledged! " 8561da177e4SLinus Torvalds "(status=%Xh, dest=%02Xh)\n", 8571da177e4SLinus Torvalds status, lp->lasttrans_dest); 8585803c512SStephen Hemminger dev->stats.tx_errors++; 8595803c512SStephen Hemminger dev->stats.tx_carrier_errors++; 8601da177e4SLinus Torvalds } else { 8611da177e4SLinus Torvalds BUGMSG(D_DURING, 8621da177e4SLinus Torvalds "broadcast was not acknowledged; that's normal " 8631da177e4SLinus Torvalds "(status=%Xh, dest=%02Xh)\n", 8641da177e4SLinus Torvalds status, lp->lasttrans_dest); 8651da177e4SLinus Torvalds } 8661da177e4SLinus Torvalds } 8671da177e4SLinus Torvalds 8681da177e4SLinus Torvalds if (lp->outgoing.proto && 8691da177e4SLinus Torvalds lp->outgoing.proto->ack_tx) { 8701da177e4SLinus Torvalds int ackstatus; 8711da177e4SLinus Torvalds if(status & TXACKflag) 8721da177e4SLinus Torvalds ackstatus=2; 8731da177e4SLinus Torvalds else if(lp->excnak_pending) 8741da177e4SLinus Torvalds ackstatus=1; 8751da177e4SLinus Torvalds else 8761da177e4SLinus Torvalds ackstatus=0; 8771da177e4SLinus Torvalds 8781da177e4SLinus Torvalds lp->outgoing.proto 8791da177e4SLinus Torvalds ->ack_tx(dev, ackstatus); 8801da177e4SLinus Torvalds } 8811da177e4SLinus Torvalds } 8821da177e4SLinus Torvalds if (lp->cur_tx != -1) 8831da177e4SLinus Torvalds release_arcbuf(dev, lp->cur_tx); 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds lp->cur_tx = -1; 8861da177e4SLinus Torvalds lp->timed_out = 0; 8871da177e4SLinus Torvalds didsomething++; 8881da177e4SLinus Torvalds 8891da177e4SLinus Torvalds /* send another packet if there is one */ 8901da177e4SLinus Torvalds go_tx(dev); 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds /* continue a split packet, if any */ 8931da177e4SLinus Torvalds if (lp->outgoing.proto && lp->outgoing.proto->continue_tx) { 8941da177e4SLinus Torvalds int txbuf = get_arcbuf(dev); 8951da177e4SLinus Torvalds if (txbuf != -1) { 8961da177e4SLinus Torvalds if (lp->outgoing.proto->continue_tx(dev, txbuf)) { 8971da177e4SLinus Torvalds /* that was the last segment */ 8985803c512SStephen Hemminger dev->stats.tx_bytes += lp->outgoing.skb->len; 8991da177e4SLinus Torvalds if(!lp->outgoing.proto->ack_tx) 9001da177e4SLinus Torvalds { 9011da177e4SLinus Torvalds dev_kfree_skb_irq(lp->outgoing.skb); 9021da177e4SLinus Torvalds lp->outgoing.proto = NULL; 9031da177e4SLinus Torvalds } 9041da177e4SLinus Torvalds } 9051da177e4SLinus Torvalds lp->next_tx = txbuf; 9061da177e4SLinus Torvalds } 9071da177e4SLinus Torvalds } 9081da177e4SLinus Torvalds /* inform upper layers of idleness, if necessary */ 9091da177e4SLinus Torvalds if (lp->cur_tx == -1) 9101da177e4SLinus Torvalds netif_wake_queue(dev); 9111da177e4SLinus Torvalds } 9121da177e4SLinus Torvalds /* now process the received packet, if any */ 9131da177e4SLinus Torvalds if (recbuf != -1) { 9141da177e4SLinus Torvalds BUGLVL(D_RX) arcnet_dump_packet(dev, recbuf, "rx irq", 0); 9151da177e4SLinus Torvalds 9161da177e4SLinus Torvalds arcnet_rx(dev, recbuf); 9171da177e4SLinus Torvalds release_arcbuf(dev, recbuf); 9181da177e4SLinus Torvalds 9191da177e4SLinus Torvalds didsomething++; 9201da177e4SLinus Torvalds } 9211da177e4SLinus Torvalds if (status & lp->intmask & RECONflag) { 9221da177e4SLinus Torvalds ACOMMAND(CFLAGScmd | CONFIGclear); 9235803c512SStephen Hemminger dev->stats.tx_carrier_errors++; 9241da177e4SLinus Torvalds 9251da177e4SLinus Torvalds BUGMSG(D_RECON, "Network reconfiguration detected (status=%Xh)\n", 9261da177e4SLinus Torvalds status); 927c6bb15a0SPieter Dejaeghere /* MYRECON bit is at bit 7 of diagstatus */ 928c6bb15a0SPieter Dejaeghere if(diagstatus & 0x80) 929c6bb15a0SPieter Dejaeghere BUGMSG(D_RECON,"Put out that recon myself\n"); 9301da177e4SLinus Torvalds 9311da177e4SLinus Torvalds /* is the RECON info empty or old? */ 9321da177e4SLinus Torvalds if (!lp->first_recon || !lp->last_recon || 9339307b570SS.Caglar Onur time_after(jiffies, lp->last_recon + HZ * 10)) { 9341da177e4SLinus Torvalds if (lp->network_down) 9351da177e4SLinus Torvalds BUGMSG(D_NORMAL, "reconfiguration detected: cabling restored?\n"); 9361da177e4SLinus Torvalds lp->first_recon = lp->last_recon = jiffies; 9371da177e4SLinus Torvalds lp->num_recons = lp->network_down = 0; 9381da177e4SLinus Torvalds 9391da177e4SLinus Torvalds BUGMSG(D_DURING, "recon: clearing counters.\n"); 9401da177e4SLinus Torvalds } else { /* add to current RECON counter */ 9411da177e4SLinus Torvalds lp->last_recon = jiffies; 9421da177e4SLinus Torvalds lp->num_recons++; 9431da177e4SLinus Torvalds 9441da177e4SLinus Torvalds BUGMSG(D_DURING, "recon: counter=%d, time=%lds, net=%d\n", 9451da177e4SLinus Torvalds lp->num_recons, 9461da177e4SLinus Torvalds (lp->last_recon - lp->first_recon) / HZ, 9471da177e4SLinus Torvalds lp->network_down); 9481da177e4SLinus Torvalds 9491da177e4SLinus Torvalds /* if network is marked up; 9501da177e4SLinus Torvalds * and first_recon and last_recon are 60+ apart; 9511da177e4SLinus Torvalds * and the average no. of recons counted is 9521da177e4SLinus Torvalds * > RECON_THRESHOLD/min; 9531da177e4SLinus Torvalds * then print a warning message. 9541da177e4SLinus Torvalds */ 9558e95a202SJoe Perches if (!lp->network_down && 9568e95a202SJoe Perches (lp->last_recon - lp->first_recon) <= HZ * 60 && 9578e95a202SJoe Perches lp->num_recons >= RECON_THRESHOLD) { 9581da177e4SLinus Torvalds lp->network_down = 1; 9591da177e4SLinus Torvalds BUGMSG(D_NORMAL, "many reconfigurations detected: cabling problem?\n"); 9608e95a202SJoe Perches } else if (!lp->network_down && 9618e95a202SJoe Perches lp->last_recon - lp->first_recon > HZ * 60) { 9621da177e4SLinus Torvalds /* reset counters if we've gone for over a minute. */ 9631da177e4SLinus Torvalds lp->first_recon = lp->last_recon; 9641da177e4SLinus Torvalds lp->num_recons = 1; 9651da177e4SLinus Torvalds } 9661da177e4SLinus Torvalds } 9679307b570SS.Caglar Onur } else if (lp->network_down && 9689307b570SS.Caglar Onur time_after(jiffies, lp->last_recon + HZ * 10)) { 9691da177e4SLinus Torvalds if (lp->network_down) 9701da177e4SLinus Torvalds BUGMSG(D_NORMAL, "cabling restored?\n"); 9711da177e4SLinus Torvalds lp->first_recon = lp->last_recon = 0; 9721da177e4SLinus Torvalds lp->num_recons = lp->network_down = 0; 9731da177e4SLinus Torvalds 9741da177e4SLinus Torvalds BUGMSG(D_DURING, "not recon: clearing counters anyway.\n"); 9751da177e4SLinus Torvalds } 9761da177e4SLinus Torvalds 9771da177e4SLinus Torvalds if(didsomething) { 9781da177e4SLinus Torvalds retval |= IRQ_HANDLED; 9791da177e4SLinus Torvalds } 9801da177e4SLinus Torvalds } 9811da177e4SLinus Torvalds while (--boguscount && didsomething); 9821da177e4SLinus Torvalds 9831da177e4SLinus Torvalds BUGMSG(D_DURING, "arcnet_interrupt complete (status=%Xh, count=%d)\n", 9841da177e4SLinus Torvalds ASTATUS(), boguscount); 9851da177e4SLinus Torvalds BUGMSG(D_DURING, "\n"); 9861da177e4SLinus Torvalds 9871da177e4SLinus Torvalds 9881da177e4SLinus Torvalds AINTMASK(0); 9891da177e4SLinus Torvalds udelay(1); 9901da177e4SLinus Torvalds AINTMASK(lp->intmask); 9911da177e4SLinus Torvalds 9921da177e4SLinus Torvalds spin_unlock(&lp->lock); 9931da177e4SLinus Torvalds return retval; 9941da177e4SLinus Torvalds } 9951da177e4SLinus Torvalds 9961da177e4SLinus Torvalds 9971da177e4SLinus Torvalds /* 9981da177e4SLinus Torvalds * This is a generic packet receiver that calls arcnet??_rx depending on the 9991da177e4SLinus Torvalds * protocol ID found. 10001da177e4SLinus Torvalds */ 1001f03aa2d8SAdrian Bunk static void arcnet_rx(struct net_device *dev, int bufnum) 10021da177e4SLinus Torvalds { 1003454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 10041da177e4SLinus Torvalds struct archdr pkt; 10051da177e4SLinus Torvalds struct arc_rfc1201 *soft; 10061da177e4SLinus Torvalds int length, ofs; 10071da177e4SLinus Torvalds 10081da177e4SLinus Torvalds soft = &pkt.soft.rfc1201; 10091da177e4SLinus Torvalds 1010*087d273cSDan Carpenter lp->hw.copy_from_card(dev, bufnum, 0, &pkt, ARC_HDR_SIZE); 10111da177e4SLinus Torvalds if (pkt.hard.offset[0]) { 10121da177e4SLinus Torvalds ofs = pkt.hard.offset[0]; 10131da177e4SLinus Torvalds length = 256 - ofs; 10141da177e4SLinus Torvalds } else { 10151da177e4SLinus Torvalds ofs = pkt.hard.offset[1]; 10161da177e4SLinus Torvalds length = 512 - ofs; 10171da177e4SLinus Torvalds } 10181da177e4SLinus Torvalds 10191da177e4SLinus Torvalds /* get the full header, if possible */ 10201da177e4SLinus Torvalds if (sizeof(pkt.soft) <= length) 10211da177e4SLinus Torvalds lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft)); 10221da177e4SLinus Torvalds else { 10231da177e4SLinus Torvalds memset(&pkt.soft, 0, sizeof(pkt.soft)); 10241da177e4SLinus Torvalds lp->hw.copy_from_card(dev, bufnum, ofs, soft, length); 10251da177e4SLinus Torvalds } 10261da177e4SLinus Torvalds 10271da177e4SLinus Torvalds BUGMSG(D_DURING, "Buffer #%d: received packet from %02Xh to %02Xh " 10281da177e4SLinus Torvalds "(%d+4 bytes)\n", 10291da177e4SLinus Torvalds bufnum, pkt.hard.source, pkt.hard.dest, length); 10301da177e4SLinus Torvalds 10315803c512SStephen Hemminger dev->stats.rx_packets++; 10325803c512SStephen Hemminger dev->stats.rx_bytes += length + ARC_HDR_SIZE; 10331da177e4SLinus Torvalds 10341da177e4SLinus Torvalds /* call the right receiver for the protocol */ 10351da177e4SLinus Torvalds if (arc_proto_map[soft->proto]->is_ip) { 10361da177e4SLinus Torvalds BUGLVL(D_PROTO) { 10371da177e4SLinus Torvalds struct ArcProto 10381da177e4SLinus Torvalds *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]], 10391da177e4SLinus Torvalds *newp = arc_proto_map[soft->proto]; 10401da177e4SLinus Torvalds 10411da177e4SLinus Torvalds if (oldp != newp) { 10421da177e4SLinus Torvalds BUGMSG(D_PROTO, 10431da177e4SLinus Torvalds "got protocol %02Xh; encap for host %02Xh is now '%c'" 10441da177e4SLinus Torvalds " (was '%c')\n", soft->proto, pkt.hard.source, 10451da177e4SLinus Torvalds newp->suffix, oldp->suffix); 10461da177e4SLinus Torvalds } 10471da177e4SLinus Torvalds } 10481da177e4SLinus Torvalds 10491da177e4SLinus Torvalds /* broadcasts will always be done with the last-used encap. */ 10501da177e4SLinus Torvalds lp->default_proto[0] = soft->proto; 10511da177e4SLinus Torvalds 10521da177e4SLinus Torvalds /* in striking contrast, the following isn't a hack. */ 10531da177e4SLinus Torvalds lp->default_proto[pkt.hard.source] = soft->proto; 10541da177e4SLinus Torvalds } 10551da177e4SLinus Torvalds /* call the protocol-specific receiver. */ 10561da177e4SLinus Torvalds arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length); 10571da177e4SLinus Torvalds } 10581da177e4SLinus Torvalds 10591da177e4SLinus Torvalds 10601da177e4SLinus Torvalds static void null_rx(struct net_device *dev, int bufnum, 10611da177e4SLinus Torvalds struct archdr *pkthdr, int length) 10621da177e4SLinus Torvalds { 10631da177e4SLinus Torvalds BUGMSG(D_PROTO, 10641da177e4SLinus Torvalds "rx: don't know how to deal with proto %02Xh from host %02Xh.\n", 10651da177e4SLinus Torvalds pkthdr->soft.rfc1201.proto, pkthdr->hard.source); 10661da177e4SLinus Torvalds } 10671da177e4SLinus Torvalds 10681da177e4SLinus Torvalds 10691da177e4SLinus Torvalds static int null_build_header(struct sk_buff *skb, struct net_device *dev, 10701da177e4SLinus Torvalds unsigned short type, uint8_t daddr) 10711da177e4SLinus Torvalds { 1072454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 10731da177e4SLinus Torvalds 10741da177e4SLinus Torvalds BUGMSG(D_PROTO, 10751da177e4SLinus Torvalds "tx: can't build header for encap %02Xh; load a protocol driver.\n", 10761da177e4SLinus Torvalds lp->default_proto[daddr]); 10771da177e4SLinus Torvalds 10781da177e4SLinus Torvalds /* always fails */ 10791da177e4SLinus Torvalds return 0; 10801da177e4SLinus Torvalds } 10811da177e4SLinus Torvalds 10821da177e4SLinus Torvalds 10831da177e4SLinus Torvalds /* the "do nothing" prepare_tx function warns that there's nothing to do. */ 10841da177e4SLinus Torvalds static int null_prepare_tx(struct net_device *dev, struct archdr *pkt, 10851da177e4SLinus Torvalds int length, int bufnum) 10861da177e4SLinus Torvalds { 1087454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 10881da177e4SLinus Torvalds struct arc_hardware newpkt; 10891da177e4SLinus Torvalds 10901da177e4SLinus Torvalds BUGMSG(D_PROTO, "tx: no encap for this host; load a protocol driver.\n"); 10911da177e4SLinus Torvalds 10921da177e4SLinus Torvalds /* send a packet to myself -- will never get received, of course */ 10931da177e4SLinus Torvalds newpkt.source = newpkt.dest = dev->dev_addr[0]; 10941da177e4SLinus Torvalds 10951da177e4SLinus Torvalds /* only one byte of actual data (and it's random) */ 10961da177e4SLinus Torvalds newpkt.offset[0] = 0xFF; 10971da177e4SLinus Torvalds 10981da177e4SLinus Torvalds lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE); 10991da177e4SLinus Torvalds 11001da177e4SLinus Torvalds return 1; /* done */ 11011da177e4SLinus Torvalds } 1102