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 4405a24b23SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 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> 53ff5688aeSMarcelo Feitoza Parisi #include <linux/jiffies.h> 541da177e4SLinus Torvalds 558890624aSMichael Grzeschik #include <linux/leds.h> 568890624aSMichael Grzeschik 5726c6d281SJoe Perches #include "arcdevice.h" 588e0f295eSJoe Perches #include "com9026.h" 5926c6d281SJoe Perches 601da177e4SLinus Torvalds /* "do nothing" functions for protocol drivers */ 611da177e4SLinus Torvalds static void null_rx(struct net_device *dev, int bufnum, 621da177e4SLinus Torvalds struct archdr *pkthdr, int length); 631da177e4SLinus Torvalds static int null_build_header(struct sk_buff *skb, struct net_device *dev, 641da177e4SLinus Torvalds unsigned short type, uint8_t daddr); 651da177e4SLinus Torvalds static int null_prepare_tx(struct net_device *dev, struct archdr *pkt, 661da177e4SLinus Torvalds int length, int bufnum); 671da177e4SLinus Torvalds 68f03aa2d8SAdrian Bunk static void arcnet_rx(struct net_device *dev, int bufnum); 691da177e4SLinus Torvalds 70f2f0a16bSJoe Perches /* one ArcProto per possible proto ID. None of the elements of 711da177e4SLinus Torvalds * arc_proto_map are allowed to be NULL; they will get set to 721da177e4SLinus Torvalds * arc_proto_default instead. It also must not be NULL; if you would like 731da177e4SLinus Torvalds * to set it to NULL, set it to &arc_proto_null instead. 741da177e4SLinus Torvalds */ 75811eafc0SJoe Perches struct ArcProto *arc_proto_map[256]; 76811eafc0SJoe Perches EXPORT_SYMBOL(arc_proto_map); 77811eafc0SJoe Perches 78811eafc0SJoe Perches struct ArcProto *arc_proto_default; 79811eafc0SJoe Perches EXPORT_SYMBOL(arc_proto_default); 80811eafc0SJoe Perches 81811eafc0SJoe Perches struct ArcProto *arc_bcast_proto; 82811eafc0SJoe Perches EXPORT_SYMBOL(arc_bcast_proto); 83811eafc0SJoe Perches 84811eafc0SJoe Perches struct ArcProto *arc_raw_proto; 85811eafc0SJoe Perches EXPORT_SYMBOL(arc_raw_proto); 861da177e4SLinus Torvalds 877f5e760cSJoe Perches static struct ArcProto arc_proto_null = { 881da177e4SLinus Torvalds .suffix = '?', 891da177e4SLinus Torvalds .mtu = XMTU, 901da177e4SLinus Torvalds .is_ip = 0, 911da177e4SLinus Torvalds .rx = null_rx, 921da177e4SLinus Torvalds .build_header = null_build_header, 931da177e4SLinus Torvalds .prepare_tx = null_prepare_tx, 941da177e4SLinus Torvalds .continue_tx = NULL, 951da177e4SLinus Torvalds .ack_tx = NULL 961da177e4SLinus Torvalds }; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds /* Exported function prototypes */ 991da177e4SLinus Torvalds int arcnet_debug = ARCNET_DEBUG; 1001da177e4SLinus Torvalds EXPORT_SYMBOL(arcnet_debug); 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds /* Internal function prototypes */ 1031da177e4SLinus Torvalds static int arcnet_header(struct sk_buff *skb, struct net_device *dev, 1043b04dddeSStephen Hemminger unsigned short type, const void *daddr, 1053b04dddeSStephen Hemminger const void *saddr, unsigned len); 1061da177e4SLinus Torvalds static int go_tx(struct net_device *dev); 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds static int debug = ARCNET_DEBUG; 1091da177e4SLinus Torvalds module_param(debug, int, 0); 1101da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds static int __init arcnet_init(void) 1131da177e4SLinus Torvalds { 1141da177e4SLinus Torvalds int count; 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds arcnet_debug = debug; 1171da177e4SLinus Torvalds 11805a24b23SJoe Perches pr_info("arcnet loaded\n"); 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds /* initialize the protocol map */ 1211da177e4SLinus Torvalds arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null; 1221da177e4SLinus Torvalds for (count = 0; count < 256; count++) 1231da177e4SLinus Torvalds arc_proto_map[count] = arc_proto_default; 1241da177e4SLinus Torvalds 12572aeea48SJoe Perches if (BUGLVL(D_DURING)) 126*5b5e0928SAlexey Dobriyan pr_info("struct sizes: %zd %zd %zd %zd %zd\n", 12705a24b23SJoe Perches sizeof(struct arc_hardware), 12805a24b23SJoe Perches sizeof(struct arc_rfc1201), 12905a24b23SJoe Perches sizeof(struct arc_rfc1051), 13005a24b23SJoe Perches sizeof(struct arc_eth_encap), 1311da177e4SLinus Torvalds sizeof(struct archdr)); 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds return 0; 1341da177e4SLinus Torvalds } 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds static void __exit arcnet_exit(void) 1371da177e4SLinus Torvalds { 1381da177e4SLinus Torvalds } 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds module_init(arcnet_init); 1411da177e4SLinus Torvalds module_exit(arcnet_exit); 1421da177e4SLinus Torvalds 143f2f0a16bSJoe Perches /* Dump the contents of an sk_buff */ 1441da177e4SLinus Torvalds #if ARCNET_DEBUG_MAX & D_SKB 1451da177e4SLinus Torvalds void arcnet_dump_skb(struct net_device *dev, 1461da177e4SLinus Torvalds struct sk_buff *skb, char *desc) 1471da177e4SLinus Torvalds { 148ad361c98SJoe Perches char hdr[32]; 1491da177e4SLinus Torvalds 150ad361c98SJoe Perches /* dump the packet */ 151ad361c98SJoe Perches snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc); 152ad361c98SJoe Perches print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET, 153ad361c98SJoe Perches 16, 1, skb->data, skb->len, true); 1541da177e4SLinus Torvalds } 1551da177e4SLinus Torvalds EXPORT_SYMBOL(arcnet_dump_skb); 1561da177e4SLinus Torvalds #endif 1571da177e4SLinus Torvalds 158f2f0a16bSJoe Perches /* Dump the contents of an ARCnet buffer */ 1591da177e4SLinus Torvalds #if (ARCNET_DEBUG_MAX & (D_RX | D_TX)) 160f03aa2d8SAdrian Bunk static void arcnet_dump_packet(struct net_device *dev, int bufnum, 161f03aa2d8SAdrian Bunk char *desc, int take_arcnet_lock) 1621da177e4SLinus Torvalds { 163454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 1641da177e4SLinus Torvalds int i, length; 1651da177e4SLinus Torvalds unsigned long flags = 0; 1661da177e4SLinus Torvalds static uint8_t buf[512]; 167ad361c98SJoe Perches char hdr[32]; 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds /* hw.copy_from_card expects IRQ context so take the IRQ lock 170f2f0a16bSJoe Perches * to keep it single threaded 171f2f0a16bSJoe Perches */ 1721da177e4SLinus Torvalds if (take_arcnet_lock) 1731da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags); 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds lp->hw.copy_from_card(dev, bufnum, 0, buf, 512); 1761da177e4SLinus Torvalds if (take_arcnet_lock) 1771da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags); 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds /* if the offset[0] byte is nonzero, this is a 256-byte packet */ 1801da177e4SLinus Torvalds length = (buf[2] ? 256 : 512); 1811da177e4SLinus Torvalds 182ad361c98SJoe Perches /* dump the packet */ 183ad361c98SJoe Perches snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc); 184ad361c98SJoe Perches print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET, 185ad361c98SJoe Perches 16, 1, buf, length, true); 1861da177e4SLinus Torvalds } 1871da177e4SLinus Torvalds 188f03aa2d8SAdrian Bunk #else 189f03aa2d8SAdrian Bunk 190f03aa2d8SAdrian Bunk #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0) 191f03aa2d8SAdrian Bunk 1921da177e4SLinus Torvalds #endif 1931da177e4SLinus Torvalds 1948890624aSMichael Grzeschik /* Trigger a LED event in response to a ARCNET device event */ 1958890624aSMichael Grzeschik void arcnet_led_event(struct net_device *dev, enum arcnet_led_event event) 1968890624aSMichael Grzeschik { 1978890624aSMichael Grzeschik struct arcnet_local *lp = netdev_priv(dev); 1988890624aSMichael Grzeschik unsigned long led_delay = 350; 1998890624aSMichael Grzeschik unsigned long tx_delay = 50; 2008890624aSMichael Grzeschik 2018890624aSMichael Grzeschik switch (event) { 2028890624aSMichael Grzeschik case ARCNET_LED_EVENT_RECON: 2038890624aSMichael Grzeschik led_trigger_blink_oneshot(lp->recon_led_trig, 2048890624aSMichael Grzeschik &led_delay, &led_delay, 0); 2058890624aSMichael Grzeschik break; 2068890624aSMichael Grzeschik case ARCNET_LED_EVENT_OPEN: 2078890624aSMichael Grzeschik led_trigger_event(lp->tx_led_trig, LED_OFF); 2088890624aSMichael Grzeschik led_trigger_event(lp->recon_led_trig, LED_OFF); 2098890624aSMichael Grzeschik break; 2108890624aSMichael Grzeschik case ARCNET_LED_EVENT_STOP: 2118890624aSMichael Grzeschik led_trigger_event(lp->tx_led_trig, LED_OFF); 2128890624aSMichael Grzeschik led_trigger_event(lp->recon_led_trig, LED_OFF); 2138890624aSMichael Grzeschik break; 2148890624aSMichael Grzeschik case ARCNET_LED_EVENT_TX: 2158890624aSMichael Grzeschik led_trigger_blink_oneshot(lp->tx_led_trig, 2168890624aSMichael Grzeschik &tx_delay, &tx_delay, 0); 2178890624aSMichael Grzeschik break; 2188890624aSMichael Grzeschik } 2198890624aSMichael Grzeschik } 2208890624aSMichael Grzeschik EXPORT_SYMBOL_GPL(arcnet_led_event); 2218890624aSMichael Grzeschik 2228890624aSMichael Grzeschik static void arcnet_led_release(struct device *gendev, void *res) 2238890624aSMichael Grzeschik { 2248890624aSMichael Grzeschik struct arcnet_local *lp = netdev_priv(to_net_dev(gendev)); 2258890624aSMichael Grzeschik 2268890624aSMichael Grzeschik led_trigger_unregister_simple(lp->tx_led_trig); 2278890624aSMichael Grzeschik led_trigger_unregister_simple(lp->recon_led_trig); 2288890624aSMichael Grzeschik } 2298890624aSMichael Grzeschik 2308890624aSMichael Grzeschik /* Register ARCNET LED triggers for a arcnet device 2318890624aSMichael Grzeschik * 2328890624aSMichael Grzeschik * This is normally called from a driver's probe function 2338890624aSMichael Grzeschik */ 2348890624aSMichael Grzeschik void devm_arcnet_led_init(struct net_device *netdev, int index, int subid) 2358890624aSMichael Grzeschik { 2368890624aSMichael Grzeschik struct arcnet_local *lp = netdev_priv(netdev); 2378890624aSMichael Grzeschik void *res; 2388890624aSMichael Grzeschik 2398890624aSMichael Grzeschik res = devres_alloc(arcnet_led_release, 0, GFP_KERNEL); 2408890624aSMichael Grzeschik if (!res) { 2418890624aSMichael Grzeschik netdev_err(netdev, "cannot register LED triggers\n"); 2428890624aSMichael Grzeschik return; 2438890624aSMichael Grzeschik } 2448890624aSMichael Grzeschik 2458890624aSMichael Grzeschik snprintf(lp->tx_led_trig_name, sizeof(lp->tx_led_trig_name), 2468890624aSMichael Grzeschik "arc%d-%d-tx", index, subid); 2478890624aSMichael Grzeschik snprintf(lp->recon_led_trig_name, sizeof(lp->recon_led_trig_name), 2488890624aSMichael Grzeschik "arc%d-%d-recon", index, subid); 2498890624aSMichael Grzeschik 2508890624aSMichael Grzeschik led_trigger_register_simple(lp->tx_led_trig_name, 2518890624aSMichael Grzeschik &lp->tx_led_trig); 2528890624aSMichael Grzeschik led_trigger_register_simple(lp->recon_led_trig_name, 2538890624aSMichael Grzeschik &lp->recon_led_trig); 2548890624aSMichael Grzeschik 2558890624aSMichael Grzeschik devres_add(&netdev->dev, res); 2568890624aSMichael Grzeschik } 2578890624aSMichael Grzeschik EXPORT_SYMBOL_GPL(devm_arcnet_led_init); 2588890624aSMichael Grzeschik 259f2f0a16bSJoe Perches /* Unregister a protocol driver from the arc_proto_map. Protocol drivers 2601da177e4SLinus Torvalds * are responsible for registering themselves, but the unregister routine 2611da177e4SLinus Torvalds * is pretty generic so we'll do it here. 2621da177e4SLinus Torvalds */ 2631da177e4SLinus Torvalds void arcnet_unregister_proto(struct ArcProto *proto) 2641da177e4SLinus Torvalds { 2651da177e4SLinus Torvalds int count; 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds if (arc_proto_default == proto) 2681da177e4SLinus Torvalds arc_proto_default = &arc_proto_null; 2691da177e4SLinus Torvalds if (arc_bcast_proto == proto) 2701da177e4SLinus Torvalds arc_bcast_proto = arc_proto_default; 2711da177e4SLinus Torvalds if (arc_raw_proto == proto) 2721da177e4SLinus Torvalds arc_raw_proto = arc_proto_default; 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds for (count = 0; count < 256; count++) { 2751da177e4SLinus Torvalds if (arc_proto_map[count] == proto) 2761da177e4SLinus Torvalds arc_proto_map[count] = arc_proto_default; 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds } 279811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_unregister_proto); 2801da177e4SLinus Torvalds 281f2f0a16bSJoe Perches /* Add a buffer to the queue. Only the interrupt handler is allowed to do 2821da177e4SLinus Torvalds * this, unless interrupts are disabled. 2831da177e4SLinus Torvalds * 2841da177e4SLinus Torvalds * Note: we don't check for a full queue, since there aren't enough buffers 2851da177e4SLinus Torvalds * to more than fill it. 2861da177e4SLinus Torvalds */ 2871da177e4SLinus Torvalds static void release_arcbuf(struct net_device *dev, int bufnum) 2881da177e4SLinus Torvalds { 289454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 2901da177e4SLinus Torvalds int i; 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvalds lp->buf_queue[lp->first_free_buf++] = bufnum; 2931da177e4SLinus Torvalds lp->first_free_buf %= 5; 2941da177e4SLinus Torvalds 29572aeea48SJoe Perches if (BUGLVL(D_DURING)) { 296a34c0932SJoe Perches arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ", 2971da177e4SLinus Torvalds bufnum); 2981da177e4SLinus Torvalds for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5) 299a34c0932SJoe Perches arc_cont(D_DURING, "#%d ", lp->buf_queue[i]); 300a34c0932SJoe Perches arc_cont(D_DURING, "\n"); 3011da177e4SLinus Torvalds } 3021da177e4SLinus Torvalds } 3031da177e4SLinus Torvalds 304f2f0a16bSJoe Perches /* Get a buffer from the queue. 305f2f0a16bSJoe Perches * If this returns -1, there are no buffers available. 3061da177e4SLinus Torvalds */ 3071da177e4SLinus Torvalds static int get_arcbuf(struct net_device *dev) 3081da177e4SLinus Torvalds { 309454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 3101da177e4SLinus Torvalds int buf = -1, i; 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds if (!atomic_dec_and_test(&lp->buf_lock)) { 3131da177e4SLinus Torvalds /* already in this function */ 314a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n", 3151da177e4SLinus Torvalds lp->buf_lock.counter); 3167f5e760cSJoe Perches } else { /* we can continue */ 3171da177e4SLinus Torvalds if (lp->next_buf >= 5) 3181da177e4SLinus Torvalds lp->next_buf -= 5; 3191da177e4SLinus Torvalds 3207f5e760cSJoe Perches if (lp->next_buf == lp->first_free_buf) { 321a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n"); 3227f5e760cSJoe Perches } else { 3231da177e4SLinus Torvalds buf = lp->buf_queue[lp->next_buf++]; 3241da177e4SLinus Torvalds lp->next_buf %= 5; 3251da177e4SLinus Torvalds } 3261da177e4SLinus Torvalds } 3271da177e4SLinus Torvalds 32872aeea48SJoe Perches if (BUGLVL(D_DURING)) { 329a34c0932SJoe Perches arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ", 330a34c0932SJoe Perches buf); 3311da177e4SLinus Torvalds for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5) 332a34c0932SJoe Perches arc_cont(D_DURING, "#%d ", lp->buf_queue[i]); 333a34c0932SJoe Perches arc_cont(D_DURING, "\n"); 3341da177e4SLinus Torvalds } 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds atomic_inc(&lp->buf_lock); 3371da177e4SLinus Torvalds return buf; 3381da177e4SLinus Torvalds } 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds static int choose_mtu(void) 3411da177e4SLinus Torvalds { 3421da177e4SLinus Torvalds int count, mtu = 65535; 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds /* choose the smallest MTU of all available encaps */ 3451da177e4SLinus Torvalds for (count = 0; count < 256; count++) { 3468e95a202SJoe Perches if (arc_proto_map[count] != &arc_proto_null && 3478e95a202SJoe Perches arc_proto_map[count]->mtu < mtu) { 3481da177e4SLinus Torvalds mtu = arc_proto_map[count]->mtu; 3491da177e4SLinus Torvalds } 3501da177e4SLinus Torvalds } 3511da177e4SLinus Torvalds 3521da177e4SLinus Torvalds return mtu == 65535 ? XMTU : mtu; 3531da177e4SLinus Torvalds } 3541da177e4SLinus Torvalds 3553b04dddeSStephen Hemminger static const struct header_ops arcnet_header_ops = { 3563b04dddeSStephen Hemminger .create = arcnet_header, 3573b04dddeSStephen Hemminger }; 3583b04dddeSStephen Hemminger 359bca5b893SStephen Hemminger static const struct net_device_ops arcnet_netdev_ops = { 360bca5b893SStephen Hemminger .ndo_open = arcnet_open, 361bca5b893SStephen Hemminger .ndo_stop = arcnet_close, 362bca5b893SStephen Hemminger .ndo_start_xmit = arcnet_send_packet, 363bca5b893SStephen Hemminger .ndo_tx_timeout = arcnet_timeout, 364bca5b893SStephen Hemminger }; 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds /* Setup a struct device for ARCnet. */ 3671da177e4SLinus Torvalds static void arcdev_setup(struct net_device *dev) 3681da177e4SLinus Torvalds { 3691da177e4SLinus Torvalds dev->type = ARPHRD_ARCNET; 370bca5b893SStephen Hemminger dev->netdev_ops = &arcnet_netdev_ops; 3713b04dddeSStephen Hemminger dev->header_ops = &arcnet_header_ops; 372980137a2SMichael Grzeschik dev->hard_header_len = sizeof(struct arc_hardware); 3731da177e4SLinus Torvalds dev->mtu = choose_mtu(); 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds dev->addr_len = ARCNET_ALEN; 3761da177e4SLinus Torvalds dev->tx_queue_len = 100; 3771da177e4SLinus Torvalds dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */ 3781da177e4SLinus Torvalds dev->watchdog_timeo = TX_TIMEOUT; 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds /* New-style flags. */ 3811da177e4SLinus Torvalds dev->flags = IFF_BROADCAST; 3821da177e4SLinus Torvalds } 3831da177e4SLinus Torvalds 38459fbcbc6SMichael Grzeschik static void arcnet_timer(unsigned long data) 38559fbcbc6SMichael Grzeschik { 38659fbcbc6SMichael Grzeschik struct net_device *dev = (struct net_device *)data; 38759fbcbc6SMichael Grzeschik 38859fbcbc6SMichael Grzeschik if (!netif_carrier_ok(dev)) { 38959fbcbc6SMichael Grzeschik netif_carrier_on(dev); 39059fbcbc6SMichael Grzeschik netdev_info(dev, "link up\n"); 39159fbcbc6SMichael Grzeschik } 39259fbcbc6SMichael Grzeschik } 39359fbcbc6SMichael Grzeschik 394bca5b893SStephen Hemminger struct net_device *alloc_arcdev(const char *name) 3951da177e4SLinus Torvalds { 3961da177e4SLinus Torvalds struct net_device *dev; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds dev = alloc_netdev(sizeof(struct arcnet_local), 399c835a677STom Gundersen name && *name ? name : "arc%d", NET_NAME_UNKNOWN, 400c835a677STom Gundersen arcdev_setup); 4011da177e4SLinus Torvalds if (dev) { 402454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 40301a1d5acSJoe Perches 4041da177e4SLinus Torvalds spin_lock_init(&lp->lock); 40559fbcbc6SMichael Grzeschik init_timer(&lp->timer); 40659fbcbc6SMichael Grzeschik lp->timer.data = (unsigned long) dev; 40759fbcbc6SMichael Grzeschik lp->timer.function = arcnet_timer; 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds return dev; 4111da177e4SLinus Torvalds } 412811eafc0SJoe Perches EXPORT_SYMBOL(alloc_arcdev); 4131da177e4SLinus Torvalds 414f2f0a16bSJoe Perches /* Open/initialize the board. This is called sometime after booting when 4151da177e4SLinus Torvalds * the 'ifconfig' program is run. 4161da177e4SLinus Torvalds * 4171da177e4SLinus Torvalds * This routine should set everything up anew at each open, even registers 4181da177e4SLinus Torvalds * that "should" only need to be set once at boot, so that there is 4191da177e4SLinus Torvalds * non-reboot way to recover if something goes wrong. 4201da177e4SLinus Torvalds */ 421bca5b893SStephen Hemminger int arcnet_open(struct net_device *dev) 4221da177e4SLinus Torvalds { 423454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 4241da177e4SLinus Torvalds int count, newmtu, error; 4251da177e4SLinus Torvalds 426a34c0932SJoe Perches arc_printk(D_INIT, dev, "opened."); 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds if (!try_module_get(lp->hw.owner)) 4291da177e4SLinus Torvalds return -ENODEV; 4301da177e4SLinus Torvalds 43172aeea48SJoe Perches if (BUGLVL(D_PROTO)) { 432a34c0932SJoe Perches arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ", 4331da177e4SLinus Torvalds arc_proto_default->suffix); 4341da177e4SLinus Torvalds for (count = 0; count < 256; count++) 435a34c0932SJoe Perches arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix); 436a34c0932SJoe Perches arc_cont(D_PROTO, "\n"); 4371da177e4SLinus Torvalds } 4381da177e4SLinus Torvalds 439a34c0932SJoe Perches arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n"); 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds /* try to put the card in a defined state - if it fails the first 4421da177e4SLinus Torvalds * time, actually reset it. 4431da177e4SLinus Torvalds */ 4441da177e4SLinus Torvalds error = -ENODEV; 445e15b0362SJoe Perches if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1)) 4461da177e4SLinus Torvalds goto out_module_put; 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvalds newmtu = choose_mtu(); 4491da177e4SLinus Torvalds if (newmtu < dev->mtu) 4501da177e4SLinus Torvalds dev->mtu = newmtu; 4511da177e4SLinus Torvalds 452a34c0932SJoe Perches arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu); 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds /* autodetect the encapsulation for each host. */ 4551da177e4SLinus Torvalds memset(lp->default_proto, 0, sizeof(lp->default_proto)); 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvalds /* the broadcast address is special - use the 'bcast' protocol */ 4581da177e4SLinus Torvalds for (count = 0; count < 256; count++) { 4591da177e4SLinus Torvalds if (arc_proto_map[count] == arc_bcast_proto) { 4601da177e4SLinus Torvalds lp->default_proto[0] = count; 4611da177e4SLinus Torvalds break; 4621da177e4SLinus Torvalds } 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds /* initialize buffers */ 4661da177e4SLinus Torvalds atomic_set(&lp->buf_lock, 1); 4671da177e4SLinus Torvalds 4681da177e4SLinus Torvalds lp->next_buf = lp->first_free_buf = 0; 4691da177e4SLinus Torvalds release_arcbuf(dev, 0); 4701da177e4SLinus Torvalds release_arcbuf(dev, 1); 4711da177e4SLinus Torvalds release_arcbuf(dev, 2); 4721da177e4SLinus Torvalds release_arcbuf(dev, 3); 4731da177e4SLinus Torvalds lp->cur_tx = lp->next_tx = -1; 4741da177e4SLinus Torvalds lp->cur_rx = -1; 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds lp->rfc1201.sequence = 1; 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds /* bring up the hardware driver */ 4791da177e4SLinus Torvalds if (lp->hw.open) 4801da177e4SLinus Torvalds lp->hw.open(dev); 4811da177e4SLinus Torvalds 4821da177e4SLinus Torvalds if (dev->dev_addr[0] == 0) 483a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "WARNING! Station address 00 is reserved for broadcasts!\n"); 4841da177e4SLinus Torvalds else if (dev->dev_addr[0] == 255) 485a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "WARNING! Station address FF may confuse DOS networking programs!\n"); 4861da177e4SLinus Torvalds 487a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); 488e15b0362SJoe Perches if (lp->hw.status(dev) & RESETflag) { 489a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", 490a34c0932SJoe Perches __FILE__, __LINE__, __func__); 491e15b0362SJoe Perches lp->hw.command(dev, CFLAGScmd | RESETclear); 4921da177e4SLinus Torvalds } 4931da177e4SLinus Torvalds 494a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); 4951da177e4SLinus Torvalds /* make sure we're ready to receive IRQ's. */ 496e15b0362SJoe Perches lp->hw.intmask(dev, 0); 4971da177e4SLinus Torvalds udelay(1); /* give it time to set the mask before 4981da177e4SLinus Torvalds * we reset it again. (may not even be 4991da177e4SLinus Torvalds * necessary) 5001da177e4SLinus Torvalds */ 501a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); 5021da177e4SLinus Torvalds lp->intmask = NORXflag | RECONflag; 503e15b0362SJoe Perches lp->hw.intmask(dev, lp->intmask); 504a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); 5051da177e4SLinus Torvalds 50659fbcbc6SMichael Grzeschik netif_carrier_off(dev); 5071da177e4SLinus Torvalds netif_start_queue(dev); 50859fbcbc6SMichael Grzeschik mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000)); 5091da177e4SLinus Torvalds 5108890624aSMichael Grzeschik arcnet_led_event(dev, ARCNET_LED_EVENT_OPEN); 5111da177e4SLinus Torvalds return 0; 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds out_module_put: 5141da177e4SLinus Torvalds module_put(lp->hw.owner); 5151da177e4SLinus Torvalds return error; 5161da177e4SLinus Torvalds } 517811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_open); 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds /* The inverse routine to arcnet_open - shuts down the card. */ 520bca5b893SStephen Hemminger int arcnet_close(struct net_device *dev) 5211da177e4SLinus Torvalds { 522454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 5231da177e4SLinus Torvalds 5248890624aSMichael Grzeschik arcnet_led_event(dev, ARCNET_LED_EVENT_STOP); 52559fbcbc6SMichael Grzeschik del_timer_sync(&lp->timer); 52659fbcbc6SMichael Grzeschik 5271da177e4SLinus Torvalds netif_stop_queue(dev); 52859fbcbc6SMichael Grzeschik netif_carrier_off(dev); 5291da177e4SLinus Torvalds 5301da177e4SLinus Torvalds /* flush TX and disable RX */ 531e15b0362SJoe Perches lp->hw.intmask(dev, 0); 532e15b0362SJoe Perches lp->hw.command(dev, NOTXcmd); /* stop transmit */ 533e15b0362SJoe Perches lp->hw.command(dev, NORXcmd); /* disable receive */ 5341da177e4SLinus Torvalds mdelay(1); 5351da177e4SLinus Torvalds 5361da177e4SLinus Torvalds /* shut down the card */ 5371da177e4SLinus Torvalds lp->hw.close(dev); 5381da177e4SLinus Torvalds module_put(lp->hw.owner); 5391da177e4SLinus Torvalds return 0; 5401da177e4SLinus Torvalds } 541811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_close); 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds static int arcnet_header(struct sk_buff *skb, struct net_device *dev, 5443b04dddeSStephen Hemminger unsigned short type, const void *daddr, 5453b04dddeSStephen Hemminger const void *saddr, unsigned len) 5461da177e4SLinus Torvalds { 5473b04dddeSStephen Hemminger const struct arcnet_local *lp = netdev_priv(dev); 5481da177e4SLinus Torvalds uint8_t _daddr, proto_num; 5491da177e4SLinus Torvalds struct ArcProto *proto; 5501da177e4SLinus Torvalds 551a34c0932SJoe Perches arc_printk(D_DURING, dev, 5521da177e4SLinus Torvalds "create header from %d to %d; protocol %d (%Xh); size %u.\n", 5531da177e4SLinus Torvalds saddr ? *(uint8_t *)saddr : -1, 5541da177e4SLinus Torvalds daddr ? *(uint8_t *)daddr : -1, 5551da177e4SLinus Torvalds type, type, len); 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds if (skb->len != 0 && len != skb->len) 558a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n", 5591da177e4SLinus Torvalds skb->len, len); 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds /* Type is host order - ? */ 5621da177e4SLinus Torvalds if (type == ETH_P_ARCNET) { 5631da177e4SLinus Torvalds proto = arc_raw_proto; 564a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n", 565a34c0932SJoe Perches proto->suffix); 5661da177e4SLinus Torvalds _daddr = daddr ? *(uint8_t *)daddr : 0; 5677f5e760cSJoe Perches } else if (!daddr) { 568f2f0a16bSJoe Perches /* if the dest addr isn't provided, we can't choose an 569f2f0a16bSJoe Perches * encapsulation! Store the packet type (eg. ETH_P_IP) 570f2f0a16bSJoe Perches * for now, and we'll push on a real header when we do 571f2f0a16bSJoe Perches * rebuild_header. 5721da177e4SLinus Torvalds */ 5731da177e4SLinus Torvalds *(uint16_t *)skb_push(skb, 2) = type; 574f2f0a16bSJoe Perches /* XXX: Why not use skb->mac_len? */ 575b0e380b1SArnaldo Carvalho de Melo if (skb->network_header - skb->mac_header != 2) 576a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! diff (%u) is not 2!\n", 577a34c0932SJoe Perches skb->network_header - skb->mac_header); 5781da177e4SLinus Torvalds return -2; /* return error -- can't transmit yet! */ 5797f5e760cSJoe Perches } else { 5801da177e4SLinus Torvalds /* otherwise, we can just add the header as usual. */ 5811da177e4SLinus Torvalds _daddr = *(uint8_t *)daddr; 5821da177e4SLinus Torvalds proto_num = lp->default_proto[_daddr]; 5831da177e4SLinus Torvalds proto = arc_proto_map[proto_num]; 584a34c0932SJoe Perches arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n", 5851da177e4SLinus Torvalds proto_num, proto->suffix); 5861da177e4SLinus Torvalds if (proto == &arc_proto_null && arc_bcast_proto != proto) { 587a34c0932SJoe Perches arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n", 5881da177e4SLinus Torvalds arc_bcast_proto->suffix); 5891da177e4SLinus Torvalds proto = arc_bcast_proto; 5901da177e4SLinus Torvalds } 5911da177e4SLinus Torvalds } 5921da177e4SLinus Torvalds return proto->build_header(skb, dev, type, _daddr); 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds /* Called by the kernel in order to transmit a packet. */ 59661357325SStephen Hemminger netdev_tx_t arcnet_send_packet(struct sk_buff *skb, 59761357325SStephen Hemminger struct net_device *dev) 5981da177e4SLinus Torvalds { 599454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 6001da177e4SLinus Torvalds struct archdr *pkt; 6011da177e4SLinus Torvalds struct arc_rfc1201 *soft; 6021da177e4SLinus Torvalds struct ArcProto *proto; 6031da177e4SLinus Torvalds int txbuf; 6041da177e4SLinus Torvalds unsigned long flags; 605b82de0e2SMichael Grzeschik int retval; 6061da177e4SLinus Torvalds 607a34c0932SJoe Perches arc_printk(D_DURING, dev, 6081da177e4SLinus Torvalds "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n", 609e15b0362SJoe Perches lp->hw.status(dev), lp->cur_tx, lp->next_tx, skb->len, skb->protocol); 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds pkt = (struct archdr *)skb->data; 6121da177e4SLinus Torvalds soft = &pkt->soft.rfc1201; 6131da177e4SLinus Torvalds proto = arc_proto_map[soft->proto]; 6141da177e4SLinus Torvalds 615a34c0932SJoe Perches arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n", 6161da177e4SLinus Torvalds skb->len, pkt->hard.dest); 61772aeea48SJoe Perches if (BUGLVL(D_SKB)) 61872aeea48SJoe Perches arcnet_dump_skb(dev, skb, "tx"); 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds /* fits in one packet? */ 6211da177e4SLinus Torvalds if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) { 622a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n"); 6231da177e4SLinus Torvalds dev_kfree_skb(skb); 624c6bb15a0SPieter Dejaeghere return NETDEV_TX_OK; /* don't try again */ 6251da177e4SLinus Torvalds } 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds /* We're busy transmitting a packet... */ 6281da177e4SLinus Torvalds netif_stop_queue(dev); 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags); 631e15b0362SJoe Perches lp->hw.intmask(dev, 0); 632c6bb15a0SPieter Dejaeghere if (lp->next_tx == -1) 6331da177e4SLinus Torvalds txbuf = get_arcbuf(dev); 6347f5e760cSJoe Perches else 635c6bb15a0SPieter Dejaeghere txbuf = -1; 6367f5e760cSJoe Perches 6371da177e4SLinus Torvalds if (txbuf != -1) { 6381da177e4SLinus Torvalds if (proto->prepare_tx(dev, pkt, skb->len, txbuf) && 6391da177e4SLinus Torvalds !proto->ack_tx) { 6401da177e4SLinus Torvalds /* done right away and we don't want to acknowledge 641f2f0a16bSJoe Perches * the package later - forget about it now 642f2f0a16bSJoe Perches */ 6435803c512SStephen Hemminger dev->stats.tx_bytes += skb->len; 644b82de0e2SMichael Grzeschik dev_kfree_skb(skb); 6451da177e4SLinus Torvalds } else { 6461da177e4SLinus Torvalds /* do it the 'split' way */ 6471da177e4SLinus Torvalds lp->outgoing.proto = proto; 6481da177e4SLinus Torvalds lp->outgoing.skb = skb; 6491da177e4SLinus Torvalds lp->outgoing.pkt = pkt; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds if (proto->continue_tx && 6521da177e4SLinus Torvalds proto->continue_tx(dev, txbuf)) { 653a34c0932SJoe Perches arc_printk(D_NORMAL, dev, 6543b4e5551SJoe Perches "bug! continue_tx finished the first time! (proto='%c')\n", 6553b4e5551SJoe Perches proto->suffix); 6561da177e4SLinus Torvalds } 6571da177e4SLinus Torvalds } 658c6bb15a0SPieter Dejaeghere retval = NETDEV_TX_OK; 6591da177e4SLinus Torvalds lp->next_tx = txbuf; 6601da177e4SLinus Torvalds } else { 661c6bb15a0SPieter Dejaeghere retval = NETDEV_TX_BUSY; 6621da177e4SLinus Torvalds } 6631da177e4SLinus Torvalds 664a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n", 665e15b0362SJoe Perches __FILE__, __LINE__, __func__, lp->hw.status(dev)); 6661da177e4SLinus Torvalds /* make sure we didn't ignore a TX IRQ while we were in here */ 667e15b0362SJoe Perches lp->hw.intmask(dev, 0); 6681da177e4SLinus Torvalds 669a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); 6701da177e4SLinus Torvalds lp->intmask |= TXFREEflag | EXCNAKflag; 671e15b0362SJoe Perches lp->hw.intmask(dev, lp->intmask); 672a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n", 673e15b0362SJoe Perches __FILE__, __LINE__, __func__, lp->hw.status(dev)); 6741da177e4SLinus Torvalds 6758890624aSMichael Grzeschik arcnet_led_event(dev, ARCNET_LED_EVENT_TX); 6768890624aSMichael Grzeschik 6771da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags); 678c6bb15a0SPieter Dejaeghere return retval; /* no need to try again */ 6791da177e4SLinus Torvalds } 680811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_send_packet); 6811da177e4SLinus Torvalds 682f2f0a16bSJoe Perches /* Actually start transmitting a packet that was loaded into a buffer 6831da177e4SLinus Torvalds * by prepare_tx. This should _only_ be called by the interrupt handler. 6841da177e4SLinus Torvalds */ 6851da177e4SLinus Torvalds static int go_tx(struct net_device *dev) 6861da177e4SLinus Torvalds { 687454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 6881da177e4SLinus Torvalds 689a34c0932SJoe Perches arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n", 690e15b0362SJoe Perches lp->hw.status(dev), lp->intmask, lp->next_tx, lp->cur_tx); 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds if (lp->cur_tx != -1 || lp->next_tx == -1) 6931da177e4SLinus Torvalds return 0; 6941da177e4SLinus Torvalds 69572aeea48SJoe Perches if (BUGLVL(D_TX)) 69672aeea48SJoe Perches arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0); 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds lp->cur_tx = lp->next_tx; 6991da177e4SLinus Torvalds lp->next_tx = -1; 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds /* start sending */ 702e15b0362SJoe Perches lp->hw.command(dev, TXcmd | (lp->cur_tx << 3)); 7031da177e4SLinus Torvalds 7045803c512SStephen Hemminger dev->stats.tx_packets++; 7051da177e4SLinus Torvalds lp->lasttrans_dest = lp->lastload_dest; 7061da177e4SLinus Torvalds lp->lastload_dest = 0; 7071da177e4SLinus Torvalds lp->excnak_pending = 0; 7081da177e4SLinus Torvalds lp->intmask |= TXFREEflag | EXCNAKflag; 7091da177e4SLinus Torvalds 7101da177e4SLinus Torvalds return 1; 7111da177e4SLinus Torvalds } 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds /* Called by the kernel when transmit times out */ 714bca5b893SStephen Hemminger void arcnet_timeout(struct net_device *dev) 7151da177e4SLinus Torvalds { 7161da177e4SLinus Torvalds unsigned long flags; 717454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 718e15b0362SJoe Perches int status = lp->hw.status(dev); 7191da177e4SLinus Torvalds char *msg; 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds spin_lock_irqsave(&lp->lock, flags); 7221da177e4SLinus Torvalds if (status & TXFREEflag) { /* transmit _DID_ finish */ 7231da177e4SLinus Torvalds msg = " - missed IRQ?"; 7241da177e4SLinus Torvalds } else { 7251da177e4SLinus Torvalds msg = ""; 7265803c512SStephen Hemminger dev->stats.tx_aborted_errors++; 7271da177e4SLinus Torvalds lp->timed_out = 1; 728e15b0362SJoe Perches lp->hw.command(dev, NOTXcmd | (lp->cur_tx << 3)); 7291da177e4SLinus Torvalds } 7305803c512SStephen Hemminger dev->stats.tx_errors++; 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds /* make sure we didn't miss a TX or a EXC NAK IRQ */ 733e15b0362SJoe Perches lp->hw.intmask(dev, 0); 7341da177e4SLinus Torvalds lp->intmask |= TXFREEflag | EXCNAKflag; 735e15b0362SJoe Perches lp->hw.intmask(dev, lp->intmask); 7361da177e4SLinus Torvalds 7371da177e4SLinus Torvalds spin_unlock_irqrestore(&lp->lock, flags); 7381da177e4SLinus Torvalds 739ff5688aeSMarcelo Feitoza Parisi if (time_after(jiffies, lp->last_timeout + 10 * HZ)) { 740a34c0932SJoe Perches arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n", 7411da177e4SLinus Torvalds msg, status, lp->intmask, lp->lasttrans_dest); 7421da177e4SLinus Torvalds lp->last_timeout = jiffies; 7431da177e4SLinus Torvalds } 7441da177e4SLinus Torvalds 7451da177e4SLinus Torvalds if (lp->cur_tx == -1) 7461da177e4SLinus Torvalds netif_wake_queue(dev); 7471da177e4SLinus Torvalds } 748811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_timeout); 7491da177e4SLinus Torvalds 750f2f0a16bSJoe Perches /* 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 761a34c0932SJoe Perches arc_printk(D_DURING, dev, "\n"); 7621da177e4SLinus Torvalds 763a34c0932SJoe Perches arc_printk(D_DURING, dev, "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 770f2f0a16bSJoe Perches /* RESET flag was enabled - if device is not running, we must 771f2f0a16bSJoe Perches * clear it right away (but nothing else). 7721da177e4SLinus Torvalds */ 7731da177e4SLinus Torvalds if (!netif_running(dev)) { 774e15b0362SJoe Perches if (lp->hw.status(dev) & RESETflag) 775e15b0362SJoe Perches lp->hw.command(dev, CFLAGScmd | RESETclear); 776e15b0362SJoe Perches lp->hw.intmask(dev, 0); 7771da177e4SLinus Torvalds spin_unlock(&lp->lock); 778226ee675SMichael Grzeschik return retval; 7791da177e4SLinus Torvalds } 7801da177e4SLinus Torvalds 781a34c0932SJoe Perches arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n", 782e15b0362SJoe Perches lp->hw.status(dev), lp->intmask); 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds boguscount = 5; 7851da177e4SLinus Torvalds do { 786e15b0362SJoe Perches status = lp->hw.status(dev); 7871da177e4SLinus Torvalds diagstatus = (status >> 8) & 0xFF; 7881da177e4SLinus Torvalds 789a34c0932SJoe Perches arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n", 790b39d66a8SHarvey Harrison __FILE__, __LINE__, __func__, status); 7911da177e4SLinus Torvalds didsomething = 0; 7921da177e4SLinus Torvalds 793f2f0a16bSJoe Perches /* RESET flag was enabled - card is resetting and if RX is 7941da177e4SLinus Torvalds * disabled, it's NOT because we just got a packet. 7951da177e4SLinus Torvalds * 796f2f0a16bSJoe Perches * The card is in an undefined state. 797f2f0a16bSJoe Perches * Clear it out and start over. 7981da177e4SLinus Torvalds */ 7991da177e4SLinus Torvalds if (status & RESETflag) { 800a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n", 801a34c0932SJoe Perches 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 } 808f2f0a16bSJoe Perches /* RX is inhibited - we must have received something. 809f2f0a16bSJoe Perches * Prepare to receive into the next buffer. 8101da177e4SLinus Torvalds * 811f2f0a16bSJoe Perches * We don't actually copy the received packet from the card 812f2f0a16bSJoe Perches * until after the transmit handler runs (and possibly 813f2f0a16bSJoe Perches * launches the next tx); this should improve latency slightly 814f2f0a16bSJoe Perches * if we get both types of interrupts at once. 8151da177e4SLinus Torvalds */ 8161da177e4SLinus Torvalds recbuf = -1; 8171da177e4SLinus Torvalds if (status & lp->intmask & NORXflag) { 8181da177e4SLinus Torvalds recbuf = lp->cur_rx; 819a34c0932SJoe Perches arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n", 8201da177e4SLinus Torvalds recbuf, status); 8211da177e4SLinus Torvalds 8221da177e4SLinus Torvalds lp->cur_rx = get_arcbuf(dev); 8231da177e4SLinus Torvalds if (lp->cur_rx != -1) { 824a34c0932SJoe Perches arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n", 8251da177e4SLinus Torvalds lp->cur_rx); 826e15b0362SJoe Perches lp->hw.command(dev, RXcmd | (lp->cur_rx << 3) | RXbcasts); 8271da177e4SLinus Torvalds } 8281da177e4SLinus Torvalds didsomething++; 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds if ((diagstatus & EXCNAKflag)) { 832a34c0932SJoe Perches arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n", 8331da177e4SLinus Torvalds diagstatus); 8341da177e4SLinus Torvalds 835e15b0362SJoe Perches lp->hw.command(dev, NOTXcmd); /* disable transmit */ 8361da177e4SLinus Torvalds lp->excnak_pending = 1; 8371da177e4SLinus Torvalds 838e15b0362SJoe Perches lp->hw.command(dev, EXCNAKclear); 8391da177e4SLinus Torvalds lp->intmask &= ~(EXCNAKflag); 8401da177e4SLinus Torvalds didsomething++; 8411da177e4SLinus Torvalds } 8421da177e4SLinus Torvalds 8431da177e4SLinus Torvalds /* a transmit finished, and we're interested in it. */ 8441da177e4SLinus Torvalds if ((status & lp->intmask & TXFREEflag) || lp->timed_out) { 8451da177e4SLinus Torvalds lp->intmask &= ~(TXFREEflag | EXCNAKflag); 8461da177e4SLinus Torvalds 847d6d7d3edSJoe Perches arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n", 848d6d7d3edSJoe Perches status); 8491da177e4SLinus Torvalds 8501da177e4SLinus Torvalds if (lp->cur_tx != -1 && !lp->timed_out) { 8511da177e4SLinus Torvalds if (!(status & TXACKflag)) { 8521da177e4SLinus Torvalds if (lp->lasttrans_dest != 0) { 853a34c0932SJoe Perches arc_printk(D_EXTRA, dev, 8543b4e5551SJoe Perches "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n", 855a34c0932SJoe Perches status, 856a34c0932SJoe Perches lp->lasttrans_dest); 8575803c512SStephen Hemminger dev->stats.tx_errors++; 8585803c512SStephen Hemminger dev->stats.tx_carrier_errors++; 8591da177e4SLinus Torvalds } else { 860a34c0932SJoe Perches arc_printk(D_DURING, dev, 8613b4e5551SJoe Perches "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n", 862a34c0932SJoe Perches status, 863a34c0932SJoe Perches lp->lasttrans_dest); 8641da177e4SLinus Torvalds } 8651da177e4SLinus Torvalds } 8661da177e4SLinus Torvalds 8671da177e4SLinus Torvalds if (lp->outgoing.proto && 8681da177e4SLinus Torvalds lp->outgoing.proto->ack_tx) { 8691da177e4SLinus Torvalds int ackstatus; 87001a1d5acSJoe Perches 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 */ 893d6d7d3edSJoe Perches if (lp->outgoing.proto && 894d6d7d3edSJoe Perches lp->outgoing.proto->continue_tx) { 8951da177e4SLinus Torvalds int txbuf = get_arcbuf(dev); 89601a1d5acSJoe Perches 8971da177e4SLinus Torvalds if (txbuf != -1) { 8981da177e4SLinus Torvalds if (lp->outgoing.proto->continue_tx(dev, txbuf)) { 8991da177e4SLinus Torvalds /* that was the last segment */ 9005803c512SStephen Hemminger dev->stats.tx_bytes += lp->outgoing.skb->len; 9017f5e760cSJoe Perches if (!lp->outgoing.proto->ack_tx) { 9021da177e4SLinus Torvalds dev_kfree_skb_irq(lp->outgoing.skb); 9031da177e4SLinus Torvalds lp->outgoing.proto = NULL; 9041da177e4SLinus Torvalds } 9051da177e4SLinus Torvalds } 9061da177e4SLinus Torvalds lp->next_tx = txbuf; 9071da177e4SLinus Torvalds } 9081da177e4SLinus Torvalds } 9091da177e4SLinus Torvalds /* inform upper layers of idleness, if necessary */ 9101da177e4SLinus Torvalds if (lp->cur_tx == -1) 9111da177e4SLinus Torvalds netif_wake_queue(dev); 9121da177e4SLinus Torvalds } 9131da177e4SLinus Torvalds /* now process the received packet, if any */ 9141da177e4SLinus Torvalds if (recbuf != -1) { 91572aeea48SJoe Perches if (BUGLVL(D_RX)) 91672aeea48SJoe Perches arcnet_dump_packet(dev, recbuf, "rx irq", 0); 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds arcnet_rx(dev, recbuf); 9191da177e4SLinus Torvalds release_arcbuf(dev, recbuf); 9201da177e4SLinus Torvalds 9211da177e4SLinus Torvalds didsomething++; 9221da177e4SLinus Torvalds } 9231da177e4SLinus Torvalds if (status & lp->intmask & RECONflag) { 924e15b0362SJoe Perches lp->hw.command(dev, CFLAGScmd | CONFIGclear); 9255803c512SStephen Hemminger dev->stats.tx_carrier_errors++; 9261da177e4SLinus Torvalds 927a34c0932SJoe Perches arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n", 9281da177e4SLinus Torvalds status); 92959fbcbc6SMichael Grzeschik if (netif_carrier_ok(dev)) { 93059fbcbc6SMichael Grzeschik netif_carrier_off(dev); 93159fbcbc6SMichael Grzeschik netdev_info(dev, "link down\n"); 93259fbcbc6SMichael Grzeschik } 93359fbcbc6SMichael Grzeschik mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000)); 93459fbcbc6SMichael Grzeschik 9358890624aSMichael Grzeschik arcnet_led_event(dev, ARCNET_LED_EVENT_RECON); 936c6bb15a0SPieter Dejaeghere /* MYRECON bit is at bit 7 of diagstatus */ 937c6bb15a0SPieter Dejaeghere if (diagstatus & 0x80) 938a34c0932SJoe Perches arc_printk(D_RECON, dev, "Put out that recon myself\n"); 9391da177e4SLinus Torvalds 9401da177e4SLinus Torvalds /* is the RECON info empty or old? */ 9411da177e4SLinus Torvalds if (!lp->first_recon || !lp->last_recon || 9429307b570SS.Caglar Onur time_after(jiffies, lp->last_recon + HZ * 10)) { 9431da177e4SLinus Torvalds if (lp->network_down) 944a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n"); 9451da177e4SLinus Torvalds lp->first_recon = lp->last_recon = jiffies; 9461da177e4SLinus Torvalds lp->num_recons = lp->network_down = 0; 9471da177e4SLinus Torvalds 948a34c0932SJoe Perches arc_printk(D_DURING, dev, "recon: clearing counters.\n"); 9491da177e4SLinus Torvalds } else { /* add to current RECON counter */ 9501da177e4SLinus Torvalds lp->last_recon = jiffies; 9511da177e4SLinus Torvalds lp->num_recons++; 9521da177e4SLinus Torvalds 953a34c0932SJoe Perches arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n", 9541da177e4SLinus Torvalds lp->num_recons, 9551da177e4SLinus Torvalds (lp->last_recon - lp->first_recon) / HZ, 9561da177e4SLinus Torvalds lp->network_down); 9571da177e4SLinus Torvalds 9581da177e4SLinus Torvalds /* if network is marked up; 9591da177e4SLinus Torvalds * and first_recon and last_recon are 60+ apart; 9601da177e4SLinus Torvalds * and the average no. of recons counted is 9611da177e4SLinus Torvalds * > RECON_THRESHOLD/min; 9621da177e4SLinus Torvalds * then print a warning message. 9631da177e4SLinus Torvalds */ 9648e95a202SJoe Perches if (!lp->network_down && 9658e95a202SJoe Perches (lp->last_recon - lp->first_recon) <= HZ * 60 && 9668e95a202SJoe Perches lp->num_recons >= RECON_THRESHOLD) { 9671da177e4SLinus Torvalds lp->network_down = 1; 968a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n"); 9698e95a202SJoe Perches } else if (!lp->network_down && 9708e95a202SJoe Perches lp->last_recon - lp->first_recon > HZ * 60) { 971d6d7d3edSJoe Perches /* reset counters if we've gone for 972d6d7d3edSJoe Perches * over a minute. 973d6d7d3edSJoe Perches */ 9741da177e4SLinus Torvalds lp->first_recon = lp->last_recon; 9751da177e4SLinus Torvalds lp->num_recons = 1; 9761da177e4SLinus Torvalds } 9771da177e4SLinus Torvalds } 9789307b570SS.Caglar Onur } else if (lp->network_down && 9799307b570SS.Caglar Onur time_after(jiffies, lp->last_recon + HZ * 10)) { 9801da177e4SLinus Torvalds if (lp->network_down) 981a34c0932SJoe Perches arc_printk(D_NORMAL, dev, "cabling restored?\n"); 9821da177e4SLinus Torvalds lp->first_recon = lp->last_recon = 0; 9831da177e4SLinus Torvalds lp->num_recons = lp->network_down = 0; 9841da177e4SLinus Torvalds 985a34c0932SJoe Perches arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n"); 98659fbcbc6SMichael Grzeschik netif_carrier_on(dev); 9871da177e4SLinus Torvalds } 9881da177e4SLinus Torvalds 9897f5e760cSJoe Perches if (didsomething) 9901da177e4SLinus Torvalds retval |= IRQ_HANDLED; 9917f5e760cSJoe Perches } while (--boguscount && didsomething); 9921da177e4SLinus Torvalds 993a34c0932SJoe Perches arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n", 994e15b0362SJoe Perches lp->hw.status(dev), boguscount); 995a34c0932SJoe Perches arc_printk(D_DURING, dev, "\n"); 9961da177e4SLinus Torvalds 997e15b0362SJoe Perches lp->hw.intmask(dev, 0); 9981da177e4SLinus Torvalds udelay(1); 999e15b0362SJoe Perches lp->hw.intmask(dev, lp->intmask); 10001da177e4SLinus Torvalds 10011da177e4SLinus Torvalds spin_unlock(&lp->lock); 10021da177e4SLinus Torvalds return retval; 10031da177e4SLinus Torvalds } 1004811eafc0SJoe Perches EXPORT_SYMBOL(arcnet_interrupt); 10051da177e4SLinus Torvalds 1006f2f0a16bSJoe Perches /* This is a generic packet receiver that calls arcnet??_rx depending on the 10071da177e4SLinus Torvalds * protocol ID found. 10081da177e4SLinus Torvalds */ 1009f03aa2d8SAdrian Bunk static void arcnet_rx(struct net_device *dev, int bufnum) 10101da177e4SLinus Torvalds { 1011454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 10121da177e4SLinus Torvalds struct archdr pkt; 10131da177e4SLinus Torvalds struct arc_rfc1201 *soft; 10141da177e4SLinus Torvalds int length, ofs; 10151da177e4SLinus Torvalds 10161da177e4SLinus Torvalds soft = &pkt.soft.rfc1201; 10171da177e4SLinus Torvalds 1018087d273cSDan Carpenter lp->hw.copy_from_card(dev, bufnum, 0, &pkt, ARC_HDR_SIZE); 10191da177e4SLinus Torvalds if (pkt.hard.offset[0]) { 10201da177e4SLinus Torvalds ofs = pkt.hard.offset[0]; 10211da177e4SLinus Torvalds length = 256 - ofs; 10221da177e4SLinus Torvalds } else { 10231da177e4SLinus Torvalds ofs = pkt.hard.offset[1]; 10241da177e4SLinus Torvalds length = 512 - ofs; 10251da177e4SLinus Torvalds } 10261da177e4SLinus Torvalds 10271da177e4SLinus Torvalds /* get the full header, if possible */ 10287f5e760cSJoe Perches if (sizeof(pkt.soft) <= length) { 10291da177e4SLinus Torvalds lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(pkt.soft)); 10307f5e760cSJoe Perches } else { 10311da177e4SLinus Torvalds memset(&pkt.soft, 0, sizeof(pkt.soft)); 10321da177e4SLinus Torvalds lp->hw.copy_from_card(dev, bufnum, ofs, soft, length); 10331da177e4SLinus Torvalds } 10341da177e4SLinus Torvalds 1035a34c0932SJoe Perches arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n", 10361da177e4SLinus Torvalds bufnum, pkt.hard.source, pkt.hard.dest, length); 10371da177e4SLinus Torvalds 10385803c512SStephen Hemminger dev->stats.rx_packets++; 10395803c512SStephen Hemminger dev->stats.rx_bytes += length + ARC_HDR_SIZE; 10401da177e4SLinus Torvalds 10411da177e4SLinus Torvalds /* call the right receiver for the protocol */ 10421da177e4SLinus Torvalds if (arc_proto_map[soft->proto]->is_ip) { 104372aeea48SJoe Perches if (BUGLVL(D_PROTO)) { 10441da177e4SLinus Torvalds struct ArcProto 10451da177e4SLinus Torvalds *oldp = arc_proto_map[lp->default_proto[pkt.hard.source]], 10461da177e4SLinus Torvalds *newp = arc_proto_map[soft->proto]; 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds if (oldp != newp) { 1049a34c0932SJoe Perches arc_printk(D_PROTO, dev, 10503b4e5551SJoe Perches "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n", 10513b4e5551SJoe Perches soft->proto, pkt.hard.source, 10521da177e4SLinus Torvalds newp->suffix, oldp->suffix); 10531da177e4SLinus Torvalds } 10541da177e4SLinus Torvalds } 10551da177e4SLinus Torvalds 10561da177e4SLinus Torvalds /* broadcasts will always be done with the last-used encap. */ 10571da177e4SLinus Torvalds lp->default_proto[0] = soft->proto; 10581da177e4SLinus Torvalds 10591da177e4SLinus Torvalds /* in striking contrast, the following isn't a hack. */ 10601da177e4SLinus Torvalds lp->default_proto[pkt.hard.source] = soft->proto; 10611da177e4SLinus Torvalds } 10621da177e4SLinus Torvalds /* call the protocol-specific receiver. */ 10631da177e4SLinus Torvalds arc_proto_map[soft->proto]->rx(dev, bufnum, &pkt, length); 10641da177e4SLinus Torvalds } 10651da177e4SLinus Torvalds 10661da177e4SLinus Torvalds static void null_rx(struct net_device *dev, int bufnum, 10671da177e4SLinus Torvalds struct archdr *pkthdr, int length) 10681da177e4SLinus Torvalds { 1069a34c0932SJoe Perches arc_printk(D_PROTO, dev, 10701da177e4SLinus Torvalds "rx: don't know how to deal with proto %02Xh from host %02Xh.\n", 10711da177e4SLinus Torvalds pkthdr->soft.rfc1201.proto, pkthdr->hard.source); 10721da177e4SLinus Torvalds } 10731da177e4SLinus Torvalds 10741da177e4SLinus Torvalds static int null_build_header(struct sk_buff *skb, struct net_device *dev, 10751da177e4SLinus Torvalds unsigned short type, uint8_t daddr) 10761da177e4SLinus Torvalds { 1077454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 10781da177e4SLinus Torvalds 1079a34c0932SJoe Perches arc_printk(D_PROTO, dev, 10801da177e4SLinus Torvalds "tx: can't build header for encap %02Xh; load a protocol driver.\n", 10811da177e4SLinus Torvalds lp->default_proto[daddr]); 10821da177e4SLinus Torvalds 10831da177e4SLinus Torvalds /* always fails */ 10841da177e4SLinus Torvalds return 0; 10851da177e4SLinus Torvalds } 10861da177e4SLinus Torvalds 10871da177e4SLinus Torvalds /* the "do nothing" prepare_tx function warns that there's nothing to do. */ 10881da177e4SLinus Torvalds static int null_prepare_tx(struct net_device *dev, struct archdr *pkt, 10891da177e4SLinus Torvalds int length, int bufnum) 10901da177e4SLinus Torvalds { 1091454d7c9bSWang Chen struct arcnet_local *lp = netdev_priv(dev); 10921da177e4SLinus Torvalds struct arc_hardware newpkt; 10931da177e4SLinus Torvalds 1094a34c0932SJoe Perches arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n"); 10951da177e4SLinus Torvalds 10961da177e4SLinus Torvalds /* send a packet to myself -- will never get received, of course */ 10971da177e4SLinus Torvalds newpkt.source = newpkt.dest = dev->dev_addr[0]; 10981da177e4SLinus Torvalds 10991da177e4SLinus Torvalds /* only one byte of actual data (and it's random) */ 11001da177e4SLinus Torvalds newpkt.offset[0] = 0xFF; 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE); 11031da177e4SLinus Torvalds 11041da177e4SLinus Torvalds return 1; /* done */ 11051da177e4SLinus Torvalds } 1106